From unknown Sun Jun 22 22:46:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time Resent-From: Mohammed Sadiq Original-Sender: "Debbugs-submit" Resent-CC: bug-cc-mode@gnu.org Resent-Date: Sat, 25 Feb 2017 10:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 25869 X-GNU-PR-Package: cc-mode X-GNU-PR-Keywords: To: 25869@debbugs.gnu.org X-Debbugs-Original-To: submit@debbugs.gnu.org Received: via spool by submit@debbugs.gnu.org id=B.148802024929894 (code B ref -1); Sat, 25 Feb 2017 10:58:01 +0000 Received: (at submit) by debbugs.gnu.org; 25 Feb 2017 10:57:29 +0000 Received: from localhost ([127.0.0.1]:55196 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cha2b-0007m5-IQ for submit@debbugs.gnu.org; Sat, 25 Feb 2017 05:57:29 -0500 Received: from us2-ob1-4.mailhostbox.com ([162.210.70.57]:36997) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cha2Z-0007lv-1M for submit@debbugs.gnu.org; Sat, 25 Feb 2017 05:57:27 -0500 Received: from rose (unknown [117.219.198.151]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sadiq@sadiqpk.org) by us2.outbound.mailhostbox.com (Postfix) with ESMTPSA id DDAD2180DBC for ; Sat, 25 Feb 2017 10:57:18 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sadiqpk.org; s=20160628; t=1488020240; bh=G+S/8UOjlNPW6p7VeI2wgmEGLhacEVvNHpaxMO1RV+I=; h=From:To:Subject:Date; b=O1Os2d0NbqKVHPbUbP1fS8LAY5XJLTF4A18rqn1nZjRCe+uxJaSkaJwfE7CJYxRv6 tntMz36vv5LyMsoa2teX9RNc570XbnRoGmNelyDjdznzRqR7alQ6EQG/A4kymNWitJ ZbUmmC+PZFOjWz3UvXCoOdfz5BLye27GAkUZBwXE= From: Mohammed Sadiq Date: Sat, 25 Feb 2017 16:26:58 +0530 Message-ID: <87a89a7d39.fsf@rose> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CMAE-Score: 0 X-CMAE-Analysis: v=2.2 cv=BqDt+cf5 c=1 sm=1 tr=0 a=jQT2mx3FtCHq7oC3UZM1Bg==:117 a=jQT2mx3FtCHq7oC3UZM1Bg==:17 a=IkcTkHD0fZMA:10 a=koBEXU2aNwIUSl8y_HgA:9 a=QEXdDO2ut3YA:10 X-Spam-Score: -0.6 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) 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. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Code starts =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D static void cc_info_panel_class_init (CcInfoPanelClass *klass) { GObjectClass *object_class =3D G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (CcInfoPanelPrivate)); object_class->dispose =3D cc_info_panel_dispose; object_class->finalize =3D cc_info_panel_finalize; g_type_ensure (CC_TYPE_INFO_OVERVIEW); } static void info_panel_setup_default_app (CcInfoPanel *self, DefaultAppData *data, guint left_attach, guint top_attach) { GtkWidget *button; GtkWidget *grid; GtkWidget *label; grid =3D WID ("default_apps_grid"); button =3D gtk_app_chooser_button_new (data->content_type); g_object_set_data (G_OBJECT (button), "cc-default-app-data", data); gtk_app_chooser_button_set_show_default_item (GTK_APP_CHOOSER_BUTTON (but= ton), TRUE); gtk_grid_attach (GTK_GRID (grid), button, left_attach, top_attach, 1, 1); g_signal_connect (G_OBJECT (button), "changed", G_CALLBACK (default_app_changed), self); gtk_widget_show (button); label =3D WID(data->label); gtk_label_set_mnemonic_widget (GTK_LABEL (label), button); } static DefaultAppData preferred_app_infos[] =3D { /* for web, we need to support text/html, application/xhtml+xml and x-scheme-handler/https, hence the "*" pattern */ { "x-scheme-handler/http", "web-label", "*" }, { "x-scheme-handler/mailto", "mail-label", NULL }, { "text/calendar", "calendar-label", NULL }, { "audio/x-vorbis+ogg", "music-label", "audio/*" }, { "video/x-ogm+ogg", "video-label", "video/*" }, { "image/jpeg", "photos-label", "image/*" } }; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Code Ends =3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Thanks Emacs : GNU Emacs 26.0.50.3 (x86_64-pc-linux-gnu, GTK+ Version 3.22.6) of 2017-02-05 Package: CC Mode 5.32.99 (C/l) Buffer Style: gnu c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-st= ring-delim gen-comment-delim syntax-properties 1-bit) current state: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (setq c-basic-offset 2 c-comment-only-line-offset '(0 . 0) c-indent-comment-alist '((anchored-comment column . 0) (end-block space . = 1) (cpp-end-block space . 2)) c-indent-comments-syntactically-p nil c-block-comment-prefix "" c-comment-prefix-regexp '((pike-mode . "//+!?\\|\\**") (awk-mode . "#+") (other . "//+\\|\\**")) c-doc-comment-style '((java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc)) c-cleanup-list '(scope-operator) c-hanging-braces-alist '((substatement-open before after) (arglist-cont-nonempty)) c-hanging-colons-alist nil c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist) c-backslash-column 48 c-backslash-max-column 72 c-special-indent-hook '(c-gnu-impose-minimum) c-label-minimum-indentation 1 c-offsets-alist '((inexpr-class . +) (inexpr-statement . +) (lambda-intro-cont . +) (inlambda . c-lineup-inexpr-block) (template-args-cont c-lineup-template-args +) (incomposition . +) (inmodule . +) (innamespace . +) (inextern-lang . +) (composition-close . 0) (module-close . 0) (namespace-close . 0) (extern-lang-close . 0) (composition-open . 0) (module-open . 0) (namespace-open . 0) (extern-lang-open . 0) (objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call + ) (objc-method-args-cont . c-lineup-ObjC-method-args) (objc-method-intro . [0]) (friend . 0) (cpp-define-intro c-lineup-cpp-define +) (cpp-macro-cont . +) (cpp-macro . [0]) (inclass . +) (stream-op . c-lineup-streamop) (arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist ) (arglist-cont c-lineup-gcc-asm-reg 0) (comment-intro c-lineup-knr-region-comment c-lineup-comment) (catch-clause . 0) (else-clause . 0) (do-while-closure . 0) (access-label . -) (case-label . 0) (substatement . +) (statement-case-intro . +) (statement . 0) (brace-entry-open . 0) (brace-list-entry . c-lineup-under-anchor) (brace-list-close . 0) (block-close . 0) (block-open . 0) (inher-cont . c-lineup-multi-inher) (inher-intro . +) (member-init-cont . c-lineup-multi-inher) (member-init-intro . +) (annotation-var-cont . +) (annotation-top-cont . 0) (topmost-intro . 0) (knr-argdecl . 0) (func-decl-cont . +) (inline-close . 0) (class-close . 0) (class-open . 0) (defun-block-intro . +) (defun-close . 0) (defun-open . 0) (c . c-lineup-C-comments) (string . c-lineup-dont-change) (topmost-intro-cont first c-lineup-topmost-intro-cont c-lineup-gnu-DEFUN-intro-cont ) (brace-list-intro . c-lineup-arglist-intro-after-paren) (brace-list-open . +) (inline-open . 0) (arglist-close . c-lineup-arglist) (arglist-intro . c-lineup-arglist-intro-after-paren) (statement-cont . +) (statement-case-open . +) (label . 0) (substatement-label . 0) (substatement-open . +) (knr-argdecl-intro . 5) (statement-block-intro . +) ) c-buffer-is-cc-mode 'c-mode c-tab-always-indent t c-syntactic-indentation t c-syntactic-indentation-in-macros t c-ignore-auto-fill '(string cpp code) c-auto-align-backslashes t c-backspace-function 'backward-delete-char-untabify c-delete-function 'delete-char c-electric-pound-behavior nil c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "gnu")) c-enable-xemacs-performance-kludge-p nil c-old-style-variable-behavior nil defun-prompt-regexp nil tab-width 8 comment-column 32 parse-sexp-ignore-comments t parse-sexp-lookup-properties t auto-fill-function nil comment-multi-line t comment-start-skip "\\(//+\\|/\\*+\\)\\s *" fill-prefix nil fill-column 70 paragraph-start "[ ]*\\(//+\\|\\**\\)[ ]*$\\|^\f" adaptive-fill-mode t adaptive-fill-regexp "[ ]*\\(//+\\|\\**\\)[ ]*\\([ ]*\\([-=E2=80=93!|#%= ;>*=C2=B7=E2=80=A2=E2=80=A3=E2=81=83=E2=97=A6]+[ ]*\\)*\\)" ) From unknown Sun Jun 22 22:46:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-cc-mode@gnu.org Resent-Date: Sun, 05 Mar 2017 22:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25869 X-GNU-PR-Package: cc-mode X-GNU-PR-Keywords: To: Mohammed Sadiq Cc: 25869@debbugs.gnu.org Received: via spool by 25869-submit@debbugs.gnu.org id=B25869.14887519013402 (code B ref 25869); Sun, 05 Mar 2017 22:12:02 +0000 Received: (at 25869) by debbugs.gnu.org; 5 Mar 2017 22:11:41 +0000 Received: from localhost ([127.0.0.1]:41455 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ckeNR-0000sn-1Q for submit@debbugs.gnu.org; Sun, 05 Mar 2017 17:11:41 -0500 Received: from ocolin.muc.de ([193.149.48.4]:10286 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1ckeNP-0000sZ-US for 25869@debbugs.gnu.org; Sun, 05 Mar 2017 17:11:40 -0500 Received: (qmail 63881 invoked by uid 3782); 5 Mar 2017 22:11:38 -0000 Received: from acm.muc.de (p548C6168.dip0.t-ipconnect.de [84.140.97.104]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 05 Mar 2017 23:11:37 +0100 Received: (qmail 12052 invoked by uid 1000); 5 Mar 2017 22:11:09 -0000 Date: Sun, 5 Mar 2017 22:11:09 +0000 Message-ID: <20170305221109.GA4137@acm> References: <87a89a7d39.fsf@rose> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a89a7d39.fsf@rose> User-Agent: Mutt/1.7.2 (2016-11-26) X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) 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). From unknown Sun Jun 22 22:46:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-cc-mode@gnu.org Resent-Date: Sun, 09 Apr 2017 14:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25869 X-GNU-PR-Package: cc-mode X-GNU-PR-Keywords: To: Mohammed Sadiq Cc: 25869@debbugs.gnu.org Received: via spool by 25869-submit@debbugs.gnu.org id=B25869.149174796524441 (code B ref 25869); Sun, 09 Apr 2017 14:27:02 +0000 Received: (at 25869) by debbugs.gnu.org; 9 Apr 2017 14:26:05 +0000 Received: from localhost ([127.0.0.1]:39848 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxDn2-0006M7-O4 for submit@debbugs.gnu.org; Sun, 09 Apr 2017 10:26:05 -0400 Received: from ocolin.muc.de ([193.149.48.4]:54614 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1cxDn0-0006LZ-Ov for 25869@debbugs.gnu.org; Sun, 09 Apr 2017 10:26:03 -0400 Received: (qmail 66217 invoked by uid 3782); 9 Apr 2017 14:25:59 -0000 Received: from acm.muc.de (p548C653A.dip0.t-ipconnect.de [84.140.101.58]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 09 Apr 2017 16:25:58 +0200 Received: (qmail 5655 invoked by uid 1000); 9 Apr 2017 14:25:15 -0000 Date: Sun, 9 Apr 2017 14:25:15 +0000 Message-ID: <20170409142515.GA5589@acm> References: <87a89a7d39.fsf@rose> <20170305221109.GA4137@acm> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170305221109.GA4137@acm> User-Agent: Mutt/1.7.2 (2016-11-26) X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hello again, Mohammed. On Sun, Mar 05, 2017 at 22:11:09 +0000, Alan Mackenzie wrote: > 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. ] OK, I think the following patch should do the trick. Would you please apply it, recompile cc-engine.el (e.g., with $ emacs -Q -batch -f batch-byte-compile cc-engine.el ), reload it (or restart Emacs), and either confirm to me that the bug has been fixed, or tell me what's still wrong about it. Thanks! diff -r 51f7a9ff5450 cc-engine.el --- a/cc-engine.el Sat Feb 25 14:39:10 2017 +0000 +++ b/cc-engine.el Sun Apr 09 14:04:38 2017 +0000 @@ -324,34 +324,41 @@ (goto-char here) nil)))))) -(defun c-end-of-macro () +(defun c-end-of-macro (&optional lim) "Go to the end of a preprocessor directive. More accurately, move the point to the end of the closest following line that doesn't end with a line continuation backslash - no check is done that the point is inside a cpp directive to begin with. +If LIM is provided, it is a limit position at which point is left +if the end of the macro doesn't occur earlier. + Note that this function might do hidden buffer changes. See the comment at the start of cc-engine.el for more info." - (if (and (cdr c-macro-cache) - (<= (point) (cdr c-macro-cache)) - (>= (point) (car c-macro-cache))) - (goto-char (cdr c-macro-cache)) - (unless (and (car c-macro-cache) - (<= (point) c-macro-cache-start-pos) - (>= (point) (car c-macro-cache))) - (setq c-macro-cache nil - c-macro-cache-start-pos nil - c-macro-cache-syntactic nil - c-macro-cache-no-comment nil)) - (while (progn - (end-of-line) - (when (and (eq (char-before) ?\\) - (not (eobp))) - (forward-char) - t))) - (when (car c-macro-cache) - (setcdr c-macro-cache (point)) - (setq c-macro-cache-syntactic nil)))) + (save-restriction + (if lim (narrow-to-region (point-min) lim)) + (if (and (cdr c-macro-cache) + (<= (point) (cdr c-macro-cache)) + (>= (point) (car c-macro-cache))) + (goto-char (cdr c-macro-cache)) + (unless (and (car c-macro-cache) + (<= (point) c-macro-cache-start-pos) + (>= (point) (car c-macro-cache))) + (setq c-macro-cache nil + c-macro-cache-start-pos nil + c-macro-cache-syntactic nil + c-macro-cache-no-comment nil)) + (while (progn + (end-of-line) + (when (and (eq (char-before) ?\\) + (not (eobp))) + (forward-char) + t))) + (when (and (car c-macro-cache) + (bolp) + (not (eq (char-before (1- (point))) ?\\))) + (setcdr c-macro-cache (point)) + (setq c-macro-cache-syntactic nil))))) (defun c-syntactic-end-of-macro () ;; Go to the end of a CPP directive, or a "safe" pos just before. @@ -1846,13 +1853,10 @@ (let (;; `rung-pos' is set to a position as early as possible in the ;; unmarked part of the simple ws region. (rung-pos (point)) next-rung-pos rung-end-pos last-put-in-sws-pos - rung-is-marked next-rung-is-marked simple-ws-end + rung-is-marked next-rung-is-marked simple-ws-end macro-start macro-end ;; `safe-start' is set when it's safe to cache the start position. - ;; It's not set if we've initially skipped over comments and line - ;; continuations since we might have gone out through the end of a - ;; macro then. This provision makes `c-forward-sws' not populate the - ;; cache in the majority of cases, but otoh is `c-backward-sws' by far - ;; more common. + ;; This is the case except when we have an unterminated block comment + ;; within a macro. safe-start) ;; Skip simple ws and do a quick check on the following character to see @@ -1928,7 +1932,33 @@ ;; Now move over any comments (x)or a CPP construct. (setq simple-ws-end (point)) - (c-forward-comments) + (setq safe-start t) + ;; Take elaborate precautions to detect an open block comment at + ;; the end of a macro. If we find one, we set `safe-start' to nil + ;; and break off any further scanning of comments. + (let ((com-begin (point)) com-end in-macro) + (when (and (c-forward-single-comment) + (setq com-end (point)) + (save-excursion + (goto-char com-begin) + (c-beginning-of-macro))) + (setq in-macro t) + (goto-char com-begin) + (if (progn (c-end-of-macro com-end) + (< (point) com-end)) + (setq safe-start nil))) + (if in-macro + (while (and safe-start + com-end (> com-end com-begin) + (setq com-begin (point)) + (when (and (c-forward-single-comment) + (setq com-end (point))) + (goto-char com-begin) + (if (progn (c-end-of-macro com-end) + (< (point) com-end)) + (setq safe-start nil)) + safe-start))) + (c-forward-comments))) (cond ((/= (point) simple-ws-end) @@ -1939,6 +1969,7 @@ ((save-excursion (and c-opt-cpp-prefix (looking-at c-opt-cpp-start) + (setq macro-start (point)) (progn (skip-chars-backward " \t") (bolp)) (or (bobp) @@ -1949,8 +1980,20 @@ (while (and (eq (char-before) ?\\) (= (forward-line 1) 0)) (end-of-line)) + (setq macro-end (point)) + ;; Check for an open block comment at the end of the macro. + (goto-char macro-start) + (let (s in-block-comment) + (while + (progn + (setq s (parse-partial-sexp (point) macro-end + nil nil s 'syntax-table)) + (< (point) macro-end)) + (setq in-block-comment + (and (elt s 4) ; in a comment + (null (elt s 7))))) ; a block comment + (if in-block-comment (setq safe-start nil))) (forward-line 1) - (setq safe-start t) ;; Don't cache at eob in case the buffer is narrowed. (not (eobp))) @@ -1958,7 +2001,6 @@ (looking-at c-noise-macro-name-re)) ;; Skip over a noise macro. (goto-char (match-end 1)) - (setq safe-start t) (not (eobp))))) ;; We've searched over a piece of non-white syntactic ws. See if this @@ -2021,8 +2063,7 @@ (if (setq rung-is-marked next-rung-is-marked) (setq rung-pos (1- (c-next-single-property-change rung-is-marked 'c-is-sws nil rung-end-pos))) - (setq rung-pos next-rung-pos)) - (setq safe-start t))) + (setq rung-pos next-rung-pos)))) ;; Make sure that the newly marked `c-in-sws' region doesn't connect to ;; another one after the point (which might occur when editing inside a -- Alan Mackenzie (Nuremberg, Germany). From unknown Sun Jun 22 22:46:33 2025 X-Loop: help-debbugs@gnu.org Subject: bug#25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time Resent-From: Mohammed Sadiq Original-Sender: "Debbugs-submit" Resent-CC: bug-cc-mode@gnu.org Resent-Date: Mon, 10 Apr 2017 01:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25869 X-GNU-PR-Package: cc-mode X-GNU-PR-Keywords: To: Alan Mackenzie Cc: 25869@debbugs.gnu.org Reply-To: Mohammed Sadiq Received: via spool by 25869-submit@debbugs.gnu.org id=B25869.149178877523485 (code B ref 25869); Mon, 10 Apr 2017 01:47:02 +0000 Received: (at 25869) by debbugs.gnu.org; 10 Apr 2017 01:46:15 +0000 Received: from localhost ([127.0.0.1]:40333 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxOPH-00066j-9j for submit@debbugs.gnu.org; Sun, 09 Apr 2017 21:46:15 -0400 Received: from us2-ob3-3.mailhostbox.com ([208.91.199.218]:41494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxOPF-00066b-T1 for 25869@debbugs.gnu.org; Sun, 09 Apr 2017 21:46:14 -0400 Received: from 172.16.214.50 (unknown [172.16.214.50]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sadiq@sadiqpk.org) by us2.outbound.mailhostbox.com (Postfix) with ESMTPSA id D8BF0C953A; Mon, 10 Apr 2017 01:46:12 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sadiqpk.org; s=20160628; t=1491788773; bh=HIallFHBxySUL+nssuVoxHQGphu/YowaTDDUN9lEPWk=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject; b=InFjq/UhDuwPyvfDhb618qTHVdP4n9sVRXio1YsMXrYqEpjfQI3Ey1LawgFOcvbvy tzRfaxUzl+7pVDcdMzWjEsvSUER2qhJL6Ei1a6c8/Ae5g5yLp0+475ZG4PwNOtL1wd +4WXGxeN/J+I4WfFv7MNR/Dh3HSkxTt0fdq2jZR0= Date: Mon, 10 Apr 2017 07:16:12 +0530 (IST) From: Mohammed Sadiq Message-ID: <917874249.2786.1491788772887@webmail.mailhostbox.com> In-Reply-To: <20170409142515.GA5589@acm> References: <87a89a7d39.fsf@rose> <20170305221109.GA4137@acm> <20170409142515.GA5589@acm> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.1-Rev14 X-Originating-Client: open-xchange-appsuite X-CMAE-Score: 0 X-CMAE-Analysis: v=2.2 cv=aawRpVgt c=1 sm=1 tr=0 a=wucOMCQccDYl2pmMnmOueA==:117 a=IkcTkHD0fZMA:10 a=5nBe4I4eMPVxmvY6dH0A:9 a=QEXdDO2ut3YA:10 a=WUJtHtwRVfAA:10 X-Spam-Score: -0.8 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) > On April 9, 2017 at 7:55 PM Alan Mackenzie wrote: > OK, I think the following patch should do the trick. Would you please > apply it, recompile cc-engine.el > [code snipped] Seems to work perfect. Tested only with the test case given for the bug. Thanks From unknown Sun Jun 22 22:46:33 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Mohammed Sadiq Subject: bug#25869: closed (Re: bug#25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time) Message-ID: References: <20170410210711.GB2053@acm> <87a89a7d39.fsf@rose> X-Gnu-PR-Message: they-closed 25869 X-Gnu-PR-Package: cc-mode Reply-To: 25869@debbugs.gnu.org Date: Mon, 10 Apr 2017 21:08:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1491858482-10585-1" This is a multi-part message in MIME format... ------------=_1491858482-10585-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim= for a long time which was filed against the cc-mode package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 25869@debbugs.gnu.org. --=20 25869: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D25869 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1491858482-10585-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 25869-done) by debbugs.gnu.org; 10 Apr 2017 21:08:00 +0000 Received: from localhost ([127.0.0.1]:41586 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxgXX-0002kV-WF for submit@debbugs.gnu.org; Mon, 10 Apr 2017 17:08:00 -0400 Received: from ocolin.muc.de ([193.149.48.4]:50932 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1cxgXW-0002kN-0t for 25869-done@debbugs.gnu.org; Mon, 10 Apr 2017 17:07:58 -0400 Received: (qmail 18096 invoked by uid 3782); 10 Apr 2017 21:07:56 -0000 Received: from acm.muc.de (p548C6C54.dip0.t-ipconnect.de [84.140.108.84]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 10 Apr 2017 23:07:56 +0200 Received: (qmail 27783 invoked by uid 1000); 10 Apr 2017 21:07:12 -0000 Date: Mon, 10 Apr 2017 21:07:12 +0000 To: 25869-done@debbugs.gnu.org Subject: Re: bug#25869: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time Message-ID: <20170410210711.GB2053@acm> References: <87a89a7d39.fsf@rose> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a89a7d39.fsf@rose> User-Agent: Mutt/1.7.2 (2016-11-26) X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Alan Mackenzie X-Primary-Address: acm@muc.de X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 25869-done Cc: Mohammed Sadiq X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Bug fixed in master. -- Alan Mackenzie (Nuremberg, Germany). ------------=_1491858482-10585-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 25 Feb 2017 10:57:29 +0000 Received: from localhost ([127.0.0.1]:55196 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cha2b-0007m5-IQ for submit@debbugs.gnu.org; Sat, 25 Feb 2017 05:57:29 -0500 Received: from us2-ob1-4.mailhostbox.com ([162.210.70.57]:36997) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cha2Z-0007lv-1M for submit@debbugs.gnu.org; Sat, 25 Feb 2017 05:57:27 -0500 Received: from rose (unknown [117.219.198.151]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sadiq@sadiqpk.org) by us2.outbound.mailhostbox.com (Postfix) with ESMTPSA id DDAD2180DBC for ; Sat, 25 Feb 2017 10:57:18 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sadiqpk.org; s=20160628; t=1488020240; bh=G+S/8UOjlNPW6p7VeI2wgmEGLhacEVvNHpaxMO1RV+I=; h=From:To:Subject:Date; b=O1Os2d0NbqKVHPbUbP1fS8LAY5XJLTF4A18rqn1nZjRCe+uxJaSkaJwfE7CJYxRv6 tntMz36vv5LyMsoa2teX9RNc570XbnRoGmNelyDjdznzRqR7alQ6EQG/A4kymNWitJ ZbUmmC+PZFOjWz3UvXCoOdfz5BLye27GAkUZBwXE= From: Mohammed Sadiq To: submit@debbugs.gnu.org Subject: CC Mode 5.32.99 (C/l); Sometimes Emacs use 100% CPU on comment-dwim for a long time X-Debbugs-Package: cc-mode Date: Sat, 25 Feb 2017 16:26:58 +0530 Message-ID: <87a89a7d39.fsf@rose> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-CMAE-Score: 0 X-CMAE-Analysis: v=2.2 cv=BqDt+cf5 c=1 sm=1 tr=0 a=jQT2mx3FtCHq7oC3UZM1Bg==:117 a=jQT2mx3FtCHq7oC3UZM1Bg==:17 a=IkcTkHD0fZMA:10 a=koBEXU2aNwIUSl8y_HgA:9 a=QEXdDO2ut3YA:10 X-Spam-Score: -0.6 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.6 (/) 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. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Code starts =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D static void cc_info_panel_class_init (CcInfoPanelClass *klass) { GObjectClass *object_class =3D G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (CcInfoPanelPrivate)); object_class->dispose =3D cc_info_panel_dispose; object_class->finalize =3D cc_info_panel_finalize; g_type_ensure (CC_TYPE_INFO_OVERVIEW); } static void info_panel_setup_default_app (CcInfoPanel *self, DefaultAppData *data, guint left_attach, guint top_attach) { GtkWidget *button; GtkWidget *grid; GtkWidget *label; grid =3D WID ("default_apps_grid"); button =3D gtk_app_chooser_button_new (data->content_type); g_object_set_data (G_OBJECT (button), "cc-default-app-data", data); gtk_app_chooser_button_set_show_default_item (GTK_APP_CHOOSER_BUTTON (but= ton), TRUE); gtk_grid_attach (GTK_GRID (grid), button, left_attach, top_attach, 1, 1); g_signal_connect (G_OBJECT (button), "changed", G_CALLBACK (default_app_changed), self); gtk_widget_show (button); label =3D WID(data->label); gtk_label_set_mnemonic_widget (GTK_LABEL (label), button); } static DefaultAppData preferred_app_infos[] =3D { /* for web, we need to support text/html, application/xhtml+xml and x-scheme-handler/https, hence the "*" pattern */ { "x-scheme-handler/http", "web-label", "*" }, { "x-scheme-handler/mailto", "mail-label", NULL }, { "text/calendar", "calendar-label", NULL }, { "audio/x-vorbis+ogg", "music-label", "audio/*" }, { "video/x-ogm+ogg", "video-label", "video/*" }, { "image/jpeg", "photos-label", "image/*" } }; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Code Ends =3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Thanks Emacs : GNU Emacs 26.0.50.3 (x86_64-pc-linux-gnu, GTK+ Version 3.22.6) of 2017-02-05 Package: CC Mode 5.32.99 (C/l) Buffer Style: gnu c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-st= ring-delim gen-comment-delim syntax-properties 1-bit) current state: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (setq c-basic-offset 2 c-comment-only-line-offset '(0 . 0) c-indent-comment-alist '((anchored-comment column . 0) (end-block space . = 1) (cpp-end-block space . 2)) c-indent-comments-syntactically-p nil c-block-comment-prefix "" c-comment-prefix-regexp '((pike-mode . "//+!?\\|\\**") (awk-mode . "#+") (other . "//+\\|\\**")) c-doc-comment-style '((java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc)) c-cleanup-list '(scope-operator) c-hanging-braces-alist '((substatement-open before after) (arglist-cont-nonempty)) c-hanging-colons-alist nil c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist) c-backslash-column 48 c-backslash-max-column 72 c-special-indent-hook '(c-gnu-impose-minimum) c-label-minimum-indentation 1 c-offsets-alist '((inexpr-class . +) (inexpr-statement . +) (lambda-intro-cont . +) (inlambda . c-lineup-inexpr-block) (template-args-cont c-lineup-template-args +) (incomposition . +) (inmodule . +) (innamespace . +) (inextern-lang . +) (composition-close . 0) (module-close . 0) (namespace-close . 0) (extern-lang-close . 0) (composition-open . 0) (module-open . 0) (namespace-open . 0) (extern-lang-open . 0) (objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call + ) (objc-method-args-cont . c-lineup-ObjC-method-args) (objc-method-intro . [0]) (friend . 0) (cpp-define-intro c-lineup-cpp-define +) (cpp-macro-cont . +) (cpp-macro . [0]) (inclass . +) (stream-op . c-lineup-streamop) (arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist ) (arglist-cont c-lineup-gcc-asm-reg 0) (comment-intro c-lineup-knr-region-comment c-lineup-comment) (catch-clause . 0) (else-clause . 0) (do-while-closure . 0) (access-label . -) (case-label . 0) (substatement . +) (statement-case-intro . +) (statement . 0) (brace-entry-open . 0) (brace-list-entry . c-lineup-under-anchor) (brace-list-close . 0) (block-close . 0) (block-open . 0) (inher-cont . c-lineup-multi-inher) (inher-intro . +) (member-init-cont . c-lineup-multi-inher) (member-init-intro . +) (annotation-var-cont . +) (annotation-top-cont . 0) (topmost-intro . 0) (knr-argdecl . 0) (func-decl-cont . +) (inline-close . 0) (class-close . 0) (class-open . 0) (defun-block-intro . +) (defun-close . 0) (defun-open . 0) (c . c-lineup-C-comments) (string . c-lineup-dont-change) (topmost-intro-cont first c-lineup-topmost-intro-cont c-lineup-gnu-DEFUN-intro-cont ) (brace-list-intro . c-lineup-arglist-intro-after-paren) (brace-list-open . +) (inline-open . 0) (arglist-close . c-lineup-arglist) (arglist-intro . c-lineup-arglist-intro-after-paren) (statement-cont . +) (statement-case-open . +) (label . 0) (substatement-label . 0) (substatement-open . +) (knr-argdecl-intro . 5) (statement-block-intro . +) ) c-buffer-is-cc-mode 'c-mode c-tab-always-indent t c-syntactic-indentation t c-syntactic-indentation-in-macros t c-ignore-auto-fill '(string cpp code) c-auto-align-backslashes t c-backspace-function 'backward-delete-char-untabify c-delete-function 'delete-char c-electric-pound-behavior nil c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "gnu")) c-enable-xemacs-performance-kludge-p nil c-old-style-variable-behavior nil defun-prompt-regexp nil tab-width 8 comment-column 32 parse-sexp-ignore-comments t parse-sexp-lookup-properties t auto-fill-function nil comment-multi-line t comment-start-skip "\\(//+\\|/\\*+\\)\\s *" fill-prefix nil fill-column 70 paragraph-start "[ ]*\\(//+\\|\\**\\)[ ]*$\\|^\f" adaptive-fill-mode t adaptive-fill-regexp "[ ]*\\(//+\\|\\**\\)[ ]*\\([ ]*\\([-=E2=80=93!|#%= ;>*=C2=B7=E2=80=A2=E2=80=A3=E2=81=83=E2=97=A6]+[ ]*\\)*\\)" ) ------------=_1491858482-10585-1--