Skip to content

bpo-42197: Disable automatic update of frame locals during tracing #23028

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

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 11 additions & 0 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,11 @@ always available.
``'c_exception'``
A C function has raised an exception. *arg* is the C function object.

.. versionchanged:: 3.10
`PyFrame_FastToLocalsWithError` and `PyFrame_LocalsToFast` are no longer
called before and after the profile function (they must now be explicitly
called when manipulating `PyFrameObject.f_locals`).

.. function:: setrecursionlimit(limit)

Set the maximum depth of the Python interpreter stack to *limit*. This limit
Expand Down Expand Up @@ -1417,6 +1422,12 @@ always available.
``'opcode'`` event type added; :attr:`f_trace_lines` and
:attr:`f_trace_opcodes` attributes added to frames

.. versionchanged:: 3.10
`PyFrame_FastToLocalsWithError` and `PyFrame_LocalsToFast` are no longer
called before and after the trace function (they must now be
explicitly called when manipulating `PyFrameObject.f_locals`).


.. function:: set_asyncgen_hooks(firstiter, finalizer)

Accepts two optional keyword arguments which are callables that accept an
Expand Down
9 changes: 9 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ Optimizations
bytecode level. It is now around 100% faster to create a function with parameter
annotations. (Contributed by Yurii Karabas and Inada Naoki in :issue:`42202`)

* `PyFrame_FastToLocalsWithError` and `PyFrame_LocalsToFast` are no longer called during profile and tracing.
(Contributed by Fabio Zadrozny in :issue:`issue42197`)

Deprecated
==========

Expand Down Expand Up @@ -656,6 +659,12 @@ Porting to Python 3.10
bugs like ``if (PyList_SET_ITEM (a, b, c) < 0) ...`` test.
(Contributed by Zackery Spytz and Victor Stinner in :issue:`30459`.)

* `PyFrame_FastToLocalsWithError` and `PyFrame_LocalsToFast` are no longer
called before and after the trace or profile function, so, they must now
be explicitly called when manipulating `PyFrameObject.f_locals`.
(Contributed by Fabio Zadrozny in :issue:`issue42197`)


Deprecated
----------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`PyFrame_FastToLocalsWithError` and `PyFrame_LocalsToFast` are no longer
called during profile nor tracing. To inspect the `PyFrameObject.f_locals` member,
debuggers and profilers implemented in C must now call `PyFrame_FastToLocalsWithError`
to update locals and `PyFrame_LocalsToFast` after `PyFrameObject.f_locals` are updated.
5 changes: 0 additions & 5 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,6 @@ static PyObject *
call_trampoline(PyThreadState *tstate, PyObject* callback,
PyFrameObject *frame, int what, PyObject *arg)
{
if (PyFrame_FastToLocalsWithError(frame) < 0) {
return NULL;
}

PyObject *stack[3];
stack[0] = (PyObject *)frame;
stack[1] = whatstrings[what];
Expand All @@ -962,7 +958,6 @@ call_trampoline(PyThreadState *tstate, PyObject* callback,
/* call the Python-level function */
PyObject *result = _PyObject_FastCallTstate(tstate, callback, stack, 3);

PyFrame_LocalsToFast(frame, 1);
if (result == NULL) {
PyTraceBack_Here(frame);
}
Expand Down