all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Herbert Euler" <herberteuler@hotmail.com>
To: herberteuler@hotmail.com, monnier@iro.umontreal.ca
Cc: acm@muc.de, emacs-devel@gnu.org
Subject: Re: C++ mode and c-beginning-of-current-token
Date: Wed, 16 May 2007 16:01:05 +0800	[thread overview]
Message-ID: <BAY143-F33F60B90E542C5BE1E651FDA3C0@phx.gbl> (raw)
In-Reply-To: <BAY143-F12822C2C38B8B0E32275C5DA3D0@phx.gbl>

>> > 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 <iostream>
>
>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/

  reply	other threads:[~2007-05-16  8:01 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-12 10:39 C++ mode and c-beginning-of-current-token Herbert Euler
2007-05-12 13:19 ` Alan Mackenzie
2007-05-12 14:30   ` Herbert Euler
2007-05-12 14:33   ` Herbert Euler
2007-05-12 16:02   ` Herbert Euler
2007-05-12 15:30 ` Herbert Euler
2007-05-12 18:49   ` Alan Mackenzie
2007-05-13  0:51     ` Herbert Euler
2007-05-13 10:01 ` Alan Mackenzie
2007-05-14  2:00   ` Herbert Euler
2007-05-14  8:50     ` Alan Mackenzie
2007-05-14  9:24       ` Herbert Euler
2007-05-14 16:58 ` Stefan Monnier
2007-05-15  3:45   ` Herbert Euler
2007-05-15  6:39     ` martin rudalics
2007-05-16 16:15     ` Stefan Monnier
2007-05-15 13:30   ` Herbert Euler
2007-05-16  8:01     ` Herbert Euler [this message]
2007-05-16  8:05       ` Herbert Euler
2007-05-17  2:12         ` Kenichi Handa
2007-05-17 10:18           ` martin rudalics
2007-05-17 12:52             ` Herbert Euler
2007-05-17 13:51               ` martin rudalics
2007-05-17 21:40                 ` martin rudalics
2007-05-17 14:32               ` Stefan Monnier
2007-05-17 14:45                 ` martin rudalics
2007-05-18 13:00                 ` Richard Stallman
2007-05-18 23:39                   ` Herbert Euler
2007-05-19 22:31                     ` Richard Stallman
2007-05-19 12:59                   ` martin rudalics
2007-05-19 15:18                     ` Stefan Monnier
2007-05-19 17:48                       ` martin rudalics
2007-05-21 13:01                       ` Kenichi Handa
2007-05-21 14:00                         ` Stefan Monnier
2007-05-22  1:37                           ` Kenichi Handa
2007-05-22 10:26                             ` Stefan Monnier
2007-05-22 12:08                               ` Kenichi Handa
2007-05-20  6:50                     ` Richard Stallman
2007-05-16  9:00       ` martin rudalics
2007-05-16 11:12         ` Herbert Euler
2007-05-16 12:21           ` martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BAY143-F33F60B90E542C5BE1E651FDA3C0@phx.gbl \
    --to=herberteuler@hotmail.com \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.