Subject: Re: bug#25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time

From: Alan Mackenzie <[email-masked]>
Date: Sun, 5 Mar 2017 22:11:09 +0000

Hello, Mohammed.

On Sat, Feb 25, 2017 at 16:26:58 +0530, Mohammed Sadiq wrote:

> When writing code, I encountered a bug in comment-dwim, which takes 100%
> CPU for a long time, and then failing to comment the line.

> How to reproduce using the following code:
> 1. Mark some line in the first function.
>    Eg: g_type_ensure (CC_TYPE_INFO_OVERVIEW);
>    do C-a C-SPC C-e
> 2. Do comment-dwim
>    ie, M-;

> The code that produced the issue is the following:
> Note: if I remove the array at the bottom of code, M-; begins to work
> fine. The code follows is an excerpt from gnome-control-center.

First of all, thank you for such a detailed and complete bug report.

The bug that this code triggers has been in CC Mode for quite some
while, but it takes a rather unusual combination of constructs in the C
source to trigger it.

What is happening is that the M-; first inserts "/* ".  This causes all
the code up to the next terminating "*/" to become, temporarily, a
comment.  One of CC Mode's functions moves forward over this comment.  A
bit later on, it has cause to move backwards over it, but only moves as
far back as the "/*" which was the original start of the second comment
(but is now merely part of the first comment).  This is the bug, I
think.

This might be quite tricky to fix.  Give me a little time, please!

[ snip source code ]

> Thanks

[ CC Mode configuration dump appreciated, but snipped. ]

-- 
Alan Mackenzie (Nuremberg, Germany).