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 77 78 79 80 81 82 83 84 85 86
|
import py
from rpython.rlib.jit import JitDriver, dont_look_inside
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib import rgc
from rpython.jit.metainterp.test.support import LLJitMixin
class DelTests:
def test_del_keep_obj(self):
myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
class Foo:
def __del__(self):
pass
def f(n):
x = None
while n > 0:
myjitdriver.can_enter_jit(x=x, n=n)
myjitdriver.jit_merge_point(x=x, n=n)
x = Foo()
Foo()
n -= 1
return 42
self.meta_interp(f, [20])
self.check_resops({'call_r': 4, # calls to a helper function
'guard_no_exception': 4, # follows the calls
'int_sub': 2,
'int_gt': 2,
'guard_true': 2,
'jump': 1})
def test_class_of_allocated(self):
myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
class Foo:
def __del__(self):
pass
def f(self):
return self.meth()
class X(Foo):
def meth(self):
return 456
class Y(Foo):
def meth(self):
return 123
def f(n):
x = None
while n > 0:
myjitdriver.can_enter_jit(x=x, n=n)
myjitdriver.jit_merge_point(x=x, n=n)
x = X()
y = Y()
assert x.f() == 456
assert y.f() == 123
n -= 1
return 42
res = self.meta_interp(f, [20])
assert res == 42
def test_instantiate_with_or_without_del(self):
import gc
mydriver = JitDriver(reds = ['n', 'x'], greens = [])
class Base: pass
class A(Base): foo = 72
class B(Base):
foo = 8
def __del__(self):
pass
def f(n):
x = 0
while n > 0:
mydriver.can_enter_jit(n=n, x=x)
mydriver.jit_merge_point(n=n, x=x)
if n % 2 == 0:
cls = A
else:
cls = B
inst = cls()
x += inst.foo
n -= 1
return 1
res = self.meta_interp(f, [20], enable_opts='')
assert res == 1
self.check_resops(call_r=1) # for the case B(), but not for the case A()
class TestLLtype(DelTests, LLJitMixin):
pass
|