Skip to content

Commit

Permalink
Support >= Boost 1.85
Browse files Browse the repository at this point in the history
  • Loading branch information
Keita Iwabuchi committed Oct 4, 2024
1 parent 2a00200 commit ace8bc2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW)
endif ()

if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27")
cmake_policy(SET CMP0144 NEW)
endif ()

if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30")
cmake_policy(SET CMP0167 NEW)
endif ()

# -------------------------------------------------------------------------------- #
# Metall general configuration
# -------------------------------------------------------------------------------- #
Expand Down Expand Up @@ -188,20 +196,17 @@ if (PRIVATEER_ROOT)
endif ()

# ---------- Boost ---------- #
# Disable the boost-cmake feature (BoostConfig.cmake or boost-config.cmake) since
# there is a tricky behavior/issue especially in Boost 1.70.0.
set(Boost_NO_BOOST_CMAKE ON)

find_package(Boost 1.80 QUIET)
find_package(Boost 1.80)
if (NOT Boost_FOUND)
message(STATUS "Boost is not found. Fetching Boost.")
FetchContent_Declare(Boost
URL https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2)
FetchContent_GetProperties(Boost)
if (NOT Boost_POPULATED)
FetchContent_Populate(Boost)
endif ()
set(BOOST_ROOT ${boost_SOURCE_DIR})
find_package(Boost 1.80)
find_package(Boost 1.80 REQUIRED)
endif ()

# -------------------------------------------------------------------------------- #
Expand Down
1 change: 0 additions & 1 deletion include/metall/kernel/manager_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <metall/object_attribute_accessor.hpp>
#include <metall/detail/utilities.hpp>
#include <metall/detail/in_place_interface.hpp>
#include <metall/detail/array_construct.hpp>
#include <metall/detail/file.hpp>
#include <metall/detail/file_clone.hpp>
#include <metall/detail/char_ptr_holder.hpp>
Expand Down
18 changes: 14 additions & 4 deletions include/metall/kernel/manager_kernel_impl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ T *manager_kernel<st, sst, cn, cs>::priv_generic_construct(
return nullptr;
}

// To prevent memory leak, deallocates the memory when array_construct throws
// exception
// To prevent memory leak, deallocates the memory when the array construction
// below throws exception
std::unique_ptr<void, std::function<void(void *)>> ptr_holder(
ptr, [this](void *const ptr) {
try {
Expand All @@ -752,12 +752,22 @@ T *manager_kernel<st, sst, cn, cs>::priv_generic_construct(
}
});

#if BOOST_VERSION >= 108500
table.construct_n(ptr, length);
#else
// Constructs each object in the allocated memory
// When one of objects of T in the array throws exception,
// this function calls T's destructor for successfully constructed objects and
// rethrows the exception
mdtl::array_construct(ptr, length, table);

std::size_t constructed = 0;
try {
table.construct_n(ptr, length, constructed);
} catch (...) {
std::size_t destroyed = 0;
table.destroy_n(ptr, constructed, destroyed);
throw;
}
#endif
ptr_holder.release(); // release the pointer since the construction succeeded

return static_cast<T *>(ptr);
Expand Down

0 comments on commit ace8bc2

Please sign in to comment.