cls_sshort.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Area: closure_call
  2. Purpose: Check return value sshort.
  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_sshort_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
  9. void* userdata __UNUSED__)
  10. {
  11. *(ffi_arg*)resp = *(signed short *)args[0];
  12. printf("%d: %d\n",*(signed short *)args[0],
  13. (int)*(ffi_arg *)(resp));
  14. }
  15. typedef signed short (*cls_ret_sshort)(signed short);
  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 short res;
  23. cl_arg_types[0] = &ffi_type_sshort;
  24. cl_arg_types[1] = NULL;
  25. /* Initialize the cif */
  26. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  27. &ffi_type_sshort, cl_arg_types) == FFI_OK);
  28. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_sshort_fn, NULL, code) == FFI_OK);
  29. res = (*((cls_ret_sshort)code))(255);
  30. /* { dg-output "255: 255" } */
  31. printf("res: %d\n",res);
  32. /* { dg-output "\nres: 255" } */
  33. exit(0);
  34. }