Skip to content

Commit e6ced48

Browse files
authored
[mypyc] Use PyGen_GetCode in gen_is_coroutine (#17931)
Instead of copying the implementation of `_PyGen_GetCode` every time it changes in cpython, use the public `PyGen_GetCode` function. The current implementation would break for Python 3.14 as it has been changed upstream in python/cpython#120835.
1 parent 706680f commit e6ced48

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

mypyc/lib-rt/pythonsupport.h

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -402,45 +402,15 @@ _CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) {
402402
PyObject_CallMethodObjArgs((self), (name), (arg), NULL)
403403
#endif
404404

405-
#if CPY_3_13_FEATURES
406-
407-
// These are copied from genobject.c in Python 3.13
408-
409-
/* Returns a borrowed reference */
410-
static inline PyCodeObject *
411-
_PyGen_GetCode(PyGenObject *gen) {
412-
_PyInterpreterFrame *frame = (_PyInterpreterFrame *)(gen->gi_iframe);
413-
return _PyFrame_GetCode(frame);
414-
}
415-
416-
static int
417-
gen_is_coroutine(PyObject *o)
418-
{
419-
if (PyGen_CheckExact(o)) {
420-
PyCodeObject *code = _PyGen_GetCode((PyGenObject*)o);
421-
if (code->co_flags & CO_ITERABLE_COROUTINE) {
422-
return 1;
423-
}
424-
}
425-
return 0;
426-
}
427-
428-
#elif CPY_3_12_FEATURES
405+
#if CPY_3_12_FEATURES
429406

430407
// These are copied from genobject.c in Python 3.12
431408

432-
/* Returns a borrowed reference */
433-
static inline PyCodeObject *
434-
_PyGen_GetCode(PyGenObject *gen) {
435-
_PyInterpreterFrame *frame = (_PyInterpreterFrame *)(gen->gi_iframe);
436-
return frame->f_code;
437-
}
438-
439409
static int
440410
gen_is_coroutine(PyObject *o)
441411
{
442412
if (PyGen_CheckExact(o)) {
443-
PyCodeObject *code = _PyGen_GetCode((PyGenObject*)o);
413+
PyCodeObject *code = PyGen_GetCode((PyGenObject*)o);
444414
if (code->co_flags & CO_ITERABLE_COROUTINE) {
445415
return 1;
446416
}

0 commit comments

Comments
 (0)