[pypy-commit] pypy ffistruct: fix translation by iterating only on the types which are known to be integers
antocuni
noreply at buildbot.pypy.org
Fri Sep 9 16:51:49 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r47187:108d00ff4edd
Date: 2011-09-09 16:49 +0200
http://bitbucket.org/pypy/pypy/changeset/108d00ff4edd/
Log: fix translation by iterating only on the types which are known to be
integers
diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py
--- a/pypy/rlib/clibffi.py
+++ b/pypy/rlib/clibffi.py
@@ -210,10 +210,7 @@
elif sz == 8: return ffi_type_uint64
else: raise ValueError("unsupported type size for %r" % (TYPE,))
-TYPE_MAP = {
- rffi.DOUBLE : ffi_type_double,
- rffi.FLOAT : ffi_type_float,
- rffi.LONGDOUBLE : ffi_type_longdouble,
+TYPE_MAP_INT = {
rffi.UCHAR : ffi_type_uchar,
rffi.CHAR : ffi_type_schar,
rffi.SHORT : ffi_type_sshort,
@@ -226,11 +223,24 @@
rffi.LONG : _signed_type_for(rffi.LONG),
rffi.ULONGLONG : _unsigned_type_for(rffi.ULONGLONG),
rffi.LONGLONG : _signed_type_for(rffi.LONGLONG),
- lltype.Void : ffi_type_void,
lltype.UniChar : _unsigned_type_for(lltype.UniChar),
lltype.Bool : _unsigned_type_for(lltype.Bool),
+}
+
+TYPE_MAP_FLOAT = {
+ rffi.DOUBLE : ffi_type_double,
+ rffi.FLOAT : ffi_type_float,
+ rffi.LONGDOUBLE : ffi_type_longdouble,
}
+TYPE_MAP = {
+ lltype.Void : ffi_type_void,
+ }
+TYPE_MAP.update(TYPE_MAP_INT)
+TYPE_MAP.update(TYPE_MAP_FLOAT)
+
+ffitype_map_int = unrolling_iterable(TYPE_MAP_INT.iteritems())
+ffitype_map_float = unrolling_iterable(TYPE_MAP_FLOAT.iteritems())
ffitype_map = unrolling_iterable(TYPE_MAP.iteritems())
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -419,7 +419,7 @@
Return the field of type ``ffitype`` at ``addr+offset``, widened to
lltype.Signed.
"""
- for TYPE, ffitype2 in clibffi.ffitype_map:
+ for TYPE, ffitype2 in clibffi.ffitype_map_int:
if ffitype is ffitype2:
value = _struct_getfield(TYPE, addr, offset)
return rffi.cast(lltype.Signed, value)
@@ -430,7 +430,7 @@
Set the field of type ``ffitype`` at ``addr+offset``. ``value`` is of
type lltype.Signed, and it's automatically converted to the right type.
"""
- for TYPE, ffitype2 in clibffi.ffitype_map:
+ for TYPE, ffitype2 in clibffi.ffitype_map_int:
if ffitype is ffitype2:
value = rffi.cast(TYPE, value)
_struct_setfield(TYPE, addr, offset, value)
More information about the pypy-commit
mailing list