Skip to content

Commit

Permalink
Use PyErr_FormatUnraisable() on Python 3.13
Browse files Browse the repository at this point in the history
Use the new public PyErr_FormatUnraisable() on Python 3.13.

The private _PyErr_WriteUnraisableMsg() function was removed in
Python 3.13:
python/cpython#111643
  • Loading branch information
vstinner committed Nov 15, 2023
1 parent a490b4b commit 5a5a972
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/c/_cffi_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -6100,7 +6100,6 @@ static void _my_PyErr_WriteUnraisable(PyObject *t, PyObject *v, PyObject *tb,
Luckily it's also Python 3.8 that adds new functionality that
people might want: the new sys.unraisablehook().
*/
PyObject *s;
int first_char;
assert(objdescr != NULL && objdescr[0] != 0); /* non-empty */
first_char = objdescr[0];
Expand All @@ -6109,6 +6108,18 @@ static void _my_PyErr_WriteUnraisable(PyObject *t, PyObject *v, PyObject *tb,
if (extra_error_line == NULL)
extra_error_line = "";

#if PY_VERSION_HEX >= 0x030D0000
if (obj != NULL) {
PyErr_FormatUnraisable("Exception ignored %c%s%R%s",
first_char, objdescr + 1, obj,
extra_error_line);
}
else {
PyErr_FormatUnraisable("Exception ignored %c%s%s",
first_char, objdescr + 1, extra_error_line);
}
#else
PyObject *s;
if (obj != NULL)
s = PyUnicode_FromFormat("%c%s%R%s",
first_char, objdescr + 1, obj, extra_error_line);
Expand All @@ -6124,6 +6135,7 @@ static void _my_PyErr_WriteUnraisable(PyObject *t, PyObject *v, PyObject *tb,
else
PyErr_WriteUnraisable(obj); /* best effort */
PyErr_Clear();
#endif

#else

Expand Down

0 comments on commit 5a5a972

Please sign in to comment.