summaryrefslogtreecommitdiffstats
path: root/Modules/signalmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-02 03:01:42 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-02 03:01:42 (GMT)
commit08c166152e9f882d475b02e2d76a198389b13d0b (patch)
tree45c799dd4b6d049e8bfddbb62ce94f26857f20f9 /Modules/signalmodule.c
parent05f7c50bfd68ed0efc68145ff029b1509685751d (diff)
downloadcpython-08c166152e9f882d475b02e2d76a198389b13d0b.zip
cpython-08c166152e9f882d475b02e2d76a198389b13d0b.tar.gz
cpython-08c166152e9f882d475b02e2d76a198389b13d0b.tar.bz2
Add finialization routines; fixed some memory leaks related to this.
Reset the SIGINT handler when the finalization is invoked.
Diffstat (limited to 'Modules/signalmodule.c')
-rw-r--r--Modules/signalmodule.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 89cab89..3a49965 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -104,6 +104,8 @@ static PyObject *DefaultHandler;
static PyObject *IgnoreHandler;
static PyObject *IntHandler;
+static RETSIGTYPE (*old_siginthandler)() = SIG_DFL;
+
static PyObject *
@@ -286,7 +288,6 @@ initsignal()
x = DefaultHandler = PyInt_FromLong((long)SIG_DFL);
if (!x || PyDict_SetItemString(d, "SIG_DFL", x) < 0)
goto finally;
- Py_DECREF(x);
x = IgnoreHandler = PyInt_FromLong((long)SIG_IGN);
if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0)
@@ -295,10 +296,12 @@ initsignal()
x = PyInt_FromLong((long)NSIG);
if (!x || PyDict_SetItemString(d, "NSIG", x) < 0)
goto finally;
+ Py_DECREF(x);
x = IntHandler = PyDict_GetItemString(d, "default_int_handler");
if (!x)
goto finally;
+ Py_INCREF(IntHandler);
Handlers[0].tripped = 0;
for (i = 1; i < NSIG; i++) {
@@ -322,10 +325,10 @@ initsignal()
}
if (Handlers[SIGINT].func == DefaultHandler) {
/* Install default int handler */
+ Py_INCREF(IntHandler);
Py_DECREF(Handlers[SIGINT].func);
Handlers[SIGINT].func = IntHandler;
- Py_INCREF(IntHandler);
- signal(SIGINT, &signal_handler);
+ old_siginthandler = signal(SIGINT, &signal_handler);
}
#ifdef SIGHUP
@@ -503,7 +506,28 @@ initsignal()
/* Check for errors */
finally:
- Py_FatalError("can't initialize module signal");
+ return;
+}
+
+static void
+finisignal()
+{
+ int i;
+
+ signal(SIGINT, old_siginthandler);
+
+ for (i = 1; i < NSIG; i++) {
+ Handlers[i].tripped = 0;
+ Py_XDECREF(Handlers[i].func);
+ Handlers[i].func = NULL;
+ }
+
+ Py_XDECREF(IntHandler);
+ IntHandler = NULL;
+ Py_XDECREF(DefaultHandler);
+ DefaultHandler = NULL;
+ Py_XDECREF(IgnoreHandler);
+ IgnoreHandler = NULL;
}
@@ -561,6 +585,13 @@ void
PyOS_InitInterrupts()
{
initsignal();
+ _PyImport_FixupExtension("signal", "signal");
+}
+
+void
+PyOS_FiniInterrupts()
+{
+ finisignal();
}
int