Subject: bug#24166: With --eval, errors in string-match-p do not produce backtraces (but errors in string-match do?!)

From: [email-masked]
Date: Sat, 06 Aug 2016 08:25:17 -0400

Eli Zaretskii <[email-masked]> writes:

>> Not related to this issue as such, but if we want to bind
>> inhibit-changing-match-data for all debuggers, why not the others too?
>
> Which ones specifically did you have in mind?  We need to consider
> each one carefully, in order to determine whether every debugger needs
> that, or just debug.el.

Well I thought all of the ones in the let-binding except
enable-recursive-minibuffers (which has a comment about a specific
debug.el command) and window-configuration (which is just a local
lexical variable), as they don't look debug.el specific. But I don't
really have the patience for careful consideration of each variable just
to solve some hypothetical problems, so let's leave it for another time.

Here's the new patch.  Is it correct to put the DEFSYM next to the
DEFVAR_LISP?  I saw a few places where they were separated, but that
seems odd since it's then documented twice, and I thought maybe it's
just because they happened to be added at different times by people who
didn't notice the existing definition.

>From 9249fece6255615b63cd6848250003051f21cd1c Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Fri, 5 Aug 2016 22:11:00 -0400
Subject: [PATCH v2] Fix debugging of string-match-p errors

* src/eval.c (call_debugger): Bind inhibit-changing-match-data to nil so
that debugger code that needs to do regexp match won't break
(Bug #23949, Bug #24166, Bug#16294).
---
 src/eval.c   | 4 ++++
 src/search.c | 1 +
 2 files changed, 5 insertions(+)

diff --git a/src/eval.c b/src/eval.c
index 33b82f7..bf5bed7 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -300,6 +300,10 @@ call_debugger (Lisp_Object arg)
   specbind (Qinhibit_redisplay, Qnil);
   specbind (Qinhibit_debugger, Qt);
 
+  /* If we are debugging an error within a call to `string-match-p',
+     then make sure debugger code can still use match data.  */
+  specbind (Qinhibit_changing_match_data, Qnil);
+
 #if 0 /* Binding this prevents execution of Lisp code during
 	 redisplay, which necessarily leads to display problems.  */
   specbind (Qinhibit_eval_during_redisplay, Qt);
diff --git a/src/search.c b/src/search.c
index 5dc4d35..9b8fc58 100644
--- a/src/search.c
+++ b/src/search.c
@@ -3390,6 +3390,7 @@ or other such regexp constructs are not replaced with this.
 A value of nil (which is the normal value) means treat spaces literally.  */);
   Vsearch_spaces_regexp = Qnil;
 
+  DEFSYM (Qinhibit_changing_match_data, "inhibit-changing-match-data");
   DEFVAR_LISP ("inhibit-changing-match-data", Vinhibit_changing_match_data,
       doc: /* Internal use only.
 If non-nil, the primitive searching and matching functions
-- 
2.8.0