diff --git a/libpcre/AUTHORS.md b/libpcre/AUTHORS.md index 708fc2325..ced81e68a 100644 --- a/libpcre/AUTHORS.md +++ b/libpcre/AUTHORS.md @@ -1,14 +1,14 @@ PCRE2 Authorship and Contributors ================================= -COPYRIGHT +Copyright --------- Please see the file [LICENCE](./LICENCE.md) in the PCRE2 distribution for copyright details. -MAINTAINERS +Maintainers ----------- The PCRE and PCRE2 libraries were authored and maintained by Philip Hazel. @@ -62,7 +62,7 @@ Both administrators are volunteers acting in a personal capacity. -CONTRIBUTORS +Contributors ------------ Many others have participated and contributed to PCRE2 over its history. @@ -77,7 +77,7 @@ All names listed alphabetically. ### Contributors to PCRE2 -This list includes names up until the PCRE2 10.44 release. New names will be +This list includes names up until the PCRE2 10.47 release. New names will be added from the Git history on each release. Scott Bell @@ -93,13 +93,16 @@ added from the Git history on each release. Addison Crump Alex Dowad Daniel Engberg + Marco Feuerstein Daniel Richard G + Isaac Oscar Gariano David Gaussmann Andrey Gorbachev Jordan Griege Jason Hood Bumsu Hyeon Roy Ivy + Nobuhiro Iwamatsu Martin Joerg Guillem Jover Ralf Junker @@ -114,13 +117,17 @@ added from the Git history on each release. Kai Lu Behzod Mansurov B. Scott Michel + Greg Minshall Nathan Moinvaziri Mike Munday Marc Mutz Fabio Pagani Christian Persch + Alex Reinking + Joshua Rogers Tristan Ross William A Rowe Jr + Rocco Ruscitti David Seifert Yaakov Selkowitz Rich Siegel @@ -131,6 +138,7 @@ added from the Git history on each release. Greg Thain Lucas Trzesniewski Theodore Tsirpanis + Aaron M. Ucko Matthew Vernon RĂ©mi Verschelde Thomas Voss diff --git a/libpcre/BUILD.bazel b/libpcre/BUILD.bazel index c975eadd7..ec1b0b9b8 100644 --- a/libpcre/BUILD.bazel +++ b/libpcre/BUILD.bazel @@ -20,15 +20,51 @@ copy_file( out = "src/pcre2_chartables.c", ) -# Removed src/pcre2_ucptables.c below because it is #included in -# src/pcre2_tables.c. Also fixed typo: ckdint should be chkdint. -# PH, 22-March-2023. +LOCAL_DEFINES = [ + "HAVE_CONFIG_H", + "SUPPORT_PCRE2_8", + "SUPPORT_UNICODE", +] + select({ + "@platforms//os:windows": [], + "//conditions:default": ["HAVE_UNISTD_H"], +}) + +# Workaround for a Bazel quirk. It is extremely strict about the #include path +# used for internal headers. We have our headers inside src/, but we #include +# them as '#include "pcre2_internal.h"', assuming that src/ is added to the +# compiler's include path. Unfortunately, that violates the conventions used by +# Bazel. +# +# This is a workaround. Note that we can't use the "include = [...]" property +# to add the src/ directory, since that pollutes the include path for projects +# depending on PCRE2 (we must not make our config.h file visible to consumers +# of PCRE2). +cc_library( + name = "pcre2_internal_headers", + hdrs = [ + "src/pcre2_compile.h", + "src/pcre2_internal.h", + "src/pcre2_intmodedep.h", + "src/pcre2_jit_match_inc.h", + "src/pcre2_jit_misc_inc.h", + "src/pcre2_printint_inc.h", + "src/pcre2_ucp.h", + "src/pcre2_ucptables_inc.h", + "src/pcre2_util.h", + "src/pcre2test_inc.h", + ":config_h_generic", + ], + strip_include_prefix = "src", + visibility = ["//visibility:private"], +) + cc_library( name = "pcre2", srcs = [ "src/pcre2_auto_possess.c", "src/pcre2_chkdint.c", "src/pcre2_compile.c", + "src/pcre2_compile_cgroup.c", "src/pcre2_compile_class.c", "src/pcre2_config.c", "src/pcre2_context.c", @@ -41,6 +77,7 @@ cc_library( "src/pcre2_maketables.c", "src/pcre2_match.c", "src/pcre2_match_data.c", + "src/pcre2_match_next.c", "src/pcre2_newline.c", "src/pcre2_ord2utf.c", "src/pcre2_pattern_info.c", @@ -55,53 +92,49 @@ cc_library( "src/pcre2_valid_utf.c", "src/pcre2_xclass.c", ":pcre2_chartables_c", - "src/pcre2_compile.h", - "src/pcre2_internal.h", - "src/pcre2_intmodedep.h", - "src/pcre2_ucp.h", - "src/pcre2_util.h", - ":config_h_generic", ], - textual_hdrs = [ - "src/pcre2_jit_match.c", - "src/pcre2_jit_misc.c", - "src/pcre2_ucptables.c", - ], - hdrs = [ - ":pcre2_h_generic", - ], - local_defines = [ - "HAVE_CONFIG_H", - "HAVE_MEMMOVE", - "PCRE2_CODE_UNIT_WIDTH=8", + hdrs = [":pcre2_h_generic"], + implementation_deps = [":pcre2_internal_headers"], + defines = [ "PCRE2_STATIC", - "SUPPORT_UNICODE", ], - includes = ["src"], + local_defines = LOCAL_DEFINES + [ + "PCRE2_CODE_UNIT_WIDTH=8", + ], strip_include_prefix = "src", + linkstatic = True, visibility = ["//visibility:public"], ) +# See below for explanation of why we need this. +# +# https://github.com/bazelbuild/bazel/issues/680 +cc_library( + name = "pcre2posix_dotc_headers", + hdrs = [ + "src/pcre2_tables.c", + ], + strip_include_prefix = "src", + visibility = ["//visibility:private"], +) + cc_library( name = "pcre2-posix", - srcs = [ - "src/pcre2posix.c", - ":config_h_generic", + srcs = ["src/pcre2posix.c"], + hdrs = ["src/pcre2posix.h"], + implementation_deps = [ + ":pcre2_internal_headers", + ":pcre2posix_dotc_headers", ], - hdrs = [ - "src/pcre2posix.h", - ], - local_defines = [ - "HAVE_CONFIG_H", - "HAVE_MEMMOVE", + local_defines = LOCAL_DEFINES + [ "PCRE2_CODE_UNIT_WIDTH=8", - "PCRE2_STATIC", - "SUPPORT_UNICODE", ], - includes = ["src"], strip_include_prefix = "src", + linkstatic = True, visibility = ["//visibility:public"], - deps = [":pcre2"], + deps = [ + ":pcre2", + ], ) # Totally weird issue in Bazel. It won't let you #include any files unless they @@ -118,7 +151,6 @@ cc_library( name = "pcre2test_dotc_headers", hdrs = [ "src/pcre2_chkdint.c", - "src/pcre2_printint.c", "src/pcre2_tables.c", "src/pcre2_ucd.c", "src/pcre2_valid_utf.c", @@ -129,27 +161,19 @@ cc_library( cc_binary( name = "pcre2test", - srcs = [ - "src/pcre2test.c", - ":config_h_generic", - ], - local_defines = [ - "HAVE_CONFIG_H", - "HAVE_MEMMOVE", - "HAVE_STRERROR", - "PCRE2_STATIC", - "SUPPORT_UNICODE", - "SUPPORT_PCRE2_8", - ] + select({ - "@platforms//os:windows": [], - "//conditions:default": ["HAVE_UNISTD_H"], - }), + srcs = ["src/pcre2test.c"], linkopts = select({ "@platforms//os:windows": ["-STACK:2500000"], "//conditions:default": [], }), + local_defines = LOCAL_DEFINES, visibility = ["//visibility:public"], - deps = [":pcre2test_dotc_headers", ":pcre2", ":pcre2-posix"], + deps = [ + ":pcre2", + ":pcre2-posix", + ":pcre2_internal_headers", + ":pcre2test_dotc_headers", + ], ) filegroup( @@ -159,6 +183,7 @@ filegroup( native_test( name = "pcre2_test", + size = "small", src = select({ "@platforms//os:windows": "RunTest.bat", "//conditions:default": "RunTest", @@ -167,6 +192,8 @@ native_test( "@platforms//os:windows": "RunTest.bat", "//conditions:default": "RunTest", }), - data = [":pcre2test", ":testdata"], - size = "small", -) \ No newline at end of file + data = [ + ":pcre2test", + ":testdata", + ], +) diff --git a/libpcre/CMakeLists.txt b/libpcre/CMakeLists.txt index 11e4e86b0..1ce401b6b 100644 --- a/libpcre/CMakeLists.txt +++ b/libpcre/CMakeLists.txt @@ -102,41 +102,50 @@ # 2022-12-10 PH added support for pcre2posix_test # 2023-01-15 Carlo added C99 as the minimum required # 2023-08-06 PH added support for setting variable length lookbehind maximum +# 2025-03-27 Theodore used standard CMake constructs to export the library's +# targets. ################################################################################ # We have used `gersemi` for auto-formatting our CMake files. # Applied to all CMake files using: # > pip3 install gersemi # > gersemi --in-place --line-length 120 --indent 2 \ -# ./CMakeLists.txt ./cmake/*.cmake ./cmake/*.cmake.in +# --definitions cmake/*.cmake \ +# -- ./CMakeLists.txt ./cmake/*.cmake ./cmake/*.cmake.in ################################################################################ +message(STATUS "Using CMake version ${CMAKE_VERSION} (${CMAKE_COMMAND})") + # Increased minimum to 3.15 to allow use of string(REPEAT). cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(PCRE2 C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED TRUE) - set(CMAKE_C_VISIBILITY_PRESET hidden) -cmake_policy(SET CMP0063 NEW) -# Set policy CMP0026 to avoid warnings for the use of LOCATION in -# GET_TARGET_PROPERTY. This should no longer be required. -# CMAKE_POLICY(SET CMP0026 OLD) +# Solaris-specific fix for "CMAKE_C_VISIBILITY_PRESET": this feature was only +# recently added to CMake for the `cc` compiler (Oracle Developer Studio). The +# CMake version from OpenCSW and Oracle's package repository is too old and +# requires this fix. +if( + CMAKE_SYSTEM_NAME STREQUAL "SunOS" + AND CMAKE_VERSION VERSION_LESS 3.31 + AND CMAKE_C_COMPILER_ID STREQUAL "SunPro" + AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.15 +) + set(CMAKE_C_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") +endif() -# With a recent cmake, you can provide a rootdir to look for non -# standard installed library dependencies, but to do so, the policy -# needs to be set to new (by uncommenting the following) -# CMAKE_POLICY(SET CMP0074 NEW) - -# For FindReadline.cmake. This was changed to allow setting CMAKE_MODULE_PATH -# on the command line. -# SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +# The following policies have been set in the PCRE2 CMake file in the past. +# Since we specify a minimum of CMake 3.15, these are no longer required. +# cmake_policy(SET CMP0063 NEW) +# cmake_policy(SET CMP0026 OLD) +# cmake_policy(SET CMP0074 NEW) +# For our modules in cmake/. This uses list(APPEND) rather than set() to allow +# setting CMAKE_MODULE_PATH on the command line. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -include_directories(${PROJECT_SOURCE_DIR}/src) - # external packages find_package(BZip2) find_package(ZLIB) @@ -148,7 +157,12 @@ include(CheckFunctionExists) include(CheckSymbolExists) include(CheckIncludeFile) include(CheckTypeSize) +include(CMakePackageConfigHelpers) +include(CMakePushCheckState) include(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR +include(PCRE2CheckVscript) +include(PCRE2UseSystemExtensions) +include(PCRE2WarningAsError) check_include_file(assert.h HAVE_ASSERT_H) check_include_file(dirent.h HAVE_DIRENT_H) @@ -157,11 +171,25 @@ check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(unistd.h HAVE_UNISTD_H) check_include_file(windows.h HAVE_WINDOWS_H) -check_symbol_exists(bcopy "strings.h" HAVE_BCOPY) -check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE) -check_symbol_exists(memmove "string.h" HAVE_MEMMOVE) -check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV) -check_symbol_exists(strerror "string.h" HAVE_STRERROR) +# Check whether any system-wide extensions need to be enabled, in order for +# OS functionality to be exposed. +pcre2_use_system_extensions() + +cmake_push_check_state(RESET) +# Somewhat awkward code to propagate the _GNU_SOURCE definition (added to +# COMPILE_DEFINITIONS by pcre2_use_system_extensions()). +get_directory_property(_pcre2_compile_definitions COMPILE_DEFINITIONS) +if(DEFINED _pcre2_compile_definitions) + set(CMAKE_REQUIRED_DEFINITIONS "") + foreach(_def IN LISTS _pcre2_compile_definitions) + list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D${_def}") + endforeach() +endif() + +check_symbol_exists(mkostemp stdlib.h HAVE_MKOSTEMP) # glibc 2.7 +check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE) # glibc 2.27 +check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV) # glibc 2.17 +cmake_pop_check_state() check_c_source_compiles( [=[ @@ -172,26 +200,55 @@ check_c_source_compiles( HAVE_REALPATH ) -set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) -if(NOT MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "XL") - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror") +# Many CMake tests use highly-dubious C source code which generates warnings +# (for example, calling a function with the wrong signature just to see whether +# the linker can find it). These couple of tests here though need to be compiled +# with -Werror to be effective. +cmake_push_check_state() +if(NOT DEFINED CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_FLAGS "") endif() +pcre2_warning_as_error(WARNING_AS_ERROR_FLAGS) +set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${WARNING_AS_ERROR_FLAGS}") check_c_source_compiles( "int main(void) { char buf[128] __attribute__((uninitialized)); (void)buf; return 0; }" HAVE_ATTRIBUTE_UNINITIALIZED ) -check_c_source_compiles( - [=[ - extern __attribute__ ((visibility ("default"))) int f(void); - int main(void) { return f(); } - int f(void) { return 42; } - ]=] - HAVE_VISIBILITY -) - -set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS}) +if(NOT MSVC) + check_c_source_compiles( + [=[ + extern __attribute__ ((visibility ("default"))) int f(void); + int main(void) { return f(); } + int f(void) { return 42; } + ]=] + HAVE_VISIBILITY + ) +endif() +if(CMAKE_C_COMPILE_OPTIONS_VISIBILITY AND NOT HAVE_VISIBILITY) + # Hmm. We don't know of any way to set a symbol to have default visibility, other + # than the common "__attribute__((visibility("default")))". But CMake thinks that + # the compiler supports CMAKE_C_VISIBILITY_PRESET. The build is likely to fail to + # generate a usable shared library. + message( + WARNING + "C compiler uses the visibility flag ${CMAKE_C_COMPILE_OPTIONS_VISIBILITY}. We did not detect support for __attribute__((visibility(\"default\"))). We do not know how to set a symbol to have default visibility." + ) +elseif(HAVE_VISIBILITY AND NOT CMAKE_C_COMPILE_OPTIONS_VISIBILITY) + # Here, the build may well work, but it's possible that CMake isn't correctly + # suppressing the visibility of private symbols. + message( + WARNING + "C compiler appears to support __attribute__((visibility(\"default\"))). However, CMake is not using a visibility flag. The visibility of private symbols may not be correct." + ) +endif() +if(HAVE_VISIBILITY) + set(PCRE2_EXPORT [=[__attribute__ ((visibility ("default")))]=]) +else() + set(PCRE2_EXPORT) +endif() +cmake_pop_check_state() check_c_source_compiles("int main(void) { __assume(1); return 0; }" HAVE_BUILTIN_ASSUME) @@ -208,11 +265,9 @@ check_c_source_compiles( HAVE_BUILTIN_UNREACHABLE ) -if(HAVE_VISIBILITY) - set(PCRE2_EXPORT [=[__attribute__ ((visibility ("default")))]=]) -else() - set(PCRE2_EXPORT) -endif() +# Detect support for linker scripts. + +pcre2_check_vscript(HAVE_VSCRIPT VSCRIPT_FLAG) # Check whether Intel CET is enabled, and if so, adjust compiler flags. This # code was written by PH, trying to imitate the logic from the autotools @@ -263,6 +318,15 @@ set( set(PCRE2_EBCDIC_NL25 OFF CACHE BOOL "Use 0x25 as EBCDIC NL character instead of 0x15; implies EBCDIC.") +set( + PCRE2_EBCDIC_IGNORING_COMPILER + OFF + CACHE BOOL + "Force EBCDIC 1047 using numeric literals rather than C character literals; implies EBCDIC." +) + +option(PCRE2_REBUILD_CHARTABLES "Rebuild char tables" OFF) + set( PCRE2_LINK_SIZE "2" @@ -317,6 +381,7 @@ set( set(PCRE2_NEWLINE "LF" CACHE STRING "What to recognize as a newline (one of CR, LF, CRLF, ANY, ANYCRLF, NUL).") set(PCRE2_HEAP_MATCH_RECURSE OFF CACHE BOOL "Obsolete option: do not use") +mark_as_advanced(PCRE2_HEAP_MATCH_RECURSE) set(PCRE2_SUPPORT_JIT OFF CACHE BOOL "Enable support for Just-in-time compiling.") @@ -332,7 +397,7 @@ set(PCRE2GREP_SUPPORT_CALLOUT ON CACHE BOOL "Enable callout string support in pc set(PCRE2GREP_SUPPORT_CALLOUT_FORK ON CACHE BOOL "Enable callout string fork support in pcre2grep.") -set(PCRE2_SUPPORT_UNICODE OFF CACHE BOOL "Enable support for Unicode and UTF-8/UTF-16/UTF-32 encoding.") +set(PCRE2_SUPPORT_UNICODE ON CACHE BOOL "Enable support for Unicode and UTF-8/UTF-16/UTF-32 encoding.") set( PCRE2_SUPPORT_BSR_ANYCRLF @@ -346,8 +411,8 @@ set(PCRE2_NEVER_BACKSLASH_C OFF CACHE BOOL "If ON, backslash-C (upper case C) is set(PCRE2_SUPPORT_VALGRIND OFF CACHE BOOL "Enable Valgrind support.") option(PCRE2_SHOW_REPORT "Show the final configuration report" ON) -option(PCRE2_BUILD_PCRE2GREP "Build pcre2grep" OFF) -option(PCRE2_BUILD_TESTS "Build the tests" OFF) +option(PCRE2_BUILD_PCRE2GREP "Build pcre2grep" ON) +option(PCRE2_BUILD_TESTS "Build the tests" ON) set( PCRE2_INSTALL_CMAKEDIR @@ -371,55 +436,37 @@ if(MINGW) endif() if(MSVC) - option(PCRE2_STATIC_RUNTIME "ON=Compile against the static runtime (/MT)." OFF) option(INSTALL_MSVC_PDB "ON=Install .pdb files built by MSVC, if generated" OFF) endif() +if(HAVE_VSCRIPT) + option(PCRE2_SYMVERS "Enable library symbol versioning" ON) +endif() + # bzip2 lib if(BZIP2_FOUND) option(PCRE2_SUPPORT_LIBBZ2 "Enable support for linking pcre2grep with libbz2." ON) endif() -if(PCRE2_SUPPORT_LIBBZ2) - include_directories(${BZIP2_INCLUDE_DIR}) -endif() # zlib if(ZLIB_FOUND) option(PCRE2_SUPPORT_LIBZ "Enable support for linking pcre2grep with libz." ON) endif() -if(PCRE2_SUPPORT_LIBZ) - include_directories(${ZLIB_INCLUDE_DIR}) -endif() # editline lib if(EDITLINE_FOUND) option(PCRE2_SUPPORT_LIBEDIT "Enable support for linking pcre2test with libedit." OFF) endif() -if(EDITLINE_FOUND) - if(PCRE2_SUPPORT_LIBEDIT) - include_directories(${EDITLINE_INCLUDE_DIR}) - endif() -else() - if(PCRE2_SUPPORT_LIBEDIT) - message( - FATAL_ERROR - " libedit not found, set EDITLINE_INCLUDE_DIR to a compatible header\n" - " or set Editline_ROOT to a full libedit installed tree, as needed\n" - " Might need to enable policy CMP0074 in CMakeLists.txt" - ) - endif() -endif() # readline lib if(READLINE_FOUND) option(PCRE2_SUPPORT_LIBREADLINE "Enable support for linking pcre2test with libreadline." ON) endif() -if(PCRE2_SUPPORT_LIBREADLINE) - include_directories(${READLINE_INCLUDE_DIR}) -endif() # Prepare build configuration +include_directories(${PROJECT_BINARY_DIR}/interface ${PROJECT_BINARY_DIR}/src ${PROJECT_SOURCE_DIR}/src) + if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS) message(FATAL_ERROR "At least one of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be enabled.") endif() @@ -448,6 +495,54 @@ if(PCRE2_BUILD_PCRE2GREP AND NOT PCRE2_BUILD_PCRE2_8) set(PCRE2_BUILD_PCRE2GREP OFF) endif() +if(PCRE2_SUPPORT_LIBBZ2) + if(BZIP2_FOUND) + include_directories(${BZIP2_INCLUDE_DIR}) + else() + message( + FATAL_ERROR + " libbz2 not found. Set BZIP2_INCLUDE_DIR to a compatible header\n" + " or set BZip2_ROOT to a full bzip2 installed tree, as needed." + ) + endif() +endif() + +if(PCRE2_SUPPORT_LIBZ) + if(ZLIB_FOUND) + include_directories(${ZLIB_INCLUDE_DIR}) + else() + message( + FATAL_ERROR + " zlib not found. Set ZLIB_INCLUDE_DIR to a compatible header\n" + " or set ZLIB_ROOT to a full zlib installed tree, as needed." + ) + endif() +endif() + +if(PCRE2_SUPPORT_LIBEDIT) + if(EDITLINE_FOUND) + include_directories(${EDITLINE_INCLUDE_DIR}) + else() + message( + FATAL_ERROR + " libedit not found. Set EDITLINE_INCLUDE_DIR to a compatible header\n" + " or set Editline_ROOT to a full libedit installed tree, as needed." + ) + endif() +endif() + +if(PCRE2_SUPPORT_LIBREADLINE) + if(READLINE_FOUND) + include_directories(${READLINE_INCLUDE_DIR}) + else() + message( + FATAL_ERROR + " libreadline not found. Set READLINE_INCLUDE_DIR to a compatible header\n" + " or set Readline_ROOT to a full libreadline installed tree, as needed." + ) + endif() +endif() + if(PCRE2_SUPPORT_LIBREADLINE AND PCRE2_SUPPORT_LIBEDIT) if(READLINE_FOUND) message( @@ -481,19 +576,7 @@ if(PCRE2_SUPPORT_JIT) endif() if(PCRE2_SUPPORT_JIT_SEALLOC) - set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) - check_symbol_exists(mkostemp stdlib.h REQUIRED) - unset(CMAKE_REQUIRED_DEFINITIONS) - if(${REQUIRED}) - if(${CMAKE_SYSTEM_NAME} MATCHES Linux|NetBSD) - add_compile_definitions(_GNU_SOURCE) - set(SLJIT_PROT_EXECUTABLE_ALLOCATOR 1) - else() - message(FATAL_ERROR "Your configuration is not supported") - endif() - else() - set(PCRE2_SUPPORT_JIT_SEALLOC OFF) - endif() + set(SLJIT_PROT_EXECUTABLE_ALLOCATOR 1) endif() if(PCRE2GREP_SUPPORT_JIT) @@ -515,6 +598,9 @@ if(PCRE2_DISABLE_PERCENT_ZT) set(DISABLE_PERCENT_ZT 1) endif() +set(PCRE2TEST_LIBS) +set(PCRE2GREP_LIBS) + # This next one used to reference ${READLINE_LIBRARY}) # but I was advised to add the NCURSES test as well, along with # some modifications to cmake/FindReadline.cmake which should @@ -522,24 +608,27 @@ endif() if(PCRE2_SUPPORT_LIBREADLINE) set(SUPPORT_LIBREADLINE 1) - set(PCRE2TEST_LIBS ${READLINE_LIBRARY} ${NCURSES_LIBRARY}) + list(APPEND PCRE2TEST_LIBS ${READLINE_LIBRARY}) + if(DEFINED NCURSES_LIBRARY) + list(APPEND PCRE2TEST_LIBS ${NCURSES_LIBRARY}) + endif() endif() # libedit is a plug-compatible alternative to libreadline if(PCRE2_SUPPORT_LIBEDIT) set(SUPPORT_LIBEDIT 1) - set(PCRE2TEST_LIBS ${EDITLINE_LIBRARY}) + list(APPEND PCRE2TEST_LIBS ${EDITLINE_LIBRARY}) endif() if(PCRE2_SUPPORT_LIBZ) set(SUPPORT_LIBZ 1) - set(PCRE2GREP_LIBS ${PCRE2GREP_LIBS} ${ZLIB_LIBRARIES}) + list(APPEND PCRE2GREP_LIBS ${ZLIB_LIBRARIES}) endif() if(PCRE2_SUPPORT_LIBBZ2) set(SUPPORT_LIBBZ2 1) - set(PCRE2GREP_LIBS ${PCRE2GREP_LIBS} ${BZIP2_LIBRARIES}) + list(APPEND PCRE2GREP_LIBS ${BZIP2_LIBRARIES}) endif() set(NEWLINE_DEFAULT "") @@ -570,18 +659,53 @@ if(NEWLINE_DEFAULT STREQUAL "") ) endif() +set(REBUILD_CHARTABLES OFF) +if(PCRE2_REBUILD_CHARTABLES) + set(REBUILD_CHARTABLES ON) +endif() + +set(EBCDIC OFF) if(PCRE2_EBCDIC) - set(EBCDIC 1) + set(EBCDIC ON) endif() if(PCRE2_EBCDIC_NL25) - set(EBCDIC 1) - set(EBCDIC_NL25 1) + set(EBCDIC ON) + set(EBCDIC_NL25 ON) endif() +if(PCRE2_EBCDIC_IGNORING_COMPILER) + set(EBCDIC ON) + set(EBCDIC_IGNORING_COMPILER ON) +endif() + +# Make sure that if EBCDIC is set (without EBCDIC_IGNORING_COMPILER), then +# REBUILD_CHARTABLES is also enabled. +# Also check that UTF support is not requested, because PCRE2 cannot handle +# EBCDIC and UTF in the same build. To do so it would need to use different +# character constants depending on the mode. +# Also, EBCDIC cannot be used with 16-bit and 32-bit libraries. +if(EBCDIC) + if(NOT EBCDIC_IGNORING_COMPILER) + set(REBUILD_CHARTABLES ON) + endif() + if(PCRE2_SUPPORT_UNICODE) + message(FATAL_ERROR "Support for EBCDIC and Unicode cannot be enabled at the same time") + endif() + if(PCRE2_BUILD_PCRE2_16 OR PCRE2_BUILD_PCRE2_32) + message(FATAL_ERROR "EBCDIC support is available only for the 8-bit library") + endif() +endif() + +# Remove the Autotools-generated copy of config.h and pcre2.h. I sometimes switch +# between Autoconf and CMake, and the conflicting copies of config.h generate some +# very unintuitive build errors. +file(REMOVE ${PROJECT_SOURCE_DIR}/src/config.h) +file(REMOVE ${PROJECT_SOURCE_DIR}/src/pcre2.h) + # Output files -configure_file(config-cmake.h.in ${PROJECT_BINARY_DIR}/config.h @ONLY) +configure_file(src/config-cmake.h.in ${PROJECT_BINARY_DIR}/src/config.h @ONLY) # Parse version numbers and date out of configure.ac @@ -607,10 +731,9 @@ set( foreach(configure_line ${configure_lines}) foreach(substitution_variable ${SEARCHED_VARIABLES}) string(TOUPPER ${substitution_variable} substitution_variable_upper) - if(NOT ${substitution_variable_upper}) - string(REGEX MATCH "m4_define\\(${substitution_variable}, *\\[(.*)\\]" MATCHED_STRING ${configure_line}) - if(CMAKE_MATCH_1) - set(${substitution_variable_upper} ${CMAKE_MATCH_1}) + if(NOT DEFINED ${substitution_variable_upper}) + if("${configure_line}" MATCHES "m4_define\\(${substitution_variable}, *\\[(.*)\\]") + set(${substitution_variable_upper} "${CMAKE_MATCH_1}") endif() endif() endforeach() @@ -640,7 +763,8 @@ parse_lib_version(LIBPCRE2_8) parse_lib_version(LIBPCRE2_16) parse_lib_version(LIBPCRE2_32) -configure_file(src/pcre2.h.in ${PROJECT_BINARY_DIR}/pcre2.h @ONLY) +configure_file(src/pcre2.h.in ${PROJECT_BINARY_DIR}/interface/pcre2.h @ONLY) +configure_file(src/pcre2posix.h ${PROJECT_BINARY_DIR}/interface/pcre2posix.h COPYONLY) # Make sure to not link debug libs # against release libs and vice versa @@ -650,31 +774,47 @@ endif() # Character table generation -option(PCRE2_REBUILD_CHARTABLES "Rebuild char tables" OFF) -if(PCRE2_REBUILD_CHARTABLES) +if(REBUILD_CHARTABLES) add_executable(pcre2_dftables src/pcre2_dftables.c) add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/pcre2_chartables.c + OUTPUT ${PROJECT_BINARY_DIR}/src/pcre2_chartables.c COMMAND pcre2_dftables - ARGS ${PROJECT_BINARY_DIR}/pcre2_chartables.c + ARGS ${PROJECT_BINARY_DIR}/src/pcre2_chartables.c DEPENDS pcre2_dftables COMMENT "Generating character tables (pcre2_chartables.c) for current locale" VERBATIM ) +elseif(NOT PCRE2_EBCDIC) + configure_file( + ${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.dist + ${PROJECT_BINARY_DIR}/src/pcre2_chartables.c + COPYONLY + ) +elseif(PCRE2_EBCDIC_NL25) + configure_file( + ${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.ebcdic-1047-nl25 + ${PROJECT_BINARY_DIR}/src/pcre2_chartables.c + COPYONLY + ) else() - configure_file(${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.dist ${PROJECT_BINARY_DIR}/pcre2_chartables.c COPYONLY) + configure_file( + ${PROJECT_SOURCE_DIR}/src/pcre2_chartables.c.ebcdic-1047-nl15 + ${PROJECT_BINARY_DIR}/src/pcre2_chartables.c + COPYONLY + ) endif() # Source code -set(PCRE2_HEADERS ${PROJECT_BINARY_DIR}/pcre2.h) +set(PCRE2_HEADERS ${PROJECT_BINARY_DIR}/interface/pcre2.h) set( PCRE2_SOURCES src/pcre2_auto_possess.c - ${PROJECT_BINARY_DIR}/pcre2_chartables.c + ${PROJECT_BINARY_DIR}/src/pcre2_chartables.c src/pcre2_chkdint.c src/pcre2_compile.c + src/pcre2_compile_cgroup.c src/pcre2_compile_class.c src/pcre2_config.c src/pcre2_context.c @@ -687,6 +827,7 @@ set( src/pcre2_maketables.c src/pcre2_match.c src/pcre2_match_data.c + src/pcre2_match_next.c src/pcre2_newline.c src/pcre2_ord2utf.c src/pcre2_pattern_info.c @@ -702,7 +843,7 @@ set( src/pcre2_xclass.c ) -set(PCRE2POSIX_HEADERS src/pcre2posix.h) +set(PCRE2POSIX_HEADERS ${PROJECT_BINARY_DIR}/interface/pcre2posix.h) set(PCRE2POSIX_SOURCES src/pcre2posix.c) if(MINGW AND BUILD_SHARED_LIBS) @@ -714,7 +855,7 @@ if(MINGW AND BUILD_SHARED_LIBS) WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Using pcre2 coff info in mingw build" ) - set(PCRE2_SOURCES ${PCRE2_SOURCES} ${PROJECT_SOURCE_DIR}/pcre2.o) + list(APPEND PCRE2_SOURCES ${PROJECT_SOURCE_DIR}/pcre2.o) endif() if(EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) @@ -725,37 +866,20 @@ if(MINGW AND BUILD_SHARED_LIBS) WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Using pcre2posix coff info in mingw build" ) - set(PCRE2POSIX_SOURCES ${PCRE2POSIX_SOURCES} ${PROJECT_SOURCE_DIR}/pcre2posix.o) + list(APPEND PCRE2POSIX_SOURCES ${PROJECT_SOURCE_DIR}/pcre2posix.o) endif() endif() if(MSVC AND BUILD_SHARED_LIBS) if(EXISTS ${PROJECT_SOURCE_DIR}/pcre2.rc) - set(PCRE2_SOURCES ${PCRE2_SOURCES} pcre2.rc) + list(APPEND PCRE2_SOURCES pcre2.rc) endif() if(EXISTS ${PROJECT_SOURCE_DIR}/pcre2posix.rc) - set(PCRE2POSIX_SOURCES ${PCRE2POSIX_SOURCES} pcre2posix.rc) + list(APPEND PCRE2POSIX_SOURCES pcre2posix.rc) endif() endif() -# Fix static compilation with MSVC: https://bugs.exim.org/show_bug.cgi?id=1681 -# This code was taken from the CMake wiki, not from WebM. - -if(MSVC AND PCRE2_STATIC_RUNTIME) - message(STATUS "** MSVC and PCRE2_STATIC_RUNTIME: modifying compiler flags to use static runtime library") - foreach( - flag_var - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL - CMAKE_C_FLAGS_RELWITHDEBINFO - ) - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endforeach() -endif() - # Build setup add_compile_definitions(HAVE_CONFIG_H) @@ -770,15 +894,15 @@ if(MSVC) add_compile_definitions(_CRT_SECURE_NO_DEPRECATE _CRT_SECURE_NO_WARNINGS) endif() -set(CMAKE_INCLUDE_CURRENT_DIR 1) - set(TARGETS) +set(DLL_PDB_FILES) +set(DLL_PDB_DEBUG_FILES) # 8-bit library if(PCRE2_BUILD_PCRE2_8) if(BUILD_STATIC_LIBS) - add_library(pcre2-8-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) + add_library(pcre2-8-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES}) set_target_properties( pcre2-8-static PROPERTIES @@ -789,11 +913,14 @@ if(PCRE2_BUILD_PCRE2_8) SOVERSION ${LIBPCRE2_8_SOVERSION} ) target_compile_definitions(pcre2-8-static PUBLIC PCRE2_STATIC) - target_include_directories(pcre2-8-static PUBLIC ${PROJECT_BINARY_DIR}) + target_include_directories( + pcre2-8-static + PUBLIC "$" "$" + ) if(REQUIRE_PTHREAD) target_link_libraries(pcre2-8-static Threads::Threads) endif() - set(TARGETS ${TARGETS} pcre2-8-static) + list(APPEND TARGETS pcre2-8-static) add_library(pcre2-posix-static STATIC ${PCRE2POSIX_HEADERS} ${PCRE2POSIX_SOURCES}) set_target_properties( pcre2-posix-static @@ -805,8 +932,11 @@ if(PCRE2_BUILD_PCRE2_8) SOVERSION ${LIBPCRE2_POSIX_SOVERSION} ) target_link_libraries(pcre2-posix-static pcre2-8-static) - target_include_directories(pcre2-posix-static PUBLIC ${PROJECT_SOURCE_DIR}/src) - set(TARGETS ${TARGETS} pcre2-posix-static) + target_include_directories( + pcre2-posix-static + PUBLIC "$" "$" + ) + list(APPEND TARGETS pcre2-posix-static) if(MSVC) set_target_properties(pcre2-8-static PROPERTIES OUTPUT_NAME pcre2-8-static) @@ -821,8 +951,11 @@ if(PCRE2_BUILD_PCRE2_8) endif() if(BUILD_SHARED_LIBS) - add_library(pcre2-8-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) - target_include_directories(pcre2-8-shared PUBLIC ${PROJECT_BINARY_DIR}) + add_library(pcre2-8-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES}) + target_include_directories( + pcre2-8-shared + PUBLIC "$" "$" + ) set_target_properties( pcre2-8-shared PROPERTIES @@ -836,12 +969,19 @@ if(PCRE2_BUILD_PCRE2_8) if(REQUIRE_PTHREAD) target_link_libraries(pcre2-8-shared Threads::Threads) endif() - set(TARGETS ${TARGETS} pcre2-8-shared) - set(DLL_PDB_FILES $/pcre2-8.pdb ${DLL_PDB_FILES}) - set(DLL_PDB_DEBUG_FILES $/pcre2-8d.pdb ${DLL_PDB_DEBUG_FILES}) + if(HAVE_VSCRIPT AND PCRE2_SYMVERS) + target_link_options(pcre2-8-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-8.sym) + set_target_properties(pcre2-8-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-8.sym) + endif() + list(APPEND TARGETS pcre2-8-shared) + list(APPEND DLL_PDB_FILES $/pcre2-8.pdb) + list(APPEND DLL_PDB_DEBUG_FILES $/pcre2-8d.pdb) add_library(pcre2-posix-shared SHARED ${PCRE2POSIX_HEADERS} ${PCRE2POSIX_SOURCES}) - target_include_directories(pcre2-posix-shared PUBLIC ${PROJECT_SOURCE_DIR}/src) + target_include_directories( + pcre2-posix-shared + PUBLIC "$" "$" + ) set_target_properties( pcre2-posix-shared PROPERTIES @@ -852,12 +992,15 @@ if(PCRE2_BUILD_PCRE2_8) SOVERSION ${LIBPCRE2_POSIX_SOVERSION} OUTPUT_NAME pcre2-posix ) - set(PCRE2POSIX_CFLAG "-DPCRE2POSIX_SHARED") - target_compile_definitions(pcre2-posix-shared PUBLIC ${PCRE2POSIX_CFLAG}) + if(HAVE_VSCRIPT AND PCRE2_SYMVERS) + target_link_options(pcre2-posix-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-posix.sym) + set_target_properties(pcre2-posix-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-posix.sym) + endif() + target_compile_definitions(pcre2-posix-shared PUBLIC PCRE2POSIX_SHARED) target_link_libraries(pcre2-posix-shared pcre2-8-shared) - set(TARGETS ${TARGETS} pcre2-posix-shared) - set(DLL_PDB_FILES $/pcre2-posix.pdb ${DLL_PDB_FILES}) - set(DLL_PDB_DEBUG_FILES $/pcre2-posixd.pdb ${DLL_PDB_DEBUG_FILES}) + list(APPEND TARGETS pcre2-posix-shared) + list(APPEND DLL_PDB_FILES $/pcre2-posix.pdb) + list(APPEND DLL_PDB_DEBUG_FILES $/pcre2-posixd.pdb) if(MINGW) if(NON_STANDARD_LIB_PREFIX) @@ -882,12 +1025,14 @@ endif() if(PCRE2_BUILD_PCRE2_16) if(BUILD_STATIC_LIBS) - add_library(pcre2-16-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) - target_include_directories(pcre2-16-static PUBLIC ${PROJECT_BINARY_DIR}) + add_library(pcre2-16-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES}) + target_include_directories( + pcre2-16-static + PUBLIC "$" "$" + ) set_target_properties( pcre2-16-static PROPERTIES - UNITY_BUILD OFF COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=16 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" @@ -898,7 +1043,7 @@ if(PCRE2_BUILD_PCRE2_16) if(REQUIRE_PTHREAD) target_link_libraries(pcre2-16-static Threads::Threads) endif() - set(TARGETS ${TARGETS} pcre2-16-static) + list(APPEND TARGETS pcre2-16-static) if(MSVC) set_target_properties(pcre2-16-static PROPERTIES OUTPUT_NAME pcre2-16-static) @@ -911,12 +1056,14 @@ if(PCRE2_BUILD_PCRE2_16) endif() if(BUILD_SHARED_LIBS) - add_library(pcre2-16-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) - target_include_directories(pcre2-16-shared PUBLIC ${PROJECT_BINARY_DIR}) + add_library(pcre2-16-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES}) + target_include_directories( + pcre2-16-shared + PUBLIC "$" "$" + ) set_target_properties( pcre2-16-shared PROPERTIES - UNITY_BUILD OFF COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=16 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" @@ -927,9 +1074,13 @@ if(PCRE2_BUILD_PCRE2_16) if(REQUIRE_PTHREAD) target_link_libraries(pcre2-16-shared Threads::Threads) endif() - set(TARGETS ${TARGETS} pcre2-16-shared) - set(DLL_PDB_FILES $/pcre2-16.pdb ${DLL_PDB_FILES}) - set(DLL_PDB_DEBUG_FILES $/pcre2-16d.pdb ${DLL_PDB_DEBUG_FILES}) + if(HAVE_VSCRIPT AND PCRE2_SYMVERS) + target_link_options(pcre2-16-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-16.sym) + set_target_properties(pcre2-16-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-16.sym) + endif() + list(APPEND TARGETS pcre2-16-shared) + list(APPEND DLL_PDB_FILES $/pcre2-16.pdb) + list(APPEND DLL_PDB_DEBUG_FILES $/pcre2-16d.pdb) if(MINGW) if(NON_STANDARD_LIB_PREFIX) @@ -952,12 +1103,14 @@ endif() if(PCRE2_BUILD_PCRE2_32) if(BUILD_STATIC_LIBS) - add_library(pcre2-32-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) - target_include_directories(pcre2-32-static PUBLIC ${PROJECT_BINARY_DIR}) + add_library(pcre2-32-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES}) + target_include_directories( + pcre2-32-static + PUBLIC "$" "$" + ) set_target_properties( pcre2-32-static PROPERTIES - UNITY_BUILD OFF COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=32 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" @@ -968,7 +1121,7 @@ if(PCRE2_BUILD_PCRE2_32) if(REQUIRE_PTHREAD) target_link_libraries(pcre2-32-static Threads::Threads) endif() - set(TARGETS ${TARGETS} pcre2-32-static) + list(APPEND TARGETS pcre2-32-static) if(MSVC) set_target_properties(pcre2-32-static PROPERTIES OUTPUT_NAME pcre2-32-static) @@ -981,12 +1134,14 @@ if(PCRE2_BUILD_PCRE2_32) endif() if(BUILD_SHARED_LIBS) - add_library(pcre2-32-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h) - target_include_directories(pcre2-32-shared PUBLIC ${PROJECT_BINARY_DIR}) + add_library(pcre2-32-shared SHARED ${PCRE2_HEADERS} ${PCRE2_SOURCES}) + target_include_directories( + pcre2-32-shared + PUBLIC "$" "$" + ) set_target_properties( pcre2-32-shared PROPERTIES - UNITY_BUILD OFF COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=32 MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}" MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}" @@ -997,9 +1152,13 @@ if(PCRE2_BUILD_PCRE2_32) if(REQUIRE_PTHREAD) target_link_libraries(pcre2-32-shared Threads::Threads) endif() - set(TARGETS ${TARGETS} pcre2-32-shared) - set(DLL_PDB_FILES $/pcre2-32.pdb ${DLL_PDB_FILES}) - set(DLL_PDB_DEBUG_FILES $/pcre2-32d.pdb ${DLL_PDB_DEBUG_FILES}) + if(HAVE_VSCRIPT AND PCRE2_SYMVERS) + target_link_options(pcre2-32-shared PRIVATE -Wl,${VSCRIPT_FLAG},${PROJECT_SOURCE_DIR}/src/libpcre2-32.sym) + set_target_properties(pcre2-32-shared PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/libpcre2-32.sym) + endif() + list(APPEND TARGETS pcre2-32-shared) + list(APPEND DLL_PDB_FILES $/pcre2-32.pdb) + list(APPEND DLL_PDB_DEBUG_FILES $/pcre2-32d.pdb) if(MINGW) if(NON_STANDARD_LIB_PREFIX) @@ -1025,10 +1184,29 @@ set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix "\${prefix}") set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") set(includedir "\${prefix}/include") + +set(LIB_POSTFIX "") if(WIN32 AND (CMAKE_BUILD_TYPE MATCHES Debug)) set(LIB_POSTFIX ${CMAKE_DEBUG_POSTFIX}) endif() +set(PCRE2_STATIC_CFLAG "") +if(NOT BUILD_SHARED_LIBS) + set(PCRE2_STATIC_CFLAG "-DPCRE2_STATIC") +endif() + +set(PCRE2POSIX_CFLAG "") +if(BUILD_SHARED_LIBS) + set(PCRE2POSIX_CFLAG "-DPCRE2POSIX_SHARED") +endif() + +set(PTHREAD_CFLAGS "") +set(PTHREAD_LIBS "") +if(REQUIRE_PTHREAD) + set(PTHREAD_CFLAGS "$") + set(PTHREAD_LIBS "$") +endif() + if(PCRE2_BUILD_PCRE2_8) set(enable_pcre2_8 "yes") else() @@ -1054,7 +1232,7 @@ configure_file(pcre2-config.in pcre2-config @ONLY NEWLINE_STYLE LF) if(PCRE2_BUILD_PCRE2GREP) add_executable(pcre2grep src/pcre2grep.c) set_property(TARGET pcre2grep PROPERTY COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8) - set(TARGETS ${TARGETS} pcre2grep) + list(APPEND TARGETS pcre2grep) target_link_libraries(pcre2grep pcre2-posix ${PCRE2GREP_LIBS}) endif() @@ -1065,6 +1243,7 @@ if(PCRE2_BUILD_TESTS) set(PCRE2TEST_SOURCES src/pcre2test.c) + set(PCRE2TEST_LINKER_FLAGS "") if(MSVC) # This is needed to avoid a stack overflow error in the standard tests. The # flag should be indicated with a forward-slash instead of a hyphen, but @@ -1073,7 +1252,7 @@ if(PCRE2_BUILD_TESTS) endif() add_executable(pcre2test ${PCRE2TEST_SOURCES}) - set(TARGETS ${TARGETS} pcre2test) + list(APPEND TARGETS pcre2test) if(PCRE2_BUILD_PCRE2_8) list(APPEND PCRE2TEST_LIBS pcre2-posix pcre2-8) endif() @@ -1155,6 +1334,14 @@ if test \"$?\" != \"0\"; then exit 1; fi if(UNIX) add_test(pcre2_grep_test sh ${PROJECT_BINARY_DIR}/pcre2_grep_test.sh) + + if(PCRE2_EBCDIC) + # The grep tests currently fail in EBCDIC mode because the test data + # files are in ASCII. This could be fixed properly, but for now, we + # have very few EBCDIC users and the pcre2grep utility is hardly even + # part of the official project artifacts. + set_property(TEST pcre2_grep_test PROPERTY WILL_FAIL TRUE) + endif() endif() endif() @@ -1206,7 +1393,12 @@ echo RunGrepTest.bat tests successfully completed ) endif() - if("$ENV{OSTYPE}" STREQUAL "msys") + if(DEFINED ENV{OSTYPE}) + if("$ENV{OSTYPE}" STREQUAL "msys") + set(MSYS2 TRUE) + endif() + endif() + if(MSYS2) # Both the sh and bat file versions of RunTest are run if make test is used # in msys add_test(pcre2_test_sh sh.exe ${PROJECT_BINARY_DIR}/pcre2_test.sh) @@ -1233,41 +1425,57 @@ set(CMAKE_INSTALL_ALWAYS 1) install( TARGETS ${TARGETS} - RUNTIME DESTINATION bin + EXPORT pcre2-targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +install(EXPORT pcre2-targets DESTINATION ${PCRE2_INSTALL_CMAKEDIR} NAMESPACE pcre2::) install(FILES ${pkg_config_files} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/pcre2-config" - DESTINATION bin + FILES "${PROJECT_BINARY_DIR}/pcre2-config" + DESTINATION ${CMAKE_INSTALL_BINDIR} # Set 0755 permissions PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) -install(FILES ${PCRE2_HEADERS} ${PCRE2POSIX_HEADERS} DESTINATION include) +install(FILES ${PCRE2_HEADERS} ${PCRE2POSIX_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # CMake config files. -set(PCRE2_CONFIG_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/pcre2-config.cmake.in) -set(PCRE2_CONFIG_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/pcre2-config.cmake) -configure_file(${PCRE2_CONFIG_IN} ${PCRE2_CONFIG_OUT} @ONLY) -set(PCRE2_CONFIG_VERSION_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/pcre2-config-version.cmake.in) -set(PCRE2_CONFIG_VERSION_OUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/pcre2-config-version.cmake) -configure_file(${PCRE2_CONFIG_VERSION_IN} ${PCRE2_CONFIG_VERSION_OUT} @ONLY) -install(FILES ${PCRE2_CONFIG_OUT} ${PCRE2_CONFIG_VERSION_OUT} DESTINATION "${PCRE2_INSTALL_CMAKEDIR}") +set(PCRE2_CONFIG_IN ${PROJECT_SOURCE_DIR}/cmake/pcre2-config.cmake.in) +set(PCRE2_CONFIG_OUT ${PROJECT_BINARY_DIR}/cmake/pcre2-config.cmake) +configure_package_config_file(${PCRE2_CONFIG_IN} ${PCRE2_CONFIG_OUT} INSTALL_DESTINATION ${PCRE2_INSTALL_CMAKEDIR}) +set(PCRE2_CONFIG_VERSION_OUT ${PROJECT_BINARY_DIR}/cmake/pcre2-config-version.cmake) +write_basic_package_version_file( + ${PCRE2_CONFIG_VERSION_OUT} + VERSION ${PCRE2_MAJOR}.${PCRE2_MINOR}.0 + COMPATIBILITY SameMajorVersion +) +install(FILES ${PCRE2_CONFIG_OUT} ${PCRE2_CONFIG_VERSION_OUT} DESTINATION ${PCRE2_INSTALL_CMAKEDIR}) +file(GLOB html ${PROJECT_SOURCE_DIR}/doc/html/*.html ${PROJECT_SOURCE_DIR}/doc/html/*.txt) file( GLOB txts + ${PROJECT_SOURCE_DIR}/doc/*.txt AUTHORS.md + COPYING + ChangeLog LICENCE.md + NEWS + README SECURITY.md ) +file(GLOB man1 ${PROJECT_SOURCE_DIR}/doc/*.1) +file(GLOB man3 ${PROJECT_SOURCE_DIR}/doc/*.3) +install(FILES ${man1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) +install(FILES ${man3} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) install(FILES ${txts} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/pcre2) +install(FILES ${html} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/pcre2/html) if(MSVC AND INSTALL_MSVC_PDB) - install(FILES ${DLL_PDB_FILES} DESTINATION bin CONFIGURATIONS RelWithDebInfo) - install(FILES ${DLL_PDB_DEBUG_FILES} DESTINATION bin CONFIGURATIONS Debug) + install(FILES ${DLL_PDB_FILES} DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS RelWithDebInfo) + install(FILES ${DLL_PDB_DEBUG_FILES} DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug) endif() # Help, only for nice output @@ -1289,6 +1497,7 @@ if(PCRE2_SHOW_REPORT) message(STATUS " Install prefix .................... : ${CMAKE_INSTALL_PREFIX}") message(STATUS " C compiler ........................ : ${CMAKE_C_COMPILER}") + set(CFSP "") if(CMAKE_C_FLAGS) set(CFSP " ") endif() @@ -1302,7 +1511,12 @@ if(PCRE2_SHOW_REPORT) endforeach() else() string(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype) - message(STATUS " C compiler flags .................. : ${CMAKE_C_FLAGS}${CFSP}${CMAKE_C_FLAGS_${buildtype}}") + if(buildtype STREQUAL "") + set(CFBLD "") + else() + set(CFBLD "${CMAKE_C_FLAGS_${buildtype}}") + endif() + message(STATUS " C compiler flags .................. : ${CMAKE_C_FLAGS}${CFSP}${CFBLD}") endif() message(STATUS "") @@ -1311,9 +1525,9 @@ if(PCRE2_SHOW_REPORT) else() message(STATUS " Build type ........................ : ${CMAKE_BUILD_TYPE}") endif() - message(STATUS " Build 8 bit PCRE2 library ......... : ${PCRE2_BUILD_PCRE2_8}") - message(STATUS " Build 16 bit PCRE2 library ........ : ${PCRE2_BUILD_PCRE2_16}") - message(STATUS " Build 32 bit PCRE2 library ........ : ${PCRE2_BUILD_PCRE2_32}") + message(STATUS " Build 8 bit pcre2 library ......... : ${PCRE2_BUILD_PCRE2_8}") + message(STATUS " Build 16 bit pcre2 library ........ : ${PCRE2_BUILD_PCRE2_16}") + message(STATUS " Build 32 bit pcre2 library ........ : ${PCRE2_BUILD_PCRE2_32}") message(STATUS " Include debugging code ............ : ${PCRE2_DEBUG}") message(STATUS " Enable JIT compiling support ...... : ${PCRE2_SUPPORT_JIT}") message(STATUS " Use SELinux allocator in JIT ...... : ${PCRE2_SUPPORT_JIT_SEALLOC}") @@ -1321,23 +1535,39 @@ if(PCRE2_SHOW_REPORT) message(STATUS " Newline char/sequence ............. : ${PCRE2_NEWLINE}") message(STATUS " \\R matches only ANYCRLF ........... : ${PCRE2_SUPPORT_BSR_ANYCRLF}") message(STATUS " \\C is disabled .................... : ${PCRE2_NEVER_BACKSLASH_C}") - message(STATUS " EBCDIC coding ..................... : ${PCRE2_EBCDIC}") - message(STATUS " EBCDIC coding with NL=0x25 ........ : ${PCRE2_EBCDIC_NL25}") - message(STATUS " Rebuild char tables ............... : ${PCRE2_REBUILD_CHARTABLES}") + + if(NOT EBCDIC) + set(EBCDIC_NL_CODE "n/a") + elseif(EBCDIC_NL25) + set(EBCDIC_NL_CODE "0x25") + else() + set(EBCDIC_NL_CODE "0x15") + endif() + message(STATUS " EBCDIC coding ..................... : ${EBCDIC}") + message(STATUS " EBCDIC code for NL ................ : ${EBCDIC_NL_CODE}") + message(STATUS " EBCDIC coding ignoring compiler ... : ${PCRE2_EBCDIC_IGNORING_COMPILER}") + message(STATUS " Rebuild char tables ............... : ${REBUILD_CHARTABLES}") + message(STATUS " Internal link size ................ : ${PCRE2_LINK_SIZE}") message(STATUS " Maximum variable lookbehind ....... : ${PCRE2_MAX_VARLOOKBEHIND}") - message(STATUS " Parentheses nest limit ............ : ${PCRE2_PARENS_NEST_LIMIT}") + message(STATUS " Nested parentheses limit .......... : ${PCRE2_PARENS_NEST_LIMIT}") message(STATUS " Heap limit ........................ : ${PCRE2_HEAP_LIMIT}") message(STATUS " Match limit ....................... : ${PCRE2_MATCH_LIMIT}") message(STATUS " Match depth limit ................. : ${PCRE2_MATCH_LIMIT_DEPTH}") message(STATUS " Build shared libs ................. : ${BUILD_SHARED_LIBS}") + if(NOT HAVE_VSCRIPT) + message(STATUS " with symbol versioning ........ : n/a") + else() + message(STATUS " with symbol versioning ........ : ${PCRE2_SYMVERS}") + endif() message(STATUS " Build static libs ................. : ${BUILD_STATIC_LIBS}") - message(STATUS " with PIC enabled ............... : ${PCRE2_STATIC_PIC}") + message(STATUS " with PIC enabled .............. : ${PCRE2_STATIC_PIC}") message(STATUS " Build pcre2grep ................... : ${PCRE2_BUILD_PCRE2GREP}") message(STATUS " Enable JIT in pcre2grep ........... : ${PCRE2GREP_SUPPORT_JIT}") message(STATUS " Enable callouts in pcre2grep ...... : ${PCRE2GREP_SUPPORT_CALLOUT}") message(STATUS " Enable callout fork in pcre2grep .. : ${PCRE2GREP_SUPPORT_CALLOUT_FORK}") - message(STATUS " Buffer size for pcre2grep ......... : ${PCRE2GREP_BUFSIZE}") + message(STATUS " Initial buffer size for pcre2grep . : ${PCRE2GREP_BUFSIZE}") + message(STATUS " Maximum buffer size for pcre2grep . : ${PCRE2GREP_MAX_BUFSIZE}") message(STATUS " Build tests (implies pcre2test .... : ${PCRE2_BUILD_TESTS}") message(STATUS " and pcre2grep)") if(ZLIB_FOUND) @@ -1360,7 +1590,7 @@ if(PCRE2_SHOW_REPORT) else() message(STATUS " Link pcre2test with libreadline ... : Library not found") endif() - message(STATUS " Support Valgrind .................. : ${PCRE2_SUPPORT_VALGRIND}") + message(STATUS " Enable Valgrind support ........... : ${PCRE2_SUPPORT_VALGRIND}") if(PCRE2_DISABLE_PERCENT_ZT) message(STATUS " Use %zu and %td ................... : OFF") else() diff --git a/libpcre/LICENCE.md b/libpcre/LICENCE.md index f58ceb75a..f6fba35db 100644 --- a/libpcre/LICENCE.md +++ b/libpcre/LICENCE.md @@ -1,4 +1,4 @@ -PCRE2 License +PCRE2 Licence ============= | SPDX-License-Identifier: | BSD-3-Clause WITH PCRE2-exception | @@ -16,7 +16,8 @@ testdata directory is not copyrighted and is in the public domain. The basic library functions are written in C and are freestanding. Also included in the distribution is a just-in-time compiler that can be used to optimize pattern matching. This is an optional feature that can be omitted when -the library is built. +the library is built. The just-in-time compiler is separately licensed under the +"2-clause BSD" licence. COPYRIGHT @@ -53,6 +54,8 @@ COPYRIGHT Copyright (c) 2009-2024 Zoltan Herczeg All rights reserved. +The code in the `deps/sljit` directory has its own LICENSE file. + ### All other contributions Many other contributors have participated in the authorship of PCRE2. As PCRE2 @@ -99,5 +102,3 @@ not apply all the way down a chain of software. If binary package A includes PCRE2, it must respect the condition, but if package B is software that includes package A, the condition is not imposed on package B unless it uses PCRE2 independently. - -End diff --git a/libpcre/MODULE.bazel b/libpcre/MODULE.bazel index 8f4c0b46c..abed25aa8 100644 --- a/libpcre/MODULE.bazel +++ b/libpcre/MODULE.bazel @@ -1,9 +1,9 @@ module( name = "pcre2", - version = "10.45", + version = "10.47", compatibility_level = 1, ) -bazel_dep(name = "rules_cc", version = "0.0.1") -bazel_dep(name = "bazel_skylib", version = "1.2.1") -bazel_dep(name = "platforms", version = "0.0.4") +bazel_dep(name = "rules_cc", version = "0.2.8") +bazel_dep(name = "bazel_skylib", version = "1.8.1") +bazel_dep(name = "platforms", version = "1.0.0") diff --git a/libpcre/Makefile.am b/libpcre/Makefile.am index 721ca204d..31f42b43a 100644 --- a/libpcre/Makefile.am +++ b/libpcre/Makefile.am @@ -7,6 +7,12 @@ ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS="-I$(srcdir)/src" +## Set some variables to accumulate conditionally-set Automake targets. + +CLEAN_LOCAL_TARGETS= +DISTCLEAN_LOCAL_TARGETS= +PHONY_TARGETS= + ## Specify the documentation files that are distributed. dist_doc_DATA = \ @@ -22,6 +28,7 @@ lib_LTLIBRARIES = # TESTS is for binary unit tests, check_SCRIPTS for script-based tests TESTS = +XFAIL_TESTS = check_SCRIPTS = dist_noinst_SCRIPTS = @@ -38,12 +45,7 @@ noinst_PROGRAMS = # we list them here. CLEANFILES = \ - pcre2_dftables \ - pcre2_jit_test \ - pcre2fuzzcheck-8 \ - pcre2fuzzcheck-16 \ - pcre2fuzzcheck-32 \ - pcre2demo + pcre2_dftables DISTCLEANFILES = src/config.h.in~ MAINTAINERCLEANFILES = @@ -56,14 +58,16 @@ EXTRA_DIST = # These files contain additional m4 macros that are used by autoconf. EXTRA_DIST += \ - m4/ax_pthread.m4 m4/pcre2_visibility.m4 + m4/ax_check_vscript.m4 \ + m4/ax_pthread.m4 \ + m4/pcre2_visibility.m4 \ + m4/pcre2_zos.m4 # These are support files for building with Bazel or Zig EXTRA_DIST += \ BUILD.bazel \ MODULE.bazel \ - WORKSPACE.bazel \ build.zig # These are support files for building under VMS @@ -97,8 +101,9 @@ src/pcre2.h.generic: src/pcre2.h.in configure.ac # running configure in a new directory, it complains. For this reason, we move # config.status out of the way while doing the default configuration. The # resulting config.h is munged by perl to put #ifdefs round any #defines for -# macros with values, and to #undef all boolean macros such as HAVE_xxx and -# SUPPORT_xxx. We also get rid of any gcc-specific visibility settings. +# macros with values, and to #undef all boolean macros such as HAVE_xxx, +# SUPPORT_xxx, and PCRE2_STATIC/PCRE2POSIX_SHARED. We also get rid of any +# GCC-specific visibility settings. src/config.h.generic: configure.ac rm -rf $@ _generic @@ -108,13 +113,13 @@ src/config.h.generic: configure.ac cs=$(srcdir)/config.status; test ! -f $$cs.aside || mv -f $$cs.aside $$cs test -f _generic/src/config.h perl -n \ - -e 'BEGIN{$$blank=0;}' \ - -e 'if(/(.+?)\s*__attribute__ \(\(visibility/){print"$$1\n";$$blank=0;next;}' \ - -e 'if(/LT_OBJDIR/){print"/* This is ignored unless you are using libtool. */\n";}' \ - -e 'if(/^#define\s((?:HAVE|SUPPORT|STDC)_\w+)/){print"/* #undef $$1 */\n";$$blank=0;next;}' \ - -e 'if(/^#define\s(?!PACKAGE|VERSION)(\w+)/){print"#ifndef $$1\n$$_#endif\n";$$blank=0;next;}' \ - -e 'if(/^\s*$$/){print unless $$blank; $$blank=1;} else{print;$$blank=0;}' \ - _generic/src/config.h >$@ + -e 'BEGIN{$$blank=0;}' \ + -e 'if(/(.+?)\s*__attribute__ \(\(visibility/){print"$$1\n";$$blank=0;next;}' \ + -e 'if(/LT_OBJDIR/){print"/* This is ignored unless you are using libtool. */\n";}' \ + -e 'if(/^#define\s((?:HAVE|SUPPORT|STDC)_\w+|PCRE2_STATIC|PCRE2POSIX_SHARED)/){print"/* #undef $$1 */\n";$$blank=0;next;}' \ + -e 'if(/^#define\s(?!PACKAGE|VERSION)(\w+)/){print"#ifndef $$1\n$$_#endif\n";$$blank=0;next;}' \ + -e 'if(/^\s*$$/){print unless $$blank; $$blank=1;} else{print;$$blank=0;}' \ + _generic/src/config.h >$@ rm -rf _generic MAINTAINERCLEANFILES += src/pcre2.h.generic src/config.h.generic @@ -143,9 +148,21 @@ src/pcre2_chartables.c: pcre2_dftables$(EXEEXT) rm -f $@ ./pcre2_dftables$(EXEEXT) $@ else +if WITH_EBCDIC +if WITH_EBCDIC_NL25 +src/pcre2_chartables.c: $(srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl25 + rm -f $@ + $(LN_S) $(abs_srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl25 $(abs_builddir)/src/pcre2_chartables.c +else # WITH_EBCDIC_NL25 +src/pcre2_chartables.c: $(srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl15 + rm -f $@ + $(LN_S) $(abs_srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl15 $(abs_builddir)/src/pcre2_chartables.c +endif # WITH_EBCDIC_NL25 +else # WITH_EBCDIC src/pcre2_chartables.c: $(srcdir)/src/pcre2_chartables.c.dist rm -f $@ $(LN_S) $(abs_srcdir)/src/pcre2_chartables.c.dist $(abs_builddir)/src/pcre2_chartables.c +endif # WITH_EBCDIC endif # WITH_REBUILD_CHARTABLES BUILT_SOURCES = src/pcre2_chartables.c @@ -159,6 +176,7 @@ COMMON_SOURCES = \ src/pcre2_chkdint.c \ src/pcre2_compile.c \ src/pcre2_compile.h \ + src/pcre2_compile_cgroup.c \ src/pcre2_compile_class.c \ src/pcre2_config.c \ src/pcre2_context.c \ @@ -169,11 +187,10 @@ COMMON_SOURCES = \ src/pcre2_find_bracket.c \ src/pcre2_internal.h \ src/pcre2_intmodedep.h \ - src/pcre2_jit_char_inc.h \ - src/pcre2_jit_compile.c \ src/pcre2_maketables.c \ src/pcre2_match.c \ src/pcre2_match_data.c \ + src/pcre2_match_next.c \ src/pcre2_newline.c \ src/pcre2_ord2utf.c \ src/pcre2_pattern_info.c \ @@ -186,14 +203,11 @@ COMMON_SOURCES = \ src/pcre2_tables.c \ src/pcre2_ucd.c \ src/pcre2_ucp.h \ + src/pcre2_ucptables_inc.h \ src/pcre2_util.h \ src/pcre2_valid_utf.c \ src/pcre2_xclass.c -# The pcre2_ucptables.c file is #included by pcre2_tables.c - -EXTRA_DIST += src/pcre2_ucptables.c - if WITH_PCRE2_8 lib_LTLIBRARIES += libpcre2-8.la libpcre2_8_la_SOURCES = \ @@ -239,10 +253,12 @@ endif # WITH_PCRE2_32 # The pcre2_chartables.c.dist file is the default version of # pcre2_chartables.c, used unless --enable-rebuild-chartables is specified. -EXTRA_DIST += src/pcre2_chartables.c.dist +EXTRA_DIST += \ + src/pcre2_chartables.c.dist \ + src/pcre2_chartables.c.ebcdic-1047-nl15 \ + src/pcre2_chartables.c.ebcdic-1047-nl25 CLEANFILES += src/pcre2_chartables.c - if WITH_PCRE2_8 libpcre2_8_la_LDFLAGS = $(EXTRA_LIBPCRE2_8_LDFLAGS) endif # WITH_PCRE2_8 @@ -292,9 +308,44 @@ libpcre2_posix_la_CFLAGS += $(GCOV_CFLAGS) endif # WITH_GCOV endif # WITH_PCRE2_8 -## If fuzzer support is enabled, build a non-distributed library containing the -## fuzzing function. Also build the standalone checking binary from the same -## source but using -DSTANDALONE. + +## -------- Testing ---------- + +# RunTest and RunGrepTest should clean up after themselves, but just in case +# they don't, add their working files to CLEANFILES. + +CLEANFILES += \ + testSinput \ + testSoutput \ + test3input \ + test3output \ + test3outputA \ + test3outputB \ + testtry \ + teststdout \ + teststderr \ + teststderrgrep \ + testtemp1grep \ + testtemp2grep \ + testtrygrep \ + testNinputgrep + +testoutput-clean: + -rm -rf testoutput8 testoutput8-jit testoutput8-dfa + -rm -rf testoutput16 testoutput16-jit testoutput16-dfa + -rm -rf testoutput32 testoutput32-jit testoutput32-dfa + +CLEAN_LOCAL_TARGETS += testoutput-clean +PHONY_TARGETS += testoutput-clean + +## ------------ End of testing ------------- + +# Symbol version files for use with GNU and Sun ld. + +EXTRA_DIST += \ + src/libpcre2-8.sym src/libpcre2-16.sym src/libpcre2-32.sym \ + src/libpcre2-posix.sym + # gcov/lcov code coverage reporting # @@ -375,35 +426,48 @@ coverage-clean: coverage-reset coverage-clean-report coverage-clean-data coverage-distclean: coverage-clean coverage: coverage-reset coverage-baseline coverage-check coverage-report -clean-local: coverage-clean -distclean-local: coverage-distclean -.PHONY: coverage coverage-baseline coverage-check coverage-report coverage-reset coverage-clean-report coverage-clean-data coverage-clean coverage-distclean - -# Without coverage support, still arrange for 'make distclean' to get rid of -# any coverage files that may have been left from a different configuration. +CLEAN_LOCAL_TARGETS += coverage-clean +DISTCLEAN_LOCAL_TARGETS += coverage-distclean +PHONY_TARGETS += coverage coverage-baseline coverage-check coverage-report coverage-reset coverage-clean-report coverage-clean-data coverage-clean coverage-distclean else coverage: @echo "Configuring with --enable-coverage is required to generate code coverage report." +# Without coverage support, still arrange for 'make distclean' to get rid of +# any coverage files that may have been left from a different configuration. + DISTCLEANFILES += src/*.gcda src/*.gcno -distclean-local: +coverage-distclean: rm -rf $(PACKAGE)-$(VERSION)-coverage* +DISTCLEAN_LOCAL_TARGETS += coverage-distclean +PHONY_TARGETS += coverage-distclean + endif # WITH_GCOV ## CMake support EXTRA_DIST += \ cmake/COPYING-CMAKE-SCRIPTS \ - cmake/FindEditline.cmake \ - cmake/FindReadline.cmake \ - cmake/pcre2-config-version.cmake.in \ cmake/pcre2-config.cmake.in \ - CMakeLists.txt \ - config-cmake.h.in + cmake/PCRE2CheckVscript.cmake \ + cmake/PCRE2UseSystemExtensions.cmake \ + cmake/PCRE2WarningAsError.cmake \ + src/config-cmake.h.in \ + CMakeLists.txt + +## Set the special make and Automake targets. We could very easily simply +## redefine these targets to append prerequisites to them, rather than +## collecting the prerequisites in variables. However, there is an annoying +## Automake behaviour where it emits a warning if a target has prerequisites +## appended in a conditional block. + +clean-local: $(CLEAN_LOCAL_TARGETS) +distclean-local: $(DISTCLEAN_LOCAL_TARGETS) +.PHONY: $(PHONY_TARGETS) ## end Makefile.am diff --git a/libpcre/Makefile.in b/libpcre/Makefile.in index ccde2c261..5f3463d20 100644 --- a/libpcre/Makefile.in +++ b/libpcre/Makefile.in @@ -93,6 +93,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ TESTS = +XFAIL_TESTS = bin_PROGRAMS = noinst_PROGRAMS = $(am__EXEEXT_1) @WITH_REBUILD_CHARTABLES_TRUE@am__append_1 = pcre2_dftables @@ -107,15 +108,23 @@ noinst_PROGRAMS = $(am__EXEEXT_1) @WITH_GCOV_TRUE@@WITH_PCRE2_32_TRUE@am__append_10 = $(GCOV_CFLAGS) @WITH_PCRE2_8_TRUE@am__append_11 = libpcre2-posix.la @WITH_GCOV_TRUE@@WITH_PCRE2_8_TRUE@am__append_12 = $(GCOV_CFLAGS) -@WITH_GCOV_FALSE@am__append_13 = src/*.gcda src/*.gcno +@WITH_GCOV_TRUE@am__append_13 = coverage-clean +@WITH_GCOV_TRUE@am__append_14 = coverage-distclean +@WITH_GCOV_TRUE@am__append_15 = coverage coverage-baseline coverage-check coverage-report coverage-reset coverage-clean-report coverage-clean-data coverage-clean coverage-distclean + +# Without coverage support, still arrange for 'make distclean' to get rid of +# any coverage files that may have been left from a different configuration. +@WITH_GCOV_FALSE@am__append_16 = src/*.gcda src/*.gcno +@WITH_GCOV_FALSE@am__append_17 = coverage-distclean +@WITH_GCOV_FALSE@am__append_18 = coverage-distclean subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/ax_pthread.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_vscript.m4 \ + $(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/m4/pcre2_visibility.m4 \ - $(top_srcdir)/configure.ac + $(top_srcdir)/m4/pcre2_zos.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ @@ -163,22 +172,24 @@ LTLIBRARIES = $(lib_LTLIBRARIES) libpcre2_16_la_DEPENDENCIES = am__libpcre2_16_la_SOURCES_DIST = src/pcre2_auto_possess.c \ src/pcre2_chkdint.c src/pcre2_compile.c src/pcre2_compile.h \ - src/pcre2_compile_class.c src/pcre2_config.c \ - src/pcre2_context.c src/pcre2_convert.c src/pcre2_dfa_match.c \ - src/pcre2_error.c src/pcre2_extuni.c src/pcre2_find_bracket.c \ - src/pcre2_internal.h src/pcre2_intmodedep.h \ - src/pcre2_jit_char_inc.h src/pcre2_jit_compile.c \ - src/pcre2_maketables.c src/pcre2_match.c \ - src/pcre2_match_data.c src/pcre2_newline.c src/pcre2_ord2utf.c \ + src/pcre2_compile_cgroup.c src/pcre2_compile_class.c \ + src/pcre2_config.c src/pcre2_context.c src/pcre2_convert.c \ + src/pcre2_dfa_match.c src/pcre2_error.c src/pcre2_extuni.c \ + src/pcre2_find_bracket.c src/pcre2_internal.h \ + src/pcre2_intmodedep.h src/pcre2_maketables.c \ + src/pcre2_match.c src/pcre2_match_data.c \ + src/pcre2_match_next.c src/pcre2_newline.c src/pcre2_ord2utf.c \ src/pcre2_pattern_info.c src/pcre2_script_run.c \ src/pcre2_serialize.c src/pcre2_string_utils.c \ src/pcre2_study.c src/pcre2_substitute.c src/pcre2_substring.c \ src/pcre2_tables.c src/pcre2_ucd.c src/pcre2_ucp.h \ - src/pcre2_util.h src/pcre2_valid_utf.c src/pcre2_xclass.c + src/pcre2_ucptables_inc.h src/pcre2_util.h \ + src/pcre2_valid_utf.c src/pcre2_xclass.c am__dirstamp = $(am__leading_dot)dirstamp am__objects_1 = src/libpcre2_16_la-pcre2_auto_possess.lo \ src/libpcre2_16_la-pcre2_chkdint.lo \ src/libpcre2_16_la-pcre2_compile.lo \ + src/libpcre2_16_la-pcre2_compile_cgroup.lo \ src/libpcre2_16_la-pcre2_compile_class.lo \ src/libpcre2_16_la-pcre2_config.lo \ src/libpcre2_16_la-pcre2_context.lo \ @@ -187,10 +198,10 @@ am__objects_1 = src/libpcre2_16_la-pcre2_auto_possess.lo \ src/libpcre2_16_la-pcre2_error.lo \ src/libpcre2_16_la-pcre2_extuni.lo \ src/libpcre2_16_la-pcre2_find_bracket.lo \ - src/libpcre2_16_la-pcre2_jit_compile.lo \ src/libpcre2_16_la-pcre2_maketables.lo \ src/libpcre2_16_la-pcre2_match.lo \ src/libpcre2_16_la-pcre2_match_data.lo \ + src/libpcre2_16_la-pcre2_match_next.lo \ src/libpcre2_16_la-pcre2_newline.lo \ src/libpcre2_16_la-pcre2_ord2utf.lo \ src/libpcre2_16_la-pcre2_pattern_info.lo \ @@ -221,21 +232,23 @@ libpcre2_16_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ libpcre2_32_la_DEPENDENCIES = am__libpcre2_32_la_SOURCES_DIST = src/pcre2_auto_possess.c \ src/pcre2_chkdint.c src/pcre2_compile.c src/pcre2_compile.h \ - src/pcre2_compile_class.c src/pcre2_config.c \ - src/pcre2_context.c src/pcre2_convert.c src/pcre2_dfa_match.c \ - src/pcre2_error.c src/pcre2_extuni.c src/pcre2_find_bracket.c \ - src/pcre2_internal.h src/pcre2_intmodedep.h \ - src/pcre2_jit_char_inc.h src/pcre2_jit_compile.c \ - src/pcre2_maketables.c src/pcre2_match.c \ - src/pcre2_match_data.c src/pcre2_newline.c src/pcre2_ord2utf.c \ + src/pcre2_compile_cgroup.c src/pcre2_compile_class.c \ + src/pcre2_config.c src/pcre2_context.c src/pcre2_convert.c \ + src/pcre2_dfa_match.c src/pcre2_error.c src/pcre2_extuni.c \ + src/pcre2_find_bracket.c src/pcre2_internal.h \ + src/pcre2_intmodedep.h src/pcre2_maketables.c \ + src/pcre2_match.c src/pcre2_match_data.c \ + src/pcre2_match_next.c src/pcre2_newline.c src/pcre2_ord2utf.c \ src/pcre2_pattern_info.c src/pcre2_script_run.c \ src/pcre2_serialize.c src/pcre2_string_utils.c \ src/pcre2_study.c src/pcre2_substitute.c src/pcre2_substring.c \ src/pcre2_tables.c src/pcre2_ucd.c src/pcre2_ucp.h \ - src/pcre2_util.h src/pcre2_valid_utf.c src/pcre2_xclass.c + src/pcre2_ucptables_inc.h src/pcre2_util.h \ + src/pcre2_valid_utf.c src/pcre2_xclass.c am__objects_3 = src/libpcre2_32_la-pcre2_auto_possess.lo \ src/libpcre2_32_la-pcre2_chkdint.lo \ src/libpcre2_32_la-pcre2_compile.lo \ + src/libpcre2_32_la-pcre2_compile_cgroup.lo \ src/libpcre2_32_la-pcre2_compile_class.lo \ src/libpcre2_32_la-pcre2_config.lo \ src/libpcre2_32_la-pcre2_context.lo \ @@ -244,10 +257,10 @@ am__objects_3 = src/libpcre2_32_la-pcre2_auto_possess.lo \ src/libpcre2_32_la-pcre2_error.lo \ src/libpcre2_32_la-pcre2_extuni.lo \ src/libpcre2_32_la-pcre2_find_bracket.lo \ - src/libpcre2_32_la-pcre2_jit_compile.lo \ src/libpcre2_32_la-pcre2_maketables.lo \ src/libpcre2_32_la-pcre2_match.lo \ src/libpcre2_32_la-pcre2_match_data.lo \ + src/libpcre2_32_la-pcre2_match_next.lo \ src/libpcre2_32_la-pcre2_newline.lo \ src/libpcre2_32_la-pcre2_ord2utf.lo \ src/libpcre2_32_la-pcre2_pattern_info.lo \ @@ -274,21 +287,23 @@ libpcre2_32_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ libpcre2_8_la_DEPENDENCIES = am__libpcre2_8_la_SOURCES_DIST = src/pcre2_auto_possess.c \ src/pcre2_chkdint.c src/pcre2_compile.c src/pcre2_compile.h \ - src/pcre2_compile_class.c src/pcre2_config.c \ - src/pcre2_context.c src/pcre2_convert.c src/pcre2_dfa_match.c \ - src/pcre2_error.c src/pcre2_extuni.c src/pcre2_find_bracket.c \ - src/pcre2_internal.h src/pcre2_intmodedep.h \ - src/pcre2_jit_char_inc.h src/pcre2_jit_compile.c \ - src/pcre2_maketables.c src/pcre2_match.c \ - src/pcre2_match_data.c src/pcre2_newline.c src/pcre2_ord2utf.c \ + src/pcre2_compile_cgroup.c src/pcre2_compile_class.c \ + src/pcre2_config.c src/pcre2_context.c src/pcre2_convert.c \ + src/pcre2_dfa_match.c src/pcre2_error.c src/pcre2_extuni.c \ + src/pcre2_find_bracket.c src/pcre2_internal.h \ + src/pcre2_intmodedep.h src/pcre2_maketables.c \ + src/pcre2_match.c src/pcre2_match_data.c \ + src/pcre2_match_next.c src/pcre2_newline.c src/pcre2_ord2utf.c \ src/pcre2_pattern_info.c src/pcre2_script_run.c \ src/pcre2_serialize.c src/pcre2_string_utils.c \ src/pcre2_study.c src/pcre2_substitute.c src/pcre2_substring.c \ src/pcre2_tables.c src/pcre2_ucd.c src/pcre2_ucp.h \ - src/pcre2_util.h src/pcre2_valid_utf.c src/pcre2_xclass.c + src/pcre2_ucptables_inc.h src/pcre2_util.h \ + src/pcre2_valid_utf.c src/pcre2_xclass.c am__objects_5 = src/libpcre2_8_la-pcre2_auto_possess.lo \ src/libpcre2_8_la-pcre2_chkdint.lo \ src/libpcre2_8_la-pcre2_compile.lo \ + src/libpcre2_8_la-pcre2_compile_cgroup.lo \ src/libpcre2_8_la-pcre2_compile_class.lo \ src/libpcre2_8_la-pcre2_config.lo \ src/libpcre2_8_la-pcre2_context.lo \ @@ -297,10 +312,10 @@ am__objects_5 = src/libpcre2_8_la-pcre2_auto_possess.lo \ src/libpcre2_8_la-pcre2_error.lo \ src/libpcre2_8_la-pcre2_extuni.lo \ src/libpcre2_8_la-pcre2_find_bracket.lo \ - src/libpcre2_8_la-pcre2_jit_compile.lo \ src/libpcre2_8_la-pcre2_maketables.lo \ src/libpcre2_8_la-pcre2_match.lo \ src/libpcre2_8_la-pcre2_match_data.lo \ + src/libpcre2_8_la-pcre2_match_next.lo \ src/libpcre2_8_la-pcre2_newline.lo \ src/libpcre2_8_la-pcre2_ord2utf.lo \ src/libpcre2_8_la-pcre2_pattern_info.lo \ @@ -359,6 +374,7 @@ am__depfiles_remade = \ src/$(DEPDIR)/libpcre2_16_la-pcre2_chartables.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_chkdint.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_compile.Plo \ + src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_cgroup.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_class.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_config.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_context.Plo \ @@ -367,10 +383,10 @@ am__depfiles_remade = \ src/$(DEPDIR)/libpcre2_16_la-pcre2_error.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_extuni.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_find_bracket.Plo \ - src/$(DEPDIR)/libpcre2_16_la-pcre2_jit_compile.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_maketables.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_match.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_match_data.Plo \ + src/$(DEPDIR)/libpcre2_16_la-pcre2_match_next.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_newline.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_ord2utf.Plo \ src/$(DEPDIR)/libpcre2_16_la-pcre2_pattern_info.Plo \ @@ -388,6 +404,7 @@ am__depfiles_remade = \ src/$(DEPDIR)/libpcre2_32_la-pcre2_chartables.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_chkdint.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_compile.Plo \ + src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_cgroup.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_class.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_config.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_context.Plo \ @@ -396,10 +413,10 @@ am__depfiles_remade = \ src/$(DEPDIR)/libpcre2_32_la-pcre2_error.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_extuni.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_find_bracket.Plo \ - src/$(DEPDIR)/libpcre2_32_la-pcre2_jit_compile.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_maketables.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_match.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_match_data.Plo \ + src/$(DEPDIR)/libpcre2_32_la-pcre2_match_next.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_newline.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_ord2utf.Plo \ src/$(DEPDIR)/libpcre2_32_la-pcre2_pattern_info.Plo \ @@ -417,6 +434,7 @@ am__depfiles_remade = \ src/$(DEPDIR)/libpcre2_8_la-pcre2_chartables.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_chkdint.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_compile.Plo \ + src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_cgroup.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_class.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_config.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_context.Plo \ @@ -425,10 +443,10 @@ am__depfiles_remade = \ src/$(DEPDIR)/libpcre2_8_la-pcre2_error.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_extuni.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_find_bracket.Plo \ - src/$(DEPDIR)/libpcre2_8_la-pcre2_jit_compile.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_maketables.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_match.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_match_data.Plo \ + src/$(DEPDIR)/libpcre2_8_la-pcre2_match_next.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_newline.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_ord2utf.Plo \ src/$(DEPDIR)/libpcre2_8_la-pcre2_pattern_info.Plo \ @@ -708,6 +726,7 @@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CET_CFLAGS = @CET_CFLAGS@ CFLAGS = @CFLAGS@ +CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ @@ -784,6 +803,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ +PTHREAD_CXX = @PTHREAD_CXX@ PTHREAD_LIBS = @PTHREAD_LIBS@ RANLIB = @RANLIB@ SED = @SED@ @@ -795,6 +815,7 @@ VALGRIND_CFLAGS = @VALGRIND_CFLAGS@ VALGRIND_LIBS = @VALGRIND_LIBS@ VERSION = @VERSION@ VISIBILITY_CFLAGS = @VISIBILITY_CFLAGS@ +VSCRIPT_LDFLAGS = @VSCRIPT_LDFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -855,6 +876,9 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = subdir-objects ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS = "-I$(srcdir)/src" +CLEAN_LOCAL_TARGETS = testoutput-clean $(am__append_13) +DISTCLEAN_LOCAL_TARGETS = $(am__append_14) $(am__append_17) +PHONY_TARGETS = testoutput-clean $(am__append_15) $(am__append_18) dist_doc_DATA = \ AUTHORS.md \ LICENCE.md \ @@ -872,10 +896,14 @@ dist_noinst_SCRIPTS = # those binaries that *this* configuration has created. If the configuration # has been changed, some binaries may not get automatically deleted. Therefore # we list them here. -CLEANFILES = pcre2_dftables pcre2_jit_test pcre2fuzzcheck-8 \ - pcre2fuzzcheck-16 pcre2fuzzcheck-32 pcre2demo \ - src/pcre2_chartables.c -DISTCLEANFILES = src/config.h.in~ $(am__append_13) + +# RunTest and RunGrepTest should clean up after themselves, but just in case +# they don't, add their working files to CLEANFILES. +CLEANFILES = pcre2_dftables src/pcre2_chartables.c testSinput \ + testSoutput test3input test3output test3outputA test3outputB \ + testtry teststdout teststderr teststderrgrep testtemp1grep \ + testtemp2grep testtrygrep testNinputgrep +DISTCLEANFILES = src/config.h.in~ $(am__append_16) MAINTAINERCLEANFILES = src/pcre2.h.generic src/config.h.generic # Additional files to bundle with the distribution, over and above what @@ -891,18 +919,24 @@ MAINTAINERCLEANFILES = src/pcre2.h.generic src/config.h.generic # for the benefit of people who are building PCRE2 manually, without the # Autotools support. -# The pcre2_ucptables.c file is #included by pcre2_tables.c - # The pcre2_chartables.c.dist file is the default version of # pcre2_chartables.c, used unless --enable-rebuild-chartables is specified. -EXTRA_DIST = m4/ax_pthread.m4 m4/pcre2_visibility.m4 BUILD.bazel \ - MODULE.bazel WORKSPACE.bazel build.zig vms/configure.com \ + +# Symbol version files for use with GNU and Sun ld. +EXTRA_DIST = m4/ax_check_vscript.m4 m4/ax_pthread.m4 \ + m4/pcre2_visibility.m4 m4/pcre2_zos.m4 BUILD.bazel \ + MODULE.bazel build.zig vms/configure.com \ vms/openvms_readme.txt vms/pcre2.h_patch vms/stdint.h \ - src/pcre2.h.generic src/config.h.generic src/pcre2_ucptables.c \ - src/pcre2_chartables.c.dist cmake/COPYING-CMAKE-SCRIPTS \ - cmake/FindEditline.cmake cmake/FindReadline.cmake \ - cmake/pcre2-config-version.cmake.in \ - cmake/pcre2-config.cmake.in CMakeLists.txt config-cmake.h.in + src/pcre2.h.generic src/config.h.generic \ + src/pcre2_chartables.c.dist \ + src/pcre2_chartables.c.ebcdic-1047-nl15 \ + src/pcre2_chartables.c.ebcdic-1047-nl25 src/libpcre2-8.sym \ + src/libpcre2-16.sym src/libpcre2-32.sym src/libpcre2-posix.sym \ + cmake/COPYING-CMAKE-SCRIPTS cmake/pcre2-config.cmake.in \ + cmake/PCRE2CheckVscript.cmake \ + cmake/PCRE2UseSystemExtensions.cmake \ + cmake/PCRE2WarningAsError.cmake src/config-cmake.h.in \ + CMakeLists.txt # These are the header files we'll install. We do not distribute pcre2.h # because it is generated from pcre2.h.in. @@ -919,6 +953,7 @@ COMMON_SOURCES = \ src/pcre2_chkdint.c \ src/pcre2_compile.c \ src/pcre2_compile.h \ + src/pcre2_compile_cgroup.c \ src/pcre2_compile_class.c \ src/pcre2_config.c \ src/pcre2_context.c \ @@ -929,11 +964,10 @@ COMMON_SOURCES = \ src/pcre2_find_bracket.c \ src/pcre2_internal.h \ src/pcre2_intmodedep.h \ - src/pcre2_jit_char_inc.h \ - src/pcre2_jit_compile.c \ src/pcre2_maketables.c \ src/pcre2_match.c \ src/pcre2_match_data.c \ + src/pcre2_match_next.c \ src/pcre2_newline.c \ src/pcre2_ord2utf.c \ src/pcre2_pattern_info.c \ @@ -946,6 +980,7 @@ COMMON_SOURCES = \ src/pcre2_tables.c \ src/pcre2_ucd.c \ src/pcre2_ucp.h \ + src/pcre2_ucptables_inc.h \ src/pcre2_util.h \ src/pcre2_valid_utf.c \ src/pcre2_xclass.c @@ -1181,6 +1216,8 @@ src/libpcre2_16_la-pcre2_chkdint.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_compile.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) +src/libpcre2_16_la-pcre2_compile_cgroup.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_compile_class.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_config.lo: src/$(am__dirstamp) \ @@ -1197,14 +1234,14 @@ src/libpcre2_16_la-pcre2_extuni.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_find_bracket.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) -src/libpcre2_16_la-pcre2_jit_compile.lo: src/$(am__dirstamp) \ - src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_maketables.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_match.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_match_data.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) +src/libpcre2_16_la-pcre2_match_next.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_newline.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_16_la-pcre2_ord2utf.lo: src/$(am__dirstamp) \ @@ -1242,6 +1279,8 @@ src/libpcre2_32_la-pcre2_chkdint.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_compile.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) +src/libpcre2_32_la-pcre2_compile_cgroup.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_compile_class.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_config.lo: src/$(am__dirstamp) \ @@ -1258,14 +1297,14 @@ src/libpcre2_32_la-pcre2_extuni.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_find_bracket.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) -src/libpcre2_32_la-pcre2_jit_compile.lo: src/$(am__dirstamp) \ - src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_maketables.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_match.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_match_data.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) +src/libpcre2_32_la-pcre2_match_next.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_newline.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_32_la-pcre2_ord2utf.lo: src/$(am__dirstamp) \ @@ -1303,6 +1342,8 @@ src/libpcre2_8_la-pcre2_chkdint.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_compile.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) +src/libpcre2_8_la-pcre2_compile_cgroup.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_compile_class.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_config.lo: src/$(am__dirstamp) \ @@ -1319,14 +1360,14 @@ src/libpcre2_8_la-pcre2_extuni.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_find_bracket.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) -src/libpcre2_8_la-pcre2_jit_compile.lo: src/$(am__dirstamp) \ - src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_maketables.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_match.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_match_data.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) +src/libpcre2_8_la-pcre2_match_next.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_newline.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libpcre2_8_la-pcre2_ord2utf.lo: src/$(am__dirstamp) \ @@ -1417,6 +1458,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_chartables.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_chkdint.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_compile.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_cgroup.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_class.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_config.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_context.Plo@am__quote@ # am--include-marker @@ -1425,10 +1467,10 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_error.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_extuni.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_find_bracket.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_jit_compile.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_maketables.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_match.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_match_data.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_match_next.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_newline.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_ord2utf.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_16_la-pcre2_pattern_info.Plo@am__quote@ # am--include-marker @@ -1446,6 +1488,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_chartables.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_chkdint.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_compile.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_cgroup.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_class.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_config.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_context.Plo@am__quote@ # am--include-marker @@ -1454,10 +1497,10 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_error.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_extuni.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_find_bracket.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_jit_compile.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_maketables.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_match.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_match_data.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_match_next.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_newline.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_ord2utf.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_32_la-pcre2_pattern_info.Plo@am__quote@ # am--include-marker @@ -1475,6 +1518,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_chartables.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_chkdint.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_compile.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_cgroup.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_class.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_config.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_context.Plo@am__quote@ # am--include-marker @@ -1483,10 +1527,10 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_error.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_extuni.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_find_bracket.Plo@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_jit_compile.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_maketables.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_match.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_match_data.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_match_next.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_newline.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_ord2utf.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libpcre2_8_la-pcre2_pattern_info.Plo@am__quote@ # am--include-marker @@ -1554,6 +1598,13 @@ src/libpcre2_16_la-pcre2_compile.lo: src/pcre2_compile.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_16_la-pcre2_compile.lo `test -f 'src/pcre2_compile.c' || echo '$(srcdir)/'`src/pcre2_compile.c +src/libpcre2_16_la-pcre2_compile_cgroup.lo: src/pcre2_compile_cgroup.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_16_la-pcre2_compile_cgroup.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_cgroup.Tpo -c -o src/libpcre2_16_la-pcre2_compile_cgroup.lo `test -f 'src/pcre2_compile_cgroup.c' || echo '$(srcdir)/'`src/pcre2_compile_cgroup.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_cgroup.Tpo src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_cgroup.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_compile_cgroup.c' object='src/libpcre2_16_la-pcre2_compile_cgroup.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_16_la-pcre2_compile_cgroup.lo `test -f 'src/pcre2_compile_cgroup.c' || echo '$(srcdir)/'`src/pcre2_compile_cgroup.c + src/libpcre2_16_la-pcre2_compile_class.lo: src/pcre2_compile_class.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_16_la-pcre2_compile_class.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_class.Tpo -c -o src/libpcre2_16_la-pcre2_compile_class.lo `test -f 'src/pcre2_compile_class.c' || echo '$(srcdir)/'`src/pcre2_compile_class.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_class.Tpo src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_class.Plo @@ -1610,13 +1661,6 @@ src/libpcre2_16_la-pcre2_find_bracket.lo: src/pcre2_find_bracket.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_16_la-pcre2_find_bracket.lo `test -f 'src/pcre2_find_bracket.c' || echo '$(srcdir)/'`src/pcre2_find_bracket.c -src/libpcre2_16_la-pcre2_jit_compile.lo: src/pcre2_jit_compile.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_16_la-pcre2_jit_compile.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_16_la-pcre2_jit_compile.Tpo -c -o src/libpcre2_16_la-pcre2_jit_compile.lo `test -f 'src/pcre2_jit_compile.c' || echo '$(srcdir)/'`src/pcre2_jit_compile.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_16_la-pcre2_jit_compile.Tpo src/$(DEPDIR)/libpcre2_16_la-pcre2_jit_compile.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_jit_compile.c' object='src/libpcre2_16_la-pcre2_jit_compile.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_16_la-pcre2_jit_compile.lo `test -f 'src/pcre2_jit_compile.c' || echo '$(srcdir)/'`src/pcre2_jit_compile.c - src/libpcre2_16_la-pcre2_maketables.lo: src/pcre2_maketables.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_16_la-pcre2_maketables.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_16_la-pcre2_maketables.Tpo -c -o src/libpcre2_16_la-pcre2_maketables.lo `test -f 'src/pcre2_maketables.c' || echo '$(srcdir)/'`src/pcre2_maketables.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_16_la-pcre2_maketables.Tpo src/$(DEPDIR)/libpcre2_16_la-pcre2_maketables.Plo @@ -1638,6 +1682,13 @@ src/libpcre2_16_la-pcre2_match_data.lo: src/pcre2_match_data.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_16_la-pcre2_match_data.lo `test -f 'src/pcre2_match_data.c' || echo '$(srcdir)/'`src/pcre2_match_data.c +src/libpcre2_16_la-pcre2_match_next.lo: src/pcre2_match_next.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_16_la-pcre2_match_next.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_16_la-pcre2_match_next.Tpo -c -o src/libpcre2_16_la-pcre2_match_next.lo `test -f 'src/pcre2_match_next.c' || echo '$(srcdir)/'`src/pcre2_match_next.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_16_la-pcre2_match_next.Tpo src/$(DEPDIR)/libpcre2_16_la-pcre2_match_next.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_match_next.c' object='src/libpcre2_16_la-pcre2_match_next.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_16_la-pcre2_match_next.lo `test -f 'src/pcre2_match_next.c' || echo '$(srcdir)/'`src/pcre2_match_next.c + src/libpcre2_16_la-pcre2_newline.lo: src/pcre2_newline.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_16_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_16_la-pcre2_newline.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_16_la-pcre2_newline.Tpo -c -o src/libpcre2_16_la-pcre2_newline.lo `test -f 'src/pcre2_newline.c' || echo '$(srcdir)/'`src/pcre2_newline.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_16_la-pcre2_newline.Tpo src/$(DEPDIR)/libpcre2_16_la-pcre2_newline.Plo @@ -1757,6 +1808,13 @@ src/libpcre2_32_la-pcre2_compile.lo: src/pcre2_compile.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_32_la-pcre2_compile.lo `test -f 'src/pcre2_compile.c' || echo '$(srcdir)/'`src/pcre2_compile.c +src/libpcre2_32_la-pcre2_compile_cgroup.lo: src/pcre2_compile_cgroup.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_32_la-pcre2_compile_cgroup.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_cgroup.Tpo -c -o src/libpcre2_32_la-pcre2_compile_cgroup.lo `test -f 'src/pcre2_compile_cgroup.c' || echo '$(srcdir)/'`src/pcre2_compile_cgroup.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_cgroup.Tpo src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_cgroup.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_compile_cgroup.c' object='src/libpcre2_32_la-pcre2_compile_cgroup.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_32_la-pcre2_compile_cgroup.lo `test -f 'src/pcre2_compile_cgroup.c' || echo '$(srcdir)/'`src/pcre2_compile_cgroup.c + src/libpcre2_32_la-pcre2_compile_class.lo: src/pcre2_compile_class.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_32_la-pcre2_compile_class.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_class.Tpo -c -o src/libpcre2_32_la-pcre2_compile_class.lo `test -f 'src/pcre2_compile_class.c' || echo '$(srcdir)/'`src/pcre2_compile_class.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_class.Tpo src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_class.Plo @@ -1813,13 +1871,6 @@ src/libpcre2_32_la-pcre2_find_bracket.lo: src/pcre2_find_bracket.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_32_la-pcre2_find_bracket.lo `test -f 'src/pcre2_find_bracket.c' || echo '$(srcdir)/'`src/pcre2_find_bracket.c -src/libpcre2_32_la-pcre2_jit_compile.lo: src/pcre2_jit_compile.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_32_la-pcre2_jit_compile.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_32_la-pcre2_jit_compile.Tpo -c -o src/libpcre2_32_la-pcre2_jit_compile.lo `test -f 'src/pcre2_jit_compile.c' || echo '$(srcdir)/'`src/pcre2_jit_compile.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_32_la-pcre2_jit_compile.Tpo src/$(DEPDIR)/libpcre2_32_la-pcre2_jit_compile.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_jit_compile.c' object='src/libpcre2_32_la-pcre2_jit_compile.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_32_la-pcre2_jit_compile.lo `test -f 'src/pcre2_jit_compile.c' || echo '$(srcdir)/'`src/pcre2_jit_compile.c - src/libpcre2_32_la-pcre2_maketables.lo: src/pcre2_maketables.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_32_la-pcre2_maketables.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_32_la-pcre2_maketables.Tpo -c -o src/libpcre2_32_la-pcre2_maketables.lo `test -f 'src/pcre2_maketables.c' || echo '$(srcdir)/'`src/pcre2_maketables.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_32_la-pcre2_maketables.Tpo src/$(DEPDIR)/libpcre2_32_la-pcre2_maketables.Plo @@ -1841,6 +1892,13 @@ src/libpcre2_32_la-pcre2_match_data.lo: src/pcre2_match_data.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_32_la-pcre2_match_data.lo `test -f 'src/pcre2_match_data.c' || echo '$(srcdir)/'`src/pcre2_match_data.c +src/libpcre2_32_la-pcre2_match_next.lo: src/pcre2_match_next.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_32_la-pcre2_match_next.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_32_la-pcre2_match_next.Tpo -c -o src/libpcre2_32_la-pcre2_match_next.lo `test -f 'src/pcre2_match_next.c' || echo '$(srcdir)/'`src/pcre2_match_next.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_32_la-pcre2_match_next.Tpo src/$(DEPDIR)/libpcre2_32_la-pcre2_match_next.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_match_next.c' object='src/libpcre2_32_la-pcre2_match_next.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_32_la-pcre2_match_next.lo `test -f 'src/pcre2_match_next.c' || echo '$(srcdir)/'`src/pcre2_match_next.c + src/libpcre2_32_la-pcre2_newline.lo: src/pcre2_newline.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_32_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_32_la-pcre2_newline.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_32_la-pcre2_newline.Tpo -c -o src/libpcre2_32_la-pcre2_newline.lo `test -f 'src/pcre2_newline.c' || echo '$(srcdir)/'`src/pcre2_newline.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_32_la-pcre2_newline.Tpo src/$(DEPDIR)/libpcre2_32_la-pcre2_newline.Plo @@ -1960,6 +2018,13 @@ src/libpcre2_8_la-pcre2_compile.lo: src/pcre2_compile.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_8_la-pcre2_compile.lo `test -f 'src/pcre2_compile.c' || echo '$(srcdir)/'`src/pcre2_compile.c +src/libpcre2_8_la-pcre2_compile_cgroup.lo: src/pcre2_compile_cgroup.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_8_la-pcre2_compile_cgroup.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_cgroup.Tpo -c -o src/libpcre2_8_la-pcre2_compile_cgroup.lo `test -f 'src/pcre2_compile_cgroup.c' || echo '$(srcdir)/'`src/pcre2_compile_cgroup.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_cgroup.Tpo src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_cgroup.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_compile_cgroup.c' object='src/libpcre2_8_la-pcre2_compile_cgroup.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_8_la-pcre2_compile_cgroup.lo `test -f 'src/pcre2_compile_cgroup.c' || echo '$(srcdir)/'`src/pcre2_compile_cgroup.c + src/libpcre2_8_la-pcre2_compile_class.lo: src/pcre2_compile_class.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_8_la-pcre2_compile_class.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_class.Tpo -c -o src/libpcre2_8_la-pcre2_compile_class.lo `test -f 'src/pcre2_compile_class.c' || echo '$(srcdir)/'`src/pcre2_compile_class.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_class.Tpo src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_class.Plo @@ -2016,13 +2081,6 @@ src/libpcre2_8_la-pcre2_find_bracket.lo: src/pcre2_find_bracket.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_8_la-pcre2_find_bracket.lo `test -f 'src/pcre2_find_bracket.c' || echo '$(srcdir)/'`src/pcre2_find_bracket.c -src/libpcre2_8_la-pcre2_jit_compile.lo: src/pcre2_jit_compile.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_8_la-pcre2_jit_compile.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_8_la-pcre2_jit_compile.Tpo -c -o src/libpcre2_8_la-pcre2_jit_compile.lo `test -f 'src/pcre2_jit_compile.c' || echo '$(srcdir)/'`src/pcre2_jit_compile.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_8_la-pcre2_jit_compile.Tpo src/$(DEPDIR)/libpcre2_8_la-pcre2_jit_compile.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_jit_compile.c' object='src/libpcre2_8_la-pcre2_jit_compile.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_8_la-pcre2_jit_compile.lo `test -f 'src/pcre2_jit_compile.c' || echo '$(srcdir)/'`src/pcre2_jit_compile.c - src/libpcre2_8_la-pcre2_maketables.lo: src/pcre2_maketables.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_8_la-pcre2_maketables.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_8_la-pcre2_maketables.Tpo -c -o src/libpcre2_8_la-pcre2_maketables.lo `test -f 'src/pcre2_maketables.c' || echo '$(srcdir)/'`src/pcre2_maketables.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_8_la-pcre2_maketables.Tpo src/$(DEPDIR)/libpcre2_8_la-pcre2_maketables.Plo @@ -2044,6 +2102,13 @@ src/libpcre2_8_la-pcre2_match_data.lo: src/pcre2_match_data.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_8_la-pcre2_match_data.lo `test -f 'src/pcre2_match_data.c' || echo '$(srcdir)/'`src/pcre2_match_data.c +src/libpcre2_8_la-pcre2_match_next.lo: src/pcre2_match_next.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_8_la-pcre2_match_next.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_8_la-pcre2_match_next.Tpo -c -o src/libpcre2_8_la-pcre2_match_next.lo `test -f 'src/pcre2_match_next.c' || echo '$(srcdir)/'`src/pcre2_match_next.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_8_la-pcre2_match_next.Tpo src/$(DEPDIR)/libpcre2_8_la-pcre2_match_next.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/pcre2_match_next.c' object='src/libpcre2_8_la-pcre2_match_next.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -c -o src/libpcre2_8_la-pcre2_match_next.lo `test -f 'src/pcre2_match_next.c' || echo '$(srcdir)/'`src/pcre2_match_next.c + src/libpcre2_8_la-pcre2_newline.lo: src/pcre2_newline.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpcre2_8_la_CFLAGS) $(CFLAGS) -MT src/libpcre2_8_la-pcre2_newline.lo -MD -MP -MF src/$(DEPDIR)/libpcre2_8_la-pcre2_newline.Tpo -c -o src/libpcre2_8_la-pcre2_newline.lo `test -f 'src/pcre2_newline.c' || echo '$(srcdir)/'`src/pcre2_newline.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libpcre2_8_la-pcre2_newline.Tpo src/$(DEPDIR)/libpcre2_8_la-pcre2_newline.Plo @@ -2660,7 +2725,6 @@ maintainer-clean-generic: @echo "it deletes files that may require special tools to rebuild." -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) -@WITH_GCOV_FALSE@clean-local: clean: clean-am clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \ @@ -2672,6 +2736,7 @@ distclean: distclean-am -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_chartables.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_chkdint.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_compile.Plo + -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_cgroup.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_class.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_config.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_context.Plo @@ -2680,10 +2745,10 @@ distclean: distclean-am -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_error.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_extuni.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_find_bracket.Plo - -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_jit_compile.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_maketables.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_match.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_match_data.Plo + -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_match_next.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_newline.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_ord2utf.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_pattern_info.Plo @@ -2701,6 +2766,7 @@ distclean: distclean-am -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_chartables.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_chkdint.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_compile.Plo + -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_cgroup.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_class.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_config.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_context.Plo @@ -2709,10 +2775,10 @@ distclean: distclean-am -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_error.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_extuni.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_find_bracket.Plo - -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_jit_compile.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_maketables.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_match.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_match_data.Plo + -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_match_next.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_newline.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_ord2utf.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_pattern_info.Plo @@ -2730,6 +2796,7 @@ distclean: distclean-am -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_chartables.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_chkdint.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_compile.Plo + -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_cgroup.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_class.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_config.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_context.Plo @@ -2738,10 +2805,10 @@ distclean: distclean-am -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_error.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_extuni.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_find_bracket.Plo - -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_jit_compile.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_maketables.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_match.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_match_data.Plo + -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_match_next.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_newline.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_ord2utf.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_pattern_info.Plo @@ -2810,6 +2877,7 @@ maintainer-clean: maintainer-clean-am -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_chartables.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_chkdint.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_compile.Plo + -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_cgroup.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_compile_class.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_config.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_context.Plo @@ -2818,10 +2886,10 @@ maintainer-clean: maintainer-clean-am -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_error.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_extuni.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_find_bracket.Plo - -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_jit_compile.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_maketables.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_match.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_match_data.Plo + -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_match_next.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_newline.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_ord2utf.Plo -rm -f src/$(DEPDIR)/libpcre2_16_la-pcre2_pattern_info.Plo @@ -2839,6 +2907,7 @@ maintainer-clean: maintainer-clean-am -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_chartables.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_chkdint.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_compile.Plo + -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_cgroup.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_compile_class.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_config.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_context.Plo @@ -2847,10 +2916,10 @@ maintainer-clean: maintainer-clean-am -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_error.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_extuni.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_find_bracket.Plo - -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_jit_compile.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_maketables.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_match.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_match_data.Plo + -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_match_next.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_newline.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_ord2utf.Plo -rm -f src/$(DEPDIR)/libpcre2_32_la-pcre2_pattern_info.Plo @@ -2868,6 +2937,7 @@ maintainer-clean: maintainer-clean-am -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_chartables.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_chkdint.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_compile.Plo + -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_cgroup.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_compile_class.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_config.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_context.Plo @@ -2876,10 +2946,10 @@ maintainer-clean: maintainer-clean-am -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_error.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_extuni.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_find_bracket.Plo - -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_jit_compile.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_maketables.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_match.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_match_data.Plo + -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_match_next.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_newline.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_ord2utf.Plo -rm -f src/$(DEPDIR)/libpcre2_8_la-pcre2_pattern_info.Plo @@ -2961,8 +3031,9 @@ src/pcre2.h.generic: src/pcre2.h.in configure.ac # running configure in a new directory, it complains. For this reason, we move # config.status out of the way while doing the default configuration. The # resulting config.h is munged by perl to put #ifdefs round any #defines for -# macros with values, and to #undef all boolean macros such as HAVE_xxx and -# SUPPORT_xxx. We also get rid of any gcc-specific visibility settings. +# macros with values, and to #undef all boolean macros such as HAVE_xxx, +# SUPPORT_xxx, and PCRE2_STATIC/PCRE2POSIX_SHARED. We also get rid of any +# GCC-specific visibility settings. src/config.h.generic: configure.ac rm -rf $@ _generic @@ -2972,20 +3043,31 @@ src/config.h.generic: configure.ac cs=$(srcdir)/config.status; test ! -f $$cs.aside || mv -f $$cs.aside $$cs test -f _generic/src/config.h perl -n \ - -e 'BEGIN{$$blank=0;}' \ - -e 'if(/(.+?)\s*__attribute__ \(\(visibility/){print"$$1\n";$$blank=0;next;}' \ - -e 'if(/LT_OBJDIR/){print"/* This is ignored unless you are using libtool. */\n";}' \ - -e 'if(/^#define\s((?:HAVE|SUPPORT|STDC)_\w+)/){print"/* #undef $$1 */\n";$$blank=0;next;}' \ - -e 'if(/^#define\s(?!PACKAGE|VERSION)(\w+)/){print"#ifndef $$1\n$$_#endif\n";$$blank=0;next;}' \ - -e 'if(/^\s*$$/){print unless $$blank; $$blank=1;} else{print;$$blank=0;}' \ - _generic/src/config.h >$@ + -e 'BEGIN{$$blank=0;}' \ + -e 'if(/(.+?)\s*__attribute__ \(\(visibility/){print"$$1\n";$$blank=0;next;}' \ + -e 'if(/LT_OBJDIR/){print"/* This is ignored unless you are using libtool. */\n";}' \ + -e 'if(/^#define\s((?:HAVE|SUPPORT|STDC)_\w+|PCRE2_STATIC|PCRE2POSIX_SHARED)/){print"/* #undef $$1 */\n";$$blank=0;next;}' \ + -e 'if(/^#define\s(?!PACKAGE|VERSION)(\w+)/){print"#ifndef $$1\n$$_#endif\n";$$blank=0;next;}' \ + -e 'if(/^\s*$$/){print unless $$blank; $$blank=1;} else{print;$$blank=0;}' \ + _generic/src/config.h >$@ rm -rf _generic @WITH_REBUILD_CHARTABLES_TRUE@src/pcre2_chartables.c: pcre2_dftables$(EXEEXT) @WITH_REBUILD_CHARTABLES_TRUE@ rm -f $@ @WITH_REBUILD_CHARTABLES_TRUE@ ./pcre2_dftables$(EXEEXT) $@ -@WITH_REBUILD_CHARTABLES_FALSE@src/pcre2_chartables.c: $(srcdir)/src/pcre2_chartables.c.dist -@WITH_REBUILD_CHARTABLES_FALSE@ rm -f $@ -@WITH_REBUILD_CHARTABLES_FALSE@ $(LN_S) $(abs_srcdir)/src/pcre2_chartables.c.dist $(abs_builddir)/src/pcre2_chartables.c +@WITH_EBCDIC_NL25_TRUE@@WITH_EBCDIC_TRUE@@WITH_REBUILD_CHARTABLES_FALSE@src/pcre2_chartables.c: $(srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl25 +@WITH_EBCDIC_NL25_TRUE@@WITH_EBCDIC_TRUE@@WITH_REBUILD_CHARTABLES_FALSE@ rm -f $@ +@WITH_EBCDIC_NL25_TRUE@@WITH_EBCDIC_TRUE@@WITH_REBUILD_CHARTABLES_FALSE@ $(LN_S) $(abs_srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl25 $(abs_builddir)/src/pcre2_chartables.c +@WITH_EBCDIC_NL25_FALSE@@WITH_EBCDIC_TRUE@@WITH_REBUILD_CHARTABLES_FALSE@src/pcre2_chartables.c: $(srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl15 +@WITH_EBCDIC_NL25_FALSE@@WITH_EBCDIC_TRUE@@WITH_REBUILD_CHARTABLES_FALSE@ rm -f $@ +@WITH_EBCDIC_NL25_FALSE@@WITH_EBCDIC_TRUE@@WITH_REBUILD_CHARTABLES_FALSE@ $(LN_S) $(abs_srcdir)/src/pcre2_chartables.c.ebcdic-1047-nl15 $(abs_builddir)/src/pcre2_chartables.c +@WITH_EBCDIC_FALSE@@WITH_REBUILD_CHARTABLES_FALSE@src/pcre2_chartables.c: $(srcdir)/src/pcre2_chartables.c.dist +@WITH_EBCDIC_FALSE@@WITH_REBUILD_CHARTABLES_FALSE@ rm -f $@ +@WITH_EBCDIC_FALSE@@WITH_REBUILD_CHARTABLES_FALSE@ $(LN_S) $(abs_srcdir)/src/pcre2_chartables.c.dist $(abs_builddir)/src/pcre2_chartables.c + +testoutput-clean: + -rm -rf testoutput8 testoutput8-jit testoutput8-dfa + -rm -rf testoutput16 testoutput16-jit testoutput16-dfa + -rm -rf testoutput32 testoutput32-jit testoutput32-dfa @WITH_GCOV_TRUE@coverage-check: all @WITH_GCOV_TRUE@ -$(MAKE) $(AM_MAKEFLAGS) -k check @@ -3039,20 +3121,17 @@ src/config.h.generic: configure.ac @WITH_GCOV_TRUE@coverage-distclean: coverage-clean @WITH_GCOV_TRUE@coverage: coverage-reset coverage-baseline coverage-check coverage-report -@WITH_GCOV_TRUE@clean-local: coverage-clean -@WITH_GCOV_TRUE@distclean-local: coverage-distclean - -@WITH_GCOV_TRUE@.PHONY: coverage coverage-baseline coverage-check coverage-report coverage-reset coverage-clean-report coverage-clean-data coverage-clean coverage-distclean - -# Without coverage support, still arrange for 'make distclean' to get rid of -# any coverage files that may have been left from a different configuration. @WITH_GCOV_FALSE@coverage: @WITH_GCOV_FALSE@ @echo "Configuring with --enable-coverage is required to generate code coverage report." -@WITH_GCOV_FALSE@distclean-local: +@WITH_GCOV_FALSE@coverage-distclean: @WITH_GCOV_FALSE@ rm -rf $(PACKAGE)-$(VERSION)-coverage* +clean-local: $(CLEAN_LOCAL_TARGETS) +distclean-local: $(DISTCLEAN_LOCAL_TARGETS) +.PHONY: $(PHONY_TARGETS) + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/libpcre/NMAP_MODIFICATIONS b/libpcre/NMAP_MODIFICATIONS index bb695e116..f8140cfd8 100644 --- a/libpcre/NMAP_MODIFICATIONS +++ b/libpcre/NMAP_MODIFICATIONS @@ -18,6 +18,7 @@ src/pcre2grep.c src/pcre2demo.c src/pcre2_fuzzsupport.c src/pcre2_printint.c +src/pcre2_jit_compile.c src/pcre2_jit_char_inc.h src/pcre2_jit_match.c src/pcre2_jit_misc.c @@ -42,6 +43,6 @@ README INSTALL NON-AUTOTOOLS-BUILDS -o Made relevant changes to Makefile.am, configure.ac, CMakeLists.txt, and - src/pcre2_jit_compile.c to accommodate our smaller, non-JIT build - and to disable Unicode support by default. +o Made relevant changes to Makefile.am, configure.ac, and CMakeLists.txt to + accommodate our smaller, non-JIT build and to disable Unicode support by + default. diff --git a/libpcre/SECURITY.md b/libpcre/SECURITY.md index 1e3a05b9a..a9cd7c166 100644 --- a/libpcre/SECURITY.md +++ b/libpcre/SECURITY.md @@ -1,6 +1,8 @@ -# Security policies +Security policies +================= -## Release security +Release security +---------------- The PCRE2 project provides source-only releases, with no binaries. @@ -20,7 +22,14 @@ Git checkout of the (GPG-signed) release tag. Please contact the maintainers for any queries about release integrity or the project's supply-chain. -## Reporting vulnerabilities +Previous vulnerabilities +------------------------ + +* CVE-2025-58050 (August 2025). Affects 10.45 only (not earlier), and is fixed + in 10.46. + +Reporting vulnerabilities +------------------------- The PCRE2 project prioritises security. We appreciate third-party testing and security research, and would be grateful if you could responsibly disclose your @@ -38,7 +47,13 @@ aim to respond within 1 week, or perhaps 2 during holidays. ### Response procedure -PCRE2 has never previously made a rapid or embargoed release in response to a -security incident. We would work with security managers from trusted downstream -distributors, such as major Linux distributions, before disclosing the -vulnerability publicly. +PCRE2 has in the past made at least one rapid release in response to +security incidents. + +We have never produced an embargoed release, or provided preferential +access to security fixes to any clients. + +We would aim to notify security managers from trusted downstream distributors, +such as major Linux distributions, via the `pcre2-dev` mailing list, by +publicly signalling an upcoming security release before disclosing the +vulnerability publicly, where advance notification is possible. diff --git a/libpcre/WORKSPACE.bazel b/libpcre/WORKSPACE.bazel deleted file mode 100644 index 4ce2c8ced..000000000 --- a/libpcre/WORKSPACE.bazel +++ /dev/null @@ -1 +0,0 @@ -# See MODULE.bazel diff --git a/libpcre/aclocal.m4 b/libpcre/aclocal.m4 index d7c332c20..ea61c79a4 100644 --- a/libpcre/aclocal.m4 +++ b/libpcre/aclocal.m4 @@ -1588,6 +1588,7 @@ AC_SUBST([am__tar]) AC_SUBST([am__untar]) ]) # _AM_PROG_TAR +m4_include([m4/ax_check_vscript.m4]) m4_include([m4/ax_pthread.m4]) m4_include([m4/libtool.m4]) m4_include([m4/ltoptions.m4]) @@ -1595,3 +1596,4 @@ m4_include([m4/ltsugar.m4]) m4_include([m4/ltversion.m4]) m4_include([m4/lt~obsolete.m4]) m4_include([m4/pcre2_visibility.m4]) +m4_include([m4/pcre2_zos.m4]) diff --git a/libpcre/build.zig b/libpcre/build.zig index 4cb6d99d6..960137ab3 100644 --- a/libpcre/build.zig +++ b/libpcre/build.zig @@ -11,13 +11,14 @@ pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const linkage = b.option(std.builtin.LinkMode, "linkage", "whether to statically or dynamically link the library") orelse @as(std.builtin.LinkMode, if (target.result.isGnuLibC()) .dynamic else .static); const codeUnitWidth = b.option(CodeUnitWidth, "code-unit-width", "Sets the code unit width") orelse .@"8"; + const jit = b.option(bool, "support_jit", "Enable/disable JIT compiler support") orelse false; const pcre2_header_dir = b.addWriteFiles(); const pcre2_header = pcre2_header_dir.addCopyFile(b.path("src/pcre2.h.generic"), "pcre2.h"); const config_header = b.addConfigHeader( .{ - .style = .{ .cmake = b.path("config-cmake.h.in") }, + .style = .{ .cmake = b.path("src/config-cmake.h.in") }, .include_path = "config.h", }, .{ @@ -25,13 +26,15 @@ pub fn build(b: *std.Build) !void { .HAVE_UNISTD_H = (target.result.os.tag != .windows), .HAVE_WINDOWS_H = (target.result.os.tag == .windows), - .HAVE_MEMMOVE = true, - .HAVE_STRERROR = true, + .HAVE_ATTRIBUTE_UNINITIALIZED = true, + .HAVE_BUILTIN_MUL_OVERFLOW = true, + .HAVE_BUILTIN_UNREACHABLE = true, .SUPPORT_PCRE2_8 = codeUnitWidth == CodeUnitWidth.@"8", .SUPPORT_PCRE2_16 = codeUnitWidth == CodeUnitWidth.@"16", .SUPPORT_PCRE2_32 = codeUnitWidth == CodeUnitWidth.@"32", .SUPPORT_UNICODE = true, + .SUPPORT_JIT = jit, .PCRE2_EXPORT = null, .PCRE2_LINK_SIZE = 2, @@ -41,28 +44,31 @@ pub fn build(b: *std.Build) !void { .PCRE2_MAX_VARLOOKBEHIND = 255, .NEWLINE_DEFAULT = 2, .PCRE2_PARENS_NEST_LIMIT = 250, + .PCRE2GREP_BUFSIZE = 20480, + .PCRE2GREP_MAX_BUFSIZE = 1048576, }, ); - // pcre2-8/16/32.so + // pcre2-8/16/32 library - const lib = std.Build.Step.Compile.create(b, .{ - .name = b.fmt("pcre2-{s}", .{@tagName(codeUnitWidth)}), - .root_module = .{ - .target = target, - .optimize = optimize, - .link_libc = true, - }, - .kind = .lib, - .linkage = linkage, + const lib_mod = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, }); - lib.defineCMacro("HAVE_CONFIG_H", null); - lib.defineCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth)); + lib_mod.addCMacro("HAVE_CONFIG_H", ""); + lib_mod.addCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth)); if (linkage == .static) { - lib.defineCMacro("PCRE2_STATIC", null); + lib_mod.addCMacro("PCRE2_STATIC", ""); } + const lib = b.addLibrary(.{ + .name = b.fmt("pcre2-{s}", .{@tagName(codeUnitWidth)}), + .root_module = lib_mod, + .linkage = linkage, + }); + lib.addConfigHeader(config_header); lib.addIncludePath(pcre2_header_dir.getDirectory()); lib.addIncludePath(b.path("src")); @@ -76,6 +82,7 @@ pub fn build(b: *std.Build) !void { "src/pcre2_auto_possess.c", "src/pcre2_chkdint.c", "src/pcre2_compile.c", + "src/pcre2_compile_cgroup.c", "src/pcre2_compile_class.c", "src/pcre2_config.c", "src/pcre2_context.c", @@ -88,6 +95,7 @@ pub fn build(b: *std.Build) !void { "src/pcre2_maketables.c", "src/pcre2_match.c", "src/pcre2_match_data.c", + "src/pcre2_match_next.c", "src/pcre2_newline.c", "src/pcre2_ord2utf.c", "src/pcre2_pattern_info.c", @@ -107,36 +115,49 @@ pub fn build(b: *std.Build) !void { lib.installHeader(pcre2_header, "pcre2.h"); b.installArtifact(lib); - // pcre2test + const pcre2test_mod = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, + }); + + pcre2test_mod.addCMacro("HAVE_CONFIG_H", ""); + if (linkage == .static) { + pcre2test_mod.addCMacro("PCRE2_STATIC", ""); + } else { + pcre2test_mod.addCMacro("PCRE2POSIX_SHARED", ""); + } + const pcre2test = b.addExecutable(.{ .name = "pcre2test", - .target = target, - .optimize = optimize, + .root_module = pcre2test_mod, }); - - // pcre2-posix.so + // pcre2-posix library if (codeUnitWidth == CodeUnitWidth.@"8") { - const posixLib = std.Build.Step.Compile.create(b, .{ - .name = "pcre2-posix", - .root_module = .{ - .target = target, - .optimize = optimize, - .link_libc = true, - }, - .kind = .lib, - .linkage = linkage, + const posixLib_mod = b.createModule(.{ + .target = target, + .optimize = optimize, + .link_libc = true, }); - posixLib.defineCMacro("HAVE_CONFIG_H", null); - posixLib.defineCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth)); + posixLib_mod.addCMacro("HAVE_CONFIG_H", ""); + posixLib_mod.addCMacro("PCRE2_CODE_UNIT_WIDTH", @tagName(codeUnitWidth)); if (linkage == .static) { - posixLib.defineCMacro("PCRE2_STATIC", null); + posixLib_mod.addCMacro("PCRE2_STATIC", ""); + } else { + posixLib_mod.addCMacro("PCRE2POSIX_SHARED", ""); } + const posixLib = b.addLibrary(.{ + .name = "pcre2-posix", + .root_module = posixLib_mod, + .linkage = linkage, + }); + posixLib.addConfigHeader(config_header); posixLib.addIncludePath(pcre2_header_dir.getDirectory()); posixLib.addIncludePath(b.path("src")); @@ -147,17 +168,16 @@ pub fn build(b: *std.Build) !void { }, }); + posixLib.linkLibrary(lib); + posixLib.installHeader(b.path("src/pcre2posix.h"), "pcre2posix.h"); b.installArtifact(posixLib); pcre2test.linkLibrary(posixLib); } - // pcre2test (again) - pcre2test.defineCMacro("HAVE_CONFIG_H", null); - pcre2test.addConfigHeader(config_header); pcre2test.addIncludePath(pcre2_header_dir.getDirectory()); pcre2test.addIncludePath(b.path("src")); @@ -166,7 +186,6 @@ pub fn build(b: *std.Build) !void { .file = b.path("src/pcre2test.c"), }); - pcre2test.linkLibC(); pcre2test.linkLibrary(lib); b.installArtifact(pcre2test); diff --git a/libpcre/cmake/PCRE2CheckVscript.cmake b/libpcre/cmake/PCRE2CheckVscript.cmake new file mode 100644 index 000000000..ed3ae12f8 --- /dev/null +++ b/libpcre/cmake/PCRE2CheckVscript.cmake @@ -0,0 +1,112 @@ +# Similarly to Autoconf's ax_check_vscript.m4, check whether the linker supports +# version scripts (GNU ld) or map files (Sun linker). +# Sets the "have_var" to TRUE or FALSE depending on the detected support; and if +# support is detected then sets "flag_var" to the appropriate flag to pass to +# the linker (namely, --version-script or -M). + +function(pcre2_check_vscript have_var flag_var) + set(${have_var} FALSE PARENT_SCOPE) + set(${flag_var} "" PARENT_SCOPE) + + if(MSVC) + return() + endif() + + set(first_run FALSE) + if(NOT DEFINED HAVE_VSCRIPT_GNU) + set(first_run TRUE) + message(STATUS "Detecting linker version script support") + endif() + + include(CheckCSourceCompiles) + include(CMakePushCheckState) + + # The BSD file here is a workaround for the fact that check_c_source_compiles + # very unfortunately only supports linking executables + # with an entrypoint (or a static library), and yet the symbol visibility + # requirements for executables are understandably different on some platforms + # as compared to linking a shared library. On FreeBSD, linking fails if you + # use the linker script to hide various global symbols from /usr/lib/crt1.o. + # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269370 + # Basically, everyone using --version-script is actually going to be creating + # a shared library. It's a frustrating mismatch. + file(WRITE ${PROJECT_BINARY_DIR}/test-map-file.sym "PCRE2_10.00 { global: exposethis; local: *; };") + file(WRITE ${PROJECT_BINARY_DIR}/test-map-file-bsd.sym "PCRE2_10.00 { global: exposethis; environ; __progname; local: *; };") + file(WRITE ${PROJECT_BINARY_DIR}/test-map-file-broken.sym "PCRE2_10.00 { global: exposethis; local: *; }; {") + + set(HAVE_VSCRIPT FALSE) + + # Using an executable to check for version-script support is rather delicate, + # because linking in an entrypoint (main) adds extra symbols into the mix. + # If CMake ever added a SHARED_LIBRARY option to check_c_source_compiles, we'd + # use it here. + set( + test_source + [=[ + int exposethis = 0, hidethis = 0; + int main(void) { + return exposethis + hidethis; + } + ]=] + ) + + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_QUIET TRUE) + + set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--version-script,${PROJECT_BINARY_DIR}/test-map-file.sym") + check_c_source_compiles("${test_source}" HAVE_VSCRIPT_GNU) + + if(HAVE_VSCRIPT_GNU) + set(VSCRIPT_FLAG --version-script) + set(HAVE_VSCRIPT TRUE) + else() + set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--version-script,${PROJECT_BINARY_DIR}/test-map-file-bsd.sym") + check_c_source_compiles("${test_source}" HAVE_VSCRIPT_BSD) + + if(HAVE_VSCRIPT_BSD) + set(VSCRIPT_FLAG --version-script) + set(HAVE_VSCRIPT TRUE) + else() + set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,-M,${PROJECT_BINARY_DIR}/test-map-file.sym") + check_c_source_compiles("${test_source}" HAVE_VSCRIPT_SUN) + + if(HAVE_VSCRIPT_SUN) + set(VSCRIPT_FLAG -M) + set(HAVE_VSCRIPT TRUE) + endif() + endif() + endif() + + if(HAVE_VSCRIPT) + # Perform the same logic as ax_check_vscript.m4, to test whether the linker + # silently ignores (and overwrites) linker scripts it doesn't understand. + set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,${VSCRIPT_FLAG},${PROJECT_BINARY_DIR}/test-map-file-broken.sym") + check_c_source_compiles("${test_source}" HAVE_VSCRIPT_BROKEN) + + if(HAVE_VSCRIPT_BROKEN) + set(HAVE_VSCRIPT FALSE) + if(first_run) + message(STATUS "Detecting linker version script support - no (linker overwrites unknown scripts)") + endif() + else() + if(first_run) + message(STATUS "Detecting linker version script support - yes (${VSCRIPT_FLAG})") + endif() + endif() + else() + if(first_run) + message(STATUS "Detecting linker version script support - none detected") + endif() + endif() + + cmake_pop_check_state() + + file(REMOVE ${PROJECT_BINARY_DIR}/test-map-file.sym) + file(REMOVE ${PROJECT_BINARY_DIR}/test-map-file-bsd.sym) + file(REMOVE ${PROJECT_BINARY_DIR}/test-map-file-broken.sym) + + if(HAVE_VSCRIPT) + set(${have_var} TRUE PARENT_SCOPE) + set(${flag_var} "${VSCRIPT_FLAG}" PARENT_SCOPE) + endif() +endfunction() diff --git a/libpcre/cmake/PCRE2UseSystemExtensions.cmake b/libpcre/cmake/PCRE2UseSystemExtensions.cmake new file mode 100644 index 000000000..a70a5f7bf --- /dev/null +++ b/libpcre/cmake/PCRE2UseSystemExtensions.cmake @@ -0,0 +1,89 @@ +# This CMake module is supposed to give similar results to the +# AC_USE_SYSTEM_EXTENSIONS Autoconf macro, which turns on a load of +# system feature-check macros, including _ALL_SOURCE, _GNU_SOURCE, +# _NETBSD_SOURCE, and many more. +# +# Because PCRE2 uses so few OS features, we don't seem to actually need to +# enable many of these. Modern platforms with CMake users generally enable +# all the basic POSIX features by default. +# +# So far, we know that we require: +# - _ALL_SOURCE on IBM systems (z/OS, probably AIX) in order to call +# getrlimit() in pcre2test. +# - _GNU_SOURCE on Linux in order to call mkostemp() in some (non-default) +# configurations of the JIT. +# +# Autoconf enables this unconditionally. However, our CMake script potentially +# supports *more* platforms than Autoconf, so we use a feature check. + +function(pcre2_use_system_extensions) + if(WIN32) + return() + endif() + + set(first_run FALSE) + set(found_macro FALSE) + if(NOT DEFINED HAVE_GETRLIMIT_NAKED) + set(first_run TRUE) + message(STATUS "Detecting platform feature test macros") + endif() + + include(CheckSymbolExists) + include(CheckCSourceCompiles) + include(CMakePushCheckState) + + cmake_push_check_state(RESET) + set( + _pcre2_test_src + [=[ + #include + #include + + int main(void) { + struct rlimit rlim; + getrlimit(RLIMIT_STACK, &rlim); + return 0; + } + ]=] + ) + set(CMAKE_REQUIRED_QUIET TRUE) + check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT_NAKED) + + if(NOT HAVE_GETRLIMIT_NAKED) + # Try again with _ALL_SOURCE + set(CMAKE_REQUIRED_DEFINITIONS "-D_ALL_SOURCE") + check_c_source_compiles("${_pcre2_test_src}" HAVE_GETRLIMIT_ALLSOURCE) + unset(CMAKE_REQUIRED_DEFINITIONS) + + if(HAVE_GETRLIMIT_ALLSOURCE) + add_compile_definitions(_ALL_SOURCE) + set(found_macro TRUE) + if(first_run) + message(STATUS "Detecting platform feature test macros - _ALL_SOURCE") + endif() + endif() + endif() + + check_symbol_exists(mkostemp stdlib.h HAVE_MKOSTEMP_NAKED) + + if(NOT HAVE_MKOSTEMP_NAKED) + # Try again with _GNU_SOURCE + set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") + check_symbol_exists(mkostemp stdlib.h HAVE_MKOSTEMP_GNUSOURCE) + unset(CMAKE_REQUIRED_DEFINITIONS) + + if(HAVE_MKOSTEMP_GNUSOURCE) + add_compile_definitions(_GNU_SOURCE) + set(found_macro TRUE) + if(first_run) + message(STATUS "Detecting platform feature test macros - _GNU_SOURCE") + endif() + endif() + endif() + + if(first_run AND NOT found_macro) + message(STATUS "Detecting platform feature test macros - none") + endif() + + cmake_pop_check_state() +endfunction() diff --git a/libpcre/cmake/PCRE2WarningAsError.cmake b/libpcre/cmake/PCRE2WarningAsError.cmake new file mode 100644 index 000000000..78b76a593 --- /dev/null +++ b/libpcre/cmake/PCRE2WarningAsError.cmake @@ -0,0 +1,35 @@ +# This file can be removed once the minimum CMake version is increased to 3.24 +# or higher. Calls to pcre2_warning_as_error can be changed to the built in +# CMAKE_C_COMPILE_OPTIONS_WARNING_AS_ERROR. + +function(pcre2_warning_as_error out_var) + set(${out_var} "" PARENT_SCOPE) + + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) + # Since CMake 3.24, we should use the CMAKE_C_COMPILE_OPTIONS_WARNING_AS_ERROR + # variable for greatest compiler compatibility. + if(DEFINED CMAKE_C_COMPILE_OPTIONS_WARNING_AS_ERROR) + set(${out_var} "${CMAKE_C_COMPILE_OPTIONS_WARNING_AS_ERROR}" PARENT_SCOPE) + endif() + else() + # The fallback probes for support, trying a few common flags. + + if(NOT MSVC) + include(CheckCCompilerFlag) + include(CMakePushCheckState) + + cmake_push_check_state(RESET) + check_c_compiler_flag("-Werror" HAVE_WERROR) + if(HAVE_WERROR) + set(${out_var} "-Werror" PARENT_SCOPE) + else() + check_c_compiler_flag("-errwarn=%all" HAVE_ERRWARN_ALL) + if(HAVE_ERRWARN_ALL) + set(${out_var} "-errwarn=%all" PARENT_SCOPE) + endif() + endif() + + cmake_pop_check_state() + endif() + endif() +endfunction() diff --git a/libpcre/cmake/pcre2-config-version.cmake.in b/libpcre/cmake/pcre2-config-version.cmake.in deleted file mode 100644 index db0060633..000000000 --- a/libpcre/cmake/pcre2-config-version.cmake.in +++ /dev/null @@ -1,14 +0,0 @@ -set(PACKAGE_VERSION_MAJOR @PCRE2_MAJOR@) -set(PACKAGE_VERSION_MINOR @PCRE2_MINOR@) -set(PACKAGE_VERSION_PATCH 0) -set(PACKAGE_VERSION @PCRE2_MAJOR@.@PCRE2_MINOR@.0) - -# Check whether the requested PACKAGE_FIND_VERSION is compatible -if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION OR PACKAGE_VERSION_MAJOR GREATER PACKAGE_FIND_VERSION_MAJOR) - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if(PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION) - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() diff --git a/libpcre/cmake/pcre2-config.cmake.in b/libpcre/cmake/pcre2-config.cmake.in index 082dc1983..bda4841dd 100644 --- a/libpcre/cmake/pcre2-config.cmake.in +++ b/libpcre/cmake/pcre2-config.cmake.in @@ -5,11 +5,17 @@ # # Static vs. shared # ----------------- -# To make use of the static library instead of the shared one, one needs +# To force using the static library instead of the shared one, one needs # to set the variable PCRE2_USE_STATIC_LIBS to ON before calling find_package. +# If the variable is not set, the static library will be used if only that has +# been built, otherwise the shared library will be used. +# +# The following components are supported: 8BIT, 16BIT, 32BIT and POSIX. +# They used to be required but not anymore; all available targets will +# be defined regardless of the requested components. # Example: # set(PCRE2_USE_STATIC_LIBS ON) -# find_package(PCRE2 CONFIG COMPONENTS 8BIT) +# find_package(PCRE2 CONFIG) # # This will define the following variables: # @@ -23,88 +29,42 @@ # PCRE2::32BIT - The 32 bit PCRE2 library. # PCRE2::POSIX - The POSIX PCRE2 library. -set(PCRE2_NON_STANDARD_LIB_PREFIX @NON_STANDARD_LIB_PREFIX@) -set(PCRE2_NON_STANDARD_LIB_SUFFIX @NON_STANDARD_LIB_SUFFIX@) -set(PCRE2_8BIT_NAME pcre2-8) -set(PCRE2_16BIT_NAME pcre2-16) -set(PCRE2_32BIT_NAME pcre2-32) -set(PCRE2_POSIX_NAME pcre2-posix) -find_path(PCRE2_INCLUDE_DIR NAMES pcre2.h DOC "PCRE2 include directory") -if(PCRE2_USE_STATIC_LIBS) - if(MSVC) - set(PCRE2_8BIT_NAME pcre2-8-static) - set(PCRE2_16BIT_NAME pcre2-16-static) - set(PCRE2_32BIT_NAME pcre2-32-static) - set(PCRE2_POSIX_NAME pcre2-posix-static) - endif() +@PACKAGE_INIT@ - set(PCRE2_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX}) - set(PCRE2_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) -else() - set(PCRE2_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX}) - if(MINGW AND PCRE2_NON_STANDARD_LIB_PREFIX) - set(PCRE2_PREFIX "") - endif() - - set(PCRE2_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) - if(MINGW AND PCRE2_NON_STANDARD_LIB_SUFFIX) - set(PCRE2_SUFFIX "-0.dll") - elseif(MSVC) - set(PCRE2_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) - endif() +include(CMakeFindDependencyMacro) +if("@REQUIRE_PTHREAD@") # REQUIRE_PTHREAD + find_dependency(Threads) endif() -find_library( - PCRE2_8BIT_LIBRARY - NAMES ${PCRE2_PREFIX}${PCRE2_8BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_8BIT_NAME}d${PCRE2_SUFFIX} - DOC "8 bit PCRE2 library" -) -find_library( - PCRE2_16BIT_LIBRARY - NAMES ${PCRE2_PREFIX}${PCRE2_16BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_16BIT_NAME}d${PCRE2_SUFFIX} - DOC "16 bit PCRE2 library" -) -find_library( - PCRE2_32BIT_LIBRARY - NAMES ${PCRE2_PREFIX}${PCRE2_32BIT_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_32BIT_NAME}d${PCRE2_SUFFIX} - DOC "32 bit PCRE2 library" -) -find_library( - PCRE2_POSIX_LIBRARY - NAMES ${PCRE2_PREFIX}${PCRE2_POSIX_NAME}${PCRE2_SUFFIX} ${PCRE2_PREFIX}${PCRE2_POSIX_NAME}d${PCRE2_SUFFIX} - DOC "8 bit POSIX PCRE2 library" -) -unset(PCRE2_NON_STANDARD_LIB_PREFIX) -unset(PCRE2_NON_STANDARD_LIB_SUFFIX) -unset(PCRE2_8BIT_NAME) -unset(PCRE2_16BIT_NAME) -unset(PCRE2_32BIT_NAME) -unset(PCRE2_POSIX_NAME) + +include("${CMAKE_CURRENT_LIST_DIR}/pcre2-targets.cmake") # Set version -if(PCRE2_INCLUDE_DIR) - set(PCRE2_VERSION "@PCRE2_MAJOR@.@PCRE2_MINOR@.0") -endif() +set(PCRE2_VERSION "@PCRE2_MAJOR@.@PCRE2_MINOR@.0") -# Which components have been found. -if(PCRE2_8BIT_LIBRARY) - set(PCRE2_8BIT_FOUND TRUE) -endif() -if(PCRE2_16BIT_LIBRARY) - set(PCRE2_16BIT_FOUND TRUE) -endif() -if(PCRE2_32BIT_LIBRARY) - set(PCRE2_32BIT_FOUND TRUE) -endif() -if(PCRE2_POSIX_LIBRARY) - set(PCRE2_POSIX_FOUND TRUE) -endif() - -# Check if at least one component has been specified. -list(LENGTH PCRE2_FIND_COMPONENTS PCRE2_NCOMPONENTS) -if(PCRE2_NCOMPONENTS LESS 1) - message(FATAL_ERROR "No components have been specified. This is not allowed. Please, specify at least one component.") -endif() -unset(PCRE2_NCOMPONENTS) +# Chooses the linkage of the library to expose in the +# unsuffixed edition of the target. +macro(_pcre2_add_component_target component target) + # If the static library exists and either PCRE2_USE_STATIC_LIBS + # is defined, or the dynamic library does not exist, use the static library. + if(NOT TARGET PCRE2::${component}) + if(TARGET pcre2::pcre2-${target}-static AND (PCRE2_USE_STATIC_LIBS OR NOT TARGET pcre2::pcre2-${target}-shared)) + add_library(PCRE2::${component} ALIAS pcre2::pcre2-${target}-static) + set(PCRE2_${component}_FOUND TRUE) + # Otherwise use the dynamic library if it exists. + elseif(TARGET pcre2::pcre2-${target}-shared AND NOT PCRE2_USE_STATIC_LIBS) + add_library(PCRE2::${component} ALIAS pcre2::pcre2-${target}-shared) + set(PCRE2_${component}_FOUND TRUE) + endif() + if(PCRE2_${component}_FOUND) + get_target_property(PCRE2_${component}_LIBRARY PCRE2::${component} IMPORTED_LOCATION) + set(PCRE2_LIBRARIES ${PCRE2_LIBRARIES} ${PCRE2_${component}_LIBRARY}) + endif() + endif() +endmacro() +_pcre2_add_component_target(8BIT 8) +_pcre2_add_component_target(16BIT 16) +_pcre2_add_component_target(32BIT 32) +_pcre2_add_component_target(POSIX posix) # When POSIX component has been specified make sure that also 8BIT component is specified. set(PCRE2_8BIT_COMPONENT FALSE) @@ -126,43 +86,5 @@ endif() unset(PCRE2_8BIT_COMPONENT) unset(PCRE2_POSIX_COMPONENT) -include(FindPackageHandleStandardArgs) -set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}") -find_package_handle_standard_args( - PCRE2 - FOUND_VAR PCRE2_FOUND - REQUIRED_VARS PCRE2_INCLUDE_DIR - HANDLE_COMPONENTS - VERSION_VAR PCRE2_VERSION - CONFIG_MODE -) - -set(PCRE2_LIBRARIES) -if(PCRE2_FOUND) - foreach(component ${PCRE2_FIND_COMPONENTS}) - if(PCRE2_USE_STATIC_LIBS) - add_library(PCRE2::${component} STATIC IMPORTED) - target_compile_definitions(PCRE2::${component} INTERFACE PCRE2_STATIC) - else() - add_library(PCRE2::${component} SHARED IMPORTED) - endif() - set_target_properties( - PCRE2::${component} - PROPERTIES - IMPORTED_LOCATION "${PCRE2_${component}_LIBRARY}" - IMPORTED_IMPLIB "${PCRE2_${component}_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${PCRE2_INCLUDE_DIR}" - ) - if(component STREQUAL "POSIX") - set_target_properties( - PCRE2::${component} - PROPERTIES INTERFACE_LINK_LIBRARIES "PCRE2::8BIT" LINK_LIBRARIES "PCRE2::8BIT" - ) - endif() - - set(PCRE2_LIBRARIES ${PCRE2_LIBRARIES} ${PCRE2_${component}_LIBRARY}) - mark_as_advanced(PCRE2_${component}_LIBRARY) - endforeach() -endif() - -mark_as_advanced(PCRE2_INCLUDE_DIR) +# Check for required components. +check_required_components("PCRE2") diff --git a/libpcre/configure b/libpcre/configure index 4bd105317..8dad8be64 100755 --- a/libpcre/configure +++ b/libpcre/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.71 for PCRE2 10.45. +# Generated by GNU Autoconf 2.71 for PCRE2 10.47. # # # Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, @@ -618,8 +618,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='PCRE2' PACKAGE_TARNAME='pcre2' -PACKAGE_VERSION='10.45' -PACKAGE_STRING='PCRE2 10.45' +PACKAGE_VERSION='10.47' +PACKAGE_STRING='PCRE2 10.47' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -684,8 +684,10 @@ EXTRA_LIBPCRE2_16_LDFLAGS EXTRA_LIBPCRE2_8_LDFLAGS PTHREAD_CFLAGS PTHREAD_LIBS +PTHREAD_CXX PTHREAD_CC ax_pthread_config +CPP PCRE2POSIX_CFLAG PCRE2_STATIC_CFLAG LIBREADLINE @@ -695,6 +697,10 @@ WITH_FUZZ_SUPPORT_FALSE WITH_FUZZ_SUPPORT_TRUE WITH_VALGRIND_FALSE WITH_VALGRIND_TRUE +WITH_EBCDIC_NL25_FALSE +WITH_EBCDIC_NL25_TRUE +WITH_EBCDIC_FALSE +WITH_EBCDIC_TRUE WITH_UNICODE_FALSE WITH_UNICODE_TRUE WITH_JIT_FALSE @@ -714,6 +720,11 @@ PCRE2_DATE PCRE2_PRERELEASE PCRE2_MINOR PCRE2_MAJOR +HAVE_VSCRIPT_COMPLEX_FALSE +HAVE_VSCRIPT_COMPLEX_TRUE +HAVE_VSCRIPT_FALSE +HAVE_VSCRIPT_TRUE +VSCRIPT_LDFLAGS HAVE_VISIBILITY VISIBILITY_CFLAGS LT_SYS_LIBRARY_PATH @@ -852,6 +863,7 @@ with_gnu_ld with_sysroot enable_libtool_lock enable_largefile +enable_symvers enable_pcre8 enable_pcre16 enable_pcre32 @@ -876,6 +888,7 @@ enable_bsr_anycrlf enable_never_backslash_C enable_ebcdic enable_ebcdic_nl25 +enable_ebcdic_ignoring_compiler enable_pcre2grep_libz enable_pcre2grep_libbz2 with_pcre2grep_bufsize @@ -895,6 +908,8 @@ enable_fuzz_support enable_diff_fuzz_support enable_stack_for_recursion enable_percent_zt +enable_Werror +enable_errwarn ' ac_precious_vars='build_alias host_alias @@ -905,6 +920,7 @@ LDFLAGS LIBS CPPFLAGS LT_SYS_LIBRARY_PATH +CPP PKG_CONFIG PKG_CONFIG_PATH PKG_CONFIG_LIBDIR @@ -1460,7 +1476,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures PCRE2 10.45 to adapt to many kinds of systems. +\`configure' configures PCRE2 10.47 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1531,7 +1547,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of PCRE2 10.45:";; + short | recursive ) echo "Configuration of PCRE2 10.47:";; esac cat <<\_ACEOF @@ -1554,6 +1570,7 @@ Optional Features: optimize for fast installation [default=yes] --disable-libtool-lock avoid locking (might break parallel builds) --disable-largefile omit support for large files + --disable-symvers disable library symbol versioning [default=auto] --disable-pcre2-8 disable 8 bit character support --enable-pcre2-16 enable 16 bit character support @@ -1583,9 +1600,12 @@ Optional Features: use of \C causes an error --enable-ebcdic assume EBCDIC coding rather than ASCII; incompatible with --enable-unicode; use only in (uncommon) EBCDIC - environments; it implies --enable-rebuild-chartables + environments --enable-ebcdic-nl25 set EBCDIC code for NL to 0x25 instead of 0x15; it implies --enable-ebcdic + --enable-ebcdic-ignoring-compiler + force EBCDIC 1047 using numeric literals rather than + C character literals; it implies --enable-ebcdic --enable-pcre2grep-libz link pcre2grep with libz to handle .gz files --enable-pcre2grep-libbz2 link pcre2grep with libbz2 to handle .bz2 files @@ -1599,6 +1619,10 @@ Optional Features: --enable-diff-fuzz-support enable differential fuzzer support --disable-percent-zt disable the use of z and t formatting modifiers + --enable-Werror Add -Werror to CFLAGS (GCC/Clang style); if -Werror + is passed to ./configure via CFLAGS it interferes + with feature detection + --enable-errwarn Add -errwarn=%all to CFLAGS (Sun cc style) Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -1640,6 +1664,7 @@ Some influential environment variables: you have headers in a nonstandard directory LT_SYS_LIBRARY_PATH User-defined run-time library search path. + CPP C preprocessor PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path @@ -1719,7 +1744,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -PCRE2 configure 10.45 +PCRE2 configure 10.47 generated by GNU Autoconf 2.71 Copyright (C) 2021 Free Software Foundation, Inc. @@ -2050,6 +2075,44 @@ printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type + +# ac_fn_c_try_cpp LINENO +# ---------------------- +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + } +then : + ac_retval=0 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_cpp ac_configure_args_raw= for ac_arg do @@ -2074,7 +2137,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by PCRE2 $as_me 10.45, which was +It was created by PCRE2 $as_me 10.47, which was generated by GNU Autoconf 2.71. Invocation command line was $ $0$ac_configure_args_raw @@ -3346,7 +3409,7 @@ fi # Define the identity of the package. PACKAGE='pcre2' - VERSION='10.45' + VERSION='10.47' printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h @@ -5160,6 +5223,127 @@ printf "%s\n" "#define int64_t $ac_cv_c_int64_t" >>confdefs.h esac +# Check for xlc which has some special (broken/non-standard) behaviour on z/OS. + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for OS/390 (z/OS)" >&5 +printf %s "checking for OS/390 (z/OS)... " >&6; } +if test ${pcre2_cv_os390+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test "`uname`" = "OS/390"; then + pcre2_cv_os390=yes + else + pcre2_cv_os390=no + fi +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $pcre2_cv_os390" >&5 +printf "%s\n" "$pcre2_cv_os390" >&6; } + if test "$pcre2_cv_os390" = "yes"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports -qhaltonmsg=CCN3296" >&5 +printf %s "checking whether the compiler supports -qhaltonmsg=CCN3296... " >&6; } +if test ${pcre2_cv_xlc_qhaltonmsg_support+y} +then : + printf %s "(cached) " >&6 +else $as_nop + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -qhaltonmsg=CCN3296" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + pcre2_cv_xlc_qhaltonmsg_support=yes +else $as_nop + pcre2_cv_xlc_qhaltonmsg_support=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CFLAGS="$save_CFLAGS" + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $pcre2_cv_xlc_qhaltonmsg_support" >&5 +printf "%s\n" "$pcre2_cv_xlc_qhaltonmsg_support" >&6; } + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether non-existent headers fail the compile" >&5 +printf %s "checking whether non-existent headers fail the compile... " >&6; } +if test ${pcre2_cv_xlc_nonexistent_fatal+y} +then : + printf %s "(cached) " >&6 +else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + pcre2_cv_xlc_nonexistent_fatal=no +else $as_nop + pcre2_cv_xlc_nonexistent_fatal=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $pcre2_cv_xlc_nonexistent_fatal" >&5 +printf "%s\n" "$pcre2_cv_xlc_nonexistent_fatal" >&6; } + + if test "$pcre2_cv_xlc_nonexistent_fatal" = "no" && test "$pcre2_cv_xlc_qhaltonmsg_support" = "yes"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -qhaltonmsg=CCN3296 fixes the non-existent-header issue" >&5 +printf %s "checking whether -qhaltonmsg=CCN3296 fixes the non-existent-header issue... " >&6; } +if test ${pcre2_cv_xlc_qhaltonmsg_fixes+y} +then : + printf %s "(cached) " >&6 +else $as_nop + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -qhaltonmsg=CCN3296" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + pcre2_cv_xlc_qhaltonmsg_fixes=no +else $as_nop + pcre2_cv_xlc_qhaltonmsg_fixes=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CFLAGS="$save_CFLAGS" + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $pcre2_cv_xlc_qhaltonmsg_fixes" >&5 +printf "%s\n" "$pcre2_cv_xlc_qhaltonmsg_fixes" >&6; } + + if test "$pcre2_cv_xlc_qhaltonmsg_fixes" = "no"; then + as_fn_error $? "-qhaltonmsg=CCN3296 not effective on non-existent headers" "$LINENO" 5 + fi + + CFLAGS="$CFLAGS -qhaltonmsg=CCN3296" + fi + + fi + + case `pwd` in *\ * | *\ *) @@ -13886,7 +14070,7 @@ _ACEOF if ac_fn_c_try_compile "$LINENO" then : - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int @@ -13975,6 +14159,341 @@ printf "%s\n" "#define HAVE_VISIBILITY $HAVE_VISIBILITY" >>confdefs.h +# Check for the availability of -Wl,--version-script (or -Wl,-M on Solaris) + + + + # Check whether --enable-symvers was given. +if test ${enable_symvers+y} +then : + enableval=$enable_symvers; want_symvers=$enableval +else $as_nop + want_symvers=yes + +fi + + + if test x$want_symvers = xyes +then : + + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking linker version script flag" >&5 +printf %s "checking linker version script flag... " >&6; } +if test ${ax_cv_check_vscript_flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop + + ax_cv_check_vscript_flag=unsupported + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: show; local: *; };" > conftest.map + if test x = xyes +then : + + echo "{" >> conftest.map + +fi + LDFLAGS="$LDFLAGS -Wl,--version-script,conftest.map" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int show, hide; +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + + ax_cv_check_vscript_flag=--version-script + +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$ax_check_vscript_save_flags" + rm -f conftest.map + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + if test x$ax_cv_check_vscript_flag = xunsupported +then : + + # PCRE2: Support for FreeBSD. Rather annoyingly, AC_LINK_IFELSE will + # only test linking executables, and in turn, on FreeBSD the main + # entrypoint will fail to link if you use "local: *" to hide the + # visibility of various shared symbols injected from /usr/lib/crt1.o. + # It's not at all pretty to hardcode those symbol names here, but I + # can't think of an obvious way to improve on this. + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: show;environ;__progname; local: *; };" > conftest.map + if test x = xyes +then : + + echo "{" >> conftest.map + +fi + LDFLAGS="$LDFLAGS -Wl,--version-script,conftest.map" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int show, hide; +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + + ax_cv_check_vscript_flag=--version-script + +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$ax_check_vscript_save_flags" + rm -f conftest.map + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +fi + if test x$ax_cv_check_vscript_flag = xunsupported +then : + + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: show; local: *; };" > conftest.map + if test x = xyes +then : + + echo "{" >> conftest.map + +fi + LDFLAGS="$LDFLAGS -Wl,-M,conftest.map" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int show, hide; +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ax_cv_check_vscript_flag=-M +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$ax_check_vscript_save_flags" + rm -f conftest.map + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +fi + + + if test x$ax_cv_check_vscript_flag != xunsupported +then : + + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: show; local: *; };" > conftest.map + if test xyes = xyes +then : + + echo "{" >> conftest.map + +fi + LDFLAGS="$LDFLAGS -Wl,$ax_cv_check_vscript_flag,conftest.map" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int show, hide; +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ax_cv_check_vscript_flag=unsupported +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$ax_check_vscript_save_flags" + rm -f conftest.map + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +fi + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_vscript_flag" >&5 +printf "%s\n" "$ax_cv_check_vscript_flag" >&6; } + + + if test x$ax_cv_check_vscript_flag != xunsupported +then : + + ax_check_vscript_flag=$ax_cv_check_vscript_flag + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if version scripts can use complex wildcards" >&5 +printf %s "checking if version scripts can use complex wildcards... " >&6; } +if test ${ax_cv_check_vscript_complex_wildcards+y} +then : + printf %s "(cached) " >&6 +else $as_nop + + ax_cv_check_vscript_complex_wildcards=no + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: sh*; local: *; };" > conftest.map + if test x = xyes +then : + + echo "{" >> conftest.map + +fi + LDFLAGS="$LDFLAGS -Wl,$ax_cv_check_vscript_flag,conftest.map" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int show, hide; +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + + ax_cv_check_vscript_complex_wildcards=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS="$ax_check_vscript_save_flags" + rm -f conftest.map + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_vscript_complex_wildcards" >&5 +printf "%s\n" "$ax_cv_check_vscript_complex_wildcards" >&6; } + ax_check_vscript_complex_wildcards="$ax_cv_check_vscript_complex_wildcards" + +else $as_nop + + ax_check_vscript_flag= + ax_check_vscript_complex_wildcards=no + +fi + +else $as_nop + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking linker version script flag" >&5 +printf %s "checking linker version script flag... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: disabled" >&5 +printf "%s\n" "disabled" >&6; } + + ax_check_vscript_flag= + ax_check_vscript_complex_wildcards=no + +fi + + if test x$ax_check_vscript_flag != x +then : + + VSCRIPT_LDFLAGS="-Wl,$ax_check_vscript_flag" + + +fi + + if test x$ax_check_vscript_flag != x; then + HAVE_VSCRIPT_TRUE= + HAVE_VSCRIPT_FALSE='#' +else + HAVE_VSCRIPT_TRUE='#' + HAVE_VSCRIPT_FALSE= +fi + + if test x$ax_check_vscript_complex_wildcards = xyes; then + HAVE_VSCRIPT_COMPLEX_TRUE= + HAVE_VSCRIPT_COMPLEX_FALSE='#' +else + HAVE_VSCRIPT_COMPLEX_TRUE='#' + HAVE_VSCRIPT_COMPLEX_FALSE= +fi + + + + # Check for Clang __attribute__((uninitialized)) feature { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __attribute__((uninitialized))" >&5 @@ -14162,9 +14681,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu # Versioning PCRE2_MAJOR="10" -PCRE2_MINOR="45" +PCRE2_MINOR="47" PCRE2_PRERELEASE="" -PCRE2_DATE="2025-02-05" +PCRE2_DATE="2025-10-21" if test "$PCRE2_MINOR" = "08" -o "$PCRE2_MINOR" = "09" then @@ -14364,7 +14883,7 @@ if test ${enable_unicode+y} then : enableval=$enable_unicode; else $as_nop - enable_unicode=no + enable_unicode=unset fi @@ -14448,6 +14967,16 @@ else $as_nop fi +# Handle --enable-ebcdic-ignoring-compiler +# Check whether --enable-ebcdic-ignoring-compiler was given. +if test ${enable_ebcdic_ignoring_compiler+y} +then : + enableval=$enable_ebcdic_ignoring_compiler; +else $as_nop + enable_ebcdic_ignoring_compiler=no +fi + + # Handle --enable-pcre2grep-libz # Check whether --enable-pcre2grep-libz was given. if test ${enable_pcre2grep_libz+y} @@ -14661,6 +15190,24 @@ else $as_nop fi +# Handle --enable-Werror/errwarn +# Check whether --enable-Werror was given. +if test ${enable_Werror+y} +then : + enableval=$enable_Werror; +else $as_nop + enable_Werror=no +fi + +# Check whether --enable-errwarn was given. +if test ${enable_errwarn+y} +then : + enableval=$enable_errwarn; +else $as_nop + enable_errwarn=no +fi + + # Set the default value for pcre2-8 if test "x$enable_pcre2_8" = "xunset" then @@ -14706,19 +15253,21 @@ case "$enable_newline" in ;; esac -# --enable-ebcdic-nl25 implies --enable-ebcdic -if test "x$enable_ebcdic_nl25" = "xyes"; then +# --enable-ebcdic-nl25 and --enable-ebcdic-ignoring-compiler imply --enable-ebcdic +if test "x$enable_ebcdic_nl25" = "xyes" -o "x$enable_ebcdic_ignoring_compiler" = "xyes"; then enable_ebcdic=yes fi -# Make sure that if enable_ebcdic is set, rebuild_chartables is also enabled. +# Make sure that if enable_ebcdic is set (without +# enable_ebcdic_ignoring_compiler), rebuild_chartables is also enabled. # Also check that UTF support is not requested, because PCRE2 cannot handle # EBCDIC and UTF in the same build. To do so it would need to use different -# character constants depending on the mode. Also, EBCDIC cannot be used with -# 16-bit and 32-bit libraries. -# +# character constants depending on the mode. +# Also, EBCDIC cannot be used with 16-bit and 32-bit libraries. if test "x$enable_ebcdic" = "xyes"; then - enable_rebuild_chartables=yes + if test "x$enable_ebcdic_ignoring_compiler" != "xyes"; then + enable_rebuild_chartables=yes + fi if test "x$enable_unicode" = "xyes"; then as_fn_error $? "support for EBCDIC and Unicode cannot be enabled at the same time" "$LINENO" 5 fi @@ -14839,6 +15388,22 @@ else WITH_UNICODE_FALSE= fi + if test "x$enable_ebcdic" = "xyes"; then + WITH_EBCDIC_TRUE= + WITH_EBCDIC_FALSE='#' +else + WITH_EBCDIC_TRUE='#' + WITH_EBCDIC_FALSE= +fi + + if test "x$enable_ebcdic_nl25" = "xyes"; then + WITH_EBCDIC_NL25_TRUE= + WITH_EBCDIC_NL25_FALSE='#' +else + WITH_EBCDIC_NL25_TRUE='#' + WITH_EBCDIC_NL25_FALSE= +fi + if test "x$enable_valgrind" = "xyes"; then WITH_VALGRIND_TRUE= WITH_VALGRIND_FALSE='#' @@ -14981,23 +15546,11 @@ fi # Checks for library functions. -ac_fn_c_check_func "$LINENO" "bcopy" "ac_cv_func_bcopy" -if test "x$ac_cv_func_bcopy" = xyes -then : - printf "%s\n" "#define HAVE_BCOPY 1" >>confdefs.h - -fi ac_fn_c_check_func "$LINENO" "memfd_create" "ac_cv_func_memfd_create" if test "x$ac_cv_func_memfd_create" = xyes then : printf "%s\n" "#define HAVE_MEMFD_CREATE 1" >>confdefs.h -fi -ac_fn_c_check_func "$LINENO" "memmove" "ac_cv_func_memmove" -if test "x$ac_cv_func_memmove" = xyes -then : - printf "%s\n" "#define HAVE_MEMMOVE 1" >>confdefs.h - fi ac_fn_c_check_func "$LINENO" "mkostemp" "ac_cv_func_mkostemp" if test "x$ac_cv_func_mkostemp" = xyes @@ -15010,12 +15563,6 @@ if test "x$ac_cv_func_secure_getenv" = xyes then : printf "%s\n" "#define HAVE_SECURE_GETENV 1" >>confdefs.h -fi -ac_fn_c_check_func "$LINENO" "strerror" "ac_cv_func_strerror" -if test "x$ac_cv_func_strerror" = xyes -then : - printf "%s\n" "#define HAVE_STRERROR 1" >>confdefs.h - fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for realpath" >&5 @@ -15166,7 +15713,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS="$OLD_LIBS" -# Check for the availabiity of libreadline +# Check for the availability of libreadline if test "$enable_pcre2test_libreadline" = "yes"; then for ac_header in readline/readline.h @@ -15349,7 +15896,7 @@ then : LIBREADLINE="-lncurses" else $as_nop unset ac_cv_lib_readline_readline; - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for readline in -lreadline" >&5 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for readline in -lreadline" >&5 printf %s "checking for readline in -lreadline... " >&6; } if test ${ac_cv_lib_readline_readline+y} then : @@ -15389,7 +15936,7 @@ then : LIBREADLINE="-lncursesw" else $as_nop unset ac_cv_lib_readline_readline; - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for readline in -lreadline" >&5 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for readline in -lreadline" >&5 printf %s "checking for readline in -lreadline... " >&6; } if test ${ac_cv_lib_readline_readline+y} then : @@ -15512,6 +16059,8 @@ fi fi +# Set up shared/static library flags + PCRE2_STATIC_CFLAG="" if test "x$enable_shared" = "xno" ; then @@ -15523,6 +16072,9 @@ fi PCRE2POSIX_CFLAG="" if test "x$enable_shared" = "xyes" ; then + +printf "%s\n" "#define PCRE2POSIX_SHARED 1" >>confdefs.h + PCRE2POSIX_CFLAG="-DPCRE2POSIX_SHARED" fi @@ -15565,6 +16117,141 @@ fi if test "$enable_jit" = "yes"; then if test "$HAVE_WINDOWS_H" != "1"; then + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +printf %s "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if test ${ac_cv_prog_CPP+y} +then : + printf %s "(cached) " >&6 +else $as_nop + # Double quotes because $CC needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO" +then : + +else $as_nop + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO" +then : + # Broken: success on invalid input. +continue +else $as_nop + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok +then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +printf "%s\n" "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO" +then : + +else $as_nop + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO" +then : + # Broken: success on invalid input. +continue +else $as_nop + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok +then : + +else $as_nop + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + ac_ext=c @@ -15576,19 +16263,28 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu ax_pthread_ok=no # We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on True64 or Sequent). +# requires special compiler flags (e.g. on Tru64 or Sequent). # It gets checked for in the link test anyway. # First of all, check if the user has set any of the PTHREAD_LIBS, # etcetera environment variables, and if threads linking works using # them: -if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then - save_CFLAGS="$CFLAGS" +if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then + ax_pthread_save_CC="$CC" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + if test "x$PTHREAD_CC" != "x" +then : + CC="$PTHREAD_CC" +fi + if test "x$PTHREAD_CXX" != "x" +then : + CXX="$PTHREAD_CXX" +fi CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS" >&5 -printf %s "checking for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS" >&5 +printf %s "checking for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -15612,12 +16308,13 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_pthread_ok" >&5 printf "%s\n" "$ax_pthread_ok" >&6; } - if test x"$ax_pthread_ok" = xno; then + if test "x$ax_pthread_ok" = "xno"; then PTHREAD_LIBS="" PTHREAD_CFLAGS="" fi - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" + CC="$ax_pthread_save_CC" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" fi # We must check for the threads library under a number of different @@ -15625,12 +16322,14 @@ fi # (e.g. DEC) have both -lpthread and -lpthreads, where one of the # libraries is broken (non-POSIX). -# Create a list of thread flags to try. Items starting with a "-" are -# C compiler flags, and other items are library names, except for "none" -# which indicates that we try without any flags at all, and "pthread-config" -# which is a program returning the flags for the Pth emulation library. +# Create a list of thread flags to try. Items with a "," contain both +# C compiler flags (before ",") and linker flags (after ","). Other items +# starting with a "-" are C compiler flags, and remaining items are +# library names, except for "none" which indicates that we try without +# any flags at all, and "pthread-config" which is a program returning +# the flags for the Pth emulation library. -ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" +ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" # The ordering *is* (sometimes) important. Some notes on the # individual items follow: @@ -15639,51 +16338,178 @@ ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mt # none: in case threads are in libc; should be tried before -Kthread and # other compiler flags to prevent continual compiler warnings # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) -# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) -# -pthreads: Solaris/gcc -# -mthreads: Mingw32/gcc, Lynx/gcc +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 +# (Note: HP C rejects this with "bad form for `-t' option") +# -pthreads: Solaris/gcc (Note: HP C also rejects) # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads too; -# also defines -D_REENTRANT) -# ... -mt is also the pthreads flag for HP/aCC +# doesn't hurt to check since this sometimes defines pthreads and +# -D_REENTRANT too), HP C (must be checked before -lpthread, which +# is present but should not be used directly; and before -mthreads, +# because the compiler interprets this as "-mt" + "-hreads") +# -mthreads: Mingw32/gcc, Lynx/gcc # pthread: Linux, etcetera # --thread-safe: KAI C++ # pthread-config: use pthread-config program (for GNU Pth library) -case ${host_os} in +case $host_os in + + freebsd*) + + # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) + # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) + + ax_pthread_flags="-kthread lthread $ax_pthread_flags" + ;; + + hpux*) + + # From the cc(1) man page: "[-mt] Sets various -D flags to enable + # multi-threading and also sets -lpthread." + + ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" + ;; + + openedition*) + + # IBM z/OS requires a feature-test macro to be defined in order to + # enable POSIX threads at all, so give the user a hint if this is + # not set. (We don't define these ourselves, as they can affect + # other portions of the system API in unpredictable ways.) + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) + AX_PTHREAD_ZOS_MISSING +# endif + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "AX_PTHREAD_ZOS_MISSING" >/dev/null 2>&1 +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support." >&5 +printf "%s\n" "$as_me: WARNING: IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support." >&2;} +fi +rm -rf conftest* + + ;; + solaris*) # On Solaris (at least, for some versions), libc contains stubbed # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (We need to link with -pthreads/-mt/ - # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather - # a function called by this macro, so we could check for that, but - # who knows whether they'll stub that too in a future libc.) So, - # we'll just look for -pthreads and -lpthread first: + # tests will erroneously succeed. (N.B.: The stubs are missing + # pthread_cleanup_push, or rather a function called by this macro, + # so we could check for that, but who knows whether they'll stub + # that too in a future libc.) So we'll check first for the + # standard Solaris way of linking pthreads (-mt -lpthread). - ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" - ;; - - darwin*) - ax_pthread_flags="-pthread $ax_pthread_flags" + ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags" ;; esac -if test x"$ax_pthread_ok" = xno; then -for flag in $ax_pthread_flags; do +# Are we compiling with Clang? - case $flag in +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC is Clang" >&5 +printf %s "checking whether $CC is Clang... " >&6; } +if test ${ax_cv_PTHREAD_CLANG+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ax_cv_PTHREAD_CLANG=no + # Note that Autoconf sets GCC=yes for Clang as well as GCC + if test "x$GCC" = "xyes"; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ +# if defined(__clang__) && defined(__llvm__) + AX_PTHREAD_CC_IS_CLANG +# endif + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "AX_PTHREAD_CC_IS_CLANG" >/dev/null 2>&1 +then : + ax_cv_PTHREAD_CLANG=yes +fi +rm -rf conftest* + + fi + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_PTHREAD_CLANG" >&5 +printf "%s\n" "$ax_cv_PTHREAD_CLANG" >&6; } +ax_pthread_clang="$ax_cv_PTHREAD_CLANG" + + +# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) + +# Note that for GCC and Clang -pthread generally implies -lpthread, +# except when -nostdlib is passed. +# This is problematic using libtool to build C++ shared libraries with pthread: +# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460 +# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333 +# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555 +# To solve this, first try -pthread together with -lpthread for GCC + +if test "x$GCC" = "xyes" +then : + ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags" +fi + +# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first + +if test "x$ax_pthread_clang" = "xyes" +then : + ax_pthread_flags="-pthread,-lpthread -pthread" +fi + + +# The presence of a feature test macro requesting re-entrant function +# definitions is, on some systems, a strong hint that pthreads support is +# correctly enabled + +case $host_os in + darwin* | hpux* | linux* | osf* | solaris*) + ax_pthread_check_macro="_REENTRANT" + ;; + + aix*) + ax_pthread_check_macro="_THREAD_SAFE" + ;; + + *) + ax_pthread_check_macro="--" + ;; +esac +if test "x$ax_pthread_check_macro" = "x--" +then : + ax_pthread_check_cond=0 +else $as_nop + ax_pthread_check_cond="!defined($ax_pthread_check_macro)" +fi + + +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do + + case $ax_pthread_try_flag in none) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether pthreads work without any flags" >&5 printf %s "checking whether pthreads work without any flags... " >&6; } ;; + *,*) + PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"` + PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"` + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether pthreads work with \"$PTHREAD_CFLAGS\" and \"$PTHREAD_LIBS\"" >&5 +printf %s "checking whether pthreads work with \"$PTHREAD_CFLAGS\" and \"$PTHREAD_LIBS\"... " >&6; } + ;; + -*) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether pthreads work with $flag" >&5 -printf %s "checking whether pthreads work with $flag... " >&6; } - PTHREAD_CFLAGS="$flag" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether pthreads work with $ax_pthread_try_flag" >&5 +printf %s "checking whether pthreads work with $ax_pthread_try_flag... " >&6; } + PTHREAD_CFLAGS="$ax_pthread_try_flag" ;; pthread-config) @@ -15730,22 +16556,25 @@ printf "%s\n" "no" >&6; } fi - if test x"$ax_pthread_config" = xno; then continue; fi + if test "x$ax_pthread_config" = "xno" +then : + continue +fi PTHREAD_CFLAGS="`pthread-config --cflags`" PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" ;; *) - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the pthreads library -l$flag" >&5 -printf %s "checking for the pthreads library -l$flag... " >&6; } - PTHREAD_LIBS="-l$flag" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the pthreads library -l$ax_pthread_try_flag" >&5 +printf %s "checking for the pthreads library -l$ax_pthread_try_flag... " >&6; } + PTHREAD_LIBS="-l$ax_pthread_try_flag" ;; esac - save_LIBS="$LIBS" - save_CFLAGS="$CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" # Check for various functions. We must include pthread.h, # since some functions may be macros. (On the Sequent, we @@ -15756,10 +16585,20 @@ printf %s "checking for the pthreads library -l$flag... " >&6; } # pthread_cleanup_push because it is one of the few pthread # functions on Solaris that doesn't have a non-functional libc stub. # We try pthread_create on general principles. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include - static void routine(void *a) { a = 0; } +# if $ax_pthread_check_cond +# error "$ax_pthread_check_macro must be defined" +# endif + static void *some_global = NULL; + static void routine(void *a) + { + /* To avoid any unused-parameter or + unused-but-set-parameter warning. */ + some_global = a; + } static void *start_routine(void *a) { return a; } int main (void) @@ -15781,77 +16620,195 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_pthread_ok" >&5 printf "%s\n" "$ax_pthread_ok" >&6; } - if test "x$ax_pthread_ok" = xyes; then - break; - fi + if test "x$ax_pthread_ok" = "xyes" +then : + break +fi PTHREAD_LIBS="" PTHREAD_CFLAGS="" done fi + +# Clang needs special handling, because older versions handle the -pthread +# option in a rather... idiosyncratic way + +if test "x$ax_pthread_clang" = "xyes"; then + + # Clang takes -pthread; it has never supported any other flag + + # (Note 1: This will need to be revisited if a system that Clang + # supports has POSIX threads in a separate library. This tends not + # to be the way of modern systems, but it's conceivable.) + + # (Note 2: On some systems, notably Darwin, -pthread is not needed + # to get POSIX threads support; the API is always present and + # active. We could reasonably leave PTHREAD_CFLAGS empty. But + # -pthread does define _REENTRANT, and while the Darwin headers + # ignore this macro, third-party headers might not.) + + # However, older versions of Clang make a point of warning the user + # that, in an invocation where only linking and no compilation is + # taking place, the -pthread option has no effect ("argument unused + # during compilation"). They expect -pthread to be passed in only + # when source code is being compiled. + # + # Problem is, this is at odds with the way Automake and most other + # C build frameworks function, which is that the same flags used in + # compilation (CFLAGS) are also used in linking. Many systems + # supported by AX_PTHREAD require exactly this for POSIX threads + # support, and in fact it is often not straightforward to specify a + # flag that is used only in the compilation phase and not in + # linking. Such a scenario is extremely rare in practice. + # + # Even though use of the -pthread flag in linking would only print + # a warning, this can be a nuisance for well-run software projects + # that build with -Werror. So if the active version of Clang has + # this misfeature, we search for an option to squash it. + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether Clang needs flag to prevent \"argument unused\" warning when linking with -pthread" >&5 +printf %s "checking whether Clang needs flag to prevent \"argument unused\" warning when linking with -pthread... " >&6; } +if test ${ax_cv_PTHREAD_CLANG_NO_WARN_FLAG+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown + # Create an alternate version of $ac_link that compiles and + # links in two steps (.c -> .o, .o -> exe) instead of one + # (.c -> exe), because the warning occurs only in the second + # step + ax_pthread_save_ac_link="$ac_link" + ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' + ax_pthread_link_step=`printf "%s\n" "$ac_link" | sed "$ax_pthread_sed"` + ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" + ax_pthread_save_CFLAGS="$CFLAGS" + for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do + if test "x$ax_pthread_try" = "xunknown" +then : + break +fi + CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" + ac_link="$ax_pthread_save_ac_link" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int main(void){return 0;} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_link="$ax_pthread_2step_ac_link" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int main(void){return 0;} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + break +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + done + ac_link="$ax_pthread_save_ac_link" + CFLAGS="$ax_pthread_save_CFLAGS" + if test "x$ax_pthread_try" = "x" +then : + ax_pthread_try=no +fi + ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" >&5 +printf "%s\n" "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" >&6; } + + case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in + no | unknown) ;; + *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; + esac + +fi # $ax_pthread_clang = yes + + + # Various other checks: -if test "x$ax_pthread_ok" = xyes; then - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - save_CFLAGS="$CFLAGS" +if test "x$ax_pthread_ok" = "xyes"; then + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for joinable pthread attribute" >&5 printf %s "checking for joinable pthread attribute... " >&6; } - attr_name=unknown - for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - cat confdefs.h - <<_ACEOF >conftest.$ac_ext +if test ${ax_cv_PTHREAD_JOINABLE_ATTR+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ax_cv_PTHREAD_JOINABLE_ATTR=unknown + for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { -int attr = $attr; return attr /* ; */ +int attr = $ax_pthread_attr; return attr /* ; */ ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : - attr_name=$attr; break + ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext - done - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $attr_name" >&5 -printf "%s\n" "$attr_name" >&6; } - if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then + done -printf "%s\n" "#define PTHREAD_CREATE_JOINABLE $attr_name" >>confdefs.h +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_PTHREAD_JOINABLE_ATTR" >&5 +printf "%s\n" "$ax_cv_PTHREAD_JOINABLE_ATTR" >&6; } + if test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ + test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ + test "x$ax_pthread_joinable_attr_defined" != "xyes" +then : - fi +printf "%s\n" "#define PTHREAD_CREATE_JOINABLE $ax_cv_PTHREAD_JOINABLE_ATTR" >>confdefs.h - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if more special flags are required for pthreads" >&5 -printf %s "checking if more special flags are required for pthreads... " >&6; } - flag=no - case ${host_os} in - aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";; - osf* | hpux*) flag="-D_REENTRANT";; - solaris*) - if test "$GCC" = "yes"; then - flag="-D_REENTRANT" - else - flag="-mt -D_REENTRANT" - fi - ;; - esac - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${flag}" >&5 -printf "%s\n" "${flag}" >&6; } - if test "x$flag" != xno; then - PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" - fi + ax_pthread_joinable_attr_defined=yes + +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether more special flags are required for pthreads" >&5 +printf %s "checking whether more special flags are required for pthreads... " >&6; } +if test ${ax_cv_PTHREAD_SPECIAL_FLAGS+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ax_cv_PTHREAD_SPECIAL_FLAGS=no + case $host_os in + solaris*) + ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" + ;; + esac + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_PTHREAD_SPECIAL_FLAGS" >&5 +printf "%s\n" "$ax_cv_PTHREAD_SPECIAL_FLAGS" >&6; } + if test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ + test "x$ax_pthread_special_flags_added" != "xyes" +then : + PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" + ax_pthread_special_flags_added=yes +fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for PTHREAD_PRIO_INHERIT" >&5 printf %s "checking for PTHREAD_PRIO_INHERIT... " >&6; } @@ -15859,15 +16816,14 @@ if test ${ax_cv_PTHREAD_PRIO_INHERIT+y} then : printf %s "(cached) " >&6 else $as_nop - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - - #include +#include int main (void) { int i = PTHREAD_PRIO_INHERIT; + return i; ; return 0; } @@ -15884,19 +16840,44 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_PTHREAD_PRIO_INHERIT" >&5 printf "%s\n" "$ax_cv_PTHREAD_PRIO_INHERIT" >&6; } - if test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" + if test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ + test "x$ax_pthread_prio_inherit_defined" != "xyes" then : printf "%s\n" "#define HAVE_PTHREAD_PRIO_INHERIT 1" >>confdefs.h + ax_pthread_prio_inherit_defined=yes + fi - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" - # More AIX lossage: must compile with xlc_r or cc_r - if test x"$GCC" != xyes; then - for ac_prog in xlc_r cc_r + # More AIX lossage: compile with *_r variant + if test "x$GCC" != "xyes"; then + case $host_os in + aix*) + case "x/$CC" in #( + x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6) : + #handle absolute path differently from PATH based program lookup + case "x$CC" in #( + x/*) : + + if as_fn_executable_p ${CC}_r +then : + PTHREAD_CC="${CC}_r" +fi + if test "x${CXX}" != "x" +then : + if as_fn_executable_p ${CXX}_r +then : + PTHREAD_CXX="${CXX}_r" +fi +fi + ;; #( + *) : + + for ac_prog in ${CC}_r do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 @@ -15942,21 +16923,81 @@ fi test -n "$PTHREAD_CC" && break done -test -n "$PTHREAD_CC" || PTHREAD_CC="${CC}" +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" - else - PTHREAD_CC=$CC - fi + if test "x${CXX}" != "x" +then : + for ac_prog in ${CXX}_r +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_PTHREAD_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$PTHREAD_CXX"; then + ac_cv_prog_PTHREAD_CXX="$PTHREAD_CXX" # Let the user override the test. else - PTHREAD_CC="$CC" +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_PTHREAD_CXX="$ac_prog" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + fi +fi +PTHREAD_CXX=$ac_cv_prog_PTHREAD_CXX +if test -n "$PTHREAD_CXX"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PTHREAD_CXX" >&5 +printf "%s\n" "$PTHREAD_CXX" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + + test -n "$PTHREAD_CXX" && break +done +test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX" + +fi + + ;; +esac + ;; #( + *) : + ;; +esac + ;; + esac + fi +fi + +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" +test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX" + # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test x"$ax_pthread_ok" = xyes; then +if test "x$ax_pthread_ok" = "xyes"; then printf "%s\n" "#define HAVE_PTHREAD 1" >>confdefs.h @@ -16133,6 +17174,8 @@ printf "%s\n" "#define MAX_NAME_COUNT 10000" >>confdefs.h + + if test "$enable_ebcdic" = "yes"; then printf "%s\n" "#define EBCDIC /**/" >>confdefs.h @@ -16145,6 +17188,12 @@ printf "%s\n" "#define EBCDIC_NL25 /**/" >>confdefs.h fi +if test "$enable_ebcdic_ignoring_compiler" = "yes"; then + +printf "%s\n" "#define EBCDIC_IGNORING_COMPILER /**/" >>confdefs.h + +fi + if test "$enable_valgrind" = "yes"; then printf "%s\n" "#define SUPPORT_VALGRIND /**/" >>confdefs.h @@ -16153,12 +17202,10 @@ fi # Platform specific issues NO_UNDEFINED= -EXPORT_ALL_SYMBOLS= case $host_os in cygwin* | mingw* ) if test X"$enable_shared" = Xyes; then NO_UNDEFINED="-no-undefined" - EXPORT_ALL_SYMBOLS="-Wl,--export-all-symbols" fi ;; esac @@ -16167,16 +17214,32 @@ esac # are m4 variables, assigned above. EXTRA_LIBPCRE2_8_LDFLAGS="$EXTRA_LIBPCRE2_8_LDFLAGS \ - $NO_UNDEFINED -version-info 14:0:14" + $NO_UNDEFINED -version-info 15:0:15" EXTRA_LIBPCRE2_16_LDFLAGS="$EXTRA_LIBPCRE2_16_LDFLAGS \ - $NO_UNDEFINED -version-info 14:0:14" + $NO_UNDEFINED -version-info 15:0:15" EXTRA_LIBPCRE2_32_LDFLAGS="$EXTRA_LIBPCRE2_32_LDFLAGS \ - $NO_UNDEFINED -version-info 14:0:14" + $NO_UNDEFINED -version-info 15:0:15" EXTRA_LIBPCRE2_POSIX_LDFLAGS="$EXTRA_LIBPCRE2_POSIX_LDFLAGS \ - $NO_UNDEFINED -version-info 3:6:0" + $NO_UNDEFINED -version-info 3:7:0" + +# Append each library's version script, if the platform supports it. + +if test x$ax_check_vscript_flag != x ; then + EXTRA_LIBPCRE2_8_LDFLAGS="$EXTRA_LIBPCRE2_8_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-8.sym" + + EXTRA_LIBPCRE2_16_LDFLAGS="$EXTRA_LIBPCRE2_16_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-16.sym" + + EXTRA_LIBPCRE2_32_LDFLAGS="$EXTRA_LIBPCRE2_32_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-32.sym" + + EXTRA_LIBPCRE2_POSIX_LDFLAGS="$EXTRA_LIBPCRE2_POSIX_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-posix.sym" +fi @@ -16719,6 +17782,15 @@ ac_config_commands="$ac_config_commands script-chmod" ac_config_commands="$ac_config_commands delete-old-chartables" +# Handle --enable-Werror/errwarn. This must come last, so that we don't mess +# with any of the library-detection tests (or similar). +if test "X$enable_Werror" = Xyes; then + CFLAGS="$CFLAGS -Werror" +fi +if test "X$enable_errwarn" = Xyes; then + CFLAGS="$CFLAGS -errwarn=%all" +fi + cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure @@ -16856,6 +17928,14 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then as_fn_error $? "conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${HAVE_VSCRIPT_TRUE}" && test -z "${HAVE_VSCRIPT_FALSE}"; then + as_fn_error $? "conditional \"HAVE_VSCRIPT\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${HAVE_VSCRIPT_COMPLEX_TRUE}" && test -z "${HAVE_VSCRIPT_COMPLEX_FALSE}"; then + as_fn_error $? "conditional \"HAVE_VSCRIPT_COMPLEX\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${WITH_PCRE2_8_TRUE}" && test -z "${WITH_PCRE2_8_FALSE}"; then as_fn_error $? "conditional \"WITH_PCRE2_8\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 @@ -16880,6 +17960,14 @@ if test -z "${WITH_UNICODE_TRUE}" && test -z "${WITH_UNICODE_FALSE}"; then as_fn_error $? "conditional \"WITH_UNICODE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${WITH_EBCDIC_TRUE}" && test -z "${WITH_EBCDIC_FALSE}"; then + as_fn_error $? "conditional \"WITH_EBCDIC\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_EBCDIC_NL25_TRUE}" && test -z "${WITH_EBCDIC_NL25_FALSE}"; then + as_fn_error $? "conditional \"WITH_EBCDIC_NL25\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${WITH_VALGRIND_TRUE}" && test -z "${WITH_VALGRIND_FALSE}"; then as_fn_error $? "conditional \"WITH_VALGRIND\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 @@ -17286,7 +18374,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by PCRE2 $as_me 10.45, which was +This file was extended by PCRE2 $as_me 10.47, which was generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -17354,7 +18442,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -PCRE2 config.status 10.45 +PCRE2 config.status 10.47 configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" @@ -19022,7 +20110,7 @@ ltmain=$ac_aux_dir/ltmain.sh ;; "script-chmod":C) chmod a+x pcre2-config ;; - "delete-old-chartables":C) rm -f pcre2_chartables.c ;; + "delete-old-chartables":C) rm -f src/pcre2_chartables.c ;; esac done # for ac_tag @@ -19081,6 +20169,13 @@ elif test "$enable_ebcdic" = "yes"; then ebcdic_nl_code=0x15 fi +with_symbol_versioning=n/a +if test x$want_symvers != xyes; then + with_symbol_versioning=no +elif test x$ax_check_vscript_flag != x; then + with_symbol_versioning=yes +fi + cat < @@ -654,7 +677,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[ AC_MSG_RESULT([no])) LIBS="$OLD_LIBS" -# Check for the availabiity of libreadline +# Check for the availability of libreadline if test "$enable_pcre2test_libreadline" = "yes"; then AC_CHECK_HEADERS([readline/readline.h], [HAVE_READLINE_H=1]) @@ -667,9 +690,9 @@ if test "$enable_pcre2test_libreadline" = "yes"; then [unset ac_cv_lib_readline_readline; AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-lncurses"], [unset ac_cv_lib_readline_readline; - AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-lncursesw"], + AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-lncursesw"], [unset ac_cv_lib_readline_readline; - AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-ltermcap"], + AC_CHECK_LIB([readline], [readline], [LIBREADLINE="-ltermcap"], [LIBREADLINE=""], [-ltermcap])], [-lncursesw])], @@ -696,16 +719,31 @@ if test "$enable_pcre2test_libedit" = "yes"; then AC_CHECK_LIB([edit], [readline], [LIBEDIT="-ledit"]) fi +# Set up shared/static library flags + PCRE2_STATIC_CFLAG="" if test "x$enable_shared" = "xno" ; then AC_DEFINE([PCRE2_STATIC], [1], [ - Define to any value if linking statically (TODO: make nice with Libtool)]) + Define to any value if linking statically. Ideally, if both static and + shared libraries are being built, then PCRE2_STATIC would be defined only + for the static build. Indeed, this is a requirement on Windows. With + Autoconf and libtool however, it is idiomatic to compile the sources once + to create both the static and shared library, so in this case, PCRE2_STATIC + should only be defined if no shared library is being built.]) PCRE2_STATIC_CFLAG="-DPCRE2_STATIC" fi AC_SUBST(PCRE2_STATIC_CFLAG) PCRE2POSIX_CFLAG="" if test "x$enable_shared" = "xyes" ; then + AC_DEFINE([PCRE2POSIX_SHARED], [1], [ + Define to any value if linking libpcre2-posix dynamically. Ideally, if both + static and shared libraries are being built, then PCRE2POSIX_SHARED would be + defined only for the shared build. Indeed, this is a requirement on Windows. + However, when building with Autoconf and libtool, we compile the sources once + only to create both the static and shared library, so in this case, + PCRE2POSIX_SHARED should only be defined if the shared library is being built, + regardless of whether or not the static library is also being built.]) PCRE2POSIX_CFLAG="-DPCRE2POSIX_SHARED" fi AC_SUBST(PCRE2POSIX_CFLAG) @@ -944,6 +982,11 @@ AH_VERBATIM([PCRE2_EXP_DEFN], [ in the C sense, but which are internal to the library. */ #undef PCRE2_EXP_DEFN]) +AH_VERBATIM([PCRE2POSIX_EXP_DEFN], [ +/* See PCRE2_EXP_DEFN; but this is applied to functions in the libpcre2-posix + library. */ +#undef PCRE2POSIX_EXP_DEFN]) + if test "$enable_ebcdic" = "yes"; then AC_DEFINE_UNQUOTED([EBCDIC], [], [ If you are compiling for a system that uses EBCDIC instead of ASCII @@ -951,7 +994,7 @@ if test "$enable_ebcdic" = "yes"; then assumes that all input strings are in EBCDIC. If you do not define this macro, PCRE2 will assume input strings are ASCII or UTF-8/16/32 Unicode. It is not possible to build a version of PCRE2 that supports both EBCDIC and - UTF-8/16/32.]) + ASCII or UTF-8/16/32.]) fi if test "$enable_ebcdic_nl25" = "yes"; then @@ -961,6 +1004,13 @@ if test "$enable_ebcdic_nl25" = "yes"; then that LF does in an ASCII/Unicode environment.]) fi +if test "$enable_ebcdic_ignoring_compiler" = "yes"; then + AC_DEFINE_UNQUOTED([EBCDIC_IGNORING_COMPILER], [], [ + To force an EBCDIC environment, define this macro to make the core PCRE2 + library functions use EBCDIC codepage 1047, regardless of whether the + compiler supports it using C character literals.]) +fi + if test "$enable_valgrind" = "yes"; then AC_DEFINE_UNQUOTED([SUPPORT_VALGRIND], [], [ Define to any value for valgrind support to find invalid memory reads.]) @@ -968,12 +1018,10 @@ fi # Platform specific issues NO_UNDEFINED= -EXPORT_ALL_SYMBOLS= case $host_os in cygwin* | mingw* ) if test X"$enable_shared" = Xyes; then NO_UNDEFINED="-no-undefined" - EXPORT_ALL_SYMBOLS="-Wl,--export-all-symbols" fi ;; esac @@ -993,6 +1041,22 @@ EXTRA_LIBPCRE2_32_LDFLAGS="$EXTRA_LIBPCRE2_32_LDFLAGS \ EXTRA_LIBPCRE2_POSIX_LDFLAGS="$EXTRA_LIBPCRE2_POSIX_LDFLAGS \ $NO_UNDEFINED -version-info libpcre2_posix_version" +# Append each library's version script, if the platform supports it. + +if test x$ax_check_vscript_flag != x ; then + EXTRA_LIBPCRE2_8_LDFLAGS="$EXTRA_LIBPCRE2_8_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-8.sym" + + EXTRA_LIBPCRE2_16_LDFLAGS="$EXTRA_LIBPCRE2_16_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-16.sym" + + EXTRA_LIBPCRE2_32_LDFLAGS="$EXTRA_LIBPCRE2_32_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-32.sym" + + EXTRA_LIBPCRE2_POSIX_LDFLAGS="$EXTRA_LIBPCRE2_POSIX_LDFLAGS \ + -Wl,$ax_check_vscript_flag,\$(srcdir)/src/libpcre2-posix.sym" +fi + AC_SUBST(EXTRA_LIBPCRE2_8_LDFLAGS) AC_SUBST(EXTRA_LIBPCRE2_16_LDFLAGS) AC_SUBST(EXTRA_LIBPCRE2_32_LDFLAGS) @@ -1147,7 +1211,16 @@ AC_CONFIG_COMMANDS([script-chmod], [chmod a+x pcre2-config]) # Make sure that pcre2_chartables.c is removed in case the method for # creating it was changed by reconfiguration. -AC_CONFIG_COMMANDS([delete-old-chartables], [rm -f pcre2_chartables.c]) +AC_CONFIG_COMMANDS([delete-old-chartables], [rm -f src/pcre2_chartables.c]) + +# Handle --enable-Werror/errwarn. This must come last, so that we don't mess +# with any of the library-detection tests (or similar). +if test "X$enable_Werror" = Xyes; then + CFLAGS="$CFLAGS -Werror" +fi +if test "X$enable_errwarn" = Xyes; then + CFLAGS="$CFLAGS -errwarn=%all" +fi AC_OUTPUT @@ -1170,6 +1243,13 @@ elif test "$enable_ebcdic" = "yes"; then ebcdic_nl_code=0x15 fi +with_symbol_versioning=n/a +if test x$want_symvers != xyes; then + with_symbol_versioning=no +elif test x$ax_check_vscript_flag != x; then + with_symbol_versioning=yes +fi + cat < +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2.99 PCRE2 + +# _AX_CHECK_VSCRIPT(flag, global-sym, action-if-link-succeeds, [junk-file=no]) +AC_DEFUN([_AX_CHECK_VSCRIPT], [ + AC_LANG_PUSH([C]) + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: $2; local: *; };" > conftest.map + AS_IF([test x$4 = xyes], [ + echo "{" >> conftest.map + ]) + LDFLAGS="$LDFLAGS -Wl,$1,conftest.map" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[int show, hide;]], [])], [$3]) + LDFLAGS="$ax_check_vscript_save_flags" + rm -f conftest.map + AC_LANG_POP([C]) +]) dnl _AX_CHECK_VSCRIPT + +AC_DEFUN([AX_CHECK_VSCRIPT], [ + + AC_ARG_ENABLE([symvers], + AS_HELP_STRING([--disable-symvers], + [disable library symbol versioning [default=auto]]), + [want_symvers=$enableval], + [want_symvers=yes] + ) + + AS_IF([test x$want_symvers = xyes], [ + + dnl First test --version-script and -M with a simple wildcard. + + AC_CACHE_CHECK([linker version script flag], ax_cv_check_vscript_flag, [ + ax_cv_check_vscript_flag=unsupported + _AX_CHECK_VSCRIPT([--version-script], [show], [ + ax_cv_check_vscript_flag=--version-script + ]) + AS_IF([test x$ax_cv_check_vscript_flag = xunsupported], [ + # PCRE2: Support for FreeBSD. Rather annoyingly, AC_LINK_IFELSE will + # only test linking executables, and in turn, on FreeBSD the main + # entrypoint will fail to link if you use "local: *" to hide the + # visibility of various shared symbols injected from /usr/lib/crt1.o. + # It's not at all pretty to hardcode those symbol names here, but I + # can't think of an obvious way to improve on this. + _AX_CHECK_VSCRIPT([--version-script], [show;environ;__progname], [ + ax_cv_check_vscript_flag=--version-script + ]) + ]) + AS_IF([test x$ax_cv_check_vscript_flag = xunsupported], [ + _AX_CHECK_VSCRIPT([-M], [show], [ax_cv_check_vscript_flag=-M]) + ]) + + dnl The linker may interpret -M (no argument) as "produce a load map." + dnl If "-M conftest.map" doesn't fail when conftest.map contains + dnl obvious syntax errors, assume this is the case. + + AS_IF([test x$ax_cv_check_vscript_flag != xunsupported], [ + _AX_CHECK_VSCRIPT([$ax_cv_check_vscript_flag], [show], + [ax_cv_check_vscript_flag=unsupported], [yes]) + ]) + ]) + + dnl If the simple wildcard worked, retest with a complex wildcard. + + AS_IF([test x$ax_cv_check_vscript_flag != xunsupported], [ + ax_check_vscript_flag=$ax_cv_check_vscript_flag + AC_CACHE_CHECK([if version scripts can use complex wildcards], + ax_cv_check_vscript_complex_wildcards, [ + ax_cv_check_vscript_complex_wildcards=no + _AX_CHECK_VSCRIPT([$ax_cv_check_vscript_flag], [sh*], [ + ax_cv_check_vscript_complex_wildcards=yes]) + ]) + ax_check_vscript_complex_wildcards="$ax_cv_check_vscript_complex_wildcards" + ], [ + ax_check_vscript_flag= + ax_check_vscript_complex_wildcards=no + ]) + ], [ + AC_MSG_CHECKING([linker version script flag]) + AC_MSG_RESULT([disabled]) + + ax_check_vscript_flag= + ax_check_vscript_complex_wildcards=no + ]) + + AS_IF([test x$ax_check_vscript_flag != x], [ + VSCRIPT_LDFLAGS="-Wl,$ax_check_vscript_flag" + AC_SUBST([VSCRIPT_LDFLAGS]) + ]) + + AM_CONDITIONAL([HAVE_VSCRIPT], + [test x$ax_check_vscript_flag != x]) + AM_CONDITIONAL([HAVE_VSCRIPT_COMPLEX], + [test x$ax_check_vscript_complex_wildcards = xyes]) + +]) dnl AX_CHECK_VSCRIPT diff --git a/libpcre/m4/ax_pthread.m4 b/libpcre/m4/ax_pthread.m4 index d90de34d1..9f35d1391 100644 --- a/libpcre/m4/ax_pthread.m4 +++ b/libpcre/m4/ax_pthread.m4 @@ -1,5 +1,5 @@ # =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_pthread.html +# https://www.gnu.org/software/autoconf-archive/ax_pthread.html # =========================================================================== # # SYNOPSIS @@ -14,24 +14,28 @@ # flags that are needed. (The user can also force certain compiler # flags/libs to be tested by setting these environment variables.) # -# Also sets PTHREAD_CC to any special C compiler that is needed for -# multi-threaded programs (defaults to the value of CC otherwise). (This -# is necessary on AIX to use the special cc_r compiler alias.) +# Also sets PTHREAD_CC and PTHREAD_CXX to any special C compiler that is +# needed for multi-threaded programs (defaults to the value of CC +# respectively CXX otherwise). (This is necessary on e.g. AIX to use the +# special cc_r/CC_r compiler alias.) # # NOTE: You are assumed to not only compile your program with these flags, -# but also link it with them as well. e.g. you should link with +# but also to link with them as well. For example, you might link with # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +# $PTHREAD_CXX $CXXFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS # -# If you are only building threads programs, you may wish to use these +# If you are only building threaded programs, you may wish to use these # variables in your default LIBS, CFLAGS, and CC: # # LIBS="$PTHREAD_LIBS $LIBS" # CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" # CC="$PTHREAD_CC" +# CXX="$PTHREAD_CXX" # # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant -# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name -# (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to +# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). # # Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the # PTHREAD_PRIO_INHERIT symbol is defined when compiling with @@ -55,6 +59,7 @@ # # Copyright (c) 2008 Steven G. Johnson # Copyright (c) 2011 Daniel Richard G. +# Copyright (c) 2019 Marc Stevens # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the @@ -67,7 +72,7 @@ # Public License for more details. # # You should have received a copy of the GNU General Public License along -# with this program. If not, see . +# with this program. If not, see . # # As a special exception, the respective Autoconf Macro's copyright owner # gives unlimited permission to copy, distribute and modify the configure @@ -82,35 +87,41 @@ # modified version of the Autoconf Macro, you may extend this special # exception to the GPL to apply to your modified version as well. -#serial 18 +#serial 31 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AC_DEFUN([AX_PTHREAD], [ AC_REQUIRE([AC_CANONICAL_HOST]) +AC_REQUIRE([AC_PROG_CC]) +AC_REQUIRE([AC_PROG_SED]) AC_LANG_PUSH([C]) ax_pthread_ok=no # We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on True64 or Sequent). +# requires special compiler flags (e.g. on Tru64 or Sequent). # It gets checked for in the link test anyway. # First of all, check if the user has set any of the PTHREAD_LIBS, # etcetera environment variables, and if threads linking works using # them: -if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then - save_CFLAGS="$CFLAGS" +if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then + ax_pthread_save_CC="$CC" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) + AS_IF([test "x$PTHREAD_CXX" != "x"], [CXX="$PTHREAD_CXX"]) CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - save_LIBS="$LIBS" LIBS="$PTHREAD_LIBS $LIBS" - AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) - AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes) - AC_MSG_RESULT($ax_pthread_ok) - if test x"$ax_pthread_ok" = xno; then + AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) + AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) + AC_MSG_RESULT([$ax_pthread_ok]) + if test "x$ax_pthread_ok" = "xno"; then PTHREAD_LIBS="" PTHREAD_CFLAGS="" fi - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" + CC="$ax_pthread_save_CC" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" fi # We must check for the threads library under a number of different @@ -118,12 +129,14 @@ fi # (e.g. DEC) have both -lpthread and -lpthreads, where one of the # libraries is broken (non-POSIX). -# Create a list of thread flags to try. Items starting with a "-" are -# C compiler flags, and other items are library names, except for "none" -# which indicates that we try without any flags at all, and "pthread-config" -# which is a program returning the flags for the Pth emulation library. +# Create a list of thread flags to try. Items with a "," contain both +# C compiler flags (before ",") and linker flags (after ","). Other items +# starting with a "-" are C compiler flags, and remaining items are +# library names, except for "none" which indicates that we try without +# any flags at all, and "pthread-config" which is a program returning +# the flags for the Pth emulation library. -ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" +ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" # The ordering *is* (sometimes) important. Some notes on the # individual items follow: @@ -132,68 +145,163 @@ ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mt # none: in case threads are in libc; should be tried before -Kthread and # other compiler flags to prevent continual compiler warnings # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) -# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) -# -pthreads: Solaris/gcc -# -mthreads: Mingw32/gcc, Lynx/gcc +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 +# (Note: HP C rejects this with "bad form for `-t' option") +# -pthreads: Solaris/gcc (Note: HP C also rejects) # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads too; -# also defines -D_REENTRANT) -# ... -mt is also the pthreads flag for HP/aCC +# doesn't hurt to check since this sometimes defines pthreads and +# -D_REENTRANT too), HP C (must be checked before -lpthread, which +# is present but should not be used directly; and before -mthreads, +# because the compiler interprets this as "-mt" + "-hreads") +# -mthreads: Mingw32/gcc, Lynx/gcc # pthread: Linux, etcetera # --thread-safe: KAI C++ # pthread-config: use pthread-config program (for GNU Pth library) -case ${host_os} in +case $host_os in + + freebsd*) + + # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) + # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) + + ax_pthread_flags="-kthread lthread $ax_pthread_flags" + ;; + + hpux*) + + # From the cc(1) man page: "[-mt] Sets various -D flags to enable + # multi-threading and also sets -lpthread." + + ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" + ;; + + openedition*) + + # IBM z/OS requires a feature-test macro to be defined in order to + # enable POSIX threads at all, so give the user a hint if this is + # not set. (We don't define these ourselves, as they can affect + # other portions of the system API in unpredictable ways.) + + AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], + [ +# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) + AX_PTHREAD_ZOS_MISSING +# endif + ], + [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) + ;; + solaris*) # On Solaris (at least, for some versions), libc contains stubbed # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (We need to link with -pthreads/-mt/ - # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather - # a function called by this macro, so we could check for that, but - # who knows whether they'll stub that too in a future libc.) So, - # we'll just look for -pthreads and -lpthread first: + # tests will erroneously succeed. (N.B.: The stubs are missing + # pthread_cleanup_push, or rather a function called by this macro, + # so we could check for that, but who knows whether they'll stub + # that too in a future libc.) So we'll check first for the + # standard Solaris way of linking pthreads (-mt -lpthread). - ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" - ;; - - darwin*) - ax_pthread_flags="-pthread $ax_pthread_flags" + ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags" ;; esac -if test x"$ax_pthread_ok" = xno; then -for flag in $ax_pthread_flags; do +# Are we compiling with Clang? - case $flag in +AC_CACHE_CHECK([whether $CC is Clang], + [ax_cv_PTHREAD_CLANG], + [ax_cv_PTHREAD_CLANG=no + # Note that Autoconf sets GCC=yes for Clang as well as GCC + if test "x$GCC" = "xyes"; then + AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], + [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ +# if defined(__clang__) && defined(__llvm__) + AX_PTHREAD_CC_IS_CLANG +# endif + ], + [ax_cv_PTHREAD_CLANG=yes]) + fi + ]) +ax_pthread_clang="$ax_cv_PTHREAD_CLANG" + + +# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) + +# Note that for GCC and Clang -pthread generally implies -lpthread, +# except when -nostdlib is passed. +# This is problematic using libtool to build C++ shared libraries with pthread: +# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460 +# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333 +# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555 +# To solve this, first try -pthread together with -lpthread for GCC + +AS_IF([test "x$GCC" = "xyes"], + [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"]) + +# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first + +AS_IF([test "x$ax_pthread_clang" = "xyes"], + [ax_pthread_flags="-pthread,-lpthread -pthread"]) + + +# The presence of a feature test macro requesting re-entrant function +# definitions is, on some systems, a strong hint that pthreads support is +# correctly enabled + +case $host_os in + darwin* | hpux* | linux* | osf* | solaris*) + ax_pthread_check_macro="_REENTRANT" + ;; + + aix*) + ax_pthread_check_macro="_THREAD_SAFE" + ;; + + *) + ax_pthread_check_macro="--" + ;; +esac +AS_IF([test "x$ax_pthread_check_macro" = "x--"], + [ax_pthread_check_cond=0], + [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) + + +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do + + case $ax_pthread_try_flag in none) AC_MSG_CHECKING([whether pthreads work without any flags]) ;; + *,*) + PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"` + PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"` + AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"]) + ;; + -*) - AC_MSG_CHECKING([whether pthreads work with $flag]) - PTHREAD_CFLAGS="$flag" + AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) + PTHREAD_CFLAGS="$ax_pthread_try_flag" ;; pthread-config) - AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no) - if test x"$ax_pthread_config" = xno; then continue; fi + AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) + AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) PTHREAD_CFLAGS="`pthread-config --cflags`" PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" ;; *) - AC_MSG_CHECKING([for the pthreads library -l$flag]) - PTHREAD_LIBS="-l$flag" + AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) + PTHREAD_LIBS="-l$ax_pthread_try_flag" ;; esac - save_LIBS="$LIBS" - save_CFLAGS="$CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" # Check for various functions. We must include pthread.h, # since some functions may be macros. (On the Sequent, we @@ -204,8 +312,18 @@ for flag in $ax_pthread_flags; do # pthread_cleanup_push because it is one of the few pthread # functions on Solaris that doesn't have a non-functional libc stub. # We try pthread_create on general principles. + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include - static void routine(void *a) { a = 0; } +# if $ax_pthread_check_cond +# error "$ax_pthread_check_macro must be defined" +# endif + static void *some_global = NULL; + static void routine(void *a) + { + /* To avoid any unused-parameter or + unused-but-set-parameter warning. */ + some_global = a; + } static void *start_routine(void *a) { return a; }], [pthread_t th; pthread_attr_t attr; pthread_create(&th, 0, start_routine, 0); @@ -213,93 +331,188 @@ for flag in $ax_pthread_flags; do pthread_attr_init(&attr); pthread_cleanup_push(routine, 0); pthread_cleanup_pop(0) /* ; */])], - [ax_pthread_ok=yes], - []) + [ax_pthread_ok=yes], + []) - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" - AC_MSG_RESULT($ax_pthread_ok) - if test "x$ax_pthread_ok" = xyes; then - break; - fi + AC_MSG_RESULT([$ax_pthread_ok]) + AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) PTHREAD_LIBS="" PTHREAD_CFLAGS="" done fi + +# Clang needs special handling, because older versions handle the -pthread +# option in a rather... idiosyncratic way + +if test "x$ax_pthread_clang" = "xyes"; then + + # Clang takes -pthread; it has never supported any other flag + + # (Note 1: This will need to be revisited if a system that Clang + # supports has POSIX threads in a separate library. This tends not + # to be the way of modern systems, but it's conceivable.) + + # (Note 2: On some systems, notably Darwin, -pthread is not needed + # to get POSIX threads support; the API is always present and + # active. We could reasonably leave PTHREAD_CFLAGS empty. But + # -pthread does define _REENTRANT, and while the Darwin headers + # ignore this macro, third-party headers might not.) + + # However, older versions of Clang make a point of warning the user + # that, in an invocation where only linking and no compilation is + # taking place, the -pthread option has no effect ("argument unused + # during compilation"). They expect -pthread to be passed in only + # when source code is being compiled. + # + # Problem is, this is at odds with the way Automake and most other + # C build frameworks function, which is that the same flags used in + # compilation (CFLAGS) are also used in linking. Many systems + # supported by AX_PTHREAD require exactly this for POSIX threads + # support, and in fact it is often not straightforward to specify a + # flag that is used only in the compilation phase and not in + # linking. Such a scenario is extremely rare in practice. + # + # Even though use of the -pthread flag in linking would only print + # a warning, this can be a nuisance for well-run software projects + # that build with -Werror. So if the active version of Clang has + # this misfeature, we search for an option to squash it. + + AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown + # Create an alternate version of $ac_link that compiles and + # links in two steps (.c -> .o, .o -> exe) instead of one + # (.c -> exe), because the warning occurs only in the second + # step + ax_pthread_save_ac_link="$ac_link" + ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' + ax_pthread_link_step=`AS_ECHO(["$ac_link"]) | sed "$ax_pthread_sed"` + ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" + ax_pthread_save_CFLAGS="$CFLAGS" + for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do + AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) + CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" + ac_link="$ax_pthread_save_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [ac_link="$ax_pthread_2step_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [break]) + ]) + done + ac_link="$ax_pthread_save_ac_link" + CFLAGS="$ax_pthread_save_CFLAGS" + AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) + ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" + ]) + + case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in + no | unknown) ;; + *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; + esac + +fi # $ax_pthread_clang = yes + + + # Various other checks: -if test "x$ax_pthread_ok" = xyes; then - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - save_CFLAGS="$CFLAGS" +if test "x$ax_pthread_ok" = "xyes"; then + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. - AC_MSG_CHECKING([for joinable pthread attribute]) - attr_name=unknown - for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], - [int attr = $attr; return attr /* ; */])], - [attr_name=$attr; break], - []) - done - AC_MSG_RESULT($attr_name) - if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then - AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, - [Define to necessary symbol if this constant - uses a non-standard name on your system.]) - fi + AC_CACHE_CHECK([for joinable pthread attribute], + [ax_cv_PTHREAD_JOINABLE_ATTR], + [ax_cv_PTHREAD_JOINABLE_ATTR=unknown + for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [int attr = $ax_pthread_attr; return attr /* ; */])], + [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], + []) + done + ]) + AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ + test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ + test "x$ax_pthread_joinable_attr_defined" != "xyes"], + [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], + [$ax_cv_PTHREAD_JOINABLE_ATTR], + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + ax_pthread_joinable_attr_defined=yes + ]) - AC_MSG_CHECKING([if more special flags are required for pthreads]) - flag=no - case ${host_os} in - aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";; - osf* | hpux*) flag="-D_REENTRANT";; - solaris*) - if test "$GCC" = "yes"; then - flag="-D_REENTRANT" - else - flag="-mt -D_REENTRANT" - fi - ;; - esac - AC_MSG_RESULT(${flag}) - if test "x$flag" != xno; then - PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" - fi + AC_CACHE_CHECK([whether more special flags are required for pthreads], + [ax_cv_PTHREAD_SPECIAL_FLAGS], + [ax_cv_PTHREAD_SPECIAL_FLAGS=no + case $host_os in + solaris*) + ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" + ;; + esac + ]) + AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ + test "x$ax_pthread_special_flags_added" != "xyes"], + [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" + ax_pthread_special_flags_added=yes]) AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], - ax_cv_PTHREAD_PRIO_INHERIT, [ - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([[#include ]], [[int i = PTHREAD_PRIO_INHERIT;]])], - [ax_cv_PTHREAD_PRIO_INHERIT=yes], - [ax_cv_PTHREAD_PRIO_INHERIT=no]) + [ax_cv_PTHREAD_PRIO_INHERIT], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[int i = PTHREAD_PRIO_INHERIT; + return i;]])], + [ax_cv_PTHREAD_PRIO_INHERIT=yes], + [ax_cv_PTHREAD_PRIO_INHERIT=no]) ]) - AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"], - AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], 1, [Have PTHREAD_PRIO_INHERIT.])) + AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ + test "x$ax_pthread_prio_inherit_defined" != "xyes"], + [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) + ax_pthread_prio_inherit_defined=yes + ]) - LIBS="$save_LIBS" - CFLAGS="$save_CFLAGS" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" - # More AIX lossage: must compile with xlc_r or cc_r - if test x"$GCC" != xyes; then - AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) - else - PTHREAD_CC=$CC + # More AIX lossage: compile with *_r variant + if test "x$GCC" != "xyes"; then + case $host_os in + aix*) + AS_CASE(["x/$CC"], + [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], + [#handle absolute path differently from PATH based program lookup + AS_CASE(["x$CC"], + [x/*], + [ + AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"]) + AS_IF([test "x${CXX}" != "x"], [AS_IF([AS_EXECUTABLE_P([${CXX}_r])],[PTHREAD_CXX="${CXX}_r"])]) + ], + [ + AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC]) + AS_IF([test "x${CXX}" != "x"], [AC_CHECK_PROGS([PTHREAD_CXX],[${CXX}_r],[$CXX])]) + ] + ) + ]) + ;; + esac fi -else - PTHREAD_CC="$CC" fi -AC_SUBST(PTHREAD_LIBS) -AC_SUBST(PTHREAD_CFLAGS) -AC_SUBST(PTHREAD_CC) +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" +test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX" + +AC_SUBST([PTHREAD_LIBS]) +AC_SUBST([PTHREAD_CFLAGS]) +AC_SUBST([PTHREAD_CC]) +AC_SUBST([PTHREAD_CXX]) # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test x"$ax_pthread_ok" = xyes; then - ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) +if test "x$ax_pthread_ok" = "xyes"; then + ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) : else ax_pthread_ok=no diff --git a/libpcre/m4/pcre2_visibility.m4 b/libpcre/m4/pcre2_visibility.m4 index 03f4fba6e..1e4e81952 100644 --- a/libpcre/m4/pcre2_visibility.m4 +++ b/libpcre/m4/pcre2_visibility.m4 @@ -34,10 +34,10 @@ AC_DEFUN([PCRE2_VISIBILITY], AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[]], [[]])], [ - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[]], [[ #warning e ]])], + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[ #warning e ]])], [], [pcre2_cv_cc_vis_werror=yes] - ) + ) ], []) CFLAGS="$pcre2_save_CFLAGS"]) AC_MSG_RESULT([$pcre2_cv_cc_vis_werror]) @@ -74,9 +74,9 @@ AC_DEFUN([PCRE2_VISIBILITY], then VISIBILITY_CFLAGS="-fvisibility=hidden" HAVE_VISIBILITY=1 - AC_DEFINE(PCRE2_EXPORT, [__attribute__ ((visibility ("default")))], [to make a symbol visible]) + AC_DEFINE(PCRE2_EXPORT, [__attribute__ ((visibility ("default")))], [Define to the annotation for making a symbol visible.]) else - AC_DEFINE(PCRE2_EXPORT, [], [to make a symbol visible]) + AC_DEFINE(PCRE2_EXPORT, [], [Define to the annotation for making a symbol visible.]) fi AC_SUBST([VISIBILITY_CFLAGS]) AC_SUBST([HAVE_VISIBILITY]) diff --git a/libpcre/m4/pcre2_zos.m4 b/libpcre/m4/pcre2_zos.m4 new file mode 100644 index 000000000..2e5dbd48b --- /dev/null +++ b/libpcre/m4/pcre2_zos.m4 @@ -0,0 +1,50 @@ +dnl Tests whether the compiler requires an additional flag in order to fail on +dnl undefined headers. + +dnl The concept of setting this commandline flag was learned from patches and +dnl mailing list discussions of the gnulib and gawk projects (credit to +dnl Bruno Haible). + +AC_DEFUN([PCRE2_ZOS_FIXES], +[ + AC_CACHE_CHECK([for OS/390 (z/OS)], [pcre2_cv_os390], + [if test "`uname`" = "OS/390"; then + pcre2_cv_os390=yes + else + pcre2_cv_os390=no + fi]) + if test "$pcre2_cv_os390" = "yes"; then + AC_CACHE_CHECK([whether the compiler supports -qhaltonmsg=CCN3296], [pcre2_cv_xlc_qhaltonmsg_support], + [save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -qhaltonmsg=CCN3296" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], + [pcre2_cv_xlc_qhaltonmsg_support=yes], + [pcre2_cv_xlc_qhaltonmsg_support=no]) + CFLAGS="$save_CFLAGS" + ]) + + AC_CACHE_CHECK([whether non-existent headers fail the compile], [pcre2_cv_xlc_nonexistent_fatal], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]])], + [pcre2_cv_xlc_nonexistent_fatal=no], + [pcre2_cv_xlc_nonexistent_fatal=yes]) + ]) + + if test "$pcre2_cv_xlc_nonexistent_fatal" = "no" && test "$pcre2_cv_xlc_qhaltonmsg_support" = "yes"; then + AC_CACHE_CHECK([whether -qhaltonmsg=CCN3296 fixes the non-existent-header issue], [pcre2_cv_xlc_qhaltonmsg_fixes], + [save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -qhaltonmsg=CCN3296" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]])], + [pcre2_cv_xlc_qhaltonmsg_fixes=no], + [pcre2_cv_xlc_qhaltonmsg_fixes=yes]) + CFLAGS="$save_CFLAGS" + ]) + + if test "$pcre2_cv_xlc_qhaltonmsg_fixes" = "no"; then + AC_MSG_ERROR([-qhaltonmsg=CCN3296 not effective on non-existent headers]) + fi + + CFLAGS="$CFLAGS -qhaltonmsg=CCN3296" + fi + + fi +]) diff --git a/libpcre/config-cmake.h.in b/libpcre/src/config-cmake.h.in similarity index 90% rename from libpcre/config-cmake.h.in rename to libpcre/src/config-cmake.h.in index 0eff0e0f7..bcc62c046 100644 --- a/libpcre/config-cmake.h.in +++ b/libpcre/src/config-cmake.h.in @@ -11,11 +11,8 @@ #cmakedefine HAVE_UNISTD_H 1 #cmakedefine HAVE_WINDOWS_H 1 -#cmakedefine HAVE_BCOPY 1 #cmakedefine HAVE_MEMFD_CREATE 1 -#cmakedefine HAVE_MEMMOVE 1 #cmakedefine HAVE_SECURE_GETENV 1 -#cmakedefine HAVE_STRERROR 1 #cmakedefine SUPPORT_PCRE2_8 1 #cmakedefine SUPPORT_PCRE2_16 1 @@ -38,7 +35,7 @@ #cmakedefine BSR_ANYCRLF 1 #cmakedefine EBCDIC 1 #cmakedefine EBCDIC_NL25 1 -#cmakedefine HEAP_MATCH_RECURSE 1 +#cmakedefine EBCDIC_IGNORING_COMPILER 1 #cmakedefine NEVER_BACKSLASH_C 1 #define PCRE2_EXPORT @PCRE2_EXPORT@ @@ -52,7 +49,7 @@ #define PCRE2GREP_BUFSIZE @PCRE2GREP_BUFSIZE@ #define PCRE2GREP_MAX_BUFSIZE @PCRE2GREP_MAX_BUFSIZE@ -#define MAX_NAME_SIZE 128 -#define MAX_NAME_COUNT 10000 +#define MAX_NAME_SIZE 128 +#define MAX_NAME_COUNT 10000 /* end config.h for CMake builds */ diff --git a/libpcre/src/config.h.generic b/libpcre/src/config.h.generic index 380a08906..48da31e1b 100644 --- a/libpcre/src/config.h.generic +++ b/libpcre/src/config.h.generic @@ -22,11 +22,7 @@ Boolean macros such as HAVE_STDLIB_H and SUPPORT_PCRE2_8 should either be defined (conventionally to 1) for TRUE, and not defined at all for FALSE. All such macros are listed as a commented #undef in config.h.generic. Macros such as MATCH_LIMIT, whose actual value is relevant, have defaults defined, but are -surrounded by #ifndef/#endif lines so that the value can be overridden by -D. - -PCRE2 uses memmove() if HAVE_MEMMOVE is defined; otherwise it uses bcopy() if -HAVE_BCOPY is defined. If your system has neither bcopy() nor memmove(), make -sure both macros are undefined; an emulation function will then be used. */ +surrounded by #ifndef/#endif lines so that the value can be overridden by -D. */ /* By default, the \R escape sequence matches any Unicode line ending character or sequence of characters. If BSR_ANYCRLF is defined (to any @@ -44,9 +40,14 @@ sure both macros are undefined; an emulation function will then be used. */ assumes that all input strings are in EBCDIC. If you do not define this macro, PCRE2 will assume input strings are ASCII or UTF-8/16/32 Unicode. It is not possible to build a version of PCRE2 that supports both EBCDIC and - UTF-8/16/32. */ + ASCII or UTF-8/16/32. */ /* #undef EBCDIC */ +/* To force an EBCDIC environment, define this macro to make the core PCRE2 + library functions use EBCDIC codepage 1047, regardless of whether the + compiler supports it using C character literals. */ +/* #undef EBCDIC_IGNORING_COMPILER */ + /* In an EBCDIC environment, define this macro to any value to arrange for the NL character to be 0x25 instead of the default 0x15. NL plays the role that LF does in an ASCII/Unicode environment. */ @@ -58,9 +59,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define this if your compiler supports __attribute__((uninitialized)) */ /* #undef HAVE_ATTRIBUTE_UNINITIALIZED */ -/* Define to 1 if you have the `bcopy' function. */ -/* #undef HAVE_BCOPY */ - /* Define this if your compiler provides __assume() */ /* #undef HAVE_BUILTIN_ASSUME */ @@ -94,9 +92,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the `memfd_create' function. */ /* #undef HAVE_MEMFD_CREATE */ -/* Define to 1 if you have the `memmove' function. */ -/* #undef HAVE_MEMMOVE */ - /* Define to 1 if you have the header file. */ /* #undef HAVE_MINIX_CONFIG_H */ @@ -133,9 +128,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the header file. */ /* #undef HAVE_STDLIB_H */ -/* Define to 1 if you have the `strerror' function. */ -/* #undef HAVE_STRERROR */ - /* Define to 1 if you have the header file. */ /* #undef HAVE_STRINGS_H */ @@ -255,7 +247,7 @@ sure both macros are undefined; an emulation function will then be used. */ #define PACKAGE_NAME "PCRE2" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "PCRE2 10.45" +#define PACKAGE_STRING "PCRE2 10.47" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "pcre2" @@ -264,7 +256,7 @@ sure both macros are undefined; an emulation function will then be used. */ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "10.45" +#define PACKAGE_VERSION "10.47" /* The value of PARENS_NEST_LIMIT specifies the maximum depth of nested parentheses (of any kind) in a pattern. This limits the amount of system @@ -291,10 +283,24 @@ sure both macros are undefined; an emulation function will then be used. */ #define PCRE2GREP_MAX_BUFSIZE 1048576 #endif +/* See PCRE2_EXP_DEFN; but this is applied to functions in the libpcre2-posix + library. */ +/* #undef PCRE2POSIX_EXP_DEFN */ + +/* Define to any value if linking libpcre2-posix dynamically. Ideally, if both + static and shared libraries are being built, then PCRE2POSIX_SHARED would + be defined only for the shared build. Indeed, this is a requirement on + Windows. However, when building with Autoconf and libtool, we compile the + sources once only to create both the static and shared library, so in this + case, PCRE2POSIX_SHARED should only be defined if the shared library is + being built, regardless of whether or not the static library is also being + built. */ +/* #undef PCRE2POSIX_SHARED */ + /* Define to any value to include debugging code. */ /* #undef PCRE2_DEBUG */ -/* to make a symbol visible */ +/* Define to the annotation for making a symbol visible. */ #define PCRE2_EXPORT /* If you are compiling for a system other than a Unix-like system or @@ -309,7 +315,12 @@ sure both macros are undefined; an emulation function will then be used. */ in the C sense, but which are internal to the library. */ /* #undef PCRE2_EXP_DEFN */ -/* Define to any value if linking statically (TODO: make nice with Libtool) */ +/* Define to any value if linking statically. Ideally, if both static and + shared libraries are being built, then PCRE2_STATIC would be defined only + for the static build. Indeed, this is a requirement on Windows. With + Autoconf and libtool however, it is idiomatic to compile the sources once + to create both the static and shared library, so in this case, PCRE2_STATIC + should only be defined if no shared library is being built. */ /* #undef PCRE2_STATIC */ /* Define to necessary symbol if this constant uses a non-standard name on @@ -464,7 +475,7 @@ sure both macros are undefined; an emulation function will then be used. */ #endif /* Version number of package */ -#define VERSION "10.45" +#define VERSION "10.47" /* Number of bits in a file offset, on hosts where this is settable. */ /* #undef _FILE_OFFSET_BITS */ diff --git a/libpcre/src/config.h.in b/libpcre/src/config.h.in index be29681c1..0f2ef3834 100644 --- a/libpcre/src/config.h.in +++ b/libpcre/src/config.h.in @@ -22,11 +22,7 @@ Boolean macros such as HAVE_STDLIB_H and SUPPORT_PCRE2_8 should either be defined (conventionally to 1) for TRUE, and not defined at all for FALSE. All such macros are listed as a commented #undef in config.h.generic. Macros such as MATCH_LIMIT, whose actual value is relevant, have defaults defined, but are -surrounded by #ifndef/#endif lines so that the value can be overridden by -D. - -PCRE2 uses memmove() if HAVE_MEMMOVE is defined; otherwise it uses bcopy() if -HAVE_BCOPY is defined. If your system has neither bcopy() nor memmove(), make -sure both macros are undefined; an emulation function will then be used. */ +surrounded by #ifndef/#endif lines so that the value can be overridden by -D. */ /* By default, the \R escape sequence matches any Unicode line ending character or sequence of characters. If BSR_ANYCRLF is defined (to any @@ -44,9 +40,14 @@ sure both macros are undefined; an emulation function will then be used. */ assumes that all input strings are in EBCDIC. If you do not define this macro, PCRE2 will assume input strings are ASCII or UTF-8/16/32 Unicode. It is not possible to build a version of PCRE2 that supports both EBCDIC and - UTF-8/16/32. */ + ASCII or UTF-8/16/32. */ #undef EBCDIC +/* To force an EBCDIC environment, define this macro to make the core PCRE2 + library functions use EBCDIC codepage 1047, regardless of whether the + compiler supports it using C character literals. */ +#undef EBCDIC_IGNORING_COMPILER + /* In an EBCDIC environment, define this macro to any value to arrange for the NL character to be 0x25 instead of the default 0x15. NL plays the role that LF does in an ASCII/Unicode environment. */ @@ -58,9 +59,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define this if your compiler supports __attribute__((uninitialized)) */ #undef HAVE_ATTRIBUTE_UNINITIALIZED -/* Define to 1 if you have the `bcopy' function. */ -#undef HAVE_BCOPY - /* Define this if your compiler provides __assume() */ #undef HAVE_BUILTIN_ASSUME @@ -94,9 +92,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the `memfd_create' function. */ #undef HAVE_MEMFD_CREATE -/* Define to 1 if you have the `memmove' function. */ -#undef HAVE_MEMMOVE - /* Define to 1 if you have the header file. */ #undef HAVE_MINIX_CONFIG_H @@ -133,9 +128,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H -/* Define to 1 if you have the `strerror' function. */ -#undef HAVE_STRERROR - /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H @@ -266,10 +258,25 @@ sure both macros are undefined; an emulation function will then be used. */ allows for the buffering of "before" and "after" lines. */ #undef PCRE2GREP_MAX_BUFSIZE + +/* See PCRE2_EXP_DEFN; but this is applied to functions in the libpcre2-posix + library. */ +#undef PCRE2POSIX_EXP_DEFN + +/* Define to any value if linking libpcre2-posix dynamically. Ideally, if both + static and shared libraries are being built, then PCRE2POSIX_SHARED would + be defined only for the shared build. Indeed, this is a requirement on + Windows. However, when building with Autoconf and libtool, we compile the + sources once only to create both the static and shared library, so in this + case, PCRE2POSIX_SHARED should only be defined if the shared library is + being built, regardless of whether or not the static library is also being + built. */ +#undef PCRE2POSIX_SHARED + /* Define to any value to include debugging code. */ #undef PCRE2_DEBUG -/* to make a symbol visible */ +/* Define to the annotation for making a symbol visible. */ #undef PCRE2_EXPORT @@ -285,7 +292,12 @@ sure both macros are undefined; an emulation function will then be used. */ in the C sense, but which are internal to the library. */ #undef PCRE2_EXP_DEFN -/* Define to any value if linking statically (TODO: make nice with Libtool) */ +/* Define to any value if linking statically. Ideally, if both static and + shared libraries are being built, then PCRE2_STATIC would be defined only + for the static build. Indeed, this is a requirement on Windows. With + Autoconf and libtool however, it is idiomatic to compile the sources once + to create both the static and shared library, so in this case, PCRE2_STATIC + should only be defined if no shared library is being built. */ #undef PCRE2_STATIC /* Define to necessary symbol if this constant uses a non-standard name on diff --git a/libpcre/src/libpcre2-16.sym b/libpcre/src/libpcre2-16.sym new file mode 100644 index 000000000..fd5257db6 --- /dev/null +++ b/libpcre/src/libpcre2-16.sym @@ -0,0 +1,88 @@ +# First version of PCRE2 in which symbols were assigned versions. +PCRE2_10.47 { + global: + pcre2_callout_enumerate_16; + pcre2_code_copy_16; + pcre2_code_copy_with_tables_16; + pcre2_code_free_16; + pcre2_compile_16; + pcre2_compile_context_copy_16; + pcre2_compile_context_create_16; + pcre2_compile_context_free_16; + pcre2_config_16; + pcre2_convert_context_copy_16; + pcre2_convert_context_create_16; + pcre2_convert_context_free_16; + pcre2_converted_pattern_free_16; + pcre2_dfa_match_16; + pcre2_general_context_copy_16; + pcre2_general_context_create_16; + pcre2_general_context_free_16; + pcre2_get_error_message_16; + pcre2_get_mark_16; + pcre2_get_match_data_heapframes_size_16; + pcre2_get_match_data_size_16; + pcre2_get_ovector_count_16; + pcre2_get_ovector_pointer_16; + pcre2_get_startchar_16; + pcre2_jit_compile_16; + pcre2_jit_free_unused_memory_16; + pcre2_jit_match_16; + pcre2_jit_stack_assign_16; + pcre2_jit_stack_create_16; + pcre2_jit_stack_free_16; + pcre2_maketables_16; + pcre2_maketables_free_16; + pcre2_match_16; + pcre2_match_context_copy_16; + pcre2_match_context_create_16; + pcre2_match_context_free_16; + pcre2_match_data_create_16; + pcre2_match_data_create_from_pattern_16; + pcre2_match_data_free_16; + pcre2_next_match_16; + pcre2_pattern_convert_16; + pcre2_pattern_info_16; + pcre2_serialize_decode_16; + pcre2_serialize_encode_16; + pcre2_serialize_free_16; + pcre2_serialize_get_number_of_codes_16; + pcre2_set_bsr_16; + pcre2_set_callout_16; + pcre2_set_character_tables_16; + pcre2_set_compile_extra_options_16; + pcre2_set_compile_recursion_guard_16; + pcre2_set_depth_limit_16; + pcre2_set_glob_escape_16; + pcre2_set_glob_separator_16; + pcre2_set_heap_limit_16; + pcre2_set_match_limit_16; + pcre2_set_max_pattern_compiled_length_16; + pcre2_set_max_pattern_length_16; + pcre2_set_max_varlookbehind_16; + pcre2_set_newline_16; + pcre2_set_offset_limit_16; + pcre2_set_optimize_16; + pcre2_set_parens_nest_limit_16; + pcre2_set_recursion_limit_16; + pcre2_set_recursion_memory_management_16; + pcre2_set_substitute_callout_16; + pcre2_set_substitute_case_callout_16; + pcre2_substitute_16; + pcre2_substring_copy_byname_16; + pcre2_substring_copy_bynumber_16; + pcre2_substring_free_16; + pcre2_substring_get_byname_16; + pcre2_substring_get_bynumber_16; + pcre2_substring_length_byname_16; + pcre2_substring_length_bynumber_16; + pcre2_substring_list_free_16; + pcre2_substring_list_get_16; + pcre2_substring_nametable_scan_16; + pcre2_substring_number_from_name_16; + local: + _fini; + _init; +}; + +# PCRE2_10.48 {} PCRE2_10.47; diff --git a/libpcre/src/libpcre2-32.sym b/libpcre/src/libpcre2-32.sym new file mode 100644 index 000000000..d4606c2b5 --- /dev/null +++ b/libpcre/src/libpcre2-32.sym @@ -0,0 +1,88 @@ +# First version of PCRE2 in which symbols were assigned versions. +PCRE2_10.47 { + global: + pcre2_callout_enumerate_32; + pcre2_code_copy_32; + pcre2_code_copy_with_tables_32; + pcre2_code_free_32; + pcre2_compile_32; + pcre2_compile_context_copy_32; + pcre2_compile_context_create_32; + pcre2_compile_context_free_32; + pcre2_config_32; + pcre2_convert_context_copy_32; + pcre2_convert_context_create_32; + pcre2_convert_context_free_32; + pcre2_converted_pattern_free_32; + pcre2_dfa_match_32; + pcre2_general_context_copy_32; + pcre2_general_context_create_32; + pcre2_general_context_free_32; + pcre2_get_error_message_32; + pcre2_get_mark_32; + pcre2_get_match_data_heapframes_size_32; + pcre2_get_match_data_size_32; + pcre2_get_ovector_count_32; + pcre2_get_ovector_pointer_32; + pcre2_get_startchar_32; + pcre2_jit_compile_32; + pcre2_jit_free_unused_memory_32; + pcre2_jit_match_32; + pcre2_jit_stack_assign_32; + pcre2_jit_stack_create_32; + pcre2_jit_stack_free_32; + pcre2_maketables_32; + pcre2_maketables_free_32; + pcre2_match_32; + pcre2_match_context_copy_32; + pcre2_match_context_create_32; + pcre2_match_context_free_32; + pcre2_match_data_create_32; + pcre2_match_data_create_from_pattern_32; + pcre2_match_data_free_32; + pcre2_next_match_32; + pcre2_pattern_convert_32; + pcre2_pattern_info_32; + pcre2_serialize_decode_32; + pcre2_serialize_encode_32; + pcre2_serialize_free_32; + pcre2_serialize_get_number_of_codes_32; + pcre2_set_bsr_32; + pcre2_set_callout_32; + pcre2_set_character_tables_32; + pcre2_set_compile_extra_options_32; + pcre2_set_compile_recursion_guard_32; + pcre2_set_depth_limit_32; + pcre2_set_glob_escape_32; + pcre2_set_glob_separator_32; + pcre2_set_heap_limit_32; + pcre2_set_match_limit_32; + pcre2_set_max_pattern_compiled_length_32; + pcre2_set_max_pattern_length_32; + pcre2_set_max_varlookbehind_32; + pcre2_set_newline_32; + pcre2_set_offset_limit_32; + pcre2_set_optimize_32; + pcre2_set_parens_nest_limit_32; + pcre2_set_recursion_limit_32; + pcre2_set_recursion_memory_management_32; + pcre2_set_substitute_callout_32; + pcre2_set_substitute_case_callout_32; + pcre2_substitute_32; + pcre2_substring_copy_byname_32; + pcre2_substring_copy_bynumber_32; + pcre2_substring_free_32; + pcre2_substring_get_byname_32; + pcre2_substring_get_bynumber_32; + pcre2_substring_length_byname_32; + pcre2_substring_length_bynumber_32; + pcre2_substring_list_free_32; + pcre2_substring_list_get_32; + pcre2_substring_nametable_scan_32; + pcre2_substring_number_from_name_32; + local: + _fini; + _init; +}; + +# PCRE2_10.48 {} PCRE2_10.47; diff --git a/libpcre/src/libpcre2-8.sym b/libpcre/src/libpcre2-8.sym new file mode 100644 index 000000000..368b4e441 --- /dev/null +++ b/libpcre/src/libpcre2-8.sym @@ -0,0 +1,88 @@ +# First version of PCRE2 in which symbols were assigned versions. +PCRE2_10.47 { + global: + pcre2_callout_enumerate_8; + pcre2_code_copy_8; + pcre2_code_copy_with_tables_8; + pcre2_code_free_8; + pcre2_compile_8; + pcre2_compile_context_copy_8; + pcre2_compile_context_create_8; + pcre2_compile_context_free_8; + pcre2_config_8; + pcre2_convert_context_copy_8; + pcre2_convert_context_create_8; + pcre2_convert_context_free_8; + pcre2_converted_pattern_free_8; + pcre2_dfa_match_8; + pcre2_general_context_copy_8; + pcre2_general_context_create_8; + pcre2_general_context_free_8; + pcre2_get_error_message_8; + pcre2_get_mark_8; + pcre2_get_match_data_heapframes_size_8; + pcre2_get_match_data_size_8; + pcre2_get_ovector_count_8; + pcre2_get_ovector_pointer_8; + pcre2_get_startchar_8; + pcre2_jit_compile_8; + pcre2_jit_free_unused_memory_8; + pcre2_jit_match_8; + pcre2_jit_stack_assign_8; + pcre2_jit_stack_create_8; + pcre2_jit_stack_free_8; + pcre2_maketables_8; + pcre2_maketables_free_8; + pcre2_match_8; + pcre2_match_context_copy_8; + pcre2_match_context_create_8; + pcre2_match_context_free_8; + pcre2_match_data_create_8; + pcre2_match_data_create_from_pattern_8; + pcre2_match_data_free_8; + pcre2_next_match_8; + pcre2_pattern_convert_8; + pcre2_pattern_info_8; + pcre2_serialize_decode_8; + pcre2_serialize_encode_8; + pcre2_serialize_free_8; + pcre2_serialize_get_number_of_codes_8; + pcre2_set_bsr_8; + pcre2_set_callout_8; + pcre2_set_character_tables_8; + pcre2_set_compile_extra_options_8; + pcre2_set_compile_recursion_guard_8; + pcre2_set_depth_limit_8; + pcre2_set_glob_escape_8; + pcre2_set_glob_separator_8; + pcre2_set_heap_limit_8; + pcre2_set_match_limit_8; + pcre2_set_max_pattern_compiled_length_8; + pcre2_set_max_pattern_length_8; + pcre2_set_max_varlookbehind_8; + pcre2_set_newline_8; + pcre2_set_offset_limit_8; + pcre2_set_optimize_8; + pcre2_set_parens_nest_limit_8; + pcre2_set_recursion_limit_8; + pcre2_set_recursion_memory_management_8; + pcre2_set_substitute_callout_8; + pcre2_set_substitute_case_callout_8; + pcre2_substitute_8; + pcre2_substring_copy_byname_8; + pcre2_substring_copy_bynumber_8; + pcre2_substring_free_8; + pcre2_substring_get_byname_8; + pcre2_substring_get_bynumber_8; + pcre2_substring_length_byname_8; + pcre2_substring_length_bynumber_8; + pcre2_substring_list_free_8; + pcre2_substring_list_get_8; + pcre2_substring_nametable_scan_8; + pcre2_substring_number_from_name_8; + local: + _fini; + _init; +}; + +# PCRE2_10.48 {} PCRE2_10.47; diff --git a/libpcre/src/libpcre2-posix.sym b/libpcre/src/libpcre2-posix.sym new file mode 100644 index 000000000..04a56cf61 --- /dev/null +++ b/libpcre/src/libpcre2-posix.sym @@ -0,0 +1,13 @@ +# First version of PCRE2 in which symbols were assigned versions. +PCRE2_10.47 { + global: + pcre2_regcomp; + pcre2_regerror; + pcre2_regexec; + pcre2_regfree; + local: + _fini; + _init; +}; + +# PCRE2_10.48 {} PCRE2_10.47; diff --git a/libpcre/src/pcre2.h.generic b/libpcre/src/pcre2.h.generic index 061f3db0a..4034e5a91 100644 --- a/libpcre/src/pcre2.h.generic +++ b/libpcre/src/pcre2.h.generic @@ -42,25 +42,21 @@ POSSIBILITY OF SUCH DAMAGE. /* The current PCRE version information. */ #define PCRE2_MAJOR 10 -#define PCRE2_MINOR 45 +#define PCRE2_MINOR 47 #define PCRE2_PRERELEASE -#define PCRE2_DATE 2025-02-05 +#define PCRE2_DATE 2025-10-21 -/* When an application links to a PCRE DLL in Windows, the symbols that are +/* When an application links to a PCRE2 DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE2, the appropriate -export setting is defined in pcre2_internal.h, which includes this file. So we -don't change existing definitions of PCRE2_EXP_DECL. */ +export setting is defined in pcre2_internal.h, which includes this file. So, we +don't change existing definitions of PCRE2_EXP_DECL. -#if defined(_WIN32) && !defined(PCRE2_STATIC) -# ifndef PCRE2_EXP_DECL -# define PCRE2_EXP_DECL extern __declspec(dllimport) -# endif -#endif - -/* By default, we use the standard "extern" declarations. */ +By default, we use the standard "extern" declarations. */ #ifndef PCRE2_EXP_DECL -# ifdef __cplusplus +# if defined(_WIN32) && !defined(PCRE2_STATIC) +# define PCRE2_EXP_DECL extern __declspec(dllimport) +# elif defined __cplusplus # define PCRE2_EXP_DECL extern "C" # else # define PCRE2_EXP_DECL extern @@ -68,14 +64,15 @@ don't change existing definitions of PCRE2_EXP_DECL. */ #endif /* When compiling with the MSVC compiler, it is sometimes necessary to include -a "calling convention" before exported function names. (This is secondhand -information; I know nothing about MSVC myself). For example, something like +a "calling convention" before exported function names. For example: void __cdecl function(....) -might be needed. In order so make this easy, all the exported functions have -PCRE2_CALL_CONVENTION just before their names. It is rarely needed; if not -set, we ensure here that it has no effect. */ +might be needed. In order to make this easy, all the exported functions have +PCRE2_CALL_CONVENTION just before their names. + +PCRE2 normally uses the platform's standard calling convention, so this should +not be set unless you know you need it. */ #ifndef PCRE2_CALL_CONVENTION #define PCRE2_CALL_CONVENTION @@ -343,6 +340,10 @@ pcre2_pattern_convert(). */ #define PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR 214 #define PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE 215 #define PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR 216 +#define PCRE2_ERROR_EXPECTED_CAPTURE_GROUP 217 +#define PCRE2_ERROR_MISSING_OPENING_PARENTHESIS 218 +#define PCRE2_ERROR_MISSING_NUMBER_TERMINATOR 219 +#define PCRE2_ERROR_NULL_ERROROFFSET 220 /* "Expected" matching error codes: no match and partial match. */ @@ -432,6 +433,11 @@ released, the numbers must not be changed. */ #define PCRE2_ERROR_JIT_UNSUPPORTED (-68) #define PCRE2_ERROR_REPLACECASE (-69) #define PCRE2_ERROR_TOOLARGEREPLACE (-70) +#define PCRE2_ERROR_DIFFSUBSPATTERN (-71) +#define PCRE2_ERROR_DIFFSUBSSUBJECT (-72) +#define PCRE2_ERROR_DIFFSUBSOFFSET (-73) +#define PCRE2_ERROR_DIFFSUBSOPTIONS (-74) +#define PCRE2_ERROR_BAD_BACKSLASH_K (-75) /* Request types for pcre2_pattern_info() */ @@ -484,6 +490,7 @@ released, the numbers must not be changed. */ #define PCRE2_CONFIG_NEVER_BACKSLASH_C 13 #define PCRE2_CONFIG_COMPILED_WIDTHS 14 #define PCRE2_CONFIG_TABLES_LENGTH 15 +#define PCRE2_CONFIG_EFFECTIVE_LINKSIZE 16 /* Optimization directives for pcre2_set_optimize(). For binary compatibility, only add to this list; do not renumber. */ @@ -743,14 +750,14 @@ PCRE2_EXP_DECL pcre2_match_data *PCRE2_CALL_CONVENTION \ PCRE2_EXP_DECL pcre2_match_data *PCRE2_CALL_CONVENTION \ pcre2_match_data_create_from_pattern(const pcre2_code *, \ pcre2_general_context *); \ +PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ + pcre2_match_data_free(pcre2_match_data *); \ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ pcre2_dfa_match(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ uint32_t, pcre2_match_data *, pcre2_match_context *, int *, PCRE2_SIZE); \ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ pcre2_match(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ uint32_t, pcre2_match_data *, pcre2_match_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_match_data_free(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SPTR PCRE2_CALL_CONVENTION \ pcre2_get_mark(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ @@ -762,7 +769,9 @@ PCRE2_EXP_DECL uint32_t PCRE2_CALL_CONVENTION \ PCRE2_EXP_DECL PCRE2_SIZE *PCRE2_CALL_CONVENTION \ pcre2_get_ovector_pointer(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ - pcre2_get_startchar(pcre2_match_data *); + pcre2_get_startchar(pcre2_match_data *); \ +PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ + pcre2_next_match(pcre2_match_data *, PCRE2_SIZE *, uint32_t *); /* Convenience functions for handling matched substrings. */ @@ -942,6 +951,7 @@ pcre2_compile are called by application code. */ #define pcre2_match_data_create PCRE2_SUFFIX(pcre2_match_data_create_) #define pcre2_match_data_create_from_pattern PCRE2_SUFFIX(pcre2_match_data_create_from_pattern_) #define pcre2_match_data_free PCRE2_SUFFIX(pcre2_match_data_free_) +#define pcre2_next_match PCRE2_SUFFIX(pcre2_next_match_) #define pcre2_pattern_convert PCRE2_SUFFIX(pcre2_pattern_convert_) #define pcre2_pattern_info PCRE2_SUFFIX(pcre2_pattern_info_) #define pcre2_serialize_decode PCRE2_SUFFIX(pcre2_serialize_decode_) diff --git a/libpcre/src/pcre2.h.in b/libpcre/src/pcre2.h.in index ca3f0b413..0dffe65fb 100644 --- a/libpcre/src/pcre2.h.in +++ b/libpcre/src/pcre2.h.in @@ -46,21 +46,17 @@ POSSIBILITY OF SUCH DAMAGE. #define PCRE2_PRERELEASE @PCRE2_PRERELEASE@ #define PCRE2_DATE @PCRE2_DATE@ -/* When an application links to a PCRE DLL in Windows, the symbols that are +/* When an application links to a PCRE2 DLL in Windows, the symbols that are imported have to be identified as such. When building PCRE2, the appropriate -export setting is defined in pcre2_internal.h, which includes this file. So we -don't change existing definitions of PCRE2_EXP_DECL. */ +export setting is defined in pcre2_internal.h, which includes this file. So, we +don't change existing definitions of PCRE2_EXP_DECL. -#if defined(_WIN32) && !defined(PCRE2_STATIC) -# ifndef PCRE2_EXP_DECL -# define PCRE2_EXP_DECL extern __declspec(dllimport) -# endif -#endif - -/* By default, we use the standard "extern" declarations. */ +By default, we use the standard "extern" declarations. */ #ifndef PCRE2_EXP_DECL -# ifdef __cplusplus +# if defined(_WIN32) && !defined(PCRE2_STATIC) +# define PCRE2_EXP_DECL extern __declspec(dllimport) +# elif defined __cplusplus # define PCRE2_EXP_DECL extern "C" # else # define PCRE2_EXP_DECL extern @@ -68,14 +64,15 @@ don't change existing definitions of PCRE2_EXP_DECL. */ #endif /* When compiling with the MSVC compiler, it is sometimes necessary to include -a "calling convention" before exported function names. (This is secondhand -information; I know nothing about MSVC myself). For example, something like +a "calling convention" before exported function names. For example: void __cdecl function(....) -might be needed. In order so make this easy, all the exported functions have -PCRE2_CALL_CONVENTION just before their names. It is rarely needed; if not -set, we ensure here that it has no effect. */ +might be needed. In order to make this easy, all the exported functions have +PCRE2_CALL_CONVENTION just before their names. + +PCRE2 normally uses the platform's standard calling convention, so this should +not be set unless you know you need it. */ #ifndef PCRE2_CALL_CONVENTION #define PCRE2_CALL_CONVENTION @@ -343,6 +340,10 @@ pcre2_pattern_convert(). */ #define PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR 214 #define PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE 215 #define PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR 216 +#define PCRE2_ERROR_EXPECTED_CAPTURE_GROUP 217 +#define PCRE2_ERROR_MISSING_OPENING_PARENTHESIS 218 +#define PCRE2_ERROR_MISSING_NUMBER_TERMINATOR 219 +#define PCRE2_ERROR_NULL_ERROROFFSET 220 /* "Expected" matching error codes: no match and partial match. */ @@ -432,6 +433,11 @@ released, the numbers must not be changed. */ #define PCRE2_ERROR_JIT_UNSUPPORTED (-68) #define PCRE2_ERROR_REPLACECASE (-69) #define PCRE2_ERROR_TOOLARGEREPLACE (-70) +#define PCRE2_ERROR_DIFFSUBSPATTERN (-71) +#define PCRE2_ERROR_DIFFSUBSSUBJECT (-72) +#define PCRE2_ERROR_DIFFSUBSOFFSET (-73) +#define PCRE2_ERROR_DIFFSUBSOPTIONS (-74) +#define PCRE2_ERROR_BAD_BACKSLASH_K (-75) /* Request types for pcre2_pattern_info() */ @@ -484,6 +490,7 @@ released, the numbers must not be changed. */ #define PCRE2_CONFIG_NEVER_BACKSLASH_C 13 #define PCRE2_CONFIG_COMPILED_WIDTHS 14 #define PCRE2_CONFIG_TABLES_LENGTH 15 +#define PCRE2_CONFIG_EFFECTIVE_LINKSIZE 16 /* Optimization directives for pcre2_set_optimize(). For binary compatibility, only add to this list; do not renumber. */ @@ -743,14 +750,14 @@ PCRE2_EXP_DECL pcre2_match_data *PCRE2_CALL_CONVENTION \ PCRE2_EXP_DECL pcre2_match_data *PCRE2_CALL_CONVENTION \ pcre2_match_data_create_from_pattern(const pcre2_code *, \ pcre2_general_context *); \ +PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ + pcre2_match_data_free(pcre2_match_data *); \ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ pcre2_dfa_match(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ uint32_t, pcre2_match_data *, pcre2_match_context *, int *, PCRE2_SIZE); \ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ pcre2_match(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, \ uint32_t, pcre2_match_data *, pcre2_match_context *); \ -PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ - pcre2_match_data_free(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SPTR PCRE2_CALL_CONVENTION \ pcre2_get_mark(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ @@ -762,7 +769,9 @@ PCRE2_EXP_DECL uint32_t PCRE2_CALL_CONVENTION \ PCRE2_EXP_DECL PCRE2_SIZE *PCRE2_CALL_CONVENTION \ pcre2_get_ovector_pointer(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ - pcre2_get_startchar(pcre2_match_data *); + pcre2_get_startchar(pcre2_match_data *); \ +PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \ + pcre2_next_match(pcre2_match_data *, PCRE2_SIZE *, uint32_t *); /* Convenience functions for handling matched substrings. */ @@ -942,6 +951,7 @@ pcre2_compile are called by application code. */ #define pcre2_match_data_create PCRE2_SUFFIX(pcre2_match_data_create_) #define pcre2_match_data_create_from_pattern PCRE2_SUFFIX(pcre2_match_data_create_from_pattern_) #define pcre2_match_data_free PCRE2_SUFFIX(pcre2_match_data_free_) +#define pcre2_next_match PCRE2_SUFFIX(pcre2_next_match_) #define pcre2_pattern_convert PCRE2_SUFFIX(pcre2_pattern_convert_) #define pcre2_pattern_info PCRE2_SUFFIX(pcre2_pattern_info_) #define pcre2_serialize_decode PCRE2_SUFFIX(pcre2_serialize_decode_) diff --git a/libpcre/src/pcre2_auto_possess.c b/libpcre/src/pcre2_auto_possess.c index 6d7f27b69..408803246 100644 --- a/libpcre/src/pcre2_auto_possess.c +++ b/libpcre/src/pcre2_auto_possess.c @@ -38,17 +38,15 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains functions that scan a compiled pattern and change repeats into possessive repeats where possible. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - - #include "pcre2_internal.h" + + /* This macro represents the max size of list[] and that is used to keep track of UCD info in several places, it should be kept on sync with the value used by GenerateUcd.py */ @@ -264,8 +262,10 @@ switch(ptype) if (c < *p) return !negated; if (c == *p++) return negated; } + /* LCOV_EXCL_START */ PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ break; + /* LCOV_EXCL_STOP */ /* Haven't yet thought these through. */ @@ -806,21 +806,21 @@ for(;;) case OP_NOT_DIGIT: invert_bits = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_DIGIT: set2 = (const uint8_t *)(cb->cbits + cbit_digit); break; case OP_NOT_WHITESPACE: invert_bits = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_WHITESPACE: set2 = (const uint8_t *)(cb->cbits + cbit_space); break; case OP_NOT_WORDCHAR: invert_bits = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_WORDCHAR: set2 = (const uint8_t *)(cb->cbits + cbit_word); break; @@ -1103,7 +1103,7 @@ for(;;) case OP_NCLASS: if (chr > 255) return FALSE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CLASS: if (chr > 255) break; @@ -1141,8 +1141,10 @@ for(;;) if (list[1] == 0) return TRUE; } +/* LCOV_EXCL_START */ PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ return FALSE; /* Avoid compiler warnings */ +/* LCOV_EXCL_STOP */ } @@ -1181,11 +1183,13 @@ for (;;) { c = *code; + /* LCOV_EXCL_START */ if (c >= OP_TABLE_LENGTH) { PCRE2_DEBUG_UNREACHABLE(); return -1; /* Something gone wrong */ } + /* LCOV_EXCL_STOP */ if (c >= OP_STAR && c <= OP_TYPEPOSUPTO) { diff --git a/libpcre/src/pcre2_chartables.c.dist b/libpcre/src/pcre2_chartables.c.dist index 7362c3f23..29f920001 100644 --- a/libpcre/src/pcre2_chartables.c.dist +++ b/libpcre/src/pcre2_chartables.c.dist @@ -19,10 +19,6 @@ PCRE2 is configured with --enable-rebuild-chartables. However, you can run pcre2_dftables manually with the -L option to build tables using the LC_ALL locale. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" const uint8_t PRIV(default_tables)[] = { diff --git a/libpcre/src/pcre2_chartables.c.ebcdic-1047-nl15 b/libpcre/src/pcre2_chartables.c.ebcdic-1047-nl15 new file mode 100644 index 000000000..071a8f425 --- /dev/null +++ b/libpcre/src/pcre2_chartables.c.ebcdic-1047-nl15 @@ -0,0 +1,196 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* This file was automatically written by the pcre2_dftables auxiliary +program. It contains character tables that are used when no external +tables are passed to PCRE2 by the application that calls it. The tables +are used only for characters whose code values are less than 256, and +only relevant if not in UCP mode. */ + +/* This set of tables was written in the EBCDIC 1047 (NL 0x15) locale. */ + +/* The pcre2_ftables program (which is distributed with PCRE2) can be used +to build alternative versions of this file. This is necessary if you are +running in an EBCDIC environment, or if you want to default to a different +encoding, for example ISO-8859-1. When pcre2_dftables is run, it creates +these tables in the "C" locale by default. This happens automatically if +PCRE2 is configured with --enable-rebuild-chartables. However, you can run +pcre2_dftables manually with the -L option to build tables using the LC_ALL +locale. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "pcre2_internal.h" + +const uint8_t PRIV(default_tables)[] = { + +/* This table is a lower casing table. */ + + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99,100,101,102,103, + 104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119, + 120,121,122,123,124,125,126,127, + 128,129,130,131,132,133,134,135, + 136,137,138,139,140,141,142,143, + 144,145,146,147,148,149,150,151, + 152,153,154,155,156,157,158,159, + 160,161,162,163,164,165,166,167, + 168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183, + 184,185,186,187,188,189,190,191, + 192,129,130,131,132,133,134,135, + 136,137,202,203,204,205,206,207, + 208,145,146,147,148,149,150,151, + 152,153,218,219,220,221,222,223, + 224,225,162,163,164,165,166,167, + 168,169,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247, + 248,249,250,251,252,253,254,255, + +/* This table is a case flipping table. */ + + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99,100,101,102,103, + 104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119, + 120,121,122,123,124,125,126,127, + 128,193,194,195,196,197,198,199, + 200,201,138,139,140,141,142,143, + 144,209,210,211,212,213,214,215, + 216,217,154,155,156,157,158,159, + 160,161,226,227,228,229,230,231, + 232,233,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183, + 184,185,186,187,188,189,190,191, + 192,129,130,131,132,133,134,135, + 136,137,202,203,204,205,206,207, + 208,145,146,147,148,149,150,151, + 152,153,218,219,220,221,222,223, + 224,225,162,163,164,165,166,167, + 168,169,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247, + 248,249,250,251,252,253,254,255, + +/* This table contains bit maps for various character classes. Each map is 32 +bytes long and the bits run from the least significant end of each byte. The +classes that have their own maps are: space, xdigit, digit, upper, lower, word, +graph, print, punct, and cntrl. Other classes are built from combinations. */ + + 0x20,0x38,0x20,0x00,0x00,0x00,0x00,0x00, /* space */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* xdigit */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7e,0x00,0x00,0x00,0x00,0x00,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* digit */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* upper */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* lower */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* word */ + 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* graph */ + 0x00,0xf8,0x01,0xfc,0x03,0xf8,0x00,0xfe, + 0xfe,0x03,0xfe,0x03,0xfe,0x23,0x00,0x20, + 0xff,0x03,0xff,0x03,0xfd,0x03,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* print */ + 0x01,0xf8,0x01,0xfc,0x03,0xf8,0x00,0xfe, + 0xfe,0x03,0xfe,0x03,0xfe,0x23,0x00,0x20, + 0xff,0x03,0xff,0x03,0xfd,0x03,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* punct */ + 0x00,0xf8,0x01,0xfc,0x03,0xf8,0x00,0xfe, + 0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x20, + 0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00, + + 0xaf,0xf8,0x6f,0xf3,0xc0,0xe0,0x84,0xb0, /* cntrl */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +/* This table identifies various classes of character by individual bits: + 0x01 white space character + 0x02 letter + 0x04 lower case letter + 0x08 decimal digit + 0x10 word (alphanumeric or '_') +*/ + + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /* 0- 7 */ + 0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00, /* 8- 15 */ + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /* 16- 23 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - ' */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* ( - / */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0 - 7 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 8 - ? */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* @ - G */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* H - O */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* P - W */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* X - _ */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* ` - g */ + 0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00, /* h - o */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* p - w */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* x -127 */ + 0x00,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* 128-135 */ + 0x16,0x16,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */ + 0x00,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* 144-151 */ + 0x16,0x16,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */ + 0x00,0x00,0x16,0x16,0x16,0x16,0x16,0x16, /* 160-167 */ + 0x16,0x16,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */ + 0x00,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* 192-199 */ + 0x12,0x12,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */ + 0x00,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* 208-215 */ + 0x12,0x12,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */ + 0x00,0x00,0x12,0x12,0x12,0x12,0x12,0x12, /* 224-231 */ + 0x12,0x12,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */ + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, /* 240-247 */ + 0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */ + +/* End of pcre2_chartables.c */ diff --git a/libpcre/src/pcre2_chartables.c.ebcdic-1047-nl25 b/libpcre/src/pcre2_chartables.c.ebcdic-1047-nl25 new file mode 100644 index 000000000..99ba81b20 --- /dev/null +++ b/libpcre/src/pcre2_chartables.c.ebcdic-1047-nl25 @@ -0,0 +1,196 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* This file was automatically written by the pcre2_dftables auxiliary +program. It contains character tables that are used when no external +tables are passed to PCRE2 by the application that calls it. The tables +are used only for characters whose code values are less than 256, and +only relevant if not in UCP mode. */ + +/* This set of tables was written in the EBCDIC 1047 (NL 0x25) locale. */ + +/* The pcre2_ftables program (which is distributed with PCRE2) can be used +to build alternative versions of this file. This is necessary if you are +running in an EBCDIC environment, or if you want to default to a different +encoding, for example ISO-8859-1. When pcre2_dftables is run, it creates +these tables in the "C" locale by default. This happens automatically if +PCRE2 is configured with --enable-rebuild-chartables. However, you can run +pcre2_dftables manually with the -L option to build tables using the LC_ALL +locale. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "pcre2_internal.h" + +const uint8_t PRIV(default_tables)[] = { + +/* This table is a lower casing table. */ + + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99,100,101,102,103, + 104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119, + 120,121,122,123,124,125,126,127, + 128,129,130,131,132,133,134,135, + 136,137,138,139,140,141,142,143, + 144,145,146,147,148,149,150,151, + 152,153,154,155,156,157,158,159, + 160,161,162,163,164,165,166,167, + 168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183, + 184,185,186,187,188,189,190,191, + 192,129,130,131,132,133,134,135, + 136,137,202,203,204,205,206,207, + 208,145,146,147,148,149,150,151, + 152,153,218,219,220,221,222,223, + 224,225,162,163,164,165,166,167, + 168,169,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247, + 248,249,250,251,252,253,254,255, + +/* This table is a case flipping table. */ + + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99,100,101,102,103, + 104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119, + 120,121,122,123,124,125,126,127, + 128,193,194,195,196,197,198,199, + 200,201,138,139,140,141,142,143, + 144,209,210,211,212,213,214,215, + 216,217,154,155,156,157,158,159, + 160,161,226,227,228,229,230,231, + 232,233,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183, + 184,185,186,187,188,189,190,191, + 192,129,130,131,132,133,134,135, + 136,137,202,203,204,205,206,207, + 208,145,146,147,148,149,150,151, + 152,153,218,219,220,221,222,223, + 224,225,162,163,164,165,166,167, + 168,169,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247, + 248,249,250,251,252,253,254,255, + +/* This table contains bit maps for various character classes. Each map is 32 +bytes long and the bits run from the least significant end of each byte. The +classes that have their own maps are: space, xdigit, digit, upper, lower, word, +graph, print, punct, and cntrl. Other classes are built from combinations. */ + + 0x20,0x38,0x00,0x00,0x20,0x00,0x00,0x00, /* space */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* xdigit */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x7e,0x00,0x00,0x00,0x00,0x00,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* digit */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* upper */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* lower */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* word */ + 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0x00,0x00, + 0xfe,0x03,0xfe,0x03,0xfc,0x03,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* graph */ + 0x00,0xf8,0x01,0xfc,0x03,0xf8,0x00,0xfe, + 0xfe,0x03,0xfe,0x03,0xfe,0x23,0x00,0x20, + 0xff,0x03,0xff,0x03,0xfd,0x03,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* print */ + 0x01,0xf8,0x01,0xfc,0x03,0xf8,0x00,0xfe, + 0xfe,0x03,0xfe,0x03,0xfe,0x23,0x00,0x20, + 0xff,0x03,0xff,0x03,0xfd,0x03,0xff,0x03, + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* punct */ + 0x00,0xf8,0x01,0xfc,0x03,0xf8,0x00,0xfe, + 0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x20, + 0x01,0x00,0x01,0x00,0x01,0x00,0x00,0x00, + + 0xaf,0xf8,0x4f,0xf3,0xe0,0xe0,0x84,0xb0, /* cntrl */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + +/* This table identifies various classes of character by individual bits: + 0x01 white space character + 0x02 letter + 0x04 lower case letter + 0x08 decimal digit + 0x10 word (alphanumeric or '_') +*/ + + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /* 0- 7 */ + 0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00, /* 8- 15 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 16- 23 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */ + 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /* - ' */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* ( - / */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0 - 7 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 8 - ? */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* @ - G */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* H - O */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* P - W */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* X - _ */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* ` - g */ + 0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00, /* h - o */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* p - w */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* x -127 */ + 0x00,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* 128-135 */ + 0x16,0x16,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */ + 0x00,0x16,0x16,0x16,0x16,0x16,0x16,0x16, /* 144-151 */ + 0x16,0x16,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */ + 0x00,0x00,0x16,0x16,0x16,0x16,0x16,0x16, /* 160-167 */ + 0x16,0x16,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */ + 0x00,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* 192-199 */ + 0x12,0x12,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */ + 0x00,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* 208-215 */ + 0x12,0x12,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */ + 0x00,0x00,0x12,0x12,0x12,0x12,0x12,0x12, /* 224-231 */ + 0x12,0x12,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */ + 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, /* 240-247 */ + 0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */ + +/* End of pcre2_chartables.c */ diff --git a/libpcre/src/pcre2_chkdint.c b/libpcre/src/pcre2_chkdint.c index 708302369..7aeb64057 100644 --- a/libpcre/src/pcre2_chkdint.c +++ b/libpcre/src/pcre2_chkdint.c @@ -37,16 +37,16 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This file contains functions to implement checked integer operation */ -#ifndef PCRE2_PCRE2TEST -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#ifndef PCRE2_PCRE2TEST #include "pcre2_internal.h" #endif + + /************************************************* * Checked Integer Multiplication * *************************************************/ diff --git a/libpcre/src/pcre2_compile.c b/libpcre/src/pcre2_compile.c index 0ffac8939..f126e41b7 100644 --- a/libpcre/src/pcre2_compile.c +++ b/libpcre/src/pcre2_compile.c @@ -39,16 +39,14 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include "pcre2_compile.h" + + #define NLBLOCK cb /* Block containing newline information */ #define PSSTART start_pattern /* Field containing processed string start */ #define PSEND end_pattern /* Field containing processed string end */ -#include "pcre2_compile.h" - /* In rare error cases debugging might require calling pcre2_printint(). */ #if 0 @@ -57,7 +55,15 @@ POSSIBILITY OF SUCH DAMAGE. #else #define PRINTABLE(c) ((c) >= 32 && (c) < 127) #endif -#include "pcre2_printint.c" +#define CHAR_OUTPUT(c) (c) +#define CHAR_OUTPUT_HEX(c) (c) +#define CHAR_INPUT(c) (c) +#define CHAR_INPUT_HEX(c) (c) +#include "pcre2_printint_inc.h" +#undef PRINTABLE +#undef CHAR_OUTPUT +#undef CHAR_OUTPUT_HEX +#undef CHAR_INPUT #define DEBUG_CALL_PRINTINT #endif @@ -84,30 +90,6 @@ by defining macros in order to minimize #if usage. */ #endif #endif -/* Macros to store and retrieve a PCRE2_SIZE value in the parsed pattern, which -consists of uint32_t elements. Assume that if uint32_t can't hold it, two of -them will be able to (i.e. assume a 64-bit world). */ - -#if PCRE2_SIZE_MAX <= UINT32_MAX -#define PUTOFFSET(s,p) *p++ = s -#define GETOFFSET(s,p) s = *p++ -#define GETPLUSOFFSET(s,p) s = *(++p) -#define READPLUSOFFSET(s,p) s = p[1] -#define SKIPOFFSET(p) p++ -#define SIZEOFFSET 1 -#else -#define PUTOFFSET(s,p) \ - { *p++ = (uint32_t)(s >> 32); *p++ = (uint32_t)(s & 0xffffffff); } -#define GETOFFSET(s,p) \ - { s = ((PCRE2_SIZE)p[0] << 32) | (PCRE2_SIZE)p[1]; p += 2; } -#define GETPLUSOFFSET(s,p) \ - { s = ((PCRE2_SIZE)p[1] << 32) | (PCRE2_SIZE)p[2]; p += 2; } -#define READPLUSOFFSET(s,p) \ - { s = ((PCRE2_SIZE)p[1] << 32) | (PCRE2_SIZE)p[2]; } -#define SKIPOFFSET(p) p += 2 -#define SIZEOFFSET 2 -#endif - /* Function definitions to allow mutual recursion */ static int @@ -216,8 +198,8 @@ static unsigned char meta_extra_lengths[] = { 3, /* META_COND_VERSION */ SIZEOFFSET, /* META_OFFSET */ 0, /* META_SCS */ - 1, /* META_SCS_NAME */ - 1, /* META_SCS_NUMBER */ + 1, /* META_CAPTURE_NAME */ + 1, /* META_CAPTURE_NUMBER */ 0, /* META_DOLLAR */ 0, /* META_DOT */ 0, /* META_ESCAPE - one more for ESC_P and ESC_p */ @@ -400,10 +382,10 @@ static const short int escapes[] = { /* 4 */ 0, /* 5 */ 0, /* 6 */ 0, /* 7 */ 0, /* 8 */ 0, /* 9 */ 0, - /* : */ CHAR_COLON, /* ; */ CHAR_SEMICOLON, - /* < */ CHAR_LESS_THAN_SIGN, /* = */ CHAR_EQUALS_SIGN, - /* > */ CHAR_GREATER_THAN_SIGN, /* ? */ CHAR_QUESTION_MARK, - /* @ */ CHAR_COMMERCIAL_AT, /* A */ -ESC_A, + /* : */ ESCAPES_FIRST+0x0a, /* ; */ ESCAPES_FIRST+0x0b, + /* < */ ESCAPES_FIRST+0x0c, /* = */ ESCAPES_FIRST+0x0d, + /* > */ ESCAPES_FIRST+0x0e, /* ? */ ESCAPES_FIRST+0x0f, + /* @ */ ESCAPES_FIRST+0x10, /* A */ -ESC_A, /* B */ -ESC_B, /* C */ -ESC_C, /* D */ -ESC_D, /* E */ -ESC_E, /* F */ 0, /* G */ -ESC_G, @@ -416,10 +398,10 @@ static const short int escapes[] = { /* T */ 0, /* U */ 0, /* V */ -ESC_V, /* W */ -ESC_W, /* X */ -ESC_X, /* Y */ 0, - /* Z */ -ESC_Z, /* [ */ CHAR_LEFT_SQUARE_BRACKET, - /* \ */ CHAR_BACKSLASH, /* ] */ CHAR_RIGHT_SQUARE_BRACKET, - /* ^ */ CHAR_CIRCUMFLEX_ACCENT, /* _ */ CHAR_UNDERSCORE, - /* ` */ CHAR_GRAVE_ACCENT, /* a */ CHAR_BEL, + /* Z */ -ESC_Z, /* [ */ ESCAPES_FIRST+0x2b, + /* \ */ ESCAPES_FIRST+0x2c, /* ] */ ESCAPES_FIRST+0x2d, + /* ^ */ ESCAPES_FIRST+0x2e, /* _ */ ESCAPES_FIRST+0x2f, + /* ` */ ESCAPES_FIRST+0x30, /* a */ CHAR_BEL, /* b */ -ESC_b, /* c */ 0, /* d */ -ESC_d, /* e */ CHAR_ESC, /* f */ CHAR_FF, /* g */ 0, @@ -438,43 +420,94 @@ static const short int escapes[] = { #else /* This is the "abnormal" table for EBCDIC systems without UTF-8 support. -It runs from 'a' to '9'. For some minimal testing of EBCDIC features, the code -is sometimes compiled on an ASCII system. In this case, we must not use CHAR_a -because it is defined as 'a', which of course picks up the ASCII value. */ +It runs from 'a' to '9'. Our EBCDIC support can be provided via the compiler, +which can interpret character literals like 'a' or '[' in an EBCDIC codepage; +in this case, there is wide variance between codepages on the interpretation of +characters between the letters ('[' and '{' and so on are placed in all sorts of +different positions in the table). Thankfully however, all EBCDIC codepages +place the letters and digits in the same location, so we hardcode that here. +Our EBCDIC support can also be provided via numeric literals instead of +character literals, so either way, 'CHAR_a' will be 0x81 when PCRE2 is compiled +in EBCDIC mode. */ -#if 'a' == 0x81 /* Check for a real EBCDIC environment */ #define ESCAPES_FIRST CHAR_a #define ESCAPES_LAST CHAR_9 #define UPPER_CASE(c) (c+64) -#else /* Testing in an ASCII environment */ -#define ESCAPES_FIRST ((unsigned char)'\x81') /* EBCDIC 'a' */ -#define ESCAPES_LAST ((unsigned char)'\xf9') /* EBCDIC '9' */ -#define UPPER_CASE(c) (c-32) -#endif static const short int escapes[] = { -/* 80 */ CHAR_BEL, -ESC_b, 0, -ESC_d, CHAR_ESC, CHAR_FF, 0, -/* 88 */ -ESC_h, 0, 0, '{', 0, 0, 0, 0, -/* 90 */ 0, 0, -ESC_k, 0, 0, CHAR_LF, 0, -ESC_p, -/* 98 */ 0, CHAR_CR, 0, '}', 0, 0, 0, 0, -/* A0 */ 0, '~', -ESC_s, CHAR_HT, 0, -ESC_v, -ESC_w, 0, -/* A8 */ 0, -ESC_z, 0, 0, 0, '[', 0, 0, -/* B0 */ 0, 0, 0, 0, 0, 0, 0, 0, -/* B8 */ 0, 0, 0, 0, 0, ']', '=', '-', -/* C0 */ '{', -ESC_A, -ESC_B, -ESC_C, -ESC_D, -ESC_E, 0, -ESC_G, -/* C8 */ -ESC_H, 0, 0, 0, 0, 0, 0, 0, -/* D0 */ '}', 0, -ESC_K, 0, 0, -ESC_N, 0, -ESC_P, -/* D8 */ -ESC_Q, -ESC_R, 0, 0, 0, 0, 0, 0, -/* E0 */ '\\', 0, -ESC_S, 0, 0, -ESC_V, -ESC_W, -ESC_X, -/* E8 */ 0, -ESC_Z, 0, 0, 0, 0, 0, 0, -/* F0 */ 0, 0, 0, 0, 0, 0, 0, 0, -/* F8 */ 0, 0 + /* 0x81 a */ CHAR_BEL, /* 0x82 b */ -ESC_b, + /* 0x83 c */ 0, /* 0x84 d */ -ESC_d, + /* 0x85 e */ CHAR_ESC, /* 0x86 f */ CHAR_FF, + /* 0x87 g */ 0, /* 0x88 h */ -ESC_h, + /* 0x89 i */ 0, /* 0x8a */ ESCAPES_FIRST+0x09, + /* 0x8b */ ESCAPES_FIRST+0x0a, /* 0x8c */ ESCAPES_FIRST+0x0b, + /* 0x8d */ ESCAPES_FIRST+0x0c, /* 0x8e */ ESCAPES_FIRST+0x0d, + /* 0x8f */ ESCAPES_FIRST+0x0e, /* 0x90 */ ESCAPES_FIRST+0x0f, + /* 0x91 j */ 0, /* 0x92 k */ -ESC_k, + /* 0x93 l */ 0, /* 0x94 m */ 0, + /* 0x95 n */ CHAR_LF, /* 0x96 o */ 0, + /* 0x97 p */ -ESC_p, /* 0x98 q */ 0, + /* 0x99 r */ CHAR_CR, /* 0x9a */ ESCAPES_FIRST+0x19, + /* 0x9b */ ESCAPES_FIRST+0x1a, /* 0x9c */ ESCAPES_FIRST+0x1b, + /* 0x9d */ ESCAPES_FIRST+0x1c, /* 0x9e */ ESCAPES_FIRST+0x1d, + /* 0x9f */ ESCAPES_FIRST+0x1e, /* 0xa0 */ ESCAPES_FIRST+0x1f, + /* 0xa1 */ ESCAPES_FIRST+0x20, /* 0xa2 s */ -ESC_s, + /* 0xa3 t */ CHAR_HT, /* 0xa4 u */ 0, + /* 0xa5 v */ -ESC_v, /* 0xa6 w */ -ESC_w, + /* 0xa7 x */ 0, /* 0xa8 y */ 0, + /* 0xa9 z */ -ESC_z, /* 0xaa */ ESCAPES_FIRST+0x29, + /* 0xab */ ESCAPES_FIRST+0x2a, /* 0xac */ ESCAPES_FIRST+0x2b, + /* 0xad */ ESCAPES_FIRST+0x2c, /* 0xae */ ESCAPES_FIRST+0x2d, + /* 0xaf */ ESCAPES_FIRST+0x2e, /* 0xb0 */ ESCAPES_FIRST+0x2f, + /* 0xb1 */ ESCAPES_FIRST+0x30, /* 0xb2 */ ESCAPES_FIRST+0x31, + /* 0xb3 */ ESCAPES_FIRST+0x32, /* 0xb4 */ ESCAPES_FIRST+0x33, + /* 0xb5 */ ESCAPES_FIRST+0x34, /* 0xb6 */ ESCAPES_FIRST+0x35, + /* 0xb7 */ ESCAPES_FIRST+0x36, /* 0xb8 */ ESCAPES_FIRST+0x37, + /* 0xb9 */ ESCAPES_FIRST+0x38, /* 0xba */ ESCAPES_FIRST+0x39, + /* 0xbb */ ESCAPES_FIRST+0x3a, /* 0xbc */ ESCAPES_FIRST+0x3b, + /* 0xbd */ ESCAPES_FIRST+0x3c, /* 0xbe */ ESCAPES_FIRST+0x3d, + /* 0xbf */ ESCAPES_FIRST+0x3e, /* 0xc0 */ ESCAPES_FIRST+0x3f, + /* 0xc1 A */ -ESC_A, /* 0xc2 B */ -ESC_B, + /* 0xc3 C */ -ESC_C, /* 0xc4 D */ -ESC_D, + /* 0xc5 E */ -ESC_E, /* 0xc6 F */ 0, + /* 0xc7 G */ -ESC_G, /* 0xc8 H */ -ESC_H, + /* 0xc9 I */ 0, /* 0xca */ ESCAPES_FIRST+0x49, + /* 0xcb */ ESCAPES_FIRST+0x4a, /* 0xcc */ ESCAPES_FIRST+0x4b, + /* 0xcd */ ESCAPES_FIRST+0x4c, /* 0xce */ ESCAPES_FIRST+0x4d, + /* 0xcf */ ESCAPES_FIRST+0x4e, /* 0xd0 */ ESCAPES_FIRST+0x4f, + /* 0xd1 J */ 0, /* 0xd2 K */ -ESC_K, + /* 0xd3 L */ 0, /* 0xd4 M */ 0, + /* 0xd5 N */ -ESC_N, /* 0xd6 O */ 0, + /* 0xd7 P */ -ESC_P, /* 0xd8 Q */ -ESC_Q, + /* 0xd9 R */ -ESC_R, /* 0xda */ ESCAPES_FIRST+0x59, + /* 0xdb */ ESCAPES_FIRST+0x5a, /* 0xdc */ ESCAPES_FIRST+0x5b, + /* 0xdd */ ESCAPES_FIRST+0x5c, /* 0xde */ ESCAPES_FIRST+0x5d, + /* 0xdf */ ESCAPES_FIRST+0x5e, /* 0xe0 */ ESCAPES_FIRST+0x5f, + /* 0xe1 */ ESCAPES_FIRST+0x60, /* 0xe2 S */ -ESC_S, + /* 0xe3 T */ 0, /* 0xe4 U */ 0, + /* 0xe5 V */ -ESC_V, /* 0xe6 W */ -ESC_W, + /* 0xe7 X */ -ESC_X, /* 0xe8 Y */ 0, + /* 0xe9 Z */ -ESC_Z, /* 0xea */ ESCAPES_FIRST+0x69, + /* 0xeb */ ESCAPES_FIRST+0x6a, /* 0xec */ ESCAPES_FIRST+0x6b, + /* 0xed */ ESCAPES_FIRST+0x6c, /* 0xee */ ESCAPES_FIRST+0x6d, + /* 0xef */ ESCAPES_FIRST+0x6e, /* 0xf0 0 */ 0, + /* 0xf1 1 */ 0, /* 0xf2 2 */ 0, + /* 0xf3 3 */ 0, /* 0xf4 4 */ 0, + /* 0xf5 5 */ 0, /* 0xf6 6 */ 0, + /* 0xf7 7 */ 0, /* 0xf8 8 */ 0, + /* 0xf9 9 */ 0, }; /* We also need a table of characters that may follow \c in an EBCDIC environment for characters 0-31. */ -static unsigned char ebcdic_escape_c[] = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"; +static unsigned char ebcdic_escape_c[] = { + CHAR_COMMERCIAL_AT, CHAR_A, CHAR_B, CHAR_C, CHAR_D, CHAR_E, CHAR_F, CHAR_G, + CHAR_H, CHAR_I, CHAR_J, CHAR_K, CHAR_L, CHAR_M, CHAR_N, CHAR_O, CHAR_P, + CHAR_Q, CHAR_R, CHAR_S, CHAR_T, CHAR_U, CHAR_V, CHAR_W, CHAR_X, CHAR_Y, + CHAR_Z, CHAR_LEFT_SQUARE_BRACKET, CHAR_BACKSLASH, CHAR_RIGHT_SQUARE_BRACKET, + CHAR_CIRCUMFLEX_ACCENT, CHAR_UNDERSCORE +}; #endif /* EBCDIC */ @@ -1037,12 +1070,12 @@ for (;;) fprintf(stderr, "META (*scan_substring:"); break; - case META_SCS_NAME: - fprintf(stderr, "META_SCS_NAME length=%d relative_offset=%d", *pptr++, (int)meta_arg); + case META_CAPTURE_NAME: + fprintf(stderr, "META_CAPTURE_NAME length=%d relative_offset=%d", *pptr++, (int)meta_arg); break; - case META_SCS_NUMBER: - fprintf(stderr, "META_SCS_NUMBER %d relative_offset=%d", *pptr++, (int)meta_arg); + case META_CAPTURE_NUMBER: + fprintf(stderr, "META_CAPTURE_NUMBER %d relative_offset=%d", *pptr++, (int)meta_arg); break; case META_MARK: @@ -1533,6 +1566,13 @@ else if ((i = escapes[c - ESCAPES_FIRST]) != 0) goto COME_FROM_NU; } #endif + + /* Improve error offset. */ + ptr = p + 2; + while (ptr < ptrend && XDIGIT(*ptr) != 0xff) ptr++; + while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; + if (ptr < ptrend && *ptr == CHAR_RIGHT_CURLY_BRACKET) ptr++; + *errorcodeptr = ERR93; } @@ -1541,6 +1581,7 @@ else if ((i = escapes[c - ESCAPES_FIRST]) != 0) else if (isclass || cb == NULL) { + ptr++; /* Skip over the opening brace */ *errorcodeptr = ERR37; } @@ -1551,7 +1592,10 @@ else if ((i = escapes[c - ESCAPES_FIRST]) != 0) { if (!read_repeat_counts(&p, ptrend, NULL, NULL, errorcodeptr) && *errorcodeptr == 0) + { + ptr++; /* Skip over the opening brace */ *errorcodeptr = ERR37; + } } } } @@ -1572,11 +1616,11 @@ else if (cb == NULL) { - if (c < CHAR_0 || - (c > CHAR_9 && (c != CHAR_c && c != CHAR_o && c != CHAR_x && c != CHAR_g))) + if (!(c >= CHAR_0 && c <= CHAR_9) && c != CHAR_c && c != CHAR_o && + c != CHAR_x && c != CHAR_g) { *errorcodeptr = ERR3; - return 0; + goto EXIT; } alt_bsux = FALSE; /* Do not modify \x handling */ } @@ -1601,7 +1645,9 @@ else because otherwise \u{ 12} (for example) would be treated as u{12}. */ case CHAR_u: - if (!alt_bsux) *errorcodeptr = ERR37; else + if (!alt_bsux) + *errorcodeptr = ERR37; + else { uint32_t xc; @@ -1727,8 +1773,8 @@ else if (p >= ptrend || *p != CHAR_GREATER_THAN_SIGN) { - /* not advancing ptr; report error at the \g character */ - *errorcodeptr = ERR57; + ptr = p; + *errorcodeptr = ERR119; /* Missing terminator for number */ break; } @@ -1764,8 +1810,8 @@ else if (p >= ptrend || *p != CHAR_RIGHT_CURLY_BRACKET) { - /* not advancing ptr; report error at the \g character */ - *errorcodeptr = ERR57; + ptr = p; + *errorcodeptr = ERR119; /* Missing terminator for number */ break; } ptr = p + 1; @@ -1890,7 +1936,7 @@ else if (c >= CHAR_8) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* \0 always starts an octal number, but we may drop through to here with a larger first octal digit. The original code used just to take the least @@ -1922,12 +1968,12 @@ else with optional spaces or tabs after { and before }. */ case CHAR_o: - if (ptr >= ptrend || *ptr++ != CHAR_LEFT_CURLY_BRACKET) + if (ptr >= ptrend || *ptr != CHAR_LEFT_CURLY_BRACKET) { - ptr--; *errorcodeptr = ERR55; break; } + ptr++; while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; if (ptr >= ptrend || *ptr == CHAR_RIGHT_CURLY_BRACKET) @@ -1962,19 +2008,19 @@ else while (ptr < ptrend && *ptr >= CHAR_0 && *ptr <= CHAR_7) ptr++; *errorcodeptr = ERR34; } - else if (ptr < ptrend && *ptr++ == CHAR_RIGHT_CURLY_BRACKET) + else if (utf && c >= 0xd800 && c <= 0xdfff && + (xoptions & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0) { - if (utf && c >= 0xd800 && c <= 0xdfff && - (xoptions & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0) - { - ptr--; - *errorcodeptr = ERR73; - } + *errorcodeptr = ERR73; + } + else if (ptr < ptrend && *ptr == CHAR_RIGHT_CURLY_BRACKET) + { + ptr++; } else { - ptr--; *errorcodeptr = ERR64; + goto ESCAPE_FAILED_FORWARD; } break; @@ -2043,14 +2089,14 @@ else while (ptr < ptrend && XDIGIT(*ptr) != 0xff) ptr++; *errorcodeptr = ERR34; } - else if (ptr < ptrend && *ptr++ == CHAR_RIGHT_CURLY_BRACKET) + else if (utf && c >= 0xd800 && c <= 0xdfff && + (xoptions & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0) { - if (utf && c >= 0xd800 && c <= 0xdfff && - (xoptions & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) == 0) - { - ptr--; - *errorcodeptr = ERR73; - } + *errorcodeptr = ERR73; + } + else if (ptr < ptrend && *ptr == CHAR_RIGHT_CURLY_BRACKET) + { + ptr++; } /* If the sequence of hex digits (followed by optional space) does not @@ -2060,8 +2106,8 @@ else else { - ptr--; *errorcodeptr = ERR67; + goto ESCAPE_FAILED_FORWARD; } } /* End of \x{} processing */ @@ -2113,11 +2159,7 @@ else For testing the EBCDIC handling of \c in an ASCII environment, recognize the EBCDIC value of 'c' explicitly. */ -#if defined EBCDIC && 'a' != 0x81 - case 0x83: -#else case CHAR_c: -#endif if (ptr >= ptrend) { *errorcodeptr = ERR2; @@ -2132,7 +2174,7 @@ else if (c < 32 || c > 126) /* Excludes all non-printable ASCII */ { *errorcodeptr = ERR68; - break; + goto ESCAPE_FAILED_FORWARD; } c ^= 0x40; @@ -2143,14 +2185,20 @@ else #else if (c == CHAR_QUESTION_MARK) - c = ('\\' == 188 && '`' == 74)? 0x5f : 0xff; + c = (CHAR_BACKSLASH == 188 && CHAR_GRAVE_ACCENT == 74)? 0x5f : 0xff; else { for (i = 0; i < 32; i++) { if (c == ebcdic_escape_c[i]) break; } - if (i < 32) c = i; else *errorcodeptr = ERR68; + if (i < 32) + c = i; + else + { + *errorcodeptr = ERR68; + goto ESCAPE_FAILED_FORWARD; + } } #endif /* EBCDIC */ @@ -2162,16 +2210,25 @@ else default: *errorcodeptr = ERR3; - *ptrptr = ptr - 1; /* Point to the character at fault */ - return 0; + break; } } /* Set the pointer to the next character before returning. */ +EXIT: *ptrptr = ptr; *chptr = c; return escape; + +/* Some errors need to indicate the next character. */ + +ESCAPE_FAILED_FORWARD: +ptr++; +#ifdef SUPPORT_UNICODE +if (utf) FORWARDCHARTEST(ptr, ptrend); +#endif +goto EXIT; } @@ -2188,6 +2245,7 @@ after the final code unit of the escape sequence. Arguments: ptrptr the pattern position pointer + utf true if the input is UTF-encoded negptr a boolean that is set TRUE for negation else FALSE ptypeptr an unsigned int that is set to the type value pdataptr an unsigned int that is set to the detailed property value @@ -2198,18 +2256,23 @@ Returns: TRUE if the type value was found, or FALSE for an invalid type */ static BOOL -get_ucp(PCRE2_SPTR *ptrptr, BOOL *negptr, uint16_t *ptypeptr, +get_ucp(PCRE2_SPTR *ptrptr, BOOL utf, BOOL *negptr, uint16_t *ptypeptr, uint16_t *pdataptr, int *errorcodeptr, compile_block *cb) { -PCRE2_UCHAR c; -PCRE2_SIZE i, bot, top; +uint32_t c; +ptrdiff_t i; +PCRE2_SIZE bot, top; PCRE2_SPTR ptr = *ptrptr; PCRE2_UCHAR name[50]; PCRE2_UCHAR *vptr = NULL; uint16_t ptscript = PT_NOTSCRIPT; +#ifndef MAYBE_UTF_MULTI +(void)utf; /* Avoid compiler warning */ +#endif + if (ptr >= cb->end_pattern) goto ERROR_RETURN; -c = *ptr++; +GETCHARINCTEST(c, ptr); *negptr = FALSE; /* \P or \p can be followed by a name in {}, optionally preceded by ^ for @@ -2230,15 +2293,14 @@ if (c == CHAR_LEFT_CURLY_BRACKET) REDO: if (ptr >= cb->end_pattern) goto ERROR_RETURN; - c = *ptr++; + GETCHARINCTEST(c, ptr); /* Skip ignorable Unicode characters. */ - while (c == CHAR_UNDERSCORE || c == CHAR_MINUS || c == CHAR_SPACE || - (c >= CHAR_HT && c <= CHAR_CR)) + if (c == CHAR_UNDERSCORE || c == CHAR_MINUS || c == CHAR_SPACE || + (c >= CHAR_HT && c <= CHAR_CR)) { - if (ptr >= cb->end_pattern) goto ERROR_RETURN; - c = *ptr++; + goto REDO; } /* The first significant character being circumflex negates the meaning of @@ -2506,7 +2568,7 @@ return -1; the name of a subpattern or a (*VERB) or an (*alpha_assertion). The initial pointer must be to the preceding character. If that character is '*' we are reading a verb or alpha assertion name. The pointer is updated to point after -the name, for a VERB or alpha assertion name, or after tha name's terminator +the name, for a VERB or alpha assertion name, or after the name's terminator for a subpattern name. Returning both the offset and the name pointer is redundant information, but some callers use one and some the other, so it is simplest just to return both. When the name is in braces, spaces and tabs are @@ -2559,12 +2621,14 @@ by Unicode properties, and underscores, but must not start with a digit. */ if (utf && is_group) { uint32_t c, type; + PCRE2_SPTR p = ptr; - GETCHAR(c, ptr); + GETCHARINC(c, p); /* Peek at next character */ type = UCD_CHARTYPE(c); if (type == ucp_Nd) { + ptr = p; *errorcodeptr = ERR44; goto FAILED; } @@ -2573,10 +2637,9 @@ if (utf && is_group) { if (type != ucp_Nd && PRIV(ucp_gentype)[type] != ucp_L && c != CHAR_UNDERSCORE) break; - ptr++; - FORWARDCHARTEST(ptr, ptrend); - if (ptr >= ptrend) break; - GETCHAR(c, ptr); + ptr = p; /* Accept character and peek again */ + if (p >= ptrend) break; + GETCHARINC(c, p); type = UCD_CHARTYPE(c); } } @@ -2592,6 +2655,7 @@ won't be recognized. */ { if (is_group && IS_DIGIT(*ptr)) { + ++ptr; *errorcodeptr = ERR44; goto FAILED; } @@ -2604,7 +2668,7 @@ won't be recognized. */ /* Check name length */ -if (ptr > *nameptr + MAX_NAME_SIZE) +if (ptr - *nameptr > MAX_NAME_SIZE) { *errorcodeptr = ERR48; goto FAILED; @@ -2623,12 +2687,15 @@ if (is_group) } if (is_braced) while (ptr < ptrend && (*ptr == CHAR_SPACE || *ptr == CHAR_HT)) ptr++; - if (ptr >= ptrend || *ptr != (PCRE2_UCHAR)terminator) + if (terminator != 0) { - *errorcodeptr = ERR42; - goto FAILED; + if (ptr >= ptrend || *ptr != (PCRE2_UCHAR)terminator) + { + *errorcodeptr = ERR42; + goto FAILED; + } + ptr++; } - ptr++; } *ptrptr = ptr; @@ -2641,6 +2708,128 @@ return FALSE; +/************************************************** +* Parse capturing bracket argument list * +**************************************************/ + +/* Reads a list of capture references. The references +can be numbers or names. + +Arguments: + ptrptr points to the character pointer variable + ptrend points to the end of the input string + utf true if the input is UTF-encoded + parsed_pattern the parsed pattern pointer + offset last known offset + errcodeptr where to put an error code + cb pointer to the compile data block + +Returns: updated parsed_pattern pointer on success + NULL otherwise +*/ + +static uint32_t * +parse_capture_list(PCRE2_SPTR *ptrptr, PCRE2_SPTR ptrend, + BOOL utf, uint32_t *parsed_pattern, PCRE2_SIZE offset, + int *errorcodeptr, compile_block *cb) +{ +PCRE2_SIZE next_offset; +PCRE2_SPTR ptr = *ptrptr; +PCRE2_SPTR name; +PCRE2_UCHAR terminator; +uint32_t meta, namelen; +int i; + +if (ptr >= ptrend || *ptr != CHAR_LEFT_PARENTHESIS) + { + *errorcodeptr = ERR118; + goto FAILED; + } + +for (;;) + { + ptr++; + next_offset = (PCRE2_SIZE)(ptr - cb->start_pattern); + + if (ptr >= ptrend) + { + *errorcodeptr = ERR117; + goto FAILED; + } + + /* Handle [+-]number cases */ + if (read_number(&ptr, ptrend, cb->bracount, MAX_GROUP_NUMBER, ERR61, + &i, errorcodeptr)) + { + PCRE2_ASSERT(i >= 0); + if (i <= 0) + { + *errorcodeptr = ERR15; + goto FAILED; + } + meta = META_CAPTURE_NUMBER; + namelen = (uint32_t)i; + } + else if (*errorcodeptr != 0) goto FAILED; /* Number too big */ + else + { + /* Handle 'name' or cases. */ + if (*ptr == CHAR_LESS_THAN_SIGN) + terminator = CHAR_GREATER_THAN_SIGN; + else if (*ptr == CHAR_APOSTROPHE) + terminator = CHAR_APOSTROPHE; + else + { + *errorcodeptr = ERR117; + goto FAILED; + } + + if (!read_name(&ptr, ptrend, utf, terminator, &next_offset, + &name, &namelen, errorcodeptr, cb)) goto FAILED; + + meta = META_CAPTURE_NAME; + } + + PCRE2_ASSERT(next_offset > 0); + if (offset == 0 || (next_offset - offset) >= 0x10000) + { + *parsed_pattern++ = META_OFFSET; + PUTOFFSET(next_offset, parsed_pattern); + offset = next_offset; + } + + /* The offset is encoded as a relative offset, because for some + inputs such as ",2" in (1,2,3), we only have space for two uint32_t + values, and an opcode and absolute offset may require three uint32_t + values. */ + *parsed_pattern++ = meta | (uint32_t)(next_offset - offset); + *parsed_pattern++ = namelen; + offset = next_offset; + + if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; + + if (*ptr == CHAR_RIGHT_PARENTHESIS) break; + + if (*ptr != CHAR_COMMA) + { + *errorcodeptr = ERR24; + goto FAILED; + } + } + +*ptrptr = ptr + 1; +return parsed_pattern; + +UNCLOSED_PARENTHESIS: +*errorcodeptr = ERR14; + +FAILED: +*ptrptr = ptr; +return NULL; +} + + + /************************************************* * Manage callouts at start of cycle * *************************************************/ @@ -2719,21 +2908,21 @@ switch(escape) { case ESC_D: prop = ESC_P; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_d: ascii_option = PCRE2_EXTRA_ASCII_BSD; break; case ESC_S: prop = ESC_P; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_s: ascii_option = PCRE2_EXTRA_ASCII_BSS; break; case ESC_W: prop = ESC_P; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_w: ascii_option = PCRE2_EXTRA_ASCII_BSW; break; @@ -2942,6 +3131,7 @@ uint32_t add_after_mark = 0; uint16_t nest_depth = 0; int16_t class_depth_m1 = -1; /* The m1 means minus 1. */ int16_t class_maxdepth_m1 = -1; +uint16_t hash; int after_manual_callout = 0; int expect_cond_assert = 0; int errorcode = 0; @@ -2951,7 +3141,7 @@ BOOL inescq = FALSE; BOOL inverbname = FALSE; BOOL utf = (options & PCRE2_UTF) != 0; BOOL auto_callout = (options & PCRE2_AUTO_CALLOUT) != 0; -BOOL isdupname; +BOOL is_dupname; BOOL negate_class; BOOL okquantifier = FALSE; PCRE2_SPTR thisptr; @@ -2996,12 +3186,15 @@ if ((options & PCRE2_LITERAL) != 0) { while (ptr < ptrend) { + /* LCOV_EXCL_START */ if (parsed_pattern >= parsed_pattern_end) { PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR63; /* Internal error (parsed pattern overflow) */ goto FAILED; } + /* LCOV_EXCL_STOP */ + thisptr = ptr; GETCHARINCTEST(c, ptr); if (auto_callout) @@ -3067,6 +3260,7 @@ while (ptr < ptrend) ptr_check = ptr; #endif + /* LCOV_EXCL_START */ if (parsed_pattern >= parsed_pattern_end) { /* Weak pre-write check; only ensures parsed_pattern[0] is writeable @@ -3075,6 +3269,7 @@ while (ptr < ptrend) errorcode = ERR63; /* Internal error (parsed pattern overflow) */ goto FAILED; } + /* LCOV_EXCL_STOP */ /* If the last time round this loop something was added, parsed_pattern will no longer be equal to this_parsed_item. Remember where the previous item @@ -3104,12 +3299,6 @@ while (ptr < ptrend) } else { - if (expect_cond_assert > 0) /* A literal is not allowed if we are */ - { /* expecting a conditional assertion, */ - ptr--; /* but an empty \Q\E sequence is OK. */ - errorcode = ERR28; - goto FAILED; - } if (inverbname) { /* Don't use PARSED_LITERAL() because it */ #if PCRE2_CODE_UNIT_WIDTH == 32 /* sets okquantifier. */ @@ -3238,6 +3427,15 @@ while (ptr < ptrend) { if (*ptr == CHAR_Q || *ptr == CHAR_E) { + /* A literal inside a \Q...\E is not allowed if we are expecting a + conditional assertion, but an empty \Q\E sequence is OK. */ + if (expect_cond_assert > 0 && *ptr == CHAR_Q && + !(ptrend - ptr >= 3 && ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)) + { + ptr--; + errorcode = ERR28; + goto FAILED; + } inescq = *ptr == CHAR_Q; ptr++; continue; @@ -3347,9 +3545,9 @@ while (ptr < ptrend) if (!ok) { - ptr--; /* Adjust error offset */ errorcode = ERR28; - goto FAILED; + if (expect_cond_assert == 2) goto FAILED; + goto FAILED_BACK; } } @@ -3425,7 +3623,7 @@ while (ptr < ptrend) else if (escape < 0) { - offset = (PCRE2_SIZE)(ptr - cb->start_pattern - 1); + offset = (PCRE2_SIZE)(ptr - cb->start_pattern); escape = -escape - 1; *parsed_pattern++ = META_BACKREF | (uint32_t)escape; if (escape < 10) @@ -3523,7 +3721,7 @@ while (ptr < ptrend) { BOOL negated; uint16_t ptype = 0, pdata = 0; - if (!get_ucp(&ptr, &negated, &ptype, &pdata, &errorcode, cb)) + if (!get_ucp(&ptr, utf, &negated, &ptype, &pdata, &errorcode, cb)) goto ESCAPE_FAILED; if (negated) escape = (escape == ESC_P)? ESC_p : ESC_P; *parsed_pattern++ = META_ESCAPE + escape; @@ -3565,10 +3763,11 @@ while (ptr < ptrend) { if (p >= ptrend || *p != terminator) { - errorcode = ERR57; + ptr = p; + errorcode = ERR119; /* Missing terminator for number */ goto ESCAPE_FAILED; } - ptr = p; + ptr = p + 1; goto SET_RECURSION; } if (errorcode != 0) goto ESCAPE_FAILED; @@ -3649,7 +3848,7 @@ while (ptr < ptrend) if (!prev_okquantifier) { errorcode = ERR9; - goto FAILED_BACK; // TODO https://github.com/PCRE2Project/pcre2/issues/549 + goto FAILED; } /* Most (*VERB)s are not allowed to be quantified, but an ungreedy @@ -3738,6 +3937,7 @@ while (ptr < ptrend) check_posix_syntax(ptr, ptrend, &tempptr)) { errorcode = (*ptr-- == CHAR_COLON)? ERR12 : ERR13; + ptr = tempptr + 2; goto FAILED; } @@ -3965,8 +4165,9 @@ while (ptr < ptrend) /* Validate nesting depth */ if (class_depth_m1 >= ECLASS_NEST_LIMIT - 1) { - errorcode = ERR107; - goto FAILED; /* Classes too deeply nested */ + ptr--; /* Point rightwards at the paren, same as ERR19. */ + errorcode = ERR107; /* Classes too deeply nested */ + goto FAILED; } /* Process the character class start. If the first character is '^', set @@ -4081,7 +4282,8 @@ while (ptr < ptrend) if (c == CHAR_RIGHT_SQUARE_BRACKET && class_depth_m1 != 0) { errorcode = ERR14; - goto FAILED_BACK; + ptr--; /* Correct the offset */ + goto FAILED; } if (c == CHAR_RIGHT_PARENTHESIS && class_depth_m1 < 1) { @@ -4301,7 +4503,6 @@ while (ptr < ptrend) case ESC_R: case ESC_X: errorcode = ERR7; - ptr--; // TODO https://github.com/PCRE2Project/pcre2/issues/549 goto FAILED; case ESC_N: /* Not permitted by Perl either */ @@ -4336,7 +4537,7 @@ while (ptr < ptrend) { BOOL negated; uint16_t ptype = 0, pdata = 0; - if (!get_ucp(&ptr, &negated, &ptype, &pdata, &errorcode, cb)) + if (!get_ucp(&ptr, utf, &negated, &ptype, &pdata, &errorcode, cb)) goto FAILED; /* In caseless matching, particular characteristics Lu, Ll, and Lt @@ -4362,9 +4563,11 @@ while (ptr < ptrend) /* All others are not allowed in a class */ + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ + /* LCOV_EXCL_STOP */ case ESC_A: case ESC_Z: @@ -4373,7 +4576,6 @@ while (ptr < ptrend) case ESC_K: case ESC_C: errorcode = ERR7; - ptr--; // TODO https://github.com/PCRE2Project/pcre2/issues/549 goto FAILED; } @@ -4464,7 +4666,7 @@ while (ptr < ptrend) else if (parsed_pattern[-2] > c) /* Check range is in order */ { errorcode = ERR8; - goto FAILED_BACK; // TODO https://github.com/PCRE2Project/pcre2/issues/549 + goto FAILED; } else { @@ -4560,10 +4762,11 @@ while (ptr < ptrend) vn = alasnames; if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, &namelen, &errorcode, cb)) goto FAILED; - if (ptr >= ptrend || *ptr != CHAR_COLON) + if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; + if (*ptr != CHAR_COLON) { errorcode = ERR95; /* Malformed */ - goto FAILED; + goto FAILED_FORWARD; } /* Scan the table of alpha assertion names */ @@ -4598,10 +4801,12 @@ while (ptr < ptrend) switch(meta) { + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR89; /* Unknown code; should never occur because */ goto FAILED; /* the meta values come from a table above. */ + /* LCOV_EXCL_STOP */ case META_ATOMIC: goto ATOMIC_GROUP; @@ -4616,87 +4821,12 @@ while (ptr < ptrend) goto NEGATIVE_LOOK_AHEAD; case META_SCS: - if (++ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - if (*ptr != CHAR_LEFT_PARENTHESIS) - { - errorcode = ERR15; - goto FAILED; - } - ptr++; *parsed_pattern++ = META_SCS; - /* Temporary variable, zero in the first iteration. */ - offset = 0; - for (;;) - { - PCRE2_SIZE next_offset = (PCRE2_SIZE)(ptr - cb->start_pattern); - - /* Handle (scan_substring:([+-]number)... */ - if (read_number(&ptr, ptrend, cb->bracount, MAX_GROUP_NUMBER, ERR61, - &i, &errorcode)) - { - PCRE2_ASSERT(i >= 0); - if (i <= 0) - { - errorcode = ERR15; - goto FAILED; - } - meta = META_SCS_NUMBER; - namelen = (uint32_t)i; - } - else if (errorcode != 0) goto FAILED; /* Number too big */ - else - { - if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - /* Handle (*scan_substring:('name') or (*scan_substring:() */ - if (*ptr == CHAR_LESS_THAN_SIGN) - terminator = CHAR_GREATER_THAN_SIGN; - else if (*ptr == CHAR_APOSTROPHE) - terminator = CHAR_APOSTROPHE; - else - { - errorcode = ERR15; - goto FAILED; - } - - if (!read_name(&ptr, ptrend, utf, terminator, &next_offset, - &name, &namelen, &errorcode, cb)) goto FAILED; - - meta = META_SCS_NAME; - } - - PCRE2_ASSERT(next_offset > 0); - if (offset == 0 || (next_offset - offset) >= 0x10000) - { - *parsed_pattern++ = META_OFFSET; - PUTOFFSET(next_offset, parsed_pattern); - offset = next_offset; - } - - /* The offset is encoded as a relative offset, because for some - inputs such as ",2" in (*scs:(1,2,3)...), we only have space for - two uint32_t values, and an opcode and absolute offset may require - three uint32_t values. */ - *parsed_pattern++ = meta | (uint32_t)(next_offset - offset); - *parsed_pattern++ = namelen; - offset = next_offset; - - if (ptr >= ptrend) goto UNCLOSED_PARENTHESIS; - - if (*ptr == CHAR_RIGHT_PARENTHESIS) break; - - if (*ptr != CHAR_COMMA) - { - errorcode = ERR24; - goto FAILED; - } - - ptr++; - } - ptr++; + parsed_pattern = parse_capture_list(&ptr, ptrend, utf, parsed_pattern, + 0, &errorcode, cb); + if (parsed_pattern == NULL) goto FAILED; goto POST_ASSERTION; case META_LOOKBEHIND: @@ -4923,7 +5053,6 @@ while (ptr < ptrend) if (!hyphenok) { errorcode = ERR94; - ptr--; /* Correct the offset */ goto FAILED; } optset = &unset; @@ -4997,7 +5126,6 @@ while (ptr < ptrend) default: errorcode = ERR11; - ptr--; /* Correct the offset */ goto FAILED; } } @@ -5066,7 +5194,7 @@ while (ptr < ptrend) if (*ptr != CHAR_EQUALS_SIGN) { errorcode = ERR41; - goto FAILED; + goto FAILED_FORWARD; } if (!read_name(&ptr, ptrend, utf, CHAR_RIGHT_PARENTHESIS, &offset, &name, &namelen, &errorcode, cb)) goto FAILED; @@ -5082,23 +5210,30 @@ while (ptr < ptrend) case CHAR_R: i = 0; /* (?R) == (?R0) */ ptr++; - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) + if (ptr >= ptrend || (*ptr != CHAR_RIGHT_PARENTHESIS && *ptr != CHAR_LEFT_PARENTHESIS)) { errorcode = ERR58; goto FAILED; } + terminator = CHAR_NUL; goto SET_RECURSION; /* An item starting (?- followed by a digit comes here via the "default" case because (?- followed by a non-digit is an options setting. */ case CHAR_PLUS: - if (ptrend - ptr < 2 || !IS_DIGIT(ptr[1])) + if (ptr + 1 >= ptrend) + { + ++ptr; + goto UNCLOSED_PARENTHESIS; + } + if (!IS_DIGIT(ptr[1])) { errorcode = ERR29; /* Missing number */ - goto FAILED; + ++ptr; + goto FAILED_FORWARD; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_0: case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4: case CHAR_5: case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9: @@ -5108,28 +5243,43 @@ while (ptr < ptrend) MAX_GROUP_NUMBER, ERR61, &i, &errorcode)) goto FAILED; PCRE2_ASSERT(i >= 0); /* NB (?0) is permitted, represented by i=0 */ - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) - goto UNCLOSED_PARENTHESIS; + terminator = CHAR_NUL; SET_RECURSION: *parsed_pattern++ = META_RECURSE | (uint32_t)i; offset = (PCRE2_SIZE)(ptr - cb->start_pattern); - ptr++; - PUTOFFSET(offset, parsed_pattern); - okquantifier = TRUE; - break; /* End of recursive call by number handling */ + /* End of recursive call by number handling */ + goto READ_RECURSION_ARGUMENTS; /* ---- Recursion/subroutine calls by name ---- */ case CHAR_AMPERSAND: RECURSE_BY_NAME: - if (!read_name(&ptr, ptrend, utf, CHAR_RIGHT_PARENTHESIS, &offset, &name, + if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, &namelen, &errorcode, cb)) goto FAILED; *parsed_pattern++ = META_RECURSE_BYNAME; *parsed_pattern++ = namelen; + terminator = CHAR_NUL; + + READ_RECURSION_ARGUMENTS: PUTOFFSET(offset, parsed_pattern); okquantifier = TRUE; + + /* Arguments are not supported for \g construct. */ + if (terminator != CHAR_NUL) break; + + if (ptr < ptrend && *ptr == CHAR_LEFT_PARENTHESIS) + { + parsed_pattern = parse_capture_list(&ptr, ptrend, utf, parsed_pattern, + offset, &errorcode, cb); + if (parsed_pattern == NULL) goto FAILED; + } + + if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) + goto UNCLOSED_PARENTHESIS; + + ptr++; break; /* ---- Callout with numerical or string argument ---- */ @@ -5137,6 +5287,7 @@ while (ptr < ptrend) case CHAR_C: if ((xoptions & PCRE2_EXTRA_NEVER_CALLOUT) != 0) { + ptr++; errorcode = ERR103; goto FAILED; } @@ -5189,7 +5340,7 @@ while (ptr < ptrend) if (delimiter == 0) { errorcode = ERR82; - goto FAILED; + goto FAILED_FORWARD; } *parsed_pattern = META_CALLOUT_STRING; @@ -5333,20 +5484,31 @@ while (ptr < ptrend) references its argument twice. */ if (*ptr != CHAR_EQUALS_SIGN || (ptr++, !IS_DIGIT(*ptr))) - goto BAD_VERSION_CONDITION; + { + errorcode = ERR79; + if (!ge) goto FAILED_FORWARD; + goto FAILED; + } if (!read_number(&ptr, ptrend, -1, 1000, ERR79, &major, &errorcode)) goto FAILED; - if (ptr >= ptrend) goto BAD_VERSION_CONDITION; - if (*ptr == CHAR_DOT) + if (ptr < ptrend && *ptr == CHAR_DOT) { - if (++ptr >= ptrend || !IS_DIGIT(*ptr)) goto BAD_VERSION_CONDITION; - minor = (*ptr++ - CHAR_0) * 10; - if (ptr >= ptrend) goto BAD_VERSION_CONDITION; - if (IS_DIGIT(*ptr)) minor += *ptr++ - CHAR_0; - if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) - goto BAD_VERSION_CONDITION; + if (++ptr >= ptrend || !IS_DIGIT(*ptr)) + { + errorcode = ERR79; + if (ptr < ptrend) goto FAILED_FORWARD; + goto FAILED; + } + if (!read_number(&ptr, ptrend, -1, 1000, ERR79, &minor, &errorcode)) + goto FAILED; + } + if (ptr >= ptrend || *ptr != CHAR_RIGHT_PARENTHESIS) + { + errorcode = ERR79; + if (ptr < ptrend) goto FAILED_FORWARD; + goto FAILED; } *parsed_pattern++ = META_COND_VERSION; @@ -5380,6 +5542,7 @@ while (ptr < ptrend) terminator = CHAR_RIGHT_PARENTHESIS; ptr--; /* Point to char before name */ } + if (!read_name(&ptr, ptrend, utf, terminator, &offset, &name, &namelen, &errorcode, cb)) goto FAILED; @@ -5559,21 +5722,37 @@ while (ptr < ptrend) scanning in case this is a duplicate with the same number. For non-duplicate names, give an error if the number is duplicated. */ - isdupname = FALSE; + is_dupname = FALSE; + hash = PRIV(compile_get_hash_from_name)(name, namelen); ng = cb->named_groups; for (i = 0; i < cb->names_found; i++, ng++) { - if (namelen == ng->length && + if (namelen == ng->length && hash == NAMED_GROUP_GET_HASH(ng) && PRIV(strncmp)(name, ng->name, (PCRE2_SIZE)namelen) == 0) { + /* When a bracket is referenced by the same name multiple + times, is not considered as a duplicate and ignored. */ if (ng->number == cb->bracount) break; if ((options & PCRE2_DUPNAMES) == 0) { errorcode = ERR43; goto FAILED; } - isdupname = ng->isdup = TRUE; /* Mark as a duplicate */ + + ng->hash_dup |= NAMED_GROUP_IS_DUPNAME; + is_dupname = TRUE; /* Mark as a duplicate */ cb->dupnames = TRUE; /* Duplicate names exist */ + + /* The entry represents a duplicate. */ + name = ng->name; + namelen = 0; + + /* Even duplicated names may refer to the same + capture index. These references are also ignored. */ + for (; i < cb->names_found; i++, ng++) + if (ng->name == name && ng->number == cb->bracount) + break; + break; } else if (ng->number == cb->bracount) { @@ -5582,7 +5761,8 @@ while (ptr < ptrend) } } - if (i < cb->names_found) break; /* Ignore duplicate with same number */ + /* Ignore duplicate with same number. */ + if (i < cb->names_found) break; /* Increase the list size if necessary */ @@ -5608,11 +5788,13 @@ while (ptr < ptrend) } /* Add this name to the list */ + if (is_dupname) + hash |= NAMED_GROUP_IS_DUPNAME; cb->named_groups[cb->names_found].name = name; cb->named_groups[cb->names_found].length = (uint16_t)namelen; cb->named_groups[cb->names_found].number = cb->bracount; - cb->named_groups[cb->names_found].isdup = (uint16_t)isdupname; + cb->named_groups[cb->names_found].hash_dup = hash; cb->names_found++; break; @@ -5678,7 +5860,7 @@ while (ptr < ptrend) if (nest_depth == 0) /* Unmatched closing parenthesis */ { errorcode = ERR22; - goto FAILED_BACK; // TODO https://github.com/PCRE2Project/pcre2/issues/549 + goto FAILED; } nest_depth--; *parsed_pattern++ = META_KET; @@ -5723,12 +5905,14 @@ else if ((xoptions & PCRE2_EXTRA_MATCH_WORD) != 0) /* Terminate the parsed pattern, then return success if all groups are closed. Otherwise we have unclosed parentheses. */ +/* LCOV_EXCL_START */ if (parsed_pattern >= parsed_pattern_end) { PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR63; /* Internal error (parsed pattern overflow) */ goto FAILED; } +/* LCOV_EXCL_STOP */ *parsed_pattern = META_END; if (nest_depth == 0) return 0; @@ -5746,12 +5930,18 @@ return errorcode; FAILED_BACK: ptr--; +#ifdef SUPPORT_UNICODE +if (utf) BACKCHAR(ptr); +#endif goto FAILED; -/* This failure happens several times. */ +/* Some errors need to indicate the next character. */ -BAD_VERSION_CONDITION: -errorcode = ERR79; +FAILED_FORWARD: +ptr++; +#ifdef SUPPORT_UNICODE +if (utf) FORWARDCHARTEST(ptr, ptrend); +#endif goto FAILED; } @@ -5795,7 +5985,7 @@ for (;;) case OP_UCP_WORD_BOUNDARY: case OP_NOT_UCP_WORD_BOUNDARY: if (!skipassert) return code; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CALLOUT: case OP_CREF: @@ -5836,78 +6026,9 @@ for (;;) } } +/* LCOV_EXCL_START */ PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ -} - - - -/************************************************* -* Find details of duplicate group names * -*************************************************/ - -/* This is called from compile_branch() when it needs to know the index and -count of duplicates in the names table when processing named backreferences, -either directly, or as conditions. - -Arguments: - name points to the name - length the length of the name - indexptr where to put the index - countptr where to put the count of duplicates - errorcodeptr where to put an error code - cb the compile block - -Returns: TRUE if OK, FALSE if not, error code set -*/ - -static BOOL -find_dupname_details(PCRE2_SPTR name, uint32_t length, int *indexptr, - int *countptr, int *errorcodeptr, compile_block *cb) -{ -uint32_t i, groupnumber; -int count; -PCRE2_UCHAR *slot = cb->name_table; - -/* Find the first entry in the table */ - -for (i = 0; i < cb->names_found; i++) - { - if (PRIV(strncmp)(name, slot+IMM2_SIZE, length) == 0 && - slot[IMM2_SIZE+length] == 0) break; - slot += cb->name_entry_size; - } - -/* This should not occur, because this function is called only when we know we -have duplicate names. Give an internal error. */ - -if (i >= cb->names_found) - { - PCRE2_DEBUG_UNREACHABLE(); - *errorcodeptr = ERR53; - cb->erroroffset = name - cb->start_pattern; - return FALSE; - } - -/* Record the index and then see how many duplicates there are, updating the -backref map and maximum back reference as we do. */ - -*indexptr = i; -count = 0; - -for (;;) - { - count++; - groupnumber = GET2(slot,0); - cb->backref_map |= (groupnumber < 32)? (1u << groupnumber) : 1; - if (groupnumber > cb->top_backref) cb->top_backref = groupnumber; - if (++i >= cb->names_found) break; - slot += cb->name_entry_size; - if (PRIV(strncmp)(name, slot+IMM2_SIZE, length) != 0 || - (slot+IMM2_SIZE)[length] != 0) break; - } - -*countptr = count; -return TRUE; +/* LCOV_EXCL_STOP */ } @@ -5965,7 +6086,7 @@ uint32_t meta, meta_arg; uint32_t firstcuflags, reqcuflags; uint32_t zeroreqcuflags, zerofirstcuflags; uint32_t req_caseopt, reqvary, tempreqvary; -/* Some opcodes, such as META_SCS_NUMBER or META_SCS_NAME, +/* Some opcodes, such as META_CAPTURE_NUMBER or META_CAPTURE_NAME, depends on the previous value of offset. */ PCRE2_SIZE offset = 0; PCRE2_SIZE length_prevgroup = 0; @@ -6042,16 +6163,21 @@ for (;; pptr++) if (lengthptr != NULL) { + /* LCOV_EXCL_START */ + if (code >= cb->start_workspace + cb->workspace_size) + { + PCRE2_DEBUG_UNREACHABLE(); + *errorcodeptr = ERR52; /* Over-ran workspace - internal error */ + cb->erroroffset = 0; + return 0; + } + /* LCOV_EXCL_STOP */ + if (code > cb->start_workspace + cb->workspace_size - WORK_SIZE_SAFETY_MARGIN) /* Check for overrun */ { - if (code >= cb->start_workspace + cb->workspace_size) - { - PCRE2_DEBUG_UNREACHABLE(); - *errorcodeptr = ERR52; /* Over-ran workspace - internal error */ - } - else - *errorcodeptr = ERR86; + *errorcodeptr = ERR86; /* Pattern too complicated */ + cb->erroroffset = 0; return 0; } @@ -6072,12 +6198,14 @@ for (;; pptr++) if (OFLOW_MAX - *lengthptr < (PCRE2_SIZE)(code - orig_code)) { *errorcodeptr = ERR20; /* Integer overflow */ + cb->erroroffset = 0; return 0; } *lengthptr += (PCRE2_SIZE)(code - orig_code); if (*lengthptr > MAX_PATTERN_SIZE) { *errorcodeptr = ERR20; /* Pattern is too large */ + cb->erroroffset = 0; return 0; } code = orig_code; @@ -6380,7 +6508,7 @@ for (;; pptr++) case META_PRUNE: case META_SKIP: cb->had_pruneorskip = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_COMMIT: case META_FAIL: *code++ = verbops[(meta - META_MARK) >> 16]; @@ -6405,7 +6533,7 @@ for (;; pptr++) case META_PRUNE_ARG: case META_SKIP_ARG: cb->had_pruneorskip = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_MARK: case META_COMMIT_ARG: VERB_ARG: @@ -6450,8 +6578,63 @@ for (;; pptr++) req_caseopt = ((options & PCRE2_CASELESS) != 0)? REQ_CASELESS : 0; break; + /* ===================================================================*/ + /* Handle scan substring. Scan substring assertion starts with META_SCS, + which recursively calls compile_branch. The first opcode processed by + this recursive call is always META_OFFSET. */ + case META_OFFSET: - GETPLUSOFFSET(offset, pptr); + if (lengthptr != NULL) + { + pptr = PRIV(compile_parse_scan_substr_args)(pptr, errorcodeptr, cb, lengthptr); + if (pptr == NULL) + return 0; + break; + } + + while (TRUE) + { + int count, index; + named_group *ng; + + switch (META_CODE(*pptr)) + { + case META_OFFSET: + pptr++; + SKIPOFFSET(pptr); + continue; + + case META_CAPTURE_NAME: + ng = cb->named_groups + pptr[1]; + pptr += 2; + count = 0; + index = 0; + + if (!PRIV(compile_find_dupname_details)(ng->name, ng->length, &index, + &count, errorcodeptr, cb)) return 0; + + code[0] = OP_DNCREF; + PUT2(code, 1, index); + PUT2(code, 1 + IMM2_SIZE, count); + code += 1 + 2 * IMM2_SIZE; + continue; + + case META_CAPTURE_NUMBER: + pptr += 2; + if (pptr[-1] == 0) continue; + + code[0] = OP_CREF; + PUT2(code, 1, pptr[-1]); + code += 1 + IMM2_SIZE; + continue; + + default: + break; + } + + break; + } + --pptr; break; case META_SCS: @@ -6470,19 +6653,17 @@ for (;; pptr++) case META_COND_RNUMBER: /* (?(Rdigits) */ case META_COND_NAME: /* (?(name) or (?'name') or ?() */ case META_COND_RNAME: /* (?(R&name) - test for recursion */ - case META_SCS_NAME: /* Name of scan substring */ bravalue = OP_COND; + + if (lengthptr != NULL) { - int count, index; - unsigned int i; + uint32_t i; PCRE2_SPTR name; - named_group *ng = cb->named_groups; + named_group *ng; + uint32_t *start_pptr = pptr; uint32_t length = *(++pptr); - if (meta == META_SCS_NAME) - offset += meta_arg; - else - GETPLUSOFFSET(offset, pptr); + GETPLUSOFFSET(offset, pptr); name = cb->start_pattern + offset; /* In the first pass, the names generated in the pre-pass are available, @@ -6491,11 +6672,9 @@ for (;; pptr++) this name is duplicated. If it is not duplicated, we can handle it as a numerical group. */ - for (i = 0; i < cb->names_found; i++, ng++) - if (length == ng->length && - PRIV(strncmp)(name, ng->name, length) == 0) break; + ng = PRIV(compile_find_named_group)(name, length, cb); - if (i >= cb->names_found) + if (ng == NULL) { /* If the name was not found we have a bad reference, unless we are dealing with R, which is treated as a recursion test by @@ -6528,61 +6707,88 @@ for (;; pptr++) translated into RREF_ANY (which is 0xffff). */ if (groupnumber == 0) groupnumber = RREF_ANY; - code[1+LINK_SIZE] = OP_RREF; - PUT2(code, 2+LINK_SIZE, groupnumber); + PCRE2_ASSERT(start_pptr[0] == META_COND_RNUMBER); + start_pptr[1] = groupnumber; skipunits = 1+IMM2_SIZE; goto GROUP_PROCESS_NOTE_EMPTY; } - else if (!ng->isdup) + + /* From here on, we know we have a name (not a number), + so treat META_COND_RNUMBER the same as META_COND_NAME. */ + if (meta == META_COND_RNUMBER) meta = META_COND_NAME; + + if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) == 0) { - /* Otherwise found a duplicated name */ + /* Found a non-duplicated name. Since it is a global, + it is enough to update it in the pre-processing phase. */ if (ng->number > cb->top_backref) cb->top_backref = ng->number; - if (meta == META_SCS_NAME) - { - code[0] = OP_CREF; - PUT2(code, 1, ng->number); - code += 1+IMM2_SIZE; - break; - } + start_pptr[0] = meta; + start_pptr[1] = ng->number; - code[1+LINK_SIZE] = (meta == META_COND_RNAME)? OP_RREF : OP_CREF; - PUT2(code, 2+LINK_SIZE, ng->number); - skipunits = 1+IMM2_SIZE; - if (meta != META_SCS_NAME) goto GROUP_PROCESS_NOTE_EMPTY; - cb->assert_depth += 1; - goto GROUP_PROCESS; + skipunits = 1 + IMM2_SIZE; + goto GROUP_PROCESS_NOTE_EMPTY; } /* We have a duplicated name. In the compile pass we have to search the main table in order to get the index and count values. */ + start_pptr[0] = meta | 1; + start_pptr[1] = (uint32_t)(ng - cb->named_groups); + + /* A duplicated name was found. Note that if an R name is found + (META_COND_RNUMBER), it is a reference test, not a recursion test. */ + skipunits = 1 + 2 * IMM2_SIZE; + } + else + { + /* Otherwise lengthptr equals to NULL, + which is the second phase of compilation. */ + int count, index; + named_group *ng; + + /* Generate code using the data + collected in the pre-processing phase. */ + + if (meta == META_COND_RNUMBER) + { + code[1+LINK_SIZE] = OP_RREF; + PUT2(code, 2 + LINK_SIZE, pptr[1]); + skipunits = 1 + IMM2_SIZE; + pptr += 1 + SIZEOFFSET; + goto GROUP_PROCESS_NOTE_EMPTY; + } + + if (meta_arg == 0) + { + code[1+LINK_SIZE] = (meta == META_COND_RNAME)? OP_RREF : OP_CREF; + PUT2(code, 2 + LINK_SIZE, pptr[1]); + skipunits = 1 + IMM2_SIZE; + pptr += 1 + SIZEOFFSET; + goto GROUP_PROCESS_NOTE_EMPTY; + } + + ng = cb->named_groups + pptr[1]; count = 0; /* Values for first pass (avoids compiler warning) */ index = 0; - if (lengthptr == NULL && !find_dupname_details(name, length, &index, - &count, errorcodeptr, cb)) return 0; - if (meta == META_SCS_NAME) - { - code[0] = OP_DNCREF; - PUT2(code, 1, index); - PUT2(code, 1+IMM2_SIZE, count); - code += 1+2*IMM2_SIZE; - break; - } + /* The failed case is an internal error. */ + if (!PRIV(compile_find_dupname_details)(ng->name, ng->length, &index, + &count, errorcodeptr, cb)) return 0; /* A duplicated name was found. Note that if an R name is found (META_COND_RNUMBER), it is a reference test, not a recursion test. */ - code[1+LINK_SIZE] = (meta == META_COND_RNAME)? OP_DNRREF : OP_DNCREF; + code[1 + LINK_SIZE] = (meta == META_COND_RNAME)? OP_DNRREF : OP_DNCREF; /* Insert appropriate data values. */ - skipunits = 1+2*IMM2_SIZE; - PUT2(code, 2+LINK_SIZE, index); - PUT2(code, 2+LINK_SIZE+IMM2_SIZE, count); + PUT2(code, 2 + LINK_SIZE, index); + PUT2(code, 2 + LINK_SIZE + IMM2_SIZE, count); + skipunits = 1 + 2 * IMM2_SIZE; + pptr += 1 + SIZEOFFSET; } - PCRE2_ASSERT(meta != META_SCS_NAME); + PCRE2_ASSERT(meta != META_CAPTURE_NAME); goto GROUP_PROCESS_NOTE_EMPTY; /* The DEFINE condition is always false. Its internal groups may never @@ -6599,12 +6805,8 @@ for (;; pptr++) /* Conditional test of a group's being set. */ case META_COND_NUMBER: - case META_SCS_NUMBER: bravalue = OP_COND; - if (meta == META_SCS_NUMBER) - offset += meta_arg; - else - GETPLUSOFFSET(offset, pptr); + GETPLUSOFFSET(offset, pptr); groupnumber = *(++pptr); if (groupnumber > cb->bracount) @@ -6615,14 +6817,6 @@ for (;; pptr++) } if (groupnumber > cb->top_backref) cb->top_backref = groupnumber; - if (meta == META_SCS_NUMBER) - { - code[0] = OP_CREF; - PUT2(code, 1, groupnumber); - code += 1+IMM2_SIZE; - break; - } - /* Point at initial ( for too many branches error */ offset -= 2; code[1+LINK_SIZE] = OP_CREF; @@ -6930,8 +7124,7 @@ for (;; pptr++) { int count, index; PCRE2_SPTR name; - BOOL is_dupname = FALSE; - named_group *ng = cb->named_groups; + named_group *ng; uint32_t length = *(++pptr); GETPLUSOFFSET(offset, pptr); @@ -6942,47 +7135,39 @@ for (;; pptr++) generated in the pre-pass in order to get a number and whether or not this name is duplicated. */ - groupnumber = 0; - for (unsigned int i = 0; i < cb->names_found; i++, ng++) - { - if (length == ng->length && - PRIV(strncmp)(name, ng->name, length) == 0) - { - is_dupname = ng->isdup; - groupnumber = ng->number; - - /* For a recursion, that's all that is needed. We can now go to - the code that handles numerical recursion, applying it to the first - group with the given name. */ - - if (meta == META_RECURSE_BYNAME) - { - meta_arg = groupnumber; - goto HANDLE_NUMERICAL_RECURSION; - } - - /* For a back reference, update the back reference map and the - maximum back reference. */ - - cb->backref_map |= (groupnumber < 32)? (1u << groupnumber) : 1; - if (groupnumber > cb->top_backref) - cb->top_backref = groupnumber; - } - } - - /* If the name was not found we have a bad reference. */ - - if (groupnumber == 0) + ng = PRIV(compile_find_named_group)(name, length, cb); + + if (ng == NULL) { + /* If the name was not found we have a bad reference. */ *errorcodeptr = ERR15; cb->erroroffset = offset; return 0; } + groupnumber = ng->number; + + /* For a recursion, that's all that is needed. We can now go to + the code that handles numerical recursion, applying it to the first + group with the given name. */ + + if (meta == META_RECURSE_BYNAME) + { + meta_arg = groupnumber; + goto HANDLE_NUMERICAL_RECURSION; + } + + /* For a back reference, update the back reference map and the + maximum back reference. */ + + cb->backref_map |= (groupnumber < 32)? (1u << groupnumber) : 1; + if (groupnumber > cb->top_backref) + cb->top_backref = groupnumber; + /* If a back reference name is not duplicated, we can handle it as a numerical reference. */ - if (!is_dupname) + if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) == 0) { meta_arg = groupnumber; goto HANDLE_SINGLE_REFERENCE; @@ -6994,8 +7179,8 @@ for (;; pptr++) count = 0; /* Values for first pass (avoids compiler warning) */ index = 0; - if (lengthptr == NULL && !find_dupname_details(name, length, &index, - &count, errorcodeptr, cb)) return 0; + if (lengthptr == NULL && !PRIV(compile_find_dupname_details)(name, length, + &index, &count, errorcodeptr, cb)) return 0; if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; *code++ = ((options & PCRE2_CASELESS) != 0)? OP_DNREFI : OP_DNREF; @@ -7279,6 +7464,7 @@ for (;; pptr++) if (repeat_min > 0 && (repeat_min != 1 || repeat_max != REPEAT_UNLIMITED)) { int replicate = repeat_min; + if (repeat_min == repeat_max) replicate--; /* In the pre-compile phase, we don't actually do the replication. We @@ -7288,7 +7474,7 @@ for (;; pptr++) if (lengthptr != NULL) { PCRE2_SIZE delta; - if (PRIV(ckd_smul)(&delta, replicate, 1 + LINK_SIZE) || + if (PRIV(ckd_smul)(&delta, replicate, (int)length_prevgroup) || OFLOW_MAX - *lengthptr < delta) { *errorcodeptr = ERR20; @@ -7296,12 +7482,11 @@ for (;; pptr++) } *lengthptr += delta; } - else for (int i = 0; i < replicate; i++) { - memcpy(code, previous, CU2BYTES(1 + LINK_SIZE)); + memcpy(code, previous, CU2BYTES(length_prevgroup)); previous = code; - code += 1 + LINK_SIZE; + code += length_prevgroup; } /* If the number of repeats is fixed, we are done. Otherwise, adjust @@ -7313,18 +7498,21 @@ for (;; pptr++) } /* Wrap the recursion call in OP_BRA brackets. */ + { + PCRE2_SIZE length = (lengthptr != NULL) ? 1 + LINK_SIZE : length_prevgroup; - (void)memmove(previous + 1 + LINK_SIZE, previous, CU2BYTES(1 + LINK_SIZE)); - op_previous = *previous = OP_BRA; - PUT(previous, 1, 2 + 2*LINK_SIZE); - previous[2 + 2*LINK_SIZE] = OP_KET; - PUT(previous, 3 + 2*LINK_SIZE, 2 + 2*LINK_SIZE); + (void)memmove(previous + 1 + LINK_SIZE, previous, CU2BYTES(length)); + op_previous = *previous = OP_BRA; + PUT(previous, 1, 1 + LINK_SIZE + length); + previous[1 + LINK_SIZE + length] = OP_KET; + PUT(previous, 2 + LINK_SIZE + length, 1 + LINK_SIZE + length); + } code += 2 + 2 * LINK_SIZE; - length_prevgroup = 3 + 3*LINK_SIZE; + length_prevgroup += 2 + 2 * LINK_SIZE; group_return = -1; /* Set "may match empty string" */ /* Now treat as a repeated OP_BRA. */ - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* If previous was a bracket group, we may have to replicate it in certain cases. Note that at this point we can encounter only the "basic" @@ -7664,13 +7852,16 @@ for (;; pptr++) here because it just makes it horribly messy. */ default: + + /* LCOV_EXCL_START */ if (op_previous >= OP_EODN || op_previous <= OP_WORD_BOUNDARY) { PCRE2_DEBUG_UNREACHABLE(); *errorcodeptr = ERR10; /* Not a character type - internal error */ return 0; } - else + /* LCOV_EXCL_STOP */ + { int prop_type, prop_value; PCRE2_UCHAR *oldcode; @@ -7993,6 +8184,52 @@ for (;; pptr++) *code = OP_RECURSE; PUT(code, 1, meta_arg); code += 1 + LINK_SIZE; + /* Repeat processing requires this information to + determine the real length in pre-compile phase. */ + length_prevgroup = 1 + LINK_SIZE; + + if (META_CODE(pptr[1]) == META_OFFSET || + META_CODE(pptr[1]) == META_CAPTURE_NAME || + META_CODE(pptr[1]) == META_CAPTURE_NUMBER) + { + recurse_arguments *args; + + if (lengthptr != NULL) + { + if (!PRIV(compile_parse_recurse_args)(pptr, offset, errorcodeptr, cb)) + return 0; + + args = (recurse_arguments*)cb->last_data; + length_prevgroup += (args->size * (1 + IMM2_SIZE)); + *lengthptr += (args->size * (1 + IMM2_SIZE)); + pptr += args->skip_size; + } + else + { + uint16_t *current, *end; + + args = (recurse_arguments*)cb->first_data; + PCRE2_ASSERT(args != NULL && args->header.type == CDATA_RECURSE_ARGS); + + current = (uint16_t*)(args + 1); + end = current + args->size; + PCRE2_ASSERT(end > current); + + do + { + code[0] = OP_CREF; + PUT2(code, 1, *current); + code += 1 + IMM2_SIZE; + } + while (++current < end); + + length_prevgroup += (args->size * (1 + IMM2_SIZE)); + pptr += args->skip_size; + cb->first_data = args->header.next; + cb->cx->memctl.free(args, cb->cx->memctl.memory_data); + } + } + groupsetfirstcu = FALSE; cb->had_recurse = TRUE; if (firstcuflags == REQ_UNSET) firstcuflags = REQ_NONE; @@ -8117,6 +8354,7 @@ for (;; pptr++) cb->external_flags |= PCRE2_HASBKC; /* Record */ #if PCRE2_CODE_UNIT_WIDTH == 32 meta_arg = OP_ALLANY; + (void)utf; /* Avoid compiler warning. */ #else if (!utf) meta_arg = OP_ALLANY; #endif @@ -8127,11 +8365,15 @@ for (;; pptr++) if ((options & PCRE2_UCP) != 0 && (xoptions & PCRE2_EXTRA_ASCII_BSW) == 0) meta_arg = (meta_arg == ESC_B)? OP_NOT_UCP_WORD_BOUNDARY : OP_UCP_WORD_BOUNDARY; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_A: if (cb->max_lookbehind == 0) cb->max_lookbehind = 1; break; + + case ESC_K: + cb->external_flags |= PCRE2_HASBSK; /* Record */ + break; } *code++ = meta_arg; @@ -8143,12 +8385,14 @@ for (;; pptr++) META_END is a literal. Otherwise we have a problem. */ default: + /* LCOV_EXCL_START */ if (meta >= META_END) { PCRE2_DEBUG_UNREACHABLE(); *errorcodeptr = ERR89; /* Internal error - unrecognized. */ return 0; } + /* LCOV_EXCL_STOP */ /* Handle a literal character. We come here by goto in the case of a 32-bit, non-UTF character whose value is greater than META_END. */ @@ -8280,8 +8524,10 @@ for (;; pptr++) } /* End of big switch */ } /* End of big loop */ +/* LCOV_EXCL_START */ PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ return 0; /* Avoid compiler warnings */ +/* LCOV_EXCL_STOP */ } @@ -8346,6 +8592,7 @@ if (cb->cx->stack_guard != NULL && cb->cx->stack_guard(cb->parens_depth, cb->cx->stack_guard_data)) { *errorcodeptr= ERR33; + cb->erroroffset = 0; return 0; } @@ -8587,8 +8834,10 @@ for (;;) pptr++; } +/* LCOV_EXCL_START */ PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ return 0; /* Avoid compiler warnings */ +/* LCOV_EXCL_STOP */ } @@ -9060,7 +9309,7 @@ do { case OP_EXACT: scode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHAR: case OP_PLUS: @@ -9073,7 +9322,7 @@ do { case OP_EXACTI: scode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHARI: case OP_PLUSI: @@ -9108,67 +9357,6 @@ return c; -/************************************************* -* Add an entry to the name/number table * -*************************************************/ - -/* This function is called between compiling passes to add an entry to the -name/number table, maintaining alphabetical order. Checking for permitted -and forbidden duplicates has already been done. - -Arguments: - cb the compile data block - name the name to add - length the length of the name - groupno the group number - tablecount the count of names in the table so far - -Returns: nothing -*/ - -static void -add_name_to_table(compile_block *cb, PCRE2_SPTR name, int length, - unsigned int groupno, uint32_t tablecount) -{ -uint32_t i; -PCRE2_UCHAR *slot = cb->name_table; - -for (i = 0; i < tablecount; i++) - { - int crc = memcmp(name, slot+IMM2_SIZE, CU2BYTES(length)); - if (crc == 0 && slot[IMM2_SIZE+length] != 0) - crc = -1; /* Current name is a substring */ - - /* Make space in the table and break the loop for an earlier name. For a - duplicate or later name, carry on. We do this for duplicates so that in the - simple case (when ?(| is not used) they are in order of their numbers. In all - cases they are in the order in which they appear in the pattern. */ - - if (crc < 0) - { - (void)memmove(slot + cb->name_entry_size, slot, - CU2BYTES((tablecount - i) * cb->name_entry_size)); - break; - } - - /* Continue the loop for a later or duplicate name */ - - slot += cb->name_entry_size; - } - -PUT2(slot, 0, groupno); -memcpy(slot + IMM2_SIZE, name, CU2BYTES(length)); - -/* Add a terminating zero and fill the rest of the slot with zeroes so that -the memory is all initialized. Otherwise valgrind moans about uninitialized -memory when saving serialized compiled patterns. */ - -memset(slot + IMM2_SIZE + length, 0, - CU2BYTES(cb->name_entry_size - length - IMM2_SIZE)); -} - - - /************************************************* * Skip in parsed pattern * *************************************************/ @@ -9210,13 +9398,14 @@ for (;; pptr++) if (meta < META_END) continue; /* Literal */ break; - case META_END: - /* The parsed regex is malformed; we have reached the end and did not find the end of the construct which we are skipping over. */ + /* LCOV_EXCL_START */ + case META_END: PCRE2_DEBUG_UNREACHABLE(); return NULL; + /* LCOV_EXCL_STOP */ /* The data for these items is variable in length. */ @@ -9281,7 +9470,9 @@ for (;; pptr++) pptr += meta_extra_lengths[meta]; } +/* LCOV_EXCL_START */ PCRE2_UNREACHABLE(); /* Control never reaches here */ +/* LCOV_EXCL_STOP */ } @@ -9566,36 +9757,30 @@ for (;; pptr++) case META_BACKREF_BYNAME: if ((cb->external_options & PCRE2_MATCH_UNSET_BACKREF) != 0) goto ISNOTFIXED; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_RECURSE_BYNAME: { - int i; PCRE2_SPTR name; BOOL is_dupname = FALSE; - named_group *ng = cb->named_groups; + named_group *ng; uint32_t meta_code = META_CODE(*pptr); uint32_t length = *(++pptr); GETPLUSOFFSET(offset, pptr); name = cb->start_pattern + offset; - for (i = 0; i < cb->names_found; i++, ng++) - { - if (length == ng->length && PRIV(strncmp)(name, ng->name, length) == 0) - { - group = ng->number; - is_dupname = ng->isdup; - break; - } - } + ng = PRIV(compile_find_named_group)(name, length, cb); - if (group == 0) + if (ng == NULL) { *errcodeptr = ERR15; /* Non-existent subpattern */ cb->erroroffset = offset; return -1; } + group = ng->number; + is_dupname = (ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0; + /* A numerical back reference can be fixed length if duplicate capturing groups are not being used. A non-duplicate named back reference can also be handled. */ @@ -9621,7 +9806,7 @@ for (;; pptr++) goto RECURSE_OR_BACKREF_LENGTH; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* For groups >= 10 - picking up group twice does no harm. */ /* A true recursion implies not fixed length, but a subroutine call may @@ -9701,7 +9886,7 @@ for (;; pptr++) case META_CAPTURE: group = META_DATA(*pptr); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_ATOMIC: case META_NOCAPTURE: @@ -9748,7 +9933,7 @@ for (;; pptr++) else itemlength = (max - 1) * lastitemlength; break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Any other item means this branch does not have a fixed length. */ @@ -9783,10 +9968,12 @@ EXIT: *minptr = branchminlength; return branchlength; +/* LCOV_EXCL_START */ PARSED_SKIP_FAILED: PCRE2_DEBUG_UNREACHABLE(); *errcodeptr = ERR90; /* Unhandled META code - internal error */ return -1; +/* LCOV_EXCL_STOP */ } @@ -9922,15 +10109,16 @@ for (; *pptr != META_END; pptr++) switch (META_CODE(*pptr)) { - default: - /* The following erroroffset is a bogus but safe value. This branch should be avoided by providing a proper implementation for all supported cases below. */ + /* LCOV_EXCL_START */ + default: PCRE2_DEBUG_UNREACHABLE(); cb->erroroffset = 0; return ERR70; /* Unrecognized meta code */ + /* LCOV_EXCL_STOP */ case META_ESCAPE: if (*pptr - META_ESCAPE == ESC_P || *pptr - META_ESCAPE == ESC_p) @@ -10021,8 +10209,8 @@ for (; *pptr != META_END; pptr++) case META_BIGVALUE: case META_POSIX: case META_POSIX_NEG: - case META_SCS_NAME: - case META_SCS_NUMBER: + case META_CAPTURE_NAME: + case META_CAPTURE_NUMBER: pptr += 1; break; @@ -10093,8 +10281,9 @@ pcre2_real_code *re = NULL; /* What we will return */ compile_block cb; /* "Static" compile-time data */ const uint8_t *tables; /* Char tables base pointer */ +PCRE2_UCHAR null_str[1] = { 0xcd }; /* Dummy for handling null inputs */ PCRE2_UCHAR *code; /* Current pointer in compiled code */ -PCRE2_UCHAR * codestart; /* Start of compiled code */ +PCRE2_UCHAR *codestart; /* Start of compiled code */ PCRE2_SPTR ptr; /* Current pointer in pattern */ uint32_t *pptr; /* Current pointer in parsed pattern */ @@ -10141,7 +10330,16 @@ PCRE2_UCHAR *cworkspace = (PCRE2_UCHAR *)c16workspace; /* There must be error code and offset pointers. */ -if (errorptr == NULL || erroroffset == NULL) return NULL; +if (errorptr == NULL) + { + if (erroroffset != NULL) *erroroffset = 0; + return NULL; + } +if (erroroffset == NULL) + { + if (errorptr != NULL) *errorptr = ERR120; + return NULL; + } *errorptr = ERR0; *erroroffset = 0; @@ -10149,7 +10347,9 @@ if (errorptr == NULL || erroroffset == NULL) return NULL; if (pattern == NULL) { - if (patlen == 0) pattern = (PCRE2_SPTR)""; else + if (patlen == 0) + pattern = null_str; + else { *errorptr = ERR16; return NULL; @@ -10245,9 +10445,9 @@ cb.start_code = cworkspace; cb.start_pattern = pattern; cb.start_workspace = cworkspace; cb.workspace_size = COMPILE_WORK_SIZE; +cb.first_data = NULL; +cb.last_data = NULL; #ifdef SUPPORT_WIDE_CHARS -cb.cranges = NULL; -cb.next_cranges = NULL; cb.char_lists_size = 0; #endif @@ -10341,6 +10541,7 @@ if ((options & PCRE2_LITERAL) == 0) { errorcode = ERR60; ptr += pp; + utf = FALSE; /* Used by HAD_EARLY_ERROR */ goto HAD_EARLY_ERROR; } if (p->type == PSO_LIMH) limit_heap = c; @@ -10373,11 +10574,13 @@ if ((options & PCRE2_LITERAL) == 0) break; + /* LCOV_EXCL_START */ default: /* All values in the enum need an explicit entry for this switch but until a better way to prevent coding mistakes is invented keep a catch all that triggers a debug build assert as a failsafe */ PCRE2_DEBUG_UNREACHABLE(); + /* LCOV_EXCL_STOP */ } break; /* Out of the table scan loop */ } @@ -10500,10 +10703,12 @@ switch(newline) cb.nltype = NLTYPE_ANYCRLF; break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR56; goto HAD_EARLY_ERROR; + /* LCOV_EXCL_STOP */ } /* Pre-scan the pattern to do two things: (1) Discover the named groups and @@ -10632,6 +10837,7 @@ if (length > MAX_PATTERN_SIZE) #endif { errorcode = ERR20; + cb.erroroffset = 0; goto HAD_CB_ERROR; } @@ -10660,6 +10866,7 @@ re_blocksize += CU2BYTES(length); if (re_blocksize > ccontext->max_pattern_compiled_length) { errorcode = ERR101; + cb.erroroffset = 0; goto HAD_CB_ERROR; } @@ -10669,6 +10876,7 @@ re = (pcre2_real_code *) if (re == NULL) { errorcode = ERR21; + cb.erroroffset = 0; goto HAD_CB_ERROR; } @@ -10734,8 +10942,14 @@ created in the pre-pass. */ if (cb.names_found > 0) { named_group *ng = cb.named_groups; + uint32_t tablecount = 0; + + /* Length 0 represents duplicates, and they have already been handled. */ for (i = 0; i < cb.names_found; i++, ng++) - add_name_to_table(&cb, ng->name, ng->length, ng->number, i); + if (ng->length > 0) + tablecount = PRIV(compile_add_name_to_table)(&cb, ng, tablecount); + + PCRE2_ASSERT(tablecount == cb.names_found); } /* Set up a starting, non-extracting bracket, then compile the expression. On @@ -10767,18 +10981,20 @@ memory as unaddressable, so that any out-of-bound reads can be detected. */ *code++ = OP_END; usedlength = code - codestart; +/* LCOV_EXCL_START */ if (usedlength > length) { PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR23; /* Overflow of code block - internal error */ + cb.erroroffset = 0; + goto HAD_CB_ERROR; } -else - { - re->blocksize -= CU2BYTES(length - usedlength); +/* LCOV_EXCL_STOP */ + +re->blocksize -= CU2BYTES(length - usedlength); #ifdef SUPPORT_VALGRIND - VALGRIND_MAKE_MEM_NOACCESS(code, CU2BYTES(length - usedlength)); +VALGRIND_MAKE_MEM_NOACCESS(code, CU2BYTES(length - usedlength)); #endif - } /* Scan the pattern for recursion/subroutine calls and convert the group numbers into offsets. Maintain a small cache so that repeated groups containing @@ -10823,12 +11039,15 @@ if (errorcode == 0 && cb.had_recurse) if (rgroup == NULL) { rgroup = PRIV(find_bracket)(search_from, utf, groupnumber); + /* LCOV_EXCL_START */ if (rgroup == NULL) { PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR53; break; } + /* LCOV_EXCL_STOP */ + if (--start < 0) start = RSCAN_CACHE_SIZE - 1; rc[start].groupnumber = groupnumber; rc[start].group = rgroup; @@ -10858,11 +11077,15 @@ function call. */ if (errorcode == 0 && (optim_flags & PCRE2_OPTIM_AUTO_POSSESS) != 0) { PCRE2_UCHAR *temp = (PCRE2_UCHAR *)codestart; - if (PRIV(auto_possessify)(temp, &cb) != 0) + int possessify_rc = PRIV(auto_possessify)(temp, &cb); + /* LCOV_EXCL_START */ + if (possessify_rc != 0) { PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR80; + cb.erroroffset = 0; } + /* LCOV_EXCL_STOP */ } /* Failed to compile, or error while post-processing. */ @@ -10892,6 +11115,7 @@ unit. */ if ((optim_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) { int minminlength = 0; /* For minimal minlength from first/required CU */ + int study_rc; /* If we do not have a first code unit, see if there is one that is asserted (these are not saved during the compile because they can cause conflicts with @@ -11015,12 +11239,16 @@ if ((optim_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) /* Study the compiled pattern to set up information such as a bitmap of starting code units and a minimum matching length. */ - if (PRIV(study)(re) != 0) + study_rc = PRIV(study)(re); + /* LCOV_EXCL_START */ + if (study_rc != 0) { PCRE2_DEBUG_UNREACHABLE(); errorcode = ERR31; + cb.erroroffset = 0; goto HAD_CB_ERROR; } + /* LCOV_EXCL_STOP */ /* If study() set a bitmap of starting code units, it implies a minimum length of at least one. */ @@ -11041,7 +11269,8 @@ groups if a larger one had to be obtained, and likewise the group information vector. */ #ifdef SUPPORT_UNICODE -PCRE2_ASSERT(cb.cranges == NULL); +/* All items must be freed. */ +PCRE2_ASSERT(cb.first_data == NULL); #endif EXIT: @@ -11067,8 +11296,22 @@ HAD_CB_ERROR: ptr = pattern + cb.erroroffset; HAD_EARLY_ERROR: -PCRE2_ASSERT(ptr >= pattern); /* Ensure we don't return invalid erroroffset */ +/* Ensure we don't return out-of-range erroroffset. */ +PCRE2_ASSERT(ptr >= pattern); PCRE2_ASSERT(ptr <= (pattern + patlen)); +/* Ensure that the erroroffset never slices a UTF-encoded character in half. +If the input is invalid, then we return an offset just before the first invalid +character, so the text to the left of the offset must always be valid. */ +#if defined PCRE2_DEBUG && defined SUPPORT_UNICODE +if (ptr > pattern && utf) + { + PCRE2_SPTR prev = ptr - 1; + PCRE2_SIZE dummyoffset; + BACKCHAR(prev); + PCRE2_ASSERT(prev >= pattern); + PCRE2_ASSERT(PRIV(valid_utf)(prev, ptr - prev, &dummyoffset) == 0); + } +#endif *erroroffset = ptr - pattern; HAD_ERROR: @@ -11076,19 +11319,18 @@ HAD_ERROR: pcre2_code_free(re); re = NULL; -#ifdef SUPPORT_WIDE_CHARS -if (cb.cranges != NULL) +if (cb.first_data != NULL) { - class_ranges* cranges = cb.cranges; + compile_data* current_data = cb.first_data; do { - class_ranges* next_cranges = cranges->next; - cb.cx->memctl.free(cranges, cb.cx->memctl.memory_data); - cranges = next_cranges; + compile_data* next_data = current_data->next; + cb.cx->memctl.free(current_data, cb.cx->memctl.memory_data); + current_data = next_data; } - while (cranges != NULL); + while (current_data != NULL); } -#endif + goto EXIT; } diff --git a/libpcre/src/pcre2_compile.h b/libpcre/src/pcre2_compile.h index c8bf610be..331ca3ad3 100644 --- a/libpcre/src/pcre2_compile.h +++ b/libpcre/src/pcre2_compile.h @@ -51,18 +51,18 @@ pcre2.h.in must be updated - their values are exactly 100 greater than these values. */ enum { ERR0 = COMPILE_ERROR_BASE, - ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, - ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, - ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30, - ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40, - ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, ERR50, - ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, ERR60, - ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70, - ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80, - ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90, - ERR91, ERR92, ERR93, ERR94, ERR95, ERR96, ERR97, ERR98, ERR99, ERR100, - ERR101,ERR102,ERR103,ERR104,ERR105,ERR106,ERR107,ERR108,ERR109,ERR110, - ERR111,ERR112,ERR113,ERR114,ERR115,ERR116 }; + ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, + ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, + ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30, + ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40, + ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, ERR50, + ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, ERR60, + ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69, ERR70, + ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERR78, ERR79, ERR80, + ERR81, ERR82, ERR83, ERR84, ERR85, ERR86, ERR87, ERR88, ERR89, ERR90, + ERR91, ERR92, ERR93, ERR94, ERR95, ERR96, ERR97, ERR98, ERR99, ERR100, + ERR101, ERR102, ERR103, ERR104, ERR105, ERR106, ERR107, ERR108, ERR109, ERR110, + ERR111, ERR112, ERR113, ERR114, ERR115, ERR116, ERR117, ERR118, ERR119, ERR120 }; /* Code values for parsed patterns, which are stored in a vector of 32-bit unsigned ints. Values less than META_END are literal data values. The coding @@ -96,11 +96,11 @@ code (meta_extra_lengths) must be updated to remain in step. */ #define META_COND_RNAME 0x80130000u /* (?(R&name)... */ #define META_COND_RNUMBER 0x80140000u /* (?(Rdigits)... */ #define META_COND_VERSION 0x80150000u /* (?(VERSIONx.y)... */ -#define META_OFFSET 0x80160000u /* Setting offset for various - META codes (e.g. META_SCS_NAME) */ +#define META_OFFSET 0x80160000u /* Setting offset for various META + codes (e.g. META_CAPTURE_NAME) */ #define META_SCS 0x80170000u /* (*scan_substring:... */ -#define META_SCS_NAME 0x80180000u /* Next of scan_substring */ -#define META_SCS_NUMBER 0x80190000u /* Next digits of scan_substring */ +#define META_CAPTURE_NAME 0x80180000u /* Next in capture lists */ +#define META_CAPTURE_NUMBER 0x80190000u /* Next digits in capture lists */ #define META_DOLLAR 0x801a0000u /* $ metacharacter */ #define META_DOT 0x801b0000u /* . metacharacter */ #define META_ESCAPE 0x801c0000u /* \d and friends */ @@ -186,6 +186,36 @@ therefore no need for it to have a length entry, so use a high value. */ #define META_DATA(x) (x & 0x0000ffffu) #define META_DIFF(x,y) ((x-y)>>16) +/* Macros to store and retrieve a PCRE2_SIZE value in the parsed pattern, which +consists of uint32_t elements. Assume that if uint32_t can't hold it, two of +them will be able to (i.e. assume a 64-bit world). */ + +#if PCRE2_SIZE_MAX <= UINT32_MAX +#define PUTOFFSET(s,p) *p++ = s +#define GETOFFSET(s,p) s = *p++ +#define GETPLUSOFFSET(s,p) s = *(++p) +#define READPLUSOFFSET(s,p) s = p[1] +#define SKIPOFFSET(p) p++ +#define SIZEOFFSET 1 +#else +#define PUTOFFSET(s,p) \ + { *p++ = (uint32_t)(s >> 32); *p++ = (uint32_t)(s & 0xffffffff); } +#define GETOFFSET(s,p) \ + { s = ((PCRE2_SIZE)p[0] << 32) | (PCRE2_SIZE)p[1]; p += 2; } +#define GETPLUSOFFSET(s,p) \ + { s = ((PCRE2_SIZE)p[1] << 32) | (PCRE2_SIZE)p[2]; p += 2; } +#define READPLUSOFFSET(s,p) \ + { s = ((PCRE2_SIZE)p[1] << 32) | (PCRE2_SIZE)p[2]; } +#define SKIPOFFSET(p) p += 2 +#define SIZEOFFSET 2 +#endif + +#ifdef PCRE2_DEBUG +/* Compile data types. */ +#define CDATA_RECURSE_ARGS 0 /* Argument list for recurse */ +#define CDATA_CRANGE 1 /* Character range list */ +#endif + /* Extended class management flags. */ #define CLASS_IS_ECLASS 0x1 @@ -236,10 +266,16 @@ typedef struct { /* Macros for the definitions below, to prevent name collisions. */ -#define _pcre2_posix_class_maps PCRE2_SUFFIX(_pcre2_posix_class_maps) -#define _pcre2_update_classbits PCRE2_SUFFIX(_pcre2_update_classbits_) -#define _pcre2_compile_class_nested PCRE2_SUFFIX(_pcre2_compile_class_nested_) -#define _pcre2_compile_class_not_nested PCRE2_SUFFIX(_pcre2_compile_class_not_nested_) +#define _pcre2_posix_class_maps PCRE2_SUFFIX(_pcre2_posix_class_maps) +#define _pcre2_update_classbits PCRE2_SUFFIX(_pcre2_update_classbits_) +#define _pcre2_compile_class_nested PCRE2_SUFFIX(_pcre2_compile_class_nested_) +#define _pcre2_compile_class_not_nested PCRE2_SUFFIX(_pcre2_compile_class_not_nested_) +#define _pcre2_compile_get_hash_from_name PCRE2_SUFFIX(_pcre2_compile_get_hash_from_name) +#define _pcre2_compile_find_named_group PCRE2_SUFFIX(_pcre2_compile_find_named_group) +#define _pcre2_compile_find_dupname_details PCRE2_SUFFIX(_pcre2_compile_find_dupname_details) +#define _pcre2_compile_add_name_to_table PCRE2_SUFFIX(_pcre2_compile_add_name_to_table) +#define _pcre2_compile_parse_scan_substr_args PCRE2_SUFFIX(_pcre2_compile_parse_scan_substr_args) +#define _pcre2_compile_parse_recurse_args PCRE2_SUFFIX(_pcre2_compile_parse_recurse_args) /* Indices of the POSIX classes in posix_names, posix_name_lengths, @@ -253,6 +289,14 @@ posix_class_maps, and posix_substitutes. They must be kept in sync. */ extern const int PRIV(posix_class_maps)[]; +/* Defines for hash_dup member in named_group structure. */ + +#define NAMED_GROUP_HASH_MASK ((uint16_t)0x7fff) +#define NAMED_GROUP_IS_DUPNAME ((uint16_t)0x8000) + +#define NAMED_GROUP_GET_HASH(ng) ((ng)->hash_dup & NAMED_GROUP_HASH_MASK) + +/* Exported functions from pcre2_compile_class.c file: */ /* Set bits in classbits according to the property type */ @@ -275,6 +319,38 @@ BOOL PRIV(compile_class_nested)(uint32_t options, uint32_t xoptions, uint32_t **pptr, PCRE2_UCHAR **pcode, int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr); +/* Exported functions from pcre2_compile_cgroup.c file: */ + +/* Compute hash from a capture name. */ + +uint16_t PRIV(compile_get_hash_from_name)(PCRE2_SPTR name, uint32_t length); + +/* Get the descriptor of a known named capture. */ + +named_group *PRIV(compile_find_named_group)(PCRE2_SPTR name, + uint32_t length, compile_block *cb); + +/* Add entires to name table in alphabetical order. */ + +uint32_t PRIV(compile_add_name_to_table)(compile_block *cb, + named_group *ng, uint32_t tablecount); + +/* Searches the properties of duplicated names, and returns them +in indexptr and countptr. */ + +BOOL PRIV(compile_find_dupname_details)(PCRE2_SPTR name, uint32_t length, + int *indexptr, int *countptr, int *errorcodeptr, compile_block *cb); + +/* Parse the arguments of recurse operations. */ + +uint32_t * PRIV(compile_parse_scan_substr_args)(uint32_t *pptr, + int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr); + +/* Parse the arguments of recurse operations. */ + +BOOL PRIV(compile_parse_recurse_args)(uint32_t *pptr_start, + PCRE2_SIZE offset, int *errorcodeptr, compile_block *cb); + #endif /* PCRE2_COMPILE_H_IDEMPOTENT_GUARD */ /* End of pcre2_compile.h */ diff --git a/libpcre/src/pcre2_compile_cgroup.c b/libpcre/src/pcre2_compile_cgroup.c new file mode 100644 index 000000000..ee0cd06b7 --- /dev/null +++ b/libpcre/src/pcre2_compile_cgroup.c @@ -0,0 +1,632 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Original API code Copyright (c) 1997-2012 University of Cambridge + New API code Copyright (c) 2016-2024 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +#include "pcre2_compile.h" + +/************************************************* +* Compute the hash code from a capture name * +*************************************************/ + +/* This function returns with a simple hash code +computed from the name of a capture group. + +Arguments: + name name of the capture group + length the length of the name + +Returns: hash code +*/ + +uint16_t +PRIV(compile_get_hash_from_name)(PCRE2_SPTR name, uint32_t length) +{ +uint16_t hash; + +PCRE2_ASSERT(length > 0); + +hash = (uint16_t)((name[0] & 0x7f) | ((name[length - 1] & 0xff) << 7)); +PCRE2_ASSERT(hash <= NAMED_GROUP_HASH_MASK); +return hash; +} + + +/************************************************* +* Get the descriptor of a known named capture * +*************************************************/ + +/* This function returns the descriptor in the +named group list of a known capture group. + +Arguments: + name name of the capture group + length the length of the name + +Returns: pointer to the descriptor when found, + NULL otherwise + */ + +named_group * +PRIV(compile_find_named_group)(PCRE2_SPTR name, + uint32_t length, compile_block *cb) +{ +uint16_t hash = PRIV(compile_get_hash_from_name)(name, length); +named_group *ng; +named_group *end = cb->named_groups + cb->names_found; + +for (ng = cb->named_groups; ng < end; ng++) + if (length == ng->length && hash == NAMED_GROUP_GET_HASH(ng) && + PRIV(strncmp)(name, ng->name, length) == 0) return ng; + +return NULL; +} + + +/************************************************* +* Add an entry to the name/number table * +*************************************************/ + +/* This function is called between compiling passes to add an entry to the +name/number table, maintaining alphabetical order. Checking for permitted +and forbidden duplicates has already been done. + +Arguments: + cb the compile data block + nb named group entry + tablecount the count of names in the table so far + +Returns: new tablecount +*/ + +uint32_t +PRIV(compile_add_name_to_table)(compile_block *cb, + named_group *ng, uint32_t tablecount) +{ +uint32_t i; +PCRE2_SPTR name = ng->name; +int length = ng->length; +uint32_t duplicate_count = 1; + +PCRE2_UCHAR *slot = cb->name_table; + +PCRE2_ASSERT(length > 0); + +if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0) + { + named_group *ng_it; + named_group *end = cb->named_groups + cb->names_found; + + for (ng_it = ng + 1; ng_it < end; ng_it++) + if (ng_it->name == name) duplicate_count++; + } + +for (i = 0; i < tablecount; i++) + { + int crc = memcmp(name, slot + IMM2_SIZE, CU2BYTES(length)); + if (crc == 0 && slot[IMM2_SIZE + length] != 0) + crc = -1; /* Current name is a substring */ + + /* Make space in the table and break the loop for an earlier name. For a + duplicate or later name, carry on. We do this for duplicates so that in the + simple case (when ?(| is not used) they are in order of their numbers. In all + cases they are in the order in which they appear in the pattern. */ + + if (crc < 0) + { + (void)memmove(slot + cb->name_entry_size * duplicate_count, slot, + CU2BYTES((tablecount - i) * cb->name_entry_size)); + break; + } + + /* Continue the loop for a later or duplicate name */ + + slot += cb->name_entry_size; + } + +tablecount += duplicate_count; + +while (TRUE) + { + PUT2(slot, 0, ng->number); + memcpy(slot + IMM2_SIZE, name, CU2BYTES(length)); + + /* Add a terminating zero and fill the rest of the slot with zeroes so that + the memory is all initialized. Otherwise valgrind moans about uninitialized + memory when saving serialized compiled patterns. */ + + memset(slot + IMM2_SIZE + length, 0, + CU2BYTES(cb->name_entry_size - length - IMM2_SIZE)); + + if (--duplicate_count == 0) break; + + while (TRUE) + { + ++ng; + if (ng->name == name) break; + } + + slot += cb->name_entry_size; + } + +return tablecount; +} + + +/************************************************* +* Find details of duplicate group names * +*************************************************/ + +/* This is called from compile_branch() when it needs to know the index and +count of duplicates in the names table when processing named backreferences, +either directly, or as conditions. + +Arguments: + name points to the name + length the length of the name + indexptr where to put the index + countptr where to put the count of duplicates + errorcodeptr where to put an error code + cb the compile block + +Returns: TRUE if OK, FALSE if not, error code set +*/ + +BOOL +PRIV(compile_find_dupname_details)(PCRE2_SPTR name, uint32_t length, + int *indexptr, int *countptr, int *errorcodeptr, compile_block *cb) +{ +uint32_t i, groupnumber; +int count; +PCRE2_UCHAR *slot = cb->name_table; + +/* Find the first entry in the table */ + +for (i = 0; i < cb->names_found; i++) + { + if (PRIV(strncmp)(name, slot + IMM2_SIZE, length) == 0 && + slot[IMM2_SIZE + length] == 0) break; + slot += cb->name_entry_size; + } + +/* This should not occur, because this function is called only when we know we +have duplicate names. Give an internal error. */ + +/* LCOV_EXCL_START */ +if (i >= cb->names_found) + { + PCRE2_DEBUG_UNREACHABLE(); + *errorcodeptr = ERR53; + cb->erroroffset = name - cb->start_pattern; + return FALSE; + } +/* LCOV_EXCL_STOP */ + +/* Record the index and then see how many duplicates there are, updating the +backref map and maximum back reference as we do. */ + +*indexptr = i; +count = 0; + +for (;;) + { + count++; + groupnumber = GET2(slot, 0); + cb->backref_map |= (groupnumber < 32)? (1u << groupnumber) : 1; + if (groupnumber > cb->top_backref) cb->top_backref = groupnumber; + if (++i >= cb->names_found) break; + slot += cb->name_entry_size; + if (PRIV(strncmp)(name, slot + IMM2_SIZE, length) != 0 || + (slot + IMM2_SIZE)[length] != 0) break; + } + +*countptr = count; +return TRUE; +} + + +/* Process the capture list of scan substring and recurse +operations. Since at least one argument must be present, +a 0 return value represents error. */ + +static size_t +PRIV(compile_process_capture_list)(uint32_t *pptr, PCRE2_SIZE offset, + int *errorcodeptr, compile_block *cb) +{ +size_t i, size = 0; +named_group *ng; +PCRE2_SPTR name; +uint32_t length; +named_group *end = cb->named_groups + cb->names_found; + +while (TRUE) + { + ++pptr; + + switch (META_CODE(*pptr)) + { + case META_OFFSET: + GETPLUSOFFSET(offset, pptr); + continue; + + case META_CAPTURE_NAME: + offset += META_DATA(*pptr); + length = *(++pptr); + name = cb->start_pattern + offset; + + ng = PRIV(compile_find_named_group)(name, length, cb); + + if (ng == NULL) + { + *errorcodeptr = ERR15; + cb->erroroffset = offset; + return 0; + } + + if ((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) == 0) + { + pptr[-1] = META_CAPTURE_NUMBER; + pptr[0] = ng->number; + size++; + continue; + } + + /* Remains only for duplicated names. */ + pptr[-1] = META_CAPTURE_NAME; + pptr[0] = (uint32_t)(ng - cb->named_groups); + size++; + name = ng->name; + + while (++ng < end) + if (ng->name == name) size++; + continue; + + case META_CAPTURE_NUMBER: + offset += META_DATA(*pptr); + + i = *(++pptr); + if (i > cb->bracount) + { + *errorcodeptr = ERR15; + cb->erroroffset = offset; + return 0; + } + if (i > cb->top_backref) cb->top_backref = (uint16_t)i; + size++; + continue; + + default: + break; + } + + PCRE2_ASSERT(size > 0); + return size; + } +} + + +/******************************************************* +* Parse the arguments of scan substring operations * +********************************************************/ + +/* This function parses the arguments of scan substring operations. + +Arguments: + pptr_start points to the current parsed pattern pointer + offset argument starting offset in the pattern + errorcodeptr where to put an error code + cb the compile block + lengthptr NULL during the real compile phase + points to length accumulator during pre-compile phase + +Returns: TRUE if OK, FALSE if not, error code set +*/ + +uint32_t * +PRIV(compile_parse_scan_substr_args)(uint32_t *pptr, + int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr) +{ +uint8_t *captures; +uint8_t *capture_ptr; +uint8_t bit; +PCRE2_SPTR name; +named_group *ng; +named_group *end = cb->named_groups + cb->names_found; +BOOL all_found; +size_t size; + +PCRE2_ASSERT(*pptr == META_OFFSET); +if (PRIV(compile_process_capture_list)(pptr - 1, 0, errorcodeptr, cb) == 0) + return NULL; + +/* Align to bytes. Since the highest capture can +be equal to bracount, +1 is added before the aligning. */ +size = (cb->bracount + 1 + 7) >> 3; +captures = (uint8_t*)cb->cx->memctl.malloc(size, cb->cx->memctl.memory_data); +if (captures == NULL) + { + *errorcodeptr = ERR21; + READPLUSOFFSET(cb->erroroffset, pptr); + return NULL; + } + +memset(captures, 0, size); + +while (TRUE) + { + switch (META_CODE(*pptr)) + { + case META_OFFSET: + pptr++; + SKIPOFFSET(pptr); + continue; + + case META_CAPTURE_NAME: + ng = cb->named_groups + pptr[1]; + PCRE2_ASSERT((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0); + pptr += 2; + name = ng->name; + + all_found = TRUE; + do + { + if (ng->name != name) continue; + + capture_ptr = captures + (ng->number >> 3); + PCRE2_ASSERT(capture_ptr < captures + size); + bit = (uint8_t)(1 << (ng->number & 0x7)); + + if ((*capture_ptr & bit) == 0) + { + *capture_ptr |= bit; + all_found = FALSE; + } + } + while (++ng < end); + + if (!all_found) + { + *lengthptr += 1 + 2 * IMM2_SIZE; + continue; + } + + pptr[-2] = META_CAPTURE_NUMBER; + pptr[-1] = 0; + continue; + + case META_CAPTURE_NUMBER: + pptr += 2; + + capture_ptr = captures + (pptr[-1] >> 3); + PCRE2_ASSERT(capture_ptr < captures + size); + bit = (uint8_t)(1 << (pptr[-1] & 0x7)); + + if ((*capture_ptr & bit) != 0) + { + pptr[-1] = 0; + continue; + } + + *capture_ptr |= bit; + *lengthptr += 1 + IMM2_SIZE; + continue; + + default: + break; + } + + break; + } + +cb->cx->memctl.free(captures, cb->cx->memctl.memory_data); +return pptr - 1; +} + + +/* Implement heapsort heapify algorithm. */ + +static void do_heapify_u16(uint16_t *captures, size_t size, size_t i) +{ +size_t max; +size_t left; +size_t right; +uint16_t tmp; + +while (TRUE) + { + max = i; + left = (i << 1) + 1; + right = left + 1; + + if (left < size && captures[left] > captures[max]) max = left; + if (right < size && captures[right] > captures[max]) max = right; + if (i == max) return; + + tmp = captures[i]; + captures[i] = captures[max]; + captures[max] = tmp; + i = max; + } +} + + +/************************************************* +* Parse the arguments of recurse operations * +*************************************************/ + +/* This function parses the arguments of recurse operations. + +Arguments: + pptr_start the current parsed pattern pointer + offset argument starting offset in the pattern + errorcodeptr where to put an error code + cb the compile block + lengthptr NULL during the real compile phase + points to length accumulator during pre-compile phase + +Returns: TRUE if OK, FALSE if not, error code set +*/ + +BOOL +PRIV(compile_parse_recurse_args)(uint32_t *pptr_start, + PCRE2_SIZE offset, int *errorcodeptr, compile_block *cb) +{ +uint32_t *pptr = pptr_start; +size_t i, size; +PCRE2_SPTR name; +named_group *ng; +named_group *end = cb->named_groups + cb->names_found; +recurse_arguments *args; +uint16_t *captures; +uint16_t *current; +uint16_t *captures_end; +uint16_t tmp; + +/* Process all arguments, compute the required size. */ + +size = PRIV(compile_process_capture_list)(pptr, offset, errorcodeptr, cb); +if (size == 0) return FALSE; + +args = cb->cx->memctl.malloc( + sizeof(recurse_arguments) + size * sizeof(uint16_t), cb->cx->memctl.memory_data); + +if (args == NULL) + { + *errorcodeptr = ERR21; + cb->erroroffset = offset; + return FALSE; + } + +args->header.next = NULL; +#ifdef PCRE2_DEBUG +args->header.type = CDATA_RECURSE_ARGS; +#endif +args->size = size; + +/* Caching the pre-processed capture list. */ +if (cb->last_data != NULL) + cb->last_data->next = &args->header; +else + cb->first_data = &args->header; + +cb->last_data = &args->header; + +/* Create the capture list size. */ + +captures = (uint16_t*)(args + 1); + +while (TRUE) + { + ++pptr; + + switch (META_CODE(*pptr)) + { + case META_OFFSET: + SKIPOFFSET(pptr); + continue; + + case META_CAPTURE_NAME: + ng = cb->named_groups + *(++pptr); + PCRE2_ASSERT((ng->hash_dup & NAMED_GROUP_IS_DUPNAME) != 0); + *captures++ = (uint16_t)(ng->number); + + name = ng->name; + + while (++ng < end) + if (ng->name == name) *captures++ = (uint16_t)(ng->number); + continue; + + case META_CAPTURE_NUMBER: + *captures++ = *(++pptr); + continue; + + default: + break; + } + + break; + } + +PCRE2_ASSERT(size == (size_t)(captures - (uint16_t*)(args + 1))); +args->skip_size = (size_t)(pptr - pptr_start) - 1; + +if (size == 1) return TRUE; + +/* Sort captures. */ + +captures = (uint16_t*)(args + 1); +i = (size >> 1) - 1; +while (TRUE) + { + do_heapify_u16(captures, size, i); + if (i == 0) break; + i--; + } + +for (i = size - 1; i > 0; i--) + { + tmp = captures[0]; + captures[0] = captures[i]; + captures[i] = tmp; + + do_heapify_u16(captures, i, 0); + } + +/* Remove duplicates. */ + +captures_end = captures + size; +tmp = *captures++; +current = captures; + +while (current < captures_end) + { + if (*current != tmp) + { + tmp = *current; + *captures++ = tmp; + } + + current++; + } + +args->size = (size_t)(captures - (uint16_t*)(args + 1)); +return TRUE; +} + +/* End of pcre2_compile_cgroup.c */ diff --git a/libpcre/src/pcre2_compile_class.c b/libpcre/src/pcre2_compile_class.c index 6a73bb9a7..9a1fc022f 100644 --- a/libpcre/src/pcre2_compile_class.c +++ b/libpcre/src/pcre2_compile_class.c @@ -38,12 +38,11 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "pcre2_compile.h" + + typedef struct { /* Option bits for eclass. */ uint32_t options; @@ -66,7 +65,7 @@ b) none of the cases here: #define CLASS_END_CASES(meta) \ default: \ PCRE2_ASSERT((meta) <= META_END); \ - /* Fall through */ \ + PCRE2_FALLTHROUGH /* Fall through */ \ case META_CLASS: \ case META_CLASS_NOT: \ case META_CLASS_EMPTY: \ @@ -525,6 +524,9 @@ if (xoptions & PCRE2_EXTRA_CASELESS_RESTRICT) if (xoptions & PCRE2_EXTRA_TURKISH_CASING) class_options |= PARSE_CLASS_TURKISH_UTF; +#else +(void)options; /* Avoid compiler warning. */ +(void)xoptions; /* Avoid compiler warning. */ #endif /* Compute required space for the range. */ @@ -543,7 +545,10 @@ cranges = cb->cx->memctl.malloc( if (cranges == NULL) return NULL; -cranges->next = NULL; +cranges->header.next = NULL; +#ifdef PCRE2_DEBUG +cranges->header.type = CDATA_CRANGE; +#endif cranges->range_list_size = (uint16_t)range_list_size; cranges->char_lists_types = 0; cranges->char_lists_size = 0; @@ -905,6 +910,10 @@ uint8_t *classbits = cb->classbits.classbits; uint32_t c, byte_start, byte_end; uint32_t classbits_end = (end <= 0xff ? end : 0xff); +#ifndef SUPPORT_UNICODE +(void)xoptions; /* Avoid compiler warning. */ +#endif + /* If caseless matching is required, scan the range and process alternate cases. In Unicode, there are 8-bit characters that have alternate cases that are greater than 255 and vice-versa (though these may be ignored if caseless @@ -1080,6 +1089,10 @@ BOOL utf = FALSE; uint32_t xclass_props; PCRE2_UCHAR *class_uchardata; class_ranges* cranges; +#else +(void)has_bitmap; /* Avoid compiler warning. */ +(void)errorcodeptr; /* Avoid compiler warning. */ +(void)lengthptr; /* Avoid compiler warning. */ #endif /* If an XClass contains a negative special such as \S, we need to flip the @@ -1112,19 +1125,19 @@ if (utf) } /* Caching the pre-processed character ranges. */ - if (cb->next_cranges != NULL) - cb->next_cranges->next = cranges; + if (cb->last_data != NULL) + cb->last_data->next = &cranges->header; else - cb->cranges = cranges; + cb->first_data = &cranges->header; - cb->next_cranges = cranges; + cb->last_data = &cranges->header; } else { /* Reuse the pre-processed character ranges. */ - cranges = cb->cranges; - PCRE2_ASSERT(cranges != NULL); - cb->cranges = cranges->next; + cranges = (class_ranges*)cb->first_data; + PCRE2_ASSERT(cranges != NULL && cranges->header.type == CDATA_CRANGE); + cb->first_data = cranges->header.next; } if (cranges->range_list_size > 0) @@ -1270,8 +1283,23 @@ while (TRUE) value of 1 removes vertical space and 2 removes underscore. */ if (tabopt < 0) tabopt = -tabopt; +#ifdef EBCDIC + { + uint8_t posix_vertical[4] = { CHAR_LF, CHAR_VT, CHAR_FF, CHAR_CR }; + uint8_t posix_underscore = CHAR_UNDERSCORE; + uint8_t *chars = NULL; + int n = 0; + + if (tabopt == 1) { chars = posix_vertical; n = 4; } + else if (tabopt == 2) { chars = &posix_underscore; n = 1; } + + for (; n > 0; ++chars, --n) + pbits.classbits[*chars/8] &= ~(1u << (*chars&7)); + } +#else if (tabopt == 1) pbits.classbits[1] &= ~0x3c; - else if (tabopt == 2) pbits.classbits[11] &= 0x7f; + else if (tabopt == 2) pbits.classbits[11] &= 0x7f; +#endif /* Add the POSIX table or its complement into the main table that is being built and we are done. */ @@ -2079,9 +2107,11 @@ switch (op) lhs_op_info->bits.classwords[i] ^= rhs_op_info->bits.classwords[i]; break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); break; + /* LCOV_EXCL_STOP */ } } @@ -2141,7 +2171,7 @@ switch (meta) } ptr++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ default: /* Scan forward characters, ranges, and properties. @@ -2158,11 +2188,13 @@ switch (meta) /* We must have a 100% guarantee that ptr increases when compile_class_operand() returns, even on Release builds, so that we can statically prove our loops terminate. */ + /* LCOV_EXCL_START */ if (ptr <= prev_ptr) { PCRE2_DEBUG_UNREACHABLE(); return FALSE; } + /* LCOV_EXCL_STOP */ /* If we fell through above, consume the closing ']'. */ if (meta == META_CLASS || meta == META_CLASS_NOT) diff --git a/libpcre/src/pcre2_config.c b/libpcre/src/pcre2_config.c index 031981b09..045f6e78d 100644 --- a/libpcre/src/pcre2_config.c +++ b/libpcre/src/pcre2_config.c @@ -38,18 +38,11 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* Save the configured link size, which is in bytes. In 16-bit and 32-bit modes -its value gets changed by pcre2_intmodedep.h (included by pcre2_internal.h) to -be in code units. */ - -static int configured_link_size = LINK_SIZE; #include "pcre2_internal.h" + + /* These macros are the standard way of turning unquoted text into C strings. They allow macros like PCRE2_MAJOR to be defined without quotes, which is convenient for user programs that want to test their values. */ @@ -79,7 +72,7 @@ pcre2_config(uint32_t what, void *where) { if (where == NULL) /* Requests a length */ { - switch(what) + switch (what) { default: return PCRE2_ERROR_BADOPTION; @@ -87,6 +80,7 @@ if (where == NULL) /* Requests a length */ case PCRE2_CONFIG_BSR: case PCRE2_CONFIG_COMPILED_WIDTHS: case PCRE2_CONFIG_DEPTHLIMIT: + case PCRE2_CONFIG_EFFECTIVE_LINKSIZE: case PCRE2_CONFIG_HEAPLIMIT: case PCRE2_CONFIG_JIT: case PCRE2_CONFIG_LINKSIZE: @@ -124,13 +118,13 @@ switch (what) case PCRE2_CONFIG_COMPILED_WIDTHS: *((uint32_t *)where) = 0 #ifdef SUPPORT_PCRE2_8 - + 1 + + (1 << 0) #endif #ifdef SUPPORT_PCRE2_16 - + 2 + + (1 << 1) #endif #ifdef SUPPORT_PCRE2_32 - + 4 + + (1 << 2) #endif ; break; @@ -139,6 +133,10 @@ switch (what) *((uint32_t *)where) = MATCH_LIMIT_DEPTH; break; + case PCRE2_CONFIG_EFFECTIVE_LINKSIZE: + *((uint32_t *)where) = LINK_SIZE * sizeof(PCRE2_UCHAR); + break; + case PCRE2_CONFIG_HEAPLIMIT: *((uint32_t *)where) = HEAP_LIMIT; break; @@ -163,7 +161,7 @@ switch (what) #endif case PCRE2_CONFIG_LINKSIZE: - *((uint32_t *)where) = (uint32_t)configured_link_size; + *((uint32_t *)where) = (uint32_t)CONFIGURED_LINK_SIZE; break; case PCRE2_CONFIG_MATCHLIMIT: @@ -206,8 +204,7 @@ switch (what) #endif return (int)(1 + ((where == NULL)? strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v))); - } - break; + } case PCRE2_CONFIG_UNICODE: #if defined SUPPORT_UNICODE @@ -244,6 +241,7 @@ switch (what) return (int)(1 + ((where == NULL)? strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v))); } + } return 0; diff --git a/libpcre/src/pcre2_context.c b/libpcre/src/pcre2_context.c index 2345145d3..6246683df 100644 --- a/libpcre/src/pcre2_context.c +++ b/libpcre/src/pcre2_context.c @@ -39,10 +39,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" @@ -506,10 +502,7 @@ return 0; } /* These functions became obsolete at release 10.30. The first is kept as a -synonym for backwards compatibility. The second now does nothing. Exclude both -from coverage reports. */ - -/* LCOV_EXCL_START */ +synonym for backwards compatibility. The second now does nothing. */ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t limit) @@ -529,8 +522,6 @@ pcre2_set_recursion_memory_management(pcre2_match_context *mcontext, return 0; } -/* LCOV_EXCL_STOP */ - /* ------------ Convert context ------------ */ @@ -543,10 +534,20 @@ ccontext->glob_separator = separator; return 0; } +static const char *globpunct = + STR_EXCLAMATION_MARK STR_QUOTATION_MARK STR_NUMBER_SIGN STR_DOLLAR_SIGN + STR_PERCENT_SIGN STR_AMPERSAND STR_APOSTROPHE STR_LEFT_PARENTHESIS + STR_RIGHT_PARENTHESIS STR_ASTERISK STR_PLUS STR_COMMA STR_MINUS STR_DOT + STR_SLASH STR_COLON STR_SEMICOLON STR_LESS_THAN_SIGN STR_EQUALS_SIGN + STR_GREATER_THAN_SIGN STR_QUESTION_MARK STR_COMMERCIAL_AT + STR_LEFT_SQUARE_BRACKET STR_BACKSLASH STR_RIGHT_SQUARE_BRACKET + STR_CIRCUMFLEX_ACCENT STR_UNDERSCORE STR_GRAVE_ACCENT STR_LEFT_CURLY_BRACKET + STR_VERTICAL_LINE STR_RIGHT_CURLY_BRACKET STR_TILDE; + PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_set_glob_escape(pcre2_convert_context *ccontext, uint32_t escape) { -if (escape > 255 || (escape != 0 && !ispunct(escape))) +if (escape > 255 || (escape != 0 && strchr(globpunct, escape) == NULL)) return PCRE2_ERROR_BADDATA; ccontext->glob_escape = escape; return 0; diff --git a/libpcre/src/pcre2_convert.c b/libpcre/src/pcre2_convert.c index d2b238ca4..ad7312ab7 100644 --- a/libpcre/src/pcre2_convert.c +++ b/libpcre/src/pcre2_convert.c @@ -39,12 +39,10 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + + #define TYPE_OPTIONS (PCRE2_CONVERT_GLOB| \ PCRE2_CONVERT_POSIX_BASIC|PCRE2_CONVERT_POSIX_EXTENDED) @@ -81,6 +79,16 @@ enum { POSIX_START_REGEX, POSIX_ANCHORED, POSIX_NOT_BRACKET, } \ } +/* Macro to check for lowercase characters. */ + +#ifdef EBCDIC +#define ISLOWER(c) (((c) >= CHAR_a && (c) <= CHAR_i) || \ + ((c) >= CHAR_j && (c) <= CHAR_r) || \ + ((c) >= CHAR_s && (c) <= CHAR_z)) +#else +#define ISLOWER(c) ((c) >= CHAR_a && (c) <= CHAR_z) +#endif + /* Literals that must be escaped: \ ? * + | . ^ $ { } [ ] ( ) */ static const char *pcre2_escaped_literals = @@ -97,6 +105,24 @@ static const char *posix_meta_escapes = STR_LEFT_CURLY_BRACKET STR_RIGHT_CURLY_BRACKET STR_1 STR_2 STR_3 STR_4 STR_5 STR_6 STR_7 STR_8 STR_9; +/* Recognized POSIX classes, colon-separated. */ + +static const char *posix_classes = + STR_a STR_l STR_p STR_h STR_a STR_COLON + STR_l STR_o STR_w STR_e STR_r STR_COLON + STR_u STR_p STR_p STR_e STR_r STR_COLON + STR_a STR_l STR_n STR_u STR_m STR_COLON + STR_a STR_s STR_c STR_i STR_i STR_COLON + STR_b STR_l STR_a STR_n STR_k STR_COLON + STR_c STR_n STR_t STR_r STR_l STR_COLON + STR_d STR_i STR_g STR_i STR_t STR_COLON + STR_g STR_r STR_a STR_p STR_h STR_COLON + STR_p STR_r STR_i STR_n STR_t STR_COLON + STR_p STR_u STR_n STR_c STR_t STR_COLON + STR_s STR_p STR_a STR_c STR_e STR_COLON + STR_w STR_o STR_r STR_d STR_COLON + STR_x STR_d STR_i STR_g STR_i STR_t STR_COLON; + /************************************************* @@ -190,7 +216,7 @@ while (plength > 0) switch (posix_state) { case POSIX_CLASS_STARTED: - if (c <= 127 && islower(c)) break; /* Remain in started state */ + if (ISLOWER(c)) break; /* Remain in started state */ posix_state = POSIX_CLASS_NOT_STARTED; if (c == CHAR_COLON && plength > 0 && *posix == CHAR_RIGHT_SQUARE_BRACKET) @@ -200,7 +226,7 @@ while (plength > 0) posix++; continue; /* With next character after :] */ } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case POSIX_CLASS_NOT_STARTED: if (c == CHAR_LEFT_SQUARE_BRACKET) @@ -277,9 +303,9 @@ while (plength > 0) if (plength == 0) return PCRE2_ERROR_END_BACKSLASH; if (extended) nextisliteral = TRUE; else { - if (*posix < 127 && strchr(posix_meta_escapes, *posix) != NULL) + if (*posix < 255 && strchr(posix_meta_escapes, *posix) != NULL) { - if (isdigit(*posix)) PUTCHARS(STR_BACKSLASH); + if (*posix >= CHAR_0 && *posix <= CHAR_9) PUTCHARS(STR_BACKSLASH); if (p + 1 > endp) return PCRE2_ERROR_NOMEMORY; lastspecial = *p++ = *posix++; plength--; @@ -295,7 +321,7 @@ while (plength > 0) case CHAR_LEFT_PARENTHESIS: bracount++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_QUESTION_MARK: case CHAR_PLUS: @@ -303,7 +329,7 @@ while (plength > 0) case CHAR_RIGHT_CURLY_BRACKET: case CHAR_VERTICAL_LINE: if (!extended) goto ESCAPE_LITERAL; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_DOT: case CHAR_DOLLAR_SIGN: @@ -332,10 +358,10 @@ while (plength > 0) posix_state = POSIX_ANCHORED; goto COPY_SPECIAL; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ default: - if (c < 128 && strchr(pcre2_escaped_literals, c) != NULL) + if (c < 255 && strchr(pcre2_escaped_literals, c) != NULL) { ESCAPE_LITERAL: PUTCHARS(STR_BACKSLASH); @@ -474,8 +500,6 @@ static int convert_glob_parse_class(PCRE2_SPTR *from, PCRE2_SPTR pattern_end, pcre2_output_context *out) { -static const char *posix_classes = "alnum:alpha:ascii:blank:cntrl:digit:" - "graph:lower:print:punct:space:upper:word:xdigit:"; PCRE2_SPTR start = *from + 1; PCRE2_SPTR pattern = start; const char *class_ptr; @@ -500,7 +524,7 @@ class_index = 1; while (TRUE) { - if (*class_ptr == CHAR_NUL) return 0; + if (*class_ptr == 0) return 0; pattern = start; @@ -539,31 +563,61 @@ Returns: !0 => character is found in the class static BOOL convert_glob_char_in_class(int class_index, PCRE2_UCHAR c) { +const uint8_t *cbits = PRIV(default_tables) + cbits_offset; +int cbit; + #if PCRE2_CODE_UNIT_WIDTH != 8 if (c > 0xff) { - /* ctype functions are not sane for c > 0xff */ - return 0; + /* Can't access the character tables for c > 0xff */ + return FALSE; } #endif +/* See posix_class_maps. This is a small local clone of that. +Note that we don't know exactly what character tables will be used at +match time, but, for the purposes of pattern conversion, it should be +sufficient to use PCRE2's built-in default tables. */ + switch (class_index) { - case 1: return isalnum(c); - case 2: return isalpha(c); - case 3: return 1; - case 4: return c == CHAR_HT || c == CHAR_SPACE; - case 5: return iscntrl(c); - case 6: return isdigit(c); - case 7: return isgraph(c); - case 8: return islower(c); - case 9: return isprint(c); - case 10: return ispunct(c); - case 11: return isspace(c); - case 12: return isupper(c); - case 13: return isalnum(c) || c == CHAR_UNDERSCORE; - default: return isxdigit(c); + case 1: /* alpha */ + if (c == CHAR_UNDERSCORE) return FALSE; + if (((cbits + cbit_digit)[c/8] & (1u << (c&7))) != 0) return FALSE; + cbit = cbit_word; + break; + + case 2: cbit = cbit_lower; break; /* lower */ + case 3: cbit = cbit_upper; break; /* upper */ + + case 4: /* alnum */ + if (c == CHAR_UNDERSCORE) return FALSE; + cbit = cbit_word; + break; + + case 5: /* ascii */ + if (((cbits + cbit_cntrl)[c/8] & (1u << (c&7))) != 0) return TRUE; + cbit = cbit_print; + break; + + case 6: /* blank */ + if (c == CHAR_LF || c == CHAR_VT || c == CHAR_FF || c == CHAR_CR) + return FALSE; + cbit = cbit_space; + break; + + case 7: cbit = cbit_cntrl; break; /* cntrl */ + case 8: cbit = cbit_digit; break; /* digit */ + case 9: cbit = cbit_graph; break; /* graph */ + case 10: cbit = cbit_print; break; /* print */ + case 11: cbit = cbit_punct; break; /* punct */ + case 12: cbit = cbit_space; break; /* space */ + case 13: cbit = cbit_word; break; /* word */ + case 14: cbit = cbit_xdigit; break; /* xdigit */ + default: return FALSE; } + +return ((cbits + cbit)[c/8] & (1u << (c&7))) != 0; } /* Parse a range of characters. @@ -1005,7 +1059,7 @@ while (pattern < pattern_end) c = *pattern++; } - if (c < 128 && strchr(pcre2_escaped_literals, c) != NULL) + if (c < 255 && strchr(pcre2_escaped_literals, c) != NULL) convert_glob_write(&out, CHAR_BACKSLASH); convert_glob_write(&out, c); @@ -1065,13 +1119,21 @@ pcre2_pattern_convert(PCRE2_SPTR pattern, PCRE2_SIZE plength, uint32_t options, pcre2_convert_context *ccontext) { int rc; +PCRE2_UCHAR null_str[1] = { 0xcd }; PCRE2_UCHAR dummy_buffer[DUMMY_BUFFER_SIZE]; PCRE2_UCHAR *use_buffer = dummy_buffer; PCRE2_SIZE use_length = DUMMY_BUFFER_SIZE; BOOL utf = (options & PCRE2_CONVERT_UTF) != 0; uint32_t pattype = options & TYPE_OPTIONS; -if (pattern == NULL || bufflenptr == NULL) return PCRE2_ERROR_NULL; +if (pattern == NULL && plength == 0) + pattern = null_str; + +if (pattern == NULL || bufflenptr == NULL) + { + if (bufflenptr != NULL) *bufflenptr = 0; /* Error offset */ + return PCRE2_ERROR_NULL; + } if ((options & ~ALL_OPTIONS) != 0 || /* Undefined bit set */ (pattype & (~pattype+1)) != pattype || /* More than one type set */ @@ -1136,8 +1198,13 @@ for (int i = 0; i < 2; i++) bufflenptr, dummyrun, ccontext); break; + /* We have already validated pattype. */ + /* LCOV_EXCL_START */ default: - goto EXIT; + PCRE2_DEBUG_UNREACHABLE(); + *bufflenptr = 0; /* Error offset */ + return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } if (rc != 0 || /* Error */ @@ -1150,20 +1217,23 @@ for (int i = 0; i < 2; i++) allocated = PRIV(memctl_malloc)(sizeof(pcre2_memctl) + (*bufflenptr + 1)*PCRE2_CODE_UNIT_WIDTH, (pcre2_memctl *)ccontext); - if (allocated == NULL) return PCRE2_ERROR_NOMEMORY; + if (allocated == NULL) + { + *bufflenptr = 0; /* Error offset */ + return PCRE2_ERROR_NOMEMORY; + } *buffptr = (PCRE2_UCHAR *)(((char *)allocated) + sizeof(pcre2_memctl)); use_buffer = *buffptr; use_length = *bufflenptr + 1; } -/* Something went terribly wrong. Trigger an assert and return an error */ +/* Running the loop above ought to have succeeded the second time. */ +/* LCOV_EXCL_START */ PCRE2_DEBUG_UNREACHABLE(); - -EXIT: - *bufflenptr = 0; /* Error offset */ return PCRE2_ERROR_INTERNAL; +/* LCOV_EXCL_STOP */ } diff --git a/libpcre/src/pcre2_dfa_match.c b/libpcre/src/pcre2_dfa_match.c index ebf31d284..f507acf8d 100644 --- a/libpcre/src/pcre2_dfa_match.c +++ b/libpcre/src/pcre2_dfa_match.c @@ -72,16 +72,14 @@ Overall, I concluded that the gains in some cases did not outweigh the losses in others, so I abandoned this code. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include "pcre2_internal.h" + + #define NLBLOCK mb /* Block containing newline information */ #define PSSTART start_subject /* Field containing processed string start */ #define PSEND end_subject /* Field containing processed string end */ -#include "pcre2_internal.h" - #define PUBLIC_DFA_MATCH_OPTIONS \ (PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY| \ PCRE2_NOTEMPTY_ATSTART|PCRE2_NO_UTF_CHECK|PCRE2_PARTIAL_HARD| \ @@ -2330,7 +2328,7 @@ for (;;) case 0x2029: #endif /* Not EBCDIC */ if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_LF: ADD_NEW(state_offset + 1, 0); @@ -2442,7 +2440,7 @@ for (;;) caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_PLUS: case OP_MINPLUS: case OP_POSPLUS: @@ -2486,7 +2484,7 @@ for (;;) case OP_NOTPOSQUERYI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_QUERY: case OP_MINQUERY: case OP_POSQUERY: @@ -2527,7 +2525,7 @@ for (;;) case OP_NOTPOSSTARI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_STAR: case OP_MINSTAR: case OP_POSSTAR: @@ -2564,7 +2562,7 @@ for (;;) case OP_NOTEXACTI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_EXACT: case OP_NOTEXACT: count = current_state->count; /* Number already matched */ @@ -2599,7 +2597,7 @@ for (;;) case OP_NOTPOSUPTOI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_UPTO: case OP_MINUPTO: case OP_POSUPTO: @@ -2941,6 +2939,9 @@ for (;;) uint32_t recno = (callpat == mb->start_code)? 0 : GET2(callpat, 1 + LINK_SIZE); + /* Argument list has not been supported yet. */ + if (code[1 + LINK_SIZE] == OP_CREF) return PCRE2_ERROR_DFA_UITEM; + if (rws->free < RWS_RSIZE + RWS_OVEC_RSIZE) { rc = more_workspace(&rws, RWS_OVEC_RSIZE, mb); @@ -3341,10 +3342,12 @@ pcre2_dfa_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, pcre2_match_context *mcontext, int *workspace, PCRE2_SIZE wscount) { int rc; -int was_zero_terminated = 0; const pcre2_real_code *re = (const pcre2_real_code *)code; +uint32_t original_options = options; +PCRE2_UCHAR null_str[1] = { 0xcd }; +PCRE2_SPTR original_subject = subject; PCRE2_SPTR start_match; PCRE2_SPTR end_subject; PCRE2_SPTR bumpalong_limit; @@ -3386,44 +3389,46 @@ rws->free = RWS_BASE_SIZE - RWS_ANCHOR_SIZE; /* Recognize NULL, length 0 as an empty string. */ -if (subject == NULL && length == 0) subject = (PCRE2_SPTR)""; +if (subject == NULL && length == 0) subject = null_str; /* Plausibility checks */ -if ((options & ~PUBLIC_DFA_MATCH_OPTIONS) != 0) return PCRE2_ERROR_BADOPTION; -if (re == NULL || subject == NULL || workspace == NULL || match_data == NULL) - return PCRE2_ERROR_NULL; +if (match_data == NULL) return PCRE2_ERROR_NULL; +if (re == NULL || subject == NULL || workspace == NULL) + { rc = PCRE2_ERROR_NULL; goto EXIT; } +if ((options & ~PUBLIC_DFA_MATCH_OPTIONS) != 0) + { rc = PCRE2_ERROR_BADOPTION; goto EXIT; } if (length == PCRE2_ZERO_TERMINATED) { length = PRIV(strlen)(subject); - was_zero_terminated = 1; } -if (wscount < 20) return PCRE2_ERROR_DFA_WSSIZE; -if (start_offset > length) return PCRE2_ERROR_BADOFFSET; +if (wscount < 20) { rc = PCRE2_ERROR_DFA_WSSIZE; goto EXIT; } +if (start_offset > length) { rc = PCRE2_ERROR_BADOFFSET; goto EXIT; } /* Partial matching and PCRE2_ENDANCHORED are currently not allowed at the same time. */ if ((options & (PCRE2_PARTIAL_HARD|PCRE2_PARTIAL_SOFT)) != 0 && ((re->overall_options | options) & PCRE2_ENDANCHORED) != 0) - return PCRE2_ERROR_BADOPTION; + { rc = PCRE2_ERROR_BADOPTION; goto EXIT; } /* Invalid UTF support is not available for DFA matching. */ if ((re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0) - return PCRE2_ERROR_DFA_UINVALID_UTF; + { rc = PCRE2_ERROR_DFA_UINVALID_UTF; goto EXIT; } /* Check that the first field in the block is the magic number. If it is not, return with PCRE2_ERROR_BADMAGIC. */ -if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; +if (re->magic_number != MAGIC_NUMBER) + { rc = PCRE2_ERROR_BADMAGIC; goto EXIT; } /* Check the code unit width. */ if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH/8) - return PCRE2_ERROR_BADMODE; + { rc = PCRE2_ERROR_BADMODE; goto EXIT; } /* PCRE2_NOTEMPTY and PCRE2_NOTEMPTY_ATSTART are match-time flags in the options variable for this function. Users of PCRE2 who are not calling the @@ -3449,8 +3454,8 @@ of the workspace. */ if ((options & PCRE2_DFA_RESTART) != 0) { if ((workspace[0] & (-2)) != 0 || workspace[1] < 1 || - workspace[1] > (int)((wscount - 2)/INTS_PER_STATEBLOCK)) - return PCRE2_ERROR_DFA_BADRESTART; + workspace[1] > (int)((wscount - 2)/INTS_PER_STATEBLOCK)) + { rc = PCRE2_ERROR_DFA_BADRESTART; goto EXIT; } } /* Set some local values */ @@ -3498,7 +3503,7 @@ else if (mcontext->offset_limit != PCRE2_UNSET) { if ((re->overall_options & PCRE2_USE_OFFSET_LIMIT) == 0) - return PCRE2_ERROR_BADOFFSETLIMIT; + { rc = PCRE2_ERROR_BADOFFSETLIMIT; goto EXIT; } bumpalong_limit = subject + mcontext->offset_limit; } mb->callout = mcontext->callout; @@ -3565,9 +3570,12 @@ switch(re->newline_convention) mb->nltype = NLTYPE_ANYCRLF; break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; + rc = PCRE2_ERROR_INTERNAL; + goto EXIT; + /* LCOV_EXCL_STOP */ } /* Check a UTF string for validity if required. For 8-bit and 16-bit strings, @@ -3588,7 +3596,7 @@ if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) #if PCRE2_CODE_UNIT_WIDTH != 32 unsigned int i; if (start_match < end_subject && NOT_FIRSTCU(*start_match)) - return PCRE2_ERROR_BADUTFOFFSET; + { rc = PCRE2_ERROR_BADUTFOFFSET; goto EXIT; } for (i = re->max_lookbehind; i > 0 && check_subject > subject; i--) { check_subject--; @@ -3609,12 +3617,12 @@ if (utf && (options & PCRE2_NO_UTF_CHECK) == 0) /* Validate the relevant portion of the subject. After an error, adjust the offset to be an absolute offset in the whole string. */ - match_data->rc = PRIV(valid_utf)(check_subject, + rc = PRIV(valid_utf)(check_subject, length - (PCRE2_SIZE)(check_subject - subject), &(match_data->startchar)); - if (match_data->rc != 0) + if (rc != 0) { match_data->startchar += (PCRE2_SIZE)(check_subject - subject); - return match_data->rc; + goto EXIT; } } #endif /* SUPPORT_UNICODE */ @@ -3678,9 +3686,10 @@ if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0) /* Fill in fields that are always returned in the match data. */ match_data->code = re; -match_data->subject = NULL; /* Default for no match */ +match_data->subject = NULL; /* Default for match error */ match_data->mark = NULL; match_data->matchedby = PCRE2_MATCHEDBY_DFA_INTERPRETER; +match_data->options = original_options; /* Call the main matching function, looping for a non-anchored regex after a failed match. If not restarting, perform certain optimizations at the start of @@ -4032,29 +4041,40 @@ for (;;) if (rc != PCRE2_ERROR_NOMATCH || anchored) { + if (rc == PCRE2_ERROR_NOMATCH) goto NOMATCH_EXIT; + if (rc == PCRE2_ERROR_PARTIAL && match_data->oveccount > 0) { match_data->ovector[0] = (PCRE2_SIZE)(start_match - subject); match_data->ovector[1] = (PCRE2_SIZE)(end_subject - subject); } - match_data->subject_length = length; - match_data->leftchar = (PCRE2_SIZE)(mb->start_used_ptr - subject); - match_data->rightchar = (PCRE2_SIZE)(mb->last_used_ptr - subject); - match_data->startchar = (PCRE2_SIZE)(start_match - subject); - match_data->rc = rc; - if (rc >= 0 &&(options & PCRE2_COPY_MATCHED_SUBJECT) != 0) + if (rc >= 0 || rc == PCRE2_ERROR_PARTIAL) { - length = CU2BYTES(length + was_zero_terminated); - match_data->subject = match_data->memctl.malloc(length, - match_data->memctl.memory_data); - if (match_data->subject == NULL) return PCRE2_ERROR_NOMEMORY; - memcpy((void *)match_data->subject, subject, length); + match_data->subject_length = length; + match_data->start_offset = start_offset; + match_data->leftchar = (PCRE2_SIZE)(mb->start_used_ptr - subject); + match_data->rightchar = (PCRE2_SIZE)(mb->last_used_ptr - subject); + match_data->startchar = (PCRE2_SIZE)(start_match - subject); + } + + if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0) + { + if (length != 0) + { + match_data->subject = match_data->memctl.malloc(CU2BYTES(length), + match_data->memctl.memory_data); + if (match_data->subject == NULL) + { rc = PCRE2_ERROR_NOMEMORY; goto EXIT; } + memcpy((void *)match_data->subject, subject, CU2BYTES(length)); + } + else + match_data->subject = NULL; match_data->flags |= PCRE2_MD_COPIED_SUBJECT; } - else + else if (rc >= 0 || rc == PCRE2_ERROR_PARTIAL) { - if (rc >= 0 || rc == PCRE2_ERROR_PARTIAL) match_data->subject = subject; + match_data->subject = original_subject; } goto EXIT; } @@ -4088,6 +4108,9 @@ for (;;) } /* "Bumpalong" loop */ NOMATCH_EXIT: +match_data->subject = original_subject; +match_data->subject_length = length; +match_data->start_offset = start_offset; rc = PCRE2_ERROR_NOMATCH; EXIT: @@ -4098,6 +4121,7 @@ while (rws->next != NULL) mb->memctl.free(next, mb->memctl.memory_data); } +match_data->rc = rc; return rc; } diff --git a/libpcre/src/pcre2_dftables.c b/libpcre/src/pcre2_dftables.c index 0f9aedf85..1d19870de 100644 --- a/libpcre/src/pcre2_dftables.c +++ b/libpcre/src/pcre2_dftables.c @@ -47,21 +47,23 @@ option can be used to select the current locale from the LC_ALL environment variable. By default, the tables are written in source form, but if -b is given, they are written in binary. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif + #include #include #include #include -#define PCRE2_DFTABLES /* for pcre2_internal.h, pcre2_maketables.c */ +/* For pcre2_internal.h, pcre2_maketables.c, pcre2_tables.c */ +#define PCRE2_DFTABLES +/* For pcre2_tables.c */ +#define PRIV(name) name #define PCRE2_CODE_UNIT_WIDTH 0 /* Must be set, but not relevant here */ #include "pcre2_internal.h" #include "pcre2_maketables.c" +#include "pcre2_tables.c" static const char *classlist[] = @@ -70,6 +72,23 @@ static const char *classlist[] = "word", "graph", "print", "punct", "cntrl" }; +static int identity(int c) { return c; } + +#ifdef EBCDIC +static int ebcdic_to_unicode(int c) +{ +if (c < 0 || c > 255) abort(); + +return ebcdic_1047_to_ascii[c]; +} + +static int unicode_to_ebcdic(int c) +{ +if (c < 0 || c > 255) abort(); + +return ascii_to_ebcdic_1047[c]; +} +#endif /************************************************* @@ -83,6 +102,9 @@ usage(void) "Usage: pcre2_dftables [options] \n" " -b Write output in binary (default is source code)\n" " -L Use locale from LC_ALL (default is \"C\" locale)\n" +#ifdef EBCDIC + " -E Use EBCDIC 1047 via locale C.UTF-8\n" +#endif ); } @@ -101,6 +123,8 @@ BOOL binary = FALSE; char *env = (char *)"C"; const uint8_t *tables; const uint8_t *base_of_tables; +int (*charfn_to)(int) = identity; +int (*charfn_from)(int) = identity; /* Process options */ @@ -125,6 +149,24 @@ for (i = 1; i < argc; i++) env = getenv("LC_ALL"); } +#ifdef EBCDIC + else if (strcmp(arg, "-E") == 0) + { + if (setlocale(LC_ALL, "C.UTF-8") == NULL) + { + (void)fprintf(stderr, "pcre2_dftables: setlocale() failed\n"); + return 1; + } +#ifdef EBCDIC_NL25 + env = "EBCDIC 1047 (NL 0x25)"; +#else + env = "EBCDIC 1047 (NL 0x15)"; +#endif + charfn_to = ebcdic_to_unicode; + charfn_from = unicode_to_ebcdic; + } +#endif + else if (strcmp(arg, "-b") == 0) binary = TRUE; @@ -143,7 +185,7 @@ if (i != argc - 1) /* Make the tables */ -tables = maketables(); +tables = maketables(charfn_to, charfn_from); base_of_tables = tables; f = fopen(argv[i], "wb"); @@ -197,20 +239,7 @@ the very long string otherwise. */ "pcre2_dftables manually with the -L option to build tables using the LC_ALL\n" "locale. */\n\n"); -/* Force config.h in z/OS */ - -#if defined NATIVE_ZOS (void)fprintf(f, - "/* For z/OS, config.h is forced */\n" - "#ifndef HAVE_CONFIG_H\n" - "#define HAVE_CONFIG_H 1\n" - "#endif\n\n"); -#endif - -(void)fprintf(f, - "#ifdef HAVE_CONFIG_H\n" - "#include \"config.h\"\n" - "#endif\n\n" "#include \"pcre2_internal.h\"\n\n"); (void)fprintf(f, diff --git a/libpcre/src/pcre2_error.c b/libpcre/src/pcre2_error.c index 8b7423c6c..df26add2b 100644 --- a/libpcre/src/pcre2_error.c +++ b/libpcre/src/pcre2_error.c @@ -39,12 +39,10 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + + #define STRING(a) # a #define XSTRING(s) STRING(s) @@ -97,7 +95,7 @@ static const unsigned char compile_error_texts[] = "a relative value of zero is not allowed\0" "conditional subpattern contains more than two branches\0" "atomic assertion expected after (?( or (?(?C)\0" - "digit expected after (?+ or (?-\0" + "digit expected after (?+\0" /* 30 */ "unknown POSIX class name\0" "internal error in pcre2_study(): should not occur\0" @@ -148,7 +146,7 @@ static const unsigned char compile_error_texts[] = #ifndef EBCDIC "\\c must be followed by a printable ASCII character\0" #else - "\\c must be followed by a letter or one of [\\]^_?\0" + "\\c must be followed by a letter or one of @[\\]^_?\0" #endif "\\k is not followed by a braced, angle-bracketed, or quoted name\0" /* 70 */ @@ -208,6 +206,11 @@ static const unsigned char compile_error_texts[] = /* 115 */ "terminating ] with no following closing parenthesis in (?[...]\0" "unexpected character in (?[...]) extended character class\0" + "expected capture group number or name\0" + "missing opening parenthesis\0" + "syntax error in subpattern number (missing terminator?)\0" + /* 120 */ + "erroroffset passed as NULL\0" ; /* Match-time and UTF error texts are in the same format. */ @@ -291,13 +294,18 @@ static const unsigned char match_error_texts[] = "heap limit exceeded\0" "invalid syntax\0" /* 65 */ - "internal error - duplicate substitution match\0" + "internal error: duplicate substitution match\0" "PCRE2_MATCH_INVALID_UTF is not supported for DFA matching\0" - "INTERNAL ERROR: invalid substring offset\0" + "internal error: invalid substring offset\0" "feature is not supported by the JIT compiler\0" "error performing replacement case transformation\0" /* 70 */ "replacement too large (longer than PCRE2_SIZE)\0" + "substitute pattern differs from prior match call\0" + "substitute subject differs from prior match call\0" + "substitute start offset differs from prior match call\0" + "substitute options differ from prior match call\0" + "disallowed use of \\K in lookaround\0" ; @@ -324,7 +332,7 @@ pcre2_get_error_message(int enumber, PCRE2_UCHAR *buffer, PCRE2_SIZE size) { const unsigned char *message; PCRE2_SIZE i; -int n; +int n, rc = 0; if (size == 0) return PCRE2_ERROR_NOMEMORY; @@ -346,7 +354,7 @@ else /* Invalid error number */ for (; n > 0; n--) { - while (*message++ != CHAR_NUL) {}; + while (*message++ != CHAR_NUL) {} if (*message == CHAR_NUL) return PCRE2_ERROR_BADDATA; } @@ -354,14 +362,23 @@ for (i = 0; *message != 0; i++) { if (i >= size - 1) { - buffer[i] = 0; /* Terminate partial message */ - return PCRE2_ERROR_NOMEMORY; + rc = PCRE2_ERROR_NOMEMORY; + break; } buffer[i] = *message++; } -buffer[i] = 0; -return (int)i; +#if defined EBCDIC && 'a' != 0x81 +/* If compiling for EBCDIC, but the compiler's string literals are not EBCDIC, +then we are in the "force EBCDIC 1047" mode. I have chosen to add a few lines +here to translate the error strings on the fly, rather than require the string +literals above to be written out arduously using the "STR_XYZ" macros. */ +for (PCRE2_SIZE j = 0; j < i; ++j) + buffer[j] = PRIV(ascii_to_ebcdic_1047)[buffer[j]]; +#endif + +buffer[i] = 0; /* Terminate message, even if truncated. */ +return rc? rc : (int)i; } /* End of pcre2_error.c */ diff --git a/libpcre/src/pcre2_extuni.c b/libpcre/src/pcre2_extuni.c index 91d839e29..1b7f04b4b 100644 --- a/libpcre/src/pcre2_extuni.c +++ b/libpcre/src/pcre2_extuni.c @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains an internal function that is used to match a Unicode extended grapheme sequence. It is used by both pcre2_match() and pcre2_dfa_match(). However, it is called only when Unicode support is being @@ -45,14 +46,10 @@ compiled. Nevertheless, we provide a dummy function when there is no Unicode support, because some compilers do not like functionless source files. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - - #include "pcre2_internal.h" + /* Dummy function */ #ifndef SUPPORT_UNICODE diff --git a/libpcre/src/pcre2_find_bracket.c b/libpcre/src/pcre2_find_bracket.c index 486f4539d..e26ee9923 100644 --- a/libpcre/src/pcre2_find_bracket.c +++ b/libpcre/src/pcre2_find_bracket.c @@ -46,13 +46,10 @@ function is called from pcre2_compile.c and also from pcre2_study.c when finding the minimum matching length. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + /************************************************* * Scan compiled regex for specific bracket * *************************************************/ diff --git a/libpcre/src/pcre2_internal.h b/libpcre/src/pcre2_internal.h index 6e0a5e05d..aa7940957 100644 --- a/libpcre/src/pcre2_internal.h +++ b/libpcre/src/pcre2_internal.h @@ -41,6 +41,15 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef PCRE2_INTERNAL_H_IDEMPOTENT_GUARD #define PCRE2_INTERNAL_H_IDEMPOTENT_GUARD +/* We do not assume that the config.h file has an idempotent include guard, +since it may well be written by clients. The standard Autoheader config.h does +not have an include guard (although we could customise that). */ + +#if defined HAVE_CONFIG_H && !defined PCRE2_CONFIG_H_IDEMPOTENT_GUARD +#define PCRE2_CONFIG_H_IDEMPOTENT_GUARD +#include "config.h" +#endif + /* We do not support both EBCDIC and Unicode at the same time. The "configure" script prevents both being selected, but not everybody uses "configure". EBCDIC is only supported for the 8-bit library, but the check for this has to be later @@ -59,13 +68,12 @@ be including this file. There is no explicit way of forcing a compile to be abandoned, but trying to include a non-existent file seems cleanest. Otherwise there will be many irrelevant consequential errors. */ -#if (!defined PCRE2_BUILDING_PCRE2TEST && !defined PCRE2_DFTABLES) && \ +#if (!defined PCRE2_PCRE2TEST && !defined PCRE2_DFTABLES) && \ (!defined PCRE2_CODE_UNIT_WIDTH || \ (PCRE2_CODE_UNIT_WIDTH != 8 && \ PCRE2_CODE_UNIT_WIDTH != 16 && \ PCRE2_CODE_UNIT_WIDTH != 32)) #error PCRE2_CODE_UNIT_WIDTH must be defined as 8, 16, or 32. -#include #endif @@ -120,13 +128,12 @@ MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */ #endif /* When compiling a DLL for Windows, the exported symbols have to be declared -using some MS magic. I found some useful information on this web page: -http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the -information there, using __declspec(dllexport) without "extern" we have a -definition; with "extern" we have a declaration. The settings here override the -setting in pcre2.h (which is included below); it defines only PCRE2_EXP_DECL, -which is all that is needed for applications (they just import the symbols). We -use: +using some MS magic, as documented here: +https://learn.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-declspec-dllexport + +In pcre2.h (which is included below), we define only PCRE2_EXP_DECL, +which is all that is needed for applications (they just import the symbols). To +compile the library, we use: PCRE2_EXP_DECL for declarations PCRE2_EXP_DEFN for definitions @@ -140,24 +147,23 @@ special-purpose environments) might want to stick other stuff in front of exported symbols. That's why, in the non-Windows case, we set PCRE2_EXP_DEFN only if it is not already set. */ +#if defined __cplusplus +#error This project uses C99. C++ is not supported. +#endif + #ifndef PCRE2_EXP_DECL -# ifdef _WIN32 -# ifndef PCRE2_STATIC -# define PCRE2_EXP_DECL extern __declspec(dllexport) -# define PCRE2_EXP_DEFN __declspec(dllexport) -# else -# define PCRE2_EXP_DECL extern PCRE2_EXPORT -# define PCRE2_EXP_DEFN -# endif +# if defined(_WIN32) && !defined(PCRE2_STATIC) +# define PCRE2_EXP_DECL extern __declspec(dllexport) # else -# ifdef __cplusplus -# define PCRE2_EXP_DECL extern "C" PCRE2_EXPORT -# else -# define PCRE2_EXP_DECL extern PCRE2_EXPORT -# endif -# ifndef PCRE2_EXP_DEFN -# define PCRE2_EXP_DEFN PCRE2_EXP_DECL -# endif +# define PCRE2_EXP_DECL extern PCRE2_EXPORT +# endif +#endif + +#ifndef PCRE2_EXP_DEFN +# if defined(_WIN32) && !defined(PCRE2_STATIC) +# define PCRE2_EXP_DEFN extern __declspec(dllexport) +# else +# define PCRE2_EXP_DEFN extern PCRE2_EXPORT # endif #endif @@ -167,19 +173,6 @@ property values. This must follow the setting of PCRE2_EXP_DECL above. */ #include "pcre2.h" #include "pcre2_ucp.h" -/* When PCRE2 is compiled as a C++ library, the subject pointer can be replaced -with a custom type. This makes it possible, for example, to allow pcre2_match() -to process subject strings that are discontinuous by using a smart pointer -class. It must always be possible to inspect all of the subject string in -pcre2_match() because of the way it backtracks. */ - -/* WARNING: This is as yet untested for PCRE2. */ - -#ifdef CUSTOM_SUBJECT_PTR -#undef PCRE2_SPTR -#define PCRE2_SPTR CUSTOM_SUBJECT_PTR -#endif - /* When checking for integer overflow, we need to handle large integers. If a 64-bit integer type is available, we can use that. Otherwise we have to cast to double, which of course requires floating point @@ -201,28 +194,6 @@ code that a non-static object is being referenced. */ #define PRIV(name) _pcre2_##name #endif -/* When compiling for use with the Virtual Pascal compiler, these functions -need to have their names changed. PCRE2 must be compiled with the -DVPCOMPAT -option on the command line. */ - -#ifdef VPCOMPAT -#define strlen(s) _strlen(s) -#define strncmp(s1,s2,m) _strncmp(s1,s2,m) -#define memcmp(s,c,n) _memcmp(s,c,n) -#define memcpy(d,s,n) _memcpy(d,s,n) -#define memmove(d,s,n) _memmove(d,s,n) -#define memset(s,c,n) _memset(s,c,n) -#else /* VPCOMPAT */ - -/* Otherwise, to cope with SunOS4 and other systems that lack memmove(), define -a macro that calls an emulating function. */ - -#ifndef HAVE_MEMMOVE -#undef memmove /* Some systems may have a macro */ -#define memmove(a, b, c) PRIV(memmove)(a, b, c) -#endif /* not HAVE_MEMMOVE */ -#endif /* not VPCOMPAT */ - /* This is an unsigned int value that no UTF character can ever have, as Unicode doesn't go beyond 0x0010ffff. */ @@ -406,7 +377,7 @@ PCRE (both APIs) for a long time. */ #define HSPACE_LIST \ CHAR_HT, CHAR_SPACE, CHAR_NBSP, \ 0x1680, 0x180e, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, \ - 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202f, 0x205f, 0x3000, \ + 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x202f, 0x205f, 0x3000, \ NOTACHAR #define HSPACE_MULTIBYTE_CASES \ @@ -422,7 +393,7 @@ PCRE (both APIs) for a long time. */ case 0x2007: /* FIGURE SPACE */ \ case 0x2008: /* PUNCTUATION SPACE */ \ case 0x2009: /* THIN SPACE */ \ - case 0x200A: /* HAIR SPACE */ \ + case 0x200a: /* HAIR SPACE */ \ case 0x202f: /* NARROW NO-BREAK SPACE */ \ case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ \ case 0x3000 /* IDEOGRAPHIC SPACE */ @@ -552,6 +523,7 @@ bytes in a code unit in that mode. */ #define PCRE2_DUPCAPUSED 0x00200000u /* contains (?| */ #define PCRE2_HASBKC 0x00400000u /* contains \C */ #define PCRE2_HASACCEPT 0x00800000u /* contains (*ACCEPT) */ +#define PCRE2_HASBSK 0x01000000u /* contains \K */ #define PCRE2_MODE_MASK (PCRE2_MODE8 | PCRE2_MODE16 | PCRE2_MODE32) @@ -698,6 +670,10 @@ same code point. */ compatibility. NEL is the Unicode newline character; make sure it is a positive value. */ +#if '\n' != 0x0a +#error "ASCII character '\n' is not 0x0a" +#endif + #define CHAR_LF '\n' #define CHAR_NL CHAR_LF #define CHAR_NEL ((unsigned char)'\x85') @@ -713,7 +689,232 @@ a positive value. */ #endif /* EBCDIC */ -/* The remaining definitions work in both environments. */ +/* When we want to use EBCDIC with an ASCII compiler, for testing EBCDIC on +ASCII platforms, then we can hardcode an EBCDIC codepage (IBM-1047). */ + +#ifdef EBCDIC_IGNORING_COMPILER + +#define CHAR_NUL '\000' +#define CHAR_HT '\005' +#define CHAR_VT '\013' +#define CHAR_FF '\014' +#define CHAR_CR '\015' +#define CHAR_BS '\026' +#define CHAR_BEL '\057' + +#define CHAR_SPACE '\100' +#define CHAR_EXCLAMATION_MARK '\132' +#define CHAR_QUOTATION_MARK '\177' +#define CHAR_NUMBER_SIGN '\173' +#define CHAR_DOLLAR_SIGN '\133' +#define CHAR_PERCENT_SIGN '\154' +#define CHAR_AMPERSAND '\120' +#define CHAR_APOSTROPHE '\175' +#define CHAR_LEFT_PARENTHESIS '\115' +#define CHAR_RIGHT_PARENTHESIS '\135' +#define CHAR_ASTERISK '\134' +#define CHAR_PLUS '\116' +#define CHAR_COMMA '\153' +#define CHAR_MINUS '\140' +#define CHAR_DOT '\113' +#define CHAR_SLASH '\141' +#define CHAR_0 ((unsigned char)'\xf0') +#define CHAR_1 ((unsigned char)'\xf1') +#define CHAR_2 ((unsigned char)'\xf2') +#define CHAR_3 ((unsigned char)'\xf3') +#define CHAR_4 ((unsigned char)'\xf4') +#define CHAR_5 ((unsigned char)'\xf5') +#define CHAR_6 ((unsigned char)'\xf6') +#define CHAR_7 ((unsigned char)'\xf7') +#define CHAR_8 ((unsigned char)'\xf8') +#define CHAR_9 ((unsigned char)'\xf9') +#define CHAR_COLON '\172' +#define CHAR_SEMICOLON '\136' +#define CHAR_LESS_THAN_SIGN '\114' +#define CHAR_EQUALS_SIGN '\176' +#define CHAR_GREATER_THAN_SIGN '\156' +#define CHAR_QUESTION_MARK '\157' +#define CHAR_COMMERCIAL_AT '\174' +#define CHAR_A ((unsigned char)'\xc1') +#define CHAR_B ((unsigned char)'\xc2') +#define CHAR_C ((unsigned char)'\xc3') +#define CHAR_D ((unsigned char)'\xc4') +#define CHAR_E ((unsigned char)'\xc5') +#define CHAR_F ((unsigned char)'\xc6') +#define CHAR_G ((unsigned char)'\xc7') +#define CHAR_H ((unsigned char)'\xc8') +#define CHAR_I ((unsigned char)'\xc9') +#define CHAR_J ((unsigned char)'\xd1') +#define CHAR_K ((unsigned char)'\xd2') +#define CHAR_L ((unsigned char)'\xd3') +#define CHAR_M ((unsigned char)'\xd4') +#define CHAR_N ((unsigned char)'\xd5') +#define CHAR_O ((unsigned char)'\xd6') +#define CHAR_P ((unsigned char)'\xd7') +#define CHAR_Q ((unsigned char)'\xd8') +#define CHAR_R ((unsigned char)'\xd9') +#define CHAR_S ((unsigned char)'\xe2') +#define CHAR_T ((unsigned char)'\xe3') +#define CHAR_U ((unsigned char)'\xe4') +#define CHAR_V ((unsigned char)'\xe5') +#define CHAR_W ((unsigned char)'\xe6') +#define CHAR_X ((unsigned char)'\xe7') +#define CHAR_Y ((unsigned char)'\xe8') +#define CHAR_Z ((unsigned char)'\xe9') +#define CHAR_LEFT_SQUARE_BRACKET ((unsigned char)'\xad') +#define CHAR_BACKSLASH ((unsigned char)'\xe0') +#define CHAR_RIGHT_SQUARE_BRACKET ((unsigned char)'\xbd') +#define CHAR_CIRCUMFLEX_ACCENT '\137' +#define CHAR_UNDERSCORE '\155' +#define CHAR_GRAVE_ACCENT '\171' +#define CHAR_a ((unsigned char)'\x81') +#define CHAR_b ((unsigned char)'\x82') +#define CHAR_c ((unsigned char)'\x83') +#define CHAR_d ((unsigned char)'\x84') +#define CHAR_e ((unsigned char)'\x85') +#define CHAR_f ((unsigned char)'\x86') +#define CHAR_g ((unsigned char)'\x87') +#define CHAR_h ((unsigned char)'\x88') +#define CHAR_i ((unsigned char)'\x89') +#define CHAR_j ((unsigned char)'\x91') +#define CHAR_k ((unsigned char)'\x92') +#define CHAR_l ((unsigned char)'\x93') +#define CHAR_m ((unsigned char)'\x94') +#define CHAR_n ((unsigned char)'\x95') +#define CHAR_o ((unsigned char)'\x96') +#define CHAR_p ((unsigned char)'\x97') +#define CHAR_q ((unsigned char)'\x98') +#define CHAR_r ((unsigned char)'\x99') +#define CHAR_s ((unsigned char)'\xa2') +#define CHAR_t ((unsigned char)'\xa3') +#define CHAR_u ((unsigned char)'\xa4') +#define CHAR_v ((unsigned char)'\xa5') +#define CHAR_w ((unsigned char)'\xa6') +#define CHAR_x ((unsigned char)'\xa7') +#define CHAR_y ((unsigned char)'\xa8') +#define CHAR_z ((unsigned char)'\xa9') +#define CHAR_LEFT_CURLY_BRACKET ((unsigned char)'\xc0') +#define CHAR_VERTICAL_LINE '\117' +#define CHAR_RIGHT_CURLY_BRACKET ((unsigned char)'\xd0') +#define CHAR_TILDE ((unsigned char)'\xa1') + +#define STR_HT "\005" +#define STR_VT "\013" +#define STR_FF "\014" +#define STR_CR "\015" +#define STR_BS "\026" +#define STR_BEL "\057" + +#define STR_SPACE "\100" +#define STR_EXCLAMATION_MARK "\132" +#define STR_QUOTATION_MARK "\177" +#define STR_NUMBER_SIGN "\173" +#define STR_DOLLAR_SIGN "\133" +#define STR_PERCENT_SIGN "\154" +#define STR_AMPERSAND "\120" +#define STR_APOSTROPHE "\175" +#define STR_LEFT_PARENTHESIS "\115" +#define STR_RIGHT_PARENTHESIS "\135" +#define STR_ASTERISK "\134" +#define STR_PLUS "\116" +#define STR_COMMA "\153" +#define STR_MINUS "\140" +#define STR_DOT "\113" +#define STR_SLASH "\141" +#define STR_0 "\360" +#define STR_1 "\361" +#define STR_2 "\362" +#define STR_3 "\363" +#define STR_4 "\364" +#define STR_5 "\365" +#define STR_6 "\366" +#define STR_7 "\367" +#define STR_8 "\370" +#define STR_9 "\371" +#define STR_COLON "\172" +#define STR_SEMICOLON "\136" +#define STR_LESS_THAN_SIGN "\114" +#define STR_EQUALS_SIGN "\176" +#define STR_GREATER_THAN_SIGN "\156" +#define STR_QUESTION_MARK "\157" +#define STR_COMMERCIAL_AT "\174" +#define STR_A "\301" +#define STR_B "\302" +#define STR_C "\303" +#define STR_D "\304" +#define STR_E "\305" +#define STR_F "\306" +#define STR_G "\307" +#define STR_H "\310" +#define STR_I "\311" +#define STR_J "\321" +#define STR_K "\322" +#define STR_L "\323" +#define STR_M "\324" +#define STR_N "\325" +#define STR_O "\326" +#define STR_P "\327" +#define STR_Q "\330" +#define STR_R "\331" +#define STR_S "\342" +#define STR_T "\343" +#define STR_U "\344" +#define STR_V "\345" +#define STR_W "\346" +#define STR_X "\347" +#define STR_Y "\350" +#define STR_Z "\351" +#define STR_LEFT_SQUARE_BRACKET "\255" +#define STR_BACKSLASH "\340" +#define STR_RIGHT_SQUARE_BRACKET "\275" +#define STR_CIRCUMFLEX_ACCENT "\137" +#define STR_UNDERSCORE "\155" +#define STR_GRAVE_ACCENT "\171" +#define STR_a "\201" +#define STR_b "\202" +#define STR_c "\203" +#define STR_d "\204" +#define STR_e "\205" +#define STR_f "\206" +#define STR_g "\207" +#define STR_h "\210" +#define STR_i "\211" +#define STR_j "\221" +#define STR_k "\222" +#define STR_l "\223" +#define STR_m "\224" +#define STR_n "\225" +#define STR_o "\226" +#define STR_p "\227" +#define STR_q "\230" +#define STR_r "\231" +#define STR_s "\242" +#define STR_t "\243" +#define STR_u "\244" +#define STR_v "\245" +#define STR_w "\246" +#define STR_x "\247" +#define STR_y "\250" +#define STR_z "\251" +#define STR_LEFT_CURLY_BRACKET "\300" +#define STR_VERTICAL_LINE "\117" +#define STR_RIGHT_CURLY_BRACKET "\320" +#define STR_TILDE "\241" + +#else /* EBCDIC_IGNORING_COMPILER */ + +/* Otherwise, on a real EBCDIC compiler or an ASCII compiler, we can use simple +string and character literals. */ + +#ifdef EBCDIC +#if 'a' != 0x81 +#error "EBCDIC character 'a' is not 0x81" +#endif +#else +#if 'a' != 0x61 +#error "ASCII character 'a' is not 0x61" +#endif +#endif #define CHAR_NUL '\0' #define CHAR_HT '\t' @@ -922,88 +1123,7 @@ a positive value. */ #define STR_RIGHT_CURLY_BRACKET "}" #define STR_TILDE "~" -#define STRING_ACCEPT0 "ACCEPT\0" -#define STRING_COMMIT0 "COMMIT\0" -#define STRING_F0 "F\0" -#define STRING_FAIL0 "FAIL\0" -#define STRING_MARK0 "MARK\0" -#define STRING_PRUNE0 "PRUNE\0" -#define STRING_SKIP0 "SKIP\0" -#define STRING_THEN "THEN" - -#define STRING_atomic0 "atomic\0" -#define STRING_pla0 "pla\0" -#define STRING_plb0 "plb\0" -#define STRING_napla0 "napla\0" -#define STRING_naplb0 "naplb\0" -#define STRING_nla0 "nla\0" -#define STRING_nlb0 "nlb\0" -#define STRING_scs0 "scs\0" -#define STRING_sr0 "sr\0" -#define STRING_asr0 "asr\0" -#define STRING_positive_lookahead0 "positive_lookahead\0" -#define STRING_positive_lookbehind0 "positive_lookbehind\0" -#define STRING_non_atomic_positive_lookahead0 "non_atomic_positive_lookahead\0" -#define STRING_non_atomic_positive_lookbehind0 "non_atomic_positive_lookbehind\0" -#define STRING_negative_lookahead0 "negative_lookahead\0" -#define STRING_negative_lookbehind0 "negative_lookbehind\0" -#define STRING_script_run0 "script_run\0" -#define STRING_atomic_script_run "atomic_script_run" -#define STRING_scan_substring0 "scan_substring\0" - -#define STRING_alpha0 "alpha\0" -#define STRING_lower0 "lower\0" -#define STRING_upper0 "upper\0" -#define STRING_alnum0 "alnum\0" -#define STRING_ascii0 "ascii\0" -#define STRING_blank0 "blank\0" -#define STRING_cntrl0 "cntrl\0" -#define STRING_digit0 "digit\0" -#define STRING_graph0 "graph\0" -#define STRING_print0 "print\0" -#define STRING_punct0 "punct\0" -#define STRING_space0 "space\0" -#define STRING_word0 "word\0" -#define STRING_xdigit "xdigit" - -#define STRING_DEFINE "DEFINE" -#define STRING_VERSION "VERSION" -#define STRING_WEIRD_STARTWORD "[:<:]]" -#define STRING_WEIRD_ENDWORD "[:>:]]" - -#define STRING_CR_RIGHTPAR "CR)" -#define STRING_LF_RIGHTPAR "LF)" -#define STRING_CRLF_RIGHTPAR "CRLF)" -#define STRING_ANY_RIGHTPAR "ANY)" -#define STRING_ANYCRLF_RIGHTPAR "ANYCRLF)" -#define STRING_NUL_RIGHTPAR "NUL)" -#define STRING_BSR_ANYCRLF_RIGHTPAR "BSR_ANYCRLF)" -#define STRING_BSR_UNICODE_RIGHTPAR "BSR_UNICODE)" -#define STRING_UTF8_RIGHTPAR "UTF8)" -#define STRING_UTF16_RIGHTPAR "UTF16)" -#define STRING_UTF32_RIGHTPAR "UTF32)" -#define STRING_UTF_RIGHTPAR "UTF)" -#define STRING_UCP_RIGHTPAR "UCP)" -#define STRING_NO_AUTO_POSSESS_RIGHTPAR "NO_AUTO_POSSESS)" -#define STRING_NO_DOTSTAR_ANCHOR_RIGHTPAR "NO_DOTSTAR_ANCHOR)" -#define STRING_NO_JIT_RIGHTPAR "NO_JIT)" -#define STRING_NO_START_OPT_RIGHTPAR "NO_START_OPT)" -#define STRING_NOTEMPTY_RIGHTPAR "NOTEMPTY)" -#define STRING_NOTEMPTY_ATSTART_RIGHTPAR "NOTEMPTY_ATSTART)" -#define STRING_CASELESS_RESTRICT_RIGHTPAR "CASELESS_RESTRICT)" -#define STRING_TURKISH_CASING_RIGHTPAR "TURKISH_CASING)" -#define STRING_LIMIT_HEAP_EQ "LIMIT_HEAP=" -#define STRING_LIMIT_MATCH_EQ "LIMIT_MATCH=" -#define STRING_LIMIT_DEPTH_EQ "LIMIT_DEPTH=" -#define STRING_LIMIT_RECURSION_EQ "LIMIT_RECURSION=" -#define STRING_MARK "MARK" - -#define STRING_bc "bc" -#define STRING_bidiclass "bidiclass" -#define STRING_sc "sc" -#define STRING_script "script" -#define STRING_scriptextensions "scriptextensions" -#define STRING_scx "scx" +#endif /* EBCDIC_WITH_ASCII_COMPILER */ #else /* SUPPORT_UNICODE */ @@ -1227,6 +1347,9 @@ only. */ #define STR_RIGHT_CURLY_BRACKET "\175" #define STR_TILDE "\176" +#endif /* SUPPORT_UNICODE */ + + #define STRING_ACCEPT0 STR_A STR_C STR_C STR_E STR_P STR_T "\0" #define STRING_COMMIT0 STR_C STR_O STR_M STR_M STR_I STR_T "\0" #define STRING_F0 STR_F "\0" @@ -1311,8 +1434,6 @@ only. */ #define STRING_scx STR_s STR_c STR_x -#endif /* SUPPORT_UNICODE */ - /* -------------------- End of character and string names -------------------*/ /* -------------------- Definitions for compiled patterns -------------------*/ @@ -1791,7 +1912,7 @@ pcre2_dfa_match.c that must be updated. */ /* This macro defines textual names for all the opcodes. These are used only for debugging, and some of them are only partial names. The macro is referenced -only in pcre2_printint.c, which fills out the full names in many cases (and in +only in pcre2_printint_inc.h, which fills out the full names in many cases (and in some cases doesn't actually use these names at all). */ #define OP_NAME_LIST \ @@ -2075,7 +2196,7 @@ tables are needed only when compiling the 8-bit library. */ #if PCRE2_CODE_UNIT_WIDTH == 8 extern const int PRIV(utf8_table1)[]; -extern const int PRIV(utf8_table1_size); +extern const unsigned PRIV(utf8_table1_size); extern const int PRIV(utf8_table2)[]; extern const int PRIV(utf8_table3)[]; extern const uint8_t PRIV(utf8_table4)[]; @@ -2110,6 +2231,8 @@ extern const uint8_t PRIV(utf8_table4)[]; #define _pcre2_utt PCRE2_SUFFIX(_pcre2_utt_) #define _pcre2_utt_names PCRE2_SUFFIX(_pcre2_utt_names_) #define _pcre2_utt_size PCRE2_SUFFIX(_pcre2_utt_size_) +#define _pcre2_ebcdic_1047_to_ascii PCRE2_SUFFIX(_pcre2_ebcdic_1047_to_ascii_) +#define _pcre2_ascii_to_ebcdic_1047 PCRE2_SUFFIX(_pcre2_ascii_to_ebcdic_1047_) extern const uint8_t PRIV(OP_lengths)[]; extern const uint32_t PRIV(callout_end_delims)[]; @@ -2142,6 +2265,8 @@ extern const char *PRIV(unicode_version); extern const ucp_type_table PRIV(utt)[]; extern const char PRIV(utt_names)[]; extern const size_t PRIV(utt_size); +extern const uint8_t PRIV(ebcdic_1047_to_ascii)[]; +extern const uint8_t PRIV(ascii_to_ebcdic_1047)[]; /* Mode-dependent macros and hidden and private structures are defined in a separate file so that pcre2test can include them at all supported widths. When @@ -2165,6 +2290,7 @@ is available. */ #define _pcre2_auto_possessify PCRE2_SUFFIX(_pcre2_auto_possessify_) #define _pcre2_check_escape PCRE2_SUFFIX(_pcre2_check_escape_) +#define _pcre2_ckd_smul PCRE2_SUFFIX(_pcre2_ckd_smul_) #define _pcre2_extuni PCRE2_SUFFIX(_pcre2_extuni_) #define _pcre2_find_bracket PCRE2_SUFFIX(_pcre2_find_bracket_) #define _pcre2_is_newline PCRE2_SUFFIX(_pcre2_is_newline_) @@ -2191,6 +2317,7 @@ extern int _pcre2_auto_possessify(PCRE2_UCHAR *, const compile_block *); extern int _pcre2_check_escape(PCRE2_SPTR *, PCRE2_SPTR, uint32_t *, int *, uint32_t, uint32_t, uint32_t, BOOL, compile_block *); +extern BOOL _pcre2_ckd_smul(PCRE2_SIZE *, int, int); extern PCRE2_SPTR _pcre2_extuni(uint32_t, PCRE2_SPTR, PCRE2_SPTR, PCRE2_SPTR, BOOL, int *); extern PCRE2_SPTR _pcre2_find_bracket(PCRE2_SPTR, BOOL, int); @@ -2217,17 +2344,8 @@ extern BOOL _pcre2_xclass(uint32_t, PCRE2_SPTR, const uint8_t *, BOOL); extern BOOL _pcre2_eclass(uint32_t, PCRE2_SPTR, PCRE2_SPTR, const uint8_t *, BOOL); -/* This function is needed only when memmove() is not available. */ - -#if !defined(VPCOMPAT) && !defined(HAVE_MEMMOVE) -#define _pcre2_memmove PCRE2_SUFFIX(_pcre2_memmove) -extern void * _pcre2_memmove(void *, const void *, size_t); -#endif - #endif /* PCRE2_CODE_UNIT_WIDTH */ -extern BOOL PRIV(ckd_smul)(PCRE2_SIZE *, int, int); - #include "pcre2_util.h" #endif /* PCRE2_INTERNAL_H_IDEMPOTENT_GUARD */ diff --git a/libpcre/src/pcre2_intmodedep.h b/libpcre/src/pcre2_intmodedep.h index 6b858139f..6cefb61d3 100644 --- a/libpcre/src/pcre2_intmodedep.h +++ b/libpcre/src/pcre2_intmodedep.h @@ -47,9 +47,16 @@ to have access to the hidden structures at all supported widths. Some of the mode-dependent macros are required at different widths for different parts of the pcre2test code (in particular, the included -pcre2_printint.c file). We undefine them here so that they can be re-defined for -multiple inclusions. Not all of these are used in pcre2test, but it's easier -just to undefine them all. */ +pcre2_printint_inc.h file). We undefine them here so that they can be re-defined +for multiple inclusions. Not all of these are used in pcre2test, but it's easier +just to undefine them all. + +You can also include pcre2_intmodedep.h with PCRE2_CODE_UNIT_WIDTH defined to +zero in order to simply clear the previous macros. */ + +#ifndef PCRE2_CODE_UNIT_WIDTH +#error PCRE2_CODE_UNIT_WIDTH must be defined +#endif #undef ACROSSCHAR #undef BACKCHAR @@ -81,9 +88,14 @@ just to undefine them all. */ #undef PUTINC #undef TABLE_GET +/************************************************* +* MACROS * +*************************************************/ +/* Macros may be undefined and re-defined if the same file handles multiple +bit-widths. */ -/* -------------------------- MACROS ----------------------------- */ +#if PCRE2_CODE_UNIT_WIDTH != 0 /* PCRE keeps offsets in its compiled code as at least 16-bit quantities (always stored in big-endian order in 8-bit mode) by default. These are used, @@ -97,11 +109,23 @@ unit string is now handled by the macros that are defined here. The macros are controlled by the value of LINK_SIZE. This defaults to 2, but values of 3 or 4 are also supported. */ +#ifndef CONFIGURED_LINK_SIZE +#if LINK_SIZE == 2 +#define CONFIGURED_LINK_SIZE 2 +#elif LINK_SIZE == 3 +#define CONFIGURED_LINK_SIZE 3 +#elif LINK_SIZE == 4 +#define CONFIGURED_LINK_SIZE 4 +#else +#error LINK_SIZE must be 2, 3, or 4 +#endif +#endif /* CONFIGURED_LINK_SIZE */ + /* ------------------- 8-bit support ------------------ */ #if PCRE2_CODE_UNIT_WIDTH == 8 -#if LINK_SIZE == 2 +#if CONFIGURED_LINK_SIZE == 2 #define PUT(a,n,d) \ (a[n] = (PCRE2_UCHAR)((d) >> 8)), \ (a[(n)+1] = (PCRE2_UCHAR)((d) & 255)) @@ -109,7 +133,7 @@ values of 3 or 4 are also supported. */ (unsigned int)(((a)[n] << 8) | (a)[(n)+1]) #define MAX_PATTERN_SIZE (1 << 16) -#elif LINK_SIZE == 3 +#elif CONFIGURED_LINK_SIZE == 3 #define PUT(a,n,d) \ (a[n] = (PCRE2_UCHAR)((d) >> 16)), \ (a[(n)+1] = (PCRE2_UCHAR)((d) >> 8)), \ @@ -118,7 +142,7 @@ values of 3 or 4 are also supported. */ (unsigned int)(((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2]) #define MAX_PATTERN_SIZE (1 << 24) -#elif LINK_SIZE == 4 +#elif CONFIGURED_LINK_SIZE == 4 #define PUT(a,n,d) \ (a[n] = (PCRE2_UCHAR)((d) >> 24)), \ (a[(n)+1] = (PCRE2_UCHAR)((d) >> 16)), \ @@ -128,8 +152,6 @@ values of 3 or 4 are also supported. */ (unsigned int)(((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3]) #define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ -#else -#error LINK_SIZE must be 2, 3, or 4 #endif @@ -137,7 +159,7 @@ values of 3 or 4 are also supported. */ #elif PCRE2_CODE_UNIT_WIDTH == 16 -#if LINK_SIZE == 2 +#if CONFIGURED_LINK_SIZE == 2 #undef LINK_SIZE #define LINK_SIZE 1 #define PUT(a,n,d) \ @@ -146,7 +168,7 @@ values of 3 or 4 are also supported. */ (a[n]) #define MAX_PATTERN_SIZE (1 << 16) -#elif LINK_SIZE == 3 || LINK_SIZE == 4 +#elif CONFIGURED_LINK_SIZE == 3 || CONFIGURED_LINK_SIZE == 4 #undef LINK_SIZE #define LINK_SIZE 2 #define PUT(a,n,d) \ @@ -156,8 +178,6 @@ values of 3 or 4 are also supported. */ (unsigned int)(((a)[n] << 16) | (a)[(n)+1]) #define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ -#else -#error LINK_SIZE must be 2, 3, or 4 #endif @@ -194,7 +214,7 @@ arithmetic results in a signed value. Hence the cast. */ #define GET2(a,n) (unsigned int)(((a)[n] << 8) | (a)[(n)+1]) #define PUT2(a,n,d) a[n] = (d) >> 8, a[(n)+1] = (d) & 255 -#else /* Code units are 16 or 32 bits */ +#elif PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 #define IMM2_SIZE 1 #define GET2(a,n) a[n] #define PUT2(a,n,d) a[n] = d @@ -219,7 +239,7 @@ check is needed before accessing these tables. */ #define CHMAX_255(c) TRUE #endif /* SUPPORT_UNICODE */ -#else /* Code units are 16 or 32 bits */ +#elif PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 #define CHMAX_255(c) ((c) <= 255u) #define MAX_255(c) ((c) <= 255u) #define MAX_MARK ((1u << 16) - 1) @@ -285,7 +305,7 @@ UTF support is omitted, we don't even define them. */ #define HAS_EXTRALEN(c) HASUTF8EXTRALEN(c) -/* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE. +/* Returns with the additional number of characters if HAS_EXTRALEN(c) is TRUE. Otherwise it has an undefined behaviour. */ #define GET_EXTRALEN(c) (PRIV(utf8_table4)[(c) & 0x3fu]) @@ -371,7 +391,7 @@ because almost all calls are already within a block of UTF-8 only code. */ #define HAS_EXTRALEN(c) (((c) & 0xfc00u) == 0xd800u) -/* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE. +/* Returns with the additional number of characters if HAS_EXTRALEN(c) is TRUE. Otherwise it has an undefined behaviour. */ #define GET_EXTRALEN(c) 1 @@ -466,7 +486,7 @@ code. */ /* ------------------- 32-bit support ------------------ */ -#else +#elif PCRE2_CODE_UNIT_WIDTH == 32 /* These are trivial for the 32-bit library, since all UTF-32 characters fit into one PCRE2_UCHAR unit. */ @@ -547,6 +567,32 @@ These are all no-ops since all UTF-32 characters fit into one PCRE2_UCHAR. */ #define PUTINC(a,n,d) PUT(a,n,d), a += LINK_SIZE #define PUT2INC(a,n,d) PUT2(a,n,d), a += IMM2_SIZE +#endif /* PCRE2_CODE_UNIT_WIDTH != 0 */ + + + +/************************************************* +* STRUCTURES * +*************************************************/ + +/* We need a more complex include guard than usual, because the file can be +included once for each bit-width to define the various structures. */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 && !defined PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_8 +#define PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_8 +#define PCRE2_INTMODEDEP_CAN_DEFINE +#endif +#if PCRE2_CODE_UNIT_WIDTH == 16 && !defined PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_16 +#define PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_16 +#define PCRE2_INTMODEDEP_CAN_DEFINE +#endif +#if PCRE2_CODE_UNIT_WIDTH == 32 && !defined PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_32 +#define PCRE2_INTMODEDEP_IDEMPOTENT_GUARD_32 +#define PCRE2_INTMODEDEP_CAN_DEFINE +#endif + +#ifdef PCRE2_INTMODEDEP_CAN_DEFINE +#undef PCRE2_INTMODEDEP_CAN_DEFINE /* ----------------------- HIDDEN STRUCTURES ----------------------------- */ @@ -624,7 +670,7 @@ have 16-bit arguments in 8-bit and 16-bit modes, so we need no more than a #define CODE_BLOCKSIZE_TYPE PCRE2_SIZE #undef LOOKBEHIND_MAX -#define LOOKBEHIND_MAX UINT16_MAX +#define LOOKBEHIND_MAX ((int)UINT16_MAX) typedef struct pcre2_real_code { pcre2_memctl memctl; /* Memory control fields */ @@ -672,12 +718,14 @@ typedef struct pcre2_real_match_data { struct heapframe *heapframes; /* Backtracking frames heap memory */ PCRE2_SIZE heapframes_size; /* Malloc-ed size */ PCRE2_SIZE subject_length; /* Subject length */ + PCRE2_SIZE start_offset; /* Offset to start of search */ PCRE2_SIZE leftchar; /* Offset to leftmost code unit */ PCRE2_SIZE rightchar; /* Offset to rightmost code unit */ PCRE2_SIZE startchar; /* Offset to starting code unit */ uint8_t matchedby; /* Type of match (normal, JIT, DFA) */ uint8_t flags; /* Various flags */ uint16_t oveccount; /* Number of pairs */ + uint32_t options; /* Options passed in to the match call */ int rc; /* The return code from the match */ PCRE2_SIZE ovector[131072]; /* Must be last in the structure */ } pcre2_real_match_data; @@ -718,20 +766,31 @@ typedef struct branch_chain { } branch_chain; /* Structure for building a list of named groups during the first pass of -compiling. */ +compiling. When a duplicate name is stored in the list, its name is set to +the name of the first entry with the same name, and its length is set to 0. */ typedef struct named_group { PCRE2_SPTR name; /* Points to the name in the pattern */ uint32_t number; /* Group number */ uint16_t length; /* Length of the name */ - uint16_t isdup; /* TRUE if a duplicate */ + uint16_t hash_dup; /* A concatenation of a 15 bit hash code and + a singe bit which represents duplication */ } named_group; +/* Structure for storing compile time data. */ + +typedef struct compile_data { + struct compile_data *next; /* Next compile data */ +#ifdef PCRE2_DEBUG + uint8_t type; /* Debug only type of the data */ +#endif +} compile_data; + /* Structure for caching sorted ranges. This improves the performance of translating META code to byte code. */ typedef struct class_ranges { - struct class_ranges *next; /* Next class ranges */ + compile_data header; /* Common header */ size_t char_lists_size; /* Total size of encoded char lists */ size_t char_lists_start; /* Start offset of encoded char lists */ uint16_t range_list_size; /* Size of ranges array */ @@ -739,6 +798,14 @@ typedef struct class_ranges { /* Followed by the list of ranges (start/end pairs) */ } class_ranges; +/* Structure for sorted recurse arguments. */ + +typedef struct recurse_arguments { + compile_data header; /* Common header */ + size_t size; /* Total size */ + size_t skip_size; /* Space consumed by arguments */ +} recurse_arguments; + typedef union class_bits_storage { uint8_t classbits[32]; uint32_t classwords[8]; @@ -789,9 +856,9 @@ typedef struct compile_block { BOOL had_pruneorskip; /* (*PRUNE) or (*SKIP) encountered */ BOOL had_recurse; /* Had a pattern recursion or subroutine call */ BOOL dupnames; /* Duplicate names exist */ + compile_data *first_data; /* First item in the compile data list */ + compile_data *last_data; /* Last item in the compile data list */ #ifdef SUPPORT_WIDE_CHARS - class_ranges *cranges; /* First class range. */ - class_ranges *next_cranges; /* Next class range. */ size_t char_lists_size; /* Current size of character lists */ #endif } compile_block; @@ -902,7 +969,9 @@ typedef struct match_block { uint32_t match_call_count; /* Number of times a new frame is created */ BOOL hitend; /* Hit the end of the subject at some point */ BOOL hasthen; /* Pattern contains (*THEN) */ + BOOL hasbsk; /* Pattern contains \K */ BOOL allowemptypartial; /* Allow empty hard partial */ + BOOL allowlookaroundbsk; /* Allow \K within lookarounds */ const uint8_t *lcc; /* Points to lower casing table */ const uint8_t *fcc; /* Points to case-flipping table */ const uint8_t *ctypes; /* Points to table of type maps */ @@ -970,4 +1039,6 @@ typedef struct dfa_match_block { #endif /* PCRE2_PCRE2TEST */ +#endif /* PCRE2_INTMODEDEP_CAN_DEFINE */ + /* End of pcre2_intmodedep.h */ diff --git a/libpcre/src/pcre2_jit_compile.c b/libpcre/src/pcre2_jit_compile.c deleted file mode 100644 index 2d3da6022..000000000 --- a/libpcre/src/pcre2_jit_compile.c +++ /dev/null @@ -1,14103 +0,0 @@ -/************************************************* -* Perl-Compatible Regular Expressions * -*************************************************/ - -/* PCRE is a library of functions to support regular expressions whose syntax -and semantics are as close as possible to those of the Perl 5 language. - - Written by Philip Hazel - This module by Zoltan Herczeg - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2024 University of Cambridge - ------------------------------------------------------------------------------ -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - * Neither the name of the University of Cambridge nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------------ -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#include -#endif /* __has_feature(memory_sanitizer) */ -#endif /* defined(__has_feature) */ - -#include "pcre2_internal.h" - -#ifdef SUPPORT_JIT - -/* All-in-one: Since we use the JIT compiler only from here, -we just include it. This way we don't need to touch the build -system files. */ - -#define SLJIT_CONFIG_AUTO 1 -#define SLJIT_CONFIG_STATIC 1 -#define SLJIT_VERBOSE 0 - -#ifdef PCRE2_DEBUG -#define SLJIT_DEBUG 1 -#else -#define SLJIT_DEBUG 0 -#endif - -#define SLJIT_MALLOC(size, allocator_data) pcre2_jit_malloc(size, allocator_data) -#define SLJIT_FREE(ptr, allocator_data) pcre2_jit_free(ptr, allocator_data) - -static void * pcre2_jit_malloc(size_t size, void *allocator_data) -{ -pcre2_memctl *allocator = ((pcre2_memctl*)allocator_data); -return allocator->malloc(size, allocator->memory_data); -} - -static void pcre2_jit_free(void *ptr, void *allocator_data) -{ -pcre2_memctl *allocator = ((pcre2_memctl*)allocator_data); -allocator->free(ptr, allocator->memory_data); -} - -#include "../deps/sljit/sljit_src/sljitLir.c" - -#if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED -#error Unsupported architecture -#endif - -/* Defines for debugging purposes. */ - -/* 1 - Use unoptimized capturing brackets. - 2 - Enable capture_last_ptr (includes option 1). */ -/* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */ - -/* 1 - Always have a control head. */ -/* #define DEBUG_FORCE_CONTROL_HEAD 1 */ - -/* Allocate memory for the regex stack on the real machine stack. -Fast, but limited size. */ -#define MACHINE_STACK_SIZE 32768 - -/* Growth rate for stack allocated by the OS. Should be the multiply -of page size. */ -#define STACK_GROWTH_RATE 8192 - -/* Enable to check that the allocation could destroy temporaries. */ -#if defined SLJIT_DEBUG && SLJIT_DEBUG -#define DESTROY_REGISTERS 1 -#endif - -/* -Short summary about the backtracking mechanism empolyed by the jit code generator: - -The code generator follows the recursive nature of the PERL compatible regular -expressions. The basic blocks of regular expressions are condition checkers -whose execute different commands depending on the result of the condition check. -The relationship between the operators can be horizontal (concatenation) and -vertical (sub-expression) (See struct backtrack_common for more details). - - 'ab' - 'a' and 'b' regexps are concatenated - 'a+' - 'a' is the sub-expression of the '+' operator - -The condition checkers are boolean (true/false) checkers. Machine code is generated -for the checker itself and for the actions depending on the result of the checker. -The 'true' case is called as the matching path (expected path), and the other is called as -the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken -branches on the matching path. - - Greedy star operator (*) : - Matching path: match happens. - Backtrack path: match failed. - Non-greedy star operator (*?) : - Matching path: no need to perform a match. - Backtrack path: match is required. - -The following example shows how the code generated for a capturing bracket -with two alternatives. Let A, B, C, D are arbirary regular expressions, and -we have the following regular expression: - - A(B|C)D - -The generated code will be the following: - - A matching path - '(' matching path (pushing arguments to the stack) - B matching path - ')' matching path (pushing arguments to the stack) - D matching path - return with successful match - - D backtrack path - ')' backtrack path (If we arrived from "C" jump to the backtrack of "C") - B backtrack path - C expected path - jump to D matching path - C backtrack path - A backtrack path - - Notice, that the order of backtrack code paths are the opposite of the fast - code paths. In this way the topmost value on the stack is always belong - to the current backtrack code path. The backtrack path must check - whether there is a next alternative. If so, it needs to jump back to - the matching path eventually. Otherwise it needs to clear out its own stack - frame and continue the execution on the backtrack code paths. -*/ - -/* -Saved stack frames: - -Atomic blocks and asserts require reloading the values of private data -when the backtrack mechanism performed. Because of OP_RECURSE, the data -are not necessarly known in compile time, thus we need a dynamic restore -mechanism. - -The stack frames are stored in a chain list, and have the following format: -([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ] - -Thus we can restore the private data to a particular point in the stack. -*/ - -typedef struct jit_arguments { - /* Pointers first. */ - struct sljit_stack *stack; - PCRE2_SPTR str; - PCRE2_SPTR begin; - PCRE2_SPTR end; - pcre2_match_data *match_data; - PCRE2_SPTR startchar_ptr; - PCRE2_UCHAR *mark_ptr; - int (*callout)(pcre2_callout_block *, void *); - void *callout_data; - /* Everything else after. */ - sljit_uw offset_limit; - sljit_u32 limit_match; - sljit_u32 oveccount; - sljit_u32 options; -} jit_arguments; - -#define JIT_NUMBER_OF_COMPILE_MODES 3 - -typedef struct executable_functions { - void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES]; - void *read_only_data_heads[JIT_NUMBER_OF_COMPILE_MODES]; - sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES]; - sljit_u32 top_bracket; - sljit_u32 limit_match; -} executable_functions; - -typedef struct jump_list { - struct sljit_jump *jump; - struct jump_list *next; -} jump_list; - -typedef struct stub_list { - struct sljit_jump *start; - struct sljit_label *quit; - struct stub_list *next; -} stub_list; - -enum frame_types { - no_frame = -1, - no_stack = -2 -}; - -enum control_types { - type_mark = 0, - type_then_trap = 1 -}; - -enum early_fail_types { - type_skip = 0, - type_fail = 1, - type_fail_range = 2 -}; - -typedef int (SLJIT_FUNC *jit_function)(jit_arguments *args); - -/* The following structure is the key data type for the recursive -code generator. It is allocated by compile_matchingpath, and contains -the arguments for compile_backtrackingpath. Must be the first member -of its descendants. */ -typedef struct backtrack_common { - /* Backtracking path of an opcode, which falls back - to our opcode, if it cannot resume matching. */ - struct backtrack_common *prev; - /* Backtracks for opcodes without backtracking path. - These opcodes are between 'prev' and the current - opcode, and they never resume the match. */ - jump_list *simple_backtracks; - /* Internal backtracking list for block constructs - which contains other opcodes, such as brackets, - asserts, conditionals, etc. */ - struct backtrack_common *top; - /* Backtracks used internally by the opcode. For component - opcodes, this list is also used by those opcodes without - backtracking path which follows the 'top' backtrack. */ - jump_list *own_backtracks; - /* Opcode pointer. */ - PCRE2_SPTR cc; -} backtrack_common; - -typedef struct assert_backtrack { - backtrack_common common; - jump_list *condfailed; - /* Less than 0 if a frame is not needed. */ - int framesize; - /* Points to our private memory word on the stack. */ - int private_data_ptr; - /* For iterators. */ - struct sljit_label *matchingpath; -} assert_backtrack; - -typedef struct bracket_backtrack { - backtrack_common common; - /* Where to coninue if an alternative is successfully matched. */ - struct sljit_label *alternative_matchingpath; - /* For rmin and rmax iterators. */ - struct sljit_label *recursive_matchingpath; - /* For greedy ? operator. */ - struct sljit_label *zero_matchingpath; - /* Contains the branches of a failed condition. */ - union { - /* Both for OP_COND, OP_SCOND, OP_ASSERT_SCS. */ - jump_list *no_capture; - assert_backtrack *assert; - /* For OP_ONCE. Less than 0 if not needed. */ - int framesize; - } u; - /* For brackets with >3 alternatives. */ - struct sljit_jump *matching_mov_addr; - /* Points to our private memory word on the stack. */ - int private_data_ptr; -} bracket_backtrack; - -typedef struct bracketpos_backtrack { - backtrack_common common; - /* Points to our private memory word on the stack. */ - int private_data_ptr; - /* Reverting stack is needed. */ - int framesize; - /* Allocated stack size. */ - int stacksize; -} bracketpos_backtrack; - -typedef struct braminzero_backtrack { - backtrack_common common; - struct sljit_label *matchingpath; -} braminzero_backtrack; - -typedef struct char_iterator_backtrack { - backtrack_common common; - /* Next iteration. */ - struct sljit_label *matchingpath; - /* Creating a range based on the next character. */ - struct { - unsigned int othercasebit; - PCRE2_UCHAR chr; - BOOL charpos_enabled; - } charpos; -} char_iterator_backtrack; - -typedef struct ref_iterator_backtrack { - backtrack_common common; - /* Next iteration. */ - struct sljit_label *matchingpath; -} ref_iterator_backtrack; - -typedef struct recurse_entry { - struct recurse_entry *next; - /* Contains the function entry label. */ - struct sljit_label *entry_label; - /* Contains the function entry label. */ - struct sljit_label *backtrack_label; - /* Collects the entry calls until the function is not created. */ - jump_list *entry_calls; - /* Collects the backtrack calls until the function is not created. */ - jump_list *backtrack_calls; - /* Points to the starting opcode. */ - sljit_sw start; -} recurse_entry; - -typedef struct recurse_backtrack { - backtrack_common common; - /* Return to the matching path. */ - struct sljit_label *matchingpath; - /* Recursive pattern. */ - recurse_entry *entry; - /* Pattern is inlined. */ - BOOL inlined_pattern; -} recurse_backtrack; - -typedef struct vreverse_backtrack { - backtrack_common common; - /* Return to the matching path. */ - struct sljit_label *matchingpath; -} vreverse_backtrack; - -#define OP_THEN_TRAP OP_TABLE_LENGTH - -typedef struct then_trap_backtrack { - backtrack_common common; - /* If then_trap is not NULL, this structure contains the real - then_trap for the backtracking path. */ - struct then_trap_backtrack *then_trap; - /* Points to the starting opcode. */ - sljit_sw start; - /* Exit point for the then opcodes of this alternative. */ - jump_list *quit; - /* Frame size of the current alternative. */ - int framesize; -} then_trap_backtrack; - -#define MAX_N_CHARS 12 -#define MAX_DIFF_CHARS 5 - -typedef struct fast_forward_char_data { - /* Number of characters in the chars array, 255 for any character. */ - sljit_u8 count; - /* Number of last UTF-8 characters in the chars array. */ - sljit_u8 last_count; - /* Available characters in the current position. */ - PCRE2_UCHAR chars[MAX_DIFF_CHARS]; -} fast_forward_char_data; - -#define MAX_CLASS_RANGE_SIZE 4 -#define MAX_CLASS_CHARS_SIZE 3 - -typedef struct compiler_common { - /* The sljit ceneric compiler. */ - struct sljit_compiler *compiler; - /* Compiled regular expression. */ - pcre2_real_code *re; - /* First byte code. */ - PCRE2_SPTR start; - /* Maps private data offset to each opcode. */ - sljit_s32 *private_data_ptrs; - /* Chain list of read-only data ptrs. */ - void *read_only_data_head; - /* Tells whether the capturing bracket is optimized. */ - sljit_u8 *optimized_cbracket; - /* Tells whether the starting offset is a target of then. */ - sljit_u8 *then_offsets; - /* Current position where a THEN must jump. */ - then_trap_backtrack *then_trap; - /* Starting offset of private data for capturing brackets. */ - sljit_s32 cbra_ptr; -#if defined SLJIT_DEBUG && SLJIT_DEBUG - /* End offset of locals for assertions. */ - sljit_s32 locals_size; -#endif - /* Output vector starting point. Must be divisible by 2. */ - sljit_s32 ovector_start; - /* Points to the starting character of the current match. */ - sljit_s32 start_ptr; - /* Last known position of the requested byte. */ - sljit_s32 req_char_ptr; - /* Head of the last recursion. */ - sljit_s32 recursive_head_ptr; - /* First inspected character for partial matching. - (Needed for avoiding zero length partial matches.) */ - sljit_s32 start_used_ptr; - /* Starting pointer for partial soft matches. */ - sljit_s32 hit_start; - /* Pointer of the match end position. */ - sljit_s32 match_end_ptr; - /* Points to the marked string. */ - sljit_s32 mark_ptr; - /* Head of the recursive control verb management chain. - Each item must have a previous offset and type - (see control_types) values. See do_search_mark. */ - sljit_s32 control_head_ptr; - /* The offset of the saved STR_END in the outermost - scan substring block. Since scan substring restores - STR_END after a match, it is enough to restore - STR_END inside a scan substring block. */ - sljit_s32 restore_end_ptr; - /* Points to the last matched capture block index. */ - sljit_s32 capture_last_ptr; - /* Fast forward skipping byte code pointer. */ - PCRE2_SPTR fast_forward_bc_ptr; - /* Locals used by fast fail optimization. */ - sljit_s32 early_fail_start_ptr; - sljit_s32 early_fail_end_ptr; - /* Variables used by recursive call generator. */ - sljit_s32 recurse_bitset_size; - uint8_t *recurse_bitset; - - /* Flipped and lower case tables. */ - const sljit_u8 *fcc; - sljit_sw lcc; - /* Mode can be PCRE2_JIT_COMPLETE and others. */ - int mode; - /* TRUE, when empty match is accepted for partial matching. */ - BOOL allow_empty_partial; - /* TRUE, when minlength is greater than 0. */ - BOOL might_be_empty; - /* \K is found in the pattern. */ - BOOL has_set_som; - /* (*SKIP:arg) is found in the pattern. */ - BOOL has_skip_arg; - /* (*THEN) is found in the pattern. */ - BOOL has_then; - /* (*SKIP) or (*SKIP:arg) is found in lookbehind assertion. */ - BOOL has_skip_in_assert_back; - /* Quit is redirected by recurse, negative assertion, or positive assertion in conditional block. */ - BOOL local_quit_available; - /* Currently in a positive assertion. */ - BOOL in_positive_assertion; - /* Newline control. */ - int nltype; - sljit_u32 nlmax; - sljit_u32 nlmin; - int newline; - int bsr_nltype; - sljit_u32 bsr_nlmax; - sljit_u32 bsr_nlmin; - /* Dollar endonly. */ - int endonly; - /* Tables. */ - sljit_sw ctypes; - /* Named capturing brackets. */ - PCRE2_SPTR name_table; - sljit_sw name_count; - sljit_sw name_entry_size; - - /* Labels and jump lists. */ - struct sljit_label *partialmatchlabel; - struct sljit_label *quit_label; - struct sljit_label *abort_label; - struct sljit_label *accept_label; - struct sljit_label *ff_newline_shortcut; - stub_list *stubs; - recurse_entry *entries; - recurse_entry *currententry; - jump_list *partialmatch; - jump_list *quit; - jump_list *positive_assertion_quit; - jump_list *abort; - jump_list *failed_match; - jump_list *accept; - jump_list *calllimit; - jump_list *stackalloc; - jump_list *revertframes; - jump_list *wordboundary; - jump_list *ucp_wordboundary; - jump_list *anynewline; - jump_list *hspace; - jump_list *vspace; - jump_list *casefulcmp; - jump_list *caselesscmp; - jump_list *reset_match; - /* Same as reset_match, but resets the STR_PTR as well. */ - jump_list *restart_match; - BOOL unset_backref; - BOOL alt_circumflex; -#ifdef SUPPORT_UNICODE - BOOL utf; - BOOL invalid_utf; - BOOL ucp; - /* Points to saving area for iref. */ - jump_list *getucd; - jump_list *getucdtype; -#if PCRE2_CODE_UNIT_WIDTH == 8 - jump_list *utfreadchar; - jump_list *utfreadtype8; - jump_list *utfpeakcharback; -#endif -#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 - jump_list *utfreadchar_invalid; - jump_list *utfreadnewline_invalid; - jump_list *utfmoveback_invalid; - jump_list *utfpeakcharback_invalid; -#endif -#endif /* SUPPORT_UNICODE */ -} compiler_common; - -/* For byte_sequence_compare. */ - -typedef struct compare_context { - int length; - int sourcereg; -#if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED - int ucharptr; - union { - sljit_s32 asint; - sljit_u16 asushort; -#if PCRE2_CODE_UNIT_WIDTH == 8 - sljit_u8 asbyte; - sljit_u8 asuchars[4]; -#elif PCRE2_CODE_UNIT_WIDTH == 16 - sljit_u16 asuchars[2]; -#elif PCRE2_CODE_UNIT_WIDTH == 32 - sljit_u32 asuchars[1]; -#endif - } c; - union { - sljit_s32 asint; - sljit_u16 asushort; -#if PCRE2_CODE_UNIT_WIDTH == 8 - sljit_u8 asbyte; - sljit_u8 asuchars[4]; -#elif PCRE2_CODE_UNIT_WIDTH == 16 - sljit_u16 asuchars[2]; -#elif PCRE2_CODE_UNIT_WIDTH == 32 - sljit_u32 asuchars[1]; -#endif - } oc; -#endif -} compare_context; - -/* Undefine sljit macros. */ -#undef CMP - -/* Used for accessing the elements of the stack. */ -#define STACK(i) ((i) * SSIZE_OF(sw)) - -#ifdef SLJIT_PREF_SHIFT_REG -#if SLJIT_PREF_SHIFT_REG == SLJIT_R2 -/* Nothing. */ -#elif SLJIT_PREF_SHIFT_REG == SLJIT_R3 -#define SHIFT_REG_IS_R3 -#else -#error "Unsupported shift register" -#endif -#endif - -#define TMP1 SLJIT_R0 -#ifdef SHIFT_REG_IS_R3 -#define TMP2 SLJIT_R3 -#define TMP3 SLJIT_R2 -#else -#define TMP2 SLJIT_R2 -#define TMP3 SLJIT_R3 -#endif -#define STR_PTR SLJIT_R1 -#define STR_END SLJIT_S0 -#define STACK_TOP SLJIT_S1 -#define STACK_LIMIT SLJIT_S2 -#define COUNT_MATCH SLJIT_S3 -#define ARGUMENTS SLJIT_S4 -#define RETURN_ADDR SLJIT_R4 - -#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) -#define HAS_VIRTUAL_REGISTERS 1 -#else -#define HAS_VIRTUAL_REGISTERS 0 -#endif - -/* Local space layout. */ -/* Max limit of recursions. */ -#define LIMIT_MATCH (0 * sizeof(sljit_sw)) -/* Local variables. Their number is computed by check_opcode_types. */ -#define LOCAL0 (1 * sizeof(sljit_sw)) -#define LOCAL1 (2 * sizeof(sljit_sw)) -#define LOCAL2 (3 * sizeof(sljit_sw)) -#define LOCAL3 (4 * sizeof(sljit_sw)) -#define LOCAL4 (5 * sizeof(sljit_sw)) -/* The output vector is stored on the stack, and contains pointers -to characters. The vector data is divided into two groups: the first -group contains the start / end character pointers, and the second is -the start pointers when the end of the capturing group has not yet reached. */ -#define OVECTOR_START (common->ovector_start) -#define OVECTOR(i) (OVECTOR_START + (i) * SSIZE_OF(sw)) -#define OVECTOR_PRIV(i) (common->cbra_ptr + (i) * SSIZE_OF(sw)) -#define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start]) - -#if PCRE2_CODE_UNIT_WIDTH == 8 -#define MOV_UCHAR SLJIT_MOV_U8 -#define IN_UCHARS(x) (x) -#elif PCRE2_CODE_UNIT_WIDTH == 16 -#define MOV_UCHAR SLJIT_MOV_U16 -#define UCHAR_SHIFT (1) -#define IN_UCHARS(x) ((x) * 2) -#elif PCRE2_CODE_UNIT_WIDTH == 32 -#define MOV_UCHAR SLJIT_MOV_U32 -#define UCHAR_SHIFT (2) -#define IN_UCHARS(x) ((x) * 4) -#else -#error Unsupported compiling mode -#endif - -/* Shortcuts. */ -#define DEFINE_COMPILER \ - struct sljit_compiler *compiler = common->compiler -#define OP1(op, dst, dstw, src, srcw) \ - sljit_emit_op1(compiler, (op), (dst), (dstw), (src), (srcw)) -#define OP2(op, dst, dstw, src1, src1w, src2, src2w) \ - sljit_emit_op2(compiler, (op), (dst), (dstw), (src1), (src1w), (src2), (src2w)) -#define OP2U(op, src1, src1w, src2, src2w) \ - sljit_emit_op2u(compiler, (op), (src1), (src1w), (src2), (src2w)) -#define OP_SRC(op, src, srcw) \ - sljit_emit_op_src(compiler, (op), (src), (srcw)) -#define LABEL() \ - sljit_emit_label(compiler) -#define JUMP(type) \ - sljit_emit_jump(compiler, (type)) -#define JUMPTO(type, label) \ - sljit_set_label(sljit_emit_jump(compiler, (type)), (label)) -#define JUMPHERE(jump) \ - sljit_set_label((jump), sljit_emit_label(compiler)) -#define SET_LABEL(jump, label) \ - sljit_set_label((jump), (label)) -#define CMP(type, src1, src1w, src2, src2w) \ - sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)) -#define CMPTO(type, src1, src1w, src2, src2w, label) \ - sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label)) -#define OP_FLAGS(op, dst, dstw, type) \ - sljit_emit_op_flags(compiler, (op), (dst), (dstw), (type)) -#define SELECT(type, dst_reg, src1, src1w, src2_reg) \ - sljit_emit_select(compiler, (type), (dst_reg), (src1), (src1w), (src2_reg)) -#define GET_LOCAL_BASE(dst, dstw, offset) \ - sljit_get_local_base(compiler, (dst), (dstw), (offset)) - -#define READ_CHAR_MAX ((sljit_u32)0xffffffff) - -#define INVALID_UTF_CHAR -1 -#define UNASSIGNED_UTF_CHAR 888 - -#if defined SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 - -#define GETCHARINC_INVALID(c, ptr, end, invalid_action) \ - { \ - if (ptr[0] <= 0x7f) \ - c = *ptr++; \ - else if (ptr + 1 < end && ptr[1] >= 0x80 && ptr[1] < 0xc0) \ - { \ - c = ptr[1] - 0x80; \ - \ - if (ptr[0] >= 0xc2 && ptr[0] <= 0xdf) \ - { \ - c |= (ptr[0] - 0xc0) << 6; \ - ptr += 2; \ - } \ - else if (ptr + 2 < end && ptr[2] >= 0x80 && ptr[2] < 0xc0) \ - { \ - c = c << 6 | (ptr[2] - 0x80); \ - \ - if (ptr[0] >= 0xe0 && ptr[0] <= 0xef) \ - { \ - c |= (ptr[0] - 0xe0) << 12; \ - ptr += 3; \ - \ - if (c < 0x800 || (c >= 0xd800 && c < 0xe000)) \ - { \ - invalid_action; \ - } \ - } \ - else if (ptr + 3 < end && ptr[3] >= 0x80 && ptr[3] < 0xc0) \ - { \ - c = c << 6 | (ptr[3] - 0x80); \ - \ - if (ptr[0] >= 0xf0 && ptr[0] <= 0xf4) \ - { \ - c |= (ptr[0] - 0xf0) << 18; \ - ptr += 4; \ - \ - if (c >= 0x110000 || c < 0x10000) \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } - -#define GETCHARBACK_INVALID(c, ptr, start, invalid_action) \ - { \ - c = ptr[-1]; \ - if (c <= 0x7f) \ - ptr--; \ - else if (ptr - 1 > start && ptr[-1] >= 0x80 && ptr[-1] < 0xc0) \ - { \ - c -= 0x80; \ - \ - if (ptr[-2] >= 0xc2 && ptr[-2] <= 0xdf) \ - { \ - c |= (ptr[-2] - 0xc0) << 6; \ - ptr -= 2; \ - } \ - else if (ptr - 2 > start && ptr[-2] >= 0x80 && ptr[-2] < 0xc0) \ - { \ - c = c << 6 | (ptr[-2] - 0x80); \ - \ - if (ptr[-3] >= 0xe0 && ptr[-3] <= 0xef) \ - { \ - c |= (ptr[-3] - 0xe0) << 12; \ - ptr -= 3; \ - \ - if (c < 0x800 || (c >= 0xd800 && c < 0xe000)) \ - { \ - invalid_action; \ - } \ - } \ - else if (ptr - 3 > start && ptr[-3] >= 0x80 && ptr[-3] < 0xc0) \ - { \ - c = c << 6 | (ptr[-3] - 0x80); \ - \ - if (ptr[-4] >= 0xf0 && ptr[-4] <= 0xf4) \ - { \ - c |= (ptr[-4] - 0xf0) << 18; \ - ptr -= 4; \ - \ - if (c >= 0x110000 || c < 0x10000) \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } \ - else \ - { \ - invalid_action; \ - } \ - } - -#elif PCRE2_CODE_UNIT_WIDTH == 16 - -#define GETCHARINC_INVALID(c, ptr, end, invalid_action) \ - { \ - if (ptr[0] < 0xd800 || ptr[0] >= 0xe000) \ - c = *ptr++; \ - else if (ptr[0] < 0xdc00 && ptr + 1 < end && ptr[1] >= 0xdc00 && ptr[1] < 0xe000) \ - { \ - c = (((ptr[0] - 0xd800) << 10) | (ptr[1] - 0xdc00)) + 0x10000; \ - ptr += 2; \ - } \ - else \ - { \ - invalid_action; \ - } \ - } - -#define GETCHARBACK_INVALID(c, ptr, start, invalid_action) \ - { \ - c = ptr[-1]; \ - if (c < 0xd800 || c >= 0xe000) \ - ptr--; \ - else if (c >= 0xdc00 && ptr - 1 > start && ptr[-2] >= 0xd800 && ptr[-2] < 0xdc00) \ - { \ - c = (((ptr[-2] - 0xd800) << 10) | (c - 0xdc00)) + 0x10000; \ - ptr -= 2; \ - } \ - else \ - { \ - invalid_action; \ - } \ - } - - -#elif PCRE2_CODE_UNIT_WIDTH == 32 - -#define GETCHARINC_INVALID(c, ptr, end, invalid_action) \ - { \ - if (ptr[0] < 0xd800 || (ptr[0] >= 0xe000 && ptr[0] < 0x110000)) \ - c = *ptr++; \ - else \ - { \ - invalid_action; \ - } \ - } - -#define GETCHARBACK_INVALID(c, ptr, start, invalid_action) \ - { \ - c = ptr[-1]; \ - if (ptr[-1] < 0xd800 || (ptr[-1] >= 0xe000 && ptr[-1] < 0x110000)) \ - ptr--; \ - else \ - { \ - invalid_action; \ - } \ - } - -#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */ -#endif /* SUPPORT_UNICODE */ - -static PCRE2_SPTR bracketend(PCRE2_SPTR cc) -{ -SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERT_SCS) || (*cc >= OP_ONCE && *cc <= OP_SCOND)); -do cc += GET(cc, 1); while (*cc == OP_ALT); -SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS); -cc += 1 + LINK_SIZE; -return cc; -} - -static int no_alternatives(PCRE2_SPTR cc) -{ -int count = 0; -SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERT_SCS) || (*cc >= OP_ONCE && *cc <= OP_SCOND)); -do - { - cc += GET(cc, 1); - count++; - } -while (*cc == OP_ALT); -SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS); -return count; -} - -static BOOL find_vreverse(PCRE2_SPTR cc) -{ - SLJIT_ASSERT(*cc == OP_ASSERTBACK || *cc == OP_ASSERTBACK_NOT || *cc == OP_ASSERTBACK_NA); - - do - { - if (cc[1 + LINK_SIZE] == OP_VREVERSE) - return TRUE; - cc += GET(cc, 1); - } - while (*cc == OP_ALT); - - return FALSE; -} - -/* Functions whose might need modification for all new supported opcodes: - next_opcode - check_opcode_types - set_private_data_ptrs - get_framesize - init_frame - get_recurse_data_length - copy_recurse_data - compile_matchingpath - compile_backtrackingpath -*/ - -static PCRE2_SPTR next_opcode(compiler_common *common, PCRE2_SPTR cc) -{ -SLJIT_UNUSED_ARG(common); -switch(*cc) - { - case OP_SOD: - case OP_SOM: - case OP_SET_SOM: - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_NOT_DIGIT: - case OP_DIGIT: - case OP_NOT_WHITESPACE: - case OP_WHITESPACE: - case OP_NOT_WORDCHAR: - case OP_WORDCHAR: - case OP_ANY: - case OP_ALLANY: - case OP_NOTPROP: - case OP_PROP: - case OP_ANYNL: - case OP_NOT_HSPACE: - case OP_HSPACE: - case OP_NOT_VSPACE: - case OP_VSPACE: - case OP_EXTUNI: - case OP_EODN: - case OP_EOD: - case OP_CIRC: - case OP_CIRCM: - case OP_DOLL: - case OP_DOLLM: - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSSTAR: - case OP_CRPOSPLUS: - case OP_CRPOSQUERY: - case OP_CRPOSRANGE: - case OP_CLASS: - case OP_NCLASS: - case OP_REF: - case OP_REFI: - case OP_DNREF: - case OP_DNREFI: - case OP_RECURSE: - case OP_CALLOUT: - case OP_ALT: - case OP_KET: - case OP_KETRMAX: - case OP_KETRMIN: - case OP_KETRPOS: - case OP_REVERSE: - case OP_VREVERSE: - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_BRA: - case OP_BRAPOS: - case OP_CBRA: - case OP_CBRAPOS: - case OP_COND: - case OP_SBRA: - case OP_SBRAPOS: - case OP_SCBRA: - case OP_SCBRAPOS: - case OP_SCOND: - case OP_CREF: - case OP_DNCREF: - case OP_RREF: - case OP_DNRREF: - case OP_FALSE: - case OP_TRUE: - case OP_BRAZERO: - case OP_BRAMINZERO: - case OP_BRAPOSZERO: - case OP_PRUNE: - case OP_SKIP: - case OP_THEN: - case OP_COMMIT: - case OP_FAIL: - case OP_ACCEPT: - case OP_ASSERT_ACCEPT: - case OP_CLOSE: - case OP_SKIPZERO: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - return cc + PRIV(OP_lengths)[*cc]; - - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - case OP_STAR: - case OP_MINSTAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_QUERY: - case OP_MINQUERY: - case OP_UPTO: - case OP_MINUPTO: - case OP_EXACT: - case OP_POSSTAR: - case OP_POSPLUS: - case OP_POSQUERY: - case OP_POSUPTO: - case OP_STARI: - case OP_MINSTARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_UPTOI: - case OP_MINUPTOI: - case OP_EXACTI: - case OP_POSSTARI: - case OP_POSPLUSI: - case OP_POSQUERYI: - case OP_POSUPTOI: - case OP_NOTSTAR: - case OP_NOTMINSTAR: - case OP_NOTPLUS: - case OP_NOTMINPLUS: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTEXACT: - case OP_NOTPOSSTAR: - case OP_NOTPOSPLUS: - case OP_NOTPOSQUERY: - case OP_NOTPOSUPTO: - case OP_NOTSTARI: - case OP_NOTMINSTARI: - case OP_NOTPLUSI: - case OP_NOTMINPLUSI: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTEXACTI: - case OP_NOTPOSSTARI: - case OP_NOTPOSPLUSI: - case OP_NOTPOSQUERYI: - case OP_NOTPOSUPTOI: - cc += PRIV(OP_lengths)[*cc]; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - return cc; - - /* Special cases. */ - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEEXACT: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - case OP_TYPEPOSUPTO: - return cc + PRIV(OP_lengths)[*cc] - 1; - - case OP_ANYBYTE: -#ifdef SUPPORT_UNICODE - if (common->utf) return NULL; -#endif - return cc + 1; - - case OP_CALLOUT_STR: - return cc + GET(cc, 1 + 2*LINK_SIZE); - -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 - case OP_ECLASS: - case OP_XCLASS: - SLJIT_COMPILE_ASSERT(OP_XCLASS + 1 == OP_ECLASS && OP_CLASS + 1 == OP_NCLASS && OP_NCLASS < OP_XCLASS, class_byte_code_order); - return cc + GET(cc, 1); -#endif - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_SKIP_ARG: - case OP_THEN_ARG: - return cc + 1 + 2 + cc[1]; - - default: - SLJIT_UNREACHABLE(); - return NULL; - } -} - -static sljit_s32 ref_update_local_size(compiler_common *common, PCRE2_SPTR cc, sljit_s32 current_locals_size) -{ -/* Depends on do_casefulcmp(), do_caselesscmp(), and compile_ref_matchingpath() */ -int locals_size = 2 * SSIZE_OF(sw); -SLJIT_UNUSED_ARG(common); - -#ifdef SUPPORT_UNICODE -if ((*cc == OP_REFI || *cc == OP_DNREFI) && (common->utf || common->ucp)) - locals_size = 3 * SSIZE_OF(sw); -#endif - -cc += PRIV(OP_lengths)[*cc]; -/* Although do_casefulcmp() uses only one local, the allocate_stack() -calls during the repeat destroys LOCAL1 variables. */ -if (*cc >= OP_CRSTAR && *cc <= OP_CRPOSRANGE) - locals_size += 2 * SSIZE_OF(sw); - -return (current_locals_size >= locals_size) ? current_locals_size : locals_size; -} - -static BOOL check_opcode_types(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend) -{ -int count; -PCRE2_SPTR slot; -PCRE2_SPTR assert_back_end = cc - 1; -PCRE2_SPTR assert_na_end = cc - 1; -sljit_s32 locals_size = 2 * SSIZE_OF(sw); -BOOL set_recursive_head = FALSE; -BOOL set_capture_last = FALSE; -BOOL set_mark = FALSE; - -/* Calculate important variables (like stack size) and checks whether all opcodes are supported. */ -while (cc < ccend) - { - switch(*cc) - { - case OP_SET_SOM: - common->has_set_som = TRUE; - common->might_be_empty = TRUE; - cc += 1; - break; - - case OP_TYPEUPTO: - case OP_TYPEEXACT: - if (cc[1 + IMM2_SIZE] == OP_EXTUNI && locals_size <= 3 * SSIZE_OF(sw)) - locals_size = 3 * SSIZE_OF(sw); - cc += (2 + IMM2_SIZE) - 1; - break; - - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - if (cc[1] == OP_EXTUNI && locals_size <= 3 * SSIZE_OF(sw)) - locals_size = 3 * SSIZE_OF(sw); - cc += 2 - 1; - break; - - case OP_TYPEPOSUPTO: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf && locals_size <= 3 * SSIZE_OF(sw)) - locals_size = 3 * SSIZE_OF(sw); -#endif - if (cc[1 + IMM2_SIZE] == OP_EXTUNI && locals_size <= 3 * SSIZE_OF(sw)) - locals_size = 3 * SSIZE_OF(sw); - cc += (2 + IMM2_SIZE) - 1; - break; - - case OP_REFI: - case OP_REF: - locals_size = ref_update_local_size(common, cc, locals_size); - common->optimized_cbracket[GET2(cc, 1)] = 0; - cc += PRIV(OP_lengths)[*cc]; - break; - - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - slot = bracketend(cc); - if (slot > assert_na_end) - assert_na_end = slot; - cc += 1 + LINK_SIZE; - break; - - case OP_CBRAPOS: - case OP_SCBRAPOS: - common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0; - cc += 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_COND: - case OP_SCOND: - /* Only AUTO_CALLOUT can insert this opcode. We do - not intend to support this case. */ - if (cc[1 + LINK_SIZE] == OP_CALLOUT || cc[1 + LINK_SIZE] == OP_CALLOUT_STR) - return FALSE; - cc += 1 + LINK_SIZE; - break; - - case OP_CREF: - common->optimized_cbracket[GET2(cc, 1)] = 0; - cc += 1 + IMM2_SIZE; - break; - - case OP_DNREFI: - case OP_DNREF: - locals_size = ref_update_local_size(common, cc, locals_size); - /* Fall through */ - case OP_DNCREF: - count = GET2(cc, 1 + IMM2_SIZE); - slot = common->name_table + GET2(cc, 1) * common->name_entry_size; - while (count-- > 0) - { - common->optimized_cbracket[GET2(slot, 0)] = 0; - slot += common->name_entry_size; - } - cc += PRIV(OP_lengths)[*cc]; - break; - - case OP_RECURSE: - /* Set its value only once. */ - set_recursive_head = TRUE; - cc += 1 + LINK_SIZE; - break; - - case OP_CALLOUT: - case OP_CALLOUT_STR: - set_capture_last = TRUE; - cc += (*cc == OP_CALLOUT) ? PRIV(OP_lengths)[OP_CALLOUT] : GET(cc, 1 + 2*LINK_SIZE); - break; - - case OP_ASSERTBACK: - slot = bracketend(cc); - if (slot > assert_back_end) - assert_back_end = slot; - cc += 1 + LINK_SIZE; - break; - - case OP_THEN_ARG: - common->has_then = TRUE; - common->control_head_ptr = 1; - /* Fall through. */ - - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_MARK: - set_mark = TRUE; - cc += 1 + 2 + cc[1]; - break; - - case OP_THEN: - common->has_then = TRUE; - common->control_head_ptr = 1; - cc += 1; - break; - - case OP_SKIP: - if (cc < assert_back_end) - common->has_skip_in_assert_back = TRUE; - cc += 1; - break; - - case OP_SKIP_ARG: - common->control_head_ptr = 1; - common->has_skip_arg = TRUE; - if (cc < assert_back_end) - common->has_skip_in_assert_back = TRUE; - cc += 1 + 2 + cc[1]; - break; - - case OP_ASSERT_ACCEPT: - if (cc < assert_na_end) - return FALSE; - cc++; - break; - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - case OP_CRPOSRANGE: - /* The second value can be 0 for infinite repeats. */ - if (common->utf && GET2(cc, 1) != GET2(cc, 1 + IMM2_SIZE) && locals_size <= 3 * SSIZE_OF(sw)) - locals_size = 3 * SSIZE_OF(sw); - cc += 1 + 2 * IMM2_SIZE; - break; - - case OP_POSUPTO: - case OP_POSUPTOI: - case OP_NOTPOSUPTO: - case OP_NOTPOSUPTOI: - if (common->utf && locals_size <= 3 * SSIZE_OF(sw)) - locals_size = 3 * SSIZE_OF(sw); -#endif - /* Fall through */ - default: - cc = next_opcode(common, cc); - if (cc == NULL) - return FALSE; - break; - } - } - -SLJIT_ASSERT((locals_size & (SSIZE_OF(sw) - 1)) == 0); -#if defined SLJIT_DEBUG && SLJIT_DEBUG -common->locals_size = locals_size; -#endif - -if (locals_size > 0) - common->ovector_start += locals_size; - -if (set_mark) - { - SLJIT_ASSERT(common->mark_ptr == 0); - common->mark_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - -if (set_recursive_head) - { - SLJIT_ASSERT(common->recursive_head_ptr == 0); - common->recursive_head_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - -if (set_capture_last) - { - SLJIT_ASSERT(common->capture_last_ptr == 0); - common->capture_last_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - -return TRUE; -} - -#define EARLY_FAIL_ENHANCE_MAX (3 + 3) - -/* - Start represent the number of allowed early fail enhancements - - The 0-2 values has a special meaning: - 0 - skip is allowed for all iterators - 1 - fail is allowed for all iterators - 2 - fail is allowed for greedy iterators - 3 - only ranged early fail is allowed - >3 - (start - 3) number of remaining ranged early fails allowed - -return: the updated value of start -*/ -static int detect_early_fail(compiler_common *common, PCRE2_SPTR cc, - int *private_data_start, sljit_s32 depth, int start) -{ -PCRE2_SPTR begin = cc; -PCRE2_SPTR next_alt; -PCRE2_SPTR end; -PCRE2_SPTR accelerated_start; -int result = 0; -int count, prev_count; - -SLJIT_ASSERT(*cc == OP_ONCE || *cc == OP_BRA || *cc == OP_CBRA); -SLJIT_ASSERT(*cc != OP_CBRA || common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] != 0); -SLJIT_ASSERT(start < EARLY_FAIL_ENHANCE_MAX); - -next_alt = cc + GET(cc, 1); -if (*next_alt == OP_ALT && start < 1) - start = 1; - -do - { - count = start; - cc += 1 + LINK_SIZE + ((*cc == OP_CBRA) ? IMM2_SIZE : 0); - - while (TRUE) - { - accelerated_start = NULL; - - switch(*cc) - { - case OP_SOD: - case OP_SOM: - case OP_SET_SOM: - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_EODN: - case OP_EOD: - case OP_CIRC: - case OP_CIRCM: - case OP_DOLL: - case OP_DOLLM: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - /* Zero width assertions. */ - cc++; - continue; - - case OP_NOT_DIGIT: - case OP_DIGIT: - case OP_NOT_WHITESPACE: - case OP_WHITESPACE: - case OP_NOT_WORDCHAR: - case OP_WORDCHAR: - case OP_ANY: - case OP_ALLANY: - case OP_ANYBYTE: - case OP_NOT_HSPACE: - case OP_HSPACE: - case OP_NOT_VSPACE: - case OP_VSPACE: - if (count < 1) - count = 1; - cc++; - continue; - - case OP_ANYNL: - case OP_EXTUNI: - if (count < 3) - count = 3; - cc++; - continue; - - case OP_NOTPROP: - case OP_PROP: - if (count < 1) - count = 1; - cc += 1 + 2; - continue; - - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - if (count < 1) - count = 1; - cc += 2; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - continue; - - case OP_TYPEMINSTAR: - case OP_TYPEMINPLUS: - if (count == 2) - count = 3; - /* Fall through */ - - case OP_TYPESTAR: - case OP_TYPEPLUS: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - /* The type or prop opcode is skipped in the next iteration. */ - cc += 1; - - if (cc[0] != OP_ANYNL && cc[0] != OP_EXTUNI) - { - accelerated_start = cc - 1; - break; - } - - if (count < 3) - count = 3; - continue; - - case OP_TYPEEXACT: - if (count < 1) - count = 1; - cc += 1 + IMM2_SIZE; - continue; - - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEPOSUPTO: - cc += IMM2_SIZE; - /* Fall through */ - - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEPOSQUERY: - /* The type or prop opcode is skipped in the next iteration. */ - if (count < 3) - count = 3; - cc += 1; - continue; - - case OP_MINSTAR: - case OP_MINPLUS: - case OP_MINSTARI: - case OP_MINPLUSI: - case OP_NOTMINSTAR: - case OP_NOTMINPLUS: - case OP_NOTMINSTARI: - case OP_NOTMINPLUSI: - if (count == 2) - count = 3; - /* Fall through */ - - case OP_STAR: - case OP_PLUS: - case OP_POSSTAR: - case OP_POSPLUS: - - case OP_STARI: - case OP_PLUSI: - case OP_POSSTARI: - case OP_POSPLUSI: - - case OP_NOTSTAR: - case OP_NOTPLUS: - case OP_NOTPOSSTAR: - case OP_NOTPOSPLUS: - - case OP_NOTSTARI: - case OP_NOTPLUSI: - case OP_NOTPOSSTARI: - case OP_NOTPOSPLUSI: - accelerated_start = cc; - cc += 2; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - case OP_EXACT: - if (count < 1) - count = 1; - cc += 2 + IMM2_SIZE; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - continue; - - case OP_UPTO: - case OP_MINUPTO: - case OP_POSUPTO: - case OP_UPTOI: - case OP_MINUPTOI: - case OP_EXACTI: - case OP_POSUPTOI: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTEXACT: - case OP_NOTPOSUPTO: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTEXACTI: - case OP_NOTPOSUPTOI: - cc += IMM2_SIZE; - /* Fall through */ - - case OP_QUERY: - case OP_MINQUERY: - case OP_POSQUERY: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_POSQUERYI: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTPOSQUERY: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTPOSQUERYI: - if (count < 3) - count = 3; - cc += 2; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - continue; - - case OP_CLASS: - case OP_NCLASS: -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 - case OP_XCLASS: - case OP_ECLASS: - accelerated_start = cc; - cc += (*cc >= OP_XCLASS) ? GET(cc, 1) : (unsigned int)(1 + (32 / sizeof(PCRE2_UCHAR))); -#else - accelerated_start = cc; - cc += (1 + (32 / sizeof(PCRE2_UCHAR))); -#endif - - switch (*cc) - { - case OP_CRMINSTAR: - case OP_CRMINPLUS: - if (count == 2) - count = 3; - /* Fall through */ - - case OP_CRSTAR: - case OP_CRPLUS: - case OP_CRPOSSTAR: - case OP_CRPOSPLUS: - cc++; - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE)) - { - /* Exact repeat. */ - cc += 1 + 2 * IMM2_SIZE; - if (count < 1) - count = 1; - continue; - } - - cc += 2 * IMM2_SIZE; - /* Fall through */ - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSQUERY: - cc++; - if (count < 3) - count = 3; - continue; - - default: - /* No repeat. */ - if (count < 1) - count = 1; - continue; - } - break; - - case OP_BRA: - case OP_CBRA: - prev_count = count; - if (count < 1) - count = 1; - - if (depth >= 4) - break; - - if (count < 3 && cc[GET(cc, 1)] == OP_ALT) - count = 3; - - end = bracketend(cc); - if (end[-1 - LINK_SIZE] != OP_KET || (*cc == OP_CBRA && common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)) - break; - - prev_count = detect_early_fail(common, cc, private_data_start, depth + 1, prev_count); - - if (prev_count > count) - count = prev_count; - - if (PRIVATE_DATA(cc) != 0) - common->private_data_ptrs[begin - common->start] = 1; - - if (count < EARLY_FAIL_ENHANCE_MAX) - { - cc = end; - continue; - } - break; - - case OP_KET: - SLJIT_ASSERT(PRIVATE_DATA(cc) == 0); - if (cc >= next_alt) - break; - cc += 1 + LINK_SIZE; - continue; - } - - if (accelerated_start == NULL) - break; - - if (count == 0) - { - common->fast_forward_bc_ptr = accelerated_start; - common->private_data_ptrs[(accelerated_start + 1) - common->start] = ((*private_data_start) << 3) | type_skip; - *private_data_start += sizeof(sljit_sw); - count = 4; - } - else if (count < 3) - { - common->private_data_ptrs[(accelerated_start + 1) - common->start] = ((*private_data_start) << 3) | type_fail; - - if (common->early_fail_start_ptr == 0) - common->early_fail_start_ptr = *private_data_start; - - *private_data_start += sizeof(sljit_sw); - common->early_fail_end_ptr = *private_data_start; - - if (*private_data_start > SLJIT_MAX_LOCAL_SIZE) - return EARLY_FAIL_ENHANCE_MAX; - - count = 4; - } - else - { - common->private_data_ptrs[(accelerated_start + 1) - common->start] = ((*private_data_start) << 3) | type_fail_range; - - if (common->early_fail_start_ptr == 0) - common->early_fail_start_ptr = *private_data_start; - - *private_data_start += 2 * sizeof(sljit_sw); - common->early_fail_end_ptr = *private_data_start; - - if (*private_data_start > SLJIT_MAX_LOCAL_SIZE) - return EARLY_FAIL_ENHANCE_MAX; - - count++; - } - - /* Cannot be part of a repeat. */ - common->private_data_ptrs[begin - common->start] = 1; - - if (count >= EARLY_FAIL_ENHANCE_MAX) - break; - } - - if (*cc != OP_ALT && *cc != OP_KET) - result = EARLY_FAIL_ENHANCE_MAX; - else if (result < count) - result = count; - - cc = next_alt; - next_alt = cc + GET(cc, 1); - } -while (*cc == OP_ALT); - -return result; -} - -static int get_class_iterator_size(PCRE2_SPTR cc) -{ -sljit_u32 min; -sljit_u32 max; -switch(*cc) - { - case OP_CRSTAR: - case OP_CRPLUS: - return 2; - - case OP_CRMINSTAR: - case OP_CRMINPLUS: - case OP_CRQUERY: - case OP_CRMINQUERY: - return 1; - - case OP_CRRANGE: - case OP_CRMINRANGE: - min = GET2(cc, 1); - max = GET2(cc, 1 + IMM2_SIZE); - if (max == 0) - return (*cc == OP_CRRANGE) ? 2 : 1; - max -= min; - if (max > (sljit_u32)(*cc == OP_CRRANGE ? 0 : 1)) - max = 2; - return max; - - default: - return 0; - } -} - -static BOOL detect_repeat(compiler_common *common, PCRE2_SPTR begin) -{ -PCRE2_SPTR end = bracketend(begin); -PCRE2_SPTR next; -PCRE2_SPTR next_end; -PCRE2_SPTR max_end; -PCRE2_UCHAR type; -sljit_sw length = end - begin; -sljit_s32 min, max, i; - -/* Detect fixed iterations first. */ -if (end[-(1 + LINK_SIZE)] != OP_KET || PRIVATE_DATA(begin) != 0) - return FALSE; - -/* /(?:AB){4,6}/ is currently converted to /(?:AB){3}(?AB){1,3}/ - * Skip the check of the second part. */ -if (PRIVATE_DATA(end - LINK_SIZE) != 0) - return TRUE; - -next = end; -min = 1; -while (1) - { - if (*next != *begin) - break; - next_end = bracketend(next); - if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0) - break; - next = next_end; - min++; - } - -if (min == 2) - return FALSE; - -max = 0; -max_end = next; -if (*next == OP_BRAZERO || *next == OP_BRAMINZERO) - { - type = *next; - while (1) - { - if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin) - break; - next_end = bracketend(next + 2 + LINK_SIZE); - if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0) - break; - next = next_end; - max++; - } - - if (next[0] == type && next[1] == *begin && max >= 1) - { - next_end = bracketend(next + 1); - if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0) - { - for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE) - if (*next_end != OP_KET) - break; - - if (i == max) - { - common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end; - common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO; - /* +2 the original and the last. */ - common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2; - if (min == 1) - return TRUE; - min--; - max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE); - } - } - } - } - -if (min >= 3) - { - common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end; - common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT; - common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min; - return TRUE; - } - -return FALSE; -} - -#define CASE_ITERATOR_PRIVATE_DATA_1 \ - case OP_MINSTAR: \ - case OP_MINPLUS: \ - case OP_QUERY: \ - case OP_MINQUERY: \ - case OP_MINSTARI: \ - case OP_MINPLUSI: \ - case OP_QUERYI: \ - case OP_MINQUERYI: \ - case OP_NOTMINSTAR: \ - case OP_NOTMINPLUS: \ - case OP_NOTQUERY: \ - case OP_NOTMINQUERY: \ - case OP_NOTMINSTARI: \ - case OP_NOTMINPLUSI: \ - case OP_NOTQUERYI: \ - case OP_NOTMINQUERYI: - -#define CASE_ITERATOR_PRIVATE_DATA_2A \ - case OP_STAR: \ - case OP_PLUS: \ - case OP_STARI: \ - case OP_PLUSI: \ - case OP_NOTSTAR: \ - case OP_NOTPLUS: \ - case OP_NOTSTARI: \ - case OP_NOTPLUSI: - -#define CASE_ITERATOR_PRIVATE_DATA_2B \ - case OP_UPTO: \ - case OP_MINUPTO: \ - case OP_UPTOI: \ - case OP_MINUPTOI: \ - case OP_NOTUPTO: \ - case OP_NOTMINUPTO: \ - case OP_NOTUPTOI: \ - case OP_NOTMINUPTOI: - -#define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \ - case OP_TYPEMINSTAR: \ - case OP_TYPEMINPLUS: \ - case OP_TYPEQUERY: \ - case OP_TYPEMINQUERY: - -#define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \ - case OP_TYPESTAR: \ - case OP_TYPEPLUS: - -#define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \ - case OP_TYPEUPTO: \ - case OP_TYPEMINUPTO: - -static void set_private_data_ptrs(compiler_common *common, int *private_data_start, PCRE2_SPTR ccend) -{ -PCRE2_SPTR cc = common->start; -PCRE2_SPTR alternative; -PCRE2_SPTR end = NULL; -int private_data_ptr = *private_data_start; -int space, size, bracketlen; -BOOL repeat_check = TRUE; - -while (cc < ccend) - { - space = 0; - size = 0; - bracketlen = 0; - if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE) - break; - - /* When the bracket is prefixed by a zero iteration, skip the repeat check (at this point). */ - if (repeat_check && (*cc == OP_ONCE || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)) - { - if (detect_repeat(common, cc)) - { - /* These brackets are converted to repeats, so no global - based single character repeat is allowed. */ - if (cc >= end) - end = bracketend(cc); - } - } - repeat_check = TRUE; - - switch(*cc) - { - case OP_KET: - if (common->private_data_ptrs[cc + 1 - common->start] != 0) - { - common->private_data_ptrs[cc - common->start] = private_data_ptr; - private_data_ptr += sizeof(sljit_sw); - cc += common->private_data_ptrs[cc + 1 - common->start]; - } - cc += 1 + LINK_SIZE; - break; - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_BRAPOS: - case OP_SBRA: - case OP_SBRAPOS: - case OP_SCOND: - common->private_data_ptrs[cc - common->start] = private_data_ptr; - private_data_ptr += sizeof(sljit_sw); - bracketlen = 1 + LINK_SIZE; - break; - - case OP_ASSERTBACK_NA: - common->private_data_ptrs[cc - common->start] = private_data_ptr; - private_data_ptr += sizeof(sljit_sw); - - if (find_vreverse(cc)) - { - common->private_data_ptrs[cc + 1 - common->start] = 1; - private_data_ptr += sizeof(sljit_sw); - } - - bracketlen = 1 + LINK_SIZE; - break; - - case OP_ASSERT_SCS: - common->private_data_ptrs[cc - common->start] = private_data_ptr; - private_data_ptr += 2 * sizeof(sljit_sw); - bracketlen = 1 + LINK_SIZE; - break; - - case OP_CBRAPOS: - case OP_SCBRAPOS: - common->private_data_ptrs[cc - common->start] = private_data_ptr; - private_data_ptr += sizeof(sljit_sw); - bracketlen = 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_COND: - /* Might be a hidden SCOND. */ - common->private_data_ptrs[cc - common->start] = 0; - alternative = cc + GET(cc, 1); - if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) - { - common->private_data_ptrs[cc - common->start] = private_data_ptr; - private_data_ptr += sizeof(sljit_sw); - } - bracketlen = 1 + LINK_SIZE; - break; - - case OP_BRA: - bracketlen = 1 + LINK_SIZE; - break; - - case OP_CBRA: - case OP_SCBRA: - bracketlen = 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_BRAZERO: - case OP_BRAMINZERO: - case OP_BRAPOSZERO: - size = 1; - repeat_check = FALSE; - break; - - CASE_ITERATOR_PRIVATE_DATA_1 - size = -2; - space = 1; - break; - - CASE_ITERATOR_PRIVATE_DATA_2A - size = -2; - space = 2; - break; - - CASE_ITERATOR_PRIVATE_DATA_2B - size = -(2 + IMM2_SIZE); - space = 2; - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_1 - size = 1; - space = 1; - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_2A - size = 1; - if (cc[1] != OP_EXTUNI) - space = 2; - break; - - case OP_TYPEUPTO: - size = 1 + IMM2_SIZE; - if (cc[1 + IMM2_SIZE] != OP_EXTUNI) - space = 2; - break; - - case OP_TYPEMINUPTO: - size = 1 + IMM2_SIZE; - space = 2; - break; - - case OP_CLASS: - case OP_NCLASS: - size = 1 + 32 / sizeof(PCRE2_UCHAR); - space = get_class_iterator_size(cc + size); - break; - -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 - case OP_XCLASS: - case OP_ECLASS: - size = GET(cc, 1); - space = get_class_iterator_size(cc + size); - break; -#endif - - default: - cc = next_opcode(common, cc); - SLJIT_ASSERT(cc != NULL); - break; - } - - /* Character iterators, which are not inside a repeated bracket, - gets a private slot instead of allocating it on the stack. */ - if (space > 0 && cc >= end) - { - common->private_data_ptrs[cc - common->start] = private_data_ptr; - private_data_ptr += sizeof(sljit_sw) * space; - } - - if (size != 0) - { - if (size < 0) - { - cc += -size; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - } - else - cc += size; - } - - if (bracketlen > 0) - { - if (cc >= end) - { - end = bracketend(cc); - if (end[-1 - LINK_SIZE] == OP_KET) - end = NULL; - } - cc += bracketlen; - } - } -*private_data_start = private_data_ptr; -} - -/* Returns with a frame_types (always < 0) if no need for frame. */ -static int get_framesize(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend, BOOL recursive, BOOL *needs_control_head) -{ -int length = 0; -int possessive = 0; -BOOL stack_restore = FALSE; -BOOL setsom_found = recursive; -BOOL setmark_found = recursive; -/* The last capture is a local variable even for recursions. */ -BOOL capture_last_found = FALSE; - -#if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD -SLJIT_ASSERT(common->control_head_ptr != 0); -*needs_control_head = TRUE; -#else -*needs_control_head = FALSE; -#endif - -if (ccend == NULL) - { - ccend = bracketend(cc) - (1 + LINK_SIZE); - if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS)) - { - possessive = length = (common->capture_last_ptr != 0) ? 5 : 3; - /* This is correct regardless of common->capture_last_ptr. */ - capture_last_found = TRUE; - } - cc = next_opcode(common, cc); - } - -SLJIT_ASSERT(cc != NULL); -while (cc < ccend) - switch(*cc) - { - case OP_SET_SOM: - SLJIT_ASSERT(common->has_set_som); - stack_restore = TRUE; - if (!setsom_found) - { - length += 2; - setsom_found = TRUE; - } - cc += 1; - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_THEN_ARG: - SLJIT_ASSERT(common->mark_ptr != 0); - stack_restore = TRUE; - if (!setmark_found) - { - length += 2; - setmark_found = TRUE; - } - if (common->control_head_ptr != 0) - *needs_control_head = TRUE; - cc += 1 + 2 + cc[1]; - break; - - case OP_RECURSE: - stack_restore = TRUE; - if (common->has_set_som && !setsom_found) - { - length += 2; - setsom_found = TRUE; - } - if (common->mark_ptr != 0 && !setmark_found) - { - length += 2; - setmark_found = TRUE; - } - if (common->capture_last_ptr != 0 && !capture_last_found) - { - length += 2; - capture_last_found = TRUE; - } - cc += 1 + LINK_SIZE; - break; - - case OP_CBRA: - case OP_CBRAPOS: - case OP_SCBRA: - case OP_SCBRAPOS: - stack_restore = TRUE; - if (common->capture_last_ptr != 0 && !capture_last_found) - { - length += 2; - capture_last_found = TRUE; - } - length += 3; - cc += 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_THEN: - stack_restore = TRUE; - if (common->control_head_ptr != 0) - *needs_control_head = TRUE; - cc ++; - break; - - default: - stack_restore = TRUE; - /* Fall through. */ - - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_NOT_DIGIT: - case OP_DIGIT: - case OP_NOT_WHITESPACE: - case OP_WHITESPACE: - case OP_NOT_WORDCHAR: - case OP_WORDCHAR: - case OP_ANY: - case OP_ALLANY: - case OP_ANYBYTE: - case OP_NOTPROP: - case OP_PROP: - case OP_ANYNL: - case OP_NOT_HSPACE: - case OP_HSPACE: - case OP_NOT_VSPACE: - case OP_VSPACE: - case OP_EXTUNI: - case OP_EODN: - case OP_EOD: - case OP_CIRC: - case OP_CIRCM: - case OP_DOLL: - case OP_DOLLM: - case OP_CHAR: - case OP_CHARI: - case OP_NOT: - case OP_NOTI: - - case OP_EXACT: - case OP_POSSTAR: - case OP_POSPLUS: - case OP_POSQUERY: - case OP_POSUPTO: - - case OP_EXACTI: - case OP_POSSTARI: - case OP_POSPLUSI: - case OP_POSQUERYI: - case OP_POSUPTOI: - - case OP_NOTEXACT: - case OP_NOTPOSSTAR: - case OP_NOTPOSPLUS: - case OP_NOTPOSQUERY: - case OP_NOTPOSUPTO: - - case OP_NOTEXACTI: - case OP_NOTPOSSTARI: - case OP_NOTPOSPLUSI: - case OP_NOTPOSQUERYI: - case OP_NOTPOSUPTOI: - - case OP_TYPEEXACT: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - case OP_TYPEPOSUPTO: - - case OP_CLASS: - case OP_NCLASS: - case OP_XCLASS: - case OP_ECLASS: - - case OP_CALLOUT: - case OP_CALLOUT_STR: - - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - - cc = next_opcode(common, cc); - SLJIT_ASSERT(cc != NULL); - break; - } - -/* Possessive quantifiers can use a special case. */ -if (SLJIT_UNLIKELY(possessive == length)) - return stack_restore ? no_frame : no_stack; - -if (length > 0) - return length + 1; -return stack_restore ? no_frame : no_stack; -} - -static void init_frame(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend, int stackpos, int stacktop) -{ -DEFINE_COMPILER; -BOOL setsom_found = FALSE; -BOOL setmark_found = FALSE; -/* The last capture is a local variable even for recursions. */ -BOOL capture_last_found = FALSE; -int offset; - -/* >= 1 + shortest item size (2) */ -SLJIT_UNUSED_ARG(stacktop); -SLJIT_ASSERT(stackpos >= stacktop + 2); - -stackpos = STACK(stackpos); -if (ccend == NULL) - { - ccend = bracketend(cc) - (1 + LINK_SIZE); - if (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS) - cc = next_opcode(common, cc); - } - -/* The data is restored by do_revertframes(). */ -SLJIT_ASSERT(cc != NULL); -while (cc < ccend) - switch(*cc) - { - case OP_SET_SOM: - SLJIT_ASSERT(common->has_set_som); - if (!setsom_found) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0)); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); - stackpos -= SSIZE_OF(sw); - setsom_found = TRUE; - } - cc += 1; - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_THEN_ARG: - SLJIT_ASSERT(common->mark_ptr != 0); - if (!setmark_found) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); - stackpos -= SSIZE_OF(sw); - setmark_found = TRUE; - } - cc += 1 + 2 + cc[1]; - break; - - case OP_RECURSE: - if (common->has_set_som && !setsom_found) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0)); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); - stackpos -= SSIZE_OF(sw); - setsom_found = TRUE; - } - if (common->mark_ptr != 0 && !setmark_found) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); - stackpos -= SSIZE_OF(sw); - setmark_found = TRUE; - } - if (common->capture_last_ptr != 0 && !capture_last_found) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); - stackpos -= SSIZE_OF(sw); - capture_last_found = TRUE; - } - cc += 1 + LINK_SIZE; - break; - - case OP_CBRA: - case OP_CBRAPOS: - case OP_SCBRA: - case OP_SCBRAPOS: - if (common->capture_last_ptr != 0 && !capture_last_found) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); - stackpos -= SSIZE_OF(sw); - capture_last_found = TRUE; - } - offset = (GET2(cc, 1 + LINK_SIZE)) << 1; - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset)); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); - stackpos -= SSIZE_OF(sw); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0); - stackpos -= SSIZE_OF(sw); - - cc += 1 + LINK_SIZE + IMM2_SIZE; - break; - - default: - cc = next_opcode(common, cc); - SLJIT_ASSERT(cc != NULL); - break; - } - -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0); -SLJIT_ASSERT(stackpos == STACK(stacktop)); -} - -#define RECURSE_TMP_REG_COUNT 3 - -typedef struct delayed_mem_copy_status { - struct sljit_compiler *compiler; - int store_bases[RECURSE_TMP_REG_COUNT]; - int store_offsets[RECURSE_TMP_REG_COUNT]; - int tmp_regs[RECURSE_TMP_REG_COUNT]; - int saved_tmp_regs[RECURSE_TMP_REG_COUNT]; - int next_tmp_reg; -} delayed_mem_copy_status; - -static void delayed_mem_copy_init(delayed_mem_copy_status *status, compiler_common *common) -{ -int i; - -for (i = 0; i < RECURSE_TMP_REG_COUNT; i++) - { - SLJIT_ASSERT(status->tmp_regs[i] >= 0); - SLJIT_ASSERT(sljit_get_register_index(SLJIT_GP_REGISTER, status->saved_tmp_regs[i]) < 0 || status->tmp_regs[i] == status->saved_tmp_regs[i]); - - status->store_bases[i] = -1; - } -status->next_tmp_reg = 0; -status->compiler = common->compiler; -} - -static void delayed_mem_copy_move(delayed_mem_copy_status *status, int load_base, sljit_sw load_offset, - int store_base, sljit_sw store_offset) -{ -struct sljit_compiler *compiler = status->compiler; -int next_tmp_reg = status->next_tmp_reg; -int tmp_reg = status->tmp_regs[next_tmp_reg]; - -SLJIT_ASSERT(load_base > 0 && store_base > 0); - -if (status->store_bases[next_tmp_reg] == -1) - { - /* Preserve virtual registers. */ - if (sljit_get_register_index(SLJIT_GP_REGISTER, status->saved_tmp_regs[next_tmp_reg]) < 0) - OP1(SLJIT_MOV, status->saved_tmp_regs[next_tmp_reg], 0, tmp_reg, 0); - } -else - OP1(SLJIT_MOV, SLJIT_MEM1(status->store_bases[next_tmp_reg]), status->store_offsets[next_tmp_reg], tmp_reg, 0); - -OP1(SLJIT_MOV, tmp_reg, 0, SLJIT_MEM1(load_base), load_offset); -status->store_bases[next_tmp_reg] = store_base; -status->store_offsets[next_tmp_reg] = store_offset; - -status->next_tmp_reg = (next_tmp_reg + 1) % RECURSE_TMP_REG_COUNT; -} - -static void delayed_mem_copy_finish(delayed_mem_copy_status *status) -{ -struct sljit_compiler *compiler = status->compiler; -int next_tmp_reg = status->next_tmp_reg; -int tmp_reg, saved_tmp_reg, i; - -for (i = 0; i < RECURSE_TMP_REG_COUNT; i++) - { - if (status->store_bases[next_tmp_reg] != -1) - { - tmp_reg = status->tmp_regs[next_tmp_reg]; - saved_tmp_reg = status->saved_tmp_regs[next_tmp_reg]; - - OP1(SLJIT_MOV, SLJIT_MEM1(status->store_bases[next_tmp_reg]), status->store_offsets[next_tmp_reg], tmp_reg, 0); - - /* Restore virtual registers. */ - if (sljit_get_register_index(SLJIT_GP_REGISTER, saved_tmp_reg) < 0) - OP1(SLJIT_MOV, tmp_reg, 0, saved_tmp_reg, 0); - } - - next_tmp_reg = (next_tmp_reg + 1) % RECURSE_TMP_REG_COUNT; - } -} - -#undef RECURSE_TMP_REG_COUNT - -static BOOL recurse_check_bit(compiler_common *common, sljit_sw bit_index) -{ -uint8_t *byte; -uint8_t mask; - -SLJIT_ASSERT((bit_index & (sizeof(sljit_sw) - 1)) == 0); - -bit_index >>= SLJIT_WORD_SHIFT; - -SLJIT_ASSERT((bit_index >> 3) < common->recurse_bitset_size); - -mask = 1 << (bit_index & 0x7); -byte = common->recurse_bitset + (bit_index >> 3); - -if (*byte & mask) - return FALSE; - -*byte |= mask; -return TRUE; -} - -enum get_recurse_flags { - recurse_flag_quit_found = (1 << 0), - recurse_flag_accept_found = (1 << 1), - recurse_flag_setsom_found = (1 << 2), - recurse_flag_setmark_found = (1 << 3), - recurse_flag_control_head_found = (1 << 4), -}; - -static int get_recurse_data_length(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend, uint32_t *result_flags) -{ -int length = 1; -int size, offset; -PCRE2_SPTR alternative; -uint32_t recurse_flags = 0; - -memset(common->recurse_bitset, 0, common->recurse_bitset_size); - -#if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD -SLJIT_ASSERT(common->control_head_ptr != 0); -recurse_flags |= recurse_flag_control_head_found; -#endif - -/* Calculate the sum of the private machine words. */ -while (cc < ccend) - { - size = 0; - switch(*cc) - { - case OP_SET_SOM: - SLJIT_ASSERT(common->has_set_som); - recurse_flags |= recurse_flag_setsom_found; - cc += 1; - break; - - case OP_RECURSE: - if (common->has_set_som) - recurse_flags |= recurse_flag_setsom_found; - if (common->mark_ptr != 0) - recurse_flags |= recurse_flag_setmark_found; - if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) - length++; - cc += 1 + LINK_SIZE; - break; - - case OP_KET: - offset = PRIVATE_DATA(cc); - if (offset != 0) - { - if (recurse_check_bit(common, offset)) - length++; - SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0); - cc += PRIVATE_DATA(cc + 1); - } - cc += 1 + LINK_SIZE; - break; - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_BRAPOS: - case OP_SBRA: - case OP_SBRAPOS: - case OP_SCOND: - SLJIT_ASSERT(PRIVATE_DATA(cc) != 0); - if (recurse_check_bit(common, PRIVATE_DATA(cc))) - length++; - cc += 1 + LINK_SIZE; - break; - - case OP_ASSERT_SCS: - SLJIT_ASSERT(PRIVATE_DATA(cc) != 0); - if (recurse_check_bit(common, PRIVATE_DATA(cc))) - length += 2; - cc += 1 + LINK_SIZE; - break; - - case OP_CBRA: - case OP_SCBRA: - offset = GET2(cc, 1 + LINK_SIZE); - if (recurse_check_bit(common, OVECTOR(offset << 1))) - { - SLJIT_ASSERT(recurse_check_bit(common, OVECTOR((offset << 1) + 1))); - length += 2; - } - if (common->optimized_cbracket[offset] == 0 && recurse_check_bit(common, OVECTOR_PRIV(offset))) - length++; - if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) - length++; - cc += 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_CBRAPOS: - case OP_SCBRAPOS: - offset = GET2(cc, 1 + LINK_SIZE); - if (recurse_check_bit(common, OVECTOR(offset << 1))) - { - SLJIT_ASSERT(recurse_check_bit(common, OVECTOR((offset << 1) + 1))); - length += 2; - } - if (recurse_check_bit(common, OVECTOR_PRIV(offset))) - length++; - if (recurse_check_bit(common, PRIVATE_DATA(cc))) - length++; - if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) - length++; - cc += 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_COND: - /* Might be a hidden SCOND. */ - alternative = cc + GET(cc, 1); - if ((*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) && recurse_check_bit(common, PRIVATE_DATA(cc))) - length++; - cc += 1 + LINK_SIZE; - break; - - CASE_ITERATOR_PRIVATE_DATA_1 - offset = PRIVATE_DATA(cc); - if (offset != 0 && recurse_check_bit(common, offset)) - length++; - cc += 2; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - CASE_ITERATOR_PRIVATE_DATA_2A - offset = PRIVATE_DATA(cc); - if (offset != 0 && recurse_check_bit(common, offset)) - { - SLJIT_ASSERT(recurse_check_bit(common, offset + sizeof(sljit_sw))); - length += 2; - } - cc += 2; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - CASE_ITERATOR_PRIVATE_DATA_2B - offset = PRIVATE_DATA(cc); - if (offset != 0 && recurse_check_bit(common, offset)) - { - SLJIT_ASSERT(recurse_check_bit(common, offset + sizeof(sljit_sw))); - length += 2; - } - cc += 2 + IMM2_SIZE; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_1 - offset = PRIVATE_DATA(cc); - if (offset != 0 && recurse_check_bit(common, offset)) - length++; - cc += 1; - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_2A - offset = PRIVATE_DATA(cc); - if (offset != 0 && recurse_check_bit(common, offset)) - { - SLJIT_ASSERT(recurse_check_bit(common, offset + sizeof(sljit_sw))); - length += 2; - } - cc += 1; - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_2B - offset = PRIVATE_DATA(cc); - if (offset != 0 && recurse_check_bit(common, offset)) - { - SLJIT_ASSERT(recurse_check_bit(common, offset + sizeof(sljit_sw))); - length += 2; - } - cc += 1 + IMM2_SIZE; - break; - - case OP_CLASS: - case OP_NCLASS: -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 - case OP_XCLASS: - case OP_ECLASS: - size = (*cc >= OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(PCRE2_UCHAR); -#else - size = 1 + 32 / (int)sizeof(PCRE2_UCHAR); -#endif - - offset = PRIVATE_DATA(cc); - if (offset != 0 && recurse_check_bit(common, offset)) - length += get_class_iterator_size(cc + size); - cc += size; - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_THEN_ARG: - SLJIT_ASSERT(common->mark_ptr != 0); - recurse_flags |= recurse_flag_setmark_found; - if (common->control_head_ptr != 0) - recurse_flags |= recurse_flag_control_head_found; - if (*cc != OP_MARK) - recurse_flags |= recurse_flag_quit_found; - - cc += 1 + 2 + cc[1]; - break; - - case OP_PRUNE: - case OP_SKIP: - case OP_COMMIT: - recurse_flags |= recurse_flag_quit_found; - cc++; - break; - - case OP_SKIP_ARG: - recurse_flags |= recurse_flag_quit_found; - cc += 1 + 2 + cc[1]; - break; - - case OP_THEN: - SLJIT_ASSERT(common->control_head_ptr != 0); - recurse_flags |= recurse_flag_quit_found | recurse_flag_control_head_found; - cc++; - break; - - case OP_ACCEPT: - case OP_ASSERT_ACCEPT: - recurse_flags |= recurse_flag_accept_found; - cc++; - break; - - default: - cc = next_opcode(common, cc); - SLJIT_ASSERT(cc != NULL); - break; - } - } -SLJIT_ASSERT(cc == ccend); - -if (recurse_flags & recurse_flag_control_head_found) - length++; -if (recurse_flags & recurse_flag_quit_found) - { - if (recurse_flags & recurse_flag_setsom_found) - length++; - if (recurse_flags & recurse_flag_setmark_found) - length++; - } - -*result_flags = recurse_flags; -return length; -} - -enum copy_recurse_data_types { - recurse_copy_from_global, - recurse_copy_private_to_global, - recurse_copy_shared_to_global, - recurse_copy_kept_shared_to_global, - recurse_swap_global -}; - -static void copy_recurse_data(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend, - int type, int stackptr, int stacktop, uint32_t recurse_flags) -{ -delayed_mem_copy_status status; -PCRE2_SPTR alternative; -sljit_sw private_srcw[2]; -sljit_sw shared_srcw[3]; -sljit_sw kept_shared_srcw[2]; -int private_count, shared_count, kept_shared_count; -int from_sp, base_reg, offset, i; - -memset(common->recurse_bitset, 0, common->recurse_bitset_size); - -#if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD -SLJIT_ASSERT(common->control_head_ptr != 0); -recurse_check_bit(common, common->control_head_ptr); -#endif - -switch (type) - { - case recurse_copy_from_global: - from_sp = TRUE; - base_reg = STACK_TOP; - break; - - case recurse_copy_private_to_global: - case recurse_copy_shared_to_global: - case recurse_copy_kept_shared_to_global: - from_sp = FALSE; - base_reg = STACK_TOP; - break; - - default: - SLJIT_ASSERT(type == recurse_swap_global); - from_sp = FALSE; - base_reg = TMP2; - break; - } - -stackptr = STACK(stackptr); -stacktop = STACK(stacktop); - -status.tmp_regs[0] = TMP1; -status.saved_tmp_regs[0] = TMP1; - -if (base_reg != TMP2) - { - status.tmp_regs[1] = TMP2; - status.saved_tmp_regs[1] = TMP2; - } -else - { - status.saved_tmp_regs[1] = RETURN_ADDR; - if (HAS_VIRTUAL_REGISTERS) - status.tmp_regs[1] = STR_PTR; - else - status.tmp_regs[1] = RETURN_ADDR; - } - -status.saved_tmp_regs[2] = TMP3; -if (HAS_VIRTUAL_REGISTERS) - status.tmp_regs[2] = STR_END; -else - status.tmp_regs[2] = TMP3; - -delayed_mem_copy_init(&status, common); - -if (type != recurse_copy_shared_to_global && type != recurse_copy_kept_shared_to_global) - { - SLJIT_ASSERT(type == recurse_copy_from_global || type == recurse_copy_private_to_global || type == recurse_swap_global); - - if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, common->recursive_head_ptr); - - if (from_sp || type == recurse_swap_global) - delayed_mem_copy_move(&status, SLJIT_SP, common->recursive_head_ptr, base_reg, stackptr); - } - -stackptr += sizeof(sljit_sw); - -#if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD -if (type != recurse_copy_shared_to_global) - { - if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, common->control_head_ptr); - - if (from_sp || type == recurse_swap_global) - delayed_mem_copy_move(&status, SLJIT_SP, common->control_head_ptr, base_reg, stackptr); - } - -stackptr += sizeof(sljit_sw); -#endif - -while (cc < ccend) - { - private_count = 0; - shared_count = 0; - kept_shared_count = 0; - - switch(*cc) - { - case OP_SET_SOM: - SLJIT_ASSERT(common->has_set_som); - if ((recurse_flags & recurse_flag_quit_found) && recurse_check_bit(common, OVECTOR(0))) - { - kept_shared_srcw[0] = OVECTOR(0); - kept_shared_count = 1; - } - cc += 1; - break; - - case OP_RECURSE: - if (recurse_flags & recurse_flag_quit_found) - { - if (common->has_set_som && recurse_check_bit(common, OVECTOR(0))) - { - kept_shared_srcw[0] = OVECTOR(0); - kept_shared_count = 1; - } - if (common->mark_ptr != 0 && recurse_check_bit(common, common->mark_ptr)) - { - kept_shared_srcw[kept_shared_count] = common->mark_ptr; - kept_shared_count++; - } - } - if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) - { - shared_srcw[0] = common->capture_last_ptr; - shared_count = 1; - } - cc += 1 + LINK_SIZE; - break; - - case OP_KET: - private_srcw[0] = PRIVATE_DATA(cc); - if (private_srcw[0] != 0) - { - if (recurse_check_bit(common, private_srcw[0])) - private_count = 1; - SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0); - cc += PRIVATE_DATA(cc + 1); - } - cc += 1 + LINK_SIZE; - break; - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_BRAPOS: - case OP_SBRA: - case OP_SBRAPOS: - case OP_SCOND: - private_srcw[0] = PRIVATE_DATA(cc); - if (recurse_check_bit(common, private_srcw[0])) - private_count = 1; - cc += 1 + LINK_SIZE; - break; - - case OP_ASSERT_SCS: - private_srcw[0] = PRIVATE_DATA(cc); - private_srcw[1] = private_srcw[0] + sizeof(sljit_sw); - if (recurse_check_bit(common, private_srcw[0])) - private_count = 2; - cc += 1 + LINK_SIZE; - break; - - case OP_CBRA: - case OP_SCBRA: - offset = GET2(cc, 1 + LINK_SIZE); - shared_srcw[0] = OVECTOR(offset << 1); - if (recurse_check_bit(common, shared_srcw[0])) - { - shared_srcw[1] = shared_srcw[0] + sizeof(sljit_sw); - SLJIT_ASSERT(recurse_check_bit(common, shared_srcw[1])); - shared_count = 2; - } - - if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) - { - shared_srcw[shared_count] = common->capture_last_ptr; - shared_count++; - } - - if (common->optimized_cbracket[offset] == 0) - { - private_srcw[0] = OVECTOR_PRIV(offset); - if (recurse_check_bit(common, private_srcw[0])) - private_count = 1; - } - - cc += 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_CBRAPOS: - case OP_SCBRAPOS: - offset = GET2(cc, 1 + LINK_SIZE); - shared_srcw[0] = OVECTOR(offset << 1); - if (recurse_check_bit(common, shared_srcw[0])) - { - shared_srcw[1] = shared_srcw[0] + sizeof(sljit_sw); - SLJIT_ASSERT(recurse_check_bit(common, shared_srcw[1])); - shared_count = 2; - } - - if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) - { - shared_srcw[shared_count] = common->capture_last_ptr; - shared_count++; - } - - private_srcw[0] = PRIVATE_DATA(cc); - if (recurse_check_bit(common, private_srcw[0])) - private_count = 1; - - offset = OVECTOR_PRIV(offset); - if (recurse_check_bit(common, offset)) - { - private_srcw[private_count] = offset; - private_count++; - } - cc += 1 + LINK_SIZE + IMM2_SIZE; - break; - - case OP_COND: - /* Might be a hidden SCOND. */ - alternative = cc + GET(cc, 1); - if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) - { - private_srcw[0] = PRIVATE_DATA(cc); - if (recurse_check_bit(common, private_srcw[0])) - private_count = 1; - } - cc += 1 + LINK_SIZE; - break; - - CASE_ITERATOR_PRIVATE_DATA_1 - private_srcw[0] = PRIVATE_DATA(cc); - if (private_srcw[0] != 0 && recurse_check_bit(common, private_srcw[0])) - private_count = 1; - cc += 2; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - CASE_ITERATOR_PRIVATE_DATA_2A - private_srcw[0] = PRIVATE_DATA(cc); - if (private_srcw[0] != 0 && recurse_check_bit(common, private_srcw[0])) - { - private_count = 2; - private_srcw[1] = private_srcw[0] + sizeof(sljit_sw); - SLJIT_ASSERT(recurse_check_bit(common, private_srcw[1])); - } - cc += 2; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - CASE_ITERATOR_PRIVATE_DATA_2B - private_srcw[0] = PRIVATE_DATA(cc); - if (private_srcw[0] != 0 && recurse_check_bit(common, private_srcw[0])) - { - private_count = 2; - private_srcw[1] = private_srcw[0] + sizeof(sljit_sw); - SLJIT_ASSERT(recurse_check_bit(common, private_srcw[1])); - } - cc += 2 + IMM2_SIZE; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); -#endif - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_1 - private_srcw[0] = PRIVATE_DATA(cc); - if (private_srcw[0] != 0 && recurse_check_bit(common, private_srcw[0])) - private_count = 1; - cc += 1; - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_2A - private_srcw[0] = PRIVATE_DATA(cc); - if (private_srcw[0] != 0 && recurse_check_bit(common, private_srcw[0])) - { - private_count = 2; - private_srcw[1] = private_srcw[0] + sizeof(sljit_sw); - SLJIT_ASSERT(recurse_check_bit(common, private_srcw[1])); - } - cc += 1; - break; - - CASE_ITERATOR_TYPE_PRIVATE_DATA_2B - private_srcw[0] = PRIVATE_DATA(cc); - if (private_srcw[0] != 0 && recurse_check_bit(common, private_srcw[0])) - { - private_count = 2; - private_srcw[1] = private_srcw[0] + sizeof(sljit_sw); - SLJIT_ASSERT(recurse_check_bit(common, private_srcw[1])); - } - cc += 1 + IMM2_SIZE; - break; - - case OP_CLASS: - case OP_NCLASS: -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 - case OP_XCLASS: - case OP_ECLASS: - i = (*cc >= OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(PCRE2_UCHAR); -#else - i = 1 + 32 / (int)sizeof(PCRE2_UCHAR); -#endif - if (PRIVATE_DATA(cc) != 0) - { - private_count = 1; - private_srcw[0] = PRIVATE_DATA(cc); - switch(get_class_iterator_size(cc + i)) - { - case 1: - break; - - case 2: - if (recurse_check_bit(common, private_srcw[0])) - { - private_count = 2; - private_srcw[1] = private_srcw[0] + sizeof(sljit_sw); - SLJIT_ASSERT(recurse_check_bit(common, private_srcw[1])); - } - break; - - default: - SLJIT_UNREACHABLE(); - break; - } - } - cc += i; - break; - - case OP_MARK: - case OP_COMMIT_ARG: - case OP_PRUNE_ARG: - case OP_THEN_ARG: - SLJIT_ASSERT(common->mark_ptr != 0); - if ((recurse_flags & recurse_flag_quit_found) && recurse_check_bit(common, common->mark_ptr)) - { - kept_shared_srcw[0] = common->mark_ptr; - kept_shared_count = 1; - } - if (common->control_head_ptr != 0 && recurse_check_bit(common, common->control_head_ptr)) - { - private_srcw[0] = common->control_head_ptr; - private_count = 1; - } - cc += 1 + 2 + cc[1]; - break; - - case OP_THEN: - SLJIT_ASSERT(common->control_head_ptr != 0); - if (recurse_check_bit(common, common->control_head_ptr)) - { - private_srcw[0] = common->control_head_ptr; - private_count = 1; - } - cc++; - break; - - default: - cc = next_opcode(common, cc); - SLJIT_ASSERT(cc != NULL); - continue; - } - - if (type != recurse_copy_shared_to_global && type != recurse_copy_kept_shared_to_global) - { - SLJIT_ASSERT(type == recurse_copy_from_global || type == recurse_copy_private_to_global || type == recurse_swap_global); - - for (i = 0; i < private_count; i++) - { - SLJIT_ASSERT(private_srcw[i] != 0); - - if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, private_srcw[i]); - - if (from_sp || type == recurse_swap_global) - delayed_mem_copy_move(&status, SLJIT_SP, private_srcw[i], base_reg, stackptr); - - stackptr += sizeof(sljit_sw); - } - } - else - stackptr += sizeof(sljit_sw) * private_count; - - if (type != recurse_copy_private_to_global && type != recurse_copy_kept_shared_to_global) - { - SLJIT_ASSERT(type == recurse_copy_from_global || type == recurse_copy_shared_to_global || type == recurse_swap_global); - - for (i = 0; i < shared_count; i++) - { - SLJIT_ASSERT(shared_srcw[i] != 0); - - if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, shared_srcw[i]); - - if (from_sp || type == recurse_swap_global) - delayed_mem_copy_move(&status, SLJIT_SP, shared_srcw[i], base_reg, stackptr); - - stackptr += sizeof(sljit_sw); - } - } - else - stackptr += sizeof(sljit_sw) * shared_count; - - if (type != recurse_copy_private_to_global && type != recurse_swap_global) - { - SLJIT_ASSERT(type == recurse_copy_from_global || type == recurse_copy_shared_to_global || type == recurse_copy_kept_shared_to_global); - - for (i = 0; i < kept_shared_count; i++) - { - SLJIT_ASSERT(kept_shared_srcw[i] != 0); - - if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, kept_shared_srcw[i]); - - if (from_sp || type == recurse_swap_global) - delayed_mem_copy_move(&status, SLJIT_SP, kept_shared_srcw[i], base_reg, stackptr); - - stackptr += sizeof(sljit_sw); - } - } - else - stackptr += sizeof(sljit_sw) * kept_shared_count; - } - -SLJIT_ASSERT(cc == ccend && stackptr == stacktop); - -delayed_mem_copy_finish(&status); -} - -static SLJIT_INLINE PCRE2_SPTR set_then_offsets(compiler_common *common, PCRE2_SPTR cc, sljit_u8 *current_offset) -{ -PCRE2_SPTR end = bracketend(cc); -BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT; - -/* Assert captures *THEN verb even if it has no alternatives. */ -if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) - current_offset = NULL; -else if (*cc >= OP_ASSERT_NA && *cc <= OP_ASSERT_SCS) - has_alternatives = TRUE; -/* Conditional block does never capture. */ -else if (*cc == OP_COND || *cc == OP_SCOND) - has_alternatives = FALSE; - -cc = next_opcode(common, cc); - -if (has_alternatives) - { - switch (*cc) - { - case OP_REVERSE: - case OP_CREF: - cc += 1 + IMM2_SIZE; - break; - case OP_VREVERSE: - case OP_DNCREF: - cc += 1 + 2 * IMM2_SIZE; - break; - } - - current_offset = common->then_offsets + (cc - common->start); - } - -while (cc < end) - { - if (*cc >= OP_ASSERT && *cc <= OP_SCOND) - { - cc = set_then_offsets(common, cc, current_offset); - continue; - } - - if (*cc == OP_ALT && has_alternatives) - { - cc += 1 + LINK_SIZE; - - if (*cc == OP_REVERSE) - cc += 1 + IMM2_SIZE; - else if (*cc == OP_VREVERSE) - cc += 1 + 2 * IMM2_SIZE; - - current_offset = common->then_offsets + (cc - common->start); - continue; - } - - if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL) - *current_offset = 1; - cc = next_opcode(common, cc); - } - -cc = end - 1 - LINK_SIZE; - -/* Ignore repeats. */ -if (*cc == OP_KET && PRIVATE_DATA(cc) != 0) - end += PRIVATE_DATA(cc + 1); - -return end; -} - -#undef CASE_ITERATOR_PRIVATE_DATA_1 -#undef CASE_ITERATOR_PRIVATE_DATA_2A -#undef CASE_ITERATOR_PRIVATE_DATA_2B -#undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1 -#undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A -#undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B - -static SLJIT_INLINE BOOL is_powerof2(unsigned int value) -{ -return (value & (value - 1)) == 0; -} - -static SLJIT_INLINE void set_jumps(jump_list *list, struct sljit_label *label) -{ -while (list != NULL) - { - /* sljit_set_label is clever enough to do nothing - if either the jump or the label is NULL. */ - SET_LABEL(list->jump, label); - list = list->next; - } -} - -static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump *jump) -{ -jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list)); -if (list_item) - { - list_item->next = *list; - list_item->jump = jump; - *list = list_item; - } -} - -static void add_stub(compiler_common *common, struct sljit_jump *start) -{ -DEFINE_COMPILER; -stub_list *list_item = sljit_alloc_memory(compiler, sizeof(stub_list)); - -if (list_item) - { - list_item->start = start; - list_item->quit = LABEL(); - list_item->next = common->stubs; - common->stubs = list_item; - } -} - -static void flush_stubs(compiler_common *common) -{ -DEFINE_COMPILER; -stub_list *list_item = common->stubs; - -while (list_item) - { - JUMPHERE(list_item->start); - add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL)); - JUMPTO(SLJIT_JUMP, list_item->quit); - list_item = list_item->next; - } -common->stubs = NULL; -} - -static SLJIT_INLINE void count_match(compiler_common *common) -{ -DEFINE_COMPILER; - -OP2(SLJIT_SUB | SLJIT_SET_Z, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1); -add_jump(compiler, &common->calllimit, JUMP(SLJIT_ZERO)); -} - -static SLJIT_INLINE void allocate_stack(compiler_common *common, int size) -{ -/* May destroy all locals and registers except TMP2. */ -DEFINE_COMPILER; - -SLJIT_ASSERT(size > 0); -OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * SSIZE_OF(sw)); -#ifdef DESTROY_REGISTERS -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345); -OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); -OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); -#if defined SLJIT_DEBUG && SLJIT_DEBUG -SLJIT_ASSERT(common->locals_size >= 2 * SSIZE_OF(sw)); -/* These two are also used by the stackalloc calls. */ -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL0, TMP1, 0); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL1, TMP1, 0); -#endif -#endif -add_stub(common, CMP(SLJIT_LESS, STACK_TOP, 0, STACK_LIMIT, 0)); -} - -static SLJIT_INLINE void free_stack(compiler_common *common, int size) -{ -DEFINE_COMPILER; - -SLJIT_ASSERT(size > 0); -OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * SSIZE_OF(sw)); -} - -static sljit_uw * allocate_read_only_data(compiler_common *common, sljit_uw size) -{ -DEFINE_COMPILER; -sljit_uw *result; - -if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return NULL; - -result = (sljit_uw *)SLJIT_MALLOC(size + sizeof(sljit_uw), compiler->allocator_data); -if (SLJIT_UNLIKELY(result == NULL)) - { - sljit_set_compiler_memory_error(compiler); - return NULL; - } - -*(void**)result = common->read_only_data_head; -common->read_only_data_head = (void *)result; -return result + 1; -} - -static SLJIT_INLINE void reset_ovector(compiler_common *common, int length) -{ -DEFINE_COMPILER; -struct sljit_label *loop; -sljit_s32 i; - -/* At this point we can freely use all temporary registers. */ -SLJIT_ASSERT(length > 1); -/* TMP1 returns with begin - 1. */ -OP2(SLJIT_SUB, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1)); -if (length < 8) - { - for (i = 1; i < length; i++) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), SLJIT_R0, 0); - } -else - { - if (sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw)) == SLJIT_SUCCESS) - { - GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START); - OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1); - loop = LABEL(); - sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw)); - OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, loop); - } - else - { - GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1); - loop = LABEL(); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R0, 0); - OP2(SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw)); - OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, loop); - } - } -} - -static SLJIT_INLINE void reset_early_fail(compiler_common *common) -{ -DEFINE_COMPILER; -sljit_u32 size = (sljit_u32)(common->early_fail_end_ptr - common->early_fail_start_ptr); -sljit_u32 uncleared_size; -sljit_s32 src = SLJIT_IMM; -sljit_s32 i; -struct sljit_label *loop; - -SLJIT_ASSERT(common->early_fail_start_ptr < common->early_fail_end_ptr); - -if (size == sizeof(sljit_sw)) - { - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->early_fail_start_ptr, SLJIT_IMM, 0); - return; - } - -if (sljit_get_register_index(SLJIT_GP_REGISTER, TMP3) >= 0 && !sljit_has_cpu_feature(SLJIT_HAS_ZERO_REGISTER)) - { - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0); - src = TMP3; - } - -if (size <= 6 * sizeof(sljit_sw)) - { - for (i = common->early_fail_start_ptr; i < common->early_fail_end_ptr; i += sizeof(sljit_sw)) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), i, src, 0); - return; - } - -GET_LOCAL_BASE(TMP1, 0, common->early_fail_start_ptr); - -uncleared_size = ((size / sizeof(sljit_sw)) % 3) * sizeof(sljit_sw); - -OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, size - uncleared_size); - -loop = LABEL(); -OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), 0, src, 0); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw)); -OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), -2 * SSIZE_OF(sw), src, 0); -OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), -1 * SSIZE_OF(sw), src, 0); -CMPTO(SLJIT_LESS, TMP1, 0, TMP2, 0, loop); - -if (uncleared_size >= sizeof(sljit_sw)) - OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), 0, src, 0); - -if (uncleared_size >= 2 * sizeof(sljit_sw)) - OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), sizeof(sljit_sw), src, 0); -} - -static SLJIT_INLINE void do_reset_match(compiler_common *common, int length) -{ -DEFINE_COMPILER; -struct sljit_label *loop; -int i; - -SLJIT_ASSERT(length > 1); -/* OVECTOR(1) contains the "string begin - 1" constant. */ -if (length > 2) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); -if (length < 8) - { - for (i = 2; i < length; i++) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), TMP1, 0); - } -else - { - if (sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, TMP1, SLJIT_MEM1(TMP2), sizeof(sljit_sw)) == SLJIT_SUCCESS) - { - GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw)); - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2); - loop = LABEL(); - sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, TMP1, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); - OP2(SLJIT_SUB | SLJIT_SET_Z, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, loop); - } - else - { - GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + 2 * sizeof(sljit_sw)); - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2); - loop = LABEL(); - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, TMP1, 0); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, sizeof(sljit_sw)); - OP2(SLJIT_SUB | SLJIT_SET_Z, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, loop); - } - } - -if (!HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, stack)); -else - OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0); - -if (common->mark_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, SLJIT_IMM, 0); -if (common->control_head_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0); -if (HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack)); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr); -OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, end)); -} - -static sljit_sw SLJIT_FUNC do_search_mark(sljit_sw *current, PCRE2_SPTR skip_arg) -{ -while (current != NULL) - { - switch (current[1]) - { - case type_then_trap: - break; - - case type_mark: - if (PRIV(strcmp)(skip_arg, (PCRE2_SPTR)current[2]) == 0) - return current[3]; - break; - - default: - SLJIT_UNREACHABLE(); - break; - } - SLJIT_ASSERT(current[0] == 0 || current < (sljit_sw*)current[0]); - current = (sljit_sw*)current[0]; - } -return 0; -} - -static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket) -{ -DEFINE_COMPILER; -struct sljit_label *loop; -BOOL has_pre; - -/* At this point we can freely use all registers. */ -OP1(SLJIT_MOV, SLJIT_S2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(1), STR_PTR, 0); - -if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, SLJIT_R0, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr); - if (common->mark_ptr != 0) - OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); - OP1(SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, oveccount)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, startchar_ptr), SLJIT_S0, 0); - if (common->mark_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_R2, 0); - OP2(SLJIT_ADD, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, match_data), - SLJIT_IMM, SLJIT_OFFSETOF(pcre2_match_data, ovector) - sizeof(PCRE2_SIZE)); - } -else - { - OP1(SLJIT_MOV, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr); - OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, match_data)); - if (common->mark_ptr != 0) - OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); - OP1(SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, oveccount)); - OP1(SLJIT_MOV, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, startchar_ptr), SLJIT_S0, 0); - if (common->mark_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_R0, 0); - OP2(SLJIT_ADD, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, SLJIT_OFFSETOF(pcre2_match_data, ovector) - sizeof(PCRE2_SIZE)); - } - -has_pre = sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_S1, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw)) == SLJIT_SUCCESS; - -GET_LOCAL_BASE(SLJIT_S0, 0, OVECTOR_START - (has_pre ? sizeof(sljit_sw) : 0)); -OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(HAS_VIRTUAL_REGISTERS ? SLJIT_R0 : ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - -loop = LABEL(); - -if (has_pre) - sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_S1, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw)); -else - { - OP1(SLJIT_MOV, SLJIT_S1, 0, SLJIT_MEM1(SLJIT_S0), 0); - OP2(SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw)); - } - -OP2(SLJIT_ADD, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, sizeof(PCRE2_SIZE)); -OP2(SLJIT_SUB, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_R0, 0); -/* Copy the integer value to the output buffer */ -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif - -SLJIT_ASSERT(sizeof(PCRE2_SIZE) == 4 || sizeof(PCRE2_SIZE) == 8); -OP1(((sizeof(PCRE2_SIZE) == 4) ? SLJIT_MOV_U32 : SLJIT_MOV), SLJIT_MEM1(SLJIT_R2), 0, SLJIT_S1, 0); - -OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); -JUMPTO(SLJIT_NOT_ZERO, loop); - -/* Calculate the return value, which is the maximum ovector value. */ -if (topbracket > 1) - { - if (sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R0), -(2 * SSIZE_OF(sw))) == SLJIT_SUCCESS) - { - GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1); - - /* OVECTOR(0) is never equal to SLJIT_S2. */ - loop = LABEL(); - sljit_emit_mem_update(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R0), -(2 * SSIZE_OF(sw))); - OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); - CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop); - OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_R1, 0); - } - else - { - GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + (topbracket - 1) * 2 * sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1); - - /* OVECTOR(0) is never equal to SLJIT_S2. */ - loop = LABEL(); - OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), 0); - OP2(SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2 * SSIZE_OF(sw)); - OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); - CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop); - OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_R1, 0); - } - } -else - OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1); -} - -static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit) -{ -DEFINE_COMPILER; -sljit_s32 mov_opcode; -sljit_s32 arguments_reg = !HAS_VIRTUAL_REGISTERS ? ARGUMENTS : SLJIT_R1; - -SLJIT_COMPILE_ASSERT(STR_END == SLJIT_S0, str_end_must_be_saved_reg0); -SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0 - && (common->mode == PCRE2_JIT_PARTIAL_SOFT ? common->hit_start != 0 : common->hit_start == 0)); - -if (arguments_reg != ARGUMENTS) - OP1(SLJIT_MOV, arguments_reg, 0, ARGUMENTS, 0); -OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), - common->mode == PCRE2_JIT_PARTIAL_SOFT ? common->hit_start : common->start_ptr); -OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_PARTIAL); - -/* Store match begin and end. */ -OP1(SLJIT_MOV, SLJIT_S1, 0, SLJIT_MEM1(arguments_reg), SLJIT_OFFSETOF(jit_arguments, begin)); -OP1(SLJIT_MOV, SLJIT_MEM1(arguments_reg), SLJIT_OFFSETOF(jit_arguments, startchar_ptr), SLJIT_R2, 0); -OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(arguments_reg), SLJIT_OFFSETOF(jit_arguments, match_data)); - -mov_opcode = (sizeof(PCRE2_SIZE) == 4) ? SLJIT_MOV_U32 : SLJIT_MOV; - -OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_S1, 0); -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif -OP1(mov_opcode, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(pcre2_match_data, ovector), SLJIT_R2, 0); - -OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_S1, 0); -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -OP2(SLJIT_ASHR, STR_END, 0, STR_END, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif -OP1(mov_opcode, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(pcre2_match_data, ovector) + sizeof(PCRE2_SIZE), STR_END, 0); - -JUMPTO(SLJIT_JUMP, quit); -} - -static SLJIT_INLINE void check_start_used_ptr(compiler_common *common) -{ -/* May destroy TMP1. */ -DEFINE_COMPILER; -struct sljit_jump *jump; - -if (common->mode == PCRE2_JIT_PARTIAL_SOFT) - { - /* The value of -1 must be kept for start_used_ptr! */ - OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, 1); - /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting - is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */ - jump = CMP(SLJIT_LESS_EQUAL, TMP1, 0, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); - JUMPHERE(jump); - } -else if (common->mode == PCRE2_JIT_PARTIAL_HARD) - { - jump = CMP(SLJIT_LESS_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); - JUMPHERE(jump); - } -} - -static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, PCRE2_SPTR cc) -{ -/* Detects if the character has an othercase. */ -unsigned int c; - -#ifdef SUPPORT_UNICODE -if (common->utf || common->ucp) - { - if (common->utf) - { - GETCHAR(c, cc); - } - else - c = *cc; - - if (c > 127) - return c != UCD_OTHERCASE(c); - - return common->fcc[c] != c; - } -else -#endif - c = *cc; -return MAX_255(c) ? common->fcc[c] != c : FALSE; -} - -static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c) -{ -/* Returns with the othercase. */ -#ifdef SUPPORT_UNICODE -if ((common->utf || common->ucp) && c > 127) - return UCD_OTHERCASE(c); -#endif -return TABLE_GET(c, common->fcc, c); -} - -static unsigned int char_get_othercase_bit(compiler_common *common, PCRE2_SPTR cc) -{ -/* Detects if the character and its othercase has only 1 bit difference. */ -unsigned int c, oc, bit; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -int n; -#endif - -#ifdef SUPPORT_UNICODE -if (common->utf || common->ucp) - { - if (common->utf) - { - GETCHAR(c, cc); - } - else - c = *cc; - - if (c <= 127) - oc = common->fcc[c]; - else - oc = UCD_OTHERCASE(c); - } -else - { - c = *cc; - oc = TABLE_GET(c, common->fcc, c); - } -#else -c = *cc; -oc = TABLE_GET(c, common->fcc, c); -#endif - -SLJIT_ASSERT(c != oc); - -bit = c ^ oc; -/* Optimized for English alphabet. */ -if (c <= 127 && bit == 0x20) - return (0 << 8) | 0x20; - -/* Since c != oc, they must have at least 1 bit difference. */ -if (!is_powerof2(bit)) - return 0; - -#if PCRE2_CODE_UNIT_WIDTH == 8 - -#ifdef SUPPORT_UNICODE -if (common->utf && c > 127) - { - n = GET_EXTRALEN(*cc); - while ((bit & 0x3f) == 0) - { - n--; - bit >>= 6; - } - return (n << 8) | bit; - } -#endif /* SUPPORT_UNICODE */ -return (0 << 8) | bit; - -#elif PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - -#ifdef SUPPORT_UNICODE -if (common->utf && c > 65535) - { - if (bit >= (1u << 10)) - bit >>= 10; - else - return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8)); - } -#endif /* SUPPORT_UNICODE */ -return (bit < 256) ? ((0u << 8) | bit) : ((1u << 8) | (bit >> 8)); - -#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */ -} - -static void check_partial(compiler_common *common, BOOL force) -{ -/* Checks whether a partial matching is occurred. Does not modify registers. */ -DEFINE_COMPILER; -struct sljit_jump *jump = NULL; - -SLJIT_ASSERT(!force || common->mode != PCRE2_JIT_COMPLETE); - -if (common->mode == PCRE2_JIT_COMPLETE) - return; - -if (!force && !common->allow_empty_partial) - jump = CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); -else if (common->mode == PCRE2_JIT_PARTIAL_SOFT) - jump = CMP(SLJIT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1); - -if (common->mode == PCRE2_JIT_PARTIAL_SOFT) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); -else - { - if (common->partialmatchlabel != NULL) - JUMPTO(SLJIT_JUMP, common->partialmatchlabel); - else - add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP)); - } - -if (jump != NULL) - JUMPHERE(jump); -} - -static void check_str_end(compiler_common *common, jump_list **end_reached) -{ -/* Does not affect registers. Usually used in a tight spot. */ -DEFINE_COMPILER; -struct sljit_jump *jump; - -if (common->mode == PCRE2_JIT_COMPLETE) - { - add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); - return; - } - -jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0); -if (common->mode == PCRE2_JIT_PARTIAL_SOFT) - { - add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); - add_jump(compiler, end_reached, JUMP(SLJIT_JUMP)); - } -else - { - add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0)); - if (common->partialmatchlabel != NULL) - JUMPTO(SLJIT_JUMP, common->partialmatchlabel); - else - add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP)); - } -JUMPHERE(jump); -} - -static void detect_partial_match(compiler_common *common, jump_list **backtracks) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; - -if (common->mode == PCRE2_JIT_COMPLETE) - { - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); - return; - } - -/* Partial matching mode. */ -jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0); -if (!common->allow_empty_partial) - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0)); -else if (common->mode == PCRE2_JIT_PARTIAL_SOFT) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1)); - -if (common->mode == PCRE2_JIT_PARTIAL_SOFT) - { - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - } -else - { - if (common->partialmatchlabel != NULL) - JUMPTO(SLJIT_JUMP, common->partialmatchlabel); - else - add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP)); - } -JUMPHERE(jump); -} - -static void process_partial_match(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; - -/* Partial matching mode. */ -if (common->mode == PCRE2_JIT_PARTIAL_SOFT) - { - jump = CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); - JUMPHERE(jump); - } -else if (common->mode == PCRE2_JIT_PARTIAL_HARD) - { - if (common->partialmatchlabel != NULL) - CMPTO(SLJIT_LESS, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0, common->partialmatchlabel); - else - add_jump(compiler, &common->partialmatch, CMP(SLJIT_LESS, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0)); - } -} - -static void detect_partial_match_to(compiler_common *common, struct sljit_label *label) -{ -DEFINE_COMPILER; - -CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, label); -process_partial_match(common); -} - -static void peek_char(compiler_common *common, sljit_u32 max, sljit_s32 dst, sljit_sw dstw, jump_list **backtracks) -{ -/* Reads the character into TMP1, keeps STR_PTR. -Does not check STR_END. TMP2, dst, RETURN_ADDR Destroyed. */ -DEFINE_COMPILER; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -struct sljit_jump *jump; -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */ - -SLJIT_UNUSED_ARG(max); -SLJIT_UNUSED_ARG(dst); -SLJIT_UNUSED_ARG(dstw); -SLJIT_UNUSED_ARG(backtracks); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utf) - { - if (max < 128) return; - - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80); - OP1(SLJIT_MOV, dst, dstw, STR_PTR, 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - add_jump(compiler, common->invalid_utf ? &common->utfreadchar_invalid : &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); - OP1(SLJIT_MOV, STR_PTR, 0, dst, dstw); - if (backtracks && common->invalid_utf) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - JUMPHERE(jump); - } -#elif PCRE2_CODE_UNIT_WIDTH == 16 -if (common->utf) - { - if (max < 0xd800) return; - - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - - if (common->invalid_utf) - { - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800); - OP1(SLJIT_MOV, dst, dstw, STR_PTR, 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL)); - OP1(SLJIT_MOV, STR_PTR, 0, dst, dstw); - if (backtracks && common->invalid_utf) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - } - else - { - /* TMP2 contains the high surrogate. */ - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000 - 0xdc00); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); - } - - JUMPHERE(jump); - } -#elif PCRE2_CODE_UNIT_WIDTH == 32 -if (common->invalid_utf) - { - if (max < 0xd800) return; - - if (backtracks != NULL) - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000)); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800)); - } - else - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000); - SELECT(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR, TMP1); - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800); - SELECT(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR, TMP1); - } - } -#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */ -#endif /* SUPPORT_UNICODE */ -} - -static void peek_char_back(compiler_common *common, sljit_u32 max, jump_list **backtracks) -{ -/* Reads one character back without moving STR_PTR. TMP2 must -contain the start of the subject buffer. Affects TMP1, TMP2, and RETURN_ADDR. */ -DEFINE_COMPILER; - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -struct sljit_jump *jump; -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */ - -SLJIT_UNUSED_ARG(max); -SLJIT_UNUSED_ARG(backtracks); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); - -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utf) - { - if (max < 128) return; - - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80); - if (common->invalid_utf) - { - add_jump(compiler, &common->utfpeakcharback_invalid, JUMP(SLJIT_FAST_CALL)); - if (backtracks != NULL) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - } - else - add_jump(compiler, &common->utfpeakcharback, JUMP(SLJIT_FAST_CALL)); - JUMPHERE(jump); - } -#elif PCRE2_CODE_UNIT_WIDTH == 16 -if (common->utf) - { - if (max < 0xd800) return; - - if (common->invalid_utf) - { - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800); - add_jump(compiler, &common->utfpeakcharback_invalid, JUMP(SLJIT_FAST_CALL)); - if (backtracks != NULL) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - } - else - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xdc00); - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xdc00); - /* TMP2 contains the low surrogate. */ - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x10000); - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); - } - JUMPHERE(jump); - } -#elif PCRE2_CODE_UNIT_WIDTH == 32 -if (common->invalid_utf) - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000)); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800)); - } -#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */ -#endif /* SUPPORT_UNICODE */ -} - -#define READ_CHAR_UPDATE_STR_PTR 0x1 -#define READ_CHAR_UTF8_NEWLINE 0x2 -#define READ_CHAR_NEWLINE (READ_CHAR_UPDATE_STR_PTR | READ_CHAR_UTF8_NEWLINE) -#define READ_CHAR_VALID_UTF 0x4 - -static void read_char(compiler_common *common, sljit_u32 min, sljit_u32 max, - jump_list **backtracks, sljit_u32 options) -{ -/* Reads the precise value of a character into TMP1, if the character is -between min and max (c >= min && c <= max). Otherwise it returns with a value -outside the range. Does not check STR_END. */ -DEFINE_COMPILER; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -struct sljit_jump *jump; -#endif -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -struct sljit_jump *jump2; -#endif - -SLJIT_UNUSED_ARG(min); -SLJIT_UNUSED_ARG(max); -SLJIT_UNUSED_ARG(backtracks); -SLJIT_UNUSED_ARG(options); -SLJIT_ASSERT(min <= max); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utf) - { - if (max < 128 && !(options & READ_CHAR_UPDATE_STR_PTR)) return; - - if (common->invalid_utf && !(options & READ_CHAR_VALID_UTF)) - { - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80); - - if (options & READ_CHAR_UTF8_NEWLINE) - add_jump(compiler, &common->utfreadnewline_invalid, JUMP(SLJIT_FAST_CALL)); - else - add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL)); - - if (backtracks != NULL) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - JUMPHERE(jump); - return; - } - - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0); - if (min >= 0x10000) - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0); - if (options & READ_CHAR_UPDATE_STR_PTR) - OP1(SLJIT_MOV_U8, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x7); - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); - OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); - OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2)); - if (!(options & READ_CHAR_UPDATE_STR_PTR)) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); - OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - JUMPHERE(jump2); - if (options & READ_CHAR_UPDATE_STR_PTR) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0); - } - else if (min >= 0x800 && max <= 0xffff) - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0); - if (options & READ_CHAR_UPDATE_STR_PTR) - OP1(SLJIT_MOV_U8, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xf); - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); - OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - if (!(options & READ_CHAR_UPDATE_STR_PTR)) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); - OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - JUMPHERE(jump2); - if (options & READ_CHAR_UPDATE_STR_PTR) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0); - } - else if (max >= 0x800) - { - add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); - } - else if (max < 128) - { - OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); - } - else - { - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - if (!(options & READ_CHAR_UPDATE_STR_PTR)) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - else - OP1(SLJIT_MOV_U8, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); - OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); - OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - if (options & READ_CHAR_UPDATE_STR_PTR) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0); - } - JUMPHERE(jump); - } -#elif PCRE2_CODE_UNIT_WIDTH == 16 -if (common->utf) - { - if (max < 0xd800 && !(options & READ_CHAR_UPDATE_STR_PTR)) return; - - if (common->invalid_utf && !(options & READ_CHAR_VALID_UTF)) - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800); - - if (options & READ_CHAR_UTF8_NEWLINE) - add_jump(compiler, &common->utfreadnewline_invalid, JUMP(SLJIT_FAST_CALL)); - else - add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL)); - - if (backtracks != NULL) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - JUMPHERE(jump); - return; - } - - if (max >= 0x10000) - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800); - /* TMP2 contains the high surrogate. */ - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000 - 0xdc00); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); - JUMPHERE(jump); - return; - } - - /* Skip low surrogate if necessary. */ - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - - if (sljit_has_cpu_feature(SLJIT_HAS_CMOV) && !HAS_VIRTUAL_REGISTERS) - { - if (options & READ_CHAR_UPDATE_STR_PTR) - OP2(SLJIT_ADD, RETURN_ADDR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP2, 0, SLJIT_IMM, 0x400); - if (options & READ_CHAR_UPDATE_STR_PTR) - SELECT(SLJIT_LESS, STR_PTR, RETURN_ADDR, 0, STR_PTR); - if (max >= 0xd800) - SELECT(SLJIT_LESS, TMP1, SLJIT_IMM, 0x10000, TMP1); - } - else - { - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400); - if (options & READ_CHAR_UPDATE_STR_PTR) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - if (max >= 0xd800) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000); - JUMPHERE(jump); - } - } -#elif PCRE2_CODE_UNIT_WIDTH == 32 -if (common->invalid_utf) - { - if (backtracks != NULL) - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000)); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800)); - } - else - { - OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000); - SELECT(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR, TMP1); - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800); - SELECT(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR, TMP1); - } - } -#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */ -#endif /* SUPPORT_UNICODE */ -} - -static void skip_valid_char(compiler_common *common) -{ -DEFINE_COMPILER; -#if (defined SUPPORT_UNICODE) && (PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16) -struct sljit_jump *jump; -#endif - -#if (defined SUPPORT_UNICODE) && (PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16) - if (common->utf) - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -#if PCRE2_CODE_UNIT_WIDTH == 8 - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0); - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); -#elif PCRE2_CODE_UNIT_WIDTH == 16 - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800); - OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0xd800); - OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - JUMPHERE(jump); - return; - } -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == [8|16] */ - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -} - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - -static BOOL is_char7_bitset(const sljit_u8 *bitset, BOOL nclass) -{ -/* Tells whether the character codes below 128 are enough -to determine a match. */ -const sljit_u8 value = nclass ? 0xff : 0; -const sljit_u8 *end = bitset + 32; - -bitset += 16; -do - { - if (*bitset++ != value) - return FALSE; - } -while (bitset < end); -return TRUE; -} - -static void read_char7_type(compiler_common *common, jump_list **backtracks, BOOL negated) -{ -/* Reads the precise character type of a character into TMP1, if the character -is less than 128. Otherwise it returns with zero. Does not check STR_END. The -full_read argument tells whether characters above max are accepted or not. */ -DEFINE_COMPILER; -struct sljit_jump *jump; - -SLJIT_ASSERT(common->utf); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -/* All values > 127 are zero in ctypes. */ -OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); - -if (negated) - { - jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x80); - - if (common->invalid_utf) - { - OP1(SLJIT_MOV, TMP1, 0, TMP2, 0); - add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL)); - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); - } - else - { - OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); - } - JUMPHERE(jump); - } -} - -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 */ - -static void read_char8_type(compiler_common *common, jump_list **backtracks, BOOL negated) -{ -/* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */ -DEFINE_COMPILER; -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 -struct sljit_jump *jump; -#endif -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -struct sljit_jump *jump2; -#endif - -SLJIT_UNUSED_ARG(backtracks); -SLJIT_UNUSED_ARG(negated); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utf) - { - /* The result of this read may be unused, but saves an "else" part. */ - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); - jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x80); - - if (!negated) - { - if (common->invalid_utf) - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); - - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2); - if (common->invalid_utf) - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe0 - 0xc2)); - - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0); - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80); - if (common->invalid_utf) - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40)); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); - jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255); - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); - JUMPHERE(jump2); - } - else if (common->invalid_utf) - { - add_jump(compiler, &common->utfreadchar_invalid, JUMP(SLJIT_FAST_CALL)); - OP1(SLJIT_MOV, TMP2, 0, TMP1, 0); - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR)); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); - jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255); - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); - JUMPHERE(jump2); - } - else - add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL)); - - JUMPHERE(jump); - return; - } -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 */ - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 32 -if (common->invalid_utf && negated) - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x110000)); -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 32 */ - -#if PCRE2_CODE_UNIT_WIDTH != 8 -/* The ctypes array contains only 256 values. */ -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); -jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255); -#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */ -OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); -#if PCRE2_CODE_UNIT_WIDTH != 8 -JUMPHERE(jump); -#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */ - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 16 -if (common->utf && negated) - { - /* Skip low surrogate if necessary. */ - if (!common->invalid_utf) - { - OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800); - - if (sljit_has_cpu_feature(SLJIT_HAS_CMOV) && !HAS_VIRTUAL_REGISTERS) - { - OP2(SLJIT_ADD, RETURN_ADDR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP2, 0, SLJIT_IMM, 0x400); - SELECT(SLJIT_LESS, STR_PTR, RETURN_ADDR, 0, STR_PTR); - } - else - { - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - JUMPHERE(jump); - } - return; - } - - OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800); - jump = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0xe000 - 0xd800); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400)); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); - - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xdc00); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400)); - - JUMPHERE(jump); - return; - } -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 16 */ -} - -static void move_back(compiler_common *common, jump_list **backtracks, BOOL must_be_valid) -{ -/* Goes one character back. Affects STR_PTR and TMP1. If must_be_valid is TRUE, -TMP2 is not used. Otherwise TMP2 must contain the start of the subject buffer, -and it is destroyed. Does not modify STR_PTR for invalid character sequences. */ -DEFINE_COMPILER; - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -struct sljit_jump *jump; -#endif - -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 -struct sljit_label *label; - -if (common->utf) - { - if (!must_be_valid && common->invalid_utf) - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x80); - add_jump(compiler, &common->utfmoveback_invalid, JUMP(SLJIT_FAST_CALL)); - if (backtracks != NULL) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0)); - JUMPHERE(jump); - return; - } - - label = LABEL(); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0); - CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label); - return; - } -#elif PCRE2_CODE_UNIT_WIDTH == 16 -if (common->utf) - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - if (!must_be_valid && common->invalid_utf) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800); - jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xe000 - 0xd800); - add_jump(compiler, &common->utfmoveback_invalid, JUMP(SLJIT_FAST_CALL)); - if (backtracks != NULL) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0)); - JUMPHERE(jump); - return; - } - - /* Skip low surrogate if necessary. */ - OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0xdc00); - OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); - return; - } -#elif PCRE2_CODE_UNIT_WIDTH == 32 -if (common->invalid_utf && !must_be_valid) - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); - if (backtracks != NULL) - { - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x110000)); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - return; - } - - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, SLJIT_IMM, 0x110000); - OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_LESS); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); - return; - } -#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */ -#endif /* SUPPORT_UNICODE */ - -SLJIT_UNUSED_ARG(backtracks); -SLJIT_UNUSED_ARG(must_be_valid); - -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -} - -static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpifmatch) -{ -/* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */ -DEFINE_COMPILER; -struct sljit_jump *jump; - -if (nltype == NLTYPE_ANY) - { - add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL)); - sljit_set_current_flags(compiler, SLJIT_SET_Z); - add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_NOT_ZERO : SLJIT_ZERO)); - } -else if (nltype == NLTYPE_ANYCRLF) - { - if (jumpifmatch) - { - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR)); - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL)); - } - else - { - jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL)); - JUMPHERE(jump); - } - } -else - { - SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256); - add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline)); - } -} - -#ifdef SUPPORT_UNICODE - -#if PCRE2_CODE_UNIT_WIDTH == 8 -static void do_utfreadchar(compiler_common *common) -{ -/* Fast decoding a UTF-8 character. TMP1 contains the first byte -of the character (>= 0xc0). Return char value in TMP1. */ -DEFINE_COMPILER; -struct sljit_jump *jump; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -/* Searching for the first zero. */ -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x800); -jump = JUMP(SLJIT_NOT_ZERO); -/* Two byte sequence. */ -OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3000); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump); -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x10000); -jump = JUMP(SLJIT_NOT_ZERO); -/* Three byte sequence. */ -OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0000); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* Four byte sequence. */ -JUMPHERE(jump); -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2)); -OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xf0000); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfreadtype8(compiler_common *common) -{ -/* Fast decoding a UTF-8 character type. TMP2 contains the first byte -of the character (>= 0xc0). Return value in TMP1. */ -DEFINE_COMPILER; -struct sljit_jump *jump; -struct sljit_jump *compare; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, 0x20); -jump = JUMP(SLJIT_NOT_ZERO); -/* Two byte sequence. */ -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f); -/* The upper 5 bits are known at this point. */ -compare = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x3); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); -OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); -OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0); -OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(compare); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* We only have types for characters less than 256. */ -JUMPHERE(jump); -OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfreadchar_invalid(compiler_common *common) -{ -/* Slow decoding a UTF-8 character. TMP1 contains the first byte -of the character (>= 0xc0). Return char value in TMP1. STR_PTR is -undefined for invalid characters. */ -DEFINE_COMPILER; -sljit_s32 i; -sljit_s32 has_cmov = sljit_has_cpu_feature(SLJIT_HAS_CMOV); -struct sljit_jump *jump; -struct sljit_jump *buffer_end_close; -struct sljit_label *three_byte_entry; -struct sljit_label *exit_invalid_label; -struct sljit_jump *exit_invalid[11]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc2); - -/* Usually more than 3 characters remained in the subject buffer. */ -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); - -/* Not a valid start of a multi-byte sequence, no more bytes read. */ -exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xf5 - 0xc2); - -buffer_end_close = CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -/* If TMP2 is in 0x80-0xbf range, TMP1 is also increased by (0x2 << 6). */ -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80); -exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x800); -jump = JUMP(SLJIT_NOT_ZERO); - -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump); - -/* Three-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - SELECT(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, 0x20000, TMP1); - exit_invalid[2] = NULL; - } -else - exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x10000); -jump = JUMP(SLJIT_NOT_ZERO); - -three_byte_entry = LABEL(); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2d800); -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, SLJIT_IMM, 0x800); - SELECT(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR - 0xd800, TMP1); - exit_invalid[3] = NULL; - } -else - exit_invalid[3] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800); -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, SLJIT_IMM, 0x800); - SELECT(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR, TMP1); - exit_invalid[4] = NULL; - } -else - exit_invalid[4] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump); - -/* Four-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - SELECT(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, 0, TMP1); - exit_invalid[5] = NULL; - } -else - exit_invalid[5] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc10000); -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x100000); - SELECT(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR - 0x10000, TMP1); - exit_invalid[6] = NULL; - } -else - exit_invalid[6] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x100000); - -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(buffer_end_close); -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); -exit_invalid[7] = CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0); - -/* Two-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -/* If TMP2 is in 0x80-0xbf range, TMP1 is also increased by (0x2 << 6). */ -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80); -exit_invalid[8] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x800); -jump = JUMP(SLJIT_NOT_ZERO); - -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* Three-byte sequence. */ -JUMPHERE(jump); -exit_invalid[9] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - SELECT(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR, TMP1); - exit_invalid[10] = NULL; - } -else - exit_invalid[10] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); - -/* One will be substracted from STR_PTR later. */ -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - -/* Four byte sequences are not possible. */ -CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x30000, three_byte_entry); - -exit_invalid_label = LABEL(); -for (i = 0; i < 11; i++) - sljit_set_label(exit_invalid[i], exit_invalid_label); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfreadnewline_invalid(compiler_common *common) -{ -/* Slow decoding a UTF-8 character, specialized for newlines. -TMP1 contains the first byte of the character (>= 0xc0). Return -char value in TMP1. */ -DEFINE_COMPILER; -struct sljit_label *loop; -struct sljit_label *skip_start; -struct sljit_label *three_byte_exit; -struct sljit_jump *jump[5]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -if (common->nltype != NLTYPE_ANY) - { - SLJIT_ASSERT(common->nltype != NLTYPE_FIXED || common->newline < 128); - - /* All newlines are ascii, just skip intermediate octets. */ - jump[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - loop = LABEL(); - if (sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_POST, TMP2, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)) == SLJIT_SUCCESS) - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_POST, TMP2, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - else - { - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - } - - OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc0); - CMPTO(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80, loop); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - JUMPHERE(jump[0]); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); - OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - return; - } - -jump[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -jump[1] = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0xc2); -jump[2] = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0xe2); - -skip_start = LABEL(); -OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc0); -jump[3] = CMP(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80); - -/* Skip intermediate octets. */ -loop = LABEL(); -jump[4] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc0); -CMPTO(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80, loop); - -JUMPHERE(jump[3]); -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -three_byte_exit = LABEL(); -JUMPHERE(jump[0]); -JUMPHERE(jump[4]); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* Two byte long newline: 0x85. */ -JUMPHERE(jump[1]); -CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0x85, skip_start); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x85); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* Three byte long newlines: 0x2028 and 0x2029. */ -JUMPHERE(jump[2]); -CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0x80, skip_start); -CMPTO(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0, three_byte_exit); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -OP2(SLJIT_SUB, TMP1, 0, TMP2, 0, SLJIT_IMM, 0x80); -CMPTO(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x40, skip_start); - -OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0x2000); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfmoveback_invalid(compiler_common *common) -{ -/* Goes one character back. */ -DEFINE_COMPILER; -sljit_s32 i; -struct sljit_jump *jump; -struct sljit_jump *buffer_start_close; -struct sljit_label *exit_ok_label; -struct sljit_label *exit_invalid_label; -struct sljit_jump *exit_invalid[7]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); -exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xc0); - -/* Two-byte sequence. */ -buffer_start_close = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2)); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0); -jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x20); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* Three-byte sequence. */ -JUMPHERE(jump); -exit_invalid[1] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, -0x40); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0); -jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x10); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* Four-byte sequence. */ -JUMPHERE(jump); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0 - 0x80); -exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x40); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xf0); -exit_invalid[3] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x05); - -exit_ok_label = LABEL(); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -/* Two-byte sequence. */ -JUMPHERE(buffer_start_close); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - -exit_invalid[4] = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0); -CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x20, exit_ok_label); - -/* Three-byte sequence. */ -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -exit_invalid[5] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, -0x40); -exit_invalid[6] = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0); -CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x10, exit_ok_label); - -/* Four-byte sequences are not possible. */ - -exit_invalid_label = LABEL(); -sljit_set_label(exit_invalid[5], exit_invalid_label); -sljit_set_label(exit_invalid[6], exit_invalid_label); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(exit_invalid[4]); -/* -2 + 4 = 2 */ -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - -exit_invalid_label = LABEL(); -for (i = 0; i < 4; i++) - sljit_set_label(exit_invalid[i], exit_invalid_label); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(4)); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfpeakcharback(compiler_common *common) -{ -/* Peak a character back. Does not modify STR_PTR. */ -DEFINE_COMPILER; -struct sljit_jump *jump[2]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0); -jump[0] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x20); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3)); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0); -jump[1] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x10); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-4)); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xe0 - 0x80); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xf0); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -JUMPHERE(jump[1]); -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -JUMPHERE(jump[0]); -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x80); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfpeakcharback_invalid(compiler_common *common) -{ -/* Peak a character back. Does not modify STR_PTR. */ -DEFINE_COMPILER; -sljit_s32 i; -sljit_s32 has_cmov = sljit_has_cpu_feature(SLJIT_HAS_CMOV); -struct sljit_jump *jump[2]; -struct sljit_label *two_byte_entry; -struct sljit_label *three_byte_entry; -struct sljit_label *exit_invalid_label; -struct sljit_jump *exit_invalid[8]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(3)); -exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xc0); -jump[0] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0); - -/* Two-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2); -jump[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x1e); - -two_byte_entry = LABEL(); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); -/* If TMP1 is in 0x80-0xbf range, TMP1 is also increased by (0x2 << 6). */ -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump[1]); -OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2 - 0x80); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80); -exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -/* Three-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3)); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xe0); -jump[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x10); - -three_byte_entry = LABEL(); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800); -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, SLJIT_IMM, 0x800); - SELECT(SLJIT_LESS, TMP1, SLJIT_IMM, -0xd800, TMP1); - exit_invalid[2] = NULL; - } -else - exit_invalid[2] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800); - -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800); -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, SLJIT_IMM, 0x800); - SELECT(SLJIT_LESS, TMP1, SLJIT_IMM, INVALID_UTF_CHAR, TMP1); - exit_invalid[3] = NULL; - } -else - exit_invalid[3] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x800); - -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump[1]); -OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xe0 - 0x80); -exit_invalid[4] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -/* Four-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-4)); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xf0); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 18); -/* ADD is used instead of OR because of the SUB 0x10000 above. */ -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); - -if (has_cmov) - { - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x100000); - SELECT(SLJIT_GREATER_EQUAL, TMP1, SLJIT_IMM, INVALID_UTF_CHAR - 0x10000, TMP1); - exit_invalid[5] = NULL; - } -else - exit_invalid[5] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x100000); - -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump[0]); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); -jump[0] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0); - -/* Two-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2); -CMPTO(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x1e, two_byte_entry); - -OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2 - 0x80); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80); -exit_invalid[6] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x40); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); - -/* Three-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-3)); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xe0); -CMPTO(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x10, three_byte_entry); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump[0]); -exit_invalid[7] = CMP(SLJIT_GREATER, TMP2, 0, STR_PTR, 0); - -/* Two-byte sequence. */ -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xc2); -CMPTO(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0x1e, two_byte_entry); - -exit_invalid_label = LABEL(); -for (i = 0; i < 8; i++) - sljit_set_label(exit_invalid[i], exit_invalid_label); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - -#if PCRE2_CODE_UNIT_WIDTH == 16 - -static void do_utfreadchar_invalid(compiler_common *common) -{ -/* Slow decoding a UTF-16 character. TMP1 contains the first half -of the character (>= 0xd800). Return char value in TMP1. STR_PTR is -undefined for invalid characters. */ -DEFINE_COMPILER; -struct sljit_jump *exit_invalid[3]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -/* TMP2 contains the high surrogate. */ -exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xdc00); -exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xdc00); -OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x10000); -exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x400); - -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(exit_invalid[0]); -JUMPHERE(exit_invalid[1]); -JUMPHERE(exit_invalid[2]); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfreadnewline_invalid(compiler_common *common) -{ -/* Slow decoding a UTF-16 character, specialized for newlines. -TMP1 contains the first half of the character (>= 0xd800). Return -char value in TMP1. */ - -DEFINE_COMPILER; -struct sljit_jump *exit_invalid[2]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -/* TMP2 contains the high surrogate. */ -exit_invalid[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); -exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xdc00); - -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xdc00); -OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP2, 0, SLJIT_IMM, 0x400); -OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); - -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(exit_invalid[0]); -JUMPHERE(exit_invalid[1]); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfmoveback_invalid(compiler_common *common) -{ -/* Goes one character back. */ -DEFINE_COMPILER; -struct sljit_jump *exit_invalid[3]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -exit_invalid[0] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x400); -exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800); -exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0x400); - -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(exit_invalid[0]); -JUMPHERE(exit_invalid[1]); -JUMPHERE(exit_invalid[2]); - -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_utfpeakcharback_invalid(compiler_common *common) -{ -/* Peak a character back. Does not modify STR_PTR. */ -DEFINE_COMPILER; -struct sljit_jump *jump; -struct sljit_jump *exit_invalid[3]; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 0xe000); -OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); -exit_invalid[0] = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xdc00); -exit_invalid[1] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, STR_PTR, 0); - -OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000 - 0xdc00); -OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800); -exit_invalid[2] = CMP(SLJIT_GREATER_EQUAL, TMP2, 0, SLJIT_IMM, 0x400); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); - -JUMPHERE(jump); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(exit_invalid[0]); -JUMPHERE(exit_invalid[1]); -JUMPHERE(exit_invalid[2]); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -#endif /* PCRE2_CODE_UNIT_WIDTH == 16 */ - -/* UCD_BLOCK_SIZE must be 128 (see the assert below). */ -#define UCD_BLOCK_MASK 127 -#define UCD_BLOCK_SHIFT 7 - -static void do_getucd(compiler_common *common) -{ -/* Search the UCD record for the character comes in TMP1. -Returns chartype in TMP1 and UCD offset in TMP2. */ -DEFINE_COMPILER; -#if PCRE2_CODE_UNIT_WIDTH == 32 -struct sljit_jump *jump; -#endif - -#if defined SLJIT_DEBUG && SLJIT_DEBUG -/* dummy_ucd_record */ -const ucd_record *record = GET_UCD(UNASSIGNED_UTF_CHAR); -SLJIT_ASSERT(record->script == ucp_Unknown && record->chartype == ucp_Cn && record->gbprop == ucp_gbOther); -SLJIT_ASSERT(record->caseset == 0 && record->other_case == 0); -#endif - -SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 12); - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -#if PCRE2_CODE_UNIT_WIDTH == 32 -if (!common->utf) - { - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, MAX_UTF_CODE_POINT + 1); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, UNASSIGNED_UTF_CHAR); - JUMPHERE(jump); - } -#endif - -OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1); -OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1)); -OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); -OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2)); -OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_getucdtype(compiler_common *common) -{ -/* Search the UCD record for the character comes in TMP1. -Returns chartype in TMP1 and UCD offset in TMP2. */ -DEFINE_COMPILER; -#if PCRE2_CODE_UNIT_WIDTH == 32 -struct sljit_jump *jump; -#endif - -#if defined SLJIT_DEBUG && SLJIT_DEBUG -/* dummy_ucd_record */ -const ucd_record *record = GET_UCD(UNASSIGNED_UTF_CHAR); -SLJIT_ASSERT(record->script == ucp_Unknown && record->chartype == ucp_Cn && record->gbprop == ucp_gbOther); -SLJIT_ASSERT(record->caseset == 0 && record->other_case == 0); -#endif - -SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 12); - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -#if PCRE2_CODE_UNIT_WIDTH == 32 -if (!common->utf) - { - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, MAX_UTF_CODE_POINT + 1); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, UNASSIGNED_UTF_CHAR); - JUMPHERE(jump); - } -#endif - -OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1); -OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1)); -OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); -OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2)); -OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1); - -/* TMP2 is multiplied by 12. Same as (TMP2 << 2) + ((TMP2 << 2) << 1). */ -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype)); -OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 2); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); -OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 1); - -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -#endif /* SUPPORT_UNICODE */ - -static SLJIT_INLINE struct sljit_label *mainloop_entry(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_label *mainloop; -struct sljit_label *newlinelabel = NULL; -struct sljit_jump *start; -struct sljit_jump *end = NULL; -struct sljit_jump *end2 = NULL; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -struct sljit_label *loop; -struct sljit_jump *jump; -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */ -jump_list *newline = NULL; -sljit_u32 overall_options = common->re->overall_options; -BOOL hascrorlf = (common->re->flags & PCRE2_HASCRORLF) != 0; -BOOL newlinecheck = FALSE; -BOOL readuchar = FALSE; - -if (!(hascrorlf || (overall_options & PCRE2_FIRSTLINE) != 0) - && (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF || common->newline > 255)) - newlinecheck = TRUE; - -SLJIT_ASSERT(common->abort_label == NULL); - -if ((overall_options & PCRE2_FIRSTLINE) != 0) - { - /* Search for the end of the first line. */ - SLJIT_ASSERT(common->match_end_ptr != 0); - OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); - - if (common->nltype == NLTYPE_FIXED && common->newline > 255) - { - mainloop = LABEL(); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop); - CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop); - JUMPHERE(end); - OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - } - else - { - end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - mainloop = LABEL(); - /* Continual stores does not cause data dependency. */ - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr, STR_PTR, 0); - read_char(common, common->nlmin, common->nlmax, NULL, READ_CHAR_NEWLINE); - check_newlinechar(common, common->nltype, &newline, TRUE); - CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, mainloop); - JUMPHERE(end); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr, STR_PTR, 0); - set_jumps(newline, LABEL()); - } - - OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); - } -else if ((overall_options & PCRE2_USE_OFFSET_LIMIT) != 0) - { - /* Check whether offset limit is set and valid. */ - SLJIT_ASSERT(common->match_end_ptr != 0); - - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, offset_limit)); - } - else - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, offset_limit)); - - OP1(SLJIT_MOV, TMP2, 0, STR_END, 0); - end = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, (sljit_sw) PCRE2_UNSET); - if (HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0); - else - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif /* PCRE2_CODE_UNIT_WIDTH == [16|32] */ - if (HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin)); - - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0); - end2 = CMP(SLJIT_LESS_EQUAL, TMP2, 0, STR_END, 0); - OP1(SLJIT_MOV, TMP2, 0, STR_END, 0); - JUMPHERE(end2); - OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_NOMATCH); - add_jump(compiler, &common->abort, CMP(SLJIT_LESS, TMP2, 0, STR_PTR, 0)); - JUMPHERE(end); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr, TMP2, 0); - } - -start = JUMP(SLJIT_JUMP); - -if (newlinecheck) - { - newlinelabel = LABEL(); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, common->newline & 0xff); - OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL); -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif /* PCRE2_CODE_UNIT_WIDTH == [16|32] */ - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); - end2 = JUMP(SLJIT_JUMP); - } - -mainloop = LABEL(); - -/* Increasing the STR_PTR here requires one less jump in the most common case. */ -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -if (common->utf && !common->invalid_utf) readuchar = TRUE; -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */ -if (newlinecheck) readuchar = TRUE; - -if (readuchar) - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - -if (newlinecheck) - CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel); - -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->invalid_utf) - { - /* Skip continuation code units. */ - loop = LABEL(); - jump = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x80); - CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x40, loop); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - JUMPHERE(jump); - } -else if (common->utf) - { - jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0); - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); - JUMPHERE(jump); - } -#elif PCRE2_CODE_UNIT_WIDTH == 16 -if (common->invalid_utf) - { - /* Skip continuation code units. */ - loop = LABEL(); - jump = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xdc00); - CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0x400, loop); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - JUMPHERE(jump); - } -else if (common->utf) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xd800); - - if (sljit_has_cpu_feature(SLJIT_HAS_CMOV)) - { - OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, SLJIT_IMM, 0x400); - SELECT(SLJIT_LESS, STR_PTR, TMP2, 0, STR_PTR); - } - else - { - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, SLJIT_IMM, 0x400); - OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_LESS); - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); - } - } -#endif /* PCRE2_CODE_UNIT_WIDTH == [8|16] */ -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */ -JUMPHERE(start); - -if (newlinecheck) - { - JUMPHERE(end); - JUMPHERE(end2); - } - -return mainloop; -} - - -static SLJIT_INLINE void add_prefix_char(PCRE2_UCHAR chr, fast_forward_char_data *chars, BOOL last) -{ -sljit_u32 i, count = chars->count; - -if (count == 255) - return; - -if (count == 0) - { - chars->count = 1; - chars->chars[0] = chr; - - if (last) - chars->last_count = 1; - return; - } - -for (i = 0; i < count; i++) - if (chars->chars[i] == chr) - return; - -if (count >= MAX_DIFF_CHARS) - { - chars->count = 255; - return; - } - -chars->chars[count] = chr; -chars->count = count + 1; - -if (last) - chars->last_count++; -} - -/* Value can be increased if needed. Patterns -such as /(a|){33}b/ can exhaust the stack. - -Note: /(a|){29}b/ already stops scan_prefix() -because it reaches the maximum step_count. */ -#define SCAN_PREFIX_STACK_END 32 - -/* -Scan prefix stores the prefix string in the chars array. -The elements of the chars array is either small character -sets or "any" (count is set to 255). - -Examples (the chars array is represented by a simple regex): - -/(abc|xbyd)/ prefix: /[ax]b[cy]/ (length: 3) -/a[a-z]b+c/ prefix: a.b (length: 3) -/ab?cd/ prefix: a[bc][cd] (length: 3) -/(ab|cd)|(ef|gh)/ prefix: [aceg][bdfh] (length: 2) - -The length is returned by scan_prefix(). The length is -less than or equal than the minimum length of the pattern. -*/ - -static int scan_prefix(compiler_common *common, PCRE2_SPTR cc, fast_forward_char_data *chars) -{ -fast_forward_char_data *chars_start = chars; -fast_forward_char_data *chars_end = chars + MAX_N_CHARS; -PCRE2_SPTR cc_stack[SCAN_PREFIX_STACK_END]; -fast_forward_char_data *chars_stack[SCAN_PREFIX_STACK_END]; -sljit_u8 next_alternative_stack[SCAN_PREFIX_STACK_END]; -BOOL last, any, class, caseless; -int stack_ptr, step_count, repeat, len, len_save; -sljit_u32 chr; /* Any unicode character. */ -sljit_u8 *bytes, *bytes_end, byte; -PCRE2_SPTR alternative, cc_save, oc; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 -PCRE2_UCHAR othercase[4]; -#elif defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 16 -PCRE2_UCHAR othercase[2]; -#else -PCRE2_UCHAR othercase[1]; -#endif - -repeat = 1; -stack_ptr = 0; -step_count = 10000; -while (TRUE) - { - if (--step_count == 0) - return 0; - - SLJIT_ASSERT(chars <= chars_start + MAX_N_CHARS); - - if (chars >= chars_end) - { - if (stack_ptr == 0) - return (int)(chars_end - chars_start); - - --stack_ptr; - cc = cc_stack[stack_ptr]; - chars = chars_stack[stack_ptr]; - - if (chars >= chars_end) - continue; - - if (next_alternative_stack[stack_ptr] != 0) - { - /* When an alternative is processed, the - next alternative is pushed onto the stack. */ - SLJIT_ASSERT(*cc == OP_ALT); - alternative = cc + GET(cc, 1); - if (*alternative == OP_ALT) - { - SLJIT_ASSERT(stack_ptr < SCAN_PREFIX_STACK_END); - SLJIT_ASSERT(chars_stack[stack_ptr] == chars); - SLJIT_ASSERT(next_alternative_stack[stack_ptr] == 1); - cc_stack[stack_ptr] = alternative; - stack_ptr++; - } - cc += 1 + LINK_SIZE; - } - } - - last = TRUE; - any = FALSE; - class = FALSE; - caseless = FALSE; - - switch (*cc) - { - case OP_CHARI: - caseless = TRUE; - /* Fall through */ - case OP_CHAR: - last = FALSE; - cc++; - break; - - case OP_SOD: - case OP_SOM: - case OP_SET_SOM: - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_EODN: - case OP_EOD: - case OP_CIRC: - case OP_CIRCM: - case OP_DOLL: - case OP_DOLLM: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - /* Zero width assertions. */ - cc++; - continue; - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - cc = bracketend(cc); - continue; - - case OP_PLUSI: - case OP_MINPLUSI: - case OP_POSPLUSI: - caseless = TRUE; - /* Fall through */ - case OP_PLUS: - case OP_MINPLUS: - case OP_POSPLUS: - cc++; - break; - - case OP_EXACTI: - caseless = TRUE; - /* Fall through */ - case OP_EXACT: - repeat = GET2(cc, 1); - last = FALSE; - cc += 1 + IMM2_SIZE; - break; - - case OP_QUERYI: - case OP_MINQUERYI: - case OP_POSQUERYI: - caseless = TRUE; - /* Fall through */ - case OP_QUERY: - case OP_MINQUERY: - case OP_POSQUERY: - len = 1; - cc++; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc); -#endif - if (stack_ptr >= SCAN_PREFIX_STACK_END) - { - chars_end = chars; - continue; - } - - cc_stack[stack_ptr] = cc + len; - chars_stack[stack_ptr] = chars; - next_alternative_stack[stack_ptr] = 0; - stack_ptr++; - - last = FALSE; - break; - - case OP_KET: - cc += 1 + LINK_SIZE; - continue; - - case OP_ALT: - cc += GET(cc, 1); - continue; - - case OP_ONCE: - case OP_BRA: - case OP_BRAPOS: - case OP_CBRA: - case OP_CBRAPOS: - alternative = cc + GET(cc, 1); - if (*alternative == OP_ALT) - { - if (stack_ptr >= SCAN_PREFIX_STACK_END) - { - chars_end = chars; - continue; - } - - cc_stack[stack_ptr] = alternative; - chars_stack[stack_ptr] = chars; - next_alternative_stack[stack_ptr] = 1; - stack_ptr++; - } - - if (*cc == OP_CBRA || *cc == OP_CBRAPOS) - cc += IMM2_SIZE; - cc += 1 + LINK_SIZE; - continue; - - case OP_CLASS: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - if (common->utf && !is_char7_bitset((const sljit_u8 *)(cc + 1), FALSE)) - { - chars_end = chars; - continue; - } -#endif - class = TRUE; - break; - - case OP_NCLASS: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - { - chars_end = chars; - continue; - } -#endif - class = TRUE; - break; - -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 - case OP_XCLASS: - case OP_ECLASS: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - { - chars_end = chars; - continue; - } -#endif - any = TRUE; - cc += GET(cc, 1); - break; -#endif - - case OP_DIGIT: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - if (common->utf && !is_char7_bitset((const sljit_u8 *)common->ctypes - cbit_length + cbit_digit, FALSE)) - { - chars_end = chars; - continue; - } -#endif - any = TRUE; - cc++; - break; - - case OP_WHITESPACE: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - if (common->utf && !is_char7_bitset((const sljit_u8 *)common->ctypes - cbit_length + cbit_space, FALSE)) - { - chars_end = chars; - continue; - } -#endif - any = TRUE; - cc++; - break; - - case OP_WORDCHAR: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 - if (common->utf && !is_char7_bitset((const sljit_u8 *)common->ctypes - cbit_length + cbit_word, FALSE)) - { - chars_end = chars; - continue; - } -#endif - any = TRUE; - cc++; - break; - - case OP_NOT: - case OP_NOTI: - cc++; - /* Fall through. */ - case OP_NOT_DIGIT: - case OP_NOT_WHITESPACE: - case OP_NOT_WORDCHAR: - case OP_ANY: - case OP_ALLANY: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - { - chars_end = chars; - continue; - } -#endif - any = TRUE; - cc++; - break; - -#ifdef SUPPORT_UNICODE - case OP_NOTPROP: - case OP_PROP: -#if PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - { - chars_end = chars; - continue; - } -#endif - any = TRUE; - cc += 1 + 2; - break; -#endif - - case OP_TYPEEXACT: - repeat = GET2(cc, 1); - cc += 1 + IMM2_SIZE; - continue; - - case OP_NOTEXACT: - case OP_NOTEXACTI: -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - { - chars_end = chars; - continue; - } -#endif - any = TRUE; - repeat = GET2(cc, 1); - cc += 1 + IMM2_SIZE + 1; - break; - - default: - chars_end = chars; - continue; - } - - SLJIT_ASSERT(chars < chars_end); - - if (any) - { - do - { - chars->count = 255; - chars++; - } - while (--repeat > 0 && chars < chars_end); - - repeat = 1; - continue; - } - - if (class) - { - bytes = (sljit_u8*) (cc + 1); - cc += 1 + 32 / sizeof(PCRE2_UCHAR); - - SLJIT_ASSERT(last == TRUE && repeat == 1); - switch (*cc) - { - case OP_CRQUERY: - case OP_CRMINQUERY: - case OP_CRPOSQUERY: - last = FALSE; - /* Fall through */ - case OP_CRSTAR: - case OP_CRMINSTAR: - case OP_CRPOSSTAR: - if (stack_ptr >= SCAN_PREFIX_STACK_END) - { - chars_end = chars; - continue; - } - - cc_stack[stack_ptr] = ++cc; - chars_stack[stack_ptr] = chars; - next_alternative_stack[stack_ptr] = 0; - stack_ptr++; - break; - - default: - case OP_CRPLUS: - case OP_CRMINPLUS: - case OP_CRPOSPLUS: - break; - - case OP_CRRANGE: - case OP_CRMINRANGE: - case OP_CRPOSRANGE: - repeat = GET2(cc, 1); - if (repeat <= 0) - { - chars_end = chars; - continue; - } - - last = (repeat != (int)GET2(cc, 1 + IMM2_SIZE)); - cc += 1 + 2 * IMM2_SIZE; - break; - } - - do - { - if (bytes[31] & 0x80) - chars->count = 255; - else if (chars->count != 255) - { - bytes_end = bytes + 32; - chr = 0; - do - { - byte = *bytes++; - SLJIT_ASSERT((chr & 0x7) == 0); - if (byte == 0) - chr += 8; - else - { - do - { - if ((byte & 0x1) != 0) - add_prefix_char(chr, chars, TRUE); - byte >>= 1; - chr++; - } - while (byte != 0); - chr = (chr + 7) & (sljit_u32)(~7); - } - } - while (chars->count != 255 && bytes < bytes_end); - bytes = bytes_end - 32; - } - - chars++; - } - while (--repeat > 0 && chars < chars_end); - - repeat = 1; - if (last) - chars_end = chars; - continue; - } - - len = 1; -#ifdef SUPPORT_UNICODE - if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc); -#endif - - if (caseless && char_has_othercase(common, cc)) - { -#ifdef SUPPORT_UNICODE - if (common->utf) - { - GETCHAR(chr, cc); - if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len) - { - chars_end = chars; - continue; - } - } - else -#endif - { - chr = *cc; -#ifdef SUPPORT_UNICODE - if (common->ucp && chr > 127) - { - chr = UCD_OTHERCASE(chr); - othercase[0] = (chr == (PCRE2_UCHAR)chr) ? chr : *cc; - } - else -#endif - othercase[0] = TABLE_GET(chr, common->fcc, chr); - } - } - else - { - caseless = FALSE; - othercase[0] = 0; /* Stops compiler warning - PH */ - } - - len_save = len; - cc_save = cc; - while (TRUE) - { - oc = othercase; - do - { - len--; - - chr = *cc; - add_prefix_char(*cc, chars, len == 0); - - if (caseless) - add_prefix_char(*oc, chars, len == 0); - - chars++; - cc++; - oc++; - } - while (len > 0 && chars < chars_end); - - if (--repeat == 0 || chars >= chars_end) - break; - - len = len_save; - cc = cc_save; - } - - repeat = 1; - if (last) - chars_end = chars; - } -} - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -static void jumpto_if_not_utf_char_start(struct sljit_compiler *compiler, sljit_s32 reg, struct sljit_label *label) -{ -#if PCRE2_CODE_UNIT_WIDTH == 8 -OP2(SLJIT_AND, reg, 0, reg, 0, SLJIT_IMM, 0xc0); -CMPTO(SLJIT_EQUAL, reg, 0, SLJIT_IMM, 0x80, label); -#elif PCRE2_CODE_UNIT_WIDTH == 16 -OP2(SLJIT_AND, reg, 0, reg, 0, SLJIT_IMM, 0xfc00); -CMPTO(SLJIT_EQUAL, reg, 0, SLJIT_IMM, 0xdc00, label); -#else -#error "Unknown code width" -#endif -} -#endif - -#include "pcre2_jit_simd_inc.h" - -#ifdef JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD - -static BOOL check_fast_forward_char_pair_simd(compiler_common *common, fast_forward_char_data *chars, int max) -{ - sljit_s32 i, j, max_i = 0, max_j = 0; - sljit_u32 max_pri = 0; - sljit_s32 max_offset = max_fast_forward_char_pair_offset(); - PCRE2_UCHAR a1, a2, a_pri, b1, b2, b_pri; - - for (i = max - 1; i >= 1; i--) - { - if (chars[i].last_count > 2) - { - a1 = chars[i].chars[0]; - a2 = chars[i].chars[1]; - a_pri = chars[i].last_count; - - j = i - max_offset; - if (j < 0) - j = 0; - - while (j < i) - { - b_pri = chars[j].last_count; - if (b_pri > 2 && (sljit_u32)a_pri + (sljit_u32)b_pri >= max_pri) - { - b1 = chars[j].chars[0]; - b2 = chars[j].chars[1]; - - if (a1 != b1 && a1 != b2 && a2 != b1 && a2 != b2) - { - max_pri = a_pri + b_pri; - max_i = i; - max_j = j; - } - } - j++; - } - } - } - -if (max_pri == 0) - return FALSE; - -fast_forward_char_pair_simd(common, max_i, chars[max_i].chars[0], chars[max_i].chars[1], max_j, chars[max_j].chars[0], chars[max_j].chars[1]); -return TRUE; -} - -#endif /* JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD */ - -static void fast_forward_first_char2(compiler_common *common, PCRE2_UCHAR char1, PCRE2_UCHAR char2, sljit_s32 offset) -{ -DEFINE_COMPILER; -struct sljit_label *start; -struct sljit_jump *match; -struct sljit_jump *partial_quit; -PCRE2_UCHAR mask; -BOOL has_match_end = (common->match_end_ptr != 0); - -SLJIT_ASSERT(common->mode == PCRE2_JIT_COMPLETE || offset == 0); - -if (has_match_end) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr); - -if (offset > 0) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offset)); - -if (has_match_end) - { - OP1(SLJIT_MOV, TMP3, 0, STR_END, 0); - - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(offset + 1)); - OP2U(SLJIT_SUB | SLJIT_SET_GREATER, STR_END, 0, TMP1, 0); - SELECT(SLJIT_GREATER, STR_END, TMP1, 0, STR_END); - } - -#ifdef JIT_HAS_FAST_FORWARD_CHAR_SIMD - -if (JIT_HAS_FAST_FORWARD_CHAR_SIMD) - { - fast_forward_char_simd(common, char1, char2, offset); - - if (offset > 0) - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offset)); - - if (has_match_end) - OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); - return; - } - -#endif - -start = LABEL(); - -partial_quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); -if (common->mode == PCRE2_JIT_COMPLETE) - add_jump(compiler, &common->failed_match, partial_quit); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -if (char1 == char2) - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, char1, start); -else - { - mask = char1 ^ char2; - if (is_powerof2(mask)) - { - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, mask); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, char1 | mask, start); - } - else - { - match = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, char1); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, char2, start); - JUMPHERE(match); - } - } - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -if (common->utf && offset > 0) - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-(offset + 1))); - jumpto_if_not_utf_char_start(compiler, TMP1, start); - } -#endif - -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offset + 1)); - -if (common->mode != PCRE2_JIT_COMPLETE) - JUMPHERE(partial_quit); - -if (has_match_end) - OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); -} - -static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_label *start; -struct sljit_jump *match; -fast_forward_char_data chars[MAX_N_CHARS]; -sljit_s32 offset; -PCRE2_UCHAR mask; -PCRE2_UCHAR *char_set, *char_set_end; -int i, max, from; -int range_right = -1, range_len; -sljit_u8 *update_table = NULL; -BOOL in_range; - -for (i = 0; i < MAX_N_CHARS; i++) - { - chars[i].count = 0; - chars[i].last_count = 0; - } - -max = scan_prefix(common, common->start, chars); - -if (max < 1) - return FALSE; - -/* Convert last_count to priority. */ -for (i = 0; i < max; i++) - { - SLJIT_ASSERT(chars[i].last_count <= chars[i].count); - - switch (chars[i].count) - { - case 0: - chars[i].count = 255; - chars[i].last_count = 0; - break; - - case 1: - chars[i].last_count = (chars[i].last_count == 1) ? 7 : 5; - /* Simplifies algorithms later. */ - chars[i].chars[1] = chars[i].chars[0]; - break; - - case 2: - SLJIT_ASSERT(chars[i].chars[0] != chars[i].chars[1]); - - if (is_powerof2(chars[i].chars[0] ^ chars[i].chars[1])) - chars[i].last_count = (chars[i].last_count == 2) ? 6 : 4; - else - chars[i].last_count = (chars[i].last_count == 2) ? 3 : 2; - break; - - default: - chars[i].last_count = (chars[i].count == 255) ? 0 : 1; - break; - } - } - -#ifdef JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD -if (JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD && check_fast_forward_char_pair_simd(common, chars, max)) - return TRUE; -#endif - -in_range = FALSE; -/* Prevent compiler "uninitialized" warning */ -from = 0; -range_len = 4 /* minimum length */ - 1; -for (i = 0; i <= max; i++) - { - if (in_range && (i - from) > range_len && (chars[i - 1].count < 255)) - { - range_len = i - from; - range_right = i - 1; - } - - if (i < max && chars[i].count < 255) - { - SLJIT_ASSERT(chars[i].count > 0); - if (!in_range) - { - in_range = TRUE; - from = i; - } - } - else - in_range = FALSE; - } - -if (range_right >= 0) - { - update_table = (sljit_u8 *)allocate_read_only_data(common, 256); - if (update_table == NULL) - return TRUE; - memset(update_table, IN_UCHARS(range_len), 256); - - for (i = 0; i < range_len; i++) - { - SLJIT_ASSERT(chars[range_right - i].count > 0 && chars[range_right - i].count < 255); - - char_set = chars[range_right - i].chars; - char_set_end = char_set + chars[range_right - i].count; - do - { - if (update_table[(*char_set) & 0xff] > IN_UCHARS(i)) - update_table[(*char_set) & 0xff] = IN_UCHARS(i); - char_set++; - } - while (char_set < char_set_end); - } - } - -offset = -1; -/* Scan forward. */ -for (i = 0; i < max; i++) - { - if (range_right == i) - continue; - - if (offset == -1) - { - if (chars[i].last_count >= 2) - offset = i; - } - else if (chars[offset].last_count < chars[i].last_count) - offset = i; - } - -SLJIT_ASSERT(offset == -1 || (chars[offset].count >= 1 && chars[offset].count <= 2)); - -if (range_right < 0) - { - if (offset < 0) - return FALSE; - /* Works regardless the value is 1 or 2. */ - fast_forward_first_char2(common, chars[offset].chars[0], chars[offset].chars[1], offset); - return TRUE; - } - -SLJIT_ASSERT(range_right != offset); - -if (common->match_end_ptr != 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr); - OP1(SLJIT_MOV, TMP3, 0, STR_END, 0); - OP2(SLJIT_SUB | SLJIT_SET_LESS, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max)); - add_jump(compiler, &common->failed_match, JUMP(SLJIT_LESS)); - OP2U(SLJIT_SUB | SLJIT_SET_GREATER, STR_END, 0, TMP1, 0); - SELECT(SLJIT_GREATER, STR_END, TMP1, 0, STR_END); - } -else - { - OP2(SLJIT_SUB | SLJIT_SET_LESS, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max)); - add_jump(compiler, &common->failed_match, JUMP(SLJIT_LESS)); - } - -SLJIT_ASSERT(range_right >= 0); - -if (!HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table); - -start = LABEL(); -add_jump(compiler, &common->failed_match, CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0)); - -#if PCRE2_CODE_UNIT_WIDTH == 8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN) -OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right)); -#else -OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1); -#endif - -if (!HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0); -else - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table); - -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); -CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start); - -if (offset >= 0) - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offset)); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - if (chars[offset].count == 1) - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[offset].chars[0], start); - else - { - mask = chars[offset].chars[0] ^ chars[offset].chars[1]; - if (is_powerof2(mask)) - { - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, mask); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[offset].chars[0] | mask, start); - } - else - { - match = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, chars[offset].chars[0]); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[offset].chars[1], start); - JUMPHERE(match); - } - } - } - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -if (common->utf && offset != 0) - { - if (offset < 0) - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - } - else - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); - - jumpto_if_not_utf_char_start(compiler, TMP1, start); - - if (offset < 0) - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - } -#endif - -if (offset >= 0) - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -if (common->match_end_ptr != 0) - OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); -else - OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max)); -return TRUE; -} - -static SLJIT_INLINE void fast_forward_first_char(compiler_common *common) -{ -PCRE2_UCHAR first_char = (PCRE2_UCHAR)(common->re->first_codeunit); -PCRE2_UCHAR oc; - -oc = first_char; -if ((common->re->flags & PCRE2_FIRSTCASELESS) != 0) - { - oc = TABLE_GET(first_char, common->fcc, first_char); -#if defined SUPPORT_UNICODE - if (first_char > 127 && (common->utf || common->ucp)) - oc = UCD_OTHERCASE(first_char); -#endif - } - -fast_forward_first_char2(common, first_char, oc, 0); -} - -static SLJIT_INLINE void fast_forward_newline(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_label *loop; -struct sljit_jump *lastchar = NULL; -struct sljit_jump *firstchar; -struct sljit_jump *quit = NULL; -struct sljit_jump *foundcr = NULL; -struct sljit_jump *notfoundnl; -jump_list *newline = NULL; - -if (common->match_end_ptr != 0) - { - OP1(SLJIT_MOV, TMP3, 0, STR_END, 0); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr); - } - -if (common->nltype == NLTYPE_FIXED && common->newline > 255) - { -#ifdef JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD - if (JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD && common->mode == PCRE2_JIT_COMPLETE) - { - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin)); - } - else - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, str)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - } - firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0); - - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2U(SLJIT_SUB | SLJIT_SET_Z, STR_PTR, 0, TMP1, 0); - OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_NOT_EQUAL); -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); - - fast_forward_char_pair_simd(common, 1, common->newline & 0xff, common->newline & 0xff, 0, (common->newline >> 8) & 0xff, (common->newline >> 8) & 0xff); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - } - else -#endif /* JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD */ - { - lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin)); - } - else - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, str)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - } - firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0); - - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2)); - OP2U(SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, STR_PTR, 0, TMP1, 0); - OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_GREATER_EQUAL); -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); - - loop = LABEL(); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop); - CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop); - - JUMPHERE(quit); - JUMPHERE(lastchar); - } - - JUMPHERE(firstchar); - - if (common->match_end_ptr != 0) - OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); - return; - } - -if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str)); - } -else - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, str)); - -/* Example: match /^/ to \r\n from offset 1. */ -firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0); - -if (common->nltype == NLTYPE_ANY) - move_back(common, NULL, FALSE); -else - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -loop = LABEL(); -common->ff_newline_shortcut = loop; - -#ifdef JIT_HAS_FAST_FORWARD_CHAR_SIMD -if (JIT_HAS_FAST_FORWARD_CHAR_SIMD && (common->nltype == NLTYPE_FIXED || common->nltype == NLTYPE_ANYCRLF)) - { - if (common->nltype == NLTYPE_ANYCRLF) - { - fast_forward_char_simd(common, CHAR_CR, CHAR_LF, 0); - if (common->mode != PCRE2_JIT_COMPLETE) - lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - quit = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR); - } - else - { - fast_forward_char_simd(common, common->newline, common->newline, 0); - - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - if (common->mode != PCRE2_JIT_COMPLETE) - { - OP2U(SLJIT_SUB | SLJIT_SET_GREATER, STR_PTR, 0, STR_END, 0); - SELECT(SLJIT_GREATER, STR_PTR, STR_END, 0, STR_PTR); - } - } - } -else -#endif /* JIT_HAS_FAST_FORWARD_CHAR_SIMD */ - { - read_char(common, common->nlmin, common->nlmax, NULL, READ_CHAR_NEWLINE); - lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF) - foundcr = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR); - check_newlinechar(common, common->nltype, &newline, FALSE); - set_jumps(newline, loop); - } - -if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF) - { - if (quit == NULL) - { - quit = JUMP(SLJIT_JUMP); - JUMPHERE(foundcr); - } - - notfoundnl = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_NL); - OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL); -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); - JUMPHERE(notfoundnl); - JUMPHERE(quit); - } - -if (lastchar) - JUMPHERE(lastchar); -JUMPHERE(firstchar); - -if (common->match_end_ptr != 0) - OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); -} - -static BOOL optimize_class(compiler_common *common, const sljit_u8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks); - -static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common) -{ -DEFINE_COMPILER; -const sljit_u8 *start_bits = common->re->start_bitmap; -struct sljit_label *start; -struct sljit_jump *partial_quit; -#if PCRE2_CODE_UNIT_WIDTH != 8 -struct sljit_jump *found = NULL; -#endif -jump_list *matches = NULL; - -if (common->match_end_ptr != 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr); - OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2U(SLJIT_SUB | SLJIT_SET_GREATER, STR_END, 0, TMP1, 0); - SELECT(SLJIT_GREATER, STR_END, TMP1, 0, STR_END); - } - -start = LABEL(); - -partial_quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); -if (common->mode == PCRE2_JIT_COMPLETE) - add_jump(compiler, &common->failed_match, partial_quit); - -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); -OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -if (!optimize_class(common, start_bits, (start_bits[31] & 0x80) != 0, FALSE, &matches)) - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - if ((start_bits[31] & 0x80) != 0) - found = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 255); - else - CMPTO(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 255, start); -#elif defined SUPPORT_UNICODE - if (common->utf && is_char7_bitset(start_bits, FALSE)) - CMPTO(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 127, start); -#endif - OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7); - OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3); - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits); - if (!HAS_VIRTUAL_REGISTERS) - { - OP2(SLJIT_SHL, TMP3, 0, SLJIT_IMM, 1, TMP2, 0); - OP2U(SLJIT_AND | SLJIT_SET_Z, TMP1, 0, TMP3, 0); - } - else - { - OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0); - OP2U(SLJIT_AND | SLJIT_SET_Z, TMP1, 0, TMP2, 0); - } - JUMPTO(SLJIT_ZERO, start); - } -else - set_jumps(matches, start); - -#if PCRE2_CODE_UNIT_WIDTH != 8 -if (found != NULL) - JUMPHERE(found); -#endif - -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -if (common->mode != PCRE2_JIT_COMPLETE) - JUMPHERE(partial_quit); - -if (common->match_end_ptr != 0) - OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0); -} - -static SLJIT_INLINE jump_list *search_requested_char(compiler_common *common, PCRE2_UCHAR req_char, BOOL caseless, BOOL has_firstchar) -{ -DEFINE_COMPILER; -struct sljit_label *loop; -struct sljit_jump *toolong; -struct sljit_jump *already_found; -struct sljit_jump *found; -struct sljit_jump *found_oc = NULL; -jump_list *not_found = NULL; -sljit_u32 oc, bit; - -SLJIT_ASSERT(common->req_char_ptr != 0); -OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(REQ_CU_MAX) * 100); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr); -toolong = CMP(SLJIT_LESS, TMP2, 0, STR_END, 0); -already_found = CMP(SLJIT_LESS, STR_PTR, 0, TMP1, 0); - -if (has_firstchar) - OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -else - OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0); - -oc = req_char; -if (caseless) - { - oc = TABLE_GET(req_char, common->fcc, req_char); -#if defined SUPPORT_UNICODE - if (req_char > 127 && (common->utf || common->ucp)) - oc = UCD_OTHERCASE(req_char); -#endif - } - -#ifdef JIT_HAS_FAST_REQUESTED_CHAR_SIMD -if (JIT_HAS_FAST_REQUESTED_CHAR_SIMD) - { - not_found = fast_requested_char_simd(common, req_char, oc); - } -else -#endif - { - loop = LABEL(); - add_jump(compiler, ¬_found, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, STR_END, 0)); - - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0); - - if (req_char == oc) - found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char); - else - { - bit = req_char ^ oc; - if (is_powerof2(bit)) - { - OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit); - found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit); - } - else - { - found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char); - found_oc = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, oc); - } - } - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); - JUMPTO(SLJIT_JUMP, loop); - - JUMPHERE(found); - if (found_oc) - JUMPHERE(found_oc); - } - -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr, TMP1, 0); - -JUMPHERE(already_found); -JUMPHERE(toolong); -return not_found; -} - -static void do_revertframes(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; -struct sljit_label *mainloop; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); -GET_LOCAL_BASE(TMP1, 0, 0); - -/* Drop frames until we reach STACK_TOP. */ -mainloop = LABEL(); -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), -SSIZE_OF(sw)); -OP2U(SLJIT_SUB | SLJIT_SET_SIG_LESS_EQUAL | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, 0); -jump = JUMP(SLJIT_SIG_LESS_EQUAL); - -OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0); -if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(STACK_TOP), -(2 * SSIZE_OF(sw))); - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(STACK_TOP), -(3 * SSIZE_OF(sw))); - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 3 * SSIZE_OF(sw)); - } -else - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), -(2 * SSIZE_OF(sw))); - OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(STACK_TOP), -(3 * SSIZE_OF(sw))); - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 3 * SSIZE_OF(sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, TMP1, 0); - GET_LOCAL_BASE(TMP1, 0, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP3, 0); - } -JUMPTO(SLJIT_JUMP, mainloop); - -JUMPHERE(jump); -sljit_set_current_flags(compiler, SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE | SLJIT_SET_SIG_LESS_EQUAL | SLJIT_SET_Z); -jump = JUMP(SLJIT_NOT_ZERO /* SIG_LESS */); -/* End of reverting values. */ -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); - -JUMPHERE(jump); -OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, TMP2, 0); -if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(STACK_TOP), -(2 * SSIZE_OF(sw))); - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2 * SSIZE_OF(sw)); - } -else - { - OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(STACK_TOP), -(2 * SSIZE_OF(sw))); - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2 * SSIZE_OF(sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, TMP3, 0); - } -JUMPTO(SLJIT_JUMP, mainloop); -} - -#ifdef SUPPORT_UNICODE -#define UCPCAT(bit) (1 << (bit)) -#define UCPCAT2(bit1, bit2) (UCPCAT(bit1) | UCPCAT(bit2)) -#define UCPCAT3(bit1, bit2, bit3) (UCPCAT(bit1) | UCPCAT(bit2) | UCPCAT(bit3)) -#define UCPCAT_RANGE(start, end) (((1 << ((end) + 1)) - 1) - ((1 << (start)) - 1)) -#define UCPCAT_L UCPCAT_RANGE(ucp_Ll, ucp_Lu) -#define UCPCAT_N UCPCAT_RANGE(ucp_Nd, ucp_No) -#define UCPCAT_ALL ((1 << (ucp_Zs + 1)) - 1) -#endif - -static void check_wordboundary(compiler_common *common, BOOL ucp) -{ -DEFINE_COMPILER; -struct sljit_jump *skipread; -jump_list *skipread_list = NULL; -#ifdef SUPPORT_UNICODE -struct sljit_label *valid_utf; -jump_list *invalid_utf1 = NULL; -#endif /* SUPPORT_UNICODE */ -jump_list *invalid_utf2 = NULL; -#if PCRE2_CODE_UNIT_WIDTH != 8 || defined SUPPORT_UNICODE -struct sljit_jump *jump; -#endif /* PCRE2_CODE_UNIT_WIDTH != 8 || SUPPORT_UNICODE */ - -SLJIT_UNUSED_ARG(ucp); -SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16); - -SLJIT_ASSERT(common->locals_size >= 2 * SSIZE_OF(sw)); -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, SLJIT_MEM1(SLJIT_SP), LOCAL0); -/* Get type of the previous char, and put it to TMP3. */ -OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin)); -OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0); -skipread = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0); - -#ifdef SUPPORT_UNICODE -if (common->invalid_utf) - { - peek_char_back(common, READ_CHAR_MAX, &invalid_utf1); - - if (common->mode != PCRE2_JIT_COMPLETE) - { - OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); - OP1(SLJIT_MOV, TMP2, 0, STR_PTR, 0); - move_back(common, NULL, TRUE); - check_start_used_ptr(common); - OP1(SLJIT_MOV, TMP1, 0, RETURN_ADDR, 0); - OP1(SLJIT_MOV, STR_PTR, 0, TMP2, 0); - } - } -else -#endif /* SUPPORT_UNICODE */ - { - if (common->mode == PCRE2_JIT_COMPLETE) - peek_char_back(common, READ_CHAR_MAX, NULL); - else - { - move_back(common, NULL, TRUE); - check_start_used_ptr(common); - read_char(common, 0, READ_CHAR_MAX, NULL, READ_CHAR_UPDATE_STR_PTR); - } - } - -/* Testing char type. */ -#ifdef SUPPORT_UNICODE -if (ucp) - { - add_jump(compiler, &common->getucdtype, JUMP(SLJIT_FAST_CALL)); - OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP1, 0); - OP2U(SLJIT_AND | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, UCPCAT2(ucp_Mn, ucp_Pc) | UCPCAT_L | UCPCAT_N); - OP_FLAGS(SLJIT_MOV, TMP3, 0, SLJIT_NOT_ZERO); - } -else -#endif /* SUPPORT_UNICODE */ - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255); -#elif defined SUPPORT_UNICODE - /* Here TMP3 has already been zeroed. */ - jump = NULL; - if (common->utf) - jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255); -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes); - OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */); - OP2(SLJIT_AND, TMP3, 0, TMP1, 0, SLJIT_IMM, 1); -#if PCRE2_CODE_UNIT_WIDTH != 8 - JUMPHERE(jump); -#elif defined SUPPORT_UNICODE - if (jump != NULL) - JUMPHERE(jump); -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - } -JUMPHERE(skipread); - -OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0); -check_str_end(common, &skipread_list); -peek_char(common, READ_CHAR_MAX, SLJIT_MEM1(SLJIT_SP), LOCAL1, &invalid_utf2); - -/* Testing char type. This is a code duplication. */ -#ifdef SUPPORT_UNICODE - -valid_utf = LABEL(); - -if (ucp) - { - add_jump(compiler, &common->getucdtype, JUMP(SLJIT_FAST_CALL)); - OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP1, 0); - OP2U(SLJIT_AND | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, UCPCAT2(ucp_Mn, ucp_Pc) | UCPCAT_L | UCPCAT_N); - OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_NOT_ZERO); - } -else -#endif /* SUPPORT_UNICODE */ - { -#if PCRE2_CODE_UNIT_WIDTH != 8 - /* TMP2 may be destroyed by peek_char. */ - OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0); - jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255); -#elif defined SUPPORT_UNICODE - OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0); - jump = NULL; - if (common->utf) - jump = CMP(SLJIT_GREATER, TMP1, 0, SLJIT_IMM, 255); -#endif - OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes); - OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */); - OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1); -#if PCRE2_CODE_UNIT_WIDTH != 8 - JUMPHERE(jump); -#elif defined SUPPORT_UNICODE - if (jump != NULL) - JUMPHERE(jump); -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ - } -set_jumps(skipread_list, LABEL()); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); -OP2(SLJIT_XOR | SLJIT_SET_Z, TMP2, 0, TMP2, 0, TMP3, 0); -OP_SRC(SLJIT_FAST_RETURN, TMP1, 0); - -#ifdef SUPPORT_UNICODE -if (common->invalid_utf) - { - set_jumps(invalid_utf1, LABEL()); - - peek_char(common, READ_CHAR_MAX, SLJIT_MEM1(SLJIT_SP), LOCAL1, NULL); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, INVALID_UTF_CHAR, valid_utf); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, -1); - OP_SRC(SLJIT_FAST_RETURN, TMP1, 0); - - set_jumps(invalid_utf2, LABEL()); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - OP1(SLJIT_MOV, TMP2, 0, TMP3, 0); - OP_SRC(SLJIT_FAST_RETURN, TMP1, 0); - } -#endif /* SUPPORT_UNICODE */ -} - -static BOOL optimize_class_ranges(compiler_common *common, const sljit_u8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks) -{ -/* May destroy TMP1. */ -DEFINE_COMPILER; -int ranges[MAX_CLASS_RANGE_SIZE]; -sljit_u8 bit, cbit, all; -int i, byte, length = 0; - -bit = bits[0] & 0x1; -/* All bits will be zero or one (since bit is zero or one). */ -all = (sljit_u8)-bit; - -for (i = 0; i < 256; ) - { - byte = i >> 3; - if ((i & 0x7) == 0 && bits[byte] == all) - i += 8; - else - { - cbit = (bits[byte] >> (i & 0x7)) & 0x1; - if (cbit != bit) - { - if (length >= MAX_CLASS_RANGE_SIZE) - return FALSE; - ranges[length] = i; - length++; - bit = cbit; - all = (sljit_u8)-cbit; /* sign extend bit into byte */ - } - i++; - } - } - -if (((bit == 0) && nclass) || ((bit == 1) && !nclass)) - { - if (length >= MAX_CLASS_RANGE_SIZE) - return FALSE; - ranges[length] = 256; - length++; - } - -if (length < 0 || length > 4) - return FALSE; - -bit = bits[0] & 0x1; -if (invert) bit ^= 0x1; - -/* No character is accepted. */ -if (length == 0 && bit == 0) - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - -switch(length) - { - case 0: - /* When bit != 0, all characters are accepted. */ - return TRUE; - - case 1: - add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_LESS : SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0])); - return TRUE; - - case 2: - if (ranges[0] + 1 != ranges[1]) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]); - add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_LESS : SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0])); - } - else - add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0])); - return TRUE; - - case 3: - if (bit != 0) - { - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2])); - if (ranges[0] + 1 != ranges[1]) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0])); - } - else - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0])); - return TRUE; - } - - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[0])); - if (ranges[1] + 1 != ranges[2]) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1])); - } - else - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1])); - return TRUE; - - case 4: - if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2]) - && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2] - && (ranges[1] & (ranges[2] - ranges[0])) == 0 - && is_powerof2(ranges[2] - ranges[0])) - { - SLJIT_ASSERT((ranges[0] & (ranges[2] - ranges[0])) == 0 && (ranges[2] & ranges[3] & (ranges[2] - ranges[0])) != 0); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]); - if (ranges[2] + 1 != ranges[3]) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]); - add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_LESS : SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2])); - } - else - add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2])); - return TRUE; - } - - if (bit != 0) - { - i = 0; - if (ranges[0] + 1 != ranges[1]) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0])); - i = ranges[0]; - } - else - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0])); - - if (ranges[2] + 1 != ranges[3]) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2])); - } - else - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i)); - return TRUE; - } - - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0])); - if (ranges[1] + 1 != ranges[2]) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1])); - } - else - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0])); - return TRUE; - - default: - SLJIT_UNREACHABLE(); - return FALSE; - } -} - -static BOOL optimize_class_chars(compiler_common *common, const sljit_u8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks) -{ -/* May destroy TMP1. */ -DEFINE_COMPILER; -uint16_t char_list[MAX_CLASS_CHARS_SIZE]; -uint8_t byte; -sljit_s32 type; -int i, j, k, len, c; - -if (!sljit_has_cpu_feature(SLJIT_HAS_CMOV)) - return FALSE; - -len = 0; - -for (i = 0; i < 32; i++) - { - byte = bits[i]; - - if (nclass) - byte = (sljit_u8)~byte; - - j = 0; - while (byte != 0) - { - if (byte & 0x1) - { - c = i * 8 + j; - - k = len; - - if ((c & 0x20) != 0) - { - for (k = 0; k < len; k++) - if (char_list[k] == c - 0x20) - { - char_list[k] |= 0x120; - break; - } - } - - if (k == len) - { - if (len >= MAX_CLASS_CHARS_SIZE) - return FALSE; - - char_list[len++] = (uint16_t) c; - } - } - - byte >>= 1; - j++; - } - } - -if (len == 0) return FALSE; /* Should never occur, but stops analyzers complaining. */ - -i = 0; -j = 0; - -if (char_list[0] == 0) - { - i++; - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0); - OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_ZERO); - } -else - OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0); - -while (i < len) - { - if ((char_list[i] & 0x100) != 0) - j++; - else - { - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, char_list[i]); - SELECT(SLJIT_ZERO, TMP2, TMP1, 0, TMP2); - } - i++; - } - -if (j != 0) - { - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x20); - - for (i = 0; i < len; i++) - if ((char_list[i] & 0x100) != 0) - { - j--; - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, char_list[i] & 0xff); - SELECT(SLJIT_ZERO, TMP2, TMP1, 0, TMP2); - } - } - -if (invert) - nclass = !nclass; - -type = nclass ? SLJIT_NOT_EQUAL : SLJIT_EQUAL; -add_jump(compiler, backtracks, CMP(type, TMP2, 0, SLJIT_IMM, 0)); -return TRUE; -} - -static BOOL optimize_class(compiler_common *common, const sljit_u8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks) -{ -/* May destroy TMP1. */ -if (optimize_class_ranges(common, bits, nclass, invert, backtracks)) - return TRUE; -return optimize_class_chars(common, bits, nclass, invert, backtracks); -} - -static void check_anynewline(compiler_common *common) -{ -/* Check whether TMP1 contains a newline character. TMP2 destroyed. */ -DEFINE_COMPILER; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a); -OP2U(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a); -OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utf) - { -#endif - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a); -#if PCRE2_CODE_UNIT_WIDTH == 8 - } -#endif -#endif /* SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == [16|32] */ -OP_FLAGS(SLJIT_OR | SLJIT_SET_Z, TMP2, 0, SLJIT_EQUAL); -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void check_hspace(compiler_common *common) -{ -/* Check whether TMP1 contains a newline character. TMP2 destroyed. */ -DEFINE_COMPILER; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x09); -OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x20); -OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0xa0); -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utf) - { -#endif - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x1680); - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x180e); - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000); - OP2U(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000); - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_LESS_EQUAL); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000); - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000); - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000); -#if PCRE2_CODE_UNIT_WIDTH == 8 - } -#endif -#endif /* SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == [16|32] */ -OP_FLAGS(SLJIT_OR | SLJIT_SET_Z, TMP2, 0, SLJIT_EQUAL); - -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void check_vspace(compiler_common *common) -{ -/* Check whether TMP1 contains a newline character. TMP2 destroyed. */ -DEFINE_COMPILER; - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); - -OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a); -OP2U(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a); -OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utf) - { -#endif - OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a); -#if PCRE2_CODE_UNIT_WIDTH == 8 - } -#endif -#endif /* SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == [16|32] */ -OP_FLAGS(SLJIT_OR | SLJIT_SET_Z, TMP2, 0, SLJIT_EQUAL); - -OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); -} - -static void do_casefulcmp(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; -struct sljit_label *label; -int char1_reg; -int char2_reg; - -if (HAS_VIRTUAL_REGISTERS) - { - char1_reg = STR_END; - char2_reg = STACK_TOP; - } -else - { - char1_reg = TMP3; - char2_reg = RETURN_ADDR; - } - -/* Update ref_update_local_size() when this changes. */ -SLJIT_ASSERT(common->locals_size >= SSIZE_OF(sw)); -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, SLJIT_MEM1(SLJIT_SP), LOCAL0); -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); - -if (char1_reg == STR_END) - { - OP1(SLJIT_MOV, TMP3, 0, char1_reg, 0); - OP1(SLJIT_MOV, RETURN_ADDR, 0, char2_reg, 0); - } - -if (sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) - { - label = LABEL(); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_POST, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); - JUMPTO(SLJIT_NOT_ZERO, label); - - JUMPHERE(jump); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - } -else if (sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - label = LABEL(); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); - JUMPTO(SLJIT_NOT_ZERO, label); - - JUMPHERE(jump); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - } -else - { - label = LABEL(); - OP1(MOV_UCHAR, char1_reg, 0, SLJIT_MEM1(TMP1), 0); - OP1(MOV_UCHAR, char2_reg, 0, SLJIT_MEM1(STR_PTR), 0); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); - JUMPTO(SLJIT_NOT_ZERO, label); - - JUMPHERE(jump); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - } - -if (char1_reg == STR_END) - { - OP1(SLJIT_MOV, char1_reg, 0, TMP3, 0); - OP1(SLJIT_MOV, char2_reg, 0, RETURN_ADDR, 0); - } - -OP_SRC(SLJIT_FAST_RETURN, TMP1, 0); -} - -static void do_caselesscmp(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; -struct sljit_label *label; -int char1_reg = STR_END; -int char2_reg; -int lcc_table; -int opt_type = 0; - -if (HAS_VIRTUAL_REGISTERS) - { - char2_reg = STACK_TOP; - lcc_table = STACK_LIMIT; - } -else - { - char2_reg = RETURN_ADDR; - lcc_table = TMP3; - } - -if (sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) - opt_type = 1; -else if (sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)) == SLJIT_SUCCESS) - opt_type = 2; - -/* Update ref_update_local_size() when this changes. */ -SLJIT_ASSERT(common->locals_size >= 2 * SSIZE_OF(sw)); -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, SLJIT_MEM1(SLJIT_SP), LOCAL0); -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); - -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL1, char1_reg, 0); - -if (char2_reg == STACK_TOP) - { - OP1(SLJIT_MOV, TMP3, 0, char2_reg, 0); - OP1(SLJIT_MOV, RETURN_ADDR, 0, lcc_table, 0); - } - -OP1(SLJIT_MOV, lcc_table, 0, SLJIT_IMM, common->lcc); - -if (opt_type == 1) - { - label = LABEL(); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_POST, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_POST, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - } -else if (opt_type == 2) - { - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - label = LABEL(); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char1_reg, SLJIT_MEM1(TMP1), IN_UCHARS(1)); - sljit_emit_mem_update(compiler, MOV_UCHAR | SLJIT_MEM_PRE, char2_reg, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - } -else - { - label = LABEL(); - OP1(MOV_UCHAR, char1_reg, 0, SLJIT_MEM1(TMP1), 0); - OP1(MOV_UCHAR, char2_reg, 0, SLJIT_MEM1(STR_PTR), 0); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1)); - } - -#if PCRE2_CODE_UNIT_WIDTH != 8 -jump = CMP(SLJIT_GREATER, char1_reg, 0, SLJIT_IMM, 255); -#endif -OP1(SLJIT_MOV_U8, char1_reg, 0, SLJIT_MEM2(lcc_table, char1_reg), 0); -#if PCRE2_CODE_UNIT_WIDTH != 8 -JUMPHERE(jump); -jump = CMP(SLJIT_GREATER, char2_reg, 0, SLJIT_IMM, 255); -#endif -OP1(SLJIT_MOV_U8, char2_reg, 0, SLJIT_MEM2(lcc_table, char2_reg), 0); -#if PCRE2_CODE_UNIT_WIDTH != 8 -JUMPHERE(jump); -#endif - -if (opt_type == 0) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -jump = CMP(SLJIT_NOT_EQUAL, char1_reg, 0, char2_reg, 0); -OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); -JUMPTO(SLJIT_NOT_ZERO, label); - -JUMPHERE(jump); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - -if (opt_type == 2) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - -if (char2_reg == STACK_TOP) - { - OP1(SLJIT_MOV, char2_reg, 0, TMP3, 0); - OP1(SLJIT_MOV, lcc_table, 0, RETURN_ADDR, 0); - } - -OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL1); -OP_SRC(SLJIT_FAST_RETURN, TMP1, 0); -} - -#include "pcre2_jit_char_inc.h" - -static PCRE2_SPTR compile_simple_assertion_matchingpath(compiler_common *common, PCRE2_UCHAR type, PCRE2_SPTR cc, jump_list **backtracks) -{ -DEFINE_COMPILER; -struct sljit_jump *jump[4]; - -switch(type) - { - case OP_SOD: - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin)); - } - else - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, TMP1, 0)); - return cc; - - case OP_SOM: - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str)); - } - else - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, str)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, TMP1, 0)); - return cc; - - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - add_jump(compiler, (type == OP_NOT_WORD_BOUNDARY || type == OP_WORD_BOUNDARY) ? &common->wordboundary : &common->ucp_wordboundary, JUMP(SLJIT_FAST_CALL)); -#ifdef SUPPORT_UNICODE - if (common->invalid_utf) - { - add_jump(compiler, backtracks, CMP((type == OP_NOT_WORD_BOUNDARY || type == OP_NOT_UCP_WORD_BOUNDARY) ? SLJIT_NOT_EQUAL : SLJIT_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, 0)); - return cc; - } -#endif /* SUPPORT_UNICODE */ - sljit_set_current_flags(compiler, SLJIT_SET_Z); - add_jump(compiler, backtracks, JUMP((type == OP_NOT_WORD_BOUNDARY || type == OP_NOT_UCP_WORD_BOUNDARY) ? SLJIT_NOT_ZERO : SLJIT_ZERO)); - return cc; - - case OP_EODN: - /* Requires rather complex checks. */ - jump[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - if (common->nltype == NLTYPE_FIXED && common->newline > 255) - { - OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - if (common->mode == PCRE2_JIT_COMPLETE) - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP2, 0, STR_END, 0)); - else - { - jump[1] = CMP(SLJIT_EQUAL, TMP2, 0, STR_END, 0); - OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP2, 0, STR_END, 0); - OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS); - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff); - OP_FLAGS(SLJIT_OR | SLJIT_SET_Z, TMP2, 0, SLJIT_NOT_EQUAL); - add_jump(compiler, backtracks, JUMP(SLJIT_NOT_EQUAL)); - check_partial(common, TRUE); - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - JUMPHERE(jump[1]); - } - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff)); - } - else if (common->nltype == NLTYPE_FIXED) - { - OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP2, 0, STR_END, 0)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline)); - } - else - { - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - jump[1] = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR); - OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - OP2U(SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_GREATER, TMP2, 0, STR_END, 0); - jump[2] = JUMP(SLJIT_GREATER); - add_jump(compiler, backtracks, JUMP(SLJIT_NOT_EQUAL) /* LESS */); - /* Equal. */ - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - jump[3] = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL); - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - - JUMPHERE(jump[1]); - if (common->nltype == NLTYPE_ANYCRLF) - { - OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP2, 0, STR_END, 0)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL)); - } - else - { - OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); - read_char(common, common->nlmin, common->nlmax, backtracks, READ_CHAR_UPDATE_STR_PTR); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, STR_END, 0)); - add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL)); - sljit_set_current_flags(compiler, SLJIT_SET_Z); - add_jump(compiler, backtracks, JUMP(SLJIT_ZERO)); - OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); - } - JUMPHERE(jump[2]); - JUMPHERE(jump[3]); - } - JUMPHERE(jump[0]); - if (common->mode != PCRE2_JIT_COMPLETE) - check_partial(common, TRUE); - return cc; - - case OP_EOD: - add_jump(compiler, backtracks, CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0)); - if (common->mode != PCRE2_JIT_COMPLETE) - check_partial(common, TRUE); - return cc; - - case OP_DOLL: - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0); - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTEOL); - } - else - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTEOL); - add_jump(compiler, backtracks, JUMP(SLJIT_NOT_ZERO)); - - if (!common->endonly) - compile_simple_assertion_matchingpath(common, OP_EODN, cc, backtracks); - else - { - add_jump(compiler, backtracks, CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0)); - check_partial(common, FALSE); - } - return cc; - - case OP_DOLLM: - jump[1] = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0); - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0); - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTEOL); - } - else - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTEOL); - add_jump(compiler, backtracks, JUMP(SLJIT_NOT_ZERO)); - check_partial(common, FALSE); - jump[0] = JUMP(SLJIT_JUMP); - JUMPHERE(jump[1]); - - if (common->nltype == NLTYPE_FIXED && common->newline > 255) - { - OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - if (common->mode == PCRE2_JIT_COMPLETE) - add_jump(compiler, backtracks, CMP(SLJIT_GREATER, TMP2, 0, STR_END, 0)); - else - { - jump[1] = CMP(SLJIT_LESS_EQUAL, TMP2, 0, STR_END, 0); - /* STR_PTR = STR_END - IN_UCHARS(1) */ - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff)); - check_partial(common, TRUE); - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - JUMPHERE(jump[1]); - } - - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff)); - } - else - { - peek_char(common, common->nlmax, TMP3, 0, NULL); - check_newlinechar(common, common->nltype, backtracks, FALSE); - } - JUMPHERE(jump[0]); - return cc; - - case OP_CIRC: - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin)); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER, STR_PTR, 0, TMP1, 0)); - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTBOL); - add_jump(compiler, backtracks, JUMP(SLJIT_NOT_ZERO)); - } - else - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - add_jump(compiler, backtracks, CMP(SLJIT_GREATER, STR_PTR, 0, TMP1, 0)); - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTBOL); - add_jump(compiler, backtracks, JUMP(SLJIT_NOT_ZERO)); - } - return cc; - - case OP_CIRCM: - /* TMP2 might be used by peek_char_back. */ - if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin)); - jump[1] = CMP(SLJIT_GREATER, STR_PTR, 0, TMP2, 0); - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTBOL); - } - else - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - jump[1] = CMP(SLJIT_GREATER, STR_PTR, 0, TMP2, 0); - OP2U(SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, options), SLJIT_IMM, PCRE2_NOTBOL); - } - add_jump(compiler, backtracks, JUMP(SLJIT_NOT_ZERO)); - jump[0] = JUMP(SLJIT_JUMP); - JUMPHERE(jump[1]); - - if (!common->alt_circumflex) - add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); - - if (common->nltype == NLTYPE_FIXED && common->newline > 255) - { - OP2(SLJIT_SUB, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); - add_jump(compiler, backtracks, CMP(SLJIT_LESS, TMP1, 0, TMP2, 0)); - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); - OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff)); - } - else - { - peek_char_back(common, common->nlmax, backtracks); - check_newlinechar(common, common->nltype, backtracks, FALSE); - } - JUMPHERE(jump[0]); - return cc; - } -SLJIT_UNREACHABLE(); -return cc; -} - -/* Forward definitions. */ -static void compile_matchingpath(compiler_common *, PCRE2_SPTR, PCRE2_SPTR, backtrack_common *); -static void compile_backtrackingpath(compiler_common *, struct backtrack_common *); - -#define PUSH_BACKTRACK(size, ccstart, error) \ - do \ - { \ - backtrack = sljit_alloc_memory(compiler, (size)); \ - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \ - return error; \ - memset(backtrack, 0, size); \ - backtrack->prev = parent->top; \ - backtrack->cc = (ccstart); \ - parent->top = backtrack; \ - } \ - while (0) - -#define PUSH_BACKTRACK_NOVALUE(size, ccstart) \ - do \ - { \ - backtrack = sljit_alloc_memory(compiler, (size)); \ - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \ - return; \ - memset(backtrack, 0, size); \ - backtrack->prev = parent->top; \ - backtrack->cc = (ccstart); \ - parent->top = backtrack; \ - } \ - while (0) - -#define BACKTRACK_AS(type) ((type *)backtrack) - -static void compile_dnref_search(compiler_common *common, PCRE2_SPTR cc, jump_list **backtracks) -{ -/* The OVECTOR offset goes to TMP2. */ -DEFINE_COMPILER; -int count = GET2(cc, 1 + IMM2_SIZE); -PCRE2_SPTR slot = common->name_table + GET2(cc, 1) * common->name_entry_size; -unsigned int offset; -jump_list *found = NULL; - -SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); - -count--; -while (count-- > 0) - { - offset = GET2(slot, 0) << 1; - GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset)); - add_jump(compiler, &found, CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0)); - slot += common->name_entry_size; - } - -offset = GET2(slot, 0) << 1; -GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset)); -if (backtracks != NULL && !common->unset_backref) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0)); - -set_jumps(found, LABEL()); -} - -static void compile_ref_matchingpath(compiler_common *common, PCRE2_SPTR cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail) -{ -DEFINE_COMPILER; -BOOL ref = (*cc == OP_REF || *cc == OP_REFI); -int offset = 0; -struct sljit_jump *jump = NULL; -struct sljit_jump *partial; -struct sljit_jump *nopartial; -#if defined SUPPORT_UNICODE -struct sljit_label *loop; -struct sljit_label *caseless_loop; -struct sljit_jump *turkish_ascii_i = NULL; -struct sljit_jump *turkish_non_ascii_i = NULL; -jump_list *no_match = NULL; -int source_reg = COUNT_MATCH; -int source_end_reg = ARGUMENTS; -int char1_reg = STACK_LIMIT; -PCRE2_UCHAR refi_flag = 0; - -if (*cc == OP_REFI || *cc == OP_DNREFI) - refi_flag = cc[PRIV(OP_lengths)[*cc] - 1]; -#endif /* SUPPORT_UNICODE */ - -if (ref) - { - offset = GET2(cc, 1) << 1; - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); - /* OVECTOR(1) contains the "string begin - 1" constant. */ - if (withchecks && !common->unset_backref) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1))); - } -else - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0); - -#if defined SUPPORT_UNICODE -if ((common->utf || common->ucp) && (*cc == OP_REFI || *cc == OP_DNREFI)) - { - /* Update ref_update_local_size() when this changes. */ - SLJIT_ASSERT(common->locals_size >= 3 * SSIZE_OF(sw)); - - if (ref) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - else - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); - - if (withchecks && emptyfail) - add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, TMP2, 0)); - - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL0, source_reg, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL1, source_end_reg, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL2, char1_reg, 0); - - OP1(SLJIT_MOV, source_reg, 0, TMP1, 0); - OP1(SLJIT_MOV, source_end_reg, 0, TMP2, 0); - - loop = LABEL(); - jump = CMP(SLJIT_GREATER_EQUAL, source_reg, 0, source_end_reg, 0); - partial = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); - - /* Read original character. It must be a valid UTF character. */ - OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); - OP1(SLJIT_MOV, STR_PTR, 0, source_reg, 0); - - read_char(common, 0, READ_CHAR_MAX, NULL, READ_CHAR_UPDATE_STR_PTR | READ_CHAR_VALID_UTF); - - OP1(SLJIT_MOV, source_reg, 0, STR_PTR, 0); - OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); - OP1(SLJIT_MOV, char1_reg, 0, TMP1, 0); - - /* Read second character. */ - read_char(common, 0, READ_CHAR_MAX, &no_match, READ_CHAR_UPDATE_STR_PTR); - - CMPTO(SLJIT_EQUAL, TMP1, 0, char1_reg, 0, loop); - - if ((refi_flag & (REFI_FLAG_TURKISH_CASING|REFI_FLAG_CASELESS_RESTRICT)) == - REFI_FLAG_TURKISH_CASING) - { - OP2(SLJIT_OR, SLJIT_TMP_DEST_REG, 0, char1_reg, 0, SLJIT_IMM, 0x20); - turkish_ascii_i = CMP(SLJIT_EQUAL, SLJIT_TMP_DEST_REG, 0, SLJIT_IMM, 0x69); - - OP2(SLJIT_OR, SLJIT_TMP_DEST_REG, 0, char1_reg, 0, SLJIT_IMM, 0x1); - turkish_non_ascii_i = CMP(SLJIT_EQUAL, SLJIT_TMP_DEST_REG, 0, SLJIT_IMM, 0x131); - } - - OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); - - add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL)); - - OP2(SLJIT_SHL, TMP1, 0, TMP2, 0, SLJIT_IMM, 2); - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0); - - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records)); - - OP1(SLJIT_MOV_S32, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(ucd_record, other_case)); - OP1(SLJIT_MOV_U8, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(ucd_record, caseset)); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP3, 0); - CMPTO(SLJIT_EQUAL, TMP1, 0, char1_reg, 0, loop); - - add_jump(compiler, &no_match, CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, 0)); - OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 2); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_caseless_sets)); - - if (refi_flag & REFI_FLAG_CASELESS_RESTRICT) - add_jump(compiler, &no_match, CMP(SLJIT_LESS | SLJIT_32, SLJIT_MEM1(TMP2), 0, SLJIT_IMM, 128)); - - caseless_loop = LABEL(); - OP1(SLJIT_MOV_U32, TMP1, 0, SLJIT_MEM1(TMP2), 0); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, sizeof(uint32_t)); - OP2U(SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, TMP1, 0, char1_reg, 0); - JUMPTO(SLJIT_EQUAL, loop); - JUMPTO(SLJIT_LESS, caseless_loop); - - if ((refi_flag & (REFI_FLAG_TURKISH_CASING|REFI_FLAG_CASELESS_RESTRICT)) == - REFI_FLAG_TURKISH_CASING) - { - add_jump(compiler, &no_match, JUMP(SLJIT_JUMP)); - JUMPHERE(turkish_ascii_i); - - OP2(SLJIT_LSHR, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 5); - OP2(SLJIT_AND, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 1); - OP2(SLJIT_XOR, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 1); - OP2(SLJIT_ADD, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 0x130); - CMPTO(SLJIT_EQUAL, TMP1, 0, char1_reg, 0, loop); - - add_jump(compiler, &no_match, JUMP(SLJIT_JUMP)); - JUMPHERE(turkish_non_ascii_i); - - OP2(SLJIT_AND, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 1); - OP2(SLJIT_XOR, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 1); - OP2(SLJIT_SHL, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 5); - OP2(SLJIT_ADD, char1_reg, 0, char1_reg, 0, SLJIT_IMM, 0x49); - CMPTO(SLJIT_EQUAL, TMP1, 0, char1_reg, 0, loop); - } - - set_jumps(no_match, LABEL()); - if (common->mode == PCRE2_JIT_COMPLETE) - JUMPHERE(partial); - - OP1(SLJIT_MOV, source_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - OP1(SLJIT_MOV, source_end_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL1); - OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL2); - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - - if (common->mode != PCRE2_JIT_COMPLETE) - { - JUMPHERE(partial); - OP1(SLJIT_MOV, source_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - OP1(SLJIT_MOV, source_end_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL1); - OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL2); - - check_partial(common, FALSE); - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - } - - JUMPHERE(jump); - OP1(SLJIT_MOV, source_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); - OP1(SLJIT_MOV, source_end_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL1); - OP1(SLJIT_MOV, char1_reg, 0, SLJIT_MEM1(SLJIT_SP), LOCAL2); - return; - } -else -#endif /* SUPPORT_UNICODE */ - { - if (ref) - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP1, 0); - else - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0); - - if (withchecks) - jump = JUMP(SLJIT_ZERO); - - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); - partial = CMP(SLJIT_GREATER, STR_PTR, 0, STR_END, 0); - if (common->mode == PCRE2_JIT_COMPLETE) - add_jump(compiler, backtracks, partial); - - add_jump(compiler, (*cc == OP_REF || *cc == OP_DNREF) ? &common->casefulcmp : &common->caselesscmp, JUMP(SLJIT_FAST_CALL)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0)); - - if (common->mode != PCRE2_JIT_COMPLETE) - { - nopartial = JUMP(SLJIT_JUMP); - JUMPHERE(partial); - /* TMP2 -= STR_END - STR_PTR */ - OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, STR_PTR, 0); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, STR_END, 0); - partial = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, 0); - OP1(SLJIT_MOV, STR_PTR, 0, STR_END, 0); - add_jump(compiler, (*cc == OP_REF || *cc == OP_DNREF) ? &common->casefulcmp : &common->caselesscmp, JUMP(SLJIT_FAST_CALL)); - add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0)); - JUMPHERE(partial); - check_partial(common, FALSE); - add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); - JUMPHERE(nopartial); - } - } - -if (jump != NULL) - { - if (emptyfail) - add_jump(compiler, backtracks, jump); - else - JUMPHERE(jump); - } -} - -static SLJIT_INLINE PCRE2_SPTR compile_ref_iterator_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -BOOL ref = (*cc == OP_REF || *cc == OP_REFI); -backtrack_common *backtrack; -PCRE2_UCHAR type; -int local_start = LOCAL2; -int offset = 0; -struct sljit_label *label; -struct sljit_jump *zerolength; -struct sljit_jump *jump = NULL; -PCRE2_SPTR ccbegin = cc; -int min = 0, max = 0; -BOOL minimize; - -PUSH_BACKTRACK(sizeof(ref_iterator_backtrack), cc, NULL); - -if (ref) - offset = GET2(cc, 1) << 1; -else - cc += IMM2_SIZE; - -if (*ccbegin == OP_REFI || *ccbegin == OP_DNREFI) - { - cc += 1; -#ifdef SUPPORT_UNICODE - if (common->utf || common->ucp) - local_start = LOCAL3; -#endif - } - -type = cc[1 + IMM2_SIZE]; - -SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even); -/* Update ref_update_local_size() when this changes. */ -SLJIT_ASSERT(local_start + 2 * SSIZE_OF(sw) <= (int)LOCAL0 + common->locals_size); -minimize = (type & 0x1) != 0; -switch(type) - { - case OP_CRSTAR: - case OP_CRMINSTAR: - min = 0; - max = 0; - cc += 1 + IMM2_SIZE + 1; - break; - case OP_CRPLUS: - case OP_CRMINPLUS: - min = 1; - max = 0; - cc += 1 + IMM2_SIZE + 1; - break; - case OP_CRQUERY: - case OP_CRMINQUERY: - min = 0; - max = 1; - cc += 1 + IMM2_SIZE + 1; - break; - case OP_CRRANGE: - case OP_CRMINRANGE: - min = GET2(cc, 1 + IMM2_SIZE + 1); - max = GET2(cc, 1 + IMM2_SIZE + 1 + IMM2_SIZE); - cc += 1 + IMM2_SIZE + 1 + 2 * IMM2_SIZE; - break; - default: - SLJIT_UNREACHABLE(); - break; - } - -if (!minimize) - { - if (min == 0) - { - allocate_stack(common, 2); - if (ref) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0); - /* Temporary release of STR_PTR. */ - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw)); - /* Handles both invalid and empty cases. Since the minimum repeat, - is zero the invalid case is basically the same as an empty case. */ - if (ref) - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - else - { - compile_dnref_search(common, ccbegin, NULL); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), local_start + SSIZE_OF(sw), TMP2, 0); - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); - } - /* Restore if not zero length. */ - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw)); - } - else - { - allocate_stack(common, 1); - if (ref) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - - if (ref) - { - if (!common->unset_backref) - add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1))); - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - } - else - { - compile_dnref_search(common, ccbegin, &backtrack->own_backtracks); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), local_start + SSIZE_OF(sw), TMP2, 0); - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); - } - } - - if (min > 1 || max > 1) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), local_start, SLJIT_IMM, 0); - - label = LABEL(); - if (!ref) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), local_start + SSIZE_OF(sw)); - compile_ref_matchingpath(common, ccbegin, &backtrack->own_backtracks, FALSE, FALSE); - - if (min > 1 || max > 1) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), local_start); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), local_start, TMP1, 0); - if (min > 1) - CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, min, label); - if (max > 1) - { - jump = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max); - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - JUMPTO(SLJIT_JUMP, label); - JUMPHERE(jump); - } - } - - if (max == 0) - { - /* Includes min > 1 case as well. */ - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - JUMPTO(SLJIT_JUMP, label); - } - - JUMPHERE(zerolength); - BACKTRACK_AS(ref_iterator_backtrack)->matchingpath = LABEL(); - - count_match(common); - return cc; - } - -allocate_stack(common, ref ? 2 : 3); -if (ref) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); -if (type != OP_CRMINSTAR) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0); - -if (min == 0) - { - /* Handles both invalid and empty cases. Since the minimum repeat, - is zero the invalid case is basically the same as an empty case. */ - if (ref) - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - else - { - compile_dnref_search(common, ccbegin, NULL); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0); - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); - } - /* Length is non-zero, we can match real repeats. */ - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - jump = JUMP(SLJIT_JUMP); - } -else - { - if (ref) - { - if (!common->unset_backref) - add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1))); - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - } - else - { - compile_dnref_search(common, ccbegin, &backtrack->own_backtracks); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0); - zerolength = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); - } - } - -BACKTRACK_AS(ref_iterator_backtrack)->matchingpath = LABEL(); -if (max > 0) - add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max)); - -if (!ref) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2)); -compile_ref_matchingpath(common, ccbegin, &backtrack->own_backtracks, TRUE, TRUE); -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - -if (min > 1) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0); - CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, min, BACKTRACK_AS(ref_iterator_backtrack)->matchingpath); - } -else if (max > 0) - OP2(SLJIT_ADD, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1); - -if (jump != NULL) - JUMPHERE(jump); -JUMPHERE(zerolength); - -count_match(common); -return cc; -} - -static SLJIT_INLINE PCRE2_SPTR compile_recurse_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; -recurse_entry *entry = common->entries; -recurse_entry *prev = NULL; -sljit_sw start = GET(cc, 1); -PCRE2_SPTR start_cc; -BOOL needs_control_head; - -PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL); - -/* Inlining simple patterns. */ -if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack) - { - start_cc = common->start + start; - compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack); - BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE; - return cc + 1 + LINK_SIZE; - } - -while (entry != NULL) - { - if (entry->start == start) - break; - prev = entry; - entry = entry->next; - } - -if (entry == NULL) - { - entry = sljit_alloc_memory(compiler, sizeof(recurse_entry)); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return NULL; - entry->next = NULL; - entry->entry_label = NULL; - entry->backtrack_label = NULL; - entry->entry_calls = NULL; - entry->backtrack_calls = NULL; - entry->start = start; - - if (prev != NULL) - prev->next = entry; - else - common->entries = entry; - } - -BACKTRACK_AS(recurse_backtrack)->entry = entry; - -if (entry->entry_label == NULL) - add_jump(compiler, &entry->entry_calls, JUMP(SLJIT_FAST_CALL)); -else - JUMPTO(SLJIT_FAST_CALL, entry->entry_label); -/* Leave if the match is failed. */ -add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0)); -BACKTRACK_AS(recurse_backtrack)->matchingpath = LABEL(); -return cc + 1 + LINK_SIZE; -} - -static sljit_s32 SLJIT_FUNC do_callout_jit(struct jit_arguments *arguments, pcre2_callout_block *callout_block, PCRE2_SPTR *jit_ovector) -{ -PCRE2_SPTR begin; -PCRE2_SIZE *ovector; -sljit_u32 oveccount, capture_top; - -if (arguments->callout == NULL) - return 0; - -SLJIT_COMPILE_ASSERT(sizeof (PCRE2_SIZE) <= sizeof (sljit_sw), pcre2_size_must_be_lower_than_sljit_sw_size); - -begin = arguments->begin; -ovector = (PCRE2_SIZE*)(callout_block + 1); -oveccount = callout_block->capture_top; - -SLJIT_ASSERT(oveccount >= 1); - -callout_block->version = 2; -callout_block->callout_flags = 0; - -/* Offsets in subject. */ -callout_block->subject_length = arguments->end - arguments->begin; -callout_block->start_match = jit_ovector[0] - begin; -callout_block->current_position = (PCRE2_SPTR)callout_block->offset_vector - begin; -callout_block->subject = begin; - -/* Convert and copy the JIT offset vector to the ovector array. */ -callout_block->capture_top = 1; -callout_block->offset_vector = ovector; - -ovector[0] = PCRE2_UNSET; -ovector[1] = PCRE2_UNSET; -ovector += 2; -jit_ovector += 2; -capture_top = 1; - -/* Convert pointers to sizes. */ -while (--oveccount != 0) - { - capture_top++; - - ovector[0] = (PCRE2_SIZE)(jit_ovector[0] - begin); - ovector[1] = (PCRE2_SIZE)(jit_ovector[1] - begin); - - if (ovector[0] != PCRE2_UNSET) - callout_block->capture_top = capture_top; - - ovector += 2; - jit_ovector += 2; - } - -return (arguments->callout)(callout_block, arguments->callout_data); -} - -#define CALLOUT_ARG_OFFSET(arg) \ - SLJIT_OFFSETOF(pcre2_callout_block, arg) - -static SLJIT_INLINE PCRE2_SPTR compile_callout_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; -sljit_s32 mov_opcode; -unsigned int callout_length = (*cc == OP_CALLOUT) - ? PRIV(OP_lengths)[OP_CALLOUT] : GET(cc, 1 + 2 * LINK_SIZE); -sljit_sw value1; -sljit_sw value2; -sljit_sw value3; -sljit_uw callout_arg_size = (common->re->top_bracket + 1) * 2 * SSIZE_OF(sw); - -PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL); - -callout_arg_size = (sizeof(pcre2_callout_block) + callout_arg_size + sizeof(sljit_sw) - 1) / sizeof(sljit_sw); - -allocate_stack(common, callout_arg_size); - -SLJIT_ASSERT(common->capture_last_ptr != 0); -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); -OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); -value1 = (*cc == OP_CALLOUT) ? cc[1 + 2 * LINK_SIZE] : 0; -OP1(SLJIT_MOV_U32, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, value1); -OP1(SLJIT_MOV_U32, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0); -OP1(SLJIT_MOV_U32, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_top), SLJIT_IMM, common->re->top_bracket + 1); - -/* These pointer sized fields temporarly stores internal variables. */ -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0); - -if (common->mark_ptr != 0) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr)); -mov_opcode = (sizeof(PCRE2_SIZE) == 4) ? SLJIT_MOV_U32 : SLJIT_MOV; -OP1(mov_opcode, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 1)); -OP1(mov_opcode, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 1 + LINK_SIZE)); - -if (*cc == OP_CALLOUT) - { - value1 = 0; - value2 = 0; - value3 = 0; - } -else - { - value1 = (sljit_sw) (cc + (1 + 4*LINK_SIZE) + 1); - value2 = (callout_length - (1 + 4*LINK_SIZE + 2)); - value3 = (sljit_sw) (GET(cc, 1 + 3*LINK_SIZE)); - } - -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_string), SLJIT_IMM, value1); -OP1(mov_opcode, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_string_length), SLJIT_IMM, value2); -OP1(mov_opcode, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_string_offset), SLJIT_IMM, value3); -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0); - -SLJIT_ASSERT(TMP1 == SLJIT_R0 && STR_PTR == SLJIT_R1); - -/* Needed to save important temporary registers. */ -SLJIT_ASSERT(common->locals_size >= SSIZE_OF(sw)); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL0, STR_PTR, 0); -/* SLJIT_R0 = arguments */ -OP1(SLJIT_MOV, SLJIT_R1, 0, STACK_TOP, 0); -GET_LOCAL_BASE(SLJIT_R2, 0, OVECTOR_START); -sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(32, W, W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(do_callout_jit)); -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); -free_stack(common, callout_arg_size); - -/* Check return value. */ -OP2U(SLJIT_SUB32 | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); -add_jump(compiler, &backtrack->own_backtracks, JUMP(SLJIT_SIG_GREATER)); -if (common->abort_label == NULL) - add_jump(compiler, &common->abort, JUMP(SLJIT_NOT_EQUAL) /* SIG_LESS */); -else - JUMPTO(SLJIT_NOT_EQUAL /* SIG_LESS */, common->abort_label); -return cc + callout_length; -} - -#undef CALLOUT_ARG_SIZE -#undef CALLOUT_ARG_OFFSET - -static PCRE2_SPTR compile_reverse_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack = NULL; -jump_list **reverse_failed; -unsigned int lmin, lmax; -#ifdef SUPPORT_UNICODE -struct sljit_jump *jump; -struct sljit_label *label; -#endif - -SLJIT_ASSERT(parent->top == NULL); - -if (*cc == OP_REVERSE) - { - reverse_failed = &parent->own_backtracks; - lmin = GET2(cc, 1); - lmax = lmin; - cc += 1 + IMM2_SIZE; - - SLJIT_ASSERT(lmin > 0); - } -else - { - SLJIT_ASSERT(*cc == OP_VREVERSE); - PUSH_BACKTRACK(sizeof(vreverse_backtrack), cc, NULL); - - reverse_failed = &backtrack->own_backtracks; - lmin = GET2(cc, 1); - lmax = GET2(cc, 1 + IMM2_SIZE); - cc += 1 + 2 * IMM2_SIZE; - - SLJIT_ASSERT(lmin < lmax); - } - -if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin)); - } -else - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, begin)); - -#ifdef SUPPORT_UNICODE -if (common->utf) - { - if (lmin > 0) - { - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, lmin); - label = LABEL(); - add_jump(compiler, reverse_failed, CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0)); - move_back(common, reverse_failed, FALSE); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - } - - if (lmin < lmax) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0); - - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, lmax - lmin); - label = LABEL(); - jump = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0); - move_back(common, reverse_failed, FALSE); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - - JUMPHERE(jump); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0); - } - } -else -#endif - { - if (lmin > 0) - { - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(lmin)); - add_jump(compiler, reverse_failed, CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0)); - } - - if (lmin < lmax) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0); - - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(lmax - lmin)); - OP2U(SLJIT_SUB | SLJIT_SET_LESS, STR_PTR, 0, TMP2, 0); - SELECT(SLJIT_LESS, STR_PTR, TMP2, 0, STR_PTR); - - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0); - } - } - -check_start_used_ptr(common); - -if (lmin < lmax) - BACKTRACK_AS(vreverse_backtrack)->matchingpath = LABEL(); - -return cc; -} - -static SLJIT_INLINE BOOL assert_needs_str_ptr_saving(PCRE2_SPTR cc) -{ -while (TRUE) - { - switch (*cc) - { - case OP_CALLOUT_STR: - cc += GET(cc, 1 + 2*LINK_SIZE); - break; - - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_CIRC: - case OP_CIRCM: - case OP_DOLL: - case OP_DOLLM: - case OP_CALLOUT: - case OP_ALT: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - cc += PRIV(OP_lengths)[*cc]; - break; - - case OP_KET: - return FALSE; - - default: - return TRUE; - } - } -} - -static PCRE2_SPTR compile_assert_matchingpath(compiler_common *common, PCRE2_SPTR cc, assert_backtrack *backtrack, BOOL conditional) -{ -DEFINE_COMPILER; -int framesize; -int extrasize; -BOOL local_quit_available = FALSE; -BOOL needs_control_head; -BOOL end_block_size = 0; -BOOL has_vreverse; -int private_data_ptr; -backtrack_common altbacktrack; -PCRE2_SPTR ccbegin; -PCRE2_UCHAR opcode; -PCRE2_UCHAR bra = OP_BRA; -jump_list *tmp = NULL; -jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.own_backtracks; -jump_list **found; -/* Saving previous accept variables. */ -BOOL save_local_quit_available = common->local_quit_available; -BOOL save_in_positive_assertion = common->in_positive_assertion; -sljit_s32 save_restore_end_ptr = common->restore_end_ptr; -then_trap_backtrack *save_then_trap = common->then_trap; -struct sljit_label *save_quit_label = common->quit_label; -struct sljit_label *save_accept_label = common->accept_label; -jump_list *save_quit = common->quit; -jump_list *save_positive_assertion_quit = common->positive_assertion_quit; -jump_list *save_accept = common->accept; -struct sljit_jump *jump; -struct sljit_jump *brajump = NULL; - -/* Assert captures then. */ -common->then_trap = NULL; - -if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO) - { - SLJIT_ASSERT(!conditional); - bra = *cc; - cc++; - } - -private_data_ptr = PRIVATE_DATA(cc); -SLJIT_ASSERT(private_data_ptr != 0); -framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head); -backtrack->framesize = framesize; -backtrack->private_data_ptr = private_data_ptr; -opcode = *cc; -SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT); -found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target; -ccbegin = cc; -cc += GET(cc, 1); - -if (bra == OP_BRAMINZERO) - { - /* This is a braminzero backtrack path. */ - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - brajump = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0); - } - -if ((opcode == OP_ASSERTBACK || opcode == OP_ASSERTBACK_NOT) && find_vreverse(ccbegin)) - end_block_size = 3; - -if (framesize < 0) - { - extrasize = 1; - if (bra == OP_BRA && !assert_needs_str_ptr_saving(ccbegin + 1 + LINK_SIZE)) - extrasize = 0; - - extrasize += end_block_size; - - if (needs_control_head) - extrasize++; - - if (framesize == no_frame) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0); - - if (extrasize > 0) - allocate_stack(common, extrasize); - - if (needs_control_head) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - - if (extrasize > 0) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - - if (needs_control_head) - { - SLJIT_ASSERT(extrasize == end_block_size + 2); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(end_block_size + 1), TMP1, 0); - } - } -else - { - extrasize = (needs_control_head ? 3 : 2) + end_block_size; - - OP1(SLJIT_MOV, TMP2, 0, STACK_TOP, 0); - allocate_stack(common, framesize + extrasize); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP2, 0); - if (needs_control_head) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - - if (needs_control_head) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(end_block_size + 2), TMP1, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(end_block_size + 1), TMP2, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0); - } - else - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(end_block_size + 1), TMP1, 0); - - init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize); - } - -if (end_block_size > 0) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), STR_END, 0); - OP1(SLJIT_MOV, STR_END, 0, STR_PTR, 0); - } - -memset(&altbacktrack, 0, sizeof(backtrack_common)); -if (conditional || (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)) - { - /* Control verbs cannot escape from these asserts. */ - local_quit_available = TRUE; - common->restore_end_ptr = 0; - common->local_quit_available = TRUE; - common->quit_label = NULL; - common->quit = NULL; - } - -common->in_positive_assertion = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK); -common->positive_assertion_quit = NULL; - -while (1) - { - common->accept_label = NULL; - common->accept = NULL; - altbacktrack.top = NULL; - altbacktrack.own_backtracks = NULL; - - if (*ccbegin == OP_ALT && extrasize > 0) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - - altbacktrack.cc = ccbegin; - ccbegin += 1 + LINK_SIZE; - - has_vreverse = (*ccbegin == OP_VREVERSE); - if (*ccbegin == OP_REVERSE || has_vreverse) - ccbegin = compile_reverse_matchingpath(common, ccbegin, &altbacktrack); - - compile_matchingpath(common, ccbegin, cc, &altbacktrack); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - { - if (local_quit_available) - { - common->local_quit_available = save_local_quit_available; - common->quit_label = save_quit_label; - common->quit = save_quit; - } - common->in_positive_assertion = save_in_positive_assertion; - common->restore_end_ptr = save_restore_end_ptr; - common->then_trap = save_then_trap; - common->accept_label = save_accept_label; - common->positive_assertion_quit = save_positive_assertion_quit; - common->accept = save_accept; - return NULL; - } - - if (has_vreverse) - { - SLJIT_ASSERT(altbacktrack.top != NULL); - add_jump(compiler, &altbacktrack.top->simple_backtracks, CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0)); - } - - common->accept_label = LABEL(); - if (common->accept != NULL) - set_jumps(common->accept, common->accept_label); - - /* Reset stack. */ - if (framesize < 0) - { - if (framesize == no_frame) - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - else if (extrasize > 0) - free_stack(common, extrasize); - - if (end_block_size > 0) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(STACK_TOP), STACK(-extrasize + 1)); - - if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(-1)); - } - else - { - if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional) - { - /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */ - OP2(SLJIT_SUB, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw)); - - if (end_block_size > 0) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(STACK_TOP), STACK(-extrasize + 2)); - - if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(-1)); - } - else - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - - if (end_block_size > 0) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(STACK_TOP), STACK(-framesize - extrasize + 1)); - - if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(-framesize - 2)); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize - 1) * sizeof(sljit_sw)); - } - } - - if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT) - { - /* We know that STR_PTR was stored on the top of the stack. */ - if (conditional) - { - if (extrasize > 0) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(-end_block_size - (needs_control_head ? 2 : 1))); - } - else if (bra == OP_BRAZERO) - { - if (framesize < 0) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(-extrasize)); - else - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(-framesize - 1)); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(-framesize - extrasize)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - } - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - else if (framesize >= 0) - { - /* For OP_BRA and OP_BRAMINZERO. */ - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(-framesize - 1)); - } - } - add_jump(compiler, found, JUMP(SLJIT_JUMP)); - - compile_backtrackingpath(common, altbacktrack.top); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - { - if (local_quit_available) - { - common->local_quit_available = save_local_quit_available; - common->quit_label = save_quit_label; - common->quit = save_quit; - } - common->in_positive_assertion = save_in_positive_assertion; - common->restore_end_ptr = save_restore_end_ptr; - common->then_trap = save_then_trap; - common->accept_label = save_accept_label; - common->positive_assertion_quit = save_positive_assertion_quit; - common->accept = save_accept; - return NULL; - } - set_jumps(altbacktrack.own_backtracks, LABEL()); - - if (*cc != OP_ALT) - break; - - ccbegin = cc; - cc += GET(cc, 1); - } - -if (local_quit_available) - { - SLJIT_ASSERT(common->positive_assertion_quit == NULL); - /* Makes the check less complicated below. */ - common->positive_assertion_quit = common->quit; - } - -/* None of them matched. */ -if (common->positive_assertion_quit != NULL) - { - jump = JUMP(SLJIT_JUMP); - set_jumps(common->positive_assertion_quit, LABEL()); - SLJIT_ASSERT(framesize != no_stack); - if (framesize < 0) - OP2(SLJIT_SUB, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw)); - else - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (extrasize + 1) * sizeof(sljit_sw)); - } - JUMPHERE(jump); - } - -if (end_block_size > 0) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - -if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(end_block_size + 1)); - -if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) - { - /* Assert is failed. */ - if ((conditional && extrasize > 0) || bra == OP_BRAZERO) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - - if (framesize < 0) - { - /* The topmost item should be 0. */ - if (bra == OP_BRAZERO) - { - if (extrasize >= 2) - free_stack(common, extrasize - 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - else if (extrasize > 0) - free_stack(common, extrasize); - } - else - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1)); - /* The topmost item should be 0. */ - if (bra == OP_BRAZERO) - { - free_stack(common, framesize + extrasize - 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - else - free_stack(common, framesize + extrasize); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - } - jump = JUMP(SLJIT_JUMP); - if (bra != OP_BRAZERO) - add_jump(compiler, target, jump); - - /* Assert is successful. */ - set_jumps(tmp, LABEL()); - if (framesize < 0) - { - /* We know that STR_PTR was stored on the top of the stack. */ - if (extrasize > 0) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(-extrasize)); - - /* Keep the STR_PTR on the top of the stack. */ - if (bra == OP_BRAZERO) - { - /* This allocation is always successful. */ - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw)); - if (extrasize >= 2) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - } - else if (bra == OP_BRAMINZERO) - { - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - } - else - { - if (bra == OP_BRA) - { - /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */ - OP2(SLJIT_SUB, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw)); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(-extrasize + 1)); - } - else - { - /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */ - OP2(SLJIT_SUB, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + end_block_size + 2) * sizeof(sljit_sw)); - - if (extrasize == 2 + end_block_size) - { - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - if (bra == OP_BRAMINZERO) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - else - { - SLJIT_ASSERT(extrasize == 3 + end_block_size); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(-1)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0); - } - } - } - - if (bra == OP_BRAZERO) - { - backtrack->matchingpath = LABEL(); - SET_LABEL(jump, backtrack->matchingpath); - } - else if (bra == OP_BRAMINZERO) - { - JUMPTO(SLJIT_JUMP, backtrack->matchingpath); - JUMPHERE(brajump); - SLJIT_ASSERT(framesize != 0); - if (framesize > 0) - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(-2)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize - 1) * sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - } - set_jumps(backtrack->common.own_backtracks, LABEL()); - } - } -else - { - /* AssertNot is successful. */ - if (framesize < 0) - { - if (extrasize > 0) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - - if (bra != OP_BRA) - { - if (extrasize >= 2) - free_stack(common, extrasize - 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - else if (extrasize > 0) - free_stack(common, extrasize); - } - else - { - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1)); - /* The topmost item should be 0. */ - if (bra != OP_BRA) - { - free_stack(common, framesize + extrasize - 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - else - free_stack(common, framesize + extrasize); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - } - - if (bra == OP_BRAZERO) - backtrack->matchingpath = LABEL(); - else if (bra == OP_BRAMINZERO) - { - JUMPTO(SLJIT_JUMP, backtrack->matchingpath); - JUMPHERE(brajump); - } - - if (bra != OP_BRA) - { - SLJIT_ASSERT(found == &backtrack->common.own_backtracks); - set_jumps(backtrack->common.own_backtracks, LABEL()); - backtrack->common.own_backtracks = NULL; - } - } - -if (local_quit_available) - { - common->local_quit_available = save_local_quit_available; - common->quit_label = save_quit_label; - common->quit = save_quit; - } - -common->in_positive_assertion = save_in_positive_assertion; -common->restore_end_ptr = save_restore_end_ptr; -common->then_trap = save_then_trap; -common->accept_label = save_accept_label; -common->positive_assertion_quit = save_positive_assertion_quit; -common->accept = save_accept; -return cc + 1 + LINK_SIZE; -} - -static SLJIT_INLINE void match_once_common(compiler_common *common, PCRE2_UCHAR ket, int framesize, int private_data_ptr, BOOL has_alternatives, BOOL needs_control_head) -{ -DEFINE_COMPILER; -int stacksize; - -if (framesize < 0) - { - if (framesize == no_frame) - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - else - { - stacksize = needs_control_head ? 1 : 0; - if (ket != OP_KET || has_alternatives) - stacksize++; - - if (stacksize > 0) - free_stack(common, stacksize); - } - - if (needs_control_head) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? STACK(-2) : STACK(-1)); - - /* TMP2 which is set here used by OP_KETRMAX below. */ - if (ket == OP_KETRMAX) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(-1)); - else if (ket == OP_KETRMIN) - { - /* Move the STR_PTR to the private_data_ptr. */ - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(-1)); - } - } -else - { - stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1; - OP2(SLJIT_SUB, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw)); - if (needs_control_head) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(-1)); - - if (ket == OP_KETRMAX) - { - /* TMP2 which is set here used by OP_KETRMAX below. */ - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - } - } -if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, TMP1, 0); -} - -static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr) -{ -DEFINE_COMPILER; - -if (common->capture_last_ptr != 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, offset >> 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0); - stacksize++; - } -if (common->optimized_cbracket[offset >> 1] == 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0); - stacksize += 2; - } -return stacksize; -} - -static PCRE2_SPTR SLJIT_FUNC do_script_run(PCRE2_SPTR ptr, PCRE2_SPTR endptr) -{ - if (PRIV(script_run)(ptr, endptr, FALSE)) - return endptr; - return NULL; -} - -#ifdef SUPPORT_UNICODE - -static PCRE2_SPTR SLJIT_FUNC do_script_run_utf(PCRE2_SPTR ptr, PCRE2_SPTR endptr) -{ - if (PRIV(script_run)(ptr, endptr, TRUE)) - return endptr; - return NULL; -} - -#endif /* SUPPORT_UNICODE */ - -static void match_script_run_common(compiler_common *common, int private_data_ptr, backtrack_common *parent) -{ -DEFINE_COMPILER; - -SLJIT_ASSERT(TMP1 == SLJIT_R0 && STR_PTR == SLJIT_R1); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); -#ifdef SUPPORT_UNICODE -sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W), SLJIT_IMM, - common->utf ? SLJIT_FUNC_ADDR(do_script_run_utf) : SLJIT_FUNC_ADDR(do_script_run)); -#else -sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(do_script_run)); -#endif - -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0); -add_jump(compiler, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks, CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0)); -} - -/* - Handling bracketed expressions is probably the most complex part. - - Stack layout naming characters: - S - Push the current STR_PTR - 0 - Push a 0 (NULL) - A - Push the current STR_PTR. Needed for restoring the STR_PTR - before the next alternative. Not pushed if there are no alternatives. - M - Any values pushed by the current alternative. Can be empty, or anything. - C - Push the previous OVECTOR(i), OVECTOR(i+1) and OVECTOR_PRIV(i) to the stack. - L - Push the previous local (pointed by localptr) to the stack - () - opional values stored on the stack - ()* - optonal, can be stored multiple times - - The following list shows the regular expression templates, their PCRE byte codes - and stack layout supported by pcre-sljit. - - (?:) OP_BRA | OP_KET A M - () OP_CBRA | OP_KET C M - (?:)+ OP_BRA | OP_KETRMAX 0 A M S ( A M S )* - OP_SBRA | OP_KETRMAX 0 L M S ( L M S )* - (?:)+? OP_BRA | OP_KETRMIN 0 A M S ( A M S )* - OP_SBRA | OP_KETRMIN 0 L M S ( L M S )* - ()+ OP_CBRA | OP_KETRMAX 0 C M S ( C M S )* - OP_SCBRA | OP_KETRMAX 0 C M S ( C M S )* - ()+? OP_CBRA | OP_KETRMIN 0 C M S ( C M S )* - OP_SCBRA | OP_KETRMIN 0 C M S ( C M S )* - (?:)? OP_BRAZERO | OP_BRA | OP_KET S ( A M 0 ) - (?:)?? OP_BRAMINZERO | OP_BRA | OP_KET S ( A M 0 ) - ()? OP_BRAZERO | OP_CBRA | OP_KET S ( C M 0 ) - ()?? OP_BRAMINZERO | OP_CBRA | OP_KET S ( C M 0 ) - (?:)* OP_BRAZERO | OP_BRA | OP_KETRMAX S 0 ( A M S )* - OP_BRAZERO | OP_SBRA | OP_KETRMAX S 0 ( L M S )* - (?:)*? OP_BRAMINZERO | OP_BRA | OP_KETRMIN S 0 ( A M S )* - OP_BRAMINZERO | OP_SBRA | OP_KETRMIN S 0 ( L M S )* - ()* OP_BRAZERO | OP_CBRA | OP_KETRMAX S 0 ( C M S )* - OP_BRAZERO | OP_SCBRA | OP_KETRMAX S 0 ( C M S )* - ()*? OP_BRAMINZERO | OP_CBRA | OP_KETRMIN S 0 ( C M S )* - OP_BRAMINZERO | OP_SCBRA | OP_KETRMIN S 0 ( C M S )* - - - Stack layout naming characters: - A - Push the alternative index (starting from 0) on the stack. - Not pushed if there is no alternatives. - M - Any values pushed by the current alternative. Can be empty, or anything. - - The next list shows the possible content of a bracket: - (|) OP_*BRA | OP_ALT ... M A - (?()|) OP_*COND | OP_ALT M A - (?>|) OP_ONCE | OP_ALT ... [stack trace] M A - Or nothing, if trace is unnecessary -*/ - -static PCRE2_SPTR compile_bracket_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; -PCRE2_UCHAR opcode; -int private_data_ptr = 0; -int offset = 0; -int i, stacksize; -int repeat_ptr = 0, repeat_length = 0; -int repeat_type = 0, repeat_count = 0; -PCRE2_SPTR ccbegin; -PCRE2_SPTR matchingpath; -PCRE2_SPTR slot; -PCRE2_UCHAR bra = OP_BRA; -PCRE2_UCHAR ket; -assert_backtrack *assert; -BOOL has_alternatives; -BOOL needs_control_head = FALSE; -BOOL has_vreverse = FALSE; -struct sljit_jump *jump; -struct sljit_jump *skip; -jump_list *jumplist; -struct sljit_label *rmax_label = NULL; -struct sljit_jump *braminzero = NULL; - -PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL); - -if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO) - { - bra = *cc; - cc++; - opcode = *cc; - } - -opcode = *cc; -ccbegin = cc; -matchingpath = bracketend(cc) - 1 - LINK_SIZE; -ket = *matchingpath; -if (ket == OP_KET && PRIVATE_DATA(matchingpath) != 0) - { - repeat_ptr = PRIVATE_DATA(matchingpath); - repeat_length = PRIVATE_DATA(matchingpath + 1); - repeat_type = PRIVATE_DATA(matchingpath + 2); - repeat_count = PRIVATE_DATA(matchingpath + 3); - SLJIT_ASSERT(repeat_length != 0 && repeat_type != 0 && repeat_count != 0); - if (repeat_type == OP_UPTO) - ket = OP_KETRMAX; - if (repeat_type == OP_MINUPTO) - ket = OP_KETRMIN; - } - -matchingpath = ccbegin + 1 + LINK_SIZE; -SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN); -SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX))); -cc += GET(cc, 1); - -has_alternatives = *cc == OP_ALT; -if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND)) - { - SLJIT_COMPILE_ASSERT(OP_DNRREF == OP_RREF + 1 && OP_FALSE == OP_RREF + 2 && OP_TRUE == OP_RREF + 3, - compile_time_checks_must_be_grouped_together); - has_alternatives = ((*matchingpath >= OP_RREF && *matchingpath <= OP_TRUE) || *matchingpath == OP_FAIL) ? FALSE : TRUE; - } - -if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN)) - opcode = OP_SCOND; - -if (opcode == OP_CBRA || opcode == OP_SCBRA) - { - /* Capturing brackets has a pre-allocated space. */ - offset = GET2(ccbegin, 1 + LINK_SIZE); - if (common->optimized_cbracket[offset] == 0) - { - private_data_ptr = OVECTOR_PRIV(offset); - offset <<= 1; - } - else - { - offset <<= 1; - private_data_ptr = OVECTOR(offset); - } - BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr; - matchingpath += IMM2_SIZE; - } -else if (opcode == OP_ASSERT_NA || opcode == OP_ASSERTBACK_NA || opcode == OP_ONCE - || opcode == OP_ASSERT_SCS || opcode == OP_SCRIPT_RUN || opcode == OP_SBRA || opcode == OP_SCOND) - { - /* Other brackets simply allocate the next entry. */ - private_data_ptr = PRIVATE_DATA(ccbegin); - SLJIT_ASSERT(private_data_ptr != 0); - BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr; - if (opcode == OP_ONCE) - BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, NULL, FALSE, &needs_control_head); - } - -/* Instructions before the first alternative. */ -stacksize = 0; -if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO)) - stacksize++; -if (bra == OP_BRAZERO) - stacksize++; - -if (stacksize > 0) - allocate_stack(common, stacksize); - -stacksize = 0; -if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO)) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0); - stacksize++; - } - -if (bra == OP_BRAZERO) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0); - -if (bra == OP_BRAMINZERO) - { - /* This is a backtrack path! (Since the try-path of OP_BRAMINZERO matches to the empty string) */ - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - if (ket != OP_KETRMIN) - { - free_stack(common, 1); - braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0); - } - else if (opcode == OP_ONCE || opcode >= OP_SBRA) - { - jump = CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - /* Nothing stored during the first run. */ - skip = JUMP(SLJIT_JUMP); - JUMPHERE(jump); - /* Checking zero-length iteration. */ - if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0) - { - /* When we come from outside, private_data_ptr contains the previous STR_PTR. */ - braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - } - else - { - /* Except when the whole stack frame must be saved. */ - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - braminzero = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), STACK(-BACKTRACK_AS(bracket_backtrack)->u.framesize - 2)); - } - JUMPHERE(skip); - } - else - { - jump = CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - JUMPHERE(jump); - } - } - -if (repeat_type != 0) - { - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, repeat_count); - if (repeat_type == OP_EXACT) - rmax_label = LABEL(); - } - -if (ket == OP_KETRMIN) - BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL(); - -if (ket == OP_KETRMAX) - { - rmax_label = LABEL(); - if (has_alternatives && opcode >= OP_BRA && opcode < OP_SBRA && repeat_type == 0) - BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmax_label; - } - -/* Handling capturing brackets and alternatives. */ -if (opcode == OP_ONCE) - { - stacksize = 0; - if (needs_control_head) - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - stacksize++; - } - - if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0) - { - /* Neither capturing brackets nor recursions are found in the block. */ - if (ket == OP_KETRMIN) - { - stacksize += 2; - if (!needs_control_head) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - } - else - { - if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0); - if (ket == OP_KETRMAX || has_alternatives) - stacksize++; - } - - if (stacksize > 0) - allocate_stack(common, stacksize); - - stacksize = 0; - if (needs_control_head) - { - stacksize++; - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - } - - if (ket == OP_KETRMIN) - { - if (needs_control_head) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0); - if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame) - OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0); - } - else if (ket == OP_KETRMAX || has_alternatives) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0); - } - else - { - if (ket != OP_KET || has_alternatives) - stacksize++; - - stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1; - allocate_stack(common, stacksize); - - if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP2(SLJIT_ADD, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw)); - - stacksize = needs_control_head ? 1 : 0; - if (ket != OP_KET || has_alternatives) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP2, 0); - stacksize++; - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0); - } - else - { - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP2, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0); - } - init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1); - } - } -else if (opcode == OP_CBRA || opcode == OP_SCBRA) - { - /* Saving the previous values. */ - if (common->optimized_cbracket[offset >> 1] != 0) - { - SLJIT_ASSERT(private_data_ptr == OVECTOR(offset)); - allocate_stack(common, 2); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0); - } - else - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - } - } -else if (opcode == OP_ASSERTBACK_NA && PRIVATE_DATA(ccbegin + 1)) - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - allocate_stack(common, 4); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw), STR_END, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0); - OP1(SLJIT_MOV, STR_END, 0, STR_PTR, 0); - - has_vreverse = (*matchingpath == OP_VREVERSE); - if (*matchingpath == OP_REVERSE || has_vreverse) - matchingpath = compile_reverse_matchingpath(common, matchingpath, backtrack); - } -else if (opcode == OP_ASSERT_NA || opcode == OP_ASSERTBACK_NA || opcode == OP_SCRIPT_RUN || opcode == OP_SBRA || opcode == OP_SCOND) - { - /* Saving the previous value. */ - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - - if (*matchingpath == OP_REVERSE) - matchingpath = compile_reverse_matchingpath(common, matchingpath, backtrack); - } -else if (opcode == OP_ASSERT_SCS) - { - /* Nested scs blocks will not update this variable. */ - if (common->restore_end_ptr == 0) - common->restore_end_ptr = private_data_ptr + sizeof(sljit_sw); - - if (*matchingpath == OP_CREF && (matchingpath[1 + IMM2_SIZE] != OP_CREF && matchingpath[1 + IMM2_SIZE] != OP_DNCREF)) - { - /* Optimized case for a single capture reference. */ - i = OVECTOR(GET2(matchingpath, 1) << 1); - - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), i); - - add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.no_capture), CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1))); - matchingpath += 1 + IMM2_SIZE; - - allocate_stack(common, has_alternatives ? 3 : 2); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, SLJIT_TMP_DEST_REG, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw), STR_END, 0); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), i + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, STR_PTR, 0, TMP2, 0); - } - else - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); - jumplist = NULL; - - while (TRUE) - { - if (*matchingpath == OP_CREF) - { - sljit_get_local_base(compiler, TMP2, 0, OVECTOR(GET2(matchingpath, 1) << 1)); - matchingpath += 1 + IMM2_SIZE; - } - else - { - SLJIT_ASSERT(*matchingpath == OP_DNCREF); - - i = GET2(matchingpath, 1 + IMM2_SIZE); - slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size; - - while (i-- > 1) - { - sljit_get_local_base(compiler, TMP2, 0, OVECTOR(GET2(slot, 0) << 1)); - add_jump(compiler, &jumplist, CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(TMP2), 0, TMP1, 0)); - slot += common->name_entry_size; - } - - sljit_get_local_base(compiler, TMP2, 0, OVECTOR(GET2(slot, 0) << 1)); - matchingpath += 1 + 2 * IMM2_SIZE; - } - - if (*matchingpath != OP_CREF && *matchingpath != OP_DNCREF) - break; - - add_jump(compiler, &jumplist, CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(TMP2), 0, TMP1, 0)); - } - - add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.no_capture), - CMP(SLJIT_EQUAL, SLJIT_MEM1(TMP2), 0, TMP1, 0)); - - set_jumps(jumplist, LABEL()); - - allocate_stack(common, has_alternatives ? 3 : 2); - - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, SLJIT_TMP_DEST_REG, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP2), 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw), STR_END, 0); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw)); - } - - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_TMP_DEST_REG, 0); - - if (has_alternatives) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0); - } -else if (has_alternatives) - { - /* Pushing the starting string pointer. */ - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - } - -/* Generating code for the first alternative. */ -if (opcode == OP_COND || opcode == OP_SCOND) - { - if (*matchingpath == OP_CREF) - { - SLJIT_ASSERT(has_alternatives); - add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.no_capture), - CMP(SLJIT_EQUAL, SLJIT_MEM1(SLJIT_SP), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_SP), OVECTOR(1))); - matchingpath += 1 + IMM2_SIZE; - } - else if (*matchingpath == OP_DNCREF) - { - SLJIT_ASSERT(has_alternatives); - - i = GET2(matchingpath, 1 + IMM2_SIZE); - slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size; - OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(GET2(slot, 0) << 1), TMP1, 0); - slot += common->name_entry_size; - i--; - while (i-- > 0) - { - OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(GET2(slot, 0) << 1), TMP1, 0); - OP2(SLJIT_OR | SLJIT_SET_Z, TMP2, 0, TMP2, 0, STR_PTR, 0); - slot += common->name_entry_size; - } - OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); - add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.no_capture), JUMP(SLJIT_ZERO)); - matchingpath += 1 + 2 * IMM2_SIZE; - } - else if ((*matchingpath >= OP_RREF && *matchingpath <= OP_TRUE) || *matchingpath == OP_FAIL) - { - /* Never has other case. */ - BACKTRACK_AS(bracket_backtrack)->u.no_capture = NULL; - SLJIT_ASSERT(!has_alternatives); - - if (*matchingpath == OP_TRUE) - { - stacksize = 1; - matchingpath++; - } - else if (*matchingpath == OP_FALSE || *matchingpath == OP_FAIL) - stacksize = 0; - else if (*matchingpath == OP_RREF) - { - stacksize = GET2(matchingpath, 1); - if (common->currententry == NULL) - stacksize = 0; - else if (stacksize == RREF_ANY) - stacksize = 1; - else if (common->currententry->start == 0) - stacksize = stacksize == 0; - else - stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE); - - if (stacksize != 0) - matchingpath += 1 + IMM2_SIZE; - } - else - { - if (common->currententry == NULL || common->currententry->start == 0) - stacksize = 0; - else - { - stacksize = GET2(matchingpath, 1 + IMM2_SIZE); - slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size; - i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE); - while (stacksize > 0) - { - if ((int)GET2(slot, 0) == i) - break; - slot += common->name_entry_size; - stacksize--; - } - } - - if (stacksize != 0) - matchingpath += 1 + 2 * IMM2_SIZE; - } - - /* The stacksize == 0 is a common "else" case. */ - if (stacksize == 0) - { - if (*cc == OP_ALT) - { - matchingpath = cc + 1 + LINK_SIZE; - cc += GET(cc, 1); - } - else - matchingpath = cc; - } - } - else - { - SLJIT_ASSERT(has_alternatives && *matchingpath >= OP_ASSERT && *matchingpath <= OP_ASSERTBACK_NOT); - /* Similar code as PUSH_BACKTRACK macro. */ - assert = sljit_alloc_memory(compiler, sizeof(assert_backtrack)); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return NULL; - memset(assert, 0, sizeof(assert_backtrack)); - assert->common.cc = matchingpath; - BACKTRACK_AS(bracket_backtrack)->u.assert = assert; - matchingpath = compile_assert_matchingpath(common, matchingpath, assert, TRUE); - } - } - -compile_matchingpath(common, matchingpath, cc, backtrack); -if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return NULL; - -switch (opcode) - { - case OP_ASSERTBACK_NA: - if (has_vreverse) - { - SLJIT_ASSERT(backtrack->top != NULL && PRIVATE_DATA(ccbegin + 1)); - add_jump(compiler, &backtrack->top->simple_backtracks, CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0)); - } - - if (PRIVATE_DATA(ccbegin + 1)) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - break; - case OP_ONCE: - match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head); - break; - case OP_SCRIPT_RUN: - match_script_run_common(common, private_data_ptr, backtrack); - break; - } - -stacksize = 0; -if (repeat_type == OP_MINUPTO) - { - /* We need to preserve the counter. TMP2 will be used below. */ - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr); - stacksize++; - } -if (ket != OP_KET || bra != OP_BRA) - stacksize++; -if (offset != 0) - { - if (common->capture_last_ptr != 0) - stacksize++; - if (common->optimized_cbracket[offset >> 1] == 0) - stacksize += 2; - } -if (has_alternatives && opcode != OP_ONCE) - stacksize++; - -if (stacksize > 0) - allocate_stack(common, stacksize); - -stacksize = 0; -if (repeat_type == OP_MINUPTO) - { - /* TMP2 was set above. */ - OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1); - stacksize++; - } - -if (ket != OP_KET || bra != OP_BRA) - { - if (ket != OP_KET) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0); - else - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0); - stacksize++; - } - -if (offset != 0) - stacksize = match_capture_common(common, stacksize, offset, private_data_ptr); - -/* Skip and count the other alternatives. */ -i = 1; -while (*cc == OP_ALT) - { - cc += GET(cc, 1); - i++; - } - -if (has_alternatives) - { - if (opcode != OP_ONCE) - { - if (i <= 3) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0); - else - BACKTRACK_AS(bracket_backtrack)->matching_mov_addr = sljit_emit_mov_addr(compiler, SLJIT_MEM1(STACK_TOP), STACK(stacksize)); - } - if (ket != OP_KETRMAX) - BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL(); - } - -/* Must be after the matchingpath label. */ -if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0) - { - SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0); - } -else switch (opcode) - { - case OP_ASSERT_NA: - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - break; - case OP_ASSERT_SCS: - OP1(SLJIT_MOV, TMP1, 0, STR_END, 0); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw), TMP1, 0); - - /* Nested scs blocks will not update this variable. */ - if (common->restore_end_ptr == private_data_ptr + SSIZE_OF(sw)) - common->restore_end_ptr = 0; - break; - } - -if (ket == OP_KETRMAX) - { - if (repeat_type != 0) - { - if (has_alternatives) - BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL(); - OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, rmax_label); - /* Drop STR_PTR for greedy plus quantifier. */ - if (opcode != OP_ONCE) - free_stack(common, 1); - } - else if (opcode < OP_BRA || opcode >= OP_SBRA) - { - if (has_alternatives) - BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL(); - - /* Checking zero-length iteration. */ - if (opcode != OP_ONCE) - { - /* This case includes opcodes such as OP_SCRIPT_RUN. */ - CMPTO(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STR_PTR, 0, rmax_label); - /* Drop STR_PTR for greedy plus quantifier. */ - if (bra != OP_BRAZERO) - free_stack(common, 1); - } - else - /* TMP2 must contain the starting STR_PTR. */ - CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmax_label); - } - else - JUMPTO(SLJIT_JUMP, rmax_label); - BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL(); - } - -if (repeat_type == OP_EXACT) - { - count_match(common); - OP2(SLJIT_SUB | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, rmax_label); - } -else if (repeat_type == OP_UPTO) - { - /* We need to preserve the counter. */ - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr); - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - } - -if (bra == OP_BRAZERO) - BACKTRACK_AS(bracket_backtrack)->zero_matchingpath = LABEL(); - -if (bra == OP_BRAMINZERO) - { - /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */ - JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->matchingpath); - if (braminzero != NULL) - { - JUMPHERE(braminzero); - /* We need to release the end pointer to perform the - backtrack for the zero-length iteration. When - framesize is < 0, OP_ONCE will do the release itself. */ - if (opcode == OP_ONCE) - { - int framesize = BACKTRACK_AS(bracket_backtrack)->u.framesize; - - SLJIT_ASSERT(framesize != 0); - if (framesize > 0) - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize - 1) * sizeof(sljit_sw)); - } - } - else if (ket == OP_KETRMIN) - free_stack(common, 1); - } - /* Continue to the normal backtrack. */ - } - -if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO || (has_alternatives && repeat_type != OP_EXACT)) - count_match(common); - -cc += 1 + LINK_SIZE; - -if (opcode == OP_ONCE) - { - int data; - int framesize = BACKTRACK_AS(bracket_backtrack)->u.framesize; - - SLJIT_ASSERT(SHRT_MIN <= framesize && framesize < SHRT_MAX/2); - /* We temporarily encode the needs_control_head in the lowest bit. - The real value should be short enough for this operation to work - without triggering Undefined Behaviour. */ - data = (int)((short)((unsigned short)framesize << 1) | (needs_control_head ? 1 : 0)); - BACKTRACK_AS(bracket_backtrack)->u.framesize = data; - } -return cc + repeat_length; -} - -static PCRE2_SPTR compile_bracketpos_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; -PCRE2_UCHAR opcode; -int private_data_ptr; -int cbraprivptr = 0; -BOOL needs_control_head; -int framesize; -int stacksize; -int offset = 0; -BOOL zero = FALSE; -PCRE2_SPTR ccbegin = NULL; -int stack; /* Also contains the offset of control head. */ -struct sljit_label *loop = NULL; -struct jump_list *emptymatch = NULL; - -PUSH_BACKTRACK(sizeof(bracketpos_backtrack), cc, NULL); -if (*cc == OP_BRAPOSZERO) - { - zero = TRUE; - cc++; - } - -opcode = *cc; -private_data_ptr = PRIVATE_DATA(cc); -SLJIT_ASSERT(private_data_ptr != 0); -BACKTRACK_AS(bracketpos_backtrack)->private_data_ptr = private_data_ptr; -switch(opcode) - { - case OP_BRAPOS: - case OP_SBRAPOS: - ccbegin = cc + 1 + LINK_SIZE; - break; - - case OP_CBRAPOS: - case OP_SCBRAPOS: - offset = GET2(cc, 1 + LINK_SIZE); - /* This case cannot be optimized in the same way as - normal capturing brackets. */ - SLJIT_ASSERT(common->optimized_cbracket[offset] == 0); - cbraprivptr = OVECTOR_PRIV(offset); - offset <<= 1; - ccbegin = cc + 1 + LINK_SIZE + IMM2_SIZE; - break; - - default: - SLJIT_UNREACHABLE(); - break; - } - -framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head); -BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize; -if (framesize < 0) - { - if (offset != 0) - { - stacksize = 2; - if (common->capture_last_ptr != 0) - stacksize++; - } - else - stacksize = 1; - - if (needs_control_head) - stacksize++; - if (!zero) - stacksize++; - - BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize; - allocate_stack(common, stacksize); - if (framesize == no_frame) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0); - - stack = 0; - if (offset != 0) - { - stack = 2; - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0); - if (common->capture_last_ptr != 0) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0); - if (needs_control_head) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - if (common->capture_last_ptr != 0) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0); - stack = 3; - } - } - else - { - if (needs_control_head) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - stack = 1; - } - - if (needs_control_head) - stack++; - if (!zero) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), SLJIT_IMM, 1); - if (needs_control_head) - { - stack--; - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0); - } - } -else - { - stacksize = framesize + 1; - if (!zero) - stacksize++; - if (needs_control_head) - stacksize++; - if (offset == 0) - stacksize++; - BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize; - - allocate_stack(common, stacksize); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - if (needs_control_head) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw)); - - stack = 0; - if (!zero) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1); - stack = 1; - } - if (needs_control_head) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0); - stack++; - } - if (offset == 0) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0); - stack++; - } - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0); - init_frame(common, cc, NULL, stacksize - 1, stacksize - framesize); - stack -= 1 + (offset == 0); - } - -if (offset != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), cbraprivptr, STR_PTR, 0); - -loop = LABEL(); -while (*cc != OP_KETRPOS) - { - backtrack->top = NULL; - backtrack->own_backtracks = NULL; - cc += GET(cc, 1); - - compile_matchingpath(common, ccbegin, cc, backtrack); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return NULL; - - if (framesize < 0) - { - if (framesize == no_frame) - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - - if (offset != 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), cbraprivptr, STR_PTR, 0); - if (common->capture_last_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, offset >> 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0); - } - else - { - if (opcode == OP_SBRAPOS) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - } - - /* Even if the match is empty, we need to reset the control head. */ - if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack)); - - if (opcode == OP_SBRAPOS || opcode == OP_SCBRAPOS) - add_jump(compiler, &emptymatch, CMP(SLJIT_EQUAL, TMP1, 0, STR_PTR, 0)); - - if (!zero) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 0); - } - else - { - if (offset != 0) - { - OP2(SLJIT_SUB, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), cbraprivptr, STR_PTR, 0); - if (common->capture_last_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, offset >> 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0); - } - else - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP2(SLJIT_SUB, STACK_TOP, 0, TMP2, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw)); - if (opcode == OP_SBRAPOS) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), STACK(-framesize - 2)); - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), STACK(-framesize - 2), STR_PTR, 0); - } - - /* Even if the match is empty, we need to reset the control head. */ - if (needs_control_head) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack)); - - if (opcode == OP_SBRAPOS || opcode == OP_SCBRAPOS) - add_jump(compiler, &emptymatch, CMP(SLJIT_EQUAL, TMP1, 0, STR_PTR, 0)); - - if (!zero) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - - JUMPTO(SLJIT_JUMP, loop); - flush_stubs(common); - - compile_backtrackingpath(common, backtrack->top); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return NULL; - set_jumps(backtrack->own_backtracks, LABEL()); - - if (framesize < 0) - { - if (offset != 0) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr); - else - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - } - else - { - if (offset != 0) - { - /* Last alternative. */ - if (*cc == OP_KETRPOS) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), cbraprivptr); - } - else - { - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP2), STACK(-framesize - 2)); - } - } - - if (*cc == OP_KETRPOS) - break; - ccbegin = cc + 1 + LINK_SIZE; - } - -/* We don't have to restore the control head in case of a failed match. */ - -backtrack->own_backtracks = NULL; -if (!zero) - { - if (framesize < 0) - add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 0)); - else /* TMP2 is set to [private_data_ptr] above. */ - add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(TMP2), STACK(-stacksize), SLJIT_IMM, 0)); - } - -/* None of them matched. */ -set_jumps(emptymatch, LABEL()); -count_match(common); -return cc + 1 + LINK_SIZE; -} - -static SLJIT_INLINE PCRE2_SPTR get_iterator_parameters(compiler_common *common, PCRE2_SPTR cc, PCRE2_UCHAR *opcode, PCRE2_UCHAR *type, sljit_u32 *max, sljit_u32 *exact, PCRE2_SPTR *end) -{ -int class_len; - -*opcode = *cc; -*exact = 0; - -if (*opcode >= OP_STAR && *opcode <= OP_POSUPTO) - { - cc++; - *type = OP_CHAR; - } -else if (*opcode >= OP_STARI && *opcode <= OP_POSUPTOI) - { - cc++; - *type = OP_CHARI; - *opcode -= OP_STARI - OP_STAR; - } -else if (*opcode >= OP_NOTSTAR && *opcode <= OP_NOTPOSUPTO) - { - cc++; - *type = OP_NOT; - *opcode -= OP_NOTSTAR - OP_STAR; - } -else if (*opcode >= OP_NOTSTARI && *opcode <= OP_NOTPOSUPTOI) - { - cc++; - *type = OP_NOTI; - *opcode -= OP_NOTSTARI - OP_STAR; - } -else if (*opcode >= OP_TYPESTAR && *opcode <= OP_TYPEPOSUPTO) - { - cc++; - *opcode -= OP_TYPESTAR - OP_STAR; - *type = OP_END; - } -else - { - SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS || *opcode == OP_ECLASS); - *type = *opcode; - class_len = (*type < OP_XCLASS) ? (int)(1 + (32 / sizeof(PCRE2_UCHAR))) : GET(cc, 1); - *opcode = cc[class_len]; - cc++; - - if (*opcode >= OP_CRSTAR && *opcode <= OP_CRMINQUERY) - { - *opcode -= OP_CRSTAR - OP_STAR; - *end = cc + class_len; - - if (*opcode == OP_PLUS || *opcode == OP_MINPLUS) - { - *exact = 1; - *opcode -= OP_PLUS - OP_STAR; - } - return cc; - } - - if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY) - { - *opcode -= OP_CRPOSSTAR - OP_POSSTAR; - *end = cc + class_len; - - if (*opcode == OP_POSPLUS) - { - *exact = 1; - *opcode = OP_POSSTAR; - } - return cc; - } - - SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE); - *max = GET2(cc, (class_len + IMM2_SIZE)); - *exact = GET2(cc, class_len); - *end = cc + class_len + 2 * IMM2_SIZE; - - if (*max == 0) - { - SLJIT_ASSERT(*exact > 1); - if (*opcode == OP_CRRANGE) - *opcode = OP_UPTO; - else if (*opcode == OP_CRPOSRANGE) - *opcode = OP_POSUPTO; - else - *opcode = OP_MINSTAR; - return cc; - } - - *max -= *exact; - if (*max == 0) - *opcode = OP_EXACT; - else - { - SLJIT_ASSERT(*exact > 0 || *max > 1); - if (*opcode == OP_CRRANGE) - *opcode = OP_UPTO; - else if (*opcode == OP_CRPOSRANGE) - *opcode = OP_POSUPTO; - else if (*max == 1) - *opcode = OP_MINQUERY; - else - *opcode = OP_MINUPTO; - } - return cc; - } - -switch(*opcode) - { - case OP_EXACT: - *exact = GET2(cc, 0); - cc += IMM2_SIZE; - break; - - case OP_PLUS: - case OP_MINPLUS: - *exact = 1; - *opcode -= OP_PLUS - OP_STAR; - break; - - case OP_POSPLUS: - *exact = 1; - *opcode = OP_POSSTAR; - break; - - case OP_UPTO: - case OP_MINUPTO: - case OP_POSUPTO: - *max = GET2(cc, 0); - cc += IMM2_SIZE; - break; - } - -if (*type == OP_END) - { - *type = *cc; - *end = next_opcode(common, cc); - cc++; - return cc; - } - -*end = cc + 1; -#ifdef SUPPORT_UNICODE -if (common->utf && HAS_EXTRALEN(*cc)) *end += GET_EXTRALEN(*cc); -#endif -return cc; -} - -static PCRE2_SPTR compile_iterator_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent, jump_list **prev_backtracks) -{ -DEFINE_COMPILER; -backtrack_common *backtrack = NULL; -PCRE2_SPTR begin = cc; -PCRE2_UCHAR opcode; -PCRE2_UCHAR type; -sljit_u32 max = 0, exact; -sljit_s32 early_fail_ptr = PRIVATE_DATA(cc + 1); -sljit_s32 early_fail_type; -BOOL charpos_enabled, use_tmp; -PCRE2_UCHAR charpos_char; -unsigned int charpos_othercasebit; -PCRE2_SPTR end; -jump_list *no_match = NULL; -jump_list *no_char1_match = NULL; -struct sljit_jump *jump = NULL; -struct sljit_label *label; -int private_data_ptr = PRIVATE_DATA(cc); -int base = (private_data_ptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_SP); -int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr; -int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + SSIZE_OF(sw); -int tmp_base, tmp_offset; - -early_fail_type = (early_fail_ptr & 0x7); -early_fail_ptr >>= 3; - -/* During recursion, these optimizations are disabled. */ -if (common->early_fail_start_ptr == 0 && common->fast_forward_bc_ptr == NULL) - { - early_fail_ptr = 0; - early_fail_type = type_skip; - } - -SLJIT_ASSERT(common->fast_forward_bc_ptr != NULL || early_fail_ptr == 0 - || (early_fail_ptr >= common->early_fail_start_ptr && early_fail_ptr <= common->early_fail_end_ptr)); - -if (early_fail_type == type_fail) - add_jump(compiler, prev_backtracks, CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr)); - -cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &exact, &end); - -if (type != OP_EXTUNI) - { - tmp_base = TMP3; - tmp_offset = 0; - } -else - { - tmp_base = SLJIT_MEM1(SLJIT_SP); - tmp_offset = LOCAL2; - } - -if (opcode == OP_EXACT) - { - SLJIT_ASSERT(early_fail_ptr == 0 && exact >= 2); - - if (common->mode == PCRE2_JIT_COMPLETE -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - && !common->utf -#endif - && type != OP_ANYNL && type != OP_EXTUNI) - { - OP2(SLJIT_SUB, TMP1, 0, STR_END, 0, STR_PTR, 0); - add_jump(compiler, prev_backtracks, CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, IN_UCHARS(exact))); - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 32 - if (type == OP_ALLANY && !common->invalid_utf) -#else - if (type == OP_ALLANY) -#endif - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(exact)); - else - { - OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, exact); - label = LABEL(); - compile_char1_matchingpath(common, type, cc, prev_backtracks, FALSE); - OP2(SLJIT_SUB | SLJIT_SET_Z, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - } - } - else - { - SLJIT_ASSERT(tmp_base == TMP3 || common->locals_size >= 3 * SSIZE_OF(sw)); - OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, exact); - label = LABEL(); - compile_char1_matchingpath(common, type, cc, prev_backtracks, TRUE); - OP2(SLJIT_SUB | SLJIT_SET_Z, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - } - } - -if (early_fail_type == type_fail_range) - { - /* Range end first, followed by range start. */ - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + SSIZE_OF(sw)); - OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, TMP2, 0); - OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, TMP2, 0); - add_jump(compiler, prev_backtracks, CMP(SLJIT_LESS_EQUAL, TMP2, 0, TMP1, 0)); - - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr + SSIZE_OF(sw), STR_PTR, 0); - } - -if (opcode < OP_EXACT) - PUSH_BACKTRACK(sizeof(char_iterator_backtrack), begin, NULL); - -switch(opcode) - { - case OP_STAR: - case OP_UPTO: - SLJIT_ASSERT(backtrack != NULL && (early_fail_ptr == 0 || opcode == OP_STAR)); - max += exact; - - if (type == OP_EXTUNI) - { - SLJIT_ASSERT(private_data_ptr == 0); - SLJIT_ASSERT(early_fail_ptr == 0); - - if (exact == 1) - { - SLJIT_ASSERT(opcode == OP_STAR); - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - } - else - { - /* If OP_EXTUNI is present, it has a separate EXACT opcode. */ - SLJIT_ASSERT(exact == 0); - - allocate_stack(common, 2); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0); - } - - if (opcode == OP_UPTO) - { - SLJIT_ASSERT(common->locals_size >= 3 * SSIZE_OF(sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL2, SLJIT_IMM, max); - } - - label = LABEL(); - compile_char1_matchingpath(common, type, cc, &backtrack->own_backtracks, TRUE); - if (opcode == OP_UPTO) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL2); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); - jump = JUMP(SLJIT_ZERO); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL2, TMP1, 0); - } - - /* We cannot use TMP3 because of allocate_stack. */ - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - JUMPTO(SLJIT_JUMP, label); - if (jump != NULL) - JUMPHERE(jump); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - break; - } -#ifdef SUPPORT_UNICODE - else if (type == OP_ALLANY && !common->invalid_utf) -#else - else if (type == OP_ALLANY) -#endif - { - if (opcode == OP_STAR) - { - if (exact == 1) - detect_partial_match(common, prev_backtracks); - - if (private_data_ptr == 0) - allocate_stack(common, 2); - - OP1(SLJIT_MOV, base, offset0, STR_END, 0); - OP1(SLJIT_MOV, base, offset1, STR_PTR, 0); - - OP1(SLJIT_MOV, STR_PTR, 0, STR_END, 0); - process_partial_match(common); - - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_END, 0); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - break; - } -#ifdef SUPPORT_UNICODE - else if (!common->utf) -#else - else -#endif - { - /* If OP_ALLANY is present, it has a separate EXACT opcode. */ - SLJIT_ASSERT(exact == 0); - - if (private_data_ptr == 0) - allocate_stack(common, 2); - - OP1(SLJIT_MOV, base, offset1, STR_PTR, 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(max)); - - if (common->mode == PCRE2_JIT_COMPLETE) - { - OP2U(SLJIT_SUB | SLJIT_SET_GREATER, STR_PTR, 0, STR_END, 0); - SELECT(SLJIT_GREATER, STR_PTR, STR_END, 0, STR_PTR); - } - else - { - jump = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, STR_END, 0); - process_partial_match(common); - JUMPHERE(jump); - } - - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - break; - } - } - - charpos_enabled = FALSE; - charpos_char = 0; - charpos_othercasebit = 0; - - SLJIT_ASSERT(tmp_base == TMP3); - if ((type != OP_CHAR && type != OP_CHARI) && (*end == OP_CHAR || *end == OP_CHARI)) - { -#ifdef SUPPORT_UNICODE - charpos_enabled = !common->utf || !HAS_EXTRALEN(end[1]); -#else - charpos_enabled = TRUE; -#endif - if (charpos_enabled && *end == OP_CHARI && char_has_othercase(common, end + 1)) - { - charpos_othercasebit = char_get_othercase_bit(common, end + 1); - if (charpos_othercasebit == 0) - charpos_enabled = FALSE; - } - - if (charpos_enabled) - { - charpos_char = end[1]; - /* Consume the OP_CHAR opcode. */ - end += 2; -#if PCRE2_CODE_UNIT_WIDTH == 8 - SLJIT_ASSERT((charpos_othercasebit >> 8) == 0); -#elif PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - SLJIT_ASSERT((charpos_othercasebit >> 9) == 0); - if ((charpos_othercasebit & 0x100) != 0) - charpos_othercasebit = (charpos_othercasebit & 0xff) << 8; -#endif - if (charpos_othercasebit != 0) - charpos_char |= charpos_othercasebit; - - BACKTRACK_AS(char_iterator_backtrack)->charpos.charpos_enabled = TRUE; - BACKTRACK_AS(char_iterator_backtrack)->charpos.chr = charpos_char; - BACKTRACK_AS(char_iterator_backtrack)->charpos.othercasebit = charpos_othercasebit; - - if (private_data_ptr == 0) - allocate_stack(common, 2); - - use_tmp = (opcode == OP_STAR); - - if (use_tmp) - { - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0); - OP1(SLJIT_MOV, base, offset0, TMP3, 0); - } - else - { - OP1(SLJIT_MOV, base, offset1, COUNT_MATCH, 0); - OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_IMM, 0); - OP1(SLJIT_MOV, base, offset0, COUNT_MATCH, 0); - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, exact == max ? 0 : (max + 1)); - } - - /* Search the first instance of charpos_char. */ - if (exact > 0) - detect_partial_match(common, &no_match); - else - jump = JUMP(SLJIT_JUMP); - - label = LABEL(); - - if (opcode == OP_UPTO) - { - if (exact == max) - OP2(SLJIT_ADD, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - else - { - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - add_jump(compiler, &no_match, JUMP(SLJIT_ZERO)); - } - } - - compile_char1_matchingpath(common, type, cc, &no_match, FALSE); - - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0); - - if (exact == 0) - JUMPHERE(jump); - - detect_partial_match(common, &no_match); - - if (opcode == OP_UPTO && exact > 0) - { - if (exact == max) - CMPTO(SLJIT_LESS, TMP3, 0, SLJIT_IMM, exact, label); - else - CMPTO(SLJIT_GREATER, TMP3, 0, SLJIT_IMM, (max + 1) - exact, label); - } - - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - if (charpos_othercasebit != 0) - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, charpos_othercasebit); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, charpos_char, label); - - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - if (use_tmp) - { - OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, SLJIT_IMM, 0); - SELECT(SLJIT_EQUAL, TMP3, STR_PTR, 0, TMP3); - } - else - { - OP2U(SLJIT_SUB | SLJIT_SET_Z, COUNT_MATCH, 0, SLJIT_IMM, 0); - SELECT(SLJIT_EQUAL, COUNT_MATCH, STR_PTR, 0, COUNT_MATCH); - } - JUMPTO(SLJIT_JUMP, label); - - set_jumps(no_match, LABEL()); - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - if (use_tmp) - OP1(SLJIT_MOV, base, offset1, TMP3, 0); - else - { - OP1(SLJIT_MOV, TMP1, 0, base, offset1); - OP1(SLJIT_MOV, base, offset1, COUNT_MATCH, 0); - OP1(SLJIT_MOV, COUNT_MATCH, 0, TMP1, 0); - } - - add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0)); - - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - break; - } - } - - if (private_data_ptr == 0) - allocate_stack(common, 2); - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - use_tmp = (opcode == OP_STAR); - - if (common->utf) - { - if (!use_tmp) - OP1(SLJIT_MOV, base, offset0, COUNT_MATCH, 0); - - OP1(SLJIT_MOV, use_tmp ? TMP3 : COUNT_MATCH, 0, STR_PTR, 0); - } -#endif - - if (opcode == OP_UPTO) - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, exact == max ? -(sljit_sw)exact : (sljit_sw)max); - - if (opcode == OP_UPTO && exact > 0) - { - label = LABEL(); - detect_partial_match(common, &no_match); - compile_char1_matchingpath(common, type, cc, &no_char1_match, FALSE); -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - OP1(SLJIT_MOV, use_tmp ? TMP3 : COUNT_MATCH, 0, STR_PTR, 0); -#endif - - if (exact == max) - { - OP2(SLJIT_ADD | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - } - else - { - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - add_jump(compiler, &no_match, JUMP(SLJIT_ZERO)); - CMPTO(SLJIT_NOT_EQUAL, TMP3, 0, SLJIT_IMM, max - exact, label); - } - - OP1(SLJIT_MOV, base, offset1, STR_PTR, 0); - JUMPTO(SLJIT_JUMP, label); - } - else - { - OP1(SLJIT_MOV, base, offset1, STR_PTR, 0); - - detect_partial_match(common, &no_match); - label = LABEL(); - compile_char1_matchingpath(common, type, cc, &no_char1_match, FALSE); -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - OP1(SLJIT_MOV, use_tmp ? TMP3 : COUNT_MATCH, 0, STR_PTR, 0); -#endif - - if (opcode == OP_UPTO) - { - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - add_jump(compiler, &no_match, JUMP(SLJIT_ZERO)); - } - - detect_partial_match_to(common, label); - } - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - { - set_jumps(no_char1_match, LABEL()); - set_jumps(no_match, LABEL()); - if (use_tmp) - { - OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); - OP1(SLJIT_MOV, base, offset0, TMP3, 0); - } - else - { - OP1(SLJIT_MOV, STR_PTR, 0, COUNT_MATCH, 0); - OP1(SLJIT_MOV, COUNT_MATCH, 0, base, offset0); - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - } - } - else -#endif - { - if (opcode != OP_UPTO || exact == 0) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - set_jumps(no_char1_match, LABEL()); - - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - set_jumps(no_match, LABEL()); - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - } - - if (opcode == OP_UPTO) - { - if (exact > 0) - { - if (max == exact) - jump = CMP(SLJIT_GREATER_EQUAL, TMP3, 0, SLJIT_IMM, -(sljit_sw)exact); - else - jump = CMP(SLJIT_GREATER, TMP3, 0, SLJIT_IMM, max - exact); - - add_jump(compiler, &backtrack->own_backtracks, jump); - } - } - else if (exact == 1) - add_jump(compiler, &backtrack->own_backtracks, CMP(SLJIT_EQUAL, base, offset1, STR_PTR, 0)); - - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0); - - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - break; - - case OP_QUERY: - SLJIT_ASSERT(backtrack != NULL && early_fail_ptr == 0); - if (private_data_ptr == 0) - allocate_stack(common, 1); - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - compile_char1_matchingpath(common, type, cc, &backtrack->own_backtracks, TRUE); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - break; - - case OP_MINSTAR: - case OP_MINQUERY: - SLJIT_ASSERT(backtrack != NULL && (opcode == OP_MINSTAR || early_fail_ptr == 0)); - if (private_data_ptr == 0) - allocate_stack(common, 1); - - if (exact >= 1) - { - if (exact >= 2) - { - /* Extuni has a separate exact opcode. */ - SLJIT_ASSERT(tmp_base == TMP3 && early_fail_ptr == 0); - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, exact); - } - - if (opcode == OP_MINQUERY) - OP1(SLJIT_MOV, base, offset0, SLJIT_IMM, -1); - - label = LABEL(); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = label; - - compile_char1_matchingpath(common, type, cc, &backtrack->own_backtracks, TRUE); - - if (exact >= 2) - { - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - } - - if (opcode == OP_MINQUERY) - OP2(SLJIT_AND, base, offset0, base, offset0, STR_PTR, 0); - else - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - } - else - { - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - } - - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0); - break; - - case OP_MINUPTO: - SLJIT_ASSERT(backtrack != NULL && early_fail_ptr == 0); - if (private_data_ptr == 0) - allocate_stack(common, 2); - - OP1(SLJIT_MOV, base, offset1, SLJIT_IMM, max + 1); - - if (exact == 0) - { - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = LABEL(); - break; - } - - if (exact >= 2) - { - /* Extuni has a separate exact opcode. */ - SLJIT_ASSERT(tmp_base == TMP3); - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, exact); - } - - label = LABEL(); - BACKTRACK_AS(char_iterator_backtrack)->matchingpath = label; - - compile_char1_matchingpath(common, type, cc, &backtrack->own_backtracks, TRUE); - - if (exact >= 2) - { - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - } - - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - break; - - case OP_EXACT: - SLJIT_ASSERT(backtrack == NULL); - break; - - case OP_POSSTAR: - SLJIT_ASSERT(backtrack == NULL); -#if defined SUPPORT_UNICODE - if (type == OP_ALLANY && !common->invalid_utf) -#else - if (type == OP_ALLANY) -#endif - { - if (exact == 1) - detect_partial_match(common, prev_backtracks); - - OP1(SLJIT_MOV, STR_PTR, 0, STR_END, 0); - process_partial_match(common); - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_END, 0); - break; - } - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - { - SLJIT_ASSERT(tmp_base == TMP3 || common->locals_size >= 3 * SSIZE_OF(sw)); - - if (tmp_base != TMP3) - { - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL2, COUNT_MATCH, 0); - tmp_base = COUNT_MATCH; - } - - OP1(SLJIT_MOV, tmp_base, 0, exact == 1 ? SLJIT_IMM : STR_PTR, 0); - detect_partial_match(common, &no_match); - label = LABEL(); - compile_char1_matchingpath(common, type, cc, &no_match, FALSE); - OP1(SLJIT_MOV, tmp_base, 0, STR_PTR, 0); - detect_partial_match_to(common, label); - - set_jumps(no_match, LABEL()); - OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, 0); - - if (tmp_base != TMP3) - OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_MEM1(SLJIT_SP), LOCAL2); - - if (exact == 1) - add_jump(compiler, prev_backtracks, CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0)); - - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0); - break; - } -#endif - - if (exact == 1) - OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0); - - detect_partial_match(common, &no_match); - label = LABEL(); - /* Extuni never fails, so no_char1_match is not used in that case. - Anynl optionally reads an extra character on success. */ - compile_char1_matchingpath(common, type, cc, &no_char1_match, FALSE); - detect_partial_match_to(common, label); - if (type != OP_EXTUNI) - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - set_jumps(no_char1_match, LABEL()); - if (type != OP_EXTUNI) - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - set_jumps(no_match, LABEL()); - - if (exact == 1) - add_jump(compiler, prev_backtracks, CMP(SLJIT_EQUAL, tmp_base, tmp_offset, STR_PTR, 0)); - - if (early_fail_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), early_fail_ptr, STR_PTR, 0); - break; - - case OP_POSUPTO: - SLJIT_ASSERT(backtrack == NULL && early_fail_ptr == 0); - max += exact; - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (type == OP_EXTUNI || common->utf) -#else - if (type == OP_EXTUNI) -#endif - { - SLJIT_ASSERT(common->locals_size >= 3 * SSIZE_OF(sw)); - - /* Count match is not modified by compile_char1_matchingpath. */ - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL2, COUNT_MATCH, 0); - OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_IMM, exact == max ? 0 : max); - - label = LABEL(); - /* Extuni only modifies TMP3 on successful match. */ - OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); - compile_char1_matchingpath(common, type, cc, &no_match, TRUE); - - if (exact == max) - { - OP2(SLJIT_ADD, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_JUMP, label); - } - else - { - OP2(SLJIT_SUB | SLJIT_SET_Z, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1); - JUMPTO(SLJIT_NOT_ZERO, label); - OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); - } - - set_jumps(no_match, LABEL()); - - if (exact > 0) - { - if (exact == max) - OP2U(SLJIT_SUB | SLJIT_SET_LESS, COUNT_MATCH, 0, SLJIT_IMM, exact); - else - OP2U(SLJIT_SUB | SLJIT_SET_GREATER, COUNT_MATCH, 0, SLJIT_IMM, max - exact); - } - - OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_MEM1(SLJIT_SP), LOCAL2); - - if (exact > 0) - add_jump(compiler, prev_backtracks, JUMP(exact == max ? SLJIT_LESS : SLJIT_GREATER)); - OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); - break; - } - - SLJIT_ASSERT(tmp_base == TMP3); - - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, exact == max ? 0 : max); - - detect_partial_match(common, &no_match); - label = LABEL(); - compile_char1_matchingpath(common, type, cc, &no_char1_match, FALSE); - - if (exact == max) - OP2(SLJIT_ADD, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - else - { - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP3, 0, TMP3, 0, SLJIT_IMM, 1); - add_jump(compiler, &no_match, JUMP(SLJIT_ZERO)); - } - detect_partial_match_to(common, label); - OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - - set_jumps(no_char1_match, LABEL()); - OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); - set_jumps(no_match, LABEL()); - - if (exact > 0) - { - if (exact == max) - jump = CMP(SLJIT_LESS, TMP3, 0, SLJIT_IMM, exact); - else - jump = CMP(SLJIT_GREATER, TMP3, 0, SLJIT_IMM, max - exact); - - add_jump(compiler, prev_backtracks, jump); - } - break; - - case OP_POSQUERY: - SLJIT_ASSERT(backtrack == NULL && early_fail_ptr == 0); - SLJIT_ASSERT(tmp_base == TMP3 || common->locals_size >= 3 * SSIZE_OF(sw)); - OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0); - compile_char1_matchingpath(common, type, cc, &no_match, TRUE); - OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0); - set_jumps(no_match, LABEL()); - OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset); - break; - - default: - SLJIT_UNREACHABLE(); - break; - } - -count_match(common); -return end; -} - -static SLJIT_INLINE PCRE2_SPTR compile_fail_accept_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; - -PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL); - -if (*cc == OP_FAIL) - { - add_jump(compiler, &backtrack->own_backtracks, JUMP(SLJIT_JUMP)); - return cc + 1; - } - -if (*cc == OP_ACCEPT && common->currententry == NULL && (common->re->overall_options & PCRE2_ENDANCHORED) != 0) - add_jump(compiler, &common->restart_match, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, STR_END, 0)); - -if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty) - { - /* No need to check notempty conditions. */ - if (common->accept_label == NULL) - add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP)); - else - JUMPTO(SLJIT_JUMP, common->accept_label); - return cc + 1; - } - -if (common->accept_label == NULL) - add_jump(compiler, &common->accept, CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0))); -else - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), common->accept_label); - -if (HAS_VIRTUAL_REGISTERS) - { - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV_U32, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, options)); - } -else - OP1(SLJIT_MOV_U32, TMP2, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, options)); - -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, PCRE2_NOTEMPTY); -add_jump(compiler, &backtrack->own_backtracks, JUMP(SLJIT_NOT_ZERO)); -OP2U(SLJIT_AND | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, PCRE2_NOTEMPTY_ATSTART); -if (common->accept_label == NULL) - add_jump(compiler, &common->accept, JUMP(SLJIT_ZERO)); -else - JUMPTO(SLJIT_ZERO, common->accept_label); - -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(HAS_VIRTUAL_REGISTERS ? TMP1 : ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, str)); -if (common->accept_label == NULL) - add_jump(compiler, &common->accept, CMP(SLJIT_NOT_EQUAL, TMP2, 0, STR_PTR, 0)); -else - CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->accept_label); -add_jump(compiler, &backtrack->own_backtracks, JUMP(SLJIT_JUMP)); -return cc + 1; -} - -static SLJIT_INLINE PCRE2_SPTR compile_close_matchingpath(compiler_common *common, PCRE2_SPTR cc) -{ -DEFINE_COMPILER; -int offset = GET2(cc, 1); -BOOL optimized_cbracket = common->optimized_cbracket[offset] != 0; - -/* Data will be discarded anyway... */ -if (common->currententry != NULL) - return cc + 1 + IMM2_SIZE; - -if (!optimized_cbracket) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR_PRIV(offset)); -offset <<= 1; -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0); -if (!optimized_cbracket) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0); -return cc + 1 + IMM2_SIZE; -} - -static SLJIT_INLINE PCRE2_SPTR compile_control_verb_matchingpath(compiler_common *common, PCRE2_SPTR cc, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; -PCRE2_UCHAR opcode = *cc; -PCRE2_SPTR ccend = cc + 1; - -if (opcode == OP_COMMIT_ARG || opcode == OP_PRUNE_ARG || - opcode == OP_SKIP_ARG || opcode == OP_THEN_ARG) - ccend += 2 + cc[1]; - -PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL); - -if (opcode == OP_SKIP) - { - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - return ccend; - } - -if (opcode == OP_COMMIT_ARG || opcode == OP_PRUNE_ARG || opcode == OP_THEN_ARG) - { - if (HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, TMP2, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(HAS_VIRTUAL_REGISTERS ? TMP1 : ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0); - } - -return ccend; -} - -static PCRE2_UCHAR then_trap_opcode[1] = { OP_THEN_TRAP }; - -static SLJIT_INLINE void compile_then_trap_matchingpath(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; -BOOL needs_control_head; -int size; - -PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc); -common->then_trap = BACKTRACK_AS(then_trap_backtrack); -BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode; -BACKTRACK_AS(then_trap_backtrack)->start = (sljit_sw)(cc - common->start); -BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head); - -size = BACKTRACK_AS(then_trap_backtrack)->framesize; -size = 3 + (size < 0 ? 0 : size); - -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); -allocate_stack(common, size); -if (size > 3) - OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw)); -else - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, STACK_TOP, 0); -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start); -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap); -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0); - -size = BACKTRACK_AS(then_trap_backtrack)->framesize; -if (size >= 0) - init_frame(common, cc, ccend, size - 1, 0); -} - -static void compile_matchingpath(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend, backtrack_common *parent) -{ -DEFINE_COMPILER; -backtrack_common *backtrack; -BOOL has_then_trap = FALSE; -then_trap_backtrack *save_then_trap = NULL; -size_t op_len; - -SLJIT_ASSERT(*ccend == OP_END || (*ccend >= OP_ALT && *ccend <= OP_KETRPOS)); - -if (common->has_then && common->then_offsets[cc - common->start] != 0) - { - SLJIT_ASSERT(*ccend != OP_END && common->control_head_ptr != 0); - has_then_trap = TRUE; - save_then_trap = common->then_trap; - /* Tail item on backtrack. */ - compile_then_trap_matchingpath(common, cc, ccend, parent); - } - -while (cc < ccend) - { - switch(*cc) - { - case OP_SOD: - case OP_SOM: - case OP_NOT_WORD_BOUNDARY: - case OP_WORD_BOUNDARY: - case OP_EODN: - case OP_EOD: - case OP_DOLL: - case OP_DOLLM: - case OP_CIRC: - case OP_CIRCM: - case OP_NOT_UCP_WORD_BOUNDARY: - case OP_UCP_WORD_BOUNDARY: - cc = compile_simple_assertion_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks); - break; - - case OP_NOT_DIGIT: - case OP_DIGIT: - case OP_NOT_WHITESPACE: - case OP_WHITESPACE: - case OP_NOT_WORDCHAR: - case OP_WORDCHAR: - case OP_ANY: - case OP_ALLANY: - case OP_ANYBYTE: - case OP_NOTPROP: - case OP_PROP: - case OP_ANYNL: - case OP_NOT_HSPACE: - case OP_HSPACE: - case OP_NOT_VSPACE: - case OP_VSPACE: - case OP_EXTUNI: - case OP_NOT: - case OP_NOTI: - cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks, TRUE); - break; - - case OP_SET_SOM: - PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)); - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - cc++; - break; - - case OP_CHAR: - case OP_CHARI: - if (common->mode == PCRE2_JIT_COMPLETE) - cc = compile_charn_matchingpath(common, cc, ccend, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks); - else - cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks, TRUE); - break; - - case OP_STAR: - case OP_MINSTAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_QUERY: - case OP_MINQUERY: - case OP_UPTO: - case OP_MINUPTO: - case OP_EXACT: - case OP_POSSTAR: - case OP_POSPLUS: - case OP_POSQUERY: - case OP_POSUPTO: - case OP_STARI: - case OP_MINSTARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_UPTOI: - case OP_MINUPTOI: - case OP_EXACTI: - case OP_POSSTARI: - case OP_POSPLUSI: - case OP_POSQUERYI: - case OP_POSUPTOI: - case OP_NOTSTAR: - case OP_NOTMINSTAR: - case OP_NOTPLUS: - case OP_NOTMINPLUS: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTEXACT: - case OP_NOTPOSSTAR: - case OP_NOTPOSPLUS: - case OP_NOTPOSQUERY: - case OP_NOTPOSUPTO: - case OP_NOTSTARI: - case OP_NOTMINSTARI: - case OP_NOTPLUSI: - case OP_NOTMINPLUSI: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTEXACTI: - case OP_NOTPOSSTARI: - case OP_NOTPOSPLUSI: - case OP_NOTPOSQUERYI: - case OP_NOTPOSUPTOI: - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEEXACT: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - case OP_TYPEPOSUPTO: - cc = compile_iterator_matchingpath(common, cc, parent, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks); - break; - - case OP_CLASS: - case OP_NCLASS: - if (cc[1 + (32 / sizeof(PCRE2_UCHAR))] >= OP_CRSTAR && cc[1 + (32 / sizeof(PCRE2_UCHAR))] <= OP_CRPOSRANGE) - cc = compile_iterator_matchingpath(common, cc, parent, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks); - else - cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks, TRUE); - break; - -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 - case OP_XCLASS: - case OP_ECLASS: - op_len = GET(cc, 1); - if (cc[op_len] >= OP_CRSTAR && cc[op_len] <= OP_CRPOSRANGE) - cc = compile_iterator_matchingpath(common, cc, parent, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks); - else - cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks, TRUE); - break; -#endif - - case OP_REF: - case OP_REFI: - op_len = PRIV(OP_lengths)[*cc]; - if (cc[op_len] >= OP_CRSTAR && cc[op_len] <= OP_CRPOSRANGE) - cc = compile_ref_iterator_matchingpath(common, cc, parent); - else - { - compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks, TRUE, FALSE); - cc += op_len; - } - break; - - case OP_DNREF: - case OP_DNREFI: - op_len = PRIV(OP_lengths)[*cc]; - if (cc[op_len] >= OP_CRSTAR && cc[op_len] <= OP_CRPOSRANGE) - cc = compile_ref_iterator_matchingpath(common, cc, parent); - else - { - compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks); - compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->simple_backtracks : &parent->own_backtracks, TRUE, FALSE); - cc += op_len; - } - break; - - case OP_RECURSE: - cc = compile_recurse_matchingpath(common, cc, parent); - break; - - case OP_CALLOUT: - case OP_CALLOUT_STR: - cc = compile_callout_matchingpath(common, cc, parent); - break; - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - PUSH_BACKTRACK_NOVALUE(sizeof(assert_backtrack), cc); - cc = compile_assert_matchingpath(common, cc, BACKTRACK_AS(assert_backtrack), FALSE); - break; - - case OP_BRAMINZERO: - PUSH_BACKTRACK_NOVALUE(sizeof(braminzero_backtrack), cc); - cc = bracketend(cc + 1); - if (*(cc - 1 - LINK_SIZE) != OP_KETRMIN) - { - allocate_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - } - else - { - allocate_stack(common, 2); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), STR_PTR, 0); - } - BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL(); - count_match(common); - break; - - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_BRA: - case OP_CBRA: - case OP_COND: - case OP_SBRA: - case OP_SCBRA: - case OP_SCOND: - cc = compile_bracket_matchingpath(common, cc, parent); - break; - - case OP_BRAZERO: - if (cc[1] > OP_ASSERTBACK_NOT) - cc = compile_bracket_matchingpath(common, cc, parent); - else - { - PUSH_BACKTRACK_NOVALUE(sizeof(assert_backtrack), cc); - cc = compile_assert_matchingpath(common, cc, BACKTRACK_AS(assert_backtrack), FALSE); - } - break; - - case OP_BRAPOS: - case OP_CBRAPOS: - case OP_SBRAPOS: - case OP_SCBRAPOS: - case OP_BRAPOSZERO: - cc = compile_bracketpos_matchingpath(common, cc, parent); - break; - - case OP_MARK: - PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc); - SLJIT_ASSERT(common->mark_ptr != 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); - allocate_stack(common, common->has_skip_arg ? 5 : 1); - if (HAS_VIRTUAL_REGISTERS) - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0), TMP2, 0); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, TMP2, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(HAS_VIRTUAL_REGISTERS ? TMP1 : ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0); - if (common->has_skip_arg) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, STACK_TOP, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0); - } - cc += 1 + 2 + cc[1]; - break; - - case OP_PRUNE: - case OP_PRUNE_ARG: - case OP_SKIP: - case OP_SKIP_ARG: - case OP_THEN: - case OP_THEN_ARG: - case OP_COMMIT: - case OP_COMMIT_ARG: - cc = compile_control_verb_matchingpath(common, cc, parent); - break; - - case OP_FAIL: - case OP_ACCEPT: - case OP_ASSERT_ACCEPT: - cc = compile_fail_accept_matchingpath(common, cc, parent); - break; - - case OP_CLOSE: - cc = compile_close_matchingpath(common, cc); - break; - - case OP_SKIPZERO: - cc = bracketend(cc + 1); - break; - - default: - SLJIT_UNREACHABLE(); - return; - } - if (cc == NULL) - return; - } - -if (has_then_trap) - { - /* Head item on backtrack. */ - PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc); - BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode; - BACKTRACK_AS(then_trap_backtrack)->then_trap = common->then_trap; - common->then_trap = save_then_trap; - } -SLJIT_ASSERT(cc == ccend); -} - -#undef PUSH_BACKTRACK -#undef PUSH_BACKTRACK_NOVALUE -#undef BACKTRACK_AS - -#define COMPILE_BACKTRACKINGPATH(current) \ - do \ - { \ - compile_backtrackingpath(common, (current)); \ - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \ - return; \ - } \ - while (0) - -#define CURRENT_AS(type) ((type *)current) - -static void compile_newline_move_back(compiler_common *common) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; - -OP2(SLJIT_SUB, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); -jump = CMP(SLJIT_LESS_EQUAL, TMP1, 0, TMP2, 0); -/* All newlines are single byte, or their last byte -is not equal to CHAR_NL/CHAR_CR even if UTF is enabled. */ -OP1(MOV_UCHAR, SLJIT_TMP_DEST_REG, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2)); -OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); -OP2(SLJIT_SHL, SLJIT_TMP_DEST_REG, 0, SLJIT_TMP_DEST_REG, 0, SLJIT_IMM, 8); -OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_TMP_DEST_REG, 0); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_CR << 8 | CHAR_NL); -OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_EQUAL); -#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 -OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); -#endif -OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); -JUMPHERE(jump); -} - -static void compile_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -PCRE2_SPTR cc = current->cc; -PCRE2_UCHAR opcode; -PCRE2_UCHAR type; -sljit_u32 max = 0, exact; -struct sljit_label *label = NULL; -struct sljit_jump *jump = NULL; -jump_list *jumplist = NULL; -PCRE2_SPTR end; -int private_data_ptr = PRIVATE_DATA(cc); -int base = (private_data_ptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_SP); -int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr; -int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + SSIZE_OF(sw); - -cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &exact, &end); - -switch(opcode) - { - case OP_STAR: - case OP_UPTO: - if (type == OP_EXTUNI) - { - SLJIT_ASSERT(private_data_ptr == 0); - set_jumps(current->own_backtracks, LABEL()); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(char_iterator_backtrack)->matchingpath); - } - else - { - if (CURRENT_AS(char_iterator_backtrack)->charpos.charpos_enabled) - { - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - OP1(SLJIT_MOV, TMP2, 0, base, offset1); - - jump = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0); - label = LABEL(); - if (type == OP_ANYNL) - compile_newline_move_back(common); - move_back(common, NULL, TRUE); - - OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); - if (CURRENT_AS(char_iterator_backtrack)->charpos.othercasebit != 0) - OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, CURRENT_AS(char_iterator_backtrack)->charpos.othercasebit); - CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CURRENT_AS(char_iterator_backtrack)->charpos.chr, CURRENT_AS(char_iterator_backtrack)->matchingpath); - /* The range beginning must match, no need to compare. */ - JUMPTO(SLJIT_JUMP, label); - - set_jumps(current->own_backtracks, LABEL()); - current->own_backtracks = NULL; - } - else - { - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - - if (opcode == OP_STAR && exact == 1) - { - if (type == OP_ANYNL) - { - OP1(SLJIT_MOV, TMP2, 0, base, offset1); - compile_newline_move_back(common); - } - - move_back(common, NULL, TRUE); - jump = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, base, offset1); - } - else - { - if (type == OP_ANYNL) - { - OP1(SLJIT_MOV, TMP2, 0, base, offset1); - jump = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0); - compile_newline_move_back(common); - } - else - jump = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, base, offset1); - - move_back(common, NULL, TRUE); - } - - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - JUMPTO(SLJIT_JUMP, CURRENT_AS(char_iterator_backtrack)->matchingpath); - - set_jumps(current->own_backtracks, LABEL()); - } - - JUMPHERE(jump); - if (private_data_ptr == 0) - free_stack(common, 2); - } - break; - - case OP_QUERY: - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - OP1(SLJIT_MOV, base, offset0, SLJIT_IMM, 0); - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(char_iterator_backtrack)->matchingpath); - jump = JUMP(SLJIT_JUMP); - set_jumps(current->own_backtracks, LABEL()); - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - OP1(SLJIT_MOV, base, offset0, SLJIT_IMM, 0); - JUMPTO(SLJIT_JUMP, CURRENT_AS(char_iterator_backtrack)->matchingpath); - JUMPHERE(jump); - if (private_data_ptr == 0) - free_stack(common, 1); - break; - - case OP_MINSTAR: - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - if (exact == 0) - { - compile_char1_matchingpath(common, type, cc, &jumplist, TRUE); - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - } - else if (exact > 1) - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1); - - JUMPTO(SLJIT_JUMP, CURRENT_AS(char_iterator_backtrack)->matchingpath); - set_jumps(exact > 0 ? current->own_backtracks : jumplist, LABEL()); - if (private_data_ptr == 0) - free_stack(common, 1); - break; - - case OP_MINUPTO: - OP1(SLJIT_MOV, TMP1, 0, base, offset1); - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - OP2(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); - - if (exact == 0) - { - add_jump(compiler, &jumplist, JUMP(SLJIT_ZERO)); - - OP1(SLJIT_MOV, base, offset1, TMP1, 0); - compile_char1_matchingpath(common, type, cc, &jumplist, TRUE); - OP1(SLJIT_MOV, base, offset0, STR_PTR, 0); - JUMPTO(SLJIT_JUMP, CURRENT_AS(char_iterator_backtrack)->matchingpath); - - set_jumps(jumplist, LABEL()); - } - else - { - if (exact > 1) - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1); - OP1(SLJIT_MOV, base, offset1, TMP1, 0); - JUMPTO(SLJIT_NOT_ZERO, CURRENT_AS(char_iterator_backtrack)->matchingpath); - - set_jumps(current->own_backtracks, LABEL()); - } - - if (private_data_ptr == 0) - free_stack(common, 2); - break; - - case OP_MINQUERY: - OP1(SLJIT_MOV, STR_PTR, 0, base, offset0); - OP1(SLJIT_MOV, base, offset0, SLJIT_IMM, 0); - - if (exact >= 1) - { - if (exact >= 2) - OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1); - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(char_iterator_backtrack)->matchingpath); - set_jumps(current->own_backtracks, LABEL()); - } - else - { - jump = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0); - compile_char1_matchingpath(common, type, cc, &jumplist, TRUE); - JUMPTO(SLJIT_JUMP, CURRENT_AS(char_iterator_backtrack)->matchingpath); - set_jumps(jumplist, LABEL()); - JUMPHERE(jump); - } - - if (private_data_ptr == 0) - free_stack(common, 1); - break; - - default: - SLJIT_UNREACHABLE(); - break; - } -} - -static SLJIT_INLINE void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -PCRE2_SPTR cc = current->cc; -BOOL ref = (*cc == OP_REF || *cc == OP_REFI); -PCRE2_UCHAR type; - -type = cc[PRIV(OP_lengths)[*cc]]; - -if ((type & 0x1) == 0) - { - /* Maximize case. */ - set_jumps(current->own_backtracks, LABEL()); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(ref_iterator_backtrack)->matchingpath); - return; - } - -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); -CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(ref_iterator_backtrack)->matchingpath); -set_jumps(current->own_backtracks, LABEL()); -free_stack(common, ref ? 2 : 3); -} - -static SLJIT_INLINE void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -recurse_entry *entry; - -if (!CURRENT_AS(recurse_backtrack)->inlined_pattern) - { - entry = CURRENT_AS(recurse_backtrack)->entry; - if (entry->backtrack_label == NULL) - add_jump(compiler, &entry->backtrack_calls, JUMP(SLJIT_FAST_CALL)); - else - JUMPTO(SLJIT_FAST_CALL, entry->backtrack_label); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, CURRENT_AS(recurse_backtrack)->matchingpath); - } -else - compile_backtrackingpath(common, current->top); - -set_jumps(current->own_backtracks, LABEL()); -} - -static void compile_assert_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -PCRE2_SPTR cc = current->cc; -PCRE2_UCHAR bra = OP_BRA; -struct sljit_jump *brajump = NULL; - -SLJIT_ASSERT(*cc != OP_BRAMINZERO); -if (*cc == OP_BRAZERO) - { - bra = *cc; - cc++; - } - -if (bra == OP_BRAZERO) - { - SLJIT_ASSERT(current->own_backtracks == NULL); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - } - -if (CURRENT_AS(assert_backtrack)->framesize < 0) - { - set_jumps(current->own_backtracks, LABEL()); - - if (bra == OP_BRAZERO) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(assert_backtrack)->matchingpath); - free_stack(common, 1); - } - return; - } - -if (bra == OP_BRAZERO) - { - if (*cc == OP_ASSERT_NOT || *cc == OP_ASSERTBACK_NOT) - { - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(assert_backtrack)->matchingpath); - free_stack(common, 1); - return; - } - free_stack(common, 1); - brajump = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0); - } - -if (*cc == OP_ASSERT || *cc == OP_ASSERTBACK) - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(assert_backtrack)->private_data_ptr); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(-2)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (CURRENT_AS(assert_backtrack)->framesize - 1) * sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(assert_backtrack)->private_data_ptr, TMP1, 0); - - set_jumps(current->own_backtracks, LABEL()); - } -else - set_jumps(current->own_backtracks, LABEL()); - -if (bra == OP_BRAZERO) - { - /* We know there is enough place on the stack. */ - OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0); - JUMPTO(SLJIT_JUMP, CURRENT_AS(assert_backtrack)->matchingpath); - JUMPHERE(brajump); - } -} - -static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -int opcode, stacksize, alt_count, alt_max; -int offset = 0; -int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr; -int repeat_ptr = 0, repeat_type = 0, repeat_count = 0; -PCRE2_SPTR cc = current->cc; -PCRE2_SPTR ccbegin; -PCRE2_SPTR ccprev; -PCRE2_UCHAR bra = OP_BRA; -PCRE2_UCHAR ket; -const assert_backtrack *assert; -BOOL has_alternatives; -BOOL needs_control_head = FALSE; -BOOL has_vreverse; -struct sljit_jump *brazero = NULL; -struct sljit_jump *next_alt = NULL; -struct sljit_jump *once = NULL; -struct sljit_jump *cond = NULL; -struct sljit_label *rmin_label = NULL; -struct sljit_label *exact_label = NULL; -struct sljit_jump *mov_addr = NULL; - -if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO) - { - bra = *cc; - cc++; - } - -opcode = *cc; -ccbegin = bracketend(cc) - 1 - LINK_SIZE; -ket = *ccbegin; -if (ket == OP_KET && PRIVATE_DATA(ccbegin) != 0) - { - repeat_ptr = PRIVATE_DATA(ccbegin); - repeat_type = PRIVATE_DATA(ccbegin + 2); - repeat_count = PRIVATE_DATA(ccbegin + 3); - SLJIT_ASSERT(repeat_type != 0 && repeat_count != 0); - if (repeat_type == OP_UPTO) - ket = OP_KETRMAX; - if (repeat_type == OP_MINUPTO) - ket = OP_KETRMIN; - } -ccbegin = cc; -cc += GET(cc, 1); -has_alternatives = *cc == OP_ALT; -if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND)) - has_alternatives = (ccbegin[1 + LINK_SIZE] >= OP_ASSERT && ccbegin[1 + LINK_SIZE] <= OP_ASSERTBACK_NOT) || CURRENT_AS(bracket_backtrack)->u.no_capture != NULL; -if (opcode == OP_CBRA || opcode == OP_SCBRA) - offset = (GET2(ccbegin, 1 + LINK_SIZE)) << 1; -if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN)) - opcode = OP_SCOND; - -alt_max = has_alternatives ? no_alternatives(ccbegin) : 0; - -/* Decoding the needs_control_head in framesize. */ -if (opcode == OP_ONCE) - { - needs_control_head = (CURRENT_AS(bracket_backtrack)->u.framesize & 0x1) != 0; - CURRENT_AS(bracket_backtrack)->u.framesize >>= 1; - } - -if (ket != OP_KET && repeat_type != 0) - { - /* TMP1 is used in OP_KETRMIN below. */ - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - if (repeat_type == OP_UPTO) - OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), repeat_ptr, TMP1, 0, SLJIT_IMM, 1); - else - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, TMP1, 0); - } - -if (ket == OP_KETRMAX) - { - if (bra == OP_BRAZERO) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - brazero = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0); - } - } -else if (ket == OP_KETRMIN) - { - if (bra != OP_BRAMINZERO) - { - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - if (repeat_type != 0) - { - /* TMP1 was set a few lines above. */ - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath); - /* Drop STR_PTR for non-greedy plus quantifier. */ - if (opcode != OP_ONCE) - free_stack(common, 1); - } - else if (opcode >= OP_SBRA || opcode == OP_ONCE) - { - /* Checking zero-length iteration. */ - if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0) - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr, CURRENT_AS(bracket_backtrack)->recursive_matchingpath); - else - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), STACK(-CURRENT_AS(bracket_backtrack)->u.framesize - 2), CURRENT_AS(bracket_backtrack)->recursive_matchingpath); - } - /* Drop STR_PTR for non-greedy plus quantifier. */ - if (opcode != OP_ONCE) - free_stack(common, 1); - } - else - JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursive_matchingpath); - } - rmin_label = LABEL(); - if (repeat_type != 0) - OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1); - } -else if (bra == OP_BRAZERO) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - brazero = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0); - } -else if (repeat_type == OP_EXACT) - { - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1); - exact_label = LABEL(); - } - -if (offset != 0) - { - if (common->capture_last_ptr != 0) - { - SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, TMP1, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2)); - free_stack(common, 3); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP2, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP1, 0); - } - else if (common->optimized_cbracket[offset >> 1] == 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - free_stack(common, 2); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP2, 0); - } - } -else if (SLJIT_UNLIKELY(opcode == OP_ASSERT_SCS)) - { - OP1(SLJIT_MOV, TMP1, 0, STR_END, 0); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw), TMP1, 0); - - /* Nested scs blocks will not update this variable. */ - if (common->restore_end_ptr == 0) - common->restore_end_ptr = private_data_ptr + sizeof(sljit_sw); - } - -if (SLJIT_UNLIKELY(opcode == OP_ONCE)) - { - int framesize = CURRENT_AS(bracket_backtrack)->u.framesize; - - SLJIT_ASSERT(framesize != 0); - if (framesize > 0) - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize - 1) * sizeof(sljit_sw)); - } - once = JUMP(SLJIT_JUMP); - } -else if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND)) - { - if (has_alternatives) - { - /* Always exactly one alternative. */ - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - - alt_max = 2; - next_alt = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0); - } - } -else if (has_alternatives) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - - if (alt_max > 3) - { - sljit_emit_ijump(compiler, SLJIT_JUMP, TMP1, 0); - - SLJIT_ASSERT(CURRENT_AS(bracket_backtrack)->matching_mov_addr != NULL); - sljit_set_label(CURRENT_AS(bracket_backtrack)->matching_mov_addr, LABEL()); - sljit_emit_op0(compiler, SLJIT_ENDBR); - } - else - next_alt = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0); - } - -COMPILE_BACKTRACKINGPATH(current->top); -if (current->own_backtracks) - set_jumps(current->own_backtracks, LABEL()); - -if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND)) - { - /* Conditional block always has at most one alternative. */ - if (ccbegin[1 + LINK_SIZE] >= OP_ASSERT && ccbegin[1 + LINK_SIZE] <= OP_ASSERTBACK_NOT) - { - SLJIT_ASSERT(has_alternatives); - assert = CURRENT_AS(bracket_backtrack)->u.assert; - SLJIT_ASSERT(assert->framesize != 0); - if (assert->framesize > 0 && (ccbegin[1 + LINK_SIZE] == OP_ASSERT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK)) - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(-2)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (assert->framesize - 1) * sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr, TMP1, 0); - } - cond = JUMP(SLJIT_JUMP); - set_jumps(CURRENT_AS(bracket_backtrack)->u.assert->condfailed, LABEL()); - } - else if (CURRENT_AS(bracket_backtrack)->u.no_capture != NULL) - { - SLJIT_ASSERT(has_alternatives); - cond = JUMP(SLJIT_JUMP); - set_jumps(CURRENT_AS(bracket_backtrack)->u.no_capture, LABEL()); - } - else - SLJIT_ASSERT(!has_alternatives); - } - -if (has_alternatives) - { - alt_count = 1; - do - { - current->top = NULL; - current->own_backtracks = NULL; - current->simple_backtracks = NULL; - /* Conditional blocks always have an additional alternative, even if it is empty. */ - if (*cc == OP_ALT) - { - ccprev = cc + 1 + LINK_SIZE; - cc += GET(cc, 1); - - has_vreverse = FALSE; - - switch (opcode) - { - case OP_ASSERTBACK: - case OP_ASSERTBACK_NA: - SLJIT_ASSERT(private_data_ptr != 0); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - - has_vreverse = (*ccprev == OP_VREVERSE); - if (*ccprev == OP_REVERSE || has_vreverse) - ccprev = compile_reverse_matchingpath(common, ccprev, current); - break; - case OP_ASSERT_SCS: - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(2)); - break; - case OP_ONCE: - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(needs_control_head ? 1 : 0)); - break; - case OP_COND: - case OP_SCOND: - break; - default: - if (private_data_ptr != 0) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - else - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - break; - } - - compile_matchingpath(common, ccprev, cc, current); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return; - - switch (opcode) - { - case OP_ASSERTBACK_NA: - if (has_vreverse) - { - SLJIT_ASSERT(current->top != NULL && PRIVATE_DATA(ccbegin + 1)); - add_jump(compiler, ¤t->top->simple_backtracks, CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0)); - } - - if (PRIVATE_DATA(ccbegin + 1)) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - break; - case OP_ASSERT_NA: - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr); - break; - case OP_SCRIPT_RUN: - match_script_run_common(common, private_data_ptr, current); - break; - } - } - - /* Instructions after the current alternative is successfully matched. */ - /* There is a similar code in compile_bracket_matchingpath. */ - if (opcode == OP_ONCE) - match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head); - - stacksize = 0; - if (repeat_type == OP_MINUPTO) - { - /* We need to preserve the counter. TMP2 will be used below. */ - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr); - stacksize++; - } - if (ket != OP_KET || bra != OP_BRA) - stacksize++; - if (offset != 0) - { - if (common->capture_last_ptr != 0) - stacksize++; - if (common->optimized_cbracket[offset >> 1] == 0) - stacksize += 2; - } - if (opcode != OP_ONCE) - stacksize++; - - if (stacksize > 0) - allocate_stack(common, stacksize); - - stacksize = 0; - if (repeat_type == OP_MINUPTO) - { - /* TMP2 was set above. */ - OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1); - stacksize++; - } - - if (ket != OP_KET || bra != OP_BRA) - { - if (ket != OP_KET) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0); - else - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0); - stacksize++; - } - - if (offset != 0) - stacksize = match_capture_common(common, stacksize, offset, private_data_ptr); - - if (opcode != OP_ONCE) - { - if (alt_max <= 3) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, alt_count); - else - mov_addr = sljit_emit_mov_addr(compiler, SLJIT_MEM1(STACK_TOP), STACK(stacksize)); - } - - if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0) - { - /* If ket is not OP_KETRMAX, this code path is executed after the jump to alternative_matchingpath. */ - SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0); - } - - JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath); - - if (opcode != OP_ONCE) - { - if (alt_max <= 3) - { - JUMPHERE(next_alt); - alt_count++; - if (alt_count < alt_max) - { - SLJIT_ASSERT(alt_count == 2 && alt_max == 3); - next_alt = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 1); - } - } - else - { - sljit_set_label(mov_addr, LABEL()); - sljit_emit_op0(compiler, SLJIT_ENDBR); - } - } - - COMPILE_BACKTRACKINGPATH(current->top); - if (current->own_backtracks) - set_jumps(current->own_backtracks, LABEL()); - SLJIT_ASSERT(!current->simple_backtracks); - } - while (*cc == OP_ALT); - - if (cond != NULL) - { - SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND); - if (ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) - { - assert = CURRENT_AS(bracket_backtrack)->u.assert; - SLJIT_ASSERT(assert->framesize != 0); - if (assert->framesize > 0) - { - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr); - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(-2)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (assert->framesize - 1) * sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), assert->private_data_ptr, TMP1, 0); - } - } - JUMPHERE(cond); - } - - /* Free the STR_PTR. */ - if (private_data_ptr == 0) - free_stack(common, 1); - } - -if (offset != 0) - { - /* Using both tmp register is better for instruction scheduling. */ - if (common->optimized_cbracket[offset >> 1] != 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - free_stack(common, 2); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP2, 0); - } - else - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - } - } -else if (opcode == OP_ASSERTBACK_NA && PRIVATE_DATA(ccbegin + 1)) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw), TMP2, 0); - free_stack(common, 4); - } -else if (opcode == OP_ASSERT_NA || opcode == OP_ASSERTBACK_NA || opcode == OP_SCRIPT_RUN || opcode == OP_SBRA || opcode == OP_SCOND) - { - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - } -else if (opcode == OP_ASSERT_SCS) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr + sizeof(sljit_sw), TMP2, 0); - free_stack(common, has_alternatives ? 3 : 2); - - set_jumps(CURRENT_AS(bracket_backtrack)->u.no_capture, LABEL()); - - /* Nested scs blocks will not update this variable. */ - if (common->restore_end_ptr == private_data_ptr + SSIZE_OF(sw)) - common->restore_end_ptr = 0; - } -else if (opcode == OP_ONCE) - { - cc = ccbegin + GET(ccbegin, 1); - stacksize = needs_control_head ? 1 : 0; - - if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0) - { - /* Reset head and drop saved frame. */ - stacksize += CURRENT_AS(bracket_backtrack)->u.framesize + ((ket != OP_KET || *cc == OP_ALT) ? 2 : 1); - } - else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN)) - { - /* The STR_PTR must be released. */ - stacksize++; - } - - if (stacksize > 0) - free_stack(common, stacksize); - - JUMPHERE(once); - /* Restore previous private_data_ptr */ - if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(-CURRENT_AS(bracket_backtrack)->u.framesize - 1)); - else if (ket == OP_KETRMIN) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - /* See the comment below. */ - free_stack(common, 2); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), private_data_ptr, TMP1, 0); - } - } - -if (repeat_type == OP_EXACT) - { - OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_SP), repeat_ptr, SLJIT_IMM, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), repeat_ptr, TMP1, 0); - CMPTO(SLJIT_LESS_EQUAL, TMP1, 0, SLJIT_IMM, repeat_count, exact_label); - } -else if (ket == OP_KETRMAX) - { - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - if (bra != OP_BRAZERO) - free_stack(common, 1); - - CMPTO(SLJIT_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath); - if (bra == OP_BRAZERO) - { - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->zero_matchingpath); - JUMPHERE(brazero); - free_stack(common, 1); - } - } -else if (ket == OP_KETRMIN) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - - /* OP_ONCE removes everything in case of a backtrack, so we don't - need to explicitly release the STR_PTR. The extra release would - affect badly the free_stack(2) above. */ - if (opcode != OP_ONCE) - free_stack(common, 1); - CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, rmin_label); - if (opcode == OP_ONCE) - free_stack(common, bra == OP_BRAMINZERO ? 2 : 1); - else if (bra == OP_BRAMINZERO) - free_stack(common, 1); - } -else if (bra == OP_BRAZERO) - { - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->zero_matchingpath); - JUMPHERE(brazero); - } -} - -static SLJIT_INLINE void compile_bracketpos_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -int offset; -struct sljit_jump *jump; -PCRE2_SPTR cc; - -/* No retry on backtrack, just drop everything. */ -if (CURRENT_AS(bracketpos_backtrack)->framesize < 0) - { - cc = current->cc; - - if (*cc == OP_BRAPOSZERO) - cc++; - - if (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS) - { - offset = (GET2(cc, 1 + LINK_SIZE)) << 1; - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0); - if (common->capture_last_ptr != 0) - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2)); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), TMP2, 0); - if (common->capture_last_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, TMP1, 0); - } - set_jumps(current->own_backtracks, LABEL()); - free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize); - return; - } - -OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(bracketpos_backtrack)->private_data_ptr); -add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); -OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (CURRENT_AS(bracketpos_backtrack)->framesize - 1) * sizeof(sljit_sw)); - -if (current->own_backtracks) - { - jump = JUMP(SLJIT_JUMP); - set_jumps(current->own_backtracks, LABEL()); - /* Drop the stack frame. */ - free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize); - JUMPHERE(jump); - } -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), STACK(-CURRENT_AS(bracketpos_backtrack)->framesize - 1)); -} - -static SLJIT_INLINE void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -assert_backtrack backtrack; - -current->top = NULL; -current->own_backtracks = NULL; -current->simple_backtracks = NULL; -if (current->cc[1] > OP_ASSERTBACK_NOT) - { - /* Manual call of compile_bracket_matchingpath and compile_bracket_backtrackingpath. */ - compile_bracket_matchingpath(common, current->cc, current); - compile_bracket_backtrackingpath(common, current->top); - } -else - { - memset(&backtrack, 0, sizeof(backtrack)); - backtrack.common.cc = current->cc; - backtrack.matchingpath = CURRENT_AS(braminzero_backtrack)->matchingpath; - /* Manual call of compile_assert_matchingpath. */ - compile_assert_matchingpath(common, current->cc, &backtrack, FALSE); - } -SLJIT_ASSERT(!current->simple_backtracks && !current->own_backtracks); -} - -static SLJIT_INLINE void compile_control_verb_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -PCRE2_UCHAR opcode = *current->cc; -struct sljit_label *loop; -struct sljit_jump *jump; - -if (opcode == OP_THEN || opcode == OP_THEN_ARG) - { - if (common->then_trap != NULL) - { - SLJIT_ASSERT(common->control_head_ptr != 0); - - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start); - jump = JUMP(SLJIT_JUMP); - - loop = LABEL(); - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - JUMPHERE(jump); - CMPTO(SLJIT_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0, loop); - CMPTO(SLJIT_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0, loop); - add_jump(compiler, &common->then_trap->quit, JUMP(SLJIT_JUMP)); - return; - } - else if (!common->local_quit_available && common->in_positive_assertion) - { - add_jump(compiler, &common->positive_assertion_quit, JUMP(SLJIT_JUMP)); - return; - } - } - -if (common->restore_end_ptr != 0 && opcode != OP_SKIP_ARG) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->restore_end_ptr); - -if (common->local_quit_available) - { - /* Abort match with a fail. */ - if (common->quit_label == NULL) - add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP)); - else - JUMPTO(SLJIT_JUMP, common->quit_label); - return; - } - -if (opcode == OP_SKIP_ARG) - { - SLJIT_ASSERT(common->control_head_ptr != 0 && TMP1 == SLJIT_R0 && STR_PTR == SLJIT_R1); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); - OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2)); - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(do_search_mark)); - - if (common->restore_end_ptr == 0) - { - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_R0, 0); - add_jump(compiler, &common->reset_match, CMP(SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 0)); - return; - } - - jump = CMP(SLJIT_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 0); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_R0, 0); - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->restore_end_ptr); - add_jump(compiler, &common->reset_match, JUMP(SLJIT_JUMP)); - JUMPHERE(jump); - return; - } - -if (opcode == OP_SKIP) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); -else - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_IMM, 0); -add_jump(compiler, &common->reset_match, JUMP(SLJIT_JUMP)); -} - -static SLJIT_INLINE void compile_vreverse_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; -struct sljit_label *label; - -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(2)); -jump = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(3)); -skip_valid_char(common); -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0); -JUMPTO(SLJIT_JUMP, CURRENT_AS(vreverse_backtrack)->matchingpath); - -label = LABEL(); -sljit_set_label(jump, label); -set_jumps(current->own_backtracks, label); -} - -static SLJIT_INLINE void compile_then_trap_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -struct sljit_jump *jump; -int framesize; -int size; - -if (CURRENT_AS(then_trap_backtrack)->then_trap) - { - common->then_trap = CURRENT_AS(then_trap_backtrack)->then_trap; - return; - } - -size = CURRENT_AS(then_trap_backtrack)->framesize; -size = 3 + (size < 0 ? 0 : size); - -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(size - 3)); -free_stack(common, size); -jump = JUMP(SLJIT_JUMP); - -set_jumps(CURRENT_AS(then_trap_backtrack)->quit, LABEL()); - -framesize = CURRENT_AS(then_trap_backtrack)->framesize; -SLJIT_ASSERT(framesize != 0); - -/* STACK_TOP is set by THEN. */ -if (framesize > 0) - { - add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL)); - OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize - 1) * sizeof(sljit_sw)); - } -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); -free_stack(common, 3); - -JUMPHERE(jump); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, TMP1, 0); -} - -static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current) -{ -DEFINE_COMPILER; -then_trap_backtrack *save_then_trap = common->then_trap; - -while (current) - { - if (current->simple_backtracks != NULL) - set_jumps(current->simple_backtracks, LABEL()); - switch(*current->cc) - { - case OP_SET_SOM: - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), TMP1, 0); - break; - - case OP_STAR: - case OP_MINSTAR: - case OP_PLUS: - case OP_MINPLUS: - case OP_QUERY: - case OP_MINQUERY: - case OP_UPTO: - case OP_MINUPTO: - case OP_EXACT: - case OP_POSSTAR: - case OP_POSPLUS: - case OP_POSQUERY: - case OP_POSUPTO: - case OP_STARI: - case OP_MINSTARI: - case OP_PLUSI: - case OP_MINPLUSI: - case OP_QUERYI: - case OP_MINQUERYI: - case OP_UPTOI: - case OP_MINUPTOI: - case OP_EXACTI: - case OP_POSSTARI: - case OP_POSPLUSI: - case OP_POSQUERYI: - case OP_POSUPTOI: - case OP_NOTSTAR: - case OP_NOTMINSTAR: - case OP_NOTPLUS: - case OP_NOTMINPLUS: - case OP_NOTQUERY: - case OP_NOTMINQUERY: - case OP_NOTUPTO: - case OP_NOTMINUPTO: - case OP_NOTEXACT: - case OP_NOTPOSSTAR: - case OP_NOTPOSPLUS: - case OP_NOTPOSQUERY: - case OP_NOTPOSUPTO: - case OP_NOTSTARI: - case OP_NOTMINSTARI: - case OP_NOTPLUSI: - case OP_NOTMINPLUSI: - case OP_NOTQUERYI: - case OP_NOTMINQUERYI: - case OP_NOTUPTOI: - case OP_NOTMINUPTOI: - case OP_NOTEXACTI: - case OP_NOTPOSSTARI: - case OP_NOTPOSPLUSI: - case OP_NOTPOSQUERYI: - case OP_NOTPOSUPTOI: - case OP_TYPESTAR: - case OP_TYPEMINSTAR: - case OP_TYPEPLUS: - case OP_TYPEMINPLUS: - case OP_TYPEQUERY: - case OP_TYPEMINQUERY: - case OP_TYPEUPTO: - case OP_TYPEMINUPTO: - case OP_TYPEEXACT: - case OP_TYPEPOSSTAR: - case OP_TYPEPOSPLUS: - case OP_TYPEPOSQUERY: - case OP_TYPEPOSUPTO: - /* Since classes has no backtracking path, this - backtrackingpath was pushed by an iterator. */ - case OP_CLASS: - case OP_NCLASS: -#if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH != 8 - case OP_XCLASS: - case OP_ECLASS: -#endif - compile_iterator_backtrackingpath(common, current); - break; - - case OP_REF: - case OP_REFI: - case OP_DNREF: - case OP_DNREFI: - compile_ref_iterator_backtrackingpath(common, current); - break; - - case OP_RECURSE: - compile_recurse_backtrackingpath(common, current); - break; - - case OP_ASSERT: - case OP_ASSERT_NOT: - case OP_ASSERTBACK: - case OP_ASSERTBACK_NOT: - compile_assert_backtrackingpath(common, current); - break; - - case OP_ASSERT_NA: - case OP_ASSERTBACK_NA: - case OP_ASSERT_SCS: - case OP_ONCE: - case OP_SCRIPT_RUN: - case OP_BRA: - case OP_CBRA: - case OP_COND: - case OP_SBRA: - case OP_SCBRA: - case OP_SCOND: - compile_bracket_backtrackingpath(common, current); - break; - - case OP_BRAZERO: - if (current->cc[1] > OP_ASSERTBACK_NOT) - compile_bracket_backtrackingpath(common, current); - else - compile_assert_backtrackingpath(common, current); - break; - - case OP_BRAPOS: - case OP_CBRAPOS: - case OP_SBRAPOS: - case OP_SCBRAPOS: - case OP_BRAPOSZERO: - compile_bracketpos_backtrackingpath(common, current); - break; - - case OP_BRAMINZERO: - compile_braminzero_backtrackingpath(common, current); - break; - - case OP_MARK: - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0)); - if (common->has_skip_arg) - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - free_stack(common, common->has_skip_arg ? 5 : 1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, TMP1, 0); - if (common->has_skip_arg) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, TMP2, 0); - break; - - case OP_THEN: - case OP_THEN_ARG: - case OP_PRUNE: - case OP_PRUNE_ARG: - case OP_SKIP: - case OP_SKIP_ARG: - compile_control_verb_backtrackingpath(common, current); - break; - - case OP_COMMIT: - case OP_COMMIT_ARG: - if (common->restore_end_ptr != 0) - OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->restore_end_ptr); - - if (!common->local_quit_available) - OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_NOMATCH); - - if (common->quit_label == NULL) - add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP)); - else - JUMPTO(SLJIT_JUMP, common->quit_label); - break; - - case OP_CALLOUT: - case OP_CALLOUT_STR: - case OP_FAIL: - case OP_ACCEPT: - case OP_ASSERT_ACCEPT: - set_jumps(current->own_backtracks, LABEL()); - break; - - case OP_VREVERSE: - compile_vreverse_backtrackingpath(common, current); - break; - - case OP_THEN_TRAP: - /* A virtual opcode for then traps. */ - compile_then_trap_backtrackingpath(common, current); - break; - - default: - SLJIT_UNREACHABLE(); - break; - } - current = current->prev; - } -common->then_trap = save_then_trap; -} - -static SLJIT_INLINE void compile_recurse(compiler_common *common) -{ -DEFINE_COMPILER; -PCRE2_SPTR cc = common->start + common->currententry->start; -PCRE2_SPTR ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE); -PCRE2_SPTR ccend = bracketend(cc) - (1 + LINK_SIZE); -uint32_t recurse_flags = 0; -int private_data_size = get_recurse_data_length(common, ccbegin, ccend, &recurse_flags); -int alt_count, alt_max, local_size; -backtrack_common altbacktrack; -jump_list *match = NULL; -struct sljit_jump *next_alt = NULL; -struct sljit_jump *accept_exit = NULL; -struct sljit_label *quit; -struct sljit_jump *mov_addr = NULL; - -/* Recurse captures then. */ -common->then_trap = NULL; - -SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS); - -alt_max = no_alternatives(cc); -alt_count = 0; - -/* Matching path. */ -SLJIT_ASSERT(common->currententry->entry_label == NULL && common->recursive_head_ptr != 0); -common->currententry->entry_label = LABEL(); -set_jumps(common->currententry->entry_calls, common->currententry->entry_label); - -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, TMP2, 0); -count_match(common); - -local_size = (alt_max > 1) ? 2 : 1; - -/* (Reversed) stack layout: - [private data][return address][optional: str ptr] ... [optional: alternative index][recursive_head_ptr] */ - -allocate_stack(common, private_data_size + local_size); -/* Save return address. */ -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(local_size - 1), TMP2, 0); - -copy_recurse_data(common, ccbegin, ccend, recurse_copy_from_global, local_size, private_data_size + local_size, recurse_flags); - -/* This variable is saved and restored all time when we enter or exit from a recursive context. */ -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr, STACK_TOP, 0); - -if (recurse_flags & recurse_flag_control_head_found) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0); - -if (alt_max > 1) - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0); - -memset(&altbacktrack, 0, sizeof(backtrack_common)); -common->quit_label = NULL; -common->accept_label = NULL; -common->quit = NULL; -common->accept = NULL; -altbacktrack.cc = ccbegin; -cc += GET(cc, 1); -while (1) - { - altbacktrack.top = NULL; - altbacktrack.own_backtracks = NULL; - - if (altbacktrack.cc != ccbegin) - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - - compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return; - - allocate_stack(common, (alt_max > 1 || (recurse_flags & recurse_flag_accept_found)) ? 2 : 1); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr); - - if (alt_max > 1 || (recurse_flags & recurse_flag_accept_found)) - { - if (alt_max > 3) - mov_addr = sljit_emit_mov_addr(compiler, SLJIT_MEM1(STACK_TOP), STACK(1)); - else - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, alt_count); - } - - add_jump(compiler, &match, JUMP(SLJIT_JUMP)); - - if (alt_count == 0) - { - /* Backtracking path entry. */ - SLJIT_ASSERT(common->currententry->backtrack_label == NULL); - common->currententry->backtrack_label = LABEL(); - set_jumps(common->currententry->backtrack_calls, common->currententry->backtrack_label); - - sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, TMP1, 0); - - if (recurse_flags & recurse_flag_accept_found) - accept_exit = CMP(SLJIT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, -1); - - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); - /* Save return address. */ - OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), STACK(local_size - 1), TMP1, 0); - - copy_recurse_data(common, ccbegin, ccend, recurse_swap_global, local_size, private_data_size + local_size, recurse_flags); - - if (alt_max > 1) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); - free_stack(common, 2); - - if (alt_max > 3) - { - sljit_emit_ijump(compiler, SLJIT_JUMP, TMP1, 0); - sljit_set_label(mov_addr, LABEL()); - sljit_emit_op0(compiler, SLJIT_ENDBR); - } - else - next_alt = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0); - } - else - free_stack(common, (recurse_flags & recurse_flag_accept_found) ? 2 : 1); - } - else if (alt_max > 3) - { - sljit_set_label(mov_addr, LABEL()); - sljit_emit_op0(compiler, SLJIT_ENDBR); - } - else - { - JUMPHERE(next_alt); - if (alt_count + 1 < alt_max) - { - SLJIT_ASSERT(alt_count == 1 && alt_max == 3); - next_alt = CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 1); - } - } - - alt_count++; - - compile_backtrackingpath(common, altbacktrack.top); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return; - set_jumps(altbacktrack.own_backtracks, LABEL()); - - if (*cc != OP_ALT) - break; - - altbacktrack.cc = cc + 1 + LINK_SIZE; - cc += GET(cc, 1); - } - -/* No alternative is matched. */ - -quit = LABEL(); - -copy_recurse_data(common, ccbegin, ccend, recurse_copy_private_to_global, local_size, private_data_size + local_size, recurse_flags); - -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(local_size - 1)); -free_stack(common, private_data_size + local_size); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); -OP_SRC(SLJIT_FAST_RETURN, TMP2, 0); - -if (common->quit != NULL) - { - SLJIT_ASSERT(recurse_flags & recurse_flag_quit_found); - - set_jumps(common->quit, LABEL()); - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr); - copy_recurse_data(common, ccbegin, ccend, recurse_copy_shared_to_global, local_size, private_data_size + local_size, recurse_flags); - JUMPTO(SLJIT_JUMP, quit); - } - -if (recurse_flags & recurse_flag_accept_found) - { - JUMPHERE(accept_exit); - free_stack(common, 2); - - /* Save return address. */ - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(local_size - 1), TMP1, 0); - - copy_recurse_data(common, ccbegin, ccend, recurse_copy_kept_shared_to_global, local_size, private_data_size + local_size, recurse_flags); - - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(local_size - 1)); - free_stack(common, private_data_size + local_size); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); - OP_SRC(SLJIT_FAST_RETURN, TMP2, 0); - } - -if (common->accept != NULL) - { - SLJIT_ASSERT(recurse_flags & recurse_flag_accept_found); - - set_jumps(common->accept, LABEL()); - - OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_SP), common->recursive_head_ptr); - OP1(SLJIT_MOV, TMP2, 0, STACK_TOP, 0); - - allocate_stack(common, 2); - OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, -1); - } - -set_jumps(match, LABEL()); - -OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0); - -copy_recurse_data(common, ccbegin, ccend, recurse_swap_global, local_size, private_data_size + local_size, recurse_flags); - -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), STACK(local_size - 1)); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 1); -OP_SRC(SLJIT_FAST_RETURN, TMP2, 0); -} - -#undef COMPILE_BACKTRACKINGPATH -#undef CURRENT_AS - -#define PUBLIC_JIT_COMPILE_CONFIGURATION_OPTIONS \ - (PCRE2_JIT_INVALID_UTF) - -static int jit_compile(pcre2_code *code, sljit_u32 mode) -{ -pcre2_real_code *re = (pcre2_real_code *)code; -struct sljit_compiler *compiler; -backtrack_common rootbacktrack; -compiler_common common_data; -compiler_common *common = &common_data; -const sljit_u8 *tables = re->tables; -void *allocator_data = &re->memctl; -int private_data_size; -PCRE2_SPTR ccend; -executable_functions *functions; -void *executable_func; -sljit_uw executable_size, private_data_length, total_length; -struct sljit_label *mainloop_label = NULL; -struct sljit_label *continue_match_label; -struct sljit_label *empty_match_found_label = NULL; -struct sljit_label *empty_match_backtrack_label = NULL; -struct sljit_label *reset_match_label; -struct sljit_label *quit_label; -struct sljit_jump *jump; -struct sljit_jump *minlength_check_failed = NULL; -struct sljit_jump *empty_match = NULL; -struct sljit_jump *end_anchor_failed = NULL; -jump_list *reqcu_not_found = NULL; - -SLJIT_ASSERT(tables); - -#if HAS_VIRTUAL_REGISTERS == 1 -SLJIT_ASSERT(sljit_get_register_index(SLJIT_GP_REGISTER, TMP3) < 0 && sljit_get_register_index(SLJIT_GP_REGISTER, ARGUMENTS) < 0 && sljit_get_register_index(SLJIT_GP_REGISTER, RETURN_ADDR) < 0); -#elif HAS_VIRTUAL_REGISTERS == 0 -SLJIT_ASSERT(sljit_get_register_index(SLJIT_GP_REGISTER, TMP3) >= 0 && sljit_get_register_index(SLJIT_GP_REGISTER, ARGUMENTS) >= 0 && sljit_get_register_index(SLJIT_GP_REGISTER, RETURN_ADDR) >= 0); -#else -#error "Invalid value for HAS_VIRTUAL_REGISTERS" -#endif - -memset(&rootbacktrack, 0, sizeof(backtrack_common)); -memset(common, 0, sizeof(compiler_common)); -common->re = re; -common->name_table = (PCRE2_SPTR)((uint8_t *)re + sizeof(pcre2_real_code)); -rootbacktrack.cc = (PCRE2_SPTR)((uint8_t *)re + re->code_start); - -#ifdef SUPPORT_UNICODE -common->invalid_utf = (mode & PCRE2_JIT_INVALID_UTF) != 0; -#endif /* SUPPORT_UNICODE */ -mode &= ~PUBLIC_JIT_COMPILE_CONFIGURATION_OPTIONS; - -common->start = rootbacktrack.cc; -common->read_only_data_head = NULL; -common->fcc = tables + fcc_offset; -common->lcc = (sljit_sw)(tables + lcc_offset); -common->mode = mode; -common->might_be_empty = (re->minlength == 0) || (re->flags & PCRE2_MATCH_EMPTY); -common->allow_empty_partial = (re->max_lookbehind > 0) || (re->flags & PCRE2_MATCH_EMPTY); -common->nltype = NLTYPE_FIXED; -switch(re->newline_convention) - { - case PCRE2_NEWLINE_CR: common->newline = CHAR_CR; break; - case PCRE2_NEWLINE_LF: common->newline = CHAR_NL; break; - case PCRE2_NEWLINE_CRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; break; - case PCRE2_NEWLINE_ANY: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANY; break; - case PCRE2_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break; - case PCRE2_NEWLINE_NUL: common->newline = CHAR_NUL; break; - default: return PCRE2_ERROR_INTERNAL; - } -common->nlmax = READ_CHAR_MAX; -common->nlmin = 0; -if (re->bsr_convention == PCRE2_BSR_UNICODE) - common->bsr_nltype = NLTYPE_ANY; -else if (re->bsr_convention == PCRE2_BSR_ANYCRLF) - common->bsr_nltype = NLTYPE_ANYCRLF; -else - { -#ifdef BSR_ANYCRLF - common->bsr_nltype = NLTYPE_ANYCRLF; -#else - common->bsr_nltype = NLTYPE_ANY; -#endif - } -common->bsr_nlmax = READ_CHAR_MAX; -common->bsr_nlmin = 0; -common->endonly = (re->overall_options & PCRE2_DOLLAR_ENDONLY) != 0; -common->ctypes = (sljit_sw)(tables + ctypes_offset); -common->name_count = re->name_count; -common->name_entry_size = re->name_entry_size; -common->unset_backref = (re->overall_options & PCRE2_MATCH_UNSET_BACKREF) != 0; -common->alt_circumflex = (re->overall_options & PCRE2_ALT_CIRCUMFLEX) != 0; -#ifdef SUPPORT_UNICODE -/* PCRE2_UTF[16|32] have the same value as PCRE2_UTF8. */ -common->utf = (re->overall_options & PCRE2_UTF) != 0; -common->ucp = (re->overall_options & PCRE2_UCP) != 0; -if (common->utf) - { - if (common->nltype == NLTYPE_ANY) - common->nlmax = 0x2029; - else if (common->nltype == NLTYPE_ANYCRLF) - common->nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL; - else - { - /* We only care about the first newline character. */ - common->nlmax = common->newline & 0xff; - } - - if (common->nltype == NLTYPE_FIXED) - common->nlmin = common->newline & 0xff; - else - common->nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL; - - if (common->bsr_nltype == NLTYPE_ANY) - common->bsr_nlmax = 0x2029; - else - common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL; - common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL; - } -else - common->invalid_utf = FALSE; -#endif /* SUPPORT_UNICODE */ -ccend = bracketend(common->start); - -/* Calculate the local space size on the stack. */ -common->ovector_start = LOCAL0; -/* Allocate space for temporary data structures. */ -private_data_length = ccend - common->start; -/* The chance of overflow is very low, but might happen on 32 bit. */ -if (private_data_length > ~(sljit_uw)0 / sizeof(sljit_s32)) - return PCRE2_ERROR_NOMEMORY; - -private_data_length *= sizeof(sljit_s32); -/* Align to 32 bit. */ -total_length = ((re->top_bracket + 1) + (sljit_uw)(sizeof(sljit_s32) - 1)) & ~(sljit_uw)(sizeof(sljit_s32) - 1); -if (~(sljit_uw)0 - private_data_length < total_length) - return PCRE2_ERROR_NOMEMORY; - -total_length += private_data_length; -common->private_data_ptrs = (sljit_s32*)SLJIT_MALLOC(total_length, allocator_data); -if (!common->private_data_ptrs) - return PCRE2_ERROR_NOMEMORY; - -memset(common->private_data_ptrs, 0, private_data_length); -common->optimized_cbracket = ((sljit_u8 *)common->private_data_ptrs) + private_data_length; -#if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 1 -memset(common->optimized_cbracket, 0, re->top_bracket + 1); -#else -memset(common->optimized_cbracket, 1, re->top_bracket + 1); -#endif - -SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET); -#if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2 -common->capture_last_ptr = common->ovector_start; -common->ovector_start += sizeof(sljit_sw); -#endif -if (!check_opcode_types(common, common->start, ccend)) - { - SLJIT_FREE(common->private_data_ptrs, allocator_data); - return PCRE2_ERROR_JIT_UNSUPPORTED; - } - -/* Checking flags and updating ovector_start. */ -if (mode == PCRE2_JIT_COMPLETE && - (re->flags & PCRE2_LASTSET) != 0 && - (re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) - { - common->req_char_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - -if (mode != PCRE2_JIT_COMPLETE) - { - common->start_used_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - if (mode == PCRE2_JIT_PARTIAL_SOFT) - { - common->hit_start = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - } - -if ((re->overall_options & (PCRE2_FIRSTLINE | PCRE2_USE_OFFSET_LIMIT)) != 0) - { - common->match_end_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - -#if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD -common->control_head_ptr = 1; -#endif - -if (common->control_head_ptr != 0) - { - common->control_head_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - -if (common->has_set_som) - { - /* Saving the real start pointer is necessary. */ - common->start_ptr = common->ovector_start; - common->ovector_start += sizeof(sljit_sw); - } - -/* Aligning ovector to even number of sljit words. */ -if ((common->ovector_start & sizeof(sljit_sw)) != 0) - common->ovector_start += sizeof(sljit_sw); - -if (common->start_ptr == 0) - common->start_ptr = OVECTOR(0); - -/* Capturing brackets cannot be optimized if callouts are allowed. */ -if (common->capture_last_ptr != 0) - memset(common->optimized_cbracket, 0, re->top_bracket + 1); - -SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0)); -common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw); -private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw); - -if ((re->overall_options & PCRE2_ANCHORED) == 0 && - (re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0 && - !common->has_skip_in_assert_back) - detect_early_fail(common, common->start, &private_data_size, 0, 0); - -set_private_data_ptrs(common, &private_data_size, ccend); - -SLJIT_ASSERT(common->early_fail_start_ptr <= common->early_fail_end_ptr); - -if (private_data_size > 65536) - { - SLJIT_FREE(common->private_data_ptrs, allocator_data); - return PCRE2_ERROR_JIT_UNSUPPORTED; - } - -if (common->has_then) - { - total_length = ccend - common->start; - common->then_offsets = (sljit_u8 *)SLJIT_MALLOC(total_length, allocator_data); - if (!common->then_offsets) - { - SLJIT_FREE(common->private_data_ptrs, allocator_data); - return PCRE2_ERROR_NOMEMORY; - } - memset(common->then_offsets, 0, total_length); - set_then_offsets(common, common->start, NULL); - } - -compiler = sljit_create_compiler(allocator_data); -if (!compiler) - { - SLJIT_FREE(common->private_data_ptrs, allocator_data); - if (common->has_then) - SLJIT_FREE(common->then_offsets, allocator_data); - return PCRE2_ERROR_NOMEMORY; - } -common->compiler = compiler; - -/* Main pcre2_jit_exec entry. */ -SLJIT_ASSERT((private_data_size & (sizeof(sljit_sw) - 1)) == 0); -sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, W), 5 | SLJIT_ENTER_VECTOR(SLJIT_NUMBER_OF_SCRATCH_VECTOR_REGISTERS), 5, private_data_size); - -/* Register init. */ -reset_ovector(common, (re->top_bracket + 1) * 2); -if (common->req_char_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr, SLJIT_R0, 0); - -OP1(SLJIT_MOV, ARGUMENTS, 0, SLJIT_S0, 0); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_S0, 0); -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str)); -OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end)); -OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack)); -OP1(SLJIT_MOV_U32, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, limit_match)); -OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, end)); -OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, start)); -OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LIMIT_MATCH, TMP1, 0); - -if (common->early_fail_start_ptr < common->early_fail_end_ptr) - reset_early_fail(common); - -if (mode == PCRE2_JIT_PARTIAL_SOFT) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, -1); -if (common->mark_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, SLJIT_IMM, 0); -if (common->control_head_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0); - -/* Main part of the matching */ -if ((re->overall_options & PCRE2_ANCHORED) == 0) - { - mainloop_label = mainloop_entry(common); - continue_match_label = LABEL(); - /* Forward search if possible. */ - if ((re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) - { - if (mode == PCRE2_JIT_COMPLETE && fast_forward_first_n_chars(common)) - ; - else if ((re->flags & PCRE2_FIRSTSET) != 0) - fast_forward_first_char(common); - else if ((re->flags & PCRE2_STARTLINE) != 0) - fast_forward_newline(common); - else if ((re->flags & PCRE2_FIRSTMAPSET) != 0) - fast_forward_start_bits(common); - } - } -else - continue_match_label = LABEL(); - -if (mode == PCRE2_JIT_COMPLETE && re->minlength > 0 && - (re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) - { - OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_NOMATCH); - OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(re->minlength)); - minlength_check_failed = CMP(SLJIT_GREATER, TMP2, 0, STR_END, 0); - } -if (common->req_char_ptr != 0) - reqcu_not_found = search_requested_char(common, (PCRE2_UCHAR)(re->last_codeunit), (re->flags & PCRE2_LASTCASELESS) != 0, (re->flags & PCRE2_FIRSTSET) != 0); - -/* Store the current STR_PTR in OVECTOR(0). */ -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(0), STR_PTR, 0); -/* Copy the limit of allowed recursions. */ -OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_MEM1(SLJIT_SP), LIMIT_MATCH); -if (common->capture_last_ptr != 0) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr, SLJIT_IMM, 0); -if (common->fast_forward_bc_ptr != NULL) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), PRIVATE_DATA(common->fast_forward_bc_ptr + 1) >> 3, STR_PTR, 0); - -if (common->start_ptr != OVECTOR(0)) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_ptr, STR_PTR, 0); - -/* Copy the beginning of the string. */ -if (mode == PCRE2_JIT_PARTIAL_SOFT) - { - jump = CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, -1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); - JUMPHERE(jump); - } -else if (mode == PCRE2_JIT_PARTIAL_HARD) - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); - -compile_matchingpath(common, common->start, ccend, &rootbacktrack); -if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - { - sljit_free_compiler(compiler); - SLJIT_FREE(common->private_data_ptrs, allocator_data); - if (common->has_then) - SLJIT_FREE(common->then_offsets, allocator_data); - PRIV(jit_free_rodata)(common->read_only_data_head, allocator_data); - return PCRE2_ERROR_NOMEMORY; - } - -if ((re->overall_options & PCRE2_ENDANCHORED) != 0) - end_anchor_failed = CMP(SLJIT_NOT_EQUAL, STR_PTR, 0, STR_END, 0); - -if (common->might_be_empty) - { - empty_match = CMP(SLJIT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)); - empty_match_found_label = LABEL(); - } - -common->accept_label = LABEL(); -if (common->accept != NULL) - set_jumps(common->accept, common->accept_label); - -/* This means we have a match. Update the ovector. */ -copy_ovector(common, re->top_bracket + 1); -common->quit_label = common->abort_label = LABEL(); -if (common->quit != NULL) - set_jumps(common->quit, common->quit_label); -if (common->abort != NULL) - set_jumps(common->abort, common->abort_label); -if (minlength_check_failed != NULL) - SET_LABEL(minlength_check_failed, common->abort_label); - -sljit_emit_op0(compiler, SLJIT_SKIP_FRAMES_BEFORE_RETURN); -sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0); - -if (common->failed_match != NULL) - { - SLJIT_ASSERT(common->mode == PCRE2_JIT_COMPLETE); - set_jumps(common->failed_match, LABEL()); - OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_NOMATCH); - JUMPTO(SLJIT_JUMP, common->abort_label); - } - -if ((re->overall_options & PCRE2_ENDANCHORED) != 0) - JUMPHERE(end_anchor_failed); - -if (mode != PCRE2_JIT_COMPLETE) - { - common->partialmatchlabel = LABEL(); - set_jumps(common->partialmatch, common->partialmatchlabel); - return_with_partial_match(common, common->quit_label); - } - -if (common->might_be_empty) - empty_match_backtrack_label = LABEL(); -compile_backtrackingpath(common, rootbacktrack.top); -if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - { - sljit_free_compiler(compiler); - SLJIT_FREE(common->private_data_ptrs, allocator_data); - if (common->has_then) - SLJIT_FREE(common->then_offsets, allocator_data); - PRIV(jit_free_rodata)(common->read_only_data_head, allocator_data); - return PCRE2_ERROR_NOMEMORY; - } - -SLJIT_ASSERT(rootbacktrack.prev == NULL); -reset_match_label = LABEL(); - -if (mode == PCRE2_JIT_PARTIAL_SOFT) - { - /* Update hit_start only in the first time. */ - jump = CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1); - OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, TMP1, 0); - JUMPHERE(jump); - } - -/* Check we have remaining characters. */ -if ((re->overall_options & PCRE2_ANCHORED) == 0 && common->match_end_ptr != 0) - { - OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr); - } - -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), - (common->fast_forward_bc_ptr != NULL) ? (PRIVATE_DATA(common->fast_forward_bc_ptr + 1) >> 3) : common->start_ptr); - -if ((re->overall_options & PCRE2_ANCHORED) == 0) - { - if (common->ff_newline_shortcut != NULL) - { - /* There cannot be more newlines if PCRE2_FIRSTLINE is set. */ - if ((re->overall_options & PCRE2_FIRSTLINE) == 0) - { - if (common->match_end_ptr != 0) - { - OP1(SLJIT_MOV, TMP3, 0, STR_END, 0); - OP1(SLJIT_MOV, STR_END, 0, TMP1, 0); - CMPTO(SLJIT_LESS, STR_PTR, 0, TMP1, 0, common->ff_newline_shortcut); - OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); - } - else - CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, common->ff_newline_shortcut); - } - } - else - CMPTO(SLJIT_LESS, STR_PTR, 0, (common->match_end_ptr == 0) ? STR_END : TMP1, 0, mainloop_label); - } - -/* No more remaining characters. */ -if (reqcu_not_found != NULL) - set_jumps(reqcu_not_found, LABEL()); - -if (mode == PCRE2_JIT_PARTIAL_SOFT) - CMPTO(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, -1, common->partialmatchlabel); - -OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_NOMATCH); -JUMPTO(SLJIT_JUMP, common->quit_label); - -flush_stubs(common); - -if (common->might_be_empty) - { - JUMPHERE(empty_match); - OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - OP1(SLJIT_MOV_U32, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, options)); - OP2U(SLJIT_AND | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, PCRE2_NOTEMPTY); - JUMPTO(SLJIT_NOT_ZERO, empty_match_backtrack_label); - OP2U(SLJIT_AND | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, PCRE2_NOTEMPTY_ATSTART); - JUMPTO(SLJIT_ZERO, empty_match_found_label); - OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str)); - CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label); - JUMPTO(SLJIT_JUMP, empty_match_backtrack_label); - } - -common->fast_forward_bc_ptr = NULL; -common->early_fail_start_ptr = 0; -common->early_fail_end_ptr = 0; -common->currententry = common->entries; -common->local_quit_available = TRUE; -quit_label = common->quit_label; -SLJIT_ASSERT(common->restore_end_ptr == 0); - -if (common->currententry != NULL) - { - /* A free bit for each private data. */ - common->recurse_bitset_size = ((private_data_size / SSIZE_OF(sw)) + 7) >> 3; - SLJIT_ASSERT(common->recurse_bitset_size > 0); - common->recurse_bitset = (sljit_u8*)SLJIT_MALLOC(common->recurse_bitset_size, allocator_data);; - - if (common->recurse_bitset != NULL) - { - do - { - /* Might add new entries. */ - compile_recurse(common); - if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - break; - flush_stubs(common); - common->currententry = common->currententry->next; - } - while (common->currententry != NULL); - - SLJIT_FREE(common->recurse_bitset, allocator_data); - } - - if (common->currententry != NULL) - { - /* The common->recurse_bitset has been freed. */ - SLJIT_ASSERT(sljit_get_compiler_error(compiler) || common->recurse_bitset == NULL); - - sljit_free_compiler(compiler); - SLJIT_FREE(common->private_data_ptrs, allocator_data); - if (common->has_then) - SLJIT_FREE(common->then_offsets, allocator_data); - PRIV(jit_free_rodata)(common->read_only_data_head, allocator_data); - return PCRE2_ERROR_NOMEMORY; - } - } - -common->local_quit_available = FALSE; -common->quit_label = quit_label; -SLJIT_ASSERT(common->restore_end_ptr == 0); - -/* Allocating stack, returns with PCRE2_ERROR_JIT_STACKLIMIT if fails. */ -/* This is a (really) rare case. */ -set_jumps(common->stackalloc, LABEL()); -/* RETURN_ADDR is not a saved register. */ -SLJIT_ASSERT(common->locals_size >= 2 * SSIZE_OF(sw)); -sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, SLJIT_MEM1(SLJIT_SP), LOCAL0); - -SLJIT_ASSERT(TMP1 == SLJIT_R0 && STR_PTR == SLJIT_R1); - -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL1, STR_PTR, 0); -OP1(SLJIT_MOV, SLJIT_R0, 0, ARGUMENTS, 0); -OP2(SLJIT_SUB, SLJIT_R1, 0, STACK_LIMIT, 0, SLJIT_IMM, STACK_GROWTH_RATE); -OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, stack)); -OP1(SLJIT_MOV, STACK_LIMIT, 0, TMP2, 0); - -sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_stack_resize)); - -jump = CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); -OP1(SLJIT_MOV, TMP2, 0, STACK_LIMIT, 0); -OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_RETURN_REG, 0); -OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), LOCAL1); -OP_SRC(SLJIT_FAST_RETURN, TMP1, 0); - -/* Allocation failed. */ -JUMPHERE(jump); -/* We break the return address cache here, but this is a really rare case. */ -OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_JIT_STACKLIMIT); -JUMPTO(SLJIT_JUMP, common->quit_label); - -/* Call limit reached. */ -set_jumps(common->calllimit, LABEL()); -OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_MATCHLIMIT); -JUMPTO(SLJIT_JUMP, common->quit_label); - -if (common->revertframes != NULL) - { - set_jumps(common->revertframes, LABEL()); - do_revertframes(common); - } -if (common->wordboundary != NULL) - { - set_jumps(common->wordboundary, LABEL()); - check_wordboundary(common, FALSE); - } -if (common->ucp_wordboundary != NULL) - { - set_jumps(common->ucp_wordboundary, LABEL()); - check_wordboundary(common, TRUE); - } -if (common->anynewline != NULL) - { - set_jumps(common->anynewline, LABEL()); - check_anynewline(common); - } -if (common->hspace != NULL) - { - set_jumps(common->hspace, LABEL()); - check_hspace(common); - } -if (common->vspace != NULL) - { - set_jumps(common->vspace, LABEL()); - check_vspace(common); - } -if (common->casefulcmp != NULL) - { - set_jumps(common->casefulcmp, LABEL()); - do_casefulcmp(common); - } -if (common->caselesscmp != NULL) - { - set_jumps(common->caselesscmp, LABEL()); - do_caselesscmp(common); - } -if (common->reset_match != NULL || common->restart_match != NULL) - { - if (common->restart_match != NULL) - { - set_jumps(common->restart_match, LABEL()); - OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr); - } - - set_jumps(common->reset_match, LABEL()); - do_reset_match(common, (re->top_bracket + 1) * 2); - /* The value of restart_match is in TMP1. */ - CMPTO(SLJIT_GREATER, STR_PTR, 0, TMP1, 0, continue_match_label); - OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0); - JUMPTO(SLJIT_JUMP, reset_match_label); - } -#ifdef SUPPORT_UNICODE -#if PCRE2_CODE_UNIT_WIDTH == 8 -if (common->utfreadchar != NULL) - { - set_jumps(common->utfreadchar, LABEL()); - do_utfreadchar(common); - } -if (common->utfreadtype8 != NULL) - { - set_jumps(common->utfreadtype8, LABEL()); - do_utfreadtype8(common); - } -if (common->utfpeakcharback != NULL) - { - set_jumps(common->utfpeakcharback, LABEL()); - do_utfpeakcharback(common); - } -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ -#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 -if (common->utfreadchar_invalid != NULL) - { - set_jumps(common->utfreadchar_invalid, LABEL()); - do_utfreadchar_invalid(common); - } -if (common->utfreadnewline_invalid != NULL) - { - set_jumps(common->utfreadnewline_invalid, LABEL()); - do_utfreadnewline_invalid(common); - } -if (common->utfmoveback_invalid) - { - set_jumps(common->utfmoveback_invalid, LABEL()); - do_utfmoveback_invalid(common); - } -if (common->utfpeakcharback_invalid) - { - set_jumps(common->utfpeakcharback_invalid, LABEL()); - do_utfpeakcharback_invalid(common); - } -#endif /* PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 */ -if (common->getucd != NULL) - { - set_jumps(common->getucd, LABEL()); - do_getucd(common); - } -if (common->getucdtype != NULL) - { - set_jumps(common->getucdtype, LABEL()); - do_getucdtype(common); - } -#endif /* SUPPORT_UNICODE */ - -SLJIT_FREE(common->private_data_ptrs, allocator_data); -if (common->has_then) - SLJIT_FREE(common->then_offsets, allocator_data); - -executable_func = sljit_generate_code(compiler, 0, NULL); -executable_size = sljit_get_generated_code_size(compiler); -sljit_free_compiler(compiler); - -if (executable_func == NULL) - { - PRIV(jit_free_rodata)(common->read_only_data_head, allocator_data); - return PCRE2_ERROR_NOMEMORY; - } - -/* Reuse the function descriptor if possible. */ -if (re->executable_jit != NULL) - functions = (executable_functions *)re->executable_jit; -else - { - functions = SLJIT_MALLOC(sizeof(executable_functions), allocator_data); - if (functions == NULL) - { - /* This case is highly unlikely since we just recently - freed a lot of memory. Not impossible though. */ - sljit_free_code(executable_func, NULL); - PRIV(jit_free_rodata)(common->read_only_data_head, allocator_data); - return PCRE2_ERROR_NOMEMORY; - } - memset(functions, 0, sizeof(executable_functions)); - functions->top_bracket = re->top_bracket + 1; - functions->limit_match = re->limit_match; - re->executable_jit = functions; - } - -/* Turn mode into an index. */ -if (mode == PCRE2_JIT_COMPLETE) - mode = 0; -else - mode = (mode == PCRE2_JIT_PARTIAL_SOFT) ? 1 : 2; - -SLJIT_ASSERT(mode < JIT_NUMBER_OF_COMPILE_MODES); -functions->executable_funcs[mode] = executable_func; -functions->read_only_data_heads[mode] = common->read_only_data_head; -functions->executable_sizes[mode] = executable_size; -return 0; -} - -#endif - -/************************************************* -* JIT compile a Regular Expression * -*************************************************/ - -/* This function used JIT to convert a previously-compiled pattern into machine -code. - -Arguments: - code a compiled pattern - options JIT option bits - -Returns: 0: success or (*NOJIT) was used - <0: an error code -*/ - -#define PUBLIC_JIT_COMPILE_OPTIONS \ - (PCRE2_JIT_COMPLETE|PCRE2_JIT_PARTIAL_SOFT|PCRE2_JIT_PARTIAL_HARD|PCRE2_JIT_INVALID_UTF) - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_jit_compile(pcre2_code *code, uint32_t options) -{ -pcre2_real_code *re = (pcre2_real_code *)code; -#ifdef SUPPORT_JIT -void *exec_memory; -executable_functions *functions; -static int executable_allocator_is_working = -1; - -if (executable_allocator_is_working == -1) - { - /* Checks whether the executable allocator is working. This check - might run multiple times in multi-threaded environments, but the - result should not be affected by it. */ - exec_memory = SLJIT_MALLOC_EXEC(32, NULL); - if (exec_memory != NULL) - { - SLJIT_FREE_EXEC(((sljit_u8*)(exec_memory)) + SLJIT_EXEC_OFFSET(exec_memory), NULL); - executable_allocator_is_working = 1; - } - else executable_allocator_is_working = 0; - } -#endif - -if (options & PCRE2_JIT_TEST_ALLOC) - { - if (options != PCRE2_JIT_TEST_ALLOC) - return PCRE2_ERROR_JIT_BADOPTION; - -#ifdef SUPPORT_JIT - return executable_allocator_is_working ? 0 : PCRE2_ERROR_NOMEMORY; -#else - return PCRE2_ERROR_JIT_UNSUPPORTED; -#endif - } - -if (code == NULL) - return PCRE2_ERROR_NULL; - -if ((options & ~PUBLIC_JIT_COMPILE_OPTIONS) != 0) - return PCRE2_ERROR_JIT_BADOPTION; - -/* Support for invalid UTF was first introduced in JIT, with the option -PCRE2_JIT_INVALID_UTF. Later, support was added to the interpreter, and the -compile-time option PCRE2_MATCH_INVALID_UTF was created. This is now the -preferred feature, with the earlier option deprecated. However, for backward -compatibility, if the earlier option is set, it forces the new option so that -if JIT matching falls back to the interpreter, there is still support for -invalid UTF. However, if this function has already been successfully called -without PCRE2_JIT_INVALID_UTF and without PCRE2_MATCH_INVALID_UTF (meaning that -non-invalid-supporting JIT code was compiled), give an error. - -If in the future support for PCRE2_JIT_INVALID_UTF is withdrawn, the following -actions are needed: - - 1. Remove the definition from pcre2.h.in and from the list in - PUBLIC_JIT_COMPILE_OPTIONS above. - - 2. Replace PCRE2_JIT_INVALID_UTF with a local flag in this module. - - 3. Replace PCRE2_JIT_INVALID_UTF in pcre2_jit_test.c. - - 4. Delete the following short block of code. The setting of "re" and - "functions" can be moved into the JIT-only block below, but if that is - done, (void)re and (void)functions will be needed in the non-JIT case, to - avoid compiler warnings. -*/ - -#ifdef SUPPORT_JIT -functions = (executable_functions *)re->executable_jit; -#endif - -if ((options & PCRE2_JIT_INVALID_UTF) != 0) - { - if ((re->overall_options & PCRE2_MATCH_INVALID_UTF) == 0) - { -#ifdef SUPPORT_JIT - if (functions != NULL) return PCRE2_ERROR_JIT_BADOPTION; -#endif - re->overall_options |= PCRE2_MATCH_INVALID_UTF; - } - } - -/* The above tests are run with and without JIT support. This means that -PCRE2_JIT_INVALID_UTF propagates back into the regex options (ensuring -interpreter support) even in the absence of JIT. But now, if there is no JIT -support, give an error return. */ - -#ifndef SUPPORT_JIT -return PCRE2_ERROR_JIT_BADOPTION; -#else /* SUPPORT_JIT */ - -/* There is JIT support. Do the necessary. */ - -if ((re->flags & PCRE2_NOJIT) != 0) return 0; - -if (!executable_allocator_is_working) - return PCRE2_ERROR_NOMEMORY; - -if ((re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0) - options |= PCRE2_JIT_INVALID_UTF; - -if ((options & PCRE2_JIT_COMPLETE) != 0 && (functions == NULL - || functions->executable_funcs[0] == NULL)) { - uint32_t excluded_options = (PCRE2_JIT_PARTIAL_SOFT | PCRE2_JIT_PARTIAL_HARD); - int result = jit_compile(code, options & ~excluded_options); - if (result != 0) - return result; - } - -if ((options & PCRE2_JIT_PARTIAL_SOFT) != 0 && (functions == NULL - || functions->executable_funcs[1] == NULL)) { - uint32_t excluded_options = (PCRE2_JIT_COMPLETE | PCRE2_JIT_PARTIAL_HARD); - int result = jit_compile(code, options & ~excluded_options); - if (result != 0) - return result; - } - -if ((options & PCRE2_JIT_PARTIAL_HARD) != 0 && (functions == NULL - || functions->executable_funcs[2] == NULL)) { - uint32_t excluded_options = (PCRE2_JIT_COMPLETE | PCRE2_JIT_PARTIAL_SOFT); - int result = jit_compile(code, options & ~excluded_options); - if (result != 0) - return result; - } - -return 0; - -#endif /* SUPPORT_JIT */ -} - -/* JIT compiler uses an all-in-one approach. This improves security, - since the code generator functions are not exported. */ - -#define INCLUDED_FROM_PCRE2_JIT_COMPILE - - -/* End of pcre2_jit_compile.c */ diff --git a/libpcre/src/pcre2_maketables.c b/libpcre/src/pcre2_maketables.c index 0474cc7db..0f6c5110a 100644 --- a/libpcre/src/pcre2_maketables.c +++ b/libpcre/src/pcre2_maketables.c @@ -45,13 +45,13 @@ own as part of the PCRE2 library. It is also included in the compilation of pcre2_dftables.c as a freestanding program, in which case the macro PCRE2_DFTABLES is defined. */ + #ifndef PCRE2_DFTABLES /* Compiling the library */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif -# include "pcre2_internal.h" +#include "pcre2_internal.h" #endif + + /************************************************* * Create PCRE2 character tables * *************************************************/ @@ -64,14 +64,15 @@ supplied, but when PCRE2_DFTABLES is defined (when compiling the pcre2_dftables freestanding auxiliary program) malloc() is used, and the function has a different name so as not to clash with the prototype in pcre2.h. -Arguments: none when PCRE2_DFTABLES is defined +Arguments: pointers to character-transforming functions when PCRE2_DFTABLES is + defined; else a PCRE2 general context or NULL -Returns: pointer to the contiguous block of data +Returns: pointer to the contiguous block of data; else NULL if memory allocation failed */ #ifdef PCRE2_DFTABLES /* Included in freestanding pcre2_dftables program */ -static const uint8_t *maketables(void) +static const uint8_t *maketables(int (*charfn_to)(int), int (*charfn_from)(int)) { uint8_t *yield = (uint8_t *)malloc(TABLES_LENGTH); @@ -82,6 +83,9 @@ pcre2_maketables(pcre2_general_context *gcontext) uint8_t *yield = (uint8_t *)((gcontext != NULL)? gcontext->memctl.malloc(TABLES_LENGTH, gcontext->memctl.memory_data) : malloc(TABLES_LENGTH)); + +#define charfn_to(c) (c) +#define charfn_from(c) (c) #endif /* PCRE2_DFTABLES */ int i; @@ -92,13 +96,18 @@ p = yield; /* First comes the lower casing table */ -for (i = 0; i < 256; i++) *p++ = tolower(i); +for (i = 0; i < 256; i++) + { + int c = charfn_from(tolower(charfn_to(i))); + *p++ = (c < 256)? c : i; + } /* Next the case-flipping table */ for (i = 0; i < 256; i++) { - int c = islower(i)? toupper(i) : tolower(i); + int c = charfn_from(islower(charfn_to(i))? toupper(charfn_to(i)) + : tolower(charfn_to(i))); *p++ = (c < 256)? c : i; } @@ -118,17 +127,17 @@ test for alnum specially. */ memset(p, 0, cbit_length); for (i = 0; i < 256; i++) { - if (isdigit(i)) p[cbit_digit + i/8] |= 1u << (i&7); - if (isupper(i)) p[cbit_upper + i/8] |= 1u << (i&7); - if (islower(i)) p[cbit_lower + i/8] |= 1u << (i&7); - if (isalnum(i)) p[cbit_word + i/8] |= 1u << (i&7); - if (i == '_') p[cbit_word + i/8] |= 1u << (i&7); - if (isspace(i)) p[cbit_space + i/8] |= 1u << (i&7); - if (isxdigit(i)) p[cbit_xdigit + i/8] |= 1u << (i&7); - if (isgraph(i)) p[cbit_graph + i/8] |= 1u << (i&7); - if (isprint(i)) p[cbit_print + i/8] |= 1u << (i&7); - if (ispunct(i)) p[cbit_punct + i/8] |= 1u << (i&7); - if (iscntrl(i)) p[cbit_cntrl + i/8] |= 1u << (i&7); + if (isdigit(charfn_to(i))) p[cbit_digit + i/8] |= 1u << (i&7); + if (isupper(charfn_to(i))) p[cbit_upper + i/8] |= 1u << (i&7); + if (islower(charfn_to(i))) p[cbit_lower + i/8] |= 1u << (i&7); + if (isalnum(charfn_to(i))) p[cbit_word + i/8] |= 1u << (i&7); + if (i == CHAR_UNDERSCORE) p[cbit_word + i/8] |= 1u << (i&7); + if (isspace(charfn_to(i))) p[cbit_space + i/8] |= 1u << (i&7); + if (isxdigit(charfn_to(i))) p[cbit_xdigit + i/8] |= 1u << (i&7); + if (isgraph(charfn_to(i))) p[cbit_graph + i/8] |= 1u << (i&7); + if (isprint(charfn_to(i))) p[cbit_print + i/8] |= 1u << (i&7); + if (ispunct(charfn_to(i))) p[cbit_punct + i/8] |= 1u << (i&7); + if (iscntrl(charfn_to(i))) p[cbit_cntrl + i/8] |= 1u << (i&7); } p += cbit_length; @@ -140,11 +149,11 @@ changed at release 8.34 and it's always been this way for PCRE2. */ for (i = 0; i < 256; i++) { int x = 0; - if (isspace(i)) x += ctype_space; - if (isalpha(i)) x += ctype_letter; - if (islower(i)) x += ctype_lcletter; - if (isdigit(i)) x += ctype_digit; - if (isalnum(i) || i == '_') x += ctype_word; + if (isspace(charfn_to(i))) x += ctype_space; + if (isalpha(charfn_to(i))) x += ctype_letter; + if (islower(charfn_to(i))) x += ctype_lcletter; + if (isdigit(charfn_to(i))) x += ctype_digit; + if (isalnum(charfn_to(i)) || i == CHAR_UNDERSCORE) x += ctype_word; *p++ = x; } @@ -152,6 +161,9 @@ return yield; } #ifndef PCRE2_DFTABLES /* Compiling the library */ +#undef charfn_to +#undef charfn_from + PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION pcre2_maketables_free(pcre2_general_context *gcontext, const uint8_t *tables) { diff --git a/libpcre/src/pcre2_match.c b/libpcre/src/pcre2_match.c index 5adc03480..d5574d721 100644 --- a/libpcre/src/pcre2_match.c +++ b/libpcre/src/pcre2_match.c @@ -39,12 +39,10 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + + /* These defines enable debugging code */ /* #define DEBUG_FRAMES_DISPLAY */ @@ -367,6 +365,10 @@ PCRE2_SIZE length; PCRE2_SPTR eptr; PCRE2_SPTR eptr_start; +#ifndef SUPPORT_UNICODE +(void)caseopts; /* Avoid compiler warning. */ +#endif + /* Deal with an unset group. The default is no match, but there is an option to match an empty string. */ @@ -385,6 +387,7 @@ if (offset >= Foffset_top || Fovector[offset] == PCRE2_UNSET) eptr = eptr_start = Feptr; p = mb->start_subject + Fovector[offset]; length = Fovector[offset+1] - Fovector[offset]; +PCRE2_ASSERT(eptr <= mb->end_subject); if (caseless) { @@ -404,7 +407,7 @@ if (caseless) bytes in UTF-8); a sequence of 3 of the former uses 6 bytes, as does a sequence of two of the latter. It is important, therefore, to check the length along the reference, not along the subject (earlier code did this - wrong). UCP without uses Unicode properties but without UTF encoding. */ + wrong). UCP uses Unicode properties but without UTF encoding. */ while (p < endptr) { @@ -483,8 +486,8 @@ else else { - if ((PCRE2_SIZE)(mb->end_subject - eptr) < length) return 1; /* Partial */ - if (memcmp(p, eptr, CU2BYTES(length)) != 0) return -1; /* No match */ + if ((PCRE2_SIZE)(mb->end_subject - eptr) < length || + memcmp(p, eptr, CU2BYTES(length)) != 0) return -1; /* No match */ eptr += length; } } @@ -495,6 +498,75 @@ return 0; /* Match */ +/************************************************* +* Restore offsets after a recurse * +*************************************************/ + +/* This function restores the ovector values when +a recursive block reaches its end, and the triggering +recurse has and argument list. + +Arguments: + F the current backtracking frame pointer + P the previous backtracking frame pointer +*/ + +static void +recurse_update_offsets(heapframe *F, heapframe *P) +{ +PCRE2_SIZE *dst = F->ovector; +PCRE2_SIZE *src = P->ovector; +/* The first bracket has offset 2, because +offset 0 is reserved for the full match. */ +PCRE2_SIZE offset = 2; +PCRE2_SIZE offset_top = Foffset_top + 2; +PCRE2_SIZE diff; +PCRE2_SPTR ecode = Fecode; + +do + { + diff = (GET2(ecode, 1) << 1) - offset; + ecode += 1 + IMM2_SIZE; + + if (offset + diff >= offset_top) + { + /* Some OP_CREF opcodes are not + processed, they must be skipped. */ + while (*ecode == OP_CREF) ecode += 1 + IMM2_SIZE; + break; + } + + if (diff == 2) + { + dst[0] = src[0]; + dst[1] = src[1]; + } + else if (diff >= 4) + memcpy(dst, src, diff * sizeof(PCRE2_SIZE)); + + /* Skip the unmodified entry. */ + diff += 2; + offset += diff; + dst += diff; + src += diff; + } +while (*ecode == OP_CREF); + +diff = offset_top - offset; +if (diff == 2) + { + dst[0] = src[0]; + dst[1] = src[1]; + } +else if (diff >= 4) + memcpy(dst, src, diff * sizeof(PCRE2_SIZE)); + +Fecode = ecode; +Foffset_top = (offset <= P->offset_top) ? P->offset_top : (offset - 2); +} + + + /****************************************************************************** ******************************************************************************* "Recursion" in the match() function @@ -898,7 +970,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, Fecode += 1 + LINK_SIZE; continue; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* OP_END itself can never be reached within a recursion because that is picked up when the OP_KET that always precedes OP_END is reached. */ @@ -938,11 +1010,28 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } #ifdef DEBUG_SHOW_OPS - fprintf(stderr, "++ Failed ACCEPT not at end (endanchnored set)\n"); + fprintf(stderr, "++ Failed ACCEPT not at end (endanchored set)\n"); #endif return MATCH_NOMATCH; /* (*ACCEPT) */ } + /* Fail if we detect that the start position was moved to be either after + the end position (\K in lookahead) or before the start offset (\K in + lookbehind). If this occurs, the pattern must have used \K in a somewhat + sneaky way (e.g. by pattern recursion), because if the \K is actually + syntactically inside the lookaround, it's blocked at compile-time. */ + + if (Fstart_match < mb->start_subject + mb->start_offset || + Fstart_match > Feptr) + { + /* The \K expression is fairly rare. We assert it was used so that we + catch any unexpected invalid data in start_match. */ + PCRE2_ASSERT(mb->hasbsk); + + if (!mb->allowlookaroundbsk) + return PCRE2_ERROR_BAD_BACKSLASH_K; + } + /* We have a successful match of the whole pattern. Record the result and then do a direct return from the function. If there is space in the offset vector, set any pairs that follow the highest-numbered captured string but @@ -982,7 +1071,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, mb->hitend = TRUE; if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Match any single character whatsoever. */ @@ -2779,9 +2868,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, /* This should never occur */ + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } Fecode += 3; @@ -3130,9 +3221,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, /* This should not occur */ + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } } @@ -3406,9 +3499,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } /* End switch(Lctype) */ else @@ -3659,9 +3754,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } } @@ -3945,9 +4042,12 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, PCRE2_UNREACHABLE(); /* Control never reaches here */ /* This should never occur */ + + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } } @@ -4100,9 +4200,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, RRETURN(MATCH_NOMATCH); break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } } } @@ -4245,9 +4347,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, RRETURN(MATCH_NOMATCH); break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } } } @@ -4514,9 +4618,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } /* Feptr is now past the end of the maximum run */ @@ -4833,9 +4939,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } if (reptype == REPTYPE_POS) continue; /* No backtracking */ @@ -5091,9 +5199,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, } break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } if (reptype == REPTYPE_POS) continue; /* No backtracking */ @@ -5824,6 +5934,9 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); Foffset_top = assert_accept_frame->offset_top; Fmark = assert_accept_frame->mark; + mb->end_subject = Lsaved_end_subject; + mb->true_end_subject = mb->end_subject + Ltrue_end_extra; + mb->moptions = Lsaved_moptions; break; } @@ -5987,7 +6100,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); Foffset_top = assert_accept_frame->offset_top; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* In the case of a match, the captures have already been put into the current frame. */ @@ -6260,12 +6373,18 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, /* Reinstate the previous set of captures and then carry on after the recursion call. */ - memcpy((char *)F + offsetof(heapframe, ovector), P->ovector, - Foffset_top * sizeof(PCRE2_SIZE)); - Foffset_top = P->offset_top; + Fecode = P->ecode + 1 + LINK_SIZE; + + if (*Fecode != OP_CREF) + { + memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE)); + Foffset_top = P->offset_top; + } + else + recurse_update_offsets(F, P); + Fcapture_last = P->capture_last; Fcurrent_recurse = P->current_recurse; - Fecode = P->ecode + 1 + LINK_SIZE; continue; /* With next opcode */ case OP_COND: /* No need to do anything for these */ @@ -6279,7 +6398,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, case OP_ASSERTBACK_NA: if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) RRETURN(MATCH_NOMATCH); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ASSERT_NA: if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; @@ -6293,12 +6412,12 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, case OP_ASSERTBACK: if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) RRETURN(MATCH_NOMATCH); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ASSERT: if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; Feptr = P->eptr; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* For an atomic group, discard internal backtracking points. We must also ensure that any remaining branches within the top-level of the group @@ -6322,7 +6441,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, case OP_ASSERTBACK_NOT: if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) RRETURN(MATCH_NOMATCH); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ASSERT_NOT: RRETURN(MATCH_MATCH); @@ -6367,12 +6486,18 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if (Fcurrent_recurse == number) { P = (heapframe *)((char *)N - frame_size); - memcpy((char *)F + offsetof(heapframe, ovector), P->ovector, - Foffset_top * sizeof(PCRE2_SIZE)); - Foffset_top = P->offset_top; + Fecode = P->ecode + 1 + LINK_SIZE; + + if (*Fecode != OP_CREF) + { + memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE)); + Foffset_top = P->offset_top; + } + else + recurse_update_offsets(F, P); + Fcapture_last = P->capture_last; Fcurrent_recurse = P->current_recurse; - Fecode = P->ecode + 1 + LINK_SIZE; continue; /* With next opcode */ } @@ -6450,7 +6575,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((mb->moptions & PCRE2_NOTEOL) != 0) RRETURN(MATCH_NOMATCH); if ((mb->poptions & PCRE2_DOLLAR_ENDONLY) == 0) goto ASSERT_NL_OR_EOS; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Unconditional end of subject assertion (\z). */ case OP_EOD: @@ -6748,9 +6873,11 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, /* There's been some horrible disaster. Arrival here can only mean there is something seriously wrong in the code above or the OP_xxx definitions. */ + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } /* Do not insert any code in here without much thought; it is assumed @@ -6798,9 +6925,11 @@ switch (Freturn_id) LBL(221) LBL(222) LBL(223) LBL(224) #endif + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } #undef LBL } @@ -6836,9 +6965,9 @@ pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, pcre2_match_context *mcontext) { int rc; -int was_zero_terminated = 0; const uint8_t *start_bits = NULL; const pcre2_real_code *re = (const pcre2_real_code *)code; +uint32_t original_options = options; BOOL anchored; BOOL firstline; @@ -6856,6 +6985,8 @@ PCRE2_UCHAR first_cu2 = 0; PCRE2_UCHAR req_cu = 0; PCRE2_UCHAR req_cu2 = 0; +PCRE2_UCHAR null_str[1] = { 0xcd }; +PCRE2_SPTR original_subject = subject; PCRE2_SPTR bumpalong_limit; PCRE2_SPTR end_subject; PCRE2_SPTR true_end_subject; @@ -6894,33 +7025,35 @@ match_block *mb = &actual_match_block; /* Recognize NULL, length 0 as an empty string. */ -if (subject == NULL && length == 0) subject = (PCRE2_SPTR)""; +if (subject == NULL && length == 0) subject = null_str; /* Plausibility checks */ -if ((options & ~PUBLIC_MATCH_OPTIONS) != 0) return PCRE2_ERROR_BADOPTION; -if (code == NULL || subject == NULL || match_data == NULL) - return PCRE2_ERROR_NULL; +if (match_data == NULL) return PCRE2_ERROR_NULL; +if (code == NULL || subject == NULL) + return match_data->rc = PCRE2_ERROR_NULL; +if ((options & ~PUBLIC_MATCH_OPTIONS) != 0) + return match_data->rc = PCRE2_ERROR_BADOPTION; start_match = subject + start_offset; req_cu_ptr = start_match - 1; if (length == PCRE2_ZERO_TERMINATED) { length = PRIV(strlen)(subject); - was_zero_terminated = 1; } true_end_subject = end_subject = subject + length; -if (start_offset > length) return PCRE2_ERROR_BADOFFSET; +if (start_offset > length) return match_data->rc = PCRE2_ERROR_BADOFFSET; /* Check that the first field in the block is the magic number. */ -if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; +if (re->magic_number != MAGIC_NUMBER) + return match_data->rc = PCRE2_ERROR_BADMAGIC; /* Check the code unit width. */ if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH/8) - return PCRE2_ERROR_BADMODE; + return match_data->rc = PCRE2_ERROR_BADMODE; /* PCRE2_NOTEMPTY and PCRE2_NOTEMPTY_ATSTART are match-time flags in the options variable for this function. Users of PCRE2 who are not calling the @@ -6967,17 +7100,18 @@ time. */ if (mb->partial != 0 && ((re->overall_options | options) & PCRE2_ENDANCHORED) != 0) - return PCRE2_ERROR_BADOPTION; + return match_data->rc = PCRE2_ERROR_BADOPTION; /* It is an error to set an offset limit without setting the flag at compile time. */ if (mcontext != NULL && mcontext->offset_limit != PCRE2_UNSET && (re->overall_options & PCRE2_USE_OFFSET_LIMIT) == 0) - return PCRE2_ERROR_BADOFFSETLIMIT; + return match_data->rc = PCRE2_ERROR_BADOFFSETLIMIT; /* If the match data block was previously used with PCRE2_COPY_MATCHED_SUBJECT, -free the memory that was obtained. Set the field to NULL for no match cases. */ +free the memory that was obtained. Set the field to NULL for match error +cases. */ if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0) { @@ -7014,11 +7148,11 @@ if (use_jit) #if PCRE2_CODE_UNIT_WIDTH != 32 if (start_match < end_subject && NOT_FIRSTCU(*start_match)) { - if (start_offset > 0) return PCRE2_ERROR_BADUTFOFFSET; + if (start_offset > 0) return match_data->rc = PCRE2_ERROR_BADUTFOFFSET; #if PCRE2_CODE_UNIT_WIDTH == 8 - return PCRE2_ERROR_UTF8_ERR20; /* Isolated 0x80 byte */ + return match_data->rc = PCRE2_ERROR_UTF8_ERR20; /* Isolated 0x80 byte */ #else - return PCRE2_ERROR_UTF16_ERR3; /* Isolated low surrogate */ + return match_data->rc = PCRE2_ERROR_UTF16_ERR3; /* Isolated low surrogate */ #endif } #endif /* WIDTH != 32 */ @@ -7053,12 +7187,12 @@ if (use_jit) /* Validate the relevant portion of the subject. Adjust the offset of an invalid code point to be an absolute offset in the whole string. */ - match_data->rc = PRIV(valid_utf)(start_match, + rc = PRIV(valid_utf)(start_match, length - (start_match - subject), &(match_data->startchar)); - if (match_data->rc != 0) + if (rc != 0) { match_data->startchar += start_match - subject; - return match_data->rc; + return match_data->rc = rc; } jit_checked_utf = TRUE; } @@ -7071,16 +7205,27 @@ if (use_jit) match_data, mcontext); if (rc != PCRE2_ERROR_JIT_BADOPTION) { - match_data->subject_length = length; + match_data->options = original_options; if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0) { - length = CU2BYTES(length + was_zero_terminated); - match_data->subject = match_data->memctl.malloc(length, - match_data->memctl.memory_data); - if (match_data->subject == NULL) return PCRE2_ERROR_NOMEMORY; - memcpy((void *)match_data->subject, subject, length); + if (length != 0) + { + match_data->subject = match_data->memctl.malloc(CU2BYTES(length), + match_data->memctl.memory_data); + if (match_data->subject == NULL) + return match_data->rc = PCRE2_ERROR_NOMEMORY; + memcpy((void *)match_data->subject, subject, CU2BYTES(length)); + } + else + match_data->subject = NULL; match_data->flags |= PCRE2_MD_COPIED_SUBJECT; } + else + { + /* When pcre2_jit_match sets the subject, it doesn't know what the + original passed-in pointer was. */ + if (match_data->subject != NULL) match_data->subject = original_subject; + } return rc; } } @@ -7137,11 +7282,11 @@ if (utf && } else if (start_match < end_subject && NOT_FIRSTCU(*start_match)) { - if (start_offset > 0) return PCRE2_ERROR_BADUTFOFFSET; + if (start_offset > 0) return match_data->rc = PCRE2_ERROR_BADUTFOFFSET; #if PCRE2_CODE_UNIT_WIDTH == 8 - return PCRE2_ERROR_UTF8_ERR20; /* Isolated 0x80 byte */ + return match_data->rc = PCRE2_ERROR_UTF8_ERR20; /* Isolated 0x80 byte */ #else - return PCRE2_ERROR_UTF16_ERR3; /* Isolated low surrogate */ + return match_data->rc = PCRE2_ERROR_UTF16_ERR3; /* Isolated low surrogate */ #endif } #endif /* WIDTH != 32 */ @@ -7189,10 +7334,10 @@ if (utf && for (;;) { - match_data->rc = PRIV(valid_utf)(mb->check_subject, + rc = PRIV(valid_utf)(mb->check_subject, length - (mb->check_subject - subject), &(match_data->startchar)); - if (match_data->rc == 0) break; /* Valid UTF string */ + if (rc == 0) break; /* Valid UTF string */ /* Invalid UTF string. Adjust the offset to be an absolute offset in the whole string. If we are handling invalid UTF strings, set end_subject to @@ -7200,7 +7345,7 @@ if (utf && Otherwise return the error. */ match_data->startchar += mb->check_subject - subject; - if (!allow_invalid || match_data->rc > 0) return match_data->rc; + if (!allow_invalid || rc > 0) return match_data->rc = rc; end_subject = subject + match_data->startchar; /* If the end precedes start_match, it means there is invalid UTF in the @@ -7265,8 +7410,11 @@ mb->start_offset = start_offset; mb->end_subject = end_subject; mb->true_end_subject = true_end_subject; mb->hasthen = (re->flags & PCRE2_HASTHEN) != 0; +mb->hasbsk = (re->flags & PCRE2_HASBSK) != 0; mb->allowemptypartial = (re->max_lookbehind > 0) || (re->flags & PCRE2_MATCH_EMPTY) != 0; +mb->allowlookaroundbsk = + (re->extra_options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) != 0; mb->poptions = re->overall_options; /* Pattern options */ mb->ignore_skip_arg = 0; mb->mark = mb->nomatch_mark = NULL; /* In case never set */ @@ -7314,9 +7462,11 @@ switch(re->newline_convention) mb->nltype = NLTYPE_ANYCRLF; break; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); - return PCRE2_ERROR_INTERNAL; + return match_data->rc = PCRE2_ERROR_INTERNAL; + /* LCOV_EXCL_STOP */ } /* The backtracking frames have fixed data at the front, and a PCRE2_SIZE @@ -7358,7 +7508,7 @@ if (heapframes_size < START_FRAMES_SIZE) heapframes_size = START_FRAMES_SIZE; if (heapframes_size / 1024 > mb->heap_limit) { PCRE2_SIZE max_size = 1024 * mb->heap_limit; - if (max_size < frame_size) return PCRE2_ERROR_HEAPLIMIT; + if (max_size < frame_size) return match_data->rc = PCRE2_ERROR_HEAPLIMIT; heapframes_size = max_size; } @@ -7374,7 +7524,7 @@ if (match_data->heapframes_size < heapframes_size) if (match_data->heapframes == NULL) { match_data->heapframes_size = 0; - return PCRE2_ERROR_NOMEMORY; + return match_data->rc = PCRE2_ERROR_NOMEMORY; } match_data->heapframes_size = heapframes_size; } @@ -7850,7 +8000,7 @@ for(;;) new_start_match = mb->verb_skip_ptr; break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* NOMATCH and PRUNE advance by one character. THEN at this level acts exactly like PRUNE. Unset ignore SKIP-with-argument. */ @@ -8008,6 +8158,7 @@ if (utf && end_subject != true_end_subject && match_data->code = re; match_data->mark = mb->mark; match_data->matchedby = PCRE2_MATCHEDBY_INTERPRETER; +match_data->options = original_options; /* Handle a fully successful match. Set the return code to the number of captured strings, or 0 if there were too many to fit into the ovector, and then @@ -8019,20 +8170,26 @@ if (rc == MATCH_MATCH) match_data->rc = ((int)mb->end_offset_top >= 2 * match_data->oveccount)? 0 : (int)mb->end_offset_top/2 + 1; match_data->subject_length = length; + match_data->start_offset = start_offset; match_data->startchar = start_match - subject; match_data->leftchar = mb->start_used_ptr - subject; match_data->rightchar = ((mb->last_used_ptr > mb->end_match_ptr)? mb->last_used_ptr : mb->end_match_ptr) - subject; if ((options & PCRE2_COPY_MATCHED_SUBJECT) != 0) { - length = CU2BYTES(length + was_zero_terminated); - match_data->subject = match_data->memctl.malloc(length, - match_data->memctl.memory_data); - if (match_data->subject == NULL) return PCRE2_ERROR_NOMEMORY; - memcpy((void *)match_data->subject, subject, length); + if (length != 0) + { + match_data->subject = match_data->memctl.malloc(CU2BYTES(length), + match_data->memctl.memory_data); + if (match_data->subject == NULL) + return match_data->rc = PCRE2_ERROR_NOMEMORY; + memcpy((void *)match_data->subject, subject, CU2BYTES(length)); + } + else + match_data->subject = NULL; match_data->flags |= PCRE2_MD_COPIED_SUBJECT; } - else match_data->subject = subject; + else match_data->subject = original_subject; return match_data->rc; } @@ -8054,8 +8211,9 @@ PCRE2_ERROR_PARTIAL. */ else if (match_partial != NULL) { - match_data->subject = subject; + match_data->subject = original_subject; match_data->subject_length = length; + match_data->start_offset = start_offset; match_data->ovector[0] = match_partial - subject; match_data->ovector[1] = end_subject - subject; match_data->startchar = match_partial - subject; @@ -8066,7 +8224,13 @@ else if (match_partial != NULL) /* Else this is the classic nomatch case. */ -else match_data->rc = PCRE2_ERROR_NOMATCH; +else + { + match_data->subject = original_subject; + match_data->subject_length = length; + match_data->start_offset = start_offset; + match_data->rc = PCRE2_ERROR_NOMATCH; + } return match_data->rc; } diff --git a/libpcre/src/pcre2_match_data.c b/libpcre/src/pcre2_match_data.c index 100e7c9d9..fade67ae5 100644 --- a/libpcre/src/pcre2_match_data.c +++ b/libpcre/src/pcre2_match_data.c @@ -39,10 +39,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" @@ -85,6 +81,7 @@ PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION pcre2_match_data_create_from_pattern(const pcre2_code *code, pcre2_general_context *gcontext) { +if (code == NULL) return NULL; if (gcontext == NULL) gcontext = (pcre2_general_context *)code; return pcre2_match_data_create(((const pcre2_real_code *)code)->top_bracket + 1, gcontext); diff --git a/libpcre/src/pcre2_match_next.c b/libpcre/src/pcre2_match_next.c new file mode 100644 index 000000000..ecd21d380 --- /dev/null +++ b/libpcre/src/pcre2_match_next.c @@ -0,0 +1,171 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Original API code Copyright (c) 1997-2012 University of Cambridge + New API code Copyright (c) 2016-2024 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +#include "pcre2_internal.h" + + + +/* Advance the offset by one code unit, and return the new value. +It is only called when the offset is not at the end of the subject. */ + +static PCRE2_SIZE do_bumpalong(pcre2_match_data *match_data, + PCRE2_SIZE offset) +{ +PCRE2_SPTR subject = match_data->subject; +PCRE2_SIZE subject_length = match_data->subject_length; +#ifdef SUPPORT_UNICODE +BOOL utf = (match_data->code->overall_options & PCRE2_UTF) != 0; +#endif + +/* Skip over CRLF as an atomic sequence, if CRLF is configured as a newline +sequence. */ + +if (subject[offset] == CHAR_CR && offset + 1 < subject_length && + subject[offset + 1] == CHAR_LF) + { + switch(match_data->code->newline_convention) + { + case PCRE2_NEWLINE_CRLF: + case PCRE2_NEWLINE_ANY: + case PCRE2_NEWLINE_ANYCRLF: + return offset + 2; + } + } + +/* Advance by one full character if in UTF mode. */ + +#ifdef SUPPORT_UNICODE +if (utf) + { + PCRE2_SPTR next = subject + offset + 1; + PCRE2_SPTR subject_end = subject + subject_length; + + (void)subject_end; /* Suppress warning; 32-bit FORWARDCHARTEST ignores this */ + FORWARDCHARTEST(next, subject_end); + return next - subject; + } +#endif + +return offset + 1; +} + + + +/************************************************* +* Advance the match * +*************************************************/ + +PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION +pcre2_next_match(pcre2_match_data *match_data, PCRE2_SIZE *pstart_offset, + uint32_t *poptions) +{ +int rc = match_data->rc; +PCRE2_SIZE start_offset = match_data->start_offset; +PCRE2_SIZE *ovector = match_data->ovector; + +/* Match error, or no match: no further iteration possible. In previous versions +of PCRE2, we recommended that clients use a strategy which involved retrying in +certain cases after PCRE2_ERROR_NOMATCH, but this is no longer required. */ + +if (rc < 0) + return FALSE; + +/* Match succeeded: get the start offset for the next match */ + +/* Although \K can affect the position of ovector[0], there are no ways to do +anything surprising with ovector[1], which must always be >= start_offset. */ + +PCRE2_ASSERT(ovector[1] >= start_offset); + +/* Special handling for patterns which contain \K in a lookaround, which enables +the match start to be pushed back to before the starting search offset +(ovector[0] < start_offset) or after the match ends (ovector[0] > ovector[1]). +This is not a problem if ovector[1] > start_offset, because in this case, we can +just attempt the next match at ovector[1]: we are making progress, which is all +that we require. + +However, if we have ovector[1] == start_offset, then we have a very rare case +which must be handled specially, because it's a non-empty match which +nonetheless fails to make progress through the subject. */ + +if (ovector[0] != start_offset && ovector[1] == start_offset) + { + /* If the match end is at the end of the subject, we are done. */ + + if (start_offset >= match_data->subject_length) + return FALSE; + + /* Otherwise, bump along by one code unit, and do a normal search. */ + + *pstart_offset = do_bumpalong(match_data, ovector[1]); + *poptions = 0; + return TRUE; + } + +/* If the previous match was for an empty string, we are finished if we are at +the end of the subject. Otherwise, arrange to run another match at the same +point to see if a non-empty match can be found. */ + +if (ovector[0] == ovector[1]) + { + /* If the match is at the end of the subject, we are done. */ + + if (ovector[0] >= match_data->subject_length) + return FALSE; + + /* Otherwise, continue at this exact same point, but we must set the flag + which ensures that we don't return the exact same empty match again. */ + + *pstart_offset = ovector[1]; + *poptions = PCRE2_NOTEMPTY_ATSTART; + return TRUE; + } + +/* Finally, we must be in the happy state of a non-empty match, where the end of +the match is further on in the subject than start_offset, so we are easily able +to continue and make progress. */ + +*pstart_offset = ovector[1]; +*poptions = 0; +return TRUE; +} + +/* End of pcre2_match_next.c */ diff --git a/libpcre/src/pcre2_newline.c b/libpcre/src/pcre2_newline.c index 6e9366db9..a7c929921 100644 --- a/libpcre/src/pcre2_newline.c +++ b/libpcre/src/pcre2_newline.c @@ -48,10 +48,6 @@ and NLTYPE_ANY. The full list of Unicode newline characters is taken from http://unicode.org/unicode/reports/tr18/. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" diff --git a/libpcre/src/pcre2_ord2utf.c b/libpcre/src/pcre2_ord2utf.c index a1e9e0880..3b8aead75 100644 --- a/libpcre/src/pcre2_ord2utf.c +++ b/libpcre/src/pcre2_ord2utf.c @@ -43,13 +43,10 @@ POSSIBILITY OF SUCH DAMAGE. into a UTF string. The behaviour is different for each code unit width. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + /* If SUPPORT_UNICODE is not defined, this function will never be called. Supply a dummy function because some compilers do not like empty source modules. */ @@ -83,16 +80,17 @@ PRIV(ord2utf)(uint32_t cvalue, PCRE2_UCHAR *buffer) /* Convert to UTF-8 */ #if PCRE2_CODE_UNIT_WIDTH == 8 -int i, j; +unsigned int i; + for (i = 0; i < PRIV(utf8_table1_size); i++) if ((int)cvalue <= PRIV(utf8_table1)[i]) break; buffer += i; -for (j = i; j > 0; j--) +for (unsigned int j = i; j != 0; j--) { *buffer-- = 0x80 | (cvalue & 0x3f); cvalue >>= 6; } -*buffer = PRIV(utf8_table2)[i] | cvalue; +*buffer = (PCRE2_UCHAR)(PRIV(utf8_table2)[i] | (int)cvalue); return i + 1; /* Convert to UTF-16 */ diff --git a/libpcre/src/pcre2_pattern_info.c b/libpcre/src/pcre2_pattern_info.c index fe4d3c661..e0bd83a90 100644 --- a/libpcre/src/pcre2_pattern_info.c +++ b/libpcre/src/pcre2_pattern_info.c @@ -39,13 +39,10 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + /************************************************* * Return info about compiled pattern * *************************************************/ @@ -292,8 +289,7 @@ if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC; if ((re->flags & (PCRE2_CODE_UNIT_WIDTH/8)) == 0) return PCRE2_ERROR_BADMODE; cb.version = 0; -cc = (PCRE2_SPTR)((const uint8_t *)re + sizeof(pcre2_real_code)) - + re->name_count * re->name_entry_size; +cc = (PCRE2_SPTR)((uint8_t *)re + re->code_start); while (TRUE) { diff --git a/libpcre/src/pcre2_printint_inc.h b/libpcre/src/pcre2_printint_inc.h new file mode 100644 index 000000000..4dd689e38 --- /dev/null +++ b/libpcre/src/pcre2_printint_inc.h @@ -0,0 +1,1098 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Original API code Copyright (c) 1997-2012 University of Cambridge + New API code Copyright (c) 2016-2024 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +/* This module contains a PCRE private debugging function for printing out the +internal form of a compiled regular expression, along with some supporting +local functions. This source file is #included in pcre2test.c at each supported +code unit width, with PCRE2_SUFFIX set appropriately, just like the functions +that comprise the library. It can also optionally be included in +pcre2_compile.c for detailed debugging in error situations. */ + + + +/* Tables of operator names. The same 8-bit table is used for all code unit +widths, so it must be defined only once. The list itself is defined in +pcre2_internal.h, which is #included by pcre2test before this file. */ + +#ifndef OP_LISTS_DEFINED +static const char *OP_names[] = { OP_NAME_LIST }; +STATIC_ASSERT(sizeof(OP_names)/sizeof(*OP_names) == OP_TABLE_LENGTH, OP_names); +#define OP_LISTS_DEFINED +#endif + +/* The functions and tables herein must all have mode-dependent names. */ + +#define OP_lengths PCRE2_SUFFIX(OP_lengths_) +#define get_ucpname PCRE2_SUFFIX(get_ucpname_) +#define pcre2_printint PCRE2_SUFFIX(pcre2_printint_) +#define print_char PCRE2_SUFFIX(print_char_) +#define print_custring PCRE2_SUFFIX(print_custring_) +#define print_custring_bylen PCRE2_SUFFIX(print_custring_bylen_) +#define print_prop PCRE2_SUFFIX(print_prop_) +#define print_char_list PCRE2_SUFFIX(print_char_list_) +#define print_map PCRE2_SUFFIX(print_map_) +#define print_class PCRE2_SUFFIX(print_class_) + +/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that +the definition is next to the definition of the opcodes in pcre2_internal.h. +The contents of the table are, however, mode-dependent. */ + +static const uint8_t OP_lengths[] = { OP_LENGTHS }; +STATIC_ASSERT(sizeof(OP_lengths)/sizeof(*OP_lengths) == OP_TABLE_LENGTH, + PCRE2_SUFFIX(OP_lengths_)); + + +/************************************************* +* Print one character from a string * +*************************************************/ + +/* In UTF mode the character may occupy more than one code unit. + +Arguments: + f file to write to + ptr pointer to first code unit of the character + utf TRUE if string is UTF (will be FALSE if UTF is not supported) + +Returns: number of additional code units used +*/ + +static unsigned int +print_char(FILE *f, PCRE2_SPTR ptr, BOOL utf) +{ +uint32_t c = *ptr; +BOOL one_code_unit = !utf; + +/* If UTF is supported and requested, check for a valid single code unit. */ + +#ifdef SUPPORT_UNICODE +if (utf) + { +#if PCRE2_CODE_UNIT_WIDTH == 8 + one_code_unit = c < 0x80; +#elif PCRE2_CODE_UNIT_WIDTH == 16 + one_code_unit = (c & 0xfc00) != 0xd800; +#else + one_code_unit = (c & 0xfffff800u) != 0xd800u; +#endif /* CODE_UNIT_WIDTH */ + } +#endif /* SUPPORT_UNICODE */ + +/* Handle a valid one-code-unit character at any width. */ + +if (one_code_unit) + { + if (PRINTABLE(c)) + fprintf(f, "%c", CHAR_OUTPUT(c)); + else + { + c = CHAR_OUTPUT_HEX(c); + if (c < 0x80) fprintf(f, "\\x%02x", c); + else fprintf(f, "\\x{%02x}", c); + } + return 0; + } + +/* Code for invalid UTF code units and multi-unit UTF characters is different +for each width. If UTF is not supported, control should never get here, but we +need a return statement to keep the compiler happy. */ + +#ifndef SUPPORT_UNICODE +return 0; +#else + +/* Malformed UTF-8 should occur only if the sanity check has been turned off. +Rather than swallow random bytes, just stop if we hit a bad one. Print it with +\X instead of \x as an indication. */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 +if ((c & 0xc0) != 0xc0) + { + fprintf(f, "\\X{%x}", c); /* Invalid starting byte */ + return 0; + } +else + { + int i; + int a = PRIV(utf8_table4)[c & 0x3f]; /* Number of additional bytes */ + int s = 6*a; + c = (c & PRIV(utf8_table3)[a]) << s; + for (i = 1; i <= a; i++) + { + if ((ptr[i] & 0xc0) != 0x80) + { + fprintf(f, "\\X{%x}", c); /* Invalid secondary byte */ + return i - 1; + } + s -= 6; + c |= (ptr[i] & 0x3f) << s; + } + fprintf(f, "\\x{%x}", c); + return a; +} +#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ + +/* UTF-16: rather than swallow a low surrogate, just stop if we hit a bad one. +Print it with \X instead of \x as an indication. */ + +#if PCRE2_CODE_UNIT_WIDTH == 16 +if ((ptr[1] & 0xfc00) != 0xdc00) + { + fprintf(f, "\\X{%x}", c); + return 0; + } +c = (((c & 0x3ff) << 10) | (ptr[1] & 0x3ff)) + 0x10000; +fprintf(f, "\\x{%x}", c); +return 1; +#endif /* PCRE2_CODE_UNIT_WIDTH == 16 */ + +/* For UTF-32 we get here only for a malformed code unit, which should only +occur if the sanity check has been turned off. Print it with \X instead of \x +as an indication. */ + +#if PCRE2_CODE_UNIT_WIDTH == 32 +fprintf(f, "\\X{%x}", c); +return 0; +#endif /* PCRE2_CODE_UNIT_WIDTH == 32 */ +#endif /* SUPPORT_UNICODE */ +} + + + +/************************************************* +* Print string as a list of code units * +*************************************************/ + +/* These take no account of UTF as they always print each individual code unit. +The string is zero-terminated for print_custring(); the length is given for +print_custring_bylen(). + +Arguments: + f file to write to + ptr point to the string + len length for print_custring_bylen() + +Returns: nothing +*/ + +static void +print_custring(FILE *f, PCRE2_SPTR ptr) +{ +while (*ptr != '\0') + { + uint32_t c = *ptr++; + if (PRINTABLE(c)) fprintf(f, "%c", CHAR_OUTPUT(c)); + else fprintf(f, "\\x{%x}", CHAR_OUTPUT_HEX(c)); + } +} + +static void +print_custring_bylen(FILE *f, PCRE2_SPTR ptr, PCRE2_UCHAR len) +{ +for (; len > 0; len--) + { + uint32_t c = *ptr++; + if (PRINTABLE(c)) fprintf(f, "%c", CHAR_OUTPUT(c)); + else fprintf(f, "\\x{%x}", CHAR_OUTPUT_HEX(c)); + } +} + + + +/************************************************* +* Find Unicode property name * +*************************************************/ + +/* When there is no UTF/UCP support, the table of names does not exist. This +function should not be called in such configurations, because a pattern that +tries to use Unicode properties won't compile. Rather than put lots of #ifdefs +into the main code, however, we just put one into this function. + +Now that the table contains both full names and their abbreviations, we do some +fiddling to try to get the full name, which is either the longer of two found +names, or a 3-character script name. */ + +static const char * +get_ucpname(unsigned int ptype, unsigned int pvalue) +{ +#ifdef SUPPORT_UNICODE +int count = 0; +const char *yield = "??"; +size_t len = 0; +unsigned int ptypex = (ptype == PT_SC)? PT_SCX : ptype; + +for (ptrdiff_t i = PRIV(utt_size) - 1; i >= 0; i--) + { + const ucp_type_table *u = PRIV(utt) + i; + + if ((ptype == u->type || ptypex == u->type) && pvalue == u->value) + { + const char *s = PRIV(utt_names) + u->name_offset; + size_t sl = strlen(s); + + if (sl == 3 && (u->type == PT_SC || u->type == PT_SCX)) + { + yield = s; + break; + } + + if (sl > len) + { + yield = s; + len = sl; + } + + if (++count >= 2) break; + } + } + +return yield; + +#else /* No UTF support */ +(void)ptype; +(void)pvalue; +return "??"; +#endif /* SUPPORT_UNICODE */ +} + + + +/************************************************* +* Print Unicode property value * +*************************************************/ + +/* "Normal" properties can be printed from tables. The PT_CLIST property is a +pseudo-property that contains a pointer to a list of case-equivalent +characters. + +Arguments: + f file to write to + code pointer in the compiled code + before text to print before + after text to print after + +Returns: nothing +*/ + +static void +print_prop(FILE *f, PCRE2_SPTR code, const char *before, const char *after) +{ +if (code[1] != PT_CLIST) + { + const char *sc = (code[1] == PT_SC)? "script:" : ""; + const char *s = get_ucpname(code[1], code[2]); + fprintf(f, "%s%s %s%c%s%s", before, OP_names[*code], sc, toupper(s[0]), s+1, after); + } +else + { + const uint32_t *p = PRIV(ucd_caseless_sets) + code[2]; + fprintf (f, "%s%sclist", before, (*code == OP_PROP)? "" : "not "); + while (*p < NOTACHAR) fprintf(f, " %04x", *p++); + fprintf(f, "%s", after); + } +} + + + +/************************************************* +* Print character list * +*************************************************/ + +/* Prints the characters and character ranges in a character list. + +Arguments: + f file to write to + code pointer in the compiled code +*/ + +static PCRE2_SPTR +print_char_list(FILE *f, PCRE2_SPTR code, const uint8_t *char_lists_end) +{ +uint32_t type, list_ind; +uint32_t char_list_add = XCL_CHAR_LIST_LOW_16_ADD; +uint32_t range_start = ~(uint32_t)0, range_end = 0; +const uint8_t *next_char; + +#if PCRE2_CODE_UNIT_WIDTH == 8 +type = (uint32_t)(code[0] << 8) | code[1]; +code += 2; +#else +type = code[0]; +code++; +#endif /* CODE_UNIT_WIDTH */ + +/* Align characters. */ +next_char = char_lists_end - (GET(code, 0) << 1); +type &= XCL_TYPE_MASK; +list_ind = 0; + +if ((type & XCL_BEGIN_WITH_RANGE) != 0) + range_start = XCL_CHAR_LIST_LOW_16_START; + +while (type > 0) + { + uint32_t item_count = type & XCL_ITEM_COUNT_MASK; + + if (item_count == XCL_ITEM_COUNT_MASK) + { + if (list_ind <= 1) + { + item_count = *(const uint16_t*)next_char; + next_char += 2; + } + else + { + item_count = *(const uint32_t*)next_char; + next_char += 4; + } + } + + while (item_count > 0) + { + if (list_ind <= 1) + { + range_end = *(const uint16_t*)next_char; + next_char += 2; + } + else + { + range_end = *(const uint32_t*)next_char; + next_char += 4; + } + + if ((range_end & XCL_CHAR_END) != 0) + { + range_end = char_list_add + (range_end >> XCL_CHAR_SHIFT); + + if (range_start < range_end) + fprintf(f, "\\x{%x}-", range_start); + + fprintf(f, "\\x{%x}", range_end); + range_start = ~(uint32_t)0; + } + else + range_start = char_list_add + (range_end >> XCL_CHAR_SHIFT); + + item_count--; + } + + list_ind++; + type >>= XCL_TYPE_BIT_LEN; + + /* The following code could be optimized to 8/16/32 bit, + but it is not worth it for a debugging function. */ + + if (range_start == ~(uint32_t)0) + { + if ((type & XCL_BEGIN_WITH_RANGE) != 0) + { + if (list_ind == 1) range_start = XCL_CHAR_LIST_HIGH_16_START; + else if (list_ind == 2) range_start = XCL_CHAR_LIST_LOW_32_START; + else range_start = XCL_CHAR_LIST_HIGH_32_START; + } + } + else if ((type & XCL_BEGIN_WITH_RANGE) == 0) + { + fprintf(f, "\\x{%x}-", range_start); + + if (list_ind == 1) range_end = XCL_CHAR_LIST_LOW_16_END; + else if (list_ind == 2) range_end = XCL_CHAR_LIST_HIGH_16_END; + else if (list_ind == 3) range_end = XCL_CHAR_LIST_LOW_32_END; + else range_end = XCL_CHAR_LIST_HIGH_32_END; + + fprintf(f, "\\x{%x}", range_end); + range_start = ~(uint32_t)0; + } + + if (list_ind == 1) char_list_add = XCL_CHAR_LIST_HIGH_16_ADD; + else if (list_ind == 2) char_list_add = XCL_CHAR_LIST_LOW_32_ADD; + else char_list_add = XCL_CHAR_LIST_HIGH_32_ADD; + } + +return code + LINK_SIZE; +} + + + +/************************************************* +* Print a character bitmap * +*************************************************/ + +/* Prints a 32-byte bitmap, which occurs within a character class opcode. + +Arguments: + f file to write to + map pointer to the bitmap + negated TRUE if the bitmap will be printed as negated + +Returns: nothing +*/ + +static void +print_map(FILE *f, const uint8_t *map, BOOL negated) +{ +BOOL first = TRUE; +uint8_t inverted_map[32]; +int i, input; + +if (negated) + { + /* Using 255 ^ instead of ~ avoids clang sanitize warning. */ + for (i = 0; i < 32; i++) inverted_map[i] = 255 ^ map[i]; + map = inverted_map; + } + +for (input = 0; input < 256; input++) + { + i = CHAR_INPUT_HEX(input); + if ((map[i/8] & (1u << (i&7))) != 0) + { + int j, jinput; + for (jinput = input; jinput+1 < 256; jinput++) + { + j = CHAR_INPUT_HEX(jinput+1); + if ((map[j/8] & (1u << (j&7))) == 0) break; + } + j = CHAR_INPUT_HEX(jinput); + if (i == CHAR_MINUS || i == CHAR_BACKSLASH || + i == CHAR_RIGHT_SQUARE_BRACKET || + (first && i == CHAR_CIRCUMFLEX_ACCENT)) + fprintf(f, "\\"); + if (PRINTABLE(i)) fprintf(f, "%c", CHAR_OUTPUT(i)); + else fprintf(f, "\\x%02x", CHAR_OUTPUT_HEX(i)); + first = FALSE; + if (jinput > input) + { + if (jinput != input + 1) fprintf(f, "-"); + if (j == CHAR_MINUS || j == CHAR_BACKSLASH || + j == CHAR_RIGHT_SQUARE_BRACKET) + fprintf(f, "\\"); + if (PRINTABLE(j)) fprintf(f, "%c", CHAR_OUTPUT(j)); + else fprintf(f, "\\x%02x", CHAR_OUTPUT_HEX(j)); + } + input = jinput; + } + } +} + + + +/************************************************* +* Print character class * +*************************************************/ + +/* Prints a character class, which must be either an OP_CLASS, OP_NCLASS, or +OP_XCLASS. + +Arguments: + f file to write to + type OP_CLASS, OP_NCLASS, or OP_XCLASS + code pointer in the compiled code (after the OP tag) + utf TRUE if re is UTF (will be FALSE if UTF is not supported) + before text to print before + after text to print after + +Returns: nothing +*/ + +static void +print_class(FILE *f, int type, PCRE2_SPTR code, const uint8_t *char_lists_end, + BOOL utf, const char *before, const char *after) +{ +BOOL printmap, negated; +PCRE2_SPTR ccode; + +/* Negative XCLASS and NCLASS both have a bitmap indicating which characters +are accepted. For clarity we print this inverted and prefixed by "^". */ +if (type == OP_XCLASS) + { + ccode = code + LINK_SIZE; + printmap = (*ccode & XCL_MAP) != 0; + negated = (*ccode & XCL_NOT) != 0; + ccode++; + } +else /* CLASS or NCLASS */ + { + printmap = TRUE; + negated = type == OP_NCLASS; + ccode = code; + } + +fprintf(f, "%s[%s", before, negated? "^" : ""); + +/* Print a bit map */ +if (printmap) + { + print_map(f, (const uint8_t *)ccode, negated); + ccode += 32 / sizeof(PCRE2_UCHAR); + } + +/* For an XCLASS there is always some additional data */ +if (type == OP_XCLASS) + { + PCRE2_UCHAR ch; + + while ((ch = *ccode++) != XCL_END) + { + const char *notch = ""; + + if (ch >= XCL_LIST) + { + ccode = print_char_list(f, ccode - 1, char_lists_end); + break; + } + + switch(ch) + { + case XCL_NOTPROP: + notch = "^"; + PCRE2_FALLTHROUGH /* Fall through */ + case XCL_PROP: + { + unsigned int ptype = *ccode++; + unsigned int pvalue = *ccode++; + const char *s; + switch(ptype) + { + case PT_PXGRAPH: + fprintf(f, "[:%sgraph:]", notch); + break; + case PT_PXPRINT: + fprintf(f, "[:%sprint:]", notch); + break; + case PT_PXPUNCT: + fprintf(f, "[:%spunct:]", notch); + break; + case PT_PXXDIGIT: + fprintf(f, "[:%sxdigit:]", notch); + break; + default: + s = get_ucpname(ptype, pvalue); + fprintf(f, "\\%c{%c%s}", ((notch[0] == '^')? 'P':'p'), + toupper(s[0]), s+1); + break; + } + } + break; + + default: + ccode += 1 + print_char(f, ccode, utf); + if (ch == XCL_RANGE) + { + fprintf(f, "-"); + ccode += 1 + print_char(f, ccode, utf); + } + break; + } + } + + PCRE2_ASSERT(ccode == code + (GET(code, 0) - 1)); + } + +/* Indicate a non-UTF class which was created by negation */ +fprintf(f, "]%s", after); +} + + + +/************************************************* +* Print compiled pattern * +*************************************************/ + +/* The print_lengths flag controls whether offsets and lengths of items are +printed. Lenths can be turned off from pcre2test so that automatic tests on +bytecode can be written that do not depend on the value of LINK_SIZE. + +Arguments: + re a compiled pattern + f the file to write to + print_lengths show various lengths + +Returns: nothing +*/ + +static void +pcre2_printint(pcre2_code *re, FILE *f, BOOL print_lengths) +{ +PCRE2_SPTR codestart, nametable, code; +uint32_t nesize = re->name_entry_size; +BOOL utf = (re->overall_options & PCRE2_UTF) != 0; + +nametable = (PCRE2_SPTR)((uint8_t *)re + sizeof(pcre2_real_code)); +code = codestart = (PCRE2_SPTR)((uint8_t *)re + re->code_start); + +for(;;) + { + PCRE2_SPTR ccode; + uint32_t c; + int i; + const char *flag = " "; + unsigned int extra = 0; + + if (print_lengths) + fprintf(f, "%3d ", (int)(code - codestart)); + else + fprintf(f, " "); + + switch(*code) + { + case OP_END: + fprintf(f, " %s\n", OP_names[*code]); + fprintf(f, "------------------------------------------------------------------\n"); + return; + + case OP_CHAR: + fprintf(f, " "); + do + { + code++; + code += 1 + print_char(f, code, utf); + } + while (*code == OP_CHAR); + fprintf(f, "\n"); + continue; + + case OP_CHARI: + fprintf(f, " /i "); + do + { + code++; + code += 1 + print_char(f, code, utf); + } + while (*code == OP_CHARI); + fprintf(f, "\n"); + continue; + + case OP_CBRA: + case OP_CBRAPOS: + case OP_SCBRA: + case OP_SCBRAPOS: + if (print_lengths) fprintf(f, "%3d ", GET(code, 1)); + else fprintf(f, " "); + fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE)); + break; + + case OP_BRA: + case OP_BRAPOS: + case OP_SBRA: + case OP_SBRAPOS: + case OP_KETRMAX: + case OP_KETRMIN: + case OP_KETRPOS: + case OP_ALT: + case OP_KET: + case OP_ASSERT: + case OP_ASSERT_NOT: + case OP_ASSERTBACK: + case OP_ASSERTBACK_NOT: + case OP_ASSERT_NA: + case OP_ASSERTBACK_NA: + case OP_ASSERT_SCS: + case OP_ONCE: + case OP_SCRIPT_RUN: + case OP_COND: + case OP_SCOND: + if (print_lengths) fprintf(f, "%3d ", GET(code, 1)); + else fprintf(f, " "); + fprintf(f, "%s", OP_names[*code]); + break; + + case OP_CLOSE: + fprintf(f, " %s %d", OP_names[*code], GET2(code, 1)); + break; + + case OP_CREF: + case OP_REVERSE: + case OP_VREVERSE: + fprintf(f, "%3d %s", GET2(code, 1), OP_names[*code]); + if (*code == OP_VREVERSE) fprintf(f, " %d", GET2(code, 1 + IMM2_SIZE)); + break; + + case OP_DNCREF: + case OP_DNRREF: + { + PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE; + fprintf(f, " %s %s<", flag, OP_names[*code]); + print_custring(f, entry); + fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); + } + break; + + case OP_RREF: + c = GET2(code, 1); + if (c == RREF_ANY) + fprintf(f, " %s any", OP_names[*code]); + else + fprintf(f, " %s %d", OP_names[*code], c); + break; + + case OP_STARI: + case OP_MINSTARI: + case OP_POSSTARI: + case OP_PLUSI: + case OP_MINPLUSI: + case OP_POSPLUSI: + case OP_QUERYI: + case OP_MINQUERYI: + case OP_POSQUERYI: + flag = "/i"; + PCRE2_FALLTHROUGH /* Fall through */ + case OP_STAR: + case OP_MINSTAR: + case OP_POSSTAR: + case OP_PLUS: + case OP_MINPLUS: + case OP_POSPLUS: + case OP_QUERY: + case OP_MINQUERY: + case OP_POSQUERY: + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEPOSSTAR: + case OP_TYPEPLUS: + case OP_TYPEMINPLUS: + case OP_TYPEPOSPLUS: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + case OP_TYPEPOSQUERY: + fprintf(f, " %s ", flag); + + if (*code >= OP_TYPESTAR) + { + if (code[1] == OP_PROP || code[1] == OP_NOTPROP) + { + print_prop(f, code + 1, "", " "); + extra = 2; + } + else fprintf(f, "%s", OP_names[code[1]]); + } + else extra = print_char(f, code+1, utf); + fprintf(f, "%s", OP_names[*code]); + break; + + case OP_EXACTI: + case OP_UPTOI: + case OP_MINUPTOI: + case OP_POSUPTOI: + flag = "/i"; + PCRE2_FALLTHROUGH /* Fall through */ + case OP_EXACT: + case OP_UPTO: + case OP_MINUPTO: + case OP_POSUPTO: + fprintf(f, " %s ", flag); + extra = print_char(f, code + 1 + IMM2_SIZE, utf); + fprintf(f, "{"); + if (*code != OP_EXACT && *code != OP_EXACTI) fprintf(f, "0,"); + fprintf(f, "%d}", GET2(code,1)); + if (*code == OP_MINUPTO || *code == OP_MINUPTOI) fprintf(f, "?"); + else if (*code == OP_POSUPTO || *code == OP_POSUPTOI) fprintf(f, "+"); + break; + + case OP_TYPEEXACT: + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + case OP_TYPEPOSUPTO: + if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP) + { + print_prop(f, code + IMM2_SIZE + 1, " ", " "); + extra = 2; + } + else fprintf(f, " %s", OP_names[code[1 + IMM2_SIZE]]); + fprintf(f, "{"); + if (*code != OP_TYPEEXACT) fprintf(f, "0,"); + fprintf(f, "%d}", GET2(code,1)); + if (*code == OP_TYPEMINUPTO) fprintf(f, "?"); + else if (*code == OP_TYPEPOSUPTO) fprintf(f, "+"); + break; + + case OP_NOTI: + flag = "/i"; + PCRE2_FALLTHROUGH /* Fall through */ + case OP_NOT: + fprintf(f, " %s [^", flag); + extra = print_char(f, code + 1, utf); + fprintf(f, "] (not)"); + break; + + case OP_NOTSTARI: + case OP_NOTMINSTARI: + case OP_NOTPOSSTARI: + case OP_NOTPLUSI: + case OP_NOTMINPLUSI: + case OP_NOTPOSPLUSI: + case OP_NOTQUERYI: + case OP_NOTMINQUERYI: + case OP_NOTPOSQUERYI: + flag = "/i"; + PCRE2_FALLTHROUGH /* Fall through */ + + case OP_NOTSTAR: + case OP_NOTMINSTAR: + case OP_NOTPOSSTAR: + case OP_NOTPLUS: + case OP_NOTMINPLUS: + case OP_NOTPOSPLUS: + case OP_NOTQUERY: + case OP_NOTMINQUERY: + case OP_NOTPOSQUERY: + fprintf(f, " %s [^", flag); + extra = print_char(f, code + 1, utf); + fprintf(f, "]%s (not)", OP_names[*code]); + break; + + case OP_NOTEXACTI: + case OP_NOTUPTOI: + case OP_NOTMINUPTOI: + case OP_NOTPOSUPTOI: + flag = "/i"; + PCRE2_FALLTHROUGH /* Fall through */ + + case OP_NOTEXACT: + case OP_NOTUPTO: + case OP_NOTMINUPTO: + case OP_NOTPOSUPTO: + fprintf(f, " %s [^", flag); + extra = print_char(f, code + 1 + IMM2_SIZE, utf); + fprintf(f, "]{"); + if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,"); + fprintf(f, "%d}", GET2(code,1)); + if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?"); + else + if (*code == OP_NOTPOSUPTO || *code == OP_NOTPOSUPTOI) fprintf(f, "+"); + fprintf(f, " (not)"); + break; + + case OP_RECURSE: + if (print_lengths) fprintf(f, "%3d ", GET(code, 1)); + else fprintf(f, " "); + fprintf(f, "%s", OP_names[*code]); + break; + + case OP_REFI: + flag = "/i"; + PCRE2_FALLTHROUGH /* Fall through */ + case OP_REF: + fprintf(f, " %s \\g{%d}", flag, GET2(code, 1)); + i = (*code == OP_REFI)? code[1 + IMM2_SIZE] : 0; + if (i != 0) fprintf(f, " 0x%02x", i); + ccode = code + OP_lengths[*code]; + goto CLASS_REF_REPEAT; + + case OP_DNREFI: + flag = "/i"; + PCRE2_FALLTHROUGH /* Fall through */ + case OP_DNREF: + { + PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE; + fprintf(f, " %s \\k<", flag); + print_custring(f, entry); + fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); + i = (*code == OP_DNREFI)? code[1 + 2*IMM2_SIZE] : 0; + if (i != 0) fprintf(f, " 0x%02x", i); + } + ccode = code + OP_lengths[*code]; + goto CLASS_REF_REPEAT; + + case OP_CALLOUT: + fprintf(f, " %s %d %d %d", OP_names[*code], code[1 + 2*LINK_SIZE], + GET(code, 1), GET(code, 1 + LINK_SIZE)); + break; + + case OP_CALLOUT_STR: + c = code[1 + 4*LINK_SIZE]; + fprintf(f, " %s %c", OP_names[*code], CHAR_OUTPUT(c)); + extra = GET(code, 1 + 2*LINK_SIZE); + print_custring_bylen(f, code + 2 + 4*LINK_SIZE, extra - 3 - 4*LINK_SIZE); + for (i = 0; PRIV(callout_start_delims)[i] != 0; i++) + if (c == PRIV(callout_start_delims)[i]) + { + c = PRIV(callout_end_delims)[i]; + break; + } + fprintf(f, "%c %d %d %d", CHAR_OUTPUT(c), GET(code, 1 + 3*LINK_SIZE), + GET(code, 1), GET(code, 1 + LINK_SIZE)); + break; + + case OP_PROP: + case OP_NOTPROP: + print_prop(f, code, " ", ""); + break; + +#ifdef SUPPORT_WIDE_CHARS + case OP_ECLASS: + extra = GET(code, 1); + fprintf(f, " eclass[\n"); + /* We print the opcodes contained inside as well. */ + ccode = code + 1 + LINK_SIZE + 1; + if ((ccode[-1] & ECL_MAP) != 0) + { + const uint8_t *map = (const uint8_t *)ccode; + /* The first 6 ASCII characters (SOH...ACK) are totally, utterly useless. + If they're set in the bitmap, then it's clearly been formed by negation.*/ + BOOL print_negated = (map[0] & 0x7e) == 0x7e; + + fprintf(f, " bitmap: [%s", print_negated? "^" : ""); + print_map(f, map, print_negated); + fprintf(f, "]\n"); + ccode += 32 / sizeof(PCRE2_UCHAR); + } + else + fprintf(f, " no bitmap\n"); + while (ccode < code + extra) + { + if (print_lengths) + fprintf(f, "%3d ", (int)(ccode - codestart)); + else + fprintf(f, " "); + + switch (*ccode) + { + case ECL_AND: + fprintf(f, " AND\n"); + ccode += 1; + break; + case ECL_OR: + fprintf(f, " OR\n"); + ccode += 1; + break; + case ECL_XOR: + fprintf(f, " XOR\n"); + ccode += 1; + break; + case ECL_NOT: + fprintf(f, " NOT\n"); + ccode += 1; + break; + + case ECL_XCLASS: + print_class(f, OP_XCLASS, ccode+1, (uint8_t*)codestart, utf, + " xclass: ", "\n"); + ccode += GET(ccode, 1); + break; + + default: + fprintf(f, " UNEXPECTED\n"); + ccode += 1; + break; + } + } + fprintf(f, " ]"); + goto CLASS_REF_REPEAT; +#endif /* SUPPORT_WIDE_CHARS */ + + case OP_CLASS: + case OP_NCLASS: +#ifdef SUPPORT_WIDE_CHARS + case OP_XCLASS: + if (*code == OP_XCLASS) + extra = GET(code, 1); +#endif + print_class(f, *code, code+1, (uint8_t*)codestart, utf, " ", ""); + ccode = code + OP_lengths[*code] + extra; + + /* Handle repeats after a class or a back reference */ + + CLASS_REF_REPEAT: + switch(*ccode) + { + unsigned int min, max; + + case OP_CRSTAR: + case OP_CRMINSTAR: + case OP_CRPLUS: + case OP_CRMINPLUS: + case OP_CRQUERY: + case OP_CRMINQUERY: + case OP_CRPOSSTAR: + case OP_CRPOSPLUS: + case OP_CRPOSQUERY: + fprintf(f, "%s", OP_names[*ccode]); + extra += OP_lengths[*ccode]; + break; + + case OP_CRRANGE: + case OP_CRMINRANGE: + case OP_CRPOSRANGE: + min = GET2(ccode,1); + max = GET2(ccode,1 + IMM2_SIZE); + if (max == 0) fprintf(f, "{%u,}", min); + else fprintf(f, "{%u,%u}", min, max); + if (*ccode == OP_CRMINRANGE) fprintf(f, "?"); + else if (*ccode == OP_CRPOSRANGE) fprintf(f, "+"); + extra += OP_lengths[*ccode]; + break; + + /* Do nothing if it's not a repeat; this code stops picky compilers + warning about the lack of a default code path. */ + + default: + break; + } + break; + + case OP_MARK: + case OP_COMMIT_ARG: + case OP_PRUNE_ARG: + case OP_SKIP_ARG: + case OP_THEN_ARG: + fprintf(f, " %s ", OP_names[*code]); + print_custring_bylen(f, code + 2, code[1]); + extra += code[1]; + break; + + case OP_CIRCM: + case OP_DOLLM: + flag = "/m"; + PCRE2_FALLTHROUGH /* Fall through */ + + /* Anything else is just an item with no data, but possibly a flag. */ + + default: + fprintf(f, " %s %s", flag, OP_names[*code]); + break; + } + + code += OP_lengths[*code] + extra; + putc('\n', f); + } +} + +/* End of pcre2_printint_inc.h */ diff --git a/libpcre/src/pcre2_script_run.c b/libpcre/src/pcre2_script_run.c index 4926fa63b..acdf41fe6 100644 --- a/libpcre/src/pcre2_script_run.c +++ b/libpcre/src/pcre2_script_run.c @@ -38,15 +38,14 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains the function for checking a script run. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "pcre2_internal.h" + /************************************************* * Check script run * *************************************************/ diff --git a/libpcre/src/pcre2_serialize.c b/libpcre/src/pcre2_serialize.c index a10e3020b..f10a3fa0d 100644 --- a/libpcre/src/pcre2_serialize.c +++ b/libpcre/src/pcre2_serialize.c @@ -38,17 +38,15 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains functions for serializing and deserializing a sequence of compiled codes. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - - #include "pcre2_internal.h" + + /* Magic number to provide a small check against being handed junk. */ #define SERIALIZED_DATA_MAGIC 0x50523253u diff --git a/libpcre/src/pcre2_string_utils.c b/libpcre/src/pcre2_string_utils.c index ebfa9434e..f1ac718f6 100644 --- a/libpcre/src/pcre2_string_utils.c +++ b/libpcre/src/pcre2_string_utils.c @@ -38,53 +38,15 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains internal functions for comparing and finding the length of strings. These are used instead of strcmp() etc because the standard functions work only on 8-bit data. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" -/************************************************* -* Emulated memmove() for systems without it * -*************************************************/ - -/* This function can make use of bcopy() if it is available. Otherwise do it by -steam, as there some non-Unix environments that lack both memmove() and -bcopy(). */ - -#if !defined(VPCOMPAT) && !defined(HAVE_MEMMOVE) -void * -PRIV(memmove)(void *d, const void *s, size_t n) -{ -#ifdef HAVE_BCOPY -bcopy(s, d, n); -return d; -#else -size_t i; -unsigned char *dest = (unsigned char *)d; -const unsigned char *src = (const unsigned char *)s; -if (dest > src) - { - dest += n; - src += n; - for (i = 0; i < n; ++i) *(--dest) = *(--src); - return (void *)dest; - } -else - { - for (i = 0; i < n; ++i) *dest++ = *src++; - return (void *)(dest - n); - } -#endif /* not HAVE_BCOPY */ -} -#endif /* not VPCOMPAT && not HAVE_MEMMOVE */ - /************************************************* * Compare two zero-terminated PCRE2 strings * diff --git a/libpcre/src/pcre2_study.c b/libpcre/src/pcre2_study.c index 85764cea5..9f7fd6bd6 100644 --- a/libpcre/src/pcre2_study.c +++ b/libpcre/src/pcre2_study.c @@ -38,16 +38,15 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains functions for scanning a compiled pattern and collecting data (e.g. minimum matching length). */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + + /* The maximum remembered capturing brackets minimum. */ #define MAX_CACHE_BACKREF 128 @@ -139,7 +138,7 @@ for (;;) PCRE2_UCHAR op; PCRE2_SPTR cs, ce; - if (branchlength >= UINT16_MAX) + if (branchlength >= (int)UINT16_MAX) { branchlength = UINT16_MAX; cc = nextbranch; @@ -176,7 +175,7 @@ for (;;) cc += 1 + LINK_SIZE; break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ONCE: case OP_SCRIPT_RUN: @@ -253,7 +252,7 @@ for (;;) case OP_ASSERT_SCS: case OP_ASSERTBACK_NA: do cc += GET(cc, 1); while (*cc == OP_ALT); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Skip over things that don't match chars */ @@ -353,7 +352,7 @@ for (;;) case OP_PROP: case OP_NOTPROP: cc += 2; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOT_DIGIT: case OP_DIGIT: @@ -434,7 +433,7 @@ for (;;) case OP_CRMINPLUS: case OP_CRPOSPLUS: branchlength++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRSTAR: case OP_CRMINSTAR: @@ -628,11 +627,11 @@ for (;;) break; } - /* Take care not to overflow: (1) min and d are ints, so check that their - product is not greater than INT_MAX. (2) branchlength is limited to - UINT16_MAX (checked at the top of the loop). */ + /* Take care not to overflow: (1) min and d are ints, so check that their + product is not greater than INT_MAX. (2) branchlength is limited to + UINT16_MAX (checked at the top of the loop). */ - if ((d > 0 && (INT_MAX/d) < min) || UINT16_MAX - branchlength < min*d) + if ((d > 0 && (INT_MAX/d) < min) || (int)UINT16_MAX - branchlength < min*d) branchlength = UINT16_MAX; else branchlength += min * d; break; @@ -753,14 +752,18 @@ for (;;) /* This should not occur: we list all opcodes explicitly so that when new ones get added they are properly considered. */ + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return -3; + /* LCOV_EXCL_STOP */ } } +/* LCOV_EXCL_START */ PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */ return -3; /* Avoid compiler warnings */ +/* LCOV_EXCL_STOP */ } @@ -1304,7 +1307,7 @@ do case OP_PROP: if (ncode[1] != PT_CLIST) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ANYNL: case OP_CHAR: case OP_CHARI: @@ -1328,7 +1331,7 @@ do tcode = ncode; continue; /* With the following significant opcode */ } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* For a group bracket or a positive assertion without an immediately following mandatory setting, recurse to set bits from within the @@ -1456,7 +1459,7 @@ do case OP_EXACT: tcode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHAR: case OP_PLUS: case OP_MINPLUS: @@ -1467,7 +1470,7 @@ do case OP_EXACTI: tcode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHARI: case OP_PLUSI: case OP_MINPLUSI: @@ -1487,10 +1490,10 @@ do SET_BIT(CHAR_SPACE); /* For the 16-bit and 32-bit libraries (which can never be EBCDIC), set - the bits for 0xA0 and for code units >= 255, independently of UTF. */ + the bits for NBSP and for code units >= 255, independently of UTF. */ #if PCRE2_CODE_UNIT_WIDTH != 8 - SET_BIT(0xA0); + SET_BIT(CHAR_NBSP); SET_BIT(0xFF); #else /* For the 8-bit library in UTF-8 mode, set the bits for the first code @@ -1506,12 +1509,9 @@ do } else #endif - /* For the 8-bit library not in UTF-8 mode, set the bit for 0xA0, unless - the code is EBCDIC. */ + /* For the 8-bit library not in UTF-8 mode, set the bit for NBSP. */ { -#ifndef EBCDIC - SET_BIT(0xA0); -#endif /* Not EBCDIC */ + SET_BIT(CHAR_NBSP); } #endif /* 8-bit support */ @@ -1606,7 +1606,8 @@ do case OP_TYPEUPTO: case OP_TYPEMINUPTO: case OP_TYPEPOSUPTO: - tcode += IMM2_SIZE; /* Fall through */ + tcode += IMM2_SIZE; + PCRE2_FALLTHROUGH /* Fall through */ case OP_TYPESTAR: case OP_TYPEMINSTAR: @@ -1626,10 +1627,10 @@ do SET_BIT(CHAR_SPACE); /* For the 16-bit and 32-bit libraries (which can never be EBCDIC), set - the bits for 0xA0 and for code units >= 255, independently of UTF. */ + the bits for NBSP and for code units >= 255, independently of UTF. */ #if PCRE2_CODE_UNIT_WIDTH != 8 - SET_BIT(0xA0); + SET_BIT(CHAR_NBSP); SET_BIT(0xFF); #else /* For the 8-bit library in UTF-8 mode, set the bits for the first code @@ -1645,12 +1646,9 @@ do } else #endif - /* For the 8-bit library not in UTF-8 mode, set the bit for 0xA0, unless - the code is EBCDIC. */ + /* For the 8-bit library not in UTF-8 mode, set the bit for NBSP. */ { -#ifndef EBCDIC - SET_BIT(0xA0); -#endif /* Not EBCDIC */ + SET_BIT(CHAR_NBSP); } #endif /* 8-bit support */ break; @@ -1779,9 +1777,11 @@ do case XCL_END: goto HANDLE_CLASSMAP; + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return SSB_UNKNOWN; /* Internal error, should not occur */ + /* LCOV_EXCL_STOP */ } } #endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 */ @@ -1790,7 +1790,7 @@ do /* It seems that the fall through comment must be outside the #ifdef if it is to avoid the gcc compiler warning. */ - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Enter here for a negative non-XCLASS. In the 8-bit library, if we are in UTF mode, any byte with a value >= 0xc4 is a potentially valid starter @@ -1805,14 +1805,15 @@ do re->start_bitmap[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */ memset(re->start_bitmap+25, 0xff, 7); /* Bits for 0xc9 - 0xff */ } + PCRE2_FALLTHROUGH /* Fall through */ #elif PCRE2_CODE_UNIT_WIDTH != 8 SET_BIT(0xFF); /* For characters >= 255 */ + PCRE2_FALLTHROUGH /* Fall through */ #endif - /* Fall through */ /* Enter here for a positive non-XCLASS. If we have fallen through from an XCLASS, classmap will already be set; just advance the code pointer. - Otherwise, set up classmap for a a non-XCLASS and advance past it. */ + Otherwise, set up classmap for a non-XCLASS and advance past it. */ case OP_CLASS: if (*tcode == OP_XCLASS) tcode += GET(tcode, 1); else @@ -1930,11 +1931,13 @@ if ((re->flags & (PCRE2_FIRSTSET|PCRE2_STARTLINE)) == 0) { int depth = 0; int rc = set_start_bits(re, code, utf, ucp, &depth); + /* LCOV_EXCL_START */ if (rc == SSB_UNKNOWN) { PCRE2_DEBUG_UNREACHABLE(); return 1; } + /* LCOV_EXCL_STOP */ /* If a list of starting code units was set up, scan the list to see if only one or two were listed. Having only one listed is rare because usually a @@ -2002,6 +2005,16 @@ if ((re->flags & (PCRE2_FIRSTSET|PCRE2_STARTLINE)) == 0) if (d != a) goto DONE; /* Not the other case of a */ b = c; /* Save second in b */ + +#ifdef EBCDIC + /* To match ASCII (which puts the uppercase one in a), swap a & b + if needed. This doesn't really matter, but neatens the tests. */ + if (TABLE_GET((unsigned int)a, re->tables + lcc_offset, a) == a) + { + b = a; + a = c; + } +#endif } else goto DONE; /* More than two characters found */ } @@ -2049,16 +2062,20 @@ if ((re->flags & (PCRE2_MATCH_EMPTY|PCRE2_HASACCEPT)) == 0 && case -1: /* \C in UTF mode or over-complex regex */ break; /* Leave minlength unchanged (will be zero) */ + /* LCOV_EXCL_START */ case -2: PCRE2_DEBUG_UNREACHABLE(); return 2; /* missing capturing bracket */ + /* LCOV_EXCL_STOP */ + /* LCOV_EXCL_START */ case -3: PCRE2_DEBUG_UNREACHABLE(); return 3; /* unrecognized opcode */ + /* LCOV_EXCL_STOP */ default: - re->minlength = (min > UINT16_MAX)? UINT16_MAX : min; + re->minlength = (min > (int)UINT16_MAX)? (int)UINT16_MAX : min; break; } } diff --git a/libpcre/src/pcre2_substitute.c b/libpcre/src/pcre2_substitute.c index 17040ce5f..5cb84748e 100644 --- a/libpcre/src/pcre2_substitute.c +++ b/libpcre/src/pcre2_substitute.c @@ -39,12 +39,10 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" + + #define PTR_STACK_SIZE 20 #define SUBSTITUTE_OPTIONS \ @@ -131,7 +129,6 @@ for (; ptr < ptrend; ptr++) ptr += 1; /* Must point after \ */ erc = PRIV(check_escape)(&ptr, ptrend, &ch, &errorcode, code->overall_options, code->extra_options, code->top_bracket, FALSE, NULL); - ptr -= 1; /* Back to last code unit of escape */ if (errorcode != 0) { /* errorcode from check_escape is positive, so must not be returned by @@ -327,9 +324,11 @@ if (input_len == 0) return 0; switch (state->to_case) { + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return 0; + /* LCOV_EXCL_STOP */ case PCRE2_SUBSTITUTE_CASE_LOWER: // Can be single_char TRUE or FALSE case PCRE2_SUBSTITUTE_CASE_UPPER: // Can only be single_char FALSE @@ -465,9 +464,11 @@ PCRE2_ASSERT(input_len != 0); switch (state->to_case) { + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return 0; + /* LCOV_EXCL_STOP */ case PCRE2_SUBSTITUTE_CASE_LOWER: // Can be single_char TRUE or FALSE case PCRE2_SUBSTITUTE_CASE_UPPER: // Can only be single_char FALSE @@ -751,12 +752,14 @@ BOOL use_existing_match; BOOL replacement_only; BOOL utf = (code->overall_options & PCRE2_UTF) != 0; PCRE2_UCHAR temp[6]; +PCRE2_UCHAR null_str[1] = { 0xcd }; +PCRE2_SPTR original_subject = subject; PCRE2_SPTR ptr; PCRE2_SPTR repend = NULL; PCRE2_SIZE extra_needed = 0; PCRE2_SIZE buff_offset, buff_length, lengthleft, fraglength; PCRE2_SIZE *ovector; -PCRE2_SIZE ovecsave[3]; +PCRE2_SIZE ovecsave[2] = { 0, 0 }; pcre2_substitute_callout_block scb; PCRE2_SIZE sub_start_extra_needed; PCRE2_SIZE (*substitute_case_callout)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, @@ -768,7 +771,6 @@ void *substitute_case_callout_data = NULL; buff_offset = 0; lengthleft = buff_length = *blength; *blength = PCRE2_UNSET; -ovecsave[0] = ovecsave[1] = ovecsave[2] = PCRE2_UNSET; if (mcontext != NULL) { @@ -788,18 +790,74 @@ zero length is interpreted as an empty string. */ if (replacement == NULL) { if (rlength != 0) return PCRE2_ERROR_NULL; - replacement = (PCRE2_SPTR)""; + replacement = null_str; } if (rlength == PCRE2_ZERO_TERMINATED) rlength = PRIV(strlen)(replacement); repend = replacement + rlength; +/* A NULL subject of zero length is treated as an empty string. */ + +if (subject == NULL) + { + if (length != 0) return PCRE2_ERROR_NULL; + subject = null_str; + } + +if (length == PCRE2_ZERO_TERMINATED) length = PRIV(strlen)(subject); + /* Check for using a match that has already happened. Note that the subject pointer in the match data may be NULL after a no-match. */ use_existing_match = ((options & PCRE2_SUBSTITUTE_MATCHED) != 0); replacement_only = ((options & PCRE2_SUBSTITUTE_REPLACEMENT_ONLY) != 0); +if (use_existing_match && match_data == NULL) return PCRE2_ERROR_NULL; + +/* If an existing match is being passed in, we should check that it matches +the passed-in subject pointer, length, and match options. We don't currently +have a use-case for someone to match on one subject, then try and use that +match data on a different subject. In a UTF-encoded string, a simple change +like replacing one character for another won't preserve the code unit offsets, +so it's hard to see, in the general case, how it would be safe or useful to +support swapping or mutating the subject string. + +Similarly, using different match options between the first (external) and +subsequent (internal, global) matches is hard to justify. */ + +if (use_existing_match) + { + /* Return early, as the rest of the match_data may not have been + initialised. This duplicates and must be in sync with the check below that + aborts substitution on any result other than success or no-match. */ + if (match_data->rc < 0 && match_data->rc != PCRE2_ERROR_NOMATCH) + return match_data->rc; + + /* Not supported if the passed-in match was from the DFA interpreter. */ + if (match_data->matchedby == PCRE2_MATCHEDBY_DFA_INTERPRETER) + return PCRE2_ERROR_DFA_UFUNC; + + if (code != match_data->code) + return PCRE2_ERROR_DIFFSUBSPATTERN; + + /* We want the passed-in subject strings to match. This implies the effective + length must match, and either: the pointers are equal (with strict matching + of NULL against NULL); or, the special case of PCRE2_COPY_MATCHED_SUBJECT + where we cannot compare pointers but we can verify the contents. */ + if (length != match_data->subject_length || + !(original_subject == match_data->subject || + ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0 && + (length == 0 || + memcmp(subject, match_data->subject, CU2BYTES(length)) == 0)))) + return PCRE2_ERROR_DIFFSUBSSUBJECT; + + if (start_offset != match_data->start_offset) + return PCRE2_ERROR_DIFFSUBSOFFSET; + + if ((options & ~SUBSTITUTE_OPTIONS) != match_data->options) + return PCRE2_ERROR_DIFFSUBSOPTIONS; + } + /* If starting from an existing match, there must be an externally provided match data block. We create an internal match_data block in two cases: (a) an external one is not supplied (and we are not starting from an existing match); @@ -816,9 +874,8 @@ have to be changes below. */ if (match_data == NULL) { pcre2_general_context gcontext; - if (use_existing_match) return PCRE2_ERROR_NULL; gcontext.memctl = (mcontext == NULL)? - ((const pcre2_real_code *)code)->memctl : + ((pcre2_real_code *)code)->memctl : ((pcre2_real_match_context *)mcontext)->memctl; match_data = internal_match_data = pcre2_match_data_create_from_pattern(code, &gcontext); @@ -830,7 +887,7 @@ else if (use_existing_match) int pairs; pcre2_general_context gcontext; gcontext.memctl = (mcontext == NULL)? - ((const pcre2_real_code *)code)->memctl : + ((pcre2_real_code *)code)->memctl : ((pcre2_real_match_context *)mcontext)->memctl; pairs = (code->top_bracket + 1 < match_data->oveccount)? code->top_bracket + 1 : match_data->oveccount; @@ -841,9 +898,15 @@ else if (use_existing_match) + 2*pairs*sizeof(PCRE2_SIZE)); internal_match_data->heapframes = NULL; internal_match_data->heapframes_size = 0; + /* Ensure that the subject is not freed when internal_match_data is */ + internal_match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT; match_data = internal_match_data; } +/* If using an internal match data, there's no need to copy the subject. */ + +if (internal_match_data != NULL) options &= ~PCRE2_COPY_MATCHED_SUBJECT; + /* Remember ovector details */ ovector = pcre2_get_ovector_pointer(match_data); @@ -856,19 +919,6 @@ scb.input = subject; scb.output = (PCRE2_SPTR)buffer; scb.ovector = ovector; -/* A NULL subject of zero length is treated as an empty string. */ - -if (subject == NULL) - { - if (length != 0) return PCRE2_ERROR_NULL; - subject = (PCRE2_SPTR)""; - } - -/* Find length of zero-terminated subject */ - -if (length == PCRE2_ZERO_TERMINATED) - length = subject? PRIV(strlen)(subject) : 0; - /* Check UTF replacement string if necessary. */ #ifdef SUPPORT_UNICODE @@ -905,7 +955,7 @@ if (!replacement_only) CHECKMEMCPY(subject, start_offset); match is taken from the match_data that was passed in. */ subs = 0; -do +for (;;) { PCRE2_SPTR ptrstack[PTR_STACK_SIZE]; uint32_t ptrstackptr = 0; @@ -925,54 +975,12 @@ do if (utf) options |= PCRE2_NO_UTF_CHECK; /* Only need to check once */ #endif - /* Any error other than no match returns the error code. No match when not - doing the special after-empty-match global rematch, or when at the end of the - subject, breaks the global loop. Otherwise, advance the starting point by one - character, copying it to the output, and try again. */ + /* Any error other than no match returns the error code. No match breaks the + global loop. */ - if (rc < 0) - { - PCRE2_SIZE save_start; + if (rc == PCRE2_ERROR_NOMATCH) break; - if (rc != PCRE2_ERROR_NOMATCH) goto EXIT; - if (goptions == 0 || start_offset >= length) break; - - /* Advance by one code point. Then, if CRLF is a valid newline sequence and - we have advanced into the middle of it, advance one more code point. In - other words, do not start in the middle of CRLF, even if CR and LF on their - own are valid newlines. */ - - save_start = start_offset++; - if (subject[start_offset-1] == CHAR_CR && - (code->newline_convention == PCRE2_NEWLINE_CRLF || - code->newline_convention == PCRE2_NEWLINE_ANY || - code->newline_convention == PCRE2_NEWLINE_ANYCRLF) && - start_offset < length && - subject[start_offset] == CHAR_LF) - start_offset++; - - /* Otherwise, in UTF mode, advance past any secondary code points. */ - - else if ((code->overall_options & PCRE2_UTF) != 0) - { -#if PCRE2_CODE_UNIT_WIDTH == 8 - while (start_offset < length && (subject[start_offset] & 0xc0) == 0x80) - start_offset++; -#elif PCRE2_CODE_UNIT_WIDTH == 16 - while (start_offset < length && - (subject[start_offset] & 0xfc00) == 0xdc00) - start_offset++; -#endif - } - - /* Copy what we have advanced past (unless not required), reset the special - global options, and continue to the next match. */ - - fraglength = start_offset - save_start; - if (!replacement_only) CHECKMEMCPY(subject + save_start, fraglength); - goptions = 0; - continue; - } + if (rc < 0) goto EXIT; /* Handle a successful match. Matches that use \K to end before they start or start before the current point in the subject are not supported. */ @@ -983,25 +991,27 @@ do goto EXIT; } - /* Check for the same match as previous. This is legitimate after matching an - empty string that starts after the initial match offset. We have tried again - at the match point in case the pattern is one like /(?<=\G.)/ which can never - match at its starting point, so running the match achieves the bumpalong. If - we do get the same (null) match at the original match point, it isn't such a - pattern, so we now do the empty string magic. In all other cases, a repeat - match should never occur. */ + /* Assert that our replacement loop is making progress, checked even in + release builds. This should be impossible to hit, however, an infinite loop + would be fairly catastrophic. - if (ovecsave[0] == ovector[0] && ovecsave[1] == ovector[1]) + "Progress" is measured as ovector[1] strictly advancing, or, an empty match + after a non-empty match. */ + + /* LCOV_EXCL_START */ + if (subs > 0 && + !(ovector[1] > ovecsave[1] || + (ovector[1] == ovector[0] && ovecsave[1] > ovecsave[0] && + ovector[1] == ovecsave[1]))) { - if (ovector[0] == ovector[1] && ovecsave[2] != start_offset) - { - goptions = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED; - ovecsave[2] = start_offset; - continue; /* Back to the top of the loop */ - } + PCRE2_DEBUG_UNREACHABLE(); rc = PCRE2_ERROR_INTERNAL_DUPMATCH; goto EXIT; } + /* LCOV_EXCL_STOP */ + + ovecsave[0] = ovector[0]; + ovecsave[1] = ovector[1]; /* Count substitutions with a paranoid check for integer overflow; surely no real call to this function would ever hit this! */ @@ -1133,6 +1143,44 @@ do subptrend = subject + length; goto SUBPTR_SUBSTITUTE; } + else if (next == CHAR_PLUS && + !(ptr+1 < repend && ptr[1] == CHAR_LEFT_CURLY_BRACKET)) + { + /* Perl supports $+ for "highest captured group" (not the same as $^N + which is mainly only useful inside Perl's match callbacks). We also + don't accept "$+{..." since that's Perl syntax for our ${name}. */ + ++ptr; + if (code->top_bracket == 0) + { + /* Treat either as "no such group" or "all groups unset" based on the + PCRE2_SUBSTITUTE_UNKNOWN_UNSET option. */ + if ((suboptions & PCRE2_SUBSTITUTE_UNKNOWN_UNSET) == 0) + { + rc = PCRE2_ERROR_NOSUBSTRING; + goto PTREXIT; + } + group = 0; + } + else + { + /* If we have any capture groups, then the ovector needs to be large + enough for all of them, or the result won't be accurate. */ + if (match_data->oveccount < code->top_bracket + 1) + { + rc = PCRE2_ERROR_UNAVAILABLE; + goto PTREXIT; + } + for (group = code->top_bracket; group > 0; group--) + if (ovector[2*group] != PCRE2_UNSET) break; + } + if (group == 0) + { + if ((suboptions & PCRE2_SUBSTITUTE_UNSET_EMPTY) != 0) continue; + rc = PCRE2_ERROR_UNSET; + goto PTREXIT; + } + goto GROUP_SUBSTITUTE; + } if (next == CHAR_LEFT_CURLY_BRACKET) { @@ -1627,19 +1675,25 @@ do } } - /* Save the details of this match. See above for how this data is used. If we - matched an empty string, do the magic for global matches. Update the start - offset to point to the rest of the subject string. If we re-used an existing - match for the first match, switch to the internal match data block. */ + /* Exit the global loop if we are not in global mode, or if pcre2_next_match() + indicates we have reached the end of the subject. */ - ovecsave[0] = ovector[0]; - ovecsave[1] = ovector[1]; - ovecsave[2] = start_offset; + if ((suboptions & PCRE2_SUBSTITUTE_GLOBAL) == 0 || + !pcre2_next_match(match_data, &start_offset, &goptions)) + { + start_offset = ovector[1]; + break; + } - goptions = (ovector[0] != ovector[1] || ovector[0] > start_offset)? 0 : - PCRE2_ANCHORED|PCRE2_NOTEMPTY_ATSTART; - start_offset = ovector[1]; - } while ((suboptions & PCRE2_SUBSTITUTE_GLOBAL) != 0); /* Repeat "do" loop */ + /* Verify that pcre2_next_match() has not done a bumpalong (because we have + already returned PCRE2_ERROR_BADSUBSPATTERN for \K in lookarounds). + + We would otherwise have to memcpy the fragment spanning from ovector[1] to the + new start_offset.*/ + + PCRE2_ASSERT(start_offset == ovector[1]); + + } /* End of global loop */ /* Copy the rest of the subject unless not required, and terminate the output with a binary zero. */ diff --git a/libpcre/src/pcre2_substring.c b/libpcre/src/pcre2_substring.c index 88afd2348..f68b464e0 100644 --- a/libpcre/src/pcre2_substring.c +++ b/libpcre/src/pcre2_substring.c @@ -39,10 +39,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include "pcre2_internal.h" @@ -126,7 +122,7 @@ PCRE2_SIZE size; rc = pcre2_substring_length_bynumber(match_data, stringnumber, &size); if (rc < 0) return rc; if (size + 1 > *sizeptr) return PCRE2_ERROR_NOMEMORY; -memcpy(buffer, match_data->subject + match_data->ovector[stringnumber*2], +if (size != 0) memcpy(buffer, match_data->subject + match_data->ovector[stringnumber*2], CU2BYTES(size)); buffer[size] = 0; *sizeptr = size; @@ -218,7 +214,7 @@ yield = PRIV(memctl_malloc)(sizeof(pcre2_memctl) + (size + 1)*PCRE2_CODE_UNIT_WIDTH, (pcre2_memctl *)match_data); if (yield == NULL) return PCRE2_ERROR_NOMEMORY; yield = (PCRE2_UCHAR *)(((char *)yield) + sizeof(pcre2_memctl)); -memcpy(yield, match_data->subject + match_data->ovector[stringnumber*2], +if (size != 0) memcpy(yield, match_data->subject + match_data->ovector[stringnumber*2], CU2BYTES(size)); yield[size] = 0; *stringptr = yield; @@ -259,7 +255,7 @@ permits duplicate names, the first substring that is set is chosen. Arguments: match_data pointer to match data stringname the name of the required substring - sizeptr where to put the length + sizeptr where to put the length, if not NULL Returns: 0 if successful, else a negative error number */ @@ -342,8 +338,15 @@ else /* Matched using pcre2_dfa_match() */ left = match_data->ovector[stringnumber*2]; right = match_data->ovector[stringnumber*2+1]; +/* LCOV_EXCL_START - this appears to be unreachable, as the ovector and +subject_length should always be set consistently, no matter what misbehaviour +the caller has committed. */ if (left > match_data->subject_length || right > match_data->subject_length) + { + PCRE2_DEBUG_UNREACHABLE(); return PCRE2_ERROR_INVALIDOFFSET; + } +/* LCOV_EXCL_STOP */ if (sizeptr != NULL) *sizeptr = (left > right)? 0 : right - left; return 0; } diff --git a/libpcre/src/pcre2_tables.c b/libpcre/src/pcre2_tables.c index 097a1acca..0b9b43bf2 100644 --- a/libpcre/src/pcre2_tables.c +++ b/libpcre/src/pcre2_tables.c @@ -38,27 +38,33 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains some fixed tables that are used by more than one of the PCRE2 code modules. The tables are also #included by the pcre2test program, which uses macros to change their names from _pcre2_xxx to xxxx, thereby avoiding name clashes with the library. In this case, PCRE2_PCRE2TEST is defined. */ -#ifndef PCRE2_PCRE2TEST /* We're compiling the library */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif + +#if !defined(PCRE2_PCRE2TEST) && !defined(PCRE2_DFTABLES) && \ + !defined(PCRE2_PCRE2POSIX) /* We're compiling the library */ #include "pcre2_internal.h" -#endif /* PCRE2_PCRE2TEST */ +#endif + + +/* Utility macros */ +#define ARR_SIZE(x) sizeof(x)/sizeof(x[0]) + + +#if !defined(PCRE2_PCRE2TEST) && !defined(PCRE2_DFTABLES) && \ + !defined(PCRE2_PCRE2POSIX) /* Table of sizes for the fixed-length opcodes. It's defined in a macro so that the definition is next to the definition of the opcodes in pcre2_internal.h. This is mode-dependent, so it is skipped when this file is included by pcre2test. */ -#ifndef PCRE2_PCRE2TEST const uint8_t PRIV(OP_lengths)[] = { OP_LENGTHS }; -#endif /* Tables of horizontal and vertical whitespace characters, suitable for adding to classes. */ @@ -66,6 +72,11 @@ adding to classes. */ const uint32_t PRIV(hspace_list)[] = { HSPACE_LIST }; const uint32_t PRIV(vspace_list)[] = { VSPACE_LIST }; +#endif /* !PCRE2_PCRE2TEST && !PCRE2_DFTABLES && !PCRE2_PCRE2POSIX */ + + +#if !defined(PCRE2_DFTABLES) && !defined(PCRE2_PCRE2POSIX) + /* These tables are the pairs of delimiters that are valid for callout string arguments. For each starting delimiter there must be a matching ending delimiter, which in fact is different only for bracket-like delimiters. */ @@ -80,6 +91,8 @@ const uint32_t PRIV(callout_end_delims[]) = { CHAR_CIRCUMFLEX_ACCENT, CHAR_PERCENT_SIGN, CHAR_NUMBER_SIGN, CHAR_DOLLAR_SIGN, CHAR_RIGHT_CURLY_BRACKET, 0 }; +#endif /* !PCRE2_DFTABLES && !PCRE2_PCRE2POSIX */ + /************************************************* * Tables for UTF-8 support * @@ -90,23 +103,24 @@ as for the library in 8-bit mode, because pcre2test uses UTF-8 internally for handling wide characters. */ #if defined PCRE2_PCRE2TEST || \ - (defined SUPPORT_UNICODE && \ - defined PCRE2_CODE_UNIT_WIDTH && \ - PCRE2_CODE_UNIT_WIDTH == 8) + (!defined(PCRE2_DFTABLES) && !defined(PCRE2_PCRE2POSIX) && \ + defined SUPPORT_UNICODE && \ + defined PCRE2_CODE_UNIT_WIDTH && \ + PCRE2_CODE_UNIT_WIDTH == 8) /* These are the breakpoints for different numbers of bytes in a UTF-8 character. */ const int PRIV(utf8_table1)[] = - { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff}; + { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff }; -const int PRIV(utf8_table1_size) = sizeof(PRIV(utf8_table1)) / sizeof(int); +const unsigned PRIV(utf8_table1_size) = ARR_SIZE(PRIV(utf8_table1)); /* These are the indicator bits and the mask for the data bits to set in the first byte of a character, indexed by the number of additional bytes. */ -const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc}; -const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01}; +const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc }; +const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01 }; /* Table of the number of extra bytes, indexed by the first byte masked with 0x3f. The highest number for a valid UTF-8 first byte is in fact 0x3d. */ @@ -120,10 +134,11 @@ const uint8_t PRIV(utf8_table4)[] = { #endif /* UTF-8 support needed */ /* Tables concerned with Unicode properties are relevant only when Unicode -support is enabled. See also the pcre2_ucptables.c file, which is generated by +support is enabled. See also the pcre2_ucptables_inc.h file, which is generated by a Python script from Unicode data files. */ -#ifdef SUPPORT_UNICODE +#if !defined(PCRE2_DFTABLES) && !defined(PCRE2_PCRE2POSIX) && \ + defined(SUPPORT_UNICODE) /* Table to translate from particular type value to the general value. */ @@ -227,8 +242,69 @@ const int PRIV(ucp_typerange)[] = { /* Finally, include the tables that are auto-generated from the Unicode data files. */ -#include "pcre2_ucptables.c" +#include "pcre2_ucptables_inc.h" -#endif /* SUPPORT_UNICODE */ +#endif /* Unicode support needed */ + + +/************************************************* +* Tables for EBCDIC support * +*************************************************/ + +#if defined(EBCDIC) && \ + (defined(PCRE2_PCRE2TEST) || defined(PCRE2_DFTABLES) || 'a' != 0x81) + +const uint8_t PRIV(ebcdic_1047_to_ascii)[256] = { + 0x00,0x01,0x02,0x03,0x9c,0x09,0x86,0x7f,0x97,0x8d,0x8e,0x0b,0x0c,0x0d,0x0e,0x0f, +#ifdef EBCDIC_NL25 + 0x10,0x11,0x12,0x13,0x9d,0x85,0x08,0x87,0x18,0x19,0x92,0x8f,0x1c,0x1d,0x1e,0x1f, + 0x80,0x81,0x82,0x83,0x84,0x0a,0x17,0x1b,0x88,0x89,0x8a,0x8b,0x8c,0x05,0x06,0x07, +#else + 0x10,0x11,0x12,0x13,0x9d,0x0a,0x08,0x87,0x18,0x19,0x92,0x8f,0x1c,0x1d,0x1e,0x1f, + 0x80,0x81,0x82,0x83,0x84,0x85,0x17,0x1b,0x88,0x89,0x8a,0x8b,0x8c,0x05,0x06,0x07, +#endif + 0x90,0x91,0x16,0x93,0x94,0x95,0x96,0x04,0x98,0x99,0x9a,0x9b,0x14,0x15,0x9e,0x1a, + 0x20,0xa0,0xe2,0xe4,0xe0,0xe1,0xe3,0xe5,0xe7,0xf1,0xa2,0x2e,0x3c,0x28,0x2b,0x7c, + 0x26,0xe9,0xea,0xeb,0xe8,0xed,0xee,0xef,0xec,0xdf,0x21,0x24,0x2a,0x29,0x3b,0x5e, + 0x2d,0x2f,0xc2,0xc4,0xc0,0xc1,0xc3,0xc5,0xc7,0xd1,0xa6,0x2c,0x25,0x5f,0x3e,0x3f, + 0xf8,0xc9,0xca,0xcb,0xc8,0xcd,0xce,0xcf,0xcc,0x60,0x3a,0x23,0x40,0x27,0x3d,0x22, + 0xd8,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0xab,0xbb,0xf0,0xfd,0xfe,0xb1, + 0xb0,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0xaa,0xba,0xe6,0xb8,0xc6,0xa4, + 0xb5,0x7e,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0xa1,0xbf,0xd0,0x5b,0xde,0xae, + 0xac,0xa3,0xa5,0xb7,0xa9,0xa7,0xb6,0xbc,0xbd,0xbe,0xdd,0xa8,0xaf,0x5d,0xb4,0xd7, + 0x7b,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0xad,0xf4,0xf6,0xf2,0xf3,0xf5, + 0x7d,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xb9,0xfb,0xfc,0xf9,0xfa,0xff, + 0x5c,0xf7,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0xb2,0xd4,0xd6,0xd2,0xd3,0xd5, + 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0xb3,0xdb,0xdc,0xd9,0xda,0x9f, +}; + +const uint8_t PRIV(ascii_to_ebcdic_1047)[256] = { +#ifdef EBCDIC_NL25 + 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f,0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, +#else + 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f,0x16,0x05,0x15,0x0b,0x0c,0x0d,0x0e,0x0f, +#endif + 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26,0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, + 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d,0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, + 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, + 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, + 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xad,0xe0,0xbd,0x5f,0x6d, + 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, + 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, +#ifdef EBCDIC_NL25 + 0x20,0x21,0x22,0x23,0x24,0x15,0x06,0x17,0x28,0x29,0x2a,0x2b,0x2c,0x09,0x0a,0x1b, +#else + 0x20,0x21,0x22,0x23,0x24,0x25,0x06,0x17,0x28,0x29,0x2a,0x2b,0x2c,0x09,0x0a,0x1b, +#endif + 0x30,0x31,0x1a,0x33,0x34,0x35,0x36,0x08,0x38,0x39,0x3a,0x3b,0x04,0x14,0x3e,0xff, + 0x41,0xaa,0x4a,0xb1,0x9f,0xb2,0x6a,0xb5,0xbb,0xb4,0x9a,0x8a,0xb0,0xca,0xaf,0xbc, + 0x90,0x8f,0xea,0xfa,0xbe,0xa0,0xb6,0xb3,0x9d,0xda,0x9b,0x8b,0xb7,0xb8,0xb9,0xab, + 0x64,0x65,0x62,0x66,0x63,0x67,0x9e,0x68,0x74,0x71,0x72,0x73,0x78,0x75,0x76,0x77, + 0xac,0x69,0xed,0xee,0xeb,0xef,0xec,0xbf,0x80,0xfd,0xfe,0xfb,0xfc,0xba,0xae,0x59, + 0x44,0x45,0x42,0x46,0x43,0x47,0x9c,0x48,0x54,0x51,0x52,0x53,0x58,0x55,0x56,0x57, + 0x8c,0x49,0xcd,0xce,0xcb,0xcf,0xcc,0xe1,0x70,0xdd,0xde,0xdb,0xdc,0x8d,0x8e,0xdf, +}; + +#endif /* EBCDIC support needed */ /* End of pcre2_tables.c */ diff --git a/libpcre/src/pcre2_ucd.c b/libpcre/src/pcre2_ucd.c index 4c5e5163b..1cbff3afe 100644 --- a/libpcre/src/pcre2_ucd.c +++ b/libpcre/src/pcre2_ucd.c @@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This file contains tables of Unicode properties that are extracted from Unicode data files. See the comments at the start of maint/GenerateUcd.py for details. @@ -52,13 +53,13 @@ _pcre2_xxx to xxxx, thereby avoiding name clashes with the library. At present, just one of these tables is actually needed. When compiling the library, some headers are needed. */ + #ifndef PCRE2_PCRE2TEST -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "pcre2_internal.h" #endif /* PCRE2_PCRE2TEST */ + + /* The tables herein are needed only when UCP support is built, and in PCRE2 that happens automatically with UTF support. This module should not be referenced otherwise, so it should not matter whether it is compiled or not. diff --git a/libpcre/src/pcre2_ucptables.c b/libpcre/src/pcre2_ucptables_inc.h similarity index 99% rename from libpcre/src/pcre2_ucptables.c rename to libpcre/src/pcre2_ucptables_inc.h index d2b34037b..6f1731d32 100644 --- a/libpcre/src/pcre2_ucptables.c +++ b/libpcre/src/pcre2_ucptables_inc.h @@ -1593,4 +1593,4 @@ const size_t PRIV(utt_size) = sizeof(PRIV(utt)) / sizeof(ucp_type_table); #endif /* SUPPORT_UNICODE */ -/* End of pcre2_ucptables.c */ +/* End of pcre2_ucptables_inc.h */ diff --git a/libpcre/src/pcre2_util.h b/libpcre/src/pcre2_util.h index ea8635552..7bfbee099 100644 --- a/libpcre/src/pcre2_util.h +++ b/libpcre/src/pcre2_util.h @@ -71,6 +71,8 @@ side-effects. */ } while(0) #endif +/* LCOV_EXCL_START */ + /* PCRE2_UNREACHABLE() can be used to mark locations on the code that shouldn't be reached. In non debug builds is defined as a hint for the compiler to eliminate any code after it, so it is useful also for @@ -107,8 +109,16 @@ the reason and the actions that should be taken if it ever triggers. */ #define PCRE2_DEBUG_UNREACHABLE() PCRE2_UNREACHABLE() +/* LCOV_EXCL_STOP */ + #endif /* PCRE2_DEBUG */ +#ifndef PCRE2_ASSERT +#define PCRE2_ASSERT(x) do {} while(0) +#endif + +/* LCOV_EXCL_START */ + #ifndef PCRE2_DEBUG_UNREACHABLE #define PCRE2_DEBUG_UNREACHABLE() do {} while(0) #endif @@ -123,8 +133,45 @@ the reason and the actions that should be taken if it ever triggers. */ #endif #endif /* !PCRE2_UNREACHABLE */ -#ifndef PCRE2_ASSERT -#define PCRE2_ASSERT(x) do {} while(0) +/* LCOV_EXCL_STOP */ + +/* We define this fallthrough macro for suppressing -Wimplicit-fallthrough warnings. +Clang only allows this via an attribute, whereas other compilers (eg. GCC) match attributes +and also specially-formatted comments. + +This macro should be used with no following semicolon, and ideally with a comment: */ + +// PCRE2_FALLTHROUGH /* Fall through */ + +#ifndef PCRE2_FALLTHROUGH + +#if defined(__cplusplus) && __cplusplus >= 202002L && \ + defined(__has_cpp_attribute) +/* Standards-compatible C++ variant. */ +#if __has_cpp_attribute(fallthrough) +#define PCRE2_FALLTHROUGH [[fallthrough]]; +#endif +#elif !defined(__cplusplus) && \ + defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L && \ + defined(__has_c_attribute) +/* Standards-compatible C variant. */ +#if __has_c_attribute(fallthrough) +#define PCRE2_FALLTHROUGH [[fallthrough]]; +#endif +#elif ((defined(__clang__) && __clang_major__ >= 10) || \ + (defined(__GNUC__) && __GNUC__ >= 7)) && \ + defined(__has_attribute) +/* Clang and GCC syntax. Rule out old versions because apparently Clang at + least has a broken implementation of __has_attribute. */ +#if __has_attribute(fallthrough) +#define PCRE2_FALLTHROUGH __attribute__((fallthrough)); +#endif +#endif + +#endif /* !PCRE2_FALLTHROUGH */ + +#ifndef PCRE2_FALLTHROUGH +#define PCRE2_FALLTHROUGH #endif #endif /* PCRE2_UTIL_H_IDEMPOTENT_GUARD */ diff --git a/libpcre/src/pcre2_valid_utf.c b/libpcre/src/pcre2_valid_utf.c index de411b919..3fac931ea 100644 --- a/libpcre/src/pcre2_valid_utf.c +++ b/libpcre/src/pcre2_valid_utf.c @@ -44,14 +44,13 @@ strings. This file is also #included by the pcre2test program, which uses macros to change names from _pcre2_xxx to xxxx, thereby avoiding name clashes with the library. In this case, PCRE2_PCRE2TEST is defined. */ + #ifndef PCRE2_PCRE2TEST /* We're compiling the library */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "pcre2_internal.h" #endif /* PCRE2_PCRE2TEST */ + #ifndef SUPPORT_UNICODE /************************************************* * Dummy function when Unicode is not supported * diff --git a/libpcre/src/pcre2_xclass.c b/libpcre/src/pcre2_xclass.c index 25de7cbf3..7bcae34e0 100644 --- a/libpcre/src/pcre2_xclass.c +++ b/libpcre/src/pcre2_xclass.c @@ -38,18 +38,16 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ + /* This module contains two internal functions that are used to match OP_XCLASS and OP_ECLASS. It is used by pcre2_auto_possessify() and by both pcre2_match() and pcre2_dfa_match(). */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - - #include "pcre2_internal.h" + + /************************************************* * Match character against an XCLASS * *************************************************/ @@ -252,9 +250,11 @@ if (*data == XCL_PROP || *data == XCL_NOTPROP) /* This should never occur, but compilers may mutter if there is no default. */ + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return FALSE; + /* LCOV_EXCL_STOP */ } data += 2; @@ -529,9 +529,11 @@ while (ptr < data_end) /* This should never occur, but compilers may mutter if there is no default. */ + /* LCOV_EXCL_START */ default: PCRE2_DEBUG_UNREACHABLE(); return FALSE; + /* LCOV_EXCL_STOP */ } } diff --git a/libpcre/src/pcre2posix.c b/libpcre/src/pcre2posix.c index f9dcbceba..89b959419 100644 --- a/libpcre/src/pcre2posix.c +++ b/libpcre/src/pcre2posix.c @@ -41,18 +41,21 @@ POSSIBILITY OF SUCH DAMAGE. /* This module is a wrapper that provides a POSIX API to the underlying PCRE2 functions. The functions are called pcre2_regcomp(), pcre2_regexec(), etc. -pcre2posix.h defines the POSIX names as macros for the corresonding pcre2_xxx +pcre2posix.h defines the POSIX names as macros for the corresponding pcre2_xxx functions, so any program that includes it and uses the POSIX names will call the PCRE2 implementations instead. */ -#ifdef HAVE_CONFIG_H +/* This module doesn't use pcre2_internal.h, because the pcre2posix dynamic +library has an "internal" view of some macros, but is an "external" client of +the pcre2-8 dynamic library. This is unusual, and justifies a (rare) direct +inclusion of config.h. */ + +#if defined HAVE_CONFIG_H && !defined PCRE2_CONFIG_H_IDEMPOTENT_GUARD +#define PCRE2_CONFIG_H_IDEMPOTENT_GUARD #include "config.h" #endif -#ifdef PCRE2POSIX_SHARED -#undef PCRE2_STATIC -#endif /* Ensure that the PCRE2POSIX_EXP_xxx macros are set appropriately for @@ -60,9 +63,24 @@ compiling these functions. This must come before including pcre2posix.h, where they are set for an application (using these functions) if they have not previously been set. */ -#if defined(_WIN32) && (defined(PCRE2POSIX_SHARED) || !defined(PCRE2_STATIC)) -# define PCRE2POSIX_EXP_DECL extern __declspec(dllexport) -# define PCRE2POSIX_EXP_DEFN __declspec(dllexport) +#if defined __cplusplus +#error This project uses C99. C++ is not supported. +#endif + +#ifndef PCRE2POSIX_EXP_DECL +# if defined(_WIN32) && defined(PCRE2POSIX_SHARED) +# define PCRE2POSIX_EXP_DECL extern __declspec(dllexport) +# else +# define PCRE2POSIX_EXP_DECL extern PCRE2_EXPORT +# endif +#endif + +#ifndef PCRE2POSIX_EXP_DEFN +# if defined(_WIN32) && defined(PCRE2POSIX_SHARED) +# define PCRE2POSIX_EXP_DEFN extern __declspec(dllexport) +# else +# define PCRE2POSIX_EXP_DEFN extern PCRE2_EXPORT +# endif #endif /* Older versions of MSVC lack snprintf(). This define allows for @@ -71,7 +89,6 @@ MSVC 10/2010. Except for VC6 (which is missing some fundamentals and fails). */ #if defined(_MSC_VER) && (_MSC_VER < 1900) #define snprintf _snprintf -#define BROKEN_SNPRINTF #endif @@ -96,6 +113,13 @@ changed. This #define is a copy of the one in pcre2_internal.h. */ #include "pcre2posix.h" #include "pcre2_util.h" +/* For pcre2_tables.c */ +#define PCRE2_PCRE2POSIX +/* For pcre2_tables.c */ +#define PRIV(name) name + +#include "pcre2_tables.c" + /* Table to translate PCRE2 compile time error codes into POSIX error codes. Only a few PCRE2 errors with a value greater than 23 turn into special POSIX codes: most go to REG_BADPAT. The second table lists, in pairs, those that @@ -167,14 +191,6 @@ static const char *const pstring[] = { "match failed" /* NOMATCH */ }; -static int message_len(const char *message, int offset) -{ -char buf[12]; - -/* 11 magic number comes from the format below */ -return (int)strlen(message) + 11 + snprintf(buf, sizeof(buf), "%d", offset); -} - /************************************************* * Translate error code to string * *************************************************/ @@ -183,66 +199,50 @@ PCRE2POSIX_EXP_DEFN size_t PCRE2_CALL_CONVENTION pcre2_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) { -int ret; const char *message; -size_t len = 0; /* keeps 0 if snprintf is used */ +char offset_buf[11+12]; /* big enough for " at offset -2147483648" */ +int snprintf_rc, have_offset = 0; +PCRE2_SIZE i; message = (errcode <= 0 || errcode >= (int)(sizeof(pstring)/sizeof(char *)))? "unknown error code" : pstring[errcode]; -if (preg != NULL && (int)preg->re_erroffset != -1) +if (preg != NULL && preg->re_erroffset != (size_t)(-1) + /* LCOV_EXCL_START - snprintf failures here are essentially unreachable */ + && (snprintf_rc = snprintf(offset_buf, sizeof(offset_buf), " at offset %d", + (int)preg->re_erroffset)) > 0 + && snprintf_rc < (int)sizeof(offset_buf)) + /* LCOV_EXCL_STOP */ { - /* no need to deal with UB in snprintf */ - if (errbuf_size > INT_MAX) errbuf_size = INT_MAX; - - /* there are 11 characters between message and offset; - update message_len() if changed */ - ret = snprintf(errbuf, errbuf_size, "%s at offset %d", message, - (int)preg->re_erroffset); - } -else - { - len = strlen(message); - if (errbuf_size != 0) - { - strncpy(errbuf, message, errbuf_size); - if (errbuf_size <= len) errbuf[errbuf_size - 1] = '\0'; - } - ret = (int)len; + have_offset = 1; + offset_buf[sizeof(offset_buf) - 1] = 0; /* Paranoia for very old snprintf */ } -PCRE2_ASSERT(len > 0 || preg != NULL); +for (i = 0; *message != 0; i++, message++) + if (i + 1 < errbuf_size) errbuf[i] = *message; -do { - if (ret < 0) - { -#ifdef BROKEN_SNPRINTF - /* _snprintf returns -1 on overflow and doesn't zero terminate */ - if (!len) - { - if (ret == -1 && errbuf_size != 0) errbuf[errbuf_size - 1] = '\0'; +if (have_offset) + { + for (message = offset_buf; *message != 0; i++, message++) + if (i + 1 < errbuf_size) errbuf[i] = *message; + } - ret = message_len(message, (int)preg->re_erroffset); - break; - } +#if defined EBCDIC && 'a' != 0x81 +/* If compiling for EBCDIC, but the compiler's string literals are not EBCDIC, +then we are in the "force EBCDIC 1047" mode. I have chosen to add a few lines +here to translate the error strings on the fly, rather than require the string +literals above to be written out arduously using the "STR_XYZ" macros. */ +for (PCRE2_SIZE j = 0; j < i && j < errbuf_size; ++j) + errbuf[j] = PRIV(ascii_to_ebcdic_1047)[(uint8_t)errbuf[j]]; #endif - /* snprintf failed, will use a 14 char long message if possible */ - ret = 14; - if (errbuf_size != 0) - { - strncpy(errbuf, "internal error", errbuf_size); - if ((int)errbuf_size <= ret) errbuf[errbuf_size - 1] = '\0'; - } - } - else if (ret == (int)errbuf_size && !len) - { - /* pre C99 snprintf returns used, so redo ret to fix that */ - ret = message_len(message, (int)preg->re_erroffset); - } -} while (0); +/* Terminate message, even if truncated. */ -return ret + 1; +if (errbuf_size > 0) + errbuf[(i < errbuf_size)? i : errbuf_size - 1] = 0; +i++; + +return (int)i; } @@ -283,6 +283,9 @@ int errorcode; int options = 0; int re_nsub = 0; +preg->re_match_data = NULL; +preg->re_pcre2_code = NULL; + patlen = ((cflags & REG_PEND) != 0)? (PCRE2_SIZE)(preg->re_endp - pattern) : PCRE2_ZERO_TERMINATED; @@ -324,10 +327,14 @@ preg->re_erroffset = (size_t)(-1); /* No meaning after successful compile */ if (preg->re_match_data == NULL) { - /* LCOV_EXCL_START */ + /* There is no facility for passing a custom allocator to the POSIX API, so + our test code cannot force a malloc failure here. If there were an API to + customize the default (global) PCRE2 allocator, we could test it. Since the + code is nonetheless reachable, I prefer not to exclude it from coverage + reporting. */ pcre2_code_free(preg->re_pcre2_code); + preg->re_pcre2_code = NULL; return REG_ESPACE; - /* LCOV_EXCL_STOP */ } return 0; diff --git a/libpcre/src/pcre2posix.h b/libpcre/src/pcre2posix.h index cccea57e7..198612afc 100644 --- a/libpcre/src/pcre2posix.h +++ b/libpcre/src/pcre2posix.h @@ -118,41 +118,38 @@ typedef struct { regoff_t rm_eo; } regmatch_t; +/* When an application links to a PCRE2 DLL in Windows, the symbols that are +imported have to be identified as such. When building PCRE2, the appropriate +export settings are needed, and are set in pcre2posix.c before including this +file. So, we don't change existing definitions of PCRE2POSIX_EXP_DECL. + +By default, we use the standard "extern" declarations. */ + +#ifndef PCRE2POSIX_EXP_DECL +# if defined(_WIN32) && defined(PCRE2POSIX_SHARED) +# define PCRE2POSIX_EXP_DECL extern __declspec(dllimport) +# elif defined __cplusplus +# define PCRE2POSIX_EXP_DECL extern "C" +# else +# define PCRE2POSIX_EXP_DECL extern +# endif +#endif + /* When compiling with the MSVC compiler, it is sometimes necessary to include -a "calling convention" before exported function names. (This is secondhand -information; I know nothing about MSVC myself). For example, something like +a "calling convention" before exported function names. For example: void __cdecl function(....) might be needed. In order to make this easy, all the exported functions have -PCRE2_CALL_CONVENTION just before their names. It is rarely needed; if not -set, we ensure here that it has no effect. */ +PCRE2_CALL_CONVENTION just before their names. + +PCRE2 normally uses the platform's standard calling convention, so this should +not be set unless you know you need it. */ #ifndef PCRE2_CALL_CONVENTION #define PCRE2_CALL_CONVENTION #endif -#ifndef PCRE2_EXPORT -#define PCRE2_EXPORT -#endif - -/* When an application links to a PCRE2 DLL in Windows, the symbols that are -imported have to be identified as such. When building PCRE2, the appropriate -export settings are needed, and are set in pcre2posix.c before including this -file. */ - -/* By default, we use the standard "extern" declarations. */ - -#ifndef PCRE2POSIX_EXP_DECL -# if defined(_WIN32) && defined(PCRE2POSIX_SHARED) && !defined(PCRE2_STATIC) -# define PCRE2POSIX_EXP_DECL extern __declspec(dllimport) -# define PCRE2POSIX_EXP_DEFN __declspec(dllimport) -# else -# define PCRE2POSIX_EXP_DECL extern PCRE2_EXPORT -# define PCRE2POSIX_EXP_DEFN -# endif -#endif - /* The functions. The actual code is in functions with pcre2_xxx names for uniqueness. POSIX names are provided as macros for API compatibility with POSIX regex functions. It's done this way to ensure to they are always linked from diff --git a/libpcre/src/pcre2test_inc.h b/libpcre/src/pcre2test_inc.h new file mode 100644 index 000000000..8124e9ca6 --- /dev/null +++ b/libpcre/src/pcre2test_inc.h @@ -0,0 +1,6349 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Original API code Copyright (c) 1997-2012 University of Cambridge + New API code Copyright (c) 2016-2024 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +/* This module contains the mode-dependent code which is used by pcre2test.c. +It is #included in pcre2test.c at each supported code unit width, with +PCRE2_SUFFIX set appropriately, just like the functions that comprise the +library. */ + + +/* ------- Macros for hiding the bit width of this file's members ---------- */ + +#define pbuffer PCRE2_SUFFIX(pbuffer) +#define pbuffer_size G(pbuffer,_size) + +#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 +#define utf_to_ord G(G(utf,PCRE2_CODE_UNIT_WIDTH),_to_ord) +#endif + +#define compiled_code PCRE2_SUFFIX(compiled_code_) +#define general_context PCRE2_SUFFIX(general_context_) +#define general_context_copy PCRE2_SUFFIX(general_context_copy_) +#define pat_context PCRE2_SUFFIX(pat_context_) +#define default_pat_context PCRE2_SUFFIX(default_pat_context_) +#define con_context PCRE2_SUFFIX(con_context_) +#define default_con_context PCRE2_SUFFIX(default_con_context_) +#define dat_context PCRE2_SUFFIX(dat_context_) +#define default_dat_context PCRE2_SUFFIX(default_dat_context_) +#define match_data PCRE2_SUFFIX(match_data_) +#define jit_stack PCRE2_SUFFIX(jit_stack_) +#define jit_stack_size PCRE2_SUFFIX(jit_stack_size_) +#define patstack PCRE2_SUFFIX(patstack_) +#define patstacknext PCRE2_SUFFIX(patstacknext_) +#define rep_in_buffer PCRE2_SUFFIX(rep_in_buffer_) +#define rep_in_buffer_size PCRE2_SUFFIX(rep_in_buffer_size_) +#define rep_out_buffer PCRE2_SUFFIX(rep_out_buffer_) +#define rep_out_buffer_size PCRE2_SUFFIX(rep_out_buffer_size_) + +#define jit_callback PCRE2_SUFFIX(jit_callback_) +#define pcre2_strcmp_c8 PCRE2_SUFFIX(pcre2_strcmp_c8_) +#define pcre2_strlen PCRE2_SUFFIX(pcre2_strlen_) +#define pchars PCRE2_SUFFIX(pchars_) +#define ptrunc PCRE2_SUFFIX(ptrunc_) +#define config_str PCRE2_SUFFIX(config_str_) +#define check_modifier PCRE2_SUFFIX(check_modifier_) +#define decode_modifiers PCRE2_SUFFIX(decode_modifiers_) +#define pattern_info PCRE2_SUFFIX(pattern_info_) +#define show_memory_info PCRE2_SUFFIX(show_memory_info_) +#define show_framesize PCRE2_SUFFIX(show_framesize_) +#define show_heapframes_size PCRE2_SUFFIX(show_heapframes_size_) +#define print_error_message_file PCRE2_SUFFIX(print_error_message_file_) +#define print_error_message PCRE2_SUFFIX(print_error_message_) +#define callout_enumerate_function PCRE2_SUFFIX(callout_enumerate_function_) +#define callout_enumerate_function_void PCRE2_SUFFIX(callout_enumerate_function_void_) +#define callout_enumerate_function_fail PCRE2_SUFFIX(callout_enumerate_function_fail_) +#define show_pattern_info PCRE2_SUFFIX(show_pattern_info_) +#define serial_error PCRE2_SUFFIX(serial_error_) +#define process_command PCRE2_SUFFIX(process_command_) +#define process_pattern PCRE2_SUFFIX(process_pattern_) +#define have_active_pattern PCRE2_SUFFIX(have_active_pattern_) +#define free_active_pattern PCRE2_SUFFIX(free_active_pattern_) +#define check_match_limit PCRE2_SUFFIX(check_match_limit_) +#define substitute_callout_function PCRE2_SUFFIX(substitute_callout_function_) +#define substitute_case_callout_function PCRE2_SUFFIX(substitute_case_callout_function_) +#define callout_function PCRE2_SUFFIX(callout_function_) +#define copy_and_get PCRE2_SUFFIX(copy_and_get_) +#define copy_substitute_string PCRE2_SUFFIX(copy_substitute_string_) +#define process_data PCRE2_SUFFIX(process_data_) +#define init_globals PCRE2_SUFFIX(init_globals_) +#define free_globals PCRE2_SUFFIX(free_globals_) +#define unittest PCRE2_SUFFIX(unittest_) + + +/* ---------------------- Mode-dependent variables ------------------------- */ + +static pcre2_code *compiled_code = NULL; +static pcre2_general_context *general_context = NULL, *general_context_copy = NULL; +static pcre2_compile_context *pat_context = NULL, *default_pat_context = NULL; +static pcre2_convert_context *con_context = NULL, *default_con_context = NULL; +static pcre2_match_context *dat_context = NULL, *default_dat_context = NULL; +static pcre2_match_data *match_data = NULL; + +static pcre2_jit_stack *jit_stack = NULL; +static size_t jit_stack_size = 0; + +static pcre2_code *patstack[PATSTACKSIZE]; +static int patstacknext = 0; + +static PCRE2_UCHAR *rep_in_buffer = NULL; +static size_t rep_in_buffer_size = REPLACE_MODSIZE; /* Code units */ +static PCRE2_UCHAR *rep_out_buffer = NULL; +static size_t rep_out_buffer_size = REPLACE_BUFFSIZE; /* Code units */ + + + +/************************************************* +* JIT memory callback * +*************************************************/ + +static pcre2_jit_stack* +jit_callback(void *arg) +{ +jit_was_used = TRUE; +return (pcre2_jit_stack *)arg; +} + + + +/************************************************* +* Compare zero-terminated PCRE2 & 8-bit strings * +*************************************************/ + +static int +pcre2_strcmp_c8(PCRE2_SPTR str1, const char *str2) +{ +PCRE2_UCHAR c1, c2; +while (*str1 != '\0' || *str2 != '\0') + { + c1 = *str1++; + c2 = *str2++; + if (c1 != c2) return ((c1 > c2) << 1) - 1; + } +return 0; +} + + + +/************************************************* +* Find the length of a PCRE2 string * +*************************************************/ + +static size_t +pcre2_strlen(PCRE2_SPTR str) +{ +size_t c = 0; +while (*str++ != 0) c++; +return c; +} + + + +/************************************************* +* Print character string * +*************************************************/ + +/* Must handle Unicode strings in UTF mode. Yields number of characters printed. +For printing *MARK strings, a negative length is given, indicating that the +length is in the first code unit. If handed a NULL file, this function just +counts chars without printing (because pchar() does that). */ + +static int pchars(int clr, PCRE2_SPTR p, ptrdiff_t length, BOOL utf, FILE *f) +{ +#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 +PCRE2_SPTR end; +uint32_t c = 0; +int yield = 0; + +colour_begin(clr, f); + +if (length < 0) length = *p++; +end = p + length; +while (length-- > 0) + { + if (utf) + { + int rc = utf_to_ord(p, end, &c); + if (rc > 0 && rc <= length + 1) /* Mustn't run over the end */ + { + length -= rc - 1; + p += rc; + yield += pchar(c, utf, f); + continue; + } + } + c = *p++; + yield += pchar(c, utf, f); + } + +colour_end(f); +return yield; + +#else +int yield = 0; + +colour_begin(clr, f); + +if (length < 0) length = *p++; +while (length-- > 0) + { + uint32_t c = *p++; + yield += pchar(c, utf, f); + } + +colour_end(f); +return yield; + +#endif +} + + + +/************************************************* +* Print truncated character string * +*************************************************/ + +/* Must handle Unicode strings in UTF mode. Passed the total input string, and +the offset to print from/to. If left is true, prints up to the offset, +truncated; otherwise prints from the offset to the right, truncated. */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 +static void ptrunc_8(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, + BOOL left, BOOL utf, FILE *f) +{ +PCRE2_SPTR start = p + offset; +PCRE2_SPTR end = p + offset; +size_t printed = 0; + +colour_begin(clr, f); + +if (left) + { + while (start > p && printed < 10) + { + printed++; + start--; + if (utf) + { while(start > p && (*start & 0xc0u) == 0x80u) start--; } + } + } +else + { + while (end < p + p_len && printed < 10) + { + printed++; + end++; + if (utf) + { while(end < p + p_len && (*end & 0xc0u) == 0x80u) end++; } + } + } + +if (left && start > p) fprintf(f, "..."); +for (; start < end; start++) fprintf(f, "%c", CHAR_OUTPUT(*start)); +if (!left && end < p + p_len) fprintf(f, "..."); + +colour_end(f); +} + +#elif PCRE2_CODE_UNIT_WIDTH == 16 +static void ptrunc_16(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, + BOOL left, BOOL utf, FILE *f) +{ +PCRE2_SPTR start = p + offset; +PCRE2_SPTR end = p + offset; +size_t printed = 0; + +colour_begin(clr, f); + +if (left) + { + while (start > p && printed < 10) + { + printed++; + start--; + if (utf) + { while(start > p && (*start & 0xfc00u) == 0xdc00u) start--; } + } + } +else + { + while (end < p + p_len && printed < 10) + { + printed++; + end++; + if (utf) + { while(end < p + p_len && (*end & 0xfc00u) == 0xdc00u) end++; } + } + } + +if (left && start > p) fprintf(f, "..."); +while (start < end) + { + uint32_t c; + int rc = utf16_to_ord(start, end, &c); + if (rc < 0) c = *start++; + else start += rc; + if (c > 0xff || (utf && c > 0x7f)) + { + uint8_t u8buff[6]; + int clen = ord_to_utf8(c, u8buff); + fprintf(f, "%.*s", clen, u8buff); + continue; + } + fputc((int)c, f); + } +if (!left && end < p + p_len) fprintf(f, "..."); + +colour_end(f); +} + +#elif PCRE2_CODE_UNIT_WIDTH == 32 +static void ptrunc_32(int clr, PCRE2_SPTR p, size_t p_len, size_t offset, + BOOL left, BOOL utf, FILE *f) +{ +PCRE2_SPTR start = p + offset; +PCRE2_SPTR end = p + offset; + +colour_begin(clr, f); + +if (left) + { + start -= (offset > 10)? 10 : offset; + } +else + { + end += (p + p_len - end > 10)? 10 : p + p_len - end; + } + +if (left && start > p) fprintf(f, "..."); +while (start < end) + { + uint32_t c = *start++; + if (c > 0xff || (utf && c > 0x7f)) + { + uint8_t u8buff[6]; + int clen = ord_to_utf8(c, u8buff); + fprintf(f, "%.*s", clen, u8buff); + continue; + } + fputc((int)c, f); + } +if (!left && end < p + p_len) fprintf(f, "..."); + +colour_end(f); +} +#endif + +#if PCRE2_CODE_UNIT_WIDTH == 16 +/************************************************* +* Convert string to 16-bit * +*************************************************/ + +/* In UTF mode the input is always interpreted as a string of UTF-8 bytes using +the original UTF-8 definition of RFC 2279, which allows for up to 6 bytes, and +code values from 0 to 0x7fffffff. However, values greater than the later UTF +limit of 0x10ffff cause an error. In non-UTF mode the input is interpreted as +UTF-8 if the utf8_input modifier is set, but an error is generated for values +greater than 0xffff. + +If all the input bytes are ASCII, the space needed for a 16-bit string is +exactly double the 8-bit size. Otherwise, the size needed for a 16-bit string +is no more than double, because up to 0xffff uses no more than 3 bytes in UTF-8 +but possibly 4 in UTF-16. Higher values use 4 bytes in UTF-8 and up to 4 bytes +in UTF-16. The result is always left in pbuffer16. Impose a minimum size to +save repeated re-sizing. + +Note that this function does not object to surrogate values. This is +deliberate; it makes it possible to construct UTF-16 strings that are invalid, +for the purpose of testing that they are correctly faulted. + +Arguments: + p points to a byte string + utf true in UTF mode + lenptr points to number of bytes in the string (excluding trailing zero) + +Returns: 0 on success, with the length updated to the number of 16-bit + data items used (excluding the trailing zero) + OR -1 if a UTF-8 string is malformed + OR -2 if a value > 0x10ffff is encountered in UTF mode + OR -3 if a value > 0xffff is encountered when not in UTF mode +*/ + +static int +to16(uint8_t *p, int utf, PCRE2_SIZE *lenptr) +{ +uint16_t *pp; +PCRE2_SIZE len = *lenptr; + +if (pbuffer16_size < 2*len + 2) + { + if (pbuffer16 != NULL) free(pbuffer16); + pbuffer16_size = 2*len + 2; + if (pbuffer16_size < 4096) pbuffer16_size = 4096; + pbuffer16 = (uint16_t *)malloc(pbuffer16_size); + if (pbuffer16 == NULL) + { + cfprintf(clr_test_error, stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n", + pbuffer16_size); + exit(1); + } + } + +pp = pbuffer16; +if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0) + { + for (; len > 0; len--) *pp++ = *p++; + } + +else while (len > 0) + { + uint32_t c; + const uint8_t *end = p + len; + int chlen = utf8_to_ord(p, end, &c); + if (chlen <= 0) return -1; + if (!utf && c > 0xffff) return -3; + if (c > 0x10ffff) return -2; + p += chlen; + len -= chlen; + if (c < 0x10000) *pp++ = c; else + { + c -= 0x10000; + *pp++ = 0xd800 | (c >> 10); + *pp++ = 0xdc00 | (c & 0x3ff); + } + } + +*pp = 0; +*lenptr = pp - pbuffer16; +return 0; +} +#endif /* PCRE2_CODE_UNIT_WIDTH == 16 */ + + + +#if PCRE2_CODE_UNIT_WIDTH == 32 +/************************************************* +* Convert string to 32-bit * +*************************************************/ + +/* In UTF mode the input is always interpreted as a string of UTF-8 bytes using +the original UTF-8 definition of RFC 2279, which allows for up to 6 bytes, and +code values from 0 to 0x7fffffff. However, values greater than the later UTF +limit of 0x10ffff cause an error. + +In non-UTF mode the input is interpreted as UTF-8 if the utf8_input modifier +is set, and no limit is imposed. There is special interpretation of the 0xff +byte (which is illegal in UTF-8) in this case: it causes the top bit of the +next character to be set. This provides a way of generating 32-bit characters +greater than 0x7fffffff. + +If all the input bytes are ASCII, the space needed for a 32-bit string is +exactly four times the 8-bit size. Otherwise, the size needed for a 32-bit +string is no more than four times, because the number of characters must be +less than the number of bytes. The result is always left in pbuffer32. Impose a +minimum size to save repeated re-sizing. + +Note that this function does not object to surrogate values. This is +deliberate; it makes it possible to construct UTF-32 strings that are invalid, +for the purpose of testing that they are correctly faulted. + +Arguments: + p points to a byte string + utf true in UTF mode + lenptr points to number of bytes in the string (excluding trailing zero) + +Returns: 0 on success, with the length updated to the number of 32-bit + data items used (excluding the trailing zero) + OR -1 if a UTF-8 string is malformed + OR -2 if a value > 0x10ffff is encountered in UTF mode +*/ + +static int +to32(uint8_t *p, int utf, PCRE2_SIZE *lenptr) +{ +uint32_t *pp; +PCRE2_SIZE len = *lenptr; + +if (pbuffer32_size < 4*len + 4) + { + if (pbuffer32 != NULL) free(pbuffer32); + pbuffer32_size = 4*len + 4; + if (pbuffer32_size < 8192) pbuffer32_size = 8192; + pbuffer32 = (uint32_t *)malloc(pbuffer32_size); + if (pbuffer32 == NULL) + { + cfprintf(clr_test_error, stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n", + pbuffer32_size); + exit(1); + } + } + +pp = pbuffer32; +if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0) + { + for (; len > 0; len--) *pp++ = *p++; + } + +else while (len > 0) + { + int chlen; + uint32_t c; + uint32_t topbit = 0; + const uint8_t *end = p + len; + if (!utf && *p == 0xff && len > 1) + { + topbit = 0x80000000u; + p++; + len--; + } + chlen = utf8_to_ord(p, end, &c); + if (chlen <= 0) return -1; + if (utf && c > 0x10ffff) return -2; + p += chlen; + len -= chlen; + *pp++ = c | topbit; + } + +*pp = 0; +*lenptr = pp - pbuffer32; +return 0; +} +#endif /* PCRE2_CODE_UNIT_WIDTH == 32 */ + + + +/************************************************* +* Read a string from pcre2_config() * +*************************************************/ + +/* Read out a version string from pcre2_config(), transcoding it into an +8-bit buffer. + +Arguments: + what the item to read + where the 8-bit buffer to receive the string +*/ + +static void +config_str(uint32_t what, char *where) +{ +int r1, r2; +PCRE2_UCHAR buf[VERSION_SIZE]; + +r1 = pcre2_config(what, NULL); +r2 = pcre2_config(what, buf); +if (r1 < 0 || r1 != r2 || r1 >= VERSION_SIZE) + { + cfprintf(clr_test_error, stderr, "pcre2test: Error in pcre2_config(%d)\n", what); + exit(1); + } + +while (r1-- > 0) where[r1] = (char)buf[r1]; +} + + + +/************************************************* +* Check a modifier and find its field * +*************************************************/ + +/* This function is called when a modifier has been identified. We check that +it is allowed here and find the field that is to be changed. + +Arguments: + m the modifier list entry + ctx CTX_PAT => pattern context + CTX_POPPAT => pattern context for popped pattern + CTX_DEFPAT => default pattern context + CTX_DAT => data context + CTX_DEFDAT => default data context + pctl point to pattern control block + dctl point to data control block + c a single character or 0 + +Returns: a field pointer or NULL +*/ + +static void * +check_modifier(modstruct *m, int ctx, patctl *pctl, datctl *dctl, uint32_t c) +{ +void *field = NULL; +PCRE2_SIZE offset = m->offset; + +if (restrict_for_perl_test) switch(m->which) + { + case MOD_PNDP: + case MOD_PATP: + case MOD_DATP: + case MOD_PDP: + break; + + default: + cfprintf(clr_test_error, outfile, "** \"%s\" is not allowed in a Perl-compatible test\n", + m->name); + return NULL; + } + +switch (m->which) + { + case MOD_CTC: /* Compile context modifier */ + if (ctx == CTX_DEFPAT) field = default_pat_context; + else if (ctx == CTX_PAT) field = pat_context; + break; + + case MOD_CTM: /* Match context modifier */ + if (ctx == CTX_DEFDAT) field = default_dat_context; + else if (ctx == CTX_DAT) field = dat_context; + break; + + case MOD_DAT: /* Data line modifier */ + case MOD_DATP: /* Allowed for Perl test */ + if (dctl != NULL) field = dctl; + break; + + case MOD_PAT: /* Pattern modifier */ + case MOD_PATP: /* Allowed for Perl test */ + if (pctl != NULL) field = pctl; + break; + + case MOD_PD: /* Pattern or data line modifier */ + case MOD_PDP: /* Ditto, allowed for Perl test */ + case MOD_PND: /* Ditto, but not default pattern */ + case MOD_PNDP: /* Ditto, allowed for Perl test */ + if (dctl != NULL) field = dctl; + else if (pctl != NULL && (m->which == MOD_PD || m->which == MOD_PDP || + ctx != CTX_DEFPAT)) + field = pctl; + break; + } + +if (field == NULL) + { + if (c == 0) + cfprintf(clr_test_error, outfile, "** \"%s\" is not valid here\n", m->name); + else + cfprintf(clr_test_error, outfile, "** /%c is not valid here\n", c); + return NULL; + } + +return (char *)field + offset; +} + + + +/************************************************* +* Decode a modifier list * +*************************************************/ + +/* A pointer to a control block is NULL when called in cases when that block is +not relevant. They are never all relevant in one call. At least one of patctl +and datctl is NULL. The second argument specifies which context to use for +modifiers that apply to contexts. + +Arguments: + p point to modifier string + ctx CTX_PAT => pattern context + CTX_POPPAT => pattern context for popped pattern + CTX_DEFPAT => default pattern context + CTX_DAT => data context + CTX_DEFDAT => default data context + pctl point to pattern control block + dctl point to data control block + +Returns: TRUE if successful decode, FALSE otherwise +*/ + +static BOOL +decode_modifiers(uint8_t *p, int ctx, patctl *pctl, datctl *dctl) +{ +uint8_t *ep, *pp; +long li; +unsigned long uli; +BOOL first = TRUE; + +for (;;) + { + void *field; + modstruct *m; + BOOL off = FALSE; + unsigned int i; + size_t len; + int index; + char *endptr; + + /* Skip white space and commas. */ + + while (isspace(*p) || *p == ',') p++; + if (*p == 0) break; + + /* Find the end of the item; lose trailing whitespace at end of line. */ + + for (ep = p; *ep != 0 && *ep != ','; ep++); + if (*ep == 0) + { + while (ep > p && isspace(ep[-1])) ep--; + *ep = 0; + } + + /* Remember if the first character is '-'. */ + + if (*p == '-') + { + off = TRUE; + p++; + } + + /* Find the length of a full-length modifier name, and scan for it. */ + + pp = p; + while (pp < ep && *pp != '=') pp++; + index = scan_modifiers(p, pp - p); + + /* If the first modifier is unrecognized, try to interpret it as a sequence + of single-character abbreviated modifiers. None of these modifiers have any + associated data. They just set options or control bits. */ + + if (index < 0) + { + uint32_t cc; + uint8_t *mp = p; + + if (!first) + { + cfprintf(clr_test_error, outfile, "** Unrecognized modifier \"%.*s\"\n", (int)(ep-p), p); + if (ep - p == 1) + cfprintf(clr_test_error, outfile, "** Single-character modifiers must come first\n"); + return FALSE; + } + + first = FALSE; + + for (cc = *p; cc != ',' && cc != '\n' && cc != 0; cc = *(++p)) + { + for (i = 0; i < C1MODLISTCOUNT; i++) + if (cc == c1modlist[i].onechar) break; + + if (i >= C1MODLISTCOUNT) + { + cfprintf(clr_test_error, outfile, "** Unrecognized modifier '%c' in modifier string " + "\"%.*s\"\n", *p, (int)(ep-mp), mp); + return FALSE; + } + + if (c1modlist[i].index >= 0) + { + index = c1modlist[i].index; + } + + else + { + index = scan_modifiers((const uint8_t *)(c1modlist[i].fullname), + strlen(c1modlist[i].fullname)); + if (index < 0) + { + cfprintf(clr_test_error, outfile, "** Internal error: single-character equivalent " + "modifier \"%s\" not found\n", c1modlist[i].fullname); + return FALSE; + } + c1modlist[i].index = index; /* Cache for next time */ + } + + field = check_modifier(modlist + index, ctx, pctl, dctl, *p); + if (field == NULL) return FALSE; + + /* /x is a special case; a second appearance changes PCRE2_EXTENDED to + PCRE2_EXTENDED_MORE. */ + + if (cc == 'x' && (*((uint32_t *)field) & PCRE2_EXTENDED) != 0) + { + *((uint32_t *)field) &= ~PCRE2_EXTENDED; + *((uint32_t *)field) |= PCRE2_EXTENDED_MORE; + } + else + *((uint32_t *)field) |= modlist[index].value; + } + + continue; /* With the next (fullname) modifier */ + } + + /* We have a match on a full-name modifier. Check for the existence of data + when needed. */ + + m = modlist + index; /* Save typing */ + if (m->type != MOD_CTL && m->type != MOD_OPT && m->type != MOD_OPTMZ && + (m->type != MOD_IND || *pp == '=')) + { + if (*pp++ != '=') + { + cfprintf(clr_test_error, outfile, "** '=' expected after \"%s\"\n", m->name); + return FALSE; + } + if (off) + { + cfprintf(clr_test_error, outfile, "** '-' is not valid for \"%s\"\n", m->name); + return FALSE; + } + } + + /* These on/off types have no data. */ + + else if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0) + { + cfprintf(clr_test_error, outfile, "** Unrecognized modifier '%.*s'\n", (int)(ep-p), p); + return FALSE; + } + + /* Set the data length for those types that have data. Then find the field + that is to be set. If check_modifier() returns NULL, it has already output an + error message. */ + + len = ep - pp; + field = check_modifier(m, ctx, pctl, dctl, 0); + if (field == NULL) return FALSE; + + /* Process according to data type. */ + + switch (m->type) + { + case MOD_CTL: + case MOD_OPT: + if (off) *((uint32_t *)field) &= ~m->value; + else *((uint32_t *)field) |= m->value; + break; + + case MOD_OPTMZ: + pcre2_set_optimize(field, m->value); + break; + + case MOD_BSR: + if (len == 7 && strncmpic(pp, (const uint8_t *)"default", 7) == 0) + { +#ifdef BSR_ANYCRLF + *((uint16_t *)field) = PCRE2_BSR_ANYCRLF; +#else + *((uint16_t *)field) = PCRE2_BSR_UNICODE; +#endif + if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 &= ~CTL2_BSR_SET; + else dctl->control2 &= ~CTL2_BSR_SET; + } + else + { + if (len == 7 && strncmpic(pp, (const uint8_t *)"anycrlf", 7) == 0) + *((uint16_t *)field) = PCRE2_BSR_ANYCRLF; + else if (len == 7 && strncmpic(pp, (const uint8_t *)"unicode", 7) == 0) + *((uint16_t *)field) = PCRE2_BSR_UNICODE; + else goto INVALID_VALUE; + if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 |= CTL2_BSR_SET; + else dctl->control2 |= CTL2_BSR_SET; + } + pp = ep; + break; + + case MOD_CHR: /* A single character */ + *((uint32_t *)field) = *pp++; + break; + + case MOD_CON: /* A convert type/options list */ + for (;; pp++) + { + uint8_t *colon = (uint8_t *)strchr((const char *)pp, ':'); + len = ((colon != NULL && colon < ep)? colon:ep) - pp; + for (i = 0; i < convertlistcount; i++) + { + if (strncmpic(pp, (const uint8_t *)convertlist[i].name, len) == 0) + { + if (*((uint32_t *)field) == CONVERT_UNSET) + *((uint32_t *)field) = convertlist[i].option; + else + *((uint32_t *)field) |= convertlist[i].option; + break; + } + } + if (i >= convertlistcount) goto INVALID_VALUE; + pp += len; + if (*pp != ':') break; + } + break; + + case MOD_IN2: /* One or two unsigned integers */ + if (!isdigit(*pp)) goto INVALID_VALUE; + uli = strtoul((const char *)pp, &endptr, 10); + if (U32OVERFLOW(uli)) goto INVALID_VALUE; + ((uint32_t *)field)[0] = (uint32_t)uli; + if (*endptr == ':') + { + uli = strtoul((const char *)endptr+1, &endptr, 10); + if (U32OVERFLOW(uli)) goto INVALID_VALUE; + ((uint32_t *)field)[1] = (uint32_t)uli; + } + else ((uint32_t *)field)[1] = 0; + pp = (uint8_t *)endptr; + break; + + /* PCRE2_SIZE_MAX is usually SIZE_MAX, which may be greater, equal to, or + less than ULONG_MAX. So first test for overflowing the long int, and then + test for overflowing PCRE2_SIZE_MAX if it is smaller than ULONG_MAX. */ + + case MOD_SIZ: /* PCRE2_SIZE value */ + if (!isdigit(*pp)) goto INVALID_VALUE; + uli = strtoul((const char *)pp, &endptr, 10); + if (uli == ULONG_MAX) goto INVALID_VALUE; +#if ULONG_MAX > PCRE2_SIZE_MAX + if (uli > PCRE2_SIZE_MAX) goto INVALID_VALUE; +#endif + *((PCRE2_SIZE *)field) = (PCRE2_SIZE)uli; + pp = (uint8_t *)endptr; + break; + + case MOD_IND: /* Unsigned integer with default */ + if (len == 0) + { + *((uint32_t *)field) = (uint32_t)(m->value); + break; + } + PCRE2_FALLTHROUGH /* Fall through */ + + case MOD_INT: /* Unsigned integer */ + if (!isdigit(*pp)) goto INVALID_VALUE; + uli = strtoul((const char *)pp, &endptr, 10); + if (U32OVERFLOW(uli)) goto INVALID_VALUE; + *((uint32_t *)field) = (uint32_t)uli; + pp = (uint8_t *)endptr; + break; + + case MOD_INS: /* Signed integer */ + if (!isdigit(*pp) && *pp != '-') goto INVALID_VALUE; + li = strtol((const char *)pp, &endptr, 10); + if (S32OVERFLOW(li)) goto INVALID_VALUE; + *((int32_t *)field) = (int32_t)li; + pp = (uint8_t *)endptr; + break; + + case MOD_NL: + for (i = 0; i < sizeof(newlines)/sizeof(char *); i++) + if (len == strlen(newlines[i]) && + strncmpic(pp, (const uint8_t *)newlines[i], len) == 0) break; + if (i >= sizeof(newlines)/sizeof(char *)) goto INVALID_VALUE; + if (i == 0) + { + pcre2_set_newline(field, NEWLINE_DEFAULT); + if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 &= ~CTL2_NL_SET; + else dctl->control2 &= ~CTL2_NL_SET; + } + else + { + pcre2_set_newline(field, i); + if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 |= CTL2_NL_SET; + else dctl->control2 |= CTL2_NL_SET; + } + pp = ep; + break; + + case MOD_NN: /* Name or (signed) number; may be several */ + if (isdigit(*pp) || *pp == '-') + { + int ct = MAXCPYGET - 1; + int32_t value; + li = strtol((const char *)pp, &endptr, 10); + if (S32OVERFLOW(li)) goto INVALID_VALUE; + value = (int32_t)li; + field = (char *)field - m->offset + m->value; /* Adjust field ptr */ + if (value >= 0) /* Add new number */ + { + while (*((int32_t *)field) >= 0 && ct-- > 0) /* Skip previous */ + field = (char *)field + sizeof(int32_t); + if (ct <= 0) + { + cfprintf(clr_test_error, outfile, "** Too many numeric \"%s\" modifiers\n", m->name); + return FALSE; + } + } + *((int32_t *)field) = value; + if (ct > 0) ((int32_t *)field)[1] = -1; + pp = (uint8_t *)endptr; + } + + /* Multiple strings are put end to end. */ + + else + { + char *nn = (char *)field; + if (len > 0) /* Add new name */ + { + if (len > MAX_NAME_SIZE) + { + cfprintf(clr_test_error, outfile, "** Group name in \"%s\" is too long\n", m->name); + return FALSE; + } + while (*nn != 0) nn += strlen(nn) + 1; + if (nn + len + 2 - (char *)field > LENCPYGET) + { + cfprintf(clr_test_error, outfile, "** Too many characters in named \"%s\" modifiers\n", + m->name); + return FALSE; + } + memcpy(nn, pp, len); + } + nn[len] = 0 ; + nn[len+1] = 0; + pp = ep; + } + break; + + case MOD_STR: + if (len + 1 > m->value) + { + cfprintf(clr_test_error, outfile, "** Overlong value for \"%s\" (max %d code units)\n", + m->name, m->value - 1); + return FALSE; + } + ((uint8_t *)field)[0] = len; + memcpy(((uint8_t *)field)+1, pp, len); + ((uint8_t *)field)[len+1] = 0; + pp = ep; + break; + } + + if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0) + { + cfprintf(clr_test_error, outfile, "** Comma expected after modifier item \"%s\"\n", m->name); + return FALSE; + } + + p = pp; + + if (ctx == CTX_POPPAT && + (pctl->options != 0 || + pctl->tables_id != 0 || + pctl->locale[0] != MOD_STR_UNSET || + (pctl->control & NOTPOP_CONTROLS) != 0)) + { + cfprintf(clr_test_error, outfile, "** \"%s\" is not valid here\n", m->name); + return FALSE; + } + } + +return TRUE; + +INVALID_VALUE: +cfprintf(clr_test_error, outfile, "** Invalid value in \"%.*s\"\n", (int)(ep-p), p); +return FALSE; +} + + + +/************************************************* +* Get info from a pattern * +*************************************************/ + +/* A wrapped call to pcre2_pattern_info(), applied to the current compiled +pattern. + +Arguments: + what code for the required information + where where to put the answer + unsetok PCRE2_ERROR_UNSET is an "expected" result + +Returns: the return from pcre2_pattern_info() +*/ + +static int +pattern_info(int what, void *where, BOOL unsetok) +{ +int rc; +(void)pcre2_pattern_info(compiled_code, what, NULL); /* Exercise the code */ +rc = pcre2_pattern_info(compiled_code, what, where); +if (rc >= 0) return 0; +if (rc != PCRE2_ERROR_UNSET || !unsetok) + { + cfprintf(clr_api_error, outfile, "Error %d from " + "pcre2_pattern_info_" STR(PCRE2_CODE_UNIT_WIDTH) "(%d)\n", rc, what); + } +return rc; +} + + + +/************************************************* +* Show memory usage info for a pattern * +*************************************************/ + +static void +show_memory_info(void) +{ +uint32_t name_count, name_entry_size; +PCRE2_SIZE size, cblock_size, data_size; + +cblock_size = sizeof(pcre2_real_code); + +(void)pattern_info(PCRE2_INFO_SIZE, &size, FALSE); +(void)pattern_info(PCRE2_INFO_NAMECOUNT, &name_count, FALSE); +(void)pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size, FALSE); + +/* The uint32_t variables are cast before multiplying to avoid potential + integer overflow. */ +data_size = CU2BYTES((PCRE2_SIZE)name_count * (PCRE2_SIZE)name_entry_size); + +cfprintf(clr_profiling, outfile, "Memory allocation - code size : %" SIZ_FORM "\n", size - + cblock_size - data_size); +if (data_size != 0) + cfprintf(clr_profiling, outfile, "Memory allocation - data size : %" SIZ_FORM "\n", data_size); + +if (pat_patctl.jit != 0) + { + (void)pattern_info(PCRE2_INFO_JITSIZE, &size, FALSE); + cfprintf(clr_profiling, outfile, "Memory allocation - JIT code : %" SIZ_FORM "\n", size); + } +} + + + +/************************************************* +* Show frame size info for a pattern * +*************************************************/ + +static void +show_framesize(void) +{ +PCRE2_SIZE frame_size; +(void)pattern_info(PCRE2_INFO_FRAMESIZE, &frame_size, FALSE); +cfprintf(clr_profiling, outfile, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size); +} + + + +/************************************************* +* Show heapframes size info for a match_data * +*************************************************/ + +static void +show_heapframes_size(void) +{ +PCRE2_SIZE heapframes_size; +heapframes_size = pcre2_get_match_data_heapframes_size(match_data); +cfprintf(clr_profiling, outfile, "Heapframes size in match_data: %" SIZ_FORM "\n", + heapframes_size); +} + + + +/************************************************* +* Get and output an error message * +*************************************************/ + +static BOOL +print_error_message_file(FILE *file, int errorcode, const char *before, + const char *after, BOOL badcode_ok) +{ +int len; +PCRE2_UCHAR buf[128]; + +len = pcre2_get_error_message(errorcode, buf, sizeof(buf)/sizeof(*buf)); +if (len == PCRE2_ERROR_BADDATA && badcode_ok) + { + cfprintf(clr_api_error, file, "%sPCRE2_ERROR_BADDATA (unknown error number)%s", before, + after); + } +else if (len < 0) + { + cfprintf(clr_test_error, file, "\n** pcre2test internal error: cannot interpret error " + "number\n** Unexpected return (%d) from pcre2_get_error_message()\n", len); + } +else if ((unsigned)len != pcre2_strlen(buf)) + { + cfprintf(clr_test_error, file, "\n** pcre2test: unexpected length %d from pcre2_get_error_message()\n", len); + return FALSE; + } +else + { + cfprintf(clr_api_error, file, "%s", before); + pchars(clr_api_error, buf, len, FALSE, file); + cfprintf(clr_api_error, file, "%s", after); + } +return len >= 0; +} + +static BOOL +print_error_message(int errorcode, const char *before, const char *after) +{ +return print_error_message_file(outfile, errorcode, before, after, FALSE); +} + + +/************************************************* +* Callback function for callout enumeration * +*************************************************/ + +/* Testing function to log data inside callout enumeration callbacks. + +Argument: + cb pointer to enumerate block + callout_data user data + +Returns: 0 +*/ + +static int callout_enumerate_function(pcre2_callout_enumerate_block *cb, + void *callout_data) +{ +uint32_t i; +PCRE2_SPTR pattern_string = pbuffer; +BOOL utf = (compiled_code->overall_options & PCRE2_UTF) != 0; +PCRE2_SIZE next_item_length = cb->next_item_length; + +(void)callout_data; /* Not currently displayed */ + +fprintf(outfile, "Callout "); +if (cb->callout_string != NULL) + { + uint32_t delimiter = cb->callout_string[-1]; + fprintf(outfile, "%c", CHAR_OUTPUT(delimiter)); + pchars(clr_none, cb->callout_string, cb->callout_string_length, utf, outfile); + for (i = 0; callout_start_delims[i] != 0; i++) + if (delimiter == callout_start_delims[i]) + { + delimiter = callout_end_delims[i]; + break; + } + fprintf(outfile, "%c ", CHAR_OUTPUT(delimiter)); + } +else fprintf(outfile, "%d ", cb->callout_number); + +if (next_item_length == 0 && pattern_string[cb->pattern_position] != 0) + next_item_length = 1; +pchars(clr_none, pattern_string+cb->pattern_position, next_item_length, utf, outfile); +fprintf(outfile, "\n"); + +return 0; +} + +static int callout_enumerate_function_void(pcre2_callout_enumerate_block *cb, + void *callout_data) +{ +(void)cb; +(void)callout_data; +return 0; +} + +static int callout_enumerate_function_fail(pcre2_callout_enumerate_block *cb, + void *callout_data) +{ +(void)cb; +return *(int *)callout_data; +} + + + +/************************************************* +* Show information about a pattern * +*************************************************/ + +/* This function is called after a pattern has been compiled if any of the +information-requesting controls have been set. + +Arguments: none + +Returns: PR_OK continue processing next line + PR_SKIP skip to a blank line + PR_ABEND abort the pcre2test run +*/ + +static int +show_pattern_info(void) +{ +int rc; +uint32_t compile_options, overall_options, extra_options; +BOOL utf = (compiled_code->overall_options & PCRE2_UTF) != 0; + +if ((pat_patctl.control & CTL_MEMORY) != 0) + show_memory_info(); + +if ((pat_patctl.control2 & CTL2_FRAMESIZE) != 0) + show_framesize(); + +if ((pat_patctl.control & (CTL_BINCODE|CTL_FULLBINCODE)) != 0) + { + fprintf(outfile, "------------------------------------------------------------------\n"); + pcre2_printint(compiled_code, outfile, + (pat_patctl.control & CTL_FULLBINCODE) != 0); + } + +if ((pat_patctl.control & CTL_INFO) != 0) + { + PCRE2_SPTR nametable; + uint8_t *start_bits; + BOOL heap_limit_set, match_limit_set, depth_limit_set; + uint32_t backrefmax, bsr_convention, capture_count, first_ctype, first_cunit, + hasbackslashc, hascrorlf, jchanged, last_ctype, last_cunit, match_empty, + depth_limit, heap_limit, match_limit, minlength, nameentrysize, namecount, + newline_convention; + + /* These info requests may return PCRE2_ERROR_UNSET. */ + + switch(pattern_info(PCRE2_INFO_HEAPLIMIT, &heap_limit, TRUE)) + { + case 0: + heap_limit_set = TRUE; + break; + + case PCRE2_ERROR_UNSET: + heap_limit_set = FALSE; + break; + + default: + return PR_ABEND; + } + + switch(pattern_info(PCRE2_INFO_MATCHLIMIT, &match_limit, TRUE)) + { + case 0: + match_limit_set = TRUE; + break; + + case PCRE2_ERROR_UNSET: + match_limit_set = FALSE; + break; + + default: + return PR_ABEND; + } + + switch(pattern_info(PCRE2_INFO_DEPTHLIMIT, &depth_limit, TRUE)) + { + case 0: + depth_limit_set = TRUE; + break; + + case PCRE2_ERROR_UNSET: + depth_limit_set = FALSE; + break; + + default: + return PR_ABEND; + } + + /* These info requests should always succeed. */ + + if (pattern_info(PCRE2_INFO_BACKREFMAX, &backrefmax, FALSE) + + pattern_info(PCRE2_INFO_BSR, &bsr_convention, FALSE) + + pattern_info(PCRE2_INFO_CAPTURECOUNT, &capture_count, FALSE) + + pattern_info(PCRE2_INFO_FIRSTBITMAP, &start_bits, FALSE) + + pattern_info(PCRE2_INFO_FIRSTCODEUNIT, &first_cunit, FALSE) + + pattern_info(PCRE2_INFO_FIRSTCODETYPE, &first_ctype, FALSE) + + pattern_info(PCRE2_INFO_HASBACKSLASHC, &hasbackslashc, FALSE) + + pattern_info(PCRE2_INFO_HASCRORLF, &hascrorlf, FALSE) + + pattern_info(PCRE2_INFO_JCHANGED, &jchanged, FALSE) + + pattern_info(PCRE2_INFO_LASTCODEUNIT, &last_cunit, FALSE) + + pattern_info(PCRE2_INFO_LASTCODETYPE, &last_ctype, FALSE) + + pattern_info(PCRE2_INFO_MATCHEMPTY, &match_empty, FALSE) + + pattern_info(PCRE2_INFO_MINLENGTH, &minlength, FALSE) + + pattern_info(PCRE2_INFO_NAMECOUNT, &namecount, FALSE) + + pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &nameentrysize, FALSE) + + pattern_info(PCRE2_INFO_NAMETABLE, &nametable, FALSE) + + pattern_info(PCRE2_INFO_NEWLINE, &newline_convention, FALSE) + != 0) + return PR_ABEND; + + fprintf(outfile, "Capture group count = %d\n", capture_count); + + if (backrefmax > 0) + fprintf(outfile, "Max back reference = %d\n", backrefmax); + + if (maxlookbehind > 0) + fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind); + + if (heap_limit_set) + fprintf(outfile, "Heap limit = %u\n", heap_limit); + + if (match_limit_set) + fprintf(outfile, "Match limit = %u\n", match_limit); + + if (depth_limit_set) + fprintf(outfile, "Depth limit = %u\n", depth_limit); + + if (namecount > 0) + { + fprintf(outfile, "Named capture groups:\n"); + for (; namecount > 0; namecount--) + { + size_t length = pcre2_strlen(nametable + IMM2_SIZE); + fprintf(outfile, " "); + + /* In UTF mode the name may be a UTF string containing non-ASCII + letters and digits. We must output it as a UTF-8 string. In non-UTF mode, + use the normal string printing functions, which use escapes for all + non-ASCII characters. */ + + if (utf) + { +#if PCRE2_CODE_UNIT_WIDTH == 32 + PCRE2_SPTR nameptr = nametable + IMM2_SIZE; + while (*nameptr != 0) + { + uint8_t u8buff[6]; + int len = ord_to_utf8(*nameptr++, u8buff); + fprintf(outfile, "%.*s", len, u8buff); + } +#endif +#if PCRE2_CODE_UNIT_WIDTH == 16 + PCRE2_SPTR nameptr = nametable + IMM2_SIZE; + PCRE2_SPTR nameptr_end = nameptr + pcre2_strlen(nameptr); + while (*nameptr != 0) + { + int len; + uint8_t u8buff[6]; + uint32_t c; + int ord_rc = utf16_to_ord(nameptr, nameptr_end, &c); + if (ord_rc > 0) nameptr += ord_rc; + else c = *nameptr++; + len = ord_to_utf8(c, u8buff); + fprintf(outfile, "%.*s", len, u8buff); + } +#endif +#if PCRE2_CODE_UNIT_WIDTH == 8 + fprintf(outfile, "%s", nametable + IMM2_SIZE); +#endif + } + else /* Not UTF mode */ + { + pchars(clr_none, nametable + IMM2_SIZE, length, FALSE, outfile); + } + + while (length++ < nameentrysize - IMM2_SIZE) putc(' ', outfile); + + fprintf(outfile, "%3d\n", GET2(nametable, 0)); + + nametable = nametable + nameentrysize; + } + } + + if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n"); + if (hasbackslashc) fprintf(outfile, "Contains \\C\n"); + if (match_empty) fprintf(outfile, "May match empty string\n"); + + pattern_info(PCRE2_INFO_ARGOPTIONS, &compile_options, FALSE); + pattern_info(PCRE2_INFO_ALLOPTIONS, &overall_options, FALSE); + pattern_info(PCRE2_INFO_EXTRAOPTIONS, &extra_options, FALSE); + + /* Remove UTF/UCP if they were there only because of forbid_utf. This saves + cluttering up the verification output of non-UTF test files. */ + + if ((pat_patctl.options & PCRE2_NEVER_UTF) == 0) + { + compile_options &= ~PCRE2_NEVER_UTF; + overall_options &= ~PCRE2_NEVER_UTF; + } + + if ((pat_patctl.options & PCRE2_NEVER_UCP) == 0) + { + compile_options &= ~PCRE2_NEVER_UCP; + overall_options &= ~PCRE2_NEVER_UCP; + } + + if ((compile_options|overall_options) != 0) + { + if (compile_options == overall_options) + show_compile_options(clr_none, compile_options, "Options:", "\n"); + else + { + show_compile_options(clr_none, compile_options, "Compile options:", "\n"); + show_compile_options(clr_none, overall_options, "Overall options:", "\n"); + } + } + + if (extra_options != 0) + show_compile_extra_options(clr_none, extra_options, "Extra options:", "\n"); + + if (compiled_code->optimization_flags != PCRE2_OPTIMIZATION_ALL) + show_optimize_flags(clr_none, compiled_code->optimization_flags, "Optimizations: ", "\n"); + + if (jchanged) fprintf(outfile, "Duplicate name status changes\n"); + + if ((pat_patctl.control2 & CTL2_BSR_SET) != 0 || + (compiled_code->flags & PCRE2_BSR_SET) != 0) + fprintf(outfile, "\\R matches %s\n", (bsr_convention == PCRE2_BSR_UNICODE)? + "any Unicode newline" : "CR, LF, or CRLF"); + + if ((compiled_code->flags & PCRE2_NL_SET) != 0) + { + switch (newline_convention) + { + case PCRE2_NEWLINE_CR: + fprintf(outfile, "Forced newline is CR\n"); + break; + + case PCRE2_NEWLINE_LF: + fprintf(outfile, "Forced newline is LF\n"); + break; + + case PCRE2_NEWLINE_CRLF: + fprintf(outfile, "Forced newline is CRLF\n"); + break; + + case PCRE2_NEWLINE_ANYCRLF: + fprintf(outfile, "Forced newline is CR, LF, or CRLF\n"); + break; + + case PCRE2_NEWLINE_ANY: + fprintf(outfile, "Forced newline is any Unicode newline\n"); + break; + + case PCRE2_NEWLINE_NUL: + fprintf(outfile, "Forced newline is NUL\n"); + break; + + default: + break; + } + } + + if (first_ctype == 2) + { + fprintf(outfile, "First code unit at start or follows newline\n"); + } + else if (first_ctype == 1) + { + const char *caseless = + ((compiled_code->flags & PCRE2_FIRSTCASELESS) == 0)? + "" : " (caseless)"; + if (first_cunit != 0xff && PRINTABLE(first_cunit)) + fprintf(outfile, "First code unit = \'%c\'%s\n", CHAR_OUTPUT(first_cunit), + caseless); + else + { + fprintf(outfile, "First code unit = "); + if (first_cunit == 0xff) + fprintf(outfile, "\\xff"); + else + pchar(first_cunit, FALSE, outfile); + fprintf(outfile, "%s\n", caseless); + } + } + else if (start_bits != NULL) + { + int input; + int c = 24; + fprintf(outfile, "Starting code units:"); + for (input = 0; input < 256; input++) + { + int i = CHAR_INPUT_HEX(input); + if ((start_bits[i/8] & (1u << (i&7))) != 0) + { + if (c > 75) + { + fprintf(outfile, "\n "); + c = 2; + } + if (PRINTABLE(i) && i != CHAR_SPACE) + { + fprintf(outfile, " %c", CHAR_OUTPUT(i)); + c += 2; + } + else + { + fprintf(outfile, " \\x%02x", CHAR_OUTPUT_HEX(i)); + c += 5; + } + } + } + fprintf(outfile, "\n"); + } + + if (last_ctype != 0) + { + const char *caseless = + ((compiled_code->flags & PCRE2_LASTCASELESS) == 0)? + "" : " (caseless)"; + if (PRINTABLE(last_cunit)) + fprintf(outfile, "Last code unit = \'%c\'%s\n", CHAR_OUTPUT(last_cunit), + caseless); + else + { + fprintf(outfile, "Last code unit = "); + pchar(last_cunit, FALSE, outfile); + fprintf(outfile, "%s\n", caseless); + } + } + + if ((compiled_code->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) + fprintf(outfile, "Subject length lower bound = %d\n", minlength); + + if (pat_patctl.jit != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0) + { +#ifdef SUPPORT_JIT + if (compiled_code->executable_jit != NULL) + fprintf(outfile, "JIT compilation was successful\n"); + else + { + cfprintf(clr_api_error, outfile, "JIT compilation was not successful"); + if (jitrc != 0 && !print_error_message(jitrc, " (", ")")) + return PR_ABEND; + fprintf(outfile, "\n"); + } +#else + cfprintf(clr_api_error, outfile, "JIT support is not available in this version of PCRE2\n"); +#endif + } + } + +rc = pcre2_callout_enumerate(compiled_code, + ((pat_patctl.control & CTL_CALLOUT_INFO) != 0)? callout_enumerate_function : + /* Exercise the callout enumeration code with a dummy callback to make sure + it works. */ + callout_enumerate_function_void, NULL); +if (rc != 0) + { + cfprintf(clr_api_error, outfile, "Callout enumerate failed: error %d: ", rc); + if (rc < 0 && !print_error_message(rc, "", "\n")) + return PR_ABEND; + return PR_SKIP; + } + +return PR_OK; +} + + + +/************************************************* +* Handle serialization error * +*************************************************/ + +/* Print an error message after a serialization failure. + +Arguments: + rc the error code + msg an initial message for what failed + +Returns: FALSE if print_error_message() fails +*/ + +static BOOL +serial_error(int rc, const char *msg) +{ +cfprintf(clr_api_error, outfile, "%s failed: error %d: ", msg, rc); +return print_error_message(rc, "", "\n"); +} + + + +/************************************************* +* Process command line * +*************************************************/ + +/* This function is called for lines beginning with # and a character that is +not ! or whitespace, when encountered between tests, which means that there is +no compiled pattern (compiled_code is NULL). The line is in buffer. + +Arguments: none + +Returns: PR_OK continue processing next line + PR_SKIP skip to a blank line + PR_ABEND abort the pcre2test run +*/ + +static int +process_command(void) +{ +FILE *f; +PCRE2_SIZE serial_size; +size_t i; +int rc, cmd, yield; +uint16_t first_listed_newline; +const char *cmdname; +size_t cmdlen; +uint8_t *argptr, *serial; +BOOL if_inverted; + +yield = PR_OK; +cmd = CMD_UNKNOWN; +cmdlen = 0; + +for (i = 0; i < cmdlistcount; i++) + { + cmdname = cmdlist[i].name; + cmdlen = strlen(cmdname); + if (strncmp((char *)(buffer+1), cmdname, cmdlen) == 0 && + (buffer[cmdlen+1] == 0 || isspace(buffer[cmdlen+1]))) + { + cmd = cmdlist[i].value; + break; + } + } + +if (preprocess_only && cmd != CMD_IF && cmd != CMD_ENDIF) + return PR_OK; + +argptr = buffer + cmdlen + 1; + +if (restrict_for_perl_test && cmd != CMD_PATTERN && cmd != CMD_SUBJECT && + cmd != CMD_IF && cmd != CMD_ENDIF) + { + cfprintf(clr_test_error, outfile, "** #%s is not allowed after #perltest\n", cmdname); + return PR_ABEND; + } + +switch(cmd) + { + case CMD_UNKNOWN: + cfprintf(clr_test_error, outfile, "** Unknown command: %s", buffer); + break; + + case CMD_FORBID_UTF: + forbid_utf = PCRE2_NEVER_UTF|PCRE2_NEVER_UCP; + break; + + case CMD_PERLTEST: + restrict_for_perl_test = TRUE; + break; + + /* Set default pattern modifiers */ + + case CMD_PATTERN: + (void)decode_modifiers(argptr, CTX_DEFPAT, &def_patctl, NULL); + if (def_patctl.jit == 0 && (def_patctl.control & CTL_JITVERIFY) != 0) + def_patctl.jit = JIT_DEFAULT; + break; + + /* Set default subject modifiers */ + + case CMD_SUBJECT: + (void)decode_modifiers(argptr, CTX_DEFDAT, NULL, &def_datctl); + break; + + /* Check the default newline, and if not one of those listed, set up the + first one to be forced. An empty list unsets. */ + + case CMD_NEWLINE_DEFAULT: + local_newline_default = 0; /* Unset */ + first_listed_newline = 0; + for (;;) + { + while (isspace(*argptr)) argptr++; + if (*argptr == 0) break; + for (uint16_t j = 1; j < sizeof(newlines)/sizeof(char *); j++) + { + size_t nlen = strlen(newlines[j]); + if (strncmpic(argptr, (const uint8_t *)newlines[j], nlen) == 0 && + isspace(argptr[nlen])) + { + if (j == NEWLINE_DEFAULT) return PR_OK; /* Default is valid */ + if (first_listed_newline == 0) first_listed_newline = j; + } + } + while (*argptr != 0 && !isspace(*argptr)) argptr++; + } + local_newline_default = first_listed_newline; + break; + + /* Pop or copy a compiled pattern off the stack. Modifiers that do not affect + the compiled pattern (e.g. to give information) are permitted. The default + pattern modifiers are ignored. */ + + case CMD_POP: + case CMD_POPCOPY: + if (patstacknext <= 0) + { + cfprintf(clr_test_error, outfile, "** Can't pop off an empty stack\n"); + return PR_SKIP; + } + patctl_zero(&pat_patctl); /* Completely unset */ + if (!decode_modifiers(argptr, CTX_POPPAT, &pat_patctl, NULL)) + return PR_SKIP; + + if (cmd == CMD_POP) + { + compiled_code = patstack[--patstacknext]; + } + else + { + compiled_code = pcre2_code_copy(patstack[patstacknext - 1]); + } + + if (pat_patctl.jit != 0) + { + jitrc = pcre2_jit_compile(compiled_code, pat_patctl.jit); + } + + rc = show_pattern_info(); + if (rc != PR_OK) return rc; + break; + + /* Save the stack of compiled patterns to a file, then empty the stack. */ + + case CMD_SAVE: + if (patstacknext <= 0) + { + cfprintf(clr_test_error, outfile, "** No stacked patterns to save\n"); + return PR_OK; + } + + rc = open_file(argptr+1, BINARY_OUTPUT_MODE, &f, "#save"); + if (rc != PR_OK) return rc; + + rc = pcre2_serialize_encode((const pcre2_code **)patstack, patstacknext, + &serial, &serial_size, general_context); + if (rc < 0) + { + fclose(f); + if (!serial_error(rc, "Serialization")) return PR_ABEND; + break; + } + + /* Write the length at the start of the file to make it straightforward to + get the right memory when re-loading. This saves having to read the file size + in different operating systems. To allow for different endianness (even + though reloading with the opposite endianness does not work), write the + length byte-by-byte. */ + + for (i = 0; i < 4; i++) fputc((serial_size >> (i*8)) & 255, f); + if (fwrite(serial, 1, serial_size, f) != serial_size) + { + cfprintf(clr_test_error, outfile, "** Wrong return from fwrite()\n"); + fclose(f); + return PR_ABEND; + } + + fclose(f); + pcre2_serialize_free(serial); + while(patstacknext > 0) + { + compiled_code = patstack[--patstacknext]; + pcre2_code_free(compiled_code); + } + compiled_code = NULL; + break; + + /* Load a set of compiled patterns from a file onto the stack */ + + case CMD_LOAD: + rc = open_file(argptr+1, BINARY_INPUT_MODE, &f, "#load"); + if (rc != PR_OK) return rc; + + serial_size = 0; + for (i = 0; i < 4; i++) serial_size |= fgetc(f) << (i*8); + + serial = malloc(serial_size); + if (serial == NULL) + { + cfprintf(clr_test_error, outfile, "** Failed to get memory (size %" SIZ_FORM ") for #load\n", + serial_size); + fclose(f); + return PR_ABEND; + } + + i = fread(serial, 1, serial_size, f); + fclose(f); + + if (i != serial_size) + { + cfprintf(clr_test_error, outfile, "** Wrong return from fread()\n"); + yield = PR_ABEND; + } + else + { + rc = pcre2_serialize_get_number_of_codes(serial); + if (rc < 0) + { + if (!serial_error(rc, "Get number of codes")) yield = PR_ABEND; + } + else + { + if (rc + patstacknext > PATSTACKSIZE) + { + cfprintf(clr_test_error, outfile, "** Not enough space on pattern stack for %d pattern%s\n", + rc, (rc == 1)? "" : "s"); + rc = PATSTACKSIZE - patstacknext; + cfprintf(clr_test_error, outfile, "** Decoding %d pattern%s\n", rc, + (rc == 1)? "" : "s"); + } + rc = pcre2_serialize_decode(patstack + patstacknext, rc, serial, + general_context); + if (rc < 0) + { + if (!serial_error(rc, "Deserialization")) yield = PR_ABEND; + } + else patstacknext += rc; + } + } + + free(serial); + break; + + /* Load a set of binary tables into tables3. */ + + case CMD_LOADTABLES: + rc = open_file(argptr+1, BINARY_INPUT_MODE, &f, "#loadtables"); + if (rc != PR_OK) return rc; + + if (tables3 == NULL) + { + int r; + r = pcre2_config(PCRE2_CONFIG_TABLES_LENGTH, &loadtables_length); + if (r >= 0) tables3 = malloc(loadtables_length); + } + + if (tables3 == NULL) + { + cfprintf(clr_test_error, outfile, "** Failed: malloc/config for #loadtables\n"); + yield = PR_ABEND; + } + else if (fread(tables3, 1, loadtables_length, f) != loadtables_length) + { + cfprintf(clr_test_error, outfile, "** Wrong return from fread()\n"); + yield = PR_ABEND; + } + + fclose(f); + break; + + case CMD_IF: + if (inside_if) + { + cfprintf(clr_test_error, outfile, "** Nested #if not supported\n"); + return PR_ABEND; + } + + while (isspace(*argptr)) argptr++; + if_inverted = FALSE; + if (*argptr == '!') + { + argptr++; + if_inverted = TRUE; + } + while (isspace(*argptr)) argptr++; + for (i = 0; i < COPTLISTCOUNT; i++) + { + size_t optlen = strlen(coptlist[i].name); + const uint8_t *argptr_trail; + if (coptlist[i].type != CONF_FIX) + continue; + if (strncmp((const char*)argptr, coptlist[i].name, optlen) != 0) + continue; + argptr_trail = argptr + optlen; + while (isspace(*argptr_trail)) argptr_trail++; + if (*argptr_trail == 0 || *argptr_trail == '\n') + break; + } + if (i == COPTLISTCOUNT) + { + cfprintf(clr_test_error, outfile, "** Unknown condition: %s\n", buffer); + return PR_ABEND; + } + + /* Condition FALSE - skip this line and everything until #endif. */ + if ((coptlist[i].value != 0) == if_inverted) + yield = PR_ENDIF; + + inside_if = TRUE; + break; + + case CMD_ENDIF: + if (!inside_if) + { + cfprintf(clr_test_error, outfile, "** Unexpected #endif\n"); + return PR_ABEND; + } + inside_if = FALSE; + break; + } + +return yield; +} + + + +/************************************************* +* Process pattern line * +*************************************************/ + +/* This function is called when the input buffer contains the start of a +pattern. The first character is known to be a valid delimiter. The pattern is +read, modifiers are interpreted, and a suitable local context is set up for +this test. The pattern is then compiled. + +Arguments: none + +Returns: PR_OK continue processing next line + PR_SKIP skip to a blank line + PR_ABEND abort the pcre2test run +*/ + +static int +process_pattern(void) +{ +BOOL utf; +uint32_t k; +uint8_t *p = buffer; +unsigned int delimiter = *p++; +int rc, errorcode; +pcre2_compile_context *use_pat_context; +PCRE2_SPTR use_pbuffer; +uint32_t use_forbid_utf = forbid_utf; +PCRE2_SIZE patlen, full_patlen; +PCRE2_SIZE valgrind_access_length; +PCRE2_SIZE erroroffset; + +/* The perltest.sh script supports only / as a delimiter. */ + +if (restrict_for_perl_test && delimiter != '/') + { + cfprintf(clr_test_error, outfile, "** The only allowed delimiter after #perltest is '/'\n"); + return PR_ABEND; + } + +/* Initialize the context and pattern/data controls for this test from the +defaults. */ + +memcpy(pat_context, default_pat_context, sizeof(pcre2_compile_context)); +memcpy(&pat_patctl, &def_patctl, sizeof(patctl)); + +/* Find the end of the pattern, reading more lines if necessary. */ + +for(;;) + { + while (*p != 0) + { + if (*p == '\\' && p[1] != 0) p++; + else if (*p == delimiter) break; + p++; + } + if (*p != 0) break; + if ((p = extend_inputline(infile, p, " > ")) == NULL) + { + cfprintf(clr_test_error, outfile, "** Unexpected EOF\n"); + return PR_ABEND; + } + if (!INTERACTIVE(infile)) cfprintf(clr_input, outfile, "%s", (char *)p); + } + +/* If the first character after the delimiter is backslash, make the pattern +end with backslash. This is purely to provide a way of testing for the error +message when a pattern ends with backslash. */ + +if (p[1] == '\\') *p++ = '\\'; + +/* Terminate the pattern at the delimiter, and compute the length. */ + +*p++ = 0; +patlen = p - buffer - 2; + +/* Look for modifiers and options after the final delimiter. */ + +if (!decode_modifiers(p, CTX_PAT, &pat_patctl, NULL)) return PR_SKIP; + +/* Note that the match_invalid_utf option also sets utf when passed to +pcre2_compile(). */ + +utf = (pat_patctl.options & (PCRE2_UTF|PCRE2_MATCH_INVALID_UTF)) != 0; + +/* The utf8_input modifier is not allowed in 8-bit mode, and is mutually +exclusive with the utf modifier. */ + +if ((pat_patctl.control & CTL_UTF8_INPUT) != 0) + { +#if PCRE2_CODE_UNIT_WIDTH == 8 + cfprintf(clr_test_error, outfile, "** The utf8_input modifier is not allowed in 8-bit mode\n"); + return PR_SKIP; +#else + if (utf) + { + cfprintf(clr_test_error, outfile, "** The utf and utf8_input modifiers are mutually exclusive\n"); + return PR_SKIP; + } +#endif + } + +/* The convert and posix modifiers are mutually exclusive. */ + +if (pat_patctl.convert_type != CONVERT_UNSET && + (pat_patctl.control & CTL_POSIX) != 0) + { + cfprintf(clr_test_error, outfile, "** The convert and posix modifiers are mutually exclusive\n"); + return PR_SKIP; + } + +/* Check for mutually exclusive control modifiers. At present, these are all in +the first control word. */ + +for (k = 0; k < sizeof(exclusive_pat_controls)/sizeof(uint32_t); k++) + { + uint32_t c = pat_patctl.control & exclusive_pat_controls[k]; + if (c != 0 && c != (c & (~c+1))) + { + show_controls(clr_test_error, c, 0, "** Not allowed together:"); + fprintf(outfile, "\n"); + return PR_SKIP; + } + } + +/* Assume full JIT compile for jitverify and/or jitfast if nothing else was +specified. */ + +if (pat_patctl.jit == 0 && + (pat_patctl.control & (CTL_JITVERIFY|CTL_JITFAST)) != 0) + pat_patctl.jit = JIT_DEFAULT; + +/* Now copy the pattern to pbuffer8 for use in 8-bit testing. Convert from hex +if requested (literal strings in quotes may be present within the hexadecimal +pairs). The result must necessarily be fewer characters so will always fit in +pbuffer8. */ + +if ((pat_patctl.control & CTL_HEXPAT) != 0) + { + uint8_t *pp, *pt; + uint32_t c, d; + + pt = pbuffer8; + for (pp = buffer + 1; *pp != 0; pp++) + { + if (isspace(*pp)) continue; + c = *pp++; + + /* Handle a literal substring */ + + if (c == '\'' || c == '"') + { + uint8_t *pq = pp; + for (;; pp++) + { + d = *pp; + if (d == 0) + { + cfprintf(clr_test_error, outfile, "** Missing closing quote in hex pattern: " + "opening quote is at offset %" PTR_FORM ".\n", pq - buffer - 2); + return PR_SKIP; + } + if (d == c) break; + *pt++ = d; + } + } + + /* Expect a hex pair */ + + else + { + if (!isxdigit(c)) + { + cfprintf(clr_test_error, outfile, "** Unexpected non-hex-digit '%c' at offset %" + PTR_FORM " in hex pattern: quote missing?\n", c, pp - buffer - 2); + return PR_SKIP; + } + if (*pp == 0) + { + cfprintf(clr_test_error, outfile, "** Odd number of digits in hex pattern\n"); + return PR_SKIP; + } + d = *pp; + if (!isxdigit(d)) + { + cfprintf(clr_test_error, outfile, "** Unexpected non-hex-digit '%c' at offset %" + PTR_FORM " in hex pattern: quote missing?\n", d, pp - buffer - 1); + return PR_SKIP; + } + c = toupper(c); + d = toupper(d); + c = isdigit(c)? (c - '0') : (c - 'A' + 10); + d = isdigit(d)? (d - '0') : (d - 'A' + 10); + *pt++ = CHAR_OUTPUT(CHAR_INPUT_HEX((c << 4) + d)); + } + } + *pt = 0; + patlen = pt - pbuffer8; + } + +/* If not a hex string, process for repetition expansion if requested. */ + +else if ((pat_patctl.control & CTL_EXPAND) != 0) + { + uint8_t *pp, *pt; + + pt = pbuffer8; + for (pp = buffer + 1; *pp != 0; pp++) + { + uint8_t *pc = pp; + uint32_t count = 1; + size_t length = 1; + + /* Check for replication syntax; if not found, the defaults just set will + prevail and one character will be copied. */ + + if (pp[0] == '\\' && pp[1] == '[') + { + uint8_t *pe; + for (pe = pp + 2; *pe != 0; pe++) + { + if (pe[0] == ']' && pe[1] == '{') + { + size_t clen = pe - pc - 2; + uint32_t i = 0; + unsigned long uli; + char *endptr; + + pe += 2; + uli = strtoul((const char *)pe, &endptr, 10); + if (U32OVERFLOW(uli)) + { + cfprintf(clr_test_error, outfile, "** Pattern repeat count too large\n"); + return PR_SKIP; + } + + i = (uint32_t)uli; + pe = (uint8_t *)endptr; + if (*pe == '}') + { + if (i == 0) + { + cfprintf(clr_test_error, outfile, "** Zero repeat not allowed\n"); + return PR_SKIP; + } + pc += 2; + count = i; + length = clen; + pp = pe; + break; + } + } + } + } + + /* Add to output. If the buffer is too small expand it. The function for + expanding buffers always keeps buffer and pbuffer8 in step as far as their + size goes. */ + + while (pt + count * length > pbuffer8 + pbuffer8_size) + { + size_t pc_offset = pc - buffer; + size_t pp_offset = pp - buffer; + size_t pt_offset = pt - pbuffer8; + expand_input_buffers(); + pc = buffer + pc_offset; + pp = buffer + pp_offset; + pt = pbuffer8 + pt_offset; + } + + for (; count > 0; count--) + { + memcpy(pt, pc, length); + pt += length; + } + } + + *pt = 0; + patlen = pt - pbuffer8; + + if ((pat_patctl.control & CTL_INFO) != 0) + fprintf(outfile, "Expanded: %s\n", pbuffer8); + } + +/* Neither hex nor expanded, just copy the input verbatim. */ + +else + { + strncpy((char *)pbuffer8, (char *)(buffer+1), patlen + 1); + } + +/* Sort out character tables */ + +if (pat_patctl.locale[0] != MOD_STR_UNSET) + { + if (pat_patctl.tables_id != 0) + { + cfprintf(clr_test_error, outfile, "** 'Locale' and 'tables' must not both be set\n"); + return PR_SKIP; + } + if (setlocale(LC_CTYPE, (const char *)pat_patctl.locale+1) == NULL) + { + cfprintf(clr_test_error, outfile, "** Failed to set locale \"%s\"\n", pat_patctl.locale+1); + return PR_SKIP; + } + if (strcmp((const char *)pat_patctl.locale+1, (const char *)locale_name) != 0) + { + strncpy((char *)locale_name, (char *)pat_patctl.locale + 1, sizeof(locale_name)); + locale_name[sizeof(locale_name) - 1] = '\0'; + if (locale_tables != NULL) + { + pcre2_maketables_free(general_context, locale_tables); + } + locale_tables = pcre2_maketables(general_context); + } + use_tables = locale_tables; + } + +else switch (pat_patctl.tables_id) + { + case 0: use_tables = NULL; break; + case 1: use_tables = tables1; break; + case 2: use_tables = tables2; break; + + case 3: + if (tables3 == NULL) + { + cfprintf(clr_test_error, outfile, "** 'Tables = 3' is invalid: binary tables have not " + "been loaded\n"); + return PR_SKIP; + } + use_tables = tables3; + break; + + default: + cfprintf(clr_test_error, outfile, "** 'Tables' must specify 0, 1, 2, or 3.\n"); + return PR_SKIP; + } + +pcre2_set_character_tables(pat_context, use_tables); + +/* Set up for the stackguard test. */ + +if (pat_patctl.stackguard_test != 0) + { + pcre2_set_compile_recursion_guard(pat_context, stack_guard, NULL); + } + +/* Handle compiling via the POSIX interface, which doesn't support the +timing, showing, or debugging options, nor the ability to pass over +local character tables. Neither does it have 16-bit or 32-bit support. */ + +if ((pat_patctl.control & CTL_POSIX) != 0) + { +#if PCRE2_CODE_UNIT_WIDTH != 8 + cfprintf(clr_test_error, outfile, "** The POSIX interface is available only in 8-bit mode\n"); + return PR_SKIP; + +#else + int cflags = 0; + const char *msg = "** Ignored with POSIX interface:"; + + /* Check for features that the POSIX interface does not support. */ + + if (pat_patctl.locale[0] != MOD_STR_UNSET) prmsg(&msg, "locale"); + if (pat_patctl.replacement[0] != MOD_STR_UNSET) prmsg(&msg, "replace"); + if (pat_patctl.tables_id != 0) prmsg(&msg, "tables"); + if (pat_patctl.stackguard_test != 0) prmsg(&msg, "stackguard"); + if (timeit > 0) prmsg(&msg, "timing"); + if (pat_patctl.jit != 0) prmsg(&msg, "JIT"); + + if ((pat_patctl.options & ~POSIX_SUPPORTED_COMPILE_OPTIONS) != 0) + { + show_compile_options( + clr_test_error, + pat_patctl.options & (uint32_t)(~POSIX_SUPPORTED_COMPILE_OPTIONS), + msg, ""); + msg = ""; + } + + if ((pat_context->extra_options & + (uint32_t)(~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS)) != 0) + { + show_compile_extra_options( + clr_test_error, + pat_context->extra_options & + (uint32_t)(~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS), + msg, ""); + msg = ""; + } + + if ((pat_patctl.control & (uint32_t)(~POSIX_SUPPORTED_COMPILE_CONTROLS)) != 0 || + (pat_patctl.control2 & (uint32_t)(~POSIX_SUPPORTED_COMPILE_CONTROLS2)) != 0) + { + show_controls( + clr_test_error, + pat_patctl.control & (uint32_t)(~POSIX_SUPPORTED_COMPILE_CONTROLS), + pat_patctl.control2 & (uint32_t)(~POSIX_SUPPORTED_COMPILE_CONTROLS2), + msg); + msg = ""; + + /* Remove ignored options so as not to get a repeated message for those + that are actually subject controls. */ + + pat_patctl.control &= (uint32_t)(POSIX_SUPPORTED_COMPILE_CONTROLS); + pat_patctl.control2 &= (uint32_t)(POSIX_SUPPORTED_COMPILE_CONTROLS2); + } + + if (local_newline_default != 0) prmsg(&msg, "#newline_default"); + if (pat_context->max_pattern_length != PCRE2_UNSET) + prmsg(&msg, "max_pattern_length"); + if (pat_context->max_pattern_compiled_length != PCRE2_UNSET) + prmsg(&msg, "max_pattern_compiled_length"); + if (pat_context->parens_nest_limit != PARENS_NEST_DEFAULT) + prmsg(&msg, "parens_nest_limit"); + + if (msg[0] == 0) fprintf(outfile, "\n"); + + /* Translate PCRE2 options to POSIX options and then compile. */ + + if (utf) cflags |= REG_UTF; + if ((pat_patctl.control & CTL_POSIX_NOSUB) != 0) cflags |= REG_NOSUB; + if ((pat_patctl.options & PCRE2_UCP) != 0) cflags |= REG_UCP; + if ((pat_patctl.options & PCRE2_CASELESS) != 0) cflags |= REG_ICASE; + if ((pat_patctl.options & PCRE2_LITERAL) != 0) cflags |= REG_NOSPEC; + if ((pat_patctl.options & PCRE2_MULTILINE) != 0) cflags |= REG_NEWLINE; + if ((pat_patctl.options & PCRE2_DOTALL) != 0) cflags |= REG_DOTALL; + if ((pat_patctl.options & PCRE2_UNGREEDY) != 0) cflags |= REG_UNGREEDY; + + if ((pat_patctl.control & (CTL_HEXPAT|CTL_USE_LENGTH)) != 0) + { + preg.re_endp = (char *)pbuffer8 + patlen; + cflags |= REG_PEND; + } + +#if defined(EBCDIC) && !EBCDIC_IO + ascii_to_ebcdic_str(pbuffer8, patlen); +#endif + + rc = regcomp(&preg, (char *)pbuffer8, cflags); + + /* Compiling failed */ + + if (rc != 0) + { + char *regbuffer; + size_t bsize, usize, strsize; + + preg.re_pcre2_code = NULL; /* In case something was left in there */ + preg.re_match_data = NULL; + + bsize = (pat_patctl.regerror_buffsize >= 0 && + (unsigned)pat_patctl.regerror_buffsize <= pbuffer8_size)? + (unsigned)pat_patctl.regerror_buffsize : pbuffer8_size; + regbuffer = (char *)pbuffer8 + (pbuffer8_size - bsize); + usize = regerror(rc, &preg, regbuffer, bsize); + strsize = ((usize > bsize)? bsize : usize) - 1; + + cfprintf(clr_api_error, outfile, "Failed: POSIX code %d: ", rc); + if (bsize > 0) pchars(clr_api_error, (PCRE2_SPTR8)regbuffer, strsize, utf, outfile); + fputs("\n", outfile); + if (usize > bsize) + { + cfprintf(clr_test_error, outfile, "** regerror() message truncated\n"); + } + if (bsize > 0 && strlen(regbuffer) != strsize) + { + cfprintf(clr_test_error, outfile, "** regerror() strlen incorrect\n"); + return PR_ABEND; + } + return PR_SKIP; + } + + /* Compiling succeeded. Check that the values in the preg block are sensible. + It can happen that pcre2test is accidentally linked with a different POSIX + library which succeeds, but of course puts different things into preg. In + this situation, calling regfree() may cause a segfault (or invalid free() in + valgrind), so ensure that preg.re_pcre2_code is NULL, which suppresses the + calling of regfree() on exit. */ + + if (preg.re_pcre2_code == NULL || + ((pcre2_real_code_8 *)preg.re_pcre2_code)->magic_number != MAGIC_NUMBER || + ((pcre2_real_code_8 *)preg.re_pcre2_code)->top_bracket != preg.re_nsub || + preg.re_match_data == NULL || + preg.re_cflags != cflags) + { + cfprintf(clr_test_error, outfile, + "** The regcomp() function returned zero (success), but the values set\n" + "** in the preg block are not valid for PCRE2. Check that pcre2test is\n" + "** linked with PCRE2's pcre2posix module (-lpcre2-posix) and not with\n" + "** some other POSIX regex library.\n**\n"); + preg.re_pcre2_code = NULL; + return PR_ABEND; + } + + return PR_OK; +#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */ + } + +/* Handle compiling via the native interface. Controls that act later are +ignored with "push". Replacements are locked out. */ + +if ((pat_patctl.control & (CTL_PUSH|CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0) + { + if (pat_patctl.replacement[0] != MOD_STR_UNSET) + { + cfprintf(clr_test_error, outfile, "** Replacement text is not supported with 'push'.\n"); + return PR_OK; + } + if ((pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS) != 0 || + (pat_patctl.control2 & ~PUSH_SUPPORTED_COMPILE_CONTROLS2) != 0) + { + show_controls(clr_test_error, pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS, + pat_patctl.control2 & ~PUSH_SUPPORTED_COMPILE_CONTROLS2, + "** Ignored when compiled pattern is stacked with 'push':"); + fprintf(outfile, "\n"); + } + if ((pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS) != 0 || + (pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2) != 0) + { + show_controls(clr_test_error, pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS, + pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2, + "** Applies only to compile when pattern is stacked with 'push':"); + fprintf(outfile, "\n"); + } + } + +/* Convert the input in non-8-bit modes. */ + +errorcode = 0; + +#if defined(EBCDIC) && !EBCDIC_IO +ascii_to_ebcdic_str(pbuffer8, patlen); +#endif + +#if PCRE2_CODE_UNIT_WIDTH != 8 +errorcode = G(to,PCRE2_CODE_UNIT_WIDTH)(pbuffer8, utf, &patlen); +switch(errorcode) + { + case -1: + cfprintf(clr_test_error, outfile, "** Failed: invalid UTF-8 string cannot be " + "converted to " STR(PCRE2_CODE_UNIT_WIDTH) "-bit string\n"); + return PR_SKIP; + + case -2: + cfprintf(clr_test_error, outfile, "** Failed: character value greater than 0x10ffff " + "cannot be converted to UTF\n"); + return PR_SKIP; + + case -3: + cfprintf(clr_test_error, outfile, "** Failed: character value greater than 0xffff " + "cannot be converted to 16-bit in non-UTF mode\n"); + return PR_SKIP; + + default: + break; + } +#endif + +/* When valgrind is supported, detect accesses to the 8-bit buffer now that we +have finished with it. */ + +#if defined SUPPORT_VALGRIND && PCRE2_CODE_UNIT_WIDTH != 8 +VALGRIND_MAKE_MEM_UNDEFINED(pbuffer8, pbuffer8_size); +#endif + +/* The pattern is now in pbuffer[8|16|32], with the length in code units in +patlen. If it is to be converted, copy the result back afterwards so that it +ends up back in the usual place. */ + +if (pat_patctl.convert_type != CONVERT_UNSET) + { + int convert_return = PR_OK; + uint32_t convert_options = pat_patctl.convert_type; + PCRE2_UCHAR *converted_pattern; + PCRE2_SIZE converted_length = JUNK_OFFSET; + BOOL zero_terminate; + + if (pat_patctl.convert_length != CONVERT_UNSET) + { + converted_length = pat_patctl.convert_length; + converted_pattern = malloc(converted_length? CU2BYTES(converted_length) : 1); + if (converted_pattern == NULL) + { + cfprintf(clr_test_error, outfile, "** Failed: malloc failed for converted pattern\n"); + return PR_ABEND; + } + } + else converted_pattern = NULL; /* Let the library allocate */ + + if (utf) convert_options |= PCRE2_CONVERT_UTF; + if ((pat_patctl.options & PCRE2_NO_UTF_CHECK) != 0) + convert_options |= PCRE2_CONVERT_NO_UTF_CHECK; + + memcpy(con_context, default_con_context, sizeof(pcre2_convert_context)); + + if (pat_patctl.convert_glob_escape != 0) + { + uint32_t escape = (pat_patctl.convert_glob_escape == '0')? 0 : + pat_patctl.convert_glob_escape; + rc = pcre2_set_glob_escape(con_context, CHAR_INPUT(escape)); + if (rc != 0) + { + cfprintf(clr_test_error, outfile, "** Invalid glob escape '%c'\n", + pat_patctl.convert_glob_escape); + convert_return = PR_SKIP; + goto CONVERT_FINISH; + } + } + + if (pat_patctl.convert_glob_separator != 0) + { + uint32_t separator = pat_patctl.convert_glob_separator; + rc = pcre2_set_glob_separator(con_context, CHAR_INPUT(separator)); + if (rc != 0) + { + cfprintf(clr_test_error, outfile, "** Invalid glob separator '%c'\n", + pat_patctl.convert_glob_separator); + convert_return = PR_SKIP; + goto CONVERT_FINISH; + } + } + + /* Set up the input buffer in the same way as for pcre2_compile() below. */ + + zero_terminate = (pat_patctl.control & (CTL_HEXPAT|CTL_USE_LENGTH)) == 0; + +#ifdef SUPPORT_VALGRIND + VALGRIND_MAKE_MEM_NOACCESS(pbuffer + CU2BYTES(patlen + zero_terminate), + pbuffer_size - CU2BYTES(patlen + zero_terminate)); +#endif + + if (zero_terminate) patlen = PCRE2_ZERO_TERMINATED; + use_pbuffer = ((pat_patctl.control2 & CTL2_NULL_PATTERN) == 0)? pbuffer : NULL; + + rc = pcre2_pattern_convert(use_pbuffer, patlen, convert_options, + &converted_pattern, &converted_length, con_context); + +#ifdef SUPPORT_VALGRIND + VALGRIND_MAKE_MEM_UNDEFINED(pbuffer, pbuffer_size); +#endif + + if (rc != 0) + { + cfprintf(clr_api_error, outfile, "** Pattern conversion error at offset %" SIZ_FORM ": ", + converted_length); + convert_return = print_error_message(rc, "", "\n")? PR_SKIP:PR_ABEND; + } + + /* Output the converted pattern, then copy it. */ + + else + { + pchars(clr_none, converted_pattern, converted_length, utf, outfile); + fprintf(outfile, "\n"); + + if (CU2BYTES(converted_length + 1) > pbuffer_size) + { + // TODO This seems... unfortunate? There must be some patterns that can + // expand when converted from glob to regex, but we aren't allowing for + // that here. Presumably we should expand the buffer rather than moan. + cfprintf(clr_test_error, outfile, "** Pattern conversion is too long for the buffer\n"); + convert_return = PR_SKIP; + } + else + { + memcpy(pbuffer, converted_pattern, CU2BYTES(converted_length + 1)); + patlen = converted_length; + } + } + + /* Free the converted pattern. */ + + CONVERT_FINISH: + if (pat_patctl.convert_length != CONVERT_UNSET) + free(converted_pattern); + else + pcre2_converted_pattern_free(converted_pattern); + + /* Return if conversion was unsuccessful. */ + + if (convert_return != PR_OK) return convert_return; + } + +/* By default we pass a zero-terminated pattern, but a length is passed if +"use_length" was specified or this is a hex pattern (which might contain binary +zeros). When valgrind is supported, arrange for the unused part of the buffer +to be marked as no-access. */ + +full_patlen = patlen; +valgrind_access_length = patlen; +if ((pat_patctl.control & (CTL_HEXPAT|CTL_USE_LENGTH)) == 0) + { + patlen = PCRE2_ZERO_TERMINATED; + valgrind_access_length += 1; /* For the terminating zero */ + } + +#ifdef SUPPORT_VALGRIND +VALGRIND_MAKE_MEM_NOACCESS(pbuffer + valgrind_access_length, + pbuffer_size - CU2BYTES(valgrind_access_length)); +#else /* Valgrind not supported */ +(void)valgrind_access_length; /* Avoid compiler warning */ +#endif + +/* If #newline_default has been used and the library was not compiled with an +appropriate default newline setting, local_newline_default will be non-zero. We +use this if there is no explicit newline modifier. */ + +if ((pat_patctl.control2 & CTL2_NL_SET) == 0 && local_newline_default != 0) + { + pcre2_set_newline(pat_context, local_newline_default); + } + +/* The null_context modifier is used to test calling pcre2_compile() with a +NULL context. */ + +use_pat_context = ((pat_patctl.control & CTL_NULLCONTEXT) != 0)? + NULL : pat_context; + +/* If PCRE2_LITERAL is set, set use_forbid_utf zero because PCRE2_NEVER_UTF +and PCRE2_NEVER_UCP are invalid with it. */ + +if ((pat_patctl.options & PCRE2_LITERAL) != 0) use_forbid_utf = 0; + +/* Set use_pbuffer to the input buffer or NULL as requested. */ + +use_pbuffer = ((pat_patctl.control2 & CTL2_NULL_PATTERN) == 0)? pbuffer : NULL; + +/* Compile many times when timing. */ + +if (timeit > 0) + { + int i; + clock_t time_taken = 0; + for (i = 0; i < timeit; i++) + { + clock_t start_time = clock(); + compiled_code = pcre2_compile(use_pbuffer, patlen, + pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, + use_pat_context); + time_taken += clock() - start_time; + if (compiled_code != NULL) + pcre2_code_free(compiled_code); + } + total_compile_time += time_taken; + cfprintf(clr_profiling, outfile, "Compile time %8.4f microseconds\n", + ((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit); + } + +/* A final compile that is used "for real". */ + +mallocs_called = 0; +compiled_code = pcre2_compile(use_pbuffer, patlen, + pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, use_pat_context); + +/* For malloc testing, we repeat the compilation. */ + +if (malloc_testing) + { + for (int i = 0, target_mallocs = mallocs_called; i <= target_mallocs; i++) + { + if (compiled_code != NULL) + pcre2_code_free(compiled_code); + + errorcode = 0; + erroroffset = 0; + mallocs_until_failure = i; + compiled_code = pcre2_compile(use_pbuffer, patlen, + pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, use_pat_context); + mallocs_until_failure = INT_MAX; + + if (i < target_mallocs && + !(compiled_code == NULL && errorcode == PCRE2_ERROR_HEAP_FAILED)) + { + cfprintf(clr_test_error, outfile, "** malloc() compile test did not fail as expected (%d)\n", + errorcode); + return PR_ABEND; + } + } + } + +/* If valgrind is supported, mark the pbuffer as accessible again. We leave the +pattern in the test-mode's buffer defined because it may be read from a callout +during matching. */ + +#ifdef SUPPORT_VALGRIND +VALGRIND_MAKE_MEM_UNDEFINED(pbuffer + valgrind_access_length, + pbuffer_size - CU2BYTES(valgrind_access_length)); +#endif + +/* Call the JIT compiler if requested. When timing, or testing malloc failures, +we must free and recompile the pattern each time because that is the only way to +free the JIT compiled code. We know that compilation will always succeed. */ + +if (compiled_code != NULL && pat_patctl.jit != 0) + { + if (timeit > 0) + { + int i; + clock_t time_taken = 0; + + for (i = 0; i < timeit; i++) + { + clock_t start_time = clock(); + jitrc = pcre2_jit_compile(compiled_code, pat_patctl.jit); + time_taken += clock() - start_time; + + pcre2_code_free(compiled_code); + compiled_code = pcre2_compile(use_pbuffer, patlen, + pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, + use_pat_context); + if (compiled_code == NULL) + { + cfprintf(clr_test_error, outfile, "** Unexpected - pattern compilation not successful\n"); + return PR_ABEND; + } + + if (jitrc != 0) + { + cfprintf(clr_api_error, outfile, "JIT compilation was not successful"); + if (!print_error_message(jitrc, " (", ")\n")) return PR_ABEND; + break; + } + } + total_jit_compile_time += time_taken; + if (jitrc == 0) + cfprintf(clr_profiling, outfile, "JIT compile %8.4f microseconds\n", + ((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit); + } + + mallocs_called = 0; + jitrc = pcre2_jit_compile(compiled_code, pat_patctl.jit); + + /* For malloc testing, we repeat the compilation. */ + + if (malloc_testing) + { + for (int i = 0, target_mallocs = mallocs_called; i <= target_mallocs; i++) + { + pcre2_code_free(compiled_code); + compiled_code = pcre2_compile(use_pbuffer, patlen, + pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, + use_pat_context); + if (compiled_code == NULL) + { + cfprintf(clr_test_error, outfile, "** Unexpected - pattern compilation not successful\n"); + return PR_ABEND; + } + + mallocs_until_failure = i; + jitrc = pcre2_jit_compile(compiled_code, pat_patctl.jit); + mallocs_until_failure = INT_MAX; + + if (i < target_mallocs && jitrc != PCRE2_ERROR_NOMEMORY) + { + cfprintf(clr_test_error, outfile, "** malloc() JIT compile test did not fail as expected (%d)\n", + jitrc); + return PR_ABEND; + } + } + } + + /* Check whether JIT compilation failed; but continue with an error message + if not. */ + + if (jitrc != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0) + { + cfprintf(clr_api_error, outfile, "JIT compilation was not successful"); + if (!print_error_message(jitrc, " (", ")\n")) return PR_ABEND; + } + } + +/* Compilation failed; go back for another re, skipping to blank line +if non-interactive. */ + +if (compiled_code == NULL) + { + int direction = error_direction(errorcode, erroroffset); + + cfprintf(clr_api_error, outfile, "Failed: error %d at offset %d: ", errorcode, + (int)erroroffset); + if (!print_error_message(errorcode, "", "\n")) return PR_ABEND; + + /* It's important that the erroroffset doesn't slice halfway through a UTF-8 + or UTF-16 character. We can verify this by checking that the input left of the + erroroffset is valid. Note that if the input is invalid (which is exercised in + some tests) then the offset will be positioned with the valid part to the left + of erroroffset. */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 + if (utf) + { + uint32_t cc; + int n = 1; + for (PCRE2_UCHAR *q = pbuffer, *q_end = q + erroroffset; q < q_end && n > 0; q += n) + n = utf_to_ord(q, q_end, &cc); + if (n <= 0) + { + cfprintf(clr_test_error, outfile, "** Erroroffset %d splits a UTF character\n", (int)erroroffset); + return PR_ABEND; + } + } +#endif + + /* Print the surrounding context around the erroroffset. */ + + if (direction < 0) + { + cfprintf(clr_test_error, outfile, "** Error code %d not implemented in error_direction().\n", errorcode); + cfprintf(clr_test_error, outfile, " error_direction() should usually return '1' for newly-added errors,\n"); + cfprintf(clr_test_error, outfile, " and the offset should be just to the right of the bad character.\n"); + return PR_ABEND; + } + + else if (direction != 0) + { + cfprintf(clr_api_error, outfile, " here: "); + if (erroroffset > 0) + { + ptrunc(clr_input, pbuffer, full_patlen, erroroffset, TRUE, utf, outfile); + fprintf(outfile, " "); + } + cfprintf(clr_api_error, outfile, (direction == 1)? "|<--|" : (direction == 2)? "|-->|" : "|<-->|"); + if (erroroffset < full_patlen) + { + fprintf(outfile, " "); + ptrunc(clr_input, pbuffer, full_patlen, erroroffset, FALSE, utf, outfile); + } + fprintf(outfile, "\n"); + } + + else if (erroroffset != 0) + { + cfprintf(clr_test_error, outfile, "** Unexpected non-zero erroroffset %d for error code %d\n", + (int)erroroffset, errorcode); + return PR_ABEND; + } + + return PR_SKIP; + } + +/* If forbid_utf is non-zero, we are running a non-UTF test. UTF and UCP are +locked out at compile time, but we must also check for occurrences of \P, \p, +and \X, which are only supported when Unicode is supported. */ + +if (forbid_utf != 0) + { + if ((compiled_code->flags & PCRE2_HASBKPORX) != 0) + { + cfprintf(clr_test_error, outfile, "** \\P, \\p, and \\X are not allowed after the " + "#forbid_utf command\n"); + return PR_SKIP; + } + } + +/* Remember the maximum lookbehind, for partial matching. */ + +if (pattern_info(PCRE2_INFO_MAXLOOKBEHIND, &maxlookbehind, FALSE) != 0) + return PR_ABEND; + +/* Remember the number of captures. */ + +if (pattern_info(PCRE2_INFO_CAPTURECOUNT, &maxcapcount, FALSE) < 0) + return PR_ABEND; + +/* If an explicit newline modifier was given, set the information flag in the +pattern so that it is preserved over push/pop. */ + +if ((pat_patctl.control2 & CTL2_NL_SET) != 0) + { + compiled_code->flags |= PCRE2_NL_SET; + } + +/* Output code size and other information if requested. */ + +rc = show_pattern_info(); +if (rc != PR_OK) return rc; + +/* The "push" control requests that the compiled pattern be remembered on a +stack. This is mainly for testing the serialization functionality. */ + +if ((pat_patctl.control & CTL_PUSH) != 0) + { + if (patstacknext >= PATSTACKSIZE) + { + cfprintf(clr_test_error, outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE); + return PR_ABEND; + } + patstack[patstacknext++] = compiled_code; + compiled_code = NULL; + } + +/* The "pushcopy" and "pushtablescopy" controls are similar, but push a +copy of the pattern, the latter with a copy of its character tables. This tests +the pcre2_code_copy() and pcre2_code_copy_with_tables() functions. */ + +if ((pat_patctl.control & (CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0) + { + if (patstacknext >= PATSTACKSIZE) + { + cfprintf(clr_test_error, outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE); + return PR_ABEND; + } + if ((pat_patctl.control & CTL_PUSHCOPY) != 0) + { + patstack[patstacknext++] = pcre2_code_copy(compiled_code); + } + else + { + patstack[patstacknext++] = pcre2_code_copy_with_tables(compiled_code); + } + } + +return PR_OK; +} + + + +/* Helper to test for an active pattern. */ + +static BOOL +have_active_pattern(void) +{ +return compiled_code != NULL; +} + + +/* Helper to free (and null-out) the active pattern. Safe to call even if there +is no active pattern. */ + +static void +free_active_pattern(void) +{ +pcre2_code_free(compiled_code); +compiled_code = NULL; +} + + + +/************************************************* +* Check heap, match or depth limit * +*************************************************/ + +/* This is used for DFA, normal, and JIT fast matching. For DFA matching it +should only be called with the third argument set to PCRE2_ERROR_DEPTHLIMIT. + +Arguments: + pp the subject string + ulen length of subject or PCRE2_ZERO_TERMINATED + errnumber defines which limit to test + msg string to include in final message + +Returns: the return from the final match function call +*/ + +static int +check_match_limit(PCRE2_SPTR pp, PCRE2_SIZE ulen, int errnumber, const char *msg) +{ +int capcount; +uint32_t min = 0; +uint32_t mid = 64; +uint32_t max = UINT32_MAX; +FILE *saved_outfile = outfile; + +pcre2_set_match_limit(dat_context, max); +pcre2_set_depth_limit(dat_context, max); +pcre2_set_heap_limit(dat_context, max); + +for (;;) + { + uint32_t stack_start = 0; + + /* If we are checking the heap limit, free any frames vector that is cached + in the match_data so we always start without one. */ + + if (errnumber == PCRE2_ERROR_HEAPLIMIT) + { + pcre2_set_heap_limit(dat_context, mid); + + match_data->memctl.free(match_data->heapframes, + match_data->memctl.memory_data); + match_data->heapframes = NULL; + match_data->heapframes_size = 0; + } + + /* No need to mess with the frames vector for match or depth limits. */ + + else if (errnumber == PCRE2_ERROR_MATCHLIMIT) + { + pcre2_set_match_limit(dat_context, mid); + } + else + { + pcre2_set_depth_limit(dat_context, mid); + } + + /* Do the appropriate match */ + + reset_callout_state(); + outfile = NULL; /* Suppress callout output during the repeated search */ + + if ((dat_datctl.control & CTL_DFA) != 0) + { + stack_start = DFA_START_RWS_SIZE/1024; + if (dfa_workspace == NULL) + dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int)); + if (dfa_matched++ == 0) + dfa_workspace[0] = -1; /* To catch bad restart */ + capcount = pcre2_dfa_match(compiled_code, pp, ulen, dat_datctl.offset, + dat_datctl.options, match_data, + dat_context, dfa_workspace, DFA_WS_DIMENSION); + } + + else if ((pat_patctl.control & CTL_JITFAST) != 0) + capcount = pcre2_jit_match(compiled_code, pp, ulen, dat_datctl.offset, + dat_datctl.options, match_data, dat_context); + + else + { + capcount = pcre2_match(compiled_code, pp, ulen, dat_datctl.offset, + dat_datctl.options, match_data, dat_context); + } + + outfile = saved_outfile; + + if (capcount == errnumber) + { + if ((mid & 0x80000000u) != 0) + { + cfprintf(clr_test_error, outfile, "** Can't find minimum %s limit: check pattern for " + "restriction\n", msg); + break; + } + + min = mid; + mid = (mid == max - 1)? max : (max != UINT32_MAX)? (min + max)/2 : mid*2; + } + else if (capcount >= 0 || + capcount == PCRE2_ERROR_NOMATCH || + capcount == PCRE2_ERROR_PARTIAL) + { + /* If we've not hit the error with a heap limit less than the size of the + initial stack frame vector (for pcre2_match()) or the initial stack + workspace vector (for pcre2_dfa_match()), the heap is not being used, so + the minimum limit is zero; there's no need to go on. The other limits are + always greater than zero. */ + + if (errnumber == PCRE2_ERROR_HEAPLIMIT && mid < stack_start) + { + fprintf(outfile, "Minimum %s limit = 0\n", msg); + break; + } + if (mid == min + 1) + { + fprintf(outfile, "Minimum %s limit = %d\n", msg, mid); + break; + } + max = mid; + mid = (min + max)/2; + } + else break; /* Some other error */ + } + +return capcount; +} + + + +/************************************************* +* Substitute callout function * +*************************************************/ + +/* Called from pcre2_substitute() when the substitute_callout modifier is set. +Print out the data that is passed back. + +Arguments: + scb pointer to substitute callout block + data_ptr callout data + +Returns: nothing +*/ + +static int +substitute_callout_function(pcre2_substitute_callout_block *scb, + void *data_ptr) +{ +int yield = 0; +BOOL utf = (compiled_code->overall_options & PCRE2_UTF) != 0; +(void)data_ptr; /* Not used */ + +if (outfile == NULL) goto YIELD; + +fprintf(outfile, "%2d(%d) Old %" SIZ_FORM " %" SIZ_FORM " \"", + scb->subscount, scb->oveccount, + scb->ovector[0], scb->ovector[1]); + +pchars(clr_none, scb->input + scb->ovector[0], scb->ovector[1] - scb->ovector[0], + utf, outfile); + +fprintf(outfile, "\" New %" SIZ_FORM " %" SIZ_FORM " \"", + scb->output_offsets[0], scb->output_offsets[1]); + +pchars(clr_none, scb->output + scb->output_offsets[0], + scb->output_offsets[1] - scb->output_offsets[0], utf, outfile); + +YIELD: + +if (scb->subscount == dat_datctl.substitute_stop) + { + yield = -1; + if (outfile != NULL) fprintf(outfile, " STOPPED"); + } +else if (scb->subscount == dat_datctl.substitute_skip) + { + yield = +1; + if (outfile != NULL) fprintf(outfile, " SKIPPED"); + } + +if (outfile != NULL) fprintf(outfile, "\"\n"); +return yield; +} + + + +/************************************************* +* Substitute case callout function * +*************************************************/ + +/* Called from pcre2_substitute() when the substitute_case_callout +modifier is set. The substitute callout block is not identical for all code unit +widths, so we have to duplicate the function for each supported width. + +Arguments: + input the input character + input_len the length of the input + output the output buffer + output_cap the output buffer capacity + to_case the case conversion type + data_ptr callout data (unused) + +Returns: the number of code units of the output +*/ + +static PCRE2_SIZE +substitute_case_callout_function( + PCRE2_SPTR input, PCRE2_SIZE input_len, + PCRE2_UCHAR *output, PCRE2_SIZE output_cap, + int to_case, void *data_ptr) +{ +PCRE2_UCHAR buf[16]; +PCRE2_SPTR input_copy; +PCRE2_SIZE written = 0; + +(void)data_ptr; /* Not used */ + +if (input_len > sizeof(buf)/sizeof(*buf)) + { + PCRE2_UCHAR *input_buf = malloc(CU2BYTES(input_len)); + if (input_buf == NULL) return ~(PCRE2_SIZE)0; + memcpy(input_buf, input, CU2BYTES(input_len)); + input_copy = input_buf; + } +else + { + memcpy(buf, input, CU2BYTES(input_len)); + input_copy = buf; + } + +for (PCRE2_SIZE i = 0; i < input_len; ) + { + int num_in = i + 1 < input_len ? 2 : 1; + uint32_t c1 = input_copy[i]; + uint32_t c2 = i + 1 < input_len ? input_copy[i + 1] : 0; + int num_read; + int num_write; + + if (!case_transform(to_case, num_in, &num_read, &num_write, &c1, &c2)) + { + written = ~(PCRE2_SIZE)0; + goto END; + } + + i += num_read; + if (to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST) + to_case = PCRE2_SUBSTITUTE_CASE_LOWER; + + if (written + num_write > output_cap) + { + written += num_write; + } + else + { + if (num_write > 0) output[written++] = c1; + if (num_write > 1) output[written++] = c2; + } + } + +END: +if (input_copy != buf) free((PCRE2_UCHAR *)input_copy); + +/* Let's be maximally cruel. The case callout is allowed to leave the output +buffer in any state at all if it overflows, so let's use random garbage. */ +if (written > output_cap) + memset(output, time(NULL) & 1 ? 0xcd : 0xdc, + CU2BYTES(output_cap)); + +return written; +} + + + +/************************************************* +* Callout function * +*************************************************/ + +/* Called from a PCRE2 library as a result of the (?C) item. We print out where +we are in the match (unless suppressed). Yield zero unless more callouts than +the fail count, or the callout data is not zero. The only differences in the +callout block for different code unit widths are that the pointers to the +subject, the most recent MARK, and a callout argument string point to strings +of the appropriate width. Casts can be used to deal with this. + +Arguments: + cb a pointer to a callout block + callout_data_ptr the provided callout data + +Returns: 0 or 1 or an error, as determined by settings +*/ + +static int +callout_function(pcre2_callout_block *cb, void *callout_data_ptr) +{ +FILE *f, *fdefault; +uint32_t i, pre_start, post_start, subject_length; +PCRE2_SIZE current_position; +BOOL utf = (compiled_code->overall_options & PCRE2_UTF) != 0; +BOOL callout_capture = (dat_datctl.control & CTL_CALLOUT_CAPTURE) != 0; +BOOL callout_where = (dat_datctl.control2 & CTL2_CALLOUT_NO_WHERE) == 0; + +if (outfile == NULL) goto YIELD; + +/* The FILE f is used for echoing the subject string if it is non-NULL. This +happens only once in simple cases, but we want to repeat after any additional +output caused by CALLOUT_EXTRA. */ + +fdefault = (!first_callout && !callout_capture && cb->callout_string == NULL)? + NULL : outfile; + +if ((dat_datctl.control2 & CTL2_CALLOUT_EXTRA) != 0) + { + f = outfile; + switch (cb->callout_flags) + { + case PCRE2_CALLOUT_BACKTRACK: + fprintf(f, "Backtrack\n"); + break; + + case PCRE2_CALLOUT_STARTMATCH|PCRE2_CALLOUT_BACKTRACK: + fprintf(f, "Backtrack\nNo other matching paths\n"); + PCRE2_FALLTHROUGH /* Fall through */ + + case PCRE2_CALLOUT_STARTMATCH: + fprintf(f, "New match attempt\n"); + break; + + default: + f = fdefault; + break; + } + } +else f = fdefault; + +/* For a callout with a string argument, show the string first because there +isn't a tidy way to fit it in the rest of the data. */ + +if (cb->callout_string != NULL) + { + uint32_t delimiter = cb->callout_string[-1]; + fprintf(outfile, "Callout (%" SIZ_FORM "): %c", + cb->callout_string_offset, CHAR_OUTPUT(delimiter)); + pchars(clr_none, cb->callout_string, cb->callout_string_length, utf, outfile); + for (i = 0; callout_start_delims[i] != 0; i++) + if (delimiter == callout_start_delims[i]) + { + delimiter = callout_end_delims[i]; + break; + } + fprintf(outfile, "%c", CHAR_OUTPUT(delimiter)); + if (!callout_capture) fprintf(outfile, "\n"); + } + +/* Show captured strings if required */ + +if (callout_capture) + { + if (cb->callout_string == NULL) + fprintf(outfile, "Callout %d:", cb->callout_number); + fprintf(outfile, " last capture = %d\n", cb->capture_last); + for (i = 2; i < cb->capture_top * 2; i += 2) + { + fprintf(outfile, "%2d: ", i/2); + if (cb->offset_vector[i] == PCRE2_UNSET) + fprintf(outfile, ""); + else + { + pchars(clr_none, cb->subject + cb->offset_vector[i], + cb->offset_vector[i+1] - cb->offset_vector[i], utf, f); + } + fprintf(outfile, "\n"); + } + } + +/* Unless suppressed, re-print the subject in canonical form (with escapes for +non-printing characters), the first time, or if giving full details. On +subsequent calls in the same match, we use pchars() just to find the printed +lengths of the substrings. */ + +if (callout_where) + { + if (f != NULL) fprintf(f, "--->"); + + /* The subject before the match start. */ + + pre_start = pchars(clr_none, cb->subject, cb->start_match, utf, f); + + /* If a lookbehind is involved, the current position may be earlier than the + match start. If so, use the match start instead. */ + + current_position = (cb->current_position >= cb->start_match)? + cb->current_position : cb->start_match; + + /* The subject between the match start and the current position. */ + + post_start = pchars(clr_none, cb->subject + cb->start_match, + current_position - cb->start_match, utf, f); + + /* Print from the current position to the end. */ + + pchars(clr_none, cb->subject + current_position, cb->subject_length - current_position, + utf, f); + + /* Calculate the total subject printed length (no print). */ + + subject_length = pchars(clr_none, cb->subject, cb->subject_length, utf, NULL); + + if (f != NULL) fprintf(f, "\n"); + + /* For automatic callouts, show the pattern offset. Otherwise, for a + numerical callout whose number has not already been shown with captured + strings, show the number here. A callout with a string argument has been + displayed above. */ + + if (cb->callout_number == 255) + { + fprintf(outfile, "%+3d ", (int)cb->pattern_position); + if (cb->pattern_position > 99) fprintf(outfile, "\n "); + } + else + { + if (callout_capture || cb->callout_string != NULL) fprintf(outfile, " "); + else fprintf(outfile, "%3d ", cb->callout_number); + } + + /* Now show position indicators */ + + for (i = 0; i < pre_start; i++) fprintf(outfile, " "); + fprintf(outfile, "^"); + + if (post_start > 0) + { + for (i = 0; i < post_start - 1; i++) fprintf(outfile, " "); + fprintf(outfile, "^"); + } + + for (i = 0; i < subject_length - pre_start - post_start + 4; i++) + fprintf(outfile, " "); + + if (cb->next_item_length != 0) + { + pchars(clr_none, pbuffer + cb->pattern_position, cb->next_item_length, utf, outfile); + } + else + fprintf(outfile, "End of pattern"); + + fprintf(outfile, "\n"); + } + +/* Show any mark info */ + +if (cb->mark != last_callout_mark) + { + if (cb->mark == NULL) + fprintf(outfile, "Latest Mark: \n"); + else + { + fprintf(outfile, "Latest Mark: "); + pchars(clr_none, cb->mark - 1, -1, utf, outfile); + putc('\n', outfile); + } + } + +YIELD: + +/* Keep count */ + +first_callout = FALSE; +last_callout_mark = cb->mark; +callout_count++; + +/* Show callout data if that determines the return code */ + +if (callout_data_ptr != NULL) + { + int callout_data = *((int32_t *)callout_data_ptr); + if (callout_data != 0) + { + if (outfile != NULL) fprintf(outfile, "Callout data = %d\n", callout_data); + return callout_data; + } + } + +/* Otherwise, the callout_error and callout_fail settings provide the return +code. */ + +if (cb->callout_number == dat_datctl.cerror[0] && + callout_count >= dat_datctl.cerror[1]) + return PCRE2_ERROR_CALLOUT; + +if (cb->callout_number == dat_datctl.cfail[0] && + callout_count >= dat_datctl.cfail[1]) + return 1; + +return 0; +} + + + +/************************************************* +* Handle *MARK and copy/get tests * +*************************************************/ + +/* This function is called after complete and partial matches. It runs the +tests for substring extraction. + +Arguments: + utf TRUE for utf + capcount return from pcre2_match() + +Returns: FALSE if print_error_message() fails +*/ + +static BOOL +copy_and_get(BOOL utf, int capcount) +{ +int i; +uint8_t *nptr; + +/* Test copy strings by number */ + +for (i = 0; i < MAXCPYGET && dat_datctl.copy_numbers[i] >= 0; i++) + { + int rc, rc2; + PCRE2_SIZE length, length2; + PCRE2_UCHAR copybuffer[256]; + uint32_t n = (uint32_t)(dat_datctl.copy_numbers[i]); + length = sizeof(copybuffer)/sizeof(*copybuffer); + rc = pcre2_substring_copy_bynumber(match_data, n, copybuffer, &length); + if (rc < 0) + { + cfprintf(clr_api_error, outfile, "Copy substring %d failed (%d): ", n, rc); + if (!print_error_message(rc, "", "\n")) return FALSE; + } + else + { + fprintf(outfile, "%2dC ", n); + pchars(clr_none, copybuffer, length, utf, outfile); + fprintf(outfile, " (%" SIZ_FORM ")\n", length); + } + rc2 = pcre2_substring_length_bynumber(match_data, n, &length2); + if (rc2 < 0) + { + cfprintf(clr_api_error, outfile, "Get substring %d length failed (%d): ", n, rc2); + if (!print_error_message(rc2, "", "\n")) return FALSE; + } + else if (rc >= 0 && length2 != length) + { + cfprintf(clr_test_error, outfile, "** Mismatched substring lengths: %" + SIZ_FORM " %" SIZ_FORM "\n", length, length2); + } + } + +/* Test copy strings by name */ + +nptr = dat_datctl.copy_names; +for (;;) + { + int rc, rc2; + int groupnumber; + PCRE2_SIZE length, length2; + PCRE2_UCHAR copybuffer[256]; + size_t namelen = strlen((const char *)nptr); +#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 + PCRE2_SIZE cnl = namelen; +#endif + if (namelen == 0) break; + +#if PCRE2_CODE_UNIT_WIDTH == 8 + strcpy((char *)pbuffer8, (char *)nptr); +#endif +#if defined(EBCDIC) && !EBCDIC_IO + ascii_to_ebcdic_str(pbuffer8, namelen); +#endif +#if PCRE2_CODE_UNIT_WIDTH == 16 + (void)to16(nptr, utf, &cnl); +#endif +#if PCRE2_CODE_UNIT_WIDTH == 32 + (void)to32(nptr, utf, &cnl); +#endif + + groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer); + if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING) + cfprintf(clr_api_error, outfile, "Number not found for group \"%s\"\n", nptr); + + length = sizeof(copybuffer)/sizeof(*copybuffer); + rc = pcre2_substring_copy_byname(match_data, pbuffer, copybuffer, &length); + if (rc < 0) + { + cfprintf(clr_api_error, outfile, "Copy substring \"%s\" failed (%d): ", nptr, rc); + if (!print_error_message(rc, "", "\n")) return FALSE; + } + else + { + fprintf(outfile, " C "); + pchars(clr_none, copybuffer, length, utf, outfile); + fprintf(outfile, " (%" SIZ_FORM ") %s", length, nptr); + if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber); + else fprintf(outfile, " (non-unique)\n"); + } + rc2 = pcre2_substring_length_byname(match_data, pbuffer, &length2); + if (rc2 < 0) + { + cfprintf(clr_api_error, outfile, "Get substring \"%s\" length failed (%d): ", nptr, rc2); + if (!print_error_message(rc2, "", "\n")) return FALSE; + } + else if (rc >= 0 && length2 != length) + { + cfprintf(clr_test_error, outfile, "** Mismatched substring lengths: %" + SIZ_FORM " %" SIZ_FORM "\n", length, length2); + } + nptr += namelen + 1; + } + +/* Test get strings by number */ + +for (i = 0; i < MAXCPYGET && dat_datctl.get_numbers[i] >= 0; i++) + { + int rc; + PCRE2_SIZE length; + PCRE2_UCHAR *gotbuffer; + uint32_t n = (uint32_t)(dat_datctl.get_numbers[i]); + rc = pcre2_substring_get_bynumber(match_data, n, &gotbuffer, &length); + if (rc < 0) + { + cfprintf(clr_api_error, outfile, "Get substring %d failed (%d): ", n, rc); + if (!print_error_message(rc, "", "\n")) return FALSE; + } + else + { + fprintf(outfile, "%2dG ", n); + pchars(clr_none, gotbuffer, length, utf, outfile); + fprintf(outfile, " (%" SIZ_FORM ")\n", length); + pcre2_substring_free(gotbuffer); + } + } + +/* Test get strings by name */ + +nptr = dat_datctl.get_names; +for (;;) + { + PCRE2_SIZE length; + PCRE2_UCHAR *gotbuffer; + int rc; + int groupnumber; + size_t namelen = strlen((const char *)nptr); +#if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 + PCRE2_SIZE cnl = namelen; +#endif + if (namelen == 0) break; + +#if PCRE2_CODE_UNIT_WIDTH == 8 + strcpy((char *)pbuffer8, (char *)nptr); +#endif +#if defined(EBCDIC) && !EBCDIC_IO + ascii_to_ebcdic_str(pbuffer8, namelen); +#endif +#if PCRE2_CODE_UNIT_WIDTH == 16 + (void)to16(nptr, utf, &cnl); +#endif +#if PCRE2_CODE_UNIT_WIDTH == 32 + (void)to32(nptr, utf, &cnl); +#endif + + groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer); + if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING) + cfprintf(clr_api_error, outfile, "Number not found for group \"%s\"\n", nptr); + + rc = pcre2_substring_get_byname(match_data, pbuffer, &gotbuffer, &length); + if (rc < 0) + { + cfprintf(clr_api_error, outfile, "Get substring \"%s\" failed (%d): ", nptr, rc); + if (!print_error_message(rc, "", "\n")) return FALSE; + } + else + { + fprintf(outfile, " G "); + pchars(clr_none, gotbuffer, length, utf, outfile); + fprintf(outfile, " (%" SIZ_FORM ") %s", length, nptr); + if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber); + else fprintf(outfile, " (non-unique)\n"); + pcre2_substring_free(gotbuffer); + } + nptr += namelen + 1; + } + +/* Test getting the complete list of captured strings. */ + +if ((dat_datctl.control & CTL_GETALL) != 0) + { + int rc; + PCRE2_UCHAR **stringlist; + PCRE2_SIZE *lengths; + rc = pcre2_substring_list_get(match_data, &stringlist, &lengths); + if (rc < 0) + { + cfprintf(clr_api_error, outfile, "get substring list failed (%d): ", rc); + if (!print_error_message(rc, "", "\n")) return FALSE; + } + else + { + for (i = 0; i < capcount; i++) + { + fprintf(outfile, "%2dL ", i); + pchars(clr_none, stringlist[i], lengths[i], utf, outfile); + putc('\n', outfile); + } + if (stringlist[i] != NULL) + cfprintf(clr_test_error, outfile, "** string list not terminated by NULL\n"); + pcre2_substring_list_free(stringlist); + } + } + +return TRUE; +} + + + +/************************************************* +* Copy a substitution string * +*************************************************/ + +/* Copy one of the string arguments to pcre2_substitute() from its uint8_t +test input to the appropriate width buffer. +*/ + +static void +copy_substitute_string(BOOL utf, uint8_t *input, PCRE2_SIZE inlen, + PCRE2_UCHAR *output, PCRE2_SIZE *outlen) +{ +uint32_t c; +uint8_t *input_end = input + inlen; +PCRE2_UCHAR *output_start = output; +PCRE2_SIZE erroroffset; +BOOL badutf = FALSE; + +/* When copying the replacement string to a buffer of the appropriate width, no +escape processing is done. + +In UTF mode, check for an invalid UTF-8 input string, and if it is invalid, just +copy its code units without UTF interpretation. This provides a means of +checking that an invalid string is detected. Otherwise, UTF-8 can be used to +include wide characters in a replacement. */ + +if (utf) badutf = valid_utf(input, inlen, &erroroffset); + +/* Not UTF or invalid UTF-8: just copy the code units. */ + +if (!utf || badutf) + { + while (input < input_end) + { + c = *input++; +#if defined(EBCDIC) && !EBCDIC_IO + c = ascii_to_ebcdic(c); +#endif + *output++ = c; + } + } + +/* Valid UTF-8 replacement string */ + +else while (input < input_end) + { + c = *input++; + if (HASUTF8EXTRALEN(c)) { GETUTF8INC(c, input); } + +#if PCRE2_CODE_UNIT_WIDTH == 8 + output += ord_to_utf8(c, output); + +#elif PCRE2_CODE_UNIT_WIDTH == 16 + if (c >= 0x10000u) + { + c-= 0x10000u; + *output++ = 0xd800 | (c >> 10); + *output++ = 0xdc00 | (c & 0x3ff); + } + else *output++ = c; + +#elif PCRE2_CODE_UNIT_WIDTH == 32 + *output++ = c; +#endif + } + +*output = 0; +*outlen = output - output_start; +} + + + +/************************************************* +* Process a data line * +*************************************************/ + +/* The line is in buffer; it will not be empty. + +Arguments: none + +Returns: PR_OK continue processing next line + PR_SKIP skip to a blank line + PR_ABEND abort the pcre2test run +*/ + +static int +process_data(void) +{ +PCRE2_SIZE ulen, arg_ulen; +uint32_t gmatched; +uint32_t c, k; +uint32_t g_notempty = 0; +uint8_t *p; /* Position within buffer (raw input line) */ +size_t len; +size_t needlen; /* Bytes, for sizing dbuffer */ +pcre2_match_context *use_dat_context; +BOOL utf; +BOOL subject_literal; + +PCRE2_SIZE *ovector; +PCRE2_SPTR ovecsave[2] = { NULL, NULL }; +uint32_t oveccount; + +PCRE2_UCHAR *q = NULL; /* Typed pointer within dbuffer */ +PCRE2_UCHAR *start_rep; /* Position within dbuffer; stashed value of q */ +PCRE2_UCHAR *pp; /* Subject pointer within dbuffer */ + +subject_literal = (pat_patctl.control2 & CTL2_SUBJECT_LITERAL) != 0; + +/* Copy the default context and data control blocks to the active ones. Then +copy from the pattern the controls that can be set in either the pattern or the +data. This allows them to be overridden in the data line. We do not do this for +options because those that are common apply separately to compiling and +matching. */ + +memcpy(dat_context, default_dat_context, sizeof(pcre2_match_context)); +memcpy(&dat_datctl, &def_datctl, sizeof(datctl)); +dat_datctl.control |= (pat_patctl.control & CTL_ALLPD); +dat_datctl.control2 |= (pat_patctl.control2 & CTL2_ALLPD); +dat_datctl.replacement[0] = pat_patctl.replacement[0]; +if (pat_patctl.replacement[0] != MOD_STR_UNSET) + memcpy(dat_datctl.replacement + 1, pat_patctl.replacement + 1, + pat_patctl.replacement[0] + 1); +if (dat_datctl.jitstack == 0) dat_datctl.jitstack = pat_patctl.jitstack; + +if (dat_datctl.substitute_skip == 0) + dat_datctl.substitute_skip = pat_patctl.substitute_skip; +if (dat_datctl.substitute_stop == 0) + dat_datctl.substitute_stop = pat_patctl.substitute_stop; + +/* Initialize for scanning the data line. */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 +utf = ((((pat_patctl.control & CTL_POSIX) != 0)? + ((pcre2_real_code *)preg.re_pcre2_code)->overall_options : + compiled_code->overall_options) & PCRE2_UTF) != 0; +#else +utf = (compiled_code->overall_options & PCRE2_UTF) != 0; +#endif + +start_rep = NULL; +len = strlen((const char *)buffer); +while (len > 0 && isspace(buffer[len-1])) len--; +buffer[len] = 0; +p = buffer; +while (isspace(*p)) + { + p++; + len--; + } + +/* Check that the data is well-formed UTF-8 if we're in UTF mode. To create +invalid input to pcre2_match(), you must use \x?? or \x{} sequences. */ + +if (utf) + { + uint8_t *ptmp; + uint32_t cc; + int n = 1; + uint8_t *ptmp_end = p + len; + + for (ptmp = p; n > 0 && *ptmp; ptmp += n) + n = utf8_to_ord(ptmp, ptmp_end, &cc); + if (n <= 0) + { + cfprintf(clr_test_error, outfile, "** Failed: invalid UTF-8 string cannot be used as input " + "in UTF mode\n"); + return PR_OK; + } + } + +#ifdef SUPPORT_VALGRIND +/* Mark the dbuffer as addressable but undefined again. */ +if (dbuffer != NULL) + { + VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size); + } +#endif + +/* Allocate a buffer to hold the data line; len+1 is an upper bound on +the number of code units that will be needed (though the buffer may have to be +extended if replication is involved). */ + +needlen = CU2BYTES(len+1); +if (dbuffer == NULL || needlen >= dbuffer_size) + { + while (needlen >= dbuffer_size) + { + if (dbuffer_size < SIZE_MAX/2) dbuffer_size *= 2; + else dbuffer_size = needlen + 1; + } + dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size); + if (dbuffer == NULL) + { + cfprintf(clr_test_error, stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n", dbuffer_size); + exit(1); + } + } +q = (PCRE2_UCHAR *)dbuffer; + +/* Scan the data line, interpreting data escapes, and put the result into a +buffer of the appropriate width. In UTF mode, input is always UTF-8; otherwise, +in 16- and 32-bit modes, it can be forced to UTF-8 by the utf8_input modifier. +*/ + +while ((c = *p++) != 0) + { + int i = 0; + size_t replen; /* Bytes, for sizing dbuffer */ + enum force_encoding encoding = FORCE_NONE; + + /* ] may mark the end of a replicated sequence */ + + if (c == ']' && start_rep != NULL) + { + long li; + char *endptr; + + if (*p++ != '{') + { + cfprintf(clr_test_error, outfile, "** Expected '{' after \\[....]\n"); + return PR_OK; + } + + li = strtol((const char *)p, &endptr, 10); + if (S32OVERFLOW(li)) + { + cfprintf(clr_test_error, outfile, "** Repeat count too large\n"); + return PR_OK; + } + i = (int)li; + + p = (uint8_t *)endptr; + if (*p++ != '}') + { + cfprintf(clr_test_error, outfile, "** Expected '}' after \\[...]{...\n"); + return PR_OK; + } + + if (i-- <= 0) + { + cfprintf(clr_test_error, outfile, "** Zero or negative repeat not allowed\n"); + return PR_OK; + } + + replen = (uint8_t *)q - (uint8_t *)start_rep; + if (i > 0 && replen > (SIZE_MAX - needlen) / i) + { + cfprintf(clr_test_error, outfile, "** Expanded content too large\n"); + return PR_OK; + } + needlen += replen * i; + + if (needlen >= dbuffer_size) + { + size_t qoffset = (uint8_t *)q - dbuffer; + size_t rep_offset = (uint8_t *)start_rep - dbuffer; + while (needlen >= dbuffer_size) + { + if (dbuffer_size < SIZE_MAX/2) dbuffer_size *= 2; + else dbuffer_size = needlen + 1; + } + dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size); + if (dbuffer == NULL) + { + cfprintf(clr_test_error, stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n", + dbuffer_size); + exit(1); + } + q = (PCRE2_UCHAR *)(dbuffer + qoffset); + start_rep = (PCRE2_UCHAR *)(dbuffer + rep_offset); + } + + while (i-- > 0) + { + memcpy(q, start_rep, replen); + q += BYTES2CU(replen); + } + + start_rep = NULL; + continue; + } + + /* Handle a non-escaped character. In non-UTF 32-bit mode with utf8_input + set, do the fudge for setting the top bit. */ + + if (c != '\\' || subject_literal) + { + uint32_t topbit = 0; +#if PCRE2_CODE_UNIT_WIDTH == 32 + if (c == 0xff && *p != 0) + { + topbit = 0x80000000; + c = *p++; + } +#endif + if ((utf || (pat_patctl.control & CTL_UTF8_INPUT) != 0) && + HASUTF8EXTRALEN(c)) + { + GETUTF8INC(c, p); + } + c |= topbit; + } + + /* Handle backslash escapes */ + + else switch ((c = *p++)) + { + case '\\': break; + case 'a': c = '\a'; break; + case 'b': c = '\b'; break; +#if defined(EBCDIC) && !EBCDIC_IO + /* \e is the odd one out since it's not defined in the C standard, + precisely because of EBCDIC (apparently EBCDIC 'ESC' character isn't + an exact match to Latin-1 'ESC', hence '\e' isn't necessarily + supported by EBCDIC compilers). */ + case 'e': c = '\x1b'; break; +#else + case 'e': c = CHAR_ESC; break; +#endif + case 'f': c = '\f'; break; + case 'n': c = '\n'; break; + case 'r': c = '\r'; break; + case 't': c = '\t'; break; + case 'v': c = '\v'; break; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + c -= '0'; + while (i++ < 2 && *p >= '0' && *p < '8') + c = c * 8 + (*p++ - '0'); + c = CHAR_OUTPUT(CHAR_INPUT_HEX(c)); + + encoding = (utf && c > 255)? FORCE_UTF : FORCE_RAW; + break; + + case 'o': + if (*p == '{') + { + uint8_t *pt = p; + c = 0; + for (pt++; isdigit(*pt) && *pt < '8'; ++i, pt++) + { + if (c >= 0x20000000u) + { + cfprintf(clr_test_error, outfile, "** \\o{ escape too large\n"); + return PR_OK; + } + else c = c * 8 + (*pt - '0'); + } + c = CHAR_OUTPUT(CHAR_INPUT_HEX(c)); + if (i == 0 || *pt != '}') + { + cfprintf(clr_test_error, outfile, "** Malformed \\o{ escape\n"); + return PR_OK; + } + else p = pt + 1; + } + break; + + case 'x': + c = 0; + if (*p == '{') + { + uint8_t *pt = p; + + /* We used to have "while (isxdigit(*(++pt)))" here, but it fails + when isxdigit() is a macro that refers to its argument more than + once. This is banned by the C Standard, but apparently happens in at + least one macOS environment. */ + + for (pt++; isxdigit(*pt); pt++) + { + if (++i == 9) + { + cfprintf(clr_test_error, outfile, "** Too many hex digits in \\x{...} item; " + "using only the first eight.\n"); + while (isxdigit(*pt)) pt++; + break; + } + else c = c * 16 + (tolower(*pt) - (isdigit(*pt)? '0' : 'a' - 10)); + } + c = CHAR_OUTPUT(CHAR_INPUT_HEX(c)); + if (i == 0 || *pt != '}') + { + cfprintf(clr_test_error, outfile, "** Malformed \\x{ escape\n"); + return PR_OK; + } + else p = pt + 1; + } + else + { + /* \x without {} always defines just one byte in 8-bit mode. This + allows UTF-8 characters to be constructed byte by byte, and also allows + invalid UTF-8 sequences to be made. Just copy the byte in UTF-8 mode. + Otherwise, pass it down as data. */ + + while (i++ < 2 && isxdigit(*p)) + { + c = c * 16 + (tolower(*p) - (isdigit(*p)? '0' : 'a' - 10)); + p++; + } + c = CHAR_OUTPUT(CHAR_INPUT_HEX(c)); +#if PCRE2_CODE_UNIT_WIDTH == 8 + if (utf) encoding = FORCE_RAW; +#endif + } + break; + + case 'N': +#ifndef EBCDIC + if (memcmp(p, "{U+", 3) == 0 && isxdigit(p[3])) + { + char *endptr; + unsigned long uli; + + p += 3; + errno = 0; + uli = strtoul((const char *)p, &endptr, 16); + if (errno == 0 && *endptr == '}' && uli <= UINT32_MAX) + { + c = (uint32_t)uli; + p = (uint8_t *)endptr + 1; + encoding = FORCE_UTF; + break; + } + } +#endif + cfprintf(clr_test_error, outfile, "** Malformed \\N{U+ escape\n"); + return PR_OK; + + case 0: /* \ followed by EOF allows for an empty line */ + p--; + continue; + + case '=': /* \= terminates the data, starts modifiers */ + goto ENDSTRING; + + case '[': /* \[ introduces a replicated character sequence */ + if (start_rep != NULL) + { + cfprintf(clr_test_error, outfile, "** Nested replication is not supported\n"); + return PR_OK; + } + start_rep = q; + continue; + + default: + if (isalnum(c)) + { + cfprintf(clr_test_error, outfile, "** Unrecognized escape sequence \"\\%c\"\n", c); + return PR_OK; + } + } + + /* We now have a character value in c that may be greater than 255. + Depending of how we got it, the encoding enum could be set to tell + us how to encode it, otherwise follow the utf modifier. */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 + if (encoding == FORCE_RAW || !(utf || encoding == FORCE_UTF)) + { + if (c > 0xffu) + { + cfprintf(clr_test_error, outfile, "** Character \\x{%x} is greater than 255 " + "and UTF-8 mode is not enabled.\n", c); + cfprintf(clr_test_error, outfile, "** Truncation will probably give the wrong " + "result.\n"); + } + *q++ = (uint8_t)c; + } + else + { + if (c > 0x7fffffff) + { + cfprintf(clr_test_error, outfile, "** Character \\N{U+%x} is greater than 0x7fffffff " + "and therefore cannot be encoded as UTF-8\n", c); + return PR_OK; + } + else if (encoding == FORCE_UTF && c > MAX_UTF_CODE_POINT) + cfprintf(clr_test_error, outfile, "** Warning: character \\N{U+%x} is greater than " + "0x%x and should not be encoded as UTF-8\n", + c, MAX_UTF_CODE_POINT); + q += ord_to_utf8(c, q); + } +#endif +#if PCRE2_CODE_UNIT_WIDTH == 16 + /* Unlike the 8-bit code, there are no forced raw suggestions for the + 16-bit mode, so assume raw unless utf is preferred */ + + if (!(encoding == FORCE_UTF || utf)) + { + if (c > 0xffffu) + { + cfprintf(clr_test_error, outfile, "** Character \\x{%x} is greater than 0xffff " + "and UTF-16 mode is not enabled.\n", c); + cfprintf(clr_test_error, outfile, "** Truncation will probably give the wrong " + "result.\n"); + } + *q++ = (uint16_t)c; + } + else + { + if (c > MAX_UTF_CODE_POINT) + { + cfprintf(clr_test_error, outfile, "** Failed: character \\N{U+%x} is greater than " + "0x%x and therefore cannot be encoded as UTF-16\n", + c, MAX_UTF_CODE_POINT); + return PR_OK; + } + else if (c >= 0x10000u) + { + c -= 0x10000u; + *q++ = 0xd800 | (c >> 10); + *q++ = 0xdc00 | (c & 0x3ff); + } + else + { + if (encoding == FORCE_UTF && 0xe000u > c && c >= 0xd800u) + cfprintf(clr_test_error, outfile, "** Warning: character \\N{U+%x} is a surrogate " + "and should not be encoded as UTF-16\n", c); + *q++ = c; + } + } +#endif +#if PCRE2_CODE_UNIT_WIDTH == 32 + if (encoding == FORCE_UTF && c > MAX_UTF_CODE_POINT) + cfprintf(clr_test_error, outfile, "** Warning: character \\N{U+%x} is greater than " + "0x%x and should not be encoded as UTF-32\n", + c, MAX_UTF_CODE_POINT); + *q++ = c; +#endif + } + +ENDSTRING: +*q = 0; +len = (uint8_t *)q - dbuffer; /* Length in bytes */ +ulen = BYTES2CU(len); /* Length in code units */ +arg_ulen = ulen; /* Value to use in match arg */ + +/* If the string was terminated by \= we must now interpret modifiers. */ + +if (p[-1] != 0 && !decode_modifiers(p, CTX_DAT, NULL, &dat_datctl)) + return PR_OK; + +/* Setting substitute_{skip,fail} implies a substitute callout. */ + +if (dat_datctl.substitute_skip != 0 || dat_datctl.substitute_stop != 0) + dat_datctl.control2 |= CTL2_SUBSTITUTE_CALLOUT; + +/* Check for mutually exclusive modifiers. At present, these are all in the +first control word. */ + +for (k = 0; k < sizeof(exclusive_dat_controls)/sizeof(uint32_t); k++) + { + c = dat_datctl.control & exclusive_dat_controls[k]; + if (c != 0 && c != (c & (~c+1))) + { + show_controls(clr_test_error, c, 0, "** Not allowed together:"); + fprintf(outfile, "\n"); + return PR_OK; + } + } + +if (dat_datctl.replacement[0] != MOD_STR_UNSET) + { + if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CALLOUT) != 0 && + (dat_datctl.control & CTL_NULLCONTEXT) != 0) + { + cfprintf(clr_test_error, outfile, "** Replacement callouts are not supported with null_context.\n"); + return PR_OK; + } + + if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CASE_CALLOUT) != 0 && + (dat_datctl.control & CTL_NULLCONTEXT) != 0) + { + cfprintf(clr_test_error, outfile, "** Replacement case callouts are not supported with null_context.\n"); + return PR_OK; + } + + if ((dat_datctl.control & CTL_ALLCAPTURES) != 0) + cfprintf(clr_test_error, outfile, "** Ignored with replacement text: allcaptures\n"); + + if (dat_datctl.substitute_subject[0] != MOD_STR_UNSET && + (dat_datctl.control2 & CTL2_SUBSTITUTE_MATCHED) == 0) + { + cfprintf(clr_test_error, outfile, "** substitute_subject requires substitute_matched.\n"); + return PR_OK; + } + } + +else + { + if (dat_datctl.substitute_subject[0] != MOD_STR_UNSET) + { + cfprintf(clr_test_error, outfile, "** substitute_subject requires replacement text.\n"); + return PR_OK; + } + } + +/* Warn for modifiers that are ignored for DFA. */ + +if ((dat_datctl.control & CTL_DFA) != 0) + { + if ((dat_datctl.control & CTL_ALLCAPTURES) != 0) + cfprintf(clr_test_error, outfile, "** Ignored for DFA matching: allcaptures\n"); + if ((dat_datctl.control2 & CTL2_HEAPFRAMES_SIZE) != 0) + cfprintf(clr_test_error, outfile, "** Ignored for DFA matching: heapframes_size\n"); + } + +/* We now have the subject in dbuffer, with len containing the byte length, and +ulen containing the code unit length, with a copy in arg_ulen for use in match +function arguments (this gets changed to PCRE2_ZERO_TERMINATED when the +zero_terminate modifier is present). + +Move the data to the end of the buffer so that a read over the end can be +caught by valgrind or other means. If we have explicit valgrind support, mark +the unused start of the buffer unaddressable. If we are using the POSIX +interface, or testing zero-termination, we must include the terminating zero in +the usable data. */ + +c = ((pat_patctl.control & CTL_POSIX) != 0 || + (dat_datctl.control & CTL_ZERO_TERMINATE) != 0)? CU2BYTES(1) : 0; +pp = memmove(dbuffer + dbuffer_size - (len + c), dbuffer, len + c); +#ifdef SUPPORT_VALGRIND +VALGRIND_MAKE_MEM_NOACCESS(dbuffer, dbuffer_size - (len + c)); +#endif + +#if defined(EBCDIC) && !EBCDIC_IO +ascii_to_ebcdic_str(pp, len); +#endif + +/* Now pp points to the subject string, but if null_subject was specified, set +it to NULL to test PCRE2's behaviour. */ + +if ((dat_datctl.control2 & CTL2_NULL_SUBJECT) != 0) pp = NULL; + +/* POSIX matching is only possible in 8-bit mode, and it does not support +timing or other fancy features. Some were checked at compile time, but we need +to check the match-time settings here. */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 +if ((pat_patctl.control & CTL_POSIX) != 0) + { + int rc; + int eflags = 0; + regmatch_t *pmatch = NULL; + regmatch_t startend_buf; + const char *msg = "** Ignored with POSIX interface:"; + + if (dat_datctl.cerror[0] != CFORE_UNSET || dat_datctl.cerror[1] != CFORE_UNSET) + prmsg(&msg, "callout_error"); + if (dat_datctl.cfail[0] != CFORE_UNSET || dat_datctl.cfail[1] != CFORE_UNSET) + prmsg(&msg, "callout_fail"); + if (dat_datctl.copy_numbers[0] >= 0 || dat_datctl.copy_names[0] != 0) + prmsg(&msg, "copy"); + if (dat_datctl.get_numbers[0] >= 0 || dat_datctl.get_names[0] != 0) + prmsg(&msg, "get"); + if (dat_datctl.jitstack != 0) prmsg(&msg, "jitstack"); + if (dat_datctl.offset != 0) prmsg(&msg, "offset"); + + if ((dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS) != 0) + { + cfprintf(clr_test_error, outfile, "%s", msg); + show_match_options(clr_test_error, dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS); + msg = ""; + } + + if ((dat_datctl.control & ~POSIX_SUPPORTED_MATCH_CONTROLS) != 0 || + (dat_datctl.control2 & ~POSIX_SUPPORTED_MATCH_CONTROLS2) != 0) + { + show_controls(clr_test_error, dat_datctl.control & ~POSIX_SUPPORTED_MATCH_CONTROLS, + dat_datctl.control2 & ~POSIX_SUPPORTED_MATCH_CONTROLS2, msg); + msg = ""; + } + + if (msg[0] == 0) fprintf(outfile, "\n"); + + if (dat_datctl.oveccount > 0) + { + pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * dat_datctl.oveccount); + if (pmatch == NULL) + { + cfprintf(clr_test_error, outfile, "** Failed to get memory for recording matching " + "information (size set = %du)\n", dat_datctl.oveccount); + return PR_ABEND; + } + } + + if (dat_datctl.startend[0] != CFORE_UNSET) + { + if (pmatch == NULL) pmatch = &startend_buf; + pmatch[0].rm_so = (regoff_t)dat_datctl.startend[0]; + pmatch[0].rm_eo = (dat_datctl.startend[1] != 0)? + (regoff_t)dat_datctl.startend[1] : (regoff_t)len; + eflags |= REG_STARTEND; + } + + if ((dat_datctl.options & PCRE2_NOTBOL) != 0) eflags |= REG_NOTBOL; + if ((dat_datctl.options & PCRE2_NOTEOL) != 0) eflags |= REG_NOTEOL; + if ((dat_datctl.options & PCRE2_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY; + + rc = regexec(&preg, (const char *)pp, dat_datctl.oveccount, pmatch, eflags); + if (rc != 0) + { + size_t usize = regerror(rc, &preg, (char *)pbuffer8, pbuffer8_size); + cfprintf(clr_api_error, outfile, "No match: POSIX code %d: ", rc); + pchars(clr_api_error, (PCRE2_SPTR8)pbuffer8, usize - 1, utf, outfile); + fputs("\n", outfile); + } + else if ((pat_patctl.control & CTL_POSIX_NOSUB) != 0) + fprintf(outfile, "Matched with REG_NOSUB\n"); + else if (dat_datctl.oveccount == 0) + fprintf(outfile, "Matched without capture\n"); + else + { + size_t i, j; + size_t last_printed = (size_t)dat_datctl.oveccount; + for (i = 0; i < (size_t)dat_datctl.oveccount; i++) + { + if (pmatch[i].rm_so >= 0) + { + PCRE2_SIZE start = pmatch[i].rm_so; + PCRE2_SIZE end = pmatch[i].rm_eo; + for (j = last_printed + 1; j < i; j++) + fprintf(outfile, "%2d: \n", (int)j); + last_printed = i; + if (start > end) + { + start = pmatch[i].rm_eo; + end = pmatch[i].rm_so; + cfprintf(clr_api_error, outfile, "Start of matched string is beyond its end - " + "displaying from end to start.\n"); + } + fprintf(outfile, "%2d: ", (int)i); + pchars(clr_none, pp + start, end - start, utf, outfile); + fprintf(outfile, "\n"); + + if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) || + (dat_datctl.control & CTL_ALLAFTERTEXT) != 0) + { + fprintf(outfile, "%2d+ ", (int)i); + /* Note: don't use the start/end variables here because we want to + show the text from what is reported as the end. */ + pchars(clr_none, pp + pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile); + fprintf(outfile, "\n"); + } + } + } + } + if (pmatch != &startend_buf) free(pmatch); + return PR_OK; + } +#endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ + + /* Handle matching via the native interface. Check for consistency of +modifiers. */ + +if (dat_datctl.startend[0] != CFORE_UNSET) + cfprintf(clr_test_error, outfile, "** \\=posix_startend ignored for non-POSIX matching\n"); + +/* ALLUSEDTEXT is not supported with JIT, but JIT is not used with DFA +matching, even if the JIT compiler was used. */ + +if ((dat_datctl.control & (CTL_ALLUSEDTEXT|CTL_DFA)) == CTL_ALLUSEDTEXT && + compiled_code->executable_jit != NULL) + { + cfprintf(clr_test_error, outfile, "** Showing all consulted text is not supported by JIT: ignored\n"); + dat_datctl.control &= ~CTL_ALLUSEDTEXT; + } + +/* Handle passing the subject as zero-terminated. */ + +if ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0) + arg_ulen = PCRE2_ZERO_TERMINATED; + +/* The nullcontext modifier is used to test calling pcre2_[jit_]match() with a +NULL context. */ + +use_dat_context = ((dat_datctl.control & CTL_NULLCONTEXT) != 0)? + NULL : dat_context; + +/* Enable display of malloc/free if wanted. We can do this only if either the +pattern or the subject is processed with a context. */ + +show_memory = (dat_datctl.control & CTL_MEMORY) != 0; + +if (show_memory && + (pat_patctl.control & dat_datctl.control & CTL_NULLCONTEXT) != 0) + cfprintf(clr_test_error, outfile, "** \\=memory requires either a pattern or a subject " + "context: ignored\n"); + +/* Create and assign a JIT stack if requested. */ + +if (dat_datctl.jitstack != 0) + { + if (dat_datctl.jitstack != jit_stack_size) + { + pcre2_jit_stack_free(jit_stack); + jit_stack = pcre2_jit_stack_create(1, dat_datctl.jitstack * 1024, NULL); + jit_stack_size = dat_datctl.jitstack; + } + pcre2_jit_stack_assign(dat_context, jit_callback, jit_stack); + } + +/* Or de-assign */ + +else if (jit_stack != NULL) + { + pcre2_jit_stack_assign(dat_context, NULL, NULL); + pcre2_jit_stack_free(jit_stack); + jit_stack = NULL; + jit_stack_size = 0; + } + +/* When no JIT stack is assigned, we must ensure that there is a JIT callback +if we want to verify that JIT was actually used. */ + +if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_stack == NULL) + { + pcre2_jit_stack_assign(dat_context, jit_callback, NULL); + } + +/* Set up the match callout. The pattern remains in pbuffer8/16/32 after +compilation, for use by the callout. */ + +if ((dat_datctl.control & CTL_CALLOUT_NONE) == 0) + { + pcre2_set_callout(dat_context, callout_function, + (void *)(&dat_datctl.callout_data)); + } +else + { + pcre2_set_callout(dat_context, NULL, NULL); /* No callout */ + } + +/* Adjust match_data according to size of offsets required. A size of zero +causes a new match data block to be obtained that exactly fits the pattern. */ + +if (dat_datctl.oveccount == 0) + { + pcre2_match_data_free(match_data); + match_data = pcre2_match_data_create_from_pattern(compiled_code, + general_context); + max_oveccount = pcre2_get_ovector_count(match_data); + } +else if (dat_datctl.oveccount <= max_oveccount) + { + match_data->oveccount = dat_datctl.oveccount; + } +else + { + max_oveccount = dat_datctl.oveccount; + pcre2_match_data_free(match_data); + match_data = pcre2_match_data_create(max_oveccount, general_context); + } + +if (match_data == NULL) + { + cfprintf(clr_test_error, outfile, "** Failed to get memory for recording matching " + "information (size requested: %d)\n", dat_datctl.oveccount); + max_oveccount = 0; + return PR_ABEND; + } + +ovector = match_data->ovector; +oveccount = pcre2_get_ovector_count(match_data); + +/* Helper to clear any cached heap frames from the match_data. */ + +#define CLEAR_HEAP_FRAMES() \ + do { \ + void *heapframes = (void *)(match_data->heapframes); \ + void *memory_data = match_data->memctl.memory_data; \ + match_data->memctl.free(heapframes, memory_data); \ + match_data->heapframes = NULL; \ + match_data->heapframes_size = 0; \ + } \ + while (0) + +/* Replacement processing is ignored for DFA matching. Allow this for +replacements with PCRE2_SUBSTITUTE_MATCHED, even though it won't work, in order +to exercise the error condition. */ + +if (dat_datctl.replacement[0] != MOD_STR_UNSET && + (dat_datctl.control & CTL_DFA) != 0 && + (dat_datctl.control2 & CTL2_SUBSTITUTE_MATCHED) == 0) + { + cfprintf(clr_test_error, outfile, "** Ignored for DFA matching: replace\n"); + dat_datctl.replacement[0] = MOD_STR_UNSET; + } + +/* If a replacement string is provided, call pcre2_substitute() instead of or +after one of the matching functions. First we have to convert the replacement +string to the appropriate width. */ + +if (dat_datctl.replacement[0] != MOD_STR_UNSET) + { + int rc; + uint8_t *pr, *prend; + PCRE2_UCHAR sbuffer[SUBSTITUTE_SUBJECT_MODSIZE]; /* Staging, not seen by pcre2_substitute() */ + PCRE2_UCHAR *rbptr; + PCRE2_UCHAR *sbptr; + uint32_t xoptions; + uint32_t emoption; /* External match option */ + PCRE2_SIZE j, rlen, full_rlen, nsize, nsize_input, slen; + pcre2_match_data *smatch_data; + + /* Fill the ovector with junk to detect elements that do not get set + when they should be (relevant only when "allvector" is specified). */ + + for (j = 0; j < 2*oveccount; j++) ovector[j] = JUNK_OFFSET; + + if (timeitm) + cfprintf(clr_test_error, outfile, "** Timing is not supported with replace: ignored\n"); + + if ((dat_datctl.control & CTL_ALTGLOBAL) != 0) + cfprintf(clr_test_error, outfile, "** Altglobal is not supported with replace: ignored\n"); + + /* Check for a test that does substitution after an initial external match. + If this is set, we run the external match, but leave the interpretation of + its output to pcre2_substitute(). */ + + emoption = ((dat_datctl.control2 & CTL2_SUBSTITUTE_MATCHED) == 0)? 0 : + PCRE2_SUBSTITUTE_MATCHED; + + if (emoption != 0) + { + reset_callout_state(); + if ((dat_datctl.control & CTL_DFA) != 0) + { + if (dfa_workspace == NULL) + dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int)); + dfa_workspace[0] = -1; + (void)pcre2_dfa_match(compiled_code, pp, arg_ulen, + dat_datctl.offset, dat_datctl.options, match_data, + use_dat_context, dfa_workspace, DFA_WS_DIMENSION); + } + else if ((pat_patctl.control & CTL_JITFAST) != 0) + { + (void)pcre2_jit_match(compiled_code, pp, arg_ulen, dat_datctl.offset, + dat_datctl.options, match_data, use_dat_context); + } + else + { + (void)pcre2_match(compiled_code, pp, arg_ulen, dat_datctl.offset, + dat_datctl.options, match_data, use_dat_context); + } + } + + xoptions = emoption | + (((dat_datctl.control & CTL_GLOBAL) == 0)? 0 : + PCRE2_SUBSTITUTE_GLOBAL) | + (((dat_datctl.control2 & CTL2_SUBSTITUTE_EXTENDED) == 0)? 0 : + PCRE2_SUBSTITUTE_EXTENDED) | + (((dat_datctl.control2 & CTL2_SUBSTITUTE_LITERAL) == 0)? 0 : + PCRE2_SUBSTITUTE_LITERAL) | + (((dat_datctl.control2 & CTL2_SUBSTITUTE_OVERFLOW_LENGTH) == 0)? 0 : + PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) | + (((dat_datctl.control2 & CTL2_SUBSTITUTE_REPLACEMENT_ONLY) == 0)? 0 : + PCRE2_SUBSTITUTE_REPLACEMENT_ONLY) | + (((dat_datctl.control2 & CTL2_SUBSTITUTE_UNKNOWN_UNSET) == 0)? 0 : + PCRE2_SUBSTITUTE_UNKNOWN_UNSET) | + (((dat_datctl.control2 & CTL2_SUBSTITUTE_UNSET_EMPTY) == 0)? 0 : + PCRE2_SUBSTITUTE_UNSET_EMPTY); + + pr = dat_datctl.replacement+1; + prend = pr + dat_datctl.replacement[0]; + + /* If the replacement starts with '[]' we interpret that as length + value for the replacement buffer. */ + + nsize = rep_out_buffer_size; + if (pr < prend && *pr == '[') + { + PCRE2_SIZE n = 0; + ++pr; + for (; pr < prend && (c = *pr) >= '0' && c <= '9'; ++pr) + n = n * 10 + (c - '0'); + if (pr >= prend || *pr != ']') + { + cfprintf(clr_test_error, outfile, "** Bad buffer size in replacement string\n"); + return PR_OK; + } + ++pr; + if (n > nsize) + { + cfprintf(clr_test_error, outfile, "** Replacement buffer setting (%" SIZ_FORM ") is too " + "large (max %" SIZ_FORM ")\n", n, nsize); + return PR_OK; + } + nsize = n; + } + +#ifdef SUPPORT_VALGRIND + VALGRIND_MAKE_MEM_UNDEFINED(rep_out_buffer, CU2BYTES(nsize)); + VALGRIND_MAKE_MEM_NOACCESS(rep_out_buffer + nsize, + CU2BYTES(rep_out_buffer_size - nsize)); +#endif + + /* Now copy the rest of the replacement string to the buffer. */ + +#ifdef SUPPORT_VALGRIND + VALGRIND_MAKE_MEM_UNDEFINED(rep_in_buffer, CU2BYTES(rep_in_buffer_size)); +#endif + + copy_substitute_string(utf, pr, prend-pr, rep_in_buffer, &rlen); + +#ifdef SUPPORT_VALGRIND + c = ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0)? 1 : 0; + VALGRIND_MAKE_MEM_NOACCESS(rep_in_buffer + rlen + c, + CU2BYTES(rep_in_buffer_size - rlen + c)); +#endif + + full_rlen = rlen; + if ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0) + rlen = PCRE2_ZERO_TERMINATED; + rbptr = ((dat_datctl.control2 & CTL2_NULL_REPLACEMENT) == 0)? rep_in_buffer : NULL; + + /* If the substitute_subject modifier is set, then we will modify the + subject in between the call to pcre2_match and pcre2_substitute. */ + + sbptr = pp; + slen = arg_ulen; + + if (dat_datctl.substitute_subject[0] != MOD_STR_UNSET) + { + copy_substitute_string(utf, dat_datctl.substitute_subject+1, + dat_datctl.substitute_subject[0], sbuffer, &slen); + + /* The buffer pointed to by pp has exactly the correct length (butted up + against the end of the memory allocation) so it would be possible but + awkward to extend the subject. However, since pcre2_substitute() won't allow + changing the length of the subject, and also early-exits if the subject + pointer changes, we can test all the branches just by supporting shrinking + the subject. */ + if (slen > ulen) + { + cfprintf(clr_test_error, outfile, "** substitute_subject is longer than match subject buffer\n"); + return PR_OK; + } + + /* In the null-subject case, there's no need to copy. */ + if (pp != NULL) + { + memcpy(pp, sbuffer, CU2BYTES(slen)); + if (slen < ulen) ((PCRE2_UCHAR *)pp)[slen] = 0; + + /* If we shrank the subject, adjust the Valgrind readable area. */ +#ifdef SUPPORT_VALGRIND + c = ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0)? 1 : 0; + VALGRIND_MAKE_MEM_NOACCESS((uint8_t *)pp + CU2BYTES(slen+c), + (dbuffer + dbuffer_size) - ((uint8_t *)pp + CU2BYTES(slen+c))); +#endif + } + + if ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0) + slen = PCRE2_ZERO_TERMINATED; + } + + /* Set up the required callouts and context, and call pcre2_substitute(). */ + + smatch_data = ((CTL2_NULL_SUBSTITUTE_MATCH_DATA & dat_datctl.control2) == 0)? + match_data : NULL; + + if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CALLOUT) != 0) + { + pcre2_set_substitute_callout(dat_context, substitute_callout_function, NULL); + } + else + { + pcre2_set_substitute_callout(dat_context, NULL, NULL); /* No callout */ + } + + if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CASE_CALLOUT) != 0) + { + pcre2_set_substitute_case_callout(dat_context, substitute_case_callout_function, NULL); + } + else + { + pcre2_set_substitute_case_callout(dat_context, NULL, NULL); /* No callout */ + } + + if (malloc_testing) CLEAR_HEAP_FRAMES(); + reset_callout_state(); + nsize_input = nsize; + rc = pcre2_substitute(compiled_code, sbptr, slen, dat_datctl.offset, + dat_datctl.options|xoptions, smatch_data, use_dat_context, + rbptr, rlen, rep_out_buffer, &nsize); + + /* For malloc testing, we repeat the substitution. */ + + if (malloc_testing && (dat_datctl.control2 & CTL2_SUBSTITUTE_CALLOUT) == 0) + { + for (int i = 0, target_mallocs = mallocs_called; i <= target_mallocs; i++) + { + FILE *saved_outfile = outfile; + CLEAR_HEAP_FRAMES(); + reset_callout_state(); + mallocs_until_failure = i; + outfile = NULL; /* Suppress callout output during the malloc repetitions */ + nsize = nsize_input; + rc = pcre2_substitute(compiled_code, sbptr, slen, dat_datctl.offset, + dat_datctl.options|xoptions, smatch_data, use_dat_context, + rbptr, rlen, rep_out_buffer, &nsize); + mallocs_until_failure = INT_MAX; + outfile = saved_outfile; + + if (i < target_mallocs && rc != PCRE2_ERROR_NOMEMORY) + { + cfprintf(clr_test_error, outfile, "** malloc() Substitution test did not fail as expected (%d)\n", + rc); + return PR_ABEND; + } + } + } + + if (rc < 0) + { + cfprintf(clr_api_error, outfile, "Failed: error %d", rc); + if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET) + cfprintf(clr_api_error, outfile, " at offset %ld in replacement", (long int)nsize); + cfprintf(clr_api_error, outfile, ": "); + if (!print_error_message(rc, "", "")) return PR_ABEND; + if (rc == PCRE2_ERROR_NOMEMORY && + (xoptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0) + cfprintf(clr_api_error, outfile, ": %ld code units are needed", (long int)nsize); + + if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET) + { + cfprintf(clr_api_error, outfile, "\n here: "); + if (nsize > 0) + { + ptrunc(clr_input, rbptr, full_rlen, nsize, TRUE, utf, outfile); + fprintf(outfile, " "); + } + cfprintf(clr_api_error, outfile, "|<--|"); + if (nsize < full_rlen) + { + fprintf(outfile, " "); + ptrunc(clr_input, rbptr, full_rlen, nsize, FALSE, utf, outfile); + } + } + } + else + { + cfprintf(clr_api_error, outfile, "%2d: ", rc); + pchars(clr_api_error, rep_out_buffer, nsize, utf, outfile); + } + + fprintf(outfile, "\n"); + show_memory = FALSE; + + /* Show final ovector contents and resulting heapframe size if requested. */ + + if ((dat_datctl.control2 & CTL2_ALLVECTOR) != 0) + show_ovector(ovector, oveccount); + + if ((dat_datctl.control2 & CTL2_HEAPFRAMES_SIZE) != 0 && + (dat_datctl.control & CTL_DFA) == 0) + show_heapframes_size(); + + return PR_OK; + } /* End of substitution handling */ + +/* When a replacement string is not provided, run a loop for global matching +with one of the basic matching functions. */ + +for (gmatched = 0;; gmatched++) + { + PCRE2_SIZE j; + int capcount; + + /* Fill the ovector with junk to detect elements that do not get set + when they should be. */ + + for (j = 0; j < 2*oveccount; j++) ovector[j] = JUNK_OFFSET; + + /* When matching is via pcre2_match(), we will detect the use of JIT via the + stack callback function. */ + + jit_was_used = (pat_patctl.control & CTL_JITFAST) != 0; + + /* Do timing if required. */ + + if (timeitm > 0) + { + int i; + clock_t start_time, time_taken; + FILE *saved_outfile = outfile; + + outfile = NULL; /* Suppress callout output during the timing repetitions */ + + if ((dat_datctl.control & CTL_DFA) != 0) + { + if ((dat_datctl.options & PCRE2_DFA_RESTART) != 0) + { + outfile = saved_outfile; + cfprintf(clr_test_error, outfile, "** Timing DFA restarts is not supported\n"); + return PR_ABEND; + } + if (dfa_workspace == NULL) + dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int)); + start_time = clock(); + for (i = 0; i < timeitm; i++) + { + (void)pcre2_dfa_match(compiled_code, pp, arg_ulen, + dat_datctl.offset, dat_datctl.options | g_notempty, match_data, + use_dat_context, dfa_workspace, DFA_WS_DIMENSION); + } + } + + else if ((pat_patctl.control & CTL_JITFAST) != 0) + { + start_time = clock(); + for (i = 0; i < timeitm; i++) + { + (void)pcre2_jit_match(compiled_code, pp, arg_ulen, + dat_datctl.offset, dat_datctl.options | g_notempty, match_data, + use_dat_context); + } + } + + else + { + start_time = clock(); + for (i = 0; i < timeitm; i++) + { + (void)pcre2_match(compiled_code, pp, arg_ulen, + dat_datctl.offset, dat_datctl.options | g_notempty, match_data, + use_dat_context); + } + } + total_match_time += (time_taken = clock() - start_time); + + outfile = saved_outfile; + cfprintf(clr_profiling, outfile, "Match time %7.4f microseconds\n", + ((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeitm); + } + + /* Find the heap, match and depth limits if requested. The depth and heap + limits are not relevant for JIT. The return from check_match_limit() is the + return from the final call to pcre2_match() or pcre2_dfa_match(). */ + + if ((dat_datctl.control & (CTL_FINDLIMITS|CTL_FINDLIMITS_NOHEAP)) != 0) + { + if ((dat_datctl.control & CTL_FINDLIMITS_NOHEAP) == 0 && + (compiled_code->executable_jit == NULL || + (dat_datctl.options & PCRE2_NO_JIT) != 0)) + { + (void)check_match_limit(pp, arg_ulen, PCRE2_ERROR_HEAPLIMIT, "heap"); + } + + capcount = check_match_limit(pp, arg_ulen, PCRE2_ERROR_MATCHLIMIT, + "match"); + + if (compiled_code->executable_jit == NULL || + (dat_datctl.options & PCRE2_NO_JIT) != 0 || + (dat_datctl.control & CTL_DFA) != 0) + { + capcount = check_match_limit(pp, arg_ulen, PCRE2_ERROR_DEPTHLIMIT, + "depth"); + } + + if (capcount == 0) + { + cfprintf(clr_api_error, outfile, "Matched, but offsets vector is too small to show all matches\n"); + capcount = dat_datctl.oveccount; + } + } + + /* Otherwise just run a single match. */ + + else + { + /* Run a single DFA or NFA match. */ + + if (malloc_testing) CLEAR_HEAP_FRAMES(); + reset_callout_state(); + if ((dat_datctl.control & CTL_DFA) != 0) + { + if (dfa_workspace == NULL) + dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int)); + if (dfa_matched++ == 0) + dfa_workspace[0] = -1; /* To catch bad restart */ + capcount = pcre2_dfa_match(compiled_code, pp, arg_ulen, + dat_datctl.offset, dat_datctl.options | g_notempty, match_data, + use_dat_context, dfa_workspace, DFA_WS_DIMENSION); + if (capcount == 0) + { + cfprintf(clr_api_error, outfile, "Matched, but offsets vector is too small to show all matches\n"); + capcount = dat_datctl.oveccount; + } + } + else + { + if ((pat_patctl.control & CTL_JITFAST) != 0) + capcount = pcre2_jit_match(compiled_code, pp, arg_ulen, dat_datctl.offset, + dat_datctl.options | g_notempty, match_data, use_dat_context); + else + capcount = pcre2_match(compiled_code, pp, arg_ulen, dat_datctl.offset, + dat_datctl.options | g_notempty, match_data, use_dat_context); + if (capcount == 0) + { + cfprintf(clr_api_error, outfile, "Matched, but too many substrings\n"); + capcount = dat_datctl.oveccount; + } + } + + /* For malloc testing, we repeat the matching. */ + + if (malloc_testing && (dat_datctl.control & CTL_CALLOUT_NONE) != 0) + { + for (int i = 0, target_mallocs = mallocs_called; i <= target_mallocs; i++) + { + FILE *saved_outfile = outfile; + + CLEAR_HEAP_FRAMES(); + reset_callout_state(); + + mallocs_until_failure = i; + outfile = NULL; /* Suppress callout output during the malloc repetitions */ + + if ((dat_datctl.control & CTL_DFA) != 0) + { + if (dfa_matched++ == 0) + dfa_workspace[0] = -1; /* To catch bad restart */ + capcount = pcre2_dfa_match(compiled_code, pp, arg_ulen, + dat_datctl.offset, dat_datctl.options | g_notempty, match_data, + use_dat_context, dfa_workspace, DFA_WS_DIMENSION); + } + else + { + if ((pat_patctl.control & CTL_JITFAST) != 0) + capcount = pcre2_jit_match(compiled_code, pp, arg_ulen, dat_datctl.offset, + dat_datctl.options | g_notempty, match_data, use_dat_context); + else + capcount = pcre2_match(compiled_code, pp, arg_ulen, dat_datctl.offset, + dat_datctl.options | g_notempty, match_data, use_dat_context); + } + + mallocs_until_failure = INT_MAX; + outfile = saved_outfile; + + if (capcount == 0) + capcount = dat_datctl.oveccount; + + if (i < target_mallocs && capcount != PCRE2_ERROR_NOMEMORY) + { + cfprintf(clr_test_error, outfile, "** malloc() match test did not fail as expected (%d)\n", + capcount); + return PR_ABEND; + } + } + } + } + + /* Verify that it's safe to call pcre2_next_match with rc < 0. */ + + if (capcount < 0 && (dat_datctl.control & CTL_ANYGLOB) != 0) + { + BOOL rc_nextmatch; + PCRE2_SIZE tmp_offset = 0xcd; + uint32_t tmp_options = 0xcd; + rc_nextmatch = pcre2_next_match(match_data, &tmp_offset, &tmp_options); + if (rc_nextmatch || tmp_offset != 0xcd || tmp_options != 0xcd) + { + cfprintf(clr_test_error, outfile, "** unexpected pcre2_next_match() for rc < 0\n"); + return PR_ABEND; + } + } + + /* The result of the match is now in capcount. First handle a successful + match. If pp was forced to be NULL (to test NULL handling) it will have been + treated as an empty string if the length was zero. So, re-create that for + outputting, preserving the invariant that pp is a valid pointer to a region + of length len followed by a null. */ + + if (capcount >= 0) + { + if (pp == NULL) + { +#ifdef SUPPORT_VALGRIND + /* Mark the start of dbuffer addressable again. */ + VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, CU2BYTES(1)); +#endif + pp = (PCRE2_UCHAR *)dbuffer; + *pp = 0; + } + + if ((unsigned)capcount > oveccount) /* Check for lunatic return value */ + { + cfprintf(clr_test_error, outfile, + "** PCRE2 error: returned count %d is too big for ovector count %d\n", + capcount, oveccount); + return PR_ABEND; + } + + /* If PCRE2_COPY_MATCHED_SUBJECT was set, check that things are as they + should be, but not for fast JIT, where it isn't supported. */ + + if ((dat_datctl.options & PCRE2_COPY_MATCHED_SUBJECT) != 0 && + (pat_patctl.control & CTL_JITFAST) == 0) + { + if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) == 0) + cfprintf(clr_test_error, outfile, + "** PCRE2 error: flag not set after copy_matched_subject\n"); + + if (match_data->subject == pp) + cfprintf(clr_test_error, outfile, + "** PCRE2 error: copy_matched_subject has not copied\n"); + + if (memcmp(match_data->subject, pp, ulen) != 0) + cfprintf(clr_test_error, outfile, + "** PCRE2 error: copy_matched_subject mismatch\n"); + } + + /* If this is not the first time round a global loop, check that the + returned string has advanced. + + There is one known case where this doesn't happen: when you have a + "badly-behaved" pattern which uses \K in a lookaround, and breaks the core + sanity rule that start_offset <= ovector[0] <= ovector[1]. An example would + be /(?<=\Ka)/g matching "aaa". + * first attempt, start_offset=0: ovector[0]=0, ovector[1]=1 + * second attempt, start_offset=1: ovector[0]=0, ovector[1]=1 + + You can see that even though we *always* ensure that start_offset advances, + this doesn't guarantee to avoid duplicate matches. + + The pcre2test behaviour is to return all the matches found, except in the + case where two adjacent matches are an exact duplicate. */ + + if (gmatched > 0 && + !(dat_datctl.offset <= ovector[0] && ovector[0] <= ovector[1]) && + pp + ovector[0] == ovecsave[0] && pp + ovector[1] == ovecsave[1]) + { + cfprintf(clr_api_error, outfile, "global repeat returned the same match as previous\n"); + goto NEXT_MATCH; + } + + /* Outside of this exceptional case, we check that either we have a + "badly-behaved" match (note that not all badly-behaved matches are caught + above, only *duplicate* ones); or else in the well-behaved case the match + must make progress. + + "Progress" is measured as ovector[1] strictly advancing, or, an empty match + after a non-empty match. */ + + if (gmatched > 0 && + (dat_datctl.offset <= ovector[0] && ovector[0] <= ovector[1]) && + !(pp + ovector[1] > ovecsave[1] || + (ovector[1] == ovector[0] && ovecsave[1] != ovecsave[0] && + pp + ovector[1] == ovecsave[1]))) + { + cfprintf(clr_test_error, outfile, + "** PCRE2 error: global repeat did not make progress\n"); + return PR_ABEND; + } + + ovecsave[0] = pp + ovector[0]; + ovecsave[1] = pp + ovector[1]; + + /* "allcaptures" requests showing of all captures in the pattern, to check + unset ones at the end. It may be set on the pattern or the data. Implement + by setting capcount to the maximum. This is not relevant for DFA matching, + so ignore it (warning given above). */ + + if ((dat_datctl.control & (CTL_ALLCAPTURES|CTL_DFA)) == CTL_ALLCAPTURES) + { + capcount = maxcapcount + 1; /* Allow for full match */ + if ((unsigned)capcount > oveccount) capcount = oveccount; + } + + /* "allvector" request showing the entire ovector. */ + + if ((dat_datctl.control2 & CTL2_ALLVECTOR) != 0) capcount = oveccount; + + /* Output the captured substrings. Note that, for the matched string, + the use of \K in an assertion can make the start later than the end. */ + + for (int i = 0; i < 2*capcount; i += 2) + { + PCRE2_SIZE lleft, lmiddle, lright; + PCRE2_SIZE start = ovector[i]; + PCRE2_SIZE end = ovector[i+1]; + + if (start > end) + { + start = ovector[i+1]; + end = ovector[i]; + cfprintf(clr_api_error, outfile, "Start of matched string is beyond its end - " + "displaying from end to start.\n"); + } + + fprintf(outfile, "%2d: ", i/2); + + /* Check for an unset group */ + + if (start == PCRE2_UNSET && end == PCRE2_UNSET) + { + fprintf(outfile, "\n"); + continue; + } + + /* Check for silly offsets, in particular, values that have not been + set when they should have been. However, if we are past the end of the + captures for this pattern ("allvector" causes this), or if we are DFA + matching, it isn't an error if the entry is unchanged. */ + + if (start > ulen || end > ulen) + { + if (((dat_datctl.control & CTL_DFA) != 0 || + i >= (int)(2*maxcapcount + 2)) && + start == JUNK_OFFSET && end == JUNK_OFFSET) + fprintf(outfile, "\n"); + else + cfprintf(clr_test_error, outfile, "** ERROR: bad value(s) for offset(s): 0x%lx 0x%lx\n", + (unsigned long int)start, (unsigned long int)end); + continue; + } + + /* When JIT is not being used, ALLUSEDTEXT may be set. (It if is set with + JIT, it is disabled above, with a comment.) When the match is done by the + interpreter, leftchar and rightchar are available, and if ALLUSEDTEXT is + set, and if the leftmost consulted character is before the start of the + match or the rightmost consulted character is past the end of the match, + we want to show all consulted characters for the main matched string, and + indicate which were lookarounds. */ + + if (i == 0) + { + BOOL showallused; + PCRE2_SIZE leftchar, rightchar; + + if ((dat_datctl.control & CTL_ALLUSEDTEXT) != 0) + { + leftchar = match_data->leftchar; + rightchar = match_data->rightchar; + showallused = i == 0 && (leftchar < start || rightchar > end); + } + else showallused = FALSE; + + if (showallused) + { + lleft = pchars(clr_none, pp + leftchar, start - leftchar, utf, outfile); + lmiddle = pchars(clr_none, pp + start, end - start, utf, outfile); + lright = pchars(clr_none, pp + end, rightchar - end, utf, outfile); + if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) + fprintf(outfile, " (JIT)"); + fprintf(outfile, "\n "); + for (j = 0; j < lleft; j++) fprintf(outfile, "<"); + for (j = 0; j < lmiddle; j++) fprintf(outfile, " "); + for (j = 0; j < lright; j++) fprintf(outfile, ">"); + } + + /* When a pattern contains \K, the start of match position may be + different to the start of the matched string. When this is the case, + show it when requested. */ + + else if ((dat_datctl.control & CTL_STARTCHAR) != 0) + { + PCRE2_SIZE startchar; + startchar = pcre2_get_startchar(match_data); + lleft = pchars(clr_none, pp + startchar, start - startchar, utf, outfile); + pchars(clr_none, pp+start, end - start, utf, outfile); + if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) + fprintf(outfile, " (JIT)"); + if (startchar != start) + { + fprintf(outfile, "\n "); + for (j = 0; j < lleft; j++) fprintf(outfile, "^"); + } + } + + /* Otherwise, just show the matched string. */ + + else + { + pchars(clr_none, pp + start, end - start, utf, outfile); + if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) + fprintf(outfile, " (JIT)"); + } + } + + /* Not the main matched string. Just show it unadorned. */ + + else + { + pchars(clr_none, pp + start, end - start, utf, outfile); + } + + fprintf(outfile, "\n"); + + /* Note: don't use the start/end variables here because we want to + show the text from what is reported as the end. */ + + if ((dat_datctl.control & CTL_ALLAFTERTEXT) != 0 || + (i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0)) + { + fprintf(outfile, "%2d+ ", i/2); + pchars(clr_none, pp + ovector[i+1], ulen - ovector[i+1], utf, outfile); + fprintf(outfile, "\n"); + } + } + + /* Output (*MARK) data if requested */ + + if ((dat_datctl.control & CTL_MARK) != 0 && + match_data->mark != NULL) + { + fprintf(outfile, "MK: "); + pchars(clr_none, match_data->mark - 1, -1, utf, outfile); + fprintf(outfile, "\n"); + } + + /* Process copy/get strings */ + + if (!copy_and_get(utf, capcount)) return PR_ABEND; + + } /* End of handling a successful match */ + + /* There was a partial match. The value of ovector[0] is the bumpalong point, + that is, startchar, not any \K point that might have been passed. When JIT is + not in use, "allusedtext" may be set, in which case we indicate the leftmost + consulted character. */ + + else if (capcount == PCRE2_ERROR_PARTIAL) + { + PCRE2_SIZE leftchar; + int backlength; + int rubriclength = 0; + + if ((dat_datctl.control & CTL_ALLUSEDTEXT) != 0) + { + leftchar = match_data->leftchar; + } + else leftchar = ovector[0]; + + cfprintf(clr_api_error, outfile, "Partial match"); + if ((dat_datctl.control & CTL_MARK) != 0 && + match_data->mark != NULL) + { + fprintf(outfile, ", mark="); + rubriclength = pchars(clr_none, match_data->mark - 1, -1, utf, outfile); + rubriclength += 7; + } + fprintf(outfile, ": "); + rubriclength += 15; + + backlength = pchars(clr_input, pp + leftchar, ovector[0] - leftchar, utf, outfile); + pchars(clr_input, pp + ovector[0], ovector[1] - ovector[0], utf, outfile); + + if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) + fprintf(outfile, " (JIT)"); + fprintf(outfile, "\n"); + + if (backlength != 0) + { + for (int i = 0; i < rubriclength; i++) fprintf(outfile, " "); + for (int i = 0; i < backlength; i++) fprintf(outfile, "<"); + fprintf(outfile, "\n"); + } + + if (ulen != ovector[1]) + cfprintf(clr_test_error, outfile, "** ovector[1] is not equal to the subject length: " + "%ld != %ld\n", (unsigned long int)ovector[1], (unsigned long int)ulen); + + /* Process copy/get strings */ + + if (!copy_and_get(utf, 1)) return PR_ABEND; + + /* "allvector" outputs the entire vector */ + + if ((dat_datctl.control2 & CTL2_ALLVECTOR) != 0) + show_ovector(ovector, oveccount); + + break; /* Out of the /g loop */ + } /* End of handling partial match */ + + /* A "normal" match failure. There will be a negative error number in + capcount. */ + + else + { + switch(capcount) + { + case PCRE2_ERROR_NOMATCH: + if (gmatched == 0) + { + cfprintf(clr_api_error, outfile, "No match"); + if ((dat_datctl.control & CTL_MARK) != 0 && + match_data->mark != NULL) + { + fprintf(outfile, ", mark = "); + pchars(clr_none, match_data->mark - 1, -1, utf, outfile); + } + if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) + fprintf(outfile, " (JIT)"); + fprintf(outfile, "\n"); + + /* "allvector" outputs the entire vector */ + + if ((dat_datctl.control2 & CTL2_ALLVECTOR) != 0) + show_ovector(ovector, oveccount); + } + break; + + case PCRE2_ERROR_BADUTFOFFSET: + cfprintf(clr_api_error, outfile, "Error %d (bad UTF-" STR(PCRE2_CODE_UNIT_WIDTH) + " offset)\n", capcount); + break; + + default: + cfprintf(clr_api_error, outfile, "Failed: error %d: ", capcount); + if (!print_error_message(capcount, "", "")) return PR_ABEND; + if (capcount <= PCRE2_ERROR_UTF8_ERR1 && + capcount >= PCRE2_ERROR_UTF32_ERR2) + { + PCRE2_SIZE startchar; + startchar = pcre2_get_startchar(match_data); + cfprintf(clr_api_error, outfile, " at offset %" SIZ_FORM, startchar); + } + fprintf(outfile, "\n"); + break; + } + + break; /* Out of the /g loop */ + } /* End of failed match handling */ + + /* Control reaches here after a match. If we are not doing a global search, + we are done. Otherwise, we adjust the parameters for the next match and + continue the matching loop. */ + + NEXT_MATCH: + + if ((dat_datctl.control & CTL_ANYGLOB) == 0) + break; + else + { + PCRE2_SIZE new_start_offset = (PCRE2_SIZE)-1; + BOOL rc_nextmatch; + + /* Use pcre2_next_match() to safely advance. This guarantees that the start + offset will advance, except after an empty match, in which case it sets + the PCRE2_NOTEMPTY_ATSTART flag to ensure the next match does not return a + duplicate. */ + + rc_nextmatch = pcre2_next_match(match_data, &new_start_offset, &g_notempty); + if (!rc_nextmatch) break; /* Out of the /g loop */ + + /* For a normal global (/g) iteration, update the start offset, leaving + other parameters alone. */ + + if ((dat_datctl.control & CTL_GLOBAL) != 0) + { + dat_datctl.offset = new_start_offset; + } + + /* For altglobal, just update the pointer and length. */ + + else + { + pp += new_start_offset; + len -= CU2BYTES(new_start_offset); + ulen -= new_start_offset; + if (arg_ulen != PCRE2_ZERO_TERMINATED) arg_ulen -= new_start_offset; + } + } + } /* End of global loop */ + +/* All matching is done; show the resulting heapframe size if requested. */ + +if ((dat_datctl.control2 & CTL2_HEAPFRAMES_SIZE) != 0 && + (dat_datctl.control & CTL_DFA) == 0) + show_heapframes_size(); + +show_memory = FALSE; +return PR_OK; +} + + + +/************************************************* +* Initialise the mode-dependent globals * +*************************************************/ + +/* Sets up the global variables used for the current test mode. */ + +static void +init_globals(void) +{ +general_context = pcre2_general_context_create(&my_malloc, &my_free, NULL); +general_context_copy = pcre2_general_context_copy(general_context); +default_pat_context = pcre2_compile_context_create(general_context); +pat_context = pcre2_compile_context_copy(default_pat_context); +default_dat_context = pcre2_match_context_create(general_context); +dat_context = pcre2_match_context_copy(default_dat_context); +default_con_context = pcre2_convert_context_create(general_context); +con_context = pcre2_convert_context_copy(default_con_context); +match_data = pcre2_match_data_create(max_oveccount, general_context); +rep_in_buffer = malloc(sizeof(PCRE2_UCHAR) * rep_in_buffer_size); +rep_out_buffer = malloc(sizeof(PCRE2_UCHAR) * rep_out_buffer_size); + +/* Set a default parentheses nest limit that is large enough to run the +standard tests (this also exercises the function). */ + +pcre2_set_parens_nest_limit(default_pat_context, PARENS_NEST_DEFAULT); +} + +/* Frees the global variables used for the current test mode. */ + +static void +free_globals(void) +{ +pcre2_maketables_free(general_context, locale_tables); +pcre2_match_data_free(match_data); +pcre2_code_free(compiled_code); + +while(patstacknext-- > 0) + { + compiled_code = patstack[patstacknext]; + pcre2_code_free(compiled_code); + } + +pcre2_jit_free_unused_memory(general_context); +if (jit_stack != NULL) + { + pcre2_jit_stack_free(jit_stack); + } + +pcre2_general_context_free(general_context); +pcre2_general_context_free(general_context_copy); +pcre2_compile_context_free(pat_context); +pcre2_compile_context_free(default_pat_context); +pcre2_match_context_free(dat_context); +pcre2_match_context_free(default_dat_context); +pcre2_convert_context_free(default_con_context); +pcre2_convert_context_free(con_context); +free(rep_in_buffer); +free(rep_out_buffer); +} + + + +/************************************************* +* Specific function tests * +*************************************************/ + +/* For tests exercising a mismatched bitmode, identify a suitable API. */ + +#if (defined(SUPPORT_PCRE2_8) + defined(SUPPORT_PCRE2_16) + \ + defined(SUPPORT_PCRE2_32)) >= 2 + +#if defined(SUPPORT_PCRE2_8) && PCRE2_CODE_UNIT_WIDTH != 8 +#define BITOTHER 8 +#elif defined(SUPPORT_PCRE2_16) && PCRE2_CODE_UNIT_WIDTH != 16 +#define BITOTHER 16 +#elif defined(SUPPORT_PCRE2_32) && PCRE2_CODE_UNIT_WIDTH != 32 +#define BITOTHER 32 +#else +#error "One other bit width must be supported" +#endif + +#endif + +/* These are tests of the public API functions in PCRE2, which wouldn't +otherwise be covered by pcre2test. This usually implies they are error cases, +or edge cases that are hard to hit in the standard flow of compile-match or +compile-substitute. + +I think of them as perhaps more like unit tests, although they are still testing +the public API, rather than internal modules. + +Inside pcre2test, which can be dynamically linked to lib-pcreX.so, we don't +have access to any non-exported functions. */ + +static void +unittest(void) +{ +int rc; +uint32_t uval; +PCRE2_SIZE sizeval; +PCRE2_UCHAR *sptrval; +const char *failure = NULL; +pcre2_general_context *test_gen_context = NULL, *test_gen_context_copy = NULL; +pcre2_compile_context *test_pat_context = NULL, *test_pat_context_copy = NULL; +pcre2_match_context *test_dat_context = NULL, *test_dat_context_copy = NULL; +pcre2_convert_context *test_con_context = NULL, *test_con_context_copy = NULL; +pcre2_match_data *test_match_data = NULL; +pcre2_code *test_compiled_code = NULL; +PCRE2_UCHAR pattern[] = { CHAR_A, CHAR_B, CHAR_C, 0 }; +PCRE2_UCHAR callout_int_pattern[] = { + CHAR_LEFT_PARENTHESIS, CHAR_QUESTION_MARK, CHAR_C, CHAR_RIGHT_PARENTHESIS, 0 }; +PCRE2_UCHAR callout_str_pattern[] = { + CHAR_LEFT_PARENTHESIS, CHAR_QUESTION_MARK, CHAR_C, CHAR_QUOTATION_MARK, + CHAR_Z, CHAR_QUOTATION_MARK, CHAR_RIGHT_PARENTHESIS, 0 }; +PCRE2_UCHAR capture_pattern[] = { + CHAR_A, CHAR_LEFT_PARENTHESIS, CHAR_QUESTION_MARK, CHAR_LESS_THAN_SIGN, + CHAR_N, CHAR_GREATER_THAN_SIGN, CHAR_DOT, CHAR_ASTERISK, + CHAR_RIGHT_PARENTHESIS, CHAR_Z, 0 }; +PCRE2_UCHAR subject_abcz[] = { + CHAR_A, CHAR_B, CHAR_C, CHAR_Z, 0 }; +PCRE2_UCHAR substitute_subject[6]; +PCRE2_UCHAR name_n[] = { CHAR_N, 0 }; +#ifdef BITOTHER +G(pcre2_code_,BITOTHER) *bitother_code = NULL; +G(PCRE2_,G(UCHAR,BITOTHER)) bitother_pattern[] = { CHAR_A, CHAR_B, CHAR_C, 0 }; +#endif +int errorcode; +PCRE2_SIZE erroroffset; +PCRE2_UCHAR errorbuffer[256]; +#if PCRE2_CODE_UNIT_WIDTH == 8 +char errorbuffer8[256]; +regex_t test_preg; +#endif +void *invalid_code = NULL; +const uint8_t *test_tables = NULL; +PCRE2_UCHAR copy_buf[64]; +PCRE2_UCHAR **stringlist; +PCRE2_SIZE *lengthslist; +PCRE2_UCHAR replace_buf[64]; +pcre2_code *subs_other_code = NULL; + +#if PCRE2_CODE_UNIT_WIDTH == 8 +memset(&test_preg, 0, sizeof(test_preg)); +#endif + +#if defined PCRE2_DEBUG && !defined NDEBUG +#define ASSERT(cond, msg) \ + do { \ + if (!(cond)) { failure = msg " at " __FILE__ ":" STR(__LINE__); goto EXIT; } \ + } while (0) +#else +#define ASSERT(cond, msg) \ + do { \ + if (!(cond)) { failure = msg; goto EXIT; } \ + } while (0) +#endif + +/* -------------------------- pcre2_config --------------------------------- */ + +rc = pcre2_config(PCRE2_CONFIG_BSR, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_COMPILED_WIDTHS, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_DEPTHLIMIT, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_EFFECTIVE_LINKSIZE, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_HEAPLIMIT, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_JIT, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_LINKSIZE, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_MATCHLIMIT, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_NEVER_BACKSLASH_C, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_NEWLINE, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_PARENSLIMIT, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_STACKRECURSE, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_TABLES_LENGTH, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_UNICODE, NULL); +ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); + +#ifdef SUPPORT_JIT +rc = pcre2_config(PCRE2_CONFIG_JITTARGET, NULL); +ASSERT(rc > 0, "pcre2_config(NULL)"); +#endif +rc = pcre2_config(PCRE2_CONFIG_UNICODE_VERSION, NULL); +ASSERT(rc > 4, "pcre2_config(NULL)"); +rc = pcre2_config(PCRE2_CONFIG_VERSION, NULL); +ASSERT(rc > 4, "pcre2_config(NULL)"); + +rc = pcre2_config(PCRE2_CONFIG_MATCHLIMIT, &uval); +ASSERT(rc == 0, "pcre2_config(PCRE2_CONFIG_MATCHLIMIT)"); + +rc = pcre2_config(999, NULL); +ASSERT(rc == PCRE2_ERROR_BADOPTION, "pcre2_config(bad option)"); + +rc = pcre2_config(999, &uval); +ASSERT(rc == PCRE2_ERROR_BADOPTION, "pcre2_config(bad option)"); + +rc = pcre2_config(PCRE2_CONFIG_STACKRECURSE, &uval); +ASSERT(rc == 0, "pcre2_config(PCRE2_CONFIG_STACKRECURSE)"); + +rc = pcre2_config(PCRE2_CONFIG_LINKSIZE, &uval); +ASSERT(rc == 0, "pcre2_config(PCRE2_CONFIG_LINKSIZE)"); + +/* ------------------------ Context functions ------------------------------ */ + +test_gen_context = pcre2_general_context_create(NULL, NULL, NULL); +ASSERT(test_gen_context != NULL, "pcre2_general_context_create(null)"); +pcre2_general_context_free(test_gen_context); + +mallocs_until_failure = 0; +test_gen_context = pcre2_general_context_create(&my_malloc, &my_free, NULL); +ASSERT(test_gen_context == NULL, "pcre2_general_context_create(malloc)"); + +mallocs_until_failure = 1; +test_gen_context = pcre2_general_context_create(&my_malloc, &my_free, NULL); +ASSERT(test_gen_context != NULL, "pcre2_general_context_create(malloc)"); + +test_pat_context = pcre2_compile_context_create(test_gen_context); +ASSERT(test_pat_context == NULL, "pcre2_compile_context_create()"); +test_dat_context = pcre2_match_context_create(test_gen_context); +ASSERT(test_dat_context == NULL, "pcre2_match_context_create()"); +test_con_context = pcre2_convert_context_create(test_gen_context); +ASSERT(test_con_context == NULL, "pcre2_convert_context_create()"); + +test_pat_context = pcre2_compile_context_create(NULL); +ASSERT(test_pat_context != NULL, "pcre2_compile_context_create(null)"); +pcre2_compile_context_free(test_pat_context); +test_dat_context = pcre2_match_context_create(NULL); +ASSERT(test_dat_context != NULL, "pcre2_match_context_create(null)"); +pcre2_match_context_free(test_dat_context); +test_con_context = pcre2_convert_context_create(NULL); +ASSERT(test_con_context != NULL, "pcre2_convert_context_create(null)"); +pcre2_convert_context_free(test_con_context); + +mallocs_until_failure = INT_MAX; +test_pat_context = pcre2_compile_context_create(test_gen_context); +ASSERT(test_pat_context != NULL, "pcre2_compile_context_create()"); +test_dat_context = pcre2_match_context_create(test_gen_context); +ASSERT(test_dat_context != NULL, "pcre2_match_context_create()"); +test_con_context = pcre2_convert_context_create(test_gen_context); +ASSERT(test_con_context != NULL, "pcre2_convert_context_create()"); + +mallocs_until_failure = 0; +test_gen_context_copy = pcre2_general_context_copy(test_gen_context); +ASSERT(test_gen_context_copy == NULL, "pcre2_general_context_copy()"); +test_pat_context_copy = pcre2_compile_context_copy(test_pat_context); +ASSERT(test_pat_context_copy == NULL, "pcre2_compile_context_copy()"); +test_dat_context_copy = pcre2_match_context_copy(test_dat_context); +ASSERT(test_dat_context_copy == NULL, "pcre2_match_context_copy()"); +test_con_context_copy = pcre2_convert_context_copy(test_con_context); +ASSERT(test_con_context_copy == NULL, "pcre2_convert_context_copy()"); + +mallocs_until_failure = INT_MAX; +test_gen_context_copy = pcre2_general_context_copy(test_gen_context); +ASSERT(test_gen_context_copy != NULL, "pcre2_general_context_copy()"); +test_pat_context_copy = pcre2_compile_context_copy(test_pat_context); +ASSERT(test_pat_context_copy != NULL, "pcre2_compile_context_copy()"); +test_dat_context_copy = pcre2_match_context_copy(test_dat_context); +ASSERT(test_dat_context_copy != NULL, "pcre2_match_context_copy()"); +test_con_context_copy = pcre2_convert_context_copy(test_con_context); +ASSERT(test_con_context_copy != NULL, "pcre2_convert_context_copy()"); + +rc = pcre2_set_compile_extra_options(test_pat_context, 0); +ASSERT(rc == 0, "pcre2_set_compile_extra_options()"); + +rc = pcre2_set_max_pattern_length(test_pat_context, 10); +ASSERT(rc == 0, "pcre2_set_max_pattern_length()"); + +rc = pcre2_set_max_pattern_compiled_length(test_pat_context, 256); +ASSERT(rc == 0, "pcre2_set_max_pattern_compiled_length()"); + +rc = pcre2_set_max_varlookbehind(test_pat_context, 0); +ASSERT(rc == 0, "pcre2_set_max_varlookbehind()"); + +rc = pcre2_set_offset_limit(test_dat_context, 0); +ASSERT(rc == 0, "pcre2_set_offset_limit()"); + +rc = pcre2_set_bsr(test_pat_context, 999); +ASSERT(rc == PCRE2_ERROR_BADDATA, "pcre2_set_bsr()"); + +rc = pcre2_set_newline(test_pat_context, 999); +ASSERT(rc == PCRE2_ERROR_BADDATA, "pcre2_set_newline()"); + +rc = pcre2_set_recursion_limit(test_dat_context, 10); +ASSERT(rc == 0, "pcre2_set_recursion_limit()"); + +rc = pcre2_set_recursion_memory_management(test_dat_context, NULL, NULL, NULL); +ASSERT(rc == 0, "pcre2_set_recursion_memory_management()"); + +rc = pcre2_set_optimize(NULL, PCRE2_OPTIMIZATION_NONE); +ASSERT(rc == PCRE2_ERROR_NULL, "pcre2_set_optimize(null)"); + +rc = pcre2_set_optimize(test_pat_context, PCRE2_AUTO_POSSESS - 1); +ASSERT(rc == PCRE2_ERROR_BADOPTION, "pcre2_set_optimize(bad option)"); + +rc = pcre2_set_optimize(test_pat_context, PCRE2_START_OPTIMIZE_OFF + 1); +ASSERT(rc == PCRE2_ERROR_BADOPTION, "pcre2_set_optimize(bad option)"); + +rc = pcre2_set_glob_escape(test_con_context, 0); +ASSERT(rc == 0, "pcre2_set_glob_escape(0)"); + +rc = pcre2_set_glob_escape(test_con_context, 1); +ASSERT(rc == PCRE2_ERROR_BADDATA, "pcre2_set_glob_escape(1)"); + +rc = pcre2_set_glob_escape(test_con_context, 256); +ASSERT(rc == PCRE2_ERROR_BADDATA, "pcre2_set_glob_escape(256)"); + +/* ----------------------- pcre2_compile ----------------------------------- */ + +test_compiled_code = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, + 0, NULL, &erroroffset, test_pat_context); +ASSERT(test_compiled_code == NULL, "test pattern compilation"); + +test_compiled_code = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, + 0, &errorcode, NULL, test_pat_context); +ASSERT(test_compiled_code == NULL && errorcode == PCRE2_ERROR_NULL_ERROROFFSET, "test pattern compilation"); + +test_compiled_code = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, + 0, &errorcode, &erroroffset, test_pat_context); +ASSERT(test_compiled_code != NULL && errorcode == 100 && erroroffset == 0, "test pattern compilation"); + +#ifdef BITOTHER +bitother_code = G(pcre2_compile_,BITOTHER)(bitother_pattern, + PCRE2_ZERO_TERMINATED, 0, &errorcode, &erroroffset, NULL); +ASSERT(bitother_code != NULL, "bitmode mismatch compile"); +#endif + +/* ---------------------- Match data functions ----------------------------- */ + +mallocs_until_failure = 0; +test_match_data = pcre2_match_data_create(10, test_gen_context); +ASSERT(test_match_data == NULL, "pcre2_match_data_create()"); + +test_match_data = pcre2_match_data_create(10, NULL); +ASSERT(test_match_data != NULL, "pcre2_match_data_create()"); +ASSERT(pcre2_get_ovector_count(test_match_data) == 10, "pcre2_get_ovector_count()"); + +sizeval = pcre2_get_match_data_size(test_match_data); +ASSERT(sizeval >= 2, "pcre2_get_match_data_size()"); + +mallocs_until_failure = INT_MAX; + +pcre2_match_data_free(test_match_data); +test_match_data = pcre2_match_data_create(0, test_gen_context); +ASSERT(test_match_data != NULL, "pcre2_match_data_create()"); +ASSERT(pcre2_get_ovector_count(test_match_data) == 1, "pcre2_get_ovector_count()"); + +pcre2_match_data_free(test_match_data); +test_match_data = pcre2_match_data_create_from_pattern(NULL, NULL); +ASSERT(test_match_data == NULL, "pcre2_match_data_create_from_pattern(null)"); + +test_match_data = pcre2_match_data_create_from_pattern(test_compiled_code, NULL); +ASSERT(test_match_data != NULL, "pcre2_match_data_create_from_pattern()"); +ASSERT(pcre2_get_ovector_count(test_match_data) == 1, "pcre2_get_ovector_count()"); + +mallocs_until_failure = 0; +pcre2_match_data_free(test_match_data); +test_match_data = pcre2_match_data_create_from_pattern(test_compiled_code, + test_gen_context); +ASSERT(test_match_data == NULL, "pcre2_match_data_create_from_pattern()"); + +mallocs_until_failure = INT_MAX; +pcre2_match_data_free(test_match_data); +test_match_data = pcre2_match_data_create_from_pattern(test_compiled_code, + test_gen_context); +ASSERT(test_match_data != NULL, "pcre2_match_data_create_from_pattern()"); + +rc = pcre2_match(test_compiled_code, pattern, PCRE2_ZERO_TERMINATED, 0, + PCRE2_COPY_MATCHED_SUBJECT, test_match_data, NULL); +ASSERT(rc == 1, "pcre2_match()"); + +pcre2_match_data_free(test_match_data); +test_match_data = NULL; + +/* ----------------------- pcre2_pattern_info ------------------------------ */ + +rc = pcre2_pattern_info(NULL, PCRE2_INFO_NEWLINE, &uval); +ASSERT(rc == PCRE2_ERROR_NULL, "pcre2_pattern_info(null)"); + +rc = pcre2_pattern_info(test_compiled_code, 999, NULL); +ASSERT(rc == PCRE2_ERROR_BADOPTION, "pcre2_pattern_info(bad option)"); + +rc = pcre2_pattern_info(test_compiled_code, 999, &uval); +ASSERT(rc == PCRE2_ERROR_BADOPTION, "pcre2_pattern_info(bad option)"); + +invalid_code = malloc(1024); +ASSERT(invalid_code != NULL, "malloc()"); +memset(invalid_code, 0, 1024); +rc = pcre2_pattern_info(invalid_code, PCRE2_INFO_NEWLINE, &uval); +ASSERT(rc == PCRE2_ERROR_BADMAGIC, "pcre2_pattern_info(bad magic)"); + +#ifdef BITOTHER +rc = pcre2_pattern_info((pcre2_code *)bitother_code, PCRE2_INFO_NEWLINE, &uval); +ASSERT(rc == PCRE2_ERROR_BADMODE, "pcre2_pattern_info(bitmode mismatch)"); +#endif + +#ifdef SUPPORT_JIT +sizeval = 0xcdcdcdcd; +rc = pcre2_pattern_info(test_compiled_code, PCRE2_INFO_JITSIZE, &sizeval); +ASSERT(rc == 0 && sizeval == 0, "pcre2_pattern_info(JIT)"); + +if (pcre2_jit_compile(test_compiled_code, PCRE2_JIT_COMPLETE) == 0) + { + rc = pcre2_pattern_info(test_compiled_code, PCRE2_INFO_JITSIZE, &sizeval); + ASSERT(rc == 0 && sizeval > 0, "pcre2_pattern_info(JIT after compile)"); + } +#endif + +/* ----------------------- POSIX functions --------------------------------- */ + +#if PCRE2_CODE_UNIT_WIDTH == 8 + +#if defined(EBCDIC) && !EBCDIC_IO +#define BUFFER_OUTPUT ebcdic_to_ascii_str((uint8_t *)errorbuffer8, sizeof(errorbuffer8)); +#else +#define BUFFER_OUTPUT +#endif + +rc = pcre2_regcomp(&test_preg, "abc", 0); +ASSERT(rc == 0, "pcre2_regcomp()"); + +rc = pcre2_regexec(&test_preg, "zabcz", 0, NULL, 0); +ASSERT(rc == 0, "pcre2_regexec(0)"); + +rc = pcre2_regexec(&test_preg, "zabcz", 0, NULL, REG_STARTEND); +ASSERT(rc == REG_INVARG, "pcre2_regexec(REG_STARTEND)"); + +memset(errorbuffer8, 0, sizeof(errorbuffer8)); +rc = regerror(REG_ASSERT, NULL, errorbuffer8, sizeof(errorbuffer8)); +BUFFER_OUTPUT +ASSERT(rc > 0 && rc <= (int)sizeof(errorbuffer8) && rc == (int)strlen(errorbuffer8) + 1, "regerror()"); + +rc = regerror(REG_NOMATCH, NULL, errorbuffer8, sizeof(errorbuffer8)); +BUFFER_OUTPUT +ASSERT(rc > 0 && rc <= (int)sizeof(errorbuffer8) && rc == (int)strlen(errorbuffer8) + 1, "regerror()"); + +rc = regerror(REG_ASSERT-1, NULL, errorbuffer8, sizeof(errorbuffer8)); +BUFFER_OUTPUT +ASSERT(rc == (int)strlen("unknown error code")+1 && strcmp(errorbuffer8, "unknown error code") == 0, "regerror(bad error code)"); + +rc = regerror(REG_NOMATCH+1, NULL, errorbuffer8, sizeof(errorbuffer8)); +BUFFER_OUTPUT +ASSERT(rc == (int)strlen("unknown error code")+1 && strcmp(errorbuffer8, "unknown error code") == 0, "regerror(bad error code)"); + +#undef BUFFER_OUTPUT + +#endif + +/* -------------------- pcre2_get_error_message ---------------------------- */ + +#if defined(EBCDIC) && !EBCDIC_IO +#define BUFFER_OUTPUT ebcdic_to_ascii_str(errorbuffer, sizeof(errorbuffer)); +#else +#define BUFFER_OUTPUT +#endif + +rc = pcre2_get_error_message(PCRE2_ERROR_BADDATA, NULL, 0); +ASSERT(rc == PCRE2_ERROR_NOMEMORY, "pcre2_get_error_message(null)"); + +memset(errorbuffer, 0, sizeof(errorbuffer)); +rc = pcre2_get_error_message(PCRE2_ERROR_BADDATA, errorbuffer, 0); +BUFFER_OUTPUT +ASSERT(rc == PCRE2_ERROR_NOMEMORY, "pcre2_get_error_message(null)"); + +rc = pcre2_get_error_message(PCRE2_ERROR_BADDATA, errorbuffer, 4); +BUFFER_OUTPUT +ASSERT(rc == PCRE2_ERROR_NOMEMORY && pcre2_strcmp_c8(errorbuffer, "bad") == 0, "pcre2_get_error_message(null)"); + +rc = pcre2_get_error_message(PCRE2_ERROR_BADDATA, errorbuffer, 14); +BUFFER_OUTPUT +ASSERT(rc == PCRE2_ERROR_NOMEMORY && pcre2_strcmp_c8(errorbuffer, "bad data valu") == 0, "pcre2_get_error_message(null)"); + +rc = pcre2_get_error_message(PCRE2_ERROR_BADDATA, errorbuffer, 15); +BUFFER_OUTPUT +ASSERT(rc == 14 && pcre2_strcmp_c8(errorbuffer, "bad data value") == 0, "pcre2_get_error_message(null)"); + +#undef BUFFER_OUTPUT + +/* ----------------------- pcre2_maketables -------------------------------- */ + +test_tables = pcre2_maketables(NULL); +ASSERT(test_tables != NULL, "pcre2_maketables(null)"); +pcre2_maketables_free(NULL, test_tables); + +test_tables = pcre2_maketables(test_gen_context); +ASSERT(test_tables != NULL, "pcre2_maketables()"); +pcre2_maketables_free(test_gen_context, test_tables); + +mallocs_until_failure = 0; +test_tables = pcre2_maketables(test_gen_context); +ASSERT(test_tables == NULL, "pcre2_maketables()"); + +mallocs_until_failure = INT_MAX; + +/* -------------------- pcre2_callout_enumerate ---------------------------- */ + +rc = pcre2_callout_enumerate(NULL, callout_enumerate_function_void, NULL); +ASSERT(rc == PCRE2_ERROR_NULL, "pcre2_callout_enumerate(null)"); + +rc = pcre2_callout_enumerate(invalid_code, callout_enumerate_function_void, NULL); +ASSERT(rc == PCRE2_ERROR_BADMAGIC, "pcre2_callout_enumerate(invalid)"); + +#ifdef BITOTHER +rc = pcre2_callout_enumerate((pcre2_code *)bitother_code, callout_enumerate_function_void, NULL); +ASSERT(rc == PCRE2_ERROR_BADMODE, "pcre2_callout_enumerate(bitmode mismatch)"); +#endif + +pcre2_code_free(test_compiled_code); +test_compiled_code = pcre2_compile(callout_int_pattern, PCRE2_ZERO_TERMINATED, + 0, &errorcode, &erroroffset, NULL); +ASSERT(test_compiled_code != NULL, "test pattern compilation"); + +rc = pcre2_callout_enumerate(test_compiled_code, callout_enumerate_function_void, &errorcode); +ASSERT(rc == 0, "pcre2_callout_enumerate(void)"); + +errorcode = -12; +rc = pcre2_callout_enumerate(test_compiled_code, callout_enumerate_function_fail, &errorcode); +ASSERT(rc == -12, "pcre2_callout_enumerate(fail)"); + +pcre2_code_free(test_compiled_code); +test_compiled_code = pcre2_compile(callout_str_pattern, PCRE2_ZERO_TERMINATED, + 0, &errorcode, &erroroffset, NULL); +ASSERT(test_compiled_code != NULL, "test pattern compilation"); + +errorcode = -123; +rc = pcre2_callout_enumerate(test_compiled_code, callout_enumerate_function_fail, &errorcode); +ASSERT(rc == -123, "pcre2_callout_enumerate(fail)"); + +/* ---------------------- Substring functions ------------------------------ */ + +/* Must handle NULL without crashing. */ +pcre2_substring_free(NULL); +pcre2_substring_list_free(NULL); + +pcre2_code_free(test_compiled_code); +test_compiled_code = pcre2_compile(capture_pattern, PCRE2_ZERO_TERMINATED, + 0, &errorcode, &erroroffset, NULL); +ASSERT(test_compiled_code != NULL, "test pattern compilation"); + +pcre2_match_data_free(test_match_data); +test_match_data = pcre2_match_data_create_from_pattern( + test_compiled_code, test_gen_context); +ASSERT(test_match_data != NULL, "pcre2_match_data_create()"); + +rc = pcre2_match(test_compiled_code, subject_abcz, PCRE2_ZERO_TERMINATED, 0, + 0, test_match_data, NULL); +ASSERT(rc == 2, "pcre2_match()"); + +/* Test the functions with insufficient buffer size. It hardly seems worth +adding controls to the pcre2test input file format to exercise this case. */ + +sizeval = 2; +rc = pcre2_substring_copy_byname(test_match_data, name_n, copy_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMEMORY && sizeval == 2, "pcre2_substring_copy_byname(small buffer)"); +sizeval = 3; +rc = pcre2_substring_copy_byname(test_match_data, name_n, copy_buf, &sizeval); +ASSERT(rc == 0 && sizeval == 2, "pcre2_substring_copy_byname(small buffer)"); +sizeval = 4; +rc = pcre2_substring_copy_byname(test_match_data, name_n, copy_buf, &sizeval); +ASSERT(rc == 0 && sizeval == 2, "pcre2_substring_copy_byname(small buffer)"); + +sizeval = 2; +rc = pcre2_substring_copy_bynumber(test_match_data, 1, copy_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMEMORY && sizeval == 2, "pcre2_substring_copy_bynumber(small buffer)"); +sizeval = 3; +rc = pcre2_substring_copy_bynumber(test_match_data, 1, copy_buf, &sizeval); +ASSERT(rc == 0 && sizeval == 2, "pcre2_substring_copy_bynumber(small buffer)"); + +mallocs_until_failure = 0; + +sizeval = 0; +sptrval = NULL; +rc = pcre2_substring_get_byname(test_match_data, name_n, &sptrval, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMEMORY && sptrval == NULL, "pcre2_substring_get_byname(small buffer)"); + +sizeval = 0; +rc = pcre2_substring_get_bynumber(test_match_data, 1, &sptrval, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMEMORY && sptrval == NULL, "pcre2_substring_get_bynumber(small buffer)"); + +mallocs_until_failure = INT_MAX; + +/* Test some unusual conditions, for which again it doesn't seem worth adding +pcre2test controls. */ + +sizeval = 0; +rc = pcre2_substring_length_bynumber(test_match_data, 1, &sizeval); +ASSERT(rc == 0 && sizeval == 2, "pcre2_substring_length_bynumber()"); +rc = pcre2_substring_length_bynumber(test_match_data, 1, NULL); +ASSERT(rc == 0, "pcre2_substring_length_bynumber()"); + +sizeval = 0; +rc = pcre2_substring_length_byname(test_match_data, name_n, &sizeval); +ASSERT(rc == 0 && sizeval == 2, "pcre2_substring_length_byname()"); +rc = pcre2_substring_length_byname(test_match_data, name_n, NULL); +ASSERT(rc == 0, "pcre2_substring_length_byname()"); + +/* Test pcre2_substring_list_get() with some NULL inputs. */ + +rc = pcre2_substring_list_get(test_match_data, &stringlist, &lengthslist); +ASSERT(rc == 0 && stringlist != NULL && lengthslist != NULL, "pcre2_substring_list_get()"); +pcre2_substring_list_free(stringlist); + +stringlist = NULL; +rc = pcre2_substring_list_get(test_match_data, &stringlist, NULL); +ASSERT(rc == 0 && stringlist != NULL, "pcre2_substring_list_get()"); +pcre2_substring_list_free(stringlist); + +mallocs_until_failure = 0; + +stringlist = NULL; +rc = pcre2_substring_list_get(test_match_data, &stringlist, &lengthslist); +ASSERT(rc == PCRE2_ERROR_NOMEMORY && stringlist == NULL, "pcre2_substring_list_get()"); + +mallocs_until_failure = INT_MAX; + +/* Test after an unsuccessful match. */ + +rc = pcre2_match(test_compiled_code, subject_abcz, PCRE2_ZERO_TERMINATED, 2, + 0, test_match_data, NULL); +ASSERT(rc == PCRE2_ERROR_NOMATCH, "pcre2_match()"); + +sizeval = 4; +rc = pcre2_substring_copy_byname(test_match_data, name_n, copy_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMATCH, "pcre2_substring_copy_byname(no match)"); +rc = pcre2_substring_copy_bynumber(test_match_data, 1, copy_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMATCH, "pcre2_substring_copy_bynumber(no match)"); +rc = pcre2_substring_get_byname(test_match_data, name_n, &sptrval, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMATCH && sptrval == NULL, "pcre2_substring_get_byname(no match)"); +rc = pcre2_substring_get_bynumber(test_match_data, 1, &sptrval, &sizeval); +ASSERT(rc == PCRE2_ERROR_NOMATCH && sptrval == NULL, "pcre2_substring_get_bynumber(no match)"); + +/* ------------- pcre2_substitute with PCRE2_SUBSTITUTE_MATCHED ------------ */ + +/* There are some specific edge cases here that would be a pain to exercise via +the standard pcre2test modifiers. The documentation is clear that when you do +a match externally and pass it in with PCRE2_SUBSTITUTE_MATCHED, you must also +pass the same match options. Here we test what happens when you don't. */ + +pcre2_code_free(test_compiled_code); +test_compiled_code = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, + 0, &errorcode, &erroroffset, NULL); +ASSERT(test_compiled_code != NULL, "test pattern compilation"); + +subs_other_code = pcre2_compile(pattern, PCRE2_ZERO_TERMINATED, + 0, &errorcode, &erroroffset, NULL); +ASSERT(subs_other_code != NULL, "test pattern compilation"); + +pcre2_match_data_free(test_match_data); +test_match_data = pcre2_match_data_create_from_pattern( + test_compiled_code, NULL); +ASSERT(test_match_data != NULL, "pcre2_match_data_create()"); + +memcpy(substitute_subject, subject_abcz, sizeof(subject_abcz)); +rc = pcre2_match(test_compiled_code, substitute_subject, PCRE2_ZERO_TERMINATED, + 0, 0, test_match_data, NULL); +ASSERT(rc == 1, "pcre2_match()"); + +/* Baseline, should succeed */ +memcpy(substitute_subject, subject_abcz, sizeof(subject_abcz)); +sizeval = sizeof(replace_buf)/sizeof(*replace_buf); +rc = pcre2_substitute(test_compiled_code, substitute_subject, + PCRE2_ZERO_TERMINATED, 0, PCRE2_SUBSTITUTE_MATCHED, test_match_data, NULL, + NULL, 0, replace_buf, &sizeval); +ASSERT(rc == 1, "pcre2_substitute(baseline)"); + +/* Move the subject pointer, but keep the contents and length the same */ +memcpy(substitute_subject+1, subject_abcz, sizeof(subject_abcz)); +sizeval = sizeof(replace_buf)/sizeof(*replace_buf); +rc = pcre2_substitute(test_compiled_code, substitute_subject+1, + PCRE2_ZERO_TERMINATED, 0, PCRE2_SUBSTITUTE_MATCHED, test_match_data, NULL, + NULL, 0, replace_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_DIFFSUBSSUBJECT, "pcre2_substitute(moved)"); + +/* Keep the subject pointer the same but extend its length */ +memcpy(substitute_subject, subject_abcz, sizeof(subject_abcz)); +substitute_subject[4] = CHAR_Y; +substitute_subject[5] = 0; +sizeval = sizeof(replace_buf)/sizeof(*replace_buf); +rc = pcre2_substitute(test_compiled_code, substitute_subject, + PCRE2_ZERO_TERMINATED, 0, PCRE2_SUBSTITUTE_MATCHED, test_match_data, NULL, + NULL, 0, replace_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_DIFFSUBSSUBJECT, "pcre2_substitute(extended)"); + +/* Change the offset */ +memcpy(substitute_subject, subject_abcz, sizeof(subject_abcz)); +sizeval = sizeof(replace_buf)/sizeof(*replace_buf); +rc = pcre2_substitute(test_compiled_code, substitute_subject, + PCRE2_ZERO_TERMINATED, 1, PCRE2_SUBSTITUTE_MATCHED, test_match_data, NULL, + NULL, 0, replace_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_DIFFSUBSOFFSET, "pcre2_substitute(offset)"); + +/* Change the options */ +memcpy(substitute_subject, subject_abcz, sizeof(subject_abcz)); +sizeval = sizeof(replace_buf)/sizeof(*replace_buf); +rc = pcre2_substitute(test_compiled_code, substitute_subject, + PCRE2_ZERO_TERMINATED, 0, PCRE2_SUBSTITUTE_MATCHED | PCRE2_NOTEMPTY, + test_match_data, NULL, NULL, 0, replace_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_DIFFSUBSOPTIONS, "pcre2_substitute(options)"); + +/* Change the pattern */ +memcpy(substitute_subject, subject_abcz, sizeof(subject_abcz)); +sizeval = sizeof(replace_buf)/sizeof(*replace_buf); +rc = pcre2_substitute(subs_other_code, substitute_subject, + PCRE2_ZERO_TERMINATED, 0, PCRE2_SUBSTITUTE_MATCHED, test_match_data, NULL, + NULL, 0, replace_buf, &sizeval); +ASSERT(rc == PCRE2_ERROR_DIFFSUBSPATTERN, "pcre2_substitute(pattern)"); + +/* ------------------------------------------------------------------------- */ + +#undef ASSERT +EXIT: + +mallocs_until_failure = INT_MAX; + +#if PCRE2_CODE_UNIT_WIDTH == 8 +pcre2_regfree(&test_preg); +#endif + +if (test_compiled_code != NULL) pcre2_code_free(test_compiled_code); +#ifdef BITOTHER +if (bitother_code != NULL) G(pcre2_code_free_,BITOTHER)(bitother_code); +#endif +if (subs_other_code != NULL) pcre2_code_free(subs_other_code); + +if (test_match_data != NULL) pcre2_match_data_free(test_match_data); + +if (test_con_context_copy != NULL) pcre2_convert_context_free(test_con_context_copy); +if (test_dat_context_copy != NULL) pcre2_match_context_free(test_dat_context_copy); +if (test_pat_context_copy != NULL) pcre2_compile_context_free(test_pat_context_copy); +if (test_gen_context_copy != NULL) pcre2_general_context_free(test_gen_context_copy); +if (test_con_context != NULL) pcre2_convert_context_free(test_con_context); +if (test_dat_context != NULL) pcre2_match_context_free(test_dat_context); +if (test_pat_context != NULL) pcre2_compile_context_free(test_pat_context); +if (test_gen_context != NULL) pcre2_general_context_free(test_gen_context); + +free(invalid_code); + +if (failure != NULL) + { + cfprintf(clr_test_error, stderr, "pcre2test: Unit test error in %s\n", failure); + exit(1); + } +} + +#undef BITOTHER + + +/* -------------------- Undo the macro definitions --------------------------*/ + +#undef pbuffer +#undef pbuffer_size + +#undef utf_to_ord + +#undef compiled_code +#undef general_context +#undef general_context_copy +#undef pat_context +#undef default_pat_context +#undef con_context +#undef default_con_context +#undef dat_context +#undef default_dat_context +#undef match_data +#undef jit_stack +#undef jit_stack_size +#undef patstack +#undef patstacknext +#undef rep_in_buffer +#undef rep_in_buffer_size +#undef rep_out_buffer +#undef rep_out_buffer_size + +#undef jit_callback +#undef pcre2_strcmp_c8 +#undef pcre2_strlen +#undef pchars +#undef ptrunc +#undef config_str +#undef check_modifier +#undef decode_modifiers +#undef pattern_info +#undef show_memory_info +#undef show_framesize +#undef show_heapframes_size +#undef print_error_message_file +#undef print_error_message +#undef callout_enumerate_function +#undef callout_enumerate_function_void +#undef callout_enumerate_function_fail +#undef show_pattern_info +#undef serial_error +#undef process_command +#undef process_pattern +#undef have_active_pattern +#undef free_active_pattern +#undef check_match_limit +#undef substitute_callout_function +#undef substitute_case_callout_function +#undef callout_function +#undef copy_and_get +#undef copy_substitute_string +#undef process_data +#undef init_globals +#undef free_globals +#undef unittest + + + +/* End of pcre2test_inc.h */ diff --git a/libpcre/vms/configure.com b/libpcre/vms/configure.com index 831f38ff7..235647867 100644 --- a/libpcre/vms/configure.com +++ b/libpcre/vms/configure.com @@ -463,11 +463,7 @@ Boolean macros such as HAVE_STDLIB_H and SUPPORT_PCRE2_8 should either be defined (conventionally to 1) for TRUE, and not defined at all for FALSE. All such macros are listed as a commented #undef in config.h.generic. Macros such as MATCH_LIMIT, whose actual value is relevant, have defaults defined, but are -surrounded by #ifndef/#endif lines so that the value can be overridden by -D. - -PCRE2 uses memmove() if HAVE_MEMMOVE is defined; otherwise it uses bcopy() if -HAVE_BCOPY is defined. If your system has neither bcopy() nor memmove(), make -sure both macros are undefined; an emulation function will then be used. */ +surrounded by #ifndef/#endif lines so that the value can be overridden by -D. */ /* By default, the \R escape sequence matches any Unicode line ending character or sequence of characters. If BSR_ANYCRLF is defined (to any @@ -499,9 +495,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the header file. */ #define HAVE_ASSERT_H 1 -/* Define to 1 if you have the 'bcopy' function. */ -#define HAVE_BCOPY 1 - /* Define this if your compiler provides __builtin_mul_overflow() */ #undef HAVE_BUILTIN_MUL_OVERFLOW @@ -529,9 +522,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the 'memfd_create' function. */ #undef HAVE_MEMFD_CREATE -/* Define to 1 if you have the 'memmove' function. */ -#define HAVE_MEMMOVE 1 - /* Define to 1 if you have the header file. */ #undef HAVE_MINIX_CONFIG_H @@ -568,9 +558,6 @@ sure both macros are undefined; an emulation function will then be used. */ /* Define to 1 if you have the header file. */ #define HAVE_STDLIB_H 1 -/* Define to 1 if you have the 'strerror' function. */ -#define HAVE_STRERROR 1 - /* Define to 1 if you have the header file. */ #define HAVE_STRINGS_H 1 @@ -905,7 +892,7 @@ sure both macros are undefined; an emulation function will then be used. */ #define PCRE2_EXPORT #define LINK_SIZE 2 #define MAX_NAME_COUNT 10000 -#define MAX_NAME_SIZE 32 +#define MAX_NAME_SIZE 128 #define MATCH_LIMIT 10000000 #define HEAP_LIMIT 20000000 #define NEWLINE_DEFAULT 2 @@ -1037,6 +1024,9 @@ PCRE2_CHKDINT.OBJ : PCRE2_CHKDINT.C PCRE2_COMPILE.OBJ : PCRE2_COMPILE.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) +PCRE2_COMPILE.OBJ : PCRE2_COMPILE_CGROUP.C + $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) + PCRE2_COMPILE.OBJ : PCRE2_COMPILE_CLASS.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) @@ -1070,12 +1060,6 @@ PCRE2_FUZZSUPPORT.OBJ : PCRE2_FUZZSUPPORT.C PCRE2_JIT_COMPILE.OBJ : PCRE2_JIT_COMPILE.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) -PCRE2_JIT_MATCH.OBJ : PCRE2_JIT_MATCH.C - $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) - -PCRE2_JIT_MISC.OBJ : PCRE2_JIT_MISC.C - $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) - PCRE2_JIT_TEST.OBJ : PCRE2_JIT_TEST.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) @@ -1088,6 +1072,9 @@ PCRE2_MATCH.OBJ : PCRE2_MATCH.C PCRE2_MATCH_DATA.OBJ : PCRE2_MATCH_DATA.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) +PCRE2_MATCH_NEXT.OBJ : PCRE2_MATCH_NEXT.C + $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) + PCRE2_NEWLINE.OBJ : PCRE2_NEWLINE.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) @@ -1097,9 +1084,6 @@ PCRE2_ORD2UTF.OBJ : PCRE2_ORD2UTF.C PCRE2_PATTERN_INFO.OBJ : PCRE2_PATTERN_INFO.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) -PCRE2_PRINTINT.OBJ : PCRE2_PRINTINT.C - $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) - PCRE2_SCRIPT_RUN.OBJ : PCRE2_SCRIPT_RUN.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) @@ -1124,9 +1108,6 @@ PCRE2_TABLES.OBJ : PCRE2_TABLES.C PCRE2_UCD.OBJ : PCRE2_UCD.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) -PCRE2_UCPTABLES.OBJ : PCRE2_UCPTABLES.C - $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET) - PCRE2_VALID_UTF.OBJ : PCRE2_VALID_UTF.C $(CC) $(CFLAGS) $(MMS$SOURCE) /OBJ=$(MMS$TARGET)