Cython 3.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +250 -0
  4. Cython/Build/Dependencies.py +1275 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +342 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/Tests/TestCyCache.py +119 -0
  9. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  10. Cython/Build/Tests/TestDependencies.py +133 -0
  11. Cython/Build/Tests/TestInline.py +112 -0
  12. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  13. Cython/Build/Tests/TestRecythonize.py +212 -0
  14. Cython/Build/Tests/TestStripLiterals.py +155 -0
  15. Cython/Build/Tests/__init__.py +1 -0
  16. Cython/Build/__init__.py +8 -0
  17. Cython/CodeWriter.py +811 -0
  18. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  19. Cython/Compiler/Annotate.py +326 -0
  20. Cython/Compiler/AutoDocTransforms.py +314 -0
  21. Cython/Compiler/Buffer.py +680 -0
  22. Cython/Compiler/Builtin.py +862 -0
  23. Cython/Compiler/CmdLine.py +243 -0
  24. Cython/Compiler/Code.pxd +145 -0
  25. Cython/Compiler/Code.py +3328 -0
  26. Cython/Compiler/CodeGeneration.py +33 -0
  27. Cython/Compiler/CythonScope.py +179 -0
  28. Cython/Compiler/Dataclass.py +868 -0
  29. Cython/Compiler/DebugFlags.py +21 -0
  30. Cython/Compiler/Errors.py +295 -0
  31. Cython/Compiler/ExprNodes.py +15051 -0
  32. Cython/Compiler/FlowControl.pxd +97 -0
  33. Cython/Compiler/FlowControl.py +1438 -0
  34. Cython/Compiler/FusedNode.py +998 -0
  35. Cython/Compiler/Future.py +16 -0
  36. Cython/Compiler/Interpreter.py +57 -0
  37. Cython/Compiler/Lexicon.py +340 -0
  38. Cython/Compiler/LineTable.py +114 -0
  39. Cython/Compiler/Main.py +779 -0
  40. Cython/Compiler/MatchCaseNodes.py +259 -0
  41. Cython/Compiler/MemoryView.py +860 -0
  42. Cython/Compiler/ModuleNode.py +4065 -0
  43. Cython/Compiler/Naming.py +369 -0
  44. Cython/Compiler/Nodes.py +10557 -0
  45. Cython/Compiler/Optimize.py +5269 -0
  46. Cython/Compiler/Options.py +828 -0
  47. Cython/Compiler/ParseTreeTransforms.pxd +78 -0
  48. Cython/Compiler/ParseTreeTransforms.py +4441 -0
  49. Cython/Compiler/Parsing.pxd +9 -0
  50. Cython/Compiler/Parsing.py +4797 -0
  51. Cython/Compiler/Pipeline.py +425 -0
  52. Cython/Compiler/PyrexTypes.py +5572 -0
  53. Cython/Compiler/Pythran.py +223 -0
  54. Cython/Compiler/Scanning.pxd +40 -0
  55. Cython/Compiler/Scanning.py +574 -0
  56. Cython/Compiler/StringEncoding.py +347 -0
  57. Cython/Compiler/Symtab.py +2998 -0
  58. Cython/Compiler/Tests/TestBuffer.py +105 -0
  59. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  60. Cython/Compiler/Tests/TestCmdLine.py +573 -0
  61. Cython/Compiler/Tests/TestCode.py +86 -0
  62. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  63. Cython/Compiler/Tests/TestGrammar.py +202 -0
  64. Cython/Compiler/Tests/TestMemView.py +71 -0
  65. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  66. Cython/Compiler/Tests/TestScanning.py +134 -0
  67. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  68. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  69. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  70. Cython/Compiler/Tests/TestTreePath.py +93 -0
  71. Cython/Compiler/Tests/TestTypes.py +75 -0
  72. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  73. Cython/Compiler/Tests/TestVisitor.py +61 -0
  74. Cython/Compiler/Tests/Utils.py +36 -0
  75. Cython/Compiler/Tests/__init__.py +1 -0
  76. Cython/Compiler/TreeFragment.py +278 -0
  77. Cython/Compiler/TreePath.py +290 -0
  78. Cython/Compiler/TypeInference.py +584 -0
  79. Cython/Compiler/TypeSlots.py +1181 -0
  80. Cython/Compiler/UFuncs.py +311 -0
  81. Cython/Compiler/UtilNodes.py +387 -0
  82. Cython/Compiler/UtilityCode.py +274 -0
  83. Cython/Compiler/Version.py +8 -0
  84. Cython/Compiler/Visitor.pxd +53 -0
  85. Cython/Compiler/Visitor.py +861 -0
  86. Cython/Compiler/__init__.py +1 -0
  87. Cython/Coverage.py +443 -0
  88. Cython/Debugger/Cygdb.py +179 -0
  89. Cython/Debugger/DebugWriter.py +82 -0
  90. Cython/Debugger/Tests/TestLibCython.py +275 -0
  91. Cython/Debugger/Tests/__init__.py +1 -0
  92. Cython/Debugger/Tests/cfuncs.c +8 -0
  93. Cython/Debugger/Tests/codefile +49 -0
  94. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  95. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  96. Cython/Debugger/__init__.py +1 -0
  97. Cython/Debugger/libcython.py +1549 -0
  98. Cython/Debugger/libpython.py +2821 -0
  99. Cython/Debugging.py +20 -0
  100. Cython/Distutils/__init__.py +2 -0
  101. Cython/Distutils/build_ext.py +137 -0
  102. Cython/Distutils/extension.py +96 -0
  103. Cython/Distutils/old_build_ext.py +351 -0
  104. Cython/Includes/cpython/__init__.pxd +173 -0
  105. Cython/Includes/cpython/array.pxd +174 -0
  106. Cython/Includes/cpython/bool.pxd +37 -0
  107. Cython/Includes/cpython/buffer.pxd +112 -0
  108. Cython/Includes/cpython/bytearray.pxd +33 -0
  109. Cython/Includes/cpython/bytes.pxd +200 -0
  110. Cython/Includes/cpython/cellobject.pxd +35 -0
  111. Cython/Includes/cpython/ceval.pxd +8 -0
  112. Cython/Includes/cpython/codecs.pxd +121 -0
  113. Cython/Includes/cpython/complex.pxd +55 -0
  114. Cython/Includes/cpython/contextvars.pxd +141 -0
  115. Cython/Includes/cpython/conversion.pxd +36 -0
  116. Cython/Includes/cpython/datetime.pxd +384 -0
  117. Cython/Includes/cpython/descr.pxd +26 -0
  118. Cython/Includes/cpython/dict.pxd +187 -0
  119. Cython/Includes/cpython/exc.pxd +263 -0
  120. Cython/Includes/cpython/fileobject.pxd +57 -0
  121. Cython/Includes/cpython/float.pxd +47 -0
  122. Cython/Includes/cpython/function.pxd +65 -0
  123. Cython/Includes/cpython/genobject.pxd +25 -0
  124. Cython/Includes/cpython/getargs.pxd +12 -0
  125. Cython/Includes/cpython/instance.pxd +25 -0
  126. Cython/Includes/cpython/iterator.pxd +36 -0
  127. Cython/Includes/cpython/iterobject.pxd +24 -0
  128. Cython/Includes/cpython/list.pxd +92 -0
  129. Cython/Includes/cpython/long.pxd +149 -0
  130. Cython/Includes/cpython/longintrepr.pxd +19 -0
  131. Cython/Includes/cpython/mapping.pxd +63 -0
  132. Cython/Includes/cpython/marshal.pxd +66 -0
  133. Cython/Includes/cpython/mem.pxd +120 -0
  134. Cython/Includes/cpython/memoryview.pxd +50 -0
  135. Cython/Includes/cpython/method.pxd +49 -0
  136. Cython/Includes/cpython/module.pxd +208 -0
  137. Cython/Includes/cpython/number.pxd +258 -0
  138. Cython/Includes/cpython/object.pxd +433 -0
  139. Cython/Includes/cpython/pycapsule.pxd +143 -0
  140. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  141. Cython/Includes/cpython/pyport.pxd +8 -0
  142. Cython/Includes/cpython/pystate.pxd +95 -0
  143. Cython/Includes/cpython/pythread.pxd +53 -0
  144. Cython/Includes/cpython/ref.pxd +67 -0
  145. Cython/Includes/cpython/sequence.pxd +134 -0
  146. Cython/Includes/cpython/set.pxd +119 -0
  147. Cython/Includes/cpython/slice.pxd +70 -0
  148. Cython/Includes/cpython/time.pxd +129 -0
  149. Cython/Includes/cpython/tuple.pxd +72 -0
  150. Cython/Includes/cpython/type.pxd +53 -0
  151. Cython/Includes/cpython/unicode.pxd +639 -0
  152. Cython/Includes/cpython/version.pxd +32 -0
  153. Cython/Includes/cpython/weakref.pxd +42 -0
  154. Cython/Includes/libc/__init__.pxd +1 -0
  155. Cython/Includes/libc/complex.pxd +35 -0
  156. Cython/Includes/libc/errno.pxd +127 -0
  157. Cython/Includes/libc/float.pxd +43 -0
  158. Cython/Includes/libc/limits.pxd +28 -0
  159. Cython/Includes/libc/locale.pxd +46 -0
  160. Cython/Includes/libc/math.pxd +209 -0
  161. Cython/Includes/libc/setjmp.pxd +10 -0
  162. Cython/Includes/libc/signal.pxd +64 -0
  163. Cython/Includes/libc/stddef.pxd +9 -0
  164. Cython/Includes/libc/stdint.pxd +105 -0
  165. Cython/Includes/libc/stdio.pxd +80 -0
  166. Cython/Includes/libc/stdlib.pxd +72 -0
  167. Cython/Includes/libc/string.pxd +50 -0
  168. Cython/Includes/libc/time.pxd +47 -0
  169. Cython/Includes/libcpp/__init__.pxd +4 -0
  170. Cython/Includes/libcpp/algorithm.pxd +320 -0
  171. Cython/Includes/libcpp/any.pxd +16 -0
  172. Cython/Includes/libcpp/atomic.pxd +59 -0
  173. Cython/Includes/libcpp/bit.pxd +29 -0
  174. Cython/Includes/libcpp/cast.pxd +12 -0
  175. Cython/Includes/libcpp/cmath.pxd +518 -0
  176. Cython/Includes/libcpp/complex.pxd +106 -0
  177. Cython/Includes/libcpp/deque.pxd +165 -0
  178. Cython/Includes/libcpp/execution.pxd +15 -0
  179. Cython/Includes/libcpp/forward_list.pxd +63 -0
  180. Cython/Includes/libcpp/functional.pxd +26 -0
  181. Cython/Includes/libcpp/iterator.pxd +34 -0
  182. Cython/Includes/libcpp/limits.pxd +61 -0
  183. Cython/Includes/libcpp/list.pxd +117 -0
  184. Cython/Includes/libcpp/map.pxd +252 -0
  185. Cython/Includes/libcpp/memory.pxd +115 -0
  186. Cython/Includes/libcpp/numbers.pxd +15 -0
  187. Cython/Includes/libcpp/numeric.pxd +131 -0
  188. Cython/Includes/libcpp/optional.pxd +34 -0
  189. Cython/Includes/libcpp/pair.pxd +1 -0
  190. Cython/Includes/libcpp/queue.pxd +25 -0
  191. Cython/Includes/libcpp/random.pxd +166 -0
  192. Cython/Includes/libcpp/set.pxd +228 -0
  193. Cython/Includes/libcpp/stack.pxd +11 -0
  194. Cython/Includes/libcpp/string.pxd +333 -0
  195. Cython/Includes/libcpp/typeindex.pxd +15 -0
  196. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  197. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  198. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  199. Cython/Includes/libcpp/utility.pxd +30 -0
  200. Cython/Includes/libcpp/vector.pxd +167 -0
  201. Cython/Includes/openmp.pxd +50 -0
  202. Cython/Includes/posix/__init__.pxd +1 -0
  203. Cython/Includes/posix/dlfcn.pxd +14 -0
  204. Cython/Includes/posix/fcntl.pxd +86 -0
  205. Cython/Includes/posix/ioctl.pxd +4 -0
  206. Cython/Includes/posix/mman.pxd +101 -0
  207. Cython/Includes/posix/resource.pxd +57 -0
  208. Cython/Includes/posix/select.pxd +21 -0
  209. Cython/Includes/posix/signal.pxd +73 -0
  210. Cython/Includes/posix/stat.pxd +98 -0
  211. Cython/Includes/posix/stdio.pxd +37 -0
  212. Cython/Includes/posix/stdlib.pxd +29 -0
  213. Cython/Includes/posix/strings.pxd +9 -0
  214. Cython/Includes/posix/time.pxd +71 -0
  215. Cython/Includes/posix/types.pxd +30 -0
  216. Cython/Includes/posix/uio.pxd +26 -0
  217. Cython/Includes/posix/unistd.pxd +271 -0
  218. Cython/Includes/posix/wait.pxd +38 -0
  219. Cython/Plex/Actions.pxd +24 -0
  220. Cython/Plex/Actions.py +119 -0
  221. Cython/Plex/DFA.pxd +14 -0
  222. Cython/Plex/DFA.py +164 -0
  223. Cython/Plex/Errors.py +48 -0
  224. Cython/Plex/Lexicons.py +178 -0
  225. Cython/Plex/Machines.pxd +36 -0
  226. Cython/Plex/Machines.py +238 -0
  227. Cython/Plex/Regexps.py +539 -0
  228. Cython/Plex/Scanners.pxd +47 -0
  229. Cython/Plex/Scanners.py +360 -0
  230. Cython/Plex/Transitions.pxd +14 -0
  231. Cython/Plex/Transitions.py +239 -0
  232. Cython/Plex/__init__.py +34 -0
  233. Cython/Runtime/__init__.py +1 -0
  234. Cython/Runtime/refnanny.pyx +261 -0
  235. Cython/Shadow.py +656 -0
  236. Cython/Shadow.pyi +521 -0
  237. Cython/StringIOTree.py +170 -0
  238. Cython/Tempita/__init__.py +4 -0
  239. Cython/Tempita/_looper.py +154 -0
  240. Cython/Tempita/_tempita.py +1091 -0
  241. Cython/TestUtils.py +417 -0
  242. Cython/Tests/TestCodeWriter.py +128 -0
  243. Cython/Tests/TestCythonUtils.py +202 -0
  244. Cython/Tests/TestJediTyper.py +223 -0
  245. Cython/Tests/TestShadow.py +114 -0
  246. Cython/Tests/TestStringIOTree.py +67 -0
  247. Cython/Tests/TestTestUtils.py +90 -0
  248. Cython/Tests/__init__.py +1 -0
  249. Cython/Tests/xmlrunner.py +390 -0
  250. Cython/Utility/AsyncGen.c +1263 -0
  251. Cython/Utility/Buffer.c +875 -0
  252. Cython/Utility/Builtins.c +660 -0
  253. Cython/Utility/CConvert.pyx +134 -0
  254. Cython/Utility/CMath.c +95 -0
  255. Cython/Utility/CommonStructures.c +139 -0
  256. Cython/Utility/Complex.c +378 -0
  257. Cython/Utility/Coroutine.c +2413 -0
  258. Cython/Utility/CpdefEnums.pyx +108 -0
  259. Cython/Utility/CppConvert.pyx +279 -0
  260. Cython/Utility/CppSupport.cpp +133 -0
  261. Cython/Utility/CythonFunction.c +1851 -0
  262. Cython/Utility/Dataclasses.c +185 -0
  263. Cython/Utility/Dataclasses.py +112 -0
  264. Cython/Utility/Embed.c +125 -0
  265. Cython/Utility/Exceptions.c +1017 -0
  266. Cython/Utility/ExtensionTypes.c +797 -0
  267. Cython/Utility/FunctionArguments.c +573 -0
  268. Cython/Utility/ImportExport.c +912 -0
  269. Cython/Utility/MemoryView.pyx +1478 -0
  270. Cython/Utility/MemoryView_C.c +992 -0
  271. Cython/Utility/ModuleSetupCode.c +2501 -0
  272. Cython/Utility/NumpyImportArray.c +46 -0
  273. Cython/Utility/ObjectHandling.c +3054 -0
  274. Cython/Utility/Optimize.c +1533 -0
  275. Cython/Utility/Overflow.c +404 -0
  276. Cython/Utility/Printing.c +86 -0
  277. Cython/Utility/Profile.c +660 -0
  278. Cython/Utility/StringTools.c +1206 -0
  279. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  280. Cython/Utility/TestCythonScope.pyx +75 -0
  281. Cython/Utility/TestUtilityLoader.c +12 -0
  282. Cython/Utility/TypeConversion.c +1329 -0
  283. Cython/Utility/UFuncs.pyx +50 -0
  284. Cython/Utility/UFuncs_C.c +89 -0
  285. Cython/Utility/__init__.py +28 -0
  286. Cython/Utility/arrayarray.h +143 -0
  287. Cython/Utils.py +687 -0
  288. Cython/__init__.py +10 -0
  289. Cython/__init__.pyi +7 -0
  290. Cython/py.typed +0 -0
  291. Cython-3.1.0a1.dist-info/COPYING.txt +19 -0
  292. Cython-3.1.0a1.dist-info/LICENSE.txt +176 -0
  293. Cython-3.1.0a1.dist-info/METADATA +67 -0
  294. Cython-3.1.0a1.dist-info/RECORD +301 -0
  295. Cython-3.1.0a1.dist-info/WHEEL +5 -0
  296. Cython-3.1.0a1.dist-info/entry_points.txt +4 -0
  297. Cython-3.1.0a1.dist-info/top_level.txt +3 -0
  298. cython.py +29 -0
  299. pyximport/__init__.py +4 -0
  300. pyximport/pyxbuild.py +160 -0
  301. pyximport/pyximport.py +482 -0
@@ -0,0 +1,2413 @@
1
+ // ### CPython revisions to investigate for potential changes:
2
+
3
+ // 2f180ce2cb6 (bpo-44530: Add co_qualname field to PyCodeObject (GH-26941))
4
+ // a4760cc32d9 (bpo-42747: Remove Py_TPFLAGS_HAVE_AM_SEND and make Py_TPFLAGS_HAVE_VERSION_TAG no-op (GH-27260))
5
+ // ae0a2b75625 (bpo-44590: Lazily allocate frame objects (GH-27077))
6
+ // 69806b9516d (bpo-46009: Do not exhaust generator when send() method raises (GH-29986))
7
+ // b04dfbbe4bd (bpo-46409: Make generators in bytecode (GH-30633) -- ".gi_suspended")
8
+ // 304197b3820 (bpo-46944: use FASTCALL calling convention in generator.throw (GH-31723))
9
+ // 8be7c2bc5ad (bpo-14911: Corrected generator.throw() documentation (GH-32207))
10
+ // 5bfb3c372bd (GH-90997: Wrap yield from/await in a virtual try/except StopIteration (GH-96010))
11
+ // 83a3de4e063 (gh-96348: Deprecate the 3-arg signature of coroutine.throw and generator.throw (GH-96428))
12
+ // f4adb975061 (GH-96793: Implement PEP 479 in bytecode. (GH-99006))
13
+ // f02fa64bf2d (GH-100762: Don't call `gen.throw()` in `gen.close()`, unless necessary. (GH-101013))
14
+ // 11a2c6ce516 (gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (in Objects/) (#102218))
15
+ // ced13c96a4e (gh-79940: add introspection API for asynchronous generators to `inspect` module (#11590) -- ".ag_suspended")
16
+ // d56c933992c (gh-104770: Let generator.close() return value (#104771))
17
+ // 7fc542c88dc (GH-89091: raise `RuntimeWarning` for unawaited async generator methods (#104611))
18
+ // 0d30a5a4096 (GH-100964: Break cycles involving exception state when returning from generator (GH-107563))
19
+ // 7d369d471cf (GH-117536: GH-117894: fix athrow().throw(...) unawaited warning (GH-117851))
20
+ // fc7e1aa3c00 (GH-117881: fix athrow().throw()/asend().throw() concurrent access (GH-117882))
21
+ // e5c699280de (GH-117714: implement athrow().close() and asend().close() using throw (GH-117906))
22
+ // 2c7209a3bdf (gh-114091: Reword error message for unawaitable types (#114090))
23
+
24
+
25
+ //////////////////// CoroutineSetYieldFrom ////////////////////
26
+
27
+ static void
28
+ __Pyx_Coroutine_Set_Owned_Yield_From(__pyx_CoroutineObject *gen, PyObject *yf) {
29
+ // NOTE: steals a reference to yf by transferring it to 'gen->yieldfrom' !
30
+ assert (!gen->yieldfrom);
31
+ #if CYTHON_USE_AM_SEND
32
+ assert (!gen->yieldfrom_am_send);
33
+ #if PY_VERSION_HEX < 0x030A00F0
34
+ if (__Pyx_PyType_HasFeature(Py_TYPE(yf), __Pyx_TPFLAGS_HAVE_AM_SEND))
35
+ #endif
36
+ {
37
+ __Pyx_pyiter_sendfunc am_send;
38
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030A0000
39
+ am_send = __Pyx_PyObject_TryGetSubSlot(yf, tp_as_async, am_send, __Pyx_pyiter_sendfunc);
40
+ #else
41
+ __Pyx_PyAsyncMethodsStruct* tp_as_async = (__Pyx_PyAsyncMethodsStruct*) Py_TYPE(yf)->tp_as_async;
42
+ am_send = tp_as_async ? tp_as_async->am_send : NULL;
43
+ #endif
44
+ if (likely(am_send)) {
45
+ // Keep a direct reference to am->am_send, if provided.
46
+ gen->yieldfrom_am_send = am_send;
47
+ }
48
+ }
49
+ #endif
50
+ gen->yieldfrom = yf;
51
+ }
52
+
53
+
54
+ //////////////////// GeneratorYieldFrom.proto ////////////////////
55
+
56
+ static CYTHON_INLINE __Pyx_PySendResult __Pyx_Generator_Yield_From(__pyx_CoroutineObject *gen, PyObject *source, PyObject **retval);
57
+
58
+ //////////////////// GeneratorYieldFrom ////////////////////
59
+ //@requires: Generator
60
+ //@requires: CoroutineSetYieldFrom
61
+ //@requires: ObjectHandling.c::IterNextPlain
62
+
63
+ #if CYTHON_USE_TYPE_SLOTS
64
+ static void __Pyx_PyIter_CheckErrorAndDecref(PyObject *source) {
65
+ __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
66
+ PyErr_Format(PyExc_TypeError,
67
+ "iter() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", source_type_name);
68
+ __Pyx_DECREF_TypeName(source_type_name);
69
+ Py_DECREF(source);
70
+ }
71
+ #endif
72
+
73
+ static CYTHON_INLINE __Pyx_PySendResult __Pyx_Generator_Yield_From(__pyx_CoroutineObject *gen, PyObject *source, PyObject **retval) {
74
+ PyObject *source_gen;
75
+ __Pyx_PySendResult result;
76
+ #ifdef __Pyx_Coroutine_USED
77
+ if (__Pyx_Coroutine_Check(source)) {
78
+ // TODO: this should only happen for types.coroutine()ed generators, but we can't determine that here
79
+ Py_INCREF(source);
80
+ source_gen = source;
81
+ result = __Pyx_Coroutine_AmSend(source, Py_None, retval);
82
+ } else
83
+ #endif
84
+ {
85
+ #if CYTHON_USE_TYPE_SLOTS
86
+ if (likely(Py_TYPE(source)->tp_iter)) {
87
+ source_gen = Py_TYPE(source)->tp_iter(source);
88
+ if (unlikely(!source_gen)) {
89
+ *retval = NULL;
90
+ return PYGEN_ERROR;
91
+ }
92
+ if (unlikely(!PyIter_Check(source_gen))) {
93
+ __Pyx_PyIter_CheckErrorAndDecref(source_gen);
94
+ *retval = NULL;
95
+ return PYGEN_ERROR;
96
+ }
97
+ } else
98
+ // CPython also allows non-iterable sequences to be iterated over
99
+ #endif
100
+ {
101
+ source_gen = PyObject_GetIter(source);
102
+ if (unlikely(!source_gen)) {
103
+ *retval = NULL;
104
+ return PYGEN_ERROR;
105
+ }
106
+ }
107
+ // source_gen is now the iterator, make the first next() call
108
+ *retval = __Pyx_PyIter_Next_Plain(source_gen);
109
+ result = __Pyx_Coroutine_status_from_result(retval);
110
+ }
111
+ if (likely(result == PYGEN_NEXT)) {
112
+ __Pyx_Coroutine_Set_Owned_Yield_From(gen, source_gen);
113
+ return PYGEN_NEXT;
114
+ }
115
+ Py_DECREF(source_gen);
116
+ return result;
117
+ }
118
+
119
+
120
+ //////////////////// CoroutineYieldFrom.proto ////////////////////
121
+
122
+ #define __Pyx_Coroutine_Yield_From(gen, source, retval) \
123
+ (__Pyx_Coroutine_Check(source) ? \
124
+ __Pyx_Coroutine_Yield_From_Coroutine(gen, source, retval) : \
125
+ __Pyx_Coroutine_Yield_From_Generic(gen, source, retval))
126
+
127
+ static CYTHON_INLINE __Pyx_PySendResult __Pyx_Coroutine_Yield_From_Coroutine(__pyx_CoroutineObject *gen, PyObject *source, PyObject **retval); /*proto*/
128
+ static CYTHON_INLINE __Pyx_PySendResult __Pyx_Coroutine_Yield_From_Generic(__pyx_CoroutineObject *gen, PyObject *source, PyObject **retval); /*proto*/
129
+
130
+ //////////////////// CoroutineYieldFrom ////////////////////
131
+ //@requires: Coroutine
132
+ //@requires: GetAwaitIter
133
+ //@requires: CoroutineSetYieldFrom
134
+ //@requires: ObjectHandling.c::IterNextPlain
135
+
136
+ static __Pyx_PySendResult __Pyx_Coroutine_Yield_From_Generic(__pyx_CoroutineObject *gen, PyObject *source, PyObject **retval) {
137
+ __Pyx_PySendResult result;
138
+ PyObject *source_gen = NULL;
139
+ #ifdef __Pyx_AsyncGen_USED
140
+ // inlined "__pyx_PyAsyncGenASend" handling to avoid the series of generic calls
141
+ if (__pyx_PyAsyncGenASend_CheckExact(source)) {
142
+ *retval = __Pyx_async_gen_asend_iternext(source);
143
+ if (*retval) {
144
+ Py_INCREF(source);
145
+ __Pyx_Coroutine_Set_Owned_Yield_From(gen, source);
146
+ return PYGEN_NEXT;
147
+ }
148
+ } else
149
+ #endif
150
+ {
151
+ source_gen = __Pyx__Coroutine_GetAwaitableIter(source);
152
+ if (unlikely(!source_gen)) return PYGEN_ERROR;
153
+
154
+ // source_gen is now the iterator, make the first next() call
155
+ if (__Pyx_Coroutine_Check(source_gen)) {
156
+ result = __Pyx_Coroutine_Yield_From_Coroutine(gen, source_gen, retval);
157
+ Py_DECREF(source_gen);
158
+ return result;
159
+ }
160
+
161
+ *retval = __Pyx_PyIter_Next_Plain(source_gen);
162
+ if (*retval) {
163
+ __Pyx_Coroutine_Set_Owned_Yield_From(gen, source_gen);
164
+ return PYGEN_NEXT;
165
+ }
166
+ }
167
+
168
+ result = __Pyx_Coroutine_status_from_result(retval);
169
+ Py_XDECREF(source_gen);
170
+ return result;
171
+ }
172
+
173
+ static CYTHON_INLINE __Pyx_PySendResult __Pyx_Coroutine_Yield_From_Coroutine(__pyx_CoroutineObject *gen, PyObject *source, PyObject **retval) {
174
+ __Pyx_PySendResult result;
175
+ if (unlikely(((__pyx_CoroutineObject*)source)->yieldfrom)) {
176
+ PyErr_SetString(
177
+ PyExc_RuntimeError,
178
+ "coroutine is being awaited already");
179
+ return PYGEN_ERROR;
180
+ }
181
+ result = __Pyx_Coroutine_AmSend(source, Py_None, retval);
182
+ if (result == PYGEN_NEXT) {
183
+ Py_INCREF(source);
184
+ __Pyx_Coroutine_Set_Owned_Yield_From(gen, source);
185
+ }
186
+ return result;
187
+ }
188
+
189
+
190
+ //////////////////// GetAwaitIter.proto ////////////////////
191
+
192
+ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o); /*proto*/
193
+ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *o); /*proto*/
194
+
195
+ //////////////////// GetAwaitIter ////////////////////
196
+ //@requires: ObjectHandling.c::PyObjectGetMethod
197
+ //@requires: ObjectHandling.c::PyObjectCallNoArg
198
+ //@requires: ObjectHandling.c::PyObjectCallOneArg
199
+
200
+ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o) {
201
+ #ifdef __Pyx_Coroutine_USED
202
+ if (__Pyx_Coroutine_Check(o)) {
203
+ return __Pyx_NewRef(o);
204
+ }
205
+ #endif
206
+ return __Pyx__Coroutine_GetAwaitableIter(o);
207
+ }
208
+
209
+
210
+ static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) {
211
+ #if PY_VERSION_HEX < 0x030d0000 || defined(_PyErr_FormatFromCause)
212
+ __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
213
+ _PyErr_FormatFromCause(PyExc_TypeError,
214
+ "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name);
215
+ __Pyx_DECREF_TypeName(source_type_name);
216
+ #else
217
+ PyObject *exc, *val, *val2, *tb;
218
+ __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source));
219
+ assert(PyErr_Occurred());
220
+ PyErr_Fetch(&exc, &val, &tb);
221
+ PyErr_NormalizeException(&exc, &val, &tb);
222
+ if (tb != NULL) {
223
+ PyException_SetTraceback(val, tb);
224
+ Py_DECREF(tb);
225
+ }
226
+ Py_DECREF(exc);
227
+ assert(!PyErr_Occurred());
228
+ PyErr_Format(PyExc_TypeError,
229
+ "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name);
230
+ __Pyx_DECREF_TypeName(source_type_name);
231
+
232
+ PyErr_Fetch(&exc, &val2, &tb);
233
+ PyErr_NormalizeException(&exc, &val2, &tb);
234
+ Py_INCREF(val);
235
+ PyException_SetCause(val2, val);
236
+ PyException_SetContext(val2, val);
237
+ PyErr_Restore(exc, val2, tb);
238
+ #endif
239
+ }
240
+
241
+ // adapted from genobject.c in Py3.5
242
+ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) {
243
+ PyObject *res;
244
+ unaryfunc am_await;
245
+ am_await = __Pyx_PyObject_TryGetSubSlot(obj, tp_as_async, am_await, unaryfunc);
246
+ if (likely(am_await)) {
247
+ res = (*am_await)(obj);
248
+ } else
249
+ if (PyCoro_CheckExact(obj)) {
250
+ return __Pyx_NewRef(obj);
251
+ } else
252
+ #if CYTHON_COMPILING_IN_CPYTHON && defined(CO_ITERABLE_COROUTINE)
253
+ #if PY_VERSION_HEX >= 0x030C00A6
254
+ if (PyGen_CheckExact(obj) && (PyGen_GetCode((PyGenObject*)obj)->co_flags & CO_ITERABLE_COROUTINE)) {
255
+ #else
256
+ if (PyGen_CheckExact(obj) && ((PyGenObject*)obj)->gi_code && ((PyCodeObject *)((PyGenObject*)obj)->gi_code)->co_flags & CO_ITERABLE_COROUTINE) {
257
+ #endif
258
+ // Python generator marked with "@types.coroutine" decorator
259
+ return __Pyx_NewRef(obj);
260
+ } else
261
+ #endif
262
+ {
263
+ PyObject *method = NULL;
264
+ int is_method = __Pyx_PyObject_GetMethod(obj, PYIDENT("__await__"), &method);
265
+ if (likely(is_method)) {
266
+ res = __Pyx_PyObject_CallOneArg(method, obj);
267
+ } else if (likely(method)) {
268
+ res = __Pyx_PyObject_CallNoArg(method);
269
+ } else
270
+ goto slot_error;
271
+ Py_DECREF(method);
272
+ }
273
+ if (unlikely(!res)) {
274
+ // surprisingly, CPython replaces the exception here...
275
+ __Pyx_Coroutine_AwaitableIterError(obj);
276
+ goto bad;
277
+ }
278
+ if (unlikely(!PyIter_Check(res))) {
279
+ __Pyx_TypeName res_type_name = __Pyx_PyType_GetName(Py_TYPE(res));
280
+ PyErr_Format(PyExc_TypeError,
281
+ "__await__() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", res_type_name);
282
+ __Pyx_DECREF_TypeName(res_type_name);
283
+ Py_CLEAR(res);
284
+ } else {
285
+ int is_coroutine = 0;
286
+ #ifdef __Pyx_Coroutine_USED
287
+ is_coroutine |= __Pyx_Coroutine_Check(res);
288
+ #endif
289
+ is_coroutine |= PyCoro_CheckExact(res);
290
+ if (unlikely(is_coroutine)) {
291
+ /* __await__ must return an *iterator*, not
292
+ a coroutine or another awaitable (see PEP 492) */
293
+ PyErr_SetString(PyExc_TypeError,
294
+ "__await__() returned a coroutine");
295
+ Py_CLEAR(res);
296
+ }
297
+ }
298
+ return res;
299
+ slot_error:
300
+ {
301
+ __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
302
+ PyErr_Format(PyExc_TypeError,
303
+ "object " __Pyx_FMT_TYPENAME " can't be used in 'await' expression", obj_type_name);
304
+ __Pyx_DECREF_TypeName(obj_type_name);
305
+ }
306
+ bad:
307
+ return NULL;
308
+ }
309
+
310
+
311
+ //////////////////// AsyncIter.proto ////////////////////
312
+
313
+ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *o); /*proto*/
314
+ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *o); /*proto*/
315
+
316
+ //////////////////// AsyncIter ////////////////////
317
+ //@requires: GetAwaitIter
318
+
319
+ static PyObject *__Pyx_Coroutine_GetAsyncIter_Fail(PyObject *obj) {
320
+ __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
321
+ PyErr_Format(PyExc_TypeError,
322
+ "'async for' requires an object with __aiter__ method, got " __Pyx_FMT_TYPENAME, obj_type_name);
323
+ __Pyx_DECREF_TypeName(obj_type_name);
324
+ return NULL;
325
+ }
326
+
327
+
328
+ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAsyncIter(PyObject *obj) {
329
+ #ifdef __Pyx_AsyncGen_USED
330
+ if (__Pyx_AsyncGen_CheckExact(obj)) {
331
+ return __Pyx_NewRef(obj);
332
+ }
333
+ #endif
334
+ {
335
+ unaryfunc am_aiter = __Pyx_PyObject_TryGetSubSlot(obj, tp_as_async, am_aiter, unaryfunc);
336
+ if (likely(am_aiter)) {
337
+ return (*am_aiter)(obj);
338
+ }
339
+ }
340
+ return __Pyx_Coroutine_GetAsyncIter_Fail(obj);
341
+ }
342
+
343
+
344
+ static PyObject *__Pyx_Coroutine_AsyncIterNext_Fail(PyObject *obj) {
345
+ __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
346
+ PyErr_Format(PyExc_TypeError,
347
+ "'async for' requires an object with __anext__ method, got " __Pyx_FMT_TYPENAME, obj_type_name);
348
+ __Pyx_DECREF_TypeName(obj_type_name);
349
+ return NULL;
350
+ }
351
+
352
+
353
+ static CYTHON_INLINE PyObject *__Pyx_Coroutine_AsyncIterNext(PyObject *obj) {
354
+ #ifdef __Pyx_AsyncGen_USED
355
+ if (__Pyx_AsyncGen_CheckExact(obj)) {
356
+ return __Pyx_async_gen_anext(obj);
357
+ }
358
+ #endif
359
+ {
360
+ unaryfunc am_anext = __Pyx_PyObject_TryGetSubSlot(obj, tp_as_async, am_anext, unaryfunc);
361
+ if (likely(am_anext)) {
362
+ return (*am_anext)(obj);
363
+ }
364
+ }
365
+ return __Pyx_Coroutine_AsyncIterNext_Fail(obj);
366
+ }
367
+
368
+
369
+ //////////////////// pep479.proto ////////////////////
370
+
371
+ static void __Pyx_Generator_Replace_StopIteration(int in_async_gen); /*proto*/
372
+
373
+ //////////////////// pep479 ////////////////////
374
+ //@requires: Exceptions.c::GetException
375
+
376
+ static void __Pyx_Generator_Replace_StopIteration(int in_async_gen) {
377
+ PyObject *exc, *val, *tb, *cur_exc, *new_exc;
378
+ __Pyx_PyThreadState_declare
379
+ int is_async_stopiteration = 0;
380
+ CYTHON_MAYBE_UNUSED_VAR(in_async_gen);
381
+
382
+ __Pyx_PyThreadState_assign
383
+ cur_exc = __Pyx_PyErr_CurrentExceptionType();
384
+ if (likely(!__Pyx_PyErr_GivenExceptionMatches(cur_exc, PyExc_StopIteration))) {
385
+ if (in_async_gen && unlikely(__Pyx_PyErr_GivenExceptionMatches(cur_exc, PyExc_StopAsyncIteration))) {
386
+ is_async_stopiteration = 1;
387
+ } else {
388
+ return;
389
+ }
390
+ }
391
+
392
+ // Explicitly chain the Stop(Async)Iteration by moving it to exc_info before creating the RuntimeError.
393
+ __Pyx_GetException(&exc, &val, &tb);
394
+ Py_XDECREF(exc);
395
+ Py_XDECREF(tb);
396
+ new_exc = PyObject_CallFunction(PyExc_RuntimeError, "s",
397
+ is_async_stopiteration ? "async generator raised StopAsyncIteration" :
398
+ in_async_gen ? "async generator raised StopIteration" :
399
+ "generator raised StopIteration");
400
+ if (!new_exc) {
401
+ Py_XDECREF(val);
402
+ return;
403
+ }
404
+ PyException_SetCause(new_exc, val); // steals ref to val
405
+ PyErr_SetObject(PyExc_RuntimeError, new_exc);
406
+ }
407
+
408
+
409
+ //////////////////// CoroutineBase.proto ////////////////////
410
+ //@substitute: naming
411
+
412
+ struct __pyx_CoroutineObject;
413
+ typedef PyObject *(*__pyx_coroutine_body_t)(struct __pyx_CoroutineObject *, PyThreadState *, PyObject *);
414
+
415
+ #if CYTHON_USE_EXC_INFO_STACK
416
+ // See https://bugs.python.org/issue25612
417
+ #define __Pyx_ExcInfoStruct _PyErr_StackItem
418
+ #else
419
+ // Minimal replacement struct for Py<3.7, without the Py3.7 exception state stack.
420
+ typedef struct {
421
+ PyObject *exc_type;
422
+ PyObject *exc_value;
423
+ PyObject *exc_traceback;
424
+ } __Pyx_ExcInfoStruct;
425
+ #endif
426
+
427
+ typedef struct __pyx_CoroutineObject {
428
+ PyObject_HEAD
429
+ __pyx_coroutine_body_t body;
430
+ PyObject *closure;
431
+ __Pyx_ExcInfoStruct gi_exc_state;
432
+ PyObject *gi_weakreflist;
433
+ PyObject *classobj;
434
+ PyObject *yieldfrom;
435
+ // "yieldfrom_am_send" is always included to avoid changing the struct layout.
436
+ __Pyx_pyiter_sendfunc yieldfrom_am_send;
437
+ PyObject *gi_name;
438
+ PyObject *gi_qualname;
439
+ PyObject *gi_modulename;
440
+ PyObject *gi_code;
441
+ PyObject *gi_frame;
442
+ #if CYTHON_USE_SYS_MONITORING && (CYTHON_PROFILE || CYTHON_TRACE)
443
+ PyMonitoringState $monitoring_states_cname[__Pyx_MonitoringEventTypes_CyGen_count];
444
+ uint64_t $monitoring_version_cname;
445
+ #endif
446
+ int resume_label;
447
+ // using T_BOOL for property below requires char value
448
+ char is_running;
449
+ } __pyx_CoroutineObject;
450
+
451
+ static __pyx_CoroutineObject *__Pyx__Coroutine_New(
452
+ PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
453
+ PyObject *name, PyObject *qualname, PyObject *module_name); /*proto*/
454
+
455
+ static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
456
+ __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
457
+ PyObject *name, PyObject *qualname, PyObject *module_name); /*proto*/
458
+
459
+ static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *self);
460
+ static int __Pyx_Coroutine_clear(PyObject *self); /*proto*/
461
+ static __Pyx_PySendResult __Pyx_Coroutine_AmSend(PyObject *self, PyObject *value, PyObject **retval); /*proto*/
462
+ static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value); /*proto*/
463
+ static __Pyx_PySendResult __Pyx_Coroutine_Close(PyObject *self, PyObject **retval); /*proto*/
464
+ static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); /*proto*/
465
+
466
+ // macros for exception state swapping instead of inline functions to make use of the local thread state context
467
+ #if CYTHON_USE_EXC_INFO_STACK
468
+ #define __Pyx_Coroutine_SwapException(self)
469
+ #define __Pyx_Coroutine_ResetAndClearException(self) __Pyx_Coroutine_ExceptionClear(&(self)->gi_exc_state)
470
+ #else
471
+ #define __Pyx_Coroutine_SwapException(self) { \
472
+ __Pyx_ExceptionSwap(&(self)->gi_exc_state.exc_type, &(self)->gi_exc_state.exc_value, &(self)->gi_exc_state.exc_traceback); \
473
+ __Pyx_Coroutine_ResetFrameBackpointer(&(self)->gi_exc_state); \
474
+ }
475
+ #define __Pyx_Coroutine_ResetAndClearException(self) { \
476
+ __Pyx_ExceptionReset((self)->gi_exc_state.exc_type, (self)->gi_exc_state.exc_value, (self)->gi_exc_state.exc_traceback); \
477
+ (self)->gi_exc_state.exc_type = (self)->gi_exc_state.exc_value = (self)->gi_exc_state.exc_traceback = NULL; \
478
+ }
479
+ #endif
480
+
481
+ #if CYTHON_FAST_THREAD_STATE
482
+ #define __Pyx_PyGen_FetchStopIterationValue(pvalue) \
483
+ __Pyx_PyGen__FetchStopIterationValue($local_tstate_cname, pvalue)
484
+ #else
485
+ #define __Pyx_PyGen_FetchStopIterationValue(pvalue) \
486
+ __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue)
487
+ #endif
488
+ static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue); /*proto*/
489
+ static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state); /*proto*/
490
+
491
+
492
+ //////////////////// Coroutine.proto ////////////////////
493
+
494
+ #define __Pyx_Coroutine_USED
495
+ #define __Pyx_Coroutine_CheckExact(obj) __Pyx_IS_TYPE(obj, CGLOBAL(__pyx_CoroutineType))
496
+ // __Pyx_Coroutine_Check(obj): see override for IterableCoroutine below
497
+ #define __Pyx_Coroutine_Check(obj) __Pyx_Coroutine_CheckExact(obj)
498
+ #define __Pyx_CoroutineAwait_CheckExact(obj) __Pyx_IS_TYPE(obj, CGLOBAL(__pyx_CoroutineAwaitType))
499
+
500
+ #define __Pyx_Coroutine_New(body, code, closure, name, qualname, module_name) \
501
+ __Pyx__Coroutine_New(CGLOBAL(__pyx_CoroutineType), body, code, closure, name, qualname, module_name)
502
+
503
+ static int __pyx_Coroutine_init(PyObject *module); /*proto*/
504
+ static PyObject *__Pyx__Coroutine_await(PyObject *coroutine); /*proto*/
505
+
506
+ typedef struct {
507
+ PyObject_HEAD
508
+ PyObject *coroutine;
509
+ } __pyx_CoroutineAwaitObject;
510
+
511
+ static __Pyx_PySendResult __Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self); /*proto*/
512
+
513
+
514
+ //////////////////// Generator.proto ////////////////////
515
+
516
+ #define __Pyx_Generator_USED
517
+ #define __Pyx_Generator_CheckExact(obj) __Pyx_IS_TYPE(obj, CGLOBAL(__pyx_GeneratorType))
518
+
519
+ #define __Pyx_Generator_New(body, code, closure, name, qualname, module_name) \
520
+ __Pyx__Coroutine_New(CGLOBAL(__pyx_GeneratorType), body, code, closure, name, qualname, module_name)
521
+
522
+ static PyObject *__Pyx_Generator_Next(PyObject *self);
523
+ static int __pyx_Generator_init(PyObject *module); /*proto*/
524
+ static CYTHON_INLINE PyObject *__Pyx_Generator_GetInlinedResult(PyObject *self); /*proto*/
525
+
526
+
527
+ //////////////////// AsyncGen ////////////////////
528
+ //@requires: AsyncGen.c::AsyncGenerator
529
+ // -> empty, only delegates to separate file
530
+
531
+
532
+ //////////////////// CoroutineBase ////////////////////
533
+ //@substitute: naming
534
+ //@requires: ReturnWithStopIteration
535
+ //@requires: Exceptions.c::PyErrFetchRestore
536
+ //@requires: Exceptions.c::PyThreadStateGet
537
+ //@requires: Exceptions.c::SwapException
538
+ //@requires: Exceptions.c::RaiseException
539
+ //@requires: Exceptions.c::SaveResetException
540
+ //@requires: ObjectHandling.c::PyObjectCallMethod1
541
+ //@requires: ObjectHandling.c::PyObjectCallNoArg
542
+ //@requires: ObjectHandling.c::PyObjectCallOneArg
543
+ //@requires: ObjectHandling.c::PyObjectFastCall
544
+ //@requires: ObjectHandling.c::PyObjectGetAttrStr
545
+ //@requires: ObjectHandling.c::PyObjectGetAttrStrNoError
546
+ //@requires: ObjectHandling.c::IterNextPlain
547
+ //@requires: CommonStructures.c::FetchCommonType
548
+ //@requires: ModuleSetupCode.c::IncludeStructmemberH
549
+ //@requires: ExtensionTypes.c::CallTypeTraverse
550
+
551
+ #if !CYTHON_COMPILING_IN_LIMITED_API
552
+ #include <frameobject.h>
553
+ #if PY_VERSION_HEX >= 0x030b00a6 && !defined(PYPY_VERSION)
554
+ #ifndef Py_BUILD_CORE
555
+ #define Py_BUILD_CORE 1
556
+ #endif
557
+ #include "internal/pycore_frame.h"
558
+ #endif
559
+ #endif // CYTHON_COMPILING_IN_LIMITED_API
560
+
561
+ static CYTHON_INLINE void
562
+ __Pyx_Coroutine_Undelegate(__pyx_CoroutineObject *gen) {
563
+ #if CYTHON_USE_AM_SEND
564
+ gen->yieldfrom_am_send = NULL;
565
+ #endif
566
+ Py_CLEAR(gen->yieldfrom);
567
+ }
568
+
569
+ // If StopIteration exception is set, fetches its 'value'
570
+ // attribute if any, otherwise sets pvalue to None.
571
+ //
572
+ // Returns 0 if no exception or StopIteration is set.
573
+ // If any other exception is set, returns -1 and leaves
574
+ // pvalue unchanged.
575
+ static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *$local_tstate_cname, PyObject **pvalue) {
576
+ PyObject *et, *ev, *tb;
577
+ PyObject *value = NULL;
578
+ CYTHON_UNUSED_VAR($local_tstate_cname);
579
+
580
+ __Pyx_ErrFetch(&et, &ev, &tb);
581
+
582
+ if (!et) {
583
+ Py_XDECREF(tb);
584
+ Py_XDECREF(ev);
585
+ Py_INCREF(Py_None);
586
+ *pvalue = Py_None;
587
+ return 0;
588
+ }
589
+
590
+ // most common case: plain StopIteration without or with separate argument
591
+ if (likely(et == PyExc_StopIteration)) {
592
+ if (!ev) {
593
+ Py_INCREF(Py_None);
594
+ value = Py_None;
595
+ }
596
+ else if (likely(__Pyx_IS_TYPE(ev, (PyTypeObject*)PyExc_StopIteration))) {
597
+ #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL
598
+ value = PyObject_GetAttr(ev, PYIDENT("value"));
599
+ if (unlikely(!value)) goto limited_api_failure;
600
+ #else
601
+ value = ((PyStopIterationObject *)ev)->value;
602
+ Py_INCREF(value);
603
+ #endif
604
+ Py_DECREF(ev);
605
+ }
606
+ // PyErr_SetObject() and friends put the value directly into ev
607
+ else if (unlikely(PyTuple_Check(ev))) {
608
+ // if it's a tuple, it is interpreted as separate constructor arguments (surprise!)
609
+ Py_ssize_t tuple_size = __Pyx_PyTuple_GET_SIZE(ev);
610
+ #if !CYTHON_ASSUME_SAFE_SIZE
611
+ if (unlikely(tuple_size < 0)) {
612
+ Py_XDECREF(tb);
613
+ Py_DECREF(ev);
614
+ Py_DECREF(et);
615
+ return -1;
616
+ }
617
+ #endif
618
+ if (tuple_size >= 1) {
619
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
620
+ value = PyTuple_GET_ITEM(ev, 0);
621
+ Py_INCREF(value);
622
+ #elif CYTHON_ASSUME_SAFE_MACROS
623
+ value = PySequence_ITEM(ev, 0);
624
+ #else
625
+ value = PySequence_GetItem(ev, 0);
626
+ if (!value) goto limited_api_failure;
627
+ #endif
628
+ } else {
629
+ Py_INCREF(Py_None);
630
+ value = Py_None;
631
+ }
632
+ Py_DECREF(ev);
633
+ }
634
+ else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
635
+ // 'steal' reference to ev
636
+ value = ev;
637
+ }
638
+ if (likely(value)) {
639
+ Py_XDECREF(tb);
640
+ Py_DECREF(et);
641
+ *pvalue = value;
642
+ return 0;
643
+ }
644
+ } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
645
+ __Pyx_ErrRestore(et, ev, tb);
646
+ return -1;
647
+ }
648
+
649
+ // otherwise: normalise and check what that gives us
650
+ PyErr_NormalizeException(&et, &ev, &tb);
651
+ if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) {
652
+ // looks like normalisation failed - raise the new exception
653
+ __Pyx_ErrRestore(et, ev, tb);
654
+ return -1;
655
+ }
656
+ Py_XDECREF(tb);
657
+ Py_DECREF(et);
658
+ #if CYTHON_COMPILING_IN_LIMITED_API
659
+ value = PyObject_GetAttr(ev, PYIDENT("value"));
660
+ #else
661
+ value = ((PyStopIterationObject *)ev)->value;
662
+ Py_INCREF(value);
663
+ #endif
664
+ Py_DECREF(ev);
665
+ #if CYTHON_COMPILING_IN_LIMITED_API
666
+ if (unlikely(!value)) return -1;
667
+ #endif
668
+ *pvalue = value;
669
+ return 0;
670
+
671
+ #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_GRAAL || !CYTHON_ASSUME_SAFE_MACROS
672
+ limited_api_failure:
673
+ Py_XDECREF(et);
674
+ Py_XDECREF(tb);
675
+ Py_XDECREF(ev);
676
+ return -1;
677
+ #endif
678
+ }
679
+
680
+ static CYTHON_INLINE
681
+ __Pyx_PySendResult __Pyx_Coroutine_status_from_result(PyObject **retval) {
682
+ if (*retval) {
683
+ return PYGEN_NEXT;
684
+ } else if (likely(__Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, retval) == 0)) {
685
+ //assert (*retval == Py_None);
686
+ return PYGEN_RETURN;
687
+ } else {
688
+ return PYGEN_ERROR;
689
+ }
690
+ }
691
+
692
+ static CYTHON_INLINE
693
+ void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) {
694
+ #if PY_VERSION_HEX >= 0x030B00a4
695
+ Py_CLEAR(exc_state->exc_value);
696
+ #else
697
+ PyObject *t, *v, *tb;
698
+ t = exc_state->exc_type;
699
+ v = exc_state->exc_value;
700
+ tb = exc_state->exc_traceback;
701
+
702
+ exc_state->exc_type = NULL;
703
+ exc_state->exc_value = NULL;
704
+ exc_state->exc_traceback = NULL;
705
+
706
+ Py_XDECREF(t);
707
+ Py_XDECREF(v);
708
+ Py_XDECREF(tb);
709
+ #endif
710
+ }
711
+
712
+ #define __Pyx_Coroutine_AlreadyRunningError(gen) (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL)
713
+ static void __Pyx__Coroutine_AlreadyRunningError(__pyx_CoroutineObject *gen) {
714
+ const char *msg;
715
+ CYTHON_MAYBE_UNUSED_VAR(gen);
716
+ if ((0)) {
717
+ #ifdef __Pyx_Coroutine_USED
718
+ } else if (__Pyx_Coroutine_Check((PyObject*)gen)) {
719
+ msg = "coroutine already executing";
720
+ #endif
721
+ #ifdef __Pyx_AsyncGen_USED
722
+ } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) {
723
+ msg = "async generator already executing";
724
+ #endif
725
+ } else {
726
+ msg = "generator already executing";
727
+ }
728
+ PyErr_SetString(PyExc_ValueError, msg);
729
+ }
730
+
731
+ static void __Pyx_Coroutine_AlreadyTerminatedError(PyObject *gen, PyObject *value, int closing) {
732
+ CYTHON_MAYBE_UNUSED_VAR(gen);
733
+ CYTHON_MAYBE_UNUSED_VAR(closing);
734
+ #ifdef __Pyx_Coroutine_USED
735
+ if (!closing && __Pyx_Coroutine_Check(gen)) {
736
+ // `self` is an exhausted coroutine: raise an error,
737
+ // except when called from gen_close(), which should
738
+ // always be a silent method.
739
+ PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine");
740
+ } else
741
+ #endif
742
+ if (value) {
743
+ // `gen` is an exhausted generator:
744
+ // only set exception if called from send().
745
+ #ifdef __Pyx_AsyncGen_USED
746
+ if (__Pyx_AsyncGen_CheckExact(gen))
747
+ PyErr_SetNone(PyExc_StopAsyncIteration);
748
+ else
749
+ #endif
750
+ PyErr_SetNone(PyExc_StopIteration);
751
+ }
752
+ }
753
+
754
+ static
755
+ __Pyx_PySendResult __Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, PyObject **result, int closing) {
756
+ __Pyx_PyThreadState_declare
757
+ PyThreadState *tstate;
758
+ __Pyx_ExcInfoStruct *exc_state;
759
+ PyObject *retval;
760
+
761
+ assert(!self->is_running);
762
+
763
+ if (unlikely(self->resume_label == -1)) {
764
+ __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing);
765
+ return PYGEN_ERROR;
766
+ }
767
+
768
+ #if CYTHON_FAST_THREAD_STATE
769
+ __Pyx_PyThreadState_assign
770
+ tstate = $local_tstate_cname;
771
+ #else
772
+ tstate = __Pyx_PyThreadState_Current;
773
+ #endif
774
+
775
+ // Traceback/Frame rules pre-Py3.7:
776
+ // - on entry, save external exception state in self->gi_exc_state, restore it on exit
777
+ // - on exit, keep internally generated exceptions in self->gi_exc_state, clear everything else
778
+ // - on entry, set "f_back" pointer of internal exception traceback to (current) outer call frame
779
+ // - on exit, clear "f_back" of internal exception traceback
780
+ // - do not touch external frames and tracebacks
781
+
782
+ // Traceback/Frame rules for Py3.7+ (CYTHON_USE_EXC_INFO_STACK):
783
+ // - on entry, push internal exception state in self->gi_exc_state on the exception stack
784
+ // - on exit, keep internally generated exceptions in self->gi_exc_state, clear everything else
785
+ // - on entry, set "f_back" pointer of internal exception traceback to (current) outer call frame
786
+ // - on exit, clear "f_back" of internal exception traceback
787
+ // - do not touch external frames and tracebacks
788
+
789
+ // In the Limited API/PyPy
790
+ // - on entry, save external exception state in self->gi_exc_state, restore it on exit
791
+ // - on exit, keep internally generated exceptions in self->gi_exc_state, clear everything else
792
+ // - don't mess with f_back because we can't work out how to do that
793
+ // - do not touch external frames and tracebacks
794
+
795
+ exc_state = &self->gi_exc_state;
796
+ if (exc_state->exc_value) {
797
+ #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
798
+ // FIXME - it'd be nice to handle f_back
799
+ #else
800
+ // Generators always return to their most recent caller, not
801
+ // necessarily their creator.
802
+ PyObject *exc_tb;
803
+ #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON
804
+ // owned reference!
805
+ exc_tb = PyException_GetTraceback(exc_state->exc_value);
806
+ #elif PY_VERSION_HEX >= 0x030B00a4
807
+ exc_tb = ((PyBaseExceptionObject*) exc_state->exc_value)->traceback;
808
+ #else
809
+ exc_tb = exc_state->exc_traceback;
810
+ #endif
811
+ if (exc_tb) {
812
+ PyTracebackObject *tb = (PyTracebackObject *) exc_tb;
813
+ PyFrameObject *f = tb->tb_frame;
814
+
815
+ assert(f->f_back == NULL);
816
+ #if PY_VERSION_HEX >= 0x030B00A1
817
+ // PyThreadState_GetFrame returns NULL if there isn't a current frame
818
+ // which is a valid state so no need to check
819
+ f->f_back = PyThreadState_GetFrame(tstate);
820
+ #else
821
+ Py_XINCREF(tstate->frame);
822
+ f->f_back = tstate->frame;
823
+ #endif
824
+ #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON
825
+ Py_DECREF(exc_tb);
826
+ #endif
827
+ }
828
+ #endif
829
+ }
830
+
831
+ #if CYTHON_USE_EXC_INFO_STACK
832
+ // See https://bugs.python.org/issue25612
833
+ exc_state->previous_item = tstate->exc_info;
834
+ tstate->exc_info = exc_state;
835
+ #else
836
+ if (exc_state->exc_type) {
837
+ // We were in an except handler when we left,
838
+ // restore the exception state which was put aside.
839
+ __Pyx_ExceptionSwap(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
840
+ // self->exc_* now holds the exception state of the caller
841
+ } else {
842
+ // save away the exception state of the caller
843
+ __Pyx_Coroutine_ExceptionClear(exc_state);
844
+ __Pyx_ExceptionSave(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback);
845
+ }
846
+ #endif
847
+
848
+ self->is_running = 1;
849
+ retval = self->body(self, tstate, value);
850
+ self->is_running = 0;
851
+
852
+ #if CYTHON_USE_EXC_INFO_STACK
853
+ // See https://bugs.python.org/issue25612
854
+ exc_state = &self->gi_exc_state;
855
+ tstate->exc_info = exc_state->previous_item;
856
+ exc_state->previous_item = NULL;
857
+ // Cut off the exception frame chain so that we can reconnect it on re-entry above.
858
+ __Pyx_Coroutine_ResetFrameBackpointer(exc_state);
859
+ #endif
860
+
861
+ *result = retval;
862
+
863
+ if (self->resume_label == -1) {
864
+ // terminated => return or error?
865
+ return likely(retval) ? PYGEN_RETURN : PYGEN_ERROR;
866
+ }
867
+ return PYGEN_NEXT;
868
+ }
869
+
870
+ static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state) {
871
+ // Don't keep the reference to f_back any longer than necessary. It
872
+ // may keep a chain of frames alive or it could create a reference
873
+ // cycle.
874
+ #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API
875
+ // FIXME: what to do in PyPy?
876
+ CYTHON_UNUSED_VAR(exc_state);
877
+ #else
878
+ PyObject *exc_tb;
879
+
880
+ #if PY_VERSION_HEX >= 0x030B00a4
881
+ if (!exc_state->exc_value) return;
882
+ // owned reference!
883
+ exc_tb = PyException_GetTraceback(exc_state->exc_value);
884
+ #else
885
+ exc_tb = exc_state->exc_traceback;
886
+ #endif
887
+
888
+ if (likely(exc_tb)) {
889
+ PyTracebackObject *tb = (PyTracebackObject *) exc_tb;
890
+ PyFrameObject *f = tb->tb_frame;
891
+ Py_CLEAR(f->f_back);
892
+ #if PY_VERSION_HEX >= 0x030B00a4
893
+ Py_DECREF(exc_tb);
894
+ #endif
895
+ }
896
+ #endif
897
+ }
898
+
899
+ static CYTHON_INLINE
900
+ PyObject *__Pyx_Coroutine_MethodReturn(PyObject* gen, PyObject *retval) {
901
+ CYTHON_MAYBE_UNUSED_VAR(gen);
902
+ if (unlikely(!retval)) {
903
+ __Pyx_PyThreadState_declare
904
+ __Pyx_PyThreadState_assign
905
+ if (!__Pyx_PyErr_Occurred()) {
906
+ // method call must not terminate with NULL without setting an exception
907
+ PyObject *exc =
908
+ #ifdef __Pyx_AsyncGen_USED
909
+ __Pyx_AsyncGen_CheckExact(gen) ? PyExc_StopAsyncIteration :
910
+ #endif
911
+ PyExc_StopIteration;
912
+ __Pyx_PyErr_SetNone(exc);
913
+ }
914
+ }
915
+ return retval;
916
+ }
917
+
918
+ #define __Pyx_Coroutine_MethodReturnFromResult(gen, result, retval) \
919
+ ((result) == PYGEN_NEXT ? (retval) : __Pyx__Coroutine_MethodReturnFromResult(gen, result, retval))
920
+
921
+ static PyObject *
922
+ __Pyx__Coroutine_MethodReturnFromResult(PyObject* gen, __Pyx_PySendResult result, PyObject *retval) {
923
+ CYTHON_MAYBE_UNUSED_VAR(gen);
924
+ if (likely(result == PYGEN_RETURN)) {
925
+ // return values pass through StopIteration or StopAsyncIteration
926
+ int is_async = 0;
927
+ #ifdef __Pyx_AsyncGen_USED
928
+ is_async = __Pyx_AsyncGen_CheckExact(gen);
929
+ #endif
930
+ __Pyx_ReturnWithStopIteration(retval, is_async);
931
+ Py_XDECREF(retval);
932
+ }
933
+ return NULL;
934
+ }
935
+
936
+ #if CYTHON_COMPILING_IN_CPYTHON
937
+ static CYTHON_INLINE
938
+ PyObject *__Pyx_PyGen_Send(PyGenObject *gen, PyObject *arg) {
939
+ #if PY_VERSION_HEX <= 0x030A00A1
940
+ return _PyGen_Send(gen, arg);
941
+ #else
942
+ PyObject *result;
943
+ // PyIter_Send() asserts non-NULL arg
944
+ if (PyIter_Send((PyObject*)gen, arg ? arg : Py_None, &result) == PYGEN_RETURN) {
945
+ if (PyAsyncGen_CheckExact(gen)) {
946
+ assert(result == Py_None);
947
+ PyErr_SetNone(PyExc_StopAsyncIteration);
948
+ }
949
+ else if (result == Py_None) {
950
+ PyErr_SetNone(PyExc_StopIteration);
951
+ }
952
+ else {
953
+ #if PY_VERSION_HEX < 0x030d00A1
954
+ _PyGen_SetStopIterationValue(result);
955
+ #else
956
+ if (!PyTuple_Check(result) && !PyExceptionInstance_Check(result)) {
957
+ // delay instantiation if possible
958
+ PyErr_SetObject(PyExc_StopIteration, result);
959
+ } else {
960
+ PyObject *exc = __Pyx_PyObject_CallOneArg(PyExc_StopIteration, result);
961
+ if (likely(exc != NULL)) {
962
+ PyErr_SetObject(PyExc_StopIteration, exc);
963
+ Py_DECREF(exc);
964
+ }
965
+ }
966
+ #endif
967
+ }
968
+ Py_DECREF(result);
969
+ result = NULL;
970
+ }
971
+ return result;
972
+ #endif
973
+ }
974
+ #endif
975
+
976
+ static CYTHON_INLINE __Pyx_PySendResult
977
+ __Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen, PyObject** retval) {
978
+ __Pyx_PySendResult result;
979
+ PyObject *val = NULL;
980
+ __Pyx_Coroutine_Undelegate(gen);
981
+ __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val);
982
+ // val == NULL on failure => pass on exception
983
+ result = __Pyx_Coroutine_SendEx(gen, val, retval, 0);
984
+ Py_XDECREF(val);
985
+ return result;
986
+ }
987
+
988
+ #if CYTHON_USE_AM_SEND
989
+ static __Pyx_PySendResult
990
+ __Pyx_Coroutine_SendToDelegate(__pyx_CoroutineObject *gen, __Pyx_pyiter_sendfunc gen_am_send, PyObject *value, PyObject **retval) {
991
+ PyObject *ret = NULL;
992
+ __Pyx_PySendResult result;
993
+ // we assume that gen->yieldfrom cannot change as long as 'gen->is_running' is set => no safety INCREF()
994
+ gen->is_running = 1;
995
+ result = gen_am_send(gen->yieldfrom, value, &ret);
996
+ gen->is_running = 0;
997
+ if (result == PYGEN_NEXT) {
998
+ assert (ret != NULL);
999
+ *retval = ret;
1000
+ return PYGEN_NEXT;
1001
+ }
1002
+ //assert (result == PYGEN_ERROR ? ret == NULL : ret != NULL);
1003
+ assert (result != PYGEN_ERROR || ret == NULL);
1004
+ __Pyx_Coroutine_Undelegate(gen);
1005
+ return __Pyx_Coroutine_SendEx(gen, ret, retval, 0);
1006
+ }
1007
+ #endif
1008
+
1009
+ static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
1010
+ PyObject *retval = NULL;
1011
+ __Pyx_PySendResult result = __Pyx_Coroutine_AmSend(self, value, &retval);
1012
+ return __Pyx_Coroutine_MethodReturnFromResult(self, result, retval);
1013
+ }
1014
+
1015
+ static __Pyx_PySendResult
1016
+ __Pyx_Coroutine_AmSend(PyObject *self, PyObject *value, PyObject **retval) {
1017
+ __Pyx_PySendResult result;
1018
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
1019
+ if (unlikely(gen->is_running)) {
1020
+ *retval = __Pyx_Coroutine_AlreadyRunningError(gen);
1021
+ return PYGEN_ERROR;
1022
+ }
1023
+ #if CYTHON_USE_AM_SEND
1024
+ if (gen->yieldfrom_am_send) {
1025
+ result = __Pyx_Coroutine_SendToDelegate(gen, gen->yieldfrom_am_send, value, retval);
1026
+ } else
1027
+ #endif
1028
+ if (gen->yieldfrom) {
1029
+ PyObject *yf = gen->yieldfrom;
1030
+ PyObject *ret;
1031
+ gen->is_running = 1;
1032
+ #if !CYTHON_USE_AM_SEND
1033
+ // Py3.10 puts "am_send" into "gen->yieldfrom_am_send" instead of using these special cases.
1034
+ // See "__Pyx_Coroutine_Set_Owned_Yield_From()" above.
1035
+ #ifdef __Pyx_Generator_USED
1036
+ if (__Pyx_Generator_CheckExact(yf)) {
1037
+ ret = __Pyx_Coroutine_Send(yf, value);
1038
+ } else
1039
+ #endif
1040
+ #ifdef __Pyx_Coroutine_USED
1041
+ if (__Pyx_Coroutine_Check(yf)) {
1042
+ ret = __Pyx_Coroutine_Send(yf, value);
1043
+ } else
1044
+ #endif
1045
+ #ifdef __Pyx_AsyncGen_USED
1046
+ if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
1047
+ ret = __Pyx_async_gen_asend_send(yf, value);
1048
+ } else
1049
+ #endif
1050
+ #if CYTHON_COMPILING_IN_CPYTHON
1051
+ if (PyGen_CheckExact(yf)) {
1052
+ ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
1053
+ } else
1054
+ if (PyCoro_CheckExact(yf)) {
1055
+ ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
1056
+ } else
1057
+ #endif
1058
+ #endif
1059
+ {
1060
+ #if !CYTHON_COMPILING_IN_LIMITED_API || __PYX_LIMITED_VERSION_HEX >= 0x03080000
1061
+ // PyIter_Check() is needed here but broken in the Py3.7 Limited API.
1062
+ if (value == Py_None && PyIter_Check(yf))
1063
+ ret = __Pyx_PyIter_Next_Plain(yf);
1064
+ else
1065
+ #endif
1066
+ ret = __Pyx_PyObject_CallMethod1(yf, PYIDENT("send"), value);
1067
+ }
1068
+ gen->is_running = 0;
1069
+ if (likely(ret)) {
1070
+ *retval = ret;
1071
+ return PYGEN_NEXT;
1072
+ }
1073
+ result = __Pyx_Coroutine_FinishDelegation(gen, retval);
1074
+ } else {
1075
+ result = __Pyx_Coroutine_SendEx(gen, value, retval, 0);
1076
+ }
1077
+ return result;
1078
+ }
1079
+
1080
+ // This helper function is used by gen_close and gen_throw to
1081
+ // close a subiterator being delegated to by yield-from.
1082
+ static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
1083
+ __Pyx_PySendResult result;
1084
+ PyObject *retval = NULL;
1085
+
1086
+ #ifdef __Pyx_Generator_USED
1087
+ if (__Pyx_Generator_CheckExact(yf)) {
1088
+ result = __Pyx_Coroutine_Close(yf, &retval);
1089
+ } else
1090
+ #endif
1091
+ #ifdef __Pyx_Coroutine_USED
1092
+ if (__Pyx_Coroutine_Check(yf)) {
1093
+ result = __Pyx_Coroutine_Close(yf, &retval);
1094
+ } else
1095
+ if (__Pyx_CoroutineAwait_CheckExact(yf)) {
1096
+ result = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf);
1097
+ } else
1098
+ #endif
1099
+ #ifdef __Pyx_AsyncGen_USED
1100
+ if (__pyx_PyAsyncGenASend_CheckExact(yf)) {
1101
+ retval = __Pyx_async_gen_asend_close(yf, NULL);
1102
+ // cannot fail
1103
+ result = PYGEN_RETURN;
1104
+ } else
1105
+ if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) {
1106
+ retval = __Pyx_async_gen_athrow_close(yf, NULL);
1107
+ // cannot fail
1108
+ result = PYGEN_RETURN;
1109
+ } else
1110
+ #endif
1111
+ {
1112
+ PyObject *meth;
1113
+ result = PYGEN_RETURN;
1114
+ gen->is_running = 1;
1115
+ meth = __Pyx_PyObject_GetAttrStrNoError(yf, PYIDENT("close"));
1116
+ if (unlikely(!meth)) {
1117
+ if (unlikely(PyErr_Occurred())) {
1118
+ PyErr_WriteUnraisable(yf);
1119
+ }
1120
+ } else {
1121
+ retval = __Pyx_PyObject_CallNoArg(meth);
1122
+ Py_DECREF(meth);
1123
+ if (unlikely(!retval)) {
1124
+ result = PYGEN_ERROR;
1125
+ }
1126
+ }
1127
+ gen->is_running = 0;
1128
+ }
1129
+ Py_XDECREF(retval);
1130
+ return result == PYGEN_ERROR ? -1 : 0;
1131
+ }
1132
+
1133
+ static PyObject *__Pyx_Generator_Next(PyObject *self) {
1134
+ __Pyx_PySendResult result;
1135
+ PyObject *retval = NULL;
1136
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
1137
+ if (unlikely(gen->is_running)) {
1138
+ return __Pyx_Coroutine_AlreadyRunningError(gen);
1139
+ }
1140
+ #if CYTHON_USE_AM_SEND
1141
+ if (gen->yieldfrom_am_send) {
1142
+ result = __Pyx_Coroutine_SendToDelegate(gen, gen->yieldfrom_am_send, Py_None, &retval);
1143
+ } else
1144
+ #endif
1145
+ if (gen->yieldfrom) {
1146
+ PyObject *yf = gen->yieldfrom;
1147
+ PyObject *ret;
1148
+ // YieldFrom code ensures that yf is an iterator
1149
+ gen->is_running = 1;
1150
+ #ifdef __Pyx_Generator_USED
1151
+ if (__Pyx_Generator_CheckExact(yf)) {
1152
+ ret = __Pyx_Generator_Next(yf);
1153
+ } else
1154
+ #endif
1155
+ #ifdef __Pyx_Coroutine_USED
1156
+ // See https://github.com/cython/cython/issues/1999
1157
+ if (__Pyx_Coroutine_CheckExact(yf)) {
1158
+ ret = __Pyx_Coroutine_Send(yf, Py_None);
1159
+ } else
1160
+ #endif
1161
+ #if CYTHON_COMPILING_IN_CPYTHON && (PY_VERSION_HEX < 0x030A00A3 || !CYTHON_USE_AM_SEND)
1162
+ // _PyGen_Send() is not needed in 3.10+ due to "am_send"
1163
+ if (PyGen_CheckExact(yf)) {
1164
+ ret = __Pyx_PyGen_Send((PyGenObject*)yf, NULL);
1165
+ } else
1166
+ #endif
1167
+ ret = __Pyx_PyIter_Next_Plain(yf);
1168
+ gen->is_running = 0;
1169
+ if (likely(ret)) {
1170
+ return ret;
1171
+ }
1172
+ result = __Pyx_Coroutine_FinishDelegation(gen, &retval);
1173
+ } else {
1174
+ result = __Pyx_Coroutine_SendEx(gen, Py_None, &retval, 0);
1175
+ }
1176
+
1177
+ return __Pyx_Coroutine_MethodReturnFromResult(self, result, retval);
1178
+ }
1179
+
1180
+ static PyObject *__Pyx_Coroutine_Close_Method(PyObject *self, PyObject *arg) {
1181
+ PyObject *retval = NULL;
1182
+ __Pyx_PySendResult result;
1183
+ CYTHON_UNUSED_VAR(arg);
1184
+ result = __Pyx_Coroutine_Close(self, &retval);
1185
+ if (unlikely(result == PYGEN_ERROR))
1186
+ return NULL;
1187
+ Py_XDECREF(retval);
1188
+ Py_RETURN_NONE;
1189
+ }
1190
+
1191
+ static __Pyx_PySendResult
1192
+ __Pyx_Coroutine_Close(PyObject *self, PyObject **retval) {
1193
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
1194
+ __Pyx_PySendResult result;
1195
+ PyObject *yf = gen->yieldfrom;
1196
+ int err = 0;
1197
+
1198
+ if (unlikely(gen->is_running)) {
1199
+ *retval = __Pyx_Coroutine_AlreadyRunningError(gen);
1200
+ return PYGEN_ERROR;
1201
+ }
1202
+
1203
+ if (yf) {
1204
+ Py_INCREF(yf);
1205
+ err = __Pyx_Coroutine_CloseIter(gen, yf);
1206
+ __Pyx_Coroutine_Undelegate(gen);
1207
+ Py_DECREF(yf);
1208
+ }
1209
+ if (err == 0)
1210
+ PyErr_SetNone(PyExc_GeneratorExit);
1211
+ result = __Pyx_Coroutine_SendEx(gen, NULL, retval, 1);
1212
+ if (result == PYGEN_ERROR) {
1213
+ // WARNING: *retval == NULL !
1214
+ __Pyx_PyThreadState_declare
1215
+ __Pyx_PyThreadState_assign
1216
+ if (!__Pyx_PyErr_Occurred()) {
1217
+ return PYGEN_RETURN;
1218
+ } else if (likely(__Pyx_PyErr_ExceptionMatches2(PyExc_GeneratorExit, PyExc_StopIteration))) {
1219
+ __Pyx_PyErr_Clear();
1220
+ return PYGEN_RETURN;
1221
+ }
1222
+ return PYGEN_ERROR;
1223
+ } else if (likely(result == PYGEN_RETURN && *retval == Py_None)) {
1224
+ return PYGEN_RETURN;
1225
+ } else {
1226
+ const char *msg;
1227
+ Py_DECREF(*retval);
1228
+ *retval = NULL;
1229
+ if ((0)) {
1230
+ #ifdef __Pyx_Coroutine_USED
1231
+ } else if (__Pyx_Coroutine_Check(self)) {
1232
+ msg = "coroutine ignored GeneratorExit";
1233
+ #endif
1234
+ #ifdef __Pyx_AsyncGen_USED
1235
+ } else if (__Pyx_AsyncGen_CheckExact(self)) {
1236
+ msg = "async generator ignored GeneratorExit";
1237
+ #endif
1238
+ } else {
1239
+ msg = "generator ignored GeneratorExit";
1240
+ }
1241
+ PyErr_SetString(PyExc_RuntimeError, msg);
1242
+ return PYGEN_ERROR;
1243
+ }
1244
+ }
1245
+
1246
+ static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb,
1247
+ PyObject *args, int close_on_genexit) {
1248
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
1249
+ PyObject *yf = gen->yieldfrom;
1250
+
1251
+ if (unlikely(gen->is_running))
1252
+ return __Pyx_Coroutine_AlreadyRunningError(gen);
1253
+
1254
+ if (yf) {
1255
+ __Pyx_PySendResult result;
1256
+ PyObject *ret;
1257
+ Py_INCREF(yf);
1258
+ if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) {
1259
+ // Asynchronous generators *should not* be closed right away.
1260
+ // We have to allow some awaits to work it through, hence the
1261
+ // `close_on_genexit` parameter here.
1262
+ int err = __Pyx_Coroutine_CloseIter(gen, yf);
1263
+ Py_DECREF(yf);
1264
+ __Pyx_Coroutine_Undelegate(gen);
1265
+ if (err < 0)
1266
+ goto propagate_exception;
1267
+ goto throw_here;
1268
+ }
1269
+ gen->is_running = 1;
1270
+ if (0
1271
+ #ifdef __Pyx_Generator_USED
1272
+ || __Pyx_Generator_CheckExact(yf)
1273
+ #endif
1274
+ #ifdef __Pyx_Coroutine_USED
1275
+ || __Pyx_Coroutine_Check(yf)
1276
+ #endif
1277
+ ) {
1278
+ ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit);
1279
+ #ifdef __Pyx_Coroutine_USED
1280
+ } else if (__Pyx_CoroutineAwait_CheckExact(yf)) {
1281
+ ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit);
1282
+ #endif
1283
+ } else {
1284
+ PyObject *meth = __Pyx_PyObject_GetAttrStrNoError(yf, PYIDENT("throw"));
1285
+ if (unlikely(!meth)) {
1286
+ Py_DECREF(yf);
1287
+ if (unlikely(PyErr_Occurred())) {
1288
+ gen->is_running = 0;
1289
+ return NULL;
1290
+ }
1291
+ __Pyx_Coroutine_Undelegate(gen);
1292
+ gen->is_running = 0;
1293
+ goto throw_here;
1294
+ }
1295
+ if (likely(args)) {
1296
+ ret = __Pyx_PyObject_Call(meth, args, NULL);
1297
+ } else {
1298
+ // "tb" or even "val" might be NULL, but that also correctly terminates the argument list
1299
+ PyObject *cargs[4] = {NULL, typ, val, tb};
1300
+ ret = __Pyx_PyObject_FastCall(meth, cargs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
1301
+ }
1302
+ Py_DECREF(meth);
1303
+ }
1304
+ gen->is_running = 0;
1305
+ Py_DECREF(yf);
1306
+ if (ret)
1307
+ return ret;
1308
+
1309
+ result = __Pyx_Coroutine_FinishDelegation(gen, &ret);
1310
+ return __Pyx_Coroutine_MethodReturnFromResult(self, result, ret);
1311
+ }
1312
+ throw_here:
1313
+ __Pyx_Raise(typ, val, tb, NULL);
1314
+
1315
+ propagate_exception:
1316
+ {
1317
+ PyObject *retval = NULL;
1318
+ __Pyx_PySendResult result = __Pyx_Coroutine_SendEx(gen, NULL, &retval, 0);
1319
+ return __Pyx_Coroutine_MethodReturnFromResult(self, result, retval);
1320
+ }
1321
+ }
1322
+
1323
+ static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
1324
+ PyObject *typ;
1325
+ PyObject *val = NULL;
1326
+ PyObject *tb = NULL;
1327
+
1328
+ if (unlikely(!PyArg_UnpackTuple(args, "throw", 1, 3, &typ, &val, &tb)))
1329
+ return NULL;
1330
+
1331
+ return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1);
1332
+ }
1333
+
1334
+ static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) {
1335
+ #if PY_VERSION_HEX >= 0x030B00a4
1336
+ Py_VISIT(exc_state->exc_value);
1337
+ #else
1338
+ Py_VISIT(exc_state->exc_type);
1339
+ Py_VISIT(exc_state->exc_value);
1340
+ Py_VISIT(exc_state->exc_traceback);
1341
+ #endif
1342
+ return 0;
1343
+ }
1344
+
1345
+ static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) {
1346
+ {
1347
+ int e = __Pyx_call_type_traverse((PyObject*)gen, 1, visit, arg);
1348
+ if (e) return e;
1349
+ }
1350
+ Py_VISIT(gen->closure);
1351
+ Py_VISIT(gen->classobj);
1352
+ Py_VISIT(gen->yieldfrom);
1353
+ return __Pyx_Coroutine_traverse_excstate(&gen->gi_exc_state, visit, arg);
1354
+ }
1355
+
1356
+ static int __Pyx_Coroutine_clear(PyObject *self) {
1357
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
1358
+
1359
+ Py_CLEAR(gen->closure);
1360
+ Py_CLEAR(gen->classobj);
1361
+ __Pyx_Coroutine_Undelegate(gen);
1362
+ __Pyx_Coroutine_ExceptionClear(&gen->gi_exc_state);
1363
+ #ifdef __Pyx_AsyncGen_USED
1364
+ if (__Pyx_AsyncGen_CheckExact(self)) {
1365
+ Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer);
1366
+ }
1367
+ #endif
1368
+ Py_CLEAR(gen->gi_code);
1369
+ Py_CLEAR(gen->gi_frame);
1370
+ Py_CLEAR(gen->gi_name);
1371
+ Py_CLEAR(gen->gi_qualname);
1372
+ Py_CLEAR(gen->gi_modulename);
1373
+ return 0;
1374
+ }
1375
+
1376
+ static void __Pyx_Coroutine_dealloc(PyObject *self) {
1377
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
1378
+
1379
+ PyObject_GC_UnTrack(gen);
1380
+ if (gen->gi_weakreflist != NULL)
1381
+ PyObject_ClearWeakRefs(self);
1382
+
1383
+ if (gen->resume_label >= 0) {
1384
+ // Generator is paused or unstarted, so we need to close
1385
+ PyObject_GC_Track(self);
1386
+ #if CYTHON_USE_TP_FINALIZE
1387
+ if (unlikely(PyObject_CallFinalizerFromDealloc(self)))
1388
+ #else
1389
+ {
1390
+ destructor del = __Pyx_PyObject_GetSlot(gen, tp_del, destructor);
1391
+ if (del) del(self);
1392
+ }
1393
+ if (unlikely(Py_REFCNT(self) > 0))
1394
+ #endif
1395
+ {
1396
+ // resurrected. :(
1397
+ return;
1398
+ }
1399
+ PyObject_GC_UnTrack(self);
1400
+ }
1401
+
1402
+ #ifdef __Pyx_AsyncGen_USED
1403
+ if (__Pyx_AsyncGen_CheckExact(self)) {
1404
+ /* We have to handle this case for asynchronous generators
1405
+ right here, because this code has to be between UNTRACK
1406
+ and GC_Del. */
1407
+ Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer);
1408
+ }
1409
+ #endif
1410
+ __Pyx_Coroutine_clear(self);
1411
+ __Pyx_PyHeapTypeObject_GC_Del(gen);
1412
+ }
1413
+
1414
+ #if !(CYTHON_USE_TYPE_SPECS && !CYTHON_USE_TP_FINALIZE)
1415
+ static void __Pyx_Coroutine_del(PyObject *self) {
1416
+ PyObject *error_type, *error_value, *error_traceback;
1417
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
1418
+ __Pyx_PyThreadState_declare
1419
+
1420
+ if (gen->resume_label < 0) {
1421
+ // already terminated => nothing to clean up
1422
+ return;
1423
+ }
1424
+
1425
+ #if !CYTHON_USE_TP_FINALIZE
1426
+ // Temporarily resurrect the object.
1427
+ assert(self->ob_refcnt == 0);
1428
+ __Pyx_SET_REFCNT(self, 1);
1429
+ #endif
1430
+
1431
+ __Pyx_PyThreadState_assign
1432
+
1433
+ // Save the current exception, if any.
1434
+ __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
1435
+
1436
+ #ifdef __Pyx_AsyncGen_USED
1437
+ if (__Pyx_AsyncGen_CheckExact(self)) {
1438
+ __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self;
1439
+ PyObject *finalizer = agen->ag_finalizer;
1440
+ if (finalizer && !agen->ag_closed) {
1441
+ PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self);
1442
+ if (unlikely(!res)) {
1443
+ PyErr_WriteUnraisable(self);
1444
+ } else {
1445
+ Py_DECREF(res);
1446
+ }
1447
+ // Restore the saved exception.
1448
+ __Pyx_ErrRestore(error_type, error_value, error_traceback);
1449
+ return;
1450
+ }
1451
+ }
1452
+ #endif
1453
+
1454
+ if (unlikely(gen->resume_label == 0 && !error_value)) {
1455
+ #ifdef __Pyx_Coroutine_USED
1456
+ #ifdef __Pyx_Generator_USED
1457
+ // only warn about (async) coroutines
1458
+ if (!__Pyx_Generator_CheckExact(self))
1459
+ #endif
1460
+ {
1461
+ // untrack dead object as we are executing Python code (which might trigger GC)
1462
+ PyObject_GC_UnTrack(self);
1463
+ if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0))
1464
+ PyErr_WriteUnraisable(self);
1465
+ PyObject_GC_Track(self);
1466
+ }
1467
+ #endif /*__Pyx_Coroutine_USED*/
1468
+ } else {
1469
+ PyObject *retval = NULL;
1470
+ __Pyx_PySendResult result = __Pyx_Coroutine_Close(self, &retval);
1471
+ if (result == PYGEN_ERROR) {
1472
+ PyErr_WriteUnraisable(self);
1473
+ } else {
1474
+ Py_XDECREF(retval);
1475
+ }
1476
+ }
1477
+
1478
+ // Restore the saved exception.
1479
+ __Pyx_ErrRestore(error_type, error_value, error_traceback);
1480
+
1481
+ #if !CYTHON_USE_TP_FINALIZE
1482
+ // Undo the temporary resurrection; can't use DECREF here, it would
1483
+ // cause a recursive call.
1484
+ assert(Py_REFCNT(self) > 0);
1485
+ if (likely(--self->ob_refcnt == 0)) {
1486
+ // this is the normal path out
1487
+ return;
1488
+ }
1489
+
1490
+ // close() resurrected it! Make it look like the original Py_DECREF
1491
+ // never happened.
1492
+ {
1493
+ #if !CYTHON_COMPILING_IN_LIMITED_API
1494
+ Py_ssize_t refcnt = Py_REFCNT(self);
1495
+ _Py_NewReference(self);
1496
+ __Pyx_SET_REFCNT(self, refcnt);
1497
+ #else
1498
+ #error __Pyx_Coroutine_del with Limited API and without CYTHON_USE_TP_FINALIZE should never be compiled
1499
+ #endif
1500
+ }
1501
+ #if CYTHON_COMPILING_IN_CPYTHON
1502
+ assert(PyType_IS_GC(Py_TYPE(self)) &&
1503
+ _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
1504
+
1505
+ // If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
1506
+ // we need to undo that.
1507
+ _Py_DEC_REFTOTAL;
1508
+ #endif
1509
+ // If Py_TRACE_REFS, _Py_NewReference re-added self to the object
1510
+ // chain, so no more to do there.
1511
+ // If COUNT_ALLOCS, the original decref bumped tp_frees, and
1512
+ // _Py_NewReference bumped tp_allocs: both of those need to be
1513
+ // undone.
1514
+ #ifdef COUNT_ALLOCS
1515
+ --Py_TYPE(self)->tp_frees;
1516
+ --Py_TYPE(self)->tp_allocs;
1517
+ #endif
1518
+ #endif
1519
+ }
1520
+ #endif
1521
+
1522
+ static PyObject *
1523
+ __Pyx_Coroutine_get_name(__pyx_CoroutineObject *self, void *context)
1524
+ {
1525
+ PyObject *name = self->gi_name;
1526
+ CYTHON_UNUSED_VAR(context);
1527
+ // avoid NULL pointer dereference during garbage collection
1528
+ if (unlikely(!name)) name = Py_None;
1529
+ Py_INCREF(name);
1530
+ return name;
1531
+ }
1532
+
1533
+ static int
1534
+ __Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value, void *context)
1535
+ {
1536
+ CYTHON_UNUSED_VAR(context);
1537
+ if (unlikely(value == NULL || !PyUnicode_Check(value))) {
1538
+ PyErr_SetString(PyExc_TypeError,
1539
+ "__name__ must be set to a string object");
1540
+ return -1;
1541
+ }
1542
+ Py_INCREF(value);
1543
+ __Pyx_Py_XDECREF_SET(self->gi_name, value);
1544
+ return 0;
1545
+ }
1546
+
1547
+ static PyObject *
1548
+ __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self, void *context)
1549
+ {
1550
+ PyObject *name = self->gi_qualname;
1551
+ CYTHON_UNUSED_VAR(context);
1552
+ // avoid NULL pointer dereference during garbage collection
1553
+ if (unlikely(!name)) name = Py_None;
1554
+ Py_INCREF(name);
1555
+ return name;
1556
+ }
1557
+
1558
+ static int
1559
+ __Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value, void *context)
1560
+ {
1561
+ CYTHON_UNUSED_VAR(context);
1562
+ if (unlikely(value == NULL || !PyUnicode_Check(value))) {
1563
+ PyErr_SetString(PyExc_TypeError,
1564
+ "__qualname__ must be set to a string object");
1565
+ return -1;
1566
+ }
1567
+ Py_INCREF(value);
1568
+ __Pyx_Py_XDECREF_SET(self->gi_qualname, value);
1569
+ return 0;
1570
+ }
1571
+
1572
+ static PyObject *
1573
+ __Pyx_Coroutine_get_frame(__pyx_CoroutineObject *self, void *context)
1574
+ {
1575
+ #if !CYTHON_COMPILING_IN_LIMITED_API
1576
+ PyObject *frame = self->gi_frame;
1577
+ CYTHON_UNUSED_VAR(context);
1578
+ if (!frame) {
1579
+ if (unlikely(!self->gi_code)) {
1580
+ // Avoid doing something stupid, e.g. during garbage collection.
1581
+ Py_RETURN_NONE;
1582
+ }
1583
+ frame = (PyObject *) PyFrame_New(
1584
+ PyThreadState_Get(), /*PyThreadState *tstate,*/
1585
+ (PyCodeObject*) self->gi_code, /*PyCodeObject *code,*/
1586
+ NAMED_CGLOBAL(moddict_cname), /*PyObject *globals,*/
1587
+ 0 /*PyObject *locals*/
1588
+ );
1589
+ if (unlikely(!frame))
1590
+ return NULL;
1591
+ // keep the frame cached once it's created
1592
+ self->gi_frame = frame;
1593
+ }
1594
+ Py_INCREF(frame);
1595
+ return frame;
1596
+ #else
1597
+ // In the limited API there probably isn't much we can usefully do to get a frame
1598
+ CYTHON_UNUSED_VAR(self);
1599
+ CYTHON_UNUSED_VAR(context);
1600
+ Py_RETURN_NONE;
1601
+ #endif
1602
+ }
1603
+
1604
+ static __pyx_CoroutineObject *__Pyx__Coroutine_New(
1605
+ PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
1606
+ PyObject *name, PyObject *qualname, PyObject *module_name) {
1607
+ __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
1608
+ if (unlikely(!gen))
1609
+ return NULL;
1610
+ return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name);
1611
+ }
1612
+
1613
+ static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit(
1614
+ __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure,
1615
+ PyObject *name, PyObject *qualname, PyObject *module_name) {
1616
+ gen->body = body;
1617
+ gen->closure = closure;
1618
+ Py_XINCREF(closure);
1619
+ gen->is_running = 0;
1620
+ gen->resume_label = 0;
1621
+ gen->classobj = NULL;
1622
+ gen->yieldfrom = NULL;
1623
+ gen->yieldfrom_am_send = NULL;
1624
+ #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_LIMITED_API
1625
+ gen->gi_exc_state.exc_value = NULL;
1626
+ #else
1627
+ gen->gi_exc_state.exc_type = NULL;
1628
+ gen->gi_exc_state.exc_value = NULL;
1629
+ gen->gi_exc_state.exc_traceback = NULL;
1630
+ #endif
1631
+ #if CYTHON_USE_EXC_INFO_STACK
1632
+ gen->gi_exc_state.previous_item = NULL;
1633
+ #endif
1634
+ gen->gi_weakreflist = NULL;
1635
+ Py_XINCREF(qualname);
1636
+ gen->gi_qualname = qualname;
1637
+ Py_XINCREF(name);
1638
+ gen->gi_name = name;
1639
+ Py_XINCREF(module_name);
1640
+ gen->gi_modulename = module_name;
1641
+ Py_XINCREF(code);
1642
+ gen->gi_code = code;
1643
+ gen->gi_frame = NULL;
1644
+
1645
+ PyObject_GC_Track(gen);
1646
+ return gen;
1647
+ }
1648
+
1649
+
1650
+ //////////////////// Coroutine ////////////////////
1651
+ //@requires: CoroutineBase
1652
+ //@requires: ExtensionTypes.c::CallTypeTraverse
1653
+ //@substitute: naming
1654
+
1655
+ static void __Pyx_CoroutineAwait_dealloc(PyObject *self) {
1656
+ PyObject_GC_UnTrack(self);
1657
+ Py_CLEAR(((__pyx_CoroutineAwaitObject*)self)->coroutine);
1658
+ __Pyx_PyHeapTypeObject_GC_Del(self);
1659
+ }
1660
+
1661
+ static int __Pyx_CoroutineAwait_traverse(__pyx_CoroutineAwaitObject *self, visitproc visit, void *arg) {
1662
+ {
1663
+ int e = __Pyx_call_type_traverse((PyObject*)self, 1, visit, arg);
1664
+ if (e) return e;
1665
+ }
1666
+ Py_VISIT(self->coroutine);
1667
+ return 0;
1668
+ }
1669
+
1670
+ static int __Pyx_CoroutineAwait_clear(__pyx_CoroutineAwaitObject *self) {
1671
+ Py_CLEAR(self->coroutine);
1672
+ return 0;
1673
+ }
1674
+
1675
+ static PyObject *__Pyx_CoroutineAwait_Next(__pyx_CoroutineAwaitObject *self) {
1676
+ return __Pyx_Generator_Next(self->coroutine);
1677
+ }
1678
+
1679
+ static PyObject *__Pyx_CoroutineAwait_Send(__pyx_CoroutineAwaitObject *self, PyObject *value) {
1680
+ return __Pyx_Coroutine_Send(self->coroutine, value);
1681
+ }
1682
+
1683
+ #if __PYX_HAS_PY_AM_SEND || !CYTHON_USE_TYPE_SPECS
1684
+ static __Pyx_PySendResult __Pyx_CoroutineAwait_AmSend(PyObject *self, PyObject *value, PyObject **retval) {
1685
+ return __Pyx_Coroutine_AmSend(((__pyx_CoroutineAwaitObject*)self)->coroutine, value, retval);
1686
+ }
1687
+ #endif
1688
+
1689
+ static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args) {
1690
+ return __Pyx_Coroutine_Throw(self->coroutine, args);
1691
+ }
1692
+
1693
+ static __Pyx_PySendResult __Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self) {
1694
+ PyObject *retval = NULL;
1695
+ __Pyx_PySendResult result = __Pyx_Coroutine_Close(self->coroutine, &retval);
1696
+ Py_XDECREF(retval);
1697
+ return result;
1698
+ }
1699
+
1700
+ static PyObject *__Pyx_CoroutineAwait_Close_Method(__pyx_CoroutineAwaitObject *self, PyObject *arg) {
1701
+ PyObject *retval = NULL;
1702
+ __Pyx_PySendResult result;
1703
+ CYTHON_UNUSED_VAR(arg);
1704
+ result = __Pyx_Coroutine_Close(self->coroutine, &retval);
1705
+ if (unlikely(result == PYGEN_ERROR))
1706
+ return NULL;
1707
+ Py_XDECREF(retval);
1708
+ Py_RETURN_NONE;
1709
+ }
1710
+
1711
+ static PyObject *__Pyx_CoroutineAwait_self(PyObject *self) {
1712
+ Py_INCREF(self);
1713
+ return self;
1714
+ }
1715
+
1716
+ #if !CYTHON_COMPILING_IN_PYPY
1717
+ static PyObject *__Pyx_CoroutineAwait_no_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {
1718
+ CYTHON_UNUSED_VAR(type);
1719
+ CYTHON_UNUSED_VAR(args);
1720
+ CYTHON_UNUSED_VAR(kwargs);
1721
+ PyErr_SetString(PyExc_TypeError, "cannot instantiate type, use 'await coroutine' instead");
1722
+ return NULL;
1723
+ }
1724
+ #endif
1725
+
1726
+ // In earlier versions of Python an object with no __dict__ and not __slots__ is assumed
1727
+ // to be pickleable by default. Coroutine-wrappers have significant state so shouldn't be.
1728
+ // Therefore provide a default implementation.
1729
+ // Something similar applies to heaptypes (i.e. with type_specs) with protocols 0 and 1
1730
+ // even in more recent versions.
1731
+ // We are applying this to all Python versions (hence the commented out version guard)
1732
+ // to make the behaviour explicit.
1733
+ // #if CYTHON_USE_TYPE_SPECS
1734
+ static PyObject *__Pyx_CoroutineAwait_reduce_ex(__pyx_CoroutineAwaitObject *self, PyObject *arg) {
1735
+ CYTHON_UNUSED_VAR(arg);
1736
+ PyErr_Format(PyExc_TypeError, "cannot pickle '%.200s' object",
1737
+ Py_TYPE(self)->tp_name);
1738
+ return NULL;
1739
+ }
1740
+ // #endif
1741
+
1742
+ static PyMethodDef __pyx_CoroutineAwait_methods[] = {
1743
+ {"send", (PyCFunction) __Pyx_CoroutineAwait_Send, METH_O,
1744
+ PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next yielded value or raise StopIteration.")},
1745
+ {"throw", (PyCFunction) __Pyx_CoroutineAwait_Throw, METH_VARARGS,
1746
+ PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next yielded value or raise StopIteration.")},
1747
+ {"close", (PyCFunction) __Pyx_CoroutineAwait_Close_Method, METH_NOARGS, PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")},
1748
+ // only needed with type-specs, but included in all versions for clarity
1749
+ // #if CYTHON_USE_TYPE_SPECS
1750
+ {"__reduce_ex__", (PyCFunction) __Pyx_CoroutineAwait_reduce_ex, METH_O, 0},
1751
+ {"__reduce__", (PyCFunction) __Pyx_CoroutineAwait_reduce_ex, METH_NOARGS, 0},
1752
+ // #endif
1753
+ {0, 0, 0, 0}
1754
+ };
1755
+
1756
+ #if CYTHON_USE_TYPE_SPECS
1757
+ static PyType_Slot __pyx_CoroutineAwaitType_slots[] = {
1758
+ {Py_tp_dealloc, (void *)__Pyx_CoroutineAwait_dealloc},
1759
+ {Py_tp_traverse, (void *)__Pyx_CoroutineAwait_traverse},
1760
+ {Py_tp_clear, (void *)__Pyx_CoroutineAwait_clear},
1761
+ #if !CYTHON_COMPILING_IN_PYPY
1762
+ {Py_tp_new, (void *)__Pyx_CoroutineAwait_no_new},
1763
+ #endif
1764
+ {Py_tp_methods, (void *)__pyx_CoroutineAwait_methods},
1765
+ {Py_tp_iter, (void *)__Pyx_CoroutineAwait_self},
1766
+ {Py_tp_iternext, (void *)__Pyx_CoroutineAwait_Next},
1767
+ #if __PYX_HAS_PY_AM_SEND
1768
+ {Py_am_send, (void *)__Pyx_CoroutineAwait_AmSend},
1769
+ #endif
1770
+ {0, 0},
1771
+ };
1772
+
1773
+ static PyType_Spec __pyx_CoroutineAwaitType_spec = {
1774
+ __PYX_TYPE_MODULE_PREFIX "coroutine_wrapper",
1775
+ sizeof(__pyx_CoroutineAwaitObject),
1776
+ 0,
1777
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1778
+ __pyx_CoroutineAwaitType_slots
1779
+ };
1780
+ #else /* CYTHON_USE_TYPE_SPECS */
1781
+ static __Pyx_PyAsyncMethodsStruct __pyx_CoroutineAwait_as_async = {
1782
+ 0, /*am_await*/
1783
+ 0, /*am_aiter*/
1784
+ 0, /*am_anext*/
1785
+ __Pyx_CoroutineAwait_AmSend, /*am_send*/
1786
+ };
1787
+
1788
+ static PyTypeObject __pyx_CoroutineAwaitType_type = {
1789
+ PyVarObject_HEAD_INIT(0, 0)
1790
+ __PYX_TYPE_MODULE_PREFIX "coroutine_wrapper", /*tp_name*/
1791
+ sizeof(__pyx_CoroutineAwaitObject), /*tp_basicsize*/
1792
+ 0, /*tp_itemsize*/
1793
+ (destructor) __Pyx_CoroutineAwait_dealloc,/*tp_dealloc*/
1794
+ 0, /*tp_print*/
1795
+ 0, /*tp_getattr*/
1796
+ 0, /*tp_setattr*/
1797
+ __Pyx_SlotTpAsAsync(__pyx_CoroutineAwait_as_async), /*tp_as_async*/
1798
+ 0, /*tp_repr*/
1799
+ 0, /*tp_as_number*/
1800
+ 0, /*tp_as_sequence*/
1801
+ 0, /*tp_as_mapping*/
1802
+ 0, /*tp_hash*/
1803
+ 0, /*tp_call*/
1804
+ 0, /*tp_str*/
1805
+ 0, /*tp_getattro*/
1806
+ 0, /*tp_setattro*/
1807
+ 0, /*tp_as_buffer*/
1808
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | __Pyx_TPFLAGS_HAVE_AM_SEND, /*tp_flags*/
1809
+ PyDoc_STR("A wrapper object implementing __await__ for coroutines."), /*tp_doc*/
1810
+ (traverseproc) __Pyx_CoroutineAwait_traverse, /*tp_traverse*/
1811
+ (inquiry) __Pyx_CoroutineAwait_clear, /*tp_clear*/
1812
+ 0, /*tp_richcompare*/
1813
+ 0, /*tp_weaklistoffset*/
1814
+ __Pyx_CoroutineAwait_self, /*tp_iter*/
1815
+ (iternextfunc) __Pyx_CoroutineAwait_Next, /*tp_iternext*/
1816
+ __pyx_CoroutineAwait_methods, /*tp_methods*/
1817
+ 0 , /*tp_members*/
1818
+ 0 , /*tp_getset*/
1819
+ 0, /*tp_base*/
1820
+ 0, /*tp_dict*/
1821
+ 0, /*tp_descr_get*/
1822
+ 0, /*tp_descr_set*/
1823
+ 0, /*tp_dictoffset*/
1824
+ 0, /*tp_init*/
1825
+ 0, /*tp_alloc*/
1826
+ #if !CYTHON_COMPILING_IN_PYPY
1827
+ __Pyx_CoroutineAwait_no_new, /*tp_new*/
1828
+ #else
1829
+ 0, /*tp_new*/
1830
+ #endif
1831
+ 0, /*tp_free*/
1832
+ 0, /*tp_is_gc*/
1833
+ 0, /*tp_bases*/
1834
+ 0, /*tp_mro*/
1835
+ 0, /*tp_cache*/
1836
+ 0, /*tp_subclasses*/
1837
+ 0, /*tp_weaklist*/
1838
+ 0, /*tp_del*/
1839
+ 0, /*tp_version_tag*/
1840
+ 0, /*tp_finalize*/
1841
+ #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
1842
+ 0, /*tp_vectorcall*/
1843
+ #endif
1844
+ #if __PYX_NEED_TP_PRINT_SLOT
1845
+ 0, /*tp_print*/
1846
+ #endif
1847
+ #if PY_VERSION_HEX >= 0x030C0000
1848
+ 0, /*tp_watched*/
1849
+ #endif
1850
+ #if PY_VERSION_HEX >= 0x030d00A4
1851
+ 0, /*tp_versions_used*/
1852
+ #endif
1853
+ #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
1854
+ 0, /*tp_pypy_flags*/
1855
+ #endif
1856
+ };
1857
+ #endif /* CYTHON_USE_TYPE_SPECS */
1858
+
1859
+ static CYTHON_INLINE PyObject *__Pyx__Coroutine_await(PyObject *coroutine) {
1860
+ __pyx_CoroutineAwaitObject *await = PyObject_GC_New(__pyx_CoroutineAwaitObject, CGLOBAL(__pyx_CoroutineAwaitType));
1861
+ if (unlikely(!await)) return NULL;
1862
+ Py_INCREF(coroutine);
1863
+ await->coroutine = coroutine;
1864
+ PyObject_GC_Track(await);
1865
+ return (PyObject*)await;
1866
+ }
1867
+
1868
+ static PyObject *__Pyx_Coroutine_await(PyObject *coroutine) {
1869
+ if (unlikely(!coroutine || !__Pyx_Coroutine_Check(coroutine))) {
1870
+ PyErr_SetString(PyExc_TypeError, "invalid input, expected coroutine");
1871
+ return NULL;
1872
+ }
1873
+ return __Pyx__Coroutine_await(coroutine);
1874
+ }
1875
+
1876
+ static PyMethodDef __pyx_Coroutine_methods[] = {
1877
+ {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
1878
+ PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next iterated value or raise StopIteration.")},
1879
+ {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
1880
+ PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next iterated value or raise StopIteration.")},
1881
+ {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS, PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")},
1882
+ {0, 0, 0, 0}
1883
+ };
1884
+
1885
+ static PyMemberDef __pyx_Coroutine_memberlist[] = {
1886
+ {"cr_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
1887
+ {"cr_await", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
1888
+ PyDoc_STR("object being awaited, or None")},
1889
+ {"cr_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL},
1890
+ {"__module__", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_modulename), 0, 0},
1891
+ #if CYTHON_USE_TYPE_SPECS
1892
+ {"__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CoroutineObject, gi_weakreflist), READONLY, 0},
1893
+ #endif
1894
+ {0, 0, 0, 0, 0}
1895
+ };
1896
+
1897
+ static PyGetSetDef __pyx_Coroutine_getsets[] = {
1898
+ {"__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
1899
+ PyDoc_STR("name of the coroutine"), 0},
1900
+ {"__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
1901
+ PyDoc_STR("qualified name of the coroutine"), 0},
1902
+ {"cr_frame", (getter)__Pyx_Coroutine_get_frame, NULL,
1903
+ PyDoc_STR("Frame of the coroutine"), 0},
1904
+ {0, 0, 0, 0, 0}
1905
+ };
1906
+
1907
+ #if CYTHON_USE_TYPE_SPECS
1908
+ static PyType_Slot __pyx_CoroutineType_slots[] = {
1909
+ {Py_tp_dealloc, (void *)__Pyx_Coroutine_dealloc},
1910
+ {Py_am_await, (void *)&__Pyx_Coroutine_await},
1911
+ {Py_tp_traverse, (void *)__Pyx_Coroutine_traverse},
1912
+ {Py_tp_methods, (void *)__pyx_Coroutine_methods},
1913
+ {Py_tp_members, (void *)__pyx_Coroutine_memberlist},
1914
+ {Py_tp_getset, (void *)__pyx_Coroutine_getsets},
1915
+ {Py_tp_getattro, (void *) PyObject_GenericGetAttr},
1916
+ #if CYTHON_USE_TP_FINALIZE
1917
+ {Py_tp_finalize, (void *)__Pyx_Coroutine_del},
1918
+ #endif
1919
+ #if __PYX_HAS_PY_AM_SEND
1920
+ {Py_am_send, (void *)__Pyx_Coroutine_AmSend},
1921
+ #endif
1922
+ {0, 0},
1923
+ };
1924
+
1925
+ static PyType_Spec __pyx_CoroutineType_spec = {
1926
+ __PYX_TYPE_MODULE_PREFIX "coroutine",
1927
+ sizeof(__pyx_CoroutineObject),
1928
+ 0,
1929
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/
1930
+ __pyx_CoroutineType_slots
1931
+ };
1932
+ #else /* CYTHON_USE_TYPE_SPECS */
1933
+
1934
+ static __Pyx_PyAsyncMethodsStruct __pyx_Coroutine_as_async = {
1935
+ __Pyx_Coroutine_await, /*am_await*/
1936
+ 0, /*am_aiter*/
1937
+ 0, /*am_anext*/
1938
+ __Pyx_Coroutine_AmSend, /*am_send*/
1939
+ };
1940
+
1941
+ static PyTypeObject __pyx_CoroutineType_type = {
1942
+ PyVarObject_HEAD_INIT(0, 0)
1943
+ __PYX_TYPE_MODULE_PREFIX "coroutine", /*tp_name*/
1944
+ sizeof(__pyx_CoroutineObject), /*tp_basicsize*/
1945
+ 0, /*tp_itemsize*/
1946
+ (destructor) __Pyx_Coroutine_dealloc,/*tp_dealloc*/
1947
+ 0, /*tp_print*/
1948
+ 0, /*tp_getattr*/
1949
+ 0, /*tp_setattr*/
1950
+ __Pyx_SlotTpAsAsync(__pyx_Coroutine_as_async), /*tp_as_async*/
1951
+ 0, /*tp_repr*/
1952
+ 0, /*tp_as_number*/
1953
+ 0, /*tp_as_sequence*/
1954
+ 0, /*tp_as_mapping*/
1955
+ 0, /*tp_hash*/
1956
+ 0, /*tp_call*/
1957
+ 0, /*tp_str*/
1958
+ 0, /*tp_getattro*/
1959
+ 0, /*tp_setattro*/
1960
+ 0, /*tp_as_buffer*/
1961
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE | __Pyx_TPFLAGS_HAVE_AM_SEND, /*tp_flags*/
1962
+ 0, /*tp_doc*/
1963
+ (traverseproc) __Pyx_Coroutine_traverse, /*tp_traverse*/
1964
+ 0, /*tp_clear*/
1965
+ 0, /*tp_richcompare*/
1966
+ offsetof(__pyx_CoroutineObject, gi_weakreflist), /*tp_weaklistoffset*/
1967
+ // no tp_iter() as iterator is only available through __await__()
1968
+ 0, /*tp_iter*/
1969
+ 0, /*tp_iternext*/
1970
+ __pyx_Coroutine_methods, /*tp_methods*/
1971
+ __pyx_Coroutine_memberlist, /*tp_members*/
1972
+ __pyx_Coroutine_getsets, /*tp_getset*/
1973
+ 0, /*tp_base*/
1974
+ 0, /*tp_dict*/
1975
+ 0, /*tp_descr_get*/
1976
+ 0, /*tp_descr_set*/
1977
+ 0, /*tp_dictoffset*/
1978
+ 0, /*tp_init*/
1979
+ 0, /*tp_alloc*/
1980
+ 0, /*tp_new*/
1981
+ 0, /*tp_free*/
1982
+ 0, /*tp_is_gc*/
1983
+ 0, /*tp_bases*/
1984
+ 0, /*tp_mro*/
1985
+ 0, /*tp_cache*/
1986
+ 0, /*tp_subclasses*/
1987
+ 0, /*tp_weaklist*/
1988
+ #if CYTHON_USE_TP_FINALIZE
1989
+ 0, /*tp_del*/
1990
+ #else
1991
+ __Pyx_Coroutine_del, /*tp_del*/
1992
+ #endif
1993
+ 0, /*tp_version_tag*/
1994
+ #if CYTHON_USE_TP_FINALIZE
1995
+ __Pyx_Coroutine_del, /*tp_finalize*/
1996
+ #else
1997
+ 0, /*tp_finalize*/
1998
+ #endif
1999
+ #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
2000
+ 0, /*tp_vectorcall*/
2001
+ #endif
2002
+ #if __PYX_NEED_TP_PRINT_SLOT
2003
+ 0, /*tp_print*/
2004
+ #endif
2005
+ #if PY_VERSION_HEX >= 0x030C0000
2006
+ 0, /*tp_watched*/
2007
+ #endif
2008
+ #if PY_VERSION_HEX >= 0x030d00A4
2009
+ 0, /*tp_versions_used*/
2010
+ #endif
2011
+ #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
2012
+ 0, /*tp_pypy_flags*/
2013
+ #endif
2014
+ };
2015
+ #endif /* CYTHON_USE_TYPE_SPECS */
2016
+
2017
+ static int __pyx_Coroutine_init(PyObject *module) {
2018
+ $modulestatetype_cname *mstate;
2019
+ CYTHON_MAYBE_UNUSED_VAR(module);
2020
+ // on Windows, C-API functions can't be used in slots statically
2021
+ mstate = __Pyx_PyModule_GetState(module);
2022
+ #if CYTHON_USE_TYPE_SPECS
2023
+ mstate->__pyx_CoroutineType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CoroutineType_spec, NULL);
2024
+ #else
2025
+ __pyx_CoroutineType_type.tp_getattro = PyObject_GenericGetAttr;
2026
+ mstate->__pyx_CoroutineType = __Pyx_FetchCommonType(&__pyx_CoroutineType_type);
2027
+ #endif
2028
+ if (unlikely(!mstate->__pyx_CoroutineType))
2029
+ return -1;
2030
+ #ifdef __Pyx_IterableCoroutine_USED
2031
+ if (unlikely(__pyx_IterableCoroutine_init(module) == -1))
2032
+ return -1;
2033
+ #endif
2034
+
2035
+ #if CYTHON_USE_TYPE_SPECS
2036
+ mstate->__pyx_CoroutineAwaitType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CoroutineAwaitType_spec, NULL);
2037
+ #else
2038
+ mstate->__pyx_CoroutineAwaitType = __Pyx_FetchCommonType(&__pyx_CoroutineAwaitType_type);
2039
+ #endif
2040
+ if (unlikely(!mstate->__pyx_CoroutineAwaitType))
2041
+ return -1;
2042
+ return 0;
2043
+ }
2044
+
2045
+
2046
+ //////////////////// IterableCoroutine.proto ////////////////////
2047
+
2048
+ #define __Pyx_IterableCoroutine_USED
2049
+
2050
+ #undef __Pyx_Coroutine_Check
2051
+ #define __Pyx_Coroutine_Check(obj) (__Pyx_Coroutine_CheckExact(obj) || __Pyx_IS_TYPE(obj, CGLOBAL(__pyx_IterableCoroutineType)))
2052
+
2053
+ #define __Pyx_IterableCoroutine_New(body, code, closure, name, qualname, module_name) \
2054
+ __Pyx__Coroutine_New(CGLOBAL(__pyx_IterableCoroutineType), body, code, closure, name, qualname, module_name)
2055
+
2056
+ static int __pyx_IterableCoroutine_init(PyObject *module);/*proto*/
2057
+
2058
+
2059
+ //////////////////// IterableCoroutine ////////////////////
2060
+ //@requires: Coroutine
2061
+ //@requires: CommonStructures.c::FetchCommonType
2062
+ //@substitute: naming
2063
+
2064
+ #if CYTHON_USE_TYPE_SPECS
2065
+ static PyType_Slot __pyx_IterableCoroutineType_slots[] = {
2066
+ {Py_tp_dealloc, (void *)__Pyx_Coroutine_dealloc},
2067
+ {Py_am_await, (void *)&__Pyx_Coroutine_await},
2068
+ {Py_tp_traverse, (void *)__Pyx_Coroutine_traverse},
2069
+ {Py_tp_iter, (void *)__Pyx_Coroutine_await},
2070
+ {Py_tp_iternext, (void *)__Pyx_Generator_Next},
2071
+ {Py_tp_methods, (void *)__pyx_Coroutine_methods},
2072
+ {Py_tp_members, (void *)__pyx_Coroutine_memberlist},
2073
+ {Py_tp_getset, (void *)__pyx_Coroutine_getsets},
2074
+ {Py_tp_getattro, (void *) PyObject_GenericGetAttr},
2075
+ #if CYTHON_USE_TP_FINALIZE
2076
+ {Py_tp_finalize, (void *)__Pyx_Coroutine_del},
2077
+ #endif
2078
+ #if __PYX_HAS_PY_AM_SEND
2079
+ {Py_am_send, (void *)__Pyx_Coroutine_AmSend},
2080
+ #endif
2081
+ {0, 0},
2082
+ };
2083
+
2084
+ static PyType_Spec __pyx_IterableCoroutineType_spec = {
2085
+ __PYX_TYPE_MODULE_PREFIX "iterable_coroutine",
2086
+ sizeof(__pyx_CoroutineObject),
2087
+ 0,
2088
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/
2089
+ __pyx_IterableCoroutineType_slots
2090
+ };
2091
+ #else /* CYTHON_USE_TYPE_SPECS */
2092
+
2093
+ static PyTypeObject __pyx_IterableCoroutineType_type = {
2094
+ PyVarObject_HEAD_INIT(0, 0)
2095
+ __PYX_TYPE_MODULE_PREFIX "iterable_coroutine", /*tp_name*/
2096
+ sizeof(__pyx_CoroutineObject), /*tp_basicsize*/
2097
+ 0, /*tp_itemsize*/
2098
+ (destructor) __Pyx_Coroutine_dealloc,/*tp_dealloc*/
2099
+ 0, /*tp_print*/
2100
+ 0, /*tp_getattr*/
2101
+ 0, /*tp_setattr*/
2102
+ __Pyx_SlotTpAsAsync(__pyx_Coroutine_as_async), /*tp_as_async*/
2103
+ 0, /*tp_repr*/
2104
+ 0, /*tp_as_number*/
2105
+ 0, /*tp_as_sequence*/
2106
+ 0, /*tp_as_mapping*/
2107
+ 0, /*tp_hash*/
2108
+ 0, /*tp_call*/
2109
+ 0, /*tp_str*/
2110
+ 0, /*tp_getattro*/
2111
+ 0, /*tp_setattro*/
2112
+ 0, /*tp_as_buffer*/
2113
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE | __Pyx_TPFLAGS_HAVE_AM_SEND, /*tp_flags*/
2114
+ 0, /*tp_doc*/
2115
+ (traverseproc) __Pyx_Coroutine_traverse, /*tp_traverse*/
2116
+ 0, /*tp_clear*/
2117
+ 0, /*tp_richcompare*/
2118
+ offsetof(__pyx_CoroutineObject, gi_weakreflist), /*tp_weaklistoffset*/
2119
+ // enable iteration for legacy support of asyncio yield-from protocol
2120
+ __Pyx_Coroutine_await, /*tp_iter*/
2121
+ (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/
2122
+ __pyx_Coroutine_methods, /*tp_methods*/
2123
+ __pyx_Coroutine_memberlist, /*tp_members*/
2124
+ __pyx_Coroutine_getsets, /*tp_getset*/
2125
+ 0, /*tp_base*/
2126
+ 0, /*tp_dict*/
2127
+ 0, /*tp_descr_get*/
2128
+ 0, /*tp_descr_set*/
2129
+ 0, /*tp_dictoffset*/
2130
+ 0, /*tp_init*/
2131
+ 0, /*tp_alloc*/
2132
+ 0, /*tp_new*/
2133
+ 0, /*tp_free*/
2134
+ 0, /*tp_is_gc*/
2135
+ 0, /*tp_bases*/
2136
+ 0, /*tp_mro*/
2137
+ 0, /*tp_cache*/
2138
+ 0, /*tp_subclasses*/
2139
+ 0, /*tp_weaklist*/
2140
+ 0, /*tp_del*/
2141
+ 0, /*tp_version_tag*/
2142
+ #if !CYTHON_COMPILING_IN_PYPY
2143
+ __Pyx_Coroutine_del, /*tp_finalize*/
2144
+ #endif
2145
+ #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
2146
+ 0, /*tp_vectorcall*/
2147
+ #endif
2148
+ #if __PYX_NEED_TP_PRINT_SLOT
2149
+ 0, /*tp_print*/
2150
+ #endif
2151
+ #if PY_VERSION_HEX >= 0x030C0000
2152
+ 0, /*tp_watched*/
2153
+ #endif
2154
+ #if PY_VERSION_HEX >= 0x030d00A4
2155
+ 0, /*tp_versions_used*/
2156
+ #endif
2157
+ #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
2158
+ 0, /*tp_pypy_flags*/
2159
+ #endif
2160
+ };
2161
+ #endif /* CYTHON_USE_TYPE_SPECS */
2162
+
2163
+
2164
+ static int __pyx_IterableCoroutine_init(PyObject *module) {
2165
+ $modulestatetype_cname *mstate = __Pyx_PyModule_GetState(module);
2166
+ #if CYTHON_USE_TYPE_SPECS
2167
+ mstate->__pyx_IterableCoroutineType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_IterableCoroutineType_spec, NULL);
2168
+ #else
2169
+ CYTHON_UNUSED_VAR(module);
2170
+ __pyx_IterableCoroutineType_type.tp_getattro = PyObject_GenericGetAttr;
2171
+ mstate->__pyx_IterableCoroutineType = __Pyx_FetchCommonType(&__pyx_IterableCoroutineType_type);
2172
+ #endif
2173
+ if (unlikely(!mstate->__pyx_IterableCoroutineType))
2174
+ return -1;
2175
+ return 0;
2176
+ }
2177
+
2178
+
2179
+ //////////////////// Generator ////////////////////
2180
+ //@requires: CoroutineBase
2181
+ //@substitute: naming
2182
+
2183
+ static PyMethodDef __pyx_Generator_methods[] = {
2184
+ {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
2185
+ PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
2186
+ {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
2187
+ PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
2188
+ {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS,
2189
+ PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
2190
+ {0, 0, 0, 0}
2191
+ };
2192
+
2193
+ static PyMemberDef __pyx_Generator_memberlist[] = {
2194
+ {"gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
2195
+ {"gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
2196
+ PyDoc_STR("object being iterated by 'yield from', or None")},
2197
+ {"gi_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL},
2198
+ {"__module__", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_modulename), 0, 0},
2199
+ #if CYTHON_USE_TYPE_SPECS
2200
+ {"__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CoroutineObject, gi_weakreflist), READONLY, 0},
2201
+ #endif
2202
+ {0, 0, 0, 0, 0}
2203
+ };
2204
+
2205
+ static PyGetSetDef __pyx_Generator_getsets[] = {
2206
+ {"__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
2207
+ PyDoc_STR("name of the generator"), 0},
2208
+ {"__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
2209
+ PyDoc_STR("qualified name of the generator"), 0},
2210
+ {"gi_frame", (getter)__Pyx_Coroutine_get_frame, NULL,
2211
+ PyDoc_STR("Frame of the generator"), 0},
2212
+ {0, 0, 0, 0, 0}
2213
+ };
2214
+
2215
+ #if CYTHON_USE_TYPE_SPECS
2216
+ static PyType_Slot __pyx_GeneratorType_slots[] = {
2217
+ {Py_tp_dealloc, (void *)__Pyx_Coroutine_dealloc},
2218
+ {Py_tp_traverse, (void *)__Pyx_Coroutine_traverse},
2219
+ {Py_tp_iter, (void *)PyObject_SelfIter},
2220
+ {Py_tp_iternext, (void *)__Pyx_Generator_Next},
2221
+ {Py_tp_methods, (void *)__pyx_Generator_methods},
2222
+ {Py_tp_members, (void *)__pyx_Generator_memberlist},
2223
+ {Py_tp_getset, (void *)__pyx_Generator_getsets},
2224
+ {Py_tp_getattro, (void *) PyObject_GenericGetAttr},
2225
+ #if CYTHON_USE_TP_FINALIZE
2226
+ {Py_tp_finalize, (void *)__Pyx_Coroutine_del},
2227
+ #endif
2228
+ #if __PYX_HAS_PY_AM_SEND
2229
+ {Py_am_send, (void *)__Pyx_Coroutine_AmSend},
2230
+ #endif
2231
+ {0, 0},
2232
+ };
2233
+
2234
+ static PyType_Spec __pyx_GeneratorType_spec = {
2235
+ __PYX_TYPE_MODULE_PREFIX "generator",
2236
+ sizeof(__pyx_CoroutineObject),
2237
+ 0,
2238
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/
2239
+ __pyx_GeneratorType_slots
2240
+ };
2241
+ #else /* CYTHON_USE_TYPE_SPECS */
2242
+ static __Pyx_PyAsyncMethodsStruct __pyx_Generator_as_async = {
2243
+ 0, /*am_await*/
2244
+ 0, /*am_aiter*/
2245
+ 0, /*am_anext*/
2246
+ __Pyx_Coroutine_AmSend, /*am_send*/
2247
+ };
2248
+
2249
+ static PyTypeObject __pyx_GeneratorType_type = {
2250
+ PyVarObject_HEAD_INIT(0, 0)
2251
+ __PYX_TYPE_MODULE_PREFIX "generator", /*tp_name*/
2252
+ sizeof(__pyx_CoroutineObject), /*tp_basicsize*/
2253
+ 0, /*tp_itemsize*/
2254
+ (destructor) __Pyx_Coroutine_dealloc,/*tp_dealloc*/
2255
+ 0, /*tp_print*/
2256
+ 0, /*tp_getattr*/
2257
+ 0, /*tp_setattr*/
2258
+ __Pyx_SlotTpAsAsync(__pyx_Generator_as_async), /*tp_as_async*/
2259
+ 0, /*tp_repr*/
2260
+ 0, /*tp_as_number*/
2261
+ 0, /*tp_as_sequence*/
2262
+ 0, /*tp_as_mapping*/
2263
+ 0, /*tp_hash*/
2264
+ 0, /*tp_call*/
2265
+ 0, /*tp_str*/
2266
+ 0, /*tp_getattro*/
2267
+ 0, /*tp_setattro*/
2268
+ 0, /*tp_as_buffer*/
2269
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE | __Pyx_TPFLAGS_HAVE_AM_SEND, /*tp_flags*/
2270
+ 0, /*tp_doc*/
2271
+ (traverseproc) __Pyx_Coroutine_traverse, /*tp_traverse*/
2272
+ 0, /*tp_clear*/
2273
+ 0, /*tp_richcompare*/
2274
+ offsetof(__pyx_CoroutineObject, gi_weakreflist), /*tp_weaklistoffset*/
2275
+ 0, /*tp_iter*/
2276
+ (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/
2277
+ __pyx_Generator_methods, /*tp_methods*/
2278
+ __pyx_Generator_memberlist, /*tp_members*/
2279
+ __pyx_Generator_getsets, /*tp_getset*/
2280
+ 0, /*tp_base*/
2281
+ 0, /*tp_dict*/
2282
+ 0, /*tp_descr_get*/
2283
+ 0, /*tp_descr_set*/
2284
+ 0, /*tp_dictoffset*/
2285
+ 0, /*tp_init*/
2286
+ 0, /*tp_alloc*/
2287
+ 0, /*tp_new*/
2288
+ 0, /*tp_free*/
2289
+ 0, /*tp_is_gc*/
2290
+ 0, /*tp_bases*/
2291
+ 0, /*tp_mro*/
2292
+ 0, /*tp_cache*/
2293
+ 0, /*tp_subclasses*/
2294
+ 0, /*tp_weaklist*/
2295
+ #if CYTHON_USE_TP_FINALIZE
2296
+ 0, /*tp_del*/
2297
+ #else
2298
+ __Pyx_Coroutine_del, /*tp_del*/
2299
+ #endif
2300
+ 0, /*tp_version_tag*/
2301
+ #if CYTHON_USE_TP_FINALIZE
2302
+ __Pyx_Coroutine_del, /*tp_finalize*/
2303
+ #else
2304
+ 0, /*tp_finalize*/
2305
+ #endif
2306
+ #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
2307
+ 0, /*tp_vectorcall*/
2308
+ #endif
2309
+ #if __PYX_NEED_TP_PRINT_SLOT
2310
+ 0, /*tp_print*/
2311
+ #endif
2312
+ #if PY_VERSION_HEX >= 0x030C0000
2313
+ 0, /*tp_watched*/
2314
+ #endif
2315
+ #if PY_VERSION_HEX >= 0x030d00A4
2316
+ 0, /*tp_versions_used*/
2317
+ #endif
2318
+ #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
2319
+ 0, /*tp_pypy_flags*/
2320
+ #endif
2321
+ };
2322
+ #endif /* CYTHON_USE_TYPE_SPECS */
2323
+
2324
+ static int __pyx_Generator_init(PyObject *module) {
2325
+ $modulestatetype_cname *mstate = __Pyx_PyModule_GetState(module);
2326
+ #if CYTHON_USE_TYPE_SPECS
2327
+ mstate->__pyx_GeneratorType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_GeneratorType_spec, NULL);
2328
+ #else
2329
+ // on Windows, C-API functions can't be used in slots statically
2330
+ __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
2331
+ __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
2332
+ mstate->__pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
2333
+ #endif
2334
+ if (unlikely(!mstate->__pyx_GeneratorType)) {
2335
+ return -1;
2336
+ }
2337
+ return 0;
2338
+ }
2339
+
2340
+ static PyObject *__Pyx_Generator_GetInlinedResult(PyObject *self) {
2341
+ __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
2342
+ PyObject *retval = NULL;
2343
+ __Pyx_PySendResult result = __Pyx_Coroutine_SendEx(gen, Py_None, &retval, 0);
2344
+ (void) result;
2345
+ assert (result == PYGEN_RETURN || result == PYGEN_ERROR);
2346
+ assert ((result == PYGEN_RETURN && retval != NULL) || (result == PYGEN_ERROR && retval == NULL));
2347
+ return retval;
2348
+ }
2349
+
2350
+
2351
+ /////////////// ReturnWithStopIteration.proto ///////////////
2352
+
2353
+ static CYTHON_INLINE void __Pyx_ReturnWithStopIteration(PyObject* value, int async); /*proto*/
2354
+
2355
+ /////////////// ReturnWithStopIteration ///////////////
2356
+ //@requires: Exceptions.c::PyErrFetchRestore
2357
+ //@requires: Exceptions.c::PyThreadStateGet
2358
+ //@requires: ObjectHandling.c::PyObjectCallOneArg
2359
+ //@substitute: naming
2360
+
2361
+ // 1) Instantiating an exception just to pass back a value is costly.
2362
+ // 2) CPython 3.12 cannot separate exception type and value
2363
+ // 3) Passing a tuple as value into PyErr_SetObject() passes its items on as arguments.
2364
+ // 4) Passing an exception as value will interpret it as an exception on unpacking and raise it (or unpack its value).
2365
+ // 5) If there is currently an exception being handled, we need to chain it.
2366
+
2367
+ static void __Pyx__ReturnWithStopIteration(PyObject* value, int async); /*proto*/
2368
+
2369
+ static CYTHON_INLINE void __Pyx_ReturnWithStopIteration(PyObject* value, int async) {
2370
+ if (value == Py_None) {
2371
+ PyErr_SetNone(async ? PyExc_StopAsyncIteration : PyExc_StopIteration);
2372
+ return;
2373
+ }
2374
+ __Pyx__ReturnWithStopIteration(value, async);
2375
+ }
2376
+
2377
+ static void __Pyx__ReturnWithStopIteration(PyObject* value, int async) {
2378
+ #if CYTHON_COMPILING_IN_CPYTHON
2379
+ __Pyx_PyThreadState_declare
2380
+ #endif
2381
+ PyObject *exc;
2382
+ PyObject *exc_type = async ? PyExc_StopAsyncIteration : PyExc_StopIteration;
2383
+ #if CYTHON_COMPILING_IN_CPYTHON
2384
+ if (PY_VERSION_HEX >= 0x030C00A6
2385
+ || unlikely(PyTuple_Check(value) || PyExceptionInstance_Check(value))) {
2386
+ exc = __Pyx_PyObject_CallOneArg(exc_type, value);
2387
+ if (unlikely(!exc)) return;
2388
+ } else {
2389
+ // it's safe to avoid instantiating the exception
2390
+ Py_INCREF(value);
2391
+ exc = value;
2392
+ }
2393
+ #if CYTHON_FAST_THREAD_STATE
2394
+ __Pyx_PyThreadState_assign
2395
+ #if CYTHON_USE_EXC_INFO_STACK
2396
+ if (!$local_tstate_cname->exc_info->exc_value)
2397
+ #else
2398
+ if (!$local_tstate_cname->exc_type)
2399
+ #endif
2400
+ {
2401
+ // no chaining needed => avoid the overhead in PyErr_SetObject()
2402
+ Py_INCREF(exc_type);
2403
+ __Pyx_ErrRestore(exc_type, exc, NULL);
2404
+ return;
2405
+ }
2406
+ #endif
2407
+ #else
2408
+ exc = __Pyx_PyObject_CallOneArg(exc_type, value);
2409
+ if (unlikely(!exc)) return;
2410
+ #endif
2411
+ PyErr_SetObject(exc_type, exc);
2412
+ Py_DECREF(exc);
2413
+ }