Commit 140313e2 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Fix #303 as per Lisandro's idea

parent 7ea04648
...@@ -793,10 +793,17 @@ class CVarDefNode(StatNode): ...@@ -793,10 +793,17 @@ class CVarDefNode(StatNode):
dest_scope = env dest_scope = env
self.dest_scope = dest_scope self.dest_scope = dest_scope
base_type = self.base_type.analyse(env) base_type = self.base_type.analyse(env)
if (dest_scope.is_c_class_scope
and self.visibility == 'public' # If the field is an external typedef, we cannot be sure about the type,
and base_type.is_pyobject # so do conversion ourself rather than rely on the CPython mechanism (through
and (base_type.is_builtin_type or base_type.is_extension_type)): # a property; made in AnalyseDeclarationsTransform).
# Also, if the type is an extension type, then the CPython mechanism does
# not do enough type-checking for us.
if (dest_scope.is_c_class_scope and
((self.visibility == 'public'
and base_type.is_pyobject
and (base_type.is_builtin_type or base_type.is_extension_type)
or (base_type.is_typedef and base_type.typedef_is_external)))):
self.need_properties = [] self.need_properties = []
need_property = True need_property = True
visibility = 'private' visibility = 'private'
......
...@@ -161,12 +161,15 @@ class CTypedefType(BaseType): ...@@ -161,12 +161,15 @@ class CTypedefType(BaseType):
# qualified_name string # qualified_name string
# typedef_cname string # typedef_cname string
# typedef_base_type PyrexType # typedef_base_type PyrexType
# typedef_is_external bool
is_typedef = 1 is_typedef = 1
typedef_is_external = 0
def __init__(self, cname, base_type): def __init__(self, cname, base_type, is_external=0):
self.typedef_cname = cname self.typedef_cname = cname
self.typedef_base_type = base_type self.typedef_base_type = base_type
self.typedef_is_external = is_external
def resolve(self): def resolve(self):
return self.typedef_base_type.resolve() return self.typedef_base_type.resolve()
......
...@@ -347,7 +347,7 @@ class Scope(object): ...@@ -347,7 +347,7 @@ class Scope(object):
cname = name cname = name
else: else:
cname = self.mangle(Naming.type_prefix, name) cname = self.mangle(Naming.type_prefix, name)
type = PyrexTypes.CTypedefType(cname, base_type) type = PyrexTypes.CTypedefType(cname, base_type, (visibility == 'extern'))
entry = self.declare_type(name, type, pos, cname, visibility) entry = self.declare_type(name, type, pos, cname, visibility)
type.qualified_name = entry.qualified_name type.qualified_name = entry.qualified_name
return entry return entry
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment