From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Vadim K Newsgroups: gmane.emacs.bugs Subject: bug#11841: 24.1; emacs hangs when opening cpp file with mixed eol styles Date: Wed, 25 Jul 2012 23:58:22 +0300 Message-ID: References: <83lij25d3w.fsf@gnu.org> <20120720211046.GA3822@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=e89a8f3b55aa45e56304c5adbd24 X-Trace: dough.gmane.org 1343249969 8856 80.91.229.3 (25 Jul 2012 20:59:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 25 Jul 2012 20:59:29 +0000 (UTC) Cc: 11841@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 25 22:59:28 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Su8g4-0002Bm-2E for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Jul 2012 22:59:28 +0200 Original-Received: from localhost ([::1]:54132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Su8g3-0007RH-Fw for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Jul 2012 16:59:27 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:44903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Su8fz-0007R3-Vt for bug-gnu-emacs@gnu.org; Wed, 25 Jul 2012 16:59:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Su8fy-0006eD-Jj for bug-gnu-emacs@gnu.org; Wed, 25 Jul 2012 16:59:23 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58334) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Su8fr-0006d8-G1; Wed, 25 Jul 2012 16:59:15 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Su8mP-00067c-Te; Wed, 25 Jul 2012 17:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vadim K Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 25 Jul 2012 21:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11841 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 11841-submit@debbugs.gnu.org id=B11841.134325031423466 (code B ref 11841); Wed, 25 Jul 2012 21:06:01 +0000 Original-Received: (at 11841) by debbugs.gnu.org; 25 Jul 2012 21:05:14 +0000 Original-Received: from localhost ([127.0.0.1]:39647 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Su8le-00066Q-6Y for submit@debbugs.gnu.org; Wed, 25 Jul 2012 17:05:14 -0400 Original-Received: from mail-pb0-f44.google.com ([209.85.160.44]:57436) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Su8lb-00066I-Dx for 11841@debbugs.gnu.org; Wed, 25 Jul 2012 17:05:12 -0400 Original-Received: by pbcwy7 with SMTP id wy7so1948226pbc.3 for <11841@debbugs.gnu.org>; Wed, 25 Jul 2012 13:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=wLVhdALdORf1PZHcxXxcNvHBBkRGHU3aXWV2MgStp2I=; b=RuMDDL1nGJU+gbX87u/s63Myr9sPjF4o0ateeQ00IKO5cSMCLmZZvlE9x4/58xZLfL 6fzOx9x0PNfxdLmypPEtUThLuDlQIn+9brGSI1rj3gV/ipicFsrAA7PFzRnrlRx0jBeG 77kvpe7WGWJyyLnGeHcNtlfMfjXPAh+u5rXikOP0HWQ48H9WilgYwgAnB0mD7LQiFGZV JpsNeHNO5aJwQGBK7LQl7YnTvCW2RseZgMGzjyCw4dPpuvgXlkPV8voSjRAf2cYVtQB9 b0OnSf3USET+P4RqgK2tf6PHvsnbKSOeA2l0BqHkh55hyQqn9nodsf3KdJMEPhEjjgdB u2xw== Original-Received: by 10.68.217.37 with SMTP id ov5mr56373587pbc.12.1343249902330; Wed, 25 Jul 2012 13:58:22 -0700 (PDT) Original-Received: by 10.68.74.70 with HTTP; Wed, 25 Jul 2012 13:58:22 -0700 (PDT) In-Reply-To: <20120720211046.GA3822@acm.acm> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:62381 Archived-At: --e89a8f3b55aa45e56304c5adbd24 Content-Type: multipart/alternative; boundary=e89a8f3b55aa45e55e04c5adbd22 --e89a8f3b55aa45e55e04c5adbd22 Content-Type: text/plain; charset=ISO-8859-1 Hello Alan, I've tried your patch and it worked fine for the original posted bad.cpp file. However I have found a variation of that file that still causes emacs to hang (see attached bad2.cpp). Vadim Kalviss On Sat, Jul 21, 2012 at 12:10 AM, Alan Mackenzie wrote: > Hello, Eli and Vadim. > > On Mon, Jul 02, 2012 at 07:42:11PM +0300, Eli Zaretskii wrote: > > > Date: Sun, 1 Jul 2012 20:51:43 -0400 > > > From: Vadim K > > > > Emacs hangs forever with 100% cpu usage when I'm trying to open a > > > specific cpp file (see attached bad.cpp). The bad.cpp file has > > > Windows end of line style (0D 0A) everywhere except in the line next > > > to the last one. > > > Inconsistent EOL format is not the problem, it is just the trigger. > > The problem seems to be that the C Mode is unable to process a buffer > > where some lines end in a ^M^J (a.k.a. CRLF) instead of a mere LF > > (newline). To see that, make the EOL format of the test file > > consistently CRLF, then do this: > > > emacs -Q > > M-x find-file-literally RET bad.cpp RET > > M-x normal-mode > > > Emacs will hang. > > > I attached a debugger and produced the backtrace below. By doing > > "finish" until it hanged, I found out that it infloops inside > > c-backward-sws. HTH. > > > > Lisp Backtrace: > > "forward-comment" (0x8890b8) > > "c-backward-sws" (0x889318) > > "c-at-macro-vsemi-p" (0x889568) > > "byte-code" (0x889740) > > "c-crosses-statement-barrier-p" (0x889af8) > > "byte-code" (0x889ce0) > > "c-beginning-of-statement-1" (0x88a0e8) > > "byte-code" (0x88a2c0) > > "c-beginning-of-decl-1" (0x88a668) > > "c-font-lock-enclosing-decls" (0x88a8c8) > > "font-lock-fontify-keywords-region" (0x88ab38) > > "font-lock-default-fontify-region" (0x88ad98) > > "c-font-lock-fontify-region" (0x88aff8) > > "font-lock-fontify-region" (0x88b38c) > > "run-hook-with-args" (0x88b388) > > "byte-code" (0x88b560) > > "jit-lock-fontify-now" (0x88b968) > > "jit-lock-function" (0x88bcf4) > > The following patch should, I hope, fix the problem. Vadim, would you > try it out, please, and report back.. > > > diff -r 1adcc48506f9 cc-engine.el > --- a/cc-engine.el Sun Apr 22 09:42:29 2012 +0000 > +++ b/cc-engine.el Fri Jul 20 20:52:39 2012 +0000 > @@ -1455,7 +1455,12 @@ > (not (bobp)) > > (if (let (open-paren-in-column-0-is-defun-start) > - (forward-comment -1)) > + (or (forward-comment -1) > + ;; Cope specifically with ^M^J here - > + ;; forward-comment gets stuck at ^Ms. > + (and (eq (char-before) ?\r) > + (progn (backward-char) > + (forward-comment -1))))) > (if (looking-at "\\*/") > ;; Emacs <= 20 and XEmacs move back over the > ;; closer of a block comment that lacks an opener. > > > -- > Alan Mackenzie (Nuremberg, Germany). > --e89a8f3b55aa45e55e04c5adbd22 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello Alan,


I've tried your patch and= it worked fine for the original posted bad.cpp file. However I have found = a variation of that file that still causes emacs to hang (see attached bad2= .cpp).=A0


Vadim Kalviss

On Sat, Jul 21, 2012 at 12:10 AM, Alan Mackenzie <acm@muc.de> wrote:
Hello, Eli and Vadim.

On Mon, Jul 02, 2012 at 07:42:11PM +0300, Eli Zaretskii wrote:
> > Date: Sun, 1 Jul 2012 20:51:43 -0400
> > From: Vadim K <vadimsks@= gmail.com>

> > Emacs hangs forever with 100% cpu usage when I'm trying to op= en a
> > specific cpp file (see attached bad.cpp). The bad.cpp file has > > Windows end of line style (0D 0A) everywhere except in the line n= ext
> > to the last one.

> Inconsistent EOL format is not the problem, it is just the trigger. > The problem seems to be that the C Mode is unable to process a buffer<= br> > where some lines end in a ^M^J (a.k.a. CRLF) instead of a mere LF
> (newline). =A0To see that, make the EOL format of the test file
> consistently CRLF, then do this:

> =A0 emacs -Q
> =A0 M-x find-file-literally RET bad.cpp RET
> =A0 M-x normal-mode

> Emacs will hang.

> I attached a debugger and produced the backtrace below. =A0By doing > "finish" until it hanged, I found out that it infloops insid= e
> c-backward-sws. =A0HTH.


> Lisp Backtrace:
> "forward-comment" (0x8890b8)
> "c-backward-sws" (0x889318)
> "c-at-macro-vsemi-p" (0x889568)
> "byte-code" (0x889740)
> "c-crosses-statement-barrier-p" (0x889af8)
> "byte-code" (0x889ce0)
> "c-beginning-of-statement-1" (0x88a0e8)
> "byte-code" (0x88a2c0)
> "c-beginning-of-decl-1" (0x88a668)
> "c-font-lock-enclosing-decls" (0x88a8c8)
> "font-lock-fontify-keywords-region" (0x88ab38)
> "font-lock-default-fontify-region" (0x88ad98)
> "c-font-lock-fontify-region" (0x88aff8)
> "font-lock-fontify-region" (0x88b38c)
> "run-hook-with-args" (0x88b388)
> "byte-code" (0x88b560)
> "jit-lock-fontify-now" (0x88b968)
> "jit-lock-function" (0x88bcf4)

The following patch should, I hope, fix the problem. =A0Vadim, would = you
try it out, please, and report back..


diff -r 1adcc48506f9 cc-engine.el
--- a/cc-engine.el =A0 =A0 =A0Sun Apr 22 09:42:29 2012 +0000
+++ b/cc-engine.el =A0 =A0 =A0Fri Jul 20 20:52:39 2012 +0000
@@ -1455,7 +1455,12 @@
=A0 =A0 =A0 =A0 =A0 =A0 (not (bobp))

=A0 =A0 =A0 =A0 =A0 =A0 (if (let (open-paren-in-column-0-is-defun-start) - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-comment -1))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (or (forward-comment -1)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; Cope specifically with ^M^J he= re -
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; forward-comment gets stuck at = ^Ms.
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (and (eq (char-before) ?\r)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(progn (backward-char)=
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-= comment -1)))))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (looking-at "\\*/")
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; Emacs <=3D 20 and XEmacs move= back over the
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; closer of a block comment that l= acks an opener.


--
Alan Mackenzie (Nuremberg, Germany).

--e89a8f3b55aa45e55e04c5adbd22-- --e89a8f3b55aa45e56304c5adbd24 Content-Type: text/x-c++src; charset=US-ASCII; name="bad2.cpp" Content-Disposition: attachment; filename="bad2.cpp" Content-Transfer-Encoding: base64 X-Attachment-Id: f_h52warek0 DQpzdHJ1Y3QgSXNGTkVxIDogcHVibGljIFVTRV9TVEQ6OmJpbmFyeV9mdW5jdGlvbiA8U0ZpbGVE ZXNjLCBTRmlsZURlc2MsIGJvb2w+DQp7DQogICByZXN1bHRfdHlwZSBvcGVyYXRvciggKSAoIGNv bnN0IGZpcnN0X2FyZ3VtZW50X3R5cGUmIGEsIA0KCQkJCSBjb25zdCBzZWNvbmRfYXJndW1lbnRf dHlwZSYgYiApIGNvbnN0DQogICB7DQogICB9DQp9Ow0KDQoNCnZvaWQgQ0E6OkV4ZWN1dGUoQ0Qg KnBDdXJTdGF0ZSkNCnsNCg0KICAgICAgICAgICAgCQlyc3AuQWRkRmlsZUluZm8oZW50cnktPmRf bmFtZSwgc3Quc3Rfc2l6ZSk7CgkJfQ0K --e89a8f3b55aa45e56304c5adbd24--