Skip to content

Commit 32cfc50

Browse files
Move signalmodule.c:signal_global_state to _PyRuntimeState.
1 parent d164289 commit 32cfc50

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Include/internal/pycore_signal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ struct _signals_runtime_state {
6363
/* Speed up sigcheck() when none tripped */
6464
_Py_atomic_int is_tripped;
6565

66+
/* These objects necessarily belong to the main interpreter. */
67+
PyObject *default_handler;
68+
PyObject *ignore_handler;
69+
#ifdef MS_WINDOWS
70+
HANDLE sigint_event;
71+
#endif
72+
6673
/* True if the main interpreter thread exited due to an unhandled
6774
* KeyboardInterrupt exception, suggesting the user pressed ^C. */
6875
int unhandled_keyboard_interrupt;

Modules/signalmodule.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,9 @@ class sigset_t_converter(CConverter):
104104
#define wakeup _PyRuntime.signals.wakeup
105105
#define is_tripped _PyRuntime.signals.is_tripped
106106

107-
typedef struct {
108-
PyObject *default_handler;
109-
PyObject *ignore_handler;
110-
#ifdef MS_WINDOWS
111-
HANDLE sigint_event;
112-
#endif
113-
} signal_state_t;
114-
115107
// State shared by all Python interpreters
116-
static signal_state_t signal_global_state = {0};
108+
typedef struct _signals_runtime_state signal_state_t;
109+
#define signal_global_state _PyRuntime.signals
117110

118111
#if defined(HAVE_GETITIMER) || defined(HAVE_SETITIMER)
119112
# define PYHAVE_ITIMER_ERROR
@@ -1627,6 +1620,8 @@ signal_module_exec(PyObject *m)
16271620
signal_state_t *state = &signal_global_state;
16281621
_signal_module_state *modstate = get_signal_state(m);
16291622

1623+
// XXX For proper isolation, these values must be guaranteed
1624+
// to be effectively const (e.g. immortal).
16301625
modstate->default_handler = state->default_handler; // borrowed ref
16311626
modstate->ignore_handler = state->ignore_handler; // borrowed ref
16321627

Tools/c-analyzer/cpython/globals-to-fix.tsv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ Modules/_tracemalloc.c - tracemalloc_traces -
408408
Modules/_tracemalloc.c - tracemalloc_domains -
409409
Modules/_tracemalloc.c - tracemalloc_reentrant_key -
410410
Modules/faulthandler.c faulthandler_dump_traceback reentrant -
411-
Modules/signalmodule.c - signal_global_state -
412411

413412

414413
##################################

0 commit comments

Comments
 (0)