Skip to content

Commit c85d1c1

Browse files
committed
CDRIVER-4451 Avoid unintentional conflict with macro-types in bson-cmp.h macros (#1091)
1 parent 61e4176 commit c85d1c1

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

src/libbson/src/bson/bson-cmp.h

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,37 @@ BSON_CMP_SET (greater_equal,
118118
#undef BSON_CMP_SET
119119

120120

121-
/* Define in_range functions for *signed* type Type. */
122-
#define BSON_IN_RANGE_SET_SIGNED(Type, min, max) \
123-
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range_, Type, _signed) ( \
124-
int64_t value) \
125-
{ \
126-
return bson_cmp_greater_equal_ss (value, min) && \
127-
bson_cmp_less_equal_ss (value, max); \
128-
} \
129-
\
130-
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range_, Type, _unsigned) ( \
131-
uint64_t value) \
132-
{ \
133-
return bson_cmp_greater_equal_us (value, min) && \
134-
bson_cmp_less_equal_us (value, max); \
121+
/* Return true if the given value is within the range of the corresponding
122+
* signed type. The suffix must match the signedness of the given value. */
123+
#define BSON_IN_RANGE_SET_SIGNED(Type, min, max) \
124+
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range, _##Type, _signed) ( \
125+
int64_t value) \
126+
{ \
127+
return bson_cmp_greater_equal_ss (value, min) && \
128+
bson_cmp_less_equal_ss (value, max); \
129+
} \
130+
\
131+
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range, _##Type, _unsigned) ( \
132+
uint64_t value) \
133+
{ \
134+
return bson_cmp_greater_equal_us (value, min) && \
135+
bson_cmp_less_equal_us (value, max); \
135136
}
136137

137-
/* Define in_range functions for *unsigned* type Type. */
138-
#define BSON_IN_RANGE_SET_UNSIGNED(Type, max) \
139-
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range_, Type, _signed) ( \
140-
int64_t value) \
141-
{ \
142-
return bson_cmp_greater_equal_su (value, 0u) && \
143-
bson_cmp_less_equal_su (value, max); \
144-
} \
145-
\
146-
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range_, Type, _unsigned) ( \
147-
uint64_t value) \
148-
{ \
149-
return bson_cmp_less_equal_uu (value, max); \
138+
/* Return true if the given value is within the range of the corresponding
139+
* unsigned type. The suffix must match the signedness of the given value. */
140+
#define BSON_IN_RANGE_SET_UNSIGNED(Type, max) \
141+
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range, _##Type, _signed) ( \
142+
int64_t value) \
143+
{ \
144+
return bson_cmp_greater_equal_su (value, 0u) && \
145+
bson_cmp_less_equal_su (value, max); \
146+
} \
147+
\
148+
static BSON_INLINE bool BSON_CONCAT3 (bson_in_range, _##Type, _unsigned) ( \
149+
uint64_t value) \
150+
{ \
151+
return bson_cmp_less_equal_uu (value, max); \
150152
}
151153

152154
BSON_IN_RANGE_SET_SIGNED (signed_char, SCHAR_MIN, SCHAR_MAX)
@@ -181,12 +183,12 @@ BSON_IN_RANGE_SET_UNSIGNED (size_t, SIZE_MAX)
181183
/* Return true if the value with *signed* type is in the representable range of
182184
* Type and false otherwise. */
183185
#define bson_in_range_signed(Type, value) \
184-
BSON_CONCAT3 (bson_in_range_, Type, _signed) (value)
186+
BSON_CONCAT3 (bson_in_range, _##Type, _signed) (value)
185187

186188
/* Return true if the value with *unsigned* type is in the representable range
187189
* of Type and false otherwise. */
188190
#define bson_in_range_unsigned(Type, value) \
189-
BSON_CONCAT3 (bson_in_range_, Type, _unsigned) (value)
191+
BSON_CONCAT3 (bson_in_range, _##Type, _unsigned) (value)
190192

191193

192194
BSON_END_DECLS

0 commit comments

Comments
 (0)