diff options
author | Mark Shannon <mark@hotpy.org> | 2021-12-06 10:13:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-06 10:13:49 (GMT) |
commit | 299483c95d601ddcfdce2f96418b6499c1fc7b9f (patch) | |
tree | cb367a04d11b54d312305996bbc1039e1a47c929 /Python/frame.c | |
parent | f34d181fa15e1f082140a4e4a8fa3b77118f8e98 (diff) | |
download | cpython-299483c95d601ddcfdce2f96418b6499c1fc7b9f.zip cpython-299483c95d601ddcfdce2f96418b6499c1fc7b9f.tar.gz cpython-299483c95d601ddcfdce2f96418b6499c1fc7b9f.tar.bz2 |
bpo-45963: Make space for the InterpreterFrame of a generator in that generator. (GH-29891)
* Make generator, coroutine and async gen structs all the same size.
* Store interpreter frame in generator (and coroutine). Reduces the number of allocations neeeded for a generator from two to one.
Diffstat (limited to 'Python/frame.c')
-rw-r--r-- | Python/frame.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/Python/frame.c b/Python/frame.c index 21f2ced..da2c1c4 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -43,18 +43,12 @@ _PyFrame_MakeAndSetFrameObject(InterpreterFrame *frame) return f; } -InterpreterFrame * -_PyFrame_Copy(InterpreterFrame *frame) +void +_PyFrame_Copy(InterpreterFrame *src, InterpreterFrame *dest) { - assert(frame->stacktop >= frame->f_code->co_nlocalsplus); - Py_ssize_t size = ((char*)&frame->localsplus[frame->stacktop]) - (char *)frame; - InterpreterFrame *copy = PyMem_Malloc(size); - if (copy == NULL) { - PyErr_NoMemory(); - return NULL; - } - memcpy(copy, frame, size); - return copy; + assert(src->stacktop >= src->f_code->co_nlocalsplus); + Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src; + memcpy(dest, src, size); } static inline void @@ -112,7 +106,7 @@ _PyFrame_Clear(InterpreterFrame * frame) } Py_DECREF(f); } - assert(_PyFrame_GetStackPointer(frame) >= _PyFrame_Stackbase(frame)); + assert(frame->stacktop >= 0); for (int i = 0; i < frame->stacktop; i++) { Py_XDECREF(frame->localsplus[i]); } |