bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] timespec: fill in other members


From: Bruno Haible
Subject: Re: [PATCH] timespec: fill in other members
Date: Mon, 15 May 2023 11:39:29 +0200

Paul Eggert wrote:
> diff --git a/lib/select.c b/lib/select.c
> index 6b6ca4154c..991f475431 100644
> --- a/lib/select.c
> +++ b/lib/select.c
> @@ -516,7 +516,7 @@ restart:
>            goto restart;
>          }
>        if (timeout && wait_timeout == 0 && rc == 0)
> -        timeout->tv_sec = timeout->tv_usec = 0;
> +        timeout = (struct timeval) {0};
>      }
>  
>    /* Now fill in the results.  */

This produces a compilation error on native Windows:

select.c(519): error C2440: '=': cannot convert from 'timeval' to 'rpl_timeval 
*'

Changing the line to
        *timeout = (struct timeval) {0};
does not fix it:

select.c(519): error C2440: '=': cannot convert from 'timeval' to 'rpl_timeval'

The reason is that on native Windows, @REPLACE_STRUCT_TIMEVAL@ evaluates to 1,
and thus gnulib's sys/time.h overrides 'struct timeval':

  # if @REPLACE_STRUCT_TIMEVAL@
  #  define timeval rpl_timeval
  # endif

  struct timeval
  {
    time_t tv_sec;
    long int tv_usec;
  };
  #  define GNULIB_defined_struct_timeval 1

Then select.c does
  #undef timeval

It would be possible to fix this by writing

  #if GNULIB_defined_struct_timeval
          *timeout = (struct rpl_timeval) {0};
  #else
          *timeout = (struct timeval) {0};
  #endif

but that is more complex than before. IMO, it is better to just ignore this
warning if someone uses mingw with GCC ≥ 13. We don't attempt warning-free
compilation on native Windows, and certainly not with extra compiler options
like -Wanalyzer-use-of-uninitialized-value.


2023-05-15  Bruno Haible  <bruno@clisp.org>

        select: Fix compilation error (regression from yesterday).
        * lib/select.c (rpl_select): Revert last change.

diff --git a/lib/select.c b/lib/select.c
index 991f475431..6b6ca4154c 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -516,7 +516,7 @@ restart:
           goto restart;
         }
       if (timeout && wait_timeout == 0 && rc == 0)
-        timeout = (struct timeval) {0};
+        timeout->tv_sec = timeout->tv_usec = 0;
     }
 
   /* Now fill in the results.  */






reply via email to

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