Skip to content

Commit 431ea20

Browse files
authored
CXX-2745 reorganize and tidy up internal code to support multiple ABI interfaces (#1323)
* format: group private headers separately from public headers * Relocate internal components out of v_noabi subdirectories * Rename private/export.hh <- test_util/export_for_testing.hh * Rename private/mock.hh <- test_util/mock.hh * Add transitive inclusion of export.hpp * Remove internal macro guard headers * Address missing include directives * v_noabi: itoa.hh * v_noabi: suppress_deprecation_warnings.hh * v_noabi: bson.hh (CXX-1366) * v_noabi: mongoc.hh (CXX-1366) * Fix warning suppression macros in internal C Driver library headers * format: remove private config headers from regex * v_noabi: relocate private headers * v_noabi: relocate component headers * v_noabi: update paths * Fix -Wconversion errors due to incorrect merge conflict resolution
1 parent 48cee76 commit 431ea20

File tree

206 files changed

+972
-1357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+972
-1357
lines changed

.clang-format

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,18 @@ IncludeCategories:
156156
Priority: 24
157157
- Regex: 'mongocxx/v1/.*\.hpp' # v1 public headers
158158
Priority: 25
159-
- Regex: 'bsoncxx/v1/.*\.hh' # v1 private headers
159+
- Regex: 'bsoncxx/v1/.*\.hh' # v1 internal headers
160160
Priority: 26
161-
- Regex: 'mongocxx/v1/.*\.hh' # v1 private headers
161+
- Regex: 'mongocxx/v1/.*\.hh' # v1 internal headers
162162
Priority: 27
163-
- Regex: 'bsoncxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
163+
- Regex: 'bsoncxx/private/.*' # private headers
164164
Priority: 60
165-
- Regex: 'mongocxx/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
165+
- Regex: 'mongocxx/private/.*' # private headers
166166
Priority: 61
167+
- Regex: 'bsoncxx/config/prelude\.(hpp|hh)' # v_noabi preludes
168+
Priority: 62
169+
- Regex: 'mongocxx/config/prelude\.(hpp|hh)' # v_noabi preludes
170+
Priority: 63
167171
- Regex: 'bsoncxx/test/.*' # test headers
168172
Priority: 70
169173
- Regex: 'mongocxx/test/.*' # test headers
@@ -174,10 +178,14 @@ IncludeCategories:
174178
Priority: 40
175179
- Regex: 'mongocxx/.*(-|\/)fwd\.(hpp|hh)' # all remaining forward headers
176180
Priority: 41
177-
- Regex: 'bsoncxx/.*' # all remaining headers
181+
- Regex: 'bsoncxx/.*\.hpp' # all remaining public headers
178182
Priority: 50
179-
- Regex: 'mongocxx/.*' # all remaining headers
183+
- Regex: 'mongocxx/.*\.hpp' # all remaining public headers
180184
Priority: 51
185+
- Regex: 'bsoncxx/.*\.hh' # all remaining internal headers
186+
Priority: 52
187+
- Regex: 'mongocxx/.*\.hh' # all remaining internal headers
188+
Priority: 53
181189
- Regex: '.*' # all other headers (third party)
182190
Priority: 90
183191
IncludeIsMainRegex: '([-_](test|unittest))?$'

src/bsoncxx/lib/CMakeLists.txt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
set(bsoncxx_sources_private
16+
bsoncxx/private/itoa.cpp
17+
)
18+
1519
set(bsoncxx_sources_v_noabi
1620
bsoncxx/v_noabi/bsoncxx/array/element.cpp
1721
bsoncxx/v_noabi/bsoncxx/array/value.cpp
@@ -28,7 +32,6 @@ set(bsoncxx_sources_v_noabi
2832
bsoncxx/v_noabi/bsoncxx/exception/exception.cpp
2933
bsoncxx/v_noabi/bsoncxx/json.cpp
3034
bsoncxx/v_noabi/bsoncxx/oid.cpp
31-
bsoncxx/v_noabi/bsoncxx/private/itoa.cpp
3235
bsoncxx/v_noabi/bsoncxx/string/view_or_value.cpp
3336
bsoncxx/v_noabi/bsoncxx/types.cpp
3437
bsoncxx/v_noabi/bsoncxx/types/bson_value/value.cpp
@@ -45,19 +48,18 @@ set(bsoncxx_sources_v1
4548
)
4649

4750
list(APPEND bsoncxx_sources
51+
${bsoncxx_sources_private}
4852
${bsoncxx_sources_v_noabi}
4953
${bsoncxx_sources_v1}
5054
)
5155
list(TRANSFORM bsoncxx_sources PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
5256
set(bsoncxx_sources "${bsoncxx_sources}" PARENT_SCOPE)
5357

5458
# Generate private headers.
55-
if(1)
56-
configure_file(
57-
bsoncxx/v_noabi/bsoncxx/config/private/config.hh.in
58-
bsoncxx/v_noabi/bsoncxx/config/private/config.hh
59-
)
60-
endif()
59+
configure_file(
60+
bsoncxx/private/config/config.hh.in
61+
bsoncxx/private/config/config.hh
62+
)
6163

6264
# Generate and install public headers.
6365
if(1)
@@ -81,21 +83,20 @@ endif()
8183

8284
set_dist_list(src_bsoncxx_lib_DIST
8385
CMakeLists.txt
86+
${bsoncxx_sources_private}
8487
${bsoncxx_sources_v_noabi}
8588
${bsoncxx_sources_v1}
86-
bsoncxx/v_noabi/bsoncxx/config/private/config.hh.in
87-
bsoncxx/v_noabi/bsoncxx/config/private/postlude.hh
88-
bsoncxx/v_noabi/bsoncxx/config/private/prelude.hh
89-
bsoncxx/v_noabi/bsoncxx/private/b64_ntop.hh
90-
bsoncxx/v_noabi/bsoncxx/private/helpers.hh
91-
bsoncxx/v_noabi/bsoncxx/private/make_unique.hh
92-
bsoncxx/v_noabi/bsoncxx/private/itoa.hh
93-
bsoncxx/v_noabi/bsoncxx/private/libbson.hh
94-
bsoncxx/v_noabi/bsoncxx/private/stack.hh
95-
bsoncxx/v_noabi/bsoncxx/private/suppress_deprecation_warnings.hh
96-
bsoncxx/v_noabi/bsoncxx/test_util/export_for_testing.hh
97-
bsoncxx/v_noabi/bsoncxx/types/bson_value/private/value.hh
98-
bsoncxx/v_noabi/bsoncxx/types/private/convert.hh
89+
bsoncxx/private/b64_ntop.hh
90+
bsoncxx/private/config/config.hh.in
91+
bsoncxx/private/convert.hh
92+
bsoncxx/private/export.hh
93+
bsoncxx/private/helpers.hh
94+
bsoncxx/private/itoa.hh
95+
bsoncxx/private/bson.hh
96+
bsoncxx/private/make_unique.hh
97+
bsoncxx/private/stack.hh
98+
bsoncxx/private/suppress_deprecation_warnings.hh
99+
bsoncxx/v_noabi/bsoncxx/types/bson_value/value.hh
99100
bsoncxx/v1/config/config.hpp.in
100101
bsoncxx/v1/config/version.hpp.in
101102
)

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/private/b64_ntop.hh renamed to src/bsoncxx/lib/bsoncxx/private/b64_ntop.hh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#include <cstdint>
4646
#include <cstdlib>
4747

48-
#include <bsoncxx/config/prelude.hpp>
49-
5048
namespace bsoncxx {
5149
namespace b64 {
5250

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

188186
} // namespace b64
189187
} // namespace bsoncxx
190-
191-
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/config/private/prelude.hh renamed to src/bsoncxx/lib/bsoncxx/private/bson.hh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <bsoncxx/config/prelude.hpp>
15+
#pragma once
1616

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

20-
#include <bsoncxx/config/private/config.hh>
19+
BSONCXX_PRIVATE_WARNINGS_PUSH();
20+
21+
BSONCXX_PRIVATE_WARNINGS_DISABLE(GNU("-Wconversion"));
22+
BSONCXX_PRIVATE_IF_MSVC(BSONCXX_PRIVATE_PRAGMA(warning(push, 1));)
23+
24+
#include <bson/bson.h>
25+
26+
BSONCXX_PRIVATE_WARNINGS_POP();

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/types/private/convert.hh renamed to src/bsoncxx/lib/bsoncxx/private/convert.hh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
#pragma once
1616

17+
#include <bsoncxx/v1/detail/macros.hpp>
18+
1719
#include <cstdlib>
1820

19-
#include <bsoncxx/private/libbson.hh>
20-
#include <bsoncxx/private/suppress_deprecation_warnings.hh>
2121
#include <bsoncxx/types.hpp>
2222
#include <bsoncxx/types/bson_value/view.hpp>
2323

24-
#include <bsoncxx/config/private/prelude.hh>
24+
#include <bsoncxx/private/bson.hh>
25+
#include <bsoncxx/private/suppress_deprecation_warnings.hh>
2526

2627
namespace bsoncxx {
2728
namespace v_noabi {
@@ -326,5 +327,3 @@ inline void convert_from_libbson(bson_value_t const* v, b_array* out) {
326327
} // namespace types
327328
} // namespace v_noabi
328329
} // namespace bsoncxx
329-
330-
#include <bsoncxx/config/private/postlude.hh>
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#pragma once
1616

17-
#include <bsoncxx/config/private/prelude.hh>
17+
#include <bsoncxx/v1/config/export.hpp>
1818

1919
// The BSONCXX_TESTING macro is intended to be used for exporting symbols for testing which are not
2020
// normally exported as part of the bsoncxx library. We currently use this workaround in lieu of
@@ -28,5 +28,3 @@
2828
#define BSONCXX_ABI_EXPORT_TESTING
2929
#define BSONCXX_ABI_EXPORT_CDECL_TESTING(...) __VA_ARGS__
3030
#endif
31-
32-
#include <bsoncxx/config/private/postlude.hh>

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/private/helpers.hh renamed to src/bsoncxx/lib/bsoncxx/private/helpers.hh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
#include <bsoncxx/document/value.hpp>
1818
#include <bsoncxx/document/view.hpp>
1919
#include <bsoncxx/oid.hpp>
20-
#include <bsoncxx/private/libbson.hh>
2120

22-
#include <bsoncxx/config/private/prelude.hh>
21+
#include <bsoncxx/private/bson.hh>
2322

2423
namespace bsoncxx {
2524
namespace helpers {
@@ -47,5 +46,3 @@ inline bsoncxx::v_noabi::oid make_oid(bson_oid_t const* bson_oid) {
4746

4847
} // namespace helpers
4948
} // namespace bsoncxx
50-
51-
#include <bsoncxx/config/private/postlude.hh>

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/private/itoa.cpp renamed to src/bsoncxx/lib/bsoncxx/private/itoa.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414

1515
#include <bsoncxx/private/itoa.hh>
1616

17-
#include <bsoncxx/config/private/prelude.hh>
18-
1917
namespace bsoncxx {
2018

2119
namespace {
2220

23-
constexpr char kIndexTable[] =
21+
constexpr char k_index_table[] =
2422
"0\0"
2523
"1\0"
2624
"2\0"
@@ -1021,38 +1019,39 @@ constexpr char kIndexTable[] =
10211019
"997\0"
10221020
"998\0"
10231021
"999\0";
1022+
10241023
} // namespace
10251024

1026-
itoa::itoa(uint32_t val) : _val(val) {
1025+
itoa::itoa(std::uint32_t val) : _val(val) {
10271026
_init();
10281027
}
10291028

1030-
itoa& itoa::operator=(uint32_t new_val) {
1029+
itoa& itoa::operator=(std::uint32_t new_val) {
10311030
_val = new_val;
10321031
_init();
10331032
return *this;
10341033
}
10351034

10361035
void itoa::_init() {
1037-
if (_val < 10) {
1038-
_str = kIndexTable + (2 * _val);
1039-
_len = 1;
1040-
} else if (_val < 100) {
1041-
_str = kIndexTable + (2 * 10) + (3 * (_val - 10));
1042-
_len = 2;
1043-
} else if (_val < 1000) {
1044-
_str = kIndexTable + (2 * 10) + (3 * 90) + (4 * (_val - 100));
1045-
_len = 3;
1036+
if (_val < 10u) {
1037+
_str = k_index_table + (2u * _val);
1038+
_len = 1u;
1039+
} else if (_val < 100u) {
1040+
_str = k_index_table + (2u * 10u) + (3u * (_val - 10u));
1041+
_len = 2u;
1042+
} else if (_val < 1000u) {
1043+
_str = k_index_table + (2u * 10u) + (3u * 90u) + (4 * (_val - 100u));
1044+
_len = 3u;
10461045
} else {
1047-
int size = static_cast<std::int32_t>(sizeof(_buf) - 1);
1046+
int size = static_cast<std::int32_t>(sizeof(_buf) - 1u);
10481047
int i = size;
10491048

10501049
_buf[i] = '\0';
10511050

1052-
while (_val > 0) {
1051+
while (_val > 0u) {
10531052
i--;
1054-
_buf[i] = static_cast<char>((_val % 10) + '0');
1055-
_val = _val / 10;
1053+
_buf[i] = static_cast<char>((_val % 10u) + '0');
1054+
_val = _val / 10u;
10561055
}
10571056

10581057
_str = _buf + i;

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/private/itoa.hh renamed to src/bsoncxx/lib/bsoncxx/private/itoa.hh

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,31 @@
1717
#include <cstddef>
1818
#include <cstdint>
1919

20-
#include <bsoncxx/test_util/export_for_testing.hh>
21-
22-
#include <bsoncxx/config/private/prelude.hh>
20+
#include <bsoncxx/private/export.hh>
2321

2422
namespace bsoncxx {
2523

2624
class itoa {
27-
public:
28-
explicit BSONCXX_ABI_EXPORT_CDECL_TESTING() itoa(uint32_t i = 0);
25+
private:
26+
std::uint32_t _val;
27+
char const* _str;
28+
std::uint8_t _len;
29+
char _buf[11];
2930

31+
public:
3032
~itoa() = default;
31-
3233
itoa(itoa&& rhs) = delete;
3334
itoa& operator=(itoa&&) = delete;
34-
3535
itoa(itoa const& rhs) = delete;
3636
itoa& operator=(itoa const&) = delete;
3737

38-
BSONCXX_ABI_EXPORT_CDECL_TESTING(itoa&) operator=(uint32_t new_value);
38+
itoa() : itoa(0u) {}
39+
40+
explicit BSONCXX_ABI_EXPORT_CDECL_TESTING() itoa(std::uint32_t i);
3941

40-
uint32_t val() const {
42+
itoa& operator=(std::uint32_t new_value);
43+
44+
std::uint32_t val() const {
4145
return _val;
4246
}
4347

@@ -51,13 +55,6 @@ class itoa {
5155

5256
private:
5357
void _init();
54-
55-
uint32_t _val;
56-
char const* _str;
57-
uint8_t _len;
58-
char _buf[11];
5958
};
6059

6160
} // namespace bsoncxx
62-
63-
#include <bsoncxx/config/private/postlude.hh>

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/private/make_unique.hh renamed to src/bsoncxx/lib/bsoncxx/private/make_unique.hh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
#pragma once
1616

17-
#include <memory>
17+
#include <bsoncxx/v1/config/export.hpp>
1818

19-
#include <bsoncxx/config/prelude.hpp>
19+
#include <memory>
2020

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

170170
#pragma pop_macro("BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE")
171-
172-
#include <bsoncxx/config/postlude.hpp>

src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/private/stack.hh renamed to src/bsoncxx/lib/bsoncxx/private/stack.hh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include <memory>
1919
#include <type_traits>
2020

21-
#include <bsoncxx/config/private/prelude.hh>
22-
2321
namespace bsoncxx {
2422

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

163161
} // namespace bsoncxx
164-
165-
#include <bsoncxx/config/private/postlude.hh>

src/mongocxx/lib/mongocxx/v_noabi/mongocxx/config/private/postlude.hh renamed to src/bsoncxx/lib/bsoncxx/private/suppress_deprecation_warnings.hh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

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

18-
// config.hh (generated by CMake)
19-
#undef MONGOCXX_ENABLE_SSL
20-
#pragma pop_macro("MONGOCXX_ENABLE_SSL")
21-
#undef MONGOCXX_COMPILER_ID
22-
#pragma pop_macro("MONGOCXX_COMPILER_ID")
23-
#undef MONGOCXX_COMPILER_VERSION
24-
#pragma pop_macro("MONGOCXX_COMPILER_VERSION")
17+
#include <bsoncxx/v1/detail/macros.hpp>
2518

26-
#include <mongocxx/config/postlude.hpp>
19+
#define BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN \
20+
BSONCXX_PRIVATE_WARNINGS_PUSH(); \
21+
BSONCXX_PRIVATE_WARNINGS_DISABLE(GNU("-Wdeprecated-declarations")); \
22+
BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4996));
23+
24+
#define BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END BSONCXX_PRIVATE_WARNINGS_POP();

0 commit comments

Comments
 (0)