struct4.c 1.3 KB

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