unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: (error "Stack overflow in regexp matcher") and (?)wrong display of regexp in backtrace
Date: Sun, 15 Mar 2020 13:22:20 +0100	[thread overview]
Message-ID: <858A7BE9-9170-477F-908B-3C2383F5A727@acm.org> (raw)
In-Reply-To: <20200315103922.GA4928@ACM>

15 mars 2020 kl. 11.39 skrev Alan Mackenzie <acm@muc.de>:

> Hello, Emacs.

Hello Alan. Thanks for the nice example!

> First of all, note the regexp, "\\(\\\\\\(.\\|\n\\)\\|[^\\\n\15]\\)*"
>                                                            ^^^
> In the source, the "\15" is "\r".  Why is this substitution being made
> for the backtrace?  Is it intentional (in which case, why not do the
> same to the "\n"?), or is it a bug?  To me, it is more like a bug.

I agree; there are some ad-hoc switches like print-escape-newlines (which only works on \n and \f) and print-escape-control-characters (which produces octal), but nothing that gives human-friendly escapes for other known control characters.

> More importantly, why is there a stack overflow here at all?  Even
> though the regexp matcher has a long, long piece of buffer to scan over,
> the regexp is a simple linear search, without any nesting to speak of.

Let's ask xr for help:

(xr-pp "\\(\\\\\\(.\\|\n\\)\\|[^\\\n\15]\\)*")
=>
(zero-or-more
 (group
  (or (seq "\\"
           (group anything))
      (not (any "\n\r\\")))))

(note that xr pretty-prints \r properly)

There are two capture groups here, neither of which are actually used. Remove them (the outer one in particular) and the regexp no longer overflows. Navigating the file also becomes noticeably faster. Like this:

(rx (zero-or-more
     (or (seq "\\" anything)
         (not (any "\n\r\\")))))

(rx will use a slightly more efficient rendition of 'anything', but that isn't actually important in this case.)




  reply	other threads:[~2020-03-15 12:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-15 10:39 (error "Stack overflow in regexp matcher") and (?)wrong display of regexp in backtrace Alan Mackenzie
2020-03-15 12:22 ` Mattias Engdegård [this message]
2020-03-15 12:33   ` Mattias Engdegård
2020-03-15 16:57   ` Alan Mackenzie
2020-03-15 20:06     ` Mattias Engdegård
2020-03-15 14:21 ` Noam Postavsky
2020-03-15 14:56   ` Eli Zaretskii
2020-03-15 16:35 ` Stefan Monnier
2020-03-15 17:32   ` Alan Mackenzie
2020-03-15 17:38     ` Mattias Engdegård
2020-03-15 17:46       ` Eli Zaretskii
2020-03-15 18:02         ` Andreas Schwab
2020-03-16  0:32           ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=858A7BE9-9170-477F-908B-3C2383F5A727@acm.org \
    --to=mattiase@acm.org \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).