mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
refactor __del__ exception handler into PyErr_WriteUnraisable
add sanity check to gc: if an exception occurs during GC, call PyErr_WriteUnraisable and then call Py_FatalEror.
This commit is contained in:
parent
b9ce5ada37
commit
b709df3810
5 changed files with 50 additions and 21 deletions
|
@ -519,26 +519,7 @@ instance_dealloc(register PyInstanceObject *inst)
|
|||
if ((del = instance_getattr2(inst, delstr)) != NULL) {
|
||||
PyObject *res = PyEval_CallObject(del, (PyObject *)NULL);
|
||||
if (res == NULL) {
|
||||
PyObject *f, *t, *v, *tb;
|
||||
PyErr_Fetch(&t, &v, &tb);
|
||||
f = PySys_GetObject("stderr");
|
||||
if (f != NULL) {
|
||||
PyFile_WriteString("Exception ", f);
|
||||
if (t) {
|
||||
PyFile_WriteObject(t, f, Py_PRINT_RAW);
|
||||
if (v && v != Py_None) {
|
||||
PyFile_WriteString(": ", f);
|
||||
PyFile_WriteObject(v, f, 0);
|
||||
}
|
||||
}
|
||||
PyFile_WriteString(" in ", f);
|
||||
PyFile_WriteObject(del, f, 0);
|
||||
PyFile_WriteString(" ignored\n", f);
|
||||
PyErr_Clear(); /* Just in case */
|
||||
}
|
||||
Py_XDECREF(t);
|
||||
Py_XDECREF(v);
|
||||
Py_XDECREF(tb);
|
||||
PyErr_WriteUnraisable(del);
|
||||
}
|
||||
else
|
||||
Py_DECREF(res);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue