[project @ 2002-11-11 11:04:10 by simonpj]
[ghc-hetmet.git] / ghc / rts / Stable.c
index 0232e18..7bfd15e 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stable.c,v 1.19 2001/12/20 16:12:09 sewardj Exp $
+ * $Id: Stable.c,v 1.22 2002/08/16 13:29:07 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -88,9 +88,9 @@
 */
 
 snEntry *stable_ptr_table;
-snEntry *stable_ptr_free;
+static snEntry *stable_ptr_free;
 
-unsigned int SPT_size;
+static unsigned int SPT_size;
 
 /* This hash table maps Haskell objects to stable names, so that every
  * call to lookupStableName on a given object will return the same
@@ -125,7 +125,7 @@ unsigned int SPT_size;
  * to the weight stored in the table entry.
  * */
 
-HashTable *addrToStableHash;
+static HashTable *addrToStableHash;
 
 #define INIT_SPT_SIZE 64
 
@@ -236,13 +236,18 @@ getStablePtr(StgPtr p)
 void
 freeStablePtr(StgStablePtr sp)
 {
-    StgWord sn = (StgWord)sp;
+    snEntry *sn = &stable_ptr_table[(StgWord)sp];
     
-    ASSERT(sn < SPT_size
-          && stable_ptr_table[sn].addr != NULL
-          && stable_ptr_table[sn].ref > 0);
-    
-    stable_ptr_table[sn].ref --;
+    ASSERT((StgWord)sp < SPT_size  &&  sn->addr != NULL  &&  sn->ref > 0);
+
+    sn->ref--;
+
+    // If this entry has no StableName attached, then just free it
+    // immediately.  This is important; it might be a while before the
+    // next major GC which actually collects the entry.
+    if (sn->sn_obj == NULL && sn->ref == 0) {
+       freeStableName(sn);
+    }
 }
 
 void