Uh oh!
There was an error while loading. Please reload this page.
gh-89373: Document that error indicator may be set in tp_dealloc - #28358
Conversation
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
the-knights-who-say-ni
commented
Sep 15, 2021
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
ezyang
commented
Sep 15, 2021
just signed CLA |
JelleZijlstra
commented
Apr 2, 2022
There is a merge conflict, could you take a look? |
ezyang
commented
Apr 3, 2022
done |
There was a problem hiding this comment.
Thanks. This note seems useful, but I am not that comfortable with the C API, and on the bug @vstinner seems to prefer a different direction, so this will need more discussion.
| :c:func:`PyObject_GC_Del` if the instance was allocated using | ||
| :c:func:`PyObject_GC_New` or :c:func:`PyObject_GC_NewVar`. | ||
| If you may call functions that may set the error indicator, you must |
There was a problem hiding this comment.
As I understand it, very little of the C API is safe to call with an active error set. So maybe this should be a stronger message?
There was a problem hiding this comment.
IIRC, the intent here was not to discuss C API functions, but if you were calling into userland (which happens if you've got some complicated cleanup functions; at least that's what bit us here.)
ezyang
commented
Apr 3, 2022
I don't know enough about CPython to know if @vstinner's suggestion to enforce deallocation is never called when error is set is feasible. Seems... difficult to enforce. |
| If you may call functions that may set the error indicator, you must | ||
| use :c:func:`PyErr_Fetch` and :c:func:`PyErr_Restore` to ensure you | ||
| don't clobber a preexisting error indicator (the deallocation could | ||
| have occurred while processing a different error): |
There was a problem hiding this comment.
I would add that the function must not raise an exception. It can use PyErr_WriteUnraisable() to log (and clear) an "unraisable" exception.
By the way, I'm surprised that _Py_Dealloc() doesn't ensure in debug mode (Py_DEBUG) that tp_dealloc does not raise a new exception. See also _Py_CheckSlotResult() and _Py_CheckFunctionResult().
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ezyang
commented
Jun 6, 2025
Merge conflicts fixed LOL, three years later |
Uh oh!
There was an error while loading. Please reload this page.
Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner
commented
Jun 7, 2025
@ezyang: Oh, the last blocker point is that you didnd't sign the CLA with your email, see: #28358 (comment) |
ezyang
commented
Jun 9, 2025
Too many emails lol. Fixed. |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, @ezyang and @vstinner, I could not cleanly backport this to |
…thonGH-28358) (cherry picked from commit 8441b26) Co-authored-by: Edward Z. Yang <ezyang@mit.edu> Signed-off-by: Edward Z. Yang <ezyang@fb.com> Signed-off-by: Edward Z. Yang <ezyang@meta.com> Co-authored-by: Victor Stinner <vstinner@python.org>
GH-135298 is a backport of this pull request to the 3.14 branch. |
vstinner
commented
Jun 9, 2025
Merged, thanks @ezyang. Better late than never :-) |
…loc (GH-28358) (#135298) bpo-45210: Document that error indicator may be set in tp_dealloc (GH-28358) (cherry picked from commit 8441b26) Signed-off-by: Edward Z. Yang <ezyang@fb.com> Signed-off-by: Edward Z. Yang <ezyang@meta.com> Co-authored-by: Edward Z. Yang <ezyang@mit.edu> Co-authored-by: Victor Stinner <vstinner@python.org>
…thon#28358) Signed-off-by: Edward Z. Yang <ezyang@fb.com> Signed-off-by: Edward Z. Yang <ezyang@meta.com> Co-authored-by: Victor Stinner <vstinner@python.org>
…thon#28358) Signed-off-by: Edward Z. Yang <ezyang@fb.com> Signed-off-by: Edward Z. Yang <ezyang@meta.com> Co-authored-by: Victor Stinner <vstinner@python.org>
…thon#28358) Signed-off-by: Edward Z. Yang <ezyang@fb.com> Signed-off-by: Edward Z. Yang <ezyang@meta.com> Co-authored-by: Victor Stinner <vstinner@python.org>
…thon#28358) Signed-off-by: Edward Z. Yang <ezyang@fb.com> Signed-off-by: Edward Z. Yang <ezyang@meta.com> Co-authored-by: Victor Stinner <vstinner@python.org>
Signed-off-by: Edward Z. Yang ezyang@fb.com
https://bugs.python.org/issue45210