File: test_incminimark_gc.py

package info (click to toggle)
pypy 2.4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 86,992 kB
  • ctags: 170,715
  • sloc: python: 1,030,417; ansic: 43,437; cpp: 5,241; asm: 5,169; sh: 458; makefile: 408; xml: 231; lisp: 45
file content (38 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download
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
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem.lloperation import llop

from rpython.memory.test import test_minimark_gc

class TestIncrementalMiniMarkGC(test_minimark_gc.TestMiniMarkGC):
    from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass
    WREF_IS_INVALID_BEFORE_DEL_IS_CALLED = True

    def test_weakref_not_in_stack(self):
        import weakref
        class A(object):
            pass
        class B(object):
            def __init__(self, next):
                self.next = next
        def g():
            a = A()
            a.x = 5
            wr = weakref.ref(a)
            llop.gc__collect(lltype.Void)   # make everything old
            assert wr() is not None
            assert a.x == 5
            return wr
        def f():
            ref = g()
            llop.gc__collect(lltype.Void, 1)    # start a major cycle
            # at this point the stack is scanned, and the weakref points
            # to an object not found, but still reachable:
            b = ref()
            llop.debug_print(lltype.Void, b)
            assert b is not None
            llop.gc__collect(lltype.Void)   # finish the major cycle
            # assert does not crash, because 'b' is still kept alive
            b.x = 42
            return ref() is b
        res = self.interpret(f, [])
        assert res == True