bpo-38631: Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() (GH-18258)

Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() in
object.c and typeobject.c to also dump the involved Python object on
a fatal error. It should ease debug when such fatal error occurs.

If the double linked list is inconsistent, _Py_ForgetReference() no
longer dumps previous and next objects in the fatal error, it now
only dumps the current object. It ensures that the error message
is displayed even if dumping the object does crash Python.

Enhance _Py_ForgetReference() error messages;
_PyObject_ASSERT_FAILED_MSG() logs the "_Py_ForgetReference" function
name.
This commit is contained in:
Victor Stinner 2020-01-30 09:01:07 +01:00 committed by GitHub
parent 188bb5b1e8
commit 5eb8bff7e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 33 deletions

View file

@ -3570,9 +3570,9 @@ type_traverse(PyTypeObject *type, visitproc visit, void *arg)
for heaptypes. */
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
char msg[200];
sprintf(msg, "type_traverse() called for non-heap type '%.100s'",
sprintf(msg, "type_traverse() called on non-heap type '%.100s'",
type->tp_name);
Py_FatalError(msg);
_PyObject_ASSERT_FAILED_MSG((PyObject *)type, msg);
}
Py_VISIT(type->tp_dict);