You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyEval_GetFrame and PyThreadState_GetFrame docs say that NULL is returned when "no frame is currently executing", and doesn't say anything about any error (probably as they explicitly clear it?).
I wonder whether PyFrame_GetBack also would want to clear error
And PyEval_GetLocals and PyFrame_GetBack are public C APIs that don't check for NULL and don't clear the error. I guess the internals are ok to propagate the errors?
Can someone explain whether PyFrame_GetBack not clearing error on null is ok/intended or it's a discrepancy/bug?
I would prefer PyFrame_GetBack to not propagate an error given that its documentation doesn't say anything about MemoryError.
Bug report
Bug description:
There are 3 callers of
_PyFrame_GetFrameObjectwhich explicitly clear error when it returns NULL.take_ownershipcpython/Python/frame.c
Lines 74 to 79 in b67a64d
PyEval_GetFramecpython/Python/ceval.c
Lines 2562 to 2564 in b67a64d
PyThreadState_GetFramecpython/Python/pystate.c
Lines 2101 to 2103 in b67a64d
PyEval_GetFrameandPyThreadState_GetFramedocs say that NULL is returned when "no frame is currently executing", and doesn't say anything about any error (probably as they explicitly clear it?).I wonder whether
PyFrame_GetBackalso would want to clear errorcpython/Objects/frameobject.c
Lines 2407 to 2409 in b67a64d
PyFrame_GetBack's documentation doesn't say anything aboutMemoryErrorwhich can be set by its internal API calls https://docs.python.org/3.15/c-api/frame.html#c.PyFrame_GetBackThe rest of the
_PyFrame_GetFrameObjectcallers that don't clear error includingPyFrame_GetBackare_PyEval_ExceptionGroupMatch_PyEval_EvalFrameDefault(error label)_gen_getframesys__getframe_impl_PyThread_CurrentFrames_Py_call_instrumentation_line_PyFrame_GetLocalsPyEval_GetLocals— Public C API (deprecated), no NULL checkPyFrame_GetBack— Public C API, no NULL checkAnd
PyEval_GetLocalsandPyFrame_GetBackare public C APIs that don't check for NULL and don't clear the error. I guess the internals are ok to propagate the errors?Can someone explain whether
PyFrame_GetBacknot clearing error on null is ok/intended or it's a discrepancy/bug?I would prefer
PyFrame_GetBackto not propagate an error given that its documentation doesn't say anything about MemoryError.CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
PyFrame_GetBackdoes not raise exceptions (GH-144824) #145318PyFrame_GetBackdoes not raise exceptions (GH-144824) #145319