2010-01-14 Daniel Witte * 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 + * testsuite/libffi.call/: Fix various tests to work with MSVC on X86_WIN32. + 2010-01-12 Daniel Witte * 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 * 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 (__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 __STDCALL__ for various compilers. */ +#undef __STDCALL__ +#if defined(__GNUC__) +#define __STDCALL__ __attribute__((stdcall)) +#elif defined (_MSC_VER) +#define __STDCALL__ __stdcall +#else +#define __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 # 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 -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 __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 __STDCALL__ my_stdcall_strlen(char *s) { return (strlen(s)); } int main (void) { ffi_cif cif; ffi_type *args[MAX_ARGS];