diff options
author | Mark Shannon <mark@hotpy.org> | 2022-01-20 11:46:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 11:46:39 +0000 |
commit | b04dfbbe4bd7071d46c8688c2263726ea31d33cd (patch) | |
tree | 17989daaffa384df343b53289845fba667e20acc /Objects/frameobject.c | |
parent | d05a66339b5e07d72d96e4c30a34cc3821bb61a2 (diff) | |
download | cpython-git-b04dfbbe4bd7071d46c8688c2263726ea31d33cd.tar.gz |
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 'Objects/frameobject.c')
-rw-r--r-- | Objects/frameobject.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 4dd2183040..81ad4cc65d 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -242,6 +242,7 @@ mark_stacks(PyCodeObject *code_obj, int len) break; } case JUMP_ABSOLUTE: + case JUMP_NO_INTERRUPT: j = get_arg(code, i); assert(j < len); if (stacks[j] == UNINITIALIZED && j < i) { @@ -625,7 +626,7 @@ frame_dealloc(PyFrameObject *f) { /* It is the responsibility of the owning generator/coroutine * to have cleared the generator pointer */ - assert(f->f_frame->generator == NULL); + assert(!f->f_frame->is_generator); if (_PyObject_GC_IS_TRACKED(f)) { _PyObject_GC_UNTRACK(f); @@ -698,8 +699,11 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) "cannot clear an executing frame"); return NULL; } - if (f->f_frame->generator) { - _PyGen_Finalize(f->f_frame->generator); + if (f->f_frame->is_generator) { + assert(!f->f_owns_frame); + size_t offset_in_gen = offsetof(PyGenObject, gi_iframe); + PyObject *gen = (PyObject *)(((char *)f->f_frame) - offset_in_gen); + _PyGen_Finalize(gen); } (void)frame_tp_clear(f); Py_RETURN_NONE; |