]> git.eshelyaron.com Git - emacs.git/commitdiff
Revert "Store bytecode offset within exec_byte_code"
authorZach Shaftel <zshaftel@gmail.com>
Sun, 14 Jun 2020 21:20:48 +0000 (17:20 -0400)
committerZach Shaftel <zshaftel@gmail.com>
Sun, 14 Jun 2020 21:20:48 +0000 (17:20 -0400)
This reverts commit f6ec28d7974785b625e395d57cb18d1f2110fe4c.

This commit was just a terrible idea. Caused segfaults, violated the
comment in lisp.h that only eval.c should access `union specbinding`,
and didn't even improve performance.

src/bytecode.c
src/eval.c
src/lisp.h

index f4900fc588f696e638accaf1025d09643db2f6fe..29b76f88ef715edd04de565678adad8874c52e21 100644 (file)
@@ -311,6 +311,8 @@ enum byte_code_op
 
 #define TOP (*top)
 
+#define UPDATE_OFFSET (backtrace_byte_offset = pc - bytestr_data);
+
 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0,
        doc: /* Function used internally in byte-compiled code.
 The first argument, BYTESTR, is a string of byte code;
@@ -378,8 +380,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
   memcpy (bytestr_data, SDATA (bytestr), bytestr_length);
   unsigned char const *pc = bytestr_data;
   ptrdiff_t count = SPECPDL_INDEX ();
-  union specbinding *bt_frame = specpdl_ptr;
-  bt_frame = backtrace_next (bt_frame);
 
   if (!NILP (args_template))
     {
@@ -426,16 +426,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
         Threading provides a performance boost.  These macros are how
         we allow the code to be compiled both ways.  */
 #ifdef BYTE_CODE_THREADED
-#define UPDATE_OFFSET(to)                                      \
-      if (bt_frame->kind == SPECPDL_BACKTRACE)                 \
-       bt_frame->bt.bytecode_offset = (to);
+
       /* The CASE macro introduces an instruction's body.  It is
         either a label or a case label.  */
 #define CASE(OP) insn_ ## OP
       /* NEXT is invoked at the end of an instruction to go to the
         next instruction.  It is either a computed goto, or a
         plain break.  */
-#define NEXT goto *(targets[op = FETCH])
+#define NEXT UPDATE_OFFSET goto *(targets[op = FETCH])
       /* FIRST is like NEXT, but is only used at the start of the
         interpreter body.  In the switch-based interpreter it is the
         switch, so the threaded definition must include a semicolon.  */
@@ -637,7 +635,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
                  }
              }
 #endif
-           UPDATE_OFFSET(pc - bytestr_data);
            TOP = Ffuncall (op + 1, &TOP);
            NEXT;
          }
@@ -1454,7 +1451,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
        unbind_to (count, Qnil);
       error ("binding stack not balanced (serious byte compiler bug)");
     }
-  UPDATE_OFFSET(-1);
+  backtrace_byte_offset = -1;
   Lisp_Object result = TOP;
   SAFE_FREE ();
   return result;
index 26e552ea5479e2fd0615b04e353ee4dab74377f2..5b43b81a6ca88712efad07d28275c534af7baa40 100644 (file)
@@ -56,10 +56,14 @@ Lisp_Object Vrun_hooks;
 /* FIXME: We should probably get rid of this!  */
 Lisp_Object Vsignaling_function;
 
+int backtrace_byte_offset = -1;
+
 /* These would ordinarily be static, but they need to be visible to GDB.  */
 bool backtrace_p (union specbinding *) EXTERNALLY_VISIBLE;
 Lisp_Object *backtrace_args (union specbinding *) EXTERNALLY_VISIBLE;
 Lisp_Object backtrace_function (union specbinding *) EXTERNALLY_VISIBLE;
+union specbinding *backtrace_next (union specbinding *) EXTERNALLY_VISIBLE;
+union specbinding *backtrace_top (void) EXTERNALLY_VISIBLE;
 
 static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
 static Lisp_Object apply_lambda (Lisp_Object, Lisp_Object, ptrdiff_t);
@@ -2152,7 +2156,10 @@ record_in_backtrace (Lisp_Object function, Lisp_Object *args, ptrdiff_t nargs)
   specpdl_ptr->bt.function = function;
   current_thread->stack_top = specpdl_ptr->bt.args = args;
   specpdl_ptr->bt.nargs = nargs;
-  specpdl_ptr->bt.bytecode_offset = -1;
+  union specbinding *nxt = specpdl_ptr;
+  nxt = backtrace_next(nxt);
+  if (nxt->kind == SPECPDL_BACKTRACE)
+    nxt->bt.bytecode_offset = backtrace_byte_offset;
   grow_specpdl ();
 
   return count;
index 8a7f62df2267510c3f3061edae713d6c5bc3938a..ef6302a4670d1cba576b7890deebd34c4a13870d 100644 (file)
@@ -4113,6 +4113,7 @@ extern Lisp_Object Vautoload_queue;
 extern Lisp_Object Vrun_hooks;
 extern Lisp_Object Vsignaling_function;
 extern Lisp_Object inhibit_lisp_code;
+extern int backtrace_byte_offset;
 
 /* To run a normal hook, use the appropriate function from the list below.
    The calling convention:
@@ -4194,8 +4195,6 @@ extern void prog_ignore (Lisp_Object);
 extern ptrdiff_t record_in_backtrace (Lisp_Object, Lisp_Object *, ptrdiff_t);
 extern void mark_specpdl (union specbinding *first, union specbinding *ptr);
 extern void get_backtrace (Lisp_Object array);
-extern union specbinding *backtrace_next (union specbinding *pdl) EXTERNALLY_VISIBLE;
-extern union specbinding *backtrace_top (void) EXTERNALLY_VISIBLE;
 Lisp_Object backtrace_top_function (void);
 extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol);