[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1]
From: |
Paul Eggert |
Subject: |
[PATCH] rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1] |
Date: |
Sun, 10 Oct 2010 13:58:05 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100915 Thunderbird/3.0.8 |
Here's a proposed patch to replace the other instances of 2*(X)-1
that I found. I haven't pushed this.
>From 1581f4d64ee29a7db92f437efb9b12da40554948 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Sun, 10 Oct 2010 13:55:10 -0700
Subject: [PATCH] rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1]
* lib/float+.h (verify_sizeof_flt, verify_sizeof_dbl):
(verify_sizeof_ldbl): Rewrite 2*X-1 to X?1:-1.
* lib/malloca.c: Include "verify.h".
(verify1): Remove, replacing with a verify call.
* lib/relocwrapper.c (verify1): Likewise.
* lib/vasnprintf.c (mp_limb_verify, mp_twolimb_verify, TCHAR_T_verify):
Likewise.
* modules/malloca (Depends-on): Add 'verify'.
* modules/relocatable-prog-wrapper (Depends-on): Add 'verify'.
* modules/vasnprintf (Depends-on): Add 'verify'.
---
ChangeLog | 12 ++++++++++++
lib/float+.h | 6 +++---
lib/malloca.c | 5 +++--
lib/relocwrapper.c | 3 ++-
lib/vasnprintf.c | 11 ++++++-----
modules/malloca | 1 +
modules/relocatable-prog-wrapper | 1 +
modules/vasnprintf | 1 +
8 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6a56a31..88ecd61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2010-10-10 Paul Eggert <address@hidden>
+ rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1]
+ * lib/float+.h (verify_sizeof_flt, verify_sizeof_dbl):
+ (verify_sizeof_ldbl): Rewrite 2*X-1 to X?1:-1.
+ * lib/malloca.c: Include "verify.h".
+ (verify1): Remove, replacing with a verify call.
+ * lib/relocwrapper.c (verify1): Likewise.
+ * lib/vasnprintf.c (mp_limb_verify, mp_twolimb_verify, TCHAR_T_verify):
+ Likewise.
+ * modules/malloca (Depends-on): Add 'verify'.
+ * modules/relocatable-prog-wrapper (Depends-on): Add 'verify'.
+ * modules/vasnprintf (Depends-on): Add 'verify'.
+
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
diff --git a/lib/float+.h b/lib/float+.h
index d254921..2bbba51 100644
--- a/lib/float+.h
+++ b/lib/float+.h
@@ -141,8 +141,8 @@
#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
/* Verify that SIZEOF_FLT <= sizeof (float) etc. */
-typedef int verify_sizeof_flt[2 * (SIZEOF_FLT <= sizeof (float)) - 1];
-typedef int verify_sizeof_dbl[2 * (SIZEOF_DBL <= sizeof (double)) - 1];
-typedef int verify_sizeof_ldbl[2 * (SIZEOF_LDBL <= sizeof (long double)) - 1];
+typedef int verify_sizeof_flt[SIZEOF_FLT <= sizeof (float) ? 1 : -1];
+typedef int verify_sizeof_dbl[SIZEOF_DBL <= sizeof (double) ? 1 : - 1];
+typedef int verify_sizeof_ldbl[SIZEOF_LDBL <= sizeof (long double) ? 1 : - 1];
#endif /* _FLOATPLUS_H */
diff --git a/lib/malloca.c b/lib/malloca.c
index 2268878..3e4fd0b 100644
--- a/lib/malloca.c
+++ b/lib/malloca.c
@@ -21,6 +21,8 @@
/* Specification. */
#include "malloca.h"
+#include "verify.h"
+
/* Use the system functions, not the gnulib overrides in this file. */
#undef malloc
@@ -53,8 +55,7 @@ struct preliminary_header { void *next; char
room[MAGIC_SIZE]; };
#define HEADER_SIZE \
(((sizeof (struct preliminary_header) + sa_alignment_max - 1) /
sa_alignment_max) * sa_alignment_max)
struct header { void *next; char room[HEADER_SIZE - sizeof (struct
preliminary_header) + MAGIC_SIZE]; };
-/* Verify that HEADER_SIZE == sizeof (struct header). */
-typedef int verify1[2 * (HEADER_SIZE == sizeof (struct header)) - 1];
+verify (HEADER_SIZE == sizeof (struct header));
/* We make the hash table quite big, so that during lookups the probability
of empty hash buckets is quite high. There is no need to make the hash
table resizable, because when the hash table gets filled so much that the
diff --git a/lib/relocwrapper.c b/lib/relocwrapper.c
index 04f2258..d3980dd 100644
--- a/lib/relocwrapper.c
+++ b/lib/relocwrapper.c
@@ -54,6 +54,7 @@
#include "progname.h"
#include "relocatable.h"
#include "c-ctype.h"
+#include "verify.h"
/* Use the system functions, not the gnulib overrides in this file. */
#undef fprintf
@@ -114,7 +115,7 @@ add_dotbin (const char *filename)
/* List of directories that contain the libraries. */
static const char *libdirs[] = { LIBDIRS NULL };
/* Verify that at least one directory is given. */
-typedef int verify1[2 * (sizeof (libdirs) / sizeof (libdirs[0]) > 1) - 1];
+verify (sizeof (libdirs) / sizeof (libdirs[0]) > 1);
/* Relocate the list of directories that contain the libraries. */
static void
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 41c6271..388ab0d 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -88,6 +88,8 @@
/* Checked size_t computations. */
#include "xsize.h"
+#include "verify.h"
+
#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
# include <math.h>
# include "float+.h"
@@ -322,11 +324,11 @@ is_infinite_or_zerol (long double x)
typedef unsigned int mp_limb_t;
# define GMP_LIMB_BITS 32
-typedef int mp_limb_verify[2 * (sizeof (mp_limb_t) * CHAR_BIT ==
GMP_LIMB_BITS) - 1];
+verify (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS);
typedef unsigned long long mp_twolimb_t;
# define GMP_TWOLIMB_BITS 64
-typedef int mp_twolimb_verify[2 * (sizeof (mp_twolimb_t) * CHAR_BIT ==
GMP_TWOLIMB_BITS) - 1];
+verify (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS);
/* Representation of a bignum >= 0. */
typedef struct
@@ -2621,7 +2623,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
size_t characters;
# if !DCHAR_IS_TCHAR
/* This code assumes that TCHAR_T is 'char'. */
- typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1];
+ verify (sizeof (TCHAR_T) == 1);
TCHAR_T *tmpsrc;
DCHAR_T *tmpdst;
size_t tmpdst_len;
@@ -5284,8 +5286,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
DCHAR_T *tmpdst;
size_t tmpdst_len;
/* This code assumes that TCHAR_T is 'char'. */
- typedef int TCHAR_T_verify
- [2 * (sizeof (TCHAR_T) == 1) - 1];
+ verify (sizeof (TCHAR_T) == 1);
# if USE_SNPRINTF
tmpsrc = (TCHAR_T *) (result + length);
# else
diff --git a/modules/malloca b/modules/malloca
index d54bf30..57cbe32 100644
--- a/modules/malloca
+++ b/modules/malloca
@@ -11,6 +11,7 @@ m4/longlong.m4
Depends-on:
alloca-opt
+verify
configure.ac:
gl_MALLOCA
diff --git a/modules/relocatable-prog-wrapper b/modules/relocatable-prog-wrapper
index de77830..b968929 100644
--- a/modules/relocatable-prog-wrapper
+++ b/modules/relocatable-prog-wrapper
@@ -42,6 +42,7 @@ unistd
environ
intprops
string
+verify
configure.ac:
gl_FUNC_READLINK_SEPARATE
diff --git a/modules/vasnprintf b/modules/vasnprintf
index 480998d..6d266a1 100644
--- a/modules/vasnprintf
+++ b/modules/vasnprintf
@@ -26,6 +26,7 @@ stdint
xsize
errno
memchr
+verify
configure.ac:
gl_FUNC_VASNPRINTF
--
1.7.2
- Re: [PATCH] time: enforce recent POSIX ruling that time_t is integral, (continued)
- Re: [PATCH] time: enforce recent POSIX ruling that time_t is integral, Bruno Haible, 2010/10/10
- Re: [PATCH] time: enforce recent POSIX ruling that time_t is integral, Paul Eggert, 2010/10/10
- [PATCH] Fix mismatched parens in previous commit, Gary V. Vaughan, 2010/10/11
- Re: [PATCH] Fix mismatched parens in previous commit, Jim Meyering, 2010/10/11
- Re: [PATCH] Fix mismatched parens in previous commit, Gary V. Vaughan, 2010/10/11
- Re: [PATCH] Fix mismatched parens in previous commit, Paul Eggert, 2010/10/11
- [PATCH] rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1],
Paul Eggert <=
- Re: [PATCH] rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1], Bruno Haible, 2010/10/10
- Re: [PATCH] rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1], Paul Eggert, 2010/10/10