Skip to content

New internal bounded string append APIs #1816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
39 commits merged into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7897c11
test the utf8-oblivious behavior of bson_string_truncate
Dec 18, 2024
6ae7b5b
document the utf8-oblivious behavior of bson_string_truncate
Dec 18, 2024
2c66192
new internal mcommon_string, mcommon_string_append, mcommon_json_appe…
Dec 18, 2024
0f672b3
some tests for UTF-8 preserving string truncation
Dec 30, 2024
9716f3c
comment typo fix
Dec 30, 2024
85391bf
comment typo
Dec 30, 2024
8b2ed78
fix size_t checks with incorrect signedness
Dec 30, 2024
ba94602
unit test for printf truncation between utf-8 code points
Dec 30, 2024
52e851b
fix for missing TXT string length validation
Dec 31, 2024
a801abb
unsigned comparison in mcommon_string_append_selected_chars assert
Dec 31, 2024
d5abbf4
comment clarification
Dec 31, 2024
6bf9e03
unnecessary printf
Dec 31, 2024
b82a62d
whitespace
Dec 31, 2024
19488c0
another range check on type conversion
Dec 31, 2024
c641bac
additional pedantic format_result conversion
Dec 31, 2024
8ccf1a0
fputc instead of fwrite
Dec 31, 2024
c794320
Additional non-null ASSERT coverage requested in code review
Jan 8, 2025
a056be8
destroy_into_buffer -> destroy_with_steal
Jan 8, 2025
9d37056
comment typo
Jan 9, 2025
ee5cf97
Update src/common/src/common-string-private.h
Jan 9, 2025
2a25de0
Merge remote-tracking branch 'origin/CDRIVER-4814' into CDRIVER-4814
Jan 9, 2025
10c57a2
Update src/libbson/src/bson/bson-iso8601.c
Jan 9, 2025
f9897ae
Update src/libbson/src/bson/bson-utf8.c
Jan 9, 2025
5c46c2c
Feedback, remove /bson/string/alloc and /bson/string/append_ex tests
Jan 10, 2025
7263e74
Feedback, add suggested NEWS item from Kevin
Jan 10, 2025
ef18bb5
Additional _bson_string_alloc test removal
Jan 10, 2025
5ea32b2
rename mcommon_string_append functions to clarify objects and lifetimes
Jan 10, 2025
d39f565
Merge branch 'master' into CDRIVER-4814
Jan 10, 2025
b689ca0
Comment about mcommon_string_new_as_fixed_capacity_append param
Jan 11, 2025
c67053a
Additional comment for mcommon_string_from_append
Jan 11, 2025
d256748
Fix comment for _mongoc_http_render_request_head
Jan 11, 2025
397daf7
Convenience methods for accessing the str and len from an append dire…
Jan 11, 2025
9b67b8b
Clarify local var naming in mcommon_json_append_value_double
Jan 11, 2025
3d02f7b
Add mcommon_string_from_append_clear convenience method
Jan 11, 2025
dda082d
Update test_mongoc_ssl_opts_from_bson with new mcommon_string_append …
Jan 11, 2025
de3e7fd
mcommon_string_new_with_capacity_as_append
Jan 11, 2025
0218303
some unsigned literals why not
Jan 11, 2025
8ff0cde
additional unsigned literal that escaped the previous patch
Jan 11, 2025
e804030
disambiguate between concurrency behavior and string truncation behav…
Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/common/src/common-bits-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2009-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "common-prelude.h"

#ifndef MONGO_C_DRIVER_COMMON_BITS_PRIVATE_H
#define MONGO_C_DRIVER_COMMON_BITS_PRIVATE_H

#include <bson/bson.h>


// Round up to the next power of two uint32_t value. Saturates on overflow.
static BSON_INLINE uint32_t
mcommon_next_power_of_two_u32 (uint32_t v)
{
if (v == 0) {
return 1;
}

// https://graphics.stanford.edu/%7Eseander/bithacks.html#RoundUpPowerOf2
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;

if (v == 0) {
return UINT32_MAX;
} else {
return v;
}
}


#endif /* MONGO_C_DRIVER_COMMON_BITS_PRIVATE_H */
Loading