mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-108082: C API: Add tests for PyErr_WriteUnraisable() (GH-111455) (GH-111507)
Also document the behavior when called with NULL.
(cherry picked from commit bca3305429
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
e5b6744f30
commit
748bc48648
3 changed files with 70 additions and 0 deletions
|
@ -331,6 +331,22 @@ _testcapi_traceback_print_impl(PyObject *module, PyObject *traceback,
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
err_writeunraisable(PyObject *Py_UNUSED(module), PyObject *args)
|
||||
{
|
||||
PyObject *exc, *obj;
|
||||
if (!PyArg_ParseTuple(args, "OO", &exc, &obj)) {
|
||||
return NULL;
|
||||
}
|
||||
NULLABLE(exc);
|
||||
NULLABLE(obj);
|
||||
if (exc) {
|
||||
PyErr_SetRaisedException(Py_NewRef(exc));
|
||||
}
|
||||
PyErr_WriteUnraisable(obj);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_testcapi.unstable_exc_prep_reraise_star
|
||||
orig: object
|
||||
|
@ -375,6 +391,7 @@ static PyTypeObject PyRecursingInfinitelyError_Type = {
|
|||
|
||||
static PyMethodDef test_methods[] = {
|
||||
{"err_restore", err_restore, METH_VARARGS},
|
||||
{"err_writeunraisable", err_writeunraisable, METH_VARARGS},
|
||||
_TESTCAPI_ERR_SET_RAISED_METHODDEF
|
||||
_TESTCAPI_EXCEPTION_PRINT_METHODDEF
|
||||
_TESTCAPI_FATAL_ERROR_METHODDEF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue