[New-bugs-announce] [issue38206] Clarify that tp_dealloc must decref for heap allocated type

Ammar Askar report at bugs.python.org
Tue Sep 17 19:27:39 EDT 2019


New submission from Ammar Askar <ammar at ammaraskar.com>:

When dealing with a heap allocated type (https://docs.python.org/3/c-api/typeobj.html#Py_TPFLAGS_HEAPTYPE / PyType_FromSpec), if the type has a custom tp_dealloc function then it MUST decrement the references to the type object itself due to this code block: https://github.com/python/cpython/blob/4a12a178f4a6b9a59d97fecc727f2b6b28dfc85f/Objects/typeobject.c#L1189-L1192

The only mention of this is within the whatsnew entry for 3.8: https://github.com/python/cpython/commit/364f0b0f19cc3f0d5e63f571ec9163cf41c62958#diff-77c703d9a958f6a4b0dc2f692b3fd5b3

This error was made in https://github.com/python/cpython/pull/16127#pullrequestreview-288312751 and https://github.com/python/cpython/pull/16071#pullrequestreview-287819525

It seems like a common pitfall, let's add a note about this in the doc.

----------
assignee: docs at python
components: Documentation
messages: 352672
nosy: ammar2, docs at python
priority: normal
severity: normal
status: open
title: Clarify that tp_dealloc must decref for heap allocated type
type: enhancement
versions: Python 3.9

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


More information about the New-bugs-announce mailing list