Commit 0fa5d0c6 authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Provide an explicit constructor for C array initialization of CrashKeyString.

This mirrors
https://chromium-review.googlesource.com/c/crashpad/crashpad/+/807645 in
Crashpad.

Bug: 598854
Change-Id: I1b98dab78df7a30d913be3a476c8b373063e6065
Reviewed-on: https://chromium-review.googlesource.com/820160Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523302}
parent e28b6223
...@@ -125,9 +125,14 @@ class CrashKeyString : public internal::CrashKeyStringImpl { ...@@ -125,9 +125,14 @@ class CrashKeyString : public internal::CrashKeyStringImpl {
constexpr static size_t chunk_count = constexpr static size_t chunk_count =
(MaxLength / internal::kCrashKeyStorageValueSize) + 1; (MaxLength / internal::kCrashKeyStorageValueSize) + 1;
// A constructor tag that can be used to initialize a C array of crash keys.
enum class Tag { kArray };
constexpr explicit CrashKeyString(const char name[]) constexpr explicit CrashKeyString(const char name[])
: internal::CrashKeyStringImpl(name, indexes_.data, chunk_count) {} : internal::CrashKeyStringImpl(name, indexes_.data, chunk_count) {}
constexpr CrashKeyString(const char name[], Tag tag) : CrashKeyString(name) {}
private: private:
// Indexes into the TransitionalCrashKeyStorage for when a value is set. // Indexes into the TransitionalCrashKeyStorage for when a value is set.
// See the comment in CrashKeyStringImpl for details. // See the comment in CrashKeyStringImpl for details.
......
...@@ -98,5 +98,23 @@ TEST_F(CrashKeyStringTest, BaseSupport) { ...@@ -98,5 +98,23 @@ TEST_F(CrashKeyStringTest, BaseSupport) {
base::debug::SetCrashKeyString(crash_key, std::string(64, 'a')); base::debug::SetCrashKeyString(crash_key, std::string(64, 'a'));
} }
TEST_F(CrashKeyStringTest, CArrayInitializer) {
static CrashKeyString<8> keys[] = {
{"test-1", CrashKeyString<8>::Tag::kArray},
{"test-2", CrashKeyString<8>::Tag::kArray},
{"test-3", CrashKeyString<8>::Tag::kArray},
};
EXPECT_FALSE(keys[0].is_set());
EXPECT_FALSE(keys[1].is_set());
EXPECT_FALSE(keys[2].is_set());
keys[1].Set("test");
EXPECT_FALSE(keys[0].is_set());
EXPECT_TRUE(keys[1].is_set());
EXPECT_FALSE(keys[2].is_set());
}
} // namespace } // namespace
} // namespace crash_reporter } // namespace crash_reporter
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