[project @ 2005-01-21 16:02:47 by simonmar]
authorsimonmar <unknown>
Fri, 21 Jan 2005 16:02:58 +0000 (16:02 +0000)
committersimonmar <unknown>
Fri, 21 Jan 2005 16:02:58 +0000 (16:02 +0000)
Don't try to run finalizers at program exit.  This turned out to be
hard if not impossible to do in general, so now we don't attempt it at
all.

The Main.main wrapper, previously called runIO and now called
runMainIO, flushes stdout and stderr before exiting.  This should
catch most cases where programs rely on Handles being flushed at
program exit, but note that now if you simply drop a Handle in your
program, there's no guarantee it'll be flushed on exit.  If the
punters complain enough, I suppose we could implement a global
Handle table and flush them all at exit... I'd rather not do this if
possible, though.  Better to teach people to close their Handles
properly.

ghc/compiler/prelude/PrelNames.lhs
ghc/compiler/typecheck/TcRnDriver.lhs
ghc/rts/RtsStartup.c
ghc/rts/Weak.c
ghc/rts/Weak.h

index a180e61..2be6f8a 100644 (file)
@@ -107,7 +107,7 @@ basicKnownKeyNames
  ++ typeableClassNames
  ++ [  -- Type constructors (synonyms especially)
        ioTyConName, ioDataConName,
-       runIOName,
+       runMainIOName,
        orderingTyConName,
        rationalTyConName,
        ratioDataConName,
@@ -425,8 +425,8 @@ and it's convenient to write them all down in one place.
 
 
 \begin{code}
-rootMainName = varQual rOOT_MAIN FSLIT("main") rootMainKey
-runIOName    = varQual pREL_TOP_HANDLER FSLIT("runIO") runMainKey
+rootMainName  = varQual rOOT_MAIN FSLIT("main") rootMainKey
+runMainIOName = varQual pREL_TOP_HANDLER FSLIT("runMainIO") runMainKey
 
 orderingTyConName = tcQual   pREL_BASE FSLIT("Ordering") orderingTyConKey
 
index cda838a..58fdf90 100644 (file)
@@ -28,7 +28,7 @@ import HsSyn          ( HsModule(..), HsExtCore(..), HsGroup(..), LHsDecl, SpliceDecl(..
                          nlHsApp, nlHsVar, pprLHsBinds )
 import RdrHsSyn                ( findSplice )
 
-import PrelNames       ( runIOName, rootMainName, mAIN,
+import PrelNames       ( runMainIOName, rootMainName, mAIN,
                          main_RDR_Unqual )
 import RdrName         ( RdrName, mkRdrUnqual, emptyGlobalRdrEnv, 
                          plusGlobalRdrEnv )
@@ -668,8 +668,8 @@ check_main ghci_mode tcg_env main_mod main_fn
             Nothing -> do { complain_no_main   
                           ; return tcg_env } ;
             Just main_name -> do
-       { let { rhs = nlHsApp (nlHsVar runIOName) (nlHsVar main_name) }
-                       -- :Main.main :: IO () = runIO main 
+       { let { rhs = nlHsApp (nlHsVar runMainIOName) (nlHsVar main_name) }
+                       -- :Main.main :: IO () = runMainIO main 
 
        ; (main_expr, ty) <- setSrcSpan (srcLocSpan (getSrcLoc main_name)) $
                             tcInferRho rhs
index 3b6f050..69ae227 100644 (file)
@@ -360,11 +360,6 @@ hs_exit(void)
     /* start timing the shutdown */
     stat_startExit();
     
-#if !defined(GRAN)
-    /* Finalize any remaining weak pointers */
-    finalizeWeakPointersNow();
-#endif
-    
     /* stop all running tasks */
     exitScheduler();
     
index 787c9e4..c6c0e43 100644 (file)
 StgWeak *weak_ptr_list;
 
 /*
- * finalizeWeakPointersNow() is called just before the system is shut
- * down.  It runs the finalizer for each weak pointer still in the
- * system.
- *
- * Careful here - rts_evalIO might cause a garbage collection, which
- * might change weak_ptr_list.  Must re-load weak_ptr_list each time
- * around the loop.
- */
-
-void
-finalizeWeakPointersNow(void)
-{
-  StgWeak *w;
-  
-  rts_lock();
-  while ((w = weak_ptr_list)) {
-    weak_ptr_list = w->link;
-    if (w->header.info != &stg_DEAD_WEAK_info) {
-       SET_HDR(w, &stg_DEAD_WEAK_info, w->header.prof.ccs);
-       IF_DEBUG(weak,debugBelch("Finalising weak pointer at %p -> %p\n", w, w->key));
-       if (w->finalizer != &stg_NO_FINALIZER_closure) {
-           rts_evalLazyIO(w->finalizer,NULL);
-           rts_unlock();
-           rts_lock();
-       }
-    }
-  }
-  rts_unlock();
-} 
-
-/*
  * scheduleFinalizers() is called on the list of weak pointers found
  * to be dead after a garbage collection.  It overwrites each object
  * with DEAD_WEAK, and creates a new thread to run the pending finalizers.
index 1cdb4d7..29bf356 100644 (file)
@@ -1,6 +1,6 @@
 /* -----------------------------------------------------------------------------
  *
- * (c) The GHC Team, 1998-2004
+ * (c) The GHC Team, 1998-2005
  *
  * Weak pointers / finalizers
  *
@@ -9,7 +9,6 @@
 #ifndef WEAK_H
 #define WEAK_H
 
-void finalizeWeakPointersNow(void);
 void scheduleFinalizers(StgWeak *w);
 void markWeakList(void);