Merge fix.
[bpt/emacs.git] / src / bytecode.c
index 271b1ee..cf4a1fc 100644 (file)
@@ -1,6 +1,5 @@
 /* Execution of byte code produced by bytecomp.el.
-   Copyright (C) 1985, 1986, 1987, 1988, 1993, 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 1985-1988, 1993, 2000-2011 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -34,6 +33,7 @@ by Hallvard:
  */
 
 #include <config.h>
+#include <setjmp.h>
 #include "lisp.h"
 #include "buffer.h"
 #include "character.h"
@@ -57,9 +57,7 @@ by Hallvard:
 \f
 #ifdef BYTE_CODE_METER
 
-Lisp_Object Vbyte_code_meter, Qbyte_code_meter;
-int byte_metering_on;
-
+Lisp_Object Qbyte_code_meter;
 #define METER_2(code1, code2) \
   XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
            ->contents[(code2)])
@@ -231,6 +229,8 @@ Lisp_Object Qbytecode;
 #define Bconstant 0300
 #define CONSTANTLIM 0100
 
+/* Whether to maintain a `top' and `bottom' field in the stack frame.  */
+#define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
 \f
 /* Structure describing a value stack used during byte-code execution
    in Fbyte_code.  */
@@ -243,7 +243,9 @@ struct byte_stack
 
   /* Top and bottom of stack.  The bottom points to an area of memory
      allocated with alloca in Fbyte_code.  */
+#if BYTE_MAINTAIN_TOP
   Lisp_Object *top, *bottom;
+#endif
 
   /* The string containing the byte-code, and its current address.
      Storing this here protects it from GC because mark_byte_stack
@@ -270,8 +272,9 @@ struct byte_stack *byte_stack_list;
 \f
 /* Mark objects on byte_stack_list.  Called during GC.  */
 
+#if BYTE_MARK_STACK
 void
-mark_byte_stack ()
+mark_byte_stack (void)
 {
   struct byte_stack *stack;
   Lisp_Object *obj;
@@ -294,13 +297,13 @@ mark_byte_stack ()
       mark_object (stack->constants);
     }
 }
-
+#endif
 
 /* Unmark objects in the stacks on byte_stack_list.  Relocate program
    counters.  Called when GC has completed.  */
 
 void
-unmark_byte_stack ()
+unmark_byte_stack (void)
 {
   struct byte_stack *stack;
 
@@ -348,8 +351,13 @@ unmark_byte_stack ()
 /* Actions that must be performed before and after calling a function
    that might GC.  */
 
+#if !BYTE_MAINTAIN_TOP
+#define BEFORE_POTENTIAL_GC()  ((void)0)
+#define AFTER_POTENTIAL_GC()   ((void)0)
+#else
 #define BEFORE_POTENTIAL_GC()  stack.top = top
 #define AFTER_POTENTIAL_GC()   stack.top = NULL
+#endif
 
 /* Garbage collect if we have consed enough since the last time.
    We do this at every branch, to avoid loops that never GC.  */
@@ -392,6 +400,7 @@ unmark_byte_stack ()
        Fsignal (Qquit, Qnil);                          \
        AFTER_POTENTIAL_GC ();                          \
       }                                                        \
+    ELSE_PENDING_SIGNALS                               \
   } while (0)
 
 
@@ -401,8 +410,7 @@ The first argument, BYTESTR, is a string of byte code;
 the second, VECTOR, a vector of constants;
 the third, MAXDEPTH, the maximum stack depth used in this function.
 If the third argument is incorrect, Emacs may crash.  */)
-     (bytestr, vector, maxdepth)
-     Lisp_Object bytestr, vector, maxdepth;
+  (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth)
 {
   int count = SPECPDL_INDEX ();
 #ifdef BYTE_CODE_METER
@@ -449,10 +457,13 @@ If the third argument is incorrect, Emacs may crash.  */)
   stack.byte_string = bytestr;
   stack.pc = stack.byte_string_start = SDATA (bytestr);
   stack.constants = vector;
-  stack.bottom = (Lisp_Object *) alloca (XFASTINT (maxdepth)
+  top = (Lisp_Object *) alloca (XFASTINT (maxdepth)
                                          * sizeof (Lisp_Object));
-  top = stack.bottom - 1;
+#if BYTE_MAINTAIN_TOP
+  stack.bottom = top;
   stack.top = NULL;
+#endif
+  top -= 1;
   stack.next = byte_stack_list;
   byte_stack_list = &stack;
 
@@ -503,8 +514,9 @@ If the third argument is incorrect, Emacs may crash.  */)
            v1 = vectorp[op];
            if (SYMBOLP (v1))
              {
-               v2 = SYMBOL_VALUE (v1);
-               if (MISCP (v2) || EQ (v2, Qunbound))
+               if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
+                   || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
+                       EQ (v2, Qunbound)))
                  {
                    BEFORE_POTENTIAL_GC ();
                    v2 = Fsymbol_value (v1);
@@ -595,14 +607,13 @@ If the third argument is incorrect, Emacs may crash.  */)
            /* Inline the most common case.  */
            if (SYMBOLP (sym)
                && !EQ (val, Qunbound)
-               && !XSYMBOL (sym)->indirect_variable
-               && !SYMBOL_CONSTANT_P (sym)
-               && !MISCP (XSYMBOL (sym)->value))
-             XSYMBOL (sym)->value = val;
+               && !XSYMBOL (sym)->redirect
+               && !SYMBOL_CONSTANT_P (sym))
+             XSYMBOL (sym)->val.value = val;
            else
              {
                BEFORE_POTENTIAL_GC ();
-               set_internal (sym, val, current_buffer, 0);
+               set_internal (sym, val, Qnil, 0);
                AFTER_POTENTIAL_GC ();
              }
          }
@@ -873,7 +884,7 @@ If the third argument is incorrect, Emacs may crash.  */)
        case Btemp_output_buffer_setup:
          BEFORE_POTENTIAL_GC ();
          CHECK_STRING (TOP);
-         temp_output_buffer_setup (SDATA (TOP));
+         temp_output_buffer_setup (SSDATA (TOP));
          AFTER_POTENTIAL_GC ();
          TOP = Vstandard_output;
          break;
@@ -1400,7 +1411,7 @@ If the third argument is incorrect, Emacs may crash.  */)
            CHECK_CHARACTER (TOP);
            AFTER_POTENTIAL_GC ();
            c = XFASTINT (TOP);
-           if (NILP (current_buffer->enable_multibyte_characters))
+           if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
              MAKE_CHAR_MULTIBYTE (c);
            XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (c)]);
          }
@@ -1676,16 +1687,16 @@ If the third argument is incorrect, Emacs may crash.  */)
 }
 
 void
-syms_of_bytecode ()
+syms_of_bytecode (void)
 {
-  Qbytecode = intern ("byte-code");
+  Qbytecode = intern_c_string ("byte-code");
   staticpro (&Qbytecode);
 
   defsubr (&Sbyte_code);
 
 #ifdef BYTE_CODE_METER
 
-  DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter,
+  DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
               doc: /* A vector of vectors which holds a histogram of byte-code usage.
 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
 opcode CODE has been executed.
@@ -1693,7 +1704,7 @@ opcode CODE has been executed.
 indicates how many times the byte opcodes CODE1 and CODE2 have been
 executed in succession.  */);
 
-  DEFVAR_BOOL ("byte-metering-on", &byte_metering_on,
+  DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
               doc: /* If non-nil, keep profiling information on byte code usage.
 The variable byte-code-meter indicates how often each byte opcode is used.
 If a symbol has a property named `byte-code-meter' whose value is an
@@ -1701,7 +1712,7 @@ integer, it is incremented each time that symbol's function is called.  */);
 
   byte_metering_on = 0;
   Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
-  Qbyte_code_meter = intern ("byte-code-meter");
+  Qbyte_code_meter = intern_c_string ("byte-code-meter");
   staticpro (&Qbyte_code_meter);
   {
     int i = 256;
@@ -1711,6 +1722,3 @@ integer, it is incremented each time that symbol's function is called.  */);
   }
 #endif
 }
-
-/* arch-tag: b9803b6f-1ed6-4190-8adf-33fd3a9d10e9
-   (do not change this comment) */