2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / testsuite / libffi.call / cls_multi_uchar.c
blob0b00bc3ff41c4e21ce7efda02c560cf2bb594e27
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned char values.
3 Limitations: none.
4 PR: PR13221.
5 Originator: <andreast@gcc.gnu.org> 20031129 */
7 /* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8 #include "ffitest.h"
10 unsigned char test_func_fn(unsigned char a1, unsigned char a2,
11 unsigned char a3, unsigned char a4)
13 unsigned char result;
15 result = a1 + a2 + a3 + a4;
17 printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
19 return result;
23 static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
25 unsigned char a1, a2, a3, a4;
27 a1 = *(unsigned char *)avals[0];
28 a2 = *(unsigned char *)avals[1];
29 a3 = *(unsigned char *)avals[2];
30 a4 = *(unsigned char *)avals[3];
32 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
36 typedef unsigned char (*test_type)(unsigned char, unsigned char,
37 unsigned char, unsigned char);
38 void test_func(ffi_cif *cif, void *rval, void **avals, void *data)
40 printf("%d %d %d %d\n", *(unsigned char *)avals[0],
41 *(unsigned char *)avals[1], *(unsigned char *)avals[2],
42 *(unsigned char *)avals[3]);
44 int main (void)
46 ffi_cif cif;
47 #ifndef USING_MMAP
48 static ffi_closure cl;
49 #endif
50 ffi_closure *pcl;
51 void * args_dbl[5];
52 ffi_type * cl_arg_types[5];
53 ffi_arg res_call;
54 unsigned char a, b, c, d, res_closure;
56 #ifdef USING_MMAP
57 pcl = allocate_mmap (sizeof(ffi_closure));
58 #else
59 pcl = &cl;
60 #endif
62 a = 1;
63 b = 2;
64 c = 127;
65 d = 125;
67 args_dbl[0] = &a;
68 args_dbl[1] = &b;
69 args_dbl[2] = &c;
70 args_dbl[3] = &d;
71 args_dbl[4] = NULL;
73 cl_arg_types[0] = &ffi_type_uchar;
74 cl_arg_types[1] = &ffi_type_uchar;
75 cl_arg_types[2] = &ffi_type_uchar;
76 cl_arg_types[3] = &ffi_type_uchar;
77 cl_arg_types[4] = NULL;
79 /* Initialize the cif */
80 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
81 &ffi_type_uchar, cl_arg_types) == FFI_OK);
83 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
84 /* { dg-output "1 2 127 125: 255" } */
85 printf("res: %d\n", res_call);
86 /* { dg-output "\nres: 255" } */
88 CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
90 res_closure = (*((test_type)pcl))(1, 2, 127, 125);
91 /* { dg-output "\n1 2 127 125: 255" } */
92 printf("res: %d\n", res_closure);
93 /* { dg-output "\nres: 255" } */
95 exit(0);