diff options
Diffstat (limited to 'malloc')
-rw-r--r-- | malloc/Makefile | 3 | ||||
-rw-r--r-- | malloc/malloc.c | 37 | ||||
-rw-r--r-- | malloc/malloc.h | 9 |
3 files changed, 36 insertions, 13 deletions
diff --git a/malloc/Makefile b/malloc/Makefile index 33502a9..b43ce13 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -50,4 +50,5 @@ $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o lib: $(objpfx)libmcheck.a -CPPFLAGS-malloc.o += -DMALLOC_DEBUG +# Uncomment this for test releases. For public releases it is too expensive. +#CPPFLAGS-malloc.o += -DMALLOC_DEBUG diff --git a/malloc/malloc.c b/malloc/malloc.c index 50bba6b..8ec5f85 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -647,7 +647,7 @@ do { \ might set to a value close to the average size of a process (program) running on your system. Releasing this much memory would allow such a process to run in memory. Generally, it's - worth it to tune for trimming rather tham memory mapping when a + worth it to tune for trimming rather than memory mapping when a program undergoes phases where several large chunks are allocated and released in ways that can reuse each other's storage, perhaps mixed with phases where there are no such @@ -1486,6 +1486,13 @@ static unsigned long max_mmapped_mem = 0; +#ifndef _LIBC +#define weak_variable +#else +/* In GNU libc we want the hook variables to be weak definitions to + avoid a problem with Emacs. */ +#define weak_variable weak_function +#endif /* Already initialized? */ int __malloc_initialized = 0; @@ -1533,12 +1540,20 @@ ptmalloc_init __MALLOC_P((void)) tsd_setspecific(arena_key, (Void_t *)&main_arena); #endif #if defined(_LIBC) || defined(MALLOC_HOOKS) + if((s = getenv("MALLOC_TRIM_THRESHOLD_"))) + mALLOPt(M_TRIM_THRESHOLD, atoi(s)); + if((s = getenv("MALLOC_TOP_PAD_"))) + mALLOPt(M_TOP_PAD, atoi(s)); + if((s = getenv("MALLOC_MMAP_THRESHOLD_"))) + mALLOPt(M_MMAP_THRESHOLD, atoi(s)); + if((s = getenv("MALLOC_MMAP_MAX_"))) + mALLOPt(M_MMAP_MAX, atoi(s)); s = getenv("MALLOC_CHECK_"); __malloc_hook = save_malloc_hook; __free_hook = save_free_hook; if(s) { - if(s[0]) mallopt(M_CHECK_ACTION, (int)(s[0] - '0')); - malloc_check_init(); + if(s[0]) mALLOPt(M_CHECK_ACTION, (int)(s[0] - '0')); + __malloc_check_init(); } if(__malloc_initialize_hook != NULL) (*__malloc_initialize_hook)(); @@ -1592,18 +1607,18 @@ memalign_hook_ini(sz, alignment) size_t sz; size_t alignment; return mEMALIGn(sz, alignment); } -void (*__malloc_initialize_hook) __MALLOC_P ((void)) = NULL; -void (*__free_hook) __MALLOC_P ((__malloc_ptr_t __ptr)) = NULL; -__malloc_ptr_t (*__malloc_hook) +void weak_variable (*__malloc_initialize_hook) __MALLOC_P ((void)) = NULL; +void weak_variable (*__free_hook) __MALLOC_P ((__malloc_ptr_t __ptr)) = NULL; +__malloc_ptr_t weak_variable (*__malloc_hook) __MALLOC_P ((size_t __size)) = malloc_hook_ini; -__malloc_ptr_t (*__realloc_hook) +__malloc_ptr_t weak_variable (*__realloc_hook) __MALLOC_P ((__malloc_ptr_t __ptr, size_t __size)) = realloc_hook_ini; -__malloc_ptr_t (*__memalign_hook) +__malloc_ptr_t weak_variable (*__memalign_hook) __MALLOC_P ((size_t __size, size_t __alignment)) = memalign_hook_ini; /* Activate a standard set of debugging hooks. */ void -malloc_check_init() +__malloc_check_init() { __malloc_hook = malloc_check; __free_hook = free_check; @@ -3265,10 +3280,12 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size; if (__malloc_hook != NULL) { sz = n * elem_size; mem = (*__malloc_hook)(sz); + if(mem == 0) + return 0; #ifdef HAVE_MEMCPY memset(mem, 0, sz); #else - while(sz > 0) mem[--sz] = 0; /* rather inefficient */ + while(sz > 0) ((char*)mem)[--sz] = 0; /* rather inefficient */ #endif return mem; } diff --git a/malloc/malloc.h b/malloc/malloc.h index ddbc694..5794f26 100644 --- a/malloc/malloc.h +++ b/malloc/malloc.h @@ -1,5 +1,5 @@ /* Prototypes and definition for malloc implementation. - Copyright (C) 1996 Free Software Foundation, Inc. + Copyright (C) 1996, 1997 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -74,6 +74,11 @@ extern "C" { #endif /* Nonzero if the malloc is already initialized. */ +#ifdef _LIBC +/* In the GNU libc we rename the global variable + `__malloc_initialized' to `__libc_malloc_initialized'. */ +#define __malloc_initialized __libc_malloc_initialized +#endif extern int __malloc_initialized; /* Initialize global configuration. Not needed with GNU libc. */ @@ -178,7 +183,7 @@ extern __malloc_ptr_t (*__memalign_hook) __MALLOC_P ((size_t __size, size_t __alignment)); /* Activate a standard set of debugging hooks. */ -extern void malloc_check_init __MALLOC_P ((void)); +extern void __malloc_check_init __MALLOC_P ((void)); #endif |