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
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
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
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')
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)
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
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')
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')
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')
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')
def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj rawrefcount.create_link_pypy(self, py_obj)
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)