FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-155742: Check singletons consistency at Python exit by vstinner · Pull Request #157572 · python/cpython · GitHub

Repository navigation

gh-155742: Check singletons consistency at Python exit - #157572

Merged
vstinner merged 12 commits into
python:mainfrom
vstinner:global_obj_fini_check
Sep 17, 2026
Merged

vstinner merged 12 commits into
python:mainfrom
vstinner:global_obj_fini_check

Conversation

vstinner commented Sep 15, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

In debug mode at Python exit, check if immutable singleton objects have been modified by mistake to detect bugs in C extensions.

Add tests corrupting bytes, str, bool and int singleton objects.

In debug mode at Python exit, check if immutable singleton objects
have been modified by mistake to detect bugs in C extensions.

Add tests corrupting bytes, str, bool and int singleton objects.
vstinner changed the title gh-155742: Check singletons consistencty at Python exit gh-155742: Check singletons consistency at Python exit Sep 15, 2026
if (!_Py_IsImmortal(obj)) {
fprintf(stderr, "Immortal Object has less refcnt than expected.\n");
PyObject_Dump(obj);
_PyStaticObject_CheckSingleton(PyObject *obj, PyTypeObject *type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It seems weird to have this much hand-written code in *_generated.h, which is hidden by default in GitHub reviews.
Did you consider moving the supporting functions to pycore_global_objects.h for example?

* Add a comment explaining why the bytes empty string doesn't need
  _PyBytes_CheckOverflow().
* Share code for unicode checks.

Copy link
Copy Markdown
Member Author

@encukou: I addressed your review.

  • I added a comment to explain why _PyBytes_CheckOverflow() is omitted on the empty string.
  • I add a sub-function to share unicode object checks.
  • Change _PyStaticObject_CheckUnicodeCharSingleton() to hardcode the size of 1 character.

It's fine to call it on an empty string.

Copy link
Copy Markdown
Member Author

I simplified _PyStaticObject_CheckBytesSingleton() to always call _PyBytes_CheckOverflow().

Comment thread Lib/test/test_capi/test_misc.py Outdated

encukou commented Sep 17, 2026

Copy link
Copy Markdown
Member

Thanks. I sent another simplification as vstinner#17
Please do consider moving the hand-written functions to a file that's shown in reviews by default.

vstinner requested a review from itamaro as a code owner September 17, 2026 12:31

Copy link
Copy Markdown
Member Author

@encukou:

Please do consider moving the hand-written functions to a file that's shown in reviews by default.

Oh right, pycore_global_objects_fini_generated.h contains hand written code and generated code, it's not new in my PR. But yeah, I was also annoyed by that: I just made a change adding pycore_global_objects_fini.h for hand written code.

I also updated pycore_runtime_init_generated.h to fully generate the file by script.

I left pycore_global_strings.h and pycore_unicodeobject_generated.h as they are (hand written code + generated code), someone else can update them if they want :-) I prefer to not make too many changes in this PR.

vstinner merged commit 8bcbcf8 into python:main Sep 17, 2026
54 checks passed
vstinner deleted the global_obj_fini_check branch September 17, 2026 14:03

Copy link
Copy Markdown
Member Author

Merged. Thanks for your reviews and contribution @encukou.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL