bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] time: enforce recent POSIX ruling that time_t is integral


From: Paul Eggert
Subject: Re: [PATCH] time: enforce recent POSIX ruling that time_t is integral
Date: Sun, 10 Oct 2010 13:44:04 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100915 Thunderbird/3.0.8

On 10/10/2010 05:09 AM, Bruno Haible wrote:
> I agree now.

Thanks for checking that.  I applied the following patch accordingly.
In a later message I'll follow up with a few more proposed patches.

>From 6c74aa7b6196c9b3d650c499ea02f1dfc1b62491 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Sun, 10 Oct 2010 13:36:34 -0700
Subject: [PATCH] prefer (X ? 1 : -1) when converting from boolean (1,0) to int 
(1,-1)

Formerly the style was sometimes 2*X - 1, because the C standard
was wrongly thought to disallow ?: in integral constant expressions.
* lib/inet_ntop.c (verify_int_size): Rewrite 2*X-7 (!) to 4<=X?1:-1.
* lib/signal.in.h (verify_NSIG_constraint): Rewrite 2*X-1 to X?1:-1.
* lib/spawn.in.h (verify_POSIX_SPAWN_USEVFORK_no_overlap): Likewise.
* lib/stdint.in.h (_verify_intmax_size): Likewise.
* lib/time.in.h (struct __time_t_must_be_integral): Rewrite
2 * ((time_t) 1 / 2 == 0) - 1 to (time_t) 1; this suffices to
verify that time_t cannot be floating.
---
 ChangeLog       |   14 ++++++++++++++
 lib/inet_ntop.c |    2 +-
 lib/signal.in.h |    2 +-
 lib/spawn.in.h  |    5 +++--
 lib/stdint.in.h |    3 ++-
 lib/time.in.h   |    2 +-
 6 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4817bf4..6a56a31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2010-10-10  Paul Eggert  <address@hidden>
+
+       prefer (X ? 1 : -1) when converting from boolean (1,0) to int (1,-1)
+
+       Formerly the style was sometimes 2*X - 1, because the C standard
+       was wrongly thought to disallow ?: in integral constant expressions.
+       * lib/inet_ntop.c (verify_int_size): Rewrite 2*X-7 (!) to 4<=X?1:-1.
+       * lib/signal.in.h (verify_NSIG_constraint): Rewrite 2*X-1 to X?1:-1.
+       * lib/spawn.in.h (verify_POSIX_SPAWN_USEVFORK_no_overlap): Likewise.
+       * lib/stdint.in.h (_verify_intmax_size): Likewise.
+       * lib/time.in.h (struct __time_t_must_be_integral): Rewrite
+       2 * ((time_t) 1 / 2 == 0) - 1 to (time_t) 1; this suffices to
+       verify that time_t cannot be floating.
+
 2010-10-08  Eric Blake  <address@hidden>
 
        time: enforce recent POSIX ruling that time_t is integral
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index 2251aaa..6583a37 100644
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -49,7 +49,7 @@
  * WARNING: Don't even consider trying to compile this on a system where
  * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
  */
-typedef int verify_int_size[2 * sizeof (int) - 7];
+typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1];
 
 static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t 
size);
 #if HAVE_IPV6
diff --git a/lib/signal.in.h b/lib/signal.in.h
index 7ab1737..807c03b 100644
--- a/lib/signal.in.h
+++ b/lib/signal.in.h
@@ -81,7 +81,7 @@ typedef unsigned int sigset_t;
 #  endif
 
 /* This code supports only 32 signals.  */
-typedef int verify_NSIG_constraint[2 * (NSIG <= 32) - 1];
+typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
 
 # endif
 
diff --git a/lib/spawn.in.h b/lib/spawn.in.h
index fa41619..543475b 100644
--- a/lib/spawn.in.h
+++ b/lib/spawn.in.h
@@ -147,10 +147,11 @@ typedef struct
     | (POSIX_SPAWN_SETSCHEDULER > 0 ? POSIX_SPAWN_SETSCHEDULER - 1 : 0))  \
    + 1)
 typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
-            [2 * (((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
+                 [((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
                     | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
                     | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
-                   & POSIX_SPAWN_USEVFORK) == 0) - 1];
+                   & POSIX_SPAWN_USEVFORK) == 0)
+                  ? 1 : -1];
 
 
 #if @GNULIB_POSIX_SPAWN@
diff --git a/lib/stdint.in.h b/lib/stdint.in.h
index 5ff935e..e660cfb 100644
--- a/lib/stdint.in.h
+++ b/lib/stdint.in.h
@@ -279,7 +279,8 @@ typedef unsigned long int gl_uintmax_t;
 /* Verify that intmax_t and uintmax_t have the same size.  Too much code
    breaks if this is not the case.  If this check fails, the reason is likely
    to be found in the autoconf macros.  */
-typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) 
- 1];
+typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
+                                ? 1 : -1];
 
 /* 7.18.2. Limits of specified-width integer types */
 
diff --git a/lib/time.in.h b/lib/time.in.h
index f6bdad6..9507087 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -90,7 +90,7 @@ struct timespec
    point, and it is much easier to write code that doesn't have to
    worry about that corner case, so we force the issue.  */
 struct __time_t_must_be_integral {
-  unsigned int __floating_time_t_unsupported : 2 * ((time_t) 1 / 2 == 0) - 1;
+  unsigned int __floating_time_t_unsupported : (time_t) 1;
 };
 
 /* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
-- 
1.7.2




reply via email to

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