diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 174be40..7ca3a58 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,21 +551,21 @@ 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: | 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,14 +597,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: | @@ -633,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,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: | @@ -689,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: | 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 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/CMakeLists.txt b/test/CMakeLists.txt index 7524ae6..5521551 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::config 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 29003c1..63c3b9e 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,7 @@ 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);