changeset 1626:5cec7ab01719

[xemacs-hg @ 2003-08-16 14:18:36 by michaels] 2003-08-12 Mike Sperber <mike@xemacs.org> * bytecode.c (GCPRO_STACK): Added. (execute_optimized_program): Use GCPRO_STACK, fixing a space leak: Formerly, the byte-code engine would always hold on to the entire stack memory area, including the stuff above the top. Now, we adjust the GCPRO record via GCPRO_STACK just before a GC may occur.
author michaels
date Sat, 16 Aug 2003 14:18:38 +0000
parents b7261453102e
children c30272e51919
files src/ChangeLog src/bytecode.c
diffstat 2 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Aug 15 21:52:30 2003 +0000
+++ b/src/ChangeLog	Sat Aug 16 14:18:38 2003 +0000
@@ -1,3 +1,12 @@
+2003-08-12  Mike Sperber  <mike@xemacs.org>
+
+	* bytecode.c (GCPRO_STACK): Added.
+	(execute_optimized_program): Use GCPRO_STACK, fixing a space leak:
+	Formerly, the byte-code engine would always hold on to the entire
+	stack memory area, including the stuff above the top.  Now, we
+	adjust the GCPRO record via GCPRO_STACK just before a GC may
+	occur.
+
 2003-07-31  René Kyllingstad  <listmailxemacs@kyllingstad.com>
 
 	* event-msw.c (mswindows_enqueue_mouse_button_event):
--- a/src/bytecode.c	Fri Aug 15 21:52:30 2003 +0000
+++ b/src/bytecode.c	Sat Aug 16 14:18:38 2003 +0000
@@ -447,6 +447,8 @@
    but don't pop it. */
 #define TOP (*stack_ptr)
 
+#define GCPRO_STACK  (gcpro1.nvars = stack_ptr - stack_beg)
+
 /* The actual interpreter for byte code.
    This function has been seriously optimized for performance.
    Don't change the constructs unless you are willing to do
@@ -460,8 +462,8 @@
 {
   /* This function can GC */
   REGISTER const Opbyte *program_ptr = (Opbyte *) program;
-  REGISTER Lisp_Object *stack_ptr
-    = alloca_array (Lisp_Object, stack_depth + 1);
+  Lisp_Object *stack_beg = alloca_array (Lisp_Object, stack_depth + 1);
+  REGISTER Lisp_Object *stack_ptr = stack_beg;
   int speccount = specpdl_depth ();
   struct gcpro gcpro1;
 
@@ -471,23 +473,11 @@
 #endif
 
 #ifdef ERROR_CHECK_BYTE_CODE
-  Lisp_Object *stack_beg = stack_ptr;
   Lisp_Object *stack_end = stack_beg + stack_depth;
 #endif
 
-  /* Initialize all the objects on the stack to Qnil,
-     so we can GCPRO the whole stack.
-     The first element of the stack is actually a dummy. */
-  {
-    int i;
-    Lisp_Object *p;
-    for (i = stack_depth, p = stack_ptr; i--;)
-      *++p = Qnil;
-  }
-
   GCPRO1 (stack_ptr[1]);
-  gcpro1.nvars = stack_depth;
-
+  
   while (1)
     {
       REGISTER Opcode opcode = (Opcode) READ_UINT_1;
@@ -512,7 +502,10 @@
 	  if (opcode >= Bconstant)
 	    PUSH (constants_data[opcode - Bconstant]);
 	  else
-	    stack_ptr = execute_rare_opcode (stack_ptr, program_ptr, opcode);
+	    {
+	      GCPRO_STACK;
+	      stack_ptr = execute_rare_opcode (stack_ptr, program_ptr, opcode);
+	    }
 	  break;
 
 	case Bvarref:
@@ -597,6 +590,7 @@
 	case Bcall+7:
 	  n = (opcode <  Bcall+6 ? opcode - Bcall :
 	       opcode == Bcall+6 ? READ_UINT_1 : READ_UINT_2);
+	  GCPRO_STACK;
 	  DISCARD (n);
 #ifdef BYTE_CODE_METER
 	  if (byte_metering_on && SYMBOLP (TOP))