--- /dev/null
+In debug mode, :c:func:`PyObject_GC_Track` now calls ``tp_traverse()`` of
+the object type to ensure that the object is valid: test that objects
+visited by ``tp_traverse()`` are valid.
Py_INCREF(self);
it->root_element = self;
- PyObject_GC_Track(it);
-
it->parent_stack = PyMem_New(ParentLocator, INIT_PARENT_STACK_SIZE);
if (it->parent_stack == NULL) {
Py_DECREF(it);
it->parent_stack_used = 0;
it->parent_stack_size = INIT_PARENT_STACK_SIZE;
+ PyObject_GC_Track(it);
+
return (PyObject *)it;
}
_PyObject_Dump(FROM_GC(g));
}
+static int
+visit_validate(PyObject *op, void *parent_raw)
+{
+ PyObject *parent = _PyObject_CAST(parent_raw);
+ if (_PyObject_IsFreed(op)) {
+ _PyObject_ASSERT_FAILED_MSG(parent,
+ "PyObject_GC_Track() object is not valid");
+ }
+ return 0;
+}
+
+
/* extension modules might be compiled with GC support so these
functions must always be available */
"by the garbage collector");
}
_PyObject_GC_TRACK(op);
+
+#ifdef Py_DEBUG
+ /* Check that the object is valid: validate objects traversed
+ by tp_traverse() */
+ traverseproc traverse = Py_TYPE(op)->tp_traverse;
+ (void)traverse(op, visit_validate, op);
+#endif
}
void
new_parser->handlers = 0;
new_parser->intern = self->intern;
Py_XINCREF(new_parser->intern);
- PyObject_GC_Track(new_parser);
if (self->buffer != NULL) {
new_parser->buffer = PyMem_Malloc(new_parser->buffer_size);
handler_info[i].handler);
}
}
+
+ PyObject_GC_Track(new_parser);
return (PyObject *)new_parser;
}
self->handlers = NULL;
self->intern = intern;
Py_XINCREF(self->intern);
- PyObject_GC_Track(self);
/* namespace_separator is either NULL or contains one char + \0 */
self->itself = XML_ParserCreate_MM(encoding, &ExpatMemoryHandler,
}
clear_handlers(self, 1);
+ PyObject_GC_Track(self);
return (PyObject*)self;
}