File: test_buffers.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (50 lines) | stat: -rw-r--r-- 1,734 bytes parent folder | download | duplicates (4)
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
from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC


class TestBuffers(BaseTestPyPyC):
    def test_re_match(self):
        def main(n):
            import re
            import array
            p = re.compile(b'.+')
            a = array.array('B', b'test' * 1000)
            i = 0
            while i < n:
                i += 1
                p.match(a)  # ID: match
            return i
        log = self.run(main, [1000])
        assert log.result == 1000
        loop, = log.loops_by_filename(self.filepath)
        assert loop.match_by_id('match', """
            guard_not_invalidated(descr=...)
            p71 = getfield_gc_r(p15, descr=...) # check that the pattern is not None and a W_BytesObject
            guard_nonnull_class(p71, ConstClass(W_BytesObject), descr=...)
            i74 = instance_ptr_eq(_, p71)
            guard_false(i74, descr=...)
            i65 = getfield_gc_i(p18, descr=...)
            i67 = int_gt(0, i65)
            guard_false(i67, descr=...)
            i69 = int_gt(#, i65)
            guard_true(i69, descr=...)
            --TICK--
        """)

    def test_struct_unpack(self):
        def main(n):
            import _struct as struct
            import array
            a = array.array('B', struct.pack('i', 42))
            i = 0
            while i < n:
                i += 1
                struct.unpack('i', a)  # ID: unpack
            return i
        log = self.run(main, [1000])
        assert log.result == 1000
        loop, = log.loops_by_filename(self.filepath)
        assert loop.match_by_id('unpack', """
            guard_not_invalidated(descr=...)
            i66 = raw_load_i(i53, 0, descr=<ArrayS 4>)
            --TICK--
        """)