Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp

0 views
Skip to first unread message

Harald Jörg

unread,
Sep 2, 2020, 4:07:05 PM9/2/20
to 16...@debbugs.gnu.org
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

Stefan Kangas

unread,
Sep 2, 2020, 6:20:05 PM9/2/20
to Harald Jörg, 16...@debbugs.gnu.org
Harald Jörg <h...@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@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



Harald Jörg

unread,
Sep 2, 2020, 7:41:05 PM9/2/20
to Stefan Kangas, 16...@debbugs.gnu.org
On 9/3/20 12:19 AM, Stefan Kangas wrote:
> Harald Jörg <h...@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@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




Stefan Kangas

unread,
Sep 3, 2020, 5:59:07 AM9/3/20
to Harald Jörg, 16...@debbugs.gnu.org
Harald Jörg <h...@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.



0 new messages