Esempio n. 1
0
 def main(argv):
     rawrefcount.create_link_pypy(w1, ob1)
     w = None
     ob = lltype.nullptr(PyObjectS)
     oblist = []
     for op in argv[1:]:
         revdb.stop_point()
         w = W_Root(42)
         ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
         ob.c_ob_refcnt = rawrefcount.REFCNT_FROM_PYPY
         rawrefcount.create_link_pypy(w, ob)
         oblist.append(ob)
     del oblist[-1]
     #
     rgc.collect()
     assert rawrefcount.from_obj(PyObject, w) == ob
     assert rawrefcount.to_obj(W_Root, ob) == w
     while True:
         ob = rawrefcount.next_dead(PyObject)
         if not ob:
             break
         assert ob in oblist
         oblist.remove(ob)
     objectmodel.keepalive_until_here(w)
     revdb.stop_point()
     return 9
Esempio n. 2
0
 def entry_point(argv):
     rawrefcount.create_link_pypy(prebuilt_p, prebuilt_ob)
     prebuilt_ob.c_ob_refcnt += REFCNT_FROM_PYPY
     oblist = [make_ob() for i in range(50)]
     rgc.collect()
     deadlist = []
     while True:
         ob = rawrefcount.next_dead(PyObject)
         if not ob: break
         if ob.c_ob_refcnt != 1:
             print "next_dead().ob_refcnt != 1"
             return 1
         deadlist.append(ob)
     if len(deadlist) == 0:
         print "no dead object"
         return 1
     if len(deadlist) < 30:
         print "not enough dead objects"
         return 1
     for ob in deadlist:
         if ob not in oblist:
             print "unexpected value for dead pointer"
             return 1
         oblist.remove(ob)
     print "OK!"
     lltype.free(ob, flavor='raw')
     return 0
Esempio n. 3
0
 def make_p():
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount.from_obj(PyObject, p) == ob
     assert rawrefcount.to_obj(W_Root, ob) == p
     return ob, p
Esempio n. 4
0
 def make_p():
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount.from_obj(PyObject, p) == ob
     assert rawrefcount.to_obj(W_Root, ob) == p
     return ob, p
Esempio n. 5
0
 def test_create_link_pypy(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_pypy(p, ob)
     assert ob.c_ob_refcnt == 0
     ob.c_ob_refcnt += REFCNT_FROM_PYPY_LIGHT
     assert rawrefcount.from_obj(PyObject, p) == ob
     assert rawrefcount.to_obj(W_Root, ob) == p
     lltype.free(ob, flavor='raw')
Esempio n. 6
0
 def test_create_link_pypy(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_pypy(p, ob)
     assert ob.c_ob_refcnt == 0
     ob.c_ob_refcnt += REFCNT_FROM_PYPY_LIGHT
     assert rawrefcount.from_obj(PyObject, p) == ob
     assert rawrefcount.to_obj(W_Root, ob) == p
     lltype.free(ob, flavor='raw')
Esempio n. 7
0
def track_reference(space, py_obj, w_obj):
    """
    Ties together a PyObject and an interpreter object.
    The PyObject's refcnt is increased by REFCNT_FROM_PYPY.
    The reference in 'py_obj' is not stolen!  Remember to Py_DecRef()
    it is you need to.
    """
    # XXX looks like a PyObject_GC_TRACK
    assert py_obj.c_ob_refcnt < rawrefcount.REFCNT_FROM_PYPY
    py_obj.c_ob_refcnt += rawrefcount.REFCNT_FROM_PYPY
    rawrefcount.create_link_pypy(w_obj, py_obj)
Esempio n. 8
0
def track_reference(space, py_obj, w_obj):
    """
    Ties together a PyObject and an interpreter object.
    The PyObject's refcnt is increased by REFCNT_FROM_PYPY.
    The reference in 'py_obj' is not stolen!  Remember to Py_DecRef()
    it is you need to.
    """
    # XXX looks like a PyObject_GC_TRACK
    assert py_obj.c_ob_refcnt < rawrefcount.REFCNT_FROM_PYPY
    py_obj.c_ob_refcnt += rawrefcount.REFCNT_FROM_PYPY
    rawrefcount.create_link_pypy(w_obj, py_obj)
Esempio n. 9
0
 def test_collect_p_dies(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY_LIGHT
     assert rawrefcount._p_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     del ob, p
     rawrefcount._collect()
     assert rawrefcount._p_list == []
     assert wr_ob() is None
     assert wr_p() is None
Esempio n. 10
0
 def test_collect_p_dies(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY_LIGHT
     assert rawrefcount._p_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     del ob, p
     rawrefcount._collect()
     assert rawrefcount._p_list == []
     assert wr_ob() is None
     assert wr_p() is None
Esempio n. 11
0
 def test_collect_p_keepalive_w_root(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY_LIGHT
     assert rawrefcount._p_list == [ob]
     wr_ob = weakref.ref(ob)
     del ob  # p remains
     rawrefcount._collect()
     ob = wr_ob()
     assert ob is not None
     assert rawrefcount._p_list == [ob]
     assert rawrefcount.to_obj(W_Root, ob) == p
     assert rawrefcount.from_obj(PyObject, p) == ob
     lltype.free(ob, flavor='raw')
Esempio n. 12
0
 def test_collect_p_keepalive_w_root(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY_LIGHT
     assert rawrefcount._p_list == [ob]
     wr_ob = weakref.ref(ob)
     del ob       # p remains
     rawrefcount._collect()
     ob = wr_ob()
     assert ob is not None
     assert rawrefcount._p_list == [ob]
     assert rawrefcount.to_obj(W_Root, ob) == p
     assert rawrefcount.from_obj(PyObject, p) == ob
     lltype.free(ob, flavor='raw')
Esempio n. 13
0
 def test_collect_s_keepalive_pyobject(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     p.pyobj = ob
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._p_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     ob.c_ob_refcnt += 1      # <=
     del ob, p
     rawrefcount._collect()
     ob = wr_ob()
     p = wr_p()
     assert ob is not None and p is not None
     assert rawrefcount._p_list == [ob]
     assert rawrefcount.to_obj(W_Root, ob) == p
     lltype.free(ob, flavor='raw')
Esempio n. 14
0
 def test_collect_s_keepalive_pyobject(self):
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     p.pyobj = ob
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._p_list == [ob]
     wr_ob = weakref.ref(ob)
     wr_p = weakref.ref(p)
     ob.c_ob_refcnt += 1  # <=
     del ob, p
     rawrefcount._collect()
     ob = wr_ob()
     p = wr_p()
     assert ob is not None and p is not None
     assert rawrefcount._p_list == [ob]
     assert rawrefcount.to_obj(W_Root, ob) == p
     lltype.free(ob, flavor='raw')
Esempio n. 15
0
 def test_collect_s_dies(self):
     trigger = []; rawrefcount.init(lambda: trigger.append(1))
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._p_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._d_list == [ob]
     assert rawrefcount._p_list == []
     assert wr_p() is None
     assert ob.c_ob_refcnt == 1       # from _d_list
     assert ob.c_ob_pypy_link == 0
     lltype.free(ob, flavor='raw')
Esempio n. 16
0
 def test_collect_s_dies(self):
     trigger = []
     rawrefcount.init(lambda: trigger.append(1))
     p = W_Root(42)
     ob = lltype.malloc(PyObjectS, flavor='raw', zero=True)
     rawrefcount.create_link_pypy(p, ob)
     ob.c_ob_refcnt += REFCNT_FROM_PYPY
     assert rawrefcount._p_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._d_list == [ob]
     assert rawrefcount._p_list == []
     assert wr_p() is None
     assert ob.c_ob_refcnt == 1  # from _d_list
     assert ob.c_ob_pypy_link == 0
     lltype.free(ob, flavor='raw')
Esempio n. 17
0
 def _cpyext_attach_pyobj(self, space, py_obj):
     self._cpy_ref = py_obj
     rawrefcount.create_link_pypy(self, py_obj)
Esempio n. 18
0
def w_root_attach_pyobj(w_obj, space, py_obj):
    from rpython.rlib.debug import check_annotation
    check_annotation(space.config.objspace.usemodules.cpyext, check_true)
    assert space.config.objspace.usemodules.cpyext
    # default implementation of _cpyext_attach_pyobj
    rawrefcount.create_link_pypy(w_obj, py_obj)