Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9fc87c6
v1: impls
eramongodb Jul 28, 2025
b034251
v1: tests
eramongodb Jul 28, 2025
e51551b
Merge remote-tracking branch 'upstream/master' into cxx-abi-v1-impls
eramongodb Jul 30, 2025
f258f76
Add some basic find() and subscript assertions
eramongodb Aug 6, 2025
25354e4
Fix doc comments for BSON array data
eramongodb Aug 6, 2025
b2a4393
Do not violate precondition in our own test cases
eramongodb Aug 6, 2025
1bc5302
Assert resulting document length in invalid_length assertions
eramongodb Aug 6, 2025
877cd50
Remove unused values array
eramongodb Aug 6, 2025
9e3d254
Fix view vs. value in btype_vs_value static assertions
eramongodb Aug 6, 2025
2cfc2d7
Move T -> T::impl conversion functions into T::impl
eramongodb Aug 6, 2025
8de4ee1
ClangFormat
eramongodb Aug 6, 2025
a3fd459
Merge remote-tracking branch 'upstream/master' into cxx-abi-v1-impls
eramongodb Aug 8, 2025
1a94bf7
Merge remote-tracking branch 'upstream/master' into HEAD
eramongodb Aug 14, 2025
2b76d2c
Distinguish "missing" vs. "invalid" after calling bson_iter_*
eramongodb Aug 14, 2025
4c6b735
Use std::array instead of raw arrays
eramongodb Aug 14, 2025
81fa5c0
BSON binary subtype values 128-255 are "user defined"
eramongodb Aug 14, 2025
22c67c2
Minor mem-list-init improvement
eramongodb Aug 14, 2025
4258c04
Make WSAGuard Windows-only and static local
eramongodb Aug 14, 2025
116890e
Use bsoncxx::make_unique_for_overwrite
eramongodb Aug 14, 2025
3de63ff
Fix and cleanup include directives
eramongodb Aug 14, 2025
e5c7fa9
Use common format for unknown error codes
eramongodb Aug 14, 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
4 changes: 4 additions & 0 deletions src/bsoncxx/include/bsoncxx/v1/oid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class oid {
/// [`bson_oid_init`](https://mongoc.org/libbson/current/bson_oid_init.html) function with the default
/// [`bson_context_t`](https://mongoc.org/libbson/current/bson_context_t.html).
///
/// @important On Windows only, the first call to this function initializes a static local variable which loads the
/// Winsock DLL by calling `WSAStartup()`. The Winsock DLL is unloaded by calling `WSACleanup()` when the static
/// local variable is destroyed.
///
/// @throws bsoncxx::v1::exception (on Windows only) with a `std::system_category()` error code
/// (as returned by
/// [`WSAGetLastError()`](https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsagetlasterror))
Expand Down
4 changes: 3 additions & 1 deletion src/bsoncxx/include/bsoncxx/v1/types/id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ enum class binary_subtype : std::uint8_t {
k_column = 0x07, ///< Compressed BSON column.
k_sensitive = 0x08, ///< Sensitive.
k_vector = 0x09, ///< Vector.
k_user = 0x80, ///< User defined.
k_user = 0x80, ///< User defined (up to 0xFF, inclusive).
};

///
/// Return the name of the enumerator (e.g. `"binary"` given `k_binary`).
///
/// @note Values in the range [0x80, 0xFF] are all equivalent to "k_user".
///
/// @attention This feature is experimental! It is not ready for use!
///
BSONCXX_ABI_EXPORT_CDECL(std::string) to_string(binary_subtype rhs);
Expand Down
4 changes: 4 additions & 0 deletions src/bsoncxx/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ set_dist_list(src_bsoncxx_lib_DIST
bsoncxx/v_noabi/bsoncxx/types/bson_value/value.hh
bsoncxx/v1/config/config.hpp.in
bsoncxx/v1/config/version.hpp.in
bsoncxx/v1/document/view.hh
bsoncxx/v1/element/view.hh
bsoncxx/v1/types/value.hh
bsoncxx/v1/types/view.hh
)
39 changes: 39 additions & 0 deletions src/bsoncxx/lib/bsoncxx/v1/array/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@

//

#include <bsoncxx/v1/exception.hpp>

#include <bsoncxx/v1/document/view.hh>
#include <bsoncxx/v1/element/view.hh>

#include <cstdint>

#include <bsoncxx/private/bson.hh>
#include <bsoncxx/private/immortal.hh>
#include <bsoncxx/private/itoa.hh>
#include <bsoncxx/private/type_traits.hh>

namespace bsoncxx {
namespace v1 {
namespace array {

using code = v1::document::view::errc;

static_assert(is_regular<view>::value, "bsoncxx::v1::array::view must be regular");
static_assert(is_semitrivial<view>::value, "bsoncxx::v1::array::view must be semitrivial");

Expand All @@ -30,6 +42,33 @@ static_assert(
is_nothrow_moveable<view::const_iterator>::value,
"bsoncxx::v1::array::view::const_iterator must be nothrow moveable");

view::const_iterator view::find(std::uint32_t i) const {
if (!_view) {
return this->cend();
}
Comment on lines +46 to +48
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not present in v_noabi). This is a consequence of the new, well-defined "invalid" state of an array view.


bsoncxx::itoa key{i};

bson_t bson;

if (!bson_init_static(&bson, _view.data(), _view.length())) {
throw v1::exception{code::invalid_data};
}

bson_iter_t iter;

if (bson_iter_init_find_w_len(&iter, &bson, key.c_str(), static_cast<int>(key.length()))) {
return const_iterator::internal::make_const_iterator(
_view.data(), _view.length(), bson_iter_offset(&iter), bson_iter_key_len(&iter));
}

if (iter.err_off != 0) {
throw v1::exception{code::invalid_data};
}

return this->end();
}

} // namespace array
} // namespace v1
} // namespace bsoncxx
104 changes: 104 additions & 0 deletions src/bsoncxx/lib/bsoncxx/v1/decimal128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,117 @@

//

#include <bsoncxx/v1/exception.hpp>

#include <climits>
#include <cstddef>
#include <string>
#include <system_error>

#include <bsoncxx/private/bson.hh>
#include <bsoncxx/private/immortal.hh>
#include <bsoncxx/private/type_traits.hh>

namespace bsoncxx {
namespace v1 {

using code = v1::decimal128::errc;

static_assert(is_regular<decimal128>::value, "bsoncxx::v1::decimal128 must be regular");
static_assert(is_semitrivial<decimal128>::value, "bsoncxx::v1::decimal128 must be semitrivial");

decimal128::decimal128(v1::stdx::string_view sv) {
if (sv.empty()) {
throw v1::exception{code::empty_string};
}

if (sv.size() > std::size_t{INT_MAX}) {
throw v1::exception{code::invalid_string_length};
}
Comment on lines +39 to +45
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are not present in v_noabi.


bson_decimal128_t d128;

if (!bson_decimal128_from_string_w_len(sv.data(), static_cast<int>(sv.size()), &d128)) {
throw v1::exception{code::invalid_string_data};
}

_high = d128.high;
_low = d128.low;
}

std::string decimal128::to_string() const {
bson_decimal128_t d128;
d128.high = _high;
d128.low = _low;
char str[BSON_DECIMAL128_STRING];
bson_decimal128_to_string(&d128, str);
return {str};
}

std::error_category const& decimal128::error_category() {
class type final : public std::error_category {
char const* name() const noexcept override {
return "bsoncxx::v1::decimal128";
}

std::string message(int v) const noexcept override {
switch (static_cast<code>(v)) {
case code::zero:
return "zero";
case code::empty_string:
return "string must not be empty";
case code::invalid_string_length:
return "length of string is too long (exceeds INT_MAX)";
case code::invalid_string_data:
return "string is not a valid Decimal128 representation";
default:
return std::string(this->name()) + ':' + std::to_string(v);
}
}

bool equivalent(int v, std::error_condition const& ec) const noexcept override {
if (ec.category() == v1::source_error_category()) {
using condition = v1::source_errc;

auto const source = static_cast<condition>(ec.value());

switch (static_cast<code>(v)) {
case code::empty_string:
case code::invalid_string_length:
case code::invalid_string_data:
return source == condition::bsoncxx;

case code::zero:
default:
return false;
}
}

if (ec.category() == v1::type_error_category()) {
using condition = v1::type_errc;

auto const type = static_cast<condition>(ec.value());

switch (static_cast<code>(v)) {
case code::empty_string:
case code::invalid_string_length:
case code::invalid_string_data:
return type == condition::invalid_argument;

case code::zero:
default:
return false;
}
}

return false;
}
};

static bsoncxx::immortal<type> const instance;

return instance.value();
}

} // namespace v1
} // namespace bsoncxx
2 changes: 2 additions & 0 deletions src/bsoncxx/lib/bsoncxx/v1/document/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace document {
static_assert(is_regular<value>::value, "bsoncxx::v1::document::value must be regular");
static_assert(is_nothrow_moveable<value>::value, "bsoncxx::v1::document::value must be nothrow moveable");

void value::noop_deleter(std::uint8_t*) { /* noop */ }

} // namespace document
} // namespace v1
} // namespace bsoncxx
Loading