gh-108082: Add PyErr_FormatUnraisable() function (GH-111086)

This commit is contained in:
Serhiy Storchaka 2023-10-31 23:42:44 +02:00 committed by GitHub
parent 453e96e302
commit f6a02327b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 142 additions and 8 deletions

View file

@ -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