Commit 3f205c43 authored by simonmar's avatar simonmar

[project @ 2005-01-21 16:02:47 by simonmar]

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.
parent 5fcb4668
......@@ -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
......
......@@ -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
......
......@@ -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();
......
......@@ -20,37 +20,6 @@
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
......
/* -----------------------------------------------------------------------------
*
* (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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment