diff options
author | Ranjit Mathew <rmathew@hotmail.com> | 2002-12-06 01:16:45 +0000 |
---|---|---|
committer | Anthony Green <green@gcc.gnu.org> | 2002-12-06 01:16:45 +0000 |
commit | eb3c46a17ebe3dfe1b374d40f8a8296a83e24751 (patch) | |
tree | 42b4b6f3ce932aab0dbf81a4fb15247efd28b464 /libffi/src/ffitest.c | |
parent | 1fcfaf375c135079ebea8aa17e726c51c938cc61 (diff) | |
download | gcc-eb3c46a17ebe3dfe1b374d40f8a8296a83e24751.zip gcc-eb3c46a17ebe3dfe1b374d40f8a8296a83e24751.tar.gz gcc-eb3c46a17ebe3dfe1b374d40f8a8296a83e24751.tar.bz2 |
ffi.h.in: Added FFI_STDCALL ffi_type enumeration for X86_WIN32.
2002-11-10 Ranjit Mathew <rmathew@hotmail.com>
* include/ffi.h.in: Added FFI_STDCALL ffi_type
enumeration for X86_WIN32.
* src/x86/win32.S: Added ffi_call_STDCALL function
definition.
* src/x86/ffi.c (ffi_call/ffi_raw_call): Added
switch cases for recognising FFI_STDCALL and
calling ffi_call_STDCALL if target is X86_WIN32.
* src/ffitest.c (my_stdcall_strlen/stdcall_many):
stdcall versions of the "my_strlen" and "many"
test functions (for X86_WIN32).
Added test cases to test stdcall invocation using
these functions.
From-SVN: r59878
Diffstat (limited to 'libffi/src/ffitest.c')
-rw-r--r-- | libffi/src/ffitest.c | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/libffi/src/ffitest.c b/libffi/src/ffitest.c index 163c4a8..da52831 100644 --- a/libffi/src/ffitest.c +++ b/libffi/src/ffitest.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- - ffitest.c - Copyright (c) 1996, 1997, 1998 Cygnus Solutions + ffitest.c - Copyright (c) 1996, 1997, 1998, 2002 Red Hat, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -49,6 +49,13 @@ static size_t my_strlen(char *s) return (strlen(s)); } +#ifdef X86_WIN32 +static size_t __attribute__((stdcall)) my_stdcall_strlen(char *s) +{ + return (strlen(s)); +} +#endif /* X86_WIN32 */ + static int promotion(signed char sc, signed short ss, unsigned char uc, unsigned short us) { @@ -112,6 +119,25 @@ static float many(float f1, return ((f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13); } +#ifdef X86_WIN32 +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) +{ + return ((f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13); +} +#endif /* X86_WIN32 */ + static double dblit(float f) { return f/3.0; @@ -954,6 +980,67 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[]) printf("Structure passing doesn't work on Win32.\n"); #endif /* X86_WIN32 */ +#ifdef X86_WIN32 + /* stdcall strlen tests */ + { + args[0] = &ffi_type_pointer; + values[0] = (void*) &s; + + /* Initialize the cif */ + CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 1, + &ffi_type_sint, args) == FFI_OK); + + s = "a"; + ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values); + CHECK(rint == 1); + + s = "1234567"; + ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values); + CHECK(rint == 7); + + s = "1234567890123456789012345"; + ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values); + CHECK(rint == 25); + + printf("stdcall strlen tests passed\n"); + } + + /* stdcall many arg tests */ + { + float ff; + float fa[13]; + + for (ul = 0; ul < 13; ul++) + { + args[ul] = &ffi_type_float; + values[ul] = &fa[ul]; + fa[ul] = (float) ul; + } + + /* Initialize the cif */ + CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 13, + &ffi_type_float, args) == FFI_OK); + + /*@-usedef@*/ + ff = stdcall_many(fa[0], fa[1], + fa[2], fa[3], + fa[4], fa[5], + fa[6], fa[7], + fa[8], fa[9], + fa[10],fa[11],fa[12]); + /*@=usedef@*/ + + ffi_call(&cif, FFI_FN(stdcall_many), &f, values); + + /*@-realcompare@*/ + if (f - ff < FLT_EPSILON) + /*@=realcompare@*/ + printf("stdcall many arg tests ok!\n"); + else + CHECK(0); + } +#endif /* X86_WIN32 */ + # if FFI_CLOSURES /* A simple closure test */ { |