Skip to content

Commit fa2c0b8

Browse files
authored
bpo-44964: Add a note explaining the new semantics of f_last_i in frame objects (GH-28200)
1 parent 2c3474a commit fa2c0b8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Doc/reference/datamodel.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,9 @@ Internal types
10691069
:attr:`f_code` is the code object being executed in this frame; :attr:`f_locals`
10701070
is the dictionary used to look up local variables; :attr:`f_globals` is used for
10711071
global variables; :attr:`f_builtins` is used for built-in (intrinsic) names;
1072-
:attr:`f_lasti` gives the precise instruction (this is an index into the
1073-
bytecode string of the code object).
1072+
:attr:`f_lasti` gives the precise instruction (it represents a wordcode index, which
1073+
means that to get an index into the bytecode string of the code object it needs to be
1074+
multiplied by 2).
10741075

10751076
Accessing ``f_code`` raises an :ref:`auditing event <auditing>`
10761077
``object.__getattr__`` with arguments ``obj`` and ``"f_code"``.

Doc/whatsnew/3.10.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,12 @@ Changes in the C API
19481948
source_buf = PyBytes_AsString(source_bytes_object);
19491949
code = Py_CompileString(source_buf, filename, Py_file_input);
19501950
1951+
* For ``FrameObject`` objects, the ``f_lasti`` member now represents a wordcode
1952+
offset instead of a simple offset into the bytecode string. This means that this
1953+
number needs to be multiplied by 2 to be used with APIs that expect a byte offset
1954+
instead (like :c:func:`PyCode_Addr2Line` for example). Notice as well that the
1955+
``f_lasti`` member of ``FrameObject`` objects is not considered stable.
1956+
19511957
CPython bytecode changes
19521958
========================
19531959

0 commit comments

Comments
 (0)