Home | History | Annotate | Download | only in libffi.call
      1 /* Area:	ffi_call
      2    Purpose:	Check structures.
      3    Limitations:	none.
      4    PR:		none.
      5    Originator:	From the original ffitest.c  */
      6 
      7 /* { dg-do run } */
      8 #include "ffitest.h"
      9 
     10 typedef struct
     11 {
     12   unsigned ui1;
     13   unsigned ui2;
     14   unsigned ui3;
     15 } test_structure_4;
     16 
     17 static test_structure_4 struct4(test_structure_4 ts)
     18 {
     19   ts.ui3 = ts.ui1 * ts.ui2 * ts.ui3;
     20 
     21   return ts;
     22 }
     23 
     24 int main (void)
     25 {
     26   ffi_cif cif;
     27   ffi_type *args[MAX_ARGS];
     28   void *values[MAX_ARGS];
     29   ffi_type ts4_type;
     30   ffi_type *ts4_type_elements[4];
     31   ts4_type.size = 0;
     32   ts4_type.alignment = 0;
     33   ts4_type.type = FFI_TYPE_STRUCT;
     34   test_structure_4 ts4_arg;
     35   ts4_type.elements = ts4_type_elements;
     36   ts4_type_elements[0] = &ffi_type_uint;
     37   ts4_type_elements[1] = &ffi_type_uint;
     38   ts4_type_elements[2] = &ffi_type_uint;
     39   ts4_type_elements[3] = NULL;
     40 
     41 
     42   /* This is a hack to get a properly aligned result buffer */
     43   test_structure_4 *ts4_result =
     44     (test_structure_4 *) malloc (sizeof(test_structure_4));
     45 
     46   args[0] = &ts4_type;
     47   values[0] = &ts4_arg;
     48 
     49   /* Initialize the cif */
     50   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts4_type, args) == FFI_OK);
     51 
     52   ts4_arg.ui1 = 2;
     53   ts4_arg.ui2 = 3;
     54   ts4_arg.ui3 = 4;
     55 
     56   ffi_call (&cif, FFI_FN(struct4), ts4_result, values);
     57 
     58   CHECK(ts4_result->ui3 == 2U * 3U * 4U);
     59 
     60 
     61   free (ts4_result);
     62   exit(0);
     63 }
     64