Skip to content

Commit f3bc6e3

Browse files
authored
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 66841d0 commit f3bc6e3

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
@@ -2578,7 +2578,7 @@ test_sessions_snapshot_prose_test_1 (void *ctx)
25782578
mongoc_client_t *client = NULL;
25792579
mongoc_session_opt_t *session_opts = NULL;
25802580
bson_error_t error;
2581-
bool r;
2581+
mongoc_client_session_t *r;
25822582

25832583
BSON_UNUSED (ctx);
25842584

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5842,9 +5842,9 @@ CEC_TEST (test_create_encrypted_collection_bad_keyId, const char *const kmsProvi
58425842
bsonBuildDecl (
58435843
ccOpts,
58445844
kv ("encryptedFields",
5845-
doc (kv (
5846-
"fields",
5847-
array (doc (kv ("path", cstr ("ssn")), kv ("bsonType", cstr ("string")), kv ("keyId", bool (true))))))));
5845+
doc (kv ("fields",
5846+
array (doc (
5847+
kv ("path", cstr ("ssn")), kv ("bsonType", cstr ("string")), kv ("keyId", boolean (true))))))));
58485848
mongoc_database_t *const db = mongoc_client_get_database (client, dbName);
58495849
bson_t *const mkey = _make_kms_masterkey (kmsProvider);
58505850
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
@@ -638,7 +638,7 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
638638
storeDocDupPtr (uri_options)),
639639
// Optional 'useMultipleMongoses' bool
640640
find (key ("useMultipleMongoses"),
641-
if (not(type (bool)), then (error ("'useMultipleMongoses' must be a bool value"))),
641+
if (not(type (boolean)), then (error ("'useMultipleMongoses' must be a bool value"))),
642642
do (use_multiple_mongoses_set = true),
643643
storeBool (use_multiple_mongoses)),
644644
// Events to observe:
@@ -683,18 +683,18 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
683683
else (error ("Missing 'version' property in 'serverApi' object")),
684684
// Toggle strictness:
685685
find (key ("strict"),
686-
if (not(type (bool)), then (error ("'serverApi.strict' must be a bool"))),
687-
do (mongoc_server_api_strict (api, bsonAs (bool)))),
686+
if (not(type (boolean)), then (error ("'serverApi.strict' must be a bool"))),
687+
do (mongoc_server_api_strict (api, bsonAs (boolean)))),
688688
// Toggle deprecation errors:
689689
find (key ("deprecationErrors"),
690-
if (not(type (bool)), then (error ("serverApi.deprecationErrors must be a bool"))),
691-
do (mongoc_server_api_deprecation_errors (api, bsonAs (bool)))))),
690+
if (not(type (boolean)), then (error ("serverApi.deprecationErrors must be a bool"))),
691+
do (mongoc_server_api_deprecation_errors (api, bsonAs (boolean)))))),
692692
// Toggle observation of sensitive commands
693693
find (key ("observeSensitiveCommands"),
694-
if (not(type (bool)), then (error ("'observeSensitiveCommands' must be a bool"))),
694+
if (not(type (boolean)), then (error ("'observeSensitiveCommands' must be a bool"))),
695695
do ({
696696
bool *p = entity->observe_sensitive_commands = bson_malloc (sizeof (bool));
697-
*p = bsonAs (bool);
697+
*p = bsonAs (boolean);
698698
})),
699699
// Which events should be available as entities:
700700
find (key ("storeEventsAsEntities"),

src/libmongoc/tests/unified/operation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,7 +3555,7 @@ operation_rename (test_t *test, operation_t *op, result_t *result, bson_error_t
35553555
const char *object = op->object;
35563556
bson_parser_t *bp = bson_parser_new ();
35573557
bool ret = false;
3558-
bool *drop_target = false;
3558+
bool *drop_target = NULL;
35593559
char *new_name = NULL;
35603560
bson_parser_utf8 (bp, "to", &new_name);
35613561
bson_parser_bool_optional (bp, "dropTarget", &drop_target);
@@ -3582,7 +3582,7 @@ operation_rename (test_t *test, operation_t *op, result_t *result, bson_error_t
35823582

35833583
// Rename the collection in the server,
35843584
mongoc_collection_t *coll = ent->value;
3585-
if (!mongoc_collection_rename (coll, NULL, new_name, drop_target, error)) {
3585+
if (!mongoc_collection_rename (coll, NULL, new_name, drop_target ? *drop_target : false, error)) {
35863586
goto done;
35873587
}
35883588
result_from_ok (result);

0 commit comments

Comments
 (0)