mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Avoid using stderr to be as robust as possible in out-of-memory.
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com> * gmessages.c (g_log_write_prefix): Avoid using stderr to be as robust as possible in out-of-memory. * gmessages.c (g_log_default_handler): Remove some dead code. * gutils.c (g_parse_debug_string): Fix to avoid mallocs.
This commit is contained in:
parent
72df5e6cab
commit
ac0bbb7605
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -1,3 +1,13 @@
|
||||
Thu May 10 23:21:30 2001 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* gmessages.c (g_log_write_prefix): Avoid using stderr
|
||||
to be as robust as possible in out-of-memory.
|
||||
|
||||
* gmessages.c (g_log_default_handler): Remove some dead
|
||||
code.
|
||||
|
||||
* gutils.c (g_parse_debug_string): Fix to avoid mallocs.
|
||||
|
||||
Fri May 11 18:25:23 2001 Tim Janik <timj@gtk.org>
|
||||
|
||||
* gdataset.c:
|
||||
|
@ -150,6 +150,59 @@ ensure_stdout_valid (void)
|
||||
#define ensure_stdout_valid() /* Define as empty */
|
||||
#endif
|
||||
|
||||
static void
|
||||
write_unsigned (gint fd,
|
||||
gulong num,
|
||||
guint radix)
|
||||
{
|
||||
char buffer[64];
|
||||
gulong tmp;
|
||||
char c;
|
||||
int i, n;
|
||||
|
||||
g_return_if_fail (radix >= 2 && radix <= 36);
|
||||
|
||||
if (!num)
|
||||
{
|
||||
write (fd, "0", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (radix == 16)
|
||||
write (fd, "0x", 2);
|
||||
else if (radix == 8)
|
||||
write (fd, "0", 1);
|
||||
|
||||
n = 0;
|
||||
tmp = num;
|
||||
while (tmp)
|
||||
{
|
||||
tmp /= radix;
|
||||
n++;
|
||||
}
|
||||
|
||||
i = n;
|
||||
while (num)
|
||||
{
|
||||
i--;
|
||||
c = (num % radix);
|
||||
if (c < 10)
|
||||
buffer[i] = c + '0';
|
||||
else
|
||||
buffer[i] = c + 'a' - 10;
|
||||
num /= radix;
|
||||
}
|
||||
|
||||
write (fd, buffer, n);
|
||||
}
|
||||
|
||||
static void
|
||||
write_string (gint fd,
|
||||
gchar *string)
|
||||
{
|
||||
write (fd, string, strlen (string));
|
||||
}
|
||||
|
||||
static void
|
||||
g_log_write_prefix (gint fd,
|
||||
GLogLevelFlags mask)
|
||||
@ -185,20 +238,20 @@ g_log_write_prefix (gint fd,
|
||||
|
||||
if ((g_log_msg_prefix & mask) == mask)
|
||||
{
|
||||
gchar prg_pid[64], *prg_name;
|
||||
gchar *prg_name;
|
||||
|
||||
prg_name = g_get_prgname ();
|
||||
|
||||
|
||||
if (!prg_name)
|
||||
{
|
||||
prg_name = "(process";
|
||||
sprintf (prg_pid, ":%u): ", getpid ());
|
||||
}
|
||||
write_string (fd, "(process:");
|
||||
else
|
||||
sprintf (prg_pid, " (pid:%u): ", getpid ());
|
||||
|
||||
write (fd, prg_name, strlen (prg_name));
|
||||
write (fd, prg_pid, strlen (prg_pid));
|
||||
{
|
||||
write_string (fd, prg_name);
|
||||
write_string (fd, " (pid:");
|
||||
}
|
||||
|
||||
write_unsigned (fd, getpid (), 10);
|
||||
write_string (fd, "): ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -530,7 +583,6 @@ g_log_default_handler (const gchar *log_domain,
|
||||
GErrorFunc local_glib_error_func;
|
||||
GWarningFunc local_glib_warning_func;
|
||||
GPrintFunc local_glib_message_func;
|
||||
gchar prg_pid[64], *prg_name = g_get_prgname ();
|
||||
|
||||
in_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
|
||||
is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
|
||||
@ -538,13 +590,6 @@ g_log_default_handler (const gchar *log_domain,
|
||||
|
||||
if (!message)
|
||||
message = "g_log_default_handler(): (NULL) message";
|
||||
if (!prg_name)
|
||||
{
|
||||
prg_name = "(process";
|
||||
sprintf (prg_pid, ":%u): ", getpid ());
|
||||
}
|
||||
else
|
||||
sprintf (prg_pid, " (pid:%u): ", getpid ());
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
/* Use just stdout as stderr is hard to get redirected from the
|
||||
|
@ -437,9 +437,8 @@ g_parse_debug_string (const gchar *string,
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *str = g_strdup (string);
|
||||
gchar *p = str;
|
||||
gchar *q;
|
||||
const gchar *p = string;
|
||||
const gchar *q;
|
||||
gboolean done = FALSE;
|
||||
|
||||
while (*p && !done)
|
||||
@ -451,16 +450,13 @@ g_parse_debug_string (const gchar *string,
|
||||
done = TRUE;
|
||||
}
|
||||
|
||||
*q = 0;
|
||||
|
||||
for (i=0; i<nkeys; i++)
|
||||
if (!g_strcasecmp(keys[i].key, p))
|
||||
if (g_strncasecmp(keys[i].key, p, q - p) == 0 &&
|
||||
keys[i].key[q - p] == '\0')
|
||||
result |= keys[i].value;
|
||||
|
||||
p = q+1;
|
||||
p = q + 1;
|
||||
}
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
81
gmessages.c
81
gmessages.c
@ -150,6 +150,59 @@ ensure_stdout_valid (void)
|
||||
#define ensure_stdout_valid() /* Define as empty */
|
||||
#endif
|
||||
|
||||
static void
|
||||
write_unsigned (gint fd,
|
||||
gulong num,
|
||||
guint radix)
|
||||
{
|
||||
char buffer[64];
|
||||
gulong tmp;
|
||||
char c;
|
||||
int i, n;
|
||||
|
||||
g_return_if_fail (radix >= 2 && radix <= 36);
|
||||
|
||||
if (!num)
|
||||
{
|
||||
write (fd, "0", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (radix == 16)
|
||||
write (fd, "0x", 2);
|
||||
else if (radix == 8)
|
||||
write (fd, "0", 1);
|
||||
|
||||
n = 0;
|
||||
tmp = num;
|
||||
while (tmp)
|
||||
{
|
||||
tmp /= radix;
|
||||
n++;
|
||||
}
|
||||
|
||||
i = n;
|
||||
while (num)
|
||||
{
|
||||
i--;
|
||||
c = (num % radix);
|
||||
if (c < 10)
|
||||
buffer[i] = c + '0';
|
||||
else
|
||||
buffer[i] = c + 'a' - 10;
|
||||
num /= radix;
|
||||
}
|
||||
|
||||
write (fd, buffer, n);
|
||||
}
|
||||
|
||||
static void
|
||||
write_string (gint fd,
|
||||
gchar *string)
|
||||
{
|
||||
write (fd, string, strlen (string));
|
||||
}
|
||||
|
||||
static void
|
||||
g_log_write_prefix (gint fd,
|
||||
GLogLevelFlags mask)
|
||||
@ -185,20 +238,20 @@ g_log_write_prefix (gint fd,
|
||||
|
||||
if ((g_log_msg_prefix & mask) == mask)
|
||||
{
|
||||
gchar prg_pid[64], *prg_name;
|
||||
gchar *prg_name;
|
||||
|
||||
prg_name = g_get_prgname ();
|
||||
|
||||
|
||||
if (!prg_name)
|
||||
{
|
||||
prg_name = "(process";
|
||||
sprintf (prg_pid, ":%u): ", getpid ());
|
||||
}
|
||||
write_string (fd, "(process:");
|
||||
else
|
||||
sprintf (prg_pid, " (pid:%u): ", getpid ());
|
||||
|
||||
write (fd, prg_name, strlen (prg_name));
|
||||
write (fd, prg_pid, strlen (prg_pid));
|
||||
{
|
||||
write_string (fd, prg_name);
|
||||
write_string (fd, " (pid:");
|
||||
}
|
||||
|
||||
write_unsigned (fd, getpid (), 10);
|
||||
write_string (fd, "): ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -530,7 +583,6 @@ g_log_default_handler (const gchar *log_domain,
|
||||
GErrorFunc local_glib_error_func;
|
||||
GWarningFunc local_glib_warning_func;
|
||||
GPrintFunc local_glib_message_func;
|
||||
gchar prg_pid[64], *prg_name = g_get_prgname ();
|
||||
|
||||
in_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
|
||||
is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
|
||||
@ -538,13 +590,6 @@ g_log_default_handler (const gchar *log_domain,
|
||||
|
||||
if (!message)
|
||||
message = "g_log_default_handler(): (NULL) message";
|
||||
if (!prg_name)
|
||||
{
|
||||
prg_name = "(process";
|
||||
sprintf (prg_pid, ":%u): ", getpid ());
|
||||
}
|
||||
else
|
||||
sprintf (prg_pid, " (pid:%u): ", getpid ());
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
/* Use just stdout as stderr is hard to get redirected from the
|
||||
|
14
gutils.c
14
gutils.c
@ -437,9 +437,8 @@ g_parse_debug_string (const gchar *string,
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *str = g_strdup (string);
|
||||
gchar *p = str;
|
||||
gchar *q;
|
||||
const gchar *p = string;
|
||||
const gchar *q;
|
||||
gboolean done = FALSE;
|
||||
|
||||
while (*p && !done)
|
||||
@ -451,16 +450,13 @@ g_parse_debug_string (const gchar *string,
|
||||
done = TRUE;
|
||||
}
|
||||
|
||||
*q = 0;
|
||||
|
||||
for (i=0; i<nkeys; i++)
|
||||
if (!g_strcasecmp(keys[i].key, p))
|
||||
if (g_strncasecmp(keys[i].key, p, q - p) == 0 &&
|
||||
keys[i].key[q - p] == '\0')
|
||||
result |= keys[i].value;
|
||||
|
||||
p = q+1;
|
||||
p = q + 1;
|
||||
}
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user