Cython 3.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. Cython/Build/BuildExecutable.py +169 -0
  2. Cython/Build/Cache.py +199 -0
  3. Cython/Build/Cythonize.py +250 -0
  4. Cython/Build/Dependencies.py +1275 -0
  5. Cython/Build/Distutils.py +1 -0
  6. Cython/Build/Inline.py +342 -0
  7. Cython/Build/IpythonMagic.py +560 -0
  8. Cython/Build/Tests/TestCyCache.py +119 -0
  9. Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
  10. Cython/Build/Tests/TestDependencies.py +133 -0
  11. Cython/Build/Tests/TestInline.py +112 -0
  12. Cython/Build/Tests/TestIpythonMagic.py +287 -0
  13. Cython/Build/Tests/TestRecythonize.py +212 -0
  14. Cython/Build/Tests/TestStripLiterals.py +155 -0
  15. Cython/Build/Tests/__init__.py +1 -0
  16. Cython/Build/__init__.py +8 -0
  17. Cython/CodeWriter.py +811 -0
  18. Cython/Compiler/AnalysedTreeTransforms.py +97 -0
  19. Cython/Compiler/Annotate.py +326 -0
  20. Cython/Compiler/AutoDocTransforms.py +314 -0
  21. Cython/Compiler/Buffer.py +680 -0
  22. Cython/Compiler/Builtin.py +862 -0
  23. Cython/Compiler/CmdLine.py +243 -0
  24. Cython/Compiler/Code.pxd +145 -0
  25. Cython/Compiler/Code.py +3328 -0
  26. Cython/Compiler/CodeGeneration.py +33 -0
  27. Cython/Compiler/CythonScope.py +179 -0
  28. Cython/Compiler/Dataclass.py +868 -0
  29. Cython/Compiler/DebugFlags.py +21 -0
  30. Cython/Compiler/Errors.py +295 -0
  31. Cython/Compiler/ExprNodes.py +15051 -0
  32. Cython/Compiler/FlowControl.pxd +97 -0
  33. Cython/Compiler/FlowControl.py +1438 -0
  34. Cython/Compiler/FusedNode.py +998 -0
  35. Cython/Compiler/Future.py +16 -0
  36. Cython/Compiler/Interpreter.py +57 -0
  37. Cython/Compiler/Lexicon.py +340 -0
  38. Cython/Compiler/LineTable.py +114 -0
  39. Cython/Compiler/Main.py +779 -0
  40. Cython/Compiler/MatchCaseNodes.py +259 -0
  41. Cython/Compiler/MemoryView.py +860 -0
  42. Cython/Compiler/ModuleNode.py +4065 -0
  43. Cython/Compiler/Naming.py +369 -0
  44. Cython/Compiler/Nodes.py +10557 -0
  45. Cython/Compiler/Optimize.py +5269 -0
  46. Cython/Compiler/Options.py +828 -0
  47. Cython/Compiler/ParseTreeTransforms.pxd +78 -0
  48. Cython/Compiler/ParseTreeTransforms.py +4441 -0
  49. Cython/Compiler/Parsing.pxd +9 -0
  50. Cython/Compiler/Parsing.py +4797 -0
  51. Cython/Compiler/Pipeline.py +425 -0
  52. Cython/Compiler/PyrexTypes.py +5572 -0
  53. Cython/Compiler/Pythran.py +223 -0
  54. Cython/Compiler/Scanning.pxd +40 -0
  55. Cython/Compiler/Scanning.py +574 -0
  56. Cython/Compiler/StringEncoding.py +347 -0
  57. Cython/Compiler/Symtab.py +2998 -0
  58. Cython/Compiler/Tests/TestBuffer.py +105 -0
  59. Cython/Compiler/Tests/TestBuiltin.py +72 -0
  60. Cython/Compiler/Tests/TestCmdLine.py +573 -0
  61. Cython/Compiler/Tests/TestCode.py +86 -0
  62. Cython/Compiler/Tests/TestFlowControl.py +65 -0
  63. Cython/Compiler/Tests/TestGrammar.py +202 -0
  64. Cython/Compiler/Tests/TestMemView.py +71 -0
  65. Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
  66. Cython/Compiler/Tests/TestScanning.py +134 -0
  67. Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
  68. Cython/Compiler/Tests/TestStringEncoding.py +33 -0
  69. Cython/Compiler/Tests/TestTreeFragment.py +63 -0
  70. Cython/Compiler/Tests/TestTreePath.py +93 -0
  71. Cython/Compiler/Tests/TestTypes.py +75 -0
  72. Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
  73. Cython/Compiler/Tests/TestVisitor.py +61 -0
  74. Cython/Compiler/Tests/Utils.py +36 -0
  75. Cython/Compiler/Tests/__init__.py +1 -0
  76. Cython/Compiler/TreeFragment.py +278 -0
  77. Cython/Compiler/TreePath.py +290 -0
  78. Cython/Compiler/TypeInference.py +584 -0
  79. Cython/Compiler/TypeSlots.py +1181 -0
  80. Cython/Compiler/UFuncs.py +311 -0
  81. Cython/Compiler/UtilNodes.py +387 -0
  82. Cython/Compiler/UtilityCode.py +274 -0
  83. Cython/Compiler/Version.py +8 -0
  84. Cython/Compiler/Visitor.pxd +53 -0
  85. Cython/Compiler/Visitor.py +861 -0
  86. Cython/Compiler/__init__.py +1 -0
  87. Cython/Coverage.py +443 -0
  88. Cython/Debugger/Cygdb.py +179 -0
  89. Cython/Debugger/DebugWriter.py +82 -0
  90. Cython/Debugger/Tests/TestLibCython.py +275 -0
  91. Cython/Debugger/Tests/__init__.py +1 -0
  92. Cython/Debugger/Tests/cfuncs.c +8 -0
  93. Cython/Debugger/Tests/codefile +49 -0
  94. Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
  95. Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
  96. Cython/Debugger/__init__.py +1 -0
  97. Cython/Debugger/libcython.py +1549 -0
  98. Cython/Debugger/libpython.py +2821 -0
  99. Cython/Debugging.py +20 -0
  100. Cython/Distutils/__init__.py +2 -0
  101. Cython/Distutils/build_ext.py +137 -0
  102. Cython/Distutils/extension.py +96 -0
  103. Cython/Distutils/old_build_ext.py +351 -0
  104. Cython/Includes/cpython/__init__.pxd +173 -0
  105. Cython/Includes/cpython/array.pxd +174 -0
  106. Cython/Includes/cpython/bool.pxd +37 -0
  107. Cython/Includes/cpython/buffer.pxd +112 -0
  108. Cython/Includes/cpython/bytearray.pxd +33 -0
  109. Cython/Includes/cpython/bytes.pxd +200 -0
  110. Cython/Includes/cpython/cellobject.pxd +35 -0
  111. Cython/Includes/cpython/ceval.pxd +8 -0
  112. Cython/Includes/cpython/codecs.pxd +121 -0
  113. Cython/Includes/cpython/complex.pxd +55 -0
  114. Cython/Includes/cpython/contextvars.pxd +141 -0
  115. Cython/Includes/cpython/conversion.pxd +36 -0
  116. Cython/Includes/cpython/datetime.pxd +384 -0
  117. Cython/Includes/cpython/descr.pxd +26 -0
  118. Cython/Includes/cpython/dict.pxd +187 -0
  119. Cython/Includes/cpython/exc.pxd +263 -0
  120. Cython/Includes/cpython/fileobject.pxd +57 -0
  121. Cython/Includes/cpython/float.pxd +47 -0
  122. Cython/Includes/cpython/function.pxd +65 -0
  123. Cython/Includes/cpython/genobject.pxd +25 -0
  124. Cython/Includes/cpython/getargs.pxd +12 -0
  125. Cython/Includes/cpython/instance.pxd +25 -0
  126. Cython/Includes/cpython/iterator.pxd +36 -0
  127. Cython/Includes/cpython/iterobject.pxd +24 -0
  128. Cython/Includes/cpython/list.pxd +92 -0
  129. Cython/Includes/cpython/long.pxd +149 -0
  130. Cython/Includes/cpython/longintrepr.pxd +19 -0
  131. Cython/Includes/cpython/mapping.pxd +63 -0
  132. Cython/Includes/cpython/marshal.pxd +66 -0
  133. Cython/Includes/cpython/mem.pxd +120 -0
  134. Cython/Includes/cpython/memoryview.pxd +50 -0
  135. Cython/Includes/cpython/method.pxd +49 -0
  136. Cython/Includes/cpython/module.pxd +208 -0
  137. Cython/Includes/cpython/number.pxd +258 -0
  138. Cython/Includes/cpython/object.pxd +433 -0
  139. Cython/Includes/cpython/pycapsule.pxd +143 -0
  140. Cython/Includes/cpython/pylifecycle.pxd +68 -0
  141. Cython/Includes/cpython/pyport.pxd +8 -0
  142. Cython/Includes/cpython/pystate.pxd +95 -0
  143. Cython/Includes/cpython/pythread.pxd +53 -0
  144. Cython/Includes/cpython/ref.pxd +67 -0
  145. Cython/Includes/cpython/sequence.pxd +134 -0
  146. Cython/Includes/cpython/set.pxd +119 -0
  147. Cython/Includes/cpython/slice.pxd +70 -0
  148. Cython/Includes/cpython/time.pxd +129 -0
  149. Cython/Includes/cpython/tuple.pxd +72 -0
  150. Cython/Includes/cpython/type.pxd +53 -0
  151. Cython/Includes/cpython/unicode.pxd +639 -0
  152. Cython/Includes/cpython/version.pxd +32 -0
  153. Cython/Includes/cpython/weakref.pxd +42 -0
  154. Cython/Includes/libc/__init__.pxd +1 -0
  155. Cython/Includes/libc/complex.pxd +35 -0
  156. Cython/Includes/libc/errno.pxd +127 -0
  157. Cython/Includes/libc/float.pxd +43 -0
  158. Cython/Includes/libc/limits.pxd +28 -0
  159. Cython/Includes/libc/locale.pxd +46 -0
  160. Cython/Includes/libc/math.pxd +209 -0
  161. Cython/Includes/libc/setjmp.pxd +10 -0
  162. Cython/Includes/libc/signal.pxd +64 -0
  163. Cython/Includes/libc/stddef.pxd +9 -0
  164. Cython/Includes/libc/stdint.pxd +105 -0
  165. Cython/Includes/libc/stdio.pxd +80 -0
  166. Cython/Includes/libc/stdlib.pxd +72 -0
  167. Cython/Includes/libc/string.pxd +50 -0
  168. Cython/Includes/libc/time.pxd +47 -0
  169. Cython/Includes/libcpp/__init__.pxd +4 -0
  170. Cython/Includes/libcpp/algorithm.pxd +320 -0
  171. Cython/Includes/libcpp/any.pxd +16 -0
  172. Cython/Includes/libcpp/atomic.pxd +59 -0
  173. Cython/Includes/libcpp/bit.pxd +29 -0
  174. Cython/Includes/libcpp/cast.pxd +12 -0
  175. Cython/Includes/libcpp/cmath.pxd +518 -0
  176. Cython/Includes/libcpp/complex.pxd +106 -0
  177. Cython/Includes/libcpp/deque.pxd +165 -0
  178. Cython/Includes/libcpp/execution.pxd +15 -0
  179. Cython/Includes/libcpp/forward_list.pxd +63 -0
  180. Cython/Includes/libcpp/functional.pxd +26 -0
  181. Cython/Includes/libcpp/iterator.pxd +34 -0
  182. Cython/Includes/libcpp/limits.pxd +61 -0
  183. Cython/Includes/libcpp/list.pxd +117 -0
  184. Cython/Includes/libcpp/map.pxd +252 -0
  185. Cython/Includes/libcpp/memory.pxd +115 -0
  186. Cython/Includes/libcpp/numbers.pxd +15 -0
  187. Cython/Includes/libcpp/numeric.pxd +131 -0
  188. Cython/Includes/libcpp/optional.pxd +34 -0
  189. Cython/Includes/libcpp/pair.pxd +1 -0
  190. Cython/Includes/libcpp/queue.pxd +25 -0
  191. Cython/Includes/libcpp/random.pxd +166 -0
  192. Cython/Includes/libcpp/set.pxd +228 -0
  193. Cython/Includes/libcpp/stack.pxd +11 -0
  194. Cython/Includes/libcpp/string.pxd +333 -0
  195. Cython/Includes/libcpp/typeindex.pxd +15 -0
  196. Cython/Includes/libcpp/typeinfo.pxd +10 -0
  197. Cython/Includes/libcpp/unordered_map.pxd +193 -0
  198. Cython/Includes/libcpp/unordered_set.pxd +152 -0
  199. Cython/Includes/libcpp/utility.pxd +30 -0
  200. Cython/Includes/libcpp/vector.pxd +167 -0
  201. Cython/Includes/openmp.pxd +50 -0
  202. Cython/Includes/posix/__init__.pxd +1 -0
  203. Cython/Includes/posix/dlfcn.pxd +14 -0
  204. Cython/Includes/posix/fcntl.pxd +86 -0
  205. Cython/Includes/posix/ioctl.pxd +4 -0
  206. Cython/Includes/posix/mman.pxd +101 -0
  207. Cython/Includes/posix/resource.pxd +57 -0
  208. Cython/Includes/posix/select.pxd +21 -0
  209. Cython/Includes/posix/signal.pxd +73 -0
  210. Cython/Includes/posix/stat.pxd +98 -0
  211. Cython/Includes/posix/stdio.pxd +37 -0
  212. Cython/Includes/posix/stdlib.pxd +29 -0
  213. Cython/Includes/posix/strings.pxd +9 -0
  214. Cython/Includes/posix/time.pxd +71 -0
  215. Cython/Includes/posix/types.pxd +30 -0
  216. Cython/Includes/posix/uio.pxd +26 -0
  217. Cython/Includes/posix/unistd.pxd +271 -0
  218. Cython/Includes/posix/wait.pxd +38 -0
  219. Cython/Plex/Actions.pxd +24 -0
  220. Cython/Plex/Actions.py +119 -0
  221. Cython/Plex/DFA.pxd +14 -0
  222. Cython/Plex/DFA.py +164 -0
  223. Cython/Plex/Errors.py +48 -0
  224. Cython/Plex/Lexicons.py +178 -0
  225. Cython/Plex/Machines.pxd +36 -0
  226. Cython/Plex/Machines.py +238 -0
  227. Cython/Plex/Regexps.py +539 -0
  228. Cython/Plex/Scanners.pxd +47 -0
  229. Cython/Plex/Scanners.py +360 -0
  230. Cython/Plex/Transitions.pxd +14 -0
  231. Cython/Plex/Transitions.py +239 -0
  232. Cython/Plex/__init__.py +34 -0
  233. Cython/Runtime/__init__.py +1 -0
  234. Cython/Runtime/refnanny.pyx +261 -0
  235. Cython/Shadow.py +656 -0
  236. Cython/Shadow.pyi +521 -0
  237. Cython/StringIOTree.py +170 -0
  238. Cython/Tempita/__init__.py +4 -0
  239. Cython/Tempita/_looper.py +154 -0
  240. Cython/Tempita/_tempita.py +1091 -0
  241. Cython/TestUtils.py +417 -0
  242. Cython/Tests/TestCodeWriter.py +128 -0
  243. Cython/Tests/TestCythonUtils.py +202 -0
  244. Cython/Tests/TestJediTyper.py +223 -0
  245. Cython/Tests/TestShadow.py +114 -0
  246. Cython/Tests/TestStringIOTree.py +67 -0
  247. Cython/Tests/TestTestUtils.py +90 -0
  248. Cython/Tests/__init__.py +1 -0
  249. Cython/Tests/xmlrunner.py +390 -0
  250. Cython/Utility/AsyncGen.c +1263 -0
  251. Cython/Utility/Buffer.c +875 -0
  252. Cython/Utility/Builtins.c +660 -0
  253. Cython/Utility/CConvert.pyx +134 -0
  254. Cython/Utility/CMath.c +95 -0
  255. Cython/Utility/CommonStructures.c +139 -0
  256. Cython/Utility/Complex.c +378 -0
  257. Cython/Utility/Coroutine.c +2413 -0
  258. Cython/Utility/CpdefEnums.pyx +108 -0
  259. Cython/Utility/CppConvert.pyx +279 -0
  260. Cython/Utility/CppSupport.cpp +133 -0
  261. Cython/Utility/CythonFunction.c +1851 -0
  262. Cython/Utility/Dataclasses.c +185 -0
  263. Cython/Utility/Dataclasses.py +112 -0
  264. Cython/Utility/Embed.c +125 -0
  265. Cython/Utility/Exceptions.c +1017 -0
  266. Cython/Utility/ExtensionTypes.c +797 -0
  267. Cython/Utility/FunctionArguments.c +573 -0
  268. Cython/Utility/ImportExport.c +912 -0
  269. Cython/Utility/MemoryView.pyx +1478 -0
  270. Cython/Utility/MemoryView_C.c +992 -0
  271. Cython/Utility/ModuleSetupCode.c +2501 -0
  272. Cython/Utility/NumpyImportArray.c +46 -0
  273. Cython/Utility/ObjectHandling.c +3054 -0
  274. Cython/Utility/Optimize.c +1533 -0
  275. Cython/Utility/Overflow.c +404 -0
  276. Cython/Utility/Printing.c +86 -0
  277. Cython/Utility/Profile.c +660 -0
  278. Cython/Utility/StringTools.c +1206 -0
  279. Cython/Utility/TestCyUtilityLoader.pyx +8 -0
  280. Cython/Utility/TestCythonScope.pyx +75 -0
  281. Cython/Utility/TestUtilityLoader.c +12 -0
  282. Cython/Utility/TypeConversion.c +1329 -0
  283. Cython/Utility/UFuncs.pyx +50 -0
  284. Cython/Utility/UFuncs_C.c +89 -0
  285. Cython/Utility/__init__.py +28 -0
  286. Cython/Utility/arrayarray.h +143 -0
  287. Cython/Utils.py +687 -0
  288. Cython/__init__.py +10 -0
  289. Cython/__init__.pyi +7 -0
  290. Cython/py.typed +0 -0
  291. Cython-3.1.0a1.dist-info/COPYING.txt +19 -0
  292. Cython-3.1.0a1.dist-info/LICENSE.txt +176 -0
  293. Cython-3.1.0a1.dist-info/METADATA +67 -0
  294. Cython-3.1.0a1.dist-info/RECORD +301 -0
  295. Cython-3.1.0a1.dist-info/WHEEL +5 -0
  296. Cython-3.1.0a1.dist-info/entry_points.txt +4 -0
  297. Cython-3.1.0a1.dist-info/top_level.txt +3 -0
  298. cython.py +29 -0
  299. pyximport/__init__.py +4 -0
  300. pyximport/pyxbuild.py +160 -0
  301. pyximport/pyximport.py +482 -0
@@ -0,0 +1,1329 @@
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
+ #else
67
+ #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AsString(s))
68
+ #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AsString(s))
69
+ #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AsString(s))
70
+ #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AsString(s))
71
+ #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AsString(s))
72
+ #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AsString(s))
73
+ #endif
74
+ #define __Pyx_PyObject_AsWritableString(s) ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
75
+ #define __Pyx_PyObject_AsWritableSString(s) ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
76
+ #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
77
+ #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
78
+ #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
79
+ #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
80
+ #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
81
+ #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
82
+ #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
83
+ #define __Pyx_PyUnicode_FromOrdinal(o) PyUnicode_FromOrdinal((int)o)
84
+ #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
85
+
86
+ static CYTHON_INLINE PyObject *__Pyx_NewRef(PyObject *obj) {
87
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030a0000 || defined(Py_NewRef)
88
+ return Py_NewRef(obj);
89
+ #else
90
+ Py_INCREF(obj);
91
+ return obj;
92
+ #endif
93
+ }
94
+
95
+ static CYTHON_INLINE PyObject *__Pyx_XNewRef(PyObject *obj) {
96
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030a0000 || defined(Py_XNewRef)
97
+ return Py_XNewRef(obj);
98
+ #else
99
+ Py_XINCREF(obj);
100
+ return obj;
101
+ #endif
102
+ }
103
+
104
+ #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
105
+ static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
106
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
107
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
108
+ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Long(PyObject* x);
109
+
110
+ #define __Pyx_PySequence_Tuple(obj) \
111
+ (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
112
+
113
+ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
114
+ static CYTHON_INLINE PyObject * __Pyx_PyLong_FromSize_t(size_t);
115
+ static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
116
+
117
+ #if CYTHON_ASSUME_SAFE_MACROS
118
+ #define __Pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
119
+ #define __Pyx_PyFloat_AS_DOUBLE(x) PyFloat_AS_DOUBLE(x)
120
+ #else
121
+ #define __Pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
122
+ #define __Pyx_PyFloat_AS_DOUBLE(x) PyFloat_AsDouble(x)
123
+ #endif
124
+ #define __Pyx_PyFloat_AsFloat(x) ((float) __Pyx_PyFloat_AsDouble(x))
125
+
126
+ // We call this __Pyx_PyNumber_Int() since it's the equivalent of the int() function call.
127
+ #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
128
+ // __Pyx_PyNumber_Float is now in its own section since it has dependencies (needed to make
129
+ // string conversion work the same in all circumstances).
130
+
131
+ #if CYTHON_USE_PYLONG_INTERNALS
132
+ #if PY_VERSION_HEX >= 0x030C00A7
133
+ #ifndef _PyLong_SIGN_MASK
134
+ #define _PyLong_SIGN_MASK 3
135
+ #endif
136
+ #ifndef _PyLong_NON_SIZE_BITS
137
+ #define _PyLong_NON_SIZE_BITS 3
138
+ #endif
139
+ #define __Pyx_PyLong_Sign(x) (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK)
140
+ #define __Pyx_PyLong_IsNeg(x) ((__Pyx_PyLong_Sign(x) & 2) != 0)
141
+ #define __Pyx_PyLong_IsNonNeg(x) (!__Pyx_PyLong_IsNeg(x))
142
+ #define __Pyx_PyLong_IsZero(x) (__Pyx_PyLong_Sign(x) & 1)
143
+ #define __Pyx_PyLong_IsPos(x) (__Pyx_PyLong_Sign(x) == 0)
144
+ #define __Pyx_PyLong_CompactValueUnsigned(x) (__Pyx_PyLong_Digits(x)[0])
145
+ #define __Pyx_PyLong_DigitCount(x) ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS))
146
+ #define __Pyx_PyLong_SignedDigitCount(x) \
147
+ ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x))
148
+
149
+ #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
150
+ #define __Pyx_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) x)
151
+ #define __Pyx_PyLong_CompactValue(x) PyUnstable_Long_CompactValue((PyLongObject*) x)
152
+ #else
153
+ #define __Pyx_PyLong_IsCompact(x) (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS))
154
+ #define __Pyx_PyLong_CompactValue(x) ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0])
155
+ #endif
156
+
157
+ // CPython 3.12 requires C99, which defines 'size_t' (but not 'ssize_t')
158
+ typedef Py_ssize_t __Pyx_compact_pylong;
159
+ typedef size_t __Pyx_compact_upylong;
160
+
161
+ #else /* Py < 3.12 */
162
+ #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0)
163
+ #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0)
164
+ #define __Pyx_PyLong_IsZero(x) (Py_SIZE(x) == 0)
165
+ #define __Pyx_PyLong_IsPos(x) (Py_SIZE(x) > 0)
166
+ #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0])
167
+ #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x))
168
+ #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x)
169
+
170
+ #define __Pyx_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
171
+ #define __Pyx_PyLong_CompactValue(x) \
172
+ ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0]))
173
+
174
+ typedef sdigit __Pyx_compact_pylong;
175
+ typedef digit __Pyx_compact_upylong;
176
+ #endif
177
+
178
+ #if PY_VERSION_HEX >= 0x030C00A5
179
+ #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit)
180
+ #else
181
+ #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->ob_digit)
182
+ #endif
183
+ #endif
184
+
185
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_UTF8
186
+ #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
187
+ #elif __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
188
+ #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeASCII(c_str, size, NULL)
189
+ #else
190
+ #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
191
+ #endif
192
+
193
+ /////////////// TypeConversions ///////////////
194
+
195
+ /* Type Conversion Functions */
196
+
197
+ #include <string.h>
198
+
199
+ static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) {
200
+ size_t len = strlen(s);
201
+ if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) {
202
+ PyErr_SetString(PyExc_OverflowError, "byte string is too long");
203
+ return -1;
204
+ }
205
+ return (Py_ssize_t) len;
206
+ }
207
+
208
+ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
209
+ Py_ssize_t len = __Pyx_ssize_strlen(c_str);
210
+ if (unlikely(len < 0)) return NULL;
211
+ return __Pyx_PyUnicode_FromStringAndSize(c_str, len);
212
+ }
213
+
214
+ static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) {
215
+ Py_ssize_t len = __Pyx_ssize_strlen(c_str);
216
+ if (unlikely(len < 0)) return NULL;
217
+ return PyByteArray_FromStringAndSize(c_str, len);
218
+ }
219
+
220
+ // Py3.7 returns a "const char*" for unicode strings
221
+ static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
222
+ Py_ssize_t ignore;
223
+ return __Pyx_PyObject_AsStringAndSize(o, &ignore);
224
+ }
225
+
226
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_UTF8
227
+ static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
228
+ if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
229
+ #if CYTHON_COMPILING_IN_LIMITED_API
230
+ {
231
+ const char* result;
232
+ Py_ssize_t unicode_length;
233
+ CYTHON_MAYBE_UNUSED_VAR(unicode_length); // only for __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
234
+ #if __PYX_LIMITED_VERSION_HEX < 0x030A0000
235
+ if (unlikely(PyArg_Parse(o, "s#", &result, length) < 0)) return NULL;
236
+ #else
237
+ result = PyUnicode_AsUTF8AndSize(o, length);
238
+ #endif
239
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
240
+ // Pre-checking "isascii" the Limited API involves making Python function calls.
241
+ // Therefore we do a post-check instead that the lengths of the encoded and unicode
242
+ // strings are the same (which is only true for ascii strings).
243
+ // If this isn't true then we've already done the encoding so it's a potential
244
+ // performance loss, but it should be better in the successful case.
245
+ unicode_length = PyUnicode_GetLength(o);
246
+ if (unlikely(unicode_length < 0)) return NULL;
247
+ if (unlikely(unicode_length != *length)) {
248
+ // raise the error
249
+ PyUnicode_AsASCIIString(o);
250
+ return NULL;
251
+ }
252
+ #endif
253
+ return result;
254
+ }
255
+ #else /* CYTHON_COMPILING_IN_LIMITED_API */
256
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
257
+ if (likely(PyUnicode_IS_ASCII(o))) {
258
+ // cached for the lifetime of the object
259
+ *length = PyUnicode_GET_LENGTH(o);
260
+ return PyUnicode_AsUTF8(o);
261
+ } else {
262
+ // raise the error
263
+ PyUnicode_AsASCIIString(o);
264
+ return NULL;
265
+ }
266
+ #else
267
+ return PyUnicode_AsUTF8AndSize(o, length);
268
+ #endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */
269
+ #endif /* !CYTHON_COMPILING_IN_LIMITED_API */
270
+ }
271
+ #endif
272
+
273
+ // Py3.7 returns a "const char*" for unicode strings
274
+ static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
275
+ #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_UTF8
276
+ if (PyUnicode_Check(o)) {
277
+ return __Pyx_PyUnicode_AsStringAndSize(o, length);
278
+ } else
279
+ #endif
280
+
281
+ #if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
282
+ if (PyByteArray_Check(o)) {
283
+ *length = PyByteArray_GET_SIZE(o);
284
+ return PyByteArray_AS_STRING(o);
285
+ } else
286
+ #endif
287
+ {
288
+ char* result;
289
+ int r = PyBytes_AsStringAndSize(o, &result, length);
290
+ if (unlikely(r < 0)) {
291
+ return NULL;
292
+ } else {
293
+ return result;
294
+ }
295
+ }
296
+ }
297
+
298
+ /* Note: __Pyx_PyObject_IsTrue is written to minimize branching. */
299
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
300
+ int is_true = x == Py_True;
301
+ if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
302
+ else return PyObject_IsTrue(x);
303
+ }
304
+
305
+ static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
306
+ int retval;
307
+ if (unlikely(!x)) return -1;
308
+ retval = __Pyx_PyObject_IsTrue(x);
309
+ Py_DECREF(x);
310
+ return retval;
311
+ }
312
+
313
+ static PyObject* __Pyx_PyNumber_LongWrongResultType(PyObject* result) {
314
+ __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result));
315
+ if (PyLong_Check(result)) {
316
+ // CPython issue #17576: warn if 'result' not of exact type int.
317
+ if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
318
+ "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). "
319
+ "The ability to return an instance of a strict subclass of int is deprecated, "
320
+ "and may be removed in a future version of Python.",
321
+ result_type_name)) {
322
+ __Pyx_DECREF_TypeName(result_type_name);
323
+ Py_DECREF(result);
324
+ return NULL;
325
+ }
326
+ __Pyx_DECREF_TypeName(result_type_name);
327
+ return result;
328
+ }
329
+ PyErr_Format(PyExc_TypeError,
330
+ "__int__ returned non-int (type " __Pyx_FMT_TYPENAME ")",
331
+ result_type_name);
332
+ __Pyx_DECREF_TypeName(result_type_name);
333
+ Py_DECREF(result);
334
+ return NULL;
335
+ }
336
+
337
+ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Long(PyObject* x) {
338
+ #if CYTHON_USE_TYPE_SLOTS
339
+ PyNumberMethods *m;
340
+ #endif
341
+ PyObject *res = NULL;
342
+ if (likely(PyLong_Check(x)))
343
+ return __Pyx_NewRef(x);
344
+ #if CYTHON_USE_TYPE_SLOTS
345
+ m = Py_TYPE(x)->tp_as_number;
346
+ if (likely(m && m->nb_int)) {
347
+ res = m->nb_int(x);
348
+ }
349
+ #else
350
+ if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
351
+ res = PyNumber_Long(x);
352
+ }
353
+ #endif
354
+ if (likely(res)) {
355
+ if (unlikely(!PyLong_CheckExact(res))) {
356
+ return __Pyx_PyNumber_LongWrongResultType(res);
357
+ }
358
+ }
359
+ else if (!PyErr_Occurred()) {
360
+ PyErr_SetString(PyExc_TypeError,
361
+ "an integer is required");
362
+ }
363
+ return res;
364
+ }
365
+
366
+ {{py: from Cython.Utility import pylong_join }}
367
+
368
+ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
369
+ Py_ssize_t ival;
370
+ PyObject *x;
371
+ if (likely(PyLong_CheckExact(b))) {
372
+ #if CYTHON_USE_PYLONG_INTERNALS
373
+ // handle most common case first to avoid indirect branch and optimise branch prediction
374
+ if (likely(__Pyx_PyLong_IsCompact(b))) {
375
+ return __Pyx_PyLong_CompactValue(b);
376
+ } else {
377
+ const digit* digits = __Pyx_PyLong_Digits(b);
378
+ const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b);
379
+ switch (size) {
380
+ {{for _size in (2, 3, 4)}}
381
+ {{for _case in (_size, -_size)}}
382
+ case {{_case}}:
383
+ if (8 * sizeof(Py_ssize_t) > {{_size}} * PyLong_SHIFT) {
384
+ return {{'-' if _case < 0 else ''}}(Py_ssize_t) {{pylong_join(_size, 'digits', 'size_t')}};
385
+ }
386
+ break;
387
+ {{endfor}}
388
+ {{endfor}}
389
+ }
390
+ }
391
+ #endif
392
+ return PyLong_AsSsize_t(b);
393
+ }
394
+ x = PyNumber_Index(b);
395
+ if (!x) return -1;
396
+ ival = PyLong_AsSsize_t(x);
397
+ Py_DECREF(x);
398
+ return ival;
399
+ }
400
+
401
+
402
+ static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
403
+ if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
404
+ return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
405
+ } else {
406
+ Py_ssize_t ival;
407
+ PyObject *x;
408
+ x = PyNumber_Index(o);
409
+ if (!x) return -1;
410
+ ival = PyLong_AsLong(x);
411
+ Py_DECREF(x);
412
+ return ival;
413
+ }
414
+ }
415
+
416
+
417
+ static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
418
+ return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
419
+ }
420
+
421
+
422
+ static CYTHON_INLINE PyObject * __Pyx_PyLong_FromSize_t(size_t ival) {
423
+ return PyLong_FromSize_t(ival);
424
+ }
425
+
426
+ /////////////// pynumber_float.proto ///////////////
427
+
428
+ static CYTHON_INLINE PyObject* __Pyx__PyNumber_Float(PyObject* obj); /* proto */
429
+ #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : __Pyx__PyNumber_Float(x))
430
+
431
+ /////////////// pynumber_float ///////////////
432
+ //@requires: Optimize.c::pybytes_as_double
433
+ //@requires: Optimize.c::pyunicode_as_double
434
+
435
+ static CYTHON_INLINE PyObject* __Pyx__PyNumber_Float(PyObject* obj) {
436
+ // 'obj is PyFloat' is handled in the calling macro
437
+ double val;
438
+ if (PyLong_CheckExact(obj)) {
439
+ #if CYTHON_USE_PYLONG_INTERNALS
440
+ if (likely(__Pyx_PyLong_IsCompact(obj))) {
441
+ val = (double) __Pyx_PyLong_CompactValue(obj);
442
+ goto no_error;
443
+ }
444
+ #endif
445
+ val = PyLong_AsDouble(obj);
446
+ } else if (PyUnicode_CheckExact(obj)) {
447
+ val = __Pyx_PyUnicode_AsDouble(obj);
448
+ } else if (PyBytes_CheckExact(obj)) {
449
+ val = __Pyx_PyBytes_AsDouble(obj);
450
+ } else if (PyByteArray_CheckExact(obj)) {
451
+ val = __Pyx_PyByteArray_AsDouble(obj);
452
+ } else {
453
+ return PyNumber_Float(obj);
454
+ }
455
+
456
+ if (unlikely(val == -1 && PyErr_Occurred())) {
457
+ return NULL;
458
+ }
459
+ #if CYTHON_USE_PYLONG_INTERNALS
460
+ no_error:
461
+ #endif
462
+ return PyFloat_FromDouble(val);
463
+ }
464
+
465
+ /////////////// GCCDiagnostics.proto ///////////////
466
+
467
+ // GCC diagnostic pragmas were introduced in GCC 4.6
468
+ // Used to silence conversion warnings that are ok but cannot be avoided.
469
+ #if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
470
+ #define __Pyx_HAS_GCC_DIAGNOSTIC
471
+ #endif
472
+
473
+
474
+ /////////////// ToPyCTupleUtility.proto ///////////////
475
+ static PyObject* {{funcname}}({{struct_type_decl}});
476
+
477
+ /////////////// ToPyCTupleUtility ///////////////
478
+ static PyObject* {{funcname}}({{struct_type_decl}} value) {
479
+ PyObject* item = NULL;
480
+ PyObject* result = PyTuple_New({{size}});
481
+ if (!result) goto bad;
482
+
483
+ {{for ix, component in enumerate(components):}}
484
+ {{py:attr = "value.f%s" % ix}}
485
+ item = {{component.to_py_function}}({{attr}});
486
+ if (!item) goto bad;
487
+ PyTuple_SET_ITEM(result, {{ix}}, item);
488
+ {{endfor}}
489
+
490
+ return result;
491
+ bad:
492
+ Py_XDECREF(item);
493
+ Py_XDECREF(result);
494
+ return NULL;
495
+ }
496
+
497
+
498
+ /////////////// FromPyCTupleUtility.proto ///////////////
499
+ static CYTHON_INLINE {{struct_type_decl}} {{funcname}}(PyObject *);
500
+
501
+ /////////////// FromPyCTupleUtility ///////////////
502
+
503
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS
504
+ static void __Pyx_tuple_{{funcname}}(PyObject * o, {{struct_type_decl}} *result) {
505
+ {{for ix, component in enumerate(components):}}
506
+ {{py:attr = "result->f%s" % ix}}
507
+ {{attr}} = {{component.from_py_function}}(PyTuple_GET_ITEM(o, {{ix}}));
508
+ if ({{component.error_condition(attr)}}) goto bad;
509
+ {{endfor}}
510
+ return;
511
+ bad:
512
+ return;
513
+ }
514
+
515
+ static void __Pyx_list_{{funcname}}(PyObject * o, {{struct_type_decl}} *result) {
516
+ {{for ix, component in enumerate(components):}}
517
+ {{py:attr = "result->f%s" % ix}}
518
+ {{attr}} = {{component.from_py_function}}(PyList_GET_ITEM(o, {{ix}}));
519
+ if ({{component.error_condition(attr)}}) goto bad;
520
+ {{endfor}}
521
+ return;
522
+ bad:
523
+ return;
524
+ }
525
+ #endif
526
+
527
+ static void __Pyx_seq_{{funcname}}(PyObject * o, {{struct_type_decl}} *result) {
528
+ if (unlikely(!PySequence_Check(o))) {
529
+ __Pyx_TypeName o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));
530
+ PyErr_Format(PyExc_TypeError,
531
+ "Expected a sequence of size %zd, got " __Pyx_FMT_TYPENAME, (Py_ssize_t) {{size}}, o_type_name);
532
+ __Pyx_DECREF_TypeName(o_type_name);
533
+ goto bad;
534
+ } else if (unlikely(PySequence_Length(o) != {{size}})) {
535
+ PyErr_Format(PyExc_TypeError,
536
+ "Expected a sequence of size %zd, got size %zd", (Py_ssize_t) {{size}}, PySequence_Length(o));
537
+ goto bad;
538
+ }
539
+
540
+ {
541
+ PyObject *item;
542
+ {{for ix, component in enumerate(components):}}
543
+ {{py:attr = "result->f%s" % ix}}
544
+ item = __Pyx_PySequence_ITEM(o, {{ix}}); if (unlikely(!item)) goto bad;
545
+ {{attr}} = {{component.from_py_function}}(item);
546
+ Py_DECREF(item);
547
+ if ({{component.error_condition(attr)}}) goto bad;
548
+ {{endfor}}
549
+ }
550
+ return;
551
+ bad:
552
+ return;
553
+ }
554
+
555
+ static CYTHON_INLINE {{struct_type_decl}} {{funcname}}(PyObject * o) {
556
+ {{struct_type_decl}} result;
557
+
558
+ #if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE && !CYTHON_AVOID_BORROWED_REFS
559
+ if (likely(PyTuple_Check(o) && PyTuple_GET_SIZE(o) == {{size}})) {
560
+ __Pyx_tuple_{{funcname}}(o, &result);
561
+ } else if (likely(PyList_Check(o) && PyList_GET_SIZE(o) == {{size}})) {
562
+ __Pyx_list_{{funcname}}(o, &result);
563
+ } else
564
+ #endif
565
+ {
566
+ __Pyx_seq_{{funcname}}(o, &result);
567
+ }
568
+
569
+ return result;
570
+ }
571
+
572
+
573
+ /////////////// UnicodeAsUCS4.proto ///////////////
574
+
575
+ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);
576
+
577
+ /////////////// UnicodeAsUCS4 ///////////////
578
+
579
+ static void __Pyx_PyUnicode_AsPy_UCS4_error(Py_ssize_t length) {
580
+ if (likely(length >= 0)) {
581
+ // "length == -1" indicates an error already.
582
+ PyErr_Format(PyExc_ValueError,
583
+ "only single character unicode strings can be converted to Py_UCS4, "
584
+ "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
585
+ }
586
+ }
587
+
588
+ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
589
+ Py_ssize_t length = __Pyx_PyUnicode_GET_LENGTH(x);
590
+ if (unlikely(length != 1)) {
591
+ __Pyx_PyUnicode_AsPy_UCS4_error(length);
592
+ return (Py_UCS4)-1;
593
+ }
594
+ return __Pyx_PyUnicode_READ_CHAR(x, 0);
595
+ }
596
+
597
+
598
+ /////////////// ObjectAsUCS4.proto ///////////////
599
+ //@requires: UnicodeAsUCS4
600
+
601
+ static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject*);
602
+
603
+ static CYTHON_INLINE Py_UCS4 __Pyx_PyObject_AsPy_UCS4(PyObject *x) {
604
+ return (likely(PyUnicode_Check(x)) ? __Pyx_PyUnicode_AsPy_UCS4(x) : __Pyx__PyObject_AsPy_UCS4(x));
605
+ }
606
+
607
+
608
+ /////////////// ObjectAsUCS4 ///////////////
609
+
610
+ static void __Pyx__PyObject_AsPy_UCS4_raise_error(long ival) {
611
+ if (ival < 0) {
612
+ if (!PyErr_Occurred())
613
+ PyErr_SetString(PyExc_OverflowError,
614
+ "cannot convert negative value to Py_UCS4");
615
+ } else {
616
+ PyErr_SetString(PyExc_OverflowError,
617
+ "value too large to convert to Py_UCS4");
618
+ }
619
+ }
620
+
621
+ static Py_UCS4 __Pyx__PyObject_AsPy_UCS4(PyObject* x) {
622
+ long ival;
623
+ ival = __Pyx_PyLong_As_long(x);
624
+ if (unlikely(!__Pyx_is_valid_index(ival, 1114111 + 1))) {
625
+ __Pyx__PyObject_AsPy_UCS4_raise_error(ival);
626
+ return (Py_UCS4)-1;
627
+ }
628
+ return (Py_UCS4)ival;
629
+ }
630
+
631
+
632
+ /////////////// ObjectAsPyUnicode.proto ///////////////
633
+
634
+ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject*);
635
+
636
+ /////////////// ObjectAsPyUnicode ///////////////
637
+
638
+ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject* x) {
639
+ long ival;
640
+ #if defined(Py_UNICODE_SIZE) && Py_UNICODE_SIZE == 2
641
+ const long maxval = 65535;
642
+ #else
643
+ const long maxval = 1114111;
644
+ #endif
645
+ if (PyUnicode_Check(x)) {
646
+ Py_ssize_t length = __Pyx_PyUnicode_GET_LENGTH(x);
647
+ if (unlikely(length != 1)) {
648
+ // -1 indicates an error.
649
+ if (length >= 0) {
650
+ PyErr_Format(PyExc_ValueError,
651
+ "only single character unicode strings can be converted to Py_UNICODE, "
652
+ "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
653
+ }
654
+ return (Py_UNICODE)-1;
655
+ }
656
+ ival = PyUnicode_READ_CHAR(x, 0);
657
+ } else {
658
+ ival = __Pyx_PyLong_As_long(x);
659
+ }
660
+ if (unlikely(!__Pyx_is_valid_index(ival, maxval + 1))) {
661
+ if (ival < 0) {
662
+ if (!PyErr_Occurred())
663
+ PyErr_SetString(PyExc_OverflowError,
664
+ "cannot convert negative value to Py_UNICODE");
665
+ return (Py_UNICODE)-1;
666
+ } else {
667
+ PyErr_SetString(PyExc_OverflowError,
668
+ "value too large to convert to Py_UNICODE");
669
+ }
670
+ return (Py_UNICODE)-1;
671
+ }
672
+ return (Py_UNICODE)ival;
673
+ }
674
+
675
+
676
+ /////////////// CIntToPy.proto ///////////////
677
+
678
+ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value);
679
+
680
+ /////////////// CIntToPy ///////////////
681
+ //@requires: GCCDiagnostics
682
+ //@requires: ObjectHandling.c::PyObjectVectorCallKwBuilder
683
+
684
+ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
685
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
686
+ #pragma GCC diagnostic push
687
+ #pragma GCC diagnostic ignored "-Wconversion"
688
+ #endif
689
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
690
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
691
+ #pragma GCC diagnostic pop
692
+ #endif
693
+ const int is_unsigned = neg_one > const_zero;
694
+ if (is_unsigned) {
695
+ if (sizeof({{TYPE}}) < sizeof(long)) {
696
+ return PyLong_FromLong((long) value);
697
+ } else if (sizeof({{TYPE}}) <= sizeof(unsigned long)) {
698
+ return PyLong_FromUnsignedLong((unsigned long) value);
699
+ #ifdef HAVE_LONG_LONG
700
+ } else if (sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG)) {
701
+ return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
702
+ #endif
703
+ }
704
+ } else {
705
+ if (sizeof({{TYPE}}) <= sizeof(long)) {
706
+ return PyLong_FromLong((long) value);
707
+ #ifdef HAVE_LONG_LONG
708
+ } else if (sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG)) {
709
+ return PyLong_FromLongLong((PY_LONG_LONG) value);
710
+ #endif
711
+ }
712
+ }
713
+ {
714
+ unsigned char *bytes = (unsigned char *)&value;
715
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
716
+ if (is_unsigned) {
717
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
718
+ } else {
719
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
720
+ }
721
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
722
+ int one = 1; int little = (int)*(unsigned char *)&one;
723
+ return _PyLong_FromByteArray(bytes, sizeof({{TYPE}}),
724
+ little, !is_unsigned);
725
+ #else
726
+ // call int.from_bytes()
727
+ int one = 1; int little = (int)*(unsigned char *)&one;
728
+ PyObject *from_bytes, *result = NULL, *kwds = NULL;
729
+ PyObject *py_bytes = NULL, *order_str = NULL;
730
+ from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
731
+ if (!from_bytes) return NULL;
732
+ py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof({{TYPE}}));
733
+ if (!py_bytes) goto limited_bad;
734
+ // I'm deliberately not using PYIDENT here because this code path is very unlikely
735
+ // to ever run so it seems a pessimization mostly.
736
+ order_str = PyUnicode_FromString(little ? "little" : "big");
737
+ if (!order_str) goto limited_bad;
738
+ {
739
+ PyObject *args[3+(CYTHON_VECTORCALL ? 1 : 0)] = { NULL, py_bytes, order_str };
740
+ if (!is_unsigned) {
741
+ kwds = __Pyx_MakeVectorcallBuilderKwds(1);
742
+ if (!kwds) goto limited_bad;
743
+ if (__Pyx_VectorcallBuilder_AddArgStr("signed", __Pyx_NewRef(Py_True), kwds, args+3, 0) < 0) goto limited_bad;
744
+ }
745
+ result = __Pyx_Object_Vectorcall_CallFromBuilder(from_bytes, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, kwds);
746
+ }
747
+
748
+ limited_bad:
749
+ Py_XDECREF(kwds);
750
+ Py_XDECREF(order_str);
751
+ Py_XDECREF(py_bytes);
752
+ Py_XDECREF(from_bytes);
753
+ return result;
754
+ #endif
755
+ }
756
+ }
757
+
758
+
759
+ /////////////// COrdinalToPyUnicode.proto ///////////////
760
+
761
+ static CYTHON_INLINE int __Pyx_CheckUnicodeValue(int value);
762
+ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromOrdinal_Padded(int value, Py_ssize_t width, char padding_char);
763
+
764
+ /////////////// COrdinalToPyUnicode ///////////////
765
+ //@requires: StringTools.c::BuildPyUnicode
766
+
767
+ static CYTHON_INLINE int __Pyx_CheckUnicodeValue(int value) {
768
+ return value <= 1114111;
769
+ }
770
+
771
+ static PyObject* __Pyx_PyUnicode_FromOrdinal_Padded(int value, Py_ssize_t ulength, char padding_char) {
772
+ if (likely(ulength <= 250)) {
773
+ // Encode to UTF-8 / Latin1 buffer, then decode.
774
+ char chars[256];
775
+
776
+ if (value <= 255) {
777
+ // Simple Latin1 result, fast to decode.
778
+ memset(chars, padding_char, (size_t) (ulength - 1));
779
+ chars[ulength-1] = (char) value;
780
+ return PyUnicode_DecodeLatin1(chars, ulength, NULL);
781
+ }
782
+
783
+ char *cpos = chars + sizeof(chars);
784
+ if (value < 0x800) {
785
+ *--cpos = (char) (0b10000000 | (value & 0x3f));
786
+ value >>= 6;
787
+ *--cpos = (char) (0b11000000 | (value & 0x1f));
788
+ } else if (value < 0x10000) {
789
+ *--cpos = (char) (0b10000000 | (char) (value & 0x3f));
790
+ value >>= 6;
791
+ *--cpos = (char) (0b10000000 | (char) (value & 0x3f));
792
+ value >>= 6;
793
+ *--cpos = (char) (0b11100000 | (char) (value & 0xf));
794
+ } else {
795
+ *--cpos = (char) (0b10000000 | (char) (value & 0x3f));
796
+ value >>= 6;
797
+ *--cpos = (char) (0b10000000 | (char) (value & 0x3f));
798
+ value >>= 6;
799
+ *--cpos = (char) (0b10000000 | (char) (value & 0x3f));
800
+ value >>= 6;
801
+ *--cpos = (char) (0b11110000 | (char) (value & 0x7));
802
+ }
803
+ cpos -= ulength;
804
+ memset(cpos, padding_char, (size_t) (ulength - 1));
805
+ return PyUnicode_DecodeUTF8(cpos, chars + sizeof(chars) - cpos, NULL);
806
+ }
807
+
808
+ if (value <= 127 && CYTHON_USE_UNICODE_INTERNALS) {
809
+ const char chars[1] = {(char) value};
810
+ return __Pyx_PyUnicode_BuildFromAscii(ulength, chars, 1, 0, padding_char);
811
+ }
812
+
813
+ {
814
+ PyObject *uchar, *padding_uchar, *padding, *result;
815
+
816
+ padding_uchar = PyUnicode_FromOrdinal(padding_char);
817
+ if (unlikely(!padding_uchar)) return NULL;
818
+ padding = PySequence_Repeat(padding_uchar, ulength - 1);
819
+ Py_DECREF(padding_uchar);
820
+ if (unlikely(!padding)) return NULL;
821
+
822
+ uchar = PyUnicode_FromOrdinal(value);
823
+ if (unlikely(!uchar)) {
824
+ Py_DECREF(padding);
825
+ return NULL;
826
+ }
827
+
828
+ result = PyUnicode_Concat(padding, uchar);
829
+ Py_DECREF(padding);
830
+ Py_DECREF(uchar);
831
+ return result;
832
+ }
833
+ }
834
+
835
+
836
+ /////////////// CIntToDigits ///////////////
837
+
838
+ static const char DIGIT_PAIRS_10[2*10*10+1] = {
839
+ "00010203040506070809"
840
+ "10111213141516171819"
841
+ "20212223242526272829"
842
+ "30313233343536373839"
843
+ "40414243444546474849"
844
+ "50515253545556575859"
845
+ "60616263646566676869"
846
+ "70717273747576777879"
847
+ "80818283848586878889"
848
+ "90919293949596979899"
849
+ };
850
+
851
+ static const char DIGIT_PAIRS_8[2*8*8+1] = {
852
+ "0001020304050607"
853
+ "1011121314151617"
854
+ "2021222324252627"
855
+ "3031323334353637"
856
+ "4041424344454647"
857
+ "5051525354555657"
858
+ "6061626364656667"
859
+ "7071727374757677"
860
+ };
861
+
862
+ static const char DIGITS_HEX[2*16+1] = {
863
+ "0123456789abcdef"
864
+ "0123456789ABCDEF"
865
+ };
866
+
867
+
868
+ /////////////// CIntToPyUnicode.proto ///////////////
869
+
870
+ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char, char format_char);
871
+
872
+ /////////////// CIntToPyUnicode ///////////////
873
+ //@requires: StringTools.c::IncludeStringH
874
+ //@requires: StringTools.c::BuildPyUnicode
875
+ //@requires: COrdinalToPyUnicode
876
+ //@requires: CIntToDigits
877
+ //@requires: GCCDiagnostics
878
+
879
+ // NOTE: inlining because most arguments are constant, which collapses lots of code below
880
+
881
+ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value, Py_ssize_t width, char padding_char, char format_char) {
882
+ // simple and conservative C string allocation on the stack: each byte gives at most 3 digits, plus sign
883
+ char digits[sizeof({{TYPE}})*3+2];
884
+ // 'dpos' points to end of digits array + 1 initially to allow for pre-decrement looping
885
+ char *dpos, *end = digits + sizeof({{TYPE}})*3+2;
886
+ const char *hex_digits = DIGITS_HEX;
887
+ Py_ssize_t length, ulength;
888
+ int prepend_sign, last_one_off;
889
+ {{TYPE}} remaining;
890
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
891
+ #pragma GCC diagnostic push
892
+ #pragma GCC diagnostic ignored "-Wconversion"
893
+ #endif
894
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
895
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
896
+ #pragma GCC diagnostic pop
897
+ #endif
898
+ const int is_unsigned = neg_one > const_zero;
899
+
900
+ // Format 'c' (unicode character) is really a different thing but included for practical reasons.
901
+ if (format_char == 'c') {
902
+ // This check is just an awful variation on "(0 <= value <= 1114111)",
903
+ // but without C compiler complaints about compile time constant conditions depending on the signed/unsigned TYPE.
904
+ if (unlikely(!(is_unsigned || value == 0 || value > 0) ||
905
+ !(sizeof(value) <= 2 || value & ~ ({{TYPE}}) 0x01fffff || __Pyx_CheckUnicodeValue((int) value)))) {
906
+ // PyUnicode_FromOrdinal() and chr() raise ValueError, f-strings raise OverflowError. :-/
907
+ PyErr_SetString(PyExc_OverflowError, "%c arg not in range(0x110000)");
908
+ return NULL;
909
+ }
910
+ if (width <= 1) {
911
+ return PyUnicode_FromOrdinal((int) value);
912
+ }
913
+ return __Pyx_PyUnicode_FromOrdinal_Padded((int) value, width, padding_char);
914
+ }
915
+
916
+ if (format_char == 'X') {
917
+ hex_digits += 16;
918
+ format_char = 'x';
919
+ }
920
+
921
+ // surprise: even trivial sprintf() calls don't get optimised in gcc (4.8)
922
+ remaining = value; /* not using abs(value) to avoid overflow problems */
923
+ last_one_off = 0;
924
+ dpos = end;
925
+ do {
926
+ int digit_pos;
927
+ switch (format_char) {
928
+ case 'o':
929
+ digit_pos = abs((int)(remaining % (8*8)));
930
+ remaining = ({{TYPE}}) (remaining / (8*8));
931
+ dpos -= 2;
932
+ memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2); /* copy 2 digits at a time, unaligned */
933
+ last_one_off = (digit_pos < 8);
934
+ break;
935
+ case 'd':
936
+ digit_pos = abs((int)(remaining % (10*10)));
937
+ remaining = ({{TYPE}}) (remaining / (10*10));
938
+ dpos -= 2;
939
+ memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2); /* copy 2 digits at a time, unaligned */
940
+ last_one_off = (digit_pos < 10);
941
+ break;
942
+ case 'x':
943
+ *(--dpos) = hex_digits[abs((int)(remaining % 16))];
944
+ remaining = ({{TYPE}}) (remaining / 16);
945
+ break;
946
+ default:
947
+ assert(0);
948
+ break;
949
+ }
950
+ } while (unlikely(remaining != 0));
951
+
952
+ // Correct dpos by 1 if we read an excess digit.
953
+ assert(!last_one_off || *dpos == '0');
954
+ dpos += last_one_off;
955
+
956
+ length = end - dpos;
957
+ ulength = length;
958
+ prepend_sign = 0;
959
+ if (!is_unsigned && value <= neg_one) {
960
+ if (padding_char == ' ' || width <= length + 1) {
961
+ *(--dpos) = '-';
962
+ ++length;
963
+ } else {
964
+ prepend_sign = 1;
965
+ }
966
+ ++ulength;
967
+ }
968
+ if (width > ulength) {
969
+ ulength = width;
970
+ }
971
+ // single character unicode strings are cached in CPython => use PyUnicode_FromOrdinal() for them
972
+ if (ulength == 1) {
973
+ return PyUnicode_FromOrdinal(*dpos);
974
+ }
975
+ return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
976
+ }
977
+
978
+
979
+ /////////////// CBIntToPyUnicode.proto ///////////////
980
+
981
+ #define {{TO_PY_FUNCTION}}(value) \
982
+ ((value) ? __Pyx_NewRef({{TRUE_CONST}}) : __Pyx_NewRef({{FALSE_CONST}}))
983
+
984
+
985
+ /////////////// CIntFromPyVerify ///////////////
986
+
987
+ // see CIntFromPy
988
+ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value) \
989
+ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
990
+
991
+ #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value) \
992
+ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
993
+
994
+ #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc) \
995
+ { \
996
+ func_type value = func_value; \
997
+ if (sizeof(target_type) < sizeof(func_type)) { \
998
+ if (unlikely(value != (func_type) (target_type) value)) { \
999
+ func_type zero = 0; \
1000
+ if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred())) \
1001
+ return (target_type) -1; \
1002
+ if (is_unsigned && unlikely(value < zero)) \
1003
+ goto raise_neg_overflow; \
1004
+ else \
1005
+ goto raise_overflow; \
1006
+ } \
1007
+ } \
1008
+ return (target_type) value; \
1009
+ }
1010
+
1011
+
1012
+ /////////////// CIntFromPy.proto ///////////////
1013
+
1014
+ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *);
1015
+
1016
+ /////////////// CIntFromPy ///////////////
1017
+ //@requires: CIntFromPyVerify
1018
+ //@requires: GCCDiagnostics
1019
+
1020
+ {{py: from Cython.Utility import pylong_join }}
1021
+
1022
+ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
1023
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1024
+ #pragma GCC diagnostic push
1025
+ #pragma GCC diagnostic ignored "-Wconversion"
1026
+ #endif
1027
+ const {{TYPE}} neg_one = ({{TYPE}}) -1, const_zero = ({{TYPE}}) 0;
1028
+ #ifdef __Pyx_HAS_GCC_DIAGNOSTIC
1029
+ #pragma GCC diagnostic pop
1030
+ #endif
1031
+ const int is_unsigned = neg_one > const_zero;
1032
+
1033
+ if (unlikely(!PyLong_Check(x))) {
1034
+ {{TYPE}} val;
1035
+ PyObject *tmp = __Pyx_PyNumber_Long(x);
1036
+ if (!tmp) return ({{TYPE}}) -1;
1037
+ val = {{FROM_PY_FUNCTION}}(tmp);
1038
+ Py_DECREF(tmp);
1039
+ return val;
1040
+ }
1041
+
1042
+ if (is_unsigned) {
1043
+ #if CYTHON_USE_PYLONG_INTERNALS
1044
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
1045
+ goto raise_neg_overflow;
1046
+ //} else if (__Pyx_PyLong_IsZero(x)) {
1047
+ // return ({{TYPE}}) 0;
1048
+ } else if (__Pyx_PyLong_IsCompact(x)) {
1049
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
1050
+ } else {
1051
+ const digit* digits = __Pyx_PyLong_Digits(x);
1052
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
1053
+ switch (__Pyx_PyLong_DigitCount(x)) {
1054
+ {{for _size in (2, 3, 4)}}
1055
+ case {{_size}}:
1056
+ if ((8 * sizeof({{TYPE}}) > {{_size-1}} * PyLong_SHIFT)) {
1057
+ if ((8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT)) {
1058
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, unsigned long, {{pylong_join(_size, 'digits')}})
1059
+ } else if ((8 * sizeof({{TYPE}}) >= {{_size}} * PyLong_SHIFT)) {
1060
+ return ({{TYPE}}) {{pylong_join(_size, 'digits', TYPE)}};
1061
+ }
1062
+ }
1063
+ break;
1064
+ {{endfor}}
1065
+ }
1066
+ }
1067
+ #endif
1068
+ #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
1069
+ if (unlikely(Py_SIZE(x) < 0)) {
1070
+ goto raise_neg_overflow;
1071
+ }
1072
+ #else
1073
+ {
1074
+ // misuse Py_False as a quick way to compare to a '0' int object in PyPy
1075
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
1076
+ if (unlikely(result < 0))
1077
+ return ({{TYPE}}) -1;
1078
+ if (unlikely(result == 1))
1079
+ goto raise_neg_overflow;
1080
+ }
1081
+ #endif
1082
+ if ((sizeof({{TYPE}}) <= sizeof(unsigned long))) {
1083
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned long, PyLong_AsUnsignedLong(x))
1084
+ #ifdef HAVE_LONG_LONG
1085
+ } else if ((sizeof({{TYPE}}) <= sizeof(unsigned PY_LONG_LONG))) {
1086
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
1087
+ #endif
1088
+ }
1089
+
1090
+ } else {
1091
+ // signed
1092
+ #if CYTHON_USE_PYLONG_INTERNALS
1093
+ if (__Pyx_PyLong_IsCompact(x)) {
1094
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
1095
+ } else {
1096
+ const digit* digits = __Pyx_PyLong_Digits(x);
1097
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
1098
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
1099
+ {{for _size in (2, 3, 4)}}
1100
+ {{for _case in (-_size, _size)}}
1101
+ case {{_case}}:
1102
+ if ((8 * sizeof({{TYPE}}){{' - 1' if _case < 0 else ''}} > {{_size-1}} * PyLong_SHIFT)) {
1103
+ if ((8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT)) {
1104
+ __PYX_VERIFY_RETURN_INT({{TYPE}}, {{'long' if _case < 0 else 'unsigned long'}}, {{'-(long) ' if _case < 0 else ''}}{{pylong_join(_size, 'digits')}})
1105
+ } else if ((8 * sizeof({{TYPE}}) - 1 > {{_size}} * PyLong_SHIFT)) {
1106
+ return ({{TYPE}}) ({{'((%s)-1)*' % TYPE if _case < 0 else ''}}{{pylong_join(_size, 'digits', TYPE)}});
1107
+ }
1108
+ }
1109
+ break;
1110
+ {{endfor}}
1111
+ {{endfor}}
1112
+ }
1113
+ }
1114
+ #endif
1115
+ if ((sizeof({{TYPE}}) <= sizeof(long))) {
1116
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, long, PyLong_AsLong(x))
1117
+ #ifdef HAVE_LONG_LONG
1118
+ } else if ((sizeof({{TYPE}}) <= sizeof(PY_LONG_LONG))) {
1119
+ __PYX_VERIFY_RETURN_INT_EXC({{TYPE}}, PY_LONG_LONG, PyLong_AsLongLong(x))
1120
+ #endif
1121
+ }
1122
+ }
1123
+
1124
+ // large integer type and no access to PyLong internals => allow for a more expensive conversion
1125
+ {
1126
+ {{TYPE}} val;
1127
+ int ret = -1;
1128
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
1129
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
1130
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
1131
+ if (unlikely(bytes_copied == -1)) {
1132
+ // failed
1133
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
1134
+ goto raise_overflow;
1135
+ } else {
1136
+ ret = 0;
1137
+ }
1138
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
1139
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
1140
+ unsigned char *bytes = (unsigned char *)&val;
1141
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
1142
+ bytes, sizeof(val),
1143
+ is_little, !is_unsigned);
1144
+ #else
1145
+ {{if IS_ENUM}}
1146
+ // The fallback implementation uses math operations like shifting, which do not work well with enums.
1147
+ PyErr_SetString(PyExc_RuntimeError,
1148
+ "_PyLong_AsByteArray() or PyLong_AsNativeBytes() not available, cannot convert large enums");
1149
+ val = ({{TYPE}}) -1;
1150
+ {{else}}
1151
+ // Inefficient copy of bit chunks through the C-API. Probably still better than a "cannot do this" exception.
1152
+ // This is substantially faster in CPython (>30%) than calling "int.to_bytes()" through the C-API.
1153
+ PyObject *v;
1154
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
1155
+ int bits, remaining_bits, is_negative = 0;
1156
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
1157
+
1158
+ // Use exact PyLong to prevent user defined &&/<</etc. implementations (and make Py_SIZE() work below).
1159
+ if (likely(PyLong_CheckExact(x))) {
1160
+ v = __Pyx_NewRef(x);
1161
+ } else {
1162
+ v = PyNumber_Long(x);
1163
+ if (unlikely(!v)) return ({{TYPE}}) -1;
1164
+ assert(PyLong_CheckExact(v));
1165
+ }
1166
+
1167
+ // Misuse Py_False as a quick way to compare to a '0' int object.
1168
+ {
1169
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
1170
+ if (unlikely(result < 0)) {
1171
+ Py_DECREF(v);
1172
+ return ({{TYPE}}) -1;
1173
+ }
1174
+ is_negative = result == 1;
1175
+ }
1176
+
1177
+ if (is_unsigned && unlikely(is_negative)) {
1178
+ Py_DECREF(v);
1179
+ goto raise_neg_overflow;
1180
+ } else if (is_negative) {
1181
+ // bit-invert to make sure we can safely convert it
1182
+ stepval = PyNumber_Invert(v);
1183
+ Py_DECREF(v);
1184
+ if (unlikely(!stepval))
1185
+ return ({{TYPE}}) -1;
1186
+ } else {
1187
+ stepval = v;
1188
+ }
1189
+ v = NULL;
1190
+
1191
+ // Unpack full chunks of bits.
1192
+ val = ({{TYPE}}) 0;
1193
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
1194
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
1195
+ for (bits = 0; bits < (int) sizeof({{TYPE}}) * 8 - chunk_size; bits += chunk_size) {
1196
+ PyObject *tmp, *digit;
1197
+ long idigit;
1198
+
1199
+ digit = PyNumber_And(stepval, mask);
1200
+ if (unlikely(!digit)) goto done;
1201
+
1202
+ idigit = PyLong_AsLong(digit);
1203
+ Py_DECREF(digit);
1204
+ if (unlikely(idigit < 0)) goto done;
1205
+ val |= (({{TYPE}}) idigit) << bits;
1206
+
1207
+ tmp = PyNumber_Rshift(stepval, shift);
1208
+ if (unlikely(!tmp)) goto done;
1209
+ Py_DECREF(stepval); stepval = tmp;
1210
+ }
1211
+
1212
+ Py_DECREF(shift); shift = NULL;
1213
+ Py_DECREF(mask); mask = NULL;
1214
+
1215
+ // Add the last bits and detect overflow.
1216
+ {
1217
+ long idigit = PyLong_AsLong(stepval);
1218
+ if (unlikely(idigit < 0)) goto done;
1219
+ remaining_bits = ((int) sizeof({{TYPE}}) * 8) - bits - (is_unsigned ? 0 : 1);
1220
+ if (unlikely(idigit >= (1L << remaining_bits)))
1221
+ goto raise_overflow;
1222
+ val |= (({{TYPE}}) idigit) << bits;
1223
+ }
1224
+
1225
+ // Handle sign and overflow into sign bit.
1226
+ if (!is_unsigned) {
1227
+ // gcc warns about unsigned (val < 0) => test sign bit instead
1228
+ if (unlikely(val & ((({{TYPE}}) 1) << (sizeof({{TYPE}}) * 8 - 1))))
1229
+ goto raise_overflow;
1230
+ // undo the PyNumber_Invert() above
1231
+ if (is_negative)
1232
+ val = ~val;
1233
+ }
1234
+ ret = 0;
1235
+ done:
1236
+ Py_XDECREF(shift);
1237
+ Py_XDECREF(mask);
1238
+ Py_XDECREF(stepval);
1239
+ {{endif}}
1240
+ #endif
1241
+ if (unlikely(ret))
1242
+ return ({{TYPE}}) -1;
1243
+ return val;
1244
+ }
1245
+
1246
+ raise_overflow:
1247
+ PyErr_SetString(PyExc_OverflowError,
1248
+ "value too large to convert to {{TYPE}}");
1249
+ return ({{TYPE}}) -1;
1250
+
1251
+ raise_neg_overflow:
1252
+ PyErr_SetString(PyExc_OverflowError,
1253
+ "can't convert negative value to {{TYPE}}");
1254
+ return ({{TYPE}}) -1;
1255
+ }
1256
+
1257
+ /////////////// CFuncPtrTypedef.proto ///////////////
1258
+ //@substitute: naming
1259
+
1260
+ #ifndef __PYX_HAVE_RT_CFuncPtrTypedef_$cyversion
1261
+ #define __PYX_HAVE_RT_CFuncPtrTypedef_$cyversion
1262
+ typedef void (*__Pyx_generic_func_pointer_$cyversion)(void);
1263
+ #endif
1264
+
1265
+ /////////////// CFuncPtrToPy.proto ///////////////
1266
+ //@requires: CFuncPtrTypedef
1267
+ //@substitute: naming
1268
+
1269
+ static PyObject *__Pyx_c_func_ptr_to_capsule(__Pyx_generic_func_pointer_$cyversion funcptr, const char* name); /* proto */
1270
+
1271
+ /////////////// CFuncPtrToPy ///////////////
1272
+ //@requires: StringTools.c::IncludeStringH
1273
+ //@substitute: naming
1274
+
1275
+ static void __Pyx_destroy_c_func_ptr_capsule(PyObject *capsule) {
1276
+ void* ptr = PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule));
1277
+ PyMem_Free(ptr);
1278
+ }
1279
+
1280
+ static PyObject *__Pyx_c_func_ptr_to_capsule(__Pyx_generic_func_pointer_$cyversion funcptr, const char* name) {
1281
+ // __Pyx_TEST_large_func_pointers exists just to force an alternative code-path in testing
1282
+ #if defined(__Pyx_TEST_large_func_pointers) && __Pyx_TEST_large_func_pointers
1283
+ if ((1))
1284
+ #else
1285
+ if (sizeof(funcptr) > sizeof(void*))
1286
+ #endif
1287
+ {
1288
+ // The C standard does not guarantee that a function pointer fits inside a regular pointer
1289
+ // (and on some platforms it doesn't). On these, we need to allocate space to store the function pointer
1290
+ __Pyx_generic_func_pointer_$cyversion *copy_into = (__Pyx_generic_func_pointer_$cyversion*) PyMem_Malloc(sizeof(funcptr));
1291
+ *copy_into = funcptr;
1292
+ return PyCapsule_New(copy_into, name, __Pyx_destroy_c_func_ptr_capsule);
1293
+ } else {
1294
+ // on all other platforms (which is the vast majority, since POSIX require a function pointer
1295
+ // can be converted to a void*) we skip the allocation and store directly into the capsule's value.
1296
+ // Use memcpy to copy the data from the function pointer to the void*.
1297
+ // (since just casting is prohibited by standard C, and using unions is prohibited by standard c++)
1298
+ void *copy_into;
1299
+ memcpy((void*)&copy_into, (void*)&funcptr, sizeof(funcptr));
1300
+ return PyCapsule_New(copy_into, name, NULL);
1301
+ }
1302
+ }
1303
+
1304
+ /////////////// CFuncPtrFromPy.proto ///////////////
1305
+ //@requires: CFuncPtrTypedef
1306
+
1307
+ static __Pyx_generic_func_pointer_$cyversion __Pyx_capsule_to_c_func_ptr_$cyversion(PyObject *capsule, const char* name); /* proto */
1308
+
1309
+ /////////////// CFuncPtrFromPy.proto ///////////////
1310
+ //@substitute: naming
1311
+
1312
+ #ifndef __PYX_HAVE_RT_CFuncPtrFromPy_$cyversion
1313
+ #define __PYX_HAVE_RT_CFuncPtrFromPy_$cyversion
1314
+ static __Pyx_generic_func_pointer_$cyversion __Pyx_capsule_to_c_func_ptr_$cyversion(PyObject *capsule, const char* name) {
1315
+ void *data = PyCapsule_GetPointer(capsule, name);
1316
+ __Pyx_generic_func_pointer_$cyversion funcptr;
1317
+ #if defined(__Pyx_TEST_large_func_pointers) && __Pyx_TEST_large_func_pointers
1318
+ if ((1))
1319
+ #else
1320
+ if (sizeof(funcptr) > sizeof(void*))
1321
+ #endif
1322
+ {
1323
+ funcptr = *((__Pyx_generic_func_pointer_$cyversion*)data);
1324
+ } else {
1325
+ memcpy((void*)&funcptr, (void*)&data, sizeof(funcptr));
1326
+ }
1327
+ return funcptr;
1328
+ }
1329
+ #endif