struct3.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. int si;
  11. } test_structure_3;
  12. static test_structure_3 ABI_ATTR struct3(test_structure_3 ts)
  13. {
  14. ts.si = -(ts.si*2);
  15. return ts;
  16. }
  17. int main (void)
  18. {
  19. ffi_cif cif;
  20. ffi_type *args[MAX_ARGS];
  21. void *values[MAX_ARGS];
  22. int compare_value;
  23. ffi_type ts3_type;
  24. ffi_type *ts3_type_elements[2];
  25. test_structure_3 ts3_arg;
  26. test_structure_3 *ts3_result =
  27. (test_structure_3 *) malloc (sizeof(test_structure_3));
  28. ts3_type.size = 0;
  29. ts3_type.alignment = 0;
  30. ts3_type.type = FFI_TYPE_STRUCT;
  31. ts3_type.elements = ts3_type_elements;
  32. ts3_type_elements[0] = &ffi_type_sint;
  33. ts3_type_elements[1] = NULL;
  34. args[0] = &ts3_type;
  35. values[0] = &ts3_arg;
  36. /* Initialize the cif */
  37. CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
  38. &ts3_type, args) == FFI_OK);
  39. ts3_arg.si = -123;
  40. compare_value = ts3_arg.si;
  41. ffi_call(&cif, FFI_FN(struct3), ts3_result, values);
  42. printf ("%d %d\n", ts3_result->si, -(compare_value*2));
  43. CHECK(ts3_result->si == -(compare_value*2));
  44. free (ts3_result);
  45. exit(0);
  46. }