mirror of https://github.com/python/cpython
Clean up the fix to #9324 with some of the suggestions raised on python-dev
in response to the original checkin. Move the validation from the original loop into a switch statement, and adjust a platform check in the tests.
This commit is contained in:
parent
92f87f7c49
commit
c734b312cb
|
@ -9,9 +9,8 @@ import subprocess
|
||||||
import traceback
|
import traceback
|
||||||
import sys, os, time, errno
|
import sys, os, time, errno
|
||||||
|
|
||||||
if sys.platform == 'os2' or sys.platform == 'riscos':
|
if sys.platform in ('os2', 'riscos'):
|
||||||
raise unittest.SkipTest("Can't test signal on %s" % \
|
raise unittest.SkipTest("Can't test signal on %s" % sys.platform)
|
||||||
sys.platform)
|
|
||||||
|
|
||||||
|
|
||||||
class HandlerBCalled(Exception):
|
class HandlerBCalled(Exception):
|
||||||
|
|
|
@ -255,21 +255,20 @@ signal_signal(PyObject *self, PyObject *args)
|
||||||
int sig_num;
|
int sig_num;
|
||||||
PyObject *old_handler;
|
PyObject *old_handler;
|
||||||
void (*func)(int);
|
void (*func)(int);
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
int cur_sig, num_valid_sigs = 6;
|
|
||||||
static int valid_sigs[] = {SIGABRT, SIGFPE, SIGILL, SIGINT,
|
|
||||||
SIGSEGV, SIGTERM};
|
|
||||||
BOOL valid_sig = FALSE;
|
|
||||||
#endif
|
|
||||||
if (!PyArg_ParseTuple(args, "iO:signal", &sig_num, &obj))
|
if (!PyArg_ParseTuple(args, "iO:signal", &sig_num, &obj))
|
||||||
return NULL;
|
return NULL;
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
/* Validate that sig_num is one of the allowable signals */
|
/* Validate that sig_num is one of the allowable signals */
|
||||||
for (cur_sig = 0; cur_sig < num_valid_sigs; cur_sig++)
|
switch (sig_num) {
|
||||||
valid_sig |= (sig_num == valid_sigs[cur_sig]);
|
case SIGABRT: break;
|
||||||
if (!valid_sig) {
|
case SIGFPE: break;
|
||||||
PyErr_SetString(PyExc_ValueError, "signal number out of range");
|
case SIGILL: break;
|
||||||
return NULL;
|
case SIGINT: break;
|
||||||
|
case SIGSEGV: break;
|
||||||
|
case SIGTERM: break;
|
||||||
|
default:
|
||||||
|
PyErr_SetString(PyExc_ValueError, "invalid signal value");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef WITH_THREAD
|
#ifdef WITH_THREAD
|
||||||
|
|
Loading…
Reference in New Issue