struct5.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. char c1;
  11. char c2;
  12. } test_structure_5;
  13. static test_structure_5 ABI_ATTR struct5(test_structure_5 ts1, test_structure_5 ts2)
  14. {
  15. ts1.c1 += ts2.c1;
  16. ts1.c2 -= ts2.c2;
  17. return ts1;
  18. }
  19. int main (void)
  20. {
  21. ffi_cif cif;
  22. ffi_type *args[MAX_ARGS];
  23. void *values[MAX_ARGS];
  24. ffi_type ts5_type;
  25. ffi_type *ts5_type_elements[3];
  26. test_structure_5 ts5_arg1, ts5_arg2;
  27. /* This is a hack to get a properly aligned result buffer */
  28. test_structure_5 *ts5_result =
  29. (test_structure_5 *) malloc (sizeof(test_structure_5));
  30. ts5_type.size = 0;
  31. ts5_type.alignment = 0;
  32. ts5_type.type = FFI_TYPE_STRUCT;
  33. ts5_type.elements = ts5_type_elements;
  34. ts5_type_elements[0] = &ffi_type_schar;
  35. ts5_type_elements[1] = &ffi_type_schar;
  36. ts5_type_elements[2] = NULL;
  37. args[0] = &ts5_type;
  38. args[1] = &ts5_type;
  39. values[0] = &ts5_arg1;
  40. values[1] = &ts5_arg2;
  41. /* Initialize the cif */
  42. CHECK(ffi_prep_cif(&cif, ABI_NUM, 2, &ts5_type, args) == FFI_OK);
  43. ts5_arg1.c1 = 2;
  44. ts5_arg1.c2 = 6;
  45. ts5_arg2.c1 = 5;
  46. ts5_arg2.c2 = 3;
  47. ffi_call (&cif, FFI_FN(struct5), ts5_result, values);
  48. CHECK(ts5_result->c1 == 7);
  49. CHECK(ts5_result->c2 == 3);
  50. free (ts5_result);
  51. exit(0);
  52. }