Skip to content

Commit b39afb7

Browse files
authored
bpo-38070: Enhance _PyObject_Dump() (GH-16243)
_PyObject_Dump() now dumps the object address for freed objects and objects with ob_type=NULL.
1 parent 8fa3e17 commit b39afb7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Objects/object.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,15 @@ void
464464
_PyObject_Dump(PyObject* op)
465465
{
466466
if (op == NULL) {
467-
fprintf(stderr, "<NULL object>\n");
467+
fprintf(stderr, "<object at NULL>\n");
468468
fflush(stderr);
469469
return;
470470
}
471471

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

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

21622162
if (obj == NULL) {
2163-
fprintf(stderr, "<NULL object>\n");
2163+
fprintf(stderr, "<object at NULL>\n");
21642164
}
21652165
else if (_PyObject_IsFreed(obj)) {
21662166
/* It seems like the object memory has been freed:
21672167
don't access it to prevent a segmentation fault. */
2168-
fprintf(stderr, "<object: freed>\n");
2168+
fprintf(stderr, "<object at %p is freed>\n", obj);
21692169
}
21702170
else if (Py_TYPE(obj) == NULL) {
2171-
fprintf(stderr, "<object: ob_type=NULL>\n");
2171+
fprintf(stderr, "<object at %p: ob_type=NULL>\n", obj);
21722172
}
21732173
else if (_PyObject_IsFreed((PyObject *)Py_TYPE(obj))) {
2174-
fprintf(stderr, "<object: freed type %p>\n", (void *)Py_TYPE(obj));
2174+
fprintf(stderr, "<object at %p: type at %p is freed>\n",
2175+
obj, (void *)Py_TYPE(obj));
21752176
}
21762177
else {
21772178
/* Display the traceback where the object has been allocated.

0 commit comments

Comments
 (0)