From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Herbert Euler" Newsgroups: gmane.emacs.devel Subject: Re: C++ mode and c-beginning-of-current-token Date: Wed, 16 May 2007 16:01:05 +0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: sea.gmane.org 1179302586 11657 80.91.229.12 (16 May 2007 08:03:06 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 16 May 2007 08:03:06 +0000 (UTC) Cc: acm@muc.de, emacs-devel@gnu.org To: herberteuler@hotmail.com, monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 16 10:03:03 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HoETM-0008GW-Rq for ged-emacs-devel@m.gmane.org; Wed, 16 May 2007 10:03:01 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HoEbI-0000C2-L1 for ged-emacs-devel@m.gmane.org; Wed, 16 May 2007 04:11:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HoEZn-00086Y-HX for emacs-devel@gnu.org; Wed, 16 May 2007 04:09:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HoEZl-00084n-5w for emacs-devel@gnu.org; Wed, 16 May 2007 04:09:38 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HoEZk-00084R-N1 for emacs-devel@gnu.org; Wed, 16 May 2007 04:09:36 -0400 Original-Received: from bay0-omc2-s6.bay0.hotmail.com ([65.54.246.142]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HoERl-0001oy-Av for emacs-devel@gnu.org; Wed, 16 May 2007 04:01:22 -0400 Original-Received: from hotmail.com ([65.55.154.113]) by bay0-omc2-s6.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Wed, 16 May 2007 01:01:10 -0700 Original-Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 16 May 2007 01:01:09 -0700 Original-Received: from 65.55.154.123 by by143fd.bay143.hotmail.msn.com with HTTP; Wed, 16 May 2007 08:01:05 GMT X-Originating-IP: [216.145.54.7] X-Originating-Email: [herberteuler@hotmail.com] X-Sender: herberteuler@hotmail.com In-Reply-To: X-OriginalArrivalTime: 16 May 2007 08:01:09.0844 (UTC) FILETIME=[5D38D940:01C79790] X-detected-kernel: Windows 2000 SP4, XP SP1+ X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:71150 Archived-At: >> > If `parse-sexp-lookup-properties' is t, `skip-syntax-backward' would >> > not return -1, but signaling an error in some cases. >> >>Sounds like a bug in skip-syntax-backward. > >In the previous message, I described a way to reproduce the error: > >0. Start Emacs with emacs -Q. > >1. Visit a new, empty C++ file. > >2. Insert the following characters: > >#include > >The error happens when inserting the second character, i. Now let's >remember the following two facts: > >a) `parse-sexp-lookup-properties' is t in a c++-mode buffer, > >b) `after-change-functions' contains `c-after-change', which leads to > invocation of `skip-syntax-backward' in the way > (skip-syntax-backward ".()" nil), > >c) the c++-mode buffer is not multibyte. > >Now, with fact a), code in syntax.c will update interval information, >including the function `skip_syntaxes', invoked by >`Fskip_syntax_backward'. Take a look at how `skip_syntaxes' works, we >might know how the error happens. > >The code that skips characters and updates interval information uses a >variable `pos', and below is how it updates interval information: > > while (1) > { > if (p <= stop) > { > if (p <= endp) > break; > p = GPT_ADDR; > stop = endp; > } > if (! fastmap[(int) SYNTAX (p[-1])]) > break; > p--, pos--, pos_byte--; > UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1); > } > >As you see, it updates interval information at position (pos - 1). At >an earlier stage in this function, `pos' is initialized to the buffer >position: > > int start_point = PT; > int pos = PT; > int pos_byte = PT_BYTE; > unsigned char *p = PT_ADDR, *endp, *stop; > >Since we're inserting the second character, `PT' is now 2, and so the >initial value of `pos' is 2. Later, before updating interval >information, `pos' is self-decreased, so (pos - 1) = (1 - 1) = 0. > >Here is how `UPDATE_SYNTAX_TABLE_BACKWARD' is defined: > > #define UPDATE_SYNTAX_TABLE_BACKWARD(charpos) \ > (parse_sexp_lookup_properties \ > && (charpos) < gl_state.b_property \ > ? (update_syntax_table ((charpos) + gl_state.offset, -1, 0, \ > gl_state.object), \ > 1) \ > : 0) > >It invokes `update_syntax_table' with `charpos' set to (charpos + >gl_state.offset). `charpos' is 0 there, and gl_state.offset is 0. So >`update_syntax_table' is invoked with `charpos' set to 0. Finally, >`update_interval' is invoked in `update_syntax_table': > > void > update_syntax_table (charpos, count, init, object) > int charpos, count, init; > Lisp_Object object; > { > /* ... ... */ > i = update_interval (i, charpos); > >So `update_interval' is invoked with `pos' set to 0: > > INTERVAL > update_interval (i, pos) > register INTERVAL i; > int pos; > { > if (NULL_INTERVAL_P (i)) > return NULL_INTERVAL; > > while (1) > { > if (pos < i->position) > { > /* Move left. */ > if (pos >= i->position - TOTAL_LENGTH (i->left)) > { > i->left->position = i->position - TOTAL_LENGTH (i->left) > + LEFT_TOTAL_LENGTH (i->left); > i = i->left; /* Move to the left child */ > } > else if (NULL_PARENT (i)) > error ("Point before start of properties"); > else > i = INTERVAL_PARENT (i); > continue; > } > >`pos' is 0, and `*i' is > >(gdb) p *i >$14 = { > total_length = 1, > position = 1, > left = 0x0, > right = 0x0, > up = { > interval = 0x86a1204, > obj = 141169156 > }, > up_obj = 1, > gcmarkbit = 0, > write_protect = 0, > visible = 0, > front_sticky = 0, > rear_sticky = 0, > plist = 156480797 >} >(gdb) > >That's why the error is signaled, I think. Ok, the function `skip_syntaxes' does not exist in the main branch, syntax.c in the unicode 2 branch is too old. Regards, Guanpeng Xu _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/