[MLton] mlton bug [String.fromCString ?]
Stephen Weeks
MLton@mlton.org
Thu, 28 Jul 2005 09:29:59 -0700
> fun fetchCString ptr =
> let
> fun loop (i, accum) =
> let
> val w = MLton.Pointer.getWord8 (ptr, i)
> in
> (* Search for explicit null termination. *)
> if w = 0wx0
> then String.implode (List.rev accum)
> else loop (i + 1, (Byte.byteToChar w) :: accum)
> end
> in
> loop (0, [])
> end
A minor point, but this can be done more efficiently with
----------------------------------------------------------------------
fun strlen p =
let
fun loop i =
if 0w0 = MLton.Pointer.getWord8 (p, i) then i else loop (i + 1)
in
loop 0
end
fun fetchCString p =
CharVector.tabulate (strlen p, fn i =>
Byte.byteToChar (MLton.Pointer.getWord8 (p, i)))
----------------------------------------------------------------------
> Also, funnyly, mlton rejects file names.sml on Solaris, in which it
> finds a syntax error ...
>
> I'm working with mlton-20041109.
This is not a Solaris issue; rather it is a mlton-20041109 issue. See
http://mlton.org/Bugs20041109#7
You must be using a newer version than 20041109 to get your program to
compile.