From d6c75d9dd895922bf5dc6c38245ac8887d3e68fc Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 3 Nov 2021 08:46:25 -0700 Subject: [PATCH] Export of internal Abseil changes -- 9f6ef337f282272bc098330c9ccacd9d39155db4 by Abseil Team : Make DestroyElements an empty function if the value types are trivially deconstructible. PiperOrigin-RevId: 407345743 -- a639bbf6f22446d6ba3da9e2c205e26cda4bebc5 by Derek Mauro : Add ctest --output-on-failure to the CMake install test PiperOrigin-RevId: 407333671 -- 54d0577fa6ba1159c6a86410ae185c52f4afaff6 by Derek Mauro : Fix Android build of elf_mem_image.cc PiperOrigin-RevId: 407331032 GitOrigin-RevId: 9f6ef337f282272bc098330c9ccacd9d39155db4 Change-Id: I7e13f01cd804aec50f280ac25934c9ec48ef3c5f --- CMake/install_test_project/test.sh | 2 +- absl/container/inlined_vector.h | 12 ++--- absl/container/internal/inlined_vector.h | 65 ++++++++++++++++-------- absl/debugging/internal/elf_mem_image.cc | 2 +- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/CMake/install_test_project/test.sh b/CMake/install_test_project/test.sh index 5a78c92c..aecbb8fe 100755 --- a/CMake/install_test_project/test.sh +++ b/CMake/install_test_project/test.sh @@ -58,7 +58,7 @@ cmake "${absl_dir}" \ -DBUILD_TESTING=ON \ -DBUILD_SHARED_LIBS="${build_shared_libs}" make -j $(nproc) -ctest -j $(nproc) +ctest -j $(nproc) --output-on-failure make install ldconfig popd diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h index df9e0991..318c4679 100644 --- a/absl/container/inlined_vector.h +++ b/absl/container/inlined_vector.h @@ -233,8 +233,8 @@ class InlinedVector { // specified allocator is also `noexcept`. InlinedVector( InlinedVector&& other, - const allocator_type& allocator) - noexcept(absl::allocator_is_nothrow::value) + const allocator_type& + allocator) noexcept(absl::allocator_is_nothrow::value) : storage_(allocator) { if (IsMemcpyOk::value) { storage_.MemcpyFrom(other.storage_); @@ -486,8 +486,8 @@ class InlinedVector { InlinedVector& operator=(InlinedVector&& other) { if (ABSL_PREDICT_TRUE(this != std::addressof(other))) { if (IsMemcpyOk::value || other.storage_.GetIsAllocated()) { - inlined_vector_internal::DestroyElements(storage_.GetAllocator(), - data(), size()); + inlined_vector_internal::DestroyAdapter::DestroyElements( + storage_.GetAllocator(), data(), size()); storage_.DeallocateIfAllocated(); storage_.MemcpyFrom(other.storage_); @@ -721,8 +721,8 @@ class InlinedVector { // Destroys all elements in the inlined vector, setting the size to `0` and // deallocating any held memory. void clear() noexcept { - inlined_vector_internal::DestroyElements(storage_.GetAllocator(), data(), - size()); + inlined_vector_internal::DestroyAdapter::DestroyElements( + storage_.GetAllocator(), data(), size()); storage_.DeallocateIfAllocated(); storage_.SetInlinedSize(0); diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h index 1d7d6cda..26caa49a 100644 --- a/absl/container/internal/inlined_vector.h +++ b/absl/container/internal/inlined_vector.h @@ -94,16 +94,30 @@ struct TypeIdentity { template using NoTypeDeduction = typename TypeIdentity::type; +template >::value> +struct DestroyAdapter; + template -void DestroyElements(NoTypeDeduction& allocator, Pointer destroy_first, - SizeType destroy_size) { - if (destroy_first != nullptr) { +struct DestroyAdapter { + static void DestroyElements(A& allocator, Pointer destroy_first, + SizeType destroy_size) { for (SizeType i = destroy_size; i != 0;) { --i; AllocatorTraits::destroy(allocator, destroy_first + i); } } -} +}; + +template +struct DestroyAdapter { + static void DestroyElements(A& allocator, Pointer destroy_first, + SizeType destroy_size) { + static_cast(allocator); + static_cast(destroy_first); + static_cast(destroy_size); + } +}; template struct Allocation { @@ -133,7 +147,7 @@ void ConstructElements(NoTypeDeduction& allocator, for (SizeType i = 0; i < construct_size; ++i) { ABSL_INTERNAL_TRY { values.ConstructNext(allocator, construct_first + i); } ABSL_INTERNAL_CATCH_ANY { - DestroyElements(allocator, construct_first, i); + DestroyAdapter::DestroyElements(allocator, construct_first, i); ABSL_INTERNAL_RETHROW; } } @@ -253,7 +267,7 @@ class ConstructionTransaction { ~ConstructionTransaction() { if (DidConstruct()) { - DestroyElements(GetAllocator(), GetData(), GetSize()); + DestroyAdapter::DestroyElements(GetAllocator(), GetData(), GetSize()); } } @@ -469,7 +483,7 @@ class Storage { template void Storage::DestroyContents() { Pointer data = GetIsAllocated() ? GetAllocatedData() : GetInlinedData(); - DestroyElements(GetAllocator(), data, GetSize()); + DestroyAdapter::DestroyElements(GetAllocator(), data, GetSize()); DeallocateIfAllocated(); } @@ -566,7 +580,8 @@ auto Storage::Assign(ValueAdapter values, SizeType new_size) ConstructElements(GetAllocator(), construct_loop.data(), values, construct_loop.size()); - DestroyElements(GetAllocator(), destroy_loop.data(), destroy_loop.size()); + DestroyAdapter::DestroyElements(GetAllocator(), destroy_loop.data(), + destroy_loop.size()); if (allocation_tx.DidAllocate()) { DeallocateIfAllocated(); @@ -587,7 +602,7 @@ auto Storage::Resize(ValueAdapter values, SizeType new_size) A& alloc = GetAllocator(); if (new_size <= size) { // Destroy extra old elements. - DestroyElements(alloc, base + new_size, size - new_size); + DestroyAdapter::DestroyElements(alloc, base + new_size, size - new_size); } else if (new_size <= storage_view.capacity) { // Construct new elements in place. ConstructElements(alloc, base + size, values, new_size - size); @@ -611,7 +626,7 @@ auto Storage::Resize(ValueAdapter values, SizeType new_size) (MoveIterator(base))); ConstructElements(alloc, new_data, move_values, size); - DestroyElements(alloc, base, size); + DestroyAdapter::DestroyElements(alloc, base, size); std::move(construction_tx).Commit(); DeallocateIfAllocated(); SetAllocation(std::move(allocation_tx).Release()); @@ -650,7 +665,8 @@ auto Storage::Insert(ConstIterator pos, ValueAdapter values, ConstructElements(GetAllocator(), new_data + insert_end_index, move_values, storage_view.size - insert_index); - DestroyElements(GetAllocator(), storage_view.data, storage_view.size); + DestroyAdapter::DestroyElements(GetAllocator(), storage_view.data, + storage_view.size); std::move(construction_tx).Commit(); std::move(move_construction_tx).Commit(); @@ -753,7 +769,8 @@ auto Storage::EmplaceBackSlow(Args&&... args) -> Reference { ABSL_INTERNAL_RETHROW; } // Destroy elements in old backing store. - DestroyElements(GetAllocator(), storage_view.data, storage_view.size); + DestroyAdapter::DestroyElements(GetAllocator(), storage_view.data, + storage_view.size); DeallocateIfAllocated(); SetAllocation(std::move(allocation_tx).Release()); @@ -778,9 +795,9 @@ auto Storage::Erase(ConstIterator from, ConstIterator to) AssignElements(storage_view.data + erase_index, move_values, storage_view.size - erase_end_index); - DestroyElements(GetAllocator(), - storage_view.data + (storage_view.size - erase_size), - erase_size); + DestroyAdapter::DestroyElements( + GetAllocator(), storage_view.data + (storage_view.size - erase_size), + erase_size); SubtractSize(erase_size); return Iterator(storage_view.data + erase_index); @@ -804,7 +821,8 @@ auto Storage::Reserve(SizeType requested_capacity) -> void { ConstructElements(GetAllocator(), new_data, move_values, storage_view.size); - DestroyElements(GetAllocator(), storage_view.data, storage_view.size); + DestroyAdapter::DestroyElements(GetAllocator(), storage_view.data, + storage_view.size); DeallocateIfAllocated(); SetAllocation(std::move(allocation_tx).Release()); @@ -847,7 +865,8 @@ auto Storage::ShrinkToFit() -> void { ABSL_INTERNAL_RETHROW; } - DestroyElements(GetAllocator(), storage_view.data, storage_view.size); + DestroyAdapter::DestroyElements(GetAllocator(), storage_view.data, + storage_view.size); MallocAdapter::Deallocate(GetAllocator(), storage_view.data, storage_view.capacity); @@ -883,9 +902,10 @@ auto Storage::Swap(Storage* other_storage_ptr) -> void { move_values, large_ptr->GetSize() - small_ptr->GetSize()); - DestroyElements(large_ptr->GetAllocator(), - large_ptr->GetInlinedData() + small_ptr->GetSize(), - large_ptr->GetSize() - small_ptr->GetSize()); + DestroyAdapter::DestroyElements( + large_ptr->GetAllocator(), + large_ptr->GetInlinedData() + small_ptr->GetSize(), + large_ptr->GetSize() - small_ptr->GetSize()); } else { Storage* allocated_ptr = this; Storage* inlined_ptr = other_storage_ptr; @@ -909,8 +929,9 @@ auto Storage::Swap(Storage* other_storage_ptr) -> void { ABSL_INTERNAL_RETHROW; } - DestroyElements(inlined_ptr->GetAllocator(), - inlined_ptr->GetInlinedData(), inlined_ptr->GetSize()); + DestroyAdapter::DestroyElements(inlined_ptr->GetAllocator(), + inlined_ptr->GetInlinedData(), + inlined_ptr->GetSize()); inlined_ptr->SetAllocation( {allocated_storage_view.data, allocated_storage_view.capacity}); diff --git a/absl/debugging/internal/elf_mem_image.cc b/absl/debugging/internal/elf_mem_image.cc index d6832eaf..29a28181 100644 --- a/absl/debugging/internal/elf_mem_image.cc +++ b/absl/debugging/internal/elf_mem_image.cc @@ -222,7 +222,7 @@ void ElfMemImage::Init(const void *base) { reinterpret_cast(dynamic_program_header->p_vaddr + relocation); for (; dynamic_entry->d_tag != DT_NULL; ++dynamic_entry) { - const ElfW(Xword) value = dynamic_entry->d_un.d_val + relocation; + const auto value = dynamic_entry->d_un.d_val + relocation; switch (dynamic_entry->d_tag) { case DT_HASH: hash_ = reinterpret_cast(value);