From 39cfc5731695c46a337606da9bc86a659dbad5b3 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 5 Mar 2017 18:15:05 +0100 Subject: replaced Linux-specific mallinfo()-based memory limiting with a more portable and faster hack * Works by "hooking" into malloc() and friends and counting the usable heap object sizes with malloc_usable_size(). Thus, it has no memory-overhead. * Will work at least on Linux and (Free)BSD. Other UNIXoid systems may work as well - this is tested by ./configure. * Usually faster than even the fallback implementation since the memory limit is hit earlier. * A similar approach could be tried on Windows (TODO). * A proper memory-limiting counting all malloc()s in the system can make a huge difference as this test case shows: sciteco -e '<@EU[X^E\a]"^E\a"%a>' It will allocate gigabytes before hitting the 500MB memory limit... * Fixed the UNIX-function checks on BSDs. --- configure.ac | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 928749b..e47ac0d 100644 --- a/configure.ac +++ b/configure.ac @@ -159,20 +159,23 @@ AC_CHECK_FUNCS([memset setlocale strchr strrchr fstat], , [ AC_MSG_ERROR([Missing libc function]) ]) -# Library functions that should exist on UNIX/Linux -# and UNIXoid systems +# Library functions that we assume exist on UNIX/Linux +# and UNIXoid systems, so that G_OS_UNIX is sufficient +# to test for them. +# FIXME: Perhaps it would be more elegant to check whether +# glib defines G_OS_UNIX||G_OS_HAIKU instead... case $host in -*-*-darwin* | *-*-linux* | *-*-cygwin* | *-*-haiku*) - AC_CHECK_FUNCS([realpath fchown dup dup2], , [ +*-*-linux* | *-*-*bsd* | *-*-darwin* | *-*-cygwin* | *-*-haiku*) + AC_CHECK_FUNCS([realpath fchown dup dup2 dlsym], , [ AC_MSG_ERROR([Missing libc function]) ]) ;; esac -# Check for optional GNU libc features. -# Will probably only be found on Linux. -AC_CHECK_HEADERS([malloc.h]) -AC_CHECK_FUNCS([malloc_trim mallinfo]) +# Check for optional libc features. +# Will probably only be found on Linux/glibc or BSD. +AC_CHECK_HEADERS([malloc.h malloc_np.h]) +AC_CHECK_FUNCS([malloc_trim malloc_usable_size]) # # Config options -- cgit v1.2.3