Commit d6c75d9d by Abseil Team Committed by vslashg

Export of internal Abseil changes

--
9f6ef337f282272bc098330c9ccacd9d39155db4 by Abseil Team <absl-team@google.com>:

Make DestroyElements an empty function if the value types are trivially deconstructible.

PiperOrigin-RevId: 407345743

--
a639bbf6f22446d6ba3da9e2c205e26cda4bebc5 by Derek Mauro <dmauro@google.com>:

Add ctest --output-on-failure to the CMake install test

PiperOrigin-RevId: 407333671

--
54d0577fa6ba1159c6a86410ae185c52f4afaff6 by Derek Mauro <dmauro@google.com>:

Fix Android build of elf_mem_image.cc

PiperOrigin-RevId: 407331032
GitOrigin-RevId: 9f6ef337f282272bc098330c9ccacd9d39155db4
Change-Id: I7e13f01cd804aec50f280ac25934c9ec48ef3c5f
parent 3b22e577
...@@ -58,7 +58,7 @@ cmake "${absl_dir}" \ ...@@ -58,7 +58,7 @@ cmake "${absl_dir}" \
-DBUILD_TESTING=ON \ -DBUILD_TESTING=ON \
-DBUILD_SHARED_LIBS="${build_shared_libs}" -DBUILD_SHARED_LIBS="${build_shared_libs}"
make -j $(nproc) make -j $(nproc)
ctest -j $(nproc) ctest -j $(nproc) --output-on-failure
make install make install
ldconfig ldconfig
popd popd
......
...@@ -233,8 +233,8 @@ class InlinedVector { ...@@ -233,8 +233,8 @@ class InlinedVector {
// specified allocator is also `noexcept`. // specified allocator is also `noexcept`.
InlinedVector( InlinedVector(
InlinedVector&& other, InlinedVector&& other,
const allocator_type& allocator) const allocator_type&
noexcept(absl::allocator_is_nothrow<allocator_type>::value) allocator) noexcept(absl::allocator_is_nothrow<allocator_type>::value)
: storage_(allocator) { : storage_(allocator) {
if (IsMemcpyOk<A>::value) { if (IsMemcpyOk<A>::value) {
storage_.MemcpyFrom(other.storage_); storage_.MemcpyFrom(other.storage_);
...@@ -486,8 +486,8 @@ class InlinedVector { ...@@ -486,8 +486,8 @@ class InlinedVector {
InlinedVector& operator=(InlinedVector&& other) { InlinedVector& operator=(InlinedVector&& other) {
if (ABSL_PREDICT_TRUE(this != std::addressof(other))) { if (ABSL_PREDICT_TRUE(this != std::addressof(other))) {
if (IsMemcpyOk<A>::value || other.storage_.GetIsAllocated()) { if (IsMemcpyOk<A>::value || other.storage_.GetIsAllocated()) {
inlined_vector_internal::DestroyElements<A>(storage_.GetAllocator(), inlined_vector_internal::DestroyAdapter<A>::DestroyElements(
data(), size()); storage_.GetAllocator(), data(), size());
storage_.DeallocateIfAllocated(); storage_.DeallocateIfAllocated();
storage_.MemcpyFrom(other.storage_); storage_.MemcpyFrom(other.storage_);
...@@ -721,8 +721,8 @@ class InlinedVector { ...@@ -721,8 +721,8 @@ class InlinedVector {
// Destroys all elements in the inlined vector, setting the size to `0` and // Destroys all elements in the inlined vector, setting the size to `0` and
// deallocating any held memory. // deallocating any held memory.
void clear() noexcept { void clear() noexcept {
inlined_vector_internal::DestroyElements<A>(storage_.GetAllocator(), data(), inlined_vector_internal::DestroyAdapter<A>::DestroyElements(
size()); storage_.GetAllocator(), data(), size());
storage_.DeallocateIfAllocated(); storage_.DeallocateIfAllocated();
storage_.SetInlinedSize(0); storage_.SetInlinedSize(0);
......
...@@ -94,16 +94,30 @@ struct TypeIdentity { ...@@ -94,16 +94,30 @@ struct TypeIdentity {
template <typename T> template <typename T>
using NoTypeDeduction = typename TypeIdentity<T>::type; using NoTypeDeduction = typename TypeIdentity<T>::type;
template <typename A, bool IsTriviallyDestructible =
absl::is_trivially_destructible<ValueType<A>>::value>
struct DestroyAdapter;
template <typename A> template <typename A>
void DestroyElements(NoTypeDeduction<A>& allocator, Pointer<A> destroy_first, struct DestroyAdapter<A, /* IsTriviallyDestructible */ false> {
SizeType<A> destroy_size) { static void DestroyElements(A& allocator, Pointer<A> destroy_first,
if (destroy_first != nullptr) { SizeType<A> destroy_size) {
for (SizeType<A> i = destroy_size; i != 0;) { for (SizeType<A> i = destroy_size; i != 0;) {
--i; --i;
AllocatorTraits<A>::destroy(allocator, destroy_first + i); AllocatorTraits<A>::destroy(allocator, destroy_first + i);
} }
} }
} };
template <typename A>
struct DestroyAdapter<A, /* IsTriviallyDestructible */ true> {
static void DestroyElements(A& allocator, Pointer<A> destroy_first,
SizeType<A> destroy_size) {
static_cast<void>(allocator);
static_cast<void>(destroy_first);
static_cast<void>(destroy_size);
}
};
template <typename A> template <typename A>
struct Allocation { struct Allocation {
...@@ -133,7 +147,7 @@ void ConstructElements(NoTypeDeduction<A>& allocator, ...@@ -133,7 +147,7 @@ void ConstructElements(NoTypeDeduction<A>& allocator,
for (SizeType<A> i = 0; i < construct_size; ++i) { for (SizeType<A> i = 0; i < construct_size; ++i) {
ABSL_INTERNAL_TRY { values.ConstructNext(allocator, construct_first + i); } ABSL_INTERNAL_TRY { values.ConstructNext(allocator, construct_first + i); }
ABSL_INTERNAL_CATCH_ANY { ABSL_INTERNAL_CATCH_ANY {
DestroyElements<A>(allocator, construct_first, i); DestroyAdapter<A>::DestroyElements(allocator, construct_first, i);
ABSL_INTERNAL_RETHROW; ABSL_INTERNAL_RETHROW;
} }
} }
...@@ -253,7 +267,7 @@ class ConstructionTransaction { ...@@ -253,7 +267,7 @@ class ConstructionTransaction {
~ConstructionTransaction() { ~ConstructionTransaction() {
if (DidConstruct()) { if (DidConstruct()) {
DestroyElements<A>(GetAllocator(), GetData(), GetSize()); DestroyAdapter<A>::DestroyElements(GetAllocator(), GetData(), GetSize());
} }
} }
...@@ -469,7 +483,7 @@ class Storage { ...@@ -469,7 +483,7 @@ class Storage {
template <typename T, size_t N, typename A> template <typename T, size_t N, typename A>
void Storage<T, N, A>::DestroyContents() { void Storage<T, N, A>::DestroyContents() {
Pointer<A> data = GetIsAllocated() ? GetAllocatedData() : GetInlinedData(); Pointer<A> data = GetIsAllocated() ? GetAllocatedData() : GetInlinedData();
DestroyElements<A>(GetAllocator(), data, GetSize()); DestroyAdapter<A>::DestroyElements(GetAllocator(), data, GetSize());
DeallocateIfAllocated(); DeallocateIfAllocated();
} }
...@@ -566,7 +580,8 @@ auto Storage<T, N, A>::Assign(ValueAdapter values, SizeType<A> new_size) ...@@ -566,7 +580,8 @@ auto Storage<T, N, A>::Assign(ValueAdapter values, SizeType<A> new_size)
ConstructElements<A>(GetAllocator(), construct_loop.data(), values, ConstructElements<A>(GetAllocator(), construct_loop.data(), values,
construct_loop.size()); construct_loop.size());
DestroyElements<A>(GetAllocator(), destroy_loop.data(), destroy_loop.size()); DestroyAdapter<A>::DestroyElements(GetAllocator(), destroy_loop.data(),
destroy_loop.size());
if (allocation_tx.DidAllocate()) { if (allocation_tx.DidAllocate()) {
DeallocateIfAllocated(); DeallocateIfAllocated();
...@@ -587,7 +602,7 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, SizeType<A> new_size) ...@@ -587,7 +602,7 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, SizeType<A> new_size)
A& alloc = GetAllocator(); A& alloc = GetAllocator();
if (new_size <= size) { if (new_size <= size) {
// Destroy extra old elements. // Destroy extra old elements.
DestroyElements<A>(alloc, base + new_size, size - new_size); DestroyAdapter<A>::DestroyElements(alloc, base + new_size, size - new_size);
} else if (new_size <= storage_view.capacity) { } else if (new_size <= storage_view.capacity) {
// Construct new elements in place. // Construct new elements in place.
ConstructElements<A>(alloc, base + size, values, new_size - size); ConstructElements<A>(alloc, base + size, values, new_size - size);
...@@ -611,7 +626,7 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, SizeType<A> new_size) ...@@ -611,7 +626,7 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, SizeType<A> new_size)
(MoveIterator<A>(base))); (MoveIterator<A>(base)));
ConstructElements<A>(alloc, new_data, move_values, size); ConstructElements<A>(alloc, new_data, move_values, size);
DestroyElements<A>(alloc, base, size); DestroyAdapter<A>::DestroyElements(alloc, base, size);
std::move(construction_tx).Commit(); std::move(construction_tx).Commit();
DeallocateIfAllocated(); DeallocateIfAllocated();
SetAllocation(std::move(allocation_tx).Release()); SetAllocation(std::move(allocation_tx).Release());
...@@ -650,7 +665,8 @@ auto Storage<T, N, A>::Insert(ConstIterator<A> pos, ValueAdapter values, ...@@ -650,7 +665,8 @@ auto Storage<T, N, A>::Insert(ConstIterator<A> pos, ValueAdapter values,
ConstructElements<A>(GetAllocator(), new_data + insert_end_index, ConstructElements<A>(GetAllocator(), new_data + insert_end_index,
move_values, storage_view.size - insert_index); move_values, storage_view.size - insert_index);
DestroyElements<A>(GetAllocator(), storage_view.data, storage_view.size); DestroyAdapter<A>::DestroyElements(GetAllocator(), storage_view.data,
storage_view.size);
std::move(construction_tx).Commit(); std::move(construction_tx).Commit();
std::move(move_construction_tx).Commit(); std::move(move_construction_tx).Commit();
...@@ -753,7 +769,8 @@ auto Storage<T, N, A>::EmplaceBackSlow(Args&&... args) -> Reference<A> { ...@@ -753,7 +769,8 @@ auto Storage<T, N, A>::EmplaceBackSlow(Args&&... args) -> Reference<A> {
ABSL_INTERNAL_RETHROW; ABSL_INTERNAL_RETHROW;
} }
// Destroy elements in old backing store. // Destroy elements in old backing store.
DestroyElements<A>(GetAllocator(), storage_view.data, storage_view.size); DestroyAdapter<A>::DestroyElements(GetAllocator(), storage_view.data,
storage_view.size);
DeallocateIfAllocated(); DeallocateIfAllocated();
SetAllocation(std::move(allocation_tx).Release()); SetAllocation(std::move(allocation_tx).Release());
...@@ -778,9 +795,9 @@ auto Storage<T, N, A>::Erase(ConstIterator<A> from, ConstIterator<A> to) ...@@ -778,9 +795,9 @@ auto Storage<T, N, A>::Erase(ConstIterator<A> from, ConstIterator<A> to)
AssignElements<A>(storage_view.data + erase_index, move_values, AssignElements<A>(storage_view.data + erase_index, move_values,
storage_view.size - erase_end_index); storage_view.size - erase_end_index);
DestroyElements<A>(GetAllocator(), DestroyAdapter<A>::DestroyElements(
storage_view.data + (storage_view.size - erase_size), GetAllocator(), storage_view.data + (storage_view.size - erase_size),
erase_size); erase_size);
SubtractSize(erase_size); SubtractSize(erase_size);
return Iterator<A>(storage_view.data + erase_index); return Iterator<A>(storage_view.data + erase_index);
...@@ -804,7 +821,8 @@ auto Storage<T, N, A>::Reserve(SizeType<A> requested_capacity) -> void { ...@@ -804,7 +821,8 @@ auto Storage<T, N, A>::Reserve(SizeType<A> requested_capacity) -> void {
ConstructElements<A>(GetAllocator(), new_data, move_values, ConstructElements<A>(GetAllocator(), new_data, move_values,
storage_view.size); storage_view.size);
DestroyElements<A>(GetAllocator(), storage_view.data, storage_view.size); DestroyAdapter<A>::DestroyElements(GetAllocator(), storage_view.data,
storage_view.size);
DeallocateIfAllocated(); DeallocateIfAllocated();
SetAllocation(std::move(allocation_tx).Release()); SetAllocation(std::move(allocation_tx).Release());
...@@ -847,7 +865,8 @@ auto Storage<T, N, A>::ShrinkToFit() -> void { ...@@ -847,7 +865,8 @@ auto Storage<T, N, A>::ShrinkToFit() -> void {
ABSL_INTERNAL_RETHROW; ABSL_INTERNAL_RETHROW;
} }
DestroyElements<A>(GetAllocator(), storage_view.data, storage_view.size); DestroyAdapter<A>::DestroyElements(GetAllocator(), storage_view.data,
storage_view.size);
MallocAdapter<A>::Deallocate(GetAllocator(), storage_view.data, MallocAdapter<A>::Deallocate(GetAllocator(), storage_view.data,
storage_view.capacity); storage_view.capacity);
...@@ -883,9 +902,10 @@ auto Storage<T, N, A>::Swap(Storage* other_storage_ptr) -> void { ...@@ -883,9 +902,10 @@ auto Storage<T, N, A>::Swap(Storage* other_storage_ptr) -> void {
move_values, move_values,
large_ptr->GetSize() - small_ptr->GetSize()); large_ptr->GetSize() - small_ptr->GetSize());
DestroyElements<A>(large_ptr->GetAllocator(), DestroyAdapter<A>::DestroyElements(
large_ptr->GetInlinedData() + small_ptr->GetSize(), large_ptr->GetAllocator(),
large_ptr->GetSize() - small_ptr->GetSize()); large_ptr->GetInlinedData() + small_ptr->GetSize(),
large_ptr->GetSize() - small_ptr->GetSize());
} else { } else {
Storage* allocated_ptr = this; Storage* allocated_ptr = this;
Storage* inlined_ptr = other_storage_ptr; Storage* inlined_ptr = other_storage_ptr;
...@@ -909,8 +929,9 @@ auto Storage<T, N, A>::Swap(Storage* other_storage_ptr) -> void { ...@@ -909,8 +929,9 @@ auto Storage<T, N, A>::Swap(Storage* other_storage_ptr) -> void {
ABSL_INTERNAL_RETHROW; ABSL_INTERNAL_RETHROW;
} }
DestroyElements<A>(inlined_ptr->GetAllocator(), DestroyAdapter<A>::DestroyElements(inlined_ptr->GetAllocator(),
inlined_ptr->GetInlinedData(), inlined_ptr->GetSize()); inlined_ptr->GetInlinedData(),
inlined_ptr->GetSize());
inlined_ptr->SetAllocation( inlined_ptr->SetAllocation(
{allocated_storage_view.data, allocated_storage_view.capacity}); {allocated_storage_view.data, allocated_storage_view.capacity});
......
...@@ -222,7 +222,7 @@ void ElfMemImage::Init(const void *base) { ...@@ -222,7 +222,7 @@ void ElfMemImage::Init(const void *base) {
reinterpret_cast<ElfW(Dyn) *>(dynamic_program_header->p_vaddr + reinterpret_cast<ElfW(Dyn) *>(dynamic_program_header->p_vaddr +
relocation); relocation);
for (; dynamic_entry->d_tag != DT_NULL; ++dynamic_entry) { 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) { switch (dynamic_entry->d_tag) {
case DT_HASH: case DT_HASH:
hash_ = reinterpret_cast<ElfW(Word) *>(value); hash_ = reinterpret_cast<ElfW(Word) *>(value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment