OSDN Git Service

45ce9bd7c387745c202fc3c7d999e49124752b4c
[pf3gnuchains/gcc-fork.git] / libffi / testsuite / libffi.call / cls_double_va.c
1 /* Area:                ffi_call, closure_call
2    Purpose:             Test doubles passed in variable argument lists.
3    Limitations: none.
4    PR:                  none.
5    Originator:  Blake Chaffin 6/6/2007   */
6
7 /* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8 #include "ffitest.h"
9
10 static void
11 cls_double_va_fn(ffi_cif* cif __UNUSED__, void* resp, 
12                  void** args, void* userdata __UNUSED__)
13 {
14         char*   format          = *(char**)args[0];
15         double  doubleValue     = *(double*)args[1];
16
17         *(ffi_arg*)resp = printf(format, doubleValue);
18 }
19
20 int main (void)
21 {
22         ffi_cif cif;
23         void *code;
24         ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
25         void* args[3];
26         ffi_type* arg_types[3];
27
28         char*   format          = "%.1f\n";
29         double  doubleArg       = 7;
30         ffi_arg res                     = 0;
31
32         arg_types[0] = &ffi_type_pointer;
33         arg_types[1] = &ffi_type_double;
34         arg_types[2] = NULL;
35
36         CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint,
37                 arg_types) == FFI_OK);
38
39         args[0] = &format;
40         args[1] = &doubleArg;
41         args[2] = NULL;
42
43         ffi_call(&cif, FFI_FN(printf), &res, args);
44         // { dg-output "7.0" }
45         printf("res: %d\n", (int) res);
46         // { dg-output "\nres: 4" }
47
48         CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK);
49
50         res     = ((int(*)(char*, double))(code))(format, doubleArg);
51         // { dg-output "\n7.0" }
52         printf("res: %d\n", (int) res);
53         // { dg-output "\nres: 4" }
54
55         exit(0);
56 }