From: Robert Bradshaw Date: Wed, 26 Nov 2008 00:28:26 +0000 (-0800) Subject: cdef extern structs may be c++ classes, can refer to themselves X-Git-Tag: 0.10.3~4^2 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=f020a6d20b1810490044d5a7bdeed8285f578724;p=cython.git cdef extern structs may be c++ classes, can refer to themselves --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 404b2c4a..a70f976c 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -790,24 +790,25 @@ class CStructOrUnionDefNode(StatNode): self.entry.defined_in_pxd = 1 for attr in self.attributes: attr.analyse_declarations(env, scope) - for attr in scope.var_entries: - type = attr.type - while type.is_array: - type = type.base_type - if type == self.entry.type: - error(attr.pos, "Struct cannot contain itself as a member.") - if self.typedef_flag: - while type.is_ptr: + if self.visibility != 'extern': + for attr in scope.var_entries: + type = attr.type + while type.is_array: type = type.base_type if type == self.entry.type: - need_typedef_indirection = True - if need_typedef_indirection and self.visibility != 'extern': - # C can't handle typedef structs that refer to themselves. - struct_entry = self.entry - cname = env.new_const_cname() - self.entry = env.declare_typedef(self.name, struct_entry.type, self.pos, cname = self.cname, visibility='ignore') - struct_entry.type.typedef_flag = False - struct_entry.cname = struct_entry.type.cname = env.new_const_cname() + error(attr.pos, "Struct cannot contain itself as a member.") + if self.typedef_flag: + while type.is_ptr: + type = type.base_type + if type == self.entry.type: + need_typedef_indirection = True + if need_typedef_indirection: + # C can't handle typedef structs that refer to themselves. + struct_entry = self.entry + cname = env.new_const_cname() + self.entry = env.declare_typedef(self.name, struct_entry.type, self.pos, cname = self.cname, visibility='ignore') + struct_entry.type.typedef_flag = False + struct_entry.cname = struct_entry.type.cname = env.new_const_cname() def analyse_expressions(self, env): pass