Home | History | Annotate | Download | only in libffi.call
      1 /* Area:	ffi_call, closure_call
      2    Purpose:	Check passing of multiple signed short/char values.
      3    Limitations:	none.
      4    PR:		PR13221.
      5    Originator:	<andreast (at) gcc.gnu.org> 20031129  */
      6 
      7 /* { dg-do run } */
      8 #include "ffitest.h"
      9 
     10 signed short test_func_fn(signed char a1, signed short a2,
     11 			  signed char a3, signed short a4)
     12 {
     13   signed short 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   signed char a1, a3;
     27   signed short a2, a4;
     28 
     29   a1 = *(signed char *)avals[0];
     30   a2 = *(signed short *)avals[1];
     31   a3 = *(signed char *)avals[2];
     32   a4 = *(signed short *)avals[3];
     33 
     34   *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
     35 
     36 }
     37 
     38 typedef signed short (*test_type)(signed char, signed short,
     39 				  signed char, signed short);
     40 
     41 int main (void)
     42 {
     43   ffi_cif cif;
     44 #ifndef USING_MMAP
     45   static ffi_closure cl;
     46 #endif
     47   ffi_closure *pcl;
     48   void * args_dbl[5];
     49   ffi_type * cl_arg_types[5];
     50   ffi_arg res_call;
     51   signed char a, c;
     52   signed short b, d, res_closure;
     53 
     54 #ifdef USING_MMAP
     55   pcl = allocate_mmap (sizeof(ffi_closure));
     56 #else
     57   pcl = &cl;
     58 #endif
     59 
     60   a = 1;
     61   b = 32765;
     62   c = 127;
     63   d = -128;
     64 
     65   args_dbl[0] = &a;
     66   args_dbl[1] = &b;
     67   args_dbl[2] = &c;
     68   args_dbl[3] = &d;
     69   args_dbl[4] = NULL;
     70 
     71   cl_arg_types[0] = &ffi_type_schar;
     72   cl_arg_types[1] = &ffi_type_sshort;
     73   cl_arg_types[2] = &ffi_type_schar;
     74   cl_arg_types[3] = &ffi_type_sshort;
     75   cl_arg_types[4] = NULL;
     76 
     77   /* Initialize the cif */
     78   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
     79 		     &ffi_type_sshort, cl_arg_types) == FFI_OK);
     80 
     81   ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
     82   /* { dg-output "1 32765 127 -128: 32765" } */
     83   printf("res: %d\n", (signed short)res_call);
     84   /* { dg-output "\nres: 32765" } */
     85 
     86   CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL)  == FFI_OK);
     87 
     88   res_closure = (*((test_type)pcl))(1, 32765, 127, -128);
     89   /* { dg-output "\n1 32765 127 -128: 32765" } */
     90   printf("res: %d\n", res_closure);
     91   /* { dg-output "\nres: 32765" } */
     92 
     93   exit(0);
     94 }
     95