changeset 21084:371ed7bdfd2b

(Fmake_string): Handle the case INIT is a multibyte character correctly.
author Richard M. Stallman <rms@gnu.org>
date Fri, 06 Mar 1998 21:50:44 +0000
parents a5a15ce66e98
children 6b0336de5fbe
files src/alloc.c
diffstat 1 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/alloc.c	Fri Mar 06 21:49:18 1998 +0000
+++ b/src/alloc.c	Fri Mar 06 21:50:44 1998 +0000
@@ -32,6 +32,7 @@
 #include "frame.h"
 #include "blockinput.h"
 #include "keyboard.h"
+#include "charset.h"
 #endif
 
 #include "syssignal.h"
@@ -1186,16 +1187,37 @@
      Lisp_Object length, init;
 {
   register Lisp_Object val;
-  register unsigned char *p, *end, c;
+  register unsigned char *p, *end;
+  int c, nbytes;
 
   CHECK_NATNUM (length, 0);
   CHECK_NUMBER (init, 1);
-  val = make_uninit_string (XFASTINT (length));
+
   c = XINT (init);
-  p = XSTRING (val)->data;
-  end = p + XSTRING (val)->size;
-  while (p != end)
-    *p++ = c;
+  if (SINGLE_BYTE_CHAR_P (c))
+    {
+      nbytes = XINT (length);
+      val = make_uninit_multibyte_string (nbytes, nbytes);
+      p = XSTRING (val)->data;
+      end = p + XSTRING (val)->size;
+      while (p != end)
+	*p++ = c;
+    }
+  else
+    {
+      unsigned char work[4], *str;
+      int len = CHAR_STRING (c, work, str);
+
+      nbytes = len * XINT (length);
+      val = make_uninit_multibyte_string (XINT (length), nbytes);
+      p = XSTRING (val)->data;
+      end = p + nbytes;
+      while (p != end)
+	{
+	  bcopy (str, p, len);
+	  p += len;
+	}
+    }
   *p = 0;
   return val;
 }