-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-46836: Add Doc/c-api/frame.rst #32051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
58aedac
675ffd6
0d422ed
71c167d
c524e8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ Other Objects | |
memoryview.rst | ||
weakref.rst | ||
capsule.rst | ||
frame.rst | ||
gen.rst | ||
coro.rst | ||
contextvars.rst | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.. highlight:: c | ||
|
||
Frame Objects | ||
------------- | ||
|
||
.. c:type:: PyFrameObject | ||
|
||
The C structure of the objects used to describe frame objects. | ||
|
||
The structure is only part of the internal C API: fields should not be | ||
access directly. Use getter functions like :c:func:`PyFrame_GetCode` and | ||
:c:func:`PyFrame_GetBack`. | ||
|
||
Debuggers and profilers can use the internal C API to access this structure | ||
vstinner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
without calling functions, but the internal C API doesn't provide any | ||
backward compatibility warranty. | ||
|
||
.. versionchanged:: 3.11 | ||
The structure moved to the internal C API headers. | ||
|
||
Public members: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be much safer to just say "don't access fields directly". For example, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the PR to clarify that these members are part of the Python API. My idea is just to explain that the Python API can be accessed in C as well.
Well, it's technically possible to do that in pure Python. If there is a bug, it should be either documented or fixed. For example, disallow setting f_trace_lines and f_trace_opcodes. Currently, f_trace_lines and f_trace_opcodes are not documented. IMO it's better to document them. If there are limits, we can document them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The struct fields cannot be safely accessed by C code. The limit is that you can't do it. |
||
|
||
* ``f_back`` (read only): Next outer frame object (this frame's caller). | ||
See also: :c:func:`PyFrame_GetBack`. | ||
* ``f_builtins`` (read only): Builtins namespace seen by this frame. | ||
* ``f_code`` (read only): Code object being executed in this frame. | ||
See also :c:func:`PyFrame_GetCode`. | ||
* ``f_globals`` (read only): Global namespace seen by this frame. | ||
* ``f_lasti`` (read only): Index of last attempted instruction in bytecode. | ||
* ``f_lineno``: Current line number in Python source code. | ||
See also :c:func:`PyFrame_GetLineNumber`. | ||
* ``f_locals`` (read only): Local namespace seen by this frame. | ||
* ``f_trace_lines``: Emit ``PyTrace_LINE`` trace events? | ||
* ``f_trace_opcodes``: Emit ``PyTrace_OPCODE`` trace events? | ||
* ``f_trace``: Tracing function for this frame, or ``None`` | ||
|
||
The :c:func:`PyObject_GetAttrString` and :c:func:`PyObject_SetAttrString` | ||
markshannon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
functions can be used to get and set these members. For example, | ||
``PyObject_GetAttrString((PyObject*)frame, "f_builtins")`` gets the frame | ||
builtins namespace. | ||
|
||
The :c:func:`PyEval_GetFrame` and :c:func:`PyThreadState_GetFrame` functions | ||
can be used to get a frame object. | ||
|
||
See also :ref:`Reflection <reflection>`. | ||
|
||
|
||
.. c:function:: PyFrameObject* PyFrame_GetBack(PyFrameObject *frame) | ||
|
||
Get the *frame* next outer frame. | ||
|
||
Return a :term:`strong reference`, or ``NULL`` if *frame* has no outer | ||
frame. | ||
|
||
*frame* must not be ``NULL``. | ||
|
||
.. versionadded:: 3.9 | ||
|
||
|
||
.. c:function:: PyCodeObject* PyFrame_GetCode(PyFrameObject *frame) | ||
|
||
Get the *frame* code. | ||
|
||
Return a :term:`strong reference`. | ||
|
||
*frame* must not be ``NULL``. The result (frame code) cannot be ``NULL``. | ||
|
||
.. versionadded:: 3.9 | ||
|
||
|
||
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame) | ||
|
||
Return the line number that *frame* is currently executing. | ||
|
||
*frame* must not be ``NULL``. |
Uh oh!
There was an error while loading. Please reload this page.