Index: glib/gunidecomp.c
===================================================================
--- glib/gunidecomp.c	(revision 5774)
+++ glib/gunidecomp.c	(working copy)
@@ -208,30 +208,27 @@
   return NULL;
 }
 
-/**
- * g_unicode_canonical_decomposition:
- * @ch: a Unicode character.
- * @result_len: location to store the length of the return value.
- *
- * Computes the canonical decomposition of a Unicode character.  
- * 
- * Return value: a newly allocated string of Unicode characters.
- *   @result_len is set to the resulting length of the string.
- **/
-gunichar *
-g_unicode_canonical_decomposition (gunichar ch,
-				   gsize   *result_len)
+static gunichar *
+real_g_unicode_canonical_decomposition (gunichar  ch,
+                                        gboolean  malloc,
+                                        gunichar *out,
+                                        gsize     out_len,
+				        gsize    *result_len)
 {
   const gchar *decomp;
   const gchar *p;
-  gunichar *r;
 
   /* Hangul syllable */
   if (ch >= 0xac00 && ch <= 0xd7a3)
     {
       decompose_hangul (ch, NULL, result_len);
-      r = g_malloc (*result_len * sizeof (gunichar));
-      decompose_hangul (ch, r, result_len);
+
+      if (malloc)
+        out = g_malloc (*result_len * sizeof (gunichar));
+      else if (*result_len > out_len)
+        return NULL;
+
+      decompose_hangul (ch, out, result_len);
     }
   else if ((decomp = find_decomposition (ch, FALSE)) != NULL)
     {
@@ -239,25 +236,82 @@
       int i;
       
       *result_len = g_utf8_strlen (decomp, -1);
-      r = g_malloc (*result_len * sizeof (gunichar));
+
+      if (malloc)
+        out = g_malloc (*result_len * sizeof (gunichar));
+      else if (*result_len > out_len)
+        return NULL;
       
       for (p = decomp, i = 0; *p != '\0'; p = g_utf8_next_char (p), i++)
-        r[i] = g_utf8_get_char (p);
+        out[i] = g_utf8_get_char (p);
     }
   else
     {
       /* Not in our table.  */
-      r = g_malloc (sizeof (gunichar));
-      *r = ch;
       *result_len = 1;
+
+      if (malloc)
+        out = g_malloc (sizeof (gunichar));
+      else if (*result_len > out_len)
+        return NULL;
+
+      *out = ch;
     }
 
   /* Supposedly following the Unicode 2.1.9 table means that the
      decompositions come out in canonical order.  I haven't tested
      this, but we rely on it here.  */
-  return r;
+  return out;
 }
 
+/**
+ * g_unicode_canonical_decomposition:
+ * @ch: a Unicode character.
+ * @result_len: location to store the length of the return value.
+ *
+ * Computes the canonical decomposition of a Unicode character.  
+ * 
+ * Return value: a newly allocated string of Unicode characters.
+ *   @result_len is set to the resulting length of the string.
+ **/
+gunichar *
+g_unicode_canonical_decomposition (gunichar ch,
+				   gsize   *result_len)
+{
+  return real_g_unicode_canonical_decomposition (ch,
+                                                 TRUE,
+                                                 NULL,
+                                                 0,
+                                                 result_len);
+}
+
+/**
+ * g_unicode_canonical_decomposition_to_buffer:
+ * @ch: a Unicode character.
+ * @out: buffer to store the decomposited string of unicode characters
+ * @out_len: size of the buffer
+ * @result_len: location to store the length of the return value.
+ *
+ * Computes the canonical decomposition of a Unicode character,
+ * storing the result in the buffer pointed to by @out if it is large enough.
+ * If @out is too small, NULL is returned and the function should be called
+ * again with a buffer of size @result_len.
+ * 
+ * Return value: @out if it was large enough, NULL otherwise.
+ **/
+gunichar *
+g_unicode_canonical_decomposition_to_buffer (gunichar  ch,
+                                             gunichar *out,
+                                             gsize     out_len,
+				             gsize    *result_len)
+{
+  return real_g_unicode_canonical_decomposition (ch,
+                                                 FALSE,
+                                                 out,
+                                                 out_len,
+                                                 result_len);
+}
+
 /* L,V => LV and LV,T => LVT  */
 static gboolean
 combine_hangul (gunichar a,
Index: glib/gunicode.h
===================================================================
--- glib/gunicode.h	(revision 5774)
+++ glib/gunicode.h	(working copy)
@@ -252,6 +252,14 @@
 gunichar *g_unicode_canonical_decomposition (gunichar  ch,
 					     gsize    *result_len) G_GNUC_MALLOC;
 
+/* Compute canonical decomposition of a character.  Fills buffer with a
+   string of Unicode characters.  RESULT_LEN is set to the resulting
+   length of the string.  */
+gunichar *g_unicode_canonical_decomposition_to_buffer (gunichar  ch,
+                                                       gunichar *out,
+                                                       gsize     out_len,
+	 			                       gsize    *result_len);
+ 
 /* Array of skip-bytes-per-initial character.
  */
 GLIB_VAR const gchar * const g_utf8_skip;
