[commit: ghc] master: Check for a weak pointer being dead before we do any allocation for it (6770663)

Ian Lynagh igloo at earth.li
Sat Jun 15 18:33:09 CEST 2013


Repository : http://darcs.haskell.org/ghc.git/

On branch  : master

https://github.com/ghc/ghc/commit/6770663f764db76dbb7138ccb3aea0527d194151

>---------------------------------------------------------------

commit 6770663f764db76dbb7138ccb3aea0527d194151
Author: Ian Lynagh <ian at well-typed.com>
Date:   Sat Jun 15 16:36:29 2013 +0100

    Check for a weak pointer being dead before we do any allocation for it

>---------------------------------------------------------------

 rts/PrimOps.cmm | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
index 8d2bc2f..b44dfe7 100644
--- a/rts/PrimOps.cmm
+++ b/rts/PrimOps.cmm
@@ -404,6 +404,14 @@ stg_addCFinalizzerToWeakzh ( W_ fptr,   // finalizer
 {
   W_ c, info;
 
+  ("ptr" info) = ccall lockClosure(w "ptr");
+
+  if (info == stg_DEAD_WEAK_info) {
+    // Already dead.
+    unlockClosure(w, info);
+    return (0);
+  }
+
   ALLOC_PRIM (SIZEOF_StgCFinalizerList)
 
   c = Hp - SIZEOF_StgCFinalizerList + WDS(1);
@@ -414,14 +422,6 @@ stg_addCFinalizzerToWeakzh ( W_ fptr,   // finalizer
   StgCFinalizerList_eptr(c) = eptr;
   StgCFinalizerList_flag(c) = flag;
 
-  ("ptr" info) = ccall lockClosure(w "ptr");
-
-  if (info == stg_DEAD_WEAK_info) {
-    // Already dead.
-    unlockClosure(w, info);
-    return (0);
-  }
-
   StgCFinalizerList_link(c) = StgWeak_cfinalizers(w);
   StgWeak_cfinalizers(w) = c;
 





More information about the ghc-commits mailing list