From 00f4f11f14fd993d343292331f7bcd494c668dec Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 21 Sep 2022 18:09:42 +0300 Subject: [PATCH 1/7] Added a check for NULL pointer in fclose_deleter. The deleter can be called on a null pointer by shared_ptr. Also added tests with unique_ptr from Boost.Move and shared_ptr from Boost.SmartPtr. --- include/boost/core/fclose_deleter.hpp | 3 ++- test/Jamfile.v2 | 6 +++--- test/fclose_deleter_test.cpp | 29 +++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/boost/core/fclose_deleter.hpp b/include/boost/core/fclose_deleter.hpp index 7a0d34a..8f7a7fd 100644 --- a/include/boost/core/fclose_deleter.hpp +++ b/include/boost/core/fclose_deleter.hpp @@ -36,7 +36,8 @@ struct fclose_deleter */ void operator() (std::FILE* p) const BOOST_NOEXCEPT { - std::fclose(p); + if (BOOST_LIKELY(!!p)) + std::fclose(p); } }; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index a601332..a08c937 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -176,7 +176,7 @@ run demangle_test.cpp run demangled_name_test.cpp : : : always_show_run_output ; -run demangled_name_test.cpp : : : off always_show_run_output : demangled_name_test_no_rtti ; +run demangled_name_test.cpp : : : off always_show_run_output : demangled_name_test_no_rtti ; run scoped_enum.cpp ; compile-fail scoped_enum_compile_fail_conv_from_int.cpp @@ -186,8 +186,8 @@ compile-fail scoped_enum_compile_fail_conv_to_int.cpp run underlying_type.cpp ; -compile fclose_deleter_test.cpp - : windows:_CRT_SECURE_NO_WARNINGS windows:_CRT_SECURE_NO_DEPRECATE ; +run fclose_deleter_test.cpp + : : : windows:_CRT_SECURE_NO_WARNINGS windows:_CRT_SECURE_NO_DEPRECATE ; run pointer_traits_pointer_test.cpp ; run pointer_traits_element_type_test.cpp ; diff --git a/test/fclose_deleter_test.cpp b/test/fclose_deleter_test.cpp index dbe85a5..4363335 100644 --- a/test/fclose_deleter_test.cpp +++ b/test/fclose_deleter_test.cpp @@ -16,17 +16,29 @@ #include #include #include +#include +#include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include #endif +boost::movelib::unique_ptr< std::FILE, boost::fclose_deleter > make_boost_unique_file(const char* filename) +{ + return boost::movelib::unique_ptr< std::FILE, boost::fclose_deleter >(std::fopen(filename, "w")); +} + +boost::shared_ptr< std::FILE > make_boost_shared_file(const char* filename) +{ + return boost::shared_ptr< std::FILE >(std::fopen(filename, "w"), boost::fclose_deleter()); +} + #if !defined(BOOST_NO_CXX11_SMART_PTR) -std::unique_ptr< std::FILE, boost::fclose_deleter > make_unique_file(const char* filename) +std::unique_ptr< std::FILE, boost::fclose_deleter > make_std_unique_file(const char* filename) { return std::unique_ptr< std::FILE, boost::fclose_deleter >(std::fopen(filename, "w")); } -std::shared_ptr< std::FILE > make_shared_file(const char* filename) +std::shared_ptr< std::FILE > make_std_shared_file(const char* filename) { return std::shared_ptr< std::FILE >(std::fopen(filename, "w"), boost::fclose_deleter()); } @@ -43,9 +55,18 @@ int main() file = NULL; } + make_boost_unique_file(filename); + make_boost_shared_file(filename); + #if !defined(BOOST_NO_CXX11_SMART_PTR) - make_unique_file(filename); - make_shared_file(filename); + make_std_unique_file(filename); + make_std_shared_file(filename); +#endif + + // Test if the deleter can be called on a NULL pointer + boost::shared_ptr< std::FILE >(static_cast< std::FILE* >(NULL), boost::fclose_deleter()); +#if !defined(BOOST_NO_CXX11_SMART_PTR) + std::shared_ptr< std::FILE >(static_cast< std::FILE* >(NULL), boost::fclose_deleter()); #endif std::remove(filename); From 860eed6baf29f5ff75cdb98b456c6d273d93b96e Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 21 Sep 2022 19:19:38 +0300 Subject: [PATCH 2/7] Use depinst to install library dependencies in GHA config. --- .github/workflows/ci.yml | 46 ++++++++++++---------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 174be40..f3b58cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -383,6 +383,7 @@ jobs: BUILD_JOBS=$((nproc || sysctl -n hw.ncpu) 2> /dev/null) echo "BUILD_JOBS=$BUILD_JOBS" >> $GITHUB_ENV echo "CMAKE_BUILD_PARALLEL_LEVEL=$BUILD_JOBS" >> $GITHUB_ENV + DEPINST_ARGS=() GIT_VERSION="$(git --version | sed -e 's/git version //')" GIT_HAS_JOBS=1 if [ -f "/etc/debian_version" ] @@ -409,25 +410,16 @@ jobs: fi if [ "$GIT_HAS_JOBS" -ne 0 ] then - GIT_ARGS="--jobs $GIT_FETCH_JOBS" + DEPINST_ARGS+=("--git_args" "--jobs $GIT_FETCH_JOBS") fi cd .. git clone -b "$BOOST_BRANCH" --depth 1 "https://github.com/boostorg/boost.git" "boost-root" cd boost-root mkdir -p libs/$LIBRARY cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY - git submodule init tools/boost_install - git submodule init libs/headers - git submodule init tools/build - git submodule init tools/cmake - git submodule init libs/assert - git submodule init libs/config - git submodule init libs/static_assert - git submodule init libs/throw_exception - git submodule init libs/type_traits - git submodule init libs/utility - git submodule init libs/io - git submodule update $GIT_ARGS + git submodule update --init tools/boostdep + DEPINST_ARGS+=("$LIBRARY") + python tools/boostdep/depinst/depinst.py "${DEPINST_ARGS[@]}" ./bootstrap.sh ./b2 headers if [ -n "${{matrix.compiler}}" -o -n "$GCC_TOOLCHAIN_ROOT" ] @@ -519,18 +511,8 @@ jobs: git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root cd boost-root xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ - git submodule init tools/boost_install - git submodule init libs/headers - git submodule init tools/build - git submodule init tools/cmake - git submodule init libs/assert - git submodule init libs/config - git submodule init libs/static_assert - git submodule init libs/throw_exception - git submodule init libs/type_traits - git submodule init libs/utility - git submodule init libs/io - git submodule update --jobs %GIT_FETCH_JOBS% + git submodule update --init tools/boostdep + python tools/boostdep/depinst/depinst.py --git_args "--jobs %GIT_FETCH_JOBS%" %LIBRARY% cmd /c bootstrap b2 -d0 headers @@ -569,14 +551,14 @@ jobs: REF=${GITHUB_BASE_REF:-$GITHUB_REF} REF=${REF#refs/heads/} echo REF: $REF - BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true + BOOST_BRANCH=develop && [ "$REF" = "master" ] && BOOST_BRANCH=master || true echo BOOST_BRANCH: $BOOST_BRANCH cd .. git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root cd boost-root cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY git submodule update --init tools/boostdep - python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY + python tools/boostdep/depinst/depinst.py --git_args "--jobs $GIT_FETCH_JOBS" $LIBRARY - name: Use library with add_subdirectory run: | @@ -615,17 +597,17 @@ jobs: REF=${GITHUB_BASE_REF:-$GITHUB_REF} REF=${REF#refs/heads/} echo REF: $REF - BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true + BOOST_BRANCH=develop && [ "$REF" = "master" ] && BOOST_BRANCH=master || true echo BOOST_BRANCH: $BOOST_BRANCH cd .. git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root cd boost-root cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY git submodule update --init tools/boostdep - python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY + python tools/boostdep/depinst/depinst.py --git_args "--jobs $GIT_FETCH_JOBS" $LIBRARY - name: Configure - run: | + run: cd ../boost-root mkdir __build__ && cd __build__ cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local .. @@ -671,14 +653,14 @@ jobs: REF=${GITHUB_BASE_REF:-$GITHUB_REF} REF=${REF#refs/heads/} echo REF: $REF - BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true + BOOST_BRANCH=develop && [ "$REF" = "master" ] && BOOST_BRANCH=master || true echo BOOST_BRANCH: $BOOST_BRANCH cd .. git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root cd boost-root cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY git submodule update --init tools/boostdep - python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY + python tools/boostdep/depinst/depinst.py --git_args "--jobs $GIT_FETCH_JOBS" $LIBRARY - name: Configure run: | From a7f76af262f3af0699781d33ea5e19b2275545db Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 21 Sep 2022 20:00:03 +0300 Subject: [PATCH 3/7] Fixed unintentional change to CMake configure step in GHA config. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3b58cf..6169ea4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -607,7 +607,7 @@ jobs: python tools/boostdep/depinst/depinst.py --git_args "--jobs $GIT_FETCH_JOBS" $LIBRARY - name: Configure - run: + run: | cd ../boost-root mkdir __build__ && cd __build__ cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local .. From fd615f3bfeba7fabe175fde813d76ed33390bb5d Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 21 Sep 2022 19:54:35 +0300 Subject: [PATCH 4/7] Use depinst in AppVeyor CI as well. --- appveyor.yml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b894436..ae3ed65 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -60,24 +60,15 @@ environment: CXXSTD: 03,11,14,1z install: + - set GIT_FETCH_JOBS=8 - set BOOST_BRANCH=develop - if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master - cd .. - git clone -b %BOOST_BRANCH% https://github.com/boostorg/boost.git boost-root - cd boost-root - - git submodule init libs/headers - - git submodule init libs/assert - - git submodule init libs/config - - git submodule init libs/predef - - git submodule init libs/static_assert - - git submodule init libs/throw_exception - - git submodule init libs/type_traits - - git submodule init libs/utility - - git submodule init libs/io - - git submodule init tools/build - - git submodule init tools/boost_install - - git submodule update --jobs 4 + - git submodule update --init tools/boostdep - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\core\ + - python tools/boostdep/depinst/depinst.py --git_args "--jobs %GIT_FETCH_JOBS%" core - cmd /c bootstrap - b2 headers From 9cbf3ac420c0b54996197198e900be338dbc3d05 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 21 Sep 2022 21:05:27 +0300 Subject: [PATCH 5/7] Fixed fclose_deleter test failing to build with CMake. Jamfile parser created incorrect test for fclose_deleter_test, which resulted in a compiler error. Prevent the parser from creating the test target by reformatting the Jamfile and create a CMake target with proper dependencies. --- test/CMakeLists.txt | 4 ++++ test/Jamfile.v2 | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7524ae6..21350f5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,6 +27,10 @@ set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::utility) boost_test(TYPE run SOURCES sv_conversion_test2.cpp) +set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::move Boost::smart_ptr) + +boost_test(TYPE run SOURCES fclose_deleter_test.cpp) + endif() add_subdirectory(swap) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index a08c937..5f356da 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -186,8 +186,7 @@ compile-fail scoped_enum_compile_fail_conv_to_int.cpp run underlying_type.cpp ; -run fclose_deleter_test.cpp - : : : windows:_CRT_SECURE_NO_WARNINGS windows:_CRT_SECURE_NO_DEPRECATE ; +run fclose_deleter_test.cpp : : : windows:_CRT_SECURE_NO_WARNINGS windows:_CRT_SECURE_NO_DEPRECATE ; run pointer_traits_pointer_test.cpp ; run pointer_traits_element_type_test.cpp ; From 09f2aa123ac4ef2598ef167ab10ced5fa9ea7517 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 21 Sep 2022 21:14:13 +0300 Subject: [PATCH 6/7] Enabled parallel build in CMake CI jobs. --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6169ea4..7ca3a58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -565,7 +565,7 @@ jobs: cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test mkdir __build__ && cd __build__ cmake .. - cmake --build . + cmake --build . -- -j $BUILD_JOBS ctest --output-on-failure --no-tests=error posix-cmake-install: @@ -615,13 +615,13 @@ jobs: - name: Install run: | cd ../boost-root/__build__ - cmake --build . --target install + cmake --build . --target install -- -j $BUILD_JOBS - name: Use the installed library run: | cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__ cmake -DCMAKE_INSTALL_PREFIX=~/.local .. - cmake --build . + cmake --build . -- -j $BUILD_JOBS ctest --output-on-failure --no-tests=error posix-cmake-test: @@ -671,7 +671,7 @@ jobs: - name: Build tests run: | cd ../boost-root/__build__ - cmake --build . --target tests + cmake --build . --target tests -- -j $BUILD_JOBS - name: Run tests run: | From 1c79871f0f29261f92f281a35505f6ab8dcc281f Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Wed, 21 Sep 2022 21:20:40 +0300 Subject: [PATCH 7/7] Added dependency on Boost.Config to fclose_deleter_test CMake target. --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 21350f5..5521551 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,7 +27,7 @@ set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::utility) boost_test(TYPE run SOURCES sv_conversion_test2.cpp) -set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::move Boost::smart_ptr) +set(BOOST_TEST_LINK_LIBRARIES Boost::core Boost::config Boost::move Boost::smart_ptr) boost_test(TYPE run SOURCES fclose_deleter_test.cpp)