Commit 9c4ff39b authored by Xavier Thompson's avatar Xavier Thompson

Assign cclass PyTypeObject pointer to underlying cypclass's wrapper instance

parent 0ec4fba9
...@@ -82,19 +82,6 @@ def cypclass_iter_scopes(scope): ...@@ -82,19 +82,6 @@ def cypclass_iter_scopes(scope):
for e, s in cypclass_iter_scopes(cypclass_scope): for e, s in cypclass_iter_scopes(cypclass_scope):
yield e, s 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 ...@@ -595,7 +582,7 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
code.putln("if(self) {") code.putln("if(self) {")
code.putln("self->ob_cypyobject = new CyPyObject(); // for now") code.putln("self->ob_cypyobject = new CyPyObject(); // for now")
code.putln("self->ob_cypyobject->ob_refcnt = 0;") 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("}") code.putln("}")
if init_entry: if init_entry:
......
...@@ -587,11 +587,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -587,11 +587,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type_entries = [t for t in type_entries if t not in vtabslot_entries] type_entries = [t for t in type_entries if t not in vtabslot_entries]
self.generate_type_header_code(type_entries, code) self.generate_type_header_code(type_entries, code)
code.putln("") code.putln("")
code.putln("/* PyTypeObject pointer declarations for cypclasses */") code.putln("/* PyTypeObject pointer declarations for all c classes */")
CypclassWrapper.generate_cypclass_typeobj_declarations(module, code, definition) self.generate_c_class_declarations(module, code, definition)
code.putln("") code.putln("")
code.putln("/* Deferred definitions for cypclasses */") code.putln("/* Deferred definitions for cypclasses */")
CypclassWrapper.generate_cyp_class_deferred_definitions(env, code, definition) CypclassWrapper.generate_cyp_class_deferred_definitions(env, code, definition)
for entry in vtabslot_list: for entry in vtabslot_list:
self.generate_objstruct_definition(entry.type, code) self.generate_objstruct_definition(entry.type, code)
self.generate_typeobj_predeclaration(entry, code) self.generate_typeobj_predeclaration(entry, code)
...@@ -620,7 +621,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -620,7 +621,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
defined_here = module is env defined_here = module is env
modulecode.putln("") modulecode.putln("")
modulecode.putln("/* Module declarations from '%s' */" % module.qualified_name) modulecode.putln("/* Module declarations from '%s' */" % module.qualified_name)
self.generate_c_class_declarations(module, modulecode, defined_here)
self.generate_cvariable_declarations(module, modulecode, defined_here) self.generate_cvariable_declarations(module, modulecode, defined_here)
self.generate_cfunction_declarations(module, modulecode, defined_here) self.generate_cfunction_declarations(module, modulecode, defined_here)
......
...@@ -1638,6 +1638,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode): ...@@ -1638,6 +1638,8 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
wrapper.declare(module_scope) wrapper.declare(module_scope)
if self.scope: if self.scope:
wrapper.analyse_declarations(module_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 self.cyp_wrapper = wrapper
......
...@@ -1361,10 +1361,12 @@ class PyExtensionType(PyObjectType): ...@@ -1361,10 +1361,12 @@ class PyExtensionType(PyObjectType):
# early_init boolean Whether to initialize early (as opposed to during module execution). # early_init boolean Whether to initialize early (as opposed to during module execution).
# defered_declarations [thunk] Used to declare class hierarchies in order # defered_declarations [thunk] Used to declare class hierarchies in order
# check_size 'warn', 'error', 'ignore' What to do if tp_basicsize does not match # 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 is_extension_type = 1
has_attributes = 1 has_attributes = 1
early_init = 1 early_init = 1
is_cyp_wrapper = 0
objtypedef_cname = None objtypedef_cname = None
...@@ -3897,6 +3899,8 @@ class CppClassType(CType): ...@@ -3897,6 +3899,8 @@ class CppClassType(CType):
class CypClassType(CppClassType): class CypClassType(CppClassType):
# lock_mode string (tri-state: "nolock"/"checklock"/"autolock") # lock_mode string (tri-state: "nolock"/"checklock"/"autolock")
# wrapper_type PyExtensionType the type of the cclass wrapper
is_cyp_class = 1 is_cyp_class = 1
to_py_function = "__Pyx_PyObject_FromCyObject" to_py_function = "__Pyx_PyObject_FromCyObject"
...@@ -3905,7 +3909,7 @@ class CypClassType(CppClassType): ...@@ -3905,7 +3909,7 @@ class CypClassType(CppClassType):
CppClassType.__init__(self, name, scope, cname, base_classes, templates, template_type, nogil) CppClassType.__init__(self, name, scope, cname, base_classes, templates, template_type, nogil)
self.lock_mode = lock_mode if lock_mode else "autolock" self.lock_mode = lock_mode if lock_mode else "autolock"
self.activable = activable self.activable = activable
self.typeobj_cname = None # set externally self.wrapper_type = None # set during
def empty_declaration_code(self): def empty_declaration_code(self):
......
...@@ -672,8 +672,6 @@ class Scope(object): ...@@ -672,8 +672,6 @@ class Scope(object):
if cypclass: if cypclass:
type = PyrexTypes.CypClassType( type = PyrexTypes.CypClassType(
name, scope, cname, base_classes, templates = templates, lock_mode=lock_mode, activable=activable) 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: else:
type = PyrexTypes.CppClassType( type = PyrexTypes.CppClassType(
name, scope, cname, base_classes, templates = templates) 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