From 3d5321605f701a44bda32fe65a6078c73119d938 Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Wed, 4 Jun 2025 11:50:38 -0600 Subject: [PATCH 1/2] Fixed compiler issue on macOS related to assert for status text Made this a test instead. Also fixed a flapper that was due to a recent change in the NATS Server where an INFO in response of the CONNECT protocol is now sent, causing the override server version that we use in the test to be replaced with the actual server version. Relates to #873 Signed-off-by: Ivan Kozlovic --- src/status.c | 4 ---- src/status.h | 2 +- test/list_test.txt | 1 + test/test.c | 33 ++++++++++++++++++++++++++++++--- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/status.c b/src/status.c index 4e98ab194..f3edc7e3f 100644 --- a/src/status.c +++ b/src/status.c @@ -11,8 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include "natsp.h" static const char *statusText[] = { @@ -78,8 +76,6 @@ static const char *statusText[] = { "Jetstream Consumer PinID Mismatch", }; -static_assert(NATS_MAX_STATUS_VALUE_ == sizeof(statusText)/sizeof(statusText[0]), "Incorrect array size"); - const char* natsStatus_GetText(natsStatus s) { return statusText[(int) s]; diff --git a/src/status.h b/src/status.h index eb080c9e3..3233f3c1e 100644 --- a/src/status.h +++ b/src/status.h @@ -136,7 +136,7 @@ typedef enum NATS_PIN_ID_MISMATCH, ///< Pin ID sent in the request does not match the currently pinned /// consumer subscriber ID on the server. - NATS_MAX_STATUS_VALUE_, ///< Maximum status value, this element MUST be the last one + NATS_MAX_STATUS_VALUE, ///< Maximum status value, this element MUST be the last one } natsStatus; diff --git a/test/list_test.txt b/test/list_test.txt index df12951c1..8ba270b3d 100644 --- a/test/list_test.txt +++ b/test/list_test.txt @@ -187,6 +187,7 @@ _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 4df6d7e86..c90866a4b 100644 --- a/test/test.c +++ b/test/test.c @@ -248,6 +248,25 @@ 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 && (isrvVersion.ma; + mi = nc->srvVersion.mi; + up = nc->srvVersion.up; nc->srvVersion.ma = 2; nc->srvVersion.mi = 7; nc->srvVersion.up = 1; @@ -33821,9 +33848,9 @@ void test_KeyValueDiscardOldToNew(void) // Now change version to 2.7.2 natsConn_Lock(nc); - nc->srvVersion.ma = 2; - nc->srvVersion.mi = 7; - nc->srvVersion.up = 2; + nc->srvVersion.ma = ma; + nc->srvVersion.mi = mi; + nc->srvVersion.up = up; natsConn_Unlock(nc); test("Check discard (old, no auto-update): "); From fde29bfcaeb06f16f245b9d68291467860b552ae Mon Sep 17 00:00:00 2001 From: Lev <1187448+levb@users.noreply.github.com> Date: Mon, 9 Jun 2025 07:36:09 -0700 Subject: [PATCH 2/2] FIXED: alternate fix for macOS static_assert issue (#875) * FIXED: alternate fix for macOS static_assert issue * Removed the new test --- src/natsp.h | 9 +++++++++ src/status.c | 4 ++++ test/list_test.txt | 1 - test/test.c | 19 ------------------- 4 files changed, 13 insertions(+), 20 deletions(-) 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..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[] = { @@ -76,6 +78,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]; 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