gh-156133: Add PyUnstable_InterpreterFrame_GetLocal - #156134
guilhermeleobas wants to merge 6 commits into
Conversation
049e1b3 to
9145c2f
Compare
Documentation build overview
398 files changed ·
|
PyUnstable_InterpreterFrame_GetLocalsPyUnstable_InterpreterFrame_GetLocal
Add an unstable C API that returns a strong reference to a single local variable of an internal interpreter frame, addressed by its localsplus index, with cell and free variables unboxed to their contents. Free variables are resolved from the function closure, so the API also works on a frame that has not started executing (before COPY_FREE_VARS runs) -- the case that motivated it -- and it does not modify the frame. Includes the PEP 689 deliverables: reference documentation in Doc/c-api/frame.rst, a What's New entry for 3.16, a Misc/NEWS.d blurb, and tests in Lib/test/test_capi/test_misc.py (TestInternalFrameApi) covering plain locals, a cell variable, and a free variable. Authored with the assistance of an AI coding agent (Claude Opus)
cbb346a to
d29acd6
Compare
|
Thanks @aisk. I've addressed your comments. |
|
Hi, thank you for the contribution, but please avoid using force push in the future, see: https://devguide.python.org/getting-started/pull-request-lifecycle/#don-t-force-push |
Sorry, it won't happen again. I did because the e-mail used in the commit was wrong and the cla-bot was failing. |
|
@aisk could you take a look at this PR again once you have some cycles to spare? |
| .. versionadded:: 3.12 | ||
|
|
||
|
|
||
| .. c:function:: PyObject* PyUnstable_InterpreterFrame_GetLocal(struct _PyInterpreterFrame *frame, Py_ssize_t index) |
There was a problem hiding this comment.
Ideally we should add an unstable API for the _PyInterpreterFrame struct too, right?
There was a problem hiding this comment.
From the discuss topic, Petr said this can be done in a follow-up PR. I can add it here if you think it is necessary.
There was a problem hiding this comment.
@encukou could you take a look at this PR once you have a chance?
There was a problem hiding this comment.
I will, after the 3.15.0 release.
…emRef` convention
Add an unstable C API that reads a frame's local variables into a caller-provided array indexed by localsplus index, with cell and free variables unboxed to their contents. Free variables are resolved from the function closure, so the API also works on a frame that has not started executing (before COPY_FREE_VARS runs), which is the case that motivated it.
Includes the three PEP 689 deliverables:
Modules/_testinternalcapi.cdriven byLib/test/test_capi/test_frame_getlocals.pycovering plain locals, a cell variable, and a free variable).Authored with the assistance of an AI coding agent (Claude Opus)
PyUnstable_InterpreterFrame_GetLocalto read a local var from an interp. frame #156133