|
7 | 7 | #include "pycore_atomic.h" // _Py_atomic_int
|
8 | 8 | #include "pycore_call.h" // _PyObject_Call()
|
9 | 9 | #include "pycore_ceval.h" // _PyEval_SignalReceived()
|
| 10 | +#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS |
10 | 11 | #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
|
11 | 12 | #include "pycore_frame.h" // _PyInterpreterFrame
|
12 | 13 | #include "pycore_moduleobject.h" // _PyModule_GetState()
|
13 | 14 | #include "pycore_pyerrors.h" // _PyErr_SetString()
|
14 |
| -#include "pycore_pylifecycle.h" // NSIG |
15 | 15 | #include "pycore_pystate.h" // _PyThreadState_GET()
|
16 |
| -#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS |
| 16 | +#include "pycore_signal.h" // Py_NSIG |
17 | 17 |
|
18 | 18 | #ifndef MS_WINDOWS
|
19 | 19 | # include "posixmodule.h"
|
@@ -106,7 +106,7 @@ static volatile struct {
|
106 | 106 | * (even though it would probably be otherwise, anyway).
|
107 | 107 | */
|
108 | 108 | _Py_atomic_address func;
|
109 |
| -} Handlers[NSIG]; |
| 109 | +} Handlers[Py_NSIG]; |
110 | 110 |
|
111 | 111 | #ifdef MS_WINDOWS
|
112 | 112 | #define INVALID_FD ((SOCKET_T)-1)
|
@@ -542,7 +542,7 @@ signal_signal_impl(PyObject *module, int signalnum, PyObject *handler)
|
542 | 542 | "of the main interpreter");
|
543 | 543 | return NULL;
|
544 | 544 | }
|
545 |
| - if (signalnum < 1 || signalnum >= NSIG) { |
| 545 | + if (signalnum < 1 || signalnum >= Py_NSIG) { |
546 | 546 | _PyErr_SetString(tstate, PyExc_ValueError,
|
547 | 547 | "signal number out of range");
|
548 | 548 | return NULL;
|
@@ -601,7 +601,7 @@ signal_getsignal_impl(PyObject *module, int signalnum)
|
601 | 601 | /*[clinic end generated code: output=35b3e0e796fd555e input=ac23a00f19dfa509]*/
|
602 | 602 | {
|
603 | 603 | PyObject *old_handler;
|
604 |
| - if (signalnum < 1 || signalnum >= NSIG) { |
| 604 | + if (signalnum < 1 || signalnum >= Py_NSIG) { |
605 | 605 | PyErr_SetString(PyExc_ValueError,
|
606 | 606 | "signal number out of range");
|
607 | 607 | return NULL;
|
@@ -634,7 +634,7 @@ signal_strsignal_impl(PyObject *module, int signalnum)
|
634 | 634 | {
|
635 | 635 | const char *res;
|
636 | 636 |
|
637 |
| - if (signalnum < 1 || signalnum >= NSIG) { |
| 637 | + if (signalnum < 1 || signalnum >= Py_NSIG) { |
638 | 638 | PyErr_SetString(PyExc_ValueError,
|
639 | 639 | "signal number out of range");
|
640 | 640 | return NULL;
|
@@ -712,7 +712,7 @@ static PyObject *
|
712 | 712 | signal_siginterrupt_impl(PyObject *module, int signalnum, int flag)
|
713 | 713 | /*[clinic end generated code: output=063816243d85dd19 input=4160acacca3e2099]*/
|
714 | 714 | {
|
715 |
| - if (signalnum < 1 || signalnum >= NSIG) { |
| 715 | + if (signalnum < 1 || signalnum >= Py_NSIG) { |
716 | 716 | PyErr_SetString(PyExc_ValueError,
|
717 | 717 | "signal number out of range");
|
718 | 718 | return NULL;
|
@@ -964,7 +964,7 @@ sigset_to_set(sigset_t mask)
|
964 | 964 | if (result == NULL)
|
965 | 965 | return NULL;
|
966 | 966 |
|
967 |
| - for (sig = 1; sig < NSIG; sig++) { |
| 967 | + for (sig = 1; sig < Py_NSIG; sig++) { |
968 | 968 | if (sigismember(&mask, sig) != 1)
|
969 | 969 | continue;
|
970 | 970 |
|
@@ -1439,13 +1439,15 @@ the first is the signal number, the second is the interrupted stack frame.");
|
1439 | 1439 | static int
|
1440 | 1440 | signal_add_constants(PyObject *module)
|
1441 | 1441 | {
|
| 1442 | + if (PyModule_AddIntConstant(module, "NSIG", Py_NSIG) < 0) { |
| 1443 | + return -1; |
| 1444 | + } |
| 1445 | + |
1442 | 1446 | #define ADD_INT_MACRO(macro) \
|
1443 | 1447 | if (PyModule_AddIntConstant(module, #macro, macro) < 0) { \
|
1444 | 1448 | return -1; \
|
1445 | 1449 | }
|
1446 | 1450 |
|
1447 |
| - ADD_INT_MACRO(NSIG); |
1448 |
| - |
1449 | 1451 | // SIG_xxx pthread_sigmask() constants
|
1450 | 1452 | #ifdef SIG_BLOCK
|
1451 | 1453 | ADD_INT_MACRO(SIG_BLOCK);
|
@@ -1605,7 +1607,7 @@ static int
|
1605 | 1607 | signal_get_set_handlers(signal_state_t *state, PyObject *mod_dict)
|
1606 | 1608 | {
|
1607 | 1609 | // Get signal handlers
|
1608 |
| - for (int signum = 1; signum < NSIG; signum++) { |
| 1610 | + for (int signum = 1; signum < Py_NSIG; signum++) { |
1609 | 1611 | void (*c_handler)(int) = PyOS_getsig(signum);
|
1610 | 1612 | PyObject *func;
|
1611 | 1613 | if (c_handler == SIG_DFL) {
|
@@ -1762,7 +1764,7 @@ _PySignal_Fini(void)
|
1762 | 1764 | signal_state_t *state = &signal_global_state;
|
1763 | 1765 |
|
1764 | 1766 | // Restore default signals and clear handlers
|
1765 |
| - for (int signum = 1; signum < NSIG; signum++) { |
| 1767 | + for (int signum = 1; signum < Py_NSIG; signum++) { |
1766 | 1768 | PyObject *func = get_handler(signum);
|
1767 | 1769 | _Py_atomic_store_relaxed(&Handlers[signum].tripped, 0);
|
1768 | 1770 | set_handler(signum, NULL);
|
@@ -1828,7 +1830,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
|
1828 | 1830 |
|
1829 | 1831 | _PyInterpreterFrame *frame = tstate->cframe->current_frame;
|
1830 | 1832 | signal_state_t *state = &signal_global_state;
|
1831 |
| - for (int i = 1; i < NSIG; i++) { |
| 1833 | + for (int i = 1; i < Py_NSIG; i++) { |
1832 | 1834 | if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) {
|
1833 | 1835 | continue;
|
1834 | 1836 | }
|
@@ -1905,7 +1907,7 @@ _PyErr_CheckSignals(void)
|
1905 | 1907 | int
|
1906 | 1908 | PyErr_SetInterruptEx(int signum)
|
1907 | 1909 | {
|
1908 |
| - if (signum < 1 || signum >= NSIG) { |
| 1910 | + if (signum < 1 || signum >= Py_NSIG) { |
1909 | 1911 | return -1;
|
1910 | 1912 | }
|
1911 | 1913 |
|
@@ -1995,7 +1997,7 @@ _PySignal_Init(int install_signal_handlers)
|
1995 | 1997 | }
|
1996 | 1998 | #endif
|
1997 | 1999 |
|
1998 |
| - for (int signum = 1; signum < NSIG; signum++) { |
| 2000 | + for (int signum = 1; signum < Py_NSIG; signum++) { |
1999 | 2001 | _Py_atomic_store_relaxed(&Handlers[signum].tripped, 0);
|
2000 | 2002 | }
|
2001 | 2003 |
|
@@ -2045,7 +2047,7 @@ _clear_pending_signals(void)
|
2045 | 2047 | }
|
2046 | 2048 |
|
2047 | 2049 | _Py_atomic_store(&is_tripped, 0);
|
2048 |
| - for (int i = 1; i < NSIG; ++i) { |
| 2050 | + for (int i = 1; i < Py_NSIG; ++i) { |
2049 | 2051 | _Py_atomic_store_relaxed(&Handlers[i].tripped, 0);
|
2050 | 2052 | }
|
2051 | 2053 | }
|
|
0 commit comments