[PATCH v3 3/7] Assume support for __extension__ ({ })

Alejandro Colomar alx@kernel.org
Mon Nov 10 14:17:32 GMT 2025


/* Oh come on.  Get a reasonable compiler.  */

GCC supports __extension__ since at least GCC 2.8.
GCC supports ({ }) since GCC 1.x.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 assert/assert.h   |   2 +-
 inet/netinet/in.h |  53 +++---------------
 malloc/obstack.h  | 140 ++++++----------------------------------------
 stdlib/setenv.c   |   3 +-
 time/strptime_l.c |   8 +--
 5 files changed, 27 insertions(+), 179 deletions(-)

diff --git a/assert/assert.h b/assert/assert.h
index 31892aebcb..273bf7f35c 100644
--- a/assert/assert.h
+++ b/assert/assert.h
@@ -101,7 +101,7 @@ __END_DECLS
       ? void (0)							\
       : __assert_fail (#expr, __ASSERT_FILE, __ASSERT_LINE,             \
                        __ASSERT_FUNCTION))
-# elif !defined __GNUC__ || defined __STRICT_ANSI__
+# elif defined __STRICT_ANSI__
 #  define assert(expr)							\
     ((expr)								\
      ? __ASSERT_VOID_CAST (0)						\
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
index fa796be406..28b93dd941 100644
--- a/inet/netinet/in.h
+++ b/inet/netinet/in.h
@@ -433,8 +433,7 @@ extern uint16_t htons (uint16_t __hostshort)
 # endif
 #endif
 
-#ifdef __GNUC__
-# define IN6_IS_ADDR_UNSPECIFIED(a) \
+#define IN6_IS_ADDR_UNSPECIFIED(a) \
   (__extension__							      \
    ({ const struct in6_addr *__a = (const struct in6_addr *) (a);	      \
       __a->__in6_u.__u6_addr32[0] == 0					      \
@@ -442,7 +441,7 @@ extern uint16_t htons (uint16_t __hostshort)
       && __a->__in6_u.__u6_addr32[2] == 0				      \
       && __a->__in6_u.__u6_addr32[3] == 0; }))
 
-# define IN6_IS_ADDR_LOOPBACK(a) \
+#define IN6_IS_ADDR_LOOPBACK(a) \
   (__extension__							      \
    ({ const struct in6_addr *__a = (const struct in6_addr *) (a);	      \
       __a->__in6_u.__u6_addr32[0] == 0					      \
@@ -450,24 +449,24 @@ extern uint16_t htons (uint16_t __hostshort)
       && __a->__in6_u.__u6_addr32[2] == 0				      \
       && __a->__in6_u.__u6_addr32[3] == htonl (1); }))
 
-# define IN6_IS_ADDR_LINKLOCAL(a) \
+#define IN6_IS_ADDR_LINKLOCAL(a) \
   (__extension__							      \
    ({ const struct in6_addr *__a = (const struct in6_addr *) (a);	      \
       (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))
 
-# define IN6_IS_ADDR_SITELOCAL(a) \
+#define IN6_IS_ADDR_SITELOCAL(a) \
   (__extension__							      \
    ({ const struct in6_addr *__a = (const struct in6_addr *) (a);	      \
       (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfec00000); }))
 
-# define IN6_IS_ADDR_V4MAPPED(a) \
+#define IN6_IS_ADDR_V4MAPPED(a) \
   (__extension__							      \
    ({ const struct in6_addr *__a = (const struct in6_addr *) (a);	      \
       __a->__in6_u.__u6_addr32[0] == 0					      \
       && __a->__in6_u.__u6_addr32[1] == 0				      \
       && __a->__in6_u.__u6_addr32[2] == htonl (0xffff); }))
 
-# define IN6_IS_ADDR_V4COMPAT(a) \
+#define IN6_IS_ADDR_V4COMPAT(a) \
   (__extension__							      \
    ({ const struct in6_addr *__a = (const struct in6_addr *) (a);	      \
       __a->__in6_u.__u6_addr32[0] == 0					      \
@@ -475,7 +474,7 @@ extern uint16_t htons (uint16_t __hostshort)
       && __a->__in6_u.__u6_addr32[2] == 0				      \
       && ntohl (__a->__in6_u.__u6_addr32[3]) > 1; }))
 
-# define IN6_ARE_ADDR_EQUAL(a,b) \
+#define IN6_ARE_ADDR_EQUAL(a,b) \
   (__extension__							      \
    ({ const struct in6_addr *__a = (const struct in6_addr *) (a);	      \
       const struct in6_addr *__b = (const struct in6_addr *) (b);	      \
@@ -483,44 +482,6 @@ extern uint16_t htons (uint16_t __hostshort)
       && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1]	      \
       && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2]	      \
       && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; }))
-#else
-# define IN6_IS_ADDR_UNSPECIFIED(a) \
-	(((const uint32_t *) (a))[0] == 0				      \
-	 && ((const uint32_t *) (a))[1] == 0				      \
-	 && ((const uint32_t *) (a))[2] == 0				      \
-	 && ((const uint32_t *) (a))[3] == 0)
-
-# define IN6_IS_ADDR_LOOPBACK(a) \
-	(((const uint32_t *) (a))[0] == 0				      \
-	 && ((const uint32_t *) (a))[1] == 0				      \
-	 && ((const uint32_t *) (a))[2] == 0				      \
-	 && ((const uint32_t *) (a))[3] == htonl (1))
-
-# define IN6_IS_ADDR_LINKLOCAL(a) \
-	((((const uint32_t *) (a))[0] & htonl (0xffc00000))		      \
-	 == htonl (0xfe800000))
-
-# define IN6_IS_ADDR_SITELOCAL(a) \
-	((((const uint32_t *) (a))[0] & htonl (0xffc00000))		      \
-	 == htonl (0xfec00000))
-
-# define IN6_IS_ADDR_V4MAPPED(a) \
-	((((const uint32_t *) (a))[0] == 0)				      \
-	 && (((const uint32_t *) (a))[1] == 0)				      \
-	 && (((const uint32_t *) (a))[2] == htonl (0xffff)))
-
-# define IN6_IS_ADDR_V4COMPAT(a) \
-	((((const uint32_t *) (a))[0] == 0)				      \
-	 && (((const uint32_t *) (a))[1] == 0)				      \
-	 && (((const uint32_t *) (a))[2] == 0)				      \
-	 && (ntohl (((const uint32_t *) (a))[3]) > 1))
-
-# define IN6_ARE_ADDR_EQUAL(a,b) \
-	((((const uint32_t *) (a))[0] == ((const uint32_t *) (b))[0])	      \
-	 && (((const uint32_t *) (a))[1] == ((const uint32_t *) (b))[1])      \
-	 && (((const uint32_t *) (a))[2] == ((const uint32_t *) (b))[2])      \
-	 && (((const uint32_t *) (a))[3] == ((const uint32_t *) (b))[3]))
-#endif
 
 #define IN6_IS_ADDR_MULTICAST(a) (((const uint8_t *) (a))[0] == 0xff)
 
diff --git a/malloc/obstack.h b/malloc/obstack.h
index 1c74d85c9b..3e43a9a735 100644
--- a/malloc/obstack.h
+++ b/malloc/obstack.h
@@ -257,23 +257,17 @@ extern int obstack_exit_failure;
 
 #define obstack_memory_used(h) _obstack_memory_used (h)
 
-#if defined __GNUC__
-/* For GNU C, if not -traditional,
-   we can define these macros to compute all args only once
-   without using a global variable.
-   Also, we can avoid using the 'temp' slot, to make faster code.  */
-
-# define obstack_object_size(OBSTACK)					      \
+#define obstack_object_size(OBSTACK)					      \
   __extension__								      \
     ({ struct obstack const *__o = (OBSTACK);				      \
        (unsigned) (__o->next_free - __o->object_base); })
 
-# define obstack_room(OBSTACK)						      \
+#define obstack_room(OBSTACK)						      \
   __extension__								      \
     ({ struct obstack const *__o = (OBSTACK);				      \
        (unsigned) (__o->chunk_limit - __o->next_free); })
 
-# define obstack_make_room(OBSTACK, length)				      \
+#define obstack_make_room(OBSTACK, length)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        int __len = (length);						      \
@@ -281,7 +275,7 @@ extern int obstack_exit_failure;
 	 _obstack_newchunk (__o, __len);				      \
        (void) 0; })
 
-# define obstack_empty_p(OBSTACK)					      \
+#define obstack_empty_p(OBSTACK)					      \
   __extension__								      \
     ({ struct obstack const *__o = (OBSTACK);				      \
        (__o->chunk->prev == 0						      \
@@ -289,7 +283,7 @@ extern int obstack_exit_failure;
 					  __o->chunk->contents,		      \
 					  __o->alignment_mask)); })
 
-# define obstack_grow(OBSTACK, where, length)				      \
+#define obstack_grow(OBSTACK, where, length)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        int __len = (length);						      \
@@ -299,7 +293,7 @@ extern int obstack_exit_failure;
        __o->next_free += __len;						      \
        (void) 0; })
 
-# define obstack_grow0(OBSTACK, where, length)				      \
+#define obstack_grow0(OBSTACK, where, length)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        int __len = (length);						      \
@@ -310,7 +304,7 @@ extern int obstack_exit_failure;
        *(__o->next_free)++ = 0;						      \
        (void) 0; })
 
-# define obstack_1grow(OBSTACK, datum)					      \
+#define obstack_1grow(OBSTACK, datum)					      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        if (__o->next_free + 1 > __o->chunk_limit)			      \
@@ -322,21 +316,21 @@ extern int obstack_exit_failure;
    or ints, and that the data added so far to the current object
    shares that much alignment.  */
 
-# define obstack_ptr_grow(OBSTACK, datum)				      \
+#define obstack_ptr_grow(OBSTACK, datum)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        if (__o->next_free + sizeof (void *) > __o->chunk_limit)		      \
 	 _obstack_newchunk (__o, sizeof (void *));			      \
        obstack_ptr_grow_fast (__o, datum); })				      \
 
-# define obstack_int_grow(OBSTACK, datum)				      \
+#define obstack_int_grow(OBSTACK, datum)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        if (__o->next_free + sizeof (int) > __o->chunk_limit)		      \
 	 _obstack_newchunk (__o, sizeof (int));				      \
        obstack_int_grow_fast (__o, datum); })
 
-# define obstack_ptr_grow_fast(OBSTACK, aptr)				      \
+#define obstack_ptr_grow_fast(OBSTACK, aptr)				      \
   __extension__								      \
     ({ struct obstack *__o1 = (OBSTACK);				      \
        void *__p1 = __o1->next_free;					      \
@@ -344,7 +338,7 @@ extern int obstack_exit_failure;
        __o1->next_free += sizeof (const void *);			      \
        (void) 0; })
 
-# define obstack_int_grow_fast(OBSTACK, aint)				      \
+#define obstack_int_grow_fast(OBSTACK, aint)				      \
   __extension__								      \
     ({ struct obstack *__o1 = (OBSTACK);				      \
        void *__p1 = __o1->next_free;					      \
@@ -352,7 +346,7 @@ extern int obstack_exit_failure;
        __o1->next_free += sizeof (int);					      \
        (void) 0; })
 
-# define obstack_blank(OBSTACK, length)					      \
+#define obstack_blank(OBSTACK, length)					      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        int __len = (length);						      \
@@ -361,19 +355,19 @@ extern int obstack_exit_failure;
        obstack_blank_fast (__o, __len);					      \
        (void) 0; })
 
-# define obstack_alloc(OBSTACK, length)					      \
+#define obstack_alloc(OBSTACK, length)					      \
   __extension__								      \
     ({ struct obstack *__h = (OBSTACK);					      \
        obstack_blank (__h, (length));					      \
        obstack_finish (__h); })
 
-# define obstack_copy(OBSTACK, where, length)				      \
+#define obstack_copy(OBSTACK, where, length)				      \
   __extension__								      \
     ({ struct obstack *__h = (OBSTACK);					      \
        obstack_grow (__h, (where), (length));				      \
        obstack_finish (__h); })
 
-# define obstack_copy0(OBSTACK, where, length)				      \
+#define obstack_copy0(OBSTACK, where, length)				      \
   __extension__								      \
     ({ struct obstack *__h = (OBSTACK);					      \
        obstack_grow0 (__h, (where), (length));				      \
@@ -381,7 +375,7 @@ extern int obstack_exit_failure;
 
 /* The local variable is named __o1 to avoid a name conflict
    when obstack_blank is called.  */
-# define obstack_finish(OBSTACK)					      \
+#define obstack_finish(OBSTACK)						      \
   __extension__								      \
     ({ struct obstack *__o1 = (OBSTACK);				      \
        void *__value = (void *) __o1->object_base;			      \
@@ -396,7 +390,7 @@ extern int obstack_exit_failure;
        __o1->object_base = __o1->next_free;				      \
        __value; })
 
-# define obstack_free(OBSTACK, OBJ)					      \
+#define obstack_free(OBSTACK, OBJ)					      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
        void *__obj = (OBJ);						      \
@@ -404,106 +398,6 @@ extern int obstack_exit_failure;
 	 __o->next_free = __o->object_base = (char *) __obj;		      \
        else (__obstack_free) (__o, __obj); })
 
-#else /* not __GNUC__ */
-
-# define obstack_object_size(h) \
-  (unsigned) ((h)->next_free - (h)->object_base)
-
-# define obstack_room(h)						      \
-  (unsigned) ((h)->chunk_limit - (h)->next_free)
-
-# define obstack_empty_p(h) \
-  ((h)->chunk->prev == 0						      \
-   && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk,		      \
-				     (h)->chunk->contents,		      \
-				     (h)->alignment_mask))
-
-/* Note that the call to _obstack_newchunk is enclosed in (..., 0)
-   so that we can avoid having void expressions
-   in the arms of the conditional expression.
-   Casting the third operand to void was tried before,
-   but some compilers won't accept it.  */
-
-# define obstack_make_room(h, length)					      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
-
-# define obstack_grow(h, where, length)					      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),		      \
-   memcpy ((h)->next_free, where, (h)->temp.tempint),			      \
-   (h)->next_free += (h)->temp.tempint)
-
-# define obstack_grow0(h, where, length)				      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0),		      \
-   memcpy ((h)->next_free, where, (h)->temp.tempint),			      \
-   (h)->next_free += (h)->temp.tempint,					      \
-   *((h)->next_free)++ = 0)
-
-# define obstack_1grow(h, datum)					      \
-  ((((h)->next_free + 1 > (h)->chunk_limit)				      \
-    ? (_obstack_newchunk ((h), 1), 0) : 0),				      \
-   obstack_1grow_fast (h, datum))
-
-# define obstack_ptr_grow(h, datum)					      \
-  ((((h)->next_free + sizeof (char *) > (h)->chunk_limit)		      \
-    ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0),		      \
-   obstack_ptr_grow_fast (h, datum))
-
-# define obstack_int_grow(h, datum)					      \
-  ((((h)->next_free + sizeof (int) > (h)->chunk_limit)			      \
-    ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0),			      \
-   obstack_int_grow_fast (h, datum))
-
-# define obstack_ptr_grow_fast(h, aptr)					      \
-  (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
-
-# define obstack_int_grow_fast(h, aint)					      \
-  (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
-
-# define obstack_blank(h, length)					      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),		      \
-   obstack_blank_fast (h, (h)->temp.tempint))
-
-# define obstack_alloc(h, length)					      \
-  (obstack_blank ((h), (length)), obstack_finish ((h)))
-
-# define obstack_copy(h, where, length)					      \
-  (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
-
-# define obstack_copy0(h, where, length)				      \
-  (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
-
-# define obstack_finish(h)						      \
-  (((h)->next_free == (h)->object_base					      \
-    ? (((h)->maybe_empty_object = 1), 0)				      \
-    : 0),								      \
-   (h)->temp.tempptr = (h)->object_base,				      \
-   (h)->next_free							      \
-     = __PTR_ALIGN ((h)->object_base, (h)->next_free,			      \
-		    (h)->alignment_mask),				      \
-   (((h)->next_free - (char *) (h)->chunk				      \
-     > (h)->chunk_limit - (char *) (h)->chunk)				      \
-   ? ((h)->next_free = (h)->chunk_limit) : 0),				      \
-   (h)->object_base = (h)->next_free,					      \
-   (h)->temp.tempptr)
-
-# define obstack_free(h, obj)						      \
-  ((h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk,		      \
-   ((((h)->temp.tempint > 0						      \
-      && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk))	      \
-    ? (void) ((h)->next_free = (h)->object_base				      \
-	      = (h)->temp.tempint + (char *) (h)->chunk)		      \
-    : (__obstack_free) (h, (h)->temp.tempint + (char *) (h)->chunk)))
-
-#endif /* not __GNUC__ */
-
 #ifdef __cplusplus
 }       /* C++ */
 #endif
diff --git a/stdlib/setenv.c b/stdlib/setenv.c
index 2b8b6cafa0..0f325c5a20 100644
--- a/stdlib/setenv.c
+++ b/stdlib/setenv.c
@@ -70,8 +70,7 @@ __libc_lock_define_initialized (static, envlock)
    allow arbitrarily many changes of the environment given that the used
    values are from a small set.  Outside glibc this will eat up all
    memory after a while.  */
-#if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \
-		      && defined __GNUC__)
+#if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH)
 # define USE_TSEARCH	1
 # include <search.h>
 
diff --git a/time/strptime_l.c b/time/strptime_l.c
index f5e2f4f5d1..caf4a4c807 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -56,17 +56,11 @@ localtime_r (const time_t *t, struct tm *tp)
 
 
 #define match_char(ch1, ch2) if (ch1 != ch2) return NULL
-#if defined __GNUC__ && __GNUC__ >= 2
-# define match_string(cs1, s2) \
+#define match_string(cs1, s2) \
   ({ size_t len = strlen (cs1);						      \
      int result = __strncasecmp_l ((cs1), (s2), len, locale) == 0;	      \
      if (result) (s2) += len;						      \
      result; })
-#else
-/* Oh come on.  Get a reasonable compiler.  */
-# define match_string(cs1, s2) \
-  (strncasecmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1))
-#endif
 /* We intentionally do not use isdigit() for testing because this will
    lead to problems with the wide character version.  */
 #define get_number(from, to, n) \
-- 
2.51.0



More information about the Libc-alpha mailing list