diff options
author | Tim Janik <timj@gtk.org> | 1998-08-24 05:26:53 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 1998-08-24 05:26:53 +0000 |
commit | b420fa84187d9cb2f89ab8b3dd2040eab24742af (patch) | |
tree | ea25b72d953340a62d7c777b4db8a088777ca90a /gstring.c | |
parent | 0b870ec357a266b5e7faa9a96310dd89503660f9 (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 'gstring.c')
-rw-r--r-- | gstring.c | 174 |
1 files changed, 15 insertions, 159 deletions
@@ -466,152 +466,16 @@ g_string_up (GString *fstring) return fstring; } -static int -get_length_upper_bound (const gchar* fmt, va_list *args) -{ - int len = 0; - int short_int; - int long_int; - int done; - char *tmp; - - while (*fmt) - { - char c = *fmt++; - - short_int = FALSE; - long_int = FALSE; - - if (c == '%') - { - done = FALSE; - while (*fmt && !done) - { - switch (*fmt++) - { - case '*': - len += va_arg(*args, int); - break; - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - fmt -= 1; - len += strtol (fmt, (char **)&fmt, 10); - break; - case 'h': - short_int = TRUE; - break; - case 'l': - long_int = TRUE; - break; - - /* I ignore 'q' and 'L', they're not portable anyway. */ - - case 's': - tmp = va_arg(*args, char *); - if(tmp) - len += strlen (tmp); - else - len += strlen ("(null)"); - done = TRUE; - break; - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - if (long_int) - (void)va_arg (*args, long); - else if (short_int) - (void)va_arg (*args, int); - else - (void)va_arg (*args, int); - len += 32; - done = TRUE; - break; - case 'D': - case 'O': - case 'U': - (void)va_arg (*args, long); - len += 32; - done = TRUE; - break; - case 'e': - case 'E': - case 'f': - case 'g': - (void)va_arg (*args, double); - len += 32; - done = TRUE; - break; - case 'c': - (void)va_arg (*args, int); - len += 1; - done = TRUE; - break; - case 'p': - case 'n': - (void)va_arg (*args, void*); - len += 32; - done = TRUE; - break; - case '%': - len += 1; - done = TRUE; - break; - default: - break; - } - } - } - else - len += 1; - } - - return len; -} - -extern gchar* g_vsprintf (const gchar *fmt, va_list *args, va_list *args2); -gchar* -g_vsprintf (const gchar *fmt, - va_list *args, - va_list *args2) -{ - static gchar *buf = NULL; - static guint alloc = 0; - guint len; - - len = get_length_upper_bound (fmt, args); - - if (len >= alloc) - { - if (buf) - g_free (buf); - - alloc = nearest_pow (MAX (len + 1, 1024 + 1)); - - buf = g_new (gchar, alloc); - } - - vsprintf (buf, fmt, *args2); - - return buf; -} - static void -g_string_sprintfa_int (GString *string, +g_string_sprintfa_int (GString *string, const gchar *fmt, - va_list *args, - va_list *args2) + va_list args) { - g_string_append (string, g_vsprintf (fmt, args, args2)); + gchar *buffer; + + buffer = g_strdup_vprintf (fmt, args); + g_string_append (string, buffer); + g_free (buffer); } void @@ -619,17 +483,13 @@ g_string_sprintf (GString *string, const gchar *fmt, ...) { - va_list args, args2; - - va_start(args, fmt); - va_start(args2, fmt); + va_list args; g_string_truncate (string, 0); - g_string_sprintfa_int (string, fmt, &args, &args2); - - va_end(args); - va_end(args2); + va_start (args, fmt); + g_string_sprintfa_int (string, fmt, args); + va_end (args); } void @@ -637,13 +497,9 @@ g_string_sprintfa (GString *string, const gchar *fmt, ...) { - va_list args, args2; - - va_start(args, fmt); - va_start(args2, fmt); - - g_string_sprintfa_int (string, fmt, &args, &args2); + va_list args; - va_end(args); - va_end(args2); + va_start (args, fmt); + g_string_sprintfa_int (string, fmt, args); + va_end (args); } |