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>
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
  • Loading branch information
ylavic committed May 15, 2024
1 parent 4aa7f37 commit 05651f8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 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__
#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@
Expand Down
3 changes: 3 additions & 0 deletions include/apr.hnw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 32 additions & 2 deletions include/apr.hw
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,41 @@
* are platform specific and should NOT be relied upon!</em></strong>
*/

#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
Expand Down
34 changes: 32 additions & 2 deletions include/apr.hwc
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,41 @@
* are platform specific and should NOT be relied upon!</em></strong>
*/

#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
Expand Down

0 comments on commit 05651f8

Please sign in to comment.