Commit a4817d83 authored by Paul Eggert's avatar Paul Eggert

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.
parent e4cd4a76
......@@ -1589,6 +1589,7 @@ fi
dnl checks for header files
AC_CHECK_HEADERS_ONCE(
malloc.h
sys/systeminfo.h
sys/sysinfo.h
coff.h pty.h
......
......@@ -59,6 +59,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "dosfns.h" /* For dos_memory_info. */
#endif
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#if (defined ENABLE_CHECKING \
&& defined HAVE_VALGRIND_VALGRIND_H \
&& !defined USE_VALGRIND)
......@@ -107,8 +111,6 @@ my_heap_start (void)
#ifdef DOUG_LEA_MALLOC
#include <malloc.h>
/* Specify maximum number of areas to mmap. It would be nice to use a
value that explicitly means "no limit". */
......
......@@ -99,7 +99,6 @@ typedef bool bool_bf;
#ifdef emacs
#define malloc hybrid_malloc
#define realloc hybrid_realloc
#define calloc hybrid_calloc
#define aligned_alloc hybrid_aligned_alloc
#define free hybrid_free
#endif
......
......@@ -134,8 +134,6 @@ bool might_dump;
extern void unexec_init_emacs_zone (void);
#endif
extern void malloc_enable_thread (void);
/* If true, Emacs should not attempt to use a window-specific code,
but instead should use the virtual terminal under which it was started. */
bool inhibit_window_system;
......
This diff is collapsed.
......@@ -3769,6 +3769,12 @@ extern void check_cons_list (void);
INLINE void (check_cons_list) (void) { lisp_h_check_cons_list (); }
#endif
#if !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC && !defined SYSTEM_MALLOC
/* Defined in gmalloc.c. */
extern size_t __malloc_extra_blocks;
#endif
extern void malloc_enable_thread (void);
#ifdef REL_ALLOC
/* Defined in ralloc.c. */
extern void *r_alloc (void **, size_t) ATTRIBUTE_ALLOC_SIZE ((2));
......
......@@ -22,31 +22,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
rather than all of them. This means allowing for a possible
hole between the first bloc and the end of malloc storage. */
#ifdef emacs
#include <config.h>
#include "lisp.h" /* Needed for VALBITS. */
#include "blockinput.h"
#include <unistd.h>
#ifdef DOUG_LEA_MALLOC
#define M_TOP_PAD -2
extern int mallopt (int, int);
#else /* not DOUG_LEA_MALLOC */
#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
extern size_t __malloc_extra_blocks;
#endif /* not SYSTEM_MALLOC and not HYBRID_MALLOC */
#endif /* not DOUG_LEA_MALLOC */
#else /* not emacs */
#include <stddef.h>
#include <malloc.h>
#endif /* not emacs */
#ifdef emacs
# include "lisp.h"
# include "blockinput.h"
# include <unistd.h>
#endif
#include "getpagesize.h"
......@@ -95,7 +79,9 @@ static int extra_bytes;
/* The hook `malloc' uses for the function which gets more space
from the system. */
#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#else
extern void *(*__morecore) (ptrdiff_t);
#endif
......
......@@ -51,9 +51,16 @@ char data_start[1] = { 1 };
# endif
#endif
/* From gmalloc.c. */
extern void (* __after_morecore_hook) (void);
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#ifndef __MALLOC_HOOK_VOLATILE
# define __MALLOC_HOOK_VOLATILE volatile
#endif
#ifndef HAVE_MALLOC_H
extern void *(*__morecore) (ptrdiff_t);
extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
#endif
/* From ralloc.c. */
#ifdef REL_ALLOC
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment