diff --git a/.evergreen/config_generator/components/earthly.py b/.evergreen/config_generator/components/earthly.py index 4dac11f31dc..67dfd739ac7 100644 --- a/.evergreen/config_generator/components/earthly.py +++ b/.evergreen/config_generator/components/earthly.py @@ -38,7 +38,7 @@ "Valid options for the SASL configuration parameter" TLSOption = Literal["OpenSSL", "off"] "Options for the TLS backend configuration parameter (AKA 'ENABLE_SSL')" -CxxVersion = Literal["none"] # TODO: Once CXX-3103 is released, add latest C++ release tag. +CxxVersion = Literal["none"] # TODO: Once CXX-3103 is released, add latest C++ release tag. "C++ driver refs that are under CI test" # A separator character, since we cannot use whitespace @@ -266,6 +266,13 @@ def tasks() -> Iterable[EvgTask]: if task is not None: yield task + yield EvgTask( + name="verify-headers", + commands=[earthly_exec(kind="test", target="verify-headers")], + tags=["pr-merge-gate"], + run_on=CONTAINER_RUN_DISTROS, + ) + def variants() -> Iterable[BuildVariant]: yield from (ev.as_evg_variant() for ev in all_possible(EarthlyVariant)) diff --git a/.evergreen/generated_configs/legacy-config.yml b/.evergreen/generated_configs/legacy-config.yml index 7a48ec2fb6b..81be961752a 100644 --- a/.evergreen/generated_configs/legacy-config.yml +++ b/.evergreen/generated_configs/legacy-config.yml @@ -16250,6 +16250,7 @@ buildvariants: - link-with-cmake - link-with-cmake-ssl - link-with-cmake-snappy + - verify-headers - name: link-with-cmake-mac distros: - macos-14-arm64 diff --git a/.evergreen/generated_configs/tasks.yml b/.evergreen/generated_configs/tasks.yml index b5abdbc7d7f..fddb7425014 100644 --- a/.evergreen/generated_configs/tasks.yml +++ b/.evergreen/generated_configs/tasks.yml @@ -6420,3 +6420,19 @@ tasks: - func: bootstrap-mongo-orchestration - func: run-simple-http-server - func: run-tests + - name: verify-headers + run_on: + - amazon2 + - debian11-large + - debian12-large + - ubuntu2204-large + - ubuntu2404-large + tags: [pr-merge-gate] + commands: + - command: subprocess.exec + type: test + params: + binary: ./tools/earthly.sh + working_dir: mongoc + args: + - +verify-headers diff --git a/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py b/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py index 29fc8753224..efa1df35819 100644 --- a/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py +++ b/.evergreen/legacy_config_generator/evergreen_config_lib/variants.py @@ -50,6 +50,7 @@ def days(n: int) -> int: "link-with-cmake", "link-with-cmake-ssl", "link-with-cmake-snappy", + "verify-headers", OD([("name", "link-with-cmake-mac"), ("distros", ["macos-14-arm64"])]), OD([("name", "link-with-cmake-windows"), ("distros", ["windows-vsCurrent-large"])]), OD([("name", "link-with-cmake-windows-ssl"), ("distros", ["windows-vsCurrent-large"])]), @@ -84,7 +85,7 @@ def days(n: int) -> int: "build-and-run-authentication-tests-openssl-1.0.1", "build-and-run-authentication-tests-openssl-1.0.2", "build-and-run-authentication-tests-openssl-1.1.0", - "build-and-run-authentication-tests-openssl-1.0.1-fips" + "build-and-run-authentication-tests-openssl-1.0.1-fips", ], {}, ), @@ -356,7 +357,7 @@ def days(n: int) -> int: "name": "ocsp-openssl-1.0.1", "execution_tasks": [".ocsp-openssl-1.0.1"], }, - ] + ], ), Variant( "packaging", @@ -380,7 +381,7 @@ def days(n: int) -> int: ".versioned-api .5.0", ".versioned-api .6.0", ".versioned-api .7.0", - ".versioned-api .8.0" + ".versioned-api .8.0", ], {}, ), diff --git a/.evergreen/scripts/check-preludes.py b/.evergreen/scripts/check-preludes.py index cd0fb8c8b09..3b5807f3707 100644 --- a/.evergreen/scripts/check-preludes.py +++ b/.evergreen/scripts/check-preludes.py @@ -39,7 +39,7 @@ }, { "name": "libbson", - "headers": list(BSON_PREFIX.glob("*.h")), + "headers": list(BSON_PREFIX.glob("bson-*.h")), "exclusions": [ BSON_PREFIX / "bson-prelude.h", BSON_PREFIX / "bson.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index b2f926510e5..a044cfb0b65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ include(FeatureSummary) include (MongoSettings) include (MongoPlatform) include (GeneratePkgConfig) +include (VerifyHeaders) # Subcomponents: mongo_bool_setting(ENABLE_MONGOC "Enable the build of libmongoc libraries (The MongoDB C database driver)") diff --git a/Earthfile b/Earthfile index 6d668088f7a..5652e55291e 100644 --- a/Earthfile +++ b/Earthfile @@ -6,25 +6,11 @@ IMPORT ./tools/ AS tools # For target names, descriptions, and build parameters, run the "doc" Earthly subcommand. # Example use: +build --env=u22 --sasl=off --tls=OpenSSL --c_compiler=gcc -# build : -# Build libmongoc and libbson using the specified environment. -# -# The --env argument specifies the build environment among the `+env.xyz` environment -# targets, using --purpose=build for the build environment. Refer to the target -# list for a list of available build environments. -build: - # env is an argument - ARG --required env - FROM --pass-args +env.$env --purpose=build - # The configuration to be built - ARG config=RelWithDebInfo - # The prefix at which to install the built result - ARG install_prefix=/opt/mongo-c-driver - # Build configuration parameters. Will be case-normalized for CMake usage. - ARG --required sasl - ARG --required tls - LET source_dir=/opt/mongoc/source - LET build_dir=/opt/mongoc/build +# COPY_SOURCE : +# Copy source files required for the build into the specified "--into" directory +COPY_SOURCE: + COMMAND + ARG --required into COPY --dir \ build/ \ CMakeLists.txt \ @@ -34,8 +20,16 @@ build: src/ \ THIRD_PARTY_NOTICES \ VERSION_CURRENT \ - "$source_dir" - ENV CCACHE_HOME=/root/.cache/ccache + "$into" + +# CONFIGURE : +# Configure the project in $source_dir into $build_dir with a common set of configuration options +CONFIGURE: + COMMAND + ARG --required source_dir + ARG --required build_dir + ARG --required tls + ARG --required sasl RUN cmake -S "$source_dir" -B "$build_dir" -G "Ninja Multi-Config" \ -D ENABLE_MAINTAINER_FLAGS=ON \ -D ENABLE_SHM_COUNTERS=ON \ @@ -47,6 +41,29 @@ build: -D ENABLE_COVERAGE=ON \ -D ENABLE_DEBUG_ASSERTIONS=ON \ -Werror + +# build : +# Build libmongoc and libbson using the specified environment. +# +# The --env argument specifies the build environment among the `+env.xyz` environment +# targets, using --purpose=build for the build environment. Refer to the target +# list for a list of available build environments. +build: + # env is an argument + ARG --required env + FROM --pass-args +env.$env --purpose=build + # The configuration to be built + ARG config=RelWithDebInfo + # The prefix at which to install the built result + ARG install_prefix=/opt/mongo-c-driver + # Build configuration parameters. Will be case-normalized for CMake usage. + ARG --required sasl + ARG --required tls + LET source_dir=/opt/mongoc/source + LET build_dir=/opt/mongoc/build + DO +COPY_SOURCE --into=$source_dir + ENV CCACHE_HOME=/root/.cache/ccache + DO --pass-args +CONFIGURE --source_dir=$source_dir --build_dir=$build_dir RUN --mount=type=cache,target=$CCACHE_HOME \ env CCACHE_BASE="$source_dir" \ cmake --build $build_dir --config $config @@ -396,6 +413,34 @@ vcpkg-base: COPY src/libmongoc/examples/cmake/vcpkg/ $src_dir WORKDIR $src_dir +# verify-headers : +# Execute CMake header verification on the sources +# +# See `earthly.rst` for more details. +verify-headers: + # We test against multiple different platforms, because glibc/musl versions may + # rearrange their header contents and requirements, so we want to check against as + # many as possible. + BUILD +do-verify-headers-impl \ + --from +env.alpine3.19 \ + --from +env.u22 \ + --from +env.centos7 \ + --sasl=off --tls=off --cxx_compiler=gcc --c_compiler=gcc + +do-verify-headers-impl: + ARG --required from + # We don't really care about the specifics of the build env/settings, so set some + # reasonable defaults so the caller doesn't need to specify. In the future, it is + # possible that we will need to test other environments and build settings. + FROM --pass-args "$from" --purpose=build + # Add C++ so we can test as C++ headers + DO --pass-args tools+ADD_CXX_COMPILER + DO +COPY_SOURCE --into=/s + DO --pass-args +CONFIGURE --source_dir /s --build_dir /s/_build + # The "all_verify_interface_header_sets" target is created automatically + # by CMake for the VERIFY_INTERFACE_HEADER_SETS target property. + RUN cmake --build /s/_build --target all_verify_interface_header_sets + # run : # Run one or more targets simultaneously. # diff --git a/build/cmake/VerifyHeaders.cmake b/build/cmake/VerifyHeaders.cmake new file mode 100644 index 00000000000..89407127878 --- /dev/null +++ b/build/cmake/VerifyHeaders.cmake @@ -0,0 +1,116 @@ +include_guard(DIRECTORY) + +#[==[ +Add header verification targets for given headers: + + mongo_verify_headers( + + [USES_LIBRARIES [ ...]] + [HEADERS [ ...]] + [EXCLUDE_REGEX [ ...]] + ) + +Here `` is an arbitrary string that is used to qualify the internal target +created for the verification. The `` expressions are used to automatically +collect sources files (relative to the current source directory). All files +collected by `` must live within the current source directory. + +After collecting sources according to the `` patterns, sources are +excluded if the filepath contains any substring that matches any regular +expression in the `` list. Each `` is tested against the +relative path to the header file that was found by ``, and not the +absolute path to the file. + +The header verification targets are compiled according to the usage requirements +from all `` arguments. +]==] +function(mongo_verify_headers tag) + list(APPEND CMAKE_MESSAGE_CONTEXT "${CMAKE_CURRENT_FUNCTION}(${tag})") + cmake_parse_arguments( + PARSE_ARGV 1 arg + "" # No flags + "" # No args + "HEADERS;EXCLUDE_REGEX;USE_LIBRARIES" # List args + ) + if(arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown arguments: ${arg_UNPARSED_ARGUMENTS}") + endif() + + # Collect headers according to our patterns + set(headers_to_verify) + foreach(pattern IN LISTS arg_HEADERS) + # Use a recursive glob from the current source dir: + file(GLOB_RECURSE more + # Make the paths relative to the calling dir to prevent parent paths + # from interfering with the exclusion regex logic below + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + # We need to re-run configuration if any files are added/removed + CONFIGURE_DEPENDS + "${pattern}" + ) + # Warn if this pattern didn't match anything. It is probably a mistake + # in the caller's argument list. + if(NOT more) + message(WARNING "Globbing pattern “${pattern}” did not match any files") + endif() + list(APPEND headers_to_verify ${more}) + endforeach() + + # Exclude anything that matches any exclusion regex + foreach(pattern IN LISTS arg_EXCLUDE_REGEX) + list(FILTER headers_to_verify EXCLUDE REGEX "${pattern}") + endforeach() + + # Drop duplicates since globs may grab a file more than once + list(REMOVE_DUPLICATES headers_to_verify) + list(SORT headers_to_verify) + foreach(file IN LISTS headers_to_verify) + message(DEBUG "Verify header file: ${file}") + endforeach() + + # We create two targets: One for C and one for C++ + # C target + set(c_target ${tag}-verify-headers-c) + message(DEBUG "Defining header verification target “${c_target}” (C)") + # Create object libraries. They will only have one empty compiled source file. + # The source file language will tell CMake how to verify the associated header files. + add_library(${c_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.c") + # Define the file set + target_sources(${c_target} PUBLIC FILE_SET HEADERS) + # Conditionally do the same thing for C++ + if(CMAKE_CXX_COMPILER) + # C++ is available. define it + set(cxx_target ${tag}-verify-headers-cxx) + message(DEBUG "Defining header verification targets “${cxx_target}” (C++)") + add_library(${cxx_target} OBJECT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/empty.cpp") + target_sources(${cxx_target} PUBLIC FILE_SET HEADERS) + else() + message(AUTHOR_WARNING "No C++ compiler is available, so the header-check C++ targets won't be defined") + unset(cxx_target) + endif() + # Populate the properties and file sets. + set_target_properties(${c_target} ${cxx_target} PROPERTIES + # The main header file set: + HEADER_SET "${headers_to_verify}" + # Enable header verification: + VERIFY_INTERFACE_HEADER_SETS TRUE + # Add the usage requirements that propagate to the generated compilation rules: + INTERFACE_LINK_LIBRARIES "${arg_USE_LIBRARIES}" + ) +endfunction() + +#[[ +Variable set to TRUE if-and-only-if CMake supports header verification. +]] +set(MONGO_CAN_VERIFY_HEADERS FALSE) +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") + set(MONGO_CAN_VERIFY_HEADERS TRUE) +endif() + +# Try to enable C++, but don't require it. This will be used to conditionally +# define the C++ header-check tests +include(CheckLanguage) +check_language(CXX) +if(CMAKE_CXX_COMPILER) + enable_language(CXX) +endif() diff --git a/build/cmake/empty.c b/build/cmake/empty.c new file mode 100644 index 00000000000..deb1f24d152 --- /dev/null +++ b/build/cmake/empty.c @@ -0,0 +1,3 @@ +/* This is an empty placeholder file used for miscellaneous build system tasks + */ +#include diff --git a/build/cmake/empty.cpp b/build/cmake/empty.cpp new file mode 100644 index 00000000000..3c896c8708a --- /dev/null +++ b/build/cmake/empty.cpp @@ -0,0 +1,2 @@ +// This is an empty placeholder file used for miscellaneous build system tasks +#include diff --git a/docs/dev/earthly.rst b/docs/dev/earthly.rst index d216fc81c47..dc1144d5b93 100644 --- a/docs/dev/earthly.rst +++ b/docs/dev/earthly.rst @@ -284,6 +284,21 @@ enumerated using ``earthly ls`` or ``earthly doc`` in the root of the repository See: `SNYK_TOKEN` +.. program:: +verify-headers +.. earthly-target:: +verify-headers + + This runs `CMake's header verification`__ on the library sources, to ensure + that the public API headers can be ``#include``\ 'd directly in a C++ + compiler. + + __ https://cmake.org/cmake/help/latest/prop_tgt/VERIFY_INTERFACE_HEADER_SETS.html + + This target does not produce any output artifacts. This only checks that our + public API headers are valid. This checks against a variety of environments + to test that we are including the necessary standard library headers in our + public API headers. + + .. _earthly.secrets: Setting Earthly Secrets diff --git a/src/common/src/common-string-private.h b/src/common/src/common-string-private.h index 83d4eecf87f..24496d9db0d 100644 --- a/src/common/src/common-string-private.h +++ b/src/common/src/common-string-private.h @@ -485,7 +485,7 @@ mcommon_string_append_overflow (mcommon_string_append_t *append) */ bool mcommon_string_append_selected_chars (mcommon_string_append_t *append, - const char *template, + const char *template_, const char *selector, size_t selector_len); diff --git a/src/common/src/common-thread-private.h b/src/common/src/common-thread-private.h index 9372d087ae3..9d876ff22c1 100644 --- a/src/common/src/common-thread-private.h +++ b/src/common/src/common-thread-private.h @@ -23,11 +23,9 @@ #ifndef MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H #define MONGO_C_DRIVER_COMMON_THREAD_PRIVATE_H -#define BSON_INSIDE -#include -#include -#include -#undef BSON_INSIDE +#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/common/src/mlib/config.h b/src/common/src/mlib/config.h index 2b7ed9045d2..6a1e45275bf 100644 --- a/src/common/src/mlib/config.h +++ b/src/common/src/mlib/config.h @@ -256,24 +256,24 @@ #define mlib_diagnostic_push() \ MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic push);) \ MLIB_IF_MSVC (mlib_pragma (warning (push));) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_diagnostic_pop() \ MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic pop);) \ MLIB_IF_MSVC (mlib_pragma (warning (pop));) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_gcc_warning_disable(Warning) \ MLIB_IF_GCC (mlib_pragma (GCC diagnostic ignored Warning);) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_gnu_warning_disable(Warning) \ MLIB_IF_GNU_LIKE (mlib_pragma (GCC diagnostic ignored Warning);) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") #define mlib_msvc_warning(...) \ MLIB_IF_MSVC (mlib_pragma (warning (__VA_ARGS__));) \ - mlib_static_assert (true, "") + mlib_static_assert (1, "") /** * @brief Attribute macro that forces the function to be inlined at all call sites. @@ -366,6 +366,6 @@ */ #define mlib_disable_unused_parameter_warnings() \ MLIB_IF_GNU_LIKE (mlib_gnu_warning_disable ("-Wunused-parameter");) \ - MLIB_IF_MSVC (mlib_msvc_warning (disable : 4100);) mlib_static_assert (true, "") + MLIB_IF_MSVC (mlib_msvc_warning (disable : 4100);) mlib_static_assert (1, "") #endif // MLIB_CONFIG_H_INCLUDED diff --git a/src/libbson/.gitignore b/src/libbson/.gitignore index d1b5f611844..14a7bfd860f 100644 --- a/src/libbson/.gitignore +++ b/src/libbson/.gitignore @@ -7,7 +7,6 @@ ChangeLog CMakeFiles CMakeCache.txt compile -config.* !config.yml configure depcomp diff --git a/src/libbson/CMakeLists.txt b/src/libbson/CMakeLists.txt index 47713afbd0d..6ba064d5dbf 100644 --- a/src/libbson/CMakeLists.txt +++ b/src/libbson/CMakeLists.txt @@ -116,13 +116,13 @@ else () endif () configure_file ( - "${PROJECT_SOURCE_DIR}/src/bson/bson-config.h.in" - "${PROJECT_BINARY_DIR}/src/bson/bson-config.h" + "${PROJECT_SOURCE_DIR}/src/bson/config.h.in" + "${PROJECT_BINARY_DIR}/src/bson/config.h" ) configure_file ( - "${PROJECT_SOURCE_DIR}/src/bson/bson-version.h.in" - "${PROJECT_BINARY_DIR}/src/bson/bson-version.h" + "${PROJECT_SOURCE_DIR}/src/bson/version.h.in" + "${PROJECT_BINARY_DIR}/src/bson/version.h" ) # 8888888b. .d888 d8b d8b 888 d8b @@ -173,6 +173,25 @@ if(ENABLE_STATIC) # User wants static libs to use PIC code. set_property(TARGET bson_static PROPERTY POSITION_INDEPENDENT_CODE TRUE) endif() + + if(MONGO_CAN_VERIFY_HEADERS AND ENABLE_TESTS) + mongo_verify_headers( + bson + USE_LIBRARIES bson::static + HEADERS + # Grab all headers + "src/*.h" + EXCLUDE_REGEX + # No -private headers + "-private\\.h" + # Ignore all headers that start with "bson-", as they have not + # been sanitized for direct inclusion. + "bson/bson-.*\\.h" + # Don't check jsonsl.h or bcon.h either + "jsonsl\\.h" + "bcon\\.h" + ) + endif() endif() if(ENABLE_SHARED) diff --git a/src/libbson/libbson.rc.in b/src/libbson/libbson.rc.in index 9015243d19d..e8f08a6d10a 100644 --- a/src/libbson/libbson.rc.in +++ b/src/libbson/libbson.rc.in @@ -2,7 +2,7 @@ // Refer: https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource #include // Defines VS_VERSION_INFO -#include // Defines BSON_MAJOR_VERSION and other version macros. +#include // Defines BSON_MAJOR_VERSION and other version macros. #define BSON_OUTPUT_BASENAME "@BSON_OUTPUT_BASENAME@" diff --git a/src/libbson/src/bson/.gitignore b/src/libbson/src/bson/.gitignore index d151f69a799..12228a2e100 100644 --- a/src/libbson/src/bson/.gitignore +++ b/src/libbson/src/bson/.gitignore @@ -1,4 +1,2 @@ -bson-config.h bson-stdint.h -bson-version.h .dirstamp diff --git a/src/libbson/src/bson/bcon.c b/src/libbson/src/bson/bcon.c index 707557ce852..d9a6d12412f 100644 --- a/src/libbson/src/bson/bcon.c +++ b/src/libbson/src/bson/bcon.c @@ -21,7 +21,7 @@ #include -#include +#include #include diff --git a/src/libbson/src/bson/bcon.h b/src/libbson/src/bson/bcon.h index c5d6b3546cd..af3a26341f0 100644 --- a/src/libbson/src/bson/bcon.h +++ b/src/libbson/src/bson/bcon.h @@ -24,8 +24,8 @@ #define BCON_H_ // Include specific headers first, because bson.h tries to include this header itself: -#include #include +#include // For other APIs, not properly grouped, but needed: #include diff --git a/src/libbson/src/bson/bson-clock.c b/src/libbson/src/bson/bson-clock.c index ee62d51e847..cb8234e9ce6 100644 --- a/src/libbson/src/bson/bson-clock.c +++ b/src/libbson/src/bson/bson-clock.c @@ -14,8 +14,8 @@ * limitations under the License. */ -#include -#include +#include +#include #if defined(BSON_HAVE_CLOCK_GETTIME) diff --git a/src/libbson/src/bson/bson-clock.h b/src/libbson/src/bson/bson-clock.h index 4179152772a..2e6194c1357 100644 --- a/src/libbson/src/bson/bson-clock.h +++ b/src/libbson/src/bson/bson-clock.h @@ -21,9 +21,9 @@ #define BSON_CLOCK_H -#include -#include #include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-context.c b/src/libbson/src/bson/bson-context.c index fcc508c40cb..d7b7e9ef326 100644 --- a/src/libbson/src/bson/bson-context.c +++ b/src/libbson/src/bson/bson-context.c @@ -21,8 +21,9 @@ #include #include -#include -#include +#include +#include +#include #include diff --git a/src/libbson/src/bson/bson-context.h b/src/libbson/src/bson/bson-context.h index 882d080bbcb..1f4ea85876c 100644 --- a/src/libbson/src/bson/bson-context.h +++ b/src/libbson/src/bson/bson-context.h @@ -21,8 +21,8 @@ #define BSON_CONTEXT_H -#include #include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-decimal128.c b/src/libbson/src/bson/bson-decimal128.c index 1fe7b9f2b8d..4f8a2cea642 100644 --- a/src/libbson/src/bson/bson-decimal128.c +++ b/src/libbson/src/bson/bson-decimal128.c @@ -18,8 +18,8 @@ #include -#include #include +#include #include #include diff --git a/src/libbson/src/bson/bson-decimal128.h b/src/libbson/src/bson/bson-decimal128.h index 1ffdbea5aec..031d87d1bbb 100644 --- a/src/libbson/src/bson/bson-decimal128.h +++ b/src/libbson/src/bson/bson-decimal128.h @@ -21,9 +21,9 @@ #define BSON_DECIMAL128_H -#include -#include #include +#include +#include #include diff --git a/src/libbson/src/bson/bson-endian.h b/src/libbson/src/bson/bson-endian.h index 37b2d6670cd..bbc9d5006e2 100644 --- a/src/libbson/src/bson/bson-endian.h +++ b/src/libbson/src/bson/bson-endian.h @@ -20,9 +20,9 @@ #ifndef BSON_ENDIAN_H #define BSON_ENDIAN_H -#include -#include -#include +#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-error-private.h b/src/libbson/src/bson/bson-error-private.h index 0d858840122..92c11f54302 100644 --- a/src/libbson/src/bson/bson-error-private.h +++ b/src/libbson/src/bson/bson-error-private.h @@ -19,8 +19,8 @@ #ifndef BSON_ERROR_PRIVATE_H #define BSON_ERROR_PRIVATE_H -#include -#include +#include +#include #define BSON_ERROR_CATEGORY 1 diff --git a/src/libbson/src/bson/bson-error.h b/src/libbson/src/bson/bson-error.h deleted file mode 100644 index 154800f2a18..00000000000 --- a/src/libbson/src/bson/bson-error.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2009-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - - -#ifndef BSON_ERROR_H -#define BSON_ERROR_H - - -#include -#include -#include - - -BSON_BEGIN_DECLS - - -#define BSON_ERROR_JSON 1 -#define BSON_ERROR_READER 2 -#define BSON_ERROR_INVALID 3 -#define BSON_ERROR_VECTOR 4 - - -BSON_EXPORT (void) -bson_set_error (bson_error_t *error, uint32_t domain, uint32_t code, const char *format, ...) BSON_GNUC_PRINTF (4, 5); -BSON_EXPORT (char *) -bson_strerror_r (int err_code, char *buf, size_t buflen); - - -BSON_END_DECLS - - -#endif /* BSON_ERROR_H */ diff --git a/src/libbson/src/bson/bson-iso8601-private.h b/src/libbson/src/bson/bson-iso8601-private.h index 72871e61064..ce0479953b9 100644 --- a/src/libbson/src/bson/bson-iso8601-private.h +++ b/src/libbson/src/bson/bson-iso8601-private.h @@ -23,8 +23,8 @@ #include -#include -#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-iso8601.c b/src/libbson/src/bson/bson-iso8601.c index 2712aaa6d01..eb8e446ba2b 100644 --- a/src/libbson/src/bson/bson-iso8601.c +++ b/src/libbson/src/bson/bson-iso8601.c @@ -18,10 +18,10 @@ #include #include -#include -#include #include -#include +#include +#include +#include static bool diff --git a/src/libbson/src/bson/bson-iter.c b/src/libbson/src/bson/bson-iter.c index 713d3b7e881..6f44caa2d1c 100644 --- a/src/libbson/src/bson/bson-iter.c +++ b/src/libbson/src/bson/bson-iter.c @@ -17,9 +17,9 @@ #include -#include #include #include +#include #include #include diff --git a/src/libbson/src/bson/bson-iter.h b/src/libbson/src/bson/bson-iter.h index 1231cb8e4a1..3c578edac59 100644 --- a/src/libbson/src/bson/bson-iter.h +++ b/src/libbson/src/bson/bson-iter.h @@ -22,9 +22,9 @@ #include -#include #include #include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-json.c b/src/libbson/src/bson/bson-json.c index 1d8bfdac29d..bdccc7655ed 100644 --- a/src/libbson/src/bson/bson-json.c +++ b/src/libbson/src/bson/bson-json.c @@ -22,8 +22,8 @@ #include #include -#include #include +#include #include #include diff --git a/src/libbson/src/bson/bson-keys.h b/src/libbson/src/bson/bson-keys.h index 08f14e8ba38..0e8f0b8cbd6 100644 --- a/src/libbson/src/bson/bson-keys.h +++ b/src/libbson/src/bson/bson-keys.h @@ -21,8 +21,8 @@ #define BSON_KEYS_H -#include #include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-oid.c b/src/libbson/src/bson/bson-oid.c index 18b090d8564..85328d32fcd 100644 --- a/src/libbson/src/bson/bson-oid.c +++ b/src/libbson/src/bson/bson-oid.c @@ -17,9 +17,10 @@ #include #include -#include -#include +#include +#include +#include #include #include diff --git a/src/libbson/src/bson/bson-oid.h b/src/libbson/src/bson/bson-oid.h index fb1ffea6915..cd216c00312 100644 --- a/src/libbson/src/bson/bson-oid.h +++ b/src/libbson/src/bson/bson-oid.h @@ -23,8 +23,8 @@ #include #include -#include #include +#include #include diff --git a/src/libbson/src/bson/bson-private.h b/src/libbson/src/bson/bson-private.h index ac3d4f1ad94..07e4802a7f4 100644 --- a/src/libbson/src/bson/bson-private.h +++ b/src/libbson/src/bson/bson-private.h @@ -21,9 +21,9 @@ #define BSON_PRIVATE_H -#include -#include #include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-reader.c b/src/libbson/src/bson/bson-reader.c index 6f06173c921..723131583a3 100644 --- a/src/libbson/src/bson/bson-reader.c +++ b/src/libbson/src/bson/bson-reader.c @@ -25,8 +25,8 @@ #include #include #endif -#include #include +#include #include #include diff --git a/src/libbson/src/bson/bson-reader.h b/src/libbson/src/bson/bson-reader.h index ab2c0a6931a..56a139fb8c5 100644 --- a/src/libbson/src/bson/bson-reader.h +++ b/src/libbson/src/bson/bson-reader.h @@ -21,9 +21,9 @@ #define BSON_READER_H -#include #include #include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-string.c b/src/libbson/src/bson/bson-string.c index 0281676118f..ecb74ea9d74 100644 --- a/src/libbson/src/bson/bson-string.c +++ b/src/libbson/src/bson/bson-string.c @@ -18,10 +18,10 @@ #include #include -#include -#include -#include #include +#include +#include +#include #include diff --git a/src/libbson/src/bson/bson-string.h b/src/libbson/src/bson/bson-string.h index 3b11638b76d..0a45c6059da 100644 --- a/src/libbson/src/bson/bson-string.h +++ b/src/libbson/src/bson/bson-string.h @@ -21,8 +21,8 @@ #define BSON_STRING_H -#include #include +#include #include diff --git a/src/libbson/src/bson/bson-timegm-private.h b/src/libbson/src/bson/bson-timegm-private.h index 0490d012a83..21d2784ecfa 100644 --- a/src/libbson/src/bson/bson-timegm-private.h +++ b/src/libbson/src/bson/bson-timegm-private.h @@ -21,8 +21,8 @@ #define BSON_TIMEGM_PRIVATE_H -#include -#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-timegm.c b/src/libbson/src/bson/bson-timegm.c index e1eab4e2a7e..b2d3390bacd 100644 --- a/src/libbson/src/bson/bson-timegm.c +++ b/src/libbson/src/bson/bson-timegm.c @@ -12,8 +12,8 @@ #include -#include -#include +#include +#include #include #include /* for INT64_MAX and INT64_MIN */ diff --git a/src/libbson/src/bson/bson-types.h b/src/libbson/src/bson/bson-types.h index 8be7ed5e8cf..6e6fa3840f5 100644 --- a/src/libbson/src/bson/bson-types.h +++ b/src/libbson/src/bson/bson-types.h @@ -20,11 +20,12 @@ #ifndef BSON_TYPES_H #define BSON_TYPES_H - -#include -#include #include -#include +#include +#include +#include +#include +#include #include @@ -104,45 +105,6 @@ typedef struct _bson_context_t bson_context_t; typedef struct _bson_json_opts_t bson_json_opts_t; -/** - * bson_t: - * - * This structure manages a buffer whose contents are a properly formatted - * BSON document. You may perform various transforms on the BSON documents. - * Additionally, it can be iterated over using bson_iter_t. - * - * See bson_iter_init() for iterating the contents of a bson_t. - * - * When building a bson_t structure using the various append functions, - * memory allocations may occur. That is performed using power of two - * allocations and realloc(). - * - * See http://bsonspec.org for the BSON document spec. - * - * This structure is meant to fit in two sequential 64-byte cachelines. - */ -BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) typedef struct _bson_t { - uint32_t flags; /* Internal flags for the bson_t. */ - uint32_t len; /* Length of BSON data. */ - uint8_t padding[120]; /* Padding for stack allocation. */ -} bson_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); - -/** - * BSON_INITIALIZER: - * - * This macro can be used to initialize a #bson_t structure on the stack - * without calling bson_init(). - * - * |[ - * bson_t b = BSON_INITIALIZER; - * ]| - */ -#define BSON_INITIALIZER {3, 5, {5}} - - -BSON_STATIC_ASSERT2 (bson_t, sizeof (bson_t) == 128); - - /** * bson_oid_t: * @@ -470,59 +432,6 @@ typedef struct { void *padding[7]; } bson_visitor_t; -#define BSON_ERROR_BUFFER_SIZE 503 - -BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) // Aligned for backwards-compatibility. -typedef struct _bson_error_t { - uint32_t domain; - uint32_t code; - char message[BSON_ERROR_BUFFER_SIZE]; - uint8_t reserved; // For internal use only! -} bson_error_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); - - -BSON_STATIC_ASSERT2 (error_t, sizeof (bson_error_t) == 512); - -/** - * @brief Reset the content of a bson_error_t to indicate no error. - * - * @param error Pointer to an error to be overwritten. If null, this function - * has no effect. - * - * This is static-inline because it is trivially optimizable as a (conditional) - * `memset`. - */ -static inline void -bson_error_clear (bson_error_t *error) -{ - if (!error) { - return; - } - // Statically initialized to a zero struct: - static bson_error_t zero_error; - // Replace the caller's value: - *error = zero_error; -} - -/** - * @brief Given a `bson_error_t` pointer l-value, ensure that it is non-null, and clear any - * error value that it might hold. - * - * @param ErrorPointer An l-value expression of type `bson_error_t*`. - * - * If the passed pointer is null, then it will be updated to point to an anonymous - * `bson_error_t` object that lives in the caller's scope. - * - * @note This macro is not valid in C++ because it relies on C99 compound literal semantics - */ -#define bson_error_reset(ErrorPointer) bson_error_reset (&(ErrorPointer), &(bson_error_t) {0}) -static inline void (bson_error_reset) (bson_error_t **error, bson_error_t *localptr) -{ - if (*error == NULL) { - *error = localptr; - } - bson_error_clear (*error); -} /** * bson_next_power_of_two: diff --git a/src/libbson/src/bson/bson-utf8.c b/src/libbson/src/bson/bson-utf8.c index 621af62b95b..48326158e38 100644 --- a/src/libbson/src/bson/bson-utf8.c +++ b/src/libbson/src/bson/bson-utf8.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include diff --git a/src/libbson/src/bson/bson-utf8.h b/src/libbson/src/bson/bson-utf8.h index fc58d3c5a72..27790b8efea 100644 --- a/src/libbson/src/bson/bson-utf8.h +++ b/src/libbson/src/bson/bson-utf8.h @@ -21,8 +21,8 @@ #define BSON_UTF8_H -#include #include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-value.c b/src/libbson/src/bson/bson-value.c index 12e7a5a6729..bc06f0d247c 100644 --- a/src/libbson/src/bson/bson-value.c +++ b/src/libbson/src/bson/bson-value.c @@ -19,8 +19,8 @@ #include -#include #include +#include #include diff --git a/src/libbson/src/bson/bson-value.h b/src/libbson/src/bson/bson-value.h index afb11a5006b..f42138a40d9 100644 --- a/src/libbson/src/bson/bson-value.h +++ b/src/libbson/src/bson/bson-value.h @@ -21,8 +21,8 @@ #define BSON_VALUE_H -#include #include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-vector-private.h b/src/libbson/src/bson/bson-vector-private.h index 7b570042628..4a62bd99f63 100644 --- a/src/libbson/src/bson/bson-vector-private.h +++ b/src/libbson/src/bson/bson-vector-private.h @@ -19,8 +19,8 @@ #ifndef BSON_VECTOR_PRIVATE_H #define BSON_VECTOR_PRIVATE_H -#include -#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-vector.h b/src/libbson/src/bson/bson-vector.h index fe38e183498..554cc1f88fd 100644 --- a/src/libbson/src/bson/bson-vector.h +++ b/src/libbson/src/bson/bson-vector.h @@ -19,9 +19,9 @@ #ifndef BSON_VECTOR_H #define BSON_VECTOR_H -#include #include -#include +#include +#include BSON_BEGIN_DECLS diff --git a/src/libbson/src/bson/bson-version-functions.c b/src/libbson/src/bson/bson-version-functions.c index 17f8d87d90f..a4896f6369d 100644 --- a/src/libbson/src/bson/bson-version-functions.c +++ b/src/libbson/src/bson/bson-version-functions.c @@ -14,11 +14,9 @@ * limitations under the License. */ - #include -#include - +#include /** * bson_get_major_version: @@ -31,7 +29,6 @@ bson_get_major_version (void) return BSON_MAJOR_VERSION; } - /** * bson_get_minor_version: * diff --git a/src/libbson/src/bson/bson-writer.h b/src/libbson/src/bson/bson-writer.h index 6308ee279ba..830e6ae3980 100644 --- a/src/libbson/src/bson/bson-writer.h +++ b/src/libbson/src/bson/bson-writer.h @@ -16,17 +16,16 @@ #include - #ifndef BSON_WRITER_H #define BSON_WRITER_H +#include +#include -#include - +#include BSON_BEGIN_DECLS - /** * bson_writer_t: * @@ -40,7 +39,6 @@ BSON_BEGIN_DECLS */ typedef struct _bson_writer_t bson_writer_t; - BSON_EXPORT (bson_writer_t *) bson_writer_new (uint8_t **buf, size_t *buflen, size_t offset, bson_realloc_func realloc_func, void *realloc_func_ctx); BSON_EXPORT (void) @@ -54,8 +52,6 @@ bson_writer_end (bson_writer_t *writer); BSON_EXPORT (void) bson_writer_rollback (bson_writer_t *writer); - BSON_END_DECLS - #endif /* BSON_WRITER_H */ diff --git a/src/libbson/src/bson/bson.c b/src/libbson/src/bson/bson.c index 3112e6cf8ab..7d3cffbdce7 100644 --- a/src/libbson/src/bson/bson.c +++ b/src/libbson/src/bson/bson.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/src/libbson/src/bson/bson.h b/src/libbson/src/bson/bson.h index d2a942c3439..287bda929c0 100644 --- a/src/libbson/src/bson/bson.h +++ b/src/libbson/src/bson/bson.h @@ -22,16 +22,11 @@ #include #include -#include -#include #include #include -#include #include #include #include -#include -#include #include #include #include @@ -40,8 +35,12 @@ #include #include #include -#include #include +#include +#include +#include +#include +#include #include #include @@ -160,8 +159,7 @@ BSON_BEGIN_DECLS * * Returns: A newly allocated bson_t that should be freed with bson_destroy(). */ -BSON_EXPORT (bson_t *) -bson_new (void); +BSON_EXPORT (bson_t *) bson_new (void); BSON_EXPORT (bson_t *) diff --git a/src/libbson/src/bson/bson_t.h b/src/libbson/src/bson/bson_t.h new file mode 100644 index 00000000000..cf68a87a589 --- /dev/null +++ b/src/libbson/src/bson/bson_t.h @@ -0,0 +1,61 @@ +/* + * Copyright 2009-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BSON_BSON_T_H_INCLUDED +#define BSON_BSON_T_H_INCLUDED + +#include + +#include + +/** + * bson_t: + * + * This structure manages a buffer whose contents are a properly formatted + * BSON document. You may perform various transforms on the BSON documents. + * Additionally, it can be iterated over using bson_iter_t. + * + * See bson_iter_init() for iterating the contents of a bson_t. + * + * When building a bson_t structure using the various append functions, + * memory allocations may occur. That is performed using power of two + * allocations and realloc(). + * + * See http://bsonspec.org for the BSON document spec. + * + * This structure is meant to fit in two sequential 64-byte cachelines. + */ +BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) typedef struct _bson_t { + uint32_t flags; /* Internal flags for the bson_t. */ + uint32_t len; /* Length of BSON data. */ + uint8_t padding[120]; /* Padding for stack allocation. */ +} bson_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); + +/** + * BSON_INITIALIZER: + * + * This macro can be used to initialize a #bson_t structure on the stack + * without calling bson_init(). + * + * |[ + * bson_t b = BSON_INITIALIZER; + * ]| + */ +#define BSON_INITIALIZER {3, 5, {5}} + +BSON_STATIC_ASSERT2 (bson_t, sizeof (bson_t) == 128); + +#endif // BSON_BSON_T_H_INCLUDED diff --git a/src/libbson/src/bson/bson-compat.h b/src/libbson/src/bson/compat.h similarity index 97% rename from src/libbson/src/bson/bson-compat.h rename to src/libbson/src/bson/compat.h index df1413fd031..999e44ee2ec 100644 --- a/src/libbson/src/bson/bson-compat.h +++ b/src/libbson/src/bson/compat.h @@ -14,9 +14,6 @@ * limitations under the License. */ -#include - - #ifndef BSON_COMPAT_H #define BSON_COMPAT_H @@ -31,8 +28,8 @@ #endif #endif -#include -#include +#include +#include #ifdef BSON_OS_WIN32 @@ -64,7 +61,7 @@ #endif -#include +#include #include #include diff --git a/src/libbson/src/bson/bson-config.h.in b/src/libbson/src/bson/config.h.in similarity index 95% rename from src/libbson/src/bson/bson-config.h.in rename to src/libbson/src/bson/config.h.in index e9011549bf2..306d35c11e7 100644 --- a/src/libbson/src/bson/bson-config.h.in +++ b/src/libbson/src/bson/config.h.in @@ -14,10 +14,6 @@ * limitations under the License. */ -#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION) -#error "Only can be included directly." -#endif - #ifndef BSON_CONFIG_H #define BSON_CONFIG_H diff --git a/src/libbson/src/bson/bson-error.c b/src/libbson/src/bson/error.c similarity index 98% rename from src/libbson/src/bson/bson-error.c rename to src/libbson/src/bson/error.c index 4c6e746bbd0..0d3a5109027 100644 --- a/src/libbson/src/bson/bson-error.c +++ b/src/libbson/src/bson/error.c @@ -18,10 +18,10 @@ #include #include -#include -#include -#include #include +#include +#include +#include #include #include diff --git a/src/libbson/src/bson/error.h b/src/libbson/src/bson/error.h new file mode 100644 index 00000000000..a57f691d685 --- /dev/null +++ b/src/libbson/src/bson/error.h @@ -0,0 +1,94 @@ +/* + * Copyright 2009-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BSON_ERROR_T_INCLUDED +#define BSON_ERROR_T_INCLUDED + +#include + +#include + +BSON_BEGIN_DECLS + +#define BSON_ERROR_BUFFER_SIZE 503 + +BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR) // Aligned for backwards-compatibility. +typedef struct _bson_error_t { + uint32_t domain; + uint32_t code; + char message[BSON_ERROR_BUFFER_SIZE]; + uint8_t reserved; // For internal use only! +} bson_error_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR); + + +BSON_STATIC_ASSERT2 (error_t, sizeof (bson_error_t) == 512); + +#define BSON_ERROR_JSON 1 +#define BSON_ERROR_READER 2 +#define BSON_ERROR_INVALID 3 +#define BSON_ERROR_VECTOR 4 + +BSON_EXPORT (void) +bson_set_error (bson_error_t *error, uint32_t domain, uint32_t code, const char *format, ...) BSON_GNUC_PRINTF (4, 5); + +BSON_EXPORT (char *) +bson_strerror_r (int err_code, char *buf, size_t buflen); + +/** + * @brief Reset the content of a bson_error_t to indicate no error. + * + * @param error Pointer to an error to be overwritten. If null, this function + * has no effect. + * + * This is static-inline because it is trivially optimizable as a (conditional) + * `memset`. + */ +static inline void +bson_error_clear (bson_error_t *error) +{ + if (!error) { + return; + } + // Statically initialized to a zero struct: + static bson_error_t zero_error; + // Replace the caller's value: + *error = zero_error; +} + +/** + * @brief Given a `bson_error_t` pointer l-value, ensure that it is non-null, and clear any + * error value that it might hold. + * + * @param ErrorPointer An l-value expression of type `bson_error_t*`. + * + * If the passed pointer is null, then it will be updated to point to an anonymous + * `bson_error_t` object that lives in the caller's scope. + * + * @note This macro is not valid in C++ because it relies on C99 compound literal semantics + */ +#define bson_error_reset(ErrorPointer) bson_error_reset (&(ErrorPointer), &(bson_error_t) {0}) +static inline void (bson_error_reset) (bson_error_t **error, bson_error_t *localptr) +{ + if (*error == NULL) { + *error = localptr; + } + bson_error_clear (*error); +} + +BSON_END_DECLS + + +#endif // BSON_ERROR_T_INCLUDED diff --git a/src/libbson/src/bson/bson-macros.h b/src/libbson/src/bson/macros.h similarity index 99% rename from src/libbson/src/bson/bson-macros.h rename to src/libbson/src/bson/macros.h index 65b3ab36e57..d47d2307b2e 100644 --- a/src/libbson/src/bson/bson-macros.h +++ b/src/libbson/src/bson/macros.h @@ -14,12 +14,10 @@ * limitations under the License. */ -#include - - #ifndef BSON_MACROS_H #define BSON_MACROS_H +#include #include #include @@ -28,8 +26,6 @@ #include #endif -#include - #if BSON_OS == 1 #define BSON_OS_UNIX diff --git a/src/libbson/src/bson/bson-memory.c b/src/libbson/src/bson/memory.c similarity index 99% rename from src/libbson/src/bson/bson-memory.c rename to src/libbson/src/bson/memory.c index 2ef775f05f9..392eca98599 100644 --- a/src/libbson/src/bson/bson-memory.c +++ b/src/libbson/src/bson/memory.c @@ -15,11 +15,11 @@ */ -#include +#include #include -#include +#include #include diff --git a/src/libbson/src/bson/bson-memory.h b/src/libbson/src/bson/memory.h similarity index 92% rename from src/libbson/src/bson/bson-memory.h rename to src/libbson/src/bson/memory.h index 1d8e2e0d50a..b670fba5bf6 100644 --- a/src/libbson/src/bson/bson-memory.h +++ b/src/libbson/src/bson/memory.h @@ -14,15 +14,10 @@ * limitations under the License. */ -#include +#ifndef BSON_MEMORY_H_INCLUDED +#define BSON_MEMORY_H_INCLUDED - -#ifndef BSON_MEMORY_H -#define BSON_MEMORY_H - - -#include -#include +#include BSON_BEGIN_DECLS @@ -30,7 +25,6 @@ BSON_BEGIN_DECLS typedef void *(BSON_CALL *bson_realloc_func) (void *mem, size_t num_bytes, void *ctx); - typedef struct _bson_mem_vtable_t { void *(BSON_CALL *malloc) (size_t num_bytes); void *(BSON_CALL *calloc) (size_t n_members, size_t num_bytes); @@ -66,8 +60,6 @@ bson_zero_free (void *mem, size_t size); #define BSON_ALIGNED_ALLOC(T) ((T *) (bson_aligned_alloc (BSON_ALIGNOF (T), sizeof (T)))) #define BSON_ALIGNED_ALLOC0(T) ((T *) (bson_aligned_alloc0 (BSON_ALIGNOF (T), sizeof (T)))) - BSON_END_DECLS - -#endif /* BSON_MEMORY_H */ +#endif // BSON_MEMORY_H_INCLUDED diff --git a/src/libbson/src/bson/bson-version.h.in b/src/libbson/src/bson/version.h.in similarity index 95% rename from src/libbson/src/bson/bson-version.h.in rename to src/libbson/src/bson/version.h.in index 4d9fcac4893..8b4c248eaa3 100644 --- a/src/libbson/src/bson/bson-version.h.in +++ b/src/libbson/src/bson/version.h.in @@ -14,11 +14,6 @@ * limitations under the License. */ - -#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION) -#error "Only can be included directly." -#endif - // clang-format off #ifndef BSON_VERSION_H diff --git a/src/libbson/src/jsonsl/jsonsl.c b/src/libbson/src/jsonsl/jsonsl.c index e2bb6a08e4d..56bb4c36cc2 100644 --- a/src/libbson/src/jsonsl/jsonsl.c +++ b/src/libbson/src/jsonsl/jsonsl.c @@ -4,7 +4,7 @@ */ #include -#include +#include #include #include diff --git a/src/libbson/src/jsonsl/jsonsl.h b/src/libbson/src/jsonsl/jsonsl.h index 4c3fbbfd62e..e6058674010 100644 --- a/src/libbson/src/jsonsl/jsonsl.h +++ b/src/libbson/src/jsonsl/jsonsl.h @@ -12,8 +12,8 @@ #ifndef JSONSL_H_ #define JSONSL_H_ -#include -#include +#include +#include #include diff --git a/src/libmongoc/CMakeLists.txt b/src/libmongoc/CMakeLists.txt index 56581bf1bfa..4fd14dbeea7 100644 --- a/src/libmongoc/CMakeLists.txt +++ b/src/libmongoc/CMakeLists.txt @@ -971,6 +971,23 @@ if (MONGOC_ENABLE_STATIC_BUILD) if(MONGOC_ENABLE_STATIC_INSTALL) mongo_generate_pkg_config (mongoc_static FILENAME mongoc${PROJECT_VERSION_MAJOR}-static.pc INSTALL) endif() + + if(MONGO_CAN_VERIFY_HEADERS AND ENABLE_TESTS) + mongo_verify_headers( + mongoc + USE_LIBRARIES mongoc::static + HEADERS "src/*.h" + EXCLUDE_REGEX + # Ignore all headers that start with "mongoc-", as they have not + # been sanitized for direct inclusion. + "mongoc/mongoc-.*\\.h" + # Other private headers that aren't for public consumption: + "/mcd-" + "service-gcp\\.h" + "uthash\\.h" + "utlist\\.h" + ) + endif() endif () diff --git a/src/libmongoc/tests/test-mongoc-retryability-helpers.c b/src/libmongoc/tests/test-mongoc-retryability-helpers.c index 8a17635d72f..c20bcdb0930 100644 --- a/src/libmongoc/tests/test-mongoc-retryability-helpers.c +++ b/src/libmongoc/tests/test-mongoc-retryability-helpers.c @@ -1,8 +1,8 @@ -#include +#include "./test-mongoc-retryability-helpers.h" #include -#include +#include #include #include diff --git a/tools/build.earth b/tools/build.earth index 7c60cb044a6..a72f2215aa7 100644 --- a/tools/build.earth +++ b/tools/build.earth @@ -83,6 +83,12 @@ ADD_CXX_COMPILER: # Old Alpine 3.16 bundles libstdc++ in g++, so we need to pull GCC along anyway LET cxx_pkg = clang g++ END + ELSE IF test -f /etc/redhat-release + IF test "$cxx_compiler" = g++ + LET cxx_pkg = "gcc-c++" + ELSE IF test "$cxx_compiler" = clang++ + LET cxx_pkg = clang gcc-c++ + END END IF test "$cxx_pkg" = "" RUN __fail "Unable to infer package name for --cxx_compiler “%s” on this platform (check spelling or pass a “--cxx_pkg” argument)" "$cxx_compiler"