vasprintf



I noticed that was some discussion about vasprintf back in February.

Here is  a patch to use it.
The patch also contains a few other things, see  #60170.

Matthias

Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.218
diff -u -3 -p -u -r1.218 configure.in
--- configure.in	2001/09/02 06:46:39	1.218
+++ configure.in	2001/09/07 07:59:31
@@ -461,7 +461,7 @@ GLIB_SIZEOF([$size_includes], ptrdiff_t,
 GLIB_SIZEOF([$size_includes], intmax_t, intmax_t)

 # Check for some functions
-AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy
strcasecmp strncasecmp poll getcwd nanosleep)
+AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy
strcasecmp strncasecmp poll getcwd nanosleep vasprintf)

 # Check if bcopy can be used for overlapping copies, if memmove isn't
found.
 # The check is borrowed from the PERL Configure script.
Index: glib/gmem.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gmem.c,v
retrieving revision 1.31
diff -u -3 -p -u -r1.31 gmem.c
--- glib/gmem.c	2001/07/31 08:01:04	1.31
+++ glib/gmem.c	2001/09/07 07:59:32
@@ -221,11 +221,17 @@ fallback_calloc (gsize n_blocks,
   return mem;
 }

+static gboolean vtable_set = FALSE;
+
+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: glib/gmem.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gmem.h,v
retrieving revision 1.5
diff -u -3 -p -u -r1.5 gmem.h
--- glib/gmem.h	2001/06/26 16:01:14	1.5
+++ glib/gmem.h	2001/09/07 07:59:32
@@ -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: glib/gmessages.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gmessages.c,v
retrieving revision 1.33
diff -u -3 -p -u -r1.33 gmessages.c
--- glib/gmessages.c	2001/07/12 09:23:38	1.33
+++ glib/gmessages.c	2001/09/07 07:59:32
@@ -487,21 +487,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))
     {
@@ -980,6 +980,7 @@ printf_string_upper_bound (const gchar *
 		    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: glib/gstrfuncs.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gstrfuncs.c,v
retrieving revision 1.67
diff -u -3 -p -u -r1.67 gstrfuncs.c
--- glib/gstrfuncs.c	2001/09/04 05:09:33	1.67
+++ glib/gstrfuncs.c	2001/09/07 07:59:32
@@ -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;
 }







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]