[pypy-commit] pypy cpyext-nowrapper: (antocuni, ronan): make Py_IncRef no_gc=True, rewrite incref not to take the space

antocuni pypy.commits at gmail.com
Sun Oct 8 18:12:55 EDT 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-nowrapper
Changeset: r92658:aae2bc78be74
Date: 2017-10-07 18:35 +0200
http://bitbucket.org/pypy/pypy/changeset/aae2bc78be74/

Log:	(antocuni, ronan): make Py_IncRef no_gc=True, rewrite incref not to
	take the space

diff --git a/pypy/module/cpyext/buffer.py b/pypy/module/cpyext/buffer.py
--- a/pypy/module/cpyext/buffer.py
+++ b/pypy/module/cpyext/buffer.py
@@ -188,7 +188,7 @@
     view.c_len = length
     view.c_obj = obj
     if obj:
-        incref(space, obj)
+        incref(obj)
     view.c_itemsize = 1
     rffi.setintfield(view, 'c_readonly', readonly)
     rffi.setintfield(view, 'c_ndim', 1)
diff --git a/pypy/module/cpyext/bytesobject.py b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -6,7 +6,7 @@
 from pypy.module.cpyext.pyerrors import PyErr_BadArgument
 from pypy.module.cpyext.pyobject import (
     PyObject, PyObjectP, decref, make_ref, from_ref, track_reference,
-    make_typedescr, get_typedescr, as_pyobj, Py_IncRef, get_w_obj_and_decref,
+    make_typedescr, get_typedescr, as_pyobj, get_w_obj_and_decref,
     pyobj_has_w_obj)
 from pypy.objspace.std.bytesobject import W_BytesObject
 
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -9,7 +9,7 @@
     bootstrap_function, slot_function)
 from pypy.module.cpyext.pyobject import (PyObject, PyObjectP, as_pyobj,
         make_typedescr, track_reference, create_ref, from_ref, decref,
-        Py_IncRef)
+        incref)
 from pypy.module.cpyext.object import _dealloc
 from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
 
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -324,7 +324,7 @@
 @cpython_api([PyObject], PyObject, result_is_ll=True)
 def PyObject_SelfIter(space, ref):
     """Undocumented function, this is what CPython does."""
-    Py_IncRef(space, ref)
+    incref(ref)
     return ref
 
 @cpython_api([PyObject, PyObject], PyObject)
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -25,7 +25,7 @@
     # Don't increase refcount for non-heaptypes
     flags = rffi.cast(lltype.Signed, pytype.c_tp_flags)
     if flags & Py_TPFLAGS_HEAPTYPE:
-        Py_IncRef(space, pytype)
+        incref(pytype)
 
     size = pytype.c_tp_basicsize
     if pytype.c_tp_itemsize:
@@ -309,9 +309,12 @@
         keepalive_until_here(w_obj)
     return w_obj
 
+def incref(obj):
+    assert is_pyobj(obj)
+    pyobj = rffi.cast(PyObject, obj)
+    pyobj.c_ob_refcnt += 1
 
- at specialize.ll()
-def incref(space, obj):
+def incref_w_obj(space, obj):
     make_ref(space, obj)
 
 def decref(obj):
@@ -331,12 +334,15 @@
 def decref_w_obj(space, obj):
     get_w_obj_and_decref(space, obj)
 
- at cpython_api([PyObject], lltype.Void)
-def Py_IncRef(space, obj):
-    incref(space, obj)
 
-# you should not call this function from RPython directly; call decref(), it's
-# slightly faster because it doesn't go through the unwrapper
+# you should not call Py_IncRef and Py_DecRef from RPython directly; call
+# incref() and decref: they are slightly faster because they don't go through
+# the unwrapper
+
+ at cpython_api([PyObject], lltype.Void, no_gc=True)
+def Py_IncRef(obj):
+    incref(obj)
+
 @cpython_api([PyObject], lltype.Void, no_gc=True)
 def Py_DecRef(obj):
     decref(obj)
diff --git a/pypy/module/cpyext/tupleobject.py b/pypy/module/cpyext/tupleobject.py
--- a/pypy/module/cpyext/tupleobject.py
+++ b/pypy/module/cpyext/tupleobject.py
@@ -197,7 +197,7 @@
             to_cp = newsize
         for i in range(to_cp):
             ob = oldref.c_ob_item[i]
-            incref(space, ob)
+            incref(ob)
             newref.c_ob_item[i] = ob
     except:
         decref(p_ref[0])


More information about the pypy-commit mailing list