APPROVE COMMIT
NOTE: This patch has been committed
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1511413729 0
# Thu Nov 23 05:08:49 2017 +0000
# Node ID 3b1ef8c61ffe707960e449c29f1b06b4e96499f3
# Parent c129b2eb4cf991ce0b541b0490b86f9fbe55f56e
Remove gmalloc.c entirely. Use mcheck.h if ERROR_CHECK_MALLOC.
ChangeLog addition:
2017-11-23 Aidan Kehoe <kehoea(a)parhasard.net>
* configure.ac (XE_COMPLEX_ARG):
Remove gmalloc.c, remove the configure line options
--with-dlmalloc, --with-system-malloc, --with-debug-malloc. Always
use the system malloc. Autodetect __after_morecore_hook, use it
for our memory-full warning if available, otherwise ignore it.
Use mcheck.h if ERROR_CHECK_MALLOC is defined, as we had planned
for years pending its maturity.
* configure.ac (have_libmcheck): Make this available.
* configure: Regenerate.
src/ChangeLog addition:
2017-11-23 Aidan Kehoe <kehoea(a)parhasard.net>
* gmalloc.c: Removed. Use the system malloc all the time instead.
* config.h.in:
Remove DOUG_LEA_MALLOC, USE_SYSTEM_MALLOC, USE_DEBUG_MALLOC from
this file.
Rename _NO_MALLOC_WARNING_ to HAVE_MALLOC_WARNING, invert its
sense.
* Makefile.in.in:
Take a different approach as to whether to include vm-limit.o or
free-hook.o.
* alloc.c:
* alloc.c (malloced_storage_size):
Now we always use the system malloc, update this to use the GNU
malloc accounting if we are on a glibc system.
* alloc.c (common_init_alloc_early):
Call mallopt() if we're on a glibc system.
* emacs.c:
* emacs.c (main_1):
* emacs.c (main):
* emacs.c (Fdump_emacs):
* emacs.c (Fkill_emacs):
Remove use of old glibc malloc hooks that are deprecated and
removed from more recent versions.
Call init_ralloc() early in every startup if we were built with
REL_ALLOC support.
Remove the use of malloc_set_state(), deprecated.
* free-hook.c:
Remove the debugging hooks for
* gc.h:
* ralloc.c:
* ralloc.c (init_ralloc):
Avoid using the deprecated glibc malloc hooks in this file.
* sysdep.c:
SYSTEM_MALLOC is effectively always defined, don't check it.
* text.h:
* text.h (STRIDE_ALIGN_BITS):
Rename ALIGN_BIGS, ALIGN_MASK, they conflict with ralloc.c.
* vm-limit.c:
Rename _NO_MALLOC_WARNING to HAVE_MALLOC_WARNING, reverse its
sense.
man/ChangeLog addition:
2017-11-23 Aidan Kehoe <kehoea(a)parhasard.net>
* internals/internals.texi (A Summary of the Various XEmacs Modules):
* internals/internals.texi (Low-Level Modules):
* internals/internals.texi (Modules for Allocation):
* internals/internals.texi (Low-level allocation):
Remove mention of malloc.c (long gone) and gmalloc.c (gone today).
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe ChangeLog
--- a/ChangeLog Thu Nov 23 03:49:37 2017 +0000
+++ b/ChangeLog Thu Nov 23 05:08:49 2017 +0000
@@ -1,3 +1,15 @@
+2017-11-23 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * configure.ac (XE_COMPLEX_ARG):
+ Remove gmalloc.c, remove the configure line options
+ --with-dlmalloc, --with-system-malloc, --with-debug-malloc. Always
+ use the system malloc. Autodetect __after_morecore_hook, use it
+ for our memory-full warning if available, otherwise ignore it.
+ Use mcheck.h if ERROR_CHECK_MALLOC is defined, as we had planned
+ for years pending its maturity.
+ * configure.ac (have_libmcheck): Make this available.
+ * configure: Regenerate.
+
2017-11-15 Aidan Kehoe <kehoea(a)parhasard.net>
* configure: Regenerate.
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe configure
--- a/configure Thu Nov 23 03:49:37 2017 +0000
+++ b/configure Thu Nov 23 05:08:49 2017 +0000
@@ -780,6 +780,7 @@
INSTALL_PROGRAM
RANLIB
AR
+libmcheck
lib_gcc
ld
start_files
@@ -824,6 +825,7 @@
docdir
oldincludedir
includedir
+runstatedir
localstatedir
sharedstatedir
sysconfdir
@@ -1012,12 +1014,6 @@
with_tls
enable_rel_alloc
with_rel_alloc
-enable_dlmalloc
-with_dlmalloc
-enable_system_malloc
-with_system_malloc
-enable_debug_malloc
-with_debug_malloc
enable_pdump
with_pdump
enable_dump_in_exec
@@ -1110,6 +1106,7 @@
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1362,6 +1359,15 @@
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
+ -runstatedir | --runstatedir | --runstatedi | --runstated \
+ | --runstate | --runstat | --runsta | --runst | --runs \
+ | --run | --ru | --r)
+ ac_prev=runstatedir ;;
+ -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+ | --run=* | --ru=* | --r=*)
+ runstatedir=$ac_optarg ;;
+
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1499,7 +1505,7 @@
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
- libdir localedir mandir
+ libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@@ -1652,6 +1658,7 @@
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -1959,9 +1966,6 @@
-------------------------
--with-rel-alloc Enable the relocating allocator.
- --with-dlmalloc Use Doug Lea's malloc implementation.
- --with-system-malloc Use the system malloc, (default).
- --with-debug-malloc Use a debugging malloc.
--with-pdump Enable portable LISP preloader.
--with-dump-in-exec Enable dumping into executable (enabled by default
for `pdump', not enabled by default in combination
@@ -2487,6 +2491,52 @@
} # ac_fn_c_try_link
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+ as_decl_name=`echo $2|sed 's/ *(.*//'`
+ as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/)
0& (/g'`
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is
declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+ (void) $as_decl_use;
+#else
+ (void) $as_decl_name;
+#endif
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ eval "$3=yes"
+else
+ eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
+
# ac_fn_c_check_func LINENO FUNC VAR
# ----------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
@@ -2554,52 +2604,6 @@
} # ac_fn_c_check_func
-# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
-# ---------------------------------------------
-# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
-# accordingly.
-ac_fn_c_check_decl ()
-{
- as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
- as_decl_name=`echo $2|sed 's/ *(.*//'`
- as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/)
0& (/g'`
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is
declared" >&5
-$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
-if eval \${$3+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-$4
-int
-main ()
-{
-#ifndef $as_decl_name
-#ifdef __cplusplus
- (void) $as_decl_use;
-#else
- (void) $as_decl_name;
-#endif
-#endif
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
- eval "$3=yes"
-else
- eval "$3=no"
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-eval ac_res=\$$3
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
- eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-
-} # ac_fn_c_check_decl
-
# ac_fn_c_check_type LINENO TYPE VAR INCLUDES
# -------------------------------------------
# Tests whether TYPE exists after having included INCLUDES, setting cache
@@ -4988,58 +4992,6 @@
else
with_rel_alloc='default'
fi;
-# If --with-dlmalloc or --without-dlmalloc were given then copy the value to the
-# equivalent enable_dlmalloc variable.
-if test "${with_dlmalloc+set}" = set; then
- enable_dlmalloc="$with_dlmalloc"
-fi;
-# If -enable-dlmalloc or --disable-dlmalloc were given then copy the value to the
-# equivalent with_dlmalloc variable.
-if test "${enable_dlmalloc+set}" = set; then
- with_dlmalloc="$enable_dlmalloc"
-fi;
-# Check whether --with-dlmalloc or --without-dlmalloc was given.
-if test "${with_dlmalloc+set}" = set; then
- enableval="$with_dlmalloc"
- withval="$with_dlmalloc"
-
-else
- with_dlmalloc='default'
-fi;
-# If --with-system-malloc or --without-system-malloc were given then copy the value to
the
-# equivalent enable_system-malloc variable.
-if test "${with_system_malloc+set}" = set; then
- enable_system_malloc="$with_system_malloc"
-fi;
-# If -enable-system-malloc or --disable-system-malloc were given then copy the value to
the
-# equivalent with_system-malloc variable.
-if test "${enable_system_malloc+set}" = set; then
- with_system_malloc="$enable_system_malloc"
-fi;
-# Check whether --with-system-malloc or --without-system-malloc was given.
-if test "${with_system_malloc+set}" = set; then
- enableval="$with_system_malloc"
- withval="$with_system_malloc"
-
-else
- with_system_malloc='default'
-fi;
-# If --with-debug-malloc or --without-debug-malloc were given then copy the value to the
-# equivalent enable_debug-malloc variable.
-if test "${with_debug_malloc+set}" = set; then
- enable_debug_malloc="$with_debug_malloc"
-fi;
-# If -enable-debug-malloc or --disable-debug-malloc were given then copy the value to
the
-# equivalent with_debug-malloc variable.
-if test "${enable_debug_malloc+set}" = set; then
- with_debug_malloc="$enable_debug_malloc"
-fi;
-# Check whether --with-debug-malloc or --without-debug-malloc was given.
-if test "${with_debug_malloc+set}" = set; then
- enableval="$with_debug_malloc"
- withval="$with_debug_malloc"
-
-fi;
# If --with-pdump or --without-pdump were given then copy the value to the
# equivalent enable_pdump variable.
if test "${with_pdump+set}" = set; then
@@ -5500,10 +5452,6 @@
fi;
-if test "$with_purify" = "yes" -o "$with_quantify" =
"yes"; then
- test "$with_system_malloc" = "default" &&
with_system_malloc=yes
-fi
-
if test "$with_cde $with_tooltalk" = "yes no"; then
(echo "$progname: Usage error:"
echo " " "--with-cde requires --with-tooltalk"
@@ -9446,12 +9394,6 @@
configure___ ordinary_link=no
#endif
-#ifdef SYSTEM_MALLOC
-configure___ system_malloc=yes
-#else
-configure___ system_malloc=no
-#endif
-
#ifdef TERMINFO
configure___ have_terminfo=yes
#else
@@ -10266,19 +10208,9 @@
-if test "$with_dlmalloc" = "yes"; then
- ac_fn_c_check_func "$LINENO" "malloc_set_state"
"ac_cv_func_malloc_set_state"
-if test "x$ac_cv_func_malloc_set_state" = xyes; then :
- doug_lea_malloc=yes
-else
- doug_lea_malloc=no
-fi
-
- if test "$doug_lea_malloc" = "yes"; then
- system_malloc=no
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether __after_morecore_hook
exists" >&5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether __after_morecore_hook
exists" >&5
$as_echo_n "checking whether __after_morecore_hook exists... " >&6; }
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
extern void (* __after_morecore_hook)();
int
@@ -10292,48 +10224,83 @@
if ac_fn_c_try_link "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
- after_morecore_hook_exists=yes
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
- after_morecore_hook_exists=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
- conftest$ac_exeext conftest.$ac_ext
- GNU_MALLOC=yes
- $as_echo "#define DOUG_LEA_MALLOC 1" >>confdefs.h
-
- if test "$after_morecore_hook_exists" = "no" ; then
- GNU_MALLOC_reason="
- - Using Doug Lea's new malloc from the Linux C Library."
- $as_echo "#define _NO_MALLOC_WARNING_ 1" >>confdefs.h
-
- else
- GNU_MALLOC_reason="
- - Using Doug Lea's new malloc from the GNU C Library."
- fi
- else
- system_malloc=yes
- fi
-elif test "$with_debug_malloc" = "yes" ; then
- debug_malloc=yes
- system_malloc=yes
- GNU_MALLOC=no
- GNU_MALLOC_reason="
- - User chose to use Debugging Malloc."
-elif test "$with_system_malloc" = "no" ; then
- GNU_MALLOC=yes
- GNU_MALLOC_reason="
- - System malloc explicitly overridden."
- system_malloc=no
-else
- GNU_MALLOC=no
- GNU_MALLOC_reason="
- - Defaulting to system malloc."
- system_malloc=yes
-fi
-
-
+ after_morecore_hook_exists=yes
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ after_morecore_hook_exists=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+if test "$after_morecore_hook_exists" = "yes" ; then
+ $as_echo "#define HAVE_MALLOC_WARNING 1" >>confdefs.h
+
+fi
+
+have_libmcheck=no
+if test "$with_error_checking_malloc" = "yes" -a
"$have_glibc" = "yes" ; then
+ for ac_header in mcheck.h
+do :
+ ac_fn_c_check_header_mongrel "$LINENO" "mcheck.h"
"ac_cv_header_mcheck_h" "$ac_includes_default"
+if test "x$ac_cv_header_mcheck_h" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_MCHECK_H 1
+_ACEOF
+
+fi
+
+done
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for mcheck in -lmcheck"
>&5
+$as_echo_n "checking for mcheck in -lmcheck... " >&6; }
+if ${ac_cv_lib_mcheck_mcheck+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lmcheck $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char mcheck ();
+int
+main ()
+{
+return mcheck ();
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_lib_mcheck_mcheck=yes
+else
+ ac_cv_lib_mcheck_mcheck=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mcheck_mcheck"
>&5
+$as_echo "$ac_cv_lib_mcheck_mcheck" >&6; }
+if test "x$ac_cv_lib_mcheck_mcheck" = xyes; then :
+ have_libmcheck=yes
+else
+ have_libmcheck=no
+fi
+
+fi
+
+if test "$have_libmcheck" = "yes"; then
+ $as_echo "#define HAVE_LIBMCHECK 1" >>confdefs.h
+
+ libmcheck=-lmcheck
+
+fi
# Extract the first word of "ar", so it can be a program name with args.
@@ -11814,7 +11781,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31)
<< 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -11860,7 +11827,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31)
<< 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -11884,7 +11851,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31)
<< 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -11929,7 +11896,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31)
<< 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -11953,7 +11920,7 @@
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31)
<< 31))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1];
@@ -19199,12 +19166,12 @@
case "$opsys" in cygwin*)
test "$with_rel_alloc" = "default" && with_rel_alloc=no ;;
esac
-test "$GNU_MALLOC" != "yes" -a "$have_mmap" !=
"yes" && with_rel_alloc=no
+
+test "$have_mmap" != "yes" && with_rel_alloc=no
if test "$with_rel_alloc $have_mmap" = "default yes"; then
- if test "$doug_lea_malloc" = "yes"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for M_MMAP_THRESHOLD"
>&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for M_MMAP_THRESHOLD"
>&5
$as_echo_n "checking for M_MMAP_THRESHOLD... " >&6; }
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <malloc.h>
int
@@ -19228,9 +19195,6 @@
$as_echo "no" >&6; };
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
- else
- with_rel_alloc=yes
- fi
fi
test "$with_rel_alloc" = "yes" && $as_echo "#define
REL_ALLOC 1" >>confdefs.h
@@ -22098,13 +22062,6 @@
-if test "$debug_malloc" = "yes"; then $as_echo "#define
USE_DEBUG_MALLOC 1" >>confdefs.h
-
- $as_echo "#define USE_SYSTEM_MALLOC 1"
>>confdefs.h
-
-elif test "$system_malloc" = "yes"; then $as_echo "#define
USE_SYSTEM_MALLOC 1" >>confdefs.h
-
-fi
test "$GCC" = "yes" && $as_echo
"#define USE_GCC 1" >>confdefs.h
test "$XEMACS_CC_GPP" = "yes" && $as_echo
"#define USE_GPLUSPLUS 1" >>confdefs.h
@@ -22211,7 +22168,6 @@
fi
echo " libc version: $libc_version"
echo " Relocating allocator for buffers: $with_rel_alloc"
-echo " Using gmalloc.c from XEmacs: ${GNU_MALLOC}${GNU_MALLOC_reason}"
case "$ld_switch_site" in
*nocombreloc*) echo " Linking with \`-z nocombreloc'.
- Consider configuring with --with-pdump." ;;
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe configure.ac
--- a/configure.ac Thu Nov 23 03:49:37 2017 +0000
+++ b/configure.ac Thu Nov 23 05:08:49 2017 +0000
@@ -969,15 +969,6 @@
XE_MERGED_ARG([rel-alloc],
AS_HELP_STRING([--with-rel-alloc],[Enable the relocating allocator.]),
[], [with_rel_alloc='default'])
-XE_MERGED_ARG([dlmalloc],
- AS_HELP_STRING([--with-dlmalloc],[Use Doug Lea's malloc implementation.]),
- [], [with_dlmalloc='default'])
-XE_MERGED_ARG([system-malloc],
- AS_HELP_STRING([--with-system-malloc],[Use the system malloc, (default).]),
- [], [with_system_malloc='default'])
-XE_MERGED_ARG([debug-malloc],
- AS_HELP_STRING([--with-debug-malloc],[Use a debugging malloc.]),
- [], [])
XE_MERGED_ARG([pdump],
AS_HELP_STRING([--with-pdump],[Enable portable LISP preloader.]),
[], [])
@@ -1098,11 +1089,6 @@
dnl -------------------------------------------------------------------------
dnl Final command line argument checks.
-dnl --with-quantify or --with-purify imply --with-system-malloc
-if test "$with_purify" = "yes" -o "$with_quantify" =
"yes"; then
- test "$with_system_malloc" = "default" &&
with_system_malloc=yes
-fi
-
dnl CDE requires tooltalk
XE_CHECK_FEATURE_DEPENDENCY(cde, tooltalk)
@@ -1818,7 +1804,6 @@
configure___ start_files=START_FILES
CPP_boolean_to_sh(ORDINARY_LINK, ordinary_link)
-CPP_boolean_to_sh(SYSTEM_MALLOC, system_malloc)
CPP_boolean_to_sh(TERMINFO, have_terminfo)
dnl The MAIL_USE_xxx variables come from the s&m headers
CPP_boolean_to_sh(MAIL_USE_FLOCK, mail_use_flock)
@@ -2533,69 +2518,34 @@
dnl Do some misc autoconf-special tests
dnl -----------------------------------
-dnl Default to the system malloc. The right thing here is to remove
-dnl src/gmalloc.c entirely, and just autoconfiscate and use malloc_set_state
-dnl and __after_morecore_hook and if they are available, otherwise no. But
-dnl this is a reasonable first step.
-
-if test "$with_dlmalloc" = "yes"; then
- AC_CHECK_FUNC(malloc_set_state, doug_lea_malloc=yes,doug_lea_malloc=no)
- if test "$doug_lea_malloc" = "yes"; then
- system_malloc=no
- AC_MSG_CHECKING(whether __after_morecore_hook exists)
- AC_LINK_IFELSE([AC_LANG_PROGRAM([extern void (* __after_morecore_hook)();],
- [__after_morecore_hook = 0])],
- [AC_MSG_RESULT(yes)
- after_morecore_hook_exists=yes],
- [AC_MSG_RESULT(no)
- after_morecore_hook_exists=no])
- GNU_MALLOC=yes
- AC_DEFINE(DOUG_LEA_MALLOC)
- if test "$after_morecore_hook_exists" = "no" ; then
- GNU_MALLOC_reason="
- - Using Doug Lea's new malloc from the Linux C Library."
- AC_DEFINE(_NO_MALLOC_WARNING_)
- else
- GNU_MALLOC_reason="
- - Using Doug Lea's new malloc from the GNU C Library."
- fi
- else
- system_malloc=yes
- fi
-elif test "$with_debug_malloc" = "yes" ; then
- debug_malloc=yes
- system_malloc=yes
- GNU_MALLOC=no
- GNU_MALLOC_reason="
- - User chose to use Debugging Malloc."
-elif test "$with_system_malloc" = "no" ; then
- GNU_MALLOC=yes
- GNU_MALLOC_reason="
- - System malloc explicitly overridden."
- system_malloc=no
-else
- GNU_MALLOC=no
- GNU_MALLOC_reason="
- - Defaulting to system malloc."
- system_malloc=yes
-fi
-
-dnl #### mcheck is broken in all versions of Linux libc and glibc.
-dnl Try this again when 2.1 hits the streets.
-dnl Avoid using free-hook.c if support exists for malloc debugging in libc
-dnl have_libmcheck=no
-dnl if test "$with_error_checking_malloc" = "yes" -a \
-dnl "$have_glibc" = "yes" -a \
-dnl "$doug_lea_malloc" = "yes"; then
-dnl AC_CHECK_HEADERS(mcheck.h)
-dnl AC_CHECK_LIB(mcheck, mcheck, have_libmcheck=yes, have_libmcheck=no)
-dnl fi
-
-dnl if test "$have_libmcheck" = "yes"; then
-dnl AC_DEFINE(HAVE_LIBMCHECK)
-dnl libmcheck=-lmcheck
-dnl AC_SUBST(libmcheck)
-dnl fi
+dnl We used to include a copy of gmalloc.c, and would usually use that. Now
+dnl that most Linuxes have gmalloc, and now that that's more maintained than
+dnl is our copy, use the system malloc() instead, even on non-Linux
+dnl platforms.
+
+AC_MSG_CHECKING(whether __after_morecore_hook exists)
+AC_LINK_IFELSE([AC_LANG_PROGRAM([extern void (* __after_morecore_hook)();],
+[__after_morecore_hook = 0])],
+[AC_MSG_RESULT(yes)
+ after_morecore_hook_exists=yes],
+[AC_MSG_RESULT(no)
+ after_morecore_hook_exists=no])
+if test "$after_morecore_hook_exists" = "yes" ; then
+ AC_DEFINE(HAVE_MALLOC_WARNING)
+fi
+
+dnl Use the support for for malloc debugging in libc if available.
+have_libmcheck=no
+if test "$with_error_checking_malloc" = "yes" -a
"$have_glibc" = "yes" ; then
+ AC_CHECK_HEADERS(mcheck.h)
+ AC_CHECK_LIB(mcheck, mcheck, have_libmcheck=yes, have_libmcheck=no)
+fi
+
+if test "$have_libmcheck" = "yes"; then
+ AC_DEFINE(HAVE_LIBMCHECK)
+ libmcheck=-lmcheck
+ AC_SUBST(libmcheck)
+fi
dnl Some other nice autoconf tests. If you add a test here which
dnl should make an entry in src/config.h, do not forget to add an
@@ -4896,23 +4846,20 @@
case "$opsys" in cygwin*)
test "$with_rel_alloc" = "default" && with_rel_alloc=no ;;
esac
-dnl rel_alloc requires either GNU malloc or system malloc with mmap
-dnl We only turn rel_alloc on by default if mmap is available.
-test "$GNU_MALLOC" != "yes" -a "$have_mmap" !=
"yes" && with_rel_alloc=no
+
+dnl rel_alloc requires system malloc with mmap. We only turn rel_alloc on by
+dnl default if mmap is available.
+test "$have_mmap" != "yes" && with_rel_alloc=no
if test "$with_rel_alloc $have_mmap" = "default yes"; then
- if test "$doug_lea_malloc" = "yes"; then
- dnl Check if malloc() calls mmap(), making rel_alloc pointless.
- AC_MSG_CHECKING(for M_MMAP_THRESHOLD)
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <malloc.h>],[
+ dnl Check if malloc() calls mmap(), making rel_alloc pointless.
+ AC_MSG_CHECKING(for M_MMAP_THRESHOLD)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <malloc.h>],[
#ifndef M_MMAP_THRESHOLD
#error No M_MMAP_THRESHOLD :-(
!@+$%^&*_)(_ - unlikely to compile...
#endif
])], [with_rel_alloc=no; AC_MSG_RESULT(yes);],
- [with_rel_alloc=yes; AC_MSG_RESULT(no);])
- else
- with_rel_alloc=yes
- fi
+ [with_rel_alloc=yes; AC_MSG_RESULT(no);])
fi
test "$with_rel_alloc" = "yes" && AC_DEFINE(REL_ALLOC)
@@ -5851,10 +5798,6 @@
dnl so that the user gets immediate feedback on the results of the
dnl autodetection.
-if test "$debug_malloc" = "yes"; then AC_DEFINE(USE_DEBUG_MALLOC)
- AC_DEFINE(USE_SYSTEM_MALLOC)
-elif test "$system_malloc" = "yes"; then
AC_DEFINE(USE_SYSTEM_MALLOC)
-fi
test "$GCC" = "yes" && AC_DEFINE(USE_GCC)
test "$XEMACS_CC_GPP" = "yes" &&
AC_DEFINE(USE_GPLUSPLUS)
test "$with_external_widget" = "yes" &&
AC_DEFINE(EXTERNAL_WIDGET)
@@ -5952,7 +5895,6 @@
fi
echo " libc version: $libc_version"
echo " Relocating allocator for buffers: $with_rel_alloc"
-echo " Using gmalloc.c from XEmacs: ${GNU_MALLOC}${GNU_MALLOC_reason}"
case "$ld_switch_site" in
*nocombreloc*) echo " Linking with \`-z nocombreloc'.
- Consider configuring with --with-pdump." ;;
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe man/ChangeLog
--- a/man/ChangeLog Thu Nov 23 03:49:37 2017 +0000
+++ b/man/ChangeLog Thu Nov 23 05:08:49 2017 +0000
@@ -1,3 +1,11 @@
+2017-11-23 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * internals/internals.texi (A Summary of the Various XEmacs Modules):
+ * internals/internals.texi (Low-Level Modules):
+ * internals/internals.texi (Modules for Allocation):
+ * internals/internals.texi (Low-level allocation):
+ Remove mention of malloc.c (long gone) and gmalloc.c (gone today).
+
2017-11-14 Stephen J. Turnbull <stephen(a)xemacs.org>
* lispref/faces.texi (Face Properties): Add items to itemize.
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe man/internals/internals.texi
--- a/man/internals/internals.texi Thu Nov 23 03:49:37 2017 +0000
+++ b/man/internals/internals.texi Thu Nov 23 05:08:49 2017 +0000
@@ -3057,7 +3057,6 @@
@item @file{glyphs-x.h} @tab @ref{Modules for other Display-Related Lisp Objects}.
@item @file{glyphs.c} @tab @ref{Modules for other Display-Related Lisp Objects}.
@item @file{glyphs.h} @tab @ref{Modules for other Display-Related Lisp Objects}.
-@item @file{gmalloc.c} @tab @ref{Low-Level Modules}.
@item @file{gpmevent.c} @tab @ref{Editor-Level Control Flow Modules}.
@item @file{gpmevent.h} @tab @ref{Editor-Level Control Flow Modules}.
@item @file{gtk-glue.c} @tab
@@ -3445,7 +3444,7 @@
very last file linked, respectively. (Actually, this is not really true.
@file{lastfile.c} should be after all Emacs modules whose initialized
data should be made constant, and before all other Emacs files and all
-libraries. In particular, the allocation modules @file{gmalloc.c},
+libraries. In particular, the allocation modules
@file{alloca.c}, etc. are normally placed past @file{lastfile.c}, and
all of the files that implement Xt widget classes @emph{must} be placed
after @file{lastfile.c} because they contain various structures that
@@ -7980,8 +7979,6 @@
@file{alloca.c}
@file{free-hook.c}
@file{getpagesize.h}
-(a)file{gmalloc.c}
-(a)file{malloc.c}
@file{mem-limits.h}
@file{ralloc.c}
@file{vm-limit.c}
@@ -7991,16 +7988,6 @@
the stack allocation function @code{alloca()} on machines that lack
this. (XEmacs makes extensive use of @code{alloca()} in its code.)
-(a)file{gmalloc.c} and @file{malloc.c} are two implementations of the standard C
-functions @code{malloc()}, @code{realloc()} and @code{free()}. They are
-often used in place of the standard system-provided @code{malloc()}
-because they usually provide a much faster implementation, at the
-expense of additional memory use. @file{gmalloc.c} is a newer implementation
-that is much more memory-efficient for large allocations than @file{malloc.c},
-and should always be preferred if it works. (At one point, @file{gmalloc.c}
-didn't work on some systems where @file{malloc.c} worked; but this should be
-fixed now.)
-
@cindex relocating allocator
@file{ralloc.c} is the @dfn{relocating allocator}. It provides
functions similar to @code{malloc()}, @code{realloc()} and @code{free()}
@@ -9644,37 +9631,11 @@
difficult in the general circumstance, perhaps requiring extra
unwind-protects and such.)
- Note that XEmacs provides two separate replacements for the standard
-@code{malloc()} library function. These are called @dfn{old GNU malloc}
-((a)file{malloc.c}) and @dfn{new GNU malloc} (@file{gmalloc.c}),
-respectively. New GNU malloc is better in pretty much every way than
-old GNU malloc, and should be used if possible. (It used to be that on
-some systems, the old one worked but the new one didn't. I think this
-was due specifically to a bug in SunOS, which the new one now works
-around; so I don't think the old one ever has to be used any more.) The
-primary difference between both of these mallocs and the standard system
-malloc is that they are much faster, at the expense of increased space.
-The basic idea is that memory is allocated in fixed chunks of powers of
-two. This allows for basically constant malloc time, since the various
-chunks can just be kept on a number of free lists. (The standard system
-malloc typically allocates arbitrary-sized chunks and has to spend some
-time, sometimes a significant amount of time, walking the heap looking
-for a free block to use and cleaning things up.) The new GNU malloc
-improves on things by allocating large objects in chunks of 4096 bytes
-rather than in ever larger powers of two, which results in ever larger
-wastage. There is a slight speed loss here, but it's of doubtful
-significance.
-
- NOTE: Apparently there is a third-generation GNU malloc that is
-significantly better than the new GNU malloc, and should probably
-be included in XEmacs.
-
There is also the relocating allocator, @file{ralloc.c}. This actually
moves blocks of memory around so that the @code{sbrk()} pointer shrunk
and virtual memory released back to the system. On some systems,
this is a big win. On all systems, it causes a noticeable (and
sometimes huge) speed penalty, so I turn it off by default.
-(a)file{ralloc.c} only works with the new GNU malloc in @file{gmalloc.c}.
There are also two versions of @file{ralloc.c}, one that uses @code{mmap()}
rather than block copies to move data around. This purports to
be faster, although that depends on the amount of data that would
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/ChangeLog
--- a/src/ChangeLog Thu Nov 23 03:49:37 2017 +0000
+++ b/src/ChangeLog Thu Nov 23 05:08:49 2017 +0000
@@ -1,3 +1,46 @@
+2017-11-23 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * gmalloc.c: Removed. Use the system malloc all the time instead.
+ * config.h.in:
+ Remove DOUG_LEA_MALLOC, USE_SYSTEM_MALLOC, USE_DEBUG_MALLOC from
+ this file.
+ Rename _NO_MALLOC_WARNING_ to HAVE_MALLOC_WARNING, invert its
+ sense.
+ * Makefile.in.in:
+ Take a different approach as to whether to include vm-limit.o or
+ free-hook.o.
+ * alloc.c:
+ * alloc.c (malloced_storage_size):
+ Now we always use the system malloc, update this to use the GNU
+ malloc accounting if we are on a glibc system.
+ * alloc.c (common_init_alloc_early):
+ Call mallopt() if we're on a glibc system.
+
+ * emacs.c:
+ * emacs.c (main_1):
+ * emacs.c (main):
+ * emacs.c (Fdump_emacs):
+ * emacs.c (Fkill_emacs):
+ Remove use of old glibc malloc hooks that are deprecated and
+ removed from more recent versions.
+ Call init_ralloc() early in every startup if we were built with
+ REL_ALLOC support.
+ Remove the use of malloc_set_state(), deprecated.
+ * free-hook.c:
+ Remove the debugging hooks for
+ * gc.h:
+ * ralloc.c:
+ * ralloc.c (init_ralloc):
+ Avoid using the deprecated glibc malloc hooks in this file.
+ * sysdep.c:
+ SYSTEM_MALLOC is effectively always defined, don't check it.
+ * text.h:
+ * text.h (STRIDE_ALIGN_BITS):
+ Rename ALIGN_BIGS, ALIGN_MASK, they conflict with ralloc.c.
+ * vm-limit.c:
+ Rename _NO_MALLOC_WARNING to HAVE_MALLOC_WARNING, reverse its
+ sense.
+
2017-11-23 Aidan Kehoe <kehoea(a)parhasard.net>
* alloca.c (xemacs_c_alloca):
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/Makefile.in.in
--- a/src/Makefile.in.in Thu Nov 23 03:49:37 2017 +0000
+++ b/src/Makefile.in.in Thu Nov 23 05:08:49 2017 +0000
@@ -307,29 +307,14 @@
#endif
malloclib = $(libmcheck)
-#ifndef SYSTEM_MALLOC
-# ifdef ERROR_CHECK_MALLOC
-# ifdef DOUG_LEA_MALLOC
-mallocobjs = free-hook.o vm-limit.o
-# else
-mallocobjs = gmalloc.o free-hook.o vm-limit.o
-# endif
-mallocdocsrc = free-hook.c
-# else /* GNU malloc, sans error checking */
-# ifdef DOUG_LEA_MALLOC
-mallocobjs = vm-limit.o
-# else
-mallocobjs = gmalloc.o vm-limit.o
-# endif
mallocdocsrc =
-# endif /* ERROR_CHECK_MALLOC */
-#else /* SYSTEM_MALLOC */
mallocobjs =
-mallocdocsrc =
-# ifdef USE_DEBUG_MALLOC
-malloclib = -ldmalloc
-# endif /* USE_DEBUG_MALLOC */
-#endif /* SYSTEM_MALLOC */
+#ifdef HAVE_MALLOC_WARNING
+mallocobjs += vm-limit.o
+#endif /* HAVE_MALLOC_WARNING */
+#ifdef DEBUG_GCPRO
+mallocobjs += free-hook.o
+#endif
#ifdef HAVE_X_WINDOWS
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/alloc.c
--- a/src/alloc.c Thu Nov 23 03:49:37 2017 +0000
+++ b/src/alloc.c Thu Nov 23 05:08:49 2017 +0000
@@ -66,7 +66,7 @@
#endif /* NEW_GC */
#include "console-stream.h"
-#ifdef DOUG_LEA_MALLOC
+#ifdef _GNU_SOURCE
#include <malloc.h>
#endif
#ifdef USE_VALGRIND
@@ -81,14 +81,6 @@
#endif
#endif
-/* Define this to use malloc/free with no freelist for all datatypes,
- the hope being that some debugging tools may help detect
- freed memory references */
-#ifdef USE_DEBUG_MALLOC /* Taking the above comment at face value -slb */
-#include <dmalloc.h>
-#define ALLOC_NO_POOLS
-#endif
-
#ifdef DEBUG_XEMACS
static Fixnum debug_allocation;
static Fixnum debug_allocation_backtrace_length;
@@ -228,7 +220,7 @@
}
}
-#if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC)
+#if !defined(HAVE_MMAP) || defined(_GNU_SOURCE)
/* If we released our reserve (due to running out of memory),
and we have a fair amount free once again,
try to set aside another reserve in case we run out once more.
@@ -241,7 +233,7 @@
if (breathing_space == 0)
breathing_space = (char *) malloc (4096 - MALLOC_OVERHEAD);
}
-#endif /* !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC) */
+#endif /* !defined(HAVE_MMAP) || defined(_GNU_SOURCE) */
#endif /* not NEW_GC */
@@ -4059,7 +4051,11 @@
{
Bytecount orig_claimed_size = claimed_size;
-#ifndef SYSTEM_MALLOC
+#ifdef _GNU_SOURCE
+ /* The following actually reflects the old gmalloc.c that we included with
+ XEmacs. The malloc implementation included in glibc has likely diverged
+ from this, but this answer is still going to be better than the
+ default. */
if (claimed_size < (Bytecount) (2 * sizeof (void *)))
claimed_size = 2 * sizeof (void *);
# ifdef SUNOS_LOCALTIME_BUG
@@ -5964,7 +5960,7 @@
all_lcrecords = 0;
#endif /* not NEW_GC */
ignore_malloc_warnings = 1;
-#ifdef DOUG_LEA_MALLOC
+#ifdef _GNU_SOURCE
mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */
#if 0 /* Moved to emacs.c */
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/config.h.in
--- a/src/config.h.in Thu Nov 23 03:49:37 2017 +0000
+++ b/src/config.h.in Thu Nov 23 05:08:49 2017 +0000
@@ -151,20 +151,12 @@
/* Undefine on systems which don't have processes */
#undef HAVE_UNIX_PROCESSES
-/* Define if you are using the GNU C Library. -- experimental. */
-#undef DOUG_LEA_MALLOC
-
/* Define if you are using libmcheck.a from the GNU C Library. */
#undef HAVE_LIBMCHECK
-/* Define if you are using dlmalloc from the Linux C library. */
-#undef _NO_MALLOC_WARNING_
-
-/* Use the system malloc? */
-#undef USE_SYSTEM_MALLOC
-
-/* Use a debugging malloc? -- experimental */
-#undef USE_DEBUG_MALLOC
+/* Define if your malloc has an __after_morecore_hook(), as is
+ usual on Linux. */
+#undef HAVE_MALLOC_WARNING
/* Use the relocating allocator for buffer space? */
#undef REL_ALLOC
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/emacs.c
--- a/src/emacs.c Thu Nov 23 03:49:37 2017 +0000
+++ b/src/emacs.c Thu Nov 23 05:08:49 2017 +0000
@@ -468,12 +468,6 @@
void report_sheap_usage (int die_if_pure_storage_exceeded);
#endif
-#if !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
-extern void *(*__malloc_hook)(size_t);
-extern void *(*__realloc_hook)(void *, size_t);
-extern void (*__free_hook)(void *);
-#endif /* not SYSTEM_MALLOC && not DOUG_LEA_MALLOC */
-
/* Command line args from shell, as list of strings */
Lisp_Object Vcommand_line_args;
@@ -482,16 +476,9 @@
on subsequent starts. */
int initialized;
-#ifdef DOUG_LEA_MALLOC
+#ifdef _GNU_SOURCE
# include <malloc.h>
-/* Preserves a pointer to the memory allocated that copies that
- static data inside glibc's malloc. */
-static void *malloc_state_ptr;
-#endif /* DOUG_LEA_MALLOC */
-
-# ifdef REL_ALLOC
-void r_alloc_reinit (void);
-# endif
+#endif /* _GNU_SOURCE */
/* Variable whose value is symbol giving operating system type. */
Lisp_Object Vsystem_type;
@@ -895,17 +882,6 @@
int skip_args = 0;
Lisp_Object load_me;
-#if (!defined (SYSTEM_MALLOC) && !defined (HAVE_LIBMCHECK) \
- && !defined (DOUG_LEA_MALLOC))
- /* Make sure that any libraries we link against haven't installed a
- hook for a gmalloc of a potentially incompatible version. */
- /* If we're using libmcheck, the hooks have already been initialized, */
- /* don't touch them. -slb */
- __malloc_hook = NULL;
- __realloc_hook = NULL;
- __free_hook = NULL;
-#endif /* not SYSTEM_MALLOC or HAVE_LIBMCHECK or DOUG_LEA_MALLOC */
-
noninteractive = 0;
display_use = NULL;
inhibit_non_essential_conversion_operations = 1;
@@ -987,12 +963,8 @@
clearerr (stdin);
-#if defined (HAVE_MMAP) && defined (REL_ALLOC)
- /* ralloc can only be used if using the GNU memory allocator. */
+#if defined (REL_ALLOC)
init_ralloc ();
-#elif defined (REL_ALLOC) && !defined (DOUG_LEA_MALLOC)
- if (initialized)
- init_ralloc ();
#endif
#ifdef HAVE_SOCKS
@@ -1000,11 +972,11 @@
SOCKSinit (argv[0]);
#endif /* HAVE_SOCKS */
-#ifndef SYSTEM_MALLOC
+#ifdef HAVE_MALLOC_WARNING
if (!initialized)
/* Arrange to get warning messages as memory fills up. */
memory_warnings (0, malloc_warning);
-#endif /* not SYSTEM_MALLOC */
+#endif /* HAVE_MALLOC_WARNING */
#ifdef SET_EMACS_PRIORITY
if (emacs_priority != 0)
@@ -1591,7 +1563,7 @@
syms_of_process_nt ();
#endif
syms_of_profile ();
-#if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined
(DOUG_LEA_MALLOC)
+#ifdef REL_ALLOC
syms_of_ralloc ();
#endif /* HAVE_MMAP && REL_ALLOC */
syms_of_rangetab ();
@@ -2205,9 +2177,9 @@
#endif
vars_of_profile ();
-#if defined (HAVE_MMAP) && defined (REL_ALLOC) && !defined
(DOUG_LEA_MALLOC)
+#ifdef REL_ALLOC
vars_of_ralloc ();
-#endif /* HAVE_MMAP && REL_ALLOC */
+#endif
vars_of_realpath ();
vars_of_redisplay ();
vars_of_regex ();
@@ -3217,7 +3189,7 @@
if (!initialized)
{
-#ifdef DOUG_LEA_MALLOC
+#ifdef _GNU_SOURCE
mallopt (M_MMAP_MAX, 0);
#endif
run_temacs_argc = 0;
@@ -3257,30 +3229,17 @@
run_time_remap (argv[0]);
#endif
-#ifdef DOUG_LEA_MALLOC
- if (initialized && (malloc_state_ptr != NULL))
+#ifdef _GNU_SOURCE
+ if (initialized)
{
- int rc = malloc_set_state (malloc_state_ptr);
- if (rc != 0)
- {
- stderr_out ("malloc_set_state failed, rc = %d\n", rc);
- ABORT ();
- }
-#if 0
- free (malloc_state_ptr);
-#endif
/* mmap works in glibc-2.1, glibc-2.0 (Non-Mule only) and Linux libc5 */
#if (defined (__GLIBC__) && __GLIBC_MINOR__ >= 1) || \
- defined (_NO_MALLOC_WARNING_) || \
- (defined (__GLIBC__) && __GLIBC_MINOR__ < 1 && !defined (MULE)) ||
\
- defined (DEBUG_DOUG_LEA_MALLOC)
+ defined (HAVE_MALLOC_WARNING) || \
+ (defined (__GLIBC__) && __GLIBC_MINOR__ < 1 && !defined (MULE))
mallopt (M_MMAP_MAX, 64);
#endif
-#ifdef REL_ALLOC
- r_alloc_reinit ();
-#endif
}
-#endif /* DOUG_LEA_MALLOC */
+#endif /* _GNU_SOURCE */
run_temacs_argc = -2;
@@ -3301,7 +3260,7 @@
/* dumping XEmacs (to a new EXE file) */
/************************************************************************/
-#if !defined (PDUMP) || !defined (SYSTEM_MALLOC)
+#if !defined (PDUMP) || defined (HAVE_MALLOC_WARNING)
extern Rawbyte my_edata[];
#endif
@@ -3361,7 +3320,7 @@
/* Tell malloc where start of impure now is */
/* Also arrange for warnings when nearly out of space. */
-#ifndef SYSTEM_MALLOC
+#ifdef HAVE_MALLOC_WARNING
memory_warnings (my_edata, malloc_warning);
#endif
@@ -3389,9 +3348,6 @@
else
symfile_ext = 0;
-# ifdef DOUG_LEA_MALLOC
- malloc_state_ptr = malloc_get_state ();
-# endif
/* here we break our rule that the filename conversion should
be performed at the actual time that the system call is made.
It's a whole lot easier to do the conversion here than to
@@ -3399,9 +3355,6 @@
conversion is applied everywhere. Don't worry about memory
leakage because this call only happens once. */
unexec (filename_ext, symfile_ext, (uintptr_t) my_edata, 0, 0);
-# ifdef DOUG_LEA_MALLOC
- free (malloc_state_ptr);
-# endif
}
#endif /* not PDUMP, not WIN32_NATIVE */
@@ -3741,25 +3694,6 @@
#endif /* TOOLTALK */
}
-/* Dumping apparently isn't supported by versions of GCC >= 2.8. */
-/* The following needs conditionalization on whether either XEmacs or */
-/* various system shared libraries have been built and linked with */
-/* GCC >= 2.8. -slb */
-#ifndef SYSTEM_MALLOC
-static void
-voodoo_free_hook (void *UNUSED (mem))
-{
- /* Disable all calls to free() when XEmacs is exiting and it doesn't */
- /* matter. */
- __free_hook =
-#if defined (TYPEOF) && !defined (UNO)
- /* prototype of __free_hook varies with glibc version */
- (TYPEOF (__free_hook))
-#endif
- voodoo_free_hook;
-}
-#endif /* SYSTEM_MALLOC */
-
DEFUN_NORETURN ("kill-emacs", Fkill_emacs, 0, 1, "P", /*
Exit the XEmacs job and kill it. Ask for confirmation, without argument.
If ARG is an integer, return ARG as the exit program code.
@@ -3816,15 +3750,6 @@
shut_down_emacs (0, STRINGP (arg) ? arg : Qnil, 0);
-#ifndef SYSTEM_MALLOC
- __free_hook =
-#if defined (TYPEOF) && !defined (UNO)
- /* prototype of __free_hook varies with glibc version */
- (TYPEOF (__free_hook))
-#endif
- voodoo_free_hook;
-#endif
-
exit (FIXNUMP (arg) ? XFIXNUM (arg) : 0);
RETURN_NOT_REACHED (Qnil);
}
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/free-hook.c
--- a/src/free-hook.c Thu Nov 23 03:49:37 2017 +0000
+++ b/src/free-hook.c Thu Nov 23 05:08:49 2017 +0000
@@ -14,404 +14,12 @@
You should have received a copy of the GNU General Public License
along with XEmacs. If not, see <
http://www.gnu.org/licenses/>. */
-/* Synched up with: Not in FSF. */
-
-/* Debugging hooks for malloc. */
-
-/* These hooks work with gmalloc to catch allocation errors.
- In particular, the following is trapped:
-
- * Freeing the same pointer twice.
- * Trying to free a pointer not returned by malloc.
- * Trying to realloc a pointer not returned by malloc.
-
- In addition, every word of every block freed is set to 0xDEADBEEF
- (-559038737). This causes many uses of freed storage to be trapped or
- recognized.
-
- When you use this, the storage used by the last FREE_QUEUE_LIMIT
- calls to free() is not recycled. When you call free for the Nth
- time, the (N - FREE_QUEUE_LIMIT)'th block is actually recycled.
-
- For these last FREE_QUEUE_LIMIT calls to free() a backtrace is
- saved showing where it was called from. The function
- find_backtrace() is provided here to be called from GDB with a
- pointer (such as would be passed to free()) as argument, e.g.
- (gdb) p/a *find_backtrace (0x234000). If SAVE_ARGS is defined,
- the first three arguments to each function are saved as well as the
- return addresses.
-
- If UNMAPPED_FREE is defined, instead of setting every word of freed
- storage to 0xDEADBEEF, every call to malloc goes on its own page(s).
- When free() is called, the block is read and write protected. This
- is very useful when debugging, since it usually generates a bus error
- when the DEADBEEF hack might only cause some garbage to be printed.
- However, this is too slow for everyday use, since it takes an enormous
- number of pages.
-
-
- Some other features that would be useful are:
-
- * Checking for storage leaks.
- This could be done by a GC-like facility that would scan the data
- segment looking for pointers to allocated storage and tell you
- about those that are no longer referenced. This could be invoked
- at any time. Another possibility is to report on what allocated
- storage is still in use when the process is exited. Typically
- there will be a large amount, so this might not be very useful.
-*/
-
-#ifdef emacs
#include <config.h>
#include "lisp.h"
-#else
-void *malloc (size_t);
-#endif
-#if !defined(HAVE_LIBMCHECK)
-#include <stdio.h>
-
-#include "hash.h"
-
-#ifdef UNMAPPED_FREE
-#include <sys/mman.h>
-#include <sys/param.h>
-#define ROUND_UP_TO_PAGE(i) (((i) + PAGEOFFSET) & PAGEMASK)
-#endif
-
-#include <sys/types.h>
-
-/* System function prototypes don't belong in C source files */
-/* extern void free (void *); */
-
-static struct hash_table *pointer_table;
-
-extern void (*__free_hook) (void *);
-extern void *(*__malloc_hook) (size_t);
-
-static void *check_malloc (size_t);
-
-typedef void (*fun_ptr) (void);
-
-/* free_queue is not too useful without backtrace logging */
-#define FREE_QUEUE_LIMIT 1
-#define TRACE_LIMIT 20
-
-typedef struct {
- fun_ptr return_pc;
-#ifdef SAVE_ARGS
- void *arg[3];
-#endif
-} fun_entry;
-
-typedef struct {
- void *address;
- unsigned long length;
-} free_queue_entry;
-
-static free_queue_entry free_queue[FREE_QUEUE_LIMIT];
-
-static int current_free;
-
-static int strict_free_check;
-
-static void
-check_free (void *ptr)
-{
- __free_hook = 0;
- __malloc_hook = 0;
- if (!pointer_table)
- pointer_table = make_hash_table (max (100, FREE_QUEUE_LIMIT * 2));
- if (ptr != 0)
- {
- long size;
-#ifdef UNMAPPED_FREE
- unsigned long rounded_up_size;
-#endif
-
- EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table,
- (const void **)
- (void *) &size);
-
- if (!present)
- {
- /* This can only happen if you try to free something that didn't
- come from malloc */
-#if !defined(__linux__)
- /* I originally wrote: "There's really no need to drop core."
- I have seen the error of my ways. -slb */
- assert (!strict_free_check);
-#endif
- printf("Freeing unmalloc'ed memory at %p\n", ptr);
- __free_hook = check_free;
- __malloc_hook = check_malloc;
- goto end;
- }
-
- if (size < 0)
- {
- /* This happens when you free twice */
-#if !defined(__linux__)
- /* See above comment. */
- assert (!strict_free_check);
-#endif
- printf("Freeing %p twice\n", ptr);
- __free_hook = check_free;
- __malloc_hook = check_malloc;
- goto end;
- }
-
- puthash (ptr, (void *)-size, pointer_table);
-#ifdef UNMAPPED_FREE
- /* Round up size to an even number of pages. */
- rounded_up_size = ROUND_UP_TO_PAGE (size);
- /* Protect the pages freed from all access */
- if (strict_free_check)
- mprotect (ptr, rounded_up_size, PROT_NONE);
-#else
- /* Set every word in the block to 0xDEADBEEF */
- if (strict_free_check)
- {
- unsigned long long_length = (size + (sizeof (long) - 1))
- / sizeof (long);
- unsigned long i;
-
- /* Not using the DEADBEEF_CONSTANT #define, since we don't know
- * that allocation sizes will be multiples of eight. */
- for (i = 0; i < long_length; i++)
- ((unsigned long *) ptr)[i] = 0xDEADBEEF;
- }
-#endif
- free_queue[current_free].address = ptr;
- free_queue[current_free].length = size;
-
- current_free++;
- if (current_free >= FREE_QUEUE_LIMIT)
- current_free = 0;
- /* Really free this if there's something there */
- {
- void *old = free_queue[current_free].address;
-
- if (old)
- {
-#ifdef UNMAPPED_FREE
- unsigned long old_len = free_queue[current_free].length;
-
- mprotect (old, old_len, PROT_READ | PROT_WRITE | PROT_EXEC);
-#endif
- free (old);
- remhash (old, pointer_table);
- }
- }
- }
- __free_hook = check_free;
- __malloc_hook = check_malloc;
-
- end:
- return;
-}
-
-static void *
-check_malloc (size_t size)
-{
- size_t rounded_up_size;
- void *result;
-
- __free_hook = 0;
- __malloc_hook = 0;
- if (size == 0)
- {
- result = 0;
- goto end;
- }
-#ifdef UNMAPPED_FREE
- /* Round up to an even number of pages. */
- rounded_up_size = ROUND_UP_TO_PAGE (size);
-#else
- rounded_up_size = size;
-#endif
- result = malloc (rounded_up_size);
- if (!pointer_table)
- pointer_table = make_hash_table (FREE_QUEUE_LIMIT * 2);
- puthash (result, (void *)size, pointer_table);
- __free_hook = check_free;
- __malloc_hook = check_malloc;
- end:
- return result;
-}
-
-extern void *(*__realloc_hook) (void *, size_t);
-
-#ifdef MIN
-#undef MIN
-#endif
-#define MIN(A, B) ((A) < (B) ? (A) : (B))
-
-/* Don't optimize realloc */
-
-static void *
-check_realloc (void * ptr, size_t size)
-{
- EMACS_INT present;
- size_t old_size;
- void *result = malloc (size);
-
- if (!ptr) return result;
- present = (EMACS_INT) gethash (ptr, pointer_table, (const void **) &old_size);
- if (!present)
- {
- /* This can only happen by reallocing a pointer that didn't
- come from malloc. */
-#if !defined(__linux__)
- /* see comment in check_free(). */
- ABORT ();
-#endif
- printf("Realloc'ing unmalloc'ed pointer at %p\n", ptr);
- }
-
- if (result == 0)
- goto end;
- memcpy (result, ptr, MIN (size, old_size));
- free (ptr);
- end:
- return result;
-}
-
-void enable_strict_free_check (void);
-void
-enable_strict_free_check (void)
-{
- strict_free_check = 1;
-}
-
-void disable_strict_free_check (void);
-void
-disable_strict_free_check (void)
-{
- strict_free_check = 0;
-}
-
-/* Note: All BLOCK_INPUT stuff removed from this file because it's
- completely gone in XEmacs */
-
-static void *
-block_input_malloc (size_t size);
-
-static void
-block_input_free (void* ptr)
-{
- __free_hook = 0;
- __malloc_hook = 0;
- free (ptr);
- __free_hook = block_input_free;
- __malloc_hook = block_input_malloc;
-}
-
-static void *
-block_input_malloc (size_t size)
-{
- void* result;
- __free_hook = 0;
- __malloc_hook = 0;
- result = malloc (size);
- __free_hook = block_input_free;
- __malloc_hook = block_input_malloc;
- return result;
-}
-
-
-static void *
-block_input_realloc (void* ptr, size_t size)
-{
- void* result;
- __free_hook = 0;
- __malloc_hook = 0;
- __realloc_hook = 0;
- result = realloc (ptr, size);
- __free_hook = block_input_free;
- __malloc_hook = block_input_malloc;
- __realloc_hook = block_input_realloc;
- return result;
-}
-
-#ifdef emacs
-
-void disable_free_hook (void);
-void
-disable_free_hook (void)
-{
- __free_hook = block_input_free;
- __malloc_hook = block_input_malloc;
- __realloc_hook = block_input_realloc;
-}
-
-void
-init_free_hook (void)
-{
- __free_hook = check_free;
- __malloc_hook = check_malloc;
- __realloc_hook = check_realloc;
- current_free = 0;
- strict_free_check = 1;
-}
-
-void really_free_one_entry (void *, int, int *);
-
-DEFUN ("really-free", Freally_free, 0, 1, "P", /*
-Actually free the storage held by the free() debug hook.
-A no-op if the free hook is disabled.
-*/
- (UNUSED (arg)))
-{
- int count[2];
- Lisp_Object lisp_count[2];
-
- if ((__free_hook != 0) && pointer_table)
- {
- count[0] = 0;
- count[1] = 0;
- __free_hook = 0;
- maphash ((maphash_function)really_free_one_entry,
- pointer_table, (void *)&count);
- memset (free_queue, 0, sizeof (free_queue_entry) * FREE_QUEUE_LIMIT);
- current_free = 0;
- __free_hook = check_free;
- lisp_count[0] = make_fixnum (count[0]);
- lisp_count[1] = make_fixnum (count[1]);
- return Fcons (lisp_count[0], lisp_count[1]);
- }
- else
- return Fcons (make_fixnum (0), make_fixnum (0));
-}
-
-void
-really_free_one_entry (void *key, int contents, int *countp)
-{
- if (contents < 0)
- {
- free (key);
-#ifdef UNMAPPED_FREE
- mprotect (key, -contents, PROT_READ | PROT_WRITE | PROT_EXEC);
-#endif
- remhash (key, pointer_table);
- countp[0]++;
- countp[1] += -contents;
- }
-}
-
-void
-syms_of_free_hook (void)
-{
- DEFSUBR (Freally_free);
-}
-
-#else
-void (*__free_hook)(void *) = check_free;
-void *(*__malloc_hook)(size_t) = check_malloc;
-void *(*__realloc_hook)(void *, size_t) = check_realloc;
-#endif
-
-#endif /* !defined(HAVE_LIBMCHECK) */
+/* This file used to include debugging hooks for malloc(), back when we
+ shipped our own copy of gmalloc.c. Now we just use the system malloc, and
+ this file has code to debug GCPROs. */
#if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO)
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/gc.h
--- a/src/gc.h Thu Nov 23 03:49:37 2017 +0000
+++ b/src/gc.h Thu Nov 23 05:08:49 2017 +0000
@@ -84,7 +84,7 @@
/************************************************************************/
#ifndef MALLOC_OVERHEAD
-#ifndef SYSTEM_MALLOC
+#ifdef _GNU_SOURCE
#define MALLOC_OVERHEAD 0
#elif defined (rcheck)
#define MALLOC_OVERHEAD 20
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/gmalloc.c
--- a/src/gmalloc.c Thu Nov 23 03:49:37 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1285 +0,0 @@
-/* Synched up with: Not synched up with FSF 19.28, even though I
- thought I did so. */
-
-/* Get the configuration files if we're being compiled for Emacs. */
-#ifdef emacs
-# include <config.h>
-# include "lisp.h"
-
-# include "sysdep.h"
-# include "getpagesize.h"
-# ifndef HAVE_CONFIG_H
-# define HAVE_CONFIG_H
-# endif
-#endif
-
-#if defined (__STDC__) && !defined (STDC_HEADERS)
- /* The ANSI standard says that defining __STDC__ to a non-zero value means
- that the compiler conforms to that standard. The standard requires
- certain header files and library functions to be present. Therefore,
- if your compiler defines __STDC__ to non-0 but does not have ANSI headers
- and the ANSI library routines, then your compiler is buggy. Conversely,
- an ANSI-conforming environment (which has both the ANSI headers and
- library routines, i.e., stdlib.h and `memmove') does not necessarily
- define the STDC_HEADERS flag. Lucid Emacs requires an ANSI compiler.
- Therefore, there is no need to consult the abominable STDC_HEADERS flag.
- -- jwz
- */
-# define STDC_HEADERS
-#endif
-
-
-/* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */
-/* Bwaa-haa-haa! Not a chance that this is actually true! */
-
-#define _MALLOC_INTERNAL
-
-/* The malloc headers and source files from the C library follow here. */
-
-/* Declarations for `malloc' and friends.
- Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
- Written May 1989 by Mike Haertel.
-
-This library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <
http://www.gnu.org/licenses/>.
-
- The author may be reached (Email) at the address mike(a)ai.mit.edu,
- or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
-
-#ifndef _MALLOC_H
-
-#define _MALLOC_H 1
-
-#ifdef _MALLOC_INTERNAL
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-#include <limits.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#endif /* _MALLOC_INTERNAL. */
-
-
-#if defined (__cplusplus) && !defined (emacs)
-extern "C"
-{
-#endif
-
-#undef __P
-#define __P(args) args
-#undef __ptr_t
-#define __ptr_t void *
-
-#include <stddef.h>
-#define __malloc_size_t size_t
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-/* XEmacs: I thought this should be int under SunOS, but that
- apparently fails. Curses on all this shit. */
-#define __free_ret_t void
-
-#undef malloc
-#undef realloc
-#undef calloc
-#undef free
-/* XEmacs: I tried commenting these out and including stdlib.h,
- but that fails badly. Urk! This sucks. */
-/* Allocate SIZE bytes of memory. */
-extern __ptr_t malloc __P ((size_t __size));
-/* Re-allocate the previously allocated block
- in __ptr_t, making the new block SIZE bytes long. */
-extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size));
-/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
-extern __ptr_t calloc __P ((size_t __nmemb, size_t __size));
-/* Free a block allocated by `malloc', `realloc' or `calloc'. */
-extern __free_ret_t free __P ((__ptr_t __ptr));
-
-/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
-extern __ptr_t memalign __P ((size_t __alignment, size_t __size));
-
-/* Allocate SIZE bytes on a page boundary. */
-extern __ptr_t valloc __P ((size_t __size));
-
-
-#ifdef _MALLOC_INTERNAL
-
-/* The allocator divides the heap into blocks of fixed size; large
- requests receive one or more whole blocks, and small requests
- receive a fragment of a block. Fragment sizes are powers of two,
- and all fragments of a block are the same size. When all the
- fragments in a block have been freed, the block itself is freed. */
-#define INT_BIT (CHAR_BIT * sizeof(int))
-#define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
-#define BLOCKSIZE (1 << BLOCKLOG)
-#define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
-
-/* Determine the amount of memory spanned by the initial heap table
- (not an absolute limit). */
-#define HEAP (INT_BIT > 16 ? 4194304 : 65536)
-
-/* Number of contiguous free blocks allowed to build up at the end of
- memory before they will be returned to the system. */
-#define FINAL_FREE_BLOCKS 8
-
-/* Data structure giving per-block information. */
-typedef union
- {
- /* Heap information for a busy block. */
- struct
- {
- /* Zero for a large block, or positive giving the
- logarithm to the base two of the fragment size. */
- int type;
- union
- {
- struct
- {
- __malloc_size_t nfree; /* Free frags in a fragmented block. */
- __malloc_size_t first; /* First free fragment of the block. */
- } frag;
- /* Size (in blocks) of a large cluster. */
- __malloc_size_t size;
- } info;
- } busy;
- /* Heap information for a free block
- (that may be the first of a free cluster). */
- struct
- {
- __malloc_size_t size; /* Size (in blocks) of a free cluster. */
- __malloc_size_t next; /* Index of next free cluster. */
- __malloc_size_t prev; /* Index of previous free cluster. */
- } free;
- } malloc_info;
-
-/* Pointer to first block of the heap. */
-extern char *_heapbase;
-
-/* Table indexed by block number giving per-block information. */
-extern malloc_info *_heapinfo;
-
-/* Address to block number and vice versa. */
-#define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
-#define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase))
-
-/* Current search index for the heap table. */
-extern __malloc_size_t _heapindex;
-
-/* Limit of valid info table indices. */
-extern __malloc_size_t _heaplimit;
-
-/* Doubly linked lists of free fragments. */
-struct list
-{
- struct list *next;
- struct list *prev;
-};
-
-/* Free list headers for each fragment size. */
-extern struct list _fraghead[];
-
-/* List of blocks allocated with `memalign' (or `valloc'). */
-struct alignlist
-{
- struct alignlist *next;
- __ptr_t aligned; /* The address that memaligned returned. */
- __ptr_t exact; /* The address that malloc returned. */
-};
-extern struct alignlist *_aligned_blocks;
-
-/* Instrumentation. */
-extern __malloc_size_t _chunks_used;
-extern __malloc_size_t _bytes_used;
-extern __malloc_size_t _chunks_free;
-extern __malloc_size_t _bytes_free;
-
-/* Internal version of `free' used in `morecore' (malloc.c). */
-extern void _free_internal __P ((__ptr_t __ptr));
-
-#endif /* _MALLOC_INTERNAL. */
-
-/* Underlying allocation function; successive calls should
- return contiguous pieces of memory. */
-extern __ptr_t (*__morecore) __P ((ptrdiff_t __size));
-
-/* Default value of `__morecore'. */
-extern __ptr_t __default_morecore __P ((ptrdiff_t __size));
-
-/* If not NULL, this function is called after each time
- `__morecore' is called to increase the data size. */
-extern void (*__after_morecore_hook) __P ((void));
-
-/* Nonzero if `malloc' has been called and done its initialization. */
- /* extern int __malloc_initialized; */
-
-/* Hooks for debugging versions. */
-extern void (*__free_hook) __P ((__ptr_t __ptr));
-extern __ptr_t (*__malloc_hook) __P ((size_t __size));
-extern __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, size_t __size));
-
-/* Return values for `mprobe': these are the kinds of inconsistencies that
- `mcheck' enables detection of. */
-enum mcheck_status
-{
- MCHECK_DISABLED = -1, /* Consistency checking is not turned on. */
- MCHECK_OK, /* Block is fine. */
- MCHECK_FREE, /* Block freed twice. */
- MCHECK_HEAD, /* Memory before the block was clobbered. */
- MCHECK_TAIL /* Memory after the block was clobbered. */
-};
-
-/* Activate a standard collection of debugging hooks. This must be called
- before `malloc' is ever called. ABORTFUNC is called with an error code
- (see enum above) when an inconsistency is detected. If ABORTFUNC is
- null, the standard function prints on stderr and then calls `abort'. */
-extern int mcheck __P ((void (*__abortfunc) __P ((enum mcheck_status))));
-
-/* Check for aberrations in a particular malloc'd block. You must have
- called `mcheck' already. These are the same checks that `mcheck' does
- when you free or reallocate a block. */
-extern enum mcheck_status mprobe __P ((__ptr_t __ptr));
-
-/* Activate a standard collection of tracing hooks. */
-extern void mtrace __P ((void));
-extern void muntrace __P ((void));
-
-/* Statistics available to the user. */
-struct mstats
-{
- __malloc_size_t bytes_total; /* Total size of the heap. */
- __malloc_size_t chunks_used; /* Chunks allocated by the user. */
- __malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */
- __malloc_size_t chunks_free; /* Chunks in the free list. */
- __malloc_size_t bytes_free; /* Byte total of chunks in the free list. */
-};
-
-/* Pick up the current statistics. */
-extern struct mstats mstats __P ((void));
-
-#if defined (__cplusplus) && !defined (emacs)
-}
-#endif
-
-/* Call WARNFUN with a warning message when memory usage is high. */
-extern void memory_warnings __P ((__ptr_t __start,
- void (*__warnfun) __P ((const char *))));
-
-
-#if 0 /* unused in this file, and conflicting prototypes anyway */
-/* Relocating allocator. */
-
-/* Allocate SIZE bytes, and store the address in *HANDLEPTR. */
-extern __ptr_t r_alloc __P ((__ptr_t *__handleptr, size_t __size));
-
-/* Free the storage allocated in HANDLEPTR. */
-extern void r_alloc_free __P ((__ptr_t *__handleptr));
-
-/* Adjust the block at HANDLEPTR to be SIZE bytes long. */
-extern __ptr_t r_re_alloc __P ((__ptr_t *__handleptr, size_t __size));
-#endif /* 0 */
-
-#endif /* malloc.h */
-/* Allocate memory on a page boundary.
- Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
-
-This library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <
http://www.gnu.org/licenses/>.
-
- The author may be reached (Email) at the address mike(a)ai.mit.edu,
- or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
-
-#if defined (__GNU_LIBRARY__) || defined (_LIBC)
-#include <stddef.h>
-#include <sys/cdefs.h>
-#if ! (defined (__GLIBC__) && (__GLIBC__ >= 2))
-extern size_t __getpagesize __P ((void));
-#endif
-#else
-#include "getpagesize.h"
-#define __getpagesize() getpagesize()
-#endif
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-static __malloc_size_t pagesize;
-
-__ptr_t
-valloc (__malloc_size_t size)
-{
- if (pagesize == 0)
- pagesize = __getpagesize ();
-
- return memalign (pagesize, size);
-}
-/* Memory allocator `malloc'.
- Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation
- Written May 1989 by Mike Haertel.
-
-This library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <
http://www.gnu.org/licenses/>.
-
- The author may be reached (Email) at the address mike(a)ai.mit.edu,
- or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-/* How to really get more memory. */
-#if defined (HEAP_IN_DATA) && !defined(PDUMP)
-/* once dumped, free() & realloc() on static heap space will fail */
-#define PURE_DATA(x) \
-((static_heap_dumped && (char*)x >= static_heap_base \
- && (char*)x <= (static_heap_base + static_heap_size) ) ? 1 : 0)
-extern int initialized;
-extern int purify_flag;
-extern char* static_heap_base;
-extern char* static_heap_ptr;
-extern char* static_heap_dumped;
-extern unsigned long static_heap_size;
-extern __ptr_t more_static_core __P ((ptrdiff_t __size));
-__ptr_t (*__morecore) __P ((ptrdiff_t __size)) = more_static_core;
-#else
-__ptr_t (*__morecore) __P ((ptrdiff_t __size)) = __default_morecore;
-#define PURE_DATA(x) 0
-#endif
-
-/* Debugging hook for `malloc'. */
-__ptr_t (*__malloc_hook) __P ((__malloc_size_t __size));
-
-/* Pointer to the base of the first block. */
-char *_heapbase;
-
-/* Block information table. Allocated with align/__free (not malloc/free). */
-malloc_info *_heapinfo;
-
-/* Number of info entries. */
-static __malloc_size_t heapsize;
-
-/* Search index in the info table. */
-__malloc_size_t _heapindex;
-
-/* Limit of valid info table indices. */
-__malloc_size_t _heaplimit;
-
-/* Free lists for each fragment size. */
-struct list _fraghead[BLOCKLOG];
-
-/* Instrumentation. */
-__malloc_size_t _chunks_used;
-__malloc_size_t _bytes_used;
-__malloc_size_t _chunks_free;
-__malloc_size_t _bytes_free;
-
-/* Are you experienced? */
-int __malloc_initialized;
-
-void (*__after_morecore_hook) __P ((void));
-
-/* Aligned allocation. */
-static __ptr_t align __P ((__malloc_size_t));
-static __ptr_t
-align (__malloc_size_t size)
-{
- __ptr_t result;
- unsigned long int adj;
-
- result = (*__morecore) (size);
- adj = (unsigned long int) ((unsigned long int) ((char *) result -
- (char *) NULL)) % BLOCKSIZE;
- if (adj != 0)
- {
- adj = BLOCKSIZE - adj;
- (void) (*__morecore) (adj);
- result = (char *) result + adj;
- }
-
- if (__after_morecore_hook)
- (*__after_morecore_hook) ();
-
- return result;
-}
-
-/* Set everything up and remember that we have. */
-static int initialize __P ((void));
-static int
-initialize ()
-{
-#if defined (HEAP_IN_DATA) && !defined(PDUMP)
- if (static_heap_dumped && __morecore == more_static_core)
- {
- __morecore = __default_morecore;
- }
-#endif
- heapsize = HEAP / BLOCKSIZE;
- _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info));
- if (_heapinfo == NULL)
- return 0;
- memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
- memset (_fraghead, 0, BLOCKLOG * sizeof (struct list));
- _heapinfo[0].free.size = 0;
- _heapinfo[0].free.next = _heapinfo[0].free.prev = 0;
- _heapindex = 0;
- _heaplimit = 0;
- _heapbase = (char *) _heapinfo;
-
- /* Account for the _heapinfo block itself in the statistics. */
- _bytes_used = heapsize * sizeof (malloc_info);
- _chunks_used = 1;
- _chunks_free=0;
- _bytes_free=0;
- _aligned_blocks=0;
-
- __malloc_initialized = 1;
- return 1;
-}
-
-/* Get neatly aligned memory, initializing or
- growing the heap info table as necessary. */
-static __ptr_t morecore __P ((__malloc_size_t));
-static __ptr_t
-morecore (__malloc_size_t size)
-{
- __ptr_t result;
- malloc_info *newinfo, *oldinfo;
- __malloc_size_t newsize;
-
- result = align (size);
- if (result == NULL)
- return NULL;
-
- /* Check if we need to grow the info table. */
- if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize)
- {
- newsize = heapsize;
- while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize)
- newsize *= 2;
- newinfo = (malloc_info *) align (newsize * sizeof (malloc_info));
- if (newinfo == NULL)
- {
- (*__morecore) (-(int)size);
- return NULL;
- }
- memcpy (newinfo, _heapinfo, heapsize * sizeof (malloc_info));
- memset (&newinfo[heapsize], 0,
- (newsize - heapsize) * sizeof (malloc_info));
- oldinfo = _heapinfo;
- newinfo[BLOCK (oldinfo)].busy.type = 0;
- newinfo[BLOCK (oldinfo)].busy.info.size
- = BLOCKIFY (heapsize * sizeof (malloc_info));
- _heapinfo = newinfo;
- /* Account for the _heapinfo block itself in the statistics. */
- _bytes_used += newsize * sizeof (malloc_info);
- ++_chunks_used;
- _free_internal (oldinfo);
- heapsize = newsize;
- }
-
- _heaplimit = BLOCK ((char *) result + size);
- return result;
-}
-
-/* Allocate memory from the heap. */
-__ptr_t
-malloc (__malloc_size_t size)
-{
- __ptr_t result;
- __malloc_size_t block, blocks, lastblocks, start;
- __malloc_size_t i;
- struct list *next;
-
- /* ANSI C allows `malloc (0)' to either return NULL, or to return a
- valid address you can realloc and free (though not dereference).
-
- It turns out that some extant code (sunrpc, at least Ultrix's version)
- expects `malloc (0)' to return non-NULL and breaks otherwise.
- Be compatible. */
-
-#ifdef HAVE_X_WINDOWS
- /* there is at least one Xt bug where calloc(n,x) is blindly called
- where n can be 0, and yet if 0 is returned, Xt barfs */
- if (size == 0)
- size = sizeof (struct list);
-#else
- if (size == 0)
- return NULL;
-#endif
-
- if (__malloc_hook != NULL)
- return (*__malloc_hook) (size);
-
- if (!__malloc_initialized)
- if (!initialize ())
- return NULL;
-
-#ifdef SUNOS_LOCALTIME_BUG
- /* Workaround for localtime() allocating 8 bytes and writing 9 bug... */
- if (size < 16)
- size = 16;
-#endif
-
- if (size < sizeof (struct list))
- size = sizeof (struct list);
-
- /* Determine the allocation policy based on the request size. */
- if (size <= BLOCKSIZE / 2)
- {
- /* Small allocation to receive a fragment of a block.
- Determine the logarithm to base two of the fragment size. */
- __malloc_size_t log2 = 1;
- --size;
- while ((size /= 2) != 0)
- ++log2;
-
- /* Look in the fragment lists for a
- free fragment of the desired size. */
- next = _fraghead[log2].next;
- if (next != NULL)
- {
- /* There are free fragments of this size.
- Pop a fragment out of the fragment list and return it.
- Update the block's nfree and first counters. */
- result = (__ptr_t) next;
- next->prev->next = next->next;
- if (next->next != NULL)
- next->next->prev = next->prev;
- block = BLOCK (result);
- if (--_heapinfo[block].busy.info.frag.nfree != 0)
- _heapinfo[block].busy.info.frag.first = (unsigned long int)
- ((unsigned long int) ((char *) next->next - (char *) NULL)
- % BLOCKSIZE) >> log2;
-
- /* Update the statistics. */
- ++_chunks_used;
- _bytes_used += 1 << log2;
- --_chunks_free;
- _bytes_free -= 1 << log2;
- }
- else
- {
- /* No free fragments of the desired size, so get a new block
- and break it into fragments, returning the first. */
- result = malloc (BLOCKSIZE);
- if (result == NULL)
- return NULL;
-
- /* Link all fragments but the first into the free list. */
- for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> log2); ++i)
- {
- next = (struct list *) ((char *) result + (i << log2));
- next->next = _fraghead[log2].next;
- next->prev = &_fraghead[log2];
- next->prev->next = next;
- if (next->next != NULL)
- next->next->prev = next;
- }
-
- /* Initialize the nfree and first counters for this block. */
- block = BLOCK (result);
- _heapinfo[block].busy.type = log2;
- _heapinfo[block].busy.info.frag.nfree = i - 1;
- _heapinfo[block].busy.info.frag.first = i - 1;
-
- _chunks_free += (BLOCKSIZE >> log2) - 1;
- _bytes_free += BLOCKSIZE - (1 << log2);
- _bytes_used -= BLOCKSIZE - (1 << log2);
- }
- }
- else
- {
- /* Large allocation to receive one or more blocks.
- Search the free list in a circle starting at the last place visited.
- If we loop completely around without finding a large enough
- space we will have to get more memory from the system. */
- blocks = BLOCKIFY (size);
- start = block = _heapindex;
- while (_heapinfo[block].free.size < blocks)
- {
- block = _heapinfo[block].free.next;
- if (block == start)
- {
- /* Need to get more from the system. Check to see if
- the new core will be contiguous with the final free
- block; if so we don't need to get as much. */
- block = _heapinfo[0].free.prev;
- lastblocks = _heapinfo[block].free.size;
- if (_heaplimit != 0 && block + lastblocks == _heaplimit &&
- (*__morecore) (0) == ADDRESS (block + lastblocks) &&
- (morecore ((blocks - lastblocks) * BLOCKSIZE)) != NULL)
- {
- /* Which block we are extending (the `final free
- block' referred to above) might have changed, if
- it got combined with a freed info table. */
- block = _heapinfo[0].free.prev;
- _heapinfo[block].free.size += (blocks - lastblocks);
- _bytes_free += (blocks - lastblocks) * BLOCKSIZE;
- continue;
- }
- result = morecore (blocks * BLOCKSIZE);
- if (result == NULL)
- return NULL;
- block = BLOCK (result);
- _heapinfo[block].busy.type = 0;
- _heapinfo[block].busy.info.size = blocks;
- ++_chunks_used;
- _bytes_used += blocks * BLOCKSIZE;
- return result;
- }
- }
-
- /* At this point we have found a suitable free list entry.
- Figure out how to remove what we need from the list. */
- result = ADDRESS (block);
- if (_heapinfo[block].free.size > blocks)
- {
- /* The block we found has a bit left over,
- so relink the tail end back into the free list. */
- _heapinfo[block + blocks].free.size
- = _heapinfo[block].free.size - blocks;
- _heapinfo[block + blocks].free.next
- = _heapinfo[block].free.next;
- _heapinfo[block + blocks].free.prev
- = _heapinfo[block].free.prev;
- _heapinfo[_heapinfo[block].free.prev].free.next
- = _heapinfo[_heapinfo[block].free.next].free.prev
- = _heapindex = block + blocks;
- }
- else
- {
- /* The block exactly matches our requirements,
- so just remove it from the list. */
- _heapinfo[_heapinfo[block].free.next].free.prev
- = _heapinfo[block].free.prev;
- _heapinfo[_heapinfo[block].free.prev].free.next
- = _heapindex = _heapinfo[block].free.next;
- --_chunks_free;
- }
-
- _heapinfo[block].busy.type = 0;
- _heapinfo[block].busy.info.size = blocks;
- ++_chunks_used;
- _bytes_used += blocks * BLOCKSIZE;
- _bytes_free -= blocks * BLOCKSIZE;
- }
-
- return result;
-}
-
-#ifndef _LIBC
-
-/* On some ANSI C systems, some libc functions call _malloc, _free
- and _realloc. Make them use the GNU functions. */
-
-__ptr_t _malloc (__malloc_size_t size);
-__ptr_t
-_malloc (__malloc_size_t size)
-{
- return malloc (size);
-}
-
-void _free (__ptr_t ptr);
-void
-_free (__ptr_t ptr)
-{
- free (ptr);
-}
-
-__ptr_t _realloc (__ptr_t ptr, __malloc_size_t size);
-__ptr_t
-_realloc (__ptr_t ptr, __malloc_size_t size)
-{
- return realloc (ptr, size);
-}
-
-#endif
-/* Free a block of memory allocated by `malloc'.
- Copyright 1990, 1991, 1992, 1994 Free Software Foundation
- Written May 1989 by Mike Haertel.
-
-This library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <
http://www.gnu.org/licenses/>.
-
- The author may be reached (Email) at the address mike(a)ai.mit.edu,
- or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-/* Debugging hook for free. */
-void (*__free_hook) __P ((__ptr_t __ptr));
-
-/* List of blocks allocated by memalign. */
-struct alignlist *_aligned_blocks = NULL;
-
-/* Return memory to the heap.
- Like `free' but don't call a __free_hook if there is one. */
-void
-_free_internal (__ptr_t ptr)
-{
- int type;
- __malloc_size_t block, blocks;
- __malloc_size_t i;
- struct list *prev, *next;
-
- block = BLOCK (ptr);
-
- type = _heapinfo[block].busy.type;
- switch (type)
- {
- case 0:
- /* Get as many statistics as early as we can. */
- --_chunks_used;
- _bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE;
- _bytes_free += _heapinfo[block].busy.info.size * BLOCKSIZE;
-
- /* Find the free cluster previous to this one in the free list.
- Start searching at the last block referenced; this may benefit
- programs with locality of allocation. */
- i = _heapindex;
- if (i > block)
- while (i > block)
- i = _heapinfo[i].free.prev;
- else
- {
- do
- i = _heapinfo[i].free.next;
- while (i > 0 && i < block);
- i = _heapinfo[i].free.prev;
- }
-
- /* Determine how to link this block into the free list. */
- if (block == i + _heapinfo[i].free.size)
- {
- /* Coalesce this block with its predecessor. */
- _heapinfo[i].free.size += _heapinfo[block].busy.info.size;
- block = i;
- }
- else
- {
- /* Really link this block back into the free list. */
- _heapinfo[block].free.size = _heapinfo[block].busy.info.size;
- _heapinfo[block].free.next = _heapinfo[i].free.next;
- _heapinfo[block].free.prev = i;
- _heapinfo[i].free.next = block;
- _heapinfo[_heapinfo[block].free.next].free.prev = block;
- ++_chunks_free;
- }
-
- /* Now that the block is linked in, see if we can coalesce it
- with its successor (by deleting its successor from the list
- and adding in its size). */
- if (block + _heapinfo[block].free.size == _heapinfo[block].free.next)
- {
- _heapinfo[block].free.size
- += _heapinfo[_heapinfo[block].free.next].free.size;
- _heapinfo[block].free.next
- = _heapinfo[_heapinfo[block].free.next].free.next;
- _heapinfo[_heapinfo[block].free.next].free.prev = block;
- --_chunks_free;
- }
-
- /* Now see if we can return stuff to the system. */
- blocks = _heapinfo[block].free.size;
- if (blocks >= FINAL_FREE_BLOCKS && block + blocks == _heaplimit
- && (*__morecore) (0) == ADDRESS (block + blocks))
- {
- __malloc_size_t bytes = blocks * BLOCKSIZE;
- _heaplimit -= blocks;
- (*__morecore) (-(int)bytes);
- _heapinfo[_heapinfo[block].free.prev].free.next
- = _heapinfo[block].free.next;
- _heapinfo[_heapinfo[block].free.next].free.prev
- = _heapinfo[block].free.prev;
- block = _heapinfo[block].free.prev;
- --_chunks_free;
- _bytes_free -= bytes;
- }
-
- /* Set the next search to begin at this block. */
- _heapindex = block;
- break;
-
- default:
- /* Do some of the statistics. */
- --_chunks_used;
- _bytes_used -= 1 << type;
- ++_chunks_free;
- _bytes_free += 1 << type;
-
- /* Get the address of the first free fragment in this block. */
- prev = (struct list *) ((char *) ADDRESS (block) +
- (_heapinfo[block].busy.info.frag.first << type));
-
- if (_heapinfo[block].busy.info.frag.nfree ==
- (__malloc_size_t) ((BLOCKSIZE >> type) - 1))
- {
- /* If all fragments of this block are free, remove them
- from the fragment list and free the whole block. */
- next = prev;
- for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> type); ++i)
- next = next->next;
- prev->prev->next = next;
- if (next != NULL)
- next->prev = prev->prev;
- _heapinfo[block].busy.type = 0;
- _heapinfo[block].busy.info.size = 1;
-
- /* Keep the statistics accurate. */
- ++_chunks_used;
- _bytes_used += BLOCKSIZE;
- _chunks_free -= BLOCKSIZE >> type;
- _bytes_free -= BLOCKSIZE;
-
- free (ADDRESS (block));
- }
- else if (_heapinfo[block].busy.info.frag.nfree != 0)
- {
- /* If some fragments of this block are free, link this
- fragment into the fragment list after the first free
- fragment of this block. */
- next = (struct list *) ptr;
- next->next = prev->next;
- next->prev = prev;
- prev->next = next;
- if (next->next != NULL)
- next->next->prev = next;
- ++_heapinfo[block].busy.info.frag.nfree;
- }
- else
- {
- /* No fragments of this block are free, so link this
- fragment into the fragment list and announce that
- it is the first free fragment of this block. */
- prev = (struct list *) ptr;
- _heapinfo[block].busy.info.frag.nfree = 1;
- _heapinfo[block].busy.info.frag.first = (unsigned long int)
- ((unsigned long int) ((char *) ptr - (char *) NULL)
- % BLOCKSIZE >> type);
- prev->next = _fraghead[type].next;
- prev->prev = &_fraghead[type];
- prev->prev->next = prev;
- if (prev->next != NULL)
- prev->next->prev = prev;
- }
- break;
- }
-}
-
-/* Return memory to the heap. */
-__free_ret_t
-free (__ptr_t ptr)
-{
- struct alignlist *l;
-
- if (ptr == NULL)
- return;
-
- if (PURE_DATA(ptr))
- {
- return;
- }
-
- for (l = _aligned_blocks; l != NULL; l = l->next)
- if (l->aligned == ptr)
- {
- l->aligned = NULL; /* Mark the slot in the list as free. */
- ptr = l->exact;
- break;
- }
-
- if (__free_hook != NULL)
- (*__free_hook) (ptr);
- else
- _free_internal (ptr);
-}
-/* Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
-
-The GNU C Library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-The GNU C Library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with the GNU C Library. If not, see <
http://www.gnu.org/licenses/>. */
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-#ifdef _LIBC
-
-#include <ansidecl.h>
-#include <gnu-stabs.h>
-
-#undef cfree
-
-function_alias(cfree, free, void, (ptr),
- DEFUN(cfree, (ptr), PTR ptr))
-
-#else
-
-void cfree (__ptr_t ptr);
-void
-cfree (__ptr_t ptr)
-{
- free (ptr);
-}
-
-#endif
-/* Change the size of a block allocated by `malloc'.
- Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
- Written May 1989 by Mike Haertel.
-
-This library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <
http://www.gnu.org/licenses/>.
-
- The author may be reached (Email) at the address mike(a)ai.mit.edu,
- or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-#ifndef min
-#define min(A, B) ((A) < (B) ? (A) : (B))
-#endif
-
-/* Debugging hook for realloc. */
-__ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size));
-
-/* Resize the given region to the new size, returning a pointer
- to the (possibly moved) region. This is optimized for speed;
- some benchmarks seem to indicate that greater compactness is
- achieved by unconditionally allocating and copying to a
- new region. This module has incestuous knowledge of the
- internals of both free and malloc. */
-__ptr_t
-realloc (__ptr_t ptr, __malloc_size_t size)
-{
- __ptr_t result;
- int type;
- __malloc_size_t block, blocks, oldlimit;
-
- if (PURE_DATA (ptr))
- {
- result = malloc (size);
- memcpy(result, ptr, size);
- return result;
- }
-
- else if (size == 0)
- {
- free (ptr);
- return malloc (0);
- }
- else if (ptr == NULL)
- return malloc (size);
-
- if (__realloc_hook != NULL)
- return (*__realloc_hook) (ptr, size);
-
- block = BLOCK (ptr);
-
- type = _heapinfo[block].busy.type;
- switch (type)
- {
- case 0:
- /* Maybe reallocate a large block to a small fragment. */
- if (size <= BLOCKSIZE / 2)
- {
- result = malloc (size);
- if (result != NULL)
- {
- memcpy (result, ptr, size);
- _free_internal (ptr);
- return result;
- }
- }
-
- /* The new size is a large allocation as well;
- see if we can hold it in place. */
- blocks = BLOCKIFY (size);
- if (blocks < _heapinfo[block].busy.info.size)
- {
- /* The new size is smaller; return
- excess memory to the free list. */
- _heapinfo[block + blocks].busy.type = 0;
- _heapinfo[block + blocks].busy.info.size
- = _heapinfo[block].busy.info.size - blocks;
- _heapinfo[block].busy.info.size = blocks;
- /* We have just created a new chunk by splitting a chunk in two.
- Now we will free this chunk; increment the statistics counter
- so it doesn't become wrong when _free_internal decrements it. */
- ++_chunks_used;
- _free_internal (ADDRESS (block + blocks));
- result = ptr;
- }
- else if (blocks == _heapinfo[block].busy.info.size)
- /* No size change necessary. */
- result = ptr;
- else
- {
- /* Won't fit, so allocate a new region that will.
- Free the old region first in case there is sufficient
- adjacent free space to grow without moving. */
- blocks = _heapinfo[block].busy.info.size;
- /* Prevent free from actually returning memory to the system. */
- oldlimit = _heaplimit;
- _heaplimit = 0;
- free (ptr);
- _heaplimit = oldlimit;
- result = malloc (size);
- if (result == NULL)
- {
- /* Now we're really in trouble. We have to unfree
- the thing we just freed. Unfortunately it might
- have been coalesced with its neighbors. */
- if (_heapindex == block)
- (void) malloc (blocks * BLOCKSIZE);
- else
- {
- __ptr_t previous = malloc ((block - _heapindex) * BLOCKSIZE);
- (void) malloc (blocks * BLOCKSIZE);
- free (previous);
- }
- return NULL;
- }
- if (ptr != result)
- memmove (result, ptr, blocks * BLOCKSIZE);
- }
- break;
-
- default:
- /* Old size is a fragment; type is logarithm
- to base two of the fragment size. */
- if (size > (__malloc_size_t) (1 << (type - 1)) &&
- size <= (__malloc_size_t) (1 << type))
- /* The new size is the same kind of fragment. */
- result = ptr;
- else
- {
- /* The new size is different; allocate a new space,
- and copy the lesser of the new size and the old. */
- result = malloc (size);
- if (result == NULL)
- return NULL;
- memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type));
- free (ptr);
- }
- break;
- }
-
- return result;
-}
-/* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
-
-This library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <
http://www.gnu.org/licenses/>.
-
- The author may be reached (Email) at the address mike(a)ai.mit.edu,
- or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-/* Allocate an array of NMEMB elements each SIZE bytes long.
- The entire array is initialized to zeros. */
-__ptr_t
-calloc (__malloc_size_t nmemb, __malloc_size_t size)
-{
- __ptr_t result = malloc (nmemb * size);
-
- if (result != NULL)
- (void) memset (result, 0, nmemb * size);
-
- return result;
-}
-/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
-
-The GNU C Library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-The GNU C Library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with the GNU C Library. If not, see <
http://www.gnu.org/licenses/>. */
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-/* #ifndef __GNU_LIBRARY__ */
-#define __sbrk sbrk
-/* #endif */
-
-#ifdef __GNU_LIBRARY__
-/* It is best not to declare this and cast its result on foreign operating
- systems with potentially hostile include files. */
-#if !(defined(linux) && defined(sparc))
-extern __ptr_t __sbrk __P ((int increment));
-#endif
-#endif
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-/* Allocate INCREMENT more bytes of data space,
- and return the start of data space, or NULL on errors.
- If INCREMENT is negative, shrink data space. */
-__ptr_t
-__default_morecore (ptrdiff_t increment)
-{
- __ptr_t result = (__ptr_t) __sbrk (increment);
- if (result == (__ptr_t) -1)
- return NULL;
- return result;
-}
-/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
-
-This library is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-This library is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <
http://www.gnu.org/licenses/>. */
-
-#ifndef _MALLOC_INTERNAL
-#define _MALLOC_INTERNAL
-#include <malloc.h>
-#endif
-
-__ptr_t
-memalign (__malloc_size_t alignment, __malloc_size_t size)
-{
- __ptr_t result;
- unsigned long int adj;
-
- size = ((size + alignment - 1) / alignment) * alignment;
-
- result = malloc (size);
- if (result == NULL)
- return NULL;
- adj = (unsigned long int) ((unsigned long int) ((char *) result -
- (char *) NULL)) % alignment;
- if (adj != 0)
- {
- struct alignlist *l;
- for (l = _aligned_blocks; l != NULL; l = l->next)
- if (l->aligned == NULL)
- /* This slot is free. Use it. */
- break;
- if (l == NULL)
- {
- l = (struct alignlist *) malloc (sizeof (struct alignlist));
- if (l == NULL)
- {
- free (result);
- return NULL;
- }
- l->next = _aligned_blocks;
- _aligned_blocks = l;
- }
- l->exact = result;
- result = l->aligned = (char *) result + alignment - adj;
- }
-
- return result;
-}
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/ralloc.c
--- a/src/ralloc.c Thu Nov 23 03:49:37 2017 +0000
+++ b/src/ralloc.c Thu Nov 23 05:08:49 2017 +0000
@@ -51,7 +51,7 @@
/* Unconditionally use unsigned char * for this. */
typedef unsigned char *POINTER;
-#ifdef DOUG_LEA_MALLOC
+#ifdef _GNU_SOURCE
#define M_TOP_PAD -2
#include <malloc.h>
#endif
@@ -82,8 +82,7 @@
#define NIL ((POINTER) 0)
-#if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC)
-
+#if !defined(HAVE_MMAP)
/* A flag to indicate whether we have initialized ralloc yet. For
Emacs's sake, please do not make this local to malloc_init; on some
machines, the dumping procedure makes all static variables
@@ -1104,12 +1103,6 @@
}
-/* The hook `malloc' uses for the function which gets more space
- from the system. */
-#ifndef DOUG_LEA_MALLOC
-extern POINTER (*__morecore) (ptrdiff_t size);
-#endif
-
/* Initialize various things for memory allocation. */
void
@@ -1119,12 +1112,6 @@
return;
r_alloc_initialized = 1;
- real_morecore = (POINTER (*) (ptrdiff_t)) __morecore;
- __morecore =
-#ifdef TYPEOF
- (TYPEOF (__morecore))
-#endif
- r_alloc_sbrk;
first_heap = last_heap = &heap_base;
first_heap->next = first_heap->prev = NIL_HEAP;
@@ -1135,7 +1122,7 @@
page_size = PAGE;
extra_bytes = ROUNDUP (50000);
-#ifdef DOUG_LEA_MALLOC
+#ifdef _GNU_SOURCE
mallopt (M_TOP_PAD, 64 * 4096);
#else
#if 0 /* Hasn't been synched yet */
@@ -1164,121 +1151,6 @@
use_relocatable_buffers = 1;
}
-#if defined (emacs) && defined (DOUG_LEA_MALLOC)
-
-/* Reinitialize the morecore hook variables after restarting a dumped
- Emacs. This is needed when using Doug Lea's malloc from GNU libc. */
-void r_alloc_reinit (void);
-void
-r_alloc_reinit (void)
-{
- /* Only do this if the hook has been reset, so that we don't get an
- infinite loop, in case Emacs was linked statically. */
- if ( (POINTER (*) (ptrdiff_t)) __morecore != r_alloc_sbrk)
- {
- real_morecore = (POINTER (*) (ptrdiff_t)) __morecore;
- __morecore =
-#ifdef TYPEOF
- (TYPEOF (__morecore))
-#endif
- r_alloc_sbrk;
- }
-}
-#if 0
-#ifdef DEBUG
-
-void
-r_alloc_check (void)
-{
- int found = 0;
- heap_ptr h, ph = 0;
- bloc_ptr b, pb = 0;
-
- if (!r_alloc_initialized)
- return;
-
- assert (first_heap);
- assert (last_heap->end <= (POINTER) sbrk (0));
- assert ((POINTER) first_heap < first_heap->start);
- assert (first_heap->start <= virtual_break_value);
- assert (virtual_break_value <= first_heap->end);
-
- for (h = first_heap; h; h = h->next)
- {
- assert (h->prev == ph);
- assert ((POINTER) ROUNDUP (h->end) == h->end);
-#if 0 /* ??? The code in ralloc.c does not really try to ensure
- the heap start has any sort of alignment.
- Perhaps it should. */
- assert ((POINTER) MEM_ROUNDUP (h->start) == h->start);
-#endif
- assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start);
- assert (h->start <= h->bloc_start && h->bloc_start <=
h->end);
-
- if (ph)
- {
- assert (ph->end < h->start);
- assert (h->start <= (POINTER)h && (POINTER)(h+1) <=
h->bloc_start);
- }
-
- if (h->bloc_start <= break_value && break_value <= h->end)
- found = 1;
-
- ph = h;
- }
-
- assert (found);
- assert (last_heap == ph);
-
- for (b = first_bloc; b; b = b->next)
- {
- assert (b->prev == pb);
- assert ((POINTER) MEM_ROUNDUP (b->data) == b->data);
- assert ((size_t) MEM_ROUNDUP (b->size) == b->size);
-
- ph = 0;
- for (h = first_heap; h; h = h->next)
- {
- if (h->bloc_start <= b->data && b->data + b->size <=
h->end)
- break;
- ph = h;
- }
-
- assert (h);
-
- if (pb && pb->data + pb->size != b->data)
- {
- assert (ph && b->data == h->bloc_start);
- while (ph)
- {
- if (ph->bloc_start <= pb->data
- && pb->data + pb->size <= ph->end)
- {
- assert (pb->data + pb->size + b->size > ph->end);
- break;
- }
- else
- {
- assert (ph->bloc_start + b->size > ph->end);
- }
- ph = ph->prev;
- }
- }
- pb = b;
- }
-
- assert (last_bloc == pb);
-
- if (last_bloc)
- assert (last_bloc->data + last_bloc->size == break_value);
- else
- assert (first_heap->bloc_start == break_value);
-}
-#endif /* DEBUG */
-#endif /* 0 */
-
-#endif
-
#else /* HAVE_MMAP */
/*
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/sysdep.c
--- a/src/sysdep.c Thu Nov 23 03:49:37 2017 +0000
+++ b/src/sysdep.c Thu Nov 23 05:08:49 2017 +0000
@@ -1892,7 +1892,7 @@
/* Need start_of_data() as much as possible now, for total_data_usage();
but with PDUMP and WIN32_NATIVE, can't currently do it. */
-#if ! (defined (PDUMP) && defined (WIN32_NATIVE) && defined
(SYSTEM_MALLOC))
+#if ! (defined (PDUMP) && defined (WIN32_NATIVE))
#define NEED_STARTS
#endif
@@ -1976,7 +1976,7 @@
#endif /* ORDINARY_LINK */
#endif /* DATA_START */
}
-#endif /* NEED_STARTS aka !(PDUMP && WIN32_NATIVE && SYSTEM_MALLOC) */
+#endif /* NEED_STARTS aka !(PDUMP && WIN32_NATIVE) */
extern void *minimum_address_seen; /* from xmalloc() */
extern void *maximum_address_seen; /* from xmalloc() */
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/text.h
--- a/src/text.h Thu Nov 23 03:49:37 2017 +0000
+++ b/src/text.h Thu Nov 23 05:08:49 2017 +0000
@@ -1548,9 +1548,9 @@
# define HIGH_BIT_MASK MAKE_32_BIT_UNSIGNED_CONSTANT (0x80808080)
#endif
-#define ALIGN_BITS ((EMACS_UINT) (ALIGNOF (STRIDE_TYPE) - 1))
-#define ALIGN_MASK (~ ALIGN_BITS)
-#define ALIGNED(ptr) ((((EMACS_UINT) ptr) & ALIGN_BITS) == 0)
+#define STRIDE_ALIGN_BITS ((EMACS_UINT) (ALIGNOF (STRIDE_TYPE) - 1))
+#define STRIDE_ALIGN_MASK (~ STRIDE_ALIGN_BITS)
+#define STRIDE_ALIGNED(ptr) ((((EMACS_UINT) ptr) & STRIDE_ALIGN_BITS) == 0)
#define STRIDE sizeof (STRIDE_TYPE)
/* Skip as many ASCII bytes as possible in the memory block [PTR, END).
@@ -1565,7 +1565,7 @@
/* Need to do in 3 sections -- before alignment start, aligned chunk,
after alignment end. */
- while (!ALIGNED (ptr))
+ while (!STRIDE_ALIGNED (ptr))
{
if (ptr == end || !byte_ascii_p (*ptr))
return ptr;
@@ -1595,7 +1595,7 @@
/* Need to do in 3 sections -- before alignment start, aligned chunk,
after alignment end. */
- while (!ALIGNED (ptr))
+ while (!STRIDE_ALIGNED (ptr))
{
if (ptr == end || !byte_ascii_p (*(ptr - 1)))
return ptr;
diff -r c129b2eb4cf9 -r 3b1ef8c61ffe src/vm-limit.c
--- a/src/vm-limit.c Thu Nov 23 03:49:37 2017 +0000
+++ b/src/vm-limit.c Thu Nov 23 05:08:49 2017 +0000
@@ -32,7 +32,7 @@
#include "mem-limits.h"
-#ifndef _NO_MALLOC_WARNING_
+#ifdef HAVE_MALLOC_WARNING
/*
Level number of warnings already issued.
@@ -134,22 +134,22 @@
}
}
-#endif /* not _NO_MALLOC_WARNING_ */
+#endif /* HAVE_MALLOC_WARNING */
/* Cause reinitialization based on job parameters;
also declare where the end of pure storage is. */
void
memory_warnings (void *start,
-#ifdef _NO_MALLOC_WARNING_
+#ifdef HAVE_MALLOC_WARNING
+ void (*warnfun) (const char *)
+#else
void (*UNUSED_ARG (warnfun)) (const char *) ATTRIBUTE_UNUSED
-#else
- void (*warnfun) (const char *)
#endif
)
{
-#ifndef _NO_MALLOC_WARNING_
- extern void (* __after_morecore_hook) (void); /* From gmalloc.c */
+#ifdef HAVE_MALLOC_WARNING
+ extern void (* __after_morecore_hook) (void); /* From glibc. */
#endif
if (start)
@@ -157,7 +157,7 @@
else
data_space_start = start_of_data ();
-#ifndef _NO_MALLOC_WARNING_
+#ifdef HAVE_MALLOC_WARNING
warn_function = warnfun;
__after_morecore_hook = check_memory_limits;
#endif
--
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after forty pints of stout’
(C. Moore)