Commit 499fd678 authored by mattip's avatar mattip

MAINT: fixes from review

parent ccb67088
...@@ -7147,7 +7147,7 @@ class AttributeNode(ExprNode): ...@@ -7147,7 +7147,7 @@ class AttributeNode(ExprNode):
#print "...obj_code =", obj_code ### #print "...obj_code =", obj_code ###
if self.entry and self.entry.is_cmethod: if self.entry and self.entry.is_cmethod:
if self.entry.is_cgetter: if self.entry.is_cgetter:
return "%s(%s)" %(self.entry.func_cname, obj_code) return "%s(%s)" % (self.entry.func_cname, obj_code)
if obj.type.is_extension_type and not self.entry.is_builtin_cmethod: if obj.type.is_extension_type and not self.entry.is_builtin_cmethod:
if self.entry.final_func_cname: if self.entry.final_func_cname:
return self.entry.final_func_cname return self.entry.final_func_cname
......
...@@ -2351,6 +2351,9 @@ class CFuncDefNode(FuncDefNode): ...@@ -2351,6 +2351,9 @@ class CFuncDefNode(FuncDefNode):
pass pass
else: else:
error(self.pos, "Cannot handle %s decorators yet" % func.name) error(self.pos, "Cannot handle %s decorators yet" % func.name)
else:
error(self.pos,
"Cannot handle %s decorators yet" % type(func).__name__)
self.is_c_class_method = env.is_c_class_scope self.is_c_class_method = env.is_c_class_scope
if self.directive_locals is None: if self.directive_locals is None:
...@@ -2366,20 +2369,20 @@ class CFuncDefNode(FuncDefNode): ...@@ -2366,20 +2369,20 @@ class CFuncDefNode(FuncDefNode):
self.is_static_method = 'staticmethod' in env.directives and not env.lookup_here('staticmethod') self.is_static_method = 'staticmethod' in env.directives and not env.lookup_here('staticmethod')
# The 2 here is because we need both function and argument names. # The 2 here is because we need both function and argument names.
if isinstance(self.declarator, CFuncDeclaratorNode): if isinstance(self.declarator, CFuncDeclaratorNode):
name_declarator, type = self.declarator.analyse( name_declarator, typ = self.declarator.analyse(
base_type, env, nonempty=2 * (self.body is not None), base_type, env, nonempty=2 * (self.body is not None),
directive_locals=self.directive_locals, visibility=self.visibility) directive_locals=self.directive_locals, visibility=self.visibility)
else: else:
name_declarator, type = self.declarator.analyse( name_declarator, typ = self.declarator.analyse(
base_type, env, nonempty=2 * (self.body is not None), visibility=self.visibility) base_type, env, nonempty=2 * (self.body is not None), visibility=self.visibility)
if not type.is_cfunction: if not typ.is_cfunction:
error(self.pos, "Suite attached to non-function declaration") error(self.pos, "Suite attached to non-function declaration")
# Remember the actual type according to the function header # Remember the actual type according to the function header
# written here, because the type in the symbol table entry # written here, because the type in the symbol table entry
# may be different if we're overriding a C method inherited # may be different if we're overriding a C method inherited
# from the base type of an extension type. # from the base type of an extension type.
self.type = type self.type = typ
type.is_overridable = self.overridable typ.is_overridable = self.overridable
declarator = self.declarator declarator = self.declarator
while not hasattr(declarator, 'args'): while not hasattr(declarator, 'args'):
declarator = declarator.base declarator = declarator.base
...@@ -2392,11 +2395,11 @@ class CFuncDefNode(FuncDefNode): ...@@ -2392,11 +2395,11 @@ class CFuncDefNode(FuncDefNode):
error(self.cfunc_declarator.pos, error(self.cfunc_declarator.pos,
"Function with optional arguments may not be declared public or api") "Function with optional arguments may not be declared public or api")
if type.exception_check == '+' and self.visibility != 'extern': if typ.exception_check == '+' and self.visibility != 'extern':
warning(self.cfunc_declarator.pos, warning(self.cfunc_declarator.pos,
"Only extern functions can throw C++ exceptions.") "Only extern functions can throw C++ exceptions.")
for formal_arg, type_arg in zip(self.args, type.args): for formal_arg, type_arg in zip(self.args, typ.args):
self.align_argument_type(env, type_arg) self.align_argument_type(env, type_arg)
formal_arg.type = type_arg.type formal_arg.type = type_arg.type
formal_arg.name = type_arg.name formal_arg.name = type_arg.name
...@@ -2417,16 +2420,16 @@ class CFuncDefNode(FuncDefNode): ...@@ -2417,16 +2420,16 @@ class CFuncDefNode(FuncDefNode):
elif 'inline' in self.modifiers: elif 'inline' in self.modifiers:
warning(formal_arg.pos, "Buffer unpacking not optimized away.", 1) warning(formal_arg.pos, "Buffer unpacking not optimized away.", 1)
self._validate_type_visibility(type.return_type, self.pos, env) self._validate_type_visibility(typ.return_type, self.pos, env)
name = name_declarator.name name = name_declarator.name
cname = name_declarator.cname cname = name_declarator.cname
type.is_const_method = self.is_const_method typ.is_const_method = self.is_const_method
type.is_static_method = self.is_static_method typ.is_static_method = self.is_static_method
self.entry = env.declare_cfunction( self.entry = env.declare_cfunction(
name, type, self.pos, name, typ, self.pos,
cname=cname, visibility=self.visibility, api=self.api, cname=cname, visibility=self.visibility, api=self.api,
defining=self.body is not None, modifiers=self.modifiers, defining=self.body is not None, modifiers=self.modifiers,
overridable=self.overridable) overridable=self.overridable)
...@@ -2435,7 +2438,7 @@ class CFuncDefNode(FuncDefNode): ...@@ -2435,7 +2438,7 @@ class CFuncDefNode(FuncDefNode):
env.property_entries.append(self.entry) env.property_entries.append(self.entry)
env.cfunc_entries.remove(self.entry) env.cfunc_entries.remove(self.entry)
self.entry.inline_func_in_pxd = self.inline_in_pxd self.entry.inline_func_in_pxd = self.inline_in_pxd
self.return_type = type.return_type self.return_type = typ.return_type
if self.return_type.is_array and self.visibility != 'extern': if self.return_type.is_array and self.visibility != 'extern':
error(self.pos, "Function cannot return an array") error(self.pos, "Function cannot return an array")
if self.return_type.is_cpp_class: if self.return_type.is_cpp_class:
......
...@@ -754,8 +754,7 @@ class Scope(object): ...@@ -754,8 +754,7 @@ class Scope(object):
def declare_cfunction(self, name, type, pos, def declare_cfunction(self, name, type, pos,
cname=None, visibility='private', api=0, in_pxd=0, cname=None, visibility='private', api=0, in_pxd=0,
defining=0, modifiers=(), utility_code=None, defining=0, modifiers=(), utility_code=None, overridable=False):
overridable=False):
# Add an entry for a C function. # Add an entry for a C function.
if not cname: if not cname:
if visibility != 'private' or api: if visibility != 'private' or api:
......
...@@ -12,10 +12,11 @@ setup(ext_modules= cythonize("foo_extension.pyx", language_level=3)) ...@@ -12,10 +12,11 @@ setup(ext_modules= cythonize("foo_extension.pyx", language_level=3))
setup(ext_modules = cythonize("getter[0-9].pyx", language_level=3)) setup(ext_modules = cythonize("getter[0-9].pyx", language_level=3))
try: for name in ("getter_fail0.pyx", "getter_fail1.pyx"):
cythonize("getter_fail0.pyx", language_level=3) try:
cythonize(name, language_level=3)
assert False assert False
except CompileError: except CompileError as e:
print("\nGot expected exception, continuing\n") print("\nGot expected exception, continuing\n")
######## foo.h ######## ######## foo.h ########
...@@ -154,6 +155,16 @@ cdef extern from "foo.h": ...@@ -154,6 +155,16 @@ cdef extern from "foo.h":
cdef void field0(): cdef void field0():
print('in staticmethod of Foo') print('in staticmethod of Foo')
######## getter_fail1.pyx ########
# Make sure not all decorators are accepted
cimport cython
cdef extern from "foo.h":
ctypedef class foo_extension.Foo [object FooStructOpaque]:
@prop.getter
cdef void field0(self):
pass
######## runner.py ######## ######## runner.py ########
......
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