Skip to content

Commit d013b24

Browse files
authored
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.
1 parent 1781d55 commit d013b24

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Modules/signalmodule.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ typedef struct {
136136
#ifdef MS_WINDOWS
137137
HANDLE sigint_event;
138138
#endif
139+
PyTypeObject *siginfo_type;
139140
} signal_state_t;
140141

141142
// State shared by all Python interpreters
@@ -1136,12 +1137,13 @@ static PyStructSequence_Desc struct_siginfo_desc = {
11361137
7 /* n_in_sequence */
11371138
};
11381139

1139-
static PyTypeObject SiginfoType;
11401140

11411141
static PyObject *
11421142
fill_siginfo(siginfo_t *si)
11431143
{
1144-
PyObject *result = PyStructSequence_New(&SiginfoType);
1144+
signal_state_t *state = &signal_global_state;
1145+
1146+
PyObject *result = PyStructSequence_New(state->siginfo_type);
11451147
if (!result)
11461148
return NULL;
11471149

@@ -1660,7 +1662,7 @@ signal_module_exec(PyObject *m)
16601662
}
16611663
#endif
16621664
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
1663-
if (PyModule_AddType(m, &SiginfoType) < 0) {
1665+
if (PyModule_AddType(m, state->siginfo_type) < 0) {
16641666
return -1;
16651667
}
16661668
#endif
@@ -1758,6 +1760,7 @@ _PySignal_Fini(void)
17581760

17591761
Py_CLEAR(state->default_handler);
17601762
Py_CLEAR(state->ignore_handler);
1763+
Py_CLEAR(state->siginfo_type);
17611764
}
17621765

17631766

@@ -1966,10 +1969,9 @@ _PySignal_Init(int install_signal_handlers)
19661969
#endif
19671970

19681971
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
1969-
if (SiginfoType.tp_name == NULL) {
1970-
if (PyStructSequence_InitType2(&SiginfoType, &struct_siginfo_desc) < 0) {
1971-
return -1;
1972-
}
1972+
state->siginfo_type = PyStructSequence_NewType(&struct_siginfo_desc);
1973+
if (state->siginfo_type == NULL) {
1974+
return -1;
19731975
}
19741976
#endif
19751977

0 commit comments

Comments
 (0)