cls_sint.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Area: closure_call
  2. Purpose: Check return value sint32.
  3. Limitations: none.
  4. PR: none.
  5. Originator: <andreast@gcc.gnu.org> 20031108 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. static void cls_ret_sint_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
  9. void* userdata __UNUSED__)
  10. {
  11. *(ffi_arg*)resp = *(signed int *)args[0];
  12. printf("%d: %d\n",*(signed int *)args[0],
  13. (int)*(ffi_arg *)(resp));
  14. }
  15. typedef signed int (*cls_ret_sint)(signed int);
  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[2];
  22. signed int res;
  23. cl_arg_types[0] = &ffi_type_sint;
  24. cl_arg_types[1] = NULL;
  25. /* Initialize the cif */
  26. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  27. &ffi_type_sint, cl_arg_types) == FFI_OK);
  28. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_sint_fn, NULL, code) == FFI_OK);
  29. res = (*((cls_ret_sint)code))(65534);
  30. /* { dg-output "65534: 65534" } */
  31. printf("res: %d\n",res);
  32. /* { dg-output "\nres: 65534" } */
  33. exit(0);
  34. }