]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libffi/testsuite/libffi.call/cls_many_mixed_args.c
2 Purpose: Check closures called with many args of mixed types
5 Originator: <david.schneider@picle.org> */
14 static void cls_ret_double_fn(ffi_cif
* cif __UNUSED__
, void* resp
, void** args
,
15 void* userdata __UNUSED__
)
20 for(i
= 0; i
< NARGS
; i
++)
22 if(i
== 4 || i
== 9 || i
== 11 || i
== 13 || i
== 15)
24 t
= *(long int *)args
[i
];
29 t
= *(double *)args
[i
];
30 CHECK(fabs(t
- ((i
+1) * 0.1)) < FLT_EPSILON
);
36 typedef double (*cls_ret_double
)(double, double, double, double, long int,
37 double, double, double, double, long int, double, long int, double, long int,
44 ffi_closure
*pcl
= ffi_closure_alloc(sizeof(ffi_closure
), &code
);
45 ffi_type
* cl_arg_types
[NARGS
];
48 double expected
= 64.9;
50 for(i
= 0; i
< NARGS
; i
++)
52 if(i
== 4 || i
== 9 || i
== 11 || i
== 13 || i
== 15)
53 cl_arg_types
[i
] = &ffi_type_slong
;
55 cl_arg_types
[i
] = &ffi_type_double
;
58 /* Initialize the cif */
59 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, NARGS
,
60 &ffi_type_double
, cl_arg_types
) == FFI_OK
);
62 CHECK(ffi_prep_closure_loc(pcl
, &cif
, cls_ret_double_fn
, NULL
, code
) == FFI_OK
);
64 res
= (((cls_ret_double
)code
))(0.1, 0.2, 0.3, 0.4, 5, 0.6, 0.7, 0.8, 0.9, 10,
65 1.1, 12, 1.3, 14, 1.5, 16);
66 if (fabs(res
- expected
) < FLT_EPSILON
)