mirror of
https://github.com/python/cpython.git
synced 2025-11-03 19:34:08 +00:00
Add finialization routines; fixed some memory leaks related to this.
Reset the SIGINT handler when the finalization is invoked.
This commit is contained in:
parent
05f7c50bfd
commit
08c166152e
1 changed files with 35 additions and 4 deletions
|
|
@ -104,6 +104,8 @@ static PyObject *DefaultHandler;
|
||||||
static PyObject *IgnoreHandler;
|
static PyObject *IgnoreHandler;
|
||||||
static PyObject *IntHandler;
|
static PyObject *IntHandler;
|
||||||
|
|
||||||
|
static RETSIGTYPE (*old_siginthandler)() = SIG_DFL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
@ -286,7 +288,6 @@ initsignal()
|
||||||
x = DefaultHandler = PyInt_FromLong((long)SIG_DFL);
|
x = DefaultHandler = PyInt_FromLong((long)SIG_DFL);
|
||||||
if (!x || PyDict_SetItemString(d, "SIG_DFL", x) < 0)
|
if (!x || PyDict_SetItemString(d, "SIG_DFL", x) < 0)
|
||||||
goto finally;
|
goto finally;
|
||||||
Py_DECREF(x);
|
|
||||||
|
|
||||||
x = IgnoreHandler = PyInt_FromLong((long)SIG_IGN);
|
x = IgnoreHandler = PyInt_FromLong((long)SIG_IGN);
|
||||||
if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0)
|
if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0)
|
||||||
|
|
@ -295,10 +296,12 @@ initsignal()
|
||||||
x = PyInt_FromLong((long)NSIG);
|
x = PyInt_FromLong((long)NSIG);
|
||||||
if (!x || PyDict_SetItemString(d, "NSIG", x) < 0)
|
if (!x || PyDict_SetItemString(d, "NSIG", x) < 0)
|
||||||
goto finally;
|
goto finally;
|
||||||
|
Py_DECREF(x);
|
||||||
|
|
||||||
x = IntHandler = PyDict_GetItemString(d, "default_int_handler");
|
x = IntHandler = PyDict_GetItemString(d, "default_int_handler");
|
||||||
if (!x)
|
if (!x)
|
||||||
goto finally;
|
goto finally;
|
||||||
|
Py_INCREF(IntHandler);
|
||||||
|
|
||||||
Handlers[0].tripped = 0;
|
Handlers[0].tripped = 0;
|
||||||
for (i = 1; i < NSIG; i++) {
|
for (i = 1; i < NSIG; i++) {
|
||||||
|
|
@ -322,10 +325,10 @@ initsignal()
|
||||||
}
|
}
|
||||||
if (Handlers[SIGINT].func == DefaultHandler) {
|
if (Handlers[SIGINT].func == DefaultHandler) {
|
||||||
/* Install default int handler */
|
/* Install default int handler */
|
||||||
|
Py_INCREF(IntHandler);
|
||||||
Py_DECREF(Handlers[SIGINT].func);
|
Py_DECREF(Handlers[SIGINT].func);
|
||||||
Handlers[SIGINT].func = IntHandler;
|
Handlers[SIGINT].func = IntHandler;
|
||||||
Py_INCREF(IntHandler);
|
old_siginthandler = signal(SIGINT, &signal_handler);
|
||||||
signal(SIGINT, &signal_handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
|
|
@ -503,7 +506,28 @@ initsignal()
|
||||||
|
|
||||||
/* Check for errors */
|
/* Check for errors */
|
||||||
finally:
|
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()
|
PyOS_InitInterrupts()
|
||||||
{
|
{
|
||||||
initsignal();
|
initsignal();
|
||||||
|
_PyImport_FixupExtension("signal", "signal");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PyOS_FiniInterrupts()
|
||||||
|
{
|
||||||
|
finisignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue