Cleanups to debug env var handling

This commit is contained in:
Matthias Clasen 2011-11-12 19:13:44 -05:00
parent 943a18b564
commit 599f254066
3 changed files with 26 additions and 41 deletions

View File

@ -108,10 +108,10 @@ g_parse_debug_string (const gchar *string,
if (!strcasecmp (string, "help")) if (!strcasecmp (string, "help"))
{ {
/* using stdio directly for the reason stated above */ /* using stdio directly for the reason stated above */
fprintf (stderr, "Supported debug values: "); fprintf (stderr, "Supported debug values:");
for (i = 0; i < nkeys; i++) for (i = 0; i < nkeys; i++)
fprintf (stderr, " %s", keys[i].key); fprintf (stderr, " %s", keys[i].key);
fprintf (stderr, "\n"); fprintf (stderr, " all help\n");
} }
else else
{ {
@ -123,7 +123,7 @@ g_parse_debug_string (const gchar *string,
{ {
q = strpbrk (p, ":;, \t"); q = strpbrk (p, ":;, \t");
if (!q) if (!q)
q = p + strlen(p); q = p + strlen (p);
if (debug_key_matches ("all", p, q - p)) if (debug_key_matches ("all", p, q - p))
{ {

View File

@ -279,40 +279,28 @@ g_slice_get_config_state (GSliceConfig ckey,
} }
} }
static const gchar *
getenv_nomalloc (const gchar *variable,
gchar buffer[1024])
{
const gchar *retval = getenv (variable);
if (retval && retval[0])
{
gint l = strlen (retval);
if (l < 1024)
{
strncpy (buffer, retval, l);
buffer[l] = 0;
return buffer;
}
}
return NULL;
}
static void static void
slice_config_init (SliceConfig *config) slice_config_init (SliceConfig *config)
{ {
/* don't use g_malloc/g_message here */ const gchar *val;
gchar buffer[1024];
const gchar *val = getenv_nomalloc ("G_SLICE", buffer);
const GDebugKey keys[] = {
{ "always-malloc", 1 << 0 },
{ "debug-blocks", 1 << 1 },
};
gint flags = !val ? 0 : g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
*config = slice_config; *config = slice_config;
if (flags & (1 << 0)) /* always-malloc */
config->always_malloc = TRUE; val = getenv ("G_SLICE");
if (flags & (1 << 1)) /* debug-blocks */ if (val != NULL)
config->debug_blocks = TRUE; {
gint flags;
const GDebugKey keys[] = {
{ "always-malloc", 1 << 0 },
{ "debug-blocks", 1 << 1 },
};
flags = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
if (flags & (1 << 0))
config->always_malloc = TRUE;
if (flags & (1 << 1))
config->debug_blocks = TRUE;
}
} }
static void static void

View File

@ -4290,15 +4290,12 @@ g_type_init_with_debug_flags (GTypeDebugFlags debug_flags)
env_string = g_getenv ("GOBJECT_DEBUG"); env_string = g_getenv ("GOBJECT_DEBUG");
if (env_string != NULL) if (env_string != NULL)
{ {
static GDebugKey debug_keys[] = { GDebugKey debug_keys[] = {
{ "objects", G_TYPE_DEBUG_OBJECTS }, { "objects", G_TYPE_DEBUG_OBJECTS },
{ "signals", G_TYPE_DEBUG_SIGNALS }, { "signals", G_TYPE_DEBUG_SIGNALS },
}; };
_g_type_debug_flags |= g_parse_debug_string (env_string, _g_type_debug_flags |= g_parse_debug_string (env_string, debug_keys, G_N_ELEMENTS (debug_keys));
debug_keys,
sizeof (debug_keys) / sizeof (debug_keys[0]));
env_string = NULL;
} }
/* quarks */ /* quarks */