GNU bug report logs - #16368
24.3; freeze in cperl mode when editing a regexp

Previous Next

Package: emacs;

Reported by: Vincent Lefevre <vincent <at> vinc17.net>

Date: Mon, 6 Jan 2014 01:30:02 UTC

Severity: normal

Tags: confirmed, patch

Found in versions 26.1, 24.3

Fixed in version 28.1

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16368 in the body.
You can then email your comments to 16368 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Mon, 06 Jan 2014 01:30:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vincent Lefevre <vincent <at> vinc17.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 06 Jan 2014 01:30:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vincent Lefevre <vincent <at> vinc17.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; freeze in cperl mode when editing a regexp
Date: Mon, 06 Jan 2014 02:28:29 +0100
Open a file in cperl mode containing the following line:

  /(\d{4})(?: +){2}/;

e.g.: "emacs -Q file" then M-x cperl-mode <RET>

Put the cursor over the second opening brace, and type <DEL>
several times to delete what is before "{2}". When one types
<DEL> at this point:

  /(\d{4})(?:{2}/;
             ^cursor

Emacs freezes. One can type C-g to interrupt.

One can also reproduce the bug by typing: /(\d{4})(?{2
Emacs freezes before the "2" appears.

This bug is also present with Emacs 23.

Bug also reported on:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734325


In GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.8.6)
 of 2013-12-22 on brahms, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11405000
System Description:	Debian GNU/Linux unstable (sid)

Configured using:
 `configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu'
 '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
 '--localstatedir=/var/lib' '--infodir=/usr/share/info'
 '--mandir=/usr/share/man' '--with-pop=yes'
 '--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3/site-lisp:/usr/share/emacs/site-lisp'
 '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes'
 '--with-x-toolkit=gtk3' '--with-toolkit-scroll-bars'
 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
 --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall'
 'LDFLAGS=-Wl,-z,relro' 'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
  value of $LC_COLLATE: POSIX
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_TIME: en_DK
  value of $LANG: POSIX
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  display-time-mode: t
  show-paren-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<escape> x r e p o r t - e m <tab> <return>

Recent messages:
Loading /etc/emacs/site-start.d/50latex-cjk-common.el (source)...
Loading cjk-enc...done
Loading /etc/emacs/site-start.d/50latex-cjk-common.el (source)...done
Loading /etc/emacs/site-start.d/50latex-cjk-thai.el (source)...done
Loading /etc/emacs/site-start.d/50psvn.el (source)...done
Loading /etc/emacs/site-start.d/50rnc-mode.el (source)...done
Loading /etc/emacs/site-start.d/50w3m-el.el (source)...done
Loading /home/vinc17/share/emacs/site-lisp/mutteditor.el (source)...done
Loading time...done
For information about GNU Emacs and the GNU system, type C-h C-a.

Load-path shadows:
/usr/share/emacs24/site-lisp/css-mode/css-mode hides /usr/share/emacs/site-lisp/css-mode/css-mode
/usr/share/emacs/site-lisp/autoconf/autotest-mode hides /usr/share/emacs/site-lisp/autotest-mode
/usr/share/emacs24/site-lisp/html-helper-mode/tempo hides /usr/share/emacs/24.3/lisp/tempo
/usr/share/emacs24/site-lisp/flim/hex-util hides /usr/share/emacs/24.3/lisp/hex-util
/usr/share/emacs24/site-lisp/flim/md4 hides /usr/share/emacs/24.3/lisp/md4
/usr/share/emacs24/site-lisp/dictionaries-common/flyspell hides /usr/share/emacs/24.3/lisp/textmodes/flyspell
/usr/share/emacs24/site-lisp/dictionaries-common/ispell hides /usr/share/emacs/24.3/lisp/textmodes/ispell
/usr/share/emacs24/site-lisp/css-mode/css-mode hides /usr/share/emacs/24.3/lisp/textmodes/css-mode
/usr/share/emacs24/site-lisp/flim/hmac-md5 hides /usr/share/emacs/24.3/lisp/net/hmac-md5
/usr/share/emacs24/site-lisp/flim/sasl-ntlm hides /usr/share/emacs/24.3/lisp/net/sasl-ntlm
/usr/share/emacs24/site-lisp/flim/sasl-cram hides /usr/share/emacs/24.3/lisp/net/sasl-cram
/usr/share/emacs24/site-lisp/flim/ntlm hides /usr/share/emacs/24.3/lisp/net/ntlm
/usr/share/emacs24/site-lisp/flim/sasl hides /usr/share/emacs/24.3/lisp/net/sasl
/usr/share/emacs24/site-lisp/flim/hmac-def hides /usr/share/emacs/24.3/lisp/net/hmac-def
/usr/share/emacs24/site-lisp/flim/sasl-digest hides /usr/share/emacs/24.3/lisp/net/sasl-digest
/usr/share/emacs24/site-lisp/latex-cjk-thai/thai-word hides /usr/share/emacs/24.3/lisp/language/thai-word
/usr/share/emacs24/site-lisp/html-helper-mode/html-helper-mode hides /usr/share/emacs/site-lisp/html-helper-mode/html-helper-mode
/usr/share/emacs24/site-lisp/html-helper-mode/hhm-config hides /usr/share/emacs/site-lisp/html-helper-mode/hhm-config
/usr/share/emacs24/site-lisp/html-helper-mode/tempo hides /usr/share/emacs/site-lisp/html-helper-mode/tempo
/usr/share/emacs24/site-lisp/html-helper-mode/visual-basic-mode hides /usr/share/emacs/site-lisp/html-helper-mode/visual-basic-mode

Features:
(shadow sort gnus-util mail-extr warnings emacsbug message format-spec
rfc822 mml easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils time cus-start cus-load paren
cc-styles cc-align cc-engine cc-vars cc-defs w3m-load jabber-autoloads
time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer loaddefs button faces cus-face macroexp files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Fri, 20 Sep 2019 23:34:02 GMT) Full text and rfc822 format available.

Message #8 received at 16368 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Vincent Lefevre <vincent <at> vinc17.net>
Cc: 16368 <at> debbugs.gnu.org
Subject: Re: bug#16368: 24.3; freeze in cperl mode when editing a regexp
Date: Sat, 21 Sep 2019 01:33:08 +0200
Vincent Lefevre <vincent <at> vinc17.net> writes:

> Open a file in cperl mode containing the following line:
>
>   /(\d{4})(?: +){2}/;
>
> e.g.: "emacs -Q file" then M-x cperl-mode <RET>
>
> Put the cursor over the second opening brace, and type <DEL>
> several times to delete what is before "{2}". When one types
> <DEL> at this point:
>
>   /(\d{4})(?:{2}/;
>              ^cursor
>
> Emacs freezes. One can type C-g to interrupt.

I can confirm this is still an issue in Emacs 26.1 and on the current
master branch.

Best regards,
Stefan Kangas




Added tag(s) confirmed. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Fri, 20 Sep 2019 23:35:01 GMT) Full text and rfc822 format available.

bug Marked as found in versions 26.1. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Fri, 20 Sep 2019 23:35:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Wed, 02 Sep 2020 20:07:01 GMT) Full text and rfc822 format available.

Message #15 received at 16368 <at> debbugs.gnu.org (full text, mbox):

From: Harald Jörg <haj <at> posteo.de>
To: 16368 <at> debbugs.gnu.org
Subject: [PATCH] cperl-mode: don't freeze over a cool regexp
Date: Wed, 2 Sep 2020 22:06:40 +0200
[Message part 1 (text/plain, inline)]
That bug exists since 14 years, but only surfaces if the regexp has a
closing brace in the wrong place (two characters before an unfinished
group starts).  The reason is that `cperl-forward-group-in-re' failed
to report unbalanced parentheses: In the function, the error was too
narrowly localized and gets lost before returning.

Patch attached, including two test cases.
-- 
Cheers,
haj
[0001-2020-09-02-Harald-J-rg-haj-posteo.de.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Wed, 02 Sep 2020 22:20:01 GMT) Full text and rfc822 format available.

Message #18 received at 16368 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Harald Jörg <haj <at> posteo.de>, 16368 <at> debbugs.gnu.org
Subject: Re: bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
Date: Wed, 2 Sep 2020 18:19:25 -0400
Harald Jörg <haj <at> posteo.de> writes:

> Patch attached, including two test cases.

Thanks for working on cperl-mode bugs.

Testing the original recipe with your patch it is already an improvement
in that it avoids the freeze.  But I see these messages:

  cperl-forward-group-in-re: error (scan-error Unbalanced parentheses 9 94)
  (scan-error Unbalanced parentheses 9 94)

Is that the expected and desired behavior?

---

Also, some minor nits:

> Subject: [PATCH] =?UTF-8?q?2020-09-02=20=20Harald=20J=C3=B6rg=20=20<haj <at> po?=
>  =?UTF-8?q?steo.de>?=

Better first line:

Fix freeze in cperl-mode when editing a regexp

>  * lisp/progmodes/cperl-mode.el (cperl-forward-group-in-re): Make
>  sure that an error is reported back to the caller (Bug#16368).
>
>  * test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-bug-16368):
>  Tests for balanced (no error) and unbalanced (caught exception)
>  cases of `cperl-forward-group-in-re'.

Format these flush to the first column (no initial space).

> --- a/test/lisp/progmodes/cperl-mode-tests.el
> +++ b/test/lisp/progmodes/cperl-mode-tests.el

I see this:

    ELC      lisp/progmodes/cperl-mode-tests.elc

  In end of data:
  lisp/progmodes/cperl-mode-tests.el:73:1: Warning: the function
      `cperl-forward-group-in-re' is not known to be defined.

You should add this line to the top:

  (require 'cperl-mode)

Best regards,
Stefan Kangas




Added tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Wed, 02 Sep 2020 22:35:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Wed, 02 Sep 2020 23:41:01 GMT) Full text and rfc822 format available.

Message #23 received at 16368 <at> debbugs.gnu.org (full text, mbox):

From: Harald Jörg <haj <at> posteo.de>
To: Stefan Kangas <stefankangas <at> gmail.com>, 16368 <at> debbugs.gnu.org
Subject: Re: bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
Date: Thu, 3 Sep 2020 01:40:45 +0200
On 9/3/20 12:19 AM, Stefan Kangas wrote:
> Harald Jörg <haj <at> posteo.de> writes:
> 
>> Patch attached, including two test cases.
> 
> Thanks for working on cperl-mode bugs.
> 
> Testing the original recipe with your patch it is already an improvement
> in that it avoids the freeze.  But I see these messages:
> 
>   cperl-forward-group-in-re: error (scan-error Unbalanced parentheses 9 94)
>   (scan-error Unbalanced parentheses 9 94)
> 
> Is that the expected and desired behavior?

Yes, it is, sort of.  Maybe it should be fine-tuned.  At this point we
_have_ the situation of unbalanced parentheses, and cperl-mode rubs it
in for every character you type.

Just open a buffer in cperl-mode and start typing:

   $a =~ s/

At this point a message appears, with a different text when you open
a parentheses, and will haunt you until you get everything closed
properly.  Given that regexps can be messy and heavy with punctuation,
I'd say this is desired behavior.

I can only guess that the first part of the message (which starts with
"cperl-forward-group-in-re") was added out of frustration: The bug
prevented the second part of the message (without
"cperl-forward-group-in-re") from ever appearing.  Only this wasn't
fatal unless... there was this closing brace two characters before.
I'll check that, and prepare an updated patch if that's true.

> ---
> 
> Also, some minor nits:
> 
>> Subject: [PATCH] =?UTF-8?q?2020-09-02=20=20Harald=20J=C3=B6rg=20=20<haj <at> po?=
>>  =?UTF-8?q?steo.de>?=
> 
> Better first line:
> 
> Fix freeze in cperl-mode when editing a regexp
> 
>>  * lisp/progmodes/cperl-mode.el (cperl-forward-group-in-re): Make
>>  sure that an error is reported back to the caller (Bug#16368).
>>
>>  * test/lisp/progmodes/cperl-mode-tests.el (cperl-mode-test-bug-16368):
>>  Tests for balanced (no error) and unbalanced (caught exception)
>>  cases of `cperl-forward-group-in-re'.
> 
> Format these flush to the first column (no initial space).

No problem, I'll do so.  I thought I was supposed to create the commit
messages with C-x 4 a, but probably I misunderstood and should have
post-processed that text in the first place.

>> --- a/test/lisp/progmodes/cperl-mode-tests.el
>> +++ b/test/lisp/progmodes/cperl-mode-tests.el
> 
> I see this:
> 
>     ELC      lisp/progmodes/cperl-mode-tests.elc
> 
>   In end of data:
>   lisp/progmodes/cperl-mode-tests.el:73:1: Warning: the function
>       `cperl-forward-group-in-re' is not known to be defined.
> 
> You should add this line to the top:
> 
>   (require 'cperl-mode)

Hm. That should rather be _moving_ that line to the top?  The line is
there, in the test which calls this function.  For me this seemed to
be enough to avoid that message when byte-compiling.  But of course,
moving the line to the top is fine, probably more tests will follow
to exercise functions which aren't autoloaded.

Give me a few hours for a nap: It's past midnight here :)
-- 
Cheers,
haj





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Thu, 03 Sep 2020 09:59:01 GMT) Full text and rfc822 format available.

Message #26 received at 16368 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Harald Jörg <haj <at> posteo.de>, 16368 <at> debbugs.gnu.org
Subject: Re: bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
Date: Thu, 3 Sep 2020 02:58:40 -0700
Harald Jörg <haj <at> posteo.de> writes:

> I'd say this is desired behavior.

OK, thanks.  Your explanation sounds good to me.

> I can only guess that the first part of the message (which starts with
> "cperl-forward-group-in-re") was added out of frustration: The bug
> prevented the second part of the message (without
> "cperl-forward-group-in-re") from ever appearing.  Only this wasn't
> fatal unless... there was this closing brace two characters before.
> I'll check that, and prepare an updated patch if that's true.

Sounds good.

> No problem, I'll do so.  I thought I was supposed to create the commit
> messages with C-x 4 a, but probably I misunderstood and should have
> post-processed that text in the first place.

I always use C-x 4 a, and then delete the spacing to the left.

> Hm. That should rather be _moving_ that line to the top?

Ah, right.  Yup, that sounds good.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Thu, 03 Sep 2020 20:28:02 GMT) Full text and rfc822 format available.

Message #29 received at 16368 <at> debbugs.gnu.org (full text, mbox):

From: Harald Jörg <haj <at> posteo.de>
To: Stefan Kangas <stefankangas <at> gmail.com>, 16368 <at> debbugs.gnu.org
Subject: Re: bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
Date: Thu, 3 Sep 2020 22:27:12 +0200
[Message part 1 (text/plain, inline)]
On 9/3/20 11:58 AM, Stefan Kangas wrote:
> Harald Jörg <haj <at> posteo.de> writes:
>
>> I'd say this is desired behavior.
>
> OK, thanks.  Your explanation sounds good to me.

It wasn't quite accurate, though.  My explanation assumed that the
regex as a whole wasn't terminated, but in fact it was.  In fact, the
message comes from the fact that (?{...}) introduces a block of code
into the regexp.  So, by removing the colon from (?:{...}), the
semantics changed from "just another shy group" to "code", and for
code cperl-mode applies stricter rules than for the contents of a
capture group.

I'd still say the message is ok.

>> I can only guess that the first part of the message (which starts with
>> "cperl-forward-group-in-re") was added out of frustration: The bug
>> prevented the second part of the message (without
>> "cperl-forward-group-in-re") from ever appearing.  Only this wasn't
>> fatal unless... there was this closing brace two characters before.
>> I'll check that, and prepare an updated patch if that's true.
>
> Sounds good.

...And done.  Now you get only one message, without the unnecessary
"cperl-forward-group-in-re" prefix.

>> No problem, I'll do so.  I thought I was supposed to create the commit
>> messages with C-x 4 a, but probably I misunderstood and should have
>> post-processed that text in the first place.
>
> I always use C-x 4 a, and then delete the spacing to the left.

Ok, adapted.  I have also used your recommendation for the commit
summary.

>> Hm. That should rather be _moving_ that line to the top?
>
> Ah, right.  Yup, that sounds good.

When I did this, I stumbled over the purpose of Stefan Monniers change
to the tests - this has been taken to emacs-devel.  For now, moving
the line to the top and skipping the test if called in a perl-mode
environment, should do the trick.

Patch, mark2, is attached!
-- 
Cheers,
haj
[0001-Fix-freeze-in-cperl-mode-when-editing-a-regexp.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16368; Package emacs. (Thu, 03 Sep 2020 21:13:02 GMT) Full text and rfc822 format available.

Message #32 received at 16368 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Harald Jörg <haj <at> posteo.de>, 16368 <at> debbugs.gnu.org
Subject: Re: bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp
Date: Thu, 3 Sep 2020 21:12:29 +0000
close 16368 28.1
thanks

Harald Jörg <haj <at> posteo.de> writes:

> Patch, mark2, is attached!

LGTM, tested and works as far as I can tell.

Pushed to master as commit 7921b5db10.

Thanks!




bug marked as fixed in version 28.1, send any further explanations to 16368 <at> debbugs.gnu.org and Vincent Lefevre <vincent <at> vinc17.net> Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 03 Sep 2020 21:13:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 02 Oct 2020 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 214 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.