This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Clarify that tp_dealloc must decref for heap allocated type
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: ammar2, docs@python, miss-islington
Priority: normal Keywords: patch

Created on 2019-09-17 23:27 by ammar2, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16248 merged ammar2, 2019-09-18 00:11
PR 16436 merged miss-islington, 2019-09-27 11:11
Messages (3)
msg352672 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2019-09-17 23:27
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.
msg353354 - (view) Author: miss-islington (miss-islington) Date: 2019-09-27 11:11
New changeset 5faff977adbe089e1f91a5916ccb2160a22dd292 by Miss Islington (bot) (Ammar Askar) in branch 'master':
bpo-38206: Clarify tp_dealloc requirements for heap allocated types. (GH-16248)
https://github.com/python/cpython/commit/5faff977adbe089e1f91a5916ccb2160a22dd292
msg353355 - (view) Author: miss-islington (miss-islington) Date: 2019-09-27 11:18
New changeset 14ddca726a8cd337d0461934374b5e6bf65bf812 by Miss Islington (bot) in branch '3.8':
bpo-38206: Clarify tp_dealloc requirements for heap allocated types. (GH-16248)
https://github.com/python/cpython/commit/14ddca726a8cd337d0461934374b5e6bf65bf812
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82387
2019-09-27 16:49:33ammar2setstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-09-27 11:18:27miss-islingtonsetmessages: + msg353355
2019-09-27 11:11:42miss-islingtonsetpull_requests: + pull_request16014
2019-09-27 11:11:35miss-islingtonsetnosy: + miss-islington
messages: + msg353354
2019-09-18 00:11:56ammar2setkeywords: + patch
stage: patch review
pull_requests: + pull_request15844
2019-09-17 23:27:39ammar2create