1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-25 10:50:08 +03:00

Use __has_attribute to check for __counted_by__ support

The initial clang patch to support __counted_by__ was landed and
reverted several times. There are some clang toolchains (e.g. the
Android toolchain) that report themselves as version 18 but do not
support __counted_by__. While it is debatable if Android should be
shipping a pre-release clang, using __has_attribute should be a bit
simpler overall.

Note that this doesn't migrate everything else to use __has_attribute:
while clang has always supported __has_attribute, gcc didn't support
it until a bit later.
This commit is contained in:
Daniel Cheng 2025-02-05 15:18:48 -08:00 committed by Nick Wellnhofer
parent 35d8a230a8
commit 3dcde736d0

View File

@ -29,6 +29,12 @@
#include "config.h"
#include <libxml/xmlversion.h>
#if defined(__has_attribute)
#define XML_HAS_ATTRIBUTE(x) __has_attribute(x)
#else
#define XML_HAS_ATTRIBUTE(x) 0
#endif
#if __STDC_VERSION__ >= 199901L
#define XML_INLINE inline
#elif defined(_MSC_VER)
@ -71,8 +77,7 @@
#define ATTRIBUTE_DESTRUCTOR __attribute__((destructor))
#endif
#if (defined(__clang__) && __clang_major__ >= 18) || \
(defined(__GNUC__) && __GNUC__ >= 15)
#if XML_HAS_ATTRIBUTE(__counted_by__)
#define ATTRIBUTE_COUNTED_BY(c) __attribute__((__counted_by__(c)))
#else
#define ATTRIBUTE_COUNTED_BY(c)