From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Harald =?UTF-8?Q?J=C3=B6rg?= Newsgroups: gmane.emacs.bugs Subject: bug#16368: [PATCH] cperl-mode: don't freeze over a cool regexp Date: Thu, 3 Sep 2020 22:27:12 +0200 Message-ID: References: <87iotxq4oy.fsf@xvii.vinc17.org> <1dce9689-f0ae-e066-bbf0-fb92f9b997ce@posteo.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------0AAFCCBF2E9EE097C1EABD02" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40462"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 To: Stefan Kangas , 16368@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 03 22:28:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDvq6-000APd-SW for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Sep 2020 22:28:10 +0200 Original-Received: from localhost ([::1]:55884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDvq5-0002Nl-VP for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Sep 2020 16:28:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDvpy-0002M3-Hz for bug-gnu-emacs@gnu.org; Thu, 03 Sep 2020 16:28:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDvpy-0002Cl-8z for bug-gnu-emacs@gnu.org; Thu, 03 Sep 2020 16:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kDvpy-0003RM-4h for bug-gnu-emacs@gnu.org; Thu, 03 Sep 2020 16:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Harald =?UTF-8?Q?J=C3=B6rg?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 03 Sep 2020 20:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16368 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch confirmed Original-Received: via spool by 16368-submit@debbugs.gnu.org id=B16368.159916484313169 (code B ref 16368); Thu, 03 Sep 2020 20:28:02 +0000 Original-Received: (at 16368) by debbugs.gnu.org; 3 Sep 2020 20:27:23 +0000 Original-Received: from localhost ([127.0.0.1]:36296 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kDvpK-0003QL-Sw for submit@debbugs.gnu.org; Thu, 03 Sep 2020 16:27:23 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:48903) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kDvpI-0003Py-4y for 16368@debbugs.gnu.org; Thu, 03 Sep 2020 16:27:21 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id AB6FF160061 for <16368@debbugs.gnu.org>; Thu, 3 Sep 2020 22:27:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1599164833; bh=2JmKqm8K0AMAV+0i41thWtxVdId3JNbXLDFF/RWDxQY=; h=Subject:To:From:Autocrypt:Date:From; b=fpPb3dYvWU0IXlKo8EQ4HCWTHitOZkUiZNZMeu1VOJEQMIYbtgWmrrQzPZ0n46120 kS4hiod3Xy/UdtZUILwZWMOn6TRpftqBCCBbFrxl8p1jQeFNM1i/x3ginf8QjOIZqV f2AiD0HaewzJfMpwAjVuU7iqtrCokkfcuFA2sUWaT643AkY6WExRP+eK6R2TK+gX+j 6DnMPatg7xbMA4qd6TKktYxGj1qiZZQGdApqms6BR/3XlMXvAnJT4w1zlO02d4T18q nPH/Zmx9W+Z4IWEXyv3RIa5NPVH/4PoH4zevSd+bRV/Qw6lJBd62H6SuqjEc+6U8iP ZmA6DA94ztmjA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4BjC5s0Y36z9rxS; Thu, 3 Sep 2020 22:27:12 +0200 (CEST) Autocrypt: addr=haj@posteo.de; keydata= mQINBF0DVrIBEAC7TRlIilBg/5Dx7R2rV4FBDEavbyMT2cS2wWyksh7JA8e17LNmTdakf+Bm u6C2m6+frolteYRlkreoyAg0fj/5tDw/s5dJDw3tM0b+m/pj2HcwTSRpQSEy5lBiCg11E6Mt F9UngCfkGtJzu8PBWXc1RDQVBwRn5MZbpMZZatE8NOq9AA3Yg6sY11Ez3xIvYU2R7a4OSxmc RJV2+dhdQ4oOTBIGQ2urQSU81kyRtkx+/Yh8WefMrk9nF3nzYziLS53euCAXyzklwYmD6Li3 XSu7wYp5fISky9DK6DPFK7h4RXEL4GFAhy31ehrVnNTcGRohM1Dm9BV9dwXkwlaeT3q0X+nE SXVqPDHtv748bXNIg2WVCZ0WgShcA46XVlSE9Fm+w0HI/1m1L4BaMmQ7gyK5dEchbhxohkk0 AqC3hEJ4ULRidrsCoCWGMFKiOIb9rjeC00vhrUkVJDkPWEGLXjhnRQykb6cESko0rPrSDLqX 9YqaNQ6KO9Un6uogE7YnXYg35EXJ8ORdX257IbXNbFVpgM8FFsl48WV3Pl9WNdADhnnOrz3O wzyK58i/BTsnjVX8ghbWkQcPQ2Kprt+4YR2trEi7TM5Uqzzrg0vp7Oe/9KZBxdxCE67thV7h ElW3CHb4q6o31b4cFmLbtFesSy+hnUU4UymgHgi/hvhxioBxIQARAQABtBxIYXJhbGQgSsO2 cmcgPGhhakBwb3N0ZW8uZGU+iQJOBBMBCAA4FiEEIpYEZLQynxF8Q17KN4XzzzqAcpsFAl0D VrICGwMFCwkIBwIGFQgJCgsCBBYCAwECHgECF4AACgkQN In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:187037 Archived-At: This is a multi-part message in MIME format. --------------0AAFCCBF2E9EE097C1EABD02 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 9/3/20 11:58 AM, Stefan Kangas wrote: > Harald Jörg 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 --------------0AAFCCBF2E9EE097C1EABD02 Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-freeze-in-cperl-mode-when-editing-a-regexp.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-Fix-freeze-in-cperl-mode-when-editing-a-regexp.patch" =46rom 2ae8d341de4cb9782241348b28e4f713c317925c Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Harald=3D20J=3DC3=3DB6rg?=3D Date: Thu, 3 Sep 2020 22:11:47 +0200 Subject: [PATCH] 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'. --- lisp/progmodes/cperl-mode.el | 9 ++++----- test/lisp/progmodes/cperl-mode-tests.el | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 44579cfd38..e2628c834c 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -3241,8 +3241,8 @@ cperl-forward-group-in-re Works before syntax recognition is done." ;; Works *before* syntax recognition is done (or st-l (setq st-l (list nil))) ; Avoid overwriting '() - (let (st b reset-st) - (condition-case b + (let (st result reset-st) + (condition-case err (progn (setq st (cperl-cached-syntax-table st-l)) (modify-syntax-entry ?\( "()" st) @@ -3250,8 +3250,7 @@ cperl-forward-group-in-re (setq reset-st (syntax-table)) (set-syntax-table st) (forward-sexp 1)) - (error (message - "cperl-forward-group-in-re: error %s" b))) + (error (setq result err))) ;; now restore the initial state (if st (progn @@ -3259,7 +3258,7 @@ cperl-forward-group-in-re (modify-syntax-entry ?\) "." st))) (if reset-st (set-syntax-table reset-st)) - b)) + result)) =20 =20 (defvar font-lock-string-face) diff --git a/test/lisp/progmodes/cperl-mode-tests.el b/test/lisp/progmode= s/cperl-mode-tests.el index be8b42d99a..e14ff98e3f 100644 --- a/test/lisp/progmodes/cperl-mode-tests.el +++ b/test/lisp/progmodes/cperl-mode-tests.el @@ -18,6 +18,8 @@ =20 (defvar cperl-test-mode #'cperl-mode) =20 +(require 'cperl-mode) + (defun cperl-test-ppss (text regexp) "Return the `syntax-ppss' of the first character matched by REGEXP in = TEXT." (interactive) @@ -48,4 +50,25 @@ cperl-mode-test-bug-42168 (let ((code "{ $a- / $b } # /")) (should (equal (nth 8 (cperl-test-ppss code "/")) 7)))) =20 +(ert-deftest cperl-mode-test-bug-16368 () + "Verify that `cperl-forward-group-in-re' doesn't hide errors." + (skip-unless (eq cperl-test-mode #'cperl-mode)) + (let ((code "/(\\d{4})(?{2}/;") ; the regex from the bug report + (result)) + (with-temp-buffer + (insert code) + (goto-char 9) + (setq result (cperl-forward-group-in-re)) + (should (equal (car result) 'scan-error)) + (should (equal (nth 1 result) "Unbalanced parentheses")) + (should (=3D (point) 9)))) ; point remains unchanged on err= or + (let ((code "/(\\d{4})(?{2})/;") ; here all parens are balanced + (result)) + (with-temp-buffer + (insert code) + (goto-char 9) + (setq result (cperl-forward-group-in-re)) + (should (equal result nil)) + (should (=3D (point) 15))))) ; point has skipped the group + ;;; cperl-mode-tests.el ends here --=20 2.20.1 --------------0AAFCCBF2E9EE097C1EABD02--