Commit fc537c18 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge branch 'typetype'

parents 702f1f4d 62c275f9
...@@ -8691,7 +8691,7 @@ class CnameDecoratorNode(StatNode): ...@@ -8691,7 +8691,7 @@ class CnameDecoratorNode(StatNode):
e.type.typeptr_cname = self.cname + '_type' e.type.typeptr_cname = self.cname + '_type'
e.type.scope.namespace_cname = e.type.typeptr_cname e.type.scope.namespace_cname = e.type.typeptr_cname
e.as_variable.cname = py_object_type.cast_code(e.type.typeptr_cname) e.as_variable.cname = e.type.typeptr_cname
scope.scope_prefix = self.cname + "_" scope.scope_prefix = self.cname + "_"
......
...@@ -985,6 +985,7 @@ class BuiltinObjectType(PyObjectType): ...@@ -985,6 +985,7 @@ class BuiltinObjectType(PyObjectType):
vtabptr_cname = None vtabptr_cname = None
typedef_flag = True typedef_flag = True
is_external = True is_external = True
decl_type = 'PyObject'
def __init__(self, name, cname, objstruct_cname=None): def __init__(self, name, cname, objstruct_cname=None):
self.name = name self.name = name
...@@ -992,6 +993,10 @@ class BuiltinObjectType(PyObjectType): ...@@ -992,6 +993,10 @@ class BuiltinObjectType(PyObjectType):
self.typeptr_cname = "(&%s)" % cname self.typeptr_cname = "(&%s)" % cname
self.objstruct_cname = objstruct_cname self.objstruct_cname = objstruct_cname
self.is_gc_simple = name in builtin_types_that_cannot_create_refcycles self.is_gc_simple = name in builtin_types_that_cannot_create_refcycles
if name == 'type':
# Special case the type type, as many C API calls (and other
# libraries) actually expect a PyTypeObject* for type arguments.
self.decl_type = objstruct_cname
def set_scope(self, scope): def set_scope(self, scope):
self.scope = scope self.scope = scope
...@@ -1079,13 +1084,19 @@ class BuiltinObjectType(PyObjectType): ...@@ -1079,13 +1084,19 @@ class BuiltinObjectType(PyObjectType):
if pyrex or for_display: if pyrex or for_display:
base_code = self.name base_code = self.name
else: else:
base_code = public_decl("PyObject", dll_linkage) base_code = public_decl(self.decl_type, dll_linkage)
entity_code = "*%s" % entity_code entity_code = "*%s" % entity_code
return self.base_declaration_code(base_code, entity_code) return self.base_declaration_code(base_code, entity_code)
def as_pyobject(self, cname):
if self.decl_type == 'PyObject':
return cname
else:
return "(PyObject *)" + cname
def cast_code(self, expr_code, to_object_struct = False): def cast_code(self, expr_code, to_object_struct = False):
return "((%s*)%s)" % ( return "((%s*)%s)" % (
to_object_struct and self.objstruct_cname or "PyObject", # self.objstruct_cname may be None to_object_struct and self.objstruct_cname or self.decl_type, # self.objstruct_cname may be None
expr_code) expr_code)
def py_type_name(self): def py_type_name(self):
......
...@@ -948,7 +948,7 @@ class BuiltinScope(Scope): ...@@ -948,7 +948,7 @@ class BuiltinScope(Scope):
var_entry = Entry(name = entry.name, var_entry = Entry(name = entry.name,
type = self.lookup('type').type, # make sure "type" is the first type declared... type = self.lookup('type').type, # make sure "type" is the first type declared...
pos = entry.pos, pos = entry.pos,
cname = "((PyObject*)%s)" % entry.type.typeptr_cname) cname = entry.type.typeptr_cname)
var_entry.is_variable = 1 var_entry.is_variable = 1
var_entry.is_cglobal = 1 var_entry.is_cglobal = 1
var_entry.is_readonly = 1 var_entry.is_readonly = 1
...@@ -1525,7 +1525,7 @@ class ModuleScope(Scope): ...@@ -1525,7 +1525,7 @@ class ModuleScope(Scope):
var_entry = Entry(name = entry.name, var_entry = Entry(name = entry.name,
type = Builtin.type_type, type = Builtin.type_type,
pos = entry.pos, pos = entry.pos,
cname = "((PyObject*)%s)" % entry.type.typeptr_cname) cname = entry.type.typeptr_cname)
var_entry.is_variable = 1 var_entry.is_variable = 1
var_entry.is_cglobal = 1 var_entry.is_cglobal = 1
var_entry.is_readonly = 1 var_entry.is_readonly = 1
......
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