Subject: Re: bug#28233: CC Mode 5.33 (C/*l); Emacs may get stuck with 100% CPU

From: Alan Mackenzie <[email-masked]>
Date: Sat, 26 Aug 2017 17:29:06 +0000

Hello, Mohammed.

On Fri, Aug 25, 2017 at 21:00:52 +0530, Mohammed Sadiq wrote:

> Emacs always get stuck when writing some code (given below), using 100 % CPU for
> (probably) limitless time:

> How to reproduce:

> 1. Open a new empty file: emacs -Q test.c
> 2. Write the following (| is where the point is)
>    #include<|
> 3. Delete the content: C-a C-k
> 4. Try to write the same again:
>    #include<|

> Result:
>   At the 4th step, after typing #,GNU Emacs begins to use full CPU and
>   does nothing. Though this can be cancelled using C-g.

Yes.  There is a bug in some cache handling code for macros, which
results in that cache thinking there's still a macro after it's been
deleted.

Thanks indeed for the bug report!

Would you please apply the following patch, then confirm to me that it's
fixed the problem, or else tell me what's still not working.  Thanks!

diff -r dbf1a31b3959 cc-engine.el
--- a/cc-engine.el	Tue Aug 22 16:38:44 2017 +0000
+++ b/cc-engine.el	Sat Aug 26 17:24:49 2017 +0000
@@ -250,7 +250,7 @@
   ;; Called from a before-change function.  If the change region is before or
   ;; in the macro characterized by `c-macro-cache' etc., nullify it
   ;; appropriately.  BEG and END are the standard before-change-functions
-  ;; parameters.  END isn't used.
+  ;; parameters.
   (cond
    ((null c-macro-cache))
    ((< beg (car c-macro-cache))
@@ -258,6 +258,12 @@
 	  c-macro-cache-start-pos nil
 	  c-macro-cache-syntactic nil
 	  c-macro-cache-no-comment nil))
+   ((and (= beg (car c-macro-cache))
+	 (> end beg))
+    (setq c-macro-cache nil
+	  c-macro-cache-start-pos nil
+	  c-macro-cache-syntactic nil
+	  c-macro-cache-no-comment nil))
    ((and (cdr c-macro-cache)
 	 (< beg (cdr c-macro-cache)))
     (setcdr c-macro-cache nil)

[ CC Mode configuration dump appreciated, but snipped. ]

-- 
Alan Mackenzie (Nuremberg, Germany).