Skip to content

Commit 3e0341a

Browse files
committed
pythongh-120834: Use PyGenObject for generators, coroutines and async generators
1 parent 375b723 commit 3e0341a

File tree

6 files changed

+129
-211
lines changed

6 files changed

+129
-211
lines changed

Include/cpython/genobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PyAPI_FUNC(PyCodeObject *) PyGen_GetCode(PyGenObject *gen);
2424

2525
/* --- PyCoroObject ------------------------------------------------------- */
2626

27-
typedef struct _PyCoroObject PyCoroObject;
27+
typedef PyGenObject PyCoroObject;
2828

2929
PyAPI_DATA(PyTypeObject) PyCoro_Type;
3030

@@ -35,7 +35,7 @@ PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
3535

3636
/* --- Asynchronous Generators -------------------------------------------- */
3737

38-
typedef struct _PyAsyncGenObject PyAsyncGenObject;
38+
typedef PyGenObject PyAsyncGenObject;
3939

4040
PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
4141
PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static inline void _Py_LeaveRecursiveCall(void) {
232232

233233
extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
234234

235-
PyAPI_FUNC(PyObject *)_Py_MakeCoro(PyFunctionObject *func);
235+
PyAPI_FUNC(PyGenObject *)_Py_MakeCoro(PyFunctionObject *func);
236236

237237
/* Handle signals, pending calls, GIL drop request
238238
and asynchronous exception */

Include/internal/pycore_genobject.h

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,25 @@ extern "C" {
1010

1111
#include "pycore_frame.h"
1212

13-
/* _PyGenObject_HEAD defines the initial segment of generator
14-
and coroutine objects. */
15-
#define _PyGenObject_HEAD(prefix) \
16-
PyObject_HEAD \
17-
/* List of weak reference. */ \
18-
PyObject *prefix##_weakreflist; \
19-
/* Name of the generator. */ \
20-
PyObject *prefix##_name; \
21-
/* Qualified name of the generator. */ \
22-
PyObject *prefix##_qualname; \
23-
_PyErr_StackItem prefix##_exc_state; \
24-
PyObject *prefix##_origin_or_finalizer; \
25-
char prefix##_hooks_inited; \
26-
char prefix##_closed; \
27-
char prefix##_running_async; \
28-
/* The frame */ \
29-
int8_t prefix##_frame_state; \
30-
struct _PyInterpreterFrame prefix##_iframe; \
31-
3213
struct _PyGenObject {
33-
/* The gi_ prefix is intended to remind of generator-iterator. */
34-
_PyGenObject_HEAD(gi)
35-
};
36-
37-
struct _PyCoroObject {
38-
_PyGenObject_HEAD(cr)
14+
/* The gi_ prefix is for generator-iterator. */
15+
PyObject_HEAD \
16+
/* List of weak reference. */ \
17+
PyObject *gi_weakreflist; \
18+
/* Name of the generator. */ \
19+
PyObject *gi_name; \
20+
/* Qualified name of the generator. */ \
21+
PyObject *gi_qualname; \
22+
_PyErr_StackItem gi_exc_state; \
23+
PyObject *gi_cr_origin_or_ag_finalizer; \
24+
char gi_hooks_inited; \
25+
char gi_closed; \
26+
char gi_running_async; \
27+
/* The frame */ \
28+
int8_t gi_frame_state; \
29+
struct _PyInterpreterFrame gi_iframe; \
3930
};
4031

41-
struct _PyAsyncGenObject {
42-
_PyGenObject_HEAD(ag)
43-
};
44-
45-
#undef _PyGenObject_HEAD
46-
4732
static inline
4833
PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)
4934
{

Include/internal/pycore_warnings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ extern int _PyWarnings_InitState(PyInterpreterState *interp);
2222

2323
extern PyObject* _PyWarnings_Init(void);
2424

25-
extern void _PyErr_WarnUnawaitedCoroutine(PyObject *coro);
26-
extern void _PyErr_WarnUnawaitedAgenMethod(PyAsyncGenObject *agen, PyObject *method);
25+
extern void _PyErr_WarnUnawaitedCoroutine(PyGenObject *coro);
26+
extern void _PyErr_WarnUnawaitedAgenMethod(PyGenObject *agen, PyObject *method);
2727

2828
#ifdef __cplusplus
2929
}

0 commit comments

Comments
 (0)