aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2021-05-20 11:26:00 +0300
committerEli Zaretskii2021-05-20 11:26:00 +0300
commitb2eed2ae568b53ac910f4a3b8458eedf8d8c67ec (patch)
treebff25c6d02605018e916b904ef77454812ca0f64 /src
parentd68f2b8681f8eeb6bbf1b4476a88f00b2962179e (diff)
downloademacs-b2eed2ae568b53ac910f4a3b8458eedf8d8c67ec.tar.gz
emacs-b2eed2ae568b53ac910f4a3b8458eedf8d8c67ec.zip
Clean up the fix for unexec build on GNU/Linux
* src/conf_post.h [HYBRID_MALLOC || DARWIN_OS && HAVE_UNEXEC]: Include <stdlib.h> here, before redirecting 'malloc' and friends to their hybrid_* and unexec_* equivalents. #undef malloc and friends before redefining. Provide prototypes for the replacements. Suggested by Paul Eggert <eggert@cs.ucla.edu>. * src/gmalloc.c [HYBRID_MALLOC]: Remove declarations of 'malloc' and friends, as they are now redundant: we include <stdlib.h> in conf_post.h before redefining 'malloc' etc., and that provides prototypes from system headers. * configure.ac (HYBRID_MALLOC): Remove kludge to avoid replacement of 'free' by Gnulib. (Bug#36649)
Diffstat (limited to 'src')
-rw-r--r--src/conf_post.h31
-rw-r--r--src/gmalloc.c10
2 files changed, 30 insertions, 11 deletions
diff --git a/src/conf_post.h b/src/conf_post.h
index 176ab28b21a..8558dc466cc 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -99,10 +99,28 @@ typedef bool bool_bf;
99# define ADDRESS_SANITIZER false 99# define ADDRESS_SANITIZER false
100#endif 100#endif
101 101
102#ifdef emacs
103/* We include stdlib.h here, because Gnulib's stdlib.h might redirect
104 'free' to its replacement, and we want to avoid that in unexec
105 builds. Inclduing it here will render its inclusion after config.h
106 a no-op. */
107# if (defined DARWIN_OS && defined HAVE_UNEXEC) || defined HYBRID_MALLOC
108# include <stdlib.h>
109# endif
110#endif
111
102#if defined DARWIN_OS && defined emacs && defined HAVE_UNEXEC 112#if defined DARWIN_OS && defined emacs && defined HAVE_UNEXEC
113# undef malloc
103# define malloc unexec_malloc 114# define malloc unexec_malloc
115# undef realloc
104# define realloc unexec_realloc 116# define realloc unexec_realloc
117# undef free
105# define free unexec_free 118# define free unexec_free
119
120extern void *unexec_malloc (size_t);
121extern void *unexec_realloc (void *, size_t);
122extern void unexec_free (void *);
123
106#endif 124#endif
107 125
108/* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use 126/* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
@@ -111,12 +129,23 @@ typedef bool bool_bf;
111 accomplish this. */ 129 accomplish this. */
112#ifdef HYBRID_MALLOC 130#ifdef HYBRID_MALLOC
113#ifdef emacs 131#ifdef emacs
132#undef malloc
114#define malloc hybrid_malloc 133#define malloc hybrid_malloc
134#undef realloc
115#define realloc hybrid_realloc 135#define realloc hybrid_realloc
136#undef aligned_alloc
116#define aligned_alloc hybrid_aligned_alloc 137#define aligned_alloc hybrid_aligned_alloc
138#undef calloc
117#define calloc hybrid_calloc 139#define calloc hybrid_calloc
140#undef free
118#define free hybrid_free 141#define free hybrid_free
119#endif 142
143extern void *hybrid_malloc (size_t);
144extern void *hybrid_calloc (size_t, size_t);
145extern void hybrid_free (void *);
146extern void *hybrid_aligned_alloc (size_t, size_t);
147extern void *hybrid_realloc (void *, size_t);
148#endif /* emacs */
120#endif /* HYBRID_MALLOC */ 149#endif /* HYBRID_MALLOC */
121 150
122/* We have to go this route, rather than the old hpux9 approach of 151/* We have to go this route, rather than the old hpux9 approach of
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 66008ea69b2..dedd25fa22f 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -1690,16 +1690,6 @@ valloc (size_t size)
1690#undef free 1690#undef free
1691 1691
1692#ifdef HYBRID_MALLOC 1692#ifdef HYBRID_MALLOC
1693/* Declare system malloc and friends. */
1694extern void *malloc (size_t size);
1695extern void *realloc (void *ptr, size_t size);
1696extern void *calloc (size_t nmemb, size_t size);
1697extern void free (void *ptr);
1698#ifdef HAVE_ALIGNED_ALLOC
1699extern void *aligned_alloc (size_t alignment, size_t size);
1700#elif defined HAVE_POSIX_MEMALIGN
1701extern int posix_memalign (void **memptr, size_t alignment, size_t size);
1702#endif
1703 1693
1704/* Assuming PTR was allocated via the hybrid malloc, return true if 1694/* Assuming PTR was allocated via the hybrid malloc, return true if
1705 PTR was allocated via gmalloc, not the system malloc. Also, return 1695 PTR was allocated via gmalloc, not the system malloc. Also, return