mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-119786: [doc] more consistent syntax in InternalDocs (#125815)
This commit is contained in:
parent
4848b0b92c
commit
d0bfff47fb
6 changed files with 371 additions and 420 deletions
|
@ -10,20 +10,19 @@ of three conceptual sections:
|
|||
globals dict, code object, instruction pointer, stack depth, the
|
||||
previous frame, etc.
|
||||
|
||||
The definition of the ``_PyInterpreterFrame`` struct is in
|
||||
[Include/internal/pycore_frame.h](https://github.com/python/cpython/blob/main/Include/internal/pycore_frame.h).
|
||||
The definition of the `_PyInterpreterFrame` struct is in
|
||||
[Include/internal/pycore_frame.h](../Include/internal/pycore_frame.h).
|
||||
|
||||
# Allocation
|
||||
|
||||
Python semantics allows frames to outlive the activation, so they need to
|
||||
be allocated outside the C call stack. To reduce overhead and improve locality
|
||||
of reference, most frames are allocated contiguously in a per-thread stack
|
||||
(see ``_PyThreadState_PushFrame`` in
|
||||
[Python/pystate.c](https://github.com/python/cpython/blob/main/Python/pystate.c)).
|
||||
(see `_PyThreadState_PushFrame` in [Python/pystate.c](../Python/pystate.c)).
|
||||
|
||||
Frames of generators and coroutines are embedded in the generator and coroutine
|
||||
objects, so are not allocated in the per-thread stack. See ``PyGenObject`` in
|
||||
[Include/internal/pycore_genobject.h](https://github.com/python/cpython/blob/main/Include/internal/pycore_genobject.h).
|
||||
objects, so are not allocated in the per-thread stack. See `PyGenObject` in
|
||||
[Include/internal/pycore_genobject.h](../Include/internal/pycore_genobject.h).
|
||||
|
||||
## Layout
|
||||
|
||||
|
@ -82,16 +81,15 @@ frames for each activation, but with low runtime overhead.
|
|||
|
||||
### Generators and Coroutines
|
||||
|
||||
Generators (objects of type ``PyGen_Type``, ``PyCoro_Type`` or
|
||||
``PyAsyncGen_Type``) have a `_PyInterpreterFrame` embedded in them, so
|
||||
Generators (objects of type `PyGen_Type`, `PyCoro_Type` or
|
||||
`PyAsyncGen_Type`) have a `_PyInterpreterFrame` embedded in them, so
|
||||
that they can be created with a single memory allocation.
|
||||
When such an embedded frame is iterated or awaited, it can be linked with
|
||||
frames on the per-thread stack via the linkage fields.
|
||||
|
||||
If a frame object associated with a generator outlives the generator, then
|
||||
the embedded `_PyInterpreterFrame` is copied into the frame object (see
|
||||
``take_ownership()`` in
|
||||
[Python/frame.c](https://github.com/python/cpython/blob/main/Python/frame.c)).
|
||||
`take_ownership()` in [Python/frame.c](../Python/frame.c)).
|
||||
|
||||
### Field names
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue