Author: Armin Rigo <[email protected]>
Branch: cpyext-avoid-roundtrip
Changeset: r92706:b2d92fe45d11
Date: 2017-10-10 16:06 +0200
http://bitbucket.org/pypy/pypy/changeset/b2d92fe45d11/

Log:    (antocuni, arigo)

        Test and fix

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
@@ -49,9 +49,8 @@
     converted to a sequence, and raises a TypeError, raise a new TypeError with
     m as the message text. If the conversion otherwise, fails, reraise the
     original exception"""
-    # CCC test and enable these two lines:
-    #if isinstance(w_obj, tupleobject.W_TupleObject):
-    #    return w_obj
+    if isinstance(w_obj, tupleobject.W_TupleObject):
+        return w_obj   # CCC avoid the double conversion that occurs here
     if isinstance(w_obj, W_ListObject):
         # make sure we can return a borrowed obj from PySequence_Fast_GET_ITEM
         w_obj.convert_to_cpy_strategy(space)
@@ -63,6 +62,7 @@
             raise OperationError(space.w_TypeError, 
space.newtext(rffi.charp2str(m)))
         raise e
 
+# CCC this should be written as a C macro
 @cpython_api([rffi.VOIDP, 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
diff --git a/pypy/module/cpyext/test/test_sequence.py 
b/pypy/module/cpyext/test/test_sequence.py
--- a/pypy/module/cpyext/test/test_sequence.py
+++ b/pypy/module/cpyext/test/test_sequence.py
@@ -14,6 +14,9 @@
         assert not api.PySequence_Check(space.newdict())
 
     def test_sequence_api(self, space, api):
+        w_tup = space.wrap((1, 2, 3, 4))
+        assert api.PySequence_Fast(w_tup, "message") is w_tup
+
         w_l = space.wrap([1, 2, 3, 4])
         assert api.PySequence_Fast(w_l, "message") is w_l
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to