strlen2.c 987 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(char *s, float a)
  9. {
  10. return (size_t) ((int) strlen(s) + (int) a);
  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. float v2;
  20. args[0] = &ffi_type_pointer;
  21. args[1] = &ffi_type_float;
  22. values[0] = (void*) &s;
  23. values[1] = (void*) &v2;
  24. /* Initialize the cif */
  25. CHECK(ffi_prep_cif(&cif, ABI_NUM, 2,
  26. &ffi_type_sint, args) == FFI_OK);
  27. s = "a";
  28. v2 = 0.0;
  29. ffi_call(&cif, FFI_FN(my_f), &rint, values);
  30. CHECK(rint == 1);
  31. s = "1234567";
  32. v2 = -1.0;
  33. ffi_call(&cif, FFI_FN(my_f), &rint, values);
  34. CHECK(rint == 6);
  35. s = "1234567890123456789012345";
  36. v2 = 1.0;
  37. ffi_call(&cif, FFI_FN(my_f), &rint, values);
  38. CHECK(rint == 26);
  39. exit(0);
  40. }