Mercurial > hg > xemacs-beta
diff src/bytecode.c @ 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 | e22b0213b713 |
children | 6c996a26d761 |
line wrap: on
line diff
--- 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))