Cython 3.1.0__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 (316) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +323 -0
  4. Cython/Build/Dependencies.py +1306 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +463 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/SharedModule.py +76 -0
  9. Cython/Build/Tests/TestCyCache.py +194 -0
  10. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  11. Cython/Build/Tests/TestDependencies.py +133 -0
  12. Cython/Build/Tests/TestInline.py +177 -0
  13. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  14. Cython/Build/Tests/TestRecythonize.py +212 -0
  15. Cython/Build/Tests/TestStripLiterals.py +155 -0
  16. Cython/Build/Tests/__init__.py +1 -0
  17. Cython/Build/__init__.py +8 -0
  18. Cython/CodeWriter.py +811 -0
  19. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  20. Cython/Compiler/Annotate.py +326 -0
  21. Cython/Compiler/AutoDocTransforms.py +320 -0
  22. Cython/Compiler/Buffer.py +680 -0
  23. Cython/Compiler/Builtin.py +934 -0
  24. Cython/Compiler/CmdLine.py +259 -0
  25. Cython/Compiler/Code.pxd +148 -0
  26. Cython/Compiler/Code.py +3375 -0
  27. Cython/Compiler/CodeGeneration.py +33 -0
  28. Cython/Compiler/CythonScope.py +187 -0
  29. Cython/Compiler/Dataclass.py +868 -0
  30. Cython/Compiler/DebugFlags.py +24 -0
  31. Cython/Compiler/Errors.py +295 -0
  32. Cython/Compiler/ExprNodes.py +15267 -0
  33. Cython/Compiler/FlowControl.pxd +97 -0
  34. Cython/Compiler/FlowControl.py +1455 -0
  35. Cython/Compiler/FusedNode.py +1002 -0
  36. Cython/Compiler/Future.py +16 -0
  37. Cython/Compiler/Interpreter.py +57 -0
  38. Cython/Compiler/Lexicon.py +340 -0
  39. Cython/Compiler/LineTable.py +114 -0
  40. Cython/Compiler/Main.py +853 -0
  41. Cython/Compiler/MatchCaseNodes.py +259 -0
  42. Cython/Compiler/MemoryView.py +922 -0
  43. Cython/Compiler/ModuleNode.py +4024 -0
  44. Cython/Compiler/Naming.py +374 -0
  45. Cython/Compiler/Nodes.py +10826 -0
  46. Cython/Compiler/Optimize.py +5256 -0
  47. Cython/Compiler/Options.py +835 -0
  48. Cython/Compiler/ParseTreeTransforms.pxd +77 -0
  49. Cython/Compiler/ParseTreeTransforms.py +4509 -0
  50. Cython/Compiler/Parsing.pxd +9 -0
  51. Cython/Compiler/Parsing.py +4789 -0
  52. Cython/Compiler/Pipeline.py +439 -0
  53. Cython/Compiler/PyrexTypes.py +5762 -0
  54. Cython/Compiler/Pythran.py +232 -0
  55. Cython/Compiler/Scanning.pxd +40 -0
  56. Cython/Compiler/Scanning.py +577 -0
  57. Cython/Compiler/StringEncoding.py +347 -0
  58. Cython/Compiler/Symtab.py +3080 -0
  59. Cython/Compiler/Tests/TestBuffer.py +105 -0
  60. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  61. Cython/Compiler/Tests/TestCmdLine.py +586 -0
  62. Cython/Compiler/Tests/TestCode.py +86 -0
  63. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  64. Cython/Compiler/Tests/TestGrammar.py +202 -0
  65. Cython/Compiler/Tests/TestMemView.py +71 -0
  66. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  67. Cython/Compiler/Tests/TestScanning.py +134 -0
  68. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  69. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  70. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  71. Cython/Compiler/Tests/TestTreePath.py +103 -0
  72. Cython/Compiler/Tests/TestTypes.py +75 -0
  73. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  74. Cython/Compiler/Tests/TestVisitor.py +61 -0
  75. Cython/Compiler/Tests/Utils.py +36 -0
  76. Cython/Compiler/Tests/__init__.py +1 -0
  77. Cython/Compiler/TreeFragment.py +278 -0
  78. Cython/Compiler/TreePath.py +303 -0
  79. Cython/Compiler/TypeInference.py +584 -0
  80. Cython/Compiler/TypeSlots.py +1181 -0
  81. Cython/Compiler/UFuncs.py +311 -0
  82. Cython/Compiler/UtilNodes.py +389 -0
  83. Cython/Compiler/UtilityCode.py +344 -0
  84. Cython/Compiler/Version.py +8 -0
  85. Cython/Compiler/Visitor.pxd +53 -0
  86. Cython/Compiler/Visitor.py +861 -0
  87. Cython/Compiler/__init__.py +1 -0
  88. Cython/Coverage.py +448 -0
  89. Cython/Debugger/Cygdb.py +175 -0
  90. Cython/Debugger/DebugWriter.py +82 -0
  91. Cython/Debugger/Tests/TestLibCython.py +275 -0
  92. Cython/Debugger/Tests/__init__.py +1 -0
  93. Cython/Debugger/Tests/cfuncs.c +8 -0
  94. Cython/Debugger/Tests/codefile +49 -0
  95. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  96. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  97. Cython/Debugger/__init__.py +1 -0
  98. Cython/Debugger/libcython.py +1548 -0
  99. Cython/Debugger/libpython.py +2821 -0
  100. Cython/Debugging.py +20 -0
  101. Cython/Distutils/__init__.py +2 -0
  102. Cython/Distutils/build_ext.py +139 -0
  103. Cython/Distutils/extension.py +96 -0
  104. Cython/Distutils/old_build_ext.py +351 -0
  105. Cython/Includes/cpython/__init__.pxd +173 -0
  106. Cython/Includes/cpython/array.pxd +174 -0
  107. Cython/Includes/cpython/bool.pxd +37 -0
  108. Cython/Includes/cpython/buffer.pxd +112 -0
  109. Cython/Includes/cpython/bytearray.pxd +33 -0
  110. Cython/Includes/cpython/bytes.pxd +200 -0
  111. Cython/Includes/cpython/cellobject.pxd +35 -0
  112. Cython/Includes/cpython/ceval.pxd +8 -0
  113. Cython/Includes/cpython/codecs.pxd +121 -0
  114. Cython/Includes/cpython/complex.pxd +60 -0
  115. Cython/Includes/cpython/contextvars.pxd +145 -0
  116. Cython/Includes/cpython/conversion.pxd +36 -0
  117. Cython/Includes/cpython/datetime.pxd +395 -0
  118. Cython/Includes/cpython/descr.pxd +26 -0
  119. Cython/Includes/cpython/dict.pxd +187 -0
  120. Cython/Includes/cpython/exc.pxd +263 -0
  121. Cython/Includes/cpython/fileobject.pxd +57 -0
  122. Cython/Includes/cpython/float.pxd +47 -0
  123. Cython/Includes/cpython/function.pxd +65 -0
  124. Cython/Includes/cpython/genobject.pxd +25 -0
  125. Cython/Includes/cpython/getargs.pxd +12 -0
  126. Cython/Includes/cpython/instance.pxd +25 -0
  127. Cython/Includes/cpython/iterator.pxd +36 -0
  128. Cython/Includes/cpython/iterobject.pxd +24 -0
  129. Cython/Includes/cpython/list.pxd +92 -0
  130. Cython/Includes/cpython/long.pxd +149 -0
  131. Cython/Includes/cpython/longintrepr.pxd +14 -0
  132. Cython/Includes/cpython/mapping.pxd +63 -0
  133. Cython/Includes/cpython/marshal.pxd +66 -0
  134. Cython/Includes/cpython/mem.pxd +120 -0
  135. Cython/Includes/cpython/memoryview.pxd +50 -0
  136. Cython/Includes/cpython/method.pxd +49 -0
  137. Cython/Includes/cpython/module.pxd +208 -0
  138. Cython/Includes/cpython/number.pxd +258 -0
  139. Cython/Includes/cpython/object.pxd +433 -0
  140. Cython/Includes/cpython/pycapsule.pxd +143 -0
  141. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  142. Cython/Includes/cpython/pyport.pxd +8 -0
  143. Cython/Includes/cpython/pystate.pxd +95 -0
  144. Cython/Includes/cpython/pythread.pxd +53 -0
  145. Cython/Includes/cpython/ref.pxd +67 -0
  146. Cython/Includes/cpython/sequence.pxd +134 -0
  147. Cython/Includes/cpython/set.pxd +119 -0
  148. Cython/Includes/cpython/slice.pxd +70 -0
  149. Cython/Includes/cpython/time.pxd +129 -0
  150. Cython/Includes/cpython/tuple.pxd +72 -0
  151. Cython/Includes/cpython/type.pxd +53 -0
  152. Cython/Includes/cpython/unicode.pxd +639 -0
  153. Cython/Includes/cpython/version.pxd +32 -0
  154. Cython/Includes/cpython/weakref.pxd +78 -0
  155. Cython/Includes/libc/__init__.pxd +1 -0
  156. Cython/Includes/libc/complex.pxd +35 -0
  157. Cython/Includes/libc/errno.pxd +127 -0
  158. Cython/Includes/libc/float.pxd +43 -0
  159. Cython/Includes/libc/limits.pxd +28 -0
  160. Cython/Includes/libc/locale.pxd +46 -0
  161. Cython/Includes/libc/math.pxd +209 -0
  162. Cython/Includes/libc/setjmp.pxd +10 -0
  163. Cython/Includes/libc/signal.pxd +64 -0
  164. Cython/Includes/libc/stddef.pxd +9 -0
  165. Cython/Includes/libc/stdint.pxd +105 -0
  166. Cython/Includes/libc/stdio.pxd +80 -0
  167. Cython/Includes/libc/stdlib.pxd +72 -0
  168. Cython/Includes/libc/string.pxd +50 -0
  169. Cython/Includes/libc/threads.pxd +84 -0
  170. Cython/Includes/libc/time.pxd +51 -0
  171. Cython/Includes/libcpp/__init__.pxd +4 -0
  172. Cython/Includes/libcpp/algorithm.pxd +320 -0
  173. Cython/Includes/libcpp/any.pxd +16 -0
  174. Cython/Includes/libcpp/atomic.pxd +59 -0
  175. Cython/Includes/libcpp/barrier.pxd +22 -0
  176. Cython/Includes/libcpp/bit.pxd +29 -0
  177. Cython/Includes/libcpp/cast.pxd +12 -0
  178. Cython/Includes/libcpp/cmath.pxd +518 -0
  179. Cython/Includes/libcpp/complex.pxd +106 -0
  180. Cython/Includes/libcpp/deque.pxd +165 -0
  181. Cython/Includes/libcpp/exception.pxd +86 -0
  182. Cython/Includes/libcpp/execution.pxd +15 -0
  183. Cython/Includes/libcpp/forward_list.pxd +63 -0
  184. Cython/Includes/libcpp/functional.pxd +26 -0
  185. Cython/Includes/libcpp/future.pxd +103 -0
  186. Cython/Includes/libcpp/iterator.pxd +34 -0
  187. Cython/Includes/libcpp/latch.pxd +17 -0
  188. Cython/Includes/libcpp/limits.pxd +61 -0
  189. Cython/Includes/libcpp/list.pxd +117 -0
  190. Cython/Includes/libcpp/map.pxd +252 -0
  191. Cython/Includes/libcpp/memory.pxd +115 -0
  192. Cython/Includes/libcpp/mutex.pxd +130 -0
  193. Cython/Includes/libcpp/numbers.pxd +15 -0
  194. Cython/Includes/libcpp/numeric.pxd +131 -0
  195. Cython/Includes/libcpp/optional.pxd +34 -0
  196. Cython/Includes/libcpp/pair.pxd +1 -0
  197. Cython/Includes/libcpp/queue.pxd +25 -0
  198. Cython/Includes/libcpp/random.pxd +166 -0
  199. Cython/Includes/libcpp/semaphore.pxd +44 -0
  200. Cython/Includes/libcpp/set.pxd +228 -0
  201. Cython/Includes/libcpp/shared_mutex.pxd +72 -0
  202. Cython/Includes/libcpp/span.pxd +87 -0
  203. Cython/Includes/libcpp/stack.pxd +11 -0
  204. Cython/Includes/libcpp/stop_token.pxd +105 -0
  205. Cython/Includes/libcpp/string.pxd +355 -0
  206. Cython/Includes/libcpp/string_view.pxd +181 -0
  207. Cython/Includes/libcpp/typeindex.pxd +15 -0
  208. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  209. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  210. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  211. Cython/Includes/libcpp/utility.pxd +30 -0
  212. Cython/Includes/libcpp/vector.pxd +186 -0
  213. Cython/Includes/openmp.pxd +50 -0
  214. Cython/Includes/posix/__init__.pxd +1 -0
  215. Cython/Includes/posix/dlfcn.pxd +14 -0
  216. Cython/Includes/posix/fcntl.pxd +86 -0
  217. Cython/Includes/posix/ioctl.pxd +4 -0
  218. Cython/Includes/posix/mman.pxd +101 -0
  219. Cython/Includes/posix/resource.pxd +57 -0
  220. Cython/Includes/posix/select.pxd +21 -0
  221. Cython/Includes/posix/signal.pxd +73 -0
  222. Cython/Includes/posix/stat.pxd +98 -0
  223. Cython/Includes/posix/stdio.pxd +37 -0
  224. Cython/Includes/posix/stdlib.pxd +29 -0
  225. Cython/Includes/posix/strings.pxd +9 -0
  226. Cython/Includes/posix/time.pxd +71 -0
  227. Cython/Includes/posix/types.pxd +30 -0
  228. Cython/Includes/posix/uio.pxd +26 -0
  229. Cython/Includes/posix/unistd.pxd +271 -0
  230. Cython/Includes/posix/wait.pxd +38 -0
  231. Cython/Plex/Actions.pxd +24 -0
  232. Cython/Plex/Actions.py +119 -0
  233. Cython/Plex/DFA.pxd +14 -0
  234. Cython/Plex/DFA.py +164 -0
  235. Cython/Plex/Errors.py +48 -0
  236. Cython/Plex/Lexicons.py +178 -0
  237. Cython/Plex/Machines.pxd +36 -0
  238. Cython/Plex/Machines.py +238 -0
  239. Cython/Plex/Regexps.py +539 -0
  240. Cython/Plex/Scanners.pxd +47 -0
  241. Cython/Plex/Scanners.py +360 -0
  242. Cython/Plex/Transitions.pxd +14 -0
  243. Cython/Plex/Transitions.py +239 -0
  244. Cython/Plex/__init__.py +34 -0
  245. Cython/Runtime/__init__.py +1 -0
  246. Cython/Runtime/refnanny.pyx +237 -0
  247. Cython/Shadow.py +690 -0
  248. Cython/Shadow.pyi +521 -0
  249. Cython/StringIOTree.py +170 -0
  250. Cython/Tempita/__init__.py +4 -0
  251. Cython/Tempita/_looper.py +154 -0
  252. Cython/Tempita/_tempita.py +1091 -0
  253. Cython/TestUtils.py +410 -0
  254. Cython/Tests/TestCodeWriter.py +128 -0
  255. Cython/Tests/TestCythonUtils.py +202 -0
  256. Cython/Tests/TestJediTyper.py +223 -0
  257. Cython/Tests/TestShadow.py +114 -0
  258. Cython/Tests/TestStringIOTree.py +67 -0
  259. Cython/Tests/TestTestUtils.py +90 -0
  260. Cython/Tests/__init__.py +1 -0
  261. Cython/Tests/xmlrunner.py +390 -0
  262. Cython/Utility/AsyncGen.c +1002 -0
  263. Cython/Utility/Buffer.c +875 -0
  264. Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
  265. Cython/Utility/Builtins.c +776 -0
  266. Cython/Utility/CConvert.pyx +134 -0
  267. Cython/Utility/CMath.c +104 -0
  268. Cython/Utility/CommonStructures.c +118 -0
  269. Cython/Utility/Complex.c +378 -0
  270. Cython/Utility/Coroutine.c +2206 -0
  271. Cython/Utility/CpdefEnums.pyx +103 -0
  272. Cython/Utility/CppConvert.pyx +279 -0
  273. Cython/Utility/CppSupport.cpp +143 -0
  274. Cython/Utility/CythonFunction.c +1794 -0
  275. Cython/Utility/Dataclasses.c +185 -0
  276. Cython/Utility/Dataclasses.py +112 -0
  277. Cython/Utility/Embed.c +125 -0
  278. Cython/Utility/Exceptions.c +1012 -0
  279. Cython/Utility/ExtensionTypes.c +809 -0
  280. Cython/Utility/FunctionArguments.c +965 -0
  281. Cython/Utility/ImportExport.c +987 -0
  282. Cython/Utility/Lock.c +136 -0
  283. Cython/Utility/MemoryView.pxd +187 -0
  284. Cython/Utility/MemoryView.pyx +1481 -0
  285. Cython/Utility/MemoryView_C.c +1046 -0
  286. Cython/Utility/ModuleSetupCode.c +3059 -0
  287. Cython/Utility/NumpyImportArray.c +46 -0
  288. Cython/Utility/ObjectHandling.c +3342 -0
  289. Cython/Utility/Optimize.c +1589 -0
  290. Cython/Utility/Overflow.c +404 -0
  291. Cython/Utility/Printing.c +86 -0
  292. Cython/Utility/Profile.c +709 -0
  293. Cython/Utility/StringTools.c +1259 -0
  294. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  295. Cython/Utility/TestCythonScope.pyx +75 -0
  296. Cython/Utility/TestUtilityLoader.c +12 -0
  297. Cython/Utility/TypeConversion.c +1284 -0
  298. Cython/Utility/UFuncs.pyx +50 -0
  299. Cython/Utility/UFuncs_C.c +89 -0
  300. Cython/Utility/__init__.py +28 -0
  301. Cython/Utility/arrayarray.h +148 -0
  302. Cython/Utils.py +687 -0
  303. Cython/__init__.py +10 -0
  304. Cython/__init__.pyi +7 -0
  305. Cython/py.typed +0 -0
  306. cython-3.1.0.dist-info/COPYING.txt +19 -0
  307. cython-3.1.0.dist-info/LICENSE.txt +176 -0
  308. cython-3.1.0.dist-info/METADATA +636 -0
  309. cython-3.1.0.dist-info/RECORD +316 -0
  310. cython-3.1.0.dist-info/WHEEL +5 -0
  311. cython-3.1.0.dist-info/entry_points.txt +4 -0
  312. cython-3.1.0.dist-info/top_level.txt +3 -0
  313. cython.py +29 -0
  314. pyximport/__init__.py +4 -0
  315. pyximport/pyxbuild.py +160 -0
  316. pyximport/pyximport.py +482 -0
@@ -0,0 +1,3342 @@
1
+ /*
2
+ * General object operations and protocol implementations,
3
+ * including their specialisations for certain builtins.
4
+ *
5
+ * Optional optimisations for builtins are in Optimize.c.
6
+ *
7
+ * Required replacements of builtins are in Builtins.c.
8
+ */
9
+
10
+ /////////////// RaiseNoneIterError.proto ///////////////
11
+
12
+ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
13
+
14
+ /////////////// RaiseNoneIterError ///////////////
15
+
16
+ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
17
+ PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
18
+ }
19
+
20
+ /////////////// RaiseTooManyValuesToUnpack.proto ///////////////
21
+
22
+ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
23
+
24
+ /////////////// RaiseTooManyValuesToUnpack ///////////////
25
+
26
+ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
27
+ PyErr_Format(PyExc_ValueError,
28
+ "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
29
+ }
30
+
31
+ /////////////// RaiseNeedMoreValuesToUnpack.proto ///////////////
32
+
33
+ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
34
+
35
+ /////////////// RaiseNeedMoreValuesToUnpack ///////////////
36
+
37
+ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
38
+ PyErr_Format(PyExc_ValueError,
39
+ "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
40
+ index, (index == 1) ? "" : "s");
41
+ }
42
+
43
+ /////////////// UnpackTupleError.proto ///////////////
44
+
45
+ static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/
46
+
47
+ /////////////// UnpackTupleError ///////////////
48
+ //@requires: RaiseNoneIterError
49
+ //@requires: RaiseNeedMoreValuesToUnpack
50
+ //@requires: RaiseTooManyValuesToUnpack
51
+
52
+ static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
53
+ if (t == Py_None) {
54
+ __Pyx_RaiseNoneNotIterableError();
55
+ } else {
56
+ Py_ssize_t size = __Pyx_PyTuple_GET_SIZE(t);
57
+ #if !CYTHON_ASSUME_SAFE_SIZE
58
+ if (unlikely(size < 0)) return;
59
+ #endif
60
+ if (size < index) {
61
+ __Pyx_RaiseNeedMoreValuesError(size);
62
+ } else {
63
+ __Pyx_RaiseTooManyValuesError(index);
64
+ }
65
+ }
66
+ }
67
+
68
+ /////////////// UnpackItemEndCheck.proto ///////////////
69
+
70
+ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
71
+
72
+ /////////////// UnpackItemEndCheck ///////////////
73
+ //@requires: RaiseTooManyValuesToUnpack
74
+ //@requires: IterFinish
75
+
76
+ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
77
+ if (unlikely(retval)) {
78
+ Py_DECREF(retval);
79
+ __Pyx_RaiseTooManyValuesError(expected);
80
+ return -1;
81
+ }
82
+
83
+ return __Pyx_IterFinish();
84
+ }
85
+
86
+ /////////////// UnpackTuple2.proto ///////////////
87
+
88
+ static CYTHON_INLINE int __Pyx_unpack_tuple2(
89
+ PyObject* tuple, PyObject** value1, PyObject** value2, int is_tuple, int has_known_size, int decref_tuple);
90
+
91
+ static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
92
+ PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple);
93
+ static int __Pyx_unpack_tuple2_generic(
94
+ PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple);
95
+
96
+ /////////////// UnpackTuple2 ///////////////
97
+ //@requires: UnpackItemEndCheck
98
+ //@requires: UnpackTupleError
99
+ //@requires: RaiseNeedMoreValuesToUnpack
100
+
101
+ static CYTHON_INLINE int __Pyx_unpack_tuple2(
102
+ PyObject* tuple, PyObject** value1, PyObject** value2, int is_tuple, int has_known_size, int decref_tuple) {
103
+ if (likely(is_tuple || PyTuple_Check(tuple))) {
104
+ Py_ssize_t size;
105
+ if (has_known_size) {
106
+ return __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple);
107
+ }
108
+ size = __Pyx_PyTuple_GET_SIZE(tuple);
109
+ if (likely(size == 2)) {
110
+ return __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple);
111
+ }
112
+ if (size >= 0) {
113
+ // "size == -1" indicates an error already.
114
+ __Pyx_UnpackTupleError(tuple, 2);
115
+ }
116
+ return -1;
117
+ } else {
118
+ return __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple);
119
+ }
120
+ }
121
+
122
+ static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
123
+ PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) {
124
+ PyObject *value1 = NULL, *value2 = NULL;
125
+ #if CYTHON_AVOID_BORROWED_REFS || !CYTHON_ASSUME_SAFE_MACROS
126
+ value1 = __Pyx_PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad;
127
+ value2 = __Pyx_PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad;
128
+ #else
129
+ value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1);
130
+ value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2);
131
+ #endif
132
+ if (decref_tuple) {
133
+ Py_DECREF(tuple);
134
+ }
135
+
136
+ *pvalue1 = value1;
137
+ *pvalue2 = value2;
138
+ return 0;
139
+ #if CYTHON_AVOID_BORROWED_REFS || !CYTHON_ASSUME_SAFE_MACROS
140
+ bad:
141
+ Py_XDECREF(value1);
142
+ Py_XDECREF(value2);
143
+ if (decref_tuple) { Py_XDECREF(tuple); }
144
+ return -1;
145
+ #endif
146
+ }
147
+
148
+ static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
149
+ int has_known_size, int decref_tuple) {
150
+ Py_ssize_t index;
151
+ PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
152
+ iternextfunc iternext;
153
+
154
+ iter = PyObject_GetIter(tuple);
155
+ if (unlikely(!iter)) goto bad;
156
+ if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
157
+
158
+ iternext = __Pyx_PyObject_GetIterNextFunc(iter);
159
+ value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
160
+ value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
161
+ if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
162
+
163
+ Py_DECREF(iter);
164
+ *pvalue1 = value1;
165
+ *pvalue2 = value2;
166
+ return 0;
167
+
168
+ unpacking_failed:
169
+ if (!has_known_size && __Pyx_IterFinish() == 0)
170
+ __Pyx_RaiseNeedMoreValuesError(index);
171
+ bad:
172
+ Py_XDECREF(iter);
173
+ Py_XDECREF(value1);
174
+ Py_XDECREF(value2);
175
+ if (decref_tuple) { Py_XDECREF(tuple); }
176
+ return -1;
177
+ }
178
+
179
+
180
+ /////////////// IterNextPlain.proto ///////////////
181
+
182
+ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next_Plain(PyObject *iterator);
183
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
184
+ static PyObject *__Pyx_GetBuiltinNext_LimitedAPI(void);
185
+ #endif
186
+
187
+ /////////////// IterNextPlain.module_state_decls ///////////////
188
+
189
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
190
+ PyObject *__Pyx_GetBuiltinNext_LimitedAPI_cache;
191
+ #endif
192
+
193
+ /////////////// IterNextPlain ///////////////
194
+ //@requires: GetBuiltinName
195
+
196
+ // There is no replacement for "Py_TYPE(obj)->iternext" in the C-API.
197
+ // PyIter_Next() discards the StopIteration, unlike Python's "next()".
198
+ // PyObject_GetSlot() rejects non-heap types in CPython < 3.10 (and PyPy).
199
+
200
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
201
+ static PyObject *__Pyx_GetBuiltinNext_LimitedAPI(void) {
202
+ if (unlikely(!CGLOBAL(__Pyx_GetBuiltinNext_LimitedAPI_cache)))
203
+ CGLOBAL(__Pyx_GetBuiltinNext_LimitedAPI_cache) = __Pyx_GetBuiltinName(PYIDENT("next"));
204
+ // Returns the globally owned reference, not a new reference!
205
+ return CGLOBAL(__Pyx_GetBuiltinNext_LimitedAPI_cache);
206
+ }
207
+ #endif
208
+
209
+ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next_Plain(PyObject *iterator) {
210
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
211
+ PyObject *result;
212
+ PyObject *next = __Pyx_GetBuiltinNext_LimitedAPI();
213
+ if (unlikely(!next)) return NULL;
214
+ result = PyObject_CallFunctionObjArgs(next, iterator, NULL);
215
+ return result;
216
+ #else
217
+ (void)__Pyx_GetBuiltinName; // only for early limited API
218
+ iternextfunc iternext = __Pyx_PyObject_GetIterNextFunc(iterator);
219
+ assert(iternext);
220
+ return iternext(iterator);
221
+ #endif
222
+ }
223
+
224
+
225
+ /////////////// IterNext.proto ///////////////
226
+
227
+ #define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL)
228
+ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/
229
+
230
+ /////////////// IterNext ///////////////
231
+ //@requires: Exceptions.c::PyThreadStateGet
232
+ //@requires: Exceptions.c::PyErrFetchRestore
233
+ //@requires: GetBuiltinName
234
+ //@requires: IterNextPlain
235
+
236
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x03080000
237
+ // In the Limited API for Py 3.7, PyIter_Check is defined but as a macro that uses
238
+ // non-limited API features and thus is unusable. Therefore, just call builtin next.
239
+ static PyObject *__Pyx_PyIter_Next2(PyObject *o, PyObject *defval) {
240
+ PyObject *result;
241
+ PyObject *next = __Pyx_GetBuiltinNext_LimitedAPI();
242
+ if (unlikely(!next)) return NULL;
243
+ // This works if defval is NULL or not
244
+ result = PyObject_CallFunctionObjArgs(next, o, defval, NULL);
245
+ return result;
246
+ }
247
+ #else
248
+ static PyObject *__Pyx_PyIter_Next2Default(PyObject* defval) {
249
+ PyObject* exc_type;
250
+ __Pyx_PyThreadState_declare
251
+ __Pyx_PyThreadState_assign
252
+ exc_type = __Pyx_PyErr_CurrentExceptionType();
253
+ if (unlikely(exc_type)) {
254
+ if (!defval || unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
255
+ return NULL;
256
+ __Pyx_PyErr_Clear();
257
+ Py_INCREF(defval);
258
+ return defval;
259
+ }
260
+ if (defval) {
261
+ Py_INCREF(defval);
262
+ return defval;
263
+ }
264
+ __Pyx_PyErr_SetNone(PyExc_StopIteration);
265
+ return NULL;
266
+ }
267
+
268
+ static void __Pyx_PyIter_Next_ErrorNoIterator(PyObject *iterator) {
269
+ __Pyx_TypeName iterator_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(iterator));
270
+ PyErr_Format(PyExc_TypeError,
271
+ __Pyx_FMT_TYPENAME " object is not an iterator", iterator_type_name);
272
+ __Pyx_DECREF_TypeName(iterator_type_name);
273
+ }
274
+
275
+ // originally copied from Py3's builtin_next()
276
+ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) {
277
+ PyObject* next;
278
+ #if !CYTHON_COMPILING_IN_LIMITED_API
279
+ // We always do a quick slot check because calling PyIter_Check() is so wasteful.
280
+ iternextfunc iternext = __Pyx_PyObject_TryGetSlot(iterator, tp_iternext, iternextfunc);
281
+ if (likely(iternext)) {
282
+ next = iternext(iterator);
283
+ if (likely(next))
284
+ return next;
285
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
286
+ // If the reason for failure was "not implemented", we're done raising the appropriate exception.
287
+ if (unlikely(iternext == &_PyObject_NextNotImplemented))
288
+ return NULL;
289
+ #endif
290
+ } else if (CYTHON_USE_TYPE_SLOTS) {
291
+ // If CYTHON_USE_TYPE_SLOTS, then the slot was really not set and we don't have an iterable.
292
+ __Pyx_PyIter_Next_ErrorNoIterator(iterator);
293
+ return NULL;
294
+ } else
295
+ // Without CYTHON_USE_TYPE_SLOTS, don't trust "tp_iternext" and rely on PyIter_Check().
296
+ #endif
297
+ if (unlikely(!PyIter_Check(iterator))) {
298
+ __Pyx_PyIter_Next_ErrorNoIterator(iterator);
299
+ return NULL;
300
+ } else {
301
+ // We'll probably only end up here in the Limited API, where we'd call Python's "next()" now.
302
+ // If we have a default value, we don't need the StopIteration and can use PyIter_Next().
303
+ next = defval ? PyIter_Next(iterator) : __Pyx_PyIter_Next_Plain(iterator);
304
+ if (likely(next))
305
+ return next;
306
+ }
307
+ return __Pyx_PyIter_Next2Default(defval);
308
+ }
309
+ #endif
310
+
311
+ /////////////// IterFinish.proto ///////////////
312
+
313
+ static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/
314
+
315
+ /////////////// IterFinish ///////////////
316
+ //@requires: Exceptions.c::PyThreadStateGet
317
+ //@requires: Exceptions.c::PyErrFetchRestore
318
+
319
+ // When PyIter_Next(iter) has returned NULL in order to signal termination,
320
+ // this function does the right cleanup and returns 0 on success. If it
321
+ // detects an error that occurred in the iterator, it returns -1.
322
+
323
+ static CYTHON_INLINE int __Pyx_IterFinish(void) {
324
+ PyObject* exc_type;
325
+ __Pyx_PyThreadState_declare
326
+ __Pyx_PyThreadState_assign
327
+ exc_type = __Pyx_PyErr_CurrentExceptionType();
328
+ if (unlikely(exc_type)) {
329
+ if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
330
+ return -1;
331
+ __Pyx_PyErr_Clear();
332
+ return 0;
333
+ }
334
+ return 0;
335
+ }
336
+
337
+
338
+ /////////////// ObjectGetItem.proto ///////////////
339
+
340
+ #if CYTHON_USE_TYPE_SLOTS
341
+ static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject *key);/*proto*/
342
+ #else
343
+ #define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key)
344
+ #endif
345
+
346
+ /////////////// ObjectGetItem ///////////////
347
+ // //@requires: GetItemInt - added in IndexNode as it uses templating.
348
+ //@requires: PyObjectGetAttrStrNoError
349
+ //@requires: PyObjectCallOneArg
350
+
351
+ #if CYTHON_USE_TYPE_SLOTS
352
+ static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject *index) {
353
+ // Get element from sequence object `obj` at index `index`.
354
+ PyObject *runerr = NULL;
355
+ Py_ssize_t key_value;
356
+ key_value = __Pyx_PyIndex_AsSsize_t(index);
357
+ if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
358
+ return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
359
+ }
360
+
361
+ // Error handling code -- only manage OverflowError differently.
362
+ if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
363
+ __Pyx_TypeName index_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(index));
364
+ PyErr_Clear();
365
+ PyErr_Format(PyExc_IndexError,
366
+ "cannot fit '" __Pyx_FMT_TYPENAME "' into an index-sized integer", index_type_name);
367
+ __Pyx_DECREF_TypeName(index_type_name);
368
+ }
369
+ return NULL;
370
+ }
371
+
372
+ static PyObject *__Pyx_PyObject_GetItem_Slow(PyObject *obj, PyObject *key) {
373
+ __Pyx_TypeName obj_type_name;
374
+ // Handles less common slow-path checks for GetItem
375
+ if (likely(PyType_Check(obj))) {
376
+ PyObject *meth = __Pyx_PyObject_GetAttrStrNoError(obj, PYIDENT("__class_getitem__"));
377
+ if (!meth) {
378
+ PyErr_Clear();
379
+ } else {
380
+ PyObject *result = __Pyx_PyObject_CallOneArg(meth, key);
381
+ Py_DECREF(meth);
382
+ return result;
383
+ }
384
+ }
385
+
386
+ obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj));
387
+ PyErr_Format(PyExc_TypeError,
388
+ "'" __Pyx_FMT_TYPENAME "' object is not subscriptable", obj_type_name);
389
+ __Pyx_DECREF_TypeName(obj_type_name);
390
+ return NULL;
391
+ }
392
+
393
+ static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject *key) {
394
+ PyTypeObject *tp = Py_TYPE(obj);
395
+ PyMappingMethods *mm = tp->tp_as_mapping;
396
+ PySequenceMethods *sm = tp->tp_as_sequence;
397
+
398
+ if (likely(mm && mm->mp_subscript)) {
399
+ return mm->mp_subscript(obj, key);
400
+ }
401
+ if (likely(sm && sm->sq_item)) {
402
+ return __Pyx_PyObject_GetIndex(obj, key);
403
+ }
404
+ return __Pyx_PyObject_GetItem_Slow(obj, key);
405
+ }
406
+ #endif
407
+
408
+
409
+ /////////////// DictGetItem.proto ///////////////
410
+
411
+ #if !CYTHON_COMPILING_IN_PYPY
412
+ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);/*proto*/
413
+
414
+ #define __Pyx_PyObject_Dict_GetItem(obj, name) \
415
+ (likely(PyDict_CheckExact(obj)) ? \
416
+ __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
417
+
418
+ #else
419
+ #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
420
+ #define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name)
421
+ #endif
422
+
423
+ /////////////// DictGetItem ///////////////
424
+
425
+ #if !CYTHON_COMPILING_IN_PYPY
426
+ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
427
+ PyObject *value;
428
+ if (unlikely(__Pyx_PyDict_GetItemRef(d, key, &value) == 0)) { // no value, no error
429
+ if (unlikely(PyTuple_Check(key))) {
430
+ // CPython interprets tuples as separate arguments => must wrap them in another tuple.
431
+ PyObject* args = PyTuple_Pack(1, key);
432
+ if (likely(args)) {
433
+ PyErr_SetObject(PyExc_KeyError, args);
434
+ Py_DECREF(args);
435
+ }
436
+ } else {
437
+ // Avoid tuple packing if possible.
438
+ PyErr_SetObject(PyExc_KeyError, key);
439
+ }
440
+ }
441
+ return value;
442
+ }
443
+ #endif
444
+
445
+ /////////////// GetItemInt.proto ///////////////
446
+ //@substitute: tempita
447
+
448
+ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
449
+ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
450
+ __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
451
+ (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \
452
+ __Pyx_GetItemInt_Generic(o, to_py_func(i))))
453
+
454
+ {{for type in ['List', 'Tuple']}}
455
+ #define __Pyx_GetItemInt_{{type}}(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
456
+ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
457
+ __Pyx_GetItemInt_{{type}}_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
458
+ (PyErr_SetString(PyExc_IndexError, "{{ type.lower() }} index out of range"), (PyObject*)NULL))
459
+
460
+ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_{{type}}_Fast(PyObject *o, Py_ssize_t i,
461
+ int wraparound, int boundscheck);
462
+ {{endfor}}
463
+
464
+ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
465
+ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
466
+ int is_list, int wraparound, int boundscheck);
467
+
468
+ /////////////// GetItemInt ///////////////
469
+ //@substitute: tempita
470
+
471
+ static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
472
+ PyObject *r;
473
+ if (unlikely(!j)) return NULL;
474
+ r = PyObject_GetItem(o, j);
475
+ Py_DECREF(j);
476
+ return r;
477
+ }
478
+
479
+ {{for type in ['List', 'Tuple']}}
480
+ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_{{type}}_Fast(PyObject *o, Py_ssize_t i,
481
+ CYTHON_NCP_UNUSED int wraparound,
482
+ CYTHON_NCP_UNUSED int boundscheck) {
483
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS{{if type == 'List'}} && !CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS{{endif}}
484
+ Py_ssize_t wrapped_i = i;
485
+ if (wraparound & unlikely(i < 0)) {
486
+ wrapped_i += Py{{type}}_GET_SIZE(o);
487
+ }
488
+ if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, Py{{type}}_GET_SIZE(o)))) {
489
+ PyObject *r = Py{{type}}_GET_ITEM(o, wrapped_i);
490
+ Py_INCREF(r);
491
+ return r;
492
+ }
493
+ return __Pyx_GetItemInt_Generic(o, PyLong_FromSsize_t(i));
494
+ #else
495
+ return PySequence_GetItem(o, i);
496
+ #endif
497
+ }
498
+ {{endfor}}
499
+
500
+ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
501
+ CYTHON_NCP_UNUSED int wraparound,
502
+ CYTHON_NCP_UNUSED int boundscheck) {
503
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
504
+ if (is_list || PyList_CheckExact(o)) {
505
+ Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
506
+ if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
507
+ return __Pyx_PyList_GetItemRef(o, n);
508
+ }
509
+ }
510
+ else if (PyTuple_CheckExact(o)) {
511
+ Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
512
+ if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
513
+ PyObject *r = PyTuple_GET_ITEM(o, n);
514
+ Py_INCREF(r);
515
+ return r;
516
+ }
517
+ } else {
518
+ // inlined PySequence_GetItem() + special cased length overflow
519
+ PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping;
520
+ PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence;
521
+ if (mm && mm->mp_subscript) {
522
+ PyObject *r, *key = PyLong_FromSsize_t(i);
523
+ if (unlikely(!key)) return NULL;
524
+ r = mm->mp_subscript(o, key);
525
+ Py_DECREF(key);
526
+ return r;
527
+ }
528
+ if (likely(sm && sm->sq_item)) {
529
+ if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) {
530
+ Py_ssize_t l = sm->sq_length(o);
531
+ if (likely(l >= 0)) {
532
+ i += l;
533
+ } else {
534
+ // if length > max(Py_ssize_t), maybe the object can wrap around itself?
535
+ if (!PyErr_ExceptionMatches(PyExc_OverflowError))
536
+ return NULL;
537
+ PyErr_Clear();
538
+ }
539
+ }
540
+ return sm->sq_item(o, i);
541
+ }
542
+ }
543
+ #else
544
+ // PySequence_GetItem behaves differently to PyObject_GetItem for i<0
545
+ // and possibly some other cases so can't generally be substituted
546
+ if (is_list || !PyMapping_Check(o)) {
547
+ return PySequence_GetItem(o, i);
548
+ }
549
+ #endif
550
+ return __Pyx_GetItemInt_Generic(o, PyLong_FromSsize_t(i));
551
+ }
552
+
553
+ /////////////// SetItemInt.proto ///////////////
554
+
555
+ #define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
556
+ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
557
+ __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) : \
558
+ (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
559
+ __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
560
+
561
+ static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
562
+ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
563
+ int is_list, int wraparound, int boundscheck);
564
+
565
+ /////////////// SetItemInt ///////////////
566
+
567
+ static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
568
+ int r;
569
+ if (unlikely(!j)) return -1;
570
+ r = PyObject_SetItem(o, j, v);
571
+ Py_DECREF(j);
572
+ return r;
573
+ }
574
+
575
+ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
576
+ CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
577
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
578
+ if (is_list || PyList_CheckExact(o)) {
579
+ Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
580
+ if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) {
581
+ Py_INCREF(v);
582
+ #if CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
583
+ PyList_SetItem(o, n, v);
584
+ #else
585
+ PyObject* old = PyList_GET_ITEM(o, n);
586
+ PyList_SET_ITEM(o, n, v);
587
+ Py_DECREF(old);
588
+ #endif
589
+ return 1;
590
+ }
591
+ } else {
592
+ // inlined PySequence_SetItem() + special cased length overflow
593
+ PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping;
594
+ PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence;
595
+ if (mm && mm->mp_ass_subscript) {
596
+ int r;
597
+ PyObject *key = PyLong_FromSsize_t(i);
598
+ if (unlikely(!key)) return -1;
599
+ r = mm->mp_ass_subscript(o, key, v);
600
+ Py_DECREF(key);
601
+ return r;
602
+ }
603
+ if (likely(sm && sm->sq_ass_item)) {
604
+ if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) {
605
+ Py_ssize_t l = sm->sq_length(o);
606
+ if (likely(l >= 0)) {
607
+ i += l;
608
+ } else {
609
+ // if length > max(Py_ssize_t), maybe the object can wrap around itself?
610
+ if (!PyErr_ExceptionMatches(PyExc_OverflowError))
611
+ return -1;
612
+ PyErr_Clear();
613
+ }
614
+ }
615
+ return sm->sq_ass_item(o, i, v);
616
+ }
617
+ }
618
+ #else
619
+ // PySequence_SetItem behaves differently to PyObject_SetItem for i<0
620
+ // and possibly some other cases so can't generally be substituted
621
+ if (is_list || !PyMapping_Check(o))
622
+ {
623
+ return PySequence_SetItem(o, i, v);
624
+ }
625
+ #endif
626
+ return __Pyx_SetItemInt_Generic(o, PyLong_FromSsize_t(i), v);
627
+ }
628
+
629
+
630
+ /////////////// DelItemInt.proto ///////////////
631
+
632
+ #define __Pyx_DelItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
633
+ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
634
+ __Pyx_DelItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound) : \
635
+ (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
636
+ __Pyx_DelItem_Generic(o, to_py_func(i))))
637
+
638
+ static int __Pyx_DelItem_Generic(PyObject *o, PyObject *j);
639
+ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
640
+ int is_list, int wraparound);
641
+
642
+ /////////////// DelItemInt ///////////////
643
+
644
+ static int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
645
+ int r;
646
+ if (unlikely(!j)) return -1;
647
+ r = PyObject_DelItem(o, j);
648
+ Py_DECREF(j);
649
+ return r;
650
+ }
651
+
652
+ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
653
+ int is_list, CYTHON_NCP_UNUSED int wraparound) {
654
+ #if !CYTHON_USE_TYPE_SLOTS
655
+ // PySequence_DelItem behaves differently to PyObject_DelItem for i<0
656
+ // and possibly some other cases so can't generally be substituted
657
+ if (is_list || !PyMapping_Check(o)) {
658
+ return PySequence_DelItem(o, i);
659
+ }
660
+ #else
661
+ // inlined PySequence_DelItem() + special cased length overflow
662
+ PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping;
663
+ PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence;
664
+ if ((!is_list) && mm && mm->mp_ass_subscript) {
665
+ PyObject *key = PyLong_FromSsize_t(i);
666
+ return likely(key) ? mm->mp_ass_subscript(o, key, (PyObject *)NULL) : -1;
667
+ }
668
+ if (likely(sm && sm->sq_ass_item)) {
669
+ if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) {
670
+ Py_ssize_t l = sm->sq_length(o);
671
+ if (likely(l >= 0)) {
672
+ i += l;
673
+ } else {
674
+ // if length > max(Py_ssize_t), maybe the object can wrap around itself?
675
+ if (!PyErr_ExceptionMatches(PyExc_OverflowError))
676
+ return -1;
677
+ PyErr_Clear();
678
+ }
679
+ }
680
+ return sm->sq_ass_item(o, i, (PyObject *)NULL);
681
+ }
682
+ #endif
683
+ return __Pyx_DelItem_Generic(o, PyLong_FromSsize_t(i));
684
+ }
685
+
686
+
687
+ /////////////// SliceObject.proto ///////////////
688
+
689
+ // we pass pointer addresses to show the C compiler what is NULL and what isn't
690
+ {{if access == 'Get'}}
691
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
692
+ PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
693
+ PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
694
+ int has_cstart, int has_cstop, int wraparound);
695
+ {{else}}
696
+ #define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound) \
697
+ __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)
698
+
699
+ // we pass pointer addresses to show the C compiler what is NULL and what isn't
700
+ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
701
+ PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop,
702
+ PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
703
+ int has_cstart, int has_cstop, int wraparound);
704
+ {{endif}}
705
+
706
+ /////////////// SliceObject ///////////////
707
+
708
+ {{if access == 'Get'}}
709
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
710
+ {{else}}
711
+ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value,
712
+ {{endif}}
713
+ Py_ssize_t cstart, Py_ssize_t cstop,
714
+ PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
715
+ int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
716
+ __Pyx_TypeName obj_type_name;
717
+ #if CYTHON_USE_TYPE_SLOTS
718
+ PyMappingMethods* mp = Py_TYPE(obj)->tp_as_mapping;
719
+ {{if access == 'Get'}}
720
+ if (likely(mp && mp->mp_subscript))
721
+ {{else}}
722
+ if (likely(mp && mp->mp_ass_subscript))
723
+ {{endif}}
724
+ #endif
725
+ {
726
+ {{if access == 'Get'}}PyObject*{{else}}int{{endif}} result;
727
+ PyObject *py_slice, *py_start, *py_stop;
728
+ if (_py_slice) {
729
+ py_slice = *_py_slice;
730
+ } else {
731
+ PyObject* owned_start = NULL;
732
+ PyObject* owned_stop = NULL;
733
+ if (_py_start) {
734
+ py_start = *_py_start;
735
+ } else {
736
+ if (has_cstart) {
737
+ owned_start = py_start = PyLong_FromSsize_t(cstart);
738
+ if (unlikely(!py_start)) goto bad;
739
+ } else
740
+ py_start = Py_None;
741
+ }
742
+ if (_py_stop) {
743
+ py_stop = *_py_stop;
744
+ } else {
745
+ if (has_cstop) {
746
+ owned_stop = py_stop = PyLong_FromSsize_t(cstop);
747
+ if (unlikely(!py_stop)) {
748
+ Py_XDECREF(owned_start);
749
+ goto bad;
750
+ }
751
+ } else
752
+ py_stop = Py_None;
753
+ }
754
+ py_slice = PySlice_New(py_start, py_stop, Py_None);
755
+ Py_XDECREF(owned_start);
756
+ Py_XDECREF(owned_stop);
757
+ if (unlikely(!py_slice)) goto bad;
758
+ }
759
+ #if CYTHON_USE_TYPE_SLOTS
760
+ {{if access == 'Get'}}
761
+ result = mp->mp_subscript(obj, py_slice);
762
+ #else
763
+ result = PyObject_GetItem(obj, py_slice);
764
+ {{else}}
765
+ result = mp->mp_ass_subscript(obj, py_slice, value);
766
+ #else
767
+ result = value ? PyObject_SetItem(obj, py_slice, value) : PyObject_DelItem(obj, py_slice);
768
+ {{endif}}
769
+ #endif
770
+ if (!_py_slice) {
771
+ Py_DECREF(py_slice);
772
+ }
773
+ return result;
774
+ }
775
+ obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj));
776
+ PyErr_Format(PyExc_TypeError,
777
+ {{if access == 'Get'}}
778
+ "'" __Pyx_FMT_TYPENAME "' object is unsliceable", obj_type_name);
779
+ {{else}}
780
+ "'" __Pyx_FMT_TYPENAME "' object does not support slice %.10s",
781
+ obj_type_name, value ? "assignment" : "deletion");
782
+ {{endif}}
783
+ __Pyx_DECREF_TypeName(obj_type_name);
784
+
785
+ bad:
786
+ return {{if access == 'Get'}}NULL{{else}}-1{{endif}};
787
+ }
788
+
789
+
790
+ /////////////// TupleAndListFromArray.proto ///////////////
791
+
792
+ #if CYTHON_COMPILING_IN_CPYTHON
793
+ static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n);
794
+ #endif
795
+ #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_METH_FASTCALL
796
+ static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n);
797
+ #endif
798
+
799
+
800
+ /////////////// TupleAndListFromArray ///////////////
801
+
802
+ #if !CYTHON_COMPILING_IN_CPYTHON && CYTHON_METH_FASTCALL
803
+ static CYTHON_INLINE PyObject *
804
+ __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
805
+ {
806
+ PyObject *res;
807
+ Py_ssize_t i;
808
+ if (n <= 0) {
809
+ return __Pyx_NewRef(EMPTY(tuple));
810
+ }
811
+ res = PyTuple_New(n);
812
+ if (unlikely(res == NULL)) return NULL;
813
+ for (i = 0; i < n; i++) {
814
+ if (unlikely(__Pyx_PyTuple_SET_ITEM(res, i, src[i]) < 0)) {
815
+ Py_DECREF(res);
816
+ return NULL;
817
+ }
818
+ Py_INCREF(src[i]);
819
+ }
820
+ return res;
821
+ }
822
+ #elif CYTHON_COMPILING_IN_CPYTHON
823
+ static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
824
+ PyObject *v;
825
+ Py_ssize_t i;
826
+ for (i = 0; i < length; i++) {
827
+ v = dest[i] = src[i];
828
+ Py_INCREF(v);
829
+ }
830
+ }
831
+
832
+ static CYTHON_INLINE PyObject *
833
+ __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
834
+ {
835
+ PyObject *res;
836
+ if (n <= 0) {
837
+ return __Pyx_NewRef(EMPTY(tuple));
838
+ }
839
+ res = PyTuple_New(n);
840
+ if (unlikely(res == NULL)) return NULL;
841
+ __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n);
842
+ return res;
843
+ }
844
+
845
+ static CYTHON_INLINE PyObject *
846
+ __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n)
847
+ {
848
+ PyObject *res;
849
+ if (n <= 0) {
850
+ return PyList_New(0);
851
+ }
852
+ res = PyList_New(n);
853
+ if (unlikely(res == NULL)) return NULL;
854
+ __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n);
855
+ return res;
856
+ }
857
+ #endif
858
+
859
+
860
+ /////////////// SliceTupleAndList.proto ///////////////
861
+
862
+ #if CYTHON_COMPILING_IN_CPYTHON
863
+ static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
864
+ static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
865
+ #else
866
+ #define __Pyx_PyList_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop)
867
+ #define __Pyx_PyTuple_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop)
868
+ #endif
869
+
870
+ /////////////// SliceTupleAndList ///////////////
871
+ //@requires: TupleAndListFromArray
872
+ //@requires: ModuleSetupCode.c::CriticalSections
873
+
874
+ #if CYTHON_COMPILING_IN_CPYTHON
875
+ static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
876
+ Py_ssize_t start = *_start, stop = *_stop, length = *_length;
877
+ if (start < 0) {
878
+ start += length;
879
+ if (start < 0)
880
+ start = 0;
881
+ }
882
+
883
+ if (stop < 0)
884
+ stop += length;
885
+ else if (stop > length)
886
+ stop = length;
887
+
888
+ *_length = stop - start;
889
+ *_start = start;
890
+ *_stop = stop;
891
+ }
892
+
893
+ static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(
894
+ PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
895
+ Py_ssize_t length = PyTuple_GET_SIZE(src);
896
+ __Pyx_crop_slice(&start, &stop, &length);
897
+ return __Pyx_PyTuple_FromArray(((PyTupleObject*)src)->ob_item + start, length);
898
+ }
899
+
900
+ static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice_locked(
901
+ PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
902
+ Py_ssize_t length = PyList_GET_SIZE(src);
903
+ __Pyx_crop_slice(&start, &stop, &length);
904
+ if (length <= 0) {
905
+ // Avoid undefined behaviour when accessing `ob_item` of an empty list.
906
+ return PyList_New(0);
907
+ }
908
+ return __Pyx_PyList_FromArray(((PyListObject*)src)->ob_item + start, length);
909
+ }
910
+
911
+ static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(
912
+ PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
913
+ PyObject *result;
914
+ __Pyx_BEGIN_CRITICAL_SECTION(src);
915
+ result = __Pyx_PyList_GetSlice_locked(src, start, stop);
916
+ __Pyx_END_CRITICAL_SECTION();
917
+ return result;
918
+ }
919
+ #endif // CYTHON_COMPILING_IN_CPYTHON
920
+
921
+
922
+ /////////////// CalculateMetaclass.proto ///////////////
923
+
924
+ static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);
925
+
926
+ /////////////// CalculateMetaclass ///////////////
927
+
928
+ static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
929
+ Py_ssize_t i, nbases;
930
+ #if CYTHON_ASSUME_SAFE_SIZE
931
+ nbases = PyTuple_GET_SIZE(bases);
932
+ #else
933
+ nbases = PyTuple_Size(bases);
934
+ if (nbases < 0) return NULL;
935
+ #endif
936
+ for (i=0; i < nbases; i++) {
937
+ PyTypeObject *tmptype;
938
+ #if CYTHON_ASSUME_SAFE_MACROS
939
+ PyObject *tmp = PyTuple_GET_ITEM(bases, i);
940
+ #else
941
+ PyObject *tmp = PyTuple_GetItem(bases, i);
942
+ if (!tmp) return NULL;
943
+ #endif
944
+ tmptype = Py_TYPE(tmp);
945
+ if (!metaclass) {
946
+ metaclass = tmptype;
947
+ continue;
948
+ }
949
+ if (PyType_IsSubtype(metaclass, tmptype))
950
+ continue;
951
+ if (PyType_IsSubtype(tmptype, metaclass)) {
952
+ metaclass = tmptype;
953
+ continue;
954
+ }
955
+ // else:
956
+ PyErr_SetString(PyExc_TypeError,
957
+ "metaclass conflict: "
958
+ "the metaclass of a derived class "
959
+ "must be a (non-strict) subclass "
960
+ "of the metaclasses of all its bases");
961
+ return NULL;
962
+ }
963
+ if (!metaclass) {
964
+ metaclass = &PyType_Type;
965
+ }
966
+ // make owned reference
967
+ Py_INCREF((PyObject*) metaclass);
968
+ return (PyObject*) metaclass;
969
+ }
970
+
971
+
972
+ /////////////// FindInheritedMetaclass.proto ///////////////
973
+
974
+ static PyObject *__Pyx_FindInheritedMetaclass(PyObject *bases); /*proto*/
975
+
976
+ /////////////// FindInheritedMetaclass ///////////////
977
+ //@requires: PyObjectGetAttrStr
978
+ //@requires: CalculateMetaclass
979
+
980
+ static PyObject *__Pyx_FindInheritedMetaclass(PyObject *bases) {
981
+ PyObject *metaclass;
982
+ #if CYTHON_ASSUME_SAFE_SIZE
983
+ if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0)
984
+ #else
985
+ Py_ssize_t tuple_size = PyTuple_Check(bases) ? PyTuple_Size(bases) : 0;
986
+ if (unlikely(tuple_size < 0)) return NULL;
987
+ if (tuple_size > 0)
988
+ #endif
989
+ {
990
+ PyTypeObject *metatype;
991
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
992
+ PyObject *base = PyTuple_GET_ITEM(bases, 0);
993
+ #else
994
+ PyObject *base = __Pyx_PySequence_ITEM(bases, 0);
995
+ #endif
996
+ metatype = Py_TYPE(base);
997
+ metaclass = __Pyx_CalculateMetaclass(metatype, bases);
998
+ #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
999
+ Py_DECREF(base);
1000
+ #endif
1001
+ } else {
1002
+ // no bases => use default metaclass
1003
+ metaclass = (PyObject *) &PyType_Type;
1004
+ Py_INCREF(metaclass);
1005
+ }
1006
+ return metaclass;
1007
+ }
1008
+
1009
+ /////////////// Py3MetaclassGet.proto ///////////////
1010
+
1011
+ static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw); /*proto*/
1012
+
1013
+ /////////////// Py3MetaclassGet ///////////////
1014
+ //@requires: FindInheritedMetaclass
1015
+ //@requires: CalculateMetaclass
1016
+
1017
+ static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw) {
1018
+ PyObject *metaclass = mkw ? __Pyx_PyDict_GetItemStr(mkw, PYIDENT("metaclass")) : NULL;
1019
+ if (metaclass) {
1020
+ Py_INCREF(metaclass);
1021
+ if (PyDict_DelItem(mkw, PYIDENT("metaclass")) < 0) {
1022
+ Py_DECREF(metaclass);
1023
+ return NULL;
1024
+ }
1025
+ if (PyType_Check(metaclass)) {
1026
+ PyObject* orig = metaclass;
1027
+ metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
1028
+ Py_DECREF(orig);
1029
+ }
1030
+ return metaclass;
1031
+ }
1032
+ return __Pyx_FindInheritedMetaclass(bases);
1033
+ }
1034
+
1035
+ /////////////// CreateClass.proto ///////////////
1036
+
1037
+ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
1038
+ PyObject *qualname, PyObject *modname); /*proto*/
1039
+
1040
+ /////////////// CreateClass ///////////////
1041
+ //@requires: FindInheritedMetaclass
1042
+ //@requires: CalculateMetaclass
1043
+
1044
+ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
1045
+ PyObject *qualname, PyObject *modname) {
1046
+ PyObject *result;
1047
+ PyObject *metaclass;
1048
+
1049
+ if (unlikely(PyDict_SetItem(dict, PYIDENT("__module__"), modname) < 0))
1050
+ return NULL;
1051
+ if (unlikely(PyDict_SetItem(dict, PYIDENT("__qualname__"), qualname) < 0))
1052
+ return NULL;
1053
+
1054
+ /* Python2 __metaclass__ */
1055
+ metaclass = __Pyx_PyDict_GetItemStr(dict, PYIDENT("__metaclass__"));
1056
+ if (metaclass) {
1057
+ Py_INCREF(metaclass);
1058
+ if (PyType_Check(metaclass)) {
1059
+ PyObject* orig = metaclass;
1060
+ metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
1061
+ Py_DECREF(orig);
1062
+ }
1063
+ } else {
1064
+ metaclass = __Pyx_FindInheritedMetaclass(bases);
1065
+ }
1066
+ if (unlikely(!metaclass))
1067
+ return NULL;
1068
+ result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
1069
+ Py_DECREF(metaclass);
1070
+ return result;
1071
+ }
1072
+
1073
+ /////////////// Py3UpdateBases.proto ///////////////
1074
+
1075
+ static PyObject* __Pyx_PEP560_update_bases(PyObject *bases); /* proto */
1076
+
1077
+ /////////////// Py3UpdateBases /////////////////////
1078
+ //@requires: PyObjectCallOneArg
1079
+ //@requires: PyObjectGetAttrStrNoError
1080
+
1081
+ /* Shamelessly adapted from cpython/bltinmodule.c update_bases */
1082
+ static PyObject*
1083
+ __Pyx_PEP560_update_bases(PyObject *bases)
1084
+ {
1085
+ Py_ssize_t i, j, size_bases;
1086
+ PyObject *base = NULL, *meth, *new_base, *result, *new_bases = NULL;
1087
+ /*assert(PyTuple_Check(bases));*/
1088
+
1089
+ #if CYTHON_ASSUME_SAFE_SIZE
1090
+ size_bases = PyTuple_GET_SIZE(bases);
1091
+ #else
1092
+ size_bases = PyTuple_Size(bases);
1093
+ if (size_bases < 0) return NULL;
1094
+ #endif
1095
+ for (i = 0; i < size_bases; i++) {
1096
+ // original code in CPython: base = args[i];
1097
+ #if CYTHON_AVOID_BORROWED_REFS
1098
+ Py_CLEAR(base);
1099
+ #endif
1100
+ #if CYTHON_ASSUME_SAFE_MACROS
1101
+ base = PyTuple_GET_ITEM(bases, i);
1102
+ #else
1103
+ base = PyTuple_GetItem(bases, i);
1104
+ if (!base) goto error;
1105
+ #endif
1106
+ #if CYTHON_AVOID_BORROWED_REFS
1107
+ Py_INCREF(base);
1108
+ #endif
1109
+ if (PyType_Check(base)) {
1110
+ if (new_bases) {
1111
+ // If we already have made a replacement, then we append every normal base,
1112
+ // otherwise just skip it.
1113
+ if (PyList_Append(new_bases, base) < 0) {
1114
+ goto error;
1115
+ }
1116
+ }
1117
+ continue;
1118
+ }
1119
+ // original code in CPython:
1120
+ // if (_PyObject_LookupAttrId(base, &PyId___mro_entries__, &meth) < 0) {
1121
+ meth = __Pyx_PyObject_GetAttrStrNoError(base, PYIDENT("__mro_entries__"));
1122
+ if (!meth && PyErr_Occurred()) {
1123
+ goto error;
1124
+ }
1125
+ if (!meth) {
1126
+ if (new_bases) {
1127
+ if (PyList_Append(new_bases, base) < 0) {
1128
+ goto error;
1129
+ }
1130
+ }
1131
+ continue;
1132
+ }
1133
+ new_base = __Pyx_PyObject_CallOneArg(meth, bases);
1134
+ Py_DECREF(meth);
1135
+ if (!new_base) {
1136
+ goto error;
1137
+ }
1138
+ if (!PyTuple_Check(new_base)) {
1139
+ PyErr_SetString(PyExc_TypeError,
1140
+ "__mro_entries__ must return a tuple");
1141
+ Py_DECREF(new_base);
1142
+ goto error;
1143
+ }
1144
+ if (!new_bases) {
1145
+ // If this is a first successful replacement, create new_bases list and
1146
+ // copy previously encountered bases.
1147
+ if (!(new_bases = PyList_New(i))) {
1148
+ goto error;
1149
+ }
1150
+ for (j = 0; j < i; j++) {
1151
+ // original code in CPython: base = args[j];
1152
+ // We use a different name here to keep refcounting separate from base
1153
+ PyObject *base_from_list;
1154
+ #if CYTHON_ASSUME_SAFE_MACROS
1155
+ base_from_list = PyTuple_GET_ITEM(bases, j);
1156
+ PyList_SET_ITEM(new_bases, j, base_from_list);
1157
+ Py_INCREF(base_from_list);
1158
+ #else
1159
+ base_from_list = PyTuple_GetItem(bases, j);
1160
+ if (!base_from_list) goto error;
1161
+ Py_INCREF(base_from_list);
1162
+ if (PyList_SetItem(new_bases, j, base_from_list) < 0) goto error;
1163
+ #endif
1164
+ }
1165
+ }
1166
+ #if CYTHON_ASSUME_SAFE_SIZE
1167
+ j = PyList_GET_SIZE(new_bases);
1168
+ #else
1169
+ j = PyList_Size(new_bases);
1170
+ if (j < 0) goto error;
1171
+ #endif
1172
+ if (PyList_SetSlice(new_bases, j, j, new_base) < 0) {
1173
+ goto error;
1174
+ }
1175
+ Py_DECREF(new_base);
1176
+ }
1177
+ if (!new_bases) {
1178
+ // unlike the CPython implementation, always return a new reference
1179
+ Py_INCREF(bases);
1180
+ return bases;
1181
+ }
1182
+ result = PyList_AsTuple(new_bases);
1183
+ Py_DECREF(new_bases);
1184
+ #if CYTHON_AVOID_BORROWED_REFS
1185
+ Py_XDECREF(base);
1186
+ #endif
1187
+ return result;
1188
+
1189
+ error:
1190
+ Py_XDECREF(new_bases);
1191
+ #if CYTHON_AVOID_BORROWED_REFS
1192
+ Py_XDECREF(base);
1193
+ #endif
1194
+ return NULL;
1195
+ }
1196
+
1197
+ /////////////// Py3ClassCreate.proto ///////////////
1198
+
1199
+ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
1200
+ PyObject *mkw, PyObject *modname, PyObject *doc); /*proto*/
1201
+ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
1202
+ PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); /*proto*/
1203
+
1204
+ /////////////// Py3ClassCreate ///////////////
1205
+ //@requires: PyObjectGetAttrStrNoError
1206
+ //@requires: CalculateMetaclass
1207
+ //@requires: PyObjectFastCall
1208
+ //@requires: PyObjectCall2Args
1209
+ //@requires: PyObjectLookupSpecial
1210
+ // only in fallback code:
1211
+
1212
+ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
1213
+ PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
1214
+ PyObject *ns;
1215
+ if (metaclass) {
1216
+ PyObject *prep = __Pyx_PyObject_GetAttrStrNoError(metaclass, PYIDENT("__prepare__"));
1217
+ if (prep) {
1218
+ PyObject *pargs[3] = {NULL, name, bases};
1219
+ ns = __Pyx_PyObject_FastCallDict(prep, pargs+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, mkw);
1220
+ Py_DECREF(prep);
1221
+ } else {
1222
+ if (unlikely(PyErr_Occurred()))
1223
+ return NULL;
1224
+ ns = PyDict_New();
1225
+ }
1226
+ } else {
1227
+ ns = PyDict_New();
1228
+ }
1229
+
1230
+ if (unlikely(!ns))
1231
+ return NULL;
1232
+
1233
+ /* Required here to emulate assignment order */
1234
+ if (unlikely(PyObject_SetItem(ns, PYIDENT("__module__"), modname) < 0)) goto bad;
1235
+ if (unlikely(PyObject_SetItem(ns, PYIDENT("__qualname__"), qualname) < 0)) goto bad;
1236
+ if (unlikely(doc && PyObject_SetItem(ns, PYIDENT("__doc__"), doc) < 0)) goto bad;
1237
+ return ns;
1238
+ bad:
1239
+ Py_DECREF(ns);
1240
+ return NULL;
1241
+ }
1242
+
1243
+ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
1244
+ PyObject *dict, PyObject *mkw,
1245
+ int calculate_metaclass, int allow_py2_metaclass) {
1246
+ PyObject *result;
1247
+ PyObject *owned_metaclass = NULL;
1248
+ PyObject *margs[4] = {NULL, name, bases, dict};
1249
+ if (allow_py2_metaclass) {
1250
+ /* honour Python2 __metaclass__ for backward compatibility */
1251
+ owned_metaclass = PyObject_GetItem(dict, PYIDENT("__metaclass__"));
1252
+ if (owned_metaclass) {
1253
+ metaclass = owned_metaclass;
1254
+ } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
1255
+ PyErr_Clear();
1256
+ } else {
1257
+ return NULL;
1258
+ }
1259
+ }
1260
+ if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
1261
+ metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
1262
+ Py_XDECREF(owned_metaclass);
1263
+ if (unlikely(!metaclass))
1264
+ return NULL;
1265
+ owned_metaclass = metaclass;
1266
+ }
1267
+ result = __Pyx_PyObject_FastCallDict(metaclass, margs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, mkw);
1268
+ Py_XDECREF(owned_metaclass);
1269
+ return result;
1270
+ }
1271
+
1272
+ /////////////// ExtTypeTest.proto ///////////////
1273
+
1274
+ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
1275
+
1276
+ /////////////// ExtTypeTest ///////////////
1277
+
1278
+ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
1279
+ __Pyx_TypeName obj_type_name;
1280
+ __Pyx_TypeName type_name;
1281
+ if (unlikely(!type)) {
1282
+ PyErr_SetString(PyExc_SystemError, "Missing type object");
1283
+ return 0;
1284
+ }
1285
+ if (likely(__Pyx_TypeCheck(obj, type)))
1286
+ return 1;
1287
+ obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj));
1288
+ type_name = __Pyx_PyType_GetFullyQualifiedName(type);
1289
+ PyErr_Format(PyExc_TypeError,
1290
+ "Cannot convert " __Pyx_FMT_TYPENAME " to " __Pyx_FMT_TYPENAME,
1291
+ obj_type_name, type_name);
1292
+ __Pyx_DECREF_TypeName(obj_type_name);
1293
+ __Pyx_DECREF_TypeName(type_name);
1294
+ return 0;
1295
+ }
1296
+
1297
+ /////////////// CallableCheck.proto ///////////////
1298
+
1299
+ #if CYTHON_USE_TYPE_SLOTS
1300
+ #define __Pyx_PyCallable_Check(obj) (Py_TYPE(obj)->tp_call != NULL)
1301
+ #else
1302
+ #define __Pyx_PyCallable_Check(obj) PyCallable_Check(obj)
1303
+ #endif
1304
+
1305
+ /////////////// PyDictContains.proto ///////////////
1306
+
1307
+ static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
1308
+ int result = PyDict_Contains(dict, item);
1309
+ return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
1310
+ }
1311
+
1312
+ /////////////// PySetContains.proto ///////////////
1313
+
1314
+ static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq); /* proto */
1315
+
1316
+ /////////////// PySetContains ///////////////
1317
+ //@requires: Builtins.c::pyfrozenset_new
1318
+
1319
+ static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) {
1320
+ int result = -1;
1321
+ if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) {
1322
+ /* Convert key to frozenset */
1323
+ PyObject *tmpkey;
1324
+ PyErr_Clear();
1325
+ tmpkey = __Pyx_PyFrozenSet_New(key);
1326
+ if (tmpkey != NULL) {
1327
+ result = PySet_Contains(set, tmpkey);
1328
+ Py_DECREF(tmpkey);
1329
+ }
1330
+ }
1331
+ return result;
1332
+ }
1333
+
1334
+ static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) {
1335
+ int result = PySet_Contains(set, key);
1336
+
1337
+ if (unlikely(result < 0)) {
1338
+ result = __Pyx_PySet_ContainsUnhashable(set, key);
1339
+ }
1340
+ return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
1341
+ }
1342
+
1343
+ /////////////// PySequenceContains.proto ///////////////
1344
+
1345
+ static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
1346
+ int result = PySequence_Contains(seq, item);
1347
+ return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
1348
+ }
1349
+
1350
+ /////////////// PyBoolOrNullFromLong.proto ///////////////
1351
+
1352
+ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
1353
+ return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
1354
+ }
1355
+
1356
+ /////////////// GetBuiltinName.proto ///////////////
1357
+
1358
+ static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/
1359
+
1360
+ /////////////// GetBuiltinName ///////////////
1361
+ //@requires: PyObjectGetAttrStrNoError
1362
+
1363
+ static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
1364
+ PyObject* result = __Pyx_PyObject_GetAttrStrNoError(NAMED_CGLOBAL(builtins_cname), name);
1365
+ if (unlikely(!result) && !PyErr_Occurred()) {
1366
+ PyErr_Format(PyExc_NameError,
1367
+ "name '%U' is not defined", name);
1368
+ }
1369
+ return result;
1370
+ }
1371
+
1372
+ /////////////// GetNameInClass.proto ///////////////
1373
+
1374
+ #define __Pyx_GetNameInClass(var, nmspace, name) (var) = __Pyx__GetNameInClass(nmspace, name)
1375
+ static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name); /*proto*/
1376
+
1377
+ /////////////// GetNameInClass ///////////////
1378
+ //@requires: GetModuleGlobalName
1379
+
1380
+ static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
1381
+ PyObject *result;
1382
+ PyObject *dict;
1383
+ assert(PyType_Check(nmspace));
1384
+ #if CYTHON_USE_TYPE_SLOTS
1385
+ dict = ((PyTypeObject*)nmspace)->tp_dict;
1386
+ Py_XINCREF(dict);
1387
+ #else
1388
+ dict = PyObject_GetAttr(nmspace, PYIDENT("__dict__"));
1389
+ #endif
1390
+ if (likely(dict)) {
1391
+ result = PyObject_GetItem(dict, name);
1392
+ Py_DECREF(dict);
1393
+ if (result) {
1394
+ return result;
1395
+ }
1396
+ }
1397
+ PyErr_Clear();
1398
+ __Pyx_GetModuleGlobalNameUncached(result, name);
1399
+ return result;
1400
+ }
1401
+
1402
+
1403
+ /////////////// SetNameInClass.proto ///////////////
1404
+
1405
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
1406
+ // Identifier names are always interned and have a pre-calculated hash value.
1407
+ #define __Pyx_SetNameInClass(ns, name, value) \
1408
+ (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value))
1409
+ #elif CYTHON_COMPILING_IN_CPYTHON
1410
+ #define __Pyx_SetNameInClass(ns, name, value) \
1411
+ (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value))
1412
+ #else
1413
+ #define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value)
1414
+ #endif
1415
+
1416
+ /////////////// SetNewInClass.proto ///////////////
1417
+
1418
+ static int __Pyx_SetNewInClass(PyObject *ns, PyObject *name, PyObject *value);
1419
+
1420
+ /////////////// SetNewInClass ///////////////
1421
+ //@requires: SetNameInClass
1422
+
1423
+ // Special-case setting __new__: if it's a Cython function, wrap it in a
1424
+ // staticmethod. This is similar to what Python does for a Python function
1425
+ // called __new__.
1426
+ static int __Pyx_SetNewInClass(PyObject *ns, PyObject *name, PyObject *value) {
1427
+ #ifdef __Pyx_CyFunction_USED
1428
+ int ret;
1429
+ if (__Pyx_CyFunction_Check(value)) {
1430
+ PyObject *staticnew;
1431
+ #if !CYTHON_COMPILING_IN_LIMITED_API
1432
+ staticnew = PyStaticMethod_New(value);
1433
+ #else
1434
+ PyObject *builtins, *staticmethod_str, *staticmethod;
1435
+ builtins = PyEval_GetBuiltins(); // borrowed
1436
+ if (!builtins) return -1;
1437
+ staticmethod_str = PyUnicode_FromStringAndSize("staticmethod", 12);
1438
+ if (!staticmethod_str) return -1;
1439
+ staticmethod = PyObject_GetItem(builtins, staticmethod_str);
1440
+ Py_DECREF(staticmethod_str);
1441
+ if (!staticmethod) return -1;
1442
+ staticnew = PyObject_CallFunctionObjArgs(staticmethod, value, NULL);
1443
+ Py_DECREF(staticmethod);
1444
+ #endif
1445
+ if (unlikely(!staticnew)) return -1;
1446
+ ret = __Pyx_SetNameInClass(ns, name, staticnew);
1447
+ Py_DECREF(staticnew);
1448
+ return ret;
1449
+ }
1450
+ #endif
1451
+ return __Pyx_SetNameInClass(ns, name, value);
1452
+ }
1453
+
1454
+
1455
+ /////////////// GetModuleGlobalName.proto ///////////////
1456
+ //@requires: PyDictVersioning
1457
+
1458
+ #if CYTHON_USE_DICT_VERSIONS
1459
+ #define __Pyx_GetModuleGlobalName(var, name) do { \
1460
+ static PY_UINT64_T __pyx_dict_version = 0; \
1461
+ static PyObject *__pyx_dict_cached_value = NULL; \
1462
+ (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(NAMED_CGLOBAL(moddict_cname)))) ? \
1463
+ (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) : \
1464
+ __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value); \
1465
+ } while(0)
1466
+ #define __Pyx_GetModuleGlobalNameUncached(var, name) do { \
1467
+ PY_UINT64_T __pyx_dict_version; \
1468
+ PyObject *__pyx_dict_cached_value; \
1469
+ (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value); \
1470
+ } while(0)
1471
+ static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); /*proto*/
1472
+ #else
1473
+ #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name)
1474
+ #define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name)
1475
+ static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); /*proto*/
1476
+ #endif
1477
+
1478
+
1479
+ /////////////// GetModuleGlobalName ///////////////
1480
+ //@requires: GetBuiltinName
1481
+ //@substitute: naming
1482
+
1483
+ #if CYTHON_USE_DICT_VERSIONS
1484
+ static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
1485
+ #else
1486
+ static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
1487
+ #endif
1488
+ {
1489
+ PyObject *result;
1490
+ #if CYTHON_COMPILING_IN_LIMITED_API
1491
+ if (unlikely(!$module_cname)) {
1492
+ if (!PyErr_Occurred())
1493
+ PyErr_SetNone(PyExc_NameError);
1494
+ return NULL;
1495
+ }
1496
+ result = PyObject_GetAttr($module_cname, name);
1497
+ if (likely(result)) {
1498
+ return result;
1499
+ }
1500
+ PyErr_Clear();
1501
+ #elif CYTHON_AVOID_BORROWED_REFS || CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
1502
+ if (unlikely(__Pyx_PyDict_GetItemRef(NAMED_CGLOBAL(moddict_cname), name, &result) == -1)) PyErr_Clear();
1503
+ __PYX_UPDATE_DICT_CACHE(NAMED_CGLOBAL(moddict_cname), result, *dict_cached_value, *dict_version)
1504
+ if (likely(result)) {
1505
+ return result;
1506
+ }
1507
+ #else
1508
+ // Identifier names are always interned and have a pre-calculated hash value.
1509
+ result = _PyDict_GetItem_KnownHash(NAMED_CGLOBAL(moddict_cname), name, ((PyASCIIObject *) name)->hash);
1510
+ __PYX_UPDATE_DICT_CACHE(NAMED_CGLOBAL(moddict_cname), result, *dict_cached_value, *dict_version)
1511
+ if (likely(result)) {
1512
+ return __Pyx_NewRef(result);
1513
+ }
1514
+ PyErr_Clear();
1515
+ #endif
1516
+ return __Pyx_GetBuiltinName(name);
1517
+ }
1518
+
1519
+ //////////////////// GetAttr.proto ////////////////////
1520
+
1521
+ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); /*proto*/
1522
+
1523
+ //////////////////// GetAttr ////////////////////
1524
+ //@requires: PyObjectGetAttrStr
1525
+
1526
+ static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
1527
+ #if CYTHON_USE_TYPE_SLOTS
1528
+ if (likely(PyUnicode_Check(n)))
1529
+ return __Pyx_PyObject_GetAttrStr(o, n);
1530
+ #endif
1531
+ return PyObject_GetAttr(o, n);
1532
+ }
1533
+
1534
+
1535
+ /////////////// PyObjectLookupSpecial.proto ///////////////
1536
+
1537
+ #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
1538
+ #define __Pyx_PyObject_LookupSpecialNoError(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 0)
1539
+ #define __Pyx_PyObject_LookupSpecial(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 1)
1540
+
1541
+ static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error); /*proto*/
1542
+
1543
+ #else
1544
+ #define __Pyx_PyObject_LookupSpecialNoError(o,n) __Pyx_PyObject_GetAttrStrNoError(o,n)
1545
+ #define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
1546
+ #endif
1547
+
1548
+ /////////////// PyObjectLookupSpecial ///////////////
1549
+ //@requires: PyObjectGetAttrStr
1550
+ //@requires: PyObjectGetAttrStrNoError
1551
+
1552
+ #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
1553
+ static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error) {
1554
+ PyObject *res;
1555
+ PyTypeObject *tp = Py_TYPE(obj);
1556
+ // adapted from CPython's special_lookup() in ceval.c
1557
+ res = _PyType_Lookup(tp, attr_name);
1558
+ if (likely(res)) {
1559
+ descrgetfunc f = Py_TYPE(res)->tp_descr_get;
1560
+ if (!f) {
1561
+ Py_INCREF(res);
1562
+ } else {
1563
+ res = f(res, obj, (PyObject *)tp);
1564
+ }
1565
+ } else if (with_error) {
1566
+ PyErr_SetObject(PyExc_AttributeError, attr_name);
1567
+ }
1568
+ return res;
1569
+ }
1570
+ #endif
1571
+
1572
+ /////////////// PyObjectGetAttrStrNoError.proto ///////////////
1573
+
1574
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);/*proto*/
1575
+
1576
+ /////////////// PyObjectGetAttrStrNoError ///////////////
1577
+ //@requires: PyObjectGetAttrStr
1578
+ //@requires: Exceptions.c::PyThreadStateGet
1579
+ //@requires: Exceptions.c::PyErrFetchRestore
1580
+ //@requires: Exceptions.c::PyErrExceptionMatches
1581
+
1582
+ #if __PYX_LIMITED_VERSION_HEX < 0x030d0000
1583
+ static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
1584
+ __Pyx_PyThreadState_declare
1585
+ __Pyx_PyThreadState_assign
1586
+ if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
1587
+ __Pyx_PyErr_Clear();
1588
+ }
1589
+ #endif
1590
+
1591
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
1592
+ PyObject *result;
1593
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
1594
+ (void) PyObject_GetOptionalAttr(obj, attr_name, &result);
1595
+ return result;
1596
+ #else
1597
+ #if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS
1598
+ // _PyObject_GenericGetAttrWithDict() in CPython 3.7+ can avoid raising the AttributeError.
1599
+ // See https://bugs.python.org/issue32544
1600
+ PyTypeObject* tp = Py_TYPE(obj);
1601
+ if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
1602
+ return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
1603
+ }
1604
+ #endif
1605
+ result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
1606
+ if (unlikely(!result)) {
1607
+ __Pyx_PyObject_GetAttrStr_ClearAttributeError();
1608
+ }
1609
+ return result;
1610
+ #endif
1611
+ }
1612
+
1613
+
1614
+ /////////////// PyObjectGetAttrStr.proto ///////////////
1615
+
1616
+ #if CYTHON_USE_TYPE_SLOTS
1617
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);/*proto*/
1618
+ #else
1619
+ #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
1620
+ #endif
1621
+
1622
+ /////////////// PyObjectGetAttrStr ///////////////
1623
+
1624
+ #if CYTHON_USE_TYPE_SLOTS
1625
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
1626
+ PyTypeObject* tp = Py_TYPE(obj);
1627
+ if (likely(tp->tp_getattro))
1628
+ return tp->tp_getattro(obj, attr_name);
1629
+ return PyObject_GetAttr(obj, attr_name);
1630
+ }
1631
+ #endif
1632
+
1633
+
1634
+ /////////////// PyObjectSetAttrStr.proto ///////////////
1635
+
1636
+ #if CYTHON_USE_TYPE_SLOTS
1637
+ #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
1638
+ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);/*proto*/
1639
+ #else
1640
+ #define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n)
1641
+ #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
1642
+ #endif
1643
+
1644
+ /////////////// PyObjectSetAttrStr ///////////////
1645
+
1646
+ #if CYTHON_USE_TYPE_SLOTS
1647
+ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
1648
+ PyTypeObject* tp = Py_TYPE(obj);
1649
+ if (likely(tp->tp_setattro))
1650
+ return tp->tp_setattro(obj, attr_name, value);
1651
+ return PyObject_SetAttr(obj, attr_name, value);
1652
+ }
1653
+ #endif
1654
+
1655
+
1656
+ /////////////// PyObjectGetMethod.proto ///////////////
1657
+
1658
+ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);/*proto*/
1659
+
1660
+ /////////////// PyObjectGetMethod ///////////////
1661
+ //@requires: PyObjectGetAttrStr
1662
+
1663
+ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
1664
+ PyObject *attr;
1665
+ #if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
1666
+ __Pyx_TypeName type_name;
1667
+ // Copied from _PyObject_GetMethod() in CPython 3.7
1668
+ PyTypeObject *tp = Py_TYPE(obj);
1669
+ PyObject *descr;
1670
+ descrgetfunc f = NULL;
1671
+ PyObject **dictptr, *dict;
1672
+ int meth_found = 0;
1673
+
1674
+ assert (*method == NULL);
1675
+
1676
+ if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
1677
+ attr = __Pyx_PyObject_GetAttrStr(obj, name);
1678
+ goto try_unpack;
1679
+ }
1680
+ if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
1681
+ return 0;
1682
+ }
1683
+
1684
+ descr = _PyType_Lookup(tp, name);
1685
+ if (likely(descr != NULL)) {
1686
+ Py_INCREF(descr);
1687
+ #if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR
1688
+ if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR))
1689
+ #else
1690
+ // Repeating the condition below accommodates for MSVC's inability to test macros inside of macro expansions.
1691
+ #ifdef __Pyx_CyFunction_USED
1692
+ if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
1693
+ #else
1694
+ if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type)))
1695
+ #endif
1696
+ #endif
1697
+ {
1698
+ meth_found = 1;
1699
+ } else {
1700
+ f = Py_TYPE(descr)->tp_descr_get;
1701
+ if (f != NULL && PyDescr_IsData(descr)) {
1702
+ attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
1703
+ Py_DECREF(descr);
1704
+ goto try_unpack;
1705
+ }
1706
+ }
1707
+ }
1708
+
1709
+ dictptr = _PyObject_GetDictPtr(obj);
1710
+ if (dictptr != NULL && (dict = *dictptr) != NULL) {
1711
+ Py_INCREF(dict);
1712
+ attr = __Pyx_PyDict_GetItemStr(dict, name);
1713
+ if (attr != NULL) {
1714
+ Py_INCREF(attr);
1715
+ Py_DECREF(dict);
1716
+ Py_XDECREF(descr);
1717
+ goto try_unpack;
1718
+ }
1719
+ Py_DECREF(dict);
1720
+ }
1721
+
1722
+ if (meth_found) {
1723
+ *method = descr;
1724
+ return 1;
1725
+ }
1726
+
1727
+ if (f != NULL) {
1728
+ attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
1729
+ Py_DECREF(descr);
1730
+ goto try_unpack;
1731
+ }
1732
+
1733
+ if (likely(descr != NULL)) {
1734
+ *method = descr;
1735
+ return 0;
1736
+ }
1737
+
1738
+ type_name = __Pyx_PyType_GetFullyQualifiedName(tp);
1739
+ PyErr_Format(PyExc_AttributeError,
1740
+ "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'",
1741
+ type_name, name);
1742
+ __Pyx_DECREF_TypeName(type_name);
1743
+ return 0;
1744
+
1745
+ // Generic fallback implementation using normal attribute lookup.
1746
+ #else
1747
+ attr = __Pyx_PyObject_GetAttrStr(obj, name);
1748
+ goto try_unpack;
1749
+ #endif
1750
+
1751
+ try_unpack:
1752
+ #if CYTHON_UNPACK_METHODS
1753
+ // Even if we failed to avoid creating a bound method object, it's still worth unpacking it now, if possible.
1754
+ if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
1755
+ PyObject *function = PyMethod_GET_FUNCTION(attr);
1756
+ Py_INCREF(function);
1757
+ Py_DECREF(attr);
1758
+ *method = function;
1759
+ return 1;
1760
+ }
1761
+ #endif
1762
+ *method = attr;
1763
+ return 0;
1764
+ }
1765
+
1766
+
1767
+ /////////////// UnpackUnboundCMethod.proto ///////////////
1768
+ //@requires: MemoryView_C.c::Atomics
1769
+
1770
+ typedef struct {
1771
+ PyObject *type;
1772
+ PyObject **method_name;
1773
+ #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
1774
+ // 0 for uninitialized, 1 for initializing, 2 for initialized
1775
+ __pyx_atomic_int_type initialized;
1776
+ #endif
1777
+ // "func" is set on first access (direct C function pointer)
1778
+ PyCFunction func;
1779
+ // "method" is set on first access (fallback)
1780
+ PyObject *method;
1781
+ int flag;
1782
+ } __Pyx_CachedCFunction;
1783
+
1784
+ #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
1785
+ static CYTHON_INLINE int __Pyx_CachedCFunction_GetAndSetInitializing(__Pyx_CachedCFunction *cfunc) {
1786
+ #if !CYTHON_ATOMICS
1787
+ // always say "we're initializing". This'll always go an inefficient route,
1788
+ // but in reality we always expect to have atomics.
1789
+ return 1;
1790
+ #else
1791
+ __pyx_nonatomic_int_type expected = 0;
1792
+ if (__pyx_atomic_int_cmp_exchange(&cfunc->initialized, &expected, 1)) {
1793
+ // we were uninitialized
1794
+ return 0;
1795
+ }
1796
+ return expected;
1797
+ #endif
1798
+ }
1799
+
1800
+ static CYTHON_INLINE void __Pyx_CachedCFunction_SetFinishedInitializing(__Pyx_CachedCFunction *cfunc) {
1801
+ #if CYTHON_ATOMICS
1802
+ __pyx_atomic_store(&cfunc->initialized, 2);
1803
+ #endif
1804
+ }
1805
+ #else
1806
+ #define __Pyx_CachedCFunction_GetAndSetInitializing(cfunc) 2
1807
+ #define __Pyx_CachedCFunction_SetFinishedInitializing(cfunc)
1808
+ #endif
1809
+
1810
+ /////////////// UnpackUnboundCMethod ///////////////
1811
+ //@requires: PyObjectGetAttrStr
1812
+
1813
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030C0000
1814
+ static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject *args, PyObject *kwargs) {
1815
+ PyObject *result;
1816
+ PyObject *selfless_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args));
1817
+ if (unlikely(!selfless_args)) return NULL;
1818
+
1819
+ result = PyObject_Call(method, selfless_args, kwargs);
1820
+ Py_DECREF(selfless_args);
1821
+ return result;
1822
+ }
1823
+ #else
1824
+ static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) {
1825
+ return
1826
+ #if PY_VERSION_HEX < 0x03090000
1827
+ _PyObject_Vectorcall
1828
+ #else
1829
+ PyObject_Vectorcall
1830
+ #endif
1831
+ (method, args ? args+1 : NULL, nargs ? (size_t) nargs-1 : 0, kwnames);
1832
+ }
1833
+ #endif
1834
+
1835
+ static PyMethodDef __Pyx_UnboundCMethod_Def = {
1836
+ /* .ml_name = */ "CythonUnboundCMethod",
1837
+ /* .ml_meth = */ __PYX_REINTERPRET_FUNCION(PyCFunction, __Pyx_SelflessCall),
1838
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030C0000
1839
+ /* .ml_flags = */ METH_VARARGS | METH_KEYWORDS,
1840
+ #else
1841
+ /* .ml_flags = */ METH_FASTCALL | METH_KEYWORDS,
1842
+ #endif
1843
+ /* .ml_doc = */ NULL
1844
+ };
1845
+
1846
+ static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
1847
+ PyObject *method, *result=NULL;
1848
+ method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
1849
+ if (unlikely(!method))
1850
+ return -1;
1851
+ result = method;
1852
+ // FIXME: use functionality from CythonFunction.c/ClassMethod
1853
+ #if CYTHON_COMPILING_IN_CPYTHON
1854
+ if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
1855
+ {
1856
+ PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
1857
+ target->func = descr->d_method->ml_meth;
1858
+ target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
1859
+ } else
1860
+ #endif
1861
+ // bound classmethods need special treatment
1862
+ #if CYTHON_COMPILING_IN_PYPY
1863
+ // In PyPy, functions are regular methods, so just do the self check.
1864
+ #else
1865
+ if (PyCFunction_Check(method))
1866
+ #endif
1867
+ {
1868
+ PyObject *self;
1869
+ int self_found;
1870
+ #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
1871
+ self = PyObject_GetAttrString(method, "__self__");
1872
+ if (!self) {
1873
+ PyErr_Clear();
1874
+ }
1875
+ #else
1876
+ self = PyCFunction_GET_SELF(method);
1877
+ #endif
1878
+ self_found = (self && self != Py_None);
1879
+ #if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
1880
+ Py_XDECREF(self);
1881
+ #endif
1882
+ if (self_found) {
1883
+ PyObject *unbound_method = PyCFunction_New(&__Pyx_UnboundCMethod_Def, method);
1884
+ if (unlikely(!unbound_method)) return -1;
1885
+ // New PyCFunction will own method reference, thus decref __Pyx_PyObject_GetAttrStr
1886
+ Py_DECREF(method);
1887
+ result = unbound_method;
1888
+ }
1889
+ }
1890
+ #if !CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
1891
+ // Unlikely corner-case where another thread has initialized target->method first.
1892
+ // Can't happen in free-threading because the whole thing is locked.
1893
+ if (unlikely(target->method)) {
1894
+ Py_DECREF(result);
1895
+ } else
1896
+ #endif
1897
+ target->method = result;
1898
+ return 0;
1899
+ }
1900
+
1901
+ /////////////// CallCFunction.proto ///////////////
1902
+ #define __Pyx_CallCFunction(cfunc, self, args) \
1903
+ ((PyCFunction)(void(*)(void))(cfunc)->func)(self, args)
1904
+ #define __Pyx_CallCFunctionWithKeywords(cfunc, self, args, kwargs) \
1905
+ ((PyCFunctionWithKeywords)(void(*)(void))(cfunc)->func)(self, args, kwargs)
1906
+ #define __Pyx_CallCFunctionFast(cfunc, self, args, nargs) \
1907
+ ((__Pyx_PyCFunctionFast)(void(*)(void))(PyCFunction)(cfunc)->func)(self, args, nargs)
1908
+ #define __Pyx_CallCFunctionFastWithKeywords(cfunc, self, args, nargs, kwnames) \
1909
+ ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))(PyCFunction)(cfunc)->func)(self, args, nargs, kwnames)
1910
+
1911
+ /////////////// CallUnboundCMethod0.proto ///////////////
1912
+
1913
+ CYTHON_UNUSED
1914
+ static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self); /*proto*/
1915
+
1916
+ #if CYTHON_COMPILING_IN_CPYTHON
1917
+ static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self); /* proto */
1918
+ #else
1919
+ #define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self)
1920
+ #endif
1921
+
1922
+ /////////////// CallUnboundCMethod0 ///////////////
1923
+ //@requires: CallCFunction
1924
+ //@requires: UnpackUnboundCMethod
1925
+ //@requires: PyObjectCallOneArg
1926
+
1927
+ #if CYTHON_COMPILING_IN_CPYTHON
1928
+ // FASTCALL methods receive "&empty_tuple" as simple "PyObject[0]*"
1929
+ static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
1930
+ int was_initialized = __Pyx_CachedCFunction_GetAndSetInitializing(cfunc);
1931
+
1932
+ if (likely(was_initialized == 2 && cfunc->func)) {
1933
+ if (likely(cfunc->flag == METH_NOARGS))
1934
+ return __Pyx_CallCFunction(cfunc, self, NULL);
1935
+ if (likely(cfunc->flag == METH_FASTCALL))
1936
+ return __Pyx_CallCFunctionFast(cfunc, self, NULL, 0);
1937
+ if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
1938
+ return __Pyx_CallCFunctionFastWithKeywords(cfunc, self, NULL, 0, NULL);
1939
+ if (likely(cfunc->flag == (METH_VARARGS | METH_KEYWORDS)))
1940
+ return __Pyx_CallCFunctionWithKeywords(cfunc, self, EMPTY(tuple), NULL);
1941
+ if (cfunc->flag == METH_VARARGS)
1942
+ return __Pyx_CallCFunction(cfunc, self, EMPTY(tuple));
1943
+ return __Pyx__CallUnboundCMethod0(cfunc, self);
1944
+ }
1945
+ #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
1946
+ else if (unlikely(was_initialized == 1)) {
1947
+ // If it's being simultaneously initialized, just work on a temp
1948
+ __Pyx_CachedCFunction tmp_cfunc = {
1949
+ #ifndef __cplusplus
1950
+ 0
1951
+ #endif
1952
+ };
1953
+ tmp_cfunc.type = cfunc->type;
1954
+ tmp_cfunc.method_name = cfunc->method_name;
1955
+ return __Pyx__CallUnboundCMethod0(&tmp_cfunc, self);
1956
+ }
1957
+ #endif
1958
+ PyObject *result = __Pyx__CallUnboundCMethod0(cfunc, self);
1959
+ __Pyx_CachedCFunction_SetFinishedInitializing(cfunc);
1960
+ return result;
1961
+ }
1962
+ #endif
1963
+
1964
+ static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
1965
+ PyObject *result;
1966
+ if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
1967
+ result = __Pyx_PyObject_CallOneArg(cfunc->method, self);
1968
+ return result;
1969
+ }
1970
+
1971
+
1972
+ /////////////// CallUnboundCMethod1.proto ///////////////
1973
+
1974
+ CYTHON_UNUSED
1975
+ static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);/*proto*/
1976
+
1977
+ #if CYTHON_COMPILING_IN_CPYTHON
1978
+ static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);/*proto*/
1979
+ #else
1980
+ #define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg)
1981
+ #endif
1982
+
1983
+ /////////////// CallUnboundCMethod1 ///////////////
1984
+ //@requires: CallCFunction
1985
+ //@requires: UnpackUnboundCMethod
1986
+ //@requires: PyObjectCall2Args
1987
+
1988
+ #if CYTHON_COMPILING_IN_CPYTHON
1989
+ static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
1990
+ int was_initialized = __Pyx_CachedCFunction_GetAndSetInitializing(cfunc);
1991
+
1992
+ if (likely(was_initialized == 2 && cfunc->func)) {
1993
+ int flag = cfunc->flag;
1994
+ if (flag == METH_O) {
1995
+ return __Pyx_CallCFunction(cfunc, self, arg);
1996
+ } else if (flag == METH_FASTCALL) {
1997
+ return __Pyx_CallCFunctionFast(cfunc, self, &arg, 1);
1998
+ } else if (flag == (METH_FASTCALL | METH_KEYWORDS)) {
1999
+ return __Pyx_CallCFunctionFastWithKeywords(cfunc, self, &arg, 1, NULL);
2000
+ }
2001
+ }
2002
+ #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
2003
+ else if (unlikely(was_initialized == 1)) {
2004
+ // Race to initialize - use a temp
2005
+ __Pyx_CachedCFunction tmp_cfunc = {
2006
+ #ifndef __cplusplus
2007
+ 0
2008
+ #endif
2009
+ };
2010
+ tmp_cfunc.type = cfunc->type;
2011
+ tmp_cfunc.method_name = cfunc->method_name;
2012
+ return __Pyx__CallUnboundCMethod1(&tmp_cfunc, self, arg);
2013
+ }
2014
+ #endif
2015
+ PyObject* result = __Pyx__CallUnboundCMethod1(cfunc, self, arg);
2016
+ __Pyx_CachedCFunction_SetFinishedInitializing(cfunc);
2017
+ return result;
2018
+ }
2019
+ #endif
2020
+
2021
+ static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
2022
+ PyObject *result = NULL;
2023
+ if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
2024
+ #if CYTHON_COMPILING_IN_CPYTHON
2025
+ if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
2026
+ PyObject *args = PyTuple_New(1);
2027
+ if (unlikely(!args)) return NULL;
2028
+ Py_INCREF(arg);
2029
+ PyTuple_SET_ITEM(args, 0, arg);
2030
+ if (cfunc->flag & METH_KEYWORDS)
2031
+ result = __Pyx_CallCFunctionWithKeywords(cfunc, self, args, NULL);
2032
+ else
2033
+ result = __Pyx_CallCFunction(cfunc, self, args);
2034
+ Py_DECREF(args);
2035
+ } else
2036
+ #endif
2037
+ {
2038
+ result = __Pyx_PyObject_Call2Args(cfunc->method, self, arg);
2039
+ }
2040
+ return result;
2041
+ }
2042
+
2043
+
2044
+ /////////////// CallUnboundCMethod2.proto ///////////////
2045
+
2046
+ CYTHON_UNUSED
2047
+ static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2); /*proto*/
2048
+
2049
+ #if CYTHON_COMPILING_IN_CPYTHON
2050
+ static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2); /*proto*/
2051
+ #else
2052
+ #define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2) __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2)
2053
+ #endif
2054
+
2055
+ /////////////// CallUnboundCMethod2 ///////////////
2056
+ //@requires: CallCFunction
2057
+ //@requires: UnpackUnboundCMethod
2058
+ //@requires: PyObjectFastCall
2059
+
2060
+ #if CYTHON_COMPILING_IN_CPYTHON
2061
+ static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
2062
+ int was_initialized = __Pyx_CachedCFunction_GetAndSetInitializing(cfunc);
2063
+
2064
+ if (likely(was_initialized == 2 && cfunc->func)) {
2065
+ PyObject *args[2] = {arg1, arg2};
2066
+ if (cfunc->flag == METH_FASTCALL) {
2067
+ return __Pyx_CallCFunctionFast(cfunc, self, args, 2);
2068
+ }
2069
+ if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
2070
+ return __Pyx_CallCFunctionFastWithKeywords(cfunc, self, args, 2, NULL);
2071
+ }
2072
+ #if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
2073
+ else if (unlikely(was_initialized == 1)) {
2074
+ // Race to initialize - run this on a temp function instead.
2075
+ __Pyx_CachedCFunction tmp_cfunc = {
2076
+ #ifndef __cplusplus
2077
+ 0
2078
+ #endif
2079
+ };
2080
+ tmp_cfunc.type = cfunc->type;
2081
+ tmp_cfunc.method_name = cfunc->method_name;
2082
+ return __Pyx__CallUnboundCMethod2(&tmp_cfunc, self, arg1, arg2);
2083
+ }
2084
+ #endif
2085
+ PyObject *result = __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
2086
+ __Pyx_CachedCFunction_SetFinishedInitializing(cfunc);
2087
+ return result;
2088
+ }
2089
+ #endif
2090
+
2091
+ static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
2092
+ if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
2093
+ #if CYTHON_COMPILING_IN_CPYTHON
2094
+ if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
2095
+ PyObject *result = NULL;
2096
+ PyObject *args = PyTuple_New(2);
2097
+ if (unlikely(!args)) return NULL;
2098
+ Py_INCREF(arg1);
2099
+ PyTuple_SET_ITEM(args, 0, arg1);
2100
+ Py_INCREF(arg2);
2101
+ PyTuple_SET_ITEM(args, 1, arg2);
2102
+ if (cfunc->flag & METH_KEYWORDS)
2103
+ result = __Pyx_CallCFunctionWithKeywords(cfunc, self, args, NULL);
2104
+ else
2105
+ result = __Pyx_CallCFunction(cfunc, self, args);
2106
+ Py_DECREF(args);
2107
+ return result;
2108
+ }
2109
+ #endif
2110
+ {
2111
+ PyObject *args[4] = {NULL, self, arg1, arg2};
2112
+ return __Pyx_PyObject_FastCall(cfunc->method, args+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
2113
+ }
2114
+ }
2115
+
2116
+
2117
+ /////////////// PyObjectFastCall.proto ///////////////
2118
+
2119
+ #define __Pyx_PyObject_FastCall(func, args, nargs) __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL)
2120
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject * const*args, size_t nargs, PyObject *kwargs); /*proto*/
2121
+
2122
+ /////////////// PyObjectFastCall ///////////////
2123
+ //@requires: PyObjectCall
2124
+ //@requires: PyFunctionFastCall
2125
+ //@requires: PyObjectCallMethO
2126
+
2127
+ #if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API
2128
+ static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject * const*args, size_t nargs, PyObject *kwargs) {
2129
+ PyObject *argstuple;
2130
+ PyObject *result = 0;
2131
+ size_t i;
2132
+
2133
+ argstuple = PyTuple_New((Py_ssize_t)nargs);
2134
+ if (unlikely(!argstuple)) return NULL;
2135
+ for (i = 0; i < nargs; i++) {
2136
+ Py_INCREF(args[i]);
2137
+ if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) != (0)) goto bad;
2138
+ }
2139
+ result = __Pyx_PyObject_Call(func, argstuple, kwargs);
2140
+ bad:
2141
+ Py_DECREF(argstuple);
2142
+ return result;
2143
+ }
2144
+ #endif
2145
+
2146
+ #if CYTHON_VECTORCALL && !CYTHON_COMPILING_IN_LIMITED_API
2147
+ #if PY_VERSION_HEX < 0x03090000
2148
+ #define __Pyx_PyVectorcall_Function(callable) _PyVectorcall_Function(callable)
2149
+ #elif CYTHON_COMPILING_IN_CPYTHON
2150
+ static CYTHON_INLINE vectorcallfunc __Pyx_PyVectorcall_Function(PyObject *callable) {
2151
+ PyTypeObject *tp = Py_TYPE(callable);
2152
+
2153
+ #if defined(__Pyx_CyFunction_USED)
2154
+ if (__Pyx_CyFunction_CheckExact(callable)) {
2155
+ return __Pyx_CyFunction_func_vectorcall(callable);
2156
+ }
2157
+ #endif
2158
+
2159
+ if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL)) {
2160
+ return NULL;
2161
+ }
2162
+ assert(PyCallable_Check(callable));
2163
+
2164
+ Py_ssize_t offset = tp->tp_vectorcall_offset;
2165
+ assert(offset > 0);
2166
+
2167
+ vectorcallfunc ptr;
2168
+ memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
2169
+ return ptr;
2170
+ }
2171
+ #else
2172
+ #define __Pyx_PyVectorcall_Function(callable) PyVectorcall_Function(callable)
2173
+ #endif
2174
+ #endif
2175
+
2176
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject *const *args, size_t _nargs, PyObject *kwargs) {
2177
+ // Special fast paths for 0 and 1 arguments
2178
+ // NOTE: in many cases, this is called with a constant value for nargs
2179
+ // which is known at compile-time. So the branches below will typically
2180
+ // be optimized away.
2181
+ Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs);
2182
+ #if CYTHON_COMPILING_IN_CPYTHON
2183
+ if (nargs == 0 && kwargs == NULL) {
2184
+ if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS))
2185
+ return __Pyx_PyObject_CallMethO(func, NULL);
2186
+ }
2187
+ else if (nargs == 1 && kwargs == NULL) {
2188
+ if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_O))
2189
+ return __Pyx_PyObject_CallMethO(func, args[0]);
2190
+ }
2191
+ #endif
2192
+
2193
+ #if PY_VERSION_HEX < 0x030800B1
2194
+ #if CYTHON_FAST_PYCCALL
2195
+ if (PyCFunction_Check(func)) {
2196
+ if (kwargs) {
2197
+ return _PyCFunction_FastCallDict(func, args, nargs, kwargs);
2198
+ } else {
2199
+ return _PyCFunction_FastCallKeywords(func, args, nargs, NULL);
2200
+ }
2201
+ }
2202
+ if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) {
2203
+ return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL);
2204
+ }
2205
+ #endif
2206
+ #if CYTHON_FAST_PYCALL
2207
+ if (PyFunction_Check(func)) {
2208
+ return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs);
2209
+ }
2210
+ #endif
2211
+ #endif
2212
+
2213
+ if (kwargs == NULL) {
2214
+ #if CYTHON_VECTORCALL && !CYTHON_COMPILING_IN_LIMITED_API
2215
+ vectorcallfunc f = __Pyx_PyVectorcall_Function(func);
2216
+ if (f) {
2217
+ return f(func, args, _nargs, NULL);
2218
+ }
2219
+ #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL
2220
+ // exclude fused functions for now
2221
+ if (__Pyx_CyFunction_CheckExact(func)) {
2222
+ __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func);
2223
+ if (f) return f(func, args, _nargs, NULL);
2224
+ }
2225
+ #elif CYTHON_COMPILING_IN_LIMITED_API && CYTHON_VECTORCALL
2226
+ return PyObject_Vectorcall(func, args, _nargs, NULL);
2227
+ #endif
2228
+ }
2229
+
2230
+ if (nargs == 0) {
2231
+ return __Pyx_PyObject_Call(func, EMPTY(tuple), kwargs);
2232
+ }
2233
+ #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API
2234
+ return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs);
2235
+ #else
2236
+ return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs);
2237
+ #endif
2238
+ }
2239
+
2240
+ /////////////// PyObjectFastCallMethod.proto ///////////////
2241
+ //@requires PyObjectFastCall
2242
+
2243
+ #if CYTHON_VECTORCALL && PY_VERSION_HEX >= 0x03090000
2244
+ #define __Pyx_PyObject_FastCallMethod(name, args, nargsf) PyObject_VectorcallMethod(name, args, nargsf, NULL)
2245
+ #else
2246
+ static PyObject *__Pyx_PyObject_FastCallMethod(PyObject *name, PyObject *const *args, size_t nargsf); /* proto */
2247
+ #endif
2248
+
2249
+ /////////////// PyObjectFastCallMethod ///////////////
2250
+
2251
+ #if !CYTHON_VECTORCALL || PY_VERSION_HEX < 0x03090000
2252
+ static PyObject *__Pyx_PyObject_FastCallMethod(PyObject *name, PyObject *const *args, size_t nargsf) {
2253
+ PyObject *result;
2254
+ PyObject *attr = PyObject_GetAttr(args[0], name);
2255
+ if (unlikely(!attr))
2256
+ return NULL;
2257
+ result = __Pyx_PyObject_FastCall(attr, args+1, nargsf - 1);
2258
+ Py_DECREF(attr);
2259
+ return result;
2260
+ }
2261
+ #endif
2262
+
2263
+ /////////////// PyObjectVectorCallKwBuilder.proto ////////////////
2264
+ //@requires: PyObjectFastCall
2265
+ // For versions that define PyObject_Vectorcall, use PyObject_Vectorcall and define functions to build a kwnames tuple and add arguments to args.
2266
+ // For versions that don't, use __Pyx_PyObject_FastCallDict and functions to build a keyword dictionary
2267
+
2268
+ CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n); /* proto */
2269
+
2270
+ #if CYTHON_VECTORCALL
2271
+ #if PY_VERSION_HEX >= 0x03090000
2272
+ #define __Pyx_Object_Vectorcall_CallFromBuilder PyObject_Vectorcall
2273
+ #else
2274
+ #define __Pyx_Object_Vectorcall_CallFromBuilder _PyObject_Vectorcall
2275
+ #endif
2276
+
2277
+ #define __Pyx_MakeVectorcallBuilderKwds(n) PyTuple_New(n)
2278
+
2279
+ static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n); /* proto */
2280
+ static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n); /* proto */
2281
+ #else
2282
+ #define __Pyx_Object_Vectorcall_CallFromBuilder __Pyx_PyObject_FastCallDict
2283
+
2284
+ #define __Pyx_MakeVectorcallBuilderKwds(n) __Pyx_PyDict_NewPresized(n)
2285
+
2286
+ #define __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n) PyDict_SetItem(builder, key, value)
2287
+ #define __Pyx_VectorcallBuilder_AddArgStr(key, value, builder, args, n) PyDict_SetItemString(builder, key, value)
2288
+ #endif
2289
+
2290
+ /////////////// PyObjectVectorCallKwBuilder ////////////////
2291
+
2292
+ #if CYTHON_VECTORCALL
2293
+ static int __Pyx_VectorcallBuilder_AddArg(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) {
2294
+ (void)__Pyx_PyObject_FastCallDict;
2295
+
2296
+ if (__Pyx_PyTuple_SET_ITEM(builder, n, key) != (0)) return -1;
2297
+ Py_INCREF(key);
2298
+ args[n] = value;
2299
+ return 0;
2300
+ }
2301
+
2302
+ CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, PyObject **args, int n) {
2303
+ (void)__Pyx_VectorcallBuilder_AddArgStr;
2304
+ if (unlikely(!PyUnicode_Check(key))) {
2305
+ PyErr_SetString(PyExc_TypeError, "keywords must be strings");
2306
+ return -1;
2307
+ }
2308
+ return __Pyx_VectorcallBuilder_AddArg(key, value, builder, args, n);
2309
+ }
2310
+
2311
+ static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, PyObject *builder, PyObject **args, int n) {
2312
+ PyObject *pyKey = PyUnicode_FromString(key);
2313
+ if (!pyKey) return -1;
2314
+ return __Pyx_VectorcallBuilder_AddArg(pyKey, value, builder, args, n);
2315
+ }
2316
+ #else // CYTHON_VECTORCALL
2317
+ CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyObject *value, PyObject *builder, CYTHON_UNUSED PyObject **args, CYTHON_UNUSED int n) {
2318
+ if (unlikely(!PyUnicode_Check(key))) {
2319
+ PyErr_SetString(PyExc_TypeError, "keywords must be strings");
2320
+ return -1;
2321
+ }
2322
+ return PyDict_SetItem(builder, key, value);
2323
+ }
2324
+ #endif
2325
+
2326
+ /////////////// PyObjectVectorCallMethodKwBuilder.proto ////////////////
2327
+
2328
+ #if CYTHON_VECTORCALL && PY_VERSION_HEX >= 0x03090000
2329
+ #define __Pyx_Object_VectorcallMethod_CallFromBuilder PyObject_VectorcallMethod
2330
+ #else
2331
+ static PyObject *__Pyx_Object_VectorcallMethod_CallFromBuilder(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames); /* proto */
2332
+ #endif
2333
+
2334
+ /////////////// PyObjectVectorCallMethodKwBuilder ////////////////
2335
+ //@requires: PyObjectVectorCallKwBuilder
2336
+
2337
+ #if !CYTHON_VECTORCALL || PY_VERSION_HEX < 0x03090000
2338
+ static PyObject *__Pyx_Object_VectorcallMethod_CallFromBuilder(PyObject *name, PyObject *const *args, size_t nargsf, PyObject *kwnames) {
2339
+ PyObject *result;
2340
+ PyObject *obj = PyObject_GetAttr(args[0], name);
2341
+ if (unlikely(!obj))
2342
+ return NULL;
2343
+ result = __Pyx_Object_Vectorcall_CallFromBuilder(obj, args+1, nargsf-1, kwnames);
2344
+ Py_DECREF(obj);
2345
+ return result;
2346
+ }
2347
+ #endif
2348
+
2349
+ /////////////// PyObjectCallMethod0.proto ///////////////
2350
+
2351
+ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); /*proto*/
2352
+
2353
+ /////////////// PyObjectCallMethod0 ///////////////
2354
+ //@requires: PyObjectGetMethod
2355
+ //@requires: PyObjectCallOneArg
2356
+ //@requires: PyObjectCallNoArg
2357
+
2358
+ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
2359
+ PyObject *method = NULL, *result = NULL;
2360
+ int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
2361
+ if (likely(is_method)) {
2362
+ result = __Pyx_PyObject_CallOneArg(method, obj);
2363
+ Py_DECREF(method);
2364
+ return result;
2365
+ }
2366
+ if (unlikely(!method)) goto bad;
2367
+ result = __Pyx_PyObject_CallNoArg(method);
2368
+ Py_DECREF(method);
2369
+ bad:
2370
+ return result;
2371
+ }
2372
+
2373
+
2374
+ /////////////// PyObjectCallMethod1.proto ///////////////
2375
+
2376
+ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); /*proto*/
2377
+
2378
+ /////////////// PyObjectCallMethod1 ///////////////
2379
+ //@requires: PyObjectGetMethod
2380
+ //@requires: PyObjectCallOneArg
2381
+ //@requires: PyObjectCall2Args
2382
+
2383
+ #if !(CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000)
2384
+ static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
2385
+ // Separate function to avoid excessive inlining.
2386
+ PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
2387
+ Py_DECREF(method);
2388
+ return result;
2389
+ }
2390
+ #endif
2391
+
2392
+ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
2393
+ #if CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000
2394
+ PyObject *args[2] = {obj, arg};
2395
+ // avoid unused functions
2396
+ (void) __Pyx_PyObject_GetMethod;
2397
+ (void) __Pyx_PyObject_CallOneArg;
2398
+ (void) __Pyx_PyObject_Call2Args;
2399
+ return PyObject_VectorcallMethod(method_name, args, 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
2400
+ #else
2401
+ PyObject *method = NULL, *result;
2402
+ int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
2403
+ if (likely(is_method)) {
2404
+ result = __Pyx_PyObject_Call2Args(method, obj, arg);
2405
+ Py_DECREF(method);
2406
+ return result;
2407
+ }
2408
+ if (unlikely(!method)) return NULL;
2409
+ return __Pyx__PyObject_CallMethod1(method, arg);
2410
+ #endif
2411
+ }
2412
+
2413
+
2414
+ /////////////// tp_new.proto ///////////////
2415
+ //@requires: ModuleSetupCode.c::GetRuntimeVersion
2416
+
2417
+ #define __Pyx_tp_new(type_obj, args) __Pyx_tp_new_kwargs(type_obj, args, NULL)
2418
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
2419
+ static PyObject* __Pyx_tp_new_fallback(PyObject* type_obj, PyObject* args, PyObject* kwargs); /*proto*/
2420
+ #endif
2421
+ static CYTHON_INLINE PyObject* __Pyx_tp_new_kwargs(PyObject* type_obj, PyObject* args, PyObject* kwargs) {
2422
+ newfunc tp_new = __Pyx_PyType_TryGetSlot((PyTypeObject*)type_obj, tp_new, newfunc);
2423
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
2424
+ if (!tp_new) return __Pyx_tp_new_fallback(type_obj, args, kwargs);
2425
+ #else
2426
+ assert(tp_new != NULL);
2427
+ #endif
2428
+ return tp_new((PyTypeObject*)type_obj, args, kwargs);
2429
+ }
2430
+
2431
+ /////////////// tp_new ///////////////
2432
+
2433
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030A0000
2434
+ static PyObject* __Pyx_tp_new_fallback(PyObject* type_obj, PyObject* args, PyObject* kwargs) {
2435
+ PyObject *new_func = NULL, *new_args = NULL, *obj;
2436
+ Py_ssize_t i, nargs = PyTuple_Size(args);
2437
+
2438
+ if (unlikely(nargs < 0)) goto bad;
2439
+ new_args = PyTuple_New(nargs + 1);
2440
+ if (unlikely(!new_args)) goto bad;
2441
+ for (i = 0; i < nargs + 1; i++) {
2442
+ PyObject *item = (i == 0) ? type_obj : PyTuple_GetItem(args, i - 1);
2443
+ if (unlikely(!item)) goto bad;
2444
+ Py_INCREF(item);
2445
+ if (unlikely(PyTuple_SetItem(new_args, i, item)) < 0) goto bad;
2446
+ }
2447
+
2448
+ new_func = PyObject_GetAttrString(type_obj, "__new__");
2449
+ if (unlikely(!new_func)) goto bad;
2450
+ obj = PyObject_Call(new_func, new_args, kwargs);
2451
+ Py_DECREF(new_func);
2452
+ Py_DECREF(new_args);
2453
+ return obj;
2454
+
2455
+ bad:
2456
+ Py_XDECREF(new_func);
2457
+ Py_XDECREF(new_args);
2458
+ return NULL;
2459
+ }
2460
+ #endif
2461
+
2462
+ /////////////// PyObjectCall.proto ///////////////
2463
+
2464
+ #if CYTHON_COMPILING_IN_CPYTHON
2465
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); /*proto*/
2466
+ #else
2467
+ #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
2468
+ #endif
2469
+
2470
+ /////////////// PyObjectCall ///////////////
2471
+
2472
+ #if CYTHON_COMPILING_IN_CPYTHON
2473
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
2474
+ PyObject *result;
2475
+ ternaryfunc call = Py_TYPE(func)->tp_call;
2476
+
2477
+ if (unlikely(!call))
2478
+ return PyObject_Call(func, arg, kw);
2479
+ if (unlikely(Py_EnterRecursiveCall(" while calling a Python object")))
2480
+ return NULL;
2481
+ result = (*call)(func, arg, kw);
2482
+ Py_LeaveRecursiveCall();
2483
+ if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
2484
+ PyErr_SetString(
2485
+ PyExc_SystemError,
2486
+ "NULL result without error in PyObject_Call");
2487
+ }
2488
+ return result;
2489
+ }
2490
+ #endif
2491
+
2492
+
2493
+ /////////////// PyObjectCallMethO.proto ///////////////
2494
+
2495
+ #if CYTHON_COMPILING_IN_CPYTHON
2496
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); /*proto*/
2497
+ #endif
2498
+
2499
+ /////////////// PyObjectCallMethO ///////////////
2500
+
2501
+ #if CYTHON_COMPILING_IN_CPYTHON
2502
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
2503
+ PyObject *self, *result;
2504
+ PyCFunction cfunc;
2505
+ cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func);
2506
+ self = __Pyx_CyOrPyCFunction_GET_SELF(func);
2507
+
2508
+ if (unlikely(Py_EnterRecursiveCall(" while calling a Python object")))
2509
+ return NULL;
2510
+ result = cfunc(self, arg);
2511
+ Py_LeaveRecursiveCall();
2512
+ if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
2513
+ PyErr_SetString(
2514
+ PyExc_SystemError,
2515
+ "NULL result without error in PyObject_Call");
2516
+ }
2517
+ return result;
2518
+ }
2519
+ #endif
2520
+
2521
+
2522
+ /////////////// PyFunctionFastCall.proto ///////////////
2523
+
2524
+ #if CYTHON_FAST_PYCALL
2525
+
2526
+ #if !CYTHON_VECTORCALL
2527
+ #define __Pyx_PyFunction_FastCall(func, args, nargs) \
2528
+ __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
2529
+
2530
+ static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs);
2531
+ #endif
2532
+
2533
+ // Backport from Python 3
2534
+ // Assert a build-time dependency, as an expression.
2535
+ // Your compile will fail if the condition isn't true, or can't be evaluated
2536
+ // by the compiler. This can be used in an expression: its value is 0.
2537
+ // Example:
2538
+ // #define foo_to_char(foo) \
2539
+ // ((char *)(foo) \
2540
+ // + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0))
2541
+ //
2542
+ // Written by Rusty Russell, public domain, https://ccodearchive.net/
2543
+ #define __Pyx_BUILD_ASSERT_EXPR(cond) \
2544
+ (sizeof(char [1 - 2*!(cond)]) - 1)
2545
+
2546
+ #ifndef Py_MEMBER_SIZE
2547
+ // Get the size of a structure member in bytes
2548
+ #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
2549
+ #endif
2550
+
2551
+ #if !CYTHON_VECTORCALL
2552
+ #if PY_VERSION_HEX >= 0x03080000
2553
+ #include "frameobject.h"
2554
+ #define __Pxy_PyFrame_Initialize_Offsets()
2555
+ #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus)
2556
+ #else
2557
+ // Initialised by module init code.
2558
+ static size_t __pyx_pyframe_localsplus_offset = 0;
2559
+
2560
+ #include "frameobject.h"
2561
+ // This is the long runtime version of
2562
+ // #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus)
2563
+ // offsetof(PyFrameObject, f_localsplus) differs between regular C-Python and Stackless Python < 3.8.
2564
+ // Therefore the offset is computed at run time from PyFrame_type.tp_basicsize. That is feasible,
2565
+ // because f_localsplus is the last field of PyFrameObject (checked by Py_BUILD_ASSERT_EXPR below).
2566
+ #define __Pxy_PyFrame_Initialize_Offsets() \
2567
+ ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)), \
2568
+ (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
2569
+ #define __Pyx_PyFrame_GetLocalsplus(frame) \
2570
+ (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
2571
+ #endif
2572
+ #endif /* !CYTHON_VECTORCALL */
2573
+
2574
+ #endif /* CYTHON_FAST_PYCALL */
2575
+
2576
+
2577
+ /////////////// PyFunctionFastCall ///////////////
2578
+ // copied from CPython 3.6 ceval.c
2579
+
2580
+ #if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL
2581
+ static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject *const *args, Py_ssize_t na,
2582
+ PyObject *globals) {
2583
+ PyFrameObject *f;
2584
+ PyThreadState *tstate = __Pyx_PyThreadState_Current;
2585
+ PyObject **fastlocals;
2586
+ Py_ssize_t i;
2587
+ PyObject *result;
2588
+
2589
+ assert(globals != NULL);
2590
+ /* XXX Perhaps we should create a specialized
2591
+ PyFrame_New() that doesn't take locals, but does
2592
+ take builtins without sanity checking them.
2593
+ */
2594
+ assert(tstate != NULL);
2595
+ f = PyFrame_New(tstate, co, globals, NULL);
2596
+ if (f == NULL) {
2597
+ return NULL;
2598
+ }
2599
+
2600
+ fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
2601
+
2602
+ for (i = 0; i < na; i++) {
2603
+ Py_INCREF(*args);
2604
+ fastlocals[i] = *args++;
2605
+ }
2606
+ result = PyEval_EvalFrameEx(f,0);
2607
+
2608
+ ++tstate->recursion_depth;
2609
+ Py_DECREF(f);
2610
+ --tstate->recursion_depth;
2611
+
2612
+ return result;
2613
+ }
2614
+
2615
+
2616
+ static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject *const *args, Py_ssize_t nargs, PyObject *kwargs) {
2617
+ PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
2618
+ PyObject *globals = PyFunction_GET_GLOBALS(func);
2619
+ PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
2620
+ PyObject *closure;
2621
+ PyObject *kwdefs;
2622
+ //PyObject *name, *qualname;
2623
+ PyObject *kwtuple, **k;
2624
+ PyObject **d;
2625
+ Py_ssize_t nd;
2626
+ Py_ssize_t nk;
2627
+ PyObject *result;
2628
+
2629
+ assert(kwargs == NULL || PyDict_Check(kwargs));
2630
+ nk = kwargs ? PyDict_Size(kwargs) : 0;
2631
+
2632
+ if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) {
2633
+ return NULL;
2634
+ }
2635
+
2636
+ if (
2637
+ co->co_kwonlyargcount == 0 &&
2638
+ likely(kwargs == NULL || nk == 0) &&
2639
+ co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
2640
+ /* Fast paths */
2641
+ if (argdefs == NULL && co->co_argcount == nargs) {
2642
+ result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
2643
+ goto done;
2644
+ }
2645
+ else if (nargs == 0 && argdefs != NULL
2646
+ && co->co_argcount == Py_SIZE(argdefs)) {
2647
+ /* function called with no arguments, but all parameters have
2648
+ a default value: use default values as arguments .*/
2649
+ args = &PyTuple_GET_ITEM(argdefs, 0);
2650
+ result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
2651
+ goto done;
2652
+ }
2653
+ }
2654
+
2655
+ if (kwargs != NULL) {
2656
+ Py_ssize_t pos, i;
2657
+ kwtuple = PyTuple_New(2 * nk);
2658
+ if (kwtuple == NULL) {
2659
+ result = NULL;
2660
+ goto done;
2661
+ }
2662
+
2663
+ k = &PyTuple_GET_ITEM(kwtuple, 0);
2664
+ pos = i = 0;
2665
+ while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
2666
+ Py_INCREF(k[i]);
2667
+ Py_INCREF(k[i+1]);
2668
+ i += 2;
2669
+ }
2670
+ nk = i / 2;
2671
+ }
2672
+ else {
2673
+ kwtuple = NULL;
2674
+ k = NULL;
2675
+ }
2676
+
2677
+ closure = PyFunction_GET_CLOSURE(func);
2678
+ kwdefs = PyFunction_GET_KW_DEFAULTS(func);
2679
+ //name = ((PyFunctionObject *)func) -> func_name;
2680
+ //qualname = ((PyFunctionObject *)func) -> func_qualname;
2681
+
2682
+ if (argdefs != NULL) {
2683
+ d = &PyTuple_GET_ITEM(argdefs, 0);
2684
+ nd = Py_SIZE(argdefs);
2685
+ }
2686
+ else {
2687
+ d = NULL;
2688
+ nd = 0;
2689
+ }
2690
+
2691
+ //return _PyEval_EvalCodeWithName((PyObject*)co, globals, (PyObject *)NULL,
2692
+ // args, nargs,
2693
+ // NULL, 0,
2694
+ // d, nd, kwdefs,
2695
+ // closure, name, qualname);
2696
+ result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
2697
+ args, (int)nargs,
2698
+ k, (int)nk,
2699
+ d, (int)nd, kwdefs, closure);
2700
+ Py_XDECREF(kwtuple);
2701
+
2702
+ done:
2703
+ Py_LeaveRecursiveCall();
2704
+ return result;
2705
+ }
2706
+ #endif /* CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL */
2707
+
2708
+
2709
+ /////////////// PyObjectCall2Args.proto ///////////////
2710
+
2711
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); /*proto*/
2712
+
2713
+ /////////////// PyObjectCall2Args ///////////////
2714
+ //@requires: PyObjectFastCall
2715
+
2716
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
2717
+ PyObject *args[3] = {NULL, arg1, arg2};
2718
+ return __Pyx_PyObject_FastCall(function, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
2719
+ }
2720
+
2721
+
2722
+ /////////////// PyObjectCallOneArg.proto ///////////////
2723
+
2724
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /*proto*/
2725
+
2726
+ /////////////// PyObjectCallOneArg ///////////////
2727
+ //@requires: PyObjectFastCall
2728
+
2729
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
2730
+ PyObject *args[2] = {NULL, arg};
2731
+ return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
2732
+ }
2733
+
2734
+
2735
+ /////////////// PyObjectCallNoArg.proto ///////////////
2736
+
2737
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); /*proto*/
2738
+
2739
+ /////////////// PyObjectCallNoArg ///////////////
2740
+ //@requires: PyObjectFastCall
2741
+
2742
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
2743
+ PyObject *arg[2] = {NULL, NULL};
2744
+ return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
2745
+ }
2746
+
2747
+
2748
+ /////////////// PyVectorcallFastCallDict.proto ///////////////
2749
+
2750
+ #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL)
2751
+ static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw);
2752
+ #endif
2753
+
2754
+ /////////////// PyVectorcallFastCallDict ///////////////
2755
+
2756
+ #if CYTHON_METH_FASTCALL && (CYTHON_VECTORCALL || CYTHON_BACKPORT_VECTORCALL)
2757
+ // Slow path when kw is non-empty
2758
+ static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw)
2759
+ {
2760
+ // Code based on _PyObject_FastCallDict() and _PyStack_UnpackDict() from CPython
2761
+ PyObject *res = NULL;
2762
+ PyObject *kwnames;
2763
+ PyObject **newargs;
2764
+ PyObject **kwvalues;
2765
+ Py_ssize_t i, pos;
2766
+ size_t j;
2767
+ PyObject *key, *value;
2768
+ unsigned long keys_are_strings;
2769
+ #if !CYTHON_ASSUME_SAFE_SIZE
2770
+ Py_ssize_t nkw = PyDict_Size(kw);
2771
+ if (unlikely(nkw == -1)) return NULL;
2772
+ #else
2773
+ Py_ssize_t nkw = PyDict_GET_SIZE(kw);
2774
+ #endif
2775
+
2776
+ // Copy positional arguments
2777
+ newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0]));
2778
+ if (unlikely(newargs == NULL)) {
2779
+ PyErr_NoMemory();
2780
+ return NULL;
2781
+ }
2782
+ for (j = 0; j < nargs; j++) newargs[j] = args[j];
2783
+
2784
+ // Copy keyword arguments
2785
+ kwnames = PyTuple_New(nkw);
2786
+ if (unlikely(kwnames == NULL)) {
2787
+ PyMem_Free(newargs);
2788
+ return NULL;
2789
+ }
2790
+ kwvalues = newargs + nargs;
2791
+ pos = i = 0;
2792
+ keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS;
2793
+ while (PyDict_Next(kw, &pos, &key, &value)) {
2794
+ keys_are_strings &=
2795
+ #if CYTHON_COMPILING_IN_LIMITED_API
2796
+ PyType_GetFlags(Py_TYPE(key));
2797
+ #else
2798
+ Py_TYPE(key)->tp_flags;
2799
+ #endif
2800
+ Py_INCREF(key);
2801
+ Py_INCREF(value);
2802
+ #if !CYTHON_ASSUME_SAFE_MACROS
2803
+ if (unlikely(PyTuple_SetItem(kwnames, i, key) < 0)) goto cleanup;
2804
+ #else
2805
+ PyTuple_SET_ITEM(kwnames, i, key);
2806
+ #endif
2807
+ kwvalues[i] = value;
2808
+ i++;
2809
+ }
2810
+ if (unlikely(!keys_are_strings)) {
2811
+ PyErr_SetString(PyExc_TypeError, "keywords must be strings");
2812
+ goto cleanup;
2813
+ }
2814
+
2815
+ // The actual call
2816
+ res = vc(func, newargs, nargs, kwnames);
2817
+
2818
+ cleanup:
2819
+ Py_DECREF(kwnames);
2820
+ for (i = 0; i < nkw; i++)
2821
+ Py_DECREF(kwvalues[i]);
2822
+ PyMem_Free(newargs);
2823
+ return res;
2824
+ }
2825
+
2826
+ static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw)
2827
+ {
2828
+ Py_ssize_t kw_size =
2829
+ likely(kw == NULL) ?
2830
+ 0 :
2831
+ #if !CYTHON_ASSUME_SAFE_SIZE
2832
+ PyDict_Size(kw);
2833
+ #else
2834
+ PyDict_GET_SIZE(kw);
2835
+ #endif
2836
+
2837
+ if (kw_size == 0) {
2838
+ return vc(func, args, nargs, NULL);
2839
+ }
2840
+ #if !CYTHON_ASSUME_SAFE_SIZE
2841
+ else if (unlikely(kw_size == -1)) {
2842
+ return NULL;
2843
+ }
2844
+ #endif
2845
+ return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw);
2846
+ }
2847
+ #endif
2848
+
2849
+
2850
+ /////////////// MatrixMultiply.proto ///////////////
2851
+
2852
+ // TODO: remove
2853
+ #define __Pyx_PyNumber_MatrixMultiply(x,y) PyNumber_MatrixMultiply(x,y)
2854
+ #define __Pyx_PyNumber_InPlaceMatrixMultiply(x,y) PyNumber_InPlaceMatrixMultiply(x,y)
2855
+
2856
+
2857
+ /////////////// PyDictVersioning.proto ///////////////
2858
+
2859
+ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
2860
+ #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
2861
+ #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
2862
+ #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) \
2863
+ (version_var) = __PYX_GET_DICT_VERSION(dict); \
2864
+ (cache_var) = (value);
2865
+
2866
+ #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) { \
2867
+ static PY_UINT64_T __pyx_dict_version = 0; \
2868
+ static PyObject *__pyx_dict_cached_value = NULL; \
2869
+ if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) { \
2870
+ (VAR) = __pyx_dict_cached_value; \
2871
+ } else { \
2872
+ (VAR) = __pyx_dict_cached_value = (LOOKUP); \
2873
+ __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT); \
2874
+ } \
2875
+ }
2876
+
2877
+ static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); /*proto*/
2878
+ static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); /*proto*/
2879
+ static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); /*proto*/
2880
+
2881
+ #else
2882
+ #define __PYX_GET_DICT_VERSION(dict) (0)
2883
+ #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
2884
+ #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP);
2885
+ #endif
2886
+
2887
+ /////////////// PyDictVersioning ///////////////
2888
+
2889
+ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
2890
+ static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
2891
+ PyObject *dict = Py_TYPE(obj)->tp_dict;
2892
+ return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
2893
+ }
2894
+
2895
+ static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
2896
+ PyObject **dictptr = NULL;
2897
+ Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
2898
+ if (offset) {
2899
+ #if CYTHON_COMPILING_IN_CPYTHON
2900
+ dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
2901
+ #else
2902
+ dictptr = _PyObject_GetDictPtr(obj);
2903
+ #endif
2904
+ }
2905
+ return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
2906
+ }
2907
+
2908
+ static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
2909
+ PyObject *dict = Py_TYPE(obj)->tp_dict;
2910
+ if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
2911
+ return 0;
2912
+ return obj_dict_version == __Pyx_get_object_dict_version(obj);
2913
+ }
2914
+ #endif
2915
+
2916
+ ////////////// CachedMethodType.module_state_decls ////////////
2917
+
2918
+ #if CYTHON_COMPILING_IN_LIMITED_API
2919
+ PyObject *__Pyx_CachedMethodType;
2920
+ #endif
2921
+
2922
+ ////////////// CachedMethodType.init //////////////
2923
+
2924
+ #if CYTHON_COMPILING_IN_LIMITED_API
2925
+ {
2926
+ PyObject *typesModule=NULL;
2927
+ typesModule = PyImport_ImportModule("types");
2928
+ if (typesModule) {
2929
+ CGLOBAL(__Pyx_CachedMethodType) = PyObject_GetAttrString(typesModule, "MethodType");
2930
+ Py_DECREF(typesModule);
2931
+ }
2932
+ } // error handling follows
2933
+ #endif
2934
+
2935
+ /////////////// CachedMethodType.cleanup ////////////////
2936
+
2937
+ #if CYTHON_COMPILING_IN_LIMITED_API
2938
+ Py_CLEAR(CGLOBAL(__Pyx_CachedMethodType));
2939
+ #endif
2940
+
2941
+ /////////////// PyMethodNew.proto ///////////////
2942
+
2943
+ static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ); /* proto */
2944
+
2945
+ /////////////// PyMethodNew ///////////////
2946
+ //@requires: CachedMethodType
2947
+
2948
+ #if CYTHON_COMPILING_IN_LIMITED_API
2949
+ static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) {
2950
+ PyObject *result;
2951
+ CYTHON_UNUSED_VAR(typ);
2952
+ if (!self)
2953
+ return __Pyx_NewRef(func);
2954
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030C0000
2955
+ {
2956
+ PyObject *args[] = {func, self};
2957
+ result = PyObject_Vectorcall(CGLOBAL(__Pyx_CachedMethodType), args, 2, NULL);
2958
+ }
2959
+ #else
2960
+ result = PyObject_CallFunctionObjArgs(CGLOBAL(__Pyx_CachedMethodType), func, self, NULL);
2961
+ #endif
2962
+ return result;
2963
+ }
2964
+ #else
2965
+ // This should be an actual function (not a macro), such that we can put it
2966
+ // directly in a tp_descr_get slot.
2967
+ static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) {
2968
+ CYTHON_UNUSED_VAR(typ);
2969
+ if (!self)
2970
+ return __Pyx_NewRef(func);
2971
+ return PyMethod_New(func, self);
2972
+ }
2973
+ #endif
2974
+
2975
+ ///////////// PyMethodNew2Arg.proto /////////////
2976
+ //@requires: CachedMethodType
2977
+
2978
+ // TODO: remove
2979
+ // Another wrapping of PyMethod_New that matches the Python3 signature
2980
+ #if CYTHON_COMPILING_IN_LIMITED_API
2981
+ static PyObject *__Pyx_PyMethod_New2Arg(PyObject *func, PyObject *self); /* proto */
2982
+ #else
2983
+ #define __Pyx_PyMethod_New2Arg PyMethod_New
2984
+ #endif
2985
+
2986
+ ///////////// PyMethodNew2Arg /////////////
2987
+ //@requires: CachedMethodType
2988
+
2989
+ #if CYTHON_COMPILING_IN_LIMITED_API
2990
+ static PyObject *__Pyx_PyMethod_New2Arg(PyObject *func, PyObject *self) {
2991
+ PyObject *result;
2992
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030C0000
2993
+ {
2994
+ PyObject *args[] = {func, self};
2995
+ result = PyObject_Vectorcall(CGLOBAL(__Pyx_CachedMethodType), args, 2, NULL);
2996
+ }
2997
+ #else
2998
+ result = PyObject_CallFunctionObjArgs(CGLOBAL(__Pyx_CachedMethodType), func, self, NULL);
2999
+ #endif
3000
+ return result;
3001
+ }
3002
+ #endif
3003
+
3004
+ /////////////// UnicodeConcatInPlace.proto ////////////////
3005
+
3006
+ # if CYTHON_COMPILING_IN_CPYTHON
3007
+ // __Pyx_PyUnicode_ConcatInPlace may modify the first argument 'left'
3008
+ // However, unlike `PyUnicode_Append` it will never NULL it.
3009
+ // It behaves like a regular function - returns a new reference and NULL on error
3010
+ #if CYTHON_REFNANNY
3011
+ #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right, __pyx_refnanny)
3012
+ #else
3013
+ #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right)
3014
+ #endif
3015
+ // __Pyx_PyUnicode_ConcatInPlace is slightly odd because it has the potential to modify the input
3016
+ // argument (but only in cases where no user should notice). Therefore, it needs to keep Cython's
3017
+ // refnanny informed.
3018
+ static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right
3019
+ #if CYTHON_REFNANNY
3020
+ , void* __pyx_refnanny
3021
+ #endif
3022
+ ); /* proto */
3023
+ #else
3024
+ #define __Pyx_PyUnicode_ConcatInPlace __Pyx_PyUnicode_Concat
3025
+ #endif
3026
+ #define __Pyx_PyUnicode_ConcatInPlaceSafe(left, right) ((unlikely((left) == Py_None) || unlikely((right) == Py_None)) ? \
3027
+ PyNumber_InPlaceAdd(left, right) : __Pyx_PyUnicode_ConcatInPlace(left, right))
3028
+
3029
+ /////////////// UnicodeConcatInPlace ////////////////
3030
+
3031
+ # if CYTHON_COMPILING_IN_CPYTHON
3032
+ // copied directly from unicode_object.c "unicode_modifiable
3033
+ // removing _PyUnicode_HASH since it's a macro we don't have
3034
+ // - this is OK because trying PyUnicode_Resize on a non-modifyable
3035
+ // object will still work, it just won't happen in place
3036
+ static int
3037
+ __Pyx_unicode_modifiable(PyObject *unicode)
3038
+ {
3039
+ if (Py_REFCNT(unicode) != 1)
3040
+ return 0;
3041
+ if (!PyUnicode_CheckExact(unicode))
3042
+ return 0;
3043
+ if (PyUnicode_CHECK_INTERNED(unicode))
3044
+ return 0;
3045
+ return 1;
3046
+ }
3047
+
3048
+ static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right
3049
+ #if CYTHON_REFNANNY
3050
+ , void* __pyx_refnanny
3051
+ #endif
3052
+ ) {
3053
+ // heavily based on PyUnicode_Append
3054
+ PyObject *left = *p_left;
3055
+ Py_ssize_t left_len, right_len, new_len;
3056
+
3057
+ if (unlikely(__Pyx_PyUnicode_READY(left) == -1))
3058
+ return NULL;
3059
+ if (unlikely(__Pyx_PyUnicode_READY(right) == -1))
3060
+ return NULL;
3061
+
3062
+ // Shortcuts
3063
+ left_len = PyUnicode_GET_LENGTH(left);
3064
+ if (left_len == 0) {
3065
+ Py_INCREF(right);
3066
+ return right;
3067
+ }
3068
+ right_len = PyUnicode_GET_LENGTH(right);
3069
+ if (right_len == 0) {
3070
+ Py_INCREF(left);
3071
+ return left;
3072
+ }
3073
+ if (unlikely(left_len > PY_SSIZE_T_MAX - right_len)) {
3074
+ PyErr_SetString(PyExc_OverflowError,
3075
+ "strings are too large to concat");
3076
+ return NULL;
3077
+ }
3078
+ new_len = left_len + right_len;
3079
+
3080
+ if (__Pyx_unicode_modifiable(left)
3081
+ && PyUnicode_CheckExact(right)
3082
+ && PyUnicode_KIND(right) <= PyUnicode_KIND(left)
3083
+ // Don't resize for ascii += latin1. Convert ascii to latin1 requires
3084
+ // to change the structure size, but characters are stored just after
3085
+ // the structure, and so it requires to move all characters which is
3086
+ // not so different than duplicating the string.
3087
+ && !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right))) {
3088
+
3089
+ int ret;
3090
+ // GIVEREF/GOTREF since we expect *p_left to change (although it won't change on failures).
3091
+ __Pyx_GIVEREF(*p_left);
3092
+ ret = PyUnicode_Resize(p_left, new_len);
3093
+ __Pyx_GOTREF(*p_left);
3094
+ if (unlikely(ret != 0))
3095
+ return NULL;
3096
+
3097
+ // copy 'right' into the newly allocated area of 'left'
3098
+ #if PY_VERSION_HEX >= 0x030d0000
3099
+ if (unlikely(PyUnicode_CopyCharacters(*p_left, left_len, right, 0, right_len) < 0)) return NULL;
3100
+ #else
3101
+ _PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len);
3102
+ #endif
3103
+ __Pyx_INCREF(*p_left);
3104
+ __Pyx_GIVEREF(*p_left);
3105
+ return *p_left;
3106
+ } else {
3107
+ return __Pyx_PyUnicode_Concat(left, right);
3108
+ }
3109
+ }
3110
+ #endif
3111
+
3112
+
3113
+ /////////////// PySequenceMultiply.proto ///////////////
3114
+
3115
+ #define __Pyx_PySequence_Multiply_Left(mul, seq) __Pyx_PySequence_Multiply(seq, mul)
3116
+ static CYTHON_INLINE PyObject* __Pyx_PySequence_Multiply(PyObject *seq, Py_ssize_t mul);
3117
+
3118
+ /////////////// PySequenceMultiply ///////////////
3119
+
3120
+ static PyObject* __Pyx_PySequence_Multiply_Generic(PyObject *seq, Py_ssize_t mul) {
3121
+ PyObject *result, *pymul = PyLong_FromSsize_t(mul);
3122
+ if (unlikely(!pymul))
3123
+ return NULL;
3124
+ result = PyNumber_Multiply(seq, pymul);
3125
+ Py_DECREF(pymul);
3126
+ return result;
3127
+ }
3128
+
3129
+ static CYTHON_INLINE PyObject* __Pyx_PySequence_Multiply(PyObject *seq, Py_ssize_t mul) {
3130
+ #if CYTHON_USE_TYPE_SLOTS
3131
+ PyTypeObject *type = Py_TYPE(seq);
3132
+ if (likely(type->tp_as_sequence && type->tp_as_sequence->sq_repeat)) {
3133
+ return type->tp_as_sequence->sq_repeat(seq, mul);
3134
+ } else
3135
+ #endif
3136
+ {
3137
+ return __Pyx_PySequence_Multiply_Generic(seq, mul);
3138
+ }
3139
+ }
3140
+
3141
+
3142
+ /////////////// FormatTypeName.proto ///////////////
3143
+
3144
+ #if CYTHON_COMPILING_IN_LIMITED_API
3145
+ typedef PyObject *__Pyx_TypeName;
3146
+ #define __Pyx_FMT_TYPENAME "%U"
3147
+ #define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj)
3148
+
3149
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
3150
+ #define __Pyx_PyType_GetFullyQualifiedName PyType_GetFullyQualifiedName
3151
+ #else
3152
+ static __Pyx_TypeName __Pyx_PyType_GetFullyQualifiedName(PyTypeObject* tp); /*proto*/
3153
+ #endif
3154
+ #else // !LIMITED_API
3155
+ typedef const char *__Pyx_TypeName;
3156
+ #define __Pyx_FMT_TYPENAME "%.200s"
3157
+ #define __Pyx_PyType_GetFullyQualifiedName(tp) ((tp)->tp_name)
3158
+ #define __Pyx_DECREF_TypeName(obj)
3159
+ #endif
3160
+
3161
+ /////////////// FormatTypeName ///////////////
3162
+
3163
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000
3164
+ static __Pyx_TypeName
3165
+ __Pyx_PyType_GetFullyQualifiedName(PyTypeObject* tp)
3166
+ {
3167
+ PyObject *module = NULL, *name = NULL, *result = NULL;
3168
+
3169
+ #if __PYX_LIMITED_VERSION_HEX < 0x030b0000
3170
+ name = __Pyx_PyObject_GetAttrStr((PyObject *)tp,
3171
+ PYIDENT("__qualname__"));
3172
+ #else
3173
+ name = PyType_GetQualName(tp);
3174
+ #endif
3175
+ if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) goto bad;
3176
+ module = __Pyx_PyObject_GetAttrStr((PyObject *)tp,
3177
+ PYIDENT("__module__"));
3178
+ if (unlikely(module == NULL) || unlikely(!PyUnicode_Check(module))) goto bad;
3179
+
3180
+ if (PyUnicode_CompareWithASCIIString(module, "builtins") == 0) {
3181
+ result = name;
3182
+ name = NULL;
3183
+ goto done;
3184
+ }
3185
+
3186
+ result = PyUnicode_FromFormat("%U.%U", module, name);
3187
+ if (unlikely(result == NULL)) goto bad;
3188
+
3189
+ done:
3190
+ Py_XDECREF(name);
3191
+ Py_XDECREF(module);
3192
+ return result;
3193
+
3194
+ bad:
3195
+ PyErr_Clear();
3196
+ if (name) {
3197
+ // Use this as second-best fallback
3198
+ result = name;
3199
+ name = NULL;
3200
+ } else {
3201
+ result = __Pyx_NewRef(PYUNICODE("?"));
3202
+ }
3203
+ goto done;
3204
+ }
3205
+ #endif
3206
+
3207
+
3208
+ /////////////// RaiseUnexpectedTypeError.proto ///////////////
3209
+
3210
+ static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj); /*proto*/
3211
+
3212
+ /////////////// RaiseUnexpectedTypeError ///////////////
3213
+
3214
+ static int
3215
+ __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj)
3216
+ {
3217
+ __Pyx_TypeName obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj));
3218
+ PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME,
3219
+ expected, obj_type_name);
3220
+ __Pyx_DECREF_TypeName(obj_type_name);
3221
+ return 0;
3222
+ }
3223
+
3224
+
3225
+ /////////////// RaiseUnboundLocalError.proto ///////////////
3226
+ static void __Pyx_RaiseUnboundLocalError(const char *varname);/*proto*/
3227
+
3228
+ /////////////// RaiseUnboundLocalError ///////////////
3229
+ static void __Pyx_RaiseUnboundLocalError(const char *varname) {
3230
+ PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
3231
+ }
3232
+
3233
+ /////////////// RaiseUnboundLocalErrorNogil.proto ///////////////
3234
+ static void __Pyx_RaiseUnboundLocalErrorNogil(const char *varname);/*proto*/
3235
+
3236
+ /////////////// RaiseUnboundLocalErrorNogil ///////////////
3237
+ //@requires: RaiseUnboundLocalError
3238
+
3239
+ // Don't inline the function, it should really never be called in production
3240
+ static void __Pyx_RaiseUnboundLocalErrorNogil(const char *varname) {
3241
+ PyGILState_STATE gilstate = PyGILState_Ensure();
3242
+ __Pyx_RaiseUnboundLocalError(varname);
3243
+ PyGILState_Release(gilstate);
3244
+ }
3245
+
3246
+
3247
+ /////////////// RaiseClosureNameError.proto ///////////////
3248
+ static void __Pyx_RaiseClosureNameError(const char *varname);/*proto*/
3249
+
3250
+ /////////////// RaiseClosureNameError ///////////////
3251
+ static void __Pyx_RaiseClosureNameError(const char *varname) {
3252
+ PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
3253
+ }
3254
+
3255
+ /////////////// RaiseClosureNameErrorNogil.proto ///////////////
3256
+ static void __Pyx_RaiseClosureNameErrorNogil(const char *varname);/*proto*/
3257
+
3258
+ /////////////// RaiseClosureNameErrorNogil ///////////////
3259
+ //@requires: RaiseClosureNameError
3260
+
3261
+ static void __Pyx_RaiseClosureNameErrorNogil(const char *varname) {
3262
+ PyGILState_STATE gilstate = PyGILState_Ensure();
3263
+ __Pyx_RaiseClosureNameError(varname);
3264
+ PyGILState_Release(gilstate);
3265
+ }
3266
+
3267
+ //////////////// RaiseCppGlobalNameError.proto ///////////////////////
3268
+ static void __Pyx_RaiseCppGlobalNameError(const char *varname); /*proto*/
3269
+
3270
+ /////////////// RaiseCppGlobalNameError //////////////////////////////
3271
+ static void __Pyx_RaiseCppGlobalNameError(const char *varname) {
3272
+ PyErr_Format(PyExc_NameError, "C++ global '%s' is not initialized", varname);
3273
+ }
3274
+
3275
+ //////////////// RaiseCppGlobalNameErrorNogil.proto ///////////////////////
3276
+ static void __Pyx_RaiseCppGlobalNameErrorNogil(const char *varname); /*proto*/
3277
+
3278
+ /////////////// RaiseCppGlobalNameErrorNogil //////////////////////////////
3279
+ //@requires: RaiseCppGlobalNameError
3280
+
3281
+ static void __Pyx_RaiseCppGlobalNameErrorNogil(const char *varname) {
3282
+ PyGILState_STATE gilstate = PyGILState_Ensure();
3283
+ __Pyx_RaiseCppGlobalNameError(varname);
3284
+ PyGILState_Release(gilstate);
3285
+ }
3286
+
3287
+ //////////////// RaiseCppAttributeError.proto ///////////////////////
3288
+ static void __Pyx_RaiseCppAttributeError(const char *varname); /*proto*/
3289
+
3290
+ /////////////// RaiseCppAttributeError //////////////////////////////
3291
+ static void __Pyx_RaiseCppAttributeError(const char *varname) {
3292
+ PyErr_Format(PyExc_AttributeError, "C++ attribute '%s' is not initialized", varname);
3293
+ }
3294
+
3295
+ //////////////// RaiseCppAttributeErrorNogil.proto ///////////////////////
3296
+ static void __Pyx_RaiseCppAttributeErrorNogil(const char *varname); /*proto*/
3297
+
3298
+ /////////////// RaiseCppAttributeErrorNogil //////////////////////////////
3299
+ //@requires: RaiseCppGlobalNameError
3300
+
3301
+ static void __Pyx_RaiseCppAttributeErrorNogil(const char *varname) {
3302
+ PyGILState_STATE gilstate = PyGILState_Ensure();
3303
+ __Pyx_RaiseCppAttributeError(varname);
3304
+ PyGILState_Release(gilstate);
3305
+ }
3306
+
3307
+ /////////////// ListPack.proto //////////////////////////////////////
3308
+
3309
+ // Equivalent to PyTuple_Pack for sections where we want to reduce the code size
3310
+ static PyObject *__Pyx_PyList_Pack(Py_ssize_t n, ...); /* proto */
3311
+
3312
+ /////////////// ListPack //////////////////////////////////////
3313
+
3314
+ static PyObject *__Pyx_PyList_Pack(Py_ssize_t n, ...) {
3315
+ va_list va;
3316
+ PyObject *l = PyList_New(n);
3317
+ va_start(va, n);
3318
+ if (unlikely(!l)) goto end;
3319
+
3320
+ for (Py_ssize_t i=0; i<n; ++i) {
3321
+ PyObject *arg = va_arg(va, PyObject*);
3322
+ Py_INCREF(arg);
3323
+ if (__Pyx_PyList_SET_ITEM(l, i, arg) != (0)) {
3324
+ Py_CLEAR(l);
3325
+ goto end;
3326
+ }
3327
+ }
3328
+
3329
+ end:
3330
+ va_end(va);
3331
+ return l;
3332
+ }
3333
+
3334
+ /////////////// LengthHint.proto //////////////////////////////////////
3335
+
3336
+ #if CYTHON_COMPILING_IN_LIMITED_API
3337
+ // We could reimplement it fully, however since it's only an optimization
3338
+ // the simpler version is to make it the default.
3339
+ #define __Pyx_PyObject_LengthHint(o, defaultval) (defaultval)
3340
+ #else
3341
+ #define __Pyx_PyObject_LengthHint(o, defaultval) PyObject_LengthHint(o, defaultval)
3342
+ #endif