Cython 3.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Cython/Build/BuildExecutable.py +169 -0
- Cython/Build/Cache.py +199 -0
- Cython/Build/Cythonize.py +323 -0
- Cython/Build/Dependencies.py +1306 -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 +8 -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 +934 -0
- Cython/Compiler/CmdLine.py +259 -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 +15267 -0
- Cython/Compiler/FlowControl.pxd +97 -0
- Cython/Compiler/FlowControl.py +1455 -0
- Cython/Compiler/FusedNode.py +1002 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +340 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/Main.py +853 -0
- Cython/Compiler/MatchCaseNodes.py +259 -0
- Cython/Compiler/MemoryView.py +922 -0
- Cython/Compiler/ModuleNode.py +4024 -0
- Cython/Compiler/Naming.py +374 -0
- Cython/Compiler/Nodes.py +10826 -0
- Cython/Compiler/Optimize.py +5256 -0
- Cython/Compiler/Options.py +835 -0
- Cython/Compiler/ParseTreeTransforms.pxd +77 -0
- Cython/Compiler/ParseTreeTransforms.py +4509 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +4789 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +5762 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +40 -0
- Cython/Compiler/Scanning.py +577 -0
- Cython/Compiler/StringEncoding.py +347 -0
- Cython/Compiler/Symtab.py +3080 -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.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/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.pxd +24 -0
- Cython/Plex/Actions.py +119 -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.pxd +36 -0
- Cython/Plex/Machines.py +238 -0
- Cython/Plex/Regexps.py +539 -0
- Cython/Plex/Scanners.pxd +47 -0
- Cython/Plex/Scanners.py +360 -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.pyx +237 -0
- Cython/Shadow.py +690 -0
- Cython/Shadow.pyi +521 -0
- Cython/StringIOTree.py +170 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -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 +1002 -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 +118 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2206 -0
- Cython/Utility/CpdefEnums.pyx +103 -0
- Cython/Utility/CppConvert.pyx +279 -0
- Cython/Utility/CppSupport.cpp +143 -0
- Cython/Utility/CythonFunction.c +1794 -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 +809 -0
- Cython/Utility/FunctionArguments.c +965 -0
- Cython/Utility/ImportExport.c +987 -0
- Cython/Utility/Lock.c +136 -0
- Cython/Utility/MemoryView.pxd +187 -0
- Cython/Utility/MemoryView.pyx +1481 -0
- Cython/Utility/MemoryView_C.c +1046 -0
- Cython/Utility/ModuleSetupCode.c +3059 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3342 -0
- Cython/Utility/Optimize.c +1589 -0
- Cython/Utility/Overflow.c +404 -0
- Cython/Utility/Printing.c +86 -0
- Cython/Utility/Profile.c +709 -0
- Cython/Utility/StringTools.c +1259 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1284 -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.py +687 -0
- Cython/__init__.py +10 -0
- Cython/__init__.pyi +7 -0
- Cython/py.typed +0 -0
- cython-3.1.0.dist-info/COPYING.txt +19 -0
- cython-3.1.0.dist-info/LICENSE.txt +176 -0
- cython-3.1.0.dist-info/METADATA +636 -0
- cython-3.1.0.dist-info/RECORD +316 -0
- cython-3.1.0.dist-info/WHEEL +5 -0
- cython-3.1.0.dist-info/entry_points.txt +4 -0
- cython-3.1.0.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,1589 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Optional optimisations of built-in functions and methods.
|
|
3
|
+
*
|
|
4
|
+
* Required replacements of builtins are in Builtins.c.
|
|
5
|
+
*
|
|
6
|
+
* General object operations and protocols are in ObjectHandling.c.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/////////////// append.proto ///////////////
|
|
10
|
+
|
|
11
|
+
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); /*proto*/
|
|
12
|
+
|
|
13
|
+
/////////////// append ///////////////
|
|
14
|
+
//@requires: ListAppend
|
|
15
|
+
//@requires: ObjectHandling.c::PyObjectCallMethod1
|
|
16
|
+
|
|
17
|
+
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
|
|
18
|
+
if (likely(PyList_CheckExact(L))) {
|
|
19
|
+
if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
|
|
20
|
+
} else {
|
|
21
|
+
PyObject* retval = __Pyx_PyObject_CallMethod1(L, PYIDENT("append"), x);
|
|
22
|
+
if (unlikely(!retval))
|
|
23
|
+
return -1;
|
|
24
|
+
Py_DECREF(retval);
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/////////////// ListAppend.proto ///////////////
|
|
30
|
+
|
|
31
|
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
|
|
32
|
+
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
|
|
33
|
+
PyListObject* L = (PyListObject*) list;
|
|
34
|
+
Py_ssize_t len = Py_SIZE(list);
|
|
35
|
+
if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
|
|
36
|
+
Py_INCREF(x);
|
|
37
|
+
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
|
|
38
|
+
// In Py3.13a1, PyList_SET_ITEM() checks that the end index is lower than the current size.
|
|
39
|
+
// However, extending the size *before* setting the value would not be correct,
|
|
40
|
+
// so we cannot call PyList_SET_ITEM().
|
|
41
|
+
L->ob_item[len] = x;
|
|
42
|
+
#else
|
|
43
|
+
PyList_SET_ITEM(list, len, x);
|
|
44
|
+
#endif
|
|
45
|
+
__Pyx_SET_SIZE(list, len + 1);
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
return PyList_Append(list, x);
|
|
49
|
+
}
|
|
50
|
+
#else
|
|
51
|
+
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
/////////////// ListCompAppend.proto ///////////////
|
|
55
|
+
|
|
56
|
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
|
|
57
|
+
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
|
|
58
|
+
PyListObject* L = (PyListObject*) list;
|
|
59
|
+
Py_ssize_t len = Py_SIZE(list);
|
|
60
|
+
if (likely(L->allocated > len)) {
|
|
61
|
+
Py_INCREF(x);
|
|
62
|
+
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
|
|
63
|
+
// In Py3.13a1, PyList_SET_ITEM() checks that the end index is lower than the current size.
|
|
64
|
+
// However, extending the size *before* setting the value would not be correct,
|
|
65
|
+
// so we cannot call PyList_SET_ITEM().
|
|
66
|
+
L->ob_item[len] = x;
|
|
67
|
+
#else
|
|
68
|
+
PyList_SET_ITEM(list, len, x);
|
|
69
|
+
#endif
|
|
70
|
+
__Pyx_SET_SIZE(list, len + 1);
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
return PyList_Append(list, x);
|
|
74
|
+
}
|
|
75
|
+
#else
|
|
76
|
+
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
//////////////////// ListExtend.proto ////////////////////
|
|
80
|
+
|
|
81
|
+
static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
|
|
82
|
+
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00a2
|
|
83
|
+
return PyList_Extend(L, v);
|
|
84
|
+
#elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
|
|
85
|
+
PyObject* none = _PyList_Extend((PyListObject*)L, v);
|
|
86
|
+
if (unlikely(!none))
|
|
87
|
+
return -1;
|
|
88
|
+
Py_DECREF(none);
|
|
89
|
+
return 0;
|
|
90
|
+
#else
|
|
91
|
+
return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
|
|
92
|
+
#endif
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/////////////// pop.proto ///////////////
|
|
96
|
+
|
|
97
|
+
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L); /*proto*/
|
|
98
|
+
|
|
99
|
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
100
|
+
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L); /*proto*/
|
|
101
|
+
#define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ? \
|
|
102
|
+
__Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L))
|
|
103
|
+
|
|
104
|
+
#else
|
|
105
|
+
#define __Pyx_PyList_Pop(L) __Pyx__PyObject_Pop(L)
|
|
106
|
+
#define __Pyx_PyObject_Pop(L) __Pyx__PyObject_Pop(L)
|
|
107
|
+
#endif
|
|
108
|
+
|
|
109
|
+
/////////////// pop ///////////////
|
|
110
|
+
//@requires: ObjectHandling.c::PyObjectCallMethod0
|
|
111
|
+
|
|
112
|
+
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
|
|
113
|
+
if (__Pyx_IS_TYPE(L, &PySet_Type)) {
|
|
114
|
+
return PySet_Pop(L);
|
|
115
|
+
}
|
|
116
|
+
return __Pyx_PyObject_CallMethod0(L, PYIDENT("pop"));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
120
|
+
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
|
|
121
|
+
/* Check that both the size is positive and no reallocation shrinking needs to be done. */
|
|
122
|
+
if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
|
|
123
|
+
__Pyx_SET_SIZE(L, Py_SIZE(L) - 1);
|
|
124
|
+
return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
|
|
125
|
+
}
|
|
126
|
+
return CALL_UNBOUND_METHOD(PyList_Type, "pop", L);
|
|
127
|
+
}
|
|
128
|
+
#endif
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
/////////////// pop_index.proto ///////////////
|
|
132
|
+
|
|
133
|
+
static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix); /*proto*/
|
|
134
|
+
static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix); /*proto*/
|
|
135
|
+
|
|
136
|
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
137
|
+
static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix); /*proto*/
|
|
138
|
+
|
|
139
|
+
#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
|
|
140
|
+
(likely(PyList_CheckExact(L) && __Pyx_fits_Py_ssize_t(ix, type, is_signed))) ? \
|
|
141
|
+
__Pyx__PyList_PopIndex(L, py_ix, ix) : ( \
|
|
142
|
+
(unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
|
|
143
|
+
__Pyx__PyObject_PopIndex(L, py_ix)))
|
|
144
|
+
|
|
145
|
+
#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
|
|
146
|
+
__Pyx_fits_Py_ssize_t(ix, type, is_signed) ? \
|
|
147
|
+
__Pyx__PyList_PopIndex(L, py_ix, ix) : ( \
|
|
148
|
+
(unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
|
|
149
|
+
__Pyx__PyObject_PopIndex(L, py_ix)))
|
|
150
|
+
|
|
151
|
+
#else
|
|
152
|
+
|
|
153
|
+
#define __Pyx_PyList_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) \
|
|
154
|
+
__Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func)
|
|
155
|
+
|
|
156
|
+
#define __Pyx_PyObject_PopIndex(L, py_ix, ix, is_signed, type, to_py_func) ( \
|
|
157
|
+
(unlikely((py_ix) == Py_None)) ? __Pyx__PyObject_PopNewIndex(L, to_py_func(ix)) : \
|
|
158
|
+
__Pyx__PyObject_PopIndex(L, py_ix))
|
|
159
|
+
#endif
|
|
160
|
+
|
|
161
|
+
/////////////// pop_index ///////////////
|
|
162
|
+
//@requires: ObjectHandling.c::PyObjectCallMethod1
|
|
163
|
+
|
|
164
|
+
static PyObject* __Pyx__PyObject_PopNewIndex(PyObject* L, PyObject* py_ix) {
|
|
165
|
+
PyObject *r;
|
|
166
|
+
if (unlikely(!py_ix)) return NULL;
|
|
167
|
+
r = __Pyx__PyObject_PopIndex(L, py_ix);
|
|
168
|
+
Py_DECREF(py_ix);
|
|
169
|
+
return r;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static PyObject* __Pyx__PyObject_PopIndex(PyObject* L, PyObject* py_ix) {
|
|
173
|
+
return __Pyx_PyObject_CallMethod1(L, PYIDENT("pop"), py_ix);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
177
|
+
static PyObject* __Pyx__PyList_PopIndex(PyObject* L, PyObject* py_ix, Py_ssize_t ix) {
|
|
178
|
+
Py_ssize_t size = PyList_GET_SIZE(L);
|
|
179
|
+
if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
|
|
180
|
+
Py_ssize_t cix = ix;
|
|
181
|
+
if (cix < 0) {
|
|
182
|
+
cix += size;
|
|
183
|
+
}
|
|
184
|
+
if (likely(__Pyx_is_valid_index(cix, size))) {
|
|
185
|
+
PyObject* v = PyList_GET_ITEM(L, cix);
|
|
186
|
+
__Pyx_SET_SIZE(L, Py_SIZE(L) - 1);
|
|
187
|
+
size -= 1;
|
|
188
|
+
memmove(&PyList_GET_ITEM(L, cix), &PyList_GET_ITEM(L, cix+1), (size_t)(size-cix)*sizeof(PyObject*));
|
|
189
|
+
return v;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (py_ix == Py_None) {
|
|
193
|
+
return __Pyx__PyObject_PopNewIndex(L, PyLong_FromSsize_t(ix));
|
|
194
|
+
} else {
|
|
195
|
+
return __Pyx__PyObject_PopIndex(L, py_ix);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
#endif
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
/////////////// dict_getitem_default.proto ///////////////
|
|
202
|
+
|
|
203
|
+
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /*proto*/
|
|
204
|
+
|
|
205
|
+
/////////////// dict_getitem_default ///////////////
|
|
206
|
+
|
|
207
|
+
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
|
|
208
|
+
PyObject* value;
|
|
209
|
+
#if !CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000
|
|
210
|
+
value = PyDict_GetItemWithError(d, key);
|
|
211
|
+
if (unlikely(!value)) {
|
|
212
|
+
if (unlikely(PyErr_Occurred()))
|
|
213
|
+
return NULL;
|
|
214
|
+
value = default_value;
|
|
215
|
+
}
|
|
216
|
+
Py_INCREF(value);
|
|
217
|
+
// avoid C compiler warning about unused utility functions
|
|
218
|
+
if ((1));
|
|
219
|
+
#else
|
|
220
|
+
if (PyBytes_CheckExact(key) || PyUnicode_CheckExact(key) || PyLong_CheckExact(key)) {
|
|
221
|
+
/* these presumably have safe hash functions */
|
|
222
|
+
value = PyDict_GetItem(d, key);
|
|
223
|
+
if (unlikely(!value)) {
|
|
224
|
+
value = default_value;
|
|
225
|
+
}
|
|
226
|
+
Py_INCREF(value);
|
|
227
|
+
}
|
|
228
|
+
#endif
|
|
229
|
+
else {
|
|
230
|
+
if (default_value == Py_None)
|
|
231
|
+
value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key);
|
|
232
|
+
else
|
|
233
|
+
value = CALL_UNBOUND_METHOD(PyDict_Type, "get", d, key, default_value);
|
|
234
|
+
}
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
/////////////// dict_setdefault.proto ///////////////
|
|
240
|
+
|
|
241
|
+
static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type); /*proto*/
|
|
242
|
+
|
|
243
|
+
/////////////// dict_setdefault ///////////////
|
|
244
|
+
|
|
245
|
+
static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value,
|
|
246
|
+
int is_safe_type) {
|
|
247
|
+
PyObject* value;
|
|
248
|
+
CYTHON_MAYBE_UNUSED_VAR(is_safe_type);
|
|
249
|
+
#if CYTHON_COMPILING_IN_LIMITED_API
|
|
250
|
+
value = PyObject_CallMethod(d, "setdefault", "OO", key, default_value);
|
|
251
|
+
#elif PY_VERSION_HEX >= 0x030d0000
|
|
252
|
+
PyDict_SetDefaultRef(d, key, default_value, &value);
|
|
253
|
+
#else
|
|
254
|
+
value = PyDict_SetDefault(d, key, default_value);
|
|
255
|
+
if (unlikely(!value)) return NULL;
|
|
256
|
+
Py_INCREF(value);
|
|
257
|
+
#endif
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
/////////////// py_dict_clear.proto ///////////////
|
|
263
|
+
|
|
264
|
+
#define __Pyx_PyDict_Clear(d) (PyDict_Clear(d), 0)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
/////////////// py_dict_pop.proto ///////////////
|
|
268
|
+
|
|
269
|
+
static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value); /*proto*/
|
|
270
|
+
|
|
271
|
+
/////////////// py_dict_pop ///////////////
|
|
272
|
+
|
|
273
|
+
static CYTHON_INLINE PyObject *__Pyx_PyDict_Pop(PyObject *d, PyObject *key, PyObject *default_value) {
|
|
274
|
+
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)
|
|
275
|
+
PyObject *value;
|
|
276
|
+
if (PyDict_Pop(d, key, &value) == 0) {
|
|
277
|
+
if (default_value) {
|
|
278
|
+
Py_INCREF(default_value);
|
|
279
|
+
} else {
|
|
280
|
+
PyErr_SetObject(PyExc_KeyError, key);
|
|
281
|
+
}
|
|
282
|
+
value = default_value;
|
|
283
|
+
}
|
|
284
|
+
// On error, PyDict_Pop() returns -1 and sets value to NULL (our own exception return value).
|
|
285
|
+
return value;
|
|
286
|
+
#elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
|
|
287
|
+
return _PyDict_Pop(d, key, default_value);
|
|
288
|
+
#else
|
|
289
|
+
if (default_value) {
|
|
290
|
+
return CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key, default_value);
|
|
291
|
+
} else {
|
|
292
|
+
return CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key);
|
|
293
|
+
}
|
|
294
|
+
#endif
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
/////////////// py_dict_pop_ignore.proto ///////////////
|
|
299
|
+
|
|
300
|
+
static CYTHON_INLINE int __Pyx_PyDict_Pop_ignore(PyObject *d, PyObject *key, PyObject *default_value); /*proto*/
|
|
301
|
+
|
|
302
|
+
/////////////// py_dict_pop_ignore ///////////////
|
|
303
|
+
|
|
304
|
+
static CYTHON_INLINE int __Pyx_PyDict_Pop_ignore(PyObject *d, PyObject *key, PyObject *default_value) {
|
|
305
|
+
// We take the "default_value" as argument to avoid "unused" warnings, but we ignore it here.
|
|
306
|
+
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d00A2 || defined(PyDict_Pop)
|
|
307
|
+
int result = PyDict_Pop(d, key, NULL);
|
|
308
|
+
CYTHON_UNUSED_VAR(default_value);
|
|
309
|
+
return (unlikely(result == -1)) ? -1 : 0;
|
|
310
|
+
#else
|
|
311
|
+
PyObject *value;
|
|
312
|
+
CYTHON_UNUSED_VAR(default_value);
|
|
313
|
+
|
|
314
|
+
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
|
|
315
|
+
value = _PyDict_Pop(d, key, Py_None);
|
|
316
|
+
#else
|
|
317
|
+
value = CALL_UNBOUND_METHOD(PyDict_Type, "pop", d, key, Py_None);
|
|
318
|
+
#endif
|
|
319
|
+
|
|
320
|
+
if (unlikely(value == NULL))
|
|
321
|
+
return -1;
|
|
322
|
+
Py_DECREF(value);
|
|
323
|
+
return 0;
|
|
324
|
+
#endif
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
/////////////// dict_iter.proto ///////////////
|
|
329
|
+
|
|
330
|
+
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
|
|
331
|
+
Py_ssize_t* p_orig_length, int* p_is_dict);
|
|
332
|
+
static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
|
|
333
|
+
PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);
|
|
334
|
+
|
|
335
|
+
/////////////// dict_iter ///////////////
|
|
336
|
+
//@requires: ObjectHandling.c::UnpackTuple2
|
|
337
|
+
//@requires: ObjectHandling.c::IterFinish
|
|
338
|
+
//@requires: ObjectHandling.c::PyObjectCallMethod0
|
|
339
|
+
|
|
340
|
+
#if CYTHON_COMPILING_IN_PYPY
|
|
341
|
+
#include <string.h>
|
|
342
|
+
#endif
|
|
343
|
+
|
|
344
|
+
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
|
|
345
|
+
Py_ssize_t* p_orig_length, int* p_source_is_dict) {
|
|
346
|
+
is_dict = is_dict || likely(PyDict_CheckExact(iterable));
|
|
347
|
+
*p_source_is_dict = is_dict;
|
|
348
|
+
if (is_dict) {
|
|
349
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
350
|
+
*p_orig_length = PyDict_Size(iterable);
|
|
351
|
+
Py_INCREF(iterable);
|
|
352
|
+
return iterable;
|
|
353
|
+
#else
|
|
354
|
+
// On PyPy3, we need to translate manually a few method names.
|
|
355
|
+
// This logic is not needed on CPython thanks to the fast case above.
|
|
356
|
+
static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL;
|
|
357
|
+
PyObject **pp = NULL;
|
|
358
|
+
if (method_name) {
|
|
359
|
+
const char *name = PyUnicode_AsUTF8(method_name);
|
|
360
|
+
if (strcmp(name, "iteritems") == 0) pp = &py_items;
|
|
361
|
+
else if (strcmp(name, "iterkeys") == 0) pp = &py_keys;
|
|
362
|
+
else if (strcmp(name, "itervalues") == 0) pp = &py_values;
|
|
363
|
+
if (pp) {
|
|
364
|
+
if (!*pp) {
|
|
365
|
+
*pp = PyUnicode_FromString(name + 4);
|
|
366
|
+
if (!*pp)
|
|
367
|
+
return NULL;
|
|
368
|
+
}
|
|
369
|
+
method_name = *pp;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
#endif
|
|
373
|
+
}
|
|
374
|
+
*p_orig_length = 0;
|
|
375
|
+
if (method_name) {
|
|
376
|
+
PyObject* iter;
|
|
377
|
+
iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
|
|
378
|
+
if (!iterable)
|
|
379
|
+
return NULL;
|
|
380
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
381
|
+
if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
|
|
382
|
+
return iterable;
|
|
383
|
+
#endif
|
|
384
|
+
iter = PyObject_GetIter(iterable);
|
|
385
|
+
Py_DECREF(iterable);
|
|
386
|
+
return iter;
|
|
387
|
+
}
|
|
388
|
+
return PyObject_GetIter(iterable);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
393
|
+
static CYTHON_INLINE int __Pyx_dict_iter_next_source_is_dict(
|
|
394
|
+
PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
|
|
395
|
+
PyObject** pkey, PyObject** pvalue, PyObject** pitem) {
|
|
396
|
+
PyObject *key, *value;
|
|
397
|
+
if (unlikely(orig_length != PyDict_Size(iter_obj))) {
|
|
398
|
+
PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
|
|
399
|
+
return -1;
|
|
400
|
+
}
|
|
401
|
+
if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
|
|
402
|
+
return 0;
|
|
403
|
+
}
|
|
404
|
+
if (pitem) {
|
|
405
|
+
PyObject* tuple = PyTuple_New(2);
|
|
406
|
+
if (unlikely(!tuple)) {
|
|
407
|
+
return -1;
|
|
408
|
+
}
|
|
409
|
+
Py_INCREF(key);
|
|
410
|
+
Py_INCREF(value);
|
|
411
|
+
#if CYTHON_ASSUME_SAFE_MACROS
|
|
412
|
+
PyTuple_SET_ITEM(tuple, 0, key);
|
|
413
|
+
PyTuple_SET_ITEM(tuple, 1, value);
|
|
414
|
+
#else
|
|
415
|
+
if (unlikely(PyTuple_SetItem(tuple, 0, key) < 0)) {
|
|
416
|
+
// decref value; PyTuple_SetItem decrefs key on failure
|
|
417
|
+
Py_DECREF(value);
|
|
418
|
+
Py_DECREF(tuple);
|
|
419
|
+
return -1;
|
|
420
|
+
}
|
|
421
|
+
if (unlikely(PyTuple_SetItem(tuple, 1, value) < 0)) {
|
|
422
|
+
// PyTuple_SetItem decrefs value on failure
|
|
423
|
+
Py_DECREF(tuple);
|
|
424
|
+
return -1;
|
|
425
|
+
}
|
|
426
|
+
#endif
|
|
427
|
+
*pitem = tuple;
|
|
428
|
+
} else {
|
|
429
|
+
if (pkey) {
|
|
430
|
+
Py_INCREF(key);
|
|
431
|
+
*pkey = key;
|
|
432
|
+
}
|
|
433
|
+
if (pvalue) {
|
|
434
|
+
Py_INCREF(value);
|
|
435
|
+
*pvalue = value;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return 1;
|
|
439
|
+
}
|
|
440
|
+
#endif
|
|
441
|
+
|
|
442
|
+
static CYTHON_INLINE int __Pyx_dict_iter_next(
|
|
443
|
+
PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
|
|
444
|
+
PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
|
|
445
|
+
PyObject* next_item;
|
|
446
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
447
|
+
if (source_is_dict) {
|
|
448
|
+
int result;
|
|
449
|
+
#if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API
|
|
450
|
+
Py_BEGIN_CRITICAL_SECTION(iter_obj);
|
|
451
|
+
#endif
|
|
452
|
+
result = __Pyx_dict_iter_next_source_is_dict(iter_obj, orig_length, ppos, pkey, pvalue, pitem);
|
|
453
|
+
#if PY_VERSION_HEX >= 0x030d0000 && !CYTHON_COMPILING_IN_LIMITED_API
|
|
454
|
+
Py_END_CRITICAL_SECTION();
|
|
455
|
+
#endif
|
|
456
|
+
return result;
|
|
457
|
+
} else if (PyTuple_CheckExact(iter_obj)) {
|
|
458
|
+
Py_ssize_t pos = *ppos;
|
|
459
|
+
Py_ssize_t tuple_size = __Pyx_PyTuple_GET_SIZE(iter_obj);
|
|
460
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
461
|
+
if (unlikely(tuple_size < 0)) return -1;
|
|
462
|
+
#endif
|
|
463
|
+
if (unlikely(pos >= tuple_size)) return 0;
|
|
464
|
+
*ppos = pos + 1;
|
|
465
|
+
#if CYTHON_ASSUME_SAFE_MACROS
|
|
466
|
+
next_item = PyTuple_GET_ITEM(iter_obj, pos);
|
|
467
|
+
#else
|
|
468
|
+
next_item = PyTuple_GetItem(iter_obj, pos);
|
|
469
|
+
if (unlikely(!next_item)) return -1;
|
|
470
|
+
#endif
|
|
471
|
+
Py_INCREF(next_item);
|
|
472
|
+
} else if (PyList_CheckExact(iter_obj)) {
|
|
473
|
+
Py_ssize_t pos = *ppos;
|
|
474
|
+
Py_ssize_t list_size = __Pyx_PyList_GET_SIZE(iter_obj);
|
|
475
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
476
|
+
if (unlikely(list_size < 0)) return -1;
|
|
477
|
+
#endif
|
|
478
|
+
if (unlikely(pos >= list_size)) return 0;
|
|
479
|
+
*ppos = pos + 1;
|
|
480
|
+
#if CYTHON_AVOID_THREAD_UNSAFE_BORROWED_REFS
|
|
481
|
+
next_item = PyList_GetItemRef(iter_obj, pos);
|
|
482
|
+
if (unlikely(!next_item)) return -1;
|
|
483
|
+
#elif CYTHON_ASSUME_SAFE_MACROS
|
|
484
|
+
next_item = PyList_GET_ITEM(iter_obj, pos);
|
|
485
|
+
Py_INCREF(next_item);
|
|
486
|
+
#else
|
|
487
|
+
next_item = PyList_GetItem(iter_obj, pos);
|
|
488
|
+
if (unlikely(!next_item)) return -1;
|
|
489
|
+
Py_INCREF(next_item);
|
|
490
|
+
#endif
|
|
491
|
+
} else
|
|
492
|
+
#endif
|
|
493
|
+
{
|
|
494
|
+
next_item = PyIter_Next(iter_obj);
|
|
495
|
+
if (unlikely(!next_item)) {
|
|
496
|
+
return __Pyx_IterFinish();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (pitem) {
|
|
500
|
+
*pitem = next_item;
|
|
501
|
+
} else if (pkey && pvalue) {
|
|
502
|
+
if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
|
|
503
|
+
return -1;
|
|
504
|
+
} else if (pkey) {
|
|
505
|
+
*pkey = next_item;
|
|
506
|
+
} else {
|
|
507
|
+
*pvalue = next_item;
|
|
508
|
+
}
|
|
509
|
+
return 1;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
/////////////// set_iter.proto ///////////////
|
|
514
|
+
|
|
515
|
+
static CYTHON_INLINE PyObject* __Pyx_set_iterator(PyObject* iterable, int is_set,
|
|
516
|
+
Py_ssize_t* p_orig_length, int* p_source_is_set); /*proto*/
|
|
517
|
+
static CYTHON_INLINE int __Pyx_set_iter_next(
|
|
518
|
+
PyObject* iter_obj, Py_ssize_t orig_length,
|
|
519
|
+
Py_ssize_t* ppos, PyObject **value,
|
|
520
|
+
int source_is_set); /*proto*/
|
|
521
|
+
|
|
522
|
+
/////////////// set_iter ///////////////
|
|
523
|
+
//@requires: ObjectHandling.c::IterFinish
|
|
524
|
+
|
|
525
|
+
static CYTHON_INLINE PyObject* __Pyx_set_iterator(PyObject* iterable, int is_set,
|
|
526
|
+
Py_ssize_t* p_orig_length, int* p_source_is_set) {
|
|
527
|
+
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
|
|
528
|
+
is_set = is_set || likely(PySet_CheckExact(iterable) || PyFrozenSet_CheckExact(iterable));
|
|
529
|
+
*p_source_is_set = is_set;
|
|
530
|
+
if (likely(is_set)) {
|
|
531
|
+
*p_orig_length = PySet_Size(iterable);
|
|
532
|
+
Py_INCREF(iterable);
|
|
533
|
+
return iterable;
|
|
534
|
+
}
|
|
535
|
+
#else
|
|
536
|
+
CYTHON_UNUSED_VAR(is_set);
|
|
537
|
+
*p_source_is_set = 0;
|
|
538
|
+
#endif
|
|
539
|
+
*p_orig_length = 0;
|
|
540
|
+
return PyObject_GetIter(iterable);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
static CYTHON_INLINE int __Pyx_set_iter_next(
|
|
544
|
+
PyObject* iter_obj, Py_ssize_t orig_length,
|
|
545
|
+
Py_ssize_t* ppos, PyObject **value,
|
|
546
|
+
int source_is_set) {
|
|
547
|
+
if (!CYTHON_COMPILING_IN_CPYTHON || PY_VERSION_HEX >= 0x030d0000 || unlikely(!source_is_set)) {
|
|
548
|
+
*value = PyIter_Next(iter_obj);
|
|
549
|
+
if (unlikely(!*value)) {
|
|
550
|
+
return __Pyx_IterFinish();
|
|
551
|
+
}
|
|
552
|
+
CYTHON_UNUSED_VAR(orig_length);
|
|
553
|
+
CYTHON_UNUSED_VAR(ppos);
|
|
554
|
+
return 1;
|
|
555
|
+
}
|
|
556
|
+
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000
|
|
557
|
+
if (unlikely(PySet_GET_SIZE(iter_obj) != orig_length)) {
|
|
558
|
+
PyErr_SetString(
|
|
559
|
+
PyExc_RuntimeError,
|
|
560
|
+
"set changed size during iteration");
|
|
561
|
+
return -1;
|
|
562
|
+
}
|
|
563
|
+
{
|
|
564
|
+
Py_hash_t hash;
|
|
565
|
+
int ret = _PySet_NextEntry(iter_obj, ppos, value, &hash);
|
|
566
|
+
// CPython does not raise errors here, only if !isinstance(iter_obj, set/frozenset)
|
|
567
|
+
assert (ret != -1);
|
|
568
|
+
if (likely(ret)) {
|
|
569
|
+
Py_INCREF(*value);
|
|
570
|
+
return 1;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
#endif
|
|
574
|
+
return 0;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/////////////// py_set_discard_unhashable ///////////////
|
|
578
|
+
//@requires: Builtins.c::pyfrozenset_new
|
|
579
|
+
|
|
580
|
+
static int __Pyx_PySet_DiscardUnhashable(PyObject *set, PyObject *key) {
|
|
581
|
+
PyObject *tmpkey;
|
|
582
|
+
int rv;
|
|
583
|
+
|
|
584
|
+
if (likely(!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)))
|
|
585
|
+
return -1;
|
|
586
|
+
PyErr_Clear();
|
|
587
|
+
tmpkey = __Pyx_PyFrozenSet_New(key);
|
|
588
|
+
if (tmpkey == NULL)
|
|
589
|
+
return -1;
|
|
590
|
+
rv = PySet_Discard(set, tmpkey);
|
|
591
|
+
Py_DECREF(tmpkey);
|
|
592
|
+
return rv;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
/////////////// py_set_discard.proto ///////////////
|
|
597
|
+
|
|
598
|
+
static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key); /*proto*/
|
|
599
|
+
|
|
600
|
+
/////////////// py_set_discard ///////////////
|
|
601
|
+
//@requires: py_set_discard_unhashable
|
|
602
|
+
|
|
603
|
+
static CYTHON_INLINE int __Pyx_PySet_Discard(PyObject *set, PyObject *key) {
|
|
604
|
+
int found = PySet_Discard(set, key);
|
|
605
|
+
// Convert *key* to frozenset if necessary
|
|
606
|
+
if (unlikely(found < 0)) {
|
|
607
|
+
found = __Pyx_PySet_DiscardUnhashable(set, key);
|
|
608
|
+
}
|
|
609
|
+
// note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
|
|
610
|
+
return found;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
/////////////// py_set_remove.proto ///////////////
|
|
615
|
+
|
|
616
|
+
static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key); /*proto*/
|
|
617
|
+
|
|
618
|
+
/////////////// py_set_remove ///////////////
|
|
619
|
+
//@requires: py_set_discard_unhashable
|
|
620
|
+
|
|
621
|
+
static int __Pyx_PySet_RemoveNotFound(PyObject *set, PyObject *key, int found) {
|
|
622
|
+
// Convert *key* to frozenset if necessary
|
|
623
|
+
if (unlikely(found < 0)) {
|
|
624
|
+
found = __Pyx_PySet_DiscardUnhashable(set, key);
|
|
625
|
+
}
|
|
626
|
+
if (likely(found == 0)) {
|
|
627
|
+
// Not found
|
|
628
|
+
PyObject *tup;
|
|
629
|
+
tup = PyTuple_Pack(1, key);
|
|
630
|
+
if (!tup)
|
|
631
|
+
return -1;
|
|
632
|
+
PyErr_SetObject(PyExc_KeyError, tup);
|
|
633
|
+
Py_DECREF(tup);
|
|
634
|
+
return -1;
|
|
635
|
+
}
|
|
636
|
+
// note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
|
|
637
|
+
return found;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
static CYTHON_INLINE int __Pyx_PySet_Remove(PyObject *set, PyObject *key) {
|
|
641
|
+
int found = PySet_Discard(set, key);
|
|
642
|
+
if (unlikely(found != 1)) {
|
|
643
|
+
// note: returns -1 on error, 0 (not found) or 1 (found) otherwise => error check for -1 or < 0 works
|
|
644
|
+
return __Pyx_PySet_RemoveNotFound(set, key, found);
|
|
645
|
+
}
|
|
646
|
+
return 0;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
/////////////// unicode_iter.proto ///////////////
|
|
651
|
+
|
|
652
|
+
static CYTHON_INLINE int __Pyx_init_unicode_iteration(
|
|
653
|
+
PyObject* ustring, Py_ssize_t *length, void** data, int *kind); /* proto */
|
|
654
|
+
|
|
655
|
+
/////////////// unicode_iter ///////////////
|
|
656
|
+
|
|
657
|
+
static CYTHON_INLINE int __Pyx_init_unicode_iteration(
|
|
658
|
+
PyObject* ustring, Py_ssize_t *length, void** data, int *kind) {
|
|
659
|
+
#if CYTHON_COMPILING_IN_LIMITED_API
|
|
660
|
+
// In the limited API we just point data to the unicode object
|
|
661
|
+
*kind = 0;
|
|
662
|
+
*length = PyUnicode_GetLength(ustring);
|
|
663
|
+
*data = (void*)ustring;
|
|
664
|
+
#else
|
|
665
|
+
if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return -1;
|
|
666
|
+
*kind = PyUnicode_KIND(ustring);
|
|
667
|
+
*length = PyUnicode_GET_LENGTH(ustring);
|
|
668
|
+
*data = PyUnicode_DATA(ustring);
|
|
669
|
+
#endif
|
|
670
|
+
return 0;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/////////////// pyobject_as_double.proto ///////////////
|
|
674
|
+
|
|
675
|
+
static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
|
|
676
|
+
|
|
677
|
+
#if CYTHON_COMPILING_IN_PYPY
|
|
678
|
+
#define __Pyx_PyObject_AsDouble(obj) \
|
|
679
|
+
(likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \
|
|
680
|
+
likely(PyLong_CheckExact(obj)) ? \
|
|
681
|
+
PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
|
|
682
|
+
#else
|
|
683
|
+
#define __Pyx_PyObject_AsDouble(obj) \
|
|
684
|
+
((likely(PyFloat_CheckExact(obj))) ? __Pyx_PyFloat_AS_DOUBLE(obj) : \
|
|
685
|
+
likely(PyLong_CheckExact(obj)) ? \
|
|
686
|
+
PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
|
|
687
|
+
#endif
|
|
688
|
+
|
|
689
|
+
/////////////// pyobject_as_double ///////////////
|
|
690
|
+
//@requires: pybytes_as_double
|
|
691
|
+
//@requires: pyunicode_as_double
|
|
692
|
+
//@requires: ObjectHandling.c::PyObjectCallOneArg
|
|
693
|
+
|
|
694
|
+
static double __Pyx__PyObject_AsDouble(PyObject* obj) {
|
|
695
|
+
if (PyUnicode_CheckExact(obj)) {
|
|
696
|
+
return __Pyx_PyUnicode_AsDouble(obj);
|
|
697
|
+
} else if (PyBytes_CheckExact(obj)) {
|
|
698
|
+
return __Pyx_PyBytes_AsDouble(obj);
|
|
699
|
+
} else if (PyByteArray_CheckExact(obj)) {
|
|
700
|
+
return __Pyx_PyByteArray_AsDouble(obj);
|
|
701
|
+
} else {
|
|
702
|
+
PyObject* float_value;
|
|
703
|
+
#if !CYTHON_USE_TYPE_SLOTS
|
|
704
|
+
float_value = PyNumber_Float(obj); if ((0)) goto bad;
|
|
705
|
+
// avoid "unused" warnings
|
|
706
|
+
(void)__Pyx_PyObject_CallOneArg;
|
|
707
|
+
#else
|
|
708
|
+
PyNumberMethods *nb = Py_TYPE(obj)->tp_as_number;
|
|
709
|
+
if (likely(nb) && likely(nb->nb_float)) {
|
|
710
|
+
float_value = nb->nb_float(obj);
|
|
711
|
+
if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
|
|
712
|
+
__Pyx_TypeName float_value_type_name = __Pyx_PyType_GetFullyQualifiedName(Py_TYPE(float_value));
|
|
713
|
+
PyErr_Format(PyExc_TypeError,
|
|
714
|
+
"__float__ returned non-float (type " __Pyx_FMT_TYPENAME ")",
|
|
715
|
+
float_value_type_name);
|
|
716
|
+
__Pyx_DECREF_TypeName(float_value_type_name);
|
|
717
|
+
Py_DECREF(float_value);
|
|
718
|
+
goto bad;
|
|
719
|
+
}
|
|
720
|
+
} else {
|
|
721
|
+
float_value = __Pyx_PyObject_CallOneArg((PyObject*)&PyFloat_Type, obj);
|
|
722
|
+
}
|
|
723
|
+
#endif
|
|
724
|
+
if (likely(float_value)) {
|
|
725
|
+
double value = __Pyx_PyFloat_AS_DOUBLE(float_value);
|
|
726
|
+
Py_DECREF(float_value);
|
|
727
|
+
return value;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
bad:
|
|
731
|
+
return (double)-1;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
/////////////// pyunicode_as_double.proto ///////////////
|
|
736
|
+
|
|
737
|
+
static CYTHON_INLINE double __Pyx_PyUnicode_AsDouble(PyObject *obj);/*proto*/
|
|
738
|
+
|
|
739
|
+
/////////////// pyunicode_as_double.proto ///////////////
|
|
740
|
+
//@requires: pybytes_as_double
|
|
741
|
+
|
|
742
|
+
#if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS
|
|
743
|
+
static const char* __Pyx__PyUnicode_AsDouble_Copy(const void* data, const int kind, char* buffer, Py_ssize_t start, Py_ssize_t end) {
|
|
744
|
+
int last_was_punctuation;
|
|
745
|
+
Py_ssize_t i;
|
|
746
|
+
// number must not start with punctuation
|
|
747
|
+
last_was_punctuation = 1;
|
|
748
|
+
for (i=start; i <= end; i++) {
|
|
749
|
+
Py_UCS4 chr = PyUnicode_READ(kind, data, i);
|
|
750
|
+
int is_punctuation = (chr == '_') | (chr == '.');
|
|
751
|
+
*buffer = (char)chr;
|
|
752
|
+
// reject sequences of '_' and '.'
|
|
753
|
+
buffer += (chr != '_');
|
|
754
|
+
if (unlikely(chr > 127)) goto parse_failure;
|
|
755
|
+
if (unlikely(last_was_punctuation & is_punctuation)) goto parse_failure;
|
|
756
|
+
last_was_punctuation = is_punctuation;
|
|
757
|
+
}
|
|
758
|
+
if (unlikely(last_was_punctuation)) goto parse_failure;
|
|
759
|
+
*buffer = '\0';
|
|
760
|
+
return buffer;
|
|
761
|
+
|
|
762
|
+
parse_failure:
|
|
763
|
+
return NULL;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
static double __Pyx__PyUnicode_AsDouble_inf_nan(const void* data, int kind, Py_ssize_t start, Py_ssize_t length) {
|
|
767
|
+
int matches = 1;
|
|
768
|
+
Py_UCS4 chr;
|
|
769
|
+
Py_UCS4 sign = PyUnicode_READ(kind, data, start);
|
|
770
|
+
int is_signed = (sign == '-') | (sign == '+');
|
|
771
|
+
start += is_signed;
|
|
772
|
+
length -= is_signed;
|
|
773
|
+
|
|
774
|
+
switch (PyUnicode_READ(kind, data, start)) {
|
|
775
|
+
#ifdef Py_NAN
|
|
776
|
+
case 'n':
|
|
777
|
+
case 'N':
|
|
778
|
+
if (unlikely(length != 3)) goto parse_failure;
|
|
779
|
+
chr = PyUnicode_READ(kind, data, start+1);
|
|
780
|
+
matches &= (chr == 'a') | (chr == 'A');
|
|
781
|
+
chr = PyUnicode_READ(kind, data, start+2);
|
|
782
|
+
matches &= (chr == 'n') | (chr == 'N');
|
|
783
|
+
if (unlikely(!matches)) goto parse_failure;
|
|
784
|
+
return (sign == '-') ? -Py_NAN : Py_NAN;
|
|
785
|
+
#endif
|
|
786
|
+
case 'i':
|
|
787
|
+
case 'I':
|
|
788
|
+
if (unlikely(length < 3)) goto parse_failure;
|
|
789
|
+
chr = PyUnicode_READ(kind, data, start+1);
|
|
790
|
+
matches &= (chr == 'n') | (chr == 'N');
|
|
791
|
+
chr = PyUnicode_READ(kind, data, start+2);
|
|
792
|
+
matches &= (chr == 'f') | (chr == 'F');
|
|
793
|
+
if (likely(length == 3 && matches))
|
|
794
|
+
return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
|
795
|
+
if (unlikely(length != 8)) goto parse_failure;
|
|
796
|
+
chr = PyUnicode_READ(kind, data, start+3);
|
|
797
|
+
matches &= (chr == 'i') | (chr == 'I');
|
|
798
|
+
chr = PyUnicode_READ(kind, data, start+4);
|
|
799
|
+
matches &= (chr == 'n') | (chr == 'N');
|
|
800
|
+
chr = PyUnicode_READ(kind, data, start+5);
|
|
801
|
+
matches &= (chr == 'i') | (chr == 'I');
|
|
802
|
+
chr = PyUnicode_READ(kind, data, start+6);
|
|
803
|
+
matches &= (chr == 't') | (chr == 'T');
|
|
804
|
+
chr = PyUnicode_READ(kind, data, start+7);
|
|
805
|
+
matches &= (chr == 'y') | (chr == 'Y');
|
|
806
|
+
if (unlikely(!matches)) goto parse_failure;
|
|
807
|
+
return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
|
808
|
+
case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
|
|
809
|
+
break;
|
|
810
|
+
default:
|
|
811
|
+
goto parse_failure;
|
|
812
|
+
}
|
|
813
|
+
return 0.0;
|
|
814
|
+
parse_failure:
|
|
815
|
+
return -1.0;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
static double __Pyx_PyUnicode_AsDouble_WithSpaces(PyObject *obj) {
|
|
819
|
+
double value;
|
|
820
|
+
const char *last;
|
|
821
|
+
char *end;
|
|
822
|
+
Py_ssize_t start, length = PyUnicode_GET_LENGTH(obj);
|
|
823
|
+
const int kind = PyUnicode_KIND(obj);
|
|
824
|
+
const void* data = PyUnicode_DATA(obj);
|
|
825
|
+
|
|
826
|
+
// strip spaces at start and end
|
|
827
|
+
start = 0;
|
|
828
|
+
while (Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, start)))
|
|
829
|
+
start++;
|
|
830
|
+
while (start < length - 1 && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, length - 1)))
|
|
831
|
+
length--;
|
|
832
|
+
length -= start;
|
|
833
|
+
if (unlikely(length <= 0)) goto fallback;
|
|
834
|
+
|
|
835
|
+
// parse NaN / inf
|
|
836
|
+
value = __Pyx__PyUnicode_AsDouble_inf_nan(data, kind, start, length);
|
|
837
|
+
if (unlikely(value == -1.0)) goto fallback;
|
|
838
|
+
if (value != 0.0) return value;
|
|
839
|
+
|
|
840
|
+
if (length < 40) {
|
|
841
|
+
char number[40];
|
|
842
|
+
last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length);
|
|
843
|
+
if (unlikely(!last)) goto fallback;
|
|
844
|
+
value = PyOS_string_to_double(number, &end, NULL);
|
|
845
|
+
} else {
|
|
846
|
+
char *number = (char*) PyMem_Malloc((length + 1) * sizeof(char));
|
|
847
|
+
if (unlikely(!number)) goto fallback;
|
|
848
|
+
last = __Pyx__PyUnicode_AsDouble_Copy(data, kind, number, start, start + length);
|
|
849
|
+
if (unlikely(!last)) {
|
|
850
|
+
PyMem_Free(number);
|
|
851
|
+
goto fallback;
|
|
852
|
+
}
|
|
853
|
+
value = PyOS_string_to_double(number, &end, NULL);
|
|
854
|
+
PyMem_Free(number);
|
|
855
|
+
}
|
|
856
|
+
if (likely(end == last) || (value == (double)-1 && PyErr_Occurred())) {
|
|
857
|
+
return value;
|
|
858
|
+
}
|
|
859
|
+
fallback:
|
|
860
|
+
return __Pyx_SlowPyString_AsDouble(obj);
|
|
861
|
+
}
|
|
862
|
+
#endif
|
|
863
|
+
|
|
864
|
+
static CYTHON_INLINE double __Pyx_PyUnicode_AsDouble(PyObject *obj) {
|
|
865
|
+
// Currently not optimised for Py2.7.
|
|
866
|
+
#if !CYTHON_COMPILING_IN_PYPY && CYTHON_ASSUME_SAFE_MACROS
|
|
867
|
+
if (unlikely(__Pyx_PyUnicode_READY(obj) == -1))
|
|
868
|
+
return (double)-1;
|
|
869
|
+
if (likely(PyUnicode_IS_ASCII(obj))) {
|
|
870
|
+
const char *s;
|
|
871
|
+
Py_ssize_t length;
|
|
872
|
+
s = PyUnicode_AsUTF8AndSize(obj, &length);
|
|
873
|
+
return __Pyx__PyBytes_AsDouble(obj, s, length);
|
|
874
|
+
}
|
|
875
|
+
return __Pyx_PyUnicode_AsDouble_WithSpaces(obj);
|
|
876
|
+
#else
|
|
877
|
+
return __Pyx_SlowPyString_AsDouble(obj);
|
|
878
|
+
#endif
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
/////////////// pybytes_as_double.proto ///////////////
|
|
883
|
+
|
|
884
|
+
static double __Pyx_SlowPyString_AsDouble(PyObject *obj);/*proto*/
|
|
885
|
+
static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length);/*proto*/
|
|
886
|
+
|
|
887
|
+
static CYTHON_INLINE double __Pyx_PyBytes_AsDouble(PyObject *obj) {
|
|
888
|
+
char* as_c_string;
|
|
889
|
+
Py_ssize_t size;
|
|
890
|
+
#if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
891
|
+
as_c_string = PyBytes_AS_STRING(obj);
|
|
892
|
+
size = PyBytes_GET_SIZE(obj);
|
|
893
|
+
#else
|
|
894
|
+
if (PyBytes_AsStringAndSize(obj, &as_c_string, &size) < 0) {
|
|
895
|
+
return (double)-1;
|
|
896
|
+
}
|
|
897
|
+
#endif
|
|
898
|
+
return __Pyx__PyBytes_AsDouble(obj, as_c_string, size);
|
|
899
|
+
}
|
|
900
|
+
static CYTHON_INLINE double __Pyx_PyByteArray_AsDouble(PyObject *obj) {
|
|
901
|
+
char* as_c_string;
|
|
902
|
+
Py_ssize_t size;
|
|
903
|
+
#if CYTHON_ASSUME_SAFE_MACROS && CYTHON_ASSUME_SAFE_SIZE
|
|
904
|
+
as_c_string = PyByteArray_AS_STRING(obj);
|
|
905
|
+
size = PyByteArray_GET_SIZE(obj);
|
|
906
|
+
#else
|
|
907
|
+
as_c_string = PyByteArray_AsString(obj);
|
|
908
|
+
if (as_c_string == NULL) {
|
|
909
|
+
return (double)-1;
|
|
910
|
+
}
|
|
911
|
+
size = PyByteArray_Size(obj);
|
|
912
|
+
#endif
|
|
913
|
+
return __Pyx__PyBytes_AsDouble(obj, as_c_string, size);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
/////////////// pybytes_as_double ///////////////
|
|
918
|
+
|
|
919
|
+
static double __Pyx_SlowPyString_AsDouble(PyObject *obj) {
|
|
920
|
+
PyObject *float_value = PyFloat_FromString(obj);
|
|
921
|
+
if (likely(float_value)) {
|
|
922
|
+
double value = __Pyx_PyFloat_AS_DOUBLE(float_value);
|
|
923
|
+
Py_DECREF(float_value);
|
|
924
|
+
return value;
|
|
925
|
+
}
|
|
926
|
+
return (double)-1;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
static const char* __Pyx__PyBytes_AsDouble_Copy(const char* start, char* buffer, Py_ssize_t length) {
|
|
930
|
+
// number must not start with punctuation
|
|
931
|
+
int last_was_punctuation = 1;
|
|
932
|
+
int parse_error_found = 0;
|
|
933
|
+
Py_ssize_t i;
|
|
934
|
+
for (i=0; i < length; i++) {
|
|
935
|
+
char chr = start[i];
|
|
936
|
+
int is_punctuation = (chr == '_') | (chr == '.') | (chr == 'e') | (chr == 'E');
|
|
937
|
+
*buffer = chr;
|
|
938
|
+
buffer += (chr != '_');
|
|
939
|
+
// reject sequences of punctuation, e.g. '_.'
|
|
940
|
+
parse_error_found |= last_was_punctuation & is_punctuation;
|
|
941
|
+
last_was_punctuation = is_punctuation;
|
|
942
|
+
}
|
|
943
|
+
// number must not end with punctuation
|
|
944
|
+
parse_error_found |= last_was_punctuation;
|
|
945
|
+
*buffer = '\0';
|
|
946
|
+
return unlikely(parse_error_found) ? NULL : buffer;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
static double __Pyx__PyBytes_AsDouble_inf_nan(const char* start, Py_ssize_t length) {
|
|
950
|
+
int matches = 1;
|
|
951
|
+
char sign = start[0];
|
|
952
|
+
int is_signed = (sign == '+') | (sign == '-');
|
|
953
|
+
start += is_signed;
|
|
954
|
+
length -= is_signed;
|
|
955
|
+
|
|
956
|
+
switch (start[0]) {
|
|
957
|
+
#ifdef Py_NAN
|
|
958
|
+
case 'n':
|
|
959
|
+
case 'N':
|
|
960
|
+
if (unlikely(length != 3)) goto parse_failure;
|
|
961
|
+
matches &= (start[1] == 'a' || start[1] == 'A');
|
|
962
|
+
matches &= (start[2] == 'n' || start[2] == 'N');
|
|
963
|
+
if (unlikely(!matches)) goto parse_failure;
|
|
964
|
+
return (sign == '-') ? -Py_NAN : Py_NAN;
|
|
965
|
+
#endif
|
|
966
|
+
case 'i':
|
|
967
|
+
case 'I':
|
|
968
|
+
if (unlikely(length < 3)) goto parse_failure;
|
|
969
|
+
matches &= (start[1] == 'n' || start[1] == 'N');
|
|
970
|
+
matches &= (start[2] == 'f' || start[2] == 'F');
|
|
971
|
+
if (likely(length == 3 && matches))
|
|
972
|
+
return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
|
973
|
+
if (unlikely(length != 8)) goto parse_failure;
|
|
974
|
+
matches &= (start[3] == 'i' || start[3] == 'I');
|
|
975
|
+
matches &= (start[4] == 'n' || start[4] == 'N');
|
|
976
|
+
matches &= (start[5] == 'i' || start[5] == 'I');
|
|
977
|
+
matches &= (start[6] == 't' || start[6] == 'T');
|
|
978
|
+
matches &= (start[7] == 'y' || start[7] == 'Y');
|
|
979
|
+
if (unlikely(!matches)) goto parse_failure;
|
|
980
|
+
return (sign == '-') ? -Py_HUGE_VAL : Py_HUGE_VAL;
|
|
981
|
+
case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
|
|
982
|
+
break;
|
|
983
|
+
default:
|
|
984
|
+
goto parse_failure;
|
|
985
|
+
}
|
|
986
|
+
return 0.0;
|
|
987
|
+
parse_failure:
|
|
988
|
+
return -1.0;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
static CYTHON_INLINE int __Pyx__PyBytes_AsDouble_IsSpace(char ch) {
|
|
992
|
+
// see Py_ISSPACE() in CPython
|
|
993
|
+
// https://github.com/python/cpython/blob/master/Python/pyctype.c
|
|
994
|
+
return (ch == 0x20) | !((ch < 0x9) | (ch > 0xd));
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
CYTHON_UNUSED static double __Pyx__PyBytes_AsDouble(PyObject *obj, const char* start, Py_ssize_t length) {
|
|
998
|
+
double value;
|
|
999
|
+
Py_ssize_t i, digits;
|
|
1000
|
+
const char *last = start + length;
|
|
1001
|
+
char *end;
|
|
1002
|
+
|
|
1003
|
+
// strip spaces at start and end
|
|
1004
|
+
while (__Pyx__PyBytes_AsDouble_IsSpace(*start))
|
|
1005
|
+
start++;
|
|
1006
|
+
while (start < last - 1 && __Pyx__PyBytes_AsDouble_IsSpace(last[-1]))
|
|
1007
|
+
last--;
|
|
1008
|
+
length = last - start;
|
|
1009
|
+
if (unlikely(length <= 0)) goto fallback;
|
|
1010
|
+
|
|
1011
|
+
// parse NaN / inf
|
|
1012
|
+
value = __Pyx__PyBytes_AsDouble_inf_nan(start, length);
|
|
1013
|
+
if (unlikely(value == -1.0)) goto fallback;
|
|
1014
|
+
if (value != 0.0) return value;
|
|
1015
|
+
|
|
1016
|
+
// look for underscores
|
|
1017
|
+
digits = 0;
|
|
1018
|
+
for (i=0; i < length; digits += start[i++] != '_');
|
|
1019
|
+
|
|
1020
|
+
if (likely(digits == length)) {
|
|
1021
|
+
value = PyOS_string_to_double(start, &end, NULL);
|
|
1022
|
+
} else if (digits < 40) {
|
|
1023
|
+
char number[40];
|
|
1024
|
+
last = __Pyx__PyBytes_AsDouble_Copy(start, number, length);
|
|
1025
|
+
if (unlikely(!last)) goto fallback;
|
|
1026
|
+
value = PyOS_string_to_double(number, &end, NULL);
|
|
1027
|
+
} else {
|
|
1028
|
+
char *number = (char*) PyMem_Malloc((digits + 1) * sizeof(char));
|
|
1029
|
+
if (unlikely(!number)) goto fallback;
|
|
1030
|
+
last = __Pyx__PyBytes_AsDouble_Copy(start, number, length);
|
|
1031
|
+
if (unlikely(!last)) {
|
|
1032
|
+
PyMem_Free(number);
|
|
1033
|
+
goto fallback;
|
|
1034
|
+
}
|
|
1035
|
+
value = PyOS_string_to_double(number, &end, NULL);
|
|
1036
|
+
PyMem_Free(number);
|
|
1037
|
+
}
|
|
1038
|
+
if (likely(end == last) || (value == (double)-1 && PyErr_Occurred())) {
|
|
1039
|
+
return value;
|
|
1040
|
+
}
|
|
1041
|
+
fallback:
|
|
1042
|
+
return __Pyx_SlowPyString_AsDouble(obj);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
/////////////// PyNumberPow2.proto ///////////////
|
|
1047
|
+
|
|
1048
|
+
#define __Pyx_PyNumber_InPlacePowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 1)
|
|
1049
|
+
#define __Pyx_PyNumber_PowerOf2(a, b, c) __Pyx__PyNumber_PowerOf2(a, b, c, 0)
|
|
1050
|
+
|
|
1051
|
+
static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace); /*proto*/
|
|
1052
|
+
|
|
1053
|
+
/////////////// PyNumberPow2 ///////////////
|
|
1054
|
+
|
|
1055
|
+
static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject *none, int inplace) {
|
|
1056
|
+
// in CPython, 1<<N is substantially faster than 2**N
|
|
1057
|
+
// see https://bugs.python.org/issue21420
|
|
1058
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
1059
|
+
Py_ssize_t shiftby;
|
|
1060
|
+
if (likely(PyLong_CheckExact(exp))) {
|
|
1061
|
+
#if CYTHON_USE_PYLONG_INTERNALS
|
|
1062
|
+
if (__Pyx_PyLong_IsZero(exp)) {
|
|
1063
|
+
return PyLong_FromLong(1L);
|
|
1064
|
+
} else if (__Pyx_PyLong_IsNeg(exp)) {
|
|
1065
|
+
goto fallback;
|
|
1066
|
+
} else if (__Pyx_PyLong_IsCompact(exp)) {
|
|
1067
|
+
shiftby = __Pyx_PyLong_CompactValueUnsigned(exp);
|
|
1068
|
+
} else {
|
|
1069
|
+
shiftby = PyLong_AsSsize_t(exp);
|
|
1070
|
+
}
|
|
1071
|
+
#else
|
|
1072
|
+
shiftby = PyLong_AsSsize_t(exp);
|
|
1073
|
+
#endif
|
|
1074
|
+
} else {
|
|
1075
|
+
goto fallback;
|
|
1076
|
+
}
|
|
1077
|
+
if (likely(shiftby >= 0)) {
|
|
1078
|
+
if ((size_t)shiftby <= sizeof(long) * 8 - 2) {
|
|
1079
|
+
long value = 1L << shiftby;
|
|
1080
|
+
return PyLong_FromLong(value);
|
|
1081
|
+
#ifdef HAVE_LONG_LONG
|
|
1082
|
+
} else if ((size_t)shiftby <= sizeof(unsigned PY_LONG_LONG) * 8 - 1) {
|
|
1083
|
+
unsigned PY_LONG_LONG value = ((unsigned PY_LONG_LONG)1) << shiftby;
|
|
1084
|
+
return PyLong_FromUnsignedLongLong(value);
|
|
1085
|
+
#endif
|
|
1086
|
+
} else {
|
|
1087
|
+
PyObject *result, *one = PyLong_FromLong(1L);
|
|
1088
|
+
if (unlikely(!one)) return NULL;
|
|
1089
|
+
result = PyNumber_Lshift(one, exp);
|
|
1090
|
+
Py_DECREF(one);
|
|
1091
|
+
return result;
|
|
1092
|
+
}
|
|
1093
|
+
} else if (shiftby == -1 && PyErr_Occurred()) {
|
|
1094
|
+
PyErr_Clear();
|
|
1095
|
+
}
|
|
1096
|
+
fallback:
|
|
1097
|
+
#endif
|
|
1098
|
+
return (inplace ? PyNumber_InPlacePower : PyNumber_Power)(two, exp, none);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
/////////////// PyLongCompare.proto ///////////////
|
|
1103
|
+
|
|
1104
|
+
{{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
|
|
1105
|
+
static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, long inplace); /*proto*/
|
|
1106
|
+
|
|
1107
|
+
/////////////// PyLongCompare ///////////////
|
|
1108
|
+
|
|
1109
|
+
{{py: pyval, ival = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
|
|
1110
|
+
{{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
|
|
1111
|
+
{{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
|
|
1112
|
+
{{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
|
|
1113
|
+
{{py: slot_name = op.lower() }}
|
|
1114
|
+
{{py: c_op = {'Eq': '==', 'Ne': '!='}[op] }}
|
|
1115
|
+
{{py:
|
|
1116
|
+
return_compare = (
|
|
1117
|
+
(lambda a,b,c_op, return_true=return_true, return_false=return_false: "if ({a} {c_op} {b}) {return_true}; else {return_false};".format(
|
|
1118
|
+
a=a, b=b, c_op=c_op, return_true=return_true, return_false=return_false))
|
|
1119
|
+
if ret_type.is_pyobject else
|
|
1120
|
+
(lambda a,b,c_op: "return ({a} {c_op} {b});".format(a=a, b=b, c_op=c_op))
|
|
1121
|
+
)
|
|
1122
|
+
}}
|
|
1123
|
+
|
|
1124
|
+
static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, long inplace) {
|
|
1125
|
+
CYTHON_MAYBE_UNUSED_VAR(intval);
|
|
1126
|
+
CYTHON_UNUSED_VAR(inplace);
|
|
1127
|
+
if (op1 == op2) {
|
|
1128
|
+
{{return_true if op == 'Eq' else return_false}};
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
#if CYTHON_USE_PYLONG_INTERNALS
|
|
1132
|
+
if (likely(PyLong_CheckExact({{pyval}}))) {
|
|
1133
|
+
int unequal;
|
|
1134
|
+
unsigned long uintval;
|
|
1135
|
+
Py_ssize_t size = __Pyx_PyLong_DigitCount({{pyval}});
|
|
1136
|
+
const digit* digits = __Pyx_PyLong_Digits({{pyval}});
|
|
1137
|
+
if (intval == 0) {
|
|
1138
|
+
{{return_compare('__Pyx_PyLong_IsZero(%s)' % pyval, '1', c_op)}}
|
|
1139
|
+
} else if (intval < 0) {
|
|
1140
|
+
if (__Pyx_PyLong_IsNonNeg({{pyval}}))
|
|
1141
|
+
{{return_false if op == 'Eq' else return_true}};
|
|
1142
|
+
// both are negative => can use absolute values now.
|
|
1143
|
+
intval = -intval;
|
|
1144
|
+
} else {
|
|
1145
|
+
// > 0 => Py_SIZE(pyval) > 0
|
|
1146
|
+
if (__Pyx_PyLong_IsNeg({{pyval}}))
|
|
1147
|
+
{{return_false if op == 'Eq' else return_true}};
|
|
1148
|
+
}
|
|
1149
|
+
// After checking that the sign is the same (and excluding 0), now compare the absolute values.
|
|
1150
|
+
// When inlining, the C compiler should select exactly one line from this unrolled loop.
|
|
1151
|
+
uintval = (unsigned long) intval;
|
|
1152
|
+
{{for _size in range(4, 0, -1)}}
|
|
1153
|
+
#if PyLong_SHIFT * {{_size}} < SIZEOF_LONG*8
|
|
1154
|
+
if (uintval >> (PyLong_SHIFT * {{_size}})) {
|
|
1155
|
+
// The C integer value is between (PyLong_BASE ** _size) and MIN(PyLong_BASE ** _size, LONG_MAX).
|
|
1156
|
+
unequal = (size != {{_size+1}}) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
|
|
1157
|
+
{{for _i in range(1, _size+1)}} | (digits[{{_i}}] != ((uintval >> ({{_i}} * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)){{endfor}};
|
|
1158
|
+
} else
|
|
1159
|
+
#endif
|
|
1160
|
+
{{endfor}}
|
|
1161
|
+
unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
|
|
1162
|
+
|
|
1163
|
+
{{return_compare('unequal', '0', c_op)}}
|
|
1164
|
+
}
|
|
1165
|
+
#endif
|
|
1166
|
+
|
|
1167
|
+
if (PyFloat_CheckExact({{pyval}})) {
|
|
1168
|
+
const long {{'a' if order == 'CObj' else 'b'}} = intval;
|
|
1169
|
+
double {{ival}} = __Pyx_PyFloat_AS_DOUBLE({{pyval}});
|
|
1170
|
+
{{return_compare('(double)a', '(double)b', c_op)}}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
|
|
1174
|
+
PyObject_RichCompare(op1, op2, Py_{{op.upper()}}));
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
/////////////// PyLongBinop.proto ///////////////
|
|
1179
|
+
|
|
1180
|
+
{{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
|
|
1181
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
1182
|
+
static CYTHON_INLINE {{c_ret_type}} __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); /*proto*/
|
|
1183
|
+
#else
|
|
1184
|
+
#define __Pyx_PyLong_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(op1, op2, intval, inplace, zerodivision_check) \
|
|
1185
|
+
{{if op in ('Eq', 'Ne')}}{{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(PyObject_RichCompare(op1, op2, Py_{{op.upper()}}))
|
|
1186
|
+
{{else}}(inplace ? PyNumber_InPlace{{op}}(op1, op2) : PyNumber_{{op}}(op1, op2))
|
|
1187
|
+
{{endif}}
|
|
1188
|
+
#endif
|
|
1189
|
+
|
|
1190
|
+
/////////////// PyLongBinop ///////////////
|
|
1191
|
+
|
|
1192
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
1193
|
+
{{py: from Cython.Utility import pylong_join }}
|
|
1194
|
+
{{py: pyval, ival = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
|
|
1195
|
+
{{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
|
|
1196
|
+
{{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
|
|
1197
|
+
{{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
|
|
1198
|
+
{{py: slot_name = {'TrueDivide': 'true_divide', 'FloorDivide': 'floor_divide'}.get(op, op.lower()) }}
|
|
1199
|
+
{{py: cfunc_name = f"__Pyx_PyLong_{'' if ret_type.is_pyobject else 'Bool'}{op}{order}" }}
|
|
1200
|
+
{{py:
|
|
1201
|
+
c_op = {
|
|
1202
|
+
'Add': '+', 'Subtract': '-', 'Multiply': '*', 'Remainder': '%', 'TrueDivide': '/', 'FloorDivide': '/',
|
|
1203
|
+
'Or': '|', 'Xor': '^', 'And': '&', 'Rshift': '>>', 'Lshift': '<<',
|
|
1204
|
+
'Eq': '==', 'Ne': '!=',
|
|
1205
|
+
}[op]
|
|
1206
|
+
}}
|
|
1207
|
+
{{py:
|
|
1208
|
+
def zerodiv_check(operand, optype='integer', _is_mod=op == 'Remainder', _needs_check=(order == 'CObj' and c_op in '%/')):
|
|
1209
|
+
return (((
|
|
1210
|
+
'if (unlikely(zerodivision_check && ((%s) == 0))) {'
|
|
1211
|
+
' PyErr_SetString(PyExc_ZeroDivisionError, "%s division%s by zero");'
|
|
1212
|
+
' return NULL;'
|
|
1213
|
+
'}') % (operand, optype, ' or modulo' if _is_mod else '')
|
|
1214
|
+
) if _needs_check else '')
|
|
1215
|
+
}}
|
|
1216
|
+
|
|
1217
|
+
static {{c_ret_type}} __Pyx_Fallback_{{cfunc_name}}(PyObject *op1, PyObject *op2, int inplace) {
|
|
1218
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1219
|
+
CYTHON_UNUSED_VAR(inplace);
|
|
1220
|
+
return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
|
|
1221
|
+
PyObject_RichCompare(op1, op2, Py_{{op.upper()}}));
|
|
1222
|
+
{{else}}
|
|
1223
|
+
return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
|
|
1224
|
+
{{endif}}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
#if CYTHON_USE_PYLONG_INTERNALS
|
|
1228
|
+
static {{c_ret_type}} __Pyx_Unpacked_{{cfunc_name}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
|
|
1229
|
+
CYTHON_MAYBE_UNUSED_VAR(inplace);
|
|
1230
|
+
CYTHON_UNUSED_VAR(zerodivision_check);
|
|
1231
|
+
|
|
1232
|
+
const long {{'a' if order == 'CObj' else 'b'}} = intval;
|
|
1233
|
+
long {{ival}}{{if op not in ('Eq', 'Ne')}}, x{{endif}};
|
|
1234
|
+
{{if op not in ('Eq', 'Ne', 'TrueDivide')}}
|
|
1235
|
+
#ifdef HAVE_LONG_LONG
|
|
1236
|
+
const PY_LONG_LONG ll{{'a' if order == 'CObj' else 'b'}} = intval;
|
|
1237
|
+
PY_LONG_LONG ll{{ival}}, llx;
|
|
1238
|
+
#endif
|
|
1239
|
+
{{endif}}
|
|
1240
|
+
|
|
1241
|
+
// special cases for 0: + - * % / // | ^ & >> <<
|
|
1242
|
+
if (unlikely(__Pyx_PyLong_IsZero({{pyval}}))) {
|
|
1243
|
+
{{if order == 'CObj' and c_op in '%/'}}
|
|
1244
|
+
// division by zero!
|
|
1245
|
+
{{zerodiv_check('0')}}
|
|
1246
|
+
{{elif order == 'CObj' and c_op in '+-|^>><<'}}
|
|
1247
|
+
// x == x+0 == x-0 == x|0 == x^0 == x>>0 == x<<0
|
|
1248
|
+
return __Pyx_NewRef(op1);
|
|
1249
|
+
{{elif order == 'CObj' and c_op in '*&'}}
|
|
1250
|
+
// 0 == x*0 == x&0
|
|
1251
|
+
return __Pyx_NewRef(op2);
|
|
1252
|
+
{{elif order == 'ObjC' and c_op in '+|^'}}
|
|
1253
|
+
// x == 0+x == 0|x == 0^x
|
|
1254
|
+
return __Pyx_NewRef(op2);
|
|
1255
|
+
{{elif order == 'ObjC' and c_op == '-'}}
|
|
1256
|
+
// -x == 0-x
|
|
1257
|
+
return PyLong_FromLong(-intval);
|
|
1258
|
+
{{elif order == 'ObjC' and (c_op in '*%&>><<' or op == 'FloorDivide')}}
|
|
1259
|
+
// 0 == 0*x == 0%x == 0&x == 0>>x == 0<<x == 0//x
|
|
1260
|
+
return __Pyx_NewRef(op1);
|
|
1261
|
+
{{endif}}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
{{if c_op == '&'}}
|
|
1265
|
+
// special case for &-ing arbitrarily large numbers with known single digit operands
|
|
1266
|
+
if ((intval & PyLong_MASK) == intval) {
|
|
1267
|
+
// Calling PyLong_CompactValue() requires the PyLong value to be compact, we only need the last digit.
|
|
1268
|
+
long last_digit = (long) __Pyx_PyLong_Digits({{pyval}})[0];
|
|
1269
|
+
long result = intval & (likely(__Pyx_PyLong_IsPos({{pyval}})) ? last_digit : (PyLong_MASK - last_digit + 1));
|
|
1270
|
+
return PyLong_FromLong(result);
|
|
1271
|
+
}
|
|
1272
|
+
{{endif}}
|
|
1273
|
+
|
|
1274
|
+
// handle most common case first to avoid indirect branch and optimise branch prediction
|
|
1275
|
+
if (likely(__Pyx_PyLong_IsCompact({{pyval}}))) {
|
|
1276
|
+
{{ival}} = __Pyx_PyLong_CompactValue({{pyval}});
|
|
1277
|
+
} else {
|
|
1278
|
+
const digit* digits = __Pyx_PyLong_Digits({{pyval}});
|
|
1279
|
+
const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount({{pyval}});
|
|
1280
|
+
switch (size) {
|
|
1281
|
+
{{for _size in range(2, 5)}}
|
|
1282
|
+
{{for _case in (-_size, _size)}}
|
|
1283
|
+
case {{_case}}:
|
|
1284
|
+
if (8 * sizeof(long) - 1 > {{_size}} * PyLong_SHIFT{{if c_op == '*'}}+30{{endif}}{{if op == 'TrueDivide'}} && {{_size-1}} * PyLong_SHIFT < 53{{endif}}) {
|
|
1285
|
+
{{ival}} = {{'-' if _case < 0 else ''}}(long) {{pylong_join(_size, 'digits')}};
|
|
1286
|
+
break;
|
|
1287
|
+
{{if op not in ('Eq', 'Ne', 'TrueDivide')}}
|
|
1288
|
+
#ifdef HAVE_LONG_LONG
|
|
1289
|
+
} else if (8 * sizeof(PY_LONG_LONG) - 1 > {{_size}} * PyLong_SHIFT{{if c_op == '*'}}+30{{endif}}) {
|
|
1290
|
+
ll{{ival}} = {{'-' if _case < 0 else ''}}(PY_LONG_LONG) {{pylong_join(_size, 'digits', 'unsigned PY_LONG_LONG')}};
|
|
1291
|
+
goto long_long;
|
|
1292
|
+
#endif
|
|
1293
|
+
{{endif}}
|
|
1294
|
+
}
|
|
1295
|
+
// if size doesn't fit into a long or PY_LONG_LONG anymore, fall through to default
|
|
1296
|
+
CYTHON_FALLTHROUGH;
|
|
1297
|
+
{{endfor}}
|
|
1298
|
+
{{endfor}}
|
|
1299
|
+
|
|
1300
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1301
|
+
#if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
|
|
1302
|
+
// unusual setup - your fault
|
|
1303
|
+
default: return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
|
|
1304
|
+
PyLong_Type.tp_richcompare({{'op1, op2' if order == 'ObjC' else 'op2, op1'}}, Py_{{op.upper()}}));
|
|
1305
|
+
#else
|
|
1306
|
+
// too large for the long values we allow => definitely not equal
|
|
1307
|
+
default: {{return_false if op == 'Eq' else return_true}};
|
|
1308
|
+
#endif
|
|
1309
|
+
{{else}}
|
|
1310
|
+
default: return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
|
|
1311
|
+
{{endif}}
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1316
|
+
if (a {{c_op}} b) {
|
|
1317
|
+
{{return_true}};
|
|
1318
|
+
} else {
|
|
1319
|
+
{{return_false}};
|
|
1320
|
+
}
|
|
1321
|
+
{{else}}
|
|
1322
|
+
{{if c_op == '*'}}
|
|
1323
|
+
CYTHON_UNUSED_VAR(a);
|
|
1324
|
+
CYTHON_UNUSED_VAR(b);
|
|
1325
|
+
#ifdef HAVE_LONG_LONG
|
|
1326
|
+
ll{{ival}} = {{ival}};
|
|
1327
|
+
goto long_long;
|
|
1328
|
+
#else
|
|
1329
|
+
return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
|
|
1330
|
+
#endif
|
|
1331
|
+
{{elif c_op == '%'}}
|
|
1332
|
+
// see CMath.c :: ModInt utility code
|
|
1333
|
+
x = a % b;
|
|
1334
|
+
x += ((x != 0) & ((x ^ b) < 0)) * b;
|
|
1335
|
+
{{elif op == 'TrueDivide'}}
|
|
1336
|
+
if ((8 * sizeof(long) <= 53 || likely(labs({{ival}}) <= ((PY_LONG_LONG)1 << 53)))
|
|
1337
|
+
|| __Pyx_PyLong_DigitCount({{pyval}}) <= 52 / PyLong_SHIFT) {
|
|
1338
|
+
return PyFloat_FromDouble((double)a / (double)b);
|
|
1339
|
+
}
|
|
1340
|
+
return PyLong_Type.tp_as_number->nb_{{slot_name}}(op1, op2);
|
|
1341
|
+
{{elif op == 'FloorDivide'}}
|
|
1342
|
+
{
|
|
1343
|
+
long q, r;
|
|
1344
|
+
// see CMath.c :: DivInt utility code
|
|
1345
|
+
q = a / b;
|
|
1346
|
+
r = a - q*b;
|
|
1347
|
+
q -= ((r != 0) & ((r ^ b) < 0));
|
|
1348
|
+
x = q;
|
|
1349
|
+
}
|
|
1350
|
+
{{else}}
|
|
1351
|
+
x = a {{c_op}} b;
|
|
1352
|
+
{{if op == 'Lshift'}}
|
|
1353
|
+
#ifdef HAVE_LONG_LONG
|
|
1354
|
+
if (unlikely(!(b < (long) (sizeof(long)*8) && a == x >> b)) && a) {
|
|
1355
|
+
ll{{ival}} = {{ival}};
|
|
1356
|
+
goto long_long;
|
|
1357
|
+
}
|
|
1358
|
+
#else
|
|
1359
|
+
if (likely(b < (long) (sizeof(long)*8) && a == x >> b) || !a) /* execute return statement below */
|
|
1360
|
+
#endif
|
|
1361
|
+
{{endif}}
|
|
1362
|
+
{{endif}}
|
|
1363
|
+
return PyLong_FromLong(x);
|
|
1364
|
+
|
|
1365
|
+
{{if op != 'TrueDivide'}}
|
|
1366
|
+
#ifdef HAVE_LONG_LONG
|
|
1367
|
+
long_long:
|
|
1368
|
+
{{if c_op == '%'}}
|
|
1369
|
+
// see CMath.c :: ModInt utility code
|
|
1370
|
+
llx = lla % llb;
|
|
1371
|
+
llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
|
|
1372
|
+
{{elif op == 'FloorDivide'}}
|
|
1373
|
+
{
|
|
1374
|
+
PY_LONG_LONG q, r;
|
|
1375
|
+
// see CMath.c :: DivInt utility code
|
|
1376
|
+
q = lla / llb;
|
|
1377
|
+
r = lla - q*llb;
|
|
1378
|
+
q -= ((r != 0) & ((r ^ llb) < 0));
|
|
1379
|
+
llx = q;
|
|
1380
|
+
}
|
|
1381
|
+
{{else}}
|
|
1382
|
+
llx = lla {{c_op}} llb;
|
|
1383
|
+
{{if op == 'Lshift'}}
|
|
1384
|
+
if (likely(lla == llx >> llb)) /* then execute 'return' below */
|
|
1385
|
+
{{endif}}
|
|
1386
|
+
{{endif}}
|
|
1387
|
+
return PyLong_FromLongLong(llx);
|
|
1388
|
+
#endif
|
|
1389
|
+
|
|
1390
|
+
return __Pyx_Fallback_{{cfunc_name}}(op1, op2, inplace);
|
|
1391
|
+
|
|
1392
|
+
{{endif}}{{# if op != 'TrueDivide' #}}
|
|
1393
|
+
{{endif}}{{# if op in ('Eq', 'Ne') #}}
|
|
1394
|
+
}
|
|
1395
|
+
#endif
|
|
1396
|
+
|
|
1397
|
+
{{if c_op in '+-*' or op in ('TrueDivide', 'Eq', 'Ne')}}
|
|
1398
|
+
static {{c_ret_type}} __Pyx_Float_{{cfunc_name}}(PyObject *float_val, long intval, int zerodivision_check) {
|
|
1399
|
+
CYTHON_UNUSED_VAR(zerodivision_check);
|
|
1400
|
+
|
|
1401
|
+
const long {{'a' if order == 'CObj' else 'b'}} = intval;
|
|
1402
|
+
double {{ival}} = __Pyx_PyFloat_AS_DOUBLE(float_val);
|
|
1403
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1404
|
+
if ((double)a {{c_op}} (double)b) {
|
|
1405
|
+
{{return_true}};
|
|
1406
|
+
} else {
|
|
1407
|
+
{{return_false}};
|
|
1408
|
+
}
|
|
1409
|
+
{{else}}
|
|
1410
|
+
double result;
|
|
1411
|
+
{{zerodiv_check('b', 'float')}}
|
|
1412
|
+
result = ((double)a) {{c_op}} (double)b;
|
|
1413
|
+
return PyFloat_FromDouble(result);
|
|
1414
|
+
{{endif}}
|
|
1415
|
+
}
|
|
1416
|
+
{{endif}}
|
|
1417
|
+
|
|
1418
|
+
static CYTHON_INLINE {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
|
|
1419
|
+
CYTHON_MAYBE_UNUSED_VAR(intval);
|
|
1420
|
+
CYTHON_UNUSED_VAR(zerodivision_check);
|
|
1421
|
+
|
|
1422
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1423
|
+
if (op1 == op2) {
|
|
1424
|
+
{{return_true if op == 'Eq' else return_false}};
|
|
1425
|
+
}
|
|
1426
|
+
{{endif}}
|
|
1427
|
+
|
|
1428
|
+
#if CYTHON_USE_PYLONG_INTERNALS
|
|
1429
|
+
if (likely(PyLong_CheckExact({{pyval}}))) {
|
|
1430
|
+
return __Pyx_Unpacked_{{cfunc_name}}(op1, op2, intval, inplace, zerodivision_check);
|
|
1431
|
+
}
|
|
1432
|
+
#endif
|
|
1433
|
+
|
|
1434
|
+
{{if c_op in '+-*' or op in ('TrueDivide', 'Eq', 'Ne')}}
|
|
1435
|
+
if (PyFloat_CheckExact({{pyval}})) {
|
|
1436
|
+
return __Pyx_Float_{{cfunc_name}}({{pyval}}, intval, zerodivision_check);
|
|
1437
|
+
}
|
|
1438
|
+
{{endif}}
|
|
1439
|
+
|
|
1440
|
+
return __Pyx_Fallback_{{cfunc_name}}(op1, op2, inplace);
|
|
1441
|
+
}
|
|
1442
|
+
#endif /* !CYTHON_COMPILING_IN_PYPY */
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
/////////////// PyFloatBinop.proto ///////////////
|
|
1446
|
+
|
|
1447
|
+
{{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
|
|
1448
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
1449
|
+
static {{c_ret_type}} __Pyx_PyFloat_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check); /*proto*/
|
|
1450
|
+
#else
|
|
1451
|
+
#define __Pyx_PyFloat_{{'' if ret_type.is_pyobject else 'Bool'}}{{op}}{{order}}(op1, op2, floatval, inplace, zerodivision_check) \
|
|
1452
|
+
{{if op in ('Eq', 'Ne')}}{{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(PyObject_RichCompare(op1, op2, Py_{{op.upper()}}))
|
|
1453
|
+
{{elif op == 'Divide'}}((inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2)))
|
|
1454
|
+
{{else}}(inplace ? PyNumber_InPlace{{op}}(op1, op2) : PyNumber_{{op}}(op1, op2))
|
|
1455
|
+
{{endif}}
|
|
1456
|
+
#endif
|
|
1457
|
+
|
|
1458
|
+
/////////////// PyFloatBinop ///////////////
|
|
1459
|
+
|
|
1460
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
1461
|
+
{{py: from Cython.Utility import pylong_join }}
|
|
1462
|
+
{{py: c_ret_type = 'PyObject*' if ret_type.is_pyobject else 'int'}}
|
|
1463
|
+
{{py: return_true = 'Py_RETURN_TRUE' if ret_type.is_pyobject else 'return 1'}}
|
|
1464
|
+
{{py: return_false = 'Py_RETURN_FALSE' if ret_type.is_pyobject else 'return 0'}}
|
|
1465
|
+
{{py: pyval, fval = ('op2', 'b') if order == 'CObj' else ('op1', 'a') }}
|
|
1466
|
+
{{py: cfunc_name = '__Pyx_PyFloat_%s%s%s' % ('' if ret_type.is_pyobject else 'Bool', op, order) }}
|
|
1467
|
+
{{py:
|
|
1468
|
+
c_op = {
|
|
1469
|
+
'Add': '+', 'Subtract': '-', 'TrueDivide': '/', 'Divide': '/', 'Remainder': '%',
|
|
1470
|
+
'Eq': '==', 'Ne': '!=',
|
|
1471
|
+
}[op]
|
|
1472
|
+
}}
|
|
1473
|
+
{{py:
|
|
1474
|
+
def zerodiv_check(operand, _is_mod=op == 'Remainder', _needs_check=(order == 'CObj' and c_op in '%/')):
|
|
1475
|
+
return (((
|
|
1476
|
+
'if (unlikely(zerodivision_check && ((%s) == 0.0))) {'
|
|
1477
|
+
' PyErr_SetString(PyExc_ZeroDivisionError, "float division%s by zero");'
|
|
1478
|
+
' return NULL;'
|
|
1479
|
+
'}') % (operand, ' or modulo' if _is_mod else '')
|
|
1480
|
+
) if _needs_check else '')
|
|
1481
|
+
}}
|
|
1482
|
+
|
|
1483
|
+
static {{c_ret_type}} {{cfunc_name}}(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check) {
|
|
1484
|
+
const double {{'a' if order == 'CObj' else 'b'}} = floatval;
|
|
1485
|
+
double {{fval}}{{if op not in ('Eq', 'Ne')}}, result{{endif}};
|
|
1486
|
+
CYTHON_UNUSED_VAR(inplace);
|
|
1487
|
+
CYTHON_UNUSED_VAR(zerodivision_check);
|
|
1488
|
+
|
|
1489
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1490
|
+
if (op1 == op2) {
|
|
1491
|
+
{{return_true if op == 'Eq' else return_false}};
|
|
1492
|
+
}
|
|
1493
|
+
{{endif}}
|
|
1494
|
+
|
|
1495
|
+
if (likely(PyFloat_CheckExact({{pyval}}))) {
|
|
1496
|
+
{{fval}} = __Pyx_PyFloat_AS_DOUBLE({{pyval}});
|
|
1497
|
+
{{zerodiv_check(fval)}}
|
|
1498
|
+
} else
|
|
1499
|
+
|
|
1500
|
+
if (likely(PyLong_CheckExact({{pyval}}))) {
|
|
1501
|
+
#if CYTHON_USE_PYLONG_INTERNALS
|
|
1502
|
+
if (__Pyx_PyLong_IsZero({{pyval}})) {
|
|
1503
|
+
{{fval}} = 0.0;
|
|
1504
|
+
{{zerodiv_check(fval)}}
|
|
1505
|
+
} else if (__Pyx_PyLong_IsCompact({{pyval}})) {
|
|
1506
|
+
{{fval}} = (double) __Pyx_PyLong_CompactValue({{pyval}});
|
|
1507
|
+
} else {
|
|
1508
|
+
const digit* digits = __Pyx_PyLong_Digits({{pyval}});
|
|
1509
|
+
const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount({{pyval}});
|
|
1510
|
+
switch (size) {
|
|
1511
|
+
{{for _size in (2, 3, 4)}}
|
|
1512
|
+
case -{{_size}}:
|
|
1513
|
+
case {{_size}}:
|
|
1514
|
+
if (8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || ({{_size-1}} * PyLong_SHIFT < 53))) {
|
|
1515
|
+
{{fval}} = (double) {{pylong_join(_size, 'digits')}};
|
|
1516
|
+
// let CPython do its own float rounding from 2**53 on (max. consecutive integer in double float)
|
|
1517
|
+
if ((8 * sizeof(unsigned long) < 53) || ({{_size}} * PyLong_SHIFT < 53) || ({{fval}} < (double) ((PY_LONG_LONG)1 << 53))) {
|
|
1518
|
+
if (size == {{-_size}})
|
|
1519
|
+
{{fval}} = -{{fval}};
|
|
1520
|
+
break;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
// Fall through if size doesn't fit safely into a double anymore.
|
|
1524
|
+
// It may not be obvious that this is a safe fall-through given the "fval < 2**53"
|
|
1525
|
+
// check above. However, the number of digits that CPython uses for a given PyLong
|
|
1526
|
+
// value is minimal, and together with the "(size-1) * SHIFT < 53" check above,
|
|
1527
|
+
// this should make it safe.
|
|
1528
|
+
CYTHON_FALLTHROUGH;
|
|
1529
|
+
{{endfor}}
|
|
1530
|
+
default:
|
|
1531
|
+
#endif
|
|
1532
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1533
|
+
{
|
|
1534
|
+
PyObject *res =
|
|
1535
|
+
#if CYTHON_USE_TYPE_SLOTS || __PYX_LIMITED_VERSION_HEX >= 0x030A0000
|
|
1536
|
+
// PyType_GetSlot only works on non-heap types from Python 3.10
|
|
1537
|
+
__Pyx_PyType_GetSlot((&PyFloat_Type), tp_richcompare, richcmpfunc)
|
|
1538
|
+
#else
|
|
1539
|
+
PyObject_RichCompare
|
|
1540
|
+
#endif
|
|
1541
|
+
({{'op1, op2' if order == 'CObj' else 'op2, op1'}},
|
|
1542
|
+
Py_{{op.upper()}});
|
|
1543
|
+
return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
|
|
1544
|
+
res);
|
|
1545
|
+
}
|
|
1546
|
+
{{else}}
|
|
1547
|
+
{{fval}} = PyLong_AsDouble({{pyval}});
|
|
1548
|
+
if (unlikely({{fval}} == -1.0 && PyErr_Occurred())) return NULL;
|
|
1549
|
+
{{if zerodiv_check(fval)}}
|
|
1550
|
+
#if !CYTHON_USE_PYLONG_INTERNALS
|
|
1551
|
+
{{zerodiv_check(fval)}}
|
|
1552
|
+
#endif
|
|
1553
|
+
{{endif}}
|
|
1554
|
+
{{endif}}
|
|
1555
|
+
#if CYTHON_USE_PYLONG_INTERNALS
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
#endif
|
|
1559
|
+
} else {
|
|
1560
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1561
|
+
return {{'' if ret_type.is_pyobject else '__Pyx_PyObject_IsTrueAndDecref'}}(
|
|
1562
|
+
PyObject_RichCompare(op1, op2, Py_{{op.upper()}}));
|
|
1563
|
+
{{elif op == 'Divide'}}
|
|
1564
|
+
return (inplace ? __Pyx_PyNumber_InPlaceDivide(op1, op2) : __Pyx_PyNumber_Divide(op1, op2));
|
|
1565
|
+
{{else}}
|
|
1566
|
+
return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
|
|
1567
|
+
{{endif}}
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
{{if op in ('Eq', 'Ne')}}
|
|
1571
|
+
if (a {{c_op}} b) {
|
|
1572
|
+
{{return_true}};
|
|
1573
|
+
} else {
|
|
1574
|
+
{{return_false}};
|
|
1575
|
+
}
|
|
1576
|
+
{{else}}
|
|
1577
|
+
{{if c_op == '%'}}
|
|
1578
|
+
result = fmod(a, b);
|
|
1579
|
+
if (result)
|
|
1580
|
+
result += ((result < 0) ^ (b < 0)) * b;
|
|
1581
|
+
else
|
|
1582
|
+
result = copysign(0.0, b);
|
|
1583
|
+
{{else}}
|
|
1584
|
+
result = a {{c_op}} b;
|
|
1585
|
+
{{endif}}
|
|
1586
|
+
return PyFloat_FromDouble(result);
|
|
1587
|
+
{{endif}}
|
|
1588
|
+
}
|
|
1589
|
+
#endif
|