From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#28850: 26.0.90; Error running timer 'jit-lock-stealth-fontify': (error "Invalid search bound (wrong side of point)") Date: Sun, 22 Oct 2017 20:13:40 +0000 Message-ID: <20171022201340.GA16074@ACM> References: <83lgkcgzs9.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1508703573 24614 195.159.176.226 (22 Oct 2017 20:19:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 22 Oct 2017 20:19:33 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: 28850@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 22 22:19:28 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e6MiB-0002wj-LX for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Oct 2017 22:19:07 +0200 Original-Received: from localhost ([::1]:34212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6MiI-0004Eu-Rb for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Oct 2017 16:19:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6MiA-0004Ef-Oh for bug-gnu-emacs@gnu.org; Sun, 22 Oct 2017 16:19:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6Mi7-00046W-Ir for bug-gnu-emacs@gnu.org; Sun, 22 Oct 2017 16:19:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47582) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e6Mi7-00045z-Cq for bug-gnu-emacs@gnu.org; Sun, 22 Oct 2017 16:19:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e6Mi6-00044n-Vp for bug-gnu-emacs@gnu.org; Sun, 22 Oct 2017 16:19:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Oct 2017 20:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28850 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28850-submit@debbugs.gnu.org id=B28850.150870350215617 (code B ref 28850); Sun, 22 Oct 2017 20:19:02 +0000 Original-Received: (at 28850) by debbugs.gnu.org; 22 Oct 2017 20:18:22 +0000 Original-Received: from localhost ([127.0.0.1]:56263 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e6MhR-00043o-HU for submit@debbugs.gnu.org; Sun, 22 Oct 2017 16:18:21 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:38500 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1e6MhP-00043f-E5 for 28850@debbugs.gnu.org; Sun, 22 Oct 2017 16:18:20 -0400 Original-Received: (qmail 69346 invoked by uid 3782); 22 Oct 2017 20:18:15 -0000 Original-Received: from acm.muc.de (p548C6A88.dip0.t-ipconnect.de [84.140.106.136]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 22 Oct 2017 22:18:14 +0200 Original-Received: (qmail 21806 invoked by uid 1000); 22 Oct 2017 20:13:40 -0000 Content-Disposition: inline In-Reply-To: <83lgkcgzs9.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:138869 Archived-At: Hello again, Eli. On Sun, Oct 15, 2017 at 19:07:50 +0300, Eli Zaretskii wrote: > This bug is bugging me for quite some time now, and my hopes for it to > be resolved are now gone, so I finally sat down to debug it. > I have jit-lock-stealth turned on in my sessions, so whenever I > restart Emacs (e.g., when I build a new binary, or after a system > restart), and restore my session using desktop.el, Emacs starts > fontifying in the background. At some point, sometimes more than > once, I get this error: > Error running timer 'jit-lock-stealth-fontify': (error "Invalid search bound (wrong side of point)") > Today I ran Emacs under a debugger, and caught this error. The > details are below, but in a nutshell, CC mode's fontification > functions call re-search-forward with BOUND that is before point. I > hope the data below is enough to understand why that happens and fix > it; if not, please tell what additional data is needed to diagnose the > problem. The details you've given me are enough to form a strong hypothesis. Thanks. > Here're the C and Lisp backtraces from the error, and some relevant > data that explains why the error happened: [ .... ] > Lisp Backtrace: > "re-search-forward" (0x8898d0) > "c-syntactic-re-search-forward" (0x889ed0) > "c-forward-declarator" (0x88a410) > "c-font-lock-declarators" (0x88a980) > "c-font-lock-single-decl" (0x88ae50) > 0xad881a0 PVEC_COMPILED > "c-find-decl-spots" (0x88c040) > "c-font-lock-declarations" (0x88c410) > "font-lock-fontify-keywords-region" (0x88ca70) > "font-lock-default-fontify-region" (0x88ce60) > "c-font-lock-fontify-region" (0x88d230) > "font-lock-fontify-region" (0x88d578) > 0x83d89a8 PVEC_COMPILED > "run-hook-wrapped" (0x88daf0) > "jit-lock--run-functions" (0x88dee0) > "jit-lock-fontify-now" (0x88e3e0) > "jit-lock-stealth-fontify" (0x88e9d0) > "apply" (0x88e9c8) > "timer-event-handler" (0x88edb8) > (gdb) p n > $1 = 1 > (gdb) p lim > $2 = > (gdb) pp bound > 123806 > (gdb) p PT > $3 = 123811 > So point is 123811 and the BOUND argument of re-search-forward is > 123806, too small. What I think's happening is that c-forward-declarator has found a "[" which is before BOUND, but then sets point to the matching "]" which is after BOUND. It then calls c-syntactic-re-search-forward again, resulting in the error. In master's process.c, there is a "]" very close to 123811. > (gdb) up > #1 0x011cd2c9 in Fre_search_forward (regexp=XIL(0x800000000ad97598), > bound=..., noerror=..., count=...) at search.c:2271 > 2271 return search_command (regexp, bound, noerror, count, 1, 1, 0); > (gdb) pp regexp > "[;:,]\\|\\s)\\|\\(=\\|\\s(\\)" > (gdb) p current_buffer > $4 = (struct buffer *) 0xb362590 > (gdb) pp current_buffer->name_ > "process.c" > These are the regexp argument to re-search-forward and the buffer > which was being fontified. > The problem happens in c-syntactic-re-search-forward in this snippet: [ .... ] > This is called from c-forward-declarator: > ;; Search syntactically to the end of the declarator (";", > ;; ",", a closing paren, eob etc) or to the beginning of an > ;; initializer or function prototype ("=" or "\\s\("). > ;; Note that square brackets are now not also treated as > ;; initializers, since this broke when there were also > ;; initializing brace lists. > (let (found) > (while > (and (progn > ;; In the next loop, we keep searching forward whilst > ;; we find ":"s which aren't single colons inside C++ > ;; "for" statements. > (while > (and > (setq found > (c-syntactic-re-search-forward <<<<<<<<<<< > "[;:,]\\|\\s)\\|\\(=\\|\\s(\\)" > limit t t)) As already suggested, I think the bug is that there aren't enough checks that (< (point) limit) in this function. I have added them in. > It looks like c-syntactic-re-search-forward calls re-search-forward in > a loop, but perhaps it fails to update the limit to be in sync with > point that moves as the search proceeds? A further problem is that c-font-lock-declarators is calling c-forward-declarator with a limit; this is silly - if the end of a declaration runs over a jit-lock chunk boundary, we still want to fontify this declaration fully. So I've changed the LIMIT argument in the pertinent two calls to nil. (There is a third call somewhere where this LIMIT argument is the end of a macro, and it is absolutely needed). > Let me know what other data I can provide to help fix this annoying > problem. I haven't reproduced the problem, but I admit I haven't tried all that hard. Could you please try out the patch below, and let me know if it fixes the bug. > In GNU Emacs 26.0.90 (build 1, i686-pc-mingw32) > of 2017-10-12 built on HOME-C4E4A596F7 > Windowing system distributor 'Microsoft Corp.', version 5.1.2600 > Recent messages: > For information about GNU Emacs and the GNU system, type C-h C-a. [ .... ] diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 3792835752..07b9215046 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -8102,12 +8102,14 @@ c-forward-declarator ;; initializing brace lists. (let (found) (while - (and (progn + (and (< (point) limit) + (progn ;; In the next loop, we keep searching forward whilst ;; we find ":"s which aren't single colons inside C++ ;; "for" statements. (while (and + (< (point) limit) (setq found (c-syntactic-re-search-forward "[;:,]\\|\\s)\\|\\(=\\|\\s(\\)" @@ -8129,7 +8131,7 @@ c-forward-declarator (c-go-up-list-forward)) (setq brackets-after-id t)) (when found (backward-char)) - t)) + (<= (point) limit))) (list id-start id-end brackets-after-id (match-beginning 1) decorated) (goto-char here) diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 02b685d240..b8dbe3c26b 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1062,7 +1062,7 @@ c-font-lock-declarators ;; The following `while' fontifies a single declarator id each time round. ;; It loops only when LIST is non-nil. (while - (and pos (setq decl-res (c-forward-declarator limit))) + (and pos (setq decl-res (c-forward-declarator))) (setq next-pos (point) id-start (car decl-res) id-face (if (and (eq (char-after) ?\() @@ -1091,7 +1091,7 @@ c-font-lock-declarators (throw 'is-function nil)) ((not (eq got-type 'maybe)) (throw 'is-function t))) - (c-forward-declarator limit t) + (c-forward-declarator nil t) (eq (char-after) ?,)) (forward-char) (c-forward-syntactic-ws)) -- Alan Mackenzie (Nuremberg, Germany).