From b04dfbbe4bd7071d46c8688c2263726ea31d33cd Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 20 Jan 2022 11:46:39 +0000 Subject: 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. --- Python/frame.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'Python/frame.c') diff --git a/Python/frame.c b/Python/frame.c index da2c1c4aec..9578747c19 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); } -- cgit v1.2.1