From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Newsgroups: gmane.emacs.bugs Subject: bug#47191: File as attachment Date: Mon, 29 Mar 2021 09:12:32 +0000 Message-ID: <20210329091232.Horde.6ZTf_gDQ6ZxXrmi21DY3MwN@cloud.cosinux.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12856"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Horde Application Framework 5 Cc: acm@muc.de, 47191@debbugs.gnu.org To: Eli Zaretskii , Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 29 11:13:18 2021 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 1lQnxV-0003Ga-PQ for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 29 Mar 2021 11:13:17 +0200 Original-Received: from localhost ([::1]:52076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQnxU-00050H-7d for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 29 Mar 2021 05:13:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQnxH-000508-KR for bug-gnu-emacs@gnu.org; Mon, 29 Mar 2021 05:13:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36283) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lQnxG-0006lN-KZ for bug-gnu-emacs@gnu.org; Mon, 29 Mar 2021 05:13:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lQnxG-0006hB-Bq for bug-gnu-emacs@gnu.org; Mon, 29 Mar 2021 05:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Damien Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 Mar 2021 09:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47191 X-GNU-PR-Package: emacs Original-Received: via spool by 47191-submit@debbugs.gnu.org id=B47191.161700916225709 (code B ref 47191); Mon, 29 Mar 2021 09:13:02 +0000 Original-Received: (at 47191) by debbugs.gnu.org; 29 Mar 2021 09:12:42 +0000 Original-Received: from localhost ([127.0.0.1]:47829 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQnwv-0006ga-HV for submit@debbugs.gnu.org; Mon, 29 Mar 2021 05:12:42 -0400 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:43187) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lQnws-0006gM-UT for 47191@debbugs.gnu.org; Mon, 29 Mar 2021 05:12:40 -0400 Original-Received: from cloud.cosinux.org (host-85-201-69-35.dynamic.voo.be [85.201.69.35]) (Authenticated sender: dam@cosinux.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 85C02200004; Mon, 29 Mar 2021 09:12:32 +0000 (UTC) In-Reply-To: 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:203226 Archived-At: The patch fixes the problem for me. Also, before the patch emacs would freeze regularly due to eglot formatting the cpp function definintions when moving past one, and everything seems ok now. Thanks a lot for helping me and fixing this ! "Alan Mackenzie" acm@muc.de – 20 mars 2021 20:30 > Hello, Eli and Damien. > > On Fri, Mar 19, 2021 at 17:28:03 +0200, Eli Zaretskii wrote: > > > From: Damien > > > Date: Wed, 17 Mar 2021 07:48:39 +0000 > > > > Also here is the file as attachment to make sure it was not a copy/paste error > > > Thanks. > > > Emacs infloops in redisplay when visiting this file, because > > fontification of this file infloops, and that happens on the master > > branch as well, so it has nothing to do with native-compilation > > branch. The infloop seems to be in c-forward-name, I attach the > > backtrace below. > > > Alan, could you please look into this? > > [ .... ] > > > Lisp Backtrace: > > "c-forward-name" (0x8234a0) > > "c-forward-type" (0x823e30) > > "c-forward-decl-or-cast-1" (0x825240) > > 0x6d7e6e0 PVEC_COMPILED > > "c-find-decl-spots" (0x826d30) > > "c-font-lock-declarations" (0x8273c8) > > "font-lock-fontify-keywords-region" (0x827b40) > > "font-lock-default-fontify-region" (0x828190) > > "c-font-lock-fontify-region" (0x828808) > > "font-lock-fontify-region" (0x828dc8) > > 0x6fdbd30 PVEC_COMPILED > > "run-hook-wrapped" (0x829690) > > "jit-lock--run-functions" (0x829cc0) > > "jit-lock-fontify-now" (0x82a3e8) > > "jit-lock-function" (0x82aa68) > > "redisplay_internal (C function)" (0x0) > > The trigger for the bug was a CC Mode "name" (the return type) which was > longer than 500 characters. This 500 was a search limit introduced for > performance reasons around the turn of the year. Part of the bug was > that when a forward scanning macro (c-forward-syntactic-ws) was given a > limit less than point, point was set back to that limit, causing the > loop. > > The fix involves not ever moving point backwards in > c-forward-syntactic-ws, and recalculating the 500 character limit after > scanning a template construct; template expressions can easily be very > long. > > Damien, would you please try out the following patch (the files are in > ..../emacs/lisp/progmodes) on your real C++ source code, and either > confirm to us that the bug is fixed, or tell us what still needs fixing. > After applying the patch, please recompile _all_ of CC Mode (the files > ..../emacs/progmodes/cc-*.el), since two macros have been amended. If > you want any help with the patching or byte compiling, feel free to send > me private mail. Thanks! > > Here's the patch: > > > > diff -r 11350de71bc6 cc-defs.el > --- a/cc-defs.el Sat Mar 06 15:11:24 2021 +0000 > +++ b/cc-defs.el Sat Mar 20 20:08:58 2021 +0000 > @@ -656,14 +656,16 @@ > > LIMIT sets an upper limit of the forward movement, if specified. If > LIMIT or the end of the buffer is reached inside a comment or > -preprocessor directive, the point will be left there. > +preprocessor directive, the point will be left there. If point starts > +on the wrong side of LIMIT, it stays unchanged. > > Note that this function might do hidden buffer changes. See the > comment at the start of cc-engine.el for more info." > (if limit > - `(save-restriction > - (narrow-to-region (point-min) (or ,limit (point-max))) > - (c-forward-sws)) > + `(when (< (point) (or ,limit (point-max))) > + (save-restriction > + (narrow-to-region (point-min) (or ,limit (point-max))) > + (c-forward-sws))) > '(c-forward-sws))) > > (defmacro c-backward-syntactic-ws (&optional limit) > @@ -675,14 +677,16 @@ > > LIMIT sets a lower limit of the backward movement, if specified. If > LIMIT is reached inside a line comment or preprocessor directive then > -the point is moved into it past the whitespace at the end. > +the point is moved into it past the whitespace at the end. If point > +starts on the wrong side of LIMIT, it stays unchanged. > > Note that this function might do hidden buffer changes. See the > comment at the start of cc-engine.el for more info." > (if limit > - `(save-restriction > - (narrow-to-region (or ,limit (point-min)) (point-max)) > - (c-backward-sws)) > + `(when (> (point) (or ,limit (point-min))) > + (save-restriction > + (narrow-to-region (or ,limit (point-min)) (point-max)) > + (c-backward-sws))) > '(c-backward-sws))) > > (defmacro c-forward-sexp (&optional count) > diff -r 11350de71bc6 cc-engine.el > --- a/cc-engine.el Sat Mar 06 15:11:24 2021 +0000 > +++ b/cc-engine.el Sat Mar 20 20:08:58 2021 +0000 > @@ -8318,7 +8318,7 @@ > ;; o - nil if no name is found; > ;; o - 'template if it's an identifier ending with an angle bracket > ;; arglist; > - ;; o - 'operator of it's an operator identifier; > + ;; o - 'operator if it's an operator identifier; > ;; o - t if it's some other kind of name. > ;; > ;; This function records identifier ranges on > @@ -8338,6 +8338,7 @@ > (lim+ (c-determine-+ve-limit 500))) > (while > (and > + (< (point) lim+) > (looking-at c-identifier-key) > > (progn > @@ -8387,23 +8388,28 @@ > ;; '*', '&' or a name followed by ":: *", > ;; where each can be followed by a sequence > ;; of `c-opt-type-modifier-key'. > - (while (cond ((looking-at "[*&]") > - (goto-char (match-end 0)) > - t) > - ((looking-at c-identifier-start) > - (and (c-forward-name) > - (looking-at "::") > - (progn > - (goto-char (match-end 0)) > - (c-forward-syntactic-ws lim+) > - (eq (char-after) ?*)) > - (progn > - (forward-char) > - t)))) > + (while > + (and > + (< (point) lim+) > + (cond ((looking-at "[*&]") > + (goto-char (match-end 0)) > + t) > + ((looking-at c-identifier-start) > + (and (c-forward-name) > + (looking-at "::") > + (progn > + (goto-char (match-end 0)) > + (c-forward-syntactic-ws lim+) > + (eq (char-after) ?*)) > + (progn > + (forward-char) > + t))))) > (while (progn > (c-forward-syntactic-ws lim+) > (setq pos (point)) > - (looking-at c-opt-type-modifier-key)) > + (and > + (<= (point) lim+) > + (looking-at c-opt-type-modifier-key))) > (goto-char (match-end 1)))))) > > ((looking-at c-overloadable-operators-regexp) > @@ -8449,6 +8455,9 @@ > ;; Maybe an angle bracket arglist. > (when (let (c-last-identifier-range) > (c-forward-<>-arglist nil)) > + ;; <> arglists can legitimately be very long, so recalculate > + ;; `lim+'. > + (setq lim+ (c-determine-+ve-limit 500)) > > (c-forward-syntactic-ws lim+) > (unless (eq (char-after) ?\() > > >