| 1 |
from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC |
| 2 |
|
| 3 |
|
| 4 |
class TestBuffers(BaseTestPyPyC): |
| 5 |
def test_re_match(self): |
| 6 |
def main(n): |
| 7 |
import re |
| 8 |
import array |
| 9 |
p = re.compile(b'.+') |
| 10 |
a = array.array('B', b'test' * 1000) |
| 11 |
i = 0 |
| 12 |
while i < n: |
| 13 |
i += 1 |
| 14 |
p.match(a) |
| 15 |
return i |
| 16 |
log = self.run(main, [1000]) |
| 17 |
assert log.result == 1000 |
| 18 |
loop, = log.loops_by_filename(self.filepath) |
| 19 |
assert loop.match_by_id('match', """ |
| 20 |
guard_not_invalidated(descr=...) |
| 21 |
p71 = getfield_gc_r(p15, descr=...) # check that the pattern is not None and a W_BytesObject |
| 22 |
guard_nonnull_class(p71, ConstClass(W_BytesObject), descr=...) |
| 23 |
i74 = instance_ptr_eq(_, p71) |
| 24 |
guard_false(i74, descr=...) |
| 25 |
i65 = getfield_gc_i(p18, descr=...) |
| 26 |
i67 = int_gt(0, i65) |
| 27 |
guard_false(i67, descr=...) |
| 28 |
i69 = int_gt(#, i65) |
| 29 |
guard_true(i69, descr=...) |
| 30 |
--TICK-- |
| 31 |
""") |
| 32 |
|
| 33 |
def test_struct_unpack(self): |
| 34 |
def main(n): |
| 35 |
import _struct as struct |
| 36 |
import array |
| 37 |
a = array.array('B', struct.pack('i', 42)) |
| 38 |
i = 0 |
| 39 |
while i < n: |
| 40 |
i += 1 |
| 41 |
struct.unpack('i', a) |
| 42 |
return i |
| 43 |
log = self.run(main, [1000]) |
| 44 |
assert log.result == 1000 |
| 45 |
loop, = log.loops_by_filename(self.filepath) |
| 46 |
assert loop.match_by_id('unpack', """ |
| 47 |
guard_not_invalidated(descr=...) |
| 48 |
i66 = raw_load_i(i53, 0, descr=<ArrayS 4>) |
| 49 |
--TICK-- |
| 50 |
""") |