cls_ulong_va.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Area: closure_call
  2. Purpose: Test anonymous unsigned long argument.
  3. Limitations: none.
  4. PR: none.
  5. Originator: ARM Ltd. */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. typedef unsigned long T;
  9. static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
  10. void* userdata __UNUSED__)
  11. {
  12. *(T *)resp = *(T *)args[0];
  13. printf("%ld: %ld %ld\n", *(T *)resp, *(T *)args[0], *(T *)args[1]);
  14. }
  15. typedef T (*cls_ret_T)(T, ...);
  16. int main (void)
  17. {
  18. ffi_cif cif;
  19. void *code;
  20. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  21. ffi_type * cl_arg_types[3];
  22. T res;
  23. cl_arg_types[0] = &ffi_type_ulong;
  24. cl_arg_types[1] = &ffi_type_ulong;
  25. cl_arg_types[2] = NULL;
  26. /* Initialize the cif */
  27. CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2,
  28. &ffi_type_ulong, cl_arg_types) == FFI_OK);
  29. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK);
  30. res = ((((cls_ret_T)code)(67, 4)));
  31. /* { dg-output "67: 67 4" } */
  32. printf("res: %ld\n", res);
  33. /* { dg-output "\nres: 67" } */
  34. exit(0);
  35. }