random_r: Override incompatible API on AIX, OSF/1.
authorBruno Haible <bruno@clisp.org>
Thu, 12 Jan 2012 21:54:15 +0000 (22:54 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 12 Jan 2012 21:54:15 +0000 (22:54 +0100)
* lib/stdlib.in.h (random_r, srandom_r, initstate_r, setstate_r):
Override the system function if REPLACE_RANDOM_R is 1.
* m4/random_r.m4 (gl_FUNC_RANDOM_R): Require AC_CANONICAL_HOST. On AIX
and OSF/1, set REPLACE_RANDOM_R.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_RANDOM_R.
* modules/stdlib (Makefile.am): Substitute REPLACE_RANDOM_R.
* modules/random_r (configure.ac): Test REPLACE_RANDOM_R.
* doc/glibc-functions/initstate_r.texi: Mention the AIX, OSF/1 problem.
* doc/glibc-functions/random_r.texi: Likewise.
* doc/glibc-functions/setstate_r.texi: Likewise.

ChangeLog
doc/glibc-functions/initstate_r.texi
doc/glibc-functions/random_r.texi
doc/glibc-functions/setstate_r.texi
lib/stdlib.in.h
m4/random_r.m4
m4/stdlib_h.m4
modules/random_r
modules/stdlib

index 9a0a69a..d85e99a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2012-01-12  Bruno Haible  <bruno@clisp.org>
 
+       random_r: Override incompatible API on AIX, OSF/1.
+       * lib/stdlib.in.h (random_r, srandom_r, initstate_r, setstate_r):
+       Override the system function if REPLACE_RANDOM_R is 1.
+       * m4/random_r.m4 (gl_FUNC_RANDOM_R): Require AC_CANONICAL_HOST. On AIX
+       and OSF/1, set REPLACE_RANDOM_R.
+       * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_RANDOM_R.
+       * modules/stdlib (Makefile.am): Substitute REPLACE_RANDOM_R.
+       * modules/random_r (configure.ac): Test REPLACE_RANDOM_R.
+       * doc/glibc-functions/initstate_r.texi: Mention the AIX, OSF/1 problem.
+       * doc/glibc-functions/random_r.texi: Likewise.
+       * doc/glibc-functions/setstate_r.texi: Likewise.
+
        random_r: Support for MSVC 9.
        * lib/random_r.c: Include stdint.h, not inttypes.h.
 
index 03a90a2..2ad27b5 100644 (file)
@@ -9,6 +9,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 11 2011-11, Cygwin, mingw, MSVC 9, Interix 3.5.
+@item
+This function has an incompatible declaration on some platforms:
+AIX 7.1, OSF/1 5.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index ee1e692..cdd0b59 100644 (file)
@@ -9,6 +9,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 11 2011-11, Cygwin, mingw, MSVC 9, Interix 3.5.
+@item
+This function has an incompatible declaration on some platforms:
+AIX 7.1, OSF/1 5.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index c1a3a5a..a906724 100644 (file)
@@ -9,6 +9,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 11 2011-11, Cygwin, mingw, MSVC 9, Interix 3.5.
+@item
+This function has an incompatible declaration on some platforms:
+AIX 7.1, OSF/1 5.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index ea1c1c3..0a439e1 100644 (file)
@@ -58,7 +58,7 @@
 #  include <random.h>
 # endif
 
-# if !@HAVE_STRUCT_RANDOM_DATA@ || !@HAVE_RANDOM_R@
+# if !@HAVE_STRUCT_RANDOM_DATA@ || @REPLACE_RANDOM_R@ || !@HAVE_RANDOM_R@
 #  include <stdint.h>
 # endif
 
@@ -505,11 +505,21 @@ _GL_CXXALIASWARN (putenv);
 #endif
 
 #if @GNULIB_RANDOM_R@
-# if !@HAVE_RANDOM_R@
+# if @REPLACE_RANDOM_R@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef random_r
+#   define random_r rpl_random_r
+#  endif
+_GL_FUNCDECL_RPL (random_r, int, (struct random_data *buf, int32_t *result)
+                                 _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (random_r, int, (struct random_data *buf, int32_t *result));
+# else
+#  if !@HAVE_RANDOM_R@
 _GL_FUNCDECL_SYS (random_r, int, (struct random_data *buf, int32_t *result)
                                  _GL_ARG_NONNULL ((1, 2)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (random_r, int, (struct random_data *buf, int32_t *result));
+# endif
 _GL_CXXALIASWARN (random_r);
 #elif defined GNULIB_POSIXCHECK
 # undef random_r
@@ -520,13 +530,25 @@ _GL_WARN_ON_USE (random_r, "random_r is unportable - "
 #endif
 
 #if @GNULIB_RANDOM_R@
-# if !@HAVE_RANDOM_R@
+# if @REPLACE_RANDOM_R@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef srandom_r
+#   define srandom_r rpl_srandom_r
+#  endif
+_GL_FUNCDECL_RPL (srandom_r, int,
+                  (unsigned int seed, struct random_data *rand_state)
+                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (srandom_r, int,
+                  (unsigned int seed, struct random_data *rand_state));
+# else
+#  if !@HAVE_RANDOM_R@
 _GL_FUNCDECL_SYS (srandom_r, int,
                   (unsigned int seed, struct random_data *rand_state)
                   _GL_ARG_NONNULL ((2)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (srandom_r, int,
                   (unsigned int seed, struct random_data *rand_state));
+# endif
 _GL_CXXALIASWARN (srandom_r);
 #elif defined GNULIB_POSIXCHECK
 # undef srandom_r
@@ -537,15 +559,29 @@ _GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - "
 #endif
 
 #if @GNULIB_RANDOM_R@
-# if !@HAVE_RANDOM_R@
+# if @REPLACE_RANDOM_R@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef initstate_r
+#   define initstate_r rpl_initstate_r
+#  endif
+_GL_FUNCDECL_RPL (initstate_r, int,
+                  (unsigned int seed, char *buf, size_t buf_size,
+                   struct random_data *rand_state)
+                  _GL_ARG_NONNULL ((2, 4)));
+_GL_CXXALIAS_RPL (initstate_r, int,
+                  (unsigned int seed, char *buf, size_t buf_size,
+                   struct random_data *rand_state));
+# else
+#  if !@HAVE_RANDOM_R@
 _GL_FUNCDECL_SYS (initstate_r, int,
                   (unsigned int seed, char *buf, size_t buf_size,
                    struct random_data *rand_state)
                   _GL_ARG_NONNULL ((2, 4)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (initstate_r, int,
                   (unsigned int seed, char *buf, size_t buf_size,
                    struct random_data *rand_state));
+# endif
 _GL_CXXALIASWARN (initstate_r);
 #elif defined GNULIB_POSIXCHECK
 # undef initstate_r
@@ -556,13 +592,25 @@ _GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - "
 #endif
 
 #if @GNULIB_RANDOM_R@
-# if !@HAVE_RANDOM_R@
+# if @REPLACE_RANDOM_R@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef setstate_r
+#   define setstate_r rpl_setstate_r
+#  endif
+_GL_FUNCDECL_RPL (setstate_r, int,
+                  (char *arg_state, struct random_data *rand_state)
+                  _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (setstate_r, int,
+                  (char *arg_state, struct random_data *rand_state));
+# else
+#  if !@HAVE_RANDOM_R@
 _GL_FUNCDECL_SYS (setstate_r, int,
                   (char *arg_state, struct random_data *rand_state)
                   _GL_ARG_NONNULL ((1, 2)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (setstate_r, int,
                   (char *arg_state, struct random_data *rand_state));
+# endif
 _GL_CXXALIASWARN (setstate_r);
 #elif defined GNULIB_POSIXCHECK
 # undef setstate_r
index 7dddada..f8f863d 100644 (file)
@@ -1,4 +1,4 @@
-# serial 4
+# serial 5
 dnl Copyright (C) 2008-2012 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,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_RANDOM_R],
 [
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   AC_CHECK_HEADERS([random.h], [], [], [AC_INCLUDES_DEFAULT])
   if test $ac_cv_header_random_h = no; then
@@ -21,10 +22,19 @@ AC_DEFUN([gl_FUNC_RANDOM_R],
       #endif
     ]])
 
-  AC_CHECK_FUNCS([random_r])
-  if test $ac_cv_func_random_r = no; then
-    HAVE_RANDOM_R=0
-  fi
+  dnl On AIX and OSF/1, these functions exist, but with different declarations.
+  dnl Override them all.
+  case "$host_os" in
+    aix* | osf*)
+      REPLACE_RANDOM_R=1
+      ;;
+    *)
+      AC_CHECK_FUNCS([random_r])
+      if test $ac_cv_func_random_r = no; then
+        HAVE_RANDOM_R=0
+      fi
+      ;;
+  esac
 ])
 
 # Prerequisites of lib/random_r.c.
index bcb4cb8..85f7126 100644 (file)
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 39
+# stdlib_h.m4 serial 40
 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -101,6 +101,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   REPLACE_MKSTEMP=0;         AC_SUBST([REPLACE_MKSTEMP])
   REPLACE_PTSNAME_R=0;       AC_SUBST([REPLACE_PTSNAME_R])
   REPLACE_PUTENV=0;          AC_SUBST([REPLACE_PUTENV])
+  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])
index 41b9b8d..52a8842 100644 (file)
@@ -11,7 +11,7 @@ stdint
 
 configure.ac:
 gl_FUNC_RANDOM_R
-if test $HAVE_RANDOM_R = 0; then
+if test $HAVE_RANDOM_R = 0 || test $REPLACE_RANDOM_R = 1; then
   AC_LIBOBJ([random_r])
   gl_PREREQ_RANDOM_R
 fi
index 2beee3d..4633841 100644 (file)
@@ -95,6 +95,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
              -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
              -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
              -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|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' \