diff -ruN klic-3.003-2002-03-04a/include/klic/g_extern.h klic-3.003-2002-03-05/include/klic/g_extern.h
--- klic-3.003-2002-03-04a/include/klic/g_extern.h	Sun Feb 17 15:40:19 2002
+++ klic-3.003-2002-03-05/include/klic/g_extern.h	Tue Mar  5 12:09:20 2002
@@ -9,7 +9,7 @@
 #define _KLIC_G_EXTERN_H_
 
 /* runtime/gc.c */
-extern q general_gc(q* term, q** sp);
+extern q general_gc(q* term);
 
 /* runtime/print.c */
 extern void general_print(
diff -ruN klic-3.003-2002-03-04a/runtime/export_table.c klic-3.003-2002-03-05/runtime/export_table.c
--- klic-3.003-2002-03-04a/runtime/export_table.c	Mon Mar  4 12:32:50 2002
+++ klic-3.003-2002-03-05/runtime/export_table.c	Tue Mar  5 12:09:20 2002
@@ -15,12 +15,11 @@
 
 #include "interpe.h"
 #include <klic/distio.h>
+#include <klic/g_extern.h>  /* general_gc */
 
 #define EXP_TABLE_INC_SIZE	0x1000
 #define UNUSED_EXPREC  0xf0f0f0ff  /* This value is curious!! */
 
-extern q general_gc();
-
 struct exp_entry{
   long index;
   long wec;
@@ -163,7 +162,7 @@
   j = 0;
   for(i=0; i<current_exp_size; i++){
     if(exp_table[i].data != (q) UNUSED_EXPREC){
-      newdata = general_gc(&(exp_table[i].data), gcsp());
+      newdata = general_gc(&(exp_table[i].data));
       exp_table[i].data = newdata;
       j++;
     }
diff -ruN klic-3.003-2002-03-04a/runtime/gc.c klic-3.003-2002-03-05/runtime/gc.c
--- klic-3.003-2002-03-04a/runtime/gc.c	Mon Mar  4 10:40:22 2002
+++ klic-3.003-2002-03-05/runtime/gc.c	Tue Mar  5 12:11:13 2002
@@ -21,15 +21,6 @@
 
 #ifdef SHM
 #include "shm.h"
-
-#define push_shm_stack(addr,sp,max) \
-do{ \
-  if( (sp) == max ){ \
-    (sp) = make_shm_larger_stack(sp); \
-    max = shm_gcmax; \
-  } \
-  *(sp)++ = (q*) (addr); \
-}while(0)
 #endif  /* SHM */
 
 #define generic_gc(obj, allocp, sp) \
@@ -52,8 +43,6 @@
 extern void set_gcsp(q** pp){ gcsp0 = pp; }
 extern void set_suspended_goal_list(struct suspended_goal_rec* p){ suspended_goal_list0 = p; }
 
-static struct goalrec* collect_garbage(struct goalrec* qp);
-
 static Inline void
 flip_spaces()
 {
@@ -66,76 +55,6 @@
   set_old_space_size(temps);
 }
 
-extern struct goalrec*
-klic_gc(qp)
-  struct goalrec* qp;
-{
-  declare_globals;
-  timerstruct before, after;
-  static int lastgc_dangerous = 0;
-  static int make_heap_larger = 0; /* make heap larger in the next GC */
-  q* new_new_space_top;
-  unsigned long bytesize;
-  int k;
-  if( measure_gc ) measure(before);
-
- gc_again:
-  if( make_heap_larger ){
-    q* new_old_space_top;
-    double_heapsize();
-    bytesize = (heapsize() + incrementsize()) * sizeof(q);
-    new_old_space_top = (q*) malloc(bytesize);
-    if( new_old_space_top != NULL ){
-      new_new_space_top = (q*) malloc(bytesize);
-      if( new_new_space_top != NULL ){
-	free(old_space_top);
-	set_old_space_top(new_old_space_top);
-	set_old_space_size(bytesize);
-      }else{
-	free(new_old_space_top);
-	if( lastgc_dangerous ){
-	  fatal("Not enough space collected and can't make heap larger");
-	}
-      }
-    }
-  }else if( lastgc_dangerous ){
-    fatalf("Maximum heap size specified (%u words) has been used up",
-	   maxheapsize());
-  }
-  flip_spaces();
-  copied_susp = 0;		/* for perpetual suspension detection */
-  qp = collect_garbage(qp);
-  if( make_heap_larger ){
-    free(old_space_top);
-    set_old_space_top(new_new_space_top);
-    set_old_space_size(bytesize);
-  }
-  make_heap_larger =
-    (heapp()-new_space_top()+this_more_space() > heapsize()*maxactiveratio() &&
-     heapsize() < maxheapsize());
-  lastgc_dangerous = (real_heaplimit() < heapp()+this_more_space());
-  if( lastgc_dangerous ){
-    goto gc_again;
-  }
-  reset_this_more_space();
-  gctimes++;
-#ifdef SHM
-  if( F_shm_gc ) qp = shm_gc(qp);
-#endif
-  if( measure_gc ){
-    measure(after);
-#ifdef GETRUSAGE
-    gcums += diff_usec(ru_utime)/1000;
-    gcsms += diff_usec(ru_stime)/1000;
-#else
-    gcums += (int) tick2msec(field_diff(tms_utime));
-    gcsms += (int) tick2msec(field_diff(tms_stime));
-#endif
-  }
-  return qp;
-}
-
-
 extern q**
 make_larger_stack(sp)
   q** sp;
@@ -164,19 +83,31 @@
   shm_gcmax = newstack + shm_gcstack_size;
   return sp;
 }
+
+static void push_shm_stack(q* addr)
+{
+  if(shm_sp == shm_gcmax)
+    shm_sp = make_shm_larger_stack(shm_sp);
+  *shm_sp = addr;
+  shm_sp++;
+}
 #endif /* SHM */
 
-#define within_new_space(x)	\
-  ((unsigned long)(x) - (unsigned long)new_space_top() < new_space_size())
+static int within_new_space(q* x)
+{
+  return (unsigned long)x - (unsigned long)new_space_top() < new_space_size();
+}
 
-#define within_old_space(x)	\
-  ((unsigned long)(x) - (unsigned long)old_space_top() < old_space_size())
+static int within_old_space(q* x)
+{
+  return (unsigned long)x - (unsigned long)old_space_top() < old_space_size();
+}
 
 #define push_gc_stack(addr, sp, max)			\
 do{							\
   if( (sp) == max ){					\
     (sp) = make_larger_stack(sp);			\
-    max = gcmax0;					\
+    max = gcmax();					\
   }							\
   *(sp)++ = (addr);					\
 }while(0)
@@ -189,7 +116,7 @@
   to = from; \
   if( !isatomic(from) ){ \
     if( is_shma(from) ){ \
-      push_shm_stack(&to, shm_sp, shm_gcmax); \
+      push_shm_stack(&to); \
     }else if( within_old_space(from) ){ \
       from = makeref(&to); \
       push_gc_stack(&to, sp, max); \
@@ -227,12 +154,12 @@
 }while(0)
 
 static void
-copy_terms(sp, max)
-  q** sp;
-  q** max;
+copy_terms(void)
 {
   declare_globals;
   q* hp = heapp();
+  q** sp = gcsp();
+  q** max = gcmax();
   while( sp > gcstack ){
     q* addr;
     q obj;
@@ -246,7 +173,7 @@
     if( is_shma(obj) ){
       *addr = obj;
       if( ptagof(obj) != ATOMIC ){
-	push_shm_stack(addr, shm_sp, shm_gcmax);
+	push_shm_stack(addr);
       }
       continue; /* while stack rests */
     }
@@ -374,7 +301,7 @@
 	  }else{
 	    *addr = value;
 #ifdef SHM
-	    if( is_shma(value) ) push_shm_stack(addr, shm_sp, shm_gcmax);
+	    if( is_shma(value) ) push_shm_stack(addr);
 #endif
 	  }
 	  break;
@@ -494,7 +421,7 @@
     hp = heapp();
     copy_one_goal(qp, gcsp0, gcmax0, 0);
     set_heapp(hp);
-    copy_terms(gcsp0, gcmax0);
+    copy_terms();
     qp->next = last;
     last = qp;
   }
@@ -597,8 +524,8 @@
       case CONS:
       case FUNCTOR:  /* generator hook but anybody reqested */
         push_gc_stack((q*) &sptr->localA, gcsp0, gcmax0);
-	copy_terms(gcsp0, gcmax0);
-        push_shm_stack(&sptr->globalA, shm_sp, shm_gcmax);
+	copy_terms();
+        push_shm_stack(&sptr->globalA);
         break;
       case ATOMIC: /* genarator object (distributed interface) */
 	{
@@ -614,7 +541,7 @@
 
 	    /* patch for debugging of hirata problem */
 	    hirata_bug1 = 1;
-	    copy_terms(gcsp0, gcmax0);
+	    copy_terms();
 	    hirata_bug1 = 0;
 
 	    wk = derefone(top);
@@ -624,10 +551,10 @@
 	    derefone(wk) = 0;
 	  }else{ /* generator */
 	    push_gc_stack(&wk, gcsp0, gcmax0);
-	    copy_terms(gcsp0, gcmax0);
+	    copy_terms();
 	    sptr->localA = (q*) tag_local(wk);
 	  }
-	  push_shm_stack(&sptr->globalA, shm_sp, shm_gcmax);
+	  push_shm_stack(&sptr->globalA);
 	  break;
 	}
       default: /* normal goal */
@@ -639,7 +566,7 @@
 	  }else if( isint(wqp->next) ){
 	    copy_one_goal(wqp, gcsp0, gcmax0, 1);
 	    sptr->localA = (q*) wqp;
-	    copy_terms(gcsp0, gcmax0);
+	    copy_terms();
 	    if( isref(sptr->globalA) ){
 	      for(;;){
 		q ww = derefone(sptr->globalA);
@@ -647,7 +574,7 @@
 		sptr->globalA = (q*) ww;
 	      }
 	    }
-	    push_shm_stack(&sptr->globalA, shm_sp, shm_gcmax);
+	    push_shm_stack(&sptr->globalA);
 	  }else{
 	  REM_HOOK:
 	    sptr->localA = 0;
@@ -722,7 +649,7 @@
 	/* not copied yet */
 	copy_one_goal(sgl->goal, gcsp0, gcmax0, 0);
 	set_heapp(hp);
-	copy_terms(gcsp0, gcmax0);
+	copy_terms();
 	hp = heapp();
 	dead_goal = sgl->goal;
       }
@@ -758,20 +685,89 @@
 {
   declare_globals;
   push_gc_stack(term, gcsp0, gcmax0);
-  copy_terms(gcsp0, gcmax0);
+  copy_terms();
 }
 
 /*
   for generic object
 */
 extern q
-general_gc(term, sp)
+general_gc(term)
   q* term;
-  q** sp;
 {
   declare_globals;
 
-  push_gc_stack(term, sp, gcmax0);
-  copy_terms(sp, gcmax0);
+  push_gc_stack(term, gcsp0, gcmax0);
+  copy_terms();
   return *term;
+}
+
+
+extern struct goalrec*
+klic_gc(qp)
+  struct goalrec* qp;
+{
+  declare_globals;
+  timerstruct before, after;
+  static int lastgc_dangerous = 0;
+  static int make_heap_larger = 0; /* make heap larger in the next GC */
+  q* new_new_space_top;
+  unsigned long bytesize;
+  int k;
+  if( measure_gc ) measure(before);
+
+ gc_again:
+  if( make_heap_larger ){
+    q* new_old_space_top;
+    double_heapsize();
+    bytesize = (heapsize() + incrementsize()) * sizeof(q);
+    new_old_space_top = (q*) malloc(bytesize);
+    if( new_old_space_top != NULL ){
+      new_new_space_top = (q*) malloc(bytesize);
+      if( new_new_space_top != NULL ){
+	free(old_space_top);
+	set_old_space_top(new_old_space_top);
+	set_old_space_size(bytesize);
+      }else{
+	free(new_old_space_top);
+	if( lastgc_dangerous ){
+	  fatal("Not enough space collected and can't make heap larger");
+	}
+      }
+    }
+  }else if( lastgc_dangerous ){
+    fatalf("Maximum heap size specified (%u words) has been used up",
+	   maxheapsize());
+  }
+  flip_spaces();
+  copied_susp = 0;		/* for perpetual suspension detection */
+  qp = collect_garbage(qp);
+  if( make_heap_larger ){
+    free(old_space_top);
+    set_old_space_top(new_new_space_top);
+    set_old_space_size(bytesize);
+  }
+  make_heap_larger =
+    (heapp()-new_space_top()+this_more_space() > heapsize()*maxactiveratio() &&
+     heapsize() < maxheapsize());
+  lastgc_dangerous = (real_heaplimit() < heapp()+this_more_space());
+  if( lastgc_dangerous ){
+    goto gc_again;
+  }
+  reset_this_more_space();
+  gctimes++;
+#ifdef SHM
+  if( F_shm_gc ) qp = shm_gc(qp);
+#endif
+  if( measure_gc ){
+    measure(after);
+#ifdef GETRUSAGE
+    gcums += diff_usec(ru_utime)/1000;
+    gcsms += diff_usec(ru_stime)/1000;
+#else
+    gcums += (int) tick2msec(field_diff(tms_utime));
+    gcsms += (int) tick2msec(field_diff(tms_stime));
+#endif
+  }
+  return qp;
 }
diff -ruN klic-3.003-2002-03-04a/runtime/sendrecv.c klic-3.003-2002-03-05/runtime/sendrecv.c
--- klic-3.003-2002-03-04a/runtime/sendrecv.c	Sat Mar  2 15:30:37 2002
+++ klic-3.003-2002-03-05/runtime/sendrecv.c	Tue Mar  5 12:09:20 2002
@@ -16,6 +16,7 @@
 #include <klic/distio.h>
 #include "interpe.h"
 #include "rmon.h"
+#include <klic/g_extern.h>  /* general_gc */
 
 /* if defined, optional eager requesting is activated. */
 /* #define REQUEST_WTC_THRESHOLD	0x3L */
@@ -38,7 +39,6 @@
 extern combuf* backup_combuf();
 extern void send_packet();
 extern combuf* receive_packet();
-extern q general_gc();
 
 extern void add_node_wtc(long wtc);
 extern long get_wtc(long request, enum get_wtc_type request_type);
@@ -539,7 +539,7 @@
 
   decode_stack_tmp = decode_stack;
   while( decode_stack_tmp != decode_stack_ptr ){
-    newdata = general_gc(decode_stack_tmp, gcsp());
+    newdata = general_gc(decode_stack_tmp);
     *decode_stack_tmp = newdata;
     decode_stack_tmp++;
 
