#include <signal.h>
#ifndef SIG_ERR
-#define SIG_ERR ((void (*)(int))-1)
+#define SIG_ERR ((PyOS_sighandler_t)(-1))
#endif
#if defined(PYOS_OS2)
#endif
-\f
/*
NOTES ON THE INTERACTION BETWEEN SIGNALS AND THREADS
static PyObject *IgnoreHandler;
static PyObject *IntHandler;
-static void (*old_siginthandler)(int) = SIG_DFL;
+static PyOS_sighandler_t old_siginthandler = SIG_DFL;
-\f
static PyObject *
signal_default_int_handler(PyObject *self, PyObject *args)
{
The default handler for SIGINT instated by Python.\n\
It raises KeyboardInterrupt.";
-\f
static int
checksignals_witharg(void * unused)
#ifdef HAVE_SIGINTERRUPT
siginterrupt(sig_num, 1);
#endif
- signal(sig_num, signal_handler);
+ PyOS_setsig(sig_num, signal_handler);
}
-\f
#ifdef HAVE_ALARM
static PyObject *
signal_alarm(PyObject *self, PyObject *args)
#endif
-\f
+
static PyObject *
signal_signal(PyObject *self, PyObject *args)
{
#ifdef HAVE_SIGINTERRUPT
siginterrupt(sig_num, 1);
#endif
- if (signal(sig_num, func) == SIG_ERR) {
+ if (PyOS_setsig(sig_num, func) == SIG_ERR) {
PyErr_SetFromErrno(PyExc_RuntimeError);
return NULL;
}
A signal handler function is called with two arguments:\n\
the first is the signal number, the second is the interrupted stack frame.";
-\f
+
static PyObject *
signal_getsignal(PyObject *self, PyObject *args)
{
anything else -- the callable Python object used as a handler\n\
";
-\f
+
/* List of functions defined in the module */
static PyMethodDef signal_methods[] = {
#ifdef HAVE_ALARM
};
-\f
static char module_doc[] =
"This module provides mechanisms to use signal handlers in Python.\n\
\n\
Handlers[0].tripped = 0;
for (i = 1; i < NSIG; i++) {
void (*t)(int);
-#ifdef HAVE_SIGACTION
- struct sigaction act;
- sigaction(i, 0, &act);
- t = act.sa_handler;
-#else
- t = signal(i, SIG_IGN);
- signal(i, t);
-#endif
+ t = PyOS_getsig(i);
Handlers[i].tripped = 0;
if (t == SIG_DFL)
Handlers[i].func = DefaultHandler;
Py_INCREF(IntHandler);
Py_DECREF(Handlers[SIGINT].func);
Handlers[SIGINT].func = IntHandler;
- old_siginthandler = signal(SIGINT, &signal_handler);
+ old_siginthandler = PyOS_setsig(SIGINT, &signal_handler);
}
#ifdef SIGHUP
int i;
PyObject *func;
- signal(SIGINT, old_siginthandler);
+ PyOS_setsig(SIGINT, old_siginthandler);
old_siginthandler = SIG_DFL;
for (i = 1; i < NSIG; i++) {
Handlers[i].func = NULL;
if (i != SIGINT && func != NULL && func != Py_None &&
func != DefaultHandler && func != IgnoreHandler)
- signal(i, SIG_DFL);
+ PyOS_setsig(i, SIG_DFL);
Py_XDECREF(func);
}
}
-\f
/* Declared in pyerrors.h */
int
PyErr_CheckSignals(void)
return 0;
}
-\f
+
/* Replacements for intrcheck.c functionality
* Declared in pyerrors.h
*/