GNU bug report logs - #16585
c-invalidate-state-cache fails if called when narrowed

Previous Next

Packages: cc-mode, emacs;

Reported by: Daniel Colascione <dancol <at> dancol.org>

Date: Wed, 29 Jan 2014 02:10:01 UTC

Severity: normal

Done: Daniel Colascione <dancol <at> dancol.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16585 in the body.
You can then email your comments to 16585 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#16585; Package emacs. (Wed, 29 Jan 2014 02:10:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Colascione <dancol <at> dancol.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 29 Jan 2014 02:10:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Colascione <dancol <at> dancol.org>
To: bug-emacs <bug-gnu-emacs <at> gnu.org>
Cc: Alan Mackenzie <acm <at> muc.de>
Subject: c-invalidate-state-cache fails if called when narrowed
Date: Tue, 28 Jan 2014 18:09:04 -0800
c-invalidate-state-cache can fail if called in a narrowed region: we end 
up calling c-clear-char-property for bob even if that's before 
point-min, causing remote-text-properties to raise (args-out-of-range 1 2).

We get into this situation when expanding yasnippet snippets; we're 
calling c-invalidate-state-cache from c-before-change.

To repro manually, first write this to some buffer.

#include <stdio.h>

void foo() {

}


Then (this is important) run M-x c-mode. After starting the mode, move 
point to inside foo's body and eval (save-restriction (narrow-to-region 
(point-at-bol) (point-at-eol)) (c-invalidate-state-cache (point))). You 
should break into the debugger.

The patch below seems correct and fixes the problem for me, but it'd be 
nice if Alan could take a look at it before I push it to trunk. The 
version of c-invalidate-state-cache in cc-mode trunk is very different.

=== modified file 'lisp/progmodes/cc-engine.el'
--- lisp/progmodes/cc-engine.el	2014-01-19 12:32:47 +0000
+++ lisp/progmodes/cc-engine.el	2014-01-29 02:07:44 +0000
@@ -3318,15 +3318,17 @@
   ;; of all parens in preprocessor constructs, except for any such 
construct
   ;; containing point.  We can then call `c-invalidate-state-cache-1' 
without
   ;; worrying further about macros and template delimiters.
-  (c-with-<->-as-parens-suppressed
-   (if (and c-state-old-cpp-beg
-	    (< c-state-old-cpp-beg here))
-       (c-with-all-but-one-cpps-commented-out
-	c-state-old-cpp-beg
-	(min c-state-old-cpp-end here)
-	(c-invalidate-state-cache-1 here))
-     (c-with-cpps-commented-out
-      (c-invalidate-state-cache-1 here)))))
+  (save-restriction
+    (widen)
+    (c-with-<->-as-parens-suppressed
+     (if (and c-state-old-cpp-beg
+              (< c-state-old-cpp-beg here))
+         (c-with-all-but-one-cpps-commented-out
+          c-state-old-cpp-beg
+          (min c-state-old-cpp-end here)
+          (c-invalidate-state-cache-1 here))
+       (c-with-cpps-commented-out
+        (c-invalidate-state-cache-1 here))))))

 (defmacro c-state-maybe-marker (place marker)
   ;; If PLACE is non-nil, return a marker marking it, otherwise nil.





Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16585; Package emacs,cc-mode. (Wed, 29 Jan 2014 02:50:02 GMT) Full text and rfc822 format available.

Message #8 received at 16585 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Daniel Colascione <dancol <at> dancol.org>
Cc: 16585 <at> debbugs.gnu.org, Alan Mackenzie <acm <at> muc.de>
Subject: Re: bug#16585: c-invalidate-state-cache fails if called when narrowed
Date: Tue, 28 Jan 2014 21:49:48 -0500
See also http://debbugs.gnu.org/13713 .

BTW, if you use

Package: emacs,cc-mode

at the start of the initial report, all mails will also go to bug-cc-mode.




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16585; Package emacs,cc-mode. (Sun, 02 Feb 2014 02:13:02 GMT) Full text and rfc822 format available.

Message #11 received at 16585 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Colascione <dancol <at> dancol.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 16585 <at> debbugs.gnu.org, Alan Mackenzie <acm <at> muc.de>, bug-cc-mode <at> gnu.org
Subject: Re: bug#16585: c-invalidate-state-cache fails if called when narrowed
Date: Sat, 01 Feb 2014 18:12:29 -0800
On 01/28/2014 06:49 PM, Glenn Morris wrote:
>
> See also http://debbugs.gnu.org/13713 .
>
> BTW, if you use
>
> Package: emacs,cc-mode
>
> at the start of the initial report, all mails will also go to bug-cc-mode.
>

Thanks. Adding bug-cc-mode manually now. I'd like to commit the change 
to Emacs before release.




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16585; Package emacs,cc-mode. (Wed, 05 Feb 2014 23:20:02 GMT) Full text and rfc822 format available.

Message #14 received at 16585 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Daniel Colascione <dancol <at> dancol.org>
Cc: bug-cc-mode <at> gnu.org, 16585 <at> debbugs.gnu.org, Glenn Morris <rgm <at> gnu.org>
Subject: Re: c-invalidate-state-cache fails if called when narrowed
Date: Wed, 5 Feb 2014 23:16:07 +0000
Hi, Daniel.

On Tue, Jan 28, 2014 at 06:09:04PM -0800, Daniel Colascione wrote:
> c-invalidate-state-cache can fail if called in a narrowed region: we end 
> up calling c-clear-char-property for bob even if that's before 
> point-min, causing remote-text-properties to raise (args-out-of-range 1 2).

> We get into this situation when expanding yasnippet snippets; we're 
> calling c-invalidate-state-cache from c-before-change.

> To repro manually, first write this to some buffer.

> #include <stdio.h>

> void foo() {

> }


> Then (this is important) run M-x c-mode. After starting the mode, move 
> point to inside foo's body and eval (save-restriction (narrow-to-region 
> (point-at-bol) (point-at-eol)) (c-invalidate-state-cache (point))). You 
> should break into the debugger.

> The patch below seems correct and fixes the problem for me, but it'd be 
> nice if Alan could take a look at it before I push it to trunk. The 
> version of c-invalidate-state-cache in cc-mode trunk is very different.

I think I'd like to check that nothing can go awry in
c-invalidate-state-cache-1 with the widened buffer.  Give me a day or
two.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16585; Package emacs,cc-mode. (Sat, 08 Feb 2014 22:48:01 GMT) Full text and rfc822 format available.

Message #17 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Daniel Colascione <dancol <at> dancol.org>
Cc: bug-emacs <bug-gnu-emacs <at> gnu.org>
Subject: Re: c-invalidate-state-cache fails if called when narrowed
Date: Sat, 8 Feb 2014 22:37:17 +0000
Hi, Daniel.

On Tue, Jan 28, 2014 at 06:09:04PM -0800, Daniel Colascione wrote:
> c-invalidate-state-cache can fail if called in a narrowed region: we end 
> up calling c-clear-char-property for bob even if that's before 
> point-min, causing remote-text-properties to raise (args-out-of-range 1 2).

> We get into this situation when expanding yasnippet snippets; we're 
> calling c-invalidate-state-cache from c-before-change.

> To repro manually, first write this to some buffer.

> #include <stdio.h>

> void foo() {

> }


> Then (this is important) run M-x c-mode. After starting the mode, move 
> point to inside foo's body and eval (save-restriction (narrow-to-region 
> (point-at-bol) (point-at-eol)) (c-invalidate-state-cache (point))). You 
> should break into the debugger.

Thanks for this crystal clear bug report, and for taking the trouble to
debug it.

> The patch below seems correct and fixes the problem for me, but it'd be 
> nice if Alan could take a look at it before I push it to trunk. The 
> version of c-invalidate-state-cache in cc-mode trunk is very different.

I don't think (but I'm not quite sure) that this patch is correct, since
it leaves c-invalidate-state-cache-1 running widened.  That might well
lead to incorrect "state cache" manipulations.  Instead I've widened the
buffer around the two calls which clear and set the text properties.
Would you please try out the following patch, which should fix the
problem.


=== modified file 'lisp/progmodes/cc-defs.el'
*** lisp/progmodes/cc-defs.el	2014-02-02 10:25:29 +0000
--- lisp/progmodes/cc-defs.el	2014-02-08 22:21:01 +0000
***************
*** 1293,1302 ****
    ;; suppressed.
    `(unwind-protect
         (c-save-buffer-state ()
! 	 (c-clear-cpp-delimiters ,beg ,end)
  	 ,`(c-with-cpps-commented-out ,@forms))
       (c-save-buffer-state ()
!        (c-set-cpp-delimiters ,beg ,end))))
  
  (defsubst c-intersect-lists (list alist)
    ;; return the element of ALIST that matches the first element found
--- 1293,1306 ----
    ;; suppressed.
    `(unwind-protect
         (c-save-buffer-state ()
! 	 (save-restriction
! 	   (widen)
! 	   (c-clear-cpp-delimiters ,beg ,end))
  	 ,`(c-with-cpps-commented-out ,@forms))
       (c-save-buffer-state ()
!        (save-restriction
! 	 (widen)
! 	 (c-set-cpp-delimiters ,beg ,end)))))
  
  (defsubst c-intersect-lists (list alist)
    ;; return the element of ALIST that matches the first element found

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16585; Package emacs,cc-mode. (Sat, 08 Feb 2014 23:01:02 GMT) Full text and rfc822 format available.

Message #20 received at 16585 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Daniel Colascione <dancol <at> dancol.org>
Cc: 16585 <at> debbugs.gnu.org
Subject: Re: bug#16585: c-invalidate-state-cache fails if called when narrowed
Date: Sat, 8 Feb 2014 22:57:02 +0000
Hi, Daniel.

On Sat, Feb 08, 2014 at 10:37:17PM +0000, Alan Mackenzie wrote:

[ .... ]

> I don't think (but I'm not quite sure) that this patch is correct, since
> it leaves c-invalidate-state-cache-1 running widened.  That might well
> lead to incorrect "state cache" manipulations.  Instead I've widened the
> buffer around the two calls which clear and set the text properties.
> Would you please try out the following patch, which should fix the
> problem.

I just forgot to say, after applying the patch, please compile first
cc-defs.el, then cc-engine.el.

-- 
Alan Mackenzie (Nuremberg, Germany).




Reply sent to Daniel Colascione <dancol <at> dancol.org>:
You have taken responsibility. (Sun, 16 Feb 2014 02:56:02 GMT) Full text and rfc822 format available.

Notification sent to Daniel Colascione <dancol <at> dancol.org>:
bug acknowledged by developer. (Sun, 16 Feb 2014 02:56:03 GMT) Full text and rfc822 format available.

Message #25 received at 16585-done <at> debbugs.gnu.org (full text, mbox):

From: Daniel Colascione <dancol <at> dancol.org>
To: Alan Mackenzie <acm <at> muc.de>, emacs-devel <at> gnu.org, 
 16585-done <at> debbugs.gnu.org
Subject: Re: [Emacs-diffs] trunk r116378: Fix c-invalidate-state-cache on
 narrowed buffers.
Date: Sat, 15 Feb 2014 18:55:00 -0800
Thanks. Seems fixed now.

On 02/09/2014 04:38 AM, Alan Mackenzie wrote:
> ------------------------------------------------------------
> revno: 116378
> revision-id: acm <at> muc.de-20140209123425-ms311yngryt01jls
> parent: rgm <at> gnu.org-20140209112300-kf0j1tnx3rj0efyn
> committer: Alan Mackenzie <acm <at> muc.de>
> branch nick: trunk
> timestamp: Sun 2014-02-09 12:34:25 +0000
> message:
>    Fix c-invalidate-state-cache on narrowed buffers.
>    progmodes/cc-defs.el (c-with-all-but-one-cpps-commented-out): Widen when
>    setting and clearing the CPP delimiter properties.
> modified:
>    lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
>    lisp/progmodes/cc-defs.el      ccdefs.el-20091113204419-o5vbwnq5f7feedwu-1226
>
>
>
> _______________________________________________
> Emacs-diffs mailing list
> Emacs-diffs <at> gnu.org
> https://lists.gnu.org/mailman/listinfo/emacs-diffs
>




Information forwarded to bug-gnu-emacs <at> gnu.org, bug-cc-mode <at> gnu.org:
bug#16585; Package emacs,cc-mode. (Sun, 16 Feb 2014 09:18:02 GMT) Full text and rfc822 format available.

Message #28 received at 16585-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: 16585-done <at> debbugs.gnu.org
Subject: Re: bug#16585: c-invalidate-state-cache fails if called when narrowed
Date: Sun, 16 Feb 2014 09:14:28 +0000
Bug fixed.

-- 
Alan Mackenzie (Nuremberg, Germany).




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 16 Mar 2014 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 101 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.