]> code.delx.au - gnu-emacs/commitdiff
(encode_coding_string): Always return a unibyte string.
authorKenichi Handa <handa@m17n.org>
Mon, 14 Feb 2005 01:04:50 +0000 (01:04 +0000)
committerKenichi Handa <handa@m17n.org>
Mon, 14 Feb 2005 01:04:50 +0000 (01:04 +0000)
If NOCOPY is nonzero and there's no need of encoding, make STR
unibyte directly.

src/ChangeLog
src/coding.c

index c6ab6985ed0dde2bfcd378d91e8f95da50541b42..999064bb47edfd69a23dd770ce59f604b24de328 100644 (file)
@@ -1,3 +1,12 @@
+2005-02-14  Kenichi Handa  <handa@m17n.org>
+
+       * coding.c (encode_coding_string): Always return a unibyte string.
+       If NOCOPY is nonzero and there's no need of encoding, make STR
+       unibyte directly.
+
+       * xselect.c (lisp_data_to_selection_data): If OBJ is a non-ASCII
+       multibyte string, signal an error instead of aborting.
+
 2005-02-12  Dan Nicolaescu  <dann@ics.uci.edu>
 
        * keyboard.c: If HAVE_FCNTL_H include fcntl.h.
index 79e32fbed604abb2d52d8f0c0ab72f4e6635255b..2ab4296381a909cc004727726e487df2704384c7 100644 (file)
@@ -6361,7 +6361,12 @@ encode_coding_string (str, coding, nocopy)
 
   if (SYMBOLP (coding->pre_write_conversion)
       && !NILP (Ffboundp (coding->pre_write_conversion)))
-    str = run_pre_post_conversion_on_str (str, coding, 1);
+    {
+      str = run_pre_post_conversion_on_str (str, coding, 1);
+      /* As STR is just newly generated, we don't have to copy it
+        anymore.  */
+      nocopy = 1;
+    }
 
   from = 0;
   to = SCHARS (str);
@@ -6369,21 +6374,10 @@ encode_coding_string (str, coding, nocopy)
 
   /* Encoding routines determine the multibyteness of the source text
      by coding->src_multibyte.  */
-  coding->src_multibyte = STRING_MULTIBYTE (str);
+  coding->src_multibyte = SCHARS (str) < SBYTES (str);
   coding->dst_multibyte = 0;
   if (! CODING_REQUIRE_ENCODING (coding))
-    {
-      coding->consumed = SBYTES (str);
-      coding->consumed_char = SCHARS (str);
-      if (STRING_MULTIBYTE (str))
-       {
-         str = Fstring_as_unibyte (str);
-         nocopy = 1;
-       }
-      coding->produced = SBYTES (str);
-      coding->produced_char = SCHARS (str);
-      return (nocopy ? str : Fcopy_sequence (str));
-    }
+    goto no_need_of_encoding;
 
   if (coding->composing != COMPOSITION_DISABLED)
     coding_save_composition (coding, from, to, str);
@@ -6399,7 +6393,7 @@ encode_coding_string (str, coding, nocopy)
       if (from == to_byte)
        {
          coding_free_composition_data (coding);
-         return (nocopy ? str : Fcopy_sequence (str));
+         goto no_need_of_encoding;
        }
       shrinked_bytes = from + (SBYTES (str) - to_byte);
     }
@@ -6444,6 +6438,25 @@ encode_coding_string (str, coding, nocopy)
   coding_free_composition_data (coding);
 
   return newstr;
+
+ no_need_of_encoding:
+  coding->consumed = SBYTES (str);
+  coding->consumed_char = SCHARS (str);
+  if (STRING_MULTIBYTE (str))
+    {
+      if (nocopy)
+       /* We are sure that STR doesn't contain a multibyte
+          character.  */
+       STRING_SET_UNIBYTE (str);
+      else
+       {
+         str = Fstring_as_unibyte (str);
+         nocopy = 1;
+       }
+    }
+  coding->produced = SBYTES (str);
+  coding->produced_char = SCHARS (str);
+  return (nocopy ? str : Fcopy_sequence (str));
 }
 
 \f