Skip to content

Commit df48766

Browse files
committed
Add __cdecl to main() in examples
1 parent 48519e3 commit df48766

39 files changed

+139
-36
lines changed

.evergreen/build_snapshot_rpm.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ sudo mock -r ${config} --use-bootstrap-image --isolation=simple --copyin "${mock
124124

125125
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --cwd "/tmp/${build_dir}" --chroot -- /bin/sh -c "(
126126
rpm -Uvh ../mock-result/*.rpm &&
127-
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -o runcommand_examples examples/mongocxx/mongodb.com/runcommand_examples.cpp -lmongocxx -lbsoncxx &&
128-
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -o aggregation_examples examples/mongocxx/mongodb.com/aggregation_examples.cpp -lmongocxx -lbsoncxx &&
129-
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -o index_examples examples/mongocxx/mongodb.com/index_examples.cpp -lmongocxx -lbsoncxx &&
130-
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -o documentation_examples examples/mongocxx/mongodb.com/documentation_examples.cpp -lmongocxx -lbsoncxx
127+
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -I. -o runcommand_examples examples/mongocxx/mongodb.com/runcommand_examples.cpp -lmongocxx -lbsoncxx &&
128+
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -I. -o aggregation_examples examples/mongocxx/mongodb.com/aggregation_examples.cpp -lmongocxx -lbsoncxx &&
129+
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -I. -o index_examples examples/mongocxx/mongodb.com/index_examples.cpp -lmongocxx -lbsoncxx &&
130+
/usr/bin/g++ -I/usr/include/bsoncxx/v_noabi -I/usr/include/mongocxx/v_noabi -I. -o documentation_examples examples/mongocxx/mongodb.com/documentation_examples.cpp -lmongocxx -lbsoncxx
131131
)"
132132

133133
if [ ! -e "${mock_root}/tmp/${build_dir}/runcommand_examples" ]; then

examples/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ function(add_examples_executable source)
6666
add_executable(${target_name} EXCLUDE_FROM_ALL ${source})
6767
target_link_libraries(${target_name} PRIVATE ${PARSED_LIBRARIES})
6868

69+
# Permit `#include <examples/macros.hh>`.
70+
target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
71+
6972
# Keep executables in separate directories.
7073
set_target_properties(${target_name} PROPERTIES
7174
OUTPUT_NAME ${name}
@@ -123,6 +126,12 @@ file(GLOB_RECURSE mongocxx_examples_sources
123126
"mongocxx/*.cpp"
124127
)
125128

129+
file(GLOB_RECURSE examples_headers
130+
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
131+
CONFIGURE_DEPENDS
132+
"*.hh"
133+
)
134+
126135
foreach(source ${api_examples_sources})
127136
add_examples_executable(${source} LIBRARIES mongocxx_target)
128137
endforeach()
@@ -155,6 +164,7 @@ set_local_dist (examples_DIST_local
155164
${api_examples_sources}
156165
${bsoncxx_examples_sources}
157166
${mongocxx_examples_sources}
167+
${examples_headers}
158168
README.md
159169
add_subdirectory/.gitignore
160170
add_subdirectory/CMakeLists.txt

examples/bsoncxx/builder_basic.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
#include <bsoncxx/builder/basic/kvp.hpp>
2020
#include <bsoncxx/types.hpp>
2121

22+
#include <examples/macros.hh>
23+
2224
using namespace bsoncxx;
2325

24-
int main() {
26+
int EXAMPLES_CDECL main() {
2527
// bsoncxx::builder::basic presents a BSON-construction interface familiar to users of the
2628
// server's
2729
// BSON library or the Java driver.

examples/bsoncxx/builder_core.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
#include <bsoncxx/builder/core.hpp>
1616
#include <bsoncxx/types.hpp>
1717

18+
#include <examples/macros.hh>
19+
1820
using namespace bsoncxx;
1921

20-
int main() {
22+
int EXAMPLES_CDECL main() {
2123
// bsoncxx::builder::core is a low-level primitive that can be useful for building other
2224
// BSON abstractions. Most users should just use builder::stream or builder::basic.
2325

examples/bsoncxx/builder_list.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include <bsoncxx/types.hpp>
1919
#include <bsoncxx/types/bson_value/value.hpp>
2020

21+
#include <examples/macros.hh>
22+
2123
using namespace bsoncxx;
2224

23-
int main() {
25+
int EXAMPLES_CDECL main() {
2426
using namespace bsoncxx::builder;
2527

2628
//

examples/bsoncxx/builder_stream.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#include <bsoncxx/builder/stream/helpers.hpp>
1818
#include <bsoncxx/types.hpp>
1919

20+
#include <examples/macros.hh>
21+
2022
using namespace bsoncxx;
2123

22-
int main() {
24+
int EXAMPLES_CDECL main() {
2325
using builder::stream::array;
2426
using builder::stream::document;
2527

examples/bsoncxx/builder_stream_customization.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <bsoncxx/builder/stream/document.hpp>
2020
#include <bsoncxx/json.hpp>
2121

22+
#include <examples/macros.hh>
23+
2224
using namespace bsoncxx;
2325

2426
// concatenates arbitrary ranges into an array context
@@ -68,7 +70,7 @@ range_kvp_appender<begin_t, end_t> make_range_kvp_appender(begin_t&& begin, end_
6870
std::forward<end_t>(end));
6971
}
7072

71-
int main() {
73+
int EXAMPLES_CDECL main() {
7274
using builder::stream::array;
7375
using builder::stream::document;
7476
using builder::stream::finalize;

examples/bsoncxx/decimal128.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
#include <bsoncxx/exception/exception.hpp>
2121
#include <bsoncxx/types.hpp>
2222

23+
#include <examples/macros.hh>
24+
2325
using namespace bsoncxx;
2426

25-
int main() {
27+
int EXAMPLES_CDECL main() {
2628
// Convert a string to BSON Decimal128.
2729
decimal128 d128;
2830
try {

examples/bsoncxx/getting_values.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
#include <bsoncxx/config/prelude.hpp>
2323

24+
#include <examples/macros.hh>
25+
2426
using namespace bsoncxx;
2527

26-
int main() {
28+
int EXAMPLES_CDECL main() {
2729
using namespace builder::stream;
2830

2931
builder::stream::document build_doc;

examples/bsoncxx/view_and_value.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
#include <bsoncxx/types.hpp>
3030
#include <bsoncxx/types/bson_value/view.hpp>
3131

32+
#include <examples/macros.hh>
33+
3234
using namespace bsoncxx;
3335

34-
int main() {
36+
int EXAMPLES_CDECL main() {
3537
// This example will cover the read-only BSON interface.
3638

3739
// Lets first build up a non-trivial BSON document using the builder interface.

examples/macros.hh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2009-present MongoDB, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#if defined(_MSC_VER)
18+
#define EXAMPLES_CDECL __cdecl
19+
#else
20+
#define EXAMPLES_CDECL
21+
#endif

examples/mongocxx/aggregate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#include <mongocxx/pipeline.hpp>
2323
#include <mongocxx/uri.hpp>
2424

25+
#include <examples/macros.hh>
26+
2527
using bsoncxx::builder::basic::kvp;
2628
using bsoncxx::builder::basic::make_document;
2729

28-
int main() {
30+
int EXAMPLES_CDECL main() {
2931
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
3032
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
3133
// must remain alive for as long as the driver is in use.

examples/mongocxx/automatic_client_side_field_level_encryption.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <mongocxx/options/data_key.hpp>
3333
#include <mongocxx/options/encrypt.hpp>
3434

35+
#include <examples/macros.hh>
36+
3537
using bsoncxx::builder::basic::kvp;
3638
using bsoncxx::builder::basic::make_document;
3739

examples/mongocxx/bulk_write.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#include <mongocxx/instance.hpp>
2323
#include <mongocxx/uri.hpp>
2424

25+
#include <examples/macros.hh>
26+
2527
using bsoncxx::builder::basic::kvp;
2628
using bsoncxx::builder::basic::make_document;
2729

28-
int main() {
30+
int EXAMPLES_CDECL main() {
2931
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
3032
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
3133
// must remain alive for as long as the driver is in use.

examples/mongocxx/causal_consistency.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
#include <mongocxx/uri.hpp>
3232
#include <mongocxx/write_concern.hpp>
3333

34+
#include <examples/macros.hh>
35+
3436
using bsoncxx::builder::stream::close_document;
3537
using bsoncxx::builder::stream::document;
3638
using bsoncxx::builder::stream::finalize;
3739
using bsoncxx::builder::stream::open_document;
3840

39-
int main() {
41+
int EXAMPLES_CDECL main() {
4042
if (const char* const topology_env = std::getenv("MONGOCXX_TEST_TOPOLOGY")) {
4143
const auto topology = std::string(topology_env);
4244
if (topology != "replica") {

examples/mongocxx/change_streams.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <mongocxx/pool.hpp>
2727
#include <mongocxx/uri.hpp>
2828

29+
#include <examples/macros.hh>
30+
2931
namespace {
3032

3133
// watch_forever iterates the change stream until an error occurs.
@@ -47,7 +49,7 @@ namespace {
4749

4850
} // namespace
4951

50-
int main(int argc, char* argv[]) {
52+
int EXAMPLES_CDECL main(int argc, char* argv[]) {
5153
if (std::getenv("MONGOCXX_TEST_TOPOLOGY")) {
5254
std::cerr << "Skipping: change_streams example should not be run by tests" << std::endl;
5355
return 0;

examples/mongocxx/client_session.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
#include <mongocxx/instance.hpp>
2424
#include <mongocxx/uri.hpp>
2525

26+
#include <examples/macros.hh>
27+
2628
using bsoncxx::to_json;
2729
using bsoncxx::builder::basic::kvp;
2830
using bsoncxx::builder::basic::make_document;
2931
using namespace mongocxx;
3032

31-
int main() {
33+
int EXAMPLES_CDECL main() {
3234
if (const char* const topology_env = std::getenv("MONGOCXX_TEST_TOPOLOGY")) {
3335
const auto topology = std::string(topology_env);
3436
if (topology != "replica") {

examples/mongocxx/connect.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <mongocxx/options/client.hpp>
2626
#include <mongocxx/uri.hpp>
2727

28+
#include <examples/macros.hh>
29+
2830
namespace {
2931

3032
class logger final : public mongocxx::logger {
@@ -50,7 +52,7 @@ std::unique_ptr<logger> make_logger() {
5052

5153
} // namespace
5254

53-
int main(int argc, char* argv[]) {
55+
int EXAMPLES_CDECL main(int argc, char* argv[]) {
5456
using bsoncxx::builder::basic::kvp;
5557
using bsoncxx::builder::basic::make_document;
5658

examples/mongocxx/create.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
#include <mongocxx/instance.hpp>
2323
#include <mongocxx/uri.hpp>
2424

25+
#include <examples/macros.hh>
26+
2527
using bsoncxx::builder::basic::kvp;
2628
using bsoncxx::builder::basic::make_array;
2729
using bsoncxx::builder::basic::make_document;
2830

29-
int main() {
31+
int EXAMPLES_CDECL main() {
3032
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
3133
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
3234
// must remain alive for as long as the driver is in use.

examples/mongocxx/document_validation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
#include <mongocxx/instance.hpp>
2323
#include <mongocxx/uri.hpp>
2424

25+
#include <examples/macros.hh>
26+
2527
using bsoncxx::builder::basic::kvp;
2628
using bsoncxx::builder::basic::make_document;
2729
using bsoncxx::stdx::string_view;
2830
using mongocxx::collection;
2931
using mongocxx::validation_criteria;
3032

31-
int main() {
33+
int EXAMPLES_CDECL main() {
3234
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
3335
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
3436
// must remain alive for as long as the driver is in use.

examples/mongocxx/exception.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
#include <mongocxx/instance.hpp>
2828
#include <mongocxx/uri.hpp>
2929

30+
#include <examples/macros.hh>
31+
3032
using bsoncxx::builder::basic::kvp;
3133
using bsoncxx::builder::basic::make_document;
3234

33-
int main() {
35+
int EXAMPLES_CDECL main() {
3436
// Do not print error messages when run in CI to prevent MSBuild diagnostic format detection
3537
// from causing build failures. There is currently no way to specify
3638
// IgnoreStandardErrorWarningFormat=true via CMake or CLI. See:

examples/mongocxx/explicit_encryption.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <mongocxx/options/data_key.hpp>
3232
#include <mongocxx/options/encrypt.hpp>
3333

34+
#include <examples/macros.hh>
35+
3436
using bsoncxx::builder::basic::kvp;
3537
using bsoncxx::builder::basic::make_document;
3638

@@ -45,7 +47,7 @@ using namespace mongocxx;
4547

4648
const int kKeyLength = 96;
4749

48-
int main() {
50+
int EXAMPLES_CDECL main() {
4951
instance inst{};
5052

5153
// This must be the same master key that was used to create

examples/mongocxx/explicit_encryption_auto_decryption.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <mongocxx/options/data_key.hpp>
3232
#include <mongocxx/options/encrypt.hpp>
3333

34+
#include <examples/macros.hh>
35+
3436
using bsoncxx::builder::basic::kvp;
3537
using bsoncxx::builder::basic::make_document;
3638

@@ -45,7 +47,7 @@ using namespace mongocxx;
4547

4648
const int kKeyLength = 96;
4749

48-
int main() {
50+
int EXAMPLES_CDECL main() {
4951
instance inst{};
5052

5153
// This must be the same master key that was used to create

examples/mongocxx/get_values_from_documents.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <mongocxx/client.hpp>
2121
#include <mongocxx/instance.hpp>
2222

23+
#include <examples/macros.hh>
24+
2325
using bsoncxx::type;
2426
using bsoncxx::builder::basic::kvp;
2527
using bsoncxx::builder::basic::make_array;

examples/mongocxx/gridfs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
#include <mongocxx/instance.hpp>
2323
#include <mongocxx/uri.hpp>
2424

25+
#include <examples/macros.hh>
26+
2527
using namespace mongocxx;
2628

27-
int main() {
29+
int EXAMPLES_CDECL main() {
2830
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
2931
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
3032
// must remain alive for as long as the driver is in use.

examples/mongocxx/index.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include <mongocxx/instance.hpp>
1919
#include <mongocxx/uri.hpp>
2020

21+
#include <examples/macros.hh>
22+
2123
using bsoncxx::builder::basic::kvp;
2224
using bsoncxx::builder::basic::make_document;
2325

24-
int main() {
26+
int EXAMPLES_CDECL main() {
2527
// The mongocxx::instance constructor and destructor initialize and shut down the driver,
2628
// respectively. Therefore, a mongocxx::instance must be created before using the driver and
2729
// must remain alive for as long as the driver is in use.

0 commit comments

Comments
 (0)