Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb698fe

Browse files
committed
Issue 24342: No need to use PyAPI_FUNC for _PyEval_ApplyCoroutineWrapper
1 parent ca82910 commit eb698fe

2 files changed

Lines changed: 30 additions & 29 deletions

File tree

Include/ceval.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
2525
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
2626
PyAPI_FUNC(void) _PyEval_SetCoroutineWrapper(PyObject *);
2727
PyAPI_FUNC(PyObject *) _PyEval_GetCoroutineWrapper(void);
28-
PyAPI_FUNC(PyObject *) _PyEval_ApplyCoroutineWrapper(PyObject *);
2928
#endif
3029

3130
struct _frame; /* Avoid including frameobject.h */

Python/ceval.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ static void format_exc_unbound(PyCodeObject *co, int oparg);
146146
static PyObject * unicode_concatenate(PyObject *, PyObject *,
147147
PyFrameObject *, unsigned char *);
148148
static PyObject * special_lookup(PyObject *, _Py_Identifier *);
149+
static PyObject * apply_coroutine_wrapper(PyObject *);
150+
149151

150152
#define NAME_ERROR_MSG \
151153
"name '%.200s' is not defined"
@@ -3935,7 +3937,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
39353937
return NULL;
39363938

39373939
if (co->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))
3938-
return _PyEval_ApplyCoroutineWrapper(gen);
3940+
return apply_coroutine_wrapper(gen);
39393941

39403942
return gen;
39413943
}
@@ -4401,33 +4403,6 @@ _PyEval_GetCoroutineWrapper(void)
44014403
return tstate->coroutine_wrapper;
44024404
}
44034405

4404-
PyObject *
4405-
_PyEval_ApplyCoroutineWrapper(PyObject *gen)
4406-
{
4407-
PyObject *wrapped;
4408-
PyThreadState *tstate = PyThreadState_GET();
4409-
PyObject *wrapper = tstate->coroutine_wrapper;
4410-
4411-
if (tstate->in_coroutine_wrapper) {
4412-
assert(wrapper != NULL);
4413-
PyErr_Format(PyExc_RuntimeError,
4414-
"coroutine wrapper %.150R attempted "
4415-
"to recursively wrap %.150R",
4416-
wrapper,
4417-
gen);
4418-
return NULL;
4419-
}
4420-
4421-
if (wrapper == NULL) {
4422-
return gen;
4423-
}
4424-
4425-
tstate->in_coroutine_wrapper = 1;
4426-
wrapped = PyObject_CallFunction(wrapper, "N", gen);
4427-
tstate->in_coroutine_wrapper = 0;
4428-
return wrapped;
4429-
}
4430-
44314406
PyObject *
44324407
PyEval_GetBuiltins(void)
44334408
{
@@ -5257,6 +5232,33 @@ unicode_concatenate(PyObject *v, PyObject *w,
52575232
return res;
52585233
}
52595234

5235+
static PyObject *
5236+
apply_coroutine_wrapper(PyObject *gen)
5237+
{
5238+
PyObject *wrapped;
5239+
PyThreadState *tstate = PyThreadState_GET();
5240+
PyObject *wrapper = tstate->coroutine_wrapper;
5241+
5242+
if (tstate->in_coroutine_wrapper) {
5243+
assert(wrapper != NULL);
5244+
PyErr_Format(PyExc_RuntimeError,
5245+
"coroutine wrapper %.200R attempted "
5246+
"to recursively wrap %.200R",
5247+
wrapper,
5248+
gen);
5249+
return NULL;
5250+
}
5251+
5252+
if (wrapper == NULL) {
5253+
return gen;
5254+
}
5255+
5256+
tstate->in_coroutine_wrapper = 1;
5257+
wrapped = PyObject_CallFunction(wrapper, "N", gen);
5258+
tstate->in_coroutine_wrapper = 0;
5259+
return wrapped;
5260+
}
5261+
52605262
#ifdef DYNAMIC_EXECUTION_PROFILE
52615263

52625264
static PyObject *

0 commit comments

Comments
 (0)