make exit() overridable, for use in DLLs
authorSimon Marlow <simonmar@microsoft.com>
Wed, 9 Aug 2006 09:24:39 +0000 (09:24 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Wed, 9 Aug 2006 09:24:39 +0000 (09:24 +0000)
See #753

includes/RtsAPI.h
rts/RtsStartup.c
rts/Storage.c

index a3a41f0..7d28328 100644 (file)
@@ -43,6 +43,8 @@ extern void shutdownHaskellAndExit ( int exitCode );
 extern void getProgArgv            ( int *argc, char **argv[] );
 extern void setProgArgv            ( int argc, char *argv[] );
 
 extern void getProgArgv            ( int *argc, char **argv[] );
 extern void setProgArgv            ( int argc, char *argv[] );
 
+/* exit() override */
+extern void (*exitFn)(int);
 
 /* ----------------------------------------------------------------------------
    Locking.
 
 /* ----------------------------------------------------------------------------
    Locking.
index 33c742b..3fef259 100644 (file)
@@ -459,6 +459,8 @@ shutdownHaskellAndExit(int n)
 static int exit_started=rtsFalse;
 #endif
 
 static int exit_started=rtsFalse;
 #endif
 
+void (*exitFn)(int) = 0;
+
 void  
 stg_exit(int n)
 { 
 void  
 stg_exit(int n)
 { 
@@ -471,5 +473,7 @@ stg_exit(int n)
   IF_PAR_DEBUG(verbose, debugBelch("==-- stg_exit %d on [%x]...", n, mytid));
   shutdownParallelSystem(n);
 #endif
   IF_PAR_DEBUG(verbose, debugBelch("==-- stg_exit %d on [%x]...", n, mytid));
   shutdownParallelSystem(n);
 #endif
+  if (exitFn)
+    (*exitFn)(n);
   exit(n);
 }
   exit(n);
 }
index d3b0597..3594f71 100644 (file)
@@ -127,7 +127,7 @@ initStorage( void )
       RtsFlags.GcFlags.minAllocAreaSize > 
       RtsFlags.GcFlags.maxHeapSize) {
       errorBelch("maximum heap size (-M) is smaller than minimum alloc area size (-A)");
       RtsFlags.GcFlags.minAllocAreaSize > 
       RtsFlags.GcFlags.maxHeapSize) {
       errorBelch("maximum heap size (-M) is smaller than minimum alloc area size (-A)");
-      exit(1);
+      RtsFlags.GcFlags.minAllocAreaSize = RtsFlags.GcFlags.maxHeapSize;
   }
 
   initBlockAllocator();
   }
 
   initBlockAllocator();