[pypy-commit] pypy cpyext-gc-support-2: fix for test_sequence

arigo pypy.commits at gmail.com
Sun Feb 14 05:30:06 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: cpyext-gc-support-2
Changeset: r82233:103bd85674e7
Date: 2016-02-14 11:29 +0100
http://bitbucket.org/pypy/pypy/changeset/103bd85674e7/

Log:	fix for test_sequence

diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -2,7 +2,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.module.cpyext.api import (
     cpython_api, CANNOT_FAIL, CONST_STRING, Py_ssize_t)
-from pypy.module.cpyext.pyobject import PyObject, borrow_from
+from pypy.module.cpyext.pyobject import PyObject
 from rpython.rtyper.lltypesystem import rffi, lltype
 from pypy.objspace.std import listobject, tupleobject
 
@@ -42,15 +42,19 @@
     which case o is returned.  Use PySequence_Fast_GET_ITEM() to access the
     members of the result.  Returns NULL on failure.  If the object is not a
     sequence, raises TypeError with m as the message text."""
-    if (isinstance(w_obj, listobject.W_ListObject) or
-        isinstance(w_obj, tupleobject.W_TupleObject)):
+    if isinstance(w_obj, listobject.W_ListObject):
+        # make sure we can return a borrowed obj from PySequence_Fast_GET_ITEM
+        # XXX how does this interact with CPyListStrategy?
+        w_obj.switch_to_object_strategy()
+        return w_obj
+    if isinstance(w_obj, tupleobject.W_TupleObject):
         return w_obj
     try:
         return tupleobject.W_TupleObject(space.fixedview(w_obj))
     except OperationError:
         raise OperationError(space.w_TypeError, space.wrap(rffi.charp2str(m)))
 
- at cpython_api([PyObject, Py_ssize_t], PyObject)
+ at cpython_api([PyObject, Py_ssize_t], PyObject, result_borrowed=True)
 def PySequence_Fast_GET_ITEM(space, w_obj, index):
     """Return the ith element of o, assuming that o was returned by
     PySequence_Fast(), o is not NULL, and that i is within bounds.
@@ -60,7 +64,7 @@
     else:
         assert isinstance(w_obj, tupleobject.W_TupleObject)
         w_res = w_obj.wrappeditems[index]
-    return borrow_from(w_obj, w_res)
+    return w_res
 
 @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
 def PySequence_Fast_GET_SIZE(space, w_obj):


More information about the pypy-commit mailing list