summaryrefslogtreecommitdiff
path: root/tests/run/closure_inside_cdef_T554.pyx
blob: 3a112868d989bdf4282701aafd49b34ad968382c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# mode: run
# tag: closures
# ticket: 554

def call_f(x):
    """
    >>> call_f(2)
    4
    """
    return f(x)


cdef f(x):                # def  here => works fine
   def g(y): return y*x   # cdef here => compile error
   return g(x)            # faults@ INCREF(.*cur_scope->.*v_x


def closure_in_void():
    """
    >>> genex = closure_in_void()
    >>> list(genex)
    ['a', 'b', 'c']
    """
    l = []
    add_gen(l)
    return l[0]


cdef void add_gen(l):
    x = "abc"
    l.append((c for c in x))


def closure_in_int():
    """
    >>> genex = closure_in_int()
    >>> list(genex)
    ['a', 'b', 'c']
    """
    l = []
    add_gen_int(l)
    return l[0]


cdef int add_gen_int(l):
    x = "abc"
    l.append((c for c in x))