From 96562f4c3bfd29e517d5107038953f92f6ced633 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Sat, 18 Mar 2023 12:58:17 +0100 Subject: [PATCH] hardened non-embedded group_access --- .../unordered/detail/foa/concurrent_table.hpp | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/include/boost/unordered/detail/foa/concurrent_table.hpp b/include/boost/unordered/detail/foa/concurrent_table.hpp index f11b2a91..b3c499f8 100644 --- a/include/boost/unordered/detail/foa/concurrent_table.hpp +++ b/include/boost/unordered/detail/foa/concurrent_table.hpp @@ -183,6 +183,19 @@ struct concurrent_group:Group,group_access }; }; +template +group_access* dummy_group_accesses() +{ + /* TODO: describe + */ + + static constexpr group_access::dummy_group_access_type + storage[Size]={typename group_access::dummy_group_access_type(),}; + + return reinterpret_cast( + const_cast(storage)); +} + template struct concurrent_table_arrays:table_arrays { @@ -192,29 +205,38 @@ struct concurrent_table_arrays:table_arrays static concurrent_table_arrays new_(Allocator& al,std::size_t n) { concurrent_table_arrays arrays={super::new_(al,n),nullptr}; - //if(arrays.elements){ + if(!arrays.elements){ + arrays.group_accesses=dummy_group_accesses(); + } + else{ using access_alloc= typename boost::allocator_rebind::type; using access_traits=boost::allocator_traits; using pointer=typename access_traits::pointer; using pointer_traits=boost::pointer_traits; - // TODO: protect with BOOST_TRY - auto aal=access_alloc(al); - arrays.group_accesses=boost::to_address( - access_traits::allocate(aal,arrays.groups_size_mask+1)); + BOOST_TRY{ + auto aal=access_alloc(al); + arrays.group_accesses=boost::to_address( + access_traits::allocate(aal,arrays.groups_size_mask+1)); - for(std::size_t n=0;n static void delete_(Allocator& al,concurrent_table_arrays& arrays)noexcept { - //if(arrays.elements){ + if(arrays.elements){ using access_alloc= typename boost::allocator_rebind::type; using access_traits=boost::allocator_traits; @@ -225,7 +247,7 @@ struct concurrent_table_arrays:table_arrays access_traits::deallocate( aal,pointer_traits::pointer_to(*arrays.group_accesses), arrays.groups_size_mask+1); - //} + } } group_access *group_accesses;