Skip to content

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

Merged
merged 9 commits into from
Jun 9, 2025

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented Sep 15, 2021

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
@the-knights-who-say-ni
Copy link

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 username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@ezyang

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!

@bedevere-bot bedevere-bot added awaiting review docs Documentation in the Doc dir labels Sep 15, 2021
@ezyang
Copy link
Contributor Author

ezyang commented Sep 15, 2021

just signed CLA

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
@JelleZijlstra
Copy link
Member

There is a merge conflict, could you take a look?

@ezyang
Copy link
Contributor Author

ezyang commented Apr 3, 2022

done

Copy link
Member

@JelleZijlstra JelleZijlstra left a 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.

@@ -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
Copy link
Member

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?

Copy link
Contributor Author

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.)

@ezyang
Copy link
Contributor Author

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):
Copy link
Member

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().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

MaxwellDupre

This comment was marked as off-topic.

@python-cla-bot
Copy link

python-cla-bot bot commented Apr 6, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@ezyang
Copy link
Contributor Author

ezyang commented Jun 6, 2025

Merge conflicts fixed LOL, three years later

Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner
Copy link
Member

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
Copy link
Contributor Author

ezyang commented Jun 9, 2025

Too many emails lol. Fixed.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner enabled auto-merge (squash) June 9, 2025 08:51
@picnixz picnixz changed the title bpo-45210: Document that error indicator may be set in tp_dealloc gh-89373: Document that error indicator may be set in tp_dealloc Jun 9, 2025
@vstinner vstinner merged commit 8441b26 into python:main Jun 9, 2025
27 of 28 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Jun 9, 2025
@vstinner vstinner added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jun 9, 2025
@miss-islington-app
Copy link

Thanks @ezyang for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Thanks @ezyang for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @ezyang and @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 8441b263af964f353bf02d56c32a4fc547cdc330 3.13

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 9, 2025
…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>
@bedevere-app
Copy link

bedevere-app bot commented Jun 9, 2025

GH-135298 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jun 9, 2025
@vstinner vstinner removed the needs backport to 3.13 bugs and security fixes label Jun 9, 2025
@vstinner
Copy link
Member

vstinner commented Jun 9, 2025

Merged, thanks @ezyang. Better late than never :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy