From b239920976585555781e8ed56ee8ba95ef2060f7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 14 May 2018 00:02:48 +0200 Subject: [PATCH] tsearch: Fix compilation error on Android. * lib/search.in.h (twalk): Declare when HAVE_TWALK, not HAVE_TSEARCH, is 0. (GNULIB_defined_tsearch, GNULIB_defined_twalk): New macros. * lib/tsearch.c (tsearch, tfind, tdelete): Define only if GNULIB_defined_tsearch is true. (twalk): Define only if GNULIB_defined_twalk is true. * modules/tsearch (configure.ac): Compile tsearch.c also if HAVE_TWALK is 0. * m4/tsearch.m4 (gl_FUNC_TSEARCH): Set HAVE_TWALK. * m4/search_h.m4 (gl_SEARCH_H_DEFAULTS): Initialize HAVE_TWALK. * modules/search (Makefile.am): Substitute HAVE_TWALK. --- ChangeLog | 15 +++++++++++++++ lib/search.in.h | 6 +++++- lib/tsearch.c | 8 ++++++++ m4/search_h.m4 | 3 ++- m4/tsearch.m4 | 7 +++++-- modules/search | 1 + modules/tsearch | 2 +- 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9dc6edb5e6..4dee31dfe6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2018-05-13 Bruno Haible + + tsearch: Fix compilation error on Android. + * lib/search.in.h (twalk): Declare when HAVE_TWALK, not HAVE_TSEARCH, + is 0. + (GNULIB_defined_tsearch, GNULIB_defined_twalk): New macros. + * lib/tsearch.c (tsearch, tfind, tdelete): Define only if + GNULIB_defined_tsearch is true. + (twalk): Define only if GNULIB_defined_twalk is true. + * modules/tsearch (configure.ac): Compile tsearch.c also if HAVE_TWALK + is 0. + * m4/tsearch.m4 (gl_FUNC_TSEARCH): Set HAVE_TWALK. + * m4/search_h.m4 (gl_SEARCH_H_DEFAULTS): Initialize HAVE_TWALK. + * modules/search (Makefile.am): Substitute HAVE_TWALK. + 2018-05-13 Bruno Haible imaxdiv: Fix compilation error on Android. diff --git a/lib/search.in.h b/lib/search.in.h index ce0a0fdb0d..47a4460c80 100644 --- a/lib/search.in.h +++ b/lib/search.in.h @@ -169,7 +169,7 @@ _GL_FUNCDECL_RPL (twalk, void, _GL_CXXALIAS_RPL (twalk, void, (const void *vroot, _gl_search_action_fn action)); # else -# if !@HAVE_TSEARCH@ +# if !@HAVE_TWALK@ _GL_FUNCDECL_SYS (twalk, void, (const void *vroot, _gl_search_action_fn action) _GL_ARG_NONNULL ((2))); @@ -179,6 +179,10 @@ _GL_CXXALIAS_SYS (twalk, void, # endif _GL_CXXALIASWARN (twalk); +/* Flags used by tsearch.c. */ +# define GNULIB_defined_tsearch (@REPLACE_TSEARCH@ || !@HAVE_TSEARCH@) +# define GNULIB_defined_twalk (@REPLACE_TSEARCH@ || !@HAVE_TWALK@) + #elif defined GNULIB_POSIXCHECK # undef tsearch # if HAVE_RAW_DECL_TSEARCH diff --git a/lib/tsearch.c b/lib/tsearch.c index bce1e9f0f6..dabd760631 100644 --- a/lib/tsearch.c +++ b/lib/tsearch.c @@ -174,6 +174,8 @@ check_tree (node root) #endif +#if GNULIB_defined_tsearch + /* Possibly "split" a node with two red successors, and/or fix up two red edges in a row. ROOTP is a pointer to the lowest node we visited, PARENTP and GPARENTP pointers to its parent/grandparent. P_R and GP_R contain the @@ -612,6 +614,10 @@ __tdelete (const void *key, void **vrootp, __compar_fn_t compar) weak_alias (__tdelete, tdelete) #endif +#endif /* GNULIB_defined_tsearch */ + + +#if GNULIB_defined_twalk /* Walk the nodes of a tree. ROOT is the root of the tree to be walked, ACTION the function to be @@ -654,6 +660,8 @@ __twalk (const void *vroot, __action_fn_t action) weak_alias (__twalk, twalk) #endif +#endif /* GNULIB_defined_twalk */ + #ifdef _LIBC diff --git a/m4/search_h.m4 b/m4/search_h.m4 index d2f7263ced..66fe46431b 100644 --- a/m4/search_h.m4 +++ b/m4/search_h.m4 @@ -1,4 +1,4 @@ -# search_h.m4 serial 9 +# search_h.m4 serial 10 dnl Copyright (C) 2007-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -56,5 +56,6 @@ AC_DEFUN([gl_SEARCH_H_DEFAULTS], GNULIB_TSEARCH=0; AC_SUBST([GNULIB_TSEARCH]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_TSEARCH=1; AC_SUBST([HAVE_TSEARCH]) + HAVE_TWALK=1; AC_SUBST([HAVE_TWALK]) REPLACE_TSEARCH=0; AC_SUBST([REPLACE_TSEARCH]) ]) diff --git a/m4/tsearch.m4 b/m4/tsearch.m4 index 87d0d90c74..82350c9761 100644 --- a/m4/tsearch.m4 +++ b/m4/tsearch.m4 @@ -1,4 +1,4 @@ -# tsearch.m4 serial 7 +# tsearch.m4 serial 8 dnl Copyright (C) 2006-2018 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_TSEARCH], [ AC_REQUIRE([gl_SEARCH_H_DEFAULTS]) - AC_CHECK_FUNCS([tsearch]) + AC_CHECK_FUNCS([tsearch twalk]) if test $ac_cv_func_tsearch = yes; then dnl On OpenBSD 4.0, the return value of tdelete() is incorrect. AC_REQUIRE([AC_PROG_CC]) @@ -53,6 +53,9 @@ main () else HAVE_TSEARCH=0 fi + if test $ac_cv_func_twalk != yes; then + HAVE_TWALK=0 + fi ]) # Prerequisites of lib/tsearch.c. diff --git a/modules/search b/modules/search index 70536ea5a9..72dbe12a1b 100644 --- a/modules/search +++ b/modules/search @@ -31,6 +31,7 @@ search.h: search.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''HAVE_TYPE_VISIT''@|$(HAVE_TYPE_VISIT)|g' \ -e 's/@''GNULIB_TSEARCH''@/$(GNULIB_TSEARCH)/g' \ -e 's|@''HAVE_TSEARCH''@|$(HAVE_TSEARCH)|g' \ + -e 's|@''HAVE_TWALK''@|$(HAVE_TWALK)|g' \ -e 's|@''REPLACE_TSEARCH''@|$(REPLACE_TSEARCH)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ diff --git a/modules/tsearch b/modules/tsearch index ffb952b8c1..4a2b5ed230 100644 --- a/modules/tsearch +++ b/modules/tsearch @@ -10,7 +10,7 @@ search configure.ac: gl_FUNC_TSEARCH -if test $HAVE_TSEARCH = 0 || test $REPLACE_TSEARCH = 1; then +if test $HAVE_TSEARCH = 0 || test $HAVE_TWALK = 0 || test $REPLACE_TSEARCH = 1; then AC_LIBOBJ([tsearch]) gl_PREREQ_TSEARCH fi -- 2.39.5