diff options
author | Mark Shannon <mark@hotpy.org> | 2021-07-26 11:22:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 11:22:16 +0100 |
commit | ae0a2b756255629140efcbe57fc2e714f0267aa3 (patch) | |
tree | 8710e8c7a398c9ec0add227fab607f367242a7e5 /Python/sysmodule.c | |
parent | 0363a4014d90df17a29042de008ef0b659f92505 (diff) | |
download | cpython-ae0a2b756255629140efcbe57fc2e714f0267aa3.tar.gz cpython-ae0a2b756255629140efcbe57fc2e714f0267aa3.zip |
bpo-44590: Lazily allocate frame objects (GH-27077)
* Convert "specials" array to InterpreterFrame struct, adding f_lasti, f_state and other non-debug FrameObject fields to it.
* Refactor, calls pushing the call to the interpreter upward toward _PyEval_Vector.
* Compute f_back when on thread stack, only filling in value when frame object outlives stack invocation.
* Move ownership of InterpreterFrame in generator from frame object to generator object.
* Do not create frame objects for Python calls.
* Do not create frame objects for generators.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index f809e2fda56..5dfa917e8ff 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -29,6 +29,7 @@ Data members: #include "code.h" #include "frameobject.h" // PyFrame_GetBack() +#include "pycore_frame.h" #include "pydtrace.h" #include "osdefs.h" // DELIM #include "stdlib_module_names.h" // _Py_stdlib_module_names @@ -1814,25 +1815,22 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - PyFrameObject *f = PyThreadState_GetFrame(tstate); + InterpreterFrame *frame = tstate->frame; - if (_PySys_Audit(tstate, "sys._getframe", "O", f) < 0) { - Py_DECREF(f); + if (_PySys_Audit(tstate, "sys._getframe", NULL) < 0) { return NULL; } - while (depth > 0 && f != NULL) { - PyFrameObject *back = PyFrame_GetBack(f); - Py_DECREF(f); - f = back; + while (depth > 0 && frame != NULL) { + frame = frame->previous; --depth; } - if (f == NULL) { + if (frame == NULL) { _PyErr_SetString(tstate, PyExc_ValueError, "call stack is not deep enough"); return NULL; } - return (PyObject*)f; + return _Py_XNewRef((PyObject *)_PyFrame_GetFrameObject(frame)); } /*[clinic input] |