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