X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FStable.c;h=c0520dae68f48eed194261552c88aace7187067c;hb=423d477bfecd490de1449c59325c8776f91d7aac;hp=e9c61816a0f918fe206cedfd71aaad276e347447;hpb=b9dfc5ac41801325ddfddd7cf9c13b7b721a2a2f;p=ghc-hetmet.git diff --git a/ghc/rts/Stable.c b/ghc/rts/Stable.c index e9c6181..c0520da 100644 --- a/ghc/rts/Stable.c +++ b/ghc/rts/Stable.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Stable.c,v 1.24 2003/01/28 17:05:43 simonmar Exp $ + * $Id: Stable.c,v 1.28 2004/08/13 13:10:45 simonmar Exp $ * * (c) The GHC Team, 1998-2002 * @@ -13,7 +13,6 @@ #include "PosixSource.h" #include "Rts.h" #include "Hash.h" -#include "StablePriv.h" #include "RtsUtils.h" #include "Storage.h" #include "RtsAPI.h" @@ -73,21 +72,6 @@ There may be additional functions on the C side to allow evaluation, application, etc of a stable pointer. - When Haskell calls C, it normally just passes over primitive integers, - floats, bools, strings, etc. This doesn't cause any problems at all - for garbage collection because the act of passing them makes a copy - from the heap, stack or wherever they are onto the C-world stack. - However, if we were to pass a heap object such as a (Haskell) @String@ - and a garbage collection occured before we finished using it, we'd run - into problems since the heap object might have been moved or even - deleted. - - So, if a C call is able to cause a garbage collection or we want to - store a pointer to a heap object between C calls, we must be careful - when passing heap objects. Our solution is to keep a table of all - objects we've given to the C-world and to make sure that the garbage - collector collects these objects --- updating the table as required to - make sure we can still find the object. */ snEntry *stable_ptr_table = NULL; @@ -132,7 +116,7 @@ static HashTable *addrToStableHash = NULL; #define INIT_SPT_SIZE 64 -static inline void +STATIC_INLINE void initFreeList(snEntry *table, nat n, snEntry *free) { snEntry *p; @@ -212,7 +196,7 @@ lookupStableName(StgPtr p) } } -static inline void +STATIC_INLINE void freeStableName(snEntry *sn) { ASSERT(sn->sn_obj == NULL); @@ -258,8 +242,8 @@ enlargeStablePtrTable(void) if (SPT_size == 0) { // 1st time SPT_size = INIT_SPT_SIZE; - stable_ptr_table = stgMallocWords(SPT_size * sizeof(snEntry), - "initStablePtrTable"); + stable_ptr_table = stgMallocBytes(SPT_size * sizeof(snEntry), + "enlargeStablePtrTable"); /* we don't use index 0 in the stable name table, because that * would conflict with the hash table lookup operations which @@ -272,9 +256,10 @@ enlargeStablePtrTable(void) // 2nd and subsequent times SPT_size *= 2; stable_ptr_table = - stgReallocWords(stable_ptr_table, SPT_size * sizeof(snEntry), + stgReallocBytes(stable_ptr_table, + SPT_size * sizeof(snEntry), "enlargeStablePtrTable"); - + initFreeList(stable_ptr_table + old_SPT_size, old_SPT_size, NULL); } }