This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] port libffi to x86/msvc


> On 01/14/2010 12:24 PM, Anthony Green wrote:
> 
> Ignore me.  You did run the testsuite.  I assume that there were no 
> unexpected failures, correct?
> 
> AG

Right - on existing platforms. I've run Mozilla's ffi_call testsuite on i686-pc-linux-gnu, x86_64-unknown-linux-gnu, i686-pc-mingw32 (with MSVC), and i386-apple-darwin9.2.0. It passes on all those. I've run libffi's testsuite on i686-pc-linux-gnu, x86_64-unknown-linux-gnu, and i386-apple-darwin9.2.0. No unexpected failures.

libffi's testsuite will need a patch for i686-pc-mingw32 with MSVC, attached. I didn't have any luck running the testsuite, for lack of getting the dejagnu stuff set up correctly. However, the Mozilla testsuite covers basically the same stuff, including some testing of the closure API. We test ffi_call for SYSV and STDCALL functions thoroughly, including small struct return values. So I'm pretty confident things are working.

I haven't tested i686-pc-mingw32 with gcc. If anyone can help with that, it would be most appreciated. :)

Thanks,
Dan.
2010-01-14  Daniel Witte  <dwitte@mozilla.com>
  * testsuite/libffi.call/: Fix various tests to work with MSVC on X86_WIN32.

diff --git a/libffi/ChangeLog b/libffi/ChangeLog
--- a/libffi/ChangeLog
+++ b/libffi/ChangeLog
@@ -1,8 +1,11 @@
+2010-01-14  Daniel Witte  <dwitte@mozilla.com>
+  * testsuite/libffi.call/: Fix various tests to work with MSVC on X86_WIN32.
+
 2010-01-12  Daniel Witte  <dwitte@mozilla.com>
   * src/x86/win32.S: Port assembly routines to MSVC and #ifdef.
   * src/x86/ffi.c: Tweak function declaration and remove excess parens.
   * include/ffi.h.in: Add __declspec(align(8)) to typedef struct ffi_closure.
 
 2010-01-12  Daniel Witte  <dwitte@mozilla.com>
   * src/x86/ffi.c: Merge ffi_call_SYSV and ffi_call_STDCALL into new
   function ffi_call_win32 on X86_WIN32.
diff --git a/libffi/testsuite/libffi.call/closure_stdcall.c b/libffi/testsuite/libffi.call/closure_stdcall.c
--- a/libffi/testsuite/libffi.call/closure_stdcall.c
+++ b/libffi/testsuite/libffi.call/closure_stdcall.c
@@ -18,17 +18,17 @@ closure_test_stdcall(ffi_cif* cif __UNUS
 
   printf("%d %d %d %d: %d\n",
 	 (int)*(int *)args[0], (int)(*(int *)args[1]),
 	 (int)(*(int *)args[2]), (int)(*(int *)args[3]),
          (int)*(ffi_arg *)resp);
 
 }
 
-typedef int (__stdcall *closure_test_type0)(int, int, int, int);
+typedef int (FFI_STDCALL *closure_test_type0)(int, int, int, int);
 
 int main (void)
 {
   ffi_cif cif;
   void *code;
   ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
   ffi_type * cl_arg_types[17];
   int res;
@@ -44,19 +44,27 @@ int main (void)
 
   /* Initialize the cif */
   CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 4,
 		     &ffi_type_sint, cl_arg_types) == FFI_OK);
 
   CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_stdcall,
                              (void *) 3 /* userdata */, code) == FFI_OK);
 
+#if defined(__GNUC__)
   asm volatile (" movl %%esp,%0" : "=g" (sp_pre));
   res = (*(closure_test_type0)code)(0, 1, 2, 3);
   asm volatile (" movl %%esp,%0" : "=g" (sp_post));
+#elif defined (_MSC_VER)
+  __asm { mov sp_pre, esp }
+  res = (*(closure_test_type0)code)(0, 1, 2, 3);
+  __asm { mov sp_post, esp }
+#else
+#error "Unknown compiler!"
+#endif
   /* { dg-output "0 1 2 3: 9" } */
 
   printf("res: %d\n",res);
   /* { dg-output "\nres: 9" } */
 
   sprintf(buf, "mismatch: pre=%p vs post=%p", sp_pre, sp_post);
   printf("stack pointer %s\n", (sp_pre == sp_post ? "match" : buf));
   /* { dg-output "\nstack pointer match" } */
diff --git a/libffi/testsuite/libffi.call/ffitest.h b/libffi/testsuite/libffi.call/ffitest.h
--- a/libffi/testsuite/libffi.call/ffitest.h
+++ b/libffi/testsuite/libffi.call/ffitest.h
@@ -20,16 +20,26 @@
 /* Define __UNUSED__ that also other compilers than gcc can run the tests.  */
 #undef __UNUSED__
 #if defined(__GNUC__)
 #define __UNUSED__ __attribute__((__unused__))
 #else
 #define __UNUSED__
 #endif
 
+/* Define FFI_STDCALL for various compilers.  */
+#undef FFI_STDCALL
+#if defined(__GNUC__)
+#define FFI_STDCALL __attribute__((stdcall))
+#elif defined (_MSC_VER)
+#define FFI_STDCALL __stdcall
+#else
+#define FFI_STDCALL
+#endif
+
 /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
    file open.  */
 #ifdef HAVE_MMAP_ANON
 # undef HAVE_MMAP_DEV_ZERO
 
 # include <sys/mman.h>
 # ifndef MAP_FAILED
 #  define MAP_FAILED -1
diff --git a/libffi/testsuite/libffi.call/many_win32.c b/libffi/testsuite/libffi.call/many_win32.c
--- a/libffi/testsuite/libffi.call/many_win32.c
+++ b/libffi/testsuite/libffi.call/many_win32.c
@@ -4,29 +4,29 @@
    PR:		none.
    Originator:	From the original ffitest.c  */
 
 /* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */
 
 #include "ffitest.h"
 #include <float.h>
 
-static float __attribute__((stdcall)) stdcall_many(float f1,
-						   float f2,
-						   float f3,
-						   float f4,
-						   float f5,
-						   float f6,
-						   float f7,
-						   float f8,
-						   float f9,
-						   float f10,
-						   float f11,
-						   float f12,
-						   float f13)
+static float FFI_STDCALL stdcall_many(float f1,
+                                      float f2,
+                                      float f3,
+                                      float f4,
+                                      float f5,
+                                      float f6,
+                                      float f7,
+                                      float f8,
+                                      float f9,
+                                      float f10,
+                                      float f11,
+                                      float f12,
+                                      float f13)
 {
   return ((f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13);
 }
 
 int main (void)
 {
   ffi_cif cif;
   ffi_type *args[13];
diff --git a/libffi/testsuite/libffi.call/strlen_win32.c b/libffi/testsuite/libffi.call/strlen_win32.c
--- a/libffi/testsuite/libffi.call/strlen_win32.c
+++ b/libffi/testsuite/libffi.call/strlen_win32.c
@@ -3,17 +3,17 @@
    Limitations:	none.
    PR:		none.
    Originator:	From the original ffitest.c  */
 
 /* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */
 
 #include "ffitest.h"
 
-static size_t __attribute__((stdcall)) my_stdcall_strlen(char *s)
+static size_t FFI_STDCALL my_stdcall_strlen(char *s)
 {
   return (strlen(s));
 }
 
 int main (void)
 {
   ffi_cif cif;
   ffi_type *args[MAX_ARGS];

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]