Skip to content

Commit

Permalink
bpo-38070: Enhance _PyObject_Dump() (GH-16243)
Browse files Browse the repository at this point in the history
_PyObject_Dump() now dumps the object address for freed objects and
objects with ob_type=NULL.
  • Loading branch information
vstinner authored Sep 17, 2019
1 parent 8fa3e17 commit b39afb7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,15 @@ void
_PyObject_Dump(PyObject* op)
{
if (op == NULL) {
fprintf(stderr, "<NULL object>\n");
fprintf(stderr, "<object at NULL>\n");
fflush(stderr);
return;
}

if (_PyObject_IsFreed(op)) {
/* It seems like the object memory has been freed:
don't access it to prevent a segmentation fault. */
fprintf(stderr, "<Freed object>\n");
fprintf(stderr, "<object at %p is freed>\n", op);
return;
}

Expand Down Expand Up @@ -2160,18 +2160,19 @@ _PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg,
fflush(stderr);

if (obj == NULL) {
fprintf(stderr, "<NULL object>\n");
fprintf(stderr, "<object at NULL>\n");
}
else if (_PyObject_IsFreed(obj)) {
/* It seems like the object memory has been freed:
don't access it to prevent a segmentation fault. */
fprintf(stderr, "<object: freed>\n");
fprintf(stderr, "<object at %p is freed>\n", obj);
}
else if (Py_TYPE(obj) == NULL) {
fprintf(stderr, "<object: ob_type=NULL>\n");
fprintf(stderr, "<object at %p: ob_type=NULL>\n", obj);
}
else if (_PyObject_IsFreed((PyObject *)Py_TYPE(obj))) {
fprintf(stderr, "<object: freed type %p>\n", (void *)Py_TYPE(obj));
fprintf(stderr, "<object at %p: type at %p is freed>\n",
obj, (void *)Py_TYPE(obj));
}
else {
/* Display the traceback where the object has been allocated.
Expand Down

0 comments on commit b39afb7

Please sign in to comment.