Skip to content

C API "Initialization" docs suggest to use PyFrameObject fields that are no longer public #111774

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

Open
chgnrdv opened this issue Nov 6, 2023 · 1 comment
Labels
docs Documentation in the Doc dir

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented Nov 6, 2023

Since #90992 PyFrameObject is an opaque structure, but Profiling and Tracing section of Initialization, Finalization and Threads part of C API docs suggests to use its private fields to change tracing behavior:

cpython/Doc/c-api/init.rst

Lines 1661 to 1665 in ba8aa1f

.. c:var:: int PyTrace_LINE
The value passed as the *what* parameter to a :c:type:`Py_tracefunc` function
(but not a profiling function) when a line-number event is being reported.
It may be disabled for a frame by setting :attr:`f_trace_lines` to *0* on that frame.

cpython/Doc/c-api/init.rst

Lines 1692 to 1697 in ba8aa1f

.. c:var:: int PyTrace_OPCODE
The value for the *what* parameter to :c:type:`Py_tracefunc` functions (but not
profiling functions) when a new opcode is about to be executed. This event is
not emitted by default: it must be explicitly requested by setting
:attr:`f_trace_opcodes` to *1* on the frame.

I guess it should instead mention PyObject_SetAttrString(frame, "f_trace_lines", Py_False) and PyObject_SetAttrString(frame, "f_trace_opcodes", Py_True) calls as a way to set values of needed fields.

Linked PRs

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jan 28, 2024

:attr:`~frame.f_trace_lines` refers not to the field of the C structure, but to the attribute of the Python object. So technically the documentation is correct (beside that it is better to use False/True instead of 0/1). What C API you use to set the value of the attribute (PyObject_SetAttr() or PyObject_SetAttrString()) is unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
2 participants