From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kazuhiro Ito Newsgroups: gmane.emacs.bugs Subject: bug#9318: 23.3.50; The first call of encode-coding-region() returns wrong result Date: Thu, 25 Aug 2011 18:54:13 +0900 Message-ID: <20110825095522.6E2482C037@msa104.auone-net.jp> References: <20110818090129.DC129360038@msa102.auone-net.jp> <20110819134637.9727A34803A@msa103.auone-net.jp> <877h67vkpf.fsf@stupidchicken.com> <20110821001726.D29052C037@msa104.auone-net.jp> <20110824093755.8E190360038@msa102.auone-net.jp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (generated by SEMI-EPG 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: dough.gmane.org 1314266200 492 80.91.229.12 (25 Aug 2011 09:56:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 25 Aug 2011 09:56:40 +0000 (UTC) Cc: Chong Yidong , 9318@debbugs.gnu.org To: Andreas Schwab Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 25 11:56:31 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 1QwWfm-0004oK-2e for geb-bug-gnu-emacs@m.gmane.org; Thu, 25 Aug 2011 11:56:30 +0200 Original-Received: from localhost ([::1]:37767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwWfl-0005vf-ML for geb-bug-gnu-emacs@m.gmane.org; Thu, 25 Aug 2011 05:56:29 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:41135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwWfi-0005rK-Ah for bug-gnu-emacs@gnu.org; Thu, 25 Aug 2011 05:56:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwWfg-0000Nq-Qs for bug-gnu-emacs@gnu.org; Thu, 25 Aug 2011 05:56:26 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwWfg-0000Nh-Nv for bug-gnu-emacs@gnu.org; Thu, 25 Aug 2011 05:56:24 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QwWiE-0004T8-7P; Thu, 25 Aug 2011 05:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kazuhiro Ito Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 Aug 2011 09:59: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.131426628817113 (code B ref 9318); Thu, 25 Aug 2011 09:59:02 +0000 Original-Received: (at 9318) by debbugs.gnu.org; 25 Aug 2011 09:58:08 +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 1QwWhM-0004Ry-9G for submit@debbugs.gnu.org; Thu, 25 Aug 2011 05:58:08 -0400 Original-Received: from msa104.auone-net.jp ([61.117.18.164]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QwWhG-0004RS-Vr for 9318@debbugs.gnu.org; Thu, 25 Aug 2011 05:58:06 -0400 Original-Received: from GUNGNIR.med.osaka-cu.ac.jp (unknown [114.179.36.76]) by msa104.auone-net.jp (au one net msa) with ESMTP id 6E2482C037; Thu, 25 Aug 2011 18:55:21 +0900 (JST) In-Reply-To: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL/10.8 EasyPG/1.0.0 Emacs/23.3.50 (i386-mingw-nt6.1.7601) MULE/6.0 (HANACHIRUSATO) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 25 Aug 2011 05:59:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) 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:50331 Archived-At: > > I think relocation of buffer may cause the problem. > > Does that help? > > diff --git a/src/coding.c b/src/coding.c > index 65c8a76..f34a023 100644 > --- a/src/coding.c > +++ b/src/coding.c > @@ -915,8 +915,8 @@ record_conversion_result (struct coding_system *coding, > } > } > > -/* This wrapper macro is used to preserve validity of pointers into > - buffer text across calls to decode_char, which could cause > +/* These wrapper macros are used to preserve validity of pointers into > + buffer text across calls to decode_char/encode_char, which could cause > relocation of buffers if it loads a charset map, because loading a > charset map allocates large structures. */ > #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ > @@ -935,6 +935,21 @@ record_conversion_result (struct coding_system *coding, > src_end += offset; \ > } \ > } 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) > > > /* If there are at least BYTES length of room at dst, allocate memory > @@ -2652,7 +2667,7 @@ encode_coding_emacs_mule (struct coding_system *coding) > { > charset = CHARSET_FROM_ID (preferred_charset_id); > if (CHAR_CHARSET_P (c, charset)) > - code = ENCODE_CHAR (charset, c); > + CODING_ENCODE_CHAR (coding, dst, dst_end, charset, c, code); > else > charset = char_charset (c, charset_list, &code); > } > @@ -4185,7 +4200,8 @@ decode_coding_iso_2022 (struct coding_system *coding) > #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); \ Andreas' patch resolved the problem partially. It resolved the problem on NetBSD with '-O0' CFLAGS, but failed on NetBSD with '-O2' and Windows. I confirmed that adding the protection of coding->dst_object to Andreas' patch resolved the problem on NetBSD with '-O2' but not on Windows. I don't know whether it is incorrect way or is not enough. --- src/coding.c 2011-07-01 11:03:55 +0000 +++ src/coding.c 2011-08-24 23:39:49 +0000 @@ -7397,10 +7436,15 @@ setup_ccl_program (&cclspec.ccl, CODING_CCL_ENCODER (coding)); } do { + struct gcpro gcpro1; + GCPRO1 (coding->dst_object); + coding_set_source (coding); consume_chars (coding, translation_table, max_lookup); coding_set_destination (coding); (*(coding->encoder)) (coding); + + UNGCPRO; } while (coding->consumed_char < coding->src_chars); if (BUFFERP (coding->dst_object) && coding->produced_char > 0) -- Kazuhiro Ito