-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace boost::container with cpp17::pmr
This removes the boost dependency to avoid having to make that work in our builds that are still using external packages. This change uses std::pmr when it is detected as available and usable. On platforms that don't have a working std::pmr (notably, macOS < 14), it uses the implementation from Pablo Halpern that is implemented with purely C++11 features. The major downfall to this approach is that if/when we start changing allocator strategies it'll require us to backport/reimplement those allocator strategies for macOS < 14. However, if we end up writing our own allocation strategies they'll work on either implementation seamlessly.
- Loading branch information
Showing
11 changed files
with
650 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# | ||
# DetectStdPmr.cmake | ||
# | ||
# | ||
# The MIT License | ||
# | ||
# Copyright (c) 2024 TileDB, Inc. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
# Detect whether polymorphic allocators are available on the system. | ||
|
||
# Special case for macOS when the MACOSX_DEPLOYMENT_TARGET is set to anything | ||
# less than 14. For some reason, std::pmr is still detectable, but the resulting | ||
# binary dies with a dyld missing symbol error. | ||
|
||
if (ENV{MACOSX_DEPLOYMENT_TARGET}) | ||
string(COMPARE LESS "$ENV{MACOSX_DEPLOYMENT_TARGET}" "14" MACOS_BAD_PMR_SUPPORT) | ||
if (MACOS_BAD_PMR_SUPPORT) | ||
set(TILEDB_USE_CPP17_PMR ON) | ||
message(STATUS "Using vendored cpp17::pmr for polymorphic allocators") | ||
return() | ||
endif() | ||
endif() | ||
|
||
# Otherwise, if we're not building a targeted macOS version, we just detect | ||
# whether std::pmr is available. | ||
# | ||
# However CMake makes this extra awesome because try_run appears to have | ||
# changed in a backwards compatible manner. We'll just version check for | ||
# selecting which to run. | ||
|
||
if (CMAKE_VERSION VERSION_LESS "3.25") | ||
try_run( | ||
TILEDB_CAN_RUN_STD_PMR | ||
TILEDB_CAN_COMPILE_STD_PMR | ||
"${CMAKE_CURRENT_BINARY_DIR}" | ||
"${CMAKE_SOURCE_DIR}/cmake/inputs/detect_std_pmr.cc" | ||
) | ||
else() | ||
try_run( | ||
TILEDB_CAN_RUN_STD_PMR | ||
TILEDB_CAN_COMPILE_STD_PMR | ||
SOURCES "${CMAKE_SOURCE_DIR}/cmake/inputs/detect_std_pmr.cc" | ||
) | ||
endif() | ||
|
||
if ("${TILEDB_CAN_COMPILE_STD_PMR}" AND "${TILEDB_CAN_RUN_STD_PMR}" EQUAL 0) | ||
message(STATUS "Using std::pmr for polymorphic allocators") | ||
else() | ||
set(TILEDB_USE_CPP17_PMR ON) | ||
message(STATUS "Using vendored cpp17::pmr for polymorphic allocators") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
#include <memory_resource> | ||
|
||
int | ||
main() { | ||
auto resource = std::pmr::get_default_resource(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Polymorphic Allocator Fallback Implementation | ||
=== | ||
|
||
This implementation of polymorphic_allocator was pulled from Pablo Halpern's | ||
C++11 implementation available here: | ||
|
||
https://github.com/phalpern/CppCon2017Code/tree/d26e7f4f6c593fe135c6b454aee93486790726b7 | ||
|
||
I have a personal forked copy here in case that repository ever dissappears: | ||
|
||
https://github.com/davisp/phalpern-CppCon2017Code/tree/d26e7f4f6c593fe135c6b454aee93486790726b7 | ||
|
||
The only changes from the original files in that repository are to reformat | ||
using TileDB coding style and adding a handful of `std::` namespace qualifiers | ||
to avoid symbol name clashes with internal TileDB symbols. |
24 changes: 24 additions & 0 deletions
24
tiledb/common/polymorphic_allocator/polymorphic_allocator.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* polymorphic_allocator.cpp -*-C++-*- | ||
* | ||
* Copyright 2012 Pablo Halpern. | ||
* Distributed under the Boost Software License, Version 1.0. | ||
* (See accompanying file LICENSE_1_0.txt or copy at | ||
* http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
#include "polymorphic_allocator.h" | ||
|
||
namespace cpp17 { | ||
|
||
atomic<pmr::memory_resource*> pmr::memory_resource::s_default_resource(nullptr); | ||
|
||
pmr::new_delete_resource* pmr::new_delete_resource_singleton() { | ||
// TBD: I think the standard makes this exception-safe, otherwise, we need | ||
// to use 'call_once()' in '<mutex>'. | ||
static new_delete_resource singleton; | ||
return &singleton; | ||
} | ||
|
||
} // namespace cpp17 | ||
|
||
// end polymorphic_allocator.cpp |
Oops, something went wrong.