Skip to content

Commit a2c33be

Browse files
authored
CDRIVER-6102 use mn for minutes suffix (#2148)
* add regression test * use `mn` not `min` for minutes suffix To avoid conflict with commonly defined `min` macro.
1 parent a48e71a commit a2c33be

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/common/src/mlib/duration.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ _mlibDurationMaxBetween(mlib_duration lhs, mlib_duration rhs)
268268
* - `us` (microseconds)
269269
* - `ms` (milliseconds)
270270
* - `s` (seconds)
271-
* - `min` (minutes)
271+
* - `mn` (minutes)
272272
* - `h` (hours)
273273
*
274274
* Other unit suffixes will generate a compile-time error
@@ -319,15 +319,15 @@ _mlibCreateDurationFromUnitCount_s(const mlib_upsized_integer n)
319319
}
320320

321321
static inline mlib_duration
322-
_mlibCreateDurationFromUnitCount_min(const mlib_upsized_integer n)
322+
_mlibCreateDurationFromUnitCount_mn(const mlib_upsized_integer n)
323323
{
324324
return mlib_duration(_mlibCreateDurationFromUnitCount_us(n), mul, 60 * 1000 * 1000);
325325
}
326326

327327
static inline mlib_duration
328328
_mlibCreateDurationFromUnitCount_h(const mlib_upsized_integer n)
329329
{
330-
return mlib_duration(_mlibCreateDurationFromUnitCount_min(n), mul, 60);
330+
return mlib_duration(_mlibCreateDurationFromUnitCount_mn(n), mul, 60);
331331
}
332332

333333
/**

src/common/tests/test-mlib.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,11 +950,11 @@ _test_duration(void)
950950
d = mlib_duration((4, s), min, (400, ms));
951951
mlib_check(mlib_duration_cmp(d, ==, (400, ms)));
952952

953-
d = mlib_duration(10, min);
953+
d = mlib_duration(10, mn);
954954
mlib_check(mlib_duration_cmp(d, ==, (600, s)));
955955

956956
d = mlib_duration(4, h);
957-
mlib_check(mlib_duration_cmp(d, ==, (240, min)));
957+
mlib_check(mlib_duration_cmp(d, ==, (240, mn)));
958958

959959
d = mlib_duration((10, s), div, 20);
960960
d = mlib_duration(
@@ -1038,6 +1038,15 @@ _test_duration(void)
10381038
ts = mlib_duration_to_timespec(mlib_duration(-5000908, us));
10391039
mlib_check(ts.tv_sec, eq, -5);
10401040
mlib_check(ts.tv_nsec, eq, -908000);
1041+
1042+
// Test when min is defined (CDRIVER-6102)
1043+
#pragma push_macro("min")
1044+
#undef min
1045+
#define min(a, b) ((a) > (b) ? (b) : (a))
1046+
d = mlib_duration((1, s), min, (2, s));
1047+
mlib_check(mlib_duration_cmp(d, ==, (1, s)));
1048+
d = mlib_duration(3, mn);
1049+
#pragma pop_macro("min")
10411050
}
10421051

10431052
static void

src/libmongoc/tests/test-mongoc-sdam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ heartbeat_succeeded(const mongoc_apm_server_heartbeat_succeeded_t *event)
755755
#endif
756756
}
757757

758-
#define RTT_TEST_TIMEOUT mlib_duration(1, min)
758+
#define RTT_TEST_TIMEOUT mlib_duration(1, mn)
759759
#define RTT_TEST_INITIAL_SLEEP mlib_duration(2, s)
760760
#define RTT_TEST_TICK mlib_duration(10, ms)
761761

0 commit comments

Comments
 (0)