struct1.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 char uc;
  11. double d;
  12. unsigned int ui;
  13. } test_structure_1;
  14. static test_structure_1 ABI_ATTR struct1(test_structure_1 ts)
  15. {
  16. ts.uc++;
  17. ts.d--;
  18. ts.ui++;
  19. return ts;
  20. }
  21. int main (void)
  22. {
  23. ffi_cif cif;
  24. ffi_type *args[MAX_ARGS];
  25. void *values[MAX_ARGS];
  26. ffi_type ts1_type;
  27. ffi_type *ts1_type_elements[4];
  28. test_structure_1 ts1_arg;
  29. /* This is a hack to get a properly aligned result buffer */
  30. test_structure_1 *ts1_result =
  31. (test_structure_1 *) malloc (sizeof(test_structure_1));
  32. ts1_type.size = 0;
  33. ts1_type.alignment = 0;
  34. ts1_type.type = FFI_TYPE_STRUCT;
  35. ts1_type.elements = ts1_type_elements;
  36. ts1_type_elements[0] = &ffi_type_uchar;
  37. ts1_type_elements[1] = &ffi_type_double;
  38. ts1_type_elements[2] = &ffi_type_uint;
  39. ts1_type_elements[3] = NULL;
  40. args[0] = &ts1_type;
  41. values[0] = &ts1_arg;
  42. /* Initialize the cif */
  43. CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
  44. &ts1_type, args) == FFI_OK);
  45. ts1_arg.uc = '\x01';
  46. ts1_arg.d = 3.14159;
  47. ts1_arg.ui = 555;
  48. ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
  49. CHECK(ts1_result->ui == 556);
  50. CHECK(ts1_result->d == 3.14159 - 1);
  51. free (ts1_result);
  52. exit(0);
  53. }