GNU bug report logs - #9318
23.3.50; The first call of encode-coding-region() returns wrong result on on Windows

Previous Next

Package: emacs;

Reported by: Kazuhiro Ito <kzhr <at> d1.dion.ne.jp>

Date: Thu, 18 Aug 2011 09:04:02 UTC

Severity: normal

Found in version 23.3.50

Fixed in version 24.0.93

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Kazuhiro Ito <kzhr <at> d1.dion.ne.jp>
Cc: Chong Yidong <cyd <at> stupidchicken.com>, 9318 <at> debbugs.gnu.org
Subject: bug#9318: 23.3.50; The first call of encode-coding-region() returns wrong result
Date: Wed, 24 Aug 2011 19:59:34 +0200
Kazuhiro Ito <kzhr <at> d1.dion.ne.jp> writes:

> 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.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




This bug report was last modified 13 years and 170 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.