gh-141518: Add PyUnstable_InterpreterFrame_GetFrameObject() function by vstinner · Pull Request #141950 · python/cpython
I don't think we should add PyUnstable_InterpreterFrame_GetFrameObject().
If someone wants a frame object, they can get it directly with sys._getframe() or the C API equivalent.
The whole point of using _PyInterpreterFrame is to avoid the overhead of creating a frame object.
Also, PyUnstable_InterpreterFrame_GetFrameObject() is not a simpler getter, but will often have to create the frame object.
sys._getframe() won't work in a frame evaluation function -- until the new frame is set up, it returns the previous one.
Should it be PyUnstable_InterpreterFrame_AsFrameObject?
In a frame evaluation function, you don't want the frame object. It is just a bulkier, slower version of the frame you already have. The frame object contains no additional information, just a pointer back to the internal frame.
In a frame evaluation function, you don't want the frame object
Yeah, you should use the internal C API to access the interpreter frame: pycore_interpframe.h provides many functions, such as:
- _PyFrame_GetCode()
- _PyFrame_GetBytecode()
- _PyFrame_GetFunction()
- _PyFrame_IsIncomplete()
- etc.
I know that it's kind of unusual to have a public function to set a frame evalution function, but need the internal C API to implement it.
The C API Working Group decided to not add a public function for this feature, but keep the _Py name instead: capi-workgroup/decisions#89.
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