From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#47191: File as attachment Date: Sat, 20 Mar 2021 20:30:54 +0000 Message-ID: References: <20210316152422.Horde.TO1-W1qcebctbn5jgBLPqE8@cloud.cosinux.org> <20210317074839.Horde.tzg5aK2BSJ1jmvbf90J_s1S@cloud.cosinux.org> <83blbfduyk.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23052"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, 47191@debbugs.gnu.org, Damien To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 20 21:32:43 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 1lNiH5-0005tO-ED for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Mar 2021 21:32:43 +0100 Original-Received: from localhost ([::1]:48650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNiH4-0004uA-2m for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Mar 2021 16:32:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNiGQ-0004hU-HW for bug-gnu-emacs@gnu.org; Sat, 20 Mar 2021 16:32:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNiGQ-00022p-9C for bug-gnu-emacs@gnu.org; Sat, 20 Mar 2021 16:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lNiGQ-0001Jd-57 for bug-gnu-emacs@gnu.org; Sat, 20 Mar 2021 16:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 Mar 2021 20:32: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.16162722654993 (code B ref 47191); Sat, 20 Mar 2021 20:32:02 +0000 Original-Received: (at 47191) by debbugs.gnu.org; 20 Mar 2021 20:31:05 +0000 Original-Received: from localhost ([127.0.0.1]:53176 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lNiFV-0001IS-2Q for submit@debbugs.gnu.org; Sat, 20 Mar 2021 16:31:05 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:60769 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lNiFQ-0001Hw-RH for 47191@debbugs.gnu.org; Sat, 20 Mar 2021 16:31:04 -0400 Original-Received: (qmail 82123 invoked by uid 3782); 20 Mar 2021 20:30:54 -0000 Original-Received: from acm.muc.de (p2e5d55b2.dip0.t-ipconnect.de [46.93.85.178]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 20 Mar 2021 21:30:54 +0100 Original-Received: (qmail 8752 invoked by uid 1000); 20 Mar 2021 20:30:54 -0000 Content-Disposition: inline In-Reply-To: <83blbfduyk.fsf@gnu.org> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de 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:202750 Archived-At: 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) ?\() -- Alan Mackenzie (Nuremberg, Germany).