changeset 39379:5530508745d3

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.
author Bruno Haible <bruno@clisp.org>
date Mon, 14 May 2018 00:02:48 +0200
parents a24cbc969ed9
children 0340fadfd052
files ChangeLog lib/search.in.h lib/tsearch.c m4/search_h.m4 m4/tsearch.m4 modules/search modules/tsearch
diffstat 7 files changed, 37 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun May 13 23:23:47 2018 +0200
+++ b/ChangeLog	Mon May 14 00:02:48 2018 +0200
@@ -1,3 +1,18 @@
+2018-05-13  Bruno Haible  <bruno@clisp.org>
+
+	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  <bruno@clisp.org>
 
 	imaxdiv: Fix compilation error on Android.
--- a/lib/search.in.h	Sun May 13 23:23:47 2018 +0200
+++ b/lib/search.in.h	Mon May 14 00:02:48 2018 +0200
@@ -169,7 +169,7 @@
 _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 @@
 # 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
--- a/lib/tsearch.c	Sun May 13 23:23:47 2018 +0200
+++ b/lib/tsearch.c	Mon May 14 00:02:48 2018 +0200
@@ -174,6 +174,8 @@
 
 #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 @@
 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 @@
 weak_alias (__twalk, twalk)
 #endif
 
+#endif /* GNULIB_defined_twalk */
+
 
 #ifdef _LIBC
 
--- a/m4/search_h.m4	Sun May 13 23:23:47 2018 +0200
+++ b/m4/search_h.m4	Mon May 14 00:02:48 2018 +0200
@@ -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 @@
   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])
 ])
--- a/m4/tsearch.m4	Sun May 13 23:23:47 2018 +0200
+++ b/m4/tsearch.m4	Mon May 14 00:02:48 2018 +0200
@@ -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 @@
 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 @@
   else
     HAVE_TSEARCH=0
   fi
+  if test $ac_cv_func_twalk != yes; then
+    HAVE_TWALK=0
+  fi
 ])
 
 # Prerequisites of lib/tsearch.c.
--- a/modules/search	Sun May 13 23:23:47 2018 +0200
+++ b/modules/search	Mon May 14 00:02:48 2018 +0200
@@ -31,6 +31,7 @@
 	      -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)' \
--- a/modules/tsearch	Sun May 13 23:23:47 2018 +0200
+++ b/modules/tsearch	Mon May 14 00:02:48 2018 +0200
@@ -10,7 +10,7 @@
 
 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