[project @ 2005-05-27 14:47:08 by tharris]
[ghc-hetmet.git] / ghc / rts / Stable.c
index c0520da..93b2246 100644 (file)
@@ -1,5 +1,4 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stable.c,v 1.28 2004/08/13 13:10:45 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2002
  *
@@ -14,6 +13,7 @@
 #include "Rts.h"
 #include "Hash.h"
 #include "RtsUtils.h"
+#include "OSThreads.h"
 #include "Storage.h"
 #include "RtsAPI.h"
 #include "RtsFlags.h"
@@ -137,6 +137,9 @@ initStablePtrTable(void)
     // Nothing to do:
     // the table will be allocated the first time makeStablePtr is
     // called, and we want the table to persist through multiple inits.
+    //
+    // Also, getStablePtr is now called from __attribute__((constructor))
+    // functions, so initialising things here wouldn't work anyway.
 }
 
 /*
@@ -164,6 +167,7 @@ StgWord
 lookupStableName(StgPtr p)
 {
   StgWord sn;
+  void* sn_tmp;
 
   if (stable_ptr_free == NULL) {
     enlargeStablePtrTable();
@@ -174,20 +178,20 @@ lookupStableName(StgPtr p)
    */
   p = (StgPtr)removeIndirections((StgClosure*)p);
 
-  (void *)sn = lookupHashTable(addrToStableHash,(W_)p);
+  sn_tmp = lookupHashTable(addrToStableHash,(W_)p);
+  sn = (StgWord)sn_tmp;
   
   if (sn != 0) {
     ASSERT(stable_ptr_table[sn].addr == p);
-    IF_DEBUG(stable,fprintf(stderr,"cached stable name %d at %p\n",sn,p));
+    IF_DEBUG(stable,debugBelch("cached stable name %ld at %p\n",sn,p));
     return sn;
   } else {
     sn = stable_ptr_free - stable_ptr_table;
-    (P_)stable_ptr_free  = stable_ptr_free->addr;
+    stable_ptr_free  = (snEntry*)(stable_ptr_free->addr);
     stable_ptr_table[sn].ref = 0;
     stable_ptr_table[sn].addr = p;
     stable_ptr_table[sn].sn_obj = NULL;
-    /* IF_DEBUG(stable,fprintf(stderr,"new stable name %d at
-       %p\n",sn,p)); */
+    /* IF_DEBUG(stable,debugBelch("new stable name %d at %p\n",sn,p)); */
     
     /* add the new stable name to the hash table */
     insertHashTable(addrToStableHash, (W_)p, (void *)sn);
@@ -372,13 +376,13 @@ gcStablePtrTable( void )
                if (p->sn_obj == NULL) {
                    // StableName object is dead
                    freeStableName(p);
-                   IF_DEBUG(stable, fprintf(stderr,"GC'd Stable name %d\n", 
-                                            p - stable_ptr_table));
+                   IF_DEBUG(stable, debugBelch("GC'd Stable name %d\n", 
+                                               p - stable_ptr_table));
                    continue;
                    
                } else {
-                   (StgClosure *)p->addr = isAlive((StgClosure *)p->addr);
-                   IF_DEBUG(stable, fprintf(stderr,"Stable name %d still alive at %p, ref %d\n", p - stable_ptr_table, p->addr, p->ref));
+                 p->addr = (StgPtr)isAlive((StgClosure *)p->addr);
+                   IF_DEBUG(stable, debugBelch("Stable name %d still alive at %p, ref %ld\n", p - stable_ptr_table, p->addr, p->ref));
                }
            }
        }