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,809 @@
1
+ /////////////// FixUpExtensionType.proto ///////////////
2
+
3
+ static CYTHON_INLINE int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); /*proto*/
4
+
5
+ /////////////// FixUpExtensionType ///////////////
6
+ //@requires:ModuleSetupCode.c::IncludeStructmemberH
7
+ //@requires:StringTools.c::IncludeStringH
8
+
9
+ static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) {
10
+ #if PY_VERSION_HEX > 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API
11
+ CYTHON_UNUSED_VAR(spec);
12
+ CYTHON_UNUSED_VAR(type);
13
+ #else
14
+ // Set tp_weakreflist, tp_dictoffset, tp_vectorcalloffset
15
+ // Copied and adapted from https://bugs.python.org/issue38140
16
+ const PyType_Slot *slot = spec->slots;
17
+ while (slot && slot->slot && slot->slot != Py_tp_members)
18
+ slot++;
19
+ if (slot && slot->slot == Py_tp_members) {
20
+ int changed = 0;
21
+ #if !(PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON)
22
+ const
23
+ #endif
24
+ PyMemberDef *memb = (PyMemberDef*) slot->pfunc;
25
+ while (memb && memb->name) {
26
+ if (memb->name[0] == '_' && memb->name[1] == '_') {
27
+ #if PY_VERSION_HEX < 0x030900b1
28
+ if (strcmp(memb->name, "__weaklistoffset__") == 0) {
29
+ // The PyMemberDef must be a Py_ssize_t and readonly.
30
+ assert(memb->type == T_PYSSIZET);
31
+ assert(memb->flags == READONLY);
32
+ type->tp_weaklistoffset = memb->offset;
33
+ // FIXME: is it even worth calling PyType_Modified() here?
34
+ changed = 1;
35
+ }
36
+ else if (strcmp(memb->name, "__dictoffset__") == 0) {
37
+ // The PyMemberDef must be a Py_ssize_t and readonly.
38
+ assert(memb->type == T_PYSSIZET);
39
+ assert(memb->flags == READONLY);
40
+ type->tp_dictoffset = memb->offset;
41
+ // FIXME: is it even worth calling PyType_Modified() here?
42
+ changed = 1;
43
+ }
44
+ #if CYTHON_METH_FASTCALL
45
+ else if (strcmp(memb->name, "__vectorcalloffset__") == 0) {
46
+ // The PyMemberDef must be a Py_ssize_t and readonly.
47
+ assert(memb->type == T_PYSSIZET);
48
+ assert(memb->flags == READONLY);
49
+ #if PY_VERSION_HEX >= 0x030800b4
50
+ type->tp_vectorcall_offset = memb->offset;
51
+ #else
52
+ type->tp_print = (printfunc) memb->offset;
53
+ #endif
54
+ // FIXME: is it even worth calling PyType_Modified() here?
55
+ changed = 1;
56
+ }
57
+ #endif
58
+ #else
59
+ if ((0));
60
+ #endif
61
+ #if PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON
62
+ else if (strcmp(memb->name, "__module__") == 0) {
63
+ // PyType_FromSpec() in CPython <= 3.9b1 overwrites this field with a constant string.
64
+ // See https://bugs.python.org/issue40703
65
+ PyObject *descr;
66
+ // The PyMemberDef must be an object and normally readable, possibly writable.
67
+ assert(memb->type == T_OBJECT);
68
+ assert(memb->flags == 0 || memb->flags == READONLY);
69
+ descr = PyDescr_NewMember(type, memb);
70
+ if (unlikely(!descr))
71
+ return -1;
72
+ if (unlikely(PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr) < 0)) {
73
+ Py_DECREF(descr);
74
+ return -1;
75
+ }
76
+ Py_DECREF(descr);
77
+ changed = 1;
78
+ }
79
+ #endif
80
+ }
81
+ memb++;
82
+ }
83
+ if (changed)
84
+ PyType_Modified(type);
85
+ }
86
+ #endif
87
+ return 0;
88
+ }
89
+
90
+
91
+ /////////////// ValidateBasesTuple.proto ///////////////
92
+
93
+ #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS
94
+ static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); /*proto*/
95
+ #endif
96
+
97
+ /////////////// ValidateBasesTuple ///////////////
98
+
99
+ #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS
100
+ static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) {
101
+ // Loop over all bases (except the first) and check that those
102
+ // really are heap types. Otherwise, it would not be safe to
103
+ // subclass them.
104
+ //
105
+ // We also check tp_dictoffset: it is unsafe to inherit
106
+ // tp_dictoffset from a base class because the object structures
107
+ // would not be compatible. So, if our extension type doesn't set
108
+ // tp_dictoffset (i.e. there is no __dict__ attribute in the object
109
+ // structure), we need to check that none of the base classes sets
110
+ // it either.
111
+ Py_ssize_t i, n;
112
+ #if CYTHON_ASSUME_SAFE_SIZE
113
+ n = PyTuple_GET_SIZE(bases);
114
+ #else
115
+ n = PyTuple_Size(bases);
116
+ if (unlikely(n < 0)) return -1;
117
+ #endif
118
+ for (i = 1; i < n; i++) /* Skip first base */
119
+ {
120
+ PyTypeObject *b;
121
+ #if CYTHON_AVOID_BORROWED_REFS
122
+ PyObject *b0 = PySequence_GetItem(bases, i);
123
+ if (!b0) return -1;
124
+ #elif CYTHON_ASSUME_SAFE_MACROS
125
+ PyObject *b0 = PyTuple_GET_ITEM(bases, i);
126
+ #else
127
+ PyObject *b0 = PyTuple_GetItem(bases, i);
128
+ if (!b0) return -1;
129
+ #endif
130
+ b = (PyTypeObject*) b0;
131
+ if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE))
132
+ {
133
+ __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b);
134
+ PyErr_Format(PyExc_TypeError,
135
+ "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name);
136
+ __Pyx_DECREF_TypeName(b_name);
137
+ #if CYTHON_AVOID_BORROWED_REFS
138
+ Py_DECREF(b0);
139
+ #endif
140
+ return -1;
141
+ }
142
+ if (dictoffset == 0)
143
+ {
144
+ Py_ssize_t b_dictoffset = 0;
145
+ #if CYTHON_USE_TYPE_SLOTS
146
+ b_dictoffset = b->tp_dictoffset;
147
+ #else
148
+ PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__");
149
+ if (!py_b_dictoffset) goto dictoffset_return;
150
+ b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset);
151
+ Py_DECREF(py_b_dictoffset);
152
+ if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return;
153
+ #endif
154
+ if (b_dictoffset) {
155
+ {
156
+ __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(b);
157
+ PyErr_Format(PyExc_TypeError,
158
+ "extension type '%.200s' has no __dict__ slot, "
159
+ "but base type '" __Pyx_FMT_TYPENAME "' has: "
160
+ "either add 'cdef dict __dict__' to the extension type "
161
+ "or add '__slots__ = [...]' to the base type",
162
+ type_name, b_name);
163
+ __Pyx_DECREF_TypeName(b_name);
164
+ }
165
+ #if !CYTHON_USE_TYPE_SLOTS
166
+ dictoffset_return:
167
+ #endif
168
+ #if CYTHON_AVOID_BORROWED_REFS
169
+ Py_DECREF(b0);
170
+ #endif
171
+ return -1;
172
+ }
173
+ }
174
+ #if CYTHON_AVOID_BORROWED_REFS
175
+ Py_DECREF(b0);
176
+ #endif
177
+ }
178
+ return 0;
179
+ }
180
+ #endif
181
+
182
+
183
+ /////////////// PyType_Ready.proto ///////////////
184
+
185
+ // unused when using type specs
186
+ CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t);/*proto*/
187
+
188
+ /////////////// PyType_Ready ///////////////
189
+ //@requires: ObjectHandling.c::PyObjectCallMethod0
190
+ //@requires: ValidateBasesTuple
191
+
192
+ CYTHON_UNUSED static int __Pyx_PyType_HasMultipleInheritance(PyTypeObject *t) {
193
+ while (t) {
194
+ PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*);
195
+ if (bases) {
196
+ return 1;
197
+ }
198
+ t = __Pyx_PyType_GetSlot(t, tp_base, PyTypeObject*);
199
+ }
200
+ return 0;
201
+ }
202
+
203
+ // Wrapper around PyType_Ready() with some runtime checks and fixes
204
+ // to deal with multiple inheritance.
205
+ static int __Pyx_PyType_Ready(PyTypeObject *t) {
206
+
207
+ #if CYTHON_USE_TYPE_SPECS || !CYTHON_COMPILING_IN_CPYTHON || defined(PYSTON_MAJOR_VERSION)
208
+ // avoid C warning about unused helper function
209
+ (void)__Pyx_PyObject_CallMethod0;
210
+ #if CYTHON_USE_TYPE_SPECS
211
+ (void)__Pyx_validate_bases_tuple;
212
+ #endif
213
+
214
+ return PyType_Ready(t);
215
+
216
+ #else
217
+ int r;
218
+
219
+ if (!__Pyx_PyType_HasMultipleInheritance(t)) {
220
+ // shortcut - if none of the base classes do multiple inheritance then we don't need to
221
+ // (and shouldn't) mess around with faking heaptypes.
222
+ return PyType_Ready(t);
223
+ }
224
+ PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*);
225
+ if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1))
226
+ return -1;
227
+
228
+ #if !defined(PYSTON_MAJOR_VERSION)
229
+ {
230
+ // Make sure GC does not pick up our non-heap type as heap type with this hack!
231
+ // For details, see https://github.com/cython/cython/issues/3603
232
+ int gc_was_enabled;
233
+ #if PY_VERSION_HEX >= 0x030A00b1
234
+ // finally added in Py3.10 :)
235
+ gc_was_enabled = PyGC_Disable();
236
+ (void)__Pyx_PyObject_CallMethod0;
237
+
238
+ #else
239
+ // Call gc.disable() as a backwards compatible fallback, but only if needed.
240
+ PyObject *ret, *py_status;
241
+ PyObject *gc = NULL;
242
+ #if (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) && \
243
+ !CYTHON_COMPILING_IN_GRAAL
244
+ // https://foss.heptapod.net/pypy/pypy/-/issues/3385
245
+ gc = PyImport_GetModule(PYUNICODE("gc"));
246
+ #endif
247
+ if (unlikely(!gc)) gc = PyImport_Import(PYUNICODE("gc"));
248
+ if (unlikely(!gc)) return -1;
249
+ py_status = __Pyx_PyObject_CallMethod0(gc, PYUNICODE("isenabled"));
250
+ if (unlikely(!py_status)) {
251
+ Py_DECREF(gc);
252
+ return -1;
253
+ }
254
+ gc_was_enabled = __Pyx_PyObject_IsTrue(py_status);
255
+ Py_DECREF(py_status);
256
+ if (gc_was_enabled > 0) {
257
+ ret = __Pyx_PyObject_CallMethod0(gc, PYUNICODE("disable"));
258
+ if (unlikely(!ret)) {
259
+ Py_DECREF(gc);
260
+ return -1;
261
+ }
262
+ Py_DECREF(ret);
263
+ } else if (unlikely(gc_was_enabled == -1)) {
264
+ Py_DECREF(gc);
265
+ return -1;
266
+ }
267
+ #endif
268
+
269
+ // As of https://github.com/python/cpython/issues/66277
270
+ // PyType_Ready enforces that all bases of a non-heap type are
271
+ // non-heap. We know that this is the case for the solid base but
272
+ // other bases are heap allocated and are kept alive through the
273
+ // tp_bases reference.
274
+ // Other than this check, the Py_TPFLAGS_HEAPTYPE flag is unused
275
+ // in PyType_Ready().
276
+ t->tp_flags |= Py_TPFLAGS_HEAPTYPE;
277
+ #if PY_VERSION_HEX >= 0x030A0000
278
+ // As of https://github.com/python/cpython/pull/25520
279
+ // PyType_Ready marks types as immutable if they are static types
280
+ // and requires the Py_TPFLAGS_IMMUTABLETYPE flag to mark types as
281
+ // immutable
282
+ // Manually set the Py_TPFLAGS_IMMUTABLETYPE flag, since the type
283
+ // is immutable
284
+ t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE;
285
+ #endif
286
+ #else
287
+ // avoid C warning about unused helper function
288
+ (void)__Pyx_PyObject_CallMethod0;
289
+ #endif
290
+
291
+ r = PyType_Ready(t);
292
+
293
+ #if !defined(PYSTON_MAJOR_VERSION)
294
+ t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
295
+
296
+ #if PY_VERSION_HEX >= 0x030A00b1
297
+ if (gc_was_enabled)
298
+ PyGC_Enable();
299
+ #else
300
+ if (gc_was_enabled) {
301
+ PyObject *tp, *v, *tb;
302
+ PyErr_Fetch(&tp, &v, &tb);
303
+ ret = __Pyx_PyObject_CallMethod0(gc, PYUNICODE("enable"));
304
+ if (likely(ret || r == -1)) {
305
+ Py_XDECREF(ret);
306
+ // do not overwrite exceptions raised by PyType_Ready() above
307
+ PyErr_Restore(tp, v, tb);
308
+ } else {
309
+ // PyType_Ready() succeeded, but gc.enable() failed.
310
+ Py_XDECREF(tp);
311
+ Py_XDECREF(v);
312
+ Py_XDECREF(tb);
313
+ r = -1;
314
+ }
315
+ }
316
+ Py_DECREF(gc);
317
+ #endif
318
+ }
319
+ #endif
320
+
321
+ return r;
322
+ #endif
323
+ }
324
+
325
+
326
+ /////////////// PyTrashcan.proto ///////////////
327
+
328
+ // These macros are taken from https://github.com/python/cpython/pull/11841
329
+ // Unlike the Py_TRASHCAN_SAFE_BEGIN/Py_TRASHCAN_SAFE_END macros, they
330
+ // allow dealing correctly with subclasses.
331
+
332
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03080000
333
+ // https://github.com/python/cpython/pull/11841 merged so Cython reimplementation
334
+ // is no longer necessary
335
+ #define __Pyx_TRASHCAN_BEGIN Py_TRASHCAN_BEGIN
336
+ #define __Pyx_TRASHCAN_END Py_TRASHCAN_END
337
+
338
+ #elif CYTHON_COMPILING_IN_CPYTHON
339
+
340
+ #define __Pyx_TRASHCAN_BEGIN_CONDITION(op, cond) \
341
+ do { \
342
+ PyThreadState *_tstate = NULL; \
343
+ // If "cond" is false, then _tstate remains NULL and the deallocator
344
+ // is run normally without involving the trashcan
345
+ if (cond) { \
346
+ _tstate = PyThreadState_GET(); \
347
+ if (_tstate->trash_delete_nesting >= PyTrash_UNWIND_LEVEL) { \
348
+ // Store the object (to be deallocated later) and jump past
349
+ // Py_TRASHCAN_END, skipping the body of the deallocator
350
+ _PyTrash_thread_deposit_object((PyObject*)(op)); \
351
+ break; \
352
+ } \
353
+ ++_tstate->trash_delete_nesting; \
354
+ }
355
+ // The body of the deallocator is here.
356
+ #define __Pyx_TRASHCAN_END \
357
+ if (_tstate) { \
358
+ --_tstate->trash_delete_nesting; \
359
+ if (_tstate->trash_delete_later && _tstate->trash_delete_nesting <= 0) \
360
+ _PyTrash_thread_destroy_chain(); \
361
+ } \
362
+ } while (0);
363
+
364
+ #define __Pyx_TRASHCAN_BEGIN(op, dealloc) __Pyx_TRASHCAN_BEGIN_CONDITION(op, \
365
+ __Pyx_PyObject_GetSlot(op, tp_dealloc, destructor) == (destructor)(dealloc))
366
+
367
+ #else
368
+ // The trashcan is a no-op on other Python implementations
369
+ // or old CPython versions
370
+ #define __Pyx_TRASHCAN_BEGIN(op, dealloc)
371
+ #define __Pyx_TRASHCAN_END
372
+ #endif
373
+
374
+ /////////////// CallNextTpDealloc.proto ///////////////
375
+
376
+ static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);
377
+
378
+ /////////////// CallNextTpDealloc ///////////////
379
+
380
+ static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc) {
381
+ PyTypeObject* type = Py_TYPE(obj);
382
+ destructor tp_dealloc = NULL;
383
+ /* try to find the first parent type that has a different tp_dealloc() function */
384
+ while (type && __Pyx_PyType_GetSlot(type, tp_dealloc, destructor) != current_tp_dealloc)
385
+ type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
386
+ while (type && (tp_dealloc = __Pyx_PyType_GetSlot(type, tp_dealloc, destructor)) == current_tp_dealloc)
387
+ type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
388
+ if (type)
389
+ tp_dealloc(obj);
390
+ }
391
+
392
+ /////////////// CallNextTpTraverse.proto ///////////////
393
+
394
+ static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse);
395
+
396
+ /////////////// CallNextTpTraverse ///////////////
397
+
398
+ static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) {
399
+ PyTypeObject* type = Py_TYPE(obj);
400
+ traverseproc tp_traverse = NULL;
401
+ /* try to find the first parent type that has a different tp_traverse() function */
402
+ while (type && __Pyx_PyType_GetSlot(type, tp_traverse, traverseproc) != current_tp_traverse)
403
+ type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
404
+ while (type && (tp_traverse = __Pyx_PyType_GetSlot(type, tp_traverse, traverseproc)) == current_tp_traverse)
405
+ type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
406
+ if (type && tp_traverse)
407
+ return tp_traverse(obj, v, a);
408
+ // FIXME: really ignore?
409
+ return 0;
410
+ }
411
+
412
+ /////////////// CallNextTpClear.proto ///////////////
413
+
414
+ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear);
415
+
416
+ /////////////// CallNextTpClear ///////////////
417
+
418
+ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
419
+ PyTypeObject* type = Py_TYPE(obj);
420
+ inquiry tp_clear = NULL;
421
+ /* try to find the first parent type that has a different tp_clear() function */
422
+ while (type && __Pyx_PyType_GetSlot(type, tp_clear, inquiry) != current_tp_clear)
423
+ type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
424
+ while (type && (tp_clear = __Pyx_PyType_GetSlot(type, tp_clear, inquiry)) == current_tp_clear)
425
+ type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
426
+ if (type && tp_clear)
427
+ tp_clear(obj);
428
+ }
429
+
430
+
431
+ /////////////// SetupReduce.proto ///////////////
432
+
433
+ static int __Pyx_setup_reduce(PyObject* type_obj);
434
+
435
+ /////////////// SetupReduce ///////////////
436
+ //@requires: ObjectHandling.c::PyObjectGetAttrStrNoError
437
+ //@requires: ObjectHandling.c::PyObjectGetAttrStr
438
+ //@requires: SetItemOnTypeDict
439
+ //@requires: DelItemOnTypeDict
440
+
441
+ static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
442
+ int ret;
443
+ PyObject *name_attr;
444
+
445
+ name_attr = __Pyx_PyObject_GetAttrStrNoError(meth, PYIDENT("__name__"));
446
+ if (likely(name_attr)) {
447
+ ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
448
+ } else {
449
+ ret = -1;
450
+ }
451
+
452
+ if (unlikely(ret < 0)) {
453
+ PyErr_Clear();
454
+ ret = 0;
455
+ }
456
+
457
+ Py_XDECREF(name_attr);
458
+ return ret;
459
+ }
460
+
461
+ static int __Pyx_setup_reduce(PyObject* type_obj) {
462
+ int ret = 0;
463
+ PyObject *object_reduce = NULL;
464
+ PyObject *object_getstate = NULL;
465
+ PyObject *object_reduce_ex = NULL;
466
+ PyObject *reduce = NULL;
467
+ PyObject *reduce_ex = NULL;
468
+ PyObject *reduce_cython = NULL;
469
+ PyObject *setstate = NULL;
470
+ PyObject *setstate_cython = NULL;
471
+ PyObject *getstate = NULL;
472
+
473
+ #if CYTHON_USE_PYTYPE_LOOKUP
474
+ getstate = _PyType_Lookup((PyTypeObject*)type_obj, PYIDENT("__getstate__"));
475
+ #else
476
+ getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__getstate__"));
477
+ if (!getstate && PyErr_Occurred()) {
478
+ goto __PYX_BAD;
479
+ }
480
+ #endif
481
+ if (getstate) {
482
+ // Python 3.11 introduces object.__getstate__. Because it's version-specific failure to find it should not be an error
483
+ #if CYTHON_USE_PYTYPE_LOOKUP
484
+ object_getstate = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__getstate__"));
485
+ #else
486
+ object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, PYIDENT("__getstate__"));
487
+ if (!object_getstate && PyErr_Occurred()) {
488
+ goto __PYX_BAD;
489
+ }
490
+ #endif
491
+ if (object_getstate != getstate) {
492
+ goto __PYX_GOOD;
493
+ }
494
+ }
495
+
496
+ #if CYTHON_USE_PYTYPE_LOOKUP
497
+ object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__reduce_ex__")); if (!object_reduce_ex) goto __PYX_BAD;
498
+ #else
499
+ object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce_ex__")); if (!object_reduce_ex) goto __PYX_BAD;
500
+ #endif
501
+
502
+ reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce_ex__")); if (unlikely(!reduce_ex)) goto __PYX_BAD;
503
+ if (reduce_ex == object_reduce_ex) {
504
+
505
+ #if CYTHON_USE_PYTYPE_LOOKUP
506
+ object_reduce = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__reduce__")); if (!object_reduce) goto __PYX_BAD;
507
+ #else
508
+ object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce__")); if (!object_reduce) goto __PYX_BAD;
509
+ #endif
510
+ reduce = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce__")); if (unlikely(!reduce)) goto __PYX_BAD;
511
+
512
+ if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, PYIDENT("__reduce_cython__"))) {
513
+ reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__reduce_cython__"));
514
+ if (likely(reduce_cython)) {
515
+ ret = __Pyx_SetItemOnTypeDict((PyTypeObject*)type_obj, PYIDENT("__reduce__"), reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
516
+ ret = __Pyx_DelItemOnTypeDict((PyTypeObject*)type_obj, PYIDENT("__reduce_cython__")); if (unlikely(ret < 0)) goto __PYX_BAD;
517
+ } else if (reduce == object_reduce || PyErr_Occurred()) {
518
+ // Ignore if we're done, i.e. if 'reduce' already has the right name and the original is gone.
519
+ // Otherwise: error.
520
+ goto __PYX_BAD;
521
+ }
522
+
523
+ setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__setstate__"));
524
+ if (!setstate) PyErr_Clear();
525
+ if (!setstate || __Pyx_setup_reduce_is_named(setstate, PYIDENT("__setstate_cython__"))) {
526
+ setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__setstate_cython__"));
527
+ if (likely(setstate_cython)) {
528
+ ret = __Pyx_SetItemOnTypeDict((PyTypeObject*)type_obj, PYIDENT("__setstate__"), setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
529
+ ret = __Pyx_DelItemOnTypeDict((PyTypeObject*)type_obj, PYIDENT("__setstate_cython__")); if (unlikely(ret < 0)) goto __PYX_BAD;
530
+ } else if (!setstate || PyErr_Occurred()) {
531
+ // Ignore if we're done, i.e. if 'setstate' already has the right name and the original is gone.
532
+ // Otherwise: error.
533
+ goto __PYX_BAD;
534
+ }
535
+ }
536
+ PyType_Modified((PyTypeObject*)type_obj);
537
+ }
538
+ }
539
+ goto __PYX_GOOD;
540
+
541
+ __PYX_BAD:
542
+ if (!PyErr_Occurred()) {
543
+ __Pyx_TypeName type_obj_name =
544
+ __Pyx_PyType_GetFullyQualifiedName((PyTypeObject*)type_obj);
545
+ PyErr_Format(PyExc_RuntimeError,
546
+ "Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name);
547
+ __Pyx_DECREF_TypeName(type_obj_name);
548
+ }
549
+ ret = -1;
550
+ __PYX_GOOD:
551
+ #if !CYTHON_USE_PYTYPE_LOOKUP
552
+ Py_XDECREF(object_reduce);
553
+ Py_XDECREF(object_reduce_ex);
554
+ Py_XDECREF(object_getstate);
555
+ Py_XDECREF(getstate);
556
+ #endif
557
+ Py_XDECREF(reduce);
558
+ Py_XDECREF(reduce_ex);
559
+ Py_XDECREF(reduce_cython);
560
+ Py_XDECREF(setstate);
561
+ Py_XDECREF(setstate_cython);
562
+ return ret;
563
+ }
564
+
565
+
566
+ /////////////// BinopSlot ///////////////
567
+
568
+ static CYTHON_INLINE PyObject *{{func_name}}_maybe_call_slot(PyTypeObject* type, PyObject *left, PyObject *right {{extra_arg_decl}}) {
569
+ {{slot_type}} slot;
570
+ #if CYTHON_USE_TYPE_SLOTS
571
+ slot = type->tp_as_number ? type->tp_as_number->{{slot_name}} : NULL;
572
+ #else
573
+ slot = ({{slot_type}}) PyType_GetSlot(type, Py_{{slot_name}});
574
+ #endif
575
+ return slot ? slot(left, right {{extra_arg}}) : __Pyx_NewRef(Py_NotImplemented);
576
+ }
577
+
578
+ static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}}) {
579
+ int maybe_self_is_left, maybe_self_is_right = 0;
580
+ maybe_self_is_left = Py_TYPE(left) == Py_TYPE(right)
581
+ #if CYTHON_USE_TYPE_SLOTS
582
+ || (Py_TYPE(left)->tp_as_number && Py_TYPE(left)->tp_as_number->{{slot_name}} == &{{func_name}})
583
+ #endif
584
+ || __Pyx_TypeCheck(left, {{type_cname}});
585
+
586
+ // Optimize for the common case where the left operation is defined (and successful).
587
+ {{if not overloads_left}}
588
+ maybe_self_is_right = Py_TYPE(left) == Py_TYPE(right)
589
+ #if CYTHON_USE_TYPE_SLOTS
590
+ || (Py_TYPE(right)->tp_as_number && Py_TYPE(right)->tp_as_number->{{slot_name}} == &{{func_name}})
591
+ #endif
592
+ || __Pyx_TypeCheck(right, {{type_cname}});
593
+ {{endif}}
594
+
595
+ if (maybe_self_is_left) {
596
+ PyObject *res;
597
+
598
+ {{if overloads_right and not overloads_left}}
599
+ if (maybe_self_is_right) {
600
+ res = {{call_right}};
601
+ if (res != Py_NotImplemented) return res;
602
+ Py_DECREF(res);
603
+ // Don't bother calling it again.
604
+ maybe_self_is_right = 0;
605
+ }
606
+ {{endif}}
607
+
608
+ res = {{call_left}};
609
+ if (res != Py_NotImplemented) return res;
610
+ Py_DECREF(res);
611
+ }
612
+
613
+ {{if overloads_left}}
614
+ maybe_self_is_right = Py_TYPE(left) == Py_TYPE(right)
615
+ #if CYTHON_USE_TYPE_SLOTS
616
+ || (Py_TYPE(right)->tp_as_number && Py_TYPE(right)->tp_as_number->{{slot_name}} == &{{func_name}})
617
+ #endif
618
+ || PyType_IsSubtype(Py_TYPE(right), {{type_cname}});
619
+ {{endif}}
620
+
621
+ if (maybe_self_is_right) {
622
+ return {{call_right}};
623
+ }
624
+ return __Pyx_NewRef(Py_NotImplemented);
625
+ }
626
+
627
+ /////////////// ValidateExternBase.proto ///////////////
628
+
629
+ static int __Pyx_validate_extern_base(PyTypeObject *base); /* proto */
630
+
631
+ /////////////// ValidateExternBase ///////////////
632
+ //@requires: ObjectHandling.c::FormatTypeName
633
+
634
+ static int __Pyx_validate_extern_base(PyTypeObject *base) {
635
+ Py_ssize_t itemsize;
636
+ #if CYTHON_COMPILING_IN_LIMITED_API
637
+ PyObject *py_itemsize;
638
+ #endif
639
+ #if !CYTHON_COMPILING_IN_LIMITED_API
640
+ itemsize = ((PyTypeObject *)base)->tp_itemsize;
641
+ #else
642
+ py_itemsize = PyObject_GetAttrString((PyObject*)base, "__itemsize__");
643
+ if (!py_itemsize)
644
+ return -1;
645
+ itemsize = PyLong_AsSsize_t(py_itemsize);
646
+ Py_DECREF(py_itemsize);
647
+ py_itemsize = 0;
648
+ if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred())
649
+ return -1;
650
+ #endif
651
+ if (itemsize) {
652
+ __Pyx_TypeName b_name = __Pyx_PyType_GetFullyQualifiedName(base);
653
+ PyErr_Format(PyExc_TypeError,
654
+ "inheritance from PyVarObject types like '" __Pyx_FMT_TYPENAME "' not currently supported", b_name);
655
+ __Pyx_DECREF_TypeName(b_name);
656
+ return -1;
657
+ }
658
+ return 0;
659
+ }
660
+
661
+ /////////////// CallTypeTraverse.proto /////////////////////
662
+
663
+ #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000)
664
+ // Without type specs, we're never responsible for this.
665
+ // If we *know* the Python version is less that 3.9 we're also not responsible
666
+ #define __Pyx_call_type_traverse(o, always_call, visit, arg) 0
667
+ #else
668
+ static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg); /* proto */
669
+ #endif
670
+
671
+ /////////////// CallTypeTraverse ////////////////////////////
672
+
673
+ #if !CYTHON_USE_TYPE_SPECS || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x03090000)
674
+ // nothing to do
675
+ #else
676
+ static int __Pyx_call_type_traverse(PyObject *o, int always_call, visitproc visit, void *arg) {
677
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x03090000
678
+ // We have to work out whether to call traverse based on the runtime version.
679
+ // __Pyx_get_runtime_version is always available so no need to require it.
680
+ if (__Pyx_get_runtime_version() < 0x03090000) return 0;
681
+ #endif
682
+ if (!always_call) {
683
+ // Written with reference to https://docs.python.org/3/howto/isolating-extensions.html
684
+ PyTypeObject *base = __Pyx_PyObject_GetSlot(o, tp_base, PyTypeObject*);
685
+ unsigned long flags = PyType_GetFlags(base);
686
+ if (flags & Py_TPFLAGS_HEAPTYPE) {
687
+ // The base class should have handled it
688
+ return 0;
689
+ }
690
+ }
691
+ Py_VISIT((PyObject*)Py_TYPE(o));
692
+ return 0;
693
+ }
694
+ #endif
695
+
696
+
697
+ ////////////////// LimitedApiGetTypeDict.proto //////////////////////
698
+
699
+ #if CYTHON_COMPILING_IN_LIMITED_API
700
+ // This is a little hacky - the Limited API works quite hard to stop us getting
701
+ // the dict of a type object. But apparently not hard enough...
702
+ //
703
+ // In future we should prefer to work with mutable types, and then make them immutable
704
+ // once we're done (pending C API support for this).
705
+ static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp); /* proto */
706
+ #endif
707
+
708
+ ////////////////// LimitedApiGetTypeDict //////////////////////
709
+
710
+ #if CYTHON_COMPILING_IN_LIMITED_API
711
+ static Py_ssize_t __Pyx_GetTypeDictOffset(void) {
712
+ PyObject *tp_dictoffset_o;
713
+ Py_ssize_t tp_dictoffset;
714
+ tp_dictoffset_o = PyObject_GetAttrString((PyObject*)(&PyType_Type), "__dictoffset__");
715
+ if (unlikely(!tp_dictoffset_o)) return -1;
716
+ tp_dictoffset = PyLong_AsSsize_t(tp_dictoffset_o);
717
+ Py_DECREF(tp_dictoffset_o);
718
+
719
+ if (unlikely(tp_dictoffset == 0)) {
720
+ PyErr_SetString(
721
+ PyExc_TypeError,
722
+ "'type' doesn't have a dictoffset");
723
+ return -1;
724
+ } else if (unlikely(tp_dictoffset < 0)) {
725
+ // This isn't completely future proof. dictoffset can be
726
+ // negative, but isn't in Python <=3.13 (current at time
727
+ // of writing). It's awkward to calculate in the limited
728
+ // API because we need to know the object size. For now
729
+ // just raise an error and fix it if it every changes.
730
+ PyErr_SetString(
731
+ PyExc_TypeError,
732
+ "'type' has an unexpected negative dictoffset. "
733
+ "Please report this as Cython bug");
734
+ return -1;
735
+ }
736
+
737
+ return tp_dictoffset;
738
+ }
739
+
740
+ static PyObject *__Pyx_GetTypeDict(PyTypeObject *tp) {
741
+ // TODO - if we ever support custom metatypes for extension types then
742
+ // we have to modify this caching.
743
+ static Py_ssize_t tp_dictoffset = 0;
744
+ if (unlikely(tp_dictoffset == 0)) {
745
+ tp_dictoffset = __Pyx_GetTypeDictOffset();
746
+ // Note that negative dictoffsets are definitely allowed.
747
+ // A dictoffset of -1 seems unlikely but isn't obviously forbidden.
748
+ if (unlikely(tp_dictoffset == -1 && PyErr_Occurred())) {
749
+ tp_dictoffset = 0; // try again next time?
750
+ return NULL;
751
+ }
752
+ }
753
+ return *(PyObject**)((char*)tp + tp_dictoffset);
754
+ }
755
+ #endif
756
+
757
+
758
+ ////////////////// SetItemOnTypeDict.proto //////////////////////////
759
+ //@requires: LimitedApiGetTypeDict
760
+
761
+ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v); /* proto */
762
+
763
+ #define __Pyx_SetItemOnTypeDict(tp, k, v) __Pyx__SetItemOnTypeDict((PyTypeObject*)tp, k, v)
764
+
765
+ ////////////////// SetItemOnTypeDict //////////////////////////
766
+
767
+ static int __Pyx__SetItemOnTypeDict(PyTypeObject *tp, PyObject *k, PyObject *v) {
768
+ int result;
769
+ PyObject *tp_dict;
770
+ #if CYTHON_COMPILING_IN_LIMITED_API
771
+ tp_dict = __Pyx_GetTypeDict(tp);
772
+ if (unlikely(!tp_dict)) return -1;
773
+ #else
774
+ tp_dict = tp->tp_dict;
775
+ #endif
776
+ result = PyDict_SetItem(tp_dict, k, v);
777
+ if (likely(!result)) {
778
+ PyType_Modified(tp);
779
+ if (unlikely(PyObject_HasAttr(v, PYIDENT("__set_name__")))) {
780
+ PyObject *setNameResult = PyObject_CallMethodObjArgs(v, PYIDENT("__set_name__"), (PyObject *) tp, k, NULL);
781
+ if (!setNameResult) return -1;
782
+ Py_DECREF(setNameResult);
783
+ }
784
+ }
785
+ return result;
786
+ }
787
+
788
+ ////////////////// DelItemOnTypeDict.proto //////////////////////////
789
+
790
+ static int __Pyx__DelItemOnTypeDict(PyTypeObject *tp, PyObject *k); /* proto */
791
+
792
+ #define __Pyx_DelItemOnTypeDict(tp, k) __Pyx__DelItemOnTypeDict((PyTypeObject*)tp, k)
793
+
794
+ ////////////////// DelItemOnTypeDict //////////////////////////
795
+ //@requires: LimitedApiGetTypeDict
796
+
797
+ static int __Pyx__DelItemOnTypeDict(PyTypeObject *tp, PyObject *k) {
798
+ int result;
799
+ PyObject *tp_dict;
800
+ #if CYTHON_COMPILING_IN_LIMITED_API
801
+ tp_dict = __Pyx_GetTypeDict(tp);
802
+ if (unlikely(!tp_dict)) return -1;
803
+ #else
804
+ tp_dict = tp->tp_dict;
805
+ #endif
806
+ result = PyDict_DelItem(tp_dict, k);
807
+ if (likely(!result)) PyType_Modified(tp);
808
+ return result;
809
+ }