[MLton-commit] r4648

Matthew Fluet MLton@mlton.org
Mon, 12 Jun 2006 09:50:59 -0700


Have GC_saveWorld return a boolean indicating whether or not it
succeeded; this seems more natural than returning a boolean indicating
whether or not it failed.

Properly leave the runtime on error paths.

Naming of world.{h,c} functions.


----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc.h

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml	2006-06-12 16:25:12 UTC (rev 4647)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml	2006-06-12 16:50:57 UTC (rev 4648)
@@ -24,7 +24,7 @@
          let
             val () = 
                SysCall.simple' 
-               ({errVal = true}, 
+               ({errVal = false}, 
                 fn () => Prim.save (NullString.nullTerm file))
          in
             if Prim.getAmOriginal gcState

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c	2006-06-12 16:25:12 UTC (rev 4647)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.c	2006-06-12 16:50:57 UTC (rev 4648)
@@ -6,12 +6,12 @@
  * See the file MLton-LICENSE for details.
  */
 
-void loadWorldFromFD (GC_state s, FILE *f) {
+void loadWorldFromFILE (GC_state s, FILE *f) {
   uint32_t magic;
   pointer start;
         
   if (DEBUG_WORLD)
-    fprintf (stderr, "loadWorldFromFD\n");
+    fprintf (stderr, "loadWorldFromFILE\n");
   until (readChar (f) == '\000') ;
   magic = readUint32 (f);
   unless (s->magic == magic)
@@ -44,14 +44,14 @@
   if (DEBUG_WORLD)
     fprintf (stderr, "loadWorldFromFileName (%s)\n", fileName);
   f = fopen_safe (fileName, "rb");
-  loadWorldFromFD (s, f);
+  loadWorldFromFILE (s, f);
   fclose_safe (f); 
 }
 
 /* Don't use 'safe' functions, because we don't want the ML program to die.
  * Instead, check return values, and propogate them up to SML for an exception.
  */
-int saveWorldToFD (GC_state s, FILE *f) {
+int saveWorldToFILE (GC_state s, FILE *f) {
   char buf[80];
   size_t len;
 
@@ -86,18 +86,24 @@
   return 0;
 }
 
-uint32_t GC_saveWorld (GC_state s, NullString8_t fileName) {
+C_Errno_t(Bool_t) GC_saveWorld (GC_state s, NullString8_t fileName) {
   FILE *f;
   
   enter (s);
-  f = fopen((const char*)fileName, "wb");
-  if (0 == f) {
+  f = fopen ((const char*)fileName, "wb");
+  if (f == 0) {
     leave (s);
-    return 1;
+    return (Bool_t)FALSE;
   }
-  if (saveWorldToFD (s, f) != 0) return 1;
-  if (fclose (f) != 0) return 1;
+  if (saveWorldToFILE (s, f) != 0) {
+    leave (s);
+    return (Bool_t)FALSE;
+  }
+  if (fclose (f) != 0) {
+    leave (s);
+    return (Bool_t)FALSE;
+  }
+  
   leave (s);
-  
-  return 0;
+  return (Bool_t)TRUE;
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.h	2006-06-12 16:25:12 UTC (rev 4647)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/world.h	2006-06-12 16:50:57 UTC (rev 4648)
@@ -8,15 +8,15 @@
 
 #if (defined (MLTON_GC_INTERNAL_FUNCS))
 
-static void loadWorldFromFD (GC_state s, FILE *f);
+static void loadWorldFromFILE (GC_state s, FILE *f);
 static void loadWorldFromFileName (GC_state s, const char *fileName);
-static int saveWorldToFD (GC_state s, FILE *f);
+static int saveWorldToFILE (GC_state s, FILE *f);
 
 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */
 
 #if (defined (MLTON_GC_INTERNAL_BASIS))
 
-/* 0 = success, 1 = failure (a bool) */
-uint32_t GC_saveWorld (GC_state s, NullString8_t fileName);
+/* TRUE = success, FALSE = failure */
+C_Errno_t(Bool_t) GC_saveWorld (GC_state s, NullString8_t fileName);
 
 #endif /* (defined (MLTON_GC_INTERNAL_BASIS)) */

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc.h	2006-06-12 16:25:12 UTC (rev 4647)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc.h	2006-06-12 16:50:57 UTC (rev 4648)
@@ -12,6 +12,7 @@
 #include "cenv.h"
 #include "util.h"
 #include "ml-types.h"
+#include "c-types.h"
 
 #include "gc/debug.h"