From 98703a5579b4f9b3817b2ac3ce06faabef714eda Mon Sep 17 00:00:00 2001 From: Lev Brouk Date: Mon, 9 Jun 2025 06:47:43 -0700 Subject: [PATCH 1/2] FIXED: alternate fix for macOS static_assert issue --- src/natsp.h | 9 +++++++++ src/status.c | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/natsp.h b/src/natsp.h index a750c4c4c..736cd6f4b 100644 --- a/src/natsp.h +++ b/src/natsp.h @@ -148,6 +148,15 @@ static inline bool nats_StringEquals(const char *s1, const char *s2) #define NATS_MILLIS_TO_NANOS(d) (((int64_t)d)*(int64_t)1E6) #define NATS_SECONDS_TO_NANOS(d) (((int64_t)d)*(int64_t)1E9) +#if __STDC_VERSION__ >= 201112L +#define NATS_GLOBAL_STATIC_ASSERT(_cond, _message_as_id) \ + _Static_assert(_cond, #_message_as_id) +#else +// for C99 we define explicitly +#define NATS_GLOBAL_STATIC_ASSERT(_cond, _message_as_id) \ + typedef char static_assertion_##_message_as_id[(_cond) ? 1 : -1] +#endif + extern int64_t gLockSpinCount; typedef void (*natsInitOnceCb)(void); diff --git a/src/status.c b/src/status.c index f3edc7e3f..fce6324d8 100644 --- a/src/status.c +++ b/src/status.c @@ -76,6 +76,8 @@ static const char *statusText[] = { "Jetstream Consumer PinID Mismatch", }; +NATS_GLOBAL_STATIC_ASSERT(NATS_MAX_STATUS_VALUE == sizeof(statusText)/sizeof(statusText[0]), Incorrect_array_size); + const char* natsStatus_GetText(natsStatus s) { return statusText[(int) s]; From 391eaeb0452b3e101c5706251a2778d869e9ed15 Mon Sep 17 00:00:00 2001 From: Lev Brouk Date: Mon, 9 Jun 2025 07:26:44 -0700 Subject: [PATCH 2/2] Removed the new test --- src/status.c | 2 ++ test/list_test.txt | 1 - test/test.c | 19 ------------------- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/status.c b/src/status.c index fce6324d8..92aa1c757 100644 --- a/src/status.c +++ b/src/status.c @@ -11,6 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "natsp.h" static const char *statusText[] = { diff --git a/test/list_test.txt b/test/list_test.txt index 8ba270b3d..df12951c1 100644 --- a/test/list_test.txt +++ b/test/list_test.txt @@ -187,7 +187,6 @@ _test(natsSock_IPOrder) _test(natsSock_ReadLine) _test(natsSock_ShuffleIPs) _test(natsSrvVersionAtLeast) -_test(natsStatusText) _test(natsStrCaseStr) _test(natsStrHash) _test(natsThread) diff --git a/test/test.c b/test/test.c index c90866a4b..cb445760c 100644 --- a/test/test.c +++ b/test/test.c @@ -248,25 +248,6 @@ void test_natsNowAndSleep(void) testCond(((end - start) >= 990) && ((end - start) <= 1010)); } -void test_natsStatusText(void) -{ - int i; - int ok = true; - - test("Check text exists for all status values: "); - for (i=0; ok && (i