aboutsummaryrefslogtreecommitdiffstats
path: root/src/ralloc.c
diff options
context:
space:
mode:
authorPaul Eggert2016-01-30 14:20:57 -0800
committerPaul Eggert2016-01-30 15:26:08 -0800
commita4817d834e7d125d31049dfb6fd0a0df4782bad0 (patch)
treeb2e63ff90a6307c20982e55fd779f670c28f6244 /src/ralloc.c
parente4cd4a76a621927bc155a18353ef7fd09133887d (diff)
downloademacs-a4817d834e7d125d31049dfb6fd0a0df4782bad0.tar.gz
emacs-a4817d834e7d125d31049dfb6fd0a0df4782bad0.zip
Include <malloc.h> when advisable
This should help insulate us better from future glibc changes. It is good hygiene to include .h files for APIs that Emacs uses. Fix type clashes between Emacs and GNU <malloc.h> (Bug#22086). * configure.ac: Check for malloc.h. * src/alloc.c: Include <malloc.h> depending on HAVE_MALLOC_H, not on DOUG_LEA_MALLOC. * src/emacs.c, src/gmalloc.c (malloc_enable_thread): Remove decl (now in lisp.h). * src/gmalloc.c: Include stddef.h earlier, for ptrdiff_t. [emacs]: Include lisp.h. [HAVE_MALLOC_H]: Include <malloc.h>. (__MALLOC_HOOK_VOLATILE): New macro, if not already defined. (__after_morecore_hook, __malloc_initialize_hook, __morecore) (__default_morecore): [!HAVE_MALLOC_H]: New decls near non-inclusion of <malloc.h>. (calloc): Make it clear that the macro should not be used. Remove unused decl. (malloc_info): New macro, to avoid clash with glibc <malloc.h>. (__morecore, __default_morecore, __after_morecore_hook) (__malloc_extra_blocks, __malloc_initialize_hook, __free_hook) (__malloc_hook, __realloc_hook, __memalign_hook, memory_warnings): Remove later decls. (gmalloc_hook, gfree_hook, grealloc_hook): Rename from __malloc_hook, __free_hook, __realloc_hook to avoid type collision with glibc <malloc.h>. All uses changed. (gmalloc_hook): (__malloc_extra_blocks) [DOUG_LEA_MALLOC||HYBRID_MALLOC||SYSTEM_MALLOC]: Now static. (gmalloc_hook, __malloc_extra_blocks): Define even if [!HYBRID_MALLOC]. (__malloc_initialize_hook, __after_morecore_hook): Declare with types compatible with glibc. (__memalign_hook, hybrid_calloc) [HYBRID_MALLOC]: Remove. All uses removed. * src/lisp.h (__malloc_extra_blocks, malloc_enable_thread): New decls. * src/ralloc.c, src/vm-limit.c: Simplify includes and include <malloc.h> if available.
Diffstat (limited to 'src/ralloc.c')
-rw-r--r--src/ralloc.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/src/ralloc.c b/src/ralloc.c
index 12d2fa9ab50..d1a9e01652e 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -22,31 +22,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 rather than all of them. This means allowing for a possible 22 rather than all of them. This means allowing for a possible
23 hole between the first bloc and the end of malloc storage. */ 23 hole between the first bloc and the end of malloc storage. */
24 24
25#ifdef emacs
26
27#include <config.h> 25#include <config.h>
28 26
29#include "lisp.h" /* Needed for VALBITS. */
30#include "blockinput.h"
31
32#include <unistd.h>
33
34#ifdef DOUG_LEA_MALLOC
35#define M_TOP_PAD -2
36extern int mallopt (int, int);
37#else /* not DOUG_LEA_MALLOC */
38#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
39extern size_t __malloc_extra_blocks;
40#endif /* not SYSTEM_MALLOC and not HYBRID_MALLOC */
41#endif /* not DOUG_LEA_MALLOC */
42
43#else /* not emacs */
44
45#include <stddef.h> 27#include <stddef.h>
46#include <malloc.h>
47
48#endif /* not emacs */
49 28
29#ifdef emacs
30# include "lisp.h"
31# include "blockinput.h"
32# include <unistd.h>
33#endif
50 34
51#include "getpagesize.h" 35#include "getpagesize.h"
52 36
@@ -95,7 +79,9 @@ static int extra_bytes;
95/* The hook `malloc' uses for the function which gets more space 79/* The hook `malloc' uses for the function which gets more space
96 from the system. */ 80 from the system. */
97 81
98#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 82#ifdef HAVE_MALLOC_H
83# include <malloc.h>
84#else
99extern void *(*__morecore) (ptrdiff_t); 85extern void *(*__morecore) (ptrdiff_t);
100#endif 86#endif
101 87