Skip to content

Commit

Permalink
Refactor --with-jemalloc option
Browse files Browse the repository at this point in the history
Find jemalloc header first, then using the found header, try [with
mangle, without mangle] x [no more additional libraries, adding
jemalloc] combination.
  • Loading branch information
nobu committed Jul 7, 2021
1 parent 82d4255 commit e8d9539
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions configure.ac
Expand Up @@ -1297,45 +1297,53 @@ AC_ARG_WITH([jemalloc],
[AS_HELP_STRING([--with-jemalloc],[use jemalloc allocator])],
[with_jemalloc=$withval], [with_jemalloc=no])
AS_IF([test "x$with_jemalloc" != xno],[
AC_SEARCH_LIBS([malloc_conf], [jemalloc],
[
AC_DEFINE(HAVE_LIBJEMALLOC, 1)
with_jemalloc=yes
],
[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
# find jemalloc header first
malloc_header=
AC_CHECK_HEADER(jemalloc/jemalloc.h, [malloc_header=jemalloc/jemalloc.h], [
AC_CHECK_HEADER(jemalloc.h, [malloc_header=jemalloc.h])
])
AS_IF([test "$malloc_header" != ""], [
AC_DEFINE_UNQUOTED(RUBY_ALTERNATIVE_MALLOC_HEADER, [<$malloc_header>])
],
[test x$with_jemalloc = xyes && with_jemalloc=no])
AS_IF([test "x$with_jemalloc" != xyes], [
AC_CACHE_CHECK([for jemalloc with JEMALLOC_MANGLE], rb_cv_jemalloc_demangle,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@define JEMALLOC_MANGLE 1
@%:@ifdef RUBY_ALTERNATIVE_MALLOC_HEADER
@%:@include RUBY_ALTERNATIVE_MALLOC_HEADER
@%:@else
extern const char *malloc_conf;
@%:@endif], [return !&malloc_conf])],
[rb_cv_jemalloc_demangle=yes],
[rb_cv_jemalloc_demangle=no])
])
])
AS_IF([test "x$rb_cv_jemalloc_demangle" = xyes], [
AC_DEFINE(JEMALLOC_MANGLE)
with_jemalloc=yes
save_LIBS="$LIBS"
AC_CACHE_CHECK([for jemalloc library], rb_cv_jemalloc_library, [
rb_cv_jemalloc_library=no
# 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
@%:@include RUBY_ALTERNATIVE_MALLOC_HEADER
@%:@else
extern const char *malloc_conf;
@%:@endif],
[/* access at runtime not to be optimized away */
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_CASE(["$with_jemalloc"],
[yes],
[
AC_DEFINE(HAVE_MALLOC_CONF)
ac_cv_func_malloc_usable_size=yes
],
[no],
[AC_MSG_ERROR([jemalloc requested but not found])
[no],
[AC_MSG_ERROR([jemalloc requested but not found])],
[-l*], [
set dummy $with_jemalloc
LIBS="$2 $LIBS"
])
])
AS_CASE(["$with_jemalloc"],
[*" with mangle"], [
AC_DEFINE(JEMALLOC_MANGLE)
])
AC_DEFINE(HAVE_MALLOC_CONF)
ac_cv_func_malloc_usable_size=yes
]) # with_jemalloc

dnl check for large file stuff
mv confdefs.h confdefs1.h
Expand Down

0 comments on commit e8d9539

Please sign in to comment.