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,987 @@
|
|
|
1
|
+
/////////////// ImportDottedModule.proto ///////////////
|
|
2
|
+
|
|
3
|
+
static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple); /*proto*/
|
|
4
|
+
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple); /*proto*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/////////////// ImportDottedModule ///////////////
|
|
8
|
+
//@requires: Import
|
|
9
|
+
|
|
10
|
+
static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) {
|
|
11
|
+
PyObject *partial_name = NULL, *slice = NULL, *sep = NULL;
|
|
12
|
+
Py_ssize_t size;
|
|
13
|
+
if (unlikely(PyErr_Occurred())) {
|
|
14
|
+
PyErr_Clear();
|
|
15
|
+
}
|
|
16
|
+
#if CYTHON_ASSUME_SAFE_SIZE
|
|
17
|
+
size = PyTuple_GET_SIZE(parts_tuple);
|
|
18
|
+
#else
|
|
19
|
+
size = PyTuple_Size(parts_tuple);
|
|
20
|
+
if (size < 0) goto bad;
|
|
21
|
+
#endif
|
|
22
|
+
if (likely(size == count)) {
|
|
23
|
+
partial_name = name;
|
|
24
|
+
} else {
|
|
25
|
+
slice = PySequence_GetSlice(parts_tuple, 0, count);
|
|
26
|
+
if (unlikely(!slice))
|
|
27
|
+
goto bad;
|
|
28
|
+
sep = PyUnicode_FromStringAndSize(".", 1);
|
|
29
|
+
if (unlikely(!sep))
|
|
30
|
+
goto bad;
|
|
31
|
+
partial_name = PyUnicode_Join(sep, slice);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
PyErr_Format(
|
|
35
|
+
PyExc_ModuleNotFoundError,
|
|
36
|
+
"No module named '%U'", partial_name);
|
|
37
|
+
|
|
38
|
+
bad:
|
|
39
|
+
Py_XDECREF(sep);
|
|
40
|
+
Py_XDECREF(slice);
|
|
41
|
+
Py_XDECREF(partial_name);
|
|
42
|
+
return NULL;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) {
|
|
46
|
+
PyObject *imported_module;
|
|
47
|
+
#if (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) || \
|
|
48
|
+
CYTHON_COMPILING_IN_GRAAL
|
|
49
|
+
PyObject *modules = PyImport_GetModuleDict();
|
|
50
|
+
if (unlikely(!modules))
|
|
51
|
+
return NULL;
|
|
52
|
+
imported_module = __Pyx_PyDict_GetItemStr(modules, name);
|
|
53
|
+
Py_XINCREF(imported_module);
|
|
54
|
+
#else
|
|
55
|
+
imported_module = PyImport_GetModule(name);
|
|
56
|
+
#endif
|
|
57
|
+
return imported_module;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) {
|
|
61
|
+
Py_ssize_t i, nparts;
|
|
62
|
+
#if CYTHON_ASSUME_SAFE_SIZE
|
|
63
|
+
nparts = PyTuple_GET_SIZE(parts_tuple);
|
|
64
|
+
#else
|
|
65
|
+
nparts = PyTuple_Size(parts_tuple);
|
|
66
|
+
if (nparts < 0) return NULL;
|
|
67
|
+
#endif
|
|
68
|
+
for (i=1; i < nparts && module; i++) {
|
|
69
|
+
PyObject *part, *submodule;
|
|
70
|
+
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
|
|
71
|
+
part = PyTuple_GET_ITEM(parts_tuple, i);
|
|
72
|
+
#else
|
|
73
|
+
part = __Pyx_PySequence_ITEM(parts_tuple, i);
|
|
74
|
+
if (!part) return NULL;
|
|
75
|
+
#endif
|
|
76
|
+
submodule = __Pyx_PyObject_GetAttrStrNoError(module, part);
|
|
77
|
+
// We stop if the attribute isn't found, i.e. if submodule is NULL here.
|
|
78
|
+
#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
|
|
79
|
+
Py_DECREF(part);
|
|
80
|
+
#endif
|
|
81
|
+
Py_DECREF(module);
|
|
82
|
+
module = submodule;
|
|
83
|
+
}
|
|
84
|
+
if (unlikely(!module)) {
|
|
85
|
+
return __Pyx__ImportDottedModule_Error(name, parts_tuple, i);
|
|
86
|
+
}
|
|
87
|
+
return module;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
|
|
91
|
+
PyObject *imported_module;
|
|
92
|
+
PyObject *module = __Pyx_Import(name, NULL, 0);
|
|
93
|
+
if (!parts_tuple || unlikely(!module))
|
|
94
|
+
return module;
|
|
95
|
+
|
|
96
|
+
// Look up module in sys.modules, which is safer than the attribute lookups below.
|
|
97
|
+
imported_module = __Pyx__ImportDottedModule_Lookup(name);
|
|
98
|
+
if (likely(imported_module)) {
|
|
99
|
+
Py_DECREF(module);
|
|
100
|
+
return imported_module;
|
|
101
|
+
}
|
|
102
|
+
PyErr_Clear();
|
|
103
|
+
return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
|
|
107
|
+
#if CYTHON_COMPILING_IN_CPYTHON
|
|
108
|
+
PyObject *module = __Pyx__ImportDottedModule_Lookup(name);
|
|
109
|
+
if (likely(module)) {
|
|
110
|
+
// CPython guards against thread-concurrent initialisation in importlib.
|
|
111
|
+
// In this case, we let PyImport_ImportModuleLevelObject() handle the locking.
|
|
112
|
+
PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, PYIDENT("__spec__"));
|
|
113
|
+
if (likely(spec)) {
|
|
114
|
+
PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, PYIDENT("_initializing"));
|
|
115
|
+
if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) {
|
|
116
|
+
Py_DECREF(spec);
|
|
117
|
+
spec = NULL;
|
|
118
|
+
}
|
|
119
|
+
Py_XDECREF(unsafe);
|
|
120
|
+
}
|
|
121
|
+
if (likely(!spec)) {
|
|
122
|
+
// Not in initialisation phase => use modules as is.
|
|
123
|
+
PyErr_Clear();
|
|
124
|
+
return module;
|
|
125
|
+
}
|
|
126
|
+
Py_DECREF(spec);
|
|
127
|
+
Py_DECREF(module);
|
|
128
|
+
} else if (PyErr_Occurred()) {
|
|
129
|
+
PyErr_Clear();
|
|
130
|
+
}
|
|
131
|
+
#endif
|
|
132
|
+
|
|
133
|
+
return __Pyx__ImportDottedModule(name, parts_tuple);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
/////////////// ImportDottedModuleRelFirst.proto ///////////////
|
|
138
|
+
|
|
139
|
+
static PyObject *__Pyx_ImportDottedModuleRelFirst(PyObject *name, PyObject *parts_tuple); /*proto*/
|
|
140
|
+
|
|
141
|
+
/////////////// ImportDottedModuleRelFirst ///////////////
|
|
142
|
+
//@requires: ImportDottedModule
|
|
143
|
+
//@requires: Import
|
|
144
|
+
|
|
145
|
+
static PyObject *__Pyx_ImportDottedModuleRelFirst(PyObject *name, PyObject *parts_tuple) {
|
|
146
|
+
PyObject *module;
|
|
147
|
+
PyObject *from_list = NULL;
|
|
148
|
+
module = __Pyx_Import(name, from_list, -1);
|
|
149
|
+
Py_XDECREF(from_list);
|
|
150
|
+
if (module) {
|
|
151
|
+
if (parts_tuple) {
|
|
152
|
+
module = __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple);
|
|
153
|
+
}
|
|
154
|
+
return module;
|
|
155
|
+
}
|
|
156
|
+
if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError)))
|
|
157
|
+
return NULL;
|
|
158
|
+
PyErr_Clear();
|
|
159
|
+
// try absolute import
|
|
160
|
+
return __Pyx_ImportDottedModule(name, parts_tuple);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
/////////////// Import.proto ///////////////
|
|
165
|
+
|
|
166
|
+
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /*proto*/
|
|
167
|
+
|
|
168
|
+
/////////////// Import ///////////////
|
|
169
|
+
//@requires: ObjectHandling.c::PyObjectGetAttrStr
|
|
170
|
+
//@requires:StringTools.c::IncludeStringH
|
|
171
|
+
|
|
172
|
+
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
|
|
173
|
+
PyObject *module = 0;
|
|
174
|
+
PyObject *empty_dict = 0;
|
|
175
|
+
PyObject *empty_list = 0;
|
|
176
|
+
empty_dict = PyDict_New();
|
|
177
|
+
if (unlikely(!empty_dict))
|
|
178
|
+
goto bad;
|
|
179
|
+
if (level == -1) {
|
|
180
|
+
if (strchr(__Pyx_MODULE_NAME, '.') != (0)) {
|
|
181
|
+
/* try package relative import first */
|
|
182
|
+
module = PyImport_ImportModuleLevelObject(
|
|
183
|
+
name, NAMED_CGLOBAL(moddict_cname), empty_dict, from_list, 1);
|
|
184
|
+
if (unlikely(!module)) {
|
|
185
|
+
if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError)))
|
|
186
|
+
goto bad;
|
|
187
|
+
PyErr_Clear();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
level = 0; /* try absolute import on failure */
|
|
191
|
+
}
|
|
192
|
+
if (!module) {
|
|
193
|
+
module = PyImport_ImportModuleLevelObject(
|
|
194
|
+
name, NAMED_CGLOBAL(moddict_cname), empty_dict, from_list, level);
|
|
195
|
+
}
|
|
196
|
+
bad:
|
|
197
|
+
Py_XDECREF(empty_dict);
|
|
198
|
+
Py_XDECREF(empty_list);
|
|
199
|
+
return module;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
/////////////// ImportFrom.proto ///////////////
|
|
204
|
+
|
|
205
|
+
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /*proto*/
|
|
206
|
+
|
|
207
|
+
/////////////// ImportFrom ///////////////
|
|
208
|
+
//@requires: ObjectHandling.c::PyObjectGetAttrStr
|
|
209
|
+
|
|
210
|
+
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
|
|
211
|
+
PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
|
|
212
|
+
if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
|
213
|
+
// 'name' may refer to a (sub-)module which has not finished initialization
|
|
214
|
+
// yet, and may not be assigned as an attribute to its parent, so try
|
|
215
|
+
// finding it by full name.
|
|
216
|
+
const char* module_name_str = 0;
|
|
217
|
+
PyObject* module_name = 0;
|
|
218
|
+
PyObject* module_dot = 0;
|
|
219
|
+
PyObject* full_name = 0;
|
|
220
|
+
PyErr_Clear();
|
|
221
|
+
module_name_str = PyModule_GetName(module);
|
|
222
|
+
if (unlikely(!module_name_str)) { goto modbad; }
|
|
223
|
+
module_name = PyUnicode_FromString(module_name_str);
|
|
224
|
+
if (unlikely(!module_name)) { goto modbad; }
|
|
225
|
+
module_dot = PyUnicode_Concat(module_name, PYUNICODE("."));
|
|
226
|
+
if (unlikely(!module_dot)) { goto modbad; }
|
|
227
|
+
full_name = PyUnicode_Concat(module_dot, name);
|
|
228
|
+
if (unlikely(!full_name)) { goto modbad; }
|
|
229
|
+
#if (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) || \
|
|
230
|
+
CYTHON_COMPILING_IN_GRAAL
|
|
231
|
+
{
|
|
232
|
+
PyObject *modules = PyImport_GetModuleDict();
|
|
233
|
+
if (unlikely(!modules))
|
|
234
|
+
goto modbad;
|
|
235
|
+
value = PyObject_GetItem(modules, full_name);
|
|
236
|
+
}
|
|
237
|
+
#else
|
|
238
|
+
value = PyImport_GetModule(full_name);
|
|
239
|
+
#endif
|
|
240
|
+
|
|
241
|
+
modbad:
|
|
242
|
+
Py_XDECREF(full_name);
|
|
243
|
+
Py_XDECREF(module_dot);
|
|
244
|
+
Py_XDECREF(module_name);
|
|
245
|
+
}
|
|
246
|
+
if (unlikely(!value)) {
|
|
247
|
+
PyErr_Format(PyExc_ImportError, "cannot import name %S", name);
|
|
248
|
+
}
|
|
249
|
+
return value;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
/////////////// ImportStar ///////////////
|
|
254
|
+
//@substitute: naming
|
|
255
|
+
|
|
256
|
+
/* import_all_from is an unexposed function from ceval.c */
|
|
257
|
+
|
|
258
|
+
static int
|
|
259
|
+
__Pyx_import_all_from(PyObject *locals, PyObject *v)
|
|
260
|
+
{
|
|
261
|
+
PyObject *all = PyObject_GetAttrString(v, "__all__");
|
|
262
|
+
PyObject *dict, *name, *value;
|
|
263
|
+
int skip_leading_underscores = 0;
|
|
264
|
+
int pos, err;
|
|
265
|
+
|
|
266
|
+
if (all == NULL) {
|
|
267
|
+
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
|
|
268
|
+
return -1; /* Unexpected error */
|
|
269
|
+
PyErr_Clear();
|
|
270
|
+
dict = PyObject_GetAttrString(v, "__dict__");
|
|
271
|
+
if (dict == NULL) {
|
|
272
|
+
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
|
|
273
|
+
return -1;
|
|
274
|
+
PyErr_SetString(PyExc_ImportError,
|
|
275
|
+
"from-import-* object has no __dict__ and no __all__");
|
|
276
|
+
return -1;
|
|
277
|
+
}
|
|
278
|
+
all = PyMapping_Keys(dict);
|
|
279
|
+
Py_DECREF(dict);
|
|
280
|
+
if (all == NULL)
|
|
281
|
+
return -1;
|
|
282
|
+
skip_leading_underscores = 1;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
for (pos = 0, err = 0; ; pos++) {
|
|
286
|
+
name = PySequence_GetItem(all, pos);
|
|
287
|
+
if (name == NULL) {
|
|
288
|
+
if (!PyErr_ExceptionMatches(PyExc_IndexError))
|
|
289
|
+
err = -1;
|
|
290
|
+
else
|
|
291
|
+
PyErr_Clear();
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
if (skip_leading_underscores && likely(PyUnicode_Check(name))) {
|
|
295
|
+
Py_ssize_t length = __Pyx_PyUnicode_GET_LENGTH(name);
|
|
296
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
297
|
+
if (unlikely(length < 0)) {
|
|
298
|
+
Py_DECREF(name);
|
|
299
|
+
return -1;
|
|
300
|
+
}
|
|
301
|
+
#endif
|
|
302
|
+
if (likely(length) && __Pyx_PyUnicode_READ_CHAR(name, 0) == '_') {
|
|
303
|
+
Py_DECREF(name);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
value = PyObject_GetAttr(v, name);
|
|
308
|
+
if (value == NULL)
|
|
309
|
+
err = -1;
|
|
310
|
+
else if (PyDict_CheckExact(locals))
|
|
311
|
+
err = PyDict_SetItem(locals, name, value);
|
|
312
|
+
else
|
|
313
|
+
err = PyObject_SetItem(locals, name, value);
|
|
314
|
+
Py_DECREF(name);
|
|
315
|
+
Py_XDECREF(value);
|
|
316
|
+
if (err != 0)
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
Py_DECREF(all);
|
|
320
|
+
return err;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
static int ${import_star}(PyObject* m) {
|
|
325
|
+
|
|
326
|
+
int i;
|
|
327
|
+
int ret = -1;
|
|
328
|
+
const char* s;
|
|
329
|
+
PyObject *locals = 0;
|
|
330
|
+
PyObject *list = 0;
|
|
331
|
+
PyObject *utf8_name = 0;
|
|
332
|
+
PyObject *name;
|
|
333
|
+
PyObject *item;
|
|
334
|
+
PyObject *import_obj;
|
|
335
|
+
Py_ssize_t size;
|
|
336
|
+
${modulestatetype_cname} *mstate = __Pyx_PyModule_GetState(m);
|
|
337
|
+
|
|
338
|
+
locals = PyDict_New(); if (!locals) goto bad;
|
|
339
|
+
if (__Pyx_import_all_from(locals, m) < 0) goto bad;
|
|
340
|
+
list = PyDict_Items(locals); if (!list) goto bad;
|
|
341
|
+
|
|
342
|
+
size = __Pyx_PyList_GET_SIZE(list);
|
|
343
|
+
#if !CYTHON_ASSUME_SAFE_SIZE
|
|
344
|
+
if (size < 0) goto bad;
|
|
345
|
+
#endif
|
|
346
|
+
for(i=0; i<size; i++) {
|
|
347
|
+
import_obj = __Pyx_PyList_GET_ITEM(list, i); if (!import_obj) goto bad;
|
|
348
|
+
name = __Pyx_PyTuple_GET_ITEM(import_obj, 0); if (!name) goto bad;
|
|
349
|
+
item = __Pyx_PyTuple_GET_ITEM(import_obj, 1); if (!item) goto bad;
|
|
350
|
+
|
|
351
|
+
utf8_name = PyUnicode_AsUTF8String(name);
|
|
352
|
+
if (!utf8_name) goto bad;
|
|
353
|
+
s = __Pyx_PyBytes_AsString(utf8_name); if (!s) goto bad;
|
|
354
|
+
if (${import_star_set}(mstate, item, name, s) < 0) goto bad;
|
|
355
|
+
Py_DECREF(utf8_name); utf8_name = 0;
|
|
356
|
+
}
|
|
357
|
+
ret = 0;
|
|
358
|
+
|
|
359
|
+
bad:
|
|
360
|
+
Py_XDECREF(locals);
|
|
361
|
+
Py_XDECREF(list);
|
|
362
|
+
Py_XDECREF(utf8_name);
|
|
363
|
+
return ret;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
/////////////// SetPackagePathFromImportLib.proto ///////////////
|
|
368
|
+
|
|
369
|
+
#if !CYTHON_PEP489_MULTI_PHASE_INIT
|
|
370
|
+
static int __Pyx_SetPackagePathFromImportLib(PyObject *module_name);
|
|
371
|
+
#else
|
|
372
|
+
#define __Pyx_SetPackagePathFromImportLib(a) 0
|
|
373
|
+
#endif
|
|
374
|
+
|
|
375
|
+
/////////////// SetPackagePathFromImportLib ///////////////
|
|
376
|
+
//@substitute: naming
|
|
377
|
+
|
|
378
|
+
#if !CYTHON_PEP489_MULTI_PHASE_INIT
|
|
379
|
+
static int __Pyx_SetPackagePathFromImportLib(PyObject *module_name) {
|
|
380
|
+
PyObject *importlib, *osmod, *ossep, *parts, *package_path;
|
|
381
|
+
PyObject *file_path = NULL;
|
|
382
|
+
PyObject *item;
|
|
383
|
+
int result;
|
|
384
|
+
PyObject *spec;
|
|
385
|
+
// package_path = [importlib.util.find_spec(module_name).origin.rsplit(os.sep, 1)[0]]
|
|
386
|
+
importlib = PyImport_ImportModule("importlib.util");
|
|
387
|
+
if (unlikely(!importlib))
|
|
388
|
+
goto bad;
|
|
389
|
+
spec = PyObject_CallMethod(importlib, "find_spec", "(O)", module_name);
|
|
390
|
+
Py_DECREF(importlib);
|
|
391
|
+
if (unlikely(!spec))
|
|
392
|
+
goto bad;
|
|
393
|
+
file_path = PyObject_GetAttrString(spec, "origin");
|
|
394
|
+
Py_DECREF(spec);
|
|
395
|
+
if (unlikely(!file_path))
|
|
396
|
+
goto bad;
|
|
397
|
+
|
|
398
|
+
if (unlikely(PyObject_SetAttrString($module_cname, "__file__", file_path) < 0))
|
|
399
|
+
goto bad;
|
|
400
|
+
|
|
401
|
+
osmod = PyImport_ImportModule("os");
|
|
402
|
+
if (unlikely(!osmod))
|
|
403
|
+
goto bad;
|
|
404
|
+
ossep = PyObject_GetAttrString(osmod, "sep");
|
|
405
|
+
Py_DECREF(osmod);
|
|
406
|
+
if (unlikely(!ossep))
|
|
407
|
+
goto bad;
|
|
408
|
+
parts = PyObject_CallMethod(file_path, "rsplit", "(Oi)", ossep, 1);
|
|
409
|
+
Py_DECREF(file_path); file_path = NULL;
|
|
410
|
+
Py_DECREF(ossep);
|
|
411
|
+
if (unlikely(!parts))
|
|
412
|
+
goto bad;
|
|
413
|
+
#if CYTHON_ASSUME_SAFE_MACROS
|
|
414
|
+
package_path = Py_BuildValue("[O]", PyList_GET_ITEM(parts, 0));
|
|
415
|
+
#else
|
|
416
|
+
item = PyList_GetItem(parts, 0);
|
|
417
|
+
if (unlikely(!item))
|
|
418
|
+
goto bad;
|
|
419
|
+
package_path = Py_BuildValue("[O]", item);
|
|
420
|
+
#endif
|
|
421
|
+
Py_DECREF(parts);
|
|
422
|
+
if (unlikely(!package_path))
|
|
423
|
+
goto bad;
|
|
424
|
+
goto set_path;
|
|
425
|
+
|
|
426
|
+
bad:
|
|
427
|
+
PyErr_WriteUnraisable(module_name);
|
|
428
|
+
Py_XDECREF(file_path);
|
|
429
|
+
|
|
430
|
+
// set an empty path list on failure
|
|
431
|
+
PyErr_Clear();
|
|
432
|
+
package_path = PyList_New(0);
|
|
433
|
+
if (unlikely(!package_path))
|
|
434
|
+
return -1;
|
|
435
|
+
|
|
436
|
+
set_path:
|
|
437
|
+
result = PyObject_SetAttrString($module_cname, "__path__", package_path);
|
|
438
|
+
Py_DECREF(package_path);
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
441
|
+
#endif
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
/////////////// TypeImport.proto ///////////////
|
|
445
|
+
//@substitute: naming
|
|
446
|
+
|
|
447
|
+
#ifndef __PYX_HAVE_RT_ImportType_proto_$cyversion
|
|
448
|
+
#define __PYX_HAVE_RT_ImportType_proto_$cyversion
|
|
449
|
+
|
|
450
|
+
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
|
451
|
+
#include <stdalign.h>
|
|
452
|
+
#endif
|
|
453
|
+
|
|
454
|
+
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || __cplusplus >= 201103L
|
|
455
|
+
#define __PYX_GET_STRUCT_ALIGNMENT_$cyversion(s) alignof(s)
|
|
456
|
+
#else
|
|
457
|
+
// best guess at what the alignment could be since we can't measure it
|
|
458
|
+
#define __PYX_GET_STRUCT_ALIGNMENT_$cyversion(s) sizeof(void*)
|
|
459
|
+
#endif
|
|
460
|
+
|
|
461
|
+
enum __Pyx_ImportType_CheckSize_$cyversion {
|
|
462
|
+
__Pyx_ImportType_CheckSize_Error_$cyversion = 0,
|
|
463
|
+
__Pyx_ImportType_CheckSize_Warn_$cyversion = 1,
|
|
464
|
+
__Pyx_ImportType_CheckSize_Ignore_$cyversion = 2
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
static PyTypeObject *__Pyx_ImportType_$cyversion(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_$cyversion check_size); /*proto*/
|
|
468
|
+
|
|
469
|
+
#endif
|
|
470
|
+
|
|
471
|
+
/////////////// TypeImport ///////////////
|
|
472
|
+
//@substitute: naming
|
|
473
|
+
|
|
474
|
+
#ifndef __PYX_HAVE_RT_ImportType_$cyversion
|
|
475
|
+
#define __PYX_HAVE_RT_ImportType_$cyversion
|
|
476
|
+
static PyTypeObject *__Pyx_ImportType_$cyversion(PyObject *module, const char *module_name, const char *class_name,
|
|
477
|
+
size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_$cyversion check_size)
|
|
478
|
+
{
|
|
479
|
+
PyObject *result = 0;
|
|
480
|
+
char warning[200];
|
|
481
|
+
Py_ssize_t basicsize;
|
|
482
|
+
Py_ssize_t itemsize;
|
|
483
|
+
#if CYTHON_COMPILING_IN_LIMITED_API
|
|
484
|
+
PyObject *py_basicsize;
|
|
485
|
+
PyObject *py_itemsize;
|
|
486
|
+
#endif
|
|
487
|
+
|
|
488
|
+
result = PyObject_GetAttrString(module, class_name);
|
|
489
|
+
if (!result)
|
|
490
|
+
goto bad;
|
|
491
|
+
if (!PyType_Check(result)) {
|
|
492
|
+
PyErr_Format(PyExc_TypeError,
|
|
493
|
+
"%.200s.%.200s is not a type object",
|
|
494
|
+
module_name, class_name);
|
|
495
|
+
goto bad;
|
|
496
|
+
}
|
|
497
|
+
#if !CYTHON_COMPILING_IN_LIMITED_API
|
|
498
|
+
basicsize = ((PyTypeObject *)result)->tp_basicsize;
|
|
499
|
+
itemsize = ((PyTypeObject *)result)->tp_itemsize;
|
|
500
|
+
#else
|
|
501
|
+
if (size == 0) {
|
|
502
|
+
return (PyTypeObject *)result;
|
|
503
|
+
}
|
|
504
|
+
py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
|
|
505
|
+
if (!py_basicsize)
|
|
506
|
+
goto bad;
|
|
507
|
+
basicsize = PyLong_AsSsize_t(py_basicsize);
|
|
508
|
+
Py_DECREF(py_basicsize);
|
|
509
|
+
py_basicsize = 0;
|
|
510
|
+
if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
|
|
511
|
+
goto bad;
|
|
512
|
+
py_itemsize = PyObject_GetAttrString(result, "__itemsize__");
|
|
513
|
+
if (!py_itemsize)
|
|
514
|
+
goto bad;
|
|
515
|
+
itemsize = PyLong_AsSsize_t(py_itemsize);
|
|
516
|
+
Py_DECREF(py_itemsize);
|
|
517
|
+
py_itemsize = 0;
|
|
518
|
+
if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred())
|
|
519
|
+
goto bad;
|
|
520
|
+
#endif
|
|
521
|
+
if (itemsize) {
|
|
522
|
+
// If itemsize is smaller than the alignment the struct can end up with some extra
|
|
523
|
+
// padding at the end. In this case we need to work out the maximum size that
|
|
524
|
+
// the padding could be when calculating the range of valid struct sizes.
|
|
525
|
+
if (size % alignment) {
|
|
526
|
+
// if this is true we've probably calculated the alignment wrongly
|
|
527
|
+
// (most likely because alignof isn't available)
|
|
528
|
+
alignment = size % alignment;
|
|
529
|
+
}
|
|
530
|
+
if (itemsize < (Py_ssize_t)alignment)
|
|
531
|
+
itemsize = (Py_ssize_t)alignment;
|
|
532
|
+
}
|
|
533
|
+
if ((size_t)(basicsize + itemsize) < size) {
|
|
534
|
+
PyErr_Format(PyExc_ValueError,
|
|
535
|
+
"%.200s.%.200s size changed, may indicate binary incompatibility. "
|
|
536
|
+
"Expected %zd from C header, got %zd from PyObject",
|
|
537
|
+
module_name, class_name, size, basicsize+itemsize);
|
|
538
|
+
goto bad;
|
|
539
|
+
}
|
|
540
|
+
// varobjects almost have structs between basicsize and basicsize + itemsize
|
|
541
|
+
// but the struct isn't always one of the two limiting values
|
|
542
|
+
if (check_size == __Pyx_ImportType_CheckSize_Error_$cyversion &&
|
|
543
|
+
((size_t)basicsize > size || (size_t)(basicsize + itemsize) < size)) {
|
|
544
|
+
PyErr_Format(PyExc_ValueError,
|
|
545
|
+
"%.200s.%.200s size changed, may indicate binary incompatibility. "
|
|
546
|
+
"Expected %zd from C header, got %zd-%zd from PyObject",
|
|
547
|
+
module_name, class_name, size, basicsize, basicsize+itemsize);
|
|
548
|
+
goto bad;
|
|
549
|
+
}
|
|
550
|
+
else if (check_size == __Pyx_ImportType_CheckSize_Warn_$cyversion && (size_t)basicsize > size) {
|
|
551
|
+
PyOS_snprintf(warning, sizeof(warning),
|
|
552
|
+
"%s.%s size changed, may indicate binary incompatibility. "
|
|
553
|
+
"Expected %zd from C header, got %zd from PyObject",
|
|
554
|
+
module_name, class_name, size, basicsize);
|
|
555
|
+
if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
|
|
556
|
+
}
|
|
557
|
+
/* check_size == __Pyx_ImportType_CheckSize_Ignore does not warn nor error */
|
|
558
|
+
return (PyTypeObject *)result;
|
|
559
|
+
bad:
|
|
560
|
+
Py_XDECREF(result);
|
|
561
|
+
return NULL;
|
|
562
|
+
}
|
|
563
|
+
#endif
|
|
564
|
+
|
|
565
|
+
/////////////// FunctionImport.proto ///////////////
|
|
566
|
+
//@substitute: naming
|
|
567
|
+
|
|
568
|
+
static int __Pyx_ImportFunction_$cyversion(PyObject *module, const char *funcname, void (**f)(void), const char *sig); /*proto*/
|
|
569
|
+
|
|
570
|
+
/////////////// FunctionImport ///////////////
|
|
571
|
+
//@substitute: naming
|
|
572
|
+
|
|
573
|
+
#ifndef __PYX_HAVE_RT_ImportFunction_$cyversion
|
|
574
|
+
#define __PYX_HAVE_RT_ImportFunction_$cyversion
|
|
575
|
+
static int __Pyx_ImportFunction_$cyversion(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
|
|
576
|
+
PyObject *d = 0;
|
|
577
|
+
PyObject *cobj = 0;
|
|
578
|
+
union {
|
|
579
|
+
void (*fp)(void);
|
|
580
|
+
void *p;
|
|
581
|
+
} tmp;
|
|
582
|
+
|
|
583
|
+
d = PyObject_GetAttrString(module, "$api_name");
|
|
584
|
+
if (!d)
|
|
585
|
+
goto bad;
|
|
586
|
+
#if PY_VERSION_HEX >= 0x030d0000
|
|
587
|
+
PyDict_GetItemStringRef(d, funcname, &cobj);
|
|
588
|
+
#else
|
|
589
|
+
cobj = PyDict_GetItemString(d, funcname);
|
|
590
|
+
Py_XINCREF(cobj);
|
|
591
|
+
#endif
|
|
592
|
+
if (!cobj) {
|
|
593
|
+
PyErr_Format(PyExc_ImportError,
|
|
594
|
+
"%.200s does not export expected C function %.200s",
|
|
595
|
+
PyModule_GetName(module), funcname);
|
|
596
|
+
goto bad;
|
|
597
|
+
}
|
|
598
|
+
if (!PyCapsule_IsValid(cobj, sig)) {
|
|
599
|
+
PyErr_Format(PyExc_TypeError,
|
|
600
|
+
"C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
|
|
601
|
+
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
|
|
602
|
+
goto bad;
|
|
603
|
+
}
|
|
604
|
+
tmp.p = PyCapsule_GetPointer(cobj, sig);
|
|
605
|
+
*f = tmp.fp;
|
|
606
|
+
if (!(*f))
|
|
607
|
+
goto bad;
|
|
608
|
+
Py_DECREF(d);
|
|
609
|
+
Py_DECREF(cobj);
|
|
610
|
+
return 0;
|
|
611
|
+
bad:
|
|
612
|
+
Py_XDECREF(d);
|
|
613
|
+
Py_XDECREF(cobj);
|
|
614
|
+
return -1;
|
|
615
|
+
}
|
|
616
|
+
#endif
|
|
617
|
+
|
|
618
|
+
/////////////// FunctionExport.proto ///////////////
|
|
619
|
+
|
|
620
|
+
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig); /*proto*/
|
|
621
|
+
|
|
622
|
+
/////////////// FunctionExport ///////////////
|
|
623
|
+
//@substitute: naming
|
|
624
|
+
|
|
625
|
+
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
|
|
626
|
+
PyObject *d = 0;
|
|
627
|
+
PyObject *cobj = 0;
|
|
628
|
+
union {
|
|
629
|
+
void (*fp)(void);
|
|
630
|
+
void *p;
|
|
631
|
+
} tmp;
|
|
632
|
+
|
|
633
|
+
d = PyObject_GetAttrString($module_cname, "$api_name");
|
|
634
|
+
if (!d) {
|
|
635
|
+
PyErr_Clear();
|
|
636
|
+
d = PyDict_New();
|
|
637
|
+
if (!d)
|
|
638
|
+
goto bad;
|
|
639
|
+
Py_INCREF(d);
|
|
640
|
+
if (PyModule_AddObject($module_cname, "$api_name", d) < 0)
|
|
641
|
+
goto bad;
|
|
642
|
+
}
|
|
643
|
+
tmp.fp = f;
|
|
644
|
+
cobj = PyCapsule_New(tmp.p, sig, 0);
|
|
645
|
+
if (!cobj)
|
|
646
|
+
goto bad;
|
|
647
|
+
if (PyDict_SetItemString(d, name, cobj) < 0)
|
|
648
|
+
goto bad;
|
|
649
|
+
Py_DECREF(cobj);
|
|
650
|
+
Py_DECREF(d);
|
|
651
|
+
return 0;
|
|
652
|
+
bad:
|
|
653
|
+
Py_XDECREF(cobj);
|
|
654
|
+
Py_XDECREF(d);
|
|
655
|
+
return -1;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/////////////// VoidPtrImport.proto ///////////////
|
|
659
|
+
//@substitute: naming
|
|
660
|
+
|
|
661
|
+
static int __Pyx_ImportVoidPtr_$cyversion(PyObject *module, const char *name, void **p, const char *sig); /*proto*/
|
|
662
|
+
|
|
663
|
+
/////////////// VoidPtrImport ///////////////
|
|
664
|
+
//@substitute: naming
|
|
665
|
+
|
|
666
|
+
#ifndef __PYX_HAVE_RT_ImportVoidPtr_$cyversion
|
|
667
|
+
#define __PYX_HAVE_RT_ImportVoidPtr_$cyversion
|
|
668
|
+
static int __Pyx_ImportVoidPtr_$cyversion(PyObject *module, const char *name, void **p, const char *sig) {
|
|
669
|
+
PyObject *d = 0;
|
|
670
|
+
PyObject *cobj = 0;
|
|
671
|
+
|
|
672
|
+
d = PyObject_GetAttrString(module, "$api_name");
|
|
673
|
+
if (!d)
|
|
674
|
+
goto bad;
|
|
675
|
+
#if PY_VERSION_HEX >= 0x030d0000
|
|
676
|
+
PyDict_GetItemStringRef(d, name, &cobj);
|
|
677
|
+
#else
|
|
678
|
+
cobj = PyDict_GetItemString(d, name);
|
|
679
|
+
Py_XINCREF(cobj);
|
|
680
|
+
#endif
|
|
681
|
+
if (!cobj) {
|
|
682
|
+
PyErr_Format(PyExc_ImportError,
|
|
683
|
+
"%.200s does not export expected C variable %.200s",
|
|
684
|
+
PyModule_GetName(module), name);
|
|
685
|
+
goto bad;
|
|
686
|
+
}
|
|
687
|
+
if (!PyCapsule_IsValid(cobj, sig)) {
|
|
688
|
+
PyErr_Format(PyExc_TypeError,
|
|
689
|
+
"C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
|
|
690
|
+
PyModule_GetName(module), name, sig, PyCapsule_GetName(cobj));
|
|
691
|
+
goto bad;
|
|
692
|
+
}
|
|
693
|
+
*p = PyCapsule_GetPointer(cobj, sig);
|
|
694
|
+
if (!(*p))
|
|
695
|
+
goto bad;
|
|
696
|
+
Py_DECREF(d);
|
|
697
|
+
Py_DECREF(cobj);
|
|
698
|
+
return 0;
|
|
699
|
+
bad:
|
|
700
|
+
Py_XDECREF(d);
|
|
701
|
+
Py_XDECREF(cobj);
|
|
702
|
+
return -1;
|
|
703
|
+
}
|
|
704
|
+
#endif
|
|
705
|
+
|
|
706
|
+
/////////////// VoidPtrExport.proto ///////////////
|
|
707
|
+
|
|
708
|
+
static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig); /*proto*/
|
|
709
|
+
|
|
710
|
+
/////////////// VoidPtrExport ///////////////
|
|
711
|
+
//@substitute: naming
|
|
712
|
+
//@requires: ObjectHandling.c::PyObjectSetAttrStr
|
|
713
|
+
|
|
714
|
+
static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig) {
|
|
715
|
+
PyObject *d;
|
|
716
|
+
PyObject *cobj = 0;
|
|
717
|
+
|
|
718
|
+
if (__Pyx_PyDict_GetItemRef(NAMED_CGLOBAL(moddict_cname), PYIDENT("$api_name"), &d) == -1)
|
|
719
|
+
goto bad;
|
|
720
|
+
if (!d) {
|
|
721
|
+
d = PyDict_New();
|
|
722
|
+
if (!d)
|
|
723
|
+
goto bad;
|
|
724
|
+
if (__Pyx_PyObject_SetAttrStr($module_cname, PYIDENT("$api_name"), d) < 0)
|
|
725
|
+
goto bad;
|
|
726
|
+
}
|
|
727
|
+
cobj = PyCapsule_New(p, sig, 0);
|
|
728
|
+
if (!cobj)
|
|
729
|
+
goto bad;
|
|
730
|
+
if (PyDict_SetItem(d, name, cobj) < 0)
|
|
731
|
+
goto bad;
|
|
732
|
+
Py_DECREF(cobj);
|
|
733
|
+
Py_DECREF(d);
|
|
734
|
+
return 0;
|
|
735
|
+
bad:
|
|
736
|
+
Py_XDECREF(cobj);
|
|
737
|
+
Py_XDECREF(d);
|
|
738
|
+
return -1;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
/////////////// SetVTable.proto ///////////////
|
|
743
|
+
|
|
744
|
+
static int __Pyx_SetVtable(PyTypeObject* typeptr , void* vtable); /*proto*/
|
|
745
|
+
|
|
746
|
+
/////////////// SetVTable ///////////////
|
|
747
|
+
|
|
748
|
+
static int __Pyx_SetVtable(PyTypeObject *type, void *vtable) {
|
|
749
|
+
PyObject *ob = PyCapsule_New(vtable, 0, 0);
|
|
750
|
+
if (unlikely(!ob))
|
|
751
|
+
goto bad;
|
|
752
|
+
#if CYTHON_COMPILING_IN_LIMITED_API
|
|
753
|
+
if (unlikely(PyObject_SetAttr((PyObject *) type, PYIDENT("__pyx_vtable__"), ob) < 0))
|
|
754
|
+
#else
|
|
755
|
+
if (unlikely(PyDict_SetItem(type->tp_dict, PYIDENT("__pyx_vtable__"), ob) < 0))
|
|
756
|
+
#endif
|
|
757
|
+
goto bad;
|
|
758
|
+
Py_DECREF(ob);
|
|
759
|
+
return 0;
|
|
760
|
+
bad:
|
|
761
|
+
Py_XDECREF(ob);
|
|
762
|
+
return -1;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
/////////////// GetVTable.proto ///////////////
|
|
767
|
+
|
|
768
|
+
static void* __Pyx_GetVtable(PyTypeObject *type); /*proto*/
|
|
769
|
+
|
|
770
|
+
/////////////// GetVTable ///////////////
|
|
771
|
+
|
|
772
|
+
static void* __Pyx_GetVtable(PyTypeObject *type) {
|
|
773
|
+
void* ptr;
|
|
774
|
+
#if CYTHON_COMPILING_IN_LIMITED_API
|
|
775
|
+
PyObject *ob = PyObject_GetAttr((PyObject *)type, PYIDENT("__pyx_vtable__"));
|
|
776
|
+
#else
|
|
777
|
+
PyObject *ob = PyObject_GetItem(type->tp_dict, PYIDENT("__pyx_vtable__"));
|
|
778
|
+
#endif
|
|
779
|
+
if (!ob)
|
|
780
|
+
goto bad;
|
|
781
|
+
ptr = PyCapsule_GetPointer(ob, 0);
|
|
782
|
+
if (!ptr && !PyErr_Occurred())
|
|
783
|
+
PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
|
|
784
|
+
Py_DECREF(ob);
|
|
785
|
+
return ptr;
|
|
786
|
+
bad:
|
|
787
|
+
Py_XDECREF(ob);
|
|
788
|
+
return NULL;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
/////////////// MergeVTables.proto ///////////////
|
|
793
|
+
//@requires: GetVTable
|
|
794
|
+
|
|
795
|
+
static int __Pyx_MergeVtables(PyTypeObject *type); /*proto*/
|
|
796
|
+
|
|
797
|
+
/////////////// MergeVTables ///////////////
|
|
798
|
+
|
|
799
|
+
static int __Pyx_MergeVtables(PyTypeObject *type) {
|
|
800
|
+
int i=0;
|
|
801
|
+
Py_ssize_t size;
|
|
802
|
+
void** base_vtables;
|
|
803
|
+
__Pyx_TypeName tp_base_name = NULL;
|
|
804
|
+
__Pyx_TypeName base_name = NULL;
|
|
805
|
+
void* unknown = (void*)-1;
|
|
806
|
+
PyObject* bases = __Pyx_PyType_GetSlot(type, tp_bases, PyObject*);
|
|
807
|
+
int base_depth = 0;
|
|
808
|
+
{
|
|
809
|
+
PyTypeObject* base = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
|
|
810
|
+
while (base) {
|
|
811
|
+
base_depth += 1;
|
|
812
|
+
base = __Pyx_PyType_GetSlot(base, tp_base, PyTypeObject*);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
base_vtables = (void**) PyMem_Malloc(sizeof(void*) * (size_t)(base_depth + 1));
|
|
816
|
+
base_vtables[0] = unknown;
|
|
817
|
+
// Could do MRO resolution of individual methods in the future, assuming
|
|
818
|
+
// compatible vtables, but for now simply require a common vtable base.
|
|
819
|
+
// Note that if the vtables of various bases are extended separately,
|
|
820
|
+
// resolution isn't possible and we must reject it just as when the
|
|
821
|
+
// instance struct is so extended. (It would be good to also do this
|
|
822
|
+
// check when a multiple-base class is created in pure Python as well.)
|
|
823
|
+
#if CYTHON_COMPILING_IN_LIMITED_API
|
|
824
|
+
size = PyTuple_Size(bases);
|
|
825
|
+
if (size < 0) goto other_failure;
|
|
826
|
+
#else
|
|
827
|
+
size = PyTuple_GET_SIZE(bases);
|
|
828
|
+
#endif
|
|
829
|
+
for (i = 1; i < size; i++) {
|
|
830
|
+
PyObject *basei;
|
|
831
|
+
void* base_vtable;
|
|
832
|
+
#if CYTHON_AVOID_BORROWED_REFS
|
|
833
|
+
basei = PySequence_GetItem(bases, i);
|
|
834
|
+
if (unlikely(!basei)) goto other_failure;
|
|
835
|
+
#elif !CYTHON_ASSUME_SAFE_MACROS
|
|
836
|
+
basei = PyTuple_GetItem(bases, i);
|
|
837
|
+
if (unlikely(!basei)) goto other_failure;
|
|
838
|
+
#else
|
|
839
|
+
basei = PyTuple_GET_ITEM(bases, i);
|
|
840
|
+
#endif
|
|
841
|
+
base_vtable = __Pyx_GetVtable((PyTypeObject*)basei);
|
|
842
|
+
#if CYTHON_AVOID_BORROWED_REFS
|
|
843
|
+
Py_DECREF(basei);
|
|
844
|
+
#endif
|
|
845
|
+
if (base_vtable != NULL) {
|
|
846
|
+
int j;
|
|
847
|
+
PyTypeObject* base = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
|
|
848
|
+
for (j = 0; j < base_depth; j++) {
|
|
849
|
+
if (base_vtables[j] == unknown) {
|
|
850
|
+
base_vtables[j] = __Pyx_GetVtable(base);
|
|
851
|
+
base_vtables[j + 1] = unknown;
|
|
852
|
+
}
|
|
853
|
+
if (base_vtables[j] == base_vtable) {
|
|
854
|
+
break;
|
|
855
|
+
} else if (base_vtables[j] == NULL) {
|
|
856
|
+
// No more potential matching bases (with vtables).
|
|
857
|
+
goto bad;
|
|
858
|
+
}
|
|
859
|
+
base = __Pyx_PyType_GetSlot(base, tp_base, PyTypeObject*);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
PyErr_Clear();
|
|
864
|
+
PyMem_Free(base_vtables);
|
|
865
|
+
return 0;
|
|
866
|
+
bad:
|
|
867
|
+
{
|
|
868
|
+
PyTypeObject* basei = NULL;
|
|
869
|
+
PyTypeObject* tp_base = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
|
|
870
|
+
tp_base_name = __Pyx_PyType_GetFullyQualifiedName(tp_base);
|
|
871
|
+
#if CYTHON_AVOID_BORROWED_REFS
|
|
872
|
+
basei = (PyTypeObject*)PySequence_GetItem(bases, i);
|
|
873
|
+
if (unlikely(!basei)) goto really_bad;
|
|
874
|
+
#elif !CYTHON_ASSUME_SAFE_MACROS
|
|
875
|
+
basei = (PyTypeObject*)PyTuple_GetItem(bases, i);
|
|
876
|
+
if (unlikely(!basei)) goto really_bad;
|
|
877
|
+
#else
|
|
878
|
+
basei = (PyTypeObject*)PyTuple_GET_ITEM(bases, i);
|
|
879
|
+
#endif
|
|
880
|
+
base_name = __Pyx_PyType_GetFullyQualifiedName(basei);
|
|
881
|
+
#if CYTHON_AVOID_BORROWED_REFS
|
|
882
|
+
Py_DECREF(basei);
|
|
883
|
+
#endif
|
|
884
|
+
}
|
|
885
|
+
PyErr_Format(PyExc_TypeError,
|
|
886
|
+
"multiple bases have vtable conflict: '" __Pyx_FMT_TYPENAME "' and '" __Pyx_FMT_TYPENAME "'", tp_base_name, base_name);
|
|
887
|
+
#if CYTHON_AVOID_BORROWED_REFS || !CYTHON_ASSUME_SAFE_MACROS
|
|
888
|
+
really_bad: // bad has failed!
|
|
889
|
+
#endif
|
|
890
|
+
__Pyx_DECREF_TypeName(tp_base_name);
|
|
891
|
+
__Pyx_DECREF_TypeName(base_name);
|
|
892
|
+
#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_AVOID_BORROWED_REFS || !CYTHON_ASSUME_SAFE_MACROS
|
|
893
|
+
other_failure:
|
|
894
|
+
#endif
|
|
895
|
+
PyMem_Free(base_vtables);
|
|
896
|
+
return -1;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/////////////// ImportNumPyArray.module_state_decls //////////////
|
|
900
|
+
//@requires: MemoryView_C.c::Atomics
|
|
901
|
+
|
|
902
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
903
|
+
__pyx_atomic_ptr_type __pyx_numpy_ndarray;
|
|
904
|
+
#else
|
|
905
|
+
// If freethreading but not atomics, then this is guarded by ndarray_mutex
|
|
906
|
+
// in __Pyx__ImportNumPyArrayTypeIfAvailable
|
|
907
|
+
PyObject *__pyx_numpy_ndarray;
|
|
908
|
+
#endif
|
|
909
|
+
|
|
910
|
+
/////////////// ImportNumPyArray.proto ///////////////
|
|
911
|
+
|
|
912
|
+
static PyObject* __Pyx_ImportNumPyArrayTypeIfAvailable(void); /*proto*/
|
|
913
|
+
|
|
914
|
+
/////////////// ImportNumPyArray.cleanup ///////////////
|
|
915
|
+
|
|
916
|
+
// I'm not actually worried about thread-safety in the cleanup function.
|
|
917
|
+
// The CYTHON_ATOMICS code is only for the type-casting.
|
|
918
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
919
|
+
{
|
|
920
|
+
PyObject* old = (PyObject*)__pyx_atomic_pointer_exchange(&CGLOBAL(__pyx_numpy_ndarray), NULL);
|
|
921
|
+
Py_XDECREF(old);
|
|
922
|
+
}
|
|
923
|
+
#else
|
|
924
|
+
Py_CLEAR(CGLOBAL(__pyx_numpy_ndarray));
|
|
925
|
+
#endif
|
|
926
|
+
|
|
927
|
+
/////////////// ImportNumPyArray ///////////////
|
|
928
|
+
//@requires: ImportExport.c::Import
|
|
929
|
+
|
|
930
|
+
static PyObject* __Pyx__ImportNumPyArray(void) {
|
|
931
|
+
PyObject *numpy_module, *ndarray_object = NULL;
|
|
932
|
+
numpy_module = __Pyx_Import(PYIDENT("numpy"), NULL, 0);
|
|
933
|
+
if (likely(numpy_module)) {
|
|
934
|
+
ndarray_object = PyObject_GetAttrString(numpy_module, "ndarray");
|
|
935
|
+
Py_DECREF(numpy_module);
|
|
936
|
+
}
|
|
937
|
+
if (unlikely(!ndarray_object)) {
|
|
938
|
+
// ImportError, AttributeError, ...
|
|
939
|
+
PyErr_Clear();
|
|
940
|
+
}
|
|
941
|
+
if (unlikely(!ndarray_object || !PyObject_TypeCheck(ndarray_object, &PyType_Type))) {
|
|
942
|
+
Py_XDECREF(ndarray_object);
|
|
943
|
+
Py_INCREF(Py_None);
|
|
944
|
+
ndarray_object = Py_None;
|
|
945
|
+
}
|
|
946
|
+
return ndarray_object;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// Returns a borrowed reference, and encapsulates all thread safety stuff needed
|
|
950
|
+
static CYTHON_INLINE PyObject* __Pyx__ImportNumPyArrayTypeIfAvailable(void) {
|
|
951
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING
|
|
952
|
+
static PyMutex ndarray_mutex = {0};
|
|
953
|
+
#endif
|
|
954
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING && CYTHON_ATOMICS
|
|
955
|
+
PyObject *result = (PyObject*)__pyx_atomic_pointer_load_relaxed(&CGLOBAL(__pyx_numpy_ndarray));
|
|
956
|
+
if (unlikely(!result)) {
|
|
957
|
+
PyMutex_Lock(&ndarray_mutex);
|
|
958
|
+
// Now we've got the lock and know that no-one else is modifying it, check again
|
|
959
|
+
// that it hasn't already been set.
|
|
960
|
+
result = (PyObject*)__pyx_atomic_pointer_load_acquire(&CGLOBAL(__pyx_numpy_ndarray));
|
|
961
|
+
if (!result) {
|
|
962
|
+
result = __Pyx__ImportNumPyArray();
|
|
963
|
+
__pyx_atomic_pointer_exchange(&CGLOBAL(__pyx_numpy_ndarray), result);
|
|
964
|
+
}
|
|
965
|
+
PyMutex_Unlock(&ndarray_mutex);
|
|
966
|
+
}
|
|
967
|
+
return result;
|
|
968
|
+
#else
|
|
969
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING // but not atomics
|
|
970
|
+
PyMutex_Lock(&ndarray_mutex);
|
|
971
|
+
#endif
|
|
972
|
+
if (unlikely(!CGLOBAL(__pyx_numpy_ndarray)))
|
|
973
|
+
{
|
|
974
|
+
CGLOBAL(__pyx_numpy_ndarray) = __Pyx__ImportNumPyArray();
|
|
975
|
+
}
|
|
976
|
+
#if CYTHON_COMPILING_IN_CPYTHON_FREETHREADING // but not atomics
|
|
977
|
+
PyMutex_Unlock(&ndarray_mutex);
|
|
978
|
+
#endif
|
|
979
|
+
return CGLOBAL(__pyx_numpy_ndarray);
|
|
980
|
+
#endif
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
static CYTHON_INLINE PyObject* __Pyx_ImportNumPyArrayTypeIfAvailable(void) {
|
|
984
|
+
PyObject *result = __Pyx__ImportNumPyArrayTypeIfAvailable();
|
|
985
|
+
Py_INCREF(result);
|
|
986
|
+
return result;
|
|
987
|
+
}
|