cls_dbls_struct.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Area: ffi_call, closure_call
  2. Purpose: Check double arguments in structs.
  3. Limitations: none.
  4. PR: none.
  5. Originator: Blake Chaffin 6/23/2007 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. typedef struct Dbls {
  9. double x;
  10. double y;
  11. } Dbls;
  12. void
  13. closure_test_fn(Dbls p)
  14. {
  15. printf("%.1f %.1f\n", p.x, p.y);
  16. }
  17. void
  18. closure_test_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
  19. void** args, void* userdata __UNUSED__)
  20. {
  21. closure_test_fn(*(Dbls*)args[0]);
  22. }
  23. int main(int argc __UNUSED__, char** argv __UNUSED__)
  24. {
  25. ffi_cif cif;
  26. void *code;
  27. ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  28. ffi_type* cl_arg_types[1];
  29. ffi_type ts1_type;
  30. ffi_type* ts1_type_elements[4];
  31. Dbls arg = { 1.0, 2.0 };
  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_double;
  37. ts1_type_elements[1] = &ffi_type_double;
  38. ts1_type_elements[2] = NULL;
  39. cl_arg_types[0] = &ts1_type;
  40. /* Initialize the cif */
  41. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  42. &ffi_type_void, cl_arg_types) == FFI_OK);
  43. CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_gn, NULL, code) == FFI_OK);
  44. ((void*(*)(Dbls))(code))(arg);
  45. /* { dg-output "1.0 2.0" } */
  46. closure_test_fn(arg);
  47. /* { dg-output "\n1.0 2.0" } */
  48. return 0;
  49. }