Author: Matti Picus <matti.pi...@gmail.com>
Branch: cpyext-obj-stealing
Changeset: r91134:e9792355d656
Date: 2017-04-26 07:02 +0300
http://bitbucket.org/pypy/pypy/changeset/e9792355d656/

Log:    cleanup, add check

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1557,7 +1557,6 @@
 
 @specialize.memo()
 def make_generic_cpy_call(FT, expect_null):
-    from pypy.module.cpyext.pyobject import make_ref, from_ref
     from pypy.module.cpyext.pyobject import is_pyobj, as_pyobj
     from pypy.module.cpyext.pyobject import get_w_obj_and_decref
     from pypy.module.cpyext.pyerrors import PyErr_Occurred
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
@@ -274,13 +274,14 @@
     """
     if is_pyobj(obj):
         pyobj = rffi.cast(PyObject, obj)
+        assert pyobj.c_ob_refcnt > 0
     else:
         pyobj = as_pyobj(space, obj, w_userdata)
-    if pyobj:
-        assert pyobj.c_ob_refcnt > 0
-        pyobj.c_ob_refcnt += 1
-        if not is_pyobj(obj):
+        if not pyobj:
             keepalive_until_here(obj)
+            return pyobj
+        assert pyobj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY
+    pyobj.c_ob_refcnt += 1
     return pyobj
 
 
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -24,7 +24,7 @@
     W_PyCMethodObject, W_PyCFunctionObject)
 from pypy.module.cpyext.modsupport import convert_method_defs
 from pypy.module.cpyext.pyobject import (
-    PyObject, make_ref, create_ref, from_ref, get_typedescr, make_typedescr,
+    PyObject, make_ref, from_ref, get_typedescr, make_typedescr,
     track_reference, Py_DecRef, as_pyobj)
 from pypy.module.cpyext.slotdefs import (
     slotdefs_for_tp_slots, slotdefs_for_wrappers, get_slot_tp_function,
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to