Refactor --with-jemalloc option

Find jemalloc header first, then using the found header, try [with
mangle, without mangle] x [no more additional libraries, adding
jemalloc] combination.
This commit is contained in:
Nobuyoshi Nakada 2021-07-07 01:08:00 +09:00
parent 82d425515d
commit e8d9539373
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6
Notes: git 2021-07-08 00:53:59 +09:00

View File

@ -1297,45 +1297,53 @@ AC_ARG_WITH([jemalloc],
[AS_HELP_STRING([--with-jemalloc],[use jemalloc allocator])], [AS_HELP_STRING([--with-jemalloc],[use jemalloc allocator])],
[with_jemalloc=$withval], [with_jemalloc=no]) [with_jemalloc=$withval], [with_jemalloc=no])
AS_IF([test "x$with_jemalloc" != xno],[ AS_IF([test "x$with_jemalloc" != xno],[
AC_SEARCH_LIBS([malloc_conf], [jemalloc], # find jemalloc header first
[ malloc_header=
AC_DEFINE(HAVE_LIBJEMALLOC, 1) AC_CHECK_HEADER(jemalloc/jemalloc.h, [malloc_header=jemalloc/jemalloc.h], [
with_jemalloc=yes AC_CHECK_HEADER(jemalloc.h, [malloc_header=jemalloc.h])
], ])
[test x$with_jemalloc = xyes && with_jemalloc=no])
for malloc_header in jemalloc/jemalloc.h jemalloc.h; do
AC_CHECK_HEADER($malloc_header, [break], [malloc_header=])
done
AS_IF([test "$malloc_header" != ""], [ AS_IF([test "$malloc_header" != ""], [
AC_DEFINE_UNQUOTED(RUBY_ALTERNATIVE_MALLOC_HEADER, [<$malloc_header>]) AC_DEFINE_UNQUOTED(RUBY_ALTERNATIVE_MALLOC_HEADER, [<$malloc_header>])
], ])
[test x$with_jemalloc = xyes && with_jemalloc=no]) save_LIBS="$LIBS"
AS_IF([test "x$with_jemalloc" != xyes], [ AC_CACHE_CHECK([for jemalloc library], rb_cv_jemalloc_library, [
AC_CACHE_CHECK([for jemalloc with JEMALLOC_MANGLE], rb_cv_jemalloc_demangle, rb_cv_jemalloc_library=no
[AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@define JEMALLOC_MANGLE 1 # try [with mangle, without mangle] x [no more additional
# libraries, adding jemalloc] combination, using the jemalloc
# header found above.
for mangle in '' mangle; do
for lib in '' -ljemalloc; do
LIBS="${lib:+$lib }$LIBS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([${mangle:+@%:@define JEMALLOC_MANGLE 1}
@%:@include <stdio.h>
@%:@ifdef RUBY_ALTERNATIVE_MALLOC_HEADER @%:@ifdef RUBY_ALTERNATIVE_MALLOC_HEADER
@%:@include RUBY_ALTERNATIVE_MALLOC_HEADER @%:@include RUBY_ALTERNATIVE_MALLOC_HEADER
@%:@else @%:@else
extern const char *malloc_conf; extern const char *malloc_conf;
@%:@endif], [return !&malloc_conf])], @%:@endif],
[rb_cv_jemalloc_demangle=yes], [/* access at runtime not to be optimized away */
[rb_cv_jemalloc_demangle=no]) if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);])],
[rb_cv_jemalloc_library="${lib:-none required}${mangle:+ with mangle}"])
LIBS="$save_LIBS"
test "${rb_cv_jemalloc_library}" = no || break 2
done
done
]) ])
]) with_jemalloc=${rb_cv_jemalloc_library}
AS_IF([test "x$rb_cv_jemalloc_demangle" = xyes], [ AS_CASE(["$with_jemalloc"],
AC_DEFINE(JEMALLOC_MANGLE) [no],
with_jemalloc=yes [AC_MSG_ERROR([jemalloc requested but not found])],
[-l*], [
set dummy $with_jemalloc
LIBS="$2 $LIBS"
]) ])
AS_CASE(["$with_jemalloc"], AS_CASE(["$with_jemalloc"],
[yes], [*" with mangle"], [
[ AC_DEFINE(JEMALLOC_MANGLE)
])
AC_DEFINE(HAVE_MALLOC_CONF) AC_DEFINE(HAVE_MALLOC_CONF)
ac_cv_func_malloc_usable_size=yes ac_cv_func_malloc_usable_size=yes
], ]) # with_jemalloc
[no],
[AC_MSG_ERROR([jemalloc requested but not found])
])
])
dnl check for large file stuff dnl check for large file stuff
mv confdefs.h confdefs1.h mv confdefs.h confdefs1.h