Subject: bug#23949: 25.0.95; Regression in handling error caused by (string-match-p "." nil)

From: Stefan Monnier <[email-masked]>
Date: Wed, 13 Jul 2016 12:41:30 -0400

>> >> > I also think that the "breaks a lot of Elisp code" part is at least a
>> >> > tad exaggerated.
>> >> Binding inhibit-changing-match-data to t will pretty much break any
>> >> function that uses match-beginning or match-end.
>> > But those functions aren't supposed to run when string-match is
>> > called.
>> Yet they are in bug#23949.
> No, they aren't.  They run from the debugger.

I guess it depends what you call "run when string-match is called".

For me, I look at the C backtrace and see that Fstring_match calls
functions which end up calling the debugger which ends up running
the rest.

>> >> > (defsubst string-match-p (regexp string &optional start)
>> >> >   "\
>> >> > Same as `string-match' except this function does not change the match data."
>> >> >   (condition-case err
>> >> >       (let ((inhibit-changing-match-data t))
>> >> > 	(string-match regexp string start))
>> >> >     (error (signal (car err) (cdr err)))))
>> >> That will still cause the same problems when debug-on-signal is non-nil.
>> > So you don't consider this an improvement that should be installed?
>> No.
> What about the suggestion made by Andreas?

I think that would also fix this problem, yes.  It won't fix other
possible cases where the string-match could end up running Elisp code,
but AFAIK there aren't any currently.

> Exactly.  And we are punishing the innocent (the calls that don't
> signal an error) for fear of the guilty (those that do).

Right.  A more efficient solution would be to implement string-match-p
in C alongside string-match rather than on top of it, so we can get rid of
inhibit-changing-match-data (replaced by some other mechanism to
propagate this info where we need it).  But it's more work.

        Stefan