Remove _PyThreadState_GetFrame #84127
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee = None closed_at = <Date 2020-03-20.16:49:31.422> created_at = <Date 2020-03-12.17:40:48.726> labels = ['interpreter-core', '3.9'] title = 'Remove _PyThreadState_GetFrame' updated_at = <Date 2020-05-04.21:50:53.284> user = 'https://github.com/vstinner'
activity = <Date 2020-05-04.21:50:53.284> actor = 'vstinner' assignee = 'none' closed = True closed_date = <Date 2020-03-20.16:49:31.422> closer = 'vstinner' components = ['Interpreter Core'] creation = <Date 2020-03-12.17:40:48.726> creator = 'vstinner' dependencies =  files =  hgrepos =  issue_num = 39946 keywords = ['patch'] message_count = 7.0 messages = ['364031', '364675', '364677', '364679', '364680', '368084', '368085'] nosy_count = 4.0 nosy_names = ['brett.cannon', 'gregory.p.smith', 'vstinner', 'Mark.Shannon'] pr_nums = ['19094'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue39946' versions = ['Python 3.9']
The text was updated successfully, but these errors were encountered:
Python has an internal function to get the frame of the PyThreadState:
/* hook for PyEval_GetFrame(), requested for Psyco */ #define _PyThreadState_GetFrame _PyRuntime.gilstate.getframe
It is used by the public function PyEval_GetFrame() for example.
The indirection was added in 2002 by:
... but psyco is outdated for a very long time (superseded by PyPy which is no longer based on CPython). Is it time to drop _PyThreadState_GetFrame() (which became _PyRuntime.gilstate.getframe in the meanwhile)?
Or if we keep it, we should use it rather accessing directly PyThreadState.frame (read or write).
It looks safe to remove this feature.
I failed to find any recent user of _PyThreadState_GetFrame.
Moreover, _PyRuntime.getframe and _PyThreadState_GetFrame have been moved to the internal C API in Python 3.7. This C API was not accessible by third-party projects in Python 3.7. The internal C API can only be used by third-party projects since Python 3.8 and it's tricky to use it... on purpose. I don't recall any complain about _PyThreadState_GetFrame becoming inaccessible.
I searched for "_PyThreadState_GetFrame" in C code on GitHub. I only found copies of Python/pystate.c files in the first 10 pages of search results, with one exception. I found one file:
It's an old (latest commit on Mar 31, 2015) debugger project written by Xavier de Gaye.
It seems like the following flavor is more recent (latest commit on Apr 20, 2019):
Note: the project contains 4 .c files, but only _pdbhandler-py27.c uses _PyThreadState_GetFrame: _pdbhandler-py3.c which is for Python 3 doesn't use _PyThreadState_GetFrame. But Python 2.7 reached its end of life, it's no longer supported.
Copy of the code:
So _PyThreadState_GetFrame was used to "disable the Python 2 restricted mode", but this mode has been removed from Python 3.