From 05651f8225d2eb9ca58e71bd8ad8809117657e57 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Wed, 15 May 2024 15:54:42 +0000 Subject: [PATCH] apr.h: __attribute__ and __has_attribute exist for !__GNUC__ compilers. PR 69009. There are more compilers than __GNUC__ that provide __attribute__ so let's not no-op it based on (un)known compilers but simply if it's not already defined (it should be provided as a pre-defined macro if defined by the compiler). While at, do the same for __has_attribute. Submitted by: Petr Sumbera Merges r1917746 from trunk git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1917747 13f79535-47bb-0310-9956-ffa450edef68 --- include/apr.h.in | 29 ++++++++++++++++++----------- include/apr.hnw | 3 +++ include/apr.hw | 34 ++++++++++++++++++++++++++++++++-- include/apr.hwc | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 15 deletions(-) diff --git a/include/apr.h.in b/include/apr.h.in index 4d8b7703335..9d8dbe96ecd 100644 --- a/include/apr.h.in +++ b/include/apr.h.in @@ -47,8 +47,8 @@ /* So that we can use inline on some critical functions, and use * GNUC attributes (such as to get -Wall warnings for printf-like - * functions). Only do this in gcc 2.7 or later ... it may work - * on earlier stuff, but why chance it. + * functions). Both __inline__ and __attribute__ exist for gcc >= 2.7, + * other !__GNUC__ compilers may provide __attribute__ still. * * We've since discovered that the gcc shipped with NeXT systems * as "cc" is completely broken. It claims to be __GNUC__ and so @@ -56,17 +56,24 @@ * means. In particular it's missing inline and the __attribute__ * stuff. So we hack around it. PR#1613. -djg */ -#if !defined(__GNUC__) || __GNUC__ < 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ||\ - defined(NEXT) -#ifndef __attribute__ +#if defined(__GNUC__) \ + && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) \ + && !defined(NEXT) +#define APR_INLINE __inline__ +#define APR_HAS_INLINE 1 +#else /* !__GNUC__ */ +#define APR_INLINE +#define APR_HAS_INLINE 0 +/* __has_attribute should always be a pre-defined macro, but not + * necessarily __attribute__ (e.g. builtin), so check for both to + * avoid overriding __attribute__. + */ +#if !(defined(__attribute__) || defined(__has_attribute)) #define __attribute__(__x) #endif -#define APR_INLINE -#define APR_HAS_INLINE 0 -#else -#define APR_INLINE __inline__ -#define APR_HAS_INLINE 1 +#endif /* !__GNUC__ */ +#ifndef __has_attribute +#define __has_attribute(__x) 0 #endif #define APR_HAVE_ARPA_INET_H @arpa_ineth@ diff --git a/include/apr.hnw b/include/apr.hnw index 5df7d9d5185..8eb2b92905b 100644 --- a/include/apr.hnw +++ b/include/apr.hnw @@ -85,6 +85,9 @@ extern "C" { #ifndef __attribute__ #define __attribute__(__x) #endif +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif #define ENUM_BITFIELD(e,n,w) signed int n : w #define APR_HAVE_CONIO_H 0 diff --git a/include/apr.hw b/include/apr.hw index 4247d6135c0..9dc5715d046 100644 --- a/include/apr.hw +++ b/include/apr.hw @@ -125,11 +125,41 @@ * are platform specific and should NOT be relied upon! */ -#define APR_INLINE __inline +/* So that we can use inline on some critical functions, and use + * GNUC attributes (such as to get -Wall warnings for printf-like + * functions). Both __inline__ and __attribute__ exist for gcc >= 2.7, + * other !__GNUC__ compilers may provide __attribute__ still. + * + * We've since discovered that the gcc shipped with NeXT systems + * as "cc" is completely broken. It claims to be __GNUC__ and so + * on, but it doesn't implement half of the things that __GNUC__ + * means. In particular it's missing inline and the __attribute__ + * stuff. So we hack around it. PR#1613. -djg + */ +#if defined(__GNUC__) \ + && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) \ + && !defined(NEXT) +#define APR_INLINE __inline__ +#define APR_HAS_INLINE 1 +#else /* !__GNUC__ */ +#if defined(_MSC_VER) +#define APR_INLINE __inline #define APR_HAS_INLINE 1 -#if !defined(__GNUC__) && !defined(__attribute__) +#else /* !_MSC_VER */ +#define APR_INLINE +#define APR_HAS_INLINE 0 +#endif /* !_MSC_VER */ +/* __has_attribute should always be a pre-defined macro, but not + * necessarily __attribute__ (e.g. builtin), so check for both to + * avoid overriding __attribute__. + */ +#if !(defined(__attribute__) || defined(__has_attribute)) #define __attribute__(__x) #endif +#endif /* !__GNUC__ */ +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif #ifndef _WIN32_WCE #define APR_HAVE_ARPA_INET_H 0 diff --git a/include/apr.hwc b/include/apr.hwc index f6672ce54ff..d61d617760d 100644 --- a/include/apr.hwc +++ b/include/apr.hwc @@ -112,11 +112,41 @@ * are platform specific and should NOT be relied upon! */ -#define APR_INLINE __inline +/* So that we can use inline on some critical functions, and use + * GNUC attributes (such as to get -Wall warnings for printf-like + * functions). Both __inline__ and __attribute__ exist for gcc >= 2.7, + * other !__GNUC__ compilers may provide __attribute__ still. + * + * We've since discovered that the gcc shipped with NeXT systems + * as "cc" is completely broken. It claims to be __GNUC__ and so + * on, but it doesn't implement half of the things that __GNUC__ + * means. In particular it's missing inline and the __attribute__ + * stuff. So we hack around it. PR#1613. -djg + */ +#if defined(__GNUC__) \ + && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) \ + && !defined(NEXT) +#define APR_INLINE __inline__ +#define APR_HAS_INLINE 1 +#else /* !__GNUC__ */ +#if defined(_MSC_VER) +#define APR_INLINE __inline #define APR_HAS_INLINE 1 -#if !defined(__GNUC__) && !defined(__attribute__) +#else /* !_MSC_VER */ +#define APR_INLINE +#define APR_HAS_INLINE 0 +#endif /* !_MSC_VER */ +/* __has_attribute should always be a pre-defined macro, but not + * necessarily __attribute__ (e.g. builtin), so check for both to + * avoid overriding __attribute__. + */ +#if !(defined(__attribute__) || defined(__has_attribute)) #define __attribute__(__x) #endif +#endif /* !__GNUC__ */ +#ifndef __has_attribute +#define __has_attribute(__x) 0 +#endif #ifndef _WIN32_WCE #define APR_HAVE_ARPA_INET_H 0