bpo-42197: Disable automatic update of frame locals during profiling and tracing

This commit is contained in:
Fabio Zadrozny 2020-12-20 07:41:05 -03:00
parent a44ce6c9f7
commit 50fe523997
4 changed files with 24 additions and 5 deletions

View File

@ -1292,6 +1292,11 @@ always available.
``'c_exception'`` ``'c_exception'``
A C function has raised an exception. *arg* is the C function object. 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) .. function:: setrecursionlimit(limit)
Set the maximum depth of the Python interpreter stack to *limit*. This limit Set the maximum depth of the Python interpreter stack to *limit*. This limit
@ -1417,6 +1422,12 @@ always available.
``'opcode'`` event type added; :attr:`f_trace_lines` and ``'opcode'`` event type added; :attr:`f_trace_lines` and
:attr:`f_trace_opcodes` attributes added to frames :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) .. function:: set_asyncgen_hooks(firstiter, finalizer)
Accepts two optional keyword arguments which are callables that accept an Accepts two optional keyword arguments which are callables that accept an

View File

@ -417,6 +417,9 @@ Optimizations
bytecode level. It is now around 100% faster to create a function with parameter 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`) 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 Deprecated
========== ==========
@ -656,6 +659,12 @@ Porting to Python 3.10
bugs like ``if (PyList_SET_ITEM (a, b, c) < 0) ...`` test. bugs like ``if (PyList_SET_ITEM (a, b, c) < 0) ...`` test.
(Contributed by Zackery Spytz and Victor Stinner in :issue:`30459`.) (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 Deprecated
---------- ----------

View File

@ -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.

View File

@ -950,10 +950,6 @@ static PyObject *
call_trampoline(PyThreadState *tstate, PyObject* callback, call_trampoline(PyThreadState *tstate, PyObject* callback,
PyFrameObject *frame, int what, PyObject *arg) PyFrameObject *frame, int what, PyObject *arg)
{ {
if (PyFrame_FastToLocalsWithError(frame) < 0) {
return NULL;
}
PyObject *stack[3]; PyObject *stack[3];
stack[0] = (PyObject *)frame; stack[0] = (PyObject *)frame;
stack[1] = whatstrings[what]; stack[1] = whatstrings[what];
@ -962,7 +958,6 @@ call_trampoline(PyThreadState *tstate, PyObject* callback,
/* call the Python-level function */ /* call the Python-level function */
PyObject *result = _PyObject_FastCallTstate(tstate, callback, stack, 3); PyObject *result = _PyObject_FastCallTstate(tstate, callback, stack, 3);
PyFrame_LocalsToFast(frame, 1);
if (result == NULL) { if (result == NULL) {
PyTraceBack_Here(frame); PyTraceBack_Here(frame);
} }