[1270] in Coldmud discussion meeting

root meeting help first previous next last

[COLD] [PATCH] grep +r

daemon@ATHENA.MIT.EDU (Fri Apr 4 05:42:09 1997 )

Date: Fri, 4 Apr 1997 12:33:58 +0200 (MET DST)
From: Miroslav Silovic <silovic@petra.zesoi.fer.hr>
To: coldstuff@cold.org


This fixes rather stupid bug in the object.c - extra object_discard
completely bombed the server if the object got swapped while task
still used the method (which was sufficiently rare to remain
unnoticed). The patch also features traceback log (that's dump_stack),
which proved invaluable when called from debugger, and reference
checker for the object on stack (currently #ifdeffed out). It also
fixes deallocing things in wrong order in frame_return (which boggled
my memory access checker, since it first called method_free, then
picked method->object to free it). Enjoy!


diff -C 5 -r orig/Genesis-1.0p26/src/execute.c Genesis-1.0p26/src/execute.c
*** orig/Genesis-1.0p26/src/execute.c	Sat Mar  8 20:25:51 1997
--- Genesis-1.0p26/src/execute.c	Fri Apr  4 12:10:02 1997
***************
*** 381,390 ****
--- 381,422 ----
  
  /*
  // ---------------------------------------------------------------
  // Nothing calls this function - it's here as a VM debug utility
  */
+ 
+ void dump_stack (void)
+ {
+     Frame *f = cur_frame;
+ 
+     while (f) {
+         printf("user #%d, sender #%d, caller #%d, #%d<#%d>.%s (%d)\n",
+                f->user, f->sender, f->caller, f->object->objnum,
+                f->method->object->objnum, ident_name(f->method->name), f->method->refs);
+         f = f->caller_frame;
+     }
+     printf ("---\n");
+ }
+ 
+ /* This call counts the references from the stack frames to the given object */
+ 
+ int count_stack_refs (int objnum)
+ {
+     Frame *f = cur_frame;
+     int s;
+ 
+     s=0;
+     while (f) {
+ 	if (f->object->objnum == objnum)
+ 	    s++;
+ 	if (f->method->object->objnum == objnum)
+ 	    s++;
+         f = f->caller_frame;
+     }
+     return s;
+ }
+ 
  #if DISABLED
  void show_queues(void) {
      VMState * v;
  
      fputs("preempted:", errfile);
***************
*** 808,820 ****
      for (i = cur_frame->stack_start; i < stack_pos; i++)
          data_discard(&stack[i]);
      stack_pos = cur_frame->stack_start;
  
      /* Let go of method and objects. */
      method_discard(cur_frame->method);
      cache_discard(cur_frame->object);
-     cache_discard(cur_frame->method->object);
  
      /* Discard any error action specifiers. */
      while (cur_frame->specifiers)
          pop_error_action_specifier();
  
--- 840,862 ----
      for (i = cur_frame->stack_start; i < stack_pos; i++)
          data_discard(&stack[i]);
      stack_pos = cur_frame->stack_start;
  
      /* Let go of method and objects. */
+ 
+ #if DISABLED
+     /* Check if any of the objects lost their refcounts */
+     if (count_stack_refs(cur_frame->method->object->objnum) > 
+ 	cur_frame->method->object->refs) {
+ 	printf ("EErrp!\n");
+ 	fflush(stdout);
+     }
+ #endif
+ 
+     cache_discard(cur_frame->method->object);
      method_discard(cur_frame->method);
      cache_discard(cur_frame->object);
  
      /* Discard any error action specifiers. */
      while (cur_frame->specifiers)
          pop_error_action_specifier();
  
diff -C 5 -r orig/Genesis-1.0p26/src/modules/moddef.h Genesis-1.0p26/src/modules/moddef.h
*** orig/Genesis-1.0p26/src/modules/moddef.h	Sat Mar 22 20:39:33 1997
--- Genesis-1.0p26/src/modules/moddef.h	Fri Apr  4 11:26:42 1997
***************
*** 95,105 ****
  #define NATIVE_MATH_SCALE 68
  #define NATIVE_MATH_IS_LOWER 69
  #define NATIVE_MATH_TRANSPOSE 70
  #define NATIVE_LAST 71
  
! #define MAGIC_MODNUMBER 859059573
  
  
  #ifdef _native_
  native_t natives[NATIVE_LAST] = {
      {"buffer",       "length",            native_buflen},
--- 95,105 ----
  #define NATIVE_MATH_SCALE 68
  #define NATIVE_MATH_IS_LOWER 69
  #define NATIVE_MATH_TRANSPOSE 70
  #define NATIVE_LAST 71
  
! #define MAGIC_MODNUMBER 860145891
  
  
  #ifdef _native_
  native_t natives[NATIVE_LAST] = {
      {"buffer",       "length",            native_buflen},
diff -C 5 -r orig/Genesis-1.0p26/src/ops/object.c Genesis-1.0p26/src/ops/object.c
*** orig/Genesis-1.0p26/src/ops/object.c	Wed Feb 12 07:23:41 1997
--- Genesis-1.0p26/src/ops/object.c	Fri Apr  4 12:11:56 1997
***************
*** 93,103 ****
      result = object_assign_var(cur_frame->object, cur_frame->method->object,
          		       args[0].u.symbol, &args[1]);
      if (result == varnf_id) {
          cthrow(varnf_id, "Object variable %I does not exist.", args[0].u.symbol);
      } else {
!         /* This is just a stupid way of returning args[1] */
          data_dup(&d, &args[1]);
          pop(2);
          data_dup(&stack[stack_pos++], &d);
          data_discard(&d);
      }
--- 93,103 ----
      result = object_assign_var(cur_frame->object, cur_frame->method->object,
          		       args[0].u.symbol, &args[1]);
      if (result == varnf_id) {
          cthrow(varnf_id, "Object variable %I does not exist.", args[0].u.symbol);
      } else {
!        /* This is just a stupid way of returning args[1] */
          data_dup(&d, &args[1]);
          pop(2);
          data_dup(&stack[stack_pos++], &d);
          data_discard(&d);
      }
***************
*** 174,184 ****
      /* keep these for later reference, if its already around */
      if (method) {
          flags = method->m_flags;
          access = method->m_access;
          native = method->native;
-         cache_discard(method->object);
      }
  
      code = args[0].u.list;
  
      /* Make sure that every element in the code list is a string. */
--- 174,183 ----