* bug#16585: c-invalidate-state-cache fails if called when narrowed
@ 2014-01-29 2:09 Daniel Colascione
2014-01-29 2:49 ` Glenn Morris
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Daniel Colascione @ 2014-01-29 2:09 UTC (permalink / raw)
To: 16585; +Cc: Alan Mackenzie
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#16585: c-invalidate-state-cache fails if called when narrowed
2014-01-29 2:09 bug#16585: c-invalidate-state-cache fails if called when narrowed Daniel Colascione
@ 2014-01-29 2:49 ` Glenn Morris
2014-02-02 2:12 ` Daniel Colascione
2014-02-05 23:16 ` Alan Mackenzie
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Glenn Morris @ 2014-01-29 2:49 UTC (permalink / raw)
To: Daniel Colascione; +Cc: 16585, Alan Mackenzie
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#16585: c-invalidate-state-cache fails if called when narrowed
2014-01-29 2:49 ` Glenn Morris
@ 2014-02-02 2:12 ` Daniel Colascione
2014-02-16 9:14 ` Alan Mackenzie
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Colascione @ 2014-02-02 2:12 UTC (permalink / raw)
To: Glenn Morris; +Cc: 16585, acm
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#16585: c-invalidate-state-cache fails if called when narrowed
2014-01-29 2:09 bug#16585: c-invalidate-state-cache fails if called when narrowed Daniel Colascione
2014-01-29 2:49 ` Glenn Morris
@ 2014-02-05 23:16 ` Alan Mackenzie
2014-02-08 22:37 ` Alan Mackenzie
[not found] ` <20140208223717.GA4063@acm.acm>
3 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2014-02-05 23:16 UTC (permalink / raw)
To: Daniel Colascione; +Cc: 16585
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).
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#16585: c-invalidate-state-cache fails if called when narrowed
2014-01-29 2:09 bug#16585: c-invalidate-state-cache fails if called when narrowed Daniel Colascione
2014-01-29 2:49 ` Glenn Morris
2014-02-05 23:16 ` Alan Mackenzie
@ 2014-02-08 22:37 ` Alan Mackenzie
[not found] ` <20140208223717.GA4063@acm.acm>
3 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2014-02-08 22:37 UTC (permalink / raw)
To: Daniel Colascione; +Cc: 16585
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))))
\f
(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)))))
\f
(defsubst c-intersect-lists (list alist)
;; return the element of ALIST that matches the first element found
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#16585: c-invalidate-state-cache fails if called when narrowed
[not found] ` <20140208223717.GA4063@acm.acm>
@ 2014-02-08 22:57 ` Alan Mackenzie
0 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2014-02-08 22:57 UTC (permalink / raw)
To: Daniel Colascione; +Cc: 16585
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).
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#16585: c-invalidate-state-cache fails if called when narrowed
2014-02-02 2:12 ` Daniel Colascione
@ 2014-02-16 9:14 ` Alan Mackenzie
0 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2014-02-16 9:14 UTC (permalink / raw)
To: 16585-done
Bug fixed.
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-02-16 9:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-29 2:09 bug#16585: c-invalidate-state-cache fails if called when narrowed Daniel Colascione
2014-01-29 2:49 ` Glenn Morris
2014-02-02 2:12 ` Daniel Colascione
2014-02-16 9:14 ` Alan Mackenzie
2014-02-05 23:16 ` Alan Mackenzie
2014-02-08 22:37 ` Alan Mackenzie
[not found] ` <20140208223717.GA4063@acm.acm>
2014-02-08 22:57 ` Alan Mackenzie
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.