Skip to content
Open
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
6 changes: 4 additions & 2 deletions examples/api/bsoncxx/examples/oid/basic_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ void example() {
{
std::time_t time = oid.get_time_t();
char str[sizeof("YYYY-MM-DD HH:MM:SS")];
EXPECT(std::strftime(str, sizeof(str), "%F %T", std::gmtime(&time)) == sizeof(str) - 1u);
// Avoid %F and %T for mingw-w64 GCC compatibiility.
EXPECT(std::strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", std::gmtime(&time)) == sizeof(str) - 1u);
EXPECT(std::string(str) == "1970-01-01 00:00:00");
}

Expand All @@ -61,7 +62,8 @@ void example() {
{
std::time_t time = oid.get_time_t();
char str[sizeof("YYYY-MM-DD HH:MM:SS")];
EXPECT(std::strftime(str, sizeof(str), "%F %T", std::gmtime(&time)) == sizeof(str) - 1u);
// Avoid %F and %T for mingw-w64 GCC compatibiility.
EXPECT(std::strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", std::gmtime(&time)) == sizeof(str) - 1u);
EXPECT(std::string(str) == "2000-01-01 23:59:59");
}

Expand Down
12 changes: 6 additions & 6 deletions examples/api/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@

#include <examples/macros.hh>

#if !defined(_MSC_VER)
#if !defined(_WIN32)

#include <unistd.h>

#include <sys/wait.h>

#endif // !defined(_MSC_VER)
#endif // !defined(_WIN32)

namespace {

Expand Down Expand Up @@ -119,7 +119,7 @@ class runner_type {

action run_forking_components() {
if (use_fork) {
#if !defined(_MSC_VER)
#if !defined(_WIN32)
// Forking with threads is difficult and the number of components that require forking
// are few in number. Run forking components sequentially.
for (auto const& component : forking_components) {
Expand Down Expand Up @@ -167,7 +167,7 @@ class runner_type {
}

return action::succeed;
#endif // !defined(_MSC_VER)
#endif // !defined(_WIN32)
}

std::cout << "Skipping API examples that require forked processes" << std::endl;
Expand Down Expand Up @@ -484,7 +484,7 @@ void runner_register_forking_component(void (*fn)(), char const* name) {
}

int EXAMPLES_CDECL main(int argc, char** argv)
#if defined(_MSC_VER)
#if defined(_WIN32)
try
#endif
{
Expand Down Expand Up @@ -539,7 +539,7 @@ int EXAMPLES_CDECL main(int argc, char** argv)

return runner.run(); // Return directly from forked processes.
}
#if defined(_MSC_VER)
#if defined(_WIN32)
// Avoid popup dialog boxes or completely-absent CLI error messages on Windows.
catch (std::exception const& ex) {
std::cerr << "API runner failed due to uncaught exception: " << ex.what() << std::endl;
Expand Down
5 changes: 5 additions & 0 deletions src/bsoncxx/include/bsoncxx/v1/detail/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@
//
// MSVC: supports inline variables since 19.12 (with /std:c++latest), but behavior is broken for static data members
// (multiple definitions) until 19.20 even when __cpp_inline_variables is defined.
//
// mingw-w64: this is an ancient bug/issue: https://sourceware.org/bugzilla/show_bug.cgi?id=9687. Use the
// Windows-specific [[gnu::selectany]] attribute instead, which provides linke-once semantics for global variables.
#if ( \
!defined(_MSC_VER) && \
(__cplusplus >= 201703L || (defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L))) || \
(defined(_MSC_VER) && _MSC_VER >= 1920 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
#define BSONCXX_PRIVATE_INLINE_CXX17 inline
#elif defined(__MINGW32__) || defined(__MINGW64__)
#define BSONCXX_PRIVATE_INLINE_CXX17 [[gnu::selectany]]
#else
#define BSONCXX_PRIVATE_INLINE_CXX17 \
BSONCXX_PRIVATE_IF_GCC([[gnu::weak]]) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class view_or_value : public bsoncxx::v_noabi::view_or_value<stdx::string_view,
///
/// Default constructor, equivalent to using an empty string.
///
BSONCXX_ABI_EXPORT_CDECL() view_or_value() = default;
view_or_value() = default;

///
/// Construct a string::view_or_value using a null-terminated const char *.
Expand Down
1 change: 0 additions & 1 deletion src/bsoncxx/test/v1/element/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <bsoncxx/test/v1/document/view.hh>
#include <bsoncxx/test/v1/exception.hh>
#include <bsoncxx/test/v1/types/value.hh>
#include <bsoncxx/test/v1/types/view.hh>

#include <cstdint>
#include <cstring>
Expand Down
6 changes: 4 additions & 2 deletions src/bsoncxx/test/v1/oid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ TEST_CASE("basic", "[bsoncxx][v1][oid]") {
{
std::time_t time = o.get_time_t();
char str[sizeof("YYYY-MM-DD HH:MM:SS")];
CHECK(std::strftime(str, sizeof(str), "%F %T", std::gmtime(&time)) == sizeof(str) - 1u);
// Avoid %F and %T for mingw-w64 GCC compatibiility.
CHECK(std::strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", std::gmtime(&time)) == sizeof(str) - 1u);
CHECK(std::string(str) == "1970-01-01 00:00:00");
}

Expand All @@ -172,7 +173,8 @@ TEST_CASE("basic", "[bsoncxx][v1][oid]") {
{
std::time_t time = o.get_time_t();
char str[sizeof("YYYY-MM-DD HH:MM:SS")];
CHECK(std::strftime(str, sizeof(str), "%F %T", std::gmtime(&time)) == sizeof(str) - 1u);
// Avoid %F and %T for mingw-w64 GCC compatibiility.
CHECK(std::strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", std::gmtime(&time)) == sizeof(str) - 1u);
CHECK(std::string(str) == "2000-01-01 23:59:59");
}

Expand Down
2 changes: 1 addition & 1 deletion src/bsoncxx/test/v1/types/value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

//

#include <bsoncxx/test/v1/types/view.hh>
#include <bsoncxx/test/v1/types/view.hh> // IWYU pragma: export

#include <catch2/catch_tostring.hpp>

Expand Down
2 changes: 2 additions & 0 deletions src/bsoncxx/test/v_noabi/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <bsoncxx/test/v1/array/view.hh>

#include <algorithm>

#include <bsoncxx/array/view.hpp>
Expand Down
16 changes: 10 additions & 6 deletions src/bsoncxx/test/v_noabi/oid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ parsed_oid parse_oid(oid const& oid) {
}

void compare_string(std::time_t const& t, bsoncxx::stdx::string_view time) {
char time_str[48] = {};
CHECK(0 != (std::strftime(time_str, sizeof(time_str), "%b %e, %Y %H:%M:%S UTC", std::gmtime(&t))));
CHECK(time_str == time);
char time_str[48];

// Avoid %e for MSVCRT-based mingw-w64 GCC compatibility.
REQUIRE(0 != (strftime(time_str, sizeof(time_str), "%b %d, %Y %H:%M:%S UTC", std::gmtime(&t))));

REQUIRE(time_str == time);
}

TEST_CASE("basic", "[bsoncxx][v_noabi][oid]") {
Expand All @@ -96,10 +99,10 @@ TEST_CASE("basic", "[bsoncxx][v_noabi][oid]") {
REQUIRE(tc == 0x80000000);
REQUIRE(td == 0xFFFFFFFF);

compare_string(ta, "Jan 1, 1970 00:00:00 UTC");
compare_string(ta, "Jan 01, 1970 00:00:00 UTC");
compare_string(tb, "Jan 19, 2038 03:14:07 UTC");
compare_string(tc, "Jan 19, 2038 03:14:08 UTC");
compare_string(td, "Feb 7, 2106 06:28:15 UTC");
compare_string(td, "Feb 07, 2106 06:28:15 UTC");
}

// Ensure that after a new process is created through a fork() or similar process creation operation, the "random
Expand Down Expand Up @@ -138,7 +141,8 @@ TEST_CASE("basic", "[bsoncxx][v_noabi][oid]") {
{
std::time_t time = o.get_time_t();
char str[sizeof("YYYY-MM-DD HH:MM:SS")];
CHECK(std::strftime(str, sizeof(str), "%F %T", std::gmtime(&time)) == sizeof(str) - 1u);
// Avoid %F and %T for mingw-w64 GCC compatibiility.
CHECK(std::strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", std::gmtime(&time)) == sizeof(str) - 1u);
CHECK(std::string(str) == "2000-01-01 23:59:59");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class client_session {
MONGOCXX_ABI_EXPORT_CDECL(client_session&) operator=(client_session&&) noexcept;

client_session(client_session const&) = delete;
MONGOCXX_ABI_EXPORT_CDECL(client_session&) operator=(client_session const&) = delete;
client_session& operator=(client_session const&) = delete;

///
/// Ends and destroys the session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ class collection {
/// - @ref mongocxx::v_noabi::bulk_write
/// - https://www.mongodb.com/docs/manual/core/bulk-write-operations/
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<result::bulk_write>)
write(model::write const& write, options::bulk_write const& options = options::bulk_write()) {
bsoncxx::v_noabi::stdx::optional<result::bulk_write> write(
model::write const& write,
options::bulk_write const& options = options::bulk_write()) {
return create_bulk_write(options).append(write).execute();
}

Expand All @@ -267,8 +268,7 @@ class collection {
/// - @ref mongocxx::v_noabi::bulk_write
/// - https://www.mongodb.com/docs/manual/core/bulk-write-operations/
///
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<result::bulk_write>)
write(
bsoncxx::v_noabi::stdx::optional<result::bulk_write> write(
client_session const& session,
model::write const& write,
options::bulk_write const& options = options::bulk_write()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class index_view {
MONGOCXX_ABI_EXPORT_CDECL() ~index_view();

index_view(index_view const&) = delete;
MONGOCXX_ABI_EXPORT_CDECL(index_view&) operator=(index_view const&) = delete;
index_view& operator=(index_view const&) = delete;

///
/// Returns a cursor over all the indexes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ class read_preference {
///
/// @return A hedge document if one was set.
///
MONGOCXX_DEPRECATED MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> const)
hedge() const {
MONGOCXX_DEPRECATED bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> const hedge() const {
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> ret;
if (auto const opt = _rp.hedge()) {
ret.emplace(*opt);
Expand Down
2 changes: 1 addition & 1 deletion src/mongocxx/lib/mongocxx/private/scoped_bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ scoped_bson& scoped_bson::operator+=(scoped_bson_view other) {
}

bson_destroy(&bson);
throw std::logic_error{"mongocxx::scoped_bson::operator+=: bson_new_from_data failed"};
throw std::logic_error{"mongocxx::scoped_bson::operator+=: bson_concat failed"};
}

// Compatible allocator: avoid an unnecessary copy by reusing the underlying BSON data.
Expand Down
29 changes: 28 additions & 1 deletion src/mongocxx/test/private/scoped_bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

//

#include <bsoncxx/test/v1/document/value.hh>

#include <cstdint>
#include <stdexcept>
#include <utility>
Expand Down Expand Up @@ -430,6 +432,8 @@ TEST_CASE("concat", "[mongocxx][private][scoped_bson]") {
auto const data = bsoncxx::make_unique_for_overwrite<char[]>(size);
auto const big_string = bsoncxx::v1::stdx::string_view{data.get(), size};

REQUIRE(data);

std::memset(data.get(), 'x', size - 1u);
data[size - 1u] = '\0';

Expand Down Expand Up @@ -513,32 +517,55 @@ TEST_CASE("concat", "[mongocxx][private][scoped_bson]") {
}

SECTION("deleter") {
auto& noop_deleter = bsoncxx::v1::document::value::noop_deleter;
auto& bson_free = ::bson_free;

scoped_bson const x1{R"({"x": 1})"};
scoped_bson const x2{R"({"x": 2})"};
scoped_bson const x1x2{R"({"x": 1, "x": 2})"};

std::uint8_t data[] = {5, 0, 0, 0, 0}; // {}
scoped_bson doc{bsoncxx::v1::document::value{data, &bsoncxx::v1::document::value::noop_deleter}};
scoped_bson doc{bsoncxx::v1::document::value{data, &noop_deleter}};

doc += x1; // noop_deleter -> bson_free

CHECK(doc.view() == x1.view());

#if defined(__MINGW32__)
{
// Linking with mingw-w64 does not guarantee a unique address for `bson_free`.
// Negative-test that the deleter is *no longer* `noop_deleter` instead.
(void)bson_free;
auto const deleter_ptr = doc.value().get_deleter().target<decltype(&noop_deleter)>();
CHECK_FALSE(deleter_ptr);
}
#else
{
auto const deleter_ptr = doc.value().get_deleter().target<decltype(&bson_free)>();
REQUIRE(deleter_ptr);
CHECK(*deleter_ptr == &bson_free);
}
#endif

doc += x2; // bson_free -> bson_free

CHECK(doc.view() == x1x2.view());

#if defined(__MINGW32__)
{
// Linking with mingw-w64 does not guarantee a unique address for `bson_free`.
// Negative-test that the deleter is *no longer* `noop_deleter` instead.
(void)bson_free;
auto const deleter_ptr = doc.value().get_deleter().target<decltype(&noop_deleter)>();
CHECK_FALSE(deleter_ptr);
}
#else
{
auto const deleter_ptr = doc.value().get_deleter().target<decltype(&bson_free)>();
REQUIRE(deleter_ptr);
CHECK(*deleter_ptr == &bson_free);
}
#endif
}
}

Expand Down
1 change: 1 addition & 0 deletions src/mongocxx/test/private/scoped_bson.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

//

#include <bsoncxx/test/v1/array/view.hh> // IWYU pragma: keep: Catch::StringMaker<bsoncxx::v1::array::view>
#include <bsoncxx/test/v1/document/view.hh> // IWYU pragma: keep: Catch::StringMaker<bsoncxx::v1::document::view>

#include <string>
Expand Down
8 changes: 4 additions & 4 deletions src/mongocxx/test/subprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <catch2/catch_test_macros.hpp>

#if !defined(_MSC_VER)
#if !defined(_WIN32)

#include <cstdlib> // exit(), strsignal(), etc.
#include <string.h> // strsignal()
Expand Down Expand Up @@ -112,7 +112,7 @@ int subprocess(std::function<void()> fn, bool* is_signal_ptr) {
} // namespace test
} // namespace mongocxx

#endif // !defined(_MSC_VER)
#endif // !defined(_WIN32)

TEST_CASE("counter", "[mongocxx][test][subprocess]") {
std::atomic_int counter{0};
Expand Down Expand Up @@ -166,7 +166,7 @@ TEST_CASE("exception", "[mongocxx][test][subprocess]") {
}

TEST_CASE("unknown exception", "[mongocxx][test][subprocess]") {
#if !defined(_MSC_VER)
#if !defined(_WIN32)
auto is_signal = false;
auto const ret = mongocxx::test::subprocess(
[] {
Expand All @@ -185,5 +185,5 @@ TEST_CASE("unknown exception", "[mongocxx][test][subprocess]") {

CHECK_SUBPROCESS([] {});

#endif // !defined(_MSC_VER)
#endif // !defined(_WIN32)
}
4 changes: 2 additions & 2 deletions src/mongocxx/test/subprocess.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace test {
// (`*is_signal_ptr` is `true`) .
int subprocess(std::function<void()> fn, bool* is_signal_ptr = nullptr);

#if !defined(_MSC_VER)
#if !defined(_WIN32)

#define CHECK_SUBPROCESS(...) \
if (1) { \
Expand All @@ -54,7 +54,7 @@ int subprocess(std::function<void()> fn, bool* is_signal_ptr = nullptr);
#define CHECK_SUBPROCESS(...) SKIP("mongocxx::test::subprocess() is not supported")
#define CHECK_FALSE_SUBPROCESS(...) SKIP("mongocxx::test::subprocess() is not supported")

#endif // !defined(_MSC_VER)
#endif // !defined(_WIN32)

} // namespace test
} // namespace mongocxx
Loading