Skip to content

Commit 9517566

Browse files
Abseil Teamcopybara-github
authored andcommitted
Change abseil hardening assertions in cleanup from macros to functions
This associates debug information with the assertion sites, allowing clearer stack-traces for assertion failures and better accounting of the performance overhead of assertions. PiperOrigin-RevId: 911622698 Change-Id: If981469b9da24c83a97534db2aa579ee21c9547c
1 parent e68f118 commit 9517566

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

absl/cleanup/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cc_library(
3939
linkopts = ABSL_DEFAULT_LINKOPTS,
4040
deps = [
4141
"//absl/base:core_headers",
42+
"//absl/base:hardening",
4243
"//absl/utility",
4344
],
4445
)
@@ -54,6 +55,7 @@ cc_library(
5455
":cleanup_internal",
5556
"//absl/base:config",
5657
"//absl/base:core_headers",
58+
"//absl/base:hardening",
5759
],
5860
)
5961

absl/cleanup/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ absl_cc_library(
2222
${ABSL_DEFAULT_COPTS}
2323
DEPS
2424
absl::core_headers
25+
absl::hardening
2526
absl::utility
2627
PUBLIC
2728
)
@@ -37,6 +38,7 @@ absl_cc_library(
3738
absl::cleanup_internal
3839
absl::config
3940
absl::core_headers
41+
absl::hardening
4042
PUBLIC
4143
)
4244

absl/cleanup/cleanup.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include <utility>
7676

7777
#include "absl/base/config.h"
78+
#include "absl/base/internal/hardening.h"
7879
#include "absl/base/macros.h"
7980
#include "absl/cleanup/internal/cleanup.h"
8081

@@ -95,12 +96,12 @@ class [[nodiscard]] Cleanup final {
9596
Cleanup(Cleanup&& other) = default;
9697

9798
void Cancel() && {
98-
ABSL_HARDENING_ASSERT(storage_.IsCallbackEngaged());
99+
absl::base_internal::HardeningAssert(storage_.IsCallbackEngaged());
99100
storage_.DestroyCallback();
100101
}
101102

102103
void Invoke() && {
103-
ABSL_HARDENING_ASSERT(storage_.IsCallbackEngaged());
104+
absl::base_internal::HardeningAssert(storage_.IsCallbackEngaged());
104105
storage_.InvokeCallback();
105106
storage_.DestroyCallback();
106107
}

absl/cleanup/internal/cleanup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <type_traits>
2020
#include <utility>
2121

22+
#include "absl/base/internal/hardening.h"
2223
#include "absl/base/macros.h"
2324
#include "absl/base/thread_annotations.h"
2425
#include "absl/utility/utility.h"
@@ -55,7 +56,7 @@ class Storage {
5556
}
5657

5758
Storage(Storage&& other) {
58-
ABSL_HARDENING_ASSERT(other.IsCallbackEngaged());
59+
absl::base_internal::HardeningAssert(other.IsCallbackEngaged());
5960

6061
::new (GetCallbackBuffer()) Callback(std::move(other.GetCallback()));
6162
is_callback_engaged_ = true;

0 commit comments

Comments
 (0)