Browse Source

Update contrib/libs/re2 to 2023-02-01

robot-contrib 2 years ago
parent
commit
2d466cb51c

+ 1 - 0
contrib/libs/re2/CMakeLists.darwin.txt

@@ -22,6 +22,7 @@ target_link_libraries(contrib-libs-re2 PUBLIC
   yutil
 )
 target_sources(contrib-libs-re2 PRIVATE
+  ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/bitmap256.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/bitstate.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/compile.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/dfa.cc

+ 1 - 0
contrib/libs/re2/CMakeLists.linux-aarch64.txt

@@ -23,6 +23,7 @@ target_link_libraries(contrib-libs-re2 PUBLIC
   yutil
 )
 target_sources(contrib-libs-re2 PRIVATE
+  ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/bitmap256.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/bitstate.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/compile.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/dfa.cc

+ 1 - 0
contrib/libs/re2/CMakeLists.linux.txt

@@ -23,6 +23,7 @@ target_link_libraries(contrib-libs-re2 PUBLIC
   yutil
 )
 target_sources(contrib-libs-re2 PRIVATE
+  ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/bitmap256.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/bitstate.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/compile.cc
   ${CMAKE_SOURCE_DIR}/contrib/libs/re2/re2/dfa.cc

+ 44 - 0
contrib/libs/re2/re2/bitmap256.cc

@@ -0,0 +1,44 @@
+// Copyright 2023 The RE2 Authors.  All Rights Reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "re2/bitmap256.h"
+
+#include <stdint.h>
+
+#include "util/util.h"
+#include "util/logging.h"
+
+namespace re2 {
+
+int Bitmap256::FindNextSetBit(int c) const {
+  DCHECK_GE(c, 0);
+  DCHECK_LE(c, 255);
+
+  // Check the word that contains the bit. Mask out any lower bits.
+  int i = c / 64;
+  uint64_t word = words_[i] & (~uint64_t{0} << (c % 64));
+  if (word != 0)
+    return (i * 64) + FindLSBSet(word);
+
+  // Check any following words.
+  i++;
+  switch (i) {
+    case 1:
+      if (words_[1] != 0)
+        return (1 * 64) + FindLSBSet(words_[1]);
+      FALLTHROUGH_INTENDED;
+    case 2:
+      if (words_[2] != 0)
+        return (2 * 64) + FindLSBSet(words_[2]);
+      FALLTHROUGH_INTENDED;
+    case 3:
+      if (words_[3] != 0)
+        return (3 * 64) + FindLSBSet(words_[3]);
+      FALLTHROUGH_INTENDED;
+    default:
+      return -1;
+  }
+}
+
+}  // namespace re2

+ 0 - 31
contrib/libs/re2/re2/bitmap256.h

@@ -11,7 +11,6 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "util/util.h"
 #include "util/logging.h"
 
 namespace re2 {
@@ -82,36 +81,6 @@ class Bitmap256 {
   uint64_t words_[4];
 };
 
-int Bitmap256::FindNextSetBit(int c) const {
-  DCHECK_GE(c, 0);
-  DCHECK_LE(c, 255);
-
-  // Check the word that contains the bit. Mask out any lower bits.
-  int i = c / 64;
-  uint64_t word = words_[i] & (~uint64_t{0} << (c % 64));
-  if (word != 0)
-    return (i * 64) + FindLSBSet(word);
-
-  // Check any following words.
-  i++;
-  switch (i) {
-    case 1:
-      if (words_[1] != 0)
-        return (1 * 64) + FindLSBSet(words_[1]);
-      FALLTHROUGH_INTENDED;
-    case 2:
-      if (words_[2] != 0)
-        return (2 * 64) + FindLSBSet(words_[2]);
-      FALLTHROUGH_INTENDED;
-    case 3:
-      if (words_[3] != 0)
-        return (3 * 64) + FindLSBSet(words_[3]);
-      FALLTHROUGH_INTENDED;
-    default:
-      return -1;
-  }
-}
-
 }  // namespace re2
 
 #endif  // RE2_BITMAP256_H_

+ 18 - 2
contrib/libs/re2/util/mutex.h

@@ -10,6 +10,10 @@
  * You should assume the locks are *not* re-entrant.
  */
 
+#ifdef RE2_NO_THREADS
+#include <assert.h>
+#define MUTEX_IS_LOCK_COUNTER
+#else
 #ifdef _WIN32
 // Requires Windows Vista or Windows Server 2008 at minimum.
 #include <windows.h>
@@ -25,8 +29,11 @@
 #define MUTEX_IS_PTHREAD_RWLOCK
 #endif
 #endif
+#endif
 
-#if defined(MUTEX_IS_WIN32_SRWLOCK)
+#if defined(MUTEX_IS_LOCK_COUNTER)
+typedef int MutexType;
+#elif defined(MUTEX_IS_WIN32_SRWLOCK)
 typedef SRWLOCK MutexType;
 #elif defined(MUTEX_IS_PTHREAD_RWLOCK)
 #include <pthread.h>
@@ -64,7 +71,16 @@ class Mutex {
   Mutex& operator=(const Mutex&) = delete;
 };
 
-#if defined(MUTEX_IS_WIN32_SRWLOCK)
+#if defined(MUTEX_IS_LOCK_COUNTER)
+
+Mutex::Mutex()             : mutex_(0) { }
+Mutex::~Mutex()            { assert(mutex_ == 0); }
+void Mutex::Lock()         { assert(--mutex_ == -1); }
+void Mutex::Unlock()       { assert(mutex_++ == -1); }
+void Mutex::ReaderLock()   { assert(++mutex_ > 0); }
+void Mutex::ReaderUnlock() { assert(mutex_-- > 0); }
+
+#elif defined(MUTEX_IS_WIN32_SRWLOCK)
 
 Mutex::Mutex()             : mutex_(SRWLOCK_INIT) { }
 Mutex::~Mutex()            { }

+ 1 - 1
contrib/libs/re2/util/pcre.h

@@ -500,7 +500,7 @@ class PCRE {
   bool                report_errors_;  // Silences error logging if false
   int                 match_limit_;    // Limit on execution resources
   int                 stack_limit_;    // Limit on stack resources (bytes)
-  mutable int32_t     hit_limit_;      // Hit limit during execution (bool)
+  mutable int         hit_limit_;      // Hit limit during execution (bool)
 
   PCRE(const PCRE&) = delete;
   PCRE& operator=(const PCRE&) = delete;