29 lines
1.3 KiB
Plaintext
29 lines
1.3 KiB
Plaintext
;;;; A string with a NUL in it, handed to C.
|
|
;;;;
|
|
;;;; A Flan string is ptr+len and a C string ends at its first NUL, so the two
|
|
;;;; disagree about what the value *is* the moment one of those bytes is in the
|
|
;;;; middle. The generated shim copies and terminates — string-of-bytes.flan
|
|
;;;; pins that — and a copy of these bytes is a C string of length 1 where the
|
|
;;;; program passed 5. The function would then act on a value nobody wrote.
|
|
;;;;
|
|
;;;; flan_path_cstr has always refused this for a path, on the grounds that the
|
|
;;;; file opened would not be the file named. Nothing about a path is special:
|
|
;;;; the same reasoning covers a window title, a shader name and a query, so
|
|
;;;; the shim refuses it too, naming the declare-c that was called. It is a
|
|
;;;; trap rather than a condition because a foreign call has no allocation site
|
|
;;;; for the compiler to guard and no transfer channel of its own.
|
|
(declare-c c-puts [s str] i32 "puts")
|
|
|
|
(defn main [] i32
|
|
(let [v (vec-new u8)]
|
|
(push v 104) ; h
|
|
(push v 105) ; i
|
|
(push v 0)
|
|
(push v 104) ; h
|
|
(push v 105) ; i
|
|
(println "before")
|
|
(c-puts (str (slice v)))
|
|
(println "unreachable")
|
|
(free v))
|
|
0)
|