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,1588 @@
1
+ /////////////// TypeConversions.proto ///////////////
2
+ //@requires: StringTools.c::IncludeStringH
3
+
4
+ /* Type Conversion Predeclarations */
5
+
6
+ #define __Pyx_uchar_cast(c) ((unsigned char)c)
7
+ #define __Pyx_long_cast(x) ((long)x)
8
+
9
+ #define __Pyx_fits_Py_ssize_t(v, type, is_signed) ( \
10
+ (sizeof(type) < sizeof(Py_ssize_t)) || \
11
+ (sizeof(type) > sizeof(Py_ssize_t) && \
12
+ likely(v < (type)PY_SSIZE_T_MAX || \
13
+ v == (type)PY_SSIZE_T_MAX) && \
14
+ (!is_signed || likely(v > (type)PY_SSIZE_T_MIN || \
15
+ v == (type)PY_SSIZE_T_MIN))) || \
16
+ (sizeof(type) == sizeof(Py_ssize_t) && \
17
+ (is_signed || likely(v < (type)PY_SSIZE_T_MAX || \
18
+ v == (type)PY_SSIZE_T_MAX))) )
19
+
20
+ static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
21
+ // Optimisation from Section 14.2 "Bounds Checking" in
22
+ // https://www.agner.org/optimize/optimizing_cpp.pdf
23
+ // See https://bugs.python.org/issue28397
24
+ // The cast to unsigned effectively tests for "0 <= i < limit".
25
+ return (size_t) i < (size_t) limit;
26
+ }
27
+
28
+ // fast and unsafe abs(Py_ssize_t) that ignores the overflow for (-PY_SSIZE_T_MAX-1)
29
+ #if defined (__cplusplus) && __cplusplus >= 201103L
30
+ #include <cstdlib>
31
+ #define __Pyx_sst_abs(value) std::abs(value)
32
+ #elif SIZEOF_INT >= SIZEOF_SIZE_T
33
+ #define __Pyx_sst_abs(value) abs(value)
34
+ #elif SIZEOF_LONG >= SIZEOF_SIZE_T
35
+ #define __Pyx_sst_abs(value) labs(value)
36
+ #elif defined (_MSC_VER)
37
+ // abs() is defined for long, but 64-bits type on MSVC is long long.
38
+ // Use MS-specific _abs64 instead.
39
+ #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
40
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
41
+ #define __Pyx_sst_abs(value) llabs(value)
42
+ #elif defined (__GNUC__)
43
+ // gcc or clang on 64 bit windows.
44
+ #define __Pyx_sst_abs(value) __builtin_llabs(value)
45
+ #else
46
+ #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
47
+ #endif
48
+
49
+ static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s);
50
+ static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
51
+ static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
52
+
53
+ static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*);
54
+ #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
55
+ #define __Pyx_PyBytes_FromString PyBytes_FromString
56
+ #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
57
+ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
58
+
59
+ #if CYTHON_ASSUME_SAFE_MACROS
60
+ #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
61
+ #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
62
+ #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
63
+ #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
64
+ #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
65
+ #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
66
+ #define __Pyx_PyByteArray_AsString(s) PyByteArray_AS_STRING(s)
67
+ #else
68
+ #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AsString(s))
69
+ #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AsString(s))
70
+ #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AsString(s))
71
+ #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AsString(s))
72
+ #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AsString(s))
73
+ #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AsString(s))
74
+ #define __Pyx_PyByteArray_AsString(s) PyByteArray_AsString(s)
75
+ #endif
76
+ #define __Pyx_PyObject_AsWritableString(s) ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
77
+ #define __Pyx_PyObject_AsWritableSString(s) ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
78
+ #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
79
+ #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
80
+ #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
81
+ #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
82
+ #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
83
+ #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
84
+ #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
85
+ #define __Pyx_PyUnicode_FromOrdinal(o) PyUnicode_FromOrdinal((int)o)
86
+ #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
87
+
88
+ static CYTHON_INLINE PyObject *__Pyx_NewRef(PyObject *obj) {
89
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030a0000 || defined(Py_NewRef)
90
+ return Py_NewRef(obj);
91
+ #else
92
+ Py_INCREF(obj);
93
+ return obj;
94
+ #endif
95
+ }
96
+
97
+ static CYTHON_INLINE PyObject *__Pyx_XNewRef(PyObject *obj) {
98
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030a0000 || defined(Py_XNewRef)
99
+ return Py_XNewRef(obj);
100
+ #else
101
+ Py_XINCREF(obj);
102
+ return obj;
103
+ #endif
104
+ }
105
+
106
+ static CYTHON_INLINE PyObject *__Pyx_Owned_Py_None(int b);
107
+ static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
108
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
109
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
110
+ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Long(PyObject* x);
111
+
112
+ #define __Pyx_PyObject_RichCompareBool(a,b,cmp) __Pyx_PyObject_IsTrueAndDecref(PyObject_RichCompare((a),(b),(cmp)))
113
+
114
+ #define __Pyx_PySequence_Tuple(obj) \
115
+ (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
116
+
117
+ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
118
+ static CYTHON_INLINE PyObject * __Pyx_PyLong_FromSize_t(size_t);
119
+ static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
120
+
121
+ #if CYTHON_ASSUME_SAFE_MACROS
122
+ #define __Pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
123
+ #define __Pyx_PyFloat_AS_DOUBLE(x) PyFloat_AS_DOUBLE(x)
124
+ #define __Pyx_PyFloat_IsNonZero(x) (PyFloat_AS_DOUBLE(x) != 0.0)
125
+ #else
126
+ #define __Pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
127
+ #define __Pyx_PyFloat_AS_DOUBLE(x) PyFloat_AsDouble(x)
128
+ #define __Pyx_PyFloat_IsNonZero(x) PyObject_IsTrue(x)
129
+ #endif
130
+ #define __Pyx_PyFloat_AsFloat(x) ((float) __Pyx_PyFloat_AsDouble(x))
131
+
132
+ // We call this __Pyx_PyNumber_Int() since it's the equivalent of the int() function call.
133
+ #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
134
+ // __Pyx_PyNumber_Float is now in its own section since it has dependencies (needed to make
135
+ // string conversion work the same in all circumstances).
136
+
137
+ #if CYTHON_USE_PYLONG_INTERNALS
138
+ #if PY_VERSION_HEX >= 0x030C00A7
139
+ #ifndef _PyLong_SIGN_MASK
140
+ #define _PyLong_SIGN_MASK 3
141
+ #endif
142
+ #ifndef _PyLong_NON_SIZE_BITS
143
+ #define _PyLong_NON_SIZE_BITS 3
144
+ #endif
145
+ #define __Pyx_PyLong_SignBits(x) ((int) (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK))
146
+ #define __Pyx_PyLong_Sign(x) (1 - __Pyx_PyLong_SignBits(x))
147
+ #define __Pyx_PyLong_IsNeg(x) ((__Pyx_PyLong_SignBits(x) & 2) != 0)
148
+ #define __Pyx_PyLong_IsNonNeg(x) (!__Pyx_PyLong_IsNeg(x))
149
+ #define __Pyx_PyLong_IsZero(x) (__Pyx_PyLong_SignBits(x) & 1)
150
+ #define __Pyx_PyLong_IsPos(x) (__Pyx_PyLong_SignBits(x) == 0)
151
+ #define __Pyx_PyLong_CompactValueUnsigned(x) (__Pyx_PyLong_Digits(x)[0])
152
+ #define __Pyx_PyLong_DigitCount(x) ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS))
153
+ #define __Pyx_PyLong_SignedDigitCount(x) \
154
+ (((Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x))
155
+
156
+ #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
157
+ #define __Pyx_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) x)
158
+ #define __Pyx_PyLong_CompactValue(x) PyUnstable_Long_CompactValue((PyLongObject*) x)
159
+ #else
160
+ #define __Pyx_PyLong_IsCompact(x) (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS))
161
+ #define __Pyx_PyLong_CompactValue(x) (((Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0])
162
+ #endif
163
+
164
+ static CYTHON_INLINE Py_ssize_t __Pyx_PyLong_CompareSignAndSize(PyObject *a, PyObject *b) {
165
+ uintptr_t tag_a = ((PyLongObject*)a)->long_value.lv_tag;
166
+ uintptr_t tag_b = ((PyLongObject*)b)->long_value.lv_tag;
167
+ if (tag_a == tag_b) return 0;
168
+ int sign_a = (int) (tag_a & _PyLong_SIGN_MASK);
169
+ int sign_b = (int) (tag_b & _PyLong_SIGN_MASK);
170
+ // 0: positive, 1: zero, 2: negative
171
+ if (sign_a > sign_b) return -1;
172
+ if (sign_a < sign_b) return 1;
173
+ Py_ssize_t size_a = (Py_ssize_t) (tag_a >> _PyLong_NON_SIZE_BITS);
174
+ Py_ssize_t size_b = (Py_ssize_t) (tag_b >> _PyLong_NON_SIZE_BITS);
175
+ return (1 - sign_a) * (size_a - size_b);
176
+ }
177
+
178
+ // CPython 3.12 requires C99, which defines 'size_t' (but not 'ssize_t')
179
+ typedef Py_ssize_t __Pyx_compact_pylong;
180
+ typedef size_t __Pyx_compact_upylong;
181
+
182
+ #else /* Py < 3.12 */
183
+ #define __Pyx_PyLong_Sign(x) ((int) ((Py_SIZE(x) == 0) ? 0 : (Py_SIZE(x) < 0) ? -1 : 1))
184
+ #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0)
185
+ #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0)
186
+ #define __Pyx_PyLong_IsZero(x) (Py_SIZE(x) == 0)
187
+ #define __Pyx_PyLong_IsPos(x) (Py_SIZE(x) > 0)
188
+ #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0])
189
+ #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x))
190
+ #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x)
191
+
192
+ #define __Pyx_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
193
+ #define __Pyx_PyLong_CompactValue(x) \
194
+ ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0]))
195
+
196
+ #define __Pyx_PyLong_CompareSignAndSize(a, b) (Py_SIZE(a) - Py_SIZE(b))
197
+
198
+ typedef sdigit __Pyx_compact_pylong;
199
+ typedef digit __Pyx_compact_upylong;
200
+ #endif
201
+
202
+ #if PY_VERSION_HEX >= 0x030C00A5
203
+ #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit)
204
+ #else
205
+ #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->ob_digit)
206
+ #endif
207
+
208
+ // Functions/macros that must be generally available, e.g. for truth testing.
209
+ #define __Pyx_PyLong_IsNonZero(x) (!__Pyx_PyLong_IsZero(x))
210
+ #else
211
+ #define __Pyx_PyLong_IsNonZero(x) PyObject_IsTrue(x)
212
+ #endif
213
+
214
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_UTF8
215
+ #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
216
+ #elif __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
217
+ #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeASCII(c_str, size, NULL)
218
+ #else
219
+ #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
220
+ #endif
221
+
222
+ /////////////// TypeConversions ///////////////
223
+
224
+ /* Type Conversion Functions */
225
+
226
+ #include <string.h>
227
+
228
+ static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) {
229
+ size_t len = strlen(s);
230
+ if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) {
231
+ PyErr_SetString(PyExc_OverflowError, "byte string is too long");
232
+ return -1;
233
+ }
234
+ return (Py_ssize_t) len;
235
+ }
236
+
237
+ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
238
+ Py_ssize_t len = __Pyx_ssize_strlen(c_str);
239
+ if (unlikely(len < 0)) return NULL;
240
+ return __Pyx_PyUnicode_FromStringAndSize(c_str, len);
241
+ }
242
+
243
+ static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) {
244
+ Py_ssize_t len = __Pyx_ssize_strlen(c_str);
245
+ if (unlikely(len < 0)) return NULL;
246
+ return PyByteArray_FromStringAndSize(c_str, len);
247
+ }
248
+
249
+ // Py3.7 returns a "const char*" for unicode strings
250
+ static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
251
+ Py_ssize_t ignore;
252
+ return __Pyx_PyObject_AsStringAndSize(o, &ignore);
253
+ }
254
+
255
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_UTF8
256
+ static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
257
+ if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
258
+ #if CYTHON_COMPILING_IN_LIMITED_API
259
+ {
260
+ const char* result;
261
+ Py_ssize_t unicode_length;
262
+ CYTHON_MAYBE_UNUSED_VAR(unicode_length); // only for __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
263
+ #if __PYX_LIMITED_VERSION_HEX < 0x030A0000
264
+ if (unlikely(PyArg_Parse(o, "s#", &result, length) < 0)) return NULL;
265
+ #else
266
+ result = PyUnicode_AsUTF8AndSize(o, length);
267
+ #endif
268
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
269
+ // Pre-checking "isascii" the Limited API involves making Python function calls.
270
+ // Therefore we do a post-check instead that the lengths of the encoded and unicode
271
+ // strings are the same (which is only true for ascii strings).
272
+ // If this isn't true then we've already done the encoding so it's a potential
273
+ // performance loss, but it should be better in the successful case.
274
+ unicode_length = PyUnicode_GetLength(o);
275
+ if (unlikely(unicode_length < 0)) return NULL;
276
+ if (unlikely(unicode_length != *length)) {
277
+ // raise the error
278
+ PyUnicode_AsASCIIString(o);
279
+ return NULL;
280
+ }
281
+ #endif
282
+ return result;
283
+ }
284
+ #else /* CYTHON_COMPILING_IN_LIMITED_API */
285
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
286
+ if (likely(PyUnicode_IS_ASCII(o))) {
287
+ // cached for the lifetime of the object
288
+ *length = PyUnicode_GET_LENGTH(o);
289
+ return PyUnicode_AsUTF8(o);
290
+ } else {
291
+ // raise the error
292
+ PyUnicode_AsASCIIString(o);
293
+ return NULL;
294
+ }
295
+ #else
296
+ return PyUnicode_AsUTF8AndSize(o, length);
297
+ #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
298
+ #endif /* !CYTHON_COMPILING_IN_LIMITED_API */
299
+ }
300
+ #endif
301
+
302
+ // Py3.7 returns a "const char*" for unicode strings
303
+ static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
304
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_UTF8
305
+ if (PyUnicode_Check(o)) {
306
+ return __Pyx_PyUnicode_AsStringAndSize(o, length);
307
+ } else
308
+ #endif
309
+
310
+ if (PyByteArray_Check(o)) {
311
+ #if (CYTHON_ASSUME_SAFE_SIZE && CYTHON_ASSUME_SAFE_MACROS) || (CYTHON_COMPILING_IN_PYPY && (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)))
312
+ *length = PyByteArray_GET_SIZE(o);
313
+ return PyByteArray_AS_STRING(o);
314
+ #else
315
+ *length = PyByteArray_Size(o);
316
+ if (*length == -1) return NULL;
317
+ return PyByteArray_AsString(o);
318
+ #endif
319
+
320
+ } else
321
+ {
322
+ char* result;
323
+ int r = PyBytes_AsStringAndSize(o, &result, length);
324
+ if (unlikely(r < 0)) {
325
+ return NULL;
326
+ } else {
327
+ return result;
328
+ }
329
+ }
330
+ }
331
+
332
+ /* Note: __Pyx_PyObject_IsTrue is written to minimize branching. */
333
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
334
+ int is_true = x == Py_True;
335
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
336
+ else return PyObject_IsTrue(x);
337
+ }
338
+
339
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
340
+ int retval;
341
+ if (unlikely(!x)) return -1;
342
+ retval = __Pyx_PyObject_IsTrue(x);
343
+ Py_DECREF(x);
344
+ return retval;
345
+ }
346
+
347
+ static PyObject* __Pyx_PyNumber_LongWrongResultType(PyObject* result) {
348
+ __Pyx_TypeName result_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(result));
349
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000
350
+ if (unlikely(!result_type_name)) goto bad;
351
+ #endif
352
+
353
+ if (PyLong_Check(result)) {
354
+ // CPython issue #17576: warn if 'result' not of exact type int.
355
+ if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
356
+ "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). "
357
+ "The ability to return an instance of a strict subclass of int is deprecated, "
358
+ "and may be removed in a future version of Python.",
359
+ result_type_name)) {
360
+ __Pyx_DECREF_TypeName(result_type_name);
361
+ goto bad;
362
+ }
363
+ __Pyx_DECREF_TypeName(result_type_name);
364
+ return result;
365
+ }
366
+
367
+ PyErr_Format(PyExc_TypeError,
368
+ "__int__ returned non-int (type " __Pyx_FMT_TYPENAME ")",
369
+ result_type_name);
370
+
371
+ __Pyx_DECREF_TypeName(result_type_name);
372
+
373
+ bad:
374
+ Py_DECREF(result);
375
+ return NULL;
376
+ }
377
+
378
+ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Long(PyObject* x) {
379
+ #if CYTHON_USE_TYPE_SLOTS
380
+ PyNumberMethods *m;
381
+ #endif
382
+ PyObject *res = NULL;
383
+ if (likely(PyLong_Check(x)))
384
+ return __Pyx_NewRef(x);
385
+ #if CYTHON_USE_TYPE_SLOTS
386
+ m = Py_TYPE(x)->tp_as_number;
387
+ if (likely(m && m->nb_int)) {
388
+ res = m->nb_int(x);
389
+ }
390
+ #else
391
+ if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
392
+ res = PyNumber_Long(x);
393
+ }
394
+ #endif
395
+ if (likely(res)) {
396
+ if (unlikely(!PyLong_CheckExact(res))) {
397
+ return __Pyx_PyNumber_LongWrongResultType(res);
398
+ }
399
+ }
400
+ else if (!PyErr_Occurred()) {
401
+ PyErr_SetString(PyExc_TypeError,
402
+ "an integer is required");
403
+ }
404
+ return res;
405
+ }
406
+
407
+ {{py: from Cython.Utility import pylong_join }}
408
+
409
+ static CYTHON_INLINE Py_ssize_t __Pyx_PyLong_AsSsize_t(PyObject* b) {
410
+ #if CYTHON_USE_PYLONG_INTERNALS
411
+ Py_ssize_t ival;
412
+ const Py_ssize_t size = __Pyx_PyLong_DigitCount(b);
413
+ const int is_neg = __Pyx_PyLong_IsNeg(b);
414
+ const digit* digits = __Pyx_PyLong_Digits(b);
415
+ if (size == 0) return 0;
416
+ {{for _size in (1, 2, 3, 4)}}
417
+ #if SIZEOF_SIZE_T * 8 > {{_size}} * PyLong_SHIFT
418
+ if (size == {{_size}}) {
419
+ ival = (Py_ssize_t) {{pylong_join(_size, 'digits', 'size_t')}};
420
+ } else
421
+ #endif
422
+ {{endfor}}
423
+ return PyLong_AsSsize_t(b);
424
+ return is_neg ? -ival : ival;
425
+
426
+ #else
427
+ return PyLong_AsSsize_t(b);
428
+ #endif
429
+ }
430
+
431
+ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
432
+ if (likely(PyLong_Check(b))) {
433
+ return __Pyx_PyLong_AsSsize_t(b);
434
+ } else {
435
+ Py_ssize_t ival;
436
+ PyObject *x = PyNumber_Index(b);
437
+ if (unlikely(!x)) return -1;
438
+ ival = __Pyx_PyLong_AsSsize_t(x);
439
+ Py_DECREF(x);
440
+ return ival;
441
+ }
442
+ }
443
+
444
+
445
+ static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
446
+ if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
447
+ return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
448
+ } else {
449
+ Py_ssize_t ival;
450
+ PyObject *x;
451
+ x = PyNumber_Index(o);
452
+ if (!x) return -1;
453
+ ival = PyLong_AsLong(x);
454
+ Py_DECREF(x);
455
+ return ival;
456
+ }
457
+ }
458
+
459
+ static CYTHON_INLINE PyObject *__Pyx_Owned_Py_None(int b) {
460
+ CYTHON_UNUSED_VAR(b);
461
+ return __Pyx_NewRef(Py_None);
462
+ }
463
+
464
+ static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
465
+ return __Pyx_NewRef(b ? Py_True: Py_False);
466
+ }
467
+
468
+
469
+ static CYTHON_INLINE PyObject * __Pyx_PyLong_FromSize_t(size_t ival) {
470
+ return PyLong_FromSize_t(ival);
471
+ }
472
+
473
+
474
+ /////////////// pybuiltin_invalid.export ///////////////
475
+ //@feature: DEFAULTS
476
+
477
+ static void __Pyx_PyBuiltin_Invalid(PyObject *obj, const char *builtin_type_name, const char *argname); /*proto*/
478
+
479
+ /////////////// pybuiltin_invalid ///////////////
480
+ //@requires: ObjectHandling.c::FormatTypeName
481
+
482
+ static void __Pyx_PyBuiltin_Invalid(PyObject *obj, const char *builtin_type_name, const char *argname) {
483
+ __Pyx_TypeName obj_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(obj));
484
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000
485
+ if (unlikely(!obj_type_name)) return;
486
+ #endif
487
+ if (argname) {
488
+ PyErr_Format(PyExc_TypeError,
489
+ "Argument '%.200s' has incorrect type (expected %.5s, got " __Pyx_FMT_TYPENAME ")",
490
+ argname, builtin_type_name, obj_type_name
491
+ );
492
+ } else {
493
+ PyErr_Format(PyExc_TypeError,
494
+ "Expected %.5s, got " __Pyx_FMT_TYPENAME,
495
+ builtin_type_name, obj_type_name
496
+ );
497
+ }
498
+ __Pyx_DECREF_TypeName(obj_type_name);
499
+ }
500
+
501
+
502
+ /////////////// pyfloat_simplify.proto ///////////////
503
+
504
+ static CYTHON_INLINE int __Pyx_PyFloat_FromNumber(PyObject **number_var, const char *argname, int accept_none); /*proto*/
505
+
506
+ /////////////// pyfloat_simplify ///////////////
507
+ //@requires: pybuiltin_invalid
508
+
509
+ static int __Pyx__PyFloat_FromNumber(PyObject **number_var, const char *argname); /*proto*/
510
+
511
+ static CYTHON_INLINE int __Pyx_PyFloat_FromNumber(PyObject **number_var, const char *argname, int accept_none) {
512
+ // Convert any float-compatible Python number object into a Python float.
513
+ // NOTE: This function decrefs 'number' if a conversion happens to replace the original object.
514
+ PyObject *number = *number_var;
515
+ if (likely((accept_none && number == Py_None) || PyFloat_CheckExact(number))) {
516
+ return 0;
517
+ }
518
+ return __Pyx__PyFloat_FromNumber(number_var, argname);
519
+ }
520
+
521
+ static int __Pyx__PyFloat_FromNumber(PyObject **number_var, const char *argname) {
522
+ PyObject *number = *number_var;
523
+ PyObject *float_object;
524
+ if (likely(PyLong_CheckExact(number))) {
525
+ double val;
526
+ #if CYTHON_USE_PYLONG_INTERNALS
527
+ if (likely(__Pyx_PyLong_IsCompact(number))) {
528
+ val = (double) __Pyx_PyLong_CompactValue(number);
529
+ } else
530
+ #endif
531
+ {
532
+ val = PyLong_AsDouble(number);
533
+ if (unlikely(val == -1.0 && PyErr_Occurred())) goto bad;
534
+ }
535
+ float_object = PyFloat_FromDouble(val);
536
+ }
537
+ else if (PyNumber_Check(number)) {
538
+ // PyNumber_Float() also parses strings, which we must reject.
539
+ float_object = PyNumber_Float(number);
540
+ } else {
541
+ __Pyx_PyBuiltin_Invalid(number, "float", argname);
542
+ goto bad;
543
+ }
544
+ if (unlikely(!float_object)) goto bad;
545
+
546
+ *number_var = float_object;
547
+ Py_DECREF(number);
548
+ return 0;
549
+
550
+ bad:
551
+ *number_var = NULL;
552
+ Py_DECREF(number);
553
+ return -1;
554
+ }
555
+
556
+
557
+ /////////////// pyint_simplify.proto ///////////////
558
+
559
+ static CYTHON_INLINE int __Pyx_PyInt_FromNumber(PyObject **number_var, const char *argname, int accept_none); /*proto*/
560
+
561
+ /////////////// pyint_simplify ///////////////
562
+ //@requires: pybuiltin_invalid
563
+
564
+ static int __Pyx__PyInt_FromNumber(PyObject **number_var, const char *argname); /*proto*/
565
+
566
+ static CYTHON_INLINE int __Pyx_PyInt_FromNumber(PyObject **number_var, const char *argname, int accept_none) {
567
+ // Convert any int-compatible Python number object into a Python int.
568
+ // NOTE: This function decrefs 'number' if a conversion happens to replace the original object.
569
+ PyObject *number = *number_var;
570
+ if (likely((accept_none && number == Py_None) || PyLong_CheckExact(number))) {
571
+ return 0;
572
+ }
573
+ return __Pyx__PyInt_FromNumber(number_var, argname);
574
+ }
575
+
576
+ static int __Pyx__PyInt_FromNumber(PyObject **number_var, const char *argname) {
577
+ PyObject *number = *number_var;
578
+ PyObject *int_object;
579
+ if (likely(PyNumber_Check(number))) {
580
+ // PyNumber_Long() also parses strings, which we must reject.
581
+ int_object = PyNumber_Long(number);
582
+ if (unlikely(!int_object)) goto bad;
583
+ } else {
584
+ __Pyx_PyBuiltin_Invalid(number, "int", argname);
585
+ goto bad;
586
+ }
587
+
588
+ *number_var = int_object;
589
+ Py_DECREF(number);
590
+ return 0;
591
+
592
+ bad:
593
+ *number_var = NULL;
594
+ Py_DECREF(number);
595
+ return -1;
596
+ }
597
+
598
+
599
+ /////////////// pynumber_float.proto ///////////////
600
+
601
+ static CYTHON_INLINE PyObject* __Pyx__PyNumber_Float(PyObject* obj); /* proto */
602
+ #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : __Pyx__PyNumber_Float(x))
603
+
604
+ /////////////// pynumber_float ///////////////
605
+ //@requires: Optimize.c::pybytes_as_double
606
+ //@requires: Optimize.c::pyunicode_as_double
607
+
608
+ static CYTHON_INLINE PyObject* __Pyx__PyNumber_Float(PyObject* obj) {
609
+ // 'obj is PyFloat' is handled in the calling macro
610
+ double val;
611
+ if (PyLong_CheckExact(obj)) {
612
+ #if CYTHON_USE_PYLONG_INTERNALS
613
+ if (likely(__Pyx_PyLong_IsCompact(obj))) {
614
+ val = (double) __Pyx_PyLong_CompactValue(obj);
615
+ goto no_error;
616
+ }
617
+ #endif
618
+ val = PyLong_AsDouble(obj);
619
+ } else if (PyUnicode_CheckExact(obj)) {
620
+ val = __Pyx_PyUnicode_AsDouble(obj);
621
+ } else if (PyBytes_CheckExact(obj)) {
622
+ val = __Pyx_PyBytes_AsDouble(obj);
623
+ } else if (PyByteArray_CheckExact(obj)) {
624
+ val = __Pyx_PyByteArray_AsDouble(obj);
625
+ } else {
626
+ return PyNumber_Float(obj);
627
+ }
628
+
629
+ if (unlikely(val == -1 && PyErr_Occurred())) {
630
+ return NULL;
631
+ }
632
+ #if CYTHON_USE_PYLONG_INTERNALS
633
+ no_error:
634
+ #endif
635
+ return PyFloat_FromDouble(val);
636
+ }
637
+
638
+ /////////////// GCCDiagnostics.proto ///////////////
639
+
640
+ // GCC diagnostic pragmas were introduced in GCC 4.6
641
+ // Used to silence conversion warnings that are ok but cannot be avoided.
642
+ #if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
643
+ #define __Pyx_HAS_GCC_DIAGNOSTIC
644
+ #endif
645
+
646
+
647
+ /////////////// ToPyCTupleUtility.proto ///////////////
648
+
649
+ static PyObject* {{funcname}}({{struct_type_decl}});
650
+
651
+ /////////////// ToPyCTupleUtility ///////////////
652
+
653
+ static PyObject* {{funcname}}({{struct_type_decl}} value) {
654
+ PyObject* items[{{size}}] = { {{ ', '.join('0'*size) }} };
655
+ PyObject* result = NULL;
656
+
657
+ {{for ix, component in enumerate(components):}}
658
+ {{py:attr = f"value.f{ix}" }}
659
+ items[{{ix}}] = {{component.to_py_function}}({{attr}});
660
+ if (unlikely(!items[{{ix}}])) goto bad;
661
+ {{endfor}}
662
+
663
+ result = PyTuple_New({{size}});
664
+ if (unlikely(!result)) goto bad;
665
+
666
+ for (Py_ssize_t i=0; i<{{ size }}; ++i) {
667
+ PyObject *item = items[i];
668
+ items[i] = NULL;
669
+ #if !CYTHON_ASSUME_SAFE_MACROS
670
+ // PyTuple_SetItem() always steals a reference.
671
+ if (unlikely(PyTuple_SetItem(result, i, item) < 0)) goto bad;
672
+ #else
673
+ PyTuple_SET_ITEM(result, i, item);
674
+ #endif
675
+ }
676
+
677
+ return result;
678
+
679
+ bad:
680
+ Py_XDECREF(result);
681
+ for (Py_ssize_t i={{ size-1 }}; i >= 0; --i) {
682
+ Py_XDECREF(items[i]);
683
+ }
684
+ return NULL;
685
+ }
686
+
687
+
688
+ /////////////// FromPyCTupleUtility.proto ///////////////
689
+ static CYTHON_INLINE {{struct_type_decl}} {{funcname}}(PyObject *);
690
+
691
+ /////////////// FromPyCTupleUtility ///////////////
692
+
693
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS
694
+ static void __Pyx_tuple_{{funcname}}(PyObject * o, {{struct_type_decl}} *result) {
695
+ {{for ix, component in enumerate(components):}}
696
+ {{py:attr = "result->f%s" % ix}}
697
+ {{attr}} = {{component.from_py_function}}(PyTuple_GET_ITEM(o, {{ix}}));
698
+ if ({{component.error_condition(attr)}}) goto bad;
699
+ {{endfor}}
700
+ return;
701
+ bad:
702
+ return;
703
+ }
704
+
705
+ static void __Pyx_list_{{funcname}}(PyObject * o, {{struct_type_decl}} *result) {
706
+ {{for ix, component in enumerate(components):}}
707
+ {{py:attr = "result->f%s" % ix}}
708
+ {{attr}} = {{component.from_py_function}}(PyList_GET_ITEM(o, {{ix}}));
709
+ if ({{component.error_condition(attr)}}) goto bad;
710
+ {{endfor}}
711
+ return;
712
+ bad:
713
+ return;
714
+ }
715
+ #endif
716
+
717
+ static void __Pyx_seq_{{funcname}}(PyObject * o, {{struct_type_decl}} *result) {
718
+ if (unlikely(!PySequence_Check(o))) {
719
+ __Pyx_TypeName o_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(o));
720
+ #if CYTHON_COMPILING_IN_LIMITED_API && __PYX_LIMITED_VERSION_HEX < 0x030d0000
721
+ if (unlikely(!o_type_name)) goto bad;
722
+ #endif
723
+ PyErr_Format(PyExc_TypeError,
724
+ "Expected a sequence of size %zd, got " __Pyx_FMT_TYPENAME, (Py_ssize_t) {{size}}, o_type_name);
725
+ __Pyx_DECREF_TypeName(o_type_name);
726
+ goto bad;
727
+ } else if (unlikely(PySequence_Length(o) != {{size}})) {
728
+ PyErr_Format(PyExc_TypeError,
729
+ "Expected a sequence of size %zd, got size %zd", (Py_ssize_t) {{size}}, PySequence_Length(o));
730
+ goto bad;
731
+ }
732
+
733
+ {
734
+ PyObject *item;
735
+ {{for ix, component in enumerate(components):}}
736
+ {{py:attr = "result->f%s" % ix}}
737
+ item = __Pyx_PySequence_ITEM(o, {{ix}}); if (unlikely(!item)) goto bad;
738
+ {{attr}} = {{component.from_py_function}}(item);
739
+ Py_DECREF(item);
740
+ if ({{component.error_condition(attr)}}) goto bad;
741
+ {{endfor}}
742
+ }
743
+ return;
744
+ bad:
745
+ return;
746
+ }
747
+
748
+ static CYTHON_INLINE {{struct_type_decl}} {{funcname}}(PyObject * o) {
749
+ {{struct_type_decl}} result;
750
+
751
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS
752
+ if (likely(PyTuple_Check(o) && PyTuple_GET_SIZE(o) == {{size}})) {
753
+ __Pyx_tuple_{{funcname}}(o, &result);
754
+ } else if (likely(PyList_Check(o) && PyList_GET_SIZE(o) == {{size}})) {
755
+ __Pyx_list_{{funcname}}(o, &result);
756
+ } else
757
+ #endif
758
+ {
759
+ __Pyx_seq_{{funcname}}(o, &result);
760
+ }
761
+
762
+ return result;
763
+ }
764
+
765
+
766
+ /////////////// UnicodeAsUCS4.proto ///////////////
767
+
768
+ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);
769
+
770
+ /////////////// UnicodeAsUCS4 ///////////////
771
+
772
+ static void __Pyx_PyUnicode_AsPy_UCS4_error(Py_ssize_t length) {
773
+ if (likely(length >= 0)) {
774
+ // "length == -1" indicates an error already.
775
+ PyErr_Format(PyExc_ValueError,
776
+ "only single character unicode strings can be converted to Py_UCS4, "
777
+ "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
778
+ }
779
+ }
780
+
781
+ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
782
+ Py_ssize_t length = __Pyx_PyUnicode_GET_LENGTH(x);
783
+ if (unlikely(length != 1)) {
784
+ __Pyx_PyUnicode_AsPy_UCS4_error(length);
785
+ return (Py_UCS4)-1;
786
+ }
787
+ return __Pyx_PyUnicode_READ_CHAR(x, 0);
788
+ }
789
+
790
+
791
+ /////////////// ObjectAsUCS4.proto ///////////////
792
+ //@requires: UnicodeAsUCS4
793
+
794
+ static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject*);
795
+
796
+ static CYTHON_INLINE Py_UCS4 __Pyx_PyObject_AsPy_UCS4(PyObject *x) {
797
+ return (likely(PyUnicode_Check(x)) ? __Pyx_PyUnicode_AsPy_UCS4(x) : __Pyx__PyObject_AsPy_UCS4(x));
798
+ }
799
+
800
+
801
+ /////////////// ObjectAsUCS4 ///////////////
802
+
803
+ static void __Pyx__PyObject_AsPy_UCS4_raise_error(long ival) {
804
+ if (ival < 0) {
805
+ if (!PyErr_Occurred())
806
+ PyErr_SetString(PyExc_OverflowError,
807
+ "cannot convert negative value to Py_UCS4");
808
+ } else {
809
+ PyErr_SetString(PyExc_OverflowError,
810
+ "value too large to convert to Py_UCS4");
811
+ }
812
+ }
813
+
814
+ static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject* x) {
815
+ long ival;
816
+ ival = __Pyx_PyLong_As_long(x);
817
+ if (unlikely(!__Pyx_is_valid_index(ival, 1114111 + 1))) {
818
+ __Pyx__PyObject_AsPy_UCS4_raise_error(ival);
819
+ return (Py_UCS4)-1;
820
+ }
821
+ return (Py_UCS4)ival;
822
+ }
823
+
824
+
825
+ /////////////// ObjectAsPyUnicode.proto ///////////////
826
+
827
+ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject*);
828
+
829
+ /////////////// ObjectAsPyUnicode ///////////////
830
+
831
+ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject* x) {
832
+ long ival;
833
+ #if defined(Py_UNICODE_SIZE) && Py_UNICODE_SIZE == 2
834
+ const long maxval = 65535;
835
+ #else
836
+ const long maxval = 1114111;
837
+ #endif
838
+ if (PyUnicode_Check(x)) {
839
+ Py_ssize_t length = __Pyx_PyUnicode_GET_LENGTH(x);
840
+ if (unlikely(length != 1)) {
841
+ // -1 indicates an error.
842
+ if (length >= 0) {
843
+ PyErr_Format(PyExc_ValueError,
844
+ "only single character unicode strings can be converted to Py_UNICODE, "
845
+ "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
846
+ }
847
+ return (Py_UNICODE)-1;
848
+ }
849
+ ival = PyUnicode_READ_CHAR(x, 0);
850
+ } else {
851
+ ival = __Pyx_PyLong_As_long(x);
852
+ }
853
+ if (unlikely(!__Pyx_is_valid_index(ival, maxval + 1))) {
854
+ if (ival < 0) {
855
+ if (!PyErr_Occurred())
856
+ PyErr_SetString(PyExc_OverflowError,
857
+ "cannot convert negative value to Py_UNICODE");
858
+ return (Py_UNICODE)-1;
859
+ } else {
860
+ PyErr_SetString(PyExc_OverflowError,
861
+ "value too large to convert to Py_UNICODE");
862
+ }
863
+ return (Py_UNICODE)-1;
864
+ }
865
+ return (Py_UNICODE)ival;
866
+ }
867
+
868
+
869
+ /////////////// CIntToPy.proto ///////////////
870
+
871
+ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value);
872
+
873
+ /////////////// CIntToPy ///////////////
874
+ //@requires: GCCDiagnostics
875
+ //@requires: ObjectHandling.c::PyObjectVectorcallMethodKwds
876
+
877
+ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
878
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
879
+ #pragma GCC diagnostic push
880
+ #pragma GCC diagnostic ignored "-Wconversion"
881
+ #endif
882
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
883
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
884
+ #pragma GCC diagnostic pop
885
+ #endif
886
+ const int is_unsigned = neg_one > const_zero;
887
+ if (is_unsigned) {
888
+ if (sizeof({{TYPE}}) < sizeof(long)) {
889
+ return PyLong_FromLong((long) value);
890
+ } else if (sizeof({{TYPE}}) <= sizeof(unsigned long)) {
891
+ return PyLong_FromUnsignedLong((unsigned long) value);
892
+ #if !CYTHON_COMPILING_IN_PYPY
893
+ // PyLong_FromUnsignedLongLong() does not necessarily accept ULL arguments in PyPy.
894
+ // See https://github.com/cython/cython/issues/6890
895
+ } else if (sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG)) {
896
+ return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
897
+ #endif
898
+ }
899
+ } else {
900
+ if (sizeof({{TYPE}}) <= sizeof(long)) {
901
+ return PyLong_FromLong((long) value);
902
+ } else if (sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG)) {
903
+ return PyLong_FromLongLong((PY_LONG_LONG) value);
904
+ }
905
+ }
906
+ {
907
+ unsigned char *bytes = (unsigned char *)&value;
908
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
909
+ if (is_unsigned) {
910
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
911
+ } else {
912
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
913
+ }
914
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
915
+ int one = 1; int little = (int)*(unsigned char *)&one;
916
+ return _PyLong_FromByteArray(bytes, sizeof({{TYPE}}),
917
+ little, !is_unsigned);
918
+ #else
919
+ // call int.from_bytes()
920
+ int one = 1; int little = (int)*(unsigned char *)&one;
921
+ PyObject *result = NULL, *kwds = NULL;
922
+ PyObject *py_bytes = NULL, *order_str = NULL, *from_bytes_str = NULL;;
923
+ py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof({{TYPE}}));
924
+ if (!py_bytes) goto limited_bad;
925
+ // I'm deliberately not using PYIDENT here because this code path is very unlikely
926
+ // to ever run so it seems a pessimization mostly.
927
+ from_bytes_str = PyUnicode_FromStringAndSize("from_bytes", 10);
928
+ if (!from_bytes_str) goto limited_bad;
929
+ order_str = PyUnicode_FromString(little ? "little" : "big");
930
+ if (!order_str) goto limited_bad;
931
+ {
932
+ PyObject *args[] = { (PyObject*)&PyLong_Type, py_bytes, order_str, Py_True };
933
+ if (!is_unsigned) {
934
+ PyObject *signed_str = PyUnicode_FromStringAndSize("signed", 6);
935
+ if (!signed_str) goto limited_bad;
936
+ #if CYTHON_VECTORCALL
937
+ kwds = PyTuple_Pack(1, signed_str);
938
+ #else
939
+ {
940
+ PyObject *keys[] = {signed_str};
941
+ PyObject *values[] = {Py_True};
942
+ kwds = __Pyx_MakeKwargDict(keys, values, 1);
943
+ }
944
+ #endif
945
+ Py_DECREF(signed_str);
946
+ if (unlikely(!kwds)) goto limited_bad;
947
+ }
948
+ result = __Pyx_Object_VectorcallMethodKwds(from_bytes_str, args, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, kwds);
949
+ }
950
+
951
+ limited_bad:
952
+ Py_XDECREF(kwds);
953
+ Py_XDECREF(order_str);
954
+ Py_XDECREF(py_bytes);
955
+ Py_XDECREF(from_bytes_str);
956
+ return result;
957
+ #endif
958
+ }
959
+ }
960
+
961
+
962
+ /////////////// COrdinalToPyUnicode.proto ///////////////
963
+
964
+ static CYTHON_INLINE int __Pyx_CheckUnicodeValue(int value);
965
+ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromOrdinal_Padded(int value, Py_ssize_t width, char padding_char);
966
+
967
+ /////////////// COrdinalToPyUnicode ///////////////
968
+ //@requires: StringTools.c::BuildPyUnicode
969
+
970
+ static CYTHON_INLINE int __Pyx_CheckUnicodeValue(int value) {
971
+ return value <= 1114111;
972
+ }
973
+
974
+ static PyObject* __Pyx_PyUnicode_FromOrdinal_Padded(int value, Py_ssize_t ulength, char padding_char) {
975
+ Py_ssize_t padding_length = ulength - 1;
976
+ if (likely((padding_length <= 250) && (value < 0xD800 || value > 0xDFFF))) {
977
+ // Encode to UTF-8 / Latin1 buffer, then decode.
978
+ char chars[256];
979
+
980
+ if (value <= 255) {
981
+ // Simple Latin1 result, fast to decode.
982
+ memset(chars, padding_char, (size_t) padding_length);
983
+ chars[ulength-1] = (char) value;
984
+ return PyUnicode_DecodeLatin1(chars, ulength, NULL);
985
+ }
986
+
987
+ char *cpos = chars + sizeof(chars);
988
+ if (value < 0x800) {
989
+ *--cpos = (char) (0x80 | (value & 0x3f));
990
+ value >>= 6;
991
+ *--cpos = (char) (0xc0 | (value & 0x1f));
992
+ } else if (value < 0x10000) {
993
+ *--cpos = (char) (0x80 | (value & 0x3f));
994
+ value >>= 6;
995
+ *--cpos = (char) (0x80 | (value & 0x3f));
996
+ value >>= 6;
997
+ *--cpos = (char) (0xe0 | (value & 0x0f));
998
+ } else {
999
+ *--cpos = (char) (0x80 | (value & 0x3f));
1000
+ value >>= 6;
1001
+ *--cpos = (char) (0x80 | (value & 0x3f));
1002
+ value >>= 6;
1003
+ *--cpos = (char) (0x80 | (value & 0x3f));
1004
+ value >>= 6;
1005
+ *--cpos = (char) (0xf0 | (value & 0x07));
1006
+ }
1007
+ cpos -= padding_length;
1008
+ memset(cpos, padding_char, (size_t) padding_length);
1009
+ return PyUnicode_DecodeUTF8(cpos, chars + sizeof(chars) - cpos, NULL);
1010
+ }
1011
+
1012
+ if (value <= 127 && CYTHON_USE_UNICODE_INTERNALS) {
1013
+ const char chars[1] = {(char) value};
1014
+ return __Pyx_PyUnicode_BuildFromAscii(ulength, chars, 1, 0, padding_char);
1015
+ }
1016
+
1017
+ {
1018
+ PyObject *uchar, *padding_uchar, *padding, *result;
1019
+
1020
+ padding_uchar = PyUnicode_FromOrdinal(padding_char);
1021
+ if (unlikely(!padding_uchar)) return NULL;
1022
+ padding = PySequence_Repeat(padding_uchar, padding_length);
1023
+ Py_DECREF(padding_uchar);
1024
+ if (unlikely(!padding)) return NULL;
1025
+
1026
+ uchar = PyUnicode_FromOrdinal(value);
1027
+ if (unlikely(!uchar)) {
1028
+ Py_DECREF(padding);
1029
+ return NULL;
1030
+ }
1031
+
1032
+ result = PyUnicode_Concat(padding, uchar);
1033
+ Py_DECREF(padding);
1034
+ Py_DECREF(uchar);
1035
+ return result;
1036
+ }
1037
+ }
1038
+
1039
+
1040
+ /////////////// CIntToDigits ///////////////
1041
+
1042
+ static const char DIGIT_PAIRS_10[2*10*10+1] = {
1043
+ "00010203040506070809"
1044
+ "10111213141516171819"
1045
+ "20212223242526272829"
1046
+ "30313233343536373839"
1047
+ "40414243444546474849"
1048
+ "50515253545556575859"
1049
+ "60616263646566676869"
1050
+ "70717273747576777879"
1051
+ "80818283848586878889"
1052
+ "90919293949596979899"
1053
+ };
1054
+
1055
+ static const char DIGIT_PAIRS_8[2*8*8+1] = {
1056
+ "0001020304050607"
1057
+ "1011121314151617"
1058
+ "2021222324252627"
1059
+ "3031323334353637"
1060
+ "4041424344454647"
1061
+ "5051525354555657"
1062
+ "6061626364656667"
1063
+ "7071727374757677"
1064
+ };
1065
+
1066
+ static const char DIGITS_HEX[2*16+1] = {
1067
+ "0123456789abcdef"
1068
+ "0123456789ABCDEF"
1069
+ };
1070
+
1071
+
1072
+ /////////////// CIntToPyUnicode.proto ///////////////
1073
+
1074
+ #define {{TO_PY_FUNCTION}}(value, width, padding_char, format_char) ( \
1075
+ ((format_char) == ('c')) ? \
1076
+ __Pyx_uchar_{{TO_PY_FUNCTION}}(value, width, padding_char) : \
1077
+ __Pyx__{{TO_PY_FUNCTION}}(value, width, padding_char, format_char) \
1078
+ )
1079
+ static CYTHON_INLINE PyObject* __Pyx_uchar_{{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char);
1080
+ static CYTHON_INLINE PyObject* __Pyx__{{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char, char format_char);
1081
+
1082
+ /////////////// CIntToPyUnicode ///////////////
1083
+ //@requires: StringTools.c::IncludeStringH
1084
+ //@requires: StringTools.c::BuildPyUnicode
1085
+ //@requires: ModuleSetupCode.c::IncludeStdlibH
1086
+ //@requires: COrdinalToPyUnicode
1087
+ //@requires: CIntToDigits
1088
+ //@requires: GCCDiagnostics
1089
+
1090
+ // NOTE: inlining because most arguments are constant, which collapses lots of code below
1091
+
1092
+ static CYTHON_INLINE PyObject* __Pyx_uchar_{{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char) {
1093
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1094
+ #pragma GCC diagnostic push
1095
+ #pragma GCC diagnostic ignored "-Wconversion"
1096
+ #endif
1097
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
1098
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1099
+ #pragma GCC diagnostic pop
1100
+ #endif
1101
+ const int is_unsigned = neg_one > const_zero;
1102
+
1103
+ // This check is just an awful variation on "(0 <= value <= 1114111)",
1104
+ // but without C compiler complaints about compile time constant conditions depending on the signed/unsigned TYPE.
1105
+ if (unlikely(!(is_unsigned || value == 0 || value > 0) ||
1106
+ !(sizeof(value) <= 2 || value & ~ ({{TYPE}}) 0x01fffff || __Pyx_CheckUnicodeValue((int) value)))) {
1107
+ // PyUnicode_FromOrdinal() and chr() raise ValueError, f-strings raise OverflowError. :-/
1108
+ PyErr_SetString(PyExc_OverflowError, "%c arg not in range(0x110000)");
1109
+ return NULL;
1110
+ }
1111
+ if (width <= 1) {
1112
+ return PyUnicode_FromOrdinal((int) value);
1113
+ }
1114
+ return __Pyx_PyUnicode_FromOrdinal_Padded((int) value, width, padding_char);
1115
+ }
1116
+
1117
+ static CYTHON_INLINE PyObject* __Pyx__{{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char, char format_char) {
1118
+ // simple and conservative C string allocation on the stack: each byte gives at most 3 digits, plus sign
1119
+ char digits[sizeof({{TYPE}})*3+2];
1120
+ // 'dpos' points to end of digits array + 1 initially to allow for pre-decrement looping
1121
+ char *dpos, *end = digits + sizeof({{TYPE}})*3+2;
1122
+ const char *hex_digits = DIGITS_HEX;
1123
+ Py_ssize_t length, ulength;
1124
+ int prepend_sign, last_one_off;
1125
+ {{TYPE}} remaining;
1126
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1127
+ #pragma GCC diagnostic push
1128
+ #pragma GCC diagnostic ignored "-Wconversion"
1129
+ #endif
1130
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
1131
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1132
+ #pragma GCC diagnostic pop
1133
+ #endif
1134
+ const int is_unsigned = neg_one > const_zero;
1135
+
1136
+ if (format_char == 'X') {
1137
+ hex_digits += 16;
1138
+ format_char = 'x';
1139
+ }
1140
+
1141
+ // surprise: even trivial sprintf() calls don't get optimised in gcc (4.8)
1142
+ remaining = value; /* not using abs(value) to avoid overflow problems */
1143
+ last_one_off = 0;
1144
+ dpos = end;
1145
+ do {
1146
+ int digit_pos;
1147
+ switch (format_char) {
1148
+ case 'o':
1149
+ digit_pos = abs((int)(remaining % (8*8)));
1150
+ remaining = ({{TYPE}}) (remaining / (8*8));
1151
+ dpos -= 2;
1152
+ memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2); /* copy 2 digits at a time, unaligned */
1153
+ last_one_off = (digit_pos < 8);
1154
+ break;
1155
+ case 'd':
1156
+ digit_pos = abs((int)(remaining % (10*10)));
1157
+ remaining = ({{TYPE}}) (remaining / (10*10));
1158
+ dpos -= 2;
1159
+ memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2); /* copy 2 digits at a time, unaligned */
1160
+ last_one_off = (digit_pos < 10);
1161
+ break;
1162
+ case 'x':
1163
+ *(--dpos) = hex_digits[abs((int)(remaining % 16))];
1164
+ remaining = ({{TYPE}}) (remaining / 16);
1165
+ break;
1166
+ default:
1167
+ assert(0);
1168
+ break;
1169
+ }
1170
+ } while (unlikely(remaining != 0));
1171
+
1172
+ // Correct dpos by 1 if we read an excess digit.
1173
+ assert(!last_one_off || *dpos == '0');
1174
+ dpos += last_one_off;
1175
+
1176
+ length = end - dpos;
1177
+ ulength = length;
1178
+ prepend_sign = 0;
1179
+ if (!is_unsigned && value <= neg_one) {
1180
+ if (padding_char == ' ' || width <= length + 1) {
1181
+ *(--dpos) = '-';
1182
+ ++length;
1183
+ } else {
1184
+ prepend_sign = 1;
1185
+ }
1186
+ ++ulength;
1187
+ }
1188
+ if (width > ulength) {
1189
+ ulength = width;
1190
+ }
1191
+ // single character unicode strings are cached in CPython => use PyUnicode_FromOrdinal() for them
1192
+ if (ulength == 1) {
1193
+ return PyUnicode_FromOrdinal(*dpos);
1194
+ }
1195
+ return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
1196
+ }
1197
+
1198
+
1199
+ /////////////// CDoubleToPyUnicode.proto ///////////////
1200
+
1201
+ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromDouble(double value, char format_char, int precision);
1202
+
1203
+ /////////////// CDoubleToPyUnicode ///////////////
1204
+
1205
+ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromDouble(double value, char format_char, int precision) {
1206
+ PyObject *result;
1207
+ // only repr() ('r') appends a trailing ".0" to integral values
1208
+ const int flags = (format_char == 'r') ? Py_DTSF_ADD_DOT_0 : 0;
1209
+ char *buffer = PyOS_double_to_string(value, format_char, precision, flags, NULL);
1210
+ if (unlikely(!buffer)) return NULL;
1211
+ result = PyUnicode_FromString(buffer);
1212
+ PyMem_Free(buffer);
1213
+ return result;
1214
+ }
1215
+
1216
+
1217
+ /////////////// CBIntToPyUnicode.proto ///////////////
1218
+
1219
+ #define {{TO_PY_FUNCTION}}(value) \
1220
+ ((value) ? __Pyx_NewRef({{TRUE_CONST}}) : __Pyx_NewRef({{FALSE_CONST}}))
1221
+
1222
+
1223
+ /////////////// CIntFromPyVerify ///////////////
1224
+
1225
+ // see CIntFromPy
1226
+ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value) \
1227
+ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
1228
+
1229
+ #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value) \
1230
+ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
1231
+
1232
+ #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc) \
1233
+ { \
1234
+ func_type value = func_value; \
1235
+ if (sizeof(target_type) < sizeof(func_type)) { \
1236
+ if (unlikely(value != (func_type) (target_type) value)) { \
1237
+ func_type zero = 0; \
1238
+ if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred())) \
1239
+ return (target_type) -1; \
1240
+ if (is_unsigned && unlikely(value < zero)) \
1241
+ goto raise_neg_overflow; \
1242
+ else \
1243
+ goto raise_overflow; \
1244
+ } \
1245
+ } \
1246
+ return (target_type) value; \
1247
+ }
1248
+
1249
+
1250
+ /////////////// CIntFromPy.proto ///////////////
1251
+
1252
+ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *);
1253
+
1254
+ /////////////// CIntFromPy ///////////////
1255
+ //@requires: CIntFromPyVerify
1256
+ //@requires: GCCDiagnostics
1257
+
1258
+ {{py: from Cython.Utility import pylong_join }}
1259
+
1260
+ static {{TYPE}} __Pyx_LargePyLong_{{FROM_PY_FUNCTION}}(PyObject *x); /*proto*/
1261
+
1262
+ static {{TYPE}} __Pyx_raise_neg_overflow_{{FROM_PY_FUNCTION}}(void) {
1263
+ {{if len(TYPE) <= 200}}
1264
+ const char* type_name = "{{TYPE}}";
1265
+ PyErr_Format(PyExc_OverflowError,
1266
+ "can't convert negative value to %.200s", type_name);
1267
+ {{else}}
1268
+ PyErr_SetString(PyExc_OverflowError,
1269
+ "can't convert negative value to {{TYPE}}");
1270
+ {{endif}}
1271
+ return ({{TYPE}}) -1;
1272
+ }
1273
+
1274
+ static {{TYPE}} __Pyx_raise_overflow_{{FROM_PY_FUNCTION}}(void) {
1275
+ {{if len(TYPE) <= 200}}
1276
+ const char* type_name = "{{TYPE}}";
1277
+ PyErr_Format(PyExc_OverflowError,
1278
+ "value too large to convert to %.200s", type_name);
1279
+ {{else}}
1280
+ PyErr_SetString(PyExc_OverflowError,
1281
+ "value too large to convert to {{TYPE}}");
1282
+ {{endif}}
1283
+ return ({{TYPE}}) -1;
1284
+ }
1285
+
1286
+ static CYTHON_INLINE {{TYPE}} __Pyx_PyULong_{{FROM_PY_FUNCTION}}(PyObject *x) {
1287
+ const int is_unsigned = 1;
1288
+ #if CYTHON_USE_PYLONG_INTERNALS
1289
+ // IsNeg() and IsCompact() were already checked in "__Pyx_PyLong_...()",
1290
+ // so 'x' is positive and at least two digits.
1291
+ {
1292
+ const digit* digits = __Pyx_PyLong_Digits(x);
1293
+ const Py_ssize_t size = __Pyx_PyLong_DigitCount(x);
1294
+ {{for _size in (2, 3, 4)}}
1295
+ if (size == {{_size}} && (8 * sizeof({{TYPE}}) > {{_size-1}} * PyLong_SHIFT)) {
1296
+ if ((8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT)) {
1297
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, unsigned long, {{pylong_join(_size, 'digits')}})
1298
+ } else if ((8 * sizeof({{TYPE}}) >= {{_size}} * PyLong_SHIFT)) {
1299
+ return ({{TYPE}}) {{pylong_join(_size, 'digits', TYPE)}};
1300
+ }
1301
+ } else
1302
+ {{endfor}}
1303
+ {}
1304
+ }
1305
+ #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
1306
+ if (unlikely(Py_SIZE(x) < 0)) {
1307
+ goto raise_neg_overflow;
1308
+ }
1309
+ #else
1310
+ {
1311
+ // misuse Py_False as a quick way to compare to a '0' int object in PyPy
1312
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
1313
+ if (unlikely(result < 0))
1314
+ return ({{TYPE}}) -1;
1315
+ if (unlikely(result == 1))
1316
+ goto raise_neg_overflow;
1317
+ }
1318
+ #endif
1319
+ if ((sizeof({{TYPE}}) <= sizeof(unsigned long))) {
1320
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned long, PyLong_AsUnsignedLong(x))
1321
+ } else if ((sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG))) {
1322
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
1323
+ }
1324
+
1325
+ return __Pyx_LargePyLong_{{FROM_PY_FUNCTION}}(x);
1326
+
1327
+ raise_neg_overflow:
1328
+ return __Pyx_raise_neg_overflow_{{FROM_PY_FUNCTION}}();
1329
+
1330
+ raise_overflow:
1331
+ return __Pyx_raise_overflow_{{FROM_PY_FUNCTION}}();
1332
+ }
1333
+
1334
+ static CYTHON_INLINE {{TYPE}} __Pyx_PySLong_{{FROM_PY_FUNCTION}}(PyObject *x) {
1335
+ const int is_unsigned = 0;
1336
+ #if CYTHON_USE_PYLONG_INTERNALS
1337
+ // IsCompact() was already checked in "__Pyx_PyLong_...()",
1338
+ // so 'x' is non-zero and at least two digits.
1339
+ if (__Pyx_PyLong_IsNeg(x)) {
1340
+ const Py_ssize_t size = __Pyx_PyLong_DigitCount(x);
1341
+ const digit* digits = __Pyx_PyLong_Digits(x);
1342
+ {{for _size in (2, 3, 4)}}
1343
+ if (size == {{_size}} && (8 * sizeof({{TYPE}}) > {{_size-1}} * PyLong_SHIFT)) {
1344
+ if ((8 * sizeof(long) > {{_size}} * PyLong_SHIFT)) {
1345
+ long ival = - (long) {{pylong_join(_size, 'digits')}};
1346
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, long, ival)
1347
+ } else if ((8 * sizeof({{TYPE}}) - 1 > {{_size}} * PyLong_SHIFT)) {
1348
+ return ({{TYPE}}) ((({{TYPE}}) -1) * {{pylong_join(_size, 'digits', TYPE)}});
1349
+ }
1350
+ } else
1351
+ {{endfor}}
1352
+ {}
1353
+ } else {
1354
+ const Py_ssize_t size = __Pyx_PyLong_DigitCount(x);
1355
+ const digit* digits = __Pyx_PyLong_Digits(x);
1356
+ {{for _size in (2, 3, 4)}}
1357
+ if (size == {{_size}} && (8 * sizeof({{TYPE}}) > {{_size-1}} * PyLong_SHIFT)) {
1358
+ if ((8 * sizeof(long) > {{_size}} * PyLong_SHIFT)) {
1359
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, unsigned long, {{pylong_join(_size, 'digits')}})
1360
+ } else if ((8 * sizeof({{TYPE}}) - 1 > {{_size}} * PyLong_SHIFT)) {
1361
+ return ({{TYPE}}) {{pylong_join(_size, 'digits', TYPE)}};
1362
+ }
1363
+ } else
1364
+ {{endfor}}
1365
+ {}
1366
+ }
1367
+ #endif
1368
+
1369
+ #if __PYX_LIMITED_VERSION_HEX >= 0x030d0000
1370
+ if ((sizeof({{TYPE}}) <= sizeof(int)) && (sizeof(int) < sizeof(long))) {
1371
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, int, PyLong_AsInt(x))
1372
+ } else
1373
+ #endif
1374
+ if ((sizeof({{TYPE}}) <= sizeof(long))) {
1375
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, long, PyLong_AsLong(x))
1376
+ } else if ((sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG))) {
1377
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, PY_LONG_LONG, PyLong_AsLongLong(x))
1378
+ }
1379
+
1380
+ return __Pyx_LargePyLong_{{FROM_PY_FUNCTION}}(x);
1381
+
1382
+ raise_neg_overflow:
1383
+ return __Pyx_raise_neg_overflow_{{FROM_PY_FUNCTION}}();
1384
+
1385
+ raise_overflow:
1386
+ return __Pyx_raise_overflow_{{FROM_PY_FUNCTION}}();
1387
+ }
1388
+
1389
+ static {{TYPE}} __Pyx_LargePyLong_{{FROM_PY_FUNCTION}}(PyObject *x) {
1390
+ // large integer type and no access to PyLong internals => allow for a more expensive conversion
1391
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1392
+ #pragma GCC diagnostic push
1393
+ #pragma GCC diagnostic ignored "-Wconversion"
1394
+ #endif
1395
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
1396
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1397
+ #pragma GCC diagnostic pop
1398
+ #endif
1399
+ const int is_unsigned = neg_one > const_zero;
1400
+
1401
+ {{TYPE}} val;
1402
+ int ret = -1;
1403
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
1404
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
1405
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
1406
+ if (unlikely(bytes_copied == -1)) {
1407
+ // failed
1408
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
1409
+ goto raise_overflow;
1410
+ } else {
1411
+ ret = 0;
1412
+ }
1413
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
1414
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
1415
+ unsigned char *bytes = (unsigned char *)&val;
1416
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
1417
+ bytes, sizeof(val),
1418
+ is_little, !is_unsigned);
1419
+ // Avoid unused label warning.
1420
+ if ((0)) goto raise_overflow;
1421
+ #else
1422
+ {{if IS_ENUM}}
1423
+ // The fallback implementation uses math operations like shifting, which do not work well with enums.
1424
+ PyErr_SetString(PyExc_RuntimeError,
1425
+ "_PyLong_AsByteArray() or PyLong_AsNativeBytes() not available, cannot convert large enums");
1426
+ val = ({{TYPE}}) -1;
1427
+ // Avoid unused label warning.
1428
+ if ((0)) goto raise_overflow;
1429
+ {{else}}
1430
+ // Inefficient copy of bit chunks through the C-API. Probably still better than a "cannot do this" exception.
1431
+ // This is substantially faster in CPython (>30%) than calling "int.to_bytes()" through the C-API.
1432
+ PyObject *v;
1433
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
1434
+ int bits, remaining_bits, is_negative = 0;
1435
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
1436
+
1437
+ // Use exact PyLong to prevent user defined &&/<</etc. implementations.
1438
+ if (likely(PyLong_CheckExact(x))) {
1439
+ v = __Pyx_NewRef(x);
1440
+ } else {
1441
+ v = PyNumber_Long(x);
1442
+ if (unlikely(!v)) return ({{TYPE}}) -1;
1443
+ assert(PyLong_CheckExact(v));
1444
+ }
1445
+
1446
+ // Misuse Py_False as a quick way to compare to a '0' int object.
1447
+ {
1448
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
1449
+ if (unlikely(result < 0)) {
1450
+ Py_DECREF(v);
1451
+ return ({{TYPE}}) -1;
1452
+ }
1453
+ is_negative = result == 1;
1454
+ }
1455
+
1456
+ if (is_unsigned && unlikely(is_negative)) {
1457
+ Py_DECREF(v);
1458
+ PyErr_SetString(PyExc_OverflowError,
1459
+ "can't convert negative value to {{TYPE}}");
1460
+ return ({{TYPE}}) -1;
1461
+ } else if (is_negative) {
1462
+ // bit-invert to make sure we can safely convert it
1463
+ stepval = PyNumber_Invert(v);
1464
+ Py_DECREF(v);
1465
+ if (unlikely(!stepval))
1466
+ return ({{TYPE}}) -1;
1467
+ } else {
1468
+ stepval = v;
1469
+ }
1470
+ v = NULL;
1471
+
1472
+ // Unpack full chunks of bits.
1473
+ val = ({{TYPE}}) 0;
1474
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
1475
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
1476
+ for (bits = 0; bits < (int) sizeof({{TYPE}}) * 8 - chunk_size; bits += chunk_size) {
1477
+ PyObject *tmp, *digit;
1478
+ long idigit;
1479
+
1480
+ digit = PyNumber_And(stepval, mask);
1481
+ if (unlikely(!digit)) goto done;
1482
+
1483
+ idigit = PyLong_AsLong(digit);
1484
+ Py_DECREF(digit);
1485
+ if (unlikely(idigit < 0)) goto done;
1486
+ val |= (({{TYPE}}) idigit) << bits;
1487
+
1488
+ tmp = PyNumber_Rshift(stepval, shift);
1489
+ if (unlikely(!tmp)) goto done;
1490
+ Py_DECREF(stepval); stepval = tmp;
1491
+ }
1492
+
1493
+ Py_DECREF(shift); shift = NULL;
1494
+ Py_DECREF(mask); mask = NULL;
1495
+
1496
+ // Add the last bits and detect overflow.
1497
+ {
1498
+ long idigit = PyLong_AsLong(stepval);
1499
+ if (unlikely(idigit < 0)) goto done;
1500
+ remaining_bits = ((int) sizeof({{TYPE}}) * 8) - bits - (is_unsigned ? 0 : 1);
1501
+ if (unlikely(idigit >= (1L << remaining_bits)))
1502
+ goto raise_overflow;
1503
+ val |= (({{TYPE}}) idigit) << bits;
1504
+ }
1505
+
1506
+ // Handle sign and overflow into sign bit.
1507
+ if (!is_unsigned) {
1508
+ // gcc warns about unsigned (val < 0) => test sign bit instead
1509
+ if (unlikely(val & ((({{TYPE}}) 1) << (sizeof({{TYPE}}) * 8 - 1))))
1510
+ goto raise_overflow;
1511
+ // undo the PyNumber_Invert() above
1512
+ if (is_negative)
1513
+ val = ~val;
1514
+ }
1515
+ ret = 0;
1516
+ done:
1517
+ Py_XDECREF(shift);
1518
+ Py_XDECREF(mask);
1519
+ Py_XDECREF(stepval);
1520
+ {{endif}}
1521
+ #endif
1522
+ if (unlikely(ret))
1523
+ return ({{TYPE}}) -1;
1524
+ return val;
1525
+
1526
+ raise_overflow:
1527
+ return __Pyx_raise_overflow_{{FROM_PY_FUNCTION}}();
1528
+ }
1529
+
1530
+ static CYTHON_INLINE {{TYPE}} __Pyx_PyLong_{{FROM_PY_FUNCTION}}(PyObject *x) {
1531
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1532
+ #pragma GCC diagnostic push
1533
+ #pragma GCC diagnostic ignored "-Wconversion"
1534
+ #endif
1535
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
1536
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1537
+ #pragma GCC diagnostic pop
1538
+ #endif
1539
+ const int is_unsigned = neg_one > const_zero;
1540
+
1541
+ if (is_unsigned) {
1542
+ #if CYTHON_USE_PYLONG_INTERNALS
1543
+ // IsNeg() check is required here and not done later!
1544
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
1545
+ goto raise_neg_overflow;
1546
+ } else if (__Pyx_PyLong_IsCompact(x)) {
1547
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
1548
+ } else
1549
+ #endif
1550
+ {
1551
+ return __Pyx_PyULong_{{FROM_PY_FUNCTION}}(x);
1552
+ }
1553
+ } else {
1554
+ #if CYTHON_USE_PYLONG_INTERNALS
1555
+ if (__Pyx_PyLong_IsCompact(x)) {
1556
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
1557
+ } else
1558
+ #endif
1559
+ {
1560
+ return __Pyx_PySLong_{{FROM_PY_FUNCTION}}(x);
1561
+ }
1562
+ }
1563
+
1564
+ #if CYTHON_USE_PYLONG_INTERNALS
1565
+ raise_neg_overflow:
1566
+ return __Pyx_raise_neg_overflow_{{FROM_PY_FUNCTION}}();
1567
+
1568
+ raise_overflow:
1569
+ return __Pyx_raise_overflow_{{FROM_PY_FUNCTION}}();
1570
+ #endif
1571
+ }
1572
+
1573
+ static {{TYPE}} __Pyx_NonPyLong_{{FROM_PY_FUNCTION}}(PyObject *x) {
1574
+ {{TYPE}} val;
1575
+ PyObject *tmp = __Pyx_PyNumber_Long(x);
1576
+ if (!tmp) return ({{TYPE}}) -1;
1577
+ val = {{FROM_PY_FUNCTION}}(tmp);
1578
+ Py_DECREF(tmp);
1579
+ return val;
1580
+ }
1581
+
1582
+ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
1583
+ if (likely(PyLong_Check(x))) {
1584
+ return __Pyx_PyLong_{{FROM_PY_FUNCTION}}(x);
1585
+ } else {
1586
+ return __Pyx_NonPyLong_{{FROM_PY_FUNCTION}}(x);
1587
+ }
1588
+ }