File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1313#include <assert.h>
1414#include "mypyc_util.h"
1515
16+ #if CPY_3_12_FEATURES
17+ #include "internal/pycore_frame.h"
18+ #endif
19+
1620#ifdef __cplusplus
1721extern "C" {
1822#endif
@@ -389,6 +393,31 @@ _CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) {
389393 _PyObject_CallMethodIdObjArgs((self), (name), (arg), NULL)
390394#endif
391395
396+ #if CPY_3_12_FEATURES
397+
398+ // These are copied from genobject.c in Python 3.12
399+
400+ /* Returns a borrowed reference */
401+ static inline PyCodeObject *
402+ _PyGen_GetCode (PyGenObject * gen ) {
403+ _PyInterpreterFrame * frame = (_PyInterpreterFrame * )(gen -> gi_iframe );
404+ return frame -> f_code ;
405+ }
406+
407+ static int
408+ gen_is_coroutine (PyObject * o )
409+ {
410+ if (PyGen_CheckExact (o )) {
411+ PyCodeObject * code = _PyGen_GetCode ((PyGenObject * )o );
412+ if (code -> co_flags & CO_ITERABLE_COROUTINE ) {
413+ return 1 ;
414+ }
415+ }
416+ return 0 ;
417+ }
418+
419+ #else
420+
392421// Copied from genobject.c in Python 3.10
393422static int
394423gen_is_coroutine (PyObject * o )
@@ -402,6 +431,8 @@ gen_is_coroutine(PyObject *o)
402431 return 0 ;
403432}
404433
434+ #endif
435+
405436/*
406437 * This helper function returns an awaitable for `o`:
407438 * - `o` if `o` is a coroutine-object;
You can’t perform that action at this time.
0 commit comments