mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-46417: signal uses PyStructSequence_NewType() (GH-30735)
The signal module now creates its struct_siginfo type as a heap type using PyStructSequence_NewType(), rather than using a static type. Add 'siginfo_type' member to the global signal_state_t structure.
This commit is contained in:
parent
1781d55eb3
commit
d013b24135
1 changed files with 9 additions and 7 deletions
|
@ -136,6 +136,7 @@ typedef struct {
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
HANDLE sigint_event;
|
HANDLE sigint_event;
|
||||||
#endif
|
#endif
|
||||||
|
PyTypeObject *siginfo_type;
|
||||||
} signal_state_t;
|
} signal_state_t;
|
||||||
|
|
||||||
// State shared by all Python interpreters
|
// State shared by all Python interpreters
|
||||||
|
@ -1136,12 +1137,13 @@ static PyStructSequence_Desc struct_siginfo_desc = {
|
||||||
7 /* n_in_sequence */
|
7 /* n_in_sequence */
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyTypeObject SiginfoType;
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
fill_siginfo(siginfo_t *si)
|
fill_siginfo(siginfo_t *si)
|
||||||
{
|
{
|
||||||
PyObject *result = PyStructSequence_New(&SiginfoType);
|
signal_state_t *state = &signal_global_state;
|
||||||
|
|
||||||
|
PyObject *result = PyStructSequence_New(state->siginfo_type);
|
||||||
if (!result)
|
if (!result)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1660,7 +1662,7 @@ signal_module_exec(PyObject *m)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
|
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
|
||||||
if (PyModule_AddType(m, &SiginfoType) < 0) {
|
if (PyModule_AddType(m, state->siginfo_type) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1758,6 +1760,7 @@ _PySignal_Fini(void)
|
||||||
|
|
||||||
Py_CLEAR(state->default_handler);
|
Py_CLEAR(state->default_handler);
|
||||||
Py_CLEAR(state->ignore_handler);
|
Py_CLEAR(state->ignore_handler);
|
||||||
|
Py_CLEAR(state->siginfo_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1966,10 +1969,9 @@ _PySignal_Init(int install_signal_handlers)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
|
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
|
||||||
if (SiginfoType.tp_name == NULL) {
|
state->siginfo_type = PyStructSequence_NewType(&struct_siginfo_desc);
|
||||||
if (PyStructSequence_InitType2(&SiginfoType, &struct_siginfo_desc) < 0) {
|
if (state->siginfo_type == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue