Cython 3.2.6__py3-none-any.whl → 3.3.0a2.dev0__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.
Potentially problematic release.
This version of Cython might be problematic. Click here for more details.
- Cython/Build/BuildExecutable.py +1 -14
- Cython/Build/Dependencies.py +6 -44
- Cython/Build/Inline.py +7 -3
- Cython/Build/IpythonMagic.py +0 -1
- Cython/Build/SharedModule.py +1 -2
- Cython/Build/Tests/TestCythonizeArgsParser.py +6 -6
- Cython/Build/Tests/TestDependencies.py +3 -3
- Cython/Build/Tests/TestInline.py +3 -3
- Cython/Build/Tests/TestIpythonMagic.py +35 -19
- Cython/Build/Tests/TestStripLiterals.py +2 -2
- Cython/Compiler/Buffer.py +5 -5
- Cython/Compiler/Builtin.py +57 -46
- Cython/Compiler/Code.pxd +12 -9
- Cython/Compiler/Code.py +220 -94
- Cython/Compiler/Dataclass.py +78 -52
- Cython/Compiler/Errors.py +21 -8
- Cython/Compiler/ExprNodes.py +871 -459
- Cython/Compiler/FlowControl.pxd +8 -6
- Cython/Compiler/FlowControl.py +111 -8
- Cython/Compiler/FusedNode.py +17 -12
- Cython/Compiler/Lexicon.py +123 -122
- Cython/Compiler/Main.py +3 -4
- Cython/Compiler/MatchCaseNodes.py +1948 -10
- Cython/Compiler/MemoryView.py +62 -33
- Cython/Compiler/ModuleNode.py +559 -283
- Cython/Compiler/Naming.py +4 -0
- Cython/Compiler/Nodes.py +333 -197
- Cython/Compiler/Optimize.py +268 -112
- Cython/Compiler/Options.py +0 -5
- Cython/Compiler/ParseTreeTransforms.pxd +2 -1
- Cython/Compiler/ParseTreeTransforms.py +180 -76
- Cython/Compiler/Parsing.py +55 -38
- Cython/Compiler/PyrexTypes.py +364 -128
- Cython/Compiler/Scanning.pxd +27 -5
- Cython/Compiler/Scanning.py +24 -14
- Cython/Compiler/StringEncoding.py +1 -2
- Cython/Compiler/Symtab.py +27 -19
- Cython/Compiler/Tests/TestBuiltin.py +41 -6
- Cython/Compiler/Tests/TestCmdLine.py +3 -2
- Cython/Compiler/Tests/TestCode.py +4 -3
- Cython/Compiler/Tests/TestFlowControl.py +2 -2
- Cython/Compiler/Tests/TestParseTreeTransforms.py +2 -2
- Cython/Compiler/Tests/TestScanning.py +2 -4
- Cython/Compiler/Tests/TestSignatureMatching.py +3 -3
- Cython/Compiler/Tests/TestStringEncoding.py +2 -3
- Cython/Compiler/Tests/TestTypes.py +46 -3
- Cython/Compiler/Tests/TestUtilityLoad.py +4 -4
- Cython/Compiler/TypeInference.py +20 -0
- Cython/Compiler/TypeSlots.py +171 -16
- Cython/Compiler/UtilNodes.py +24 -0
- Cython/Compiler/UtilityCode.py +1 -0
- Cython/Compiler/Visitor.pxd +1 -1
- Cython/Compiler/Visitor.py +3 -2
- Cython/Debugger/Tests/TestLibCython.py +7 -2
- Cython/Debugger/Tests/test_libcython_in_gdb.py +4 -2
- Cython/Debugger/Tests/test_libpython_in_gdb.py +1 -1
- Cython/Includes/cpython/array.pxd +5 -5
- Cython/Includes/cpython/dict.pxd +1 -6
- Cython/Includes/cpython/float.pxd +19 -10
- Cython/Includes/cpython/frozendict.pxd +37 -0
- Cython/Includes/cpython/long.pxd +31 -0
- Cython/Includes/cpython/object.pxd +9 -12
- Cython/Includes/cpython/sentinel.pxd +17 -0
- Cython/Includes/cpython/type.pxd +93 -0
- Cython/Includes/libcpp/exception.pxd +90 -0
- Cython/LZSS.py +170 -0
- Cython/Shadow.py +550 -73
- Cython/StringIOTree.py +1 -2
- Cython/Tempita/_tempita.py +45 -46
- Cython/TestUtils.py +50 -8
- Cython/Tests/TestCythonUtils.py +2 -2
- Cython/Tests/TestJediTyper.py +1 -1
- Cython/Tests/TestShadow.py +7 -5
- Cython/Tests/TestStringIOTree.py +4 -3
- Cython/Tests/TestTestUtils.py +2 -3
- Cython/Utility/AsyncGen.c +59 -19
- Cython/Utility/Buffer.c +4 -3
- Cython/Utility/Builtins.c +139 -17
- Cython/Utility/CConvert.pyx +27 -12
- Cython/Utility/CommonStructures.c +55 -37
- Cython/Utility/Coroutine.c +112 -68
- Cython/Utility/CythonFunction.c +607 -330
- Cython/Utility/Embed.c +8 -0
- Cython/Utility/Exceptions.c +20 -3
- Cython/Utility/ExtensionTypes.c +414 -224
- Cython/Utility/FunctionArguments.c +83 -81
- Cython/Utility/ImportExport.c +72 -61
- Cython/Utility/MatchCase.c +979 -0
- Cython/Utility/MatchCase_Cy.pyx +12 -0
- Cython/Utility/MemoryView.pxd +9 -88
- Cython/Utility/MemoryView.pyx +173 -61
- Cython/Utility/MemoryView_C.c +3 -3
- Cython/Utility/ModuleSetupCode.c +306 -157
- Cython/Utility/ObjectHandling.c +483 -404
- Cython/Utility/Optimize.c +1117 -164
- Cython/Utility/Overflow.c +3 -9
- Cython/Utility/Profile.c +4 -0
- Cython/Utility/StringTools.c +187 -149
- Cython/Utility/Synchronization.c +39 -0
- Cython/Utility/TString.c +24 -13
- Cython/Utility/TypeConversion.c +405 -250
- Cython/Utility/arrayarray.h +24 -22
- Cython/Utils.py +11 -23
- Cython/__init__.py +3 -1
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/METADATA +14 -33
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/RECORD +109 -107
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/WHEEL +1 -1
- Cython/Shadow.pyi +0 -521
- Cython/Utility/Printing.c +0 -86
- Cython/__init__.pyi +0 -7
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/entry_points.txt +0 -0
- {cython-3.2.6.dist-info → cython-3.3.0a2.dev0.dist-info}/top_level.txt +0 -0
Cython/Compiler/TypeSlots.py
CHANGED
|
@@ -9,6 +9,7 @@ from . import PyrexTypes
|
|
|
9
9
|
from .Errors import error, warn_once
|
|
10
10
|
|
|
11
11
|
import copy
|
|
12
|
+
import enum
|
|
12
13
|
|
|
13
14
|
invisible = ['__cinit__', '__dealloc__', '__richcmp__',
|
|
14
15
|
'__nonzero__', '__bool__']
|
|
@@ -24,7 +25,7 @@ class Signature:
|
|
|
24
25
|
# fixed_arg_format string
|
|
25
26
|
# ret_format string
|
|
26
27
|
# error_value string
|
|
27
|
-
# use_fastcall
|
|
28
|
+
# use_fastcall FastcallUsed enum
|
|
28
29
|
#
|
|
29
30
|
# The formats are strings made up of the following
|
|
30
31
|
# characters:
|
|
@@ -89,8 +90,15 @@ class Signature:
|
|
|
89
90
|
'z': "-1",
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
# Describes whether to use fastcall, and what macro
|
|
94
|
+
# to use the guard the use of fastcall.
|
|
95
|
+
class FastcallUsed(enum.IntEnum):
|
|
96
|
+
NO = 0
|
|
97
|
+
YES = 1 # guarded by CYTHON_FASTCALL
|
|
98
|
+
TP_NEW = 2 # guarded by CYTHON_FASTCALL_TPNEW
|
|
99
|
+
|
|
92
100
|
# Use METH_FASTCALL instead of METH_VARARGS
|
|
93
|
-
use_fastcall =
|
|
101
|
+
use_fastcall = FastcallUsed.NO
|
|
94
102
|
|
|
95
103
|
def __init__(self, arg_format, ret_format, nogil=False):
|
|
96
104
|
self.has_dummy_arg = False
|
|
@@ -200,21 +208,32 @@ class Signature:
|
|
|
200
208
|
return "__Pyx_PyCFunction_FastCall" + kw
|
|
201
209
|
return None
|
|
202
210
|
|
|
203
|
-
def with_fastcall(self):
|
|
211
|
+
def with_fastcall(self, fastcall_type=FastcallUsed.YES):
|
|
204
212
|
# Return a copy of this Signature with use_fastcall=True
|
|
205
213
|
sig = copy.copy(self)
|
|
206
|
-
sig.use_fastcall =
|
|
214
|
+
sig.use_fastcall = fastcall_type
|
|
207
215
|
return sig
|
|
208
216
|
|
|
209
217
|
@property
|
|
210
218
|
def fastvar(self):
|
|
211
219
|
# Used to select variants of functions, one dealing with METH_VARARGS
|
|
212
220
|
# and one dealing with __Pyx_METH_FASTCALL
|
|
213
|
-
if self.use_fastcall:
|
|
221
|
+
if self.use_fastcall == self.FastcallUsed.YES:
|
|
214
222
|
return "FASTCALL"
|
|
223
|
+
elif self.use_fastcall == self.FastcallUsed.TP_NEW:
|
|
224
|
+
return "FASTCALL_TPNEW"
|
|
215
225
|
else:
|
|
216
226
|
return "VARARGS"
|
|
217
227
|
|
|
228
|
+
@property
|
|
229
|
+
def fastcall_guard(self):
|
|
230
|
+
if self.use_fastcall == self.FastcallUsed.YES:
|
|
231
|
+
return "CYTHON_VECTORCALL"
|
|
232
|
+
elif self.use_fastcall == self.FastcallUsed.TP_NEW:
|
|
233
|
+
return "CYTHON_VECTORCALL_TPNEW"
|
|
234
|
+
else:
|
|
235
|
+
return "1"
|
|
236
|
+
|
|
218
237
|
|
|
219
238
|
class SlotDescriptor:
|
|
220
239
|
# Abstract base class for type slot descriptors.
|
|
@@ -455,12 +474,20 @@ class ConstructorSlot(InternalMethodSlot):
|
|
|
455
474
|
InternalMethodSlot.__init__(self, slot_name, **kargs)
|
|
456
475
|
self.method = method
|
|
457
476
|
|
|
477
|
+
def to_vectorcall_slot(self):
|
|
478
|
+
# Return a dummy slot used to implement tp_vectorcall.
|
|
479
|
+
# It has the same rules about when to generate it as tp_new.
|
|
480
|
+
assert self.slot_name == "tp_new"
|
|
481
|
+
self_copy = copy.copy(self)
|
|
482
|
+
self_copy.slot_name = "tp_new_vectorcall"
|
|
483
|
+
return self_copy
|
|
484
|
+
|
|
458
485
|
def _needs_own(self, scope):
|
|
459
486
|
if (scope.parent_type.base_type
|
|
460
487
|
and not scope.has_pyobject_attrs
|
|
461
488
|
and not scope.has_memoryview_attrs
|
|
462
489
|
and not scope.has_explicitly_constructable_attrs
|
|
463
|
-
and not (self.slot_name
|
|
490
|
+
and not (self.slot_name in ('tp_new', 'tp_new_vectorcall') and scope.parent_type.vtabslot_cname)):
|
|
464
491
|
entry = scope.lookup_here(self.method) if self.method else None
|
|
465
492
|
if not (entry and entry.is_special):
|
|
466
493
|
return False
|
|
@@ -502,6 +529,40 @@ class ConstructorSlot(InternalMethodSlot):
|
|
|
502
529
|
self.generate_set_slot_code(src, scope, code)
|
|
503
530
|
|
|
504
531
|
|
|
532
|
+
class TpVectorcallSlot(ConstructorSlot):
|
|
533
|
+
def _needs_own(self, scope):
|
|
534
|
+
return True # never inherited
|
|
535
|
+
|
|
536
|
+
def slot_code(self, scope):
|
|
537
|
+
tp = scope.parent_type
|
|
538
|
+
seen_init = False
|
|
539
|
+
while tp:
|
|
540
|
+
if not tp.is_extension_type:
|
|
541
|
+
return "0"
|
|
542
|
+
if tp.is_external:
|
|
543
|
+
return "0"
|
|
544
|
+
if tp.scope.parent_scope is not scope.parent_scope:
|
|
545
|
+
# In a pxd file. We don't have enough visibility to make this work.
|
|
546
|
+
return "0"
|
|
547
|
+
if tp.multiple_bases:
|
|
548
|
+
return "0" # Can't reason about __init__
|
|
549
|
+
# If we don't have the second overloaded alternative for __cinit__ or __init__
|
|
550
|
+
# this means the signature was wrong and so we haven't generated code for the
|
|
551
|
+
# vectorcall wrappers in DefNode.analyse_declarations
|
|
552
|
+
cinit_entry = tp.scope.lookup_here("__cinit__")
|
|
553
|
+
if cinit_entry and not (cinit_entry.is_special and cinit_entry.tp_new_can_be_vectorcall):
|
|
554
|
+
return "0"
|
|
555
|
+
if not seen_init and (init_entry := tp.scope.lookup_here("__init__")):
|
|
556
|
+
if not (init_entry.is_special and init_entry.tp_new_can_be_vectorcall):
|
|
557
|
+
return "0"
|
|
558
|
+
seen_init = True
|
|
559
|
+
tp = tp.base_type
|
|
560
|
+
return super().slot_code(scope)
|
|
561
|
+
|
|
562
|
+
def generate_dynamic_init_code(self, scope, code):
|
|
563
|
+
return # never do anything dynamic here
|
|
564
|
+
|
|
565
|
+
|
|
505
566
|
class SyntheticSlot(InternalMethodSlot):
|
|
506
567
|
# Type slot descriptor for a synthesized method which
|
|
507
568
|
# dispatches to one or more user-defined methods depending
|
|
@@ -525,6 +586,75 @@ class SyntheticSlot(InternalMethodSlot):
|
|
|
525
586
|
return self.slot_code(scope)
|
|
526
587
|
|
|
527
588
|
|
|
589
|
+
class SubscriptSlot(SyntheticSlot):
|
|
590
|
+
"""
|
|
591
|
+
Slot descriptor that implements the functionally overlapping sequence/mapping slots.
|
|
592
|
+
"""
|
|
593
|
+
def __init__(self, slot_name, user_methods):
|
|
594
|
+
super().__init__(slot_name, user_methods, "0")
|
|
595
|
+
|
|
596
|
+
_slot_methods = {
|
|
597
|
+
'sq_item': ['__getitem__'],
|
|
598
|
+
'sq_ass_item': ['__setitem__', '__delitem__'],
|
|
599
|
+
'mp_subscript': ['__getitem__'],
|
|
600
|
+
'mp_ass_subscript': ['__setitem__', '__delitem__'],
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
@staticmethod
|
|
604
|
+
def find_special_method(scope, method_name):
|
|
605
|
+
while True:
|
|
606
|
+
entry = scope.lookup_here(method_name)
|
|
607
|
+
if entry is not None:
|
|
608
|
+
return entry if entry.is_special else None
|
|
609
|
+
base_type = scope.parent_type.base_type
|
|
610
|
+
if base_type is None or base_type.is_external:
|
|
611
|
+
return None
|
|
612
|
+
scope = base_type.scope
|
|
613
|
+
|
|
614
|
+
@classmethod
|
|
615
|
+
def implements_slot(cls, scope, slot_name):
|
|
616
|
+
scope_implements_methods = False
|
|
617
|
+
is_sequence_impl = True
|
|
618
|
+
for method_name in cls._slot_methods[slot_name]:
|
|
619
|
+
entry = cls.find_special_method(scope, method_name)
|
|
620
|
+
if entry is None:
|
|
621
|
+
continue
|
|
622
|
+
if entry.scope is scope:
|
|
623
|
+
scope_implements_methods = True
|
|
624
|
+
if entry.signature != sequence_subscript_signatures[method_name]:
|
|
625
|
+
is_sequence_impl = False
|
|
626
|
+
|
|
627
|
+
if not scope_implements_methods:
|
|
628
|
+
return False
|
|
629
|
+
|
|
630
|
+
if slot_name.startswith('mp_') and scope.parent_type.base_type is not None:
|
|
631
|
+
# Even when implementing the sequence protocol, a base class might have chosen to
|
|
632
|
+
# implement the mapping protocol (or may choose to do so in the future),
|
|
633
|
+
# and that would unfortunately take precedence.
|
|
634
|
+
return True
|
|
635
|
+
|
|
636
|
+
collection_type = scope.directives.get('collection_type')
|
|
637
|
+
if collection_type == 'mapping':
|
|
638
|
+
if slot_name.startswith('mp_'):
|
|
639
|
+
return True
|
|
640
|
+
# Implementing the Sequence slot doesn't hurt because the Mapping protocol takes precedence.
|
|
641
|
+
elif collection_type == 'sequence':
|
|
642
|
+
if slot_name.startswith('sq_'):
|
|
643
|
+
return True
|
|
644
|
+
elif is_sequence_impl:
|
|
645
|
+
# Mapping slot in a Sequence, implemented with sequence signature.
|
|
646
|
+
# By not implementing it, we allow callers to see that it would be inefficient to use.
|
|
647
|
+
return False
|
|
648
|
+
|
|
649
|
+
return True
|
|
650
|
+
|
|
651
|
+
def slot_code(self, scope):
|
|
652
|
+
if self.implements_slot(scope, self.slot_name):
|
|
653
|
+
return InternalMethodSlot.slot_code(self, scope)
|
|
654
|
+
else:
|
|
655
|
+
return self.default_value
|
|
656
|
+
|
|
657
|
+
|
|
528
658
|
class BinopSlot(SyntheticSlot):
|
|
529
659
|
def __init__(self, signature, slot_name, left_method, method_name_to_slot, **kargs):
|
|
530
660
|
assert left_method.startswith('__')
|
|
@@ -536,6 +666,17 @@ class BinopSlot(SyntheticSlot):
|
|
|
536
666
|
self.right_slot = MethodSlot(signature, "", right_method, method_name_to_slot, **kargs)
|
|
537
667
|
|
|
538
668
|
|
|
669
|
+
class InitSlot(MethodSlot):
|
|
670
|
+
def slot_code(self, scope):
|
|
671
|
+
super_slot_code = super().slot_code(scope)
|
|
672
|
+
if super_slot_code != "0":
|
|
673
|
+
entry = scope.lookup(self.method_name)
|
|
674
|
+
if entry and entry.is_special and entry.signature.use_fastcall:
|
|
675
|
+
# we need a wrapper
|
|
676
|
+
return InternalMethodSlot.slot_code(self, scope)
|
|
677
|
+
return super_slot_code
|
|
678
|
+
|
|
679
|
+
|
|
539
680
|
class RichcmpSlot(MethodSlot):
|
|
540
681
|
def slot_code(self, scope):
|
|
541
682
|
entry = scope.lookup_here(self.method_name)
|
|
@@ -558,13 +699,15 @@ class TypeFlagsSlot(SlotDescriptor):
|
|
|
558
699
|
else:
|
|
559
700
|
# Used to be in 'Py_TPFLAGS_DEFAULT' up to Py3.10.
|
|
560
701
|
value = f"({value}&~Py_TPFLAGS_HAVE_VERSION_TAG)"
|
|
561
|
-
value += "|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER"
|
|
562
702
|
if not scope.parent_type.is_final_type:
|
|
563
703
|
value += "|Py_TPFLAGS_BASETYPE"
|
|
564
704
|
if scope.needs_gc():
|
|
565
705
|
value += "|Py_TPFLAGS_HAVE_GC"
|
|
566
706
|
if scope.parent_type.has_sequence_flag:
|
|
567
707
|
value += "|Py_TPFLAGS_SEQUENCE"
|
|
708
|
+
if scope.parent_type.has_mapping_flag:
|
|
709
|
+
assert not scope.parent_type.has_sequence_flag
|
|
710
|
+
value += "|Py_TPFLAGS_MAPPING"
|
|
568
711
|
return value
|
|
569
712
|
|
|
570
713
|
def generate_spec(self, scope, code):
|
|
@@ -715,8 +858,9 @@ class DictOffsetSlot(SlotDescriptor):
|
|
|
715
858
|
def slot_code(self, scope):
|
|
716
859
|
dict_entry = scope.lookup_here("__dict__") if not scope.is_closure_class_scope else None
|
|
717
860
|
if dict_entry and dict_entry.is_variable:
|
|
718
|
-
|
|
719
|
-
|
|
861
|
+
if dict_entry.is_inherited:
|
|
862
|
+
return "0"
|
|
863
|
+
if not dict_entry.type.is_pydict_type:
|
|
720
864
|
error(dict_entry.pos, "__dict__ slot must be of type 'dict'")
|
|
721
865
|
return "0"
|
|
722
866
|
type = scope.parent_type
|
|
@@ -847,6 +991,7 @@ intargfunc = Signature("Ti", "O") # typedef PyObject *(*intargfunc)(PyO
|
|
|
847
991
|
ssizeargfunc = Signature("Tz", "O") # typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
|
|
848
992
|
intintargfunc = Signature("Tii", "O") # typedef PyObject *(*intintargfunc)(PyObject *, int, int);
|
|
849
993
|
ssizessizeargfunc = Signature("Tzz", "O") # typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
|
|
994
|
+
ssizeargproc = Signature("Tz", "r") # typedef int(*ssizeargfunc)(PyObject *, Py_ssize_t);
|
|
850
995
|
intobjargproc = Signature("TiO", 'r') # typedef int(*intobjargproc)(PyObject *, int, PyObject *);
|
|
851
996
|
ssizeobjargproc = Signature("TzO", 'r') # typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
|
|
852
997
|
intintobjargproc = Signature("TiiO", 'r') # typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *);
|
|
@@ -899,6 +1044,12 @@ sendfunc = PyrexTypes.CPtrType(PyrexTypes.CFuncType(
|
|
|
899
1044
|
exception_check=True, # we allow returning PYGEN_ERROR without GeneratorExit / StopIteration
|
|
900
1045
|
))
|
|
901
1046
|
|
|
1047
|
+
sequence_subscript_signatures = {
|
|
1048
|
+
'__getitem__': ssizeargfunc,
|
|
1049
|
+
'__setitem__': ssizeobjargproc,
|
|
1050
|
+
'__delitem__': ssizeargproc,
|
|
1051
|
+
}
|
|
1052
|
+
|
|
902
1053
|
|
|
903
1054
|
#------------------------------------------------------------------------------------------
|
|
904
1055
|
#
|
|
@@ -989,9 +1140,9 @@ class SlotTable:
|
|
|
989
1140
|
MethodSlot(lenfunc, "sq_length", "__len__", method_name_to_slot),
|
|
990
1141
|
EmptySlot("sq_concat"), # nb_add used instead
|
|
991
1142
|
EmptySlot("sq_repeat"), # nb_multiply used instead
|
|
992
|
-
|
|
1143
|
+
SubscriptSlot("sq_item", ["__getitem__"]),
|
|
993
1144
|
EmptySlot("sq_slice"),
|
|
994
|
-
|
|
1145
|
+
SubscriptSlot("sq_ass_item", ["__setitem__", "__delitem__"]),
|
|
995
1146
|
EmptySlot("sq_ass_slice"),
|
|
996
1147
|
MethodSlot(cmpfunc, "sq_contains", "__contains__", method_name_to_slot),
|
|
997
1148
|
EmptySlot("sq_inplace_concat"), # nb_inplace_add used instead
|
|
@@ -1000,8 +1151,8 @@ class SlotTable:
|
|
|
1000
1151
|
|
|
1001
1152
|
self.PyMappingMethods = (
|
|
1002
1153
|
MethodSlot(lenfunc, "mp_length", "__len__", method_name_to_slot),
|
|
1003
|
-
|
|
1004
|
-
|
|
1154
|
+
SubscriptSlot("mp_subscript", ["__getitem__"]),
|
|
1155
|
+
SubscriptSlot("mp_ass_subscript", ["__setitem__", "__delitem__"]),
|
|
1005
1156
|
)
|
|
1006
1157
|
|
|
1007
1158
|
self.PyBufferProcs = (
|
|
@@ -1069,7 +1220,7 @@ class SlotTable:
|
|
|
1069
1220
|
|
|
1070
1221
|
DictOffsetSlot("tp_dictoffset", ifdef="!CYTHON_USE_TYPE_SPECS"), # otherwise set via "__dictoffset__" member
|
|
1071
1222
|
|
|
1072
|
-
|
|
1223
|
+
InitSlot(initproc, "tp_init", "__init__", method_name_to_slot),
|
|
1073
1224
|
EmptySlot("tp_alloc"), #FixedSlot("tp_alloc", "PyType_GenericAlloc"),
|
|
1074
1225
|
ConstructorSlot("tp_new", "__cinit__"),
|
|
1075
1226
|
EmptySlot("tp_free"),
|
|
@@ -1084,12 +1235,15 @@ class SlotTable:
|
|
|
1084
1235
|
EmptySlot("tp_version_tag"),
|
|
1085
1236
|
SyntheticSlot("tp_finalize", ["__del__"], "0",
|
|
1086
1237
|
used_ifdef="CYTHON_USE_TP_FINALIZE"),
|
|
1087
|
-
|
|
1238
|
+
TpVectorcallSlot("tp_vectorcall",
|
|
1239
|
+
ifdef="(!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) && "
|
|
1240
|
+
"(!CYTHON_COMPILING_IN_LIMITED_API || __PYX_LIMITED_VERSION_HEX >= 0x030E0000)",
|
|
1241
|
+
used_ifdef="CYTHON_VECTORCALL_TPNEW"),
|
|
1088
1242
|
EmptySlot("tp_print", ifdef="__PYX_NEED_TP_PRINT_SLOT == 1"),
|
|
1089
1243
|
EmptySlot("tp_watched", ifdef="PY_VERSION_HEX >= 0x030C0000"),
|
|
1090
1244
|
EmptySlot("tp_versions_used", ifdef="PY_VERSION_HEX >= 0x030d00A4"),
|
|
1091
1245
|
# PyPy specific extension - only here to avoid C compiler warnings.
|
|
1092
|
-
EmptySlot("tp_pypy_flags", ifdef="CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX
|
|
1246
|
+
EmptySlot("tp_pypy_flags", ifdef="CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x030a0000"),
|
|
1093
1247
|
)
|
|
1094
1248
|
|
|
1095
1249
|
#------------------------------------------------------------------------------------------
|
|
@@ -1103,6 +1257,7 @@ class SlotTable:
|
|
|
1103
1257
|
MethodSlot(initproc, "", "__cinit__", method_name_to_slot)
|
|
1104
1258
|
MethodSlot(destructor, "", "__dealloc__", method_name_to_slot)
|
|
1105
1259
|
MethodSlot(destructor, "", "__del__", method_name_to_slot)
|
|
1260
|
+
MethodSlot(objargfunc, "", "__getitem__", method_name_to_slot)
|
|
1106
1261
|
MethodSlot(objobjargproc, "", "__setitem__", method_name_to_slot)
|
|
1107
1262
|
MethodSlot(objargproc, "", "__delitem__", method_name_to_slot)
|
|
1108
1263
|
MethodSlot(ssizessizeobjargproc, "", "__setslice__", method_name_to_slot)
|
Cython/Compiler/UtilNodes.py
CHANGED
|
@@ -387,3 +387,27 @@ class HasNoGilNode(AtomicExprNode):
|
|
|
387
387
|
|
|
388
388
|
def calculate_result_code(self):
|
|
389
389
|
return str(int(self.in_nogil_context))
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
class CPropertySetNode(ExprNodes.ExprNode):
|
|
393
|
+
subexprs = ['call_node']
|
|
394
|
+
arg1 : ExprNodes.RawCNameExprNode
|
|
395
|
+
call_node : ExprNodes.ExprNode
|
|
396
|
+
|
|
397
|
+
def is_lvalue(self):
|
|
398
|
+
return True
|
|
399
|
+
|
|
400
|
+
def analyse_types(self, env):
|
|
401
|
+
self.call_node = self.call_node.analyse_types(env)
|
|
402
|
+
return self
|
|
403
|
+
|
|
404
|
+
def generate_assignment_code(self, rhs, code, overloaded_assignment=False, exception_check=None, exception_value=None):
|
|
405
|
+
assert not overloaded_assignment
|
|
406
|
+
assert exception_check is None, exception_check
|
|
407
|
+
assert exception_value is None, exception_value
|
|
408
|
+
self.arg1.set_cname(rhs.result())
|
|
409
|
+
|
|
410
|
+
self.call_node.generate_evaluation_code(code)
|
|
411
|
+
|
|
412
|
+
rhs.generate_disposal_code(code)
|
|
413
|
+
rhs.free_temps(code)
|
Cython/Compiler/UtilityCode.py
CHANGED
Cython/Compiler/Visitor.pxd
CHANGED
Cython/Compiler/Visitor.py
CHANGED
|
@@ -304,7 +304,7 @@ class CythonTransform(VisitorTransform):
|
|
|
304
304
|
self.current_directives = node.directives
|
|
305
305
|
return super().__call__(node)
|
|
306
306
|
|
|
307
|
-
def
|
|
307
|
+
def visit_CompilerDirectivesMixin(self, node):
|
|
308
308
|
old = self.current_directives
|
|
309
309
|
self.current_directives = node.directives
|
|
310
310
|
self._process_children(node)
|
|
@@ -842,7 +842,8 @@ class PrintTree(TreeVisitor):
|
|
|
842
842
|
node.declared_name(), getattr(node, "type", None))
|
|
843
843
|
elif isinstance(node, ExprNodes.AttributeNode):
|
|
844
844
|
result += "(type=%s, attribute=\"%s\")" % (repr(node.type), node.attribute)
|
|
845
|
-
elif isinstance(node,
|
|
845
|
+
elif isinstance(node,
|
|
846
|
+
(ExprNodes.ConstNode, ExprNodes.PyConstNode, ExprNodes.ImagNode)):
|
|
846
847
|
result += "(type=%s, value=%r)" % (repr(node.type), node.value)
|
|
847
848
|
elif isinstance(node, ExprNodes.ExprNode):
|
|
848
849
|
t = node.type
|
|
@@ -12,9 +12,11 @@ import subprocess
|
|
|
12
12
|
from distutils import ccompiler
|
|
13
13
|
|
|
14
14
|
import runtests
|
|
15
|
-
import Cython
|
|
15
|
+
import Cython
|
|
16
|
+
#import Cython.Distutils.extension
|
|
16
17
|
import Cython.Distutils.old_build_ext as build_ext
|
|
17
18
|
from Cython.Debugger import Cygdb as cygdb
|
|
19
|
+
from ...TestUtils import TimedTest
|
|
18
20
|
|
|
19
21
|
root = os.path.dirname(os.path.abspath(__file__))
|
|
20
22
|
codefile = os.path.join(root, 'codefile')
|
|
@@ -66,7 +68,7 @@ def test_gdb():
|
|
|
66
68
|
return have_gdb
|
|
67
69
|
|
|
68
70
|
|
|
69
|
-
class DebuggerTestCase(
|
|
71
|
+
class DebuggerTestCase(TimedTest):
|
|
70
72
|
|
|
71
73
|
def setUp(self):
|
|
72
74
|
"""
|
|
@@ -158,7 +160,10 @@ class DebuggerTestCase(unittest.TestCase):
|
|
|
158
160
|
os.chdir(self.cwd)
|
|
159
161
|
raise
|
|
160
162
|
|
|
163
|
+
super().setUp()
|
|
164
|
+
|
|
161
165
|
def tearDown(self):
|
|
166
|
+
super().tearDown()
|
|
162
167
|
if not test_gdb():
|
|
163
168
|
return
|
|
164
169
|
os.chdir(self.cwd)
|
|
@@ -27,6 +27,7 @@ import gdb
|
|
|
27
27
|
from .. import libcython
|
|
28
28
|
from .. import libpython
|
|
29
29
|
from . import TestLibCython as test_libcython
|
|
30
|
+
from ...TestUtils import TimedTest
|
|
30
31
|
|
|
31
32
|
# for some reason sys.argv is missing in gdb
|
|
32
33
|
sys.argv = ['gdb']
|
|
@@ -53,7 +54,7 @@ class TraceMethodCallMeta(type):
|
|
|
53
54
|
setattr(self, func_name, print_on_call_decorator(func))
|
|
54
55
|
|
|
55
56
|
|
|
56
|
-
class DebugTestCase(
|
|
57
|
+
class DebugTestCase(TimedTest, metaclass=TraceMethodCallMeta):
|
|
57
58
|
"""
|
|
58
59
|
Base class for test cases. On teardown it kills the inferior and unsets
|
|
59
60
|
all breakpoints.
|
|
@@ -91,6 +92,7 @@ class DebugTestCase(unittest.TestCase, metaclass=TraceMethodCallMeta):
|
|
|
91
92
|
gdb.execute('run', to_string=True)
|
|
92
93
|
|
|
93
94
|
def tearDown(self):
|
|
95
|
+
super().tearDown()
|
|
94
96
|
gdb.execute('delete breakpoints', to_string=True)
|
|
95
97
|
try:
|
|
96
98
|
gdb.execute('kill inferior 1', to_string=True)
|
|
@@ -161,7 +163,7 @@ class TestReprMethods(DebugTestCase):
|
|
|
161
163
|
libcython.frame_repr(frame))
|
|
162
164
|
|
|
163
165
|
|
|
164
|
-
class TestParameters(
|
|
166
|
+
class TestParameters(TimedTest):
|
|
165
167
|
|
|
166
168
|
def test_parameters(self):
|
|
167
169
|
gdb.execute('set cy_colorize_code on')
|
|
@@ -122,23 +122,23 @@ cdef inline array clone(array template, Py_ssize_t length, bint zero):
|
|
|
122
122
|
if zero is true, new array will be initialized with zeroes."""
|
|
123
123
|
cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
|
|
124
124
|
if zero and op is not None:
|
|
125
|
-
memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
|
|
125
|
+
memset(op.data.as_chars, 0, <size_t> length * <size_t> op.ob_descr.itemsize)
|
|
126
126
|
return op
|
|
127
127
|
|
|
128
128
|
cdef inline array copy(array self):
|
|
129
129
|
""" make a copy of an array. """
|
|
130
130
|
cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
|
|
131
|
-
memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
|
|
131
|
+
memcpy(op.data.as_chars, self.data.as_chars, <size_t> Py_SIZE(op) * <size_t> op.ob_descr.itemsize)
|
|
132
132
|
return op
|
|
133
133
|
|
|
134
134
|
cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:
|
|
135
135
|
""" efficient appending of new stuff of same type
|
|
136
136
|
(e.g. of same array type)
|
|
137
137
|
n: number of elements (not number of bytes!) """
|
|
138
|
-
cdef
|
|
138
|
+
cdef size_t itemsize = <size_t> self.ob_descr.itemsize
|
|
139
139
|
cdef Py_ssize_t origsize = Py_SIZE(self)
|
|
140
140
|
resize_smart(self, origsize + n)
|
|
141
|
-
memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
|
|
141
|
+
memcpy(self.data.as_chars + <size_t> origsize * itemsize, stuff, <size_t> n * itemsize)
|
|
142
142
|
return 0
|
|
143
143
|
|
|
144
144
|
cdef inline int extend(array self, array other) except -1:
|
|
@@ -149,4 +149,4 @@ cdef inline int extend(array self, array other) except -1:
|
|
|
149
149
|
|
|
150
150
|
cdef inline void zero(array self) noexcept:
|
|
151
151
|
""" set all elements of array to zero. """
|
|
152
|
-
memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
|
|
152
|
+
memset(self.data.as_chars, 0, <size_t> Py_SIZE(self) * <size_t> self.ob_descr.itemsize)
|
Cython/Includes/cpython/dict.pxd
CHANGED
|
@@ -2,13 +2,8 @@ from .object cimport PyObject
|
|
|
2
2
|
from .pyport cimport uint64_t
|
|
3
3
|
|
|
4
4
|
cdef extern from *:
|
|
5
|
-
#
|
|
6
|
-
# Also backport PyDict_GetItemStringRef and PyDict_SetDefaultRef
|
|
5
|
+
# Backport PyDict_GetItemStringRef and PyDict_SetDefaultRef
|
|
7
6
|
"""
|
|
8
|
-
#if PY_MAJOR_VERSION <= 2
|
|
9
|
-
#define PyDict_GetItemWithError _PyDict_GetItemWithError
|
|
10
|
-
#endif
|
|
11
|
-
|
|
12
7
|
#if __PYX_LIMITED_VERSION_HEX < 0x030d0000
|
|
13
8
|
static CYTHON_INLINE int
|
|
14
9
|
__Pyx_CAPI_PyDict_GetItemStringRef(PyObject *mp, const char *key, PyObject **result)
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
cdef extern from *:
|
|
2
|
-
"""
|
|
3
|
-
#if PY_MAJOR_VERSION >= 3
|
|
4
|
-
#define __Pyx_PyFloat_FromString(obj) PyFloat_FromString(obj)
|
|
5
|
-
#else
|
|
6
|
-
#define __Pyx_PyFloat_FromString(obj) PyFloat_FromString(obj, NULL)
|
|
7
|
-
#endif
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
1
|
cdef extern from "Python.h":
|
|
11
2
|
############################################################################
|
|
12
3
|
# 7.2.3
|
|
@@ -29,7 +20,7 @@ cdef extern from "Python.h":
|
|
|
29
20
|
# Return true if its argument is a PyFloatObject, but not a
|
|
30
21
|
# subtype of PyFloatObject.
|
|
31
22
|
|
|
32
|
-
object PyFloat_FromString
|
|
23
|
+
object PyFloat_FromString(object str)
|
|
33
24
|
# Return value: New reference.
|
|
34
25
|
# Create a PyFloatObject object based on the string value in str,
|
|
35
26
|
# or NULL on failure. The pend argument is ignored. It remains
|
|
@@ -45,3 +36,21 @@ cdef extern from "Python.h":
|
|
|
45
36
|
double PyFloat_AS_DOUBLE(object pyfloat)
|
|
46
37
|
# Return a C double representation of the contents of pyfloat, but
|
|
47
38
|
# without error checking.
|
|
39
|
+
|
|
40
|
+
int PyFloat_Pack2(double x, unsigned char *p, int le) except -1
|
|
41
|
+
# Pack a C double as the IEEE 754 binary16 half-precision format.
|
|
42
|
+
|
|
43
|
+
int PyFloat_Pack4(double x, unsigned char *p, int le) except -1
|
|
44
|
+
# Pack a C double as the IEEE 754 binary32 single precision format.
|
|
45
|
+
|
|
46
|
+
int PyFloat_Pack8(double x, unsigned char *p, int le) except -1
|
|
47
|
+
# Pack a C double as the IEEE 754 binary64 double precision format.
|
|
48
|
+
|
|
49
|
+
double PyFloat_Unpack2(const unsigned char *p, int le) except? -1.0
|
|
50
|
+
# Unpack the IEEE 754 binary16 half-precision format as a C double.
|
|
51
|
+
|
|
52
|
+
double PyFloat_Unpack4(const unsigned char *p, int le) except? -1.0
|
|
53
|
+
# Unpack the IEEE 754 binary32 single precision format as a C double.
|
|
54
|
+
|
|
55
|
+
double PyFloat_Unpack8(const unsigned char *p, int le) except? -1.0
|
|
56
|
+
# Unpack the IEEE 754 binary64 double precision format as a C double.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
############################################################################
|
|
2
|
+
# Frozen Dictionary Objects (Python 3.15+)
|
|
3
|
+
# Backported to older Python versions by falling back to 'dict'.
|
|
4
|
+
############################################################################
|
|
5
|
+
|
|
6
|
+
cdef extern from "Python.h":
|
|
7
|
+
# PyTypeObject PyFrozenDict_Type
|
|
8
|
+
# This instance of PyTypeObject represents the Python frozen dictionary type.
|
|
9
|
+
# This is the same object as frozendict in the Python layer.
|
|
10
|
+
|
|
11
|
+
bint PyAnyDict_Check "__Pyx_PyAnyDict_Check" (object p) noexcept
|
|
12
|
+
# Return true if p is a dict object, a frozendict object, or an instance of a subtype
|
|
13
|
+
# of the dict or frozendict type.
|
|
14
|
+
# This function always succeeds.
|
|
15
|
+
|
|
16
|
+
bint PyAnyDict_CheckExact "__Pyx_PyAnyDict_CheckExact" (object p) noexcept
|
|
17
|
+
# Return true if p is a dict object or a frozendict object, but not an instance
|
|
18
|
+
# of a subtype of the dict or frozendict type.
|
|
19
|
+
# This function always succeeds.
|
|
20
|
+
|
|
21
|
+
bint PyFrozenDict_Check "__Pyx_PyFrozenDict_Check" (object p) noexcept
|
|
22
|
+
# Return true if p is a frozendict object or an instance of a subtype of the
|
|
23
|
+
# frozendict type.
|
|
24
|
+
# This function always succeeds.
|
|
25
|
+
|
|
26
|
+
bint PyFrozenDict_CheckExact "__Pyx_PyFrozenDict_CheckExact" (object p) noexcept
|
|
27
|
+
# Return true if p is a frozendict object, but not an instance of a subtype
|
|
28
|
+
# of the frozendict type.
|
|
29
|
+
# This function always succeeds.
|
|
30
|
+
|
|
31
|
+
frozendict PyFrozenDict_New "__Pyx_PyFrozenDict_New" (object iterable)
|
|
32
|
+
# Return a new frozendict from an iterable, or NULL on failure with an exception set.
|
|
33
|
+
# Create an empty dictionary if iterable is NULL.
|
|
34
|
+
|
|
35
|
+
frozendict PyFrozenDict_NewEmpty "__Pyx_PyFrozenDict_NewEmpty" ()
|
|
36
|
+
# Return a new frozendict from an iterable, or NULL on failure with an exception set.
|
|
37
|
+
# Create an empty dictionary if iterable is NULL.
|
Cython/Includes/cpython/long.pxd
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from libc.stdint cimport uint32_t, uint64_t, int32_t, int64_t
|
|
1
2
|
|
|
2
3
|
cdef extern from "Python.h":
|
|
3
4
|
ctypedef long long PY_LONG_LONG
|
|
@@ -16,6 +17,15 @@ cdef extern from "Python.h":
|
|
|
16
17
|
# This instance of PyTypeObject represents the Python long integer
|
|
17
18
|
# type. This is the same object as long and types.LongType.
|
|
18
19
|
|
|
20
|
+
cdef enum:
|
|
21
|
+
Py_ASNATIVEBYTES_DEFAULTS,
|
|
22
|
+
Py_ASNATIVEBYTES_BIG_ENDIAN,
|
|
23
|
+
Py_ASNATIVEBYTES_LITTLE_ENDIAN,
|
|
24
|
+
Py_ASNATIVEBYTES_NATIVE_ENDIAN,
|
|
25
|
+
Py_ASNATIVEBYTES_UNSIGNED_BUFFER,
|
|
26
|
+
Py_ASNATIVEBYTES_REJECT_NEGATIVE,
|
|
27
|
+
Py_ASNATIVEBYTES_ALLOW_INDEX
|
|
28
|
+
|
|
19
29
|
bint PyLong_Check(object p)
|
|
20
30
|
# Return true if its argument is a PyLongObject or a subtype of PyLongObject.
|
|
21
31
|
|
|
@@ -147,3 +157,24 @@ cdef extern from "Python.h":
|
|
|
147
157
|
# raised. This is only assured to produce a usable void pointer
|
|
148
158
|
# for values created with PyLong_FromVoidPtr(). For values outside
|
|
149
159
|
# 0..LONG_MAX, both signed and unsigned integers are accepted.
|
|
160
|
+
|
|
161
|
+
object PyLong_FromNativeBytes(const void *buffer, size_t n_bytes, int flags)
|
|
162
|
+
# Create a Python integer from the value contained in the firstn_bytes
|
|
163
|
+
# of buffer, interpreted as a two’s-complement signed number.
|
|
164
|
+
|
|
165
|
+
object PyLong_FromUnsignedNativeBytes(const void *buffer, size_t n_bytes, int flags)
|
|
166
|
+
# Create a Python integer from the value contained in the first n_bytes of
|
|
167
|
+
# buffer, interpreted as an unsigned number.
|
|
168
|
+
|
|
169
|
+
Py_ssize_t PyLong_AsNativeBytes(object pylong, void *buffer, Py_ssize_t n_bytes, int flags) except -1
|
|
170
|
+
# Copy the Python integer value pylong to a native buffer of size n_bytes.
|
|
171
|
+
# The flags can be set to -1 to behave similarly to a C cast, or to values
|
|
172
|
+
# to control the behavior.
|
|
173
|
+
|
|
174
|
+
int PyLong_AsInt32(object obj, int32_t *value) except -1
|
|
175
|
+
int PyLong_AsInt64(object obj, int64_t *value) except -1
|
|
176
|
+
# Set *value to a signed C int32_t or int64_t representation of obj.
|
|
177
|
+
|
|
178
|
+
int PyLong_AsUInt32(object obj, uint32_t *value) except -1
|
|
179
|
+
int PyLong_AsUInt64(object obj, uint64_t *value) except -1
|
|
180
|
+
# Set *value to an unsigned C uint32_t or uint64_t representation of obj.
|