diff --git a/src/cpp.c b/src/cpp.c
index 993c72d61f0ce53e8832a8ed14e14cfee894356c..ec05413c15ad7ff647136baf46c017db929ab068 100644
--- a/src/cpp.c
+++ b/src/cpp.c
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: cpp.c,v 1.50 1999/03/27 17:17:00 grubba Exp $
+ * $Id: cpp.c,v 1.51 1999/04/07 23:10:03 hubbe Exp $
  */
 #include "global.h"
 #include "language.h"
@@ -1199,8 +1199,9 @@ void add_predefine(char *s)
   pike_predefs=tmp;
 }
 
-void exit_cpp()
+void exit_cpp(void)
 {
+#ifdef DO_PIKE_CLEANUP
   struct pike_predef_s *tmp;
   while((tmp=pike_predefs))
   {
@@ -1214,4 +1215,5 @@ void exit_cpp()
 
   free_string(constant_macro->link.s);
   free((char *)constant_macro);
+#endif
 }
diff --git a/src/global.h b/src/global.h
index c65a6f2c27f3c2d6e1eb465e7c1edaccc68f1a03..e6510688ee8af3c6ec2e878f3e764ab1e685531b 100644
--- a/src/global.h
+++ b/src/global.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: global.h,v 1.28 1999/03/02 03:13:14 hubbe Exp $
+ * $Id: global.h,v 1.29 1999/04/07 23:10:05 hubbe Exp $
  */
 #ifndef GLOBAL_H
 #define GLOBAL_H
@@ -211,12 +211,22 @@ typedef struct p_wchar_p
  static char *rcsid = X
 #endif
 
+#ifdef PIKE_DEBUG
+#define DO_IF_DEBUG(X) X
+#else
+#define DO_IF_DEBUG(X)
+#endif
+
 #if defined(__GNUC__) && !defined(PIKE_DEBUG) && !defined(lint)
 #define INLINE inline
 #else
 #define INLINE
 #endif
 
+#if defined(PURIFY) || defined(__CHECKER__) || defined(DEBUG_MALLOC)
+#define DO_PIKE_CLEANUP
+#endif
+
 #include "port.h"
 #include "dmalloc.h"
 
diff --git a/src/interpret.h b/src/interpret.h
index 642225e03c31922857ac55975b0ab60504aa1264..a8eb3cb8ce65da5087733dd18b48d8f410e9449e 100644
--- a/src/interpret.h
+++ b/src/interpret.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: interpret.h,v 1.27 1999/03/02 03:13:17 hubbe Exp $
+ * $Id: interpret.h,v 1.28 1999/04/07 23:10:06 hubbe Exp $
  */
 #ifndef INTERPRET_H
 #define INTERPRET_H
@@ -96,24 +96,25 @@ struct pike_frame
 #define free_pike_frame(F) do{ struct pike_frame *f_=(F); debug_malloc_touch(f_); if(!--f_->refs) really_free_pike_frame(f_); }while(0)
 
 #define POP_PIKE_FRAME() do {						\
-  struct pike_frame *tmp_=fp;						\
-  fp=tmp_->next;							\
-  if(!--tmp_->refs)							\
+  struct pike_frame *tmp_=fp->next;					\
+  if(!--fp->refs)							\
   {									\
-    really_free_pike_frame(tmp_);					\
+    really_free_pike_frame(fp);						\
   }else{								\
-    if(tmp_->num_locals)						\
+    DO_IF_DEBUG(if( fp->locals+fp->num_locals>sp) fatal("Stack failiure in POP_PIKE_FRAME!\n"));                                                      \
+    if(fp->num_locals)							\
     {									\
       struct svalue *s=(struct svalue *)xalloc(sizeof(struct svalue)*	\
-					       tmp_->num_locals);	\
-      assign_svalues_no_free(s,tmp_->locals,tmp_->num_locals,BIT_MIXED);\
-      tmp_->locals=s;							\
-      tmp_->malloced_locals=1;						\
+					       fp->num_locals);		\
+      assign_svalues_no_free(s,fp->locals,fp->num_locals,BIT_MIXED);	\
+      fp->locals=s;							\
+      fp->malloced_locals=1;						\
     }else{								\
-      tmp_->locals=0;							\
+      fp->locals=0;							\
     }									\
-    tmp_->next=0;							\
+    fp->next=0;								\
   }									\
+  fp=tmp_;								\
  }while(0)
 
 
diff --git a/src/language.yacc b/src/language.yacc
index c832fce373c7ba2b39244ef4e9aed33cf4143029..8fca302c231ca6b8fe6e950a9a03bced126dffa2 100644
--- a/src/language.yacc
+++ b/src/language.yacc
@@ -181,7 +181,7 @@
 /* This is the grammar definition of Pike. */
 
 #include "global.h"
-RCSID("$Id: language.yacc,v 1.115 1999/03/29 20:17:21 grubba Exp $");
+RCSID("$Id: language.yacc,v 1.116 1999/04/07 23:10:07 hubbe Exp $");
 #ifdef HAVE_MEMORY_H
 #include <memory.h>
 #endif
@@ -624,7 +624,7 @@ def: modifiers type_or_error optional_stars F_IDENTIFIER
 
     if(compiler_pass==1)
     {
-      define_function($4->u.sval.u.string,
+      $<number>5=define_function($4->u.sval.u.string,
 		      $<n>$->u.sval.u.string,
 		      $1,
 		      IDENTIFIER_PIKE_FUNCTION,
@@ -650,6 +650,9 @@ def: modifiers type_or_error optional_stars F_IDENTIFIER
 #ifdef PIKE_DEBUG
       if(recoveries && sp-evaluator_stack < recoveries->sp)
 	fatal("Stack error (underflow)\n");
+
+	if(compiler_pass == 1 && f!=$<number>5)
+	  fatal("define_function screwed up! %d != %d\n",f,$<number>5);
 #endif
     }
     pop_compiler_frame();
diff --git a/src/object.c b/src/object.c
index c0f8700cb7737b1ea75721ba1f60e26e2b81ec54..d1c70ad1b25185110a682f0fe201f509973626a6 100644
--- a/src/object.c
+++ b/src/object.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: object.c,v 1.67 1999/04/02 02:09:05 hubbe Exp $");
+RCSID("$Id: object.c,v 1.68 1999/04/07 23:10:08 hubbe Exp $");
 #include "object.h"
 #include "dynamic_buffer.h"
 #include "interpret.h"
@@ -359,7 +359,7 @@ struct destroy_called_mark
 
 PTR_HASH_ALLOC(destroy_called_mark,128)
 
-static void call_destroy(struct object *o)
+static void call_destroy(struct object *o, int foo)
 {
   int e;
   if(!o || !o->prog) return; /* Object already destructed */
@@ -370,7 +370,8 @@ static void call_destroy(struct object *o)
     if(check_destroy_called_mark_semafore(o))
     {
       /* fprintf(stderr, "destruct(): Calling destroy().\n"); */
-      safe_apply_low(o, e, 0);
+      if(foo) push_int(1);
+      safe_apply_low(o, e, foo?1:0);
       pop_stack();
     }
   }
@@ -387,7 +388,7 @@ void destruct(struct object *o)
 
   add_ref(o);
 
-  call_destroy(o);
+  call_destroy(o,0);
   remove_destroy_called_mark(o);
 
   /* destructed in destroy() */
@@ -972,11 +973,12 @@ void cleanup_objects(void)
   for(o=first_object;o;o=next)
   {
     add_ref(o);
-    call_destroy(o);
+    call_destroy(o,1);
     next=o->next;
     free_object(o);
   }
 
+#ifdef DO_PIKE_CLEANUP
   for(o=first_object;o;o=next)
   {
     add_ref(o);
@@ -989,6 +991,7 @@ void cleanup_objects(void)
   free_program(master_program);
   master_program=0;
   destruct_objects_to_destruct();
+#endif
 }
 
 struct array *object_indices(struct object *o)
@@ -1176,7 +1179,7 @@ void gc_free_all_unreferenced_objects(void)
     if(gc_do_free(o))
     {
       add_ref(o);
-      call_destroy(o);
+      call_destroy(o,0);
       next=o->next;
       free_object(o);
     }else{
diff --git a/src/program.c b/src/program.c
index c096a8d60c74855cd410af56b101d2ca004bf6a8..0a3968fb2d45f8d5a29893e9c74c76c84a9e20a3 100644
--- a/src/program.c
+++ b/src/program.c
@@ -5,7 +5,7 @@
 \*/
 /**/
 #include "global.h"
-RCSID("$Id: program.c,v 1.119 1999/04/03 01:34:00 hubbe Exp $");
+RCSID("$Id: program.c,v 1.120 1999/04/07 23:10:10 hubbe Exp $");
 #include "program.h"
 #include "object.h"
 #include "dynamic_buffer.h"
@@ -1848,43 +1848,44 @@ INT32 define_function(struct pike_string *name,
       my_yyerror("Illegal to redefine 'nomask' function %s.",name->str);
     }
 
-    if(!(ref.id_flags & ID_INLINE) || compiler_pass!=1)
+    /* We modify the old definition if it is in this program */
+    if(ref.inherit_offset==0)
     {
-      /* We modify the old definition if it is in this program */
-      if(ref.inherit_offset==0)
-      {
-	if(func)
-	  funp->func = *func;
-	else
-	  funp->func.offset = -1;
-	
-	funp->identifier_flags=function_flags;
-      }else{
-	/* Otherwise we make a new definition */
-	copy_shared_string(fun.name, name);
-	copy_shared_string(fun.type, type);
-	
-	fun.run_time_type=T_FUNCTION;
-	
-	fun.identifier_flags=function_flags;
-	if(function_flags & IDENTIFIER_C_FUNCTION)
-	  new_program->flags |= PROGRAM_HAS_C_METHODS;
-	
-	if(func)
-	  fun.func = *func;
-	else
-	  fun.func.offset = -1;
-	
-	ref.identifier_offset=new_program->num_identifiers;
-	add_to_identifiers(fun);
-      }
+      if(func)
+	funp->func = *func;
+      else
+	funp->func.offset = -1;
       
-      ref.inherit_offset = 0;
-      ref.id_flags = flags;
-      new_program->identifier_references[i]=ref;
-      return i;
+      funp->identifier_flags=function_flags;
+    }else{
+      if(compiler_pass==1  || (ref.id_flags & ID_INLINE))
+	goto make_a_new_def;
+      
+      /* Otherwise we make a new definition */
+      copy_shared_string(fun.name, name);
+      copy_shared_string(fun.type, type);
+      
+      fun.run_time_type=T_FUNCTION;
+      
+      fun.identifier_flags=function_flags;
+      if(function_flags & IDENTIFIER_C_FUNCTION)
+	new_program->flags |= PROGRAM_HAS_C_METHODS;
+      
+      if(func)
+	fun.func = *func;
+      else
+	fun.func.offset = -1;
+      
+      ref.identifier_offset=new_program->num_identifiers;
+      add_to_identifiers(fun);
     }
+    
+    ref.inherit_offset = 0;
+    ref.id_flags = flags;
+    new_program->identifier_references[i]=ref;
+    return i;
   }
+make_a_new_def:
 
 #ifdef PIKE_DEBUG
   if(compiler_pass==2)
@@ -1914,7 +1915,7 @@ INT32 define_function(struct pike_string *name,
   ref.id_flags = flags;
   ref.identifier_offset = i;
   ref.inherit_offset = 0;
-  
+
   i=new_program->num_identifier_references;
   add_to_identifier_references(ref);
 
@@ -2619,6 +2620,8 @@ void cleanup_program(void)
     }
   }
 #endif
+
+#ifdef DO_PIKE_CLEANUP
   if(resolve_cache)
   {
     free_mapping(resolve_cache);
@@ -2630,6 +2633,7 @@ void cleanup_program(void)
     free_program(pike_trampoline_program);
     pike_trampoline_program=0;
   }
+#endif
 }
 
 #ifdef GC2
diff --git a/src/svalue.h b/src/svalue.h
index 756f5414f72bdacd3e443634ac7139517eb440da..807275e3cdcdf58f5deccd2f853af36ae31ce299 100644
--- a/src/svalue.h
+++ b/src/svalue.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: svalue.h,v 1.23 1999/03/26 23:41:00 grubba Exp $
+ * $Id: svalue.h,v 1.24 1999/04/07 23:10:11 hubbe Exp $
  */
 #ifndef SVALUE_H
 #define SVALUE_H
@@ -215,7 +215,7 @@ do{ \
 }while(0)
 
 #ifdef PIKE_DEBUG
-#define check_type(T) if(T > MAX_TYPE && T!=T_LVALUE && T!=T_SHORT_LVALUE && T!=T_VOID && T!=T_DELETED && T!=T_ARRAY_LVALUE) fatal("Type error\n")
+#define check_type(T) if(T > MAX_TYPE && T!=T_LVALUE && T!=T_SHORT_LVALUE && T!=T_VOID && T!=T_DELETED && T!=T_ARRAY_LVALUE) fatal("Type error: %d\n",T)
 #define check_refs(S) if((S)->type < MAX_REF_TYPE && (!(S)->u.refs || (S)->u.refs[0] < 0)) fatal("Svalue to object without references.\n")
 #define check_refs2(S,T) if((T) < MAX_REF_TYPE && (S)->refs && (S)->refs[0] <= 0) fatal("Svalue to object without references.\n")
 
diff --git a/src/threads.h b/src/threads.h
index a9e49053b8b629d85f92517a1e43647d35c1f957..b67bb2aa5c391221dd3388eb4ff554dbb45e2656 100644
--- a/src/threads.h
+++ b/src/threads.h
@@ -1,5 +1,5 @@
 /*
- * $Id: threads.h,v 1.63 1999/02/01 06:13:16 hubbe Exp $
+ * $Id: threads.h,v 1.64 1999/04/07 23:10:12 hubbe Exp $
  */
 #ifndef THREADS_H
 #define THREADS_H
@@ -358,12 +358,6 @@ struct thread_state {
 #define DO_IF_PROFILING(X)
 #endif
 
-#ifdef PIKE_DEBUG
-#define DO_IF_DEBUG(X) X
-#else
-#define DO_IF_DEBUG(X)
-#endif
-
 #define SWAP_OUT_THREAD(_tmp) do { \
        (_tmp)->swapped=1; \
        (_tmp)->evaluator_stack=evaluator_stack;\