Imported File#ftype spec from rubyspecs.
[rbx.git] / shotgun / external_libs / libffi / testsuite / libffi.call / cls_multi_uchar.c
blob2c84aef6134c26a1f84a442f8842798ee4dede99
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 } */
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 __UNUSED__, void *rval, void **avals,
24 void *data __UNUSED__)
26 unsigned char a1, a2, a3, a4;
28 a1 = *(unsigned char *)avals[0];
29 a2 = *(unsigned char *)avals[1];
30 a3 = *(unsigned char *)avals[2];
31 a4 = *(unsigned char *)avals[3];
33 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
37 typedef unsigned char (*test_type)(unsigned char, unsigned char,
38 unsigned char, unsigned char);
40 void test_func(ffi_cif *cif __UNUSED__, void *rval __UNUSED__, void **avals,
41 void *data __UNUSED__)
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]);
47 int main (void)
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;
59 #ifdef USING_MMAP
60 pcl = allocate_mmap (sizeof(ffi_closure));
61 #else
62 pcl = &cl;
63 #endif
65 a = 1;
66 b = 2;
67 c = 127;
68 d = 125;
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;
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;
82 /* Initialize the cif */
83 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
84 &ffi_type_uchar, cl_arg_types) == FFI_OK);
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" } */
91 CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
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" } */
98 exit(0);