Author: Armin Rigo <ar...@tunes.org>
Branch: release-5.x
Changeset: r83410:b5d52a043b5e
Date: 2016-03-28 00:35 +0200
http://bitbucket.org/pypy/pypy/changeset/b5d52a043b5e/

Log:    hg revert to 78860f97739e. All commits that come after that are
        backed out (all grafts). A pypy at 78860f97739e translates on
        ppc64be and the result itself is able to run a further translation;
        this is not the case after the grafts.

        To investivate on default.

diff --git a/pypy/module/_rawffi/callback.py b/pypy/module/_rawffi/callback.py
--- a/pypy/module/_rawffi/callback.py
+++ b/pypy/module/_rawffi/callback.py
@@ -1,23 +1,17 @@
-import sys
+
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from rpython.rtyper.lltypesystem import lltype, rffi
 from pypy.module._rawffi.interp_rawffi import write_ptr
 from pypy.module._rawffi.structure import W_Structure
 from pypy.module._rawffi.interp_rawffi import (W_DataInstance, letter2tp,
-     unwrap_value, unpack_argshapes, got_libffi_error, is_narrow_integer_type,
-     LL_TYPEMAP, NARROW_INTEGER_TYPES)
+     unwrap_value, unpack_argshapes, got_libffi_error)
 from rpython.rlib.clibffi import USERDATA_P, CallbackFuncPtr, FUNCFLAG_CDECL
 from rpython.rlib.clibffi import ffi_type_void, LibFFIError
 from rpython.rlib import rweakref
 from pypy.module._rawffi.tracker import tracker
 from pypy.interpreter.error import OperationError
 from pypy.interpreter import gateway
-from rpython.rlib.unroll import unrolling_iterable
-
-BIGENDIAN = sys.byteorder == 'big'
-
-unroll_narrow_integer_types = unrolling_iterable(NARROW_INTEGER_TYPES)
 
 app = gateway.applevel('''
     def tbprint(tb, err):
@@ -48,17 +42,8 @@
                 args_w[i] = space.wrap(rffi.cast(rffi.ULONG, ll_args[i]))
         w_res = space.call(w_callable, space.newtuple(args_w))
         if callback_ptr.result is not None: # don't return void
-            ptr = ll_res
-            letter = callback_ptr.result
-            if BIGENDIAN:
-                # take care of narrow integers!
-                for int_type in unroll_narrow_integer_types:
-                    if int_type == letter:
-                        T = LL_TYPEMAP[int_type]
-                        n = rffi.sizeof(lltype.Signed) - rffi.sizeof(T)
-                        ptr = rffi.ptradd(ptr, n)
-                        break
-            unwrap_value(space, write_ptr, ptr, 0, letter, w_res)
+            unwrap_value(space, write_ptr, ll_res, 0,
+                         callback_ptr.result, w_res)
     except OperationError, e:
         tbprint(space, space.wrap(e.get_traceback()),
                 space.wrap(e.errorstr(space)))
diff --git a/pypy/module/_rawffi/interp_rawffi.py 
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -1,4 +1,3 @@
-import sys
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
 from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -20,8 +19,6 @@
 from pypy.module._rawffi.buffer import RawFFIBuffer
 from pypy.module._rawffi.tracker import tracker
 
-BIGENDIAN = sys.byteorder == 'big'
-
 TYPEMAP = {
     # XXX A mess with unsigned/signed/normal chars :-/
     'c' : ffi_type_uchar,
@@ -334,14 +331,10 @@
             if tracker.DO_TRACING:
                 ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
                 tracker.trace_allocation(ll_buf, self)
-        self._ll_buffer = self.ll_buffer
 
     def getbuffer(self, space):
         return space.wrap(rffi.cast(lltype.Unsigned, self.ll_buffer))
 
-    def buffer_advance(self, n):
-        self.ll_buffer = rffi.ptradd(self.ll_buffer, n)
-
     def byptr(self, space):
         from pypy.module._rawffi.array import ARRAY_OF_PTRS
         array = ARRAY_OF_PTRS.allocate(space, 1)
@@ -349,17 +342,16 @@
         return space.wrap(array)
 
     def free(self, space):
-        if not self._ll_buffer:
+        if not self.ll_buffer:
             raise segfault_exception(space, "freeing NULL pointer")
         self._free()
 
     def _free(self):
         if tracker.DO_TRACING:
-            ll_buf = rffi.cast(lltype.Signed, self._ll_buffer)
+            ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
             tracker.trace_free(ll_buf)
-        lltype.free(self._ll_buffer, flavor='raw')
+        lltype.free(self.ll_buffer, flavor='raw')
         self.ll_buffer = lltype.nullptr(rffi.VOIDP.TO)
-        self._ll_buffer = self.ll_buffer
 
     def buffer_w(self, space, flags):
         return RawFFIBuffer(self)
@@ -440,19 +432,12 @@
                          space.wrap("cannot directly read value"))
 wrap_value._annspecialcase_ = 'specialize:arg(1)'
 
-NARROW_INTEGER_TYPES = 'cbhiBIH?'
-
-def is_narrow_integer_type(letter):
-    return letter in NARROW_INTEGER_TYPES
 
 class W_FuncPtr(W_Root):
     def __init__(self, space, ptr, argshapes, resshape):
         self.ptr = ptr
         self.argshapes = argshapes
         self.resshape = resshape
-        self.narrow_integer = False
-        if resshape is not None:
-            self.narrow_integer = 
is_narrow_integer_type(resshape.itemcode.lower())
 
     def getbuffer(self, space):
         return space.wrap(rffi.cast(lltype.Unsigned, self.ptr.funcsym))
@@ -512,10 +497,6 @@
                 result = self.resshape.allocate(space, 1, autofree=True)
                 # adjust_return_size() was used here on result.ll_buffer
                 self.ptr.call(args_ll, result.ll_buffer)
-                if BIGENDIAN and self.narrow_integer:
-                    # we get a 8 byte value in big endian
-                    n = rffi.sizeof(lltype.Signed) - result.shape.size
-                    result.buffer_advance(n)
                 return space.wrap(result)
             else:
                 self.ptr.call(args_ll, lltype.nullptr(rffi.VOIDP.TO))
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
@@ -1791,7 +1791,6 @@
 
     def test_scalar_view(self):
         from numpy import array
-        import sys
         a = array(3, dtype='int32')
         b = a.view(dtype='float32')
         assert b.shape == ()
@@ -1800,27 +1799,17 @@
         assert exc.value[0] == "new type not compatible with array."
         exc = raises(TypeError, a.view, 'string')
         assert exc.value[0] == "data-type must not be 0-sized"
-        if sys.byteorder == 'big':
-            assert a.view('S4') == '\x00\x00\x00\x03'
-        else:
-            assert a.view('S4') == '\x03'
+        assert a.view('S4') == '\x03'
         a = array('abc1', dtype='c')
         assert (a == ['a', 'b', 'c', '1']).all()
         assert a.view('S4') == 'abc1'
         b = a.view([('a', 'i2'), ('b', 'i2')])
         assert b.shape == (1,)
-        if sys.byteorder == 'big':
-            assert b[0][0] == 0x6162
-            assert b[0][1] == 0x6331
-        else:
-            assert b[0][0] == 25185
-            assert b[0][1] == 12643
+        assert b[0][0] == 25185
+        assert b[0][1] == 12643
         a = array([(1, 2)], dtype=[('a', 'int64'), ('b', 'int64')])[0]
         assert a.shape == ()
-        if sys.byteorder == 'big':
-            assert a.view('S16') == '\x00' * 7 + '\x01' + '\x00' * 7 + '\x02'
-        else:
-            assert a.view('S16') == '\x01' + '\x00' * 7 + '\x02'
+        assert a.view('S16') == '\x01' + '\x00' * 7 + '\x02'
         a = array(2, dtype='<i8')
         b = a.view('<c8')
         assert 0 < b.real < 1
@@ -1829,19 +1818,15 @@
 
     def test_array_view(self):
         from numpy import array, dtype
-        import sys
         x = array((1, 2), dtype='int8')
         assert x.shape == (2,)
         y = x.view(dtype='int16')
         assert x.shape == (2,)
-        if sys.byteorder == 'big':
-            assert y[0] == 0x0102
-        else:
-            assert y[0] == 513 == 0x0201
+        assert y[0] == 513
         assert y.dtype == dtype('int16')
         y[0] = 670
-        assert x[0] == 2
-        assert x[1] == -98
+        assert x[0] == -98
+        assert x[1] == 2
         f = array([1000, -1234], dtype='i4')
         nnp = self.non_native_prefix
         d = f.view(dtype=nnp + 'i4')
@@ -1862,10 +1847,7 @@
         assert x.view('S4')[0] == 'abc'
         assert x.view('S4')[1] == 'defg'
         a = array([(1, 2)], dtype=[('a', 'int64'), ('b', 'int64')])
-        if sys.byteorder == 'big':
-            assert a.view('S16')[0] == '\x00' * 7 + '\x01' + '\x00' * 7 + 
'\x02'
-        else:
-            assert a.view('S16')[0] == '\x01' + '\x00' * 7 + '\x02'
+        assert a.view('S16')[0] == '\x01' + '\x00' * 7 + '\x02'
 
     def test_half_conversions(self):
         from numpy import array, arange
@@ -2443,16 +2425,11 @@
         from numpy import array
         import sys
         a = array([1, 2, 3, 4], dtype='i4')
-        assert a.data[0] == ('\x01' if sys.byteorder == 'little' else '\x00')
+        assert a.data[0] == '\x01'
         assert a.data[1] == '\x00'
-        assert a.data[3] == ('\x00' if sys.byteorder == 'little' else '\x01')
-        assert a.data[4] == ('\x02' if sys.byteorder == 'little' else '\x00')
-        a.data[4] = '\x7f'
-        if sys.byteorder == 'big':
-            a.data[7] = '\x00' # make sure 0x02 is reset to 0
-            assert a[1] == (0x7f000000)
-        else:
-            assert a[1] == 0x7f
+        assert a.data[4] == '\x02'
+        a.data[4] = '\xff'
+        assert a[1] == 0xff
         assert len(a.data) == 16
         assert type(a.data) is buffer
         if '__pypy__' in sys.builtin_module_names:
@@ -2524,17 +2501,12 @@
     def test__reduce__(self):
         from numpy import array, dtype
         from cPickle import loads, dumps
-        import sys
 
         a = array([1, 2], dtype="int64")
         data = a.__reduce__()
 
-        if sys.byteorder == 'big':
-            assert data[2][4] == '\x00\x00\x00\x00\x00\x00\x00\x01' \
-                                 '\x00\x00\x00\x00\x00\x00\x00\x02'
-        else:
-            assert data[2][4] == '\x01\x00\x00\x00\x00\x00\x00\x00' \
-                                 '\x02\x00\x00\x00\x00\x00\x00\x00'
+        assert data[2][4] == '\x01\x00\x00\x00\x00\x00\x00\x00' \
+                             '\x02\x00\x00\x00\x00\x00\x00\x00'
 
         pickled_data = dumps(a)
         assert (loads(pickled_data) == a).all()
@@ -2667,16 +2639,12 @@
     def test_ndarray_from_buffer(self):
         import numpy as np
         import array
-        import sys
         buf = array.array('c', ['\x00']*2*3)
         a = np.ndarray((3,), buffer=buf, dtype='i2')
         a[0] = ord('b')
         a[1] = ord('a')
         a[2] = ord('r')
-        if sys.byteorder == 'big':
-            assert list(buf) == ['\x00', 'b', '\x00', 'a', '\x00', 'r']
-        else:
-            assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00']
+        assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00']
         assert a.base is buf
 
     def test_ndarray_subclass_from_buffer(self):
@@ -2691,17 +2659,13 @@
     def test_ndarray_from_buffer_and_offset(self):
         import numpy as np
         import array
-        import sys
         buf = array.array('c', ['\x00']*7)
         buf[0] = 'X'
         a = np.ndarray((3,), buffer=buf, offset=1, dtype='i2')
         a[0] = ord('b')
         a[1] = ord('a')
         a[2] = ord('r')
-        if sys.byteorder == 'big':
-            assert list(buf) == ['X', '\x00', 'b', '\x00', 'a', '\x00', 'r']
-        else:
-            assert list(buf) == ['X', 'b', '\x00', 'a', '\x00', 'r', '\x00']
+        assert list(buf) == ['X', 'b', '\x00', 'a', '\x00', 'r', '\x00']
 
     def test_ndarray_from_buffer_out_of_bounds(self):
         import numpy as np
@@ -3537,11 +3501,7 @@
         BaseNumpyAppTest.setup_class.im_func(cls)
         cls.w_data = cls.space.wrap(struct.pack('dddd', 1, 2, 3, 4))
         cls.w_fdata = cls.space.wrap(struct.pack('f', 2.3))
-        import sys
-        if sys.byteorder == 'big':
-            cls.w_float16val = cls.space.wrap('E\x00') # 5.0 in float16
-        else:
-            cls.w_float16val = cls.space.wrap('\x00E') # 5.0 in float16
+        cls.w_float16val = cls.space.wrap('\x00E') # 5.0 in float16
         cls.w_float32val = cls.space.wrap(struct.pack('f', 5.2))
         cls.w_float64val = cls.space.wrap(struct.pack('d', 300.4))
         cls.w_ulongval = cls.space.wrap(struct.pack('L', 12))
@@ -3649,15 +3609,9 @@
         assert (t == []).all()
         u = fromstring("\x01\x00\x00\x00\x00\x00\x00\x00", dtype=int)
         if sys.maxint > 2 ** 31 - 1:
-            if sys.byteorder == 'big':
-                assert (u == [0x0100000000000000]).all()
-            else:
-                assert (u == [1]).all()
+            assert (u == [1]).all()
         else:
-            if sys.byteorder == 'big':
-                assert (u == [0x01000000, 0]).all()
-            else:
-                assert (u == [1, 0]).all()
+            assert (u == [1, 0]).all()
         v = fromstring("abcd", dtype="|S2")
         assert v[0] == "ab"
         assert v[1] == "cd"
@@ -3714,15 +3668,9 @@
         k = fromstring(self.float16val, dtype='float16')
         assert k[0] == dtype('float16').type(5.)
         dt =  array([5], dtype='longfloat').dtype
-        print(dt.itemsize)
         if dt.itemsize == 8:
-            import sys
-            if sys.byteorder == 'big':
-                m = fromstring('@\x14\x00\x00\x00\x00\x00\x00',
-                               dtype='float64')
-            else:
-                m = fromstring('\x00\x00\x00\x00\x00\x00\x14@',
-                               dtype='float64')
+            m = fromstring('\x00\x00\x00\x00\x00\x00\x14@',
+                           dtype='float64')
         elif dt.itemsize == 12:
             m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00',
                            dtype='float96')
@@ -3744,13 +3692,8 @@
 
     def test_tostring(self):
         from numpy import array
-        import sys
-        if sys.byteorder == 'big':
-            assert array([1, 2, 3], 'i2').tostring() == 
'\x00\x01\x00\x02\x00\x03'
-            assert array([1, 2, 3], 'i2')[::2].tostring() == '\x00\x01\x00\x03'
-        else:
-            assert array([1, 2, 3], 'i2').tostring() == 
'\x01\x00\x02\x00\x03\x00'
-            assert array([1, 2, 3], 'i2')[::2].tostring() == '\x01\x00\x03\x00'
+        assert array([1, 2, 3], 'i2').tostring() == '\x01\x00\x02\x00\x03\x00'
+        assert array([1, 2, 3], 'i2')[::2].tostring() == '\x01\x00\x03\x00'
         assert array([1, 2, 3], '<i2')[::2].tostring() == '\x01\x00\x03\x00'
         assert array([1, 2, 3], '>i2')[::2].tostring() == '\x00\x01\x00\x03'
         assert array(0, dtype='i2').tostring() == '\x00\x00'
@@ -4246,11 +4189,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:
-            assert v[0][-1] == 2.53125
+        assert v[0][-1] == 2.53125
         exc = raises(ValueError, "a.view(('float32', 2))")
         assert exc.value[0] == 'new type not compatible with array.'
 
diff --git a/pypy/module/micronumpy/test/test_scalar.py 
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -109,7 +109,6 @@
 
     def test_pickle(self):
         from numpy import dtype, zeros
-        import sys
         try:
             from numpy.core.multiarray import scalar
         except ImportError:
@@ -120,11 +119,9 @@
         f = dtype('float64').type(13.37)
         c = dtype('complex128').type(13 + 37.j)
 
-        swap = lambda s: (''.join(reversed(s))) if sys.byteorder == 'big' else 
s
-        assert i.__reduce__() == (scalar, (dtype('int32'), 
swap('9\x05\x00\x00')))
-        assert f.__reduce__() == (scalar, (dtype('float64'), 
swap('=\n\xd7\xa3p\xbd*@')))
-        assert c.__reduce__() == (scalar, (dtype('complex128'), 
swap('\x00\x00\x00\x00\x00\x00*@') + \
-                                                                
swap('\x00\x00\x00\x00\x00\x80B@')))
+        assert i.__reduce__() == (scalar, (dtype('int32'), '9\x05\x00\x00'))
+        assert f.__reduce__() == (scalar, (dtype('float64'), 
'=\n\xd7\xa3p\xbd*@'))
+        assert c.__reduce__() == (scalar, (dtype('complex128'), 
'\x00\x00\x00\x00\x00\x00*@\x00\x00\x00\x00\x00\x80B@'))
 
         assert loads(dumps(i)) == i
         assert loads(dumps(f)) == f
@@ -259,20 +256,13 @@
         assert t < 7e-323
         t = s.view('complex64')
         assert type(t) is np.complex64
-        if sys.byteorder == 'big':
-            assert 0 < t.imag < 1
-            assert t.real == 0
-        else:
-            assert 0 < t.real < 1
-            assert t.imag == 0
+        assert 0 < t.real < 1
+        assert t.imag == 0
         exc = raises(TypeError, s.view, 'string')
         assert exc.value[0] == "data-type must not be 0-sized"
         t = s.view('S8')
         assert type(t) is np.string_
-        if sys.byteorder == 'big':
-            assert t == '\x00' * 7 + '\x0c'
-        else:
-            assert t == '\x0c'
+        assert t == '\x0c'
         s = np.dtype('string').type('abc1')
         assert s.view('S4') == 'abc1'
         if '__pypy__' in sys.builtin_module_names:
diff --git a/pypy/module/micronumpy/test/test_selection.py 
b/pypy/module/micronumpy/test/test_selection.py
--- a/pypy/module/micronumpy/test/test_selection.py
+++ b/pypy/module/micronumpy/test/test_selection.py
@@ -327,15 +327,10 @@
 # tests from numpy/core/tests/test_regression.py
     def test_sort_bigendian(self):
         from numpy import array, dtype
-        import sys
-
-        # little endian sorting for big endian machine
-        # is not yet supported! IMPL ME
-        if sys.byteorder == 'little':
-            a = array(range(11), dtype='float64')
-            c = a.astype(dtype('<f8'))
-            c.sort()
-            assert max(abs(a-c)) < 1e-32
+        a = array(range(11), dtype='float64')
+        c = a.astype(dtype('<f8'))
+        c.sort()
+        assert max(abs(a-c)) < 1e-32
 
     def test_string_argsort_with_zeros(self):
         import numpy as np
diff --git a/pypy/module/micronumpy/test/test_subtype.py 
b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -478,7 +478,6 @@
                 (version, shp, typ, isf, raw) = state
                 ndarray.__setstate__(self, (shp, typ, isf, raw))
 
-        E = '<' if sys.byteorder == 'little' else '>'
         D.__module__ = 'mod'
         mod = new.module('mod')
         mod.D = D
@@ -511,7 +510,7 @@
             tp9
             Rp10
             (I3
-            S'{E}'
+            S'<'
             p11
             NNNI-1
             I-1
@@ -521,7 +520,7 @@
             S'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@'
             p13
             tp14
-            b.'''.replace('            ','').format(E=E)
+            b.'''.replace('            ','')
         for ss,sn in zip(s.split('\n')[1:],s_from_numpy.split('\n')[1:]):
             if len(ss)>10:
                 # ignore binary data, it will be checked later
diff --git a/rpython/rlib/clibffi.py b/rpython/rlib/clibffi.py
--- a/rpython/rlib/clibffi.py
+++ b/rpython/rlib/clibffi.py
@@ -594,12 +594,9 @@
                                             intmask(argtypes[i].c_size),
                                             flavor='raw')
         if restype != ffi_type_void:
-            self.restype_size = intmask(restype.c_size)
-            size = adjust_return_size(self.restype_size)
+            size = adjust_return_size(intmask(restype.c_size))
             self.ll_result = lltype.malloc(rffi.VOIDP.TO, size,
                                            flavor='raw')
-        else:
-            self.restype_size = -1
 
     def push_arg(self, value):
         #if self.pushed_args == self.argnum:
@@ -636,12 +633,7 @@
                             rffi.cast(VOIDPP, self.ll_args))
         if RES_TP is not lltype.Void:
             TP = lltype.Ptr(rffi.CArray(RES_TP))
-            ptr = self.ll_result
-            if _BIG_ENDIAN and RES_TP in TYPE_MAP_INT:
-                # 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]
+            res = rffi.cast(TP, self.ll_result)[0]
         else:
             res = None
         self._clean_args()
diff --git a/rpython/rlib/libffi.py b/rpython/rlib/libffi.py
--- a/rpython/rlib/libffi.py
+++ b/rpython/rlib/libffi.py
@@ -4,7 +4,6 @@
 from __future__ import with_statement
 
 from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib.unroll import unrolling_iterable
 from rpython.rlib.objectmodel import specialize, enforceargs
 from rpython.rlib.rarithmetic import intmask, r_uint, r_singlefloat, r_longlong
 from rpython.rlib import jit
@@ -16,9 +15,6 @@
 from rpython.rlib.rdynload import DLLHANDLE
 
 import os
-import sys
-
-_BIG_ENDIAN = sys.byteorder == 'big'
 
 class types(object):
     """
@@ -215,8 +211,6 @@
 
 # ======================================================================
 
-NARROW_INTEGER_TYPES = unrolling_iterable([rffi.CHAR,
-    rffi.UCHAR, rffi.SHORT, rffi.USHORT, rffi.INT, rffi.UINT])
 
 class Func(AbstractFuncPtr):
 
@@ -269,12 +263,7 @@
             res = self._do_call_raw(self.funcsym, ll_args)
         elif _fits_into_signed(RESULT):
             assert not types.is_struct(self.restype)
-            for res in NARROW_INTEGER_TYPES:
-                if RESULT is res:
-                    res = self._do_call_int(self.funcsym, ll_args, rffi.CHAR)
-                    break
-            else:
-                res = self._do_call_int(self.funcsym, ll_args, rffi.SIGNED)
+            res = self._do_call_int(self.funcsym, ll_args)
         elif RESULT is rffi.DOUBLE:
             return self._do_call_float(self.funcsym, ll_args)
         elif RESULT is rffi.FLOAT:
@@ -336,9 +325,8 @@
 
     #@jit.oopspec('libffi_call_int(self, funcsym, ll_args)')
     @jit.dont_look_inside
-    @specialize.arg(3)
-    def _do_call_int(self, funcsym, ll_args, TP):
-        return self._do_call(funcsym, ll_args, TP)
+    def _do_call_int(self, funcsym, ll_args):
+        return self._do_call(funcsym, ll_args, rffi.SIGNED)
 
     #@jit.oopspec('libffi_call_float(self, funcsym, ll_args)')
     @jit.dont_look_inside
@@ -380,10 +368,10 @@
     @specialize.arg(3)
     def _do_call(self, funcsym, ll_args, RESULT):
         # XXX: check len(args)?
-        ll_result = lltype.nullptr(rffi.VOIDP.TO)
+        ll_result = lltype.nullptr(rffi.CCHARP.TO)
         if self.restype != types.void:
             size = adjust_return_size(intmask(self.restype.c_size))
-            ll_result = lltype.malloc(rffi.VOIDP.TO, size,
+            ll_result = lltype.malloc(rffi.CCHARP.TO, size,
                                       flavor='raw')
         ffires = c_ffi_call(self.ll_cif,
                             self.funcsym,
@@ -391,20 +379,14 @@
                             rffi.cast(rffi.VOIDPP, ll_args))
         if RESULT is not lltype.Void:
             TP = lltype.Ptr(rffi.CArray(RESULT))
+            buf = rffi.cast(TP, ll_result)
             if types.is_struct(self.restype):
                 assert RESULT == rffi.SIGNED
                 # for structs, we directly return the buffer and transfer the
                 # ownership
-                buf = rffi.cast(TP, ll_result)
                 res = rffi.cast(RESULT, buf)
             else:
-                if _BIG_ENDIAN and types.getkind(self.restype) in ('i','u'):
-                    ptr = ll_result
-                    n = rffi.sizeof(lltype.Signed) - self.restype.c_size
-                    ptr = rffi.ptradd(ptr, n)
-                    res = rffi.cast(TP, ptr)[0]
-                else:
-                    res = rffi.cast(TP, ll_result)[0]
+                res = buf[0]
         else:
             res = None
         self._free_buffers(ll_result, ll_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,13 +6,11 @@
 
 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]
-        result = 3 if sys.byteorder == 'little' else 3 << (LONG_BIT-8)
-        assert fn() == result
-        assert self.interpret(fn, []) == result
+        assert fn() == 3
+        assert self.interpret(fn, []) == 3
 
     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,12 +181,11 @@
             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.SIGNEDP, ll_res)
-            # must store a full ffi arg!
+            res = rffi.cast(rffi.INTP, ll_res)
             if a1 > a2:
-                res[0] = 1
+                res[0] = rffi.cast(rffi.INT, 1)
             else:
-                res[0] = -1
+                res[0] = rffi.cast(rffi.INT, -1)
 
         ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer],
                               ffi_type_sint, callback)
diff --git a/rpython/rlib/test/test_libffi.py b/rpython/rlib/test/test_libffi.py
--- a/rpython/rlib/test/test_libffi.py
+++ b/rpython/rlib/test/test_libffi.py
@@ -274,7 +274,7 @@
         """
         libfoo = self.get_libfoo()
         func = (libfoo, 'diff_xy', [types.sint, types.signed], types.sint)
-        res = self.call(func, [50, 8], rffi.INT)
+        res = self.call(func, [50, 8], lltype.Signed)
         assert res == 42
 
     def test_simple(self):
@@ -287,7 +287,7 @@
         """
         libfoo = self.get_libfoo()
         func = (libfoo, 'sum_xy', [types.sint, types.double], types.sint)
-        res = self.call(func, [38, 4.2], rffi.INT, jitif=["floats"])
+        res = self.call(func, [38, 4.2], lltype.Signed, jitif=["floats"])
         assert res == 42
 
     def test_float_result(self):
@@ -319,7 +319,7 @@
         """
         libfoo = self.get_libfoo()
         func = (libfoo, 'many_args', [types.uchar, types.sint], types.sint)
-        res = self.call(func, [chr(20), 22], rffi.INT)
+        res = self.call(func, [chr(20), 22], rffi.SIGNED)
         assert res == 42
 
     def test_char_args(self):
@@ -418,12 +418,12 @@
         set_dummy = (libfoo, 'set_dummy', [types.sint], types.void)
         get_dummy = (libfoo, 'get_dummy', [], types.sint)
         #
-        initval = self.call(get_dummy, [], rffi.INT)
+        initval = self.call(get_dummy, [], rffi.SIGNED)
         #
         res = self.call(set_dummy, [initval+1], lltype.Void)
         assert res is None
         #
-        res = self.call(get_dummy, [], rffi.INT)
+        res = self.call(get_dummy, [], rffi.SIGNED)
         assert res == initval+1
 
     def test_single_float_args(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to