bpo-41713: Remove PyOS_InitInterrupts() function (GH-23342)
Remove the undocumented PyOS_InitInterrupts() C function. * Rename PyOS_InitInterrupts() to _PySignal_Init(). It now installs other signal handlers, not only SIGINT. * Rename PyOS_FiniInterrupts() to _PySignal_Fini()
This commit is contained in:
parent
975022b77b
commit
296a796951
|
@ -583,3 +583,8 @@ Removed
|
||||||
``Py_END_ALLOW_RECURSION`` and the ``recursion_critical`` field of the
|
``Py_END_ALLOW_RECURSION`` and the ``recursion_critical`` field of the
|
||||||
:c:type:`PyInterpreterState` structure.
|
:c:type:`PyInterpreterState` structure.
|
||||||
(Contributed by Serhiy Storchaka in :issue:`41936`.)
|
(Contributed by Serhiy Storchaka in :issue:`41936`.)
|
||||||
|
|
||||||
|
* Removed the undocumented ``PyOS_InitInterrupts()`` function. Initializing
|
||||||
|
Python already implicitly installs signal handlers: see
|
||||||
|
:c:member:`PyConfig.install_signal_handlers`.
|
||||||
|
(Contributed by Victor Stinner in :issue:`41713`.)
|
||||||
|
|
|
@ -68,7 +68,8 @@ extern void _PyFloat_Fini(PyThreadState *tstate);
|
||||||
extern void _PySlice_Fini(PyThreadState *tstate);
|
extern void _PySlice_Fini(PyThreadState *tstate);
|
||||||
extern void _PyAsyncGen_Fini(PyThreadState *tstate);
|
extern void _PyAsyncGen_Fini(PyThreadState *tstate);
|
||||||
|
|
||||||
extern void PyOS_FiniInterrupts(void);
|
extern int _PySignal_Init(int install_signal_handlers);
|
||||||
|
extern void _PySignal_Fini(void);
|
||||||
|
|
||||||
extern void _PyExc_Fini(PyThreadState *tstate);
|
extern void _PyExc_Fini(PyThreadState *tstate);
|
||||||
extern void _PyImport_Fini(void);
|
extern void _PyImport_Fini(void);
|
||||||
|
|
|
@ -5,7 +5,6 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyOS_InterruptOccurred(void);
|
PyAPI_FUNC(int) PyOS_InterruptOccurred(void);
|
||||||
PyAPI_FUNC(void) PyOS_InitInterrupts(void);
|
|
||||||
#ifdef HAVE_FORK
|
#ifdef HAVE_FORK
|
||||||
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
|
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000
|
||||||
PyAPI_FUNC(void) PyOS_BeforeFork(void);
|
PyAPI_FUNC(void) PyOS_BeforeFork(void);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Removed the undocumented ``PyOS_InitInterrupts()`` function. Initializing
|
||||||
|
Python already implicitly installs signal handlers: see
|
||||||
|
:c:member:`PyConfig.install_signal_handlers`. Patch by Victor Stinner.
|
|
@ -1674,8 +1674,8 @@ PyInit__signal(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
void
|
||||||
finisignal(void)
|
_PySignal_Fini(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
PyObject *func;
|
PyObject *func;
|
||||||
|
@ -1792,19 +1792,32 @@ PyErr_SetInterrupt(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
PyOS_InitInterrupts(void)
|
_PySignal_Init(int install_signal_handlers)
|
||||||
{
|
{
|
||||||
PyObject *m = PyImport_ImportModule("_signal");
|
if (!install_signal_handlers) {
|
||||||
if (m) {
|
// Nothing to do
|
||||||
Py_DECREF(m);
|
return 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
#ifdef SIGPIPE
|
||||||
PyOS_FiniInterrupts(void)
|
PyOS_setsig(SIGPIPE, SIG_IGN);
|
||||||
{
|
#endif
|
||||||
finisignal();
|
#ifdef SIGXFZ
|
||||||
|
PyOS_setsig(SIGXFZ, SIG_IGN);
|
||||||
|
#endif
|
||||||
|
#ifdef SIGXFSZ
|
||||||
|
PyOS_setsig(SIGXFSZ, SIG_IGN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Import _signal to install the Python SIGINT handler
|
||||||
|
PyObject *module = PyImport_ImportModule("_signal");
|
||||||
|
if (!module) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
Py_DECREF(module);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,6 @@ static PyStatus add_main_module(PyInterpreterState *interp);
|
||||||
static PyStatus init_import_site(void);
|
static PyStatus init_import_site(void);
|
||||||
static PyStatus init_set_builtins_open(void);
|
static PyStatus init_set_builtins_open(void);
|
||||||
static PyStatus init_sys_streams(PyThreadState *tstate);
|
static PyStatus init_sys_streams(PyThreadState *tstate);
|
||||||
static PyStatus init_signals(PyThreadState *tstate);
|
|
||||||
static void call_py_exitfuncs(PyThreadState *tstate);
|
static void call_py_exitfuncs(PyThreadState *tstate);
|
||||||
static void wait_for_thread_shutdown(PyThreadState *tstate);
|
static void wait_for_thread_shutdown(PyThreadState *tstate);
|
||||||
static void call_ll_exitfuncs(_PyRuntimeState *runtime);
|
static void call_ll_exitfuncs(_PyRuntimeState *runtime);
|
||||||
|
@ -1047,11 +1046,8 @@ init_interp_main(PyThreadState *tstate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_main_interp) {
|
if (is_main_interp) {
|
||||||
if (config->install_signal_handlers) {
|
if (_PySignal_Init(config->install_signal_handlers) < 0) {
|
||||||
status = init_signals(tstate);
|
return _PyStatus_ERR("can't initialize signals");
|
||||||
if (_PyStatus_EXCEPTION(status)) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyTraceMalloc_Init(config->tracemalloc) < 0) {
|
if (_PyTraceMalloc_Init(config->tracemalloc) < 0) {
|
||||||
|
@ -1702,7 +1698,7 @@ Py_FinalizeEx(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable signal handling */
|
/* Disable signal handling */
|
||||||
PyOS_FiniInterrupts();
|
_PySignal_Fini();
|
||||||
|
|
||||||
/* Collect garbage. This may call finalizers; it's nice to call these
|
/* Collect garbage. This may call finalizers; it's nice to call these
|
||||||
* before all modules are destroyed.
|
* before all modules are destroyed.
|
||||||
|
@ -2730,25 +2726,6 @@ Py_Exit(int sts)
|
||||||
exit(sts);
|
exit(sts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyStatus
|
|
||||||
init_signals(PyThreadState *tstate)
|
|
||||||
{
|
|
||||||
#ifdef SIGPIPE
|
|
||||||
PyOS_setsig(SIGPIPE, SIG_IGN);
|
|
||||||
#endif
|
|
||||||
#ifdef SIGXFZ
|
|
||||||
PyOS_setsig(SIGXFZ, SIG_IGN);
|
|
||||||
#endif
|
|
||||||
#ifdef SIGXFSZ
|
|
||||||
PyOS_setsig(SIGXFSZ, SIG_IGN);
|
|
||||||
#endif
|
|
||||||
PyOS_InitInterrupts(); /* May imply init_signals() */
|
|
||||||
if (_PyErr_Occurred(tstate)) {
|
|
||||||
return _PyStatus_ERR("can't import signal");
|
|
||||||
}
|
|
||||||
return _PyStatus_OK();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.
|
/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue