Skip to content

Commit d28dcbf

Browse files
authored
SWIFT-1567 Vendor libmongoc 1.22.0-beta0 (#761)
1 parent ae7a126 commit d28dcbf

File tree

163 files changed

+7984
-2106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+7984
-2106
lines changed

Sources/CLibMongoC/bson/bson-decimal128.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ bson_decimal128_from_string_w_len (const char *string, /* IN */
542542
continue;
543543
}
544544

545-
if (ndigits_stored < 34) {
545+
if (ndigits_stored < BSON_DECIMAL128_MAX_DIGITS) {
546546
if (*str_read != '0' || found_nonzero) {
547547
if (!found_nonzero) {
548548
first_nonzero = ndigits_read;
@@ -634,7 +634,7 @@ bson_decimal128_from_string_w_len (const char *string, /* IN */
634634
/* Shift exponent to significand and decrease */
635635
last_digit++;
636636

637-
if (last_digit - first_digit > BSON_DECIMAL128_MAX_DIGITS) {
637+
if (last_digit - first_digit >= BSON_DECIMAL128_MAX_DIGITS) {
638638
/* The exponent is too great to shift into the significand. */
639639
if (significant_digits == 0) {
640640
/* Value is zero, we are allowed to clamp the exponent. */

Sources/CLibMongoC/bson/bson-iter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,8 +1894,8 @@ bson_iter_visit_all (bson_iter_t *iter, /* INOUT */
18941894
const bson_visitor_t *visitor, /* IN */
18951895
void *data) /* IN */
18961896
{
1897-
uint32_t bson_type;
1898-
const char *key;
1897+
uint32_t bson_type = 0;
1898+
const char *key = NULL;
18991899
bool unsupported;
19001900

19011901
BSON_ASSERT (iter);

Sources/CLibMongoC/bson/bson-json.c

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ _bson_json_parse_binary_elem (bson_json_reader_t *reader,
870870

871871
if (bs == BSON_JSON_LF_BINARY) {
872872
data->binary.has_binary = true;
873-
binary_len = COMMON_PREFIX (bson_b64_pton (val_w_null, NULL, 0));
873+
binary_len = mcommon_b64_pton (val_w_null, NULL, 0);
874874
if (binary_len < 0) {
875875
_bson_json_read_set_error (
876876
reader,
@@ -879,9 +879,9 @@ _bson_json_parse_binary_elem (bson_json_reader_t *reader,
879879
}
880880

881881
_bson_json_buf_ensure (&bson->bson_type_buf[0], (size_t) binary_len + 1);
882-
if (COMMON_PREFIX (bson_b64_pton (val_w_null,
883-
bson->bson_type_buf[0].buf,
884-
(size_t) binary_len + 1) < 0)) {
882+
if (mcommon_b64_pton (val_w_null,
883+
bson->bson_type_buf[0].buf,
884+
(size_t) binary_len + 1) < 0) {
885885
_bson_json_read_set_error (
886886
reader,
887887
"Invalid input string \"%s\", looking for base64-encoded binary",
@@ -1178,18 +1178,59 @@ _bson_json_read_start_map (bson_json_reader_t *reader) /* IN */
11781178
BASIC_CB_PREAMBLE;
11791179

11801180
if (bson->read_state == BSON_JSON_IN_BSON_TYPE) {
1181-
if (bson->bson_state == BSON_JSON_LF_DATE) {
1181+
switch (bson->bson_state) {
1182+
case BSON_JSON_LF_DATE:
11821183
bson->read_state = BSON_JSON_IN_BSON_TYPE_DATE_NUMBERLONG;
1183-
} else if (bson->bson_state == BSON_JSON_LF_BINARY) {
1184+
break;
1185+
case BSON_JSON_LF_BINARY:
11841186
bson->read_state = BSON_JSON_IN_BSON_TYPE_BINARY_VALUES;
1185-
} else if (bson->bson_state == BSON_JSON_LF_TYPE) {
1187+
break;
1188+
case BSON_JSON_LF_TYPE:
11861189
/* special case, we started parsing {$type: {$numberInt: "2"}} and we
11871190
* expected a legacy Binary format. now we see the second "{", so
11881191
* backtrack and parse $type query operator. */
11891192
bson->read_state = BSON_JSON_IN_START_MAP;
11901193
STACK_PUSH_DOC (bson_append_document_begin (
11911194
STACK_BSON_PARENT, key, len, STACK_BSON_CHILD));
11921195
_bson_json_save_map_key (bson, (const uint8_t *) "$type", 5);
1196+
break;
1197+
case BSON_JSON_LF_CODE:
1198+
case BSON_JSON_LF_DECIMAL128:
1199+
case BSON_JSON_LF_DOUBLE:
1200+
case BSON_JSON_LF_INT32:
1201+
case BSON_JSON_LF_INT64:
1202+
case BSON_JSON_LF_MAXKEY:
1203+
case BSON_JSON_LF_MINKEY:
1204+
case BSON_JSON_LF_OID:
1205+
case BSON_JSON_LF_OPTIONS:
1206+
case BSON_JSON_LF_REGEX:
1207+
/**
1208+
* NOTE: A read_state of BSON_JSON_IN_BSON_TYPE is used when "$regex" is
1209+
* found, but BSON_JSON_IN_BSON_TYPE_REGEX_STARTMAP is used for
1210+
* "$regularExpression", which will instead go to a below 'if else' branch
1211+
* instead of this switch statement. They're both called "regex" in their
1212+
* respective enumerators, but they behave differently when parsing.
1213+
*/
1214+
// fallthrough
1215+
case BSON_JSON_LF_REGULAR_EXPRESSION_OPTIONS:
1216+
case BSON_JSON_LF_REGULAR_EXPRESSION_PATTERN:
1217+
case BSON_JSON_LF_SYMBOL:
1218+
case BSON_JSON_LF_UNDEFINED:
1219+
case BSON_JSON_LF_UUID:
1220+
// These special keys do not expect objects as their values. Fail.
1221+
_bson_json_read_set_error (
1222+
reader,
1223+
"Unexpected nested object value for \"%s\" key",
1224+
reader->bson.unescaped.buf);
1225+
break;
1226+
case BSON_JSON_LF_DBPOINTER:
1227+
case BSON_JSON_LF_SCOPE:
1228+
case BSON_JSON_LF_TIMESTAMP_I:
1229+
case BSON_JSON_LF_TIMESTAMP_T:
1230+
default:
1231+
// These special LF keys aren't handled with BSON_JSON_IN_BSON_TYPE
1232+
BSON_UNREACHABLE (
1233+
"These LF values are handled with a different read_state");
11931234
}
11941235
} else if (bson->read_state == BSON_JSON_IN_BSON_TYPE_TIMESTAMP_STARTMAP) {
11951236
bson->read_state = BSON_JSON_IN_BSON_TYPE_TIMESTAMP_VALUES;

Sources/CLibMongoC/bson/bson-md5.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
void
88
bson_md5_init (bson_md5_t *pms)
99
{
10-
COMMON_PREFIX (_bson_md5_init (pms));
10+
mcommon_md5_init (pms);
1111
}
1212

1313

1414
void
1515
bson_md5_append (bson_md5_t *pms, const uint8_t *data, uint32_t nbytes)
1616
{
17-
COMMON_PREFIX (_bson_md5_append (pms, data, nbytes));
17+
mcommon_md5_append (pms, data, nbytes);
1818
}
1919

2020
void
2121
bson_md5_finish (bson_md5_t *pms, uint8_t digest[16])
2222
{
23-
COMMON_PREFIX (_bson_md5_finish (pms, digest));
23+
mcommon_md5_finish (pms, digest);
2424
}

Sources/CLibMongoC/bson/bson.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,10 +2696,9 @@ _bson_as_json_visit_binary (const bson_iter_t *iter,
26962696
size_t b64_len;
26972697
char *b64;
26982698

2699-
b64_len = COMMON_PREFIX (bson_b64_ntop_calculate_target_size (v_binary_len));
2699+
b64_len = mcommon_b64_ntop_calculate_target_size (v_binary_len);
27002700
b64 = bson_malloc0 (b64_len);
2701-
BSON_ASSERT (
2702-
COMMON_PREFIX (bson_b64_ntop (v_binary, v_binary_len, b64, b64_len) != -1));
2701+
BSON_ASSERT (mcommon_b64_ntop (v_binary, v_binary_len, b64, b64_len) != -1);
27032702

27042703
if (state->mode == BSON_JSON_MODE_CANONICAL ||
27052704
state->mode == BSON_JSON_MODE_RELAXED) {

Sources/CLibMongoC/bson/jsonsl.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,23 @@ jsonsl_feed(jsonsl_t jsn, const jsonsl_char_t *bytes, size_t nbytes)
457457
} else if (state->special_flags & JSONSL_SPECIALf_NULL ||
458458
state->special_flags & JSONSL_SPECIALf_NAN) {
459459
/* previous char was "n", are we parsing null or nan? */
460-
if (CUR_CHAR != 'u') {
460+
const bool not_u = CUR_CHAR != 'u';
461+
const bool not_a = tolower (CUR_CHAR) != 'a';
462+
if (not_u) {
461463
state->special_flags &= ~JSONSL_SPECIALf_NULL;
462464
}
463-
464-
if (tolower(CUR_CHAR) != 'a') {
465+
if (not_a) {
465466
state->special_flags &= ~JSONSL_SPECIALf_NAN;
466467
}
468+
if (not_u && not_a) {
469+
/* This verify will always fail, as we have an 'n'
470+
* followed by a character that is neither 'a' nor 'u'
471+
* (and hence cannot be "null"). The purpose of this
472+
* VERIFY_SPECIAL is to generate an error in tokenization
473+
* that stops if a bare 'n' cannot possibly be a "nan" or
474+
* a "null". */
475+
VERIFY_SPECIAL ("null", 4);
476+
}
467477
#endif
468478
}
469479
INCR_METRIC(SPECIAL_FASTPATH);

Sources/CLibMongoC/common/common-b64.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ static const char Pad64 = '=';
113113
* characters followed by one "=" padding character.
114114
*/
115115

116-
int COMMON_PREFIX (bson_b64_ntop) (uint8_t const *src,
117-
size_t srclength,
118-
char *target,
119-
size_t targsize)
116+
int
117+
mcommon_b64_ntop (uint8_t const *src,
118+
size_t srclength,
119+
char *target,
120+
size_t targsize)
120121
{
121122
size_t datalength = 0;
122123
uint8_t input[3];
@@ -517,9 +518,8 @@ mongoc_b64_pton_len (char const *src)
517518
}
518519

519520

520-
int COMMON_PREFIX (bson_b64_pton) (char const *src,
521-
uint8_t *target,
522-
size_t targsize)
521+
int
522+
mcommon_b64_pton (char const *src, uint8_t *target, size_t targsize)
523523
{
524524
static mongoc_common_once_t once = MONGOC_COMMON_ONCE_INIT;
525525

@@ -535,7 +535,8 @@ int COMMON_PREFIX (bson_b64_pton) (char const *src,
535535
return mongoc_b64_pton_len (src);
536536
}
537537

538-
size_t COMMON_PREFIX (bson_b64_ntop_calculate_target_size) (size_t raw_size)
538+
size_t
539+
mcommon_b64_ntop_calculate_target_size (size_t raw_size)
539540
{
540541
size_t num_bits = raw_size * 8;
541542
/* Calculate how many groups of six bits this contains, adding 5 to round up
@@ -547,8 +548,8 @@ size_t COMMON_PREFIX (bson_b64_ntop_calculate_target_size) (size_t raw_size)
547548
return num_b64_chars_with_padding + 1;
548549
}
549550

550-
size_t COMMON_PREFIX (bson_b64_pton_calculate_target_size) (
551-
size_t base64_encoded_size)
551+
size_t
552+
mcommon_b64_pton_calculate_target_size (size_t base64_encoded_size)
552553
{
553554
/* Without inspecting the data, we don't know how many padding characters
554555
* there are. Assuming none, that means each character represents 6 bits of

Sources/CLibMongoC/common/common-md5.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ bson_md5_process (bson_md5_t *md5, const uint8_t *data)
324324
md5->abcd[3] += d;
325325
}
326326

327-
void COMMON_PREFIX (_bson_md5_init) (bson_md5_t *pms)
327+
void
328+
mcommon_md5_init (bson_md5_t *pms)
328329
{
329330
pms->count[0] = pms->count[1] = 0;
330331
pms->abcd[0] = 0x67452301;
@@ -333,9 +334,8 @@ void COMMON_PREFIX (_bson_md5_init) (bson_md5_t *pms)
333334
pms->abcd[3] = 0x10325476;
334335
}
335336

336-
void COMMON_PREFIX (_bson_md5_append) (bson_md5_t *pms,
337-
const uint8_t *data,
338-
uint32_t nbytes)
337+
void
338+
mcommon_md5_append (bson_md5_t *pms, const uint8_t *data, uint32_t nbytes)
339339
{
340340
const uint8_t *p = data;
341341
int left = nbytes;
@@ -373,7 +373,8 @@ void COMMON_PREFIX (_bson_md5_append) (bson_md5_t *pms,
373373
}
374374

375375

376-
void COMMON_PREFIX (_bson_md5_finish) (bson_md5_t *pms, uint8_t digest[16])
376+
void
377+
mcommon_md5_finish (bson_md5_t *pms, uint8_t digest[16])
377378
{
378379
static const uint8_t pad[64] = {
379380
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -386,10 +387,9 @@ void COMMON_PREFIX (_bson_md5_finish) (bson_md5_t *pms, uint8_t digest[16])
386387
for (i = 0; i < 8; ++i)
387388
data[i] = (uint8_t) (pms->count[i >> 2] >> ((i & 3) << 3));
388389
/* Pad to 56 bytes mod 64. */
389-
COMMON_PREFIX (_bson_md5_append)
390-
(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
390+
mcommon_md5_append (pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
391391
/* Append the length. */
392-
COMMON_PREFIX (_bson_md5_append) (pms, data, sizeof (data));
392+
mcommon_md5_append (pms, data, sizeof (data));
393393
for (i = 0; i < 16; ++i)
394394
digest[i] = (uint8_t) (pms->abcd[i >> 2] >> ((i & 3) << 3));
395395
}

Sources/CLibMongoC/common/common-thread.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,42 @@
1717
#include "CLibMongoC_common-thread-private.h"
1818

1919
#if defined(BSON_OS_UNIX)
20-
int COMMON_PREFIX (thread_create) (bson_thread_t *thread,
21-
BSON_THREAD_FUN_TYPE (func),
22-
void *arg)
20+
int
21+
mcommon_thread_create (bson_thread_t *thread,
22+
BSON_THREAD_FUN_TYPE (func),
23+
void *arg)
2324
{
2425
return pthread_create (thread, NULL, func, arg);
2526
}
26-
int COMMON_PREFIX (thread_join) (bson_thread_t thread)
27+
int
28+
mcommon_thread_join (bson_thread_t thread)
2729
{
2830
return pthread_join (thread, NULL);
2931
}
3032

3133
#if defined(MONGOC_ENABLE_DEBUG_ASSERTIONS) && defined(BSON_OS_UNIX)
32-
bool COMMON_PREFIX (mutex_is_locked) (bson_mutex_t *mutex)
34+
bool
35+
mcommon_mutex_is_locked (bson_mutex_t *mutex)
3336
{
3437
return mutex->valid_tid &&
3538
pthread_equal (pthread_self (), mutex->lock_owner);
3639
}
3740
#endif
3841

3942
#else
40-
int COMMON_PREFIX (thread_create) (bson_thread_t *thread,
41-
BSON_THREAD_FUN_TYPE (func),
42-
void *arg)
43+
int
44+
mcommon_thread_create (bson_thread_t *thread,
45+
BSON_THREAD_FUN_TYPE (func),
46+
void *arg)
4347
{
4448
*thread = (HANDLE) _beginthreadex (NULL, 0, func, arg, 0, NULL);
4549
if (0 == *thread) {
4650
return 1;
4751
}
4852
return 0;
4953
}
50-
int COMMON_PREFIX (thread_join) (bson_thread_t thread)
54+
int
55+
mcommon_thread_join (bson_thread_t thread)
5156
{
5257
int ret;
5358

0 commit comments

Comments
 (0)