Skip to content

Commit

Permalink
Fix MacOS crash which involves two static absl::flat_hash_set globals.
Browse files Browse the repository at this point in the history
Details:

```shell
Assertion failed: (ctrl != nullptr), function iterator, file external/com_google_absl/absl/container/internal/raw_hash_set.h, line 749.
Process 70835 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = hit program assert
    frame #4: 0x000000010000ae22 utf8_delimiters_test`absl::container_internal::raw_hash_set<absl::container_internal::FlatHashSetPolicy<char32_t>, absl::hash_internal::Hash<char32_t>, std::__1::equal_to<char32_t>, std::__1::allocator<char32_t> >::iterator::iterator(signed char*, char32_t*) + 98
utf8_delimiters_test`absl::container_internal::raw_hash_set<absl::container_internal::FlatHashSetPolicy<char32_t>, absl::hash_internal::Hash<char32_t>, std::__1::equal_to<char32_t>, std::__1::allocator<char32_t> >::iterator::iterator:
->  0x10000ae22 <+98>:  jmp    0x10000ae27               ; <+103>
    0x10000ae27 <+103>: addq   $0x20, %rsp
    0x10000ae2b <+107>: popq   %rbp
    0x10000ae2c <+108>: retq
Target 0: (utf8_delimiters_test) stopped.
(lldb) up
```

PiperOrigin-RevId: 382336985
  • Loading branch information
agutkin authored and copybara-github committed Jun 30, 2021
1 parent cf78fbb commit bc4ba9b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions nisaba/port/unicode_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace nisaba {
namespace utf8 {
namespace {

const absl::flat_hash_set<char32_t> kBreakingWhitespace = {
constexpr char32_t kBreakingWhitespace[] = {
U'\u0009', // character tabulation
U'\u000A', // line feed
U'\u000B', // line tabulation
Expand Down Expand Up @@ -49,7 +49,7 @@ const absl::flat_hash_set<char32_t> kBreakingWhitespace = {
U'\u3000', // ideographic space
};

const absl::flat_hash_set<char32_t> kNonBreakingWhitespace = {
constexpr char32_t kNonBreakingWhitespace[] = {
U'\u180E', // mongolian vowel separator
U'\u200B', // zero width space
U'\u200C', // zero width non-joiner
Expand All @@ -61,17 +61,20 @@ const absl::flat_hash_set<char32_t> kNonBreakingWhitespace = {
} // namespace

absl::flat_hash_set<char32_t> GetBreakingWhitespaceChars() {
return kBreakingWhitespace;
return absl::flat_hash_set<char32_t>(std::begin(kBreakingWhitespace),
std::end(kBreakingWhitespace));
}

absl::flat_hash_set<char32_t> GetNonBreakingWhitespaceChars() {
return kNonBreakingWhitespace;
return absl::flat_hash_set<char32_t>(std::begin(kNonBreakingWhitespace),
std::end(kNonBreakingWhitespace));
}

absl::flat_hash_set<char32_t> GetAllWhitespaceChars() {
absl::flat_hash_set<char32_t> all_chars;
std::set_union(kBreakingWhitespace.begin(), kBreakingWhitespace.end(),
kNonBreakingWhitespace.begin(), kNonBreakingWhitespace.end(),
std::set_union(std::begin(kBreakingWhitespace), std::end(kBreakingWhitespace),
std::begin(kNonBreakingWhitespace),
std::end(kNonBreakingWhitespace),
std::inserter(all_chars, all_chars.begin()));
return all_chars;
}
Expand Down

0 comments on commit bc4ba9b

Please sign in to comment.