From patchwork Thu Sep 22 13:30:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 15903 Received: (qmail 83011 invoked by alias); 22 Sep 2016 13:31:06 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 82923 invoked by uid 89); 22 Sep 2016 13:31:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=reveals, *__restrict, sk:__stdc_, sk:__STDC_ X-HELO: l2mail1.panix.com From: Zack Weinberg To: libc-alpha@sourceware.org Cc: carlos@redhat.com, joseph@codesourcery.com Subject: [PATCH 1c/6] Installed header hygiene (BZ#20366): _LIBC and __STDC_VERSION__ are not always defined. Date: Thu, 22 Sep 2016 09:30:44 -0400 Message-Id: <20160922133054.22210-4-zackw@panix.com> In-Reply-To: <20160922133054.22210-3-zackw@panix.com> References: <20160922133054.22210-1-zackw@panix.com> <20160922133054.22210-2-zackw@panix.com> <20160922133054.22210-3-zackw@panix.com> MIME-Version: 1.0 It seems to me that _LIBC should not appear in installed headers, but avoiding that for argp specifically would require more surgery than feels appropriate for this patch set. It's possible that "#ifdef _LIBC" would be sufficient, but I wanted to be conservative. All three versions of bits/socket.h want to know whether __flexarr will produce a real flexible array member -- specifically, one that doesn't alter sizeof(the structure containing it). They were testing for this with a complicated #if condition that did not agree with sys/cdefs.h and that tripped -Wundef warnings under -std=c90. I added a new macro to sys/cdefs.h, __glibc_c99_flexarr_available, which reveals exactly what these headers want to know. I also took the opportunity to flatten the rather messy conditional nest defining __flexarr. * argp/argp.h: Check whether _LIBC is defined before expanding it. * posix/glob.h: Check whether __USE_XOPEN2K8 is defined instead of expanding it. * misc/sys/cdefs.h: Tidy up conditional nest defining __flexarr. Define __glibc_c99_flexarr_available to 1 when the compiler supports C99-compatible flexible array members, 0 otherwise. * sysdeps/unix/sysv/linux/bits/socket.h * sysdeps/mach/hurd/bits/socket.h * bits/socket.h: Use __glibc_c99_flexarr_available in definitions of struct cmsghdr and CMSG_DATA. --- argp/argp.h | 4 ++-- bits/socket.h | 4 ++-- misc/sys/cdefs.h | 30 ++++++++++++++++++------------ posix/glob.h | 2 +- sysdeps/mach/hurd/bits/socket.h | 4 ++-- sysdeps/unix/sysv/linux/bits/socket.h | 4 ++-- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/argp/argp.h b/argp/argp.h index 7cb5a69..5066776 100644 --- a/argp/argp.h +++ b/argp/argp.h @@ -511,7 +511,7 @@ extern void *__argp_input (const struct argp *__restrict __argp, #ifdef __USE_EXTERN_INLINES -# if !_LIBC +# if !(defined _LIBC && _LIBC) # define __argp_usage argp_usage # define __argp_state_help argp_state_help # define __option_is_short _option_is_short @@ -546,7 +546,7 @@ __NTH (__option_is_end (const struct argp_option *__opt)) return !__opt->key && !__opt->name && !__opt->doc && !__opt->group; } -# if !_LIBC +# if !(defined _LIBC && _LIBC) # undef __argp_usage # undef __argp_state_help # undef __option_is_short diff --git a/bits/socket.h b/bits/socket.h index a22fd56..18adca4 100644 --- a/bits/socket.h +++ b/bits/socket.h @@ -216,13 +216,13 @@ struct cmsghdr of cmsghdr structure. */ int cmsg_level; /* Originating protocol. */ int cmsg_type; /* Protocol specific type. */ -#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L +#if __glibc_c99_flexarr_available __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data. */ #endif }; /* Ancillary data object manipulation macros. */ -#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L +#if __glibc_c99_flexarr_available # define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data) #else # define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1)) diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 6e9b840..935a94b 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -153,21 +153,27 @@ # define __errordecl(name, msg) extern void name (void) #endif -/* Support for flexible arrays. */ -#if __GNUC_PREREQ (2,97) -/* GCC 2.97 supports C99 flexible array members. */ +/* Support for flexible arrays. + Headers that should use flexible arrays only if they're "real" + (e.g. only if they won't affect sizeof()) should test + #if __glibc_c99_flexarr_available. */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L # define __flexarr [] +# define __glibc_c99_flexarr_available 1 +#elif __GNUC_PREREQ (2,97) +/* GCC 2.97 supports C99 flexible array members as an extension, + even when in C89 mode or compiling C++ (any version). */ +# define __flexarr [] +# define __glibc_c99_flexarr_available 1 +#elif defined __GNUC__ +/* Pre-2.97 GCC did not support C99 flexible arrays but did have + an equivalent extension with slightly different notation. */ +# define __flexarr [0] +# define __glibc_c99_flexarr_available 1 #else -# ifdef __GNUC__ -# define __flexarr [0] -# else -# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L -# define __flexarr [] -# else /* Some other non-C99 compiler. Approximate with [1]. */ -# define __flexarr [1] -# endif -# endif +# define __flexarr [1] +# define __glibc_c99_flexarr_available 0 #endif diff --git a/posix/glob.h b/posix/glob.h index e4548f6..ae70fa7 100644 --- a/posix/glob.h +++ b/posix/glob.h @@ -25,7 +25,7 @@ __BEGIN_DECLS /* We need `size_t' for the following definitions. */ #ifndef __size_t typedef __SIZE_TYPE__ __size_t; -# if defined __USE_XOPEN || __USE_XOPEN2K8 +# if defined __USE_XOPEN || defined __USE_XOPEN2K8 typedef __SIZE_TYPE__ size_t; # endif #else diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h index 257e438..5a8cd89 100644 --- a/sysdeps/mach/hurd/bits/socket.h +++ b/sysdeps/mach/hurd/bits/socket.h @@ -220,13 +220,13 @@ struct cmsghdr of cmsghdr structure. */ int cmsg_level; /* Originating protocol. */ int cmsg_type; /* Protocol specific type. */ -#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L +#if __glibc_c99_flexarr_available __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data. */ #endif }; /* Ancillary data object manipulation macros. */ -#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L +#if __glibc_c99_flexarr_available # define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data) #else # define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1)) diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h index 2266047..514c373 100644 --- a/sysdeps/unix/sysv/linux/bits/socket.h +++ b/sysdeps/unix/sysv/linux/bits/socket.h @@ -273,13 +273,13 @@ struct cmsghdr with this. */ int cmsg_level; /* Originating protocol. */ int cmsg_type; /* Protocol specific type. */ -#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L +#if __glibc_c99_flexarr_available __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data. */ #endif }; /* Ancillary data object manipulation macros. */ -#if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L +#if __glibc_c99_flexarr_available # define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data) #else # define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))