bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

random: workaround old Cygwin bug


From: Bruno Haible
Subject: random: workaround old Cygwin bug
Date: Thu, 17 Aug 2017 19:07:02 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-91-generic; KDE/5.18.0; x86_64; ; )

Althrough I don't want to spent time fixing normal bugs seen on old
Cygwin 1.5.25, this one is a compilation error:

../../gltests/test-random.c:22: warning: initialization from incompatible 
pointer type
../../gltests/test-random.c:23: error: `initstate' undeclared here (not in a 
function)
../../gltests/test-random.c:24: error: `setstate' undeclared here (not in a 
function)
../../gltests/test-random.c:25: warning: initialization from incompatible 
pointer type
../../gltests/test-random.c: In function `main':
../../gltests/test-random.c:38: warning: implicit declaration of function 
`initstate'
make[4]: *** [test-random.o] Error 1

Caused by missing declarations of initstate() and setstate() in 
/usr/include/cygwin/stdlib.h.

This patch fixes it.


2017-08-17  Bruno Haible  <address@hidden>

        random: Fix test compilation failure on Cygwin 1.5.25.
        * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_DECL_INITSTATE,
        HAVE_DECL_SETSTATE.
        * m4/random.m4 (gl_FUNC_RANDOM): Test whether initstate and setstate are
        declared.
        * modules/stdlib (Makefile.am): Substitute HAVE_DECL_INITSTATE,
        HAVE_DECL_SETSTATE.
        * lib/stdlib.in.h (initstate): Declare also if HAVE_DECL_INITSTATE is 0.
        (setstate): Declare also if HAVE_DECL_SETSTATE is 0.
        * doc/posix-functions/initstate.texi: Mention the Cygwin 1.5.x problem.
        * doc/posix-functions/random.texi: Likewise.
        * doc/posix-functions/setstate.texi: Likewise.
        * doc/posix-functions/srandom.texi: Likewise.

diff --git a/doc/posix-functions/initstate.texi 
b/doc/posix-functions/initstate.texi
index aca7e7b..0ddfebf 100644
--- a/doc/posix-functions/initstate.texi
+++ b/doc/posix-functions/initstate.texi
@@ -11,6 +11,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Solaris 2.4, mingw, MSVC 14.
address@hidden
+This function is not declared on some platforms:
+Cygwin 1.5.25.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/doc/posix-functions/random.texi b/doc/posix-functions/random.texi
index 93093df..88d36f9 100644
--- a/doc/posix-functions/random.texi
+++ b/doc/posix-functions/random.texi
@@ -15,4 +15,8 @@ Solaris 2.4, mingw, MSVC 14.
 
 Portability problems not fixed by Gnulib:
 @itemize
address@hidden
+This function has a slightly incompatible declaration (the return type being
address@hidden instead of @samp{long}) on some platforms:
+Cygwin 1.5.25.
 @end itemize
diff --git a/doc/posix-functions/setstate.texi 
b/doc/posix-functions/setstate.texi
index bc4a01e..2393574 100644
--- a/doc/posix-functions/setstate.texi
+++ b/doc/posix-functions/setstate.texi
@@ -11,6 +11,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Solaris 2.4, mingw, MSVC 14.
address@hidden
+This function is not declared on some platforms:
+Cygwin 1.5.25.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/doc/posix-functions/srandom.texi b/doc/posix-functions/srandom.texi
index db0eaef..74770f7 100644
--- a/doc/posix-functions/srandom.texi
+++ b/doc/posix-functions/srandom.texi
@@ -15,4 +15,8 @@ Solaris 2.4, mingw, MSVC 14.
 
 Portability problems not fixed by Gnulib:
 @itemize
address@hidden
+This function has a slightly incompatible declaration (the return type being
address@hidden instead of @samp{void) on some platforms:
+Cygwin 1.5.25.
 @end itemize
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index c6e68fd..ef41c99 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -597,7 +597,7 @@ _GL_WARN_ON_USE (srandom, "srandom is unportable - "
 #endif
 
 #if @GNULIB_RANDOM@
-# if address@hidden@
+# if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (initstate, char *,
                   (unsigned int seed, char *buf, size_t buf_size)
                   _GL_ARG_NONNULL ((2)));
@@ -614,7 +614,7 @@ _GL_WARN_ON_USE (initstate, "initstate is unportable - "
 #endif
 
 #if @GNULIB_RANDOM@
-# if address@hidden@
+# if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
 # endif
 _GL_CXXALIAS_SYS (setstate, char *, (char *arg_state));
diff --git a/m4/random.m4 b/m4/random.m4
index acd093d..f5cf0b5 100644
--- a/m4/random.m4
+++ b/m4/random.m4
@@ -1,4 +1,4 @@
-# random.m4 serial 1
+# random.m4 serial 2
 dnl Copyright (C) 2012-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -12,6 +12,16 @@ AC_DEFUN([gl_FUNC_RANDOM],
   if test $ac_cv_func_random = no; then
     HAVE_RANDOM=0
   fi
+
+  AC_CHECK_DECLS_ONCE([initstate])
+  if test $ac_cv_have_decl_initstate = no; then
+    HAVE_DECL_INITSTATE=0
+  fi
+
+  AC_CHECK_DECLS_ONCE([setstate])
+  if test $ac_cv_have_decl_setstate = no; then
+    HAVE_DECL_SETSTATE=0
+  fi
 ])
 
 # Prerequisites of lib/random.c.
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index ec4a058..3537346 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 43
+# stdlib_h.m4 serial 44
 dnl Copyright (C) 2007-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -78,6 +78,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_DECL_INITSTATE=1;     AC_SUBST([HAVE_DECL_INITSTATE])
   HAVE_MKDTEMP=1;            AC_SUBST([HAVE_MKDTEMP])
   HAVE_MKOSTEMP=1;           AC_SUBST([HAVE_MKOSTEMP])
   HAVE_MKOSTEMPS=1;          AC_SUBST([HAVE_MKOSTEMPS])
@@ -96,6 +97,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_DECL_SETSTATE=1;      AC_SUBST([HAVE_DECL_SETSTATE])
   HAVE_STRTOD=1;             AC_SUBST([HAVE_STRTOD])
   HAVE_STRTOLL=1;            AC_SUBST([HAVE_STRTOLL])
   HAVE_STRTOULL=1;           AC_SUBST([HAVE_STRTOULL])
diff --git a/modules/stdlib b/modules/stdlib
index 257b5db..62224e8 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_DECL_INITSTATE''@|$(HAVE_DECL_INITSTATE)|g' \
              -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
              -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
              -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
@@ -89,6 +90,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_DECL_SETSTATE''@|$(HAVE_DECL_SETSTATE)|g' \
              -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
              -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
              -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]