Subject: Re: bug#40088: 27.0.90; Symbol’s value as variable is void: debugger-outer-match-data

From: Noam Postavsky <[email-masked]>
Date: Fri, 20 Mar 2020 04:37:49 -0400

tags 40088 + patch
quit

Stefan Monnier <[email-masked]> writes:

>> Since the void-variable is getting triggered from
>> backtrace_eval_unrewind, I tried the patch below, which almost seems
>> to fix the problem,
>
> Indeed, the patch looks good (except for the removal of `static` which
> seems like a spurious artifact).

No, the removal is on purpose, because I'm calling default_value from
eval.c, and it's defined in data.c.  But, maybe you thought that because
I didn't add the corresponding declaration in a header file, and...

>> but after continuing from the debugger there's a
>> segfault in GC, so it's definitely not the Right Thing.

... the segfault happens because I forgot to declare default_value in
lisp.h, so its return value got converted to int.  *Forehead slap*

So here's the proper patch.  Eli, is it okay for emacs-27?  As I
mentioned earlier, the underlying bug was present in Emacs 26 and
earlier, but it's only surfaced in Emacs 27 because of debug.el
enhancements.

>From 9afae526cf1959f5922dffb9254578dfe12ee4be Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Fri, 20 Mar 2020 04:07:39 -0400
Subject: [PATCH] Don't signal during backtrace unrewind (Bug#40088)

* src/data.c (default_value): Make non-static.
* src/lisp.h: Declare it.
* src/eval.c (backtrace_eval_unrewind): Call default_value and
buffer_local_value instead of Fdefault_value and Fbuffer_local_value,
respectively, so that unrewinding to unbound variables will not signal
an error.
---
 src/data.c | 2 +-
 src/eval.c | 4 ++--
 src/lisp.h | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/data.c b/src/data.c
index b153068846..5ce5e360ab 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1573,7 +1573,7 @@ notify_variable_watchers (Lisp_Object symbol,
 /* Return the default value of SYMBOL, but don't check for voidness.
    Return Qunbound if it is void.  */
 
-static Lisp_Object
+Lisp_Object
 default_value (Lisp_Object symbol)
 {
   struct Lisp_Symbol *sym;
diff --git a/src/eval.c b/src/eval.c
index 4559a0e1f6..78a787c4ff 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3816,7 +3816,7 @@ backtrace_eval_unrewind (int distance)
 	  {
 	    Lisp_Object sym = specpdl_symbol (tmp);
 	    Lisp_Object old_value = specpdl_old_value (tmp);
-	    set_specpdl_old_value (tmp, Fdefault_value (sym));
+	    set_specpdl_old_value (tmp, default_value (sym));
 	    Fset_default (sym, old_value);
 	  }
 	  break;
@@ -3832,7 +3832,7 @@ backtrace_eval_unrewind (int distance)
 	    if (!NILP (Flocal_variable_p (symbol, where)))
 	      {
 		set_specpdl_old_value
-		  (tmp, Fbuffer_local_value (symbol, where));
+		  (tmp, buffer_local_value (symbol, where));
                 set_internal (symbol, old_value, where, SET_INTERNAL_UNBIND);
 	      }
 	  }
diff --git a/src/lisp.h b/src/lisp.h
index 8674fe11a6..92294ac1d3 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -594,6 +594,7 @@ #define ENUM_BF(TYPE) enum TYPE
 
 /* Defined in data.c.  */
 extern AVOID wrong_type_argument (Lisp_Object, Lisp_Object);
+extern Lisp_Object default_value (Lisp_Object symbol);

 /* Defined in emacs.c.  */
-- 
2.11.0