bpo-46417: Finalize structseq types at exit#30645
bpo-46417: Finalize structseq types at exit#30645vstinner merged 5 commits intopython:mainfrom vstinner:WIP_type_fini
Conversation
|
There are a few more structseq types:
|
|
I changed my mind and also enabled the code on Python release build. Previously, I only enabled the code if the Py_DEBUG macro was defined. For example, the Windows CI job on pull requests builds Python in release mode. If something is wrong, I prefer to catch the bug early and fix it. |
Add _PyStructSequence_FiniType() and _PyStaticType_Dealloc() functions to finalize a structseq static type in Py_Finalize(). Currrently, these functions do nothing if Python is built in release mode. Clear static types: * AsyncGenHooksType: sys.set_asyncgen_hooks() * FlagsType: sys.flags * FloatInfoType: sys.float_info * Hash_InfoType: sys.hash_info * Int_InfoType: sys.int_info * ThreadInfoType: sys.thread_info * UnraisableHookArgsType: sys.unraisablehook * VersionInfoType: sys.version * WindowsVersionType: sys.getwindowsversion()
|
The PR is now ready for a review :-) |
shihai1991
left a comment
There was a problem hiding this comment.
OK. This PR looks good to me :)
But I think another question: Can we add a global cache to maintain the StructSequenceType and don't call the dealloc function in finalize_interp_types() manually?
Do you mean to create a list of structseq types when _PyStructSequence_InitType() or _PyStructSequence_InitType2() is called? Yeah, I had this idea, but I am not sure about it. A problem is to control exactly when these types are deleted and types them in a specific order. The Python finalization is quite complex, see my notes about past issues: https://pythondev.readthedocs.io/finalization.html
|
Yes. That's what I mean : )
OK, Thanks for your information. I will study your notes. |
|
I enhanced the tests to check more PyTypeObject members. |
Add _PyStructSequence_FiniType() and _PyStaticType_Dealloc()
functions to finalize a structseq static type in Py_Finalize().
Currrently, these functions do nothing if Python is built in release
mode.
Clear static types:
https://bugs.python.org/issue46417