]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41146: Convert signal.default_int_handler() to Argument Clinic (GH-21197)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 12 Jul 2020 16:15:20 +0000 (19:15 +0300)
committerGitHub <noreply@github.com>
Sun, 12 Jul 2020 16:15:20 +0000 (19:15 +0300)
Modules/clinic/signalmodule.c.h
Modules/signalmodule.c

index 33a278e488f9439bcb9fe208bc4190fb991b4e51..4713bab7486acb9fda93a776cbb54da8e715172c 100644 (file)
@@ -2,6 +2,42 @@
 preserve
 [clinic start generated code]*/
 
+PyDoc_STRVAR(signal_default_int_handler__doc__,
+"default_int_handler($module, signalnum, frame, /)\n"
+"--\n"
+"\n"
+"The default handler for SIGINT installed by Python.\n"
+"\n"
+"It raises KeyboardInterrupt.");
+
+#define SIGNAL_DEFAULT_INT_HANDLER_METHODDEF    \
+    {"default_int_handler", (PyCFunction)(void(*)(void))signal_default_int_handler, METH_FASTCALL, signal_default_int_handler__doc__},
+
+static PyObject *
+signal_default_int_handler_impl(PyObject *module, int signalnum,
+                                PyObject *frame);
+
+static PyObject *
+signal_default_int_handler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    int signalnum;
+    PyObject *frame;
+
+    if (!_PyArg_CheckPositional("default_int_handler", nargs, 2, 2)) {
+        goto exit;
+    }
+    signalnum = _PyLong_AsInt(args[0]);
+    if (signalnum == -1 && PyErr_Occurred()) {
+        goto exit;
+    }
+    frame = args[1];
+    return_value = signal_default_int_handler_impl(module, signalnum, frame);
+
+exit:
+    return return_value;
+}
+
 #if defined(HAVE_ALARM)
 
 PyDoc_STRVAR(signal_alarm__doc__,
@@ -662,4 +698,4 @@ exit:
 #ifndef SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
     #define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
 #endif /* !defined(SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF) */
-/*[clinic end generated code: output=dff93c869101f043 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=59c33f0af42aebb5 input=a9049054013a1b77]*/
index ef3536a210b04ce40bc0acfc5d652483bb3a0476..7bc1b535e6e2caae8f382e30e84f55f5d610c552 100644 (file)
@@ -189,19 +189,26 @@ itimer_retval(struct itimerval *iv)
 }
 #endif
 
+/*[clinic input]
+signal.default_int_handler
+    signalnum: int
+    frame: object
+    /
+
+The default handler for SIGINT installed by Python.
+
+It raises KeyboardInterrupt.
+[clinic start generated code]*/
+
 static PyObject *
-signal_default_int_handler(PyObject *self, PyObject *args)
+signal_default_int_handler_impl(PyObject *module, int signalnum,
+                                PyObject *frame)
+/*[clinic end generated code: output=bb11c2eb115ace4e input=efcd4a56a207acfd]*/
 {
     PyErr_SetNone(PyExc_KeyboardInterrupt);
     return NULL;
 }
 
-PyDoc_STRVAR(default_int_handler_doc,
-"default_int_handler(...)\n\
-\n\
-The default handler for SIGINT installed by Python.\n\
-It raises KeyboardInterrupt.");
-
 
 static int
 report_wakeup_write_error(void *data)
@@ -1297,7 +1304,7 @@ signal_pidfd_send_signal_impl(PyObject *module, int pidfd, int signalnum,
 /* List of functions defined in the module -- some of the methoddefs are
    defined to nothing if the corresponding C function is not available. */
 static PyMethodDef signal_methods[] = {
-    {"default_int_handler", signal_default_int_handler, METH_VARARGS, default_int_handler_doc},
+    SIGNAL_DEFAULT_INT_HANDLER_METHODDEF
     SIGNAL_ALARM_METHODDEF
     SIGNAL_SETITIMER_METHODDEF
     SIGNAL_GETITIMER_METHODDEF