Commit 953d754d authored by Xavier Thompson's avatar Xavier Thompson

Assign cclass PyTypeObject pointer to underlying cypclass's wrapper instance

parent 255c4e25
......@@ -82,19 +82,6 @@ def cypclass_iter_scopes(scope):
for e, s in cypclass_iter_scopes(cypclass_scope):
yield e, s
def generate_cypclass_typeobj_declarations(env, code, definition):
"""
Generate pre-declarations of the PyTypeObject for each cypclass
"""
for entry in cypclass_iter(env):
if definition or entry.defined_in_pxd:
# Todo: determine whether the __new__ called in the constructor
# actually returns an instance of the cypclass type.
# and do this computation only once
# (cf generate_cyp_class_wrapper_definition)
code.putln("static PyTypeObject %s;" % (entry.type.typeobj_cname))
......@@ -595,7 +582,7 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
code.putln("if(self) {")
code.putln("self->ob_cypyobject = new CyPyObject(); // for now")
code.putln("self->ob_cypyobject->ob_refcnt = 0;")
code.putln("self->ob_cypyobject->ob_type = &%s;" % type.typeobj_cname)
code.putln("self->ob_cypyobject->ob_type = %s;" % type.wrapper_type.typeptr_cname)
code.putln("}")
if init_entry:
......
......@@ -633,7 +633,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env.c_class_entries[:] = self.sort_types_by_inheritance(
entry_dict, entry_order, key_func)
def generate_type_definitions(self, env, modules, vtab_list, vtabslot_list, code):
def generate_type_definitions(self, env, modules, vtab_list, vtabslot_list, code, globalstate):
# TODO: Why are these separated out?
for entry in vtabslot_list:
self.generate_objstruct_predeclaration(entry.type, code)
......@@ -652,11 +652,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type_entries = [t for t in type_entries if t not in vtabslot_entries]
self.generate_type_header_code(type_entries, code)
code.putln("")
code.putln("/* PyTypeObject pointer declarations for cypclasses */")
CypclassWrapper.generate_cypclass_typeobj_declarations(module, code, definition)
code.putln("/* PyTypeObject pointer declarations for all c classes */")
self.generate_c_class_declarations(module, code, definition, globalstate)
code.putln("")
code.putln("/* Deferred definitions for cypclasses */")
CypclassWrapper.generate_cyp_class_deferred_definitions(env, code, definition)
for entry in vtabslot_list:
self.generate_objstruct_definition(entry.type, code)
self.generate_typeobj_predeclaration(entry, code)
......@@ -679,13 +680,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
typecode.putln('#endif')
vtab_list, vtabslot_list = self.sort_type_hierarchy(modules, env)
self.generate_type_definitions(
env, modules, vtab_list, vtabslot_list, typecode)
env, modules, vtab_list, vtabslot_list, typecode, globalstate)
modulecode = globalstate['module_declarations']
for module in modules:
defined_here = module is env
modulecode.putln("")
modulecode.putln("/* Module declarations from %s */" % module.qualified_name.as_c_string_literal())
self.generate_c_class_declarations(module, modulecode, defined_here, globalstate)
self.generate_cvariable_declarations(module, modulecode, defined_here)
self.generate_cfunction_declarations(module, modulecode, defined_here)
......
......@@ -1663,6 +1663,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
wrapper.declare(module_scope)
if self.scope:
wrapper.analyse_declarations(module_scope)
self.entry.type.wrapper_type = wrapper.entry.type
wrapper.entry.type.is_cyp_wrapper = 1
self.cyp_wrapper = wrapper
......
......@@ -1498,10 +1498,12 @@ class PyExtensionType(PyObjectType):
# early_init boolean Whether to initialize early (as opposed to during module execution).
# defered_declarations [thunk] Used to declare class hierarchies in order
# check_size 'warn', 'error', 'ignore' What to do if tp_basicsize does not match
# is_cyp_wrapper boolean Whether this extension type wraps a cypclass
is_extension_type = 1
has_attributes = 1
early_init = 1
is_cyp_wrapper = 0
objtypedef_cname = None
......@@ -4173,6 +4175,8 @@ def compute_mro_generic(cls):
class CypClassType(CppClassType):
# lock_mode string (tri-state: "nolock"/"checklock"/"autolock")
# _mro [CppClassType] or None The Method Resolution Order of this cypclass according to Python
# wrapper_type PyExtensionType the type of the cclass wrapper
is_cyp_class = 1
to_py_function = "__Pyx_PyObject_FromCyObject"
......@@ -4182,7 +4186,7 @@ class CypClassType(CppClassType):
self.lock_mode = lock_mode if lock_mode else "autolock"
self.activable = activable
self._mro = None
self.typeobj_cname = None # set externally
self.wrapper_type = None # set during
# Return the MRO for this cypclass
# Compute all the mro needed when a previous computation is not available
......
......@@ -737,8 +737,6 @@ class Scope(object):
if cypclass:
type = PyrexTypes.CypClassType(
name, scope, cname, base_classes, templates = templates, lock_mode=lock_mode, activable=activable)
# generate PyTypeObject cname for cypclass
type.typeobj_cname = self.c_mangle(Naming.typeobj_prefix, name)
else:
type = PyrexTypes.CppClassType(
name, scope, cname, base_classes, templates = templates)
......
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