mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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:
parent
b68431fadb
commit
d7163bb35d
7 changed files with 46 additions and 10 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue