From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kenichi Handa Newsgroups: gmane.emacs.bugs Subject: bug#9318: 23.3.50; The first call of encode-coding-region() returns wrong result Date: Thu, 01 Dec 2011 10:56:12 +0900 Message-ID: References: <20110818090129.DC129360038@msa102.auone-net.jp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1322704628 9928 80.91.229.12 (1 Dec 2011 01:57:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 1 Dec 2011 01:57:08 +0000 (UTC) Cc: schwab@linux-m68k.org, 9318@debbugs.gnu.org To: Kazuhiro Ito Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 01 02:57:03 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RVvtX-0007AZ-E8 for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Dec 2011 02:57:03 +0100 Original-Received: from localhost ([::1]:46473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVvtW-0002uq-Uv for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Nov 2011 20:57:02 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:50583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVvtS-0002u4-E6 for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2011 20:57:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RVvtQ-0000nw-TG for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2011 20:56:58 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46475) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVvtQ-0000nj-QI for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2011 20:56:56 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1RVvtW-0008PT-4a for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2011 20:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Kenichi Handa Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Dec 2011 01:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9318 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 9318-submit@debbugs.gnu.org id=B9318.132270459032290 (code B ref 9318); Thu, 01 Dec 2011 01:57:02 +0000 Original-Received: (at 9318) by debbugs.gnu.org; 1 Dec 2011 01:56:30 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RVvt0-0008Ol-7k for submit@debbugs.gnu.org; Wed, 30 Nov 2011 20:56:30 -0500 Original-Received: from mx1.aist.go.jp ([150.29.246.133]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RVvsw-0008Ob-IF for 9318@debbugs.gnu.org; Wed, 30 Nov 2011 20:56:28 -0500 Original-Received: from rqsmtp2.aist.go.jp (rqsmtp2.aist.go.jp [150.29.254.123]) by mx1.aist.go.jp with ESMTP id pB11uE52012360; Thu, 1 Dec 2011 10:56:14 +0900 (JST) env-from (handa@m17n.org) Original-Received: from smtp2.aist.go.jp by rqsmtp2.aist.go.jp with ESMTP id pB11uEbh021807; Thu, 1 Dec 2011 10:56:14 +0900 (JST) env-from (handa@m17n.org) Original-Received: by smtp2.aist.go.jp with ESMTP id pB11uC2C028007; Thu, 1 Dec 2011 10:56:12 +0900 (JST) env-from (handa@m17n.org) In-Reply-To: <20110830233131.C74A61E0043@msa101.auone-net.jp> (message from Kazuhiro Ito on Wed, 31 Aug 2011 08:30:47 +0900) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 30 Nov 2011 20:57:02 -0500 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:54522 Archived-At: In article <20110830233131.C74A61E0043@msa101.auone-net.jp>, Kazuhiro Ito writes: > Here is the patch for the code, which contains Andreas' patch. In my > environment, problems are fixed. I think it would be better that the > interface of encode_designation_at_bol() is changed. Oops, sorry, I have vaguely thought that your patch below has already been applied, but just noticed that it was not. I'll commit a slightly modified version including the improved interface for encode_designation_at_bol soon. By the way, it would be good if we had a way to suppress buffer text relocation temporarily. --- Kenichi Handa handa@m17n.org > === modified file 'src/coding.c' > --- src/coding.c 2011-05-09 09:59:23 +0000 > +++ src/coding.c 2011-08-28 07:33:54 +0000 > @@ -1026,6 +1026,54 @@ > } \ > } while (0) > +#define CODING_ENCODE_CHAR(coding, dst, dst_end, charset, c, code) \ > + do { \ > + charset_map_loaded = 0; \ > + code = ENCODE_CHAR (charset, c); \ > + if (charset_map_loaded) \ > + { \ > + const unsigned char *orig = coding->destination; \ > + EMACS_INT offset; \ > + \ > + coding_set_destination (coding); \ > + offset = coding->destination - orig; \ > + dst += offset; \ > + dst_end += offset; \ > + } \ > + } while (0) > + > +#define CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, code_return, charset) \ > + do { \ > + charset_map_loaded = 0; \ > + charset = char_charset (c, charset_list, code_return); \ > + if (charset_map_loaded) \ > + { \ > + const unsigned char *orig = coding->destination; \ > + EMACS_INT offset; \ > + \ > + coding_set_destination (coding); \ > + offset = coding->destination - orig; \ > + dst += offset; \ > + dst_end += offset; \ > + } \ > + } while (0) > + > +#define CODING_CHAR_CHARSET_P(coding, dst, dst_end, c, charset, result) \ > + do { \ > + charset_map_loaded = 0; \ > + result = CHAR_CHARSET_P(c, charset); \ > + if (charset_map_loaded) \ > + { \ > + const unsigned char *orig = coding->destination; \ > + EMACS_INT offset; \ > + \ > + coding_set_destination (coding); \ > + offset = coding->destination - orig; \ > + dst += offset; \ > + dst_end += offset; \ > + } \ > + } while (0) > + > /* If there are at least BYTES length of room at dst, allocate memory > for coding->destination and update dst and dst_end. We don't have > @@ -2778,14 +2826,19 @@ > if (preferred_charset_id >= 0) > { > + int result; > + > charset = CHARSET_FROM_ID (preferred_charset_id); > - if (CHAR_CHARSET_P (c, charset)) > + CODING_CHAR_CHARSET_P (coding, dst, dst_end, c, charset, result); > + if (result) > code = ENCODE_CHAR (charset, c); > else > - charset = char_charset (c, charset_list, &code); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + &code, charset); > } > else > - charset = char_charset (c, charset_list, &code); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + &code, charset); > if (! charset) > { > c = coding->default_char; > @@ -2794,7 +2847,8 @@ > EMIT_ONE_ASCII_BYTE (c); > continue; > } > - charset = char_charset (c, charset_list, &code); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + &code, charset); > } > dimension = CHARSET_DIMENSION (charset); > emacs_mule_id = CHARSET_EMACS_MULE_ID (charset); > @@ -4317,8 +4371,9 @@ > #define ENCODE_ISO_CHARACTER(charset, c) \ > do { \ > - int code = ENCODE_CHAR ((charset),(c)); \ > - \ > + int code; \ > + CODING_ENCODE_CHAR (coding, dst, dst_end, (charset), (c), code); \ > + \ > if (CHARSET_DIMENSION (charset) == 1) \ > ENCODE_ISO_CHARACTER_DIMENSION1 ((charset), code); \ > else \ > @@ -4476,7 +4531,17 @@ > c = *charbuf++; > if (c == '\n') > break; > + > + charset_map_loaded = 0; > charset = char_charset (c, charset_list, NULL); > + if (charset_map_loaded) > + { > + const unsigned char *orig = coding->destination; > + > + coding_set_destination (coding); > + dst += coding->destination - orig; > + } > + > id = CHARSET_ID (charset); > reg = CODING_ISO_REQUEST (coding, id); > if (reg >= 0 && r[reg] < 0) > @@ -4543,6 +4608,12 @@ > /* We have to produce designation sequences if any now. */ > dst = encode_designation_at_bol (coding, charbuf, charbuf_end, dst); > + if (charset_map_loaded) > + { > + EMACS_INT offset = coding->destination + coding->dst_bytes - dst_end; > + dst_end += offset; > + dst_prev += offset; > + } > bol_designation = 0; > /* We are sure that designation sequences are all ASCII bytes. */ > produced_chars += dst - dst_prev; > @@ -4616,12 +4687,17 @@ > if (preferred_charset_id >= 0) > { > + int result; > + > charset = CHARSET_FROM_ID (preferred_charset_id); > - if (! CHAR_CHARSET_P (c, charset)) > - charset = char_charset (c, charset_list, NULL); > + CODING_CHAR_CHARSET_P (coding, dst, dst_end, c, charset, result); > + if (! result) > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + NULL, charset); > } > else > - charset = char_charset (c, charset_list, NULL); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + NULL, charset); > if (!charset) > { > if (coding->mode & CODING_MODE_SAFE_ENCODING) > @@ -4632,7 +4708,8 @@ > else > { > c = coding->default_char; > - charset = char_charset (c, charset_list, NULL); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, > + charset_list, NULL, charset); > } > } > ENCODE_ISO_CHARACTER (charset, c); > @@ -5064,7 +5141,9 @@ > else > { > unsigned code; > - struct charset *charset = char_charset (c, charset_list, &code); > + struct charset *charset; > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + &code, charset); > if (!charset) > { > @@ -5076,7 +5155,8 @@ > else > { > c = coding->default_char; > - charset = char_charset (c, charset_list, &code); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, > + charset_list, &code, charset); > } > } > if (code == CHARSET_INVALID_CODE (charset)) > @@ -5153,7 +5233,9 @@ > else > { > unsigned code; > - struct charset *charset = char_charset (c, charset_list, &code); > + struct charset *charset; > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + &code, charset); > if (! charset) > { > @@ -5165,7 +5247,8 @@ > else > { > c = coding->default_char; > - charset = char_charset (c, charset_list, &code); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, > + charset_list, &code, charset); > } > } > if (code == CHARSET_INVALID_CODE (charset)) > @@ -5747,7 +5831,9 @@ > } > else > { > - charset = char_charset (c, charset_list, &code); > + CODING_CHAR_CHARSET(coding, dst, dst_end, c, charset_list, > + &code, charset); > + > if (charset) > { > if (CHARSET_DIMENSION (charset) == 1) > -- > Kazuhiro Ito