gh-64783: Fix signal.NSIG value on FreeBSD (#91929)

Fix signal.NSIG value on FreeBSD to accept signal numbers greater
than 32, like signal.SIGRTMIN and signal.SIGRTMAX.

* Add Py_NSIG constant.
* Add pycore_signal.h internal header file.
* _Py_Sigset_Converter() now includes the range of valid signals in
  the error message.
This commit is contained in:
Victor Stinner
2022-04-26 00:13:31 +02:00
committed by GitHub
parent 61381d7da1
commit 20cc695286
11 changed files with 81 additions and 51 deletions

View File

@@ -2,6 +2,7 @@
#include "pycore_initconfig.h" // _PyStatus_ERR
#include "pycore_pyerrors.h" // _Py_DumpExtensionModules
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_signal.h" // Py_NSIG
#include "pycore_traceback.h" // _Py_DumpTracebackThreads
#include "frameobject.h"
@@ -115,19 +116,6 @@ typedef struct {
static user_signal_t *user_signals;
/* the following macros come from Python: Modules/signalmodule.c */
#ifndef NSIG
# if defined(_NSIG)
# define NSIG _NSIG /* For BSD/SysV */
# elif defined(_SIGMAX)
# define NSIG (_SIGMAX + 1) /* For QNX */
# elif defined(SIGMAX)
# define NSIG (SIGMAX + 1) /* For djgpp */
# else
# define NSIG 64 /* Use a reasonable default value */
# endif
#endif
static void faulthandler_user(int signum);
#endif /* FAULTHANDLER_USER */
@@ -896,7 +884,7 @@ check_signum(int signum)
return 0;
}
}
if (signum < 1 || NSIG <= signum) {
if (signum < 1 || Py_NSIG <= signum) {
PyErr_SetString(PyExc_ValueError, "signal number out of range");
return 0;
}
@@ -935,7 +923,7 @@ faulthandler_register_py(PyObject *self,
return NULL;
if (user_signals == NULL) {
user_signals = PyMem_Calloc(NSIG, sizeof(user_signal_t));
user_signals = PyMem_Calloc(Py_NSIG, sizeof(user_signal_t));
if (user_signals == NULL)
return PyErr_NoMemory();
}
@@ -1215,7 +1203,7 @@ faulthandler_traverse(PyObject *module, visitproc visit, void *arg)
Py_VISIT(thread.file);
#ifdef FAULTHANDLER_USER
if (user_signals != NULL) {
for (size_t signum=0; signum < NSIG; signum++)
for (size_t signum=0; signum < Py_NSIG; signum++)
Py_VISIT(user_signals[signum].file);
}
#endif
@@ -1416,7 +1404,7 @@ void _PyFaulthandler_Fini(void)
#ifdef FAULTHANDLER_USER
/* user */
if (user_signals != NULL) {
for (size_t signum=0; signum < NSIG; signum++) {
for (size_t signum=0; signum < Py_NSIG; signum++) {
faulthandler_unregister(&user_signals[signum], signum);
}
PyMem_Free(user_signals);