prefer static library_call, following recent changes to structure Foreign;
authorwenzelm
Sun, 01 Nov 2020 14:30:09 +0100
changeset 72534 e0c6522d5d43
parent 72533 63ec86626ec3
child 72535 7cb68b5b103d
prefer static library_call, following recent changes to structure Foreign;
src/Pure/General/sha1.ML
--- a/src/Pure/General/sha1.ML	Sun Nov 01 14:04:52 2020 +0100
+++ b/src/Pure/General/sha1.ML	Sun Nov 01 14:30:09 2020 +0100
@@ -148,6 +148,11 @@
 val library_path =
   Path.explode ("$ML_HOME/" ^ (if ML_System.platform_is_windows then "sha1.dll" else "libsha1.so"));
 
+val library_call =
+  Foreign.buildCall3
+    (Foreign.getSymbol (Foreign.loadLibrary (File.platform_path library_path)) "sha1_buffer",
+      (Foreign.cByteArray, Foreign.cUlong, Foreign.cPointer), Foreign.cPointer);
+
 fun with_memory n =
   Thread_Attributes.uninterruptible (fn restore_attributes => fn f =>
     let
@@ -166,12 +171,8 @@
 fun digest_string_external str =
   with_memory 20 (fn mem =>
     let
-      val library = Foreign.loadLibrary (File.platform_path library_path);
       val bytes = Byte.stringToBytes str;
-      val _ =
-        Foreign.buildCall3 (Foreign.getSymbol library "sha1_buffer",
-          (Foreign.cByteArray, Foreign.cUlong, Foreign.cPointer), Foreign.cPointer)
-          (bytes, Word8Vector.length bytes, mem);
+      val _ = library_call (bytes, Word8Vector.length bytes, mem);
       fun get i = hex_string (Foreign.Memory.get8 (mem, Word.fromInt i));
     in implode (map get (0 upto 19)) end);