[MLton-commit] r6766
Matthew Fluet
fluet at mlton.org
Tue Aug 19 15:16:15 PDT 2008
Restore use of nested indirect types in FFI for Basis Library implementation.
----------------------------------------------------------------------
U mlton/trunk/basis-library/util/CUtil.sig
U mlton/trunk/basis-library/util/CUtil.sml
----------------------------------------------------------------------
Modified: mlton/trunk/basis-library/util/CUtil.sig
===================================================================
--- mlton/trunk/basis-library/util/CUtil.sig 2008-08-19 22:16:10 UTC (rev 6765)
+++ mlton/trunk/basis-library/util/CUtil.sig 2008-08-19 22:16:14 UTC (rev 6766)
@@ -1,4 +1,4 @@
-(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+(* Copyright (C) 1999-2006, 2008 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
*
@@ -37,6 +37,7 @@
sig
type t = C_StringArray.t
+ val fromList: string list -> NullString.t array
(* extract first n strings from array *)
val toArrayOfLength: t * int -> string array
val toList: t -> string list
Modified: mlton/trunk/basis-library/util/CUtil.sml
===================================================================
--- mlton/trunk/basis-library/util/CUtil.sml 2008-08-19 22:16:10 UTC (rev 6765)
+++ mlton/trunk/basis-library/util/CUtil.sml 2008-08-19 22:16:14 UTC (rev 6766)
@@ -1,4 +1,4 @@
-(* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
+(* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
*
@@ -89,6 +89,23 @@
fun toArray css = toArrayOfLength (css, length css)
val toList = Array.toList o toArray
+
+ (* The C side converts the last element of the array, "",
+ * to the null terminator that C primitives expect.
+ * As far as C can tell, the other elements of the array
+ * are just char*'s.
+ *)
+ fun fromList l =
+ let
+ val a = Array.array (1 +? List.length l, NullString.empty)
+ val _ =
+ List.foldl (fn (s, i) =>
+ (Array.update (a, i, NullString.nullTerm s)
+ ; i +? 1))
+ 0 l
+ in
+ a
+ end
end
structure StringVector =
More information about the MLton-commit
mailing list