]> git.eshelyaron.com Git - emacs.git/commitdiff
Clean up the fix for unexec build on GNU/Linux
authorEli Zaretskii <eliz@gnu.org>
Thu, 20 May 2021 08:26:00 +0000 (11:26 +0300)
committerEli Zaretskii <eliz@gnu.org>
Thu, 20 May 2021 08:26:00 +0000 (11:26 +0300)
* 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)

configure.ac
src/conf_post.h
src/gmalloc.c

index d35ac6dbd376beb86933a815f3362c09682abe34..d99e5395d35f6aeb288e38bc4afd9ba0f73e170c 100644 (file)
@@ -2309,9 +2309,6 @@ elif test "$hybrid_malloc" = yes; then
   GNU_MALLOC_reason=" (only before dumping)"
   GMALLOC_OBJ=gmalloc.o
   VMLIMIT_OBJ=
-  # FIXME: This is to prevent Gnulib from redirecting 'free' to its
-  # replacement, instead of 'hybrid_free' in gmalloc.c.
-  gl_cv_func_free_preserves_errno=yes
 else
   test "$doug_lea_malloc" != "yes" && GMALLOC_OBJ=gmalloc.o
   VMLIMIT_OBJ=vm-limit.o
index 176ab28b21ab2d3876a415ff60314dc8cf48091c..8558dc466ccb96deac75e65c4c5b4fe9c6e94e72 100644 (file)
@@ -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
index 66008ea69b2f868d3fa1b3f1e430721a73877513..dedd25fa22fa6e9e68336d8054c088fb997c1650 100644 (file)
@@ -1690,16 +1690,6 @@ valloc (size_t size)
 #undef free
 
 #ifdef HYBRID_MALLOC
-/* Declare system malloc and friends.  */
-extern void *malloc (size_t size);
-extern void *realloc (void *ptr, size_t size);
-extern void *calloc (size_t nmemb, size_t size);
-extern void free (void *ptr);
-#ifdef HAVE_ALIGNED_ALLOC
-extern void *aligned_alloc (size_t alignment, size_t size);
-#elif defined HAVE_POSIX_MEMALIGN
-extern int posix_memalign (void **memptr, size_t alignment, size_t size);
-#endif
 
 /* Assuming PTR was allocated via the hybrid malloc, return true if
    PTR was allocated via gmalloc, not the system malloc.  Also, return