cls_multi_uchar.c 2.2 KB

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