[pypy-commit] pypy default: libffi has a problem with test_byval_result on windows.

ctismer noreply at buildbot.pypy.org
Sat Mar 17 01:45:45 CET 2012


Author: Christian Tismer <tismer at stackless.com>
Branch: 
Changeset: r53741:688bcf1a07ed
Date: 2012-03-16 17:45 -0700
http://bitbucket.org/pypy/pypy/changeset/688bcf1a07ed/

Log:	libffi has a problem with test_byval_result on windows. On win64,
	this even gives an access violation, also on test_byval_argument.
	Moving to default since it doesn't worsen the currect windows state
	-- please can somebody look into this?

diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -35,6 +35,7 @@
         cls.ulong = clibffi.cast_type_to_ffitype(rffi.ULONG)
         cls.slonglong = clibffi.cast_type_to_ffitype(rffi.LONGLONG)
         cls.ulonglong = clibffi.cast_type_to_ffitype(rffi.ULONGLONG)
+        cls.signed = clibffi.cast_type_to_ffitype(rffi.SIGNED)
         cls.wchar_t = clibffi.cast_type_to_ffitype(lltype.UniChar)
         del cls._import
 
@@ -79,16 +80,20 @@
 
 types._import()
 
+# this was '_fits_into_long', which is not adequate, because long is
+# not necessary the type where we compute with. Actually meant is
+# the type 'Signed'.
+
 @specialize.arg(0)
-def _fits_into_long(TYPE):
+def _fits_into_signed(TYPE):
     if isinstance(TYPE, lltype.Ptr):
-        return True # pointers always fits into longs
+        return True # pointers always fits into Signeds
     if not isinstance(TYPE, lltype.Primitive):
         return False
     if TYPE is lltype.Void or TYPE is rffi.FLOAT or TYPE is rffi.DOUBLE:
         return False
     sz = rffi.sizeof(TYPE)
-    return sz <= rffi.sizeof(rffi.LONG)
+    return sz <= rffi.sizeof(rffi.SIGNED)
 
 
 # ======================================================================
@@ -115,9 +120,9 @@
     def arg(self, val):
         TYPE = lltype.typeOf(val)
         _check_type(TYPE)
-        if _fits_into_long(TYPE):
+        if _fits_into_signed(TYPE):
             cls = IntArg
-            val = rffi.cast(rffi.LONG, val)
+            val = rffi.cast(rffi.SIGNED, val)
         elif TYPE is rffi.DOUBLE:
             cls = FloatArg
         elif TYPE is rffi.LONGLONG or TYPE is rffi.ULONGLONG:
@@ -250,7 +255,7 @@
         if is_struct:
             assert types.is_struct(self.restype)
             res = self._do_call_raw(self.funcsym, ll_args)
-        elif _fits_into_long(RESULT):
+        elif _fits_into_signed(RESULT):
             assert not types.is_struct(self.restype)
             res = self._do_call_int(self.funcsym, ll_args)
         elif RESULT is rffi.DOUBLE:
@@ -309,7 +314,7 @@
 
     @jit.oopspec('libffi_call_int(self, funcsym, ll_args)')
     def _do_call_int(self, funcsym, ll_args):
-        return self._do_call(funcsym, ll_args, rffi.LONG)
+        return self._do_call(funcsym, ll_args, rffi.SIGNED)
 
     @jit.oopspec('libffi_call_float(self, funcsym, ll_args)')
     def _do_call_float(self, funcsym, ll_args):
@@ -322,7 +327,7 @@
     @jit.dont_look_inside
     def _do_call_raw(self, funcsym, ll_args):
         # same as _do_call_int, but marked as jit.dont_look_inside
-        return self._do_call(funcsym, ll_args, rffi.LONG)
+        return self._do_call(funcsym, ll_args, rffi.SIGNED)
 
     @jit.oopspec('libffi_call_longlong(self, funcsym, ll_args)')
     def _do_call_longlong(self, funcsym, ll_args):
@@ -360,7 +365,7 @@
             TP = lltype.Ptr(rffi.CArray(RESULT))
             buf = rffi.cast(TP, ll_result)
             if types.is_struct(self.restype):
-                assert RESULT == rffi.LONG
+                assert RESULT == rffi.SIGNED
                 # for structs, we directly return the buffer and transfer the
                 # ownership
                 res = rffi.cast(RESULT, buf)
diff --git a/pypy/rlib/test/test_libffi.py b/pypy/rlib/test/test_libffi.py
--- a/pypy/rlib/test/test_libffi.py
+++ b/pypy/rlib/test/test_libffi.py
@@ -34,8 +34,8 @@
         # .arg() only supports integers and floats
         chain = ArgChain()
         x = lltype.malloc(lltype.GcStruct('xxx'))
-        y = lltype.malloc(lltype.GcArray(rffi.LONG), 3)
-        z = lltype.malloc(lltype.Array(rffi.LONG), 4, flavor='raw')
+        y = lltype.malloc(lltype.GcArray(rffi.SIGNED), 3)
+        z = lltype.malloc(lltype.Array(rffi.SIGNED), 4, flavor='raw')
         py.test.raises(TypeError, "chain.arg(x)")
         py.test.raises(TypeError, "chain.arg(y)")
         py.test.raises(TypeError, "chain.arg(z)")
@@ -100,6 +100,7 @@
     def setup_class(cls):
         from pypy.tool.udir import udir
         from pypy.translator.tool.cbuild import ExternalCompilationInfo
+        from pypy.translator.tool.cbuild import STANDARD_DEFINES
         from pypy.translator.platform import platform
 
         BaseFfiTest.setup_class()
@@ -120,7 +121,7 @@
                     for match in re.finditer(" ([a-z_]+)\(", meth.__doc__):
                         exports.append(match.group(1))
         #
-        c_file.write(py.code.Source('\n'.join(snippets)))
+        c_file.write(STANDARD_DEFINES + str(py.code.Source('\n'.join(snippets))))
         eci = ExternalCompilationInfo(export_symbols=exports)
         cls.libfoo_name = str(platform.compile([c_file], eci, 'x',
                                                standalone=False))
@@ -157,13 +158,13 @@
 
     def test_very_simple(self):
         """
-            int diff_xy(int x, long y)
+            int diff_xy(int x, Signed y)
             {
                 return x - y;
             }
         """
         libfoo = self.get_libfoo()
-        func = (libfoo, 'diff_xy', [types.sint, types.slong], types.sint)
+        func = (libfoo, 'diff_xy', [types.sint, types.signed], types.sint)
         res = self.call(func, [50, 8], lltype.Signed)
         assert res == 42
 
@@ -206,7 +207,7 @@
         """
         libfoo = self.get_libfoo()
         func = (libfoo, 'many_args', [types.uchar, types.sint], types.sint)
-        res = self.call(func, [chr(20), 22], rffi.LONG)
+        res = self.call(func, [chr(20), 22], rffi.SIGNED)
         assert res == 42
 
     def test_char_args(self):
@@ -235,9 +236,9 @@
 
     def test_pointer_as_argument(self):
         """#include <stdlib.h>
-            long inc(long* x)
+            Signed inc(Signed* x)
             {
-                long oldval;
+                Signed oldval;
                 if (x == NULL)
                     return -1;
                 oldval = *x;
@@ -246,15 +247,14 @@
             }
         """
         libfoo = self.get_libfoo()
-        func = (libfoo, 'inc', [types.pointer], types.slong)
-        LONGP = lltype.Ptr(rffi.CArray(rffi.LONG))
-        null = lltype.nullptr(LONGP.TO)
-        res = self.call(func, [null], rffi.LONG)
+        func = (libfoo, 'inc', [types.pointer], types.signed)
+        null = lltype.nullptr(rffi.SIGNEDP.TO)
+        res = self.call(func, [null], rffi.SIGNED)
         assert res == -1
         #
-        ptr_result = lltype.malloc(LONGP.TO, 1, flavor='raw')
+        ptr_result = lltype.malloc(rffi.SIGNEDP.TO, 1, flavor='raw')
         ptr_result[0] = 41
-        res = self.call(func, [ptr_result], rffi.LONG)
+        res = self.call(func, [ptr_result], rffi.SIGNED)
         if self.__class__ is TestLibffiCall:
             # the function was called only once
             assert res == 41
@@ -274,21 +274,20 @@
     def test_return_pointer(self):
         """
             struct pair {
-                long a;
-                long b;
+                Signed a;
+                Signed b;
             };
 
             struct pair my_static_pair = {10, 20};
 
-            long* get_pointer_to_b()
+            Signed* get_pointer_to_b()
             {
                 return &my_static_pair.b;
             }
         """
         libfoo = self.get_libfoo()
         func = (libfoo, 'get_pointer_to_b', [], types.pointer)
-        LONGP = lltype.Ptr(rffi.CArray(rffi.LONG))
-        res = self.call(func, [], LONGP)
+        res = self.call(func, [], rffi.SIGNEDP)
         assert res[0] == 20
 
     def test_void_result(self):
@@ -301,12 +300,12 @@
         set_dummy = (libfoo, 'set_dummy', [types.sint], types.void)
         get_dummy = (libfoo, 'get_dummy', [], types.sint)
         #
-        initval = self.call(get_dummy, [], rffi.LONG)
+        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.LONG)
+        res = self.call(get_dummy, [], rffi.SIGNED)
         assert res == initval+1
 
     def test_single_float_args(self):
@@ -386,32 +385,32 @@
             else:
                 assert False, 'Did not raise'
 
-        my_raises("self.call(func, [38], rffi.LONG)") # one less
-        my_raises("self.call(func, [38, 12.3, 42], rffi.LONG)") # one more
+        my_raises("self.call(func, [38], rffi.SIGNED)") # one less
+        my_raises("self.call(func, [38, 12.3, 42], rffi.SIGNED)") # one more
 
 
     def test_byval_argument(self):
         """
             struct Point {
-                long x;
-                long y;
+                Signed x;
+                Signed y;
             };
 
-            long sum_point(struct Point p) {
+            Signed sum_point(struct Point p) {
                 return p.x + p.y;
             }
         """
         libfoo = CDLL(self.libfoo_name)
-        ffi_point_struct = make_struct_ffitype_e(0, 0, [types.slong, types.slong])
+        ffi_point_struct = make_struct_ffitype_e(0, 0, [types.signed, types.signed])
         ffi_point = ffi_point_struct.ffistruct
-        sum_point = (libfoo, 'sum_point', [ffi_point], types.slong)
+        sum_point = (libfoo, 'sum_point', [ffi_point], types.signed)
         #
-        ARRAY = rffi.CArray(rffi.LONG)
+        ARRAY = rffi.CArray(rffi.SIGNED)
         buf = lltype.malloc(ARRAY, 2, flavor='raw')
         buf[0] = 30
         buf[1] = 12
         adr = rffi.cast(rffi.VOIDP, buf)
-        res = self.call(sum_point, [('arg_raw', adr)], rffi.LONG,
+        res = self.call(sum_point, [('arg_raw', adr)], rffi.SIGNED,
                         jitif=["byval"])
         assert res == 42
         # check that we still have the ownership on the buffer
@@ -422,7 +421,7 @@
 
     def test_byval_result(self):
         """
-            struct Point make_point(long x, long y) {
+            struct Point make_point(Signed x, Signed y) {
                 struct Point p;
                 p.x = x;
                 p.y = y;
@@ -430,13 +429,13 @@
             }
         """
         libfoo = CDLL(self.libfoo_name)
-        ffi_point_struct = make_struct_ffitype_e(0, 0, [types.slong, types.slong])
+        ffi_point_struct = make_struct_ffitype_e(0, 0, [types.signed, types.signed])
         ffi_point = ffi_point_struct.ffistruct
 
         libfoo = CDLL(self.libfoo_name)
-        make_point = (libfoo, 'make_point', [types.slong, types.slong], ffi_point)
+        make_point = (libfoo, 'make_point', [types.signed, types.signed], ffi_point)
         #
-        PTR = lltype.Ptr(rffi.CArray(rffi.LONG))
+        PTR = lltype.Ptr(rffi.CArray(rffi.SIGNED))
         p = self.call(make_point, [12, 34], PTR, is_struct=True,
                       jitif=["byval"])
         assert p[0] == 12


More information about the pypy-commit mailing list