allow NUL characters in ML string passed to C library;
authorwenzelm
Mon, 26 Aug 2013 21:53:56 +0200
changeset 53211 753b9fbe18be
parent 53210 7219c61796c0
child 53212 387b9f7cb0ac
allow NUL characters in ML string passed to C library;
src/Pure/General/sha1_polyml.ML
--- a/src/Pure/General/sha1_polyml.ML	Mon Aug 26 18:08:54 2013 +0200
+++ b/src/Pure/General/sha1_polyml.ML	Mon Aug 26 21:53:56 2013 +0200
@@ -21,12 +21,16 @@
   ("$ML_HOME/" ^ (if ML_System.platform_is_cygwin then "sha1.dll" else "libsha1.so"))
   |> Path.explode;
 
+val STRING_INPUT_BYTES =
+  CInterface.mkConversion undefined (CInterface.toCbytes o Byte.stringToBytes)
+    (CInterface.Cpointer CInterface.Cchar);
+
 fun digest_external str =
   let
     val digest = CInterface.alloc 20 CInterface.Cchar;
     val _ =
       CInterface.call3 (CInterface.get_sym (File.platform_path lib_path) "sha1_buffer")
-        (CInterface.STRING, CInterface.LONG, CInterface.POINTER)
+        (STRING_INPUT_BYTES, CInterface.LONG, CInterface.POINTER)
         CInterface.POINTER (str, size str, CInterface.address digest);
   in fold (suffix o hex_string digest) (0 upto 19) "" end;