From: Robert Bradshaw Date: Tue, 15 Dec 2009 10:36:32 +0000 (-0800) Subject: Use C++ style constructor declarations rather than __init__. X-Git-Tag: 0.13.beta0~353^2~34 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=16bf4f7648cd6d95fc797b3c253ab3cfea4a2fff;p=cython.git Use C++ style constructor declarations rather than __init__. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 9ab2b259..5381666a 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1095,12 +1095,12 @@ class NewExprNode(AtomicExprNode): type = entry.type.specialize_here(self.pos, template_types) else: type = entry.type - constructor = type.scope.lookup(u'__init__') + constructor = type.scope.lookup(u'') if constructor is None: return_type = PyrexTypes.CFuncType(type, []) return_type = PyrexTypes.CPtrType(return_type) - type.scope.declare_cfunction(u'__init__', return_type, self.pos) - constructor = type.scope.lookup(u'__init__') + type.scope.declare_cfunction(u'', return_type, self.pos) + constructor = type.scope.lookup(u'') self.class_type = type self.entry = constructor self.type = constructor.type @@ -4282,8 +4282,7 @@ class NumBinopNode(BinopNode): entry = env.lookup(type1.name) function = entry.type.scope.lookup("operator%s" % self.operator) if not function: - error(self.pos, "'%s' operator not defined for '%s %s %s'" - % (self.operator, type1, self.operator, type2)) + self.type_error() return entry = PyrexTypes.best_match([self.operand1, self.operand2], function.all_alternatives(), self.pos) if entry is None: @@ -4981,8 +4980,8 @@ class PrimaryCmpNode(NewTempExprNode, CmpNode): entry = env.lookup(type1.name) function = entry.type.scope.lookup("operator%s" % self.operator) if not function: - error(self.pos, "'%s' operator not defined for '%s %s %s'" - % (self.operator, type1, self.operator, type2)) + error(self.pos, "Invalid types for '%s' (%s, %s)" % + (self.operator, type1, type2)) return entry = PyrexTypes.best_match([self.operand1, self.operand2], function.all_alternatives(), self.pos) if entry is None: diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index e26f35c8..0be550e8 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1634,6 +1634,8 @@ class CppClassScope(Scope): def declare_cfunction(self, name, type, pos, cname = None, visibility = 'extern', defining = 0, api = 0, in_pxd = 0, modifiers = ()): + if name == self.name.split('::')[-1] and cname is None: + name = '' entry = self.declare_var(name, type, pos, cname, visibility) def declare_inherited_cpp_attributes(self, base_scope): diff --git a/tests/compile/cpp_templates.pyx b/tests/compile/cpp_templates.pyx index fb1b2cc3..2476a530 100644 --- a/tests/compile/cpp_templates.pyx +++ b/tests/compile/cpp_templates.pyx @@ -1,12 +1,12 @@ cdef extern from "templates.h": cdef cppclass TemplateTest1[T]: - __init__() + TemplateTest1() T value int t T getValue() cdef cppclass TemplateTest2[T, U]: - __init__() + TemplateTest2() T value1 U value2 T getValue1() diff --git a/tests/run/cpp_classes.pyx b/tests/run/cpp_classes.pyx index 84cbfaa0..5e5747df 100644 --- a/tests/run/cpp_classes.pyx +++ b/tests/run/cpp_classes.pyx @@ -14,16 +14,16 @@ cdef extern from "shapes.h" namespace shapes: cdef cppclass Circle(Shape): int radius - __init__(int) + Circle(int) cdef cppclass Rectangle(Shape): int width int height - __init__(int, int) + Rectangle(int, int) cdef cppclass Square(Rectangle): int side - __init__(int) + Square(int) int constructor_count, destructor_count