1 /* -----------------------------------------------------------------------------
2 * $Id: Stable.h,v 1.10 2001/11/21 10:09:15 simonmar Exp $
4 * (c) The GHC Team, 1998-2000
6 * Stable Pointers: A stable pointer is represented as an index into
7 * the stable pointer table in the low BITS_PER_WORD-8 bits with a
8 * weight in the upper 8 bits.
10 * SUP: StgStablePtr used to be a synonym for StgWord, but stable pointers
11 * are guaranteed to be void* on the C-side, so we have to do some occasional
12 * casting. Size is not a matter, because StgWord is always the same size as
15 * ----------------------------------------------------------------------------*/
17 /* -----------------------------------------------------------------------------
19 -------------------------------------------------------------------------- */
21 extern StgPtr deRefStablePtr(StgStablePtr stable_ptr);
22 extern void freeStablePtr(StgStablePtr sp);
23 extern StgStablePtr splitStablePtr(StgStablePtr sp);
24 extern StgStablePtr getStablePtr(StgPtr p);
26 /* -----------------------------------------------------------------------------
28 -------------------------------------------------------------------------- */
31 StgPtr addr; /* Haskell object, free list, or NULL */
32 StgPtr old; /* old Haskell object, used during GC */
33 StgWord ref; /* used for reference counting */
34 StgClosure *sn_obj; /* the StableName object (or NULL) */
37 extern DLL_IMPORT_RTS snEntry *stable_ptr_table;
38 extern DLL_IMPORT_RTS snEntry *stable_ptr_free;
40 extern DLL_IMPORT_RTS unsigned int SPT_size;
43 deRefStablePtr(StgStablePtr sp)
45 ASSERT(stable_ptr_table[(StgWord)sp].ref > 0);
46 return stable_ptr_table[(StgWord)sp].addr;
50 freeStablePtr(StgStablePtr sp)
52 StgWord sn = (StgWord)sp;
55 && stable_ptr_table[sn].addr != NULL
56 && stable_ptr_table[sn].ref > 0);
58 stable_ptr_table[sn].ref --;
61 extern inline StgStablePtr
62 splitStablePtr(StgStablePtr sp)
64 stable_ptr_table[(StgWord)sp].ref ++;
68 /* No deRefStableName, because the existence of a stable name doesn't
69 * guarantee the existence of the object itself.