>From 0ee89d5aa9eae1bf72e5cc715d8b2e3afce37703 Mon Sep 17 00:00:00 2001 From: Wolfgang Jenkner Date: Sun, 29 Nov 2015 17:39:56 +0100 Subject: [PATCH 2/5] For HYBRID_MALLOC, give most gmalloc symbols internal linkage. This avoids clashes with symbols if the after-dump malloc is derived from Doug Lea's implementation. * src/gmalloc.c (emacs_abort, __morecore, __default_morecore): Move declarations up. For HYBRID_MALLOC, turn all `extern' declarations below to `static' ones. (aligned_alloc): Declare for !MSDOS as well. (heapsize, _fraghead): Move resp. copy declaration downwards. For HYBRID_MALLOC, conditionalize out the other definitions, since the previous `static' declarations double as tentative definitions, anyway. (_malloc, _free, _realloc, __free_hook, _aligned_blocks) (__realloc_hook, __memalign_hook): Conditionalize out. (cfree, memalign, valloc): Ditto. --- src/gmalloc.c | 58 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/gmalloc.c b/src/gmalloc.c index 90a52a1..240408e 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -87,6 +87,20 @@ extern "C" #include +#ifdef emacs +extern void emacs_abort (void); +#endif + +/* Underlying allocation function; successive calls should + return contiguous pieces of memory. */ +extern void *(*__morecore) (ptrdiff_t size); + +/* Default value of `__morecore'. */ +extern void *__default_morecore (ptrdiff_t size); + +#ifdef HYBRID_MALLOC +#define extern static +#endif /* Allocate SIZE bytes of memory. */ extern void *malloc (size_t size) ATTRIBUTE_MALLOC_SIZE ((1)); @@ -99,8 +113,8 @@ extern void *calloc (size_t nmemb, size_t size) ATTRIBUTE_MALLOC_SIZE ((1,2)); extern void free (void *ptr); /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ -#ifdef MSDOS extern void *aligned_alloc (size_t, size_t); +#ifdef MSDOS extern void *memalign (size_t, size_t); extern int posix_memalign (void **, size_t, size_t); #endif @@ -110,10 +124,6 @@ extern int posix_memalign (void **, size_t, size_t); extern void malloc_enable_thread (void); #endif -#ifdef emacs -extern void emacs_abort (void); -#endif - /* The allocator divides the heap into blocks of fixed size; large requests receive one or more whole blocks, and small requests receive a fragment of a block. Fragment sizes are powers of two, @@ -249,13 +259,6 @@ extern int _malloc_thread_enabled_p; return the address of the beginning of the object. */ extern void *malloc_find_object_address (void *ptr); -/* Underlying allocation function; successive calls should - return contiguous pieces of memory. */ -extern void *(*__morecore) (ptrdiff_t size); - -/* Default value of `__morecore'. */ -extern void *__default_morecore (ptrdiff_t size); - /* If not NULL, this function is called after each time `__morecore' is called to increase the data size. */ extern void (*__after_morecore_hook) (void); @@ -318,6 +321,8 @@ extern struct mstats mstats (void); /* Call WARNFUN with a warning message when memory usage is high. */ extern void memory_warnings (void *start, void (*warnfun) (const char *)); +#undef extern + #ifdef __cplusplus } #endif @@ -346,6 +351,8 @@ License along with this library. If not, see . void *(*__morecore) (ptrdiff_t size) = __default_morecore; +#ifndef HYBRID_MALLOC + /* Debugging hook for `malloc'. */ void *(*__malloc_hook) (size_t size); @@ -355,9 +362,6 @@ char *_heapbase; /* Block information table. Allocated with align/__free (not malloc/free). */ malloc_info *_heapinfo; -/* Number of info entries. */ -static size_t heapsize; - /* Search index in the info table. */ size_t _heapindex; @@ -381,6 +385,15 @@ size_t __malloc_extra_blocks; void (*__malloc_initialize_hook) (void); void (*__after_morecore_hook) (void); +#else + +static struct list _fraghead[BLOCKLOG]; + +#endif /* HYBRID_MALLOC */ + +/* Number of info entries. */ +static size_t heapsize; + #if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE /* Some code for hunting a bug writing into _heapinfo. @@ -946,7 +959,7 @@ malloc (size_t size) return (hook != NULL ? *hook : _malloc_internal) (size); } -#ifndef _LIBC +#if !(defined (_LIBC) || defined (HYBRID_MALLOC)) /* On some ANSI C systems, some libc functions call _malloc, _free and _realloc. Make them use the GNU functions. */ @@ -995,11 +1008,13 @@ License along with this library. If not, see . or (US mail) as Mike Haertel c/o Free Software Foundation. */ +#ifndef HYBRID_MALLOC /* Debugging hook for free. */ void (*__free_hook) (void *__ptr); /* List of blocks allocated by aligned_alloc. */ struct alignlist *_aligned_blocks = NULL; +#endif /* Return memory to the heap. Like `_free_internal' but don't lock mutex. */ @@ -1270,6 +1285,7 @@ free (void *ptr) _free_internal (ptr); } +#ifndef HYBRID_MALLOC /* Define the `cfree' alias for `free'. */ #ifdef weak_alias weak_alias (free, cfree) @@ -1280,6 +1296,7 @@ cfree (void *ptr) free (ptr); } #endif +#endif /* Change the size of a block allocated by `malloc'. Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Written May 1989 by Mike Haertel. @@ -1304,8 +1321,10 @@ License along with this library. If not, see . #define min(a, b) ((a) < (b) ? (a) : (b)) #endif +#ifndef HYBRID_MALLOC /* Debugging hook for realloc. */ void *(*__realloc_hook) (void *ptr, size_t size); +#endif /* Resize the given region to the new size, returning a pointer to the (possibly moved) region. This is optimized for speed; @@ -1549,7 +1568,9 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with this library. If not, see . */ +#ifndef HYBRID_MALLOC void *(*__memalign_hook) (size_t size, size_t alignment); +#endif void * aligned_alloc (size_t alignment, size_t size) @@ -1638,6 +1659,8 @@ aligned_alloc (size_t alignment, size_t size) return result; } +/* Note that memalign and posix_memalign are not used in Emacs. */ +#ifndef HYBRID_MALLOC /* An obsolete alias for aligned_alloc, for any old libraries that use this alias. */ @@ -1649,7 +1672,6 @@ memalign (size_t alignment, size_t size) /* If HYBRID_MALLOC is defined, we may want to use the system posix_memalign below. */ -#ifndef HYBRID_MALLOC int posix_memalign (void **memptr, size_t alignment, size_t size) { @@ -1689,6 +1711,7 @@ License along with this library. If not, see . The author may be reached (Email) at the address mike@ai.mit.edu, or (US mail) as Mike Haertel c/o Free Software Foundation. */ +#ifndef HYBRID_MALLOC /* Allocate SIZE bytes on a page boundary. */ extern void *valloc (size_t); @@ -1708,6 +1731,7 @@ valloc (size_t size) return aligned_alloc (pagesize, size); } +#endif /* HYBRID_MALLOC */ #undef malloc #undef realloc -- 2.6.3