changeset 40134:cfcc57a4ed05

random: Fix compilation error on Android 4.3. * lib/stdlib.in.h (random, srandom): Test also REPLACE_RANDOM. (initstate): Test REPLACE_INITSTATE and HAVE_INITSTATE, not HAVE_RANDOM. (setstate): Test REPLACE_SETSTATE and HAVE_SETSTATE, not HAVE_RANDOM. * m4/random.m4 (gl_FUNC_RANDOM): Set HAVE_INITSTATE, HAVE_SETSTATE, REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_INITSTATE, HAVE_SETSTATE, REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE. * modules/stdlib (Makefile.am): Substitute HAVE_INITSTATE, HAVE_SETSTATE, REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE. * modules/random (Depends-on, configure.ac): Test also REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE. * doc/posix-functions/random.texi: Correct the description of the situation on Android. * doc/posix-functions/srandom.texi: Likewise. * doc/posix-functions/rand.texi: Likewise. * doc/posix-functions/srand.texi: Likewise.
author Bruno Haible <bruno@clisp.org>
date Fri, 25 Jan 2019 01:36:26 +0100
parents 11b97647fb11
children f03dfb30b48c
files ChangeLog doc/posix-functions/rand.texi doc/posix-functions/random.texi doc/posix-functions/srand.texi doc/posix-functions/srandom.texi lib/stdlib.in.h m4/random.m4 m4/stdlib_h.m4 modules/random modules/stdlib
diffstat 10 files changed, 118 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jan 25 00:42:40 2019 +0100
+++ b/ChangeLog	Fri Jan 25 01:36:26 2019 +0100
@@ -1,3 +1,23 @@
+2019-01-24  Bruno Haible  <bruno@clisp.org>
+
+	random: Fix compilation error on Android 4.3.
+	* lib/stdlib.in.h (random, srandom): Test also REPLACE_RANDOM.
+	(initstate): Test REPLACE_INITSTATE and HAVE_INITSTATE, not HAVE_RANDOM.
+	(setstate): Test REPLACE_SETSTATE and HAVE_SETSTATE, not HAVE_RANDOM.
+	* m4/random.m4 (gl_FUNC_RANDOM): Set HAVE_INITSTATE, HAVE_SETSTATE,
+	REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_INITSTATE,
+	HAVE_SETSTATE, REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* modules/stdlib (Makefile.am): Substitute HAVE_INITSTATE, HAVE_SETSTATE,
+	REPLACE_RANDOM, REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* modules/random (Depends-on, configure.ac): Test also REPLACE_RANDOM,
+	REPLACE_INITSTATE, REPLACE_SETSTATE.
+	* doc/posix-functions/random.texi: Correct the description of the
+	situation on Android.
+	* doc/posix-functions/srandom.texi: Likewise.
+	* doc/posix-functions/rand.texi: Likewise.
+	* doc/posix-functions/srand.texi: Likewise.
+
 2019-01-24  Bruno Haible  <bruno@clisp.org>
 
 	mbtowc: Fix compilation error on Android 4.3.
--- a/doc/posix-functions/rand.texi	Fri Jan 25 00:42:40 2019 +0100
+++ b/doc/posix-functions/rand.texi	Fri Jan 25 01:36:26 2019 +0100
@@ -13,6 +13,6 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
+This function is only defined as an inline function on some platforms:
 Android 4.4.
 @end itemize
--- a/doc/posix-functions/random.texi	Fri Jan 25 00:42:40 2019 +0100
+++ b/doc/posix-functions/random.texi	Fri Jan 25 01:36:26 2019 +0100
@@ -10,7 +10,12 @@
 @itemize
 @item
 This function is missing on some platforms:
-Solaris 2.4, mingw, MSVC 14, Android 4.4.
+Solaris 2.4, mingw, MSVC 14.
+@item
+This function is only defined as an inline function on some platforms:
+Android 4.4.
+@item
+
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/posix-functions/srand.texi	Fri Jan 25 00:42:40 2019 +0100
+++ b/doc/posix-functions/srand.texi	Fri Jan 25 01:36:26 2019 +0100
@@ -13,6 +13,6 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
+This function is only defined as an inline function on some platforms:
 Android 4.4.
 @end itemize
--- a/doc/posix-functions/srandom.texi	Fri Jan 25 00:42:40 2019 +0100
+++ b/doc/posix-functions/srandom.texi	Fri Jan 25 01:36:26 2019 +0100
@@ -10,7 +10,10 @@
 @itemize
 @item
 This function is missing on some platforms:
-Solaris 2.4, mingw, MSVC 14, Android 4.4.
+Solaris 2.4, mingw, MSVC 14.
+@item
+This function is only defined as an inline function on some platforms:
+Android 4.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/lib/stdlib.in.h	Fri Jan 25 00:42:40 2019 +0100
+++ b/lib/stdlib.in.h	Fri Jan 25 01:36:26 2019 +0100
@@ -582,10 +582,19 @@
 
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@
+# if @REPLACE_RANDOM@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef random
+#   define random rpl_random
+#  endif
+_GL_FUNCDECL_RPL (random, long, (void));
+_GL_CXXALIAS_RPL (random, long, (void));
+# else
+#  if !@HAVE_RANDOM@
 _GL_FUNCDECL_SYS (random, long, (void));
+#  endif
+_GL_CXXALIAS_SYS (random, long, (void));
 # endif
-_GL_CXXALIAS_SYS (random, long, (void));
 _GL_CXXALIASWARN (random);
 #elif defined GNULIB_POSIXCHECK
 # undef random
@@ -596,10 +605,19 @@
 #endif
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@
+# if @REPLACE_RANDOM@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef srandom
+#   define srandom rpl_srandom
+#  endif
+_GL_FUNCDECL_RPL (srandom, void, (unsigned int seed));
+_GL_CXXALIAS_RPL (srandom, void, (unsigned int seed));
+# else
+#  if !@HAVE_RANDOM@
 _GL_FUNCDECL_SYS (srandom, void, (unsigned int seed));
+#  endif
+_GL_CXXALIAS_SYS (srandom, void, (unsigned int seed));
 # endif
-_GL_CXXALIAS_SYS (srandom, void, (unsigned int seed));
 _GL_CXXALIASWARN (srandom);
 #elif defined GNULIB_POSIXCHECK
 # undef srandom
@@ -610,31 +628,52 @@
 #endif
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@ || !@HAVE_DECL_INITSTATE@
+# if @REPLACE_INITSTATE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef initstate
+#   define initstate rpl_initstate
+#  endif
+_GL_FUNCDECL_RPL (initstate, char *,
+                  (unsigned int seed, char *buf, size_t buf_size)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (initstate, char *,
+                  (unsigned int seed, char *buf, size_t buf_size));
+# else
+#  if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
 _GL_FUNCDECL_SYS (initstate, char *,
                   (unsigned int seed, char *buf, size_t buf_size)
                   _GL_ARG_NONNULL ((2)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (initstate, char *,
                   (unsigned int seed, char *buf, size_t buf_size));
+# endif
 _GL_CXXALIASWARN (initstate);
 #elif defined GNULIB_POSIXCHECK
 # undef initstate
-# if HAVE_RAW_DECL_INITSTATE_R
+# if HAVE_RAW_DECL_INITSTATE
 _GL_WARN_ON_USE (initstate, "initstate is unportable - "
                  "use gnulib module random for portability");
 # endif
 #endif
 
 #if @GNULIB_RANDOM@
-# if !@HAVE_RANDOM@ || !@HAVE_DECL_SETSTATE@
+# if @REPLACE_SETSTATE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef setstate
+#   define setstate rpl_setstate
+#  endif
+_GL_FUNCDECL_RPL (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (setstate, char *, (char *arg_state));
+# else
+#  if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
 _GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
+#  endif
+_GL_CXXALIAS_SYS (setstate, char *, (char *arg_state));
 # endif
-_GL_CXXALIAS_SYS (setstate, char *, (char *arg_state));
 _GL_CXXALIASWARN (setstate);
 #elif defined GNULIB_POSIXCHECK
 # undef setstate
-# if HAVE_RAW_DECL_SETSTATE_R
+# if HAVE_RAW_DECL_SETSTATE
 _GL_WARN_ON_USE (setstate, "setstate is unportable - "
                  "use gnulib module random for portability");
 # endif
--- a/m4/random.m4	Fri Jan 25 00:42:40 2019 +0100
+++ b/m4/random.m4	Fri Jan 25 01:36:26 2019 +0100
@@ -1,4 +1,4 @@
-# random.m4 serial 3
+# random.m4 serial 4
 dnl Copyright (C) 2012-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -21,6 +21,27 @@
     ])
   if test $gl_cv_func_random = no; then
     HAVE_RANDOM=0
+    HAVE_INITSTATE=0
+    HAVE_SETSTATE=0
+  else
+    AC_CHECK_FUNCS([initstate setstate])
+    if test $ac_cv_func_initstate = no; then
+      HAVE_INITSTATE=0
+    fi
+    if test $ac_cv_func_setstate = no; then
+      HAVE_SETSTATE=0
+    fi
+    if test $ac_cv_func_initstate = no || test $ac_cv_func_setstate = no; then
+      dnl In order to define initstate or setstate, we need to define all the
+      dnl functions at once.
+      REPLACE_RANDOM=1
+      if test $ac_cv_func_initstate = yes; then
+        REPLACE_INITSTATE=1
+      fi
+      if test $ac_cv_func_setstate = yes; then
+        REPLACE_SETSTATE=1
+      fi
+    fi
   fi
 
   AC_CHECK_DECLS_ONCE([initstate])
--- a/m4/stdlib_h.m4	Fri Jan 25 00:42:40 2019 +0100
+++ b/m4/stdlib_h.m4	Fri Jan 25 01:36:26 2019 +0100
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 46
+# stdlib_h.m4 serial 47
 dnl Copyright (C) 2007-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -81,6 +81,7 @@
   HAVE_DECL_GETLOADAVG=1;    AC_SUBST([HAVE_DECL_GETLOADAVG])
   HAVE_GETSUBOPT=1;          AC_SUBST([HAVE_GETSUBOPT])
   HAVE_GRANTPT=1;            AC_SUBST([HAVE_GRANTPT])
+  HAVE_INITSTATE=1;          AC_SUBST([HAVE_INITSTATE])
   HAVE_DECL_INITSTATE=1;     AC_SUBST([HAVE_DECL_INITSTATE])
   HAVE_MBTOWC=1;             AC_SUBST([HAVE_MBTOWC])
   HAVE_MKDTEMP=1;            AC_SUBST([HAVE_MKDTEMP])
@@ -101,6 +102,7 @@
   HAVE_SECURE_GETENV=1;      AC_SUBST([HAVE_SECURE_GETENV])
   HAVE_SETENV=1;             AC_SUBST([HAVE_SETENV])
   HAVE_DECL_SETENV=1;        AC_SUBST([HAVE_DECL_SETENV])
+  HAVE_SETSTATE=1;           AC_SUBST([HAVE_SETSTATE])
   HAVE_DECL_SETSTATE=1;      AC_SUBST([HAVE_DECL_SETSTATE])
   HAVE_STRTOD=1;             AC_SUBST([HAVE_STRTOD])
   HAVE_STRTOLL=1;            AC_SUBST([HAVE_STRTOLL])
@@ -111,6 +113,7 @@
   HAVE_DECL_UNSETENV=1;      AC_SUBST([HAVE_DECL_UNSETENV])
   REPLACE_CALLOC=0;          AC_SUBST([REPLACE_CALLOC])
   REPLACE_CANONICALIZE_FILE_NAME=0;  AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
+  REPLACE_INITSTATE=0;       AC_SUBST([REPLACE_INITSTATE])
   REPLACE_MALLOC=0;          AC_SUBST([REPLACE_MALLOC])
   REPLACE_MBTOWC=0;          AC_SUBST([REPLACE_MBTOWC])
   REPLACE_MKSTEMP=0;         AC_SUBST([REPLACE_MKSTEMP])
@@ -118,10 +121,12 @@
   REPLACE_PTSNAME_R=0;       AC_SUBST([REPLACE_PTSNAME_R])
   REPLACE_PUTENV=0;          AC_SUBST([REPLACE_PUTENV])
   REPLACE_QSORT_R=0;         AC_SUBST([REPLACE_QSORT_R])
+  REPLACE_RANDOM=0;          AC_SUBST([REPLACE_RANDOM])
   REPLACE_RANDOM_R=0;        AC_SUBST([REPLACE_RANDOM_R])
   REPLACE_REALLOC=0;         AC_SUBST([REPLACE_REALLOC])
   REPLACE_REALPATH=0;        AC_SUBST([REPLACE_REALPATH])
   REPLACE_SETENV=0;          AC_SUBST([REPLACE_SETENV])
+  REPLACE_SETSTATE=0;        AC_SUBST([REPLACE_SETSTATE])
   REPLACE_STRTOD=0;          AC_SUBST([REPLACE_STRTOD])
   REPLACE_UNSETENV=0;        AC_SUBST([REPLACE_UNSETENV])
   REPLACE_WCTOMB=0;          AC_SUBST([REPLACE_WCTOMB])
--- a/modules/random	Fri Jan 25 00:42:40 2019 +0100
+++ b/modules/random	Fri Jan 25 01:36:26 2019 +0100
@@ -6,14 +6,14 @@
 m4/random.m4
 
 Depends-on:
-libc-config     [test $HAVE_RANDOM = 0]
+libc-config     [test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1]
 stdlib
-stdint          [test $HAVE_RANDOM = 0]
-random_r        [test $HAVE_RANDOM = 0]
+stdint          [test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1]
+random_r        [test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1]
 
 configure.ac:
 gl_FUNC_RANDOM
-if test $HAVE_RANDOM = 0; then
+if test $HAVE_RANDOM = 0 || test $REPLACE_RANDOM = 1 || test $REPLACE_INITSTATE = 1 || test $REPLACE_SETSTATE = 1; then
   AC_LIBOBJ([random])
   gl_PREREQ_RANDOM
 fi
--- a/modules/stdlib	Fri Jan 25 00:42:40 2019 +0100
+++ b/modules/stdlib	Fri Jan 25 01:36:26 2019 +0100
@@ -72,6 +72,7 @@
 	      -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
 	      -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
 	      -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
+	      -e 's|@''HAVE_INITSTATE''@|$(HAVE_INITSTATE)|g' \
 	      -e 's|@''HAVE_DECL_INITSTATE''@|$(HAVE_DECL_INITSTATE)|g' \
 	      -e 's|@''HAVE_MBTOWC''@|$(HAVE_MBTOWC)|g' \
 	      -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
@@ -91,6 +92,7 @@
 	      -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
 	      -e 's|@''HAVE_SECURE_GETENV''@|$(HAVE_SECURE_GETENV)|g' \
 	      -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \
+	      -e 's|@''HAVE_SETSTATE''@|$(HAVE_SETSTATE)|g' \
 	      -e 's|@''HAVE_DECL_SETSTATE''@|$(HAVE_DECL_SETSTATE)|g' \
 	      -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
 	      -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
@@ -101,6 +103,7 @@
 	      -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
 	      -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
 	      -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
+	      -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
 	      -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
 	      -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
 	      -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
@@ -108,10 +111,12 @@
 	      -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
 	      -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
 	      -e 's|@''REPLACE_QSORT_R''@|$(REPLACE_QSORT_R)|g' \
+	      -e 's|@''REPLACE_RANDOM''@|$(REPLACE_RANDOM)|g' \
 	      -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \
 	      -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
 	      -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
 	      -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
+	      -e 's|@''REPLACE_SETSTATE''@|$(REPLACE_SETSTATE)|g' \
 	      -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
 	      -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
 	      -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \