From c09a3f984513594fbfe7711c1ac296e82e57888b Mon Sep 17 00:00:00 2001 From: jdymitarai Date: Wed, 9 Sep 2026 23:35:28 +0000 Subject: [PATCH] re2: pass Mutex by pointer in MutexLock usage Revert commit 972a15ce9aa71e98fec1fc4a10e8eac9fa3bcf24 ("re2: remove unnecessary & in MutexLock usage"). vcpkg and other packaging systems use Abseil LTS (such as 20250127), which only provides the pointer-based MutexLock(Mutex*) constructor. Passing Mutex by reference causes MSVC compilation failure with error C2665. Passing by pointer is also consistent with re2/regexp.cc. Fixes #628. --- re2/dfa.cc | 8 ++++---- re2/testing/regexp_benchmark.cc | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/re2/dfa.cc b/re2/dfa.cc index d587a5520..712a7b694 100644 --- a/re2/dfa.cc +++ b/re2/dfa.cc @@ -1015,7 +1015,7 @@ void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq, DFA::State* DFA::RunStateOnByteUnlocked(State* state, int c) { // Keep only one RunStateOnByte going // even if the DFA is being run by multiple threads. - absl::MutexLock l(mutex_); + absl::MutexLock l(&mutex_); return RunStateOnByte(state, c); } @@ -1267,7 +1267,7 @@ DFA::StateSaver::~StateSaver() { DFA::State* DFA::StateSaver::Restore() { if (is_special_) return special_; - absl::MutexLock l(dfa_->mutex_); + absl::MutexLock l(&dfa_->mutex_); State* s = dfa_->CachedState(inst_, ninst_, flag_); if (s == NULL) ABSL_LOG(DFATAL) << "StateSaver failed to restore state."; @@ -1730,7 +1730,7 @@ bool DFA::AnalyzeSearchHelper(SearchParams* params, StartInfo* info, if (start != NULL) return true; - absl::MutexLock l(mutex_); + absl::MutexLock l(&mutex_); start = info->start.load(std::memory_order_relaxed); if (start != NULL) return true; @@ -2050,7 +2050,7 @@ bool DFA::PossibleMatchRange(std::string* min, std::string* max, int maxlen) { // Build minimum prefix. State* s = params.start; min->clear(); - absl::MutexLock lock(mutex_); + absl::MutexLock lock(&mutex_); for (int i = 0; i < maxlen; i++) { if (previously_visited_states[s] > kMaxEltRepetitions) break; diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc index 3940467dd..3b0a5330b 100644 --- a/re2/testing/regexp_benchmark.cc +++ b/re2/testing/regexp_benchmark.cc @@ -964,7 +964,7 @@ void SearchRE2(benchmark::State& state, const char* regexp, Prog* GetCachedProg(const char* regexp) { static auto& mutex = *new absl::Mutex; - absl::MutexLock lock(mutex); + absl::MutexLock lock(&mutex); static auto& cache = *new absl::flat_hash_map; Prog* prog = cache[regexp]; if (prog == NULL) { @@ -982,7 +982,7 @@ Prog* GetCachedProg(const char* regexp) { PCRE* GetCachedPCRE(const char* regexp) { static auto& mutex = *new absl::Mutex; - absl::MutexLock lock(mutex); + absl::MutexLock lock(&mutex); static auto& cache = *new absl::flat_hash_map; PCRE* re = cache[regexp]; if (re == NULL) { @@ -995,7 +995,7 @@ PCRE* GetCachedPCRE(const char* regexp) { RE2* GetCachedRE2(const char* regexp) { static auto& mutex = *new absl::Mutex; - absl::MutexLock lock(mutex); + absl::MutexLock lock(&mutex); static auto& cache = *new absl::flat_hash_map; RE2* re = cache[regexp]; if (re == NULL) {