From 09cbfe821a3c4b7dd2045af14b4306fd232d14c9 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 4 Feb 2010 14:44:21 -0800 Subject: [PATCH] More restrictions on stack allocated C++ objects. --- Cython/Compiler/Symtab.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 162acb9f..d9f5995c 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -431,6 +431,10 @@ class Scope(object): cname = name else: cname = self.mangle(Naming.var_prefix, name) + if type.is_cpp_class and visibility != 'extern': + constructor = type.scope.lookup(u'') + if constructor is not None and PyrexTypes.best_match([], constructor.all_alternatives()) is None: + error(pos, "C++ class must have an empty constructor to be stack allocated") entry = self.declare(name, cname, type, pos, visibility) entry.is_variable = 1 self.control_flow.set_state((), (name, 'initalized'), False) @@ -1359,6 +1363,8 @@ class CClassScope(ClassScope): cname = name if visibility == 'private': cname = c_safe_identifier(cname) + if type.is_cpp_class and visibility != 'extern': + error(pos, "C++ classes not allowed as members of an extension type, use a pointer or reference instead") entry = self.declare(name, cname, type, pos, visibility) entry.is_variable = 1 self.var_entries.append(entry) -- 2.26.2