diff -ruN klic-3.003-2002-03-05d/runtime/gc.c klic-3.003-2002-03-05e/runtime/gc.c
--- klic-3.003-2002-03-05d/runtime/gc.c	Tue Mar  5 16:24:50 2002
+++ klic-3.003-2002-03-05e/runtime/gc.c	Tue Mar  5 16:59:47 2002
@@ -23,7 +23,7 @@
 #include "shm.h"
 #endif  /* SHM */
 
-#define generic_gc(obj, allocp)  (method_table_of(obj)->gc((obj), (allocp)))
+#define generic_gc(obj)  (method_table_of(obj)->gc((obj), heapp()))
 
 extern const struct predicate queue_empty_pred;
 
@@ -140,9 +140,7 @@
 do{							\
   struct goalrec* og = (goal);				\
   int n = og->pred->arity;				\
-  struct goalrec* ng = (struct goalrec*) hp;		\
-  hp += n + 2;						\
-  set_heapp(hp); \
+  struct goalrec* ng = (struct goalrec*) klic_alloc(n + 2); \
   ng->next = og->next;					\
   og->next = ng;					\
   ng->pred = og->pred;					\
@@ -158,7 +156,6 @@
 copy_terms(void)
 {
   declare_globals;
-  q* hp = heapp();
   while( gcsp() > gcstack ){
     q* addr;
     q obj;
@@ -192,9 +189,7 @@
 	if( isstruct(cdr) && within_new_space((q*) cdr) ){
 	  *addr = cdr;
 	}else{
-	  q newcons = makecons(hp);
-	  hp += 2;
-	  set_heapp(hp);
+	  q newcons = makecons(klic_alloc(2));
 	  reserve_copy(car_of(obj), car_of(newcons));
 	  *addr = cdr_of(obj) = newcons;
 	  if( isatomic(cdr) ){
@@ -221,14 +216,11 @@
 	}else if( isref(f) ){
 	  struct data_object* oldobj = (struct data_object*) functorp(obj);
 	  q* newobj;
-	  newobj = generic_gc(oldobj, hp);
-	  hp = heapp();
+	  newobj = generic_gc(oldobj);
 	  *addr = functor_of(obj) = makefunctor(newobj);
 	}else{
-	  q newfunct = makefunctor(hp);
 	  int k = arityof(f);
+	  q newfunct = makefunctor(klic_alloc(k + 1));
-	  hp += k+1;
-	  set_heapp(hp);
 	  *addr = functor_of(obj) = newfunct;
 	  functor_of(newfunct) = f;
 	  do{
@@ -272,9 +264,8 @@
 	    if( within_new_space(addr) ){
 	      *addr = derefone(obj) = makeref(addr);
 	    }else{
+	      q* hp = klic_alloc(1);
 	      *addr = derefone(obj) = *hp = makeref(hp);
-	      hp++;
-	      set_heapp(hp);
 	    }
 	  }else{
 	    struct susprec* s = suspp(value);
@@ -283,13 +274,9 @@
 	      struct generator_susp* newgsusp;
 	      struct generator_susp* gsusp = generator_suspp(s);
 	      q newplace;
-	      q newvar = *addr = derefone(obj) = makeref(hp);
-
-	      hp++;
-	      set_heapp(hp);
+	      q newvar = *addr = derefone(obj) = makeref(klic_alloc(1));
+	      q* hp = klic_alloc(sizeof(struct generator_susp) / sizeof(q));
 	      newgsusp = generator_suspp(hp);
-	      hp += sizeof(struct generator_susp) / sizeof(q);
-	      set_heapp(hp);
 	      derefone(newvar) = makeref(newgsusp);
 	      newgsusp->backpt = makeref(newvar);
 	      oldobj = untag_generator_susp(gsusp->u.o);
@@ -300,8 +287,7 @@
 	      }else{
 		/* not yet copied */
 		struct generator_object* newobj;
-		newobj = (struct generator_object*) generic_gc(oldobj, hp);
-		hp = heapp();
+		newobj = (struct generator_object*) generic_gc(oldobj);
 		oldobj->method_table =
 		  (struct generator_object_method_table*) makefunctor(newobj);
 		newgsusp->u.o = tag_generator_susp(newobj);
@@ -315,9 +301,8 @@
 	      q newvar;
 
 	      /* make a new variable, anyway */
+	      q* hp = klic_alloc(1);
 	      newvar = *addr = derefone(obj) = *hp = makeref(hp);
-	      hp++;
-	      set_heapp(hp);
 	      lastu.l = 0;
 	      do{
 		union goal_or_consumer u = h->u;
@@ -341,8 +326,7 @@
 		    }else{
 		      struct consumer_object* newobj;
 		      newobj = (struct consumer_object*)
-			  generic_gc(untag_consumer_hook(u.o), hp);
-		      hp = heapp();
+			  generic_gc(untag_consumer_hook(u.o));
 		      untag_consumer_hook(u.o)->method_table =
 			(struct consumer_object_method_table*)
 			  makefunctor(newobj);
@@ -350,9 +334,8 @@
 		    }
 		  }
 		  if( lastu.l != 0 ){
+		    q* hp = klic_alloc(sizeof(struct hook) / sizeof(q));
 		    struct hook* nh = (struct hook*) hp;
-		    hp += sizeof(struct hook)/sizeof(q);
-		    set_heapp(hp);
 		    nh->u = lastu;
 		    last->next = nh;
 		    last = nh;
@@ -363,9 +346,8 @@
 		h = h->next;
 	      }while( h != second_hook );
 	      if( lastu.l != 0 ){
+		q* hp = klic_alloc(sizeof(struct susprec) / sizeof(q));
 		struct susprec* ns = (struct susprec*) hp;
-		hp += sizeof(struct susprec)/sizeof(q);
-		set_heapp(hp);
 		last->next = &ns->u.first_hook;
 		ns->backpt = newvar;
 		ns->u.first_hook.next = dummy.next;
@@ -380,7 +362,6 @@
       break;
     }  /* switch ptagof(obj) */
   }  /* while stack rests */
-  set_heapp(hp);
 }
 
 static struct goalrec*
@@ -405,7 +386,6 @@
   qp = last;
   last = &goal_queue_tail;
   for( ; qp != NULL; qp=next ){
-    q* hp;
     next = qp->next;
 #ifdef SHM
     if( is_shma(qp) ){
@@ -414,9 +394,7 @@
       continue; /* for qp */
     }
 #endif
-    hp = heapp();
     copy_one_goal(qp, 0);
-    set_heapp(hp);
     copy_terms();
     qp->next = last;
     last = qp;
@@ -614,7 +592,6 @@
     struct suspended_goal_rec* sgl;
     struct suspended_goal_rec** sgl_tail = &suspended_goal_list0;
     struct goalrec* dead_goal = NULL;
-    q* hp = heapp();
     if( copied_susp != suspensions() - resumes() ){
       klic_fprintf(stderr,
 		   "%d perpetually suspending goals found\n",
@@ -627,9 +604,8 @@
     for( sgl = suspended_goal_list(); sgl != NULL; sgl = sgl->next ){
       if( sgl->goal->pred == 0 || !isref(sgl->goal->next) ){
 	/* already copied or not resumed yet */
-	struct suspended_goal_rec* newsgr =
-	  (struct suspended_goal_rec*) hp;
-	hp += sizeof(struct suspended_goal_rec)/sizeof(q);
+	q* hp = klic_alloc(sizeof(struct suspended_goal_rec) / sizeof(q));
+	struct suspended_goal_rec* newsgr = (struct suspended_goal_rec*) hp;
 	*sgl_tail = newsgr;
 	newsgr->goal = sgl->goal;
 	sgl_tail = &newsgr->next;
@@ -644,18 +620,15 @@
       }else{
 	/* not copied yet */
 	copy_one_goal(sgl->goal, 0);
-	set_heapp(hp);
 	copy_terms();
-	hp = heapp();
 	dead_goal = sgl->goal;
       }
     }
-    set_heapp(hp);
     if( dead_goal != 0 ){
       /* we have to make the dead goal look like a normal ready queue */
+      q* hp = klic_alloc(sizeof(struct goalrec) / sizeof(q));
       ((struct goalrec*) hp)->pred = &queue_empty_pred;
       dead_goal->next = (struct goalrec*) hp;
-      hp += sizeof(struct goalrec)/sizeof(q);
       trace_deadlock(dead_goal);
     }
   }
