Skip to content

Commit

Permalink
apr.h: __attribute__ and __has_attribute exist for !__GNUC__ compiler…
Browse files Browse the repository at this point in the history
…s. 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 <petr.sumbera oracle.com>



git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1917746 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ylavic committed May 15, 2024
1 parent ab76f3c commit b6b94ef
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 41 deletions.
29 changes: 18 additions & 11 deletions include/apr.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,33 @@

/* 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
* 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)
#ifndef __attribute__
#define __attribute__(__x)
#endif
#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
#else
#define APR_INLINE __inline__
#define APR_HAS_INLINE 1
/* __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

#define APR_HAVE_ARPA_INET_H @arpa_ineth@
Expand Down
3 changes: 3 additions & 0 deletions include/apr.hnw
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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
Expand Down
36 changes: 21 additions & 15 deletions include/apr.hw
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,38 @@

/* 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
* 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_INLINE __inline
#define APR_HAS_INLINE 1
#ifndef __attribute__
#define __attribute__(__x)
#endif
#elif !defined(__GNUC__) || __GNUC__ < 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ < 7) ||\
defined(NEXT)
#ifndef __attribute__
#define __attribute__(__x)
#endif
#else /* !_MSC_VER */
#define APR_INLINE
#define APR_HAS_INLINE 0
#else
#define APR_INLINE __inline__
#define APR_HAS_INLINE 1
#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

#define APR_HAVE_ARPA_INET_H 0
Expand Down
36 changes: 21 additions & 15 deletions include/apr.hwc
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,38 @@

/* 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
* 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_INLINE __inline
#define APR_HAS_INLINE 1
#ifndef __attribute__
#define __attribute__(__x)
#endif
#elif !defined(__GNUC__) || __GNUC__ < 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ < 7) ||\
defined(NEXT)
#ifndef __attribute__
#define __attribute__(__x)
#endif
#else /* !_MSC_VER */
#define APR_INLINE
#define APR_HAS_INLINE 0
#else
#define APR_INLINE __inline__
#define APR_HAS_INLINE 1
#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

#define APR_HAVE_ARPA_INET_H 0
Expand Down

0 comments on commit b6b94ef

Please sign in to comment.