summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2024-04-24 11:55:19 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-04-24 11:56:38 -0700
commitb65852fa1e384d6e593b09dcf2134566e44dc02a (patch)
treef9dd21e634dae509997926343fd900351396f81d /absl
parentc3b4f2950a803109f52d455bffcef3681dbe522d (diff)
Remove the hand-rolled CordLeaker and replace with absl::NoDestructor
to test the after-exit behavior PiperOrigin-RevId: 627804039 Change-Id: Idc1c5fc14cea466dcc98f0d8746c02cafe887502
Diffstat (limited to 'absl')
-rw-r--r--absl/strings/BUILD.bazel1
-rw-r--r--absl/strings/CMakeLists.txt1
-rw-r--r--absl/strings/cord_test.cc34
3 files changed, 9 insertions, 27 deletions
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 <typename Str>
- 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 <typename Str>
-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<absl::Cord> 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 {