summaryrefslogtreecommitdiff
path: root/src/conf_post.h
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2021-05-20 11:26:00 +0300
committerEli Zaretskii <eliz@gnu.org>2021-05-20 11:26:00 +0300
commitb2eed2ae568b53ac910f4a3b8458eedf8d8c67ec (patch)
treebff25c6d02605018e916b904ef77454812ca0f64 /src/conf_post.h
parentd68f2b8681f8eeb6bbf1b4476a88f00b2962179e (diff)
downloademacs-b2eed2ae568b53ac910f4a3b8458eedf8d8c67ec.tar.gz
emacs-b2eed2ae568b53ac910f4a3b8458eedf8d8c67ec.tar.bz2
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/conf_post.h')
-rw-r--r--src/conf_post.h31
1 files changed, 30 insertions, 1 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;
# define ADDRESS_SANITIZER false
#endif
+#ifdef emacs
+/* We include stdlib.h here, because Gnulib's stdlib.h might redirect
+ 'free' to its replacement, and we want to avoid that in unexec
+ builds. Inclduing it here will render its inclusion after config.h
+ a no-op. */
+# if (defined DARWIN_OS && defined HAVE_UNEXEC) || defined HYBRID_MALLOC
+# include <stdlib.h>
+# endif
+#endif
+
#if defined DARWIN_OS && defined emacs && defined HAVE_UNEXEC
+# undef malloc
# define malloc unexec_malloc
+# undef realloc
# define realloc unexec_realloc
+# undef free
# define free unexec_free
+
+extern void *unexec_malloc (size_t);
+extern void *unexec_realloc (void *, size_t);
+extern void unexec_free (void *);
+
#endif
/* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
@@ -111,12 +129,23 @@ typedef bool bool_bf;
accomplish this. */
#ifdef HYBRID_MALLOC
#ifdef emacs
+#undef malloc
#define malloc hybrid_malloc
+#undef realloc
#define realloc hybrid_realloc
+#undef aligned_alloc
#define aligned_alloc hybrid_aligned_alloc
+#undef calloc
#define calloc hybrid_calloc
+#undef free
#define free hybrid_free
-#endif
+
+extern void *hybrid_malloc (size_t);
+extern void *hybrid_calloc (size_t, size_t);
+extern void hybrid_free (void *);
+extern void *hybrid_aligned_alloc (size_t, size_t);
+extern void *hybrid_realloc (void *, size_t);
+#endif /* emacs */
#endif /* HYBRID_MALLOC */
/* We have to go this route, rather than the old hpux9 approach of