summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-12-06 10:13:49 (GMT)
committerGitHub <noreply@github.com>2021-12-06 10:13:49 (GMT)
commit299483c95d601ddcfdce2f96418b6499c1fc7b9f (patch)
treecb367a04d11b54d312305996bbc1039e1a47c929 /Include
parentf34d181fa15e1f082140a4e4a8fa3b77118f8e98 (diff)
downloadcpython-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 'Include')
-rw-r--r--Include/cpython/genobject.h23
-rw-r--r--Include/internal/pycore_ceval.h2
-rw-r--r--Include/internal/pycore_frame.h2
3 files changed, 10 insertions, 17 deletions
diff --git a/Include/cpython/genobject.h b/Include/cpython/genobject.h
index 8f87cf5..ad2818e 100644
--- a/Include/cpython/genobject.h
+++ b/Include/cpython/genobject.h
@@ -14,7 +14,6 @@ extern "C" {
#define _PyGenObject_HEAD(prefix) \
PyObject_HEAD \
/* Note: gi_frame can be NULL if the generator is "finished" */ \
- struct _interpreter_frame *prefix##_xframe; \
/* The code object backing the generator */ \
PyCodeObject *prefix##_code; \
/* List of weak reference. */ \
@@ -23,7 +22,14 @@ extern "C" {
PyObject *prefix##_name; \
/* Qualified name of the generator. */ \
PyObject *prefix##_qualname; \
- _PyErr_StackItem prefix##_exc_state;
+ _PyErr_StackItem prefix##_exc_state; \
+ PyObject *prefix##_origin_or_finalizer; \
+ char prefix##_hooks_inited; \
+ char prefix##_closed; \
+ char prefix##_running_async; \
+ /* The frame */ \
+ char prefix##_frame_valid; \
+ PyObject *prefix##_iframe[1];
typedef struct {
/* The gi_ prefix is intended to remind of generator-iterator. */
@@ -48,7 +54,6 @@ PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
typedef struct {
_PyGenObject_HEAD(cr)
- PyObject *cr_origin;
} PyCoroObject;
PyAPI_DATA(PyTypeObject) PyCoro_Type;
@@ -64,18 +69,6 @@ PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
typedef struct {
_PyGenObject_HEAD(ag)
- PyObject *ag_finalizer;
-
- /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks
- were called on the generator, to avoid calling them more
- than once. */
- int ag_hooks_inited;
-
- /* Flag is set to 1 when aclose() is called for the first time, or
- when a StopAsyncIteration exception is raised. */
- int ag_closed;
-
- int ag_running_async;
} PyAsyncGenObject;
PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h
index 9987f20..26d5677 100644
--- a/Include/internal/pycore_ceval.h
+++ b/Include/internal/pycore_ceval.h
@@ -113,7 +113,7 @@ static inline void _Py_LeaveRecursiveCall_inline(void) {
struct _interpreter_frame *_PyEval_GetFrame(void);
-PyObject *_Py_MakeCoro(PyFunctionObject *func, struct _interpreter_frame *);
+PyObject *_Py_MakeCoro(PyFunctionObject *func);
#ifdef __cplusplus
}
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
index b0e51a6..f4f7ab9 100644
--- a/Include/internal/pycore_frame.h
+++ b/Include/internal/pycore_frame.h
@@ -74,7 +74,7 @@ static inline void _PyFrame_StackPush(InterpreterFrame *f, PyObject *value) {
#define FRAME_SPECIALS_SIZE ((sizeof(InterpreterFrame)-1)/sizeof(PyObject *))
-InterpreterFrame *_PyFrame_Copy(InterpreterFrame *frame);
+void _PyFrame_Copy(InterpreterFrame *src, InterpreterFrame *dest);
static inline void
_PyFrame_InitializeSpecials(