diff options
| author | Wolfgang Jenkner | 2016-01-30 14:20:55 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-01-30 15:26:06 -0800 |
| commit | cb22fce283e3852ea33a09f40707cf0c004c717e (patch) | |
| tree | f5d16201ab6b8afa06401a7b9e7d2d3deadc225e /src/gmalloc.c | |
| parent | 935b4d0ce4b1f03dedd276548fd506bea1f0c0fd (diff) | |
| download | emacs-cb22fce283e3852ea33a09f40707cf0c004c717e.tar.gz emacs-cb22fce283e3852ea33a09f40707cf0c004c717e.zip | |
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.
Diffstat (limited to 'src/gmalloc.c')
| -rw-r--r-- | src/gmalloc.c | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index 00b83641319..72d65af4974 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c | |||
| @@ -87,6 +87,20 @@ extern "C" | |||
| 87 | 87 | ||
| 88 | #include <stddef.h> | 88 | #include <stddef.h> |
| 89 | 89 | ||
| 90 | #ifdef emacs | ||
| 91 | extern void emacs_abort (void); | ||
| 92 | #endif | ||
| 93 | |||
| 94 | /* Underlying allocation function; successive calls should | ||
| 95 | return contiguous pieces of memory. */ | ||
| 96 | extern void *(*__morecore) (ptrdiff_t size); | ||
| 97 | |||
| 98 | /* Default value of `__morecore'. */ | ||
| 99 | extern void *__default_morecore (ptrdiff_t size); | ||
| 100 | |||
| 101 | #ifdef HYBRID_MALLOC | ||
| 102 | #define extern static | ||
| 103 | #endif | ||
| 90 | 104 | ||
| 91 | /* Allocate SIZE bytes of memory. */ | 105 | /* Allocate SIZE bytes of memory. */ |
| 92 | extern void *malloc (size_t size) ATTRIBUTE_MALLOC_SIZE ((1)); | 106 | 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)); | |||
| 99 | extern void free (void *ptr); | 113 | extern void free (void *ptr); |
| 100 | 114 | ||
| 101 | /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ | 115 | /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */ |
| 102 | #ifdef MSDOS | ||
| 103 | extern void *aligned_alloc (size_t, size_t); | 116 | extern void *aligned_alloc (size_t, size_t); |
| 117 | #ifdef MSDOS | ||
| 104 | extern void *memalign (size_t, size_t); | 118 | extern void *memalign (size_t, size_t); |
| 105 | extern int posix_memalign (void **, size_t, size_t); | 119 | extern int posix_memalign (void **, size_t, size_t); |
| 106 | #endif | 120 | #endif |
| @@ -110,10 +124,6 @@ extern int posix_memalign (void **, size_t, size_t); | |||
| 110 | extern void malloc_enable_thread (void); | 124 | extern void malloc_enable_thread (void); |
| 111 | #endif | 125 | #endif |
| 112 | 126 | ||
| 113 | #ifdef emacs | ||
| 114 | extern void emacs_abort (void); | ||
| 115 | #endif | ||
| 116 | |||
| 117 | /* The allocator divides the heap into blocks of fixed size; large | 127 | /* The allocator divides the heap into blocks of fixed size; large |
| 118 | requests receive one or more whole blocks, and small requests | 128 | requests receive one or more whole blocks, and small requests |
| 119 | receive a fragment of a block. Fragment sizes are powers of two, | 129 | receive a fragment of a block. Fragment sizes are powers of two, |
| @@ -249,13 +259,6 @@ extern int _malloc_thread_enabled_p; | |||
| 249 | return the address of the beginning of the object. */ | 259 | return the address of the beginning of the object. */ |
| 250 | extern void *malloc_find_object_address (void *ptr); | 260 | extern void *malloc_find_object_address (void *ptr); |
| 251 | 261 | ||
| 252 | /* Underlying allocation function; successive calls should | ||
| 253 | return contiguous pieces of memory. */ | ||
| 254 | extern void *(*__morecore) (ptrdiff_t size); | ||
| 255 | |||
| 256 | /* Default value of `__morecore'. */ | ||
| 257 | extern void *__default_morecore (ptrdiff_t size); | ||
| 258 | |||
| 259 | /* If not NULL, this function is called after each time | 262 | /* If not NULL, this function is called after each time |
| 260 | `__morecore' is called to increase the data size. */ | 263 | `__morecore' is called to increase the data size. */ |
| 261 | extern void (*__after_morecore_hook) (void); | 264 | extern void (*__after_morecore_hook) (void); |
| @@ -318,6 +321,8 @@ extern struct mstats mstats (void); | |||
| 318 | /* Call WARNFUN with a warning message when memory usage is high. */ | 321 | /* Call WARNFUN with a warning message when memory usage is high. */ |
| 319 | extern void memory_warnings (void *start, void (*warnfun) (const char *)); | 322 | extern void memory_warnings (void *start, void (*warnfun) (const char *)); |
| 320 | 323 | ||
| 324 | #undef extern | ||
| 325 | |||
| 321 | #ifdef __cplusplus | 326 | #ifdef __cplusplus |
| 322 | } | 327 | } |
| 323 | #endif | 328 | #endif |
| @@ -346,6 +351,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 346 | 351 | ||
| 347 | void *(*__morecore) (ptrdiff_t size) = __default_morecore; | 352 | void *(*__morecore) (ptrdiff_t size) = __default_morecore; |
| 348 | 353 | ||
| 354 | #ifndef HYBRID_MALLOC | ||
| 355 | |||
| 349 | /* Debugging hook for `malloc'. */ | 356 | /* Debugging hook for `malloc'. */ |
| 350 | void *(*__malloc_hook) (size_t size); | 357 | void *(*__malloc_hook) (size_t size); |
| 351 | 358 | ||
| @@ -355,9 +362,6 @@ char *_heapbase; | |||
| 355 | /* Block information table. Allocated with align/__free (not malloc/free). */ | 362 | /* Block information table. Allocated with align/__free (not malloc/free). */ |
| 356 | malloc_info *_heapinfo; | 363 | malloc_info *_heapinfo; |
| 357 | 364 | ||
| 358 | /* Number of info entries. */ | ||
| 359 | static size_t heapsize; | ||
| 360 | |||
| 361 | /* Search index in the info table. */ | 365 | /* Search index in the info table. */ |
| 362 | size_t _heapindex; | 366 | size_t _heapindex; |
| 363 | 367 | ||
| @@ -381,6 +385,15 @@ size_t __malloc_extra_blocks; | |||
| 381 | void (*__malloc_initialize_hook) (void); | 385 | void (*__malloc_initialize_hook) (void); |
| 382 | void (*__after_morecore_hook) (void); | 386 | void (*__after_morecore_hook) (void); |
| 383 | 387 | ||
| 388 | #else | ||
| 389 | |||
| 390 | static struct list _fraghead[BLOCKLOG]; | ||
| 391 | |||
| 392 | #endif /* HYBRID_MALLOC */ | ||
| 393 | |||
| 394 | /* Number of info entries. */ | ||
| 395 | static size_t heapsize; | ||
| 396 | |||
| 384 | #if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE | 397 | #if defined GC_MALLOC_CHECK && defined GC_PROTECT_MALLOC_STATE |
| 385 | 398 | ||
| 386 | /* Some code for hunting a bug writing into _heapinfo. | 399 | /* Some code for hunting a bug writing into _heapinfo. |
| @@ -946,7 +959,7 @@ malloc (size_t size) | |||
| 946 | return (hook != NULL ? *hook : _malloc_internal) (size); | 959 | return (hook != NULL ? *hook : _malloc_internal) (size); |
| 947 | } | 960 | } |
| 948 | 961 | ||
| 949 | #ifndef _LIBC | 962 | #if !(defined (_LIBC) || defined (HYBRID_MALLOC)) |
| 950 | 963 | ||
| 951 | /* On some ANSI C systems, some libc functions call _malloc, _free | 964 | /* On some ANSI C systems, some libc functions call _malloc, _free |
| 952 | and _realloc. Make them use the GNU functions. */ | 965 | 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/>. | |||
| 995 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 1008 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| 996 | 1009 | ||
| 997 | 1010 | ||
| 1011 | #ifndef HYBRID_MALLOC | ||
| 998 | /* Debugging hook for free. */ | 1012 | /* Debugging hook for free. */ |
| 999 | void (*__free_hook) (void *__ptr); | 1013 | void (*__free_hook) (void *__ptr); |
| 1000 | 1014 | ||
| 1001 | /* List of blocks allocated by aligned_alloc. */ | 1015 | /* List of blocks allocated by aligned_alloc. */ |
| 1002 | struct alignlist *_aligned_blocks = NULL; | 1016 | struct alignlist *_aligned_blocks = NULL; |
| 1017 | #endif | ||
| 1003 | 1018 | ||
| 1004 | /* Return memory to the heap. | 1019 | /* Return memory to the heap. |
| 1005 | Like `_free_internal' but don't lock mutex. */ | 1020 | Like `_free_internal' but don't lock mutex. */ |
| @@ -1270,6 +1285,7 @@ free (void *ptr) | |||
| 1270 | _free_internal (ptr); | 1285 | _free_internal (ptr); |
| 1271 | } | 1286 | } |
| 1272 | 1287 | ||
| 1288 | #ifndef HYBRID_MALLOC | ||
| 1273 | /* Define the `cfree' alias for `free'. */ | 1289 | /* Define the `cfree' alias for `free'. */ |
| 1274 | #ifdef weak_alias | 1290 | #ifdef weak_alias |
| 1275 | weak_alias (free, cfree) | 1291 | weak_alias (free, cfree) |
| @@ -1280,6 +1296,7 @@ cfree (void *ptr) | |||
| 1280 | free (ptr); | 1296 | free (ptr); |
| 1281 | } | 1297 | } |
| 1282 | #endif | 1298 | #endif |
| 1299 | #endif | ||
| 1283 | /* Change the size of a block allocated by `malloc'. | 1300 | /* Change the size of a block allocated by `malloc'. |
| 1284 | Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. | 1301 | Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. |
| 1285 | Written May 1989 by Mike Haertel. | 1302 | Written May 1989 by Mike Haertel. |
| @@ -1304,8 +1321,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 1304 | #define min(a, b) ((a) < (b) ? (a) : (b)) | 1321 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| 1305 | #endif | 1322 | #endif |
| 1306 | 1323 | ||
| 1324 | #ifndef HYBRID_MALLOC | ||
| 1307 | /* Debugging hook for realloc. */ | 1325 | /* Debugging hook for realloc. */ |
| 1308 | void *(*__realloc_hook) (void *ptr, size_t size); | 1326 | void *(*__realloc_hook) (void *ptr, size_t size); |
| 1327 | #endif | ||
| 1309 | 1328 | ||
| 1310 | /* Resize the given region to the new size, returning a pointer | 1329 | /* Resize the given region to the new size, returning a pointer |
| 1311 | to the (possibly moved) region. This is optimized for speed; | 1330 | to the (possibly moved) region. This is optimized for speed; |
| @@ -1549,7 +1568,9 @@ General Public License for more details. | |||
| 1549 | You should have received a copy of the GNU General Public | 1568 | You should have received a copy of the GNU General Public |
| 1550 | License along with this library. If not, see <http://www.gnu.org/licenses/>. */ | 1569 | License along with this library. If not, see <http://www.gnu.org/licenses/>. */ |
| 1551 | 1570 | ||
| 1571 | #ifndef HYBRID_MALLOC | ||
| 1552 | void *(*__memalign_hook) (size_t size, size_t alignment); | 1572 | void *(*__memalign_hook) (size_t size, size_t alignment); |
| 1573 | #endif | ||
| 1553 | 1574 | ||
| 1554 | void * | 1575 | void * |
| 1555 | aligned_alloc (size_t alignment, size_t size) | 1576 | aligned_alloc (size_t alignment, size_t size) |
| @@ -1638,6 +1659,8 @@ aligned_alloc (size_t alignment, size_t size) | |||
| 1638 | return result; | 1659 | return result; |
| 1639 | } | 1660 | } |
| 1640 | 1661 | ||
| 1662 | /* Note that memalign and posix_memalign are not used in Emacs. */ | ||
| 1663 | #ifndef HYBRID_MALLOC | ||
| 1641 | /* An obsolete alias for aligned_alloc, for any old libraries that use | 1664 | /* An obsolete alias for aligned_alloc, for any old libraries that use |
| 1642 | this alias. */ | 1665 | this alias. */ |
| 1643 | 1666 | ||
| @@ -1649,7 +1672,6 @@ memalign (size_t alignment, size_t size) | |||
| 1649 | 1672 | ||
| 1650 | /* If HYBRID_MALLOC is defined, we may want to use the system | 1673 | /* If HYBRID_MALLOC is defined, we may want to use the system |
| 1651 | posix_memalign below. */ | 1674 | posix_memalign below. */ |
| 1652 | #ifndef HYBRID_MALLOC | ||
| 1653 | int | 1675 | int |
| 1654 | posix_memalign (void **memptr, size_t alignment, size_t size) | 1676 | posix_memalign (void **memptr, size_t alignment, size_t size) |
| 1655 | { | 1677 | { |
| @@ -1689,6 +1711,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 1689 | The author may be reached (Email) at the address mike@ai.mit.edu, | 1711 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 1690 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ | 1712 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| 1691 | 1713 | ||
| 1714 | #ifndef HYBRID_MALLOC | ||
| 1692 | /* Allocate SIZE bytes on a page boundary. */ | 1715 | /* Allocate SIZE bytes on a page boundary. */ |
| 1693 | extern void *valloc (size_t); | 1716 | extern void *valloc (size_t); |
| 1694 | 1717 | ||
| @@ -1708,6 +1731,7 @@ valloc (size_t size) | |||
| 1708 | 1731 | ||
| 1709 | return aligned_alloc (pagesize, size); | 1732 | return aligned_alloc (pagesize, size); |
| 1710 | } | 1733 | } |
| 1734 | #endif /* HYBRID_MALLOC */ | ||
| 1711 | 1735 | ||
| 1712 | #undef malloc | 1736 | #undef malloc |
| 1713 | #undef realloc | 1737 | #undef realloc |