[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master cb22fce 01/15: Internal linkage for gmalloc etc. if
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master cb22fce 01/15: Internal linkage for gmalloc etc. if HYBRID_MALLOC |
Date: |
Sat, 30 Jan 2016 23:26:13 +0000 |
branch: master
commit cb22fce283e3852ea33a09f40707cf0c004c717e
Author: Wolfgang Jenkner <address@hidden>
Commit: Paul Eggert <address@hidden>
Internal linkage for gmalloc etc. if HYBRID_MALLOC
This avoids clashes with symbols if the after-dump malloc is
derived from Doug Lea's implementation (Bug#22086).
* 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 files changed, 41 insertions(+), 17 deletions(-)
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 00b8364..72d65af 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -87,6 +87,20 @@ extern "C"
#include <stddef.h>
+#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
<http://www.gnu.org/licenses/>.
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
<http://www.gnu.org/licenses/>.
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
<http://www.gnu.org/licenses/>.
#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 <http://www.gnu.org/licenses/>.
*/
+#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
<http://www.gnu.org/licenses/>.
The author may be reached (Email) at the address address@hidden,
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
- [Emacs-diffs] master updated (935b4d0 -> 692e410), Paul Eggert, 2016/01/30
- [Emacs-diffs] master dec1390 03/15: unexelf.c hook to support HYBRID_MALLOC on ELF, Paul Eggert, 2016/01/30
- [Emacs-diffs] master 874c59a 06/15: Report static heap usage on non-Cygwin, too, Paul Eggert, 2016/01/30
- [Emacs-diffs] master a5f8586 02/15: Link temacs with gnulib compiled with -Demacs, Paul Eggert, 2016/01/30
- [Emacs-diffs] master 384ffef 05/15: Pacify GCC on extern decls, Paul Eggert, 2016/01/30
- [Emacs-diffs] master d6585a9 04/15: Add musl patch to support HYBRID_MALLOC on elf systems, Paul Eggert, 2016/01/30
- [Emacs-diffs] master cb22fce 01/15: Internal linkage for gmalloc etc. if HYBRID_MALLOC,
Paul Eggert <=
- [Emacs-diffs] master e4cd4a7 08/15: * src/alloc.c: Include "sheap.h"., Paul Eggert, 2016/01/30
- [Emacs-diffs] master e1a9f20 07/15: Pacify --enable-gcc-warnings when HYBRID_MALLOC, Paul Eggert, 2016/01/30
- [Emacs-diffs] master 2ee2963 12/15: Shrink static heap a bit, Paul Eggert, 2016/01/30
- [Emacs-diffs] master 370a260 14/15: Make it easy to override preferred-branch test, Paul Eggert, 2016/01/30
- [Emacs-diffs] master 3d82a8e 11/15: Fix extern symbols defined and not used, Paul Eggert, 2016/01/30
- [Emacs-diffs] master 7fdc3cf 10/15: Build lib/e-*.o only on platforms that need it, Paul Eggert, 2016/01/30
- [Emacs-diffs] master a4817d8 09/15: Include <malloc.h> when advisable, Paul Eggert, 2016/01/30
- [Emacs-diffs] master 692e410 15/15: Tell Automake the new lib/Makefile.am is OK, Paul Eggert, 2016/01/30
- [Emacs-diffs] master ffbf163 13/15: ; Try to clean up ChangeLog.2 mess created by merge., Paul Eggert, 2016/01/30