]> Savannah Git Hosting - gnulib.git/commitdiff
rand: Use the usual patterns for overriding a function.
authorBruno Haible <bruno@clisp.org>
Tue, 21 Nov 2023 14:25:24 +0000 (15:25 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 21 Nov 2023 14:25:24 +0000 (15:25 +0100)
* lib/stdlib.in.h (RAND_MAX): Override also if module 'rand' is present.
(rand): New declaration.
* m4/stdlib_h.m4 (gl_STDLIB_H_REQUIRE_DEFAULTS): Initialize GNULIB_RAND.
(gl_STDLIB_H_DEFAULTS): Initialize REPLACE_RAND.
* modules/stdlib (Makefile.am): Substitute GNULIB_RAND and REPLACE_RAND.

ChangeLog
lib/stdlib.in.h
m4/stdlib_h.m4
modules/stdlib

index 713cee5183af7c0c26426a9f5f5f151aa6415bd0..aeed7eafea085863e4a275dc80ff1045e9b60891 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-11-21  Bruno Haible  <bruno@clisp.org>
+
+       rand: Use the usual patterns for overriding a function.
+       * lib/stdlib.in.h (RAND_MAX): Override also if module 'rand' is present.
+       (rand): New declaration.
+       * m4/stdlib_h.m4 (gl_STDLIB_H_REQUIRE_DEFAULTS): Initialize GNULIB_RAND.
+       (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_RAND.
+       * modules/stdlib (Makefile.am): Substitute GNULIB_RAND and REPLACE_RAND.
+
 2023-11-18  Bruno Haible  <bruno@clisp.org>
 
        nan, snan tests: Don't include these tests by default.
index b27d2c08c67abffca78bcea94ff52263d8ce0947..ea4c3e6b63e4d444f286421ceea18456a7d57a7b 100644 (file)
@@ -1122,11 +1122,26 @@ _GL_WARN_ON_USE (qsort_r, "qsort_r is not portable - "
 #endif
 
 
-#if @GNULIB_RANDOM_R@
-# if !@HAVE_RANDOM_R@
-#  ifndef RAND_MAX
-#   define RAND_MAX 2147483647
+#if @GNULIB_RAND@ || (@GNULIB_RANDOM_R@ && !@HAVE_RANDOM_R@)
+# ifndef RAND_MAX
+#  define RAND_MAX 2147483647
+# endif
+#endif
+
+
+#if @GNULIB_RAND@
+# if @REPLACE_RAND@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef rand
+#   define rand rpl_rand
 #  endif
+_GL_FUNCDECL_RPL (rand, int, (void));
+_GL_CXXALIAS_RPL (rand, int, (void));
+# else
+_GL_CXXALIAS_SYS (rand, int, (void));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (rand);
 # endif
 #endif
 
index f47c1eb37b3050c661f4ab74aba14c4221305826..6f9e992aef0228a950f9053d0dbb13a8042c2f53 100644 (file)
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 75
+# stdlib_h.m4 serial 76
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -134,6 +134,7 @@ AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS],
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTSNAME_R])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTENV])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_QSORT_R])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RAND])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM_R])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOCARRAY])
@@ -237,6 +238,7 @@ 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_RAND=0;            AC_SUBST([REPLACE_RAND])
   REPLACE_RANDOM=0;          AC_SUBST([REPLACE_RANDOM])
   REPLACE_RANDOM_R=0;        AC_SUBST([REPLACE_RANDOM_R])
   REPLACE_REALLOC_FOR_REALLOC_GNU=0;    AC_SUBST([REPLACE_REALLOC_FOR_REALLOC_GNU])
index 23229103e7fe5890e51bcea7cb1ad05b418bbefc..baf4b29a8c59e9f0b5384f997d41eea8e335f0da 100644 (file)
@@ -62,6 +62,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
              -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \
              -e 's/@''GNULIB_PUTENV''@/$(GNULIB_PUTENV)/g' \
              -e 's/@''GNULIB_QSORT_R''@/$(GNULIB_QSORT_R)/g' \
+             -e 's/@''GNULIB_RAND''@/$(GNULIB_RAND)/g' \
              -e 's/@''GNULIB_RANDOM''@/$(GNULIB_RANDOM)/g' \
              -e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \
              -e 's/@''GNULIB_REALLOC_GNU''@/$(GNULIB_REALLOC_GNU)/g' \
@@ -159,6 +160,7 @@ 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_RAND''@|$(REPLACE_RAND)|g' \
              -e 's|@''REPLACE_RANDOM''@|$(REPLACE_RANDOM)|g' \
              -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \
              -e 's|@''REPLACE_REALLOC_FOR_REALLOC_GNU''@|$(REPLACE_REALLOC_FOR_REALLOC_GNU)|g' \