Skip to content

Commit 6c6a153

Browse files
authored
bpo-46417: signal: move siginfo_type to the module state (GH-30964)
1 parent ace0aa2 commit 6c6a153

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

Modules/signalmodule.c

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

142141
// State shared by all Python interpreters
@@ -152,6 +151,7 @@ typedef struct {
152151
#ifdef PYHAVE_ITIMER_ERROR
153152
PyObject *itimer_error;
154153
#endif
154+
PyTypeObject *siginfo_type;
155155
} _signal_module_state;
156156

157157

@@ -1139,10 +1139,8 @@ static PyStructSequence_Desc struct_siginfo_desc = {
11391139

11401140

11411141
static PyObject *
1142-
fill_siginfo(siginfo_t *si)
1142+
fill_siginfo(_signal_module_state *state, siginfo_t *si)
11431143
{
1144-
signal_state_t *state = &signal_global_state;
1145-
11461144
PyObject *result = PyStructSequence_New(state->siginfo_type);
11471145
if (!result)
11481146
return NULL;
@@ -1206,7 +1204,8 @@ signal_sigwaitinfo_impl(PyObject *module, sigset_t sigset)
12061204
if (err == -1)
12071205
return (!async_err) ? PyErr_SetFromErrno(PyExc_OSError) : NULL;
12081206

1209-
return fill_siginfo(&si);
1207+
_signal_module_state *state = get_signal_state(module);
1208+
return fill_siginfo(state, &si);
12101209
}
12111210

12121211
#endif /* #ifdef HAVE_SIGWAITINFO */
@@ -1274,7 +1273,8 @@ signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
12741273
}
12751274
} while (1);
12761275

1277-
return fill_siginfo(&si);
1276+
_signal_module_state *state = get_signal_state(module);
1277+
return fill_siginfo(state, &si);
12781278
}
12791279

12801280
#endif /* #ifdef HAVE_SIGTIMEDWAIT */
@@ -1661,8 +1661,15 @@ signal_module_exec(PyObject *m)
16611661
return -1;
16621662
}
16631663
#endif
1664+
1665+
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
1666+
modstate->siginfo_type = PyStructSequence_NewType(&struct_siginfo_desc);
1667+
if (modstate->siginfo_type == NULL) {
1668+
return -1;
1669+
}
1670+
#endif
16641671
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
1665-
if (PyModule_AddType(m, state->siginfo_type) < 0) {
1672+
if (PyModule_AddType(m, modstate->siginfo_type) < 0) {
16661673
return -1;
16671674
}
16681675
#endif
@@ -1683,16 +1690,18 @@ signal_module_exec(PyObject *m)
16831690
static int
16841691
_signal_module_traverse(PyObject *module, visitproc visit, void *arg)
16851692
{
1686-
_signal_module_state *modstate = get_signal_state(module);
1687-
Py_VISIT(modstate->itimer_error);
1693+
_signal_module_state *state = get_signal_state(module);
1694+
Py_VISIT(state->itimer_error);
1695+
Py_VISIT(state->siginfo_type);
16881696
return 0;
16891697
}
16901698

16911699
static int
16921700
_signal_module_clear(PyObject *module)
16931701
{
1694-
_signal_module_state *modstate = get_signal_state(module);
1695-
Py_CLEAR(modstate->itimer_error);
1702+
_signal_module_state *state = get_signal_state(module);
1703+
Py_CLEAR(state->itimer_error);
1704+
Py_CLEAR(state->siginfo_type);
16961705
return 0;
16971706
}
16981707

@@ -1760,7 +1769,6 @@ _PySignal_Fini(void)
17601769

17611770
Py_CLEAR(state->default_handler);
17621771
Py_CLEAR(state->ignore_handler);
1763-
Py_CLEAR(state->siginfo_type);
17641772
}
17651773

17661774

@@ -1968,13 +1976,6 @@ _PySignal_Init(int install_signal_handlers)
19681976
}
19691977
#endif
19701978

1971-
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
1972-
state->siginfo_type = PyStructSequence_NewType(&struct_siginfo_desc);
1973-
if (state->siginfo_type == NULL) {
1974-
return -1;
1975-
}
1976-
#endif
1977-
19781979
for (int signum = 1; signum < NSIG; signum++) {
19791980
_Py_atomic_store_relaxed(&Handlers[signum].tripped, 0);
19801981
}

0 commit comments

Comments
 (0)