From 348e8f801ab659d84acfb49a5c7bbac63646e73a Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Wed, 14 Jan 2009 12:15:26 +0000 Subject: Detect when a C finalizer calls back to Haskell This is illegal now, after the fix for #1364, but it turns out that the existing check for dodgy callbacks doesn't catch finalizers calling back, so we need another test. This will be particularly important for 6.10.2, because the behaviour has changed. --- rts/Weak.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'rts/Weak.c') diff --git a/rts/Weak.c b/rts/Weak.c index a50a72e59c..17150f6b3c 100644 --- a/rts/Weak.c +++ b/rts/Weak.c @@ -22,6 +22,9 @@ StgWeak *weak_ptr_list; +// So that we can detect when a finalizer illegally calls back into Haskell +rtsBool running_finalizers = rtsFalse; + void runCFinalizer(StgVoid *fn, StgVoid *ptr, StgVoid *env, StgWord flag) { @@ -36,6 +39,8 @@ runAllCFinalizers(StgWeak *list) { StgWeak *w; + running_finalizers = rtsTrue; + for (w = list; w; w = w->link) { StgArrWords *farr; @@ -47,6 +52,8 @@ runAllCFinalizers(StgWeak *list) (StgVoid *)farr->payload[2], farr->payload[3]); } + + running_finalizers = rtsFalse; } /* @@ -72,6 +79,8 @@ scheduleFinalizers(Capability *cap, StgWeak *list) StgMutArrPtrs *arr; nat n; + running_finalizers = rtsTrue; + // count number of finalizers, and kill all the weak pointers first... n = 0; for (w = list; w; w = w->link) { @@ -105,6 +114,8 @@ scheduleFinalizers(Capability *cap, StgWeak *list) SET_HDR(w, &stg_DEAD_WEAK_info, w->header.prof.ccs); } + running_finalizers = rtsFalse; + // No finalizers to run? if (n == 0) return; -- cgit v1.2.1