t_cstring_prog.mod 903 B

1234567891011121314151617181920212223242526272829303132333435
  1. MODULE TCStringProg;
  2. (* C string boundary regression: an ARRAY OF CHAR actual must arrive at
  3. a foreign C procedure as a NUL-terminated char *, not as the V3
  4. descriptor address. Expected exit code: 42. *)
  5. FROM TCString IMPORT m2_c_strlen, m2_c_fill;
  6. VAR
  7. ExitCode : INTEGER;
  8. fixed : ARRAY [0..7] OF CHAR;
  9. raw : ARRAY [0..3] OF CHAR;
  10. out : ARRAY [0..7] OF CHAR;
  11. n : CARDINAL;
  12. PROCEDURE open_len (s : ARRAY OF CHAR) : CARDINAL;
  13. BEGIN
  14. RETURN m2_c_strlen(s)
  15. END open_len;
  16. BEGIN
  17. fixed := "hello";
  18. raw[0] := 'a'; raw[1] := 'b'; raw[2] := 'c'; raw[3] := 'd';
  19. n := m2_c_fill(out, 8, 'x');
  20. IF (m2_c_strlen("hello") = 5)
  21. AND (m2_c_strlen(fixed) = 5)
  22. AND (m2_c_strlen(raw) = 4)
  23. AND (open_len("world") = 5)
  24. AND (n = 7)
  25. AND (out[0] = 'x')
  26. AND (out[6] = 'x')
  27. AND (out[7] = CHR(0)) THEN
  28. ExitCode := 42
  29. ELSE
  30. ExitCode := 1
  31. END
  32. END TCStringProg.