Commit 2a3bfd58 authored by Josh Tobin's avatar Josh Tobin Committed by Stefan Behnel

Mangle cname for closures in derived c class (GH-2990)

parent f76d28ca
...@@ -2738,9 +2738,12 @@ class CreateClosureClasses(CythonTransform): ...@@ -2738,9 +2738,12 @@ class CreateClosureClasses(CythonTransform):
node.needs_outer_scope = True node.needs_outer_scope = True
return return
# entry.cname can contain periods (eg. a derived C method of a class).
# We want to use the cname as part of a C struct name, so we replace
# periods with double underscores.
as_name = '%s_%s' % ( as_name = '%s_%s' % (
target_module_scope.next_id(Naming.closure_class_prefix), target_module_scope.next_id(Naming.closure_class_prefix),
node.entry.cname) node.entry.cname.replace('.','__'))
entry = target_module_scope.declare_c_class( entry = target_module_scope.declare_c_class(
name=as_name, pos=node.pos, defining=True, name=as_name, pos=node.pos, defining=True,
......
# mode: run
# tag: closures
# ticket: 2967
cdef class BaseClass:
cdef func(self):
pass
cdef class ClosureInsideExtensionClass(BaseClass):
"""
>>> y = ClosureInsideExtensionClass(42)
>>> y.test(42)
43
"""
cdef func(self):
a = 1
return (lambda x : x+a)
def test(self, b):
return self.func()(b)
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