AsyncGen.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. // This is copied from genobject.c in CPython 3.6.
  2. // Try to keep it in sync by doing this from time to time:
  3. // sed -e 's|__pyx_||ig' Cython/Utility/AsyncGen.c | diff -udw - cpython/Objects/genobject.c | less
  4. //////////////////// AsyncGenerator.proto ////////////////////
  5. //@requires: Coroutine.c::Coroutine
  6. #define __Pyx_AsyncGen_USED
  7. typedef struct {
  8. __pyx_CoroutineObject coro;
  9. PyObject *ag_finalizer;
  10. int ag_hooks_inited;
  11. int ag_closed;
  12. } __pyx_PyAsyncGenObject;
  13. static PyTypeObject *__pyx__PyAsyncGenWrappedValueType = 0;
  14. static PyTypeObject *__pyx__PyAsyncGenASendType = 0;
  15. static PyTypeObject *__pyx__PyAsyncGenAThrowType = 0;
  16. static PyTypeObject *__pyx_AsyncGenType = 0;
  17. #define __Pyx_AsyncGen_CheckExact(obj) (Py_TYPE(obj) == __pyx_AsyncGenType)
  18. #define __pyx_PyAsyncGenASend_CheckExact(o) \
  19. (Py_TYPE(o) == __pyx__PyAsyncGenASendType)
  20. #define __pyx_PyAsyncGenAThrow_CheckExact(o) \
  21. (Py_TYPE(o) == __pyx__PyAsyncGenAThrowType)
  22. static PyObject *__Pyx_async_gen_anext(PyObject *o);
  23. static CYTHON_INLINE PyObject *__Pyx_async_gen_asend_iternext(PyObject *o);
  24. static PyObject *__Pyx_async_gen_asend_send(PyObject *o, PyObject *arg);
  25. static PyObject *__Pyx_async_gen_asend_close(PyObject *o, PyObject *args);
  26. static PyObject *__Pyx_async_gen_athrow_close(PyObject *o, PyObject *args);
  27. static PyObject *__Pyx__PyAsyncGenValueWrapperNew(PyObject *val);
  28. static __pyx_CoroutineObject *__Pyx_AsyncGen_New(
  29. __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
  30. PyObject *name, PyObject *qualname, PyObject *module_name) {
  31. __pyx_PyAsyncGenObject *gen = PyObject_GC_New(__pyx_PyAsyncGenObject, __pyx_AsyncGenType);
  32. if (unlikely(!gen))
  33. return NULL;
  34. gen->ag_finalizer = NULL;
  35. gen->ag_closed = 0;
  36. gen->ag_hooks_inited = 0;
  37. return __Pyx__Coroutine_NewInit((__pyx_CoroutineObject*)gen, body, code, closure, name, qualname, module_name);
  38. }
  39. static int __pyx_AsyncGen_init(void);
  40. static void __Pyx_PyAsyncGen_Fini(void);
  41. //////////////////// AsyncGenerator.cleanup ////////////////////
  42. __Pyx_PyAsyncGen_Fini();
  43. //////////////////// AsyncGeneratorInitFinalizer ////////////////////
  44. // this is separated out because it needs more adaptation
  45. #if PY_VERSION_HEX < 0x030600B0
  46. static int __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o) {
  47. #if 0
  48. // TODO: implement finalizer support in older Python versions
  49. PyThreadState *tstate;
  50. PyObject *finalizer;
  51. PyObject *firstiter;
  52. #endif
  53. if (likely(o->ag_hooks_inited)) {
  54. return 0;
  55. }
  56. o->ag_hooks_inited = 1;
  57. #if 0
  58. tstate = __Pyx_PyThreadState_Current;
  59. finalizer = tstate->async_gen_finalizer;
  60. if (finalizer) {
  61. Py_INCREF(finalizer);
  62. o->ag_finalizer = finalizer;
  63. }
  64. firstiter = tstate->async_gen_firstiter;
  65. if (firstiter) {
  66. PyObject *res;
  67. Py_INCREF(firstiter);
  68. res = __Pyx_PyObject_CallOneArg(firstiter, (PyObject*)o);
  69. Py_DECREF(firstiter);
  70. if (res == NULL) {
  71. return 1;
  72. }
  73. Py_DECREF(res);
  74. }
  75. #endif
  76. return 0;
  77. }
  78. #endif
  79. //////////////////// AsyncGenerator ////////////////////
  80. //@requires: AsyncGeneratorInitFinalizer
  81. //@requires: Coroutine.c::Coroutine
  82. //@requires: Coroutine.c::ReturnWithStopIteration
  83. //@requires: ObjectHandling.c::PyObjectCall2Args
  84. //@requires: ObjectHandling.c::PyObject_GenericGetAttrNoDict
  85. PyDoc_STRVAR(__Pyx_async_gen_send_doc,
  86. "send(arg) -> send 'arg' into generator,\n\
  87. return next yielded value or raise StopIteration.");
  88. PyDoc_STRVAR(__Pyx_async_gen_close_doc,
  89. "close() -> raise GeneratorExit inside generator.");
  90. PyDoc_STRVAR(__Pyx_async_gen_throw_doc,
  91. "throw(typ[,val[,tb]]) -> raise exception in generator,\n\
  92. return next yielded value or raise StopIteration.");
  93. PyDoc_STRVAR(__Pyx_async_gen_await_doc,
  94. "__await__() -> return a representation that can be passed into the 'await' expression.");
  95. // COPY STARTS HERE:
  96. static PyObject *__Pyx_async_gen_asend_new(__pyx_PyAsyncGenObject *, PyObject *);
  97. static PyObject *__Pyx_async_gen_athrow_new(__pyx_PyAsyncGenObject *, PyObject *);
  98. static const char *__Pyx_NON_INIT_CORO_MSG = "can't send non-None value to a just-started coroutine";
  99. static const char *__Pyx_ASYNC_GEN_IGNORED_EXIT_MSG = "async generator ignored GeneratorExit";
  100. typedef enum {
  101. __PYX_AWAITABLE_STATE_INIT, /* new awaitable, has not yet been iterated */
  102. __PYX_AWAITABLE_STATE_ITER, /* being iterated */
  103. __PYX_AWAITABLE_STATE_CLOSED, /* closed */
  104. } __pyx_AwaitableState;
  105. typedef struct {
  106. PyObject_HEAD
  107. __pyx_PyAsyncGenObject *ags_gen;
  108. /* Can be NULL, when in the __anext__() mode (equivalent of "asend(None)") */
  109. PyObject *ags_sendval;
  110. __pyx_AwaitableState ags_state;
  111. } __pyx_PyAsyncGenASend;
  112. typedef struct {
  113. PyObject_HEAD
  114. __pyx_PyAsyncGenObject *agt_gen;
  115. /* Can be NULL, when in the "aclose()" mode (equivalent of "athrow(GeneratorExit)") */
  116. PyObject *agt_args;
  117. __pyx_AwaitableState agt_state;
  118. } __pyx_PyAsyncGenAThrow;
  119. typedef struct {
  120. PyObject_HEAD
  121. PyObject *agw_val;
  122. } __pyx__PyAsyncGenWrappedValue;
  123. #ifndef _PyAsyncGen_MAXFREELIST
  124. #define _PyAsyncGen_MAXFREELIST 80
  125. #endif
  126. // Freelists boost performance 6-10%; they also reduce memory
  127. // fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend
  128. // are short-living objects that are instantiated for every
  129. // __anext__ call.
  130. static __pyx__PyAsyncGenWrappedValue *__Pyx_ag_value_freelist[_PyAsyncGen_MAXFREELIST];
  131. static int __Pyx_ag_value_freelist_free = 0;
  132. static __pyx_PyAsyncGenASend *__Pyx_ag_asend_freelist[_PyAsyncGen_MAXFREELIST];
  133. static int __Pyx_ag_asend_freelist_free = 0;
  134. #define __pyx__PyAsyncGenWrappedValue_CheckExact(o) \
  135. (Py_TYPE(o) == __pyx__PyAsyncGenWrappedValueType)
  136. static int
  137. __Pyx_async_gen_traverse(__pyx_PyAsyncGenObject *gen, visitproc visit, void *arg)
  138. {
  139. Py_VISIT(gen->ag_finalizer);
  140. return __Pyx_Coroutine_traverse((__pyx_CoroutineObject*)gen, visit, arg);
  141. }
  142. static PyObject *
  143. __Pyx_async_gen_repr(__pyx_CoroutineObject *o)
  144. {
  145. // avoid NULL pointer dereference for qualname during garbage collection
  146. return PyUnicode_FromFormat("<async_generator object %S at %p>",
  147. o->gi_qualname ? o->gi_qualname : Py_None, o);
  148. }
  149. #if PY_VERSION_HEX >= 0x030600B0
  150. static int
  151. __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o)
  152. {
  153. #if !CYTHON_COMPILING_IN_PYPY
  154. PyThreadState *tstate;
  155. #endif
  156. PyObject *finalizer;
  157. PyObject *firstiter;
  158. if (o->ag_hooks_inited) {
  159. return 0;
  160. }
  161. o->ag_hooks_inited = 1;
  162. #if CYTHON_COMPILING_IN_PYPY
  163. finalizer = _PyEval_GetAsyncGenFinalizer();
  164. #else
  165. tstate = __Pyx_PyThreadState_Current;
  166. finalizer = tstate->async_gen_finalizer;
  167. #endif
  168. if (finalizer) {
  169. Py_INCREF(finalizer);
  170. o->ag_finalizer = finalizer;
  171. }
  172. #if CYTHON_COMPILING_IN_PYPY
  173. firstiter = _PyEval_GetAsyncGenFirstiter();
  174. #else
  175. firstiter = tstate->async_gen_firstiter;
  176. #endif
  177. if (firstiter) {
  178. PyObject *res;
  179. #if CYTHON_UNPACK_METHODS
  180. PyObject *self;
  181. #endif
  182. Py_INCREF(firstiter);
  183. // at least asyncio stores methods here => optimise the call
  184. #if CYTHON_UNPACK_METHODS
  185. if (likely(PyMethod_Check(firstiter)) && likely((self = PyMethod_GET_SELF(firstiter)) != NULL)) {
  186. PyObject *function = PyMethod_GET_FUNCTION(firstiter);
  187. res = __Pyx_PyObject_Call2Args(function, self, (PyObject*)o);
  188. } else
  189. #endif
  190. res = __Pyx_PyObject_CallOneArg(firstiter, (PyObject*)o);
  191. Py_DECREF(firstiter);
  192. if (unlikely(res == NULL)) {
  193. return 1;
  194. }
  195. Py_DECREF(res);
  196. }
  197. return 0;
  198. }
  199. #endif
  200. static PyObject *
  201. __Pyx_async_gen_anext(PyObject *g)
  202. {
  203. __pyx_PyAsyncGenObject *o = (__pyx_PyAsyncGenObject*) g;
  204. if (__Pyx_async_gen_init_hooks(o)) {
  205. return NULL;
  206. }
  207. return __Pyx_async_gen_asend_new(o, NULL);
  208. }
  209. static PyObject *
  210. __Pyx_async_gen_anext_method(PyObject *g, CYTHON_UNUSED PyObject *arg) {
  211. return __Pyx_async_gen_anext(g);
  212. }
  213. static PyObject *
  214. __Pyx_async_gen_asend(__pyx_PyAsyncGenObject *o, PyObject *arg)
  215. {
  216. if (__Pyx_async_gen_init_hooks(o)) {
  217. return NULL;
  218. }
  219. return __Pyx_async_gen_asend_new(o, arg);
  220. }
  221. static PyObject *
  222. __Pyx_async_gen_aclose(__pyx_PyAsyncGenObject *o, CYTHON_UNUSED PyObject *arg)
  223. {
  224. if (__Pyx_async_gen_init_hooks(o)) {
  225. return NULL;
  226. }
  227. return __Pyx_async_gen_athrow_new(o, NULL);
  228. }
  229. static PyObject *
  230. __Pyx_async_gen_athrow(__pyx_PyAsyncGenObject *o, PyObject *args)
  231. {
  232. if (__Pyx_async_gen_init_hooks(o)) {
  233. return NULL;
  234. }
  235. return __Pyx_async_gen_athrow_new(o, args);
  236. }
  237. static PyObject *
  238. __Pyx_async_gen_self_method(PyObject *g, CYTHON_UNUSED PyObject *arg) {
  239. return __Pyx_NewRef(g);
  240. }
  241. static PyGetSetDef __Pyx_async_gen_getsetlist[] = {
  242. {(char*) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
  243. (char*) PyDoc_STR("name of the async generator"), 0},
  244. {(char*) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
  245. (char*) PyDoc_STR("qualified name of the async generator"), 0},
  246. //REMOVED: {(char*) "ag_await", (getter)coro_get_cr_await, NULL,
  247. //REMOVED: (char*) PyDoc_STR("object being awaited on, or None")},
  248. {0, 0, 0, 0, 0} /* Sentinel */
  249. };
  250. static PyMemberDef __Pyx_async_gen_memberlist[] = {
  251. //REMOVED: {(char*) "ag_frame", T_OBJECT, offsetof(__pyx_PyAsyncGenObject, ag_frame), READONLY},
  252. {(char*) "ag_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
  253. //REMOVED: {(char*) "ag_code", T_OBJECT, offsetof(__pyx_PyAsyncGenObject, ag_code), READONLY},
  254. //ADDED: "ag_await"
  255. {(char*) "ag_await", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
  256. (char*) PyDoc_STR("object being awaited on, or None")},
  257. {0, 0, 0, 0, 0} /* Sentinel */
  258. };
  259. PyDoc_STRVAR(__Pyx_async_aclose_doc,
  260. "aclose() -> raise GeneratorExit inside generator.");
  261. PyDoc_STRVAR(__Pyx_async_asend_doc,
  262. "asend(v) -> send 'v' in generator.");
  263. PyDoc_STRVAR(__Pyx_async_athrow_doc,
  264. "athrow(typ[,val[,tb]]) -> raise exception in generator.");
  265. PyDoc_STRVAR(__Pyx_async_aiter_doc,
  266. "__aiter__(v) -> return an asynchronous iterator.");
  267. PyDoc_STRVAR(__Pyx_async_anext_doc,
  268. "__anext__(v) -> continue asynchronous iteration and return the next element.");
  269. static PyMethodDef __Pyx_async_gen_methods[] = {
  270. {"asend", (PyCFunction)__Pyx_async_gen_asend, METH_O, __Pyx_async_asend_doc},
  271. {"athrow",(PyCFunction)__Pyx_async_gen_athrow, METH_VARARGS, __Pyx_async_athrow_doc},
  272. {"aclose", (PyCFunction)__Pyx_async_gen_aclose, METH_NOARGS, __Pyx_async_aclose_doc},
  273. {"__aiter__", (PyCFunction)__Pyx_async_gen_self_method, METH_NOARGS, __Pyx_async_aiter_doc},
  274. {"__anext__", (PyCFunction)__Pyx_async_gen_anext_method, METH_NOARGS, __Pyx_async_anext_doc},
  275. {0, 0, 0, 0} /* Sentinel */
  276. };
  277. #if CYTHON_USE_ASYNC_SLOTS
  278. static __Pyx_PyAsyncMethodsStruct __Pyx_async_gen_as_async = {
  279. 0, /* am_await */
  280. PyObject_SelfIter, /* am_aiter */
  281. (unaryfunc)__Pyx_async_gen_anext, /* am_anext */
  282. #if PY_VERSION_HEX >= 0x030A00A3
  283. 0, /*am_send*/
  284. #endif
  285. };
  286. #endif
  287. static PyTypeObject __pyx_AsyncGenType_type = {
  288. PyVarObject_HEAD_INIT(0, 0)
  289. "async_generator", /* tp_name */
  290. sizeof(__pyx_PyAsyncGenObject), /* tp_basicsize */
  291. 0, /* tp_itemsize */
  292. (destructor)__Pyx_Coroutine_dealloc, /* tp_dealloc */
  293. 0, /* tp_print */
  294. 0, /* tp_getattr */
  295. 0, /* tp_setattr */
  296. #if CYTHON_USE_ASYNC_SLOTS
  297. &__Pyx_async_gen_as_async, /* tp_as_async */
  298. #else
  299. 0, /*tp_reserved*/
  300. #endif
  301. (reprfunc)__Pyx_async_gen_repr, /* tp_repr */
  302. 0, /* tp_as_number */
  303. 0, /* tp_as_sequence */
  304. 0, /* tp_as_mapping */
  305. 0, /* tp_hash */
  306. 0, /* tp_call */
  307. 0, /* tp_str */
  308. 0, /* tp_getattro */
  309. 0, /* tp_setattro */
  310. 0, /* tp_as_buffer */
  311. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
  312. Py_TPFLAGS_HAVE_FINALIZE, /* tp_flags */
  313. 0, /* tp_doc */
  314. (traverseproc)__Pyx_async_gen_traverse, /* tp_traverse */
  315. 0, /* tp_clear */
  316. #if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
  317. // in order to (mis-)use tp_reserved above, we must also implement tp_richcompare
  318. __Pyx_Coroutine_compare, /*tp_richcompare*/
  319. #else
  320. 0, /*tp_richcompare*/
  321. #endif
  322. offsetof(__pyx_CoroutineObject, gi_weakreflist), /* tp_weaklistoffset */
  323. 0, /* tp_iter */
  324. 0, /* tp_iternext */
  325. __Pyx_async_gen_methods, /* tp_methods */
  326. __Pyx_async_gen_memberlist, /* tp_members */
  327. __Pyx_async_gen_getsetlist, /* tp_getset */
  328. 0, /* tp_base */
  329. 0, /* tp_dict */
  330. 0, /* tp_descr_get */
  331. 0, /* tp_descr_set */
  332. 0, /* tp_dictoffset */
  333. 0, /* tp_init */
  334. 0, /* tp_alloc */
  335. 0, /* tp_new */
  336. 0, /* tp_free */
  337. 0, /* tp_is_gc */
  338. 0, /* tp_bases */
  339. 0, /* tp_mro */
  340. 0, /* tp_cache */
  341. 0, /* tp_subclasses */
  342. 0, /* tp_weaklist */
  343. #if CYTHON_USE_TP_FINALIZE
  344. 0, /*tp_del*/
  345. #else
  346. __Pyx_Coroutine_del, /*tp_del*/
  347. #endif
  348. 0, /* tp_version_tag */
  349. #if CYTHON_USE_TP_FINALIZE
  350. __Pyx_Coroutine_del, /* tp_finalize */
  351. #elif PY_VERSION_HEX >= 0x030400a1
  352. 0, /* tp_finalize */
  353. #endif
  354. #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  355. 0, /*tp_vectorcall*/
  356. #endif
  357. #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  358. 0, /*tp_print*/
  359. #endif
  360. #if PY_VERSION_HEX >= 0x030C0000
  361. 0, /*tp_watched*/
  362. #endif
  363. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  364. 0, /*tp_pypy_flags*/
  365. #endif
  366. };
  367. static int
  368. __Pyx_PyAsyncGen_ClearFreeLists(void)
  369. {
  370. int ret = __Pyx_ag_value_freelist_free + __Pyx_ag_asend_freelist_free;
  371. while (__Pyx_ag_value_freelist_free) {
  372. __pyx__PyAsyncGenWrappedValue *o;
  373. o = __Pyx_ag_value_freelist[--__Pyx_ag_value_freelist_free];
  374. assert(__pyx__PyAsyncGenWrappedValue_CheckExact(o));
  375. PyObject_GC_Del(o);
  376. }
  377. while (__Pyx_ag_asend_freelist_free) {
  378. __pyx_PyAsyncGenASend *o;
  379. o = __Pyx_ag_asend_freelist[--__Pyx_ag_asend_freelist_free];
  380. assert(Py_TYPE(o) == __pyx__PyAsyncGenASendType);
  381. PyObject_GC_Del(o);
  382. }
  383. return ret;
  384. }
  385. static void
  386. __Pyx_PyAsyncGen_Fini(void)
  387. {
  388. __Pyx_PyAsyncGen_ClearFreeLists();
  389. }
  390. static PyObject *
  391. __Pyx_async_gen_unwrap_value(__pyx_PyAsyncGenObject *gen, PyObject *result)
  392. {
  393. if (result == NULL) {
  394. PyObject *exc_type = PyErr_Occurred();
  395. if (!exc_type) {
  396. PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration);
  397. gen->ag_closed = 1;
  398. } else if (__Pyx_PyErr_GivenExceptionMatches2(exc_type, __Pyx_PyExc_StopAsyncIteration, PyExc_GeneratorExit)) {
  399. gen->ag_closed = 1;
  400. }
  401. return NULL;
  402. }
  403. if (__pyx__PyAsyncGenWrappedValue_CheckExact(result)) {
  404. /* async yield */
  405. __Pyx_ReturnWithStopIteration(((__pyx__PyAsyncGenWrappedValue*)result)->agw_val);
  406. Py_DECREF(result);
  407. return NULL;
  408. }
  409. return result;
  410. }
  411. /* ---------- Async Generator ASend Awaitable ------------ */
  412. static void
  413. __Pyx_async_gen_asend_dealloc(__pyx_PyAsyncGenASend *o)
  414. {
  415. PyObject_GC_UnTrack((PyObject *)o);
  416. Py_CLEAR(o->ags_gen);
  417. Py_CLEAR(o->ags_sendval);
  418. if (__Pyx_ag_asend_freelist_free < _PyAsyncGen_MAXFREELIST) {
  419. assert(__pyx_PyAsyncGenASend_CheckExact(o));
  420. __Pyx_ag_asend_freelist[__Pyx_ag_asend_freelist_free++] = o;
  421. } else {
  422. PyObject_GC_Del(o);
  423. }
  424. }
  425. static int
  426. __Pyx_async_gen_asend_traverse(__pyx_PyAsyncGenASend *o, visitproc visit, void *arg)
  427. {
  428. Py_VISIT(o->ags_gen);
  429. Py_VISIT(o->ags_sendval);
  430. return 0;
  431. }
  432. static PyObject *
  433. __Pyx_async_gen_asend_send(PyObject *g, PyObject *arg)
  434. {
  435. __pyx_PyAsyncGenASend *o = (__pyx_PyAsyncGenASend*) g;
  436. PyObject *result;
  437. if (unlikely(o->ags_state == __PYX_AWAITABLE_STATE_CLOSED)) {
  438. PyErr_SetNone(PyExc_StopIteration);
  439. return NULL;
  440. }
  441. if (o->ags_state == __PYX_AWAITABLE_STATE_INIT) {
  442. if (arg == NULL || arg == Py_None) {
  443. arg = o->ags_sendval ? o->ags_sendval : Py_None;
  444. }
  445. o->ags_state = __PYX_AWAITABLE_STATE_ITER;
  446. }
  447. result = __Pyx_Coroutine_Send((PyObject*)o->ags_gen, arg);
  448. result = __Pyx_async_gen_unwrap_value(o->ags_gen, result);
  449. if (result == NULL) {
  450. o->ags_state = __PYX_AWAITABLE_STATE_CLOSED;
  451. }
  452. return result;
  453. }
  454. static CYTHON_INLINE PyObject *
  455. __Pyx_async_gen_asend_iternext(PyObject *o)
  456. {
  457. return __Pyx_async_gen_asend_send(o, Py_None);
  458. }
  459. static PyObject *
  460. __Pyx_async_gen_asend_throw(__pyx_PyAsyncGenASend *o, PyObject *args)
  461. {
  462. PyObject *result;
  463. if (unlikely(o->ags_state == __PYX_AWAITABLE_STATE_CLOSED)) {
  464. PyErr_SetNone(PyExc_StopIteration);
  465. return NULL;
  466. }
  467. result = __Pyx_Coroutine_Throw((PyObject*)o->ags_gen, args);
  468. result = __Pyx_async_gen_unwrap_value(o->ags_gen, result);
  469. if (result == NULL) {
  470. o->ags_state = __PYX_AWAITABLE_STATE_CLOSED;
  471. }
  472. return result;
  473. }
  474. static PyObject *
  475. __Pyx_async_gen_asend_close(PyObject *g, CYTHON_UNUSED PyObject *args)
  476. {
  477. __pyx_PyAsyncGenASend *o = (__pyx_PyAsyncGenASend*) g;
  478. o->ags_state = __PYX_AWAITABLE_STATE_CLOSED;
  479. Py_RETURN_NONE;
  480. }
  481. static PyMethodDef __Pyx_async_gen_asend_methods[] = {
  482. {"send", (PyCFunction)__Pyx_async_gen_asend_send, METH_O, __Pyx_async_gen_send_doc},
  483. {"throw", (PyCFunction)__Pyx_async_gen_asend_throw, METH_VARARGS, __Pyx_async_gen_throw_doc},
  484. {"close", (PyCFunction)__Pyx_async_gen_asend_close, METH_NOARGS, __Pyx_async_gen_close_doc},
  485. {"__await__", (PyCFunction)__Pyx_async_gen_self_method, METH_NOARGS, __Pyx_async_gen_await_doc},
  486. {0, 0, 0, 0} /* Sentinel */
  487. };
  488. #if CYTHON_USE_ASYNC_SLOTS
  489. static __Pyx_PyAsyncMethodsStruct __Pyx_async_gen_asend_as_async = {
  490. PyObject_SelfIter, /* am_await */
  491. 0, /* am_aiter */
  492. 0, /* am_anext */
  493. #if PY_VERSION_HEX >= 0x030A00A3
  494. 0, /*am_send*/
  495. #endif
  496. };
  497. #endif
  498. static PyTypeObject __pyx__PyAsyncGenASendType_type = {
  499. PyVarObject_HEAD_INIT(0, 0)
  500. "async_generator_asend", /* tp_name */
  501. sizeof(__pyx_PyAsyncGenASend), /* tp_basicsize */
  502. 0, /* tp_itemsize */
  503. /* methods */
  504. (destructor)__Pyx_async_gen_asend_dealloc, /* tp_dealloc */
  505. 0, /* tp_print */
  506. 0, /* tp_getattr */
  507. 0, /* tp_setattr */
  508. #if CYTHON_USE_ASYNC_SLOTS
  509. &__Pyx_async_gen_asend_as_async, /* tp_as_async */
  510. #else
  511. 0, /*tp_reserved*/
  512. #endif
  513. 0, /* tp_repr */
  514. 0, /* tp_as_number */
  515. 0, /* tp_as_sequence */
  516. 0, /* tp_as_mapping */
  517. 0, /* tp_hash */
  518. 0, /* tp_call */
  519. 0, /* tp_str */
  520. 0, /* tp_getattro */
  521. 0, /* tp_setattro */
  522. 0, /* tp_as_buffer */
  523. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
  524. 0, /* tp_doc */
  525. (traverseproc)__Pyx_async_gen_asend_traverse, /* tp_traverse */
  526. 0, /* tp_clear */
  527. #if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
  528. // in order to (mis-)use tp_reserved above, we must also implement tp_richcompare
  529. __Pyx_Coroutine_compare, /*tp_richcompare*/
  530. #else
  531. 0, /*tp_richcompare*/
  532. #endif
  533. 0, /* tp_weaklistoffset */
  534. PyObject_SelfIter, /* tp_iter */
  535. (iternextfunc)__Pyx_async_gen_asend_iternext, /* tp_iternext */
  536. __Pyx_async_gen_asend_methods, /* tp_methods */
  537. 0, /* tp_members */
  538. 0, /* tp_getset */
  539. 0, /* tp_base */
  540. 0, /* tp_dict */
  541. 0, /* tp_descr_get */
  542. 0, /* tp_descr_set */
  543. 0, /* tp_dictoffset */
  544. 0, /* tp_init */
  545. 0, /* tp_alloc */
  546. 0, /* tp_new */
  547. 0, /* tp_free */
  548. 0, /* tp_is_gc */
  549. 0, /* tp_bases */
  550. 0, /* tp_mro */
  551. 0, /* tp_cache */
  552. 0, /* tp_subclasses */
  553. 0, /* tp_weaklist */
  554. 0, /* tp_del */
  555. 0, /* tp_version_tag */
  556. #if PY_VERSION_HEX >= 0x030400a1
  557. 0, /* tp_finalize */
  558. #endif
  559. #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  560. 0, /*tp_vectorcall*/
  561. #endif
  562. #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  563. 0, /*tp_print*/
  564. #endif
  565. #if PY_VERSION_HEX >= 0x030C0000
  566. 0, /*tp_watched*/
  567. #endif
  568. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  569. 0, /*tp_pypy_flags*/
  570. #endif
  571. };
  572. static PyObject *
  573. __Pyx_async_gen_asend_new(__pyx_PyAsyncGenObject *gen, PyObject *sendval)
  574. {
  575. __pyx_PyAsyncGenASend *o;
  576. if (__Pyx_ag_asend_freelist_free) {
  577. __Pyx_ag_asend_freelist_free--;
  578. o = __Pyx_ag_asend_freelist[__Pyx_ag_asend_freelist_free];
  579. _Py_NewReference((PyObject *)o);
  580. } else {
  581. o = PyObject_GC_New(__pyx_PyAsyncGenASend, __pyx__PyAsyncGenASendType);
  582. if (o == NULL) {
  583. return NULL;
  584. }
  585. }
  586. Py_INCREF(gen);
  587. o->ags_gen = gen;
  588. Py_XINCREF(sendval);
  589. o->ags_sendval = sendval;
  590. o->ags_state = __PYX_AWAITABLE_STATE_INIT;
  591. PyObject_GC_Track((PyObject*)o);
  592. return (PyObject*)o;
  593. }
  594. /* ---------- Async Generator Value Wrapper ------------ */
  595. static void
  596. __Pyx_async_gen_wrapped_val_dealloc(__pyx__PyAsyncGenWrappedValue *o)
  597. {
  598. PyObject_GC_UnTrack((PyObject *)o);
  599. Py_CLEAR(o->agw_val);
  600. if (__Pyx_ag_value_freelist_free < _PyAsyncGen_MAXFREELIST) {
  601. assert(__pyx__PyAsyncGenWrappedValue_CheckExact(o));
  602. __Pyx_ag_value_freelist[__Pyx_ag_value_freelist_free++] = o;
  603. } else {
  604. PyObject_GC_Del(o);
  605. }
  606. }
  607. static int
  608. __Pyx_async_gen_wrapped_val_traverse(__pyx__PyAsyncGenWrappedValue *o,
  609. visitproc visit, void *arg)
  610. {
  611. Py_VISIT(o->agw_val);
  612. return 0;
  613. }
  614. static PyTypeObject __pyx__PyAsyncGenWrappedValueType_type = {
  615. PyVarObject_HEAD_INIT(0, 0)
  616. "async_generator_wrapped_value", /* tp_name */
  617. sizeof(__pyx__PyAsyncGenWrappedValue), /* tp_basicsize */
  618. 0, /* tp_itemsize */
  619. /* methods */
  620. (destructor)__Pyx_async_gen_wrapped_val_dealloc, /* tp_dealloc */
  621. 0, /* tp_print */
  622. 0, /* tp_getattr */
  623. 0, /* tp_setattr */
  624. 0, /* tp_as_async */
  625. 0, /* tp_repr */
  626. 0, /* tp_as_number */
  627. 0, /* tp_as_sequence */
  628. 0, /* tp_as_mapping */
  629. 0, /* tp_hash */
  630. 0, /* tp_call */
  631. 0, /* tp_str */
  632. 0, /* tp_getattro */
  633. 0, /* tp_setattro */
  634. 0, /* tp_as_buffer */
  635. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
  636. 0, /* tp_doc */
  637. (traverseproc)__Pyx_async_gen_wrapped_val_traverse, /* tp_traverse */
  638. 0, /* tp_clear */
  639. 0, /* tp_richcompare */
  640. 0, /* tp_weaklistoffset */
  641. 0, /* tp_iter */
  642. 0, /* tp_iternext */
  643. 0, /* tp_methods */
  644. 0, /* tp_members */
  645. 0, /* tp_getset */
  646. 0, /* tp_base */
  647. 0, /* tp_dict */
  648. 0, /* tp_descr_get */
  649. 0, /* tp_descr_set */
  650. 0, /* tp_dictoffset */
  651. 0, /* tp_init */
  652. 0, /* tp_alloc */
  653. 0, /* tp_new */
  654. 0, /* tp_free */
  655. 0, /* tp_is_gc */
  656. 0, /* tp_bases */
  657. 0, /* tp_mro */
  658. 0, /* tp_cache */
  659. 0, /* tp_subclasses */
  660. 0, /* tp_weaklist */
  661. 0, /* tp_del */
  662. 0, /* tp_version_tag */
  663. #if PY_VERSION_HEX >= 0x030400a1
  664. 0, /* tp_finalize */
  665. #endif
  666. #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  667. 0, /*tp_vectorcall*/
  668. #endif
  669. #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  670. 0, /*tp_print*/
  671. #endif
  672. #if PY_VERSION_HEX >= 0x030C0000
  673. 0, /*tp_watched*/
  674. #endif
  675. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  676. 0, /*tp_pypy_flags*/
  677. #endif
  678. };
  679. static PyObject *
  680. __Pyx__PyAsyncGenValueWrapperNew(PyObject *val)
  681. {
  682. // NOTE: steals a reference to val !
  683. __pyx__PyAsyncGenWrappedValue *o;
  684. assert(val);
  685. if (__Pyx_ag_value_freelist_free) {
  686. __Pyx_ag_value_freelist_free--;
  687. o = __Pyx_ag_value_freelist[__Pyx_ag_value_freelist_free];
  688. assert(__pyx__PyAsyncGenWrappedValue_CheckExact(o));
  689. _Py_NewReference((PyObject*)o);
  690. } else {
  691. o = PyObject_GC_New(__pyx__PyAsyncGenWrappedValue, __pyx__PyAsyncGenWrappedValueType);
  692. if (unlikely(!o)) {
  693. Py_DECREF(val);
  694. return NULL;
  695. }
  696. }
  697. o->agw_val = val;
  698. // no Py_INCREF(val) - steals reference!
  699. PyObject_GC_Track((PyObject*)o);
  700. return (PyObject*)o;
  701. }
  702. /* ---------- Async Generator AThrow awaitable ------------ */
  703. static void
  704. __Pyx_async_gen_athrow_dealloc(__pyx_PyAsyncGenAThrow *o)
  705. {
  706. PyObject_GC_UnTrack((PyObject *)o);
  707. Py_CLEAR(o->agt_gen);
  708. Py_CLEAR(o->agt_args);
  709. PyObject_GC_Del(o);
  710. }
  711. static int
  712. __Pyx_async_gen_athrow_traverse(__pyx_PyAsyncGenAThrow *o, visitproc visit, void *arg)
  713. {
  714. Py_VISIT(o->agt_gen);
  715. Py_VISIT(o->agt_args);
  716. return 0;
  717. }
  718. static PyObject *
  719. __Pyx_async_gen_athrow_send(__pyx_PyAsyncGenAThrow *o, PyObject *arg)
  720. {
  721. __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*)o->agt_gen;
  722. PyObject *retval;
  723. if (o->agt_state == __PYX_AWAITABLE_STATE_CLOSED) {
  724. PyErr_SetNone(PyExc_StopIteration);
  725. return NULL;
  726. }
  727. if (o->agt_state == __PYX_AWAITABLE_STATE_INIT) {
  728. if (o->agt_gen->ag_closed) {
  729. PyErr_SetNone(PyExc_StopIteration);
  730. return NULL;
  731. }
  732. if (arg != Py_None) {
  733. PyErr_SetString(PyExc_RuntimeError, __Pyx_NON_INIT_CORO_MSG);
  734. return NULL;
  735. }
  736. o->agt_state = __PYX_AWAITABLE_STATE_ITER;
  737. if (o->agt_args == NULL) {
  738. /* aclose() mode */
  739. o->agt_gen->ag_closed = 1;
  740. retval = __Pyx__Coroutine_Throw((PyObject*)gen,
  741. /* Do not close generator when
  742. PyExc_GeneratorExit is passed */
  743. PyExc_GeneratorExit, NULL, NULL, NULL, 0);
  744. if (retval && __pyx__PyAsyncGenWrappedValue_CheckExact(retval)) {
  745. Py_DECREF(retval);
  746. goto yield_close;
  747. }
  748. } else {
  749. PyObject *typ;
  750. PyObject *tb = NULL;
  751. PyObject *val = NULL;
  752. if (!PyArg_UnpackTuple(o->agt_args, "athrow", 1, 3,
  753. &typ, &val, &tb)) {
  754. return NULL;
  755. }
  756. retval = __Pyx__Coroutine_Throw((PyObject*)gen,
  757. /* Do not close generator when PyExc_GeneratorExit is passed */
  758. typ, val, tb, o->agt_args, 0);
  759. retval = __Pyx_async_gen_unwrap_value(o->agt_gen, retval);
  760. }
  761. if (retval == NULL) {
  762. goto check_error;
  763. }
  764. return retval;
  765. }
  766. assert (o->agt_state == __PYX_AWAITABLE_STATE_ITER);
  767. retval = __Pyx_Coroutine_Send((PyObject *)gen, arg);
  768. if (o->agt_args) {
  769. return __Pyx_async_gen_unwrap_value(o->agt_gen, retval);
  770. } else {
  771. /* aclose() mode */
  772. if (retval) {
  773. if (__pyx__PyAsyncGenWrappedValue_CheckExact(retval)) {
  774. Py_DECREF(retval);
  775. goto yield_close;
  776. }
  777. else {
  778. return retval;
  779. }
  780. }
  781. else {
  782. goto check_error;
  783. }
  784. }
  785. yield_close:
  786. PyErr_SetString(
  787. PyExc_RuntimeError, __Pyx_ASYNC_GEN_IGNORED_EXIT_MSG);
  788. return NULL;
  789. check_error:
  790. if (PyErr_ExceptionMatches(__Pyx_PyExc_StopAsyncIteration)) {
  791. o->agt_state = __PYX_AWAITABLE_STATE_CLOSED;
  792. if (o->agt_args == NULL) {
  793. // when aclose() is called we don't want to propagate
  794. // StopAsyncIteration; just raise StopIteration, signalling
  795. // that 'aclose()' is done.
  796. PyErr_Clear();
  797. PyErr_SetNone(PyExc_StopIteration);
  798. }
  799. }
  800. else if (PyErr_ExceptionMatches(PyExc_GeneratorExit)) {
  801. o->agt_state = __PYX_AWAITABLE_STATE_CLOSED;
  802. PyErr_Clear(); /* ignore these errors */
  803. PyErr_SetNone(PyExc_StopIteration);
  804. }
  805. return NULL;
  806. }
  807. static PyObject *
  808. __Pyx_async_gen_athrow_throw(__pyx_PyAsyncGenAThrow *o, PyObject *args)
  809. {
  810. PyObject *retval;
  811. if (o->agt_state == __PYX_AWAITABLE_STATE_INIT) {
  812. PyErr_SetString(PyExc_RuntimeError, __Pyx_NON_INIT_CORO_MSG);
  813. return NULL;
  814. }
  815. if (o->agt_state == __PYX_AWAITABLE_STATE_CLOSED) {
  816. PyErr_SetNone(PyExc_StopIteration);
  817. return NULL;
  818. }
  819. retval = __Pyx_Coroutine_Throw((PyObject*)o->agt_gen, args);
  820. if (o->agt_args) {
  821. return __Pyx_async_gen_unwrap_value(o->agt_gen, retval);
  822. } else {
  823. /* aclose() mode */
  824. if (retval && __pyx__PyAsyncGenWrappedValue_CheckExact(retval)) {
  825. Py_DECREF(retval);
  826. PyErr_SetString(PyExc_RuntimeError, __Pyx_ASYNC_GEN_IGNORED_EXIT_MSG);
  827. return NULL;
  828. }
  829. return retval;
  830. }
  831. }
  832. static PyObject *
  833. __Pyx_async_gen_athrow_iternext(__pyx_PyAsyncGenAThrow *o)
  834. {
  835. return __Pyx_async_gen_athrow_send(o, Py_None);
  836. }
  837. static PyObject *
  838. __Pyx_async_gen_athrow_close(PyObject *g, CYTHON_UNUSED PyObject *args)
  839. {
  840. __pyx_PyAsyncGenAThrow *o = (__pyx_PyAsyncGenAThrow*) g;
  841. o->agt_state = __PYX_AWAITABLE_STATE_CLOSED;
  842. Py_RETURN_NONE;
  843. }
  844. static PyMethodDef __Pyx_async_gen_athrow_methods[] = {
  845. {"send", (PyCFunction)__Pyx_async_gen_athrow_send, METH_O, __Pyx_async_gen_send_doc},
  846. {"throw", (PyCFunction)__Pyx_async_gen_athrow_throw, METH_VARARGS, __Pyx_async_gen_throw_doc},
  847. {"close", (PyCFunction)__Pyx_async_gen_athrow_close, METH_NOARGS, __Pyx_async_gen_close_doc},
  848. {"__await__", (PyCFunction)__Pyx_async_gen_self_method, METH_NOARGS, __Pyx_async_gen_await_doc},
  849. {0, 0, 0, 0} /* Sentinel */
  850. };
  851. #if CYTHON_USE_ASYNC_SLOTS
  852. static __Pyx_PyAsyncMethodsStruct __Pyx_async_gen_athrow_as_async = {
  853. PyObject_SelfIter, /* am_await */
  854. 0, /* am_aiter */
  855. 0, /* am_anext */
  856. #if PY_VERSION_HEX >= 0x030A00A3
  857. 0, /*am_send*/
  858. #endif
  859. };
  860. #endif
  861. static PyTypeObject __pyx__PyAsyncGenAThrowType_type = {
  862. PyVarObject_HEAD_INIT(0, 0)
  863. "async_generator_athrow", /* tp_name */
  864. sizeof(__pyx_PyAsyncGenAThrow), /* tp_basicsize */
  865. 0, /* tp_itemsize */
  866. (destructor)__Pyx_async_gen_athrow_dealloc, /* tp_dealloc */
  867. 0, /* tp_print */
  868. 0, /* tp_getattr */
  869. 0, /* tp_setattr */
  870. #if CYTHON_USE_ASYNC_SLOTS
  871. &__Pyx_async_gen_athrow_as_async, /* tp_as_async */
  872. #else
  873. 0, /*tp_reserved*/
  874. #endif
  875. 0, /* tp_repr */
  876. 0, /* tp_as_number */
  877. 0, /* tp_as_sequence */
  878. 0, /* tp_as_mapping */
  879. 0, /* tp_hash */
  880. 0, /* tp_call */
  881. 0, /* tp_str */
  882. 0, /* tp_getattro */
  883. 0, /* tp_setattro */
  884. 0, /* tp_as_buffer */
  885. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
  886. 0, /* tp_doc */
  887. (traverseproc)__Pyx_async_gen_athrow_traverse, /* tp_traverse */
  888. 0, /* tp_clear */
  889. #if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1
  890. // in order to (mis-)use tp_reserved above, we must also implement tp_richcompare
  891. __Pyx_Coroutine_compare, /*tp_richcompare*/
  892. #else
  893. 0, /*tp_richcompare*/
  894. #endif
  895. 0, /* tp_weaklistoffset */
  896. PyObject_SelfIter, /* tp_iter */
  897. (iternextfunc)__Pyx_async_gen_athrow_iternext, /* tp_iternext */
  898. __Pyx_async_gen_athrow_methods, /* tp_methods */
  899. 0, /* tp_members */
  900. 0, /* tp_getset */
  901. 0, /* tp_base */
  902. 0, /* tp_dict */
  903. 0, /* tp_descr_get */
  904. 0, /* tp_descr_set */
  905. 0, /* tp_dictoffset */
  906. 0, /* tp_init */
  907. 0, /* tp_alloc */
  908. 0, /* tp_new */
  909. 0, /* tp_free */
  910. 0, /* tp_is_gc */
  911. 0, /* tp_bases */
  912. 0, /* tp_mro */
  913. 0, /* tp_cache */
  914. 0, /* tp_subclasses */
  915. 0, /* tp_weaklist */
  916. 0, /* tp_del */
  917. 0, /* tp_version_tag */
  918. #if PY_VERSION_HEX >= 0x030400a1
  919. 0, /* tp_finalize */
  920. #endif
  921. #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  922. 0, /*tp_vectorcall*/
  923. #endif
  924. #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
  925. 0, /*tp_print*/
  926. #endif
  927. #if PY_VERSION_HEX >= 0x030C0000
  928. 0, /*tp_watched*/
  929. #endif
  930. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  931. 0, /*tp_pypy_flags*/
  932. #endif
  933. };
  934. static PyObject *
  935. __Pyx_async_gen_athrow_new(__pyx_PyAsyncGenObject *gen, PyObject *args)
  936. {
  937. __pyx_PyAsyncGenAThrow *o;
  938. o = PyObject_GC_New(__pyx_PyAsyncGenAThrow, __pyx__PyAsyncGenAThrowType);
  939. if (o == NULL) {
  940. return NULL;
  941. }
  942. o->agt_gen = gen;
  943. o->agt_args = args;
  944. o->agt_state = __PYX_AWAITABLE_STATE_INIT;
  945. Py_INCREF(gen);
  946. Py_XINCREF(args);
  947. PyObject_GC_Track((PyObject*)o);
  948. return (PyObject*)o;
  949. }
  950. /* ---------- global type sharing ------------ */
  951. static int __pyx_AsyncGen_init(void) {
  952. // on Windows, C-API functions can't be used in slots statically
  953. __pyx_AsyncGenType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  954. __pyx__PyAsyncGenWrappedValueType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  955. __pyx__PyAsyncGenAThrowType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  956. __pyx__PyAsyncGenASendType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict;
  957. __pyx_AsyncGenType = __Pyx_FetchCommonType(&__pyx_AsyncGenType_type);
  958. if (unlikely(!__pyx_AsyncGenType))
  959. return -1;
  960. __pyx__PyAsyncGenAThrowType = __Pyx_FetchCommonType(&__pyx__PyAsyncGenAThrowType_type);
  961. if (unlikely(!__pyx__PyAsyncGenAThrowType))
  962. return -1;
  963. __pyx__PyAsyncGenWrappedValueType = __Pyx_FetchCommonType(&__pyx__PyAsyncGenWrappedValueType_type);
  964. if (unlikely(!__pyx__PyAsyncGenWrappedValueType))
  965. return -1;
  966. __pyx__PyAsyncGenASendType = __Pyx_FetchCommonType(&__pyx__PyAsyncGenASendType_type);
  967. if (unlikely(!__pyx__PyAsyncGenASendType))
  968. return -1;
  969. return 0;
  970. }