>From de9ed4e371d8bde6c2fd47ca9612ed150da51c10 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 25 Jan 2019 01:36:26 +0100 Subject: [PATCH 7/7] 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. --- ChangeLog | 20 ++++++++++++++ doc/posix-functions/rand.texi | 2 +- doc/posix-functions/random.texi | 7 ++++- doc/posix-functions/srand.texi | 2 +- doc/posix-functions/srandom.texi | 5 +++- lib/stdlib.in.h | 59 +++++++++++++++++++++++++++++++++------- m4/random.m4 | 23 +++++++++++++++- m4/stdlib_h.m4 | 7 ++++- modules/random | 8 +++--- modules/stdlib | 5 ++++ 10 files changed, 118 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24d5755..cd89cc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,25 @@ 2019-01-24 Bruno Haible + 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 + mbtowc: Fix compilation error on Android 4.3. * lib/stdlib.in.h (mbtowc): Test also HAVE_MBTOWC. * m4/mbtowc.m4 (gl_FUNC_MBTOWC): Test whether mbtowc exists. Set diff --git a/doc/posix-functions/rand.texi b/doc/posix-functions/rand.texi index d8446ea..decf1fc 100644 --- a/doc/posix-functions/rand.texi +++ b/doc/posix-functions/rand.texi @@ -13,6 +13,6 @@ Portability problems fixed by Gnulib: 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 diff --git a/doc/posix-functions/random.texi b/doc/posix-functions/random.texi index 9280102..36b5857 100644 --- a/doc/posix-functions/random.texi +++ b/doc/posix-functions/random.texi @@ -10,7 +10,12 @@ Portability problems fixed by Gnulib: @itemize @item This function is missing on some platforms: -Solaris 2.4, mingw, MSVC 14, Android 4.4. +Solaris 2.4, mingw, MSVC 14. address@hidden +This function is only defined as an inline function on some platforms: +Android 4.4. address@hidden + @end itemize Portability problems not fixed by Gnulib: diff --git a/doc/posix-functions/srand.texi b/doc/posix-functions/srand.texi index 344f631..5a6e6b7 100644 --- a/doc/posix-functions/srand.texi +++ b/doc/posix-functions/srand.texi @@ -13,6 +13,6 @@ Portability problems fixed by Gnulib: 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 diff --git a/doc/posix-functions/srandom.texi b/doc/posix-functions/srandom.texi index 7c3292a..09d033e 100644 --- a/doc/posix-functions/srandom.texi +++ b/doc/posix-functions/srandom.texi @@ -10,7 +10,10 @@ Portability problems fixed by Gnulib: @itemize @item This function is missing on some platforms: -Solaris 2.4, mingw, MSVC 14, Android 4.4. +Solaris 2.4, mingw, MSVC 14. address@hidden +This function is only defined as an inline function on some platforms: +Android 4.4. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 0f581d9..be8ab3b 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -582,10 +582,19 @@ _GL_WARN_ON_USE (qsort_r, "qsort_r is not portable - " #if @GNULIB_RANDOM@ -# if address@hidden@ +# 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 address@hidden@ _GL_FUNCDECL_SYS (random, long, (void)); -# endif +# endif _GL_CXXALIAS_SYS (random, long, (void)); +# endif _GL_CXXALIASWARN (random); #elif defined GNULIB_POSIXCHECK # undef random @@ -596,10 +605,19 @@ _GL_WARN_ON_USE (random, "random is unportable - " #endif #if @GNULIB_RANDOM@ -# if address@hidden@ +# 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 address@hidden@ _GL_FUNCDECL_SYS (srandom, void, (unsigned int seed)); -# endif +# endif _GL_CXXALIAS_SYS (srandom, void, (unsigned int seed)); +# endif _GL_CXXALIASWARN (srandom); #elif defined GNULIB_POSIXCHECK # undef srandom @@ -610,31 +628,52 @@ _GL_WARN_ON_USE (srandom, "srandom is unportable - " #endif #if @GNULIB_RANDOM@ -# if address@hidden@ || address@hidden@ +# 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 address@hidden@ || address@hidden@ _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 address@hidden@ || address@hidden@ +# 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 address@hidden@ || address@hidden@ _GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1))); -# endif +# endif _GL_CXXALIAS_SYS (setstate, char *, (char *arg_state)); +# endif _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 diff --git a/m4/random.m4 b/m4/random.m4 index 996c406..15da67e 100644 --- a/m4/random.m4 +++ b/m4/random.m4 @@ -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 @@ AC_DEFUN([gl_FUNC_RANDOM], ]) 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]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index c449a54..c5db804 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -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 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], 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 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], 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 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], 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 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], 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]) diff --git a/modules/random b/modules/random index 706096b..e58ebd1 100644 --- a/modules/random +++ b/modules/random @@ -6,14 +6,14 @@ lib/random.c 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 diff --git a/modules/stdlib b/modules/stdlib index dd1556e..a43f79c 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -72,6 +72,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -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 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -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 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -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 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -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' \ -- 2.7.4