Exemplo n.º 1
0
 def test_create_link_pyobj(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     assert rawrefcount.from_obj(PyObject, p) == lltype.nullptr(PyObjectS)
     assert rawrefcount.to_obj(W_Root, ob) == None
     rawrefcount.create_link_pyobj(p, ob)
     assert ob.c_ob_refcnt == 0
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount.from_obj(PyObject, p) == lltype.nullptr(PyObjectS)
     assert rawrefcount.to_obj(W_Root, ob) == p
     lltype.free(ob, flavor='raw')
Exemplo n.º 2
0
 def test_create_link_pyobj(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     assert rawrefcount.from_obj(PyObject, p) == lltype.nullptr(PyObjectS)
     assert rawrefcount.to_obj(W_Root, ob) == None
     rawrefcount.create_link_pyobj(p, ob)
     assert ob.c_ob_refcnt == 0
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount.from_obj(PyObject, p) == lltype.nullptr(PyObjectS)
     assert rawrefcount.to_obj(W_Root, ob) == p
     lltype.free(ob, flavor='raw')
Exemplo n.º 3
0
 def test_collect_o_keepalive_w_root(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     p.pyobj = ob
     rawrefcount.create_link_pyobj(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._o_list == [ob]
     wr_ob = weakref.ref(ob)
     del ob  # p remains
     rawrefcount._collect()
     ob = wr_ob()
     assert ob is not None
     assert rawrefcount._o_list == [ob]
     assert rawrefcount.to_obj(W_Root, ob) == p
     assert p.pyobj == ob
     lltype.free(ob, flavor='raw')
Exemplo n.º 4
0
 def test_collect_o_keepalive_w_root(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     p.pyobj = ob
     rawrefcount.create_link_pyobj(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._o_list == [ob]
     wr_ob = weakref.ref(ob)
     del ob       # p remains
     rawrefcount._collect()
     ob = wr_ob()
     assert ob is not None
     assert rawrefcount._o_list == [ob]
     assert rawrefcount.to_obj(W_Root, ob) == p
     assert p.pyobj == ob
     lltype.free(ob, flavor='raw')
Exemplo n.º 5
0
 def test_collect_o_keepalive_pyobject(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     p.pyobj = ob
     rawrefcount.create_link_pyobj(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._o_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     ob.c_ob_refcnt += 1  # <=
     del p
     rawrefcount._collect()
     p = wr_p()
     assert p is None  # was unlinked
     assert ob.c_ob_refcnt == 1  # != REFCNT_FROM_PYPY_OBJECT + 1
     assert rawrefcount._o_list == []
     assert rawrefcount.to_obj(W_Root, ob) == None
     lltype.free(ob, flavor='raw')
Exemplo n.º 6
0
 def test_collect_o_keepalive_pyobject(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     p.pyobj = ob
     rawrefcount.create_link_pyobj(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._o_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     ob.c_ob_refcnt += 1      # <=
     del p
     rawrefcount._collect()
     p = wr_p()
     assert p is None            # was unlinked
     assert ob.c_ob_refcnt == 1    # != REFCNT_FROM_PYPY_OBJECT + 1
     assert rawrefcount._o_list == []
     assert rawrefcount.to_obj(W_Root, ob) == None
     lltype.free(ob, flavor='raw')
Exemplo n.º 7
0
 def test_collect_o_dies(self):
     trigger = []; rawrefcount.init(lambda: trigger.append(1))
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pyobj(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._o_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     del ob, p
     rawrefcount._collect()
     ob = wr_ob()
     assert ob is not None
     assert trigger == [1]
     assert rawrefcount.next_dead(PyObject) == ob
     assert rawrefcount.next_dead(PyObject) == lltype.nullptr(PyObjectS)
     assert rawrefcount.next_dead(PyObject) == lltype.nullptr(PyObjectS)
     assert rawrefcount._o_list == []
     assert wr_p() is None
     assert ob.c_ob_refcnt == 1       # from the pending list
     assert ob.c_ob_pypy_link == 0
     lltype.free(ob, flavor='raw')
Exemplo n.º 8
0
 def test_collect_o_dies(self):
     trigger = []
     rawrefcount.init(lambda: trigger.append(1))
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pyobj(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._o_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     del ob, p
     rawrefcount._collect()
     ob = wr_ob()
     assert ob is not None
     assert trigger == [1]
     assert rawrefcount.next_dead(PyObject) == ob
     assert rawrefcount.next_dead(PyObject) == lltype.nullptr(PyObjectS)
     assert rawrefcount.next_dead(PyObject) == lltype.nullptr(PyObjectS)
     assert rawrefcount._o_list == []
     assert wr_p() is None
     assert ob.c_ob_refcnt == 1  # from the pending list
     assert ob.c_ob_pypy_link == 0
     lltype.free(ob, flavor='raw')
Exemplo n.º 9
0
 def _cpyext_attach_pyobj(self, space, py_obj):
     self._cpy_ref = py_obj
     rawrefcount.create_link_pyobj(self, py_obj)