Skip to content

bpo-44964: Add a note explaining the new semantics of f_last_i in frame objects #28200

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

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,9 @@ Internal types
:attr:`f_code` is the code object being executed in this frame; :attr:`f_locals`
is the dictionary used to look up local variables; :attr:`f_globals` is used for
global variables; :attr:`f_builtins` is used for built-in (intrinsic) names;
:attr:`f_lasti` gives the precise instruction (this is an index into the
bytecode string of the code object).
:attr:`f_lasti` gives the precise instruction (it represents a wordcode index, which
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. f_lasti is the index in the bytecode. No need to multiply by two.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #28208

means that to get an index into the bytecode string of the code object it needs to be
multiplied by 2).

Accessing ``f_code`` raises an :ref:`auditing event <auditing>`
``object.__getattr__`` with arguments ``obj`` and ``"f_code"``.
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,12 @@ Changes in the C API
source_buf = PyBytes_AsString(source_bytes_object);
code = Py_CompileString(source_buf, filename, Py_file_input);

* For ``FrameObject`` objects, the ``f_lasti`` member now represents a wordcode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note to use PyFrame_GetLineNumber() instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #28208

offset instead of a simple offset into the bytecode string. This means that this
number needs to be multiplied by 2 to be used with APIs that expect a byte offset
instead (like :c:func:`PyCode_Addr2Line` for example). Notice as well that the
``f_lasti`` member of ``FrameObject`` objects is not considered stable.

CPython bytecode changes
========================

Expand Down