File: test_gilanalysis.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (76 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download | duplicates (9)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import py

from rpython.annotator.listdef import s_list_of_strings
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.translator.backendopt import gilanalysis
from rpython.memory.gctransform.test.test_transform import rtype
from rpython.translator.translator import graphof

def test_canrelease_external():
    for rel in ['auto', True, False]:
        for sbxs in [True, False]:
            fext = rffi.llexternal('fext2', [], lltype.Void, 
                                   releasegil=rel, sandboxsafe=sbxs)
            def g():
                fext()
            t = rtype(g, [])
            gg = graphof(t, g)

            releases = (rel == 'auto' and not sbxs) or rel is True
            assert releases == gilanalysis.GilAnalyzer(t).analyze_direct_call(gg)

def test_canrelease_instantiate():
    class O:
        pass
    class A(O):
        pass
    class B(O):
        pass

    classes = [A, B]
    def g(i):
        classes[i]()

    t = rtype(g, [int])
    gg = graphof(t, g)
    assert not gilanalysis.GilAnalyzer(t).analyze_direct_call(gg)



def test_no_release_gil():
    from rpython.rlib import rgc

    @rgc.no_release_gil
    def g():
        return 1

    assert g._dont_inline_
    assert g._no_release_gil_

    def entrypoint(argv):
        return g() + 2
    
    t = rtype(entrypoint, [s_list_of_strings])
    gilanalysis.analyze(t.graphs, t)



def test_no_release_gil_detect(gc="minimark"):
    from rpython.rlib import rgc

    fext1 = rffi.llexternal('fext1', [], lltype.Void, releasegil=True)
    @rgc.no_release_gil
    def g():
        fext1()
        return 1

    assert g._dont_inline_
    assert g._no_release_gil_

    def entrypoint(argv):
        return g() + 2
    
    t = rtype(entrypoint, [s_list_of_strings])
    f = py.test.raises(Exception, gilanalysis.analyze, t.graphs, t)
    expected = "'no_release_gil' function can release the GIL: <function g at "
    assert str(f.value).startswith(expected)