cls_ushort.c 1.1 KB

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