This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, libgfortran, committed] Don't use rand_s on CYGWIN
- From: NightStrike <nightstrike at gmail dot com>
- To: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Fortran List <fortran at gcc dot gnu dot org>, JonY <10walls at gmail dot com>
- Date: Sun, 12 Mar 2017 13:26:42 -0400
- Subject: Re: [Patch, libgfortran, committed] Don't use rand_s on CYGWIN
- Authentication-results: sourceware.org; auth=none
- References: <CAO9iq9HLQ_pgS=foupwWUzmRXaKnx4J5GbMy_TjDgzuh3vHayw@mail.gmail.com>
On Mon, Feb 27, 2017 at 6:15 AM, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> Don't try to use rand_s on CYGWIN
>
> CYGWIN seems to include _mingw.h and thus __MINGW64_VERSION_MAJOR is
> defined even though rand_s is not available. Thus add an extra check
> for __CYGWIN__.
>
> Thanks to Tim Prince and Nightstrike for bringing this issue to my attention.
>
> Committed as r245755.
>
> 2017-02-27 Janne Blomqvist <jb@gcc.gnu.org>
>
> * intrinsics/random.c (getosrandom): Don't try to use rand_s on
> CYGWIN.
1) There was no patch attached to the email.
2) As mentioned on IRC, I don't think this is the right fix. The real
problem is that time_1.h includes windows.h on CYGWIN, which it
shouldn't be doing. This then pollutes the translation unit with all
sorts of MINGW-isms that aren't exactly appropriate for cygwin.
Removing the include in time_1.h and then adjusting a few ifdefs in
system_clock.c that also had the same bug fixes the problem. The
testsuite is running right now on this.
See the following diff for reference:
Index: ../gccsvn/libgfortran/intrinsics/random.c
===================================================================
--- ../gccsvn/libgfortran/intrinsics/random.c (revision 246075)
+++ ../gccsvn/libgfortran/intrinsics/random.c (working copy)
@@ -304,7 +304,7 @@
getosrandom (void *buf, size_t buflen)
{
/* rand_s is available in MinGW-w64 but not plain MinGW. */
-#if defined(__MINGW64_VERSION_MAJOR) && !defined(__CYGWIN__)
+#ifdef __MINGW64_VERSION_MAJOR
unsigned int* b = buf;
for (unsigned i = 0; i < buflen / sizeof (unsigned int); i++)
rand_s (&b[i]);
Index: ../gccsvn/libgfortran/intrinsics/system_clock.c
===================================================================
--- ../gccsvn/libgfortran/intrinsics/system_clock.c (revision 246075)
+++ ../gccsvn/libgfortran/intrinsics/system_clock.c (working copy)
@@ -29,7 +29,7 @@
#include "time_1.h"
-#if !defined(__MINGW32__) && !defined(__CYGWIN__)
+#if !defined(__MINGW32__)
/* POSIX states that CLOCK_REALTIME must be present if clock_gettime
is available, others are optional. */
@@ -121,7 +121,7 @@
system_clock_4 (GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate,
GFC_INTEGER_4 *count_max)
{
-#if defined(__MINGW32__) || defined(__CYGWIN__)
+#if defined(__MINGW32__)
if (count)
{
/* Use GetTickCount here as the resolution and range is
@@ -174,7 +174,7 @@
system_clock_8 (GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate,
GFC_INTEGER_8 *count_max)
{
-#if defined(__MINGW32__) || defined(__CYGWIN__)
+#if defined(__MINGW32__)
LARGE_INTEGER cnt;
LARGE_INTEGER freq;
bool fail = false;
Index: ../gccsvn/libgfortran/intrinsics/time_1.h
===================================================================
--- ../gccsvn/libgfortran/intrinsics/time_1.h (revision 246075)
+++ ../gccsvn/libgfortran/intrinsics/time_1.h (working copy)
@@ -101,7 +101,7 @@
CPU_TIME intrinsics. Returns 0 for success or -1 if no
CPU time could be computed. */
-#if defined(__MINGW32__) || defined(__CYGWIN__)
+#if defined(__MINGW32__)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>