Skip to content

CXX-2745 reorganize and tidy up internal code to support multiple ABI interfaces #1323

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 25 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 14 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,18 @@ IncludeCategories:
Priority: 24
- Regex: 'mongocxx/v1/.*\.hpp' # v1 public headers
Priority: 25
- Regex: 'bsoncxx/v1/.*\.hh' # v1 private headers
- Regex: 'bsoncxx/v1/.*\.hh' # v1 internal headers
Priority: 26
- Regex: 'mongocxx/v1/.*\.hh' # v1 private headers
- Regex: 'mongocxx/v1/.*\.hh' # v1 internal headers
Priority: 27
- Regex: 'bsoncxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
- Regex: 'bsoncxx/private/.*' # private headers
Priority: 60
- Regex: 'mongocxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
- Regex: 'mongocxx/private/.*' # private headers
Priority: 61
- Regex: 'bsoncxx/config/prelude\.(hpp|hh)' # v_noabi preludes
Priority: 62
- Regex: 'mongocxx/config/prelude\.(hpp|hh)' # v_noabi preludes
Priority: 63
- Regex: 'bsoncxx/test/.*' # test headers
Priority: 70
- Regex: 'mongocxx/test/.*' # test headers
Expand All @@ -174,10 +178,14 @@ IncludeCategories:
Priority: 40
- Regex: 'mongocxx/.*(-|\/)fwd\.(hpp|hh)' # all remaining forward headers
Priority: 41
- Regex: 'bsoncxx/.*' # all remaining headers
- Regex: 'bsoncxx/.*\.hpp' # all remaining public headers
Priority: 50
- Regex: 'mongocxx/.*' # all remaining headers
- Regex: 'mongocxx/.*\.hpp' # all remaining public headers
Priority: 51
- Regex: 'bsoncxx/.*\.hh' # all remaining internal headers
Priority: 52
- Regex: 'mongocxx/.*\.hh' # all remaining internal headers
Priority: 53
- Regex: '.*' # all other headers (third party)
Priority: 90
IncludeIsMainRegex: '([-_](test|unittest))?$'
Expand Down
41 changes: 21 additions & 20 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,19 +48,18 @@ set(bsoncxx_sources_v1
)

list(APPEND bsoncxx_sources
${bsoncxx_sources_private}
${bsoncxx_sources_v_noabi}
${bsoncxx_sources_v1}
)
list(TRANSFORM bsoncxx_sources PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
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
)
endif()
configure_file(
bsoncxx/private/config/config.hh.in
bsoncxx/private/config/config.hh
)

# Generate and install public headers.
if(1)
Expand All @@ -81,21 +83,20 @@ 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/v_noabi/bsoncxx/types/bson_value/private/value.hh
bsoncxx/v_noabi/bsoncxx/types/private/convert.hh
bsoncxx/private/b64_ntop.hh
bsoncxx/private/config/config.hh.in
bsoncxx/private/convert.hh
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/value.hh
bsoncxx/v1/config/config.hpp.in
bsoncxx/v1/config/version.hpp.in
)
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,14 +14,15 @@

#pragma once

#include <bsoncxx/v1/detail/macros.hpp>

#include <cstdlib>

#include <bsoncxx/private/libbson.hh>
#include <bsoncxx/private/suppress_deprecation_warnings.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/suppress_deprecation_warnings.hh>

namespace bsoncxx {
namespace v_noabi {
Expand Down Expand Up @@ -326,5 +327,3 @@ inline void convert_from_libbson(bson_value_t const* v, b_array* out) {
} // namespace types
} // namespace v_noabi
} // namespace bsoncxx

#include <bsoncxx/config/private/postlude.hh>
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<char>((_val % 10) + '0');
_val = _val / 10;
_buf[i] = static_cast<char>((_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();
Loading