diff options
author | Mark Shannon <mark@hotpy.org> | 2022-03-25 12:57:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-25 12:57:50 (GMT) |
commit | d7163bb35d1ed46bde9affcd4eb267dfd0b703dd (patch) | |
tree | 50ced5b75c3e1579c4e23fd7c404ac33c53b7fc3 /Python/sysmodule.c | |
parent | b68431fadb3150134ac6ccbf501cdfeaf4c75678 (diff) | |
download | cpython-d7163bb35d1ed46bde9affcd4eb267dfd0b703dd.zip cpython-d7163bb35d1ed46bde9affcd4eb267dfd0b703dd.tar.gz cpython-d7163bb35d1ed46bde9affcd4eb267dfd0b703dd.tar.bz2 |
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.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c89f81f..6322af5 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -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); |