[pypy-commit] pypy faster-rstruct-2: WIP: add a failing test, which is triggered when W_BytearrayObject._offset > 0
antocuni
pypy.commits at gmail.com
Wed May 17 11:47:56 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct-2
Changeset: r91321:b207c44e74ae
Date: 2017-05-17 17:21 +0200
http://bitbucket.org/pypy/pypy/changeset/b207c44e74ae/
Log: WIP: add a failing test, which is triggered when
W_BytearrayObject._offset > 0
diff --git a/pypy/module/struct/test/test_struct.py b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -541,3 +541,12 @@
buf = bytearray(len(expected))
self.struct.pack_into("xxi", buf, 0, 42)
assert buf == expected
+
+ def test_pack_into_bytearray_delete(self):
+ expected = self.struct.pack("i", 42)
+ # force W_BytearrayObject._delete_from_start
+ buf = bytearray(64)
+ del buf[:8]
+ self.struct.pack_into("i", buf, 0, 42)
+ buf = buf[:len(expected)]
+ assert buf == expected
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -1111,7 +1111,7 @@
list.__delitem__(self, index)
def __getslice__(self, i, j):
- return list.__getslice__(self.__as_list(), i, j)
+ return self.__class__(list.__getslice__(self.__as_list(), i, j))
def __setslice__(self, i, j, new):
lst = self.__as_list()
diff --git a/rpython/rlib/test/test_rgc.py b/rpython/rlib/test/test_rgc.py
--- a/rpython/rlib/test/test_rgc.py
+++ b/rpython/rlib/test/test_rgc.py
@@ -304,6 +304,30 @@
data = subprocess.check_output([str(exename), '.', '.', '.'])
assert data.strip().endswith('OK!')
+
+def test_nonmoving_raw_ptr_for_resizable_list_getslice():
+ def f(n):
+ lst = ['a', 'b', 'c', 'd', 'e']
+ lst = rgc.resizable_list_supporting_raw_ptr(lst)
+ lst = lst[:3]
+ lst.append(chr(n))
+ assert lst[3] == chr(n)
+ assert lst[-1] == chr(n)
+ #
+ ptr = rgc.nonmoving_raw_ptr_for_resizable_list(lst)
+ assert lst[:] == ['a', 'b', 'c', chr(n)]
+ assert lltype.typeOf(ptr) == rffi.CCHARP
+ assert [ptr[i] for i in range(4)] == ['a', 'b', 'c', chr(n)]
+ return lst
+ #
+ # direct untranslated run
+ lst = f(35)
+ assert isinstance(lst, rgc._ResizableListSupportingRawPtr)
+ #
+ # llinterp run
+ interpret(f, [35])
+
+
def test_ll_for_resizable_list():
def f(n):
lst = ['a', 'b', 'c']
More information about the pypy-commit
mailing list