summaryrefslogtreecommitdiff
path: root/gmessages.c
diff options
context:
space:
mode:
authorTim Janik <timj@gtk.org>1998-08-24 05:26:53 +0000
committerTim Janik <timj@src.gnome.org>1998-08-24 05:26:53 +0000
commitb420fa84187d9cb2f89ab8b3dd2040eab24742af (patch)
treeea25b72d953340a62d7c777b4db8a088777ca90a /gmessages.c
parent0b870ec357a266b5e7faa9a96310dd89503660f9 (diff)
removed this function which was not publically exported in glib.h. to
Mon Aug 24 02:08:56 1998 Tim Janik <timj@gtk.org> * glib.h: * gstring.c: * gstrfuncs.c: (g_vsprintf): removed this function which was not publically exported in glib.h. to export it, it should have been named differently in the first place, since its semantics differ from vsprintf(). apart from that, it was a possible cause for problems since it worked on a previously allocated memory area and was used in a lot places of glib. exporting it would have been a guararant for problems with threaded programs. (g_printf_string_upper_bound): exported this function to return a string size, guarranteed to be big enough to hold the fully expanded format+args string. added 'q', 'L' and 'll' flag handling. in fact, the newly allocated area is in most cases much bigger than required. (g_strdup_vprintf()): new function returning a newly allocated string containing the contents of *format and associated args (size is calculated with g_printf_string_upper_bound()). (g_strdup_printf): new function which wraps g_strdup_vprintf(). * configure.in: check for va_copy() or __va_copy() alternatively. check whether va_lists can be copyied by value. * glib.h: provide a definition for G_VA_COPY. * glib.h: * gmessages.c: (g_logv): (g_vsnprintf): pass va_lists by value, not by reference, since this causes problems on platforms that implement va_list as as arrays. internaly, use G_VA_COPY (new_arg, org_arg); va_end (new_arg); to produce a second va_list variable, if multiple passes are required. changed all callers. * glib.h: * gerror.h: renamed g_debug() to g_on_error_query(), cleaned up a bit. renamed g_stack_trace() to g_on_error_stack_trace() since both functions cluttered different namespaces. there is an appropriate comment in glib.h now that explains the unix and gdb specific dependencies of both functions. removed g_attach_process(). g_on_error_stack_trace() should probably be handled with caution, i've seem several different linux versions (2.0.x) become unstable after invokation of this function.
Diffstat (limited to 'gmessages.c')
-rw-r--r--gmessages.c76
1 files changed, 34 insertions, 42 deletions
diff --git a/gmessages.c b/gmessages.c
index f8271afd3..12a2c59b1 100644
--- a/gmessages.c
+++ b/gmessages.c
@@ -43,12 +43,6 @@ struct _GLogHandler
};
-/* --- prototypes --- */
-extern gchar* g_vsprintf (const gchar *fmt,
- va_list *args,
- va_list *args2);
-
-
/* --- variables --- */
const gchar *g_log_domain_glib = "GLib";
static GLogDomain *g_log_domains = NULL;
@@ -258,9 +252,9 @@ void
g_logv (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *format,
- va_list *args1,
- va_list *args2)
+ va_list args1)
{
+ va_list args2;
gchar buffer[1025];
register gint i;
@@ -269,9 +263,23 @@ g_logv (const gchar *log_domain,
return;
/* we use a stack buffer of fixed size, because we might get called
- * recursively, and we can also be out of memory.
+ * recursively.
*/
- g_vsnprintf (buffer, 1025, format, args1, args2);
+ G_VA_COPY (args2, args1);
+ if (g_printf_string_upper_bound (format, 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);
for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
{
@@ -312,13 +320,11 @@ g_log (const gchar *log_domain,
const gchar *format,
...)
{
- va_list arg_list1, arg_list2;
+ va_list args;
- va_start (arg_list1, format);
- va_start (arg_list2, format);
- g_logv (log_domain, log_level, format, &arg_list1, &arg_list2);
- va_end (arg_list2);
- va_end (arg_list1);
+ va_start (args, format);
+ g_logv (log_domain, log_level, format, args);
+ va_end (args);
}
void
@@ -523,30 +529,23 @@ void
g_print (const gchar *format,
...)
{
- va_list args, args2;
- char *buf;
+ va_list args;
+ gchar *string;
g_return_if_fail (format != NULL);
va_start (args, format);
- va_start (args2, format);
- buf = g_vsprintf (format, &args, &args2);
+ string = g_strdup_vprintf (format, args);
va_end (args);
- va_end (args2);
if (glib_print_func)
- {
- gchar *string;
-
- string = g_strdup (buf);
- glib_print_func (string);
- g_free (string);
- }
+ glib_print_func (string);
else
{
- fputs (buf, stdout);
+ fputs (string, stdout);
fflush (stdout);
}
+ g_free (string);
}
GPrintFunc
@@ -564,30 +563,23 @@ void
g_printerr (const gchar *format,
...)
{
- va_list args, args2;
- char *buf;
+ va_list args;
+ gchar *string;
g_return_if_fail (format != NULL);
va_start (args, format);
- va_start (args2, format);
- buf = g_vsprintf (format, &args, &args2);
+ string = g_strdup_vprintf (format, args);
va_end (args);
- va_end (args2);
if (glib_printerr_func)
- {
- gchar *string;
-
- string = g_strdup (buf);
- glib_printerr_func (string);
- g_free (string);
- }
+ glib_printerr_func (string);
else
{
- fputs (buf, stderr);
+ fputs (string, stderr);
fflush (stderr);
}
+ g_free (string);
}
/* compatibility code */