def test_slonglong_args(self): """ long long sum_xy_longlong(long long x, long long y) { return x+y; } """ maxint32 = 2147483647 # we cannot really go above maxint on 64 bits # (and we would not test anything, as there long # is the same as long long) libfoo = self.get_libfoo() func = (libfoo, 'sum_xy_longlong', [types.slonglong, types.slonglong], types.slonglong) if IS_32_BIT: x = r_longlong(maxint32+1) y = r_longlong(maxint32+2) zero = longlong2float(r_longlong(0)) else: x = maxint32+1 y = maxint32+2 zero = 0 res = self.call(func, [x, y], rffi.LONGLONG, init_result=zero) if IS_32_BIT: # obscure, on 32bit it's really a long long, so it returns a # DOUBLE because of the JIT hack res = float2longlong(res) expected = maxint32*2 + 3 assert res == expected
def _call_longlong(self, space, argchain, reskind): # this is a hack: we store the 64 bits of the long long into the 64 # bits of a float (i.e., a C double) floatres = self.func.call(argchain, rffi.LONGLONG) llres = libffi.float2longlong(floatres) if reskind == 'I': return space.wrap(llres) elif reskind == 'U': ullres = rffi.cast(rffi.ULONGLONG, llres) return space.wrap(ullres) else: assert False
def test_ulonglong_args(self): """ unsigned long long sum_xy_ulonglong(unsigned long long x, unsigned long long y) { return x+y; } """ maxint64 = 9223372036854775807 # maxint64+1 does not fit into a # longlong, but it does into a # ulonglong libfoo = self.get_libfoo() func = (libfoo, 'sum_xy_ulonglong', [types.ulonglong, types.ulonglong], types.ulonglong) x = r_ulonglong(maxint64+1) y = r_ulonglong(2) res = self.call(func, [x, y], rffi.ULONGLONG, init_result=0) if IS_32_BIT: # obscure, on 32bit it's really a long long, so it returns a # DOUBLE because of the JIT hack res = float2longlong(res) res = rffi.cast(rffi.ULONGLONG, res) expected = maxint64 + 3 assert res == expected
def fn(x): d = longlong2float(x) ll = float2longlong(d) return ll