summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-12-12 23:50:19 (GMT)
committerGitHub <noreply@github.com>2022-12-12 23:50:19 (GMT)
commit5eb28bca9fc963607189e3b3e1403f341dbf640a (patch)
tree1792f79a0b49dd91a5193bba68f427a0410341fa /Include
parent53d9cd95cd91f1a291a3923acb95e0e86942291a (diff)
downloadcpython-5eb28bca9fc963607189e3b3e1403f341dbf640a.zip
cpython-5eb28bca9fc963607189e3b3e1403f341dbf640a.tar.gz
cpython-5eb28bca9fc963607189e3b3e1403f341dbf640a.tar.bz2
gh-81057: Move Signal-Related Globals to _PyRuntimeState (gh-100085)
https://github.com/python/cpython/issues/81057
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_runtime.h7
-rw-r--r--Include/internal/pycore_runtime_init.h1
-rw-r--r--Include/internal/pycore_signal.h63
3 files changed, 66 insertions, 5 deletions
diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h
index b9ed8f5..92ed459 100644
--- a/Include/internal/pycore_runtime.h
+++ b/Include/internal/pycore_runtime.h
@@ -23,6 +23,7 @@ extern "C" {
#include "pycore_pyhash.h" // struct pyhash_runtime_state
#include "pycore_pythread.h" // struct _pythread_runtime_state
#include "pycore_obmalloc.h" // struct obmalloc_state
+#include "pycore_signal.h" // struct _signals_runtime_state
#include "pycore_time.h" // struct _time_runtime_state
#include "pycore_tracemalloc.h" // struct _tracemalloc_runtime_state
#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
@@ -93,13 +94,9 @@ typedef struct pyruntimestate {
struct _pymem_allocators allocators;
struct _obmalloc_state obmalloc;
struct pyhash_runtime_state pyhash_state;
- struct {
- /* True if the main interpreter thread exited due to an unhandled
- * KeyboardInterrupt exception, suggesting the user pressed ^C. */
- int unhandled_keyboard_interrupt;
- } signals;
struct _time_runtime_state time;
struct _pythread_runtime_state threads;
+ struct _signals_runtime_state signals;
struct pyinterpreters {
PyThread_type_lock mutex;
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index 9677a72..1431096 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -26,6 +26,7 @@ extern "C" {
}, \
.obmalloc = _obmalloc_state_INIT(runtime.obmalloc), \
.pyhash_state = pyhash_state_INIT, \
+ .signals = _signals_RUNTIME_INIT, \
.interpreters = { \
/* This prevents interpreters from getting created \
until _PyInterpreterState_Enable() is called. */ \
diff --git a/Include/internal/pycore_signal.h b/Include/internal/pycore_signal.h
index b921dd1..ca3f69d 100644
--- a/Include/internal/pycore_signal.h
+++ b/Include/internal/pycore_signal.h
@@ -10,8 +10,11 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
+#include "pycore_atomic.h" // _Py_atomic_address
+
#include <signal.h> // NSIG
+
#ifdef _SIG_MAXSIG
// gh-91145: On FreeBSD, <signal.h> defines NSIG as 32: it doesn't include
// realtime signals: [SIGRTMIN,SIGRTMAX]. Use _SIG_MAXSIG instead. For
@@ -29,6 +32,66 @@ extern "C" {
# define Py_NSIG 64 // Use a reasonable default value
#endif
+#define INVALID_FD (-1)
+
+struct _signals_runtime_state {
+ volatile struct {
+ _Py_atomic_int tripped;
+ /* func is atomic to ensure that PyErr_SetInterrupt is async-signal-safe
+ * (even though it would probably be otherwise, anyway).
+ */
+ _Py_atomic_address func;
+ } handlers[Py_NSIG];
+
+ volatile struct {
+#ifdef MS_WINDOWS
+ /* This would be "SOCKET fd" if <winsock2.h> were always included.
+ It isn't so we must cast to SOCKET where appropriate. */
+ volatile int fd;
+#elif defined(__VXWORKS__)
+ int fd;
+#else
+ sig_atomic_t fd;
+#endif
+
+ int warn_on_full_buffer;
+#ifdef MS_WINDOWS
+ int use_send;
+#endif
+ } wakeup;
+
+ /* Speed up sigcheck() when none tripped */
+ _Py_atomic_int is_tripped;
+
+ /* These objects necessarily belong to the main interpreter. */
+ PyObject *default_handler;
+ PyObject *ignore_handler;
+
+#ifdef MS_WINDOWS
+ /* This would be "HANDLE sigint_event" if <windows.h> were always included.
+ It isn't so we must cast to HANDLE everywhere "sigint_event" is used. */
+ void *sigint_event;
+#endif
+
+ /* True if the main interpreter thread exited due to an unhandled
+ * KeyboardInterrupt exception, suggesting the user pressed ^C. */
+ int unhandled_keyboard_interrupt;
+};
+
+#ifdef MS_WINDOWS
+# define _signals_WAKEUP_INIT \
+ {.fd = INVALID_FD, .warn_on_full_buffer = 1, .use_send = 0}
+#else
+# define _signals_WAKEUP_INIT \
+ {.fd = INVALID_FD, .warn_on_full_buffer = 1}
+#endif
+
+#define _signals_RUNTIME_INIT \
+ { \
+ .wakeup = _signals_WAKEUP_INIT, \
+ }
+
+
#ifdef __cplusplus
}
#endif