pypy / pypy / module / cpyext / src / pysignals.c

The branch 'reflex-support' does not exist.
#include <Python.h>
#include <signal.h>

/* From pythonrun.c in the standard Python distribution */

/* Wrappers around sigaction() or signal(). */

/* It may seem odd that these functions do not interact with the rest of the
 * system (i.e.  their effects are not visible in the signal module) but
 * this is apparently intentional, CPython works the same way.  The signal
 * handlers defined in the signal module define what happens if the normal
 * Python signal handler is called.
 * A bit whacky, but that's the way it is */

PyOS_getsig(int sig)
    /* assume sigaction exists */
    struct sigaction context;
    if (sigaction(sig, NULL, &context) == -1)
        return SIG_ERR;
    return context.sa_handler;
    PyOS_sighandler_t handler;
/* Special signal handling for the secure CRT in Visual Studio 2005 */
#if defined(_MSC_VER) && _MSC_VER >= 1400
    switch (sig) {
    /* Only these signals are valid */
    case SIGINT:
    case SIGILL:
    case SIGFPE:
    case SIGSEGV:
    case SIGTERM:
    case SIGBREAK:
    case SIGABRT:
    /* Don't call signal() with other values or it will assert */
        return SIG_ERR;
#endif /* _MSC_VER && _MSC_VER >= 1400 */
    handler = signal(sig, SIG_IGN);
    if (handler != SIG_ERR)
        signal(sig, handler);
    return handler;

PyOS_setsig(int sig, PyOS_sighandler_t handler)
    /* assume sigaction exists */
    struct sigaction context, ocontext;
    context.sa_handler = handler;
    context.sa_flags = 0;
    if (sigaction(sig, &context, &ocontext) == -1)
        return SIG_ERR;
    return ocontext.sa_handler;
    PyOS_sighandler_t oldhandler;
    oldhandler = signal(sig, handler);
#ifndef MS_WINDOWS
    /* should check if this exists */
    siginterrupt(sig, 1);
    return oldhandler;