Skip to content

Commit 3012f26

Browse files
committed
CDRIVER-5629 do not use bool in BSON DSL (#1667)
* fix usage of `drop_target` bool in test * use correct return type in test * update BSON DSL to use `boolean`, rather than `bool` To address a reported compile issue: https://www.mongodb.com/community/forums/t/error-when-build-mongo-c-driver-with-visual-studio-2019/287062/2 The report suggests `bool` or `_Bool` was `#define`ed to `int`, causing the DSL to evaluate to undefined symbols (e.g. `_bsonDSL_Type_int`, instead of `_bsonDSL_Type_bool`).
1 parent 80566df commit 3012f26

File tree

7 files changed

+26
-34
lines changed

7 files changed

+26
-34
lines changed

src/common/bson-dsl.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
242242
bsonBuildError = "Error while appending bool(" _bsonDSL_str (b) ")"; \
243243
} else \
244244
((void) 0)
245-
#define _bsonArrayOperation_bool(X) _bsonArrayAppendValue (bool (X))
246-
#define _bsonValueOperation__Bool(b) _bsonValueOperation_bool (b)
247-
#define _bsonArrayOperation__Bool(X) _bsonArrayAppendValue (_Bool (X))
245+
#define _bsonArrayOperation_boolean(X) _bsonArrayAppendValue (boolean (X))
246+
#define _bsonValueOperation_boolean(b) _bsonValueOperation_bool (b)
248247

249248
#define _bsonValueOperation_null \
250249
if (!bson_append_null (_bsonBuildAppendArgs)) { \
@@ -386,9 +385,8 @@ BSON_IF_GNU_LIKE (_Pragma ("GCC diagnostic ignored \"-Wshadow\""))
386385
#define _bsonDSL_Type_binary BSON_TYPE_BINARY
387386
#define _bsonDSL_Type_undefined BSON_TYPE_UNDEFINED
388387
#define _bsonDSL_Type_oid BSON_TYPE_OID
389-
#define _bsonDSL_Type_bool BSON_TYPE_BOOL
390-
// ("bool" may be spelled _Bool due to macro expansion:)
391-
#define _bsonDSL_Type__Bool BSON_TYPE_BOOL
388+
// Use `boolean`, not `bool`. `bool` may be defined as a macro to `_Bool` or `int`:
389+
#define _bsonDSL_Type_boolean BSON_TYPE_BOOL
392390
#define _bsonDSL_Type_date_time BSON_TYPE_DATE_TIME
393391
#define _bsonDSL_Type_null BSON_TYPE_NULL
394392
#define _bsonDSL_Type_regex BSON_TYPE_REGEX
@@ -1069,17 +1067,11 @@ _bsonVisitIterAs_int32 (void)
10691067
}
10701068

10711069
static BSON_INLINE bool
1072-
_bsonVisitIterAs_bool (void)
1070+
_bsonVisitIterAs_boolean (void)
10731071
{
10741072
return bson_iter_as_bool (&bsonVisitIter);
10751073
}
10761074

1077-
static BSON_INLINE bool
1078-
_bsonVisitIterAs__Bool (void)
1079-
{
1080-
return _bsonVisitIterAs_bool ();
1081-
}
1082-
10831075
#define bsonAs(Type) _bsonDSL_paste (_bsonVisitIterAs_, Type) ()
10841076

10851077
/// Convert the given argument into a string without inhibitting macro expansion

src/common/bson-dsl.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Result:
5050
### A Simple "okay"
5151

5252
```c
53-
bsonBuildDecl(e, kv("okay", bool(true)));
53+
bsonBuildDecl(e, kv("okay", boolean(true)));
5454
```
5555
5656
Result:
@@ -245,7 +245,7 @@ appended to a document or array.
245245
Generates a BSON null value.
246246

247247

248-
#### `bool(bool b)`
248+
#### `boolean(bool b)`
249249

250250
Generate a BSON boolean value from the given C boolean expression.
251251

@@ -642,7 +642,7 @@ match.
642642
Matches if the element's current type matches the `TypeName` `t`.
643643
644644
The `TypeName`s are: `double`, `utf8`, `doc`, `array`, `binary`, `undefined`,
645-
`oid`, `bool`, `date_time`, `null`, `regex`, `dbpointer`, `code`, `codewscope`,
645+
`oid`, `boolean`, `date_time`, `null`, `regex`, `dbpointer`, `code`, `codewscope`,
646646
`int32`, `timestamp`, `int64`, and `decimal128`.
647647
648648
@@ -858,7 +858,7 @@ bsonParse(
858858
find(key("readonly"),
859859
// bsonPredicate() will evaluate a predicate on bsonVisitIter
860860
// (which here points to the "readonly" property in "input")
861-
append(*output, kv("readonly", bool(bsonPredicate(truthy))))));
861+
append(*output, kv("readonly", boolean(bsonPredicate(truthy))))));
862862
```
863863

864864

src/libmongoc/src/mongoc/mongoc-uri.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,9 +1633,9 @@ _mongoc_uri_build_write_concern (mongoc_uri_t *uri, bson_error_t *error)
16331633
uri->write_concern = write_concern;
16341634

16351635
bsonParse (uri->options,
1636-
find (iKeyWithType (MONGOC_URI_SAFE, bool),
1636+
find (iKeyWithType (MONGOC_URI_SAFE, boolean),
16371637
do (mongoc_write_concern_set_w (write_concern,
1638-
bsonAs (bool) ? 1 : MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED))));
1638+
bsonAs (boolean) ? 1 : MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED))));
16391639

16401640
if (bsonParseError) {
16411641
MONGOC_URI_ERROR (error, "Error while parsing 'safe' URI option: %s", bsonParseError);
@@ -1651,8 +1651,8 @@ _mongoc_uri_build_write_concern (mongoc_uri_t *uri, bson_error_t *error)
16511651
}
16521652

16531653
bsonParse (uri->options,
1654-
find (iKeyWithType (MONGOC_URI_JOURNAL, bool),
1655-
do (mongoc_write_concern_set_journal (write_concern, bsonAs (bool)))));
1654+
find (iKeyWithType (MONGOC_URI_JOURNAL, boolean),
1655+
do (mongoc_write_concern_set_journal (write_concern, bsonAs (boolean)))));
16561656
if (bsonParseError) {
16571657
MONGOC_URI_ERROR (error, "Error while parsing 'journal' URI option: %s", bsonParseError);
16581658
return false;

src/libmongoc/tests/test-mongoc-client-session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,7 @@ test_sessions_snapshot_prose_test_1 (void *ctx)
25572557
mongoc_client_t *client = NULL;
25582558
mongoc_session_opt_t *session_opts = NULL;
25592559
bson_error_t error;
2560-
bool r;
2560+
mongoc_client_session_t *r;
25612561

25622562
BSON_UNUSED (ctx);
25632563

src/libmongoc/tests/test-mongoc-client-side-encryption.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5841,9 +5841,9 @@ CEC_TEST (test_create_encrypted_collection_bad_keyId, const char *const kmsProvi
58415841
bsonBuildDecl (
58425842
ccOpts,
58435843
kv ("encryptedFields",
5844-
doc (kv (
5845-
"fields",
5846-
array (doc (kv ("path", cstr ("ssn")), kv ("bsonType", cstr ("string")), kv ("keyId", bool (true))))))));
5844+
doc (kv ("fields",
5845+
array (doc (
5846+
kv ("path", cstr ("ssn")), kv ("bsonType", cstr ("string")), kv ("keyId", boolean (true))))))));
58475847
mongoc_database_t *const db = mongoc_client_get_database (client, dbName);
58485848
bson_t *const mkey = _make_kms_masterkey (kmsProvider);
58495849
mongoc_collection_t *const coll = mongoc_client_encryption_create_encrypted_collection (

src/libmongoc/tests/unified/entity-map.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
566566
storeDocDupPtr (uri_options)),
567567
// Optional 'useMultipleMongoses' bool
568568
find (key ("useMultipleMongoses"),
569-
if (not(type (bool)), then (error ("'useMultipleMongoses' must be a bool value"))),
569+
if (not(type (boolean)), then (error ("'useMultipleMongoses' must be a bool value"))),
570570
do (use_multiple_mongoses_set = true),
571571
storeBool (use_multiple_mongoses)),
572572
// Events to observe:
@@ -611,18 +611,18 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
611611
else (error ("Missing 'version' property in 'serverApi' object")),
612612
// Toggle strictness:
613613
find (key ("strict"),
614-
if (not(type (bool)), then (error ("'serverApi.strict' must be a bool"))),
615-
do (mongoc_server_api_strict (api, bsonAs (bool)))),
614+
if (not(type (boolean)), then (error ("'serverApi.strict' must be a bool"))),
615+
do (mongoc_server_api_strict (api, bsonAs (boolean)))),
616616
// Toggle deprecation errors:
617617
find (key ("deprecationErrors"),
618-
if (not(type (bool)), then (error ("serverApi.deprecationErrors must be a bool"))),
619-
do (mongoc_server_api_deprecation_errors (api, bsonAs (bool)))))),
618+
if (not(type (boolean)), then (error ("serverApi.deprecationErrors must be a bool"))),
619+
do (mongoc_server_api_deprecation_errors (api, bsonAs (boolean)))))),
620620
// Toggle observation of sensitive commands
621621
find (key ("observeSensitiveCommands"),
622-
if (not(type (bool)), then (error ("'observeSensitiveCommands' must be a bool"))),
622+
if (not(type (boolean)), then (error ("'observeSensitiveCommands' must be a bool"))),
623623
do ({
624624
bool *p = entity->observe_sensitive_commands = bson_malloc (sizeof (bool));
625-
*p = bsonAs (bool);
625+
*p = bsonAs (boolean);
626626
})),
627627
// Which events should be available as entities:
628628
find (key ("storeEventsAsEntities"),

src/libmongoc/tests/unified/operation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,7 +3272,7 @@ operation_rename (test_t *test, operation_t *op, result_t *result, bson_error_t
32723272
const char *object = op->object;
32733273
bson_parser_t *bp = bson_parser_new ();
32743274
bool ret = false;
3275-
bool *drop_target = false;
3275+
bool *drop_target = NULL;
32763276
char *new_name = NULL;
32773277
bson_parser_utf8 (bp, "to", &new_name);
32783278
bson_parser_bool_optional (bp, "dropTarget", &drop_target);
@@ -3299,7 +3299,7 @@ operation_rename (test_t *test, operation_t *op, result_t *result, bson_error_t
32993299

33003300
// Rename the collection in the server,
33013301
mongoc_collection_t *coll = ent->value;
3302-
if (!mongoc_collection_rename (coll, NULL, new_name, drop_target, error)) {
3302+
if (!mongoc_collection_rename (coll, NULL, new_name, drop_target ? *drop_target : false, error)) {
33033303
goto done;
33043304
}
33053305
result_from_ok (result);

0 commit comments

Comments
 (0)