Up through 3.10, I’ve been using a non-standard way to get at a thread frame’s line number while in an unsafe state. It basically involves getting a PyThreadState and iterating over PyFrameObjects via
PyThreadState->frame and then
PyFrameObject->f_back, each time calling
I tried doing an analogous thing in 3.11, using
_PyCFrame->previous->current_frame->frame_obj. The problem I’m running into, though, is
frame_obj is often NULL. IIUC, this is due to how frames are lazily generated in 3.11.
I’ve tried using something like
PyEval_GetFrame to force frame_obj generation immediately prior to doing this, but the unsafe state i’m in makes this fail.
I’ve had 2 thoughts related to potential workarounds. First is if there is a way to “turn on” non-lazy frame generation at the beginning of the program. IDK if this is possible in 3.11 though. Second workaround is maybe there is other info lying around in fields/structs I could save off to reconstruct the line number later. Not sure if this is possible either, though.
Any help would be appreciated.