initialize GSlice config from G_SLICE environemtn variable. we support

Mon Jan 23 16:46:20 2006  Tim Janik  <timj@imendio.com>

        * glib/gslice.c (slice_config_init): initialize GSlice config from
        G_SLICE environemtn variable. we support G_SLICE=always-malloc
        currently, which forces all g_slice_*() allocations to use the system
        malloc instead.

        * glib/gutils.c:
        g_parse_debug_string(): added a note about not using g_malloc() here.
        _g_getenv_nomalloc(): getenv() variant that doesn't use g_malloc or
        g_slice. contains only guesswork in the WIN32 branch.
This commit is contained in:
Tim Janik 2006-01-23 15:51:06 +00:00 committed by Tim Janik
parent e511719c33
commit 75db578288
6 changed files with 123 additions and 5 deletions

View File

@ -1,3 +1,15 @@
Mon Jan 23 16:46:20 2006 Tim Janik <timj@imendio.com>
* glib/gslice.c (slice_config_init): initialize GSlice config from
G_SLICE environemtn variable. we support G_SLICE=always-malloc
currently, which forces all g_slice_*() allocations to use the system
malloc instead.
* glib/gutils.c:
g_parse_debug_string(): added a note about not using g_malloc() here.
_g_getenv_nomalloc(): getenv() variant that doesn't use g_malloc or
g_slice. contains only guesswork in the WIN32 branch.
2006-01-18 Matthias Clasen <mclasen@redhat.com>
* Bump version

View File

@ -1,3 +1,15 @@
Mon Jan 23 16:46:20 2006 Tim Janik <timj@imendio.com>
* glib/gslice.c (slice_config_init): initialize GSlice config from
G_SLICE environemtn variable. we support G_SLICE=always-malloc
currently, which forces all g_slice_*() allocations to use the system
malloc instead.
* glib/gutils.c:
g_parse_debug_string(): added a note about not using g_malloc() here.
_g_getenv_nomalloc(): getenv() variant that doesn't use g_malloc or
g_slice. contains only guesswork in the WIN32 branch.
2006-01-18 Matthias Clasen <mclasen@redhat.com>
* Bump version

View File

@ -1,3 +1,15 @@
Mon Jan 23 16:46:20 2006 Tim Janik <timj@imendio.com>
* glib/gslice.c (slice_config_init): initialize GSlice config from
G_SLICE environemtn variable. we support G_SLICE=always-malloc
currently, which forces all g_slice_*() allocations to use the system
malloc instead.
* glib/gutils.c:
g_parse_debug_string(): added a note about not using g_malloc() here.
_g_getenv_nomalloc(): getenv() variant that doesn't use g_malloc or
g_slice. contains only guesswork in the WIN32 branch.
2006-01-18 Matthias Clasen <mclasen@redhat.com>
* Bump version

View File

@ -180,10 +180,10 @@ static inline gsize allocator_get_magazine_threshold (Allocator *allocator,
guint ix);
/* --- variables --- */
static GPrivate *private_thread_memory = NULL;
static gsize sys_page_size = 0;
static Allocator allocator[1] = { { 0, }, };
static SliceConfig slice_config = {
static GPrivate *private_thread_memory = NULL;
static gsize sys_page_size = 0;
static Allocator allocator[1] = { { 0, }, };
static SliceConfig slice_config = {
FALSE, /* always_malloc */
FALSE, /* bypass_magazines */
15 * 1000, /* working_set_msecs */
@ -255,6 +255,23 @@ g_slice_get_config_state (GSliceConfig ckey,
}
}
static void
slice_config_init (SliceConfig *config)
{
/* don't use g_malloc/g_message here */
gchar buffer[1024];
const gchar *val = _g_getenv_nomalloc ("G_SLICE", buffer);
static const GDebugKey keys[] = {
{ "always-malloc", 1 << 0 },
};
gint flags = !val ? 0 : g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
*config = slice_config;
if (flags & (1 << 0)) /* always-malloc */
{
config->always_malloc = TRUE;
}
}
static void
g_slice_init_nomessage (void)
{
@ -273,7 +290,7 @@ g_slice_init_nomessage (void)
#endif
mem_assert (sys_page_size >= 2 * LARGEALIGNMENT);
mem_assert ((sys_page_size & (sys_page_size - 1)) == 0);
allocator->config = slice_config;
slice_config_init (&allocator->config);
allocator->min_page_size = sys_page_size;
#if HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN
/* allow allocation of pages up to 8KB (with 8KB alignment).

View File

@ -577,6 +577,11 @@ g_parse_debug_string (const gchar *string,
g_return_val_if_fail (string != NULL, 0);
/* this function is used by gmem.c/gslice.c initialization code,
* so introducing malloc dependencies here would require adaptions
* of those code portions.
*/
if (!g_ascii_strcasecmp (string, "all"))
{
for (i=0; i<nkeys; i++)
@ -1155,6 +1160,64 @@ g_getenv (const gchar *variable)
#endif /* G_OS_WIN32 */
}
/* _g_getenv_nomalloc
* this function does a getenv() without doing any kind of allocation
* through glib. it's suitable for chars <= 127 only (both, for the
* variable name and the contents) and for contents < 1024 chars in
* length. also, it aliases "" to a NULL return value.
**/
const gchar*
_g_getenv_nomalloc (const gchar *variable,
gchar buffer[1024])
{
#ifndef G_OS_WIN32
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;
#else /* G_OS_WIN32 */
if (G_WIN32_HAVE_WIDECHAR_API ())
{
/* convert variable name to wchar_t without malloc */
wchar_t wname[256], result[1024];
gint i, l = strlen (variable);
if (l >= 256)
return NULL;
for (i = 0; variable[i]; i++)
wname[i] = variable[i];
wname[i] = 0;
l = GetEnvironmentVariableW (wname, result, 1024);
if (l > 0 && l < 1024 && result[0])
{
/* convert variable contents from wchar_t without malloc */
for (i = 0; i < l; i++)
buffer[i] = result[i];
buffer[i] = 0;
return buffer;
}
return NULL;
}
else
{
gint l = GetEnvironmentVariableW (variable, buffer, 1024);
if (l > 0 && l < 1024 && buffer[0])
{
buffer[l] = 0;
return buffer;
}
return NULL;
}
#endif /* G_OS_WIN32 */
}
/**
* g_setenv:
* @variable: the environment variable to set, must not contain '='.

View File

@ -211,6 +211,8 @@ gboolean g_setenv (const gchar *variable,
gboolean overwrite);
void g_unsetenv (const gchar *variable);
gchar** g_listenv (void);
const gchar* _g_getenv_nomalloc (const gchar *variable,
gchar buffer[1024]);
/* we try to provide a usefull equivalent for ATEXIT if it is
* not defined, but use is actually abandoned. people should