diff options
author | Vladimir Matveev <v2matveev@outlook.com> | 2019-01-08 09:58:25 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-01-08 09:58:25 (GMT) |
commit | c24c6c2c9357da99961bf257078240529181daf3 (patch) | |
tree | 552b9c627f21770d971d26f0d7d38e8a1b58ea02 /Modules | |
parent | e61cc481e02b758c8d8289163102c236d0658a55 (diff) | |
download | cpython-c24c6c2c9357da99961bf257078240529181daf3.zip cpython-c24c6c2c9357da99961bf257078240529181daf3.tar.gz cpython-c24c6c2c9357da99961bf257078240529181daf3.tar.bz2 |
bpo-35568: add 'raise_signal' function (GH-11335)
As in title, expose C `raise` function as `raise_function` in `signal` module. Also drop existing `raise_signal` in `_testcapi` module and replace all usages with new function.
https://bugs.python.org/issue35568
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 21 | ||||
-rw-r--r-- | Modules/clinic/signalmodule.c.h | 35 | ||||
-rw-r--r-- | Modules/signalmodule.c | 26 |
3 files changed, 60 insertions, 22 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 4933ef3..85810f3 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3859,25 +3859,6 @@ exit: return res; } -static PyObject* -test_raise_signal(PyObject* self, PyObject *args) -{ - int signum, err; - - if (!PyArg_ParseTuple(args, "i:raise_signal", &signum)) { - return NULL; - } - - err = raise(signum); - if (err) - return PyErr_SetFromErrno(PyExc_OSError); - - if (PyErr_CheckSignals() < 0) - return NULL; - - Py_RETURN_NONE; -} - /* marshal */ static PyObject* @@ -4908,8 +4889,6 @@ static PyMethodDef TestMethods[] = { {"docstring_with_signature_with_defaults", (PyCFunction)test_with_docstring, METH_NOARGS, docstring_with_signature_with_defaults}, - {"raise_signal", - (PyCFunction)test_raise_signal, METH_VARARGS}, {"call_in_temporary_c_thread", call_in_temporary_c_thread, METH_O, PyDoc_STR("set_error_class(error_class) -> None")}, {"pymarshal_write_long_to_file", diff --git a/Modules/clinic/signalmodule.c.h b/Modules/clinic/signalmodule.c.h index 6745f45..f374226 100644 --- a/Modules/clinic/signalmodule.c.h +++ b/Modules/clinic/signalmodule.c.h @@ -66,6 +66,39 @@ signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* defined(HAVE_PAUSE) */ +PyDoc_STRVAR(signal_raise_signal__doc__, +"raise_signal($module, signalnum, /)\n" +"--\n" +"\n" +"Send a signal to the executing process."); + +#define SIGNAL_RAISE_SIGNAL_METHODDEF \ + {"raise_signal", (PyCFunction)signal_raise_signal, METH_O, signal_raise_signal__doc__}, + +static PyObject * +signal_raise_signal_impl(PyObject *module, int signalnum); + +static PyObject * +signal_raise_signal(PyObject *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int signalnum; + + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + signalnum = _PyLong_AsInt(arg); + if (signalnum == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = signal_raise_signal_impl(module, signalnum); + +exit: + return return_value; +} + PyDoc_STRVAR(signal_signal__doc__, "signal($module, signalnum, handler, /)\n" "--\n" @@ -558,4 +591,4 @@ exit: #ifndef SIGNAL_PTHREAD_KILL_METHODDEF #define SIGNAL_PTHREAD_KILL_METHODDEF #endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */ -/*[clinic end generated code: output=4ed8c36860f9f577 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=365db4e807c26d4e input=a9049054013a1b77]*/ diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 52ab4e9..4f8f71a 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -390,6 +390,31 @@ signal_pause_impl(PyObject *module) #endif +/*[clinic input] +signal.raise_signal + + signalnum: int + / + +Send a signal to the executing process. +[clinic start generated code]*/ + +static PyObject * +signal_raise_signal_impl(PyObject *module, int signalnum) +/*[clinic end generated code: output=e2b014220aa6111d input=e90c0f9a42358de6]*/ +{ + int err; + Py_BEGIN_ALLOW_THREADS + _Py_BEGIN_SUPPRESS_IPH + err = raise(signalnum); + _Py_END_SUPPRESS_IPH + Py_END_ALLOW_THREADS + + if (err) { + return PyErr_SetFromErrno(PyExc_OSError); + } + Py_RETURN_NONE; +} /*[clinic input] signal.signal @@ -1208,6 +1233,7 @@ static PyMethodDef signal_methods[] = { SIGNAL_SETITIMER_METHODDEF SIGNAL_GETITIMER_METHODDEF SIGNAL_SIGNAL_METHODDEF + SIGNAL_RAISE_SIGNAL_METHODDEF SIGNAL_STRSIGNAL_METHODDEF SIGNAL_GETSIGNAL_METHODDEF {"set_wakeup_fd", (PyCFunction)(void(*)(void))signal_set_wakeup_fd, METH_VARARGS | METH_KEYWORDS, set_wakeup_fd_doc}, |