[pypy-svn] pypy jitypes2: .c_type is an USHORT, and you cannot compare them. Fix translation.

antocuni commits-noreply at bitbucket.org
Thu Dec 23 19:10:16 CET 2010


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40218:1a553addc9f8
Date: 2010-12-23 18:49 +0100
http://bitbucket.org/pypy/pypy/changeset/1a553addc9f8/

Log:	.c_type is an USHORT, and you cannot compare them. Fix translation.

diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -65,9 +65,13 @@
         elif ffi_type is types.sint64:  return 'I'
         elif ffi_type is types.uint64:  return 'U'
         #
-        elif ffi_type.c_type == FFI_TYPE_STRUCT: return 'S'
+        elif types.is_struct(ffi_type): return 'S'
         raise KeyError
 
+    @staticmethod
+    def is_struct(ffi_type):
+        return intmask(ffi_type.c_type) == intmask(FFI_TYPE_STRUCT)
+
 types._import()
 
 @specialize.arg(0)
@@ -407,7 +411,7 @@
         if RESULT is not lltype.Void:
             TP = lltype.Ptr(rffi.CArray(RESULT))
             buf = rffi.cast(TP, ll_result)
-            if self.restype.c_type == FFI_TYPE_STRUCT:
+            if types.is_struct(self.restype):
                 # for structs, we directly return the buffer and transfer the
                 # ownership
                 res = rffi.cast(RESULT, buf)
@@ -431,7 +435,7 @@
         # if it's a struct, the buffer is not freed and the ownership is
         # already of the caller (in case of ll_args buffers) or transferred to
         # it (in case of ll_result buffer)
-        if ffitype.c_type != FFI_TYPE_STRUCT:
+        if not types.is_struct(ffitype):
             lltype.free(buf, flavor='raw')
 
 

diff --git a/pypy/module/_ffi/interp_ffi.py b/pypy/module/_ffi/interp_ffi.py
--- a/pypy/module/_ffi/interp_ffi.py
+++ b/pypy/module/_ffi/interp_ffi.py
@@ -37,7 +37,7 @@
     from pypy.rlib.clibffi import FFI_TYPE_P
     tdict = {}
     for key, value in libffi.types.__dict__.iteritems():
-        if key == 'getkind' or key.startswith('__'):
+        if key == 'getkind' or key == 'is_struct' or key.startswith('__'):
             continue
         assert lltype.typeOf(value) == FFI_TYPE_P
         tdict[key] = W_FFIType(key, value)


More information about the Pypy-commit mailing list