Commit 570f187b authored by Stefan Behnel's avatar Stefan Behnel

Streamline some coroutine delegation code paths to avoid generic Python method calls.

Also make some C function signatures generic to avoid a dependency on concrete struct types in "far away" code.
parent f0bc3768
......@@ -13,8 +13,6 @@ typedef struct {
int ag_closed;
} __pyx_PyAsyncGenObject;
typedef struct __pyx_PyAsyncGenASend_struct __pyx_PyAsyncGenASend;
static PyTypeObject *__pyx__PyAsyncGenWrappedValueType = 0;
static PyTypeObject *__pyx__PyAsyncGenASendType = 0;
static PyTypeObject *__pyx__PyAsyncGenAThrowType = 0;
......@@ -23,10 +21,14 @@ static PyTypeObject *__pyx_AsyncGenType = 0;
#define __Pyx_AsyncGen_CheckExact(obj) (Py_TYPE(obj) == __pyx_AsyncGenType)
#define __pyx_PyAsyncGenASend_CheckExact(o) \
(Py_TYPE(o) == __pyx__PyAsyncGenASendType)
#define __pyx_PyAsyncGenAThrow_CheckExact(o) \
(Py_TYPE(o) == __pyx__PyAsyncGenAThrowType)
static PyObject *__Pyx_async_gen_anext(__pyx_PyAsyncGenObject *o);
static CYTHON_INLINE PyObject *__Pyx_async_gen_asend_iternext(__pyx_PyAsyncGenASend *o);
static PyObject *__Pyx_async_gen_asend_send(__pyx_PyAsyncGenASend *o, PyObject *arg);
static PyObject *__Pyx_async_gen_anext(PyObject *o);
static CYTHON_INLINE PyObject *__Pyx_async_gen_asend_iternext(PyObject *o);
static PyObject *__Pyx_async_gen_asend_send(PyObject *o, PyObject *arg);
static PyObject *__Pyx_async_gen_asend_close(PyObject *o, PyObject *args);
static PyObject *__Pyx_async_gen_athrow_close(PyObject *o, PyObject *args);
static PyObject *__Pyx__PyAsyncGenValueWrapperNew(PyObject *val);
......@@ -131,7 +133,7 @@ typedef enum {
__PYX_AWAITABLE_STATE_CLOSED, /* closed */
} __pyx_AwaitableState;
struct __pyx_PyAsyncGenASend_struct {
typedef struct {
PyObject_HEAD
__pyx_PyAsyncGenObject *ags_gen;
......@@ -139,7 +141,7 @@ struct __pyx_PyAsyncGenASend_struct {
PyObject *ags_sendval;
__pyx_AwaitableState ags_state;
};
} __pyx_PyAsyncGenASend;
typedef struct {
......@@ -237,8 +239,9 @@ __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o)
static PyObject *
__Pyx_async_gen_anext(__pyx_PyAsyncGenObject *o)
__Pyx_async_gen_anext(PyObject *g)
{
__pyx_PyAsyncGenObject *o = (__pyx_PyAsyncGenObject*) g;
if (__Pyx_async_gen_init_hooks(o)) {
return NULL;
}
......@@ -478,8 +481,9 @@ __Pyx_async_gen_asend_traverse(__pyx_PyAsyncGenASend *o, visitproc visit, void *
static PyObject *
__Pyx_async_gen_asend_send(__pyx_PyAsyncGenASend *o, PyObject *arg)
__Pyx_async_gen_asend_send(PyObject *g, PyObject *arg)
{
__pyx_PyAsyncGenASend *o = (__pyx_PyAsyncGenASend*) g;
PyObject *result;
if (unlikely(o->ags_state == __PYX_AWAITABLE_STATE_CLOSED)) {
......@@ -506,7 +510,7 @@ __Pyx_async_gen_asend_send(__pyx_PyAsyncGenASend *o, PyObject *arg)
static CYTHON_INLINE PyObject *
__Pyx_async_gen_asend_iternext(__pyx_PyAsyncGenASend *o)
__Pyx_async_gen_asend_iternext(PyObject *o)
{
return __Pyx_async_gen_asend_send(o, Py_None);
}
......@@ -534,8 +538,9 @@ __Pyx_async_gen_asend_throw(__pyx_PyAsyncGenASend *o, PyObject *args)
static PyObject *
__Pyx_async_gen_asend_close(__pyx_PyAsyncGenASend *o, CYTHON_UNUSED PyObject *args)
__Pyx_async_gen_asend_close(PyObject *g, CYTHON_UNUSED PyObject *args)
{
__pyx_PyAsyncGenASend *o = (__pyx_PyAsyncGenASend*) g;
o->ags_state = __PYX_AWAITABLE_STATE_CLOSED;
Py_RETURN_NONE;
}
......@@ -920,8 +925,9 @@ __Pyx_async_gen_athrow_iternext(__pyx_PyAsyncGenAThrow *o)
static PyObject *
__Pyx_async_gen_athrow_close(__pyx_PyAsyncGenAThrow *o, CYTHON_UNUSED PyObject *args)
__Pyx_async_gen_athrow_close(PyObject *g, CYTHON_UNUSED PyObject *args)
{
__pyx_PyAsyncGenAThrow *o = (__pyx_PyAsyncGenAThrow*) g;
o->agt_state = __PYX_AWAITABLE_STATE_CLOSED;
Py_RETURN_NONE;
}
......
......@@ -90,7 +90,7 @@ static CYTHON_INLINE PyObject* __Pyx_Coroutine_Yield_From(__pyx_CoroutineObject
#ifdef __Pyx_AsyncGen_USED
// inlined "__pyx_PyAsyncGenASend" handling to avoid the series of generic calls below
} else if (__pyx_PyAsyncGenASend_CheckExact(source)) {
retval = __Pyx_async_gen_asend_iternext((__pyx_PyAsyncGenASend *)source);
retval = __Pyx_async_gen_asend_iternext(source);
if (retval) {
Py_INCREF(source);
gen->yieldfrom = source;
......@@ -299,7 +299,7 @@ static PyObject *__Pyx__Coroutine_AsyncIterNext(PyObject *obj) {
static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *obj) {
#ifdef __Pyx_AsyncGen_USED
if (__Pyx_AsyncGen_CheckExact(obj)) {
return __Pyx_async_gen_anext((__pyx_PyAsyncGenObject*) obj);
return __Pyx_async_gen_anext(obj);
}
#endif
#if CYTHON_USE_ASYNC_SLOTS
......@@ -402,6 +402,7 @@ static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue); /*proto*/
static PyTypeObject *__pyx_CoroutineType = 0;
static PyTypeObject *__pyx_CoroutineAwaitType = 0;
#define __Pyx_Coroutine_CheckExact(obj) (Py_TYPE(obj) == __pyx_CoroutineType)
#define __Pyx_CoroutineAwait_CheckExact(obj) (Py_TYPE(obj) == __pyx_CoroutineAwaitType)
#define __Pyx_Coroutine_New(body, closure, name, qualname, module_name) \
__Pyx__Coroutine_New(__pyx_CoroutineType, body, closure, name, qualname, module_name)
......@@ -409,6 +410,14 @@ static PyTypeObject *__pyx_CoroutineAwaitType = 0;
static int __pyx_Coroutine_init(void); /*proto*/
static PyObject *__Pyx__Coroutine_await(PyObject *coroutine); /*proto*/
typedef struct {
PyObject_HEAD
PyObject *coroutine;
} __pyx_CoroutineAwaitObject;
static PyObject *__Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self); /*proto*/
static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args); /*proto*/
//////////////////// Generator.proto ////////////////////
......@@ -730,7 +739,7 @@ static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
#endif
#ifdef __Pyx_AsyncGen_USED
if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
ret = __Pyx_async_gen_asend_send((__pyx_PyAsyncGenASend *)yf, value);
ret = __Pyx_async_gen_asend_send(yf, value);
} else
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000
......@@ -780,6 +789,21 @@ static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
if (!retval)
return -1;
} else
if (__Pyx_CoroutineAwait_CheckExact(yf)) {
retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf);
if (!retval)
return -1;
} else
#endif
#ifdef __Pyx_AsyncGen_USED
if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
retval = __Pyx_async_gen_asend_close(yf, NULL);
// cannot fail
} else
if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) {
retval = __Pyx_async_gen_athrow_close(yf, NULL);
// cannot fail
} else
#endif
{
PyObject *meth;
......@@ -913,12 +937,13 @@ static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject
#endif
#ifdef __Pyx_Coroutine_USED
|| __Pyx_Coroutine_CheckExact(yf)
#endif
#ifdef __Pyx_AsyncGen_USED
|| __Pyx_AsyncGen_CheckExact(yf)
#endif
) {
ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit);
#ifdef __Pyx_Coroutine_USED
} else if (__Pyx_CoroutineAwait_CheckExact(yf)) {
ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit);
#endif
} else {
PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, PYIDENT("throw"));
if (unlikely(!meth)) {
......@@ -1275,11 +1300,6 @@ static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
//@requires: CoroutineBase
//@requires: PatchGeneratorABC
typedef struct {
PyObject_HEAD
PyObject *coroutine;
} __pyx_CoroutineAwaitObject;
static void __Pyx_CoroutineAwait_dealloc(PyObject *self) {
PyObject_GC_UnTrack(self);
Py_CLEAR(((__pyx_CoroutineAwaitObject*)self)->coroutine);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment