Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
e3ec8cd8
Commit
e3ec8cd8
authored
Jun 05, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update PEP 525 implementation to match the code in Py3.6/7 (currently non-functional)
parent
32192948
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
195 additions
and
132 deletions
+195
-132
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+2
-1
Cython/Utility/AsyncGen.c
Cython/Utility/AsyncGen.c
+190
-128
Cython/Utility/Coroutine.c
Cython/Utility/Coroutine.c
+3
-3
No files found.
Cython/Compiler/ExprNodes.py
View file @
e3ec8cd8
...
...
@@ -9473,7 +9473,8 @@ class YieldExprNode(ExprNode):
code
.
putln
(
"%s->resume_label = %d;"
%
(
Naming
.
generator_cname
,
label_num
))
if
self
.
in_async_gen
and
not
self
.
is_await
:
code
.
putln
(
"return __pyx__PyAsyncGenWrapValue(%s);"
%
Naming
.
retval_cname
)
# __Pyx__PyAsyncGenValueWrapperNew() steals a reference to the return value
code
.
putln
(
"return __Pyx__PyAsyncGenValueWrapperNew(%s);"
%
Naming
.
retval_cname
)
else
:
code
.
putln
(
"return %s;"
%
Naming
.
retval_cname
)
...
...
Cython/Utility/AsyncGen.c
View file @
e3ec8cd8
...
...
@@ -10,7 +10,7 @@ typedef struct {
PyObject
*
ag_finalizer
;
int
ag_hooks_inited
;
int
ag_closed
;
}
__pyx_AsyncGenObject
;
}
__pyx_
Py
AsyncGenObject
;
static
PyTypeObject
*
__pyx__PyAsyncGenWrappedValueType
=
0
;
...
...
@@ -19,32 +19,36 @@ static PyTypeObject *__pyx__PyAsyncGenAThrowType = 0;
static
PyTypeObject
*
__pyx_AsyncGenType
=
0
;
#define __Pyx_AsyncGen_CheckExact(obj) (Py_TYPE(obj) == __pyx_AsyncGenType)
static
PyObject
*
__Pyx_
AsyncGen_AN
ext
(
PyObject
*
o
);
static
PyObject
*
__Pyx_
async_gen_an
ext
(
PyObject
*
o
);
static
PyObject
*
__
pyx__PyAsyncGenWrapValue
(
PyObject
*
val
);
static
PyObject
*
__
Pyx__PyAsyncGenValueWrapperNew
(
PyObject
*
val
);
static
__pyx_CoroutineObject
*
__Pyx_AsyncGen_New
(
__pyx_coroutine_body_t
body
,
PyObject
*
closure
,
PyObject
*
name
,
PyObject
*
qualname
,
PyObject
*
module_name
)
{
__pyx_
AsyncGenObject
*
gen
=
PyObject_GC_New
(
__pyx_
AsyncGenObject
,
__pyx_AsyncGenType
);
__pyx_
PyAsyncGenObject
*
gen
=
PyObject_GC_New
(
__pyx_Py
AsyncGenObject
,
__pyx_AsyncGenType
);
if
(
unlikely
(
!
gen
))
return
NULL
;
gen
->
ag_finalizer
=
NULL
;
gen
->
ag_hooks_inited
=
0
;
gen
->
ag_closed
=
0
;
gen
->
ag_hooks_inited
=
0
;
return
__Pyx__Coroutine_NewInit
((
__pyx_CoroutineObject
*
)
gen
,
body
,
closure
,
name
,
qualname
,
module_name
);
}
static
int
__pyx_AsyncGen_init
(
void
);
static
void
__Pyx_PyAsyncGen_Fini
(
void
);
//////////////////// AsyncGenerator.cleanup ////////////////////
__Pyx_PyAsyncGen_Fini
();
//////////////////// AsyncGeneratorInitFinalizer ////////////////////
// this is separated out because it needs more adaptation
#if PY_VERSION_HEX < 0x030600B0
static
int
__Pyx_async_gen_init_
finalizer
(
__pyx_
AsyncGenObject
*
o
)
{
static
int
__Pyx_async_gen_init_
hooks
(
__pyx_Py
AsyncGenObject
*
o
)
{
#if 0
// TODO: implement finalizer support in older Python versions
PyThreadState *tstate;
...
...
@@ -104,31 +108,43 @@ return next yielded value or raise StopIteration.");
// COPY STARTS HERE:
static
PyObject
*
__Pyx_async_gen_asend_new
(
__pyx_AsyncGenObject
*
,
PyObject
*
);
static
PyObject
*
__Pyx_async_gen_athrow_new
(
__pyx_AsyncGenObject
*
,
PyObject
*
);
static
PyObject
*
__Pyx_async_gen_asend_new
(
__pyx_
Py
AsyncGenObject
*
,
PyObject
*
);
static
PyObject
*
__Pyx_async_gen_athrow_new
(
__pyx_
Py
AsyncGenObject
*
,
PyObject
*
);
static
const
char
*
__Pyx_NON_INIT_CORO_MSG
=
"can't send non-None value to a just-started coroutine"
;
static
const
char
*
__Pyx_ASYNC_GEN_IGNORED_EXIT_MSG
=
"async generator ignored GeneratorExit"
;
typedef
enum
{
__PYX_AWAITABLE_STATE_INIT
,
/* new awaitable, has not yet been iterated */
__PYX_AWAITABLE_STATE_ITER
,
/* being iterated */
__PYX_AWAITABLE_STATE_CLOSED
,
/* closed */
}
__pyx_AwaitableState
;
typedef
struct
{
PyObject_HEAD
__pyx_AsyncGenObject
*
aw_gen
;
PyObject
*
aw_sendval
;
int
aw_state
;
__pyx_PyAsyncGenObject
*
ags_gen
;
/* Can be NULL, when in the __anext__() mode (equivalent of "asend(None)") */
PyObject
*
ags_sendval
;
__pyx_AwaitableState
ags_state
;
}
__pyx_PyAsyncGenASend
;
typedef
struct
{
PyObject_HEAD
__pyx_AsyncGenObject
*
ac_gen
;
PyObject
*
ac_args
;
int
ac_state
;
__pyx_PyAsyncGenObject
*
agt_gen
;
/* Can be NULL, when in the "aclose()" mode (equivalent of "athrow(GeneratorExit)") */
PyObject
*
agt_args
;
__pyx_AwaitableState
agt_state
;
}
__pyx_PyAsyncGenAThrow
;
typedef
struct
{
PyObject_HEAD
PyObject
*
val
;
PyObject
*
agw_
val
;
}
__pyx__PyAsyncGenWrappedValue
;
...
...
@@ -142,11 +158,11 @@ typedef struct {
__anext__ call.
*/
static
__pyx__PyAsyncGenWrappedValue
*
__Pyx_ag_value_f
l
[
_PyAsyncGen_MAXFREELIST
];
static
int
__Pyx_ag_value_f
l
_free
=
0
;
static
__pyx__PyAsyncGenWrappedValue
*
__Pyx_ag_value_f
reelist
[
_PyAsyncGen_MAXFREELIST
];
static
int
__Pyx_ag_value_f
reelist
_free
=
0
;
static
__pyx_PyAsyncGenASend
*
__Pyx_ag_asend_f
l
[
_PyAsyncGen_MAXFREELIST
];
static
int
__Pyx_ag_asend_f
l
_free
=
0
;
static
__pyx_PyAsyncGenASend
*
__Pyx_ag_asend_f
reelist
[
_PyAsyncGen_MAXFREELIST
];
static
int
__Pyx_ag_asend_f
reelist
_free
=
0
;
#define __pyx__PyAsyncGenWrappedValue_CheckExact(o) \
(Py_TYPE(o) == __pyx__PyAsyncGenWrappedValueType)
...
...
@@ -156,7 +172,7 @@ static int __Pyx_ag_asend_fl_free = 0;
static
int
__Pyx_async_gen_traverse
(
__pyx_AsyncGenObject
*
gen
,
visitproc
visit
,
void
*
arg
)
__Pyx_async_gen_traverse
(
__pyx_
Py
AsyncGenObject
*
gen
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
gen
->
ag_finalizer
);
return
__Pyx_Coroutine_traverse
((
__pyx_CoroutineObject
*
)
gen
,
visit
,
arg
);
...
...
@@ -173,7 +189,7 @@ __Pyx_async_gen_repr(__pyx_CoroutineObject *o)
#if PY_VERSION_HEX >= 0x030600B0
static
int
__Pyx_async_gen_init_
finalizer
(
__pyx_
AsyncGenObject
*
o
)
__Pyx_async_gen_init_
hooks
(
__pyx_Py
AsyncGenObject
*
o
)
{
PyThreadState
*
tstate
;
PyObject
*
finalizer
;
...
...
@@ -212,10 +228,9 @@ __Pyx_async_gen_init_finalizer(__pyx_AsyncGenObject *o)
static
PyObject
*
__Pyx_
AsyncGen_ANext
(
PyObject
*
self
)
__Pyx_
async_gen_anext
(
__pyx_PyAsyncGenObject
*
o
)
{
__pyx_AsyncGenObject
*
o
=
(
__pyx_AsyncGenObject
*
)
self
;
if
(
__Pyx_async_gen_init_finalizer
(
o
))
{
if
(
__Pyx_async_gen_init_hooks
(
o
))
{
return
NULL
;
}
return
__Pyx_async_gen_asend_new
(
o
,
NULL
);
...
...
@@ -223,9 +238,9 @@ __Pyx_AsyncGen_ANext(PyObject *self)
static
PyObject
*
__Pyx_async_gen_asend
(
__pyx_AsyncGenObject
*
o
,
PyObject
*
arg
)
__Pyx_async_gen_asend
(
__pyx_
Py
AsyncGenObject
*
o
,
PyObject
*
arg
)
{
if
(
__Pyx_async_gen_init_
finalizer
(
o
))
{
if
(
__Pyx_async_gen_init_
hooks
(
o
))
{
return
NULL
;
}
return
__Pyx_async_gen_asend_new
(
o
,
arg
);
...
...
@@ -233,18 +248,18 @@ __Pyx_async_gen_asend(__pyx_AsyncGenObject *o, PyObject *arg)
static
PyObject
*
__Pyx_async_gen_aclose
(
__pyx_AsyncGenObject
*
o
,
CYTHON_UNUSED
PyObject
*
arg
)
__Pyx_async_gen_aclose
(
__pyx_
Py
AsyncGenObject
*
o
,
CYTHON_UNUSED
PyObject
*
arg
)
{
if
(
__Pyx_async_gen_init_
finalizer
(
o
))
{
if
(
__Pyx_async_gen_init_
hooks
(
o
))
{
return
NULL
;
}
return
__Pyx_async_gen_athrow_new
(
o
,
NULL
);
}
static
PyObject
*
__Pyx_async_gen_athrow
(
__pyx_AsyncGenObject
*
o
,
PyObject
*
args
)
__Pyx_async_gen_athrow
(
__pyx_
Py
AsyncGenObject
*
o
,
PyObject
*
args
)
{
if
(
__Pyx_async_gen_init_
finalizer
(
o
))
{
if
(
__Pyx_async_gen_init_
hooks
(
o
))
{
return
NULL
;
}
return
__Pyx_async_gen_athrow_new
(
o
,
args
);
...
...
@@ -262,9 +277,9 @@ static PyGetSetDef __Pyx_async_gen_getsetlist[] = {
};
static
PyMemberDef
__Pyx_async_gen_memberlist
[]
=
{
//REMOVED: {"ag_frame", T_OBJECT, offsetof(__pyx_AsyncGenObject, ag_frame), READONLY},
//REMOVED: {"ag_frame", T_OBJECT, offsetof(__pyx_
Py
AsyncGenObject, ag_frame), READONLY},
{
"ag_running"
,
T_BOOL
,
offsetof
(
__pyx_CoroutineObject
,
is_running
),
READONLY
,
NULL
},
//REMOVED: {"ag_code", T_OBJECT, offsetof(__pyx_AsyncGenObject, ag_code), READONLY},
//REMOVED: {"ag_code", T_OBJECT, offsetof(__pyx_
Py
AsyncGenObject, ag_code), READONLY},
//ADDED: "ag_await"
{(
char
*
)
"ag_await"
,
T_OBJECT
,
offsetof
(
__pyx_CoroutineObject
,
yieldfrom
),
READONLY
,
(
char
*
)
PyDoc_STR
(
"object being awaited on, or None"
)},
...
...
@@ -291,14 +306,14 @@ static PyMethodDef __Pyx_async_gen_methods[] = {
static
PyAsyncMethods
__Pyx_async_gen_as_async
=
{
0
,
/* am_await */
PyObject_SelfIter
,
/* am_aiter */
(
unaryfunc
)
__Pyx_
AsyncGen_AN
ext
/* am_anext */
(
unaryfunc
)
__Pyx_
async_gen_an
ext
/* am_anext */
};
PyTypeObject
__pyx_AsyncGenType_type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"async_generator"
,
/* tp_name */
sizeof
(
__pyx_AsyncGenObject
),
/* tp_basicsize */
sizeof
(
__pyx_
Py
AsyncGenObject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
/* methods */
(
destructor
)
__Pyx_Coroutine_check_and_dealloc
,
/* tp_dealloc */
...
...
@@ -320,7 +335,8 @@ PyTypeObject __pyx_AsyncGenType_type = {
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
|
Py_TPFLAGS_HAVE_FINALIZE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
|
Py_TPFLAGS_HAVE_FINALIZE
,
/* tp_flags */
0
,
/* tp_doc */
(
traverseproc
)
__Pyx_async_gen_traverse
,
/* tp_traverse */
0
,
/* tp_clear */
...
...
@@ -366,20 +382,20 @@ PyTypeObject __pyx_AsyncGenType_type = {
static
int
__Pyx_PyAsyncGen_ClearFreeLists
(
void
)
{
int
ret
=
__Pyx_ag_value_f
l_free
+
__Pyx_ag_asend_fl
_free
;
int
ret
=
__Pyx_ag_value_f
reelist_free
+
__Pyx_ag_asend_freelist
_free
;
while
(
__Pyx_ag_value_f
l
_free
)
{
while
(
__Pyx_ag_value_f
reelist
_free
)
{
__pyx__PyAsyncGenWrappedValue
*
o
;
o
=
__Pyx_ag_value_f
l
[
--
__Pyx_ag_value_fl
_free
];
o
=
__Pyx_ag_value_f
reelist
[
--
__Pyx_ag_value_freelist
_free
];
assert
(
__pyx__PyAsyncGenWrappedValue_CheckExact
(
o
));
PyObject_Del
(
o
);
PyObject_
GC_
Del
(
o
);
}
while
(
__Pyx_ag_asend_f
l
_free
)
{
while
(
__Pyx_ag_asend_f
reelist
_free
)
{
__pyx_PyAsyncGenASend
*
o
;
o
=
__Pyx_ag_asend_f
l
[
--
__Pyx_ag_asend_fl
_free
];
o
=
__Pyx_ag_asend_f
reelist
[
--
__Pyx_ag_asend_freelist
_free
];
assert
(
Py_TYPE
(
o
)
==
__pyx__PyAsyncGenASendType
);
PyObject_Del
(
o
);
PyObject_
GC_
Del
(
o
);
}
return
ret
;
...
...
@@ -393,7 +409,7 @@ __Pyx_PyAsyncGen_Fini(void)
static
PyObject
*
__Pyx_async_gen_unwrap_value
(
__pyx_AsyncGenObject
*
gen
,
PyObject
*
result
)
__Pyx_async_gen_unwrap_value
(
__pyx_
Py
AsyncGenObject
*
gen
,
PyObject
*
result
)
{
if
(
result
==
NULL
)
{
PyObject
*
exc_type
=
PyErr_Occurred
();
...
...
@@ -412,7 +428,7 @@ __Pyx_async_gen_unwrap_value(__pyx_AsyncGenObject *gen, PyObject *result)
if
(
__pyx__PyAsyncGenWrappedValue_CheckExact
(
result
))
{
/* async yield */
__Pyx_ReturnWithStopIteration
(((
__pyx__PyAsyncGenWrappedValue
*
)
result
)
->
val
);
__Pyx_ReturnWithStopIteration
(((
__pyx__PyAsyncGenWrappedValue
*
)
result
)
->
agw_
val
);
Py_DECREF
(
result
);
return
NULL
;
}
...
...
@@ -427,39 +443,48 @@ __Pyx_async_gen_unwrap_value(__pyx_AsyncGenObject *gen, PyObject *result)
static
void
__Pyx_async_gen_asend_dealloc
(
__pyx_PyAsyncGenASend
*
o
)
{
Py_CLEAR
(
o
->
aw_gen
);
Py_CLEAR
(
o
->
aw_sendval
);
if
(
__Pyx_ag_asend_fl_free
<
_PyAsyncGen_MAXFREELIST
)
{
_PyObject_GC_UNTRACK
((
PyObject
*
)
o
);
Py_CLEAR
(
o
->
ags_gen
);
Py_CLEAR
(
o
->
ags_sendval
);
if
(
__Pyx_ag_asend_freelist_free
<
_PyAsyncGen_MAXFREELIST
)
{
assert
(
__pyx_PyAsyncGenASend_CheckExact
(
o
));
__Pyx_ag_asend_f
l
[
__Pyx_ag_asend_fl
_free
++
]
=
o
;
__Pyx_ag_asend_f
reelist
[
__Pyx_ag_asend_freelist
_free
++
]
=
o
;
}
else
{
PyObject_Del
(
o
);
PyObject_
GC_
Del
(
o
);
}
}
static
int
__Pyx_async_gen_asend_traverse
(
__pyx_PyAsyncGenASend
*
o
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
o
->
ags_gen
);
Py_VISIT
(
o
->
ags_sendval
);
return
0
;
}
static
PyObject
*
__Pyx_async_gen_asend_send
(
__pyx_PyAsyncGenASend
*
o
,
PyObject
*
arg
)
{
PyObject
*
result
;
if
(
o
->
a
w_state
==
2
)
{
if
(
o
->
a
gs_state
==
__PYX_AWAITABLE_STATE_CLOSED
)
{
PyErr_SetNone
(
PyExc_StopIteration
);
return
NULL
;
}
if
(
o
->
a
w_state
==
0
)
{
if
(
o
->
a
gs_state
==
__PYX_AWAITABLE_STATE_INIT
)
{
if
(
arg
==
NULL
||
arg
==
Py_None
)
{
arg
=
o
->
a
w_sendval
?
o
->
aw_sendval
:
Py_None
;
arg
=
o
->
a
gs_sendval
;
}
o
->
a
w_state
=
1
;
o
->
a
gs_state
=
__PYX_AWAITABLE_STATE_ITER
;
}
result
=
__Pyx_Coroutine_SendEx
((
__pyx_CoroutineObject
*
)
o
->
a
w
_gen
,
arg
);
result
=
__Pyx_async_gen_unwrap_value
(
o
->
a
w
_gen
,
result
);
result
=
__Pyx_Coroutine_SendEx
((
__pyx_CoroutineObject
*
)
o
->
a
gs
_gen
,
arg
);
result
=
__Pyx_async_gen_unwrap_value
(
o
->
a
gs
_gen
,
result
);
if
(
result
==
NULL
)
{
o
->
a
w_state
=
2
;
o
->
a
gs_state
=
__PYX_AWAITABLE_STATE_CLOSED
;
}
return
result
;
...
...
@@ -478,16 +503,16 @@ __Pyx_async_gen_asend_throw(__pyx_PyAsyncGenASend *o, PyObject *args)
{
PyObject
*
result
;
if
(
o
->
a
w_state
==
2
)
{
if
(
o
->
a
gs_state
==
__PYX_AWAITABLE_STATE_CLOSED
)
{
PyErr_SetNone
(
PyExc_StopIteration
);
return
NULL
;
}
result
=
__Pyx_Coroutine_Throw
((
PyObject
*
)
o
->
a
w
_gen
,
args
);
result
=
__Pyx_async_gen_unwrap_value
(
o
->
a
w
_gen
,
result
);
result
=
__Pyx_Coroutine_Throw
((
PyObject
*
)
o
->
a
gs
_gen
,
args
);
result
=
__Pyx_async_gen_unwrap_value
(
o
->
a
gs
_gen
,
result
);
if
(
result
==
NULL
)
{
o
->
a
w_state
=
2
;
o
->
a
gs_state
=
__PYX_AWAITABLE_STATE_CLOSED
;
}
return
result
;
...
...
@@ -497,7 +522,7 @@ __Pyx_async_gen_asend_throw(__pyx_PyAsyncGenASend *o, PyObject *args)
static
PyObject
*
__Pyx_async_gen_asend_close
(
__pyx_PyAsyncGenASend
*
o
,
CYTHON_UNUSED
PyObject
*
args
)
{
o
->
a
w_state
=
2
;
o
->
a
gs_state
=
__PYX_AWAITABLE_STATE_CLOSED
;
Py_RETURN_NONE
;
}
...
...
@@ -542,9 +567,9 @@ PyTypeObject __pyx__PyAsyncGenASendType_type = {
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
0
,
/* tp_doc */
0
,
/* tp_traverse */
(
traverseproc
)
__Pyx_async_gen_asend_traverse
,
/* tp_traverse */
0
,
/* tp_clear */
#if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
// in order to (mis-)use tp_reserved above, we must also implement tp_richcompare
...
...
@@ -582,24 +607,29 @@ PyTypeObject __pyx__PyAsyncGenASendType_type = {
static
PyObject
*
__Pyx_async_gen_asend_new
(
__pyx_AsyncGenObject
*
gen
,
PyObject
*
sendval
)
__Pyx_async_gen_asend_new
(
__pyx_
Py
AsyncGenObject
*
gen
,
PyObject
*
sendval
)
{
__pyx_PyAsyncGenASend
*
o
;
if
(
__Pyx_ag_asend_f
l
_free
)
{
__Pyx_ag_asend_f
l
_free
--
;
o
=
__Pyx_ag_asend_f
l
[
__Pyx_ag_asend_fl
_free
];
if
(
__Pyx_ag_asend_f
reelist
_free
)
{
__Pyx_ag_asend_f
reelist
_free
--
;
o
=
__Pyx_ag_asend_f
reelist
[
__Pyx_ag_asend_freelist
_free
];
_Py_NewReference
((
PyObject
*
)
o
);
}
else
{
o
=
PyObject_New
(
__pyx_PyAsyncGenASend
,
__pyx__PyAsyncGenASendType
);
o
=
PyObject_
GC_
New
(
__pyx_PyAsyncGenASend
,
__pyx__PyAsyncGenASendType
);
if
(
o
==
NULL
)
{
return
NULL
;
}
}
o
->
aw_gen
=
gen
;
o
->
aw_state
=
0
;
o
->
aw_sendval
=
sendval
;
Py_XINCREF
(
sendval
);
Py_INCREF
(
gen
);
o
->
ags_gen
=
gen
;
Py_XINCREF
(
sendval
);
o
->
ags_sendval
=
sendval
;
o
->
ags_state
=
__PYX_AWAITABLE_STATE_INIT
;
_PyObject_GC_TRACK
((
PyObject
*
)
o
);
return
(
PyObject
*
)
o
;
}
...
...
@@ -610,16 +640,26 @@ __Pyx_async_gen_asend_new(__pyx_AsyncGenObject *gen, PyObject *sendval)
static
void
__Pyx_async_gen_wrapped_val_dealloc
(
__pyx__PyAsyncGenWrappedValue
*
o
)
{
Py_CLEAR
(
o
->
val
);
if
(
__Pyx_ag_value_fl_free
<
_PyAsyncGen_MAXFREELIST
)
{
_PyObject_GC_UNTRACK
((
PyObject
*
)
o
);
Py_CLEAR
(
o
->
agw_val
);
if
(
__Pyx_ag_value_freelist_free
<
_PyAsyncGen_MAXFREELIST
)
{
assert
(
__pyx__PyAsyncGenWrappedValue_CheckExact
(
o
));
__Pyx_ag_value_f
l
[
__Pyx_ag_value_fl
_free
++
]
=
o
;
__Pyx_ag_value_f
reelist
[
__Pyx_ag_value_freelist
_free
++
]
=
o
;
}
else
{
PyObject_Del
(
o
);
PyObject_
GC_
Del
(
o
);
}
}
static
int
__Pyx_async_gen_wrapped_val_traverse
(
__pyx__PyAsyncGenWrappedValue
*
o
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
o
->
agw_val
);
return
0
;
}
PyTypeObject
__pyx__PyAsyncGenWrappedValueType_type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"async_generator_wrapped_value"
,
/* tp_name */
...
...
@@ -641,9 +681,9 @@ PyTypeObject __pyx__PyAsyncGenWrappedValueType_type = {
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
0
,
/* tp_doc */
0
,
/* tp_traverse */
(
traverseproc
)
__Pyx_async_gen_wrapped_val_traverse
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
...
...
@@ -676,26 +716,27 @@ PyTypeObject __pyx__PyAsyncGenWrappedValueType_type = {
static
PyObject
*
__
pyx__PyAsyncGenWrapValue
(
PyObject
*
val
)
__
Pyx__PyAsyncGenValueWrapperNew
(
PyObject
*
val
)
{
// NOTE: steals a reference to val !
__pyx__PyAsyncGenWrappedValue
*
o
;
if
(
unlikely
(
!
val
))
return
NULL
;
assert
(
val
);
if
(
__Pyx_ag_value_f
l
_free
)
{
__Pyx_ag_value_f
l
_free
--
;
o
=
__Pyx_ag_value_f
l
[
__Pyx_ag_value_fl
_free
];
if
(
__Pyx_ag_value_f
reelist
_free
)
{
__Pyx_ag_value_f
reelist
_free
--
;
o
=
__Pyx_ag_value_f
reelist
[
__Pyx_ag_value_freelist
_free
];
assert
(
__pyx__PyAsyncGenWrappedValue_CheckExact
(
o
));
_Py_NewReference
((
PyObject
*
)
o
);
}
else
{
o
=
PyObject_New
(
__pyx__PyAsyncGenWrappedValue
,
__pyx__PyAsyncGenWrappedValueType
);
o
=
PyObject_
GC_
New
(
__pyx__PyAsyncGenWrappedValue
,
__pyx__PyAsyncGenWrappedValueType
);
if
(
unlikely
(
!
o
))
{
Py_DECREF
(
val
);
return
NULL
;
}
}
o
->
val
=
val
;
o
->
agw_
val
=
val
;
// no Py_INCREF(val) - steals reference!
_PyObject_GC_TRACK
((
PyObject
*
)
o
);
return
(
PyObject
*
)
o
;
}
...
...
@@ -706,25 +747,35 @@ __pyx__PyAsyncGenWrapValue(PyObject *val)
static
void
__Pyx_async_gen_athrow_dealloc
(
__pyx_PyAsyncGenAThrow
*
o
)
{
Py_CLEAR
(
o
->
ac_gen
);
Py_CLEAR
(
o
->
ac_args
);
PyObject_Del
(
o
);
_PyObject_GC_UNTRACK
((
PyObject
*
)
o
);
Py_CLEAR
(
o
->
agt_gen
);
Py_CLEAR
(
o
->
agt_args
);
PyObject_GC_Del
(
o
);
}
static
int
__Pyx_async_gen_athrow_traverse
(
__pyx_PyAsyncGenAThrow
*
o
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
o
->
agt_gen
);
Py_VISIT
(
o
->
agt_args
);
return
0
;
}
static
PyObject
*
__Pyx_async_gen_athrow_send
(
__pyx_PyAsyncGenAThrow
*
o
,
PyObject
*
arg
)
{
__pyx_CoroutineObject
*
gen
=
(
__pyx_CoroutineObject
*
)
o
->
a
c
_gen
;
__pyx_CoroutineObject
*
gen
=
(
__pyx_CoroutineObject
*
)
o
->
a
gt
_gen
;
PyObject
*
retval
;
if
(
o
->
a
c_state
==
2
)
{
if
(
o
->
a
gt_state
==
__PYX_AWAITABLE_STATE_CLOSED
)
{
PyErr_SetNone
(
PyExc_StopIteration
);
return
NULL
;
}
if
(
o
->
a
c_state
==
0
)
{
if
(
o
->
a
c
_gen
->
ag_closed
)
{
if
(
o
->
a
gt_state
==
__PYX_AWAITABLE_STATE_INIT
)
{
if
(
o
->
a
gt
_gen
->
ag_closed
)
{
PyErr_SetNone
(
PyExc_StopIteration
);
return
NULL
;
}
...
...
@@ -734,11 +785,11 @@ __Pyx_async_gen_athrow_send(__pyx_PyAsyncGenAThrow *o, PyObject *arg)
return
NULL
;
}
o
->
a
c_state
=
1
;
o
->
a
gt_state
=
__PYX_AWAITABLE_STATE_ITER
;
if
(
o
->
a
c
_args
==
NULL
)
{
if
(
o
->
a
gt
_args
==
NULL
)
{
/* aclose() mode */
o
->
a
c
_gen
->
ag_closed
=
1
;
o
->
a
gt
_gen
->
ag_closed
=
1
;
retval
=
__Pyx__Coroutine_Throw
((
PyObject
*
)
gen
,
/* Do not close generator when
...
...
@@ -754,7 +805,7 @@ __Pyx_async_gen_athrow_send(__pyx_PyAsyncGenAThrow *o, PyObject *arg)
PyObject
*
tb
=
NULL
;
PyObject
*
val
=
NULL
;
if
(
!
PyArg_UnpackTuple
(
o
->
a
c
_args
,
"athrow"
,
1
,
3
,
if
(
!
PyArg_UnpackTuple
(
o
->
a
gt
_args
,
"athrow"
,
1
,
3
,
&
typ
,
&
val
,
&
tb
))
{
return
NULL
;
}
...
...
@@ -762,8 +813,8 @@ __Pyx_async_gen_athrow_send(__pyx_PyAsyncGenAThrow *o, PyObject *arg)
retval
=
__Pyx__Coroutine_Throw
((
PyObject
*
)
gen
,
/* Do not close generator when
PyExc_GeneratorExit is passed */
typ
,
val
,
tb
,
o
->
a
c
_args
,
0
);
retval
=
__Pyx_async_gen_unwrap_value
(
o
->
a
c
_gen
,
retval
);
typ
,
val
,
tb
,
o
->
a
gt
_args
,
0
);
retval
=
__Pyx_async_gen_unwrap_value
(
o
->
a
gt
_gen
,
retval
);
}
if
(
retval
==
NULL
)
{
goto
check_error
;
...
...
@@ -771,24 +822,26 @@ __Pyx_async_gen_athrow_send(__pyx_PyAsyncGenAThrow *o, PyObject *arg)
return
retval
;
}
if
(
o
->
ac_state
==
1
)
{
PyObject
*
retval
=
__Pyx_Coroutine_SendEx
((
__pyx_CoroutineObject
*
)
gen
,
arg
);
if
(
o
->
ac_args
)
{
return
__Pyx_async_gen_unwrap_value
(
o
->
ac_gen
,
retval
);
assert
(
o
->
agt_state
==
__PYX_AWAITABLE_STATE_ITER
);
retval
=
__Pyx_Coroutine_SendEx
((
__pyx_CoroutineObject
*
)
gen
,
arg
);
if
(
o
->
agt_args
)
{
return
__Pyx_async_gen_unwrap_value
(
o
->
agt_gen
,
retval
);
}
else
{
/* aclose() mode */
if
(
retval
&&
__pyx__PyAsyncGenWrappedValue_CheckExact
(
retval
))
{
if
(
retval
)
{
if
(
__pyx__PyAsyncGenWrappedValue_CheckExact
(
retval
))
{
Py_DECREF
(
retval
);
goto
yield_close
;
}
if
(
retval
==
NULL
)
{
goto
check_error
;
}
else
{
return
retval
;
}
}
return
NULL
;
else
{
goto
check_error
;
}
}
yield_close:
PyErr_SetString
(
...
...
@@ -796,10 +849,18 @@ yield_close:
return
NULL
;
check_error:
if
(
PyErr_ExceptionMatches
(
__Pyx_PyExc_StopAsyncIteration
)
||
PyErr_ExceptionMatches
(
PyExc_GeneratorExit
)
)
{
o
->
ac_state
=
2
;
if
(
PyErr_ExceptionMatches
(
__Pyx_PyExc_StopAsyncIteration
))
{
o
->
agt_state
=
__PYX_AWAITABLE_STATE_CLOSED
;
if
(
o
->
agt_args
==
NULL
)
{
// when aclose() is called we don't want to propagate
// StopAsyncIteration; just raise StopIteration, signalling
// that 'aclose()' is done.
PyErr_Clear
();
PyErr_SetNone
(
PyExc_StopIteration
);
}
}
else
if
(
PyErr_ExceptionMatches
(
PyExc_GeneratorExit
))
{
o
->
agt_state
=
__PYX_AWAITABLE_STATE_CLOSED
;
PyErr_Clear
();
/* ignore these errors */
PyErr_SetNone
(
PyExc_StopIteration
);
}
...
...
@@ -812,19 +873,19 @@ __Pyx_async_gen_athrow_throw(__pyx_PyAsyncGenAThrow *o, PyObject *args)
{
PyObject
*
retval
;
if
(
o
->
a
c_state
==
0
)
{
if
(
o
->
a
gt_state
==
__PYX_AWAITABLE_STATE_INIT
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
__Pyx_NON_INIT_CORO_MSG
);
return
NULL
;
}
if
(
o
->
a
c_state
==
2
)
{
if
(
o
->
a
gt_state
==
__PYX_AWAITABLE_STATE_CLOSED
)
{
PyErr_SetNone
(
PyExc_StopIteration
);
return
NULL
;
}
retval
=
__Pyx_Coroutine_Throw
((
PyObject
*
)
o
->
a
c
_gen
,
args
);
if
(
o
->
a
c
_args
)
{
return
__Pyx_async_gen_unwrap_value
(
o
->
a
c
_gen
,
retval
);
retval
=
__Pyx_Coroutine_Throw
((
PyObject
*
)
o
->
a
gt
_gen
,
args
);
if
(
o
->
a
gt
_args
)
{
return
__Pyx_async_gen_unwrap_value
(
o
->
a
gt
_gen
,
retval
);
}
else
{
/* aclose() mode */
if
(
retval
&&
__pyx__PyAsyncGenWrappedValue_CheckExact
(
retval
))
{
...
...
@@ -847,7 +908,7 @@ __Pyx_async_gen_athrow_iternext(__pyx_PyAsyncGenAThrow *o)
static
PyObject
*
__Pyx_async_gen_athrow_close
(
__pyx_PyAsyncGenAThrow
*
o
,
CYTHON_UNUSED
PyObject
*
args
)
{
o
->
a
c_state
=
2
;
o
->
a
gt_state
=
__PYX_AWAITABLE_STATE_CLOSED
;
Py_RETURN_NONE
;
}
...
...
@@ -891,9 +952,9 @@ PyTypeObject __pyx__PyAsyncGenAThrowType_type = {
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
0
,
/* tp_doc */
0
,
/* tp_traverse */
(
traverseproc
)
__Pyx_async_gen_athrow_traverse
,
/* tp_traverse */
0
,
/* tp_clear */
#if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
// in order to (mis-)use tp_reserved above, we must also implement tp_richcompare
...
...
@@ -931,18 +992,19 @@ PyTypeObject __pyx__PyAsyncGenAThrowType_type = {
static
PyObject
*
__Pyx_async_gen_athrow_new
(
__pyx_AsyncGenObject
*
gen
,
PyObject
*
args
)
__Pyx_async_gen_athrow_new
(
__pyx_
Py
AsyncGenObject
*
gen
,
PyObject
*
args
)
{
__pyx_PyAsyncGenAThrow
*
o
;
o
=
PyObject_New
(
__pyx_PyAsyncGenAThrow
,
__pyx__PyAsyncGenAThrowType
);
o
=
PyObject_
GC_
New
(
__pyx_PyAsyncGenAThrow
,
__pyx__PyAsyncGenAThrowType
);
if
(
o
==
NULL
)
{
return
NULL
;
}
o
->
a
c
_gen
=
gen
;
o
->
a
c
_args
=
args
;
o
->
a
c_state
=
0
;
o
->
a
gt
_gen
=
gen
;
o
->
a
gt
_args
=
args
;
o
->
a
gt_state
=
__PYX_AWAITABLE_STATE_INIT
;
Py_INCREF
(
gen
);
Py_XINCREF
(
args
);
_PyObject_GC_TRACK
((
PyObject
*
)
o
);
return
(
PyObject
*
)
o
;
}
...
...
Cython/Utility/Coroutine.c
View file @
e3ec8cd8
...
...
@@ -292,7 +292,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *obj) {
static
CYTHON_INLINE
PyObject
*
__Pyx_Coroutine_AsyncIterNext
(
PyObject
*
obj
)
{
#ifdef __Pyx_AsyncGen_USED
if
(
__Pyx_AsyncGen_CheckExact
(
obj
))
{
return
__Pyx_
AsyncGen_AN
ext
(
obj
);
return
__Pyx_
async_gen_an
ext
(
obj
);
}
#endif
#if CYTHON_USE_ASYNC_SLOTS
...
...
@@ -927,7 +927,7 @@ static int __Pyx_Coroutine_clear(PyObject *self) {
Py_CLEAR
(
gen
->
exc_traceback
);
#ifdef __Pyx_AsyncGen_USED
if
(
__Pyx_AsyncGen_CheckExact
(
self
))
{
Py_CLEAR
(((
__pyx_AsyncGenObject
*
)
gen
)
->
ag_finalizer
);
Py_CLEAR
(((
__pyx_
Py
AsyncGenObject
*
)
gen
)
->
ag_finalizer
);
}
#endif
Py_CLEAR
(
gen
->
gi_name
);
...
...
@@ -1324,7 +1324,7 @@ static void __Pyx_Coroutine_check_and_dealloc(PyObject *self) {
PyObject_GC_Track
(
self
);
#ifdef __Pyx_AsyncGen_USED
}
else
if
(
__Pyx_AsyncGen_CheckExact
(
self
))
{
__pyx_
AsyncGenObject
*
agen
=
(
__pyx_
AsyncGenObject
*
)
self
;
__pyx_
PyAsyncGenObject
*
agen
=
(
__pyx_Py
AsyncGenObject
*
)
self
;
PyObject
*
finalizer
=
agen
->
ag_finalizer
;
if
(
finalizer
&&
!
agen
->
ag_closed
)
{
/* Save the current exception, if any. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment