Cython 3.1.6__py3-none-any.whl → 3.2.0b2__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/Cythonize.py +1 -1
- Cython/Build/Dependencies.py +9 -6
- Cython/Build/SharedModule.py +19 -1
- Cython/CodeWriter.py +6 -2
- Cython/Compiler/Annotate.py +6 -3
- Cython/Compiler/AutoDocTransforms.py +1 -1
- Cython/Compiler/Builtin.py +82 -46
- Cython/Compiler/CmdLine.py +4 -0
- Cython/Compiler/Code.pxd +42 -41
- Cython/Compiler/Code.py +556 -201
- Cython/Compiler/Dataclass.py +10 -14
- Cython/Compiler/Errors.py +7 -5
- Cython/Compiler/ExprNodes.py +478 -224
- Cython/Compiler/FlowControl.py +14 -18
- Cython/Compiler/FusedNode.py +192 -224
- Cython/Compiler/Lexicon.py +78 -5
- Cython/Compiler/LineTable.py +2 -2
- Cython/Compiler/Main.py +15 -11
- Cython/Compiler/MemoryView.py +32 -54
- Cython/Compiler/ModuleNode.py +373 -190
- Cython/Compiler/Naming.py +4 -15
- Cython/Compiler/Nodes.py +227 -221
- Cython/Compiler/Optimize.py +309 -277
- Cython/Compiler/Options.py +10 -2
- Cython/Compiler/ParseTreeTransforms.py +177 -62
- Cython/Compiler/Parsing.py +270 -284
- Cython/Compiler/PyrexTypes.py +147 -65
- Cython/Compiler/Scanning.pxd +8 -0
- Cython/Compiler/Scanning.py +145 -14
- Cython/Compiler/StringEncoding.py +19 -70
- Cython/Compiler/Symtab.py +11 -16
- Cython/Compiler/Tests/TestCode.py +59 -1
- Cython/Compiler/Tests/TestStringEncoding.py +0 -12
- Cython/Compiler/TypeInference.py +21 -14
- Cython/Compiler/TypeSlots.py +14 -17
- Cython/Debugger/Cygdb.py +1 -1
- Cython/Debugger/libcython.py +1 -1
- Cython/Debugger/libpython.py +1 -1
- Cython/Includes/cpython/array.pxd +10 -6
- Cython/Includes/cpython/datetime.pxd +3 -3
- Cython/Includes/cpython/object.pxd +32 -32
- Cython/Includes/libc/threads.pxd +153 -3
- Cython/Includes/libc/time.pxd +1 -0
- Cython/Includes/libcpp/condition_variable.pxd +322 -0
- Cython/Includes/libcpp/mutex.pxd +257 -0
- Cython/Includes/libcpp/semaphore.pxd +0 -1
- Cython/Includes/libcpp/shared_mutex.pxd +24 -0
- Cython/Includes/libcpp/stop_token.pxd +14 -2
- Cython/Includes/libcpp/string_view.pxd +2 -0
- Cython/Plex/Machines.py +2 -2
- Cython/Plex/Regexps.py +4 -8
- Cython/Plex/Scanners.pxd +0 -1
- Cython/Plex/Scanners.py +0 -33
- Cython/Runtime/refnanny.pyx +1 -1
- Cython/Shadow.py +2 -2
- Cython/TestUtils.py +12 -0
- Cython/Utility/AsyncGen.c +48 -22
- Cython/Utility/Buffer.c +0 -10
- Cython/Utility/Builtins.c +37 -3
- Cython/Utility/CommonStructures.c +33 -10
- Cython/Utility/Coroutine.c +92 -12
- Cython/Utility/CppSupport.cpp +8 -0
- Cython/Utility/CythonFunction.c +92 -65
- Cython/Utility/Dataclasses.c +5 -89
- Cython/Utility/Embed.c +13 -17
- Cython/Utility/Exceptions.c +40 -36
- Cython/Utility/ExtensionTypes.c +159 -5
- Cython/Utility/FunctionArguments.c +108 -36
- Cython/Utility/FusedFunction.pyx +44 -0
- Cython/Utility/ImportExport.c +154 -238
- Cython/Utility/MemoryView.pxd +2 -1
- Cython/Utility/MemoryView.pyx +3 -2
- Cython/Utility/MemoryView_C.c +100 -74
- Cython/Utility/ModuleSetupCode.c +197 -97
- Cython/Utility/ObjectHandling.c +208 -302
- Cython/Utility/Optimize.c +115 -124
- Cython/Utility/Overflow.c +0 -28
- Cython/Utility/StringTools.c +211 -109
- Cython/Utility/Synchronization.c +55 -21
- Cython/Utility/TString.c +356 -0
- Cython/Utility/TypeConversion.c +100 -19
- Cython/Utility/arrayarray.h +42 -23
- {cython-3.1.6.dist-info → cython-3.2.0b2.dist-info}/METADATA +48 -4
- {cython-3.1.6.dist-info → cython-3.2.0b2.dist-info}/RECORD +88 -86
- cython.py +1 -1
- Cython/Utility/Dataclasses.py +0 -112
- {cython-3.1.6.dist-info → cython-3.2.0b2.dist-info}/WHEEL +0 -0
- {cython-3.1.6.dist-info → cython-3.2.0b2.dist-info}/entry_points.txt +0 -0
- {cython-3.1.6.dist-info → cython-3.2.0b2.dist-info}/top_level.txt +0 -0
Cython/Build/Cythonize.py
CHANGED
|
@@ -26,7 +26,7 @@ def find_package_base(path):
|
|
|
26
26
|
return base_dir, package_path
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
def cython_compile(path_pattern, options)
|
|
29
|
+
def cython_compile(path_pattern, options):
|
|
30
30
|
all_paths = map(os.path.abspath, extended_iglob(path_pattern))
|
|
31
31
|
ext_modules_by_basedir = _cython_compile_files(all_paths, options)
|
|
32
32
|
_build(list(ext_modules_by_basedir.items()), options.parallel)
|
Cython/Build/Dependencies.py
CHANGED
|
@@ -773,6 +773,10 @@ def create_extension_list(patterns, exclude=None, ctx=None, aliases=None, quiet=
|
|
|
773
773
|
elif isinstance(pattern, extension_classes):
|
|
774
774
|
cython_sources = [s for s in pattern.sources
|
|
775
775
|
if os.path.splitext(s)[1] in ('.py', '.pyx')]
|
|
776
|
+
template = pattern
|
|
777
|
+
name = template.name
|
|
778
|
+
base = DistutilsInfo(exn=template)
|
|
779
|
+
ext_language = None # do not override whatever the Extension says
|
|
776
780
|
if cython_sources:
|
|
777
781
|
filepattern = cython_sources[0]
|
|
778
782
|
if len(cython_sources) > 1:
|
|
@@ -781,11 +785,14 @@ def create_extension_list(patterns, exclude=None, ctx=None, aliases=None, quiet=
|
|
|
781
785
|
"for sharing declarations among Cython files." % (pattern.name, cython_sources))
|
|
782
786
|
elif shared_utility_qualified_name and pattern.name == shared_utility_qualified_name:
|
|
783
787
|
# This is the shared utility code file.
|
|
788
|
+
sources = pattern.sources or [
|
|
789
|
+
shared_utility_qualified_name.replace('.', os.sep) + ('.cpp' if pattern.language == 'c++' else '.c')]
|
|
784
790
|
m, _ = create_extension(pattern, dict(
|
|
785
791
|
name=shared_utility_qualified_name,
|
|
786
|
-
sources=
|
|
787
|
-
shared_utility_qualified_name.replace('.', os.sep) + ('.cpp' if pattern.language == 'c++' else '.c')],
|
|
792
|
+
sources=sources,
|
|
788
793
|
language=pattern.language,
|
|
794
|
+
# shared utility code uses only parameters specified as argument of Extension() class
|
|
795
|
+
**base.values
|
|
789
796
|
))
|
|
790
797
|
m.np_pythran = False
|
|
791
798
|
m.shared_utility_qualified_name = None
|
|
@@ -795,10 +802,6 @@ def create_extension_list(patterns, exclude=None, ctx=None, aliases=None, quiet=
|
|
|
795
802
|
# ignore non-cython modules
|
|
796
803
|
module_list.append(pattern)
|
|
797
804
|
continue
|
|
798
|
-
template = pattern
|
|
799
|
-
name = template.name
|
|
800
|
-
base = DistutilsInfo(exn=template)
|
|
801
|
-
ext_language = None # do not override whatever the Extension says
|
|
802
805
|
else:
|
|
803
806
|
msg = str("pattern is not of type str nor subclass of Extension (%s)"
|
|
804
807
|
" but of type %s and class %s" % (repr(Extension),
|
Cython/Build/SharedModule.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import tempfile
|
|
2
1
|
import os
|
|
2
|
+
import re
|
|
3
3
|
import shutil
|
|
4
|
+
import tempfile
|
|
4
5
|
|
|
5
6
|
from Cython.Compiler import (
|
|
6
7
|
MemoryView, Code, Options, Pipeline, Errors, Main, Symtab
|
|
@@ -27,6 +28,22 @@ def create_shared_library_pipeline(context, scope, options, result):
|
|
|
27
28
|
|
|
28
29
|
return generate_tree
|
|
29
30
|
|
|
31
|
+
def generate_c_utilities(module_node):
|
|
32
|
+
UtilityCode = Code.UtilityCode
|
|
33
|
+
match_special = UtilityCode.get_special_comment_matcher('/')
|
|
34
|
+
for c_utility_file in os.listdir(Code.get_utility_dir()):
|
|
35
|
+
if not c_utility_file.endswith('.c'):
|
|
36
|
+
continue
|
|
37
|
+
for line in Code.read_utilities_hook(c_utility_file):
|
|
38
|
+
if not ((m := match_special(line)) and (name := m.group('name'))):
|
|
39
|
+
continue
|
|
40
|
+
if not (section_title := UtilityCode.match_section_title(name)):
|
|
41
|
+
continue
|
|
42
|
+
name, section_type = section_title.groups()
|
|
43
|
+
if section_type == 'export':
|
|
44
|
+
module_node.scope.use_utility_code(UtilityCode.load_cached(name, c_utility_file))
|
|
45
|
+
return module_node
|
|
46
|
+
|
|
30
47
|
orig_cimport_from_pyx = Options.cimport_from_pyx
|
|
31
48
|
|
|
32
49
|
def set_cimport_from_pyx(cimport_from_pyx):
|
|
@@ -40,6 +57,7 @@ def create_shared_library_pipeline(context, scope, options, result):
|
|
|
40
57
|
set_cimport_from_pyx(True),
|
|
41
58
|
generate_tree_factory(context),
|
|
42
59
|
*Pipeline.create_pipeline(context, 'pyx', exclude_classes=()),
|
|
60
|
+
generate_c_utilities,
|
|
43
61
|
Pipeline.inject_pxd_code_stage_factory(context),
|
|
44
62
|
Pipeline.inject_utility_code_stage_factory(context, internalise_c_class_entries=False),
|
|
45
63
|
Pipeline.inject_utility_pxd_code_stage_factory(context),
|
Cython/CodeWriter.py
CHANGED
|
@@ -482,11 +482,12 @@ class ExpressionWriter(TreeVisitor):
|
|
|
482
482
|
A Cython code writer that is intentionally limited to expressions.
|
|
483
483
|
"""
|
|
484
484
|
|
|
485
|
-
def __init__(self, result=None):
|
|
485
|
+
def __init__(self, result=None, allow_unknown_nodes=False):
|
|
486
486
|
super().__init__()
|
|
487
487
|
if result is None:
|
|
488
488
|
result = ""
|
|
489
489
|
self.result = result
|
|
490
|
+
self.allow_unknown_nodes = allow_unknown_nodes
|
|
490
491
|
self.precedence = [0]
|
|
491
492
|
|
|
492
493
|
def write(self, tree):
|
|
@@ -508,7 +509,10 @@ class ExpressionWriter(TreeVisitor):
|
|
|
508
509
|
self.visit(items[-1])
|
|
509
510
|
|
|
510
511
|
def visit_Node(self, node):
|
|
511
|
-
|
|
512
|
+
if self.allow_unknown_nodes:
|
|
513
|
+
self.put("...")
|
|
514
|
+
else:
|
|
515
|
+
raise AssertionError("Node not handled by serializer: %r" % node)
|
|
512
516
|
|
|
513
517
|
# TODO: Remove redundancy below. Most constants serialise fine as just "repr(node.value)".
|
|
514
518
|
|
Cython/Compiler/Annotate.py
CHANGED
|
@@ -107,9 +107,12 @@ class AnnotationCCodeWriter(CCodeWriter):
|
|
|
107
107
|
|
|
108
108
|
# on-click toggle function to show/hide C source code
|
|
109
109
|
_onclick_attr = ' onclick="{}"'.format((
|
|
110
|
-
|
|
111
|
-
"
|
|
112
|
-
"
|
|
110
|
+
# Use local JS variables by declaring them as function arguments.
|
|
111
|
+
"(function(f, s, c) {"
|
|
112
|
+
" c = f.nodeValue == '+';"
|
|
113
|
+
" s.display = c ? 'block' : 'none';"
|
|
114
|
+
" f.nodeValue = c ? '−' : '+'"
|
|
115
|
+
"})(this.firstChild, this.nextElementSibling.style)"
|
|
113
116
|
).replace(' ', '') # poor dev's JS minification
|
|
114
117
|
)
|
|
115
118
|
|
|
@@ -50,7 +50,7 @@ class EmbedSignature(CythonTransform):
|
|
|
50
50
|
self.class_node = None
|
|
51
51
|
|
|
52
52
|
def _fmt_expr(self, node):
|
|
53
|
-
writer = ExpressionWriter()
|
|
53
|
+
writer = ExpressionWriter(allow_unknown_nodes=True)
|
|
54
54
|
result = writer.write(node)
|
|
55
55
|
# print(type(node).__name__, '-->', result)
|
|
56
56
|
return result
|
Cython/Compiler/Builtin.py
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
from .StringEncoding import EncodedString
|
|
7
7
|
from .Symtab import BuiltinScope, CClassScope, StructOrUnionScope, ModuleScope, Entry
|
|
8
|
-
from .Code import UtilityCode, TempitaUtilityCode
|
|
8
|
+
from .Code import UtilityCode, TempitaUtilityCode, KNOWN_PYTHON_BUILTINS, uncachable_builtins
|
|
9
9
|
from .TypeSlots import Signature
|
|
10
10
|
from . import PyrexTypes
|
|
11
11
|
|
|
@@ -18,6 +18,7 @@ getattr3_utility_code = UtilityCode.load("GetAttr3", "Builtins.c")
|
|
|
18
18
|
pyexec_utility_code = UtilityCode.load("PyExec", "Builtins.c")
|
|
19
19
|
pyexec_globals_utility_code = UtilityCode.load("PyExecGlobals", "Builtins.c")
|
|
20
20
|
globals_utility_code = UtilityCode.load("Globals", "Builtins.c")
|
|
21
|
+
range_utility_code = UtilityCode.load("PyRange_Check", "Builtins.c")
|
|
21
22
|
include_std_lib_h_utility_code = UtilityCode.load("IncludeStdlibH", "ModuleSetupCode.c")
|
|
22
23
|
pysequence_multiply_utility_code = UtilityCode.load("PySequenceMultiply", "ObjectHandling.c")
|
|
23
24
|
slice_accessor_utility_code = UtilityCode.load("PySliceAccessors", "Builtins.c")
|
|
@@ -224,27 +225,37 @@ builtin_function_table = [
|
|
|
224
225
|
utility_code=UtilityCode.load("py_abs", "Builtins.c")),
|
|
225
226
|
#('all', "", "", ""),
|
|
226
227
|
#('any', "", "", ""),
|
|
227
|
-
#('
|
|
228
|
-
#('
|
|
228
|
+
#('aiter', "", "", ""),
|
|
229
|
+
#('anext', "", "", ""),
|
|
230
|
+
BuiltinFunction('ascii', "O", "O", "PyObject_ASCII", builtin_return_type='str'),
|
|
231
|
+
BuiltinFunction('bin', "O", "O", "__Pyx_PyNumber_Bin", builtin_return_type='str',
|
|
232
|
+
utility_code=UtilityCode(
|
|
233
|
+
proto="#define __Pyx_PyNumber_Bin(obj) PyNumber_ToBase((obj), 2)",
|
|
234
|
+
name="PyNumber_Bin")),
|
|
235
|
+
#('breakpoint', "", "", ""),
|
|
229
236
|
BuiltinFunction('callable', "O", "b", "__Pyx_PyCallable_Check",
|
|
230
237
|
utility_code = UtilityCode.load("CallableCheck", "ObjectHandling.c")),
|
|
231
238
|
BuiltinFunction('chr', "i", "O", "PyUnicode_FromOrdinal", builtin_return_type='str'),
|
|
232
|
-
#('cmp', "", "", "", ""), # int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result)
|
|
233
239
|
#('compile', "", "", ""), # PyObject* Py_CompileString( char *str, char *filename, int start)
|
|
234
240
|
BuiltinFunction('delattr', "OO", "r", "__Pyx_PyObject_DelAttr",
|
|
235
241
|
utility_code=UtilityCode.load("PyObjectDelAttr", "ObjectHandling.c")),
|
|
236
242
|
BuiltinFunction('dir', "O", "O", "PyObject_Dir"),
|
|
237
243
|
BuiltinFunction('divmod', "OO", "O", "PyNumber_Divmod",
|
|
238
244
|
specialiser=_generate_divmod_function),
|
|
245
|
+
#('enumerate', "", "", ""),
|
|
246
|
+
#('eval', "", "", ""),
|
|
239
247
|
BuiltinFunction('exec', "O", "O", "__Pyx_PyExecGlobals",
|
|
240
248
|
utility_code = pyexec_globals_utility_code),
|
|
241
249
|
BuiltinFunction('exec', "OO", "O", "__Pyx_PyExec2",
|
|
242
250
|
utility_code = pyexec_utility_code),
|
|
243
251
|
BuiltinFunction('exec', "OOO", "O", "__Pyx_PyExec3",
|
|
244
252
|
utility_code = pyexec_utility_code),
|
|
245
|
-
#('eval', "", "", ""),
|
|
246
|
-
#('execfile', "", "", ""),
|
|
247
253
|
#('filter', "", "", ""),
|
|
254
|
+
BuiltinFunction('format', "OO", "O", "PyObject_Format", builtin_return_type='str'),
|
|
255
|
+
BuiltinFunction('format', "O", "O", "__Pyx_PyObject_Format1", builtin_return_type='str',
|
|
256
|
+
utility_code=UtilityCode(
|
|
257
|
+
proto="#define __Pyx_PyObject_Format1(obj) PyObject_Format((obj), NULL)",
|
|
258
|
+
name="PyObject_Format1")),
|
|
248
259
|
BuiltinFunction('getattr3', "OOO", "O", "__Pyx_GetAttr3", "getattr",
|
|
249
260
|
utility_code=getattr3_utility_code), # Pyrex legacy
|
|
250
261
|
BuiltinFunction('getattr', "OOO", "O", "__Pyx_GetAttr3",
|
|
@@ -254,10 +265,14 @@ builtin_function_table = [
|
|
|
254
265
|
BuiltinFunction('hasattr', "OO", "b", "__Pyx_HasAttr",
|
|
255
266
|
utility_code = UtilityCode.load("HasAttr", "Builtins.c")),
|
|
256
267
|
BuiltinFunction('hash', "O", "h", "PyObject_Hash"),
|
|
257
|
-
#('
|
|
268
|
+
#('help', "", "", ""),
|
|
269
|
+
BuiltinFunction('hex', "O", "O", "__Pyx_PyNumber_Hex", builtin_return_type='str',
|
|
270
|
+
utility_code=UtilityCode(
|
|
271
|
+
proto="#define __Pyx_PyNumber_Hex(obj) PyNumber_ToBase((obj), 16)",
|
|
272
|
+
name="PyNumber_Hex")),
|
|
258
273
|
#('id', "", "", ""),
|
|
259
274
|
#('input', "", "", ""),
|
|
260
|
-
BuiltinFunction('intern', "O", "O", "__Pyx_Intern",
|
|
275
|
+
BuiltinFunction('intern', "O", "O", "__Pyx_Intern", # Py2 legacy
|
|
261
276
|
utility_code = UtilityCode.load("Intern", "Builtins.c")),
|
|
262
277
|
BuiltinFunction('isinstance', "OO", "b", "PyObject_IsInstance"),
|
|
263
278
|
BuiltinFunction('issubclass', "OO", "b", "PyObject_IsSubclass"),
|
|
@@ -269,11 +284,14 @@ builtin_function_table = [
|
|
|
269
284
|
#('max', "", "", ""),
|
|
270
285
|
#('min', "", "", ""),
|
|
271
286
|
BuiltinFunction('next', "O", "O", "__Pyx_PyIter_Next",
|
|
272
|
-
utility_code = iter_next_utility_code),
|
|
287
|
+
utility_code = iter_next_utility_code),
|
|
273
288
|
BuiltinFunction('next', "OO", "O", "__Pyx_PyIter_Next2",
|
|
274
|
-
utility_code = iter_next_utility_code),
|
|
275
|
-
|
|
276
|
-
|
|
289
|
+
utility_code = iter_next_utility_code),
|
|
290
|
+
BuiltinFunction('oct', "O", "O", "__Pyx_PyNumber_Oct", builtin_return_type='str',
|
|
291
|
+
utility_code=UtilityCode(
|
|
292
|
+
proto="#define __Pyx_PyNumber_Oct(obj) PyNumber_ToBase((obj), 8)",
|
|
293
|
+
name="PyNumber_Oct")),
|
|
294
|
+
#('open', "ss", "O", ""), # no C-API equivalent in Py3
|
|
277
295
|
] + [
|
|
278
296
|
BuiltinFunction('ord', None, None, "__Pyx_long_cast",
|
|
279
297
|
func_type=PyrexTypes.CFuncType(
|
|
@@ -297,22 +315,19 @@ builtin_function_table = [
|
|
|
297
315
|
BuiltinFunction('pow', "OOO", "O", "PyNumber_Power"),
|
|
298
316
|
BuiltinFunction('pow', "OO", "O", "__Pyx_PyNumber_Power2",
|
|
299
317
|
utility_code = UtilityCode.load("pow2", "Builtins.c")),
|
|
300
|
-
#('
|
|
301
|
-
#('
|
|
302
|
-
|
|
303
|
-
BuiltinFunction('reload', "O", "O", "PyImport_ReloadModule"),
|
|
318
|
+
#('print', "", "", ""),
|
|
319
|
+
#('property', "", "", ""),
|
|
320
|
+
BuiltinFunction('reload', "O", "O", "PyImport_ReloadModule"), # legacy Py2
|
|
304
321
|
BuiltinFunction('repr', "O", "O", "PyObject_Repr", builtin_return_type='str'),
|
|
322
|
+
#('reversed', "", "", ""),
|
|
305
323
|
#('round', "", "", ""),
|
|
306
324
|
BuiltinFunction('setattr', "OOO", "r", "PyObject_SetAttr"),
|
|
307
|
-
#('sum', "", "", ""),
|
|
308
325
|
#('sorted', "", "", ""),
|
|
326
|
+
#('sum', "", "", ""),
|
|
309
327
|
#('type', "O", "O", "PyObject_Type"),
|
|
310
|
-
BuiltinFunction('unichr', "i", "O", "PyUnicode_FromOrdinal", builtin_return_type='str'),
|
|
328
|
+
BuiltinFunction('unichr', "i", "O", "PyUnicode_FromOrdinal", builtin_return_type='str'), # legacy Py2
|
|
311
329
|
#('vars', "", "", ""),
|
|
312
330
|
#('zip', "", "", ""),
|
|
313
|
-
# Can't do these easily until we have builtin type entries.
|
|
314
|
-
#('typecheck', "OO", "i", "PyObject_TypeCheck", False),
|
|
315
|
-
#('issubtype', "OO", "i", "PyType_IsSubtype", False),
|
|
316
331
|
|
|
317
332
|
# Put in namespace append optimization.
|
|
318
333
|
BuiltinFunction('__Pyx_PyObject_Append', "OO", "O", "__Pyx_PyObject_Append"),
|
|
@@ -325,33 +340,34 @@ builtin_function_table = [
|
|
|
325
340
|
|
|
326
341
|
# Builtin types
|
|
327
342
|
# bool
|
|
328
|
-
#
|
|
343
|
+
# bytearray
|
|
344
|
+
# bytes
|
|
329
345
|
# classmethod
|
|
346
|
+
# complex
|
|
330
347
|
# dict
|
|
331
348
|
# enumerate
|
|
332
|
-
# file
|
|
333
349
|
# float
|
|
350
|
+
# frozenset
|
|
334
351
|
# int
|
|
335
352
|
# list
|
|
336
353
|
# long
|
|
354
|
+
# memoryview
|
|
337
355
|
# object
|
|
338
356
|
# property
|
|
357
|
+
# range
|
|
358
|
+
# set
|
|
339
359
|
# slice
|
|
340
360
|
# staticmethod
|
|
341
|
-
# super
|
|
342
361
|
# str
|
|
362
|
+
# super
|
|
343
363
|
# tuple
|
|
344
364
|
# type
|
|
345
|
-
# xrange
|
|
346
365
|
|
|
347
366
|
builtin_types_table = [
|
|
348
367
|
|
|
349
368
|
("type", "&PyType_Type", []),
|
|
350
369
|
|
|
351
|
-
|
|
352
|
-
# C++ is too liberal about PyObject* <-> bool conversions,
|
|
353
|
-
# resulting in unintuitive runtime behavior and segfaults.
|
|
354
|
-
# ("bool", "&PyBool_Type", []),
|
|
370
|
+
("bool", "&PyBool_Type", []),
|
|
355
371
|
|
|
356
372
|
("int", "&PyLong_Type", []),
|
|
357
373
|
("float", "&PyFloat_Type", []),
|
|
@@ -365,7 +381,7 @@ builtin_types_table = [
|
|
|
365
381
|
BuiltinMethod("__mul__", "Tz", "T", "__Pyx_PySequence_Multiply",
|
|
366
382
|
utility_code=pysequence_multiply_utility_code),
|
|
367
383
|
]),
|
|
368
|
-
("bytes", "&PyBytes_Type", [BuiltinMethod("join", "TO", "
|
|
384
|
+
("bytes", "&PyBytes_Type", [BuiltinMethod("join", "TO", "T", "__Pyx_PyBytes_Join",
|
|
369
385
|
utility_code=UtilityCode.load("StringJoin", "StringTools.c")),
|
|
370
386
|
BuiltinMethod("__mul__", "Tz", "T", "__Pyx_PySequence_Multiply",
|
|
371
387
|
utility_code=pysequence_multiply_utility_code),
|
|
@@ -414,6 +430,8 @@ builtin_types_table = [
|
|
|
414
430
|
utility_code=UtilityCode.load("py_dict_clear", "Optimize.c")),
|
|
415
431
|
BuiltinMethod("copy", "T", "T", "PyDict_Copy")]),
|
|
416
432
|
|
|
433
|
+
("range", "&PyRange_Type", []),
|
|
434
|
+
|
|
417
435
|
("slice", "&PySlice_Type", [BuiltinProperty("start", PyrexTypes.py_object_type, '__Pyx_PySlice_Start',
|
|
418
436
|
utility_code=slice_accessor_utility_code),
|
|
419
437
|
BuiltinProperty("stop", PyrexTypes.py_object_type, '__Pyx_PySlice_Stop',
|
|
@@ -466,12 +484,14 @@ builtin_types_table = [
|
|
|
466
484
|
|
|
467
485
|
|
|
468
486
|
types_that_construct_their_instance = frozenset({
|
|
469
|
-
#
|
|
487
|
+
# Some builtin types do not always return an instance of
|
|
470
488
|
# themselves - these do:
|
|
471
489
|
'type', 'bool', 'int', 'float', 'complex',
|
|
472
490
|
'bytes', 'unicode', 'bytearray', 'str',
|
|
473
491
|
'tuple', 'list', 'dict', 'set', 'frozenset',
|
|
474
|
-
'memoryview'
|
|
492
|
+
'memoryview', 'range',
|
|
493
|
+
# All builtin exception types create their own instance.
|
|
494
|
+
*filter(PyrexTypes.is_exception_type_name, KNOWN_PYTHON_BUILTINS),
|
|
475
495
|
})
|
|
476
496
|
|
|
477
497
|
|
|
@@ -719,7 +739,6 @@ builtin_structs_table = [
|
|
|
719
739
|
("shape", PyrexTypes.c_py_ssize_t_ptr_type),
|
|
720
740
|
("strides", PyrexTypes.c_py_ssize_t_ptr_type),
|
|
721
741
|
("suboffsets", PyrexTypes.c_py_ssize_t_ptr_type),
|
|
722
|
-
("smalltable", PyrexTypes.CArrayType(PyrexTypes.c_py_ssize_t_type, 2)),
|
|
723
742
|
("internal", PyrexTypes.c_void_ptr_type),
|
|
724
743
|
]),
|
|
725
744
|
('Py_complex', 'Py_complex',
|
|
@@ -757,18 +776,42 @@ def init_builtin_types():
|
|
|
757
776
|
objstruct_cname = "PyBaseExceptionObject"
|
|
758
777
|
else:
|
|
759
778
|
objstruct_cname = 'Py%sObject' % name.capitalize()
|
|
779
|
+
|
|
780
|
+
utility_code = None
|
|
760
781
|
type_class = PyrexTypes.BuiltinObjectType
|
|
761
782
|
if name in ['dict', 'list', 'set', 'frozenset']:
|
|
762
783
|
type_class = PyrexTypes.BuiltinTypeConstructorObjectType
|
|
763
784
|
elif name == 'tuple':
|
|
764
785
|
type_class = PyrexTypes.PythonTupleTypeConstructor
|
|
786
|
+
elif name == 'range':
|
|
787
|
+
utility_code = range_utility_code
|
|
765
788
|
the_type = builtin_scope.declare_builtin_type(
|
|
766
|
-
name, cname, objstruct_cname=objstruct_cname, type_class=type_class)
|
|
789
|
+
name, cname, objstruct_cname=objstruct_cname, type_class=type_class, utility_code=utility_code)
|
|
767
790
|
builtin_types[name] = the_type
|
|
768
791
|
for method in methods:
|
|
769
792
|
method.declare_in_type(the_type)
|
|
770
793
|
|
|
771
794
|
|
|
795
|
+
def init_builtin_exceptions():
|
|
796
|
+
"""Declare known builtin Python exceptions as types.
|
|
797
|
+
"""
|
|
798
|
+
for name in KNOWN_PYTHON_BUILTINS:
|
|
799
|
+
if name in uncachable_builtins:
|
|
800
|
+
# Exclude builtins specific to later Python versions or platforms.
|
|
801
|
+
continue
|
|
802
|
+
if not PyrexTypes.is_exception_type_name(name):
|
|
803
|
+
continue
|
|
804
|
+
if builtin_scope.lookup_here(name) is not None:
|
|
805
|
+
# Already declared as builtin type above in a more specialised way.
|
|
806
|
+
continue
|
|
807
|
+
utility_code = UtilityCode(
|
|
808
|
+
proto=f"#define __Pyx_PyExc_{name}_Check(obj) __Pyx_TypeCheck(obj, PyExc_{name})",
|
|
809
|
+
name=f"Py{name}_Check",
|
|
810
|
+
)
|
|
811
|
+
builtin_types[name] = builtin_scope.declare_builtin_type(
|
|
812
|
+
name, f"((PyTypeObject*)PyExc_{name})", utility_code=utility_code)
|
|
813
|
+
|
|
814
|
+
|
|
772
815
|
def init_builtin_structs():
|
|
773
816
|
for name, cname, attribute_types in builtin_structs_table:
|
|
774
817
|
scope = StructOrUnionScope(name)
|
|
@@ -783,6 +826,7 @@ def init_builtins():
|
|
|
783
826
|
#Errors.init_thread() # hopefully not needed - we should not emit warnings ourselves
|
|
784
827
|
init_builtin_structs()
|
|
785
828
|
init_builtin_types()
|
|
829
|
+
init_builtin_exceptions()
|
|
786
830
|
init_builtin_funcs()
|
|
787
831
|
|
|
788
832
|
entry = builtin_scope.declare_var(
|
|
@@ -790,7 +834,8 @@ def init_builtins():
|
|
|
790
834
|
pos=None, cname='__pyx_assertions_enabled()', is_cdef=True)
|
|
791
835
|
entry.utility_code = UtilityCode.load_cached("AssertionsEnabled", "Exceptions.c")
|
|
792
836
|
|
|
793
|
-
global type_type, list_type, tuple_type, dict_type, set_type, frozenset_type
|
|
837
|
+
global type_type, list_type, tuple_type, dict_type, set_type, frozenset_type
|
|
838
|
+
global slice_type, range_type
|
|
794
839
|
global bytes_type, unicode_type, bytearray_type
|
|
795
840
|
global float_type, int_type, bool_type, complex_type
|
|
796
841
|
global memoryview_type, py_buffer_type
|
|
@@ -802,6 +847,7 @@ def init_builtins():
|
|
|
802
847
|
set_type = builtin_scope.lookup('set').type
|
|
803
848
|
frozenset_type = builtin_scope.lookup('frozenset').type
|
|
804
849
|
slice_type = builtin_scope.lookup('slice').type
|
|
850
|
+
range_type = builtin_scope.lookup('range').type
|
|
805
851
|
|
|
806
852
|
bytes_type = builtin_scope.lookup('bytes').type
|
|
807
853
|
unicode_type = builtin_scope.lookup('str').type
|
|
@@ -810,19 +856,9 @@ def init_builtins():
|
|
|
810
856
|
|
|
811
857
|
float_type = builtin_scope.lookup('float').type
|
|
812
858
|
int_type = builtin_scope.lookup('int').type
|
|
813
|
-
|
|
859
|
+
bool_type = builtin_scope.lookup('bool').type
|
|
814
860
|
complex_type = builtin_scope.lookup('complex').type
|
|
815
861
|
|
|
816
|
-
# Most entries are initialized via "declare_builtin_type()"", except for "bool"
|
|
817
|
-
# which is apparently a special case because it conflicts with C++ bool.
|
|
818
|
-
# Here, we only declare it as builtin name, not as actual type.
|
|
819
|
-
bool_type = PyrexTypes.BuiltinObjectType(EncodedString('bool'), "((PyObject*)&PyBool_Type)", "PyLongObject")
|
|
820
|
-
scope = CClassScope('bool', outer_scope=None, visibility='extern', parent_type=bool_type)
|
|
821
|
-
bool_type.set_scope(scope)
|
|
822
|
-
bool_type.is_final_type = True
|
|
823
|
-
bool_type.entry = builtin_scope.declare_var(EncodedString('bool'), bool_type, pos=None, cname="((PyObject*)&PyBool_Type)")
|
|
824
|
-
builtin_types['bool'] = bool_type
|
|
825
|
-
|
|
826
862
|
sequence_types = (
|
|
827
863
|
list_type,
|
|
828
864
|
tuple_type,
|
Cython/Compiler/CmdLine.py
CHANGED
|
@@ -125,6 +125,8 @@ Environment variables:
|
|
|
125
125
|
parser.add_argument('--embed', action='store_const', const='main',
|
|
126
126
|
help='Generate a main() function that embeds the Python interpreter. '
|
|
127
127
|
'Pass --embed=<method_name> for a name other than main().')
|
|
128
|
+
parser.add_argument('--embed-modules', action='store', type=comma_list,
|
|
129
|
+
help='')
|
|
128
130
|
parser.add_argument('-2', dest='language_level', action='store_const', const=2,
|
|
129
131
|
help='Compile based on Python-2 syntax and code semantics.')
|
|
130
132
|
parser.add_argument('-3', dest='language_level', action='store_const', const=3,
|
|
@@ -180,6 +182,8 @@ Environment variables:
|
|
|
180
182
|
|
|
181
183
|
return parser
|
|
182
184
|
|
|
185
|
+
def comma_list(string):
|
|
186
|
+
return string.split(',')
|
|
183
187
|
|
|
184
188
|
def parse_command_line_raw(parser, args):
|
|
185
189
|
# special handling for --embed and --embed=xxxx as they aren't correctly parsed
|
Cython/Compiler/Code.pxd
CHANGED
|
@@ -13,16 +13,20 @@ cdef class UtilityCodeBase(AbstractUtilityCode):
|
|
|
13
13
|
cdef class UtilityCode(UtilityCodeBase):
|
|
14
14
|
cdef public object name
|
|
15
15
|
cdef public object proto
|
|
16
|
+
cdef public object export
|
|
16
17
|
cdef public object impl
|
|
17
18
|
cdef public object init
|
|
18
19
|
cdef public object cleanup
|
|
19
|
-
cdef
|
|
20
|
-
cdef
|
|
20
|
+
cdef object proto_block
|
|
21
|
+
cdef readonly object module_state_decls
|
|
22
|
+
cdef readonly object module_state_traverse
|
|
23
|
+
cdef readonly object module_state_clear
|
|
21
24
|
cdef public object requires
|
|
22
|
-
cdef
|
|
23
|
-
cdef
|
|
25
|
+
cdef dict _cache
|
|
26
|
+
cdef list specialize_list
|
|
24
27
|
cdef public object file
|
|
25
|
-
cdef
|
|
28
|
+
cdef readonly tuple _parts_tuple
|
|
29
|
+
cdef list shared_utility_functions
|
|
26
30
|
|
|
27
31
|
cpdef none_or_sub(self, s, context)
|
|
28
32
|
# TODO - Signature not compatible with previous declaration
|
|
@@ -30,8 +34,9 @@ cdef class UtilityCode(UtilityCodeBase):
|
|
|
30
34
|
#cdef bint _put_code_section(self, writer, code_type: str) except -1
|
|
31
35
|
|
|
32
36
|
|
|
37
|
+
@cython.final
|
|
33
38
|
cdef class FunctionState:
|
|
34
|
-
cdef
|
|
39
|
+
cdef set names_taken
|
|
35
40
|
cdef public object owner
|
|
36
41
|
cdef public object scope
|
|
37
42
|
|
|
@@ -41,7 +46,7 @@ cdef class FunctionState:
|
|
|
41
46
|
cdef public object return_label
|
|
42
47
|
cdef public object continue_label
|
|
43
48
|
cdef public object break_label
|
|
44
|
-
cdef
|
|
49
|
+
cdef readonly list yield_labels
|
|
45
50
|
|
|
46
51
|
cdef public object return_from_error_cleanup_label # not used in __init__ ?
|
|
47
52
|
|
|
@@ -50,15 +55,15 @@ cdef class FunctionState:
|
|
|
50
55
|
cdef public bint can_trace
|
|
51
56
|
cdef public bint gil_owned
|
|
52
57
|
|
|
53
|
-
cdef
|
|
54
|
-
cdef
|
|
55
|
-
cdef
|
|
56
|
-
cdef
|
|
57
|
-
cdef
|
|
58
|
-
cdef
|
|
58
|
+
cdef list temps_allocated
|
|
59
|
+
cdef dict temps_free
|
|
60
|
+
cdef dict temps_used_type
|
|
61
|
+
cdef set zombie_temps
|
|
62
|
+
cdef size_t temp_counter
|
|
63
|
+
cdef list collect_temps_stack
|
|
59
64
|
|
|
60
|
-
cdef
|
|
61
|
-
cdef
|
|
65
|
+
cdef readonly object closure_temps
|
|
66
|
+
cdef bint should_declare_error_indicator
|
|
62
67
|
cdef public bint uses_error_indicator
|
|
63
68
|
cdef public bint error_without_exception
|
|
64
69
|
|
|
@@ -74,30 +79,31 @@ cdef class FunctionState:
|
|
|
74
79
|
|
|
75
80
|
cpdef list temps_in_use(self)
|
|
76
81
|
|
|
77
|
-
cdef class IntConst:
|
|
78
|
-
cdef public object cname
|
|
79
|
-
cdef public object value
|
|
80
|
-
cdef public bint is_long
|
|
81
82
|
|
|
83
|
+
@cython.final
|
|
82
84
|
cdef class PyObjectConst:
|
|
83
|
-
cdef
|
|
84
|
-
cdef
|
|
85
|
+
cdef readonly object cname
|
|
86
|
+
cdef readonly object type
|
|
85
87
|
|
|
88
|
+
|
|
89
|
+
@cython.final
|
|
86
90
|
cdef class StringConst:
|
|
87
|
-
cdef
|
|
88
|
-
cdef
|
|
89
|
-
cdef
|
|
90
|
-
cdef
|
|
91
|
-
cdef public
|
|
91
|
+
cdef readonly object cname
|
|
92
|
+
cdef readonly object text
|
|
93
|
+
cdef readonly object escaped_value
|
|
94
|
+
cdef readonly dict py_strings
|
|
95
|
+
cdef public bint c_used
|
|
92
96
|
|
|
93
97
|
cpdef get_py_string_const(self, encoding, identifier=*)
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
|
|
100
|
+
@cython.final
|
|
101
|
+
cdef class PyStringConst:
|
|
102
|
+
cdef readonly object cname
|
|
103
|
+
cdef readonly object encoding
|
|
104
|
+
cdef readonly bint is_unicode
|
|
105
|
+
cdef readonly bint intern
|
|
106
|
+
|
|
101
107
|
|
|
102
108
|
#class GlobalState(object):
|
|
103
109
|
|
|
@@ -107,7 +113,7 @@ cdef class CCodeWriter(object):
|
|
|
107
113
|
cdef readonly StringIOTree buffer
|
|
108
114
|
cdef readonly list pyclass_stack
|
|
109
115
|
cdef readonly object globalstate
|
|
110
|
-
cdef readonly
|
|
116
|
+
cdef readonly FunctionState funcstate
|
|
111
117
|
cdef object code_config
|
|
112
118
|
cdef tuple last_pos
|
|
113
119
|
cdef tuple last_marked_pos
|
|
@@ -116,27 +122,22 @@ cdef class CCodeWriter(object):
|
|
|
116
122
|
cdef bint bol
|
|
117
123
|
|
|
118
124
|
cpdef write(self, s)
|
|
119
|
-
@cython.final
|
|
120
125
|
cdef _write_lines(self, s)
|
|
121
126
|
cpdef _write_to_buffer(self, s)
|
|
127
|
+
cdef put_multilines(self, code)
|
|
122
128
|
cpdef put(self, code)
|
|
123
129
|
cpdef put_safe(self, code)
|
|
124
130
|
cpdef putln(self, code=*, bint safe=*)
|
|
125
|
-
@cython.final
|
|
126
131
|
cdef emit_marker(self)
|
|
127
|
-
@cython.final
|
|
128
132
|
cdef _build_marker(self, tuple pos)
|
|
129
|
-
@cython.final
|
|
130
133
|
cdef increase_indent(self)
|
|
131
|
-
@cython.final
|
|
132
134
|
cdef decrease_indent(self)
|
|
133
|
-
@cython.final
|
|
134
135
|
cdef indent(self)
|
|
135
136
|
|
|
136
137
|
|
|
137
138
|
cdef class PyrexCodeWriter:
|
|
138
|
-
cdef
|
|
139
|
-
cdef
|
|
139
|
+
cdef readonly object f
|
|
140
|
+
cdef readonly Py_ssize_t level
|
|
140
141
|
|
|
141
142
|
|
|
142
143
|
cdef class PyxCodeWriter:
|