Make a function for get_itbl, rather than using a CPP macro
authorIan Lynagh <ian@well-typed.com>
Sat, 25 Aug 2012 10:31:50 +0000 (11:31 +0100)
committerIan Lynagh <ian@well-typed.com>
Sat, 25 Aug 2012 10:31:50 +0000 (11:31 +0100)
This has several advantages:
* It can be called from gdb
* There is more type information for the user, and type checking
  for the compiler
* Less opportunity for things to go wrong, e.g. due to missing
  parentheses or repeated execution

The sizes of the non-debug .o files hasn't changed (other than
Inlines.o), so I'm pretty sure the compiled code is identical.

includes/rts/storage/ClosureMacros.h
rts/Printer.c
rts/RaiseAsync.c
rts/sm/MarkWeak.c
rts/sm/Sanity.c

index 122f446..4442838 100644 (file)
 #define GET_INFO(c)   ((c)->header.info)
 #define GET_ENTRY(c)  (ENTRY_CODE(GET_INFO(c)))
 
-#define get_itbl(c)   (INFO_PTR_TO_STRUCT((c)->header.info))
-#define get_ret_itbl(c) (RET_INFO_PTR_TO_STRUCT((c)->header.info))
-#define get_fun_itbl(c) (FUN_INFO_PTR_TO_STRUCT((c)->header.info))
-#define get_thunk_itbl(c) (THUNK_INFO_PTR_TO_STRUCT((c)->header.info))
-#define get_con_itbl(c) (CON_INFO_PTR_TO_STRUCT((c)->header.info))
-
 #define GET_TAG(con) (get_itbl(con)->srt_bitmap)
 
 #ifdef TABLES_NEXT_TO_CODE
 #define itbl_to_con_itbl(i) ((StgConInfoTable *)(i))
 #endif
 
+EXTERN_INLINE StgInfoTable *get_itbl(StgClosure *c);
+EXTERN_INLINE StgInfoTable *get_itbl(StgClosure *c) {return INFO_PTR_TO_STRUCT(c->header.info);}
+#define get_ret_itbl(c) (RET_INFO_PTR_TO_STRUCT((c)->header.info))
+#define get_fun_itbl(c) (FUN_INFO_PTR_TO_STRUCT((c)->header.info))
+#define get_thunk_itbl(c) (THUNK_INFO_PTR_TO_STRUCT((c)->header.info))
+#define get_con_itbl(c) (CON_INFO_PTR_TO_STRUCT((c)->header.info))
+
 /* -----------------------------------------------------------------------------
    Macros for building closures
    -------------------------------------------------------------------------- */
index a7ce367..737fba4 100644 (file)
@@ -91,7 +91,7 @@ printThunkPayload( StgThunk *obj )
     StgWord i, j;
     const StgInfoTable* info;
 
-    info = get_itbl(obj);
+    info = get_itbl((StgClosure *)obj);
     for (i = 0; i < info->layout.payload.ptrs; ++i) {
         debugBelch(", ");
         printPtr((StgPtr)obj->payload[i]);
index 9e5a8c3..47d8806 100644 (file)
@@ -306,7 +306,7 @@ check_target:
 
        // ASSUMPTION: tso->block_info must always point to a
        // closure.  In the threaded RTS it does.
-        switch (get_itbl(mvar)->type) {
+        switch (get_itbl((StgClosure *)mvar)->type) {
         case MVAR_CLEAN:
         case MVAR_DIRTY:
             break;
index b7d6226..d57f7a0 100644 (file)
@@ -127,7 +127,7 @@ traverseWeakPtrList(void)
              continue;
          }
          
-          info = get_itbl(w);
+          info = get_itbl((StgClosure *)w);
          switch (info->type) {
 
          case WEAK:
@@ -269,7 +269,7 @@ static rtsBool tidyThreadList (generation *gen)
             t = tmp;
         }
         
-        ASSERT(get_itbl(t)->type == TSO);
+        ASSERT(get_itbl((StgClosure *)t)->type == TSO);
         next = t->global_link;
         
         // if the thread is not masking exceptions but there are
index 9a22dcb..99cea93 100644 (file)
@@ -328,12 +328,12 @@ checkClosure( StgClosure* p )
         // ASSERT(get_itbl(bq->bh)->type == BLACKHOLE);
         ASSERT(LOOKS_LIKE_CLOSURE_PTR(bq->bh));
 
-        ASSERT(get_itbl(bq->owner)->type == TSO);
+        ASSERT(get_itbl((StgClosure *)(bq->owner))->type == TSO);
         ASSERT(bq->queue == (MessageBlackHole*)END_TSO_QUEUE 
                || bq->queue->header.info == &stg_MSG_BLACKHOLE_info);
         ASSERT(bq->link == (StgBlockingQueue*)END_TSO_QUEUE || 
-               get_itbl(bq->link)->type == IND ||
-               get_itbl(bq->link)->type == BLOCKING_QUEUE);
+               get_itbl((StgClosure *)(bq->link))->type == IND ||
+               get_itbl((StgClosure *)(bq->link))->type == BLOCKING_QUEUE);
 
         return sizeofW(StgBlockingQueue);
     }
@@ -567,7 +567,7 @@ checkGlobalTSOList (rtsBool checkTSOs)
       for (tso=generations[g].threads; tso != END_TSO_QUEUE; 
            tso = tso->global_link) {
           ASSERT(LOOKS_LIKE_CLOSURE_PTR(tso));
-          ASSERT(get_itbl(tso)->type == TSO);
+          ASSERT(get_itbl((StgClosure *)tso)->type == TSO);
           if (checkTSOs)
               checkTSO(tso);