Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c68049a
format: group private headers separately from public headers
eramongodb Jan 16, 2025
83acc8f
Relocate internal components out of v_noabi subdirectories
eramongodb Jan 16, 2025
6033b0f
Rename private/export.hh <- test_util/export_for_testing.hh
eramongodb Jan 16, 2025
973bf1b
Rename private/mock.hh <- test_util/mock.hh
eramongodb Jan 16, 2025
0613b77
Add transitive inclusion of export.hpp
eramongodb Jan 16, 2025
ac2fecc
Remove internal macro guard headers
eramongodb Jan 16, 2025
dc9cd5c
Address missing include directives
eramongodb Jan 16, 2025
a4b9049
v_noabi: itoa.hh
eramongodb Jan 16, 2025
9954cad
v_noabi: suppress_deprecation_warnings.hh
eramongodb Jan 16, 2025
ad5609e
v_noabi: bson.hh <- libbson.hh
eramongodb Jan 16, 2025
8dd2eda
v_noabi: bson.hh (CXX-1366)
eramongodb Jan 16, 2025
0888c57
v_noabi: mongoc.hh <- libmongoc.hh
eramongodb Jan 16, 2025
4765973
v_noabi: mongoc.hh (CXX-1366)
eramongodb Jan 16, 2025
dd624da
Merge remote-tracking branch 'upstream/master' into HEAD
eramongodb Jan 30, 2025
e4c7a7f
Fix warning suppression macros in internal C Driver library headers
eramongodb Jan 30, 2025
c505b96
format: remove private config headers from regex
eramongodb Jan 30, 2025
b65fcd0
Merge remote-tracking branch 'upstream/master' into cxx-abi-internals
eramongodb Jan 30, 2025
f4ff4e7
v_noabi: relocate private headers
eramongodb Feb 4, 2025
09e13d0
v_noabi: relocate component headers
eramongodb Feb 4, 2025
b1b49ae
v_noabi: update paths
eramongodb Feb 4, 2025
4c5760d
format: separate public and internal v_noabi headers
eramongodb Feb 4, 2025
d47cfe0
Merge remote-tracking branch 'upstream/master' into cxx-abi-internals
eramongodb Feb 12, 2025
696e8db
Remove redundant if(1) block
eramongodb Feb 12, 2025
beba4a0
Reorder Priority 60 include categories in order of priority
eramongodb Feb 12, 2025
f28d1ae
Fix -Wconversion errors due to incorrect merge conflict resolution
eramongodb Feb 12, 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
8 changes: 6 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ IncludeCategories:
Priority: 26
- Regex: 'mongocxx/v1/.*\.hh' # v1 private headers
Priority: 27
- Regex: 'bsoncxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
- Regex: 'bsoncxx/config/prelude\.(hpp|hh)' # v_noabi preludes
Priority: 62
- Regex: 'mongocxx/config/prelude\.(hpp|hh)' # v_noabi preludes
Priority: 63
- Regex: 'bsoncxx/private/.*' # private headers
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Can these YAML mappings be re-sorted by their Priority field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Priority: 6* categories look like they can be reordered, so updated as suggested.

However, in general, unfortunately no. The "first regex match" in the order they are listed is what determines the group and priority of the header. e.g. given:

- Regex: '<[[:alnum:]_.]+>' # system headers
  Priority: 30
- Regex: 'bsoncxx/private/.*' # private headers
  Priority: 60

the <bsoncxx/private/.*> headers will never match the priority 60 "private headers" regex because they'll always match the priority 30 "system headers" regex first.

Priority: 60
- Regex: 'mongocxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
- Regex: 'mongocxx/private/.*' # private headers
Priority: 61
- Regex: 'bsoncxx/test/.*' # test headers
Priority: 70
Expand Down
31 changes: 17 additions & 14 deletions src/bsoncxx/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(bsoncxx_sources_private
bsoncxx/private/itoa.cpp
)

set(bsoncxx_sources_v_noabi
bsoncxx/v_noabi/bsoncxx/array/element.cpp
bsoncxx/v_noabi/bsoncxx/array/value.cpp
Expand All @@ -28,7 +32,6 @@ set(bsoncxx_sources_v_noabi
bsoncxx/v_noabi/bsoncxx/exception/exception.cpp
bsoncxx/v_noabi/bsoncxx/json.cpp
bsoncxx/v_noabi/bsoncxx/oid.cpp
bsoncxx/v_noabi/bsoncxx/private/itoa.cpp
bsoncxx/v_noabi/bsoncxx/string/view_or_value.cpp
bsoncxx/v_noabi/bsoncxx/types.cpp
bsoncxx/v_noabi/bsoncxx/types/bson_value/value.cpp
Expand All @@ -45,6 +48,7 @@ set(bsoncxx_sources_v1
)

list(APPEND bsoncxx_sources
${bsoncxx_sources_private}
${bsoncxx_sources_v_noabi}
${bsoncxx_sources_v1}
)
Expand All @@ -54,8 +58,8 @@ set(bsoncxx_sources "${bsoncxx_sources}" PARENT_SCOPE)
# Generate private headers.
if(1)
configure_file(
bsoncxx/v_noabi/bsoncxx/config/private/config.hh.in
bsoncxx/v_noabi/bsoncxx/config/private/config.hh
bsoncxx/private/config/config.hh.in
bsoncxx/private/config/config.hh
)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

Aside: What's up with the if(1) blocks all over the CMake code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a primitive workaround to make up for the lack of "scope blocks" in CMake without needing to resort to function() (overkill for these use cases) or comment-based begin+end delimiters. It is comparable to function-local block statements in C/C++ without any condition or loop.

That being said, this particular if(1) isn't doing anything useful anymore, so I've removed it in response.

Note: CMake 3.25 added block() which would be a much better and more appropriate command to use than if(1) once the minimum CMake required version is raised accordingly.


Expand All @@ -81,19 +85,18 @@ endif()

set_dist_list(src_bsoncxx_lib_DIST
CMakeLists.txt
${bsoncxx_sources_private}
${bsoncxx_sources_v_noabi}
${bsoncxx_sources_v1}
bsoncxx/v_noabi/bsoncxx/config/private/config.hh.in
bsoncxx/v_noabi/bsoncxx/config/private/postlude.hh
bsoncxx/v_noabi/bsoncxx/config/private/prelude.hh
bsoncxx/v_noabi/bsoncxx/private/b64_ntop.hh
bsoncxx/v_noabi/bsoncxx/private/helpers.hh
bsoncxx/v_noabi/bsoncxx/private/make_unique.hh
bsoncxx/v_noabi/bsoncxx/private/itoa.hh
bsoncxx/v_noabi/bsoncxx/private/libbson.hh
bsoncxx/v_noabi/bsoncxx/private/stack.hh
bsoncxx/v_noabi/bsoncxx/private/suppress_deprecation_warnings.hh
bsoncxx/v_noabi/bsoncxx/test_util/export_for_testing.hh
bsoncxx/private/b64_ntop.hh
bsoncxx/private/config/config.hh.in
bsoncxx/private/export.hh
bsoncxx/private/helpers.hh
bsoncxx/private/itoa.hh
bsoncxx/private/bson.hh
bsoncxx/private/make_unique.hh
bsoncxx/private/stack.hh
bsoncxx/private/suppress_deprecation_warnings.hh
bsoncxx/v_noabi/bsoncxx/types/bson_value/private/value.hh
bsoncxx/v_noabi/bsoncxx/types/private/convert.hh
bsoncxx/v1/config/config.hpp.in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#include <cstdint>
#include <cstdlib>

#include <bsoncxx/config/prelude.hpp>

namespace bsoncxx {
namespace b64 {

Expand Down Expand Up @@ -187,5 +185,3 @@ inline int ntop(std::uint8_t const* src, std::size_t srclength, char* target, st

} // namespace b64
} // namespace bsoncxx

#include <bsoncxx/config/postlude.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <bsoncxx/config/prelude.hpp>
#pragma once

// NOTE: Push any macros here that are defined by the following
// headers here.
#include <bsoncxx/v1/detail/macros.hpp>

#include <bsoncxx/config/private/config.hh>
BSONCXX_PRIVATE_WARNINGS_PUSH();

BSONCXX_PRIVATE_WARNINGS_DISABLE(GNU("-Wconversion"));
BSONCXX_PRIVATE_IF_MSVC(BSONCXX_PRIVATE_PRAGMA(warning(push, 1));)

#include <bson/bson.h>

BSONCXX_PRIVATE_WARNINGS_POP();
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include <bsoncxx/config/private/prelude.hh>
#include <bsoncxx/v1/config/export.hpp>

// The BSONCXX_TESTING macro is intended to be used for exporting symbols for testing which are not
// normally exported as part of the bsoncxx library. We currently use this workaround in lieu of
Expand All @@ -28,5 +28,3 @@
#define BSONCXX_ABI_EXPORT_TESTING
#define BSONCXX_ABI_EXPORT_CDECL_TESTING(...) __VA_ARGS__
#endif

#include <bsoncxx/config/private/postlude.hh>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
#include <bsoncxx/document/value.hpp>
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/oid.hpp>
#include <bsoncxx/private/libbson.hh>

#include <bsoncxx/config/private/prelude.hh>
#include <bsoncxx/private/bson.hh>

namespace bsoncxx {
namespace helpers {
Expand Down Expand Up @@ -47,5 +46,3 @@ inline bsoncxx::v_noabi::oid make_oid(bson_oid_t const* bson_oid) {

} // namespace helpers
} // namespace bsoncxx

#include <bsoncxx/config/private/postlude.hh>
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@

#include <bsoncxx/private/itoa.hh>

#include <bsoncxx/config/private/prelude.hh>

namespace bsoncxx {

namespace {

constexpr char kIndexTable[] =
constexpr char k_index_table[] =
"0\0"
"1\0"
"2\0"
Expand Down Expand Up @@ -1021,38 +1019,39 @@ constexpr char kIndexTable[] =
"997\0"
"998\0"
"999\0";

} // namespace

itoa::itoa(uint32_t val) : _val(val) {
itoa::itoa(std::uint32_t val) : _val(val) {
_init();
}

itoa& itoa::operator=(uint32_t new_val) {
itoa& itoa::operator=(std::uint32_t new_val) {
_val = new_val;
_init();
return *this;
}

void itoa::_init() {
if (_val < 10) {
_str = kIndexTable + (2 * _val);
_len = 1;
} else if (_val < 100) {
_str = kIndexTable + (2 * 10) + (3 * (_val - 10));
_len = 2;
} else if (_val < 1000) {
_str = kIndexTable + (2 * 10) + (3 * 90) + (4 * (_val - 100));
_len = 3;
if (_val < 10u) {
_str = k_index_table + (2u * _val);
_len = 1u;
} else if (_val < 100u) {
_str = k_index_table + (2u * 10u) + (3u * (_val - 10u));
_len = 2u;
} else if (_val < 1000u) {
_str = k_index_table + (2u * 10u) + (3u * 90u) + (4 * (_val - 100u));
_len = 3u;
} else {
int size = static_cast<std::int32_t>(sizeof(_buf) - 1);
int size = static_cast<std::int32_t>(sizeof(_buf) - 1u);
int i = size;

_buf[i] = '\0';

while (_val > 0) {
while (_val > 0u) {
i--;
_buf[i] = static_cast<std::int8_t>((_val % 10) + '0');
_val = _val / 10;
_buf[i] = static_cast<std::int8_t>((_val % 10u) + '0');
_val = _val / 10u;
}

_str = _buf + i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@
#include <cstddef>
#include <cstdint>

#include <bsoncxx/test_util/export_for_testing.hh>

#include <bsoncxx/config/private/prelude.hh>
#include <bsoncxx/private/export.hh>

namespace bsoncxx {

class itoa {
public:
explicit BSONCXX_ABI_EXPORT_CDECL_TESTING() itoa(uint32_t i = 0);
private:
std::uint32_t _val;
char const* _str;
std::uint8_t _len;
char _buf[11];

public:
~itoa() = default;

itoa(itoa&& rhs) = delete;
itoa& operator=(itoa&&) = delete;

itoa(itoa const& rhs) = delete;
itoa& operator=(itoa const&) = delete;

BSONCXX_ABI_EXPORT_CDECL_TESTING(itoa&) operator=(uint32_t new_value);
itoa() : itoa(0u) {}

explicit BSONCXX_ABI_EXPORT_CDECL_TESTING() itoa(std::uint32_t i);

uint32_t val() const {
itoa& operator=(std::uint32_t new_value);

std::uint32_t val() const {
return _val;
}

Expand All @@ -51,13 +55,6 @@ class itoa {

private:
void _init();

uint32_t _val;
char const* _str;
uint8_t _len;
char _buf[11];
};

} // namespace bsoncxx

#include <bsoncxx/config/private/postlude.hh>
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#pragma once

#include <memory>
#include <bsoncxx/v1/config/export.hpp>

#include <bsoncxx/config/prelude.hpp>
#include <memory>

#pragma push_macro("BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE")
#undef BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE
Expand Down Expand Up @@ -168,5 +168,3 @@ std::unique_ptr<T> make_unique_for_overwrite(std::size_t count) {
} // namespace bsoncxx

#pragma pop_macro("BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE")

#include <bsoncxx/config/postlude.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <memory>
#include <type_traits>

#include <bsoncxx/config/private/prelude.hh>

namespace bsoncxx {

// Note: This stack is only intended for use with the 'frame' type in
Expand Down Expand Up @@ -161,5 +159,3 @@ class stack {
};

} // namespace bsoncxx

#include <bsoncxx/config/private/postlude.hh>
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// NOTE: Pop any macros here that are defined by the headers included
// in private/prelude.hpp.
#pragma once

// config.hh (generated by CMake)
#undef MONGOCXX_ENABLE_SSL
#pragma pop_macro("MONGOCXX_ENABLE_SSL")
#undef MONGOCXX_COMPILER_ID
#pragma pop_macro("MONGOCXX_COMPILER_ID")
#undef MONGOCXX_COMPILER_VERSION
#pragma pop_macro("MONGOCXX_COMPILER_VERSION")
#include <bsoncxx/v1/detail/macros.hpp>

#include <mongocxx/config/postlude.hpp>
#define BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN \
BSONCXX_PRIVATE_WARNINGS_PUSH(); \
BSONCXX_PRIVATE_WARNINGS_DISABLE(GNU("-Wdeprecated-declarations")); \
BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4996));

#define BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END BSONCXX_PRIVATE_WARNINGS_POP();
2 changes: 0 additions & 2 deletions src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/array/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include <bsoncxx/array/element.hpp>
#include <bsoncxx/types/bson_value/view.hpp>

#include <bsoncxx/config/private/prelude.hh>

namespace bsoncxx {
namespace v_noabi {
namespace array {
Expand Down
2 changes: 0 additions & 2 deletions src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/array/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include <bsoncxx/array/value.hpp>

#include <bsoncxx/config/private/prelude.hh>

namespace bsoncxx {
namespace v_noabi {
namespace array {
Expand Down
5 changes: 2 additions & 3 deletions src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/array/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
#include <tuple>

#include <bsoncxx/array/view.hpp>
#include <bsoncxx/private/itoa.hh>
#include <bsoncxx/private/libbson.hh>
#include <bsoncxx/types.hpp>
#include <bsoncxx/types/bson_value/view.hpp>

#include <bsoncxx/config/private/prelude.hh>
#include <bsoncxx/private/bson.hh>
#include <bsoncxx/private/itoa.hh>

namespace bsoncxx {
namespace v_noabi {
Expand Down
11 changes: 5 additions & 6 deletions src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/builder/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
#include <bsoncxx/builder/core.hpp>
#include <bsoncxx/exception/error_code.hpp>
#include <bsoncxx/exception/exception.hpp>
#include <bsoncxx/private/itoa.hh>
#include <bsoncxx/private/libbson.hh>
#include <bsoncxx/private/make_unique.hh>
#include <bsoncxx/private/stack.hh>
#include <bsoncxx/private/suppress_deprecation_warnings.hh>
#include <bsoncxx/stdx/string_view.hpp>
#include <bsoncxx/string/to_string.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/types/bson_value/view.hpp>

#include <bsoncxx/config/private/prelude.hh>
#include <bsoncxx/private/bson.hh>
#include <bsoncxx/private/itoa.hh>
#include <bsoncxx/private/make_unique.hh>
#include <bsoncxx/private/stack.hh>
#include <bsoncxx/private/suppress_deprecation_warnings.hh>

namespace bsoncxx {
namespace v_noabi {
Expand Down
Loading