Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Include/cpython/genobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PyAPI_FUNC(PyCodeObject *) PyGen_GetCode(PyGenObject *gen);

/* --- PyCoroObject ------------------------------------------------------- */

typedef struct _PyCoroObject PyCoroObject;
typedef PyGenObject PyCoroObject;

PyAPI_DATA(PyTypeObject) PyCoro_Type;

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

/* --- Asynchronous Generators -------------------------------------------- */

typedef struct _PyAsyncGenObject PyAsyncGenObject;
typedef PyGenObject PyAsyncGenObject;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyCoroObject and PyAsyncGenObject are mentioned in the docs, so I think we need to leave this even though we're not using these names.


PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static inline void _Py_LeaveRecursiveCall(void) {

extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);

PyAPI_FUNC(PyObject *)_Py_MakeCoro(PyFunctionObject *func);
PyAPI_FUNC(PyGenObject *)_Py_MakeCoro(PyFunctionObject *func);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally have a convention that there is a correspondence between the C type and the Python class.
e.g. if PyXXX_Check[Exact](obj) is true, then it is safe to cast (PyXXXObject *)obj and vice-versa.
This sort of breaks that for coroutines and async generators.

So, I think it best to leave this as PyObject *. Does that make sense to you?


/* Handle signals, pending calls, GIL drop request
and asynchronous exception */
Expand Down
47 changes: 16 additions & 31 deletions Include/internal/pycore_genobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,25 @@ extern "C" {

#include "pycore_frame.h"

/* _PyGenObject_HEAD defines the initial segment of generator
and coroutine objects. */
#define _PyGenObject_HEAD(prefix) \
PyObject_HEAD \
/* List of weak reference. */ \
PyObject *prefix##_weakreflist; \
/* Name of the generator. */ \
PyObject *prefix##_name; \
/* Qualified name of the generator. */ \
PyObject *prefix##_qualname; \
_PyErr_StackItem prefix##_exc_state; \
PyObject *prefix##_origin_or_finalizer; \
char prefix##_hooks_inited; \
char prefix##_closed; \
char prefix##_running_async; \
/* The frame */ \
int8_t prefix##_frame_state; \
struct _PyInterpreterFrame prefix##_iframe; \

struct _PyGenObject {
/* The gi_ prefix is intended to remind of generator-iterator. */
_PyGenObject_HEAD(gi)
};

struct _PyCoroObject {
_PyGenObject_HEAD(cr)
/* The gi_ prefix is for generator-iterator. */
PyObject_HEAD \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the line extension \s any more.

/* List of weak reference. */ \
PyObject *gi_weakreflist; \
/* Name of the generator. */ \
PyObject *gi_name; \
/* Qualified name of the generator. */ \
PyObject *gi_qualname; \
_PyErr_StackItem gi_exc_state; \
PyObject *gi_cr_origin_or_ag_finalizer; \
char gi_hooks_inited; \
char gi_closed; \
char gi_running_async; \
/* The frame */ \
int8_t gi_frame_state; \
struct _PyInterpreterFrame gi_iframe; \
};

struct _PyAsyncGenObject {
_PyGenObject_HEAD(ag)
};

#undef _PyGenObject_HEAD

static inline
PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)
{
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extern int _PyWarnings_InitState(PyInterpreterState *interp);

extern PyObject* _PyWarnings_Init(void);

extern void _PyErr_WarnUnawaitedCoroutine(PyObject *coro);
extern void _PyErr_WarnUnawaitedAgenMethod(PyAsyncGenObject *agen, PyObject *method);
extern void _PyErr_WarnUnawaitedCoroutine(PyGenObject *coro);
extern void _PyErr_WarnUnawaitedAgenMethod(PyGenObject *agen, PyObject *method);

#ifdef __cplusplus
}
Expand Down
Loading