This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Mark.Shannon, corona10, eric.snow, gvanrossum, kumaraditya, vstinner
Date 2022-01-23.14:00:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642946407.23.0.125152712939.issue46476@roundup.psfhosted.org>
In-reply-to
Content
> See branch https://github.com/kumaraditya303/cpython/commits/fix-code

Oh nice, I like this new _Py_Deepfreeze_Fini() function :-) I suggest to create a function specific to only clear immortal code objects. In my experience, it's important to control exactly when objects are cleared at Python exit: Py_Finalize() is complex and fragile. See my notes:
https://pythondev.readthedocs.io/finalization.html

Be careful, Python must remain usable after Py_Finalize(): it's legit to call Py_Initialize() again and execute new Python code. Example executing the same code 4 times, each time Py_Initialize() and Py_Finalize() are called:

./Programs/_testembed test_repeated_init_exec 'print("Hello")'

My _PyStaticMethod_Dealloc() implementation uses Py_CLEAR() rather than Py_XDECREF() to set structure members to NULL.

Moreover, there are more things than just co_quickened which should be cleared. I suggest to add a new function to clear an "immortal" code object. For example, I also suggest to call PyObject_ClearWeakRefs(). I guess that co_extra should also be cleared.
History
Date User Action Args
2022-01-23 14:00:07vstinnersetrecipients: + vstinner, gvanrossum, Mark.Shannon, eric.snow, corona10, kumaraditya
2022-01-23 14:00:07vstinnersetmessageid: <1642946407.23.0.125152712939.issue46476@roundup.psfhosted.org>
2022-01-23 14:00:07vstinnerlinkissue46476 messages
2022-01-23 14:00:06vstinnercreate