diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index d47d917f822c5c19793d4a561812d7951ea1146f..68a6af741f80ce1ab26fde92b3100bb692bb6d9b 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -6595,6 +6595,7 @@ class TupleNode(SequenceNode): self.generate_sequence_packing_code(code) code.put_giveref(self.py_result()) else: + self.type.entry.used = True self.generate_sequence_packing_code(code) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 4e7a38a1c20742b3339eb67ac2f0538ca0080005..560acc1b818a2d7bf1986f545b605d267870488b 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -721,6 +721,8 @@ 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: + self.generate_struct_union_predeclaration(entry.type.struct_entry, code) elif type.is_extension_type: self.generate_objstruct_predeclaration(type, code) # Actual declarations @@ -734,6 +736,8 @@ 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: + self.generate_struct_union_definition(entry.type.struct_entry, code) elif type.is_cpp_class: self.generate_cpp_class_definition(entry, code) elif type.is_extension_type: diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 6d1fee7fb70f2e3a90297a7c37aa0735546de647..0f75741fc705b95053f3afc65aef9a0a69a9748e 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1172,7 +1172,8 @@ class CTupleBaseTypeNode(CBaseTypeNode): return PyrexType.error_type component_types.append(type) type = PyrexTypes.c_tuple_type(component_types) - env.declare_tuple_type(self.pos, type) + entry = env.declare_tuple_type(self.pos, type) + entry.used = True return type diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 0f781112ece39c4e71c3e193ebcd6f7b1a87cc04..a60f5e31643cc5278c0a0c072979f6b81f405d3b 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -607,7 +607,7 @@ class Scope(object): return entry def declare_tuple_type(self, pos, type): - self.outer_scope.declare_tuple_type(pos, type) + return self.outer_scope.declare_tuple_type(pos, type) def declare_var(self, name, type, pos, cname = None, visibility = 'private', @@ -1070,9 +1070,11 @@ class ModuleScope(Scope): scope = StructOrUnionScope(cname) for ix, component in enumerate(type.components): scope.declare_var(name="f%s" % ix, type=component, pos=pos) - entry = self.declare_struct_or_union(cname, 'struct', scope, typedef_flag=True, pos=pos, cname=cname) - entry.used = True - type.struct = entry + struct_entry = self.declare_struct_or_union(cname + '_struct', 'struct', scope, typedef_flag=True, pos=pos, cname=cname) + self.type_entries.remove(struct_entry) + type.struct_entry = struct_entry + type.entry = self.declare_type(cname, type, pos, cname) + return type.entry def declare_builtin(self, name, pos): if not hasattr(builtins, name) \