struct8.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 f1;
  11. float f2;
  12. float f3;
  13. float f4;
  14. } test_structure_8;
  15. static test_structure_8 ABI_ATTR struct8 (test_structure_8 ts)
  16. {
  17. ts.f1 += 1;
  18. ts.f2 += 1;
  19. ts.f3 += 1;
  20. ts.f4 += 1;
  21. return ts;
  22. }
  23. int main (void)
  24. {
  25. ffi_cif cif;
  26. ffi_type *args[MAX_ARGS];
  27. void *values[MAX_ARGS];
  28. ffi_type ts8_type;
  29. ffi_type *ts8_type_elements[5];
  30. test_structure_8 ts8_arg;
  31. /* This is a hack to get a properly aligned result buffer */
  32. test_structure_8 *ts8_result =
  33. (test_structure_8 *) malloc (sizeof(test_structure_8));
  34. ts8_type.size = 0;
  35. ts8_type.alignment = 0;
  36. ts8_type.type = FFI_TYPE_STRUCT;
  37. ts8_type.elements = ts8_type_elements;
  38. ts8_type_elements[0] = &ffi_type_float;
  39. ts8_type_elements[1] = &ffi_type_float;
  40. ts8_type_elements[2] = &ffi_type_float;
  41. ts8_type_elements[3] = &ffi_type_float;
  42. ts8_type_elements[4] = NULL;
  43. args[0] = &ts8_type;
  44. values[0] = &ts8_arg;
  45. /* Initialize the cif */
  46. CHECK(ffi_prep_cif(&cif, ABI_NUM, 1, &ts8_type, args) == FFI_OK);
  47. ts8_arg.f1 = 5.55f;
  48. ts8_arg.f2 = 55.5f;
  49. ts8_arg.f3 = -5.55f;
  50. ts8_arg.f4 = -55.5f;
  51. printf ("%g\n", ts8_arg.f1);
  52. printf ("%g\n", ts8_arg.f2);
  53. printf ("%g\n", ts8_arg.f3);
  54. printf ("%g\n", ts8_arg.f4);
  55. ffi_call(&cif, FFI_FN(struct8), ts8_result, values);
  56. printf ("%g\n", ts8_result->f1);
  57. printf ("%g\n", ts8_result->f2);
  58. printf ("%g\n", ts8_result->f3);
  59. printf ("%g\n", ts8_result->f4);
  60. CHECK(ts8_result->f1 == 5.55f + 1);
  61. CHECK(ts8_result->f2 == 55.5f + 1);
  62. CHECK(ts8_result->f3 == -5.55f + 1);
  63. CHECK(ts8_result->f4 == -55.5f + 1);
  64. free (ts8_result);
  65. exit(0);
  66. }