-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-89373: Document that error indicator may be set in tp_dealloc #28358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
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! |
just signed CLA |
There is a merge conflict, could you take a look? |
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Doc/c-api/typeobj.rst
Outdated
@@ -668,6 +668,20 @@ and :c:type:`PyType_Type` effectively act as defaults.) | |||
: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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.)
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. |
Doc/c-api/typeobj.rst
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Merge conflicts fixed LOL, three years later |
Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@ezyang: Oh, the last blocker point is that you didnd't sign the CLA with your email, see: #28358 (comment) |
Too many emails lol. Fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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. |
Merged, thanks @ezyang. Better late than never :-) |
Signed-off-by: Edward Z. Yang ezyang@fb.com
https://bugs.python.org/issue45210