summaryrefslogtreecommitdiff
path: root/tests/run/cfuncptr.pyx
blob: b7018cce09ee2a508b785c2861db2ee56e4f405f (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
48
49
50
51
52
53
54
55
56
57
58
59
60
# mode: run


cdef int grail():
    cdef int (*spam)()
    spam = &grail
    spam = grail
    assert spam is grail
    assert spam == grail
    assert spam == &grail


ctypedef int funcptr_t()

cdef funcptr_t* get_grail():
    return &grail


def test_assignments():
    """
    >>> test_assignments()
    """
    grail()


def test_return_value():
    """
    >>> test_return_value()
    True
    """
    g = get_grail()
    return g == &grail


def call_cfuncptr():
    """
    >>> call_cfuncptr()
    """
    cdef int (*spam)()
    spam = grail
    spam()

cdef int exceptminus2(int bad) except -2:
    if bad:
        raise RuntimeError
    else:
        return 0

def call_exceptminus2(bad):
    """
    >>> call_exceptminus2(True)
    Traceback (most recent call last):
    ...
    RuntimeError
    >>> call_exceptminus2(False)
    0
    """
    cdef int (*fptr)(int) except *  # GH4770 - should not be treated as except? -1
    fptr = exceptminus2
    return fptr(bad)