emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CCL_WRITE_CHAR and CCL_WRITE_MULTIBYTE_CHAR


From: YAMAMOTO Mitsuharu
Subject: Re: CCL_WRITE_CHAR and CCL_WRITE_MULTIBYTE_CHAR
Date: Thu, 31 Jan 2008 21:37:24 +0900 (JST)

>>>>> On Thu, 31 Jan 2008 20:35:34 +0900, Kenichi Handa <address@hidden> said:

> At least, in CCL_WRITE_CHAR, that change is not safe because
> extra_bytes will be incremented after that check.

But in the original code, extra_bytes is initialized to 1, not 0, in
the case that increment occurs.

> I've just installed the attached change to the main trunk.  I dared
> not install that change to EMACS_22_BASE because I'm still not that
> confident about the change.  In addition the problem has not been
> revealed so long, and it can be avoided by giving a bigger
> BUFFER_MAGNIFICATION in define-ccl-program.

I'm planning to add some event handlers to the Carbon port after the
Emacs 22.2 release so we can look up a word pointed to by the mouse in
dictionaries using Command-Control-D.  That hander requires us to fill
a given storage with a specified range of buffer text in UTF-16.  (I'm
thinking about BMP-only case.)  The size of the storage in bytes is
exactly twice as large as the length of the range.  That's the "tight
situation" I mentioned in the previous mail.

                                     YAMAMOTO Mitsuharu
                                address@hidden

/* Store the text of the buffer BUF from START to END as Unicode
   characters in CHARACTERS.  Return non-zero if successful.  */

int
mac_store_buffer_text_to_unicode_chars (buf, start, end, characters)
     struct buffer *buf;
     int start, end;
     UniChar *characters;
{
  int start_byte, end_byte, char_count, byte_count;
  struct coding_system coding;
  unsigned char *dst = (unsigned char *) characters;

  start_byte = buf_charpos_to_bytepos (buf, start);
  end_byte = buf_charpos_to_bytepos (buf, end);
  char_count = end - start;
  byte_count = end_byte - start_byte;

  if (setup_coding_system (
#ifdef WORDS_BIG_ENDIAN
                           intern ("utf-16be")
#else
                           intern ("utf-16le")
#endif
                           , &coding) < 0)
    return 0;

  coding.src_multibyte = !NILP (buf->enable_multibyte_characters);
  coding.dst_multibyte = 0;
  coding.mode |= CODING_MODE_LAST_BLOCK;
  coding.composing = COMPOSITION_DISABLED;

  if (BUF_GPT_BYTE (buf) <= start_byte || end_byte <= BUF_GPT_BYTE (buf))
    encode_coding (&coding, BUF_BYTE_ADDRESS (buf, start_byte), dst,
                   byte_count, char_count * sizeof (UniChar));
  else
    {
      int first_byte_count = BUF_GPT_BYTE (buf) - start_byte;

      encode_coding (&coding, BUF_BYTE_ADDRESS (buf, start_byte), dst,
                     first_byte_count, char_count * sizeof (UniChar));
      if (coding.result == CODING_FINISH_NORMAL)
        encode_coding (&coding,
                       BUF_BYTE_ADDRESS (buf, start_byte + first_byte_count),
                       dst + coding.produced,
                       byte_count - first_byte_count,
                       char_count * sizeof (UniChar) - coding.produced);
    }

  if (coding.result != CODING_FINISH_NORMAL)
    return 0;

  return 1;
}

PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]