Author: Armin Rigo <[email protected]>
Branch:
Changeset: r67554:20c63568140f
Date: 2013-10-24 10:22 +0200
http://bitbucket.org/pypy/pypy/changeset/20c63568140f/
Log: test and fix
diff --git a/pypy/module/_cffi_backend/ctypeprim.py
b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -291,7 +291,8 @@
def unpack_list_of_int_items(self, w_cdata):
if self.value_fits_long:
res = [0] * w_cdata.get_array_length()
- misc.unpack_list_from_raw_array(res, w_cdata._cdata, self.size)
+ misc.unpack_unsigned_list_from_raw_array(res, w_cdata._cdata,
+ self.size)
return res
return None
diff --git a/pypy/module/_cffi_backend/misc.py
b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -346,6 +346,15 @@
return
raise NotImplementedError("bad integer size")
+def unpack_unsigned_list_from_raw_array(int_list, source, size):
+ for TP, TPP in _prim_unsigned_types:
+ if size == rffi.sizeof(TP):
+ ptr = rffi.cast(TPP, source)
+ for i in range(len(int_list)):
+ int_list[i] = rffi.cast(lltype.Signed, ptr[i])
+ return
+ raise NotImplementedError("bad integer size")
+
def unpack_cfloat_list_from_raw_array(float_list, source):
ptr = rffi.cast(rffi.FLOATP, source)
for i in range(len(float_list)):
diff --git a/pypy/module/_cffi_backend/test/test_fastpath.py
b/pypy/module/_cffi_backend/test/test_fastpath.py
--- a/pypy/module/_cffi_backend/test/test_fastpath.py
+++ b/pypy/module/_cffi_backend/test/test_fastpath.py
@@ -153,6 +153,14 @@
misc.unpack_cfloat_list_from_raw_array = (
unpack_cfloat_list_from_raw_array)
#
+ original4 = misc.unpack_unsigned_list_from_raw_array
+ def unpack_unsigned_list_from_raw_array(*args):
+ self.count += 1
+ return original4(*args)
+ self._original4 = original4
+ misc.unpack_unsigned_list_from_raw_array = (
+ unpack_unsigned_list_from_raw_array)
+ #
self.w_runappdirect = self.space.wrap(self.runappdirect)
@@ -161,6 +169,7 @@
rarray.populate_list_from_raw_array = self._original
misc.unpack_list_from_raw_array = self._original2
misc.unpack_cfloat_list_from_raw_array = self._original3
+ misc.unpack_unsigned_list_from_raw_array = self._original4
def test_list_int(self):
import _cffi_backend
@@ -230,9 +239,9 @@
buf = _cffi_backend.newp(USHORT_ARRAY)
buf[0] = 1
buf[1] = 2
- buf[2] = 3
+ buf[2] = 50505
lst = list(buf)
- assert lst == [1, 2, 3]
+ assert lst == [1, 2, 50505]
if not self.runappdirect:
assert self.get_count() == 1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit