cls_multi_ushort.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Area: ffi_call, closure_call
  2. Purpose: Check passing of multiple unsigned short values.
  3. Limitations: none.
  4. PR: PR13221.
  5. Originator: <andreast@gcc.gnu.org> 20031129 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. unsigned short test_func_fn(unsigned short a1, unsigned short a2)
  9. {
  10. unsigned short result;
  11. result = a1 + a2;
  12. printf("%d %d: %d\n", a1, a2, result);
  13. return result;
  14. }
  15. static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
  16. void *data __UNUSED__)
  17. {
  18. unsigned short a1, a2;
  19. a1 = *(unsigned short *)avals[0];
  20. a2 = *(unsigned short *)avals[1];
  21. *(ffi_arg *)rval = test_func_fn(a1, a2);
  22. }
  23. typedef unsigned short (*test_type)(unsigned short, unsigned short);
  24. int main (void)
  25. {
  26. ffi_cif cif;
  27. void *code;
  28. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  29. void * args_dbl[3];
  30. ffi_type * cl_arg_types[3];
  31. ffi_arg res_call;
  32. unsigned short a, b, res_closure;
  33. a = 2;
  34. b = 32765;
  35. args_dbl[0] = &a;
  36. args_dbl[1] = &b;
  37. args_dbl[2] = NULL;
  38. cl_arg_types[0] = &ffi_type_ushort;
  39. cl_arg_types[1] = &ffi_type_ushort;
  40. cl_arg_types[2] = NULL;
  41. /* Initialize the cif */
  42. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
  43. &ffi_type_ushort, cl_arg_types) == FFI_OK);
  44. ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
  45. /* { dg-output "2 32765: 32767" } */
  46. printf("res: %d\n", (unsigned short)res_call);
  47. /* { dg-output "\nres: 32767" } */
  48. CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
  49. res_closure = (*((test_type)code))(2, 32765);
  50. /* { dg-output "\n2 32765: 32767" } */
  51. printf("res: %d\n", res_closure);
  52. /* { dg-output "\nres: 32767" } */
  53. exit(0);
  54. }