Author: Richard Plangger <[email protected]>
Branch: release-5.x
Changeset: r83399:c8ccc2e362ae
Date: 2016-01-22 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/c8ccc2e362ae/
Log: fixed callsite of clibffi with the same big endian issues as found
yesterday evening (grafted from
6840459f9b22b6e1071bf3e1aa37cb0cca978e68)
diff --git a/pypy/module/micronumpy/test/test_ndarray.py
b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -4246,6 +4246,7 @@
v = a.view(('float32', 4))
assert v.dtype == np.dtype('float32')
assert v.shape == (10, 4)
+ import sys
if sys.byteorder == 'big':
assert v[0][-2] == 2.53125
else:
diff --git a/rpython/rlib/clibffi.py b/rpython/rlib/clibffi.py
--- a/rpython/rlib/clibffi.py
+++ b/rpython/rlib/clibffi.py
@@ -597,6 +597,9 @@
size = adjust_return_size(intmask(restype.c_size))
self.ll_result = lltype.malloc(rffi.VOIDP.TO, size,
flavor='raw')
+ self.restype_size = intmask(restype.c_size)
+ else:
+ self.restype_size = -1
def push_arg(self, value):
#if self.pushed_args == self.argnum:
@@ -633,7 +636,12 @@
rffi.cast(VOIDPP, self.ll_args))
if RES_TP is not lltype.Void:
TP = lltype.Ptr(rffi.CArray(RES_TP))
- res = rffi.cast(TP, self.ll_result)[0]
+ ptr = self.ll_result
+ if _BIG_ENDIAN and self.restype_size != -1:
+ # we get a 8 byte value in big endian
+ n = rffi.sizeof(lltype.Signed) - self.restype_size
+ ptr = rffi.ptradd(ptr, n)
+ res = rffi.cast(TP, ptr)[0]
else:
res = None
self._clean_args()
diff --git a/rpython/rlib/rstruct/test/test_runpack.py
b/rpython/rlib/rstruct/test/test_runpack.py
--- a/rpython/rlib/rstruct/test/test_runpack.py
+++ b/rpython/rlib/rstruct/test/test_runpack.py
@@ -6,11 +6,13 @@
class TestRStruct(BaseRtypingTest):
def test_unpack(self):
+ import sys
pad = '\x00' * (LONG_BIT//8-1) # 3 or 7 null bytes
def fn():
return runpack('sll', 'a'+pad+'\x03'+pad+'\x04'+pad)[1]
- assert fn() == 3
- assert self.interpret(fn, []) == 3
+ result = 3 if sys.byteorder == 'little' else 3 << (LONG_BIT-8)
+ assert fn() == result
+ assert self.interpret(fn, []) == result
def test_unpack_2(self):
data = struct.pack('iiii', 0, 1, 2, 4)
diff --git a/rpython/rlib/test/test_clibffi.py
b/rpython/rlib/test/test_clibffi.py
--- a/rpython/rlib/test/test_clibffi.py
+++ b/rpython/rlib/test/test_clibffi.py
@@ -181,11 +181,12 @@
p_a2 = rffi.cast(rffi.VOIDPP, ll_args[1])[0]
a1 = rffi.cast(rffi.INTP, p_a1)[0]
a2 = rffi.cast(rffi.INTP, p_a2)[0]
- res = rffi.cast(rffi.INTP, ll_res)
+ res = rffi.cast(rffi.SIGNEDP, ll_res)
+ # must store a full ffi arg!
if a1 > a2:
- res[0] = rffi.cast(rffi.INT, 1)
+ res[0] = 1
else:
- res[0] = rffi.cast(rffi.INT, -1)
+ res[0] = -1
ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer],
ffi_type_sint, callback)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit