[New-bugs-announce] [issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

STINNER Victor report at bugs.python.org
Mon Jun 28 22:02:58 EDT 2021


New submission from STINNER Victor <vstinner at python.org>:

The PyType_GenericAlloc() function tracks the newly created object in the garbage collector (GC) as soon as memory is initialized, but before all object members are initialized.

If a GC collection happens before the object is fully initialized, the traverse function of the newly created object can crash.

This case is hypothetical for built-in types since their constructor should not trigger a GC collection. It is more likely in third party extensions and subclasses.

Anyway, I propose to add a new _PyType_AllocNoTrack() function which allocates memory without tracking the newly allocated object directly in the GC.

This function can be used to only track explicitly the object in the GC once it is fully initialized.

----------
components: C API
messages: 396695
nosy: vstinner
priority: normal
severity: normal
status: open
title: Add _PyType_AllocNoTrack() function: allocate without tracking in the GC
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44531>
_______________________________________


More information about the New-bugs-announce mailing list