diff --git a/ChangeLog b/ChangeLog index 97936bd71..afe33f1d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 97936bd71..afe33f1d0 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 97936bd71..afe33f1d0 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 97936bd71..afe33f1d0 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 97936bd71..afe33f1d0 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 97936bd71..afe33f1d0 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 97936bd71..afe33f1d0 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 97936bd71..afe33f1d0 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,22 @@ +Wed Sep 19 14:17:31 2001 Owen Taylor + + 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 * glib/{gcache.c,gmem.c,grel.c,gstring.c,gtimer.c,gtree}: diff --git a/glib/gmem.c b/glib/gmem.c index c96307cbd..a7c1fcff9 100644 --- a/glib/gmem.c +++ b/glib/gmem.c @@ -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; diff --git a/glib/gmem.h b/glib/gmem.h index 392a06cda..d1f3d6a6b 100644 --- a/glib/gmem.h +++ b/glib/gmem.h @@ -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() */ diff --git a/glib/gmessages.c b/glib/gmessages.c index 5c761798e..a72afb925 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -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 diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index c7863e28b..f699ca9cf 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -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; }