strlen4.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Area: ffi_call
  2. Purpose: Check strlen function call with additional arguments.
  3. Limitations: none.
  4. PR: none.
  5. Originator: From the original ffitest.c */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. static size_t ABI_ATTR my_f(float a, char *s, int i)
  9. {
  10. return (size_t) ((int) strlen(s) + (int) a + i);
  11. }
  12. int main (void)
  13. {
  14. ffi_cif cif;
  15. ffi_type *args[MAX_ARGS];
  16. void *values[MAX_ARGS];
  17. ffi_arg rint;
  18. char *s;
  19. int v1;
  20. float v2;
  21. args[2] = &ffi_type_sint;
  22. args[1] = &ffi_type_pointer;
  23. args[0] = &ffi_type_float;
  24. values[2] = (void*) &v1;
  25. values[1] = (void*) &s;
  26. values[0] = (void*) &v2;
  27. /* Initialize the cif */
  28. CHECK(ffi_prep_cif(&cif, ABI_NUM, 3,
  29. &ffi_type_sint, args) == FFI_OK);
  30. s = "a";
  31. v1 = 1;
  32. v2 = 0.0;
  33. ffi_call(&cif, FFI_FN(my_f), &rint, values);
  34. CHECK(rint == 2);
  35. s = "1234567";
  36. v2 = -1.0;
  37. v1 = -2;
  38. ffi_call(&cif, FFI_FN(my_f), &rint, values);
  39. CHECK(rint == 4);
  40. s = "1234567890123456789012345";
  41. v2 = 1.0;
  42. v1 = 2;
  43. ffi_call(&cif, FFI_FN(my_f), &rint, values);
  44. CHECK(rint == 28);
  45. exit(0);
  46. }