From 9a79278a9793574cad2773b3445a887f949bc705 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Mon, 29 Jan 2024 12:14:16 -0800 Subject: Fix a corner case in SpyHashState for exact boundaries. AbslHash allows for piecewise chunks to be streamed incrementally into hash states and requires them to hash identically to one giant stream. The exact size window for this is an internal details `PiecewiseChunkSize`. There was an off by one error in this code. Add tests and fix it. PiperOrigin-RevId: 602463183 Change-Id: I159bbb5e7e745f55b2fe6eaf0d2735bd0a08aca9 --- absl/strings/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) (limited to 'absl/strings/BUILD.bazel') diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index 8e8371b3..ed2ab04f 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -918,6 +918,7 @@ cc_test( "//absl/container:fixed_array", "//absl/functional:function_ref", "//absl/hash", + "//absl/hash:hash_testing", "//absl/log", "//absl/log:check", "//absl/random", -- cgit v1.2.3 From cbdbec098f6365c5afc1e3c088a6f48fb8835b59 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 30 Jan 2024 08:13:49 -0800 Subject: Use absl::NoDestructor for cordz global queue. Also updated the return value to reference to clarify non-nullability. PiperOrigin-RevId: 602730828 Change-Id: Ia36f7fde3cc87ac597ba4f194eebe9ebb90a1a09 --- absl/strings/BUILD.bazel | 2 +- absl/strings/CMakeLists.txt | 1 + absl/strings/internal/cordz_handle.cc | 48 +++++++++++++++++------------------ 3 files changed, 26 insertions(+), 25 deletions(-) (limited to 'absl/strings/BUILD.bazel') diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index ed2ab04f..1b6c7e4b 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -614,8 +614,8 @@ cc_library( "//absl:__subpackages__", ], deps = [ - "//absl/base", "//absl/base:config", + "//absl/base:no_destructor", "//absl/base:raw_logging_internal", "//absl/synchronization", ], diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt index ce9c5e46..9258e553 100644 --- a/absl/strings/CMakeLists.txt +++ b/absl/strings/CMakeLists.txt @@ -799,6 +799,7 @@ absl_cc_library( DEPS absl::base absl::config + absl::no_destructor absl::raw_logging_internal absl::synchronization ) diff --git a/absl/strings/internal/cordz_handle.cc b/absl/strings/internal/cordz_handle.cc index a7061dbe..53d5f529 100644 --- a/absl/strings/internal/cordz_handle.cc +++ b/absl/strings/internal/cordz_handle.cc @@ -16,6 +16,7 @@ #include #include "absl/base/internal/raw_logging.h" // For ABSL_RAW_CHECK +#include "absl/base/no_destructor.h" #include "absl/synchronization/mutex.h" namespace absl { @@ -43,33 +44,32 @@ struct Queue { } }; -static Queue* GlobalQueue() { - static Queue* global_queue = new Queue; - return global_queue; +static Queue& GlobalQueue() { + static absl::NoDestructor global_queue; + return *global_queue; } } // namespace CordzHandle::CordzHandle(bool is_snapshot) : is_snapshot_(is_snapshot) { - Queue* global_queue = GlobalQueue(); + Queue& global_queue = GlobalQueue(); if (is_snapshot) { - MutexLock lock(&global_queue->mutex); - CordzHandle* dq_tail = - global_queue->dq_tail.load(std::memory_order_acquire); + MutexLock lock(&global_queue.mutex); + CordzHandle* dq_tail = global_queue.dq_tail.load(std::memory_order_acquire); if (dq_tail != nullptr) { dq_prev_ = dq_tail; dq_tail->dq_next_ = this; } - global_queue->dq_tail.store(this, std::memory_order_release); + global_queue.dq_tail.store(this, std::memory_order_release); } } CordzHandle::~CordzHandle() { - Queue* global_queue = GlobalQueue(); + Queue& global_queue = GlobalQueue(); if (is_snapshot_) { std::vector to_delete; { - MutexLock lock(&global_queue->mutex); + MutexLock lock(&global_queue.mutex); CordzHandle* next = dq_next_; if (dq_prev_ == nullptr) { // We were head of the queue, delete every CordzHandle until we reach @@ -85,7 +85,7 @@ CordzHandle::~CordzHandle() { if (next) { next->dq_prev_ = dq_prev_; } else { - global_queue->dq_tail.store(dq_prev_, std::memory_order_release); + global_queue.dq_tail.store(dq_prev_, std::memory_order_release); } } for (CordzHandle* handle : to_delete) { @@ -95,20 +95,20 @@ CordzHandle::~CordzHandle() { } bool CordzHandle::SafeToDelete() const { - return is_snapshot_ || GlobalQueue()->IsEmpty(); + return is_snapshot_ || GlobalQueue().IsEmpty(); } void CordzHandle::Delete(CordzHandle* handle) { assert(handle); if (handle) { - Queue* const queue = GlobalQueue(); + Queue& queue = GlobalQueue(); if (!handle->SafeToDelete()) { - MutexLock lock(&queue->mutex); - CordzHandle* dq_tail = queue->dq_tail.load(std::memory_order_acquire); + MutexLock lock(&queue.mutex); + CordzHandle* dq_tail = queue.dq_tail.load(std::memory_order_acquire); if (dq_tail != nullptr) { handle->dq_prev_ = dq_tail; dq_tail->dq_next_ = handle; - queue->dq_tail.store(handle, std::memory_order_release); + queue.dq_tail.store(handle, std::memory_order_release); return; } } @@ -118,9 +118,9 @@ void CordzHandle::Delete(CordzHandle* handle) { std::vector CordzHandle::DiagnosticsGetDeleteQueue() { std::vector handles; - Queue* global_queue = GlobalQueue(); - MutexLock lock(&global_queue->mutex); - CordzHandle* dq_tail = global_queue->dq_tail.load(std::memory_order_acquire); + Queue& global_queue = GlobalQueue(); + MutexLock lock(&global_queue.mutex); + CordzHandle* dq_tail = global_queue.dq_tail.load(std::memory_order_acquire); for (const CordzHandle* p = dq_tail; p; p = p->dq_prev_) { handles.push_back(p); } @@ -133,9 +133,9 @@ bool CordzHandle::DiagnosticsHandleIsSafeToInspect( if (handle == nullptr) return true; if (handle->is_snapshot_) return false; bool snapshot_found = false; - Queue* global_queue = GlobalQueue(); - MutexLock lock(&global_queue->mutex); - for (const CordzHandle* p = global_queue->dq_tail; p; p = p->dq_prev_) { + Queue& global_queue = GlobalQueue(); + MutexLock lock(&global_queue.mutex); + for (const CordzHandle* p = global_queue.dq_tail; p; p = p->dq_prev_) { if (p == handle) return !snapshot_found; if (p == this) snapshot_found = true; } @@ -150,8 +150,8 @@ CordzHandle::DiagnosticsGetSafeToInspectDeletedHandles() { return handles; } - Queue* global_queue = GlobalQueue(); - MutexLock lock(&global_queue->mutex); + Queue& global_queue = GlobalQueue(); + MutexLock lock(&global_queue.mutex); for (const CordzHandle* p = dq_next_; p != nullptr; p = p->dq_next_) { if (!p->is_snapshot()) { handles.push_back(p); -- cgit v1.2.3 From 780bfc194d807dbd56363635ca40bf96743aa00b Mon Sep 17 00:00:00 2001 From: Shahriar Rouf Date: Wed, 31 Jan 2024 10:07:48 -0800 Subject: Replace `testonly = 1` with `testonly = True` in abseil BUILD files. https://bazel.build/build/style-guide#other-conventions PiperOrigin-RevId: 603084345 Change-Id: Ibd7c9573d820f88059d12c46ff82d7d322d002ae --- absl/base/BUILD.bazel | 18 +++++++++--------- absl/container/BUILD.bazel | 40 ++++++++++++++++++++-------------------- absl/crc/BUILD.bazel | 2 +- absl/flags/BUILD.bazel | 2 +- absl/hash/BUILD.bazel | 6 +++--- absl/log/internal/BUILD.bazel | 2 +- absl/numeric/BUILD.bazel | 2 +- absl/profiling/BUILD.bazel | 2 +- absl/random/BUILD.bazel | 6 +++--- absl/random/internal/BUILD.bazel | 8 ++++---- absl/strings/BUILD.bazel | 8 ++++---- absl/synchronization/BUILD.bazel | 10 +++++----- absl/time/BUILD.bazel | 2 +- 13 files changed, 54 insertions(+), 54 deletions(-) (limited to 'absl/strings/BUILD.bazel') diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 0eb735da..1eb8f098 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -294,7 +294,7 @@ cc_library( cc_library( name = "atomic_hook_test_helper", - testonly = 1, + testonly = True, srcs = ["internal/atomic_hook_test_helper.cc"], hdrs = ["internal/atomic_hook_test_helper.h"], copts = ABSL_DEFAULT_COPTS, @@ -380,7 +380,7 @@ cc_test( cc_library( name = "exception_testing", - testonly = 1, + testonly = True, hdrs = ["internal/exception_testing.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -404,7 +404,7 @@ cc_library( cc_library( name = "exception_safety_testing", - testonly = 1, + testonly = True, srcs = ["internal/exception_safety_testing.cc"], hdrs = ["internal/exception_safety_testing.h"], copts = ABSL_TEST_COPTS, @@ -470,7 +470,7 @@ cc_test( # AbslInternalSpinLockDelay and AbslInternalSpinLockWake. cc_library( name = "spinlock_test_common", - testonly = 1, + testonly = True, srcs = ["spinlock_test_common.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -507,7 +507,7 @@ cc_test( cc_library( name = "spinlock_benchmark_common", - testonly = 1, + testonly = True, srcs = ["internal/spinlock_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -527,7 +527,7 @@ cc_library( cc_binary( name = "spinlock_benchmark", - testonly = 1, + testonly = True, copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, tags = ["benchmark"], @@ -608,7 +608,7 @@ cc_test( cc_binary( name = "no_destructor_benchmark", - testonly = 1, + testonly = True, srcs = ["no_destructor_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -710,7 +710,7 @@ cc_test( cc_library( name = "scoped_set_env", - testonly = 1, + testonly = True, srcs = ["internal/scoped_set_env.cc"], hdrs = ["internal/scoped_set_env.h"], linkopts = ABSL_DEFAULT_LINKOPTS, @@ -784,7 +784,7 @@ cc_test( cc_binary( name = "strerror_benchmark", - testonly = 1, + testonly = True, srcs = ["internal/strerror_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel index bc5b2201..91633948 100644 --- a/absl/container/BUILD.bazel +++ b/absl/container/BUILD.bazel @@ -108,7 +108,7 @@ cc_test( cc_binary( name = "fixed_array_benchmark", - testonly = 1, + testonly = True, srcs = ["fixed_array_benchmark.cc"], copts = ABSL_TEST_COPTS + ["$(STACK_FRAME_UNLIMITED)"], linkopts = ABSL_DEFAULT_LINKOPTS, @@ -151,7 +151,7 @@ cc_library( cc_library( name = "test_allocator", - testonly = 1, + testonly = True, copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, textual_hdrs = ["internal/test_allocator.h"], @@ -181,7 +181,7 @@ cc_test( cc_binary( name = "inlined_vector_benchmark", - testonly = 1, + testonly = True, srcs = ["inlined_vector_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -210,7 +210,7 @@ cc_test( cc_library( name = "test_instance_tracker", - testonly = 1, + testonly = True, srcs = ["internal/test_instance_tracker.cc"], hdrs = ["internal/test_instance_tracker.h"], copts = ABSL_DEFAULT_COPTS, @@ -449,7 +449,7 @@ cc_test( cc_library( name = "hash_generator_testing", - testonly = 1, + testonly = True, srcs = ["internal/hash_generator_testing.cc"], hdrs = ["internal/hash_generator_testing.h"], copts = ABSL_TEST_COPTS, @@ -465,7 +465,7 @@ cc_library( cc_library( name = "hash_policy_testing", - testonly = 1, + testonly = True, hdrs = ["internal/hash_policy_testing.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -707,7 +707,7 @@ cc_test( cc_binary( name = "raw_hash_set_benchmark", - testonly = 1, + testonly = True, srcs = ["internal/raw_hash_set_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -724,7 +724,7 @@ cc_binary( cc_binary( name = "raw_hash_set_probe_benchmark", - testonly = 1, + testonly = True, srcs = ["internal/raw_hash_set_probe_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = select({ @@ -798,7 +798,7 @@ cc_test( cc_binary( name = "layout_benchmark", - testonly = 1, + testonly = True, srcs = ["internal/layout_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -814,7 +814,7 @@ cc_binary( cc_library( name = "tracked", - testonly = 1, + testonly = True, hdrs = ["internal/tracked.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -825,7 +825,7 @@ cc_library( cc_library( name = "unordered_map_constructor_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_map_constructor_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -838,7 +838,7 @@ cc_library( cc_library( name = "unordered_map_lookup_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_map_lookup_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -851,7 +851,7 @@ cc_library( cc_library( name = "unordered_map_modifiers_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_map_modifiers_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -864,7 +864,7 @@ cc_library( cc_library( name = "unordered_set_constructor_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_set_constructor_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -878,7 +878,7 @@ cc_library( cc_library( name = "unordered_set_members_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_set_members_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -890,7 +890,7 @@ cc_library( cc_library( name = "unordered_map_members_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_map_members_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -902,7 +902,7 @@ cc_library( cc_library( name = "unordered_set_lookup_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_set_lookup_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -915,7 +915,7 @@ cc_library( cc_library( name = "unordered_set_modifiers_test", - testonly = 1, + testonly = True, hdrs = ["internal/unordered_set_modifiers_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -1008,7 +1008,7 @@ cc_library( cc_library( name = "btree_test_common", - testonly = 1, + testonly = True, hdrs = ["btree_test.h"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -1059,7 +1059,7 @@ cc_test( cc_binary( name = "btree_benchmark", - testonly = 1, + testonly = True, srcs = [ "btree_benchmark.cc", ], diff --git a/absl/crc/BUILD.bazel b/absl/crc/BUILD.bazel index d923aec4..9dc81819 100644 --- a/absl/crc/BUILD.bazel +++ b/absl/crc/BUILD.bazel @@ -203,7 +203,7 @@ cc_test( cc_binary( name = "crc32c_benchmark", - testonly = 1, + testonly = True, srcs = ["crc32c_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel index d3b06227..657f8d2c 100644 --- a/absl/flags/BUILD.bazel +++ b/absl/flags/BUILD.bazel @@ -404,7 +404,7 @@ cc_test( cc_binary( name = "flag_benchmark", - testonly = 1, + testonly = True, srcs = [ "flag_benchmark.cc", ], diff --git a/absl/hash/BUILD.bazel b/absl/hash/BUILD.bazel index 1e8ad451..fe567e91 100644 --- a/absl/hash/BUILD.bazel +++ b/absl/hash/BUILD.bazel @@ -61,7 +61,7 @@ cc_library( cc_library( name = "hash_testing", - testonly = 1, + testonly = True, hdrs = ["hash_testing.h"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ @@ -128,7 +128,7 @@ cc_test( cc_binary( name = "hash_benchmark", - testonly = 1, + testonly = True, srcs = ["hash_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -148,7 +148,7 @@ cc_binary( cc_library( name = "spy_hash_state", - testonly = 1, + testonly = True, hdrs = ["internal/spy_hash_state.h"], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/log/internal/BUILD.bazel b/absl/log/internal/BUILD.bazel index 1be13499..2a8c1a47 100644 --- a/absl/log/internal/BUILD.bazel +++ b/absl/log/internal/BUILD.bazel @@ -400,7 +400,7 @@ cc_library( cc_binary( name = "vlog_config_benchmark", - testonly = 1, + testonly = True, srcs = ["vlog_config_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/numeric/BUILD.bazel b/absl/numeric/BUILD.bazel index db02b9c0..41c015db 100644 --- a/absl/numeric/BUILD.bazel +++ b/absl/numeric/BUILD.bazel @@ -46,7 +46,7 @@ cc_library( cc_binary( name = "bits_benchmark", - testonly = 1, + testonly = True, srcs = ["bits_benchmark.cc"], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/profiling/BUILD.bazel b/absl/profiling/BUILD.bazel index 86f205f9..abe127ec 100644 --- a/absl/profiling/BUILD.bazel +++ b/absl/profiling/BUILD.bazel @@ -126,7 +126,7 @@ cc_test( cc_binary( name = "periodic_sampler_benchmark", - testonly = 1, + testonly = True, srcs = ["internal/periodic_sampler_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/random/BUILD.bazel b/absl/random/BUILD.bazel index 80c4f055..bec979d6 100644 --- a/absl/random/BUILD.bazel +++ b/absl/random/BUILD.bazel @@ -132,7 +132,7 @@ cc_library( cc_library( name = "mock_distributions", - testonly = 1, + testonly = True, hdrs = ["mock_distributions.h"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ @@ -146,7 +146,7 @@ cc_library( cc_library( name = "mocking_bit_gen", - testonly = 1, + testonly = True, hdrs = [ "mocking_bit_gen.h", ], @@ -521,7 +521,7 @@ cc_test( # Benchmarks for various methods / test utilities cc_binary( name = "benchmarks", - testonly = 1, + testonly = True, srcs = [ "benchmarks.cc", ], diff --git a/absl/random/internal/BUILD.bazel b/absl/random/internal/BUILD.bazel index 71a742ee..69fb5f2b 100644 --- a/absl/random/internal/BUILD.bazel +++ b/absl/random/internal/BUILD.bazel @@ -137,7 +137,7 @@ cc_library( cc_library( name = "explicit_seed_seq", - testonly = 1, + testonly = True, hdrs = [ "explicit_seed_seq.h", ], @@ -151,7 +151,7 @@ cc_library( cc_library( name = "sequence_urbg", - testonly = 1, + testonly = True, hdrs = [ "sequence_urbg.h", ], @@ -375,7 +375,7 @@ cc_binary( cc_library( name = "distribution_test_util", - testonly = 1, + testonly = True, srcs = [ "chi_square.cc", "distribution_test_util.cc", @@ -534,7 +534,7 @@ cc_library( cc_library( name = "mock_overload_set", - testonly = 1, + testonly = True, hdrs = ["mock_overload_set.h"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index 1b6c7e4b..942c5324 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -829,7 +829,7 @@ cc_test( cc_library( name = "cord_test_helpers", - testonly = 1, + testonly = True, hdrs = [ "cord_test_helpers.h", ], @@ -845,7 +845,7 @@ cc_library( cc_library( name = "cord_rep_test_util", - testonly = 1, + testonly = True, hdrs = ["internal/cord_rep_test_util.h"], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -859,7 +859,7 @@ cc_library( cc_library( name = "cordz_test_helpers", - testonly = 1, + testonly = True, hdrs = ["cordz_test_helpers.h"], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -1449,7 +1449,7 @@ cc_test( cc_binary( name = "atod_manual_test", - testonly = 1, + testonly = True, srcs = ["atod_manual_test.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel index de06ebdd..f747d14a 100644 --- a/absl/synchronization/BUILD.bazel +++ b/absl/synchronization/BUILD.bazel @@ -183,7 +183,7 @@ cc_test( cc_binary( name = "blocking_counter_benchmark", - testonly = 1, + testonly = True, srcs = ["blocking_counter_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -230,7 +230,7 @@ cc_test( cc_library( name = "thread_pool", - testonly = 1, + testonly = True, hdrs = ["internal/thread_pool.h"], linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ @@ -281,7 +281,7 @@ cc_test( cc_library( name = "mutex_benchmark_common", - testonly = 1, + testonly = True, srcs = ["mutex_benchmark.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, @@ -300,7 +300,7 @@ cc_library( cc_binary( name = "mutex_benchmark", - testonly = 1, + testonly = True, copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ @@ -326,7 +326,7 @@ cc_test( cc_library( name = "per_thread_sem_test_common", - testonly = 1, + testonly = True, srcs = ["internal/per_thread_sem_test.cc"], copts = ABSL_TEST_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/time/BUILD.bazel b/absl/time/BUILD.bazel index e3fe705b..05f1f2f2 100644 --- a/absl/time/BUILD.bazel +++ b/absl/time/BUILD.bazel @@ -65,7 +65,7 @@ cc_library( cc_library( name = "test_util", - testonly = 1, + testonly = True, srcs = ["internal/test_util.cc"], hdrs = ["internal/test_util.h"], copts = ABSL_DEFAULT_COPTS, -- cgit v1.2.3 From 55d28d4b3b82f9a47b3fa9b811b675a032820621 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Feb 2024 20:11:58 -0800 Subject: Automated Code Change PiperOrigin-RevId: 611321915 Change-Id: Ia63e3e2f66981d9e4f5b97f6df276b8195459ba2 --- absl/strings/BUILD.bazel | 2 ++ 1 file changed, 2 insertions(+) (limited to 'absl/strings/BUILD.bazel') diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index 942c5324..8b307832 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -899,6 +899,7 @@ cc_test( cc_test( name = "cord_test", size = "medium", + timeout = "long", srcs = ["cord_test.cc"], copts = ABSL_TEST_COPTS, visibility = ["//visibility:private"], @@ -1377,6 +1378,7 @@ cc_test( cc_test( name = "str_format_convert_test", size = "medium", + timeout = "long", srcs = ["internal/str_format/convert_test.cc"], copts = ABSL_TEST_COPTS, visibility = ["//visibility:private"], -- cgit v1.2.3 From 5953a4885ae8dc4baa3f66292d6519e0ec254313 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 2 Apr 2024 09:03:50 -0700 Subject: Add internal traits to absl::string_view for lifetimebound detection This helps compilers that understand `ABSL_ATTRIBUTE_LIFETIME_BOUND` flag constructs such as `absl::StatusOr str = std::string(...)` as error-prone. PiperOrigin-RevId: 621196818 Change-Id: I78d4c66854cde9d06eaaec05869d956376109d9c --- absl/strings/BUILD.bazel | 1 + absl/strings/CMakeLists.txt | 1 + absl/strings/string_view.h | 1 + absl/strings/string_view_test.cc | 9 +++++++++ 4 files changed, 12 insertions(+) (limited to 'absl/strings/BUILD.bazel') diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index 8b307832..d93a78a9 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -359,6 +359,7 @@ cc_test( "//absl/base:config", "//absl/base:core_headers", "//absl/base:dynamic_annotations", + "//absl/meta:type_traits", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt index 9258e553..53e85188 100644 --- a/absl/strings/CMakeLists.txt +++ b/absl/strings/CMakeLists.txt @@ -274,6 +274,7 @@ absl_cc_test( absl::config absl::core_headers absl::dynamic_annotations + absl::type_traits GTest::gmock_main ) diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h index b393c6fc..b1fb7a10 100644 --- a/absl/strings/string_view.h +++ b/absl/strings/string_view.h @@ -173,6 +173,7 @@ class string_view { using reverse_iterator = const_reverse_iterator; using size_type = size_t; using difference_type = std::ptrdiff_t; + using absl_internal_is_view = std::true_type; static constexpr size_type npos = static_cast(-1); diff --git a/absl/strings/string_view_test.cc b/absl/strings/string_view_test.cc index 251f1842..e978fc3f 100644 --- a/absl/strings/string_view_test.cc +++ b/absl/strings/string_view_test.cc @@ -32,6 +32,7 @@ #include "gtest/gtest.h" #include "absl/base/config.h" +#include "absl/meta/type_traits.h" #if defined(ABSL_HAVE_STD_STRING_VIEW) || defined(__ANDROID__) // We don't control the death messaging when using std::string_view. @@ -46,6 +47,14 @@ namespace { +static_assert(!absl::type_traits_internal::IsOwner::value && + absl::type_traits_internal::IsView::value, + "string_view is a view, not an owner"); + +static_assert(absl::type_traits_internal::IsLifetimeBoundAssignment< + absl::string_view, std::string>::value, + "lifetimebound assignment not detected"); + // A minimal allocator that uses malloc(). template struct Mallocator { -- cgit v1.2.3 From b65852fa1e384d6e593b09dcf2134566e44dc02a Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Wed, 24 Apr 2024 11:55:19 -0700 Subject: Remove the hand-rolled CordLeaker and replace with absl::NoDestructor to test the after-exit behavior PiperOrigin-RevId: 627804039 Change-Id: Idc1c5fc14cea466dcc98f0d8746c02cafe887502 --- absl/strings/BUILD.bazel | 1 + absl/strings/CMakeLists.txt | 1 + absl/strings/cord_test.cc | 34 +++++++--------------------------- 3 files changed, 9 insertions(+), 27 deletions(-) (limited to 'absl/strings/BUILD.bazel') diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index d93a78a9..48793edd 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -917,6 +917,7 @@ cc_test( "//absl/base:config", "//absl/base:core_headers", "//absl/base:endian", + "//absl/base:no_destructor", "//absl/container:fixed_array", "//absl/functional:function_ref", "//absl/hash", diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt index 53e85188..99156cfe 100644 --- a/absl/strings/CMakeLists.txt +++ b/absl/strings/CMakeLists.txt @@ -1075,6 +1075,7 @@ absl_cc_test( absl::function_ref absl::hash absl::hash_testing + absl::no_destructor absl::log absl::optional absl::random_random diff --git a/absl/strings/cord_test.cc b/absl/strings/cord_test.cc index 658ad55b..ad96aafa 100644 --- a/absl/strings/cord_test.cc +++ b/absl/strings/cord_test.cc @@ -38,6 +38,7 @@ #include "absl/base/config.h" #include "absl/base/internal/endian.h" #include "absl/base/macros.h" +#include "absl/base/no_destructor.h" #include "absl/base/options.h" #include "absl/container/fixed_array.h" #include "absl/functional/function_ref.h" @@ -2796,34 +2797,15 @@ class AfterExitCordTester { absl::string_view expected_; }; -// Deliberately prevents the destructor for an absl::Cord from running. The cord -// is accessible via the cord member during the lifetime of the CordLeaker. -// After the CordLeaker is destroyed, pointers to the cord will remain valid -// until the CordLeaker's memory is deallocated. -struct CordLeaker { - union { - absl::Cord cord; - }; - - template - constexpr explicit CordLeaker(const Str& str) : cord(str) {} - - ~CordLeaker() { - // Don't do anything, including running cord's destructor. (cord's - // destructor won't run automatically because cord is hidden inside a - // union.) - } -}; - template -void TestConstinitConstructor(Str) { +void TestAfterExit(Str) { const auto expected = Str::value; // Defined before `cord` to be destroyed after it. static AfterExitCordTester exit_tester; // NOLINT - ABSL_CONST_INIT static CordLeaker cord_leaker(Str{}); // NOLINT + static absl::NoDestructor cord_leaker(Str{}); // cord_leaker is static, so this reference will remain valid through the end // of program execution. - static absl::Cord& cord = cord_leaker.cord; + static absl::Cord& cord = *cord_leaker; static bool init_exit_tester = exit_tester.Set(&cord, expected); (void)init_exit_tester; @@ -2875,11 +2857,9 @@ struct LongView { }; -TEST_P(CordTest, ConstinitConstructor) { - TestConstinitConstructor( - absl::strings_internal::MakeStringConstant(ShortView{})); - TestConstinitConstructor( - absl::strings_internal::MakeStringConstant(LongView{})); +TEST_P(CordTest, AfterExit) { + TestAfterExit(absl::strings_internal::MakeStringConstant(ShortView{})); + TestAfterExit(absl::strings_internal::MakeStringConstant(LongView{})); } namespace { -- cgit v1.2.3 From c98bd9c8840f9ded87cf1fd1238455468d325628 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 26 Jun 2024 08:13:11 -0700 Subject: Three-way comparison spaceship <=> operators for Cord. This is portable because cord already has `operator<` etc., which will be unaffected. This just allows C++ >= 20 users to explicitly call `operator<=>`. PiperOrigin-RevId: 646951415 Change-Id: I1432e224bd5dc09b99d56a1d27e95078463adf45 --- absl/strings/BUILD.bazel | 2 ++ absl/strings/CMakeLists.txt | 1 + absl/strings/cord.h | 33 +++++++++++++++++++++++++++++++++ absl/strings/cord_test.cc | 26 ++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) (limited to 'absl/strings/BUILD.bazel') diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index 48793edd..9bffae61 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -600,6 +600,7 @@ cc_library( "//absl/functional:function_ref", "//absl/meta:type_traits", "//absl/numeric:bits", + "//absl/types:compare", "//absl/types:optional", "//absl/types:span", ], @@ -925,6 +926,7 @@ cc_test( "//absl/log", "//absl/log:check", "//absl/random", + "//absl/types:compare", "//absl/types:optional", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt index 4696eb30..4a84dbbd 100644 --- a/absl/strings/CMakeLists.txt +++ b/absl/strings/CMakeLists.txt @@ -705,6 +705,7 @@ absl_cc_library( absl::compressed_tuple absl::config absl::container_memory + absl::compare absl::core_headers absl::crc_cord_state absl::endian diff --git a/absl/strings/cord.h b/absl/strings/cord.h index 0d8d7007..c68b6f10 100644 --- a/absl/strings/cord.h +++ b/absl/strings/cord.h @@ -96,6 +96,7 @@ #include "absl/strings/internal/resize_uninitialized.h" #include "absl/strings/internal/string_constant.h" #include "absl/strings/string_view.h" +#include "absl/types/compare.h" #include "absl/types/optional.h" namespace absl { @@ -849,6 +850,38 @@ class Cord { friend bool operator==(const Cord& lhs, const Cord& rhs); friend bool operator==(const Cord& lhs, absl::string_view rhs); +#ifdef __cpp_impl_three_way_comparison + + // Cords support comparison with other Cords and string_views via operator< + // and others; here we provide a wrapper for the C++20 three-way comparison + // <=> operator. + + static inline std::strong_ordering ConvertCompareResultToStrongOrdering( + int c) { + if (c == 0) { + return std::strong_ordering::equal; + } else if (c < 0) { + return std::strong_ordering::less; + } else { + return std::strong_ordering::greater; + } + } + + friend inline std::strong_ordering operator<=>(const Cord& x, const Cord& y) { + return ConvertCompareResultToStrongOrdering(x.Compare(y)); + } + + friend inline std::strong_ordering operator<=>(const Cord& lhs, + absl::string_view rhs) { + return ConvertCompareResultToStrongOrdering(lhs.Compare(rhs)); + } + + friend inline std::strong_ordering operator<=>(absl::string_view lhs, + const Cord& rhs) { + return ConvertCompareResultToStrongOrdering(-rhs.Compare(lhs)); + } +#endif + friend absl::Nullable GetCordzInfoForTesting( const Cord& cord); diff --git a/absl/strings/cord_test.cc b/absl/strings/cord_test.cc index c4a7288a..eaf6d719 100644 --- a/absl/strings/cord_test.cc +++ b/absl/strings/cord_test.cc @@ -60,6 +60,7 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" +#include "absl/types/compare.h" #include "absl/types/optional.h" // convenience local constants @@ -3283,6 +3284,31 @@ TEST(CrcCordTest, ChecksummedEmptyCordEstimateMemoryUsage) { EXPECT_NE(cord.EstimatedMemoryUsage(), 0); } +TEST(CordThreeWayComparisonTest, CompareCords) { +#ifndef __cpp_impl_three_way_comparison + GTEST_SKIP() << "C++20 three-way <=> comparison not supported"; +#else + EXPECT_EQ(absl::Cord("a") <=> absl::Cord("a"), std::strong_ordering::equal); + EXPECT_EQ(absl::Cord("aaaa") <=> absl::Cord("aaab"), + std::strong_ordering::less); + EXPECT_EQ(absl::Cord("baaa") <=> absl::Cord("a"), + std::strong_ordering::greater); +#endif +} + +TEST(CordThreeWayComparisonTest, CompareCordsAndStringViews) { +#ifndef __cpp_impl_three_way_comparison + GTEST_SKIP() << "C++20 three-way <=> comparison not supported"; +#else + EXPECT_EQ(absl::string_view("a") <=> absl::Cord("a"), + std::strong_ordering::equal); + EXPECT_EQ(absl::Cord("a") <=> absl::string_view("b"), + std::strong_ordering::less); + EXPECT_EQ(absl::string_view("b") <=> absl::Cord("a"), + std::strong_ordering::greater); +#endif +} + #if defined(GTEST_HAS_DEATH_TEST) && defined(ABSL_INTERNAL_CORD_HAVE_SANITIZER) // Returns an expected poison / uninitialized death message expression. -- cgit v1.2.3 From 0598e582f659594aa3592c70ba7dcb251649d264 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Thu, 18 Jul 2024 07:03:57 -0700 Subject: Delete absl/strings/internal/has_absl_stringify.h now that the GoogleTest version we depend on uses the public file PiperOrigin-RevId: 653606441 Change-Id: Id49b18835443162ddf9747cc31619f3acf01f4ef --- CMake/AbseilDll.cmake | 1 - absl/strings/BUILD.bazel | 1 - absl/strings/CMakeLists.txt | 1 - absl/strings/internal/has_absl_stringify.h | 54 ------------------------------ 4 files changed, 57 deletions(-) delete mode 100644 absl/strings/internal/has_absl_stringify.h (limited to 'absl/strings/BUILD.bazel') diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake index a81cbaf3..24093634 100644 --- a/CMake/AbseilDll.cmake +++ b/CMake/AbseilDll.cmake @@ -321,7 +321,6 @@ set(ABSL_INTERNAL_DLL_FILES "strings/internal/string_constant.h" "strings/internal/stringify_sink.h" "strings/internal/stringify_sink.cc" - "strings/internal/has_absl_stringify.h" "strings/has_absl_stringify.h" "strings/has_ostream_operator.h" "strings/match.cc" diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index 9bffae61..2cc014ed 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -77,7 +77,6 @@ cc_library( "escaping.h", "has_absl_stringify.h", "internal/damerau_levenshtein_distance.h", - "internal/has_absl_stringify.h", "internal/string_constant.h", "match.h", "numbers.h", diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt index 4a84dbbd..3a1619e8 100644 --- a/absl/strings/CMakeLists.txt +++ b/absl/strings/CMakeLists.txt @@ -42,7 +42,6 @@ absl_cc_library( "has_absl_stringify.h" "internal/damerau_levenshtein_distance.h" "internal/string_constant.h" - "internal/has_absl_stringify.h" "match.h" "numbers.h" "str_cat.h" diff --git a/absl/strings/internal/has_absl_stringify.h b/absl/strings/internal/has_absl_stringify.h deleted file mode 100644 index 98f27dff..00000000 --- a/absl/strings/internal/has_absl_stringify.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2024 The Abseil Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_STRINGS_INTERNAL_HAS_ABSL_STRINGIFY_H_ -#define ABSL_STRINGS_INTERNAL_HAS_ABSL_STRINGIFY_H_ - -#include "absl/strings/has_absl_stringify.h" - -#include -#include - -#include "absl/base/config.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN - -namespace strings_internal { - -// This exists to fix a circular dependency problem with the GoogleTest release. -// GoogleTest referenced this internal file and this internal trait. Since -// simultaneous releases are not possible since once release must reference -// another, we will temporarily add this back. -// https://github.com/google/googletest/blob/v1.14.x/googletest/include/gtest/gtest-printers.h#L119 -// -// This file can be deleted after the next Abseil and GoogleTest release. -// -// https://github.com/google/googletest/pull/4368#issuecomment-1717699895 -// https://github.com/google/googletest/pull/4368#issuecomment-1717699895 -template -struct HasAbslStringify : std::false_type {}; - -template -struct HasAbslStringify< - T, std::enable_if_t(), - std::declval()))>::value>> : std::true_type {}; - -} // namespace strings_internal - -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_STRINGS_INTERNAL_HAS_ABSL_STRINGIFY_H_ -- cgit v1.2.3