From 22c85c61390dfceb1a9cebe284c0b4019ea9e13b Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Wed, 28 Feb 2024 11:16:36 +0200 Subject: [PATCH] refactor(array): use pragma GCC in clang too --- lib/src/array.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/src/array.h b/lib/src/array.h index 45969242..186ba673 100644 --- a/lib/src/array.h +++ b/lib/src/array.h @@ -15,10 +15,7 @@ extern "C" { #ifdef _MSC_VER #pragma warning(disable : 4101) -#elif defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-variable" -#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" #endif @@ -109,9 +106,13 @@ extern "C" { #define array_assign(self, other) \ _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self)) +/// Swap one array with another #define array_swap(self, other) \ _array__swap((Array *)(self), (Array *)(other)) +/// Get the size of the array contents +#define array_elem_size(self) (sizeof *(self)->contents) + /// Search a sorted array for a given `needle` value, using the given `compare` /// callback to determine the order. /// @@ -128,7 +129,7 @@ extern "C" { /// /// See also `array_search_sorted_with`. #define array_search_sorted_by(self, field, needle, _index, _exists) \ - _array__search_sorted(self, 0, compare_int, field, needle, _index, _exists) + _array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists) /// Insert a given `value` into a sorted array, using the given `compare` /// callback to determine the order. @@ -154,8 +155,6 @@ extern "C" { typedef Array(void) Array; -#define array_elem_size(self) sizeof(*(self)->contents) - /// This is not what you're looking for, see `array_delete`. static inline void _array__delete(Array *self) { if (self->contents) { @@ -273,13 +272,11 @@ static inline void _array__splice(Array *self, size_t element_size, /// Helper macro for the `_sorted_by` routines below. This takes the left (existing) /// parameter by reference in order to work with the generic sorting function above. -#define compare_int(a, b) ((int)*(a) - (int)(b)) +#define _compare_int(a, b) ((int)*(a) - (int)(b)) #ifdef _MSC_VER #pragma warning(default : 4101) -#elif defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop #endif