You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clarify that tp_dealloc must decref for heap allocated type #82387
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-09-27.16:49:33.332>created_at=<Date2019-09-17.23:27:39.940>labels= ['type-feature', '3.9', 'docs']
title='Clarify that tp_dealloc must decref for heap allocated type'updated_at=<Date2019-09-27.16:49:33.332>user='https://github.com/ammaraskar'
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:
New changeset 5faff97 by Miss Islington (bot) (Ammar Askar) in branch 'master': bpo-38206: Clarify tp_dealloc requirements for heap allocated types. (GH-16248) 5faff97
Activity
ammaraskar commentedon Sep 17, 2019
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:
cpython/Objects/typeobject.c
Lines 1189 to 1192 in 4a12a17
The only mention of this is within the whatsnew entry for 3.8: 364f0b0#diff-77c703d9a958f6a4b0dc2f692b3fd5b3
This error was made in #16127 (review) and #16071 (review)
It seems like a common pitfall, let's add a note about this in the doc.
miss-islington commentedon Sep 27, 2019
New changeset 5faff97 by Miss Islington (bot) (Ammar Askar) in branch 'master':
bpo-38206: Clarify tp_dealloc requirements for heap allocated types. (GH-16248)
5faff97
miss-islington commentedon Sep 27, 2019
New changeset 14ddca7 by Miss Islington (bot) in branch '3.8':
bpo-38206: Clarify tp_dealloc requirements for heap allocated types. (GH-16248)
14ddca7