Commit 695dc278 authored by Stefan Behnel's avatar Stefan Behnel

fix ticket #742: 'self' in closure of extension type method crashes at runtime

parent d2ef994b
...@@ -2457,8 +2457,11 @@ class DefNode(FuncDefNode): ...@@ -2457,8 +2457,11 @@ class DefNode(FuncDefNode):
for arg in self.args: for arg in self.args:
if not arg.type.is_pyobject: if not arg.type.is_pyobject:
done = arg.type.create_from_py_utility_code(env) if not arg.type.create_from_py_utility_code(env):
if not done: pass # will fail later pass # will fail later
elif arg.is_self_arg and arg.entry.in_closure:
# must store 'self' in the closure explicitly for extension types
self.generate_arg_assignment(arg, arg.hdr_cname, code)
if not self.signature_has_generic_args(): if not self.signature_has_generic_args():
if has_star_or_kw_args: if has_star_or_kw_args:
...@@ -2945,7 +2948,7 @@ class DefNode(FuncDefNode): ...@@ -2945,7 +2948,7 @@ class DefNode(FuncDefNode):
for arg in self.args: for arg in self.args:
if arg.needs_conversion: if arg.needs_conversion:
self.generate_arg_conversion(arg, code) self.generate_arg_conversion(arg, code)
elif arg.entry.in_closure: elif not arg.is_self_arg and arg.entry.in_closure:
if arg.type.is_pyobject: if arg.type.is_pyobject:
code.put_incref(arg.hdr_cname, py_object_type) code.put_incref(arg.hdr_cname, py_object_type)
code.putln('%s = %s;' % (arg.entry.cname, arg.hdr_cname)) code.putln('%s = %s;' % (arg.entry.cname, arg.hdr_cname))
......
# mode: run
# ticket: 742
import cython
@cython.cclass
class ExtType(object):
def const1(self):
return 1
def ext_method0(self):
"""
>>> x = ExtType()
>>> x.ext_method0()()
1
"""
def func():
return self.const1()
return func
def ext_method1(self, a):
"""
>>> x = ExtType()
>>> x.ext_method1(2)()
(1, 2)
"""
def func():
return self.const1(), a
return func
def ext_method1_def(self, a=2):
"""
>>> x = ExtType()
>>> x.ext_method1_def()()
(1, 2)
>>> x.ext_method1_def(3)()
(1, 3)
"""
def func():
return self.const1(), a
return func
def ext_method_args(self, *args):
"""
>>> x = ExtType()
>>> x.ext_method_args(2)()
(1, 2)
"""
def func():
return self.const1(), args[0]
return func
def ext_method_args_only(*args):
"""
>>> x = ExtType()
>>> x.ext_method_args_only(2)()
(1, 2)
"""
def func():
return args[0].const1(), args[1]
return func
@cython.cclass
class GenType(object):
def const1(self):
return 1
def gen0(self):
"""
>>> x = GenType()
>>> tuple(x.gen0())
(1, 2)
"""
yield self.const1()
yield 2
def gen1(self, a):
"""
>>> x = GenType()
>>> tuple(x.gen1(2))
(1, 2)
"""
yield self.const1()
yield a
def gen_default(self, a=2):
"""
>>> x = GenType()
>>> tuple(x.gen_default())
(1, 2)
>>> tuple(x.gen_default(3))
(1, 3)
"""
yield self.const1()
yield a
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