[pypy-commit] pypy default: Hit a case where this incorrect ll2ctypes type is really wrong. Trying
arigo
pypy.commits at gmail.com
Sun Jun 26 16:21:02 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r85385:a635618d95ba
Date: 2016-06-26 14:39 +0200
http://bitbucket.org/pypy/pypy/changeset/a635618d95ba/
Log: Hit a case where this incorrect ll2ctypes type is really wrong.
Trying to improve...
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -166,7 +166,19 @@
})
if '__int128_t' in rffi.TYPES:
- _ctypes_cache[rffi.__INT128_T] = ctypes.c_longlong # XXX: Not right at all. But for some reason, It started by while doing JIT compile after a merge with default. Can't extend ctypes, because thats a python standard, right?
+ class c_int128(ctypes.Array): # based on 2 ulongs
+ _type_ = ctypes.c_uint64
+ _length_ = 2
+ @property
+ def value(self):
+ if sys.byteorder == 'little':
+ res = self[0] | (self[1] << 64)
+ else:
+ res = self[1] | (self[0] << 64)
+ if res >= (1 << 127):
+ res -= 1 << 128
+ return res
+ _ctypes_cache[rffi.__INT128_T] = c_int128
# for unicode strings, do not use ctypes.c_wchar because ctypes
# automatically converts arrays into unicode strings.
diff --git a/rpython/rtyper/lltypesystem/test/test_rffi.py b/rpython/rtyper/lltypesystem/test/test_rffi.py
--- a/rpython/rtyper/lltypesystem/test/test_rffi.py
+++ b/rpython/rtyper/lltypesystem/test/test_rffi.py
@@ -825,3 +825,13 @@
assert charp2str(p2) == "helLD"
free_charp(p1)
free_charp(p2)
+
+def test_sign_when_casting_uint_to_larger_int():
+ from rpython.rtyper.lltypesystem import rffi
+ from rpython.rlib.rarithmetic import r_uint32, r_uint64
+ #
+ value = 0xAAAABBBB
+ assert cast(lltype.SignedLongLong, r_uint32(value)) == value
+ if hasattr(rffi, '__INT128_T'):
+ value = 0xAAAABBBBCCCCDDDD
+ assert cast(rffi.__INT128_T, r_uint64(value)) == value
More information about the pypy-commit
mailing list