mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-81057: Move Signal-Related Globals to _PyRuntimeState (gh-100085)
https://github.com/python/cpython/issues/81057
This commit is contained in:
parent
53d9cd95cd
commit
5eb28bca9f
6 changed files with 82 additions and 69 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue