struct6.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. float f;
  11. double d;
  12. } test_structure_6;
  13. static test_structure_6 ABI_ATTR struct6 (test_structure_6 ts)
  14. {
  15. ts.f += 1;
  16. ts.d += 1;
  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 ts6_type;
  25. ffi_type *ts6_type_elements[3];
  26. test_structure_6 ts6_arg;
  27. /* This is a hack to get a properly aligned result buffer */
  28. test_structure_6 *ts6_result =
  29. (test_structure_6 *) malloc (sizeof(test_structure_6));
  30. ts6_type.size = 0;
  31. ts6_type.alignment = 0;
  32. ts6_type.type = FFI_TYPE_STRUCT;
  33. ts6_type.elements = ts6_type_elements;
  34. ts6_type_elements[0] = &ffi_type_float;
  35. ts6_type_elements[1] = &ffi_type_double;
  36. ts6_type_elements[2] = NULL;
  37. args[0] = &ts6_type;
  38. values[0] = &ts6_arg;
  39. /* Initialize the cif */
  40. CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts6_type, args) == FFI_OK);
  41. ts6_arg.f = 5.55f;
  42. ts6_arg.d = 6.66;
  43. printf ("%g\n", ts6_arg.f);
  44. printf ("%g\n", ts6_arg.d);
  45. ffi_call(&cif, FFI_FN(struct6), ts6_result, values);
  46. CHECK(ts6_result->f == 5.55f + 1);
  47. CHECK(ts6_result->d == 6.66 + 1);
  48. free (ts6_result);
  49. exit(0);
  50. }