diff options
author | Cronet Mainline Eng <cronet-mainline-eng+copybara@google.com> | 2024-06-07 18:59:21 +0900 |
---|---|---|
committer | Motomu Utsumi <motomuman@google.com> | 2024-06-07 19:00:37 +0900 |
commit | 93dc77d4cfa4a2996ac5bf4c67b0d4223847eb65 (patch) | |
tree | 92c5aba3655194ff55d27c652a265bd6f87b0470 /third_party/re2/src | |
parent | b66ce594f84a102bf71c3e2754d9c0bfdd620b85 (diff) | |
download | cronet-93dc77d4cfa4a2996ac5bf4c67b0d4223847eb65.tar.gz |
Import Cronet version 124.0.6367.42
FolderOrigin-RevId: /tmp/copybara-origin/src
Change-Id: I727d2277512236d7d0db42e102d291b6204b38e5
Diffstat (limited to 'third_party/re2/src')
-rw-r--r-- | third_party/re2/src/.bazelrc | 7 | ||||
-rwxr-xr-x | third_party/re2/src/.github/bazel.sh | 37 | ||||
-rwxr-xr-x | third_party/re2/src/.github/cmake.sh | 13 | ||||
-rw-r--r-- | third_party/re2/src/.github/workflows/ci-bazel.yml | 4 | ||||
-rw-r--r-- | third_party/re2/src/.github/workflows/ci-cmake.yml | 6 | ||||
-rw-r--r-- | third_party/re2/src/.github/workflows/ci.yml | 8 | ||||
-rw-r--r-- | third_party/re2/src/.github/workflows/pages.yml | 10 | ||||
-rw-r--r-- | third_party/re2/src/.github/workflows/pr.yml | 4 | ||||
-rw-r--r-- | third_party/re2/src/.github/workflows/python.yml | 30 | ||||
-rw-r--r-- | third_party/re2/src/MODULE.bazel | 8 | ||||
-rw-r--r-- | third_party/re2/src/README | 2 | ||||
-rwxr-xr-x | third_party/re2/src/doc/mksyntaxgo | 2 | ||||
-rw-r--r-- | third_party/re2/src/python/BUILD.bazel | 2 | ||||
-rw-r--r-- | third_party/re2/src/python/_re2.cc | 7 | ||||
-rw-r--r-- | third_party/re2/src/python/re2.py | 5 | ||||
-rw-r--r-- | third_party/re2/src/python/re2_test.py | 7 | ||||
-rw-r--r-- | third_party/re2/src/re2/filtered_re2.cc | 3 | ||||
-rw-r--r-- | third_party/re2/src/re2/prefilter_tree.cc | 6 |
18 files changed, 89 insertions, 72 deletions
diff --git a/third_party/re2/src/.bazelrc b/third_party/re2/src/.bazelrc index c8ff98fa2..0311dd3e0 100644 --- a/third_party/re2/src/.bazelrc +++ b/third_party/re2/src/.bazelrc @@ -8,10 +8,6 @@ build --features=layering_check build --features=parse_headers # Abseil requires C++14 at minimum. -# Previously, the flag was set via `BAZEL_CXXOPTS`. On macOS, we also had to set -# `BAZEL_USE_CPP_ONLY_TOOLCHAIN` since Bazel wouldn't respect the former without -# the latter. However, the latter stopped Bazel from using Xcode and `-framework -# Foundation`, which CCTZ (vendored into Abseil) requires. build --enable_platform_specific_config build:linux --cxxopt=-std=c++14 build:macos --cxxopt=-std=c++14 @@ -19,3 +15,6 @@ build:windows --cxxopt=/std:c++14 # Print test logs for failed tests. test --test_output=errors + +# https://bazel.build/configure/best-practices#bazelrc-file +try-import %workspace%/user.bazelrc diff --git a/third_party/re2/src/.github/bazel.sh b/third_party/re2/src/.github/bazel.sh index 7295ec6a8..1fe309fab 100755 --- a/third_party/re2/src/.github/bazel.sh +++ b/third_party/re2/src/.github/bazel.sh @@ -1,24 +1,25 @@ #!/bin/bash set -eux -bazel clean -bazel build --compilation_mode=dbg -- //:all -bazel test --compilation_mode=dbg -- //:all \ - -//:dfa_test \ - -//:exhaustive1_test \ - -//:exhaustive2_test \ - -//:exhaustive3_test \ - -//:exhaustive_test \ - -//:random_test +# Disable MSYS/MSYS2 path conversion, which interferes with Bazel. +export MSYS_NO_PATHCONV='1' +export MSYS2_ARG_CONV_EXCL='*' -bazel clean -bazel build --compilation_mode=opt -- //:all -bazel test --compilation_mode=opt -- //:all \ - -//:dfa_test \ - -//:exhaustive1_test \ - -//:exhaustive2_test \ - -//:exhaustive3_test \ - -//:exhaustive_test \ - -//:random_test +for compilation_mode in dbg opt +do + bazel clean + bazel build --compilation_mode=${compilation_mode} -- \ + //:re2 \ + //python:re2 + bazel test --compilation_mode=${compilation_mode} -- \ + //:all \ + -//:dfa_test \ + -//:exhaustive1_test \ + -//:exhaustive2_test \ + -//:exhaustive3_test \ + -//:exhaustive_test \ + -//:random_test \ + //python:all +done exit 0 diff --git a/third_party/re2/src/.github/cmake.sh b/third_party/re2/src/.github/cmake.sh index 782334e81..5e42d3703 100755 --- a/third_party/re2/src/.github/cmake.sh +++ b/third_party/re2/src/.github/cmake.sh @@ -1,12 +1,11 @@ #!/bin/bash set -eux -cmake . -D CMAKE_BUILD_TYPE=Debug -D RE2_BUILD_TESTING=ON "$@" -cmake --build . --config Debug --clean-first -ctest -C Debug --output-on-failure -E 'dfa|exhaustive|random' - -cmake . -D CMAKE_BUILD_TYPE=Release -D RE2_BUILD_TESTING=ON "$@" -cmake --build . --config Release --clean-first -ctest -C Release --output-on-failure -E 'dfa|exhaustive|random' +for CMAKE_BUILD_TYPE in Debug Release +do + cmake . -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -D RE2_BUILD_TESTING=ON "$@" + cmake --build . --config ${CMAKE_BUILD_TYPE} --clean-first + ctest -C ${CMAKE_BUILD_TYPE} --output-on-failure -E 'dfa|exhaustive|random' +done exit 0 diff --git a/third_party/re2/src/.github/workflows/ci-bazel.yml b/third_party/re2/src/.github/workflows/ci-bazel.yml index a12a7c580..4eea110fb 100644 --- a/third_party/re2/src/.github/workflows/ci-bazel.yml +++ b/third_party/re2/src/.github/workflows/ci-bazel.yml @@ -14,8 +14,8 @@ jobs: env: BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v4 - - uses: p0deje/setup-bazel@0.6.0 + - uses: actions/checkout@v4.1.1 + - uses: bazel-contrib/setup-bazel@0.8.1 with: bazelisk-version: '1.x' - run: .github/bazel.sh diff --git a/third_party/re2/src/.github/workflows/ci-cmake.yml b/third_party/re2/src/.github/workflows/ci-cmake.yml index a49fd53b1..6e131fe1a 100644 --- a/third_party/re2/src/.github/workflows/ci-cmake.yml +++ b/third_party/re2/src/.github/workflows/ci-cmake.yml @@ -15,7 +15,7 @@ jobs: matrix: build_shared_libs: [OFF, ON] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 - name: Install CMake run: | apt update -y @@ -35,7 +35,7 @@ jobs: matrix: build_shared_libs: [OFF, ON] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 - name: Install Abseil, GoogleTest and Benchmark run: | brew update @@ -50,7 +50,7 @@ jobs: matrix: build_shared_libs: [OFF, ON] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 - name: Install Abseil, GoogleTest and Benchmark run: | vcpkg update diff --git a/third_party/re2/src/.github/workflows/ci.yml b/third_party/re2/src/.github/workflows/ci.yml index 445da78d6..27ce6ece7 100644 --- a/third_party/re2/src/.github/workflows/ci.yml +++ b/third_party/re2/src/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: # (The other two flags are the default provided for CXXFLAGS in Makefile.) CXXFLAGS: -O3 -g -std=c++${{ matrix.ver }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 - name: Install Abseil, GoogleTest and Benchmark run: | brew update @@ -34,12 +34,12 @@ jobs: strategy: fail-fast: false matrix: - ver: [15, 16, 17] + ver: [16, 17, 18] env: CC: clang-${{ matrix.ver }} CXX: clang++-${{ matrix.ver }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 - name: Install Clang ${{ matrix.ver }} run: | # Avoid `Conflicts: python3-lldb-x.y` between packages. @@ -65,7 +65,7 @@ jobs: CC: gcc-${{ matrix.ver }} CXX: g++-${{ matrix.ver }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 - name: Install Abseil, GoogleTest and Benchmark run: | sudo apt update -y diff --git a/third_party/re2/src/.github/workflows/pages.yml b/third_party/re2/src/.github/workflows/pages.yml index 0f0a57a15..5bff8306c 100644 --- a/third_party/re2/src/.github/workflows/pages.yml +++ b/third_party/re2/src/.github/workflows/pages.yml @@ -17,13 +17,13 @@ jobs: # Bazel fails if the username is unknown. USER: runner steps: - - uses: actions/checkout@v4 - - uses: p0deje/setup-bazel@0.6.0 + - uses: actions/checkout@v4.1.1 + - uses: bazel-contrib/setup-bazel@0.8.1 with: bazelisk-version: '1.x' - run: app/build.sh shell: bash - - uses: actions/upload-pages-artifact@v3 + - uses: actions/upload-pages-artifact@v3.0.1 with: path: app/deploy deploy: @@ -37,5 +37,5 @@ jobs: environment: github-pages runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/deploy-pages@v4 + - uses: actions/checkout@v4.1.1 + - uses: actions/deploy-pages@v4.0.4 diff --git a/third_party/re2/src/.github/workflows/pr.yml b/third_party/re2/src/.github/workflows/pr.yml index 267dd5d7d..805f0fa4a 100644 --- a/third_party/re2/src/.github/workflows/pr.yml +++ b/third_party/re2/src/.github/workflows/pr.yml @@ -15,8 +15,8 @@ jobs: pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/github-script@v7 + - uses: actions/checkout@v4.1.1 + - uses: actions/github-script@v7.0.1 with: script: | const fs = require('fs'); diff --git a/third_party/re2/src/.github/workflows/python.yml b/third_party/re2/src/.github/workflows/python.yml index 892922e48..7d9048c09 100644 --- a/third_party/re2/src/.github/workflows/python.yml +++ b/third_party/re2/src/.github/workflows/python.yml @@ -31,11 +31,11 @@ jobs: # Bazel fails if the username is unknown. USER: runner steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 # Stash the timestamp for the commit SHA that triggered the workflow. - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" shell: bash - - uses: p0deje/setup-bazel@0.6.0 + - uses: bazel-contrib/setup-bazel@0.8.1 with: bazelisk-version: '1.x' - name: Prepare Python ${{ matrix.ver }} environment @@ -58,7 +58,7 @@ jobs: "${PYTHON}" re2_test.py shell: bash working-directory: python - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4.3.1 with: name: ${{ hashFiles('python/google_re2-*.whl') }} path: python/google_re2-*.whl @@ -84,14 +84,14 @@ jobs: # Otherwise, Python refuses to install the built wheel! SYSTEM_VERSION_COMPAT: 0 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 # Stash the timestamp for the commit SHA that triggered the workflow. - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" shell: bash - - uses: p0deje/setup-bazel@0.6.0 + - uses: bazel-contrib/setup-bazel@0.8.1 with: bazelisk-version: '1.x' - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5.0.0 with: python-version: ${{ matrix.ver }} - name: Prepare Python ${{ matrix.ver }} environment @@ -115,7 +115,7 @@ jobs: python re2_test.py shell: bash working-directory: python - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4.3.1 with: name: ${{ hashFiles('python/google_re2-*.whl') }} path: python/google_re2-*.whl @@ -135,11 +135,11 @@ jobs: BAZEL_CPU: ${{ matrix.arch.bazel-name }}_windows PLAT_NAME: ${{ matrix.arch.python-name }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 # Stash the timestamp for the commit SHA that triggered the workflow. - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" shell: bash - - uses: p0deje/setup-bazel@0.6.0 + - uses: bazel-contrib/setup-bazel@0.8.1 with: bazelisk-version: '1.x' # Lowercase the architecture name for `actions/setup-python`. @@ -147,7 +147,7 @@ jobs: ARCHITECTURE=${{ matrix.arch.name }} echo "architecture=${ARCHITECTURE,,}" >> "${GITHUB_ENV}" shell: bash - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5.0.0 with: python-version: ${{ matrix.ver }} architecture: ${{ env.architecture }} @@ -171,7 +171,7 @@ jobs: python re2_test.py shell: bash working-directory: python - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4.3.1 with: name: ${{ hashFiles('python/google_re2-*.whl') }} path: python/google_re2-*.whl @@ -183,11 +183,11 @@ jobs: - wheel-windows runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.1 # Stash the timestamp for the commit SHA that triggered the workflow. - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" shell: bash - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5.0.0 with: python-version: '3.x' - name: Prepare Python 3.x environment @@ -203,7 +203,7 @@ jobs: python -m build --sdist shell: bash working-directory: python - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v4.1.4 with: path: python - name: Set build number to ${{ inputs.build }} @@ -219,7 +219,7 @@ jobs: shell: bash working-directory: python - if: inputs.build >= 1 - uses: pypa/gh-action-pypi-publish@release/v1 + uses: pypa/gh-action-pypi-publish@v1.8.14 with: password: ${{ secrets.PYPI_API_TOKEN }} packages-dir: python/dist diff --git a/third_party/re2/src/MODULE.bazel b/third_party/re2/src/MODULE.bazel index 77a8a2e29..423572761 100644 --- a/third_party/re2/src/MODULE.bazel +++ b/third_party/re2/src/MODULE.bazel @@ -6,16 +6,16 @@ module( name = "re2", - version = "2024-02-01", + version = "2024-03-01", compatibility_level = 1, ) bazel_dep(name = "platforms", version = "0.0.8") -bazel_dep(name = "apple_support", version = "1.12.0") +bazel_dep(name = "apple_support", version = "1.14.0") bazel_dep(name = "rules_cc", version = "0.0.9") -bazel_dep(name = "abseil-cpp", version = "20240116.0") +bazel_dep(name = "abseil-cpp", version = "20240116.1") bazel_dep(name = "rules_python", version = "0.31.0") -bazel_dep(name = "pybind11_bazel", version = "2.11.1.bzl.2") +bazel_dep(name = "pybind11_bazel", version = "2.11.1.bzl.3") # This is a temporary hack for `x64_x86_windows`. # TODO(junyer): Remove whenever no longer needed. diff --git a/third_party/re2/src/README b/third_party/re2/src/README index 469d6f397..21a4358c8 100644 --- a/third_party/re2/src/README +++ b/third_party/re2/src/README @@ -32,7 +32,7 @@ under the BSD-style license found in the LICENSE file. RE2's native language is C++. -The Python wrapper is at https://github.com/google/re2/tree/abseil/python +The Python wrapper is at https://github.com/google/re2/tree/main/python and on PyPI (https://pypi.org/project/google-re2/). A C wrapper is at https://github.com/marcomaggi/cre2/. diff --git a/third_party/re2/src/doc/mksyntaxgo b/third_party/re2/src/doc/mksyntaxgo index 1a09b87cc..10a253efa 100755 --- a/third_party/re2/src/doc/mksyntaxgo +++ b/third_party/re2/src/doc/mksyntaxgo @@ -19,7 +19,7 @@ sam -d $out <<'!' // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// DO NOT EDIT. This file is generated by mksyntaxgo from the RE2 distribution. +// Code generated by mksyntaxgo from the RE2 distribution. DO NOT EDIT. /* Package syntax parses regular expressions into parse trees and compiles diff --git a/third_party/re2/src/python/BUILD.bazel b/third_party/re2/src/python/BUILD.bazel index ed1726ba3..74b7339a5 100644 --- a/third_party/re2/src/python/BUILD.bazel +++ b/third_party/re2/src/python/BUILD.bazel @@ -19,7 +19,7 @@ pybind_extension( py_library( name = "re2", srcs = ["re2.py"], - data = [":_re2.so"], + data = [":_re2"], imports = ["."], visibility = ["//visibility:public"], ) diff --git a/third_party/re2/src/python/_re2.cc b/third_party/re2/src/python/_re2.cc index 8564f8a4f..07e33cec2 100644 --- a/third_party/re2/src/python/_re2.cc +++ b/third_party/re2/src/python/_re2.cc @@ -219,6 +219,10 @@ class Filter { } std::vector<int> Match(py::buffer buffer, bool potential) const { + if (set_ == nullptr) { + py::pybind11_fail("Match() called before compiling"); + } + auto bytes = buffer.request(); auto text = FromBytes(bytes); std::vector<int> atoms; @@ -243,6 +247,9 @@ class Filter { }; PYBIND11_MODULE(_re2, module) { + // Translate exceptions thrown by py::pybind11_fail() into Python. + py::register_local_exception<std::runtime_error>(module, "Error"); + module.def("CharLenToBytes", &CharLenToBytes); module.def("BytesToCharLen", &BytesToCharLen); diff --git a/third_party/re2/src/python/re2.py b/third_party/re2/src/python/re2.py index 8a6d98539..d5023e767 100644 --- a/third_party/re2/src/python/re2.py +++ b/third_party/re2/src/python/re2.py @@ -33,8 +33,9 @@ import itertools import _re2 -class error(Exception): - pass +# pybind11 translates C++ exceptions to Python exceptions. +# We use that same Python exception class for consistency. +error = _re2.Error class Options(_re2.RE2.Options): diff --git a/third_party/re2/src/python/re2_test.py b/third_party/re2/src/python/re2_test.py index 86aa9ae51..df1a9eb70 100644 --- a/third_party/re2/src/python/re2_test.py +++ b/third_party/re2/src/python/re2_test.py @@ -477,6 +477,13 @@ class FilterTest(absltest.TestCase): # Verify whether the underlying RE2 object is usable. self.assertEqual(0, f.re(2).groups) + def test_issue_484(self): + # Previously, the shim would dereference a null pointer and crash. + f = re2.Filter() + with self.assertRaisesRegex(re2.error, + r'Match\(\) called before compiling'): + f.Match('') + if __name__ == '__main__': absltest.main() diff --git a/third_party/re2/src/re2/filtered_re2.cc b/third_party/re2/src/re2/filtered_re2.cc index 49cf68601..1ce26a38e 100644 --- a/third_party/re2/src/re2/filtered_re2.cc +++ b/third_party/re2/src/re2/filtered_re2.cc @@ -70,8 +70,9 @@ void FilteredRE2::Compile(std::vector<std::string>* atoms) { return; } + // Similarly to PrefilterTree::Compile(), make compiling + // a no-op if it's attempted before adding any patterns. if (re2_vec_.empty()) { - LOG(ERROR) << "Compile called before Add."; return; } diff --git a/third_party/re2/src/re2/prefilter_tree.cc b/third_party/re2/src/re2/prefilter_tree.cc index 3afb241c9..299a680fb 100644 --- a/third_party/re2/src/re2/prefilter_tree.cc +++ b/third_party/re2/src/re2/prefilter_tree.cc @@ -57,8 +57,9 @@ void PrefilterTree::Compile(std::vector<std::string>* atom_vec) { // Some legacy users of PrefilterTree call Compile() before // adding any regexps and expect Compile() to have no effect. - if (prefilter_vec_.empty()) + if (prefilter_vec_.empty()) { return; + } compiled_ = true; @@ -272,8 +273,9 @@ void PrefilterTree::RegexpsGivenStrings( // Some legacy users of PrefilterTree call Compile() before // adding any regexps and expect Compile() to have no effect. // This kludge is a counterpart to that kludge. - if (prefilter_vec_.empty()) + if (prefilter_vec_.empty()) { return; + } LOG(ERROR) << "RegexpsGivenStrings called before Compile."; for (size_t i = 0; i < prefilter_vec_.size(); i++) |