diff --git a/CMakeLists.txt b/CMakeLists.txt index b5b8d96dc3b..4fbc4845394 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,7 +161,6 @@ set(libtorrent_extensions_include_files set(libtorrent_aux_include_files alert_manager aligned_storage - aligned_union alloca allocating_handler array diff --git a/Makefile b/Makefile index c40361acbaf..1ab86a2e4b3 100644 --- a/Makefile +++ b/Makefile @@ -542,7 +542,6 @@ HEADERS = \ \ aux_/alert_manager.hpp \ aux_/aligned_storage.hpp \ - aux_/aligned_union.hpp \ aux_/alloca.hpp \ aux_/allocating_handler.hpp \ aux_/announce_entry.hpp \ diff --git a/include/libtorrent/aux_/aligned_union.hpp b/include/libtorrent/aux_/aligned_union.hpp deleted file mode 100644 index 54aa25931ca..00000000000 --- a/include/libtorrent/aux_/aligned_union.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - -Copyright (c) 2017, 2020, Arvid Norberg -Copyright (c) 2017, Alden Torres -All rights reserved. - -You may use, distribute and modify this code under the terms of the BSD license, -see LICENSE file. -*/ - -#ifndef TORRENT_ALIGNED_UNION_HPP_INCLUDE -#define TORRENT_ALIGNED_UNION_HPP_INCLUDE - -#include - -namespace libtorrent { namespace aux { - -#if defined __GNUC__ && __GNUC__ < 5 && !defined(_LIBCPP_VERSION) - -constexpr std::size_t max(std::size_t a) -{ return a; } - -constexpr std::size_t max(std::size_t a, std::size_t b) -{ return a > b ? a : b; } - -template -constexpr std::size_t max(std::size_t a, std::size_t b, Vals... v) -{ return max(a, max(b, v...)); } - -// this is for backwards compatibility with not-quite C++11 compilers -template -struct aligned_union -{ - struct type - { - alignas(max(alignof(Types)...)) - char buffer[max(Len, max(sizeof(Types)...))]; - }; -}; - -#else - -using std::aligned_union; - -#endif - -}} - -#endif diff --git a/include/libtorrent/aux_/socket_type.hpp b/include/libtorrent/aux_/socket_type.hpp index ecb04e065c6..874368e060b 100644 --- a/include/libtorrent/aux_/socket_type.hpp +++ b/include/libtorrent/aux_/socket_type.hpp @@ -13,7 +13,6 @@ see LICENSE file. #define TORRENT_SOCKET_TYPE #include "libtorrent/assert.hpp" -#include "libtorrent/aux_/aligned_union.hpp" #include "libtorrent/aux_/polymorphic_socket.hpp" #include "libtorrent/aux_/rtc_stream.hpp" #include "libtorrent/aux_/utp_stream.hpp" diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index 609dcb7526a..5f5c4bea652 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -30,7 +30,6 @@ see LICENSE file. #include // for print_endpoint #include // for aux::time_now -#include #include // for is_v6 #include @@ -113,17 +112,20 @@ void observer::set_id(node_id const& id) if (m_algorithm) m_algorithm->resort_result(this); } -using observer_storage = aux::aligned_union<1 - , find_data_observer - , announce_observer - , put_data_observer - , direct_observer - , get_item_observer - , get_peers_observer - , obfuscated_get_peers_observer - , sample_infohashes_observer - , null_observer - , traversal_observer>::type; +namespace { + + std::size_t const observer_storage_size = std::max( + {sizeof(find_data_observer) + , sizeof(announce_observer) + , sizeof(put_data_observer) + , sizeof(direct_observer) + , sizeof(get_item_observer) + , sizeof(get_peers_observer) + , sizeof(obfuscated_get_peers_observer) + , sizeof(sample_infohashes_observer) + , sizeof(null_observer) + , sizeof(traversal_observer)}); +} rpc_manager::rpc_manager(node_id const& our_id , aux::session_settings const& settings @@ -131,7 +133,7 @@ rpc_manager::rpc_manager(node_id const& our_id , aux::listen_socket_handle sock , socket_manager* sock_man , dht_logger* log) - : m_pool_allocator(sizeof(observer_storage), 10) + : m_pool_allocator(observer_storage_size, 10) , m_sock(std::move(sock)) , m_sock_man(sock_man) #ifndef TORRENT_DISABLE_LOGGING @@ -177,7 +179,7 @@ void rpc_manager::free_observer(void* ptr) #if TORRENT_USE_ASSERTS size_t rpc_manager::allocation_size() const { - return sizeof(observer_storage); + return observer_storage_size; } #endif #if TORRENT_USE_INVARIANT_CHECKS