Skip to content

Commit 5a5a972

Browse files
committed
Use PyErr_FormatUnraisable() on Python 3.13
Use the new public PyErr_FormatUnraisable() on Python 3.13. The private _PyErr_WriteUnraisableMsg() function was removed in Python 3.13: python/cpython#111643
1 parent a490b4b commit 5a5a972

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/c/_cffi_backend.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6100,7 +6100,6 @@ static void _my_PyErr_WriteUnraisable(PyObject *t, PyObject *v, PyObject *tb,
61006100
Luckily it's also Python 3.8 that adds new functionality that
61016101
people might want: the new sys.unraisablehook().
61026102
*/
6103-
PyObject *s;
61046103
int first_char;
61056104
assert(objdescr != NULL && objdescr[0] != 0); /* non-empty */
61066105
first_char = objdescr[0];
@@ -6109,6 +6108,18 @@ static void _my_PyErr_WriteUnraisable(PyObject *t, PyObject *v, PyObject *tb,
61096108
if (extra_error_line == NULL)
61106109
extra_error_line = "";
61116110

6111+
#if PY_VERSION_HEX >= 0x030D0000
6112+
if (obj != NULL) {
6113+
PyErr_FormatUnraisable("Exception ignored %c%s%R%s",
6114+
first_char, objdescr + 1, obj,
6115+
extra_error_line);
6116+
}
6117+
else {
6118+
PyErr_FormatUnraisable("Exception ignored %c%s%s",
6119+
first_char, objdescr + 1, extra_error_line);
6120+
}
6121+
#else
6122+
PyObject *s;
61126123
if (obj != NULL)
61136124
s = PyUnicode_FromFormat("%c%s%R%s",
61146125
first_char, objdescr + 1, obj, extra_error_line);
@@ -6124,6 +6135,7 @@ static void _my_PyErr_WriteUnraisable(PyObject *t, PyObject *v, PyObject *tb,
61246135
else
61256136
PyErr_WriteUnraisable(obj); /* best effort */
61266137
PyErr_Clear();
6138+
#endif
61276139

61286140
#else
61296141

0 commit comments

Comments
 (0)