dest_scope = env
self.dest_scope = dest_scope
base_type = self.base_type.analyse(env)
- 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)):
+
+ # If the field is an external typedef, we cannot be sure about the type,
+ # so do conversion ourself rather than rely on the CPython mechanism (through
+ # 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 = []
need_property = True
visibility = 'private'
# qualified_name string
# typedef_cname string
# typedef_base_type PyrexType
+ # typedef_is_external bool
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_base_type = base_type
+ self.typedef_is_external = is_external
def resolve(self):
return self.typedef_base_type.resolve()
cname = name
else:
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)
type.qualified_name = entry.qualified_name
return entry