-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-120834: Use PyGenObject for generators, coroutines and async generators #120976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. So, I think it best to leave this as |
||
|
|
||
| /* Handle signals, pending calls, GIL drop request | ||
| and asynchronous exception */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need the line extension |
||
| /* 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) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
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.