[Python-checkins] gh-104469: Convert _testcapi/exceptions to use AC (gh-104502)

corona10 webhook-mailer at python.org
Sun May 21 05:40:02 EDT 2023


https://github.com/python/cpython/commit/2e91c7e62609ef405901dd5c4cb9d5aa794591ab
commit: 2e91c7e62609ef405901dd5c4cb9d5aa794591ab
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2023-05-21T18:39:45+09:00
summary:

gh-104469: Convert _testcapi/exceptions to use AC (gh-104502)

files:
A Modules/_testcapi/clinic/exceptions.c.h
M Lib/test/test_capi/test_exceptions.py
M Lib/test/test_faulthandler.py
M Modules/_testcapi/exceptions.c

diff --git a/Lib/test/test_capi/test_exceptions.py b/Lib/test/test_capi/test_exceptions.py
index b1c1a61e2068..1081f40b6981 100644
--- a/Lib/test/test_capi/test_exceptions.py
+++ b/Lib/test/test_capi/test_exceptions.py
@@ -66,7 +66,7 @@ def check_fatal_error(self, code, expected, not_expected=()):
             rc, out, err = assert_python_failure('-sSI', '-c', code)
 
         err = decode_stderr(err)
-        self.assertIn('Fatal Python error: test_fatal_error: MESSAGE\n',
+        self.assertIn('Fatal Python error: _testcapi_fatal_error_impl: MESSAGE\n',
                       err)
 
         match = re.search(r'^Extension modules:(.*) \(total: ([0-9]+)\)$',
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index 8d106daaf652..2e97de592712 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -270,7 +270,7 @@ def check_fatal_error_func(self, release_gil):
                 """,
                 2,
                 'xyz',
-                func='test_fatal_error',
+                func='_testcapi_fatal_error_impl',
                 py_fatal_error=True)
 
     def test_fatal_error(self):
diff --git a/Modules/_testcapi/clinic/exceptions.c.h b/Modules/_testcapi/clinic/exceptions.c.h
new file mode 100644
index 000000000000..2cc4ef3dc0d4
--- /dev/null
+++ b/Modules/_testcapi/clinic/exceptions.c.h
@@ -0,0 +1,398 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+#  include "pycore_gc.h"            // PyGC_Head
+#  include "pycore_runtime.h"       // _Py_ID()
+#endif
+
+
+PyDoc_STRVAR(_testcapi_err_set_raised__doc__,
+"err_set_raised($module, exception, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_ERR_SET_RAISED_METHODDEF    \
+    {"err_set_raised", (PyCFunction)_testcapi_err_set_raised, METH_O, _testcapi_err_set_raised__doc__},
+
+PyDoc_STRVAR(_testcapi_exception_print__doc__,
+"exception_print($module, exception, legacy=False, /)\n"
+"--\n"
+"\n"
+"To test the format of exceptions as printed out.");
+
+#define _TESTCAPI_EXCEPTION_PRINT_METHODDEF    \
+    {"exception_print", _PyCFunction_CAST(_testcapi_exception_print), METH_FASTCALL, _testcapi_exception_print__doc__},
+
+static PyObject *
+_testcapi_exception_print_impl(PyObject *module, PyObject *exc, int legacy);
+
+static PyObject *
+_testcapi_exception_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *exc;
+    int legacy = 0;
+
+    if (!_PyArg_CheckPositional("exception_print", nargs, 1, 2)) {
+        goto exit;
+    }
+    exc = args[0];
+    if (nargs < 2) {
+        goto skip_optional;
+    }
+    legacy = PyObject_IsTrue(args[1]);
+    if (legacy < 0) {
+        goto exit;
+    }
+skip_optional:
+    return_value = _testcapi_exception_print_impl(module, exc, legacy);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_make_exception_with_doc__doc__,
+"make_exception_with_doc($module, /, name, doc=<unrepresentable>,\n"
+"                        base=<unrepresentable>, dict=<unrepresentable>)\n"
+"--\n"
+"\n"
+"Test PyErr_NewExceptionWithDoc (also exercise PyErr_NewException). Run via Lib/test/test_exceptions.py");
+
+#define _TESTCAPI_MAKE_EXCEPTION_WITH_DOC_METHODDEF    \
+    {"make_exception_with_doc", _PyCFunction_CAST(_testcapi_make_exception_with_doc), METH_FASTCALL|METH_KEYWORDS, _testcapi_make_exception_with_doc__doc__},
+
+static PyObject *
+_testcapi_make_exception_with_doc_impl(PyObject *module, const char *name,
+                                       const char *doc, PyObject *base,
+                                       PyObject *dict);
+
+static PyObject *
+_testcapi_make_exception_with_doc(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+    PyObject *return_value = NULL;
+    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+    #define NUM_KEYWORDS 4
+    static struct {
+        PyGC_Head _this_is_not_used;
+        PyObject_VAR_HEAD
+        PyObject *ob_item[NUM_KEYWORDS];
+    } _kwtuple = {
+        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+        .ob_item = { &_Py_ID(name), &_Py_ID(doc), &_Py_ID(base), &_Py_ID(dict), },
+    };
+    #undef NUM_KEYWORDS
+    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+    #else  // !Py_BUILD_CORE
+    #  define KWTUPLE NULL
+    #endif  // !Py_BUILD_CORE
+
+    static const char * const _keywords[] = {"name", "doc", "base", "dict", NULL};
+    static _PyArg_Parser _parser = {
+        .keywords = _keywords,
+        .fname = "make_exception_with_doc",
+        .kwtuple = KWTUPLE,
+    };
+    #undef KWTUPLE
+    PyObject *argsbuf[4];
+    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
+    const char *name;
+    const char *doc = NULL;
+    PyObject *base = NULL;
+    PyObject *dict = NULL;
+
+    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
+    if (!args) {
+        goto exit;
+    }
+    if (!PyUnicode_Check(args[0])) {
+        _PyArg_BadArgument("make_exception_with_doc", "argument 'name'", "str", args[0]);
+        goto exit;
+    }
+    Py_ssize_t name_length;
+    name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+    if (name == NULL) {
+        goto exit;
+    }
+    if (strlen(name) != (size_t)name_length) {
+        PyErr_SetString(PyExc_ValueError, "embedded null character");
+        goto exit;
+    }
+    if (!noptargs) {
+        goto skip_optional_pos;
+    }
+    if (args[1]) {
+        if (!PyUnicode_Check(args[1])) {
+            _PyArg_BadArgument("make_exception_with_doc", "argument 'doc'", "str", args[1]);
+            goto exit;
+        }
+        Py_ssize_t doc_length;
+        doc = PyUnicode_AsUTF8AndSize(args[1], &doc_length);
+        if (doc == NULL) {
+            goto exit;
+        }
+        if (strlen(doc) != (size_t)doc_length) {
+            PyErr_SetString(PyExc_ValueError, "embedded null character");
+            goto exit;
+        }
+        if (!--noptargs) {
+            goto skip_optional_pos;
+        }
+    }
+    if (args[2]) {
+        base = args[2];
+        if (!--noptargs) {
+            goto skip_optional_pos;
+        }
+    }
+    dict = args[3];
+skip_optional_pos:
+    return_value = _testcapi_make_exception_with_doc_impl(module, name, doc, base, dict);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_exc_set_object__doc__,
+"exc_set_object($module, exception, obj, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_EXC_SET_OBJECT_METHODDEF    \
+    {"exc_set_object", _PyCFunction_CAST(_testcapi_exc_set_object), METH_FASTCALL, _testcapi_exc_set_object__doc__},
+
+static PyObject *
+_testcapi_exc_set_object_impl(PyObject *module, PyObject *exc, PyObject *obj);
+
+static PyObject *
+_testcapi_exc_set_object(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *exc;
+    PyObject *obj;
+
+    if (!_PyArg_CheckPositional("exc_set_object", nargs, 2, 2)) {
+        goto exit;
+    }
+    exc = args[0];
+    obj = args[1];
+    return_value = _testcapi_exc_set_object_impl(module, exc, obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_exc_set_object_fetch__doc__,
+"exc_set_object_fetch($module, exception, obj, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_EXC_SET_OBJECT_FETCH_METHODDEF    \
+    {"exc_set_object_fetch", _PyCFunction_CAST(_testcapi_exc_set_object_fetch), METH_FASTCALL, _testcapi_exc_set_object_fetch__doc__},
+
+static PyObject *
+_testcapi_exc_set_object_fetch_impl(PyObject *module, PyObject *exc,
+                                    PyObject *obj);
+
+static PyObject *
+_testcapi_exc_set_object_fetch(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *exc;
+    PyObject *obj;
+
+    if (!_PyArg_CheckPositional("exc_set_object_fetch", nargs, 2, 2)) {
+        goto exit;
+    }
+    exc = args[0];
+    obj = args[1];
+    return_value = _testcapi_exc_set_object_fetch_impl(module, exc, obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_raise_exception__doc__,
+"raise_exception($module, exception, num_args, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_RAISE_EXCEPTION_METHODDEF    \
+    {"raise_exception", _PyCFunction_CAST(_testcapi_raise_exception), METH_FASTCALL, _testcapi_raise_exception__doc__},
+
+static PyObject *
+_testcapi_raise_exception_impl(PyObject *module, PyObject *exc, int num_args);
+
+static PyObject *
+_testcapi_raise_exception(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *exc;
+    int num_args;
+
+    if (!_PyArg_CheckPositional("raise_exception", nargs, 2, 2)) {
+        goto exit;
+    }
+    exc = args[0];
+    num_args = _PyLong_AsInt(args[1]);
+    if (num_args == -1 && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = _testcapi_raise_exception_impl(module, exc, num_args);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_raise_memoryerror__doc__,
+"raise_memoryerror($module, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_RAISE_MEMORYERROR_METHODDEF    \
+    {"raise_memoryerror", (PyCFunction)_testcapi_raise_memoryerror, METH_NOARGS, _testcapi_raise_memoryerror__doc__},
+
+static PyObject *
+_testcapi_raise_memoryerror_impl(PyObject *module);
+
+static PyObject *
+_testcapi_raise_memoryerror(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _testcapi_raise_memoryerror_impl(module);
+}
+
+PyDoc_STRVAR(_testcapi_fatal_error__doc__,
+"fatal_error($module, message, release_gil=False, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_FATAL_ERROR_METHODDEF    \
+    {"fatal_error", _PyCFunction_CAST(_testcapi_fatal_error), METH_FASTCALL, _testcapi_fatal_error__doc__},
+
+static PyObject *
+_testcapi_fatal_error_impl(PyObject *module, const char *message,
+                           int release_gil);
+
+static PyObject *
+_testcapi_fatal_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    const char *message;
+    int release_gil = 0;
+
+    if (!_PyArg_ParseStack(args, nargs, "y|p:fatal_error",
+        &message, &release_gil)) {
+        goto exit;
+    }
+    return_value = _testcapi_fatal_error_impl(module, message, release_gil);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_set_exc_info__doc__,
+"set_exc_info($module, new_type, new_value, new_tb, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_SET_EXC_INFO_METHODDEF    \
+    {"set_exc_info", _PyCFunction_CAST(_testcapi_set_exc_info), METH_FASTCALL, _testcapi_set_exc_info__doc__},
+
+static PyObject *
+_testcapi_set_exc_info_impl(PyObject *module, PyObject *new_type,
+                            PyObject *new_value, PyObject *new_tb);
+
+static PyObject *
+_testcapi_set_exc_info(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *new_type;
+    PyObject *new_value;
+    PyObject *new_tb;
+
+    if (!_PyArg_CheckPositional("set_exc_info", nargs, 3, 3)) {
+        goto exit;
+    }
+    new_type = args[0];
+    new_value = args[1];
+    new_tb = args[2];
+    return_value = _testcapi_set_exc_info_impl(module, new_type, new_value, new_tb);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_set_exception__doc__,
+"set_exception($module, new_exc, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_SET_EXCEPTION_METHODDEF    \
+    {"set_exception", (PyCFunction)_testcapi_set_exception, METH_O, _testcapi_set_exception__doc__},
+
+PyDoc_STRVAR(_testcapi_write_unraisable_exc__doc__,
+"write_unraisable_exc($module, exception, err_msg, obj, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCAPI_WRITE_UNRAISABLE_EXC_METHODDEF    \
+    {"write_unraisable_exc", _PyCFunction_CAST(_testcapi_write_unraisable_exc), METH_FASTCALL, _testcapi_write_unraisable_exc__doc__},
+
+static PyObject *
+_testcapi_write_unraisable_exc_impl(PyObject *module, PyObject *exc,
+                                    PyObject *err_msg, PyObject *obj);
+
+static PyObject *
+_testcapi_write_unraisable_exc(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *exc;
+    PyObject *err_msg;
+    PyObject *obj;
+
+    if (!_PyArg_CheckPositional("write_unraisable_exc", nargs, 3, 3)) {
+        goto exit;
+    }
+    exc = args[0];
+    err_msg = args[1];
+    obj = args[2];
+    return_value = _testcapi_write_unraisable_exc_impl(module, exc, err_msg, obj);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_testcapi_traceback_print__doc__,
+"traceback_print($module, traceback, file, /)\n"
+"--\n"
+"\n"
+"To test the format of tracebacks as printed out.");
+
+#define _TESTCAPI_TRACEBACK_PRINT_METHODDEF    \
+    {"traceback_print", _PyCFunction_CAST(_testcapi_traceback_print), METH_FASTCALL, _testcapi_traceback_print__doc__},
+
+static PyObject *
+_testcapi_traceback_print_impl(PyObject *module, PyObject *traceback,
+                               PyObject *file);
+
+static PyObject *
+_testcapi_traceback_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *traceback;
+    PyObject *file;
+
+    if (!_PyArg_CheckPositional("traceback_print", nargs, 2, 2)) {
+        goto exit;
+    }
+    traceback = args[0];
+    file = args[1];
+    return_value = _testcapi_traceback_print_impl(module, traceback, file);
+
+exit:
+    return return_value;
+}
+/*[clinic end generated code: output=ec1b2e62adea9846 input=a9049054013a1b77]*/
diff --git a/Modules/_testcapi/exceptions.c b/Modules/_testcapi/exceptions.c
index 6099f7d20eb5..0a9902c135a7 100644
--- a/Modules/_testcapi/exceptions.c
+++ b/Modules/_testcapi/exceptions.c
@@ -1,7 +1,20 @@
 #include "parts.h"
+#include "clinic/exceptions.c.h"
+
+/*[clinic input]
+module _testcapi
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6361033e795369fc]*/
+
+/*[clinic input]
+_testcapi.err_set_raised
+    exception as exc: object
+    /
+[clinic start generated code]*/
 
 static PyObject *
-err_set_raised(PyObject *self, PyObject *exc)
+_testcapi_err_set_raised(PyObject *module, PyObject *exc)
+/*[clinic end generated code: output=0a0c7743961fcae5 input=c5f7331864a94df9]*/
 {
     Py_INCREF(exc);
     PyErr_SetRaisedException(exc);
@@ -35,16 +48,19 @@ err_restore(PyObject *self, PyObject *args) {
     return NULL;
 }
 
-/* To test the format of exceptions as printed out. */
+/*[clinic input]
+_testcapi.exception_print
+    exception as exc: object
+    legacy: bool = False
+    /
+
+To test the format of exceptions as printed out.
+[clinic start generated code]*/
+
 static PyObject *
-exception_print(PyObject *self, PyObject *args)
+_testcapi_exception_print_impl(PyObject *module, PyObject *exc, int legacy)
+/*[clinic end generated code: output=3f04fe0c18412ae0 input=c76f42cb94136dbf]*/
 {
-    PyObject *exc;
-    int legacy = 0;
-
-    if (!PyArg_ParseTuple(args, "O|i:exception_print", &exc, &legacy)) {
-        return NULL;
-    }
     if (legacy) {
         PyObject *tb = NULL;
         if (PyExceptionInstance_Check(exc)) {
@@ -59,55 +75,53 @@ exception_print(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
-/* Test PyErr_NewExceptionWithDoc (also exercise PyErr_NewException).
-   Run via Lib/test/test_exceptions.py */
-static PyObject *
-make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs)
-{
-    const char *name;
-    const char *doc = NULL;
-    PyObject *base = NULL;
-    PyObject *dict = NULL;
-
-    static char *kwlist[] = {"name", "doc", "base", "dict", NULL};
+/*[clinic input]
+_testcapi.make_exception_with_doc
+    name: str
+    doc: str = NULL
+    base: object = NULL
+    dict: object = NULL
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
-                                     "s|sOO:make_exception_with_doc", kwlist,
-                                     &name, &doc, &base, &dict))
-    {
-        return NULL;
-    }
+Test PyErr_NewExceptionWithDoc (also exercise PyErr_NewException). Run via Lib/test/test_exceptions.py
+[clinic start generated code]*/
 
+static PyObject *
+_testcapi_make_exception_with_doc_impl(PyObject *module, const char *name,
+                                       const char *doc, PyObject *base,
+                                       PyObject *dict)
+/*[clinic end generated code: output=439f0d963c1ce2c4 input=23a73013f8a8795a]*/
+{
     return PyErr_NewExceptionWithDoc(name, doc, base, dict);
 }
 
+/*[clinic input]
+_testcapi.exc_set_object
+    exception as exc: object
+    obj: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-exc_set_object(PyObject *self, PyObject *args)
+_testcapi_exc_set_object_impl(PyObject *module, PyObject *exc, PyObject *obj)
+/*[clinic end generated code: output=34c8c7c83e5c8463 input=fc530aafb1b0a360]*/
 {
-    PyObject *exc;
-    PyObject *obj;
-
-    if (!PyArg_ParseTuple(args, "OO:exc_set_object", &exc, &obj)) {
-        return NULL;
-    }
-
     PyErr_SetObject(exc, obj);
     return NULL;
 }
 
+/*[clinic input]
+_testcapi.exc_set_object_fetch = _testcapi.exc_set_object
+[clinic start generated code]*/
+
 static PyObject *
-exc_set_object_fetch(PyObject *self, PyObject *args)
+_testcapi_exc_set_object_fetch_impl(PyObject *module, PyObject *exc,
+                                    PyObject *obj)
+/*[clinic end generated code: output=7a5ff5f6d3cf687f input=77ec686f1f95fa38]*/
 {
-    PyObject *exc;
-    PyObject *obj;
     PyObject *type;
     PyObject *value;
     PyObject *tb;
 
-    if (!PyArg_ParseTuple(args, "OO:exc_set_object", &exc, &obj)) {
-        return NULL;
-    }
-
     PyErr_SetObject(exc, obj);
     PyErr_Fetch(&type, &value, &tb);
     Py_XDECREF(type);
@@ -115,16 +129,17 @@ exc_set_object_fetch(PyObject *self, PyObject *args)
     return value;
 }
 
+/*[clinic input]
+_testcapi.raise_exception
+    exception as exc: object
+    num_args: int
+    /
+[clinic start generated code]*/
+
 static PyObject *
-raise_exception(PyObject *self, PyObject *args)
+_testcapi_raise_exception_impl(PyObject *module, PyObject *exc, int num_args)
+/*[clinic end generated code: output=eb0a9c5d69e0542d input=83d6262c3829d088]*/
 {
-    PyObject *exc;
-    int num_args;
-
-    if (!PyArg_ParseTuple(args, "Oi:raise_exception", &exc, &num_args)) {
-        return NULL;
-    }
-
     PyObject *exc_args = PyTuple_New(num_args);
     if (exc_args == NULL) {
         return NULL;
@@ -142,21 +157,29 @@ raise_exception(PyObject *self, PyObject *args)
     return NULL;
 }
 
-/* reliably raise a MemoryError */
+/*[clinic input]
+_testcapi.raise_memoryerror
+[clinic start generated code]*/
+
 static PyObject *
-raise_memoryerror(PyObject *self, PyObject *Py_UNUSED(ignored))
+_testcapi_raise_memoryerror_impl(PyObject *module)
+/*[clinic end generated code: output=dd057803fb0131e6 input=6ca521bd07fb73cb]*/
 {
     return PyErr_NoMemory();
 }
 
+/*[clinic input]
+_testcapi.fatal_error
+    message: str(accept={robuffer})
+    release_gil: bool = False
+    /
+[clinic start generated code]*/
+
 static PyObject *
-test_fatal_error(PyObject *self, PyObject *args)
+_testcapi_fatal_error_impl(PyObject *module, const char *message,
+                           int release_gil)
+/*[clinic end generated code: output=9c3237116e6a03e8 input=1be357a2ccb04c8c]*/
 {
-    char *message;
-    int release_gil = 0;
-    if (!PyArg_ParseTuple(args, "y|i:fatal_error", &message, &release_gil)) {
-        return NULL;
-    }
     if (release_gil) {
         Py_BEGIN_ALLOW_THREADS
         Py_FatalError(message);
@@ -169,17 +192,20 @@ test_fatal_error(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
+/*[clinic input]
+_testcapi.set_exc_info
+    new_type: object
+    new_value: object
+    new_tb: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-test_set_exc_info(PyObject *self, PyObject *args)
+_testcapi_set_exc_info_impl(PyObject *module, PyObject *new_type,
+                            PyObject *new_value, PyObject *new_tb)
+/*[clinic end generated code: output=b55fa35dec31300e input=ea9f19e0f55fe5b3]*/
 {
-    PyObject *new_type, *new_value, *new_tb;
     PyObject *type, *value, *tb;
-    if (!PyArg_ParseTuple(args, "OOO:test_set_exc_info",
-                          &new_type, &new_value, &new_tb))
-    {
-        return NULL;
-    }
-
     PyErr_GetExcInfo(&type, &value, &tb);
 
     Py_INCREF(new_type);
@@ -197,23 +223,35 @@ test_set_exc_info(PyObject *self, PyObject *args)
     return orig_exc;
 }
 
+/*[clinic input]
+_testcapi.set_exception
+    new_exc: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-test_set_exception(PyObject *self, PyObject *new_exc)
+_testcapi_set_exception(PyObject *module, PyObject *new_exc)
+/*[clinic end generated code: output=8b969b35d029e96d input=c89d4ca966c69738]*/
 {
     PyObject *exc = PyErr_GetHandledException();
     assert(PyExceptionInstance_Check(exc) || exc == NULL);
-
     PyErr_SetHandledException(new_exc);
     return exc;
 }
 
+/*[clinic input]
+_testcapi.write_unraisable_exc
+    exception as exc: object
+    err_msg: object
+    obj: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-test_write_unraisable_exc(PyObject *self, PyObject *args)
+_testcapi_write_unraisable_exc_impl(PyObject *module, PyObject *exc,
+                                    PyObject *err_msg, PyObject *obj)
+/*[clinic end generated code: output=39827c5e0a8c2092 input=582498da5b2ee6cf]*/
 {
-    PyObject *exc, *err_msg, *obj;
-    if (!PyArg_ParseTuple(args, "OOO", &exc, &err_msg, &obj)) {
-        return NULL;
-    }
 
     const char *err_msg_utf8;
     if (err_msg != Py_None) {
@@ -231,19 +269,19 @@ test_write_unraisable_exc(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
-/* To test the format of tracebacks as printed out. */
+/*[clinic input]
+_testcapi.traceback_print
+    traceback: object
+    file: object
+    /
+To test the format of tracebacks as printed out.
+[clinic start generated code]*/
+
 static PyObject *
-traceback_print(PyObject *self, PyObject *args)
+_testcapi_traceback_print_impl(PyObject *module, PyObject *traceback,
+                               PyObject *file)
+/*[clinic end generated code: output=17074ecf9d95cf30 input=9423f2857b008ca8]*/
 {
-    PyObject *file;
-    PyObject *traceback;
-
-    if (!PyArg_ParseTuple(args, "OO:traceback_print",
-                            &traceback, &file))
-    {
-        return NULL;
-    }
-
     if (PyTraceBack_Print(traceback, file) < 0) {
         return NULL;
     }
@@ -278,20 +316,18 @@ static PyTypeObject PyRecursingInfinitelyError_Type = {
 
 static PyMethodDef test_methods[] = {
     {"err_restore",             err_restore,                     METH_VARARGS},
-    {"err_set_raised",          err_set_raised,                  METH_O},
-    {"exception_print",         exception_print,                 METH_VARARGS},
-    {"fatal_error",             test_fatal_error,                METH_VARARGS,
-     PyDoc_STR("fatal_error(message, release_gil=False): call Py_FatalError(message)")},
-    {"make_exception_with_doc", _PyCFunction_CAST(make_exception_with_doc),
-     METH_VARARGS | METH_KEYWORDS},
-    {"exc_set_object",          exc_set_object,                  METH_VARARGS},
-    {"exc_set_object_fetch",    exc_set_object_fetch,            METH_VARARGS},
-    {"raise_exception",         raise_exception,                 METH_VARARGS},
-    {"raise_memoryerror",       raise_memoryerror,               METH_NOARGS},
-    {"set_exc_info",            test_set_exc_info,               METH_VARARGS},
-    {"set_exception",           test_set_exception,              METH_O},
-    {"traceback_print",         traceback_print,                 METH_VARARGS},
-    {"write_unraisable_exc",    test_write_unraisable_exc,       METH_VARARGS},
+    _TESTCAPI_ERR_SET_RAISED_METHODDEF
+    _TESTCAPI_EXCEPTION_PRINT_METHODDEF
+    _TESTCAPI_FATAL_ERROR_METHODDEF
+    _TESTCAPI_MAKE_EXCEPTION_WITH_DOC_METHODDEF
+    _TESTCAPI_EXC_SET_OBJECT_METHODDEF
+    _TESTCAPI_EXC_SET_OBJECT_FETCH_METHODDEF
+    _TESTCAPI_RAISE_EXCEPTION_METHODDEF
+    _TESTCAPI_RAISE_MEMORYERROR_METHODDEF
+    _TESTCAPI_SET_EXC_INFO_METHODDEF
+    _TESTCAPI_SET_EXCEPTION_METHODDEF
+    _TESTCAPI_TRACEBACK_PRINT_METHODDEF
+    _TESTCAPI_WRITE_UNRAISABLE_EXC_METHODDEF
     {NULL},
 };
 



More information about the Python-checkins mailing list