oxython 0.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 (321) hide show
  1. Cython/Build/BuildExecutable.py +156 -0
  2. Cython/Build/Cache.py +198 -0
  3. Cython/Build/Cythonize.py +349 -0
  4. Cython/Build/Dependencies.py +1320 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +467 -0
  7. Cython/Build/IpythonMagic.py +559 -0
  8. Cython/Build/SharedModule.py +165 -0
  9. Cython/Build/Tests/TestCyCache.py +222 -0
  10. Cython/Build/Tests/TestCythonizeArgsParser.py +480 -0
  11. Cython/Build/Tests/TestDependencies.py +133 -0
  12. Cython/Build/Tests/TestInline.py +177 -0
  13. Cython/Build/Tests/TestIpythonMagic.py +303 -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 +11 -0
  18. Cython/CodeWriter.py +825 -0
  19. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  20. Cython/Compiler/Annotate.py +328 -0
  21. Cython/Compiler/AutoDocTransforms.py +320 -0
  22. Cython/Compiler/Buffer.py +679 -0
  23. Cython/Compiler/Builtin.py +1102 -0
  24. Cython/Compiler/CmdLine.py +373 -0
  25. Cython/Compiler/Code.pxd +154 -0
  26. Cython/Compiler/Code.py +3760 -0
  27. Cython/Compiler/CodeGeneration.py +33 -0
  28. Cython/Compiler/CythonScope.py +208 -0
  29. Cython/Compiler/Dataclass.py +890 -0
  30. Cython/Compiler/DebugFlags.py +24 -0
  31. Cython/Compiler/Errors.py +310 -0
  32. Cython/Compiler/ExprNodes.py +16319 -0
  33. Cython/Compiler/FlowControl.pxd +112 -0
  34. Cython/Compiler/FlowControl.py +1575 -0
  35. Cython/Compiler/FusedNode.py +978 -0
  36. Cython/Compiler/Future.py +16 -0
  37. Cython/Compiler/Interpreter.py +57 -0
  38. Cython/Compiler/Lexicon.py +442 -0
  39. Cython/Compiler/LineTable.py +114 -0
  40. Cython/Compiler/Main.py +879 -0
  41. Cython/Compiler/MatchCaseNodes.py +2200 -0
  42. Cython/Compiler/MemoryView.py +930 -0
  43. Cython/Compiler/ModuleNode.py +4558 -0
  44. Cython/Compiler/Naming.py +370 -0
  45. Cython/Compiler/Nodes.py +11334 -0
  46. Cython/Compiler/Optimize.py +5563 -0
  47. Cython/Compiler/Options.py +841 -0
  48. Cython/Compiler/ParseTreeTransforms.pxd +80 -0
  49. Cython/Compiler/ParseTreeTransforms.py +4808 -0
  50. Cython/Compiler/Parsing.pxd +9 -0
  51. Cython/Compiler/Parsing.py +5442 -0
  52. Cython/Compiler/Pipeline.py +439 -0
  53. Cython/Compiler/PyrexTypes.py +6588 -0
  54. Cython/Compiler/Pythran.py +232 -0
  55. Cython/Compiler/Scanning.pxd +74 -0
  56. Cython/Compiler/Scanning.py +771 -0
  57. Cython/Compiler/StringEncoding.py +354 -0
  58. Cython/Compiler/Symtab.py +3122 -0
  59. Cython/Compiler/Tests/TestBuffer.py +105 -0
  60. Cython/Compiler/Tests/TestBuiltin.py +196 -0
  61. Cython/Compiler/Tests/TestCmdLine.py +652 -0
  62. Cython/Compiler/Tests/TestCode.py +145 -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 +132 -0
  68. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  69. Cython/Compiler/Tests/TestStringEncoding.py +20 -0
  70. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  71. Cython/Compiler/Tests/TestTreePath.py +103 -0
  72. Cython/Compiler/Tests/TestTypes.py +119 -0
  73. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  74. Cython/Compiler/Tests/TestVisitor.py +119 -0
  75. Cython/Compiler/Tests/Utils.py +36 -0
  76. Cython/Compiler/Tests/__init__.py +1 -0
  77. Cython/Compiler/TreeFragment.py +279 -0
  78. Cython/Compiler/TreePath.py +303 -0
  79. Cython/Compiler/TypeInference.py +626 -0
  80. Cython/Compiler/TypeSlots.py +1330 -0
  81. Cython/Compiler/UFuncs.py +317 -0
  82. Cython/Compiler/UtilNodes.py +389 -0
  83. Cython/Compiler/UtilityCode.py +354 -0
  84. Cython/Compiler/Version.py +8 -0
  85. Cython/Compiler/Visitor.pxd +52 -0
  86. Cython/Compiler/Visitor.py +914 -0
  87. Cython/Compiler/__init__.py +1 -0
  88. Cython/Coverage.py +448 -0
  89. Cython/Debugger/Cygdb.py +214 -0
  90. Cython/Debugger/DebugWriter.py +82 -0
  91. Cython/Debugger/Tests/TestLibCython.py +280 -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 +580 -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 +143 -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 +159 -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 +268 -0
  120. Cython/Includes/cpython/exc.pxd +263 -0
  121. Cython/Includes/cpython/fileobject.pxd +57 -0
  122. Cython/Includes/cpython/float.pxd +56 -0
  123. Cython/Includes/cpython/frozendict.pxd +37 -0
  124. Cython/Includes/cpython/function.pxd +65 -0
  125. Cython/Includes/cpython/genobject.pxd +25 -0
  126. Cython/Includes/cpython/getargs.pxd +12 -0
  127. Cython/Includes/cpython/instance.pxd +25 -0
  128. Cython/Includes/cpython/iterator.pxd +36 -0
  129. Cython/Includes/cpython/iterobject.pxd +24 -0
  130. Cython/Includes/cpython/list.pxd +144 -0
  131. Cython/Includes/cpython/long.pxd +180 -0
  132. Cython/Includes/cpython/longintrepr.pxd +14 -0
  133. Cython/Includes/cpython/mapping.pxd +63 -0
  134. Cython/Includes/cpython/marshal.pxd +66 -0
  135. Cython/Includes/cpython/mem.pxd +120 -0
  136. Cython/Includes/cpython/memoryview.pxd +50 -0
  137. Cython/Includes/cpython/method.pxd +49 -0
  138. Cython/Includes/cpython/module.pxd +208 -0
  139. Cython/Includes/cpython/number.pxd +258 -0
  140. Cython/Includes/cpython/object.pxd +430 -0
  141. Cython/Includes/cpython/pycapsule.pxd +143 -0
  142. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  143. Cython/Includes/cpython/pyport.pxd +8 -0
  144. Cython/Includes/cpython/pystate.pxd +95 -0
  145. Cython/Includes/cpython/pythread.pxd +53 -0
  146. Cython/Includes/cpython/ref.pxd +141 -0
  147. Cython/Includes/cpython/sentinel.pxd +17 -0
  148. Cython/Includes/cpython/sequence.pxd +134 -0
  149. Cython/Includes/cpython/set.pxd +119 -0
  150. Cython/Includes/cpython/slice.pxd +70 -0
  151. Cython/Includes/cpython/time.pxd +129 -0
  152. Cython/Includes/cpython/tuple.pxd +72 -0
  153. Cython/Includes/cpython/type.pxd +146 -0
  154. Cython/Includes/cpython/unicode.pxd +639 -0
  155. Cython/Includes/cpython/version.pxd +32 -0
  156. Cython/Includes/cpython/weakref.pxd +78 -0
  157. Cython/Includes/libc/__init__.pxd +1 -0
  158. Cython/Includes/libc/complex.pxd +35 -0
  159. Cython/Includes/libc/errno.pxd +127 -0
  160. Cython/Includes/libc/float.pxd +43 -0
  161. Cython/Includes/libc/limits.pxd +28 -0
  162. Cython/Includes/libc/locale.pxd +46 -0
  163. Cython/Includes/libc/math.pxd +209 -0
  164. Cython/Includes/libc/setjmp.pxd +10 -0
  165. Cython/Includes/libc/signal.pxd +64 -0
  166. Cython/Includes/libc/stdbool.pxd +5 -0
  167. Cython/Includes/libc/stddef.pxd +9 -0
  168. Cython/Includes/libc/stdint.pxd +105 -0
  169. Cython/Includes/libc/stdio.pxd +80 -0
  170. Cython/Includes/libc/stdlib.pxd +72 -0
  171. Cython/Includes/libc/string.pxd +50 -0
  172. Cython/Includes/libc/threads.pxd +234 -0
  173. Cython/Includes/libc/time.pxd +52 -0
  174. Cython/Includes/libcpp/__init__.pxd +4 -0
  175. Cython/Includes/libcpp/algorithm.pxd +320 -0
  176. Cython/Includes/libcpp/any.pxd +16 -0
  177. Cython/Includes/libcpp/atomic.pxd +59 -0
  178. Cython/Includes/libcpp/barrier.pxd +22 -0
  179. Cython/Includes/libcpp/bit.pxd +29 -0
  180. Cython/Includes/libcpp/cast.pxd +12 -0
  181. Cython/Includes/libcpp/cmath.pxd +518 -0
  182. Cython/Includes/libcpp/complex.pxd +106 -0
  183. Cython/Includes/libcpp/condition_variable.pxd +322 -0
  184. Cython/Includes/libcpp/deque.pxd +165 -0
  185. Cython/Includes/libcpp/exception.pxd +216 -0
  186. Cython/Includes/libcpp/execution.pxd +15 -0
  187. Cython/Includes/libcpp/forward_list.pxd +63 -0
  188. Cython/Includes/libcpp/functional.pxd +26 -0
  189. Cython/Includes/libcpp/future.pxd +103 -0
  190. Cython/Includes/libcpp/iterator.pxd +34 -0
  191. Cython/Includes/libcpp/latch.pxd +17 -0
  192. Cython/Includes/libcpp/limits.pxd +61 -0
  193. Cython/Includes/libcpp/list.pxd +117 -0
  194. Cython/Includes/libcpp/map.pxd +252 -0
  195. Cython/Includes/libcpp/memory.pxd +115 -0
  196. Cython/Includes/libcpp/mutex.pxd +387 -0
  197. Cython/Includes/libcpp/numbers.pxd +15 -0
  198. Cython/Includes/libcpp/numeric.pxd +131 -0
  199. Cython/Includes/libcpp/optional.pxd +34 -0
  200. Cython/Includes/libcpp/pair.pxd +1 -0
  201. Cython/Includes/libcpp/queue.pxd +25 -0
  202. Cython/Includes/libcpp/random.pxd +166 -0
  203. Cython/Includes/libcpp/semaphore.pxd +43 -0
  204. Cython/Includes/libcpp/set.pxd +228 -0
  205. Cython/Includes/libcpp/shared_mutex.pxd +96 -0
  206. Cython/Includes/libcpp/span.pxd +87 -0
  207. Cython/Includes/libcpp/stack.pxd +11 -0
  208. Cython/Includes/libcpp/stop_token.pxd +117 -0
  209. Cython/Includes/libcpp/string.pxd +355 -0
  210. Cython/Includes/libcpp/string_view.pxd +183 -0
  211. Cython/Includes/libcpp/typeindex.pxd +15 -0
  212. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  213. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  214. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  215. Cython/Includes/libcpp/utility.pxd +30 -0
  216. Cython/Includes/libcpp/vector.pxd +186 -0
  217. Cython/Includes/numpy/math.pxd +150 -0
  218. Cython/Includes/openmp.pxd +50 -0
  219. Cython/Includes/posix/__init__.pxd +1 -0
  220. Cython/Includes/posix/dlfcn.pxd +14 -0
  221. Cython/Includes/posix/fcntl.pxd +86 -0
  222. Cython/Includes/posix/ioctl.pxd +4 -0
  223. Cython/Includes/posix/mman.pxd +101 -0
  224. Cython/Includes/posix/resource.pxd +57 -0
  225. Cython/Includes/posix/select.pxd +21 -0
  226. Cython/Includes/posix/signal.pxd +73 -0
  227. Cython/Includes/posix/stat.pxd +98 -0
  228. Cython/Includes/posix/stdio.pxd +37 -0
  229. Cython/Includes/posix/stdlib.pxd +29 -0
  230. Cython/Includes/posix/strings.pxd +9 -0
  231. Cython/Includes/posix/time.pxd +71 -0
  232. Cython/Includes/posix/types.pxd +30 -0
  233. Cython/Includes/posix/uio.pxd +26 -0
  234. Cython/Includes/posix/unistd.pxd +271 -0
  235. Cython/Includes/posix/wait.pxd +38 -0
  236. Cython/LZSS.py +184 -0
  237. Cython/Plex/Actions.pxd +24 -0
  238. Cython/Plex/Actions.py +119 -0
  239. Cython/Plex/DFA.pxd +14 -0
  240. Cython/Plex/DFA.py +164 -0
  241. Cython/Plex/Errors.py +48 -0
  242. Cython/Plex/Lexicons.py +178 -0
  243. Cython/Plex/Machines.pxd +36 -0
  244. Cython/Plex/Machines.py +238 -0
  245. Cython/Plex/Regexps.py +535 -0
  246. Cython/Plex/Scanners.pxd +45 -0
  247. Cython/Plex/Scanners.py +328 -0
  248. Cython/Plex/Transitions.pxd +14 -0
  249. Cython/Plex/Transitions.py +239 -0
  250. Cython/Plex/__init__.py +34 -0
  251. Cython/Runtime/__init__.py +1 -0
  252. Cython/Runtime/refnanny.pyx +237 -0
  253. Cython/Shadow.py +1172 -0
  254. Cython/StringIOTree.py +169 -0
  255. Cython/Tempita/__init__.py +4 -0
  256. Cython/Tempita/_looper.py +154 -0
  257. Cython/Tempita/_tempita.py +1087 -0
  258. Cython/TestUtils.py +472 -0
  259. Cython/Tests/TestCodeWriter.py +128 -0
  260. Cython/Tests/TestCythonUtils.py +237 -0
  261. Cython/Tests/TestJediTyper.py +223 -0
  262. Cython/Tests/TestShadow.py +125 -0
  263. Cython/Tests/TestStringIOTree.py +68 -0
  264. Cython/Tests/TestTestUtils.py +89 -0
  265. Cython/Tests/__init__.py +1 -0
  266. Cython/Tests/xmlrunner.py +390 -0
  267. Cython/Utility/AsyncGen.c +1152 -0
  268. Cython/Utility/Buffer.c +866 -0
  269. Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
  270. Cython/Utility/Builtins.c +1068 -0
  271. Cython/Utility/CConvert.pyx +153 -0
  272. Cython/Utility/CMath.c +104 -0
  273. Cython/Utility/CommonStructures.c +244 -0
  274. Cython/Utility/Complex.c +378 -0
  275. Cython/Utility/Coroutine.c +2344 -0
  276. Cython/Utility/CpdefEnums.pyx +119 -0
  277. Cython/Utility/CppConvert.pyx +284 -0
  278. Cython/Utility/CppSupport.cpp +151 -0
  279. Cython/Utility/CythonFunction.c +2143 -0
  280. Cython/Utility/Dataclasses.c +101 -0
  281. Cython/Utility/Embed.c +129 -0
  282. Cython/Utility/Exceptions.c +1331 -0
  283. Cython/Utility/Exceptions_Cy.pyx +109 -0
  284. Cython/Utility/ExtensionTypes.c +1199 -0
  285. Cython/Utility/FunctionArguments.c +1052 -0
  286. Cython/Utility/FusedFunction.pyx +44 -0
  287. Cython/Utility/ImportExport.c +972 -0
  288. Cython/Utility/MatchCase.c +985 -0
  289. Cython/Utility/MatchCase_Cy.pyx +12 -0
  290. Cython/Utility/MemoryView.pxd +108 -0
  291. Cython/Utility/MemoryView.pyx +1499 -0
  292. Cython/Utility/MemoryView_C.c +1056 -0
  293. Cython/Utility/ModuleSetupCode.c +3349 -0
  294. Cython/Utility/NumpyImportArray.c +46 -0
  295. Cython/Utility/ObjectHandling.c +3404 -0
  296. Cython/Utility/Optimize.c +2575 -0
  297. Cython/Utility/Overflow.c +378 -0
  298. Cython/Utility/Profile.c +736 -0
  299. Cython/Utility/StringTools.c +1534 -0
  300. Cython/Utility/Synchronization.c +438 -0
  301. Cython/Utility/TString.c +369 -0
  302. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  303. Cython/Utility/TestCythonScope.pyx +75 -0
  304. Cython/Utility/TestUtilityLoader.c +12 -0
  305. Cython/Utility/TypeConversion.c +1588 -0
  306. Cython/Utility/UFuncs.pyx +50 -0
  307. Cython/Utility/UFuncs_C.c +89 -0
  308. Cython/Utility/__init__.py +28 -0
  309. Cython/Utility/arrayarray.h +190 -0
  310. Cython/Utils.py +682 -0
  311. Cython/__init__.py +12 -0
  312. Cython/py.typed +0 -0
  313. cython.py +29 -0
  314. oxython-0.1.0.dist-info/METADATA +138 -0
  315. oxython-0.1.0.dist-info/RECORD +321 -0
  316. oxython-0.1.0.dist-info/WHEEL +5 -0
  317. oxython-0.1.0.dist-info/entry_points.txt +4 -0
  318. oxython-0.1.0.dist-info/top_level.txt +3 -0
  319. pyximport/__init__.py +4 -0
  320. pyximport/pyxbuild.py +160 -0
  321. pyximport/pyximport.py +482 -0
@@ -0,0 +1,2575 @@
1
+ /*
2
+ * Optional optimisations of built-in functions and methods.
3
+ *
4
+ * Required replacements of builtins are in Builtins.c.
5
+ *
6
+ * General object operations and protocols are in ObjectHandling.c.
7
+ */
8
+
9
+ /////////////// append.proto ///////////////
10
+
11
+ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /*proto*/
12
+
13
+ /////////////// append ///////////////
14
+ //@requires: ListAppend
15
+ //@requires: ObjectHandling.c::PyObjectCallMethod1
16
+
17
+ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
18
+ if (likely(PyList_CheckExact(L))) {
19
+ if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
20
+ } else {
21
+ PyObject* retval = __Pyx_PyObject_CallMethod1(L, PYIDENT("append"), x);
22
+ if (unlikely(!retval))
23
+ return -1;
24
+ Py_DECREF(retval);
25
+ }
26
+ return 0;
27
+ }
28
+
29
+
30
+ /////////////// ListAppendAndDecrefInternal ///////////////
31
+
32
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
33
+ static CYTHON_INLINE void __Pyx__ListComp_AppendAndDecref(PyObject* list, Py_ssize_t len, PyObject* x) {
34
+ PyList_SET_ITEM(list, len, x);
35
+ Py_SET_SIZE(list, len + 1);
36
+ }
37
+ #endif
38
+
39
+
40
+ /////////////// ListAppend.proto ///////////////
41
+
42
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
43
+ static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x); /*proto*/
44
+ #else
45
+ #define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
46
+ #endif
47
+
48
+ /////////////// ListAppend ///////////////
49
+ //@requires: ListAppendAndDecrefInternal
50
+
51
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
52
+ static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
53
+ PyListObject* L = (PyListObject*) list;
54
+ Py_ssize_t len = Py_SIZE(list);
55
+
56
+ if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
57
+ Py_INCREF(x);
58
+ __Pyx__ListComp_AppendAndDecref(list, len, x);
59
+ return 0;
60
+ }
61
+ return PyList_Append(list, x);
62
+ }
63
+ #endif
64
+
65
+
66
+ /////////////// ListCompAppend.proto ///////////////
67
+
68
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
69
+ static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x); /*proto*/
70
+ #else
71
+ #define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
72
+ #endif
73
+
74
+ /////////////// ListCompAppend ///////////////
75
+ //@requires: ListAppendAndDecrefInternal
76
+
77
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
78
+ static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
79
+ PyListObject* L = (PyListObject*) list;
80
+ Py_ssize_t len = Py_SIZE(list);
81
+
82
+ if (likely(L->allocated > len)) {
83
+ Py_INCREF(x);
84
+ __Pyx__ListComp_AppendAndDecref(list, len, x);
85
+ return 0;
86
+ }
87
+ return PyList_Append(list, x);
88
+ }
89
+ #endif
90
+
91
+
92
+ /////////////// ListCompAppendAndDecref.proto ///////////////
93
+
94
+ static CYTHON_INLINE int __Pyx_ListComp_AppendAndDecref(PyObject* list, PyObject* x); /*proto*/
95
+
96
+ /////////////// ListCompAppendAndDecref ///////////////
97
+ //@requires: ListAppendAndDecrefInternal
98
+
99
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
100
+ static CYTHON_INLINE int __Pyx_ListComp_AppendAndDecref(PyObject* list, PyObject* x) {
101
+ PyListObject* L = (PyListObject*) list;
102
+ Py_ssize_t len = Py_SIZE(list);
103
+
104
+ if (likely(L->allocated > len)) {
105
+ __Pyx__ListComp_AppendAndDecref(list, len, x);
106
+ return 0;
107
+ }
108
+
109
+ int result = PyList_Append(list, x);
110
+ Py_DECREF(x);
111
+ return result;
112
+ }
113
+
114
+ #else
115
+ static CYTHON_INLINE int __Pyx_ListComp_AppendAndDecref(PyObject* list, PyObject* x) {
116
+ int result = PyList_Append(list, x);
117
+ Py_DECREF(x);
118
+ return result;
119
+ }
120
+ #endif
121
+
122
+
123
+ //////////////////// ListExtend.proto ////////////////////
124
+
125
+ #if (CYTHON_COMPILING_IN_LIMITED_API || PY_VERSION_HEX < 0x030d0000) && !defined(PyList_Extend)
126
+ static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v); /*proto*/
127
+ #else
128
+ #define __Pyx_PyList_Extend(L, v) PyList_Extend(L, v)
129
+ #endif
130
+
131
+ //////////////////// ListExtend ////////////////////
132
+
133
+ #if (CYTHON_COMPILING_IN_LIMITED_API || PY_VERSION_HEX < 0x030d0000) && !defined(PyList_Extend)
134
+ static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
135
+ #if CYTHON_COMPILING_IN_CPYTHON
136
+ PyObject* none = _PyList_Extend((PyListObject*)L, v);
137
+ if (unlikely(!none))
138
+ return -1;
139
+ Py_DECREF(none);
140
+ return 0;
141
+ #else
142
+ return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
143
+ #endif
144
+ }
145
+ #endif
146
+
147
+
148
+ /////////////// pop.proto ///////////////
149
+
150
+ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); /*proto*/
151
+
152
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
153
+ static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L); /*proto*/
154
+ #define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ? \
155
+ __Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L))
156
+
157
+ #else
158
+ #define __Pyx_PyList_Pop(L) __Pyx__PyObject_Pop(L)
159
+ #define __Pyx_PyObject_Pop(L) __Pyx__PyObject_Pop(L)
160
+ #endif
161
+
162
+ /////////////// pop ///////////////
163
+ //@requires: ObjectHandling.c::PyObjectCallMethod0
164
+
165
+ static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
166
+ if (Py_IS_TYPE(L, &PySet_Type)) {
167
+ return PySet_Pop(L);
168
+ }
169
+ return __Pyx_PyObject_CallMethod0(L, PYIDENT("pop"));
170
+ }
171
+
172
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
173
+ static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
174
+ /* Check that both the size is positive and no reallocation shrinking needs to be done. */
175
+ if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
176
+ Py_SET_SIZE(L, Py_SIZE(L) - 1);
177
+ return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
178
+ }
179
+ return CALL_UNBOUND_METHOD(PyList_Type, "pop", L);
180
+ }
181
+ #endif
182
+
183
+
184
+ /////////////// pop_index.proto ///////////////
185
+
186
+ static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix); /*proto*/
187
+ static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix); /*proto*/
188
+
189
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
190
+ static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix); /*proto*/
191
+
192
+ #define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
193
+ (likely(PyList_CheckExact(L) && __Pyx_fits_Py_ssize_t(ix, type, is_signed))) ? \
194
+ __Pyx__PyList_PopIndex(L, py_ix, ix) : ( \
195
+ (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
196
+ __Pyx__PyObject_PopIndex(L, py_ix)))
197
+
198
+ #define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
199
+ __Pyx_fits_Py_ssize_t(ix, type, is_signed) ? \
200
+ __Pyx__PyList_PopIndex(L, py_ix, ix) : ( \
201
+ (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
202
+ __Pyx__PyObject_PopIndex(L, py_ix)))
203
+
204
+ #else
205
+
206
+ #define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) \
207
+ __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)
208
+
209
+ #define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
210
+ (unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
211
+ __Pyx__PyObject_PopIndex(L, py_ix))
212
+ #endif
213
+
214
+ /////////////// pop_index ///////////////
215
+ //@requires: ObjectHandling.c::PyObjectCallMethod1
216
+
217
+ static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix) {
218
+ PyObject *r;
219
+ if (unlikely(!py_ix)) return NULL;
220
+ r = __Pyx__PyObject_PopIndex(L, py_ix);
221
+ Py_DECREF(py_ix);
222
+ return r;
223
+ }
224
+
225
+ static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix) {
226
+ return __Pyx_PyObject_CallMethod1(L, PYIDENT("pop"), py_ix);
227
+ }
228
+
229
+ #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
230
+ static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix) {
231
+ Py_ssize_t size = PyList_GET_SIZE(L);
232
+ if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
233
+ Py_ssize_t cix = ix;
234
+ if (cix < 0) {
235
+ cix += size;
236
+ }
237
+ if (likely(__Pyx_is_valid_index(cix, size))) {
238
+ PyObject* v = PyList_GET_ITEM(L, cix);
239
+ Py_SET_SIZE(L, Py_SIZE(L) - 1);
240
+ size -= 1;
241
+ memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*));
242
+ return v;
243
+ }
244
+ }
245
+ if (py_ix == Py_None) {
246
+ return __Pyx__PyObject_PopNewIndex(L, PyLong_FromSsize_t(ix));
247
+ } else {
248
+ return __Pyx__PyObject_PopIndex(L, py_ix);
249
+ }
250
+ }
251
+ #endif
252
+
253
+
254
+ /////////////// dict_getitem_default.proto ///////////////
255
+
256
+ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /*proto*/
257
+
258
+ /////////////// dict_getitem_default ///////////////
259
+
260
+ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
261
+ PyObject* value;
262
+ #if !CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000
263
+ value = PyDict_GetItemWithError(d, key);
264
+ if (unlikely(!value)) {
265
+ if (unlikely(PyErr_Occurred()))
266
+ return NULL;
267
+ value = default_value;
268
+ }
269
+ Py_INCREF(value);
270
+ // avoid C compiler warning about unused utility functions
271
+ if ((1));
272
+ #else
273
+ if (PyBytes_CheckExact(key) || PyUnicode_CheckExact(key) || PyLong_CheckExact(key)) {
274
+ /* these presumably have safe hash functions */
275
+ value = PyDict_GetItem(d, key);
276
+ if (unlikely(!value)) {
277
+ value = default_value;
278
+ }
279
+ Py_INCREF(value);
280
+ }
281
+ #endif
282
+ else {
283
+ if (default_value == Py_None)
284
+ value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key);
285
+ else
286
+ value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key, default_value);
287
+ }
288
+ return value;
289
+ }
290
+
291
+
292
+ /////////////// py_dict_clear.proto ///////////////
293
+
294
+ #define __Pyx_PyDict_Clear(d) (PyDict_Clear(d), 0)
295
+
296
+
297
+ /////////////// py_dict_pop.proto ///////////////
298
+
299
+ static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value); /*proto*/
300
+
301
+ /////////////// py_dict_pop ///////////////
302
+
303
+ static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value) {
304
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)
305
+ PyObject *value;
306
+ if (PyDict_Pop(d, key, &value) == 0) {
307
+ if (default_value) {
308
+ Py_INCREF(default_value);
309
+ } else {
310
+ PyErr_SetObject(PyExc_KeyError, key);
311
+ }
312
+ value = default_value;
313
+ }
314
+ // On error, PyDict_Pop() returns -1 and sets value to NULL (our own exception return value).
315
+ return value;
316
+ #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
317
+ return _PyDict_Pop(d, key, default_value);
318
+ #else
319
+ if (default_value) {
320
+ return CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key, default_value);
321
+ } else {
322
+ return CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key);
323
+ }
324
+ #endif
325
+ }
326
+
327
+
328
+ /////////////// py_dict_pop_ignore.proto ///////////////
329
+
330
+ static CYTHON_INLINE int __Pyx_PyDict_Pop_ignore(PyObject *d, PyObject *key, PyObject *default_value); /*proto*/
331
+
332
+ /////////////// py_dict_pop_ignore ///////////////
333
+
334
+ static CYTHON_INLINE int __Pyx_PyDict_Pop_ignore(PyObject *d, PyObject *key, PyObject *default_value) {
335
+ // We take the "default_value" as argument to avoid "unused" warnings, but we ignore it here.
336
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)
337
+ int result = PyDict_Pop(d, key, NULL);
338
+ CYTHON_UNUSED_VAR(default_value);
339
+ return (unlikely(result == -1)) ? -1 : 0;
340
+ #else
341
+ PyObject *value;
342
+ CYTHON_UNUSED_VAR(default_value);
343
+
344
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
345
+ value = _PyDict_Pop(d, key, Py_None);
346
+ #else
347
+ value = CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key, Py_None);
348
+ #endif
349
+
350
+ if (unlikely(value == NULL))
351
+ return -1;
352
+ Py_DECREF(value);
353
+ return 0;
354
+ #endif
355
+ }
356
+
357
+
358
+ /////////////// dict_iter_common.proto ///////////////
359
+ static PyObject *__Pyx_dict_call_to_get_iterable(PyObject* iterable, PyObject* method_name); /* proto */
360
+ static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
361
+ PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);
362
+
363
+ /////////////// dict_iter_common ///////////////
364
+ //@requires: ObjectHandling.c::UnpackTuple2
365
+ //@requires: ObjectHandling.c::IterFinish
366
+ //@requires: ObjectHandling.c::PyObjectCallMethod0
367
+
368
+ static PyObject *__Pyx_dict_call_to_get_iterable(PyObject* iterable, PyObject* method_name) {
369
+
370
+ PyObject* iter;
371
+ iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
372
+ if (!iterable)
373
+ return NULL;
374
+ #if !CYTHON_AVOID_BORROWED_REFS
375
+ if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
376
+ return iterable;
377
+ #endif
378
+ iter = PyObject_GetIter(iterable);
379
+ Py_DECREF(iterable);
380
+ return iter;
381
+ }
382
+
383
+ #if !CYTHON_AVOID_BORROWED_REFS
384
+ static CYTHON_INLINE int __Pyx_dict_iter_next_source_is_dict(
385
+ PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
386
+ PyObject** pkey, PyObject** pvalue, PyObject** pitem) {
387
+ PyObject *key, *value;
388
+ if (unlikely(orig_length != PyDict_Size(iter_obj))) {
389
+ PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
390
+ return -1;
391
+ }
392
+ if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
393
+ return 0;
394
+ }
395
+ if (pitem) {
396
+ PyObject* tuple = PyTuple_New(2);
397
+ if (unlikely(!tuple)) {
398
+ return -1;
399
+ }
400
+ Py_INCREF(key);
401
+ Py_INCREF(value);
402
+ #if CYTHON_ASSUME_SAFE_MACROS
403
+ PyTuple_SET_ITEM(tuple, 0, key);
404
+ PyTuple_SET_ITEM(tuple, 1, value);
405
+ #else
406
+ if (unlikely(PyTuple_SetItem(tuple, 0, key) < 0)) {
407
+ // decref value; PyTuple_SetItem decrefs key on failure
408
+ Py_DECREF(value);
409
+ Py_DECREF(tuple);
410
+ return -1;
411
+ }
412
+ if (unlikely(PyTuple_SetItem(tuple, 1, value) < 0)) {
413
+ // PyTuple_SetItem decrefs value on failure
414
+ Py_DECREF(tuple);
415
+ return -1;
416
+ }
417
+ #endif
418
+ *pitem = tuple;
419
+ } else {
420
+ if (pkey) {
421
+ Py_INCREF(key);
422
+ *pkey = key;
423
+ }
424
+ if (pvalue) {
425
+ Py_INCREF(value);
426
+ *pvalue = value;
427
+ }
428
+ }
429
+ return 1;
430
+ }
431
+ #endif
432
+
433
+ static CYTHON_INLINE int __Pyx_dict_iter_next(
434
+ PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
435
+ PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
436
+ PyObject* next_item;
437
+ #if !CYTHON_AVOID_BORROWED_REFS
438
+ if (source_is_dict) {
439
+ int result;
440
+ #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API
441
+ Py_BEGIN_CRITICAL_SECTION(iter_obj);
442
+ #endif
443
+ result = __Pyx_dict_iter_next_source_is_dict(iter_obj, orig_length, ppos, pkey, pvalue, pitem);
444
+ #if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API
445
+ Py_END_CRITICAL_SECTION();
446
+ #endif
447
+ return result;
448
+ } else if (PyTuple_CheckExact(iter_obj)) {
449
+ Py_ssize_t pos = *ppos;
450
+ Py_ssize_t tuple_size = __Pyx_PyTuple_GET_SIZE(iter_obj);
451
+ #if !CYTHON_ASSUME_SAFE_SIZE
452
+ if (unlikely(tuple_size < 0)) return -1;
453
+ #endif
454
+ if (unlikely(pos >= tuple_size)) return 0;
455
+ *ppos = pos + 1;
456
+ #if CYTHON_ASSUME_SAFE_MACROS
457
+ next_item = PyTuple_GET_ITEM(iter_obj, pos);
458
+ #else
459
+ next_item = PyTuple_GetItem(iter_obj, pos);
460
+ if (unlikely(!next_item)) return -1;
461
+ #endif
462
+ Py_INCREF(next_item);
463
+ } else if (PyList_CheckExact(iter_obj)) {
464
+ Py_ssize_t pos = *ppos;
465
+ Py_ssize_t list_size = __Pyx_PyList_GET_SIZE(iter_obj);
466
+ #if !CYTHON_ASSUME_SAFE_SIZE
467
+ if (unlikely(list_size < 0)) return -1;
468
+ #endif
469
+ if (unlikely(pos >= list_size)) return 0;
470
+ *ppos = pos + 1;
471
+ next_item = __Pyx_PyList_GET_ITEM_REF(iter_obj, pos, __Pyx_ReferenceSharing_OwnStrongReference);
472
+ if (unlikely(!next_item)) return -1;
473
+ } else
474
+ #endif
475
+ {
476
+ next_item = PyIter_Next(iter_obj);
477
+ if (unlikely(!next_item)) {
478
+ return __Pyx_IterFinish();
479
+ }
480
+ }
481
+ if (pitem) {
482
+ *pitem = next_item;
483
+ } else if (pkey && pvalue) {
484
+ if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
485
+ return -1;
486
+ } else if (pkey) {
487
+ *pkey = next_item;
488
+ } else {
489
+ *pvalue = next_item;
490
+ }
491
+ return 1;
492
+ }
493
+
494
+ /////////////// dict_iter_legacy.proto //////////////
495
+
496
+ // "legacy" handles old-style iter* methods
497
+ static CYTHON_INLINE PyObject* __Pyx_dict_iterator_legacy(PyObject* dict, int is_dict, PyObject* method_name,
498
+ Py_ssize_t* p_orig_length, int* p_is_dict);
499
+
500
+ /////////////// dict_iter_legacy //////////////////
501
+ //@requires: dict_iter_common
502
+
503
+ #if CYTHON_AVOID_BORROWED_REFS
504
+ #include <string.h>
505
+ #endif
506
+
507
+ static CYTHON_INLINE PyObject* __Pyx_dict_iterator_legacy(PyObject* iterable, int is_dict, PyObject* method_name,
508
+ Py_ssize_t* p_orig_length, int* p_source_is_dict) {
509
+ int owned_method_name = 0;
510
+ // Don't include frozendict.
511
+ is_dict = is_dict || likely(PyDict_CheckExact(iterable));
512
+ *p_source_is_dict = is_dict;
513
+ if (is_dict) {
514
+ #if !CYTHON_AVOID_BORROWED_REFS
515
+ *p_orig_length = PyDict_Size(iterable);
516
+ Py_INCREF(iterable);
517
+ return iterable;
518
+ #else
519
+ // On PyPy3/GraalPy, we need to translate manually the method name.
520
+ // This logic is not needed on CPython thanks to the fast case above.
521
+ if (method_name) {
522
+ method_name = PyUnicode_Substring(method_name, 4, 10); // longest is "itervalues" (len=10)
523
+ if (unlikely(!method_name))
524
+ return NULL;
525
+ owned_method_name = 1;
526
+ }
527
+ #endif
528
+ }
529
+ *p_orig_length = 0;
530
+ if (method_name) {
531
+ iterable = __Pyx_dict_call_to_get_iterable(iterable, method_name);
532
+ if (owned_method_name) {
533
+ Py_DECREF(method_name);
534
+ }
535
+ return iterable;
536
+ } else {
537
+ return PyObject_GetIter(iterable);
538
+ }
539
+ }
540
+
541
+ /////////////// dict_iter.proto ///////////////
542
+
543
+ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
544
+ Py_ssize_t* p_orig_length, int* p_is_dict);
545
+
546
+ /////////////// dict_iter ///////////////
547
+ //@requires: Builtins.c::PyFrozenDict
548
+ //@requires: dict_iter_common
549
+
550
+ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
551
+ Py_ssize_t* p_orig_length, int* p_source_is_dict) {
552
+ is_dict = is_dict || likely(__Pyx_PyAnyDict_CheckExact(iterable));
553
+ *p_source_is_dict = is_dict;
554
+ #if !CYTHON_AVOID_BORROWED_REFS
555
+ if (is_dict) {
556
+ *p_orig_length = PyDict_Size(iterable);
557
+ Py_INCREF(iterable);
558
+ return iterable;
559
+ }
560
+ #endif
561
+ *p_orig_length = 0;
562
+ if (method_name) {
563
+ return __Pyx_dict_call_to_get_iterable(iterable, method_name);
564
+ } else {
565
+ return PyObject_GetIter(iterable);
566
+ }
567
+ }
568
+
569
+
570
+ /////////////// set_iter.proto ///////////////
571
+
572
+ static CYTHON_INLINE PyObject* __Pyx_set_iterator(PyObject* iterable, int is_set,
573
+ Py_ssize_t* p_orig_length, int* p_source_is_set); /*proto*/
574
+ static CYTHON_INLINE int __Pyx_set_iter_next(
575
+ PyObject* iter_obj, Py_ssize_t orig_length,
576
+ Py_ssize_t* ppos, PyObject **value,
577
+ int source_is_set); /*proto*/
578
+
579
+ /////////////// set_iter ///////////////
580
+ //@requires: ObjectHandling.c::IterFinish
581
+
582
+ static CYTHON_INLINE PyObject* __Pyx_set_iterator(PyObject* iterable, int is_set,
583
+ Py_ssize_t* p_orig_length, int* p_source_is_set) {
584
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
585
+ is_set = is_set || likely(PySet_CheckExact(iterable) || PyFrozenSet_CheckExact(iterable));
586
+ *p_source_is_set = is_set;
587
+ if (likely(is_set)) {
588
+ *p_orig_length = PySet_Size(iterable);
589
+ Py_INCREF(iterable);
590
+ return iterable;
591
+ }
592
+ #else
593
+ CYTHON_UNUSED_VAR(is_set);
594
+ *p_source_is_set = 0;
595
+ #endif
596
+ *p_orig_length = 0;
597
+ return PyObject_GetIter(iterable);
598
+ }
599
+
600
+ static CYTHON_INLINE int __Pyx_set_iter_next(
601
+ PyObject* iter_obj, Py_ssize_t orig_length,
602
+ Py_ssize_t* ppos, PyObject **value,
603
+ int source_is_set) {
604
+ if (!CYTHON_COMPILING_IN_CPYTHON || PY_VERSION_HEX >= 0x030d0000 || unlikely(!source_is_set)) {
605
+ *value = PyIter_Next(iter_obj);
606
+ if (unlikely(!*value)) {
607
+ return __Pyx_IterFinish();
608
+ }
609
+ CYTHON_UNUSED_VAR(orig_length);
610
+ CYTHON_UNUSED_VAR(ppos);
611
+ return 1;
612
+ }
613
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
614
+ if (unlikely(PySet_GET_SIZE(iter_obj) != orig_length)) {
615
+ PyErr_SetString(
616
+ PyExc_RuntimeError,
617
+ "set changed size during iteration");
618
+ return -1;
619
+ }
620
+ {
621
+ Py_hash_t hash;
622
+ int ret = _PySet_NextEntry(iter_obj, ppos, value, &hash);
623
+ // CPython does not raise errors here, only if !isinstance(iter_obj, set/frozenset)
624
+ assert (ret != -1);
625
+ if (likely(ret)) {
626
+ Py_INCREF(*value);
627
+ return 1;
628
+ }
629
+ }
630
+ #endif
631
+ return 0;
632
+ }
633
+
634
+ /////////////// py_set_discard_unhashable ///////////////
635
+ //@requires: Builtins.c::pyfrozenset_new
636
+
637
+ static int __Pyx_PySet_DiscardUnhashable(PyObject *set, PyObject *key) {
638
+ PyObject *tmpkey;
639
+ int rv;
640
+
641
+ if (likely(!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)))
642
+ return -1;
643
+ PyErr_Clear();
644
+ tmpkey = __Pyx_PyFrozenSet_New(key);
645
+ if (tmpkey == NULL)
646
+ return -1;
647
+ rv = PySet_Discard(set, tmpkey);
648
+ Py_DECREF(tmpkey);
649
+ return rv;
650
+ }
651
+
652
+
653
+ /////////////// py_set_discard.proto ///////////////
654
+
655
+ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key); /*proto*/
656
+
657
+ /////////////// py_set_discard ///////////////
658
+ //@requires: py_set_discard_unhashable
659
+
660
+ static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
661
+ int found = PySet_Discard(set, key);
662
+ // Convert *key* to frozenset if necessary
663
+ if (unlikely(found < 0)) {
664
+ found = __Pyx_PySet_DiscardUnhashable(set, key);
665
+ }
666
+ // note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
667
+ return found;
668
+ }
669
+
670
+
671
+ /////////////// py_set_remove.proto ///////////////
672
+
673
+ static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key); /*proto*/
674
+
675
+ /////////////// py_set_remove ///////////////
676
+ //@requires: py_set_discard_unhashable
677
+
678
+ static int __Pyx_PySet_RemoveNotFound(PyObject *set, PyObject *key, int found) {
679
+ // Convert *key* to frozenset if necessary
680
+ if (unlikely(found < 0)) {
681
+ found = __Pyx_PySet_DiscardUnhashable(set, key);
682
+ }
683
+ if (likely(found == 0)) {
684
+ // Not found
685
+ PyObject *tup;
686
+ tup = PyTuple_Pack(1, key);
687
+ if (!tup)
688
+ return -1;
689
+ PyErr_SetObject(PyExc_KeyError, tup);
690
+ Py_DECREF(tup);
691
+ return -1;
692
+ }
693
+ // note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
694
+ return found;
695
+ }
696
+
697
+ static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key) {
698
+ int found = PySet_Discard(set, key);
699
+ if (unlikely(found != 1)) {
700
+ // note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
701
+ return __Pyx_PySet_RemoveNotFound(set, key, found);
702
+ }
703
+ return 0;
704
+ }
705
+
706
+
707
+ /////////////// unicode_iter.proto ///////////////
708
+
709
+ static CYTHON_INLINE int __Pyx_init_unicode_iteration(
710
+ PyObject* ustring, Py_ssize_t *length, void** data, int *kind); /* proto */
711
+
712
+ /////////////// unicode_iter ///////////////
713
+
714
+ static CYTHON_INLINE int __Pyx_init_unicode_iteration(
715
+ PyObject* ustring, Py_ssize_t *length, void** data, int *kind) {
716
+ #if CYTHON_COMPILING_IN_LIMITED_API
717
+ // In the limited API we just point data to the unicode object
718
+ *kind = 0;
719
+ *length = PyUnicode_GetLength(ustring);
720
+ *data = (void*)ustring;
721
+ #else
722
+ if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return -1;
723
+ *kind = PyUnicode_KIND(ustring);
724
+ *length = PyUnicode_GET_LENGTH(ustring);
725
+ *data = PyUnicode_DATA(ustring);
726
+ #endif
727
+ return 0;
728
+ }
729
+
730
+ /////////////// pyobject_as_double.proto ///////////////
731
+
732
+ static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
733
+
734
+ #if CYTHON_COMPILING_IN_PYPY
735
+ #define __Pyx_PyObject_AsDouble(obj) \
736
+ (likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \
737
+ likely(PyLong_CheckExact(obj)) ? \
738
+ PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
739
+ #else
740
+ #define __Pyx_PyObject_AsDouble(obj) \
741
+ ((likely(PyFloat_CheckExact(obj))) ? __Pyx_PyFloat_AS_DOUBLE(obj) : \
742
+ likely(PyLong_CheckExact(obj)) ? \
743
+ PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
744
+ #endif
745
+
746
+ /////////////// pyobject_as_double ///////////////
747
+ //@requires: pybytes_as_double
748
+ //@requires: pyunicode_as_double
749
+ //@requires: ObjectHandling.c::PyObjectCallOneArg
750
+ //@requires: ObjectHandling.c::RaiseErrorWithObjectType
751
+
752
+ static double __Pyx__PyObject_AsDouble(PyObject* obj) {
753
+ if (PyUnicode_CheckExact(obj)) {
754
+ return __Pyx_PyUnicode_AsDouble(obj);
755
+ } else if (PyBytes_CheckExact(obj)) {
756
+ return __Pyx_PyBytes_AsDouble(obj);
757
+ } else if (PyByteArray_CheckExact(obj)) {
758
+ return __Pyx_PyByteArray_AsDouble(obj);
759
+ } else {
760
+ PyObject* float_value;
761
+ #if !CYTHON_USE_TYPE_SLOTS
762
+ float_value = PyNumber_Float(obj); if ((0)) goto bad;
763
+ // avoid "unused" warnings
764
+ (void)&__Pyx_PyObject_CallOneArg;
765
+ #else
766
+ PyNumberMethods *nb = Py_TYPE(obj)->tp_as_number;
767
+ if (likely(nb) && likely(nb->nb_float)) {
768
+ float_value = nb->nb_float(obj);
769
+ if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
770
+ __Pyx_RaiseTypeErrorWithObjectType(
771
+ "__float__ returned non-float (type " __Pyx_FMT_TYPENAME ")",
772
+ float_value);
773
+ Py_DECREF(float_value);
774
+ goto bad;
775
+ }
776
+ } else {
777
+ float_value = __Pyx_PyObject_CallOneArg((PyObject*)&PyFloat_Type, obj);
778
+ }
779
+ #endif
780
+ if (likely(float_value)) {
781
+ double value = __Pyx_PyFloat_AS_DOUBLE(float_value);
782
+ Py_DECREF(float_value);
783
+ return value;
784
+ }
785
+ }
786
+ bad:
787
+ return (double)-1;
788
+ }
789
+
790
+
791
+ /////////////// pyunicode_as_double.proto ///////////////
792
+
793
+ static CYTHON_INLINE double __Pyx_PyUnicode_AsDouble(PyObject *obj);/*proto*/
794
+
795
+ /////////////// pyunicode_as_double.proto ///////////////
796
+ //@requires: pybytes_as_double
797
+
798
+ #if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS
799
+ static const char* __Pyx__PyUnicode_AsDouble_Copy(const void* data, const int kind, char* buffer, Py_ssize_t start, Py_ssize_t end) {
800
+ int last_was_punctuation;
801
+ Py_ssize_t i;
802
+ // number must not start with punctuation
803
+ last_was_punctuation = 1;
804
+ for (i=start; i <= end; i++) {
805
+ Py_UCS4 chr = PyUnicode_READ(kind, data, i);
806
+ int is_punctuation = (chr == '_') | (chr == '.');
807
+ *buffer = (char)chr;
808
+ // reject sequences of '_' and '.'
809
+ buffer += (chr != '_');
810
+ if (unlikely(chr > 127)) goto parse_failure;
811
+ if (unlikely(last_was_punctuation & is_punctuation)) goto parse_failure;
812
+ last_was_punctuation = is_punctuation;
813
+ }
814
+ if (unlikely(last_was_punctuation)) goto parse_failure;
815
+ *buffer = '\0';
816
+ return buffer;
817
+
818
+ parse_failure:
819
+ return NULL;
820
+ }
821
+
822
+ static double __Pyx__PyUnicode_AsDouble_inf_nan(const void* data, int kind, Py_ssize_t start, Py_ssize_t length) {
823
+ int matches = 1;
824
+ Py_UCS4 chr;
825
+ Py_UCS4 sign = PyUnicode_READ(kind, data, start);
826
+ int is_signed = (sign == '-') | (sign == '+');
827
+ start += is_signed;
828
+ length -= is_signed;
829
+
830
+ switch (PyUnicode_READ(kind, data, start)) {
831
+ #ifdef Py_NAN
832
+ case 'n':
833
+ case 'N':
834
+ if (unlikely(length != 3)) goto parse_failure;
835
+ chr = PyUnicode_READ(kind, data, start+1);
836
+ matches &= (chr == 'a') | (chr == 'A');
837
+ chr = PyUnicode_READ(kind, data, start+2);
838
+ matches &= (chr == 'n') | (chr == 'N');
839
+ if (unlikely(!matches)) goto parse_failure;
840
+ return (sign == '-') ? -Py_NAN : Py_NAN;
841
+ #endif
842
+ case 'i':
843
+ case 'I':
844
+ if (unlikely(length < 3)) goto parse_failure;
845
+ chr = PyUnicode_READ(kind, data, start+1);
846
+ matches &= (chr == 'n') | (chr == 'N');
847
+ chr = PyUnicode_READ(kind, data, start+2);
848
+ matches &= (chr == 'f') | (chr == 'F');
849
+ if (likely(length == 3 && matches))
850
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
851
+ if (unlikely(length != 8)) goto parse_failure;
852
+ chr = PyUnicode_READ(kind, data, start+3);
853
+ matches &= (chr == 'i') | (chr == 'I');
854
+ chr = PyUnicode_READ(kind, data, start+4);
855
+ matches &= (chr == 'n') | (chr == 'N');
856
+ chr = PyUnicode_READ(kind, data, start+5);
857
+ matches &= (chr == 'i') | (chr == 'I');
858
+ chr = PyUnicode_READ(kind, data, start+6);
859
+ matches &= (chr == 't') | (chr == 'T');
860
+ chr = PyUnicode_READ(kind, data, start+7);
861
+ matches &= (chr == 'y') | (chr == 'Y');
862
+ if (unlikely(!matches)) goto parse_failure;
863
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
864
+ case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
865
+ break;
866
+ default:
867
+ goto parse_failure;
868
+ }
869
+ return 0.0;
870
+ parse_failure:
871
+ return -1.0;
872
+ }
873
+
874
+ static double __Pyx_PyUnicode_AsDouble_WithSpaces(PyObject *obj) {
875
+ double value;
876
+ const char *last;
877
+ char *end;
878
+ int valid_parse;
879
+ Py_ssize_t start, length = PyUnicode_GET_LENGTH(obj);
880
+ const int kind = PyUnicode_KIND(obj);
881
+ const void* data = PyUnicode_DATA(obj);
882
+
883
+ // strip spaces at start and end
884
+ start = 0;
885
+ while (Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, start)))
886
+ start++;
887
+ while (start < length - 1 && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, length - 1)))
888
+ length--;
889
+ length -= start;
890
+ if (unlikely(length <= 0)) goto fallback;
891
+
892
+ // parse NaN / inf
893
+ value = __Pyx__PyUnicode_AsDouble_inf_nan(data, kind, start, length);
894
+ if (value != 0.0) {
895
+ if (unlikely(value == -1.0)) goto fallback;
896
+ return value;
897
+ }
898
+
899
+ if (length < 40) {
900
+ char number[40];
901
+ last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length);
902
+ if (unlikely(!last)) goto fallback;
903
+ value = PyOS_string_to_double(number, &end, NULL);
904
+ valid_parse = (end == last);
905
+ } else {
906
+ char *number = (char*) PyMem_Malloc(((size_t) length + 1) * sizeof(char));
907
+ if (unlikely(!number)) goto fallback;
908
+ last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length);
909
+ if (unlikely(!last)) {
910
+ PyMem_Free(number);
911
+ goto fallback;
912
+ }
913
+ value = PyOS_string_to_double(number, &end, NULL);
914
+ valid_parse = (end == last);
915
+ PyMem_Free(number);
916
+ }
917
+ if (likely(valid_parse) || (value == (double)-1 && PyErr_Occurred())) {
918
+ return value;
919
+ }
920
+ fallback:
921
+ return __Pyx_SlowPyString_AsDouble(obj);
922
+ }
923
+ #endif
924
+
925
+ static CYTHON_INLINE double __Pyx_PyUnicode_AsDouble(PyObject *obj) {
926
+ // Currently not optimised for Py2.7.
927
+ #if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS
928
+ if (unlikely(__Pyx_PyUnicode_READY(obj) == -1))
929
+ return (double)-1;
930
+ if (likely(PyUnicode_IS_ASCII(obj))) {
931
+ const char *s;
932
+ Py_ssize_t length;
933
+ s = PyUnicode_AsUTF8AndSize(obj, &length);
934
+ return __Pyx__PyBytes_AsDouble(obj, s, length);
935
+ }
936
+ return __Pyx_PyUnicode_AsDouble_WithSpaces(obj);
937
+ #else
938
+ return __Pyx_SlowPyString_AsDouble(obj);
939
+ #endif
940
+ }
941
+
942
+
943
+ /////////////// pybytes_as_double.proto ///////////////
944
+
945
+ static double __Pyx_SlowPyString_AsDouble(PyObject *obj);/*proto*/
946
+ static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length);/*proto*/
947
+
948
+ static CYTHON_INLINE double __Pyx_PyBytes_AsDouble(PyObject *obj) {
949
+ char* as_c_string;
950
+ Py_ssize_t size;
951
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
952
+ as_c_string = PyBytes_AS_STRING(obj);
953
+ size = PyBytes_GET_SIZE(obj);
954
+ #else
955
+ if (PyBytes_AsStringAndSize(obj, &as_c_string, &size) < 0) {
956
+ return (double)-1;
957
+ }
958
+ #endif
959
+ return __Pyx__PyBytes_AsDouble(obj, as_c_string, size);
960
+ }
961
+ static CYTHON_INLINE double __Pyx_PyByteArray_AsDouble(PyObject *obj) {
962
+ char* as_c_string;
963
+ Py_ssize_t size;
964
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
965
+ as_c_string = PyByteArray_AS_STRING(obj);
966
+ size = PyByteArray_GET_SIZE(obj);
967
+ #else
968
+ as_c_string = PyByteArray_AsString(obj);
969
+ if (as_c_string == NULL) {
970
+ return (double)-1;
971
+ }
972
+ size = PyByteArray_Size(obj);
973
+ #endif
974
+ return __Pyx__PyBytes_AsDouble(obj, as_c_string, size);
975
+ }
976
+
977
+
978
+ /////////////// pybytes_as_double ///////////////
979
+
980
+ static double __Pyx_SlowPyString_AsDouble(PyObject *obj) {
981
+ PyObject *float_value = PyFloat_FromString(obj);
982
+ if (likely(float_value)) {
983
+ double value = __Pyx_PyFloat_AS_DOUBLE(float_value);
984
+ Py_DECREF(float_value);
985
+ return value;
986
+ }
987
+ return (double)-1;
988
+ }
989
+
990
+ static const char* __Pyx__PyBytes_AsDouble_Copy(const char* start, char* buffer, Py_ssize_t length) {
991
+ // number must not start with punctuation
992
+ int last_was_punctuation = 1;
993
+ int parse_error_found = 0;
994
+ Py_ssize_t i;
995
+ for (i=0; i < length; i++) {
996
+ char chr = start[i];
997
+ int is_punctuation = (chr == '_') | (chr == '.') | (chr == 'e') | (chr == 'E');
998
+ *buffer = chr;
999
+ buffer += (chr != '_');
1000
+ // reject sequences of punctuation, e.g. '_.'
1001
+ parse_error_found |= last_was_punctuation & is_punctuation;
1002
+ last_was_punctuation = is_punctuation;
1003
+ }
1004
+ // number must not end with punctuation
1005
+ parse_error_found |= last_was_punctuation;
1006
+ *buffer = '\0';
1007
+ return unlikely(parse_error_found) ? NULL : buffer;
1008
+ }
1009
+
1010
+ static double __Pyx__PyBytes_AsDouble_inf_nan(const char* start, Py_ssize_t length) {
1011
+ int matches = 1;
1012
+ char sign = start[0];
1013
+ int is_signed = (sign == '+') | (sign == '-');
1014
+ start += is_signed;
1015
+ length -= is_signed;
1016
+
1017
+ switch (start[0]) {
1018
+ #ifdef Py_NAN
1019
+ case 'n':
1020
+ case 'N':
1021
+ if (unlikely(length != 3)) goto parse_failure;
1022
+ matches &= (start[1] == 'a' || start[1] == 'A');
1023
+ matches &= (start[2] == 'n' || start[2] == 'N');
1024
+ if (unlikely(!matches)) goto parse_failure;
1025
+ return (sign == '-') ? -Py_NAN : Py_NAN;
1026
+ #endif
1027
+ case 'i':
1028
+ case 'I':
1029
+ if (unlikely(length < 3)) goto parse_failure;
1030
+ matches &= (start[1] == 'n' || start[1] == 'N');
1031
+ matches &= (start[2] == 'f' || start[2] == 'F');
1032
+ if (likely(length == 3 && matches))
1033
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
1034
+ if (unlikely(length != 8)) goto parse_failure;
1035
+ matches &= (start[3] == 'i' || start[3] == 'I');
1036
+ matches &= (start[4] == 'n' || start[4] == 'N');
1037
+ matches &= (start[5] == 'i' || start[5] == 'I');
1038
+ matches &= (start[6] == 't' || start[6] == 'T');
1039
+ matches &= (start[7] == 'y' || start[7] == 'Y');
1040
+ if (unlikely(!matches)) goto parse_failure;
1041
+ return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
1042
+ case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
1043
+ break;
1044
+ default:
1045
+ goto parse_failure;
1046
+ }
1047
+ return 0.0;
1048
+ parse_failure:
1049
+ return -1.0;
1050
+ }
1051
+
1052
+ static CYTHON_INLINE int __Pyx__PyBytes_AsDouble_IsSpace(char ch) {
1053
+ // see Py_ISSPACE() in CPython
1054
+ // https://github.com/python/cpython/blob/master/Python/pyctype.c
1055
+ return (ch == 0x20) | !((ch < 0x9) | (ch > 0xd));
1056
+ }
1057
+
1058
+ CYTHON_UNUSED static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length) {
1059
+ double value;
1060
+ Py_ssize_t i, digits;
1061
+ const char *last = start + length;
1062
+ char *end;
1063
+ int valid_parse;
1064
+
1065
+ // strip spaces at start and end
1066
+ while (__Pyx__PyBytes_AsDouble_IsSpace(*start))
1067
+ start++;
1068
+ while (start < last - 1 && __Pyx__PyBytes_AsDouble_IsSpace(last[-1]))
1069
+ last--;
1070
+ length = last - start;
1071
+ if (unlikely(length <= 0)) goto fallback;
1072
+
1073
+ // parse NaN / inf
1074
+ value = __Pyx__PyBytes_AsDouble_inf_nan(start, length);
1075
+ if (value != 0.0) {
1076
+ if (unlikely(value == -1.0)) goto fallback;
1077
+ return value;
1078
+ }
1079
+
1080
+ // look for underscores
1081
+ digits = 0;
1082
+ for (i=0; i < length; digits += start[i++] != '_');
1083
+
1084
+ if (likely(digits == length)) {
1085
+ value = PyOS_string_to_double(start, &end, NULL);
1086
+ valid_parse = (end == last);
1087
+ } else if (digits < 40) {
1088
+ char number[40];
1089
+ last = __Pyx__PyBytes_AsDouble_Copy(start, number, length);
1090
+ if (unlikely(!last)) goto fallback;
1091
+ value = PyOS_string_to_double(number, &end, NULL);
1092
+ valid_parse = (end == last);
1093
+ } else {
1094
+ char *number = (char*) PyMem_Malloc(((size_t) digits + 1) * sizeof(char));
1095
+ if (unlikely(!number)) goto fallback;
1096
+ last = __Pyx__PyBytes_AsDouble_Copy(start, number, length);
1097
+ if (unlikely(!last)) {
1098
+ PyMem_Free(number);
1099
+ goto fallback;
1100
+ }
1101
+ value = PyOS_string_to_double(number, &end, NULL);
1102
+ valid_parse = (end == last);
1103
+ PyMem_Free(number);
1104
+ }
1105
+ if (likely(valid_parse) || (value == (double)-1 && PyErr_Occurred())) {
1106
+ return value;
1107
+ }
1108
+ fallback:
1109
+ return __Pyx_SlowPyString_AsDouble(obj);
1110
+ }
1111
+
1112
+
1113
+ /////////////// PyNumberPow2.proto ///////////////
1114
+
1115
+ #define __Pyx_PyNumber_InPlacePowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 1)
1116
+ #define __Pyx_PyNumber_PowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 0)
1117
+
1118
+ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace); /*proto*/
1119
+
1120
+ /////////////// PyNumberPow2 ///////////////
1121
+ //@requires: Exceptions.c::IgnoreException
1122
+
1123
+ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace) {
1124
+ // in CPython, 1<<N is substantially faster than 2**N
1125
+ // see https://bugs.python.org/issue21420
1126
+ #if !CYTHON_COMPILING_IN_PYPY
1127
+ Py_ssize_t shiftby;
1128
+ if (likely(PyLong_CheckExact(exp))) {
1129
+ #if CYTHON_USE_PYLONG_INTERNALS
1130
+ if (__Pyx_PyLong_IsZero(exp)) {
1131
+ return PyLong_FromLong(1L);
1132
+ } else if (__Pyx_PyLong_IsNeg(exp)) {
1133
+ goto fallback;
1134
+ } else if (__Pyx_PyLong_IsCompact(exp)) {
1135
+ shiftby = __Pyx_PyLong_CompactValueUnsigned(exp);
1136
+ } else {
1137
+ shiftby = PyLong_AsSsize_t(exp);
1138
+ }
1139
+ #else
1140
+ shiftby = PyLong_AsSsize_t(exp);
1141
+ #endif
1142
+ } else {
1143
+ goto fallback;
1144
+ }
1145
+ if (likely(shiftby >= 0)) {
1146
+ if ((size_t)shiftby <= sizeof(long) * 8 - 2) {
1147
+ long value = 1L << shiftby;
1148
+ return PyLong_FromLong(value);
1149
+ } else if ((size_t)shiftby <= sizeof(unsigned PY_LONG_LONG) * 8 - 1) {
1150
+ unsigned PY_LONG_LONG value = ((unsigned PY_LONG_LONG)1) << shiftby;
1151
+ return PyLong_FromUnsignedLongLong(value);
1152
+ } else {
1153
+ PyObject *result, *one = PyLong_FromLong(1L);
1154
+ if (unlikely(!one)) return NULL;
1155
+ result = PyNumber_Lshift(one, exp);
1156
+ Py_DECREF(one);
1157
+ return result;
1158
+ }
1159
+ } else if (shiftby == -1) {
1160
+ PyObject *err = PyErr_Occurred();
1161
+ if (err && !__Pyx_IgnoreGivenException(err, PyExc_Exception)) {
1162
+ return NULL; // BaseException
1163
+ }
1164
+ }
1165
+ fallback:
1166
+ #endif
1167
+ return (inplace ? PyNumber_InPlacePower : PyNumber_Power)(two, exp, none);
1168
+ }
1169
+
1170
+ /////////////// PyNumberBinop.proto ///////////////
1171
+
1172
+ #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_GRAAL || CYTHON_COMPILING_IN_LIMITED_API
1173
+
1174
+ #define __Pyx_{{op_name}}_{{type1}}_{{type2}}(op1, op2) {{op_name}}(op1, op2)
1175
+ #define __Pyx_{{inplace_op_name}}_{{type1}}_{{type2}}(op1, op2) {{inplace_op_name}}(op1, op2)
1176
+
1177
+ #else
1178
+
1179
+ #define __Pyx_{{op_name}}_{{type1}}_{{type2}}(op1, op2) __Pyx__{{op_name}}_{{type1}}_{{type2}}(op1, op2, 0)
1180
+ #define __Pyx_{{inplace_op_name}}_{{type1}}_{{type2}}(op1, op2) __Pyx__{{op_name}}_{{type1}}_{{type2}}(op1, op2, 1)
1181
+
1182
+ static CYTHON_INLINE PyObject* __Pyx__{{op_name}}_{{type1}}_{{type2}}(PyObject *op1, PyObject *op2, int inplace); /*proto*/
1183
+ #endif
1184
+
1185
+ /////////////// PyNumberBinop ///////////////
1186
+ //@requires: ObjectHandling.c::RaiseErrorWithObjectTypes
1187
+
1188
+ #if !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_GRAAL || CYTHON_COMPILING_IN_LIMITED_API)
1189
+
1190
+ {{py: assert type1 in ('object', 'int', 'float'), type1 }}
1191
+ {{py: assert type2 in ('object', 'int', 'float'), type2 }}
1192
+ {{py: slot_name = {'+': 'add', '-': 'subtract', '*': 'multiply', '^': 'xor', '&': 'and', '|': 'or'}[c_op] }}
1193
+ {{py:
1194
+ def is_type(operand, expected, type1=type1, type2=type2):
1195
+ assert operand in ('op1', 'op2'), operand
1196
+ assert expected in ('int', 'float'), type
1197
+ type = type1 if operand == 'op1' else type2
1198
+ if type == expected:
1199
+ check = f"likely({operand} != Py_None)"
1200
+ else:
1201
+ function = "PyFloat_CheckExact" if expected == 'float' else 'PyLong_CheckExact'
1202
+ check = f"{function}({operand})"
1203
+ other_type = type2 if operand == 'op1' else type1
1204
+ if other_type == expected:
1205
+ check = f"likely({check})"
1206
+ return check
1207
+ }}
1208
+
1209
+ {{if c_op in '+-*' or type1 != 'float'}}
1210
+
1211
+ #if CYTHON_USE_TYPE_SLOTS || __PYX_LIMITED_VERSION_HEX >= 0x030A0000
1212
+ #ifndef __Pyx_DEFINED_BinopTypeError
1213
+ #define __Pyx_DEFINED_BinopTypeError
1214
+
1215
+ static void __Pyx_BinopTypeError(PyObject *op1, PyObject *op2, const char* op, int inplace) {
1216
+ // op1 is either 'int' or 'float', op2 is unknown.
1217
+ // op has either 1 or 2 characters, ending with NUL.
1218
+ char opname[4] = {op[0], op[1], 0, 0};
1219
+ if (inplace) {
1220
+ opname[op[1] ? 2 : 1] = '=';
1221
+ }
1222
+ __Pyx_RaiseErrorWithObjectTypes1(
1223
+ PyExc_TypeError,
1224
+ "unsupported operand type(s) for %.3s: '" __Pyx_FMT_TYPENAME "' and '" __Pyx_FMT_TYPENAME "'",
1225
+ opname, op1, op2);
1226
+ }
1227
+ #endif
1228
+ #endif
1229
+
1230
+ {{endif}}
1231
+
1232
+ {{if c_op in '+-*'}}
1233
+
1234
+ {{if type1 in ('object', 'float')}}
1235
+ #ifndef __Pyx_DEFINED_{{op_name}}_xfloat_{{type2}}
1236
+ #define __Pyx_DEFINED_{{op_name}}_xfloat_{{type2}}
1237
+
1238
+ static PyObject* __Pyx_{{op_name}}_xfloat_{{type2}}(PyObject *op1, PyObject *op2, int inplace) {
1239
+ {{if type2 in ('object', 'int')}}
1240
+ if ({{is_type('op2', 'int')}}) {
1241
+ double int_op2;
1242
+ #if CYTHON_USE_PYLONG_INTERNALS
1243
+ if (__Pyx_PyLong_IsCompact(op2)) {
1244
+ Py_ssize_t compact_op2 = __Pyx_PyLong_CompactValue(op2);
1245
+ {{if c_op in '+-'}}
1246
+ if (compact_op2 == 0) return __Pyx_NewRef(op1);
1247
+ {{endif}}
1248
+ int_op2 = (double) compact_op2;
1249
+ } else
1250
+ #endif
1251
+ {
1252
+ int_op2 = PyLong_AsDouble(op2);
1253
+ if (unlikely((int_op2 == -1.) && PyErr_Occurred())) return NULL;
1254
+
1255
+ {{if c_op in '+-'}}
1256
+ #if !CYTHON_USE_PYLONG_INTERNALS
1257
+ if (int_op2 == 0.) return __Pyx_NewRef(op1);
1258
+ #endif
1259
+ {{endif}}
1260
+ }
1261
+
1262
+ double float_op1 = __Pyx_PyFloat_AS_DOUBLE(op1);
1263
+ #if !CYTHON_ASSUME_SAFE_MACROS
1264
+ if (unlikely((float_op1 == -1.) && PyErr_Occurred())) return NULL;
1265
+ #endif
1266
+
1267
+ {{if c_op == '*'}}
1268
+ // "0 * op2" could be handled before extracting op2, but that has the potential
1269
+ // to fail for very large numbers in op2 and we'd like to keep that error.
1270
+ if (float_op1 == 0.) return __Pyx_NewRef(op1);
1271
+ {{endif}}
1272
+
1273
+ return PyFloat_FromDouble(float_op1 {{c_op}} int_op2);
1274
+ }
1275
+ {{endif}}
1276
+
1277
+ {{if type2 == 'object'}}
1278
+ if (PyLong_Check(op2)) {
1279
+ // Pass PyLong subclasses to PyFloat-op1.
1280
+ binaryfunc slot_func = __Pyx_PyType_GetSubSlot(&PyFloat_Type, tp_as_number, nb_{{slot_name}}, binaryfunc);
1281
+ if (likely(slot_func)) {
1282
+ return slot_func(op1, op2);
1283
+ }
1284
+ }
1285
+ {{endif}}
1286
+
1287
+ // PyFloat-op1 only handles exact PyFloat/PyLong as op2, everything else is left to op2.
1288
+ // PyLong-op2 is handled above, so we can always pass on to op2 here.
1289
+
1290
+ // Avoid running into non-heap-type problems in Py<3.10 Limited API.
1291
+ #if CYTHON_USE_TYPE_SLOTS || __PYX_LIMITED_VERSION_HEX >= 0x030A0000
1292
+ {
1293
+ PyTypeObject *type_op2 = Py_TYPE(op2);
1294
+ // Reverse operation => ignore 'InPlace' operator since it applies to op1, not op2.
1295
+ binaryfunc slot_func = __Pyx_PyType_GetSubSlot(type_op2, tp_as_number, nb_{{slot_name}}, binaryfunc);
1296
+ if (likely(slot_func)) {
1297
+ PyObject *result = slot_func(op1, op2);
1298
+ if (likely(result != Py_NotImplemented)) {
1299
+ return result;
1300
+ }
1301
+ Py_DECREF(result);
1302
+ }
1303
+ // No "sq_concat" since Python doesn't try it on op2 and 'float' definitely doesn't have it.
1304
+
1305
+ __Pyx_BinopTypeError(op1, op2, "{{c_op}}", inplace);
1306
+ return NULL;
1307
+
1308
+ }
1309
+ #else
1310
+ return (inplace) ? {{inplace_op_name}}(op1, op2) : {{op_name}}(op1, op2);
1311
+ #endif
1312
+ }
1313
+ #endif
1314
+ {{endif}}
1315
+
1316
+ // c_op in '+-*'
1317
+ {{endif}}
1318
+
1319
+ {{if type1 in ('object', 'int')}}
1320
+ #ifndef __Pyx_DEFINED_{{op_name}}_xint_{{type2}}
1321
+ #define __Pyx_DEFINED_{{op_name}}_xint_{{type2}}
1322
+
1323
+ static PyObject* __Pyx_{{op_name}}_xint_{{type2}}(PyObject *op1, PyObject *op2, int inplace) {
1324
+ {{if type2 in ('object', 'float') and c_op in '+-*'}}
1325
+ if ({{is_type('op2', 'float')}}) {
1326
+ double int_op1;
1327
+ #if CYTHON_USE_PYLONG_INTERNALS
1328
+ if (__Pyx_PyLong_IsCompact(op1)) {
1329
+ Py_ssize_t compact_op1 = __Pyx_PyLong_CompactValue(op1);
1330
+ {{if c_op == '+'}}
1331
+ if (compact_op1 == 0) return __Pyx_NewRef(op2);
1332
+ {{endif}}
1333
+ int_op1 = (double) compact_op1;
1334
+ } else
1335
+ #endif
1336
+ {
1337
+ int_op1 = PyLong_AsDouble(op1);
1338
+ if (unlikely((int_op1 == -1.) && PyErr_Occurred())) return NULL;
1339
+
1340
+ {{if c_op == '+'}}
1341
+ #if !CYTHON_USE_PYLONG_INTERNALS
1342
+ if (int_op1 == 0.) return __Pyx_NewRef(op2);
1343
+ #endif
1344
+ {{endif}}
1345
+ }
1346
+
1347
+ double float_op2 = __Pyx_PyFloat_AS_DOUBLE(op2);
1348
+ #if !CYTHON_ASSUME_SAFE_MACROS
1349
+ if (unlikely((float_op2 == -1.) && PyErr_Occurred())) return NULL;
1350
+ #endif
1351
+
1352
+ return PyFloat_FromDouble(int_op1 {{c_op}} float_op2);
1353
+ }
1354
+ {{endif}}
1355
+
1356
+ // PyLong-op1 only handles exact PyLong as op2, everything else is left to op2.
1357
+ // Thus, we can always pass on to op2 here.
1358
+
1359
+ // Avoid running into non-heap-type problems in Py<3.10 Limited API.
1360
+ #if CYTHON_USE_TYPE_SLOTS || __PYX_LIMITED_VERSION_HEX >= 0x030A0000
1361
+ {
1362
+ PyTypeObject *type_op2 = Py_TYPE(op2);
1363
+ // Reverse operation => ignore 'InPlace' operator since it applies to op1, not op2.
1364
+ binaryfunc slot_func = __Pyx_PyType_GetSubSlot(type_op2, tp_as_number, nb_{{slot_name}}, binaryfunc);
1365
+ if (likely(slot_func)) {
1366
+ PyObject *result = slot_func(op1, op2);
1367
+ if (likely(result != Py_NotImplemented)) {
1368
+ return result;
1369
+ }
1370
+ Py_DECREF(result);
1371
+ }
1372
+ // No "sq_concat" since Python doesn't try it on op2 and 'int' definitely doesn't have it.
1373
+ {{if c_op == '*'}}
1374
+ ssizeargfunc repeat_func = __Pyx_PyType_GetSubSlot(type_op2, tp_as_sequence, sq_repeat, ssizeargfunc);
1375
+ if (likely(repeat_func)) {
1376
+ Py_ssize_t count;
1377
+ #if CYTHON_USE_PYLONG_INTERNALS
1378
+ if (__Pyx_PyLong_IsCompact(op1)) {
1379
+ count = __Pyx_PyLong_CompactValue(op1);
1380
+ } else
1381
+ #endif
1382
+ {
1383
+ count = PyLong_AsSsize_t(op1);
1384
+ if (unlikely((count == -1) && PyErr_Occurred())) return NULL;
1385
+ }
1386
+ return repeat_func(op2, count);
1387
+ }
1388
+ {{endif}}
1389
+
1390
+ __Pyx_BinopTypeError(op1, op2, "{{c_op}}", inplace);
1391
+ return NULL;
1392
+
1393
+ }
1394
+ #else
1395
+ return (inplace) ? {{inplace_op_name}}(op1, op2) : {{op_name}}(op1, op2);
1396
+ #endif
1397
+ }
1398
+ #endif
1399
+ {{endif}}
1400
+
1401
+ static CYTHON_INLINE PyObject* __Pyx__{{op_name}}_{{type1}}_{{type2}}(PyObject *op1, PyObject *op2, int inplace) {
1402
+ {{if type1 in ('object', 'float') and c_op in '+-*'}}
1403
+ if ({{is_type('op1', 'float')}}) {
1404
+ {{if type2 in ('object', 'float')}}
1405
+ if ({{is_type('op2', 'float')}}) {
1406
+ double float_op2 = __Pyx_PyFloat_AS_DOUBLE(op2);
1407
+ #if !CYTHON_ASSUME_SAFE_MACROS
1408
+ if (unlikely((float_op2 == -1.) && PyErr_Occurred())) return NULL;
1409
+ #endif
1410
+ double float_op1 = __Pyx_PyFloat_AS_DOUBLE(op1);
1411
+ #if !CYTHON_ASSUME_SAFE_MACROS
1412
+ if (unlikely((float_op1 == -1.) && PyErr_Occurred())) return NULL;
1413
+ #endif
1414
+
1415
+ return PyFloat_FromDouble(float_op1 {{c_op}} float_op2);
1416
+ }
1417
+ {{endif}}
1418
+ return __Pyx_{{op_name}}_xfloat_{{type2}}(op1, op2, inplace);
1419
+ }
1420
+ {{endif}}
1421
+
1422
+ {{if type1 in ('object', 'int')}}
1423
+ if ({{is_type('op1', 'int')}}) {
1424
+ {{if type2 in ('object', 'int')}}
1425
+ if ({{is_type('op2', 'int')}}) {
1426
+ #if CYTHON_USE_PYLONG_INTERNALS
1427
+ {{if c_op == '*'}}
1428
+
1429
+ if (__Pyx_PyLong_IsCompact(op1)) {
1430
+ long long int_op1 = (long long) __Pyx_PyLong_CompactValue(op1);
1431
+ if (int_op1 == 0) return __Pyx_NewRef(op1);
1432
+
1433
+ if (__Pyx_PyLong_IsCompact(op2)) {
1434
+ long long int_op2 = (long long) __Pyx_PyLong_CompactValue(op2);
1435
+ if (int_op2 == 0) return __Pyx_NewRef(op2);
1436
+
1437
+ return PyLong_FromLongLong(int_op1 {{c_op}} int_op2);
1438
+ }
1439
+ }
1440
+
1441
+ {{else}}
1442
+
1443
+ if (__Pyx_PyLong_IsCompact(op1)) {
1444
+ Py_ssize_t int_op1 = __Pyx_PyLong_CompactValue(op1);
1445
+ {{if c_op in '+|^'}}
1446
+ if (int_op1 == 0) return __Pyx_NewRef(op2);
1447
+ {{elif c_op == '&'}}
1448
+ if (int_op1 == 0) return __Pyx_NewRef(op1);
1449
+ {{endif}}
1450
+
1451
+ if (__Pyx_PyLong_IsCompact(op2)) {
1452
+ Py_ssize_t int_op2 = __Pyx_PyLong_CompactValue(op2);
1453
+ {{if c_op in '+-|^'}}
1454
+ if (int_op2 == 0) return __Pyx_NewRef(op1);
1455
+ {{elif c_op == '&'}}
1456
+ if (int_op2 == 0) return __Pyx_NewRef(op2);
1457
+ {{endif}}
1458
+
1459
+ return PyLong_FromSsize_t(int_op1 {{c_op}} int_op2);
1460
+ }
1461
+ }
1462
+ {{endif}}
1463
+
1464
+ // op1 is not compact, but op2 might still hit the special case for '0':
1465
+ // identity for '+-|^' -> reuse op1
1466
+ // zero for '*&' -> reuse op2
1467
+ else if (__Pyx_PyLong_IsZero(op2)) return __Pyx_NewRef({{if c_op in '+-|^'}}op1{{else}}op2{{endif}});
1468
+
1469
+ #endif
1470
+
1471
+ binaryfunc slot_func = __Pyx_PyType_GetSubSlot(&PyLong_Type, tp_as_number, nb_{{slot_name}}, binaryfunc);
1472
+ if (likely(slot_func)) {
1473
+ return slot_func(op1, op2);
1474
+ }
1475
+ }
1476
+ {{endif}}
1477
+
1478
+ return __Pyx_{{op_name}}_xint_{{type2}}(op1, op2, inplace);
1479
+ }
1480
+ {{endif}}
1481
+
1482
+ return (inplace) ? {{inplace_op_name}}(op1, op2) : {{op_name}}(op1, op2);
1483
+ }
1484
+ // !(PyPy/Graal/LimitedAPI)
1485
+ #endif
1486
+
1487
+
1488
+ /////////////// UnicodeEquals.proto ///////////////
1489
+ //@requires: PyObjectCompare{"return_obj": 0, "op": "Eq", "c_op": "==", "type1": "str", "type2": "str"}
1490
+
1491
+ #define __Pyx_PyUnicode_Equals(s1, s2) __Pyx_PyObject_CompareBoolEq_str_str(s1, s2, Py_EQ)
1492
+
1493
+
1494
+ /////////////// PyObjectCompare.proto ///////////////
1495
+
1496
+ {{py: c_ret_type = 'PyObject*' if return_obj else 'int'}}
1497
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyObject_Compare{{'' if return_obj else 'Bool'}}{{op}}_{{type1}}_{{type2}}(PyObject *op1, PyObject *op2, int pyop); /*proto*/
1498
+
1499
+ /////////////// PyObjectCompare ///////////////
1500
+ //@requires: StringTools.c::IncludeStringH
1501
+
1502
+ {{py: c_ret_type = 'PyObject*' if return_obj else 'int'}}
1503
+ {{py: func_suffix = f"{'' if return_obj else 'Bool'}{op}"}}
1504
+ {{py: return_true = 'goto __pyx_return_true'}}
1505
+ {{py: return_false = 'goto __pyx_return_false'}}
1506
+ {{py: return_error = "return NULL" if return_obj else "return -1"}}
1507
+ {{py: c_op_reversed = {'==': '==', '!=': '!=', '<': '>=', '<=': '>', '>=': '<', '>': '<='}[c_op] }}
1508
+ {{py:
1509
+ check_functions = {
1510
+ 'float': "PyFloat_CheckExact",
1511
+ 'int': 'PyLong_CheckExact',
1512
+ 'str': 'PyUnicode_CheckExact',
1513
+ 'bytes': 'PyBytes_CheckExact',
1514
+ 'bytearray': 'PyByteArray_CheckExact',
1515
+ }
1516
+ }}
1517
+ {{py:
1518
+ def is_type(operand, expected, type1=type1, type2=type2, check_functions=check_functions):
1519
+ assert operand in ('op1', 'op2'), operand
1520
+ assert expected in check_functions, expected
1521
+ type = type1 if operand == 'op1' else type2
1522
+ if type == expected:
1523
+ check = f"likely({operand} != Py_None)"
1524
+ else:
1525
+ function = check_functions[expected]
1526
+ check = f"{function}({operand})"
1527
+ other_type = type2 if operand == 'op1' else type1
1528
+ if other_type == expected:
1529
+ check = f"likely({check})"
1530
+ return check
1531
+ }}
1532
+
1533
+ // str comparisons
1534
+
1535
+ {{if type1 in ('object', 'str') and type2 in ('object', 'str')}}
1536
+ #ifndef __Pyx_DEFINED_PyObject_CompareStrStr{{func_suffix}}
1537
+ #define __Pyx_DEFINED_PyObject_CompareStrStr{{func_suffix}}
1538
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyObject_CompareStrStr{{func_suffix}}(PyObject* s1, PyObject* s2) {
1539
+ {{if op in 'EqNe'}}
1540
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030e0000
1541
+ int result = PyUnicode_Equal(s1, s2);
1542
+ #if !CYTHON_COMPILING_IN_CPYTHON
1543
+ // Cannot fail in CPython, but might in others.
1544
+ if (unlikely(result == -1)) {{return_error}};
1545
+ #endif
1546
+ if (result {{c_op}} 0) {{return_false}}; else {{return_true}};
1547
+ #else
1548
+ {{endif}}
1549
+ int result = PyUnicode_Compare(s1, s2);
1550
+ if (unlikely((result == -1) && PyErr_Occurred())) {{return_error}};
1551
+ if (result {{c_op}} 0) {{return_true}}; else {{return_false}};
1552
+ {{if op in 'EqNe'}}
1553
+ #endif
1554
+ {{endif}}
1555
+
1556
+ __pyx_return_true:
1557
+ {{'Py_RETURN_TRUE' if return_obj else 'return 1'}};
1558
+ __pyx_return_false:
1559
+ {{'Py_RETURN_FALSE' if return_obj else 'return 0'}};
1560
+ }
1561
+ #endif
1562
+ // end of str comparisons
1563
+ {{endif}}
1564
+
1565
+ // bytes/bytearray comparisons
1566
+
1567
+ {{for s1_type in ('bytes', 'bytearray')}}
1568
+ {{for s2_type in ('bytes', 'bytearray')}}
1569
+
1570
+ {{if type1 in ('object', s1_type) and type2 in ('object', s2_type)}}
1571
+
1572
+ {{py: s1_prefix = "PyBytes" if s1_type == 'bytes' else "PyByteArray"}}
1573
+ {{py: s2_prefix = "PyBytes" if s2_type == 'bytes' else "PyByteArray"}}
1574
+
1575
+ #if !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_GRAAL)
1576
+
1577
+ #ifndef __Pyx_DEFINED_PyObject_Compare{{s1_prefix}}{{s2_prefix}}{{func_suffix}}
1578
+ #define __Pyx_DEFINED_PyObject_Compare{{s1_prefix}}{{s2_prefix}}{{func_suffix}}
1579
+
1580
+ {{if op in 'EqNe'}}
1581
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyObject_Compare{{s1_prefix}}{{s2_prefix}}{{func_suffix}}(PyObject* s1, PyObject* s2) {
1582
+ #if CYTHON_ASSUME_SAFE_SIZE && CYTHON_ASSUME_SAFE_MACROS
1583
+ const char *ps1, *ps2;
1584
+ Py_ssize_t length = {{s1_prefix}}_GET_SIZE(s1);
1585
+ if (length != {{s2_prefix}}_GET_SIZE(s2)) {{return_false if op == 'Eq' else return_true}};
1586
+
1587
+ ps1 = {{s1_prefix}}_AS_STRING(s1);
1588
+ ps2 = {{s2_prefix}}_AS_STRING(s2);
1589
+
1590
+ #else
1591
+
1592
+ char *ps1, *ps2;
1593
+ Py_ssize_t length, length2;
1594
+
1595
+ {{if s1_type == 'bytes'}}
1596
+ if (unlikely(PyBytes_AsStringAndSize(s1, &ps1, &length) == -1)) {{return_error}};
1597
+ {{else}}
1598
+ ps1 = __Pyx_PyByteArray_AsString(s1); if (unlikely(!ps1)) {{return_error}};
1599
+ length = __Pyx_PyByteArray_GET_SIZE(s1); if (unlikely(length == -1)) {{return_error}};
1600
+ {{endif}}
1601
+
1602
+ {{if s2_type == 'bytes'}}
1603
+ if (unlikely(PyBytes_AsStringAndSize(s2, &ps2, &length2) == -1)) {{return_error}};
1604
+ {{else}}
1605
+ ps2 = __Pyx_PyByteArray_AsString(s2); if (unlikely(!ps2)) {{return_error}};
1606
+ length2 = __Pyx_PyByteArray_GET_SIZE(s2); if (unlikely(length2 == -1)) {{return_error}};
1607
+ {{endif}}
1608
+
1609
+ if (length != length2) {{return_false if op == 'Eq' else return_true}};
1610
+
1611
+ #endif
1612
+
1613
+ // len(s1) == len(s2)
1614
+ {{if s1_type == 'bytearray'}}
1615
+ if (length == 0) {{return_true if op == 'Eq' else return_false}};
1616
+ {{else}}
1617
+ // bytes: length >= 1 (empty bytes is singleton, and "s1 is not s2")
1618
+ {{endif}}
1619
+
1620
+ if (ps1[0] != ps2[0]) {{return_false if op == 'Eq' else return_true}};
1621
+ if (length == 1) {{return_true if op == 'Eq' else return_false}};
1622
+
1623
+ {
1624
+ int cmp;
1625
+ {{if s1_type == 'bytes' and s2_type == 'bytes'}}
1626
+ #if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000)
1627
+ Py_hash_t hash1 = ((PyBytesObject*)s1)->ob_shash;
1628
+ Py_hash_t hash2 = ((PyBytesObject*)s2)->ob_shash;
1629
+ if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {{return_false if op == 'Eq' else return_true}};
1630
+ #endif
1631
+ {{endif}}
1632
+ cmp = memcmp(ps1, ps2, (size_t)length);
1633
+ if (cmp {{c_op}} 0) {{return_true}}; else {{return_false}};
1634
+ }
1635
+
1636
+ __pyx_return_true:
1637
+ {{'Py_RETURN_TRUE' if return_obj else 'return 1'}};
1638
+ __pyx_return_false:
1639
+ {{'Py_RETURN_FALSE' if return_obj else 'return 0'}};
1640
+ }
1641
+
1642
+ {{else}}
1643
+ // !EqNe
1644
+
1645
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyObject_Compare{{s1_prefix}}{{s2_prefix}}{{func_suffix}}(PyObject* s1, PyObject* s2) {
1646
+ Py_ssize_t cmp;
1647
+ Py_ssize_t length1, length2, short_length;
1648
+
1649
+ #if CYTHON_ASSUME_SAFE_SIZE && CYTHON_ASSUME_SAFE_MACROS
1650
+ const char *ps1, *ps2;
1651
+ length1 = __Pyx_{{s1_prefix}}_GET_SIZE(s1);
1652
+ length2 = __Pyx_{{s2_prefix}}_GET_SIZE(s2);
1653
+
1654
+ short_length = (length1 < length2) ? length1 : length2;
1655
+ if (short_length == 0) {
1656
+ if (length1 == 0) {{return_true if op in 'LtLe' else return_false}}; else {{return_false if op in 'LtLe' else return_true}};
1657
+ }
1658
+
1659
+ ps1 = {{s1_prefix}}_AS_STRING(s1);
1660
+ ps2 = {{s2_prefix}}_AS_STRING(s2);
1661
+
1662
+ #else
1663
+ char *ps1, *ps2;
1664
+
1665
+ {{if s1_type == 'bytes'}}
1666
+ if (unlikely(PyBytes_AsStringAndSize(s1, &ps1, &length1) == -1)) {{return_error}};
1667
+ {{else}}
1668
+ ps1 = __Pyx_PyByteArray_AsString(s1); if (unlikely(!ps1)) {{return_error}};
1669
+ length1 = __Pyx_PyByteArray_GET_SIZE(s1); if (unlikely(length1 == -1)) {{return_error}};
1670
+ {{endif}}
1671
+
1672
+ {{if s2_type == 'bytes'}}
1673
+ if (unlikely(PyBytes_AsStringAndSize(s2, &ps2, &length2) == -1)) {{return_error}};
1674
+ {{else}}
1675
+ ps2 = __Pyx_PyByteArray_AsString(s2); if (unlikely(!ps2)) {{return_error}};
1676
+ length2 = __Pyx_PyByteArray_GET_SIZE(s2); if (unlikely(length2 == -1)) {{return_error}};
1677
+ {{endif}}
1678
+
1679
+ short_length = (length1 < length2) ? length1 : length2;
1680
+ if (short_length == 0) {
1681
+ if (length1 == 0) {{return_true if op in 'LtLe' else return_false}}; else {{return_false if op in 'LtLe' else return_true}};
1682
+ }
1683
+ #endif
1684
+
1685
+ cmp = (Py_ssize_t) ((const unsigned char*) ps1)[0] - (Py_ssize_t) ((const unsigned char*) ps2)[0];
1686
+ if (cmp == 0 && short_length > 1) {
1687
+ cmp = memcmp(ps1, ps2, (size_t)short_length);
1688
+ }
1689
+ if (cmp == 0) cmp = (length1 - length2);
1690
+ if (cmp {{c_op}} 0) {{return_true}}; else {{return_false}};
1691
+
1692
+ __pyx_return_true:
1693
+ {{'Py_RETURN_TRUE' if return_obj else 'return 1'}};
1694
+ __pyx_return_false:
1695
+ {{'Py_RETURN_FALSE' if return_obj else 'return 0'}};
1696
+ }
1697
+ {{endif}}
1698
+
1699
+ // End of bytes/bytearray comparisons.
1700
+ #endif
1701
+ #endif
1702
+ {{endif}}
1703
+
1704
+ {{endfor}}
1705
+ {{endfor}}
1706
+
1707
+ // float/int comparisons
1708
+
1709
+ {{if type1 in ('object', 'float') and type2 in ('object', 'int')}}
1710
+ // Less likely, non-inlined comparison of float and int.
1711
+ #ifndef __Pyx_DEFINED_PyObject_CompareFloatInt{{func_suffix}}
1712
+ #define __Pyx_DEFINED_PyObject_CompareFloatInt{{func_suffix}}
1713
+ static {{c_ret_type}} __Pyx_PyObject_CompareFloatInt{{func_suffix}}(PyObject *op1, PyObject *op2) {
1714
+ double float_op1 = __Pyx_PyFloat_AS_DOUBLE(op1);
1715
+ #if !CYTHON_ASSUME_SAFE_MACROS
1716
+ if (unlikely(float_op1 == -1. && PyErr_Occurred())) {{return_error}};
1717
+ #endif
1718
+
1719
+ #if CYTHON_USE_PYLONG_INTERNALS
1720
+ if (__Pyx_PyLong_IsCompact(op2)) {
1721
+ Py_ssize_t iop2 = __Pyx_PyLong_CompactValue(op2);
1722
+ if (float_op1 {{c_op}} ((double)iop2)) {{return_true}}; else {{return_false}};
1723
+ }
1724
+ if (unlikely(!__Pyx_isfinite(float_op1))) {
1725
+ // CPython just compares inf/nan to 0.0
1726
+ if (float_op1 {{c_op}} 0.0) {{return_true}}; else {{return_false}};
1727
+ } else {
1728
+ // op2 != 0 (which would be compact)
1729
+ int sign2 = __Pyx_PyLong_Sign(op2);
1730
+ if (float_op1 >= 0.) {
1731
+ if (sign2 < 0) {{return_true if op in 'NeGeGt' else return_false}};
1732
+ // same sign - is float value compact while PyLong is not?
1733
+ if (float_op1 < (double) (1L << PyLong_SHIFT)) {{return_true if op in 'NeLeLt' else return_false}};
1734
+ } else {
1735
+ if (sign2 > 0) {{return_true if op in 'NeLeLt' else return_false}};
1736
+ // same sign - is float value compact while PyLong is not?
1737
+ if (float_op1 > -(double) (1L << PyLong_SHIFT)) {{return_false if op in 'EqLeLt' else return_true}};
1738
+ }
1739
+ }
1740
+ #else
1741
+ if (unlikely(!__Pyx_isfinite(float_op1))) {
1742
+ // CPython just compares inf/nan to 0.0
1743
+ if (float_op1 {{c_op}} 0.0) {{return_true}}; else {{return_false}};
1744
+ } else {
1745
+ int overflow2;
1746
+ // We know that we have an exact PyLong value, so we assume no exceptions.
1747
+ long iop2 = PyLong_AsLongAndOverflow(op2, &overflow2);
1748
+ if (likely(!overflow2)) {
1749
+ if ((long long) iop2 >= (1LL << 53)) {
1750
+ overflow2 = 1;
1751
+ } else if ((long long) iop2 <= - (1LL << 53)) {
1752
+ overflow2 = -1;
1753
+ } else {
1754
+ if (float_op1 {{c_op}} ((double) iop2)) {{return_true}}; else {{return_false}};
1755
+ }
1756
+ }
1757
+ if (overflow2 > 0) {
1758
+ if (float_op1 < ((double) (1LL << 53))) {{return_true if op in 'NeLeLt' else return_false}};
1759
+ } else {
1760
+ if (float_op1 > - ((double) (1LL << 53))) {{return_true if op in 'NeGeGt' else return_false}};
1761
+ }
1762
+ }
1763
+ #endif
1764
+
1765
+ return {{'PyObject_RichCompare' if return_obj else '__Pyx_PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}});
1766
+
1767
+ __pyx_return_true:
1768
+ {{'Py_RETURN_TRUE' if return_obj else 'return 1'}};
1769
+ __pyx_return_false:
1770
+ {{'Py_RETURN_FALSE' if return_obj else 'return 0'}};
1771
+ }
1772
+ #endif
1773
+ {{endif}}
1774
+
1775
+ {{if type1 in ('object', 'int') and type2 in ('object', 'float')}}
1776
+ // Less likely, non-inlined comparison of int and float.
1777
+ #ifndef __Pyx_DEFINED_PyObject_CompareIntFloat{{func_suffix}}
1778
+ #define __Pyx_DEFINED_PyObject_CompareIntFloat{{func_suffix}}
1779
+ static {{c_ret_type}} __Pyx_PyObject_CompareIntFloat{{func_suffix}}(PyObject *op1, PyObject *op2) {
1780
+ double float_op2 = __Pyx_PyFloat_AS_DOUBLE(op2);
1781
+ #if !CYTHON_ASSUME_SAFE_MACROS
1782
+ if (unlikely(float_op2 == -1. && PyErr_Occurred())) {{return_error}};
1783
+ #endif
1784
+
1785
+ #if CYTHON_USE_PYLONG_INTERNALS
1786
+ if (__Pyx_PyLong_IsCompact(op1)) {
1787
+ Py_ssize_t iop1 = __Pyx_PyLong_CompactValue(op1);
1788
+ if (((double)iop1) {{c_op}} float_op2) {{return_true}}; else {{return_false}};
1789
+ }
1790
+ if (unlikely(!__Pyx_isfinite(float_op2))) {
1791
+ // CPython just compares inf/nan to 0.0
1792
+ if (0.0 {{c_op}} float_op2) {{return_true}}; else {{return_false}};
1793
+ } else {
1794
+ // op1 != 0 (which would be compact)
1795
+ int sign1 = __Pyx_PyLong_Sign(op1);
1796
+ if (float_op2 >= 0.) {
1797
+ if (sign1 < 0) {{return_true if op in 'NeLeLt' else return_false}};
1798
+ // same sign - is float value compact while PyLong is not?
1799
+ if (float_op2 < (double) (1L << PyLong_SHIFT)) {{return_true if op in 'NeGeGt' else return_false}};
1800
+ } else {
1801
+ if (sign1 > 0) {{return_true if op in 'NeGeGt' else return_false}};
1802
+ // same sign - is float value compact while PyLong is not?
1803
+ if (float_op2 > -(double) (1L << PyLong_SHIFT)) {{return_false if op in 'EqGeGt' else return_true}};
1804
+ }
1805
+ }
1806
+ #else
1807
+ if (unlikely(!__Pyx_isfinite(float_op2))) {
1808
+ // CPython just compares inf/nan to 0.0
1809
+ if (0.0 {{c_op}} float_op2) {{return_true}}; else {{return_false}};
1810
+ } else {
1811
+ int overflow1;
1812
+ // We know that we have an exact PyLong value, so we assume no exceptions.
1813
+ long iop1 = PyLong_AsLongAndOverflow(op1, &overflow1);
1814
+ if (likely(!overflow1)) {
1815
+ if ((long long) iop1 >= (1LL << 53)) {
1816
+ overflow1 = 1;
1817
+ } else if ((long long) iop1 <= - (1LL << 53)) {
1818
+ overflow1 = -1;
1819
+ } else {
1820
+ if (((double) iop1) {{c_op}} float_op2) {{return_true}}; else {{return_false}};
1821
+ }
1822
+ }
1823
+ if (overflow1 < 0) {
1824
+ if (float_op2 > ((double) (1LL << 53))) {{return_true if op in 'NeLeLt' else return_false}};
1825
+ } else {
1826
+ if (float_op2 < - ((double) (1LL << 53))) {{return_true if op in 'NeGeGt' else return_false}};
1827
+ }
1828
+ }
1829
+ #endif
1830
+
1831
+ return {{'PyObject_RichCompare' if return_obj else '__Pyx_PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}});
1832
+
1833
+ __pyx_return_true:
1834
+ {{'Py_RETURN_TRUE' if return_obj else 'return 1'}};
1835
+ __pyx_return_false:
1836
+ {{'Py_RETURN_FALSE' if return_obj else 'return 0'}};
1837
+ }
1838
+ #endif
1839
+ {{endif}}
1840
+
1841
+ {{if type1 in ('object', 'int') and type2 in ('object', 'int')}}
1842
+ {{py: from Cython.Utility import pylong_join }}
1843
+
1844
+ #if CYTHON_USE_PYLONG_INTERNALS
1845
+
1846
+ #ifndef __Pyx_DEFINED_PyObject_CompareIntIntBool{{op}}
1847
+ #define __Pyx_DEFINED_PyObject_CompareIntIntBool{{op}}
1848
+ static int __Pyx_PyObject_CompareIntIntBool{{op}}(PyObject *op1, PyObject *op2) {
1849
+ Py_ssize_t cmp = __Pyx_PyLong_CompareSignAndSize(op1, op2);
1850
+ if (cmp == 0) {
1851
+ Py_ssize_t size = __Pyx_PyLong_DigitCount(op1);
1852
+ if (size > 0) {
1853
+ const digit* digits1 = __Pyx_PyLong_Digits(op1);
1854
+ const digit* digits2 = __Pyx_PyLong_Digits(op2);
1855
+ if (size == 1) {
1856
+ cmp = (Py_ssize_t) digits1[0] - (Py_ssize_t) digits2[0];
1857
+ } else if ((size == 2) && (8 * sizeof(Py_ssize_t) >= 2 * PyLong_SHIFT)) {
1858
+ cmp = (Py_ssize_t) {{pylong_join(2, 'digits1', 'size_t')}} - (Py_ssize_t) {{pylong_join(2, 'digits2', 'size_t')}};
1859
+ } else {
1860
+ for (Py_ssize_t i=size-1; i >= 0 && !cmp; --i) {
1861
+ cmp = (Py_ssize_t) digits1[i] - (Py_ssize_t) digits2[i];
1862
+ }
1863
+ }
1864
+ }
1865
+ if (cmp == 0) return {{'1' if op in 'EqLeGe' else '0'}};
1866
+ if (__Pyx_PyLong_IsNeg(op1)) cmp = -cmp;
1867
+ }
1868
+
1869
+ return {{if op == 'Eq'}}0{{elif op == 'Ne'}}1{{else}}(cmp {{c_op}} 0){{endif}};
1870
+ }
1871
+ #endif
1872
+
1873
+ #ifndef __Pyx_DEFINED_PyObject_CompareIntInt{{func_suffix}}
1874
+ #define __Pyx_DEFINED_PyObject_CompareIntInt{{func_suffix}}
1875
+ static CYTHON_INLINE PyObject* __Pyx_PyObject_CompareIntInt{{op}}(PyObject *op1, PyObject *op2) {
1876
+ int result = __Pyx_PyObject_CompareIntIntBool{{op}}(op1, op2);
1877
+ if (unlikely(result == -1)) return NULL;
1878
+ return __Pyx_NewRef(result ? Py_True : Py_False);
1879
+ }
1880
+ #endif
1881
+
1882
+ #else
1883
+
1884
+ #ifndef __Pyx_DEFINED_PyObject_CompareIntInt{{func_suffix}}
1885
+ #define __Pyx_DEFINED_PyObject_CompareIntInt{{func_suffix}}
1886
+ static {{c_ret_type}} __Pyx_PyObject_CompareIntInt{{func_suffix}}(PyObject *op1, PyObject *op2) {
1887
+ int overflow1, overflow2;
1888
+ // We know that we have two exact PyLong values, so we assume no exceptions.
1889
+ long long iop1 = PyLong_AsLongLongAndOverflow(op1, &overflow1);
1890
+ long long iop2 = PyLong_AsLongLongAndOverflow(op2, &overflow2);
1891
+ if (likely(!(overflow1 | overflow2))) {
1892
+ if (iop1 {{c_op}} iop2) {{return_true}}; else {{return_false}};
1893
+ } else if (overflow1 != overflow2) {
1894
+ if (overflow1 {{c_op}} overflow2) {{return_true}}; else {{return_false}};
1895
+ } else {
1896
+ return {{'PyObject_RichCompare' if return_obj else '__Pyx_PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}});
1897
+ }
1898
+
1899
+ __pyx_return_true:
1900
+ {{'Py_RETURN_TRUE' if return_obj else 'return 1'}};
1901
+ __pyx_return_false:
1902
+ {{'Py_RETURN_FALSE' if return_obj else 'return 0'}};
1903
+ }
1904
+ #endif
1905
+
1906
+ #endif
1907
+
1908
+ // end of float/int comparisons
1909
+ {{endif}}
1910
+
1911
+ // main comparison function
1912
+
1913
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyObject_Compare{{func_suffix}}_{{type1}}_{{type2}}(PyObject *op1, PyObject *op2, int pyop) {
1914
+ CYTHON_UNUSED_VAR(pyop);
1915
+
1916
+ {{if type1 != 'object'}}
1917
+ // For concrete types, the whole rest simplifies a lot if we handle None up front.
1918
+ if (unlikely(op1 == Py_None)) {
1919
+ {{if op == 'Eq'}}
1920
+ if (op2 == Py_None) {{return_true}}; else {{if type2 != 'object'}}{{return_false}}{{else}}goto __pyx_richcmp{{endif}};
1921
+ {{elif op == 'Ne'}}
1922
+ if (op2 == Py_None) {{return_false}}; else {{if type2 != 'object'}}{{return_true}}{{else}}goto __pyx_richcmp{{endif}};
1923
+ {{else}}
1924
+ goto __pyx_richcmp;
1925
+ {{endif}}
1926
+ }
1927
+ {{endif}}
1928
+ {{if type2 != 'object'}}
1929
+ if (unlikely(op2 == Py_None)) {
1930
+ {{if op == 'Eq'}}
1931
+ if (op1 == Py_None) {{return_true}}; else {{if type1 != 'object'}}{{return_false}}{{else}}goto __pyx_richcmp{{endif}};
1932
+ {{elif op == 'Ne'}}
1933
+ if (op1 == Py_None) {{return_false}}; else {{if type1 != 'object'}}{{return_true}}{{else}}goto __pyx_richcmp{{endif}};
1934
+ {{else}}
1935
+ goto __pyx_richcmp;
1936
+ {{endif}}
1937
+ }
1938
+ {{endif}}
1939
+
1940
+ {{if (type1 == 'int' or type2 == 'int') and (type1 != 'float' and type2 != 'float')}}
1941
+ if (op1 == op2) {{return_true if op in 'EqLeGe' else return_false}};
1942
+ {{endif}}
1943
+
1944
+ {{if type1 in ('object', 'float')}}
1945
+ if ({{is_type('op1', 'float')}}) {
1946
+ {{if type2 in ('object', 'float')}}
1947
+ if ({{is_type('op2', 'float')}}) {
1948
+ double float_op1 = __Pyx_PyFloat_AS_DOUBLE(op1);
1949
+ #if !CYTHON_ASSUME_SAFE_MACROS
1950
+ if (unlikely(float_op1 == -1. && PyErr_Occurred())) {{return_error}};
1951
+ #endif
1952
+ double float_op2 = __Pyx_PyFloat_AS_DOUBLE(op2);
1953
+ #if !CYTHON_ASSUME_SAFE_MACROS
1954
+ if (unlikely(float_op2 == -1. && PyErr_Occurred())) {{return_error}};
1955
+ #endif
1956
+ if (float_op1 {{c_op}} float_op2) {{return_true}}; else {{return_false}};
1957
+ }
1958
+ {{endif}}
1959
+
1960
+ {{if type2 in ('object', 'int')}}
1961
+ if ({{is_type('op2', 'int')}}) {
1962
+ return __Pyx_PyObject_CompareFloatInt{{func_suffix}}(op1, op2);
1963
+ }
1964
+ {{endif}}
1965
+
1966
+ goto __pyx_richcmp;
1967
+ }
1968
+ {{endif}}
1969
+
1970
+ {{if type1 in ('object', 'int')}}
1971
+ if ({{is_type('op1', 'int')}}) {
1972
+ if (op1 == op2) {{return_true if op in 'EqLeGe' else return_false}};
1973
+
1974
+ {{if type2 in ('object', 'int')}}
1975
+ if ({{is_type('op2', 'int')}}) {
1976
+ return __Pyx_PyObject_CompareIntInt{{func_suffix}}(op1, op2);
1977
+ }
1978
+ {{endif}}
1979
+
1980
+ {{if type2 in ('object', 'float')}}
1981
+ if ({{is_type('op2', 'float')}}) {
1982
+ return __Pyx_PyObject_CompareIntFloat{{func_suffix}}(op1, op2);
1983
+ }
1984
+ {{endif}}
1985
+
1986
+ goto __pyx_richcmp;
1987
+ }
1988
+ {{endif}}
1989
+
1990
+ {{for string_type in ('str', 'bytes', 'bytearray')}}
1991
+ {{if type1 in ('object', string_type) and type2 in ('object', string_type)}}
1992
+
1993
+ {{if string_type != 'str'}}#if !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_GRAAL){{endif}}
1994
+ if ({{is_type('op1', string_type)}}) {
1995
+ // Catch interned and identical strings as well as the empty string.
1996
+ if (op1 == op2) {{return_true if op in 'EqLeGe' else return_false}};
1997
+
1998
+ if ({{is_type('op2', string_type)}}) {
1999
+ {{if string_type == 'bytes'}}
2000
+ return __Pyx_PyObject_ComparePyBytesPyBytes{{func_suffix}}(op1, op2);
2001
+ {{elif string_type == 'bytearray'}}
2002
+ return __Pyx_PyObject_ComparePyByteArrayPyByteArray{{func_suffix}}(op1, op2);
2003
+ {{else}}
2004
+ return __Pyx_PyObject_CompareStrStr{{func_suffix}}(op1, op2);
2005
+ {{endif}}
2006
+ }
2007
+
2008
+ {{if string_type == 'bytes' and type2 in ('object', 'bytearray')}}
2009
+ if ({{is_type('op2', 'bytearray')}}) {
2010
+ return __Pyx_PyObject_ComparePyBytesPyByteArray{{func_suffix}}(op1, op2);
2011
+ }
2012
+ {{elif string_type == 'bytearray' and type2 in ('object', 'bytes')}}
2013
+ if ({{is_type('op2', 'bytes')}}) {
2014
+ return __Pyx_PyObject_ComparePyByteArrayPyBytes{{func_suffix}}(op1, op2);
2015
+ }
2016
+ {{endif}}
2017
+
2018
+ goto __pyx_richcmp;
2019
+ }
2020
+ {{if string_type != 'str'}}#endif{{endif}}
2021
+
2022
+ {{endif}}
2023
+ {{endfor}}
2024
+
2025
+ // avoid unused labels
2026
+ if ((0)) goto __pyx_richcmp;
2027
+ if ((0)) {{return_true}};
2028
+ if ((0)) {{return_false}};
2029
+
2030
+ __pyx_richcmp:
2031
+ return {{'PyObject_RichCompare' if return_obj else '__Pyx_PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}});
2032
+
2033
+ __pyx_return_true:
2034
+ {{'Py_RETURN_TRUE' if return_obj else 'return 1'}};
2035
+ __pyx_return_false:
2036
+ {{'Py_RETURN_FALSE' if return_obj else 'return 0'}};
2037
+ }
2038
+
2039
+
2040
+ /////////////// PyLongCompare.proto ///////////////
2041
+
2042
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
2043
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, long inplace); /*proto*/
2044
+
2045
+ /////////////// PyLongCompare ///////////////
2046
+
2047
+ {{py: pyval, ival = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
2048
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
2049
+ {{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
2050
+ {{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
2051
+ {{py: slot_name = op.lower() }}
2052
+ {{py: c_op = {'Eq': '==', 'Ne': '!='}[op] }}
2053
+ {{py:
2054
+ return_compare = (
2055
+ (lambda a,b,c_op, return_true=return_true, return_false=return_false: "if ({a} {c_op} {b}) {return_true}; else {return_false};".format(
2056
+ a=a, b=b, c_op=c_op, return_true=return_true, return_false=return_false))
2057
+ if ret_type.is_pyobject else
2058
+ (lambda a,b,c_op: "return ({a} {c_op} {b});".format(a=a, b=b, c_op=c_op))
2059
+ )
2060
+ }}
2061
+
2062
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, long inplace) {
2063
+ CYTHON_MAYBE_UNUSED_VAR(intval);
2064
+ CYTHON_UNUSED_VAR(inplace);
2065
+ if (op1 == op2) {
2066
+ {{return_true if op == 'Eq' else return_false}};
2067
+ }
2068
+
2069
+ #if CYTHON_USE_PYLONG_INTERNALS
2070
+ if (likely(PyLong_CheckExact({{pyval}}))) {
2071
+ int unequal;
2072
+ unsigned long uintval;
2073
+ Py_ssize_t size = __Pyx_PyLong_DigitCount({{pyval}});
2074
+ const digit* digits = __Pyx_PyLong_Digits({{pyval}});
2075
+ if (intval == 0) {
2076
+ {{return_compare('__Pyx_PyLong_IsZero(%s)' % pyval, '1', c_op)}}
2077
+ } else if (intval < 0) {
2078
+ if (__Pyx_PyLong_IsNonNeg({{pyval}}))
2079
+ {{return_false if op == 'Eq' else return_true}};
2080
+ // both are negative => can use absolute values now.
2081
+ intval = -intval;
2082
+ } else {
2083
+ // > 0 => Py_SIZE(pyval) > 0
2084
+ if (__Pyx_PyLong_IsNeg({{pyval}}))
2085
+ {{return_false if op == 'Eq' else return_true}};
2086
+ }
2087
+ // After checking that the sign is the same (and excluding 0), now compare the absolute values.
2088
+ // When inlining, the C compiler should select exactly one line from this unrolled loop.
2089
+ uintval = (unsigned long) intval;
2090
+ {{for _size in range(4, 0, -1)}}
2091
+ #if PyLong_SHIFT * {{_size}} < SIZEOF_LONG*8
2092
+ if (uintval >> (PyLong_SHIFT * {{_size}})) {
2093
+ // The C integer value is between (PyLong_BASE ** _size) and MIN(PyLong_BASE ** _size, LONG_MAX).
2094
+ unequal = (size != {{_size+1}}) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
2095
+ {{for _i in range(1, _size+1)}} | (digits[{{_i}}] != ((uintval >> ({{_i}} * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)){{endfor}};
2096
+ } else
2097
+ #endif
2098
+ {{endfor}}
2099
+ unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
2100
+
2101
+ {{return_compare('unequal', '0', c_op)}}
2102
+ }
2103
+ #endif
2104
+
2105
+ if (PyFloat_CheckExact({{pyval}})) {
2106
+ const long {{'a' if order == 'CObj' else 'b'}} = intval;
2107
+ double {{ival}} = __Pyx_PyFloat_AS_DOUBLE({{pyval}});
2108
+ {{return_compare('(double)a', '(double)b', c_op)}}
2109
+ }
2110
+
2111
+ return {{'PyObject_RichCompare' if ret_type.is_pyobject else '__Pyx_PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}});
2112
+ }
2113
+
2114
+
2115
+ /////////////// PyLongBinop.proto ///////////////
2116
+
2117
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
2118
+ #if !CYTHON_COMPILING_IN_PYPY
2119
+ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); /*proto*/
2120
+ #else
2121
+ #define __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(op1, op2, intval, inplace, zerodivision_check) \
2122
+ {{if op in ('Eq', 'Ne')}}{{'PyObject_RichCompare' if ret_type.is_pyobject else 'PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}})
2123
+ {{else}}(inplace ? PyNumber_InPlace{{op}}(op1, op2) : PyNumber_{{op}}(op1, op2))
2124
+ {{endif}}
2125
+ #endif
2126
+
2127
+ /////////////// PyLongBinop ///////////////
2128
+
2129
+ #if !CYTHON_COMPILING_IN_PYPY
2130
+ {{py: from Cython.Utility import pylong_join }}
2131
+ {{py: pyval, ival = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
2132
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
2133
+ {{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
2134
+ {{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
2135
+ {{py: slot_name = {'TrueDivide': 'true_divide', 'FloorDivide': 'floor_divide'}.get(op, op.lower()) }}
2136
+ {{py: cfunc_name = f"__Pyx_PyLong_{'' if ret_type.is_pyobject else 'Bool'}{op}{order}" }}
2137
+ {{py:
2138
+ c_op = {
2139
+ 'Add': '+', 'Subtract': '-', 'Multiply': '*', 'Remainder': '%', 'TrueDivide': '/', 'FloorDivide': '/',
2140
+ 'Or': '|', 'Xor': '^', 'And': '&', 'Rshift': '>>', 'Lshift': '<<',
2141
+ 'Eq': '==', 'Ne': '!=',
2142
+ }[op]
2143
+ }}
2144
+ {{py:
2145
+ def zerodiv_check(operand, optype='integer', _is_mod=op == 'Remainder', _needs_check=(order == 'CObj' and c_op in '%/')):
2146
+ return (((
2147
+ 'if (unlikely(zerodivision_check && ((%s) == 0))) {'
2148
+ ' PyErr_SetString(PyExc_ZeroDivisionError, "%s division%s by zero");'
2149
+ ' return NULL;'
2150
+ '}') % (operand, optype, ' or modulo' if _is_mod else '')
2151
+ ) if _needs_check else '')
2152
+ }}
2153
+
2154
+ static {{c_ret_type}} __Pyx_Fallback_{{cfunc_name}}(PyObject *op1, PyObject *op2, int inplace) {
2155
+ {{if op in ('Eq', 'Ne')}}
2156
+ CYTHON_UNUSED_VAR(inplace);
2157
+ return {{'PyObject_RichCompare' if ret_type.is_pyobject else '__Pyx_PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}});
2158
+ {{else}}
2159
+ return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
2160
+ {{endif}}
2161
+ }
2162
+
2163
+ #if CYTHON_USE_PYLONG_INTERNALS
2164
+ {{if op == 'Lshift'}}
2165
+ #if __clang__ || __GNUC__
2166
+ // left-shift by more than the width of the number is undefined behaviour.
2167
+ // We do check it (and test that it gives the right answer though).
2168
+ __attribute__((no_sanitize("shift")))
2169
+ #endif
2170
+ {{endif}}
2171
+ static {{c_ret_type}} __Pyx_Unpacked_{{cfunc_name}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
2172
+ CYTHON_MAYBE_UNUSED_VAR(inplace);
2173
+ CYTHON_UNUSED_VAR(zerodivision_check);
2174
+
2175
+ const long {{'a' if order == 'CObj' else 'b'}} = intval;
2176
+ long {{ival}};
2177
+ {{if op not in ('Eq', 'Ne', 'TrueDivide')}}
2178
+ const PY_LONG_LONG ll{{'a' if order == 'CObj' else 'b'}} = intval;
2179
+ PY_LONG_LONG ll{{ival}};
2180
+ {{endif}}
2181
+ {{if op == 'Rshift' or op == 'Lshift'}}
2182
+ // shifting negative numbers is technically implementation defined on C, and
2183
+ // C++ before C++20. Most implementation do the right thing though so
2184
+ // special case ones we know are good.
2185
+ #if (defined(__cplusplus) && __cplusplus >= 202002L) \
2186
+ || (defined(__GNUC__) || (defined(__clang__))) && \
2187
+ (defined(__arm__) || defined(__x86_64__) || defined(__i386__)) \
2188
+ || (defined(_MSC_VER) && \
2189
+ (defined(_M_ARM) || defined(_M_AMD64) || defined(_M_IX86)))
2190
+ const int negative_shift_works = 1;
2191
+ #else
2192
+ const int negative_shift_works = 0;
2193
+ #endif
2194
+ {{endif}}
2195
+
2196
+ // special cases for 0: + - * % / // | ^ & >> <<
2197
+ if (unlikely(__Pyx_PyLong_IsZero({{pyval}}))) {
2198
+ {{if order == 'CObj' and c_op in '%/'}}
2199
+ // division by zero!
2200
+ {{zerodiv_check('0')}}
2201
+ {{elif order == 'CObj' and c_op in '+-|^>><<'}}
2202
+ // x == x+0 == x-0 == x|0 == x^0 == x>>0 == x<<0
2203
+ return __Pyx_NewRef(op1);
2204
+ {{elif order == 'CObj' and c_op in '*&'}}
2205
+ // 0 == x*0 == x&0
2206
+ return __Pyx_NewRef(op2);
2207
+ {{elif order == 'ObjC' and c_op in '+|^'}}
2208
+ // x == 0+x == 0|x == 0^x
2209
+ return __Pyx_NewRef(op2);
2210
+ {{elif order == 'ObjC' and c_op == '-'}}
2211
+ // -x == 0-x
2212
+ return PyLong_FromLong(-intval);
2213
+ {{elif order == 'ObjC' and (c_op in '*%&>><<' or op == 'FloorDivide')}}
2214
+ // 0 == 0*x == 0%x == 0&x == 0>>x == 0<<x == 0//x
2215
+ return __Pyx_NewRef(op1);
2216
+ {{endif}}
2217
+ }
2218
+
2219
+ // IsZero/IsPos/IsNeg are practically the same and can probably be decided almost for free.
2220
+ const int is_positive = __Pyx_PyLong_IsPos({{pyval}});
2221
+
2222
+ {{if c_op == '&'}}
2223
+ // special case for &-ing arbitrarily large numbers with known single digit operands
2224
+ if ((intval & PyLong_MASK) == intval) {
2225
+ // Calling PyLong_CompactValue() requires the PyLong value to be compact, we only need the last digit.
2226
+ long last_digit = (long) __Pyx_PyLong_Digits({{pyval}})[0];
2227
+ long result = intval & (likely(is_positive) ? last_digit : (PyLong_MASK - last_digit + 1));
2228
+ return PyLong_FromLong(result);
2229
+ }
2230
+ {{endif}}
2231
+
2232
+ // Handle most common case (fits into 'long') first to avoid indirect branch and optimise branch prediction.
2233
+ const digit* digits = __Pyx_PyLong_Digits({{pyval}});
2234
+ const Py_ssize_t size = __Pyx_PyLong_DigitCount({{pyval}});
2235
+ if (likely(size == 1)) {
2236
+ {{ival}} = (long) digits[0];
2237
+ if (!is_positive) {{ival}} *= -1;
2238
+ } else {
2239
+ {{for _size in range(2, 5)}}
2240
+ if (size == {{_size}} && 8 * sizeof(long) - 1 > {{_size}} * PyLong_SHIFT{{if c_op == '*'}}+30{{endif}}{{if op == 'TrueDivide'}} && {{_size-1}} * PyLong_SHIFT < 53{{endif}}) {
2241
+ {{ival}} = (long) {{pylong_join(_size, 'digits')}};
2242
+ if (!is_positive) {{ival}} *= -1;
2243
+ goto calculate_long;
2244
+ {{if op != 'TrueDivide'}}
2245
+ } else if (size == {{_size}} && 8 * sizeof(PY_LONG_LONG) - 1 > {{_size}} * PyLong_SHIFT{{if c_op == '*'}}+30{{endif}}) {
2246
+ ll{{ival}} = (PY_LONG_LONG) {{pylong_join(_size, 'digits', 'unsigned PY_LONG_LONG')}};
2247
+ if (!is_positive) ll{{ival}} *= -1;
2248
+ goto calculate_long_long;
2249
+ {{endif}}
2250
+ } else
2251
+ // size doesn't fit into a long or PY_LONG_LONG any more
2252
+ {{endfor}}
2253
+ {}
2254
+
2255
+ {{if op in ('Eq', 'Ne')}}
2256
+ #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
2257
+ // unusual setup - your fault
2258
+ return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
2259
+ PyLong_Type.tp_richcompare({{'op1, op2' if order == 'ObjC' else 'op2, op1'}}, Py_{{op.upper()}}));
2260
+ #else
2261
+ // too large for the long values we allow => definitely not equal
2262
+ {{return_false if op == 'Eq' else return_true}};
2263
+ #endif
2264
+ {{else}}
2265
+ return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
2266
+ {{endif}}
2267
+ }
2268
+
2269
+ calculate_long:
2270
+
2271
+ {{if op in ('Eq', 'Ne')}}
2272
+ if (a {{c_op}} b) {
2273
+ {{return_true}};
2274
+ } else {
2275
+ {{return_false}};
2276
+ }
2277
+ {{elif c_op == '*'}}
2278
+ // Multiplying a 'long' value with a <= 30 bits constant can give a 'long long' value.
2279
+ // Note that we constrain the bit count of the PyLong in the unpacking code above.
2280
+ CYTHON_UNUSED_VAR(a);
2281
+ CYTHON_UNUSED_VAR(b);
2282
+ ll{{ival}} = {{ival}};
2283
+ goto calculate_long_long;
2284
+ {{elif c_op == '%'}}
2285
+ {
2286
+ // see CMath.c :: ModInt utility code
2287
+ long x = a % b;
2288
+ x += ((x != 0) & ((x ^ b) < 0)) * b;
2289
+ return PyLong_FromLong(x);
2290
+ }
2291
+ {{elif op == 'TrueDivide'}}
2292
+ if ((8 * sizeof(long) <= 53 || likely(labs({{ival}}) <= ((PY_LONG_LONG)1 << 53)))
2293
+ || __Pyx_PyLong_DigitCount({{pyval}}) <= 52 / PyLong_SHIFT) {
2294
+ return PyFloat_FromDouble((double)a / (double)b);
2295
+ }
2296
+ return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
2297
+ {{elif op == 'FloorDivide'}}
2298
+ {
2299
+ long q, r;
2300
+ // see CMath.c :: DivInt utility code
2301
+ q = a / b;
2302
+ r = a - q*b;
2303
+ q -= ((r != 0) & ((r ^ b) < 0));
2304
+ return PyLong_FromLong(q);
2305
+ }
2306
+ {{else}}
2307
+ {{if op == 'Rshift' or op == 'Lshift'}}
2308
+ if ((!negative_shift_works) && unlikely(a < 0)) goto fallback;
2309
+ {{endif}}
2310
+
2311
+ {
2312
+ long x;
2313
+ {{if op == 'Rshift'}}
2314
+ if (unlikely(b >= (long) (sizeof(long)*8))) {
2315
+ x = (a < 0) ? -1 : 0;
2316
+ } else
2317
+ {{endif}}
2318
+ x = a {{c_op}} b;
2319
+
2320
+ {{if op == 'Lshift'}}
2321
+ if (unlikely(!(b < (long) (sizeof(long)*8) && a == x >> b)) && a) {
2322
+ ll{{ival}} = {{ival}};
2323
+ goto calculate_long_long;
2324
+ }
2325
+ {{endif}}
2326
+
2327
+ return PyLong_FromLong(x);
2328
+ }
2329
+ {{endif}}
2330
+
2331
+ {{if op != 'TrueDivide'}}
2332
+ calculate_long_long:
2333
+ {{if op == 'Eq'}}
2334
+ // One operand fits into a 30 bit 'long', the other doesn't => not equal.
2335
+ {{return_false}};
2336
+ {{elif op == 'Ne'}}
2337
+ // One operand fits into a 30 bit 'long', the other doesn't => not equal.
2338
+ {{return_true}};
2339
+ {{elif c_op == '%'}}
2340
+ {
2341
+ // see CMath.c :: ModInt utility code
2342
+ PY_LONG_LONG llx = lla % llb;
2343
+ llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
2344
+ return PyLong_FromLongLong(llx);
2345
+ }
2346
+ {{elif op == 'FloorDivide'}}
2347
+ {
2348
+ PY_LONG_LONG q, r;
2349
+ // see CMath.c :: DivInt utility code
2350
+ q = lla / llb;
2351
+ r = lla - q*llb;
2352
+ q -= ((r != 0) & ((r ^ llb) < 0));
2353
+ return PyLong_FromLongLong(q);
2354
+ }
2355
+ {{else}}
2356
+ {{if op == 'LShift' or op == 'Rshift'}}
2357
+ if ((!negative_shift_works) && unlikely(lla < 0)) goto fallback;
2358
+ {{endif}}
2359
+
2360
+ {
2361
+ PY_LONG_LONG llx;
2362
+ {{if op == 'Rshift'}}
2363
+ if (unlikely(llb >= (long long) (sizeof(long long)*8))) {
2364
+ llx = (lla < 0) ? -1 : 0;
2365
+ } else
2366
+ {{endif}}
2367
+ llx = lla {{c_op}} llb;
2368
+
2369
+ {{if op == 'Lshift'}}
2370
+ if (unlikely(lla != llx >> llb)) goto fallback;
2371
+ {{endif}}
2372
+ return PyLong_FromLongLong(llx);
2373
+ }
2374
+ {{endif}}
2375
+
2376
+ {{if op == 'Lshift' or op == 'Rshift'}}
2377
+ fallback:
2378
+ return __Pyx_Fallback_{{cfunc_name}}(op1, op2, inplace);
2379
+ {{endif}}
2380
+
2381
+ {{endif}}{{# if op != 'TrueDivide' #}}
2382
+ }
2383
+ #endif
2384
+
2385
+ {{if c_op in '+-*' or op in ('TrueDivide', 'Eq', 'Ne')}}
2386
+ static {{c_ret_type}} __Pyx_Float_{{cfunc_name}}(PyObject *float_val, long intval, int zerodivision_check) {
2387
+ CYTHON_UNUSED_VAR(zerodivision_check);
2388
+
2389
+ const long {{'a' if order == 'CObj' else 'b'}} = intval;
2390
+ double {{ival}} = __Pyx_PyFloat_AS_DOUBLE(float_val);
2391
+ {{if op in ('Eq', 'Ne')}}
2392
+ if ((double)a {{c_op}} (double)b) {
2393
+ {{return_true}};
2394
+ } else {
2395
+ {{return_false}};
2396
+ }
2397
+ {{else}}
2398
+ double result;
2399
+ {{zerodiv_check('b', 'float')}}
2400
+ result = ((double)a) {{c_op}} (double)b;
2401
+ return PyFloat_FromDouble(result);
2402
+ {{endif}}
2403
+ }
2404
+ {{endif}}
2405
+
2406
+ static CYTHON_INLINE {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
2407
+ CYTHON_MAYBE_UNUSED_VAR(intval);
2408
+ CYTHON_UNUSED_VAR(zerodivision_check);
2409
+
2410
+ {{if op in ('Eq', 'Ne')}}
2411
+ if (op1 == op2) {
2412
+ {{return_true if op == 'Eq' else return_false}};
2413
+ }
2414
+ {{endif}}
2415
+
2416
+ #if CYTHON_USE_PYLONG_INTERNALS
2417
+ if (likely(PyLong_CheckExact({{pyval}}))) {
2418
+ return __Pyx_Unpacked_{{cfunc_name}}(op1, op2, intval, inplace, zerodivision_check);
2419
+ }
2420
+ #endif
2421
+
2422
+ {{if c_op in '+-*' or op in ('TrueDivide', 'Eq', 'Ne')}}
2423
+ if (PyFloat_CheckExact({{pyval}})) {
2424
+ return __Pyx_Float_{{cfunc_name}}({{pyval}}, intval, zerodivision_check);
2425
+ }
2426
+ {{endif}}
2427
+
2428
+ return __Pyx_Fallback_{{cfunc_name}}(op1, op2, inplace);
2429
+ }
2430
+ #endif /* !CYTHON_COMPILING_IN_PYPY */
2431
+
2432
+
2433
+ /////////////// PyFloatBinop.proto ///////////////
2434
+
2435
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
2436
+ #if !CYTHON_COMPILING_IN_PYPY
2437
+ static {{c_ret_type}} __Pyx_PyFloat_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check); /*proto*/
2438
+ #else
2439
+ #define __Pyx_PyFloat_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(op1, op2, floatval, inplace, zerodivision_check) \
2440
+ {{if op in ('Eq', 'Ne')}}{{'PyObject_RichCompare' if ret_type.is_pyobject else 'PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}})
2441
+ {{elif op == 'Divide'}}((inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2)))
2442
+ {{else}}(inplace ? PyNumber_InPlace{{op}}(op1, op2) : PyNumber_{{op}}(op1, op2))
2443
+ {{endif}}
2444
+ #endif
2445
+
2446
+ /////////////// PyFloatBinop ///////////////
2447
+
2448
+ #if !CYTHON_COMPILING_IN_PYPY
2449
+ {{py: from Cython.Utility import pylong_join }}
2450
+ {{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
2451
+ {{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
2452
+ {{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
2453
+ {{py: pyval, fval = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
2454
+ {{py: cfunc_name = '__Pyx_PyFloat_%s%s%s' % ('' if ret_type.is_pyobject else 'Bool', op, order) }}
2455
+ {{py:
2456
+ c_op = {
2457
+ 'Add': '+', 'Subtract': '-', 'TrueDivide': '/', 'Divide': '/', 'Remainder': '%',
2458
+ 'Eq': '==', 'Ne': '!=',
2459
+ }[op]
2460
+ }}
2461
+ {{py:
2462
+ def zerodiv_check(operand, _is_mod=op == 'Remainder', _needs_check=(order == 'CObj' and c_op in '%/')):
2463
+ return (((
2464
+ 'if (unlikely(zerodivision_check && ((%s) == 0.0))) {'
2465
+ ' PyErr_SetString(PyExc_ZeroDivisionError, "float division%s by zero");'
2466
+ ' return NULL;'
2467
+ '}') % (operand, ' or modulo' if _is_mod else '')
2468
+ ) if _needs_check else '')
2469
+ }}
2470
+
2471
+ static {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check) {
2472
+ const double {{'a' if order == 'CObj' else 'b'}} = floatval;
2473
+ double {{fval}};
2474
+ CYTHON_UNUSED_VAR(inplace);
2475
+ CYTHON_UNUSED_VAR(zerodivision_check);
2476
+
2477
+ {{if op in ('Eq', 'Ne')}}
2478
+ if (op1 == op2) {
2479
+ {{return_true if op == 'Eq' else return_false}};
2480
+ }
2481
+ {{endif}}
2482
+
2483
+ if (likely(PyFloat_CheckExact({{pyval}}))) {
2484
+ {{fval}} = __Pyx_PyFloat_AS_DOUBLE({{pyval}});
2485
+ {{zerodiv_check(fval)}}
2486
+ } else
2487
+
2488
+ if (likely(PyLong_CheckExact({{pyval}}))) {
2489
+ #if CYTHON_USE_PYLONG_INTERNALS
2490
+ if (__Pyx_PyLong_IsZero({{pyval}})) {
2491
+ {{fval}} = 0.0;
2492
+ {{zerodiv_check(fval)}}
2493
+ goto digits_done;
2494
+ } else if (__Pyx_PyLong_IsCompact({{pyval}})) {
2495
+ {{fval}} = (double) __Pyx_PyLong_CompactValue({{pyval}});
2496
+ goto digits_done;
2497
+ } else {
2498
+ const digit* digits = __Pyx_PyLong_Digits({{pyval}});
2499
+ const Py_ssize_t size = __Pyx_PyLong_DigitCount({{pyval}});
2500
+ {{for _size in (2, 3, 4)}}
2501
+ if (size <= {{_size}} && (8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || ({{_size-1}} * PyLong_SHIFT < 53)))) {
2502
+ {{fval}} = (double) {{pylong_join(_size, 'digits')}};
2503
+ // let CPython do its own float rounding from 2**53 on (max. consecutive integer in double float)
2504
+ if ((8 * sizeof(unsigned long) < 53) || ({{_size}} * PyLong_SHIFT < 53) || ({{fval}} < (double) ((PY_LONG_LONG)1 << 53))) {
2505
+ if (__Pyx_PyLong_IsNeg({{pyval}})) {{fval}} = -{{fval}};
2506
+ goto digits_done;
2507
+ }
2508
+ }
2509
+ // Fall through if size doesn't fit safely into a double anymore.
2510
+ // It may not be obvious that this is a safe fall-through given the "fval < 2**53"
2511
+ // check above. However, the number of digits that CPython uses for a given PyLong
2512
+ // value is minimal, and together with the "(size-1) * SHIFT < 53" check above,
2513
+ // this should make it safe.
2514
+ {{endfor}}
2515
+ }
2516
+ #endif
2517
+
2518
+ {{if op in ('Eq', 'Ne')}}
2519
+ {
2520
+ PyObject *res =
2521
+ #if CYTHON_USE_TYPE_SLOTS || __PYX_LIMITED_VERSION_HEX >= 0x030A0000
2522
+ // PyType_GetSlot only works on non-heap types from Python 3.10
2523
+ __Pyx_PyType_GetSlot((&PyFloat_Type), tp_richcompare, richcmpfunc)
2524
+ #else
2525
+ PyObject_RichCompare
2526
+ #endif
2527
+ ({{'op1, op2' if order == 'CObj' else 'op2, op1'}},
2528
+ Py_{{op.upper()}});
2529
+
2530
+ return {{if ret_type.is_pyobject}}res{{else}}__Pyx_PyObject_IsTrueAndDecref(res){{endif}};
2531
+ }
2532
+ {{else}}
2533
+ {{fval}} = PyLong_AsDouble({{pyval}});
2534
+ if (unlikely({{fval}} == -1.0 && PyErr_Occurred())) return NULL;
2535
+ {{if zerodiv_check(fval)}}
2536
+ #if !CYTHON_USE_PYLONG_INTERNALS
2537
+ {{zerodiv_check(fval)}}
2538
+ #endif
2539
+ {{endif}}
2540
+ {{endif}}
2541
+ } else {
2542
+ {{if op in ('Eq', 'Ne')}}
2543
+ return {{'PyObject_RichCompare' if ret_type.is_pyobject else '__Pyx_PyObject_RichCompareBool'}}(op1, op2, Py_{{op.upper()}});
2544
+ {{elif op == 'Divide'}}
2545
+ return (inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2));
2546
+ {{else}}
2547
+ return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
2548
+ {{endif}}
2549
+ }
2550
+
2551
+ #if CYTHON_USE_PYLONG_INTERNALS
2552
+ digits_done:;
2553
+ #endif
2554
+
2555
+ {{if op in ('Eq', 'Ne')}}
2556
+ if (a {{c_op}} b) {
2557
+ {{return_true}};
2558
+ } else {
2559
+ {{return_false}};
2560
+ }
2561
+ {{else}}
2562
+ double result;
2563
+ {{if c_op == '%'}}
2564
+ result = fmod(a, b);
2565
+ if (result)
2566
+ result += ((result < 0) ^ (b < 0)) * b;
2567
+ else
2568
+ result = copysign(0.0, b);
2569
+ {{else}}
2570
+ result = a {{c_op}} b;
2571
+ {{endif}}
2572
+ return PyFloat_FromDouble(result);
2573
+ {{endif}}
2574
+ }
2575
+ #endif