mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 10:08:56 +01:00 
			
		
		
		
	Patch from Matthias Clasen (#59806)
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.
This commit is contained in:
		
							
								
								
									
										19
									
								
								ChangeLog
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								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}:
 | 
			
		||||
 
 | 
			
		||||
@@ -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}:
 | 
			
		||||
 
 | 
			
		||||
@@ -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}:
 | 
			
		||||
 
 | 
			
		||||
@@ -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}:
 | 
			
		||||
 
 | 
			
		||||
@@ -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}:
 | 
			
		||||
 
 | 
			
		||||
@@ -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}:
 | 
			
		||||
 
 | 
			
		||||
@@ -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}:
 | 
			
		||||
 
 | 
			
		||||
@@ -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}:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								glib/gmem.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user