Patch from Matthias Clasen (#59806)
authorOwen Taylor <otaylor@redhat.com>
Wed, 19 Sep 2001 18:43:22 +0000 (18:43 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Wed, 19 Sep 2001 18:43:22 +0000 (18:43 +0000)
Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>

Patch from Matthias Clasen (#59806)

* configure.in: Check for vasprintf().

* glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
for efficiency hacks to avoid extra copies when not
needed.

* glib/gstrfuncs.c: Use vasprintf() to implement
g_strdup_printf() when available.

* glib/gmessages.c (g_logv): Avoid using
printf_string_upper_bound() when we have have vsnprintf.

* glib/gmessages.c (printf_string_upper_bound): Don't
segfault when warning about positional parameters.

12 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gmem.c
glib/gmem.h
glib/gmessages.c
glib/gstrfuncs.c

index 97936bd..afe33f1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index 97936bd..afe33f1 100644 (file)
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index 97936bd..afe33f1 100644 (file)
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index 97936bd..afe33f1 100644 (file)
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index 97936bd..afe33f1 100644 (file)
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index 97936bd..afe33f1 100644 (file)
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index 97936bd..afe33f1 100644 (file)
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index 97936bd..afe33f1 100644 (file)
@@ -1,3 +1,22 @@
+Wed Sep 19 14:17:31 2001  Owen Taylor  <otaylor@redhat.com>
+
+       Patch from Matthias Clasen (#59806)
+
+       * configure.in: Check for vasprintf().
+
+       * glib/gmem.[ch]: Add g_mem_vtable_is_set() to be used
+       for efficiency hacks to avoid extra copies when not
+       needed.
+
+       * glib/gstrfuncs.c: Use vasprintf() to implement
+       g_strdup_printf() when available.
+
+       * glib/gmessages.c (g_logv): Avoid using 
+       printf_string_upper_bound() when we have have vsnprintf.
+
+       * glib/gmessages.c (printf_string_upper_bound): Don't
+       segfault when warning about positional parameters.
+
 Wed Sep 19 14:05:27 2001  Owen Taylor  <otaylor@redhat.com>
 
        * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}:
index c96307c..a7c1fcf 100644 (file)
@@ -221,11 +221,28 @@ fallback_calloc (gsize n_blocks,
   return mem;
 }
 
+static gboolean vtable_set = FALSE;
+
+/**
+ * g_mem_vtable_is_set:
+ * 
+ * Checks whether a custom vtable as been set by g_mem_set_vtable.
+ * If a custom vtable has not been set, memory allocated with
+ * free() can be used interchangeable with memory allocated using
+ * g_free(). This function is useful for avoiding an extra copy
+ * of allocated memory returned by a non-GLib-based API.
+ * 
+ * Return value: if %TRUE, a custom vtable has been set.
+ **/
+gboolean
+g_mem_vtable_is_set (void)
+{
+  return vtable_set;
+}
+
 void
 g_mem_set_vtable (GMemVTable *vtable)
 {
-  static gboolean vtable_set = FALSE;
-
   if (!vtable_set)
     {
       vtable_set = TRUE;
index 392a06c..d1f3d6a 100644 (file)
@@ -83,7 +83,7 @@ struct _GMemVTable
                           gsize    n_bytes);
 };
 void    g_mem_set_vtable (GMemVTable   *vtable);
-
+gboolean g_mem_vtable_is_set (void);
 
 /* Memory profiler and checker, has to be enabled via g_mem_set_vtable()
  */
index 5c76179..a72afb9 100644 (file)
@@ -484,21 +484,21 @@ g_logv (const gchar   *log_domain,
   /* we use a stack buffer of fixed size, because we might get called
    * recursively.
    */
+#ifdef  HAVE_VSNPRINTF
+  vsnprintf (buffer, 1024, format, args1);
+#else  /* !HAVE_VSNPRINTF */
   G_VA_COPY (args2, args1);
   if (printf_string_upper_bound (format, FALSE, args1) < 1024)
     vsprintf (buffer, format, args2);
   else
     {
       /* since we might be out of memory, we can't use g_vsnprintf(). */
-#ifdef  HAVE_VSNPRINTF
-      vsnprintf (buffer, 1024, format, args2);
-#else  /* !HAVE_VSNPRINTF */
       /* we are out of luck here */
       strncpy (buffer, format, 1024);
-#endif /* !HAVE_VSNPRINTF */
       buffer[1024] = 0;
     }
   va_end (args2);
+#endif /* !HAVE_VSNPRINTF */
   
   for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
     {
@@ -908,6 +908,7 @@ printf_string_upper_bound (const gchar *format,
                    g_warning (G_GNUC_PRETTY_FUNCTION
                               "(): unable to handle positional parameters (%%n$)");
                  len += 1024; /* try adding some safety padding */
+                 conv_done = TRUE;
                  break;
 
                  /* parse flags
index c7863e2..f699ca9 100644 (file)
@@ -184,6 +184,15 @@ g_strdup_vprintf (const gchar *format,
                  va_list      args1)
 {
   gchar *buffer;
+#ifdef HAVE_VASPRINTF
+  vasprintf (&buffer, format, args1);
+  if (g_mem_vtable_is_set ()) 
+    {
+      gchar *buffer1 = g_strdup (buffer);
+      free (buffer);
+      buffer = buffer1;
+    }
+#else
   va_list args2;
 
   G_VA_COPY (args2, args1);
@@ -192,7 +201,7 @@ g_strdup_vprintf (const gchar *format,
 
   vsprintf (buffer, format, args2);
   va_end (args2);
-
+#endif
   return buffer;
 }