OSDN Git Service

Merge "Only mips needs libffi (for unoptimized dalvik JNI)."
[android-x86/external-libffi.git] / testsuite / libffi.call / cls_multi_uchar.c
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  */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9
10 unsigned char test_func_fn(unsigned char a1, unsigned char a2,
11                            unsigned char a3, unsigned char a4)
12 {
13   unsigned char result;
14
15   result = a1 + a2 + a3 + a4;
16
17   printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
18
19   return result;
20
21 }
22
23 static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
24                          void *data __UNUSED__)
25 {
26   unsigned char a1, a2, a3, a4;
27
28   a1 = *(unsigned char *)avals[0];
29   a2 = *(unsigned char *)avals[1];
30   a3 = *(unsigned char *)avals[2];
31   a4 = *(unsigned char *)avals[3];
32
33   *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
34
35 }
36
37 typedef unsigned char (*test_type)(unsigned char, unsigned char,
38                                    unsigned char, unsigned char);
39
40 void test_func(ffi_cif *cif __UNUSED__, void *rval __UNUSED__, void **avals,
41                void *data __UNUSED__)
42 {
43   printf("%d %d %d %d\n", *(unsigned char *)avals[0],
44          *(unsigned char *)avals[1], *(unsigned char *)avals[2],
45          *(unsigned char *)avals[3]);
46 }
47 int main (void)
48 {
49   ffi_cif cif;
50 #ifndef USING_MMAP
51   static ffi_closure cl;
52 #endif
53   ffi_closure *pcl;
54   void * args_dbl[5];
55   ffi_type * cl_arg_types[5];
56   ffi_arg res_call;
57   unsigned char a, b, c, d, res_closure;
58
59 #ifdef USING_MMAP
60   pcl = allocate_mmap (sizeof(ffi_closure));
61 #else
62   pcl = &cl;
63 #endif
64
65   a = 1;
66   b = 2;
67   c = 127;
68   d = 125;
69
70   args_dbl[0] = &a;
71   args_dbl[1] = &b;
72   args_dbl[2] = &c;
73   args_dbl[3] = &d;
74   args_dbl[4] = NULL;
75
76   cl_arg_types[0] = &ffi_type_uchar;
77   cl_arg_types[1] = &ffi_type_uchar;
78   cl_arg_types[2] = &ffi_type_uchar;
79   cl_arg_types[3] = &ffi_type_uchar;
80   cl_arg_types[4] = NULL;
81
82   /* Initialize the cif */
83   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
84                      &ffi_type_uchar, cl_arg_types) == FFI_OK);
85
86   ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
87   /* { dg-output "1 2 127 125: 255" } */
88   printf("res: %d\n", (unsigned char)res_call);
89   /* { dg-output "\nres: 255" } */
90
91   CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL)  == FFI_OK);
92
93   res_closure = (*((test_type)pcl))(1, 2, 127, 125);
94   /* { dg-output "\n1 2 127 125: 255" } */
95   printf("res: %d\n", res_closure);
96   /* { dg-output "\nres: 255" } */
97
98   exit(0);
99 }