diff --git a/.bazelrc b/.bazelrc index c8ff98fa2..0311dd3e0 100644 --- a/.bazelrc +++ b/.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/.github/bazel.sh b/.github/bazel.sh index 7295ec6a8..f9f925cd6 100755 --- a/.github/bazel.sh +++ b/.github/bazel.sh @@ -1,24 +1,29 @@ #!/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 \ + --extra_toolchains=//python/toolchains:all \ + --compilation_mode=${compilation_mode} -- \ + //:re2 \ + //python:re2 + bazel test \ + --extra_toolchains=//python/toolchains:all \ + --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/.github/cmake.sh b/.github/cmake.sh index 782334e81..5e42d3703 100755 --- a/.github/cmake.sh +++ b/.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/.github/workflows/ci-bazel.yml b/.github/workflows/ci-bazel.yml index 174ed68a9..2b56d9954 100644 --- a/.github/workflows/ci-bazel.yml +++ b/.github/workflows/ci-bazel.yml @@ -11,10 +11,23 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] + ver: ['3.8', '3.9', '3.10', '3.11', '3.12'] env: BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v4 - - uses: bazelbuild/setup-bazelisk@v3 + - uses: actions/checkout@v4.1.7 + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + bazelisk-version: '1.x' + - uses: actions/setup-python@v5.1.0 + with: + python-version: ${{ matrix.ver }} + - name: Prepare Python ${{ matrix.ver }} environment + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade absl-py mypy + python python/toolchains/generate.py + shell: bash - run: .github/bazel.sh shell: bash + # TODO(junyer): Run mypy as per https://github.com/google/re2/issues/496. diff --git a/.github/workflows/ci-cmake.yml b/.github/workflows/ci-cmake.yml index a49fd53b1..8c3e8d679 100644 --- a/.github/workflows/ci-cmake.yml +++ b/.github/workflows/ci-cmake.yml @@ -7,26 +7,20 @@ permissions: jobs: build-linux: runs-on: ubuntu-latest - # The Benchmark package on Ubuntu 22.04 LTS is problematic whereas this - # Docker container is based on Debian bookworm and has a newer version. - container: gcc:13 strategy: fail-fast: false matrix: build_shared_libs: [OFF, ON] steps: - - uses: actions/checkout@v4 - - name: Install CMake - run: | - apt update -y - apt install -y cmake - shell: bash + - uses: actions/checkout@v4.1.7 - name: Install Abseil, GoogleTest and Benchmark run: | - apt update -y - apt install -y libabsl-dev libgtest-dev libbenchmark-dev + vcpkg update + vcpkg install abseil gtest benchmark shell: bash - - run: .github/cmake.sh -D BUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} + - run: | + .github/cmake.sh -D BUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} \ + -D CMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake shell: bash build-macos: runs-on: macos-latest @@ -35,7 +29,7 @@ jobs: matrix: build_shared_libs: [OFF, ON] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 - name: Install Abseil, GoogleTest and Benchmark run: | brew update @@ -50,7 +44,7 @@ jobs: matrix: build_shared_libs: [OFF, ON] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 - name: Install Abseil, GoogleTest and Benchmark run: | vcpkg update diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 445da78d6..494563894 100644 --- a/.github/workflows/ci.yml +++ b/.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.7 - name: Install Abseil, GoogleTest and Benchmark run: | brew update @@ -34,12 +34,13 @@ jobs: strategy: fail-fast: false matrix: - ver: [15, 16, 17] + ver: [16, 17, 18] env: CC: clang-${{ matrix.ver }} CXX: clang++-${{ matrix.ver }} + PKG_CONFIG_PATH: /usr/local/share/vcpkg/installed/x64-linux/lib/pkgconfig steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 - name: Install Clang ${{ matrix.ver }} run: | # Avoid `Conflicts: python3-lldb-x.y` between packages. @@ -50,26 +51,28 @@ jobs: shell: bash - name: Install Abseil, GoogleTest and Benchmark run: | - sudo apt update -y - sudo apt install -y libabsl-dev libgtest-dev libbenchmark-dev + vcpkg update + vcpkg install abseil gtest benchmark shell: bash - run: make && make test shell: bash build-gcc: - runs-on: ubuntu-latest + # TODO(junyer): Switch back to `ubuntu-latest` when this becomes that. + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: - ver: [11, 12, 13] + ver: [12, 13, 14] env: CC: gcc-${{ matrix.ver }} CXX: g++-${{ matrix.ver }} + PKG_CONFIG_PATH: /usr/local/share/vcpkg/installed/x64-linux/lib/pkgconfig steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 - name: Install Abseil, GoogleTest and Benchmark run: | - sudo apt update -y - sudo apt install -y libabsl-dev libgtest-dev libbenchmark-dev + vcpkg update + vcpkg install abseil gtest benchmark shell: bash - run: make && make test shell: bash diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 0810aa8bd..e3653142a 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -17,11 +17,13 @@ jobs: # Bazel fails if the username is unknown. USER: runner steps: - - uses: actions/checkout@v4 - - uses: bazelbuild/setup-bazelisk@v3 + - uses: actions/checkout@v4.1.7 + - uses: bazel-contrib/setup-bazel@0.8.5 + 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: @@ -35,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.7 + - uses: actions/deploy-pages@v4.0.5 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 267dd5d7d..e3f99a4f5 100644 --- a/.github/workflows/pr.yml +++ b/.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.7 + - uses: actions/github-script@v7.0.1 with: script: | const fs = require('fs'); diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c69081bda..d97fcb62b 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -5,6 +5,10 @@ on: build: required: true type: number + force-sdist: + required: false + type: boolean + default: false permissions: contents: read jobs: @@ -21,8 +25,9 @@ jobs: fail-fast: false matrix: arch: - - { name: X64, python-name: x86_64, runs-on: [ubuntu-latest] } - - { name: ARM64, python-name: aarch64, runs-on: [self-hosted, linux, arm64] } + - { name: X64, python-name: x86_64, runs-on: [ubuntu-latest] } + # TODO(junyer): Update the label after ARM64 graduates from beta. + - { name: ARM64, python-name: aarch64, runs-on: [arm-ubuntu-arm-22.04-4core] } os: [manylinux_2_28] ver: ['3.8', '3.9', '3.10', '3.11', '3.12'] env: @@ -31,16 +36,19 @@ jobs: # Bazel fails if the username is unknown. USER: runner steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 # Stash the timestamp for the commit SHA that triggered the workflow. - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" shell: bash - - uses: bazelbuild/setup-bazelisk@v3 + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + bazelisk-version: '1.x' - name: Prepare Python ${{ matrix.ver }} environment run: | "${PYTHON}" -m pip install --upgrade pip - "${PYTHON}" -m pip install --upgrade build wheel auditwheel - "${PYTHON}" -m pip install --upgrade absl-py + "${PYTHON}" -m pip install --upgrade setuptools build wheel auditwheel + "${PYTHON}" -m pip install --upgrade absl-py mypy + "${PYTHON}" python/toolchains/generate.py shell: bash - name: Build wheel env: @@ -53,10 +61,14 @@ jobs: - name: Test wheel run: | "${PYTHON}" -m pip install google_re2-*.whl + # Pivot out of the repository so that we test the wheel. + DIR=$(mktemp -d) + cp re2_test.py "${DIR}" + cd "${DIR}" "${PYTHON}" re2_test.py shell: bash working-directory: python - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4.3.3 with: name: ${{ hashFiles('python/google_re2-*.whl') }} path: python/google_re2-*.whl @@ -78,23 +90,29 @@ jobs: BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BAZEL_CPU: darwin_${{ matrix.arch.bazel-name }} PLAT_NAME: macosx-${{ matrix.os }}.0-${{ matrix.arch.python-name }} + # Force a specific target version of macOS. + # Otherwise, `delocate` renames the wheels! + MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os }}.0 # Stop macOS from reporting the system version as 10.x. # Otherwise, Python refuses to install the built wheel! SYSTEM_VERSION_COMPAT: 0 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 # Stash the timestamp for the commit SHA that triggered the workflow. - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" shell: bash - - uses: bazelbuild/setup-bazelisk@v3 - - uses: actions/setup-python@v5 + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + bazelisk-version: '1.x' + - uses: actions/setup-python@v5.1.0 with: python-version: ${{ matrix.ver }} - name: Prepare Python ${{ matrix.ver }} environment run: | python -m pip install --upgrade pip - python -m pip install --upgrade build wheel delocate - python -m pip install --upgrade absl-py + python -m pip install --upgrade setuptools build wheel delocate + python -m pip install --upgrade absl-py mypy + python python/toolchains/generate.py shell: bash - name: Build wheel env: @@ -108,10 +126,14 @@ jobs: name: Test wheel run: | python -m pip install google_re2-*.whl + # Pivot out of the repository so that we test the wheel. + DIR=$(mktemp -d) + cp re2_test.py "${DIR}" + cd "${DIR}" python re2_test.py shell: bash working-directory: python - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4.3.3 with: name: ${{ hashFiles('python/google_re2-*.whl') }} path: python/google_re2-*.whl @@ -131,30 +153,28 @@ jobs: BAZEL_CPU: ${{ matrix.arch.bazel-name }}_windows PLAT_NAME: ${{ matrix.arch.python-name }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 # Stash the timestamp for the commit SHA that triggered the workflow. - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}" shell: bash - # Avoid the Chocolatey install of Bazel getting in the way; - # `bazelbuild/setup-bazelisk` doesn't work for some reason. - - run: | - choco uninstall -y bazel - choco install -y bazelisk - shell: bash + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + bazelisk-version: '1.x' # Lowercase the architecture name for `actions/setup-python`. - run: | ARCHITECTURE=${{ matrix.arch.name }} echo "architecture=${ARCHITECTURE,,}" >> "${GITHUB_ENV}" shell: bash - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5.1.0 with: python-version: ${{ matrix.ver }} architecture: ${{ env.architecture }} - name: Prepare Python ${{ matrix.ver }} environment run: | python -m pip install --upgrade pip - python -m pip install --upgrade build wheel delvewheel - python -m pip install --upgrade absl-py + python -m pip install --upgrade setuptools build wheel delvewheel + python -m pip install --upgrade absl-py mypy + python python/toolchains/generate.py shell: bash - name: Build wheel env: @@ -167,10 +187,14 @@ jobs: - name: Test wheel run: | python -m pip install google_re2-*.whl + # Pivot out of the repository so that we test the wheel. + DIR=$(mktemp -d) + cp re2_test.py "${DIR}" + cd "${DIR}" python re2_test.py shell: bash working-directory: python - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v4.3.3 with: name: ${{ hashFiles('python/google_re2-*.whl') }} path: python/google_re2-*.whl @@ -180,29 +204,33 @@ jobs: - wheel-linux - wheel-macos - wheel-windows + permissions: + contents: read + # Required for PyPI publishing. + id-token: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4.1.7 # 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.1.0 with: python-version: '3.x' - name: Prepare Python 3.x environment run: | python -m pip install --upgrade pip - python -m pip install --upgrade build wheel + python -m pip install --upgrade setuptools build wheel shell: bash - - if: inputs.build == 1 - name: Build source + - if: inputs.build <= 1 || inputs.force-sdist == true + name: Build sdist env: SOURCE_DATE_EPOCH: ${{ env.timestamp }} run: | python -m build --sdist shell: bash working-directory: python - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v4.1.7 with: path: python - name: Set build number to ${{ inputs.build }} @@ -218,7 +246,6 @@ 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.9.0 with: - password: ${{ secrets.PYPI_API_TOKEN }} packages-dir: python/dist diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..6c513923b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Release +on: + push: + tags: ['**'] +permissions: + contents: read +jobs: + create: + permissions: + # Required to create the release + # and upload the release assets. + contents: write + # Required for Sigstore signing. + id-token: write + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4.1.7 + - run: | + gh release create "${GITHUB_REF_NAME}" \ + --generate-notes --latest --verify-tag \ + --repo "${GITHUB_REPOSITORY}" + gh release download "${GITHUB_REF_NAME}" \ + --archive tar.gz \ + --repo "${GITHUB_REPOSITORY}" + gh release download "${GITHUB_REF_NAME}" \ + --archive zip \ + --repo "${GITHUB_REPOSITORY}" + shell: bash + - uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + # N.B. This is a whitespace-separated string! + inputs: '*.tar.gz *.zip' + - run: | + gh release upload "${GITHUB_REF_NAME}" \ + *.tar.gz *.zip *.sigstore \ + --repo "${GITHUB_REPOSITORY}" + shell: bash diff --git a/.gitignore b/.gitignore index a671fe2cf..56f0a3153 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ core obj/ benchlog.* +user.bazelrc diff --git a/BUILD.bazel b/BUILD.bazel index ffe56c0c5..643d71f3f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -42,7 +42,6 @@ cc_library( "re2/unicode_groups.cc", "re2/unicode_groups.h", "re2/walker-inl.h", - "util/logging.h", "util/rune.cc", "util/strutil.cc", "util/strutil.h", @@ -58,6 +57,7 @@ cc_library( # WebAssembly support for threads is... fraught at every level. "@platforms//cpu:wasm32": [], "@platforms//cpu:wasm64": [], + "@platforms//os:emscripten": [], "@platforms//os:wasi": [], "@platforms//os:windows": [], "//conditions:default": ["-pthread"], @@ -70,23 +70,27 @@ cc_library( # WebAssembly support for threads is... fraught at every level. "@platforms//cpu:wasm32": [], "@platforms//cpu:wasm64": [], + "@platforms//os:emscripten": [], "@platforms//os:wasi": [], "@platforms//os:windows": [], "//conditions:default": ["-pthread"], }), visibility = ["//visibility:public"], deps = [ - "@com_google_absl//absl/base", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/container:fixed_array", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/container:inlined_vector", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/synchronization", - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/types:span", + "@abseil-cpp//absl/base", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/container:fixed_array", + "@abseil-cpp//absl/container:flat_hash_map", + "@abseil-cpp//absl/container:flat_hash_set", + "@abseil-cpp//absl/container:inlined_vector", + "@abseil-cpp//absl/hash", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:str_format", + "@abseil-cpp//absl/synchronization", + "@abseil-cpp//absl/types:optional", + "@abseil-cpp//absl/types:span", ], ) @@ -123,18 +127,20 @@ cc_library( "re2/unicode_casefold.h", "re2/unicode_groups.h", "re2/walker-inl.h", - "util/logging.h", "util/strutil.h", "util/utf.h", ], visibility = [":__subpackages__"], deps = [ ":re2", - "@com_google_absl//absl/base", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", + "@abseil-cpp//absl/base", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/container:flat_hash_set", + "@abseil-cpp//absl/flags:flag", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:str_format", "@googletest//:gtest", ], ) @@ -145,8 +151,8 @@ cc_test( srcs = ["re2/testing/charclass_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/strings:str_format", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/strings:str_format", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -158,7 +164,10 @@ cc_test( srcs = ["re2/testing/compile_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/strings", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -171,7 +180,9 @@ cc_test( deps = [ ":re2", ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -183,7 +194,9 @@ cc_test( srcs = ["re2/testing/mimics_pcre_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -195,7 +208,9 @@ cc_test( srcs = ["re2/testing/parse_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -208,8 +223,10 @@ cc_test( deps = [ ":re2", ":testing", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/strings", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/strings", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -222,7 +239,10 @@ cc_test( deps = [ ":re2", ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/types:optional", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -235,8 +255,11 @@ cc_test( deps = [ ":re2", ":testing", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/strings:str_format", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:str_format", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -248,6 +271,8 @@ cc_test( srcs = ["re2/testing/regexp_test.cc"], deps = [ ":testing", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -259,7 +284,9 @@ cc_test( srcs = ["re2/testing/required_prefix_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -271,7 +298,7 @@ cc_test( srcs = ["re2/testing/search_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -284,6 +311,8 @@ cc_test( deps = [ ":re2", ":testing", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -295,7 +324,9 @@ cc_test( srcs = ["re2/testing/simplify_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/base:core_headers", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -307,6 +338,7 @@ cc_test( srcs = ["re2/testing/string_generator_test.cc"], deps = [ ":testing", + "@abseil-cpp//absl/strings", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -319,9 +351,12 @@ cc_test( deps = [ ":re2", ":testing", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/strings:str_format", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/flags:flag", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:str_format", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -377,8 +412,8 @@ cc_test( srcs = ["re2/testing/random_test.cc"], deps = [ ":testing", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/strings:str_format", + "@abseil-cpp//absl/flags:flag", + "@abseil-cpp//absl/strings:str_format", "@googletest//:gtest", "@googletest//:gtest_main", ], @@ -391,10 +426,13 @@ cc_binary( deps = [ ":re2", ":testing", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/synchronization", + "@abseil-cpp//absl/container:flat_hash_map", + "@abseil-cpp//absl/flags:flag", + "@abseil-cpp//absl/log:absl_check", + "@abseil-cpp//absl/log:absl_log", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:str_format", + "@abseil-cpp//absl/synchronization", "@google_benchmark//:benchmark_main", ], ) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdac5afd6..a2ade77a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,12 +60,15 @@ if(UNIX) endif() set(ABSL_DEPS + absl_absl_check + absl_absl_log absl_base absl_core_headers absl_fixed_array absl_flags absl_flat_hash_map absl_flat_hash_set + absl_hash absl_inlined_vector absl_optional absl_span @@ -150,7 +153,9 @@ if(UNIX) endif() foreach(dep ${ABSL_DEPS}) - string(REGEX REPLACE "^absl_" "absl::" dep ${dep}) + # Work around https://gitlab.kitware.com/cmake/cmake/-/issues/16899. >:( + string(PREPEND dep "^") + string(REGEX REPLACE "\\^absl_" "absl::" dep ${dep}) target_link_libraries(re2 PUBLIC ${dep}) endforeach() diff --git a/MODULE.bazel b/MODULE.bazel index f99fcd259..ab50c94aa 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,28 +6,24 @@ module( name = "re2", - version = "2024-02-01", + version = "2024-07-02", compatibility_level = 1, ) -bazel_dep(name = "platforms", version = "0.0.8") -bazel_dep(name = "apple_support", version = "1.11.1", repo_name = "build_bazel_apple_support") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "apple_support", version = "1.15.1") bazel_dep(name = "rules_cc", version = "0.0.9") -bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "com_google_absl") -bazel_dep(name = "rules_python", version = "0.29.0") -bazel_dep(name = "pybind11_bazel", version = "2.11.1.bzl.1") +bazel_dep(name = "abseil-cpp", version = "20240116.2") +bazel_dep(name = "rules_python", version = "0.33.2") +bazel_dep(name = "pybind11_bazel", version = "2.12.0") # This is a temporary hack for `x64_x86_windows`. # TODO(junyer): Remove whenever no longer needed. cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") use_repo(cc_configure, "local_config_cc") -python_configure = use_extension("@pybind11_bazel//:python_configure.bzl", "extension") -python_configure.toolchain(python_version = "3") # ignored when non-root module -use_repo(python_configure, "local_config_python", "pybind11") - # These dependencies will be ignored when the `re2` module is not # the root module (or when `--ignore_dev_dependency` is enabled). -bazel_dep(name = "google_benchmark", version = "1.8.3", dev_dependency = True) +bazel_dep(name = "google_benchmark", version = "1.8.4", dev_dependency = True) bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True) -bazel_dep(name = "abseil-py", version = "1.4.0", dev_dependency = True) +bazel_dep(name = "abseil-py", version = "2.1.0", dev_dependency = True) diff --git a/Makefile b/Makefile index 017ab5567..e01529b2e 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,15 @@ # Build against Abseil. ABSL_DEPS=\ + absl_absl_check\ + absl_absl_log\ absl_base\ absl_core_headers\ absl_fixed_array\ absl_flags\ absl_flat_hash_map\ absl_flat_hash_set\ + absl_hash\ absl_inlined_vector\ absl_optional\ absl_span\ @@ -29,6 +32,13 @@ LDABSL=$(shell $(PKG_CONFIG) $(ABSL_DEPS) --libs | sed -e 's/-Wl / /g') # CCICU=$(shell $(PKG_CONFIG) icu-uc --cflags) -DRE2_USE_ICU # LDICU=$(shell $(PKG_CONFIG) icu-uc --libs) +# Build against GoogleTest and Benchmark for... testing and benchmarking. +# Capture only the `-L` flags for now; we will pass the `-l` flags later. +CCGTEST=$(shell $(PKG_CONFIG) gtest gtest_main --cflags) +LDGTEST=$(shell $(PKG_CONFIG) gtest gtest_main --libs-only-L) +CCBENCHMARK=$(shell $(PKG_CONFIG) benchmark --cflags) +LDBENCHMARK=$(shell $(PKG_CONFIG) benchmark --libs-only-L) + # To build against PCRE for testing and benchmarking, # uncomment the next two lines: # CCPCRE=-I/usr/local/include -DUSEPCRE @@ -39,8 +49,8 @@ CXX?=g++ CXXFLAGS?=-O3 -g LDFLAGS?= # required -RE2_CXXFLAGS?=-pthread -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. $(CCABSL) $(CCICU) $(CCPCRE) -RE2_LDFLAGS?=-pthread $(LDABSL) $(LDICU) $(LDPCRE) +RE2_CXXFLAGS?=-pthread -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. $(CCABSL) $(CCICU) $(CCGTEST) $(CCBENCHMARK) $(CCPCRE) +RE2_LDFLAGS?=-pthread $(LDABSL) $(LDICU) $(LDGTEST) $(LDBENCHMARK) $(LDPCRE) AR?=ar ARFLAGS?=rsc NM?=nm @@ -106,7 +116,6 @@ INSTALL_HFILES=\ re2/stringpiece.h\ HFILES=\ - util/logging.h\ util/malloc_counter.h\ util/pcre.h\ util/strutil.h\ @@ -233,22 +242,22 @@ obj/so/libre2.$(SOEXT): $(SOFILES) libre2.symbols libre2.symbols.darwin .PRECIOUS: obj/dbg/test/% obj/dbg/test/%: obj/dbg/libre2.a obj/dbg/re2/testing/%.o $(DTESTOFILES) @mkdir -p obj/dbg/test - $(CXX) -o $@ obj/dbg/re2/testing/$*.o $(DTESTOFILES) -lgtest -lgtest_main obj/dbg/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/dbg/re2/testing/$*.o $(DTESTOFILES) obj/dbg/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) -lgtest -lgtest_main .PRECIOUS: obj/test/% obj/test/%: obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) @mkdir -p obj/test - $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) -lgtest -lgtest_main obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) -lgtest -lgtest_main # Test the shared lib, falling back to the static lib for private symbols .PRECIOUS: obj/so/test/% obj/so/test/%: obj/so/libre2.$(SOEXT) obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) @mkdir -p obj/so/test - $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) -lgtest -lgtest_main -Lobj/so -lre2 obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) -Lobj/so -lre2 obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) -lgtest -lgtest_main obj/test/regexp_benchmark: obj/libre2.a obj/re2/testing/regexp_benchmark.o $(TESTOFILES) @mkdir -p obj/test - $(CXX) -o $@ obj/re2/testing/regexp_benchmark.o $(TESTOFILES) -lgtest -lbenchmark -lbenchmark_main obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) + $(CXX) -o $@ obj/re2/testing/regexp_benchmark.o $(TESTOFILES) obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS) -lgtest -lbenchmark -lbenchmark_main obj/test/re2_fuzzer: obj/libre2.a obj/re2/fuzzing/re2_fuzzer.o @mkdir -p obj/test diff --git a/README b/README index 469d6f397..21a4358c8 100644 --- a/README +++ b/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/app/build.sh b/app/build.sh index a46374446..c8a2ae50e 100755 --- a/app/build.sh +++ b/app/build.sh @@ -7,9 +7,9 @@ DSTDIR=$(mktemp --directory --tmpdir $(basename $0).XXXXXXXXXX) cd ${SRCDIR} # Emscripten doesn't support `-fstack-protector`. AR=emar CC=emcc \ - bazel build --compilation_mode=opt \ + bazel build \ --copt=-fno-stack-protector \ - -- :all + --compilation_mode=opt -- :all cp ../bazel-bin/app/_re2.js ${DSTDIR} bazel clean --expunge cp app.ts index.html _re2.d.ts ${DSTDIR} diff --git a/doc/mksyntaxgo b/doc/mksyntaxgo index 1a09b87cc..10a253efa 100755 --- a/doc/mksyntaxgo +++ b/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/python/BUILD.bazel b/python/BUILD.bazel index 48d7d3f58..74b7339a5 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -12,14 +12,14 @@ pybind_extension( srcs = ["_re2.cc"], deps = [ "//:re2", - "@com_google_absl//absl/strings", + "@abseil-cpp//absl/strings", ], ) py_library( name = "re2", srcs = ["re2.py"], - data = [":_re2.so"], + data = [":_re2"], imports = ["."], visibility = ["//visibility:public"], ) diff --git a/python/_re2.cc b/python/_re2.cc index 8564f8a4f..22f092b23 100644 --- a/python/_re2.cc +++ b/python/_re2.cc @@ -2,15 +2,22 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include +#include + #include +#include #include #include #include #include -#include -#include #include "absl/strings/string_view.h" +#include "pybind11/buffer_info.h" +#include "pybind11/gil.h" +#include "pybind11/pybind11.h" +#include "pybind11/pytypes.h" +#include "pybind11/stl.h" // IWYU pragma: keep #include "re2/filtered_re2.h" #include "re2/re2.h" #include "re2/set.h" @@ -219,6 +226,10 @@ class Filter { } std::vector 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 atoms; @@ -243,6 +254,9 @@ class Filter { }; PYBIND11_MODULE(_re2, module) { + // Translate exceptions thrown by py::pybind11_fail() into Python. + py::register_local_exception(module, "Error"); + module.def("CharLenToBytes", &CharLenToBytes); module.def("BytesToCharLen", &BytesToCharLen); diff --git a/python/re2.py b/python/re2.py index 8a6d98539..d5023e767 100644 --- a/python/re2.py +++ b/python/re2.py @@ -33,8 +33,9 @@ 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/python/re2_test.py b/python/re2_test.py index 86aa9ae51..df1a9eb70 100644 --- a/python/re2_test.py +++ b/python/re2_test.py @@ -477,6 +477,13 @@ def test_match(self): # 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/python/setup.py b/python/setup.py index df65415ee..a67509b3f 100644 --- a/python/setup.py +++ b/python/setup.py @@ -3,10 +3,10 @@ # license that can be found in the LICENSE file. import os +import re import setuptools import setuptools.command.build_ext import shutil -import sys long_description = r"""A drop-in replacement for the re module. @@ -48,9 +48,6 @@ def build_extension(self, ext): if 'GITHUB_ACTIONS' not in os.environ: return super().build_extension(ext) - # For @pybind11_bazel's `python_configure()`. - os.environ['PYTHON_BIN_PATH'] = sys.executable - cmd = ['bazel', 'build'] try: cpu = os.environ['BAZEL_CPU'] @@ -63,10 +60,13 @@ def build_extension(self, ext): cmd.append(f'--extra_toolchains=@local_config_cc//:cc-toolchain-{cpu}') except KeyError: pass - # Register the local Python toolchain with highest priority. - cmd.append('--extra_toolchains=@local_config_python//:py_toolchain') - # Print debug information during toolchain resolution. - cmd.append('--toolchain_resolution_debug=.*') + try: + ver = os.environ['MACOSX_DEPLOYMENT_TARGET'] + cmd.append(f'--macos_minimum_os={ver}') + except KeyError: + pass + # Register the local Python toolchains with highest priority. + cmd.append('--extra_toolchains=//python/toolchains:all') cmd += ['--compilation_mode=opt', '--', ':all'] self.spawn(cmd) @@ -104,25 +104,55 @@ def include_dirs(): extra_compile_args=['-fvisibility=hidden'], ) -setuptools.setup( - name='google-re2', - version='1.1', - description='RE2 Python bindings', - long_description=long_description, - long_description_content_type='text/plain', - author='The RE2 Authors', - author_email='re2-dev@googlegroups.com', - url='https://github.com/google/re2', - py_modules=['re2'], - ext_modules=[ext_module], - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Programming Language :: C++', - 'Programming Language :: Python :: 3.8', - ], - options=options(), - cmdclass={'build_ext': BuildExt}, - python_requires='~=3.8', -) +# We need `re2` to be a package, not a module, because it appears that +# modules can't have `.pyi` files, so munge the module into a package. +PACKAGE = 're2' +try: + # If we are building from the sdist, we are already in package form. + if not os.path.exists('PKG-INFO'): + os.makedirs(PACKAGE) + for filename in ( + 're2.py', + # TODO(junyer): Populate as per https://github.com/google/re2/issues/496. + # 're2.pyi', + # '_re2.pyi', + ): + with open(filename, 'r') as file: + contents = file.read() + filename = re.sub(r'^re2(?=\.py)', '__init__', filename) + contents = re.sub(r'^(?=import _)', 'from . ', contents, flags=re.MULTILINE) + with open(f'{PACKAGE}/{filename}', 'x') as file: + file.write(contents) + # TODO(junyer): Populate as per https://github.com/google/re2/issues/496. + # with open(f'{PACKAGE}/py.typed', 'x') as file: + # pass + + setuptools.setup( + name='google-re2', + version='1.1.20240702', + description='RE2 Python bindings', + long_description=long_description, + long_description_content_type='text/plain', + author='The RE2 Authors', + author_email='re2-dev@googlegroups.com', + url='https://github.com/google/re2', + packages=[PACKAGE], + ext_package=PACKAGE, + ext_modules=[ext_module], + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Programming Language :: C++', + 'Programming Language :: Python :: 3.8', + ], + options=options(), + cmdclass={'build_ext': BuildExt}, + python_requires='~=3.8', + ) +except: + raise +else: + # If we are building from the sdist, we are already in package form. + if not os.path.exists('PKG-INFO'): + shutil.rmtree(PACKAGE) diff --git a/python/toolchains/generate.py b/python/toolchains/generate.py new file mode 100644 index 000000000..84fef7800 --- /dev/null +++ b/python/toolchains/generate.py @@ -0,0 +1,98 @@ +# Copyright 2019 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. + +import os +import shutil +import sys +import sysconfig + + +def generate(): + include = sysconfig.get_path('include') + libs = os.path.join(include, '../libs') + + mydir = os.path.dirname(sys.argv[0]) or '.' + shutil.copytree(include, f'{mydir}/include') + try: + shutil.copytree(libs, f'{mydir}/libs') + except FileNotFoundError: + # We must not be running on Windows. :) + pass + + with open(f'{mydir}/BUILD.bazel', 'x') as file: + file.write( + """\ +load("@rules_python//python/cc:py_cc_toolchain.bzl", "py_cc_toolchain") +load("@rules_python//python:py_runtime.bzl", "py_runtime") +load("@rules_python//python:py_runtime_pair.bzl", "py_runtime_pair") + +package(default_visibility = ["//visibility:public"]) + +toolchain( + name = "py", + toolchain = ":py_toolchain", + toolchain_type = "@rules_python//python:toolchain_type", +) + +py_runtime_pair( + name = "py_toolchain", + py3_runtime = ":interpreter", +) + +py_runtime( + name = "interpreter", + interpreter_path = "{interpreter_path}", + interpreter_version_info = {{ + "major": "{major}", + "minor": "{minor}", + }}, + python_version = "PY3", +) + +toolchain( + name = "py_cc", + toolchain = ":py_cc_toolchain", + toolchain_type = "@rules_python//python/cc:toolchain_type", +) + +py_cc_toolchain( + name = "py_cc_toolchain", + headers = ":headers", + libs = ":libraries", + python_version = "{major}.{minor}", +) + +cc_library( + name = "headers", + hdrs = glob(["include/**/*.h"]), + includes = ["include"], + deps = select({{ + "@platforms//os:windows": [":interface_library"], + "//conditions:default": [], + }}), +) + +cc_import( + name = "interface_library", + interface_library = select({{ + "@platforms//os:windows": "libs/python{major}{minor}.lib", + "//conditions:default": None, + }}), + system_provided = True, +) + +# Not actually necessary for our purposes. :) +cc_library( + name = "libraries", +) +""".format( + interpreter_path=sys.executable.replace('\\', '/'), + major=sys.version_info.major, + minor=sys.version_info.minor, + ) + ) + + +if __name__ == '__main__': + generate() diff --git a/re2/bitmap256.cc b/re2/bitmap256.cc index f6fbca304..4b9eee430 100644 --- a/re2/bitmap256.cc +++ b/re2/bitmap256.cc @@ -6,14 +6,14 @@ #include -#include "absl/base/macros.h" -#include "util/logging.h" +#include "absl/base/attributes.h" +#include "absl/log/absl_check.h" namespace re2 { int Bitmap256::FindNextSetBit(int c) const { - DCHECK_GE(c, 0); - DCHECK_LE(c, 255); + ABSL_DCHECK_GE(c, 0); + ABSL_DCHECK_LE(c, 255); // Check the word that contains the bit. Mask out any lower bits. int i = c / 64; diff --git a/re2/bitmap256.h b/re2/bitmap256.h index 293b31d85..e303e7155 100644 --- a/re2/bitmap256.h +++ b/re2/bitmap256.h @@ -5,13 +5,15 @@ #ifndef RE2_BITMAP256_H_ #define RE2_BITMAP256_H_ -#ifdef _MSC_VER -#include -#endif #include #include -#include "util/logging.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" + +#ifdef _MSC_VER +#include +#endif namespace re2 { @@ -28,16 +30,16 @@ class Bitmap256 { // Tests the bit with index c. bool Test(int c) const { - DCHECK_GE(c, 0); - DCHECK_LE(c, 255); + ABSL_DCHECK_GE(c, 0); + ABSL_DCHECK_LE(c, 255); return (words_[c / 64] & (uint64_t{1} << (c % 64))) != 0; } // Sets the bit with index c. void Set(int c) { - DCHECK_GE(c, 0); - DCHECK_LE(c, 255); + ABSL_DCHECK_GE(c, 0); + ABSL_DCHECK_LE(c, 255); words_[c / 64] |= (uint64_t{1} << (c % 64)); } @@ -49,7 +51,7 @@ class Bitmap256 { private: // Finds the least significant non-zero bit in n. static int FindLSBSet(uint64_t n) { - DCHECK_NE(n, 0); + ABSL_DCHECK_NE(n, uint64_t{0}); #if defined(__GNUC__) return __builtin_ctzll(n); #elif defined(_MSC_VER) && defined(_M_X64) diff --git a/re2/bitstate.cc b/re2/bitstate.cc index 38a0b87cc..71f41c383 100644 --- a/re2/bitstate.cc +++ b/re2/bitstate.cc @@ -20,10 +20,13 @@ #include #include #include + #include #include -#include "util/logging.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/prog.h" #include "re2/regexp.h" @@ -107,9 +110,9 @@ void BitState::Push(int id, const char* p) { if (njob_ >= job_.size()) { GrowStack(); if (njob_ >= job_.size()) { - LOG(DFATAL) << "GrowStack() failed: " - << "njob_ = " << njob_ << ", " - << "job_.size() = " << job_.size(); + ABSL_LOG(DFATAL) << "GrowStack() failed: " + << "njob_ = " << njob_ << ", " + << "job_.size() = " << job_.size(); return; } } @@ -167,7 +170,7 @@ bool BitState::TrySearch(int id0, const char* p0) { Prog::Inst* ip = prog_->inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "Unexpected opcode: " << ip->opcode(); + ABSL_LOG(DFATAL) << "Unexpected opcode: " << ip->opcode(); return false; case kInstFail: @@ -233,7 +236,7 @@ bool BitState::TrySearch(int id0, const char* p0) { CheckAndLoop: // Sanity check: id is the head of its list, which must // be the case if id-1 is the last of *its* list. :) - DCHECK(id == 0 || prog_->inst(id-1)->last()); + ABSL_DCHECK(id == 0 || prog_->inst(id-1)->last()); if (ShouldVisit(id, p)) goto Loop; break; diff --git a/re2/compile.cc b/re2/compile.cc index aa798872e..95c1b32dd 100644 --- a/re2/compile.cc +++ b/re2/compile.cc @@ -10,17 +10,20 @@ #include #include + +#include #include -#include "absl/base/macros.h" #include "absl/container/flat_hash_map.h" -#include "util/logging.h" -#include "util/utf.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/prog.h" #include "re2/re2.h" #include "re2/regexp.h" #include "re2/walker-inl.h" +#include "util/utf.h" namespace re2 { @@ -522,8 +525,8 @@ void Compiler::AddSuffix(int id) { } int Compiler::AddSuffixRecursive(int root, int id) { - DCHECK(inst_[root].opcode() == kInstAlt || - inst_[root].opcode() == kInstByteRange); + ABSL_DCHECK(inst_[root].opcode() == kInstAlt || + inst_[root].opcode() == kInstByteRange); Frag f = FindByteRange(root, id); if (IsNoMatch(f)) { @@ -565,7 +568,7 @@ int Compiler::AddSuffixRecursive(int root, int id) { if (!IsCachedRuneByteSuffix(id)) { // The head should be the instruction most recently allocated, so free it // instead of leaving it unreachable. - DCHECK_EQ(id, ninst_-1); + ABSL_DCHECK_EQ(id, ninst_-1); inst_[id].out_opcode_ = 0; inst_[id].out1_ = 0; ninst_--; @@ -613,7 +616,7 @@ Frag Compiler::FindByteRange(int root, int id) { return NoMatch(); } - LOG(DFATAL) << "should never happen"; + ABSL_LOG(DFATAL) << "should never happen"; return NoMatch(); } @@ -738,7 +741,7 @@ void Compiler::AddRuneRangeUTF8(Rune lo, Rune hi, bool foldcase) { int n = runetochar(reinterpret_cast(ulo), &lo); int m = runetochar(reinterpret_cast(uhi), &hi); (void)m; // USED(m) - DCHECK_EQ(n, m); + ABSL_DCHECK_EQ(n, m); // The logic below encodes this thinking: // @@ -791,7 +794,7 @@ void Compiler::AddRuneRangeUTF8(Rune lo, Rune hi, bool foldcase) { Frag Compiler::Copy(Frag arg) { // We're using WalkExponential; there should be no copying. failed_ = true; - LOG(DFATAL) << "Compiler::Copy called!"; + ABSL_LOG(DFATAL) << "Compiler::Copy called!"; return NoMatch(); } @@ -918,7 +921,7 @@ Frag Compiler::PostVisit(Regexp* re, Frag, Frag, Frag* child_frags, if (cc->empty()) { // This can't happen. failed_ = true; - LOG(DFATAL) << "No ranges in char class"; + ABSL_LOG(DFATAL) << "No ranges in char class"; return NoMatch(); } @@ -976,7 +979,7 @@ Frag Compiler::PostVisit(Regexp* re, Frag, Frag, Frag* child_frags, return EmptyWidth(kEmptyNonWordBoundary); } failed_ = true; - LOG(DFATAL) << "Missing case in Compiler: " << re->op(); + ABSL_LOG(DFATAL) << "Missing case in Compiler: " << re->op(); return NoMatch(); } diff --git a/re2/dfa.cc b/re2/dfa.cc index e35fcb281..1619614ea 100644 --- a/re2/dfa.cc +++ b/re2/dfa.cc @@ -25,28 +25,32 @@ #include #include #include + #include #include #include -#include +#include #include #include #include +#include "absl/base/attributes.h" #include "absl/base/call_once.h" -#include "absl/base/macros.h" #include "absl/base/thread_annotations.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "absl/hash/hash.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/span.h" -#include "util/logging.h" -#include "util/strutil.h" #include "re2/pod_array.h" #include "re2/prog.h" #include "re2/re2.h" #include "re2/sparse_set.h" +#include "util/strutil.h" // Silence "zero-sized array in struct/union" warning for DFA::State::next_. #ifdef _MSC_VER @@ -149,15 +153,15 @@ class DFA { struct StateHash { size_t operator()(const State* a) const { - DCHECK(a != NULL); + ABSL_DCHECK(a != NULL); return absl::Hash()(*a); } }; struct StateEqual { bool operator()(const State* a, const State* b) const { - DCHECK(a != NULL); - DCHECK(b != NULL); + ABSL_DCHECK(a != NULL); + ABSL_DCHECK(b != NULL); return *a == *b; } }; @@ -659,7 +663,7 @@ DFA::State* DFA::WorkqToCachedState(Workq* q, Workq* mq, uint32_t flag) { break; } } - DCHECK_LE(n, q->size()); + ABSL_DCHECK_LE(n, q->size()); if (n > 0 && inst[n-1] == Mark) n--; @@ -847,7 +851,7 @@ void DFA::AddToQueue(Workq* q, int id, uint32_t flag) { stk[nstk++] = id; while (nstk > 0) { - DCHECK_LE(nstk, stack_.size()); + ABSL_DCHECK_LE(nstk, stack_.size()); id = stk[--nstk]; Loop: @@ -872,7 +876,7 @@ void DFA::AddToQueue(Workq* q, int id, uint32_t flag) { Prog::Inst* ip = prog_->inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); + ABSL_LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); break; case kInstByteRange: // just save these on the queue @@ -898,7 +902,7 @@ void DFA::AddToQueue(Workq* q, int id, uint32_t flag) { goto Loop; case kInstAltMatch: - DCHECK(!ip->last()); + ABSL_DCHECK(!ip->last()); id = id+1; goto Loop; @@ -961,7 +965,7 @@ void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq, Prog::Inst* ip = prog_->inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); + ABSL_LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); break; case kInstFail: // never succeeds @@ -1029,14 +1033,14 @@ DFA::State* DFA::RunStateOnByte(State* state, int c) { return FullMatchState; } if (state == DeadState) { - LOG(DFATAL) << "DeadState in RunStateOnByte"; + ABSL_LOG(DFATAL) << "DeadState in RunStateOnByte"; return NULL; } if (state == NULL) { - LOG(DFATAL) << "NULL state in RunStateOnByte"; + ABSL_LOG(DFATAL) << "NULL state in RunStateOnByte"; return NULL; } - LOG(DFATAL) << "Unexpected special state in RunStateOnByte"; + ABSL_LOG(DFATAL) << "Unexpected special state in RunStateOnByte"; return NULL; } @@ -1267,7 +1271,7 @@ DFA::State* DFA::StateSaver::Restore() { absl::MutexLock l(&dfa_->mutex_); State* s = dfa_->CachedState(inst_, ninst_, flag_); if (s == NULL) - LOG(DFATAL) << "StateSaver failed to restore state."; + ABSL_LOG(DFATAL) << "StateSaver failed to restore state."; return s; } @@ -1451,13 +1455,13 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params) { // Restore start and s so we can continue. if ((start = save_start.Restore()) == NULL || (s = save_s.Restore()) == NULL) { - // Restore already did LOG(DFATAL). + // Restore already did ABSL_LOG(DFATAL). params->failed = true; return false; } ns = RunStateOnByteUnlocked(s, c); if (ns == NULL) { - LOG(DFATAL) << "RunStateOnByteUnlocked failed after ResetCache"; + ABSL_LOG(DFATAL) << "RunStateOnByteUnlocked failed after ResetCache"; params->failed = true; return false; } @@ -1529,7 +1533,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params) { } ns = RunStateOnByteUnlocked(s, lastbyte); if (ns == NULL) { - LOG(DFATAL) << "RunStateOnByteUnlocked failed after Reset"; + ABSL_LOG(DFATAL) << "RunStateOnByteUnlocked failed after Reset"; params->failed = true; return false; } @@ -1646,7 +1650,7 @@ bool DFA::AnalyzeSearch(SearchParams* params) { // Sanity check: make sure that text lies within context. if (BeginPtr(text) < BeginPtr(context) || EndPtr(text) > EndPtr(context)) { - LOG(DFATAL) << "context does not contain text"; + ABSL_LOG(DFATAL) << "context does not contain text"; params->start = DeadState; return true; } @@ -1694,7 +1698,7 @@ bool DFA::AnalyzeSearch(SearchParams* params) { ResetCache(params->cache_lock); if (!AnalyzeSearchHelper(params, info, flags)) { params->failed = true; - LOG(DFATAL) << "Failed to analyze start state."; + ABSL_LOG(DFATAL) << "Failed to analyze start state."; return false; } } @@ -1768,7 +1772,7 @@ bool DFA::Search(absl::string_view text, absl::string_view context, params.want_earliest_match = want_earliest_match; params.run_forward = run_forward; // matches should be null except when using RE2::Set. - DCHECK(matches == NULL || kind_ == Prog::kManyMatch); + ABSL_DCHECK(matches == NULL || kind_ == Prog::kManyMatch); params.matches = matches; if (!AnalyzeSearch(¶ms)) { diff --git a/re2/filtered_re2.cc b/re2/filtered_re2.cc index 49cf68601..f0995a10b 100644 --- a/re2/filtered_re2.cc +++ b/re2/filtered_re2.cc @@ -5,10 +5,13 @@ #include "re2/filtered_re2.h" #include + #include #include +#include -#include "util/logging.h" +#include "absl/log/absl_log.h" +#include "absl/strings/string_view.h" #include "re2/prefilter.h" #include "re2/prefilter_tree.h" @@ -52,8 +55,8 @@ RE2::ErrorCode FilteredRE2::Add(absl::string_view pattern, if (!re->ok()) { if (options.log_errors()) { - LOG(ERROR) << "Couldn't compile regular expression, skipping: " - << pattern << " due to error " << re->error(); + ABSL_LOG(ERROR) << "Couldn't compile regular expression, skipping: " + << pattern << " due to error " << re->error(); } delete re; } else { @@ -66,12 +69,13 @@ RE2::ErrorCode FilteredRE2::Add(absl::string_view pattern, void FilteredRE2::Compile(std::vector* atoms) { if (compiled_) { - LOG(ERROR) << "Compile called already."; + ABSL_LOG(ERROR) << "Compile called already."; 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; } @@ -94,7 +98,7 @@ int FilteredRE2::SlowFirstMatch(absl::string_view text) const { int FilteredRE2::FirstMatch(absl::string_view text, const std::vector& atoms) const { if (!compiled_) { - LOG(DFATAL) << "FirstMatch called before Compile."; + ABSL_LOG(DFATAL) << "FirstMatch called before Compile."; return -1; } std::vector regexps; diff --git a/re2/fuzzing/re2_fuzzer.cc b/re2/fuzzing/re2_fuzzer.cc index 9a7af08a7..8a8c2acc8 100644 --- a/re2/fuzzing/re2_fuzzer.cc +++ b/re2/fuzzing/re2_fuzzer.cc @@ -5,10 +5,12 @@ #include #include #include + #include #include #include +#include "absl/strings/string_view.h" #include "re2/filtered_re2.h" #include "re2/re2.h" #include "re2/regexp.h" diff --git a/re2/mimics_pcre.cc b/re2/mimics_pcre.cc index ac0c69d7e..172406366 100644 --- a/re2/mimics_pcre.cc +++ b/re2/mimics_pcre.cc @@ -22,7 +22,7 @@ // // Regexp::MimicsPCRE checks for any of these conditions. -#include "util/logging.h" +#include "absl/log/absl_log.h" #include "re2/regexp.h" #include "re2/walker-inl.h" @@ -44,7 +44,7 @@ class PCREWalker : public Regexp::Walker { virtual bool ShortVisit(Regexp* re, bool a) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "PCREWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "PCREWalker::ShortVisit called"; #endif return a; } @@ -128,7 +128,7 @@ class EmptyStringWalker : public Regexp::Walker { virtual bool ShortVisit(Regexp* re, bool a) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "EmptyStringWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "EmptyStringWalker::ShortVisit called"; #endif return a; } diff --git a/re2/nfa.cc b/re2/nfa.cc index a655884d7..a35976f25 100644 --- a/re2/nfa.cc +++ b/re2/nfa.cc @@ -26,14 +26,16 @@ #include #include + #include #include #include #include -#include +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" -#include "util/logging.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/prog.h" #include "re2/regexp.h" @@ -172,17 +174,17 @@ NFA::Thread* NFA::AllocThread() { } NFA::Thread* NFA::Incref(Thread* t) { - DCHECK(t != NULL); + ABSL_DCHECK(t != NULL); t->ref++; return t; } void NFA::Decref(Thread* t) { - DCHECK(t != NULL); + ABSL_DCHECK(t != NULL); t->ref--; if (t->ref > 0) return; - DCHECK_EQ(t->ref, 0); + ABSL_DCHECK_EQ(t->ref, 0); t->next = freelist_; freelist_ = t; } @@ -208,7 +210,7 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, absl::string_view context, stk[nstk++] = {id0, NULL}; while (nstk > 0) { - DCHECK_LE(nstk, stack_.size()); + ABSL_DCHECK_LE(nstk, stack_.size()); AddState a = stk[--nstk]; Loop: @@ -238,7 +240,7 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, absl::string_view context, Prog::Inst* ip = prog_->inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled " << ip->opcode() << " in AddToThreadq"; + ABSL_LOG(DFATAL) << "unhandled " << ip->opcode() << " in AddToThreadq"; break; case kInstFail: @@ -249,7 +251,7 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, absl::string_view context, t = Incref(t0); *tp = t; - DCHECK(!ip->last()); + ABSL_DCHECK(!ip->last()); a = {id+1, NULL}; goto Loop; @@ -350,7 +352,7 @@ int NFA::Step(Threadq* runq, Threadq* nextq, int c, absl::string_view context, switch (ip->opcode()) { default: // Should only see the values handled below. - LOG(DFATAL) << "Unhandled " << ip->opcode() << " in step"; + ABSL_LOG(DFATAL) << "Unhandled " << ip->opcode() << " in step"; break; case kInstByteRange: @@ -455,7 +457,7 @@ bool NFA::Search(absl::string_view text, absl::string_view context, // Sanity check: make sure that text lies within context. if (BeginPtr(text) < BeginPtr(context) || EndPtr(text) > EndPtr(context)) { - LOG(DFATAL) << "context does not contain text"; + ABSL_LOG(DFATAL) << "context does not contain text"; return false; } @@ -470,7 +472,7 @@ bool NFA::Search(absl::string_view text, absl::string_view context, } if (nsubmatch < 0) { - LOG(DFATAL) << "Bad args: nsubmatch=" << nsubmatch; + ABSL_LOG(DFATAL) << "Bad args: nsubmatch=" << nsubmatch; return false; } @@ -527,7 +529,7 @@ bool NFA::Search(absl::string_view text, absl::string_view context, // This is a no-op the first time around the loop because runq is empty. int id = Step(runq, nextq, p < etext_ ? p[0] & 0xFF : -1, context, p); - DCHECK_EQ(runq->size(), 0); + ABSL_DCHECK_EQ(runq->size(), 0); using std::swap; swap(nextq, runq); nextq->clear(); @@ -538,7 +540,8 @@ bool NFA::Search(absl::string_view text, absl::string_view context, Prog::Inst* ip = prog_->inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "Unexpected opcode in short circuit: " << ip->opcode(); + ABSL_LOG(DFATAL) << "Unexpected opcode in short circuit: " + << ip->opcode(); break; case kInstCapture: @@ -599,7 +602,7 @@ bool NFA::Search(absl::string_view text, absl::string_view context, // This complements the special case in NFA::Step(). if (p == NULL) { (void) Step(runq, nextq, -1, context, p); - DCHECK_EQ(runq->size(), 0); + ABSL_DCHECK_EQ(runq->size(), 0); using std::swap; swap(nextq, runq); nextq->clear(); @@ -655,7 +658,7 @@ bool Prog::SearchNFA(absl::string_view text, absl::string_view context, // fanout holds the results and is also the work queue for the outer iteration. // reachable holds the reached nodes for the inner iteration. void Prog::Fanout(SparseArray* fanout) { - DCHECK_EQ(fanout->max_size(), size()); + ABSL_DCHECK_EQ(fanout->max_size(), size()); SparseSet reachable(size()); fanout->clear(); fanout->set_new(start(), 0); @@ -668,7 +671,8 @@ void Prog::Fanout(SparseArray* fanout) { Prog::Inst* ip = inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled " << ip->opcode() << " in Prog::Fanout()"; + ABSL_LOG(DFATAL) << "unhandled " << ip->opcode() + << " in Prog::Fanout()"; break; case kInstByteRange: @@ -682,7 +686,7 @@ void Prog::Fanout(SparseArray* fanout) { break; case kInstAltMatch: - DCHECK(!ip->last()); + ABSL_DCHECK(!ip->last()); reachable.insert(id+1); break; diff --git a/re2/onepass.cc b/re2/onepass.cc index 7931cf911..fb7f69431 100644 --- a/re2/onepass.cc +++ b/re2/onepass.cc @@ -52,19 +52,21 @@ #include #include + #include #include #include -#include #include "absl/container/fixed_array.h" #include "absl/container/inlined_vector.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" -#include "util/logging.h" -#include "util/utf.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/prog.h" #include "re2/sparse_set.h" +#include "util/utf.h" // Silence "zero-sized array in struct/union" warning for OneState::action. #ifdef _MSC_VER @@ -215,7 +217,7 @@ bool Prog::SearchOnePass(absl::string_view text, absl::string_view context, Anchor anchor, MatchKind kind, absl::string_view* match, int nmatch) { if (anchor != kAnchored && kind != kFullMatch) { - LOG(DFATAL) << "Cannot use SearchOnePass for unanchored matches."; + ABSL_LOG(DFATAL) << "Cannot use SearchOnePass for unanchored matches."; return false; } @@ -442,13 +444,13 @@ bool Prog::IsOnePass() { Prog::Inst* ip = inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); + ABSL_LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); break; case kInstAltMatch: // TODO(rsc): Ignoring kInstAltMatch optimization. // Should implement it in this engine, but it's subtle. - DCHECK(!ip->last()); + ABSL_DCHECK(!ip->last()); // If already on work queue, (1) is violated: bail out. if (!AddQ(&workq, id+1)) goto fail; @@ -460,7 +462,7 @@ bool Prog::IsOnePass() { if (nextindex == -1) { if (nalloc >= maxnodes) { if (ExtraDebug) - LOG(ERROR) << absl::StrFormat( + ABSL_LOG(ERROR) << absl::StrFormat( "Not OnePass: hit node limit %d >= %d", nalloc, maxnodes); goto fail; } @@ -485,7 +487,7 @@ bool Prog::IsOnePass() { node->action[b] = newact; } else if (act != newact) { if (ExtraDebug) - LOG(ERROR) << absl::StrFormat( + ABSL_LOG(ERROR) << absl::StrFormat( "Not OnePass: conflict on byte %#x at state %d", c, *it); goto fail; } @@ -506,7 +508,7 @@ bool Prog::IsOnePass() { node->action[b] = newact; } else if (act != newact) { if (ExtraDebug) - LOG(ERROR) << absl::StrFormat( + ABSL_LOG(ERROR) << absl::StrFormat( "Not OnePass: conflict on byte %#x at state %d", c, *it); goto fail; } @@ -547,7 +549,7 @@ bool Prog::IsOnePass() { // If already on work queue, (1) is violated: bail out. if (!AddQ(&workq, ip->out())) { if (ExtraDebug) - LOG(ERROR) << absl::StrFormat( + ABSL_LOG(ERROR) << absl::StrFormat( "Not OnePass: multiple paths %d -> %d", *it, ip->out()); goto fail; } @@ -558,7 +560,7 @@ bool Prog::IsOnePass() { if (matched) { // (3) is violated if (ExtraDebug) - LOG(ERROR) << absl::StrFormat( + ABSL_LOG(ERROR) << absl::StrFormat( "Not OnePass: multiple matches from %d", *it); goto fail; } @@ -579,9 +581,9 @@ bool Prog::IsOnePass() { } } - if (ExtraDebug) { // For debugging, dump one-pass NFA to LOG(ERROR). - LOG(ERROR) << "bytemap:\n" << DumpByteMap(); - LOG(ERROR) << "prog:\n" << Dump(); + if (ExtraDebug) { // For debugging, dump one-pass NFA to ABSL_LOG(ERROR). + ABSL_LOG(ERROR) << "bytemap:\n" << DumpByteMap(); + ABSL_LOG(ERROR) << "prog:\n" << Dump(); std::map idmap; for (int i = 0; i < size; i++) @@ -606,7 +608,7 @@ bool Prog::IsOnePass() { idmap[node->action[i] >> kIndexShift]); } } - LOG(ERROR) << "nodes:\n" << dump; + ABSL_LOG(ERROR) << "nodes:\n" << dump; } dfa_mem_ -= nalloc*statesize; diff --git a/re2/parse.cc b/re2/parse.cc index 904599280..6f7a5612f 100644 --- a/re2/parse.cc +++ b/re2/parse.cc @@ -16,24 +16,25 @@ // and recognizes the Perl escape sequences \d, \s, \w, \D, \S, and \W. // See regexp.h for rationale. -#include #include #include #include + #include -#include #include #include +#include "absl/base/attributes.h" #include "absl/base/macros.h" +#include "absl/log/absl_log.h" #include "absl/strings/ascii.h" -#include "util/logging.h" -#include "util/utf.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/regexp.h" #include "re2/unicode_casefold.h" #include "re2/unicode_groups.h" #include "re2/walker-inl.h" +#include "util/utf.h" #if defined(RE2_USE_ICU) #include "unicode/uniset.h" @@ -337,6 +338,20 @@ Rune CycleFoldRune(Rune r) { return ApplyFold(f, r); } +// Add lo-hi to the class, along with their fold-equivalent characters. +static void AddFoldedRangeLatin1(CharClassBuilder* cc, Rune lo, Rune hi) { + while (lo <= hi) { + cc->AddRange(lo, lo); + if ('A' <= lo && lo <= 'Z') { + cc->AddRange(lo - 'A' + 'a', lo - 'A' + 'a'); + } + if ('a' <= lo && lo <= 'z') { + cc->AddRange(lo - 'a' + 'A', lo - 'a' + 'A'); + } + lo++; + } +} + // Add lo-hi to the class, along with their fold-equivalent characters. // If lo-hi is already in the class, assume that the fold-equivalent // chars are there too, so there's no work to do. @@ -346,7 +361,7 @@ static void AddFoldedRange(CharClassBuilder* cc, Rune lo, Rune hi, int depth) { // current Unicode tables. make_unicode_casefold.py checks that // the cycles are not too long, and we double-check here using depth. if (depth > 10) { - LOG(DFATAL) << "AddFoldedRange recurses too much."; + ABSL_LOG(DFATAL) << "AddFoldedRange recurses too much."; return; } @@ -394,17 +409,26 @@ static void AddFoldedRange(CharClassBuilder* cc, Rune lo, Rune hi, int depth) { // Pushes the literal rune r onto the stack. bool Regexp::ParseState::PushLiteral(Rune r) { // Do case folding if needed. - if ((flags_ & FoldCase) && CycleFoldRune(r) != r) { - Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase); - re->ccb_ = new CharClassBuilder; - Rune r1 = r; - do { - if (!(flags_ & NeverNL) || r != '\n') { - re->ccb_->AddRange(r, r); - } - r = CycleFoldRune(r); - } while (r != r1); - return PushRegexp(re); + if (flags_ & FoldCase) { + if (flags_ & Latin1 && (('A' <= r && r <= 'Z') || + ('a' <= r && r <= 'z'))) { + Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase); + re->ccb_ = new CharClassBuilder; + AddFoldedRangeLatin1(re->ccb_, r, r); + return PushRegexp(re); + } + if (!(flags_ & Latin1) && CycleFoldRune(r) != r) { + Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase); + re->ccb_ = new CharClassBuilder; + Rune r1 = r; + do { + if (!(flags_ & NeverNL) || r != '\n') { + re->ccb_->AddRange(r, r); + } + r = CycleFoldRune(r); + } while (r != r1); + return PushRegexp(re); + } } // Exclude newline if applicable. @@ -556,7 +580,7 @@ int RepetitionWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg, int RepetitionWalker::ShortVisit(Regexp* re, int parent_arg) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "RepetitionWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "RepetitionWalker::ShortVisit called"; #endif return 0; } @@ -776,7 +800,8 @@ Rune* Regexp::LeadingString(Regexp* re, int* nrune, while (re->op() == kRegexpConcat && re->nsub() > 0) re = re->sub()[0]; - *flags = static_cast(re->parse_flags_ & Regexp::FoldCase); + *flags = static_cast(re->parse_flags_ & + (Regexp::FoldCase | Regexp::Latin1)); if (re->op() == kRegexpLiteral) { *nrune = 1; @@ -843,7 +868,7 @@ void Regexp::RemoveLeadingString(Regexp* re, int n) { case 0: case 1: // Impossible. - LOG(DFATAL) << "Concat of " << re->nsub(); + ABSL_LOG(DFATAL) << "Concat of " << re->nsub(); re->submany_ = NULL; re->op_ = kRegexpEmptyMatch; break; @@ -973,7 +998,7 @@ int Regexp::FactorAlternation(Regexp** sub, int nsub, ParseFlags flags) { i += iter->nsub; break; default: - LOG(DFATAL) << "unknown round: " << round; + ABSL_LOG(DFATAL) << "unknown round: " << round; break; } // If we are done, copy until the end of sub. @@ -1012,7 +1037,7 @@ int Regexp::FactorAlternation(Regexp** sub, int nsub, ParseFlags flags) { continue; } default: - LOG(DFATAL) << "unknown round: " << round; + ABSL_LOG(DFATAL) << "unknown round: " << round; break; } @@ -1175,7 +1200,7 @@ void FactorAlternationImpl::Round3(Regexp** sub, int nsub, if (re->op() == kRegexpCharClass) { CharClass* cc = re->cc(); for (CharClass::iterator it = cc->begin(); it != cc->end(); ++it) - ccb.AddRange(it->lo, it->hi); + ccb.AddRangeFlags(it->lo, it->hi, re->parse_flags()); } else if (re->op() == kRegexpLiteral) { if (re->parse_flags() & Regexp::FoldCase) { // AddFoldedRange() can terminate prematurely if the character class @@ -1189,12 +1214,12 @@ void FactorAlternationImpl::Round3(Regexp** sub, int nsub, ccb.AddRangeFlags(re->rune(), re->rune(), re->parse_flags()); } } else { - LOG(DFATAL) << "RE2: unexpected op: " << re->op() << " " - << re->ToString(); + ABSL_LOG(DFATAL) << "RE2: unexpected op: " << re->op() << " " + << re->ToString(); } re->Decref(); } - Regexp* re = Regexp::NewCharClass(ccb.GetCharClass(), flags); + Regexp* re = Regexp::NewCharClass(ccb.GetCharClass(), flags & ~Regexp::FoldCase); splices->emplace_back(re, sub + start, i - start); } @@ -1451,7 +1476,7 @@ static int UnHex(int c) { return c - 'A' + 10; if ('a' <= c && c <= 'f') return c - 'a' + 10; - LOG(DFATAL) << "Bad hex digit " << c; + ABSL_LOG(DFATAL) << "Bad hex digit " << c; return 0; } @@ -1622,10 +1647,15 @@ void CharClassBuilder::AddRangeFlags( } // If folding case, add fold-equivalent characters too. - if (parse_flags & Regexp::FoldCase) - AddFoldedRange(this, lo, hi, 0); - else + if (parse_flags & Regexp::FoldCase) { + if (parse_flags & Regexp::Latin1) { + AddFoldedRangeLatin1(this, lo, hi); + } else { + AddFoldedRange(this, lo, hi, 0); + } + } else { AddRange(lo, hi); + } } // Look for a group with the given name. @@ -2066,7 +2096,7 @@ bool Regexp::ParseState::ParsePerlFlags(absl::string_view* s) { // Caller is supposed to check this. if (!(flags_ & PerlX) || t.size() < 2 || t[0] != '(' || t[1] != '?') { status_->set_code(kRegexpInternalError); - LOG(DFATAL) << "Bad call to ParseState::ParsePerlFlags"; + ABSL_LOG(DFATAL) << "Bad call to ParseState::ParsePerlFlags"; return false; } diff --git a/re2/prefilter.cc b/re2/prefilter.cc index 3c7886f83..decc412ba 100644 --- a/re2/prefilter.cc +++ b/re2/prefilter.cc @@ -5,17 +5,19 @@ #include "re2/prefilter.h" #include -#include + #include #include #include +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" -#include "util/logging.h" -#include "util/utf.h" #include "re2/re2.h" +#include "re2/regexp.h" #include "re2/unicode_casefold.h" #include "re2/walker-inl.h" +#include "util/utf.h" namespace re2 { @@ -300,8 +302,8 @@ void Prefilter::CrossProduct(const SSet& a, const SSet& b, SSet* dst) { Prefilter::Info* Prefilter::Info::Concat(Info* a, Info* b) { if (a == NULL) return b; - DCHECK(a->is_exact_); - DCHECK(b && b->is_exact_); + ABSL_DCHECK(a->is_exact_); + ABSL_DCHECK(b && b->is_exact_); Info *ab = new Info(); CrossProduct(a->exact_, b->exact_, &ab->exact_); @@ -450,9 +452,9 @@ typedef CharClass::iterator CCIter; Prefilter::Info* Prefilter::Info::CClass(CharClass *cc, bool latin1) { if (ExtraDebug) { - LOG(ERROR) << "CharClassInfo:"; + ABSL_LOG(ERROR) << "CharClassInfo:"; for (CCIter i = cc->begin(); i != cc->end(); ++i) - LOG(ERROR) << " " << i->lo << "-" << i->hi; + ABSL_LOG(ERROR) << " " << i->lo << "-" << i->hi; } // If the class is too large, it's okay to overestimate. @@ -473,7 +475,7 @@ Prefilter::Info* Prefilter::Info::CClass(CharClass *cc, a->is_exact_ = true; if (ExtraDebug) - LOG(ERROR) << " = " << a->ToString(); + ABSL_LOG(ERROR) << " = " << a->ToString(); return a; } @@ -501,7 +503,7 @@ class Prefilter::Info::Walker : public Regexp::Walker { Prefilter::Info* Prefilter::BuildInfo(Regexp* re) { if (ExtraDebug) - LOG(ERROR) << "BuildPrefilter::Info: " << re->ToString(); + ABSL_LOG(ERROR) << "BuildPrefilter::Info: " << re->ToString(); bool latin1 = (re->parse_flags() & Regexp::Latin1) != 0; Prefilter::Info::Walker w(latin1); @@ -531,7 +533,7 @@ Prefilter::Info* Prefilter::Info::Walker::PostVisit( default: case kRegexpRepeat: info = EmptyString(); - LOG(DFATAL) << "Bad regexp op " << re->op(); + ABSL_LOG(DFATAL) << "Bad regexp op " << re->op(); break; case kRegexpNoMatch: @@ -634,8 +636,8 @@ Prefilter::Info* Prefilter::Info::Walker::PostVisit( } if (ExtraDebug) - LOG(ERROR) << "BuildInfo " << re->ToString() - << ": " << (info ? info->ToString() : ""); + ABSL_LOG(ERROR) << "BuildInfo " << re->ToString() + << ": " << (info ? info->ToString() : ""); return info; } @@ -662,7 +664,7 @@ Prefilter* Prefilter::FromRegexp(Regexp* re) { std::string Prefilter::DebugString() const { switch (op_) { default: - LOG(DFATAL) << "Bad op in Prefilter::DebugString: " << op_; + ABSL_LOG(DFATAL) << "Bad op in Prefilter::DebugString: " << op_; return absl::StrFormat("op%d", op_); case NONE: return "*no-matches*"; diff --git a/re2/prefilter.h b/re2/prefilter.h index 018691dcd..2645790cf 100644 --- a/re2/prefilter.h +++ b/re2/prefilter.h @@ -13,7 +13,8 @@ #include #include -#include "util/logging.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" namespace re2 { @@ -42,7 +43,7 @@ class Prefilter { // The children of the Prefilter node. std::vector* subs() { - DCHECK(op_ == AND || op_ == OR); + ABSL_DCHECK(op_ == AND || op_ == OR); return subs_; } diff --git a/re2/prefilter_tree.cc b/re2/prefilter_tree.cc index 3afb241c9..0a7bea984 100644 --- a/re2/prefilter_tree.cc +++ b/re2/prefilter_tree.cc @@ -5,17 +5,17 @@ #include "re2/prefilter_tree.h" #include + #include #include -#include #include #include #include +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" -#include "util/logging.h" #include "re2/prefilter.h" -#include "re2/re2.h" namespace re2 { @@ -38,7 +38,7 @@ PrefilterTree::~PrefilterTree() { void PrefilterTree::Add(Prefilter* prefilter) { if (compiled_) { - LOG(DFATAL) << "Add called after Compile."; + ABSL_LOG(DFATAL) << "Add called after Compile."; return; } if (prefilter != NULL && !KeepNode(prefilter)) { @@ -51,14 +51,15 @@ void PrefilterTree::Add(Prefilter* prefilter) { void PrefilterTree::Compile(std::vector* atom_vec) { if (compiled_) { - LOG(DFATAL) << "Compile called already."; + ABSL_LOG(DFATAL) << "Compile called already."; return; } // 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; @@ -82,7 +83,7 @@ bool PrefilterTree::KeepNode(Prefilter* node) const { switch (node->op()) { default: - LOG(DFATAL) << "Unexpected op in KeepNode: " << node->op(); + ABSL_LOG(DFATAL) << "Unexpected op in KeepNode: " << node->op(); return false; case Prefilter::ALL: @@ -177,7 +178,7 @@ void PrefilterTree::AssignUniqueIds(NodeSet* nodes, int id = prefilter->unique_id(); switch (prefilter->op()) { default: - LOG(DFATAL) << "Unexpected op: " << prefilter->op(); + ABSL_LOG(DFATAL) << "Unexpected op: " << prefilter->op(); return; case Prefilter::ATOM: @@ -211,7 +212,7 @@ void PrefilterTree::AssignUniqueIds(NodeSet* nodes, if (prefilter_vec_[i] == NULL) continue; int id = CanonicalNode(nodes, prefilter_vec_[i])->unique_id(); - DCHECK_LE(0, id); + ABSL_DCHECK_LE(0, id); Entry* entry = &entries_[id]; entry->regexps.push_back(static_cast(i)); } @@ -272,10 +273,11 @@ 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."; + ABSL_LOG(ERROR) << "RegexpsGivenStrings called before Compile."; for (size_t i = 0; i < prefilter_vec_.size(); i++) regexps->push_back(static_cast(i)); } else { @@ -329,31 +331,31 @@ void PrefilterTree::PropagateMatch(const std::vector& atom_ids, // Debugging help. void PrefilterTree::PrintPrefilter(int regexpid) { - LOG(ERROR) << DebugNodeString(prefilter_vec_[regexpid]); + ABSL_LOG(ERROR) << DebugNodeString(prefilter_vec_[regexpid]); } void PrefilterTree::PrintDebugInfo(NodeSet* nodes) { - LOG(ERROR) << "#Unique Atoms: " << atom_index_to_id_.size(); - LOG(ERROR) << "#Unique Nodes: " << entries_.size(); + ABSL_LOG(ERROR) << "#Unique Atoms: " << atom_index_to_id_.size(); + ABSL_LOG(ERROR) << "#Unique Nodes: " << entries_.size(); for (size_t i = 0; i < entries_.size(); i++) { const std::vector& parents = entries_[i].parents; const std::vector& regexps = entries_[i].regexps; - LOG(ERROR) << "EntryId: " << i - << " N: " << parents.size() << " R: " << regexps.size(); + ABSL_LOG(ERROR) << "EntryId: " << i + << " N: " << parents.size() << " R: " << regexps.size(); for (int parent : parents) - LOG(ERROR) << parent; + ABSL_LOG(ERROR) << parent; } - LOG(ERROR) << "Set:"; + ABSL_LOG(ERROR) << "Set:"; for (NodeSet::const_iterator iter = nodes->begin(); iter != nodes->end(); ++iter) - LOG(ERROR) << "NodeId: " << (*iter)->unique_id(); + ABSL_LOG(ERROR) << "NodeId: " << (*iter)->unique_id(); } std::string PrefilterTree::DebugNodeString(Prefilter* node) const { std::string node_string = ""; if (node->op() == Prefilter::ATOM) { - DCHECK(!node->atom().empty()); + ABSL_DCHECK(!node->atom().empty()); node_string += node->atom(); } else { // Adding the operation disambiguates AND and OR nodes. diff --git a/re2/prefilter_tree.h b/re2/prefilter_tree.h index 71e7a294f..885170df8 100644 --- a/re2/prefilter_tree.h +++ b/re2/prefilter_tree.h @@ -20,9 +20,10 @@ #include #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "re2/prefilter.h" #include "re2/sparse_array.h" -#include "util/logging.h" namespace re2 { @@ -62,15 +63,15 @@ class PrefilterTree { struct PrefilterHash { size_t operator()(const Prefilter* a) const { - DCHECK(a != NULL); + ABSL_DCHECK(a != NULL); return absl::Hash()(*a); } }; struct PrefilterEqual { bool operator()(const Prefilter* a, const Prefilter* b) const { - DCHECK(a != NULL); - DCHECK(b != NULL); + ABSL_DCHECK(a != NULL); + ABSL_DCHECK(b != NULL); return *a == *b; } }; diff --git a/re2/prog.cc b/re2/prog.cc index 6cadcfa83..9f1cc0082 100644 --- a/re2/prog.cc +++ b/re2/prog.cc @@ -7,35 +7,43 @@ #include "re2/prog.h" -#if defined(__AVX2__) -#include -#ifdef _MSC_VER -#include -#endif -#endif #include #include + #include -#include +#include #include +#include -#include "absl/base/macros.h" +#include "absl/base/attributes.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" -#include "util/logging.h" +#include "absl/strings/string_view.h" #include "re2/bitmap256.h" +#include "re2/pod_array.h" +#include "re2/sparse_array.h" +#include "re2/sparse_set.h" + +#if defined(__AVX2__) +#include +#ifdef _MSC_VER +#include +#endif +#endif namespace re2 { // Constructors per Inst opcode void Prog::Inst::InitAlt(uint32_t out, uint32_t out1) { - DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstAlt); out1_ = out1; } void Prog::Inst::InitByteRange(int lo, int hi, int foldcase, uint32_t out) { - DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstByteRange); lo_ = lo & 0xFF; hi_ = hi & 0xFF; @@ -43,30 +51,30 @@ void Prog::Inst::InitByteRange(int lo, int hi, int foldcase, uint32_t out) { } void Prog::Inst::InitCapture(int cap, uint32_t out) { - DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstCapture); cap_ = cap; } void Prog::Inst::InitEmptyWidth(EmptyOp empty, uint32_t out) { - DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_out_opcode(out, kInstEmptyWidth); empty_ = empty; } void Prog::Inst::InitMatch(int32_t id) { - DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_opcode(kInstMatch); match_id_ = id; } void Prog::Inst::InitNop(uint32_t out) { - DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_opcode(kInstNop); } void Prog::Inst::InitFail() { - DCHECK_EQ(out_opcode_, 0); + ABSL_DCHECK_EQ(out_opcode_, uint32_t{0}); set_opcode(kInstFail); } @@ -198,7 +206,7 @@ static bool IsMatch(Prog* prog, Prog::Inst* ip) { for (;;) { switch (ip->opcode()) { default: - LOG(DFATAL) << "Unexpected opcode in IsMatch: " << ip->opcode(); + ABSL_LOG(DFATAL) << "Unexpected opcode in IsMatch: " << ip->opcode(); return false; case kInstAlt: @@ -362,11 +370,11 @@ class ByteMapBuilder { }; void ByteMapBuilder::Mark(int lo, int hi) { - DCHECK_GE(lo, 0); - DCHECK_GE(hi, 0); - DCHECK_LE(lo, 255); - DCHECK_LE(hi, 255); - DCHECK_LE(lo, hi); + ABSL_DCHECK_GE(lo, 0); + ABSL_DCHECK_GE(hi, 0); + ABSL_DCHECK_LE(lo, 255); + ABSL_DCHECK_LE(hi, 255); + ABSL_DCHECK_LE(lo, hi); // Ignore any [0-255] ranges. They cause us to recolor every range, which // has no effect on the eventual result and is therefore a waste of time. @@ -511,7 +519,7 @@ void Prog::ComputeByteMap() { builder.Build(bytemap_, &bytemap_range_); if ((0)) { // For debugging, use trivial bytemap. - LOG(ERROR) << "Using trivial bytemap."; + ABSL_LOG(ERROR) << "Using trivial bytemap."; for (int i = 0; i < 256; i++) bytemap_[i] = static_cast(i); bytemap_range_ = 256; @@ -615,12 +623,12 @@ void Prog::Flatten() { size_t total = 0; for (int i = 0; i < kNumInst; i++) total += inst_count_[i]; - CHECK_EQ(total, flat.size()); + ABSL_CHECK_EQ(total, flat.size()); #endif // Remap start_unanchored and start. if (start_unanchored() == 0) { - DCHECK_EQ(start(), 0); + ABSL_DCHECK_EQ(start(), 0); } else if (start_unanchored() == start()) { set_start_unanchored(flatmap[1]); set_start(flatmap[1]); @@ -677,7 +685,7 @@ void Prog::MarkSuccessors(SparseArray* rootmap, Inst* ip = inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); + ABSL_LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); break; case kInstAltMatch: @@ -737,7 +745,7 @@ void Prog::MarkDominator(int root, SparseArray* rootmap, Inst* ip = inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); + ABSL_LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); break; case kInstAltMatch: @@ -804,7 +812,7 @@ void Prog::EmitList(int root, SparseArray* rootmap, Inst* ip = inst(id); switch (ip->opcode()) { default: - LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); + ABSL_LOG(DFATAL) << "unhandled opcode: " << ip->opcode(); break; case kInstAltMatch: @@ -1105,7 +1113,7 @@ const void* Prog::PrefixAccel_ShiftDFA(const void* data, size_t size) { #if defined(__AVX2__) // Finds the least significant non-zero bit in n. static int FindLSBSet(uint32_t n) { - DCHECK_NE(n, 0); + ABSL_DCHECK_NE(n, uint32_t{0}); #if defined(__GNUC__) return __builtin_ctz(n); #elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) @@ -1127,7 +1135,7 @@ static int FindLSBSet(uint32_t n) { #endif const void* Prog::PrefixAccel_FrontAndBack(const void* data, size_t size) { - DCHECK_GE(prefix_size_, 2); + ABSL_DCHECK_GE(prefix_size_, size_t{2}); if (size < prefix_size_) return NULL; // Don't bother searching the last prefix_size_-1 bytes for prefix_front_. @@ -1164,7 +1172,7 @@ const void* Prog::PrefixAccel_FrontAndBack(const void* data, size_t size) { const char* p0 = reinterpret_cast(data); for (const char* p = p0;; p++) { - DCHECK_GE(size, static_cast(p-p0)); + ABSL_DCHECK_GE(size, static_cast(p-p0)); p = reinterpret_cast(memchr(p, prefix_front_, size - (p-p0))); if (p == NULL || p[prefix_size_-1] == prefix_back_) return p; diff --git a/re2/prog.h b/re2/prog.h index 41923f314..d0889bdca 100644 --- a/re2/prog.h +++ b/re2/prog.h @@ -10,14 +10,16 @@ // expression symbolically. #include + #include #include -#include #include +#include #include "absl/base/call_once.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/string_view.h" -#include "util/logging.h" #include "re2/pod_array.h" #include "re2/re2.h" #include "re2/sparse_array.h" @@ -79,20 +81,44 @@ class Prog { // Getters int id(Prog* p) { return static_cast(this - p->inst_.data()); } - InstOp opcode() { return static_cast(out_opcode_&7); } - int last() { return (out_opcode_>>3)&1; } - int out() { return out_opcode_>>4; } - int out1() { DCHECK(opcode() == kInstAlt || opcode() == kInstAltMatch); return out1_; } - int cap() { DCHECK_EQ(opcode(), kInstCapture); return cap_; } - int lo() { DCHECK_EQ(opcode(), kInstByteRange); return lo_; } - int hi() { DCHECK_EQ(opcode(), kInstByteRange); return hi_; } - int foldcase() { DCHECK_EQ(opcode(), kInstByteRange); return hint_foldcase_&1; } - int hint() { DCHECK_EQ(opcode(), kInstByteRange); return hint_foldcase_>>1; } - int match_id() { DCHECK_EQ(opcode(), kInstMatch); return match_id_; } - EmptyOp empty() { DCHECK_EQ(opcode(), kInstEmptyWidth); return empty_; } + InstOp opcode() { return static_cast(out_opcode_ & 7); } + int last() { return (out_opcode_ >> 3) & 1; } + int out() { return out_opcode_ >> 4; } + int out1() { + ABSL_DCHECK(opcode() == kInstAlt || opcode() == kInstAltMatch); + return out1_; + } + int cap() { + ABSL_DCHECK_EQ(opcode(), kInstCapture); + return cap_; + } + int lo() { + ABSL_DCHECK_EQ(opcode(), kInstByteRange); + return lo_; + } + int hi() { + ABSL_DCHECK_EQ(opcode(), kInstByteRange); + return hi_; + } + int foldcase() { + ABSL_DCHECK_EQ(opcode(), kInstByteRange); + return hint_foldcase_ & 1; + } + int hint() { + ABSL_DCHECK_EQ(opcode(), kInstByteRange); + return hint_foldcase_ >> 1; + } + int match_id() { + ABSL_DCHECK_EQ(opcode(), kInstMatch); + return match_id_; + } + EmptyOp empty() { + ABSL_DCHECK_EQ(opcode(), kInstEmptyWidth); + return empty_; + } bool greedy(Prog* p) { - DCHECK_EQ(opcode(), kInstAltMatch); + ABSL_DCHECK_EQ(opcode(), kInstAltMatch); return p->inst(out())->opcode() == kInstByteRange || (p->inst(out())->opcode() == kInstNop && p->inst(p->inst(out())->out())->opcode() == kInstByteRange); @@ -100,7 +126,7 @@ class Prog { // Does this inst (an kInstByteRange) match c? inline bool Matches(int c) { - DCHECK_EQ(opcode(), kInstByteRange); + ABSL_DCHECK_EQ(opcode(), kInstByteRange); if (foldcase() && 'A' <= c && c <= 'Z') c += 'a' - 'A'; return lo_ <= c && c <= hi_; @@ -221,7 +247,7 @@ class Prog { // Accelerates to the first likely occurrence of the prefix. // Returns a pointer to the first byte or NULL if not found. const void* PrefixAccel(const void* data, size_t size) { - DCHECK(can_prefix_accel()); + ABSL_DCHECK(can_prefix_accel()); if (prefix_foldcase_) { return PrefixAccel_ShiftDFA(data, size); } else if (prefix_size_ != 1) { diff --git a/re2/re2.cc b/re2/re2.cc index 61d9d1f0c..ffdb367b0 100644 --- a/re2/re2.cc +++ b/re2/re2.cc @@ -9,31 +9,36 @@ #include "re2/re2.h" -#include #include -#ifdef _MSC_VER -#include -#endif +#include #include #include #include + #include #include -#include +#include #include #include #include +#include "absl/base/call_once.h" #include "absl/base/macros.h" #include "absl/container/fixed_array.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/ascii.h" #include "absl/strings/str_format.h" -#include "util/logging.h" -#include "util/strutil.h" -#include "util/utf.h" +#include "absl/strings/string_view.h" #include "re2/prog.h" #include "re2/regexp.h" #include "re2/sparse_array.h" +#include "util/strutil.h" +#include "util/utf.h" + +#ifdef _MSC_VER +#include +#endif namespace re2 { @@ -158,7 +163,7 @@ int RE2::Options::ParseFlags() const { switch (encoding()) { default: if (log_errors()) - LOG(ERROR) << "Unknown encoding " << encoding(); + ABSL_LOG(ERROR) << "Unknown encoding " << encoding(); break; case RE2::Options::EncodingUTF8: break; @@ -229,8 +234,8 @@ void RE2::Init(absl::string_view pattern, const Options& options) { &status); if (entire_regexp_ == NULL) { if (options_.log_errors()) { - LOG(ERROR) << "Error parsing '" << trunc(*pattern_) << "': " - << status.Text(); + ABSL_LOG(ERROR) << "Error parsing '" << trunc(*pattern_) << "': " + << status.Text(); } error_ = new std::string(status.Text()); error_code_ = RegexpErrorToRE2(status.code()); @@ -254,7 +259,7 @@ void RE2::Init(absl::string_view pattern, const Options& options) { prog_ = suffix_regexp_->CompileToProg(options_.max_mem()*2/3); if (prog_ == NULL) { if (options_.log_errors()) - LOG(ERROR) << "Error compiling '" << trunc(*pattern_) << "'"; + ABSL_LOG(ERROR) << "Error compiling '" << trunc(*pattern_) << "'"; error_ = new std::string("pattern too large - compile failed"); error_code_ = RE2::ErrorPatternTooLarge; return; @@ -280,8 +285,8 @@ re2::Prog* RE2::ReverseProg() const { re->suffix_regexp_->CompileToReverseProg(re->options_.max_mem() / 3); if (re->rprog_ == NULL) { if (re->options_.log_errors()) - LOG(ERROR) << "Error reverse compiling '" << trunc(*re->pattern_) - << "'"; + ABSL_LOG(ERROR) << "Error reverse compiling '" << trunc(*re->pattern_) + << "'"; // We no longer touch error_ and error_code_ because failing to compile // the reverse Prog is not a showstopper: falling back to NFA execution // is fine. More importantly, an RE2 object is supposed to be logically @@ -327,7 +332,7 @@ int RE2::ReverseProgramSize() const { // Finds the most significant non-zero bit in n. static int FindMSBSet(uint32_t n) { - DCHECK_NE(n, 0); + ABSL_DCHECK_NE(n, uint32_t{0}); #if defined(__GNUC__) return 31 ^ __builtin_clz(n); #elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) @@ -453,8 +458,8 @@ bool RE2::Replace(std::string* str, if (!re.Rewrite(&s, rewrite, vec, nvec)) return false; - DCHECK_GE(vec[0].data(), str->data()); - DCHECK_LE(vec[0].data() + vec[0].size(), str->data() + str->size()); + ABSL_DCHECK_GE(vec[0].data(), str->data()); + ABSL_DCHECK_LE(vec[0].data() + vec[0].size(), str->data() + str->size()); str->replace(vec[0].data() - str->data(), vec[0].size(), s); return true; } @@ -653,16 +658,16 @@ bool RE2::Match(absl::string_view text, int nsubmatch) const { if (!ok()) { if (options_.log_errors()) - LOG(ERROR) << "Invalid RE2: " << *error_; + ABSL_LOG(ERROR) << "Invalid RE2: " << *error_; return false; } if (startpos > endpos || endpos > text.size()) { if (options_.log_errors()) - LOG(ERROR) << "RE2: invalid startpos, endpos pair. [" - << "startpos: " << startpos << ", " - << "endpos: " << endpos << ", " - << "text size: " << text.size() << "]"; + ABSL_LOG(ERROR) << "RE2: invalid startpos, endpos pair. [" + << "startpos: " << startpos << ", " + << "endpos: " << endpos << ", " + << "text size: " << text.size() << "]"; return false; } @@ -732,7 +737,7 @@ bool RE2::Match(absl::string_view text, bool skipped_test = false; switch (re_anchor) { default: - LOG(DFATAL) << "Unexpected re_anchor value: " << re_anchor; + ABSL_LOG(DFATAL) << "Unexpected re_anchor value: " << re_anchor; return false; case UNANCHORED: { @@ -750,11 +755,11 @@ bool RE2::Match(absl::string_view text, Prog::kLongestMatch, matchp, &dfa_failed, NULL)) { if (dfa_failed) { if (options_.log_errors()) - LOG(ERROR) << "DFA out of memory: " - << "pattern length " << pattern_->size() << ", " - << "program size " << prog->size() << ", " - << "list count " << prog->list_count() << ", " - << "bytemap range " << prog->bytemap_range(); + ABSL_LOG(ERROR) << "DFA out of memory: " + << "pattern length " << pattern_->size() << ", " + << "program size " << prog->size() << ", " + << "list count " << prog->list_count() << ", " + << "bytemap range " << prog->bytemap_range(); // Fall back to NFA below. skipped_test = true; break; @@ -770,11 +775,11 @@ bool RE2::Match(absl::string_view text, matchp, &dfa_failed, NULL)) { if (dfa_failed) { if (options_.log_errors()) - LOG(ERROR) << "DFA out of memory: " - << "pattern length " << pattern_->size() << ", " - << "program size " << prog_->size() << ", " - << "list count " << prog_->list_count() << ", " - << "bytemap range " << prog_->bytemap_range(); + ABSL_LOG(ERROR) << "DFA out of memory: " + << "pattern length " << pattern_->size() << ", " + << "program size " << prog_->size() << ", " + << "list count " << prog_->list_count() << ", " + << "bytemap range " << prog_->bytemap_range(); // Fall back to NFA below. skipped_test = true; break; @@ -796,17 +801,17 @@ bool RE2::Match(absl::string_view text, Prog::kLongestMatch, &match, &dfa_failed, NULL)) { if (dfa_failed) { if (options_.log_errors()) - LOG(ERROR) << "DFA out of memory: " - << "pattern length " << pattern_->size() << ", " - << "program size " << prog->size() << ", " - << "list count " << prog->list_count() << ", " - << "bytemap range " << prog->bytemap_range(); + ABSL_LOG(ERROR) << "DFA out of memory: " + << "pattern length " << pattern_->size() << ", " + << "program size " << prog->size() << ", " + << "list count " << prog->list_count() << ", " + << "bytemap range " << prog->bytemap_range(); // Fall back to NFA below. skipped_test = true; break; } if (options_.log_errors()) - LOG(ERROR) << "SearchDFA inconsistency"; + ABSL_LOG(ERROR) << "SearchDFA inconsistency"; return false; } break; @@ -839,11 +844,11 @@ bool RE2::Match(absl::string_view text, &match, &dfa_failed, NULL)) { if (dfa_failed) { if (options_.log_errors()) - LOG(ERROR) << "DFA out of memory: " - << "pattern length " << pattern_->size() << ", " - << "program size " << prog_->size() << ", " - << "list count " << prog_->list_count() << ", " - << "bytemap range " << prog_->bytemap_range(); + ABSL_LOG(ERROR) << "DFA out of memory: " + << "pattern length " << pattern_->size() << ", " + << "program size " << prog_->size() << ", " + << "list count " << prog_->list_count() << ", " + << "bytemap range " << prog_->bytemap_range(); // Fall back to NFA below. skipped_test = true; break; @@ -875,20 +880,20 @@ bool RE2::Match(absl::string_view text, if (can_one_pass && anchor != Prog::kUnanchored) { if (!prog_->SearchOnePass(subtext1, text, anchor, kind, submatch, ncap)) { if (!skipped_test && options_.log_errors()) - LOG(ERROR) << "SearchOnePass inconsistency"; + ABSL_LOG(ERROR) << "SearchOnePass inconsistency"; return false; } } else if (can_bit_state && subtext1.size() <= bit_state_text_max_size) { if (!prog_->SearchBitState(subtext1, text, anchor, kind, submatch, ncap)) { if (!skipped_test && options_.log_errors()) - LOG(ERROR) << "SearchBitState inconsistency"; + ABSL_LOG(ERROR) << "SearchBitState inconsistency"; return false; } } else { if (!prog_->SearchNFA(subtext1, text, anchor, kind, submatch, ncap)) { if (!skipped_test && options_.log_errors()) - LOG(ERROR) << "SearchNFA inconsistency"; + ABSL_LOG(ERROR) << "SearchNFA inconsistency"; return false; } } @@ -913,7 +918,7 @@ bool RE2::DoMatch(absl::string_view text, int n) const { if (!ok()) { if (options_.log_errors()) - LOG(ERROR) << "Invalid RE2: " << *error_; + ABSL_LOG(ERROR) << "Invalid RE2: " << *error_; return false; } @@ -1033,8 +1038,8 @@ bool RE2::Rewrite(std::string* out, int n = (c - '0'); if (n >= veclen) { if (options_.log_errors()) { - LOG(ERROR) << "invalid substitution \\" << n - << " from " << veclen << " groups"; + ABSL_LOG(ERROR) << "invalid substitution \\" << n + << " from " << veclen << " groups"; } return false; } @@ -1045,7 +1050,7 @@ bool RE2::Rewrite(std::string* out, out->push_back('\\'); } else { if (options_.log_errors()) - LOG(ERROR) << "invalid rewrite pattern: " << rewrite.data(); + ABSL_LOG(ERROR) << "invalid rewrite pattern: " << rewrite; return false; } } diff --git a/re2/re2.h b/re2/re2.h index 68fbed1d8..d797bc040 100644 --- a/re2/re2.h +++ b/re2/re2.h @@ -50,10 +50,10 @@ // supplied pattern exactly. // // Example: successful match -// CHECK(RE2::FullMatch("hello", "h.*o")); +// ABSL_CHECK(RE2::FullMatch("hello", "h.*o")); // // Example: unsuccessful match (requires full match): -// CHECK(!RE2::FullMatch("hello", "e")); +// ABSL_CHECK(!RE2::FullMatch("hello", "e")); // // ----------------------------------------------------------------------- // UTF-8 AND THE MATCHING INTERFACE: @@ -62,8 +62,9 @@ // The RE2::Latin1 option causes them to be interpreted as Latin-1. // // Example: -// CHECK(RE2::FullMatch(utf8_string, RE2(utf8_pattern))); -// CHECK(RE2::FullMatch(latin1_string, RE2(latin1_pattern, RE2::Latin1))); +// ABSL_CHECK(RE2::FullMatch(utf8_string, RE2(utf8_pattern))); +// ABSL_CHECK(RE2::FullMatch(latin1_string, RE2(latin1_pattern, +// RE2::Latin1))); // // ----------------------------------------------------------------------- // SUBMATCH EXTRACTION: @@ -83,27 +84,27 @@ // Example: extracts "ruby" into "s" and 1234 into "i" // int i; // std::string s; -// CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i)); +// ABSL_CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i)); // // Example: extracts "ruby" into "s" and no value into "i" // absl::optional i; // std::string s; -// CHECK(RE2::FullMatch("ruby", "(\\w+)(?::(\\d+))?", &s, &i)); +// ABSL_CHECK(RE2::FullMatch("ruby", "(\\w+)(?::(\\d+))?", &s, &i)); // // Example: fails because string cannot be stored in integer -// CHECK(!RE2::FullMatch("ruby", "(.*)", &i)); +// ABSL_CHECK(!RE2::FullMatch("ruby", "(.*)", &i)); // // Example: fails because there aren't enough sub-patterns -// CHECK(!RE2::FullMatch("ruby:1234", "\\w+:\\d+", &s)); +// ABSL_CHECK(!RE2::FullMatch("ruby:1234", "\\w+:\\d+", &s)); // // Example: does not try to extract any extra sub-patterns -// CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s)); +// ABSL_CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s)); // // Example: does not try to extract into NULL -// CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", NULL, &i)); +// ABSL_CHECK(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", NULL, &i)); // // Example: integer overflow causes failure -// CHECK(!RE2::FullMatch("ruby:1234567891234", "\\w+:(\\d+)", &i)); +// ABSL_CHECK(!RE2::FullMatch("ruby:1234567891234", "\\w+:(\\d+)", &i)); // // NOTE(rsc): Asking for submatches slows successful matches quite a bit. // This may get a little faster in the future, but right now is slower @@ -117,12 +118,12 @@ // to match any substring of the text. // // Example: simple search for a string: -// CHECK(RE2::PartialMatch("hello", "ell")); +// ABSL_CHECK(RE2::PartialMatch("hello", "ell")); // // Example: find first number in a string // int number; -// CHECK(RE2::PartialMatch("x*100 + 20", "(\\d+)", &number)); -// CHECK_EQ(number, 100); +// ABSL_CHECK(RE2::PartialMatch("x*100 + 20", "(\\d+)", &number)); +// ABSL_CHECK_EQ(number, 100); // // ----------------------------------------------------------------------- // PRE-COMPILED REGULAR EXPRESSIONS @@ -203,27 +204,28 @@ // // Example: // int a, b, c, d; -// CHECK(RE2::FullMatch("100 40 0100 0x40", "(.*) (.*) (.*) (.*)", +// ABSL_CHECK(RE2::FullMatch("100 40 0100 0x40", "(.*) (.*) (.*) (.*)", // RE2::Octal(&a), RE2::Hex(&b), RE2::CRadix(&c), RE2::CRadix(&d)); // will leave 64 in a, b, c, and d. #include #include + #include #include #include #include #include -#if defined(__APPLE__) -#include -#endif - #include "absl/base/call_once.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "re2/stringpiece.h" +#if defined(__APPLE__) +#include +#endif + namespace re2 { class Prog; class Regexp; @@ -469,7 +471,7 @@ class RE2 { // text. E.g., // // std::string s = "yabba dabba doo"; - // CHECK(RE2::Replace(&s, "b+", "d")); + // ABSL_CHECK(RE2::Replace(&s, "b+", "d")); // // will leave "s" containing "yada dabba doo" // @@ -483,7 +485,7 @@ class RE2 { // of the pattern in the string with the rewrite. E.g. // // std::string s = "yabba dabba doo"; - // CHECK(RE2::GlobalReplace(&s, "b+", "d")); + // ABSL_CHECK(RE2::GlobalReplace(&s, "b+", "d")); // // will leave "s" containing "yada dada doo" // Replacements are not subject to re-matching. @@ -890,14 +892,12 @@ class RE2::Arg { re2_internal::Parse4ary::value, int>::type; -#if !defined(_MSC_VER) template using CanParseFrom = typename std::enable_if< std::is_member_function_pointer< decltype(static_cast( &T::ParseFrom))>::value, int>::type; -#endif public: Arg() : Arg(nullptr) {} @@ -909,10 +909,8 @@ class RE2::Arg { template = 0> Arg(T* ptr) : arg_(ptr), parser_(DoParse4ary) {} -#if !defined(_MSC_VER) template = 0> Arg(T* ptr) : arg_(ptr), parser_(DoParseFrom) {} -#endif typedef bool (*Parser)(const char* str, size_t n, void* dest); @@ -938,13 +936,11 @@ class RE2::Arg { return re2_internal::Parse(str, n, reinterpret_cast(dest), 10); } -#if !defined(_MSC_VER) template static bool DoParseFrom(const char* str, size_t n, void* dest) { if (dest == NULL) return true; return reinterpret_cast(dest)->ParseFrom(str, n); } -#endif void* arg_; Parser parser_; @@ -972,7 +968,7 @@ inline RE2::Arg RE2::Octal(T* ptr) { } // Silence warnings about missing initializers for members of LazyRE2. -#if !defined(__clang__) && defined(__GNUC__) +#if defined(__GNUC__) #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif diff --git a/re2/regexp.cc b/re2/regexp.cc index 4ea81cfcd..f7e5ba297 100644 --- a/re2/regexp.cc +++ b/re2/regexp.cc @@ -10,6 +10,7 @@ #include #include #include + #include #include #include @@ -18,11 +19,12 @@ #include "absl/base/call_once.h" #include "absl/base/macros.h" #include "absl/container/flat_hash_map.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/synchronization/mutex.h" -#include "util/logging.h" -#include "util/utf.h" #include "re2/pod_array.h" #include "re2/walker-inl.h" +#include "util/utf.h" namespace re2 { @@ -45,7 +47,7 @@ Regexp::Regexp(RegexpOp op, ParseFlags parse_flags) // required Decref() to have handled them for us. Regexp::~Regexp() { if (nsub_ > 0) - LOG(DFATAL) << "Regexp not destroyed."; + ABSL_LOG(DFATAL) << "Regexp not destroyed."; switch (op_) { default: @@ -154,7 +156,7 @@ void Regexp::Destroy() { Regexp* re = stack; stack = re->down_; if (re->ref_ != 0) - LOG(DFATAL) << "Bad reference count " << re->ref_; + ABSL_LOG(DFATAL) << "Bad reference count " << re->ref_; if (re->nsub_ > 0) { Regexp** subs = re->sub(); for (int i = 0; i < re->nsub_; i++) { @@ -179,7 +181,7 @@ void Regexp::Destroy() { } void Regexp::AddRuneToString(Rune r) { - DCHECK(op_ == kRegexpLiteralString); + ABSL_DCHECK(op_ == kRegexpLiteralString); if (nrunes_ == 0) { // start with 8 runes_ = new Rune[8]; @@ -421,7 +423,7 @@ static bool TopEqual(Regexp* a, Regexp* b) { } } - LOG(DFATAL) << "Unexpected op in Regexp::Equal: " << a->op(); + ABSL_LOG(DFATAL) << "Unexpected op in Regexp::Equal: " << a->op(); return 0; } @@ -496,7 +498,7 @@ bool Regexp::Equal(Regexp* a, Regexp* b) { if (n == 0) break; - DCHECK_GE(n, 2); + ABSL_DCHECK_GE(n, size_t{2}); a = stk[n-2]; b = stk[n-1]; stk.resize(n-2); @@ -562,7 +564,7 @@ class NumCapturesWalker : public Regexp::Walker { virtual Ignored ShortVisit(Regexp* re, Ignored ignored) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "NumCapturesWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "NumCapturesWalker::ShortVisit called"; #endif return ignored; } @@ -609,7 +611,7 @@ class NamedCapturesWalker : public Regexp::Walker { virtual Ignored ShortVisit(Regexp* re, Ignored ignored) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "NamedCapturesWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "NamedCapturesWalker::ShortVisit called"; #endif return ignored; } @@ -653,7 +655,7 @@ class CaptureNamesWalker : public Regexp::Walker { virtual Ignored ShortVisit(Regexp* re, Ignored ignored) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "CaptureNamesWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "CaptureNamesWalker::ShortVisit called"; #endif return ignored; } @@ -993,7 +995,7 @@ CharClass* CharClassBuilder::GetCharClass() { for (iterator it = begin(); it != end(); ++it) cc->ranges_[n++] = *it; cc->nranges_ = n; - DCHECK_LE(n, static_cast(ranges_.size())); + ABSL_DCHECK_LE(n, static_cast(ranges_.size())); cc->nrunes_ = nrunes_; cc->folds_ascii_ = FoldsASCII(); return cc; diff --git a/re2/regexp.h b/re2/regexp.h index df4989479..531b42044 100644 --- a/re2/regexp.h +++ b/re2/regexp.h @@ -88,12 +88,14 @@ #include #include + #include #include #include +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/string_view.h" -#include "util/logging.h" #include "util/utf.h" namespace re2 { @@ -332,15 +334,42 @@ class Regexp { return submany_; } - int min() { DCHECK_EQ(op_, kRegexpRepeat); return min_; } - int max() { DCHECK_EQ(op_, kRegexpRepeat); return max_; } - Rune rune() { DCHECK_EQ(op_, kRegexpLiteral); return rune_; } - CharClass* cc() { DCHECK_EQ(op_, kRegexpCharClass); return cc_; } - int cap() { DCHECK_EQ(op_, kRegexpCapture); return cap_; } - const std::string* name() { DCHECK_EQ(op_, kRegexpCapture); return name_; } - Rune* runes() { DCHECK_EQ(op_, kRegexpLiteralString); return runes_; } - int nrunes() { DCHECK_EQ(op_, kRegexpLiteralString); return nrunes_; } - int match_id() { DCHECK_EQ(op_, kRegexpHaveMatch); return match_id_; } + int min() { + ABSL_DCHECK_EQ(op_, kRegexpRepeat); + return min_; + } + int max() { + ABSL_DCHECK_EQ(op_, kRegexpRepeat); + return max_; + } + Rune rune() { + ABSL_DCHECK_EQ(op_, kRegexpLiteral); + return rune_; + } + CharClass* cc() { + ABSL_DCHECK_EQ(op_, kRegexpCharClass); + return cc_; + } + int cap() { + ABSL_DCHECK_EQ(op_, kRegexpCapture); + return cap_; + } + const std::string* name() { + ABSL_DCHECK_EQ(op_, kRegexpCapture); + return name_; + } + Rune* runes() { + ABSL_DCHECK_EQ(op_, kRegexpLiteralString); + return runes_; + } + int nrunes() { + ABSL_DCHECK_EQ(op_, kRegexpLiteralString); + return nrunes_; + } + int match_id() { + ABSL_DCHECK_EQ(op_, kRegexpHaveMatch); + return match_id_; + } // Increments reference count, returns object as convenience. Regexp* Incref(); @@ -515,7 +544,7 @@ class Regexp { // Allocate space for n sub-regexps. void AllocSub(int n) { - DCHECK(n >= 0 && static_cast(n) == n); + ABSL_DCHECK(n >= 0 && static_cast(n) == n); if (n > 1) submany_ = new Regexp*[n]; nsub_ = static_cast(n); diff --git a/re2/set.cc b/re2/set.cc index b9c918e07..caebd24e4 100644 --- a/re2/set.cc +++ b/re2/set.cc @@ -5,15 +5,20 @@ #include "re2/set.h" #include + #include #include +#include #include +#include -#include "util/logging.h" +#include "absl/log/absl_log.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/prog.h" #include "re2/re2.h" #include "re2/regexp.h" +#include "re2/sparse_set.h" namespace re2 { @@ -52,7 +57,7 @@ RE2::Set& RE2::Set::operator=(Set&& other) { int RE2::Set::Add(absl::string_view pattern, std::string* error) { if (compiled_) { - LOG(DFATAL) << "RE2::Set::Add() called after compiling"; + ABSL_LOG(DFATAL) << "RE2::Set::Add() called after compiling"; return -1; } @@ -64,7 +69,7 @@ int RE2::Set::Add(absl::string_view pattern, std::string* error) { if (error != NULL) *error = status.Text(); if (options_.log_errors()) - LOG(ERROR) << "Error parsing '" << pattern << "': " << status.Text(); + ABSL_LOG(ERROR) << "Error parsing '" << pattern << "': " << status.Text(); return -1; } @@ -91,7 +96,7 @@ int RE2::Set::Add(absl::string_view pattern, std::string* error) { bool RE2::Set::Compile() { if (compiled_) { - LOG(DFATAL) << "RE2::Set::Compile() called more than once"; + ABSL_LOG(DFATAL) << "RE2::Set::Compile() called more than once"; return false; } compiled_ = true; @@ -128,7 +133,7 @@ bool RE2::Set::Match(absl::string_view text, std::vector* v, if (!compiled_) { if (error_info != NULL) error_info->kind = kNotCompiled; - LOG(DFATAL) << "RE2::Set::Match() called before compiling"; + ABSL_LOG(DFATAL) << "RE2::Set::Match() called before compiling"; return false; } #ifdef RE2_HAVE_THREAD_LOCAL @@ -144,10 +149,10 @@ bool RE2::Set::Match(absl::string_view text, std::vector* v, NULL, &dfa_failed, matches.get()); if (dfa_failed) { if (options_.log_errors()) - LOG(ERROR) << "DFA out of memory: " - << "program size " << prog_->size() << ", " - << "list count " << prog_->list_count() << ", " - << "bytemap range " << prog_->bytemap_range(); + ABSL_LOG(ERROR) << "DFA out of memory: " + << "program size " << prog_->size() << ", " + << "list count " << prog_->list_count() << ", " + << "bytemap range " << prog_->bytemap_range(); if (error_info != NULL) error_info->kind = kOutOfMemory; return false; @@ -161,7 +166,7 @@ bool RE2::Set::Match(absl::string_view text, std::vector* v, if (matches->empty()) { if (error_info != NULL) error_info->kind = kInconsistent; - LOG(DFATAL) << "RE2::Set::Match() matched, but no matches returned?!"; + ABSL_LOG(DFATAL) << "RE2::Set::Match() matched, but no matches returned"; return false; } v->assign(matches->begin(), matches->end()); diff --git a/re2/simplify.cc b/re2/simplify.cc index cea100b08..d0524aff5 100644 --- a/re2/simplify.cc +++ b/re2/simplify.cc @@ -6,14 +6,17 @@ // to use simple extended regular expression features. // Also sort and simplify character classes. +#include + #include #include -#include "util/logging.h" -#include "util/utf.h" +#include "absl/log/absl_log.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/regexp.h" #include "re2/walker-inl.h" +#include "util/utf.h" namespace re2 { @@ -94,7 +97,7 @@ bool Regexp::ComputeSimple() { case kRegexpRepeat: return false; } - LOG(DFATAL) << "Case not handled in ComputeSimple: " << op_; + ABSL_LOG(DFATAL) << "Case not handled in ComputeSimple: " << op_; return false; } @@ -222,7 +225,7 @@ Regexp* CoalesceWalker::Copy(Regexp* re) { Regexp* CoalesceWalker::ShortVisit(Regexp* re, Regexp* parent_arg) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "CoalesceWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "CoalesceWalker::ShortVisit called"; #endif return re->Incref(); } @@ -372,7 +375,7 @@ void CoalesceWalker::DoCoalesce(Regexp** r1ptr, Regexp** r2ptr) { default: nre->Decref(); - LOG(DFATAL) << "DoCoalesce failed: r1->op() is " << r1->op(); + ABSL_LOG(DFATAL) << "DoCoalesce failed: r1->op() is " << r1->op(); return; } @@ -433,7 +436,7 @@ void CoalesceWalker::DoCoalesce(Regexp** r1ptr, Regexp** r2ptr) { default: nre->Decref(); - LOG(DFATAL) << "DoCoalesce failed: r2->op() is " << r2->op(); + ABSL_LOG(DFATAL) << "DoCoalesce failed: r2->op() is " << r2->op(); return; } @@ -448,7 +451,7 @@ Regexp* SimplifyWalker::Copy(Regexp* re) { Regexp* SimplifyWalker::ShortVisit(Regexp* re, Regexp* parent_arg) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "SimplifyWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "SimplifyWalker::ShortVisit called"; #endif return re->Incref(); } @@ -564,7 +567,7 @@ Regexp* SimplifyWalker::PostVisit(Regexp* re, } } - LOG(ERROR) << "Simplify case not handled: " << re->op(); + ABSL_LOG(ERROR) << "Simplify case not handled: " << re->op(); return re->Incref(); } @@ -661,7 +664,8 @@ Regexp* SimplifyWalker::SimplifyRepeat(Regexp* re, int min, int max, if (nre == NULL) { // Some degenerate case, like min > max, or min < max < 0. // This shouldn't happen, because the parser rejects such regexps. - LOG(DFATAL) << "Malformed repeat " << re->ToString() << " " << min << " " << max; + ABSL_LOG(DFATAL) << "Malformed repeat of " << re->ToString() + << " min " << min << " max " << max; return new Regexp(kRegexpNoMatch, f); } diff --git a/re2/sparse_array.h b/re2/sparse_array.h index 09ffe086b..8174d9a0a 100644 --- a/re2/sparse_array.h +++ b/re2/sparse_array.h @@ -88,21 +88,23 @@ // // A moved-from SparseArray will be empty. +#include +#include + +#include +#include +#include + +#include "re2/pod_array.h" + // Doing this simplifies the logic below. #ifndef __has_feature #define __has_feature(x) 0 #endif -#include -#include #if __has_feature(memory_sanitizer) #include #endif -#include -#include -#include - -#include "re2/pod_array.h" namespace re2 { diff --git a/re2/sparse_set.h b/re2/sparse_set.h index 06ed88d81..c08e93d29 100644 --- a/re2/sparse_set.h +++ b/re2/sparse_set.h @@ -47,21 +47,23 @@ // // See sparse_array.h for implementation details. +#include +#include + +#include +#include +#include + +#include "re2/pod_array.h" + // Doing this simplifies the logic below. #ifndef __has_feature #define __has_feature(x) 0 #endif -#include -#include #if __has_feature(memory_sanitizer) #include #endif -#include -#include -#include - -#include "re2/pod_array.h" namespace re2 { diff --git a/re2/testing/backtrack.cc b/re2/testing/backtrack.cc index 90071bb0f..7504e1a46 100644 --- a/re2/testing/backtrack.cc +++ b/re2/testing/backtrack.cc @@ -13,7 +13,7 @@ // THIS CODE SHOULD NEVER BE USED IN PRODUCTION: // - It uses a ton of memory. // - It uses a ton of stack. -// - It uses CHECK and LOG(FATAL). +// - It uses ABSL_CHECK() and ABSL_LOG(FATAL). // - It implements unanchored search by repeated anchored search. // // On the other hand, it is very simple and a good reference @@ -28,7 +28,9 @@ #include #include "absl/base/macros.h" -#include "util/logging.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" +#include "absl/strings/string_view.h" #include "re2/pod_array.h" #include "re2/prog.h" #include "re2/regexp.h" @@ -111,7 +113,7 @@ bool Backtracker::Search(absl::string_view text, absl::string_view context, endmatch_ = prog_->anchor_end(); submatch_ = submatch; nsubmatch_ = nsubmatch; - CHECK_LT(2*nsubmatch_, static_cast(ABSL_ARRAYSIZE(cap_))); + ABSL_CHECK_LT(2*nsubmatch_, static_cast(ABSL_ARRAYSIZE(cap_))); memset(cap_, 0, sizeof cap_); // We use submatch_[0] for our own bookkeeping, @@ -157,10 +159,10 @@ bool Backtracker::Visit(int id, const char* p) { // Check bitmap. If we've already explored from here, // either it didn't match or it did but we're hoping for a better match. // Either way, don't go down that road again. - CHECK(p <= text_.data() + text_.size()); + ABSL_CHECK(p <= text_.data() + text_.size()); int n = id * static_cast(text_.size()+1) + static_cast(p-text_.data()); - CHECK_LT(n/32, visited_.size()); + ABSL_CHECK_LT(n/32, visited_.size()); if (visited_[n/32] & (1 << (n&31))) return false; visited_[n/32] |= 1 << (n&31); @@ -188,7 +190,7 @@ bool Backtracker::Try(int id, const char* p) { Prog::Inst* ip = prog_->inst(id); switch (ip->opcode()) { default: - LOG(FATAL) << "Unexpected opcode: " << (int)ip->opcode(); + ABSL_LOG(FATAL) << "Unexpected opcode: " << ip->opcode(); return false; // not reached case kInstAltMatch: diff --git a/re2/testing/charclass_test.cc b/re2/testing/charclass_test.cc index ad95d6c26..efe38aec1 100644 --- a/re2/testing/charclass_test.cc +++ b/re2/testing/charclass_test.cc @@ -9,8 +9,8 @@ #include "absl/base/macros.h" #include "absl/strings/str_format.h" #include "gtest/gtest.h" -#include "util/utf.h" #include "re2/regexp.h" +#include "util/utf.h" namespace re2 { diff --git a/re2/testing/compile_test.cc b/re2/testing/compile_test.cc index f6899d3d2..7ac01f9b1 100644 --- a/re2/testing/compile_test.cc +++ b/re2/testing/compile_test.cc @@ -4,13 +4,16 @@ // Test prog.cc, compile.cc +#include + #include #include "absl/base/macros.h" +#include "absl/log/absl_log.h" +#include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "util/logging.h" -#include "re2/regexp.h" #include "re2/prog.h" +#include "re2/regexp.h" namespace re2 { @@ -132,13 +135,13 @@ TEST(TestRegexpCompileToProg, Simple) { const re2::Test& t = tests[i]; Regexp* re = Regexp::Parse(t.regexp, Regexp::PerlX|Regexp::Latin1, NULL); if (re == NULL) { - LOG(ERROR) << "Cannot parse: " << t.regexp; + ABSL_LOG(ERROR) << "Cannot parse: " << t.regexp; failed++; continue; } Prog* prog = re->CompileToProg(0); if (prog == NULL) { - LOG(ERROR) << "Cannot compile: " << t.regexp; + ABSL_LOG(ERROR) << "Cannot compile: " << t.regexp; re->Decref(); failed++; continue; @@ -146,9 +149,9 @@ TEST(TestRegexpCompileToProg, Simple) { ASSERT_TRUE(re->CompileToProg(1) == NULL); std::string s = prog->Dump(); if (s != t.code) { - LOG(ERROR) << "Incorrect compiled code for: " << t.regexp; - LOG(ERROR) << "Want:\n" << t.code; - LOG(ERROR) << "Got:\n" << s; + ABSL_LOG(ERROR) << "Incorrect compiled code for: " << t.regexp; + ABSL_LOG(ERROR) << "Want:\n" << t.code; + ABSL_LOG(ERROR) << "Got:\n" << s; failed++; } delete prog; diff --git a/re2/testing/dfa_test.cc b/re2/testing/dfa_test.cc index b0759f7c7..a8178c889 100644 --- a/re2/testing/dfa_test.cc +++ b/re2/testing/dfa_test.cc @@ -2,22 +2,24 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include #include + #include #include #include #include "absl/base/macros.h" #include "absl/flags/flag.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "util/logging.h" -#include "util/malloc_counter.h" #include "re2/prog.h" #include "re2/re2.h" #include "re2/regexp.h" -#include "re2/testing/regexp_generator.h" #include "re2/testing/string_generator.h" +#include "util/malloc_counter.h" static const bool UsingMallocCounter = false; @@ -111,10 +113,10 @@ TEST(SingleThreaded, BuildEntireDFA) { delete prog; } if (UsingMallocCounter) { - //LOG(INFO) << "limit " << limit << ", " - // << "prog usage " << progusage << ", " - // << "DFA budget " << dfamem << ", " - // << "total " << usage; + //ABSL_LOG(INFO) << "limit " << limit << ", " + // << "prog usage " << progusage << ", " + // << "DFA budget " << dfamem << ", " + // << "total " << usage; // Tolerate +/- 10%. ASSERT_GT(usage, limit*9/10); ASSERT_LT(usage, limit*11/10); @@ -189,8 +191,8 @@ TEST(SingleThreaded, SearchDFA) { delete prog; } if (UsingMallocCounter) { - //LOG(INFO) << "usage " << usage << ", " - // << "peak usage " << peak_usage; + //ABSL_LOG(INFO) << "usage " << usage << ", " + // << "peak usage " << peak_usage; ASSERT_LT(usage, 1<SearchDFA(t.text, absl::string_view(), Prog::kUnanchored, Prog::kFirstMatch, NULL, &failed, NULL); if (matched != t.match) { - LOG(ERROR) << t.regexp << " on " << t.text << ": want " << t.match; + ABSL_LOG(ERROR) << t.regexp << " on " << t.text << ": want " << t.match; nfail++; } delete prog; @@ -360,8 +362,9 @@ TEST(DFA, Callback) { dump += match ? "]]" : "]"; }); if (dump != t.dump) { - LOG(ERROR) << t.regexp << " bytemap:\n" << prog->DumpByteMap(); - LOG(ERROR) << t.regexp << " dump:\ngot " << dump << "\nwant " << t.dump; + ABSL_LOG(ERROR) << t.regexp << " bytemap:\n" << prog->DumpByteMap(); + ABSL_LOG(ERROR) << t.regexp << " dump:\n" << "got " << dump << "\n" + << "want " << t.dump; nfail++; } delete prog; diff --git a/re2/testing/dump.cc b/re2/testing/dump.cc index 5cddd2334..382ac208a 100644 --- a/re2/testing/dump.cc +++ b/re2/testing/dump.cc @@ -19,11 +19,12 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" #include "gtest/gtest.h" -#include "util/logging.h" -#include "util/utf.h" #include "re2/regexp.h" +#include "util/utf.h" namespace re2 { @@ -96,17 +97,25 @@ static void DumpRegexpAppending(Regexp* re, std::string* s) { break; case kRegexpLiteral: { Rune r = re->rune(); - char buf[UTFmax+1]; - buf[runetochar(buf, &r)] = 0; - s->append(buf); + if (re->parse_flags() & Regexp::Latin1) { + s->push_back(r); + } else { + char buf[UTFmax+1]; + buf[runetochar(buf, &r)] = 0; + s->append(buf); + } break; } case kRegexpLiteralString: for (int i = 0; i < re->nrunes(); i++) { Rune r = re->runes()[i]; - char buf[UTFmax+1]; - buf[runetochar(buf, &r)] = 0; - s->append(buf); + if (re->parse_flags() & Regexp::Latin1) { + s->push_back(r); + } else { + char buf[UTFmax+1]; + buf[runetochar(buf, &r)] = 0; + s->append(buf); + } } break; case kRegexpConcat: @@ -121,7 +130,7 @@ static void DumpRegexpAppending(Regexp* re, std::string* s) { break; case kRegexpCapture: if (re->cap() == 0) - LOG(DFATAL) << "kRegexpCapture cap() == 0"; + ABSL_LOG(DFATAL) << "kRegexpCapture cap() == 0"; if (re->name()) { s->append(*re->name()); s->append(":"); @@ -153,7 +162,7 @@ static void DumpRegexpAppending(Regexp* re, std::string* s) { std::string Regexp::Dump() { // Make sure that we are being called from a unit test. // Should cause a link error if used outside of testing. - CHECK(!::testing::TempDir().empty()); + ABSL_CHECK(!::testing::TempDir().empty()); std::string s; DumpRegexpAppending(this, &s); diff --git a/re2/testing/exhaustive1_test.cc b/re2/testing/exhaustive1_test.cc index 933798995..0056cf232 100644 --- a/re2/testing/exhaustive1_test.cc +++ b/re2/testing/exhaustive1_test.cc @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include "re2/testing/exhaustive_tester.h" +#include "re2/testing/regexp_generator.h" namespace re2 { diff --git a/re2/testing/exhaustive2_test.cc b/re2/testing/exhaustive2_test.cc index 14f629d4a..31079fb38 100644 --- a/re2/testing/exhaustive2_test.cc +++ b/re2/testing/exhaustive2_test.cc @@ -5,12 +5,13 @@ // Exhaustive testing of regular expression matching. #include -#include + #include #include #include "gtest/gtest.h" #include "re2/testing/exhaustive_tester.h" +#include "re2/testing/regexp_generator.h" namespace re2 { @@ -69,4 +70,3 @@ TEST(LineEnds, Exhaustive) { // } } // namespace re2 - diff --git a/re2/testing/exhaustive3_test.cc b/re2/testing/exhaustive3_test.cc index de703c00e..afc387f9a 100644 --- a/re2/testing/exhaustive3_test.cc +++ b/re2/testing/exhaustive3_test.cc @@ -5,13 +5,14 @@ // Exhaustive testing of regular expression matching. #include -#include + #include #include #include "gtest/gtest.h" -#include "util/utf.h" #include "re2/testing/exhaustive_tester.h" +#include "re2/testing/regexp_generator.h" +#include "util/utf.h" namespace re2 { @@ -97,4 +98,3 @@ TEST(InterestingUTF8, AB) { } } // namespace re2 - diff --git a/re2/testing/exhaustive_test.cc b/re2/testing/exhaustive_test.cc index 5e586f1fe..1bae2f3c7 100644 --- a/re2/testing/exhaustive_test.cc +++ b/re2/testing/exhaustive_test.cc @@ -33,4 +33,3 @@ TEST(EgrepLiterals, UTF8) { } } // namespace re2 - diff --git a/re2/testing/exhaustive_tester.cc b/re2/testing/exhaustive_tester.cc index a57f700bc..d8fa1ffa8 100644 --- a/re2/testing/exhaustive_tester.cc +++ b/re2/testing/exhaustive_tester.cc @@ -11,14 +11,23 @@ // the NFA, DFA, and a trivial backtracking implementation agree about // the location of the match. +#include "re2/testing/exhaustive_tester.h" + #include +#include +#include + #include "absl/base/macros.h" #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "util/logging.h" -#include "re2/testing/exhaustive_tester.h" +#include "re2/prog.h" +#include "re2/re2.h" +#include "re2/testing/regexp_generator.h" #include "re2/testing/tester.h" // For target `log' in the Makefile. @@ -40,7 +49,7 @@ static char* escape(absl::string_view sp) { *p++ = '\"'; for (size_t i = 0; i < sp.size(); i++) { if(p+5 >= buf+sizeof buf) - LOG(FATAL) << "ExhaustiveTester escape: too long"; + ABSL_LOG(FATAL) << "ExhaustiveTester escape: too long"; if(sp[i] == '\\' || sp[i] == '\"') { *p++ = '\\'; *p++ = sp[i]; @@ -82,7 +91,7 @@ void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) { std::string regexp = const_regexp; if (!topwrapper_.empty()) { auto fmt = absl::ParsedFormat<'s'>::New(topwrapper_); - CHECK(fmt != nullptr); + ABSL_CHECK(fmt != nullptr); regexp = absl::StrFormat(*fmt, regexp); } @@ -95,7 +104,7 @@ void ExhaustiveTester::HandleRegexp(const std::string& const_regexp) { // Write out test cases and answers for use in testing // other implementations, such as Go's regexp package. if (randomstrings_) - LOG(ERROR) << "Cannot log with random strings."; + ABSL_LOG(ERROR) << "Cannot log with random strings."; if (regexps_ == 1) { // first absl::PrintF("strings\n"); strgen_.Reset(); diff --git a/re2/testing/exhaustive_tester.h b/re2/testing/exhaustive_tester.h index 906be0c8c..8b0421d71 100644 --- a/re2/testing/exhaustive_tester.h +++ b/re2/testing/exhaustive_tester.h @@ -6,6 +6,7 @@ #define RE2_TESTING_EXHAUSTIVE_TESTER_H_ #include + #include #include diff --git a/re2/testing/filtered_re2_test.cc b/re2/testing/filtered_re2_test.cc index a8d2dfc72..6da76b228 100644 --- a/re2/testing/filtered_re2_test.cc +++ b/re2/testing/filtered_re2_test.cc @@ -2,17 +2,18 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include "re2/filtered_re2.h" + #include + #include -#include #include -#include #include +#include #include "absl/base/macros.h" +#include "absl/log/absl_log.h" #include "gtest/gtest.h" -#include "util/logging.h" -#include "re2/filtered_re2.h" #include "re2/re2.h" namespace re2 { @@ -32,14 +33,14 @@ TEST(FilteredRE2Test, EmptyTest) { FilterTestVars v; v.f.Compile(&v.atoms); - EXPECT_EQ(0, v.atoms.size()); + EXPECT_EQ(size_t{0}, v.atoms.size()); // Compile has no effect at all when called before Add: it will not // record that it has been called and it will not clear the vector. // The second point does not matter here, but the first point means // that an error will be logged during the call to AllMatches. v.f.AllMatches("foo", v.atom_indices, &v.matches); - EXPECT_EQ(0, v.matches.size()); + EXPECT_EQ(size_t{0}, v.matches.size()); } TEST(FilteredRE2Test, SmallOrTest) { @@ -48,10 +49,10 @@ TEST(FilteredRE2Test, SmallOrTest) { v.f.Add("(foo|bar)", v.opts, &id); v.f.Compile(&v.atoms); - EXPECT_EQ(0, v.atoms.size()); + EXPECT_EQ(size_t{0}, v.atoms.size()); v.f.AllMatches("lemurs bar", v.atom_indices, &v.matches); - EXPECT_EQ(1, v.matches.size()); + EXPECT_EQ(size_t{1}, v.matches.size()); EXPECT_EQ(id, v.matches[0]); } @@ -62,12 +63,12 @@ TEST(FilteredRE2Test, SmallLatinTest) { v.opts.set_encoding(RE2::Options::EncodingLatin1); v.f.Add("\xde\xadQ\xbe\xef", v.opts, &id); v.f.Compile(&v.atoms); - EXPECT_EQ(1, v.atoms.size()); + EXPECT_EQ(size_t{1}, v.atoms.size()); EXPECT_EQ(v.atoms[0], "\xde\xadq\xbe\xef"); v.atom_indices.push_back(0); v.f.AllMatches("foo\xde\xadQ\xbe\xeflemur", v.atom_indices, &v.matches); - EXPECT_EQ(1, v.matches.size()); + EXPECT_EQ(size_t{1}, v.matches.size()); EXPECT_EQ(id, v.matches[0]); } @@ -172,13 +173,13 @@ bool CheckExpectedAtoms(const char* atoms[], pass = pass && expected[i] == v->atoms[i]; if (!pass) { - LOG(ERROR) << "Failed " << testname; - LOG(ERROR) << "Expected #atoms = " << expected.size(); + ABSL_LOG(ERROR) << "Failed " << testname; + ABSL_LOG(ERROR) << "Expected #atoms = " << expected.size(); for (size_t i = 0; i < expected.size(); i++) - LOG(ERROR) << expected[i]; - LOG(ERROR) << "Found #atoms = " << v->atoms.size(); + ABSL_LOG(ERROR) << expected[i]; + ABSL_LOG(ERROR) << "Found #atoms = " << v->atoms.size(); for (size_t i = 0; i < v->atoms.size(); i++) - LOG(ERROR) << v->atoms[i]; + ABSL_LOG(ERROR) << v->atoms[i]; } return pass; @@ -255,7 +256,7 @@ TEST(FilteredRE2Test, MatchTests) { FindAtomIndices(v.atoms, atoms, &atom_ids); std::vector matching_regexps; v.f.AllMatches(text, atom_ids, &matching_regexps); - EXPECT_EQ(1, matching_regexps.size()); + EXPECT_EQ(size_t{1}, matching_regexps.size()); text = "abc12312yyyzzz"; atoms.clear(); @@ -264,7 +265,7 @@ TEST(FilteredRE2Test, MatchTests) { atoms.push_back("yyyzzz"); FindAtomIndices(v.atoms, atoms, &atom_ids); v.f.AllMatches(text, atom_ids, &matching_regexps); - EXPECT_EQ(1, matching_regexps.size()); + EXPECT_EQ(size_t{1}, matching_regexps.size()); text = "abcd12yyy32yyyzzz"; atoms.clear(); @@ -273,11 +274,11 @@ TEST(FilteredRE2Test, MatchTests) { atoms.push_back("yyy"); atoms.push_back("yyyzzz"); FindAtomIndices(v.atoms, atoms, &atom_ids); - LOG(INFO) << "S: " << atom_ids.size(); + ABSL_LOG(INFO) << "S: " << atom_ids.size(); for (size_t i = 0; i < atom_ids.size(); i++) - LOG(INFO) << "i: " << i << " : " << atom_ids[i]; + ABSL_LOG(INFO) << "i: " << i << " : " << atom_ids[i]; v.f.AllMatches(text, atom_ids, &matching_regexps); - EXPECT_EQ(2, matching_regexps.size()); + EXPECT_EQ(size_t{2}, matching_regexps.size()); } TEST(FilteredRE2Test, EmptyStringInStringSetBug) { @@ -300,43 +301,43 @@ TEST(FilteredRE2Test, MoveSemantics) { v1.f.Add("foo\\d+", v1.opts, &id); EXPECT_EQ(0, id); v1.f.Compile(&v1.atoms); - EXPECT_EQ(1, v1.atoms.size()); + EXPECT_EQ(size_t{1}, v1.atoms.size()); EXPECT_EQ("foo", v1.atoms[0]); v1.f.AllMatches("abc foo1 xyz", {0}, &v1.matches); - EXPECT_EQ(1, v1.matches.size()); + EXPECT_EQ(size_t{1}, v1.matches.size()); EXPECT_EQ(0, v1.matches[0]); v1.f.AllMatches("abc bar2 xyz", {0}, &v1.matches); - EXPECT_EQ(0, v1.matches.size()); + EXPECT_EQ(size_t{0}, v1.matches.size()); // The moved-to object should do what the moved-from object did. FilterTestVars v2; v2.f = std::move(v1.f); v2.f.AllMatches("abc foo1 xyz", {0}, &v2.matches); - EXPECT_EQ(1, v2.matches.size()); + EXPECT_EQ(size_t{1}, v2.matches.size()); EXPECT_EQ(0, v2.matches[0]); v2.f.AllMatches("abc bar2 xyz", {0}, &v2.matches); - EXPECT_EQ(0, v2.matches.size()); + EXPECT_EQ(size_t{0}, v2.matches.size()); // The moved-from object should have been reset and be reusable. v1.f.Add("bar\\d+", v1.opts, &id); EXPECT_EQ(0, id); v1.f.Compile(&v1.atoms); - EXPECT_EQ(1, v1.atoms.size()); + EXPECT_EQ(size_t{1}, v1.atoms.size()); EXPECT_EQ("bar", v1.atoms[0]); v1.f.AllMatches("abc foo1 xyz", {0}, &v1.matches); - EXPECT_EQ(0, v1.matches.size()); + EXPECT_EQ(size_t{0}, v1.matches.size()); v1.f.AllMatches("abc bar2 xyz", {0}, &v1.matches); - EXPECT_EQ(1, v1.matches.size()); + EXPECT_EQ(size_t{1}, v1.matches.size()); EXPECT_EQ(0, v1.matches[0]); // Verify that "overwriting" works and also doesn't leak memory. // (The latter will need a leak detector such as LeakSanitizer.) v1.f = std::move(v2.f); v1.f.AllMatches("abc foo1 xyz", {0}, &v1.matches); - EXPECT_EQ(1, v1.matches.size()); + EXPECT_EQ(size_t{1}, v1.matches.size()); EXPECT_EQ(0, v1.matches[0]); v1.f.AllMatches("abc bar2 xyz", {0}, &v1.matches); - EXPECT_EQ(0, v1.matches.size()); + EXPECT_EQ(size_t{0}, v1.matches.size()); } } // namespace re2 diff --git a/re2/testing/mimics_pcre_test.cc b/re2/testing/mimics_pcre_test.cc index 829659d67..36a348f02 100644 --- a/re2/testing/mimics_pcre_test.cc +++ b/re2/testing/mimics_pcre_test.cc @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include + #include "absl/base/macros.h" #include "gtest/gtest.h" -#include "util/logging.h" #include "re2/prog.h" #include "re2/regexp.h" diff --git a/re2/testing/null_walker.cc b/re2/testing/null_walker.cc index 745364b3c..3e17bc39e 100644 --- a/re2/testing/null_walker.cc +++ b/re2/testing/null_walker.cc @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "gtest/gtest.h" -#include "util/logging.h" +#include "absl/log/absl_log.h" #include "re2/regexp.h" #include "re2/walker-inl.h" @@ -21,7 +20,7 @@ class NullWalker : public Regexp::Walker { virtual bool ShortVisit(Regexp* re, bool a) { // Should never be called: we use Walk(), not WalkExponential(). #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - LOG(DFATAL) << "NullWalker::ShortVisit called"; + ABSL_LOG(DFATAL) << "NullWalker::ShortVisit called"; #endif return a; } diff --git a/re2/testing/parse_test.cc b/re2/testing/parse_test.cc index 7684b62a4..53ef24ec7 100644 --- a/re2/testing/parse_test.cc +++ b/re2/testing/parse_test.cc @@ -4,11 +4,13 @@ // Test parse.cc, dump.cc, and tostring.cc. +#include + #include #include "absl/base/macros.h" +#include "absl/log/absl_log.h" #include "gtest/gtest.h" -#include "util/logging.h" #include "re2/regexp.h" namespace re2 { @@ -225,6 +227,29 @@ static Test tests[] = { // Bug in Regexp::ToString() that emitted [^], which // would (obviously) fail to parse when fed back in. { "[\\s\\S]", "cc{0-0x10ffff}" }, + + // As per https://github.com/google/re2/issues/477, + // there were long-standing bugs involving Latin-1. + // Here, we exercise it WITHOUT case folding... + { "\xa5\x64\xd1", "str{\xa5""d\xd1}", Regexp::Latin1 }, + { "\xa5\xd1\x64", "str{\xa5\xd1""d}", Regexp::Latin1 }, + { "\xa5\x64[\xd1\xd2]", "cat{str{\xa5""d}cc{0xd1-0xd2}}", Regexp::Latin1 }, + { "\xa5[\xd1\xd2]\x64", "cat{lit{\xa5}cc{0xd1-0xd2}lit{d}}", Regexp::Latin1 }, + { "\xa5\x64|\xa5\xd1", "cat{lit{\xa5}cc{0x64 0xd1}}", Regexp::Latin1 }, + { "\xa5\xd1|\xa5\x64", "cat{lit{\xa5}cc{0x64 0xd1}}", Regexp::Latin1 }, + { "\xa5\x64|\xa5[\xd1\xd2]", "cat{lit{\xa5}cc{0x64 0xd1-0xd2}}", Regexp::Latin1 }, + { "\xa5[\xd1\xd2]|\xa5\x64", "cat{lit{\xa5}cc{0x64 0xd1-0xd2}}", Regexp::Latin1 }, + // Here, we exercise it WITH case folding... + // 0x64 should fold to 0x44, but neither 0xD1 nor 0xD2 + // should fold to 0xF1 and 0xF2, respectively. + { "\xa5\x64\xd1", "strfold{\xa5""d\xd1}", Regexp::Latin1 | Regexp::FoldCase }, + { "\xa5\xd1\x64", "strfold{\xa5\xd1""d}", Regexp::Latin1 | Regexp::FoldCase }, + { "\xa5\x64[\xd1\xd2]", "cat{strfold{\xa5""d}cc{0xd1-0xd2}}", Regexp::Latin1 | Regexp::FoldCase }, + { "\xa5[\xd1\xd2]\x64", "cat{lit{\xa5}cc{0xd1-0xd2}litfold{d}}", Regexp::Latin1 | Regexp::FoldCase }, + { "\xa5\x64|\xa5\xd1", "cat{lit{\xa5}cc{0x44 0x64 0xd1}}", Regexp::Latin1 | Regexp::FoldCase }, + { "\xa5\xd1|\xa5\x64", "cat{lit{\xa5}cc{0x44 0x64 0xd1}}", Regexp::Latin1 | Regexp::FoldCase }, + { "\xa5\x64|\xa5[\xd1\xd2]", "cat{lit{\xa5}cc{0x44 0x64 0xd1-0xd2}}", Regexp::Latin1 | Regexp::FoldCase }, + { "\xa5[\xd1\xd2]|\xa5\x64", "cat{lit{\xa5}cc{0x44 0x64 0xd1-0xd2}}", Regexp::Latin1 | Regexp::FoldCase }, }; bool RegexpEqualTestingOnly(Regexp* a, Regexp* b) { @@ -492,12 +517,12 @@ TEST(TestToString, EquivalentParse) { // << " t=" << t << " regexp=" << tests[i].regexp; // Test that if we parse the new regexp we get the same structure. - Regexp* nre = Regexp::Parse(t, Regexp::MatchNL | Regexp::PerlX, &status); + Regexp* nre = Regexp::Parse(t, f, &status); ASSERT_TRUE(nre != NULL) << " reparse " << t << " " << status.Text(); std::string ss = nre->Dump(); std::string tt = nre->ToString(); if (s != ss || t != tt) - LOG(INFO) << "ToString(" << tests[i].regexp << ") = " << t; + ABSL_LOG(INFO) << "ToString(" << tests[i].regexp << ") = " << t; EXPECT_EQ(s, ss); EXPECT_EQ(t, tt); nre->Decref(); diff --git a/re2/testing/possible_match_test.cc b/re2/testing/possible_match_test.cc index fe199c662..f217947d6 100644 --- a/re2/testing/possible_match_test.cc +++ b/re2/testing/possible_match_test.cc @@ -3,13 +3,15 @@ // license that can be found in the LICENSE file. #include + #include #include #include "absl/base/macros.h" +#include "absl/log/absl_log.h" #include "absl/strings/escaping.h" +#include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "util/logging.h" #include "re2/prog.h" #include "re2/re2.h" #include "re2/regexp.h" @@ -113,7 +115,7 @@ TEST(PossibleMatchRange, HandWritten) { const PrefixTest& t = tests[i]; std::string min, max; if (j == 0) { - LOG(INFO) << "Checking regexp=" << absl::CEscape(t.regexp); + ABSL_LOG(INFO) << "Checking regexp=" << absl::CEscape(t.regexp); Regexp* re = Regexp::Parse(t.regexp, Regexp::LikePerl, NULL); ASSERT_TRUE(re != NULL); Prog* prog = re->CompileToProg(0); @@ -202,7 +204,7 @@ class PossibleMatchTester : public RegexpGenerator { void PossibleMatchTester::HandleRegexp(const std::string& regexp) { regexps_++; - VLOG(3) << absl::CEscape(regexp); + ABSL_VLOG(3) << absl::CEscape(regexp); RE2 re(regexp, RE2::Latin1); ASSERT_EQ(re.error(), ""); @@ -214,7 +216,8 @@ void PossibleMatchTester::HandleRegexp(const std::string& regexp) { // complicated expressions. if(strstr(regexp.c_str(), "\\C*")) return; - LOG(QFATAL) << "PossibleMatchRange failed on: " << absl::CEscape(regexp); + ABSL_LOG(QFATAL) << "PossibleMatchRange failed on: " + << absl::CEscape(regexp); } strgen_.Reset(); @@ -241,8 +244,8 @@ TEST(PossibleMatchRange, Exhaustive) { RegexpGenerator::EgrepOps(), stringlen, Explode("ab4")); t.Generate(); - LOG(INFO) << t.regexps() << " regexps, " - << t.tests() << " tests"; + ABSL_LOG(INFO) << t.regexps() << " regexps, " + << t.tests() << " tests"; } } // namespace re2 diff --git a/re2/testing/random_test.cc b/re2/testing/random_test.cc index d076b39b1..6ff358762 100644 --- a/re2/testing/random_test.cc +++ b/re2/testing/random_test.cc @@ -4,7 +4,6 @@ // Random testing of regular expression matching. -#include #include #include @@ -12,6 +11,7 @@ #include "absl/strings/str_format.h" #include "gtest/gtest.h" #include "re2/testing/exhaustive_tester.h" +#include "re2/testing/regexp_generator.h" ABSL_FLAG(int, regexpseed, 404, "Random regexp seed."); ABSL_FLAG(int, regexpcount, 100, "How many random regexps to generate."); diff --git a/re2/testing/re2_arg_test.cc b/re2/testing/re2_arg_test.cc index 4b00be358..c895c30a9 100644 --- a/re2/testing/re2_arg_test.cc +++ b/re2/testing/re2_arg_test.cc @@ -11,8 +11,9 @@ #include #include "absl/base/macros.h" +#include "absl/log/absl_log.h" +#include "absl/types/optional.h" #include "gtest/gtest.h" -#include "util/logging.h" #include "re2/re2.h" namespace re2 { @@ -135,10 +136,9 @@ TEST(RE2ArgTest, Uint64Test) { } TEST(RE2ArgTest, ParseFromTest) { -#if !defined(_MSC_VER) struct { bool ParseFrom(const char* str, size_t n) { - LOG(INFO) << "str = " << str << ", n = " << n; + ABSL_LOG(INFO) << "str = " << str << ", n = " << n; return true; } } obj1; @@ -147,7 +147,7 @@ TEST(RE2ArgTest, ParseFromTest) { struct { bool ParseFrom(const char* str, size_t n) { - LOG(INFO) << "str = " << str << ", n = " << n; + ABSL_LOG(INFO) << "str = " << str << ", n = " << n; return false; } // Ensure that RE2::Arg works even with overloaded ParseFrom(). @@ -155,7 +155,6 @@ TEST(RE2ArgTest, ParseFromTest) { } obj2; RE2::Arg arg2(&obj2); EXPECT_FALSE(arg2.Parse("two", 3)); -#endif } TEST(RE2ArgTest, OptionalDoubleTest) { diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc index 151525f2d..04c040e9e 100644 --- a/re2/testing/re2_test.cc +++ b/re2/testing/re2_test.cc @@ -5,26 +5,30 @@ // TODO: Test extractions for PartialMatch/Consume +#include "re2/re2.h" + #include #include #include #include + #include #include #include #include -#if !defined(_MSC_VER) && !defined(__CYGWIN__) && !defined(__MINGW32__) -#include -#include /* for sysconf */ -#endif #include "absl/base/macros.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "util/logging.h" -#include "re2/re2.h" #include "re2/regexp.h" +#if !defined(_MSC_VER) && !defined(__CYGWIN__) && !defined(__MINGW32__) +#include +#include +#endif + namespace re2 { TEST(RE2, HexTests) { @@ -554,14 +558,14 @@ TEST(Capture, NamedGroups) { RE2 re("(hello world)"); ASSERT_EQ(re.NumberOfCapturingGroups(), 1); const std::map& m = re.NamedCapturingGroups(); - ASSERT_EQ(m.size(), 0); + ASSERT_EQ(m.size(), size_t{0}); } { RE2 re("(?Pexpr(?Pexpr)(?Pexpr))((expr)(?Pexpr))"); ASSERT_EQ(re.NumberOfCapturingGroups(), 6); const std::map& m = re.NamedCapturingGroups(); - ASSERT_EQ(m.size(), 4); + ASSERT_EQ(m.size(), size_t{4}); ASSERT_EQ(m.find("A")->second, 1); ASSERT_EQ(m.find("B")->second, 2); ASSERT_EQ(m.find("C")->second, 3); @@ -683,7 +687,7 @@ TEST(RE2, FullMatchStringViewArg) { absl::string_view sp; // string_view-arg ASSERT_TRUE(RE2::FullMatch("ruby:1234", "(\\w+):(\\d+)", &sp, &i)); - ASSERT_EQ(sp.size(), 4); + ASSERT_EQ(sp.size(), size_t{4}); ASSERT_TRUE(memcmp(sp.data(), "ruby", 4) == 0); ASSERT_EQ(i, 1234); } @@ -773,7 +777,7 @@ TEST(RE2, NULTerminated) { v = static_cast(mmap(NULL, 2*pagesize, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0)); ASSERT_TRUE(v != reinterpret_cast(-1)); - LOG(INFO) << "Memory at " << (void*)v; + ABSL_LOG(INFO) << "Memory at " << reinterpret_cast(v); ASSERT_EQ(munmap(v + pagesize, pagesize), 0) << " error " << errno; v[pagesize - 1] = '1'; @@ -792,6 +796,11 @@ TEST(RE2, FullMatchTypeTests) { ASSERT_TRUE(RE2::FullMatch("Hello", "(H)ello", &c)); ASSERT_EQ(c, 'H'); } + { + signed char c; + ASSERT_TRUE(RE2::FullMatch("Hello", "(H)ello", &c)); + ASSERT_EQ(c, static_cast('H')); + } { unsigned char c; ASSERT_TRUE(RE2::FullMatch("Hello", "(H)ello", &c)); @@ -837,7 +846,7 @@ TEST(RE2, FullMatchTypeTests) { { uint32_t v; static const uint32_t max = UINT32_C(0xffffffff); - ASSERT_TRUE(RE2::FullMatch("100", "(\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("100", "(\\d+)", &v)); ASSERT_EQ(v, uint32_t{100}); ASSERT_TRUE(RE2::FullMatch("4294967295", "(\\d+)", &v)); ASSERT_EQ(v, max); ASSERT_FALSE(RE2::FullMatch("4294967296", "(\\d+)", &v)); ASSERT_FALSE(RE2::FullMatch("-1", "(\\d+)", &v)); @@ -875,7 +884,7 @@ TEST(RE2, FullMatchTypeTests) { static const uint64_t max = UINT64_C(0xffffffffffffffff); std::string str; - ASSERT_TRUE(RE2::FullMatch("100", "(-?\\d+)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch("100", "(-?\\d+)", &v)); ASSERT_EQ(v, uint64_t{100}); ASSERT_TRUE(RE2::FullMatch("-100", "(-?\\d+)", &v2)); ASSERT_EQ(v2, -100); str = std::to_string(max); @@ -893,11 +902,11 @@ TEST(RE2, FloatingPointFullMatchTypes) { float v; ASSERT_TRUE(RE2::FullMatch("100", "(.*)", &v)); ASSERT_EQ(v, 100); ASSERT_TRUE(RE2::FullMatch("-100.", "(.*)", &v)); ASSERT_EQ(v, -100); - ASSERT_TRUE(RE2::FullMatch("1e23", "(.*)", &v)); ASSERT_EQ(v, float(1e23)); + ASSERT_TRUE(RE2::FullMatch("1e23", "(.*)", &v)); ASSERT_EQ(v, float{1e23}); ASSERT_TRUE(RE2::FullMatch(" 100", "(.*)", &v)); ASSERT_EQ(v, 100); ASSERT_TRUE(RE2::FullMatch(zeros + "1e23", "(.*)", &v)); - ASSERT_EQ(v, float(1e23)); + ASSERT_EQ(v, float{1e23}); // 6700000000081920.1 is an edge case. // 6700000000081920 is exactly halfway between @@ -926,9 +935,11 @@ TEST(RE2, FloatingPointFullMatchTypes) { double v; ASSERT_TRUE(RE2::FullMatch("100", "(.*)", &v)); ASSERT_EQ(v, 100); ASSERT_TRUE(RE2::FullMatch("-100.", "(.*)", &v)); ASSERT_EQ(v, -100); - ASSERT_TRUE(RE2::FullMatch("1e23", "(.*)", &v)); ASSERT_EQ(v, 1e23); + ASSERT_TRUE(RE2::FullMatch("1e23", "(.*)", &v)); ASSERT_EQ(v, double{1e23}); + ASSERT_TRUE(RE2::FullMatch(" 100", "(.*)", &v)); ASSERT_EQ(v, 100); + ASSERT_TRUE(RE2::FullMatch(zeros + "1e23", "(.*)", &v)); - ASSERT_EQ(v, double(1e23)); + ASSERT_EQ(v, double{1e23}); ASSERT_TRUE(RE2::FullMatch("0.1", "(.*)", &v)); ASSERT_EQ(v, 0.1) << absl::StrFormat("%.17g != %.17g", v, 0.1); @@ -1562,7 +1573,7 @@ TEST(RE2, Bug18391750) { TEST(RE2, Bug18458852) { // Bug in parser accepting invalid (too large) rune, - // causing compiler to fail in DCHECK in UTF-8 + // causing compiler to fail in ABSL_DCHECK() in UTF-8 // character class code. const char b[] = { (char)0x28, (char)0x05, (char)0x05, (char)0x41, (char)0x41, (char)0x28, @@ -1598,7 +1609,7 @@ TEST(RE2, Bug18523943) { TEST(RE2, Bug21371806) { // Bug in parser accepting Unicode groups in Latin-1 mode, - // causing compiler to fail in DCHECK in prog.cc. + // causing compiler to fail in ABSL_DCHECK() in prog.cc. RE2::Options opt; opt.set_encoding(RE2::Options::EncodingLatin1); @@ -1658,4 +1669,23 @@ TEST(RE2, Issue310) { ASSERT_EQ(m, "") << " got m='" << m << "', want ''"; } +TEST(RE2, Issue477) { + // Regexp::LeadingString didn't output Latin1 into flags. + // In the given pattern, 0xA5 should be factored out, but + // shouldn't lose its Latin1-ness in the process. Because + // that was happening, the prefix for accel was 0xC2 0xA5 + // instead of 0xA5. Note that the former doesn't occur in + // the given input and so replacements weren't occurring. + + const char bytes[] = { + (char)0xa5, (char)0xd1, (char)0xa5, (char)0xd1, + (char)0x61, (char)0x63, (char)0xa5, (char)0x64, + }; + std::string s(bytes, ABSL_ARRAYSIZE(bytes)); + RE2 re("\xa5\xd1|\xa5\x64", RE2::Latin1); + int n = RE2::GlobalReplace(&s, re, ""); + ASSERT_EQ(n, 3); + ASSERT_EQ(s, "\x61\x63"); +} + } // namespace re2 diff --git a/re2/testing/regexp_benchmark.cc b/re2/testing/regexp_benchmark.cc index 5352b3101..3b0a5330b 100644 --- a/re2/testing/regexp_benchmark.cc +++ b/re2/testing/regexp_benchmark.cc @@ -7,20 +7,22 @@ #include #include #include + #include #include -#include #include "absl/container/flat_hash_map.h" #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "benchmark/benchmark.h" -#include "util/logging.h" -#include "util/malloc_counter.h" #include "re2/prog.h" #include "re2/re2.h" #include "re2/regexp.h" +#include "util/malloc_counter.h" #include "util/pcre.h" namespace re2 { @@ -34,21 +36,22 @@ namespace re2 { void Test() { Regexp* re = Regexp::Parse("(\\d+)-(\\d+)-(\\d+)", Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->IsOnePass()); - CHECK(prog->CanBitState()); + ABSL_CHECK(prog); + ABSL_CHECK(prog->IsOnePass()); + ABSL_CHECK(prog->CanBitState()); const char* text = "650-253-0001"; absl::string_view sp[4]; - CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); - CHECK_EQ(sp[0], "650-253-0001"); - CHECK_EQ(sp[1], "650"); - CHECK_EQ(sp[2], "253"); - CHECK_EQ(sp[3], "0001"); + ABSL_CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, + sp, 4)); + ABSL_CHECK_EQ(sp[0], "650-253-0001"); + ABSL_CHECK_EQ(sp[1], "650"); + ABSL_CHECK_EQ(sp[2], "253"); + ABSL_CHECK_EQ(sp[3], "0001"); delete prog; re->Decref(); - LOG(INFO) << "test passed\n"; + ABSL_LOG(INFO) << "test passed\n"; } void MemoryUsage() { @@ -57,23 +60,25 @@ void MemoryUsage() { { MallocCounter mc(MallocCounter::THIS_THREAD_ONLY); Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); - // Can't pass mc.HeapGrowth() and mc.PeakHeapGrowth() to LOG(INFO) directly, - // because LOG(INFO) might do a big allocation before they get evaluated. + ABSL_CHECK(re); + // Can't pass mc.HeapGrowth() and mc.PeakHeapGrowth() to ABSL_LOG(INFO) + // directly because ABSL_LOG(INFO) might do a big allocation before they + // get evaluated. absl::FPrintF(stderr, "Regexp: %7d bytes (peak=%d)\n", mc.HeapGrowth(), mc.PeakHeapGrowth()); mc.Reset(); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->IsOnePass()); - CHECK(prog->CanBitState()); + ABSL_CHECK(prog); + ABSL_CHECK(prog->IsOnePass()); + ABSL_CHECK(prog->CanBitState()); absl::FPrintF(stderr, "Prog: %7d bytes (peak=%d)\n", mc.HeapGrowth(), mc.PeakHeapGrowth()); mc.Reset(); absl::string_view sp[4]; - CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); + ABSL_CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 4)); absl::FPrintF(stderr, "Search: %7d bytes (peak=%d)\n", mc.HeapGrowth(), mc.PeakHeapGrowth()); delete prog; @@ -168,7 +173,7 @@ std::string RandomText(int64_t nbytes) { } return text; }(); - CHECK_LE(nbytes, 16<<20); + ABSL_CHECK_LE(nbytes, 16<<20); return text->substr(0, nbytes); } @@ -319,8 +324,8 @@ void FindAndConsume(benchmark::State& state) { for (auto _ : state) { absl::string_view t = s; absl::string_view u; - CHECK(RE2::FindAndConsume(&t, re, &u)); - CHECK_EQ(u, "Hello World"); + ABSL_CHECK(RE2::FindAndConsume(&t, re, &u)); + ABSL_CHECK_EQ(u, "Hello World"); } state.SetBytesProcessed(state.iterations() * state.range(0)); } @@ -660,7 +665,7 @@ BENCHMARK(Parse_CachedSplitBig2_RE2)->ThreadRange(1, NumCPUs()); void ParseRegexp(benchmark::State& state, const std::string& regexp) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); re->Decref(); } } @@ -668,9 +673,9 @@ void ParseRegexp(benchmark::State& state, const std::string& regexp) { void SimplifyRegexp(benchmark::State& state, const std::string& regexp) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Regexp* sre = re->Simplify(); - CHECK(sre); + ABSL_CHECK(sre); sre->Decref(); re->Decref(); } @@ -678,7 +683,7 @@ void SimplifyRegexp(benchmark::State& state, const std::string& regexp) { void NullWalkRegexp(benchmark::State& state, const std::string& regexp) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); for (auto _ : state) { re->NullWalk(); } @@ -688,11 +693,11 @@ void NullWalkRegexp(benchmark::State& state, const std::string& regexp) { void SimplifyCompileRegexp(benchmark::State& state, const std::string& regexp) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Regexp* sre = re->Simplify(); - CHECK(sre); + ABSL_CHECK(sre); Prog* prog = sre->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); delete prog; sre->Decref(); re->Decref(); @@ -702,9 +707,9 @@ void SimplifyCompileRegexp(benchmark::State& state, const std::string& regexp) { void CompileRegexp(benchmark::State& state, const std::string& regexp) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); delete prog; re->Decref(); } @@ -712,10 +717,10 @@ void CompileRegexp(benchmark::State& state, const std::string& regexp) { void CompileToProg(benchmark::State& state, const std::string& regexp) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); for (auto _ : state) { Prog* prog = re->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); delete prog; } re->Decref(); @@ -723,9 +728,9 @@ void CompileToProg(benchmark::State& state, const std::string& regexp) { void CompileByteMap(benchmark::State& state, const std::string& regexp) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); for (auto _ : state) { prog->ComputeByteMap(); } @@ -736,14 +741,14 @@ void CompileByteMap(benchmark::State& state, const std::string& regexp) { void CompilePCRE(benchmark::State& state, const std::string& regexp) { for (auto _ : state) { PCRE re(regexp, PCRE::UTF8); - CHECK_EQ(re.error(), ""); + ABSL_CHECK_EQ(re.error(), ""); } } void CompileRE2(benchmark::State& state, const std::string& regexp) { for (auto _ : state) { RE2 re(regexp); - CHECK_EQ(re.error(), ""); + ABSL_CHECK_EQ(re.error(), ""); } } @@ -862,14 +867,14 @@ void SearchDFA(benchmark::State& state, const char* regexp, bool expect_match) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); bool failed = false; - CHECK_EQ(prog->SearchDFA(text, absl::string_view(), anchor, - Prog::kFirstMatch, NULL, &failed, NULL), - expect_match); - CHECK(!failed); + ABSL_CHECK_EQ(prog->SearchDFA(text, absl::string_view(), anchor, + Prog::kFirstMatch, NULL, &failed, NULL), + expect_match); + ABSL_CHECK(!failed); delete prog; re->Decref(); } @@ -880,12 +885,12 @@ void SearchNFA(benchmark::State& state, const char* regexp, bool expect_match) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK_EQ(prog->SearchNFA(text, absl::string_view(), anchor, - Prog::kFirstMatch, NULL, 0), - expect_match); + ABSL_CHECK(prog); + ABSL_CHECK_EQ(prog->SearchNFA(text, absl::string_view(), anchor, + Prog::kFirstMatch, NULL, 0), + expect_match); delete prog; re->Decref(); } @@ -896,12 +901,13 @@ void SearchOnePass(benchmark::State& state, const char* regexp, bool expect_match) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->IsOnePass()); - CHECK_EQ(prog->SearchOnePass(text, text, anchor, Prog::kFirstMatch, NULL, 0), - expect_match); + ABSL_CHECK(prog); + ABSL_CHECK(prog->IsOnePass()); + ABSL_CHECK_EQ( + prog->SearchOnePass(text, text, anchor, Prog::kFirstMatch, NULL, 0), + expect_match); delete prog; re->Decref(); } @@ -912,12 +918,13 @@ void SearchBitState(benchmark::State& state, const char* regexp, bool expect_match) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->CanBitState()); - CHECK_EQ(prog->SearchBitState(text, text, anchor, Prog::kFirstMatch, NULL, 0), - expect_match); + ABSL_CHECK(prog); + ABSL_CHECK(prog->CanBitState()); + ABSL_CHECK_EQ( + prog->SearchBitState(text, text, anchor, Prog::kFirstMatch, NULL, 0), + expect_match); delete prog; re->Decref(); } @@ -928,11 +935,12 @@ void SearchPCRE(benchmark::State& state, const char* regexp, bool expect_match) { for (auto _ : state) { PCRE re(regexp, PCRE::UTF8); - CHECK_EQ(re.error(), ""); - if (anchor == Prog::kAnchored) - CHECK_EQ(PCRE::FullMatch(text, re), expect_match); - else - CHECK_EQ(PCRE::PartialMatch(text, re), expect_match); + ABSL_CHECK_EQ(re.error(), ""); + if (anchor == Prog::kAnchored) { + ABSL_CHECK_EQ(PCRE::FullMatch(text, re), expect_match); + } else { + ABSL_CHECK_EQ(PCRE::PartialMatch(text, re), expect_match); + } } } @@ -941,11 +949,12 @@ void SearchRE2(benchmark::State& state, const char* regexp, bool expect_match) { for (auto _ : state) { RE2 re(regexp); - CHECK_EQ(re.error(), ""); - if (anchor == Prog::kAnchored) - CHECK_EQ(RE2::FullMatch(text, re), expect_match); - else - CHECK_EQ(RE2::PartialMatch(text, re), expect_match); + ABSL_CHECK_EQ(re.error(), ""); + if (anchor == Prog::kAnchored) { + ABSL_CHECK_EQ(RE2::FullMatch(text, re), expect_match); + } else { + ABSL_CHECK_EQ(RE2::PartialMatch(text, re), expect_match); + } } } @@ -960,9 +969,9 @@ Prog* GetCachedProg(const char* regexp) { Prog* prog = cache[regexp]; if (prog == NULL) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); prog = re->CompileToProg(int64_t{1}<<31); // mostly for the DFA - CHECK(prog); + ABSL_CHECK(prog); cache[regexp] = prog; re->Decref(); // We must call this here - while we have exclusive access. @@ -978,7 +987,7 @@ PCRE* GetCachedPCRE(const char* regexp) { PCRE* re = cache[regexp]; if (re == NULL) { re = new PCRE(regexp, PCRE::UTF8); - CHECK_EQ(re->error(), ""); + ABSL_CHECK_EQ(re->error(), ""); cache[regexp] = re; } return re; @@ -991,7 +1000,7 @@ RE2* GetCachedRE2(const char* regexp) { RE2* re = cache[regexp]; if (re == NULL) { re = new RE2(regexp); - CHECK_EQ(re->error(), ""); + ABSL_CHECK_EQ(re->error(), ""); cache[regexp] = re; } return re; @@ -1003,10 +1012,10 @@ void SearchCachedDFA(benchmark::State& state, const char* regexp, Prog* prog = GetCachedProg(regexp); for (auto _ : state) { bool failed = false; - CHECK_EQ(prog->SearchDFA(text, absl::string_view(), anchor, + ABSL_CHECK_EQ(prog->SearchDFA(text, absl::string_view(), anchor, Prog::kFirstMatch, NULL, &failed, NULL), expect_match); - CHECK(!failed); + ABSL_CHECK(!failed); } } @@ -1015,7 +1024,7 @@ void SearchCachedNFA(benchmark::State& state, const char* regexp, bool expect_match) { Prog* prog = GetCachedProg(regexp); for (auto _ : state) { - CHECK_EQ(prog->SearchNFA(text, absl::string_view(), anchor, + ABSL_CHECK_EQ(prog->SearchNFA(text, absl::string_view(), anchor, Prog::kFirstMatch, NULL, 0), expect_match); } @@ -1025,10 +1034,11 @@ void SearchCachedOnePass(benchmark::State& state, const char* regexp, absl::string_view text, Prog::Anchor anchor, bool expect_match) { Prog* prog = GetCachedProg(regexp); - CHECK(prog->IsOnePass()); + ABSL_CHECK(prog->IsOnePass()); for (auto _ : state) { - CHECK_EQ(prog->SearchOnePass(text, text, anchor, Prog::kFirstMatch, NULL, 0), - expect_match); + ABSL_CHECK_EQ( + prog->SearchOnePass(text, text, anchor, Prog::kFirstMatch, NULL, 0), + expect_match); } } @@ -1036,10 +1046,11 @@ void SearchCachedBitState(benchmark::State& state, const char* regexp, absl::string_view text, Prog::Anchor anchor, bool expect_match) { Prog* prog = GetCachedProg(regexp); - CHECK(prog->CanBitState()); + ABSL_CHECK(prog->CanBitState()); for (auto _ : state) { - CHECK_EQ(prog->SearchBitState(text, text, anchor, Prog::kFirstMatch, NULL, 0), - expect_match); + ABSL_CHECK_EQ( + prog->SearchBitState(text, text, anchor, Prog::kFirstMatch, NULL, 0), + expect_match); } } @@ -1048,10 +1059,11 @@ void SearchCachedPCRE(benchmark::State& state, const char* regexp, bool expect_match) { PCRE& re = *GetCachedPCRE(regexp); for (auto _ : state) { - if (anchor == Prog::kAnchored) - CHECK_EQ(PCRE::FullMatch(text, re), expect_match); - else - CHECK_EQ(PCRE::PartialMatch(text, re), expect_match); + if (anchor == Prog::kAnchored) { + ABSL_CHECK_EQ(PCRE::FullMatch(text, re), expect_match); + } else { + ABSL_CHECK_EQ(PCRE::PartialMatch(text, re), expect_match); + } } } @@ -1060,10 +1072,11 @@ void SearchCachedRE2(benchmark::State& state, const char* regexp, bool expect_match) { RE2& re = *GetCachedRE2(regexp); for (auto _ : state) { - if (anchor == Prog::kAnchored) - CHECK_EQ(RE2::FullMatch(text, re), expect_match); - else - CHECK_EQ(RE2::PartialMatch(text, re), expect_match); + if (anchor == Prog::kAnchored) { + ABSL_CHECK_EQ(RE2::FullMatch(text, re), expect_match); + } else { + ABSL_CHECK_EQ(RE2::PartialMatch(text, re), expect_match); + } } } @@ -1074,11 +1087,11 @@ void Parse3NFA(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); absl::string_view sp[4]; // 4 because sp[0] is whole match. - CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, + ABSL_CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, Prog::kFullMatch, sp, 4)); delete prog; re->Decref(); @@ -1089,12 +1102,13 @@ void Parse3OnePass(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->IsOnePass()); + ABSL_CHECK(prog); + ABSL_CHECK(prog->IsOnePass()); absl::string_view sp[4]; // 4 because sp[0] is whole match. - CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); + ABSL_CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 4)); delete prog; re->Decref(); } @@ -1104,12 +1118,13 @@ void Parse3BitState(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->CanBitState()); + ABSL_CHECK(prog); + ABSL_CHECK(prog->CanBitState()); absl::string_view sp[4]; // 4 because sp[0] is whole match. - CHECK(prog->SearchBitState(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); + ABSL_CHECK(prog->SearchBitState(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 4)); delete prog; re->Decref(); } @@ -1119,11 +1134,12 @@ void Parse3Backtrack(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); absl::string_view sp[4]; // 4 because sp[0] is whole match. - CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); + ABSL_CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 4)); delete prog; re->Decref(); } @@ -1133,9 +1149,9 @@ void Parse3PCRE(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { PCRE re(regexp, PCRE::UTF8); - CHECK_EQ(re.error(), ""); + ABSL_CHECK_EQ(re.error(), ""); absl::string_view sp1, sp2, sp3; - CHECK(PCRE::FullMatch(text, re, &sp1, &sp2, &sp3)); + ABSL_CHECK(PCRE::FullMatch(text, re, &sp1, &sp2, &sp3)); } } @@ -1143,9 +1159,9 @@ void Parse3RE2(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { RE2 re(regexp); - CHECK_EQ(re.error(), ""); + ABSL_CHECK_EQ(re.error(), ""); absl::string_view sp1, sp2, sp3; - CHECK(RE2::FullMatch(text, re, &sp1, &sp2, &sp3)); + ABSL_CHECK(RE2::FullMatch(text, re, &sp1, &sp2, &sp3)); } } @@ -1154,7 +1170,7 @@ void Parse3CachedNFA(benchmark::State& state, const char* regexp, Prog* prog = GetCachedProg(regexp); absl::string_view sp[4]; // 4 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, + ABSL_CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, Prog::kFullMatch, sp, 4)); } } @@ -1162,20 +1178,22 @@ void Parse3CachedNFA(benchmark::State& state, const char* regexp, void Parse3CachedOnePass(benchmark::State& state, const char* regexp, absl::string_view text) { Prog* prog = GetCachedProg(regexp); - CHECK(prog->IsOnePass()); + ABSL_CHECK(prog->IsOnePass()); absl::string_view sp[4]; // 4 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); + ABSL_CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 4)); } } void Parse3CachedBitState(benchmark::State& state, const char* regexp, absl::string_view text) { Prog* prog = GetCachedProg(regexp); - CHECK(prog->CanBitState()); + ABSL_CHECK(prog->CanBitState()); absl::string_view sp[4]; // 4 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->SearchBitState(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); + ABSL_CHECK(prog->SearchBitState(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 4)); } } @@ -1184,7 +1202,8 @@ void Parse3CachedBacktrack(benchmark::State& state, const char* regexp, Prog* prog = GetCachedProg(regexp); absl::string_view sp[4]; // 4 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 4)); + ABSL_CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 4)); } } @@ -1193,7 +1212,7 @@ void Parse3CachedPCRE(benchmark::State& state, const char* regexp, PCRE& re = *GetCachedPCRE(regexp); absl::string_view sp1, sp2, sp3; for (auto _ : state) { - CHECK(PCRE::FullMatch(text, re, &sp1, &sp2, &sp3)); + ABSL_CHECK(PCRE::FullMatch(text, re, &sp1, &sp2, &sp3)); } } @@ -1202,7 +1221,7 @@ void Parse3CachedRE2(benchmark::State& state, const char* regexp, RE2& re = *GetCachedRE2(regexp); absl::string_view sp1, sp2, sp3; for (auto _ : state) { - CHECK(RE2::FullMatch(text, re, &sp1, &sp2, &sp3)); + ABSL_CHECK(RE2::FullMatch(text, re, &sp1, &sp2, &sp3)); } } @@ -1213,12 +1232,12 @@ void Parse1NFA(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); + ABSL_CHECK(prog); absl::string_view sp[2]; // 2 because sp[0] is whole match. - CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, - Prog::kFullMatch, sp, 2)); + ABSL_CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, + Prog::kFullMatch, sp, 2)); delete prog; re->Decref(); } @@ -1228,12 +1247,13 @@ void Parse1OnePass(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->IsOnePass()); + ABSL_CHECK(prog); + ABSL_CHECK(prog->IsOnePass()); absl::string_view sp[2]; // 2 because sp[0] is whole match. - CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2)); + ABSL_CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 2)); delete prog; re->Decref(); } @@ -1243,12 +1263,13 @@ void Parse1BitState(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { Regexp* re = Regexp::Parse(regexp, Regexp::LikePerl, NULL); - CHECK(re); + ABSL_CHECK(re); Prog* prog = re->CompileToProg(0); - CHECK(prog); - CHECK(prog->CanBitState()); + ABSL_CHECK(prog); + ABSL_CHECK(prog->CanBitState()); absl::string_view sp[2]; // 2 because sp[0] is whole match. - CHECK(prog->SearchBitState(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2)); + ABSL_CHECK(prog->SearchBitState(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 2)); delete prog; re->Decref(); } @@ -1258,9 +1279,9 @@ void Parse1PCRE(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { PCRE re(regexp, PCRE::UTF8); - CHECK_EQ(re.error(), ""); + ABSL_CHECK_EQ(re.error(), ""); absl::string_view sp1; - CHECK(PCRE::FullMatch(text, re, &sp1)); + ABSL_CHECK(PCRE::FullMatch(text, re, &sp1)); } } @@ -1268,9 +1289,9 @@ void Parse1RE2(benchmark::State& state, const char* regexp, absl::string_view text) { for (auto _ : state) { RE2 re(regexp); - CHECK_EQ(re.error(), ""); + ABSL_CHECK_EQ(re.error(), ""); absl::string_view sp1; - CHECK(RE2::FullMatch(text, re, &sp1)); + ABSL_CHECK(RE2::FullMatch(text, re, &sp1)); } } @@ -1279,7 +1300,7 @@ void Parse1CachedNFA(benchmark::State& state, const char* regexp, Prog* prog = GetCachedProg(regexp); absl::string_view sp[2]; // 2 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, + ABSL_CHECK(prog->SearchNFA(text, absl::string_view(), Prog::kAnchored, Prog::kFullMatch, sp, 2)); } } @@ -1287,20 +1308,22 @@ void Parse1CachedNFA(benchmark::State& state, const char* regexp, void Parse1CachedOnePass(benchmark::State& state, const char* regexp, absl::string_view text) { Prog* prog = GetCachedProg(regexp); - CHECK(prog->IsOnePass()); + ABSL_CHECK(prog->IsOnePass()); absl::string_view sp[2]; // 2 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2)); + ABSL_CHECK(prog->SearchOnePass(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 2)); } } void Parse1CachedBitState(benchmark::State& state, const char* regexp, absl::string_view text) { Prog* prog = GetCachedProg(regexp); - CHECK(prog->CanBitState()); + ABSL_CHECK(prog->CanBitState()); absl::string_view sp[2]; // 2 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->SearchBitState(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2)); + ABSL_CHECK(prog->SearchBitState(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 2)); } } @@ -1309,7 +1332,8 @@ void Parse1CachedBacktrack(benchmark::State& state, const char* regexp, Prog* prog = GetCachedProg(regexp); absl::string_view sp[2]; // 2 because sp[0] is whole match. for (auto _ : state) { - CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, Prog::kFullMatch, sp, 2)); + ABSL_CHECK(prog->UnsafeSearchBacktrack(text, text, Prog::kAnchored, + Prog::kFullMatch, sp, 2)); } } @@ -1318,7 +1342,7 @@ void Parse1CachedPCRE(benchmark::State& state, const char* regexp, PCRE& re = *GetCachedPCRE(regexp); absl::string_view sp1; for (auto _ : state) { - CHECK(PCRE::FullMatch(text, re, &sp1)); + ABSL_CHECK(PCRE::FullMatch(text, re, &sp1)); } } @@ -1327,7 +1351,7 @@ void Parse1CachedRE2(benchmark::State& state, const char* regexp, RE2& re = *GetCachedRE2(regexp); absl::string_view sp1; for (auto _ : state) { - CHECK(RE2::FullMatch(text, re, &sp1)); + ABSL_CHECK(RE2::FullMatch(text, re, &sp1)); } } @@ -1336,7 +1360,7 @@ void SearchParse2CachedPCRE(benchmark::State& state, const char* regexp, PCRE& re = *GetCachedPCRE(regexp); for (auto _ : state) { absl::string_view sp1, sp2; - CHECK(PCRE::PartialMatch(text, re, &sp1, &sp2)); + ABSL_CHECK(PCRE::PartialMatch(text, re, &sp1, &sp2)); } } @@ -1345,7 +1369,7 @@ void SearchParse2CachedRE2(benchmark::State& state, const char* regexp, RE2& re = *GetCachedRE2(regexp); for (auto _ : state) { absl::string_view sp1, sp2; - CHECK(RE2::PartialMatch(text, re, &sp1, &sp2)); + ABSL_CHECK(RE2::PartialMatch(text, re, &sp1, &sp2)); } } @@ -1354,7 +1378,7 @@ void SearchParse1CachedPCRE(benchmark::State& state, const char* regexp, PCRE& re = *GetCachedPCRE(regexp); for (auto _ : state) { absl::string_view sp1; - CHECK(PCRE::PartialMatch(text, re, &sp1)); + ABSL_CHECK(PCRE::PartialMatch(text, re, &sp1)); } } @@ -1363,7 +1387,7 @@ void SearchParse1CachedRE2(benchmark::State& state, const char* regexp, RE2& re = *GetCachedRE2(regexp); for (auto _ : state) { absl::string_view sp1; - CHECK(RE2::PartialMatch(text, re, &sp1)); + ABSL_CHECK(RE2::PartialMatch(text, re, &sp1)); } } @@ -1499,7 +1523,7 @@ void FullMatchPCRE(benchmark::State& state, const char *regexp) { s += "ABCDEFGHIJ"; PCRE re(regexp); for (auto _ : state) { - CHECK(PCRE::FullMatch(s, re)); + ABSL_CHECK(PCRE::FullMatch(s, re)); } state.SetBytesProcessed(state.iterations() * state.range(0)); } @@ -1509,19 +1533,31 @@ void FullMatchRE2(benchmark::State& state, const char *regexp) { s += "ABCDEFGHIJ"; RE2 re(regexp, RE2::Latin1); for (auto _ : state) { - CHECK(RE2::FullMatch(s, re)); + ABSL_CHECK(RE2::FullMatch(s, re)); } state.SetBytesProcessed(state.iterations() * state.range(0)); } -void FullMatch_DotStar_CachedPCRE(benchmark::State& state) { FullMatchPCRE(state, "(?s).*"); } -void FullMatch_DotStar_CachedRE2(benchmark::State& state) { FullMatchRE2(state, "(?s).*"); } +void FullMatch_DotStar_CachedPCRE(benchmark::State& state) { + FullMatchPCRE(state, "(?s).*"); +} +void FullMatch_DotStar_CachedRE2(benchmark::State& state) { + FullMatchRE2(state, "(?s).*"); +} -void FullMatch_DotStarDollar_CachedPCRE(benchmark::State& state) { FullMatchPCRE(state, "(?s).*$"); } -void FullMatch_DotStarDollar_CachedRE2(benchmark::State& state) { FullMatchRE2(state, "(?s).*$"); } +void FullMatch_DotStarDollar_CachedPCRE(benchmark::State& state) { + FullMatchPCRE(state, "(?s).*$"); +} +void FullMatch_DotStarDollar_CachedRE2(benchmark::State& state) { + FullMatchRE2(state, "(?s).*$"); +} -void FullMatch_DotStarCapture_CachedPCRE(benchmark::State& state) { FullMatchPCRE(state, "(?s)((.*)()()($))"); } -void FullMatch_DotStarCapture_CachedRE2(benchmark::State& state) { FullMatchRE2(state, "(?s)((.*)()()($))"); } +void FullMatch_DotStarCapture_CachedPCRE(benchmark::State& state) { + FullMatchPCRE(state, "(?s)((.*)()()($))"); +} +void FullMatch_DotStarCapture_CachedRE2(benchmark::State& state) { + FullMatchRE2(state, "(?s)((.*)()()($))"); +} #ifdef USEPCRE BENCHMARK_RANGE(FullMatch_DotStar_CachedPCRE, 8, 2<<20); @@ -1544,7 +1580,7 @@ void PossibleMatchRangeCommon(benchmark::State& state, const char* regexp) { std::string max; const int kMaxLen = 16; for (auto _ : state) { - CHECK(re.PossibleMatchRange(&min, &max, kMaxLen)); + ABSL_CHECK(re.PossibleMatchRange(&min, &max, kMaxLen)); } } diff --git a/re2/testing/regexp_generator.cc b/re2/testing/regexp_generator.cc index b1761ed93..a702e7d83 100644 --- a/re2/testing/regexp_generator.cc +++ b/re2/testing/regexp_generator.cc @@ -20,22 +20,26 @@ // Then RunPostfix turns each sequence into a regular expression // and passes the regexp to HandleRegexp. +#include "re2/testing/regexp_generator.h" + #include #include #include #include + #include +#include #include #include #include #include "absl/base/macros.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/escaping.h" #include "absl/strings/str_format.h" -#include "gtest/gtest.h" -#include "util/logging.h" +#include "absl/strings/string_view.h" #include "util/utf.h" -#include "re2/testing/regexp_generator.h" namespace re2 { @@ -196,13 +200,13 @@ void RegexpGenerator::RunPostfix(const std::vector& post) { for (size_t i = 0; i < post.size(); i++) { switch (CountArgs(post[i])) { default: - LOG(FATAL) << "Bad operator: " << post[i]; + ABSL_LOG(FATAL) << "Bad operator: " << post[i]; case 0: regexps.push(post[i]); break; case 1: { auto fmt = absl::ParsedFormat<'s'>::New(post[i]); - CHECK(fmt != nullptr); + ABSL_CHECK(fmt != nullptr); std::string a = regexps.top(); regexps.pop(); regexps.push("(?:" + absl::StrFormat(*fmt, a) + ")"); @@ -210,7 +214,7 @@ void RegexpGenerator::RunPostfix(const std::vector& post) { } case 2: { auto fmt = absl::ParsedFormat<'s', 's'>::New(post[i]); - CHECK(fmt != nullptr); + ABSL_CHECK(fmt != nullptr); std::string b = regexps.top(); regexps.pop(); std::string a = regexps.top(); @@ -232,7 +236,7 @@ void RegexpGenerator::RunPostfix(const std::vector& post) { absl::PrintF(" %s\n", absl::CEscape(regexps.top())); regexps.pop(); } - LOG(FATAL) << "Bad regexp program."; + ABSL_LOG(FATAL) << "Bad regexp program."; } HandleRegexp(regexps.top()); diff --git a/re2/testing/regexp_generator.h b/re2/testing/regexp_generator.h index e1be1a93d..bb2128da8 100644 --- a/re2/testing/regexp_generator.h +++ b/re2/testing/regexp_generator.h @@ -9,6 +9,7 @@ // regular expressions within given parameters (see below for details). #include + #include #include #include diff --git a/re2/testing/regexp_test.cc b/re2/testing/regexp_test.cc index ef8f59d36..edbbe0839 100644 --- a/re2/testing/regexp_test.cc +++ b/re2/testing/regexp_test.cc @@ -4,14 +4,15 @@ // Test parse.cc, dump.cc, and tostring.cc. +#include "re2/regexp.h" + #include + #include #include #include #include "gtest/gtest.h" -#include "util/logging.h" -#include "re2/regexp.h" namespace re2 { @@ -53,8 +54,8 @@ TEST(Regexp, NamedCaptures) { EXPECT_EQ(4, x->NumCaptures()); const std::map* have = x->NamedCaptures(); EXPECT_TRUE(have != NULL); - EXPECT_EQ(2, have->size()); // there are only two named groups in - // the regexp: 'g1' and 'g2'. + // there are only two named groups in the regexp: 'g1' and 'g2'. + EXPECT_EQ(size_t{2}, have->size()); std::map want; want["g1"] = 1; want["g2"] = 3; @@ -72,7 +73,7 @@ TEST(Regexp, CaptureNames) { EXPECT_EQ(4, x->NumCaptures()); const std::map* have = x->CaptureNames(); EXPECT_TRUE(have != NULL); - EXPECT_EQ(3, have->size()); + EXPECT_EQ(size_t{3}, have->size()); std::map want; want[1] = "g1"; want[3] = "g2"; diff --git a/re2/testing/required_prefix_test.cc b/re2/testing/required_prefix_test.cc index 231fd3485..ab7f4121f 100644 --- a/re2/testing/required_prefix_test.cc +++ b/re2/testing/required_prefix_test.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include + #include #include "absl/base/macros.h" #include "gtest/gtest.h" -#include "util/logging.h" #include "re2/prog.h" #include "re2/regexp.h" diff --git a/re2/testing/search_test.cc b/re2/testing/search_test.cc index 166652a2d..0d0cb78b1 100644 --- a/re2/testing/search_test.cc +++ b/re2/testing/search_test.cc @@ -2,12 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include + +#include +#include + #include "absl/base/macros.h" #include "gtest/gtest.h" -#include "re2/prog.h" -#include "re2/regexp.h" -#include "re2/testing/tester.h" #include "re2/testing/exhaustive_tester.h" +#include "re2/testing/tester.h" // For target `log' in the Makefile. #ifndef LOGGING diff --git a/re2/testing/set_test.cc b/re2/testing/set_test.cc index fdbc0b2c7..b4aaf92a1 100644 --- a/re2/testing/set_test.cc +++ b/re2/testing/set_test.cc @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +#include "re2/set.h" + #include -#include -#include + #include +#include #include "gtest/gtest.h" -#include "util/logging.h" #include "re2/re2.h" -#include "re2/set.h" namespace re2 { @@ -28,16 +28,16 @@ TEST(Set, Unanchored) { std::vector v; ASSERT_EQ(s.Match("foobar", &v), true); - ASSERT_EQ(v.size(), 2); + ASSERT_EQ(v.size(), size_t{2}); ASSERT_EQ(v[0], 0); ASSERT_EQ(v[1], 1); ASSERT_EQ(s.Match("fooba", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); ASSERT_EQ(s.Match("oobar", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 1); } @@ -56,21 +56,21 @@ TEST(Set, UnanchoredFactored) { std::vector v; ASSERT_EQ(s.Match("foobar", &v), true); - ASSERT_EQ(v.size(), 2); + ASSERT_EQ(v.size(), size_t{2}); ASSERT_EQ(v[0], 0); ASSERT_EQ(v[1], 1); ASSERT_EQ(s.Match("obarfoobaroo", &v), true); - ASSERT_EQ(v.size(), 2); + ASSERT_EQ(v.size(), size_t{2}); ASSERT_EQ(v[0], 0); ASSERT_EQ(v[1], 1); ASSERT_EQ(s.Match("fooba", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); ASSERT_EQ(s.Match("oobar", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); } TEST(Set, UnanchoredDollar) { @@ -84,11 +84,11 @@ TEST(Set, UnanchoredDollar) { std::vector v; ASSERT_EQ(s.Match("foo", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); ASSERT_EQ(s.Match("foobar", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); } TEST(Set, UnanchoredWordBoundary) { @@ -103,14 +103,14 @@ TEST(Set, UnanchoredWordBoundary) { std::vector v; ASSERT_EQ(s.Match("foo", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); ASSERT_EQ(s.Match("foobar", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); ASSERT_EQ(s.Match("foo bar", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); } @@ -130,20 +130,20 @@ TEST(Set, Anchored) { std::vector v; ASSERT_EQ(s.Match("foobar", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); ASSERT_EQ(s.Match("fooba", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); ASSERT_EQ(s.Match("oobar", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); ASSERT_EQ(s.Match("foo", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); ASSERT_EQ(s.Match("bar", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 1); } @@ -157,10 +157,10 @@ TEST(Set, EmptyUnanchored) { std::vector v; ASSERT_EQ(s.Match("", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); ASSERT_EQ(s.Match("foobar", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); } TEST(Set, EmptyAnchored) { @@ -173,10 +173,10 @@ TEST(Set, EmptyAnchored) { std::vector v; ASSERT_EQ(s.Match("", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); ASSERT_EQ(s.Match("foobar", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); } TEST(Set, Prefix) { @@ -191,14 +191,14 @@ TEST(Set, Prefix) { std::vector v; ASSERT_EQ(s.Match("/prefix", &v), false); - ASSERT_EQ(v.size(), 0); + ASSERT_EQ(v.size(), size_t{0}); ASSERT_EQ(s.Match("/prefix/", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); ASSERT_EQ(s.Match("/prefix/42", &v), true); - ASSERT_EQ(v.size(), 1); + ASSERT_EQ(v.size(), size_t{1}); ASSERT_EQ(v[0], 0); } diff --git a/re2/testing/simplify_test.cc b/re2/testing/simplify_test.cc index 5b683f580..efbe96745 100644 --- a/re2/testing/simplify_test.cc +++ b/re2/testing/simplify_test.cc @@ -5,11 +5,10 @@ // Test simplify.cc. #include -#include #include "absl/base/macros.h" +#include "absl/log/absl_log.h" #include "gtest/gtest.h" -#include "util/logging.h" #include "re2/regexp.h" namespace re2 { @@ -264,7 +263,7 @@ static Test tests[] = { TEST(TestSimplify, SimpleRegexps) { for (size_t i = 0; i < ABSL_ARRAYSIZE(tests); i++) { RegexpStatus status; - VLOG(1) << "Testing " << tests[i].regexp; + ABSL_VLOG(1) << "Testing " << tests[i].regexp; Regexp* re = Regexp::Parse(tests[i].regexp, Regexp::MatchNL | (Regexp::LikePerl & ~Regexp::OneLine), diff --git a/re2/testing/string_generator.cc b/re2/testing/string_generator.cc index 1891b14a7..6e450a942 100644 --- a/re2/testing/string_generator.cc +++ b/re2/testing/string_generator.cc @@ -6,14 +6,17 @@ // maxlen letters using the set of letters in alpha. // Fetch strings using a Java-like Next()/HasNext() interface. +#include "re2/testing/string_generator.h" + #include #include + +#include #include #include -#include "gtest/gtest.h" -#include "util/logging.h" -#include "re2/testing/string_generator.h" +#include "absl/log/absl_check.h" +#include "absl/strings/string_view.h" namespace re2 { @@ -82,7 +85,7 @@ bool StringGenerator::RandomDigits() { // after computing the string, so that it knows the answer // for subsequent HasNext() calls. absl::string_view StringGenerator::Next() { - CHECK(hasnext_); + ABSL_CHECK(hasnext_); if (generate_null_) { generate_null_ = false; sp_ = absl::string_view(); @@ -112,8 +115,8 @@ void StringGenerator::GenerateNULL() { } std::string DeBruijnString(int n) { - CHECK_GE(n, 1); - CHECK_LE(n, 29); + ABSL_CHECK_GE(n, 1); + ABSL_CHECK_LE(n, 29); const size_t size = size_t{1} << static_cast(n); const size_t mask = size - 1; std::vector did(size, false); @@ -131,10 +134,10 @@ std::string DeBruijnString(int n) { } else { s += '0'; } - CHECK(!did[bits]); + ABSL_CHECK(!did[bits]); did[bits] = true; } - CHECK_EQ(s.size(), static_cast(n - 1) + size); + ABSL_CHECK_EQ(s.size(), static_cast(n - 1) + size); return s; } diff --git a/re2/testing/string_generator.h b/re2/testing/string_generator.h index 0d6f5fcba..acdb3d5f1 100644 --- a/re2/testing/string_generator.h +++ b/re2/testing/string_generator.h @@ -10,6 +10,7 @@ // Fetch strings using a Java-like Next()/HasNext() interface. #include + #include #include #include diff --git a/re2/testing/string_generator_test.cc b/re2/testing/string_generator_test.cc index b1273d9f6..909843425 100644 --- a/re2/testing/string_generator_test.cc +++ b/re2/testing/string_generator_test.cc @@ -4,13 +4,17 @@ // Test StringGenerator. +#include "re2/testing/string_generator.h" + +#include #include + #include +#include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "util/utf.h" -#include "re2/testing/string_generator.h" #include "re2/testing/regexp_generator.h" +#include "util/utf.h" namespace re2 { @@ -43,7 +47,7 @@ static void RunTest(int len, const std::string& alphabet, bool donull) { EXPECT_TRUE(g.HasNext()); absl::string_view sp = g.Next(); EXPECT_EQ(sp.data(), static_cast(NULL)); - EXPECT_EQ(sp.size(), 0); + EXPECT_EQ(sp.size(), size_t{0}); } while (g.HasNext()) { diff --git a/re2/testing/tester.cc b/re2/testing/tester.cc index a094cb4ff..72925e392 100644 --- a/re2/testing/tester.cc +++ b/re2/testing/tester.cc @@ -4,20 +4,25 @@ // Regular expression engine tester -- test all the implementations against each other. +#include "re2/testing/tester.h" + #include #include #include + #include #include "absl/base/macros.h" #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/escaping.h" #include "absl/strings/str_format.h" -#include "util/logging.h" -#include "re2/testing/tester.h" +#include "absl/strings/string_view.h" #include "re2/prog.h" #include "re2/re2.h" #include "re2/regexp.h" +#include "util/pcre.h" ABSL_FLAG(bool, dump_prog, false, "dump regexp program"); ABSL_FLAG(bool, log_okay, false, "log successful runs"); @@ -50,9 +55,9 @@ const char* engine_names[kEngineMax] = { // Returns the name of the engine. static const char* EngineName(Engine e) { - CHECK_GE(e, 0); - CHECK_LT(e, ABSL_ARRAYSIZE(engine_names)); - CHECK(engine_names[e] != NULL); + ABSL_CHECK_GE(e, 0); + ABSL_CHECK_LT(e, ABSL_ARRAYSIZE(engine_names)); + ABSL_CHECK(engine_names[e] != NULL); return engine_names[e]; } @@ -73,12 +78,12 @@ static uint32_t Engines() { } if (cached_engines == 0) - LOG(INFO) << "Warning: no engines enabled."; + ABSL_LOG(INFO) << "Warning: no engines enabled."; if (!UsingPCRE) cached_engines &= ~(1<(0); i < kEngineMax; i++) { if (cached_engines & (1<NumCaptures(); prog_ = regexp_->CompileToProg(0); if (prog_ == NULL) { - LOG(INFO) << "Cannot compile: " << absl::CEscape(regexp_str_); + ABSL_LOG(INFO) << "Cannot compile: " << absl::CEscape(regexp_str_); error_ = true; return; } if (absl::GetFlag(FLAGS_dump_prog)) { - LOG(INFO) << "Prog for " - << " regexp " - << absl::CEscape(regexp_str_) - << " (" << FormatKind(kind_) - << ", " << FormatMode(flags_) - << ")\n" - << prog_->Dump(); + ABSL_LOG(INFO) << "Prog for " + << " regexp " + << absl::CEscape(regexp_str_) + << " (" << FormatKind(kind_) + << ", " << FormatMode(flags_) + << ")\n" + << prog_->Dump(); } // Compile regexp to reversed prog. Only needed for DFA engines. if (Engines() & ((1<CompileToReverseProg(0); if (rprog_ == NULL) { - LOG(INFO) << "Cannot reverse compile: " << absl::CEscape(regexp_str_); + ABSL_LOG(INFO) << "Cannot reverse compile: " + << absl::CEscape(regexp_str_); error_ = true; return; } if (absl::GetFlag(FLAGS_dump_rprog)) - LOG(INFO) << rprog_->Dump(); + ABSL_LOG(INFO) << rprog_->Dump(); } // Create re string that will be used for RE and RE2. @@ -257,7 +263,7 @@ TestInstance::TestInstance(absl::string_view regexp_str, Prog::MatchKind kind, options.set_longest_match(true); re2_ = new RE2(re, options); if (!re2_->error().empty()) { - LOG(INFO) << "Cannot RE2: " << absl::CEscape(re); + ABSL_LOG(INFO) << "Cannot RE2: " << absl::CEscape(re); error_ = true; return; } @@ -283,7 +289,7 @@ TestInstance::TestInstance(absl::string_view regexp_str, Prog::MatchKind kind, // add one more layer of parens. re_ = new PCRE("("+re+")", o); if (!re_->error().empty()) { - LOG(INFO) << "Cannot PCRE: " << absl::CEscape(re); + ABSL_LOG(INFO) << "Cannot PCRE: " << absl::CEscape(re); error_ = true; return; } @@ -318,7 +324,7 @@ void TestInstance::RunSearch(Engine type, absl::string_view orig_text, switch (type) { default: - LOG(FATAL) << "Bad RunSearch type: " << (int)type; + ABSL_LOG(FATAL) << "Bad RunSearch type: " << (int)type; case kEngineBacktrack: if (prog_ == NULL) { @@ -366,9 +372,9 @@ void TestInstance::RunSearch(Engine type, absl::string_view orig_text, Prog::kAnchored, Prog::kLongestMatch, result->submatch, &result->skipped, NULL)) { - LOG(ERROR) << "Reverse DFA inconsistency: " - << absl::CEscape(regexp_str_) - << " on " << absl::CEscape(text); + ABSL_LOG(ERROR) << "Reverse DFA inconsistency: " + << absl::CEscape(regexp_str_) + << " on " << absl::CEscape(text); result->matched = false; } } @@ -520,16 +526,16 @@ bool TestInstance::RunCase(absl::string_view text, absl::string_view context, if (correct.skipped) { if (regexp_ == NULL) return true; - LOG(ERROR) << "Skipped backtracking! " << absl::CEscape(regexp_str_) - << " " << FormatMode(flags_); + ABSL_LOG(ERROR) << "Skipped backtracking! " << absl::CEscape(regexp_str_) + << " " << FormatMode(flags_); return false; } - VLOG(1) << "Try: regexp " << absl::CEscape(regexp_str_) - << " text " << absl::CEscape(text) - << " (" << FormatKind(kind_) - << ", " << FormatAnchor(anchor) - << ", " << FormatMode(flags_) - << ")"; + ABSL_VLOG(1) << "Try: regexp " << absl::CEscape(regexp_str_) + << " text " << absl::CEscape(text) + << " (" << FormatKind(kind_) + << ", " << FormatAnchor(anchor) + << ", " << FormatMode(flags_) + << ")"; // Compare the others. bool all_okay = true; @@ -560,22 +566,22 @@ bool TestInstance::RunCase(absl::string_view text, absl::string_view context, context, anchor); if (r.matched != correct.matched) { if (r.matched) { - LOG(INFO) << " Should not match (but does)."; + ABSL_LOG(INFO) << " Should not match (but does)."; } else { - LOG(INFO) << " Should match (but does not)."; + ABSL_LOG(INFO) << " Should match (but does not)."; continue; } } for (int i = 0; i < 1+num_captures_; i++) { if (r.submatch[i].data() != correct.submatch[i].data() || r.submatch[i].size() != correct.submatch[i].size()) { - LOG(INFO) << + ABSL_LOG(INFO) << absl::StrFormat(" $%d: should be %s is %s", i, FormatCapture(text, correct.submatch[i]), FormatCapture(text, r.submatch[i])); } else { - LOG(INFO) << + ABSL_LOG(INFO) << absl::StrFormat(" $%d: %s ok", i, FormatCapture(text, r.submatch[i])); } @@ -587,7 +593,7 @@ bool TestInstance::RunCase(absl::string_view text, absl::string_view context, // and that is desirable because we want to enforce a global limit. static int max_regexp_failures = absl::GetFlag(FLAGS_max_regexp_failures); if (max_regexp_failures > 0 && --max_regexp_failures == 0) - LOG(QFATAL) << "Too many regexp failures."; + ABSL_LOG(QFATAL) << "Too many regexp failures."; } return all_okay; @@ -596,7 +602,7 @@ bool TestInstance::RunCase(absl::string_view text, absl::string_view context, void TestInstance::LogMatch(const char* prefix, Engine e, absl::string_view text, absl::string_view context, Prog::Anchor anchor) { - LOG(INFO) << prefix + ABSL_LOG(INFO) << prefix << EngineName(e) << " regexp " << absl::CEscape(regexp_str_) diff --git a/re2/testing/tester.h b/re2/testing/tester.h index 59be5ea0a..9a87138e8 100644 --- a/re2/testing/tester.h +++ b/re2/testing/tester.h @@ -12,8 +12,8 @@ #include "absl/strings/string_view.h" #include "re2/prog.h" -#include "re2/regexp.h" #include "re2/re2.h" +#include "re2/regexp.h" #include "util/pcre.h" namespace re2 { diff --git a/re2/tostring.cc b/re2/tostring.cc index 33179fdeb..24a530e64 100644 --- a/re2/tostring.cc +++ b/re2/tostring.cc @@ -6,13 +6,14 @@ // Tested by parse_test.cc #include + #include +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" -#include "util/logging.h" -#include "util/utf.h" #include "re2/regexp.h" #include "re2/walker-inl.h" +#include "util/utf.h" namespace re2 { @@ -101,7 +102,7 @@ int ToStringWalker::PreVisit(Regexp* re, int parent_arg, bool* stop) { case kRegexpCapture: t_->append("("); if (re->cap() == 0) - LOG(DFATAL) << "kRegexpCapture cap() == 0"; + ABSL_LOG(DFATAL) << "kRegexpCapture cap() == 0"; if (re->name()) { t_->append("?P<"); t_->append(*re->name()); @@ -184,7 +185,7 @@ int ToStringWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg, if ((*t_)[t_->size()-1] == '|') t_->erase(t_->size()-1); else - LOG(DFATAL) << "Bad final char: " << t_; + ABSL_LOG(DFATAL) << "Bad final char: " << t_; if (prec < PrecAlternate) t_->append(")"); break; diff --git a/re2/walker-inl.h b/re2/walker-inl.h index 45763a7b2..2283d6daf 100644 --- a/re2/walker-inl.h +++ b/re2/walker-inl.h @@ -16,7 +16,8 @@ #include #include "absl/base/macros.h" -#include "util/logging.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "re2/regexp.h" namespace re2 { @@ -147,7 +148,7 @@ template Regexp::Walker::~Walker() { // Logs DFATAL if stack is not already clear. template void Regexp::Walker::Reset() { if (!stack_.empty()) { - LOG(DFATAL) << "Stack not empty."; + ABSL_LOG(DFATAL) << "Stack not empty."; while (!stack_.empty()) { if (stack_.top().re->nsub_ > 1) delete[] stack_.top().child_args; @@ -161,7 +162,7 @@ template T Regexp::Walker::WalkInternal(Regexp* re, T top_arg, Reset(); if (re == NULL) { - LOG(DFATAL) << "Walk NULL"; + ABSL_LOG(DFATAL) << "Walk NULL"; return top_arg; } diff --git a/re2Config.cmake.in b/re2Config.cmake.in index 6a177c615..be7b6bc64 100644 --- a/re2Config.cmake.in +++ b/re2Config.cmake.in @@ -6,8 +6,6 @@ include(CMakeFindDependencyMacro) -set_and_check(re2_INCLUDE_DIR ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@) - if(UNIX) set(THREADS_PREFER_PTHREAD_FLAG ON) find_dependency(Threads REQUIRED) diff --git a/util/logging.h b/util/logging.h deleted file mode 100644 index 946962b39..000000000 --- a/util/logging.h +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2009 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. - -#ifndef UTIL_LOGGING_H_ -#define UTIL_LOGGING_H_ - -// Simplified version of Google's logging. - -#include -#include -#include -#include -#include - -#include "absl/base/attributes.h" - -// Debug-only checking. -#define DCHECK(condition) assert(condition) -#define DCHECK_EQ(val1, val2) assert((val1) == (val2)) -#define DCHECK_NE(val1, val2) assert((val1) != (val2)) -#define DCHECK_LE(val1, val2) assert((val1) <= (val2)) -#define DCHECK_LT(val1, val2) assert((val1) < (val2)) -#define DCHECK_GE(val1, val2) assert((val1) >= (val2)) -#define DCHECK_GT(val1, val2) assert((val1) > (val2)) - -// Always-on checking -#define CHECK(x) if(x){}else LogMessageFatal(__FILE__, __LINE__).stream() << "Check failed: " #x -#define CHECK_LT(x, y) CHECK((x) < (y)) -#define CHECK_GT(x, y) CHECK((x) > (y)) -#define CHECK_LE(x, y) CHECK((x) <= (y)) -#define CHECK_GE(x, y) CHECK((x) >= (y)) -#define CHECK_EQ(x, y) CHECK((x) == (y)) -#define CHECK_NE(x, y) CHECK((x) != (y)) - -#define LOG_INFO LogMessage(__FILE__, __LINE__) -#define LOG_WARNING LogMessage(__FILE__, __LINE__) -#define LOG_ERROR LogMessage(__FILE__, __LINE__) -#define LOG_FATAL LogMessageFatal(__FILE__, __LINE__) -#define LOG_QFATAL LOG_FATAL - -// It seems that one of the Windows header files defines ERROR as 0. -#ifdef _WIN32 -#define LOG_0 LOG_INFO -#endif - -#ifdef NDEBUG -#define LOG_DFATAL LOG_ERROR -#else -#define LOG_DFATAL LOG_FATAL -#endif - -#define LOG(severity) LOG_ ## severity.stream() - -#define VLOG(x) if((x)>0){}else LOG_INFO.stream() - -class LogMessage { - public: - LogMessage(const char* file, int line) - : flushed_(false) { - stream() << file << ":" << line << ": "; - } - void Flush() { - stream() << "\n"; - std::string s = str_.str(); - size_t n = s.size(); - if (fwrite(s.data(), 1, n, stderr) < n) {} // shut up gcc - flushed_ = true; - } - ~LogMessage() { - if (!flushed_) { - Flush(); - } - } - std::ostream& stream() { return str_; } - - private: - bool flushed_; - std::ostringstream str_; - - LogMessage(const LogMessage&) = delete; - LogMessage& operator=(const LogMessage&) = delete; -}; - -// Silence "destructor never returns" warning for ~LogMessageFatal(). -// Since this is a header file, push and then pop to limit the scope. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4722) -#endif - -class LogMessageFatal : public LogMessage { - public: - LogMessageFatal(const char* file, int line) - : LogMessage(file, line) {} - ABSL_ATTRIBUTE_NORETURN ~LogMessageFatal() { - Flush(); - abort(); - } - private: - LogMessageFatal(const LogMessageFatal&) = delete; - LogMessageFatal& operator=(const LogMessageFatal&) = delete; -}; - -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -#endif // UTIL_LOGGING_H_ diff --git a/util/pcre.cc b/util/pcre.cc index f54cb28f8..94a88b7c9 100644 --- a/util/pcre.cc +++ b/util/pcre.cc @@ -16,16 +16,17 @@ #include #include "absl/flags/flag.h" +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" #include "absl/strings/str_format.h" -#include "util/logging.h" #include "util/pcre.h" // Silence warnings about the wacky formatting in the operator() functions. -#if !defined(__clang__) && defined(__GNUC__) +#if defined(__GNUC__) #pragma GCC diagnostic ignored "-Wmisleading-indentation" #endif -#define PCREPORT(level) LOG(level) +#define PCREPORT(level) ABSL_LOG(level) // Default PCRE limits. // Defaults chosen to allow a plausible amount of CPU and diff --git a/util/pcre.h b/util/pcre.h index 846f30019..c0e944e02 100644 --- a/util/pcre.h +++ b/util/pcre.h @@ -39,10 +39,10 @@ // supplied pattern exactly. // // Example: successful match -// CHECK(PCRE::FullMatch("hello", "h.*o")); +// ABSL_CHECK(PCRE::FullMatch("hello", "h.*o")); // // Example: unsuccessful match (requires full match): -// CHECK(!PCRE::FullMatch("hello", "e")); +// ABSL_CHECK(!PCRE::FullMatch("hello", "e")); // // ----------------------------------------------------------------------- // UTF-8 AND THE MATCHING INTERFACE: @@ -58,7 +58,7 @@ // // Example: // PCRE re(utf8_pattern, PCRE::UTF8); -// CHECK(PCRE::FullMatch(utf8_string, re)); +// ABSL_CHECK(PCRE::FullMatch(utf8_string, re)); // // ----------------------------------------------------------------------- // MATCHING WITH SUBSTRING EXTRACTION: @@ -68,22 +68,22 @@ // Example: extracts "ruby" into "s" and 1234 into "i" // int i; // std::string s; -// CHECK(PCRE::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i)); +// ABSL_CHECK(PCRE::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s, &i)); // // Example: fails because string cannot be stored in integer -// CHECK(!PCRE::FullMatch("ruby", "(.*)", &i)); +// ABSL_CHECK(!PCRE::FullMatch("ruby", "(.*)", &i)); // // Example: fails because there aren't enough sub-patterns: -// CHECK(!PCRE::FullMatch("ruby:1234", "\\w+:\\d+", &s)); +// ABSL_CHECK(!PCRE::FullMatch("ruby:1234", "\\w+:\\d+", &s)); // // Example: does not try to extract any extra sub-patterns -// CHECK(PCRE::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s)); +// ABSL_CHECK(PCRE::FullMatch("ruby:1234", "(\\w+):(\\d+)", &s)); // // Example: does not try to extract into NULL -// CHECK(PCRE::FullMatch("ruby:1234", "(\\w+):(\\d+)", NULL, &i)); +// ABSL_CHECK(PCRE::FullMatch("ruby:1234", "(\\w+):(\\d+)", NULL, &i)); // // Example: integer overflow causes failure -// CHECK(!PCRE::FullMatch("ruby:1234567891234", "\\w+:(\\d+)", &i)); +// ABSL_CHECK(!PCRE::FullMatch("ruby:1234567891234", "\\w+:(\\d+)", &i)); // // ----------------------------------------------------------------------- // PARTIAL MATCHES @@ -92,12 +92,12 @@ // to match any substring of the text. // // Example: simple search for a string: -// CHECK(PCRE::PartialMatch("hello", "ell")); +// ABSL_CHECK(PCRE::PartialMatch("hello", "ell")); // // Example: find first number in a string // int number; -// CHECK(PCRE::PartialMatch("x*100 + 20", "(\\d+)", &number)); -// CHECK_EQ(number, 100); +// ABSL_CHECK(PCRE::PartialMatch("x*100 + 20", "(\\d+)", &number)); +// ABSL_CHECK_EQ(number, 100); // // ----------------------------------------------------------------------- // PPCRE-COMPILED PCREGULAR EXPPCRESSIONS @@ -157,7 +157,7 @@ // // Example: // int a, b, c, d; -// CHECK(PCRE::FullMatch("100 40 0100 0x40", "(.*) (.*) (.*) (.*)", +// ABSL_CHECK(PCRE::FullMatch("100 40 0100 0x40", "(.*) (.*) (.*) (.*)", // Octal(&a), Hex(&b), CRadix(&c), CRadix(&d)); // will leave 64 in a, b, c, and d. @@ -379,7 +379,7 @@ class PCRE { // text. E.g., // // std::string s = "yabba dabba doo"; - // CHECK(PCRE::Replace(&s, "b+", "d")); + // ABSL_CHECK(PCRE::Replace(&s, "b+", "d")); // // will leave "s" containing "yada dabba doo" // @@ -393,7 +393,7 @@ class PCRE { // re-matching. E.g., // // std::string s = "yabba dabba doo"; - // CHECK(PCRE::GlobalReplace(&s, "b+", "d")); + // ABSL_CHECK(PCRE::GlobalReplace(&s, "b+", "d")); // // will leave "s" containing "yada dada doo" // @@ -417,7 +417,7 @@ class PCRE { // * The @p rewrite string doesn't have any syntax errors // ('\' followed by anything besides [0-9] and '\'). // Making this test will guarantee that "replace" and "extract" - // operations won't LOG(ERROR) or fail because of a bad rewrite + // operations won't ABSL_LOG(ERROR) or fail because of a bad rewrite // string. // @param rewrite The proposed rewrite string. // @param error An error message is recorded here, iff we return false.