Commit 41737f12 authored by Simon Marlow's avatar Simon Marlow
Browse files

Deprecate lnat, and use StgWord instead

lnat was originally "long unsigned int" but we were using it when we
wanted a 64-bit type on a 64-bit machine.  This broke on Windows x64,
where long == int == 32 bits.  Using types of unspecified size is bad,
but what we really wanted was a type with N bits on an N-bit machine.
StgWord is exactly that.

lnat was mentioned in some APIs that clients might be using
(e.g. StackOverflowHook()), so we leave it defined but with a comment
to say that it's deprecated.
parent a8179622
......@@ -40,7 +40,7 @@ defaultsHook (void)
}
void
StackOverflowHook (lnat stack_size) /* in bytes */
StackOverflowHook (StgWord stack_size) /* in bytes */
{
fprintf(stderr, "GHC stack-space overflow: current limit is %zu bytes.\nUse the `-K<size>' option to increase it.\n", (size_t)stack_size);
}
......
......@@ -225,7 +225,7 @@ main(int argc, char *argv[])
printf("#define BLOCK_SIZE %u\n", BLOCK_SIZE);
printf("#define MBLOCK_SIZE %u\n", MBLOCK_SIZE);
printf("#define BLOCKS_PER_MBLOCK %" FMT_SizeT "\n", (lnat)BLOCKS_PER_MBLOCK);
printf("#define BLOCKS_PER_MBLOCK %" FMT_SizeT "\n", (W_)BLOCKS_PER_MBLOCK);
// could be derived, but better to save doing the calculation twice
printf("\n\n");
......
......@@ -18,9 +18,9 @@ extern char *ghc_rts_opts;
extern void OnExitHook (void);
extern int NoRunnableThreadsHook (void);
extern void StackOverflowHook (lnat stack_size);
extern void OutOfHeapHook (lnat request_size, lnat heap_size);
extern void MallocFailHook (lnat request_size /* in bytes */, char *msg);
extern void StackOverflowHook (W_ stack_size);
extern void OutOfHeapHook (W_ request_size, W_ heap_size);
extern void MallocFailHook (W_ request_size /* in bytes */, char *msg);
extern void defaultsHook (void);
#endif /* RTS_HOOKS_H */
......@@ -34,7 +34,7 @@ typedef struct SpinLock_
typedef StgWord SpinLock;
#endif
typedef lnat SpinLockCount;
typedef StgWord SpinLockCount;
#if defined(PROF_SPIN)
......
......@@ -16,8 +16,10 @@
#include <stddef.h>
typedef unsigned int nat; /* at least 32 bits (like int) */
typedef size_t lnat; /* at least 32 bits */
typedef unsigned int nat; /* at least 32 bits (like int) */
// Deprecated; just use StgWord instead
typedef StgWord lnat;
/* ullong (64|128-bit) type: only include if needed (not ANSI) */
#if defined(__GNUC__)
......
......@@ -429,20 +429,20 @@ EXTERN_INLINE StgWord stack_frame_sizeW( StgClosure *frame )
-------------------------------------------------------------------------- */
// The number of card bytes needed
INLINE_HEADER lnat mutArrPtrsCards (lnat elems)
INLINE_HEADER W_ mutArrPtrsCards (W_ elems)
{
return (lnat)((elems + (1 << MUT_ARR_PTRS_CARD_BITS) - 1)
return (W_)((elems + (1 << MUT_ARR_PTRS_CARD_BITS) - 1)
>> MUT_ARR_PTRS_CARD_BITS);
}
// The number of words in the card table
INLINE_HEADER lnat mutArrPtrsCardTableSize (lnat elems)
INLINE_HEADER W_ mutArrPtrsCardTableSize (W_ elems)
{
return ROUNDUP_BYTES_TO_WDS(mutArrPtrsCards(elems));
}
// The address of the card for a particular card number
INLINE_HEADER StgWord8 *mutArrPtrsCard (StgMutArrPtrs *a, lnat n)
INLINE_HEADER StgWord8 *mutArrPtrsCard (StgMutArrPtrs *a, W_ n)
{
return ((StgWord8 *)&(a->payload[a->ptrs]) + n);
}
......
......@@ -149,8 +149,8 @@ extern generation * oldest_gen;
-------------------------------------------------------------------------- */
StgPtr allocate ( Capability *cap, lnat n );
StgPtr allocatePinned ( Capability *cap, lnat n );
StgPtr allocate ( Capability *cap, W_ n );
StgPtr allocatePinned ( Capability *cap, W_ n );
/* memory allocator for executable memory */
void * allocateExec(unsigned int len, void **exec_addr);
......
......@@ -12,8 +12,8 @@
#ifndef RTS_STORAGE_MBLOCK_H
#define RTS_STORAGE_MBLOCK_H
extern lnat peak_mblocks_allocated;
extern lnat mblocks_allocated;
extern W_ peak_mblocks_allocated;
extern W_ mblocks_allocated;
extern void initMBlocks(void);
extern void * getMBlock(void);
......@@ -156,7 +156,7 @@ typedef struct {
MBlockMapLine lines[MBLOCK_MAP_ENTRIES];
} MBlockMap;
extern lnat mpc_misses;
extern W_ mpc_misses;
StgBool HEAP_ALLOCED_miss(StgWord mblock, void *p);
......
......@@ -80,7 +80,7 @@ arenaAlloc( Arena *arena, size_t size )
return p;
} else {
// allocate a fresh block...
req_blocks = (lnat)BLOCK_ROUND_UP(size) / BLOCK_SIZE;
req_blocks = (W_)BLOCK_ROUND_UP(size) / BLOCK_SIZE;
bd = allocGroup_lock(req_blocks);
arena_blocks += req_blocks;
......
......@@ -123,7 +123,7 @@ struct Capability_ {
SparkCounters spark_stats;
#endif
// Total words allocated by this cap since rts start
lnat total_allocated;
W_ total_allocated;
// Per-capability STM-related data
StgTVarWatchQueue *free_tvar_watch_queues;
......
......@@ -80,7 +80,7 @@ disInstr ( StgBCO *bco, int pc )
pc += 1; break;
case bci_STKCHECK: {
StgWord stk_words_reqd = BCO_GET_LARGE_ARG + 1;
debugBelch("STKCHECK %" FMT_SizeT "\n", (lnat)stk_words_reqd );
debugBelch("STKCHECK %" FMT_SizeT "\n", (W_)stk_words_reqd );
break;
}
case bci_PUSH_L:
......
......@@ -296,7 +296,7 @@ numLabel( GtkWidget *lbl, nat n )
}
void
updateFrontPanelAfterGC( nat N, lnat live )
updateFrontPanelAfterGC( nat N, W_ live )
{
char buf[1000];
......
......@@ -19,7 +19,7 @@
void initFrontPanel( void );
void stopFrontPanel( void );
void updateFrontPanelBeforeGC( nat N );
void updateFrontPanelAfterGC( nat N, lnat live );
void updateFrontPanelAfterGC( nat N, W_ live );
void updateFrontPanel( void );
......
......@@ -1900,7 +1900,7 @@ mmap_again:
MAP_PRIVATE|TRY_MAP_32BIT|fixed|flags, fd, 0);
if (result == MAP_FAILED) {
sysErrorBelch("mmap %" FMT_SizeT " bytes at %p",(lnat)size,map_addr);
sysErrorBelch("mmap %" FMT_SizeT " bytes at %p",(W_)size,map_addr);
errorBelch("Try specifying an address with +RTS -xm<addr> -RTS");
stg_exit(EXIT_FAILURE);
}
......@@ -1943,7 +1943,7 @@ mmap_again:
}
#endif
IF_DEBUG(linker, debugBelch("mmapForLinker: mapped %" FMT_SizeT " bytes starting at %p\n", (lnat)size, result));
IF_DEBUG(linker, debugBelch("mmapForLinker: mapped %" FMT_SizeT " bytes starting at %p\n", (W_)size, result));
IF_DEBUG(linker, debugBelch("mmapForLinker: done\n"));
return result;
}
......@@ -4937,7 +4937,7 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
default:
errorBelch("%s: unhandled ELF relocation(Rel) type %" FMT_SizeT "\n",
oc->fileName, (lnat)ELF_R_TYPE(info));
oc->fileName, (W_)ELF_R_TYPE(info));
return 0;
}
......@@ -5252,7 +5252,7 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC,
default:
errorBelch("%s: unhandled ELF relocation(RelA) type %" FMT_SizeT "\n",
oc->fileName, (lnat)ELF_R_TYPE(info));
oc->fileName, (W_)ELF_R_TYPE(info));
return 0;
}
......
......@@ -74,7 +74,7 @@ loop:
{
StgTSO *tso = ((MessageWakeup *)m)->tso;
debugTraceCap(DEBUG_sched, cap, "message: try wakeup thread %ld",
(lnat)tso->id);
(W_)tso->id);
tryWakeupThread(cap, tso);
}
else if (i == &stg_MSG_THROWTO_info)
......@@ -90,7 +90,7 @@ loop:
}
debugTraceCap(DEBUG_sched, cap, "message: throwTo %ld -> %ld",
(lnat)t->source->id, (lnat)t->target->id);
(W_)t->source->id, (W_)t->target->id);
ASSERT(t->source->why_blocked == BlockedOnMsgThrowTo);
ASSERT(t->source->block_info.closure == (StgClosure *)m);
......@@ -167,7 +167,7 @@ nat messageBlackHole(Capability *cap, MessageBlackHole *msg)
StgTSO *owner;
debugTraceCap(DEBUG_sched, cap, "message: thread %d blocking on blackhole %p",
(lnat)msg->tso->id, msg->bh);
(W_)msg->tso->id, msg->bh);
info = bh->header.info;
......@@ -256,7 +256,7 @@ loop:
recordClosureMutated(cap,bh); // bh was mutated
debugTraceCap(DEBUG_sched, cap, "thread %d blocked on thread %d",
(lnat)msg->tso->id, (lnat)owner->id);
(W_)msg->tso->id, (W_)owner->id);
return 1; // blocked
}
......@@ -289,7 +289,7 @@ loop:
}
debugTraceCap(DEBUG_sched, cap, "thread %d blocked on thread %d",
(lnat)msg->tso->id, (lnat)owner->id);
(W_)msg->tso->id, (W_)owner->id);
// See above, #3838
if (owner->why_blocked == NotBlocked && owner->id != msg->tso->id) {
......
......@@ -300,21 +300,21 @@ printClosure( StgClosure *obj )
StgWord i;
debugBelch("ARR_WORDS(\"");
for (i=0; i<arr_words_words((StgArrWords *)obj); i++)
debugBelch("%" FMT_SizeT, (lnat)((StgArrWords *)obj)->payload[i]);
debugBelch("%" FMT_SizeT, (W_)((StgArrWords *)obj)->payload[i]);
debugBelch("\")\n");
break;
}
case MUT_ARR_PTRS_CLEAN:
debugBelch("MUT_ARR_PTRS_CLEAN(size=%" FMT_SizeT ")\n", (lnat)((StgMutArrPtrs *)obj)->ptrs);
debugBelch("MUT_ARR_PTRS_CLEAN(size=%" FMT_SizeT ")\n", (W_)((StgMutArrPtrs *)obj)->ptrs);
break;
case MUT_ARR_PTRS_DIRTY:
debugBelch("MUT_ARR_PTRS_DIRTY(size=%" FMT_SizeT ")\n", (lnat)((StgMutArrPtrs *)obj)->ptrs);
debugBelch("MUT_ARR_PTRS_DIRTY(size=%" FMT_SizeT ")\n", (W_)((StgMutArrPtrs *)obj)->ptrs);
break;
case MUT_ARR_PTRS_FROZEN:
debugBelch("MUT_ARR_PTRS_FROZEN(size=%" FMT_SizeT ")\n", (lnat)((StgMutArrPtrs *)obj)->ptrs);
debugBelch("MUT_ARR_PTRS_FROZEN(size=%" FMT_SizeT ")\n", (W_)((StgMutArrPtrs *)obj)->ptrs);
break;
case MVAR_CLEAN:
......@@ -431,7 +431,7 @@ printSmallBitmap( StgPtr spBottom, StgPtr payload, StgWord bitmap, nat size )
printPtr((P_)payload[i]);
debugBelch("\n");
} else {
debugBelch("Word# %" FMT_SizeT "\n", (lnat)payload[i]);
debugBelch("Word# %" FMT_SizeT "\n", (W_)payload[i]);
}
}
}
......@@ -447,12 +447,12 @@ printLargeBitmap( StgPtr spBottom, StgPtr payload, StgLargeBitmap* large_bitmap,
StgWord bitmap = large_bitmap->bitmap[bmp];
j = 0;
for(; i < size && j < BITS_IN(W_); j++, i++, bitmap >>= 1 ) {
debugBelch(" stk[%" FMT_SizeT "] (%p) = ", (lnat)(spBottom-(payload+i)), payload+i);
debugBelch(" stk[%" FMT_SizeT "] (%p) = ", (W_)(spBottom-(payload+i)), payload+i);
if ((bitmap & 1) == 0) {
printPtr((P_)payload[i]);
debugBelch("\n");
} else {
debugBelch("Word# %" FMT_SizeT "\n", (lnat)payload[i]);
debugBelch("Word# %" FMT_SizeT "\n", (W_)payload[i]);
}
}
}
......
......@@ -821,7 +821,7 @@ dumpCensus( Census *census )
}
#endif
fprintf(hp_file, "\t%" FMT_SizeT "\n", (lnat)count * sizeof(W_));
fprintf(hp_file, "\t%" FMT_SizeT "\n", (W_)count * sizeof(W_));
}
printSample(rtsFalse, census->time);
......
......@@ -42,7 +42,7 @@ unsigned int CCS_ID = 1;
/* figures for the profiling report.
*/
static StgWord64 total_alloc;
static lnat total_prof_ticks;
static W_ total_prof_ticks;
/* Globals for opening the profiling log file(s)
*/
......
......@@ -271,11 +271,11 @@ isEmptyRetainerStack( void )
* Returns size of stack
* -------------------------------------------------------------------------- */
#ifdef DEBUG
lnat
W_
retainerStackBlocks( void )
{
bdescr* bd;
lnat res = 0;
W_ res = 0;
for (bd = firstStack; bd != NULL; bd = bd->link)
res += bd->blocks;
......
......@@ -43,7 +43,7 @@ retainerSetOf( StgClosure *c )
// Used by Storage.c:memInventory()
#ifdef DEBUG
extern lnat retainerStackBlocks ( void );
extern W_ retainerStackBlocks ( void );
#endif
#include "EndPrivate.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment