Commit a0b9c1c5 authored by gsamain's avatar gsamain

Fix C++ garbage when trying to access __constructor__: generate each...

Fix C++ garbage when trying to access __constructor__: generate each constructor wrapper as a static method inside the class
parent 912351a1
...@@ -5532,18 +5532,7 @@ class CallNode(ExprNode): ...@@ -5532,18 +5532,7 @@ class CallNode(ExprNode):
constructor = wrapper = type.scope.lookup_here("<constructor>") constructor = wrapper = type.scope.lookup_here("<constructor>")
if not wrapper: if not wrapper:
error(self.function.pos, "no constructor wrapper found for Cypclass type '%s'" % self.function.name) error(self.function.pos, "no constructor wrapper found for Cypclass type '%s'" % self.function.name)
namespace_list = wrapper.func_cname.split('::') constructor_cname = wrapper.func_cname
templates = ''
if type.templates:
templates = '<' + ','.join([param.declaration_code('')
for param in type.templates
if not PyrexTypes.is_optional_template_param(param) and not param.is_fused]) + '>'
if len(namespace_list) > 2:
# We do this because cypclass wrappers are outside of the class namespace
# in the C++ code, but they are declared within the class scope
constructor_cname = '::'.join(namespace_list[:-2] + [namespace_list[-1]]) + templates
else:
constructor_cname = namespace_list[-1] + templates
constructor_type = wrapper.type constructor_type = wrapper.type
elif not constructor: elif not constructor:
error(self.function.pos, "no constructor found for C++ type '%s'" % self.function.name) error(self.function.pos, "no constructor found for C++ type '%s'" % self.function.name)
......
...@@ -975,7 +975,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -975,7 +975,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else: else:
code.putln("%s(%s);" % (type.cname, ", ".join(arg_decls))) code.putln("%s(%s);" % (type.cname, ", ".join(arg_decls)))
if not type.is_cyp_class and (constructor or py_attrs): if type.is_cyp_class:
constructor = scope.lookup_here("<constructor>")
for constructor_alternative in constructor.all_alternatives():
code.putln("static %s;" % constructor_alternative.type.declaration_code(constructor_alternative.cname))
elif constructor or py_attrs:
if constructor: if constructor:
for constructor_alternative in constructor.all_alternatives(): for constructor_alternative in constructor.all_alternatives():
arg_decls = [] arg_decls = []
...@@ -1085,7 +1089,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1085,7 +1089,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self_type = wrapper_entry.type.return_type.declaration_code('') self_type = wrapper_entry.type.return_type.declaration_code('')
type_string = type.empty_declaration_code() type_string = type.empty_declaration_code()
class_name = type.name class_name = type.name
wrapper_cname = "%s__constructor__%s" % (Naming.func_prefix, class_name) wrapper_cname = "%s::%s__constructor__%s" % (type_string, Naming.func_prefix, class_name)
wrapper_type = wrapper_entry.type wrapper_type = wrapper_entry.type
arg_decls = [] arg_decls = []
...@@ -1107,7 +1111,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1107,7 +1111,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
arg_decls = ["void"] arg_decls = ["void"]
decl_arg_string = ', '.join(arg_decls) decl_arg_string = ', '.join(arg_decls)
code.putln("static %s %s(%s)" % (self_type, wrapper_cname, decl_arg_string)) code.putln("%s %s(%s)" % (self_type, wrapper_cname, decl_arg_string))
code.putln("{") code.putln("{")
wrapper_arg_types = [arg.type for arg in wrapper_entry.type.args] wrapper_arg_types = [arg.type for arg in wrapper_entry.type.args]
......
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