diff options
author | Andrew Morrow <acm@mongodb.com> | 2020-09-01 13:06:46 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-02 03:02:47 +0000 |
commit | b478d31b7dd7b73a965ef48a3a242e9b2c2d4d9a (patch) | |
tree | 65576bc681d099800dcc9da38afeed46afd912de | |
parent | 762d65bb4685589a47f0a6b750222e6b4d774f57 (diff) | |
download | mongo-b478d31b7dd7b73a965ef48a3a242e9b2c2d4d9a.tar.gz |
SERVER-27507 Add basic visibility support and a test
-rw-r--r-- | SConstruct | 60 | ||||
-rw-r--r-- | site_scons/libdeps.py | 7 | ||||
-rw-r--r-- | site_scons/site_tools/auto_install_binaries.py | 9 | ||||
-rw-r--r-- | src/mongo/platform/SConscript | 80 | ||||
-rw-r--r-- | src/mongo/platform/visibility.h | 62 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test1.cpp | 39 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test2.cpp | 39 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test_lib1.cpp | 55 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test_lib1.h | 50 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test_lib2.cpp | 55 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test_lib2.h | 49 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test_libcommon.cpp | 53 | ||||
-rw-r--r-- | src/mongo/platform/visibility_test_libcommon.h | 41 |
13 files changed, 592 insertions, 7 deletions
diff --git a/SConstruct b/SConstruct index a111a1d39dd..c29b0ac94c5 100644 --- a/SConstruct +++ b/SConstruct @@ -537,6 +537,15 @@ add_option('libdeps-linting', type='choice', ) +add_option('experimental-visibility-support', + choices=['on', 'off'], + const='on', + default='off', + help='Enable visibility annotations (experimental)', + nargs='?', + type='choice', +) + try: with open("version.json", "r") as version_fp: version_data = json.load(version_fp) @@ -1431,8 +1440,9 @@ if use_libunwind == True: # Windows can't currently support anything other than 'object' or 'static', until # we have annotated functions for export. -if env.TargetOSIs('windows') and link_model not in ['object', 'static', 'dynamic-sdk']: - env.FatalError("Windows builds must use the 'object', 'dynamic-sdk', or 'static' link models") +if env.TargetOSIs('windows') and get_option('experimental-visibility-support') != 'on': + if link_model not in ['object', 'static', 'dynamic-sdk']: + env.FatalError("Windows builds must use the 'object', 'dynamic-sdk', or 'static' link models") # The 'object' mode for libdeps is enabled by setting _LIBDEPS to $_LIBDEPS_OBJS. The other two # modes operate in library mode, enabled by setting _LIBDEPS to $_LIBDEPS_LIBS. @@ -1453,6 +1463,39 @@ env['BUILDERS']['SharedArchive'] = SCons.Builder.Builder( if link_model.startswith("dynamic"): + if link_model == "dynamic" and get_option('experimental-visibility-support') == 'on': + + def visibility_cppdefines_generator(target, source, env, for_signature): + if not 'MONGO_API_NAME' in env: + return None + return "MONGO_API_${MONGO_API_NAME}" + + env['MONGO_VISIBILITY_CPPDEFINES_GENERATOR'] = visibility_cppdefines_generator + + def visibility_shccflags_generator(target, source, env, for_signature): + if env.get('MONGO_API_NAME'): + return "-fvisibility=hidden" + return None + if not env.TargetOSIs('windows'): + env['MONGO_VISIBILITY_SHCCFLAGS_GENERATOR'] = visibility_shccflags_generator + + env.AppendUnique( + CPPDEFINES=[ + 'MONGO_USE_VISIBILITY', + '$MONGO_VISIBILITY_CPPDEFINES_GENERATOR', + ], + SHCCFLAGS=[ + '$MONGO_VISIBILITY_SHCCFLAGS_GENERATOR', + ], + SHCXXFLAGS=[ + # TODO: This has broader implications and seems not to + # work right now at least on macOS. We should + # investigate further in the future. + # + # '-fvisibility-inlines-hidden' if not env.TargetOSIs('windows') else [], + ], + ) + def library(env, target, source, *args, **kwargs): sharedLibrary = env.SharedLibrary(target, source, *args, **kwargs) sharedArchive = env.SharedArchive(target, source=sharedLibrary[0].sources, *args, **kwargs) @@ -1872,6 +1915,12 @@ elif env.TargetOSIs('windows'): # have these, but we don't want to fix them up before we roll # over to C++17. "/wd5041", + + # C4251: This warning attempts to prevent usage of CRT (C++ + # standard library) types in DLL interfaces. That is a good + # idea for DLLs you ship to others, but in our case, we know + # that all DLLs are built consistently. Suppress the warning. + "/wd4251", ]) # mozjs-60 requires the following @@ -4646,6 +4695,13 @@ cachePrune = env.Command( env.AlwaysBuild(cachePrune) +# Add a trivial Alias called `configure`. This makes it simple to run, +# or re-run, the SConscript reading and conf tests, but not build any +# real targets. This can be helpful when you are planning a dry-run +# build, or simply want to validate your changes to SConstruct, tools, +# and all the other setup that happens before we begin a real graph +# walk. +env.Alias('configure', None) # We have finished all SConscripts and targets, so we can ask # auto_install_binaries to finalize the installation setup. diff --git a/site_scons/libdeps.py b/site_scons/libdeps.py index 63d1aeaa62e..4e2d1723a9c 100644 --- a/site_scons/libdeps.py +++ b/site_scons/libdeps.py @@ -714,6 +714,13 @@ def __get_node_with_ixes(env, node, node_builder_type): except KeyError: prefix = node_builder.get_prefix(env) suffix = node_builder.get_suffix(env) + + # TODO(SERVER-50681): Find a way to do this that doesn't hard + # code these extensions. See the code review for SERVER-27507 + # for additional discussion. + if suffix == ".dll": + suffix = ".lib" + __get_node_with_ixes.node_type_ixes[cache_key] = (prefix, suffix) node_with_ixes = SCons.Util.adjustixes(node, prefix, suffix) diff --git a/site_scons/site_tools/auto_install_binaries.py b/site_scons/site_tools/auto_install_binaries.py index 136b0e5b393..d42cd3cba7b 100644 --- a/site_scons/site_tools/auto_install_binaries.py +++ b/site_scons/site_tools/auto_install_binaries.py @@ -268,12 +268,13 @@ def scan_for_transitive_install(node, env, _path): if base_base_entry.files: results.update(base_base_entry.files) - installed_children = [ + installed_children = set( grandchild for child in node.children() - for grandchild in child.children() - if grandchild.has_builder() - ] + for direct_children in child.children() + for grandchild in direct_children.get_executor().get_all_targets() + if direct_children.get_executor() and grandchild.has_builder() + ) for child in installed_children: auto_installed_files = get_auto_installed_files(env, child) diff --git a/src/mongo/platform/SConscript b/src/mongo/platform/SConscript index 648445c0746..e898e9642e7 100644 --- a/src/mongo/platform/SConscript +++ b/src/mongo/platform/SConscript @@ -1,6 +1,10 @@ # -*- mode: python -*- -Import("env") +Import([ + "env", + "get_option", +]) + env = env.Clone() env.CppUnitTest( target='platform_test', @@ -29,3 +33,77 @@ env.Benchmark( ], ) +if not get_option("link-model") == "dynamic": + Return() + +env.Library( + target="visibility_test_libcommon", + source=[ + "visibility_test_libcommon.cpp", + ], + LIBDEPS=[], + DISABLE_ALLOCATOR_SHIM_INJECTION=True, + MONGO_API_NAME="visibility_test_libcommon", +) + +env.Library( + target="visibility_test_lib1", + source=[ + "visibility_test_lib1.cpp" + ], + LIBDEPS=[], + LIBDEPS_PRIVATE=[ + "visibility_test_libcommon", + ], + DISABLE_ALLOCATOR_SHIM_INJECTION=True, + MONGO_API_NAME="visibility_test_lib1", +) + +env.Library( + target="visibility_test_lib2", + source=[ + "visibility_test_lib2.cpp" + ], + LIBDEPS=[ + "visibility_test_lib1", + ], + LIBDEPS_PRIVATE=[ + "visibility_test_libcommon", + ], + DISABLE_ALLOCATOR_SHIM_INJECTION=True, + MONGO_API_NAME="visibility_test_lib2", +) + +visibility_test1 = env.Program( + target="visibility_test1", + source=[ + "visibility_test1.cpp", + ], + LIBDEPS=[ + "visibility_test_lib1", + ], + DISABLE_ALLOCATOR_SHIM_INJECTION=True, + AIB_COMPONENT="visibility-test", + AIB_COMPONENTS_EXTRA=[ + "unittests", + "tests", + ], +) +env.RegisterTest("$UNITTEST_LIST", visibility_test1[0]) + +visibility_test2 = env.Program( + target="visibility_test2", + source=[ + "visibility_test2.cpp", + ], + LIBDEPS=[ + "visibility_test_lib2", + ], + DISABLE_ALLOCATOR_SHIM_INJECTION=True, + AIB_COMPONENT="visibility-test", + AIB_COMPONENTS_EXTRA=[ + "unittests", + "tests", + ], +) +env.RegisterTest("$UNITTEST_LIST", visibility_test2[0]) diff --git a/src/mongo/platform/visibility.h b/src/mongo/platform/visibility.h new file mode 100644 index 00000000000..b251ab705e0 --- /dev/null +++ b/src/mongo/platform/visibility.h @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#if !defined(MONGO_USE_VISIBILITY) + +#define MONGO_VISIBILITY_PUBLIC() +#define MONGO_VISIBILITY_PRIVATE() +#define MONGO_PRIVATE +#define MONGO_API(LIB) + +#else + +#if defined(_MSC_VER) + +#include <boost/preprocessor/control/iif.hpp> +#include <boost/vmd/is_number.hpp> + +#define MONGO_DLLEXPORT() __declspec(dllexport) +#define MONGO_DLLIMPORT() __declspec(dllimport) +#define MONGO_PRIVATE +#define MONGO_API_IMPL2(COND) BOOST_PP_IIF(COND, MONGO_DLLEXPORT, MONGO_DLLIMPORT)() +#define MONGO_API_IMPL(ARG) MONGO_API_IMPL2(BOOST_VMD_IS_NUMBER(ARG)) +#define MONGO_API(LIB) MONGO_API_IMPL(MONGO_API_##LIB) + +#else + +#define MONGO_VISIBILITY_PUBLIC() __attribute__((visibility("default"))) +#define MONGO_VISIBILITY_PRIVATE() __attribute__((visibility("hidden"))) +#define MONGO_PRIVATE MONGO_VISIBILITY_PRIVATE() +#define MONGO_API(LIB) MONGO_VISIBILITY_PUBLIC() + +#endif + +#endif diff --git a/src/mongo/platform/visibility_test1.cpp b/src/mongo/platform/visibility_test1.cpp new file mode 100644 index 00000000000..33341d8a5e0 --- /dev/null +++ b/src/mongo/platform/visibility_test1.cpp @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/platform/visibility_test_lib1.h" + +#include <cstdlib> + +int main(int argc, char* argv[]) { + mongo::visibility_test_lib1::Base b("hello"); + return (b.name() == "hello") ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/src/mongo/platform/visibility_test2.cpp b/src/mongo/platform/visibility_test2.cpp new file mode 100644 index 00000000000..baf69b36412 --- /dev/null +++ b/src/mongo/platform/visibility_test2.cpp @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/platform/visibility_test_lib2.h" + +#include <cstdlib> + +int main(int argc, char* argv[]) { + mongo::visibility_test_lib2::Derived d("hello", argc); + return (d.value() == argc) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/src/mongo/platform/visibility_test_lib1.cpp b/src/mongo/platform/visibility_test_lib1.cpp new file mode 100644 index 00000000000..073f743c2af --- /dev/null +++ b/src/mongo/platform/visibility_test_lib1.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/platform/visibility_test_lib1.h" + +#include <stdexcept> + +#include "mongo/platform/visibility_test_libcommon.h" + +namespace mongo { +namespace visibility_test_lib1 { + +Base::Base(const std::string& name) : _name(name) { + _validate(_name); +} + +std::string_view Base::name() const { + return _name; +} + +void Base::_validate(std::string_view name) { + if (!visibility_test_libcommon::validate(name)) + throw std::logic_error("Invalid name"); +} + +} // namespace visibility_test_lib1 +} // namespace mongo diff --git a/src/mongo/platform/visibility_test_lib1.h b/src/mongo/platform/visibility_test_lib1.h new file mode 100644 index 00000000000..d35ff10e4e6 --- /dev/null +++ b/src/mongo/platform/visibility_test_lib1.h @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include <string> +#include <string_view> + +#include "mongo/platform/visibility.h" + +namespace mongo { +namespace visibility_test_lib1 { + +class MONGO_API(visibility_test_lib1) Base { +public: + explicit Base(const std::string& name); + std::string_view name() const; + +private: + MONGO_PRIVATE static void _validate(std::string_view); + + std::string _name; +}; + +} // namespace visibility_test_lib1 +} // namespace mongo diff --git a/src/mongo/platform/visibility_test_lib2.cpp b/src/mongo/platform/visibility_test_lib2.cpp new file mode 100644 index 00000000000..0fc9d9d9f65 --- /dev/null +++ b/src/mongo/platform/visibility_test_lib2.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/platform/visibility_test_lib2.h" + +#include <stdexcept> + +#include "mongo/platform/visibility_test_libcommon.h" + +namespace mongo { +namespace visibility_test_lib2 { + +Derived::Derived(const std::string& name, double value) : Base(name), _value(value) { + _validate(_value); +} + +double Derived::value() const { + return _value; +} + +void Derived::_validate(double value) { + if (!visibility_test_libcommon::validate(value)) + throw std::logic_error("Invalid value"); +} + +} // namespace visibility_test_lib2 +} // namespace mongo diff --git a/src/mongo/platform/visibility_test_lib2.h b/src/mongo/platform/visibility_test_lib2.h new file mode 100644 index 00000000000..94143460cec --- /dev/null +++ b/src/mongo/platform/visibility_test_lib2.h @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + + +#include "mongo/platform/visibility.h" +#include "mongo/platform/visibility_test_lib1.h" + +namespace mongo { +namespace visibility_test_lib2 { + +class MONGO_API(visibility_test_lib2) Derived : public visibility_test_lib1::Base { +public: + explicit Derived(const std::string& name, double value); + double value() const; + +private: + MONGO_PRIVATE static void _validate(double); + + double _value; +}; + +} // namespace visibility_test_lib2 +} // namespace mongo diff --git a/src/mongo/platform/visibility_test_libcommon.cpp b/src/mongo/platform/visibility_test_libcommon.cpp new file mode 100644 index 00000000000..112554a4a99 --- /dev/null +++ b/src/mongo/platform/visibility_test_libcommon.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/platform/visibility_test_libcommon.h" + +#include <stdexcept> + +namespace mongo { +namespace visibility_test_libcommon { + +namespace { +const std::string_view kInvalidStringView = "invalid"; +const double kInvalidDouble = -1; +} // namespace + +bool validate(std::string_view data) { + return data != kInvalidStringView; +} + +bool validate(double data) { + return data != kInvalidDouble; +} + +} // namespace visibility_test_libcommon +} // namespace mongo diff --git a/src/mongo/platform/visibility_test_libcommon.h b/src/mongo/platform/visibility_test_libcommon.h new file mode 100644 index 00000000000..feb77f996fb --- /dev/null +++ b/src/mongo/platform/visibility_test_libcommon.h @@ -0,0 +1,41 @@ +/** + * Copyright (C) 2020-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include <string_view> + +#include "mongo/platform/visibility.h" + +namespace mongo { +namespace visibility_test_libcommon { + +MONGO_API(visibility_test_libcommon) bool validate(std::string_view data); +MONGO_API(visibility_test_libcommon) bool validate(double data); + +} // namespace visibility_test_libcommon +} // namespace mongo |