Skip to content

CXX-3251 remove workaround for big_string length in API examples #1357

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
merged 4 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Only LIBMONGOC_DOWNLOAD_VERSION needs to be updated when pinning to an unreleased commit.
# If pinning to an unreleased commit, create a "Blocked" JIRA ticket with
# a "depends on" link to the appropriate C Driver version release ticket.
MONGOC_VERSION_MINIMUM = '1.30.1'
MONGOC_VERSION_MINIMUM = '57bffac11fde38d1ce097bb22fb5322a6114d644' # CXX-3103: bump to 2.0.0 once released.


class InstallCDriver(Function):
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/generated_configs/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ functions:
type: setup
params:
updates:
- { key: mongoc_version_minimum, value: 1.30.1 }
- { key: mongoc_version_minimum, value: 57bffac11fde38d1ce097bb22fb5322a6114d644 }
- command: subprocess.exec
type: setup
params:
Expand Down
3 changes: 3 additions & 0 deletions .evergreen/scripts/install-c-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ tar xzf mongo-c-driver.tar.gz --directory "${mongoc_dir}" --strip-components=1
# C Driver needs VERSION_CURRENT to compute BUILD_VERSION.
if [[ -f "${mongoc_dir}/VERSION_CURRENT" ]]; then
: # Use the existing VERSION_CURRENT bundled with the release tarball.

# CXX-3103: overwrite incompatible build versions to support the upcoming 2.0.0 release.
echo "1.31.0-pre" >|"${mongoc_dir}/VERSION_CURRENT"
else
# RegEx pattern to match SemVer strings. See https://semver.org/.
declare -r semver_regex="^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ set(LIBBSON_REQUIRED_ABI_VERSION 1.0)

# Also update etc/purls.txt.
set(LIBMONGOC_REQUIRED_VERSION 1.30.0)
set(LIBMONGOC_DOWNLOAD_VERSION 1.30.1)
set(LIBMONGOC_DOWNLOAD_VERSION 57bffac11fde38d1ce097bb22fb5322a6114d644)
set(LIBMONGOC_REQUIRED_ABI_VERSION 1.0)

set(NEED_DOWNLOAD_C_DRIVER false)
Expand Down
3 changes: 1 addition & 2 deletions examples/api/bsoncxx/examples/bson_errors/big_string.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ namespace examples {
// Used to trigger builder append failure.
struct big_string {
// BSON_SIZE_MAX == 0x7FFFFFFF
// Leave some room for CDRIVER-5732.
std::size_t length{static_cast<std::size_t>(std::numeric_limits<std::int32_t>::max() - 32u)};
std::size_t length{static_cast<std::size_t>(std::numeric_limits<std::int32_t>::max())};

// Allocate an UNINITIALIZED blob of data that will not be accessed due to length checks.
// Leaving memory unitialized (rather than zero-init) should hopefully avoid slow and expensive
Expand Down
15 changes: 8 additions & 7 deletions src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/builder/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,14 @@ core& core::append(types::b_double const& value) {

core& core::append(types::b_string const& value) {
stdx::string_view key = _impl->next_key();

if (!bson_append_utf8(
_impl->back(),
key.data(),
static_cast<std::int32_t>(key.length()),
value.value.data(),
static_cast<std::int32_t>(value.value.length()))) {
std::size_t value_length = value.value.length();

if (value_length > std::size_t{INT32_MAX} || !bson_append_utf8(
_impl->back(),
key.data(),
static_cast<std::int32_t>(key.length()),
value.value.data(),
static_cast<std::int32_t>(value_length))) {
throw bsoncxx::v_noabi::exception{error_code::k_cannot_append_string};
}

Expand Down