Author: Carl Friedrich Bolz <[email protected]>
Branch: 
Changeset: r92178:06465478f8df
Date: 2017-08-20 12:37 +0200
http://bitbucket.org/pypy/pypy/changeset/06465478f8df/

Log:    issue #2637 testing: implement CPyListStrategy.getstorage_copy

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
@@ -330,7 +330,11 @@
         return w_list.strategy.getitems_copy(w_list)
 
     def getstorage_copy(self, w_list):
-        raise NotImplementedError
+        storage = self.unerase(w_list.lstorage)
+        lst = [None] * storage._length
+        for i in range(storage._length):
+            lst[i] = from_ref(w_list.space, storage._elems[i])
+        return self.erase(CPyListStorage(w_list.space, lst))
 
     def append(self, w_list, w_item):
         w_list.switch_to_object_strategy()
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
@@ -226,6 +226,15 @@
         w_l.inplace_mul(2)
         assert space.int_w(space.len(w_l)) == 10
 
+    def test_getstorage_copy(self, space, api):
+        w = space.wrap
+        w_l = w([1, 2, 3, 4])
+        api.PySequence_Fast(w_l, "foo") # converts
+
+        w_l1 = w([])
+        space.setitem(w_l1, space.newslice(w(0), w(0), w(1)), w_l)
+        assert map(space.unwrap, space.unpackiterable(w_l1)) == [1, 2, 3, 4]
+
 
 class AppTestSequenceObject(AppTestCpythonExtensionBase):
     def test_fast(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to