Commit 877cf431 authored by gsamain's avatar gsamain Committed by Xavier Thompson

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 359d9a03
......@@ -5599,18 +5599,7 @@ class CallNode(ExprNode):
constructor = wrapper = type.scope.lookup_here("<constructor>")
if not wrapper:
error(self.function.pos, "no constructor wrapper found for Cypclass type '%s'" % self.function.name)
namespace_list = wrapper.func_cname.split('::')
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_cname = wrapper.func_cname
constructor_type = wrapper.type
elif not constructor:
error(self.function.pos, "no constructor found for C++ type '%s'" % self.function.name)
......
......@@ -1048,7 +1048,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
else:
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:
for constructor_alternative in constructor.all_alternatives():
arg_decls = []
......@@ -1158,7 +1162,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self_type = wrapper_entry.type.return_type.declaration_code('')
type_string = type.empty_declaration_code()
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
arg_decls = []
......@@ -1180,7 +1184,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
arg_decls = ["void"]
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("{")
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