diff -ruN klic-3.003-2002-02-24b/include/klic/gd_macro.h klic-3.003-2002-02-24c/include/klic/gd_macro.h
--- klic-3.003-2002-02-24b/include/klic/gd_macro.h	Fri Feb 22 11:27:31 2002
+++ klic-3.003-2002-02-24c/include/klic/gd_macro.h	Sun Feb 24 17:04:08 2002
@@ -71,15 +71,18 @@
 #define GD_ALLOC_AREA(new,type,size) \
 do{ \
   q res; \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   G_HEAPALLOC_WITH_CHECK((new), (size), type, res); \
-  assert(res==GENERIC_GCREQUEST || \
-        (res==GENERIC_SUCCEEDED && g_allocp >= heapp()+(size)) ); \
+  assert((res==GENERIC_GCREQUEST && g_allocp == heapp()) || \
+         (res==GENERIC_SUCCEEDED && g_allocp == heapp()+(size)) ); \
   if(GD_GCREQUEST == res){ \
     struct goalrec *goal; \
     g_allocp = \
       GD_MAKE_GENERIC_GOAL(&goal,makefunctor(GD_SELF),g_method_functor, \
 			   GD_ARGV,g_allocp); \
+    assert(g_allocp == heapp() + \
+      G_SIZE_IN_Q(struct functor) + arities(g_method_functor) - 1 + \
+      G_SIZE_IN_Q(struct goalrec) - 4 ); \
     G_PUSH_GOAL(goal); \
     GD_RETURN; \
   } \
@@ -88,16 +91,17 @@
 #define GD_ALLOC_AREA_FOR_NEW(new,type,size) \
 do{ \
   q res; \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   G_HEAPALLOC_WITH_CHECK((new), (size), type, res); \
-  assert(res==GENERIC_GCREQUEST || \
-        (res==GENERIC_SUCCEEDED && g_allocp >= heapp()+(size)) ); \
+  assert((res==GENERIC_GCREQUEST && g_allocp == heapp()) || \
+         (res==GENERIC_SUCCEEDED && g_allocp == heapp()+(size)) ); \
   if(GD_GCREQUEST == res){ \
     q var; \
     struct goalrec *goal; \
     G_MAKE_THE_NEW_GOAL(&var, &goal, g_myself, GD_ARGC, GD_ARGV, g_allocp); \
     g_allocp = heapp(); \
     G_PUSH_GOAL_TO_SPECIAL_QUEUE(goal); \
+    assert(g_allocp == heapp()); \
     GD_SUSPEND_NEW(var); \
   } \
 }while(0)
@@ -107,16 +111,17 @@
 #define GDSET_NEWOBJ_FOR_NEW(newgobj,size) \
 do{ \
   q res; \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   G_HEAPALLOC_WITH_CHECK((newgobj), (size), (GD_OBJ_TYPE*), res); \
-  assert(res==GENERIC_GCREQUEST || \
-        (res==GENERIC_SUCCEEDED && g_allocp >= heapp()+(size)) ); \
+  assert((res==GENERIC_GCREQUEST && g_allocp == heapp()) || \
+         (res==GENERIC_SUCCEEDED && g_allocp == heapp()+(size)) ); \
   if(GENERIC_GCREQUEST == res){ \
     q var; \
     struct goalrec *goal; \
     G_MAKE_THE_NEW_GOAL(&var, &goal, g_myself, GD_ARGC, GD_ARGV, g_allocp); \
     g_allocp = heapp(); \
     G_PUSH_GOAL_TO_SPECIAL_QUEUE(goal); \
+    assert(g_allocp == heapp()); \
     GD_SUSPEND_NEW(var); \
   } \
   (newgobj)->method_table = &GD_method_table; \
@@ -125,11 +130,11 @@
 #define GDSET_NEWOBJ(newgobj) \
 do{ \
   q res; \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   G_HEAPALLOC_WITH_CHECK((newgobj), GD_OBJ_SIZE(GD_SELF), \
 			 (GD_OBJ_TYPE*), res); \
-  assert(res==GENERIC_GCREQUEST || \
-        (res==GENERIC_SUCCEEDED && g_allocp >= heapp()+GD_OBJ_SIZE(GD_SELF)) ); \
+  assert((res==GENERIC_GCREQUEST && g_allocp == heapp()) || \
+         (res==GENERIC_SUCCEEDED && g_allocp == heapp()+GD_OBJ_SIZE(GD_SELF)) ); \
   if (GD_GCREQUEST == res) { \
     struct goalrec *goal; \
     g_allocp = \
@@ -236,13 +241,13 @@
 
 #define GD_SUSPEND_NEW(v) \
 do{ \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   return (v); \
 }while(0)
 
 #define GD_RETURN_FROM_NEW(x) \
 do{ \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   return makefunctor(x); \
 }while(0)
 
@@ -258,7 +263,7 @@
 
 #define GD_UNIFY(x,y) \
 do{ \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   do_shallow_unify((x), (y)); \
   g_allocp = heapp(); \
 }while(0)
@@ -375,7 +380,7 @@
 #define GD_RETURN_FROM_GC(newgobj) \
 do{ \
   gcsp = g_sp; \
-  set_heapp(g_allocp); \
+  assert(g_allocp == heapp()); \
   return(((q *)(newgobj))); \
 }while(0)
 
diff -ruN klic-3.003-2002-02-24b/runtime/gcode.c klic-3.003-2002-02-24c/runtime/gcode.c
--- klic-3.003-2002-02-24b/runtime/gcode.c	Fri Feb 22 10:56:33 2002
+++ klic-3.003-2002-02-24c/runtime/gcode.c	Sun Feb 24 17:00:52 2002
@@ -62,6 +62,7 @@
   newself->pdesc = GD_SELF->pdesc;
   GD_COPY_KL1_TERM_TO_NEWGEN(GD_SELF->module_obj, newself->module_obj);
   newself->predicate_name = GD_SELF->predicate_name;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -71,7 +72,9 @@
 {
   G_STD_DECL;
 
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[0], GD_SELF->module_obj);
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -79,7 +82,9 @@
 {
   G_STD_DECL;
 
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[0], GD_SELF->predicate_name);
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -88,7 +93,9 @@
   G_STD_DECL;
   const struct predicate* pred = GD_SELF->pdesc;
 
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[0], makeint(pred->arity));
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -274,9 +281,12 @@
     GD_ERROR_IN_NEW(message);
   }
 
+  set_heapp(g_allocp);
   GDSET_NEWOBJ_FOR_NEW(newpred, sizeof(struct predicate_object));
+  assert(g_allocp == heapp() + sizeof(struct predicate_object));
   newpred->pdesc = predaddr;
   newpred->module_obj = G_MAKEFUNCTOR(module_obj);
   newpred->predicate_name = predname;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_NEW(newpred);
 }
diff -ruN klic-3.003-2002-02-24b/runtime/gfloat.c klic-3.003-2002-02-24c/runtime/gfloat.c
--- klic-3.003-2002-02-24b/runtime/gfloat.c	Fri Feb 22 10:58:40 2002
+++ klic-3.003-2002-02-24c/runtime/gfloat.c	Sun Feb 24 17:01:13 2002
@@ -114,6 +114,7 @@
   ALIGN();
   GDSET_NEWOBJ_IN_NEWGEN(newself);
   newself->value = GD_SELF->value;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -186,7 +187,9 @@
 
   default:
     ALIGN();
+    set_heapp(g_allocp);
     GDSET_NEWOBJ(newobj);
+    assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
     GD_SWITCH_ON_ARITY {
     case 1: {
       result_index = 0;
@@ -252,7 +255,9 @@
   result = func(self);
  apply_2:
   newobj->value = result;
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[result_index], makefunctor(newobj));
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -386,7 +391,9 @@
 
   GD_DEREF_FOR_NEW(init);
   ALIGN();
+  set_heapp(g_allocp);
   GDSET_NEWOBJ_FOR_NEW(newobj, G_SIZE_IN_Q(GD_OBJ_TYPE));
+  assert(g_allocp == heapp() + G_SIZE_IN_Q(GD_OBJ_TYPE));
   if( G_ISINT(init) ){
     newobj->value = (double) G_INTVAL(init);
   }else if( G_ISGOBJ(init) &&
@@ -397,6 +404,7 @@
     debug_printf("### %k ###\n", init);
     GD_FAIL("Invalid initial value for floating point objects");
   }
+  set_heapp(g_allocp);
   GD_RETURN_FROM_NEW(newobj);
 }
 
diff -ruN klic-3.003-2002-02-24b/runtime/ggoal.c klic-3.003-2002-02-24c/runtime/ggoal.c
--- klic-3.003-2002-02-24b/runtime/ggoal.c	Sat Feb 16 11:57:26 2002
+++ klic-3.003-2002-02-24c/runtime/ggoal.c	Sun Feb 24 17:01:29 2002
@@ -134,6 +134,7 @@
   GDSET_NEWOBJ_IN_NEWGEN(newself);
   newself->goal = newgoal;
   newself->id = GD_SELF->id;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -150,7 +151,9 @@
 {
   G_STD_DECL;
   struct goalrec *newgoal;
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(newgoal, (struct goalrec *), 2+5);
+  assert(g_allocp == heapp() + 2+5);
   newgoal->pred = &step_trigger_pred;
   newgoal->args[0] = makefunctor(GD_SELF);
   newgoal->args[1] = GD_ARGV[0]; /* children info */
@@ -173,7 +176,9 @@
   GDSET_INTARG_WITHIN_RANGE(position, GD_ARGV[0], 1, size+1);
   the_arg = goal->args[position-1];
 
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[1], the_arg);
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -191,7 +196,9 @@
   oldarg = GD_SELF->goal->args[position-1];
 
   /* Allocate and set up new goal record */
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(newgoal, (struct goalrec *), size+2);
+  assert(g_allocp == heapp() + size+2);
   oldgoal = GD_SELF->goal;
   newgoal->pred = oldgoal->pred;
   for (k = 0; k < size; k++) {
@@ -200,10 +207,14 @@
   newgoal->args[position-1] = GD_ARGV[2];
 
   /* Allocate and set up new goal object */
+  set_heapp(g_allocp);
   GDSET_NEWOBJ(newobj);
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   newobj->goal = newgoal;
 
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[1], oldarg);
+  assert(g_allocp == heapp());
   GD_UNIFY_VALUE(GD_ARGV[3], GD_OBJ(newobj));
   GD_RETURN;
 }
@@ -257,14 +268,18 @@
   }
 
   /* Allocate and set up new goal record */
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(newgoal, (struct goalrec *), arity+2);
+  assert(g_allocp == heapp() + arity+2);
   newgoal->pred = pred->pdesc;
   for (k = 0; k < arity; k++) {
     newgoal->args[k] = oldgoal->args[k];
   }
 
   /* Allocate and set up new goal object */
+  set_heapp(g_allocp);
   GDSET_NEWOBJ(newobj);
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   newobj->goal = newgoal;
 
   GD_UNIFY_VALUE(GD_ARGV[1], GD_OBJ(newobj));
@@ -365,14 +380,19 @@
     GD_ERROR_IN_NEW("Number of args mismatch with the predicate");
   }
 
+  set_heapp(g_allocp);
   GD_ALLOC_AREA_FOR_NEW(newgoal, (struct goalrec *), pred_arity+2);
+  assert(g_allocp == heapp() + pred_arity+2);
   newgoal->pred = pred->pdesc;
   for (k = 0; k < pred_arity; k++) {
     extern q element_of_vector();
     newgoal->args[k] = element_of_vector(argvq, makeint(k));
   }
+  set_heapp(g_allocp);
   GDSET_NEWOBJ_FOR_NEW(newobj, G_SIZE_IN_Q(GD_OBJ_TYPE));
+  assert(g_allocp == heapp() + G_SIZE_IN_Q(GD_OBJ_TYPE));
   newobj->goal = newgoal;
   newobj->id = goal_obj_id++;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_NEW(newobj);
 }
diff -ruN klic-3.003-2002-02-24b/runtime/gmodule.c klic-3.003-2002-02-24c/runtime/gmodule.c
--- klic-3.003-2002-02-24b/runtime/gmodule.c	Fri Jan 11 10:35:20 2002
+++ klic-3.003-2002-02-24c/runtime/gmodule.c	Sun Feb 24 17:01:47 2002
@@ -62,6 +62,7 @@
 
   GDSET_NEWOBJ_IN_NEWGEN(newself);
   newself->name = GD_SELF->name;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -70,7 +71,9 @@
 GDDEF_METHOD(name_1)
 {
   G_STD_DECL;
+  set_heapp(g_allocp);
   GD_UNIFY( GD_ARGV[0],GD_SELF->name);
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -157,8 +160,11 @@
   for (mp = defined_modules; mp->name != 0; mp++) {
     if (strcmp((char *)mp->name, (char *)name) == 0) {
       GD_OBJ_TYPE *newmodule;
+      set_heapp(g_allocp);
       GDSET_NEWOBJ_FOR_NEW(newmodule,sizeof(struct module_object));
+      assert(g_allocp == heapp() + sizeof(struct module_object));
       newmodule->name = atom;
+      set_heapp(g_allocp);
       GD_RETURN_FROM_NEW(newmodule);
     }
   }
diff -ruN klic-3.003-2002-02-24b/runtime/gmvv.c klic-3.003-2002-02-24c/runtime/gmvv.c
--- klic-3.003-2002-02-24b/runtime/gmvv.c	Fri Feb 22 11:27:31 2002
+++ klic-3.003-2002-02-24c/runtime/gmvv.c	Sun Feb 24 17:02:01 2002
@@ -126,7 +126,9 @@
   for (k=0; k<size; k++) {
     q x = GD_OTHER->body[k];
     Shallow(GD_SELF);
+    set_heapp(g_allocp);
     GD_UNIFY(GD_SELF->body[k], x);
+    assert(g_allocp == heapp());
     Shallow(GD_OTHER);
   }
   GD_RETURN;
@@ -174,6 +176,7 @@
     *(g_sp++) = (q *)&(newself->body);
     /* End of manual expansion */
   }
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -239,7 +242,9 @@
   int position;
   Shallow(GD_SELF);
   GDSET_INTARG_WITHIN_RANGE(position,GD_ARGV[0],0,GD_SELF->index);
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[1], GD_SELF->body[position]);
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -247,7 +252,9 @@
 {
   G_STD_DECL;
   Shallow(GD_SELF);
+  set_heapp(g_allocp);
   GD_UNIFY_VALUE(GD_ARGV[0], G_MAKEINT(GD_SELF->index));
+  assert(g_allocp == heapp());
   GD_RETURN;
 }
 
@@ -265,7 +272,9 @@
   iscnst = GD_SELF->iscnst;
   body = GD_SELF->body;
   GDSET_INTARG_WITHIN_RANGE(position,GD_ARGV[0],0,size);
+  set_heapp(g_allocp);
   GDSET_NEWOBJ(newvect);
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   if (!iscnst) {
     q olddata = body[position];
 
@@ -277,7 +286,9 @@
   } else {
     long k;
     q *newbody;
+    set_heapp(g_allocp);
     GD_ALLOC_AREA(newbody,(q*),size);
+    assert(g_allocp == heapp() + size);
     for (k=0; k<size; k++) newbody[k] = body[k];
     newbody[position] = GD_ARGV[1];
     newvect->body = newbody;
@@ -305,9 +316,13 @@
   iscnst = GD_SELF->iscnst;
 
   GDSET_INTARG_WITHIN_RANGE(position,GD_ARGV[0],0,size);
+  set_heapp(g_allocp);
   GDSET_NEWOBJ(newvect);
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   olddata = body[position];
+  set_heapp(g_allocp);
   GD_UNIFY(GD_ARGV[1], olddata);
+  assert(g_allocp == heapp());
   if (!iscnst) {
     GD_SELF->index = position;
     GD_SELF->body = (q *)olddata;
@@ -317,7 +332,9 @@
   } else {
     long k;
     q *newbody;
+    set_heapp(g_allocp);
     GD_ALLOC_AREA(newbody,(q*),size);
+    assert(g_allocp == heapp() + size);
     for (k=0; k<size; k++) newbody[k] = body[k];
     newbody[position] = GD_ARGV[2];
     newvect->body = newbody;
@@ -341,10 +358,18 @@
   size = GD_SELF->index;
   GDSET_INTARG_WITHIN_RANGE(split_point,GD_ARGV[0],0,size+1);
   lower_size = size-split_point;
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(upper_body, (q *), split_point);
+  assert(g_allocp == heapp() + split_point);
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(lower_body, (q *), lower_size);
+  assert(g_allocp == heapp() + lower_size);
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(upper, (GD_OBJ_TYPE *), GD_OBJ_SIZE(GD_SELF));
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(lower, (GD_OBJ_TYPE *), GD_OBJ_SIZE(GD_SELF));
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   BCOPY((char *)GD_SELF->body, (char *)upper_body, split_point*sizeof(q));
   BCOPY((char *)(GD_SELF->body+split_point), (char *)lower_body,
 	lower_size*sizeof(q));
@@ -380,8 +405,12 @@
   Shallow(another);
   size2 = another->index;
   newsize = size1+size2;
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(newbody, (q *), newsize);
+  assert(g_allocp == heapp() + newsize);
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(new, (GD_OBJ_TYPE *), GD_OBJ_SIZE(GD_SELF));
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   Shallow(GD_SELF);
   BCOPY((char *)GD_SELF->body, (char *)newbody, size1*sizeof(q));
   Shallow(another);
@@ -540,11 +569,15 @@
   if (GD_ARGC!=1) GD_ERROR_IN_NEW("Too few or too many arguments");
   init = GD_ARGV[0];
   GD_DEREF_FOR_NEW(init);
+  set_heapp(g_allocp);
   GDSET_NEWOBJ_FOR_NEW(newvect, G_SIZE_IN_Q(GD_OBJ_TYPE));
+  assert(g_allocp == heapp() + G_SIZE_IN_Q(GD_OBJ_TYPE));
   if (G_ISINT(init)) {
     size = G_INTVAL(init);
     if (size < 0) GD_ERROR_IN_NEW("Negative size specified");
+    set_heapp(g_allocp);
     GD_ALLOC_AREA_FOR_NEW(body, (q*), size);
+    assert(g_allocp == heapp() + size);
     for (k=0; k<size; k++) body[k] = G_MAKEINT(0L);
   } else if (init==NILATOM || G_ISCONS(init)) {
     for (size=0; ; size++) {
@@ -555,7 +588,9 @@
 	GD_ERROR_IN_NEW("Invalid parameter");
     }
     init = GD_ARGV[0];
+    set_heapp(g_allocp);
     GD_ALLOC_AREA_FOR_NEW(body, (q*), size);
+    assert(g_allocp == heapp() + size);
     for (k=0; k<size; k++) {
       GD_DEREF_FOR_NEW(init);
       body[k] = G_CAR_OF(init);
@@ -568,6 +603,7 @@
   newvect->iscnst = 0;
   newvect->index = size;
   newvect->body = body;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_NEW(newvect);
 }
 
@@ -623,7 +659,9 @@
   q res;
   module decoder;
 
-  /* GDSET_NEWOBJ_FOR_NEW(newvect, G_SIZE_IN_Q(GD_OBJ_TYPE)); */
+  /* set_heapp(g_allocp);
+   * GDSET_NEWOBJ_FOR_NEW(newvect, G_SIZE_IN_Q(GD_OBJ_TYPE));
+   * assert(g_allocp == heapp() + G_SIZE_IN_Q(GD_OBJ_TYPE)); */
   set_heapp(g_allocp);
   G_HEAPALLOC_WITH_CHECK(newvect, G_SIZE_IN_Q(GD_OBJ_TYPE),
                           (GD_OBJ_TYPE*), res);
@@ -642,7 +680,9 @@
   newvect->method_table = &GD_method_table;
   newvect-> index = size = (long)GET_BUFFER(inbuf);
 
-  /* GD_ALLOC_AREA_FOR_NEW(body, (q*), size); */
+  /* set_heapp(g_allocp);
+   * GD_ALLOC_AREA_FOR_NEW(body, (q*), size);
+   * assert(g_allocp == heapp() + size) */
   set_heapp(g_allocp);
   G_HEAPALLOC_WITH_CHECK(body, size, (q*), res); 
   assert(res==GENERIC_GCREQUEST ||
diff -ruN klic-3.003-2002-02-24b/runtime/gpointer.c klic-3.003-2002-02-24c/runtime/gpointer.c
--- klic-3.003-2002-02-24b/runtime/gpointer.c	Fri Feb 22 11:01:29 2002
+++ klic-3.003-2002-02-24c/runtime/gpointer.c	Sun Feb 24 17:02:14 2002
@@ -39,6 +39,7 @@
   GD_OBJ_TYPE *newself;
   GDSET_NEWOBJ_IN_NEWGEN(newself);
   newself->pointer = GD_SELF->pointer;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -57,6 +58,7 @@
   assert(g_allocp >= heapp() + GD_OBJ_SIZE(newobj));
   newobj->method_table = &GD_method_table;
   newobj->pointer = (char *)GD_ARGV[0];
+  set_heapp(g_allocp);
   GD_RETURN_FROM_NEW(newobj);
 }
 
diff -ruN klic-3.003-2002-02-24b/runtime/gstring.c klic-3.003-2002-02-24c/runtime/gstring.c
--- klic-3.003-2002-02-24b/runtime/gstring.c	Fri Feb 22 11:27:31 2002
+++ klic-3.003-2002-02-24c/runtime/gstring.c	Sun Feb 24 17:02:28 2002
@@ -151,6 +151,7 @@
     newself->body = GD_SELF->body;
     GD_COPY_KL1_TERM_TO_NEWGEN(GD_SELF->next, newself->next);
   }
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -257,7 +258,9 @@
   body = GD_SELF->body;
   GDSET_INTARG_WITHIN_RANGE(position,GD_ARGV[0],0,size);
   GDSET_INTARG_WITHIN_RANGE(newelem,GD_ARGV[1],0,256);
+  set_heapp(g_allocp);
   GDSET_NEWOBJ(newstr);
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   if (!iscnst) {
     unsigned char olddata = body[position];
 
@@ -269,7 +272,9 @@
   } else {
     unsigned char *newbody;
     unsigned long qsize = ROUND_UP(size);
+    set_heapp(g_allocp);
     GD_ALLOC_AREA(newbody, (unsigned char *), qsize);
+    assert(g_allocp == heapp() + qsize);
     BCOPY(body, newbody, qsize*sizeof(q));
     newbody[position] = newelem;
     newstr->body = newbody;
@@ -293,10 +298,18 @@
   size = GD_SELF->index;
   GDSET_INTARG_WITHIN_RANGE(split_point,GD_ARGV[0],0,size+1);
   lower_size = size-split_point;
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(upper_body, (unsigned char *), ROUND_UP(split_point));
+  assert(g_allocp == heapp() + ROUND_UP(split_point));
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(lower_body, (unsigned char *), ROUND_UP(lower_size));
+  assert(g_allocp == heapp() + ROUND_UP(lower_size));
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(upper, (GD_OBJ_TYPE *), GD_OBJ_SIZE(GD_SELF));
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(lower, (GD_OBJ_TYPE *), GD_OBJ_SIZE(GD_SELF));
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   BCOPY(GD_SELF->body, upper_body, split_point);
   BCOPY(GD_SELF->body+split_point, lower_body, lower_size);
   upper->method_table = lower->method_table = GD_SELF->method_table;
@@ -332,8 +345,12 @@
   Shallow(another);
   size2 = another->index;
   newsize = size1+size2;
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(newbody, (unsigned char *), ROUND_UP(newsize));
+  assert(g_allocp == heapp() + ROUND_UP(newsize));
+  set_heapp(g_allocp);
   GD_ALLOC_AREA(new, (GD_OBJ_TYPE *), GD_OBJ_SIZE(GD_SELF));
+  assert(g_allocp == heapp() + GD_OBJ_SIZE(GD_SELF));
   Shallow(GD_SELF);
   BCOPY(GD_SELF->body, newbody, size1);
   Shallow(another);
@@ -607,13 +624,17 @@
   if (GD_ARGC!=1) GD_ERROR_IN_NEW("Too few or too many arguments");
   init = GD_ARGV[0];
   GD_DEREF_FOR_NEW(init);
+  set_heapp(g_allocp);
   GDSET_NEWOBJ_FOR_NEW(newstr, G_SIZE_IN_Q(GD_OBJ_TYPE));
+  assert(g_allocp == heapp() + G_SIZE_IN_Q(GD_OBJ_TYPE));
   if (G_ISINT(init)) {
     unsigned long qsize;
     size = G_INTVAL(init);
     if (size < 0) GD_ERROR_IN_NEW("Negative size specified");
     qsize = ROUND_UP(size);
+    set_heapp(g_allocp);
     GD_ALLOC_AREA_FOR_NEW(body, (unsigned char *), qsize);
+    assert(g_allocp == heapp() + qsize);
     BZERO(body, qsize*sizeof(q));
   } else if (init==NILATOM || G_ISCONS(init)) {
     unsigned long qsize, k;
@@ -632,7 +653,9 @@
     }
     qsize = ROUND_UP(size);
     init = GD_ARGV[0];
+    set_heapp(g_allocp);
     GD_ALLOC_AREA_FOR_NEW(body, (unsigned char *), qsize);
+    assert(g_allocp == heapp() + qsize);
     for (k=0; k<size; k++) {
       q elem;
       GD_DEREF_FOR_NEW(init);
@@ -648,6 +671,7 @@
   newstr->iscnst = 0;
   newstr->index = size;
   newstr->body = body;
+  set_heapp(g_allocp);
   GD_RETURN_FROM_NEW(newstr);
 }
 
diff -ruN klic-3.003-2002-02-24b/runtime/gtermarray.c klic-3.003-2002-02-24c/runtime/gtermarray.c
--- klic-3.003-2002-02-24b/runtime/gtermarray.c	Sun Feb 24 13:21:29 2002
+++ klic-3.003-2002-02-24c/runtime/gtermarray.c	Sun Feb 24 17:02:48 2002
@@ -47,6 +47,7 @@
     G_COPY_KL1_TERM_TO_NEWGEN(GD_SELF->terms[i],newself->terms[i]);
     assert(g_allocp >= heapp());
   }
+  set_heapp(g_allocp);
   GD_RETURN_FROM_GC(newself);
 }
 
@@ -70,6 +71,7 @@
   for (i=0; i<size; i++) {
     newobj->terms[i] = GD_ARGV[i];
   }
+  set_heapp(g_allocp);
   GD_RETURN_FROM_NEW(newobj);
 }
 
