summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapi
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-10-31 21:42:44 (GMT)
committerGitHub <noreply@github.com>2023-10-31 21:42:44 (GMT)
commitf6a02327b5fcdc10df855985ca9d2d9dc2a0a46f (patch)
treebd0599c585b71b87092536ef0d8f381164283622 /Modules/_testcapi
parent453e96e3020d38cfcaebf82b24cb681c6384fa82 (diff)
downloadcpython-f6a02327b5fcdc10df855985ca9d2d9dc2a0a46f.zip
cpython-f6a02327b5fcdc10df855985ca9d2d9dc2a0a46f.tar.gz
cpython-f6a02327b5fcdc10df855985ca9d2d9dc2a0a46f.tar.bz2
gh-108082: Add PyErr_FormatUnraisable() function (GH-111086)
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r--Modules/_testcapi/exceptions.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/_testcapi/exceptions.c b/Modules/_testcapi/exceptions.c
index aac672a..42a9915 100644
--- a/Modules/_testcapi/exceptions.c
+++ b/Modules/_testcapi/exceptions.c
@@ -319,6 +319,30 @@ err_writeunraisable(PyObject *Py_UNUSED(module), PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *
+err_formatunraisable(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ PyObject *exc;
+ const char *fmt;
+ Py_ssize_t fmtlen;
+ PyObject *objs[10] = {NULL};
+
+ if (!PyArg_ParseTuple(args, "Oz#|OOOOOOOOOO", &exc, &fmt, &fmtlen,
+ &objs[0], &objs[1], &objs[2], &objs[3], &objs[4],
+ &objs[5], &objs[6], &objs[7], &objs[8], &objs[9]))
+ {
+ return NULL;
+ }
+ NULLABLE(exc);
+ if (exc) {
+ PyErr_SetRaisedException(Py_NewRef(exc));
+ }
+ PyErr_FormatUnraisable(fmt,
+ objs[0], objs[1], objs[2], objs[3], objs[4],
+ objs[5], objs[6], objs[7], objs[8], objs[9]);
+ Py_RETURN_NONE;
+}
+
/*[clinic input]
_testcapi.unstable_exc_prep_reraise_star
orig: object
@@ -364,6 +388,7 @@ static PyTypeObject PyRecursingInfinitelyError_Type = {
static PyMethodDef test_methods[] = {
{"err_restore", err_restore, METH_VARARGS},
{"err_writeunraisable", err_writeunraisable, METH_VARARGS},
+ {"err_formatunraisable", err_formatunraisable, METH_VARARGS},
_TESTCAPI_ERR_SET_RAISED_METHODDEF
_TESTCAPI_EXCEPTION_PRINT_METHODDEF
_TESTCAPI_FATAL_ERROR_METHODDEF