bpo-42197: Don't create f_locals dictionary unless we actually need it. (GH-32055)
* `PyFrame_FastToLocalsWithError` and `PyFrame_LocalsToFast` are no longer called during profile and tracing. (Contributed by Fabio Zadrozny) * Make accesses to a frame's `f_locals` safe from C code, not relying on calls to `PyFrame_FastToLocals` or `PyFrame_LocalsToFast`. * Document new `PyFrame_GetLocals` C-API function.
This commit is contained in:
@@ -924,15 +924,19 @@ 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];
|
||||
stack[2] = (arg != NULL) ? arg : Py_None;
|
||||
|
||||
/* Discard any previous modifications the frame's fast locals */
|
||||
if (frame->f_fast_as_locals) {
|
||||
if (PyFrame_FastToLocalsWithError(frame) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* call the Python-level function */
|
||||
PyObject *result = _PyObject_FastCallTstate(tstate, callback, stack, 3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user