New submission from STINNER Victor <vstin...@python.org>:

In bpo-38392, I modified PyObject_GC_Track() to ensure that the object newly 
tracked is valid: call its traverse function.
=> commit 1b1845569539db5c1a6948a5d32daea381f1e35f

I propose to now also attempt to implement the same check in 
_PyObject_GC_TRACK() which is part of the internal C API.

PyType_GenericAlloc() allocates memory for a type allocated on the heap... and 
then immediately track it in the GC. Problem: this type is not initialized yet, 
all fields are set to zero. Calling type_traverse() at this point fails with an 
assertion error:
---
Objects/typeobject.c:3570: type_traverse: Assertion failed: type_traverse() 
called on non-heap type '(null)'
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x840860
object refcount : 1
object type     : 0x7e0900
object type name: type
object repr     : 
---

By the way, Python crash in _PyObject_Dump() on PyObject_Repr() call: 
type_repr() crash when accessing type->tp_name which is NULL.

type_call() should only track the newly created type when it's fully 
initialized.


Try attached track.patch to reproduce the crash.

----------
components: Interpreter Core
files: track.patch
keywords: patch
messages: 365515
nosy: vstinner
priority: normal
severity: normal
status: open
title: Modify _PyObject_GC_TRACK() to ensure that newly tracked object is valid
type: enhancement
versions: Python 3.9
Added file: https://bugs.python.org/file49021/track.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40142>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to