diff options
| author | shadchin <[email protected]> | 2025-05-22 22:01:46 +0300 |
|---|---|---|
| committer | shadchin <[email protected]> | 2025-05-22 22:15:38 +0300 |
| commit | 523a8cd4f0e1be40af627a02a1a5b7d2a3fa92a7 (patch) | |
| tree | 3914b20600eb3e1b20a0c7cd9fee2d473ee4b519 /contrib/tools/cython/Cython/Compiler | |
| parent | d60f47d7590712a9608073b8451e3347e5ebc805 (diff) | |
Update Cython to 3.0.11
commit_hash:ad41766fcde35c98b754b17abb8523d40312b2a6
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler')
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/Code.py | 39 | ||||
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/ExprNodes.py | 9 | ||||
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/ModuleNode.py | 4 | ||||
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/Nodes.py | 1 | ||||
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/Optimize.py | 6 | ||||
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/PyrexTypes.py | 17 | ||||
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/TypeInference.py | 5 | ||||
| -rw-r--r-- | contrib/tools/cython/Cython/Compiler/TypeSlots.py | 1 |
8 files changed, 54 insertions, 28 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Code.py b/contrib/tools/cython/Cython/Compiler/Code.py index ac384d99fd3..cd7ca03443d 100644 --- a/contrib/tools/cython/Cython/Compiler/Code.py +++ b/contrib/tools/cython/Cython/Compiler/Code.py @@ -66,7 +66,7 @@ uncachable_builtins = [ # Global/builtin names that cannot be cached because they may or may not # be available at import time, for various reasons: ## Python 3.13+ - 'IncompleteInputError', + '_IncompleteInputError', 'PythonFinalizationError', ## Python 3.11+ 'BaseExceptionGroup', @@ -641,18 +641,23 @@ class UtilityCode(UtilityCodeBase): self.cleanup(writer, output.module_pos) -def sub_tempita(s, context, file=None, name=None): +def sub_tempita(s, context, file=None, name=None, __cache={}): "Run tempita on string s with given context." if not s: return None if file: - context['__name'] = "%s:%s" % (file, name) - elif name: + name = "%s:%s" % (file, name) + if name: context['__name'] = name - from ..Tempita import sub - return sub(s, **context) + try: + template = __cache[s] + except KeyError: + from ..Tempita import Template + template = __cache[s] = Template(s, name=name) + + return template.substitute(context) class TempitaUtilityCode(UtilityCode): @@ -1542,8 +1547,18 @@ class GlobalState(object): # which aren't necessarily PyObjects, so aren't appropriate # to clear. continue - self.parts['module_state_clear'].putln( - "Py_CLEAR(clear_module_state->%s);" % cname) + + self.parts['module_state_clear'].put_xdecref_clear( + "clear_module_state->%s" % cname, + c.type, + clear_before_decref=True, + nanny=False, + ) + + if c.type.is_memoryviewslice: + # TODO: Implement specific to type like CodeWriter.put_xdecref_clear() + cname += "->memview" + self.parts['module_state_traverse'].putln( "Py_VISIT(traverse_module_state->%s);" % cname) @@ -2084,14 +2099,6 @@ class CCodeWriter(object): elif fix_indent: self.level += 1 - def putln_tempita(self, code, **context): - from ..Tempita import sub - self.putln(sub(code, **context)) - - def put_tempita(self, code, **context): - from ..Tempita import sub - self.put(sub(code, **context)) - def increase_indent(self): self.level += 1 diff --git a/contrib/tools/cython/Cython/Compiler/ExprNodes.py b/contrib/tools/cython/Cython/Compiler/ExprNodes.py index 7876d09470f..952617e375d 100644 --- a/contrib/tools/cython/Cython/Compiler/ExprNodes.py +++ b/contrib/tools/cython/Cython/Compiler/ExprNodes.py @@ -481,7 +481,12 @@ class ExprNode(Node): constant_result = constant_value_not_set - child_attrs = property(fget=operator.attrgetter('subexprs')) + if getattr(getattr(sys, "implementation", None), "name", "cpython") == "cpython": + child_attrs = property(fget=operator.attrgetter('subexprs')) + else: + @property + def child_attrs(self): + return self.subexprs def analyse_annotations(self, env): pass @@ -6590,7 +6595,7 @@ class PyMethodCallNode(SimpleCallNode): self_arg = code.funcstate.allocate_temp(py_object_type, manage_ref=True) code.putln("%s = NULL;" % self_arg) - arg_offset_cname = code.funcstate.allocate_temp(PyrexTypes.c_int_type, manage_ref=False) + arg_offset_cname = code.funcstate.allocate_temp(PyrexTypes.c_uint_type, manage_ref=False) code.putln("%s = 0;" % arg_offset_cname) def attribute_is_likely_method(attr): diff --git a/contrib/tools/cython/Cython/Compiler/ModuleNode.py b/contrib/tools/cython/Cython/Compiler/ModuleNode.py index 493926637ad..469b968f6a8 100644 --- a/contrib/tools/cython/Cython/Compiler/ModuleNode.py +++ b/contrib/tools/cython/Cython/Compiler/ModuleNode.py @@ -972,7 +972,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): pass elif type.is_struct_or_union or type.is_cpp_class: self.generate_struct_union_predeclaration(entry, code) - elif type.is_ctuple and entry.used: + elif type.is_ctuple and not type.is_fused and entry.used: self.generate_struct_union_predeclaration(entry.type.struct_entry, code) elif type.is_extension_type: self.generate_objstruct_predeclaration(type, code) @@ -987,7 +987,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): self.generate_enum_definition(entry, code) elif type.is_struct_or_union: self.generate_struct_union_definition(entry, code) - elif type.is_ctuple and entry.used: + elif type.is_ctuple and not type.is_fused and entry.used: self.generate_struct_union_definition(entry.type.struct_entry, code) elif type.is_cpp_class: self.generate_cpp_class_definition(entry, code) diff --git a/contrib/tools/cython/Cython/Compiler/Nodes.py b/contrib/tools/cython/Cython/Compiler/Nodes.py index c2fcd9d6727..e1fe6ee56c9 100644 --- a/contrib/tools/cython/Cython/Compiler/Nodes.py +++ b/contrib/tools/cython/Cython/Compiler/Nodes.py @@ -3126,6 +3126,7 @@ class DefNode(FuncDefNode): if scope is None: scope = cfunc.scope cfunc_type = cfunc.type + has_explicit_exc_clause=True if len(self.args) != len(cfunc_type.args) or cfunc_type.has_varargs: error(self.pos, "wrong number of arguments") error(cfunc.pos, "previous declaration here") diff --git a/contrib/tools/cython/Cython/Compiler/Optimize.py b/contrib/tools/cython/Cython/Compiler/Optimize.py index da5f64c29b9..8dd48e951ac 100644 --- a/contrib/tools/cython/Cython/Compiler/Optimize.py +++ b/contrib/tools/cython/Cython/Compiler/Optimize.py @@ -2450,6 +2450,9 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, def _handle_simple_function_str(self, node, function, pos_args): """Optimize single argument calls to str(). """ + if node.type is Builtin.unicode_type: + # type already deduced as unicode (language_level=3) + return self._handle_simple_function_unicode(node, function, pos_args) if len(pos_args) != 1: if len(pos_args) == 0: return ExprNodes.StringNode(node.pos, value=EncodedString(), constant_result='') @@ -3516,7 +3519,8 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin, if not result: return node func_cname, utility_code, extra_args, num_type = result - args = list(args)+extra_args + assert all([arg.type.is_pyobject for arg in args]) + args = list(args) + extra_args call_node = self._substitute_method_call( node, function, diff --git a/contrib/tools/cython/Cython/Compiler/PyrexTypes.py b/contrib/tools/cython/Cython/Compiler/PyrexTypes.py index e84fcb5f93a..b522a131751 100644 --- a/contrib/tools/cython/Cython/Compiler/PyrexTypes.py +++ b/contrib/tools/cython/Cython/Compiler/PyrexTypes.py @@ -1498,7 +1498,7 @@ class BuiltinObjectType(PyObjectType): # For backwards compatibility of (Py3) 'x: int' annotations in Py2, we also allow 'long' there. type_check = '__Pyx_Py3Int_Check' elif type_name == "memoryview": - # captialize doesn't catch the 'V' + # capitalize doesn't catch the 'V' type_check = "PyMemoryView_Check" else: type_check = 'Py%s_Check' % type_name.capitalize() @@ -4582,6 +4582,8 @@ class CTupleType(CType): is_ctuple = True + subtypes = ['components'] + def __init__(self, cname, components): self.cname = cname self.components = components @@ -4666,10 +4668,19 @@ class CTupleType(CType): def cast_code(self, expr_code): return expr_code + def specialize(self, values): + assert hasattr(self, "entry") + components = [c.specialize(values) for c in self.components] + new_entry = self.entry.scope.declare_tuple_type(self.entry.pos, components) + return new_entry.type + def c_tuple_type(components): components = tuple(components) - cname = Naming.ctuple_type_prefix + type_list_identifier(components) + if any(c.is_fused for c in components): + cname = "<dummy fused ctuple>" # should never end up in code + else: + cname = Naming.ctuple_type_prefix + type_list_identifier(components) tuple_type = CTupleType(cname, components) return tuple_type @@ -5051,7 +5062,7 @@ def best_match(arg_types, functions, pos=None, env=None, args=None): if len(candidates) == 1: return candidates[0][0] elif len(candidates) == 0: - if pos is not None: + if pos is not None and errors: func, errmsg = errors[0] if len(errors) == 1 or [1 for func, e in errors if e == errmsg]: error(pos, errmsg) diff --git a/contrib/tools/cython/Cython/Compiler/TypeInference.py b/contrib/tools/cython/Cython/Compiler/TypeInference.py index 70d64fcf525..bb68db8976a 100644 --- a/contrib/tools/cython/Cython/Compiler/TypeInference.py +++ b/contrib/tools/cython/Cython/Compiler/TypeInference.py @@ -233,10 +233,7 @@ class MarkParallelAssignments(EnvTransform): self.parallel_errors = True if node.is_prange: - child_attrs = node.child_attrs - node.child_attrs = ['body', 'target', 'args'] - self.visitchildren(node) - node.child_attrs = child_attrs + self.visitchildren(node, attrs=('body', 'target', 'args')) self.parallel_block_stack.pop() if node.else_clause: diff --git a/contrib/tools/cython/Cython/Compiler/TypeSlots.py b/contrib/tools/cython/Cython/Compiler/TypeSlots.py index 2c891f64810..ad27e0d6eaa 100644 --- a/contrib/tools/cython/Cython/Compiler/TypeSlots.py +++ b/contrib/tools/cython/Cython/Compiler/TypeSlots.py @@ -1102,6 +1102,7 @@ class SlotTable(object): EmptySlot("tp_vectorcall", ifdef="PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)"), EmptySlot("tp_print", ifdef="__PYX_NEED_TP_PRINT_SLOT == 1"), EmptySlot("tp_watched", ifdef="PY_VERSION_HEX >= 0x030C0000"), + EmptySlot("tp_versions_used", ifdef="PY_VERSION_HEX >= 0x030d00A4"), # PyPy specific extension - only here to avoid C compiler warnings. EmptySlot("tp_pypy_flags", ifdef="CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000"), ) |
