From 78871be70d6212247b65418266134afd0a2be485 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 18 Feb 2010 18:01:37 -0800 Subject: [PATCH] C++ class constructor calls. --- Cython/Compiler/ExprNodes.py | 9 +++++++++ Cython/Compiler/PyrexTypes.py | 2 ++ Cython/Compiler/Symtab.py | 1 + tests/run/cpp_nested_templates.pyx | 5 ++--- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index a6b52f7d..2e5eb163 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2453,6 +2453,15 @@ class CallNode(ExprNode): self.analyse_types(env) self.coerce_to(type, env) return True + elif type and type.is_cpp_class: + for arg in self.args: + arg.analyse_types(env) + constructor = type.scope.lookup("") + self.function = RawCNameExprNode(self.function.pos, constructor.type) + self.function.entry = constructor + self.function.set_cname(type.declaration_code("")) + self.analyse_c_function_call(env) + return True def nogil_check(self, env): func_type = self.function_type() diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index e9c4ff38..a8f4acce 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1890,6 +1890,8 @@ class CppClassType(CType): def assignable_from_resolved_type(self, other_type): # TODO: handle operator=(...) here? + if other_type is error_type: + return True return other_type.is_cpp_class and other_type.is_subclass(self) def attributes_known(self): diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 70de775d..1e6cdbe8 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1536,6 +1536,7 @@ class CppClassScope(Scope): api = 0, in_pxd = 0, modifiers = ()): if name == self.name.split('::')[-1] and cname is None: name = '' + type.return_type = self.lookup(self.name).type prev_entry = self.lookup_here(name) entry = self.declare_var(name, type, pos, cname, visibility) if prev_entry: diff --git a/tests/run/cpp_nested_templates.pyx b/tests/run/cpp_nested_templates.pyx index 7c79e3b8..85e7c475 100644 --- a/tests/run/cpp_nested_templates.pyx +++ b/tests/run/cpp_nested_templates.pyx @@ -22,8 +22,7 @@ def test_wrap_pair(int i, double x): (2, 2.25, True) """ try: - pair = new Pair[int, double](i, x) - wrap = new Wrap[Pair[int, double]](deref(pair)) + wrap = new Wrap[Pair[int, double]](Pair[int, double](i, x)) return wrap.get().first(), wrap.get().second(), deref(wrap) == deref(wrap) finally: - del pair, wrap + del wrap -- 2.26.2