diff options
author | Mark Shannon <mark@hotpy.org> | 2022-01-20 11:46:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 11:46:39 (GMT) |
commit | b04dfbbe4bd7071d46c8688c2263726ea31d33cd (patch) | |
tree | 17989daaffa384df343b53289845fba667e20acc /Python/frame.c | |
parent | d05a66339b5e07d72d96e4c30a34cc3821bb61a2 (diff) | |
download | cpython-b04dfbbe4bd7071d46c8688c2263726ea31d33cd.zip cpython-b04dfbbe4bd7071d46c8688c2263726ea31d33cd.tar.gz cpython-b04dfbbe4bd7071d46c8688c2263726ea31d33cd.tar.bz2 |
bpo-46409: Make generators in bytecode (GH-30633)
* Add RETURN_GENERATOR and JUMP_NO_INTERRUPT opcodes.
* Trim frame and generator by word each.
* Minor refactor of frame.c
* Update test.test_sys to account for smaller frames.
* Treat generator functions as normal functions when evaluating and specializing.
Diffstat (limited to 'Python/frame.c')
-rw-r--r-- | Python/frame.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/Python/frame.c b/Python/frame.c index da2c1c4..9578747 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -3,6 +3,7 @@ #include "frameobject.h" #include "pycore_frame.h" #include "pycore_object.h" // _PyObject_GC_UNTRACK() +#include "opcode.h" int _PyFrame_Traverse(InterpreterFrame *frame, visitproc visit, void *arg) @@ -51,15 +52,6 @@ _PyFrame_Copy(InterpreterFrame *src, InterpreterFrame *dest) memcpy(dest, src, size); } -static inline void -clear_specials(InterpreterFrame *frame) -{ - frame->generator = NULL; - Py_XDECREF(frame->frame_obj); - Py_XDECREF(frame->f_locals); - Py_DECREF(frame->f_func); - Py_DECREF(frame->f_code); -} static void take_ownership(PyFrameObject *f, InterpreterFrame *frame) @@ -94,8 +86,8 @@ void _PyFrame_Clear(InterpreterFrame * frame) { /* It is the responsibility of the owning generator/coroutine - * to have cleared the generator pointer */ - assert(frame->generator == NULL); + * to have cleared the enclosing generator, if any. */ + assert(!frame->is_generator); if (frame->frame_obj) { PyFrameObject *f = frame->frame_obj; frame->frame_obj = NULL; @@ -110,5 +102,8 @@ _PyFrame_Clear(InterpreterFrame * frame) for (int i = 0; i < frame->stacktop; i++) { Py_XDECREF(frame->localsplus[i]); } - clear_specials(frame); + Py_XDECREF(frame->frame_obj); + Py_XDECREF(frame->f_locals); + Py_DECREF(frame->f_func); + Py_DECREF(frame->f_code); } |