From: Matthew Vernon Date: Tue, 21 Oct 2025 10:08:32 +0000 (+0100) Subject: New upstream version 10.47 X-Git-Tag: archive/raspbian/10.48-2+rpi1^2~17^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=4b3dd64c080fe260d0564e1c2493c68333a98d19;p=pcre2.git New upstream version 10.47 --- diff --git a/AUTHORS.md b/AUTHORS.md index 708fc23..ced81e6 100644 --- a/AUTHORS.md +++ b/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/BUILD.bazel b/BUILD.bazel index c975ead..ec1b0b9 100644 --- a/BUILD.bazel +++ b/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", + hdrs = [":pcre2_h_generic"], + implementation_deps = [":pcre2_internal_headers"], + defines = [ + "PCRE2_STATIC", ], - 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"], ) +# See below for explanation of why we need this. +# +# https://github.com/bazelbuild/bazel/issues/680 cc_library( - name = "pcre2-posix", - srcs = [ - "src/pcre2posix.c", - ":config_h_generic", - ], + name = "pcre2posix_dotc_headers", hdrs = [ - "src/pcre2posix.h", + "src/pcre2_tables.c", + ], + strip_include_prefix = "src", + visibility = ["//visibility:private"], +) + +cc_library( + name = "pcre2-posix", + srcs = ["src/pcre2posix.c"], + hdrs = ["src/pcre2posix.h"], + implementation_deps = [ + ":pcre2_internal_headers", + ":pcre2posix_dotc_headers", ], - 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/CMakeLists.txt b/CMakeLists.txt index 9e91617..c970996 100644 --- a/CMakeLists.txt +++ b/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) -# 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) +# 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() -# 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) @@ -150,7 +159,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) @@ -159,11 +173,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( [=[ @@ -174,26 +202,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) @@ -210,11 +267,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 @@ -265,6 +320,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" @@ -319,6 +383,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.") @@ -373,55 +438,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() @@ -450,6 +497,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( @@ -483,19 +578,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) @@ -517,6 +600,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 @@ -524,24 +610,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 "") @@ -572,18 +661,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 @@ -609,10 +733,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() @@ -642,7 +765,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 @@ -652,31 +776,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 @@ -689,6 +829,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 @@ -704,7 +845,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) @@ -716,7 +857,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) @@ -727,37 +868,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) @@ -772,15 +896,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 @@ -791,11 +915,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 @@ -807,8 +934,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) @@ -823,8 +953,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 @@ -838,12 +971,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 @@ -854,12 +994,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) @@ -884,12 +1027,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}" @@ -900,7 +1045,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) @@ -913,12 +1058,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}" @@ -929,9 +1076,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) @@ -954,12 +1105,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}" @@ -970,7 +1123,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) @@ -983,12 +1136,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}" @@ -999,9 +1154,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) @@ -1027,31 +1186,54 @@ 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) - configure_file(libpcre2-posix.pc.in libpcre2-posix.pc @ONLY) - list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-posix.pc") - configure_file(libpcre2-8.pc.in libpcre2-8.pc @ONLY) - list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-8.pc") + configure_file(libpcre2-posix.pc.in libpcre2-posix.pc.generator @ONLY) + file(GENERATE OUTPUT libpcre2-posix.pc INPUT "${PROJECT_BINARY_DIR}/libpcre2-posix.pc.generator") + list(APPEND pkg_config_files "${PROJECT_BINARY_DIR}/libpcre2-posix.pc") + configure_file(libpcre2-8.pc.in libpcre2-8.pc.generator @ONLY) + file(GENERATE OUTPUT libpcre2-8.pc INPUT "${PROJECT_BINARY_DIR}/libpcre2-8.pc.generator") + list(APPEND pkg_config_files "${PROJECT_BINARY_DIR}/libpcre2-8.pc") set(enable_pcre2_8 "yes") else() set(enable_pcre2_8 "no") endif() if(PCRE2_BUILD_PCRE2_16) - configure_file(libpcre2-16.pc.in libpcre2-16.pc @ONLY) - list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-16.pc") + configure_file(libpcre2-16.pc.in libpcre2-16.pc.generator @ONLY) + file(GENERATE OUTPUT libpcre2-16.pc INPUT "${PROJECT_BINARY_DIR}/libpcre2-16.pc.generator") + list(APPEND pkg_config_files "${PROJECT_BINARY_DIR}/libpcre2-16.pc") set(enable_pcre2_16 "yes") else() set(enable_pcre2_16 "no") endif() if(PCRE2_BUILD_PCRE2_32) - configure_file(libpcre2-32.pc.in libpcre2-32.pc @ONLY) - list(APPEND pkg_config_files "${CMAKE_CURRENT_BINARY_DIR}/libpcre2-32.pc") + configure_file(libpcre2-32.pc.in libpcre2-32.pc.generator @ONLY) + file(GENERATE OUTPUT libpcre2-32.pc INPUT "${PROJECT_BINARY_DIR}/libpcre2-32.pc.generator") + list(APPEND pkg_config_files "${PROJECT_BINARY_DIR}/libpcre2-32.pc") set(enable_pcre2_32 "yes") else() set(enable_pcre2_32 "no") @@ -1064,7 +1246,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() @@ -1075,6 +1257,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 @@ -1083,7 +1266,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() @@ -1165,6 +1348,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() @@ -1216,7 +1407,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) @@ -1243,28 +1439,33 @@ 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( @@ -1287,8 +1488,8 @@ 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 @@ -1310,6 +1511,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() @@ -1323,7 +1525,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 "") @@ -1332,9 +1539,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}") @@ -1342,23 +1549,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) @@ -1381,7 +1604,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/ChangeLog b/ChangeLog index 766313d..95cfa9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,85 @@ there is also the log of commit messages. Internal changes which are not visible to clients of the library are mostly not listed here. +Version 10.47 21-October-2025 +----------------------------- + +1. (#660, #655, #663) Expanded platforms tested by CI: FreeBSD, OpenBSD, +Solaris, MSYS (Cygwin), S390x, PPC64le, ARMv7, AARCH64, RiscV. + +2. (#655) Made build clean of `/W3` warnings on MSVC. Further suppression of +minor build warnings on other platforms (various commits). + +3. (#651) Added `--enable-Werror` flag to `./configure` to treat warnings as +errors (or `--enable-errwarn` for Solaris cc). Previously, you had to hackily +override the CPPFLAGS when calling make since you can't pass `-Werror` as a +CFLAG into `./configure` (it breaks compiler feature detection). + +4. (#682) Added AM_MAINTAINER_MODE for Git tag releases. Users building with +the `./configure` script can check out the release tag using Git, which assigns +the current time as the modification time to each checked-out file. This caused +Autoconf to attempt to regenerate the configure script. + +5. (#692) Add LICENSE file for sljit to the tarball release, to clarify that the +sljit code is governed separately by the 2-clause BSD license. + +6. (#656, #695) Add full support for z/OS and native EBCDIC support. The z/OS +support is tested nightly using the XLC and IBM-Clang compilers, with Autoconf +and CMake. In addition, for test purposes, the EBCDIC support can now be enabled +on any platform using the new Autoconf `--enable-ebcdic-ignoring-compiler` and +CMake `-DPCRE2_EBCDIC_IGNORING_COMPILER` options. + +7. (#700) Faster lookup of named capture groups during pattern compilation using +a hash table. + +8. (#697, #756, #778) Improvements to pcre2test to increase code coverage: +-malloc argument; more detailed test assertions. + +9. (#705, #710, #737, #738) Powerful new feature: pattern recursion of +the form "(?1(GROUP_NAME_OR_NUM,...))" acts as a subroutine call which +additionally returns the listed capturing groups to the calling context. + +10. (#721) Add linker scripts to enable symbol versioning for the PCRE2 dynamic +libraries. Downstream Linux distributions may make use of this, or disable it +with the new Autoconf `--disable-symvers` and CMake `-DPCRE2_SYMVERS` options. +Currently, Linux, Solaris, and FreeBSD (GNU ld, LLVM lld, and Solaris ld) are +tested and supported. + +11. (#733) New API function: pcre2_next_match(). This function makes it both +simpler and safer for clients to iterate over all matches in a subject. The +documentation in `pcre2api` also provides improved guidance in the section +"Iterating over all matches". + +12. (#739, #744, #753) Modernize the CMake build files, to use standard +commands to export the PCRE2 targets. This makes use of the +"$" and "$" expressions alongside +the built-in "install(EXPORT...)" command. This brings the CMake files in line +with the patches used by vcpkg to distribute PCRE2. The minimum CMake version +remains 3.15. + +13. (#756) Improved error offsets and diagnostics for syntax errors during +pattern compilation. + +14. (#708, #729, #724, #731, #777) Various updates to Bazel and Zig +build support. + +15. (#775) Added PCRE2_CONFIG_EFFECTIVE_LINKSIZE option to pcre2_config(), to +report the actual number of code units used in compiled patterns for recording +string lengths and offsets. + +16. (#801) Significant bugfix: Fix a crash in pcre2_callout_enumerate() which is +easily reachable on any pattern that contains a Unicode character class. If your +application uses this function, please read the details for this change and +evaluate its severity for your application. + +17. (#806, #807) Improved input validation for pcre2_substitute() used with +PCRE2_SUBSTITUTE_MATCHED. + +18. (#817) Add support for $+ replacement to pcre2_substitute(). + +19. (#818) New SIMD code generation in the JIT for AArch64. + + Version 10.46 27-August-2025 ---------------------------- diff --git a/HACKING b/HACKING index 65de9e3..ace2c4c 100644 --- a/HACKING +++ b/HACKING @@ -251,7 +251,7 @@ The following are followed by a length element, then a number of character code values (which should match with the length): META_MARK (*MARK:xxxx) -META_COMMIT_ARG )*COMMIT:xxxx) +META_COMMIT_ARG (*COMMIT:xxxx) META_PRUNE_ARG (*PRUNE:xxx) META_SKIP_ARG (*SKIP:xxxx) META_THEN_ARG (*THEN:xxxx) diff --git a/LICENCE.md b/LICENCE.md index f58ceb7..f6fba35 100644 --- a/LICENCE.md +++ b/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/MODULE.bazel b/MODULE.bazel index 042676b..abed25a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,9 +1,9 @@ module( name = "pcre2", - version = "10.46", + 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/Makefile.am b/Makefile.am index 8aaa0cc..da5e3d9 100644 --- a/Makefile.am +++ b/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 = \ @@ -67,6 +73,7 @@ dist_html_DATA = \ doc/html/pcre2_match_data_create.html \ doc/html/pcre2_match_data_create_from_pattern.html \ doc/html/pcre2_match_data_free.html \ + doc/html/pcre2_next_match.html \ doc/html/pcre2_pattern_convert.html \ doc/html/pcre2_pattern_info.html \ doc/html/pcre2_serialize_decode.html \ @@ -168,6 +175,7 @@ dist_man_MANS = \ doc/pcre2_match_data_create.3 \ doc/pcre2_match_data_create_from_pattern.3 \ doc/pcre2_match_data_free.3 \ + doc/pcre2_next_match.3 \ doc/pcre2_pattern_convert.3 \ doc/pcre2_pattern_info.3 \ doc/pcre2_serialize_decode.3 \ @@ -235,6 +243,7 @@ lib_LTLIBRARIES = # TESTS is for binary unit tests, check_SCRIPTS for script-based tests TESTS = +XFAIL_TESTS = check_SCRIPTS = dist_noinst_SCRIPTS = @@ -269,7 +278,10 @@ 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 files contain maintenance information @@ -282,7 +294,6 @@ EXTRA_DIST += \ EXTRA_DIST += \ BUILD.bazel \ MODULE.bazel \ - WORKSPACE.bazel \ build.zig # These are support files for building under VMS @@ -316,8 +327,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 @@ -327,13 +339,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 @@ -362,9 +374,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 @@ -378,6 +402,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 \ @@ -390,14 +415,17 @@ COMMON_SOURCES = \ src/pcre2_intmodedep.h \ src/pcre2_jit_char_inc.h \ src/pcre2_jit_compile.c \ - src/pcre2_jit_neon_inc.h \ + src/pcre2_jit_match_inc.h \ + src/pcre2_jit_misc_inc.h \ src/pcre2_jit_simd_inc.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_printint_inc.h \ src/pcre2_script_run.c \ src/pcre2_serialize.c \ src/pcre2_string_utils.c \ @@ -407,14 +435,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 = \ @@ -460,13 +485,18 @@ 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 # The JIT compiler lives in a separate directory, but its files are #included # when pcre2_jit_compile.c is processed, so they must be distributed. EXTRA_DIST += \ + deps/sljit/LICENSE \ + deps/sljit/README.md \ deps/sljit/sljit_src/sljitConfig.h \ deps/sljit/sljit_src/sljitConfigCPU.h \ deps/sljit/sljit_src/sljitConfigInternal.h \ @@ -501,12 +531,6 @@ EXTRA_DIST += \ deps/sljit/sljit_src/allocator_src/sljitWXExecAllocatorPosix.c \ deps/sljit/sljit_src/allocator_src/sljitWXExecAllocatorWindows.c -# Some of the JIT sources are also in separate files that are #included. - -EXTRA_DIST += \ - src/pcre2_jit_match.c \ - src/pcre2_jit_misc.c - if WITH_PCRE2_8 libpcre2_8_la_LDFLAGS = $(EXTRA_LIBPCRE2_8_LDFLAGS) endif # WITH_PCRE2_8 @@ -662,13 +686,10 @@ pcre2_jit_test_LDADD += $(GCOV_LIBS) endif # WITH_GCOV endif # WITH_JIT -# Build the general pcre2test program. The file src/pcre2_printint.c is -# #included by pcre2test as many times as needed, at different code unit -# widths. +# Build the general pcre2test program. bin_PROGRAMS += pcre2test -EXTRA_DIST += src/pcre2_printint.c -pcre2test_SOURCES = src/pcre2test.c +pcre2test_SOURCES = src/pcre2test.c src/pcre2test_inc.h pcre2test_CFLAGS = $(AM_CFLAGS) pcre2test_LDADD = $(LIBREADLINE) @@ -707,6 +728,9 @@ if WITH_PCRE2_8 TESTS += RunGrepTest EXTRA_DIST += RunGrepTest.bat dist_noinst_SCRIPTS += RunGrepTest +if WITH_EBCDIC +XFAIL_TESTS += RunGrepTest +endif # WITH_EBCDIC endif # WITH_PCRE2_8 ## Distribute all the test data files @@ -766,7 +790,8 @@ EXTRA_DIST += \ testdata/testinput25 \ testdata/testinput26 \ testdata/testinput27 \ - testdata/testinputEBC \ + testdata/testinput28 \ + testdata/testinput29 \ testdata/testinputheap \ testdata/testoutput1 \ testdata/testoutput2 \ @@ -778,10 +803,7 @@ EXTRA_DIST += \ testdata/testoutput6 \ testdata/testoutput7 \ testdata/testoutput8-16-2 \ - testdata/testoutput8-16-3 \ testdata/testoutput8-16-4 \ - testdata/testoutput8-32-2 \ - testdata/testoutput8-32-3 \ testdata/testoutput8-32-4 \ testdata/testoutput8-8-2 \ testdata/testoutput8-8-3 \ @@ -811,7 +833,8 @@ EXTRA_DIST += \ testdata/testoutput25 \ testdata/testoutput26 \ testdata/testoutput27 \ - testdata/testoutputEBC \ + testdata/testoutput28 \ + testdata/testoutput29 \ testdata/testoutputheap-16 \ testdata/testoutputheap-32 \ testdata/testoutputheap-8 \ @@ -824,19 +847,28 @@ EXTRA_DIST += \ # they don't, add their working files to CLEANFILES. CLEANFILES += \ - testSinput \ - test3input \ - test3output \ - test3outputA \ - test3outputB \ - testtry \ - teststdout \ - teststderr \ - teststderrgrep \ - testtemp1grep \ - testtemp2grep \ - testtrygrep \ - testNinputgrep + 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 ------------- @@ -865,6 +897,13 @@ pkgconfig_DATA += libpcre2-32.pc endif +# 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 # # Coverage reporting targets: @@ -944,24 +983,27 @@ 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 @@ -970,9 +1012,21 @@ 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/Makefile.in b/Makefile.in index 5deb080..35f2abe 100644 --- a/Makefile.in +++ b/Makefile.in @@ -142,18 +142,27 @@ noinst_PROGRAMS = $(am__EXEEXT_2) $(am__EXEEXT_3) $(am__EXEEXT_4) \ @WITH_PCRE2_8_TRUE@am__append_43 = RunGrepTest @WITH_PCRE2_8_TRUE@am__append_44 = RunGrepTest.bat @WITH_PCRE2_8_TRUE@am__append_45 = RunGrepTest -@WITH_PCRE2_8_TRUE@am__append_46 = libpcre2-8.pc libpcre2-posix.pc -@WITH_PCRE2_16_TRUE@am__append_47 = libpcre2-16.pc -@WITH_PCRE2_32_TRUE@am__append_48 = libpcre2-32.pc -@WITH_GCOV_FALSE@am__append_49 = src/*.gcda src/*.gcno +@WITH_EBCDIC_TRUE@@WITH_PCRE2_8_TRUE@am__append_46 = RunGrepTest +@WITH_PCRE2_8_TRUE@am__append_47 = libpcre2-8.pc libpcre2-posix.pc +@WITH_PCRE2_16_TRUE@am__append_48 = libpcre2-16.pc +@WITH_PCRE2_32_TRUE@am__append_49 = libpcre2-32.pc +@WITH_GCOV_TRUE@am__append_50 = coverage-clean +@WITH_GCOV_TRUE@am__append_51 = coverage-distclean +@WITH_GCOV_TRUE@am__append_52 = 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_53 = src/*.gcda src/*.gcno +@WITH_GCOV_FALSE@am__append_54 = coverage-distclean +@WITH_GCOV_FALSE@am__append_55 = 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 \ @@ -239,22 +248,27 @@ _libs_libpcre2_fuzzsupport_a_OBJECTS = \ 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_jit_neon_inc.h src/pcre2_jit_simd_inc.h \ + 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_jit_char_inc.h \ + src/pcre2_jit_compile.c src/pcre2_jit_match_inc.h \ + src/pcre2_jit_misc_inc.h src/pcre2_jit_simd_inc.h \ src/pcre2_maketables.c src/pcre2_match.c \ - src/pcre2_match_data.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_match_data.c src/pcre2_match_next.c \ + src/pcre2_newline.c src/pcre2_ord2utf.c \ + src/pcre2_pattern_info.c src/pcre2_printint_inc.h \ + 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_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 \ @@ -267,6 +281,7 @@ am__objects_1 = src/libpcre2_16_la-pcre2_auto_possess.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 \ @@ -297,22 +312,27 @@ 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_jit_neon_inc.h src/pcre2_jit_simd_inc.h \ + 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_jit_char_inc.h \ + src/pcre2_jit_compile.c src/pcre2_jit_match_inc.h \ + src/pcre2_jit_misc_inc.h src/pcre2_jit_simd_inc.h \ src/pcre2_maketables.c src/pcre2_match.c \ - src/pcre2_match_data.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_match_data.c src/pcre2_match_next.c \ + src/pcre2_newline.c src/pcre2_ord2utf.c \ + src/pcre2_pattern_info.c src/pcre2_printint_inc.h \ + 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 \ @@ -325,6 +345,7 @@ am__objects_3 = src/libpcre2_32_la-pcre2_auto_possess.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 \ @@ -351,22 +372,27 @@ 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_jit_neon_inc.h src/pcre2_jit_simd_inc.h \ + 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_jit_char_inc.h \ + src/pcre2_jit_compile.c src/pcre2_jit_match_inc.h \ + src/pcre2_jit_misc_inc.h src/pcre2_jit_simd_inc.h \ src/pcre2_maketables.c src/pcre2_match.c \ - src/pcre2_match_data.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_match_data.c src/pcre2_match_next.c \ + src/pcre2_newline.c src/pcre2_ord2utf.c \ + src/pcre2_pattern_info.c src/pcre2_printint_inc.h \ + 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 \ @@ -379,6 +405,7 @@ am__objects_5 = src/libpcre2_8_la-pcre2_auto_possess.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 \ @@ -516,6 +543,7 @@ am__depfiles_remade = src/$(DEPDIR)/_libs_libpcre2_fuzzsupport_16_a-pcre2_fuzzsu 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 \ @@ -528,6 +556,7 @@ am__depfiles_remade = src/$(DEPDIR)/_libs_libpcre2_fuzzsupport_16_a-pcre2_fuzzsu 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 \ @@ -545,6 +574,7 @@ am__depfiles_remade = src/$(DEPDIR)/_libs_libpcre2_fuzzsupport_16_a-pcre2_fuzzsu 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 \ @@ -557,6 +587,7 @@ am__depfiles_remade = src/$(DEPDIR)/_libs_libpcre2_fuzzsupport_16_a-pcre2_fuzzsu 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 \ @@ -574,6 +605,7 @@ am__depfiles_remade = src/$(DEPDIR)/_libs_libpcre2_fuzzsupport_16_a-pcre2_fuzzsu 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 \ @@ -586,6 +618,7 @@ am__depfiles_remade = src/$(DEPDIR)/_libs_libpcre2_fuzzsupport_16_a-pcre2_fuzzsu 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 \ @@ -897,6 +930,7 @@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CET_CFLAGS = @CET_CFLAGS@ CFLAGS = @CFLAGS@ +CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ @@ -973,6 +1007,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@ @@ -984,6 +1019,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@ @@ -1044,6 +1080,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_50) +DISTCLEAN_LOCAL_TARGETS = $(am__append_51) $(am__append_54) +PHONY_TARGETS = testoutput-clean $(am__append_52) $(am__append_55) dist_doc_DATA = \ AUTHORS.md \ COPYING \ @@ -1102,6 +1141,7 @@ dist_html_DATA = \ doc/html/pcre2_match_data_create.html \ doc/html/pcre2_match_data_create_from_pattern.html \ doc/html/pcre2_match_data_free.html \ + doc/html/pcre2_next_match.html \ doc/html/pcre2_pattern_convert.html \ doc/html/pcre2_pattern_info.html \ doc/html/pcre2_serialize_decode.html \ @@ -1203,6 +1243,7 @@ dist_man_MANS = \ doc/pcre2_match_data_create.3 \ doc/pcre2_match_data_create_from_pattern.3 \ doc/pcre2_match_data_free.3 \ + doc/pcre2_next_match.3 \ doc/pcre2_pattern_convert.3 \ doc/pcre2_pattern_info.3 \ doc/pcre2_serialize_decode.3 \ @@ -1266,6 +1307,7 @@ dist_man_MANS = \ # The Libtool libraries to install. We'll add to this later. lib_LTLIBRARIES = $(am__append_2) $(am__append_3) $(am__append_4) \ $(am__append_11) +XFAIL_TESTS = $(am__append_46) check_SCRIPTS = dist_noinst_SCRIPTS = RunTest $(am__append_45) @@ -1279,11 +1321,11 @@ dist_noinst_SCRIPTS = RunTest $(am__append_45) # they don't, add their working files to CLEANFILES. CLEANFILES = pcre2_dftables pcre2_jit_test pcre2fuzzcheck-8 \ pcre2fuzzcheck-16 pcre2fuzzcheck-32 pcre2demo \ - src/pcre2_chartables.c testSinput test3input test3output \ - test3outputA test3outputB testtry teststdout teststderr \ - teststderrgrep testtemp1grep testtemp2grep testtrygrep \ - testNinputgrep -DISTCLEANFILES = src/config.h.in~ $(am__append_49) + 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_53) MAINTAINERCLEANFILES = src/pcre2.h.generic src/config.h.generic # Additional files to bundle with the distribution, over and above what @@ -1301,24 +1343,25 @@ 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. # The JIT compiler lives in a separate directory, but its files are #included # when pcre2_jit_compile.c is processed, so they must be distributed. -# Some of the JIT sources are also in separate files that are #included. - # PCRE2 demonstration program. Not built automatically. The point is that the # users should build it themselves. So just distribute the source. -EXTRA_DIST = m4/ax_pthread.m4 m4/pcre2_visibility.m4 \ - NON-AUTOTOOLS-BUILD HACKING 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 NON-AUTOTOOLS-BUILD \ + HACKING 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 deps/sljit/sljit_src/sljitConfig.h \ + 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 deps/sljit/LICENSE \ + deps/sljit/README.md deps/sljit/sljit_src/sljitConfig.h \ deps/sljit/sljit_src/sljitConfigCPU.h \ deps/sljit/sljit_src/sljitConfigInternal.h \ deps/sljit/sljit_src/sljitLir.c \ @@ -1351,10 +1394,9 @@ EXTRA_DIST = m4/ax_pthread.m4 m4/pcre2_visibility.m4 \ deps/sljit/sljit_src/allocator_src/sljitProtExecAllocatorPosix.c \ deps/sljit/sljit_src/allocator_src/sljitWXExecAllocatorPosix.c \ deps/sljit/sljit_src/allocator_src/sljitWXExecAllocatorWindows.c \ - src/pcre2_jit_match.c src/pcre2_jit_misc.c \ - src/pcre2_printint.c RunTest.bat $(am__append_44) \ - testdata/grepbinary testdata/grepfilelist testdata/grepinput \ - testdata/grepinput3 testdata/grepinput8 testdata/grepinputBad8 \ + RunTest.bat $(am__append_44) testdata/grepbinary \ + testdata/grepfilelist testdata/grepinput testdata/grepinput3 \ + testdata/grepinput8 testdata/grepinputBad8 \ testdata/grepinputBad8_Trail testdata/grepinputC.bz2 \ testdata/grepinputC.gz testdata/grepinputM \ testdata/grepinputUN testdata/grepinputv testdata/grepinputx \ @@ -1373,35 +1415,39 @@ EXTRA_DIST = m4/ax_pthread.m4 m4/pcre2_visibility.m4 \ testdata/testinput19 testdata/testinput20 testdata/testinput21 \ testdata/testinput22 testdata/testinput23 testdata/testinput24 \ testdata/testinput25 testdata/testinput26 testdata/testinput27 \ - testdata/testinputEBC testdata/testinputheap \ - testdata/testoutput1 testdata/testoutput2 testdata/testoutput3 \ + testdata/testinput28 testdata/testinput29 \ + testdata/testinputheap testdata/testoutput1 \ + testdata/testoutput2 testdata/testoutput3 \ testdata/testoutput3A testdata/testoutput3B \ testdata/testoutput4 testdata/testoutput5 testdata/testoutput6 \ testdata/testoutput7 testdata/testoutput8-16-2 \ - testdata/testoutput8-16-3 testdata/testoutput8-16-4 \ - testdata/testoutput8-32-2 testdata/testoutput8-32-3 \ - testdata/testoutput8-32-4 testdata/testoutput8-8-2 \ - testdata/testoutput8-8-3 testdata/testoutput8-8-4 \ - testdata/testoutput9 testdata/testoutput10 \ - testdata/testoutput11-16 testdata/testoutput11-32 \ - testdata/testoutput12-16 testdata/testoutput12-32 \ - testdata/testoutput13 testdata/testoutput14-16 \ - testdata/testoutput14-32 testdata/testoutput14-8 \ - testdata/testoutput15 testdata/testoutput16 \ - testdata/testoutput17 testdata/testoutput18 \ - testdata/testoutput19 testdata/testoutput20 \ - testdata/testoutput21 testdata/testoutput22-16 \ - testdata/testoutput22-32 testdata/testoutput22-8 \ - testdata/testoutput23 testdata/testoutput24 \ - testdata/testoutput25 testdata/testoutput26 \ - testdata/testoutput27 testdata/testoutputEBC \ + testdata/testoutput8-16-4 testdata/testoutput8-32-4 \ + testdata/testoutput8-8-2 testdata/testoutput8-8-3 \ + testdata/testoutput8-8-4 testdata/testoutput9 \ + testdata/testoutput10 testdata/testoutput11-16 \ + testdata/testoutput11-32 testdata/testoutput12-16 \ + testdata/testoutput12-32 testdata/testoutput13 \ + testdata/testoutput14-16 testdata/testoutput14-32 \ + testdata/testoutput14-8 testdata/testoutput15 \ + testdata/testoutput16 testdata/testoutput17 \ + testdata/testoutput18 testdata/testoutput19 \ + testdata/testoutput20 testdata/testoutput21 \ + testdata/testoutput22-16 testdata/testoutput22-32 \ + testdata/testoutput22-8 testdata/testoutput23 \ + testdata/testoutput24 testdata/testoutput25 \ + testdata/testoutput26 testdata/testoutput27 \ + testdata/testoutput28 testdata/testoutput29 \ testdata/testoutputheap-16 testdata/testoutputheap-32 \ testdata/testoutputheap-8 testdata/valgrind-jit.supp \ testdata/wintestinput3 testdata/wintestoutput3 perltest.sh \ - src/pcre2demo.c 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/pcre2demo.c src/libpcre2-8.sym src/libpcre2-16.sym \ + src/libpcre2-32.sym src/libpcre2-posix.sym \ + cmake/COPYING-CMAKE-SCRIPTS cmake/FindEditline.cmake \ + cmake/FindReadline.cmake 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. @@ -1418,6 +1464,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 \ @@ -1430,14 +1477,17 @@ COMMON_SOURCES = \ src/pcre2_intmodedep.h \ src/pcre2_jit_char_inc.h \ src/pcre2_jit_compile.c \ - src/pcre2_jit_neon_inc.h \ + src/pcre2_jit_match_inc.h \ + src/pcre2_jit_misc_inc.h \ src/pcre2_jit_simd_inc.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_printint_inc.h \ src/pcre2_script_run.c \ src/pcre2_serialize.c \ src/pcre2_string_utils.c \ @@ -1447,6 +1497,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 @@ -1545,14 +1596,14 @@ COMMON_SOURCES = \ @WITH_JIT_TRUE@pcre2_jit_test_LDADD = $(am__append_32) \ @WITH_JIT_TRUE@ $(am__append_33) $(am__append_34) \ @WITH_JIT_TRUE@ $(am__append_36) -pcre2test_SOURCES = src/pcre2test.c +pcre2test_SOURCES = src/pcre2test.c src/pcre2test_inc.h pcre2test_CFLAGS = $(AM_CFLAGS) $(am__append_40) $(am__append_41) pcre2test_LDADD = $(LIBREADLINE) $(am__append_37) $(am__append_38) \ $(am__append_39) $(am__append_42) # We have .pc files for pkg-config users. pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = $(am__append_46) $(am__append_47) $(am__append_48) +pkgconfig_DATA = $(am__append_47) $(am__append_48) $(am__append_49) # gcov/lcov code coverage reporting # @@ -1774,6 +1825,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) \ @@ -1798,6 +1851,8 @@ 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) \ @@ -1835,6 +1890,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) \ @@ -1859,6 +1916,8 @@ 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) \ @@ -1896,6 +1955,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) \ @@ -1920,6 +1981,8 @@ 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) \ @@ -2055,6 +2118,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 @@ -2067,6 +2131,7 @@ distclean-compile: @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 @@ -2084,6 +2149,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 @@ -2096,6 +2162,7 @@ distclean-compile: @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 @@ -2113,6 +2180,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 @@ -2125,6 +2193,7 @@ distclean-compile: @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 @@ -2241,6 +2310,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 @@ -2325,6 +2401,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 @@ -2444,6 +2527,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 @@ -2528,6 +2618,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 @@ -2647,6 +2744,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 @@ -2731,6 +2835,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 @@ -3602,7 +3713,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 \ @@ -3618,6 +3728,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 @@ -3630,6 +3741,7 @@ distclean: distclean-am -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 @@ -3647,6 +3759,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 @@ -3659,6 +3772,7 @@ distclean: distclean-am -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 @@ -3676,6 +3790,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 @@ -3688,6 +3803,7 @@ distclean: distclean-am -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 @@ -3767,6 +3883,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 @@ -3779,6 +3896,7 @@ maintainer-clean: maintainer-clean-am -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 @@ -3796,6 +3914,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 @@ -3808,6 +3927,7 @@ maintainer-clean: maintainer-clean-am -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 @@ -3825,6 +3945,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 @@ -3837,6 +3958,7 @@ maintainer-clean: maintainer-clean-am -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 @@ -3932,8 +4054,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 @@ -3943,20 +4066,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 @@ -4010,20 +4144,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/NEWS b/NEWS index ea7af0c..cbe60b6 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,46 @@ News about PCRE2 releases ------------------------- +Version 10.47 21-October-2025 +----------------------------- + +This is a regular semi-annual release, incorporating a few new features and +several maintenance and build improvements. + +Only changes to behaviour, changes to the API, and other significant changes +are described here. Please see the ChangeLog and Git log for further details. + +* (Powerful new feature) Pattern recursion of the form +"(?1(GROUP_NAME_OR_NUM,...))" acts as a subroutine call which additionally +returns the listed capturing groups to the calling context. + +* (Significant bugfix) Fixed a crash in pcre2_callout_enumerate() which is +easily reachable on any pattern that contains a Unicode character class. If your +application uses this function, please read the details for this change and +evaluate its severity for your application. + +* (Build change) There are now linker scripts to enable symbol versioning for +the PCRE2 dynamic libraries. Downstream Linux distributions may make use of +this, or disable it with the new Autoconf `--disable-symvers` and CMake +`-DPCRE2_SYMVERS` options. Linux, Solaris, and FreeBSD (GNU ld, LLVM lld, and +Solaris ld) are tested and supported. + +* (New API function) Added pcre2_next_match(). This function makes it both +simpler and safer for clients to iterate over all matches in a subject. The +documentation in `pcre2api` also provides improved guidance in the section +"Iterating over all matches". + +* (Minor API addition) Added the PCRE2_CONFIG_EFFECTIVE_LINKSIZE option to +pcre2_config(). + +* (Minor replacement syntax extension) Added support for $+ replacement to +pcre2_substitute(). + +* (Build change) Modernize the CMake build files, to use the +"$", "$" and "install(EXPORT...)" +expressions to export the PCRE2 targets. + + Version 10.46 27-August-2025 ---------------------------- diff --git a/NON-AUTOTOOLS-BUILD b/NON-AUTOTOOLS-BUILD index bb687f7..45c8bad 100644 --- a/NON-AUTOTOOLS-BUILD +++ b/NON-AUTOTOOLS-BUILD @@ -1,5 +1,5 @@ Building PCRE2 without using autotools --------------------------------------- +====================================== This document contains the following sections: @@ -12,11 +12,12 @@ This document contains the following sections: Building PCRE2 on Windows with CMake Building PCRE2 on Windows with Visual Studio Testing with RunTest.bat - Building PCRE2 on native z/OS and z/VM + Building PCRE2 on z/OS and z/VM Building PCRE2 under VMS -GENERAL +General +------- The source of the PCRE2 libraries consists entirely of code written in Standard C, and so should compile successfully on any system that has a Standard C @@ -37,7 +38,8 @@ provided for those who build PCRE2 without using "configure" or CMake. If you use "configure" or CMake, the .generic versions are not used. -GENERIC INSTRUCTIONS FOR THE PCRE2 C LIBRARIES +Generic instructions for the PCRE2 C libraries +---------------------------------------------- There are three possible PCRE2 libraries, each handling data with a specific code unit width: 8, 16, or 32 bits. You can build any combination of them. The @@ -105,6 +107,7 @@ example. pcre2_chkdint.c pcre2_chartables.c pcre2_compile.c + pcre2_compile_cgroup.c pcre2_compile_class.c pcre2_config.c pcre2_context.c @@ -117,6 +120,7 @@ example. pcre2_maketables.c pcre2_match.c pcre2_match_data.c + pcre2_match_next.c pcre2_newline.c pcre2_ord2utf.c pcre2_pattern_info.c @@ -140,9 +144,7 @@ example. defined SUPPORT_JIT in src/config.h, because when JIT support is not configured, dummy functions are compiled. When JIT support IS configured, pcre2_jit_compile.c #includes other files from the sljit dependency, - all of whose names begin with "sljit". It also #includes - src/pcre2_jit_match.c and src/pcre2_jit_misc.c, so you should not compile - those yourself. + all of whose names begin with "sljit". Note also that the pcre2_fuzzsupport.c file contains special code that is useful to those who want to run fuzzing tests on the PCRE2 library. Unless @@ -169,7 +171,7 @@ example. src/config.h) . Compile src/pcre2test.c; don't forget -DHAVE_CONFIG_H if necessary, but do NOT define PCRE2_CODE_UNIT_WIDTH. Then link with the appropriate library/ies. If you compiled an 8-bit library, pcre2test also - needs the pcre2posix wrapper library. + needs the pcre2posix wrapper library when linking. (9) Run pcre2test on the testinput files in the testdata directory, and check that the output matches the corresponding testoutput files. There are @@ -207,20 +209,23 @@ example. defining SUPPORT_JIT, pcre2grep does not try to make use of JIT. -STACK SIZE IN WINDOWS ENVIRONMENTS +Stack size in Windows environments +---------------------------------- Prior to release 10.30 the default system stack size of 1MiB in some Windows environments caused issues with some tests. This should no longer be the case for 10.30 and later releases. -LINKING PROGRAMS IN WINDOWS ENVIRONMENTS +Linking programs in Windows environments +---------------------------------------- If you want to statically link a program against a PCRE2 library in the form of a non-dll .a file, you must define PCRE2_STATIC before including src/pcre2.h. -CALLING CONVENTIONS IN WINDOWS ENVIRONMENTS +Calling conventions in Windows environments +------------------------------------------- It is possible to compile programs to use different calling conventions using MSVC. Search the web for "calling conventions" for more information. To make it @@ -231,7 +236,8 @@ not set, it defaults to empty; the default calling convention is then used (which is what is wanted most of the time). -COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE2 ON WINDOWS WITH CMAKE") +Comments about Win32 builds (see also "Building PCRE2 on Windows with CMake") +--------------------------- There are two ways of building PCRE2 using the "configure, make, make install" paradigm on Windows systems: using MinGW or using Cygwin. These are not at all @@ -293,7 +299,8 @@ newline option that includes LF as a valid newline, it may be necessary to change the line terminators in the test files to get some of the tests to work. -BUILDING PCRE2 ON WINDOWS WITH CMAKE +Building PCRE2 on Windows with CMake +------------------------------------ CMake is an alternative configuration facility that can be used instead of "configure". CMake creates project files (make files, solution files, etc.) @@ -364,7 +371,8 @@ be deleted. Regardless of build system used, `ctest` will run the tests. -BUILDING PCRE2 ON WINDOWS WITH VISUAL STUDIO +Building PCRE2 on Windows with Visual Studio +-------------------------------------------- The code currently cannot be compiled without an inttypes.h header, which is available only with Visual Studio 2013 or newer. However, this portable and @@ -376,7 +384,8 @@ alternative: Just rename it and drop it into the top level of the build tree. -TESTING WITH RUNTEST.BAT +Testing with RunTest.bat +------------------------ If configured with CMake, building the test project ("make test" or building ALL_TESTS in Visual Studio) creates (and runs) pcre2_test.bat (and depending @@ -410,33 +419,69 @@ Otherwise: To independently test the just-in-time compiler, run pcre2_jit_test.exe. -BUILDING PCRE2 ON NATIVE Z/OS AND Z/VM +Building PCRE2 on z/OS and z/VM +------------------------------- z/OS and z/VM are operating systems for mainframe computers, produced by IBM. The character code used is EBCDIC, not ASCII or Unicode. In z/OS, UNIX APIs and -applications can be supported through UNIX System Services, and in such an -environment it should be possible to build PCRE2 in the same way as in other -systems, with the EBCDIC related configuration settings, but it is not known if -anybody has tried this. - -In native z/OS (without UNIX System Services) and in z/VM, special ports are -required. For details, please see file 939 on this web site: +applications can be supported through UNIX System Services. + +The PCRE2 codebase compiles and runs with native EBCDIC support on modern z/OS +systems, using the pre-installed tools (/bin/sh, ./configure, and the XLC or +IBM-Clang compilers). PCRE2 supports z/OS using both Autoconf (./configure) and +CMake (which IBM distributes via "zopen install cmake"). + +Note that as of the time of writing, IBM's port of CMake to z/OS has only +partial support for EBCDIC. It is recommended to build PCRE2 using the +./configure script, if you require an EBCDIC build. + +Any EBCDIC codepage should work (PCRE2 does not assume or require IBM-1047), or +PCRE2 can compiled for ASCII/Latin-1/Unicode. + +After unpacking the PCRE2 tarball, you must subsequently tag the files as ASCII +in order for the z/OS shell and compiler to interpret them correctly: + chtag -R -tc ISO8859-1 + +Some unusual features on the IBM platform are: + - The _ALL_SOURCE macro must be provided. Unlike on Linux or macOS, even quite + standard POSIX APIs are not made visible by default. PCRE2's Autoconf and + CMake system both provide this for you. + - The `cc`, `c89`, and even `c99` compilers provided by IBM do not default to + the same argument ordering as other Unix platforms. + - The XLC compiler requires `-qhaltonmsg=CCN3296`, otherwise it will treat any + preprocessor #include errors as a warning rather than an error. Needless to + say this default wrecks Autoconf and CMake's feature-detection tests. + PCRE2's build system is aware of this. + - The test suite (in the testdata/ directory) is entirely in ASCII/UTF-8. + When running the tests, you must ensure that the EBCDIC-native build of + pcre2test receives an EBCDIC version of these files. The easiest way to + achieve this is via filesystem tagging (chtag). Alternatively, you could + manually re-encode the testdata files as EBCDIC, and tag them as EBCDIC. + (Latin-1 and EBCDIC are one-to-one convertible encodings, a simple + byte-by-byte permutation of the 256 values.) + +In native z/OS (without UNIX System Services) and in z/VM, a user has provided a +special port of PCRE2. For details, please see file 939 on this web site: http://www.cbttape.org -Everything in that location, source and executable, is in EBCDIC and native -z/OS file formats. The port provides an API for LE languages such as COBOL and +The user-provided port also provides an API for LE languages such as COBOL and for the z/OS and z/VM versions of the Rexx languages. -BUILDING PCRE2 UNDER VMS +Building PCRE2 under VMS +------------------------ Alexey Chuphin has contributed some auxiliary files for building PCRE2 under OpenVMS. They are in the "vms" directory in the distribution tarball. Please read the file called vms/openvms_readme.txt. The pcre2test and pcre2grep programs contain some VMS-specific code. -============================== -Last updated: 26 December 2024 -============================== +This has not been tested for some time. The PCRE2 maintainers would be grateful +to learn whether it still works (or if anyone still uses it). + + +============================= +Last updated: 17 October 2025 +============================= diff --git a/README b/README index 5a50f7f..593bab2 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ README file for PCRE2 (Perl-compatible regular expression library) ------------------------------------------------------------------- +================================================================== PCRE2 is a re-working of the original PCRE1 library to provide an entirely new API. Since its initial release in 2015, there has been further development of @@ -88,15 +88,17 @@ Building PCRE2 on non-Unix-like systems For a non-Unix-like system, please read the file NON-AUTOTOOLS-BUILD, though if your system supports the use of "configure" and "make" you may be able to build -PCRE2 using autotools in the same way as for many Unix-like systems. +PCRE2 using autotools in the same way as for many Unix-like systems. This file +also contains useful information on building for some unusual Unix environments +(such as EBCDIC mainframes). PCRE2 can also be configured using CMake, which can be run in various ways (command line, GUI, etc). This creates Makefiles, solution files, etc. The file NON-AUTOTOOLS-BUILD has information about CMake. PCRE2 has been compiled on many different operating systems. It should be -straightforward to build PCRE2 on any system that has a Standard C compiler and -library, because it uses only Standard C functions. +straightforward to build PCRE2 on any system that has a C99 or later compiler +and library. Building PCRE2 without using autotools @@ -169,6 +171,9 @@ library. They are also documented in the pcre2build man page. versions of all the relevant libraries are available for linking. See also "Shared libraries" below. + Shared libraries are compiled with symbol versioning enabled on platforms that + support this, but this can be disabled by adding --disable-symvers. + . By default, only the 8-bit library is built. If you add --enable-pcre2-16 to the "configure" command, the 16-bit library is also built. If you add --enable-pcre2-32 to the "configure" command, the 32-bit library is also @@ -309,11 +314,22 @@ library. They are also documented in the pcre2build man page. --enable-ebcdic --disable-unicode - This automatically implies --enable-rebuild-chartables (see above). However, - when PCRE2 is built this way, it always operates in EBCDIC. It cannot support - both EBCDIC and UTF-8/16/32. There is a second option, --enable-ebcdic-nl25, - which specifies that the code value for the EBCDIC NL character is 0x25 - instead of the default 0x15. + This automatically implies --enable-rebuild-chartables (see above), in order + to ensure that you have the correct default character tables for your system's + codepage. There is an exception when you set --enable-ebcdic-ignoring-compiler + (see below), which allows using a default set of EBCDIC 1047 character tables + rather than forcing use of --enable-rebuild-chartables. + + When PCRE2 is built with EBCDIC support, it always operates in EBCDIC. It + cannot support both EBCDIC and ASCII or UTF-8/16/32. + + There is a second option, --enable-ebcdic-nl25, which specifies that the code + value for the EBCDIC NL character is 0x25 instead of the default 0x15. + + There is a third option, --enable-ebcdic-ignoring-compiler, which disregards + the compiler's codepage for determining the numeric value of C character + constants such as 'z', and instead forces PCRE2 to use numeric constants for + the EBCDIC 1047 codepage instead. . If you specify --enable-debug, additional debugging code is included in the build. This option is intended for use by the PCRE2 maintainers. @@ -607,7 +623,7 @@ zip formats. The command "make distcheck" does the same, but then does a trial build of the new distribution to ensure that it works. If you have modified any of the man page sources in the doc directory, you -should first run the maint/PrepareRelease script before making a distribution. +should first run the maint/UpdateAlways script before making a distribution. This script creates the .txt and HTML forms of the documentation from the man pages. @@ -626,9 +642,9 @@ NON-AUTOTOOLS-BUILD. The RunTest script runs the pcre2test test program (which is documented in its own man page) on each of the relevant testinput files in the testdata directory, and compares the output with the contents of the corresponding -testoutput files. RunTest uses a file called testtry to hold the main output -from pcre2test. Other files whose names begin with "test" are used as working -files in some tests. +testoutput files. RunTest places its output in directories +testoutput{8,16,32}{,-jit,-dfa}. Other files whose names begin with "test" are +used as working files in some tests. Some tests are relevant only when certain build-time options were selected. For example, the tests for UTF-8/16/32 features are run only when Unicode support @@ -744,8 +760,16 @@ and with UTF support, respectively. Test 23 tests \C when it is locked out. Tests 24 and 25 test the experimental pattern conversion functions, without and with UTF support, respectively. -Test 26 checks Unicode property support using tests that are generated -automatically from the Unicode data tables. +Test 26 checks Unicode property support using tests that were generated +automatically from the Unicode data tables. These are the archived version of +the tests from Unicode 15. + +Test 27 checks Unicode property support using tests that are generated +automatically from the currently-used Unicode data tables. + +Test 28 tests EBCDIC support, and is only run when PCRE2 is specifically +compiled for EBCDIC. Test 29 tests EBCDIC when NL has been configured to be +0x25. Character tables @@ -822,11 +846,16 @@ The distribution should contain the files listed below. src/pcre2_chartables.c.dist a default set of character tables that assume ASCII coding; unless --enable-rebuild-chartables is specified, used by copying to pcre2_chartables.c + src/pcre2_chartables.c.ebcdic-1047-{nl15,nl25} a default set of character + tables for EBCDIC 1047; used if + --enable-ebcdic-ignoring-compiler is specified + without --enable-rebuild-chartables src/pcre2posix.c ) 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 ) @@ -836,11 +865,10 @@ The distribution should contain the files listed below. src/pcre2_extuni.c ) src/pcre2_find_bracket.c ) src/pcre2_jit_compile.c ) - src/pcre2_jit_match.c ) sources for the functions in the library, - src/pcre2_jit_misc.c ) and some internal functions that they use - src/pcre2_maketables.c ) - src/pcre2_match.c ) + src/pcre2_maketables.c ) sources for the functions in the library, + src/pcre2_match.c ) and some internal functions that they use src/pcre2_match_data.c ) + src/pcre2_match_next.c ) src/pcre2_newline.c ) src/pcre2_ord2utf.c ) src/pcre2_pattern_info.c ) @@ -852,11 +880,9 @@ The distribution should contain the files listed below. src/pcre2_substring.c ) src/pcre2_tables.c ) src/pcre2_ucd.c ) - src/pcre2_ucptables.c ) src/pcre2_valid_utf.c ) src/pcre2_xclass.c ) - src/pcre2_printint.c debugging function that is used by pcre2test, src/pcre2_fuzzsupport.c function for (optional) fuzzing support src/config.h.in template for config.h, when built by "configure" @@ -866,9 +892,12 @@ The distribution should contain the files listed below. src/pcre2_internal.h header for internal use src/pcre2_intmodedep.h a mode-specific internal header src/pcre2_jit_char_inc.h header used by JIT - src/pcre2_jit_neon_inc.h header used by JIT + src/pcre2_jit_match_inc.h header used by JIT + src/pcre2_jit_misc_inc.h header used by JIT src/pcre2_jit_simd_inc.h header used by JIT + src/pcre2_printint_inc.h debugging function that is used by pcre2test src/pcre2_ucp.h header for Unicode property handling + src/pcre2_ucptables_inc.h header with Unicode data tables src/pcre2_util.h header for internal utils deps/sljit/sljit_src/* source files for the JIT compiler @@ -878,6 +907,7 @@ The distribution should contain the files listed below. src/pcre2demo.c simple demonstration of coding calls to PCRE2 src/pcre2grep.c source of a grep utility that uses PCRE2 src/pcre2test.c comprehensive test program + src/pcre2test_inc.h header used by pcre2test src/pcre2_jit_test.c JIT test program src/pcre2posix_test.c POSIX wrapper API test program @@ -932,16 +962,22 @@ The distribution should contain the files listed below. testdata/testoutput* expected test results testdata/grep* input and output for pcre2grep tests testdata/* other supporting test files + src/libpcre2-8.sym ) + src/libpcre2-16.sym ) symbol version scripts for the GNU and Sun linkers + src/libpcre2-32.sym ) + src/libpcre2-posix.sym ) (D) Auxiliary files for CMake support cmake/COPYING-CMAKE-SCRIPTS cmake/FindEditline.cmake cmake/FindReadline.cmake - cmake/pcre2-config-version.cmake.in cmake/pcre2-config.cmake.in + cmake/PCRE2CheckVscript.cmake + cmake/PCRE2UseSystemExtensions.cmake + cmake/PCRE2WarningAsError.cmake + src/config-cmake.h.in CMakeLists.txt - config-cmake.h.in (E) Auxiliary files for building PCRE2 "by hand" @@ -952,9 +988,8 @@ The distribution should contain the files listed below. (F) Auxiliary files for building PCRE2 using other build systems - BUILD.bazel ) - MODULE.bazel ) files used by the Bazel build system - WORKSPACE.bazel ) + BUILD.bazel ) files used by the Bazel + MODULE.bazel ) build system build.zig file used by zig's build system (G) Auxiliary files for building PCRE2 under OpenVMS @@ -964,7 +999,7 @@ The distribution should contain the files listed below. vms/pcre2.h_patch ) vms/stdint.h ) -============================== -Last updated: 18 December 2024 -============================== +============================= +Last updated: 15 October 2025 +============================= diff --git a/RunGrepTest b/RunGrepTest index 396884c..76af369 100755 --- a/RunGrepTest +++ b/RunGrepTest @@ -728,7 +728,7 @@ echo "---------------------------- Test 131 -----------------------------" >>tes echo "RC=$?" >>testtrygrep echo "---------------------------- Test 132 -----------------------------" >>testtrygrep -(cd $srcdir; exec 3>testtrygrep 2>&1 +(cd $srcdir; exec 3>testtrygrep 2>&1 echo "RC=$?" >>testtrygrep echo "---------------------------- Test 133 -----------------------------" >>testtrygrep @@ -859,8 +859,13 @@ if [ $? -ne 0 ]; then echo "RC=2" >>testtrygrep else - (cd $srcdir; unset LC_ALL; LC_CTYPE=locale.bad $valgrind $vjs $pcre2grep abc /dev/null) >>testtrygrep 2>&1 + (cd $srcdir; unset LC_ALL; LC_CTYPE=locale.bad; export LC_CTYPE; $valgrind $vjs $pcre2grep abc /dev/null >>$builddir/testtrygrep 2>&1) >testtemp1grep 2>&1 echo "RC=$?" >>testtrygrep + shell_errors=`cat testtemp1grep` + if [ x"$shell_errors" != x ] ; then + printf "shell errors during locale test: " + echo "$shell_errors" + fi fi echo "---------------------------- Test 151 -----------------------------" >>testtrygrep @@ -1148,6 +1153,9 @@ checkspecial '--line-buffered --colour=auto abc /dev/null' 1 checkspecial '--line-buffered --color abc /dev/null' 1 checkspecial '-dskip abc .' 1 checkspecial '-Dread -Dskip abc /dev/null' 1 +checkspecial "-f $srcdir/testdata/greplistBad /dev/null" 2 +checkspecial "(unpaired /dev/null" 2 +checkspecial "-e (unpaired1 -e (unpaired2 /dev/null" 2 # Clean up local working files rm -f testNinputgrep teststderrgrep testtrygrep testtemp1grep testtemp2grep diff --git a/RunGrepTest.bat b/RunGrepTest.bat index b7ee629..3c918e3 100644 --- a/RunGrepTest.bat +++ b/RunGrepTest.bat @@ -693,7 +693,7 @@ echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 132 ----------------------------->>testtrygrep :: The Unix tests use fd3 here, but Windows only has StdIn/StdOut/StdErr (which, at the kernel :: level, are not even numbered). Use a subshell instead. -(pushd %srcdir% & (%pcre2grep% -m1 -A3 "^match" & echo ---& head -1) >testtrygrep 2>&1 +(pushd %srcdir% & (%pcre2grep% -m1 -A3 "^match" & echo ---& %pcre2grep% -m1 ".*") >testtrygrep 2>&1 echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 133 ----------------------------->>testtrygrep @@ -1089,6 +1089,9 @@ call :checkspecial "--line-buffered --colour=auto abc nul" 1 || exit /b 1 call :checkspecial "--line-buffered --color abc nul" 1 || exit /b 1 call :checkspecial "-dskip abc ." 1 || exit /b 1 call :checkspecial "-Dread -Dskip abc nul" 1 || exit /b 1 +call :checkspecial "-f %srcdir%\testdata\greplistBad nul" 2 || exit /b 1 +call :checkspecial "(unpaired nul" 2 || exit /b 1 +call :checkspecial "-e (unpaired1 -e (unpaired2 nul" 2 || exit /b 1 :: Clean up local working files diff --git a/RunTest b/RunTest index dafef3e..57a0345 100755 --- a/RunTest +++ b/RunTest @@ -45,15 +45,9 @@ # very much more stack than normal. In environments where the stack can be # set at runtime, -bigstack sets a gigantic stack. # -# There are two special cases where only one argument is allowed: -# -# If the first and only argument is "ebcdic", the script runs the special -# EBCDIC test that can be useful for checking certain EBCDIC features, even -# when run in an ASCII environment. PCRE2 must be built with EBCDIC support for -# this test to be run. -# -# If the script is obeyed as "RunTest list", a list of available tests is -# output, but none of them are run. +# Special cases where only one argument is allowed: +# - If the script is invoked as "RunTest list", a list of available tests is +# output, but none of them are run. ############################################################################### # Define test titles in variables so that they can be output as a list. Some @@ -90,7 +84,9 @@ title24="Test 24: Non-UTF pattern conversion tests" title25="Test 25: UTF pattern conversion tests" title26="Test 26: Unicode property tests (compatible with Perl >= 5.38)" title27="Test 27: Auto-generated unicode property tests" -maxtest=27 +title28="Test 28: EBCDIC-specific tests" +title29="Test 29: EBCDIC-specific tests (for NL=0x25)" +maxtest=29 titleheap="Test 'heap': Environment-specific heap tests" if [ $# -eq 1 -a "$1" = "list" ]; then @@ -122,6 +118,8 @@ if [ $# -eq 1 -a "$1" = "list" ]; then echo $title25 echo $title26 echo $title27 + echo $title28 + echo $title29 echo "" echo $titleheap echo "" @@ -132,9 +130,11 @@ fi # Set up a suitable "diff" command for comparison. Some systems # have a diff that lacks a -u option. Try to deal with this. +# Use gdiff if available. cf="diff" -diff -u /dev/null /dev/null 2>/dev/null && cf="diff -u" +gdiff /dev/null /dev/null 2>/dev/null && cf="gdiff" +$cf -u /dev/null /dev/null 2>/dev/null && cf="$cf -u" # Find the test data @@ -149,6 +149,8 @@ else exit 1 fi +yield=0 + # ------ Function to check results of a test ------- @@ -163,19 +165,29 @@ fi checkresult() { if [ $1 -ne 0 ] ; then - echo "** pcre2test failed - check testtry" - exit 1 + echo "** pcre2test failed - check testoutput$bits$3/testoutput$2" + yield=1 + return fi case "$3" in -jit) with=" with JIT";; -dfa) with=" with DFA";; *) with="";; esac - $cf $testdata/testoutput$2 testtry + cf_out="$testdata/testoutput$2" + if [ $ebcdic -eq 1 ] ; then + # We currently only use the #if ... #endif support in pcre2test for EBCDIC + # testing. Run in "preprocess-only" mode (-E) on the testoutput file to trim + # the output lines matching the input lines which are discarded. + $sim $pcre2test -q -E "$cf_out" >testoutput$bits$3/testoutput$2-expected + cf_out=testoutput$bits$3/testoutput$2-expected + fi + $cf "$cf_out" testoutput$bits$3/testoutput$2 if [ $? != 0 ] ; then echo "" echo "** Test $2 failed$with" - exit 1 + yield=1 + return fi echo " OK$with" } @@ -185,11 +197,14 @@ checkresult() checkspecial() { - $sim $valgrind $vjs $pcre2test $1 >>testtry - if [ $? -ne 0 ] ; then - echo "** pcre2test $1 failed - check testtry" - exit 1 + expect=${2:-0} + $sim $valgrind $vjs $pcre2test $1 >>testSoutput 2>&1 + if [ $? -ne "$expect" ] ; then + echo "** pcre2test $1 failed - check testSoutput" + yield=1 + return 1 fi + return 0 } @@ -202,10 +217,12 @@ arg16= arg32= nojit= bigstack= +malloc= sim= skip= valgrind= vjs= +globalopts="-q" : ${pcre2test:=./pcre2test} # This is in case the caller has set aliases (as I do - PH) @@ -247,8 +264,9 @@ do24=no do25=no do26=no do27=no +do28=no +do29=no doheap=no -doebcdic=no while [ $# -gt 0 ] ; do case $1 in @@ -280,16 +298,18 @@ while [ $# -gt 0 ] ; do 25) do25=yes;; 26) do26=yes;; 27) do27=yes;; + 28) do28=yes;; + 29) do29=yes;; heap) doheap=yes;; - ebcdic) doebcdic=yes;; -8) arg8=yes;; -16) arg16=yes;; -32) arg32=yes;; bigstack|-bigstack) bigstack=yes;; + malloc|-malloc) malloc=yes;; nojit|-nojit) nojit=yes;; sim|-sim) shift; sim=$1;; - valgrind|-valgrind) valgrind="valgrind --tool=memcheck -q --smc-check=all-non-file --error-exitcode=70";; - valgrind-log|-valgrind-log) valgrind="valgrind --tool=memcheck --num-callers=30 --leak-check=no --error-limit=no --smc-check=all-non-file --log-file=report.%p ";; + valgrind|-valgrind) valgrind="valgrind --tool=memcheck -q --leak-check=yes --errors-for-leak-kinds=all --smc-check=all-non-file --error-exitcode=70";; + valgrind-log|-valgrind-log) valgrind="valgrind --tool=memcheck --num-callers=30 --leak-check=yes --errors-for-leak-kinds=all --error-limit=no --smc-check=all-non-file --log-file=report.%p ";; ~*) if expr "$1" : '~[0-9][0-9]*$' >/dev/null; then skip="$skip `expr "$1" : '~\([0-9]*\)*$'`" @@ -318,28 +338,19 @@ while [ $# -gt 0 ] ; do shift done -# Find which optional facilities are available. - -$sim $pcre2test -C linksize >/dev/null -link_size=$? -if [ $link_size -lt 2 ] ; then - echo "RunTest: Failed to find internal link size" - exit 1 -fi -if [ $link_size -gt 4 ] ; then - echo "RunTest: Failed to find internal link size" - exit 1 -fi - # If it is possible to set the system stack size and -bigstack was given, # set up a large stack. -$sim $pcre2test -S 32 /dev/null /dev/null +$sim $pcre2test -S 32 /dev/null /dev/null >/dev/null 2>&1 support_setstack=$? if [ $support_setstack -eq 0 -a "$bigstack" != "" ] ; then - setstack="-S 32" -else - setstack="" + globalopts="$globalopts -S 32" +fi + +# If the malloc option is given, then call pcre2test with -malloc. + +if [ "$malloc" != "" ] ; then + globalopts="$globalopts -malloc" fi # All of 8-bit, 16-bit, and 32-bit character strings may be supported, but only @@ -357,6 +368,27 @@ support32=$? $sim $pcre2test -C backslash-C >/dev/null supportBSC=$? +# Check if compiled in EBCDIC mode, and whether we have EBCDIC I/O and NL=0x25 +$sim $pcre2test -C ebcdic >/dev/null +ebcdic=$? +$sim $pcre2test -C ebcdic-io >/dev/null +ebcdic_io=$? +$sim $pcre2test -C ebcdic-nl25 >/dev/null +ebcdic_nl25=$? + +if [ $ebcdic -eq 1 ]; then + if [ $ebcdic_io -eq 0 ]; then + echo "Running tests in EBCDIC mode, and expecting ASCII test data" + else + echo "Running tests in EBCDIC mode, and expecting EBCDIC test data" + echo "If you are on an EBCDIC machine, you will need to convert the PCRE2" + echo "testdata/ directory from ISO8859-1, so the data match the EBCDIC" + echo "codepage that your C compiler is using for C character literals." + echo "For example:" + echo " iconv -f ISO8859-1 -t IBM-1047 ..." + fi +fi + # Initialize all bitsizes skipped test8=skip @@ -433,7 +465,7 @@ if [ $do0 = no -a $do1 = no -a $do2 = no -a $do3 = no -a \ $do16 = no -a $do17 = no -a $do18 = no -a $do19 = no -a \ $do20 = no -a $do21 = no -a $do22 = no -a $do23 = no -a \ $do24 = no -a $do25 = no -a $do26 = no -a $do27 = no -a \ - $doheap = no -a $doebcdic = no \ + $do28 = no -a $do29 = no -a $doheap = no \ ]; then do0=yes do1=yes @@ -463,6 +495,8 @@ if [ $do0 = no -a $do1 = no -a $do2 = no -a $do3 = no -a \ do25=yes do26=yes do27=yes + do28=yes + do29=yes fi # Handle any explicit skips at this stage, so that an argument list may consist @@ -490,6 +524,11 @@ for bmode in "$test8" "$test16" "$test32"; do -8) bits=8; echo "---- Testing 8-bit library ----"; echo "";; esac + # Set up directories for test output. + [ -d testoutput$bits ] || mkdir testoutput$bits + [ -d testoutput$bits$jitopt ] || mkdir testoutput$bits$jitopt + [ -d testoutput$bits-dfa ] || mkdir testoutput$bits-dfa + # Test 0 is a special test. Its output is not checked, because it will # be different on different hardware and with different configurations. # Running this test just exercises the code. @@ -498,13 +537,28 @@ for bmode in "$test8" "$test16" "$test32"; do echo $title0 echo '/abc/jit,memory,framesize' >testSinput echo ' abc' >>testSinput - echo '' >testtry - checkspecial '-C' - checkspecial '--help' + echo '' >testSoutput + saverc=0 + checkspecial "$bmode -C" || saverc=$? + checkspecial '--help' || saverc=$? + checkspecial "$bmode testSinput" || saverc=$? + checkspecial "$bmode $testdata/testinputheap" || saverc=$? if [ $support_setstack -eq 0 ] ; then - checkspecial '-S 1 -t 10 testSinput' + checkspecial "$bmode -S 1 -t 10 testSinput" || saverc=$? + fi + checkspecial "$bmode reallydoesnotexist" 1 || saverc=$? + checkspecial "$bmode testSinput reallydoesnotexist/outfile" 1 || saverc=$? + checkspecial "$bmode -pattern debug testSinput" || saverc=$? + checkspecial "$bmode -pattern INVALID testSinput" 1 2>/dev/null || saverc=$? + checkspecial "$bmode -subject notempty testSinput" || saverc=$? + checkspecial "$bmode -subject INVALID testSinput" 1 2>/dev/null || saverc=$? + checkspecial -LM || saverc=$? + checkspecial -LP || saverc=$? + checkspecial -LS || saverc=$? + checkspecial "$bmode -unittest" || saverc=$? + if [ $saverc -eq 0 ] ; then + echo " OK" fi - echo " OK" fi # Primary non-UTF test, compatible with JIT and all versions of Perl >= 5.8 @@ -512,7 +566,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $do1 = yes ] ; then echo $title1 for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput1 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput1 testoutput$bits$opt/testoutput1 checkresult $? 1 "$opt" done fi @@ -524,10 +578,10 @@ for bmode in "$test8" "$test16" "$test32"; do echo $title2 "(excluding UTF-$bits)" cp $testdata/testbtables . for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput2 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput2 testoutput$bits$opt/testoutput2 saverc=$? if [ $saverc = 0 ] ; then - $sim $valgrind ${opt:+$vjs} $pcre2test -q $bmode $opt -error -80,-62,-2,-1,0,100,101,191,300 >>testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt -error -80,-62,-2,-1,0,100,101,191,300 >>testoutput$bits$opt/testoutput2 checkresult $? 2 "$opt" else checkresult $saverc 2 "$opt" @@ -562,15 +616,18 @@ for bmode in "$test8" "$test16" "$test32"; do outfile=$testdata/testoutput3 outfile2=$testdata/testoutput3A outfile3=$testdata/testoutput3B + outfile4=$testdata/testoutput3C else infile=test3input outfile=test3output outfile2=test3outputA outfile3=test3outputB + outfile4=test3outputC sed "s/fr_FR/$loc/" $testdata/testinput3 >test3input sed "s/fr_FR/$loc/" $testdata/testoutput3 >test3output sed "s/fr_FR/$loc/" $testdata/testoutput3A >test3outputA sed "s/fr_FR/$loc/" $testdata/testoutput3B >test3outputB + sed "s/fr_FR/$loc/" $testdata/testoutput3C >test3outputC fi break fi @@ -580,25 +637,30 @@ for bmode in "$test8" "$test16" "$test32"; do if [ "$locale" != "" ] ; then echo $title3 "(using '$locale' locale)" for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $infile testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $infile testoutput$bits/testoutput3 if [ $? = 0 ] ; then case "$opt" in -jit) with=" with JIT";; *) with="";; esac - if $cf $outfile testtry >teststdout || \ - $cf $outfile2 testtry >teststdout || \ - $cf $outfile3 testtry >teststdout + if $cf $outfile testoutput$bits/testoutput3 >teststdout || \ + $cf $outfile2 testoutput$bits/testoutput3 >>teststdout || \ + $cf $outfile3 testoutput$bits/testoutput3 >>teststdout || \ + $cf $outfile4 testoutput$bits/testoutput3 >>teststdout then echo " OK$with" else + cat teststdout + echo "" echo "** Locale test did not run successfully$with. The output did not match" - echo " $outfile, $outfile2 or $outfile3." + echo " $outfile, $outfile2, $outfile3 or $outfile4." echo " This may mean that there is a problem with the locale settings rather" echo " than a bug in PCRE2." - exit 1 + yield=1 fi - else exit 1 + else + echo "** pcre2test failed - check testoutput$bits/testoutput3" + yield=1 fi done else @@ -617,7 +679,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because UTF-$bits support is not available" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput4 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput4 testoutput$bits$opt/testoutput4 checkresult $? 4 "$opt" done fi @@ -629,7 +691,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because UTF-$bits support is not available" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput5 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput5 testoutput$bits$opt/testoutput5 checkresult $? 5 "$opt" done fi @@ -639,7 +701,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $do6 = yes ] ; then echo $title6 - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput6 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput6 testoutput$bits/testoutput6 checkresult $? 6 "" fi @@ -648,7 +710,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $utf -eq 0 ] ; then echo " Skipped because UTF-$bits support is not available" else - $sim $valgrind $pcre2test -q $setstack $bmode $opt $testdata/testinput7 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput7 testoutput$bits/testoutput7 checkresult $? 7 "" fi fi @@ -663,11 +725,13 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $do8 = yes ] ; then echo $title8 + $sim $pcre2test -$bits -C linksize >/dev/null + bits_link_size=$? if [ $utf -eq 0 ] ; then echo " Skipped because UTF-$bits support is not available" else - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput8 testtry - checkresult $? 8-$bits-$link_size "" + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput8 testoutput$bits/testoutput8-$bits-$bits_link_size + checkresult $? 8-$bits-$bits_link_size "" fi fi @@ -679,7 +743,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped when running 16/32-bit tests" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput9 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput9 testoutput$bits$opt/testoutput9 checkresult $? 9 "$opt" done fi @@ -695,7 +759,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because UTF-$bits support is not available" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput10 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput10 testoutput$bits$opt/testoutput10 checkresult $? 10 "$opt" done fi @@ -709,7 +773,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped when running 8-bit tests" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput11 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput11 testoutput$bits$opt/testoutput11-$bits checkresult $? 11-$bits "$opt" done fi @@ -726,7 +790,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because UTF-$bits support is not available" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput12 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput12 testoutput$bits$opt/testoutput12-$bits checkresult $? 12-$bits "$opt" done fi @@ -739,7 +803,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ "$bits" = "8" ] ; then echo " Skipped when running 8-bit tests" else - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput13 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput13 testoutput$bits/testoutput13 checkresult $? 13 "" fi fi @@ -751,7 +815,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $utf -eq 0 ] ; then echo " Skipped because UTF-$bits support is not available" else - $sim $valgrind $pcre2test -q $setstack $bmode $opt $testdata/testinput14 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput14 testoutput$bits/testoutput14-$bits checkresult $? 14-$bits "" fi fi @@ -760,7 +824,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $do15 = yes ] ; then echo $title15 - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput15 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput15 testoutput$bits/testoutput15 checkresult $? 15 "" fi @@ -771,7 +835,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $jit -ne 0 ] ; then echo " Skipped because JIT is available" else - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput16 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput16 testoutput$bits/testoutput16 checkresult $? 16 "" fi fi @@ -783,7 +847,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $jit -eq 0 -o "$nojit" = "yes" ] ; then echo " Skipped because JIT is not available or nojit was specified" else - $sim $valgrind $vjs $pcre2test -q $setstack $bmode $testdata/testinput17 testtry + $sim $valgrind $vjs $pcre2test $globalopts $bmode $testdata/testinput17 testoutput$bits/testoutput17 checkresult $? 17 "" fi fi @@ -795,7 +859,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ "$bits" = "16" -o "$bits" = "32" ] ; then echo " Skipped when running 16/32-bit tests" else - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput18 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput18 testoutput$bits/testoutput18 checkresult $? 18 "" fi fi @@ -809,7 +873,7 @@ for bmode in "$test8" "$test16" "$test32"; do elif [ $utf -eq 0 ] ; then echo " Skipped because UTF-$bits support is not available" else - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput19 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput19 testoutput$bits/testoutput19 checkresult $? 19 "" fi fi @@ -818,7 +882,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $do20 = yes ] ; then echo $title20 - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput20 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput20 testoutput$bits/testoutput20 checkresult $? 20 "" fi @@ -830,7 +894,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because \C is disabled" else for opt in "" $jitopt -dfa; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput21 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput21 testoutput$bits$opt/testoutput21 checkresult $? 21 "$opt" done fi @@ -846,7 +910,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because UTF-$bits support is not available" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput22 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput22 testoutput$bits$opt/testoutput22-$bits checkresult $? 22-$bits "$opt" done fi @@ -859,7 +923,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $supportBSC -ne 0 ] ; then echo " Skipped because \C is not disabled" else - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput23 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput23 testoutput$bits/testoutput23 checkresult $? 23 "" fi fi @@ -868,7 +932,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ "$do24" = yes ] ; then echo $title24 - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput24 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput24 testoutput$bits/testoutput24 checkresult $? 24 "" fi @@ -879,7 +943,7 @@ for bmode in "$test8" "$test16" "$test32"; do if [ $utf -eq 0 ] ; then echo " Skipped because UTF-$bits support is not available" else - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput25 testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput25 testoutput$bits/testoutput25 checkresult $? 25 "" fi fi @@ -892,7 +956,7 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because UTF-$bits support is not available" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput26 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput26 testoutput$bits$opt/testoutput26 checkresult $? 26 "$opt" done fi @@ -906,18 +970,48 @@ for bmode in "$test8" "$test16" "$test32"; do echo " Skipped because UTF-$bits support is not available" else for opt in "" $jitopt; do - $sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput27 testtry + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput27 testoutput$bits$opt/testoutput27 checkresult $? 27 "$opt" done fi fi + # EBCDIC tests + + if [ $do28 = yes ] ; then + echo $title28 + if [ $ebcdic -eq 0 ] ; then + echo " Skipped when not targetting EBCDIC" + else + for opt in "" $jitopt "-dfa"; do + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput28 testoutput$bits$opt/testoutput28 + checkresult $? 28 "$opt" + done + fi + fi + + # EBCDIC tests (for NL=0x25) + + if [ $do29 = yes ] ; then + echo $title29 + if [ $ebcdic -eq 0 ] ; then + echo " Skipped when not targetting EBCDIC" + elif [ $ebcdic_nl25 -eq 0 ] ; then + echo " Skipped because EBCDIC newline is not 0x25" + else + for opt in "" $jitopt "-dfa"; do + $sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput29 testoutput$bits$opt/testoutput29 + checkresult $? 29 "$opt" + done + fi + fi + # Manually selected heap tests - output may vary in different environments, # which is why that are not automatically run. if [ $doheap = yes ] ; then echo $titleheap - $sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinputheap testtry + $sim $valgrind $pcre2test $globalopts $bmode $testdata/testinputheap testoutput$bits/testoutputheap-$bits checkresult $? heap-$bits "" fi @@ -925,23 +1019,20 @@ for bmode in "$test8" "$test16" "$test32"; do done -# ------ Special EBCDIC Test ------- +if [ $yield -eq 0 ] ; then + echo "" + echo "All tests passed." -if [ $doebcdic = yes ] ; then - $sim $valgrind $pcre2test -C ebcdic >/dev/null - ebcdic=$? - if [ $ebcdic -ne 1 ] ; then - echo "Cannot run EBCDIC tests: EBCDIC support not compiled" - exit 1 - fi - for opt in "" "-dfa"; do - $sim $valgrind $pcre2test -q $opt $testdata/testinputEBC >testtry - checkresult $? EBC "$opt" - done + # Clean up local working files + rm -f testbtables testSinput testSoutput test3input test3output test3outputA test3outputB testsaved1 testsaved2 teststdout teststderr + rm -rf testoutput8 testoutput8-jit testoutput8-dfa \ + testoutput16 testoutput16-jit testoutput16-dfa \ + testoutput32 testoutput32-jit testoutput32-dfa +else + echo "" + echo "** Tests failed. See output above for details." fi - -# Clean up local working files -rm -f testbtables testSinput test3input testsaved1 testsaved2 test3output test3outputA test3outputB teststdout teststderr testtry +exit $yield # End diff --git a/RunTest.bat b/RunTest.bat index 67e5202..f55e5bb 100644 --- a/RunTest.bat +++ b/RunTest.bat @@ -1,8 +1,7 @@ @echo off @rem @rem MS Windows batch file to run pcre2test on testfiles with the correct -@rem options. This file must use CRLF linebreaks to function properly, -@rem and requires both pcre2test and pcre2grep. +@rem options. This file must use CRLF linebreaks to function properly. @rem @rem ------------------------ HISTORY ---------------------------------- @rem This file was originally contributed to PCRE1 by Ralf Junker, and touched @@ -14,7 +13,7 @@ @rem @rem Sheri Pierce added logic to skip feature dependent tests @rem tests 4 5 7 10 12 14 19 22 25 and 26 require Unicode support -@rem 8 requires Unicode and link size 2 +@rem 8 requires Unicode @rem 16 requires absence of jit support @rem 17 requires presence of jit support @rem Sheri P also added override tests for study and jit testing @@ -57,8 +56,6 @@ call :conferror exit /b 1 ) -%pcre2test% -C linksize >NUL -set link_size=%ERRORLEVEL% %pcre2test% -C pcre2-8 >NUL set support8=%ERRORLEVEL% %pcre2test% -C pcre2-16 >NUL @@ -71,6 +68,10 @@ set unicode=%ERRORLEVEL% set jit=%ERRORLEVEL% %pcre2test% -C backslash-C >NUL set supportBSC=%ERRORLEVEL% +%pcre2test% -C ebcdic >NUL +set ebcdic=%ERRORLEVEL% +%pcre2test% -C ebcdic-nl25 >NUL +set ebcdic_nl25=%ERRORLEVEL% if %support8% EQU 1 ( if not exist testout8 md testout8 @@ -114,18 +115,20 @@ set do24=no set do25=no set do26=no set do27=no +set do28=no +set do29=no set all=yes for %%a in (%*) do ( set valid=no - for %%v in (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) do if %%v == %%a set valid=yes + for %%v in (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) do if %%v == %%a set valid=yes if "!valid!" == "yes" ( set do%%a=yes set all=no ) else ( echo Invalid test number - %%a! echo Usage %0 [ test_number ] ... - echo Where test_number is one or more optional test numbers 1 through 27, default is all tests. + echo Where test_number is one or more optional test numbers 1 through 29, default is all tests. exit /b 1 ) ) @@ -159,6 +162,8 @@ if "%all%" == "yes" ( set do25=yes set do26=yes set do27=yes + set do28=yes + set do29=yes ) @echo RunTest.bat's pcre2test output is written to newly created subfolders @@ -214,6 +219,8 @@ if "%do24%" == "yes" call :do24 if "%do25%" == "yes" call :do25 if "%do26%" == "yes" call :do26 if "%do27%" == "yes" call :do27 +if "%do28%" == "yes" call :do28 +if "%do29%" == "yes" call :do29 :modeSkip if "%mode%" == "" ( set mode=-16 @@ -259,7 +266,9 @@ if [%3] == [] ( ) if %1 == 8 ( - set outnum=%1-%bits%-%link_size% + %pcre2test% -%bits% -C linksize >NUL + set bits_link_size=!ERRORLEVEL! + set outnum=%1-%bits%-!bits_link_size! ) else if %1 == 11 ( set outnum=%1-%bits% ) else if %1 == 12 ( @@ -289,10 +298,20 @@ if errorlevel 1 ( %pcre2test% %mode% %4 %5 %6 %7 %8 %9 -error -80,-62,-2,-1,0,100,101,191,300 >>%2%bits%\%testoutput% ) -fc /n %srcdir%\testdata\%testoutput% %2%bits%\%testoutput% >NUL +set testexpected=%srcdir%\testdata\%testoutput% + +if %ebcdic% EQU 1 ( + @rem We currently only use the #if ... #endif support in pcre2test for EBCDIC + @rem testing. Run in "preprocess-only" mode (-E) on the testoutput file to trim + @rem the output lines matching the input lines which are discarded. + %pcre2test% -q -E %testexpected% >%2%bits%\%testoutput%-trimmed + set testexpected=%2%bits%\%testoutput%-trimmed +) + +fc /n %testexpected% %2%bits%\%testoutput% >NUL if errorlevel 1 ( - echo. failed comparison: fc /n %srcdir%\testdata\%testoutput% %2%bits%\%testoutput% + echo. failed comparison: fc /n %testexpected% %2%bits%\%testoutput% if [%1]==[3] ( echo. echo ** Test 3 failure usually means french locale is not @@ -300,7 +319,7 @@ if errorlevel 1 ( echo. goto :eof ) - fc /n %srcdir%\testdata\%testoutput% %2%bits%\%testoutput% + fc /n %testexpected% %2%bits%\%testoutput% set failed="yes" goto :eof @@ -356,10 +375,6 @@ if %unicode% EQU 0 ( goto :eof :do8 -if NOT %link_size% EQU 2 ( - echo Test 8 Skipped because link size is not 2. - goto :eof -) if %unicode% EQU 0 ( echo Test 8 Skipped due to absence of Unicode support. goto :eof @@ -540,6 +555,30 @@ if %unicode% EQU 0 ( if %jit% EQU 1 call :runsub 27 testoutjit "Test with JIT Override" -q -jit goto :eof +:do28 +if %ebcdic% EQU 0 ( + echo Test 28 Skipped when not targetting EBCDIC. + goto :eof +) + call :runsub 28 testout "EBCDIC-specific tests" -q + call :runsub 28 testout "EBCDIC-specific tests (DFA)" -q -dfa + if %jit% EQU 1 call :runsub 28 testoutjit "Test with JIT Override" -q -jit +goto :eof + +:do29 +if %ebcdic% EQU 0 ( + echo Test 29 Skipped when not targetting EBCDIC. + goto :eof +) +if %ebcdic_nl25% EQU 0 ( + echo Test 29 Skipped because EBCDIC newline is not 0x25. + goto :eof +) + call :runsub 29 testout "EBCDIC-specific tests for NL=0x25" -q + call :runsub 29 testout "EBCDIC-specific tests for NL=0x25 (DFA)" -q -dfa + if %jit% EQU 1 call :runsub 29 testoutjit "Test with JIT Override" -q -jit +goto :eof + :conferror @echo. @echo Either your build is incomplete or you have a configuration error. diff --git a/SECURITY.md b/SECURITY.md index b39ddb7..a9cd7c1 100644 --- a/SECURITY.md +++ b/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,12 +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. -## Previous vulnerabilities +Previous vulnerabilities +------------------------ * CVE-2025-58050 (August 2025). Affects 10.45 only (not earlier), and is fixed in 10.46. -## Reporting vulnerabilities +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 diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel deleted file mode 100644 index 4ce2c8c..0000000 --- a/WORKSPACE.bazel +++ /dev/null @@ -1 +0,0 @@ -# See MODULE.bazel diff --git a/aclocal.m4 b/aclocal.m4 index d7c332c..ea61c79 100644 --- a/aclocal.m4 +++ b/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/build.zig b/build.zig index 4cb6d99..960137a 100644 --- a/build.zig +++ b/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 = b.addExecutable(.{ - .name = "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", + .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/cmake/FindEditline.cmake b/cmake/FindEditline.cmake index 38d075f..c973c7b 100644 --- a/cmake/FindEditline.cmake +++ b/cmake/FindEditline.cmake @@ -1,13 +1,10 @@ # Modified from FindReadline.cmake (PH Feb 2012) -if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY) - set(EDITLINE_FOUND TRUE) -else() - find_path(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES editline edit/readline) +find_path(EDITLINE_INCLUDE_DIR readline.h PATH_SUFFIXES editline edit/readline) +mark_as_advanced(EDITLINE_INCLUDE_DIR) - find_library(EDITLINE_LIBRARY NAMES edit) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Editline DEFAULT_MSG EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY) +find_library(EDITLINE_LIBRARY NAMES edit) +mark_as_advanced(EDITLINE_LIBRARY) - mark_as_advanced(EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY) -endif() +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Editline DEFAULT_MSG EDITLINE_LIBRARY EDITLINE_INCLUDE_DIR) diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake index 6b65046..399096c 100644 --- a/cmake/FindReadline.cmake +++ b/cmake/FindReadline.cmake @@ -3,25 +3,50 @@ # --> BSD licensed # # GNU Readline library finder -if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY) - set(READLINE_FOUND TRUE) -else() - find_path(READLINE_INCLUDE_DIR readline/readline.h /usr/include/readline) - - # 2008-04-22 The next clause used to read like this: - # - # FIND_LIBRARY(READLINE_LIBRARY NAMES readline) - # FIND_LIBRARY(NCURSES_LIBRARY NAMES ncurses ) - # include(FindPackageHandleStandardArgs) - # FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG NCURSES_LIBRARY READLINE_INCLUDE_DIR READLINE_LIBRARY ) - # - # I was advised to modify it such that it will find an ncurses library if - # required, but not if one was explicitly given, that is, it allows the - # default to be overridden. PH - - find_library(READLINE_LIBRARY NAMES readline) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY) - - mark_as_advanced(READLINE_INCLUDE_DIR READLINE_LIBRARY) + +find_path(READLINE_INCLUDE_DIR readline/readline.h PATH_SUFFIXES include) +mark_as_advanced(READLINE_INCLUDE_DIR) + +find_library(READLINE_LIBRARY NAMES readline) +mark_as_advanced(READLINE_LIBRARY) + +if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY) + # Check if we need to link to ncurses as well + + include(CheckSymbolExists) + include(CMakePushCheckState) + + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}") + set(CMAKE_REQUIRED_INCLUDES "${READLINE_INCLUDE_DIR}") + check_symbol_exists("readline" "stdio.h;readline/readline.h" HAVE_READLINE_FUNC) + + if(NOT HAVE_READLINE_FUNC) + foreach( + lib + IN + ITEMS tinfo curses ncurses ncursesw termcap + ) + find_library(NCURSES_LIBRARY_${lib} NAMES ${lib}) + mark_as_advanced(NCURSES_LIBRARY_${lib}) + if(NCURSES_LIBRARY_${lib}) + cmake_reset_check_state() + set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}" "${NCURSES_LIBRARY_${lib}}") + set(CMAKE_REQUIRED_INCLUDES "${READLINE_INCLUDE_DIR}") + check_symbol_exists("readline" "stdio.h;readline/readline.h" HAVE_READLINE_FUNC_${lib}) + + if(HAVE_READLINE_FUNC_${lib}) + message(STATUS "Looking for readline - readline needs ${lib}") + set(NCURSES_LIBRARY "${NCURSES_LIBRARY_${lib}}" CACHE FILEPATH "Path to the ncurses library") + mark_as_advanced(NCURSES_LIBRARY) + break() + endif() + endif() + endforeach() + endif() + + cmake_pop_check_state() endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR) diff --git a/cmake/PCRE2CheckVscript.cmake b/cmake/PCRE2CheckVscript.cmake new file mode 100644 index 0000000..ed3ae12 --- /dev/null +++ b/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/cmake/PCRE2UseSystemExtensions.cmake b/cmake/PCRE2UseSystemExtensions.cmake new file mode 100644 index 0000000..a70a5f7 --- /dev/null +++ b/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/cmake/PCRE2WarningAsError.cmake b/cmake/PCRE2WarningAsError.cmake new file mode 100644 index 0000000..78b76a5 --- /dev/null +++ b/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/cmake/pcre2-config-version.cmake.in b/cmake/pcre2-config-version.cmake.in deleted file mode 100644 index db00606..0000000 --- a/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/cmake/pcre2-config.cmake.in b/cmake/pcre2-config.cmake.in index 082dc19..bda4841 100644 --- a/cmake/pcre2-config.cmake.in +++ b/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() - - 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() +@PACKAGE_INIT@ - 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) -# Set version -if(PCRE2_INCLUDE_DIR) - set(PCRE2_VERSION "@PCRE2_MAJOR@.@PCRE2_MINOR@.0") -endif() +include("${CMAKE_CURRENT_LIST_DIR}/pcre2-targets.cmake") -# 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() +# Set version +set(PCRE2_VERSION "@PCRE2_MAJOR@.@PCRE2_MINOR@.0") -# 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/config-cmake.h.in b/config-cmake.h.in deleted file mode 100644 index 0eff0e0..0000000 --- a/config-cmake.h.in +++ /dev/null @@ -1,58 +0,0 @@ -/* config.h for CMake builds */ - -#cmakedefine HAVE_ASSERT_H 1 -#cmakedefine HAVE_BUILTIN_ASSUME 1 -#cmakedefine HAVE_BUILTIN_MUL_OVERFLOW 1 -#cmakedefine HAVE_BUILTIN_UNREACHABLE 1 -#cmakedefine HAVE_ATTRIBUTE_UNINITIALIZED 1 -#cmakedefine HAVE_DIRENT_H 1 -#cmakedefine HAVE_SYS_STAT_H 1 -#cmakedefine HAVE_SYS_TYPES_H 1 -#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 -#cmakedefine SUPPORT_PCRE2_32 1 -#cmakedefine DISABLE_PERCENT_ZT 1 - -#cmakedefine SUPPORT_LIBBZ2 1 -#cmakedefine SUPPORT_LIBEDIT 1 -#cmakedefine SUPPORT_LIBREADLINE 1 -#cmakedefine SUPPORT_LIBZ 1 - -#cmakedefine SUPPORT_JIT 1 -#cmakedefine SLJIT_PROT_EXECUTABLE_ALLOCATOR 1 -#cmakedefine SUPPORT_PCRE2GREP_JIT 1 -#cmakedefine SUPPORT_PCRE2GREP_CALLOUT 1 -#cmakedefine SUPPORT_PCRE2GREP_CALLOUT_FORK 1 -#cmakedefine SUPPORT_UNICODE 1 -#cmakedefine SUPPORT_VALGRIND 1 - -#cmakedefine BSR_ANYCRLF 1 -#cmakedefine EBCDIC 1 -#cmakedefine EBCDIC_NL25 1 -#cmakedefine HEAP_MATCH_RECURSE 1 -#cmakedefine NEVER_BACKSLASH_C 1 - -#define PCRE2_EXPORT @PCRE2_EXPORT@ -#define LINK_SIZE @PCRE2_LINK_SIZE@ -#define HEAP_LIMIT @PCRE2_HEAP_LIMIT@ -#define MATCH_LIMIT @PCRE2_MATCH_LIMIT@ -#define MATCH_LIMIT_DEPTH @PCRE2_MATCH_LIMIT_DEPTH@ -#define MAX_VARLOOKBEHIND @PCRE2_MAX_VARLOOKBEHIND@ -#define NEWLINE_DEFAULT @NEWLINE_DEFAULT@ -#define PARENS_NEST_LIMIT @PCRE2_PARENS_NEST_LIMIT@ -#define PCRE2GREP_BUFSIZE @PCRE2GREP_BUFSIZE@ -#define PCRE2GREP_MAX_BUFSIZE @PCRE2GREP_MAX_BUFSIZE@ - -#define MAX_NAME_SIZE 128 -#define MAX_NAME_COUNT 10000 - -/* end config.h for CMake builds */ diff --git a/configure b/configure index 4750b9b..b3cc4d0 100755 --- a/configure +++ b/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.46. +# 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.46' -PACKAGE_STRING='PCRE2 10.46' +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.46 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.46:";; + 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.46 +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.46, 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.46' + 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,184 +14159,519 @@ printf "%s\n" "#define HAVE_VISIBILITY $HAVE_VISIBILITY" >>confdefs.h -# Check for Clang __attribute__((uninitialized)) feature +# Check for the availability of -Wl,--version-script (or -Wl,-M on Solaris) -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __attribute__((uninitialized))" >&5 -printf %s "checking for __attribute__((uninitialized))... " >&6; } -ac_ext=c + + + # 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 -tmp_CFLAGS=$CFLAGS -if test $WORKING_WERROR -eq 1; then - CFLAGS="$CFLAGS -Werror" + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: show; local: *; };" > conftest.map + if test x = xyes +then : + + echo "{" >> conftest.map + fi -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + LDFLAGS="$LDFLAGS -Wl,--version-script,conftest.map" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - +int show, hide; int main (void) { -char buf[128] __attribute__((uninitialized));(void)buf + ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" +if ac_fn_c_try_link "$LINENO" then : - pcre2_cc_cv_attribute_uninitialized=yes -else $as_nop - pcre2_cc_cv_attribute_uninitialized=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $pcre2_cc_cv_attribute_uninitialized" >&5 -printf "%s\n" "$pcre2_cc_cv_attribute_uninitialized" >&6; } -if test "$pcre2_cc_cv_attribute_uninitialized" = yes; then -printf "%s\n" "#define HAVE_ATTRIBUTE_UNINITIALIZED 1" >>confdefs.h + ax_cv_check_vscript_flag=--version-script fi -CFLAGS=$tmp_CFLAGS -ac_ext=c +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 -# Check for the assume() builtin + if test x$ax_cv_check_vscript_flag = xunsupported +then : -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __assume()" >&5 -printf %s "checking for __assume()... " >&6; } -ac_ext=c + # 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 -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ + 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) { -__assume(1) + ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : - pcre2_cc_cv_builtin_assume=yes -else $as_nop - pcre2_cc_cv_builtin_assume=no -fi -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: $pcre2_cc_cv_builtin_assume" >&5 -printf "%s\n" "$pcre2_cc_cv_builtin_assume" >&6; } -if test "$pcre2_cc_cv_builtin_assume" = yes; then -printf "%s\n" "#define HAVE_BUILTIN_ASSUME 1" >>confdefs.h + ax_cv_check_vscript_flag=--version-script fi -ac_ext=c +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 -# Check for the mul_overflow() builtin -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_mul_overflow()" >&5 -printf %s "checking for __builtin_mul_overflow()... " >&6; } -ac_ext=c +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 -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - #ifdef HAVE_SYS_TYPES_H - #include - #endif - #include + ax_check_vscript_save_flags="$LDFLAGS" + echo "V1 { global: show; local: *; };" > conftest.map + if test x = xyes +then : - int a, b; - size_t m; + 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) { -__builtin_mul_overflow(a, b, &m) + ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : - pcre2_cc_cv_builtin_mul_overflow=yes -else $as_nop - pcre2_cc_cv_builtin_mul_overflow=no + ax_cv_check_vscript_flag=-M fi 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: $pcre2_cc_cv_builtin_mul_overflow" >&5 -printf "%s\n" "$pcre2_cc_cv_builtin_mul_overflow" >&6; } -if test "$pcre2_cc_cv_builtin_mul_overflow" = yes; then - -printf "%s\n" "#define HAVE_BUILTIN_MUL_OVERFLOW 1" >>confdefs.h - -fi -ac_ext=c + 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 -# Check for the unreachable() builtin -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_unreachable()" >&5 -printf %s "checking for __builtin_unreachable()... " >&6; } -ac_ext=c +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 -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + 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 r; +int show, hide; int main (void) { -if (r) __builtin_unreachable() + ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : - pcre2_cc_cv_builtin_unreachable=yes -else $as_nop - pcre2_cc_cv_builtin_unreachable=no + ax_cv_check_vscript_flag=unsupported fi 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: $pcre2_cc_cv_builtin_unreachable" >&5 -printf "%s\n" "$pcre2_cc_cv_builtin_unreachable" >&6; } -if test "$pcre2_cc_cv_builtin_unreachable" = yes; then - -printf "%s\n" "#define HAVE_BUILTIN_UNREACHABLE 1" >>confdefs.h - -fi -ac_ext=c + 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 +printf %s "checking for __attribute__((uninitialized))... " >&6; } +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 + +tmp_CFLAGS=$CFLAGS +if test $WORKING_WERROR -eq 1; then + CFLAGS="$CFLAGS -Werror" +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ +char buf[128] __attribute__((uninitialized));(void)buf + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + pcre2_cc_cv_attribute_uninitialized=yes +else $as_nop + pcre2_cc_cv_attribute_uninitialized=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $pcre2_cc_cv_attribute_uninitialized" >&5 +printf "%s\n" "$pcre2_cc_cv_attribute_uninitialized" >&6; } +if test "$pcre2_cc_cv_attribute_uninitialized" = yes; then + +printf "%s\n" "#define HAVE_ATTRIBUTE_UNINITIALIZED 1" >>confdefs.h + +fi +CFLAGS=$tmp_CFLAGS +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 + + +# Check for the assume() builtin + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __assume()" >&5 +printf %s "checking for __assume()... " >&6; } +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 + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ +__assume(1) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + pcre2_cc_cv_builtin_assume=yes +else $as_nop + pcre2_cc_cv_builtin_assume=no +fi +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: $pcre2_cc_cv_builtin_assume" >&5 +printf "%s\n" "$pcre2_cc_cv_builtin_assume" >&6; } +if test "$pcre2_cc_cv_builtin_assume" = yes; then + +printf "%s\n" "#define HAVE_BUILTIN_ASSUME 1" >>confdefs.h + +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 + + +# Check for the mul_overflow() builtin + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_mul_overflow()" >&5 +printf %s "checking for __builtin_mul_overflow()... " >&6; } +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 + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #ifdef HAVE_SYS_TYPES_H + #include + #endif + #include + + int a, b; + size_t m; + +int +main (void) +{ +__builtin_mul_overflow(a, b, &m) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + pcre2_cc_cv_builtin_mul_overflow=yes +else $as_nop + pcre2_cc_cv_builtin_mul_overflow=no +fi +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: $pcre2_cc_cv_builtin_mul_overflow" >&5 +printf "%s\n" "$pcre2_cc_cv_builtin_mul_overflow" >&6; } +if test "$pcre2_cc_cv_builtin_mul_overflow" = yes; then + +printf "%s\n" "#define HAVE_BUILTIN_MUL_OVERFLOW 1" >>confdefs.h + +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 + + +# Check for the unreachable() builtin + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __builtin_unreachable()" >&5 +printf %s "checking for __builtin_unreachable()... " >&6; } +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 + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int r; +int +main (void) +{ +if (r) __builtin_unreachable() + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + pcre2_cc_cv_builtin_unreachable=yes +else $as_nop + pcre2_cc_cv_builtin_unreachable=no +fi +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: $pcre2_cc_cv_builtin_unreachable" >&5 +printf "%s\n" "$pcre2_cc_cv_builtin_unreachable" >&6; } +if test "$pcre2_cc_cv_builtin_unreachable" = yes; then + +printf "%s\n" "#define HAVE_BUILTIN_UNREACHABLE 1" >>confdefs.h + +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' @@ -14162,9 +14681,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu # Versioning PCRE2_MAJOR="10" -PCRE2_MINOR="46" +PCRE2_MINOR="47" PCRE2_PRERELEASE="" -PCRE2_DATE="2025-08-27" +PCRE2_DATE="2025-10-21" if test "$PCRE2_MINOR" = "08" -o "$PCRE2_MINOR" = "09" then @@ -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 @@ -15547,24 +16099,159 @@ printf "%s\n" "#define SUPPORT_PCRE2_32 /**/" >>confdefs.h fi -if test "$enable_debug" = "yes"; then - -printf "%s\n" "#define PCRE2_DEBUG /**/" >>confdefs.h +if test "$enable_debug" = "yes"; then + +printf "%s\n" "#define PCRE2_DEBUG /**/" >>confdefs.h + +fi + +if test "$enable_percent_zt" = "no"; then + +printf "%s\n" "#define DISABLE_PERCENT_ZT /**/" >>confdefs.h + +else + enable_percent_zt=auto +fi + +# Unless running under Windows, JIT support requires pthreads. + +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 -if test "$enable_percent_zt" = "no"; 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" "#define DISABLE_PERCENT_ZT /**/" >>confdefs.h -else - enable_percent_zt=auto -fi -# Unless running under Windows, JIT support requires pthreads. -if test "$enable_jit" = "yes"; then - if test "$HAVE_WINDOWS_H" != "1"; then 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="-mt,-lpthread pthread $ax_pthread_flags" + ;; +esac + +# Are we compiling with Clang? + +{ 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 - ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" +_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" ;; - darwin*) - ax_pthread_flags="-pthread $ax_pthread_flags" + *) + 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 flag in $ax_pthread_flags; do - case $flag in +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 + +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 : -printf "%s\n" "#define PTHREAD_CREATE_JOINABLE $attr_name" >>confdefs.h +printf "%s\n" "#define PTHREAD_CREATE_JOINABLE $ax_cv_PTHREAD_JOINABLE_ATTR" >>confdefs.h - fi + ax_pthread_joinable_attr_defined=yes - { 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 +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: 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 + ;; #( + *) : - # 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 + 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.46, 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.46 +PCRE2 config.status 10.47 configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" @@ -19026,7 +20114,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 @@ -19085,6 +20173,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) @@ -1151,7 +1215,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 @@ -1174,6 +1247,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 < + +# SLJIT + +Platform-independent low-level JIT compiler + +https://zherczeg.github.io/sljit/ + + + +--- + +## Purpose + +SLJIT is a low-level, platform-independent JIT compiler, which is very well suited for translating bytecode into machine code. + +## Features + +- Supports a variety of target architectures: + - `x86` 32 / 64 + - `ARM` 32 / 64 + - `RISC-V` 32 / 64 + - `s390x` 64 + - `PowerPC` 32 / 64 + - `LoongArch` 64 + - `MIPS` 32 / 64 +- Supports a large number of operations + - Self-modifying code + - Tail calls + - Fast calls + - Byte order reverse (endianness switching) + - Unaligned memory accesses + - SIMD + - Atomic operations +- Allows direct access to registers (both integer and floating point) +- Supports stack space allocation for function local variables +- Supports all-in-one compilation + - Allows SLJIT's API to be completely hidden from external use +- Allows serializing the compiler into a byte buffer + - Useful for ahead-of-time (AOT) compilation + - Code generation can be resumed after deserialization (partial AOT compilation) + +## Documentation + +The primary source of documentation is [`sljitLir.h`](./sljit_src/sljitLir.h). + +Additional documentation can be found on [SLJIT's website](https://zherczeg.github.io/sljit/), as well as in the [`docs` folder](./docs/). + +## Contact + +Either open an [issue](https://github.com/zherczeg/sljit/issues) or write an email to hzmester@freemail.hu. + +## License + +SLJIT is licensed under the [Simplified BSD License](./LICENSE). + +## Special Thanks + +- Alexander Nasonov +- Carlo Marcelo Arenas Belón +- Christian Persch +- Daniel Richard G. +- Giuseppe D'Angelo +- H.J. Lu +- James Cowgill +- Jason Hood +- Jiong Wang (*TileGX support*) +- Marc Mutz +- Martin Storsjö +- Michael McConville +- Mingtao Zhou (*LoongArch support*) +- Walter Lee +- Wen Xichang +- YunQiang Su diff --git a/deps/sljit/sljit_src/allocator_src/sljitExecAllocatorCore.c b/deps/sljit/sljit_src/allocator_src/sljitExecAllocatorCore.c index 4e1119b..314483c 100644 --- a/deps/sljit/sljit_src/allocator_src/sljitExecAllocatorCore.c +++ b/deps/sljit/sljit_src/allocator_src/sljitExecAllocatorCore.c @@ -49,9 +49,9 @@ n - The size of the previous block. Using these size values we can go forward or backward on the block chain. - The unused blocks are stored in a chain list pointed by free_blocks. This - list is useful if we need to find a suitable memory area when the allocator - is called. + The unused blocks are stored in a chain list pointed by sljit_free_blocks. + This list is useful if we need to find a suitable memory area when the + allocator is called. When a block is freed, the new free block is connected to its adjacent free blocks if possible. @@ -115,20 +115,20 @@ struct free_block { #define ALIGN_SIZE(size) (((size) + sizeof(struct block_header) + 7u) & ~(sljit_uw)7) #define CHUNK_EXTRA_SIZE (sizeof(struct block_header) + CHUNK_HEADER_SIZE) -static struct free_block* free_blocks; -static sljit_uw allocated_size; -static sljit_uw total_size; +static struct free_block* sljit_free_blocks; +static sljit_uw sljit_allocated_size; +static sljit_uw sljit_total_size; static SLJIT_INLINE void sljit_insert_free_block(struct free_block *free_block, sljit_uw size) { free_block->header.size = 0; free_block->size = size; - free_block->next = free_blocks; + free_block->next = sljit_free_blocks; free_block->prev = NULL; - if (free_blocks) - free_blocks->prev = free_block; - free_blocks = free_block; + if (sljit_free_blocks) + sljit_free_blocks->prev = free_block; + sljit_free_blocks = free_block; } static SLJIT_INLINE void sljit_remove_free_block(struct free_block *free_block) @@ -139,8 +139,8 @@ static SLJIT_INLINE void sljit_remove_free_block(struct free_block *free_block) if (free_block->prev) free_block->prev->next = free_block->next; else { - SLJIT_ASSERT(free_blocks == free_block); - free_blocks = free_block->next; + SLJIT_ASSERT(sljit_free_blocks == free_block); + sljit_free_blocks = free_block->next; } } @@ -166,7 +166,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size) size = ALIGN_SIZE(size); SLJIT_ALLOCATOR_LOCK(); - free_block = free_blocks; + free_block = sljit_free_blocks; while (free_block) { if (free_block->size >= size) { chunk_size = free_block->size; @@ -186,7 +186,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size) header = (struct block_header*)free_block; size = chunk_size; } - allocated_size += size; + sljit_allocated_size += size; header->size = size; SLJIT_ALLOCATOR_UNLOCK(); return MEM_START(header); @@ -207,7 +207,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size) #endif /* SLJIT_HAS_EXECUTABLE_OFFSET */ chunk_size -= CHUNK_EXTRA_SIZE; - total_size += chunk_size; + sljit_total_size += chunk_size; header = (struct block_header*)(((sljit_u8*)chunk_header) + CHUNK_HEADER_SIZE); @@ -218,7 +218,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size) if (chunk_size > size + 64) { /* Cut the allocated space into a free and a used block. */ - allocated_size += size; + sljit_allocated_size += size; header->size = size; chunk_size -= size; @@ -231,7 +231,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size) next_header = AS_BLOCK_HEADER(free_block, chunk_size); } else { /* All space belongs to this allocation. */ - allocated_size += chunk_size; + sljit_allocated_size += chunk_size; header->size = chunk_size; next_header = AS_BLOCK_HEADER(header, chunk_size); } @@ -254,7 +254,7 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void *ptr) #ifdef SLJIT_HAS_EXECUTABLE_OFFSET header = AS_BLOCK_HEADER(header, -header->executable_offset); #endif /* SLJIT_HAS_EXECUTABLE_OFFSET */ - allocated_size -= header->size; + sljit_allocated_size -= header->size; SLJIT_UPDATE_WX_FLAGS(NULL, NULL, 0); @@ -282,9 +282,9 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void *ptr) /* The whole chunk is free. */ if (SLJIT_UNLIKELY(!free_block->header.prev_size && header->size == 1)) { - /* If this block is freed, we still have (allocated_size / 2) free space. */ - if (total_size - free_block->size > (allocated_size * 3 / 2)) { - total_size -= free_block->size; + /* If this block is freed, we still have (sljit_allocated_size / 2) free space. */ + if (sljit_total_size - free_block->size > (sljit_allocated_size * 3 / 2)) { + sljit_total_size -= free_block->size; sljit_remove_free_block(free_block); free_chunk(free_block, free_block->size + CHUNK_EXTRA_SIZE); } @@ -302,19 +302,19 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void) SLJIT_ALLOCATOR_LOCK(); SLJIT_UPDATE_WX_FLAGS(NULL, NULL, 0); - free_block = free_blocks; + free_block = sljit_free_blocks; while (free_block) { next_free_block = free_block->next; if (!free_block->header.prev_size && AS_BLOCK_HEADER(free_block, free_block->size)->size == 1) { - total_size -= free_block->size; + sljit_total_size -= free_block->size; sljit_remove_free_block(free_block); free_chunk(free_block, free_block->size + CHUNK_EXTRA_SIZE); } free_block = next_free_block; } - SLJIT_ASSERT(total_size || (!total_size && !free_blocks)); + SLJIT_ASSERT(sljit_total_size || (!sljit_total_size && !sljit_free_blocks)); SLJIT_UPDATE_WX_FLAGS(NULL, NULL, 1); SLJIT_ALLOCATOR_UNLOCK(); } diff --git a/deps/sljit/sljit_src/sljitConfigInternal.h b/deps/sljit/sljit_src/sljitConfigInternal.h index 3ae944e..c052434 100644 --- a/deps/sljit/sljit_src/sljitConfigInternal.h +++ b/deps/sljit/sljit_src/sljitConfigInternal.h @@ -71,6 +71,7 @@ SLJIT_SEPARATE_VECTOR_REGISTERS : if this macro is defined, the vector registers do not overlap with floating point registers SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_sw/sljit_uw array by index + SLJIT_POINTER_SHIFT : the shift required to apply when accessing a sljit_sp/sljit_up array by index SLJIT_F32_SHIFT : the shift required to apply when accessing a single precision floating point array by index SLJIT_F64_SHIFT : the shift required to apply when accessing @@ -96,15 +97,21 @@ SLJIT_TMP_FR(i) : accessing temporary floating point registers SLJIT_TMP_VR0 .. VR9 : accessing temporary vector registers SLJIT_TMP_VR(i) : accessing temporary vector registers - SLJIT_TMP_DEST_REG : a temporary register for results - SLJIT_TMP_MEM_REG : a temporary base register for accessing memory - (can be the same as SLJIT_TMP_DEST_REG) - SLJIT_TMP_DEST_FREG : a temporary register for float results - SLJIT_TMP_DEST_VREG : a temporary register for vector results + SLJIT_TMP_DEST_REG : a temporary register for results, see the rules below + SLJIT_TMP_DEST_FREG : a temporary register for float results, see the rules below + SLJIT_TMP_DEST_VREG : a temporary register for vector results, see the rules below + SLJIT_TMP_OPT_REG : a temporary register which might not be defined, see the rules below SLJIT_FUNC : calling convention attribute for both calling JIT from C and C calling back from JIT SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (platform independent helper) SLJIT_F64_SECOND(reg) : provides the register index of the second 32 bit part of a 64 bit floating point register when SLJIT_HAS_F64_AS_F32_PAIR returns non-zero + + Temporary register rules (e.g. SLJIT_TMP_DEST_REG / SLJIT_TMP_OPT_REG): + Sljit tries to emit instructions without using any temporary registers whenever it is possible. + When a single temporary register is needed, it is always the "OPT" register. When two temporary + registers are needed, both the "DEST" and "OPT" are used. The x86-32 does not define an "OPT" + register, and handles all cases without an "OPT" register which requires an "OPT" register + on other architectures. */ #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ @@ -602,7 +609,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 1 #define SLJIT_TMP_DEST_REG SLJIT_TMP_R0 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R0 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_LOCALS_OFFSET_BASE (8 * (sljit_s32)sizeof(sljit_sw)) #define SLJIT_PREF_SHIFT_REG SLJIT_R2 @@ -627,7 +633,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_LOCALS_OFFSET_BASE (4 * (sljit_s32)sizeof(sljit_sw)) #endif /* !_WIN64 */ #define SLJIT_TMP_DEST_REG SLJIT_TMP_R0 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R0 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R1 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_PREF_SHIFT_REG SLJIT_R3 #define SLJIT_MASKED_SHIFT 1 @@ -644,7 +650,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 8 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 #define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R1 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_LOCALS_OFFSET_BASE 0 @@ -657,7 +663,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 8 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 #define SLJIT_TMP_DEST_REG SLJIT_TMP_R0 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R0 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R1 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_LOCALS_OFFSET_BASE (2 * (sljit_s32)sizeof(sljit_sw)) #define SLJIT_MASKED_SHIFT 1 @@ -674,7 +680,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 18 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 #define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R1 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX) #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * (sljit_s32)sizeof(sljit_sw)) @@ -702,7 +708,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 5 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 3 #define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R1 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_MASKED_SHIFT 1 #define SLJIT_MASKED_SHIFT32 1 @@ -721,7 +727,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS 0 #define SLJIT_NUMBER_OF_TEMPORARY_VECTOR_REGISTERS 2 #define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R1 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_TMP_DEST_VREG SLJIT_TMP_VR0 #define SLJIT_LOCALS_OFFSET_BASE 0 @@ -759,8 +765,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_FLOAT_REGISTERS 15 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 8 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 1 -#define SLJIT_TMP_DEST_REG SLJIT_TMP_R0 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R2 +#define SLJIT_TMP_DEST_REG SLJIT_TMP_R2 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R1 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_LOCALS_OFFSET_BASE SLJIT_S390X_DEFAULT_STACK_FRAME_SIZE #define SLJIT_MASKED_SHIFT 1 @@ -776,7 +782,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 12 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 #define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 -#define SLJIT_TMP_MEM_REG SLJIT_TMP_R1 +#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 #define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 #define SLJIT_LOCALS_OFFSET_BASE 0 #define SLJIT_MASKED_SHIFT 1 @@ -793,7 +799,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0 #define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 0 #define SLJIT_TMP_DEST_REG 0 -#define SLJIT_TMP_MEM_REG 0 #define SLJIT_TMP_DEST_FREG 0 #define SLJIT_LOCALS_OFFSET_BASE 0 @@ -965,6 +970,37 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); #endif /* !SLJIT_COMPILE_ASSERT */ +#ifndef SLJIT_FALLTHROUGH + +#if defined(__cplusplus) && __cplusplus >= 202002L && \ + defined(__has_cpp_attribute) +/* Standards-compatible C++ variant. */ +#if __has_cpp_attribute(fallthrough) +#define SLJIT_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 SLJIT_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 SLJIT_FALLTHROUGH __attribute__((fallthrough)); +#endif +#endif + +#ifndef SLJIT_FALLTHROUGH +#define SLJIT_FALLTHROUGH +#endif + +#endif /* !SLJIT_FALLTHROUGH */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/deps/sljit/sljit_src/sljitLir.c b/deps/sljit/sljit_src/sljitLir.c index 6b2d556..633e794 100644 --- a/deps/sljit/sljit_src/sljitLir.c +++ b/deps/sljit/sljit_src/sljitLir.c @@ -95,17 +95,12 @@ #define VARIABLE_FLAG_SHIFT (10) /* All variable flags are even. */ #define VARIABLE_FLAG_MASK (0x3e << VARIABLE_FLAG_SHIFT) +#define ALL_STATUS_FLAGS_MASK (VARIABLE_FLAG_MASK | SLJIT_SET_Z) #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT) #define GET_FLAG_TYPE_MASK(op) (((op) >> VARIABLE_FLAG_SHIFT) & 0x3e) - -#define GET_OPCODE(op) \ - ((op) & 0xff) - -#define HAS_FLAGS(op) \ - ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)) - -#define GET_ALL_FLAGS(op) \ - ((op) & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK)) +#define GET_OPCODE(op) ((op) & 0xff) +#define HAS_FLAGS(op) ((op) & ALL_STATUS_FLAGS_MASK) +#define GET_ALL_FLAGS(op) ((op) & (SLJIT_32 | ALL_STATUS_FLAGS_MASK)) #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) #define TYPE_CAST_NEEDED(op) \ @@ -155,10 +150,22 @@ #define SLJIT_SIMD_TYPE_MASK(m) ((sljit_s32)0xff000fff & ~(SLJIT_SIMD_FLOAT | SLJIT_SIMD_TEST | (m))) #define SLJIT_SIMD_TYPE_MASK2(m) ((sljit_s32)0xc0000fff & ~(SLJIT_SIMD_FLOAT | SLJIT_SIMD_TEST | (m))) -/* Jump flags. */ +/* Label definitions. */ + +#define SLJIT_LABEL_ALIGNED ((~(sljit_uw)0) - 1) + +struct sljit_extended_label { + struct sljit_label label; + sljit_uw index; + sljit_uw data; +}; + +/* Jump definitions. */ + +/* Jump flag bits. */ #define JUMP_ADDR 0x1 #define JUMP_MOV_ADDR 0x2 -/* SLJIT_REWRITABLE_JUMP is 0x1000. */ +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) # define PATCH_MB 0x04 @@ -172,14 +179,15 @@ # define JUMP_MAX_SIZE ((sljit_uw)5) # define CJUMP_MAX_SIZE ((sljit_uw)6) #endif /* SLJIT_CONFIG_X86_64 */ -# define TYPE_SHIFT 13 +# define TYPE_SHIFT 17 #if (defined SLJIT_DEBUG && SLJIT_DEBUG) -/* Bits 7..12 is for debug jump size, SLJIT_REWRITABLE_JUMP is 0x1000 */ -# define JUMP_SIZE_SHIFT 7 +/* Bits 7..15 is for debug jump size, SLJIT_REWRITABLE_JUMP is 0x10000 */ +# define JUMP_SIZE_SHIFT 8 #endif /* SLJIT_DEBUG */ #endif /* SLJIT_CONFIG_X86 */ #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ # define IS_BL 0x04 # define PATCH_B 0x08 #endif /* SLJIT_CONFIG_ARM_V6 || SLJIT_CONFIG_ARM_V7 */ @@ -194,8 +202,11 @@ #endif /* SLJIT_CONFIG_ARM_V7 */ #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ # define IS_COND 0x04 # define IS_BL 0x08 + /* mov_addr does not use IS_BL */ +# define IS_ABS IS_BL /* conditional + imm8 */ # define PATCH_TYPE1 0x10 /* conditional + imm20 */ @@ -214,6 +225,7 @@ #endif /* SLJIT_CONFIG_ARM_THUMB2 */ #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ # define IS_COND 0x004 # define IS_CBZ 0x008 # define IS_BL 0x010 @@ -227,6 +239,7 @@ #endif /* SLJIT_CONFIG_ARM_64 */ #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ # define IS_COND 0x004 # define IS_CALL 0x008 # define PATCH_B 0x010 @@ -243,6 +256,7 @@ #endif /* SLJIT_CONFIG_PPC */ #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ # define IS_MOVABLE 0x004 # define IS_JAL 0x008 # define IS_CALL 0x010 @@ -270,26 +284,36 @@ #endif /* SLJIT_CONFIG_MIPS */ #if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) -# define IS_COND 0x004 -# define IS_CALL 0x008 +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ +# define IS_COND 0x0004 +# define IS_CALL 0x0008 -# define PATCH_B 0x010 -# define PATCH_J 0x020 +# define IS_COND16 0x0010 +# define PATCH_B 0x0020 +# define PATCH_J 0x0040 +# define PATCH_16 0x0080 #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) -# define PATCH_REL32 0x040 -# define PATCH_ABS32 0x080 -# define PATCH_ABS44 0x100 -# define PATCH_ABS52 0x200 +# define PATCH_REL32 0x0100 +# define PATCH_ABS32 0x0200 +# define PATCH_ABS44 0x0400 +# define PATCH_ABS52 0x0800 # define JUMP_SIZE_SHIFT 58 -# define JUMP_MAX_SIZE ((sljit_uw)6) +# define JUMP_MAX_SIZE ((sljit_uw)12) #else /* !SLJIT_CONFIG_RISCV_64 */ # define JUMP_SIZE_SHIFT 26 -# define JUMP_MAX_SIZE ((sljit_uw)2) +# define JUMP_MAX_SIZE ((sljit_uw)4) #endif /* SLJIT_CONFIG_RISCV_64 */ #endif /* SLJIT_CONFIG_RISCV */ +#if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ +# define PATCH_POOL 0x004 +# define PATCH_IMM32 0x008 +#endif /* SLJIT_CONFIG_S390X */ + #if (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) +/* SLJIT_REWRITABLE_JUMP is 0x10000. */ # define IS_COND 0x004 # define IS_CALL 0x008 @@ -303,6 +327,7 @@ # define JUMP_MAX_SIZE ((sljit_uw)4) #endif /* SLJIT_CONFIG_LOONGARCH */ + /* Stack management. */ #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \ @@ -451,12 +476,12 @@ /* Public functions */ /* --------------------------------------------------------------------- */ -#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) +#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) || (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) #define SLJIT_NEEDS_COMPILER_INIT 1 static sljit_s32 compiler_initialized = 0; /* A thread safe initialization. */ static void init_compiler(void); -#endif /* SLJIT_CONFIG_X86 */ +#endif /* SLJIT_CONFIG_X86 || SLJIT_CONFIG_RISCV */ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data) { @@ -475,8 +500,12 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allo && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8) && (sizeof(sljit_uw) == sizeof(sljit_sw)), invalid_integer_types); - SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_32, - rewritable_jump_and_single_op_must_not_be_the_same); + SLJIT_COMPILE_ASSERT((SLJIT_REWRITABLE_JUMP & SLJIT_32) == 0 + && (ALL_STATUS_FLAGS_MASK & SLJIT_32) == 0 + && (SLJIT_REWRITABLE_JUMP & ALL_STATUS_FLAGS_MASK) == 0, + rewritable_jump_and_status_flag_bits_and_sljit_32_must_not_have_common_bits); + SLJIT_COMPILE_ASSERT((VARIABLE_FLAG_MASK & SLJIT_SET_Z) == 0, + rewritable_jump_and_status_flag_bits_must_not_have_common_bits); SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_F_EQUAL & 0x1) && !(SLJIT_JUMP & 0x1), conditional_flags_must_be_even_numbers); @@ -615,8 +644,8 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw } } -#define SLJIT_CURRENT_FLAGS_ALL \ - (SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE) +#define SLJIT_CURRENT_FLAGS_ALL (SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD \ + | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE | SLJIT_CURRENT_FLAGS_OP2CMPZ) SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags) { @@ -624,12 +653,18 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *com SLJIT_UNUSED_ARG(current_flags); #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE) +#if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) + if (current_flags & SLJIT_CURRENT_FLAGS_OP2CMPZ) { + current_flags |= SLJIT_SET_Z; + } +#endif /* SLJIT_CONFIG_S390X */ + compiler->status_flags_state = current_flags; #endif /* SLJIT_HAS_STATUS_FLAGS_STATE */ #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) compiler->last_flags = 0; - if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ALL)) == 0) { + if ((current_flags & ~(ALL_STATUS_FLAGS_MASK | SLJIT_CURRENT_FLAGS_ALL)) == 0) { compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_32 | SLJIT_SET_Z)); } #endif /* SLJIT_ARGUMENT_CHECKS */ @@ -826,22 +861,34 @@ static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compi label->next = NULL; label->u.index = compiler->label_count++; label->size = compiler->size; + if (compiler->last_label != NULL) compiler->last_label->next = label; else compiler->labels = label; + compiler->last_label = label; } +static SLJIT_INLINE void set_extended_label(struct sljit_extended_label *ext_label, struct sljit_compiler *compiler, sljit_uw type, sljit_uw data) +{ + set_label(&ext_label->label, compiler); + ext_label->index = ext_label->label.u.index; + ext_label->label.u.index = type; + ext_label->data = data; +} + static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_u32 flags) { jump->next = NULL; jump->flags = flags; jump->u.label = NULL; + if (compiler->last_jump != NULL) compiler->last_jump->next = jump; else compiler->jumps = jump; + compiler->last_jump = jump; } @@ -1318,6 +1365,10 @@ static const char* call_arg_names[] = { "void", "w", "32", "p", "f64", "f32" }; +static const char* op_addr_types[] = { + "mov_addr", "mov_abs_addr", "add_abs_addr" +}; + #endif /* SLJIT_VERBOSE */ /* --------------------------------------------------------------------- */ @@ -1328,18 +1379,21 @@ static const char* call_arg_names[] = { || (defined SLJIT_VERBOSE && SLJIT_VERBOSE) #define SLJIT_SKIP_CHECKS(compiler) (compiler)->skip_checks = 1 -#define SLJIT_CHECK_OPCODE(op, flags) ((op) & ~(SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK | (flags))) +#define SLJIT_CHECK_OPCODE(op, flags) ((op) & ~(SLJIT_32 | ALL_STATUS_FLAGS_MASK | (flags))) -static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler) +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler, sljit_s32 options) { #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) struct sljit_jump *jump; #endif /* SLJIT_ARGUMENT_CHECKS */ SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(options); #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(compiler->size > 0); + CHECK_ARGUMENT((options & ~(SLJIT_GENERATE_CODE_BUFFER | SLJIT_GENERATE_CODE_NO_CONTEXT)) == 0); + jump = compiler->jumps; while (jump) { /* All jumps have target. */ @@ -1643,11 +1697,11 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler case SLJIT_REV_U32: case SLJIT_REV_S32: /* Nothing allowed */ - CHECK_ARGUMENT(!(op & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))); + CHECK_ARGUMENT(!(op & (SLJIT_32 | ALL_STATUS_FLAGS_MASK))); break; default: /* Only SLJIT_32 is allowed. */ - CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))); + CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); break; } @@ -1679,8 +1733,8 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_load(struct sljit_ #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_ATOMIC)); - CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | SLJIT_SET_Z | VARIABLE_FLAG_MASK) >= SLJIT_MOV - && SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | SLJIT_SET_Z | VARIABLE_FLAG_MASK) <= SLJIT_MOV_P); + CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | ALL_STATUS_FLAGS_MASK) >= SLJIT_MOV + && SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | ALL_STATUS_FLAGS_MASK) <= SLJIT_MOV_P); CHECK_ARGUMENT((op & (SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS)) != (SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS)); /* All arguments must be valid registers. */ @@ -1778,19 +1832,10 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_store(struct sljit CHECK_RETURN_OK; } -static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset, - sljit_s32 dst, sljit_sw dstw, - sljit_s32 src1, sljit_sw src1w, - sljit_s32 src2, sljit_sw src2w) -{ - if (SLJIT_UNLIKELY(compiler->skip_checks)) { - compiler->skip_checks = 0; - CHECK_RETURN_OK; - } - #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) - CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_ADD && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_ROTR); +static sljit_s32 check_sljit_emit_op2_operation(struct sljit_compiler *compiler, sljit_s32 op) +{ switch (GET_OPCODE(op)) { case SLJIT_AND: case SLJIT_OR: @@ -1801,39 +1846,49 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler case SLJIT_MLSHR: case SLJIT_ASHR: case SLJIT_MASHR: - CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)); - break; + return !(op & VARIABLE_FLAG_MASK); case SLJIT_MUL: - CHECK_ARGUMENT(!(op & SLJIT_SET_Z)); - CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK) - || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW); - break; + return !(op & SLJIT_SET_Z) && (!(op & VARIABLE_FLAG_MASK) || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW); case SLJIT_ADD: - CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK) + return !(op & VARIABLE_FLAG_MASK) || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY) - || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW); - break; + || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW; case SLJIT_SUB: - CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK) + return !(op & VARIABLE_FLAG_MASK) || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW) - || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)); - break; + || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY); case SLJIT_ADDC: case SLJIT_SUBC: - CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK) - || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)); - CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY)); - CHECK_ARGUMENT((op & SLJIT_32) == (compiler->last_flags & SLJIT_32)); + return (!(op & VARIABLE_FLAG_MASK) || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)) + && (compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY) + && (op & SLJIT_32) == (compiler->last_flags & SLJIT_32); break; case SLJIT_ROTL: case SLJIT_ROTR: - CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))); - break; - default: - SLJIT_UNREACHABLE(); - break; + return !(op & ALL_STATUS_FLAGS_MASK); } + /* Operation type should be checked earlier. */ + SLJIT_UNREACHABLE(); + return 1; +} + +#endif /* SLJIT_ARGUMENT_CHECKS */ + +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w) +{ + if (SLJIT_UNLIKELY(compiler->skip_checks)) { + compiler->skip_checks = 0; + CHECK_RETURN_OK; + } + +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_ADD && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_ROTR); + CHECK_ARGUMENT(check_sljit_emit_op2_operation(compiler, op)); + if (unset) { CHECK_ARGUMENT(HAS_FLAGS(op)); } else { @@ -1923,6 +1978,36 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_shift_into(struct sljit_c CHECK_RETURN_OK; } +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + SLJIT_UNUSED_ARG(shift_arg); +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT((op & ~SLJIT_SRC2_UNDEFINED) == (SLJIT_ADD | SLJIT_SHL_IMM)); + FUNCTION_CHECK_DST(dst, dstw); + FUNCTION_CHECK_SRC(src1, src1w); + FUNCTION_CHECK_SRC(src2, src2w); + compiler->last_flags = 0; +#endif /* SLJIT_ARGUMENT_CHECKS */ +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) + if (SLJIT_UNLIKELY(!!compiler->verbose)) { + fprintf(compiler->verbose, " %s.shl_imm%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], + (op & SLJIT_SRC2_UNDEFINED) ? ".src2und" : ""); + + sljit_verbose_param(compiler, dst, dstw); + fprintf(compiler->verbose, ", "); + sljit_verbose_param(compiler, src1, src1w); + fprintf(compiler->verbose, ", "); + sljit_verbose_param(compiler, src2, src2w); + fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", shift_arg); + } +#endif /* SLJIT_VERBOSE */ + CHECK_RETURN_OK; +} + static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -2005,12 +2090,12 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_co #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) CHECK_ARGUMENT(size > 0 && size < 16); -#elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) +#elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0) || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0)); #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) CHECK_ARGUMENT(size == 2 || size == 4 || size == 6); -#else /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM_THUMB2 && !SLJIT_CONFIG_S390X */ +#else /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM_THUMB2 && !SLJIT_CONFIG_RISCV && !SLJIT_CONFIG_S390X */ CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0); #endif /* SLJIT_CONFIG_X86 */ @@ -2039,7 +2124,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compile #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_MOV_F64 && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_ABS_F64); - CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))); + CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); FUNCTION_FCHECK(src, srcw, op & SLJIT_32); FUNCTION_FCHECK(dst, dstw, op & SLJIT_32); #endif /* SLJIT_ARGUMENT_CHECKS */ @@ -2110,7 +2195,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(str #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); - CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))); + CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); FUNCTION_FCHECK(src, srcw, op & SLJIT_32); FUNCTION_CHECK_DST(dst, dstw); #endif /* SLJIT_ARGUMENT_CHECKS */ @@ -2139,7 +2224,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_w(stru #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); - CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))); + CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); FUNCTION_CHECK_SRC(src, srcw); FUNCTION_FCHECK(dst, dstw, op & SLJIT_32); #endif /* SLJIT_ARGUMENT_CHECKS */ @@ -2170,7 +2255,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compile #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_ADD_F64 && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_DIV_F64); - CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))); + CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); FUNCTION_FCHECK(src1, src1w, op & SLJIT_32); FUNCTION_FCHECK(src2, src2w, op & SLJIT_32); FUNCTION_FCHECK(dst, dstw, op & SLJIT_32); @@ -2269,7 +2354,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcopy(struct sljit_compil #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_COPY_TO_F64 && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_COPY_FROM_F64); - CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))); + CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg, op & SLJIT_32)); #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) @@ -2341,6 +2426,37 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compil CHECK_RETURN_OK; } +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + SLJIT_UNUSED_ARG(compiler); + SLJIT_UNUSED_ARG(buffers); + +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT(alignment >= SLJIT_LABEL_ALIGN_1 && alignment <= SLJIT_LABEL_ALIGN_16); + compiler->last_flags = 0; +#endif /* SLJIT_ARGUMENT_CHECKS */ + +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) + if (SLJIT_UNLIKELY(!!compiler->verbose)) { + fprintf(compiler->verbose, "label.al%d:%s", 1 << alignment, buffers == NULL ? "\n" : " ["); + + if (buffers != NULL) { + fprintf(compiler->verbose, "%ld", (long int)buffers->size); + buffers = buffers->next; + + while (buffers != NULL) { + fprintf(compiler->verbose, ", %ld", (long int)buffers->size); + buffers = buffers->next; + } + + fprintf(compiler->verbose, "]\n"); + } + } +#endif /* SLJIT_VERBOSE */ + CHECK_RETURN_OK; +} + #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ || (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) @@ -2427,6 +2543,11 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w) { + if (SLJIT_UNLIKELY(compiler->skip_checks)) { + compiler->skip_checks = 0; + CHECK_RETURN_OK; + } + #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32))); CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL); @@ -2472,6 +2593,40 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compile CHECK_RETURN_OK; } +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w) +{ + SLJIT_COMPILE_ASSERT((SLJIT_JUMP_IF_ZERO == SLJIT_SET_Z) && (SLJIT_JUMP_IF_NON_ZERO == 0), + incorrect_values_for_sljit_jump_zero_or_non_zero); + +#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, SLJIT_REWRITABLE_JUMP) >= SLJIT_ADD && SLJIT_CHECK_OPCODE(op, SLJIT_REWRITABLE_JUMP) <= SLJIT_ROTR); + /* Not all opcodes allow setting zero flags. */ + CHECK_ARGUMENT(check_sljit_emit_op2_operation(compiler, ((op | SLJIT_SET_Z) & ~SLJIT_REWRITABLE_JUMP))); + FUNCTION_CHECK_DST(dst, dstw); + FUNCTION_CHECK_SRC(src1, src1w); + FUNCTION_CHECK_SRC(src2, src2w); + compiler->last_flags = GET_FLAG_TYPE(op) | (op & SLJIT_32); +#endif /* SLJIT_ARGUMENT_CHECKS */ +#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) + if (SLJIT_UNLIKELY(!!compiler->verbose)) { + fprintf(compiler->verbose, " cmp%sz.%s%s%s%s%s ", (op & SLJIT_JUMP_IF_ZERO) ? "" : "n", + op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32", + !(op & VARIABLE_FLAG_MASK) ? "" : ".", !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op & ~SLJIT_REWRITABLE_JUMP)], + !(op & SLJIT_REWRITABLE_JUMP) ? "" : ".r"); + sljit_verbose_param(compiler, dst, dstw); + fprintf(compiler->verbose, ", "); + sljit_verbose_param(compiler, src1, src1w); + fprintf(compiler->verbose, ", "); + sljit_verbose_param(compiler, src2, src2w); + fprintf(compiler->verbose, "\n"); + } +#endif /* SLJIT_VERBOSE */ + CHECK_RETURN_OK; +} + static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { @@ -2578,27 +2733,30 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_select(struct sljit_compi sljit_s32 src2_reg) { #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) - sljit_s32 cond = type & ~SLJIT_32; - - CHECK_ARGUMENT(cond >= SLJIT_EQUAL && cond <= SLJIT_ORDERED_LESS_EQUAL); - + sljit_s32 cond = type & ~(SLJIT_32 | SLJIT_COMPARE_SELECT); + CHECK_ARGUMENT((type & SLJIT_COMPARE_SELECT) ? (cond >= SLJIT_LESS && cond <= SLJIT_SET_SIG_LESS_EQUAL) + : (cond >= SLJIT_EQUAL && cond <= SLJIT_ORDERED_LESS_EQUAL)); CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg)); FUNCTION_CHECK_SRC(src1, src1w); CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src2_reg)); - if (cond <= SLJIT_NOT_ZERO) - CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z); - else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) { - CHECK_ARGUMENT((type & 0xfe) == SLJIT_CARRY); - compiler->last_flags = 0; + if (!(type & SLJIT_COMPARE_SELECT)) { + if (cond <= SLJIT_NOT_ZERO) + CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z); + else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) { + CHECK_ARGUMENT((type & 0xfe) == SLJIT_CARRY); + compiler->last_flags = 0; + } else + CHECK_ARGUMENT((cond & 0xfe) == (compiler->last_flags & 0xff) + || CHECK_UNORDERED(cond, compiler->last_flags)); } else - CHECK_ARGUMENT((cond & 0xfe) == (compiler->last_flags & 0xff) - || CHECK_UNORDERED(cond, compiler->last_flags)); + compiler->last_flags = 0; #endif /* SLJIT_ARGUMENT_CHECKS */ #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) if (SLJIT_UNLIKELY(!!compiler->verbose)) { - fprintf(compiler->verbose, " select%s %s, ", + fprintf(compiler->verbose, " %sselect%s %s, ", + !(type & SLJIT_COMPARE_SELECT) ? "" : "cmp_", !(type & SLJIT_32) ? "" : "32", jump_names[type & ~SLJIT_32]); sljit_verbose_reg(compiler, dst_reg); @@ -2680,7 +2838,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler case SLJIT_MOV_P: case SLJIT_MOV: allowed_flags |= SLJIT_MEM_ALIGNED_32; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_MOV_U32: case SLJIT_MOV_S32: case SLJIT_MOV32: @@ -2714,11 +2872,11 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler !(type & SLJIT_32) ? "" : "32", op1_types[(type & 0xff) - SLJIT_OP1_BASE]); if (type & SLJIT_MEM_UNALIGNED) - printf(".unal"); + fprintf(compiler->verbose, ".unal"); else if (type & SLJIT_MEM_ALIGNED_16) - printf(".al16"); + fprintf(compiler->verbose, ".al16"); else if (type & SLJIT_MEM_ALIGNED_32) - printf(".al32"); + fprintf(compiler->verbose, ".al32"); if (reg & REG_PAIR_MASK) { fprintf(compiler->verbose, " {"); @@ -3176,16 +3334,21 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_co CHECK_RETURN_OK; } -static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { SLJIT_UNUSED_ARG(init_value); #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV_S32 + || op == SLJIT_MOV32 || (op | SLJIT_32) == SLJIT_MOV32_U8); FUNCTION_CHECK_DST(dst, dstw); #endif /* SLJIT_ARGUMENT_CHECKS */ #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) if (SLJIT_UNLIKELY(!!compiler->verbose)) { - fprintf(compiler->verbose, " const "); + fprintf(compiler->verbose, " const%s%s ", + !(op & SLJIT_32) ? "" : "32", op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE]); sljit_verbose_param(compiler, dst, dstw); fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value); } @@ -3193,14 +3356,16 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compil CHECK_RETURN_OK; } -static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT(op == SLJIT_MOV_ADDR || op == SLJIT_MOV_ABS_ADDR || op == SLJIT_ADD_ABS_ADDR); FUNCTION_CHECK_DST(dst, dstw); #endif /* SLJIT_ARGUMENT_CHECKS */ #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) if (SLJIT_UNLIKELY(!!compiler->verbose)) { - fprintf(compiler->verbose, " mov_addr "); + fprintf(compiler->verbose, " %s ", op_addr_types[op]); sljit_verbose_param(compiler, dst, dstw); fprintf(compiler->verbose, "\n"); } @@ -3276,6 +3441,14 @@ static sljit_s32 sljit_emit_fmem_unaligned(struct sljit_compiler *compiler, slji #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM */ +static void sljit_reset_read_only_buffers(struct sljit_read_only_buffer *buffers) +{ + while (buffers != NULL) { + buffers->u.label = NULL; + buffers = buffers->next; + } +} + /* CPU description section */ #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE) @@ -3501,6 +3674,49 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compile return sljit_emit_jump(compiler, type); } +#if !(defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \ + && !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \ + && !(defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w) +{ + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_op2cmpz(compiler, op, dst, dstw, src1, src1w, src2, src2w)); + + SLJIT_SKIP_CHECKS(compiler); + PTR_FAIL_IF(sljit_emit_op2(compiler, ((op | SLJIT_SET_Z) & ~SLJIT_REWRITABLE_JUMP), dst, dstw, src1, src1w, src2, src2w)); + + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_jump(compiler, ((op & SLJIT_JUMP_IF_ZERO) ? SLJIT_ZERO : SLJIT_NOT_ZERO) | (op & SLJIT_REWRITABLE_JUMP)); +} + +#else /* SLJIT_CONFIG_RISCV || SLJIT_CONFIG_MIPS || SLJIT_CONFIG_LOONGARCH */ + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w) +{ + sljit_s32 reg; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_op2cmpz(compiler, op, dst, dstw, src1, src1w, src2, src2w)); + + SLJIT_SKIP_CHECKS(compiler); + PTR_FAIL_IF(sljit_emit_op2(compiler, (op & ~(SLJIT_SET_Z | SLJIT_REWRITABLE_JUMP)), dst, dstw, src1, src1w, src2, src2w)); + + /* When dst is a memory operand, its value is stored in SLJIT_TMP_DEST_FREG. */ + reg = FAST_IS_REG(dst) ? dst : SLJIT_TMP_DEST_REG; + + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_cmp(compiler, ((op & SLJIT_JUMP_IF_ZERO) ? SLJIT_ZERO : SLJIT_NOT_ZERO) | (op & (SLJIT_32 | SLJIT_REWRITABLE_JUMP)), reg, 0, SLJIT_IMM, 0); +} + +#endif /* !SLJIT_CONFIG_RISCV && !SLJIT_CONFIG_MIPS && !SLJIT_CONFIG_LOONGARCH */ + #if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \ && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) @@ -3687,4 +3903,23 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM_64 */ +SLJIT_API_FUNC_ATTRIBUTE void* sljit_read_only_buffer_start_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset) +{ + SLJIT_UNUSED_ARG(size); + SLJIT_UNUSED_ARG(executable_offset); + + SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + size), 0); + return SLJIT_ADD_EXEC_OFFSET(addr, -executable_offset); +} + +SLJIT_API_FUNC_ATTRIBUTE void sljit_read_only_buffer_end_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset) +{ + SLJIT_UNUSED_ARG(addr); + SLJIT_UNUSED_ARG(size); + SLJIT_UNUSED_ARG(executable_offset); + + SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + size), 1); + SLJIT_CACHE_FLUSH((void*)addr, (void*)(addr + size)); +} + #endif /* !SLJIT_CONFIG_UNSUPPORTED */ diff --git a/deps/sljit/sljit_src/sljitLir.h b/deps/sljit/sljit_src/sljitLir.h index 60d34f1..c5bf128 100644 --- a/deps/sljit/sljit_src/sljitLir.h +++ b/deps/sljit/sljit_src/sljitLir.h @@ -503,6 +503,16 @@ struct sljit_generate_code_buffer { sljit_sw executable_offset; }; +struct sljit_read_only_buffer { + struct sljit_read_only_buffer *next; + sljit_uw size; + /* Label can be replaced by address after sljit_generate_code. */ + union { + struct sljit_label *label; + sljit_uw addr; + } u; +}; + struct sljit_compiler { sljit_s32 error; sljit_s32 options; @@ -705,6 +715,12 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *comp buffer which type is sljit_generate_code_buffer. */ #define SLJIT_GENERATE_CODE_BUFFER 0x1 +/* When SLJIT_INDIRECT_CALL is defined, no function context is +created for the generated code (see sljit_set_function_context), +so the returned pointer cannot be directly called from C code. +The flag is ignored when SLJIT_INDIRECT_CALL is not defined. */ +#define SLJIT_GENERATE_CODE_NO_CONTEXT 0x2 + /* Create executable code from the instruction stream. This is the final step of the code generation, and no more instructions can be emitted after this call. @@ -1450,6 +1466,24 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * sljit_s32 src2_reg, sljit_s32 src3, sljit_sw src3w); +/* The following options are used by sljit_emit_op2_shift. */ + +/* The src2 argument is shifted left by an immedate value. */ +#define SLJIT_SHL_IMM (1 << 9) +/* When src2 argument is a register, its value is undefined after the operation. */ +#define SLJIT_SRC2_UNDEFINED (1 << 10) + +/* Emits an addition operation, where the second argument is shifted by a value. + + op must be SLJIT_ADD | SLJIT_SHL_IMM, where the immedate value is stored in shift_arg + + Flags: - (may destroy flags) */ +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg); + /* Starting index of opcodes for sljit_emit_op_src and sljit_emit_op_dst. */ #define SLJIT_OP_SRC_DST_BASE 112 @@ -1629,8 +1663,53 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fcopy(struct sljit_compiler *compi /* Label and jump instructions. */ +/* Emits a label which can be the target of jump / mov_addr instructions. */ + SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler); +/* Alignment values for sljit_emit_aligned_label. */ + +#define SLJIT_LABEL_ALIGN_1 0 +#define SLJIT_LABEL_ALIGN_2 1 +#define SLJIT_LABEL_ALIGN_4 2 +#define SLJIT_LABEL_ALIGN_8 3 +#define SLJIT_LABEL_ALIGN_16 4 +#define SLJIT_LABEL_ALIGN_W SLJIT_WORD_SHIFT +#define SLJIT_LABEL_ALIGN_P SLJIT_POINTER_SHIFT + +/* Emits a label which address is aligned to a power of 2 value. When some + extra space needs to be added to align the label, that space is filled + with SLJIT_NOP instructions. These labels usually represent the end of a + compilation block, and a new function or some read-only data (e.g. a + jump table) follows it. In these typical cases the SLJIT_NOPs are never + executed. + + Optionally, buffers for storing read-only data or code can be allocated + by this operation. The buffers are passed as a chain list, and a separate + memory area is allocated for each item in the list. All buffers are aligned + to SLJIT_NOP instruction size, and their starting address is returned as + as a label. The sljit_get_label_abs_addr function or the SLJIT_MOV_ABS_ADDR + operation can be used to get the real address. The label of the first buffer + is always the same as the returned label. The buffers are initially + initialized with SLJIT_NOP instructions. The alignment of the buffers can + be controlled by their starting address and sizes. If the starting address + is aligned to N, and size is also divisible by N, the next buffer is aligned + to N. I.e. if a buffer is 16 byte aligned, and its size is divisible by 4, + the next buffer is 4 byte aligned. Note: if a buffer is N (>=2) byte aligned, + it is also N/2 byte aligned. + + align represents the alignment, and its value can + be specified by SLJIT_LABEL_* constants + + buffers is a list of read-only buffers stored in a chain list. + After calling sljit_generate_code, these buffers can be + modified by sljit_read_only_buffer_start_writing() / + sljit_read_only_buffer_end_writing() functions + + Note: the constant pool (if present) may be stored before the label. */ +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers); + /* The SLJIT_FAST_CALL is a calling method for creating lightweight function calls. This type of calls preserve the values of all registers and stack frame. Unlike normal function calls, the enter and return operations must @@ -1757,16 +1836,16 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi #define SLJIT_CALL_REG_ARG 39 /* The target can be changed during runtime (see: sljit_set_jump_addr). */ -#define SLJIT_REWRITABLE_JUMP 0x1000 +#define SLJIT_REWRITABLE_JUMP 0x10000 /* When this flag is passed, the execution of the current function ends and the called function returns to the caller of the current function. The stack usage is reduced before the call, but it is not necessarily reduced to zero. In the latter case the compiler needs to allocate space for some arguments and the return address must be stored on the stack as well. */ -#define SLJIT_CALL_RETURN 0x2000 +#define SLJIT_CALL_RETURN 0x20000 /* Emit a jump instruction. The destination is not set, only the type of the jump. - type must be between SLJIT_EQUAL and SLJIT_FAST_CALL + type must be between SLJIT_JUMP and SLJIT_FAST_CALL type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP Flags: does not modify flags. */ @@ -1780,31 +1859,56 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile Flags: destroy all flags. */ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 arg_types); -/* Basic arithmetic comparison. In most architectures it is implemented as - a compare operation followed by a sljit_emit_jump. However some - architectures (i.e: ARM64 or MIPS) may employ special optimizations - here. It is suggested to use this comparison form when appropriate. +/* Integer comparison operation. In most architectures it is implemented + as a compare (sljit_emit_op2u with SLJIT_SUB) operation followed by + an sljit_emit_jump. However, some architectures (e.g: ARM64 or RISCV) + may optimize the generated code further. It is suggested to use this + comparison form when appropriate. type must be between SLJIT_EQUAL and SLJIT_SIG_LESS_EQUAL - type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP + type can be combined (or'ed) with SLJIT_32 or SLJIT_REWRITABLE_JUMP Flags: may destroy flags. */ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w); -/* Basic floating point comparison. In most architectures it is implemented as - a SLJIT_CMP_F32/64 operation (setting appropriate flags) followed by a - sljit_emit_jump. However some architectures (i.e: MIPS) may employ - special optimizations here. It is suggested to use this comparison form - when appropriate. +/* Floating point comparison operation. In most architectures it is + implemented as a SLJIT_CMP_F32/64 operation (setting appropriate + flags) followed by a sljit_emit_jump. However, some architectures + (e.g: MIPS) may optimize the generated code further. It is suggested + to use this comparison form when appropriate. type must be between SLJIT_F_EQUAL and SLJIT_ORDERED_LESS_EQUAL - type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP + type can be combined (or'ed) with SLJIT_32 or SLJIT_REWRITABLE_JUMP + Flags: destroy flags. - Note: when an operand is NaN the behaviour depends on the comparison type. */ + Note: when any operand is NaN the behaviour depends on the comparison type. */ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w); +/* The following flags are used by sljit_emit_op2cmpz(). */ +#define SLJIT_JUMP_IF_NON_ZERO 0 +#define SLJIT_JUMP_IF_ZERO SLJIT_SET_Z + +/* Perform an integer arithmetic operation, then its result is compared to + zero. In most architectures it is implemented as an sljit_emit_op2 + followed by an sljit_emit_jump. However, some architectures (e.g: RISCV) + may optimize the generated code further. It is suggested to use this + operation form when appropriate (e.g. for loops with counters). + + op must be an sljit_emit_op2 operation where zero flag can be set, + op can be combined with SLJIT_SET_* status flag setters except + SLJIT_SET_Z, SLJIT_REWRITABLE_JUMP or SLJIT_JUMP_IF_* option bits. + + Note: SLJIT_JUMP_IF_NON_ZERO is the default operation if neither + SLJIT_JUMP_IF_ZERO or SLJIT_JUMP_IF_NON_ZERO is specified. + Flags: sets the variable flag depending on op argument, the + zero flag is undefined. */ +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w); + /* Set the destination of the jump to this label. */ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label); /* Set the destination address of the jump to this label. */ @@ -1831,7 +1935,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compi /* Perform an operation using the conditional flags as the second argument. Type must always be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL. The value represented by the type is 1, if the condition represented - by the type is fulfilled, and 0 otherwise. + by type is fulfilled, and 0 otherwise. When op is SLJIT_MOV or SLJIT_MOV32: Set dst to the value represented by the type (0 or 1). @@ -1844,27 +1948,55 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co sljit_s32 dst, sljit_sw dstw, sljit_s32 type); +/* The following flags are used by sljit_emit_select(). */ + +/* Compare src1 and src2_reg operands before executing select + (i.e. converts the select operation to a min/max operation). */ +#define SLJIT_COMPARE_SELECT SLJIT_SET_Z + /* Emit a conditional select instruction which moves src1 to dst_reg, - if the condition is satisfied, or src2_reg to dst_reg otherwise. + if the conditional flag is set, or src2_reg to dst_reg otherwise. + The conditional flag should be set before executing the select + instruction unless SLJIT_COMPARE_SELECT is specified. type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL + when SLJIT_COMPARE_SELECT option is NOT specified + type must be between SLJIT_LESS and SLJIT_SET_SIG_LESS_EQUAL + when SLJIT_COMPARE_SELECT option is specified type can be combined (or'ed) with SLJIT_32 to move 32 bit register values instead of word sized ones + type can be combined (or'ed) with SLJIT_COMPARE_SELECT + which compares src1 and src2_reg before executing the select dst_reg and src2_reg must be valid registers src1 must be valid operand Note: if src1 is a memory operand, its value - might be loaded even if the condition is false. - - Flags: - (does not modify flags) */ + might be loaded even if the condition is false + + Note: when SLJIT_COMPARE_SELECT is specified, the status flag + bits might not represent the result of a normal compare + operation, hence flags are not specified after the operation + + Note: if sljit_has_cpu_feature(SLJIT_HAS_CMOV) returns with a non-zero value: + (a) conditional register move (dst_reg==src2_reg, src1 is register) + can be performed using a single instruction, except on RISCV, + where three instructions are needed + (b) conditional clearing (dst_reg==src2_reg, src1==SLJIT_IMM, + src1w==0) can be performed using a single instruction, + except on x86, where two instructions are needed + + Flags: + When SLJIT_COMPARE_SELECT is NOT specified: - (does not modify flags) + When SLJIT_COMPARE_SELECT is specified: - (may destroy flags) */ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 dst_reg, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2_reg); /* Emit a conditional floating point select instruction which moves - src1 to dst_reg, if the condition is satisfied, or src2_reg to - dst_reg otherwise. + src1 to dst_reg, if the conditional flag is set, or src2_reg to + dst_reg otherwise. The conditional flag should be set before + executing the select instruction. type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL type can be combined (or'ed) with SLJIT_32 to move 32 bit @@ -2301,26 +2433,66 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler Flags: - (may destroy flags) */ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset); -/* Store a value that can be changed runtime (see: sljit_get_const_addr / sljit_set_const) +/* Store a value that can be changed at runtime. The constant + can be managed by sljit_get_const_addr and sljit_set_const. + + op must be SLJIT_MOV, SLJIT_MOV32, SLJIT_MOV_S32, + SLJIT_MOV_U8, SLJIT_MOV32_U8 + + Note: when SLJIT_MOV_U8 is used, and dst is a register, + init_value supports a 9 bit signed value between [-256..255] + Flags: - (does not modify flags) */ -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value); +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value); + +/* Opcodes for sljit_emit_mov_addr. */ + +/* The address is suitable for jump/call target. */ +#define SLJIT_MOV_ADDR 0 +/* The address is suitable for reading memory. */ +#define SLJIT_MOV_ABS_ADDR 1 +/* Add absolute address. */ +#define SLJIT_ADD_ABS_ADDR 2 /* Store the value of a label (see: sljit_set_label / sljit_set_target) Flags: - (does not modify flags) */ -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw); +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw); + +/* Returns the address of a label after sljit_generate_code is called, and + before the compiler is freed by sljit_free_compiler. It is recommended + to save these addresses elsewhere before sljit_free_compiler is called. + + The address returned by sljit_get_label_addr is suitable for a jump/call + target, and the address returned by sljit_get_label_abs_addr is suitable + for reading memory. */ -/* Provides the address of label, jump and const instructions after sljit_generate_code - is called. The returned value is unspecified before the sljit_generate_code call. - Since these structures are freed by sljit_free_compiler, the addresses must be - preserved by the user program elsewere. */ static SLJIT_INLINE sljit_uw sljit_get_label_addr(struct sljit_label *label) { return label->u.addr; } +#if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) +static SLJIT_INLINE sljit_uw sljit_get_label_abs_addr(struct sljit_label *label) { return label->u.addr & ~(sljit_uw)1; } +#else /* !SLJIT_CONFIG_ARM_THUMB2 */ +static SLJIT_INLINE sljit_uw sljit_get_label_abs_addr(struct sljit_label *label) { return label->u.addr; } +#endif /* SLJIT_CONFIG_ARM_THUMB2 */ + +/* Returns the address of jump and const instructions after sljit_generate_code + is called, and before the compiler is freed by sljit_free_compiler. It is + recommended to save these addresses elsewhere before sljit_free_compiler is called. */ + static SLJIT_INLINE sljit_uw sljit_get_jump_addr(struct sljit_jump *jump) { return jump->addr; } static SLJIT_INLINE sljit_uw sljit_get_const_addr(struct sljit_const *const_) { return const_->addr; } /* Only the address and executable offset are required to perform dynamic code modifications. See sljit_get_executable_offset function. */ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset); -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset); +/* The op opcode must be set to the same value that was passed to sljit_emit_const. */ +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset); + +/* Only a single buffer is writable at a time, so sljit_read_only_buffer_end_writing() + must be called before sljit_read_only_buffer_start_writing() is called again. */ +SLJIT_API_FUNC_ATTRIBUTE void* sljit_read_only_buffer_start_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset); +SLJIT_API_FUNC_ATTRIBUTE void sljit_read_only_buffer_end_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset); /* --------------------------------------------------------------------- */ /* CPU specific functions */ @@ -2369,13 +2541,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *c /* Flags were set by an ADD or ADDC operations. */ #define SLJIT_CURRENT_FLAGS_ADD 0x01 -/* Flags were set by a SUB, SUBC, or NEG operation. */ +/* Flags were set by a SUB or SUBC operation. */ #define SLJIT_CURRENT_FLAGS_SUB 0x02 /* Flags were set by sljit_emit_op2u with SLJIT_SUB opcode. Must be combined with SLJIT_CURRENT_FLAGS_SUB. */ #define SLJIT_CURRENT_FLAGS_COMPARE 0x04 +/* Flags were set by sljit_emit_op2cmpz operation. */ +#define SLJIT_CURRENT_FLAGS_OP2CMPZ 0x08 + /* Define the currently available CPU status flags. It is usually used after an sljit_emit_label or sljit_emit_op_custom operations to define which CPU status flags are available. @@ -2405,10 +2580,14 @@ static SLJIT_INLINE struct sljit_const *sljit_get_next_const(struct sljit_const /* A number starting from 0 is assigned to each label, which represents its creation index. The first label created by the -compiler has index 0, the second has index 1, the third has -index 2, and so on. The returned value is unspecified after -sljit_generate_code() is called. */ -static SLJIT_INLINE sljit_uw sljit_get_label_index(struct sljit_label *label) { return label->u.index; } +compiler has index 0, the second one has index 1, the third one +has index 2, and so on. The returned value is unspecified after +sljit_generate_code() is called. + +It is recommended to use this function to get the creation index +of a label, since sljit_emit_label() may return with the last label, +if no code is generated since the last sljit_emit_label() call. */ +SLJIT_API_FUNC_ATTRIBUTE sljit_uw sljit_get_label_index(struct sljit_label *label); /* The sljit_jump_has_label() and sljit_jump_has_target() functions returns non-zero value if a label or target is set for the jump diff --git a/deps/sljit/sljit_src/sljitNativeARM_32.c b/deps/sljit/sljit_src/sljitNativeARM_32.c index 327dc82..16ef399 100644 --- a/deps/sljit/sljit_src/sljitNativeARM_32.c +++ b/deps/sljit/sljit_src/sljitNativeARM_32.c @@ -93,7 +93,7 @@ static const sljit_u8 freg_ebit_map[((SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) << 1) #define VN(vn) (((sljit_ins)freg_map[vn] << 16) | ((sljit_ins)freg_ebit_map[vn] << 7)) /* --------------------------------------------------------------------- */ -/* Instrucion forms */ +/* Instruction forms */ /* --------------------------------------------------------------------- */ /* The instruction includes the AL condition. @@ -771,6 +771,12 @@ static SLJIT_INLINE sljit_sw mov_addr_get_length(struct sljit_jump *jump, sljit_ #endif /* SLJIT_CONFIG_ARM_V6 */ } +static SLJIT_INLINE sljit_ins *process_extended_label(sljit_ins *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_ins*)((sljit_uw)code_ptr & ~(ext_label->data)); +} + #if (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) static void reduce_code_size(struct sljit_compiler *compiler) @@ -882,7 +888,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); /* Second code generation pass. */ #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) @@ -945,6 +951,11 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_ASSERT(!const_ || const_->addr >= word_count); if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + *code_ptr = buf_ptr[-1]; + } + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -1011,6 +1022,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } while (buf); if (label && label->size == word_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -1111,17 +1125,23 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil const_ = compiler->consts; while (const_) { buf_ptr = (sljit_ins*)const_->addr; - const_->addr = (sljit_uw)code_ptr; - code_ptr[0] = (sljit_ins)buf_ptr; - code_ptr[1] = *buf_ptr; - if (*buf_ptr & (1 << 23)) - buf_ptr += ((*buf_ptr & 0xfff) >> 2) + 2; - else - buf_ptr += 1; - /* Set the value again (can be a simple constant). */ - set_const_value((sljit_uw)code_ptr, executable_offset, *buf_ptr, 0); - code_ptr += 2; + /* Note: MVN = (MOV ^ 0x400000) */ + SLJIT_ASSERT((*buf_ptr & 0xfdb00000) == MOV || (*buf_ptr & 0xfd100000) == LDR); + + if ((*buf_ptr & 0x4000000) != 0) { + const_->addr = (sljit_uw)code_ptr; + + code_ptr[0] = (sljit_ins)buf_ptr; + code_ptr[1] = *buf_ptr; + if (*buf_ptr & (1 << 23)) + buf_ptr += ((*buf_ptr & 0xfff) >> 2) + 2; + else + buf_ptr += 1; + /* Set the value again (can be a simple constant). */ + set_const_value((sljit_uw)code_ptr, executable_offset, *buf_ptr, 0); + code_ptr += 2; + } const_ = const_->next; } @@ -1800,7 +1820,7 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl src2 = TMP_REG2; } else compiler->shift_imm = (sljit_uw)(-(sljit_sw)compiler->shift_imm) & 0x1f; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ROTR: shift_type = 3; @@ -2613,6 +2633,54 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst(compiler, ORR | RD(dst_reg) | RN(dst_reg) | RM8(TMP_REG2) | ((sljit_ins)(is_left ? 1 : 0) << 5) | 0x10 | RM(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r, tmp_r; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= 0x1f; + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, TMP_REG1, (sljit_uw)src1w)); + src1 = TMP_REG1; + } else if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, TMP_REG1, src1, src1w, TMP_REG1)); + src1 = TMP_REG1; + } + + if (src2 & SLJIT_MEM) { + tmp_r = (src1 == TMP_REG1) ? TMP_REG2 : TMP_REG1; + FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, tmp_r, src2, src2w, tmp_r)); + src2 = tmp_r; + } + + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + FAIL_IF(push_inst(compiler, ADD | RD(dst_r) | RN(src1) | RM(src2) | ((sljit_ins)shift_arg << 7))); + + if (dst & SLJIT_MEM) + return emit_op_mem(compiler, WORD_SIZE, dst_r, dst, dstw, TMP_REG1); + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -2624,9 +2692,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *comp case SLJIT_FAST_RETURN: SLJIT_ASSERT(reg_map[TMP_REG2] == 14); - if (FAST_IS_REG(src)) - FAIL_IF(push_inst(compiler, MOV | RD(TMP_REG2) | RM(src))); - else + if (FAST_IS_REG(src)) { + if (src != TMP_REG2) + FAIL_IF(push_inst(compiler, MOV | RD(TMP_REG2) | RM(src))); + } else FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, TMP_REG2, src, srcw, TMP_REG1)); return push_inst(compiler, BX | RM(TMP_REG2)); @@ -2656,8 +2725,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *comp case SLJIT_FAST_ENTER: SLJIT_ASSERT(reg_map[TMP_REG2] == 14); - if (FAST_IS_REG(dst)) + if (FAST_IS_REG(dst)) { + if (dst == TMP_REG2) + return SLJIT_SUCCESS; return push_inst(compiler, MOV | RD(dst) | RM(TMP_REG2)); + } break; case SLJIT_GET_RETURN_ADDRESS: size = GET_SAVED_REGISTERS_SIZE(compiler->scratches, compiler->saveds - SLJIT_KEPT_SAVEDS_COUNT(compiler->options), 0); @@ -3065,7 +3137,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD) return 0x20000000; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_LESS: return 0x30000000; @@ -3073,7 +3145,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_NOT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD) return 0x30000000; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_GREATER_EQUAL: return 0x20000000; @@ -3108,7 +3180,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_OVERFLOW: if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB))) return 0x10000000; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_UNORDERED: return 0x60000000; @@ -3116,7 +3188,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_NOT_OVERFLOW: if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB))) return 0x00000000; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ORDERED: return 0x70000000; @@ -3150,6 +3222,65 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, i; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + +#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) + if (SLJIT_UNLIKELY(compiler->cpool_diff != CONST_POOL_EMPTY)) + PTR_FAIL_IF(push_cpool(compiler)); +#endif /* SLJIT_CONFIG_ARM_V6 */ + + if (alignment <= SLJIT_LABEL_ALIGN_4) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_ins); + + for (i = (mask >> 2); i != 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + for (i = (buffers->size + 3) >> 2; i > 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type) { struct sljit_jump *jump; @@ -3604,7 +3735,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp sljit_s32 src1, sljit_sw src1w, sljit_s32 src2_reg) { - sljit_ins cc, tmp; + sljit_ins cc, tmp, tmp2; CHECK_ERROR(); CHECK(check_sljit_emit_select(compiler, type, dst_reg, src1, src1w, src2_reg)); @@ -3615,7 +3746,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp src1 = src2_reg; src1w = 0; src2_reg = dst_reg; - type ^= 0x1; + if (!(type & SLJIT_COMPARE_SELECT)) + type ^= 0x1; } if (src1 & SLJIT_MEM) { @@ -3624,7 +3756,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp if (src2_reg != dst_reg) { src1 = src2_reg; src1w = 0; - type ^= 0x1; + if (!(type & SLJIT_COMPARE_SELECT)) + type ^= 0x1; } else { src1 = TMP_REG1; src1w = 0; @@ -3632,29 +3765,48 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp } else if (dst_reg != src2_reg) FAIL_IF(push_inst(compiler, MOV | RD(dst_reg) | RM(src2_reg))); - cc = get_cc(compiler, type & ~SLJIT_32); + if (type & SLJIT_COMPARE_SELECT) + type ^= 0x1; + + cc = get_cc(compiler, type & ~(SLJIT_32 | SLJIT_COMPARE_SELECT)); if (SLJIT_UNLIKELY(src1 == SLJIT_IMM)) { tmp = get_imm((sljit_uw)src1w); - if (tmp) + if (tmp) { + if (type & SLJIT_COMPARE_SELECT) + FAIL_IF(push_inst(compiler, (CMP | SET_FLAGS | RN(dst_reg) | tmp))); return push_inst(compiler, ((MOV | RD(dst_reg) | tmp) & ~COND_MASK) | cc); + } tmp = get_imm(~(sljit_uw)src1w); + if (tmp && (type & SLJIT_COMPARE_SELECT)) { + tmp2 = get_imm((sljit_uw)-src1w); + if (tmp2) + FAIL_IF(push_inst(compiler, (CMN | SET_FLAGS | RN(dst_reg) | tmp2))); + else + tmp = 0; + } + if (tmp) return push_inst(compiler, ((MVN | RD(dst_reg) | tmp) & ~COND_MASK) | cc); #if (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) - tmp = (sljit_ins)src1w; - FAIL_IF(push_inst(compiler, (MOVW & ~COND_MASK) | cc | RD(dst_reg) | ((tmp << 4) & 0xf0000) | (tmp & 0xfff))); - if (tmp <= 0xffff) - return SLJIT_SUCCESS; - return push_inst(compiler, (MOVT & ~COND_MASK) | cc | RD(dst_reg) | ((tmp >> 12) & 0xf0000) | ((tmp >> 16) & 0xfff)); -#else /* !SLJIT_CONFIG_ARM_V7 */ + if (!(type & SLJIT_COMPARE_SELECT)) { + tmp = (sljit_ins)src1w; + FAIL_IF(push_inst(compiler, (MOVW & ~COND_MASK) | cc | RD(dst_reg) | ((tmp << 4) & 0xf0000) | (tmp & 0xfff))); + if (tmp <= 0xffff) + return SLJIT_SUCCESS; + return push_inst(compiler, (MOVT & ~COND_MASK) | cc | RD(dst_reg) | ((tmp >> 12) & 0xf0000) | ((tmp >> 16) & 0xfff)); + } +#endif /* SLJIT_CONFIG_ARM_V7 */ + FAIL_IF(load_immediate(compiler, TMP_REG1, (sljit_uw)src1w)); src1 = TMP_REG1; -#endif /* SLJIT_CONFIG_ARM_V7 */ } + if (type & SLJIT_COMPARE_SELECT) + FAIL_IF(push_inst(compiler, (CMP | SET_FLAGS | RN(dst_reg) | RM(src1)))); + return push_inst(compiler, ((MOV | RD(dst_reg) | RM(src1)) & ~COND_MASK) | cc); } @@ -4688,13 +4840,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return SLJIT_SUCCESS; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +#define SLJIT_EMIT_CONST_U8(c) \ + (((c) & 0x100) != 0 ? (MVN | SRC2_IMM | (~(c) & 0xff)) : (MOV | SRC2_IMM | ((c) & 0xff))) + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_SIZE; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -4703,35 +4861,52 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + if (GET_OPCODE(op) == SLJIT_MOV_U8) { + PTR_FAIL_IF(push_inst(compiler, SLJIT_EMIT_CONST_U8(init_value) | RD(dst_r))); + mem_flags = BYTE_SIZE; + } else { #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) - PTR_FAIL_IF(push_inst_with_unique_literal(compiler, - EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, dst_r, TMP_PC, 0), (sljit_ins)init_value)); - compiler->patches++; + PTR_FAIL_IF(push_inst_with_unique_literal(compiler, + EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, dst_r, TMP_PC, 0), (sljit_ins)init_value)); + compiler->patches++; #else /* !SLJIT_CONFIG_ARM_V6 */ - PTR_FAIL_IF(emit_imm(compiler, dst_r, init_value)); + PTR_FAIL_IF(emit_imm(compiler, dst_r, init_value)); #endif /* SLJIT_CONFIG_ARM_V6 */ + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, dst, dstw, TMP_REG1)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG2, dst, dstw, TMP_REG1)); + return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_s32 dst_r; + sljit_s32 dst_r, target_r; + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = TMP_REG1; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | LOAD_DATA, TMP_REG2, dst, dstw, TMP_REG1)); + } + #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) - PTR_FAIL_IF(push_inst_with_unique_literal(compiler, EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, dst_r, TMP_PC, 0), 0)); + PTR_FAIL_IF(push_inst_with_unique_literal(compiler, EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, target_r, TMP_PC, 0), 0)); compiler->patches++; #else /* !SLJIT_CONFIG_ARM_V6 */ - PTR_FAIL_IF(push_inst(compiler, RD(dst_r))); + PTR_FAIL_IF(push_inst(compiler, RD(target_r))); #endif /* SLJIT_CONFIG_ARM_V6 */ jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); @@ -4742,6 +4917,9 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com compiler->size += 1; #endif /* SLJIT_CONFIG_ARM_V7 */ + if (op == SLJIT_ADD_ABS_ADDR) + PTR_FAIL_IF(push_inst(compiler, ADD | RD(dst_r) | RN(dst_r) | RM(TMP_REG1))); + if (dst & SLJIT_MEM) PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, dst, dstw, TMP_REG1)); return jump; @@ -4752,7 +4930,21 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta set_jump_addr(addr, executable_offset, new_target, 1); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - set_const_value(addr, executable_offset, (sljit_uw)new_constant, 1); + sljit_ins *inst; + + if (GET_OPCODE(op) != SLJIT_MOV_U8) { + set_const_value(addr, executable_offset, (sljit_uw)new_constant, 1); + return; + } + + inst = (sljit_ins*)addr; + SLJIT_ASSERT((inst[0] & 0xfff00000) == (MOV | SRC2_IMM) || (inst[0] & 0xfff00000) == (MVN | SRC2_IMM)); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + *inst = SLJIT_EMIT_CONST_U8(new_constant) | (*inst & 0xf000); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins*)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); } diff --git a/deps/sljit/sljit_src/sljitNativeARM_64.c b/deps/sljit/sljit_src/sljitNativeARM_64.c index d80c9e5..dabbd3b 100644 --- a/deps/sljit/sljit_src/sljitNativeARM_64.c +++ b/deps/sljit/sljit_src/sljitNativeARM_64.c @@ -24,9 +24,15 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __ARM_FEATURE_ATOMICS +#define ARM_ATOMIC_INFO " (LSE)" +#else +#define ARM_ATOMIC_INFO "" +#endif + SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void) { - return "ARM-64" SLJIT_CPUINFO; + return "ARM-64" ARM_ATOMIC_INFO SLJIT_CPUINFO; } /* Length of an instruction word */ @@ -64,7 +70,7 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { #define VM(vm) ((sljit_ins)freg_map[vm] << 16) /* --------------------------------------------------------------------- */ -/* Instrucion forms */ +/* Instruction forms */ /* --------------------------------------------------------------------- */ #define ADC 0x9a000000 @@ -91,6 +97,7 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { #define CLZ 0xdac01000 #define CSEL 0x9a800000 #define CSINC 0x9a800400 +#define CSINV 0xda800000 #define DMB_SY 0xd5033fbf #define DUP_e 0x0e000400 #define DUP_g 0x0e000c00 @@ -385,6 +392,12 @@ static SLJIT_INLINE void generate_jump_or_mov_addr(struct sljit_jump *jump, slji buf_ptr[3] = MOVK | ((sljit_ins)((sljit_uw)addr >> 48) << 5) | (3 << 21) | dst; } +static SLJIT_INLINE sljit_ins *process_extended_label(sljit_ins *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_ins*)((sljit_uw)code_ptr & ~(ext_label->data)); +} + static void reduce_code_size(struct sljit_compiler *compiler) { struct sljit_label *label; @@ -499,7 +512,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reduce_code_size(compiler); @@ -529,6 +542,11 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil /* These structures are ordered by their address. */ if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + *code_ptr = buf_ptr[-1]; + } + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -565,6 +583,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } while (buf); if (label && label->size == word_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -884,7 +905,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s if (flags & ARG1_IMM) break; imm = -imm; - /* Fall through. */ + SLJIT_FALLTHROUGH case SLJIT_ADD: if (op != SLJIT_SUB) compiler->status_flags_state = SLJIT_CURRENT_FLAGS_ADD; @@ -930,7 +951,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s FAIL_IF(push_inst(compiler, (ORN ^ inv_bits) | RD(dst) | RN(TMP_ZERO) | RM(reg))); goto set_flags; } - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_OR: inst_bits = logical_imm(imm, LOGICAL_IMM_CHECK | ((flags & INT_OP) ? 16 : 32)); if (!inst_bits) @@ -1039,7 +1060,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); if (dst == arg2) return SLJIT_SUCCESS; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_MOV_U32: SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1); return push_inst(compiler, (MOV ^ W_OP) | RD(dst) | RM(arg2)); @@ -1124,7 +1145,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s case SLJIT_ROTL: FAIL_IF(push_inst(compiler, (SUB ^ inv_bits) | RD(TMP_REG2) | RN(TMP_ZERO) | RM(arg2))); arg2 = TMP_REG2; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ROTR: return push_inst(compiler, (RORV ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2)); case SLJIT_MULADD: @@ -1855,6 +1876,54 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst(compiler, (ORR ^ inv_bits) | RD(dst_reg) | RN(dst_reg) | RM(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r, tmp_r; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= 0x3f; + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, TMP_REG2, src1w)); + src1 = TMP_REG2; + } else if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, src1, src1w, TMP_REG2)); + src1 = TMP_REG2; + } + + if (src2 & SLJIT_MEM) { + tmp_r = (src1 == TMP_REG2) ? TMP_REG1 : TMP_REG2; + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, tmp_r, src2, src2w, tmp_r)); + src2 = tmp_r; + } + + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; + FAIL_IF(push_inst(compiler, ADD | RD(dst_r) | RN(src1) | RM(src2) | ((sljit_ins)shift_arg << 10))); + + if (dst & SLJIT_MEM) + return emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2); + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -1864,9 +1933,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_RETURN: - if (FAST_IS_REG(src)) - FAIL_IF(push_inst(compiler, MOV | RD(TMP_LR) | RM(src))); - else + if (FAST_IS_REG(src)) { + if (src != TMP_LR) + FAIL_IF(push_inst(compiler, MOV | RD(TMP_LR) | RM(src))); + } else FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_LR, src, srcw, TMP_REG1)); return push_inst(compiler, RET | RN(TMP_LR)); @@ -1906,8 +1976,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_ENTER: - if (FAST_IS_REG(dst)) + if (FAST_IS_REG(dst)) { + if (dst == TMP_LR) + return SLJIT_SUCCESS; return push_inst(compiler, MOV | RD(dst) | RM(TMP_LR)); + } break; case SLJIT_GET_RETURN_ADDRESS: dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; @@ -2291,7 +2364,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD) return 0x3; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_LESS: return 0x2; @@ -2299,7 +2372,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_NOT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD) return 0x2; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_GREATER_EQUAL: return 0x3; @@ -2334,7 +2407,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_OVERFLOW: if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB))) return 0x0; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_UNORDERED: return 0x7; @@ -2342,7 +2415,7 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_NOT_OVERFLOW: if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB))) return 0x1; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ORDERED: return 0x6; @@ -2376,6 +2449,60 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, i; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (alignment <= SLJIT_LABEL_ALIGN_4) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_ins); + + for (i = (mask >> 2); i != 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + for (i = (buffers->size + 3) >> 2; i > 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type) { struct sljit_jump *jump; @@ -2565,6 +2692,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp sljit_s32 src2_reg) { sljit_ins inv_bits = (type & SLJIT_32) ? W_OP : 0; + sljit_ins op = CSEL; + sljit_ins cmp = 0; sljit_ins cc; CHECK_ERROR(); @@ -2575,15 +2704,38 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp if (src1 == SLJIT_IMM) { if (type & SLJIT_32) src1w = (sljit_s32)src1w; - FAIL_IF(load_immediate(compiler, TMP_REG2, src1w)); - src1 = TMP_REG2; + + if (src1w <= 1 && src1w >= -1) { + src1 = TMP_ZERO; + cmp = (SUBI ^ inv_bits) | (1 << 29) | RD(TMP_ZERO); + + if (src1w == 1) { + op = CSINC; + cmp = (SUBI ^ inv_bits) | (1 << 29) | RD(TMP_ZERO) | (1 << 10); + } else if (src1w == -1) { + op = CSINV; + cmp = (ADDI ^ inv_bits) | (1 << 29) | RD(TMP_ZERO) | (1 << 10); + } + + src1w = 0; + } else { + FAIL_IF(load_immediate(compiler, TMP_REG2, src1w)); + src1 = TMP_REG2; + } } else if (src1 & SLJIT_MEM) { FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, src1, src1w, TMP_REG2)); src1 = TMP_REG2; } - cc = get_cc(compiler, type & ~SLJIT_32); - return push_inst(compiler, (CSEL ^ inv_bits) | (cc << 12) | RD(dst_reg) | RN(src2_reg) | RM(src1)); + if (type & SLJIT_COMPARE_SELECT) { + type ^= 0x1; + if (cmp == 0) + cmp = (SUB ^ inv_bits) | (1 << 29) | RD(TMP_ZERO) | RM(src1); + FAIL_IF(push_inst(compiler, cmp | RN(src2_reg))); + } + + cc = get_cc(compiler, type & ~(SLJIT_32 | SLJIT_COMPARE_SELECT)); + return push_inst(compiler, (op ^ inv_bits) | (cc << 12) | RD(dst_reg) | RN(src2_reg) | RM(src1)); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *compiler, sljit_s32 type, @@ -2701,19 +2853,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler * break; case SLJIT_MOV_S8: sign = 1; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_MOV_U8: inst = STURBI | (MEM_SIZE_SHIFT(BYTE_SIZE) << 30) | 0x400; break; case SLJIT_MOV_S16: sign = 1; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_MOV_U16: inst = STURBI | (MEM_SIZE_SHIFT(HALF_SIZE) << 30) | 0x400; break; case SLJIT_MOV_S32: sign = 1; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_MOV_U32: case SLJIT_MOV32: inst = STURBI | (MEM_SIZE_SHIFT(INT_SIZE) << 30) | 0x400; @@ -3378,6 +3530,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler { sljit_ins ins; sljit_ins cmp = 0; + SLJIT_UNUSED_ARG(temp_reg); /* !__ARM_FEATURE_ATOMICS */ CHECK_ERROR(); CHECK(check_sljit_emit_atomic_store(compiler, op, src_reg, mem_reg, temp_reg)); @@ -3467,6 +3620,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c CHECK_ERROR(); CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset)); + ADJUST_LOCAL_OFFSET(dst, dstw); ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset); dst_reg = FAST_IS_REG(dst) ? dst : TMP_REG1; @@ -3500,13 +3654,21 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c return SLJIT_SUCCESS; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +#define SLJIT_EMIT_CONST_U8(c) \ + (((c) & 0x100) != 0 ? (MOVN | (sljit_ins)((~(c) & 0xff) << 5)) : (MOVZ | (sljit_ins)(((c) & 0xff) << 5))) +#define SLJIT_EMIT_CONST_S32(c) \ + (((c) < 0) ? (MOVN | (sljit_ins)((~(c) & 0xffff) << 5)) : (MOVZ | (sljit_ins)(((c) & 0xffff) << 5))) + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_SIZE | STORE; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -3514,24 +3676,58 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; - PTR_FAIL_IF(emit_imm64_const(compiler, dst_r, (sljit_uw)init_value)); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + PTR_FAIL_IF(push_inst(compiler, SLJIT_EMIT_CONST_U8(init_value) | RD(dst_r))); + mem_flags = BYTE_SIZE | STORE; + break; + + case SLJIT_MOV32: + case SLJIT_MOV_S32: + if (GET_OPCODE(op) == SLJIT_MOV32) { + init_value = (sljit_u32)init_value; + mem_flags = INT_SIZE | STORE; + } else + init_value = (sljit_s32)init_value; + + PTR_FAIL_IF(push_inst(compiler, SLJIT_EMIT_CONST_S32(init_value) | RD(dst_r))); + PTR_FAIL_IF(push_inst(compiler, MOVK | (1 << 21) | (sljit_ins)((init_value >> 11) & 0x1fffe0) | RD(dst_r))); + break; + + default: + PTR_FAIL_IF(emit_imm64_const(compiler, dst_r, (sljit_uw)init_value)); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, dst_r, dst, dstw, TMP_REG2)); return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_s32 dst_r; + sljit_s32 dst_r, target_r; + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; - PTR_FAIL_IF(push_inst(compiler, RD(dst_r))); + + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = TMP_REG2; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, dst, dstw, TMP_REG2)); + } + + PTR_FAIL_IF(push_inst(compiler, RD(target_r))); jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); PTR_FAIL_IF(!jump); @@ -3539,6 +3735,9 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com compiler->size += 3; + if (op == SLJIT_ADD_ABS_ADDR) + PTR_FAIL_IF(push_inst(compiler, ADD | RD(dst_r) | RN(dst_r) | RM(TMP_REG2))); + if (dst & SLJIT_MEM) PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2)); @@ -3565,7 +3764,42 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_CACHE_FLUSH(inst, inst + 4); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_ins* inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_ins*)addr; + SLJIT_ASSERT((inst[0] & 0xffe00000) == MOVZ || (inst[0] & 0xffe00000) == MOVN); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + inst[0] = SLJIT_EMIT_CONST_U8(new_constant) | (inst[0] & 0x1f); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); + return; + + case SLJIT_MOV32: + case SLJIT_MOV_S32: + if (GET_OPCODE(op) == SLJIT_MOV32) + new_constant = (sljit_u32)new_constant; + else + new_constant = (sljit_s32)new_constant; + + inst = (sljit_ins*)addr; + SLJIT_ASSERT(((inst[0] & 0xffe00000) == MOVZ || (inst[0] & 0xffe00000) == MOVN) && (inst[1] & 0xffe00000) == (MOVK | (1 << 21))); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[0] = SLJIT_EMIT_CONST_S32(new_constant) | (inst[0] & 0x1f); + inst[1] = MOVK | (1 << 21) | (sljit_ins)((new_constant >> 11) & 0x1fffe0) | (inst[1] & 0x1f); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } } diff --git a/deps/sljit/sljit_src/sljitNativeARM_T2_32.c b/deps/sljit/sljit_src/sljitNativeARM_T2_32.c index d8058ab..eab9ec1 100644 --- a/deps/sljit/sljit_src/sljitNativeARM_T2_32.c +++ b/deps/sljit/sljit_src/sljitNativeARM_T2_32.c @@ -102,7 +102,7 @@ static const sljit_u8 freg_ebit_map[((SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) << 1) (COPY_BITS(imm, 11, 26, 1) | COPY_BITS(imm, 8, 12, 3) | ((sljit_ins)imm & 0xff)) /* --------------------------------------------------------------------- */ -/* Instrucion forms */ +/* Instruction forms */ /* --------------------------------------------------------------------- */ /* dot '.' changed to _ @@ -160,6 +160,7 @@ static const sljit_u8 freg_ebit_map[((SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2) << 1) #define LSR_WI 0xea4f0010 #define MLA 0xfb000000 #define MOV 0x4600 +#define MOVI 0x2000 #define MOVS 0x0000 #define MOVSI 0x2000 #define MOVT 0xf2c00000 @@ -444,6 +445,9 @@ static SLJIT_INLINE void generate_jump_or_mov_addr(struct sljit_jump *jump, slji diff = (sljit_sw)((jump->flags & JUMP_ADDR) ? jump->u.target : jump->u.label->u.addr); + if ((jump->flags & (JUMP_MOV_ADDR | IS_ABS)) == (JUMP_MOV_ADDR | IS_ABS)) + diff &= ~(sljit_sw)1; + if (SLJIT_UNLIKELY(type == 0)) { ins = (jump->flags & JUMP_MOV_ADDR) ? *jump_inst : RDN3(TMP_REG1); set_imm32_const((sljit_u16*)jump->addr, ins, (sljit_uw)diff); @@ -506,6 +510,12 @@ static SLJIT_INLINE void generate_jump_or_mov_addr(struct sljit_jump *jump, slji jump_inst[1] |= 0xd000; } +static SLJIT_INLINE sljit_u16 *process_extended_label(sljit_u16 *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_u16*)((sljit_uw)code_ptr & ~(ext_label->data)); +} + static void reduce_code_size(struct sljit_compiler *compiler) { struct sljit_label *label; @@ -615,7 +625,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reduce_code_size(compiler); @@ -645,6 +655,11 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil /* These structures are ordered by their address. */ if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + *code_ptr = buf_ptr[-1]; + } + label->u.addr = ((sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset)) | 0x1; label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -682,6 +697,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } while (buf); if (label && label->size == half_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = ((sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset)) | 0x1; label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -1025,7 +1043,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s return push_inst32(compiler, ASR_WI | (flags & SET_FLAGS) | RD4(dst) | RM4(reg) | IMM5(imm)); case SLJIT_ROTL: imm = (imm ^ 0x1f) + 1; - /* fallthrough */ + SLJIT_FALLTHROUGH default: /* SLJIT_ROTR */ return push_inst32(compiler, ROR_WI | RD4(dst) | RM4(reg) | IMM5(imm)); } @@ -1161,7 +1179,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2; FAIL_IF(push_inst32(compiler, ANDI | RD4(reg) | RN4(arg2) | 0x1f)); arg2 = (sljit_uw)reg; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_SHL: if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, LSLS | RD3(dst) | RN3(arg2)); @@ -1170,7 +1188,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2; FAIL_IF(push_inst32(compiler, ANDI | RD4(reg) | RN4(arg2) | 0x1f)); arg2 = (sljit_uw)reg; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_LSHR: if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, LSRS | RD3(dst) | RN3(arg2)); @@ -1179,7 +1197,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2; FAIL_IF(push_inst32(compiler, ANDI | RD4(reg) | RN4(arg2) | 0x1f)); arg2 = (sljit_uw)reg; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ASHR: if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, ASRS | RD3(dst) | RN3(arg2)); @@ -1188,7 +1206,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2; FAIL_IF(push_inst32(compiler, RSB_WI | RD4(reg) | RN4(arg2) | 0)); arg2 = (sljit_uw)reg; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ROTR: if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2)) return push_inst16(compiler, RORS | RD3(dst) | RN3(arg2)); @@ -2182,6 +2200,54 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst32(compiler, ORR_W | RD4(dst_reg) | RN4(dst_reg) | RM4(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r, tmp_r; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= 0x1f; + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, TMP_REG1, (sljit_uw)src1w)); + src1 = TMP_REG1; + } else if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, src1, src1w, TMP_REG1)); + src1 = TMP_REG1; + } + + if (src2 & SLJIT_MEM) { + tmp_r = (src1 == TMP_REG1) ? TMP_REG2 : TMP_REG1; + FAIL_IF(emit_op_mem(compiler, WORD_SIZE, tmp_r, src2, src2w, tmp_r)); + src2 = tmp_r; + } + + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + FAIL_IF(push_inst32(compiler, ADD_W | RD4(dst_r) | RN4(src1) | RM4(src2) | ((sljit_ins)(shift_arg & 0x3) << 6) | ((sljit_ins)(shift_arg & 0x1c) << 10))); + + if (dst & SLJIT_MEM) + return emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG1); + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -2193,9 +2259,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *comp case SLJIT_FAST_RETURN: SLJIT_ASSERT(reg_map[TMP_REG2] == 14); - if (FAST_IS_REG(src)) - FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG2, src))); - else + if (FAST_IS_REG(src)) { + if (src != TMP_REG2) + FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG2, src))); + } else FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, src, srcw, TMP_REG2)); return push_inst16(compiler, BX | RN3(TMP_REG2)); @@ -2224,8 +2291,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *comp case SLJIT_FAST_ENTER: SLJIT_ASSERT(reg_map[TMP_REG2] == 14); - if (FAST_IS_REG(dst)) + if (FAST_IS_REG(dst)) { + if (dst == TMP_REG2) + return SLJIT_SUCCESS; return push_inst16(compiler, MOV | SET_REGS44(dst, TMP_REG2)); + } break; case SLJIT_GET_RETURN_ADDRESS: size = GET_SAVED_REGISTERS_SIZE(compiler->scratches, compiler->saveds - SLJIT_KEPT_SAVEDS_COUNT(compiler->options), 0); @@ -2632,7 +2702,7 @@ static sljit_uw get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD) return 0x2; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_LESS: return 0x3; @@ -2640,7 +2710,7 @@ static sljit_uw get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_NOT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD) return 0x3; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_GREATER_EQUAL: return 0x2; @@ -2675,7 +2745,7 @@ static sljit_uw get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_OVERFLOW: if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB))) return 0x1; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_UNORDERED: return 0x6; @@ -2683,7 +2753,7 @@ static sljit_uw get_cc(struct sljit_compiler *compiler, sljit_s32 type) case SLJIT_NOT_OVERFLOW: if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB))) return 0x0; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ORDERED: return 0x7; @@ -2717,6 +2787,60 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, i; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (alignment <= SLJIT_LABEL_ALIGN_2) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_u16); + + for (i = (mask >> 1); i != 0; i--) + PTR_FAIL_IF(push_inst16(compiler, NOP)); + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + for (i = (buffers->size + 1) >> 1; i > 0; i--) + PTR_FAIL_IF(push_inst16(compiler, NOP)); + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type) { struct sljit_jump *jump; @@ -3166,7 +3290,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp sljit_s32 src1, sljit_sw src1w, sljit_s32 src2_reg) { - sljit_uw cc, tmp; + sljit_uw cc, tmp, tmp2; CHECK_ERROR(); CHECK(check_sljit_emit_select(compiler, type, dst_reg, src1, src1w, src2_reg)); @@ -3177,7 +3301,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp src1 = src2_reg; src1w = 0; src2_reg = dst_reg; - type ^= 0x1; + if (!(type & SLJIT_COMPARE_SELECT)) + type ^= 0x1; } if (src1 & SLJIT_MEM) { @@ -3186,7 +3311,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp if (src2_reg != dst_reg) { src1 = src2_reg; src1w = 0; - type ^= 0x1; + if (!(type & SLJIT_COMPARE_SELECT)) + type ^= 0x1; } else { src1 = TMP_REG1; src1w = 0; @@ -3194,9 +3320,55 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp } else if (dst_reg != src2_reg) FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(dst_reg, src2_reg))); - cc = get_cc(compiler, type & ~SLJIT_32); + if ((type & SLJIT_COMPARE_SELECT)) + type ^= 0x1; + cc = get_cc(compiler, type & ~(SLJIT_32 | SLJIT_COMPARE_SELECT)); + + if (src1 == SLJIT_IMM && (type & SLJIT_COMPARE_SELECT)) { + tmp = (sljit_uw)src1w; + if (tmp <= 0xff && reg_map[dst_reg] <= 7) { + if (type & SLJIT_COMPARE_SELECT) + FAIL_IF(push_inst16(compiler, CMPI | IMM8(tmp) | RDN3(dst_reg))); + FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8)); + return push_inst16(compiler, MOVI | IMM8(tmp) | RDN3(dst_reg)); + } + + tmp = get_imm((sljit_uw)src1w); + if (tmp != INVALID_IMM) { + if (type & SLJIT_COMPARE_SELECT) + FAIL_IF(push_inst32(compiler, CMPI_W | RN4(dst_reg) | tmp)); + FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8)); + return push_inst32(compiler, MOV_WI | RD4(dst_reg) | tmp); + } + + tmp = get_imm(~(sljit_uw)src1w); + if (tmp != INVALID_IMM && (type & SLJIT_COMPARE_SELECT)) { + tmp2 = get_imm(NEGATE(src1w)); + if (tmp2 != INVALID_IMM) + FAIL_IF(push_inst32(compiler, CMNI_W | RN4(dst_reg) | tmp2)); + else + tmp = INVALID_IMM; + } + + if (tmp != INVALID_IMM) { + FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8)); + return push_inst32(compiler, MVN_WI | RD4(dst_reg) | tmp); + } + + if (type & SLJIT_COMPARE_SELECT) { + FAIL_IF(load_immediate(compiler, TMP_REG1, (sljit_uw)src1w)); + src1 = TMP_REG1; + } + } if (src1 != SLJIT_IMM) { + if (type & SLJIT_COMPARE_SELECT) { + if (IS_2_LO_REGS(dst_reg, src1)) + FAIL_IF(push_inst16(compiler, CMP | RD3(dst_reg) | RN3(src1))); + else + FAIL_IF(push_inst16(compiler, CMP_X | SET_REGS44(dst_reg, src1))); + } + FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8)); return push_inst16(compiler, MOV | SET_REGS44(dst_reg, src1)); } @@ -3210,18 +3382,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp | COPY_BITS(tmp, 12, 16, 4) | COPY_BITS(tmp, 11, 26, 1) | COPY_BITS(tmp, 8, 12, 3) | (tmp & 0xff)); } - tmp = get_imm((sljit_uw)src1w); - if (tmp != INVALID_IMM) { - FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8)); - return push_inst32(compiler, MOV_WI | RD4(dst_reg) | tmp); - } - - tmp = get_imm(~(sljit_uw)src1w); - if (tmp != INVALID_IMM) { - FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8)); - return push_inst32(compiler, MVN_WI | RD4(dst_reg) | tmp); - } - FAIL_IF(push_inst16(compiler, IT | (cc << 4) | ((cc & 0x1) << 3) | 0x4)); tmp = (sljit_uw)src1w; @@ -4357,13 +4517,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return SLJIT_SUCCESS; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_SIZE | STORE; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -4371,32 +4534,55 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; - PTR_FAIL_IF(emit_imm32_const(compiler, dst_r, (sljit_uw)init_value)); + + if (GET_OPCODE(op) == SLJIT_MOV_U8) { + PTR_FAIL_IF(push_inst32(compiler, + ((init_value & 0x100) != 0 ? (MVN_WI | (~init_value & 0xff)) : (MOV_WI | (init_value & 0xff))) | RD4(dst_r))); + mem_flags = BYTE_SIZE | STORE; + } else + PTR_FAIL_IF(emit_imm32_const(compiler, dst_r, (sljit_uw)init_value)); if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, dst_r, dst, dstw, TMP_REG2)); return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_s32 dst_r; + sljit_s32 dst_r, target_r; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = TMP_REG1; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE, dst_r, dst, dstw, TMP_REG1)); + } + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); PTR_FAIL_IF(!jump); set_mov_addr(jump, compiler, 0); - dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; - PTR_FAIL_IF(push_inst16(compiler, RDN3(dst_r))); + if (op != SLJIT_MOV_ADDR) + jump->flags |= IS_ABS; + + PTR_FAIL_IF(push_inst16(compiler, RDN3(target_r))); compiler->size += 3; + if (op == SLJIT_ADD_ABS_ADDR) + PTR_FAIL_IF(push_inst16(compiler, ADD | SET_REGS44(dst_r, TMP_REG1))); + if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2)); + PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG1)); return jump; } @@ -4412,7 +4598,28 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_CACHE_FLUSH(inst, inst + 4); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_u16 *inst; + + if (GET_OPCODE(op) != SLJIT_MOV_U8) { + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } + + inst = (sljit_u16*)addr; + SLJIT_ASSERT(inst[0] == (MOV_WI >> 16) || inst[0] == (MVN_WI >> 16)); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + + if ((new_constant & 0x100) != 0) { + inst[0] = (sljit_u16)(MVN_WI >> 16); + new_constant = ~new_constant; + } else + inst[0] = (sljit_u16)(MOV_WI >> 16); + + inst[1] = (sljit_u16)((new_constant & 0xff) | (inst[1] & 0xf00)); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst + 1, inst + 2); } diff --git a/deps/sljit/sljit_src/sljitNativeLOONGARCH_64.c b/deps/sljit/sljit_src/sljitNativeLOONGARCH_64.c index 73868ca..1331966 100644 --- a/deps/sljit/sljit_src/sljitNativeLOONGARCH_64.c +++ b/deps/sljit/sljit_src/sljitNativeLOONGARCH_64.c @@ -53,7 +53,7 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { }; /* --------------------------------------------------------------------- */ -/* Instrucion forms */ +/* Instruction forms */ /* --------------------------------------------------------------------- */ /* @@ -256,6 +256,7 @@ lower parts in the instruction word, denoted by the “L” and “H” suffixes /* Other instructions */ #define BREAK OPC_3R(0x54) #define DBGCALL OPC_3R(0x55) +#define NOP ANDI #define SYSCALL OPC_3R(0x56) /* Basic Floating-Point Instructions */ @@ -580,6 +581,12 @@ static SLJIT_INLINE void load_addr_to_reg(struct sljit_jump *jump, sljit_sw exec ins[1] = ORI | RD(reg) | RJ(reg) | IMM_I12(addr); } +static SLJIT_INLINE sljit_ins *process_extended_label(sljit_ins *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_ins*)((sljit_uw)code_ptr & ~(ext_label->data)); +} + static void reduce_code_size(struct sljit_compiler *compiler) { struct sljit_label *label; @@ -694,7 +701,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reduce_code_size(compiler); @@ -724,6 +731,11 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil /* These structures are ordered by their address. */ if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + *code_ptr = buf_ptr[-1]; + } + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -759,6 +771,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } while (buf); if (label && label->size == word_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)code_ptr; label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -893,14 +908,18 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r if (imm <= 0x7fffffffl && imm >= -0x80000000l) { FAIL_IF(push_inst(compiler, LU12I_W | RD(dst_r) | (sljit_ins)(((imm & 0xffffffff) >> 12) << 5))); - return push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(imm)); + if (IMM_I12(imm) != 0) + return push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(imm)); + return SLJIT_SUCCESS; } else if (imm <= 0x7ffffffffffffl && imm >= -0x8000000000000l) { FAIL_IF(push_inst(compiler, LU12I_W | RD(dst_r) | (sljit_ins)(((imm & 0xffffffff) >> 12) << 5))); - FAIL_IF(push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(imm))); + if (IMM_I12(imm) != 0) + FAIL_IF(push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(imm))); return push_inst(compiler, LU32I_D | RD(dst_r) | (sljit_ins)(((imm >> 32) & 0xfffff) << 5)); } FAIL_IF(push_inst(compiler, LU12I_W | RD(dst_r) | (sljit_ins)(((imm & 0xffffffff) >> 12) << 5))); - FAIL_IF(push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(imm))); + if (IMM_I12(imm) != 0) + FAIL_IF(push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(imm))); FAIL_IF(push_inst(compiler, LU32I_D | RD(dst_r) | (sljit_ins)(((imm >> 32) & 0xfffff) << 5))); return push_inst(compiler, LU52I_D | RD(dst_r) | RJ(dst_r) | IMM_I12(imm >> 52)); } @@ -1596,7 +1615,7 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (src2 >= 0) FAIL_IF(push_inst(compiler, INST(ADDI, op) | RD(EQUAL_FLAG) | RJ(src1) | IMM_I12(0))); else { - FAIL_IF(push_inst(compiler, INST(ADDI, op) | RD(EQUAL_FLAG) | RJ(src1) | IMM_I12(-1))); + FAIL_IF(push_inst(compiler, INST(ADDI, op) | RD(EQUAL_FLAG) | RJ(TMP_ZERO) | IMM_I12(-1))); FAIL_IF(push_inst(compiler, XOR | RD(EQUAL_FLAG) | RJ(src1) | RK(EQUAL_FLAG))); } } else if (op & SLJIT_SET_Z) @@ -1897,7 +1916,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compile case SLJIT_BREAKPOINT: return push_inst(compiler, BREAK); case SLJIT_NOP: - return push_inst(compiler, ANDI | RD(TMP_ZERO) | RJ(TMP_ZERO) | IMM_I12(0)); + return push_inst(compiler, NOP); case SLJIT_LMUL_UW: FAIL_IF(push_inst(compiler, ADDI_D | RD(TMP_REG1) | RJ(SLJIT_R1) | IMM_I12(0))); FAIL_IF(push_inst(compiler, MULH_DU | RD(SLJIT_R1) | RJ(SLJIT_R0) | RK(SLJIT_R1))); @@ -2155,6 +2174,55 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst(compiler, OR | RD(dst_reg) | RJ(dst_reg) | RK(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r, tmp_r; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= (sljit_sw)((sizeof(sljit_sw) * 8) - 1); + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + if (src2 & SLJIT_MEM) { + FAIL_IF(emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, TMP_REG2, src2, src2w, src1, src1w)); + src2 = TMP_REG2; + } + + if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, TMP_REG1, src1w)); + src1 = TMP_REG1; + } else if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, src1, src1w, dst, dstw)); + src1 = TMP_REG1; + } + + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + tmp_r = (src1 == TMP_REG1) ? TMP_REG2 : TMP_REG1; + FAIL_IF(push_inst(compiler, SLLI_D | RD(tmp_r) | RJ(src2) | IMM_I12(shift_arg))); + FAIL_IF(push_inst(compiler, ADD_D | RD(dst_r) | RJ(src1) | RK(tmp_r))); + + if (dst & SLJIT_MEM) + return emit_op_mem2(compiler, WORD_DATA, dst_r, dst, dstw, 0, 0); + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -2166,9 +2234,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_RETURN: - if (FAST_IS_REG(src)) - FAIL_IF(push_inst(compiler, ADDI_D | RD(RETURN_ADDR_REG) | RJ(src) | IMM_I12(0))); - else + if (FAST_IS_REG(src)) { + if (src != RETURN_ADDR_REG) + FAIL_IF(push_inst(compiler, ADDI_D | RD(RETURN_ADDR_REG) | RJ(src) | IMM_I12(0))); + } else FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG, src, srcw)); return push_inst(compiler, JIRL | RD(TMP_ZERO) | RJ(RETURN_ADDR_REG) | IMM_I12(0)); @@ -2207,8 +2276,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_ENTER: - if (FAST_IS_REG(dst)) + if (FAST_IS_REG(dst)) { + if (dst == RETURN_ADDR_REG) + return SLJIT_SUCCESS; return push_inst(compiler, ADDI_D | RD(dst) | RJ(RETURN_ADDR_REG) | IMM_I12(0)); + } SLJIT_ASSERT(RETURN_ADDR_REG == TMP_REG2); break; @@ -2676,6 +2748,60 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, i; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (alignment <= SLJIT_LABEL_ALIGN_4) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_ins); + + for (i = (mask >> 2); i != 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + for (i = (buffers->size + 3) >> 2; i > 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + static sljit_ins get_jump_instruction(sljit_s32 type) { switch (type) { @@ -3032,19 +3158,27 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp { sljit_ins *ptr; sljit_uw size; + sljit_s32 is_compare = (type & SLJIT_COMPARE_SELECT); sljit_s32 inp_flags = ((type & SLJIT_32) ? INT_DATA : WORD_DATA) | LOAD_DATA; CHECK_ERROR(); CHECK(check_sljit_emit_select(compiler, type, dst_reg, src1, src1w, src2_reg)); ADJUST_LOCAL_OFFSET(src1, src1w); + if (src1 == SLJIT_IMM && type & SLJIT_32) + src1w = (sljit_s32)src1w; + + type &= ~(SLJIT_32 | SLJIT_COMPARE_SELECT); + if (dst_reg != src2_reg) { if (dst_reg == src1) { src1 = src2_reg; src1w = 0; - type ^= 0x1; + if (!is_compare) + type ^= 0x1; } else { if (ADDRESSING_DEPENDS_ON(src1, dst_reg)) { + SLJIT_ASSERT(!(type & SLJIT_COMPARE_SELECT)); FAIL_IF(push_inst(compiler, ADDI_D | RD(TMP_REG1) | RJ(dst_reg) | IMM_I12(0))); if ((src1 & REG_MASK) == dst_reg) @@ -3058,6 +3192,15 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp } } + if (is_compare) { + if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, inp_flags, TMP_REG3, src1, src1w)); + } else if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, TMP_REG3, src1w)); + } else + FAIL_IF(push_inst(compiler, ADDI_D | RD(TMP_REG3) | RJ(src1) | IMM_I12(0))); + } + size = compiler->size; ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins)); @@ -3067,13 +3210,35 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp if (src1 & SLJIT_MEM) { FAIL_IF(emit_op_mem(compiler, inp_flags, dst_reg, src1, src1w)); } else if (src1 == SLJIT_IMM) { - if (type & SLJIT_32) - src1w = (sljit_s32)src1w; FAIL_IF(load_immediate(compiler, dst_reg, src1w)); } else FAIL_IF(push_inst(compiler, ADDI_D | RD(dst_reg) | RJ(src1) | IMM_I12(0))); - *ptr = get_jump_instruction(type & ~SLJIT_32) | IMM_I16(compiler->size - size); + if (is_compare) { + switch (type) { + case SLJIT_LESS: + case SLJIT_LESS_EQUAL: + *ptr = BGEU; + break; + case SLJIT_GREATER: + case SLJIT_GREATER_EQUAL: + *ptr = BLTU; + break; + case SLJIT_SIG_LESS: + case SLJIT_SIG_LESS_EQUAL: + *ptr = BGE; + break; + default: + *ptr = BLT; + break; + } + + *ptr |= RJ(TMP_REG3) | RD(dst_reg); + } else { + *ptr = get_jump_instruction(type); + } + + *ptr |= IMM_I16(compiler->size - size); return SLJIT_SUCCESS; } @@ -3830,13 +3995,16 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_CACHE_FLUSH(inst, inst + 4); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_DATA; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -3844,39 +4012,112 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(emit_const(compiler, dst_r, init_value, 0)); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xf00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, ADDI_D | RD(dst_r) | RJ(TMP_ZERO) | IMM_I12(init_value))); + mem_flags = BYTE_DATA; + break; + + case SLJIT_MOV32: + mem_flags = INT_DATA; + SLJIT_FALLTHROUGH + case SLJIT_MOV_S32: + PTR_FAIL_IF(push_inst(compiler, LU12I_W | RD(dst_r) | (sljit_ins)((init_value >> 7) & 0x1ffffe0))); + PTR_FAIL_IF(push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(init_value))); + break; + + default: + PTR_FAIL_IF(emit_const(compiler, dst_r, init_value, 0)); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG2, dst, dstw)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG2, dst, dstw)); return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_s32 dst_r; + sljit_s32 dst_r, target_r; + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = TMP_REG1; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG2, dst, dstw)); + } + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); PTR_FAIL_IF(!jump); set_mov_addr(jump, compiler, 0); - dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(push_inst(compiler, (sljit_ins)dst_r)); + PTR_FAIL_IF(push_inst(compiler, (sljit_ins)target_r)); compiler->size += JUMP_MAX_SIZE - 1; + if (op == SLJIT_ADD_ABS_ADDR) + PTR_FAIL_IF(push_inst(compiler, ADD_D | RD(dst_r) | RJ(dst_r) | RK(TMP_REG1))); + if (dst & SLJIT_MEM) PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG2, dst, dstw)); return jump; } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_ins* inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_ins*)addr; + SLJIT_ASSERT((inst[0] & OPC_2RI12(0xb)) == ADDI_D); + + if (new_constant & 0x100) + new_constant |= 0xf00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + inst[0] = (inst[0] & 0xffc003ff) | (sljit_ins)((new_constant & 0xfff) << 10); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); + return; + + case SLJIT_MOV32: + case SLJIT_MOV_S32: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & OPC_1RI20(0xa)) == LU12I_W && (inst[1] & OPC_2RI12(0xe)) == ORI); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[0] = (inst[0] & (OPC_1RI20(0xa) | 0x1f)) | (sljit_ins)((new_constant >> 7) & 0x1ffffe0); + inst[1] = (inst[1] & (OPC_2RI12(0xe) | 0x3ff)) | (sljit_ins)((new_constant & 0xfff) << 10); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } } diff --git a/deps/sljit/sljit_src/sljitNativeMIPS_32.c b/deps/sljit/sljit_src/sljitNativeMIPS_32.c index 91153e5..8397961 100644 --- a/deps/sljit/sljit_src/sljitNativeMIPS_32.c +++ b/deps/sljit/sljit_src/sljitNativeMIPS_32.c @@ -196,18 +196,13 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); SLJIT_ASSERT((inst[0] & 0xffe00000) == LUI && (inst[1] & 0xfc000000) == ORI); - inst[0] = (inst[0] & 0xffff0000) | ((new_target >> 16) & 0xffff); - inst[1] = (inst[1] & 0xffff0000) | (new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_target >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 2); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) -{ - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); -} - static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_ins *ins_ptr, sljit_u32 *extra_space) { sljit_u32 is_tail_call = *extra_space & SLJIT_CALL_RETURN; diff --git a/deps/sljit/sljit_src/sljitNativeMIPS_64.c b/deps/sljit/sljit_src/sljitNativeMIPS_64.c index b9f03a7..965931b 100644 --- a/deps/sljit/sljit_src/sljitNativeMIPS_64.c +++ b/deps/sljit/sljit_src/sljitNativeMIPS_64.c @@ -202,20 +202,15 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UNUSED_ARG(executable_offset); SLJIT_UPDATE_WX_FLAGS(inst, inst + 6, 0); - inst[0] = (inst[0] & 0xffff0000) | ((sljit_ins)(new_target >> 48) & 0xffff); - inst[1] = (inst[1] & 0xffff0000) | ((sljit_ins)(new_target >> 32) & 0xffff); - inst[3] = (inst[3] & 0xffff0000) | ((sljit_ins)(new_target >> 16) & 0xffff); - inst[5] = (inst[5] & 0xffff0000) | ((sljit_ins)new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_target >> 48); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_target >> 32); + inst[3] = (inst[3] & 0xffff0000) | IMM(new_target >> 16); + inst[5] = (inst[5] & 0xffff0000) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 6, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 6); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) -{ - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); -} - static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_ins *ins_ptr) { sljit_s32 arg_count = 0; diff --git a/deps/sljit/sljit_src/sljitNativeMIPS_common.c b/deps/sljit/sljit_src/sljitNativeMIPS_common.c index 1b951fe..771abfe 100644 --- a/deps/sljit/sljit_src/sljitNativeMIPS_common.c +++ b/deps/sljit/sljit_src/sljitNativeMIPS_common.c @@ -121,7 +121,7 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 4] = { #endif /* SLJIT_CONFIG_MIPS_32 */ /* --------------------------------------------------------------------- */ -/* Instrucion forms */ +/* Instruction forms */ /* --------------------------------------------------------------------- */ #define S(s) ((sljit_ins)reg_map[s] << 21) @@ -709,6 +709,12 @@ static SLJIT_INLINE void load_addr_to_reg(struct sljit_jump *jump) ins[1] = ORI | S(reg) | T(reg) | IMM(addr & 0xffff); } +static SLJIT_INLINE sljit_ins *process_extended_label(sljit_ins *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_ins*)((sljit_uw)code_ptr & ~(ext_label->data)); +} + SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler, sljit_s32 options, void *exec_allocator_data) { struct sljit_memory_fragment *buf; @@ -725,7 +731,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reverse_buf(compiler); code = (sljit_ins*)allocate_executable_memory(compiler->size * sizeof(sljit_ins), options, exec_allocator_data, &executable_offset); @@ -752,6 +758,11 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil /* These structures are ordered by their address. */ if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + *code_ptr = buf_ptr[-1]; + } + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -796,6 +807,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } while (buf); if (label && label->size == word_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)code_ptr; label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -1532,11 +1546,11 @@ static sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, s return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar) | IMM(argw), delay_slot); } -static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg1, sljit_sw arg1w, sljit_s32 arg2, sljit_sw arg2w) +static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg_ar, sljit_s32 arg1, sljit_sw arg1w, sljit_s32 arg2, sljit_sw arg2w) { - if (getput_arg_fast(compiler, flags, reg, arg1, arg1w)) + if (getput_arg_fast(compiler, flags, reg_ar, arg1, arg1w)) return compiler->error; - return getput_arg(compiler, flags, reg, arg1, arg1w, arg2, arg2w); + return getput_arg(compiler, flags, reg_ar, arg1, arg1w, arg2, arg2w); } #define EMIT_LOGICAL(op_imm, op_reg) \ @@ -2167,7 +2181,7 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl FAIL_IF(push_inst(compiler, SELECT_OP(DSUBU, SUBU) | SA(0) | T(src2) | D(TMP_REG2), DR(TMP_REG2))); src2 = TMP_REG2; } - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ROTR: EMIT_SHIFT(DROTR, DROTR32, ROTR, DROTRV, ROTRV); @@ -2634,7 +2648,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile if ((src1 == SLJIT_IMM && src1w == -1) || (src2 == SLJIT_IMM && src2w == -1)) { return emit_op(compiler, op, flags | CUMULATIVE_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w); } - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_AND: case SLJIT_OR: return emit_op(compiler, op, flags | CUMULATIVE_OP | LOGICAL_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w); @@ -2780,6 +2794,59 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst(compiler, OR | S(dst_reg) | T(TMP_REG1) | D(dst_reg), DR(dst_reg)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r, tmp_r; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= (sljit_sw)((sizeof(sljit_sw) * 8) - 1); + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + if (src2 & SLJIT_MEM) { + FAIL_IF(emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, DR(TMP_REG2), src2, src2w, src1, src1w)); + src2 = TMP_REG2; + } + + if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, DR(TMP_REG1), src1w)); + src1 = TMP_REG1; + } else if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, DR(TMP_REG1), src1, src1w, dst, dstw)); + src1 = TMP_REG1; + } + + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + tmp_r = (src1 == TMP_REG1) ? TMP_REG2 : TMP_REG1; +#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) + FAIL_IF(push_inst(compiler, (shift_arg >= 32 ? DSLL32 : DSLL) | T(src2) | D(tmp_r) | SH_IMM(shift_arg & 0x1f), DR(tmp_r))); +#else /* !SLJIT_CONFIG_MIPS_64 */ + FAIL_IF(push_inst(compiler, SLL | T(src2) | D(tmp_r) | SH_IMM(shift_arg), DR(tmp_r))); +#endif /* SLJIT_CONFIG_MIPS_64 */ + FAIL_IF(push_inst(compiler, ADDU_W | S(src1) | T(tmp_r) | D(dst_r), DR(dst_r))); + + if (dst & SLJIT_MEM) + return emit_op_mem2(compiler, WORD_DATA, DR(dst_r), dst, dstw, 0, 0); + return SLJIT_SUCCESS; +} + #undef SELECT_OP3 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, @@ -2791,9 +2858,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_RETURN: - if (FAST_IS_REG(src)) - FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | DA(RETURN_ADDR_REG), RETURN_ADDR_REG)); - else + if (FAST_IS_REG(src)) { + if (DR(src) != RETURN_ADDR_REG) + FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | DA(RETURN_ADDR_REG), RETURN_ADDR_REG)); + } else FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG, src, srcw)); FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS)); @@ -2825,8 +2893,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_ENTER: - if (FAST_IS_REG(dst)) + if (FAST_IS_REG(dst)) { + if (DR(dst) == RETURN_ADDR_REG) + return SLJIT_SUCCESS; return push_inst(compiler, ADDU_W | SA(RETURN_ADDR_REG) | TA(0) | D(dst), UNMOVABLE_INS); + } break; case SLJIT_GET_RETURN_ADDRESS: dst_ar = DR(FAST_IS_REG(dst) ? dst : TMP_REG2); @@ -3278,6 +3349,60 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, i; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (alignment <= SLJIT_LABEL_ALIGN_4) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_ins); + + for (i = (mask >> 2); i != 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS)); + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + for (i = (buffers->size + 3) >> 2; i > 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS)); + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) #define BRANCH_LENGTH 4 #else @@ -3718,7 +3843,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co static sljit_ins get_select_cc(sljit_s32 type, sljit_s32 is_float) { - switch (type & ~SLJIT_32) { + switch (type) { case SLJIT_EQUAL: return (is_float ? MOVZ_S : MOVZ) | TA(EQUAL_FLAG); case SLJIT_NOT_EQUAL: @@ -3789,15 +3914,37 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp CHECK(check_sljit_emit_select(compiler, type, dst_reg, src1, src1w, src2_reg)); ADJUST_LOCAL_OFFSET(src1, src1w); +#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) + if (src1 == SLJIT_IMM && (type & SLJIT_32)) + src1w = (sljit_s32)src1w; +#endif + + type &= ~SLJIT_32; + + if (type & SLJIT_COMPARE_SELECT) { + type ^= SLJIT_COMPARE_SELECT; + + if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, inp_flags, DR(TMP_REG1), src1, src1w)); + src1 = TMP_REG1; + } else if (src1 == SLJIT_IMM) { + if (src1w == 0) { + src1 = 0; + } else { + FAIL_IF(load_immediate(compiler, DR(TMP_REG1), src1w)); + src1 = TMP_REG1; + } + } + + src1w = 0; + FAIL_IF(emit_op(compiler, SLJIT_SUB | SLJIT_SET(type & ~0x1), IMM_OP, 0, 0, src1, 0, src2_reg, 0)); + } + #if (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 1 && SLJIT_MIPS_REV < 6) if (src1 & SLJIT_MEM) { FAIL_IF(emit_op_mem(compiler, inp_flags, DR(TMP_REG1), src1, src1w)); src1 = TMP_REG1; } else if (src1 == SLJIT_IMM) { -#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) - if (type & SLJIT_32) - src1w = (sljit_s32)src1w; -#endif FAIL_IF(load_immediate(compiler, DR(TMP_REG1), src1w)); src1 = TMP_REG1; } @@ -3834,16 +3981,12 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp } SLJIT_SKIP_CHECKS(compiler); - jump = sljit_emit_jump(compiler, (type & ~SLJIT_32) ^ 0x1); + jump = sljit_emit_jump(compiler, type ^ 0x1); FAIL_IF(!jump); if (src1 & SLJIT_MEM) { FAIL_IF(emit_op_mem(compiler, inp_flags, DR(dst_reg), src1, src1w)); } else if (src1 == SLJIT_IMM) { -#if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) - if (type & SLJIT_32) - src1w = (sljit_s32)src1w; -#endif /* SLJIT_CONFIG_MIPS_64 */ FAIL_IF(load_immediate(compiler, DR(dst_reg), src1w)); } else FAIL_IF(push_inst(compiler, mov_ins | S(src1) | TA(0) | D(dst_reg), DR(dst_reg))); @@ -3887,11 +4030,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *com src1 = TMP_FREG2; } - return push_inst(compiler, get_select_cc(type, 1) | FMT(type) | FS(src1) | FD(dst_freg), MOVABLE_INS); + return push_inst(compiler, get_select_cc(type & ~SLJIT_32, 1) | FMT(type) | FS(src1) | FD(dst_freg), MOVABLE_INS); #else /* SLJIT_MIPS_REV < 1 || SLJIT_MIPS_REV >= 6 */ SLJIT_SKIP_CHECKS(compiler); - jump = sljit_emit_jump(compiler, (type & ~SLJIT_32) ^ 0x1); + jump = sljit_emit_jump(compiler, type ^ 0x1); FAIL_IF(!jump); if (src1 & SLJIT_MEM) @@ -4301,7 +4444,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) ins = SCD; break; -#endif /* SLJIT_CONFIG_RISCV_64 */ +#endif /* SLJIT_CONFIG_MIPS_64 */ case SLJIT_MOV_S32: case SLJIT_MOV32: op |= SLJIT_32; @@ -4319,13 +4462,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return push_inst(compiler, ins | TA(OTHER_FLAG) | S(mem_reg), OTHER_FLAG); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_DATA; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -4333,37 +4479,119 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xff00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, ADDIU | SA(0) | T(dst_r) | IMM(init_value), DR(dst_r))); + mem_flags = BYTE_DATA; + break; + +#if (defined(SLJIT_CONFIG_MIPS_64) && SLJIT_CONFIG_MIPS_64) + case SLJIT_MOV32: + mem_flags = INT_DATA; + SLJIT_FALLTHROUGH + case SLJIT_MOV_S32: + PTR_FAIL_IF(push_inst(compiler, LUI | T(dst_r) | IMM(init_value >> 16), DR(dst_r))); + PTR_FAIL_IF(push_inst(compiler, ORI | S(dst_r) | T(dst_r) | IMM(init_value), DR(dst_r))); + break; +#endif /* SLJIT_CONFIG_MIPS_64 */ + + default: + PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, DR(TMP_REG2), dst, dstw)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, DR(TMP_REG2), dst, dstw)); return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_s32 dst_r; + sljit_s32 dst_r, target_r; + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = TMP_REG1; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, DR(TMP_REG2), dst, dstw)); + } + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); PTR_FAIL_IF(!jump); set_mov_addr(jump, compiler, 0); - dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(push_inst(compiler, (sljit_ins)dst_r, UNMOVABLE_INS)); + PTR_FAIL_IF(push_inst(compiler, (sljit_ins)target_r, UNMOVABLE_INS)); #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) compiler->size += 1; #else compiler->size += 5; #endif + if (op == SLJIT_ADD_ABS_ADDR) + PTR_FAIL_IF(push_inst(compiler, ADDU_W | S(dst_r) | T(TMP_REG1) | D(dst_r), DR(dst_r))); + if (dst & SLJIT_MEM) PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, DR(TMP_REG2), dst, dstw)); return jump; } + +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) +{ + sljit_ins *inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xfc000000) == ADDIU); + + if (new_constant & 0x100) + new_constant |= 0xff00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); + return; + +#if (defined(SLJIT_CONFIG_MIPS_64) && SLJIT_CONFIG_MIPS_64) + case SLJIT_MOV32: + case SLJIT_MOV_S32: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xffe00000) == LUI && (inst[1] & 0xfc000000) == ORI); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; +#endif /* SLJIT_CONFIG_MIPS_64 */ + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } +} diff --git a/deps/sljit/sljit_src/sljitNativePPC_32.c b/deps/sljit/sljit_src/sljitNativePPC_32.c index 2352fad..c07f4b4 100644 --- a/deps/sljit/sljit_src/sljitNativePPC_32.c +++ b/deps/sljit/sljit_src/sljitNativePPC_32.c @@ -477,8 +477,8 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); SLJIT_ASSERT((inst[0] & 0xfc1f0000) == ADDIS && (inst[1] & 0xfc000000) == ORI); - inst[0] = (inst[0] & 0xffff0000) | ((new_target >> 16) & 0xffff); - inst[1] = (inst[1] & 0xffff0000) | (new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_target >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 2); diff --git a/deps/sljit/sljit_src/sljitNativePPC_64.c b/deps/sljit/sljit_src/sljitNativePPC_64.c index b3cf9d0..2b07fcb 100644 --- a/deps/sljit/sljit_src/sljitNativePPC_64.c +++ b/deps/sljit/sljit_src/sljitNativePPC_64.c @@ -709,10 +709,10 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UNUSED_ARG(executable_offset); SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 0); - inst[0] = (inst[0] & 0xffff0000u) | ((sljit_ins)(new_target >> 48) & 0xffff); - inst[1] = (inst[1] & 0xffff0000u) | ((sljit_ins)(new_target >> 32) & 0xffff); - inst[3] = (inst[3] & 0xffff0000u) | ((sljit_ins)(new_target >> 16) & 0xffff); - inst[4] = (inst[4] & 0xffff0000u) | ((sljit_ins)new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000u) | IMM(new_target >> 48); + inst[1] = (inst[1] & 0xffff0000u) | IMM(new_target >> 32); + inst[3] = (inst[3] & 0xffff0000u) | IMM(new_target >> 16); + inst[4] = (inst[4] & 0xffff0000u) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 5); diff --git a/deps/sljit/sljit_src/sljitNativePPC_common.c b/deps/sljit/sljit_src/sljitNativePPC_common.c index 3d2268e..07df86f 100644 --- a/deps/sljit/sljit_src/sljitNativePPC_common.c +++ b/deps/sljit/sljit_src/sljitNativePPC_common.c @@ -113,7 +113,7 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 3] = { }; /* --------------------------------------------------------------------- */ -/* Instrucion forms */ +/* Instruction forms */ /* --------------------------------------------------------------------- */ #define D(d) ((sljit_ins)reg_map[d] << 21) #define S(s) ((sljit_ins)reg_map[s] << 21) @@ -504,6 +504,12 @@ static void generate_jump_or_mov_addr(struct sljit_jump *jump, sljit_sw executab #endif /* SLJIT_CONFIG_PPC_32 */ } +static SLJIT_INLINE sljit_ins *process_extended_label(sljit_ins *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_ins*)((sljit_uw)code_ptr & ~(ext_label->data)); +} + static void reduce_code_size(struct sljit_compiler *compiler) { struct sljit_label *label; @@ -619,18 +625,20 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reduce_code_size(compiler); #if (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) + if (!(options & SLJIT_GENERATE_CODE_NO_CONTEXT)) { /* add to compiler->size additional instruction space to hold the trampoline and padding */ #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - compiler->size += (compiler->size & 0x1) + (sizeof(struct sljit_function_context) / sizeof(sljit_ins)); -#else - compiler->size += (sizeof(struct sljit_function_context) / sizeof(sljit_ins)); -#endif -#endif + compiler->size += (compiler->size & 0x1) + (sizeof(struct sljit_function_context) / sizeof(sljit_ins)); +#else /* !SLJIT_CONFIG_PPC_64 */ + compiler->size += (sizeof(struct sljit_function_context) / sizeof(sljit_ins)); +#endif /* SLJIT_CONFIG_PPC_64 */ + } +#endif /* SLJIT_INDIRECT_CALL */ code = (sljit_ins*)allocate_executable_memory(compiler->size * sizeof(sljit_ins), options, exec_allocator_data, &executable_offset); PTR_FAIL_WITH_EXEC_IF(code); @@ -657,6 +665,11 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil /* These structures are ordered by their address. */ if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + *code_ptr = buf_ptr[-1]; + } + /* Just recording the address. */ label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); @@ -700,6 +713,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } while (buf); if (label && label->size == word_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -710,7 +726,8 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_ASSERT(!const_); #if (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) - SLJIT_ASSERT(code_ptr - code <= (sljit_sw)(compiler->size - (sizeof(struct sljit_function_context) / sizeof(sljit_ins)))); + SLJIT_ASSERT(code_ptr - code <= (sljit_sw)(compiler->size - + ((options & SLJIT_GENERATE_CODE_NO_CONTEXT) ? 0 : (sizeof(struct sljit_function_context) / sizeof(sljit_ins))))); #else SLJIT_ASSERT(code_ptr - code <= (sljit_sw)compiler->size); #endif @@ -727,12 +744,14 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil code = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(code, executable_offset); #if (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) + if (!(options & SLJIT_GENERATE_CODE_NO_CONTEXT)) { #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) - if (((sljit_sw)code_ptr) & 0x4) - code_ptr++; -#endif - sljit_set_function_context(NULL, (struct sljit_function_context*)code_ptr, (sljit_uw)code, (void*)sljit_generate_code); -#endif + if (((sljit_sw)code_ptr) & 0x4) + code_ptr++; +#endif /* SLJIT_CONFIG_PPC_64 */ + sljit_set_function_context(NULL, (struct sljit_function_context*)code_ptr, (sljit_uw)code, (void*)sljit_generate_code); + } +#endif /* SLJIT_INDIRECT_CALL */ code_ptr = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); @@ -740,12 +759,14 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_UPDATE_WX_FLAGS(code, code_ptr, 1); #if (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) - compiler->executable_size = (sljit_uw)(code_ptr - code) * sizeof(sljit_ins) + sizeof(struct sljit_function_context); - return code_ptr; -#else + if (!(options & SLJIT_GENERATE_CODE_NO_CONTEXT)) { + compiler->executable_size = (sljit_uw)(code_ptr - code) * sizeof(sljit_ins) + sizeof(struct sljit_function_context); + return code_ptr; + } +#endif /* SLJIT_INDIRECT_CALL */ + compiler->executable_size = (sljit_uw)(code_ptr - code) * sizeof(sljit_ins); return code; -#endif } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) @@ -1683,7 +1704,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) op |= SLJIT_32; #endif /* SLJIT_CONFIG_PPC_64 */ - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_REV: case SLJIT_REV_U16: case SLJIT_REV_S16: @@ -1925,7 +1946,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile if (src1 == SLJIT_IMM && src1w == -1) { return emit_op(compiler, GET_OPCODE(op), flags | ALT_FORM4, dst, dstw, TMP_REG1, 0, src2, src2w); } - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_AND: case SLJIT_OR: /* Commutative unsigned operations. */ @@ -2103,6 +2124,56 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst(compiler, OR | S(dst_reg) | A(dst_reg) | B(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r, tmp_r; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= (sljit_sw)((sizeof(sljit_sw) * 8) - 1); + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, TMP_REG1, src1w)); + src1 = TMP_REG1; + } else if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, src1, src1w, TMP_REG1)); + src1 = TMP_REG1; + } + + tmp_r = (src1 == TMP_REG1) ? TMP_REG2 : TMP_REG1; + + if (src2 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, tmp_r, src2, src2w, tmp_r)); + src2 = tmp_r; + } + + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + FAIL_IF(push_inst(compiler, SLWI_W(shift_arg) | S(src2) | A(tmp_r))); + FAIL_IF(push_inst(compiler, ADD | D(dst_r) | A(src1) | B(tmp_r))); + + if (dst & SLJIT_MEM) + return emit_op_mem(compiler, WORD_DATA, dst_r, dst, dstw, TMP_REG1); + return SLJIT_SUCCESS; +} + static sljit_s32 emit_prefetch(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw) { @@ -2322,7 +2393,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compil FAIL_IF(push_inst(compiler, FRSP | FD(dst_r) | FB(src))); break; } - /* Fall through. */ + SLJIT_FALLTHROUGH case SLJIT_MOV_F64: if (src != dst_r) { if (!(dst & SLJIT_MEM)) @@ -2447,13 +2518,67 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, i; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (alignment <= SLJIT_LABEL_ALIGN_4) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_ins); + + for (i = (mask >> 2); i != 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + for (i = (buffers->size + 3) >> 2; i > 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + static sljit_ins get_bo_bi_flags(struct sljit_compiler *compiler, sljit_s32 type) { switch (type) { case SLJIT_NOT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_SUB) return (4 << 21) | (2 << 16); - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_EQUAL: case SLJIT_ATOMIC_STORED: @@ -2462,7 +2587,7 @@ static sljit_ins get_bo_bi_flags(struct sljit_compiler *compiler, sljit_s32 type case SLJIT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_SUB) return (12 << 21) | (2 << 16); - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_NOT_EQUAL: case SLJIT_ATOMIC_NOT_STORED: @@ -2835,6 +2960,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp { sljit_ins *ptr; sljit_uw size; + sljit_s32 is_compare = (type & SLJIT_COMPARE_SELECT); + sljit_ins ins; #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) sljit_s32 inp_flags = ((type & SLJIT_32) ? INT_DATA : WORD_DATA) | LOAD_DATA; #else /* !SLJIT_CONFIG_PPC_64 */ @@ -2846,6 +2973,45 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp ADJUST_LOCAL_OFFSET(src1, src1w); +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + if (src1 == SLJIT_IMM && (type & SLJIT_32)) + src1w = (sljit_s32)src1w; +#endif /* SLJIT_CONFIG_PPC_64 */ + + type &= ~(SLJIT_32 | SLJIT_COMPARE_SELECT); + + if (is_compare) { + ins = 0; + + if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, inp_flags, TMP_REG1, src1, src1w, TMP_REG1)); + src1 = TMP_REG1; + src1w = 0; + } + + if (src1 == SLJIT_IMM) { + if (type >= SLJIT_LESS && type <= SLJIT_LESS_EQUAL && src1w >= 0 && src1w <= UIMM_MAX) + ins = CMPLI | CRD(0) | IMM(src1w); + else if (type >= SLJIT_SIG_LESS && type <= SLJIT_SIG_LESS_EQUAL && src1w >= SIMM_MIN && src1w <= SIMM_MAX) + ins = CMPI | CRD(0) | IMM(src1w); + else { + FAIL_IF(load_immediate(compiler, TMP_REG1, src1w)); + src1 = TMP_REG1; + src1w = 0; + } + } + + if (ins == 0) + ins = ((type >= SLJIT_LESS && type <= SLJIT_LESS_EQUAL) ? CMPL : CMP) | CRD(0) | B(src1); + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + if (inp_flags == (WORD_DATA | LOAD_DATA)) + ins |= CRD(1); +#endif /* SLJIT_CONFIG_PPC_64 */ + FAIL_IF(push_inst(compiler, ins | A(src2_reg))); + type ^= 0x1; + } + if (dst_reg != src2_reg) { if (dst_reg == src1) { src1 = src2_reg; @@ -2866,7 +3032,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp } } - if (((type & ~SLJIT_32) | 0x1) == SLJIT_NOT_CARRY) + if ((type | 0x1) == SLJIT_NOT_CARRY) FAIL_IF(push_inst(compiler, ADDE | RC(ALT_SET_FLAGS) | D(TMP_REG1) | A(TMP_ZERO) | B(TMP_ZERO))); size = compiler->size; @@ -2878,15 +3044,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp if (src1 & SLJIT_MEM) { FAIL_IF(emit_op_mem(compiler, inp_flags, dst_reg, src1, src1w, TMP_REG1)); } else if (src1 == SLJIT_IMM) { -#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) - if (type & SLJIT_32) - src1w = (sljit_s32)src1w; -#endif /* SLJIT_CONFIG_RISCV_64 */ FAIL_IF(load_immediate(compiler, dst_reg, src1w)); } else FAIL_IF(push_inst(compiler, OR | S(src1) | A(dst_reg) | B(src1))); - *ptr = BCx | get_bo_bi_flags(compiler, (type ^ 0x1) & ~SLJIT_32) | (sljit_ins)((compiler->size - size) << 2); + *ptr = BCx | get_bo_bi_flags(compiler, type ^ 0x1) | (sljit_ins)((compiler->size - size) << 2); return SLJIT_SUCCESS; } @@ -3162,7 +3324,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_load(struct sljit_compiler #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) ins = LDARX; break; -#endif /* SLJIT_CONFIG_RISCV_64 */ +#endif /* SLJIT_CONFIG_PPC_64 */ case SLJIT_MOV_U32: case SLJIT_MOV32: ins = LWARX; @@ -3200,7 +3362,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) ins = STDCX | 0x1; break; -#endif /* SLJIT_CONFIG_RISCV_64 */ +#endif /* SLJIT_CONFIG_PPC_64 */ case SLJIT_MOV_U32: case SLJIT_MOV32: ins = STWCX | 0x1; @@ -3216,13 +3378,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return push_inst(compiler, ins | D(src_reg) | B(mem_reg)); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_DATA; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -3230,42 +3395,119 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xff00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, ADDI | D(dst_r) | A(0) | IMM(init_value))); + mem_flags = BYTE_DATA; + break; + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + case SLJIT_MOV32: + mem_flags = INT_DATA; + SLJIT_FALLTHROUGH + case SLJIT_MOV_S32: + PTR_FAIL_IF(push_inst(compiler, ADDIS | D(dst_r) | A(0) | IMM(init_value >> 16))); + PTR_FAIL_IF(push_inst(compiler, ORI | S(dst_r) | A(dst_r) | IMM(init_value))); + break; +#endif /* SLJIT_CONFIG_PPC_64 */ + + default: + PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, dst_r, dst, dstw, TMP_REG1)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, dst_r, dst, dstw, TMP_REG1)); return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_s32 dst_r; + sljit_s32 dst_r, target_r; + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = TMP_REG1; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, dst_r, dst, dstw, TMP_REG1)); + } + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); PTR_FAIL_IF(!jump); set_mov_addr(jump, compiler, 0); - dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(push_inst(compiler, (sljit_ins)dst_r)); + PTR_FAIL_IF(push_inst(compiler, (sljit_ins)target_r)); #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) compiler->size++; #else compiler->size += 4; #endif + if (op == SLJIT_ADD_ABS_ADDR) + PTR_FAIL_IF(push_inst(compiler, ADD | D(dst_r) | A(dst_r) | B(TMP_REG1))); + if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, dst, dstw, TMP_REG1, 0, TMP_REG2, 0)); + PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, dst_r, dst, dstw, TMP_REG1)); return jump; } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_ins *inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xfc1f0000) == ADDI); + + if (new_constant & 0x100) + new_constant |= 0xff00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); + return; + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + case SLJIT_MOV32: + case SLJIT_MOV_S32: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xfc1f0000) == ADDIS && (inst[1] & 0xfc000000) == ORI); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; +#endif /* SLJIT_CONFIG_PPC_64 */ + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } } diff --git a/deps/sljit/sljit_src/sljitNativeRISCV_32.c b/deps/sljit/sljit_src/sljitNativeRISCV_32.c index 396c956..e2dfb01 100644 --- a/deps/sljit/sljit_src/sljitNativeRISCV_32.c +++ b/deps/sljit/sljit_src/sljitNativeRISCV_32.c @@ -28,17 +28,28 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r { SLJIT_UNUSED_ARG(tmp_r); + if (RISCV_HAS_COMPRESSED(200) && imm <= SIMM16_MAX && imm >= SIMM16_MIN) + return push_inst16(compiler, C_LI | C_RD(dst_r) | C_IMM_I(imm)); + if (imm <= SIMM_MAX && imm >= SIMM_MIN) return push_inst(compiler, ADDI | RD(dst_r) | RS1(TMP_ZERO) | IMM_I(imm)); if (imm & 0x800) imm += 0x1000; - FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~0xfff))); + if (RISCV_HAS_COMPRESSED(200) && imm <= 0x1ffff && imm >= -0x20000) + FAIL_IF(push_inst16(compiler, C_LUI | C_RD(dst_r) | ((sljit_u16)(((imm) & 0x1f000) >> 10) | ((imm) & 0x20000) >> 5))); + else + FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~(sljit_sw)0xfff))); + + imm &= 0xfff; - if ((imm & 0xfff) == 0) + if (imm == 0) return SLJIT_SUCCESS; + if (RISCV_HAS_COMPRESSED(200) && (imm <= 0x1f || imm >= 0xfe0)) + return push_inst16(compiler, C_ADDI | C_RD(dst_r) | C_IMM_I(imm)); + return push_inst(compiler, ADDI | RD(dst_r) | RS1(dst_r) | IMM_I(imm)); } @@ -123,20 +134,21 @@ static SLJIT_INLINE sljit_s32 emit_const(struct sljit_compiler *compiler, sljit_ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset) { - sljit_ins *inst = (sljit_ins*)addr; + sljit_u16 *inst = (sljit_u16*)addr; SLJIT_UNUSED_ARG(executable_offset); if ((new_target & 0x800) != 0) new_target += 0x1000; - SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 0); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 4, 0); SLJIT_ASSERT((inst[0] & 0x7f) == LUI); - inst[0] = (inst[0] & 0xfff) | (sljit_ins)((sljit_sw)new_target & ~0xfff); - SLJIT_ASSERT((inst[1] & 0x707f) == ADDI || (inst[1] & 0x707f) == JALR); - inst[1] = (inst[1] & 0xfffff) | IMM_I(new_target); - - SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 1); - inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); - SLJIT_CACHE_FLUSH(inst, inst + 5); + inst[0] = (sljit_u16)((inst[0] & 0xfff) | (new_target & 0xf000)); + inst[1] = (sljit_u16)(new_target >> 16); + SLJIT_ASSERT((inst[2] & 0x707f) == ADDI || (inst[2] & 0x707f) == JALR); + inst[3] = (sljit_u16)((inst[3] & 0xf) | (new_target << 4)); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 4, 1); + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 4); } diff --git a/deps/sljit/sljit_src/sljitNativeRISCV_64.c b/deps/sljit/sljit_src/sljitNativeRISCV_64.c index 7fcf2c5..113d1f8 100644 --- a/deps/sljit/sljit_src/sljitNativeRISCV_64.c +++ b/deps/sljit/sljit_src/sljitNativeRISCV_64.c @@ -24,29 +24,88 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r, sljit_sw imm, sljit_s32 tmp_r) +static sljit_s32 load_immediate32(struct sljit_compiler *compiler, sljit_s32 dst_r, sljit_sw imm) { - sljit_sw high; + SLJIT_ASSERT((imm <= 0x7fffffffl && imm > SIMM_MAX) || (imm >= S32_MIN && imm < SIMM_MIN)); - if (imm <= SIMM_MAX && imm >= SIMM_MIN) - return push_inst(compiler, ADDI | RD(dst_r) | RS1(TMP_ZERO) | IMM_I(imm)); + if (imm > S32_MAX) { + SLJIT_ASSERT((imm & 0x800) != 0); + FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)0x80000000u)); + return push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(imm)); + } - if (imm <= 0x7fffffffl && imm >= S32_MIN) { - if (imm > S32_MAX) { + if (RISCV_HAS_COMPRESSED(200) && imm <= 0x1ffff && imm >= -0x20000) { + if (imm > 0x1f7ff) { SLJIT_ASSERT((imm & 0x800) != 0); - FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)0x80000000u)); + FAIL_IF(push_inst16(compiler, C_LUI | C_RD(dst_r) | (sljit_u16)0x1000)); return push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(imm)); } if ((imm & 0x800) != 0) imm += 0x1000; - FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~0xfff))); + FAIL_IF(push_inst16(compiler, C_LUI | C_RD(dst_r) | ((sljit_u16)(((imm) & 0x1f000) >> 10) | ((imm) & 0x20000) >> 5))); + } else { + if ((imm & 0x800) != 0) + imm += 0x1000; + + FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~(sljit_sw)0xfff))); + } + + imm &= 0xfff; + + if (imm == 0) + return SLJIT_SUCCESS; + + if (RISCV_HAS_COMPRESSED(200) && (imm <= 0x1f || imm >= 0xfe0)) + return push_inst16(compiler, C_ADDI | C_RD(dst_r) | C_IMM_I(imm)); + + return push_inst(compiler, ADDI | RD(dst_r) | RS1(dst_r) | IMM_I(imm)); +} + +static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r, sljit_sw imm, sljit_s32 tmp_r) +{ + sljit_sw high, shift; + + if (RISCV_HAS_COMPRESSED(200) && imm <= SIMM16_MAX && imm >= SIMM16_MIN) + return push_inst16(compiler, C_LI | C_RD(dst_r) | C_IMM_I(imm)); - if ((imm & 0xfff) == 0) - return SLJIT_SUCCESS; + if (imm <= SIMM_MAX && imm >= SIMM_MIN) + return push_inst(compiler, ADDI | RD(dst_r) | RS1(TMP_ZERO) | IMM_I(imm)); + + if (imm <= 0x7fffffffl && imm >= S32_MIN) + return load_immediate32(compiler, dst_r, imm); + + /* Shifted small immediates. */ + + high = imm; + shift = 0; + while ((high & 0xff) == 0) { + high >>= 8; + shift += 8; + } + + if ((high & 0xf) == 0) { + high >>= 4; + shift += 4; + } + + if ((high & 0x3) == 0) { + high >>= 2; + shift += 2; + } + + if ((high & 0x1) == 0) { + high >>= 1; + shift += 1; + } + + if (high <= 0x7fffffffl && high >= S32_MIN) { + load_immediate(compiler, dst_r, high, tmp_r); - return push_inst(compiler, ADDI | RD(dst_r) | RS1(dst_r) | IMM_I(imm)); + if (RISCV_HAS_COMPRESSED(200)) + return push_inst16(compiler, C_SLLI | C_RD(dst_r) | C_IMM_I(shift)); + return push_inst(compiler, SLLI | RD(dst_r) | RS1(dst_r) | IMM_I(shift)); } /* Trailing zeroes could be used to produce shifted immediates. */ @@ -57,26 +116,15 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r if (imm & 0x800) high = ~high; - if (high > S32_MAX) { - SLJIT_ASSERT((high & 0x800) != 0); - FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)0x80000000u)); - FAIL_IF(push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(high))); - } else { - if ((high & 0x800) != 0) - high += 0x1000; - - FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(high & ~0xfff))); + FAIL_IF(load_immediate32(compiler, dst_r, high)); - if ((high & 0xfff) != 0) - FAIL_IF(push_inst(compiler, ADDI | RD(dst_r) | RS1(dst_r) | IMM_I(high))); - } - - FAIL_IF(push_inst(compiler, SLLI | RD(dst_r) | RS1(dst_r) | IMM_I(12))); + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_SLLI | C_RD(dst_r) | (sljit_u16)(12 << 2))); + else + FAIL_IF(push_inst(compiler, SLLI | RD(dst_r) | RS1(dst_r) | IMM_I(12))); - if ((imm & 0xfff) != 0) - return push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(imm)); - - return SLJIT_SUCCESS; + SLJIT_ASSERT((imm & 0xfff) != 0); + return push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(imm)); } SLJIT_ASSERT(dst_r != tmp_r); @@ -99,7 +147,10 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r } if (imm <= SIMM_MAX && imm >= SIMM_MIN) { - FAIL_IF(push_inst(compiler, ADDI | RD(dst_r) | RS1(TMP_ZERO) | IMM_I(imm))); + if (RISCV_HAS_COMPRESSED(200) && imm <= 0x1f && imm >= -0x20) + FAIL_IF(push_inst16(compiler, C_LI | C_RD(dst_r) | C_IMM_I(imm))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(dst_r) | RS1(TMP_ZERO) | IMM_I(imm))); imm = 0; } else if (imm > S32_MAX) { SLJIT_ASSERT((imm & 0x800) != 0); @@ -110,19 +161,35 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r if ((imm & 0x800) != 0) imm += 0x1000; - FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~0xfff))); + if (RISCV_HAS_COMPRESSED(200) && imm <= 0x1ffff && imm >= -0x20000) + FAIL_IF(push_inst16(compiler, C_LUI | C_RD(dst_r) | ((sljit_u16)(((imm) & 0x1f000) >> 10) | ((imm) & 0x20000) >> 5))); + else + FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~0xfff))); imm &= 0xfff; } - if ((high & 0xfff) != 0) - FAIL_IF(push_inst(compiler, ADDI | RD(tmp_r) | RS1(tmp_r) | IMM_I(high))); + if ((high & 0xfff) != 0) { + SLJIT_ASSERT(high <= 0xfff); + if (RISCV_HAS_COMPRESSED(200) && (high <= 0x1f || high >= 0xfe0)) + FAIL_IF(push_inst16(compiler, C_ADDI | C_RD(tmp_r) | C_IMM_I(high))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(tmp_r) | RS1(tmp_r) | IMM_I(high))); + } if (imm & 0x1000) FAIL_IF(push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(imm))); - else if (imm != 0) - FAIL_IF(push_inst(compiler, ADDI | RD(dst_r) | RS1(dst_r) | IMM_I(imm))); + else if (imm != 0) { + SLJIT_ASSERT(imm <= 0xfff); + if (RISCV_HAS_COMPRESSED(200) && (imm <= 0x1f || imm >= 0xfe0)) + FAIL_IF(push_inst16(compiler, C_ADDI | C_RD(dst_r) | C_IMM_I(imm))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(dst_r) | RS1(dst_r) | IMM_I(imm))); + } - FAIL_IF(push_inst(compiler, SLLI | RD(tmp_r) | RS1(tmp_r) | IMM_I((high & 0x1000) ? 20 : 32))); + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_SLLI | C_RD(tmp_r) | (sljit_u16)((high & 0x1000) ? (20 << 2) : (1 << 12)))); + else + FAIL_IF(push_inst(compiler, SLLI | RD(tmp_r) | RS1(tmp_r) | IMM_I((high & 0x1000) ? 20 : 32))); return push_inst(compiler, XOR | RD(dst_r) | RS1(dst_r) | RS2(tmp_r)); } @@ -190,7 +257,7 @@ static SLJIT_INLINE sljit_s32 emit_const(struct sljit_compiler *compiler, sljit_ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset) { - sljit_ins *inst = (sljit_ins*)addr; + sljit_u16 *inst = (sljit_u16*)addr; sljit_sw high; SLJIT_UNUSED_ARG(executable_offset); @@ -205,18 +272,20 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta if ((high & 0x800) != 0) high += 0x1000; - SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 0); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 12, 0); SLJIT_ASSERT((inst[0] & 0x7f) == LUI); - inst[0] = (inst[0] & 0xfff) | (sljit_ins)(high & ~0xfff); - SLJIT_ASSERT((inst[1] & 0x707f) == ADDI); - inst[1] = (inst[1] & 0xfffff) | IMM_I(high); - SLJIT_ASSERT((inst[2] & 0x7f) == LUI); - inst[2] = (inst[2] & 0xfff) | (sljit_ins)((sljit_sw)new_target & ~0xfff); - SLJIT_ASSERT((inst[5] & 0x707f) == ADDI || (inst[5] & 0x707f) == JALR); - inst[5] = (inst[5] & 0xfffff) | IMM_I(new_target); - SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 1); - - inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); - SLJIT_CACHE_FLUSH(inst, inst + 5); + inst[0] = (sljit_u16)((inst[0] & 0xfff) | (high & 0xf000)); + inst[1] = (sljit_u16)(high >> 16); + SLJIT_ASSERT((inst[2] & 0x707f) == ADDI); + inst[3] = (sljit_u16)((inst[3] & 0xf) | (high << 4)); + SLJIT_ASSERT((inst[4] & 0x7f) == LUI); + inst[4] = (sljit_u16)((inst[4] & 0xfff) | (new_target & 0xf000)); + inst[5] = (sljit_u16)(new_target >> 16); + SLJIT_ASSERT((inst[10] & 0x707f) == ADDI || (inst[10] & 0x707f) == JALR); + inst[11] = (sljit_u16)((inst[11] & 0xf) | (new_target << 4)); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 12, 1); + + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 12); } diff --git a/deps/sljit/sljit_src/sljitNativeRISCV_common.c b/deps/sljit/sljit_src/sljitNativeRISCV_common.c index d3ba46d..dec12c9 100644 --- a/deps/sljit/sljit_src/sljitNativeRISCV_common.c +++ b/deps/sljit/sljit_src/sljitNativeRISCV_common.c @@ -24,17 +24,148 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#if !(defined SLJIT_CONFIG_RISCV_ATOMIC) && defined(__riscv_atomic) +/* Auto detect atomic instruction support. */ +#define SLJIT_CONFIG_RISCV_ATOMIC 200 +#endif /* !SLJIT_CONFIG_RISCV_ATOMIC && __riscv_atomic */ + +/* SLJIT_CONFIG_RISCV_ATOMIC enables/disables atomic instruction + support. Non-zero values represents the highest version of the feature + that is supported by the CPU. + Allowed values: 0 - disabled, 200 - 2.00 */ +#if (defined SLJIT_CONFIG_RISCV_ATOMIC && SLJIT_CONFIG_RISCV_ATOMIC != 0) +#if SLJIT_CONFIG_RISCV_ATOMIC != 200 +#error "Unsupported value for SLJIT_CONFIG_RISCV_ATOMIC" +#endif +#define RISCV_HAS_ATOMIC(x) ((SLJIT_CONFIG_RISCV_ATOMIC) >= (x)) +#define RISCV_ATOMIC_INFO "a" +#else /* !SLJIT_CONFIG_RISCV_ATOMIC || SLJIT_CONFIG_RISCV_ATOMIC == 0 */ +#define RISCV_HAS_ATOMIC(x) 0 +#define RISCV_ATOMIC_INFO "" +#endif /* SLJIT_CONFIG_RISCV_ATOMIC && SLJIT_CONFIG_RISCV_ATOMIC != 0 */ + +#if !(defined SLJIT_CONFIG_RISCV_COMPRESSED) && defined(__riscv_compressed) +/* Auto detect compressed instruction support. */ +#define SLJIT_CONFIG_RISCV_COMPRESSED 200 +#endif /* !SLJIT_CONFIG_RISCV_COMPRESSED && __riscv_compressed */ + +/* SLJIT_CONFIG_RISCV_COMPRESSED enables/disables compressed instruction + support. Non-zero values represents the highest version of the feature + that is supported by the CPU. + Allowed values: 0 - disabled, 200 - 2.00 */ +#if (defined SLJIT_CONFIG_RISCV_COMPRESSED && SLJIT_CONFIG_RISCV_COMPRESSED != 0) +#if SLJIT_CONFIG_RISCV_COMPRESSED != 200 +#error "Unsupported value for SLJIT_CONFIG_RISCV_COMPRESSED" +#endif +#define RISCV_HAS_COMPRESSED(x) ((SLJIT_CONFIG_RISCV_COMPRESSED) >= (x)) +#define RISCV_COMPRESSED_CHECK(x) (x) +#define RISCV_COMPRESSED_INFO "c" +#else /* !SLJIT_CONFIG_RISCV_COMPRESSED || SLJIT_CONFIG_RISCV_COMPRESSED == 0 */ +#define RISCV_HAS_COMPRESSED(x) 0 +#define RISCV_COMPRESSED_CHECK(x) 0 +#define RISCV_COMPRESSED_INFO "" +#endif /* SLJIT_CONFIG_RISCV_COMPRESSED && SLJIT_CONFIG_RISCV_COMPRESSED != 0 */ + +#if !(defined SLJIT_CONFIG_RISCV_VECTOR) && defined(__riscv_vector) +/* Auto detect vector instruction support. */ +#define SLJIT_CONFIG_RISCV_VECTOR 100 +#endif /* !SLJIT_CONFIG_RISCV_VECTOR && __riscv_vector */ + +/* SLJIT_CONFIG_RISCV_VECTOR enables/disables vector instruction + support. Non-zero values represents the highest version of the feature + that is supported by the CPU. + Allowed values: 0 - disabled, 100 - 1.00 */ +#if (defined SLJIT_CONFIG_RISCV_VECTOR && SLJIT_CONFIG_RISCV_VECTOR != 0) +#if SLJIT_CONFIG_RISCV_VECTOR != 100 +#error "Unsupported value for SLJIT_CONFIG_RISCV_VECTOR" +#endif +#define RISCV_HAS_VECTOR(x) ((SLJIT_CONFIG_RISCV_VECTOR) >= (x)) +#define RISCV_VECTOR_INFO "v" +#else /* !SLJIT_CONFIG_RISCV_VECTOR || SLJIT_CONFIG_RISCV_VECTOR == 0 */ +#define RISCV_HAS_VECTOR(x) 0 +#define RISCV_VECTOR_INFO "" +#endif /* SLJIT_CONFIG_RISCV_VECTOR && SLJIT_CONFIG_RISCV_VECTOR != 0 */ + +#if !(defined SLJIT_CONFIG_RISCV_BITMANIP_A) && defined(__riscv_zba) +/* Auto detect bit manipulation extension A instruction support. */ +#define SLJIT_CONFIG_RISCV_BITMANIP_A 93 +#endif /* !SLJIT_CONFIG_RISCV_BITMANIP_A && __riscv_zba */ + +/* SLJIT_CONFIG_RISCV_BITMANIP_A enables/disables bit manipulation extension A + instruction support. Non-zero values represents the highest version of the + feature that is supported by the CPU. + Allowed values: 0 - disabled, 93 - 0.93 */ +#if (defined SLJIT_CONFIG_RISCV_BITMANIP_A && SLJIT_CONFIG_RISCV_BITMANIP_A != 0) +#if SLJIT_CONFIG_RISCV_BITMANIP_A != 93 +#error "Unsupported value for SLJIT_CONFIG_RISCV_BITMANIP_A" +#endif +#define RISCV_HAS_BITMANIP_A(x) ((SLJIT_CONFIG_RISCV_BITMANIP_A) >= (x)) +#define RISCV_BITMANIP_A_INFO "_zba" +#else /* !SLJIT_CONFIG_RISCV_BITMANIP_A || SLJIT_CONFIG_RISCV_BITMANIP_A == 0 */ +#define RISCV_HAS_BITMANIP_A(x) 0 +#define RISCV_BITMANIP_A_INFO "" +#endif /* SLJIT_CONFIG_RISCV_BITMANIP_A && SLJIT_CONFIG_RISCV_BITMANIP_A != 0 */ + +#if !(defined SLJIT_CONFIG_RISCV_BITMANIP_B) && defined(__riscv_zbb) +/* Auto detect bit manipulation extension B instruction support. */ +#define SLJIT_CONFIG_RISCV_BITMANIP_B 93 +#endif /* !SLJIT_CONFIG_RISCV_BITMANIP_B && __riscv_zbb */ + +/* SLJIT_CONFIG_RISCV_BITMANIP_B enables/disables bit manipulation extension B + instruction support. Non-zero values represents the highest version of the + feature that is supported by the CPU. + Allowed values: 0 - disabled, 93 - 0.93 */ +#if (defined SLJIT_CONFIG_RISCV_BITMANIP_B && SLJIT_CONFIG_RISCV_BITMANIP_B != 0) +#if SLJIT_CONFIG_RISCV_BITMANIP_B != 93 +#error "Unsupported value for SLJIT_CONFIG_RISCV_BITMANIP_B" +#endif +#define RISCV_HAS_BITMANIP_B(x) ((SLJIT_CONFIG_RISCV_BITMANIP_B) >= (x)) +#define RISCV_BITMANIP_B_INFO "_zbb" +#else /* !SLJIT_CONFIG_RISCV_BITMANIP_B || SLJIT_CONFIG_RISCV_BITMANIP_B == 0 */ +#define RISCV_HAS_BITMANIP_B(x) 0 +#define RISCV_BITMANIP_B_INFO "" +#endif /* SLJIT_CONFIG_RISCV_BITMANIP_B && SLJIT_CONFIG_RISCV_BITMANIP_B != 0 */ + +#if !(defined SLJIT_CONFIG_RISCV_ICOND) && defined(__riscv_zicond) +/* Auto detect integer conditional instruction support. */ +#define SLJIT_CONFIG_RISCV_ICOND 100 +#endif /* !SLJIT_CONFIG_RISCV_ICOND && __riscv_zicond */ + +/* SLJIT_CONFIG_RISCV_ICOND enables/disables integer conditional + instruction support. Non-zero values represents the highest version of the + feature that is supported by the CPU. + Allowed values: 0 - disabled, 100 - 1.00 */ +#if (defined SLJIT_CONFIG_RISCV_ICOND && SLJIT_CONFIG_RISCV_ICOND != 0) +#if SLJIT_CONFIG_RISCV_ICOND != 100 +#error "Unsupported value for SLJIT_CONFIG_RISCV_ICOND" +#endif +#define RISCV_HAS_ICOND(x) ((SLJIT_CONFIG_RISCV_ICOND) >= (x)) +#define RISCV_ICOND_INFO "_zicond" +#else /* !SLJIT_CONFIG_RISCV_ICOND || SLJIT_CONFIG_RISCV_ICOND == 0 */ +#define RISCV_HAS_ICOND(x) 0 +#define RISCV_ICOND_INFO "" +#endif /* SLJIT_CONFIG_RISCV_ICOND && SLJIT_CONFIG_RISCV_ICOND != 0 */ + +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) +#define RISCV_CHECK_COMPRESSED_JUMP(jump, diff, unit) \ + (!((jump)->flags & IS_CALL) && (diff) >= (JUMP16_MIN / SSIZE_OF(unit)) && (diff) <= (JUMP16_MAX / SSIZE_OF(unit))) +#else /* !SLJIT_CONFIG_RISCV_64 */ +#define RISCV_CHECK_COMPRESSED_JUMP(jump, diff, unit) \ + ((diff) >= (JUMP16_MIN / SSIZE_OF(unit)) && (diff) <= (JUMP16_MAX / SSIZE_OF(unit))) +#endif /* SLJIT_CONFIG_RISCV_64 */ + SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void) { + /* The arch string is not entirely correct since 'g' contains 'a'. */ #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) - return "RISC-V-32" SLJIT_CPUINFO; + return "RISC-V-32 (rv32g" RISCV_ATOMIC_INFO RISCV_COMPRESSED_INFO RISCV_VECTOR_INFO RISCV_BITMANIP_A_INFO RISCV_BITMANIP_B_INFO RISCV_ICOND_INFO ")" SLJIT_CPUINFO; #else /* !SLJIT_CONFIG_RISCV_32 */ - return "RISC-V-64" SLJIT_CPUINFO; + return "RISC-V-64 (rv64g" RISCV_ATOMIC_INFO RISCV_COMPRESSED_INFO RISCV_VECTOR_INFO RISCV_BITMANIP_A_INFO RISCV_BITMANIP_B_INFO RISCV_ICOND_INFO ")" SLJIT_CPUINFO; #endif /* SLJIT_CONFIG_RISCV_32 */ } -/* Length of an instruction word - Both for riscv-32 and riscv-64 */ +/* Most instructions are 32 bit long on RISCV. + Code is processed as 16 bit units. */ typedef sljit_u32 sljit_ins; #define TMP_REG1 (SLJIT_NUMBER_OF_REGISTERS + 2) @@ -66,7 +197,7 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { }; /* --------------------------------------------------------------------- */ -/* Instrucion forms */ +/* Instruction forms */ /* --------------------------------------------------------------------- */ #define RD(rd) ((sljit_ins)reg_map[rd] << 7) @@ -80,9 +211,28 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define VRS2(rs2) ((sljit_ins)vreg_map[rs2] << 20) #define IMM_I(imm) ((sljit_ins)(imm) << 20) #define IMM_S(imm) ((((sljit_ins)(imm) & 0xfe0) << 20) | (((sljit_ins)(imm) & 0x1f) << 7)) +#define C_RD(rd) ((sljit_u16)((sljit_u16)reg_map[rd] << 7)) +#define C_RS2(rd) ((sljit_u16)((sljit_u16)reg_map[rd] << 2)) +#define C_FRD(rd) ((sljit_u16)((sljit_u16)freg_map[rd] << 7)) +#define C_FRS2(rd) ((sljit_u16)((sljit_u16)freg_map[rd] << 2)) +#define C_RS1_R3(rs1) ((sljit_u16)((sljit_u16)(reg_map[rs1] & 0x7) << 7)) +#define C_RS2_R3(rs2) ((sljit_u16)((sljit_u16)(reg_map[rs2] & 0x7) << 2)) +#define C_FRS2_R3(rs2) ((sljit_u16)((sljit_u16)(freg_map[rs2] & 0x7) << 2)) +#define C_IS_R3(r) ((reg_map[r] & 0x18) == 0x08) +#define C_IS_FR3(r) ((freg_map[r] & 0x18) == 0x08) +#define C_IMM_I(imm) ((sljit_u16)((((imm) & 0x1f) << 2) | (((imm) & 0x20) << 7))) +#define C_LD32_SP(imm) ((sljit_u16)((((imm) & 0x1c) << 2) | (((imm) & 0x20) << 7) | (((imm) & 0xc0) >> 4))) +#define C_ST32_SP(imm) ((sljit_u16)((((imm) & 0x3c) << 7) | (((imm) & 0xc0) << 1))) +#define C_LD64_SP(imm) ((sljit_u16)((((imm) & 0x18) << 2) | (((imm) & 0x20) << 7) | (((imm) & 0x1c0) >> 4))) +#define C_ST64_SP(imm) ((sljit_u16)((((imm) & 0x38) << 7) | (((imm) & 0x1c0) << 1))) +#define C_MEM32(imm) ((sljit_u16)((((imm) & 0x4) << 4) | (((imm) & 0x38) << 7) | (((imm) & 0x40) >> 1))) +#define C_MEM64(imm) ((sljit_u16)((((imm) & 0x38) << 7) | (((imm) & 0xc0) >> 1))) +#define C_BRN16(imm) ((sljit_u16)((((imm) & 0x6) << 2) | (((imm) & 0x18) << 7) | (((imm) & 0x20) >> 3) | (((imm) & 0xc0) >> 1) | (((imm) & 0x100) << 4))) +#define C_JMP16(imm) ((sljit_u16)((((imm) & 0xb40) << 1) | (((imm) & 0xe) << 2) | (((imm) & 0x10) << 7) | (((imm) & 0x20) >> 3) | (((imm) & 0x80) >> 1) | (((imm) & 0x400) >> 2))) /* Represents funct(i) parts of the instructions. */ #define OPC(o) ((sljit_ins)(o)) +#define C_OPC(o1, o2) ((sljit_u16)((o1) | ((o2) << 13))) #define F3(f) ((sljit_ins)(f) << 12) #define F12(f) ((sljit_ins)(f) << 20) #define F7(f) ((sljit_ins)(f) << 25) @@ -107,10 +257,50 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define BGE (F3(0x5) | OPC(0x63)) #define BLTU (F3(0x6) | OPC(0x63)) #define BGEU (F3(0x7) | OPC(0x63)) -#if defined __riscv_zbb +/* C_*: compressed */ +#define C_ADD (C_OPC(0x2, 0x4) | (sljit_u16)(1 << 12)) +#define C_ADDI (C_OPC(0x1, 0x0)) +#define C_ADDIW (C_OPC(0x1, 0x1)) +#define C_ADDW (C_OPC(0x1, 0x4) | (sljit_u16)(7 << 10) | (sljit_u16)(1 << 5)) +#define C_ADDI16SP (C_OPC(0x1, 0x3) | (sljit_u16)(2 << 7)) +#define C_AND (C_OPC(0x1, 0x4) | (sljit_u16)(3 << 10) | (sljit_u16)(3 << 5)) +#define C_ANDI (C_OPC(0x1, 0x4) | (sljit_u16)(2 << 10)) +#define C_BEQZ (C_OPC(0x1, 0x6)) +#define C_BNEZ (C_OPC(0x1, 0x7)) +#define C_EBREAK (C_OPC(0x2, 0x4) | (sljit_u16)(1 << 12)) +#define C_FLDSP (C_OPC(0x2, 0x1)) +#define C_FLWSP (C_OPC(0x2, 0x3)) +#define C_FSD (C_OPC(0x0, 0x5)) +#define C_FSDSP (C_OPC(0x2, 0x5)) +#define C_FSW (C_OPC(0x0, 0x7)) +#define C_FSWSP (C_OPC(0x2, 0x7)) +#define C_J (C_OPC(0x1, 0x5)) +#define C_JR (C_OPC(0x2, 0x4)) +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) +#define C_JAL (C_OPC(0x1, 0x1)) +#endif +#define C_JALR (C_OPC(0x2, 0x4) | (sljit_u16)(1 << 12)) +#define C_LI (C_OPC(0x1, 0x2)) +#define C_LUI (C_OPC(0x1, 0x3)) +#define C_LDSP (C_OPC(0x2, 0x3)) +#define C_LWSP (C_OPC(0x2, 0x2)) +#define C_MV (C_OPC(0x2, 0x4)) +#define C_NOP (C_OPC(0x1, 0x0)) +#define C_SD (C_OPC(0x0, 0x7)) +#define C_SDSP (C_OPC(0x2, 0x7)) +#define C_SLLI (C_OPC(0x2, 0x0)) +#define C_OR (C_OPC(0x1, 0x4) | (sljit_u16)(3 << 10) | (sljit_u16)(2 << 5)) +#define C_SRAI (C_OPC(0x1, 0x4) | (sljit_u16)(1 << 10)) +#define C_SRLI (C_OPC(0x1, 0x4) | (sljit_u16)(0 << 10)) +#define C_SUB (C_OPC(0x1, 0x4) | (sljit_u16)(3 << 10) | (sljit_u16)(0 << 5)) +#define C_SW (C_OPC(0x0, 0x6)) +#define C_SWSP (C_OPC(0x2, 0x6)) +#define C_XOR (C_OPC(0x1, 0x4) | (sljit_u16)(3 << 10) | (sljit_u16)(1 << 5)) +/* CLZ / CTZ: zbb */ #define CLZ (F7(0x30) | F3(0x1) | OPC(0x13)) #define CTZ (F7(0x30) | F12(0x1) | F3(0x1) | OPC(0x13)) -#endif /* __riscv_zbb */ +#define CZERO_EQZ (F7(0x7) | F3(0x5) | OPC(0x33)) +#define CZERO_NEZ (F7(0x7) | F3(0x7) | OPC(0x33)) #define DIV (F7(0x1) | F3(0x4) | OPC(0x33)) #define DIVU (F7(0x1) | F3(0x5) | OPC(0x33)) #define EBREAK (F12(0x1) | F3(0x0) | OPC(0x73)) @@ -140,35 +330,39 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define LD (F3(0x3) | OPC(0x3)) #define LUI (OPC(0x37)) #define LW (F3(0x2) | OPC(0x3)) +/* LR: atomic */ #define LR (F7(0x8) | OPC(0x2f)) +#define MAX (F7(0x5) | F3(0x6) | OPC(0x33)) +#define MAXU (F7(0x5) | F3(0x7) | OPC(0x33)) +#define MIN (F7(0x5) | F3(0x4) | OPC(0x33)) +#define MINU (F7(0x5) | F3(0x5) | OPC(0x33)) #define MUL (F7(0x1) | F3(0x0) | OPC(0x33)) #define MULH (F7(0x1) | F3(0x1) | OPC(0x33)) #define MULHU (F7(0x1) | F3(0x3) | OPC(0x33)) +#define NOP ADDI #define OR (F7(0x0) | F3(0x6) | OPC(0x33)) #define ORI (F3(0x6) | OPC(0x13)) #define REM (F7(0x1) | F3(0x6) | OPC(0x33)) #define REMU (F7(0x1) | F3(0x7) | OPC(0x33)) -#if defined __riscv_zbb -#if defined SLJIT_CONFIG_RISCV_32 +/* REV8 / ROL / ROR / RORI: zbb */ +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) #define REV8 (F12(0x698) | F3(0x5) | OPC(0x13)) -#elif defined SLJIT_CONFIG_RISCV_64 +#elif (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) #define REV8 (F12(0x6b8) | F3(0x5) | OPC(0x13)) #endif /* SLJIT_CONFIG_RISCV_32 */ #define ROL (F7(0x30) | F3(0x1) | OPC(0x33)) #define ROR (F7(0x30) | F3(0x5) | OPC(0x33)) #define RORI (F7(0x30) | F3(0x5) | OPC(0x13)) -#endif /* __riscv_zbb */ +/* SC: atomic */ #define SC (F7(0xc) | OPC(0x2f)) #define SD (F3(0x3) | OPC(0x23)) -#if defined __riscv_zbb +/* SEXTB / SEXTH: zbb */ #define SEXTB (F7(0x30) | F12(0x4) | F3(0x1) | OPC(0x13)) #define SEXTH (F7(0x30) | F12(0x5) | F3(0x1) | OPC(0x13)) -#endif /* __riscv_zbb */ -#if defined __riscv_zba +/* SH1ADD / SH2ADD / SH3ADD: zba */ #define SH1ADD (F7(0x10) | F3(0x2) | OPC(0x33)) #define SH2ADD (F7(0x10) | F3(0x4) | OPC(0x33)) #define SH3ADD (F7(0x10) | F3(0x6) | OPC(0x33)) -#endif /* __riscv_zba */ #define SLL (F7(0x0) | F3(0x1) | OPC(0x33)) #define SLLI (F3(0x1) | OPC(0x13)) #define SLT (F7(0x0) | F3(0x2) | OPC(0x33)) @@ -181,6 +375,7 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define SRAI (F7(0x20) | F3(0x5) | OPC(0x13)) #define SUB (F7(0x20) | F3(0x0) | OPC(0x33)) #define SW (F3(0x2) | OPC(0x23)) +/* V*: vector */ #define VAND_VV (F7(0x13) | OPIVV) #define VFMV_FS (F7(0x21) | OPFVV) #define VFMV_SF (F7(0x21) | OPFVF) @@ -194,6 +389,7 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define VMV_VX (F7(0x2f) | OPIVX) #define VMV_XS (F7(0x21) | OPMVV) #define VOR_VV (F7(0x15) | OPIVV) +#define VSETVLI (F7(0x0) | F3(0x7) | OPC(0x57)) #define VSETIVLI (F7(0x60) | F3(0x7) | OPC(0x57)) #define VS (F7(0x1) | OPC(0x27)) #define VSLIDEDOWN_VX (F7(0x1f) | OPIVX) @@ -208,20 +404,25 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define VZEXT_VF8 (F7(0x25) | (0x2 << 15) | OPMVV) #define XOR (F7(0x0) | F3(0x4) | OPC(0x33)) #define XORI (F3(0x4) | OPC(0x13)) -#if defined __riscv_zbb -#if defined SLJIT_CONFIG_RISCV_32 +/* ZEXTH: zbb */ +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) #define ZEXTH (F7(0x4) | F3(0x4) | OPC(0x33)) -#elif defined SLJIT_CONFIG_RISCV_64 +#else /* SLJIT_CONFIG_RISCV_64 */ #define ZEXTH (F7(0x4) | F3(0x4) | OPC(0x3B)) #endif /* SLJIT_CONFIG_RISCV_32 */ -#endif /* __riscv_zbb */ #define SIMM_MAX (0x7ff) #define SIMM_MIN (-0x800) +#define SIMM16_MAX (0x1f) +#define SIMM16_MIN (-0x20) #define BRANCH_MAX (0xfff) #define BRANCH_MIN (-0x1000) +#define BRANCH16_MAX (0xff) +#define BRANCH16_MIN (-0x100) #define JUMP_MAX (0xfffff) #define JUMP_MIN (-0x100000) +#define JUMP16_MAX SIMM_MAX +#define JUMP16_MIN SIMM_MIN #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) #define S32_MAX (0x7ffff7ffl) @@ -230,9 +431,30 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define S52_MAX (0x7ffffffffffffl) #endif /* SLJIT_CONFIG_RISCV_64 */ +#define C_ADDI_W(word) (C_ADDI | (sljit_u16)((word) << 10)) +#define C_SUB_W(word) (C_SUB | (sljit_u16)((word) << 9)) + +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) +#define BRANCH_LENGTH ((sljit_ins)(3 * sizeof(sljit_ins)) << 7) +#define BRANCH16_LENGTH C_BRN16(5 * sizeof(sljit_u16)) +#else /* !SLJIT_CONFIG_RISCV_32 */ +#define BRANCH_LENGTH ((sljit_ins)(7 * sizeof(sljit_ins)) << 7) +#define BRANCH16_LENGTH C_BRN16(13 * sizeof(sljit_u16)) +#endif /* SLJIT_CONFIG_RISCV_32 */ + static sljit_s32 push_inst(struct sljit_compiler *compiler, sljit_ins ins) { - sljit_ins *ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins)); + sljit_u16 *ptr = (sljit_u16*)ensure_buf(compiler, sizeof(sljit_ins)); + FAIL_IF(!ptr); + ptr[0] = (sljit_u16)ins; + ptr[1] = (sljit_u16)(ins >> 16); + compiler->size += 2; + return SLJIT_SUCCESS; +} + +static sljit_s32 push_inst16(struct sljit_compiler *compiler, sljit_u16 ins) +{ + sljit_u16 *ptr = (sljit_u16*)ensure_buf(compiler, sizeof(sljit_u16)); FAIL_IF(!ptr); *ptr = ins; compiler->size++; @@ -244,12 +466,16 @@ static sljit_s32 push_imm_s_inst(struct sljit_compiler *compiler, sljit_ins ins, return push_inst(compiler, ins | IMM_S(imm)); } -static SLJIT_INLINE sljit_ins* detect_jump_type(struct sljit_jump *jump, sljit_ins *code_ptr, sljit_ins *code, sljit_sw executable_offset) +static SLJIT_INLINE sljit_u16* detect_jump_type(struct sljit_jump *jump, sljit_u16 *code_ptr, sljit_u16 *code, sljit_sw executable_offset) { - sljit_sw diff; + sljit_sw diff, cond_diff; sljit_uw target_addr; sljit_uw jump_addr = (sljit_uw)code_ptr; sljit_uw orig_addr = jump->addr; + sljit_ins ins; +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + sljit_s32 jalr_offset = JUMP_MAX_SIZE - 1; +#endif /* SLJIT_CONFIG_RISCV_64 */ SLJIT_UNUSED_ARG(executable_offset); jump->addr = jump_addr; @@ -269,90 +495,131 @@ static SLJIT_INLINE sljit_ins* detect_jump_type(struct sljit_jump *jump, sljit_i diff = (sljit_sw)target_addr - (sljit_sw)SLJIT_ADD_EXEC_OFFSET(jump_addr, executable_offset); if (jump->flags & IS_COND) { - diff += SSIZE_OF(ins); + cond_diff = diff + SSIZE_OF(ins); + + if (RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16))) { + SLJIT_ASSERT((code_ptr[-1] & 0xe003) == C_BEQZ || (code_ptr[-1] & 0xe003) == C_BNEZ); + + cond_diff = diff + SSIZE_OF(u16); + + if (diff >= BRANCH16_MIN && diff <= BRANCH16_MAX) { + code_ptr--; + code_ptr[0] = (sljit_u16)((code_ptr[0] & 0xe383) ^ 0x2000); + jump->flags |= PATCH_B | PATCH_16; + jump->addr = (sljit_uw)code_ptr; + return code_ptr; + } + } + + if (cond_diff >= BRANCH_MIN && cond_diff <= BRANCH_MAX) { + if (RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16))) { + /* Converting 16 bit branch to 32 bit branch. */ + code_ptr--; + code_ptr[1] = (sljit_u16)(((code_ptr[0] & 0x300) >> 8) | 0x4); + code_ptr[0] = (sljit_u16)((BNE ^ ((code_ptr[0] & 0x2000) >> 1)) | ((code_ptr[0] & 0x80) << 8)); + } else { + code_ptr -= 2; + code_ptr[0] = (sljit_u16)((code_ptr[0] & 0xf07f) ^ 0x1000); + code_ptr[1] = (sljit_u16)(code_ptr[1] & 0x1ff); + } - if (diff >= BRANCH_MIN && diff <= BRANCH_MAX) { - code_ptr--; - code_ptr[0] = (code_ptr[0] & 0x1fff07f) ^ 0x1000; jump->flags |= PATCH_B; jump->addr = (sljit_uw)code_ptr; - return code_ptr; + return code_ptr + 1; } + } - diff -= SSIZE_OF(ins); + if (RISCV_HAS_COMPRESSED(200) && RISCV_CHECK_COMPRESSED_JUMP(jump, diff, u8)) { + /* A conditional instruction has larger max offset + than a 16 bit jump instruction. */ + SLJIT_ASSERT(!(jump->flags & IS_COND)); + jump->flags |= PATCH_J | PATCH_16; + return code_ptr; } if (diff >= JUMP_MIN && diff <= JUMP_MAX) { if (jump->flags & IS_COND) { -#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) - code_ptr[-1] -= (sljit_ins)(1 * sizeof(sljit_ins)) << 7; -#else /* !SLJIT_CONFIG_RISCV_32 */ - code_ptr[-1] -= (sljit_ins)(5 * sizeof(sljit_ins)) << 7; -#endif /* SLJIT_CONFIG_RISCV_32 */ + if (RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16))) + code_ptr[-1] ^= (sljit_u16)(BRANCH16_LENGTH ^ C_BRN16(3 * sizeof(sljit_u16))); + else + code_ptr[-2] ^= (sljit_u16)(BRANCH_LENGTH ^ (2 * sizeof(sljit_ins) << 7)); } jump->flags |= PATCH_J; - return code_ptr; + return code_ptr + 1; } #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) if (diff >= S32_MIN && diff <= S32_MAX) { - if (jump->flags & IS_COND) - code_ptr[-1] -= (sljit_ins)(4 * sizeof(sljit_ins)) << 7; + if (jump->flags & IS_COND) { + if (RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16))) + code_ptr[-1] ^= (sljit_u16)(BRANCH16_LENGTH ^ C_BRN16(5 * sizeof(sljit_u16))); + else + code_ptr[-2] ^= (sljit_u16)(BRANCH_LENGTH ^ (3 * sizeof(sljit_ins) << 7)); + } jump->flags |= PATCH_REL32; - code_ptr[1] = code_ptr[0]; - return code_ptr + 1; - } - - if (target_addr <= (sljit_uw)S32_MAX) { - if (jump->flags & IS_COND) - code_ptr[-1] -= (sljit_ins)(4 * sizeof(sljit_ins)) << 7; + jalr_offset = 3; + } else if (target_addr <= (sljit_uw)S32_MAX) { + if (jump->flags & IS_COND) { + if (RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16))) + code_ptr[-1] ^= (sljit_u16)(BRANCH16_LENGTH ^ C_BRN16(5 * sizeof(sljit_u16))); + else + code_ptr[-2] ^= (sljit_u16)(BRANCH_LENGTH ^ (3 * sizeof(sljit_ins) << 7)); + } jump->flags |= PATCH_ABS32; - code_ptr[1] = code_ptr[0]; - return code_ptr + 1; - } - - if (target_addr <= S44_MAX) { - if (jump->flags & IS_COND) - code_ptr[-1] -= (sljit_ins)(2 * sizeof(sljit_ins)) << 7; + jalr_offset = 3; + } else if (target_addr <= S44_MAX) { + if (jump->flags & IS_COND) { + if (RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16))) + code_ptr[-1] ^= (sljit_u16)(BRANCH16_LENGTH ^ C_BRN16(9 * sizeof(sljit_u16))); + else + code_ptr[-2] ^= (sljit_u16)(BRANCH_LENGTH ^ (5 * sizeof(sljit_ins) << 7)); + } jump->flags |= PATCH_ABS44; - code_ptr[3] = code_ptr[0]; - return code_ptr + 3; - } - - if (target_addr <= S52_MAX) { - if (jump->flags & IS_COND) - code_ptr[-1] -= (sljit_ins)(1 * sizeof(sljit_ins)) << 7; + jalr_offset = 7; + } else if (target_addr <= S52_MAX) { + if (jump->flags & IS_COND) { + if (RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16))) + code_ptr[-1] ^= (sljit_u16)(BRANCH16_LENGTH ^ C_BRN16(11 * sizeof(sljit_u16))); + else + code_ptr[-2] ^= (sljit_u16)(BRANCH_LENGTH ^ (6 * sizeof(sljit_ins) << 7)); + } jump->flags |= PATCH_ABS52; - code_ptr[4] = code_ptr[0]; - return code_ptr + 4; + jalr_offset = 9; } #endif /* SLJIT_CONFIG_RISCV_64 */ exit: + ins = JALR | RS1(TMP_REG1) | IMM_I(0); + if (jump->flags & IS_CALL) + ins |= RD(RETURN_ADDR_REG); + #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) - code_ptr[1] = code_ptr[0]; - return code_ptr + 1; + code_ptr[2] = (sljit_u16)ins; + code_ptr[3] = (sljit_u16)(ins >> 16); + return code_ptr + 3; #else /* !SLJIT_CONFIG_RISCV_32 */ - code_ptr[5] = code_ptr[0]; - return code_ptr + 5; + code_ptr += jalr_offset; + code_ptr[-1] = (sljit_u16)ins; + code_ptr[0] = (sljit_u16)(ins >> 16); + return code_ptr; #endif /* SLJIT_CONFIG_RISCV_32 */ } #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) -static SLJIT_INLINE sljit_sw mov_addr_get_length(struct sljit_jump *jump, sljit_ins *code_ptr, sljit_ins *code, sljit_sw executable_offset) +static SLJIT_INLINE sljit_sw mov_addr_get_length(struct sljit_jump *jump, sljit_u16 *code_ptr, sljit_u16 *code, sljit_sw executable_offset) { sljit_uw addr; sljit_uw jump_addr = (sljit_uw)code_ptr; sljit_sw diff; SLJIT_UNUSED_ARG(executable_offset); - SLJIT_ASSERT(jump->flags < ((sljit_uw)6 << JUMP_SIZE_SHIFT)); + SLJIT_ASSERT(jump->flags < (JUMP_MAX_SIZE << JUMP_SIZE_SHIFT)); if (jump->flags & JUMP_ADDR) addr = jump->u.target; else { @@ -365,31 +632,31 @@ static SLJIT_INLINE sljit_sw mov_addr_get_length(struct sljit_jump *jump, sljit_ diff = (sljit_sw)addr - (sljit_sw)SLJIT_ADD_EXEC_OFFSET(jump_addr, executable_offset); if (diff >= S32_MIN && diff <= S32_MAX) { - SLJIT_ASSERT(jump->flags >= ((sljit_uw)1 << JUMP_SIZE_SHIFT)); + SLJIT_ASSERT(jump->flags >= ((sljit_uw)3 << JUMP_SIZE_SHIFT)); jump->flags |= PATCH_REL32; - return 1; + return 3; } if (addr <= S32_MAX) { - SLJIT_ASSERT(jump->flags >= ((sljit_uw)1 << JUMP_SIZE_SHIFT)); + SLJIT_ASSERT(jump->flags >= ((sljit_uw)3 << JUMP_SIZE_SHIFT)); jump->flags |= PATCH_ABS32; - return 1; + return 3; } if (addr <= S44_MAX) { - SLJIT_ASSERT(jump->flags >= ((sljit_uw)3 << JUMP_SIZE_SHIFT)); + SLJIT_ASSERT(jump->flags >= ((sljit_uw)7 << JUMP_SIZE_SHIFT)); jump->flags |= PATCH_ABS44; - return 3; + return 7; } if (addr <= S52_MAX) { - SLJIT_ASSERT(jump->flags >= ((sljit_uw)4 << JUMP_SIZE_SHIFT)); + SLJIT_ASSERT(jump->flags >= ((sljit_uw)9 << JUMP_SIZE_SHIFT)); jump->flags |= PATCH_ABS52; - return 4; + return 9; } - SLJIT_ASSERT(jump->flags >= ((sljit_uw)5 << JUMP_SIZE_SHIFT)); - return 5; + SLJIT_ASSERT(jump->flags >= ((sljit_uw)11 << JUMP_SIZE_SHIFT)); + return 11; } #endif /* SLJIT_CONFIG_RISCV_64 */ @@ -398,8 +665,9 @@ static SLJIT_INLINE void load_addr_to_reg(struct sljit_jump *jump, sljit_sw exec { sljit_uw flags = jump->flags; sljit_uw addr = (flags & JUMP_ADDR) ? jump->u.target : jump->u.label->u.addr; - sljit_ins *ins = (sljit_ins*)jump->addr; - sljit_u32 reg = (flags & JUMP_MOV_ADDR) ? *ins : TMP_REG1; + sljit_ins ins; + sljit_u16 *buf = (sljit_u16 *)jump->addr; + sljit_u32 reg = (flags & JUMP_MOV_ADDR) ? *buf : TMP_REG1; #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) sljit_sw high; #endif /* SLJIT_CONFIG_RISCV_64 */ @@ -407,20 +675,26 @@ static SLJIT_INLINE void load_addr_to_reg(struct sljit_jump *jump, sljit_sw exec #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) if (flags & PATCH_REL32) { - addr -= (sljit_uw)SLJIT_ADD_EXEC_OFFSET(ins, executable_offset); + addr -= (sljit_uw)SLJIT_ADD_EXEC_OFFSET(buf, executable_offset); SLJIT_ASSERT((sljit_sw)addr >= S32_MIN && (sljit_sw)addr <= S32_MAX); if ((addr & 0x800) != 0) addr += 0x1000; - ins[0] = AUIPC | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); + ins = AUIPC | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); + buf[0] = (sljit_u16)ins; + buf[1] = (sljit_u16)(ins >> 16); if (!(flags & JUMP_MOV_ADDR)) { - SLJIT_ASSERT((ins[1] & 0x707f) == JALR); - ins[1] = (ins[1] & 0xfffff) | IMM_I(addr); + ins = JALR | RS1(reg) | IMM_I(addr); + if (jump->flags & IS_CALL) + ins |= RD(RETURN_ADDR_REG); } else - ins[1] = ADDI | RD(reg) | RS1(reg) | IMM_I(addr); + ins = ADDI | RD(reg) | RS1(reg) | IMM_I(addr); + + buf[2] = (sljit_u16)ins; + buf[3] = (sljit_u16)(ins >> 16); return; } #endif /* SLJIT_CONFIG_RISCV_64 */ @@ -429,30 +703,44 @@ static SLJIT_INLINE void load_addr_to_reg(struct sljit_jump *jump, sljit_sw exec addr += 0x1000; #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) - ins[0] = LUI | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); + ins = LUI | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); + buf[0] = (sljit_u16)ins; + buf[1] = (sljit_u16)(ins >> 16); #else /* !SLJIT_CONFIG_RISCV_32 */ if (flags & PATCH_ABS32) { SLJIT_ASSERT(addr <= S32_MAX); - ins[0] = LUI | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); + ins = LUI | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); + buf[0] = (sljit_u16)ins; + buf[1] = (sljit_u16)(ins >> 16); } else if (flags & PATCH_ABS44) { high = (sljit_sw)addr >> 12; SLJIT_ASSERT((sljit_uw)high <= 0x7fffffff); if (high > S32_MAX) { SLJIT_ASSERT((high & 0x800) != 0); - ins[0] = LUI | RD(reg) | (sljit_ins)0x80000000u; - ins[1] = XORI | RD(reg) | RS1(reg) | IMM_I(high); + ins = LUI | RD(reg) | (sljit_ins)0x80000000u; + buf[0] = (sljit_u16)ins; + buf[1] = (sljit_u16)(ins >> 16); + ins = XORI | RD(reg) | RS1(reg) | IMM_I(high); + buf[2] = (sljit_u16)ins; + buf[3] = (sljit_u16)(ins >> 16); } else { if ((high & 0x800) != 0) high += 0x1000; - ins[0] = LUI | RD(reg) | (sljit_ins)(high & ~0xfff); - ins[1] = ADDI | RD(reg) | RS1(reg) | IMM_I(high); + ins = LUI | RD(reg) | (sljit_ins)(high & ~0xfff); + buf[0] = (sljit_u16)ins; + buf[1] = (sljit_u16)(ins >> 16); + ins = ADDI | RD(reg) | RS1(reg) | IMM_I(high); + buf[2] = (sljit_u16)ins; + buf[3] = (sljit_u16)(ins >> 16); } - ins[2] = SLLI | RD(reg) | RS1(reg) | IMM_I(12); - ins += 2; + ins = SLLI | RD(reg) | RS1(reg) | IMM_I(12); + buf[4] = (sljit_u16)ins; + buf[5] = (sljit_u16)(ins >> 16); + buf += 4; } else { high = (sljit_sw)addr >> 32; @@ -461,27 +749,49 @@ static SLJIT_INLINE void load_addr_to_reg(struct sljit_jump *jump, sljit_sw exec if (flags & PATCH_ABS52) { SLJIT_ASSERT(addr <= S52_MAX); - ins[0] = LUI | RD(TMP_REG3) | (sljit_ins)(high << 12); + ins = LUI | RD(TMP_REG3) | (sljit_ins)(high << 12); + buf[0] = (sljit_u16)ins; + buf[1] = (sljit_u16)(ins >> 16); } else { if ((high & 0x800) != 0) high += 0x1000; - ins[0] = LUI | RD(TMP_REG3) | (sljit_ins)(high & ~0xfff); - ins[1] = ADDI | RD(TMP_REG3) | RS1(TMP_REG3) | IMM_I(high); - ins++; + ins = LUI | RD(TMP_REG3) | (sljit_ins)(high & ~0xfff); + buf[0] = (sljit_u16)ins; + buf[1] = (sljit_u16)(ins >> 16); + ins = ADDI | RD(TMP_REG3) | RS1(TMP_REG3) | IMM_I(high); + buf[2] = (sljit_u16)ins; + buf[3] = (sljit_u16)(ins >> 16); + buf += 2; } - ins[1] = LUI | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); - ins[2] = SLLI | RD(TMP_REG3) | RS1(TMP_REG3) | IMM_I((flags & PATCH_ABS52) ? 20 : 32); - ins[3] = XOR | RD(reg) | RS1(reg) | RS2(TMP_REG3); - ins += 3; + ins = LUI | RD(reg) | (sljit_ins)((sljit_sw)addr & ~0xfff); + buf[2] = (sljit_u16)ins; + buf[3] = (sljit_u16)(ins >> 16); + ins = SLLI | RD(TMP_REG3) | RS1(TMP_REG3) | IMM_I((flags & PATCH_ABS52) ? 20 : 32); + buf[4] = (sljit_u16)ins; + buf[5] = (sljit_u16)(ins >> 16); + ins = XOR | RD(reg) | RS1(reg) | RS2(TMP_REG3); + buf[6] = (sljit_u16)ins; + buf[7] = (sljit_u16)(ins >> 16); + buf += 6; } #endif /* !SLJIT_CONFIG_RISCV_32 */ if (!(flags & JUMP_MOV_ADDR)) { - SLJIT_ASSERT((ins[1] & 0x707f) == JALR); - ins[1] = (ins[1] & 0xfffff) | IMM_I(addr); + ins = JALR | RS1(reg) | IMM_I(addr); + if (jump->flags & IS_CALL) + ins |= RD(RETURN_ADDR_REG); } else - ins[1] = ADDI | RD(reg) | RS1(reg) | IMM_I(addr); + ins = ADDI | RD(reg) | RS1(reg) | IMM_I(addr); + + buf[2] = (sljit_u16)ins; + buf[3] = (sljit_u16)(ins >> 16); +} + +static SLJIT_INLINE sljit_u16 *process_extended_label(sljit_u16 *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_u16*)((sljit_uw)code_ptr & ~(ext_label->data)); } static void reduce_code_size(struct sljit_compiler *compiler) @@ -492,7 +802,7 @@ static void reduce_code_size(struct sljit_compiler *compiler) SLJIT_NEXT_DEFINE_TYPES; sljit_uw total_size; sljit_uw size_reduce = 0; - sljit_sw diff; + sljit_sw diff, cond_size, cond_diff; label = compiler->labels; jump = compiler->jumps; @@ -530,11 +840,11 @@ static void reduce_code_size(struct sljit_compiler *compiler) if (jump->flags & JUMP_ADDR) { #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) if (jump->u.target <= S32_MAX) - total_size = 2; - else if (jump->u.target <= S44_MAX) total_size = 4; + else if (jump->u.target <= S44_MAX) + total_size = 8; else if (jump->u.target <= S52_MAX) - total_size = 5; + total_size = 10; #endif /* SLJIT_CONFIG_RISCV_64 */ } else { /* Unit size: instruction. */ @@ -544,13 +854,20 @@ static void reduce_code_size(struct sljit_compiler *compiler) diff -= (sljit_sw)size_reduce; } - if ((jump->flags & IS_COND) && (diff + 1) <= (BRANCH_MAX / SSIZE_OF(ins)) && (diff + 1) >= (BRANCH_MIN / SSIZE_OF(ins))) + cond_size = RISCV_COMPRESSED_CHECK((jump->flags & IS_COND16) != 0); + cond_diff = diff + 2 - cond_size; + + if (RISCV_COMPRESSED_CHECK(cond_size) && diff >= (BRANCH16_MIN / SSIZE_OF(u16)) && diff <= (BRANCH16_MAX / SSIZE_OF(u16))) total_size = 0; - else if (diff >= (JUMP_MIN / SSIZE_OF(ins)) && diff <= (JUMP_MAX / SSIZE_OF(ins))) + else if ((jump->flags & IS_COND) && cond_diff <= (BRANCH_MAX / SSIZE_OF(u16)) && cond_diff >= (BRANCH_MIN / SSIZE_OF(u16))) + total_size = (sljit_uw)cond_size; + else if (RISCV_HAS_COMPRESSED(200) && RISCV_CHECK_COMPRESSED_JUMP(jump, diff, u16)) total_size = 1; -#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) - else if (diff >= (S32_MIN / SSIZE_OF(ins)) && diff <= (S32_MAX / SSIZE_OF(ins))) + else if (diff >= (JUMP_MIN / SSIZE_OF(u16)) && diff <= (JUMP_MAX / SSIZE_OF(u16))) total_size = 2; +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + else if (diff >= (S32_MIN / SSIZE_OF(u16)) && diff <= (S32_MAX / SSIZE_OF(u16))) + total_size = 4; #endif /* SLJIT_CONFIG_RISCV_64 */ } } @@ -559,26 +876,26 @@ static void reduce_code_size(struct sljit_compiler *compiler) jump->flags |= total_size << JUMP_SIZE_SHIFT; #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) } else { - total_size = 5; + total_size = 11; if (!(jump->flags & JUMP_ADDR)) { - /* Real size minus 1. Unit size: instruction. */ + /* Real size minus 1. Unit size: 16 bit. */ diff = (sljit_sw)jump->u.label->size - (sljit_sw)jump->addr; if (jump->u.label->size > jump->addr) { SLJIT_ASSERT(jump->u.label->size - size_reduce >= jump->addr); diff -= (sljit_sw)size_reduce; } - if (diff >= (S32_MIN / SSIZE_OF(ins)) && diff <= (S32_MAX / SSIZE_OF(ins))) - total_size = 1; + if (diff >= (S32_MIN / SSIZE_OF(u16)) && diff <= (S32_MAX / SSIZE_OF(u16))) + total_size = 3; } else if (jump->u.target < S32_MAX) - total_size = 1; - else if (jump->u.target < S44_MAX) total_size = 3; + else if (jump->u.target < S44_MAX) + total_size = 7; else if (jump->u.target <= S52_MAX) - total_size = 4; + total_size = 9; - size_reduce += 5 - total_size; + size_reduce += 11 - total_size; jump->flags |= total_size << JUMP_SIZE_SHIFT; #endif /* !SLJIT_CONFIG_RISCV_64 */ } @@ -593,32 +910,33 @@ static void reduce_code_size(struct sljit_compiler *compiler) SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler, sljit_s32 options, void *exec_allocator_data) { struct sljit_memory_fragment *buf; - sljit_ins *code; - sljit_ins *code_ptr; - sljit_ins *buf_ptr; - sljit_ins *buf_end; - sljit_uw word_count; + sljit_u16 *code; + sljit_u16 *code_ptr; + sljit_u16 *buf_ptr; + sljit_u16 *buf_end; + sljit_uw half_count; SLJIT_NEXT_DEFINE_TYPES; sljit_sw executable_offset; sljit_uw addr; + sljit_ins ins; struct sljit_label *label; struct sljit_jump *jump; struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reduce_code_size(compiler); - code = (sljit_ins*)allocate_executable_memory(compiler->size * sizeof(sljit_ins), options, exec_allocator_data, &executable_offset); + code = (sljit_u16 *)allocate_executable_memory(compiler->size * sizeof(sljit_u16), options, exec_allocator_data, &executable_offset); PTR_FAIL_WITH_EXEC_IF(code); reverse_buf(compiler); buf = compiler->buf; code_ptr = code; - word_count = 0; + half_count = 0; label = compiler->labels; jump = compiler->jumps; const_ = compiler->consts; @@ -626,17 +944,22 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_GET_NEXT_MIN(); do { - buf_ptr = (sljit_ins*)buf->memory; - buf_end = buf_ptr + (buf->used_size >> 2); + buf_ptr = (sljit_u16*)buf->memory; + buf_end = buf_ptr + (buf->used_size >> 1); do { *code_ptr = *buf_ptr++; - if (next_min_addr == word_count) { - SLJIT_ASSERT(!label || label->size >= word_count); - SLJIT_ASSERT(!jump || jump->addr >= word_count); - SLJIT_ASSERT(!const_ || const_->addr >= word_count); + if (next_min_addr == half_count) { + SLJIT_ASSERT(!label || label->size >= half_count); + SLJIT_ASSERT(!jump || jump->addr >= half_count); + SLJIT_ASSERT(!const_ || const_->addr >= half_count); /* These structures are ordered by their address. */ if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + *code_ptr = buf_ptr[-1]; + } + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -645,16 +968,16 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil if (next_min_addr == next_jump_addr) { if (!(jump->flags & JUMP_MOV_ADDR)) { - word_count = word_count - 1 + (jump->flags >> JUMP_SIZE_SHIFT); + half_count = half_count - 1 + (jump->flags >> JUMP_SIZE_SHIFT); code_ptr = detect_jump_type(jump, code_ptr, code, executable_offset); SLJIT_ASSERT((jump->flags & PATCH_B) || ((sljit_uw)code_ptr - jump->addr < (jump->flags >> JUMP_SIZE_SHIFT) * sizeof(sljit_ins))); } else { #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) - word_count += 1; + half_count += 3; jump->addr = (sljit_uw)code_ptr; - code_ptr += 1; + code_ptr += 3; #else /* !SLJIT_CONFIG_RISCV_32 */ - word_count += jump->flags >> JUMP_SIZE_SHIFT; + half_count += jump->flags >> JUMP_SIZE_SHIFT; addr = (sljit_uw)code_ptr; code_ptr += mov_addr_get_length(jump, code_ptr, code, executable_offset); jump->addr = addr; @@ -671,13 +994,16 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_GET_NEXT_MIN(); } code_ptr++; - word_count++; + half_count++; } while (buf_ptr < buf_end); buf = buf->next; } while (buf); - if (label && label->size == word_count) { + if (label && label->size == half_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)code_ptr; label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -697,19 +1023,41 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } addr = (jump->flags & JUMP_ADDR) ? jump->u.target : jump->u.label->u.addr; - buf_ptr = (sljit_ins *)jump->addr; + buf_ptr = (sljit_u16 *)jump->addr; addr -= (sljit_uw)SLJIT_ADD_EXEC_OFFSET(buf_ptr, executable_offset); if (jump->flags & PATCH_B) { + SLJIT_ASSERT(RISCV_HAS_COMPRESSED(200) || !(jump->flags & PATCH_16)); SLJIT_ASSERT((sljit_sw)addr >= BRANCH_MIN && (sljit_sw)addr <= BRANCH_MAX); - addr = ((addr & 0x800) >> 4) | ((addr & 0x1e) << 7) | ((addr & 0x7e0) << 20) | ((addr & 0x1000) << 19); - buf_ptr[0] |= (sljit_ins)addr; + + if (RISCV_COMPRESSED_CHECK(jump->flags & PATCH_16)) { + buf_ptr[0] |= C_BRN16(addr); + break; + } + + buf_ptr[0] |= (sljit_u16)(((addr & 0x800) >> 4) | ((addr & 0x1e) << 7)); + buf_ptr[1] |= (sljit_u16)(((addr & 0x7e0) << 4) | ((addr & 0x1000) << 3)); + break; + } + + SLJIT_ASSERT(RISCV_HAS_COMPRESSED(200) || !(jump->flags & PATCH_16)); + if (RISCV_COMPRESSED_CHECK(jump->flags & PATCH_16)) { + SLJIT_ASSERT((sljit_sw)addr >= JUMP16_MIN && (sljit_sw)addr <= JUMP16_MAX); +#if defined SLJIT_CONFIG_RISCV_32 + ins = ((jump->flags & IS_CALL) ? C_JAL : C_J) | C_JMP16(addr); +#else /* !SLJIT_CONFIG_RISCV_32 */ + SLJIT_ASSERT(!(jump->flags & IS_CALL)); + ins = C_J | C_JMP16(addr); +#endif /* SLJIT_CONFIG_RISCV_32 */ + buf_ptr[0] = (sljit_u16)ins; break; } SLJIT_ASSERT((sljit_sw)addr >= JUMP_MIN && (sljit_sw)addr <= JUMP_MAX); addr = (addr & 0xff000) | ((addr & 0x800) << 9) | ((addr & 0x7fe) << 20) | ((addr & 0x100000) << 11); - buf_ptr[0] = JAL | RD((jump->flags & IS_CALL) ? RETURN_ADDR_REG : TMP_ZERO) | (sljit_ins)addr; + ins = JAL | RD((jump->flags & IS_CALL) ? RETURN_ADDR_REG : TMP_ZERO) | (sljit_ins)addr; + buf_ptr[0] = (sljit_u16)ins; + buf_ptr[1] = (sljit_u16)(ins >> 16); } while (0); jump = jump->next; @@ -719,8 +1067,8 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil compiler->executable_offset = executable_offset; compiler->executable_size = (sljit_uw)(code_ptr - code) * sizeof(sljit_ins); - code = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(code, executable_offset); - code_ptr = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); + code = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(code, executable_offset); + code_ptr = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); SLJIT_CACHE_FLUSH(code, code_ptr); SLJIT_UPDATE_WX_FLAGS(code, code_ptr, 1); @@ -744,18 +1092,18 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) case SLJIT_HAS_COPY_F64: #endif /* !SLJIT_CONFIG_RISCV_64 */ case SLJIT_HAS_ATOMIC: + return RISCV_HAS_ATOMIC(200) ? 1 : 0; case SLJIT_HAS_MEMORY_BARRIER: -#ifdef __riscv_vector - case SLJIT_HAS_SIMD: -#endif /* __riscv_vector */ return 1; -#ifdef __riscv_zbb case SLJIT_HAS_CLZ: case SLJIT_HAS_CTZ: case SLJIT_HAS_REV: case SLJIT_HAS_ROT: - return 1; -#endif /* __riscv_zbb */ + return RISCV_HAS_BITMANIP_B(93) ? 1 : 0; + case SLJIT_HAS_CMOV: + return RISCV_HAS_ICOND(100) ? 2 : 0; + case SLJIT_HAS_SIMD: + return RISCV_HAS_VECTOR(100) ? 1 : 0; default: return 0; } @@ -813,9 +1161,15 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type) #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) #define STACK_STORE SW #define STACK_LOAD LW +#define C_STACK_OFFSET_CHECK(offset) ((offset) <= 0xfc) +#define C_STACK_LOAD(offset) (C_LWSP | C_LD32_SP(offset)) +#define C_STACK_STORE(offset) (C_SWSP | C_ST32_SP(offset)) #else /* !SLJIT_CONFIG_RISCV_32 */ #define STACK_STORE SD #define STACK_LOAD LD +#define C_STACK_OFFSET_CHECK(offset) ((offset) <= 0x1f8) +#define C_STACK_LOAD(offset) (C_LDSP | C_LD64_SP(offset)) +#define C_STACK_STORE(offset) (C_SDSP | C_ST64_SP(offset)) #endif /* SLJIT_CONFIG_RISCV_32 */ #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) @@ -858,8 +1212,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi if (local_size <= STACK_MAX_DISTANCE) { /* Frequent case. */ - FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RS1(SLJIT_SP) | IMM_I(-local_size))); offset = local_size - SSIZE_OF(sw); + local_size = -local_size; + if (RISCV_HAS_COMPRESSED(200) && local_size >= -0x200) { + SLJIT_ASSERT((local_size & 0x200) != 0 && (local_size & 0xf) == 0); + FAIL_IF(push_inst16(compiler, C_ADDI16SP | (sljit_u16)(((local_size & 0x10) << 2) | ((local_size & 0x20) >> 3) | ((local_size & 0x40) >> 1) | ((local_size & 0x180) >> 4) | (1 << 12)))); + } else + FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RS1(SLJIT_SP) | IMM_I(local_size))); local_size = 0; } else { FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RS1(SLJIT_SP) | IMM_I(STACK_MAX_DISTANCE))); @@ -870,17 +1229,26 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi offset = STACK_MAX_DISTANCE - SSIZE_OF(sw); } - FAIL_IF(push_imm_s_inst(compiler, STACK_STORE | RS1(SLJIT_SP) | RS2(RETURN_ADDR_REG), offset)); + if (RISCV_HAS_COMPRESSED(200) && C_STACK_OFFSET_CHECK(offset)) + FAIL_IF(push_inst16(compiler, C_STACK_STORE(offset) | C_RS2(RETURN_ADDR_REG))); + else + FAIL_IF(push_imm_s_inst(compiler, STACK_STORE | RS1(SLJIT_SP) | RS2(RETURN_ADDR_REG), offset)); tmp = SLJIT_S0 - saveds; for (i = SLJIT_S0 - saved_arg_count; i > tmp; i--) { offset -= SSIZE_OF(sw); - FAIL_IF(push_imm_s_inst(compiler, STACK_STORE | RS1(SLJIT_SP) | RS2(i), offset)); + if (RISCV_HAS_COMPRESSED(200) && C_STACK_OFFSET_CHECK(offset)) + FAIL_IF(push_inst16(compiler, C_STACK_STORE(offset) | C_RS2(i))); + else + FAIL_IF(push_imm_s_inst(compiler, STACK_STORE | RS1(SLJIT_SP) | RS2(i), offset)); } for (i = scratches; i >= SLJIT_FIRST_SAVED_REG; i--) { offset -= SSIZE_OF(sw); - FAIL_IF(push_imm_s_inst(compiler, STACK_STORE | RS1(SLJIT_SP) | RS2(i), offset)); + if (RISCV_HAS_COMPRESSED(200) && C_STACK_OFFSET_CHECK(offset)) + FAIL_IF(push_inst16(compiler, C_STACK_STORE(offset) | C_RS2(i))); + else + FAIL_IF(push_imm_s_inst(compiler, STACK_STORE | RS1(SLJIT_SP) | RS2(i), offset)); } #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) @@ -892,12 +1260,18 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi tmp = SLJIT_FS0 - fsaveds; for (i = SLJIT_FS0; i > tmp; i--) { offset -= SSIZE_OF(f64); - FAIL_IF(push_imm_s_inst(compiler, FSD | RS1(SLJIT_SP) | FRS2(i), offset)); + if (RISCV_HAS_COMPRESSED(200) && offset <= 0x1f8) + FAIL_IF(push_inst16(compiler, C_FSDSP | C_FRS2(i) | C_ST64_SP(offset))); + else + FAIL_IF(push_imm_s_inst(compiler, FSD | RS1(SLJIT_SP) | FRS2(i), offset)); } for (i = fscratches; i >= SLJIT_FIRST_SAVED_FLOAT_REG; i--) { offset -= SSIZE_OF(f64); - FAIL_IF(push_imm_s_inst(compiler, FSD | RS1(SLJIT_SP) | FRS2(i), offset)); + if (RISCV_HAS_COMPRESSED(200) && offset <= 0x1f8) + FAIL_IF(push_inst16(compiler, C_FSDSP | C_FRS2(i) | C_ST64_SP(offset))); + else + FAIL_IF(push_imm_s_inst(compiler, FSD | RS1(SLJIT_SP) | FRS2(i), offset)); } if (local_size > STACK_MAX_DISTANCE) @@ -915,7 +1289,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compi while (arg_types > 0) { if ((arg_types & SLJIT_ARG_MASK) < SLJIT_ARG_TYPE_F64) { if (!(arg_types & SLJIT_ARG_TYPE_SCRATCH_REG)) { - FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_S0 - saved_arg_count) | RS1(tmp) | IMM_I(0))); + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_MV | C_RD(SLJIT_S0 - saved_arg_count) | C_RS2(tmp))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_S0 - saved_arg_count) | RS1(tmp) | IMM_I(0))); saved_arg_count++; } tmp++; @@ -979,18 +1356,28 @@ static sljit_s32 emit_stack_frame_release(struct sljit_compiler *compiler, sljit SLJIT_ASSERT(local_size > 0); offset = local_size - SSIZE_OF(sw); - if (!is_return_to) - FAIL_IF(push_inst(compiler, STACK_LOAD | RD(RETURN_ADDR_REG) | RS1(SLJIT_SP) | IMM_I(offset))); + if (!is_return_to) { + if (RISCV_HAS_COMPRESSED(200) && C_STACK_OFFSET_CHECK(offset)) + FAIL_IF(push_inst16(compiler, C_STACK_LOAD(offset) | C_RD(RETURN_ADDR_REG))); + else + FAIL_IF(push_inst(compiler, STACK_LOAD | RD(RETURN_ADDR_REG) | RS1(SLJIT_SP) | IMM_I(offset))); + } tmp = SLJIT_S0 - compiler->saveds; for (i = SLJIT_S0 - SLJIT_KEPT_SAVEDS_COUNT(compiler->options); i > tmp; i--) { offset -= SSIZE_OF(sw); - FAIL_IF(push_inst(compiler, STACK_LOAD | RD(i) | RS1(SLJIT_SP) | IMM_I(offset))); + if (RISCV_HAS_COMPRESSED(200) && C_STACK_OFFSET_CHECK(offset)) + FAIL_IF(push_inst16(compiler, C_STACK_LOAD(offset) | C_RD(i))); + else + FAIL_IF(push_inst(compiler, STACK_LOAD | RD(i) | RS1(SLJIT_SP) | IMM_I(offset))); } for (i = compiler->scratches; i >= SLJIT_FIRST_SAVED_REG; i--) { offset -= SSIZE_OF(sw); - FAIL_IF(push_inst(compiler, STACK_LOAD | RD(i) | RS1(SLJIT_SP) | IMM_I(offset))); + if (RISCV_HAS_COMPRESSED(200) && C_STACK_OFFSET_CHECK(offset)) + FAIL_IF(push_inst16(compiler, C_STACK_LOAD(offset) | C_RD(i))); + else + FAIL_IF(push_inst(compiler, STACK_LOAD | RD(i) | RS1(SLJIT_SP) | IMM_I(offset))); } #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) @@ -1002,12 +1389,23 @@ static sljit_s32 emit_stack_frame_release(struct sljit_compiler *compiler, sljit tmp = SLJIT_FS0 - compiler->fsaveds; for (i = SLJIT_FS0; i > tmp; i--) { offset -= SSIZE_OF(f64); - FAIL_IF(push_inst(compiler, FLD | FRD(i) | RS1(SLJIT_SP) | IMM_I(offset))); + if (RISCV_HAS_COMPRESSED(200) && offset <= 0x1f8) + FAIL_IF(push_inst16(compiler, C_FLDSP | C_FRD(i) | C_LD64_SP(offset))); + else + FAIL_IF(push_inst(compiler, FLD | FRD(i) | RS1(SLJIT_SP) | IMM_I(offset))); } for (i = compiler->fscratches; i >= SLJIT_FIRST_SAVED_FLOAT_REG; i--) { offset -= SSIZE_OF(f64); - FAIL_IF(push_inst(compiler, FLD | FRD(i) | RS1(SLJIT_SP) | IMM_I(offset))); + if (RISCV_HAS_COMPRESSED(200) && offset <= 0x1f8) + FAIL_IF(push_inst16(compiler, C_FLDSP | C_FRD(i) | C_LD64_SP(offset))); + else + FAIL_IF(push_inst(compiler, FLD | FRD(i) | RS1(SLJIT_SP) | IMM_I(offset))); + } + + if (RISCV_HAS_COMPRESSED(200) && local_size <= 0x1f0) { + SLJIT_ASSERT((local_size & 0xf) == 0); + return push_inst16(compiler, C_ADDI16SP | (sljit_u16)(((local_size & 0x10) << 2) | ((local_size & 0x20) >> 3) | ((local_size & 0x40) >> 1) | ((local_size & 0x180) >> 4))); } return push_inst(compiler, ADDI | RD(SLJIT_SP) | RS1(SLJIT_SP) | IMM_I(local_size)); @@ -1087,14 +1485,80 @@ static const sljit_ins data_transfer_insts[16 + 4] = { static sljit_s32 push_mem_inst(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 base, sljit_sw offset) { sljit_ins ins; + sljit_s32 signed_flags; + sljit_s32 load_flags; SLJIT_ASSERT(FAST_IS_REG(base) && offset <= 0xfff && offset >= SIMM_MIN); - ins = data_transfer_insts[flags & MEM_MASK] | RS1(base); + flags &= MEM_MASK; + + if (RISCV_HAS_COMPRESSED(200) && offset >= 0) { + if (base == SLJIT_SP) { + signed_flags = flags | SIGNED_DATA; + + if ((offset & 0x3) == 0 && offset <= 0xfc) { +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) + if ((signed_flags == (SIGNED_DATA | LOAD_DATA) || signed_flags == (INT_DATA | SIGNED_DATA | LOAD_DATA))) + return push_inst16(compiler, C_LWSP | C_RD(reg) | C_LD32_SP(offset)); + if ((signed_flags == SIGNED_DATA || signed_flags == (INT_DATA | SIGNED_DATA))) + return push_inst16(compiler, C_SWSP | C_RS2(reg) | C_ST32_SP(offset)); + if (flags == (SINGLE_DATA | LOAD_DATA)) + return push_inst16(compiler, C_FLWSP | C_FRD(reg) | C_LD32_SP(offset)); + if (flags == SINGLE_DATA) + return push_inst16(compiler, C_FSWSP | C_FRS2(reg) | C_ST32_SP(offset)); +#else /* !SLJIT_CONFIG_RISCV_32 */ + if (flags == (INT_DATA | SIGNED_DATA | LOAD_DATA)) + return push_inst16(compiler, C_LWSP | C_RD(reg) | C_LD32_SP(offset)); + if (signed_flags == (INT_DATA | SIGNED_DATA)) + return push_inst16(compiler, C_SWSP | C_RS2(reg) | C_ST32_SP(offset)); +#endif /* SLJIT_CONFIG_RISCV_32 */ + } + + if ((offset & 0x7) == 0 && offset <= 0x1f8) { +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + if (signed_flags == (SIGNED_DATA | LOAD_DATA)) + return push_inst16(compiler, C_LDSP | C_RD(reg) | C_LD64_SP(offset)); + if (signed_flags == SIGNED_DATA) + return push_inst16(compiler, C_SDSP | C_RS2(reg) | C_ST64_SP(offset)); +#endif /* SLJIT_CONFIG_RISCV_64 */ + if (flags == (DOUBLE_DATA | LOAD_DATA)) + return push_inst16(compiler, C_FLDSP | C_FRD(reg) | C_LD64_SP(offset)); + if (flags == DOUBLE_DATA) + return push_inst16(compiler, C_FSDSP | C_FRS2(reg) | C_ST64_SP(offset)); + } + } else if (C_IS_R3(base) && (flags <= GPR_REG ? C_IS_R3(reg) : C_IS_FR3(reg))) { + SLJIT_COMPILE_ASSERT(LOAD_DATA == 1, load_data_bit_error); + signed_flags = flags | LOAD_DATA | SIGNED_DATA; + load_flags = flags | LOAD_DATA; + + if ((offset & 0x3) == 0 && offset <= 0x7c) { +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) + if (signed_flags == (SIGNED_DATA | LOAD_DATA) || signed_flags == (INT_DATA | SIGNED_DATA | LOAD_DATA)) + return push_inst16(compiler, (C_SW ^ (sljit_u16)((flags & LOAD_DATA) << 15)) | C_RS1_R3(base) | C_RS2_R3(reg) | C_MEM32(offset)); + if (load_flags == (SINGLE_DATA | LOAD_DATA)) + return push_inst16(compiler, (C_FSW ^ (sljit_u16)((flags & LOAD_DATA) << 15)) | C_RS1_R3(base) | C_FRS2_R3(reg) | C_MEM32(offset)); +#else /* !SLJIT_CONFIG_RISCV_32 */ + if (load_flags == (INT_DATA | SIGNED_DATA | LOAD_DATA)) + return push_inst16(compiler, (C_SW ^ (sljit_u16)((flags & LOAD_DATA) << 15)) | C_RS1_R3(base) | C_RS2_R3(reg) | C_MEM32(offset)); +#endif /* SLJIT_CONFIG_RISCV_32 */ + } + + if ((offset & 0x7) == 0 && offset <= 0xf8) { +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + if (signed_flags == (SIGNED_DATA | LOAD_DATA)) + return push_inst16(compiler, (C_SD ^ (sljit_u16)((flags & LOAD_DATA) << 15)) | C_RS1_R3(base) | C_RS2_R3(reg) | C_MEM64(offset)); +#endif /* SLJIT_CONFIG_RISCV_64 */ + if (load_flags == (DOUBLE_DATA | LOAD_DATA)) + return push_inst16(compiler, (C_FSD ^ (sljit_u16)((flags & LOAD_DATA) << 15)) | C_RS1_R3(base) | C_FRS2_R3(reg) | C_MEM64(offset)); + } + } + } + + ins = data_transfer_insts[flags] | RS1(base); if (flags & LOAD_DATA) - ins |= ((flags & MEM_MASK) <= GPR_REG ? RD(reg) : FRD(reg)) | IMM_I(offset); + ins |= (flags <= GPR_REG ? RD(reg) : FRD(reg)) | IMM_I(offset); else - ins |= ((flags & MEM_MASK) <= GPR_REG ? RS2(reg) : FRS2(reg)) | IMM_S(offset); + ins |= (flags <= GPR_REG ? RS2(reg) : FRS2(reg)) | IMM_S(offset); return push_inst(compiler, ins); } @@ -1148,9 +1612,7 @@ static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sl sljit_s32 base = arg & REG_MASK; sljit_s32 tmp_r = (flags & MEM_USE_TMP2) ? TMP_REG2 : TMP_REG1; sljit_sw offset, argw_hi; -#if defined __riscv_zba sljit_ins ins = ADD; -#endif /* __riscv_zba */ SLJIT_ASSERT(arg & SLJIT_MEM); if (!(next_arg & SLJIT_MEM)) { @@ -1161,20 +1623,22 @@ static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sl if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) { argw &= 0x3; -#if defined __riscv_zba - switch (argw) { - case 1: - ins = SH1ADD; - break; - case 2: - ins = SH2ADD; - break; - case 3: - ins = SH3ADD; - break; + if (RISCV_HAS_BITMANIP_A(93)) { + switch (argw) { + case 1: + ins = SH1ADD; + break; + case 2: + ins = SH2ADD; + break; + case 3: + ins = SH3ADD; + break; + } + FAIL_IF(push_inst(compiler, ins | RD(tmp_r) | RS1(OFFS_REG(arg)) | RS2(base))); + return push_mem_inst(compiler, flags, reg, tmp_r, 0); } - FAIL_IF(push_inst(compiler, ins | RD(tmp_r) | RS1(OFFS_REG(arg)) | RS2(base))); -#else /* !__riscv_zba */ + /* Using the cache. */ if (argw == compiler->cache_argw) { if (arg == compiler->cache_arg) @@ -1206,7 +1670,6 @@ static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sl } else FAIL_IF(push_inst(compiler, ADD | RD(tmp_r) | RS1(base) | RS2(!argw ? OFFS_REG(arg) : TMP_REG3))); -#endif /* __riscv_zba */ return push_mem_inst(compiler, flags, reg, tmp_r, 0); } @@ -1294,7 +1757,27 @@ static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, slji #define WORD_32 0x08 #define IMM_EXTEND(v) (IMM_I((op & SLJIT_32) ? (v) : (32 + (v)))) #endif /* SLJIT_CONFIG_RISCV_32 */ -#ifndef __riscv_zbb + +static sljit_s32 emit_add(struct sljit_compiler *compiler, sljit_ins word, sljit_s32 dst, sljit_s32 src1, sljit_sw src2) +{ + SLJIT_UNUSED_ARG(word); + + if (dst == src2) { + src2 = src1; + src1 = dst; + } + + if (RISCV_HAS_COMPRESSED(200) && dst == src1) { + if (WORD == 0 && src2 != 0) + return push_inst16(compiler, C_ADD | C_RD(dst) | C_RS2(src2)); + + if (WORD == 0x8 && C_IS_R3(dst) && C_IS_R3(src2)) + return push_inst16(compiler, C_ADDW | C_RS1_R3(dst) | C_RS2_R3(src2)); + } + + return push_inst(compiler, ADD | WORD | RD(dst) | RS1(src1) | RS2(src2)); +} + static sljit_s32 emit_clz_ctz(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 dst, sljit_sw src) { sljit_s32 is_clz = (GET_OPCODE(op) == SLJIT_CLZ); @@ -1378,7 +1861,11 @@ static sljit_s32 emit_rev(struct sljit_compiler *compiler, sljit_s32 op, sljit_s FAIL_IF(push_inst(compiler, SRLI | WORD_32 | RD(TMP_REG1) | RS1(dst) | IMM_I(8))); FAIL_IF(push_inst(compiler, AND | RD(dst) | RS1(dst) | RS2(OTHER_FLAG))); FAIL_IF(push_inst(compiler, AND | RD(TMP_REG1) | RS1(TMP_REG1) | RS2(OTHER_FLAG))); - FAIL_IF(push_inst(compiler, SLLI | WORD_32 | RD(dst) | RS1(dst) | IMM_I(8))); +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + FAIL_IF(push_inst(compiler, SLLI | (GET_OPCODE(op) == SLJIT_REV_S32 ? WORD_32 : 0) | RD(dst) | RS1(dst) | IMM_I(8))); +#else /* !SLJIT_CONFIG_RISCV_64 */ + FAIL_IF(push_inst(compiler, SLLI | RD(dst) | RS1(dst) | IMM_I(8))); +#endif /* SLJIT_CONFIG_RISCV_64 */ return push_inst(compiler, OR | RD(dst) | RS1(dst) | RS2(TMP_REG1)); } @@ -1397,26 +1884,33 @@ static sljit_s32 emit_rev16(struct sljit_compiler *compiler, sljit_s32 op, sljit FAIL_IF(push_inst(compiler, (GET_OPCODE(op) == SLJIT_REV_U16 ? SRLI : SRAI) | WORD | RD(dst) | RS1(dst) | IMM_I(word_size - 16))); return push_inst(compiler, OR | RD(dst) | RS1(dst) | RS2(TMP_REG1)); } -#endif /* !__riscv_zbb */ -#define EMIT_LOGICAL(op_imm, op_reg) \ +#define EMIT_LOGICAL(op_imm, op_c_imm, op_reg, op_c_reg) \ if (flags & SRC2_IMM) { \ if (op & SLJIT_SET_Z) \ FAIL_IF(push_inst(compiler, op_imm | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(src2))); \ - if (!(flags & UNUSED_DEST)) \ - FAIL_IF(push_inst(compiler, op_imm | RD(dst) | RS1(src1) | IMM_I(src2))); \ - } \ - else { \ + if (!(flags & UNUSED_DEST)) { \ + if (op_c_imm != 0 && RISCV_HAS_COMPRESSED(200) && dst == src1 && src2 <= SIMM16_MAX && src2 >= SIMM16_MIN && C_IS_R3(dst)) \ + FAIL_IF(push_inst16(compiler, op_c_imm | C_RS1_R3(dst) | C_IMM_I(src2))); \ + else \ + FAIL_IF(push_inst(compiler, op_imm | RD(dst) | RS1(src1) | IMM_I(src2))); \ + } \ + } else { \ + if (dst == src2) { \ + src2 = src1; \ + src1 = dst; \ + } \ + \ if (op & SLJIT_SET_Z) \ FAIL_IF(push_inst(compiler, op_reg | RD(EQUAL_FLAG) | RS1(src1) | RS2(src2))); \ - if (!(flags & UNUSED_DEST)) \ - FAIL_IF(push_inst(compiler, op_reg | RD(dst) | RS1(src1) | RS2(src2))); \ + if (!(flags & UNUSED_DEST)) { \ + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && C_IS_R3(dst) && C_IS_R3(src2)) \ + FAIL_IF(push_inst16(compiler, op_c_reg | C_RS1_R3(dst) | C_RS2_R3(src2))); \ + else \ + FAIL_IF(push_inst(compiler, op_reg | RD(dst) | RS1(src1) | RS2(src2))); \ + } \ } -#define EMIT_SHIFT(imm, reg) \ - op_imm = (imm); \ - op_reg = (reg); - static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 flags, sljit_s32 dst, sljit_s32 src1, sljit_sw src2) { @@ -1431,9 +1925,16 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl switch (GET_OPCODE(op)) { case SLJIT_MOV: SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); - if (dst != src2) + if (dst == src2) + return SLJIT_SUCCESS; + + if (!RISCV_HAS_COMPRESSED(200)) return push_inst(compiler, ADDI | RD(dst) | RS1(src2) | IMM_I(0)); - return SLJIT_SUCCESS; + + /* Revert the x0 to immediate 0. */ + if (src2 == 0) + return push_inst16(compiler, C_LI | C_RD(dst)); + return push_inst16(compiler, C_MV | C_RD(dst) | C_RS2(src2)); case SLJIT_MOV_U8: SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); @@ -1443,9 +1944,9 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl return SLJIT_SUCCESS; case SLJIT_MOV_S8: -#if defined __riscv_zbb - return push_inst(compiler, SEXTB | RD(dst) | RS1(src2)); -#else /* !__riscv_zbb */ + if (RISCV_HAS_BITMANIP_B(93)) + return push_inst(compiler, SEXTB | RD(dst) | RS1(src2)); + SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { FAIL_IF(push_inst(compiler, SLLI | WORD | RD(dst) | RS1(src2) | IMM_EXTEND(24))); @@ -1453,12 +1954,11 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl } SLJIT_ASSERT(dst == src2); return SLJIT_SUCCESS; -#endif /* __riscv_zbb */ case SLJIT_MOV_U16: -#if defined __riscv_zbb - return push_inst(compiler, ZEXTH | RD(dst) | RS1(src2)); -#else /* !__riscv_zbb */ + if (RISCV_HAS_BITMANIP_B(93)) + return push_inst(compiler, ZEXTH | RD(dst) | RS1(src2)); + SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { FAIL_IF(push_inst(compiler, SLLI | WORD | RD(dst) | RS1(src2) | IMM_EXTEND(16))); @@ -1466,12 +1966,11 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl } SLJIT_ASSERT(dst == src2); return SLJIT_SUCCESS; -#endif /* __riscv_zbb */ case SLJIT_MOV_S16: -#if defined __riscv_zbb - return push_inst(compiler, SEXTH | RD(dst) | RS1(src2)); -#else /* !__riscv_zbb */ + if (RISCV_HAS_BITMANIP_B(93)) + return push_inst(compiler, SEXTH | RD(dst) | RS1(src2)); + SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { FAIL_IF(push_inst(compiler, SLLI | WORD | RD(dst) | RS1(src2) | IMM_EXTEND(16))); @@ -1479,7 +1978,6 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl } SLJIT_ASSERT(dst == src2); return SLJIT_SUCCESS; -#endif /* !__riscv_zbb */ #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) case SLJIT_MOV_U32: @@ -1493,74 +1991,54 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl case SLJIT_MOV_S32: SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); - if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) + if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { + if (RISCV_HAS_COMPRESSED(200) && dst == src2) + return push_inst16(compiler, C_ADDIW | C_RD(dst)); return push_inst(compiler, ADDI | 0x8 | RD(dst) | RS1(src2) | IMM_I(0)); + } SLJIT_ASSERT(dst == src2); return SLJIT_SUCCESS; #endif /* SLJIT_CONFIG_RISCV_64 */ case SLJIT_CLZ: -#if defined __riscv_zbb - return push_inst(compiler, CLZ | WORD | RD(dst) | RS1(src2)); -#endif /* __riscv_zbb */ case SLJIT_CTZ: -#if defined __riscv_zbb - return push_inst(compiler, CTZ | WORD | RD(dst) | RS1(src2)); -#else /* !__riscv_zbb */ SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); + if (RISCV_HAS_BITMANIP_B(93)) + return push_inst(compiler, ((GET_OPCODE(op) == SLJIT_CLZ) ? CLZ : CTZ) | WORD | RD(dst) | RS1(src2)); + return emit_clz_ctz(compiler, op, dst, src2); -#endif /* __riscv_zbb */ case SLJIT_REV: -#if defined __riscv_zbb - SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); - FAIL_IF(push_inst(compiler, REV8 | RD(dst) | RS1(src2))); -#if defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64 - if (op & SLJIT_32) - return push_inst(compiler, SRAI | RD(dst) | RS1(dst) | IMM_I(32)); - return SLJIT_SUCCESS; -#else /* !SLJIT_CONFIG_RISCV_64 */ - return SLJIT_SUCCESS; -#endif /* SLJIT_CONFIG_RISCV_64 */ -#endif /* __riscv_zbb */ case SLJIT_REV_S32: -#if ((defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) || defined __riscv_zbb) case SLJIT_REV_U32: -#endif /* SLJIT_CONFIG_RISCV_32 || __riscv_zbb */ SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); -#if defined __riscv_zbb - FAIL_IF(push_inst(compiler, REV8 | RD(dst) | RS1(src2))); + if (RISCV_HAS_BITMANIP_B(93)) { #if defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64 - return push_inst(compiler, (GET_OPCODE(op) == SLJIT_REV_U32 ? SRLI : SRAI )| RD(dst) | RS1(dst) | IMM_I(32)); + FAIL_IF(push_inst(compiler, REV8 | RD(dst) | RS1(src2))); + if ((op & SLJIT_32) || GET_OPCODE(op) != SLJIT_REV) + return push_inst(compiler, (GET_OPCODE(op) == SLJIT_REV_U32 ? SRLI : SRAI)| RD(dst) | RS1(dst) | IMM_I(32)); + return SLJIT_SUCCESS; #else /* !SLJIT_CONFIG_RISCV_64 */ - return SLJIT_SUCCESS; + return push_inst(compiler, REV8 | RD(dst) | RS1(src2)); #endif /* SLJIT_CONFIG_RISCV_64 */ -#else /* !__riscv_zbb */ + } + return emit_rev(compiler, op, dst, src2); -#endif /* __riscv_zbb */ + case SLJIT_REV_U16: case SLJIT_REV_S16: SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM)); -#if defined __riscv_zbb - FAIL_IF(push_inst(compiler, REV8 | RD(dst) | RS1(src2))); + if (RISCV_HAS_BITMANIP_B(93)) { + FAIL_IF(push_inst(compiler, REV8 | RD(dst) | RS1(src2))); #if defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64 - return push_inst(compiler, (GET_OPCODE(op) == SLJIT_REV_U16 ? SRLI : SRAI )| RD(dst) | RS1(dst) | IMM_I(48)); + return push_inst(compiler, (GET_OPCODE(op) == SLJIT_REV_U16 ? SRLI : SRAI)| RD(dst) | RS1(dst) | IMM_I(48)); #else /* !SLJIT_CONFIG_RISCV_64 */ - return push_inst(compiler, (GET_OPCODE(op) == SLJIT_REV_U16 ? SRLI : SRAI) | RD(dst) | RS1(dst) | IMM_I(16)); + return push_inst(compiler, (GET_OPCODE(op) == SLJIT_REV_U16 ? SRLI : SRAI) | RD(dst) | RS1(dst) | IMM_I(16)); #endif /* SLJIT_CONFIG_RISCV_64 */ -#else /* !__riscv_zbb */ + } + return emit_rev16(compiler, op, dst, src2); -#endif /* __riscv_zbb */ -#if ((defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) && !defined __riscv_zbb) - case SLJIT_REV_U32: - SLJIT_ASSERT(src1 == TMP_ZERO && !(flags & SRC2_IMM) && dst != TMP_REG1); - FAIL_IF(emit_rev(compiler, op, dst, src2)); - if (dst == TMP_REG2) - return SLJIT_SUCCESS; - FAIL_IF(push_inst(compiler, SLLI | RD(dst) | RS1(dst) | IMM_I(32))); - return push_inst(compiler, SRLI | RD(dst) | RS1(dst) | IMM_I(32)); -#endif /* SLJIT_CONFIG_RISCV_64 && !__riscv_zbb */ case SLJIT_ADD: /* Overflow computation (both add and sub): overflow = src1_sign ^ src2_sign ^ result_sign ^ carry_flag */ is_overflow = GET_FLAG_TYPE(op) == SLJIT_OVERFLOW; @@ -1568,19 +2046,26 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (flags & SRC2_IMM) { if (is_overflow) { - if (src2 >= 0) - FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(0))); - else + if (src2 >= 0) { + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_MV | C_RD(EQUAL_FLAG) | C_RS2(src1))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(0))); + } else FAIL_IF(push_inst(compiler, XORI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(-1))); } else if (op & SLJIT_SET_Z) FAIL_IF(push_inst(compiler, ADDI | WORD | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(src2))); /* Only the zero flag is needed. */ - if (!(flags & UNUSED_DEST) || (op & VARIABLE_FLAG_MASK)) - FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(src2))); - } - else { + if (!(flags & UNUSED_DEST) || (op & VARIABLE_FLAG_MASK)) { + SLJIT_ASSERT(src2 != 0); + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && src2 <= SIMM16_MAX && src2 >= SIMM16_MIN) + FAIL_IF(push_inst16(compiler, C_ADDI_W(WORD) | C_RD(dst) | C_IMM_I(src2))); + else + FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(src2))); + } + } else { if (is_overflow) FAIL_IF(push_inst(compiler, XOR | RD(EQUAL_FLAG) | RS1(src1) | RS2(src2))); else if (op & SLJIT_SET_Z) @@ -1599,7 +2084,7 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl /* Only the zero flag is needed. */ if (!(flags & UNUSED_DEST) || (op & VARIABLE_FLAG_MASK)) - FAIL_IF(push_inst(compiler, ADD | WORD | RD(dst) | RS1(src1) | RS2(src2))); + FAIL_IF(emit_add(compiler, WORD, dst, src1, src2)); } /* Carry is zero if a + b >= a or a + b >= b, otherwise it is 1. */ @@ -1614,8 +2099,12 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl return SLJIT_SUCCESS; FAIL_IF(push_inst(compiler, XOR | RD(TMP_REG1) | RS1(dst) | RS2(EQUAL_FLAG))); - if (op & SLJIT_SET_Z) - FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(dst) | IMM_I(0))); + if (op & SLJIT_SET_Z) { + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_MV | C_RD(EQUAL_FLAG) | C_RS2(dst))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(dst) | IMM_I(0))); + } FAIL_IF(push_inst(compiler, SRLI | WORD | RD(TMP_REG1) | RS1(TMP_REG1) | IMM_EXTEND(31))); return push_inst(compiler, XOR | RD(OTHER_FLAG) | RS1(TMP_REG1) | RS2(OTHER_FLAG)); @@ -1623,7 +2112,11 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl carry_src_r = GET_FLAG_TYPE(op) == SLJIT_CARRY; if (flags & SRC2_IMM) { - FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(src2))); + SLJIT_ASSERT(src2 != 0); + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && src2 <= SIMM16_MAX && src2 >= SIMM16_MIN) + FAIL_IF(push_inst16(compiler, C_ADDI_W(WORD) | C_RD(dst) | C_IMM_I(src2))); + else + FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(src2))); } else { if (carry_src_r != 0) { if (src1 != dst) @@ -1631,12 +2124,15 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl else if (src2 != dst) carry_src_r = (sljit_s32)src2; else { - FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(0))); + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_MV | C_RD(EQUAL_FLAG) | C_RS2(src1))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(0))); carry_src_r = EQUAL_FLAG; } } - FAIL_IF(push_inst(compiler, ADD | WORD | RD(dst) | RS1(src1) | RS2(src2))); + FAIL_IF(emit_add(compiler, WORD, dst, src1, src2)); } /* Carry is zero if a + b >= a or a + b >= b, otherwise it is 1. */ @@ -1647,7 +2143,10 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl FAIL_IF(push_inst(compiler, SLTU | RD(EQUAL_FLAG) | RS1(dst) | RS2(carry_src_r))); } - FAIL_IF(push_inst(compiler, ADD | WORD | RD(dst) | RS1(dst) | RS2(OTHER_FLAG))); + if (RISCV_HAS_COMPRESSED(200) && WORD == 0) + FAIL_IF(push_inst16(compiler, C_ADD | C_RD(dst) | C_RS2(OTHER_FLAG))); + else + FAIL_IF(push_inst(compiler, ADD | WORD | RD(dst) | RS1(dst) | RS2(OTHER_FLAG))); if (carry_src_r == 0) return SLJIT_SUCCESS; @@ -1670,8 +2169,7 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (GET_FLAG_TYPE(op) == SLJIT_LESS) { FAIL_IF(push_inst(compiler, SLTUI | RD(OTHER_FLAG) | RS1(src1) | IMM_I(src2))); is_handled = 1; - } - else if (GET_FLAG_TYPE(op) == SLJIT_SIG_LESS) { + } else if (GET_FLAG_TYPE(op) == SLJIT_SIG_LESS) { FAIL_IF(push_inst(compiler, SLTI | RD(OTHER_FLAG) | RS1(src1) | IMM_I(src2))); is_handled = 1; } @@ -1682,7 +2180,11 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (flags & SRC2_IMM) { reg = (src1 == TMP_REG1) ? TMP_REG2 : TMP_REG1; - FAIL_IF(push_inst(compiler, ADDI | RD(reg) | RS1(TMP_ZERO) | IMM_I(src2))); + if (RISCV_HAS_COMPRESSED(200) && src2 <= SIMM16_MAX && src2 >= SIMM16_MIN) + FAIL_IF(push_inst16(compiler, C_LI | C_RD(reg) | C_IMM_I(src2))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(reg) | RS1(TMP_ZERO) | IMM_I(src2))); + src2 = reg; flags &= ~SRC2_IMM; } @@ -1707,14 +2209,22 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (flags & SRC2_IMM) { if (op & SLJIT_SET_Z) FAIL_IF(push_inst(compiler, ADDI | WORD | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(-src2))); - if (!(flags & UNUSED_DEST)) - return push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(-src2)); - } - else { + if (!(flags & UNUSED_DEST)) { + src2 = -src2; + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && src2 <= SIMM16_MAX && src2 >= SIMM16_MIN) + return push_inst16(compiler, C_ADDI_W(WORD) | C_RD(dst) | C_IMM_I(src2)); + + return push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(src2)); + } + } else { if (op & SLJIT_SET_Z) FAIL_IF(push_inst(compiler, SUB | WORD | RD(EQUAL_FLAG) | RS1(src1) | RS2(src2))); - if (!(flags & UNUSED_DEST)) + if (!(flags & UNUSED_DEST)) { + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && C_IS_R3(dst) && C_IS_R3(src2)) + return push_inst16(compiler, C_SUB_W(WORD) | C_RS1_R3(dst) | C_RS2_R3(src2)); + return push_inst(compiler, SUB | WORD | RD(dst) | RS1(src1) | RS2(src2)); + } } return SLJIT_SUCCESS; } @@ -1724,22 +2234,28 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (flags & SRC2_IMM) { if (is_overflow) { - if (src2 >= 0) - FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(0))); - else + if (src2 >= 0) { + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_MV | C_RD(EQUAL_FLAG) | C_RS2(src1))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(0))); + } else FAIL_IF(push_inst(compiler, XORI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(-1))); - } - else if (op & SLJIT_SET_Z) + } else if (op & SLJIT_SET_Z) FAIL_IF(push_inst(compiler, ADDI | WORD | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(-src2))); if (is_overflow || is_carry) FAIL_IF(push_inst(compiler, SLTUI | RD(OTHER_FLAG) | RS1(src1) | IMM_I(src2))); /* Only the zero flag is needed. */ - if (!(flags & UNUSED_DEST) || (op & VARIABLE_FLAG_MASK)) - FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(-src2))); - } - else { + if (!(flags & UNUSED_DEST) || (op & VARIABLE_FLAG_MASK)) { + src2 = -src2; + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && src2 <= SIMM16_MAX && src2 >= SIMM16_MIN) + FAIL_IF(push_inst16(compiler, C_ADDI_W(WORD) | C_RD(dst) | C_IMM_I(src2))); + else + FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(src2))); + } + } else { if (is_overflow) FAIL_IF(push_inst(compiler, XOR | RD(EQUAL_FLAG) | RS1(src1) | RS2(src2))); else if (op & SLJIT_SET_Z) @@ -1749,16 +2265,24 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl FAIL_IF(push_inst(compiler, SLTU | RD(OTHER_FLAG) | RS1(src1) | RS2(src2))); /* Only the zero flag is needed. */ - if (!(flags & UNUSED_DEST) || (op & VARIABLE_FLAG_MASK)) - FAIL_IF(push_inst(compiler, SUB | WORD | RD(dst) | RS1(src1) | RS2(src2))); + if (!(flags & UNUSED_DEST) || (op & VARIABLE_FLAG_MASK)) { + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && C_IS_R3(dst) && C_IS_R3(src2)) + FAIL_IF(push_inst16(compiler, C_SUB_W(WORD) | C_RS1_R3(dst) | C_RS2_R3(src2))); + else + FAIL_IF(push_inst(compiler, SUB | WORD | RD(dst) | RS1(src1) | RS2(src2))); + } } if (!is_overflow) return SLJIT_SUCCESS; FAIL_IF(push_inst(compiler, XOR | RD(TMP_REG1) | RS1(dst) | RS2(EQUAL_FLAG))); - if (op & SLJIT_SET_Z) - FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(dst) | IMM_I(0))); + if (op & SLJIT_SET_Z) { + if (RISCV_HAS_COMPRESSED(200)) + FAIL_IF(push_inst16(compiler, C_MV | C_RD(EQUAL_FLAG) | C_RS2(dst))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(EQUAL_FLAG) | RS1(dst) | IMM_I(0))); + } FAIL_IF(push_inst(compiler, SRLI | WORD | RD(TMP_REG1) | RS1(TMP_REG1) | IMM_EXTEND(31))); return push_inst(compiler, XOR | RD(OTHER_FLAG) | RS1(TMP_REG1) | RS2(OTHER_FLAG)); @@ -1775,13 +2299,19 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (is_carry) FAIL_IF(push_inst(compiler, SLTUI | RD(EQUAL_FLAG) | RS1(src1) | IMM_I(src2))); - FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(-src2))); - } - else { + src2 = -src2; + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && src2 <= SIMM16_MAX && src2 >= SIMM16_MIN) + FAIL_IF(push_inst16(compiler, C_ADDI_W(WORD) | C_RD(dst) | C_IMM_I(src2))); + else + FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(src2))); + } else { if (is_carry) FAIL_IF(push_inst(compiler, SLTU | RD(EQUAL_FLAG) | RS1(src1) | RS2(src2))); - FAIL_IF(push_inst(compiler, SUB | WORD | RD(dst) | RS1(src1) | RS2(src2))); + if (RISCV_HAS_COMPRESSED(200) && dst == src1 && C_IS_R3(dst) && C_IS_R3(src2)) + FAIL_IF(push_inst16(compiler, C_SUB_W(WORD) | C_RS1_R3(dst) | C_RS2_R3(src2))); + else + FAIL_IF(push_inst(compiler, SUB | WORD | RD(dst) | RS1(src1) | RS2(src2))); } if (is_carry) @@ -1818,46 +2348,51 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl return push_inst(compiler, SUB | RD(OTHER_FLAG) | RS1(EQUAL_FLAG) | RS2(OTHER_FLAG)); case SLJIT_AND: - EMIT_LOGICAL(ANDI, AND); + EMIT_LOGICAL(ANDI, C_ANDI, AND, C_AND); return SLJIT_SUCCESS; case SLJIT_OR: - EMIT_LOGICAL(ORI, OR); + EMIT_LOGICAL(ORI, 0, OR, C_OR); return SLJIT_SUCCESS; case SLJIT_XOR: - EMIT_LOGICAL(XORI, XOR); + EMIT_LOGICAL(XORI, 0, XOR, C_XOR); return SLJIT_SUCCESS; case SLJIT_SHL: case SLJIT_MSHL: - EMIT_SHIFT(SLLI, SLL); + op_imm = SLLI; + op_reg = SLL; break; case SLJIT_LSHR: case SLJIT_MLSHR: - EMIT_SHIFT(SRLI, SRL); + op_imm = SRLI; + op_reg = SRL; break; case SLJIT_ASHR: case SLJIT_MASHR: - EMIT_SHIFT(SRAI, SRA); + op_imm = SRAI; + op_reg = SRA; break; case SLJIT_ROTL: case SLJIT_ROTR: if (flags & SRC2_IMM) { SLJIT_ASSERT(src2 != 0); -#if defined __riscv_zbb - if (GET_OPCODE(op) == SLJIT_ROTL) { + + if (RISCV_HAS_BITMANIP_B(93)) { + if (GET_OPCODE(op) == SLJIT_ROTL) { #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) - src2 = ((op & SLJIT_32) ? 32 : 64) - src2; + src2 = ((op & SLJIT_32) ? 32 : 64) - src2; #else /* !SLJIT_CONFIG_RISCV_64 */ - src2 = 32 - src2; + src2 = 32 - src2; #endif /* SLJIT_CONFIG_RISCV_64 */ + } + return push_inst(compiler, RORI | WORD | RD(dst) | RS1(src1) | IMM_I(src2)); } - return push_inst(compiler, RORI | WORD | RD(dst) | RS1(src1) | IMM_I(src2)); -#else /* !__riscv_zbb */ + op_imm = (GET_OPCODE(op) == SLJIT_ROTL) ? SLLI : SRLI; FAIL_IF(push_inst(compiler, op_imm | WORD | RD(OTHER_FLAG) | RS1(src1) | IMM_I(src2))); @@ -1869,12 +2404,11 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl op_imm = (GET_OPCODE(op) == SLJIT_ROTL) ? SRLI : SLLI; FAIL_IF(push_inst(compiler, op_imm | WORD | RD(dst) | RS1(src1) | IMM_I(src2))); return push_inst(compiler, OR | RD(dst) | RS1(dst) | RS2(OTHER_FLAG)); -#endif /* !__riscv_zbb */ } -#if defined __riscv_zbb - return push_inst(compiler, (GET_OPCODE(op) == SLJIT_ROTL ? ROL : ROR) | WORD | RD(dst) | RS1(src1) | RS2(src2)); -#else /* !__riscv_zbb */ + if (RISCV_HAS_BITMANIP_B(93)) + return push_inst(compiler, (GET_OPCODE(op) == SLJIT_ROTL ? ROL : ROR) | WORD | RD(dst) | RS1(src1) | RS2(src2)); + if (src2 == TMP_ZERO) { if (dst != src1) return push_inst(compiler, ADDI | WORD | RD(dst) | RS1(src1) | IMM_I(0)); @@ -1887,7 +2421,6 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl op_reg = (GET_OPCODE(op) == SLJIT_ROTL) ? SRL : SLL; FAIL_IF(push_inst(compiler, op_reg | WORD | RD(dst) | RS1(src1) | RS2(EQUAL_FLAG))); return push_inst(compiler, OR | RD(dst) | RS1(dst) | RS2(OTHER_FLAG)); -#endif /* !riscv_zbb */ default: SLJIT_UNREACHABLE(); return SLJIT_SUCCESS; @@ -1899,6 +2432,15 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl if (flags & UNUSED_DEST) return SLJIT_SUCCESS; + + if (RISCV_HAS_COMPRESSED(200) && WORD == 0 && dst == src1) { + if (op_imm == SLLI) + return push_inst16(compiler, C_SLLI | C_RD(dst) | C_IMM_I(src2)); + + if (C_IS_R3(dst)) + return push_inst16(compiler, (op_imm == SRLI ? C_SRLI : C_SRAI) | C_RS1_R3(dst) | C_IMM_I(src2)); + } + return push_inst(compiler, op_imm | WORD | RD(dst) | RS1(src1) | IMM_I(src2)); } @@ -2051,9 +2593,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compile switch (GET_OPCODE(op)) { case SLJIT_BREAKPOINT: + if (RISCV_HAS_COMPRESSED(200)) + return push_inst16(compiler, C_EBREAK); return push_inst(compiler, EBREAK); case SLJIT_NOP: - return push_inst(compiler, ADDI | RD(TMP_ZERO) | RS1(TMP_ZERO) | IMM_I(0)); + if (RISCV_HAS_COMPRESSED(200)) + return push_inst16(compiler, C_NOP); + return push_inst(compiler, NOP); case SLJIT_LMUL_UW: FAIL_IF(push_inst(compiler, ADDI | RD(TMP_REG1) | RS1(SLJIT_R1) | IMM_I(0))); FAIL_IF(push_inst(compiler, MULHU | RD(SLJIT_R1) | RS1(SLJIT_R0) | RS2(SLJIT_R1))); @@ -2337,6 +2883,76 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst(compiler, OR | RD(dst_reg) | RS1(dst_reg) | RS2(TMP_REG1)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r, tmp_r; + sljit_ins ins; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= (sljit_sw)((sizeof(sljit_sw) * 8) - 1); + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + if (src2 & SLJIT_MEM) { + FAIL_IF(emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, TMP_REG2, src2, src2w, src1, src1w)); + src2 = TMP_REG2; + } + + if (src1 == SLJIT_IMM) { + FAIL_IF(load_immediate(compiler, TMP_REG1, src1w, TMP_REG3)); + src1 = TMP_REG1; + } else if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, src1, src1w, dst, dstw)); + src1 = TMP_REG1; + } + + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + ins = 0; + + if (RISCV_HAS_BITMANIP_A(93)) { + switch (shift_arg) { + case 1: + ins = SH1ADD; + break; + case 2: + ins = SH2ADD; + break; + case 3: + ins = SH3ADD; + break; + } + } + + if (ins == 0) { + tmp_r = (src1 == TMP_REG1) ? TMP_REG2 : TMP_REG1; + FAIL_IF(push_inst(compiler, SLLI | RD(tmp_r) | RS1(src2) | IMM_I(shift_arg))); + FAIL_IF(push_inst(compiler, ADD | RD(dst_r) | RS1(src1) | RS2(tmp_r))); + } else { + FAIL_IF(push_inst(compiler, ins | RD(dst_r) | RS1(src2) | RS2(src1))); + } + + if (dst & SLJIT_MEM) + return emit_op_mem2(compiler, WORD_DATA, dst_r, dst, dstw, 0, 0); + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -2346,9 +2962,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_RETURN: - if (FAST_IS_REG(src)) - FAIL_IF(push_inst(compiler, ADDI | RD(RETURN_ADDR_REG) | RS1(src) | IMM_I(0))); - else + if (FAST_IS_REG(src)) { + if (src != RETURN_ADDR_REG) + FAIL_IF(push_inst(compiler, ADDI | RD(RETURN_ADDR_REG) | RS1(src) | IMM_I(0))); + } else FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG, src, srcw)); return push_inst(compiler, JALR | RD(TMP_ZERO) | RS1(RETURN_ADDR_REG) | IMM_I(0)); @@ -2375,8 +2992,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_ENTER: - if (FAST_IS_REG(dst)) + if (FAST_IS_REG(dst)) { + if (dst == RETURN_ADDR_REG) + return SLJIT_SUCCESS; return push_inst(compiler, ADDI | RD(dst) | RS1(RETURN_ADDR_REG) | IMM_I(0)); + } SLJIT_ASSERT(RETURN_ADDR_REG == TMP_REG2); break; @@ -2413,6 +3033,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *c CHECK_ERROR(); CHECK(check_sljit_emit_op_custom(compiler, instruction, size)); + if (size == 2) + return push_inst16(compiler, *(sljit_u16*)instruction); + return push_inst(compiler, *(sljit_ins*)instruction); } @@ -2749,11 +3372,80 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } -#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) -#define BRANCH_LENGTH ((sljit_ins)(3 * sizeof(sljit_ins)) << 7) -#else /* !SLJIT_CONFIG_RISCV_32 */ -#define BRANCH_LENGTH ((sljit_ins)(7 * sizeof(sljit_ins)) << 7) -#endif /* SLJIT_CONFIG_RISCV_32 */ +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask = 0, i; + struct sljit_label *label = NULL; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (RISCV_HAS_COMPRESSED(200)) { + if (alignment <= SLJIT_LABEL_ALIGN_2) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_u16); + + for (i = (mask >> 1); i != 0; i--) + PTR_FAIL_IF(push_inst16(compiler, C_NOP)); + } + } else { + if (alignment <= SLJIT_LABEL_ALIGN_4) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_ins); + + for (i = (mask >> 2); i != 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + } + } + + if (label == NULL) { + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + if (RISCV_HAS_COMPRESSED(200)) { + for (i = (buffers->size + 1) >> 1; i > 0; i--) + PTR_FAIL_IF(push_inst16(compiler, C_NOP)); + } else { + for (i = (buffers->size + 3) >> 2; i > 0; i--) + PTR_FAIL_IF(push_inst(compiler, NOP)); + } + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} static sljit_ins get_jump_instruction(sljit_s32 type) { @@ -2826,14 +3518,11 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compile } jump->addr = compiler->size; - inst = JALR | RS1(TMP_REG1) | IMM_I(0); - if (type >= SLJIT_FAST_CALL) { + if (type >= SLJIT_FAST_CALL) jump->flags |= IS_CALL; - inst |= RD(RETURN_ADDR_REG); - } - PTR_FAIL_IF(push_inst(compiler, inst)); + PTR_FAIL_IF(push_inst16(compiler, 0)); /* Maximum number of instructions required for generating a constant. */ compiler->size += JUMP_MAX_SIZE - 1; @@ -2913,9 +3602,37 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler switch (type) { case SLJIT_EQUAL: + if (RISCV_HAS_COMPRESSED(200)) { + if (src1 == TMP_ZERO && C_IS_R3(src2)) { + inst = C_BNEZ | C_RS1_R3(src2) | BRANCH16_LENGTH; + jump->flags |= IS_COND16; + break; + } + + if (src2 == TMP_ZERO && C_IS_R3(src1)) { + inst = C_BNEZ | C_RS1_R3(src1) | BRANCH16_LENGTH; + jump->flags |= IS_COND16; + break; + } + } + inst = BNE | RS1(src1) | RS2(src2) | BRANCH_LENGTH; break; case SLJIT_NOT_EQUAL: + if (RISCV_HAS_COMPRESSED(200)) { + if (src1 == TMP_ZERO && C_IS_R3(src2)) { + inst = C_BEQZ | C_RS1_R3(src2) | BRANCH16_LENGTH; + jump->flags |= IS_COND16; + break; + } + + if (src2 == TMP_ZERO && C_IS_R3(src1)) { + inst = C_BEQZ | C_RS1_R3(src1) | BRANCH16_LENGTH; + jump->flags |= IS_COND16; + break; + } + } + inst = BEQ | RS1(src1) | RS2(src2) | BRANCH_LENGTH; break; case SLJIT_LESS: @@ -2939,23 +3656,25 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler case SLJIT_SIG_GREATER: inst = BGE | RS1(src2) | RS2(src1) | BRANCH_LENGTH; break; - case SLJIT_SIG_LESS_EQUAL: + default: /* SLJIT_SIG_LESS_EQUAL */ inst = BLT | RS1(src2) | RS2(src1) | BRANCH_LENGTH; break; } - PTR_FAIL_IF(push_inst(compiler, inst)); + SLJIT_COMPILE_ASSERT((C_BEQZ & 0x2) == 0 && (C_BNEZ & 0x2) == 0, branch16_bit_error); + if (RISCV_COMPRESSED_CHECK((inst & 0x2) == 0)) + PTR_FAIL_IF(push_inst16(compiler, (sljit_u16)inst)); + else + PTR_FAIL_IF(push_inst(compiler, inst)); jump->addr = compiler->size; - PTR_FAIL_IF(push_inst(compiler, JALR | RD(TMP_ZERO) | RS1(TMP_REG1) | IMM_I(0))); + PTR_FAIL_IF(push_inst16(compiler, 0)); /* Maximum number of instructions required for generating a constant. */ compiler->size += JUMP_MAX_SIZE - 1; return jump; } -#undef BRANCH_LENGTH - SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { struct sljit_jump *jump; @@ -2969,6 +3688,10 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG1, src, srcw)); src = TMP_REG1; } + + if (RISCV_HAS_COMPRESSED(200)) + return push_inst16(compiler, ((type >= SLJIT_FAST_CALL) ? C_JALR : C_JR) | C_RD(src)); + return push_inst(compiler, JALR | RD((type >= SLJIT_FAST_CALL) ? RETURN_ADDR_REG : TMP_ZERO) | RS1(src) | IMM_I(0)); } @@ -2979,7 +3702,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compi jump->u.target = (sljit_uw)srcw; jump->addr = compiler->size; - FAIL_IF(push_inst(compiler, JALR | RD((type >= SLJIT_FAST_CALL) ? RETURN_ADDR_REG : TMP_ZERO) | RS1(TMP_REG1) | IMM_I(0))); + FAIL_IF(push_inst16(compiler, 0)); /* Maximum number of instructions required for generating a constant. */ compiler->size += JUMP_MAX_SIZE - 1; @@ -3110,8 +3833,11 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp sljit_s32 src1, sljit_sw src1w, sljit_s32 src2_reg) { - sljit_ins *ptr; + sljit_u16 *ptr; sljit_uw size; + sljit_ins ins; + sljit_s32 cond_is_1; + sljit_s32 is_compare = (type & SLJIT_COMPARE_SELECT); #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) sljit_ins word = (sljit_ins)(type & SLJIT_32) >> 5; sljit_s32 inp_flags = ((type & SLJIT_32) ? INT_DATA : WORD_DATA) | LOAD_DATA; @@ -3126,13 +3852,92 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp ADJUST_LOCAL_OFFSET(src1, src1w); +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + if (src1 == SLJIT_IMM && word) + src1w = (sljit_s32)src1w; +#endif /* SLJIT_CONFIG_RISCV_64 */ + + type &= ~(SLJIT_32 | SLJIT_COMPARE_SELECT); + + if (is_compare || RISCV_HAS_ICOND(100)) { + if (src1 & SLJIT_MEM) { + FAIL_IF(emit_op_mem(compiler, inp_flags, TMP_REG1, src1, src1w)); + src1 = TMP_REG1; + src1w = 0; + } else if (src1 == SLJIT_IMM) { + if (src1w == 0) { + src1 = TMP_ZERO; + } else { + FAIL_IF(load_immediate(compiler, TMP_REG1, src1w, TMP_REG3)); + src1 = TMP_REG1; + src1w = 0; + } + } + + if (RISCV_HAS_BITMANIP_B(93) && is_compare) { + switch (type) { + case SLJIT_LESS: + case SLJIT_LESS_EQUAL: + return push_inst(compiler, MINU | RD(dst_reg) | RS1(src1) | RS2(src2_reg)); + case SLJIT_GREATER: + case SLJIT_GREATER_EQUAL: + return push_inst(compiler, MAXU | RD(dst_reg) | RS1(src1) | RS2(src2_reg)); + case SLJIT_SIG_LESS: + case SLJIT_SIG_LESS_EQUAL: + return push_inst(compiler, MIN | RD(dst_reg) | RS1(src1) | RS2(src2_reg)); + default: + return push_inst(compiler, MAX | RD(dst_reg) | RS1(src1) | RS2(src2_reg)); + } + } + + if (RISCV_HAS_ICOND(100)) { + if (is_compare) { + cond_is_1 = 0; + + switch (type) { + case SLJIT_LESS: + case SLJIT_LESS_EQUAL: + cond_is_1 = 1; + SLJIT_FALLTHROUGH + case SLJIT_GREATER: + case SLJIT_GREATER_EQUAL: + FAIL_IF(push_inst(compiler, SLTU | RD(OTHER_FLAG) | RS1(src1) | RS2(src2_reg))); + break; + case SLJIT_SIG_LESS: + case SLJIT_SIG_LESS_EQUAL: + cond_is_1 = 1; + SLJIT_FALLTHROUGH + default: + FAIL_IF(push_inst(compiler, SLT | RD(OTHER_FLAG) | RS1(src1) | RS2(src2_reg))); + break; + } + + type = OTHER_FLAG; + } else { + /* BEQ instruction (type is inverted). */ + cond_is_1 = (get_jump_instruction(type) & F3(0x1)) == 0; + type = (type == SLJIT_EQUAL || type == SLJIT_NOT_EQUAL) ? EQUAL_FLAG : OTHER_FLAG; + } + + if (src1 == TMP_ZERO) + return push_inst(compiler, (cond_is_1 ? CZERO_NEZ : CZERO_EQZ) | RD(dst_reg) | RS1(src2_reg) | RS2(type)); + + FAIL_IF(push_inst(compiler, (cond_is_1 ? CZERO_EQZ : CZERO_NEZ) | RD(TMP_REG1) | RS1(src1) | RS2(type))); + FAIL_IF(push_inst(compiler, (cond_is_1 ? CZERO_NEZ : CZERO_EQZ) | RD(dst_reg) | RS1(src2_reg) | RS2(type))); + return push_inst(compiler, OR | RD(dst_reg) | RS1(dst_reg) | RS2(TMP_REG1)); + } + } + if (dst_reg != src2_reg) { if (dst_reg == src1) { src1 = src2_reg; src1w = 0; - type ^= 0x1; + src2_reg = dst_reg; + if (!is_compare) + type ^= 0x1; } else { if (ADDRESSING_DEPENDS_ON(src1, dst_reg)) { + SLJIT_ASSERT(!(type & SLJIT_COMPARE_SELECT)); FAIL_IF(push_inst(compiler, ADDI | RD(TMP_REG1) | RS1(dst_reg) | IMM_I(0))); if ((src1 & REG_MASK) == dst_reg) @@ -3146,25 +3951,77 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp } } + if (src1 == SLJIT_IMM && (src1w <= 0 && src1w >= -1)) { + src1 = OTHER_FLAG; + + if (type == SLJIT_EQUAL || type == SLJIT_NOT_EQUAL) { + FAIL_IF(push_inst(compiler, SLTUI | RD(TMP_REG1) | RS1(EQUAL_FLAG) | IMM_I(1))); + src1 = TMP_REG1; + cond_is_1 = (type == SLJIT_EQUAL); + } else { + /* BEQ instruction (type is inverted). */ + cond_is_1 = (get_jump_instruction(type) & F3(0x1)) == 0; + } + + if (src1w == 0) { + if (cond_is_1) + FAIL_IF(push_inst(compiler, ADDI | RD(TMP_REG1) | RS1(src1) | IMM_I(-1))); + else + FAIL_IF(push_inst(compiler, SUB | RD(TMP_REG1) | RS1(TMP_ZERO) | RS2(src1))); + + return push_inst(compiler, AND | RD(dst_reg) | RS1(dst_reg) | RS2(TMP_REG1)); + } + + if (cond_is_1) + FAIL_IF(push_inst(compiler, SUB | RD(TMP_REG1) | RS1(TMP_ZERO) | RS2(src1))); + else + FAIL_IF(push_inst(compiler, ADDI | RD(TMP_REG1) | RS1(src1) | IMM_I(-1))); + + return push_inst(compiler, OR | RD(dst_reg) | RS1(dst_reg) | RS2(TMP_REG1)); + } + size = compiler->size; - ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins)); + ptr = (sljit_u16 *)ensure_buf(compiler, sizeof(sljit_ins)); FAIL_IF(!ptr); - compiler->size++; + compiler->size += 2; if (src1 & SLJIT_MEM) { FAIL_IF(emit_op_mem(compiler, inp_flags, dst_reg, src1, src1w)); } else if (src1 == SLJIT_IMM) { -#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) - if (word) - src1w = (sljit_s32)src1w; -#endif /* SLJIT_CONFIG_RISCV_64 */ FAIL_IF(load_immediate(compiler, dst_reg, src1w, TMP_REG1)); } else FAIL_IF(push_inst(compiler, ADDI | WORD | RD(dst_reg) | RS1(src1) | IMM_I(0))); size = compiler->size - size; - *ptr = get_jump_instruction(type & ~SLJIT_32) | (sljit_ins)((size & 0x7) << 9) | (sljit_ins)((size >> 3) << 25); + + if (is_compare) { + switch (type) { + case SLJIT_LESS: + case SLJIT_LESS_EQUAL: + ins = BGEU; + break; + case SLJIT_GREATER: + case SLJIT_GREATER_EQUAL: + ins = BLTU; + break; + case SLJIT_SIG_LESS: + case SLJIT_SIG_LESS_EQUAL: + ins = BGE; + break; + default: + ins = BLT; + break; + } + + ins |= RS1(src1) | RS2(src2_reg); + } else { + ins = get_jump_instruction(type); + } + + ins |= (sljit_ins)((size & 0xf) << 8) | (sljit_ins)((size >> 4) << 25); + ptr[0] = (sljit_u16)ins; + ptr[1] = (sljit_u16)(ins >> 16); return SLJIT_SUCCESS; } @@ -3175,7 +4032,8 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *com sljit_s32 src1, sljit_sw src1w, sljit_s32 src2_freg) { - sljit_ins *ptr; + sljit_u16 *ptr; + sljit_ins ins; sljit_uw size; CHECK_ERROR(); @@ -3194,9 +4052,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *com size = compiler->size; - ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins)); + ptr = (sljit_u16 *)ensure_buf(compiler, sizeof(sljit_ins)); FAIL_IF(!ptr); - compiler->size++; + compiler->size += 2; if (src1 & SLJIT_MEM) FAIL_IF(emit_op_mem(compiler, FLOAT_DATA(type) | LOAD_DATA, dst_freg, src1, src1w)); @@ -3204,7 +4062,9 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *com FAIL_IF(push_inst(compiler, FSGNJ_S | FMT(type) | FRD(dst_freg) | FRS1(src1) | FRS2(src1))); size = compiler->size - size; - *ptr = get_jump_instruction(type & ~SLJIT_32) | (sljit_ins)((size & 0x7) << 9) | (sljit_ins)((size >> 3) << 25); + ins = get_jump_instruction(type & ~SLJIT_32) | (sljit_ins)((size & 0xf) << 8) | (sljit_ins)((size >> 4) << 25); + ptr[0] = (sljit_u16)ins; + ptr[1] = (sljit_u16)(ins >> 16); return SLJIT_SUCCESS; } @@ -3276,7 +4136,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_load(struct sljit_compiler CHECK_ERROR(); CHECK(check_sljit_emit_atomic_load(compiler, op, dst_reg, mem_reg)); - if (op & SLJIT_ATOMIC_USE_CAS) + if (!RISCV_HAS_ATOMIC(200) || (op & SLJIT_ATOMIC_USE_CAS)) return SLJIT_ERR_UNSUPPORTED; switch (GET_OPCODE(op)) { @@ -3314,7 +4174,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler CHECK_ERROR(); CHECK(check_sljit_emit_atomic_store(compiler, op, src_reg, mem_reg, temp_reg)); - if (op & SLJIT_ATOMIC_USE_CAS) + if (!RISCV_HAS_ATOMIC(200) || (op & SLJIT_ATOMIC_USE_CAS)) return SLJIT_ERR_UNSUPPORTED; switch (GET_OPCODE(op)) { @@ -3339,6 +4199,28 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return push_inst(compiler, ins | RD(OTHER_FLAG) | RS1(mem_reg) | RS2(src_reg)); } +static sljit_s32 sljit_max_vector_length = 0; + +static void init_compiler(void) +{ + sljit_sw vector_length; + sljit_s32 vector_length_log2; + + if (!RISCV_HAS_VECTOR(100)) + return; + + __asm__ __volatile__ ("csrr %0, 0xc22" : "=r" (vector_length)); + + /* Probably something is wrong. */ + if (vector_length < (1 << 3)) + return; + + vector_length_log2 = 3; + if (vector_length_log2 < 6 && vector_length > (1 << vector_length_log2)) + vector_length_log2++; + sljit_max_vector_length = vector_length_log2; +} + /* SEW = Selected element width LMUL = Vector register group multiplier @@ -3359,13 +4241,22 @@ static SLJIT_INLINE sljit_s32 sljit_emit_vsetivli(struct sljit_compiler *compile sljit_ins elem_size = (sljit_ins)SLJIT_SIMD_GET_ELEM_SIZE(type); sljit_ins avl = (sljit_ins)1 << (SLJIT_SIMD_GET_REG_SIZE(type) - elem_size); - return push_inst(compiler, VSETIVLI | RD(TMP_REG1) | (elem_size << 23) | (vlmul << 20) | (avl << 15)); + if (avl < 31) + return push_inst(compiler, VSETIVLI | RD(TMP_REG1) | (elem_size << 23) | (vlmul << 20) | (avl << 15)); + + FAIL_IF(push_inst(compiler, ADDI | RD(TMP_REG1) | RS1(TMP_ZERO) | IMM_I(avl))); + return push_inst(compiler, VSETVLI | RD(TMP_REG1) | (elem_size << 23) | (vlmul << 20) | RS1(TMP_REG1)); } static SLJIT_INLINE sljit_s32 sljit_emit_vsetivli_size(struct sljit_compiler *compiler, sljit_s32 reg_size, sljit_s32 elem_size) { sljit_ins avl = (sljit_ins)1 << (reg_size - elem_size); - return push_inst(compiler, VSETIVLI | RD(TMP_REG1) | ((sljit_ins)elem_size << 23) | (avl << 15)); + + if (avl < 31) + return push_inst(compiler, VSETIVLI | RD(TMP_REG1) | ((sljit_ins)elem_size << 23) | (avl << 15)); + + FAIL_IF(push_inst(compiler, ADDI | RD(TMP_REG1) | RS1(TMP_ZERO) | IMM_I(avl))); + return push_inst(compiler, VSETVLI | RD(TMP_REG1) | ((sljit_ins)elem_size << 23) | RS1(TMP_REG1)); } static sljit_s32 sljit_emit_vmem(struct sljit_compiler *compiler, sljit_ins ins, sljit_s32 elem_size, sljit_s32 mem, sljit_sw memw) @@ -3415,7 +4306,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_mov(struct sljit_compiler *co ADJUST_LOCAL_OFFSET(srcdst, srcdstw); - if (reg_size != 4) + if (reg_size < 3 || reg_size > sljit_max_vector_length) return SLJIT_ERR_UNSUPPORTED; if (type & SLJIT_SIMD_TEST) @@ -3484,7 +4375,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_replicate(struct sljit_compil ADJUST_LOCAL_OFFSET(src, srcw); - if (reg_size != 4) + if (reg_size < 3 || reg_size > sljit_max_vector_length) return SLJIT_ERR_UNSUPPORTED; #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) @@ -3542,7 +4433,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_mov(struct sljit_compile ADJUST_LOCAL_OFFSET(srcdst, srcdstw); - if (reg_size != 4) + if (reg_size < 3 || reg_size > sljit_max_vector_length) return SLJIT_ERR_UNSUPPORTED; #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) @@ -3645,7 +4536,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_replicate(struct sljit_c CHECK_ERROR(); CHECK(check_sljit_emit_simd_lane_replicate(compiler, type, vreg, src, src_lane_index)); - if (reg_size != 4) + if (reg_size < 3 || reg_size > sljit_max_vector_length) return SLJIT_ERR_UNSUPPORTED; if (((type & SLJIT_SIMD_FLOAT) && elem_size < 2) || elem_size > 3) @@ -3676,7 +4567,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_extend(struct sljit_compiler ADJUST_LOCAL_OFFSET(src, srcw); - if (reg_size != 4) + if (reg_size < 3 || reg_size > sljit_max_vector_length) return SLJIT_ERR_UNSUPPORTED; #if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) @@ -3741,7 +4632,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_sign(struct sljit_compiler *c ADJUST_LOCAL_OFFSET(dst, dstw); - if (reg_size != 4) + if (reg_size < 3 || reg_size > sljit_max_vector_length) return SLJIT_ERR_UNSUPPORTED; if (((type & SLJIT_SIMD_FLOAT) && elem_size < 2) || elem_size > 3) @@ -3749,7 +4640,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_sign(struct sljit_compiler *c FAIL_IF(sljit_emit_vsetivli(compiler, type, 0)); FAIL_IF(push_inst(compiler, VMV_VI | VRD(TMP_VREG1) | (0x0 << 15))); - FAIL_IF(push_inst(compiler, VMSLE_VI | VRD(TMP_VREG1) | (0x0 << 15) | VRS2(vreg))); + FAIL_IF(push_inst(compiler, VMSLE_VI | VRD(TMP_VREG1) | (0x1f << 15) | VRS2(vreg))); FAIL_IF(sljit_emit_vsetivli_size(compiler, 2, 2)); FAIL_IF(push_inst(compiler, VMV_XS | RD(dst_r) | VRS2(TMP_VREG1))); @@ -3771,7 +4662,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_op2(struct sljit_compiler *co ADJUST_LOCAL_OFFSET(src2, src2w); - if (reg_size != 4) + if (reg_size < 3 || reg_size > sljit_max_vector_length) return SLJIT_ERR_UNSUPPORTED; if ((type & SLJIT_SIMD_FLOAT) && (elem_size < 2 || elem_size > 3)) @@ -3822,13 +4713,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_op2(struct sljit_compiler *co return push_inst(compiler, ins | VRD(dst_vreg) | VRS1(src2) | VRS2(src1_vreg)); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_DATA; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -3836,34 +4730,77 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(emit_const(compiler, dst_r, init_value, ADDI | RD(dst_r))); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xf00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, ADDI | RD(dst_r) | IMM_I(init_value))); + mem_flags = BYTE_DATA; + break; + +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + case SLJIT_MOV32: + mem_flags = INT_DATA; + SLJIT_FALLTHROUGH + case SLJIT_MOV_S32: + if ((init_value & 0x800) != 0) + init_value ^= ~(sljit_sw)0xfff; + + PTR_FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(init_value & ~(sljit_sw)0xfff))); + PTR_FAIL_IF(push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(init_value))); + break; +#endif /* SLJIT_CONFIG_RISCV_64 */ + + default: + PTR_FAIL_IF(emit_const(compiler, dst_r, init_value, ADDI | RD(dst_r))); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG2, dst, dstw)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG2, dst, dstw)); return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_s32 dst_r; + sljit_s32 dst_r, target_r; + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = TMP_REG1; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, TMP_REG2, dst, dstw)); + } + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); PTR_FAIL_IF(!jump); set_mov_addr(jump, compiler, 0); - dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(push_inst(compiler, (sljit_ins)dst_r)); -#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) - compiler->size += 1; -#else /* !SLJIT_CONFIG_RISCV_32 */ - compiler->size += 5; -#endif /* SLJIT_CONFIG_RISCV_32 */ + PTR_FAIL_IF(push_inst16(compiler, (sljit_u16)target_r)); + compiler->size += JUMP_MAX_SIZE - 1; + + if (op == SLJIT_ADD_ABS_ADDR) { + if (RISCV_HAS_COMPRESSED(200)) + PTR_FAIL_IF(push_inst16(compiler, C_ADD | C_RD(dst_r) | C_RS2(TMP_REG1))); + else + PTR_FAIL_IF(push_inst(compiler, ADD | RD(dst_r) | RS1(dst_r) | RS2(TMP_REG1))); + } if (dst & SLJIT_MEM) PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG2, dst, dstw)); @@ -3871,7 +4808,48 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com return jump; } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_u16 *inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_u16*)addr; + SLJIT_ASSERT((inst[0] & 0x707f) == ADDI); + + if (new_constant & 0x100) + new_constant |= 0xf00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[1] = (sljit_u16)(new_constant << 4) | (inst[1] & 0xf); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; + +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + case SLJIT_MOV32: + case SLJIT_MOV_S32: + inst = (sljit_u16*)addr; + SLJIT_ASSERT((inst[0] & 0x7f) == LUI && (inst[2] & 0x707f) == XORI); + + if ((new_constant & 0x800) != 0) + new_constant ^= ~(sljit_sw)0xfff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 4, 0); + inst[0] = (sljit_u16)((inst[0] & 0xfff) | (new_constant & 0xf000)); + inst[1] = (sljit_u16)(new_constant >> 16); + inst[3] = (sljit_u16)(new_constant << 4) | (inst[3] & 0xf); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 4, 1); + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 4); + return; +#endif /* SLJIT_CONFIG_RISCV_64 */ + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } } diff --git a/deps/sljit/sljit_src/sljitNativeS390X.c b/deps/sljit/sljit_src/sljitNativeS390X.c index 7ce9f9f..98f671e 100644 --- a/deps/sljit/sljit_src/sljitNativeS390X.c +++ b/deps/sljit/sljit_src/sljitNativeS390X.c @@ -93,9 +93,6 @@ static const sljit_gpr r15 = 15; /* reg_map[SLJIT_NUMBER_OF_REGISTERS + 1]: stac #define tmp0 r0 #define tmp1 r1 -/* When reg cannot be unused. */ -#define IS_GPR_REG(reg) ((reg > 0) && (reg) <= SLJIT_SP) - /* Link register. */ static const sljit_gpr link_r = 14; /* r14 */ @@ -125,11 +122,6 @@ static const sljit_u8 freg_map[SLJIT_NUMBER_OF_FLOAT_REGISTERS + 2] = { #define F32(r) (R32A((sljit_ins)freg_map[r])) #define F36(r) (R36A((sljit_ins)freg_map[r])) -struct sljit_s390x_const { - struct sljit_const const_; /* must be first */ - sljit_sw init_value; /* required to build literal pool */ -}; - /* Convert SLJIT register to hardware register. */ static SLJIT_INLINE sljit_gpr gpr(sljit_s32 r) { @@ -169,14 +161,14 @@ static SLJIT_INLINE sljit_u8 get_cc(struct sljit_compiler *compiler, sljit_s32 t switch (type) { case SLJIT_EQUAL: if (SLJIT_ADD_SUB_NO_COMPARE(compiler->status_flags_state)) { - sljit_s32 type = GET_FLAG_TYPE(compiler->status_flags_state); - if (type >= SLJIT_SIG_LESS && type <= SLJIT_SIG_LESS_EQUAL) + sljit_s32 flag_type = GET_FLAG_TYPE(compiler->status_flags_state); + if (flag_type >= SLJIT_SIG_LESS && flag_type <= SLJIT_SIG_LESS_EQUAL) return cc0; - if (type == SLJIT_OVERFLOW) + if (flag_type == SLJIT_OVERFLOW) return (cc0 | cc3); return (cc0 | cc2); } - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ATOMIC_STORED: case SLJIT_F_EQUAL: @@ -185,14 +177,14 @@ static SLJIT_INLINE sljit_u8 get_cc(struct sljit_compiler *compiler, sljit_s32 t case SLJIT_NOT_EQUAL: if (SLJIT_ADD_SUB_NO_COMPARE(compiler->status_flags_state)) { - sljit_s32 type = GET_FLAG_TYPE(compiler->status_flags_state); - if (type >= SLJIT_SIG_LESS && type <= SLJIT_SIG_LESS_EQUAL) + sljit_s32 flag_type = GET_FLAG_TYPE(compiler->status_flags_state); + if (flag_type >= SLJIT_SIG_LESS && flag_type <= SLJIT_SIG_LESS_EQUAL) return (cc1 | cc2 | cc3); - if (type == SLJIT_OVERFLOW) + if (flag_type == SLJIT_OVERFLOW) return (cc1 | cc2); return (cc1 | cc3); } - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_UNORDERED_OR_NOT_EQUAL: return (cc1 | cc2 | cc3); @@ -223,7 +215,7 @@ static SLJIT_INLINE sljit_u8 get_cc(struct sljit_compiler *compiler, sljit_s32 t case SLJIT_NOT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_SUB) return (cc2 | cc3); - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_SIG_LESS_EQUAL: case SLJIT_F_LESS_EQUAL: @@ -233,7 +225,7 @@ static SLJIT_INLINE sljit_u8 get_cc(struct sljit_compiler *compiler, sljit_s32 t case SLJIT_CARRY: if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_SUB) return (cc0 | cc1); - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_SIG_GREATER: case SLJIT_UNORDERED_OR_GREATER: @@ -246,7 +238,7 @@ static SLJIT_INLINE sljit_u8 get_cc(struct sljit_compiler *compiler, sljit_s32 t case SLJIT_OVERFLOW: if (compiler->status_flags_state & SLJIT_SET_Z) return (cc2 | cc3); - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_UNORDERED: return cc3; @@ -254,7 +246,7 @@ static SLJIT_INLINE sljit_u8 get_cc(struct sljit_compiler *compiler, sljit_s32 t case SLJIT_NOT_OVERFLOW: if (compiler->status_flags_state & SLJIT_SET_Z) return (cc0 | cc1); - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_ORDERED: return (cc0 | cc1 | cc2); @@ -333,7 +325,7 @@ static SLJIT_INLINE int have_facility_static(facility_bit x) return 0; } -static SLJIT_INLINE unsigned long get_hwcap() +static SLJIT_INLINE unsigned long get_hwcap(void) { static unsigned long hwcap = 0; if (SLJIT_UNLIKELY(!hwcap)) { @@ -343,7 +335,7 @@ static SLJIT_INLINE unsigned long get_hwcap() return hwcap; } -static SLJIT_INLINE int have_stfle() +static SLJIT_INLINE int have_stfle(void) { if (have_facility_static(STORE_FACILITY_LIST_EXTENDED_FACILITY)) return 1; @@ -410,10 +402,10 @@ HAVE_FACILITY(have_misc2, MISCELLANEOUS_INSTRUCTION_EXTENSIONS_2_FACILITY) #define CHECK_SIGNED(v, bitlen) \ ((v) >= -(1 << ((bitlen) - 1)) && (v) < (1 << ((bitlen) - 1))) -#define is_s8(d) CHECK_SIGNED((d), 8) -#define is_s16(d) CHECK_SIGNED((d), 16) +#define is_s8(d) ((sljit_sw)(d) == (sljit_s8)(d)) +#define is_s16(d) ((sljit_sw)(d) == (sljit_s16)(d)) #define is_s20(d) CHECK_SIGNED((d), 20) -#define is_s32(d) ((d) == (sljit_s32)(d)) +#define is_s32(d) ((sljit_sw)(d) == (sljit_s32)(d)) static SLJIT_INLINE sljit_ins disp_s20(sljit_s32 d) { @@ -983,6 +975,12 @@ static const sljit_ins store_forms[3] = { 0xe30000000024 /* stg */ }; +static const sljit_ins store_byte_forms[3] = { + 0x42000000 /* stc */, + 0xe30000000072 /* stcy */, + 0 +}; + static const sljit_ins load_halfword_forms[3] = { 0x48000000 /* lh */, 0xe30000000078 /* lhy */, @@ -1021,6 +1019,13 @@ static SLJIT_INLINE sljit_s32 store_word(struct sljit_compiler *compiler, sljit_ return load_store_op(compiler, src_r, dst, dstw, is_32bit, store_forms); } +/* May clobber tmp1. */ +static SLJIT_INLINE sljit_s32 store_byte(struct sljit_compiler *compiler, sljit_gpr src_r, + sljit_s32 dst, sljit_sw dstw) +{ + return load_store_op(compiler, src_r, dst, dstw, 1, store_byte_forms); +} + #undef WHEN static sljit_s32 emit_move(struct sljit_compiler *compiler, @@ -1029,7 +1034,7 @@ static sljit_s32 emit_move(struct sljit_compiler *compiler, { sljit_gpr src_r; - SLJIT_ASSERT(!IS_GPR_REG(src) || dst_r != gpr(src & REG_MASK)); + SLJIT_ASSERT(!FAST_IS_REG(src) || dst_r != gpr(src & REG_MASK)); if (src == SLJIT_IMM) return push_load_imm_inst(compiler, dst_r, srcw); @@ -1392,6 +1397,12 @@ static sljit_s32 emit_non_commutative(struct sljit_compiler *compiler, const str return emit_rrf(compiler, ins, dst, src1, src1w, src2, src2w); } +static SLJIT_INLINE sljit_u16 *process_extended_label(sljit_u16 *code_ptr, struct sljit_extended_label *ext_label) +{ + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + return (sljit_u16*)((sljit_uw)code_ptr & ~(ext_label->data)); +} + SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler, sljit_s32 options, void *exec_allocator_data) { struct sljit_label *label; @@ -1413,30 +1424,28 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil sljit_sw source, offset; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reverse_buf(compiler); jump = compiler->jumps; while (jump != NULL) { - if (jump->flags & (SLJIT_REWRITABLE_JUMP | JUMP_ADDR | JUMP_MOV_ADDR)) { + if (jump->flags & (SLJIT_REWRITABLE_JUMP | JUMP_ADDR)) { /* encoded: */ /* brasl %r14, (or brcl , ) */ /* replace with: */ /* lgrl %r1, */ /* bras %r14, %r1 (or bcr , %r1) */ - pool_size += sizeof(*pool); + if (((jump->flags & SLJIT_REWRITABLE_JUMP) || !is_s32(jump->u.target))) + pool_size += sizeof(sljit_uw); + else + jump->flags |= PATCH_IMM32; + if (!(jump->flags & JUMP_MOV_ADDR)) ins_size += 2; } jump = jump->next; } - const_ = compiler->consts; - while (const_) { - pool_size += sizeof(*pool); - const_ = const_->next; - } - /* pad code size to 8 bytes so is accessible with half word offsets */ /* the literal pool needs to be doubleword aligned */ pad_size = ((ins_size + 7UL) & ~7UL) - ins_size; @@ -1475,80 +1484,91 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_ASSERT(!const_ || const_->addr >= half_count); if (next_min_addr == next_label_size) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label = label->next; next_label_size = SLJIT_GET_NEXT_SIZE(label); } if (next_min_addr == next_jump_addr) { - if (SLJIT_UNLIKELY(jump->flags & JUMP_MOV_ADDR)) { - source = (sljit_sw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); - - jump->addr = (sljit_uw)pool_ptr; - - /* store target into pool */ - offset = (sljit_sw)SLJIT_ADD_EXEC_OFFSET(pool_ptr, executable_offset) - source; - pool_ptr++; + jump->addr = (sljit_uw)code_ptr; - SLJIT_ASSERT(!(offset & 1)); - offset >>= 1; - SLJIT_ASSERT(is_s32(offset)); - ins |= (sljit_ins)offset & 0xffffffff; + if (SLJIT_UNLIKELY(jump->flags & JUMP_MOV_ADDR)) { + if (jump->flags & PATCH_IMM32) { + SLJIT_ASSERT((jump->flags & JUMP_ADDR) && is_s32(jump->u.target)); + ins = 0xc00100000000 /* lgfi */ | (ins & 0xf000000000); + } else if (jump->flags & JUMP_ADDR) { + source = (sljit_sw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); + offset = (sljit_sw)(jump->u.target - (sljit_uw)source); + + if ((offset & 0x1) != 0 || offset > 0xffffffffl || offset < -0x100000000l) { + jump->addr = (sljit_uw)pool_ptr; + jump->flags |= PATCH_POOL; + + /* store target into pool */ + offset = (sljit_sw)SLJIT_ADD_EXEC_OFFSET(pool_ptr, executable_offset) - source; + pool_ptr++; + + SLJIT_ASSERT(!(offset & 1)); + offset >>= 1; + SLJIT_ASSERT(is_s32(offset)); + ins = 0xc40800000000 /* lgrl */ | (ins & 0xf000000000) | (sljit_ins)(offset & 0xffffffff); + } + } } else if (jump->flags & (SLJIT_REWRITABLE_JUMP | JUMP_ADDR)) { - sljit_ins arg; - - jump->addr = (sljit_uw)pool_ptr; - - /* load address into tmp1 */ source = (sljit_sw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); - offset = (sljit_sw)SLJIT_ADD_EXEC_OFFSET(pool_ptr, executable_offset) - source; - - SLJIT_ASSERT(!(offset & 1)); - offset >>= 1; - SLJIT_ASSERT(is_s32(offset)); - - code_ptr[0] = (sljit_u16)(0xc408 | R4A(tmp1) /* lgrl */); - code_ptr[1] = (sljit_u16)(offset >> 16); - code_ptr[2] = (sljit_u16)offset; - code_ptr += 3; - pool_ptr++; - - /* branch to tmp1 */ - arg = (ins >> 36) & 0xf; - if (((ins >> 32) & 0xf) == 4) { - /* brcl -> bcr */ - ins = bcr(arg, tmp1); - } else { - SLJIT_ASSERT(((ins >> 32) & 0xf) == 5); - /* brasl -> basr */ - ins = basr(arg, tmp1); + + if (jump->flags & PATCH_IMM32) { + SLJIT_ASSERT((jump->flags & JUMP_ADDR) && is_s32(jump->u.target)); + code_ptr[0] = (sljit_u16)(0xc001 /* lgfi */ | R4A(tmp1)); + code_ptr += 3; + } else if (!(jump->flags & SLJIT_REWRITABLE_JUMP)) { + offset = (sljit_sw)(jump->u.target - (sljit_uw)source); + + if ((offset & 0x1) != 0 || offset > 0xffffffffl || offset < -0x100000000l) + jump->flags |= PATCH_POOL; + } else + jump->flags |= PATCH_POOL; + + if (jump->flags & PATCH_POOL) { + jump->addr = (sljit_uw)pool_ptr; + + /* load address into tmp1 */ + offset = (sljit_sw)SLJIT_ADD_EXEC_OFFSET(pool_ptr, executable_offset) - source; + + SLJIT_ASSERT(!(offset & 1)); + offset >>= 1; + SLJIT_ASSERT(is_s32(offset)); + + code_ptr[0] = (sljit_u16)(0xc408 /* lgrl */ | R4A(tmp1)); + code_ptr[1] = (sljit_u16)(offset >> 16); + code_ptr[2] = (sljit_u16)offset; + code_ptr += 3; + pool_ptr++; } - /* Adjust half_count. */ - half_count += 2; - } else - jump->addr = (sljit_uw)code_ptr; + if (jump->flags & (PATCH_POOL | PATCH_IMM32)) { + /* branch to tmp1 */ + if (((ins >> 32) & 0xf) == 4) { + /* brcl -> bcr */ + ins = 0x0700 /* bcr */ | ((ins >> 32) & 0xf0) | R0A(tmp1); + } else { + SLJIT_ASSERT(((ins >> 32) & 0xf) == 5); + /* brasl -> basr */ + ins = 0x0d00 /* basr */ | ((ins >> 32) & 0xf0) | R0A(tmp1); + } + + /* Adjust half_count. */ + half_count += 2; + } + } jump = jump->next; next_jump_addr = SLJIT_GET_NEXT_ADDRESS(jump); - } else if (next_min_addr == next_const_addr) { - /* update instruction with relative address of constant */ - source = (sljit_sw)code_ptr; - offset = (sljit_sw)pool_ptr - source; - - SLJIT_ASSERT(!(offset & 0x1)); - offset >>= 1; /* halfword (not byte) offset */ - SLJIT_ASSERT(is_s32(offset)); - - ins |= (sljit_ins)offset & 0xffffffff; - - /* update address */ - const_->addr = (sljit_uw)pool_ptr; - - /* store initial value into pool and update pool address */ - *(pool_ptr++) = (sljit_uw)(((struct sljit_s390x_const*)const_)->init_value); - - /* move to next constant */ + } else if (next_min_addr == next_const_addr) { + const_->addr = (sljit_uw)code_ptr; const_ = const_->next; next_const_addr = SLJIT_GET_NEXT_ADDRESS(const_); } @@ -1574,6 +1594,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } while (buf); if (next_label_size == half_count) { + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label = label->next; } @@ -1581,25 +1604,30 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil SLJIT_ASSERT(!label); SLJIT_ASSERT(!jump); SLJIT_ASSERT(!const_); - SLJIT_ASSERT(code + (ins_size >> 1) == code_ptr); - SLJIT_ASSERT((sljit_u8 *)pool + pool_size == (sljit_u8 *)pool_ptr); + SLJIT_ASSERT(code_ptr <= code + (ins_size >> 1)); + SLJIT_ASSERT((sljit_u8 *)pool_ptr <= (sljit_u8 *)pool + pool_size); jump = compiler->jumps; while (jump != NULL) { offset = (sljit_sw)((jump->flags & JUMP_ADDR) ? jump->u.target : jump->u.label->u.addr); - if (jump->flags & (SLJIT_REWRITABLE_JUMP | JUMP_ADDR | JUMP_MOV_ADDR)) { - /* Store jump target into pool. */ - *(sljit_uw*)(jump->addr) = (sljit_uw)offset; - } else { + if (!(jump->flags & (PATCH_POOL | PATCH_IMM32))) { code_ptr = (sljit_u16*)jump->addr; offset -= (sljit_sw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); - /* offset must be halfword aligned */ + /* Offset must be halfword aligned. */ SLJIT_ASSERT(!(offset & 1)); offset >>= 1; SLJIT_ASSERT(is_s32(offset)); /* TODO(mundaym): handle arbitrary offsets */ + code_ptr[1] = (sljit_u16)(offset >> 16); + code_ptr[2] = (sljit_u16)offset; + } else if (jump->flags & PATCH_POOL) { + /* Store jump target into pool. */ + *(sljit_uw*)(jump->addr) = (sljit_uw)offset; + } else { + SLJIT_ASSERT(is_s32(offset)); + code_ptr = (sljit_u16*)jump->addr; code_ptr[1] = (sljit_u16)(offset >> 16); code_ptr[2] = (sljit_u16)offset; } @@ -2243,7 +2271,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile } /* STORE and STORE IMMEDIATE */ if ((dst & SLJIT_MEM) && (FAST_IS_REG(src) || src == SLJIT_IMM)) { - struct addr mem; sljit_gpr reg = FAST_IS_REG(src) ? gpr(src) : tmp0; if (src == SLJIT_IMM) { @@ -2276,7 +2303,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile #undef LEVAL /* MOVE CHARACTERS */ if ((dst & SLJIT_MEM) && (src & SLJIT_MEM)) { - struct addr mem; FAIL_IF(make_addr_bxy(compiler, &mem, src, srcw, tmp1)); switch (opcode) { case SLJIT_MOV_U8: @@ -2335,7 +2361,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile case SLJIT_REV_U32: case SLJIT_REV_S32: op |= SLJIT_32; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_REV: case SLJIT_REV_U16: case SLJIT_REV_S16: @@ -2648,7 +2674,7 @@ static sljit_s32 sljit_emit_bitwise_imm(struct sljit_compiler *compiler, sljit_s sljit_gpr dst_r = tmp0; sljit_s32 needs_move = 1; - if (IS_GPR_REG(dst)) { + if (FAST_IS_REG(dst)) { dst_r = gpr(dst & REG_MASK); if (dst == src1) needs_move = 0; @@ -3119,6 +3145,75 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return push_inst(compiler, 0xb9810000 /* ogr */ | R4A(dst_r) | R0A(tmp0)); } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_gpr dst_r, tmp_r, src_r; + struct addr addr; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= 0x3f; + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + tmp_r = FAST_IS_REG(dst) && (dst != src1) ? gpr(dst) : tmp0; + + if (src2 & SLJIT_MEM) { + FAIL_IF(load_word(compiler, tmp_r, src2, src2w, 0 /* 64-bit */)); + src_r = tmp_r; + } else { + src_r = gpr(src2); + } + + FAIL_IF(push_inst(compiler, 0xeb000000000d /* sllg */ | R36A(tmp_r) | R32A(src_r) | ((sljit_ins)shift_arg << 16))); + + if (src1 & SLJIT_MEM) { + FAIL_IF(make_addr_bxy(compiler, &addr, src1, src1w, tmp1)); + FAIL_IF(push_inst(compiler, 0xe30000000008 /* ag */ | R36A(tmp_r) | R32A(addr.index) | R28A(addr.base) | disp_s20(addr.offset))); + src_r = tmp_r; + } else if (src1 == SLJIT_IMM) { + if (is_s32(src1w)) { + FAIL_IF(push_inst(compiler, 0xc20800000000 /* agfi */ | R36A(tmp_r) | (sljit_u32)src1w)); + src_r = tmp_r; + } else { + src_r = tmp_r != tmp0 ? tmp0 : tmp1; + FAIL_IF(push_load_imm_inst(compiler, src_r, src1w)); + } + } else { + src_r = gpr(src1); + } + + dst_r = (FAST_IS_REG(dst) ? gpr(dst) : tmp0); + + if (src_r != tmp_r) { + if (src_r == dst_r) { + FAIL_IF(push_inst(compiler, 0xb9080000 /* agr */ | R4A(dst_r) | R0A(tmp_r))); + } else { + FAIL_IF(push_inst(compiler, 0xb9e80000 /* agrk */ | R12A(tmp_r) | R4A(dst_r) | R0A(src_r))); + } + } + + if (dst & SLJIT_MEM) + return store_word(compiler, dst_r, dst, dstw, 0 /* 64-bit */); + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -3131,11 +3226,14 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_RETURN: - src_r = FAST_IS_REG(src) ? gpr(src) : tmp1; - if (src & SLJIT_MEM) - FAIL_IF(load_word(compiler, tmp1, src, srcw, 0)); + if (FAST_IS_REG(src)) { + src_r = gpr(src); + if (src_r != link_r) + FAIL_IF(push_inst(compiler, lgr(link_r, src_r))); + } else + FAIL_IF(load_word(compiler, link_r, src, srcw, 0)); - return push_inst(compiler, br(src_r)); + return push_inst(compiler, br(link_r)); case SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN: return SLJIT_SUCCESS; case SLJIT_PREFETCH_L1: @@ -3163,8 +3261,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *comp switch (op) { case SLJIT_FAST_ENTER: - if (FAST_IS_REG(dst)) - return push_inst(compiler, lgr(gpr(dst), link_r)); + if (FAST_IS_REG(dst)) { + dst_r = gpr(dst); + + if (dst_r == link_r) + return SLJIT_SUCCESS; + return push_inst(compiler, lgr(dst_r, link_r)); + } break; case SLJIT_GET_RETURN_ADDRESS: dst_r = FAST_IS_REG(dst) ? gpr(dst) : tmp0; @@ -3591,6 +3694,60 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, i; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (alignment <= SLJIT_LABEL_ALIGN_2) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - sizeof(sljit_u16); + + for (i = (mask >> 1); i != 0; i--) + PTR_FAIL_IF(push_inst(compiler, 0x0700 /* 2-byte nop */)); + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + + for (i = (buffers->size + 1) >> 1; i > 0; i--) + PTR_FAIL_IF(push_inst(compiler, 0x0700 /* 2-byte nop */)); + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type) { struct sljit_jump *jump; @@ -3633,25 +3790,36 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compile SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw) { + struct sljit_jump *jump; sljit_gpr src_r = FAST_IS_REG(src) ? gpr(src) : tmp1; CHECK_ERROR(); CHECK(check_sljit_emit_ijump(compiler, type, src, srcw)); - if (src == SLJIT_IMM) { - SLJIT_ASSERT(!(srcw & 1)); /* target address must be even */ - FAIL_IF(push_load_imm_inst(compiler, src_r, srcw)); - } - else if (src & SLJIT_MEM) { - ADJUST_LOCAL_OFFSET(src, srcw); - FAIL_IF(load_word(compiler, src_r, src, srcw, 0 /* 64-bit */)); + if (src != SLJIT_IMM) { + if (src & SLJIT_MEM) { + ADJUST_LOCAL_OFFSET(src, srcw); + FAIL_IF(load_word(compiler, src_r, src, srcw, 0 /* 64-bit */)); + } + + /* emit jump instruction */ + if (type >= SLJIT_FAST_CALL) + return push_inst(compiler, basr(link_r, src_r)); + + return push_inst(compiler, br(src_r)); } - /* emit jump instruction */ + jump = (struct sljit_jump *)ensure_abuf(compiler, sizeof(struct sljit_jump)); + FAIL_IF(!jump); + set_jump(jump, compiler, JUMP_ADDR); + jump->addr = compiler->size; + jump->u.target = (sljit_uw)srcw; + + type &= 0xff; if (type >= SLJIT_FAST_CALL) - return push_inst(compiler, basr(link_r, src_r)); + return push_inst(compiler, brasl(link_r, 0)); - return push_inst(compiler, br(src_r)); + return push_inst(compiler, brcl(0xf, 0)); } SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, @@ -3711,7 +3879,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *co break; case SLJIT_MOV32: op |= SLJIT_32; - /* fallthrough */ + SLJIT_FALLTHROUGH case SLJIT_MOV: /* can write straight into destination */ loc_r = dst_r; @@ -3766,6 +3934,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp sljit_ins mask; sljit_gpr src_r; sljit_gpr dst_r = gpr(dst_reg); + sljit_s32 is_32bit = (type & SLJIT_32) != 0; sljit_ins ins; CHECK_ERROR(); @@ -3773,6 +3942,43 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp ADJUST_LOCAL_OFFSET(src1, src1w); + type &= ~SLJIT_32; + if (src1 == SLJIT_IMM && is_32bit) + src1w = (sljit_s32)src1w; + + if (type & SLJIT_COMPARE_SELECT) { + type ^= SLJIT_COMPARE_SELECT; + compiler->status_flags_state = SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE; + + if (src1 & SLJIT_MEM) { + FAIL_IF(load_word(compiler, tmp0, src1, src1w, is_32bit)); + src1 = TMP_REG1; + src1w = 0; + } else if (src1 == SLJIT_IMM) { + if (type >= SLJIT_LESS && type <= SLJIT_LESS_EQUAL && src1w >= 0 && src1w <= 0x7fff) { + ins = is_32bit ? 0xc20f00000000 /* clfi */ : 0xc20e00000000 /* clgfi */; + FAIL_IF(push_inst(compiler, ins | R36A(gpr(src2_reg)) | (sljit_ins)src1w)); + type ^= 0x1; + } else if (type >= SLJIT_SIG_LESS && type <= SLJIT_SIG_LESS_EQUAL && is_s20(src1w)) { + ins = is_32bit ? 0xc20d00000000 /* cfi */ : 0xc20c00000000 /* cgfi */; + FAIL_IF(push_inst(compiler, ins | R36A(gpr(src2_reg)) | ((sljit_ins)src1w & 0xffffffff))); + type ^= 0x1; + } else { + FAIL_IF(push_load_imm_inst(compiler, tmp0, src1w)); + src1 = TMP_REG1; + src1w = 0; + } + } + + if (FAST_IS_REG(src1)) { + if (type >= SLJIT_LESS && type <= SLJIT_LESS_EQUAL) + ins = is_32bit ? 0x1500 /* clr */ : 0xb9210000 /* clgr */; + else + ins = is_32bit ? 0x1900 /* cr */ : 0xb9200000 /* cgr */; + FAIL_IF(push_inst(compiler, ins | R4A(gpr(src1)) | R0A(gpr(src2_reg)))); + } + } + if (dst_reg != src2_reg) { if (src1 == dst_reg) { src1 = src2_reg; @@ -3780,16 +3986,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp type ^= 0x1; } else { if (ADDRESSING_DEPENDS_ON(src1, dst_reg)) { - FAIL_IF(load_word(compiler, dst_r, src1, src1w, type & SLJIT_32)); + FAIL_IF(load_word(compiler, dst_r, src1, src1w, is_32bit)); src1 = src2_reg; src1w = 0; type ^= 0x1; } else - FAIL_IF(push_inst(compiler, ((type & SLJIT_32) ? 0x1800 /* lr */ : 0xb9040000 /* lgr */) | R4A(dst_r) | R0A(gpr(src2_reg)))); + FAIL_IF(push_inst(compiler, (is_32bit ? 0x1800 /* lr */ : 0xb9040000 /* lgr */) | R4A(dst_r) | R0A(gpr(src2_reg)))); } } - mask = get_cc(compiler, type & ~SLJIT_32); + mask = get_cc(compiler, type); if (src1 & SLJIT_MEM) { if (src1 & OFFS_REG_MASK) { @@ -3807,23 +4013,20 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp FAIL_IF(push_load_imm_inst(compiler, tmp1, src1w)); if (src1 & REG_MASK) - FAIL_IF(push_inst(compiler, 0xb9e80000 /* agrk */ | R12A(tmp1) | R4A(tmp1) | R0A(gpr(src1 & REG_MASK)))); + FAIL_IF(push_inst(compiler, 0xb9080000 /* agr */ | R4A(tmp1) | R0A(gpr(src1 & REG_MASK)))); src_r = tmp1; src1w = 0; } else src_r = gpr(src1 & REG_MASK); - ins = (type & SLJIT_32) ? 0xeb00000000f2 /* loc */ : 0xeb00000000e2 /* locg */; + ins = is_32bit ? 0xeb00000000f2 /* loc */ : 0xeb00000000e2 /* locg */; return push_inst(compiler, ins | R36A(dst_r) | (mask << 32) | R28A(src_r) | disp_s20((sljit_s32)src1w)); } if (src1 == SLJIT_IMM) { - if (type & SLJIT_32) - src1w = (sljit_s32)src1w; - if (have_lscond2() && is_s16(src1w)) { - ins = (type & SLJIT_32) ? 0xec0000000042 /* lochi */ : 0xec0000000046 /* locghi */; + ins = is_32bit ? 0xec0000000042 /* lochi */ : 0xec0000000046 /* locghi */; return push_inst(compiler, ins | R36A(dst_r) | (mask << 32) | (sljit_ins)(src1w & 0xffff) << 16); } @@ -3832,7 +4035,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp } else src_r = gpr(src1); - ins = (type & SLJIT_32) ? 0xb9f20000 /* locr */ : 0xb9e20000 /* locgr */; + ins = is_32bit ? 0xb9f20000 /* locr */ : 0xb9e20000 /* locgr */; return push_inst(compiler, ins | (mask << 12) | R4A(dst_r) | R0A(src_r)); } @@ -4461,40 +4664,52 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler /* Other instructions */ /* --------------------------------------------------------------------- */ -/* On s390x we build a literal pool to hold constants. This has two main - advantages: - - 1. we only need one instruction in the instruction stream (LGRL) - 2. we can store 64 bit addresses and use 32 bit offsets - - To retrofit the extra information needed to build the literal pool we - add a new sljit_s390x_const struct that contains the initial value but - can still be cast to a sljit_const. */ - -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { - struct sljit_s390x_const *const_; + struct sljit_const *const_; sljit_gpr dst_r; + int is_32 = 0; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); + ADJUST_LOCAL_OFFSET(dst, dstw); - const_ = (struct sljit_s390x_const*)ensure_abuf(compiler, - sizeof(struct sljit_s390x_const)); + const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); PTR_FAIL_IF(!const_); set_const((struct sljit_const*)const_, compiler); - const_->init_value = init_value; dst_r = FAST_IS_REG(dst) ? gpr(dst & REG_MASK) : tmp0; - if (have_genext()) - PTR_FAIL_IF(push_inst(compiler, lgrl(dst_r, 0))); - else { - PTR_FAIL_IF(push_inst(compiler, larl(tmp1, 0))); - PTR_FAIL_IF(push_inst(compiler, lg(dst_r, 0, r0, tmp1))); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xff00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, 0xa7090000 /* lghi */ | R20A(dst_r) | (sljit_ins)(init_value & 0xffff))); + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(store_byte(compiler, dst_r, dst, dstw)); + return (struct sljit_const*)const_; + + case SLJIT_MOV32: + is_32 = 1; + SLJIT_FALLTHROUGH + case SLJIT_MOV_S32: + PTR_FAIL_IF(push_inst(compiler, 0xc00100000000 /* lgfi */ | R36A(dst_r) | (sljit_ins)(init_value & 0xffffffff))); + break; + + default: + PTR_FAIL_IF(push_inst(compiler, 0xc00f00000000 /* llilf */ | R36A(dst_r) | (sljit_ins)(init_value & 0xffffffff))); + PTR_FAIL_IF(push_inst(compiler, 0xc00800000000 /* iihf */ | R36A(dst_r) | (sljit_ins)((init_value >> 32) & 0xffffffff))); + break; } if (dst & SLJIT_MEM) - PTR_FAIL_IF(store_word(compiler, dst_r, dst, dstw, 0 /* always 64-bit */)); + PTR_FAIL_IF(store_word(compiler, dst_r, dst, dstw, is_32)); return (struct sljit_const*)const_; } @@ -4511,32 +4726,85 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_CACHE_FLUSH(ptr, ptr + 1); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_u16 *inst = (sljit_u16*)addr; + SLJIT_UNUSED_ARG(executable_offset); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + SLJIT_ASSERT((inst[0] & 0xff0f) == 0xa709 /* lghi */); + + if (new_constant & 0x100) + new_constant |= 0xff00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[1] = (sljit_u16)new_constant; + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_u16*)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; + + case SLJIT_MOV32: + case SLJIT_MOV_S32: + SLJIT_ASSERT((inst[0] & 0xff0f) == 0xc001 /* lgfi */); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 3, 0); + inst[1] = (sljit_u16)(new_constant >> 16); + inst[2] = (sljit_u16)new_constant; + SLJIT_UPDATE_WX_FLAGS(inst, inst + 3, 1); + inst = (sljit_u16*)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 3); + return; + + default: + SLJIT_ASSERT((inst[0] & 0xff0f) == 0xc00f /* llilf */ && (inst[3] & 0xff0f) == 0xc008 /* iihf */); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 6, 0); + inst[1] = (sljit_u16)(new_constant >> 16); + inst[2] = (sljit_u16)new_constant; + inst[4] = (sljit_u16)(new_constant >> 48); + inst[5] = (sljit_u16)(new_constant >> 32); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 6, 1); + inst = (sljit_u16*)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 6); + return; + } } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; - sljit_gpr dst_r; + sljit_gpr dst_r, target_r; + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); + dst_r = FAST_IS_REG(dst) ? gpr(dst & REG_MASK) : tmp0; + + if (op != SLJIT_ADD_ABS_ADDR) + target_r = dst_r; + else { + target_r = tmp1; + + if (dst & SLJIT_MEM) + PTR_FAIL_IF(load_word(compiler, dst_r, dst, dstw, 0)); + } + jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump)); PTR_FAIL_IF(!jump); set_mov_addr(jump, compiler, 0); - dst_r = FAST_IS_REG(dst) ? gpr(dst & REG_MASK) : tmp0; + /* Might be converted to lgrl. */ + PTR_FAIL_IF(push_inst(compiler, 0xc00000000000 /* larl */ | R36A(target_r))); - if (have_genext()) - PTR_FAIL_IF(push_inst(compiler, lgrl(dst_r, 0))); - else { - PTR_FAIL_IF(push_inst(compiler, larl(tmp1, 0))); - PTR_FAIL_IF(push_inst(compiler, lg(dst_r, 0, r0, tmp1))); - } + if (op == SLJIT_ADD_ABS_ADDR) + PTR_FAIL_IF(push_inst(compiler, 0xb90a0000 /* algr */ | R4A(dst_r) | R0A(tmp1))); if (dst & SLJIT_MEM) PTR_FAIL_IF(store_word(compiler, dst_r, dst, dstw, 0)); diff --git a/deps/sljit/sljit_src/sljitNativeX86_32.c b/deps/sljit/sljit_src/sljitNativeX86_32.c index 217a149..95faa74 100644 --- a/deps/sljit/sljit_src/sljitNativeX86_32.c +++ b/deps/sljit/sljit_src/sljitNativeX86_32.c @@ -105,20 +105,20 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_uw if (a == SLJIT_IMM) { if (flags & EX86_BIN_INS) { if (imma <= 127 && imma >= -128) { - inst_size += 1; + inst_size += sizeof(sljit_s8); flags |= EX86_BYTE_ARG; } else - inst_size += 4; + inst_size += sizeof(sljit_sw); } else if (flags & EX86_SHIFT_INS) { SLJIT_ASSERT(imma <= 0x1f); if (imma != 1) { - inst_size++; + inst_size += sizeof(sljit_s8); flags |= EX86_BYTE_ARG; } } else if (flags & EX86_BYTE_ARG) - inst_size++; + inst_size += sizeof(sljit_s8); else if (flags & EX86_HALF_ARG) - inst_size += sizeof(short); + inst_size += sizeof(sljit_s16); else inst_size += sizeof(sljit_sw); } else @@ -1268,41 +1268,59 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp CHECK_EXTRA_REGS(src1, src1w, (void)0); CHECK_EXTRA_REGS(src2_reg, src2w, (void)0); - type &= ~SLJIT_32; - if (dst & SLJIT_MEM) { if (src1 == SLJIT_IMM || (!(src1 & SLJIT_MEM) && (src2_reg & SLJIT_MEM))) { EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w); src1 = src2_reg; src1w = src2w; - type ^= 0x1; + if (!(type & SLJIT_COMPARE_SELECT)) + type ^= 0x1; } else EMIT_MOV(compiler, TMP_REG1, 0, src2_reg, src2w); dst_reg = TMP_REG1; - } else { - if (dst_reg != src2_reg) { - if (dst_reg == src1) { - src1 = src2_reg; - src1w = src2w; + } else if (dst_reg != src2_reg) { + if (dst_reg == src1) { + src1 = src2_reg; + src1w = src2w; + if (!(type & SLJIT_COMPARE_SELECT)) type ^= 0x1; - } else if (ADDRESSING_DEPENDS_ON(src1, dst_reg)) { - EMIT_MOV(compiler, dst_reg, 0, src1, src1w); - src1 = src2_reg; - src1w = src2w; + } else if (ADDRESSING_DEPENDS_ON(src1, dst_reg)) { + EMIT_MOV(compiler, dst_reg, 0, src1, src1w); + src1 = src2_reg; + src1w = src2w; + if (!(type & SLJIT_COMPARE_SELECT)) type ^= 0x1; - } else - EMIT_MOV(compiler, dst_reg, 0, src2_reg, src2w); - } + } else + EMIT_MOV(compiler, dst_reg, 0, src2_reg, src2w); } - if (sljit_has_cpu_feature(SLJIT_HAS_CMOV) && (src1 != SLJIT_IMM || dst_reg != TMP_REG1)) { - if (SLJIT_UNLIKELY(src1 == SLJIT_IMM)) { + if (type & SLJIT_COMPARE_SELECT) { + if (dst_reg != TMP_REG1 && !FAST_IS_REG(src1)) { EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w); src1 = TMP_REG1; src1w = 0; } + type ^= 0x1; + FAIL_IF(emit_cmp_binary(compiler, dst_reg, 0, src1, src1w)); + } + + type &= ~(SLJIT_32 | SLJIT_COMPARE_SELECT); + + if (sljit_has_cpu_feature(SLJIT_HAS_CMOV)) { + if (SLJIT_UNLIKELY(src1 == SLJIT_IMM)) { + if (dst_reg != TMP_REG1) { + EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_IMM, src1w); + src1 = TMP_REG1; + src1w = 0; + } else { + EMIT_MOV(compiler, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, src1w); + src1 = SLJIT_MEM1(SLJIT_SP); + src1w = 0; + } + } + FAIL_IF(emit_groupf(compiler, U8(get_jump_code((sljit_uw)type) - 0x40), dst_reg, src1, src1w)); } else FAIL_IF(emit_cmov_generic(compiler, type, dst_reg, src1, src1w)); diff --git a/deps/sljit/sljit_src/sljitNativeX86_64.c b/deps/sljit/sljit_src/sljitNativeX86_64.c index e4d3db8..0a2f59d 100644 --- a/deps/sljit/sljit_src/sljitNativeX86_64.c +++ b/deps/sljit/sljit_src/sljitNativeX86_64.c @@ -152,20 +152,20 @@ static sljit_u8* emit_x86_instruction(struct sljit_compiler *compiler, sljit_uw if (a == SLJIT_IMM) { if (flags & EX86_BIN_INS) { if (imma <= 127 && imma >= -128) { - inst_size += 1; + inst_size += sizeof(sljit_s8); flags |= EX86_BYTE_ARG; } else - inst_size += 4; + inst_size += sizeof(sljit_s32); } else if (flags & EX86_SHIFT_INS) { SLJIT_ASSERT(imma <= (compiler->mode32 ? 0x1f : 0x3f)); if (imma != 1) { - inst_size++; + inst_size += sizeof(sljit_s8); flags |= EX86_BYTE_ARG; } } else if (flags & EX86_BYTE_ARG) - inst_size++; + inst_size += sizeof(sljit_s8); else if (flags & EX86_HALF_ARG) - inst_size += sizeof(short); + inst_size += sizeof(sljit_s16); else inst_size += sizeof(sljit_s32); } else { @@ -362,7 +362,7 @@ static sljit_u8* detect_far_jump_type(struct sljit_jump *jump, sljit_u8 *code_pt { sljit_uw type = jump->flags >> TYPE_SHIFT; - int short_addr = !(jump->flags & SLJIT_REWRITABLE_JUMP) && (jump->flags & JUMP_ADDR) && (jump->u.target <= 0xffffffff); + int short_addr = ((jump->flags & (SLJIT_REWRITABLE_JUMP | JUMP_ADDR)) == JUMP_ADDR) && (jump->u.target <= 0xffffffff); /* The relative jump below specialized for this case. */ SLJIT_ASSERT(reg_map[TMP_REG2] >= 8 && TMP_REG2 != SLJIT_TMP_DEST_REG); @@ -805,7 +805,7 @@ static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_t if (word_arg_count == 0) return SLJIT_SUCCESS; - if (word_arg_count >= 3) { + if (word_arg_count >= 3 || src == SLJIT_R2) { if (src == SLJIT_R2) *src_ptr = TMP_REG1; EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_R2, 0); @@ -1029,13 +1029,28 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *comp sljit_s32 src1, sljit_sw src1w, sljit_s32 src2_reg) { + sljit_u8* inst; + CHECK_ERROR(); CHECK(check_sljit_emit_select(compiler, type, dst_reg, src1, src1w, src2_reg)); ADJUST_LOCAL_OFFSET(src1, src1w); compiler->mode32 = type & SLJIT_32; - type &= ~SLJIT_32; + + if (type & SLJIT_COMPARE_SELECT) { + if (!FAST_IS_REG(src1)) { + EMIT_MOV(compiler, TMP_REG2, 0, src1, src1w); + src1 = TMP_REG2; + src1w = 0; + } + + inst = emit_x86_instruction(compiler, 1, src1, 0, src2_reg, 0); + FAIL_IF(!inst); + *inst = CMP_r_rm; + } + + type &= ~(SLJIT_32 | SLJIT_COMPARE_SELECT); if (dst_reg != src2_reg) { if (dst_reg == src1) { diff --git a/deps/sljit/sljit_src/sljitNativeX86_common.c b/deps/sljit/sljit_src/sljitNativeX86_common.c index 9f599d5..25085a8 100644 --- a/deps/sljit/sljit_src/sljitNativeX86_common.c +++ b/deps/sljit/sljit_src/sljitNativeX86_common.c @@ -780,6 +780,22 @@ static void generate_jump_or_mov_addr(struct sljit_jump *jump, sljit_sw executab } } +static sljit_u8 *process_extended_label(sljit_u8 *code_ptr, struct sljit_extended_label *ext_label) +{ + sljit_uw mask; + sljit_u8 *ptr = code_ptr; + + SLJIT_ASSERT(ext_label->label.u.index == SLJIT_LABEL_ALIGNED); + mask = ext_label->data; + + code_ptr = (sljit_u8*)(((sljit_uw)code_ptr + mask) & ~mask); + + while (ptr < code_ptr) + *ptr++ = NOP; + + return code_ptr; +} + static void reduce_code_size(struct sljit_compiler *compiler) { struct sljit_label *label; @@ -914,7 +930,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil struct sljit_const *const_; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_generate_code(compiler)); + CHECK_PTR(check_sljit_generate_code(compiler, options)); reduce_code_size(compiler); @@ -944,6 +960,9 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil } else { switch (len) { case SLJIT_INST_LABEL: + if (label->u.index >= SLJIT_LABEL_ALIGNED) + code_ptr = process_extended_label(code_ptr, (struct sljit_extended_label*)label); + label->u.addr = (sljit_uw)SLJIT_ADD_EXEC_OFFSET(code_ptr, executable_offset); label->size = (sljit_uw)(code_ptr - code); label = label->next; @@ -962,7 +981,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil #endif /* SLJIT_CONFIG_X86_32 */ } - SLJIT_ASSERT((sljit_uw)code_ptr - addr <= ((jump->flags >> JUMP_SIZE_SHIFT) & 0x1f)); + SLJIT_ASSERT((sljit_uw)code_ptr - addr <= ((jump->flags >> JUMP_SIZE_SHIFT) & 0xff)); jump = jump->next; break; case SLJIT_INST_MOV_ADDR: @@ -974,7 +993,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil break; default: SLJIT_ASSERT(len == SLJIT_INST_CONST); - const_->addr = ((sljit_uw)code_ptr) - sizeof(sljit_sw); + const_->addr = (sljit_uw)code_ptr; const_ = const_->next; break; } @@ -2998,6 +3017,125 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler * return SLJIT_SUCCESS; } +SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_s32 src1, sljit_sw src1w, + sljit_s32 src2, sljit_sw src2w, + sljit_sw shift_arg) +{ + sljit_s32 dst_r; + int use_lea = 0; + sljit_u8* inst; + + CHECK_ERROR(); + CHECK(check_sljit_emit_op2_shift(compiler, op, dst, dstw, src1, src1w, src2, src2w, shift_arg)); + ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(src1, src1w); + ADJUST_LOCAL_OFFSET(src2, src2w); + + shift_arg &= (sljit_sw)((sizeof(sljit_sw) * 8) - 1); + + if (src2 == SLJIT_IMM) { + src2w = src2w << shift_arg; + shift_arg = 0; + } + + if (shift_arg == 0) { + SLJIT_SKIP_CHECKS(compiler); + return sljit_emit_op2(compiler, GET_OPCODE(op), dst, dstw, src1, src1w, src2, src2w); + } + + CHECK_EXTRA_REGS(dst, dstw, (void)0); + CHECK_EXTRA_REGS(src1, src1w, (void)0); + CHECK_EXTRA_REGS(src2, src2w, (void)0); + +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + compiler->mode32 = 0; +#endif + +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + if (shift_arg <= 3) { + use_lea = 1; + if (!FAST_IS_REG(src2)) { + EMIT_MOV(compiler, TMP_REG1, 0, src2, src2w); + src2 = TMP_REG1; + } + + if (!FAST_IS_REG(src1)) { + EMIT_MOV(compiler, src2 == TMP_REG1 ? TMP_REG2 : TMP_REG1, 0, src1, src1w); + src1 = src2 == TMP_REG1 ? TMP_REG2 : TMP_REG1; + } + } +#else /* !SLJIT_CONFIG_X86_64 */ + if (shift_arg <= 3 && (FAST_IS_REG(src1) || (FAST_IS_REG(src2) && src2 != TMP_REG1))) { + use_lea = 1; + if (!FAST_IS_REG(src2)) { + EMIT_MOV(compiler, TMP_REG1, 0, src2, src2w); + src2 = TMP_REG1; + } + + if (!FAST_IS_REG(src1)) { + EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w); + src1 = TMP_REG1; + } + } +#endif /* SLJIT_CONFIG_X86_64 */ + + if (use_lea) { + dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; + + inst = emit_x86_instruction(compiler, 1, dst_r, 0, SLJIT_MEM2(src1, src2), shift_arg); + FAIL_IF(!inst); + *inst = LEA_r_m; + + if (!FAST_IS_REG(dst)) + return emit_mov(compiler, dst, dstw, dst_r, 0); + + return SLJIT_SUCCESS; + } + + if ((op & SLJIT_SRC2_UNDEFINED) != 0 && FAST_IS_REG(src2) && src1 != src2) + dst_r = src2; + else { + dst_r = FAST_IS_REG(dst) && (dst != src1) ? dst : TMP_REG1; + + if (src2 != dst_r) { + EMIT_MOV(compiler, dst_r, 0, src2, src2w); + } + } + + inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_IMM, shift_arg, dst_r, 0); + FAIL_IF(!inst); + inst[1] |= SHL; + + if (dst == src1 && dstw == src1w) { + inst = emit_x86_instruction(compiler, 1, dst_r, 0, dst, dstw); + FAIL_IF(!inst); + *inst = ADD_rm_r; + return SLJIT_SUCCESS; + } + + if (FAST_IS_REG(dst) && FAST_IS_REG(src1)) { + inst = emit_x86_instruction(compiler, 1, dst, 0, SLJIT_MEM2(src1, dst_r), 0); + FAIL_IF(!inst); + *inst = LEA_r_m; + return SLJIT_SUCCESS; + } + + if (src1 == SLJIT_IMM) { + BINARY_IMM(ADD, ADD_rm_r, src1w, dst_r, 0); + } else { + inst = emit_x86_instruction(compiler, 1, dst_r, 0, src1, src1w); + FAIL_IF(!inst); + *inst = ADD_r_rm; + } + + if (dst != dst_r) + return emit_mov(compiler, dst, dstw, dst_r, 0); + + return SLJIT_SUCCESS; +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) { @@ -3438,6 +3576,82 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compi return label; } +SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler, + sljit_s32 alignment, struct sljit_read_only_buffer *buffers) +{ + sljit_uw mask, size; + sljit_u8 *inst; + struct sljit_label *label; + struct sljit_label *next_label; + struct sljit_extended_label *ext_label; + + CHECK_ERROR_PTR(); + CHECK_PTR(check_sljit_emit_aligned_label(compiler, alignment, buffers)); + + sljit_reset_read_only_buffers(buffers); + + if (alignment <= SLJIT_LABEL_ALIGN_1) { + SLJIT_SKIP_CHECKS(compiler); + label = sljit_emit_label(compiler); + PTR_FAIL_IF(!label); + } else { + /* The used space is filled with NOPs. */ + mask = ((sljit_uw)1 << alignment) - 1; + compiler->size += mask; + + inst = (sljit_u8*)ensure_buf(compiler, 1); + PTR_FAIL_IF(!inst); + inst[0] = SLJIT_INST_LABEL; + + ext_label = (struct sljit_extended_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + PTR_FAIL_IF(!ext_label); + set_extended_label(ext_label, compiler, SLJIT_LABEL_ALIGNED, mask); + label = &ext_label->label; + } + + if (buffers == NULL) + return label; + + next_label = label; + + while (1) { + buffers->u.label = next_label; + size = buffers->size; + + while (size >= 4) { + inst = (sljit_u8*)ensure_buf(compiler, 1 + 4); + PTR_FAIL_IF(!inst); + INC_SIZE(4); + inst[0] = NOP; + inst[1] = NOP; + inst[2] = NOP; + inst[3] = NOP; + size -= 4; + } + + if (size > 0) { + inst = (sljit_u8*)ensure_buf(compiler, 1 + size); + PTR_FAIL_IF(!inst); + INC_SIZE(size); + + do { + *inst++ = NOP; + } while (--size != 0); + } + + buffers = buffers->next; + + if (buffers == NULL) + break; + + SLJIT_SKIP_CHECKS(compiler); + next_label = sljit_emit_label(compiler); + PTR_FAIL_IF(!next_label); + } + + return label; +} + SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type) { sljit_u8 *inst; @@ -3965,7 +4179,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_replicate(struct sljit_compil else FAIL_IF(emit_groupf(compiler, PSHUFLW_x_xm | EX86_PREF_F2 | EX86_SSE2, vreg, vreg, 0)); FAIL_IF(emit_byte(compiler, 0)); - /* fallthrough */ + SLJIT_FALLTHROUGH default: if (use_vex) FAIL_IF(emit_vex_instruction(compiler, PSHUFD_x_xm | EX86_PREF_66 | EX86_SSE2, vreg, 0, vreg, 0)); @@ -4539,7 +4753,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_replicate(struct sljit_c return emit_vex_instruction(compiler, VPBROADCASTD_x_xm | EX86_PREF_66 | VEX_OP_0F38 | EX86_SSE2, vreg, 0, vreg, 0); src = vreg; - /* fallthrough */ + SLJIT_FALLTHROUGH case 2: byte = U8(src_lane_index); byte = U8(byte | (byte << 2)); @@ -5002,6 +5216,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c CHECK_ERROR(); CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset)); ADJUST_LOCAL_OFFSET(dst, dstw); + ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset); CHECK_EXTRA_REGS(dst, dstw, (void)0); @@ -5009,8 +5224,6 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c compiler->mode32 = 0; #endif - ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset); - #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) if (NOT_HALFWORD(offset)) { FAIL_IF(emit_load_imm64(compiler, TMP_REG1, offset)); @@ -5028,59 +5241,105 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c return emit_mov(compiler, dst, dstw, SLJIT_SP, 0); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { sljit_u8 *inst; struct sljit_const *const_; -#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) sljit_s32 reg; -#endif +#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) + sljit_s32 dst_is_ereg = 0; +#endif /* !SLJIT_CONFIG_X86_32 */ CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); - CHECK_EXTRA_REGS(dst, dstw, (void)0); + CHECK_EXTRA_REGS(dst, dstw, dst_is_ereg = 1); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); PTR_FAIL_IF(!const_); set_const(const_, compiler); + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) - compiler->mode32 = 0; - reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + compiler->mode32 = (op & SLJIT_32); +#endif /* SLJIT_CONFIG_X86_64 */ - if (emit_load_imm64(compiler, reg, init_value)) - return NULL; -#else - if (emit_mov(compiler, dst, dstw, SLJIT_IMM, init_value)) - return NULL; -#endif + if ((init_value & 0x100) != 0) + init_value = init_value | -(sljit_sw)0x100; + else + init_value = (sljit_u8)init_value; + +#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) + if (dst_is_ereg) { + if (emit_mov(compiler, dst, dstw, SLJIT_IMM, (sljit_s32)init_value)) + return NULL; + dst = 0; + break; + } +#endif /* !SLJIT_CONFIG_X86_32 */ + + reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + + if (emit_mov(compiler, reg, 0, SLJIT_IMM, init_value)) + return NULL; + break; +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + case SLJIT_MOV: + compiler->mode32 = 0; + reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + + if (emit_load_imm64(compiler, reg, init_value)) + return NULL; + break; +#endif /* SLJIT_CONFIG_X86_64 */ + default: +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + compiler->mode32 = (op == SLJIT_MOV32); +#endif /* SLJIT_CONFIG_X86_64 */ + + if (emit_mov(compiler, dst, dstw, SLJIT_IMM, (sljit_s32)init_value)) + return NULL; + dst = 0; + break; + } inst = (sljit_u8*)ensure_buf(compiler, 1); PTR_FAIL_IF(!inst); inst[0] = SLJIT_INST_CONST; + if (dst & SLJIT_MEM) { #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) - if (dst & SLJIT_MEM) - if (emit_mov(compiler, dst, dstw, TMP_REG1, 0)) - return NULL; + if (op == SLJIT_MOV) { + if (emit_mov(compiler, dst, dstw, TMP_REG1, 0)) + return NULL; + return const_; + } #endif + if (emit_mov_byte(compiler, 0, dst, dstw, TMP_REG1, 0)) + return NULL; + } + return const_; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw) { struct sljit_jump *jump; sljit_u8 *inst; #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) sljit_s32 reg; #endif /* SLJIT_CONFIG_X86_64 */ + SLJIT_UNUSED_ARG(op); CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_mov_addr(compiler, dst, dstw)); + CHECK_PTR(check_sljit_emit_op_addr(compiler, op, dst, dstw)); ADJUST_LOCAL_OFFSET(dst, dstw); CHECK_EXTRA_REGS(dst, dstw, (void)0); @@ -5091,7 +5350,10 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) compiler->mode32 = 0; - reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + if (dst & SLJIT_MEM) + reg = TMP_REG1; + else + reg = (op != SLJIT_ADD_ABS_ADDR) ? dst : TMP_REG2; PTR_FAIL_IF(emit_load_imm64(compiler, reg, 0)); jump->addr = compiler->size; @@ -5099,7 +5361,17 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com if (reg_map[reg] >= 8) jump->flags |= MOV_ADDR_HI; #else /* !SLJIT_CONFIG_X86_64 */ - PTR_FAIL_IF(emit_mov(compiler, dst, dstw, SLJIT_IMM, 0)); + if (op == SLJIT_ADD_ABS_ADDR) { + if (dst != SLJIT_R0) { + /* Must not be a signed byte argument. */ + inst = emit_x86_instruction(compiler, 1 | EX86_BIN_INS, SLJIT_IMM, 0x100, dst, dstw); + PTR_FAIL_IF(!inst); + *(inst + 1) |= ADD; + } else + PTR_FAIL_IF(emit_do_imm(compiler, ADD_EAX_i32, 0)); + } else { + PTR_FAIL_IF(emit_mov(compiler, dst, dstw, SLJIT_IMM, 0)); + } #endif /* SLJIT_CONFIG_X86_64 */ inst = (sljit_u8*)ensure_buf(compiler, 1); @@ -5108,7 +5380,11 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com inst[0] = SLJIT_INST_MOV_ADDR; #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) - if (dst & SLJIT_MEM) + if (op == SLJIT_ADD_ABS_ADDR) { + inst = emit_x86_instruction(compiler, 1, reg, 0, dst, dstw); + PTR_FAIL_IF(!inst); + *inst = ADD_rm_r; + } else if (dst & SLJIT_MEM) PTR_FAIL_IF(emit_mov(compiler, dst, dstw, TMP_REG1, 0)); #endif /* SLJIT_CONFIG_X86_64 */ @@ -5128,11 +5404,31 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + sizeof(sljit_uw)), 1); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { + void *start_addr; SLJIT_UNUSED_ARG(executable_offset); - SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + sizeof(sljit_sw)), 0); - sljit_unaligned_store_sw((void*)addr, new_constant); - SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + sizeof(sljit_sw)), 1); +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + if (op == SLJIT_MOV) { + start_addr = (void*)(addr - sizeof(sljit_sw)); + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 0); + sljit_unaligned_store_sw(start_addr, new_constant); + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 1); + return; + } +#endif + + start_addr = (void*)(addr - sizeof(sljit_s32)); + + if ((op | SLJIT_32) == SLJIT_MOV32_U8) { + if ((new_constant & 0x100) != 0) + new_constant = new_constant | -(sljit_sw)0x100; + else + new_constant = (sljit_u8)new_constant; + } + + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 0); + sljit_unaligned_store_s32(start_addr, (sljit_s32)new_constant); + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 1); } diff --git a/deps/sljit/sljit_src/sljitSerialize.c b/deps/sljit/sljit_src/sljitSerialize.c index 6ef161f..042cc18 100644 --- a/deps/sljit/sljit_src/sljitSerialize.c +++ b/deps/sljit/sljit_src/sljitSerialize.c @@ -24,6 +24,14 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#define SLJIT_GET_LABEL_INDEX(label) \ + ((label)->u.index < SLJIT_LABEL_ALIGNED ? (label)->u.index : ((struct sljit_extended_label*)(label))->index) + +SLJIT_API_FUNC_ATTRIBUTE sljit_uw sljit_get_label_index(struct sljit_label *label) +{ + return SLJIT_GET_LABEL_INDEX(label); +} + SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_label(struct sljit_jump *jump) { return !(jump->flags & JUMP_ADDR) && (jump->u.label != NULL); @@ -48,6 +56,7 @@ struct sljit_serialized_compiler { sljit_uw buf_segment_count; sljit_uw label_count; + sljit_uw aligned_label_count; sljit_uw jump_count; sljit_uw const_count; @@ -94,6 +103,11 @@ struct sljit_serialized_label { sljit_uw size; }; +struct sljit_serialized_aligned_label { + sljit_uw size; + sljit_uw data; +}; + struct sljit_serialized_jump { sljit_uw addr; sljit_uw flags; @@ -122,6 +136,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compile struct sljit_const *const_; struct sljit_serialized_compiler *serialized_compiler; struct sljit_serialized_label *serialized_label; + struct sljit_serialized_aligned_label *serialized_aligned_label; struct sljit_serialized_jump *serialized_jump; struct sljit_serialized_const *serialized_const; #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ @@ -155,7 +170,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compile buf = buf->next; } - serialized_size += compiler->label_count * sizeof(struct sljit_serialized_label); + label = compiler->labels; + while (label != NULL) { + used_size = sizeof(struct sljit_serialized_label); + + if (label->u.index >= SLJIT_LABEL_ALIGNED) + used_size += sizeof(struct sljit_serialized_aligned_label); + + serialized_size += used_size; + label = label->next; + } jump = compiler->jumps; while (jump != NULL) { @@ -229,12 +253,23 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compile serialized_compiler->buf_segment_count = counter; label = compiler->labels; + counter = 0; while (label != NULL) { serialized_label = (struct sljit_serialized_label*)ptr; - serialized_label->size = label->size; + serialized_label->size = (label->u.index < SLJIT_LABEL_ALIGNED) ? label->size : label->u.index; ptr += sizeof(struct sljit_serialized_label); + + if (label->u.index >= SLJIT_LABEL_ALIGNED) { + serialized_aligned_label = (struct sljit_serialized_aligned_label*)ptr; + serialized_aligned_label->size = label->size; + serialized_aligned_label->data = ((struct sljit_extended_label*)label)->data; + ptr += sizeof(struct sljit_serialized_aligned_label); + counter++; + } + label = label->next; } + serialized_compiler->aligned_label_count = counter; jump = compiler->jumps; counter = 0; @@ -246,7 +281,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compile if (jump->flags & JUMP_ADDR) serialized_jump->value = jump->u.target; else if (jump->u.label != NULL) - serialized_jump->value = jump->u.label->u.index; + serialized_jump->value = SLJIT_GET_LABEL_INDEX(jump->u.label); else serialized_jump->value = SLJIT_MAX_ADDRESS; @@ -291,6 +326,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit struct sljit_compiler *compiler; struct sljit_serialized_compiler *serialized_compiler; struct sljit_serialized_label *serialized_label; + struct sljit_serialized_aligned_label *serialized_aligned_label; struct sljit_serialized_jump *serialized_jump; struct sljit_serialized_const *serialized_const; #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ @@ -302,13 +338,15 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit struct sljit_label *label; struct sljit_label *last_label; struct sljit_label **label_list = NULL; + struct sljit_label **label_list_ptr = NULL; struct sljit_jump *jump; struct sljit_jump *last_jump; struct sljit_const *const_; struct sljit_const *last_const; sljit_u8 *ptr = (sljit_u8*)buffer; sljit_u8 *end = ptr + size; - sljit_uw i, used_size, aligned_size, label_count; + sljit_uw i, type, used_size, aligned_size; + sljit_uw label_count, aligned_label_count; SLJIT_UNUSED_ARG(options); if (size < sizeof(struct sljit_serialized_compiler) || (size & (sizeof(sljit_uw) - 1)) != 0) @@ -403,22 +441,31 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit last_label = NULL; label_count = serialized_compiler->label_count; - if ((sljit_uw)(end - ptr) < label_count * sizeof(struct sljit_serialized_label)) + aligned_label_count = serialized_compiler->aligned_label_count; + i = (label_count * sizeof(struct sljit_serialized_label)) + (aligned_label_count * sizeof(struct sljit_serialized_aligned_label)); + + if ((sljit_uw)(end - ptr) < i) goto error; label_list = (struct sljit_label **)SLJIT_MALLOC(label_count * sizeof(struct sljit_label*), allocator_data); if (label_list == NULL) goto error; + label_list_ptr = label_list; for (i = 0; i < label_count; i++) { - label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label)); + serialized_label = (struct sljit_serialized_label*)ptr; + type = serialized_label->size; + + if (type < SLJIT_LABEL_ALIGNED) { + label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label)); + } else { + label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label)); + } + if (label == NULL) goto error; - serialized_label = (struct sljit_serialized_label*)ptr; label->next = NULL; - label->u.index = i; - label->size = serialized_label->size; if (last_label != NULL) last_label->next = label; @@ -426,11 +473,33 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit compiler->labels = label; last_label = label; - label_list[i] = label; + *label_list_ptr++ = label; + ptr += sizeof(struct sljit_serialized_label); + + if (type < SLJIT_LABEL_ALIGNED) { + label->u.index = i; + label->size = type; + } else { + if (aligned_label_count == 0) + goto error; + + aligned_label_count--; + + serialized_aligned_label = (struct sljit_serialized_aligned_label*)ptr; + label->u.index = type; + label->size = serialized_aligned_label->size; + + ((struct sljit_extended_label*)label)->index = i; + ((struct sljit_extended_label*)label)->data = serialized_aligned_label->data; + ptr += sizeof(struct sljit_serialized_aligned_label); + } } compiler->last_label = last_label; + if (aligned_label_count != 0) + goto error; + last_jump = NULL; i = serialized_compiler->jump_count; if ((sljit_uw)(end - ptr) < i * sizeof(struct sljit_serialized_jump)) diff --git a/doc/html/NON-AUTOTOOLS-BUILD.txt b/doc/html/NON-AUTOTOOLS-BUILD.txt index bb687f7..45c8bad 100644 --- a/doc/html/NON-AUTOTOOLS-BUILD.txt +++ b/doc/html/NON-AUTOTOOLS-BUILD.txt @@ -1,5 +1,5 @@ Building PCRE2 without using autotools --------------------------------------- +====================================== This document contains the following sections: @@ -12,11 +12,12 @@ This document contains the following sections: Building PCRE2 on Windows with CMake Building PCRE2 on Windows with Visual Studio Testing with RunTest.bat - Building PCRE2 on native z/OS and z/VM + Building PCRE2 on z/OS and z/VM Building PCRE2 under VMS -GENERAL +General +------- The source of the PCRE2 libraries consists entirely of code written in Standard C, and so should compile successfully on any system that has a Standard C @@ -37,7 +38,8 @@ provided for those who build PCRE2 without using "configure" or CMake. If you use "configure" or CMake, the .generic versions are not used. -GENERIC INSTRUCTIONS FOR THE PCRE2 C LIBRARIES +Generic instructions for the PCRE2 C libraries +---------------------------------------------- There are three possible PCRE2 libraries, each handling data with a specific code unit width: 8, 16, or 32 bits. You can build any combination of them. The @@ -105,6 +107,7 @@ example. pcre2_chkdint.c pcre2_chartables.c pcre2_compile.c + pcre2_compile_cgroup.c pcre2_compile_class.c pcre2_config.c pcre2_context.c @@ -117,6 +120,7 @@ example. pcre2_maketables.c pcre2_match.c pcre2_match_data.c + pcre2_match_next.c pcre2_newline.c pcre2_ord2utf.c pcre2_pattern_info.c @@ -140,9 +144,7 @@ example. defined SUPPORT_JIT in src/config.h, because when JIT support is not configured, dummy functions are compiled. When JIT support IS configured, pcre2_jit_compile.c #includes other files from the sljit dependency, - all of whose names begin with "sljit". It also #includes - src/pcre2_jit_match.c and src/pcre2_jit_misc.c, so you should not compile - those yourself. + all of whose names begin with "sljit". Note also that the pcre2_fuzzsupport.c file contains special code that is useful to those who want to run fuzzing tests on the PCRE2 library. Unless @@ -169,7 +171,7 @@ example. src/config.h) . Compile src/pcre2test.c; don't forget -DHAVE_CONFIG_H if necessary, but do NOT define PCRE2_CODE_UNIT_WIDTH. Then link with the appropriate library/ies. If you compiled an 8-bit library, pcre2test also - needs the pcre2posix wrapper library. + needs the pcre2posix wrapper library when linking. (9) Run pcre2test on the testinput files in the testdata directory, and check that the output matches the corresponding testoutput files. There are @@ -207,20 +209,23 @@ example. defining SUPPORT_JIT, pcre2grep does not try to make use of JIT. -STACK SIZE IN WINDOWS ENVIRONMENTS +Stack size in Windows environments +---------------------------------- Prior to release 10.30 the default system stack size of 1MiB in some Windows environments caused issues with some tests. This should no longer be the case for 10.30 and later releases. -LINKING PROGRAMS IN WINDOWS ENVIRONMENTS +Linking programs in Windows environments +---------------------------------------- If you want to statically link a program against a PCRE2 library in the form of a non-dll .a file, you must define PCRE2_STATIC before including src/pcre2.h. -CALLING CONVENTIONS IN WINDOWS ENVIRONMENTS +Calling conventions in Windows environments +------------------------------------------- It is possible to compile programs to use different calling conventions using MSVC. Search the web for "calling conventions" for more information. To make it @@ -231,7 +236,8 @@ not set, it defaults to empty; the default calling convention is then used (which is what is wanted most of the time). -COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE2 ON WINDOWS WITH CMAKE") +Comments about Win32 builds (see also "Building PCRE2 on Windows with CMake") +--------------------------- There are two ways of building PCRE2 using the "configure, make, make install" paradigm on Windows systems: using MinGW or using Cygwin. These are not at all @@ -293,7 +299,8 @@ newline option that includes LF as a valid newline, it may be necessary to change the line terminators in the test files to get some of the tests to work. -BUILDING PCRE2 ON WINDOWS WITH CMAKE +Building PCRE2 on Windows with CMake +------------------------------------ CMake is an alternative configuration facility that can be used instead of "configure". CMake creates project files (make files, solution files, etc.) @@ -364,7 +371,8 @@ be deleted. Regardless of build system used, `ctest` will run the tests. -BUILDING PCRE2 ON WINDOWS WITH VISUAL STUDIO +Building PCRE2 on Windows with Visual Studio +-------------------------------------------- The code currently cannot be compiled without an inttypes.h header, which is available only with Visual Studio 2013 or newer. However, this portable and @@ -376,7 +384,8 @@ alternative: Just rename it and drop it into the top level of the build tree. -TESTING WITH RUNTEST.BAT +Testing with RunTest.bat +------------------------ If configured with CMake, building the test project ("make test" or building ALL_TESTS in Visual Studio) creates (and runs) pcre2_test.bat (and depending @@ -410,33 +419,69 @@ Otherwise: To independently test the just-in-time compiler, run pcre2_jit_test.exe. -BUILDING PCRE2 ON NATIVE Z/OS AND Z/VM +Building PCRE2 on z/OS and z/VM +------------------------------- z/OS and z/VM are operating systems for mainframe computers, produced by IBM. The character code used is EBCDIC, not ASCII or Unicode. In z/OS, UNIX APIs and -applications can be supported through UNIX System Services, and in such an -environment it should be possible to build PCRE2 in the same way as in other -systems, with the EBCDIC related configuration settings, but it is not known if -anybody has tried this. - -In native z/OS (without UNIX System Services) and in z/VM, special ports are -required. For details, please see file 939 on this web site: +applications can be supported through UNIX System Services. + +The PCRE2 codebase compiles and runs with native EBCDIC support on modern z/OS +systems, using the pre-installed tools (/bin/sh, ./configure, and the XLC or +IBM-Clang compilers). PCRE2 supports z/OS using both Autoconf (./configure) and +CMake (which IBM distributes via "zopen install cmake"). + +Note that as of the time of writing, IBM's port of CMake to z/OS has only +partial support for EBCDIC. It is recommended to build PCRE2 using the +./configure script, if you require an EBCDIC build. + +Any EBCDIC codepage should work (PCRE2 does not assume or require IBM-1047), or +PCRE2 can compiled for ASCII/Latin-1/Unicode. + +After unpacking the PCRE2 tarball, you must subsequently tag the files as ASCII +in order for the z/OS shell and compiler to interpret them correctly: + chtag -R -tc ISO8859-1 + +Some unusual features on the IBM platform are: + - The _ALL_SOURCE macro must be provided. Unlike on Linux or macOS, even quite + standard POSIX APIs are not made visible by default. PCRE2's Autoconf and + CMake system both provide this for you. + - The `cc`, `c89`, and even `c99` compilers provided by IBM do not default to + the same argument ordering as other Unix platforms. + - The XLC compiler requires `-qhaltonmsg=CCN3296`, otherwise it will treat any + preprocessor #include errors as a warning rather than an error. Needless to + say this default wrecks Autoconf and CMake's feature-detection tests. + PCRE2's build system is aware of this. + - The test suite (in the testdata/ directory) is entirely in ASCII/UTF-8. + When running the tests, you must ensure that the EBCDIC-native build of + pcre2test receives an EBCDIC version of these files. The easiest way to + achieve this is via filesystem tagging (chtag). Alternatively, you could + manually re-encode the testdata files as EBCDIC, and tag them as EBCDIC. + (Latin-1 and EBCDIC are one-to-one convertible encodings, a simple + byte-by-byte permutation of the 256 values.) + +In native z/OS (without UNIX System Services) and in z/VM, a user has provided a +special port of PCRE2. For details, please see file 939 on this web site: http://www.cbttape.org -Everything in that location, source and executable, is in EBCDIC and native -z/OS file formats. The port provides an API for LE languages such as COBOL and +The user-provided port also provides an API for LE languages such as COBOL and for the z/OS and z/VM versions of the Rexx languages. -BUILDING PCRE2 UNDER VMS +Building PCRE2 under VMS +------------------------ Alexey Chuphin has contributed some auxiliary files for building PCRE2 under OpenVMS. They are in the "vms" directory in the distribution tarball. Please read the file called vms/openvms_readme.txt. The pcre2test and pcre2grep programs contain some VMS-specific code. -============================== -Last updated: 26 December 2024 -============================== +This has not been tested for some time. The PCRE2 maintainers would be grateful +to learn whether it still works (or if anyone still uses it). + + +============================= +Last updated: 17 October 2025 +============================= diff --git a/doc/html/README.txt b/doc/html/README.txt index 5a50f7f..593bab2 100644 --- a/doc/html/README.txt +++ b/doc/html/README.txt @@ -1,5 +1,5 @@ README file for PCRE2 (Perl-compatible regular expression library) ------------------------------------------------------------------- +================================================================== PCRE2 is a re-working of the original PCRE1 library to provide an entirely new API. Since its initial release in 2015, there has been further development of @@ -88,15 +88,17 @@ Building PCRE2 on non-Unix-like systems For a non-Unix-like system, please read the file NON-AUTOTOOLS-BUILD, though if your system supports the use of "configure" and "make" you may be able to build -PCRE2 using autotools in the same way as for many Unix-like systems. +PCRE2 using autotools in the same way as for many Unix-like systems. This file +also contains useful information on building for some unusual Unix environments +(such as EBCDIC mainframes). PCRE2 can also be configured using CMake, which can be run in various ways (command line, GUI, etc). This creates Makefiles, solution files, etc. The file NON-AUTOTOOLS-BUILD has information about CMake. PCRE2 has been compiled on many different operating systems. It should be -straightforward to build PCRE2 on any system that has a Standard C compiler and -library, because it uses only Standard C functions. +straightforward to build PCRE2 on any system that has a C99 or later compiler +and library. Building PCRE2 without using autotools @@ -169,6 +171,9 @@ library. They are also documented in the pcre2build man page. versions of all the relevant libraries are available for linking. See also "Shared libraries" below. + Shared libraries are compiled with symbol versioning enabled on platforms that + support this, but this can be disabled by adding --disable-symvers. + . By default, only the 8-bit library is built. If you add --enable-pcre2-16 to the "configure" command, the 16-bit library is also built. If you add --enable-pcre2-32 to the "configure" command, the 32-bit library is also @@ -309,11 +314,22 @@ library. They are also documented in the pcre2build man page. --enable-ebcdic --disable-unicode - This automatically implies --enable-rebuild-chartables (see above). However, - when PCRE2 is built this way, it always operates in EBCDIC. It cannot support - both EBCDIC and UTF-8/16/32. There is a second option, --enable-ebcdic-nl25, - which specifies that the code value for the EBCDIC NL character is 0x25 - instead of the default 0x15. + This automatically implies --enable-rebuild-chartables (see above), in order + to ensure that you have the correct default character tables for your system's + codepage. There is an exception when you set --enable-ebcdic-ignoring-compiler + (see below), which allows using a default set of EBCDIC 1047 character tables + rather than forcing use of --enable-rebuild-chartables. + + When PCRE2 is built with EBCDIC support, it always operates in EBCDIC. It + cannot support both EBCDIC and ASCII or UTF-8/16/32. + + There is a second option, --enable-ebcdic-nl25, which specifies that the code + value for the EBCDIC NL character is 0x25 instead of the default 0x15. + + There is a third option, --enable-ebcdic-ignoring-compiler, which disregards + the compiler's codepage for determining the numeric value of C character + constants such as 'z', and instead forces PCRE2 to use numeric constants for + the EBCDIC 1047 codepage instead. . If you specify --enable-debug, additional debugging code is included in the build. This option is intended for use by the PCRE2 maintainers. @@ -607,7 +623,7 @@ zip formats. The command "make distcheck" does the same, but then does a trial build of the new distribution to ensure that it works. If you have modified any of the man page sources in the doc directory, you -should first run the maint/PrepareRelease script before making a distribution. +should first run the maint/UpdateAlways script before making a distribution. This script creates the .txt and HTML forms of the documentation from the man pages. @@ -626,9 +642,9 @@ NON-AUTOTOOLS-BUILD. The RunTest script runs the pcre2test test program (which is documented in its own man page) on each of the relevant testinput files in the testdata directory, and compares the output with the contents of the corresponding -testoutput files. RunTest uses a file called testtry to hold the main output -from pcre2test. Other files whose names begin with "test" are used as working -files in some tests. +testoutput files. RunTest places its output in directories +testoutput{8,16,32}{,-jit,-dfa}. Other files whose names begin with "test" are +used as working files in some tests. Some tests are relevant only when certain build-time options were selected. For example, the tests for UTF-8/16/32 features are run only when Unicode support @@ -744,8 +760,16 @@ and with UTF support, respectively. Test 23 tests \C when it is locked out. Tests 24 and 25 test the experimental pattern conversion functions, without and with UTF support, respectively. -Test 26 checks Unicode property support using tests that are generated -automatically from the Unicode data tables. +Test 26 checks Unicode property support using tests that were generated +automatically from the Unicode data tables. These are the archived version of +the tests from Unicode 15. + +Test 27 checks Unicode property support using tests that are generated +automatically from the currently-used Unicode data tables. + +Test 28 tests EBCDIC support, and is only run when PCRE2 is specifically +compiled for EBCDIC. Test 29 tests EBCDIC when NL has been configured to be +0x25. Character tables @@ -822,11 +846,16 @@ The distribution should contain the files listed below. src/pcre2_chartables.c.dist a default set of character tables that assume ASCII coding; unless --enable-rebuild-chartables is specified, used by copying to pcre2_chartables.c + src/pcre2_chartables.c.ebcdic-1047-{nl15,nl25} a default set of character + tables for EBCDIC 1047; used if + --enable-ebcdic-ignoring-compiler is specified + without --enable-rebuild-chartables src/pcre2posix.c ) 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 ) @@ -836,11 +865,10 @@ The distribution should contain the files listed below. src/pcre2_extuni.c ) src/pcre2_find_bracket.c ) src/pcre2_jit_compile.c ) - src/pcre2_jit_match.c ) sources for the functions in the library, - src/pcre2_jit_misc.c ) and some internal functions that they use - src/pcre2_maketables.c ) - src/pcre2_match.c ) + src/pcre2_maketables.c ) sources for the functions in the library, + src/pcre2_match.c ) and some internal functions that they use src/pcre2_match_data.c ) + src/pcre2_match_next.c ) src/pcre2_newline.c ) src/pcre2_ord2utf.c ) src/pcre2_pattern_info.c ) @@ -852,11 +880,9 @@ The distribution should contain the files listed below. src/pcre2_substring.c ) src/pcre2_tables.c ) src/pcre2_ucd.c ) - src/pcre2_ucptables.c ) src/pcre2_valid_utf.c ) src/pcre2_xclass.c ) - src/pcre2_printint.c debugging function that is used by pcre2test, src/pcre2_fuzzsupport.c function for (optional) fuzzing support src/config.h.in template for config.h, when built by "configure" @@ -866,9 +892,12 @@ The distribution should contain the files listed below. src/pcre2_internal.h header for internal use src/pcre2_intmodedep.h a mode-specific internal header src/pcre2_jit_char_inc.h header used by JIT - src/pcre2_jit_neon_inc.h header used by JIT + src/pcre2_jit_match_inc.h header used by JIT + src/pcre2_jit_misc_inc.h header used by JIT src/pcre2_jit_simd_inc.h header used by JIT + src/pcre2_printint_inc.h debugging function that is used by pcre2test src/pcre2_ucp.h header for Unicode property handling + src/pcre2_ucptables_inc.h header with Unicode data tables src/pcre2_util.h header for internal utils deps/sljit/sljit_src/* source files for the JIT compiler @@ -878,6 +907,7 @@ The distribution should contain the files listed below. src/pcre2demo.c simple demonstration of coding calls to PCRE2 src/pcre2grep.c source of a grep utility that uses PCRE2 src/pcre2test.c comprehensive test program + src/pcre2test_inc.h header used by pcre2test src/pcre2_jit_test.c JIT test program src/pcre2posix_test.c POSIX wrapper API test program @@ -932,16 +962,22 @@ The distribution should contain the files listed below. testdata/testoutput* expected test results testdata/grep* input and output for pcre2grep tests testdata/* other supporting test files + src/libpcre2-8.sym ) + src/libpcre2-16.sym ) symbol version scripts for the GNU and Sun linkers + src/libpcre2-32.sym ) + src/libpcre2-posix.sym ) (D) Auxiliary files for CMake support cmake/COPYING-CMAKE-SCRIPTS cmake/FindEditline.cmake cmake/FindReadline.cmake - cmake/pcre2-config-version.cmake.in cmake/pcre2-config.cmake.in + cmake/PCRE2CheckVscript.cmake + cmake/PCRE2UseSystemExtensions.cmake + cmake/PCRE2WarningAsError.cmake + src/config-cmake.h.in CMakeLists.txt - config-cmake.h.in (E) Auxiliary files for building PCRE2 "by hand" @@ -952,9 +988,8 @@ The distribution should contain the files listed below. (F) Auxiliary files for building PCRE2 using other build systems - BUILD.bazel ) - MODULE.bazel ) files used by the Bazel build system - WORKSPACE.bazel ) + BUILD.bazel ) files used by the Bazel + MODULE.bazel ) build system build.zig file used by zig's build system (G) Auxiliary files for building PCRE2 under OpenVMS @@ -964,7 +999,7 @@ The distribution should contain the files listed below. vms/pcre2.h_patch ) vms/stdint.h ) -============================== -Last updated: 18 December 2024 -============================== +============================= +Last updated: 15 October 2025 +============================= diff --git a/doc/html/index.html b/doc/html/index.html index 2d81b67..f33d615 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -7,6 +7,22 @@ --> PCRE2 specification +

Perl-compatible Regular Expressions (revised API: PCRE2)

@@ -18,67 +34,67 @@ first. - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
pcre2  Introductory page
Introductory page
pcre2-config  Information about the installation configuration
Information about the installation configuration
pcre2api  PCRE2's native API
PCRE2's native API
pcre2build  Building PCRE2
Building PCRE2
pcre2callout  The callout facility
The callout facility
pcre2compat  Compability with Perl
Compability with Perl
pcre2convert  Experimental foreign pattern conversion functions
Experimental foreign pattern conversion functions
pcre2demo  A demonstration C program that uses the PCRE2 library
A demonstration C program that uses the PCRE2 library
pcre2grep  The pcre2grep command
The pcre2grep command
pcre2jit  Discussion of the just-in-time optimization support
Discussion of the just-in-time optimization support
pcre2limits  Details of size and other limits
Details of size and other limits
pcre2matching  Discussion of the two matching algorithms
Discussion of the two matching algorithms
pcre2partial  Using PCRE2 for partial matching
Using PCRE2 for partial matching
pcre2pattern  Specification of the regular expressions supported by PCRE2
Specification of the regular expressions supported by PCRE2
pcre2perform  Some comments on performance
Some comments on performance
pcre2posix  The POSIX API to the PCRE2 8-bit library
The POSIX API to the PCRE2 8-bit library
pcre2sample  Discussion of the pcre2demo program
Discussion of the pcre2demo program
pcre2serialize  Serializing functions for saving precompiled patterns
Serializing functions for saving precompiled patterns
pcre2syntax  Syntax quick-reference summary
Syntax quick-reference summary
pcre2test  The pcre2test command for testing PCRE2
The pcre2test command for testing PCRE2
pcre2unicode  Discussion of Unicode and UTF-8/UTF-16/UTF-32 support
Discussion of Unicode and UTF-8/UTF-16/UTF-32 support

@@ -89,238 +105,241 @@ in the library. - + - + - + - + - + - + - + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + - + - + - + - + - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - +
pcre2_callout_enumerate  Enumerate callouts in a compiled pattern
Enumerate callouts in a compiled pattern
pcre2_code_copy  Copy a compiled pattern
Copy a compiled pattern
pcre2_code_copy_with_tables  Copy a compiled pattern and its character tables
Copy a compiled pattern and its character tables
pcre2_code_free  Free a compiled pattern
Free a compiled pattern
pcre2_compile  Compile a regular expression pattern
Compile a regular expression pattern
pcre2_compile_context_copy  Copy a compile context
Copy a compile context
pcre2_compile_context_create  Create a compile context
Create a compile context
pcre2_compile_context_free  Free a compile context
Free a compile context
pcre2_config  Show build-time configuration options
Show build-time related configuration options
pcre2_convert_context_copy  Copy a convert context
Copy a convert context
pcre2_convert_context_create  Create a convert context
Create a convert context
pcre2_convert_context_free  Free a convert context
Free a convert context
pcre2_converted_pattern_free  Free converted foreign pattern
Free converted foreign pattern
pcre2_dfa_match  Match a compiled pattern to a subject string + Match a compiled pattern to a subject string (DFA algorithm; not Perl compatible)
pcre2_general_context_copy  Copy a general context
Copy a general context
pcre2_general_context_create  Create a general context
Create a general context
pcre2_general_context_free  Free a general context
Free a general context
pcre2_get_error_message  Get textual error message for error number
Get textual error message for error number
pcre2_get_mark  Get a (*MARK) name
Get a (*MARK) name
pcre2_get_match_data_size  Get the size of a match data block
Get the size of a match data block
pcre2_get_ovector_count  Get the ovector count
Get the ovector count
pcre2_get_ovector_pointer  Get a pointer to the ovector
Get a pointer to the ovector
pcre2_get_startchar  Get the starting character offset
Get the starting character offset
pcre2_jit_compile  Process a compiled pattern with the JIT compiler
Process a compiled pattern with the JIT compiler
pcre2_jit_free_unused_memory  Free unused JIT memory
Free unused JIT memory
pcre2_jit_match  Fast path interface to JIT matching
Fast path interface to JIT matching
pcre2_jit_stack_assign  Assign stack for JIT matching
Assign stack for JIT matching
pcre2_jit_stack_create  Create a stack for JIT matching
Create a stack for JIT matching
pcre2_jit_stack_free  Free a JIT matching stack
Free a JIT matching stack
pcre2_maketables  Build character tables in current locale
Build character tables in current locale
pcre2_maketables_free  Free character tables
Free character tables
pcre2_match  Match a compiled pattern to a subject string + Match a compiled pattern to a subject string (Perl compatible)
pcre2_match_context_copy  Copy a match context
Copy a match context
pcre2_match_context_create  Create a match context
Create a match context
pcre2_match_context_free  Free a match context
Free a match context
pcre2_match_data_create  Create a match data block
Create a match data block
pcre2_match_data_create_from_pattern  Create a match data block getting size from pattern
Create a match data block getting size from pattern
pcre2_match_data_free  Free a match data block
Free a match data block
pcre2_next_matchGet the match parameters for the next match
pcre2_pattern_convert  Experimental foreign pattern converter
Experimental foreign pattern converter
pcre2_pattern_info  Extract information about a pattern
Extract information about a pattern
pcre2_serialize_decode  Decode serialized compiled patterns
Decode serialized compiled patterns
pcre2_serialize_encode  Serialize compiled patterns for save/restore
Serialize compiled patterns for save/restore
pcre2_serialize_free  Free serialized compiled patterns
Free serialized compiled patterns
pcre2_serialize_get_number_of_codes  Get number of serialized compiled patterns
Get number of serialized compiled patterns
pcre2_set_bsr  Set \R convention
Set \R convention
pcre2_set_callout  Set up a callout function
Set up a callout function
pcre2_set_character_tables  Set character tables
Set character tables
pcre2_set_compile_extra_options  Set compile time extra options
Set compile time extra options
pcre2_set_compile_recursion_guard  Set up a compile recursion guard function
Set up a compile recursion guard function
pcre2_set_depth_limit  Set the match backtracking depth limit
Set the match backtracking depth limit
pcre2_set_glob_escape  Set glob escape character
Set glob escape character
pcre2_set_glob_separator  Set glob separator character
Set glob separator character
pcre2_set_heap_limit  Set the match backtracking heap limit
Set the match backtracking heap limit
pcre2_set_match_limit  Set the match limit
Set the match limit
pcre2_set_max_pattern_compiled_length  Set the maximum length of a compiled pattern
Set the maximum length of a compiled pattern
pcre2_set_max_pattern_length  Set the maximum length of a pattern
Set the maximum length of a pattern
pcre2_set_max_varlookbehind  Set the maximum match length for a variable-length lookbehind
Set the maximum match length for a variable-length lookbehind
pcre2_set_newline  Set the newline convention
Set the newline convention
pcre2_set_offset_limit  Set the offset limit
Set the offset limit
pcre2_set_optimize  Set an optimization directive
Set an optimization directive
pcre2_set_parens_nest_limit  Set the parentheses nesting limit
Set the parentheses nesting limit
pcre2_set_recursion_limit  Obsolete: use pcre2_set_depth_limit
Obsolete: use pcre2_set_depth_limit
pcre2_set_recursion_memory_management  Obsolete function that (from 10.30 onwards) does nothing
Obsolete function that (from 10.30 onwards) does nothing
pcre2_set_substitute_callout  Set a substitution callout function
Set a substitution callout function
pcre2_set_substitute_case_callout  Set a substitution case callout function
Set a substitution case callout function
pcre2_substitute  Match a compiled pattern to a subject string and do + Match a compiled pattern to a subject string and do substitutions
pcre2_substring_copy_byname  Extract named substring into given buffer
Extract named substring into given buffer
pcre2_substring_copy_bynumber  Extract numbered substring into given buffer
Extract numbered substring into given buffer
pcre2_substring_free  Free extracted substring
Free extracted substring
pcre2_substring_get_byname  Extract named substring into new memory
Extract named substring into new memory
pcre2_substring_get_bynumber  Extract numbered substring into new memory
Extract numbered substring into new memory
pcre2_substring_length_byname  Find length of named substring
Find length of named substring
pcre2_substring_length_bynumber  Find length of numbered substring
Find length of numbered substring
pcre2_substring_list_free  Free list of extracted substrings
Free list of extracted substrings
pcre2_substring_list_get  Extract all substrings into new memory
Extract all substrings into new memory
pcre2_substring_nametable_scan  Find table entries for given string name
Find table entries for given string name
pcre2_substring_number_from_name  Convert captured string name to number
Convert captured string name to number
diff --git a/doc/html/pcre2-config.html b/doc/html/pcre2-config.html index b71d760..371ec8f 100644 --- a/doc/html/pcre2-config.html +++ b/doc/html/pcre2-config.html @@ -20,82 +20,83 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    SYNOPSIS
    -

    +

    SYNOPSIS

    +

    pcre2-config [--prefix] [--exec-prefix] [--version] [--libs8] [--libs16] [--libs32] [--libs-posix] [--cflags] [--cflags-posix] -

    -
    DESCRIPTION
    -

    +

    +

    DESCRIPTION

    +

    pcre2-config returns the configuration of the installed PCRE2 libraries and the options required to compile a program to use them. Some of the options -apply only to the 8-bit, or 16-bit, or 32-bit libraries, respectively, and are -not available for libraries that have not been built. If an unavailable option -is encountered, the "usage" information is output. -

    -
    OPTIONS
    -

    +apply only to the 8-bit, 16-bit, or 32-bit libraries, respectively, and are not +available for libraries that have not been built. If an unavailable option is +encountered, the "usage" information is output. +

    +

    OPTIONS

    +

    --prefix -Writes the directory prefix used in the PCRE2 installation for architecture -independent files (/usr on many systems, /usr/local on some -systems) to the standard output. -

    -

    +Writes the directory prefix used in the PCRE2 installation for +architecture-independent files (/usr on many systems, /usr/local on +some systems) to the standard output. +

    +

    --exec-prefix -Writes the directory prefix used in the PCRE2 installation for architecture -dependent files (normally the same as --prefix) to the standard output. -

    -

    +Writes the directory prefix used in the PCRE2 installation for +architecture-dependent files (normally the same as --prefix) to the +standard output. +

    +

    --version Writes the version number of the installed PCRE2 libraries to the standard output. -

    -

    +

    +

    --libs8 Writes to the standard output the command line options required to link with the 8-bit PCRE2 library (-lpcre2-8 on many systems). -

    -

    +

    +

    --libs16 Writes to the standard output the command line options required to link with the 16-bit PCRE2 library (-lpcre2-16 on many systems). -

    -

    +

    +

    --libs32 Writes to the standard output the command line options required to link with the 32-bit PCRE2 library (-lpcre2-32 on many systems). -

    -

    +

    +

    --libs-posix Writes to the standard output the command line options required to link with PCRE2's POSIX API wrapper library (-lpcre2-posix -lpcre2-8 on many systems). -

    -

    +

    +

    --cflags Writes to the standard output the command line options required to compile files that use PCRE2 (this may include some -I options, but is blank on many systems). -

    -

    +

    +

    --cflags-posix Writes to the standard output the command line options required to compile files that use PCRE2's POSIX API wrapper library (this may include some -I options, but is blank on many systems). -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2(3) -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    This manual page was originally written by Mark Baker for the Debian GNU/Linux system. It has been subsequently revised as a generic PCRE2 man page. -

    -
    REVISION
    -

    -Last updated: 28 September 2014 +

    +

    REVISION

    +

    +Last updated: 22 February 2025

    Return to the PCRE2 index page. diff --git a/doc/html/pcre2.html b/doc/html/pcre2.html index e72b6b1..69b25db 100644 --- a/doc/html/pcre2.html +++ b/doc/html/pcre2.html @@ -19,8 +19,8 @@ please consult the man page, in case the conversion went wrong.

  • AUTHORS
  • REVISION -
    INTRODUCTION
    -

    +

    INTRODUCTION

    +

    PCRE2 is the name used for a revised API for the PCRE library, which is a set of functions, written in C, that implement regular expression pattern matching using the same syntax and semantics as Perl, with just a few differences. After @@ -30,23 +30,23 @@ by abolishing the separate "study" optimizing function; in PCRE2, patterns are automatically optimized where possible. Since forking from PCRE1, the code has been extensively refactored and new features introduced. The old library is now obsolete and is no longer maintained. -

    -

    +

    +

    As well as Perl-style regular expression patterns, some features that appeared in Python and the original PCRE before they appeared in Perl are available -using the Python syntax. There is also some support for one or two .NET and -Oniguruma syntax items, and there are options for requesting some minor changes -that give better ECMAScript (aka JavaScript) compatibility. -

    -

    +using the Python syntax. There is also support for some .NET and Oniguruma +syntax items, and there are options for requesting minor changes that give +better ECMAScript (JavaScript) compatibility. +

    +

    The source code for PCRE2 can be compiled to support strings of 8-bit, 16-bit, or 32-bit code units, which means that up to three separate libraries may be -installed, one for each code unit size. The size of code unit is not related to -the bit size of the underlying hardware. In a 64-bit environment that also +installed, one for each code unit size. The size of a code unit is not related +to the bit size of the underlying hardware. In a 64-bit environment that also supports 32-bit applications, versions of PCRE2 that are compiled in both 64-bit and 32-bit modes may be needed. -

    -

    +

    +

    The original work to extend PCRE to 16-bit and 32-bit code units was done by Zoltan Herczeg and Christian Persch, respectively. In all three cases, strings can be interpreted either as one character per code unit, or as UTF-encoded @@ -56,25 +56,25 @@ UTF code units must be enabled explicitly at run time. The version of Unicode in use can be discovered by running

       pcre2test -C
    -
    -

    -

    + +

    +

    The three libraries contain identical sets of functions, with names ending in _8, _16, or _32, respectively (for example, pcre2_compile_8()). However, by defining PCRE2_CODE_UNIT_WIDTH to be 8, 16, or 32, a program that uses just one code unit width can be written using generic names such as pcre2_compile(), and the documentation is written assuming that this is the case. -

    -

    +

    +

    In addition to the Perl-compatible matching function, PCRE2 contains an alternative function that matches the same compiled patterns in a different way. In certain circumstances, the alternative function has some advantages. For a discussion of the two matching algorithms, see the pcre2matching page. -

    -

    +

    +

    Details of exactly which Perl regular expression features are and are not supported by PCRE2 are given in separate documents. See the pcre2pattern @@ -83,8 +83,8 @@ and pages. There is a syntax summary in the pcre2syntax page. -

    -

    +

    +

    Some features of PCRE2 can be included, excluded, or changed when the library is built. The pcre2_config() @@ -95,10 +95,10 @@ page. Documentation about building PCRE2 for various operating systems can be found in the README and -NON-AUTOTOOLS_BUILD +NON-AUTOTOOLS-BUILD files in the source distribution. -

    -

    +

    +

    The libraries contains a number of undocumented internal functions and data tables that are used by more than one of the exported external functions, but which are not intended for use by external callers. Their names all begin with @@ -106,9 +106,9 @@ which are not intended for use by external callers. Their names all begin with environments, it is possible to control which external symbols are exported when a shared library is built, and in these cases the undocumented symbols are not exported. -

    -
    SECURITY CONSIDERATIONS
    -

    +

    +

    SECURITY CONSIDERATIONS

    +

    If you are using PCRE2 in a non-UTF application that permits users to supply arbitrary patterns for compilation, you should be aware of a feature that allows users to turn on UTF support from within a pattern. For example, an @@ -118,34 +118,34 @@ patterns and subjects as strings of UTF-8 code units instead of individual matched to be checked for UTF-8 validity. If the data string is very long, such a check might use sufficiently many resources as to cause your application to lose performance. -

    -

    +

    +

    One way of guarding against this possibility is to use the pcre2_pattern_info() function to check the compiled pattern's options for PCRE2_UTF. Alternatively, you can set the PCRE2_NEVER_UTF option when calling pcre2_compile(). This causes a compile time error if the pattern contains a UTF-setting sequence. -

    -

    +

    +

    The use of Unicode properties for character types such as \d can also be enabled from within the pattern, by specifying "(*UCP)". This feature can be disallowed by setting the PCRE2_NEVER_UCP option. -

    -

    +

    +

    If your application is one that supports UTF, be aware that validity checking can take time. If the same data string is to be matched many times, you can use the PCRE2_NO_UTF_CHECK option for the second and subsequent matches to avoid running redundant checks. -

    -

    +

    +

    The use of the \C escape sequence in a UTF-8 or UTF-16 pattern can lead to problems, because it may leave the current matching point in the middle of a multi-code-unit character. The PCRE2_NEVER_BACKSLASH_C option can be used by an application to lock out the use of \C, causing a compile-time error if it is encountered. It is also possible to build PCRE2 with the use of \C permanently disabled. -

    -

    +

    +

    Another way that performance can be hit is by running a pattern that has a very large search tree against a string that will never match. Nested unlimited repeats in a pattern are a common example. PCRE2 provides some protection @@ -153,9 +153,9 @@ against this: see the pcre2_set_match_limit() function in the pcre2api page. There is a similar function called pcre2_set_depth_limit() that can be used to restrict the amount of memory that is used. -

    -
    USER DOCUMENTATION
    -

    +

    +

    USER DOCUMENTATION

    +

    The user documentation for PCRE2 comprises a number of different sections. In the "man" format, each of these is a separate "man page". In the HTML format, each is a separate page, linked from the index page. In the plain text format, @@ -189,23 +189,23 @@ listing), and the short pages for individual functions, are concatenated in In the "man" and HTML formats, there is also a short page for each C library function, listing its arguments and results. -

    -
    AUTHORS
    -

    +

    +

    AUTHORS

    +

    The current maintainers of PCRE2 are Nicholas Wilson and Zoltan Herczeg. -

    -

    +

    +

    PCRE2 was written by Philip Hazel, of the University Computing Service, Cambridge, England. Many others have also contributed. -

    -

    +

    +

    To contact the maintainers, please use the GitHub issues tracker or PCRE2 mailing list, as described at the project page: https://github.com/PCRE2Project/pcre2 -

    -
    REVISION
    -

    -Last updated: 18 December 2024 +

    +

    REVISION

    +

    +Last updated: 22 February 2025
    Copyright © 1997-2021 University of Cambridge.
    diff --git a/doc/html/pcre2_callout_enumerate.html b/doc/html/pcre2_callout_enumerate.html index 505ea7b..6f4aec9 100644 --- a/doc/html/pcre2_callout_enumerate.html +++ b/doc/html/pcre2_callout_enumerate.html @@ -12,21 +12,21 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_callout_enumerate(const pcre2_code *code, int (*callback)(pcre2_callout_enumerate_block *, void *), void *callout_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function scans a compiled regular expression and calls the callback() function for each callout within the pattern. The yield of the function is zero for success and non-zero otherwise. The arguments are: @@ -51,8 +51,8 @@ that was passed to pcre2_callout_enumerate(). The callback() function must return zero for success. Any other value causes the pattern scan to stop, with the value being passed back as the result of pcre2_callout_enumerate(). -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_code_copy.html b/doc/html/pcre2_code_copy.html index 667d7b7..0dbecbb 100644 --- a/doc/html/pcre2_code_copy.html +++ b/doc/html/pcre2_code_copy.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_code *pcre2_code_copy(const pcre2_code *code); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function makes a copy of the memory used for a compiled pattern, excluding any memory used by the JIT compiler. Without a subsequent call to pcre2_jit_compile(), the copy can be used only for non-JIT matching. The pointer to the character tables is copied, not the tables themselves (see pcre2_code_copy_with_tables()). The yield of the function is NULL if code is NULL or if sufficient memory cannot be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_code_copy_with_tables.html b/doc/html/pcre2_code_copy_with_tables.html index 67b2e1f..3fb3885 100644 --- a/doc/html/pcre2_code_copy_with_tables.html +++ b/doc/html/pcre2_code_copy_with_tables.html @@ -12,19 +12,19 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_code *pcre2_code_copy_with_tables(const pcre2_code *code); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function makes a copy of the memory used for a compiled pattern, excluding any memory used by the JIT compiler. Without a subsequent call to pcre2_jit_compile(), the copy can be used only for non-JIT matching. @@ -32,8 +32,8 @@ Unlike pcre2_code_copy(), a separate copy of the character tables is also made, with the new code pointing to it. This memory will be automatically freed when pcre2_code_free() is called. The yield of the function is NULL if code is NULL or if sufficient memory cannot be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_code_free.html b/doc/html/pcre2_code_free.html index ff302fc..8fad4a9 100644 --- a/doc/html/pcre2_code_free.html +++ b/doc/html/pcre2_code_free.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_code_free(pcre2_code *code); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    If code is NULL, this function does nothing. Otherwise, code must point to a compiled pattern. This function frees its memory, including any memory used by the JIT compiler. If the compiled pattern was created by a call to pcre2_code_copy_with_tables(), the memory for the character tables is also freed. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_compile.html b/doc/html/pcre2_compile.html index ee933f3..59ec537 100644 --- a/doc/html/pcre2_compile.html +++ b/doc/html/pcre2_compile.html @@ -12,21 +12,21 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_code *pcre2_compile(PCRE2_SPTR pattern, PCRE2_SIZE length, uint32_t options, int *errorcode, PCRE2_SIZE *erroroffset, pcre2_compile_context *ccontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function compiles a regular expression pattern into an internal form. Its arguments are:

    @@ -88,13 +88,13 @@ The primary option bits are:
     
    PCRE2 must be built with Unicode support (the default) in order to use PCRE2_UTF, PCRE2_UCP and related options. -

    -

    +

    +

    Additional options may be set in the compile context via the pcre2_set_compile_extra_options function. -

    -

    +

    +

    If either of errorcode or erroroffset is NULL, the function returns NULL immediately. Otherwise, the yield of this function is a pointer to a private data structure that contains the compiled pattern, or NULL if an error @@ -102,13 +102,13 @@ was detected. In the error case, a text error message can be obtained by passing the value returned via the errorcode argument to the pcre2_get_error_message() function. The offset (in code units) where the error was encountered is returned via the erroroffset argument. -

    -

    +

    +

    If there is no error, the value passed via errorcode returns the message "no error" if passed to pcre2_get_error_message(), and the value passed via erroroffset is zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API, with more detail on each option, in the pcre2api diff --git a/doc/html/pcre2_compile_context_copy.html b/doc/html/pcre2_compile_context_copy.html index 9e9884b..d413015 100644 --- a/doc/html/pcre2_compile_context_copy.html +++ b/doc/html/pcre2_compile_context_copy.html @@ -12,25 +12,25 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_compile_context *pcre2_compile_context_copy( pcre2_compile_context *ccontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function makes a new copy of a compile context, using the memory allocation function that was used for the original context. The result is NULL if the memory cannot be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_compile_context_create.html b/doc/html/pcre2_compile_context_create.html index 5eacd4e..5433b3e 100644 --- a/doc/html/pcre2_compile_context_create.html +++ b/doc/html/pcre2_compile_context_create.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_compile_context *pcre2_compile_context_create( pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function creates and initializes a new compile context. If its argument is NULL, malloc() is used to get the necessary memory; otherwise the memory allocation function within the general context is used. The result is NULL if the memory could not be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_compile_context_free.html b/doc/html/pcre2_compile_context_free.html index b4159b1..8d30527 100644 --- a/doc/html/pcre2_compile_context_free.html +++ b/doc/html/pcre2_compile_context_free.html @@ -12,25 +12,25 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_compile_context_free(pcre2_compile_context *ccontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function frees the memory occupied by a compile context, using the memory freeing function from the general context with which it was created, or free() if that was not set. If the argument is NULL, the function returns immediately without doing anything. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_config.html b/doc/html/pcre2_config.html index f05bd06..e45542c 100644 --- a/doc/html/pcre2_config.html +++ b/doc/html/pcre2_config.html @@ -12,19 +12,19 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_config(uint32_t what, void *where); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function makes it possible for a client program to find out which optional features are available in the version of the PCRE2 library it is using. The arguments are as follows: @@ -35,45 +35,46 @@ arguments are as follows: If where is NULL, the function returns the amount of memory needed for the requested information. When the information is a string, the value is in code units; for other types of data it is in bytes. -

    -

    +

    +

    If where is not NULL, for PCRE2_CONFIG_JITTARGET, PCRE2_CONFIG_UNICODE_VERSION, and PCRE2_CONFIG_VERSION it must point to a buffer that is large enough to hold the string. For all other codes it must point to a uint32_t integer variable. The available codes are:

    -  PCRE2_CONFIG_BSR             Indicates what \R matches by default:
    -                                 PCRE2_BSR_UNICODE
    -                                 PCRE2_BSR_ANYCRLF
    -  PCRE2_CONFIG_COMPILED_WIDTHS Which of 8/16/32 support was compiled
    -  PCRE2_CONFIG_DEPTHLIMIT      Default backtracking depth limit
    -  PCRE2_CONFIG_HEAPLIMIT       Default heap memory limit
    -  PCRE2_CONFIG_JIT             Availability of just-in-time compiler support (1=yes 0=no)
    -  PCRE2_CONFIG_JITTARGET       Information (a string) about the target architecture for the JIT compiler
    -  PCRE2_CONFIG_LINKSIZE        Configured internal link size (2, 3, 4)
    -  PCRE2_CONFIG_MATCHLIMIT      Default internal resource limit
    +  PCRE2_CONFIG_BSR                Indicates what \R matches by default:
    +                                    PCRE2_BSR_UNICODE
    +                                    PCRE2_BSR_ANYCRLF
    +  PCRE2_CONFIG_COMPILED_WIDTHS    Which of 8/16/32 support was compiled
    +  PCRE2_CONFIG_DEPTHLIMIT         Default backtracking depth limit
    +  PCRE2_CONFIG_EFFECTIVE_LINKSIZE How many bytes are used for link size
    +  PCRE2_CONFIG_HEAPLIMIT          Default heap memory limit
    +  PCRE2_CONFIG_JIT                Availability of just-in-time compiler support (1=yes 0=no)
    +  PCRE2_CONFIG_JITTARGET          Information (a string) about the target architecture for the JIT compiler
    +  PCRE2_CONFIG_LINKSIZE           Configured internal link size (2, 3, 4)
    +  PCRE2_CONFIG_MATCHLIMIT         Default internal resource limit
       PCRE2_CONFIG_NEVER_BACKSLASH_C  Whether or not \C is disabled
    -  PCRE2_CONFIG_NEWLINE         Code for the default newline sequence:
    -                                 PCRE2_NEWLINE_CR
    -                                 PCRE2_NEWLINE_LF
    -                                 PCRE2_NEWLINE_CRLF
    -                                 PCRE2_NEWLINE_ANY
    -                                 PCRE2_NEWLINE_ANYCRLF
    -                                 PCRE2_NEWLINE_NUL
    -  PCRE2_CONFIG_PARENSLIMIT     Default parentheses nesting limit
    -  PCRE2_CONFIG_RECURSIONLIMIT  Obsolete: use PCRE2_CONFIG_DEPTHLIMIT
    -  PCRE2_CONFIG_STACKRECURSE    Obsolete: always returns 0
    -  PCRE2_CONFIG_UNICODE         Availability of Unicode support (1=yes 0=no)
    -  PCRE2_CONFIG_UNICODE_VERSION The Unicode version (a string)
    -  PCRE2_CONFIG_VERSION         The PCRE2 version (a string)
    +  PCRE2_CONFIG_NEWLINE            Code for the default newline sequence:
    +                                    PCRE2_NEWLINE_CR
    +                                    PCRE2_NEWLINE_LF
    +                                    PCRE2_NEWLINE_CRLF
    +                                    PCRE2_NEWLINE_ANY
    +                                    PCRE2_NEWLINE_ANYCRLF
    +                                    PCRE2_NEWLINE_NUL
    +  PCRE2_CONFIG_PARENSLIMIT        Default parentheses nesting limit
    +  PCRE2_CONFIG_RECURSIONLIMIT     Obsolete: use PCRE2_CONFIG_DEPTHLIMIT
    +  PCRE2_CONFIG_STACKRECURSE       Obsolete: always returns 0
    +  PCRE2_CONFIG_UNICODE            Availability of Unicode support (1=yes 0=no)
    +  PCRE2_CONFIG_UNICODE_VERSION    The Unicode version (a string)
    +  PCRE2_CONFIG_VERSION            The PCRE2 version (a string)
     
    The function yields a non-negative value on success or the negative value PCRE2_ERROR_BADOPTION otherwise. This is also the result for the PCRE2_CONFIG_JITTARGET code if JIT support is not available. When a string is requested, the function returns the number of code units used, including the terminating zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_convert_context_copy.html b/doc/html/pcre2_convert_context_copy.html index 3c44ac6..5f6be6a 100644 --- a/doc/html/pcre2_convert_context_copy.html +++ b/doc/html/pcre2_convert_context_copy.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_convert_context *pcre2_convert_context_copy( pcre2_convert_context *cvcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is part of an experimental set of pattern conversion functions. It makes a new copy of a convert context, using the memory allocation function that was used for the original context. The result is NULL if the memory cannot be obtained. -

    -

    +

    +

    The pattern conversion functions are described in the pcre2convert documentation. diff --git a/doc/html/pcre2_convert_context_create.html b/doc/html/pcre2_convert_context_create.html index 2564780..d5ab22a 100644 --- a/doc/html/pcre2_convert_context_create.html +++ b/doc/html/pcre2_convert_context_create.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_convert_context *pcre2_convert_context_create( pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is part of an experimental set of pattern conversion functions. It creates and initializes a new convert context. If its argument is NULL, malloc() is used to get the necessary memory; otherwise the memory allocation function within the general context is used. The result is NULL if the memory could not be obtained. -

    -

    +

    +

    The pattern conversion functions are described in the pcre2convert documentation. diff --git a/doc/html/pcre2_convert_context_free.html b/doc/html/pcre2_convert_context_free.html index e9b142b..cc19e79 100644 --- a/doc/html/pcre2_convert_context_free.html +++ b/doc/html/pcre2_convert_context_free.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_convert_context_free(pcre2_convert_context *cvcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is part of an experimental set of pattern conversion functions. It frees the memory occupied by a convert context, using the memory freeing function from the general context with which it was created, or free() if that was not set. If the argument is NULL, the function returns immediately without doing anything. -

    -

    +

    +

    The pattern conversion functions are described in the pcre2convert documentation. diff --git a/doc/html/pcre2_converted_pattern_free.html b/doc/html/pcre2_converted_pattern_free.html index 01d28d7..8f082f4 100644 --- a/doc/html/pcre2_converted_pattern_free.html +++ b/doc/html/pcre2_converted_pattern_free.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_converted_pattern_free(PCRE2_UCHAR *converted_pattern); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is part of an experimental set of pattern conversion functions. It frees the memory occupied by a converted pattern that was obtained by calling pcre2_pattern_convert() with arguments that caused it to place the converted pattern into newly obtained heap memory. If the argument is NULL, the function returns immediately without doing anything. -

    -

    +

    +

    The pattern conversion functions are described in the pcre2convert documentation. diff --git a/doc/html/pcre2_dfa_match.html b/doc/html/pcre2_dfa_match.html index 0ae428c..0f36de5 100644 --- a/doc/html/pcre2_dfa_match.html +++ b/doc/html/pcre2_dfa_match.html @@ -12,23 +12,23 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_dfa_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext, int *workspace, PCRE2_SIZE wscount); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function matches a compiled regular expression against a given subject string, using an alternative matching algorithm that scans the subject string just once (except when processing lookaround assertions). This function is @@ -49,8 +49,8 @@ The size of output vector needed to contain all the results depends on the number of simultaneous matches, not on the number of parentheses in the pattern. Using pcre2_match_data_create_from_pattern() to create the match data block is therefore not advisable when using this function. -

    -

    +

    +

    A match context is needed only if you want to set up a callout function or specify the heap limit or the match or the recursion depth limits. The length and startoffset values are code units, not characters. The diff --git a/doc/html/pcre2_general_context_copy.html b/doc/html/pcre2_general_context_copy.html index 0018534..fb2c296 100644 --- a/doc/html/pcre2_general_context_copy.html +++ b/doc/html/pcre2_general_context_copy.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_general_context *pcre2_general_context_copy( pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function makes a new copy of a general context, using the memory allocation functions in the context, if set, to get the necessary memory. Otherwise malloc() is used. The result is NULL if the memory cannot be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_general_context_create.html b/doc/html/pcre2_general_context_create.html index a1a165d..808bbcc 100644 --- a/doc/html/pcre2_general_context_create.html +++ b/doc/html/pcre2_general_context_create.html @@ -12,28 +12,28 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_general_context *pcre2_general_context_create( void *(*private_malloc)(size_t, void *), void (*private_free)(void *, void *), void *memory_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function creates and initializes a general context. The arguments define custom memory management functions and a data value that is passed to them when they are called. The private_malloc() function is used to get memory for the context. If either of the first two arguments is NULL, the system memory management function is used. The result is NULL if no memory could be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_general_context_free.html b/doc/html/pcre2_general_context_free.html index 9f335f5..e370f1c 100644 --- a/doc/html/pcre2_general_context_free.html +++ b/doc/html/pcre2_general_context_free.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_general_context_free(pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function frees the memory occupied by a general context, using the memory freeing function within the context, if set. If the argument is NULL, the function returns immediately without doing anything. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_get_error_message.html b/doc/html/pcre2_get_error_message.html index 7005760..904e24d 100644 --- a/doc/html/pcre2_get_error_message.html +++ b/doc/html/pcre2_get_error_message.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_get_error_message(int errorcode, PCRE2_UCHAR *buffer, PCRE2_SIZE bufflen); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function provides a textual error message for each PCRE2 error code. Compilation errors are positive numbers; UTF formatting errors and matching errors are negative numbers. The arguments are: @@ -39,8 +39,8 @@ trailing zero, or the negative error code PCRE2_ERROR_NOMEMORY if the buffer is too small. In this case, the returned message is truncated (but still with a trailing zero). If errorcode does not contain a recognized error code number, the negative value PCRE2_ERROR_BADDATA is returned. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_get_mark.html b/doc/html/pcre2_get_mark.html index 88e6326..fe15fc5 100644 --- a/doc/html/pcre2_get_mark.html +++ b/doc/html/pcre2_get_mark.html @@ -12,31 +12,31 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    PCRE2_SPTR pcre2_get_mark(pcre2_match_data *match_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    After a call of pcre2_match() that was passed the match block that is this function's argument, this function returns a pointer to the last (*MARK), (*PRUNE), or (*THEN) name that was encountered during the matching process. The name is zero-terminated, and is within the compiled pattern. The length of the name is in the preceding code unit. If no name is available, NULL is returned. -

    -

    +

    +

    After a successful match, the name that is returned is the last one on the matching path. After a failed match or a partial match, the last encountered name is returned. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_get_match_data_heapframes_size.html b/doc/html/pcre2_get_match_data_heapframes_size.html index 3c705c6..17ace9c 100644 --- a/doc/html/pcre2_get_match_data_heapframes_size.html +++ b/doc/html/pcre2_get_match_data_heapframes_size.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    PCRE2_SIZE pcre2_get_match_data_heapframes_size( pcre2_match_data *match_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function returns the size, in bytes, of the heapframes data block that is owned by its argument. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_get_match_data_size.html b/doc/html/pcre2_get_match_data_size.html index 113ecaa..d191a90 100644 --- a/doc/html/pcre2_get_match_data_size.html +++ b/doc/html/pcre2_get_match_data_size.html @@ -12,23 +12,23 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    PCRE2_SIZE pcre2_get_match_data_size(pcre2_match_data *match_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function returns the size, in bytes, of the match data block that is its argument. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_get_ovector_count.html b/doc/html/pcre2_get_ovector_count.html index 05aacb6..fed1cdf 100644 --- a/doc/html/pcre2_get_ovector_count.html +++ b/doc/html/pcre2_get_ovector_count.html @@ -12,23 +12,23 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    uint32_t pcre2_get_ovector_count(pcre2_match_data *match_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function returns the number of pairs of offsets in the ovector that forms part of the given match data block. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_get_ovector_pointer.html b/doc/html/pcre2_get_ovector_pointer.html index ff6317e..2b76b7c 100644 --- a/doc/html/pcre2_get_ovector_pointer.html +++ b/doc/html/pcre2_get_ovector_pointer.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *match_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function returns a pointer to the vector of offsets that forms part of the given match data block. The number of pairs can be found by calling pcre2_get_ovector_count(). -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_get_startchar.html b/doc/html/pcre2_get_startchar.html index d2c28b2..56f0fee 100644 --- a/doc/html/pcre2_get_startchar.html +++ b/doc/html/pcre2_get_startchar.html @@ -12,19 +12,19 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *match_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    After a successful call of pcre2_match() that was passed the match block that is this function's argument, this function returns the code unit offset of the character at which the successful match started. For a non-partial match, @@ -32,8 +32,8 @@ this can be different to the value of ovector[0] if the pattern contains the \K escape sequence. After a partial match, however, this value is always the same as ovector[0] because \K does not affect the result of a partial match. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_jit_compile.html b/doc/html/pcre2_jit_compile.html index 791dd0c..edf5b39 100644 --- a/doc/html/pcre2_jit_compile.html +++ b/doc/html/pcre2_jit_compile.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_jit_compile(pcre2_code *code, uint32_t options); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function requests JIT compilation, which, if the just-in-time compiler is available, further processes a compiled pattern into machine code that executes much faster than the pcre2_match() interpretive matching function. Full details are given in the pcre2jit documentation. -

    -

    +

    +

    The availability of JIT support can be tested by calling pcre2_compile_jit() with a single option PCRE2_JIT_TEST_ALLOC (the code argument is ignored, so a NULL value is accepted). Such a call @@ -40,8 +40,8 @@ returns zero if JIT is available and has a working allocator. Otherwise it returns PCRE2_ERROR_NOMEMORY if JIT is available but cannot allocate executable memory, or PCRE2_ERROR_JIT_UNSUPPORTED if JIT support is not compiled. -

    -

    +

    +

    Otherwise, the first argument must be a pointer that was returned by a successful call to pcre2_compile(), and the second must contain one or more of the following bits: @@ -53,8 +53,8 @@ more of the following bits: There is also an obsolete option called PCRE2_JIT_INVALID_UTF, which has been superseded by the pcre2_compile() option PCRE2_MATCH_INVALID_UTF. The old option is deprecated and may be removed in the future. -

    -

    +

    +

    The yield of the function when called with any of the three options above is 0 for success, or a negative error code otherwise. In particular, PCRE2_ERROR_JIT_BADOPTION is returned if JIT is not supported or if an unknown @@ -62,8 +62,8 @@ bit is set in options. The function can also return PCRE2_ERROR_NOMEMORY if JIT is unable to allocate executable memory for the compiler, even if it was because of a system security restriction. In a few cases, the function may return with PCRE2_ERROR_JIT_UNSUPPORTED for unsupported features. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_jit_free_unused_memory.html b/doc/html/pcre2_jit_free_unused_memory.html index 7f37e58..0ee2f13 100644 --- a/doc/html/pcre2_jit_free_unused_memory.html +++ b/doc/html/pcre2_jit_free_unused_memory.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_jit_free_unused_memory(pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function frees unused JIT executable memory. The argument is a general context, for custom memory management, or NULL for standard memory management. JIT memory allocation retains some memory in order to improve future JIT compilation speed. In low memory conditions, pcre2_jit_free_unused_memory() can be used to cause this memory to be freed. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_jit_match.html b/doc/html/pcre2_jit_match.html index 56144ff..0294e6b 100644 --- a/doc/html/pcre2_jit_match.html +++ b/doc/html/pcre2_jit_match.html @@ -12,54 +12,54 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_jit_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function matches a compiled regular expression that has been successfully processed by the JIT compiler against a given subject string, using a matching algorithm that is similar to Perl's. It is a "fast path" interface to JIT, and it bypasses some of the sanity checks that pcre2_match() applies. -

    -

    +

    +

    In UTF mode, the subject string is not checked for UTF validity. Unless PCRE2_MATCH_INVALID_UTF was set when the pattern was compiled, passing an invalid UTF string results in undefined behaviour. Your program may crash or loop or give wrong results. In the absence of PCRE2_MATCH_INVALID_UTF you should only call pcre2_jit_match() in UTF mode if you are sure the subject is valid. -

    -

    +

    +

    The arguments for pcre2_jit_match() are exactly the same as for pcre2_match(), except that the subject string must be specified with a length; PCRE2_ZERO_TERMINATED is not supported. -

    -

    +

    +

    The supported options are PCRE2_NOTBOL, PCRE2_NOTEOL, PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_PARTIAL_HARD, and PCRE2_PARTIAL_SOFT. Unsupported options are ignored. -

    -

    +

    +

    The return values are the same as for pcre2_match() plus PCRE2_ERROR_JIT_BADOPTION if a matching mode (partial or complete) is requested that was not compiled. For details of partial matching, see the pcre2partial page. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the JIT API in the diff --git a/doc/html/pcre2_jit_stack_assign.html b/doc/html/pcre2_jit_stack_assign.html index 4b3abb9..1e83d98 100644 --- a/doc/html/pcre2_jit_stack_assign.html +++ b/doc/html/pcre2_jit_stack_assign.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_jit_stack_assign(pcre2_match_context *mcontext, pcre2_jit_callback callback_function, void *callback_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function provides control over the memory used by JIT as a run-time stack when pcre2_match() or pcre2_jit_match() is called with a pattern that has been successfully processed by the JIT compiler. The information that @@ -35,36 +35,36 @@ passed to a matching function. The arguments of this function are: mcontext a pointer to a match context callback a callback function callback_data a JIT stack or a value to be passed to the callback - -

    -

    + +

    +

    If mcontext is NULL, the function returns immediately, without doing anything. -

    -

    +

    +

    If callback is NULL and callback_data is NULL, an internal 32KiB block on the machine stack is used. -

    -

    +

    +

    If callback is NULL and callback_data is not NULL, callback_data must be a valid JIT stack, the result of calling pcre2_jit_stack_create(). -

    -

    +

    +

    If callback not NULL, it is called with callback_data as an argument at the start of matching, in order to set up a JIT stack. If the result is NULL, the internal 32KiB stack is used; otherwise the return value must be a valid JIT stack, the result of calling pcre2_jit_stack_create(). -

    -

    +

    +

    You may safely use the same JIT stack for multiple patterns, as long as they are all matched in the same thread. In a multithread application, each thread must use its own JIT stack. For more details, see the pcre2jit page. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_jit_stack_create.html b/doc/html/pcre2_jit_stack_create.html index b9dc59d..0c28a13 100644 --- a/doc/html/pcre2_jit_stack_create.html +++ b/doc/html/pcre2_jit_stack_create.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_jit_stack *pcre2_jit_stack_create(size_t startsize, size_t maxsize, pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is used to create a stack for use by the code compiled by the JIT compiler. The first two arguments are a starting size for the stack, and a maximum size to which it is allowed to grow. The final argument is a general @@ -38,8 +38,8 @@ pattern. If the stack couldn't be allocated or the values passed were not reasonable, NULL will be returned. For more details, see the pcre2jit page. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_jit_stack_free.html b/doc/html/pcre2_jit_stack_free.html index 1d078d7..bebdbdd 100644 --- a/doc/html/pcre2_jit_stack_free.html +++ b/doc/html/pcre2_jit_stack_free.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_jit_stack_free(pcre2_jit_stack *jit_stack); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is used to free a JIT stack that was created by pcre2_jit_stack_create() when it is no longer needed. If the argument is NULL, the function returns immediately without doing anything. For more details, see the pcre2jit page. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_maketables.html b/doc/html/pcre2_maketables.html index 1963654..06ec34f 100644 --- a/doc/html/pcre2_maketables.html +++ b/doc/html/pcre2_maketables.html @@ -12,32 +12,32 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    const uint8_t *pcre2_maketables(pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function builds a set of character tables for character code points that are less than 256. These can be passed to pcre2_compile() in a compile context in order to override the internal, built-in tables (which were either defaulted or made by pcre2_maketables() when PCRE2 was compiled). See the pcre2_set_character_tables() page. You might want to do this if you are using a non-standard locale. -

    -

    +

    +

    If the argument is NULL, malloc() is used to get memory for the tables. Otherwise it must point to a general context, which can supply pointers to a custom memory manager. The function yields a pointer to the tables. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_maketables_free.html b/doc/html/pcre2_maketables_free.html index 7316ab2..5532f0f 100644 --- a/doc/html/pcre2_maketables_free.html +++ b/doc/html/pcre2_maketables_free.html @@ -12,30 +12,30 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_maketables_free(pcre2_general_context *gcontext, const uint8_t *tables); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function discards a set of character tables that were created by a call to pcre2_maketables(). -

    -

    +

    +

    The gcontext parameter should match what was used in that call to account for any custom allocators that might be in use; if it is NULL the system free() is used. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page. diff --git a/doc/html/pcre2_match.html b/doc/html/pcre2_match.html index 5584ae3..7f40a56 100644 --- a/doc/html/pcre2_match.html +++ b/doc/html/pcre2_match.html @@ -12,22 +12,22 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function matches a compiled regular expression against a given subject string, using a matching algorithm that is similar to Perl's. It returns offsets to what it has matched and to captured substrings via the diff --git a/doc/html/pcre2_match_context_copy.html b/doc/html/pcre2_match_context_copy.html index 4a719d6..068f7f9 100644 --- a/doc/html/pcre2_match_context_copy.html +++ b/doc/html/pcre2_match_context_copy.html @@ -12,25 +12,25 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_match_context *pcre2_match_context_copy( pcre2_match_context *mcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function makes a new copy of a match context, using the memory allocation function that was used for the original context. The result is NULL if the memory cannot be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_match_context_create.html b/doc/html/pcre2_match_context_create.html index f7f2735..5d0f4d5 100644 --- a/doc/html/pcre2_match_context_create.html +++ b/doc/html/pcre2_match_context_create.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_match_context *pcre2_match_context_create( pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function creates and initializes a new match context. If its argument is NULL, malloc() is used to get the necessary memory; otherwise the memory allocation function within the general context is used. The result is NULL if the memory could not be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_match_context_free.html b/doc/html/pcre2_match_context_free.html index 7f00ea9..7bf3237 100644 --- a/doc/html/pcre2_match_context_free.html +++ b/doc/html/pcre2_match_context_free.html @@ -12,25 +12,25 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_match_context_free(pcre2_match_context *mcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function frees the memory occupied by a match context, using the memory freeing function from the general context with which it was created, or free() if that was not set. If the argument is NULL, the function returns immediately without doing anything. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_match_data_create.html b/doc/html/pcre2_match_data_create.html index c26c3b3..96f7968 100644 --- a/doc/html/pcre2_match_data_create.html +++ b/doc/html/pcre2_match_data_create.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_match_data *pcre2_match_data_create(uint32_t ovecsize, pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function creates a new match data block, which is used for holding the result of a match. The first argument specifies the number of pairs of offsets that are required. These form the "output vector" (ovector) within the match @@ -33,13 +33,13 @@ data block, and are used to identify the matched string and any captured substrings when matching with pcre2_match(), or a number of different matches at the same point when used with pcre2_dfa_match(). There is always one pair of offsets; if ovecsize is zero, it is treated as one. -

    -

    +

    +

    The second argument points to a general context, for custom memory management, or is NULL for system memory management. The result of the function is NULL if the memory for the block could not be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_match_data_create_from_pattern.html b/doc/html/pcre2_match_data_create_from_pattern.html index db58ab9..73e7bdd 100644 --- a/doc/html/pcre2_match_data_create_from_pattern.html +++ b/doc/html/pcre2_match_data_create_from_pattern.html @@ -12,37 +12,37 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    pcre2_match_data *pcre2_match_data_create_from_pattern( const pcre2_code *code, pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function creates a new match data block for holding the result of a match. -The first argument points to a compiled pattern. The number of capturing -parentheses within the pattern is used to compute the number of pairs of -offsets that are required in the match data block. These form the "output -vector" (ovector) within the match data block, and are used to identify the -matched string and any captured substrings when matching with -pcre2_match(). If you are using pcre2_dfa_match(), which uses the -output vector in a different way, you should use pcre2_match_data_create() -instead of this function. -

    -

    +If the first argument is NULL, this function returns NULL, otherwise the first +argument points to a compiled pattern. The number of capturing parentheses +within the pattern is used to compute the number of pairs of offsets that are +required in the match data block. These form the "output vector" (ovector) +within the match data block, and are used to identify the matched string and +any captured substrings when matching with pcre2_match(). If you are +using pcre2_dfa_match(), which uses the output vector in a different way, +you should use pcre2_match_data_create() instead of this function. +

    +

    The second argument points to a general context, for custom memory management, -or is NULL to use the same memory allocator as was used for the compiled +or is NULL to use the same memory allocator that was used for the compiled pattern. The result of the function is NULL if the memory for the block could -not be obtained. -

    -

    +not be obtained or if NULL was provided as the first argument. +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_match_data_free.html b/doc/html/pcre2_match_data_free.html index 1c2520b..8893bf8 100644 --- a/doc/html/pcre2_match_data_free.html +++ b/doc/html/pcre2_match_data_free.html @@ -12,32 +12,32 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_match_data_free(pcre2_match_data *match_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    If match_data is NULL, this function does nothing. Otherwise, match_data must point to a match data block, which this function frees, using the memory freeing function from the general context or compiled pattern with which it was created, or free() if that was not set. If the match data block was previously passed to pcre2_match(), it will have an attached heapframe vector; this is also freed. -

    -

    +

    +

    If the PCRE2_COPY_MATCHED_SUBJECT was used for a successful match using this match data block, the copy of the subject that was referenced within the block is also freed. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_next_match.html b/doc/html/pcre2_next_match.html new file mode 100644 index 0000000..f5f8c46 --- /dev/null +++ b/doc/html/pcre2_next_match.html @@ -0,0 +1,55 @@ + + +pcre2_next_match specification + + +

    pcre2_next_match man page

    +

    +Return to the PCRE2 index page. +

    +

    +This page is part of the PCRE2 HTML documentation. It was generated +automatically from the original man page. If there is any nonsense in it, +please consult the man page, in case the conversion went wrong. +
    +

    +SYNOPSIS +

    +

    +#include <pcre2.h> +

    +

    +int pcre2_next_match(pcre2_match_data *match_data, + PCRE2_SIZE *pstart_offset, uint32_t *poptions); +

    +

    +DESCRIPTION +

    +

    +This function can be called after one of the match functions +(pcre2_match(), pcre2_dfa_match(), or pcre2_jit_match()), and +must be provided with the same match_data parameter. It outputs the +appropriate parameters for searching for the next match in the same subject +string, and is suitable for applications providing "global" matching behaviour +(for example, replacing all matches in the subject, or splitting the subject on +all matches, or simply counting the number of matches). +

    +

    +It returns 0 ("false") if there is no need to make any further match attempts, +or 1 ("true") if another match should be attempted. +

    +

    +The *pstart_offset and *poptions are set if the function returns 1. +The *pstart_offset should be passed to the next match attempt directly, +and the *poptions should be passed to the next match attempt by combining +with the application's match options using OR. +

    +

    +There is a complete description of the PCRE2 native API in the +pcre2api +page and a description of the POSIX API in the +pcre2posix +page. +

    +Return to the PCRE2 index page. +

    diff --git a/doc/html/pcre2_pattern_convert.html b/doc/html/pcre2_pattern_convert.html index 2fcd7cc..58635ad 100644 --- a/doc/html/pcre2_pattern_convert.html +++ b/doc/html/pcre2_pattern_convert.html @@ -12,21 +12,21 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_pattern_convert(PCRE2_SPTR pattern, PCRE2_SIZE length, uint32_t options, PCRE2_UCHAR **buffer, PCRE2_SIZE *blength, pcre2_convert_context *cvcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is part of an experimental set of pattern conversion functions. It converts a foreign pattern (for example, a glob) into a PCRE2 regular expression pattern. Its arguments are: @@ -46,8 +46,8 @@ present (or else malloc()), and the field pointed to by buffer is updated. If buffer points to a non-NULL field, that must point to a buffer whose size is in the variable pointed to by blength. This value is updated. -

    -

    +

    +

    The option bits are:

       PCRE2_CONVERT_UTF                     Input is UTF
    @@ -60,8 +60,8 @@ The option bits are:
     
    The return value from pcre2_pattern_convert() is zero on success or a non-zero PCRE2 error code. -

    -

    +

    +

    The pattern conversion functions are described in the pcre2convert documentation. diff --git a/doc/html/pcre2_pattern_info.html b/doc/html/pcre2_pattern_info.html index eaaac6c..42427af 100644 --- a/doc/html/pcre2_pattern_info.html +++ b/doc/html/pcre2_pattern_info.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_pattern_info(const pcre2_code *code, uint32_t what, void *where); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function returns information about a compiled pattern. Its arguments are:

       code     Pointer to a compiled regular expression pattern
    @@ -96,9 +96,9 @@ The yield of the function is zero on success or:
       PCRE2_ERROR_BADOPTION      the value of what is invalid
       PCRE2_ERROR_BADMODE        the pattern was compiled in the wrong mode
       PCRE2_ERROR_UNSET          the requested information is not set
    -
    -

    -

    + +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_serialize_decode.html b/doc/html/pcre2_serialize_decode.html index 618ffa9..d275df8 100644 --- a/doc/html/pcre2_serialize_decode.html +++ b/doc/html/pcre2_serialize_decode.html @@ -12,21 +12,21 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int32_t pcre2_serialize_decode(pcre2_code **codes, int32_t number_of_codes, const uint8_t *bytes, pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function decodes a serialized set of compiled patterns back into a list of individual patterns. This is possible only on a host that is running the same version of PCRE2, with the same code unit width, and the host must also have @@ -53,8 +53,8 @@ the following negative error codes: PCRE2_ERROR_BADMAGIC may mean that the data is corrupt, or that it was compiled on a system with different endianness. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the serialization functions in the diff --git a/doc/html/pcre2_serialize_encode.html b/doc/html/pcre2_serialize_encode.html index f153270..d25bbd8 100644 --- a/doc/html/pcre2_serialize_encode.html +++ b/doc/html/pcre2_serialize_encode.html @@ -12,21 +12,21 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int32_t pcre2_serialize_encode(const pcre2_code **codes, int32_t number_of_codes, uint8_t **serialized_bytes, PCRE2_SIZE *serialized_size, pcre2_general_context *gcontext); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function encodes a list of compiled patterns into a byte stream that can be saved on disc or elsewhere. Note that this is not an abstract format like Java or .NET. Conversion of the byte stream back into usable compiled patterns @@ -54,8 +54,8 @@ serialized patterns, or one of the following negative error codes: PCRE2_ERROR_BADMAGIC means either that a pattern's code has been corrupted, or that a slot in the vector does not point to a compiled pattern. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the serialization functions in the diff --git a/doc/html/pcre2_serialize_free.html b/doc/html/pcre2_serialize_free.html index 26b435b..aea20fd 100644 --- a/doc/html/pcre2_serialize_free.html +++ b/doc/html/pcre2_serialize_free.html @@ -12,25 +12,25 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_serialize_free(uint8_t *bytes); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function frees the memory that was obtained by pcre2_serialize_encode() to hold a serialized byte stream. The argument must point to such a byte stream or be NULL, in which case the function returns without doing anything. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the serialization functions in the diff --git a/doc/html/pcre2_serialize_get_number_of_codes.html b/doc/html/pcre2_serialize_get_number_of_codes.html index fdd2429..3ddaa02 100644 --- a/doc/html/pcre2_serialize_get_number_of_codes.html +++ b/doc/html/pcre2_serialize_get_number_of_codes.html @@ -12,19 +12,19 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int32_t pcre2_serialize_get_number_of_codes(const uint8_t *bytes); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    The bytes argument must point to a serialized byte stream that was originally created by pcre2_serialize_encode() (though it may have been saved on disc or elsewhere in the meantime). The function returns the number of @@ -37,8 +37,8 @@ codes: PCRE2_ERROR_BADMAGIC may mean that the data is corrupt, or that it was compiled on a system with different endianness. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the serialization functions in the diff --git a/doc/html/pcre2_set_bsr.html b/doc/html/pcre2_set_bsr.html index 8a62f18..2b47bef 100644 --- a/doc/html/pcre2_set_bsr.html +++ b/doc/html/pcre2_set_bsr.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_bsr(pcre2_compile_context *ccontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the convention for processing \R within a compile context. The second argument must be one of PCRE2_BSR_ANYCRLF or PCRE2_BSR_UNICODE. The result is zero for success or PCRE2_ERROR_BADDATA if the second argument is invalid. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_callout.html b/doc/html/pcre2_set_callout.html index 4e7aca6..e74a8f5 100644 --- a/doc/html/pcre2_set_callout.html +++ b/doc/html/pcre2_set_callout.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_callout(pcre2_match_context *mcontext, int (*callout_function)(pcre2_callout_block *), void *callout_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the callout fields in a match context (the first argument). The second argument specifies a callout function, and the third argument is an opaque data item that is passed to it. The result of this function is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_character_tables.html b/doc/html/pcre2_set_character_tables.html index 8564eea..98420bf 100644 --- a/doc/html/pcre2_set_character_tables.html +++ b/doc/html/pcre2_set_character_tables.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_character_tables(pcre2_compile_context *ccontext, const uint8_t *tables); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets a pointer to custom character tables within a compile context. The second argument must point to a set of PCRE2 character tables or be NULL to request the default tables. The result is always zero. Character @@ -33,8 +33,8 @@ tables can be created by calling pcre2_maketables() or by running the pcre2_dftables maintenance command in binary mode (see the pcre2build documentation). -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_compile_extra_options.html b/doc/html/pcre2_set_compile_extra_options.html index cb62022..d6c25cf 100644 --- a/doc/html/pcre2_set_compile_extra_options.html +++ b/doc/html/pcre2_set_compile_extra_options.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_compile_extra_options(pcre2_compile_context *ccontext, uint32_t extra_options); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets additional option bits for pcre2_compile() that are housed in a compile context. It completely replaces all the bits. The extra options are: diff --git a/doc/html/pcre2_set_compile_recursion_guard.html b/doc/html/pcre2_set_compile_recursion_guard.html index c09942c..d392792 100644 --- a/doc/html/pcre2_set_compile_recursion_guard.html +++ b/doc/html/pcre2_set_compile_recursion_guard.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_compile_recursion_guard(pcre2_compile_context *ccontext, int (*guard_function)(uint32_t, void *), void *user_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function defines, within a compile context, a function that is called whenever pcre2_compile() starts to compile a parenthesized part of a pattern. The first argument to the function gives the current depth of @@ -34,8 +34,8 @@ function is set up. The callout function should return zero if all is well, or non-zero to force an error. This feature is provided so that applications can check the available system stack space, in order to avoid running out. The result of pcre2_set_compile_recursion_guard() is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_depth_limit.html b/doc/html/pcre2_set_depth_limit.html index a1cf706..631d1c1 100644 --- a/doc/html/pcre2_set_depth_limit.html +++ b/doc/html/pcre2_set_depth_limit.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_depth_limit(pcre2_match_context *mcontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the backtracking depth limit field in a match context. The result is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_glob_escape.html b/doc/html/pcre2_set_glob_escape.html index 2b55627..0b4a853 100644 --- a/doc/html/pcre2_set_glob_escape.html +++ b/doc/html/pcre2_set_glob_escape.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_glob_escape(pcre2_convert_context *cvcontext, uint32_t escape_char); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is part of an experimental set of pattern conversion functions. It sets the escape character that is used when converting globs. The second argument must either be zero (meaning there is no escape character) or a @@ -33,8 +33,8 @@ punctuation character whose code point is less than 256. The default is grave accent if running under Windows, otherwise backslash. The result of the function is zero for success or PCRE2_ERROR_BADDATA if the second argument is invalid. -

    -

    +

    +

    The pattern conversion functions are described in the pcre2convert documentation. diff --git a/doc/html/pcre2_set_glob_separator.html b/doc/html/pcre2_set_glob_separator.html index 283648e..1d6bdaf 100644 --- a/doc/html/pcre2_set_glob_separator.html +++ b/doc/html/pcre2_set_glob_separator.html @@ -12,28 +12,28 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_glob_separator(pcre2_convert_context *cvcontext, uint32_t separator_char); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is part of an experimental set of pattern conversion functions. It sets the component separator character that is used when converting globs. The second argument must be one of the characters forward slash, backslash, or dot. The default is backslash when running under Windows, otherwise forward slash. The result of the function is zero for success or PCRE2_ERROR_BADDATA if the second argument is invalid. -

    -

    +

    +

    The pattern conversion functions are described in the pcre2convert documentation. diff --git a/doc/html/pcre2_set_heap_limit.html b/doc/html/pcre2_set_heap_limit.html index 3631ef6..a9b53a8 100644 --- a/doc/html/pcre2_set_heap_limit.html +++ b/doc/html/pcre2_set_heap_limit.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_heap_limit(pcre2_match_context *mcontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the backtracking heap limit field in a match context. The result is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_match_limit.html b/doc/html/pcre2_set_match_limit.html index e840c74..a8de8ae 100644 --- a/doc/html/pcre2_set_match_limit.html +++ b/doc/html/pcre2_set_match_limit.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_match_limit(pcre2_match_context *mcontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the match limit field in a match context. The result is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_max_pattern_compiled_length.html b/doc/html/pcre2_set_max_pattern_compiled_length.html index a40f41e..abc1ca7 100644 --- a/doc/html/pcre2_set_max_pattern_compiled_length.html +++ b/doc/html/pcre2_set_max_pattern_compiled_length.html @@ -12,28 +12,28 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_max_pattern_compiled_length( pcre2_compile_context *ccontext, PCRE2_SIZE value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets, in a compile context, the maximum size (in bytes) for the memory needed to hold the compiled version of a pattern that is using this context. The result is always zero. If a pattern that is passed to pcre2_compile() referencing this context needs more memory, an error is generated. The default is the largest number that a PCRE2_SIZE variable can hold, which is effectively unlimited. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_max_pattern_length.html b/doc/html/pcre2_set_max_pattern_length.html index f6e422a..d5fe6aa 100644 --- a/doc/html/pcre2_set_max_pattern_length.html +++ b/doc/html/pcre2_set_max_pattern_length.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_max_pattern_length(pcre2_compile_context *ccontext, PCRE2_SIZE value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets, in a compile context, the maximum text length (in code units) of the pattern that can be compiled. The result is always zero. If a longer pattern is passed to pcre2_compile() there is an immediate error return. The default is effectively unlimited, being the largest value a PCRE2_SIZE variable can hold. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_max_varlookbehind.html b/doc/html/pcre2_set_max_varlookbehind.html index 1c03def..4aca6f0 100644 --- a/doc/html/pcre2_set_max_varlookbehind.html +++ b/doc/html/pcre2_set_max_varlookbehind.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_max_varlookbehind(pcre2_compile_context *ccontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This sets a maximum length for the number of characters matched by a variable-length lookbehind assertion. The default is set when PCRE2 is built, with the ultimate default being 255, the same as Perl. Lookbehind assertions without a bounding length are not supported. The result is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_newline.html b/doc/html/pcre2_set_newline.html index ba81300..34722ff 100644 --- a/doc/html/pcre2_set_newline.html +++ b/doc/html/pcre2_set_newline.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_newline(pcre2_compile_context *ccontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the newline convention within a compile context. This specifies which character(s) are recognized as newlines when compiling and matching patterns. The second argument must be one of: @@ -39,8 +39,8 @@ matching patterns. The second argument must be one of: The result is zero for success or PCRE2_ERROR_BADDATA if the second argument is invalid. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_offset_limit.html b/doc/html/pcre2_set_offset_limit.html index 6d9a85c..51c4e76 100644 --- a/doc/html/pcre2_set_offset_limit.html +++ b/doc/html/pcre2_set_offset_limit.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_offset_limit(pcre2_match_context *mcontext, PCRE2_SIZE value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the offset limit field in a match context. The result is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_optimize.html b/doc/html/pcre2_set_optimize.html index 47caeb2..4b839c6 100644 --- a/doc/html/pcre2_set_optimize.html +++ b/doc/html/pcre2_set_optimize.html @@ -12,31 +12,31 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_optimize(pcre2_compile_context *ccontext, uint32_t directive); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function controls which performance optimizations will be applied by pcre2_compile(). It can be called multiple times with the same compile context; the effects are cumulative, with the effects of later calls taking precedence over earlier ones. -

    -

    +

    +

    The result is zero for success, PCRE2_ERROR_NULL if ccontext is NULL, or PCRE2_ERROR_BADOPTION if directive is unknown. The latter could be useful to detect if a certain optimization is available. -

    -

    +

    +

    The list of possible values for the directive parameter are:

       PCRE2_OPTIMIZATION_FULL   Enable all optimizations (default)
    diff --git a/doc/html/pcre2_set_parens_nest_limit.html b/doc/html/pcre2_set_parens_nest_limit.html
    index 95fd31c..133a63b 100644
    --- a/doc/html/pcre2_set_parens_nest_limit.html
    +++ b/doc/html/pcre2_set_parens_nest_limit.html
    @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated
     automatically from the original man page. If there is any nonsense in it,
     please consult the man page, in case the conversion went wrong.
     
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_parens_nest_limit(pcre2_compile_context *ccontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets, in a compile context, the maximum depth of nested parentheses in a pattern. The result is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_recursion_limit.html b/doc/html/pcre2_set_recursion_limit.html index 9ff68c2..998676e 100644 --- a/doc/html/pcre2_set_recursion_limit.html +++ b/doc/html/pcre2_set_recursion_limit.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t value); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function is obsolete and should not be used in new code. Use pcre2_set_depth_limit() instead. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_recursion_memory_management.html b/doc/html/pcre2_set_recursion_memory_management.html index 37af73c..98742d2 100644 --- a/doc/html/pcre2_set_recursion_memory_management.html +++ b/doc/html/pcre2_set_recursion_memory_management.html @@ -12,26 +12,26 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_recursion_memory_management( pcre2_match_context *mcontext, void *(*private_malloc)(size_t, void *), void (*private_free)(void *, void *), void *memory_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    From release 10.30 onwards, this function is obsolete and does nothing. The result is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_substitute_callout.html b/doc/html/pcre2_set_substitute_callout.html index 8640728..c5ece21 100644 --- a/doc/html/pcre2_set_substitute_callout.html +++ b/doc/html/pcre2_set_substitute_callout.html @@ -12,27 +12,27 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_substitute_callout(pcre2_match_context *mcontext, int (*callout_function)(pcre2_substitute_callout_block *, void *), void *callout_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the substitute callout fields in a match context (the first argument). The second argument specifies a callout function, and the third argument is an opaque data item that is passed to it. The result of this function is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_set_substitute_case_callout.html b/doc/html/pcre2_set_substitute_case_callout.html index ab50687..1e22cd9 100644 --- a/doc/html/pcre2_set_substitute_case_callout.html +++ b/doc/html/pcre2_set_substitute_case_callout.html @@ -12,29 +12,29 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_set_substitute_case_callout(pcre2_match_context *mcontext, PCRE2_SIZE (*callout_function)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, PCRE2_SIZE, int, void *), void *callout_data); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function sets the substitute case callout fields in a match context (the first argument). The second argument specifies a callout function, and the third argument is an opaque data item that is passed to it. The result of this function is always zero. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substitute.html b/doc/html/pcre2_substitute.html index abf0a70..8fa9df0 100644 --- a/doc/html/pcre2_substitute.html +++ b/doc/html/pcre2_substitute.html @@ -12,24 +12,24 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substitute(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext, PCRE2_SPTR replacement, PCRE2_SIZE rlength, PCRE2_UCHAR *outputbuffer, PCRE2_SIZE *outlengthptr); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function matches a compiled regular expression against a given subject string, using a matching algorithm that is similar to Perl's. It then makes a copy of the subject, substituting a replacement string for what was matched. @@ -63,8 +63,8 @@ not characters, as is the contents of the variable pointed at by when the function is called. If the function is successful, the value is changed to the length of the new string, excluding the trailing zero that is automatically added. -

    -

    +

    +

    The subject and replacement lengths can be given as PCRE2_ZERO_TERMINATED for zero-terminated strings. The options are:

    @@ -88,19 +88,20 @@ zero-terminated strings. The options are:
     
    If PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_EXTENDED, PCRE2_SUBSTITUTE_UNKNOWN_UNSET, and PCRE2_SUBSTITUTE_UNSET_EMPTY are ignored. -

    -

    +

    +

    If PCRE2_SUBSTITUTE_MATCHED is set, match_data must be non-NULL; its -contents must be the result of a call to pcre2_match() using the same -pattern and subject. -

    -

    +contents must be the result of a call to pcre2_match() (or +pcre2_jit_match()) using the same pattern, subject pointer, effective +subject length, start offset, and match options. +

    +

    The function returns the number of substitutions, which may be zero if there are no matches. The result may be greater than one only when PCRE2_SUBSTITUTE_GLOBAL is set. In the event of an error, a negative error code is returned. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_copy_byname.html b/doc/html/pcre2_substring_copy_byname.html index fd01805..64427ce 100644 --- a/doc/html/pcre2_substring_copy_byname.html +++ b/doc/html/pcre2_substring_copy_byname.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_copy_byname(pcre2_match_data *match_data, PCRE2_SPTR name, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This is a convenience function for extracting a captured substring, identified by name, into a given buffer. The arguments are:

    @@ -46,8 +46,8 @@ success or one of the following error numbers:
     If there is more than one group with the given name, the first one that is set
     is returned. In this situation PCRE2_ERROR_UNSET means that no group with the
     given name was set.
    -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_copy_bynumber.html b/doc/html/pcre2_substring_copy_bynumber.html index 83e1a27..496bee4 100644 --- a/doc/html/pcre2_substring_copy_bynumber.html +++ b/doc/html/pcre2_substring_copy_bynumber.html @@ -12,21 +12,21 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_copy_bynumber(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This is a convenience function for extracting a captured substring into a given buffer. The arguments are:

    @@ -44,9 +44,9 @@ or one of the following error numbers:
       PCRE2_ERROR_UNSET         the group did not participate in the match
       PCRE2_ERROR_NOMEMORY      the buffer is too small
     
    -
    -

    -

    +

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_free.html b/doc/html/pcre2_substring_free.html index e0d0fbd..ea884ec 100644 --- a/doc/html/pcre2_substring_free.html +++ b/doc/html/pcre2_substring_free.html @@ -12,25 +12,25 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_substring_free(PCRE2_UCHAR *buffer); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This is a convenience function for freeing the memory obtained by a previous call to pcre2_substring_get_byname() or pcre2_substring_get_bynumber(). Its only argument is a pointer to the string. If the argument is NULL, the function does nothing. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_get_byname.html b/doc/html/pcre2_substring_get_byname.html index a4b8771..66ab078 100644 --- a/doc/html/pcre2_substring_get_byname.html +++ b/doc/html/pcre2_substring_get_byname.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_get_byname(pcre2_match_data *match_data, PCRE2_SPTR name, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This is a convenience function for extracting a captured substring by name into newly acquired memory. The arguments are:

    @@ -48,8 +48,8 @@ the following error numbers:
     If there is more than one group with the given name, the first one that is set
     is returned. In this situation PCRE2_ERROR_UNSET means that no group with the
     given name was set.
    -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_get_bynumber.html b/doc/html/pcre2_substring_get_bynumber.html index 391bc82..d9f0d0c 100644 --- a/doc/html/pcre2_substring_get_bynumber.html +++ b/doc/html/pcre2_substring_get_bynumber.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_get_bynumber(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This is a convenience function for extracting a captured substring by number into newly acquired memory. The arguments are:

    @@ -45,9 +45,9 @@ the following error numbers:
       PCRE2_ERROR_UNSET         the group did not participate in the match
       PCRE2_ERROR_NOMEMORY      memory could not be obtained
     
    -
    -

    -

    +

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_length_byname.html b/doc/html/pcre2_substring_length_byname.html index 213bc94..4b7fa79 100644 --- a/doc/html/pcre2_substring_length_byname.html +++ b/doc/html/pcre2_substring_length_byname.html @@ -12,30 +12,32 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_length_byname(pcre2_match_data *match_data, PCRE2_SPTR name, PCRE2_SIZE *length); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function returns the length of a matched substring, identified by name. The arguments are:

       match_data   The match data block for the match
       name         The substring name
    -  length       Where to return the length
    +  length       Where to return the length, or NULL
     
    -The yield is zero on success, or an error code if the substring is not found. -

    -

    +The third argument may be NULL if all you want to know is whether or not a +substring is set. The yield is zero on success, or a negative error code +otherwise. +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_length_bynumber.html b/doc/html/pcre2_substring_length_bynumber.html index db01cca..51371fa 100644 --- a/doc/html/pcre2_substring_length_bynumber.html +++ b/doc/html/pcre2_substring_length_bynumber.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_length_bynumber(pcre2_match_data *match_data, uint32_t number, PCRE2_SIZE *length); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This function returns the length of a matched substring, identified by number. The arguments are:

    @@ -36,8 +36,8 @@ The arguments are:
     The third argument may be NULL if all you want to know is whether or not a
     substring is set. The yield is zero on success, or a negative error code
     otherwise. After a partial match, only substring 0 is available.
    -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_list_free.html b/doc/html/pcre2_substring_list_free.html index dea8bc5..0606116 100644 --- a/doc/html/pcre2_substring_list_free.html +++ b/doc/html/pcre2_substring_list_free.html @@ -12,25 +12,25 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    void pcre2_substring_list_free(PCRE2_UCHAR **list); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This is a convenience function for freeing the store obtained by a previous call to pcre2substring_list_get(). Its only argument is a pointer to the list of string pointers. If the argument is NULL, the function returns immediately, without doing anything. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_list_get.html b/doc/html/pcre2_substring_list_get.html index fd43627..5d22331 100644 --- a/doc/html/pcre2_substring_list_get.html +++ b/doc/html/pcre2_substring_list_get.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_list_get(pcre2_match_data *match_data, " PCRE2_UCHAR ***listptr, PCRE2_SIZE **lengthsptr); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This is a convenience function for extracting all the captured substrings after a pattern match. It builds a list of pointers to the strings, and (optionally) a second list that contains their lengths (in code units), excluding a @@ -44,8 +44,8 @@ A pointer to a list of pointers is put in the variable whose address is in not NULL, a matching list of lengths is created, and its address is placed in lengthsptr. The yield of the function is zero on success or PCRE2_ERROR_NOMEMORY if sufficient memory could not be obtained. -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2_substring_nametable_scan.html b/doc/html/pcre2_substring_nametable_scan.html index 277affa..ae35328 100644 --- a/doc/html/pcre2_substring_nametable_scan.html +++ b/doc/html/pcre2_substring_nametable_scan.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_nametable_scan(const pcre2_code *code, PCRE2_SPTR name, PCRE2_SPTR *first, PCRE2_SPTR *last); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This convenience function finds, for a compiled pattern, the first and last entries for a given name in the table that translates capture group names into numbers. @@ -40,8 +40,8 @@ returns a group number, but if there is more than one matching entry, it is not defined which one. Otherwise, when both pointers have been set, the yield of the function is the length of each entry in code units. If the name is not found, PCRE2_ERROR_NOSUBSTRING is returned. -

    -

    +

    +

    There is a complete description of the PCRE2 native API, including the format of the table entries, in the pcre2api diff --git a/doc/html/pcre2_substring_number_from_name.html b/doc/html/pcre2_substring_number_from_name.html index 160fbda..f00cef6 100644 --- a/doc/html/pcre2_substring_number_from_name.html +++ b/doc/html/pcre2_substring_number_from_name.html @@ -12,20 +12,20 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SYNOPSIS -
    -

    +

    +

    #include <pcre2.h> -

    -

    +

    +

    int pcre2_substring_number_from_name(const pcre2_code *code, PCRE2_SPTR name); -

    -
    +

    +

    DESCRIPTION -
    -

    +

    +

    This convenience function finds the number of a named substring capturing parenthesis in a compiled pattern, provided that it is a unique name. The function arguments are: @@ -38,8 +38,8 @@ found, or PCRE2_ERROR_NOSUBSTRING if it is not found. When duplicate names are allowed (PCRE2_DUPNAMES is set), if the name is not unique, PCRE2_ERROR_NOUNIQUESUBSTRING is returned. You can obtain the list of numbers with the same name by calling pcre2_substring_nametable_scan(). -

    -

    +

    +

    There is a complete description of the PCRE2 native API in the pcre2api page and a description of the POSIX API in the diff --git a/doc/html/pcre2api.html b/doc/html/pcre2api.html index 079cf17..52f013e 100644 --- a/doc/html/pcre2api.html +++ b/doc/html/pcre2api.html @@ -46,18 +46,19 @@ please consult the man page, in case the conversion went wrong.

  • OTHER INFORMATION ABOUT A MATCH
  • ERROR RETURNS FROM pcre2_match()
  • OBTAINING A TEXTUAL ERROR MESSAGE -
  • EXTRACTING CAPTURED SUBSTRINGS BY NUMBER -
  • EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS -
  • EXTRACTING CAPTURED SUBSTRINGS BY NAME -
  • CREATING A NEW STRING WITH SUBSTITUTIONS -
  • DUPLICATE CAPTURE GROUP NAMES -
  • FINDING ALL POSSIBLE MATCHES AT ONE POSITION -
  • MATCHING A PATTERN: THE ALTERNATIVE FUNCTION -
  • SEE ALSO -
  • AUTHOR -
  • REVISION +
  • ITERATING OVER ALL MATCHES +
  • EXTRACTING CAPTURED SUBSTRINGS BY NUMBER +
  • EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS +
  • EXTRACTING CAPTURED SUBSTRINGS BY NAME +
  • CREATING A NEW STRING WITH SUBSTITUTIONS +
  • DUPLICATE CAPTURE GROUP NAMES +
  • FINDING ALL POSSIBLE MATCHES AT ONE POSITION +
  • MATCHING A PATTERN: THE ALTERNATIVE FUNCTION +
  • SEE ALSO +
  • AUTHOR +
  • REVISION -

    +

    #include <pcre2.h>

    @@ -65,9 +66,9 @@ PCRE2 is a new API for PCRE, starting at release 10.0. This document contains a description of all its native functions. See the pcre2 document for an overview of all the PCRE2 documentation. -

    -
    PCRE2 NATIVE API BASIC FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API BASIC FUNCTIONS

    +

    pcre2_code *pcre2_compile(PCRE2_SPTR pattern, PCRE2_SIZE length, uint32_t options, int *errorcode, PCRE2_SIZE *erroroffset, pcre2_compile_context *ccontext); @@ -98,9 +99,9 @@ document for an overview of all the PCRE2 documentation.

    void pcre2_match_data_free(pcre2_match_data *match_data); -

    -
    PCRE2 NATIVE API AUXILIARY MATCH FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API AUXILIARY MATCH FUNCTIONS

    +

    PCRE2_SPTR pcre2_get_mark(pcre2_match_data *match_data);

    @@ -118,9 +119,9 @@ document for an overview of all the PCRE2 documentation.

    PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *match_data); -

    -
    PCRE2 NATIVE API GENERAL CONTEXT FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API GENERAL CONTEXT FUNCTIONS

    +

    pcre2_general_context *pcre2_general_context_create( void *(*private_malloc)(PCRE2_SIZE, void *), void (*private_free)(void *, void *), void *memory_data); @@ -131,9 +132,9 @@ document for an overview of all the PCRE2 documentation.

    void pcre2_general_context_free(pcre2_general_context *gcontext); -

    -
    PCRE2 NATIVE API COMPILE CONTEXT FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API COMPILE CONTEXT FUNCTIONS

    +

    pcre2_compile_context *pcre2_compile_context_create( pcre2_general_context *gcontext);
    @@ -166,7 +167,7 @@ document for an overview of all the PCRE2 documentation.

    int pcre2_set_max_varlookbehind(pcre2_compile_contest *ccontext, -" uint32_t value); + uint32_t value);

    int pcre2_set_newline(pcre2_compile_context *ccontext, @@ -183,9 +184,9 @@ document for an overview of all the PCRE2 documentation.
    int pcre2_set_optimize(pcre2_compile_context *ccontext, uint32_t directive); -

    -
    PCRE2 NATIVE API MATCH CONTEXT FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API MATCH CONTEXT FUNCTIONS

    +

    pcre2_match_context *pcre2_match_context_create( pcre2_general_context *gcontext);
    @@ -228,9 +229,9 @@ document for an overview of all the PCRE2 documentation.
    int pcre2_set_depth_limit(pcre2_match_context *mcontext, uint32_t value); -

    -
    PCRE2 NATIVE API STRING EXTRACTION FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API STRING EXTRACTION FUNCTIONS

    +

    int pcre2_substring_copy_byname(pcre2_match_data *match_data, PCRE2_SPTR name, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen);
    @@ -272,19 +273,19 @@ document for an overview of all the PCRE2 documentation.

    int pcre2_substring_list_get(pcre2_match_data *match_data, -" PCRE2_UCHAR ***listptr, PCRE2_SIZE **lengthsptr); -

    -
    PCRE2 NATIVE API STRING SUBSTITUTION FUNCTION
    -

    + PCRE2_UCHAR ***listptr, PCRE2_SIZE **lengthsptr); +

    +

    PCRE2 NATIVE API STRING SUBSTITUTION FUNCTION

    +

    int pcre2_substitute(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, - pcre2_match_context *mcontext, PCRE2_SPTR replacementz, + pcre2_match_context *mcontext, PCRE2_SPTR replacement, PCRE2_SIZE rlength, PCRE2_UCHAR *outputbuffer, PCRE2_SIZE *outlengthptr); -

    -
    PCRE2 NATIVE API JIT FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API JIT FUNCTIONS

    +

    int pcre2_jit_compile(pcre2_code *code, uint32_t options);

    @@ -306,9 +307,9 @@ document for an overview of all the PCRE2 documentation.

    void pcre2_jit_stack_free(pcre2_jit_stack *jit_stack); -

    -
    PCRE2 NATIVE API SERIALIZATION FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API SERIALIZATION FUNCTIONS

    +

    int32_t pcre2_serialize_decode(pcre2_code **codes, int32_t number_of_codes, const uint8_t *bytes, pcre2_general_context *gcontext); @@ -323,9 +324,9 @@ document for an overview of all the PCRE2 documentation.

    int32_t pcre2_serialize_get_number_of_codes(const uint8_t *bytes); -

    -
    PCRE2 NATIVE API AUXILIARY FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API AUXILIARY FUNCTIONS

    +

    pcre2_code *pcre2_code_copy(const pcre2_code *code);

    @@ -353,9 +354,9 @@ document for an overview of all the PCRE2 documentation.

    int pcre2_config(uint32_t what, void *where); -

    -
    PCRE2 NATIVE API OBSOLETE FUNCTIONS
    -

    +

    +

    PCRE2 NATIVE API OBSOLETE FUNCTIONS

    +

    int pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t value);
    @@ -370,9 +371,9 @@ These functions became obsolete at release 10.30 and are retained only for backward compatibility. They should not be used in new code. The first is replaced by pcre2_set_depth_limit(); the second is no longer needed and has no effect (it always returns zero). -

    -
    PCRE2 EXPERIMENTAL PATTERN CONVERSION FUNCTIONS
    -

    +

    +

    PCRE2 EXPERIMENTAL PATTERN CONVERSION FUNCTIONS

    +

    pcre2_convert_context *pcre2_convert_context_create( pcre2_general_context *gcontext);
    @@ -406,9 +407,9 @@ experimental and may be changed in future releases. At present, "globs" and POSIX basic and extended patterns can be converted. Details are given in the pcre2convert documentation. -

    -
    PCRE2 8-BIT, 16-BIT, AND 32-BIT LIBRARIES
    -

    +

    +

    PCRE2 8-BIT, 16-BIT, AND 32-BIT LIBRARIES

    +

    There are three PCRE2 libraries, supporting 8-bit, 16-bit, and 32-bit code units, respectively. However, there is just one header file, pcre2.h. This contains the function prototypes and other definitions for all three @@ -431,14 +432,14 @@ The UCHAR types define unsigned code units of the appropriate widths. For example, PCRE2_UCHAR16 is usually defined as `uint16_t'. The SPTR types are pointers to constants of the equivalent UCHAR types, that is, they are pointers to vectors of unsigned code units. -

    -

    +

    +

    Character strings are passed to a PCRE2 library as sequences of unsigned integers in code units of the appropriate width. The length of a string may be given as a number of code units, or the string may be specified as zero-terminated. -

    -

    +

    +

    Many applications use only one code unit width. For their convenience, macros are defined whose names are the generic forms such as pcre2_compile() and PCRE2_SPTR. These macros use the value of the macro PCRE2_CODE_UNIT_WIDTH to @@ -446,53 +447,53 @@ generate the appropriate width-specific function and macro names. PCRE2_CODE_UNIT_WIDTH is not defined by default. An application must define it to be 8, 16, or 32 before including pcre2.h in order to make use of the generic names. -

    -

    +

    +

    Applications that use more than one code unit width can be linked with more than one PCRE2 library, but must define PCRE2_CODE_UNIT_WIDTH to be 0 before including pcre2.h, and then use the real function names. Any code that is to be included in an environment where the value of PCRE2_CODE_UNIT_WIDTH is unknown should also use the real function names. (Unfortunately, it is not possible in C code to save and restore the value of a macro.) -

    -

    +

    +

    If PCRE2_CODE_UNIT_WIDTH is not defined before including pcre2.h, a compiler error occurs. -

    -

    +

    +

    When using multiple libraries in an application, you must take care when processing any particular pattern to use only functions from a single library. For example, if you want to run a match using a pattern that was compiled with pcre2_compile_16(), you must do so with pcre2_match_16(), not pcre2_match_8() or pcre2_match_32(). -

    -

    +

    +

    In the function summaries above, and in the rest of this document and other PCRE2 documents, functions and data types are described using their generic names, without the _8, _16, or _32 suffix. -

    -
    PCRE2 API OVERVIEW
    -

    +

    +

    PCRE2 API OVERVIEW

    +

    PCRE2 has its own native API, which is described in this document. There are also some wrapper functions for the 8-bit library that correspond to the POSIX regular expression API, but they do not give access to all the functionality of PCRE2 and they are not thread-safe. They are described in the pcre2posix documentation. Both these APIs define a set of C function calls. -

    -

    +

    +

    The native API C data types, function prototypes, option values, and error codes are defined in the header file pcre2.h, which also contains definitions of PCRE2_MAJOR and PCRE2_MINOR, the major and minor release numbers for the library. Applications can use these to include support for different releases of PCRE2. -

    -

    +

    +

    In a Windows environment, if you want to statically link an application program against a non-dll PCRE2 library, you must define PCRE2_STATIC before including pcre2.h. -

    -

    +

    +

    The functions pcre2_compile() and pcre2_match() are used for compiling and matching regular expressions in a Perl-compatible manner. A sample program that demonstrates the simplest way of using them is provided in @@ -502,36 +503,36 @@ of this program is given in the documentation, and the pcre2sample documentation describes how to compile and run it. -

    -

    +

    +

    The compiling and matching functions recognize various options that are passed as bits in an options argument. There are also some more complicated parameters such as custom memory management functions and resource limits that are passed in "contexts" (which are just memory blocks, described below). Simple applications do not need to make use of contexts. -

    -

    +

    +

    Just-in-time (JIT) compiler support is an optional feature of PCRE2 that can be built in appropriate hardware environments. It greatly speeds up the matching performance of many patterns. Programs can request that it be used if available by calling pcre2_jit_compile() after a pattern has been successfully compiled by pcre2_compile(). This does nothing if JIT support is not available. -

    -

    +

    +

    More complicated programs might need to make use of the specialist functions pcre2_jit_stack_create(), pcre2_jit_stack_free(), and pcre2_jit_stack_assign() in order to control the JIT code's memory usage. -

    -

    +

    +

    JIT matching is automatically used by pcre2_match() if it is available, unless the PCRE2_NO_JIT option is set. There is also a direct interface for JIT matching, which gives improved performance at the expense of less sanity checking. The JIT-specific functions are discussed in the pcre2jit documentation. -

    -

    +

    +

    A second matching function, pcre2_dfa_match(), which is not Perl-compatible, is also provided. This uses a different algorithm for the matching. The alternative algorithm finds all possible matches (at a given @@ -541,8 +542,8 @@ substrings. A description of the two matching algorithms and their advantages and disadvantages is given in the pcre2matching documentation. There is no JIT support for pcre2_dfa_match(). -

    -

    +

    +

    In addition to the main compiling and matching functions, there are convenience functions for extracting captured substrings from a subject string that has been matched by pcre2_match(). They are: @@ -561,28 +562,28 @@ been matched by pcre2_match(). They are: provided, to free memory used for extracted strings. If either of these functions is called with a NULL argument, the function returns immediately without doing anything. -

    -

    +

    +

    The function pcre2_substitute() can be called to match a pattern and return a copy of the subject string with substitutions for parts that were matched. -

    -

    +

    +

    Functions whose names begin with pcre2_serialize_ are used for saving compiled patterns on disc or elsewhere, and reloading them later. -

    -

    +

    +

    Finally, there are functions for finding out information about a compiled pattern (pcre2_pattern_info()) and about the configuration with which -PCRE2 was built (pcre2_config()). -

    -

    +PCRE2 was built (pcre2_config()) and that it is using. +

    +

    Functions with names ending with _free() are used for freeing memory blocks of various sorts. In all cases, if one of these functions is called with a NULL argument, it does nothing. -

    -
    STRING LENGTHS AND OFFSETS
    -

    +

    +

    STRING LENGTHS AND OFFSETS

    +

    The PCRE2 API uses string lengths and offsets into strings of code units in several places. These values are always of type PCRE2_SIZE, which is an unsigned integer type, currently always defined as size_t. The largest @@ -591,9 +592,9 @@ as a special indicator for zero-terminated strings and unset offsets. Therefore, the longest string that can be handled is one less than this maximum. Note that string lengths are always given in code units. Only in the 8-bit library is such a length the same as the number of bytes in the string. -

    -
    NEWLINES
    -

    +

    +

    NEWLINES

    +

    PCRE2 supports five different conventions for indicating line breaks in strings: a single CR (carriage return) character, a single LF (linefeed) character, the two-character sequence CRLF, any of the three preceding, or any @@ -601,8 +602,8 @@ Unicode newline sequence. The Unicode newline sequences are the three just mentioned, plus the single characters VT (vertical tab, U+000B), FF (form feed, U+000C), NEL (next line, U+0085), LS (line separator, U+2028), and PS (paragraph separator, U+2029). -

    -

    +

    +

    Each of the first three conventions is used by at least one operating system as its standard newline sequence. When PCRE2 is built, a default can be specified. If it is not, the default is set to LF, which is the Unix standard. However, @@ -611,8 +612,8 @@ the newline convention can be changed by an application when calling the pattern itself; this overrides any other settings. See the pcre2pattern page for details of the special character sequences. -

    -

    +

    +

    In the PCRE2 documentation the word "newline" is used to mean "the character or pair of characters that indicate a line break". The choice of newline convention affects the handling of the dot, circumflex, and dollar @@ -621,28 +622,28 @@ recognized line ending sequence, the match position advancement for a non-anchored pattern. There is more detail about this in the section on pcre2_match() options below. -

    -

    +

    +

    The choice of newline convention does not affect the interpretation of the \n or \r escape sequences, nor does it affect what \R matches; this has its own separate convention. -

    -
    MULTITHREADING
    -

    +

    +

    MULTITHREADING

    +

    In a multithreaded application it is important to keep thread-specific data separate from data that can be shared between threads. The PCRE2 library code itself is thread-safe: it contains no static or global variables. The API is designed to be fairly simple for non-threaded applications while at the same time ensuring that multithreaded applications can use it. -

    -

    +

    +

    There are several different blocks of data that are used to pass information between the application and the PCRE2 libraries. -

    -
    +

    +

    The compiled pattern -
    -

    +

    +

    A pointer to the compiled form of a pattern is returned to the user when pcre2_compile() is successful. The data in the compiled pattern is fixed, and does not change when the pattern is matched. Therefore, it is thread-safe, @@ -653,8 +654,8 @@ just-in-time (JIT) optimization feature is being used, it needs separate memory stack areas for each thread. See the pcre2jit documentation for more details. -

    -

    +

    +

    In a more complicated situation, where patterns are compiled only when they are first needed, but are still shared between threads, pointers to compiled patterns must be protected from simultaneous writing by multiple threads. This @@ -671,8 +672,8 @@ atomic in your environment, you can use logic like this: Use pointer in pcre2_match()

  • Of course, testing for compilation errors should also be included in the code. -

    -

    +

    +

    The reason for checking the pointer a second time is as follows: Several threads may have acquired the shared lock and tested the pointer for being NULL, but only one of them will be given the write lock, with the rest kept @@ -681,8 +682,8 @@ After this thread releases the write lock, another thread will get it, and if it does not retest pointer for being NULL, will recompile the pattern and overwrite the pointer, creating a memory leak and possibly causing other issues. -

    -

    +

    +

    In an environment where writing to a pointer may not be atomic, the above logic is not sufficient. The thread that is doing the compiling may be descheduled after writing only part of the pointer, which could cause other threads to use @@ -709,11 +710,11 @@ thread must gain unique write access to the pointer before calling pcre2_jit_compile(). Alternatively, pcre2_code_copy() or pcre2_code_copy_with_tables() can be used to obtain a private copy of the compiled code before calling the JIT compiler. -

    -
    +

    +

    Context blocks -
    -

    +

    +

    The next main section below introduces the idea of "contexts" in which PCRE2 functions are called. A context is nothing more than a collection of parameters that control the way PCRE2 operates. Grouping a number of parameters together @@ -721,24 +722,24 @@ in a context is a convenient way of passing them to a PCRE2 function without using lots of arguments. The parameters that are stored in contexts are in some sense "advanced features" of the API. Many straightforward applications will not need to use contexts. -

    -

    +

    +

    In a multithreaded application, if the parameters in a context are values that are never changed, the same context can be used by all the threads. However, if any thread needs to change any value in a context, it must make its own thread-specific copy. -

    -
    +

    +

    Match blocks -
    -

    +

    +

    The matching functions need a block of memory for storing the results of a match. This includes details of what was matched, as well as additional information such as the name of a (*MARK) setting. Each thread must provide its own copy of this memory. -

    -
    PCRE2 CONTEXTS
    -

    +

    +

    PCRE2 CONTEXTS

    +

    Some PCRE2 functions have a lot of parameters, many of which are used only by specialist applications, for example, those that use custom memory management or non-standard character tables. To keep function argument lists at a @@ -747,15 +748,15 @@ parameters are passed to certain functions in a context instead of directly. A context is just a block of memory that holds the parameter values. Applications that do not need to adjust any of the context parameters can pass NULL when a context pointer is required. -

    -

    +

    +

    There are three different types of context: a general context that is relevant for several PCRE2 operations, a compile-time context, and a match-time context. -

    -
    +

    +

    The general context -
    -

    +

    +

    At present, this context just contains pointers to (and data for) external memory management functions that are called from several places in the PCRE2 library. The context is named `general' rather than specifically `memory' @@ -782,13 +783,13 @@ function may be NULL, in which case the system memory management functions there are no other fields in a general context, but in future there might be.) The private_malloc() function is used (if supplied) to obtain memory for storing the context, and all three values are saved as part of the context. -

    -

    +

    +

    Whenever PCRE2 creates a data block of any kind, the block contains a pointer to the free() function that matches the malloc() function that was used. When the time comes to free the block, this function is called. -

    -

    +

    +

    A general context can be copied by calling:

    @@ -804,11 +805,11 @@ The memory used for a general context should be freed by calling:
    If this function is passed a NULL argument, it returns immediately without doing anything. -

    -
    +

    +

    The compile context -
    -

    +

    +

    A compile context is required if you want to provide an external function for stack checking during compilation or to change the default values of any of the following compile-time parameters: @@ -824,8 +825,8 @@ following compile-time parameters: A compile context is also required if you are using custom memory management. If none of these apply, just pass NULL as the context argument of pcre2_compile(). -

    -

    +

    +

    A compile context is created, copied, and freed by the following functions:

    @@ -903,7 +904,7 @@ can hold, which is effectively unlimited.

    int pcre2_set_max_varlookbehind(pcre2_compile_contest *ccontext, -" uint32_t value); + uint32_t value);

    This sets a maximum length for the number of characters matched by a @@ -922,14 +923,14 @@ PCRE2_NEWLINE_LF (linefeed only), PCRE2_NEWLINE_CRLF (the two-character sequence CR followed by LF), PCRE2_NEWLINE_ANYCRLF (any of the above), PCRE2_NEWLINE_ANY (any Unicode newline sequence), or PCRE2_NEWLINE_NUL (the NUL character, that is a binary zero). -

    -

    +

    +

    A pattern can override the value set in the compile context by starting with a sequence such as (*CRLF). See the pcre2pattern page for details. -

    -

    +

    +

    When a pattern is compiled with the PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option, the newline convention affects the recognition of the end of internal comments starting with #. The value is saved with the compiled pattern for @@ -958,8 +959,8 @@ available during compilation. For a finer control, you can supply a function that is called whenever pcre2_compile() starts to compile a parenthesized part of a pattern. This function can check the actual stack size (or anything else that it wants to, of course). -

    -

    +

    +

    The first argument to the callout function gives the current depth of nesting, and the second is user data that is set up by the last argument of pcre2_set_compile_recursion_guard(). The callout function should return @@ -977,8 +978,8 @@ faster. By default, all available optimizations are enabled. However, in rare cases, one might wish to disable specific optimizations. For example, if it is known that some optimizations cannot benefit a certain regex, it might be desirable to disable them, in order to speed up compilation. -

    -

    +

    +

    The permitted values of directive are as follows:

       PCRE2_OPTIMIZATION_FULL
    @@ -1009,8 +1010,8 @@ PCRE2_DOTALL is set for all the .* items and PCRE2_MULTILINE is not set for any
     ^ items. Otherwise, the fact that any match must start either at the start of
     the subject or following a newline is remembered. Like other optimizations,
     this can cause callouts to be skipped.
    -

    -

    +

    +

    Dotstar anchor optimization is automatically disabled for .* if it is inside an atomic group or a capture group that is the subject of a backreference, or if the pattern contains (*PRUNE) or (*SKIP). @@ -1029,13 +1030,13 @@ Also, when callouts or (*MARK) items are in use, these "start-up" optimizations can cause them to be skipped if the pattern is never actually used. The start-up optimizations are in effect a pre-scan of the subject that takes place before the pattern is run. -

    -

    +

    +

    Disabling start-up optimizations ensures that in cases where the result is "no match", the callouts do occur, and that items such as (*COMMIT) and (*MARK) are considered at every possible starting position in the subject string. -

    -

    +

    +

    Disabling start-up optimizations may change the outcome of a matching operation. Consider the pattern

    @@ -1050,8 +1051,8 @@ match is run without start-up optimizations, the initial scan along the subject
     string does not happen. The first match attempt is run starting from "D" and
     when this fails, (*COMMIT) prevents any further matches being tried, so the
     overall result is "no match".
    -

    -

    +

    +

    Another start-up optimization makes use of a minimum length for a matching subject, which is recorded when possible. Consider the pattern

    @@ -1068,11 +1069,11 @@ where (*MARK:1) is encountered, but there is no "B", so the "last mark seen"
     that is returned is "1". In this case, the optimizations do not affect the
     overall match result, which is still "no match", but they do affect the
     auxiliary information that is returned.
    -

    -
    +

    +

    The match context -
    -

    +

    +

    A match context is required if you want to:

       Set up a callout function
    @@ -1084,8 +1085,8 @@ A match context is required if you want to:
     
    If none of these apply, just pass NULL as the context argument of pcre2_match(), pcre2_dfa_match(), or pcre2_jit_match(). -

    -

    +

    +

    A match context is created, copied, and freed by the following functions:

    @@ -1150,21 +1151,21 @@ advance in the subject string. The default value is PCRE2_UNSET. The PCRE2_ERROR_NOMATCH if a match with a starting point before or at the given offset is not found. The pcre2_substitute() function makes no more substitutions. -

    -

    +

    +

    For example, if the pattern /abc/ is matched against "123abc" with an offset limit less than 3, the result is PCRE2_ERROR_NOMATCH. A match can never be found if the startoffset argument of pcre2_match(), pcre2_dfa_match(), or pcre2_substitute() is greater than the offset limit set in the match context. -

    -

    +

    +

    When using this facility, you must set the PCRE2_USE_OFFSET_LIMIT option when calling pcre2_compile() so that when JIT is in use, different code can be compiled. If a match is started with a non-default match limit when PCRE2_USE_OFFSET_LIMIT is not set, an error is generated. -

    -

    +

    +

    The offset limit facility can be used to track progress when searching large subject strings or to limit the extent of global substitutions. See also the PCRE2_FIRSTLINE option, which requires a match to start before or at the first @@ -1189,8 +1190,8 @@ documentation for more details). If the limit is reached, the negative error code PCRE2_ERROR_HEAPLIMIT is returned. The default limit can be set when PCRE2 is built; if it is not, the default is set very large and is essentially unlimited. -

    -

    +

    +

    A value for the heap limit may also be supplied by an item at the start of a pattern of the form

    @@ -1199,15 +1200,15 @@ pattern of the form
     where ddd is a decimal number. However, such a setting is ignored unless ddd is
     less than the limit set by the caller of pcre2_match() or, if no such
     limit is set, less than the default.
    -

    -

    +

    +

    The pcre2_match() function always needs some heap memory, so setting a value of zero guarantees a "heap limit exceeded" error. Details of how pcre2_match() uses the heap are given in the pcre2perform documentation. -

    -

    +

    +

    For pcre2_dfa_match(), a vector on the system stack is used when processing pattern recursions, lookarounds, or atomic groups, and only if this is not big enough is heap memory used. In this case, setting a value of zero @@ -1222,8 +1223,8 @@ The match_limit parameter provides a means of preventing PCRE2 from using up too many computing resources when processing patterns that are not going to match, but which have a very large number of possibilities in their search trees. The classic example is a pattern that uses nested unlimited repeats. -

    -

    +

    +

    There is an internal counter in pcre2_match() that is incremented each time round its main matching loop. If this value reaches the match limit, pcre2_match() returns the negative value PCRE2_ERROR_MATCHLIMIT. This has @@ -1231,16 +1232,16 @@ the effect of limiting the amount of backtracking that can take place. For patterns that are not anchored, the count restarts from zero for each position in the subject string. This limit also applies to pcre2_dfa_match(), though the counting is done in a different way. -

    -

    +

    +

    When pcre2_match() is called with a pattern that was successfully processed by pcre2_jit_compile(), the way in which matching is executed is entirely different. However, there is still the possibility of runaway matching that goes on for a very long time, and so the match_limit value is also used in this case (but in a different way) to limit how long the matching can continue. -

    -

    +

    +

    The default value for the limit can be set when PCRE2 is built; the default is 10 million, which handles all but the most extreme cases. A value for the match limit may also be supplied by an item at the start of a pattern of the form @@ -1264,8 +1265,8 @@ because the size of each memory frame depends on the number of capturing parentheses, the actual memory limit varies from pattern to pattern. This limit was more useful in versions before 10.30, where function recursion was used for backtracking. -

    -

    +

    +

    The depth limit is not relevant, and is ignored, when matching is done using JIT compiled code. However, it is supported by pcre2_dfa_match(), which uses it to limit the depth of nested internal recursive function calls that @@ -1275,8 +1276,8 @@ in versions before 10.32, when stack memory was used for local workspace vectors for recursive function calls. From version 10.32, only local variables are allocated on the stack and as each call uses only a few hundred bytes, even a small stack can support quite a lot of recursion. -

    -

    +

    +

    If the depth of internal recursive function calls is great enough, local workspace vectors are allocated on the heap from version 10.32 onwards, so the depth limit also indirectly limits the amount of heap memory that is used. A @@ -1284,8 +1285,8 @@ recursive pattern such as /(.(?2))((?1)|)/, when matched to a very long string using pcre2_dfa_match(), can use a great deal of memory. However, it is probably better to limit heap usage directly by calling pcre2_set_heap_limit(). -

    -

    +

    +

    The default value for the depth limit can be set when PCRE2 is built; if it is not, the default is set to the same value as the default for the match limit. If the limit is exceeded, pcre2_match() or pcre2_dfa_match() @@ -1297,19 +1298,19 @@ supplied by an item at the start of a pattern of the form where ddd is a decimal number. However, such a setting is ignored unless ddd is less than the limit set by the caller of pcre2_match() or pcre2_dfa_match() or, if no such limit is set, less than the default. -

    -
    CHECKING BUILD-TIME OPTIONS
    -

    +

    +

    CHECKING BUILD-TIME OPTIONS

    +

    int pcre2_config(uint32_t what, void *where); -

    -

    +

    +

    The function pcre2_config() makes it possible for a PCRE2 client to find the value of certain configuration parameters and to discover which optional features have been compiled into the PCRE2 library. The pcre2build documentation has more details about these features. -

    -

    +

    +

    The first argument for pcre2_config() specifies which information is required. The second argument is a pointer to memory into which the information is placed. If NULL is passed, the function returns the amount of memory that is @@ -1317,8 +1318,8 @@ needed for the requested information. For calls that return numerical values, the value is in bytes; when requesting these values, where should point to appropriately aligned memory. For calls that return strings, the required length is given in code units, not counting the terminating zero. -

    -

    +

    +

    When requesting information, the returned value from pcre2_config() is non-negative on success, or the negative error code PCRE2_ERROR_BADOPTION if the value in the first argument is not recognized. The following information is @@ -1344,6 +1345,13 @@ The output is a uint32_t integer that gives the default limit for the depth of nested backtracking in pcre2_match() or the depth of nested recursions, lookarounds, and atomic groups in pcre2_dfa_match(). Further details are given with pcre2_set_depth_limit() above. +

    +  PCRE2_CONFIG_EFFECTIVE_LINKSIZE
    +
    +The output is a uint32_t integer that contains the number of bytes the library +uses for internal linkage in compiled regular expressions. Its value is derived +from the value that was provided at build time and that is described below by +PCRE2_CONFIG_LINKSIZE.
       PCRE2_CONFIG_HEAPLIMIT
     
    @@ -1366,7 +1374,7 @@ documentation for more details.
       PCRE2_CONFIG_JITTARGET
     
    -The where argument should point to a buffer that is at least 48 code +The where argument should point to a buffer that is at least 64 code units long. (The exact length required can be found by calling pcre2_config() with where set to NULL.) The buffer is filled with a string that contains the name of the architecture for which the JIT compiler is @@ -1377,15 +1385,17 @@ for the terminating zero.
       PCRE2_CONFIG_LINKSIZE
     
    -The output is a uint32_t integer that contains the number of bytes used for -internal linkage in compiled regular expressions. When PCRE2 is configured, the -value can be set to 2, 3, or 4, with the default being 2. This is the value -that is returned by pcre2_config(). However, when the 16-bit library is -compiled, a value of 3 is rounded up to 4, and when the 32-bit library is -compiled, internal linkages always use 4 bytes, so the configured value is not -relevant. -

    -

    +The output is a uint32_t integer that contains the number of bytes the library +was instructed to use for internal linkage in compiled regular expressions. +When PCRE2 is configured, the value can be set to 2, 3, or 4, with the default +being 2 for most libraries. +

    +

    +The actual number of bytes used depends on the size of the code units that the +library supports and can be higher. See PCRE2_CONFIG_EFFECTIVE_LINKSIZE above +for details. +

    +

    The default value of 2 for the 8-bit and 16-bit libraries is sufficient for all but the most massive patterns, since it allows the size of the compiled pattern to be up to 65535 code units. Larger values allow larger regular expressions to @@ -1461,9 +1471,9 @@ units long. (The exact length required can be found by calling the PCRE2 version string, zero-terminated. The number of code units used is returned. This is the length of the string plus one unit for the terminating zero. -

    -
    COMPILING A PATTERN
    -

    +

    +

    COMPILING A PATTERN

    +

    pcre2_code *pcre2_compile(PCRE2_SPTR pattern, PCRE2_SIZE length, uint32_t options, int *errorcode, PCRE2_SIZE *erroroffset, pcre2_compile_context *ccontext); @@ -1476,8 +1486,8 @@ zero.

    pcre2_code *pcre2_code_copy_with_tables(const pcre2_code *code); -

    -

    +

    +

    The pcre2_compile() function compiles a pattern into an internal form. The pattern is defined by a pointer to a string of code units and a length in code units. If the pattern is zero-terminated, the length can be specified as @@ -1485,16 +1495,16 @@ PCRE2_ZERO_TERMINATED. A NULL pattern pointer with a length of zero is treated as an empty string (NULL with a non-zero length causes an error return). The function returns a pointer to a block of memory that contains the compiled pattern and related data, or NULL if an error occurred. -

    -

    +

    +

    If the compile context argument ccontext is NULL, memory for the compiled pattern is obtained by calling malloc(). Otherwise, it is obtained from the same memory function that was used for the compile context. The caller must free the memory by calling pcre2_code_free() when it is no longer needed. If pcre2_code_free() is called with a NULL argument, it returns immediately, without doing anything. -

    -

    +

    +

    The function pcre2_code_copy() makes a copy of the compiled code in new memory, using the same memory allocator as was used for the original. However, if the code has been processed by the JIT compiler (see @@ -1503,8 +1513,8 @@ the JIT information cannot be copied (because it is position-dependent). The new copy can initially be used only for non-JIT matching, though it can be passed to pcre2_jit_compile() if required. If pcre2_code_copy() is called with a NULL argument, it returns NULL. -

    -

    +

    +

    The pcre2_code_copy() function provides a way for individual threads in a multithreaded application to acquire a private copy of shared compiled code. However, it does not make a copy of the character tables used by the compiled @@ -1520,8 +1530,8 @@ the new tables. The memory for the new tables is automatically freed when pcre2_code_free() is called for the new copy of the compiled code. If pcre2_code_copy_with_tables() is called with a NULL argument, it returns NULL. -

    -

    +

    +

    NOTE: When one of the matching functions is called, pointers to the compiled pattern and the subject string are set in the match data block so that they can be referenced by the substring extraction functions after a successful match. @@ -1532,8 +1542,8 @@ have taken place, unless, in the case of the subject string, you have used the PCRE2_COPY_MATCHED_SUBJECT option, which is described in the section entitled "Option bits for pcre2_match()" below. -

    -

    +

    +

    The options argument for pcre2_compile() contains various bit settings that affect the compilation. It should be zero if none of them are required. The available options are described below. Some of them (in @@ -1542,27 +1552,27 @@ also be set and unset from within the pattern (see the detailed description in the pcre2pattern documentation). -

    -

    +

    +

    For those options that can be different in different parts of the pattern, the contents of the options argument specifies their settings at the start of compilation. The PCRE2_ANCHORED, PCRE2_ENDANCHORED, and PCRE2_NO_UTF_CHECK options can be set at the time of matching as well as at compile time. -

    -

    +

    +

    Some additional options and less frequently required compile-time parameters (for example, the newline setting) can be provided in a compile context (as described above). -

    -

    +

    +

    If errorcode or erroroffset is NULL, pcre2_compile() returns NULL immediately. Otherwise, the variables to which these point are set to an error code and an offset (number of code units) within the pattern, respectively, when pcre2_compile() returns NULL because a compilation error has occurred. -

    -

    +

    +

    There are over 100 positive error codes that pcre2_compile() may return if it finds an error in the pattern. There are also some negative error codes that are used for invalid UTF strings when validity checking is in force. These @@ -1578,8 +1588,8 @@ should be self-explanatory. Macro names starting with PCRE2_ERROR_ are defined for both positive and negative error codes in pcre2.h. When compilation is successful errorcode is set to a value that returns the message "no error" if passed to pcre2_get_error_message(). -

    -

    +

    +

    The value returned in erroroffset is an indication of where in the pattern an error occurred. When there is no error, zero is returned. A non-zero value is not necessarily the furthest point in the pattern that was read. For @@ -1587,14 +1597,14 @@ example, after the error "lookbehind assertion is not fixed length", the error offset points to the start of the failing assertion. For an invalid UTF-8 or UTF-16 string, the offset is that of the first code unit of the failing character. -

    -

    +

    +

    Some errors are not detected until the whole pattern has been scanned; in these cases, the offset passed back is the length of the pattern. Note that the offset is in code units, not characters, even in a UTF mode. It may sometimes point into the middle of a UTF-8 or UTF-16 character. -

    -

    +

    +

    This code fragment shows a typical straightforward call to pcre2_compile():

    @@ -1609,12 +1619,12 @@ This code fragment shows a typical straightforward call to
         &erroffset,             /* for error offset */
         NULL);                  /* no compile context */
     
    -
    -

    -
    +
    +

    +

    Main compile options -
    -

    +

    +

    The following names for option bits are defined in the pcre2.h header file:

    @@ -1637,25 +1647,24 @@ therefore contains no characters and so can never match.
     
    This option request alternative handling of three escape sequences, which makes PCRE2's behaviour more like ECMAscript (aka JavaScript). When it is set: -

    -

    +

    +

    (1) \U matches an upper case "U" character; by default \U causes a compile time error (Perl uses \U to upper case subsequent characters). -

    -

    +

    +

    (2) \u matches a lower case "u" character unless it is followed by four hexadecimal digits, in which case the hexadecimal number defines the code point to match. By default, \u causes a compile time error (Perl uses it to upper case the following character). -

    -

    +

    +

    (3) \x matches a lower case "x" character unless it is followed by two hexadecimal digits, in which case the hexadecimal number defines the code point to match. By default, as in Perl, a hexadecimal number is always expected after -\x, but it may have zero, one, or two digits (so, for example, \xz matches a -binary zero character followed by z). -

    -

    +\x, but it may have one or two digits. +

    +

    ECMAscript 6 added additional functionality to \u. This can be accessed using the PCRE2_EXTRA_ALT_BSUX extra option (see "Extra compile options" below). @@ -1692,7 +1701,7 @@ option is set, normal backslash processing is applied to verb names and only an unescaped closing parenthesis terminates the name. A closing parenthesis can be included in a name either as \) or between \Q and \E. If the PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option is set with PCRE2_ALT_VERBNAMES, unescaped -whitespace in verb names is skipped and #-comments are recognized, exactly as +white space in verb names is skipped and #-comments are recognized, exactly as in the rest of the pattern.

       PCRE2_AUTO_CALLOUT
    @@ -1712,26 +1721,26 @@ changed within a pattern by a (?i) option setting. If either PCRE2_UTF or
     PCRE2_UCP is set, Unicode properties are used for all characters with more than
     one other case, and for all characters whose code points are greater than
     U+007F.
    -

    -

    +

    +

    Note that there are two ASCII characters, K and S, that, in addition to their lower case ASCII equivalents, are case-equivalent with U+212A (Kelvin sign) and U+017F (long S) respectively. If you do not want this case equivalence, you can suppress it by setting PCRE2_EXTRA_CASELESS_RESTRICT. -

    -

    +

    +

    One language family, Turkish and Azeri, has its own case-insensitivity rules, which can be selected by setting PCRE2_EXTRA_TURKISH_CASING. This alters the behaviour of the 'i', 'I', U+0130 (capital I with dot above), and U+0131 (small dotless i) characters. -

    -

    +

    +

    For lower valued characters with only one other case, a lookup table is used for speed. When neither PCRE2_UTF nor PCRE2_UCP is set, a lookup table is used for all code points less than 256, and higher code points (available only in 16-bit or 32-bit mode) are treated as not having another case. -

    -

    +

    +

    From release 10.45 PCRE2_CASELESS also affects what some of the letter-related Unicode property escapes (\p and \P) match. The properties Lu (upper case letter), Ll (lower case letter), and Lt (title case letter) are all treated as @@ -1783,8 +1792,8 @@ If matched against "abc" with PCRE2_ENDANCHORED set, the first matches "c" whereas the second matches "bc". The effect of PCRE2_ENDANCHORED can also be achieved by appropriate constructs in the pattern itself, which is the only way to do it in Perl. -

    -

    +

    +

    For DFA matching with pcre2_dfa_match(), PCRE2_ENDANCHORED applies only to the first (that is, the longest) matched string. Other parallel matches, which are necessarily substrings of the first one, must obviously end before @@ -1800,8 +1809,8 @@ as {1,3}. Ignorable white space is permitted between an item and a following quantifier and between a quantifier and a following + that indicates possessiveness. PCRE2_EXTENDED is equivalent to Perl's /x option, and it can be changed within a pattern by a (?x) option setting. -

    -

    +

    +

    When PCRE2 is compiled without Unicode support, PCRE2_EXTENDED recognizes as white space only those characters with code points less than 256 that are flagged as white space in its low-character table. The table is normally @@ -1811,8 +1820,8 @@ which uses the isspace() function to identify space characters. In most ASCII environments, the relevant characters are those with code points 0x0009 (tab), 0x000A (linefeed), 0x000B (vertical tab), 0x000C (formfeed), 0x000D (carriage return), and 0x0020 (space). -

    -

    +

    +

    When PCRE2 is compiled with Unicode support, in addition to these characters, five more Unicode "Pattern White Space" characters are recognized by PCRE2_EXTENDED. These are U+0085 (next line), U+200E (left-to-right mark), @@ -1820,16 +1829,16 @@ U+200F (right-to-left mark), U+2028 (line separator), and U+2029 (paragraph separator). This set of characters is the same as recognized by Perl's /x option. Note that the horizontal and vertical space characters that are matched by the \h and \v escapes in patterns are a much bigger set. -

    -

    +

    +

    As well as ignoring most white space, PCRE2_EXTENDED also causes characters between an unescaped # outside a character class and the next newline, inclusive, to be ignored, which makes it possible to include comments inside complicated patterns. Note that the end of this type of comment is a literal newline sequence in the pattern; escape sequences that happen to represent a newline do not count. -

    -

    +

    +

    Which characters are interpreted as newlines can be specified by a setting in the compile context that is passed to pcre2_compile() or by a special sequence at the start of the pattern, as described in the section entitled @@ -1904,8 +1913,8 @@ matches only at the start of the string, and the "end of line" metacharacter (except when PCRE2_DOLLAR_ENDONLY is set). Note, however, that unless PCRE2_DOTALL is set, the "any character" metacharacter (.) does not match at a newline. This behaviour (for ^, $, and dot) is the same as Perl. -

    -

    +

    +

    When PCRE2_MULTILINE it is set, the "start of line" and "end of line" constructs match immediately following or immediately before internal newlines in the subject string, respectively, as well as at the very start and end. This @@ -1962,8 +1971,8 @@ use, auto-possessification means that some callouts are never taken. You can set this option if you want the matching functions to do a full unoptimized search and run all the callouts, but it is mainly provided for testing purposes. -

    -

    +

    +

    If a compile context is available, it is recommended to use pcre2_set_optimize() with the directive PCRE2_AUTO_POSSESS_OFF rather than the compile option PCRE2_NO_AUTO_POSSESS. Note that PCRE2_NO_AUTO_POSSESS @@ -1990,18 +1999,19 @@ instead.)

    This is an option whose main effect is at matching time. It does not change what pcre2_compile() generates, but it does affect the output of the JIT -compiler. Setting this option is equivalent to calling pcre2_set_optimize() -with the directive parameter set to PCRE2_START_OPTIMIZE_OFF. -

    -

    +compiler. Setting this option is equivalent to calling +pcre2_set_optimize() with the directive parameter set to +PCRE2_START_OPTIMIZE_OFF. +

    +

    There are a number of optimizations that may occur at the start of a match, in order to speed up the process. For example, if it is known that an unanchored match must start with a specific code unit value, the matching code searches the subject for that value, and fails immediately if it cannot find it, without actually running the main matching function. The start-up optimizations are in effect a pre-scan of the subject that takes place before the pattern is run. -

    -

    +

    +

    Disabling the start-up optimizations may cause performance to suffer. However, this may be desirable for patterns which contain callouts or items such as (*COMMIT) and (*MARK). See the above description of PCRE2_START_OPTIMIZE_OFF @@ -2019,19 +2029,19 @@ in the pcre2unicode document. If an invalid UTF sequence is found, pcre2_compile() returns a negative error code. -

    -

    +

    +

    If you know that your pattern is a valid UTF string, and you want to skip this check for performance reasons, you can set the PCRE2_NO_UTF_CHECK option. When it is set, the effect of passing an invalid UTF string as a pattern is undefined. It may cause your program to crash or loop. -

    -

    +

    +

    Note that this option can also be passed to pcre2_match() and pcre2_dfa_match(), to suppress UTF validity checking of the subject string. -

    -

    +

    +

    Note also that setting PCRE2_NO_UTF_CHECK at compile time does not disable the error that is given if an escape sequence for an invalid Unicode code point is encountered in the pattern. In particular, the so-called "surrogate" code @@ -2054,19 +2064,19 @@ given in the section on in the pcre2pattern page. -

    -

    +

    +

    The second effect of PCRE2_UCP is to force the use of Unicode properties for upper/lower casing operations, even when PCRE2_UTF is not set. This makes it possible to process strings in the 16-bit UCS-2 code. This option is available only if PCRE2 has been compiled with Unicode support (which is the default). -

    -

    +

    +

    The PCRE2_EXTRA_CASELESS_RESTRICT option (see above) restricts caseless matching such that ASCII characters match only ASCII characters and non-ASCII -characters match only non-ASCII characters. The PCRE2_EXTRA_TURKISH_CASING option -(see above) alters the matching of the 'i' characters to follow their behaviour -in Turkish and Azeri languages. For further details on +characters match only non-ASCII characters. The PCRE2_EXTRA_TURKISH_CASING +option (see above) alters the matching of the 'i' characters to follow their +behaviour in Turkish and Azeri languages. For further details on PCRE2_EXTRA_CASELESS_RESTRICT and PCRE2_EXTRA_TURKISH_CASING, see the pcre2unicode page. @@ -2098,11 +2108,11 @@ the use of this option provokes an error. Details of how PCRE2_UTF changes the behaviour of PCRE2 are given in the pcre2unicode page. In particular, note that it changes the way PCRE2_CASELESS works. -

    -
    +

    +

    Extra compile options -
    -

    +

    +

    The option bits that can be set in a compile context by calling the pcre2_set_compile_extra_options() function are as follows:

    @@ -2122,16 +2132,16 @@ code points with values in the range 0x10000 to 0x10ffff. The surrogates cannot
     therefore be represented in UTF-16. They can be represented in UTF-8 and
     UTF-32, but are defined as invalid code points, and cause errors if encountered
     in a UTF-8 or UTF-32 string that is being checked for validity by PCRE2.
    -

    -

    +

    +

    These values also cause errors if encountered in escape sequences such as \x{d912} within a pattern. However, it seems that some applications, when using PCRE2 to check for unwanted characters in UTF-8 strings, explicitly test for the surrogates using escape sequences. The PCRE2_NO_UTF_CHECK option does not disable the error that occurs, because it applies only to the testing of input strings for UTF validity. -

    -

    +

    +

    If the extra option PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is set, surrogate code point values in UTF-8 and UTF-32 patterns no longer provoke errors and are incorporated in the compiled pattern. However, they can only match subject @@ -2185,8 +2195,8 @@ such items: for example, \j is treated as a literal "j", and non-hexadecimal digits in \x{} are just ignored, though warnings are given in both cases if Perl's warning switch is enabled. However, a malformed octal number after \o{ always causes an error in Perl. -

    -

    +

    +

    If the PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL extra option is passed to pcre2_compile(), all unrecognized or malformed escape sequences are treated as single-character escapes. For example, \j is a literal "j" and @@ -2262,9 +2272,9 @@ alphabet used by Turkish and Azeri languages. The option can be changed within a pattern by the (*TURKISH_CASING) start-of-pattern setting. Either the UTF or UCP options must be set. In the 8-bit library, UTF must be set. This option cannot be combined with PCRE2_EXTRA_CASELESS_RESTRICT. -

    -
    JUST-IN-TIME (JIT) COMPILATION
    -

    +

    +

    JUST-IN-TIME (JIT) COMPILATION

    +

    int pcre2_jit_compile(pcre2_code *code, uint32_t options);

    @@ -2286,37 +2296,37 @@ cannot be combined with PCRE2_EXTRA_CASELESS_RESTRICT.

    void pcre2_jit_stack_free(pcre2_jit_stack *jit_stack); -

    -

    +

    +

    These functions provide support for JIT compilation, which, if the just-in-time compiler is available, further processes a compiled pattern into machine code that executes much faster than the pcre2_match() interpretive matching function. Full details are given in the pcre2jit documentation. -

    -

    +

    +

    JIT compilation is a heavyweight optimization. It can take some time for patterns to be analyzed, and for one-off matches and simple patterns the benefit of faster execution might be offset by a much slower compilation time. Most (but not all) patterns can be optimized by the JIT compiler. -

    -
    LOCALE SUPPORT
    -

    +

    +

    LOCALE SUPPORT

    +

    const uint8_t *pcre2_maketables(pcre2_general_context *gcontext);

    void pcre2_maketables_free(pcre2_general_context *gcontext, const uint8_t *tables); -

    -

    +

    +

    PCRE2 handles caseless matching, and determines whether characters are letters, digits, or whatever, by reference to a set of tables, indexed by character code point. However, this applies only to characters whose code points are less than 256. By default, higher-valued code points never match escapes such as \w or \d. -

    -

    +

    +

    When PCRE2 is built with Unicode support (the default), certain Unicode character properties can be tested with \p and \P, or, alternatively, the PCRE2_UCP option can be set when a pattern is compiled; this causes \w and @@ -2325,34 +2335,34 @@ PCRE2_UCP also causes upper/lower casing operations on characters with code points greater than 127 to use Unicode properties. These effects apply even when PCRE2_UTF is not set. There are, however, some PCRE2_EXTRA options (see above) that can be used to modify or suppress them. -

    -

    +

    +

    The use of locales with Unicode is discouraged. If you are handling characters with code points greater than 127, you should either use Unicode support, or use locales, but not try to mix the two. -

    -

    +

    +

    PCRE2 contains a built-in set of character tables that are used by default. These are sufficient for many applications. Normally, the internal tables recognize only ASCII characters. However, when PCRE2 is built, it is possible to cause the internal tables to be rebuilt in the default "C" locale of the local system, which may cause them to be different. -

    -

    +

    +

    The built-in tables can be overridden by tables supplied by the application that calls PCRE2. These may be created in a different locale from the default. As more and more applications change to using Unicode, the need for this locale support is expected to die away. -

    -

    +

    +

    External tables are built by calling the pcre2_maketables() function, in the relevant locale. The only argument to this function is a general context, which can be used to pass a custom memory allocator. If the argument is NULL, the system malloc() is used. The result can be passed to pcre2_compile() as often as necessary, by creating a compile context and calling pcre2_set_character_tables() to set the tables pointer therein. -

    -

    +

    +

    For example, to build and use tables that are appropriate for the French locale (where accented characters with values greater than 127 are treated as letters), the following code could be used: @@ -2365,25 +2375,25 @@ letters), the following code could be used:

    The locale name "fr_FR" is used on Linux and other Unix-like systems; if you are using Windows, the name for the French locale is "french". -

    -

    +

    +

    The pointer that is passed (via the compile context) to pcre2_compile() is saved with the compiled pattern, and the same tables are used by the matching functions. Thus, for any single pattern, compilation and matching both happen in the same locale, but different patterns can be processed in different locales. -

    -

    +

    +

    It is the caller's responsibility to ensure that the memory containing the tables remains available while they are still in use. When they are no longer needed, you can discard them using pcre2_maketables_free(), which should pass as its first parameter the same global context that was used to create the tables. -

    -
    +

    +

    Saving locale tables -
    -

    +

    +

    The tables described above are just a sequence of binary bytes, which makes them independent of hardware characteristics such as endianness or whether the processor is 32-bit or 64-bit. A copy of the result of pcre2_maketables() @@ -2396,12 +2406,12 @@ the PCRE2 build system, can be used stand-alone to create a file that contains a set of binary tables. See the pcre2build documentation for details. -

    -
    INFORMATION ABOUT A COMPILED PATTERN
    -

    +

    +

    INFORMATION ABOUT A COMPILED PATTERN

    +

    int pcre2_pattern_info(const pcre2 *code, uint32_t what, void *where); -

    -

    +

    +

    The pcre2_pattern_info() function returns general information about a compiled pattern. For information about callouts, see the next section. @@ -2443,15 +2453,15 @@ the compile options as modified by any top-level (*XXX) option settings such as (*UTF) at the start of the pattern itself. PCRE2_INFO_EXTRAOPTIONS returns the extra options that were set in the compile context by calling the pcre2_set_compile_extra_options() function. -

    -

    +

    +

    For example, if the pattern /(*UTF)abc/ is compiled with the PCRE2_EXTENDED option, the result for PCRE2_INFO_ALLOPTIONS is PCRE2_EXTENDED and PCRE2_UTF. Option settings such as (?i) that can change within a pattern do not affect the result of PCRE2_INFO_ALLOPTIONS, even if they appear right at the start of the pattern. (This was different in some earlier releases.) -

    -

    +

    +

    A pattern compiled without PCRE2_ANCHORED is automatically anchored by PCRE2 if the first significant item in every top-level branch is one of the following:

    @@ -2621,8 +2631,8 @@ integer. The simple assertions \b and \B require a one-character lookbehind
     and cause PCRE2_INFO_MAXLOOKBEHIND to return 1 in the absence of anything
     longer. \A also registers a one-character lookbehind, though it does not
     actually inspect the previous character.
    -

    -

    +

    +

    Note that this information is useful for multi-segment matching only if the pattern contains no nested lookbehinds. For example, the pattern (?<=a(?<=ba)c) returns a maximum lookbehind of 2, but when it is processed, the @@ -2656,14 +2666,14 @@ converting the name to a number in order to access the correct pointers in the output vector (described with pcre2_match() below). To do the conversion, you need to use the name-to-number map, which is described by these three values. -

    -

    +

    +

    The map consists of a number of fixed-size entries. PCRE2_INFO_NAMECOUNT gives the number of entries, and PCRE2_INFO_NAMEENTRYSIZE gives the size of each entry in code units; both of these return a uint32_t value. The entry size depends on the length of the longest name. -

    -

    +

    +

    PCRE2_INFO_NAMETABLE returns a pointer to the first entry of the table. This is a PCRE2_SPTR pointer to a block of code units. In the 8-bit library, the first two bytes of each entry are the number of the capturing parenthesis, most @@ -2672,8 +2682,8 @@ code units, the first of which contains the parenthesis number. In the 32-bit library, the pointer points to 32-bit code units, the first of which contains the parenthesis number. The rest of the entry is the corresponding name, zero terminated. -

    -

    +

    +

    The names are in alphabetical order. If (?| is used to create multiple capture groups with the same number, as described in the section on duplicate group numbers @@ -2681,15 +2691,15 @@ in the pcre2pattern page, the groups may be given the same name, but there is only one entry in the table. Different names for groups of the same number are not permitted. -

    -

    +

    +

    Duplicate names for capture groups with different numbers are permitted, but only if PCRE2_DUPNAMES is set. They appear in the table in the order in which they were found in the pattern. In the absence of (?| this is the order of increasing number; when (?| is used this is not necessarily the case because later capture groups may have lower numbers. -

    -

    +

    +

    As a simple example of the name/number table, consider the following pattern after compilation by the 8-bit library (assume PCRE2_EXTENDED is set, so white space - including newlines - is ignored): @@ -2733,9 +2743,9 @@ memory in which to place the compiled pattern may be slightly larger than the value returned by this option, because there are cases where the code that calculates the size has to over-estimate. Processing a pattern with the JIT compiler does not alter the value returned by this option. -

    -
    INFORMATION ABOUT A PATTERN'S CALLOUTS
    -

    +

    +

    INFORMATION ABOUT A PATTERN'S CALLOUTS

    +

    int pcre2_callout_enumerate(const pcre2_code *code, int (*callback)(pcre2_callout_enumerate_block *, void *), void *user_data); @@ -2752,9 +2762,9 @@ a pointer to a callout enumeration block, and its second argument is the contents of the callout enumeration block are described in the pcre2callout documentation, which also gives further details about callouts. -

    -
    SERIALIZATION AND PRECOMPILING
    -

    +

    +

    SERIALIZATION AND PRECOMPILING

    +

    It is possible to save compiled patterns on disc or elsewhere, and reload them later, subject to a number of restrictions. The host on which the patterns are reloaded must be running the same version of PCRE2, with the same code unit @@ -2766,9 +2776,9 @@ converting to and from the serialized form. They are described in the pcre2serialize documentation. Note that PCRE2 serialization does not convert compiled patterns to an abstract format like Java or .NET serialization. -

    -
    THE MATCH DATA BLOCK
    -

    +

    +

    THE MATCH DATA BLOCK

    +

    pcre2_match_data *pcre2_match_data_create(uint32_t ovecsize, pcre2_general_context *gcontext);
    @@ -2778,46 +2788,46 @@ to an abstract format like Java or .NET serialization.

    void pcre2_match_data_free(pcre2_match_data *match_data); -

    -

    +

    +

    Information about a successful or unsuccessful match is placed in a match data block, which is an opaque structure that is accessed by function calls. In particular, the match data block contains a vector of offsets into the subject string that define the matched parts of the subject. This is known as the ovector. -

    -

    +

    +

    Before calling pcre2_match(), pcre2_dfa_match(), or pcre2_jit_match() you must create a match data block by calling one of the creation functions above. For pcre2_match_data_create(), the first argument is the number of pairs of offsets in the ovector. -

    -

    +

    +

    When using pcre2_match(), one pair of offsets is required to identify the string that matched the whole pattern, with an additional pair for each captured substring. For example, a value of 4 creates enough space to record the matched portion of the subject plus three captured substrings. -

    -

    +

    +

    When using pcre2_dfa_match() there may be multiple matched substrings of different lengths at the same point in the subject. The ovector should be made large enough to hold as many as are expected. -

    -

    +

    +

    A minimum of at least 1 pair is imposed by pcre2_match_data_create(), so it is always possible to return the overall matched string in the case of pcre2_match() or the longest match in the case of pcre2_dfa_match(). The maximum number of pairs is 65535; if the first argument of pcre2_match_data_create() is greater than this, 65535 is used. -

    -

    +

    +

    The second argument of pcre2_match_data_create() is a pointer to a general context, which can specify custom memory management for obtaining the memory for the match data block. If you are not using custom memory management, pass NULL, which causes malloc() to be used. -

    -

    +

    +

    For pcre2_match_data_create_from_pattern(), the first argument is a pointer to a compiled pattern. The ovector is created to be exactly the right size to hold all the substrings a pattern might capture when matched using @@ -2825,8 +2835,8 @@ size to hold all the substrings a pattern might capture when matched using pcre2_dfa_match(). The second argument is again a pointer to a general context, but in this case if NULL is passed, the memory is obtained using the same allocator that was used for the compiled pattern (custom or default). -

    -

    +

    +

    A match data block can be used many times, with the same or different compiled patterns. You can extract information from a match data block after a match operation has finished, using functions that are described in the sections on @@ -2834,14 +2844,14 @@ operation has finished, using functions that are described in the sections on and other match data below. -

    -

    +

    +

    When a call of pcre2_match() fails, valid data is available in the match block only when the error is PCRE2_ERROR_NOMATCH, PCRE2_ERROR_PARTIAL, or one of the error codes for an invalid UTF string. Exactly what is available depends on the error, and is detailed below. -

    -

    +

    +

    When one of the matching functions is called, pointers to the compiled pattern and the subject string are set in the match data block so that they can be referenced by the extraction functions after a successful match. After running @@ -2851,26 +2861,26 @@ unless, in the case of the subject string, you have used the PCRE2_COPY_MATCHED_SUBJECT option, which is described in the section entitled "Option bits for pcre2_match()" below. -

    -

    +

    +

    When a match data block itself is no longer needed, it should be freed by calling pcre2_match_data_free(). If this function is called with a NULL argument, it returns immediately, without doing anything. -

    -
    MEMORY USE FOR MATCH DATA BLOCKS
    -

    +

    +

    MEMORY USE FOR MATCH DATA BLOCKS

    +

    PCRE2_SIZE pcre2_get_match_data_size(pcre2_match_data *match_data);

    PCRE2_SIZE pcre2_get_match_data_heapframes_size( pcre2_match_data *match_data); -

    -

    +

    +

    The size of a match data block depends on the size of the ovector that it contains. The function pcre2_get_match_data_size() returns the size, in bytes, of the block that is its argument. -

    -

    +

    +

    When pcre2_match() runs interpretively (that is, without using JIT), it makes use of a vector of data frames for remembering backtracking positions. The size of each individual frame depends on the number of capturing @@ -2878,44 +2888,44 @@ parentheses in the pattern and can be obtained by calling pcre2_pattern_info() with the PCRE2_INFO_FRAMESIZE option (see the section entitled "Information about a compiled pattern" above). -

    -

    +

    +

    Heap memory is used for the frames vector; if the initial memory block turns out to be too small during matching, it is automatically expanded. When pcre2_match() returns, the memory is not freed, but remains attached to the match data block, for use by any subsequent matches that use the same block. It is automatically freed when the match data block itself is freed. -

    -

    +

    +

    You can find the current size of the frames vector that a match data block owns by calling pcre2_get_match_data_heapframes_size(). For a newly created match data block the size will be zero. Some types of match may require a lot of frames and thus a large vector; applications that run in environments where memory is constrained can check this and free the match data block if the heap frames vector has become too big. -

    -
    MATCHING A PATTERN: THE TRADITIONAL FUNCTION
    -

    +

    +

    MATCHING A PATTERN: THE TRADITIONAL FUNCTION

    +

    int pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext); -

    -

    +

    +

    The function pcre2_match() is called to match a subject string against a compiled pattern, which is passed in the code argument. You can call pcre2_match() with the same code argument as many times as you like, in order to find multiple matches in the subject string or to match different subject strings with the same pattern. -

    -

    +

    +

    This function is the main matching facility of the library, and it operates in a Perl-like manner. For specialist use there is also an alternative matching function, which is described below in the section about the pcre2_dfa_match() function. -

    -

    +

    +

    Here is an example of a simple call to pcre2_match():

       pcre2_match_data *md = pcre2_match_data_create(4, NULL);
    @@ -2933,11 +2943,11 @@ PCRE2_ZERO_TERMINATED. A match context must be provided if certain less common
     matching parameters are to be changed. For details, see the section on
     the match context
     above.
    -

    -
    +

    +

    The string to be matched by pcre2_match() -
    -

    +

    +

    The subject string is passed to pcre2_match() as a pointer in subject, a length in length, and a starting offset in startoffset. The length and offset are in code units, not characters. @@ -2946,8 +2956,8 @@ That is, they are in bytes for the 8-bit library, 16-bit code units for the UTF processing is enabled. As a special case, if subject is NULL and length is zero, the subject is assumed to be an empty string. If length is non-zero, an error occurs if subject is NULL. -

    -

    +

    +

    If startoffset is greater than the length of the subject, pcre2_match() returns PCRE2_ERROR_BADOFFSET. When the starting offset is zero, the search for a match starts at the beginning of the subject, and this @@ -2955,8 +2965,8 @@ is by far the most common case. In UTF-8 or UTF-16 mode, the starting offset must point to the start of a character, or to the end of the subject (in UTF-32 mode, one code unit equals one character, so all offsets are valid). Like the pattern string, the subject may contain binary zeros. -

    -

    +

    +

    A non-zero starting offset is useful when searching for another match in the same subject by calling pcre2_match() again after a previous success. Setting startoffset differs from passing over a shortened string and @@ -2975,39 +2985,33 @@ at the start of the subject, which is deemed to be a word boundary. However, if startoffset set to 4, it finds the second occurrence of "iss" because it is able to look behind the starting point to discover that it is preceded by a letter. -

    -

    +

    +

    Finding all the matches in a subject is tricky when the pattern can match an -empty string. It is possible to emulate Perl's /g behaviour by first trying the -match again at the same offset, with the PCRE2_NOTEMPTY_ATSTART and -PCRE2_ANCHORED options, and then if that fails, advancing the starting offset -and trying an ordinary match again. There is some code that demonstrates how to -do this in the -pcre2demo -sample program. In the most general case, you have to check to see if the -newline convention recognizes CRLF as a newline, and if so, and the current -character is CR followed by LF, advance the starting offset by two characters -instead of one. -

    -

    +empty string. PCRE2 includes a helper API to assist with this; see the +section entitled "Iterating over all matches" +below +for details. +

    +

    If a non-zero starting offset is passed when the pattern is anchored, a single attempt to match at the given offset is made. This can only succeed if the pattern does not require the match to be at the start of the subject. In other words, the anchoring must be the result of setting the PCRE2_ANCHORED option or the use of .* with PCRE2_DOTALL, not by starting the pattern with ^ or \A. -

    -
    +

    +

    Option bits for pcre2_match() -
    -

    +

    +

    The unused bits of the options argument for pcre2_match() must be zero. The only bits that may be set are PCRE2_ANCHORED, PCRE2_COPY_MATCHED_SUBJECT, PCRE2_DISABLE_RECURSELOOP_CHECK, PCRE2_ENDANCHORED, PCRE2_NOTBOL, PCRE2_NOTEOL, PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_JIT, PCRE2_NO_UTF_CHECK, PCRE2_PARTIAL_HARD, and PCRE2_PARTIAL_SOFT. Their action is described below. -

    -

    +

    +

    Setting PCRE2_ANCHORED or PCRE2_ENDANCHORED at match time is not supported by the just-in-time (JIT) compiler. If it is set, JIT matching is disabled and the interpretive code in pcre2_match() is run. @@ -3018,7 +3022,7 @@ PCRE2_DISABLE_RECURSELOOP_CHECK is ignored by JIT, but apart from PCRE2_NO_JIT

    The PCRE2_ANCHORED option limits pcre2_match() to matching at the first matching position. If a pattern was compiled with PCRE2_ANCHORED, or turned out -to be anchored by virtue of its contents, it cannot be made unachored at +to be anchored by virtue of its contents, it cannot be made unanchored at matching time. Note that setting the option at match time disables JIT matching.
    @@ -3042,8 +3046,8 @@ operation.
     
    This option is relevant only to pcre2_match() for interpretive matching. It is ignored when JIT is used, and is forbidden for pcre2_dfa_match(). -

    -

    +

    +

    The use of recursion in patterns can lead to infinite loops. In the interpretive matcher these would be eventually caught by the match or heap limits, but this could take a long time and/or use a lot of memory if the @@ -3051,8 +3055,8 @@ limits are large. There is therefore a check at the start of each recursion. If the same group is still active from a previous call, and the current subject pointer is the same as it was at the start of that group, and the furthest inspected character of the subject has not changed, an error is generated. -

    -

    +

    +

    There are rare cases of matches that would complete, but nevertheless trigger this error. This option disables the check. It is provided mainly for testing when comparing JIT and interpretive behaviour. @@ -3116,8 +3120,8 @@ PCRE2_MATCH_INVALID_UTF was passed to pcre2_compile(). The latter special case is discussed in detail in the pcre2unicode documentation. -

    -

    +

    +

    In the default case, if a non-zero starting offset is given, the check is applied only to that part of the subject that could be inspected during matching, and there is a check that the starting offset points to the first @@ -3127,8 +3131,8 @@ Otherwise, it starts at the length of the longest lookbehind before the starting offset, or at the start of the subject if there are not that many characters before the starting offset. Note that the sequences \b and \B are one-character lookbehinds. -

    -

    +

    +

    The check is carried out before any other processing takes place, and a negative error code is returned if the check fails. There are several UTF error codes for each code unit width, corresponding to different problems with the @@ -3140,15 +3144,15 @@ and in the pcre2unicode documentation. -

    -

    +

    +

    If you know that your subject is valid, and you want to skip this check for performance reasons, you can set the PCRE2_NO_UTF_CHECK option when calling pcre2_match(). You might want to do this for the second and subsequent calls to pcre2_match() if you are making repeated calls to find multiple matches in the same subject string. -

    -

    +

    +

    Warning: Unless PCRE2_MATCH_INVALID_UTF was set at compile time, when PCRE2_NO_UTF_CHECK is set at match time the effect of passing an invalid string as a subject, or an invalid value of startoffset, is undefined. @@ -3162,30 +3166,30 @@ the end of the subject string is reached successfully, but there are not enough subject characters to complete the match. In addition, either at least one character must have been inspected or the pattern must contain a lookbehind, or the pattern must be one that could match an empty string. -

    -

    +

    +

    If this situation arises when PCRE2_PARTIAL_SOFT (but not PCRE2_PARTIAL_HARD) is set, matching continues by testing any remaining alternatives. Only if no complete match can be found is PCRE2_ERROR_PARTIAL returned instead of PCRE2_ERROR_NOMATCH. In other words, PCRE2_PARTIAL_SOFT specifies that the caller is prepared to handle a partial match, but only if no complete match can be found. -

    -

    +

    +

    If PCRE2_PARTIAL_HARD is set, it overrides PCRE2_PARTIAL_SOFT. In this case, if a partial match is found, pcre2_match() immediately returns PCRE2_ERROR_PARTIAL, without considering any other alternatives. In other words, when PCRE2_PARTIAL_HARD is set, a partial match is considered to be more -important that an alternative complete match. -

    -

    +important than an alternative complete match. +

    +

    There is a more detailed discussion of partial and multi-segment matching, with examples, in the pcre2partial documentation. -

    -
    NEWLINE HANDLING WHEN MATCHING
    -

    +

    +

    NEWLINE HANDLING WHEN MATCHING

    +

    When PCRE2 is built, a default newline convention is set; this is usually the standard convention for the operating system. The default can be overridden in a @@ -3198,40 +3202,40 @@ in the page. During matching, the newline choice affects the behaviour of the dot, circumflex, and dollar metacharacters. It may also alter the way the match starting position is advanced after a match failure for an unanchored pattern. -

    -

    +

    +

    When PCRE2_NEWLINE_CRLF, PCRE2_NEWLINE_ANYCRLF, or PCRE2_NEWLINE_ANY is set as the newline convention, and a match attempt for an unanchored pattern fails when the current starting position is at a CRLF sequence, and the pattern contains no explicit matches for CR or LF characters, the match position is advanced by two characters instead of one, in other words, to after the CRLF. -

    -

    +

    +

    The above rule is a compromise that makes the most common cases work as expected. For example, if the pattern is .+A (and the PCRE2_DOTALL option is not set), it does not match the string "\r\nA" because, after failing at the start, it skips both the CR and the LF before retrying. However, the pattern [\r\n]A does match that string, because it contains an explicit CR or LF reference, and so advances only by one character after the first failure. -

    -

    +

    +

    An explicit match for CR of LF is either a literal appearance of one of those characters in the pattern, or one of the \r or \n or equivalent octal or hexadecimal escape sequences. Implicit matches such as [^X] do not count, nor does \s, even though it includes CR and LF in the characters that it matches. -

    -

    +

    +

    Notwithstanding the above, anomalous effects may still occur when CRLF is a valid newline sequence and explicit \r or \n escapes appear in the pattern. -

    -
    HOW PCRE2_MATCH() RETURNS A STRING AND CAPTURED SUBSTRINGS
    -

    +

    +

    HOW PCRE2_MATCH() RETURNS A STRING AND CAPTURED SUBSTRINGS

    +

    uint32_t pcre2_get_ovector_count(pcre2_match_data *match_data);

    PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *match_data); -

    -

    +

    +

    In general, a pattern matches a certain portion of the subject, and in addition, further substrings from the subject may be picked out by parenthesized parts of the pattern. Following the usage in Jeffrey Friedl's @@ -3241,15 +3245,15 @@ substring. PCRE2 supports several other kinds of parenthesized group that do not cause substrings to be captured. The pcre2_pattern_info() function can be used to find out how many capture groups there are in a compiled pattern. -

    -

    +

    +

    You can use auxiliary functions for accessing captured substrings by number or by name, as described in sections below. -

    -

    +

    +

    Alternatively, you can make direct use of the vector of PCRE2_SIZE values, called the ovector, which contains the offsets of captured strings. It is part of the @@ -3257,23 +3261,23 @@ part of the The function pcre2_get_ovector_pointer() returns the address of the ovector, and pcre2_get_ovector_count() returns the number of pairs of values it contains. -

    -

    +

    +

    Within the ovector, the first in each pair of values is set to the offset of the first code unit of a substring, and the second is set to the offset of the first code unit after the end of a substring. These values are always code unit offsets, not character offsets. That is, they are byte offsets in the 8-bit library, 16-bit offsets in the 16-bit library, and 32-bit offsets in the 32-bit library. -

    -

    +

    +

    After a partial match (error return PCRE2_ERROR_PARTIAL), only the first pair of offsets (that is, ovector[0] and ovector[1]) are set. They identify the part of the subject that was partially matched. See the pcre2partial documentation for details of partial matching. -

    -

    +

    +

    After a fully successful match, the first pair of offsets identifies the portion of the subject string that was matched by the entire pattern. The next pair is used for the first captured substring, and so on. The value returned by @@ -3281,60 +3285,60 @@ pair is used for the first captured substring, and so on. The value returned by set. For example, if two substrings have been captured, the returned value is 3. If there are no captured substrings, the return value from a successful match is 1, indicating that just the first pair of offsets has been set. -

    -

    -If a pattern uses the \K escape sequence within a positive assertion, the -reported start of a successful match can be greater than the end of the match. -For example, if the pattern (?=ab\K) is matched against "ab", the start and -end offset values for the match are 2 and 0. -

    -

    +

    +

    +If a pattern uses the \K escape sequence within a positive lookahead assertion, +the reported start of a successful match can be greater than the end of the +match. For example, if the pattern (?=ab\K) is matched against "ab", the start +and end offset values for the match are 2 and 0. +

    +

    If a capture group is matched repeatedly within a single match operation, it is the last portion of the subject that it matched that is returned. -

    -

    +

    +

    If the ovector is too small to hold all the captured substring offsets, as much as possible is filled in, and the function returns a value of zero. If captured substrings are not of interest, pcre2_match() may be called with a match data block whose ovector is of minimum length (that is, one pair). -

    -

    +

    +

    It is possible for capture group number n+1 to match some part of the subject when group n has not been used at all. For example, if the string "abc" is matched against the pattern (a|(z))(bc) the return from the function is 4, and groups 1 and 3 are matched, but 2 is not. When this happens, both values in the offset pairs corresponding to unused groups are set to PCRE2_UNSET. -

    -

    +

    +

    Offset values that correspond to unused groups at the end of the expression are also set to PCRE2_UNSET. For example, if the string "abc" is matched against the pattern (abc)(x(yz)?)? groups 2 and 3 are not matched. The return from the function is 2, because the highest used capture group number is 1. The offsets for the second and third capture groups (assuming the vector is large enough, of course) are set to PCRE2_UNSET. -

    -

    +

    +

    Elements in the ovector that do not correspond to capturing parentheses in the pattern are never changed. That is, if a pattern contains n capturing parentheses, no more than ovector[0] to ovector[2n+1] are set by pcre2_match(). The other elements retain whatever values they previously had. After a failed match attempt, the contents of the ovector are unchanged. -

    -
    OTHER INFORMATION ABOUT A MATCH
    -

    +

    +

    OTHER INFORMATION ABOUT A MATCH

    +

    PCRE2_SPTR pcre2_get_mark(pcre2_match_data *match_data);

    PCRE2_SIZE pcre2_get_startchar(pcre2_match_data *match_data); -

    -

    +

    +

    As well as the offsets in the ovector, other information about a match is retained in the match data block and can be retrieved by the above functions in appropriate circumstances. If they are called at other times, the result is undefined. -

    -

    +

    +

    After a successful match, a partial match (PCRE2_ERROR_PARTIAL), or a failure to match (PCRE2_ERROR_NOMATCH), a mark name may be available. The function pcre2_get_mark() can be called to access this name, which can be @@ -3345,8 +3349,8 @@ available, NULL is returned. The length of the name (excluding the terminating zero) is stored in the code unit that precedes the name. You should use this length instead of relying on the terminating zero if the name might contain a binary zero. -

    -

    +

    +

    After a successful match, the name that is returned is the last mark name encountered on the matching path through the pattern. Instances of backtracking verbs without names do not count. Thus, for example, if the matching path @@ -3359,8 +3363,8 @@ this pattern: When it matches "bc", the returned name is A. The B mark is "seen" in the first branch of the group, but it is not on the matching path. On the other hand, when this pattern fails to match "bx", the returned name is B. -

    -

    +

    +

    Warning: By default, certain start-of-match optimizations are used to give a fast "no match" result in some situations. For example, if the anchoring is removed from the pattern above, there is an initial check for the presence @@ -3368,8 +3372,8 @@ of "c" in the subject before running the matching engine. This check fails for "bx", causing a match failure without seeing any marks. You can disable the start-of-match optimizations by setting the PCRE2_NO_START_OPTIMIZE option for pcre2_compile() or by starting the pattern with (*NO_START_OPT). -

    -

    +

    +

    After a successful match, a partial match, or one of the invalid UTF errors (for example, PCRE2_ERROR_UTF8_ERR5), pcre2_get_startchar() can be called. After a successful or partial match it returns the code unit offset of @@ -3377,15 +3381,15 @@ the character at which the match started. For a non-partial match, this can be different to the value of ovector[0] if the pattern contains the \K escape sequence. After a partial match, however, this value is always the same as ovector[0] because \K does not affect the result of a partial match. -

    -

    +

    +

    After a UTF check failure, pcre2_get_startchar() can be used to obtain the code unit offset of the invalid UTF character. Details are given in the pcre2unicode page. -

    -
    ERROR RETURNS FROM pcre2_match()
    -

    +

    +

    ERROR RETURNS FROM pcre2_match()

    +

    If pcre2_match() fails, it returns a negative number. This can be converted to a text string by calling the pcre2_get_error_message() function (see "Obtaining a textual error message" @@ -3490,30 +3494,122 @@ position in the subject string. Some simple patterns that might do this are detected and faulted at compile time, but more complicated cases, in particular mutual recursions between two different groups, cannot be detected until matching is attempted. -

    -
    OBTAINING A TEXTUAL ERROR MESSAGE
    -

    +

    +

    OBTAINING A TEXTUAL ERROR MESSAGE

    +

    int pcre2_get_error_message(int errorcode, PCRE2_UCHAR *buffer, PCRE2_SIZE bufflen); -

    -

    +

    +

    A text message for an error code from any PCRE2 function (compile, match, or auxiliary) can be obtained by calling pcre2_get_error_message(). The code is passed as the first argument, with the remaining two arguments specifying a code unit buffer and its length in code units, into which the text message is placed. The message is returned in code units of the appropriate width for the library that is being used. -

    -

    +

    +

    The returned message is terminated with a trailing zero, and the function returns the number of code units used, excluding the trailing zero. If the error number is unknown, the negative error code PCRE2_ERROR_BADDATA is returned. If the buffer is too small, the message is truncated (but still with a trailing zero), and the negative error code PCRE2_ERROR_NOMEMORY is returned. -None of the messages are very long; a buffer size of 120 code units is ample. -

    -
    EXTRACTING CAPTURED SUBSTRINGS BY NUMBER
    -

    +None of the messages is very long; a buffer size of 120 code units is ample. +

    +

    ITERATING OVER ALL MATCHES

    +

    +int pcre2_next_match(pcre2_match_data *match_data, + PCRE2_SIZE *pstart_offset, uint32_t *poptions); +

    +

    +A common task for applications is to implement "global" matching behaviour, +for example, replacing all matches in the subject; splitting the subject on all +matches; or simply counting the number of matches. The pcre2_next_match() +function helps with this task by providing the appropriate parameters for the +next match attempt (available since PCRE2 10.46). +

    +

    +First, a match attempt should be made using one of the matching functions +(pcre2_match(), pcre2_dfa_match(), or pcre2_jit_match()). +Then, pcre2_next_match() can be called, providing the same +match_data parameter. +

    +

    +It returns 0 ("false") if there is no need to make a further match attempt, or +1 ("true") if another match should be attempted. Returning 1 does not imply that +there is another match, only that another match should be attempted (which may +return PCRE2_ERROR_NOMATCH). +

    +

    +The *pstart_offset and *poptions are set if the function returns 1. +The *pstart_offset should be passed to the next match attempt directly, +and the *poptions should be passed to the next match attempt by combining +with the application's match options using OR. +

    +

    +There is some code that demonstrates how to do this in the +pcre2demo +sample program. The general pattern is: +
    +
    +

    +  uint32_t app_options = ...;
    +  uint32_t global_options = 0;
    +  PCRE2_SIZE start_offset = 0;
    +  while (1)
    +    {
    +    int rc = pcre2_match(re, subject, subject_len, start_offset,
    +                         app_options | global_options, match_data,
    +                         match_context);
    +
    +    if (rc == PCRE2_ERROR_NOMATCH) break; /* no match, and no more attempts */
    +    if (rc < 0) { ... exit }
    +
    +    ...handle the match
    +
    +    if (!pcre2_next_match(match_data, &start_offset, &global_options))
    +      break; /* no more attempts */
    +    }
    +
    +

    +

    +The guarantees provided by pcre2_next_match() are that the start_offset +will advance, so the loop will definitely terminate. The conditions which +ensure this are that either: (a) pcre2_next_match() returns 0 (false); or +(b) the returned *pstart_offset is strictly greater than the previous +start_offset; or (c) if the previous match was a successful match of the empty +string then the returned *pstart_offset is equal to the previous +ovector[1], and *poptions will be set to PCRE2_NOTEMPTY_ATSTART to prevent +another empty match from being returned. +

    +

    +A loop implemented as shown above will always terminate, unless there is a bug +in PCRE2. As a measure of "defensive programming", applications are encouraged +to add an assertion or check to break their loop if it does not make progress +(and report the issue as a bug). +

    +

    +If an application does not use the flag PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK, then +each match is "well-behaved" and satisfies: +

    +  start_offset <= ovector[0] <= ovector[1].
    +
    +In this case, the matches found by pcre2_match() with pcre2_next_match() will be +sorted, non-overlapping (possibly touching), and with no duplicates. +

    +

    +Otherwise, if PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK is used, then the guarantees are +considerably weaker. We do not guarantee that the matches will always advance: +only that the start_offset will. The matches found by pcre2_match() with +pcre2_next_match() will be a finite sequence (as pcre2_next_match() ensures that +start_offset advances, so the search will terminate). The matches can however be +overlapping, can contain duplicates, and (in truly pathological examples) may +not even be sorted by ovector[0]. Additionally, each match itself can end before +it starts (ovector[1] < ovector[0]). We recommend that applications do not set +PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK. +

    +

    EXTRACTING CAPTURED SUBSTRINGS BY NUMBER

    +

    int pcre2_substring_length_bynumber(pcre2_match_data *match_data, uint32_t number, PCRE2_SIZE *length);
    @@ -3529,59 +3625,60 @@ None of the messages are very long; a buffer size of 120 code units is ample.

    void pcre2_substring_free(PCRE2_UCHAR *buffer); -

    -

    +

    +

    Captured substrings can be accessed directly by using the ovector as described above. For convenience, auxiliary functions are provided for extracting captured substrings as new, separate, zero-terminated strings. A substring that contains a binary zero is correctly extracted and has a further zero added on the end, but the result is not, of course, a C string. -

    -

    +

    +

    The functions in this section identify substrings by number. The number zero refers to the entire matched substring, with higher numbers referring to substrings captured by parenthesized groups. After a partial match, only substring zero is available. An attempt to extract any other substring gives the error PCRE2_ERROR_PARTIAL. The next section describes similar functions for extracting captured substrings by name. -

    -

    -If a pattern uses the \K escape sequence within a positive assertion, the -reported start of a successful match can be greater than the end of the match. -For example, if the pattern (?=ab\K) is matched against "ab", the start and -end offset values for the match are 2 and 0. In this situation, calling these -functions with a zero substring number extracts a zero-length empty string. -

    -

    +

    +

    +If a pattern uses the \K escape sequence within a positive lookahead assertion, +the reported start of a successful match can be greater than the end of the +match. For example, if the pattern (?=ab\K) is matched against "ab", the start +and end offset values for the match are 2 and 0. In this situation, calling +these functions with a zero substring number extracts a zero-length empty +string. +

    +

    You can find the length in code units of a captured substring without extracting it by calling pcre2_substring_length_bynumber(). The first argument is a pointer to the match data block, the second is the group number, and the third is a pointer to a variable into which the length is placed. If you just want to know whether or not the substring has been captured, you can pass the third argument as NULL. -

    -

    +

    +

    The pcre2_substring_copy_bynumber() function copies a captured substring into a supplied buffer, whereas pcre2_substring_get_bynumber() copies it into new memory, obtained using the same memory allocation function that was used for the match data block. The first two arguments of these functions are a pointer to the match data block and a capture group number. -

    -

    +

    +

    The final arguments of pcre2_substring_copy_bynumber() are a pointer to the buffer and a pointer to a variable that contains its length in code units. This is updated to contain the actual number of code units used for the extracted substring, excluding the terminating zero. -

    -

    +

    +

    For pcre2_substring_get_bynumber() the third and fourth arguments point to variables that are updated with a pointer to the new memory and the number of code units that comprise the substring, again excluding the terminating zero. When the substring is no longer needed, the memory should be freed by calling pcre2_substring_free(). -

    -

    +

    +

    The return value from all these functions is zero for success, or a negative error code. If the pattern match failed, the match failure code is returned. If a substring number greater than zero is used after a partial match, @@ -3608,28 +3705,28 @@ could not be captured. The substring did not participate in the match. For example, if the pattern is (abc)|(def) and the subject is "def", and the ovector contains at least two capturing slots, substring number 1 is unset. -

    -
    EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS
    -

    +

    +

    EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS

    +

    int pcre2_substring_list_get(pcre2_match_data *match_data, -" PCRE2_UCHAR ***listptr, PCRE2_SIZE **lengthsptr); + PCRE2_UCHAR ***listptr, PCRE2_SIZE **lengthsptr);

    void pcre2_substring_list_free(PCRE2_UCHAR **list); -

    -

    +

    +

    The pcre2_substring_list_get() function extracts all available substrings and builds a list of pointers to them. It also (optionally) builds a second list that contains their lengths (in code units), excluding a terminating zero that is added to each of them. All this is done in a single block of memory that is obtained using the same memory allocation function that was used to get the match data block. -

    -

    +

    +

    This function must be called only after a successful match. If called after a partial match, the error code PCRE2_ERROR_PARTIAL is returned. -

    -

    +

    +

    The address of the memory block is returned via listptr, which is also the start of the list of string pointers. The end of the list is marked by a NULL pointer. The address of the list of lengths is returned via @@ -3639,17 +3736,17 @@ argument to disable the creation of a list of lengths. The yield of the function is zero if all went well, or PCRE2_ERROR_NOMEMORY if the memory block could not be obtained. When the list is no longer needed, it should be freed by calling pcre2_substring_list_free(). -

    -

    +

    +

    If this function encounters a substring that is unset, which can happen when capture group number n+1 matches some part of the subject, but group n has not been used at all, it returns an empty string. This can be distinguished from a genuine zero-length substring by inspecting the appropriate offset in the ovector, which contain PCRE2_UNSET for unset substrings, or by calling pcre2_substring_length_bynumber(). -

    -
    EXTRACTING CAPTURED SUBSTRINGS BY NAME
    -

    +

    +

    EXTRACTING CAPTURED SUBSTRINGS BY NAME

    +

    int pcre2_substring_number_from_name(const pcre2_code *code, PCRE2_SPTR name);
    @@ -3667,8 +3764,8 @@ substrings, or by calling pcre2_substring_length_bynumber().

    void pcre2_substring_free(PCRE2_UCHAR *buffer); -

    -

    +

    +

    To extract a substring by name, you first have to find associated number. For example, for this pattern:

    @@ -3682,22 +3779,22 @@ group number, PCRE2_ERROR_NOSUBSTRING if there is no group with that name, or
     PCRE2_ERROR_NOUNIQUESUBSTRING if there is more than one group with that name.
     Given the number, you can extract the substring directly from the ovector, or
     use one of the "bynumber" functions described above.
    -

    -

    +

    +

    For convenience, there are also "byname" functions that correspond to the "bynumber" functions, the only difference being that the second argument is a name instead of a number. If PCRE2_DUPNAMES is set and there are duplicate names, these functions scan all the groups with the given name, and return the captured substring from the first named group that is set. -

    -

    +

    +

    If there are no groups with the given name, PCRE2_ERROR_NOSUBSTRING is returned. If all groups with the name have numbers that are greater than the number of slots in the ovector, PCRE2_ERROR_UNAVAILABLE is returned. If there is at least one group with a slot in the ovector, but no group is found to be set, PCRE2_ERROR_UNSET is returned. -

    -

    +

    +

    Warning: If the pattern uses the (?| feature to set up multiple capture groups with the same number, as described in the section on duplicate group numbers @@ -3707,17 +3804,17 @@ page, you cannot use names to distinguish the different capture groups, because names are not included in the compiled code. The matching process uses only numbers. For this reason, the use of different names for groups with the same number causes an error at compile time. -

    -
    CREATING A NEW STRING WITH SUBSTITUTIONS
    -

    +

    +

    CREATING A NEW STRING WITH SUBSTITUTIONS

    +

    int pcre2_substitute(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext, PCRE2_SPTR replacement, PCRE2_SIZE rlength, PCRE2_UCHAR *outputbuffer, PCRE2_SIZE *outlengthptr); -

    -

    +

    +

    This function optionally calls pcre2_match() and then makes a copy of the subject string in outputbuffer, replacing parts that were matched with the replacement string, whose length is supplied in rlength, which @@ -3725,66 +3822,92 @@ can be given as PCRE2_ZERO_TERMINATED for a zero-terminated string. As a special case, if replacement is NULL and rlength is zero, the replacement is assumed to be an empty string. If rlength is non-zero, an error occurs if replacement is NULL. -

    -

    +

    +

    There is an option (see PCRE2_SUBSTITUTE_REPLACEMENT_ONLY below) to return just the replacement string(s). The default action is to perform just one replacement if the pattern matches, but there is an option that requests multiple replacements (see PCRE2_SUBSTITUTE_GLOBAL below). -

    -

    +

    +

    If successful, pcre2_substitute() returns the number of substitutions that were carried out. This may be zero if no match was found, and is never greater than one unless PCRE2_SUBSTITUTE_GLOBAL is set. A negative value is returned if an error is detected. -

    -

    +

    +

    Matches in which a \K item in a lookahead in the pattern causes the match to end before it starts are not supported, and give rise to an error return. For global replacements, matches in which \K in a lookbehind causes the match to start earlier than the point that was reached in the previous iteration are -also not supported. -

    -

    +also not supported. (These cases are only possible if the pattern was compiled +with the backwards-compatibility option PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK.) +

    +

    The first seven arguments of pcre2_substitute() are the same as for pcre2_match(), except that the partial matching options are not permitted, and match_data may be passed as NULL, in which case a match data block is obtained and freed within this function, using memory management functions from the match context, if provided, or else those that were used to allocate memory for the compiled code. -

    -

    +

    +

    If match_data is not NULL and PCRE2_SUBSTITUTE_MATCHED is not set, the provided block is used for all calls to pcre2_match(), and its contents -afterwards are the result of the final call. For global changes, this will +afterwards are the result of the final call made internally by +pcre2_substitute() to the matching function. For global changes, this will always be a no-match error. The contents of the ovector within the match data block may or may not have been changed. -

    -

    +

    +

    As well as the usual options for pcre2_match(), a number of additional options can be set in the options argument of pcre2_substitute(). One such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external match_data block must be provided, and it must have already been used for -an external call to pcre2_match() with the same pattern and subject -arguments. The data in the match_data block (return code, offset vector) -is then used for the first substitution instead of calling pcre2_match() -from within pcre2_substitute(). This allows an application to check for a -match before choosing to substitute, without having to repeat the match. -

    -

    +an external call to pcre2_match() (or pcre2_jit_match()) with the +same pattern, subject pointer, effective subject length, start offset, and match +option arguments (substitute-specific options can be added to the options +argument). If any of these parameters is changed, pcre2_substitute() +returns an error. The data in the match_data block (return code, offset +vector) is used for the first substitution instead of calling +pcre2_match() from within pcre2_substitute(). This allows an +application to check for a match before choosing to substitute, without having +to repeat the match. +

    +

    +If the contents of the subject buffer are mutated in between pcre2_match() +and a call to pcre2_substitute() with PCRE2_SUBSTITUTE_MATCHED, the +behaviour is unsafe; in particular, in this case, PCRE2 is unable to ensure that +the offsets in the ovector point to the start of characters (with UTF-encoded +input). +

    +

    The contents of the externally supplied match data block are not changed when -PCRE2_SUBSTITUTE_MATCHED is set. If PCRE2_SUBSTITUTE_GLOBAL is also set, -pcre2_match() is called after the first substitution to check for further -matches, but this is done using an internally obtained match data block, thus -always leaving the external block unchanged. -

    -

    +PCRE2_SUBSTITUTE_MATCHED is set, and so the match block is permitted for use in +another call using PCRE2_SUBSTITUTE_MATCHED. If PCRE2_SUBSTITUTE_GLOBAL is also +set, pcre2_match() is called after the first substitution to check for +furthe matches, but this is done using an internally obtained match data block, +thus always leaving the external block unchanged. +

    +

    The code argument is not used for matching before the first substitution when PCRE2_SUBSTITUTE_MATCHED is set, but it must be provided, even when PCRE2_SUBSTITUTE_GLOBAL is not set, because it contains information such as the UTF setting and the number of capturing parentheses in the pattern. -

    -

    +

    +

    +When using PCRE2_SUBSTITUTE_MATCHED, you should not modify the subject string +in between the prior call to pcre2_match() and pcre2_substitute(), +as the substitution assumes that the passed-in ovector is compatible with the +subject string. Although PCRE2 does verify that the subject is a pointer to the +same buffer, it cannot in general verify whether the contents of the buffer have +changed. For example, if the subject buffer is mutated from one valid UTF-8 +string to another valid string, of the same length in code units, the ovector +offsets are no longer guaranteed to point to the start of a character. Beware +that with PCRE2_SUBSTITUTE_MATCHED in UTF mode, the subject string is not +re-scanned for UTF validity when pcre2_substitute() first uses it. +

    +

    The default action of pcre2_substitute() is to return a copy of the subject string with matched substrings replaced. However, if PCRE2_SUBSTITUTE_REPLACEMENT_ONLY is set, only the replacement substrings are @@ -3792,22 +3915,22 @@ returned. In the global case, multiple replacements are concatenated in the output buffer. Substitution callouts (see below) can be used to separate them if necessary. -

    -

    +

    +

    The outlengthptr argument of pcre2_substitute() must point to a variable that contains the length, in code units, of the output buffer. If the function is successful, the value is updated to contain the length in code units of the new string, excluding the trailing zero that is automatically added. -

    -

    +

    +

    If the function is not successful, the value set via outlengthptr depends on the type of error. For syntax errors in the replacement string, the value is the offset in the replacement string where the error was detected. For other errors, the value is PCRE2_UNSET by default. This includes the case of the output buffer being too small, unless PCRE2_SUBSTITUTE_OVERFLOW_LENGTH is set. -

    -

    +

    +

    PCRE2_SUBSTITUTE_OVERFLOW_LENGTH changes what happens when the output buffer is too small. The default action is to return PCRE2_ERROR_NOMEMORY immediately. If this option is set, however, pcre2_substitute() continues to go through @@ -3816,20 +3939,20 @@ in order to compute the size of buffer that is needed, which will include the extra space for the terminating NUL. This value is passed back via the outlengthptr variable, with the result of the function still being PCRE2_ERROR_NOMEMORY. -

    -

    +

    +

    Passing a buffer size of zero is a permitted way of finding out how much memory is needed for given substitution. However, this does mean that the entire operation is carried out twice. Depending on the application, it may be more efficient to allocate a large buffer and free the excess afterwards, instead of using PCRE2_SUBSTITUTE_OVERFLOW_LENGTH. -

    -

    +

    +

    The replacement string, which is interpreted as a UTF string in UTF mode, is checked for UTF validity unless PCRE2_NO_UTF_CHECK is set. An invalid UTF replacement string causes an immediate return with the relevant UTF error code. -

    -

    +

    +

    If PCRE2_SUBSTITUTE_LITERAL is set, the replacement string is not interpreted in any way. By default, however, a dollar character is an escape character that can specify the insertion of characters from capture groups and names from @@ -3843,19 +3966,20 @@ recognized: $` insert the substring that precedes the match $' insert the substring that follows the match $_ insert the entire input string + $+ insert the highest-numbered capture group which matched $*MARK or ${*MARK} insert a control verb name

    -Either a group number or a group name can be given for n, for example $2 or -$NAME. Curly brackets are required only if the following character would be +Either a group number or a group name can be given for n, for example $2 +or $NAME. Curly brackets are required only if the following character would be interpreted as part of the number or name. The number may be zero to include the entire matched string. For example, if the pattern a(b)c is matched with "=abc=" and the replacement string "+$1$0$1+", the result is "=+babcb+=". -

    -

    +

    +

    The JavaScript form $<name>, where the angle brackets are part of the syntax, is also recognized for group names, but not for group numbers or *MARK. -

    -

    +

    +

    $*MARK inserts the name from the last encountered backtracking control verb on the matching path that has a name. (*MARK) must always include a name, but the other verbs need not. For example, in the case of (*MARK:A)(*PRUNE) the name @@ -3874,8 +3998,20 @@ original subject string (that is, previous replacements do not affect it). Iteration is implemented by advancing the startoffset value for each search, which is always passed the entire subject string. If an offset limit is set in the match context, searching stops when that limit is reached. -

    -

    +

    +

    +Because global substitutions apply the pattern repeatedly to the subject string, +and always iterate over non-overlapping matches, the substitutions done by +pcre2_substitute() do not match and substitute text inside the replacement +strings themselves (no recursive/iterative substitution). However, applications +can easily implement other alternative replacement strategies, such as +iteratively replacing, then matching and replacing on the result. The +replacement loop inside pcre2_substitute() is simple and can be emulated +in client code by allocating a buffer, searching for matches in a loop, and +calling pcre2_substitute() with PCRE2_SUBSTITUTE_REPLACEMENT_ONLY an +PCRE2_SUBSTITUTE_MATCHED, and without PCRE2_SUBSTITUTE_GLOBAL. +

    +

    You can restrict the effect of a global substitution to a portion of the subject string by setting either or both of startoffset and an offset limit. Here is a pcre2test example: @@ -3889,46 +4025,46 @@ length, an attempt to find a non-empty match at the same offset is performed. If this is not successful, the offset is advanced by one character except when CRLF is a valid newline sequence and the next two characters are CR, LF. In this case, the offset is advanced by two characters. -

    -

    +

    +

    PCRE2_SUBSTITUTE_UNKNOWN_UNSET causes references to capture groups that do not appear in the pattern to be treated as unset groups. This option should be used with care, because it means that a typo in a group name or number no longer causes the PCRE2_ERROR_NOSUBSTRING error. -

    -

    +

    +

    PCRE2_SUBSTITUTE_UNSET_EMPTY causes unset capture groups (including unknown groups when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) to be treated as empty strings when inserted as described above. If this option is not set, an attempt to insert an unset group causes the PCRE2_ERROR_UNSET error. This option does not influence the extended substitution syntax described below. -

    -

    +

    +

    PCRE2_SUBSTITUTE_EXTENDED causes extra processing to be applied to the replacement string. Without this option, only the dollar character is special, and only the group insertion forms listed above are valid. When PCRE2_SUBSTITUTE_EXTENDED is set, several things change: -

    -

    +

    +

    Firstly, backslash in a replacement string is interpreted as an escape character. The usual forms such as \x{ddd} can be used to specify particular character codes, and backslash followed by any non-alphanumeric character quotes that character. Extended quoting can be coded using \Q...\E, exactly as in pattern strings. The escapes \b and \v are interpreted as the characters backspace and vertical tab, respectively. -

    -

    +

    +

    The interpretation of backslash followed by one or more digits is the same as in a pattern, which in Perl has some ambiguities. Details are given in the pcre2pattern page. -

    -

    -The Python form \g<n>, where the angle brackets are part of the syntax and n -is either a group name or number, is recognized as an altertive way of -inserting the contents of a group, for example \g<3>. -

    -

    +

    +

    +The Python form \g<n>, where the angle brackets are part of the syntax and +n is either a group name or number, is recognized as an alternative way +of inserting the contents of a group, for example \g<3>. +

    +

    There are also four escape sequences for forcing the case of inserted letters. Case forcing applies to all inserted characters, including those from capture groups and letters within \Q...\E quoted sequences. The insertion mechanism @@ -3938,15 +4074,15 @@ case forcing, respectively, and \E (when not terminating a \Q quoted sequence) reverts to no case forcing. The sequences \u and \l force the next character (if it is a letter) to upper or lower case, respectively, and then the state automatically reverts to no case forcing. -

    -

    +

    +

    However, if \u is immediately followed by \L or \l is immediately followed by \U, the next character's case is forced by the first escape sequence, and subsequent characters by the second. This provides a "title casing" facility that can be applied to group captures. For example, if group 1 has captured "heLLo", the replacement string "\u\L$1" becomes "Hello". -

    -

    +

    +

    If either PCRE2_UTF or PCRE2_UCP was set when the pattern was compiled, Unicode properties are used for case forcing characters whose code points are greater than 127. However, only simple case folding, as determined by the Unicode file @@ -3954,14 +4090,14 @@ than 127. However, only simple case folding, as determined by the Unicode file special casing rules such as using different lower case Greek sigmas in the middle and ends of words (as defined in the Unicode file SpecialCasing.txt). -

    -

    +

    +

    Note that case forcing sequences such as \U...\E do not nest. For example, the result of processing "\Uaa\LBB\Ecc\E" is "AAbbcc"; the final \E has no effect. Note also that the PCRE2_ALT_BSUX and PCRE2_EXTRA_ALT_BSUX options do not apply to replacement strings. -

    -

    +

    +

    The final effect of setting PCRE2_SUBSTITUTE_EXTENDED is to add more flexibility to capture group substitution. The syntax is similar to that used by Bash: @@ -3990,71 +4126,71 @@ string remains in force afterwards, as shown in this pcre2test example: The PCRE2_SUBSTITUTE_UNSET_EMPTY option does not affect these extended substitutions. However, PCRE2_SUBSTITUTE_UNKNOWN_UNSET does cause unknown groups in the extended syntax forms to be treated as unset. -

    -

    +

    +

    If PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_UNKNOWN_UNSET, PCRE2_SUBSTITUTE_UNSET_EMPTY, and PCRE2_SUBSTITUTE_EXTENDED are irrelevant and are ignored. -

    -
    +

    +

    Substitution errors -
    -

    +

    +

    In the event of an error, pcre2_substitute() returns a negative error code. Except for PCRE2_ERROR_NOMATCH (which is never returned), errors from pcre2_match() are passed straight back. -

    -

    +

    +

    PCRE2_ERROR_NOSUBSTRING is returned for a non-existent substring insertion, unless PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set. -

    -

    +

    +

    PCRE2_ERROR_UNSET is returned for an unset substring insertion (including an unknown substring when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) when the simple (non-extended) syntax is used and PCRE2_SUBSTITUTE_UNSET_EMPTY is not set. -

    -

    +

    +

    PCRE2_ERROR_NOMEMORY is returned if the output buffer is not big enough. If the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set, the size of buffer that is needed is returned via outlengthptr. Note that this does not happen by default. -

    -

    +

    +

    PCRE2_ERROR_NULL is returned if PCRE2_SUBSTITUTE_MATCHED is set but the match_data argument is NULL or if the subject or replacement arguments are NULL. For backward compatibility reasons an exception is made for the replacement argument if the rlength argument is also 0. -

    -

    +

    +

    PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in the replacement string, with more particular errors being PCRE2_ERROR_BADREPESCAPE (invalid escape sequence), PCRE2_ERROR_REPMISSINGBRACE (closing curly bracket not found), PCRE2_ERROR_BADSUBSTITUTION (syntax error in extended group substitution), and PCRE2_ERROR_BADSUBSPATTERN (the pattern match ended before it started or the match started earlier than the current position in the -subject, which can happen if \K is used in an assertion). -

    -

    +subject, which can happen if \K is used in a lookaround assertion). +

    +

    As for all PCRE2 errors, a text message that describes the error can be obtained by calling the pcre2_get_error_message() function (see "Obtaining a textual error message" above). -

    -
    +

    +

    Substitution callouts -
    -

    +

    +

    int pcre2_set_substitute_callout(pcre2_match_context *mcontext, int (*callout_function)(pcre2_substitute_callout_block *, void *), void *callout_data);

    -The pcre2_set_substitution_callout() function can be used to specify a +The pcre2_set_substitute_callout() function can be used to specify a callout function for pcre2_substitute(). This information is passed in a match context. The callout function is called after each substitution has been processed, but it can cause the replacement not to happen. -

    -

    +

    +

    The callout function is not called for simulated substitutions that happen as a result of the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option. In this mode, when substitution processing exceeds the buffer space provided by the caller, @@ -4064,8 +4200,8 @@ required buffer size. Whichever is larger of accepted or rejected substitution is reported as the required size. Therefore, the returned buffer length may be an overestimate (without a substitution callout, it is normally an exact measurement). -

    -

    +

    +

    The first argument of the callout function is a pointer to a substitute callout block structure, which contains the following fields, not necessarily in this order: @@ -4081,28 +4217,28 @@ order: The version field contains the version number of the block format. The current version is 0. The version number will increase in future if more fields are added, but the intention is never to remove any of the existing fields. -

    -

    +

    +

    The subscount field is the number of the current match. It is 1 for the first callout, 2 for the second, and so on. The input and output pointers are copies of the values passed to pcre2_substitute(). -

    -

    +

    +

    The ovector field points to the ovector, which contains the result of the most recent match. The oveccount field contains the number of pairs that are set in the ovector, and is always greater than zero. -

    -

    +

    +

    The output_offsets vector contains the offsets of the replacement in the output string. This has already been processed for dollar and (if requested) backslash substitutions as described above. -

    -

    +

    +

    The second argument of the callout function is the value passed as callout_data when the function was registered. The value returned by the callout function is interpreted as follows: -

    -

    +

    +

    If the value is zero, the replacement is accepted, and, if PCRE2_SUBSTITUTE_GLOBAL is set, processing continues with a search for the next match. If the value is not zero, the current replacement is not accepted. If @@ -4111,11 +4247,11 @@ PCRE2_SUBSTITUTE_GLOBAL is set. Otherwise (the value is less than zero or PCRE2_SUBSTITUTE_GLOBAL is not set), the rest of the input is copied to the output and the call to pcre2_substitute() exits, returning the number of matches so far. -

    -
    +

    +

    Substitution case callouts -
    -

    +

    +

    int pcre2_set_substitute_case_callout(pcre2_match_context *mcontext, PCRE2_SIZE (*callout_function)(PCRE2_SPTR, PCRE2_SIZE, PCRE2_UCHAR *, PCRE2_SIZE, @@ -4123,24 +4259,24 @@ Substitution case callouts void *callout_data);

    -The pcre2_set_substitution_case_callout() function can be used to specify +The pcre2_set_substitute_case_callout() function can be used to specify a callout function for pcre2_substitute() to use when performing case transformations. This does not affect any case insensitivity behaviour when performing a match, but only the user-visible transformations performed when processing a substitution such as:

         pcre2_substitute(..., "\\U$1", ...)
    -
    -

    -

    +

    +

    +

    The default case transformations applied by PCRE2 are reasonably complete, and, in UTF or UCP mode, perform the simple locale-invariant case transformations as specified by Unicode. This is suitable for the internal (invisible) case-equivalence procedures used during pattern matching, but an application may wish to use more sophisticated locale-aware processing for the user-visible substitution transformations. -

    -

    +

    +

    One example implementation of the callout_function using the ICU library would be:
    @@ -4162,16 +4298,16 @@ library would be: if (U_FAILURE(err)) return (~(PCRE2_SIZE)0); return r; } -

    -

    -

    +

    +

    +

    The first and second arguments of the case callout function are the Unicode string to transform. -

    -

    +

    +

    The third and fourth arguments are the output buffer and its capacity. -

    -

    +

    +

    The fifth is one of the constants PCRE2_SUBSTITUTE_CASE_LOWER, PCRE2_SUBSTITUTE_CASE_UPPER, or PCRE2_SUBSTITUTE_CASE_TITLE_FIRST. PCRE2_SUBSTITUTE_CASE_LOWER and PCRE2_SUBSTITUTE_CASE_UPPER are passed to the @@ -4181,12 +4317,12 @@ only the first character or glyph should be transformed to Unicode titlecase and the rest to Unicode lowercase (note that titlecasing sometimes uses Unicode properties to titlecase each word in a string; but PCRE2 is requesting that only the single leading character is to be titlecased). -

    -

    +

    +

    The sixth argument is the callout_data supplied to pcre2_set_substitute_case_callout(). -

    -

    +

    +

    The resulting string in the destination buffer may be larger or smaller than the input, if the casing rules merge or split characters. The return value is the length required for the output string. If a buffer of sufficient size was @@ -4195,13 +4331,13 @@ number of code units returned. If the result does not fit in the provided buffer, then the required capacity must be returned and PCRE2 will not make use of the output buffer. PCRE2 provides input and output buffers which overlap, so the callout must support this by suitable internal buffering. -

    -

    +

    +

    Alternatively, if the callout wishes to indicate an error, then it may return (~(PCRE2_SIZE)0). In this case pcre2_substitute() will immediately fail with error PCRE2_ERROR_REPLACECASE. -

    -

    +

    +

    When a case callout is combined with the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option, there are situations when pcre2_substitute() will return an underestimate of the required buffer size. If you call pcre2_substitute() once @@ -4212,55 +4348,55 @@ The second call should also pass PCRE2_SUBSTITUTE_OVERFLOW_LENGTH, because that second call is not guaranteed to succeed either, if the case callout requires more buffer space than expected. The caller must make repeated attempts in a loop. -

    -
    DUPLICATE CAPTURE GROUP NAMES
    -

    +

    +

    DUPLICATE CAPTURE GROUP NAMES

    +

    int pcre2_substring_nametable_scan(const pcre2_code *code, PCRE2_SPTR name, PCRE2_SPTR *first, PCRE2_SPTR *last); -

    -

    +

    +

    When a pattern is compiled with the PCRE2_DUPNAMES option, names for capture groups are not required to be unique. Duplicate names are always allowed for groups with the same number, created by using the (?| feature. Indeed, if such groups are named, they are required to use the same names. -

    -

    +

    +

    Normally, patterns that use duplicate names are such that in any one match, only one of each set of identically-named groups participates. An example is shown in the pcre2pattern documentation. -

    -

    +

    +

    When duplicates are present, pcre2_substring_copy_byname() and pcre2_substring_get_byname() return the first substring corresponding to the given name that is set. Only if none are set is PCRE2_ERROR_UNSET is returned. The pcre2_substring_number_from_name() function returns the error PCRE2_ERROR_NOUNIQUESUBSTRING when there are duplicate names. -

    -

    +

    +

    If you want to get full details of all captured substrings for a given name, you must use the pcre2_substring_nametable_scan() function. The first argument is the compiled pattern, and the second is the name. If the third and fourth arguments are NULL, the function returns a group number for a unique name, or PCRE2_ERROR_NOUNIQUESUBSTRING otherwise. -

    -

    +

    +

    When the third and fourth arguments are not NULL, they must be pointers to variables that are updated by the function. After it has run, they point to the first and last entries in the name-to-number table for the given name, and the function returns the length of each entry in code units. In both cases, PCRE2_ERROR_NOSUBSTRING is returned if there are no entries for the given name. -

    -

    +

    +

    The format of the name table is described above in the section entitled Information about a pattern. Given all the relevant entries for the name, you can extract each of their numbers, and hence the captured data. -

    -
    FINDING ALL POSSIBLE MATCHES AT ONE POSITION
    -

    +

    +

    FINDING ALL POSSIBLE MATCHES AT ONE POSITION

    +

    The traditional matching function uses a similar algorithm to Perl, which stops when it finds the first match at a given point in the subject. If you want to find all possible matches, or the longest possible match at a given position, @@ -4269,23 +4405,23 @@ cannot use the alternative function, you can kludge it up by making use of the callout facility, which is described in the pcre2callout documentation. -

    -

    +

    +

    What you have to do is to insert a callout right at the end of the pattern. When your callout function is called, extract and save the current matched substring. Then return 1, which forces pcre2_match() to backtrack and try other alternatives. Ultimately, when it runs out of matches, pcre2_match() will yield PCRE2_ERROR_NOMATCH. -

    -
    MATCHING A PATTERN: THE ALTERNATIVE FUNCTION
    -

    +

    +

    MATCHING A PATTERN: THE ALTERNATIVE FUNCTION

    +

    int pcre2_dfa_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext, int *workspace, PCRE2_SIZE wscount); -

    -

    +

    +

    The function pcre2_dfa_match() is called to match a subject string against a compiled pattern, using a matching algorithm that scans the subject string just once (not counting lookaround assertions), and does not backtrack @@ -4297,21 +4433,21 @@ matching algorithms, and a list of features that pcre2_dfa_match() does not support, see the pcre2matching documentation. -

    -

    +

    +

    The arguments for the pcre2_dfa_match() function are the same as for pcre2_match(), plus two extras. The ovector within the match data block is used in a different way, and this is described below. The other common arguments are used in the same way as for pcre2_match(), so their description is not repeated here. -

    -

    +

    +

    The two additional arguments provide workspace for the function. The workspace vector should contain at least 20 elements. It is used for keeping track of multiple paths through the pattern tree. More workspace is needed for patterns and subjects where there are a lot of potential matches. -

    -

    +

    +

    Here is an example of a simple call to pcre2_dfa_match():

       int wspace[20];
    @@ -4326,12 +4462,12 @@ Here is an example of a simple call to pcre2_dfa_match():
         NULL,           /* a match context; NULL means use defaults */
         wspace,         /* working space vector */
         20);            /* number of elements (NOT size in bytes) */
    -
    -

    -
    +
    +

    +

    Option bits for pcre2_dfa_match() -
    -

    +

    +

    The unused bits of the options argument for pcre2_dfa_match() must be zero. The only bits that may be set are PCRE2_ANCHORED, PCRE2_COPY_MATCHED_SUBJECT, PCRE2_ENDANCHORED, PCRE2_NOTBOL, PCRE2_NOTEOL, @@ -4375,11 +4511,11 @@ before because data about the match so far is left in them after a partial match. There is more discussion of this facility in the pcre2partial documentation. -

    -
    +

    +

    Successful returns from pcre2_dfa_match() -
    -

    +

    +

    When pcre2_dfa_match() succeeds, it may have matched more than one substring in the subject. Note, however, that all the matches from one run of the function start at the same point in the subject. The shorter matches are @@ -4402,31 +4538,31 @@ the number of matched substrings. The offsets of the substrings are returned in the ovector, and can be extracted by number in the same way as for pcre2_match(), but the numbers bear no relation to any capture groups that may exist in the pattern, because DFA matching does not support capturing. -

    -

    +

    +

    Calls to the convenience functions that extract substrings by name return the error PCRE2_ERROR_DFA_UFUNC (unsupported function) if used after a DFA match. The convenience functions that extract substrings by number never return PCRE2_ERROR_NOSUBSTRING. -

    -

    +

    +

    The matched strings are stored in the ovector in reverse order of length; that is, the longest matching string is first. If there were too many matches to fit into the ovector, the yield of the function is zero, and the vector is filled with the longest matches. -

    -

    +

    +

    NOTE: PCRE2's "auto-possessification" optimization usually applies to character repeats at the end of a pattern (as well as internally). For example, the pattern "a\d+" is compiled as if it were "a\d++". For DFA matching, this means that only one possible match is found. If you really do want multiple matches in such cases, either use an ungreedy repeat such as "a\d+?" or set the PCRE2_NO_AUTO_POSSESS option when compiling. -

    -
    +

    +

    Error returns from pcre2_dfa_match() -
    -

    +

    +

    The pcre2_dfa_match() function returns a negative number when it fails. Many of the errors are the same as for pcre2_match(), as described above. @@ -4469,25 +4605,25 @@ When pcre2_dfa_match() is called with the PCRE2_DFA_RESTART option some plausibility checks are made on the contents of the workspace, which should contain data about the previous partial match. If any of these checks fail, this error is given. -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2build(3), pcre2callout(3), pcre2demo(3), pcre2matching(3), pcre2partial(3), pcre2posix(3), pcre2sample(3), pcre2unicode(3). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 26 December 2024 +

    +

    REVISION

    +

    +Last updated: 19 October 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2build.html b/doc/html/pcre2build.html index f4e127f..603e9ab 100644 --- a/doc/html/pcre2build.html +++ b/doc/html/pcre2build.html @@ -41,12 +41,12 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    BUILDING PCRE2
    -

    +

    BUILDING PCRE2

    +

    PCRE2 is distributed with a configure script that can be used to build -the library in Unix-like environments using the applications known as -Autotools. Also in the distribution are files to support building using -CMake instead of configure. The text file +the library in Unix-like environments using the Autotools applications. Also in +the distribution are files to support building using CMake instead of +configure. The text file README contains general information about building with Autotools (some of which is repeated below), and also has some comments about building on various operating @@ -58,23 +58,23 @@ hand") in the text file called You should consult this file as well as the README file if you are building in a non-Unix-like environment. -

    -
    PCRE2 BUILD-TIME OPTIONS
    -

    +

    +

    PCRE2 BUILD-TIME OPTIONS

    +

    The rest of this document describes the optional features of PCRE2 that can be selected when the library is compiled. It assumes use of the configure script, where the optional features are selected or deselected by providing options to configure before running the make command. However, the same options can be selected in both Unix-like and non-Unix-like environments if you are using CMake instead of configure to build PCRE2. -

    -

    +

    +

    If you are not using Autotools or CMake, option selection can be done by editing the config.h file, or by passing parameter settings to the compiler, as described in NON-AUTOTOOLS-BUILD. -

    -

    +

    +

    The complete list of options for configure (which includes the standard ones such as the selection of the installation directory) can be obtained by running @@ -87,9 +87,9 @@ works, --enable and --disable always come in pairs, so the complementary option always exists as well, but as it specifies the default, it is not described. Options that specify values have names that start with --with. At the end of a configure run, a summary of the configuration is output. -

    -
    BUILDING 8-BIT, 16-BIT AND 32-BIT LIBRARIES
    -

    +

    +

    BUILDING 8-BIT, 16-BIT AND 32-BIT LIBRARIES

    +

    By default, a library called libpcre2-8 is built, containing functions that take string arguments contained in arrays of bytes, interpreted either as single-byte characters, or UTF-8 strings. You can also build two other @@ -110,9 +110,9 @@ as well. At least one of the three libraries must be built. Note that the POSIX wrapper is for the 8-bit library only, and that pcre2grep is an 8-bit program. Neither of these are built if you select only the 16-bit or 32-bit libraries. -

    -
    BUILDING SHARED AND STATIC LIBRARIES
    -

    +

    +

    BUILDING SHARED AND STATIC LIBRARIES

    +

    The Autotools PCRE2 building process uses libtool to build both shared and static libraries by default. You can suppress an unwanted library by adding one of @@ -133,9 +133,9 @@ LDFLAGS=--static ./configure --disable-shared
    Note the two hyphens in --static. Of course, this works only if static versions of all the relevant libraries are available for linking. -

    -
    UNICODE AND UTF SUPPORT
    -

    +

    +

    UNICODE AND UTF SUPPORT

    +

    By default, PCRE2 is built with support for Unicode and UTF character strings. To build it without Unicode support, add

    @@ -144,44 +144,44 @@ To build it without Unicode support, add
     to the configure command. This setting applies to all three libraries. It
     is not possible to build one library with Unicode support and another without
     in the same configuration.
    -

    -

    +

    +

    Of itself, Unicode support does not make PCRE2 treat strings as UTF-8, UTF-16 or UTF-32. To do that, applications that use the library can set the PCRE2_UTF option when they call pcre2_compile() to compile a pattern. Alternatively, patterns may be started with (*UTF) unless the application has locked this out by setting PCRE2_NEVER_UTF. -

    -

    +

    +

    UTF support allows the libraries to process character code points up to 0x10ffff in the strings that they handle. Unicode support also gives access to the Unicode properties of characters, using pattern escapes such as \P, \p, and \X. Only the general category properties such as Lu and Nd, -script names, and some bi-directional properties are supported. Details are -given in the +script names, and some bi-directional and binary properties are supported. +Details are given in the pcre2pattern documentation. -

    -

    +

    +

    Pattern escapes such as \d and \w do not by default make use of Unicode properties. The application can request that they do by setting the PCRE2_UCP option. Unless the application has set PCRE2_NEVER_UCP, a pattern may also request this by starting with (*UCP). -

    -
    DISABLING THE USE OF \C
    -

    +

    +

    DISABLING THE USE OF \C

    +

    The \C escape sequence, which matches a single code unit, even in a UTF mode, can cause unpredictable behaviour because it may leave the current matching -point in the middle of a multi-code-unit character. The application can lock it -out by setting the PCRE2_NEVER_BACKSLASH_C option when calling +point in the middle of a multi-code-unit character. The application can lock +it out by setting the PCRE2_NEVER_BACKSLASH_C option when calling pcre2_compile(). There is also a build-time option

       --enable-never-backslash-C
     
    (note the upper case C) which locks out the use of \C entirely. -

    -
    JUST-IN-TIME COMPILER SUPPORT
    -

    +

    +

    JUST-IN-TIME COMPILER SUPPORT

    +

    Just-in-time (JIT) compiler support is included in the build by specifying

       --enable-jit
    @@ -208,9 +208,9 @@ documentation for a discussion of JIT usage. When JIT support is enabled,
       --disable-pcre2grep-jit
     
    to the configure command. -

    -
    NEWLINE RECOGNITION
    -

    +

    +

    NEWLINE RECOGNITION

    +

    By default, PCRE2 interprets the linefeed (LF) character as indicating the end of a line. This is the normal newline character on Unix-like systems. You can compile PCRE2 to use carriage return (CR) instead, by adding @@ -219,8 +219,8 @@ compile PCRE2 to use carriage return (CR) instead, by adding

    to the configure command. There is also an --enable-newline-is-lf option, which explicitly specifies linefeed as the newline character. -

    -

    +

    +

    Alternatively, you can specify that line endings are to be indicated by the two-character sequence CRLF (CR immediately followed by LF). If you want this, add @@ -244,14 +244,14 @@ separator, U+2028), and PS (paragraph separator, U+2029). The final option is --enable-newline-is-nul

  • which causes NUL (binary zero) to be set as the default line-ending character. -

    -

    +

    +

    Whatever default line ending convention is selected when PCRE2 is built can be overridden by applications that use the library. At build time it is recommended to use the standard for your operating system. -

    -
    WHAT \R MATCHES
    -

    +

    +

    WHAT \R MATCHES

    +

    By default, the sequence \R in a pattern matches any Unicode newline sequence, independently of what has been selected as the line ending sequence. If you specify @@ -261,9 +261,9 @@ specify the default is changed so that \R matches only CR, LF, or CRLF. Whatever is selected when PCRE2 is built can be overridden by applications that use the library. -

    -
    HANDLING VERY LARGE PATTERNS
    -

    +

    +

    HANDLING VERY LARGE PATTERNS

    +

    Within a compiled pattern, offset values are used to point from one part to another (for example, from an opening parenthesis to an alternation metacharacter). By default, in the 8-bit and 16-bit libraries, two-byte values @@ -280,9 +280,9 @@ to the configure command. The value given must be 2, 3, or 4. For the longer offsets slows down the operation of PCRE2 because it has to load additional data when handling them. For the 32-bit library the value is always 4 and cannot be overridden; the value of --with-link-size is ignored. -

    -
    LIMITING PCRE2 RESOURCE USAGE
    -

    +

    +

    LIMITING PCRE2 RESOURCE USAGE

    +

    The pcre2_match() function increments a counter each time it goes round its main loop. Putting a limit on this counter controls the amount of computing resource used by a single call to pcre2_match(). The limit can be changed @@ -296,8 +296,8 @@ setting such as to the configure command. This setting also applies to the pcre2_dfa_match() matching function, and to JIT matching (though the counting is done differently). -

    -

    +

    +

    The pcre2_match() function uses heap memory to record backtracking points. The more nested backtracking points there are (that is, the deeper the search tree), the more memory is needed. There is an upper limit, specified in @@ -314,8 +314,8 @@ interpretive matching in pcre2_match() and pcre2_dfa_match(), whic may also use the heap for internal workspace when processing complicated patterns. This limit does not apply when JIT (which has its own memory arrangements) is used. -

    -

    +

    +

    You can also explicitly limit the depth of nested backtracking in the pcre2_match() interpreter. This limit defaults to the value that is set for --with-match-limit. You can set a lower default limit by adding, for @@ -329,15 +329,15 @@ because the size of each backtracking "frame" depends on the number of capturing parentheses in a pattern, the amount of heap that is used before the limit is reached varies from pattern to pattern. This limit was more useful in versions before 10.30, where function recursion was used for backtracking. -

    -

    +

    +

    As well as applying to pcre2_match(), the depth limit also controls the depth of recursive function calls in pcre2_dfa_match(). These are used for lookaround assertions, atomic groups, and recursion within patterns. The limit does not apply to JIT matching. -

    -
    LIMITING VARIABLE-LENGTH LOOKBEHIND ASSERTIONS
    -

    +

    +

    LIMITING VARIABLE-LENGTH LOOKBEHIND ASSERTIONS

    +

    Lookbehind assertions in which one or more branches can match a variable number of characters are supported only if there is a maximum matching length for each top-level branch. There is a limit to this maximum that defaults to 255 @@ -349,9 +349,9 @@ The limit can be changed at runtime by calling pcre2_set_max_varlookbehind(). Lookbehind assertions in which every branch matches a fixed number of characters (not necessarily all the same) are not constrained by this limit. -

    -
    CREATING CHARACTER TABLES AT BUILD TIME
    -

    +

    +

    CREATING CHARACTER TABLES AT BUILD TIME

    +

    PCRE2 uses fixed tables for processing characters whose code points are less than 256. By default, PCRE2 is built with a set of tables that are distributed in the file src/pcre2_chartables.c.dist. These tables are for ASCII codes @@ -365,8 +365,8 @@ outputs the source for new set of tables, created in the default locale of your C run-time system. This method of replacing the tables does not work if you are cross compiling, because pcre2_dftables needs to be run on the local host and therefore not compiled with the cross compiler. -

    -

    +

    +

    If you need to create alternative tables when cross compiling, you will have to do so "by hand". There may also be other reasons for creating tables manually. To cause pcre2_dftables to be built on the local host, run a normal @@ -388,9 +388,9 @@ same way as tables created by calling pcre2_maketables(). The tables are just a string of bytes, independent of hardware characteristics such as endianness. This means they can be bundled with an application that runs in different environments, to ensure consistent behaviour. -

    -
    USING EBCDIC CODE
    -

    +

    +

    USING EBCDIC CODE

    +

    PCRE2 assumes by default that it will run in an environment where the character code is ASCII or Unicode, which is a superset of ASCII. This is the case for most computer operating systems. PCRE2 can, however, be compiled to run in an @@ -398,34 +398,53 @@ most computer operating systems. PCRE2 can, however, be compiled to run in an

       --enable-ebcdic --disable-unicode
     
    -to the configure command. This setting implies ---enable-rebuild-chartables. You should only use it if you know that you are in -an EBCDIC environment (for example, an IBM mainframe operating system). -

    -

    -It is not possible to support both EBCDIC and UTF-8 codes in the same version -of the library. Consequently, --enable-unicode and --enable-ebcdic are mutually -exclusive. -

    -

    +to the configure command. You should only use it if you know that you are +in an EBCDIC environment (for example, an IBM mainframe operating system). +

    +

    +This setting implies --enable-rebuild-chartables, in order to ensure that you +have the correct default character tables for your system's codepage. There is +an exception when you set --enable-ebcdic-ignoring-compiler (see below), which +allows using a default set of EBCDIC 1047 character tables rather than forcing +use of --enable-rebuild-chartables. +

    +

    +It is not supported to enable both EBCDIC input and either ASCII or UTF-8/16/32 +in the same build of the library. When PCRE2 is built with EBCDIC support, it +always operates in EBCDIC, and consequently --enable-unicode and --enable-ebcdic +are mutually exclusive. +

    +

    The EBCDIC character that corresponds to an ASCII LF is assumed to have the value 0x15 by default. However, in some EBCDIC environments, 0x25 is used. In such an environment you should use

       --enable-ebcdic-nl25
     
    -as well as, or instead of, --enable-ebcdic. The EBCDIC character for CR has the -same value as in ASCII, namely, 0x0d. Whichever of 0x15 and 0x25 is not -chosen as LF is made to correspond to the Unicode NEL character (which, in -Unicode, is 0x85). -

    -

    +(which implies --enable-ebcdic). The EBCDIC character for CR has the same value +as in ASCII, namely, 0x0d. Whichever of 0x15 and 0x25 is not chosen as LF +is made to correspond to the Unicode NEL character (which, in Unicode, is 0x85). +

    +

    The options that select newline behaviour, such as --enable-newline-is-cr, and equivalent run-time options, refer to these character values in an EBCDIC environment. -

    -
    PCRE2GREP SUPPORT FOR EXTERNAL SCRIPTS
    -

    +

    +

    +On systems requiring an EBCDIC build of PCRE2, the compiler should be set to use +the correct codepage, so that C character literals such as 'z' use the correct +numeric value for whichever EBCDIC codpage is in use. (PCRE2 cannot support +multiple EBCDIC codepages dynamically.) However, if this not possible, then you +can use +

    +  --enable-ebcdic-ignoring-compiler
    +
    +in order to disregard the compiler's codepage, and instead force PCRE2 to use +numeric constants corresponding to the EBCDIC 1047 codepage instead. This can be +used to build (or test) EBCDIC support on an ASCII/UTF-8 system such as Linux. +

    +

    PCRE2GREP SUPPORT FOR EXTERNAL SCRIPTS

    +

    By default pcre2grep supports the use of callouts with string arguments within the patterns it is matching. There are two kinds: one that generates output using local code, and another that calls an external program or script. @@ -435,9 +454,9 @@ used, all callouts are completely ignored. For more details of pcre2grep callouts, see the pcre2grep documentation. -

    -
    PCRE2GREP OPTIONS FOR COMPRESSED FILE SUPPORT
    -

    +

    +

    PCRE2GREP OPTIONS FOR COMPRESSED FILE SUPPORT

    +

    By default, pcre2grep reads all files as plain text. You can build it so that it recognizes files whose names end in .gz or .bz2, and reads them with libz or libbz2, respectively, by adding one or both of @@ -448,9 +467,9 @@ them with libz or libbz2, respectively, by adding one or both of to the configure command. These options naturally require that the relevant libraries are installed on your system. Configuration will fail if they are not. -

    -
    PCRE2GREP BUFFER SIZE
    -

    +

    +

    PCRE2GREP BUFFER SIZE

    +

    pcre2grep uses an internal buffer to hold a "window" on the file it is scanning, in order to be able to output "before" and "after" lines when it finds a match. The default starting size of the buffer is 20KiB. The buffer @@ -466,9 +485,9 @@ default parameter values by adding, for example, to the configure command. The caller of pcre2grep can override these values by using --buffer-size and --max-buffer-size on the command line. -

    -
    PCRE2TEST OPTION FOR LIBREADLINE SUPPORT
    -

    +

    +

    PCRE2TEST OPTION FOR LIBREADLINE SUPPORT

    +

    If you add one of

       --enable-pcre2test-libreadline
    @@ -481,8 +500,8 @@ line-editing and history facilities. Note that libreadline is
     GPL-licensed, so if you distribute a binary of pcre2test linked in this
     way, there may be licensing issues. These can be avoided by linking instead
     with libedit, which has a BSD licence.
    -

    -

    +

    +

    Setting --enable-pcre2test-libreadline causes the -lreadline option to be added to the pcre2test build. In many operating environments with a system-installed readline library this is sufficient. However, in some @@ -497,21 +516,21 @@ use), some extra configuration may be necessary. The INSTALL file for If your environment has not been set up so that an appropriate library is automatically included, you may need to add something like

    -  LIBS="-ncurses"
    +  LIBS="-lncurses"
     
    immediately before the configure command. -

    -
    INCLUDING DEBUGGING CODE
    -

    +

    +

    INCLUDING DEBUGGING CODE

    +

    If you add

       --enable-debug
     
    to the configure command, additional debugging code is included in the build. This feature is intended for use by the PCRE2 maintainers. -

    -
    DEBUGGING WITH VALGRIND SUPPORT
    -

    +

    +

    DEBUGGING WITH VALGRIND SUPPORT

    +

    If you add

       --enable-valgrind
    @@ -519,9 +538,9 @@ If you add
     to the configure command, PCRE2 will use valgrind annotations to mark
     certain memory regions as unaddressable. This allows it to detect invalid
     memory accesses, and is mostly useful for debugging PCRE2 itself.
    -

    -
    CODE COVERAGE REPORTING
    -

    +

    +

    CODE COVERAGE REPORTING

    +

    If your C compiler is gcc, you can build a version of PCRE2 that can generate a code coverage report for its test suite. To enable this, you must install lcov version 1.6 or above. Then specify @@ -529,8 +548,8 @@ code coverage report for its test suite. To enable this, you must install --enable-coverage

    to the configure command and build PCRE2 in the usual way. -

    -

    +

    +

    Note that using ccache (a caching C compiler) is incompatible with code coverage reporting. If you have configured ccache to run automatically on your system, you must set the environment variable @@ -538,8 +557,8 @@ on your system, you must set the environment variable CCACHE_DISABLE=1

    before running make to build PCRE2, so that ccache is not used. -

    -

    +

    +

    When --enable-coverage is used, the following addition targets are added to the Makefile:

    @@ -576,9 +595,9 @@ created at compile time (*.gcno).
     This cleans all coverage data including the generated coverage report. For more
     information about code coverage, see the gcov and lcov
     documentation.
    -

    -
    DISABLING THE Z AND T FORMATTING MODIFIERS
    -

    +

    +

    DISABLING THE Z AND T FORMATTING MODIFIERS

    +

    The C99 standard defines formatting modifiers z and t for size_t and ptrdiff_t values, respectively. By default, PCRE2 uses these modifiers in environments other than old versions of Microsoft Visual Studio when @@ -591,9 +610,9 @@ support these modifiers. If

    is specified, no use is made of the z or t modifiers. Instead of %td or %zu, a suitable format is used depending in the size of long for the platform. -

    -
    SUPPORT FOR FUZZERS
    -

    +

    +

    SUPPORT FOR FUZZERS

    +

    There is a special option for use by people who want to run fuzzing tests on PCRE2:

    @@ -606,8 +625,8 @@ a pointer to a string and the length of the string. When called, this function
     tries to compile the string as a pattern, and if that succeeds, to match it.
     This is done both with no options and with some random options bits that are
     generated from the string.
    -

    -

    +

    +

    Setting --enable-fuzz-support also causes a binary called pcre2fuzzcheck to be created. This is normally run under valgrind or used when PCRE2 is compiled with address sanitizing enabled. It calls the fuzzing function and @@ -615,9 +634,9 @@ outputs information about what it is doing. The input strings are specified by arguments: if an argument starts with "=" the rest of it is a literal input string. Otherwise, it is assumed to be a file name, and the contents of the file are the test string. -

    -
    OBSOLETE OPTION
    -

    +

    +

    OBSOLETE OPTION

    +

    In versions of PCRE2 prior to 10.30, there were two ways of handling backtracking in the pcre2_match() function. The default was to use the system stack, but if @@ -627,23 +646,23 @@ system stack, but if was set, memory on the heap was used. From release 10.30 onwards this has changed (the stack is no longer used) and this option now does nothing except give a warning. -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2api(3), pcre2-config(3). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 16 April 2024 +

    +

    REVISION

    +

    +Last updated: 17 October 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2callout.html b/doc/html/pcre2callout.html index cdb65ad..62885a5 100644 --- a/doc/html/pcre2callout.html +++ b/doc/html/pcre2callout.html @@ -22,36 +22,36 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    SYNOPSIS
    -

    +

    SYNOPSIS

    +

    #include <pcre2.h> -

    -

    +

    +

    int (*pcre2_callout)(pcre2_callout_block *, void *);

    int pcre2_callout_enumerate(const pcre2_code *code, int (*callback)(pcre2_callout_enumerate_block *, void *), void *user_data); -

    -
    DESCRIPTION
    -

    +

    +

    DESCRIPTION

    +

    PCRE2 provides a feature called "callout", which is a means of temporarily passing control to the caller of PCRE2 in the middle of pattern matching. The caller of PCRE2 provides an external function by putting its entry point in a match context (see pcre2_set_callout() in the pcre2api documentation). -

    -

    +

    +

    When using the pcre2_substitute() function, an additional callout feature is available. This does a callout after each change to the subject string and is described in the pcre2api documentation; the rest of this document is concerned with callouts during pattern matching. -

    -

    +

    +

    Within a regular expression, (?C<arg>) indicates a point at which the external function is to be called. Different callout points can be identified by putting a number less than 256 after the letter C. The default value is zero. @@ -91,25 +91,25 @@ condition. Such a callout may also be inserted explicitly, for example:

  • This applies only to assertion conditions (because they are themselves independent groups). -

    -

    +

    +

    Callouts can be useful for tracking the progress of pattern matching. The pcre2test program has a pattern qualifier (/auto_callout) that sets automatic callouts. When any callouts are present, the output from pcre2test indicates how the pattern is being matched. This is useful information when you are trying to optimize the performance of a particular pattern. -

    -
    MISSING CALLOUTS
    -

    +

    +

    MISSING CALLOUTS

    +

    You should be aware that, because of optimizations in the way PCRE2 compiles and matches patterns, callouts sometimes do not happen exactly as you might expect. -

    -
    +

    +

    Auto-possessification -
    -

    +

    +

    At compile time, PCRE2 "auto-possessifies" repeated items when it knows that what follows cannot be part of the repeat. For example, a+[bc] is compiled as if it were a++[bc]. The pcre2test output when this pattern is compiled @@ -137,25 +137,25 @@ the pattern with (*NO_AUTO_POSSESS). In this case, the output changes to this: This time, when matching [bc] fails, the matcher backtracks into a+ and tries again, repeatedly, until a+ itself fails. -

    -
    +

    +

    Automatic .* anchoring -
    -

    +

    +

    By default, an optimization is applied when .* is the first significant item in a pattern. If PCRE2_DOTALL is set, so that the dot can match any character, the pattern is automatically anchored. If PCRE2_DOTALL is not set, a match can start only after an internal newline or at the beginning of the subject, and pcre2_compile() remembers this. If a pattern has more than one top-level branch, automatic anchoring occurs if all branches are anchorable. -

    -

    +

    +

    This optimization is disabled, however, if .* is in an atomic group or if there is a backreference to the capture group in which it appears. It is also disabled if the pattern contains (*PRUNE) or (*SKIP). However, the presence of callouts does not affect it. -

    -

    +

    +

    For example, if the pattern .*\d is compiled with PCRE2_AUTO_CALLOUT and applied to the string "aa", the pcre2test output is:

    @@ -184,11 +184,11 @@ pattern with (*NO_DOTSTAR_ANCHOR). In this case, the output changes to:
     This shows more match attempts, starting at the second subject character.
     Another optimization, described in the next section, means that there is no
     subsequent attempt to match with an empty subject.
    -

    -
    +

    +

    Other optimizations -
    -

    +

    +

    Other optimizations that provide fast "no match" results also affect callouts. For example, if the pattern is

    @@ -198,21 +198,21 @@ PCRE2 knows that any matching string must contain the letter "d". If the
     subject string is "abyz", the lack of "d" means that matching doesn't ever
     start, and the callout is never reached. However, with "abyd", though the
     result is still no match, the callout is obeyed.
    -

    -

    +

    +

    For most patterns PCRE2 also knows the minimum length of a matching string, and will immediately give a "no match" return without actually running a match if the subject is not long enough, or, for unanchored patterns, if it has been scanned far enough. -

    -

    +

    +

    You can disable these optimizations by passing the PCRE2_NO_START_OPTIMIZE option to pcre2_compile(), or by starting the pattern with (*NO_START_OPT). This slows down the matching process, but does ensure that callouts such as the example above are obeyed. -

    -
    THE CALLOUT INTERFACE
    -

    +

    +

    THE CALLOUT INTERFACE

    +

    During matching, when PCRE2 reaches a callout point, if an external function is provided in the match context, it is called. This applies to both normal, DFA, and JIT matching. The first argument to the callout function is a pointer @@ -247,20 +247,20 @@ application that might use an earlier release of PCRE2, you should check the version number before accessing any of these fields. The version number will increase in future if more fields are added, but the intention is never to remove any of the existing fields. -

    -
    +

    +

    Fields for numerical callouts -
    -

    +

    +

    For a numerical callout, callout_string is NULL, and callout_number contains the number of the callout, in the range 0-255. This is the number that follows (?C for callouts that part of the pattern; it is 255 for automatically generated callouts. -

    -
    +

    +

    Fields for string callouts -
    -

    +

    +

    For callouts with string arguments, callout_number is always zero, and callout_string points to the string that is contained within the compiled pattern. Its length is given by callout_string_length. Duplicated ending @@ -271,34 +271,34 @@ string, but is not included in the length. The delimiter that was used to start the string is also stored within the pattern, immediately before the string itself. You can access this delimiter as callout_string[-1] if you need it. -

    -

    +

    +

    The callout_string_offset field is the code unit offset to the start of the callout argument string within the original pattern string. This is provided for the benefit of applications such as script languages that might need to report errors in the callout string within the pattern. -

    -
    +

    +

    Fields for all callouts -
    -

    +

    +

    The remaining fields in the callout block are the same for both kinds of callout. -

    -

    +

    +

    The offset_vector field is a pointer to a vector of capturing offsets (the "ovector"). You may read the elements in this vector, but you must not change any of them. -

    -

    +

    +

    For calls to pcre2_match(), the offset_vector field is not (since release 10.30) a pointer to the actual ovector that was passed to the matching function in the match data block. Instead it points to an internal ovector of a size large enough to hold all possible captured substrings in the pattern. Note that whenever a recursion or subroutine call within a pattern completes, the capturing state is reset to what it was before. -

    -

    +

    +

    The capture_last field contains the number of the most recently captured substring, and the capture_top field contains one more than the number of the highest numbered captured substring so far. If no substrings have yet been @@ -306,8 +306,8 @@ captured, the value of capture_last is 0 and the value of capture_top is 1. The values of these fields do not always differ by one; for example, when the callout in the pattern ((a)(b))(?C2) is taken, capture_last is 1 but capture_top is 4. -

    -

    +

    +

    The contents of ovector[2] to ovector[<capture_top>*2-1] can be inspected in order to extract substrings that have been matched so far, in the same way as extracting substrings after a match has completed. The values in ovector[0] and @@ -315,8 +315,8 @@ ovector[1] are always PCRE2_UNSET because the match is by definition not complete. Substrings that have not been captured but whose numbers are less than capture_top also have both of their ovector slots set to PCRE2_UNSET. -

    -

    +

    +

    For DFA matching, the offset_vector field points to the ovector that was passed to the matching function in the match data block for callouts at the top level, but to an internal ovector during the processing of pattern recursions, @@ -324,28 +324,28 @@ lookarounds, and atomic groups. However, these ovectors hold no useful information because pcre2_dfa_match() does not support substring capturing. The value of capture_top is always 1 and the value of capture_last is always 0 for DFA matching. -

    -

    +

    +

    The subject and subject_length fields contain copies of the values that were passed to the matching function. -

    -

    +

    +

    The start_match field normally contains the offset within the subject at which the current match attempt started. However, if the escape sequence \K has been encountered, this value is changed to reflect the modified starting point. If the pattern is not anchored, the callout function may be called several times from the same point in the pattern for different starting points in the subject. -

    -

    +

    +

    The current_position field contains the offset within the subject of the current match pointer. -

    -

    +

    +

    The pattern_position field contains the offset in the pattern string to the next item to be matched. -

    -

    +

    +

    The next_item_length field contains the length of the next item to be processed in the pattern string. When the callout is at the end of the pattern, the length is zero. When the callout precedes an opening parenthesis, the @@ -356,22 +356,22 @@ is followed by a quantifier, in which case its length is included. (This changed in release 10.23. In earlier releases, before an opening parenthesis the length was that of the entire group, and before an alternation bar or a closing parenthesis the length was zero.) -

    -

    +

    +

    The pattern_position and next_item_length fields are intended to help in distinguishing between different automatic callouts, which all have the same callout number. However, they are set for all callouts, and are used by pcre2test to show the next item to be matched when displaying callout information. -

    -

    +

    +

    In callouts from pcre2_match() the mark field contains a pointer to the zero-terminated name of the most recently passed (*MARK), (*PRUNE), or (*THEN) item in the match, or NULL if no such items have been passed. Instances of (*PRUNE) or (*THEN) without a name do not obliterate a previous (*MARK). In callouts from the DFA matching function this field always contains NULL. -

    -

    +

    +

    The callout_flags field is always zero in callouts from pcre2_dfa_match() or when JIT is being used. When pcre2_match() without JIT is used, the following bits may be set: @@ -386,13 +386,13 @@ starting position in the subject. This is set if there has been a matching backtrack since the previous callout, or since the start of matching if this is the first callout from a pcre2_match() run. -

    -

    +

    +

    Both bits are set when a backtrack has caused a "bumpalong" to a new starting position in the subject. Output from pcre2test does not indicate the presence of these bits unless the callout_extra modifier is set. -

    -

    +

    +

    The information in the callout_flags field is provided so that applications can track and tell their users how matching with backtracking is done. This can be useful when trying to optimize patterns, or just to @@ -400,24 +400,24 @@ understand how PCRE2 works. There is no support in pcre2_dfa_match() because there is no backtracking in DFA matching, and there is no support in JIT because JIT is all about maximimizing matching performance. In both these cases the callout_flags field is always zero. -

    -
    RETURN VALUES FROM CALLOUTS
    -

    +

    +

    RETURN VALUES FROM CALLOUTS

    +

    The external callout function returns an integer to PCRE2. If the value is zero, matching proceeds as normal. If the value is greater than zero, matching fails at the current point, but the testing of other matching possibilities goes ahead, just as if a lookahead assertion had failed. If the value is less than zero, the match is abandoned, and the matching function returns the negative value. -

    -

    +

    +

    Negative values should normally be chosen from the set of PCRE2_ERROR_xxx values. In particular, PCRE2_ERROR_NOMATCH forces a standard "no match" failure. The error number PCRE2_ERROR_CALLOUT is reserved for use by callout functions; it will never be used by PCRE2 itself. -

    -
    CALLOUT ENUMERATION
    -

    +

    +

    CALLOUT ENUMERATION

    +

    int pcre2_callout_enumerate(const pcre2_code *code, int (*callback)(pcre2_callout_enumerate_block *, void *), void *user_data); @@ -446,32 +446,32 @@ added to the block. The remaining fields are the same as their namesakes in the pcre2_callout block that is used for callouts during matching, as described above. -

    -

    +

    +

    Note that the value of pattern_position is unique for each callout. However, if a callout occurs inside a group that is quantified with a non-zero minimum or a fixed maximum, the group is replicated inside the compiled pattern. For example, a pattern such as /(a){2}/ is compiled as if it were /(a)(a)/. This means that the callout will be enumerated more than once, but with the same value for pattern_position in each case. -

    -

    +

    +

    The callback function should normally return zero. If it returns a non-zero value, scanning the pattern stops, and that value is returned from pcre2_callout_enumerate(). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 19 January 2024 +

    +

    REVISION

    +

    +Last updated: 26 February 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2compat.html b/doc/html/pcre2compat.html index 5f7e280..3700abf 100644 --- a/doc/html/pcre2compat.html +++ b/doc/html/pcre2compat.html @@ -12,16 +12,16 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    DIFFERENCES BETWEEN PCRE2 AND PERL -
    -

    +

    +

    This document describes some of the known differences in the ways that PCRE2 and Perl handle regular expressions. The differences described here are with respect to Perl version 5.38.0, but as both Perl and PCRE2 are continually changing, the information may at times be out of date. -

    -

    +

    +

    1. When PCRE2_DOTALL (equivalent to Perl's /s qualifier) is not set, the behaviour of the '.' metacharacter differs from Perl. In PCRE2, '.' matches the next character unless it is the start of a newline sequence. This means that, @@ -29,14 +29,14 @@ if the newline setting is CR, CRLF, or NUL, '.' will match the code point LF (0x0A) in ASCII/Unicode environments, and NL (either 0x15 or 0x25) when using EBCDIC. In Perl, '.' appears never to match LF, even when 0x0A is not a newline indicator. -

    -

    +

    +

    2. PCRE2 has only a subset of Perl's Unicode support. Details of what it does have are given in the pcre2unicode page. -

    -

    +

    +

    3. Like Perl, PCRE2 allows repeat quantifiers on parenthesized assertions, but they do not mean what you might think. For example, (?!a){3} does not assert that the next three characters are not "a". It just asserts that the next @@ -44,19 +44,23 @@ character is not "a" three times (in principle; PCRE2 optimizes this to run the assertion just once). Perl allows some repeat quantifiers on other assertions, for example, \b* , but these do not seem to have any use. PCRE2 does not allow any kind of quantifier on non-lookaround assertions. -

    -

    +

    +

    4. If a braced quantifier such as {1,2} appears where there is nothing to repeat (for example, at the start of a branch), PCRE2 raises an error whereas -Perl treats the quantifier characters as literal. -

    -

    +Perl treats the quantifier characters as literal. When a braced quantifier +(...){min,max} has min > max, Perl treats it as an item which fails to match +any portion of the subject (as no number of repetitions can meet the +condition), and additionally issues a warning when in warning mode. PCRE2 has +no warning features, so it gives an error in this case. +

    +

    5. Capture groups that occur inside negative lookaround assertions are counted, but their entries in the offsets vector are set only when a negative assertion is a condition that has a matching branch (that is, the condition is false). Perl may set such capture groups in other circumstances. -

    -

    +

    +

    6. The following Perl escape sequences are not supported: \F, \l, \L, \u, \U, and \N when followed by a character name. \N on its own, matching a non-newline character, and \N{U+dd..}, matching a Unicode code point, are @@ -66,8 +70,8 @@ matching engine. If any of these are encountered by PCRE2, an error is generated by default. However, if either of the PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX options is set, \U and \u are interpreted as ECMAScript interprets them. -

    -

    +

    +

    7. The Perl escape sequences \p, \P, and \X are supported only if PCRE2 is built with Unicode support (the default). The properties that can be tested with \p and \P are limited to the general category properties such as Lu and @@ -79,8 +83,8 @@ the documentation for details. The long synonyms for property names that Perl supports (such as \p{Letter}) are not supported by PCRE2, nor is it permitted to prefix any of these properties with "Is". -

    -

    +

    +

    8. PCRE2 supports the \Q...\E escape for quoting substrings. Characters in between are treated as literals. However, this is slightly different from Perl in that $ and @ are also handled as literals inside the quotes. In Perl, @@ -105,20 +109,20 @@ recognize the sequence as a quantifier. Perl recognizes a quantifier if (redundantly) either of the numbers is inside \Q...\E, but not if the separating comma is. When not recognized as a quantifier a sequence such as {\Q1\E,2} is treated as the literal string "{1,2}". -

    -

    +

    +

    9. Fairly obviously, PCRE2 does not support the (?{code}) and (??{code}) constructions. However, PCRE2 does have a "callout" feature, which allows an external function to be called during pattern matching. See the pcre2callout documentation for details. -

    -

    +

    +

    10. Subroutine calls (whether recursive or not) were treated as atomic groups up to PCRE2 release 10.23, but from release 10.30 this changed, and backtracking into subroutine calls is now supported, as in Perl. -

    -

    +

    +

    11. In PCRE2, if any of the backtracking control verbs are used in a group that is called as a subroutine (whether or not recursively), their effect is confined to that group; it does not extend to the surrounding pattern. This is @@ -128,21 +132,21 @@ the group does not contain any | characters. Note that such groups are processed as anchored at the point where they are tested. PCRE2 also confines all control verbs within atomic assertions, again including (*THEN) in assertions with only one branch. -

    -

    +

    +

    12. If a pattern contains more than one backtracking control verb, the first one that is backtracked onto acts. For example, in the pattern A(*COMMIT)B(*PRUNE)C a failure in B triggers (*COMMIT), but a failure in C triggers (*PRUNE). Perl's behaviour is more complex; in many cases it is the same as PCRE2, but there are cases where it differs. -

    -

    +

    +

    13. There are some differences that are concerned with the settings of captured strings when part of a pattern is repeated. For example, matching "aba" against the pattern /^(a(b)?)+$/ in Perl leaves $2 unset, but in PCRE2 it is set to "b". -

    -

    +

    +

    14. PCRE2's handling of duplicate capture group numbers and names is not as general as Perl's. This is a consequence of the fact the PCRE2 works internally just with numbers, using an external table to translate between numbers and @@ -151,35 +155,35 @@ capture groups have the same number but different names, is not supported, and causes an error at compile time. If it were allowed, it would not be possible to distinguish which group matched, because both names map to capture group number 1. To avoid this confusing situation, an error is given at compile time. -

    -

    +

    +

    15. Perl used to recognize comments in some places that PCRE2 does not, for example, between the ( and ? at the start of a group. If the /x modifier is set, Perl allowed white space between ( and ? though the latest Perls give an error (for a while it was just deprecated). There may still be some cases where Perl behaves differently. -

    -

    +

    +

    16. Perl, when in warning mode, gives warnings for character classes such as [A-\d] or [a-[:digit:]]. It then treats the hyphens as literals. PCRE2 has no warning features, so it gives an error in these cases because they are almost certainly user mistakes. -

    -

    +

    +

    17. In PCRE2, until release 10.45, the upper/lower case character properties Lu and Ll were not affected when case-independent matching was specified. Perl has changed in this respect, and PCRE2 has now changed to match. When caseless matching is in force, Lu, Ll, and Lt (title case) are all treated as Lc (cased letter). -

    -

    +

    +

    18. From release 5.32.0, Perl locks out the use of \K in lookaround assertions. From release 10.38 PCRE2 does the same by default. However, there is an option for re-enabling the previous behaviour. When this option is set, \K is acted on when it occurs in positive assertions, but is ignored in negative assertions. -

    -

    +

    +

    19. PCRE2 provides some extensions to the Perl regular expression facilities. Perl 5.10 included new features that were not in earlier versions of Perl, some of which (such as named parentheses) were in PCRE2 for some time before. This @@ -218,7 +222,7 @@ variable interpolation, but not general hooks on every match. (h) The partial matching facility is PCRE2-specific.

    -(i) The alternative matching function (pcre2_dfa_match() matches in a +(i) The alternative matching function (pcre2_dfa_match()) matches in a different way and is not Perl-compatible.

    @@ -242,55 +246,55 @@ numbering at all for conditions.
    (m) The scan substring assertion (syntax (*scs:(n)...)) is a PCRE2 extension that is not available in Perl. -

    -

    +

    +

    20. Perl has different limits than PCRE2. See the -pcre2limit +pcre2limits documentation for details. Perl went with 5.10 from recursion to iteration keeping the intermediate matches on the heap, which is ~10% slower but does not fall into any stack-overflow limit. PCRE2 made a similar change at release 10.30, and also has many build-time and run-time customizable limits. -

    -

    +

    +

    21. Unlike Perl, PCRE2 doesn't have character set modifiers and specially no way to set characters by context just like Perl's "/d". A regular expression using PCRE2_UTF and PCRE2_UCP will use similar rules to Perl's "/u"; something closer to "/a" could be selected by adding other PCRE2_EXTRA_ASCII* options on top. -

    -

    +

    +

    22. Some recursive patterns that Perl diagnoses as infinite recursions can be handled by PCRE2, either by the interpreter or the JIT. An example is /(?:|(?0)abcd)(?(R)|\z)/, which matches a sequence of any number of repeated "abcd" substrings at the end of the subject. -

    -

    +

    +

    23. Both PCRE2 and Perl error when \x{ escapes are invalid, but Perl tries to recover and prints a warning if the problem was that an invalid hexadecimal -digit was found, since PCRE2 doesn't have warnings it returns an error instead. +digit was found. Since PCRE2 doesn't have warnings it returns an error instead. Additionally, Perl accepts \x{} and generates NUL unlike PCRE2. -

    -

    +

    +

    24. From release 10.45, PCRE2 gives an error if \x is not followed by a hexadecimal digit or a curly bracket. It used to interpret this as the NUL character. Perl still generates NUL, but warns when in warning mode in most cases. -

    -
    +

    +

    AUTHOR -
    -

    +

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    +

    +

    REVISION -
    -

    -Last updated: 02 October 2024 +

    +

    +Last updated: 02 June 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2convert.html b/doc/html/pcre2convert.html index 57e8989..8d57478 100644 --- a/doc/html/pcre2convert.html +++ b/doc/html/pcre2convert.html @@ -21,15 +21,15 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    EXPERIMENTAL PATTERN CONVERSION FUNCTIONS
    -

    +

    EXPERIMENTAL PATTERN CONVERSION FUNCTIONS

    +

    This document describes a set of functions that can be used to convert "foreign" patterns into PCRE2 regular expressions. This facility is currently experimental, and may be changed in future releases. Two kinds of pattern, globs and POSIX patterns, are supported. -

    -
    THE CONVERT CONTEXT
    -

    +

    +

    THE CONVERT CONTEXT

    +

    pcre2_convert_context *pcre2_convert_context_create( pcre2_general_context *gcontext);
    @@ -55,21 +55,21 @@ you want to override the defaults. There are the usual create, copy, and free functions. If custom memory management functions are set in a general context that is passed to pcre2_convert_context_create(), they are used for all memory management within the conversion functions. -

    -

    +

    +

    There are only two parameters in the convert context at present. Both apply only to glob conversions. The escape character defaults to grave accent under Windows, otherwise backslash. It can be set to zero, meaning no escape character, or to any punctuation character with a code point less than 256. The separator character defaults to backslash under Windows, otherwise forward slash. It can be set to forward slash, backslash, or dot. -

    -

    +

    +

    The two setting functions return zero on success, or PCRE2_ERROR_BADDATA if their second argument is invalid. -

    -
    THE CONVERSION FUNCTION
    -

    +

    +

    THE CONVERSION FUNCTION

    +

    int pcre2_pattern_convert(PCRE2_SPTR pattern, PCRE2_SIZE length, uint32_t options, PCRE2_UCHAR **buffer, PCRE2_SIZE *blength, pcre2_convert_context *cvcontext); @@ -94,94 +94,94 @@ set to define the type of conversion that is required:

  • Details of the conversions are given below. The buffer and blength arguments define how the output is handled: -

    -

    +

    +

    If buffer is NULL, the function just returns the length of the converted pattern via blength. This is one less than the length of buffer needed, because a terminating zero is always added to the output. -

    -

    +

    +

    If buffer points to a NULL pointer, an output buffer is obtained using the allocator in the context or malloc() if no context is supplied. A pointer to this buffer is placed in the variable to which buffer points. When no longer needed the output buffer must be freed by calling pcre2_converted_pattern_free(). If this function is called with a NULL argument, it returns immediately without doing anything. -

    -

    +

    +

    If buffer points to a non-NULL pointer, blength must be set to the actual length of the buffer provided (in code units). -

    -

    +

    +

    In all cases, after successful conversion, the variable pointed to by blength is updated to the length actually used (in code units), excluding the terminating zero that is always added. -

    -

    +

    +

    If an error occurs, the length (via blength) is set to the offset within the input pattern where the error was detected. Only gross syntax errors are caught; there are plenty of errors that will get passed on for pcre2_compile() to discover. -

    -

    +

    +

    The return from pcre2_pattern_convert() is zero on success or a non-zero PCRE2 error code. Note that PCRE2 error codes may be positive or negative: pcre2_compile() uses mostly positive codes and pcre2_match() negative ones; pcre2_convert() uses existing codes of both kinds. A textual error message can be obtained by calling pcre2_get_error_message(). -

    -
    CONVERTING GLOBS
    -

    +

    +

    CONVERTING GLOBS

    +

    Globs are used to match file names, and consequently have the concept of a "path separator", which defaults to backslash under Windows and forward slash otherwise. If PCRE2_CONVERT_GLOB is set, the wildcards * and ? are not permitted to match separator characters, but the double-star (**) feature (which does match separators) is supported. -

    -

    +

    +

    PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR matches globs with wildcards allowed to match separator characters. PCRE2_CONVERT_GLOB_NO_STARSTAR matches globs with the double-star feature disabled. These options may be given together. -

    -
    CONVERTING POSIX PATTERNS
    -

    +

    +

    CONVERTING POSIX PATTERNS

    +

    POSIX defines two kinds of regular expression pattern: basic and extended. These can be processed by setting PCRE2_CONVERT_POSIX_BASIC or PCRE2_CONVERT_POSIX_EXTENDED, respectively. -

    -

    +

    +

    In POSIX patterns, backslash is not special in a character class. Unmatched closing parentheses are treated as literals. -

    -

    +

    +

    In basic patterns, ? + | {} and () must be escaped to be recognized as metacharacters outside a character class. If the first character in the pattern is * it is treated as a literal. ^ is a metacharacter only at the start of a branch. -

    -

    +

    +

    In extended patterns, a backslash not in a character class always makes the next character literal, whatever it is. There are no backreferences. -

    -

    +

    +

    Note: POSIX mandates that the longest possible match at the first matching position must be found. This is not what pcre2_match() does; it yields the first match that is found. An application can use pcre2_dfa_match() to find the longest match, but that does not support backreferences (but then neither do POSIX extended patterns). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    +

    +

    REVISION

    +

    Last updated: 14 November 2023
    Copyright © 1997-2018 University of Cambridge. diff --git a/doc/html/pcre2demo.html b/doc/html/pcre2demo.html index 1cb7e0a..37525fd 100644 --- a/doc/html/pcre2demo.html +++ b/doc/html/pcre2demo.html @@ -12,10 +12,10 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SOURCE CODE -
    -
    +

    +
     /*************************************************
     *           PCRE2 DEMONSTRATION PROGRAM          *
     *************************************************/
    @@ -91,36 +91,38 @@ PCRE2_SPTR pattern;     /* PCRE2_SPTR is a pointer to unsigned code units of */
     PCRE2_SPTR subject;     /* the appropriate width (in this case, 8 bits). */
     PCRE2_SPTR name_table;
     
    -int crlf_is_newline;
     int errornumber;
    -int find_all;
    +int find_all, caseless_match;
     int i;
     int rc;
    -int utf8;
     
    -uint32_t option_bits;
     uint32_t namecount;
     uint32_t name_entry_size;
    -uint32_t newline;
     
     PCRE2_SIZE erroroffset;
     PCRE2_SIZE *ovector;
    +PCRE2_SIZE ovector_last[2];
     PCRE2_SIZE subject_length;
     
     pcre2_match_data *match_data;
     
     
     /**************************************************************************
    -* First, sort out the command line. There is only one possible option at  *
    -* the moment, "-g" to request repeated matching to find all occurrences,  *
    -* like Perl's /g option. We set the variable find_all to a non-zero value *
    -* if the -g option is present.                                            *
    +* First, sort out the command line. Options:                              *
    +* - "-g" to request repeated matching to find all occurrences,            *
    +*   like Perl's /g option. We set the variable find_all to a non-zero     *
    +*   value if the -g option is present.                                    *
    +* - "-i" to request caseless matching, like Perl's /i option.  We set the *
    +*   variable caseless_match to PCRE2_CASELESS if the -i option is         *
    +*   present.                                                              *
     **************************************************************************/
     
     find_all = 0;
    +caseless_match = 0;
     for (i = 1; i < argc; i++)
       {
       if (strcmp(argv[i], "-g") == 0) find_all = 1;
    +  else if (strcmp(argv[i], "-i") == 0) caseless_match = PCRE2_CASELESS;
       else if (argv[i][0] == '-')
         {
         printf("Unrecognised option %s\n", argv[i]);
    @@ -156,7 +158,7 @@ subject_length = (PCRE2_SIZE)strlen((char *)subject);
     re = pcre2_compile(
       pattern,               /* the pattern */
       PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */
    -  0,                     /* default options */
    +  caseless_match,        /* possibly enable caseless */
       &errornumber,          /* for error number */
       &erroroffset,          /* for error offset */
       NULL);                 /* use default compile context */
    @@ -236,11 +238,12 @@ if (rc == 0)
       printf("ovector was not big enough for all the captured substrings\n");
     
     /* Since release 10.38 PCRE2 has locked out the use of \K in lookaround
    -assertions. However, there is an option to re-enable the old behaviour. If that
    -is set, it is possible to run patterns such as /(?=.\K)/ that use \K in an
    -assertion to set the start of a match later than its end. In this demonstration
    -program, we show how to detect this case, but it shouldn't arise because the
    -option is never set. */
    +assertions. This is the recommended behaviour. However, the option
    +PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK allows applications to re-enable the old
    +behaviour. If that is set, it is possible to run patterns such as /(?=.\K)/ that
    +use \K in an assertion to set the start of a match later than its end. In this
    +demonstration program, we show how to detect this case, although it cannot arise
    +because the option is never set. */
     
     if (ovector[0] > ovector[1])
       {
    @@ -279,7 +282,9 @@ we have to extract the count of named parentheses from the pattern. */
       PCRE2_INFO_NAMECOUNT, /* get the number of named substrings */
       &namecount);          /* where to put the answer */
     
    -if (namecount == 0) printf("No named substrings\n"); else
    +if (namecount == 0)
    +  printf("No named substrings\n");
    +else
       {
       PCRE2_SPTR tabptr;
       printf("Named substrings\n");
    @@ -317,28 +322,8 @@ if (namecount == 0) printf("No named substrings\n"); else
     * to search for additional matches in the subject string, in a similar   *
     * way to the /g option in Perl. This turns out to be trickier than you   *
     * might think because of the possibility of matching an empty string.    *
    -* What happens is as follows:                                            *
     *                                                                        *
    -* If the previous match was NOT for an empty string, we can just start   *
    -* the next match at the end of the previous one.                         *
    -*                                                                        *
    -* If the previous match WAS for an empty string, we can't do that, as it *
    -* would lead to an infinite loop. Instead, a call of pcre2_match() is    *
    -* made with the PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set. The *
    -* first of these tells PCRE2 that an empty string at the start of the    *
    -* subject is not a valid match; other possibilities must be tried. The   *
    -* second flag restricts PCRE2 to one match attempt at the initial string *
    -* position. If this match succeeds, an alternative to the empty string   *
    -* match has been found, and we can print it and proceed round the loop,  *
    -* advancing by the length of whatever was found. If this match does not  *
    -* succeed, we still stay in the loop, advancing by just one character.   *
    -* In UTF-8 mode, which can be set by (*UTF) in the pattern, this may be  *
    -* more than one byte.                                                    *
    -*                                                                        *
    -* However, there is a complication concerned with newlines. When the     *
    -* newline convention is such that CRLF is a valid newline, we must       *
    -* advance by two characters rather than one. The newline convention can  *
    -* be set in the regex by (*CR), etc.; if not, we must find the default.  *
    +* To help with this task, PCRE2 provides the pcre2_next_match() helper.  *
     *************************************************************************/
     
     if (!find_all)     /* Check for -g */
    @@ -348,60 +333,21 @@ if (!find_all)     /* Check for -g */
       return 0;                           /* Exit the program. */
       }
     
    -/* Before running the loop, check for UTF-8 and whether CRLF is a valid newline
    -sequence. First, find the options with which the regex was compiled and extract
    -the UTF state. */
    -
    -(void)pcre2_pattern_info(re, PCRE2_INFO_ALLOPTIONS, &option_bits);
    -utf8 = (option_bits & PCRE2_UTF) != 0;
    -
    -/* Now find the newline convention and see whether CRLF is a valid newline
    -sequence. */
    -
    -(void)pcre2_pattern_info(re, PCRE2_INFO_NEWLINE, &newline);
    -crlf_is_newline = newline == PCRE2_NEWLINE_ANY ||
    -                  newline == PCRE2_NEWLINE_CRLF ||
    -                  newline == PCRE2_NEWLINE_ANYCRLF;
    -
     /* Loop for second and subsequent matches */
     
    +ovector_last[0] = ovector[0];
    +ovector_last[1] = ovector[1];
    +
     for (;;)
       {
    -  uint32_t options = 0;                   /* Normally no options */
    -  PCRE2_SIZE start_offset = ovector[1];   /* Start at end of previous match */
    +  PCRE2_SIZE start_offset;
    +  uint32_t options;
     
    -  /* 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. */
    +  /* After each successful match, we use pcre2_next_match() to obtain the match
    +  parameters for subsequent match attempts. */
     
    -  if (ovector[0] == ovector[1])
    -    {
    -    if (ovector[0] == subject_length) break;
    -    options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
    -    }
    -
    -  /* If the previous match was not an empty string, there is one tricky case to
    -  consider. If a pattern contains \K within a lookbehind assertion at the
    -  start, the end of the matched string can be at the offset where the match
    -  started. Without special action, this leads to a loop that keeps on matching
    -  the same substring. We must detect this case and arrange to move the start on
    -  by one character. The pcre2_get_startchar() function returns the starting
    -  offset that was passed to pcre2_match(). */
    -
    -  else
    -    {
    -    PCRE2_SIZE startchar = pcre2_get_startchar(match_data);
    -    if (start_offset <= startchar)
    -      {
    -      if (startchar >= subject_length) break;   /* Reached end of subject.   */
    -      start_offset = startchar + 1;             /* Advance by one character. */
    -      if (utf8)                                 /* If UTF-8, it may be more  */
    -        {                                       /*   than one code unit.     */
    -        for (; start_offset < subject_length; start_offset++)
    -          if ((subject[start_offset] & 0xc0) != 0x80) break;
    -        }
    -      }
    -    }
    +  if (!pcre2_next_match(match_data, &start_offset, &options))
    +    break;
     
       /* Run the next matching operation */
     
    @@ -414,38 +360,10 @@ for (;;)
         match_data,           /* block for storing the result */
         NULL);                /* use default match context */
     
    -  /* This time, a result of NOMATCH isn't an error. If the value in "options"
    -  is zero, it just means we have found all possible matches, so the loop ends.
    -  Otherwise, it means we have failed to find a non-empty-string match at a
    -  point where there was a previous empty-string match. In this case, we do what
    -  Perl does: advance the matching position by one character, and continue. We
    -  do this by setting the "end of previous match" offset, because that is picked
    -  up at the top of the loop as the point at which to start again.
    -
    -  There are two complications: (a) When CRLF is a valid newline sequence, and
    -  the current position is just before it, advance by an extra byte. (b)
    -  Otherwise we must ensure that we skip an entire UTF character if we are in
    -  UTF mode. */
    +  /* If this match attempt fails, exit the loop for subsequent matches. */
     
       if (rc == PCRE2_ERROR_NOMATCH)
    -    {
    -    if (options == 0) break;                    /* All matches found */
    -    ovector[1] = start_offset + 1;              /* Advance one code unit */
    -    if (crlf_is_newline &&                      /* If CRLF is a newline & */
    -        start_offset < subject_length - 1 &&    /* we are at CRLF, */
    -        subject[start_offset] == '\r' &&
    -        subject[start_offset + 1] == '\n')
    -      ovector[1] += 1;                          /* Advance by one more. */
    -    else if (utf8)                              /* Otherwise, ensure we */
    -      {                                         /* advance a whole UTF-8 */
    -      while (ovector[1] < subject_length)       /* character. */
    -        {
    -        if ((subject[ovector[1]] & 0xc0) != 0x80) break;
    -        ovector[1] += 1;
    -        }
    -      }
    -    continue;    /* Go round the loop again */
    -    }
    +    break;
     
       /* Other matching errors are not recoverable. */
     
    @@ -457,7 +375,33 @@ for (;;)
         return 1;
         }
     
    -  /* Match succeeded */
    +  /* This demonstration program depends on pcre2_next_match() to ensure that the
    +  loop for second and subsequent matches does not run forever. However, it would
    +  be robust practice for a production application to verify this. The following
    +  block of code shows how to do this. This error case is not reachable unless
    +  there is a bug in PCRE2.
    +
    +  Because this program does not set the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option,
    +  the logic is simple. We verify that either ovector[1] has advanced, or that we
    +  have an empty match touching the end of a previous non-empty match. See the
    +  API documentation for guidance if your application uses
    +  PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK and searches for multiple matches. */
    +
    +  if (!(ovector[1] > ovector_last[1] ||
    +        (ovector[1] == ovector[0] && ovector_last[1] > ovector_last[0] &&
    +         ovector[1] == ovector_last[1])))
    +    {
    +    printf("\\K was used in an assertion to yield non-advancing matches.\n");
    +    printf("Run abandoned\n");
    +    pcre2_match_data_free(match_data);
    +    pcre2_code_free(re);
    +    return 1;
    +    }
    +
    +  ovector_last[0] = ovector[0];
    +  ovector_last[1] = ovector[1];
    +
    +  /* Match succeeded. */
     
       printf("\nMatch succeeded again at offset %d\n", (int)ovector[0]);
     
    @@ -467,9 +411,11 @@ for (;;)
       if (rc == 0)
         printf("ovector was not big enough for all the captured substrings\n");
     
    -  /* We must guard against patterns such as /(?=.\K)/ that use \K in an
    -  assertion to set the start of a match later than its end. In this
    -  demonstration program, we just detect this case and give up. */
    +  /* We guard against patterns such as /(?=.\K)/ that use \K in an assertion to
    +  set the start of a match later than its end. As explained above, this case
    +  should not occur because this demonstration program does not set the
    +  PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option, however, we do include code showing
    +  how to detect it. */
     
       if (ovector[0] > ovector[1])
         {
    @@ -492,7 +438,9 @@ for (;;)
         printf("%2d: %.*s\n", i, (int)substring_length, (char *)substring_start);
         }
     
    -  if (namecount == 0) printf("No named substrings\n"); else
    +  if (namecount == 0)
    +    printf("No named substrings\n");
    +  else
         {
         PCRE2_SPTR tabptr = name_table;
         printf("Named substrings\n");
    @@ -507,6 +455,7 @@ for (;;)
       }      /* End of loop to find second and subsequent matches */
     
     printf("\n");
    +
     pcre2_match_data_free(match_data);
     pcre2_code_free(re);
     return 0;
    diff --git a/doc/html/pcre2grep.html b/doc/html/pcre2grep.html
    index 66c5602..deb667e 100644
    --- a/doc/html/pcre2grep.html
    +++ b/doc/html/pcre2grep.html
    @@ -30,12 +30,12 @@ please consult the man page, in case the conversion went wrong.
     
  • AUTHOR
  • REVISION -
    SYNOPSIS
    -

    +

    SYNOPSIS

    +

    pcre2grep [options] [long options] [pattern] [path1 path2 ...] -

    -
    DESCRIPTION
    -

    +

    +

    DESCRIPTION

    +

    pcre2grep searches files for character patterns, in the same way as other grep commands do, but it uses the PCRE2 regular expression library to support patterns that are compatible with the regular expressions of Perl 5. See @@ -44,8 +44,8 @@ for a quick-reference summary of pattern syntax, or pcre2pattern(3) for a full description of the syntax and semantics of the regular expressions that PCRE2 supports. -

    -

    +

    +

    Patterns, whether supplied on the command line or in a separate file, are given without delimiters. For example:

    @@ -56,15 +56,15 @@ slashes, as is common in Perl scripts), they are interpreted as part of the
     pattern. Quotes can of course be used to delimit patterns on the command line
     because they are interpreted by the shell, and indeed quotes are required if a
     pattern contains white space or shell metacharacters.
    -

    -

    +

    +

    The first argument that follows any option settings is treated as the single pattern to be matched when neither -e nor -f is present. Conversely, when one or both of these options are used to specify patterns, all arguments are treated as path names. At least one of -e, -f, or an argument pattern must be provided. -

    -

    +

    +

    If no files are specified, pcre2grep reads the standard input. The standard input can also be referenced by a name consisting of a single hyphen. For example: @@ -81,8 +81,8 @@ option makes it possible to search for strings that span line boundaries. What defines a line boundary is controlled by the -N (--newline) option. The -h and -H options control whether or not file names are shown, and the -Z option changes the file name terminator to a zero byte. -

    -

    +

    +

    The amount of memory used for buffering files that are being scanned is controlled by parameters that can be set by the --buffer-size and --max-buffer-size options. The first of these sets the size of buffer @@ -93,24 +93,24 @@ default values for these parameters can be set when pcre2grep is built; if nothing is specified, the defaults are set to 20KiB and 1MiB respectively. An error occurs if a line is too long and the buffer can no longer be expanded. -

    -

    +

    +

    The block of memory that is actually used is three times the "buffer size", to allow for buffering "before" and "after" lines. If the buffer size is too small, fewer than requested "before" and "after" lines may be output. -

    -

    +

    +

    When matching with a multiline pattern, the size of the buffer must be at least half of the maximum match expected or the pattern might fail to match. -

    -

    +

    +

    Patterns can be no longer than 8KiB or BUFSIZ bytes, whichever is the greater. BUFSIZ is defined in <stdio.h>. When there is more than one pattern (specified by the use of -e and/or -f), each pattern is applied to each line in the order in which they are defined, except that all the -e patterns are tried before the -f patterns. -

    -

    +

    +

    By default, as soon as one pattern matches a line, no further patterns are considered. However, if --colour (or --color) is used to colour the matching substrings, or if --only-matching, --file-offsets, @@ -121,31 +121,31 @@ there is more than one match, the one that begins nearest to the start of the subject is processed; if there is more than one match at that position, the one with the longest matching substring is processed; if the matching substrings are equal, the first match found is processed. -

    -

    +

    +

    Scanning with all the patterns resumes immediately following the match, so that later matches on the same line can be found. Note, however, that an overlapping match that starts in the middle of another match will not be processed. -

    -

    +

    +

    The above behaviour was changed at release 10.41 to be more compatible with GNU grep. In earlier releases, pcre2grep did not recognize matches from later patterns that were earlier in the subject. -

    -

    +

    +

    Patterns that can match an empty string are accepted, but empty string matches are never recognized. An example is the pattern "(super)?(man)?", in which all components are optional. This pattern finds all occurrences of both "super" and "man"; the output differs from matching with "super|man" when only the matching substrings are being shown. -

    -

    +

    +

    If the LC_ALL or LC_CTYPE environment variable is set, pcre2grep uses the value to set a locale when calling the PCRE2 library. The --locale option can be used to override this. -

    -
    SUPPORT FOR COMPRESSED FILES
    -

    +

    +

    SUPPORT FOR COMPRESSED FILES

    +

    Compile-time options for pcre2grep can set it up to use libz or libbz2 for reading compressed files whose names end in .gz or .bz2, respectively. You can find out whether your pcre2grep binary @@ -155,37 +155,37 @@ treated as plain text. The standard input is always so treated. If a file with a .gz or .bz2 extension is not in fact compressed, it is read as a plain text file. When input is from a compressed .gz or .bz2 file, the --line-buffered option is ignored. -

    -
    BINARY FILES
    -

    +

    +

    BINARY FILES

    +

    By default, a file that contains a binary zero byte within the first 1024 bytes is identified as a binary file, and is processed specially. However, if the newline type is specified as NUL, that is, the line terminator is a binary zero, the test for a binary file is not applied. See the --binary-files option for a means of changing the way binary files are handled. -

    -
    BINARY ZEROS IN PATTERNS
    -

    +

    +

    BINARY ZEROS IN PATTERNS

    +

    Patterns passed from the command line are strings that are terminated by a binary zero, so cannot contain internal zeros. However, patterns that are read from a file via the -f option may contain binary zeros. -

    -
    OPTIONS
    -

    +

    +

    OPTIONS

    +

    The order in which some of the options appear can affect the output. For example, both the -H and -l options affect the printing of file names. Whichever comes later in the command line will be the one that takes effect. Similarly, except where noted below, if an option is given twice, the later setting is used. Numerical values for options may be followed by K or M, to signify multiplication by 1024 or 1024*1024 respectively. -

    -

    +

    +

    -- This terminates the list of options. It is useful if the next item on the command line starts with a hyphen but is not an option. This allows for the processing of patterns and file names that start with hyphens. -

    -

    +

    +

    -A number, --after-context=number Output up to number lines of context after each matching line. Fewer lines are output if the next match or the end of the file is reached, or if the @@ -196,19 +196,19 @@ terminator to a zero byte). A line containing "--" is output between each group of lines, unless they are in fact contiguous in the input file. The value of number is expected to be relatively small. When -c is used, -A is ignored. -

    -

    +

    +

    -a, --text Treat binary files as text. This is equivalent to --binary-files=text. -

    -

    +

    +

    --allow-lookaround-bsk PCRE2 now forbids the use of \K in lookarounds by default, in line with Perl. This option causes pcre2grep to set the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option, which enables this somewhat dangerous usage. -

    -

    +

    +

    -B number, --before-context=number Output up to number lines of context before each matching line. Fewer lines are output if the previous match or the start of the file is within @@ -219,8 +219,8 @@ change the file name terminator to a zero byte). A line containing "--" is output between each group of lines, unless they are in fact contiguous in the input file. The value of number is expected to be relatively small. When -c is used, -B is ignored. -

    -

    +

    +

    --binary-files=word Specify how binary files are to be processed. If the word is "binary" (the default), pattern matching is performed on binary files, but the only output is @@ -232,19 +232,19 @@ sent to a terminal. If the word is "without-match", which is equivalent to the -I option, binary files are not processed at all; they are assumed not to be of interest and are skipped without causing any output or affecting the return code. -

    -

    +

    +

    --buffer-size=number Set the parameter that controls how much memory is obtained at the start of processing for buffering files that are being scanned. See also --max-buffer-size below. -

    -

    +

    +

    -C number, --context=number Output number lines of context both before and after each matching line. This is equivalent to setting both -A and -B to the same value. -

    -

    +

    +

    -c, --count Do not output lines from the files that are being scanned; instead output the number of lines that would have been shown, either because they matched, or, if @@ -260,14 +260,14 @@ be used to cause a total to be output at the end. However, if the --files-with-matches option is also used, only those files whose counts are greater than zero are listed. When -c is used, the -A, -B, and -C options are ignored. -

    -

    +

    +

    --colour, --color If this option is given without any data, it is equivalent to "--colour=auto". If data is required, it must be given in the same shell item, separated by an equals sign. -

    -

    +

    +

    --colour=value, --color=value This option specifies under what circumstances the parts of a line that matched a pattern should be coloured in the output. It is ignored if @@ -297,14 +297,14 @@ is used. The string is copied directly into the control string for setting colour on a terminal, so it is your responsibility to ensure that the values make sense. If no relevant environment variable is set, the default is "1;31", which gives red. -

    -

    +

    +

    -D action, --devices=action If an input path is not a regular file or a directory, "action" specifies how it is to be processed. Valid values are "read" (the default) or "skip" (silently skip the path). -

    -

    +

    +

    -d action, --directories=action If an input path is a directory, "action" specifies how it is to be processed. Valid values are "read" (the default in non-Windows environments, for @@ -313,20 +313,20 @@ compatibility with GNU grep), "recurse" (equivalent to the -r option), or "read" case, directories are read as if they were ordinary files. In some operating systems the effect of reading a directory like this is an immediate end-of-file; in others it may provoke an error. -

    -

    +

    +

    --depth-limit=number See --match-limit below. -

    -

    +

    +

    -E, --case-restrict When case distinctions are being ignored in Unicode mode, two ASCII letters (K and S) will by default match Unicode characters U+212A (Kelvin sign) and U+017F (long S) respectively, as well as their lower case ASCII counterparts. When this option is set, case equivalences are restricted such that no ASCII character matches a non-ASCII character, and vice versa. -

    -

    +

    +

    -e pattern, --regex=pattern, --regexp=pattern Specify a pattern to be matched. This option can be used multiple times in order to specify several patterns. It can also be used as a way of specifying a @@ -339,8 +339,8 @@ line in the order in which they are defined. If -f is used with -e, the command line patterns are matched first, followed by the patterns from the file(s), independent of the order in which these options are specified. -

    -

    +

    +

    --exclude=pattern Files (but not directories) whose names match the pattern are skipped without being processed. This applies to all files, whether listed on the command line, @@ -351,16 +351,16 @@ not apply to this pattern. The option may be given any number of times in order to specify multiple patterns. If a file name matches both an --include and an --exclude pattern, it is excluded. There is no short form for this option. -

    -

    +

    +

    --exclude-from=filename Treat each non-empty line of the file as the data for an --exclude option. What constitutes a newline when reading the file is the operating system's default. The --newline option has no effect on this option. This option may be given more than once in order to specify a number of files to read. -

    -

    +

    +

    --exclude-dir=pattern Directories whose names match the pattern are skipped without being processed, whatever the setting of the --recursive option. This applies to all @@ -372,8 +372,8 @@ apply to this pattern. The option may be given any number of times in order to specify more than one pattern. If a directory matches both --include-dir and --exclude-dir, it is excluded. There is no short form for this option. -

    -

    +

    +

    -F, --fixed-strings Interpret each data-matching pattern as a list of fixed strings, separated by newlines, instead of as a regular expression. What constitutes a newline for @@ -384,8 +384,8 @@ strings are found in it (subject to -w or -x, if present). This option applies only to the patterns that are matched against the contents of files; it does not apply to patterns specified by any of the --include or --exclude options. -

    -

    +

    +

    -f filename, --file=filename Read patterns from the file, one per line. As is the case with patterns on the command line, no delimiters should be used. What constitutes a newline when @@ -403,8 +403,8 @@ as "-" to refer to the standard input. When -f is used, patterns specified on the command line using -e may also be present; they are matched before the file's patterns. However, no pattern is taken from the command line; all arguments are treated as the names of paths to be searched. -

    -

    +

    +

    --file-list=filename Read a list of files and/or directories that are to be scanned from the given file, one per line. What constitutes a newline when reading the file is the @@ -416,8 +416,8 @@ patterns are read first. This is useful only when the standard input is a terminal, from which further lines (the list of files) can be read after an end-of-file indication. If this option is given more than once, all the specified files are read. -

    -

    +

    +

    --file-offsets Instead of showing lines or parts of lines that match, show each match as an offset from the start of the file and a length, separated by a comma. In this @@ -425,13 +425,13 @@ mode, --colour has no effect, and no context is shown. That is, the -A, -B, and -C options are ignored. If there is more than one match in a line, each of them is shown separately. This option is mutually exclusive with --output, --line-offsets, and --only-matching. -

    -

    +

    +

    --group-separator=text Output this text string instead of two hyphens between groups of lines when -A, -B, or -C is in use. See also --no-group-separator. -

    -

    +

    +

    -H, --with-filename Force the inclusion of the file name at the start of output lines when searching a single file. The file name is not normally shown in this case. @@ -441,8 +441,8 @@ change the terminator to a zero byte. If a line number is also being output, it follows the file name. When the -M option causes a pattern to match more than one line, only the first is preceded by the file name. This option overrides any previous -h, -l, or -L options. -

    -

    +

    +

    -h, --no-filename Suppress the output file names when searching multiple files. File names are normally shown when multiple files are searched. By default, for matching @@ -450,29 +450,29 @@ lines, the file name is followed by a colon; for context lines, a hyphen separator is used. The -Z option can be used to change the terminator to a zero byte. If a line number is also being output, it follows the file name. This option overrides any previous -H, -L, or -l options. -

    -

    +

    +

    --heap-limit=number See --match-limit below. -

    -

    +

    +

    --help Output a help message, giving brief details of the command options and file type support, and then exit. Anything else on the command line is ignored. -

    -

    +

    +

    -I Ignore binary files. This is equivalent to --binary-files=without-match. -

    -

    +

    +

    -i, --ignore-case Ignore upper/lower case distinctions when pattern matching. This applies when matching path names for inclusion or exclusion as well as when matching lines in files. -

    -

    +

    +

    --include=pattern If any --include patterns are specified, the only files that are processed are those whose names match one of the patterns and do not match an @@ -484,15 +484,15 @@ the entire path. The -F, -w, and -x options do not apply to this pattern. The option may be given any number of times. If a file name matches both an --include and an --exclude pattern, it is excluded. There is no short form for this option. -

    -

    +

    +

    --include-from=filename Treat each non-empty line of the file as the data for an --include option. What constitutes a newline for this purpose is the operating system's default. The --newline option has no effect on this option. This option may be given any number of times; all the files are read. -

    -

    +

    +

    --include-dir=pattern If any --include-dir patterns are specified, the only directories that are processed are those whose names match one of the patterns and do not match @@ -503,16 +503,16 @@ the final component of the directory name, not the entire path. The -F, -w, and -x options do not apply to this pattern. The option may be given any number of times. If a directory matches both --include-dir and --exclude-dir, it is excluded. There is no short form for this option. -

    -

    +

    +

    -L, --files-without-match Instead of outputting lines from the files, just output the names of the files that do not contain any lines that would have been output. Each file name is output once, on a separate line by default, but if the -Z option is set, they are separated by zero bytes instead of newlines. This option overrides any previous -H, -h, or -l options. -

    -

    +

    +

    -l, --files-with-matches Instead of outputting lines from the files, just output the names of the files containing lines that would have been output. Each file name is output once, on @@ -524,14 +524,14 @@ have at least one match are listed along with their counts. Using this option with -c is a way of suppressing the listing of files with no matches that occurs with -c on its own. This option overrides any previous -H, -h, or -L options. -

    -

    +

    +

    --label=name This option supplies a name to be used for the standard input when file names are being output. If not supplied, "(standard input)" is used. There is no short form for this option. -

    -

    +

    +

    --line-buffered When this option is given, non-compressed input is read and processed line by line, and the output is flushed after each write. By default, input is read in @@ -543,8 +543,8 @@ pipe and you do not want pcre2grep to buffer up large amounts of data. However, its use will affect performance, and the -M (multiline) option ceases to work. When input is from a compressed .gz or .bz2 file, --line-buffered is ignored. -

    -

    +

    +

    --line-offsets Instead of showing lines or parts of lines that match, show each match as a line number, the offset from the start of the line, and a length. The line @@ -554,15 +554,15 @@ effect, and no context is shown. That is, the -A, -B, and -C--output, --file-offsets, and --only-matching. -

    -

    +

    +

    --locale=locale-name This option specifies a locale to be used for pattern matching. It overrides the value in the LC_ALL or LC_CTYPE environment variables. If no locale is specified, the PCRE2 library's default (usually the "C" locale) is used. There is no short form for this option. -

    -

    +

    +

    -M, --multiline Allow patterns to match more than one line. When this option is set, the PCRE2 library is called in "multiline" mode, and a match is allowed to continue past @@ -604,8 +604,8 @@ large processing buffer, this should not be a problem.
    The -M option does not work when input is read line by line (see --line-buffered.) -

    -

    +

    +

    -m number, --max-count=number Stop processing after finding number matching lines, or non-matching lines if -v is also set. Any trailing context lines are output after the @@ -615,8 +615,8 @@ a regular file, the file is left positioned just after the last matching line. If -c is also set, the count that is output is never greater than number. This option has no effect if used with -L, -l, or -q, or when just checking for a match in a binary file. -

    -

    +

    +

    --match-limit=number Processing some regular expression patterns may take a very long time to search for all possible matching strings. Others may require a very large amount of @@ -646,14 +646,14 @@ set smaller than --match-limit. There are no short forms for these options. The default limits can be set when the PCRE2 library is compiled; if they are not specified, the defaults are very large and so effectively unlimited. -

    -

    +

    +

    --max-buffer-size=number This limits the expansion of the processing buffer, whose initial size can be set by --buffer-size. The maximum buffer size is silently forced to be no smaller than the starting buffer size. -

    -

    +

    +

    -N newline-type, --newline=newline-type Six different conventions for indicating the ends of lines in scanned files are supported. For example: @@ -683,30 +683,30 @@ option, pcre2grep may behave in strange ways. Note that this option does not apply to files specified by the -f, --exclude-from, or --include-from options, which are expected to use the operating system's standard newline sequence. -

    -

    +

    +

    -n, --line-number Precede each output line by its line number in the file, followed by a colon for matching lines or a hyphen for context lines. If the file name is also being output, it precedes the line number. When the -M option causes a pattern to match more than one line, only the first is preceded by its line number. This option is forced if --line-offsets is used. -

    -

    +

    +

    --no-group-separator Do not output a separator between groups of lines when -A, -B, or -C is in use. The default is to output a line containing two hyphens. See also --group-separator. -

    -

    +

    +

    --no-jit If the PCRE2 library is built with support for just-in-time compiling (which speeds up matching), pcre2grep automatically makes use of this, unless it was explicitly disabled at build time. This option can be used to disable the use of JIT at run time. It is provided for testing and working around problems. It should never be needed in normal use. -

    -

    +

    +

    -O text, --output=text When there is a match, instead of outputting the line that matched, output just the text specified in this option, followed by an operating-system standard @@ -747,8 +747,8 @@ character, the second form must be used.
    Any other character is substituted by itself. In particular, $$ is replaced by a single dollar. -

    -

    +

    +

    -o, --only-matching Show only the part of the line that matched a pattern instead of the whole line. In this mode, no context is shown. That is, the -A, -B, and @@ -760,8 +760,8 @@ the matched portion of the line is empty, nothing is output unless the file name or line number are being printed, in which case they are shown on an otherwise empty line. This option is mutually exclusive with --output, --file-offsets and --line-offsets. -

    -

    +

    +

    -onumber, --only-matching=number Show only the part of the line that matched the capturing parentheses of the given number. Up to 50 capturing parentheses are supported by default. This @@ -785,18 +785,18 @@ match, in the order the options are given, and all on one line. For example, -o3 -o1 -o3 causes the substrings matched by capturing parentheses 3 and 1 and then 3 again to be output. By default, there is no separator (but see the next but one option). -

    -

    +

    +

    --om-capture=number Set the number of capturing parentheses that can be accessed by -o. The default is 50. -

    -

    +

    +

    --om-separator=text Specify a separating string for multiple occurrences of -o. The default is an empty string. Separating strings are never coloured. -

    -

    +

    +

    -P, --no-ucp Starting from release 10.43, when UTF/Unicode mode is specified with -u or -U, the PCRE2_UCP option is used by default. This means that the @@ -807,8 +807,8 @@ as was the case in earlier releases. Note that there are now more fine-grained option settings within patterns that affect individual classes. For example, when in UCP mode, the sequence (?aP) restricts [:word:] to ASCII letters, while allowing \w to match Unicode letters and digits. -

    -

    +

    +

    --posix-pattern-file When patterns are provided with the -f option, do not trim trailing spaces or ignore empty lines in a similar way than other grep tools. To keep @@ -816,32 +816,32 @@ the behaviour consistent with older versions, if the pattern read was terminated with CRLF (as character literals) then both characters won't be included as part of it, so if you really need to have pattern ending in '\r', use a escape sequence or provide it by a different method. -

    -

    +

    +

    -q, --quiet Work quietly, that is, display nothing except error messages. The exit status indicates whether or not any matches were found. -

    -

    +

    +

    -r, --recursive If any given path is a directory, recursively scan the files it contains, taking note of any --include and --exclude settings. By default, a directory is read as a normal file; in some operating systems this gives an immediate end-of-file. This option is a shorthand for setting the -d option to "recurse". -

    -

    +

    +

    --recursion-limit=number This is an obsolete synonym for --depth-limit. See --match-limit above for details. -

    -

    +

    +

    -s, --no-messages Suppress error messages about non-existent or unreadable files. Such files are quietly skipped. However, the return code is still 2, even if matches were found in other files. -

    -

    +

    +

    -t, --total-count This option is useful when scanning more than one file. If used on its own, -t suppresses all output except for a grand total number of matching @@ -852,16 +852,16 @@ is listed. If file names are being output, the grand total is preceded by "TOTAL:". Otherwise, it appears as just another number. The -t option is ignored when used with -L (list files without matches), because the grand total would always be zero. -

    -

    +

    +

    -u, --utf Operate in UTF/Unicode mode. This option is available only if PCRE2 has been compiled with UTF-8 support. All patterns (including those for any --exclude and --include options) and all lines that are scanned must be valid strings of UTF-8 characters. If an invalid UTF-8 string is encountered, an error occurs. -

    -

    +

    +

    -U, --utf-allow-invalid As --utf, but in addition subject lines may contain invalid UTF-8 code unit sequences. These can never form part of any pattern match. Patterns @@ -871,21 +871,21 @@ or other binary files. For more details about matching in non-valid UTF-8 strings, see the pcre2unicode(3) documentation. -

    -

    +

    +

    -V, --version Write the version numbers of pcre2grep and the PCRE2 library to the standard output and then exit. Anything else on the command line is ignored. -

    -

    +

    +

    -v, --invert-match Invert the sense of the match, so that lines which do not match any of the patterns are the ones that are found. When this option is set, options such as --only-matching and --output, which specify parts of a match that are to be output, are ignored. -

    -

    +

    +

    -w, --word-regex, --word-regexp Force the patterns only to match "words". That is, there must be a word boundary at the start and end of each matched string. This is equivalent to @@ -893,8 +893,8 @@ having "\b(?:" at the start of each pattern, and ")\b" at the end. This option applies only to the patterns that are matched against the contents of files; it does not apply to patterns specified by any of the --include or --exclude options. -

    -

    +

    +

    -x, --line-regex, --line-regexp Force the patterns to start matching only at the beginnings of lines, and in addition, require them to match entire lines. In multiline mode the match may @@ -902,38 +902,38 @@ be more than one line. This is equivalent to having "^(?:" at the start of each pattern and ")$" at the end. This option applies only to the patterns that are matched against the contents of files; it does not apply to patterns specified by any of the --include or --exclude options. -

    -

    +

    +

    -Z, --null Terminate files names in the regular output with a zero byte (the NUL character) instead of what would normally appear. This is useful when file names contain unusual characters such as colons, hyphens, or even newlines. The option does not apply to file names in error messages. -

    -
    ENVIRONMENT VARIABLES
    -

    +

    +

    ENVIRONMENT VARIABLES

    +

    The environment variables LC_ALL and LC_CTYPE are examined, in that order, for a locale. The first one that is set is used. This can be overridden by the --locale option. If no locale is set, the PCRE2 library's default (usually the "C" locale) is used. -

    -
    NEWLINES
    -

    +

    +

    NEWLINES

    +

    The -N (--newline) option allows pcre2grep to scan files with newline conventions that differ from the default. This option affects only the way scanned files are processed. It does not affect the interpretation of files specified by the -f, --file-list, --exclude-from, or --include-from options. -

    -

    +

    +

    Any parts of the scanned input files that are written to the standard output are copied with whatever newline sequences they have in the input. However, if the final line of a file is output, and it does not end with a newline sequence, a newline sequence is added. If the newline setting is CR, LF, CRLF or NUL, that line ending is output; for the other settings (ANYCRLF or ANY) a single NL is used. -

    -

    +

    +

    The newline setting does not affect the way in which pcre2grep writes newlines in informational messages to the standard output and error streams. Under Windows, the standard output is set to be binary, so that "\r\n" at the @@ -941,9 +941,9 @@ ends of output lines that are copied from the input is not converted to "\r\r\n" by the C I/O library. This means that any messages written to the standard output must end with "\r\n". For all other operating systems, and for all messages to the standard error stream, "\n" is used. -

    -
    OPTIONS COMPATIBILITY WITH GNU GREP
    -

    +

    +

    OPTIONS COMPATIBILITY WITH GNU GREP

    +

    Many of the short and long forms of pcre2grep's options are the same as in the GNU grep program. Any long option of the form --xxx-regexp (GNU terminology) is also available as --xxx-regex (PCRE2 terminology). @@ -955,17 +955,17 @@ However, the --case-restrict, --depth-limit, -E, -U, and --utf-allow-invalid options are specific to pcre2grep, as is the use of the --only-matching option with a capturing parentheses number. -

    -

    +

    +

    Although most of the common options work the same way, a few are different in pcre2grep. For example, the --include option's argument is a glob for GNU grep, but in pcre2grep it is a regular expression to which the -i option applies. If both the -c and -l options are given, GNU grep lists only file names, without counts, but pcre2grep gives the counts as well. -

    -
    OPTIONS WITH DATA
    -

    +

    +

    OPTIONS WITH DATA

    +

    There are four different ways in which an option with data can be specified. If a short form option is used, the data may follow immediately, or (with one exception) in the next command line item. For example: @@ -976,8 +976,8 @@ exception) in the next command line item. For example: The exception is the -o option, which may appear with or without data. Because of this, if data is present, it must follow immediately in the same item, for example -o3. -

    -

    +

    +

    If a long form option is used, the data may appear in the same command line item, separated by an equals character, or (with two exceptions) it may appear in the next command line item. For example: @@ -989,15 +989,15 @@ Note, however, that if you want to supply a file name beginning with ~ as data in a shell command, and have the shell expand ~ to a home directory, you must separate the file name from the option, because the shell does not treat ~ specially unless it is at the start of an item. -

    -

    +

    +

    The exceptions to the above are the --colour (or --color) and --only-matching options, for which the data is optional. If one of these options does have data, it must be given in the first form, using an equals character. Otherwise pcre2grep will assume that it has no data. -

    -
    USING PCRE2'S CALLOUT FACILITY
    -

    +

    +

    USING PCRE2'S CALLOUT FACILITY

    +

    pcre2grep has, by default, support for calling external programs or scripts or echoing specific strings during matching by making use of PCRE2's callout facility. However, this support can be completely or partially disabled @@ -1006,18 +1006,18 @@ for callouts by running it with the --help option. If callout support is completely disabled, callouts in patterns are forbidden by pcre2grep. If the facility is partially disabled, calling external programs is not supported, and callouts that request it are ignored. -

    -

    +

    +

    A callout in a PCRE2 pattern is of the form (?C<arg>) where the argument is either a number or a quoted string (see the pcre2callout documentation for details). Numbered callouts are ignored by pcre2grep; only callouts with string arguments are useful. -

    -
    +

    +

    Echoing a specific string -
    -

    +

    +

    Starting the callout string with a pipe character invokes an echoing facility that avoids calling an external program or script. This facility is always available, provided that callouts were not completely disabled when @@ -1037,17 +1037,17 @@ the escape $n. For example: Matching continues normally after the string is output. If you want to see only the callout output but not any output from an actual match, you should end the pattern with (*FAIL). -

    -
    +

    +

    Calling external programs or scripts -
    -

    +

    +

    This facility can be independently disabled when pcre2grep is built. It is supported for Windows, where a call to _spawnvp() is used, for VMS, where lib$spawn() is used, and for any Unix-like environment where fork() and execv() are available. -

    -

    +

    +

    If the callout string does not start with a pipe (vertical bar) character, it is parsed into a list of substrings separated by pipe characters. The first substring must be an executable name, with the following substrings specifying @@ -1081,9 +1081,9 @@ a dollar not followed by another character) causes the callout to be ignored. If running the program fails for any reason (including the non-existence of the executable), a local matching failure occurs and the matcher backtracks in the normal way. -

    -
    MATCHING ERRORS
    -

    +

    +

    MATCHING ERRORS

    +

    It is possible to supply a regular expression that takes a very long time to fail to match certain lines. Such patterns normally involve nested indefinite repeats, for example: (a+)*\d when matched against a line of a's with no final @@ -1091,42 +1091,42 @@ digit. The PCRE2 matching function has a resource limit that causes it to abort in these circumstances. If this happens, pcre2grep outputs an error message and the line that caused the problem to the standard error stream. If there are more than 20 such errors, pcre2grep gives up. -

    -

    +

    +

    The --match-limit option of pcre2grep can be used to set the overall resource limit. There are also other limits that affect the amount of memory used during matching; see the discussion of --heap-limit and --depth-limit above. -

    -
    DIAGNOSTICS
    -

    +

    +

    DIAGNOSTICS

    +

    Exit status is 0 if any matches were found, 1 if no matches were found, and 2 for syntax errors, overlong lines, non-existent or inaccessible files (even if matches were found in other files) or too many matching errors. Using the -s option to suppress error messages about inaccessible files does not affect the return code. -

    -

    +

    +

    When run under VMS, the return code is placed in the symbol PCRE2GREP_RC because VMS does not distinguish between exit(0) and exit(1). -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2pattern(3), pcre2syntax(3), pcre2callout(3), pcre2unicode(3). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 04 February 2025 +

    +

    REVISION

    +

    +Last updated: 24 January 2025
    Copyright © 1997-2023 University of Cambridge.
    diff --git a/doc/html/pcre2jit.html b/doc/html/pcre2jit.html index 6835cd8..cc26cc0 100644 --- a/doc/html/pcre2jit.html +++ b/doc/html/pcre2jit.html @@ -28,8 +28,8 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    PCRE2 JUST-IN-TIME COMPILER SUPPORT
    -

    +

    PCRE2 JUST-IN-TIME COMPILER SUPPORT

    +

    Just-in-time compiling is a heavyweight optimization that can greatly speed up pattern matching. However, it comes at the cost of extra processing before the match is performed, so it is of most benefit when the same pattern is going to @@ -39,14 +39,14 @@ times at various positions in the subject, even for a single call. Therefore, if the subject string is very long, it may still pay to use JIT even for one-off matches. JIT support is available for all of the 8-bit, 16-bit and 32-bit PCRE2 libraries. -

    -

    +

    +

    JIT support applies only to the traditional Perl-compatible matching function. It does not apply when the DFA matching function is being used. The code for JIT support was written by Zoltan Herczeg. -

    -
    AVAILABILITY OF JIT SUPPORT
    -

    +

    +

    AVAILABILITY OF JIT SUPPORT

    +

    JIT support is an optional feature of PCRE2. The "configure" option --enable-jit (or equivalent CMake option) must be set when PCRE2 is built if you want to use JIT. The support is limited to the following hardware @@ -62,8 +62,8 @@ platforms: RISC-V 32-bit and 64-bit

  • If --enable-jit is set on an unsupported platform, compilation fails. -

    -

    +

    +

    A client program can tell if JIT support has been compiled by calling pcre2_config() with the PCRE2_CONFIG_JIT option. The result is one if PCRE2 was built with JIT support, and zero otherwise. However, having the JIT @@ -75,48 +75,48 @@ items that are executable memory in which to build its compiled code. The only guarantee from pcre2_config() is that if it returns zero, JIT will definitely not be used. -

    -

    +

    +

    As of release 10.45 there is a more informative way to test for JIT support. If pcre2_compile_jit() is called with the single option PCRE2_JIT_TEST_ALLOC it returns zero if JIT is available and has a working allocator. Otherwise it returns PCRE2_ERROR_NOMEMORY if JIT is available but cannot allocate executable memory, or PCRE2_ERROR_JIT_UNSUPPORTED if JIT support is not compiled. The code argument is ignored, so it can be a NULL value. -

    -

    +

    +

    A simple program does not need to check availability in order to use JIT when possible. The API is implemented in a way that falls back to the interpretive code if JIT is not available or cannot be used for a given match. For programs that need the best possible performance, there is a "fast path" API that is JIT-specific. -

    -
    SIMPLE USE OF JIT
    -

    +

    +

    SIMPLE USE OF JIT

    +

    To make use of the JIT support in the simplest way, all you have to do is to call pcre2_jit_compile() after successfully compiling a pattern with pcre2_compile(). This function has two arguments: the first is the compiled pattern pointer that was returned by pcre2_compile(), and the second is zero or more of the following option bits: PCRE2_JIT_COMPLETE, PCRE2_JIT_PARTIAL_HARD, or PCRE2_JIT_PARTIAL_SOFT. -

    -

    +

    +

    If JIT support is not available, a call to pcre2_jit_compile() does nothing and returns PCRE2_ERROR_JIT_BADOPTION. Otherwise, the compiled pattern is passed to the JIT compiler, which turns it into machine code that executes much faster than the normal interpretive code, but yields exactly the same results. The returned value from pcre2_jit_compile() is zero on success, or a negative error code. -

    -

    +

    +

    There is a limit to the size of pattern that JIT supports, imposed by the size of machine stack that it uses. The exact rules are not documented because they may change at any time, in particular, when new optimizations are introduced. If a pattern is too big, a call to pcre2_jit_compile() returns PCRE2_ERROR_NOMEMORY. -

    -

    +

    +

    PCRE2_JIT_COMPLETE requests the JIT compiler to generate code for complete matches. If you want to run partial matches using the PCRE2_PARTIAL_HARD or PCRE2_PARTIAL_SOFT options of pcre2_match(), you should set one or both @@ -125,8 +125,8 @@ compiler generates different optimized code for each of the three modes (normal, soft partial, hard partial). When pcre2_match() is called, the appropriate code is run if it is available. Otherwise, the pattern is matched using interpretive code. -

    -

    +

    +

    You can call pcre2_jit_compile() multiple times for the same compiled pattern. It does nothing if it has previously compiled code for any of the option bits. For example, you can call it once with PCRE2_JIT_COMPLETE and @@ -136,18 +136,18 @@ PCRE2_JIT_COMPLETE and just compile code for partial matching. If pcre2_jit_compile() is called with no option bits set, it immediately returns zero. This is an alternative way of testing whether JIT support has been compiled. -

    -

    +

    +

    At present, it is not possible to free JIT compiled code except when the entire compiled pattern is freed by calling pcre2_code_free(). -

    -

    +

    +

    In some circumstances you may need to call additional functions. These are described in the section entitled "Controlling the JIT stack" below. -

    -

    +

    +

    There are some pcre2_match() options that are not supported by JIT, and there are also some pattern items that JIT cannot handle. Details are given below. @@ -160,8 +160,8 @@ below, even if you do not need to supply a non-default JIT stack. Such a callback function is called whenever JIT code is about to be obeyed. If the match-time options are not right for JIT execution, the callback function is not obeyed. -

    -

    +

    +

    If the JIT compiler finds an unsupported item, no JIT data is generated. You can find out if JIT compilation was successful for a compiled pattern by calling pcre2_pattern_info() with the PCRE2_INFO_JITSIZE option. A @@ -171,9 +171,9 @@ that JIT support is not available, or the pattern was not processed by pattern. Successful JIT compilation does not, however, guarantee the use of JIT at match time because there are some match time options that are not supported by JIT. -

    -
    MATCHING SUBJECTS CONTAINING INVALID UTF
    -

    +

    +

    MATCHING SUBJECTS CONTAINING INVALID UTF

    +

    When a pattern is compiled with the PCRE2_UTF option, subject strings are normally expected to be a valid sequence of UTF code units. By default, this is checked at the start of matching and an error is generated if invalid UTF is @@ -181,8 +181,8 @@ detected. The PCRE2_NO_UTF_CHECK option can be passed to pcre2_match() to skip the check (for improved performance) if you are sure that a subject string is valid. If this option is used with an invalid string, the result is undefined. The calling program may crash or loop or otherwise misbehave. -

    -

    +

    +

    However, a way of running matches on strings that may contain invalid UTF sequences is available. Calling pcre2_compile() with the PCRE2_MATCH_INVALID_UTF option has two effects: it tells the interpreter in @@ -192,48 +192,48 @@ Details of how this support works, in both the JIT and the interpretive cases, is given in the pcre2unicode documentation. -

    -

    +

    +

    There is also an obsolete option for pcre2_jit_compile() called PCRE2_JIT_INVALID_UTF, which currently exists only for backward compatibility. It is superseded by the pcre2_compile() option PCRE2_MATCH_INVALID_UTF and should no longer be used. It may be removed in future. -

    -
    UNSUPPORTED OPTIONS AND PATTERN ITEMS
    -

    +

    +

    UNSUPPORTED OPTIONS AND PATTERN ITEMS

    +

    The pcre2_match() options that are supported for JIT matching are PCRE2_COPY_MATCHED_SUBJECT, PCRE2_NOTBOL, PCRE2_NOTEOL, PCRE2_NOTEMPTY, PCRE2_NOTEMPTY_ATSTART, PCRE2_NO_UTF_CHECK, PCRE2_PARTIAL_HARD, and PCRE2_PARTIAL_SOFT. The PCRE2_ANCHORED and PCRE2_ENDANCHORED options are not supported at match time. -

    -

    +

    +

    If the PCRE2_NO_JIT option is passed to pcre2_match() it disables the use of JIT, forcing matching by the interpreter code. -

    -

    +

    +

    The only unsupported pattern items are \C (match a single data unit) when running in a UTF mode, and a callout immediately before an assertion condition in a conditional group. -

    -
    RETURN VALUES FROM JIT MATCHING
    -

    +

    +

    RETURN VALUES FROM JIT MATCHING

    +

    When a pattern is matched using JIT, the return values are the same as those given by the interpretive pcre2_match() code, with the addition of one new error code: PCRE2_ERROR_JIT_STACKLIMIT. This means that the memory used for the JIT stack was insufficient. See "Controlling the JIT stack" below for a discussion of JIT stack usage. -

    -

    +

    +

    The error code PCRE2_ERROR_MATCHLIMIT is returned by the JIT code if searching a very large pattern tree goes on for too long, as it is in the same circumstance when JIT is not used, but the details of exactly what is counted are not the same. The PCRE2_ERROR_DEPTHLIMIT error code is never returned when JIT matching is used. -

    -
    CONTROLLING THE JIT STACK
    -

    +

    +

    CONTROLLING THE JIT STACK

    +

    When the compiled JIT code runs, it needs a block of memory to use as a stack. By default, it uses 32KiB on the machine stack. However, some large or complicated patterns need more than this. The error PCRE2_ERROR_JIT_STACKLIMIT @@ -242,8 +242,8 @@ managing blocks of memory for use as JIT stacks. There is further discussion about the use of JIT stacks in the section entitled "JIT stack FAQ" below. -

    -

    +

    +

    The pcre2_jit_stack_create() function creates a JIT stack. Its arguments are a starting size, a maximum size, and a general context (for memory allocation functions, or NULL for standard memory allocation). It returns a @@ -253,8 +253,8 @@ that is no longer needed. If its argument is NULL, this function returns immediately, without doing anything. (For the technically minded: the address space is allocated by mmap or VirtualAlloc.) A maximum stack size of 512KiB to 1MiB should be more than enough for any pattern. -

    -

    +

    +

    The pcre2_jit_stack_assign() function specifies which stack JIT code should use. Its arguments are as follows:

    @@ -286,31 +286,31 @@ A callback function is obeyed whenever JIT code is about to be run; it is not
     obeyed when pcre2_match() is called with options that are incompatible
     for JIT matching. A callback function can therefore be used to determine
     whether a match operation was executed by JIT or by the interpreter.
    -

    -

    +

    +

    You may safely use the same JIT stack for more than one pattern (either by assigning directly or by callback), as long as the patterns are matched sequentially in the same thread. Currently, the only way to set up non-sequential matches in one thread is to use callouts: if a callout function starts another match, that match must use a different JIT stack to the one used for currently suspended match(es). -

    -

    +

    +

    In a multithread application, if you do not specify a JIT stack, or if you assign or pass back NULL from a callback, that is thread-safe, because each thread has its own machine stack. However, if you assign or pass back a non-NULL JIT stack, this must be a different stack for each thread so that the application is thread-safe. -

    -

    +

    +

    Strictly speaking, even more is allowed. You can assign the same non-NULL stack to a match context that is used by any number of patterns, as long as they are not used for matching by multiple threads at the same time. For example, you could use the same stack in all compiled patterns, with a global mutex in the callback to wait until the stack is available for use. However, this is an inefficient solution, and not recommended. -

    -

    +

    +

    This is a suggestion for how a multithreaded program that needs to set up non-default JIT stacks might operate:

    @@ -324,9 +324,9 @@ non-default JIT stacks might operate:
         return thread_local_var
     
    All the functions described in this section do nothing if JIT is not available. -

    -
    JIT STACK FAQ
    -

    +

    +

    JIT STACK FAQ

    +

    (1) Why do we need JIT stacks?

    @@ -336,8 +336,8 @@ Allocating real machine stack on some platforms is difficult. For example, the stack chain needs to be updated every time if we extend the stack on PowerPC. Although it is possible, its updating time overhead decreases performance. So we do the recursion in memory. -

    -

    +

    +

    (2) Why don't we simply allocate blocks of memory with malloc()?

    @@ -347,8 +347,8 @@ address space, so the stack could grow without moving memory data (this is important because of pointers). Thus we can allocate 1MiB address space, and use only a single memory page (usually 4KiB) if that is enough. However, we can still grow up to 1MiB anytime if needed. -

    -

    +

    +

    (3) Who "owns" a JIT stack?

    @@ -359,8 +359,8 @@ to the pattern currently running), that stack must not be used by any other threads (to avoid overwriting the same memory area). The best practice for multithreaded programs is to allocate a stack for each thread, and return this stack through the JIT callback function. -

    -

    +

    +

    (4) When should a JIT stack be freed?

    @@ -373,8 +373,8 @@ already freed stack, as that will cause SEGFAULT. (Also, do not free a stack currently used by pcre2_match() in another thread). You can also replace the stack in a context at any time when it is not in use. You should free the previous stack before assigning a replacement. -

    -

    +

    +

    (5) Should I allocate/free a stack every time before/after calling pcre2_match()?
    @@ -383,8 +383,8 @@ No, because this is too costly in terms of resources. However, you could implement some clever idea which release the stack if it is not used in let's say two minutes. The JIT callback can help to achieve this without keeping a list of patterns. -

    -

    +

    +

    (6) OK, the stack is for long term memory allocation. But what happens if a pattern causes stack overflow with a stack of 1MiB? Is that 1MiB kept until the stack is freed? @@ -395,29 +395,29 @@ sometimes without freeing the stack. There is no API for this at the moment. Probably a function call which returns with the currently allocated memory for any stack and another which allows releasing memory (shrinking the stack) would be a good idea if someone needs this. -

    -

    +

    +

    (7) This is too much of a headache. Isn't there any better solution for JIT stack handling?

    No, thanks to Windows. If POSIX threads were used everywhere, we could throw out this complicated API. -

    -
    FREEING JIT SPECULATIVE MEMORY
    -

    +

    +

    FREEING JIT SPECULATIVE MEMORY

    +

    void pcre2_jit_free_unused_memory(pcre2_general_context *gcontext); -

    -

    +

    +

    The JIT executable allocator does not free all memory when it is possible. It expects new allocations, and keeps some free memory around to improve allocation speed. However, in low memory conditions, it might be better to free all possible memory. You can cause this to happen by calling pcre2_jit_free_unused_memory(). Its argument is a general context, for custom memory management, or NULL for standard memory management. -

    -
    EXAMPLE CODE
    -

    +

    +

    EXAMPLE CODE

    +

    This is a single-threaded example that specifies a JIT stack without using a callback. A real program should include error checking after all the function calls. @@ -443,10 +443,10 @@ calls. pcre2_match_context_free(mcontext); pcre2_jit_stack_free(jit_stack); -

    -

    -
    JIT FAST PATH API
    -

    +

  • +

    +

    JIT FAST PATH API

    +

    Because the API described above falls back to interpreted matching when JIT is not available, it is convenient for programs that are written for general use in many environments. However, calling JIT via pcre2_match() does have a @@ -455,8 +455,8 @@ available, and which need the best possible performance, can instead use a "fast path" API to call JIT matching directly instead of calling pcre2_match() (obviously only for patterns that have been successfully processed by pcre2_jit_compile()). -

    -

    +

    +

    The fast path function is called pcre2_jit_match(), and it takes exactly the same arguments as pcre2_match(). However, the subject string must be specified with a length; PCRE2_ZERO_TERMINATED is not supported. Unsupported @@ -464,8 +464,8 @@ option bits (for example, PCRE2_ANCHORED and PCRE2_ENDANCHORED) are ignored, as is the PCRE2_NO_JIT option. The return values are also the same as for pcre2_match(), plus PCRE2_ERROR_JIT_BADOPTION if a matching mode (partial or complete) is requested that was not compiled. -

    -

    +

    +

    When you call pcre2_match(), as well as testing for invalid options, a number of other sanity checks are performed on the arguments. For example, if the subject pointer is NULL but the length is non-zero, an immediate error is @@ -476,26 +476,26 @@ set for pcre2_compile(), the result is undefined. The program may crash or loop or give wrong results. In the absence of PCRE2_MATCH_INVALID_UTF you should call pcre2_jit_match() in UTF mode only if you are sure the subject is valid. -

    -

    +

    +

    Bypassing the sanity checks and the pcre2_match() wrapping can give speedups of more than 10%. -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2api(3), pcre2unicode(3) -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel (FAQ by Zoltan Herczeg)
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    +

    +

    REVISION

    +

    Last updated: 22 August 2024
    Copyright © 1997-2024 University of Cambridge. diff --git a/doc/html/pcre2limits.html b/doc/html/pcre2limits.html index 514c50b..968a7f2 100644 --- a/doc/html/pcre2limits.html +++ b/doc/html/pcre2limits.html @@ -12,14 +12,14 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    SIZE AND OTHER LIMITATIONS -
    -

    +

    +

    There are some size limitations in PCRE2 but it is hoped that they will never in practice be relevant. -

    -

    +

    +

    The maximum size of a compiled pattern is approximately 64 thousand code units for the 8-bit and 16-bit libraries if PCRE2 is compiled with the default internal linkage size, which is 2 bytes for these libraries. If you want to @@ -30,31 +30,31 @@ rounded up to 4). See the README file in the source distribution and the documentation for details. In these cases the limit is substantially larger. However, the speed of execution is slower. In the 32-bit library, the internal linkage size is always 4. -

    -

    +

    +

    The maximum length of a source pattern string is essentially unlimited; it is the largest number a PCRE2_SIZE variable can hold. However, the program that calls pcre2_compile() can specify a smaller limit. -

    -

    +

    +

    The maximum length (in code units) of a subject string is one less than the largest number a PCRE2_SIZE variable can hold. PCRE2_SIZE is an unsigned integer type, usually defined as size_t. Its maximum value (that is ~(PCRE2_SIZE)0) is reserved as a special indicator for zero-terminated strings and unset offsets. -

    -

    +

    +

    All values in repeating quantifiers must be less than 65536. -

    -

    +

    +

    There are two different limits that apply to branches of lookbehind assertions. If every branch in such an assertion matches a fixed number of characters, the maximum length of any branch is 65535 characters. If any branch matches a variable number of characters, then the maximum matching length for every branch is limited. The default limit is set at compile time, defaulting to 255, but can be changed by the calling program. -

    -

    +

    +

    There is no limit to the number of parenthesized groups, but there can be no more than 65535 capture groups, and there is a limit to the depth of nesting of parenthesized subpatterns of all kinds. This is imposed in order to limit the @@ -62,41 +62,44 @@ amount of system stack used at compile time. The default limit can be specified when PCRE2 is built; if not, the default is set to 250. An application can change this limit by calling pcre2_set_parens_nest_limit() to set the limit in a compile context. -

    -

    -The maximum length of name for a named capture group is 32 code units, and the -maximum number of such groups is 10000. -

    -

    +

    +

    +The maximum length of the name for a named capture group as well as the number +of such groups is configurable at build time. The maximum length for the name +defaults to +128 code units, and the maximum number of such groups to +10000. +

    +

    The maximum length of a name in a (*MARK), (*PRUNE), (*SKIP), or (*THEN) verb is 255 code units for the 8-bit library and 65535 code units for the 16-bit and 32-bit libraries. -

    -

    +

    +

    The maximum length of a string argument to a callout is the largest number a 32-bit unsigned integer can hold. -

    -

    +

    +

    The maximum amount of heap memory used for matching is controlled by the heap limit, which can be set in a pattern or in a match context. The default is a very large number, effectively unlimited. -

    -
    +

    +

    AUTHOR -
    -

    +

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    +

    +

    REVISION -
    -

    -Last updated: 16 August 2023 +

    +

    +Last updated: 03 September 2025
    Copyright © 1997-2023 University of Cambridge.
    diff --git a/doc/html/pcre2matching.html b/doc/html/pcre2matching.html index 4d02325..f015355 100644 --- a/doc/html/pcre2matching.html +++ b/doc/html/pcre2matching.html @@ -22,24 +22,24 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    PCRE2 MATCHING ALGORITHMS
    -

    +

    PCRE2 MATCHING ALGORITHMS

    +

    This document describes the two different algorithms that are available in PCRE2 for matching a compiled regular expression against a given subject string. The "standard" algorithm is the one provided by the pcre2_match() -function. This works in the same as Perl's matching function, and provides a +function. This works in the same way as Perl's matching function, and provides a Perl-compatible matching operation. The just-in-time (JIT) optimization that is described in the pcre2jit documentation is compatible with this function. -

    -

    +

    +

    An alternative algorithm is provided by the pcre2_dfa_match() function; it operates in a different way, and is not Perl-compatible. This alternative has advantages and disadvantages compared with the standard algorithm, and these are described below. -

    -

    +

    +

    When there is only one possible way in which a given subject string can match a pattern, the two algorithms give the same answer. A difference arises, however, when there are multiple possibilities. For example, if the anchored pattern @@ -52,18 +52,18 @@ is matched against the string

  • there are three possible answers. The standard algorithm finds only one of them, whereas the alternative algorithm finds all three. -

    -
    REGULAR EXPRESSIONS AS TREES
    -

    +

    +

    REGULAR EXPRESSIONS AS TREES

    +

    The set of strings that are matched by a regular expression can be represented as a tree structure. An unlimited repetition in the pattern makes the tree of infinite size, but it is still a tree. Matching the pattern to a given subject string (from a given starting point) can be thought of as a search of the tree. There are two ways to search a tree: depth-first and breadth-first, and these correspond to the two matching algorithms provided by PCRE2. -

    -
    THE STANDARD MATCHING ALGORITHM
    -

    +

    +

    THE STANDARD MATCHING ALGORITHM

    +

    In the terminology of Jeffrey Friedl's book "Mastering Regular Expressions", the standard algorithm is an "NFA algorithm". It conducts a depth-first search of the pattern tree. That is, it proceeds along a single path through the tree, @@ -73,23 +73,23 @@ fail, it backs up to the previous branch point in the tree, and tries the next alternative branch at that level. This often involves backing up (moving to the left) in the subject string as well. The order in which repetition branches are tried is controlled by the greedy or ungreedy nature of the quantifier. -

    -

    +

    +

    If a leaf node is reached, a matching string has been found, and at that point the algorithm stops. Thus, if there is more than one possible match, this algorithm returns the first one that it finds. Whether this is the shortest, the longest, or some intermediate length depends on the way the alternations and the greedy or ungreedy repetition quantifiers are specified in the pattern. -

    -

    +

    +

    Because it ends up with a single path through the tree, it is relatively straightforward for this algorithm to keep track of the substrings that are matched by portions of the pattern in parentheses. This provides support for capturing parentheses and backreferences. -

    -
    THE ALTERNATIVE MATCHING ALGORITHM
    -

    +

    +

    THE ALTERNATIVE MATCHING ALGORITHM

    +

    This algorithm conducts a breadth-first search of the tree. Starting from the first matching point in the subject, it scans the subject string from left to right, once, character by character, and as it does this, it remembers all the @@ -97,14 +97,14 @@ paths through the tree that represent valid matches. In Friedl's terminology, this is a kind of "DFA algorithm", though it is not implemented as a traditional finite state machine (it keeps multiple states active simultaneously). -

    -

    +

    +

    Although the general principle of this matching algorithm is that it scans the subject string only once, without backtracking, there is one exception: when a lookaround assertion is encountered, the characters following or preceding the current point have to be independently inspected. -

    -

    +

    +

    The scan continues until either the end of the subject is reached, or there are no more unterminated paths. At this point, terminated paths represent the different matching possibilities (if there are none, the match has failed). @@ -112,14 +112,14 @@ Thus, if there is more than one possible match, this algorithm finds all of them, and in particular, it finds the longest. The matches are returned in the output vector in decreasing order of length. There is an option to stop the algorithm after the first match (which is necessarily the shortest) is found. -

    -

    +

    +

    Note that the size of vector needed to contain all the results depends on the number of simultaneous matches, not on the number of capturing parentheses in the pattern. Using pcre2_match_data_create_from_pattern() to create the match data block is therefore not advisable when doing DFA matching. -

    -

    +

    +

    Note also that all the matches that are found start at the same point in the subject. If the pattern

    @@ -129,8 +129,8 @@ is matched against the string "the caterpillar catchment", the result is the
     three strings "caterpillar", "cater", and "cat" that start at the fifth
     character of the subject. The algorithm does not automatically move on to find
     matches that start at later positions.
    -

    -

    +

    +

    PCRE2's "auto-possessification" optimization usually applies to character repeats at the end of a pattern (as well as internally). For example, the pattern "a\d+" is compiled as if it were "a\d++" because there is no point @@ -138,13 +138,13 @@ even considering the possibility of backtracking into the repeated digits. For DFA matching, this means that only one possible match is found. If you really do want multiple matches in such cases, either use an ungreedy repeat ("a\d+?") or set the PCRE2_NO_AUTO_POSSESS option when compiling. -

    -

    +

    +

    There are a number of features of PCRE2 regular expressions that are not supported or behave differently in the alternative matching function. Those that are not supported cause an error if encountered. -

    -

    +

    +

    1. Because the algorithm finds all possible matches, the greedy or ungreedy nature of repetition quantifiers is not relevant (though it may affect auto-possessification, as just described). During matching, greedy and ungreedy @@ -158,14 +158,14 @@ This pattern matches "aaab!" but not "aaa!", which would be matched by a non-possessive quantifier. Similarly, if an atomic group is present, it is matched as if it were a standalone pattern at the current point, and the longest match is then "locked in" for the rest of the overall pattern. -

    -

    +

    +

    2. When dealing with multiple paths through the tree simultaneously, it is not straightforward to keep track of captured substrings for the different matching possibilities, and PCRE2's implementation of this algorithm does not attempt to do this. This means that no captured substrings are available. -

    -

    +

    +

    3. Because no substrings are captured, a number of related features are not available:
    @@ -181,79 +181,79 @@ for a specific group recursion;

    (d) Scan substring assertions. -

    -

    +

    +

    4. Because many paths through the tree may be active, the \K escape sequence, which resets the start of the match when encountered (but may be on some paths and not on others), is not supported. -

    -

    +

    +

    5. Callouts are supported, but the value of the capture_top field is always 1, and the value of the capture_last field is always 0. -

    -

    +

    +

    6. The \C escape sequence, which (in the standard algorithm) always matches a single code unit, even in a UTF mode, is not supported in UTF modes because the alternative algorithm moves through the subject string one character (not code unit) at a time, for all active paths through the tree. -

    -

    +

    +

    7. Except for (*FAIL), the backtracking control verbs such as (*PRUNE) are not supported. (*FAIL) is supported, and behaves like a failing negative assertion. -

    -

    +

    +

    8. The PCRE2_MATCH_INVALID_UTF option for pcre2_compile() is not supported by pcre2_dfa_match(). -

    -
    ADVANTAGES OF THE ALTERNATIVE ALGORITHM
    -

    +

    +

    ADVANTAGES OF THE ALTERNATIVE ALGORITHM

    +

    The main advantage of the alternative algorithm is that all possible matches (at a single point in the subject) are automatically found, and in particular, the longest match is found. To find more than one match at the same point using the standard algorithm, you have to do kludgy things with callouts. -

    -

    +

    +

    Partial matching is possible with this algorithm, though it has some limitations. The pcre2partial documentation gives details of partial matching and discusses multi-segment matching. -

    -
    DISADVANTAGES OF THE ALTERNATIVE ALGORITHM
    -

    +

    +

    DISADVANTAGES OF THE ALTERNATIVE ALGORITHM

    +

    The alternative algorithm suffers from a number of disadvantages: -

    -

    +

    +

    1. It is substantially slower than the standard algorithm. This is partly because it has to search for all possible matches, but is also because it is less susceptible to optimization. -

    -

    +

    +

    2. Capturing parentheses and other features such as backreferences that rely on them are not supported. -

    -

    +

    +

    3. Matching within invalid UTF strings is not supported. -

    -

    +

    +

    4. Although atomic groups are supported, their use does not provide the performance advantage that it does for the standard algorithm. -

    -

    +

    +

    5. JIT optimization is not supported. -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 30 August 2024 +

    +

    REVISION

    +

    +Last updated: 22 February 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2partial.html b/doc/html/pcre2partial.html index 067064d..529cc7b 100644 --- a/doc/html/pcre2partial.html +++ b/doc/html/pcre2partial.html @@ -22,33 +22,33 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    PARTIAL MATCHING IN PCRE2
    -

    +

    PARTIAL MATCHING IN PCRE2

    +

    In normal use of PCRE2, if there is a match up to the end of a subject string, but more characters are needed to match the entire pattern, PCRE2_ERROR_NOMATCH is returned, just like any other failing match. There are circumstances where it might be helpful to distinguish this "partial match" case. -

    -

    +

    +

    One example is an application where the subject string is very long, and not all available at once. The requirement here is to be able to do the matching segment by segment, but special action is needed when a matched substring spans the boundary between two segments. -

    -

    +

    +

    Another example is checking a user input string as it is typed, to ensure that it conforms to a required format. Invalid characters can be immediately diagnosed and rejected, giving instant feedback. -

    -

    +

    +

    Partial matching is a PCRE2-specific feature; it is not Perl-compatible. It is requested by setting one of the PCRE2_PARTIAL_HARD or PCRE2_PARTIAL_SOFT options when calling a matching function. The difference between the two options is whether or not a partial match is preferred to an alternative complete match, though the details differ between the two types of matching function. If both options are set, PCRE2_PARTIAL_HARD takes precedence. -

    -

    +

    +

    If you want to use partial matching with just-in-time optimized code, as well as setting a partial match option for the matching function, you must also call pcre2_jit_compile() with one or both of these options: @@ -59,8 +59,8 @@ as setting a partial match option for the matching function, you must also call PCRE2_JIT_COMPLETE should also be set if you are going to run non-partial matches on the same pattern. Separate code is compiled for each mode. If the appropriate JIT mode has not been compiled, interpretive matching code is used. -

    -

    +

    +

    Setting a partial matching option disables two of PCRE2's standard optimization hints. PCRE2 remembers the last literal code unit in a pattern, and abandons matching immediately if it is not present in the subject string. @@ -68,43 +68,43 @@ This optimization cannot be used for a subject string that might match only partially. PCRE2 also remembers a minimum length of a matching string, and does not bother to run the matching function on shorter strings. This optimization is also disabled for partial matching. -

    -
    REQUIREMENTS FOR A PARTIAL MATCH
    -

    +

    +

    REQUIREMENTS FOR A PARTIAL MATCH

    +

    A possible partial match occurs during matching when the end of the subject string is reached successfully, but either more characters are needed to complete the match, or the addition of more characters might change what is matched. -

    -

    +

    +

    Example 1: if the pattern is /abc/ and the subject is "ab", more characters are definitely needed to complete a match. In this case both hard and soft matching options yield a partial match. -

    -

    +

    +

    Example 2: if the pattern is /ab+/ and the subject is "ab", a complete match can be found, but the addition of more characters might change what is matched. In this case, only PCRE2_PARTIAL_HARD returns a partial match; PCRE2_PARTIAL_SOFT returns the complete match. -

    -

    +

    +

    On reaching the end of the subject, when PCRE2_PARTIAL_HARD is set, if the next pattern item is \z, \Z, \b, \B, or $ there is always a partial match. Otherwise, for both options, the next pattern item must be one that inspects a character, and at least one of the following must be true: -

    -

    +

    +

    (1) At least one character has already been inspected. An inspected character need not form part of the final matched string; lookbehind assertions and the \K escape sequence provide ways of inspecting characters before the start of a matched string. -

    -

    +

    +

    (2) The pattern contains one or more lookbehind assertions. This condition exists in case there is a lookbehind that inspects characters before the start of the match. -

    -

    +

    +

    (3) There is a special case when the whole pattern can match an empty string. When the starting point is at the end of the subject, the empty string match is a possibility, and if PCRE2_PARTIAL_SOFT is set and neither of the above @@ -113,26 +113,26 @@ might result in a non-empty match, PCRE2_PARTIAL_HARD returns a partial match, which in this case means "there is going to be a match at this point, but until some more characters are added, we do not know if it will be an empty string or something longer". -

    -
    PARTIAL MATCHING USING pcre2_match()
    -

    +

    +

    PARTIAL MATCHING USING pcre2_match()

    +

    When a partial matching option is set, the result of calling pcre2_match() can be one of the following: -

    -

    +

    +

    A successful match A complete match has been found, starting and ending within this subject. -

    -

    +

    +

    PCRE2_ERROR_NOMATCH No match can start anywhere in this subject. -

    -

    +

    +

    PCRE2_ERROR_PARTIAL Adding more characters may result in a complete match that uses one or more characters from the end of this subject. -

    -

    +

    +

    When a partial match is returned, the first two elements in the ovector point to the portion of the subject that was matched, but the values in the rest of the ovector are undefined. The appearance of \K in the pattern has no effect @@ -146,8 +146,8 @@ match" point. However, if a partial match is requested and the subject string is "456abc12", a partial match is found for the string "abc12", because all these characters are needed for a subsequent re-match with additional characters. -

    -

    +

    +

    If there is more than one partial match, the first one that was found provides the data that is returned. Consider this pattern:

    @@ -158,23 +158,23 @@ fail to match, but the end of the subject is reached during matching, so
     PCRE2_ERROR_PARTIAL is returned. The offsets are set to 3 and 9, identifying
     "123dog" as the first partial match. (In this example, there are two partial
     matches, because "dog" on its own partially matches the second alternative.)
    -

    -
    +

    +

    How a partial match is processed by pcre2_match() -
    -

    +

    +

    What happens when a partial match is identified depends on which of the two partial matching options is set. -

    -

    +

    +

    If PCRE2_PARTIAL_HARD is set, PCRE2_ERROR_PARTIAL is returned as soon as a partial match is found, without continuing to search for possible complete matches. This option is "hard" because it prefers an earlier partial match over a later complete match. For this reason, the assumption is made that the end of the supplied subject string is not the true end of the available data, which is why \z, \Z, \b, \B, and $ always give a partial match. -

    -

    +

    +

    If PCRE2_PARTIAL_SOFT is set, the partial match is remembered, but matching continues as normal, and other alternatives in the pattern are tried. If no complete match can be found, PCRE2_ERROR_PARTIAL is returned instead of @@ -183,8 +183,8 @@ over a partial match. All the various matching items in a pattern behave as if the subject string is potentially complete; \z, \Z, and $ match at the end of the subject, as normal, and for \b and \B the end of the subject is treated as a non-alphanumeric. -

    -

    +

    +

    The difference between the two partial matching options can be illustrated by a pattern such as:

    @@ -207,11 +207,11 @@ to follow this explanation by thinking of the two patterns like this:
     
    The second pattern will never match "dogsbody", because it will always find the shorter match first. -

    -
    +

    +

    Example of partial matching using pcre2test -
    -

    +

    +

    The pcre2test data modifiers partial_hard (or ph) and partial_soft (or ps) set PCRE2_PARTIAL_HARD and PCRE2_PARTIAL_SOFT, respectively, when calling pcre2_match(). Here is a run of @@ -239,9 +239,9 @@ options. Here is an example where there is a difference: With PCRE2_PARTIAL_SOFT, the subject is matched completely. For PCRE2_PARTIAL_HARD, however, the subject is assumed not to be complete, so there is only a partial match. -

    -
    MULTI-SEGMENT MATCHING WITH pcre2_match()
    -

    +

    +

    MULTI-SEGMENT MATCHING WITH pcre2_match()

    +

    PCRE was not originally designed with multi-segment matching in mind. However, over time, features (including partial matching) that make multi-segment matching possible have been added. A very long string can be searched segment @@ -250,15 +250,15 @@ the same results that would happen if the entire string was available for searching all the time. Normally, the strings that are being sought are much shorter than each individual segment, and are in the middle of very long strings, so the pattern is normally not anchored. -

    -

    +

    +

    Special logic must be implemented to handle a matched substring that spans a segment boundary. PCRE2_PARTIAL_HARD should be used, because it returns a partial match at the end of a segment whenever there is the possibility of changing the match by adding more characters. The PCRE2_NOTBOL option should also be set for all but the first segment. -

    -

    +

    +

    When a partial match occurs, the next segment must be added to the current subject and the match re-run, using the startoffset argument of pcre2_match() to begin at the point where the partial match started. @@ -279,8 +279,8 @@ segment. After a partial match, the first half of the buffer is discarded, the second half is moved to the start of the buffer, and a new segment is added before repeating the match as in the example above. After a no match, the entire buffer can be discarded. -

    -

    +

    +

    If there are memory constraints, you may want to discard text that precedes a partial match before adding the next segment. Unfortunately, this is not at present straightforward. In cases such as the above, where the pattern does not @@ -301,8 +301,8 @@ For this reason, this information is not available via the API. It is therefore not possible in general to obtain the exact number of characters that must be retained in order to get the right match result. If you cannot retain the entire segment, you must find some heuristic way of choosing. -

    -

    +

    +

    If you know the approximate length of the matching substrings, you can use that to decide how much text to retain. The only lookbehind information that is currently available via the API is the length of the longest individual @@ -312,27 +312,27 @@ PCRE2_INFO_MAXLOOKBEHIND option is the maximum number of characters (not code units) that any individual lookbehind moves back when it is processed. A pattern such as "(?<=(?<!b)a)" has a maximum lookbehind value of one, but inspects two characters before its starting point. -

    -

    +

    +

    In a non-UTF or a 32-bit case, moving back is just a subtraction, but in UTF-8 or UTF-16 you have to count characters while moving back through the code units. -

    -
    PARTIAL MATCHING USING pcre2_dfa_match()
    -

    +

    +

    PARTIAL MATCHING USING pcre2_dfa_match()

    +

    The DFA function moves along the subject string character by character, without backtracking, searching for all possible matches simultaneously. If the end of the subject is reached before the end of the pattern, there is the possibility of a partial match. -

    -

    +

    +

    When PCRE2_PARTIAL_SOFT is set, PCRE2_ERROR_PARTIAL is returned only if there have been no complete matches. Otherwise, the complete matches are returned. If PCRE2_PARTIAL_HARD is set, a partial match takes precedence over any complete matches. The portion of the string that was matched when the longest partial match was found is set as the first matching string. -

    -

    +

    +

    Because the DFA function always searches for all possible matches, and there is no difference between greedy and ungreedy repetition, its behaviour is different from the pcre2_match(). Consider the string "dog" matched @@ -343,9 +343,9 @@ against this ungreedy pattern: Whereas the standard function stops as soon as it finds the complete match for "dog", the DFA function also finds the partial match for "dogsbody", and so returns that when PCRE2_PARTIAL_HARD is set. -

    -
    MULTI-SEGMENT MATCHING WITH pcre2_dfa_match()
    -

    +

    +

    MULTI-SEGMENT MATCHING WITH pcre2_dfa_match()

    +

    When a partial match has been found using the DFA matching function, it is possible to continue the match by providing additional subject data and calling the function again with the same compiled regular expression, this time setting @@ -379,26 +379,26 @@ subject string. Attempting to continue with the string "7890" does not yield a match because only those alternatives that match at one point in the subject are remembered. Depending on the application, this may or may not be what you want. -

    -

    +

    +

    If you do want to allow for starting again at the next character, one way of doing it is to retain some or all of the segment and try a new complete match, as described for pcre2_match() above. Another possibility is to work with two buffers. If a partial match at offset n in the first buffer is followed by "no match" when PCRE2_DFA_RESTART is used on the second buffer, you can then try a new match starting at offset n+1 in the first buffer. -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    +

    +

    REVISION

    +

    Last updated: 27 November 2024
    Copyright © 1997-2019 University of Cambridge. diff --git a/doc/html/pcre2pattern.html b/doc/html/pcre2pattern.html index 84eb0aa..a18a297 100644 --- a/doc/html/pcre2pattern.html +++ b/doc/html/pcre2pattern.html @@ -41,17 +41,15 @@ please consult the man page, in case the conversion went wrong.

  • CONDITIONAL GROUPS
  • COMMENTS
  • RECURSIVE PATTERNS -
  • GROUPS AS SUBROUTINES -
  • ONIGURUMA SUBROUTINE SYNTAX -
  • CALLOUTS -
  • BACKTRACKING CONTROL -
  • EBCDIC ENVIRONMENTS -
  • SEE ALSO -
  • AUTHOR -
  • REVISION +
  • CALLOUTS +
  • BACKTRACKING CONTROL +
  • EBCDIC ENVIRONMENTS +
  • SEE ALSO +
  • AUTHOR +
  • REVISION -
    PCRE2 REGULAR EXPRESSION DETAILS
    -

    +

    PCRE2 REGULAR EXPRESSION DETAILS

    +

    The syntax and semantics of the regular expressions that are supported by PCRE2 are described in detail below. There is a quick-reference syntax summary in the pcre2syntax @@ -61,15 +59,15 @@ conflict with the Perl syntax in order to provide some compatibility with regular expressions in Python, .NET, and Oniguruma. There are in addition some options that enable alternative syntax and semantics that are not the same as in Perl. -

    -

    +

    +

    Perl's regular expressions are described in its own documentation, and regular expressions in general are covered in a number of books, some of which have copious examples. Jeffrey Friedl's "Mastering Regular Expressions", published by O'Reilly, covers regular expressions in great detail. This description of PCRE2's regular expressions is intended as reference material. -

    -

    +

    +

    This document discusses the regular expression patterns that are supported by PCRE2 when its main matching function, pcre2_match(), is used. PCRE2 also has an alternative matching function, pcre2_dfa_match(), which matches @@ -79,9 +77,9 @@ disadvantages of the alternative function, and how it differs from the normal function, are discussed in the pcre2matching page. -

    -
    EBCDIC CHARACTER CODES
    -

    +

    +

    EBCDIC CHARACTER CODES

    +

    Most computers use ASCII or Unicode for encoding characters, and PCRE2 assumes this by default. However, it can be compiled to run in an environment that uses the EBCDIC code, which is the case for some IBM mainframe operating systems. In @@ -91,20 +89,20 @@ code points greater than 255. Differences in behaviour when PCRE2 is running in an EBCDIC environment are described in the section "EBCDIC environments" below, which you can ignore unless you really are in an EBCDIC environment. -

    -
    SPECIAL START-OF-PATTERN ITEMS
    -

    +

    +

    SPECIAL START-OF-PATTERN ITEMS

    +

    A number of options that can be passed to pcre2_compile() can also be set by special items at the start of a pattern. These are not Perl-compatible, but are provided to make these options accessible to pattern writers who are not able to change the program that processes the pattern. Any number of these items may appear, but they must all be together right at the start of the pattern string, and the letters must be in upper case. -

    -
    +

    +

    UTF support -
    -

    +

    +

    In the 8-bit and 16-bit PCRE2 libraries, characters may be coded either as single code units, or as multiple UTF-8 or UTF-16 code units. UTF-32 can be specified for the 32-bit library, in which case it constrains the character @@ -117,17 +115,17 @@ setting a UTF mode affects pattern matching is mentioned in several places below. There is also a summary of features in the pcre2unicode page. -

    -

    +

    +

    Some applications that allow their users to supply patterns may wish to restrict them to non-UTF data for security reasons. If the PCRE2_NEVER_UTF option is passed to pcre2_compile(), (*UTF) is not allowed, and its appearance in a pattern causes an error. -

    -
    +

    +

    Unicode property support -
    -

    +

    +

    Another special sequence that may appear at the start of a pattern is (*UCP). This has the same effect as setting the PCRE2_UCP option: it causes sequences such as \d and \w to use Unicode properties to determine character types, @@ -137,27 +135,27 @@ for characters with code points greater than 127, even when UTF is not set. These behaviours can be changed within the pattern; see the section entitled "Internal Option Setting" below. -

    -

    +

    +

    Some applications that allow their users to supply patterns may wish to restrict them for security reasons. If the PCRE2_NEVER_UCP option is passed to pcre2_compile(), (*UCP) is not allowed, and its appearance in a pattern causes an error. -

    -
    +

    +

    Locking out empty string matching -
    -

    +

    +

    Starting a pattern with (*NOTEMPTY) or (*NOTEMPTY_ATSTART) has the same effect as passing the PCRE2_NOTEMPTY or PCRE2_NOTEMPTY_ATSTART option to whichever matching function is subsequently called to match the pattern. These options lock out the matching of empty strings, either entirely, or only at the start of the subject. -

    -
    +

    +

    Disabling auto-possessification -
    -

    +

    +

    If a pattern starts with (*NO_AUTO_POSSESS), it has the same effect as setting the PCRE2_NO_AUTO_POSSESS option, or calling pcre2_set_optimize() with a PCRE2_AUTO_POSSESS_OFF directive. This stops PCRE2 from making quantifiers @@ -165,50 +163,51 @@ possessive when what follows cannot match the repeated item. For example, by default a+b is treated as a++b. For more details, see the pcre2api documentation. -

    -
    +

    +

    Disabling start-up optimizations -
    -

    +

    +

    If a pattern starts with (*NO_START_OPT), it has the same effect as setting the PCRE2_NO_START_OPTIMIZE option, or calling pcre2_set_optimize() with a PCRE2_START_OPTIMIZE_OFF directive. This disables several optimizations for quickly reaching "no match" results. For more details, see the pcre2api documentation. -

    -
    +

    +

    Disabling automatic anchoring -
    -

    +

    +

    If a pattern starts with (*NO_DOTSTAR_ANCHOR), it has the same effect as -setting the PCRE2_NO_DOTSTAR_ANCHOR option, or calling pcre2_set_optimize() -with a PCRE2_DOTSTAR_ANCHOR_OFF directive. This disables optimizations that -apply to patterns whose top-level branches all start with .* (match any number -of arbitrary characters). For more details, see the +setting the PCRE2_NO_DOTSTAR_ANCHOR option, or +calling pcre2_set_optimize() with a PCRE2_DOTSTAR_ANCHOR_OFF directive. +This disables optimizations that apply to patterns whose top-level branches +all start with .* (match any number of arbitrary characters). For more details, +see the pcre2api documentation. -

    -
    +

    +

    Disabling JIT compilation -
    -

    +

    +

    If a pattern that starts with (*NO_JIT) is successfully compiled, an attempt by the application to apply the JIT optimization by calling pcre2_jit_compile() is ignored. -

    -
    +

    +

    Setting match resource limits -
    -

    +

    +

    The pcre2_match() function contains a counter that is incremented every time it goes round its main loop. The caller of pcre2_match() can set a limit on this counter, which therefore limits the amount of computing resource used for a match. The maximum depth of nested backtracking can also be limited; this indirectly restricts the amount of heap memory that is used, but there is also an explicit memory limit that can be set. -

    -

    +

    +

    These facilities are provided to catch runaway matches that are provoked by patterns with huge matching trees. A common example is a pattern with nested unlimited repeats applied to a long string that does not match. When one of @@ -225,12 +224,12 @@ for it to have any effect. In other words, the pattern writer can lower the limits set by the programmer, but not raise them. If there is more than one setting of one of these limits, the lower value is used. The heap limit is specified in kibibytes (units of 1024 bytes). -

    -

    +

    +

    Prior to release 10.30, LIMIT_DEPTH was called LIMIT_RECURSION. This name is still recognized for backwards compatibility. -

    -

    +

    +

    The heap limit applies only when the pcre2_match() or pcre2_dfa_match() interpreters are used for matching. It does not apply to JIT. The match limit is used (but in a different way) when JIT is being @@ -239,11 +238,11 @@ usage by those matching functions. The depth limit is ignored by JIT but is relevant for DFA matching, which uses function recursion for recursions within the pattern and for lookaround assertions and atomic groups. In this case, the depth limit controls the depth of such recursion. -

    -
    +

    +

    Newline conventions -
    -

    +

    +

    PCRE2 supports six different conventions for indicating line breaks in strings: a single CR (carriage return) character, a single LF (linefeed) character, the two-character sequence CRLF, any of the three preceding, any @@ -253,8 +252,8 @@ page has further discussion about newlines, and shows how to set the newline convention when calling pcre2_compile(). -

    -

    +

    +

    It is also possible to specify a newline convention by starting a pattern string with one of the following sequences:

    @@ -273,8 +272,8 @@ example, on a Unix system where LF is the default newline sequence, the pattern
     changes the convention to CR. That pattern matches "a\nb" because LF is no
     longer a newline. If more than one of these settings is present, the last one
     is used.
    -

    -

    +

    +

    The newline convention affects where the circumflex and dollar assertions are true. It also affects the interpretation of the dot metacharacter when PCRE2_DOTALL is not set, and the behaviour of \N when not followed by an @@ -285,19 +284,19 @@ description of \R in the section entitled "Newline sequences" below. A change of \R setting can be combined with a change of newline convention. -

    -
    +

    +

    Specifying what \R matches -
    -

    +

    +

    It is possible to restrict \R to match only CR, LF, or CRLF (instead of the complete set of Unicode line endings) by setting the option PCRE2_BSR_ANYCRLF at compile time. This effect can also be achieved by starting a pattern with (*BSR_ANYCRLF). For completeness, (*BSR_UNICODE) is also recognized, corresponding to PCRE2_BSR_UNICODE. -

    -
    CHARACTERS AND METACHARACTERS
    -

    +

    +

    CHARACTERS AND METACHARACTERS

    +

    A regular expression is a pattern that is matched against a subject string from left to right. Most characters stand for themselves in a pattern, and match the corresponding characters in the subject. As a trivial example, the pattern @@ -315,14 +314,14 @@ PCRE2_EXTRA_CASELESS_RESTRICT option is in force (either passed to pattern). If the PCRE2_EXTRA_TURKISH_CASING option is in force (either passed to pcre2_compile() or set by (*TURKISH_CASING) within the pattern), then the 'i' letters are matched according to Turkish and Azeri languages. -

    -

    +

    +

    The power of regular expressions comes from the ability to include wild cards, character classes, alternatives, and repetitions in the pattern. These are encoded in the pattern by the use of metacharacters, which do not stand for themselves but instead are interpreted in some special way. -

    -

    +

    +

    There are two different sets of metacharacters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized within square brackets. Outside square brackets, the metacharacters @@ -349,8 +348,8 @@ exception to this is \u{...} which is an ECMAScript compatibility feature that is recognized only when the PCRE2_EXTRA_ALT_BSUX option is set. ECMAScript does not ignore such white space; it causes the item to be interpreted as literal. -

    -

    +

    +

    Part of a pattern that is in square brackets is called a "character class". In a character class the only metacharacters are:

    @@ -372,30 +371,30 @@ character class. Option settings can be changed within a pattern; see the
     section entitled
     "Internal Option Setting"
     below.
    -

    -

    +

    +

    The following sections describe the use of each of the metacharacters. -

    -
    BACKSLASH
    -

    +

    +

    BACKSLASH

    +

    The backslash character has several uses. Firstly, if it is followed by a character that is not a digit or a letter, it takes away any special meaning that character may have. This use of backslash as an escape character applies both inside and outside character classes. -

    -

    +

    +

    For example, if you want to match a * character, you must write \* in the pattern. This escaping action applies whether or not the following character would otherwise be interpreted as a metacharacter, so it is always safe to precede a non-alphanumeric with backslash to specify that it stands for itself. In particular, if you want to match a backslash, you write \\. -

    -

    +

    +

    Only ASCII digits and letters have any special meaning after a backslash. All other characters (in particular, those whose code points are greater than 127) are treated as literals. -

    -

    +

    +

    If you want to treat all characters in a sequence as literals, you can do so by putting them between \Q and \E. Note that this includes white space even when the PCRE2_EXTENDED option is set so that most other white space is ignored. The @@ -420,19 +419,19 @@ by \E later in the pattern, the literal interpretation continues to the end of the pattern (that is, \E is assumed at the end). If the isolated \Q is inside a character class, this causes an error, because the character class is then not terminated by a closing square bracket. -

    -

    +

    +

    Another difference from Perl is that any appearance of \Q or \E inside what might otherwise be a quantifier causes PCRE2 not to recognize the sequence as a quantifier. Perl recognizes a quantifier if (redundantly) either of the numbers is inside \Q...\E, but not if the separating comma is. When not recognized as a quantifier a sequence such as {\Q1\E,2} is treated as the literal string "{1,2}". -

    -
    +

    +

    Non-printing characters -
    -

    +

    +

    A second use of backslash provides a way of encoding non-printing characters in patterns in a visible manner. There is no restriction on the appearance of non-printing characters in a pattern, but when a pattern is being prepared by @@ -458,26 +457,26 @@ A description of how back references work is given later, following the discussion of parenthesized groups. -

    -

    +

    +

    By default, after \x that is not followed by {, one or two hexadecimal digits are read (letters can be in upper or lower case). If the character that follows \x is neither { nor a hexadecimal digit, an error occurs. This is different from Perl's default behaviour, which generates a NUL character, but is in line with the behaviour of Perl's 'strict' mode in re. -

    -

    +

    +

    Any number of hexadecimal digits may appear between \x{ and }. If a character other than a hexadecimal digit appears between \x{ and }, or if there is no terminating }, an error occurs. -

    -

    +

    +

    Characters whose code points are less than 256 can be defined by either of the two syntaxes for \x or by an octal sequence. There is no difference in the way they are handled. For example, \xdc is exactly the same as \x{dc} or \334. However, using the braced versions does make such sequences easier to read. -

    -

    +

    +

    Support is available for some ECMAScript (aka JavaScript) escape sequences via two compile-time options. If PCRE2_ALT_BSUX is set, the sequence \x followed by { is not recognized. Only if \x is followed by two hexadecimal digits is it @@ -485,28 +484,28 @@ recognized as a character escape. Otherwise it is interpreted as a literal "x" character. In this mode, support for code points greater than 256 is provided by \u, which must be followed by four hexadecimal digits; otherwise it is interpreted as a literal "u" character. -

    -

    +

    +

    PCRE2_EXTRA_ALT_BSUX has the same effect as PCRE2_ALT_BSUX and, in addition, \u{hhh..} is recognized as the character specified by hexadecimal code point. There may be any number of hexadecimal digits, but unlike other places that also use curly brackets, spaces are not allowed and would result in the string being interpreted as a literal. This syntax is from ECMAScript 6. -

    -

    +

    +

    The \N{U+hhh..} escape sequence is recognized only when PCRE2 is operating in UTF mode. Perl also uses \N{name} to specify characters by Unicode name; PCRE2 does not support this. Note that when \N is not followed by an opening brace (curly bracket) it has an entirely different meaning, matching any character that is not a newline. -

    -

    +

    +

    There are some legacy applications where the escape sequence \r is expected to match a newline. If the PCRE2_EXTRA_ESCAPED_CR_IS_LF option is set, \r in a pattern is converted to \n so that it matches a LF (linefeed) instead of a CR (carriage return) character. -

    -

    +

    +

    An error occurs if \c is not followed by a character whose ASCII code point is in the range 32 to 126. The precise effect of \cx is as follows: if x is a lower case letter, it is converted to upper case. Then bit 6 of the character @@ -514,51 +513,51 @@ lower case letter, it is converted to upper case. Then bit 6 of the character 5A), but \c{ becomes hex 3B ({ is 7B), and \c; becomes hex 7B (; is 3B). If the code unit following \c has a code point less than 32 or greater than 126, a compile-time error occurs. -

    -

    +

    +

    For differences in the way some escapes behave in EBCDIC environments, see section "EBCDIC environments" below. -

    -
    +

    +

    Octal escapes and back references -
    -

    +

    +

    The escape \o must be followed by a sequence of octal digits, enclosed in braces. An error occurs if this is not the case. This escape provides a way of specifying character code points as octal numbers greater than 0777, and it also allows octal numbers and backreferences to be unambiguously distinguished. -

    -

    +

    +

    If braces are not used, after \0 up to two further octal digits are read. However, if the PCRE2_EXTRA_NO_BS0 option is set, at least one more octal digit must follow \0 (use \00 to generate a NUL character). Make sure you supply two digits after the initial zero if the pattern character that follows is itself an octal digit. -

    -

    +

    +

    Inside a character class, when a backslash is followed by any octal digit, up to three octal digits are read to generate a code point. Any subsequent digits stand for themselves. The sequences \8 and \9 are treated as the literal characters "8" and "9". -

    -

    +

    +

    Outside a character class, Perl's handling of a backslash followed by a digit other than 0 is complicated by ambiguity, and Perl has changed over time, causing PCRE2 also to change. From PCRE2 release 10.45 there is an option called PCRE2_EXTRA_PYTHON_OCTAL that causes PCRE2 to use Python's unambiguous rules. The next two subsections describe the two sets of rules. -

    -

    +

    +

    For greater clarity and unambiguity, it is best to avoid following \ by a digit greater than zero. Instead, use \o{...} or \x{...} to specify numerical character code points, and \g{...} to specify backreferences. -

    -
    +

    +

    Perl rules for non-class backslash 1-9 -
    -

    +

    +

    All the digits that follow the backslash are read as a decimal number. If the number is less than 10, begins with the digit 8 or 9, or if there are at least that many previous capture groups in the expression, the entire sequence is @@ -578,11 +577,11 @@ a character code. For example: Note that octal values of 100 or greater that are specified using this syntax must not be introduced by a leading zero, because no more than three octal digits are ever read. -

    -
    +

    +

    Python rules for non_class backslash 1-9 -
    -

    +

    +

    If there are at least three octal digits after the backslash, exactly three are read as an octal code point number, but the value must be no greater than \377, even in modes where higher code point values are supported. Any @@ -591,11 +590,11 @@ digits, the sequence is taken as a decimal back reference. Thus, for example, \12 is always a back reference, independent of how many captures there are in the pattern. An error is generated for a reference to a non-existent capturing group. -

    -
    +

    +

    Constraints on character values -
    -

    +

    +

    Characters that are specified using octal or hexadecimal numbers are limited to certain values, as follows:

    @@ -609,47 +608,47 @@ so-called "surrogate" code points). The check for these can be disabled by the
     caller of pcre2_compile() by setting the option
     PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES. However, this is possible only in UTF-8
     and UTF-32 modes, because these values are not representable in UTF-16.
    -

    -
    +

    +

    Escape sequences in character classes -
    -

    +

    +

    All the sequences that define a single character value can be used both inside and outside character classes. In addition, inside a character class, \b is interpreted as the backspace character (hex 08). -

    -

    +

    +

    When not followed by an opening brace, \N is not allowed in a character class. \B, \R, and \X are not special inside a character class. Like other unrecognized alphabetic escape sequences, they cause an error. Outside a character class, these sequences have different meanings. -

    -
    +

    +

    Unsupported escape sequences -
    -

    +

    +

    In Perl, the sequences \F, \l, \L, \u, and \U are recognized by its string handler and used to modify the case of following characters. By default, PCRE2 does not support these escape sequences in patterns. However, if either of the PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX options is set, \U matches a "U" character, and \u can be used to define a character by code point, as described above. -

    -
    +

    +

    Absolute and relative backreferences -
    -

    +

    +

    The sequence \g followed by a signed or unsigned number, optionally enclosed in braces, is an absolute or relative backreference. A named backreference can be coded as \g{name}. Backreferences are discussed later, following the discussion of parenthesized groups. -

    -
    +

    +

    Absolute and relative subroutine calls -
    -

    +

    +

    For compatibility with Oniguruma, the non-Perl syntax \g followed by a name or a number enclosed either in angle brackets or single quotes, is an alternative syntax for referencing a capture group as a subroutine. Details are discussed @@ -658,11 +657,11 @@ Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are no synonymous. The former is a backreference; the latter is a subroutine call. -

    -
    +

    +

    Generic character types -
    -

    +

    +

    Another use of backslash is for specifying generic character types:

       \d     any decimal digit
    @@ -685,23 +684,23 @@ different meaning. See the section entitled
     "Non-printing characters"
     above for details. Perl also uses \N{name} to specify characters by Unicode
     name; PCRE2 does not support this.
    -

    -

    +

    +

    Each pair of lower and upper case escape sequences partitions the complete set of characters into two disjoint sets. Any given character matches one, and only one, of each pair. The sequences can appear both inside and outside character classes. They each match one character of the appropriate type. If the current matching point is at the end of the subject string, all of them fail, because there is no character to match. -

    -

    +

    +

    The default \s characters are HT (9), LF (10), VT (11), FF (12), CR (13), and space (32), which are defined as white space in the "C" locale. This list may vary if locale-specific matching is taking place. For example, in some locales the "non-breaking space" character (\xA0) is recognized as white space, and in others the VT character is not. -

    -

    +

    +

    A "word" character is an underscore or any character that is a letter or digit. By default, the definition of letters and digits is controlled by PCRE2's low-valued character tables, and may vary if locale-specific matching is taking @@ -713,8 +712,8 @@ page). For example, in a French locale such as "fr_FR" in Unix-like systems, or "french" in Windows, some character codes greater than 127 are used for accented letters, and these are then matched by \w. The use of locales with Unicode is discouraged. -

    -

    +

    +

    By default, characters whose code points are greater than 127 never match \d, \s, or \w, and always match \D, \S, and \W, although this may be different for characters in the range 128-255 when locale-specific matching is happening. @@ -730,22 +729,22 @@ determine character types, as follows: The addition of \p{Mn} (non-spacing mark) and the replacement of an explicit test for underscore with a test for \p{Pc} (connector punctuation) happened in PCRE2 release 10.43. This brings PCRE2 into line with Perl. -

    -

    +

    +

    The upper case escapes match the inverse sets of characters. Note that \d matches only decimal digits, whereas \w matches any Unicode digit, as well as other character categories. Note also that PCRE2_UCP affects \b, and \B because they are defined in terms of \w and \W. Matching these sequences is noticeably slower when PCRE2_UCP is set. -

    -

    +

    +

    The effect of PCRE2_UCP on any one of these escape sequences can be negated by the options PCRE2_EXTRA_ASCII_BSD, PCRE2_EXTRA_ASCII_BSS, and PCRE2_EXTRA_ASCII_BSW, respectively. These options can be set and reset within a pattern by means of an internal option setting (see below). -

    -

    +

    +

    The sequences \h, \H, \v, and \V, in contrast to the other sequences, which match only ASCII characters by default, always match a specific list of code points, whether or not PCRE2_UCP is set. The horizontal space characters are: @@ -782,11 +781,11 @@ The vertical space characters are:

    In 8-bit, non-UTF-8 mode, only the characters with code points less than 256 are relevant. -

    -
    +

    +

    Newline sequences -
    -

    +

    +

    Outside a character class, by default, the escape sequence \R matches any Unicode newline sequence. In 8-bit non-UTF-8 mode \R is equivalent to the following: @@ -800,13 +799,13 @@ LF, or one of the single characters LF (linefeed, U+000A), VT (vertical tab, U+000B), FF (form feed, U+000C), CR (carriage return, U+000D), or NEL (next line, U+0085). Because this is an atomic group, the two-character sequence is treated as a single unit that cannot be split. -

    -

    +

    +

    In other modes, two additional characters whose code points are greater than 255 are added: LS (line separator, U+2028) and PS (paragraph separator, U+2029). Unicode support is not needed for these characters to be recognized. -

    -

    +

    +

    It is possible to restrict \R to match only CR, LF, or CRLF (instead of the complete set of Unicode line endings) by setting the option PCRE2_BSR_ANYCRLF at compile time. (BSR is an abbreviation for "backslash R".) This can be made @@ -829,11 +828,11 @@ with a change of newline convention; for example, a pattern can start with: They can also be combined with the (*UTF) or (*UCP) special sequences. Inside a character class, \R is treated as an unrecognized escape sequence, and causes an error. -

    -
    +

    +

    Unicode character properties -
    -

    +

    +

    When PCRE2 is built with Unicode support (the default), three additional escape sequences that match characters with specific properties are available. They can be used in any mode, though in 8-bit and 16-bit non-UTF modes these @@ -841,15 +840,15 @@ sequences are of course limited to testing characters whose code points are less than U+0100 or U+10000, respectively. In 32-bit non-UTF mode, code points greater than 0x10ffff (the Unicode limit) may be encountered. These are all treated as being in the Unknown script and with an unassigned type. -

    -

    +

    +

    Matching characters by Unicode property is not fast, because PCRE2 has to do a multistage table lookup in order to find a character's property. That is why the traditional escape sequences such as \d and \w do not use Unicode properties in PCRE2 by default, though you can make them do so by setting the PCRE2_UCP option or by starting the pattern with (*UCP). -

    -

    +

    +

    The extra escape sequences that provide property support are:

       \p{xx}   a character with the xx property
    @@ -859,14 +858,14 @@ The extra escape sequences that provide property support are:
     For compatibility with Perl, negation can be specified by including a
     circumflex between the opening brace and the property. For example, \p{^Lu} is
     the same as \P{Lu}.
    -

    -

    +

    +

    In accordance with Unicode's "loose matching" rules, ASCII white space characters, hyphens, and underscores are ignored in the properties represented by xx above. As well as the space character, ASCII white space can be tab, linefeed, vertical tab, formfeed, or carriage return. -

    -

    +

    +

    Some properties are specified as a name only; others as a name and a value, separated by a colon or an equals sign. The names and values consist of ASCII letters and digits (with one Perl-specific exception, see below). They are not @@ -887,11 +886,11 @@ binary (yes/no) properties, and some special PCRE2 properties (described Certain other Perl properties such as "InMusicalSymbols" are not supported by PCRE2. Note that \P{Any} does not match any characters, so always causes a match failure. -

    -
    +

    +

    Script properties for \p and \P -
    -

    +

    +

    There are three different syntax forms for matching a script. Each Unicode character has a basic script and, optionally, a list of other scripts ("Script Extensions") with which it is commonly used. Using the Adlam script as an @@ -903,8 +902,8 @@ equals sign is an alternative to the colon. If a script name is given without a property type, for example, \p{Adlam}, it is treated as \p{scx:Adlam}. Perl changed to this interpretation at release 5.26 and PCRE2 changed at release 10.40. -

    -

    +

    +

    Unassigned characters (and in non-UTF 32-bit mode, characters with code points greater than 0x10FFFF) are assigned the "Unknown" script. Others that are not part of an identified script are lumped together as "Common". The current list @@ -913,12 +912,12 @@ by running this command:

       pcre2test -LS
     
    -
    -

    -
    +
    +

    +

    The general category property for \p and \P -
    -

    +

    +

    Each character has exactly one Unicode general category property, specified by a two-letter abbreviation. If only one letter is specified with \p or \P, it includes all the general category properties that start with that letter. In @@ -982,8 +981,8 @@ that is not classified as a modifier or "other". From release 10.45 of PCRE2 the properties Lu, Ll, and Lt are all treated as Lc when case-independent matching is set by the PCRE2_CASELESS option or (?i) within the pattern. The other properties are not affected by caseless matching. -

    -

    +

    +

    The Cs (Surrogate) property applies only to characters whose code points are in the range U+D800 to U+DFFF. These characters are no different to any other character when PCRE2 is not in UTF mode (using the 16-bit or 32-bit library). @@ -992,33 +991,33 @@ in UTF mode, unless UTF validity checking has been turned off (see the discussion of PCRE2_NO_UTF_CHECK in the pcre2api page). -

    -

    +

    +

    The long synonyms for property names that Perl supports (such as \p{Letter}) are not supported by PCRE2, nor is it permitted to prefix any of these properties with "Is". -

    -

    +

    +

    No character that is in the Unicode table has the Cn (unassigned) property. Instead, this property is assumed for any code point that is not in the Unicode table. -

    -
    +

    +

    Binary (yes/no) properties for \p and \P -
    -

    +

    +

    Unicode defines a number of binary properties, that is, properties whose only values are true or false. You can obtain a list of those that are recognized by \p and \P, along with their abbreviations, by running this command:

       pcre2test -LP
     
    -
    -

    -
    +
    +

    +

    The Bidi_Class property for \p and \P -
    -

    +

    +

       \p{Bidi_Class:<class>}   matches a character with the given class
       \p{BC:<class>}           matches a character with the given class
    @@ -1052,11 +1051,11 @@ The recognized classes are:
     As in all property specifications, an equals sign may be used instead of a
     colon and the class names are case-insensitive. Only the short names listed
     above are recognized; PCRE2 does not at present support any long alternatives.
    -

    -
    +

    +

    Extended grapheme clusters -
    -

    +

    +

    The \X escape matches any number of Unicode characters that form an "extended grapheme cluster", and treats the sequence as an atomic group (see below). @@ -1067,50 +1066,50 @@ Unicode Standard Annex 29, "Unicode Text Segmentation". Unicode 11.0.0 abandoned the use of some previous properties that had been used for emojis. Instead it introduced various emoji-specific properties. PCRE2 uses only the Extended Pictographic property. -

    -

    +

    +

    \X always matches at least one character. Then it decides whether to add additional characters according to the following rules for ending a cluster: -

    -

    +

    +

    1. End at the end of the subject string. -

    -

    +

    +

    2. Do not end between CR and LF; otherwise end after any control character. -

    -

    +

    +

    3. Do not break Hangul (a Korean script) syllable sequences. Hangul characters are of five types: L, V, T, LV, and LVT. An L character may be followed by an L, V, LV, or LVT character; an LV or V character may be followed by a V or T character; an LVT or T character may be followed only by a T character. -

    -

    +

    +

    4. Do not end before extending characters or spacing marks or the zero-width joiner (ZWJ) character. Characters with the "mark" property always have the "extend" grapheme breaking property. -

    -

    +

    +

    5. Do not end after prepend characters. -

    -

    +

    +

    6. Do not end within emoji modifier sequences or emoji ZWJ (zero-width joiner) sequences. An emoji ZWJ sequence consists of a character with the Extended_Pictographic property, optionally followed by one or more characters with the Extend property, followed by the ZWJ character, followed by another Extended_Pictographic character. -

    -

    +

    +

    7. Do not break within emoji flag sequences. That is, do not break between regional indicator (RI) characters if there are an odd number of RI characters before the break point. -

    -

    +

    +

    8. Otherwise, end the cluster. -

    -
    +

    +

    PCRE2's additional properties -
    -

    +

    +

    As well as the standard Unicode properties described above, PCRE2 supports four more that make it possible to convert traditional escape sequences such as \w and \s to use Unicode properties. PCRE2 uses these non-standard, non-Perl @@ -1129,8 +1128,8 @@ carriage return, and any other character that has the Z (separator) property to exclude vertical tab, for Perl compatibility, but Perl changed. Xwd matches the same characters as Xan, plus those that match Mn (non-spacing mark) or Pc (connector punctuation, which includes underscore). -

    -

    +

    +

    There is another non-standard property, Xuc, which matches any character that can be represented by a Universal Character Name in C++ and other programming languages. These are the characters $, @, ` (grave accent), and all characters @@ -1139,11 +1138,11 @@ surrogates U+D800 to U+DFFF. Note that most base (ASCII) characters are excluded. (Universal Character Names are of the form \uHHHH or \UHHHHHHHH where H is a hexadecimal digit. Note that the Xuc property does not match these sequences but the characters that they represent.) -

    -
    +

    +

    Resetting the match start -
    -

    +

    +

    In normal use, the escape sequence \K causes any previously matched characters not to be included in the final matched sequence that is returned. For example, the pattern: @@ -1168,8 +1167,8 @@ For example, when the pattern (foo)\Kbar

    matches "foobar", the first substring is still set to "foo". -

    -

    +

    +

    From version 5.32.0 Perl forbids the use of \K in lookaround assertions. From release 10.38 PCRE2 also forbids this by default. However, the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option can be used when calling @@ -1185,11 +1184,11 @@ lead to odd effects. For example, consider this pattern: If the subject is "foobar", a call to pcre2_match() with a starting offset of 3 succeeds and reports the matching string as "foobar", that is, the start of the reported match is earlier than where the match started. -

    -
    +

    +

    Simple assertions -
    -

    +

    +

    The final use of backslash is for certain simple assertions. An assertion specifies a condition that has to be met at a particular point in a match, without consuming any characters from the subject string. The use of @@ -1208,8 +1207,8 @@ The backslashed assertions are: Inside a character class, \b has a different meaning; it matches the backspace character. If any other of these assertions appears in a character class, an "invalid escape sequence" error is generated. -

    -

    +

    +

    A word boundary is a position in the subject string where the current character and the previous character do not both match \w or \W (i.e. one matches \w and the other matches \W), or the start or end of the string if the @@ -1219,8 +1218,8 @@ PCRE2_UCP option. When this is done, it also affects \b and \B. Neither PCRE2 nor Perl has a separate "start of word" or "end of word" metasequence. However, whatever follows \b normally determines which it is. For example, the fragment \ba matches "a" at the start of a word. -

    -

    +

    +

    The \A, \Z, and \z assertions differ from the traditional circumflex and dollar (described in the next section) in that they only ever match at the very start and end of the subject string, whatever options are set. Thus, they are @@ -1232,29 +1231,29 @@ start at a point other than the beginning of the subject, \A can never match. The difference between \Z and \z is that \Z matches before a newline at the end of the string as well as at the very end, whereas \z matches only at the end. -

    -

    +

    +

    The \G assertion is true only when the current matching position is at the start point of the matching process, as specified by the startoffset argument of pcre2_match(). It differs from \A when the value of startoffset is non-zero. By calling pcre2_match() multiple times with appropriate arguments, you can mimic Perl's /g option, and it is in this kind of implementation where \G can be useful. -

    -

    +

    +

    Note, however, that PCRE2's implementation of \G, being true at the starting character of the matching process, is subtly different from Perl's, which defines it as true at the end of the previous match. In Perl, these can be different when the previously matched string was empty. Because PCRE2 does just one match at a time, it cannot reproduce this behaviour. -

    -

    +

    +

    If all the alternatives of a pattern begin with \G, the expression is anchored to the starting match position, and the "anchored" flag is set in the compiled regular expression. -

    -
    CIRCUMFLEX AND DOLLAR
    -

    +

    +

    CIRCUMFLEX AND DOLLAR

    +

    The circumflex and dollar metacharacters are zero-width assertions. That is, they test for a particular condition being true without consuming any characters from the subject string. These two metacharacters are concerned with @@ -1262,8 +1261,8 @@ matching the starts and ends of lines. If the newline convention is set so that only the two-character sequence CRLF is recognized as a newline, isolated CR and LF characters are treated as ordinary data characters, and are not recognized as newlines. -

    -

    +

    +

    Outside a character class, in the default matching mode, the circumflex character is an assertion that is true only if the current matching point is at the start of the subject string. If the startoffset argument of @@ -1271,8 +1270,8 @@ the start of the subject string. If the startoffset argument of never match if the PCRE2_MULTILINE option is unset. Inside a character class, circumflex has an entirely different meaning (see below). -

    -

    +

    +

    Circumflex need not be the first character of the pattern if a number of alternatives are involved, but it should be the first thing in each alternative in which it appears if the pattern is ever to match that branch. If all @@ -1280,8 +1279,8 @@ possible alternatives start with a circumflex, that is, if the pattern is constrained to match only at the start of the subject, it is said to be an "anchored" pattern. (There are also other constructs that can cause a pattern to be anchored.) -

    -

    +

    +

    The dollar character is an assertion that is true only if the current matching point is at the end of the subject string, or immediately before a newline at the end of the string (by default), unless PCRE2_NOTEOL is set. Note, however, @@ -1289,13 +1288,13 @@ that it does not actually match the newline. Dollar need not be the last character of the pattern if a number of alternatives are involved, but it should be the last item in any branch in which it appears. Dollar has no special meaning in a character class. -

    -

    +

    +

    The meaning of dollar can be changed so that it matches only at the very end of the string, by setting the PCRE2_DOLLAR_ENDONLY option at compile time. This does not affect the \Z assertion. -

    -

    +

    +

    The meanings of the circumflex and dollar metacharacters are changed if the PCRE2_MULTILINE option is set. When this is the case, a dollar character matches before any newlines in the string, as well as at the very end, and a @@ -1303,16 +1302,16 @@ circumflex matches immediately after internal newlines as well as at the start of the subject string. It does not match after a newline that ends the string, for compatibility with Perl. However, this can be changed by setting the PCRE2_ALT_CIRCUMFLEX option. -

    -

    +

    +

    For example, the pattern /^abc$/ matches the subject string "def\nabc" (where \n represents a newline) in multiline mode, but not otherwise. Consequently, patterns that are anchored in single line mode because all branches start with ^ are not anchored in multiline mode, and a match for circumflex is possible when the startoffset argument of pcre2_match() is non-zero. The PCRE2_DOLLAR_ENDONLY option is ignored if PCRE2_MULTILINE is set. -

    -

    +

    +

    When the newline convention (see "Newline conventions" below) recognizes the two-character sequence CRLF as a newline, this is @@ -1321,74 +1320,74 @@ newlines. For example, if the newline convention is "any", a multiline mode circumflex matches before "xyz" in the string "abc\r\nxyz" rather than after CR, even though CR on its own is a valid newline. (It also matches at the very start of the string, of course.) -

    -

    +

    +

    Note that the sequences \A, \Z, and \z can be used to match the start and end of the subject in both modes, and if all branches of a pattern start with \A it is always anchored, whether or not PCRE2_MULTILINE is set. -

    -
    FULL STOP (PERIOD, DOT) AND \N
    -

    +

    +

    FULL STOP (PERIOD, DOT) AND \N

    +

    Outside a character class, a dot in the pattern matches any one character in the subject string except (by default) a character that signifies the end of a line. One or more characters may be specified as line terminators (see "Newline conventions" above). -

    -

    +

    +

    Dot never matches a single line-ending character. When the two-character sequence CRLF is the only line ending, dot does not match CR if it is immediately followed by LF, but otherwise it matches all characters (including isolated CRs and LFs). When ANYCRLF is selected for line endings, no occurrences of CR of LF match dot. When all Unicode line endings are being recognized, dot does not match CR or LF or any of the other line ending characters. -

    -

    +

    +

    The behaviour of dot with regard to newlines can be changed. If the PCRE2_DOTALL option is set, a dot matches any one character, without exception. If the two-character sequence CRLF is present in the subject string, it takes two dots to match it. -

    -

    +

    +

    The handling of dot is entirely independent of the handling of circumflex and dollar, the only relationship being that they both involve newlines. Dot has no special meaning in a character class. -

    -

    +

    +

    The escape sequence \N when not followed by an opening brace behaves like a dot, except that it is not affected by the PCRE2_DOTALL option. In other words, it matches any character except one that signifies the end of a line. -

    -

    +

    +

    When \N is followed by an opening brace it has a different meaning. See the section entitled -"Non-printing characters" +"Non-printing characters" above for details. Perl also uses \N{name} to specify characters by Unicode name; PCRE2 does not support this. -

    -
    MATCHING A SINGLE CODE UNIT
    -

    +

    +

    MATCHING A SINGLE CODE UNIT

    +

    Outside a character class, the escape sequence \C matches any one code unit, whether or not a UTF mode is set. In the 8-bit library, one code unit is one byte; in the 16-bit library it is a 16-bit unit; in the 32-bit library it is a 32-bit unit. Unlike a dot, \C always matches line-ending characters. The feature is provided in Perl in order to match individual bytes in UTF-8 mode, but it is unclear how it can usefully be used. -

    -

    +

    +

    Because \C breaks up characters into individual code units, matching one unit with \C in UTF-8 or UTF-16 mode means that the rest of the string may start with a malformed UTF character. This has undefined results, because PCRE2 assumes that it is matching character by character in a valid UTF string (by default it checks the subject string's validity at the start of processing unless the PCRE2_NO_UTF_CHECK or PCRE2_MATCH_INVALID_UTF option is used). -

    -

    +

    +

    An application can lock out the use of \C by setting the PCRE2_NEVER_BACKSLASH_C option when compiling a pattern. It is also possible to build PCRE2 with the use of \C permanently disabled. -

    -

    +

    +

    PCRE2 does not allow \C to appear in lookbehind assertions (described below) in UTF-8 or UTF-16 modes, because this would make it impossible to calculate @@ -1396,13 +1395,13 @@ the length of the lookbehind. Neither the alternative matching function pcre2_dfa_match() nor the JIT optimizer support \C in these UTF modes. The former gives a match-time error; the latter fails to optimize and so the match is always run using the interpreter. -

    -

    +

    +

    In the 32-bit library, however, \C is always supported (when not explicitly locked out) because it always matches a single code unit, whether or not UTF-32 is specified. -

    -

    +

    +

    In general, the \C escape sequence is best avoided. However, one way of using it that avoids the problem of malformed UTF-8 or UTF-16 characters is to use a lookahead to check the length of the next character, as in this pattern, which @@ -1420,9 +1419,9 @@ below). The assertions at the start of each branch check the next UTF-8 character for values whose encoding uses 1, 2, 3, or 4 bytes, respectively. The character's individual bytes are then captured by the appropriate number of \C groups. -

    -
    SQUARE BRACKETS AND CHARACTER CLASSES
    -

    +

    +

    SQUARE BRACKETS AND CHARACTER CLASSES

    +

    An opening square bracket introduces a character class, terminated by a closing square bracket. A closing square bracket on its own is not special by default. If a closing square bracket is required as a member of the class, it should be @@ -1430,24 +1429,24 @@ the first data character in the class (after an initial circumflex, if present) or escaped with a backslash. This means that, by default, an empty class cannot be defined. However, if the PCRE2_ALLOW_EMPTY_CLASS option is set, a closing square bracket at the start does end the (empty) class. -

    -

    +

    +

    A character class matches a single character in the subject. A matched character must be in the set of characters defined by the class, unless the first character in the class definition is a circumflex, in which case the subject character must not be in the set defined by the class. If a circumflex is actually required as a member of the class, ensure it is not the first character, or escape it with a backslash. -

    -

    +

    +

    For example, the character class [aeiou] matches any lower case English vowel, whereas [^aeiou] matches all other characters. Note that a circumflex is just a convenient notation for specifying the characters that are in the class by enumerating those that are not. A class that starts with a circumflex is not an assertion; it still consumes a character from the subject string, and therefore it fails to match if the current pointer is at the end of the string. -

    -

    +

    +

    Characters in a class may be specified by their code points using \o, \x, or \N{U+hh..} in the usual way. When caseless matching is set, any letters in a class represent both their upper case and lower case versions, so for example, @@ -1459,14 +1458,14 @@ respectively when either PCRE2_UTF or PCRE2_UCP is set. If you do not want these ASCII/non-ASCII case equivalences, you can suppress them by setting PCRE2_EXTRA_CASELESS_RESTRICT, either as an option in a compile context, or by including (*CASELESS_RESTRICT) or (?r) within a pattern. -

    -

    +

    +

    Characters that might indicate line breaks are never treated in any special way when matching character classes, whatever line-ending sequence is in use, and whatever setting of the PCRE2_DOTALL and PCRE2_MULTILINE options is used. A class such as [^a] always matches one of these characters. -

    -

    +

    +

    The generic character type escape sequences \d, \D, \h, \H, \p, \P, \s, \S, \v, \V, \w, and \W may appear in a character class, and add the characters that they match to the class. For example, [\dABCDEF] matches any @@ -1479,8 +1478,8 @@ class; it matches the backspace character. The sequences \B, \R, and \X are not special inside a character class. Like any other unrecognized escape sequences, they cause an error. The same is true for \N when not followed by an opening brace. -

    -

    +

    +

    The minus (hyphen) character can be used to specify a range of characters in a character class. For example, [d-m] matches any letter between d and m, inclusive. If a minus character is required in a class, it must be escaped with @@ -1488,21 +1487,21 @@ a backslash or appear in a position where it cannot be interpreted as indicating a range, typically as the first or last character in the class, or immediately after a range. For example, [b-d-z] matches letters in the range b to d, a hyphen character, or z. -

    -

    +

    +

    There is some special treatment for alphabetic ranges in EBCDIC environments; see the section "EBCDIC environments" below. -

    -

    +

    +

    Perl treats a hyphen as a literal if it appears before or after a POSIX class (see below) or before or after a character type escape such as \d or \H. However, unless the hyphen is the last character in the class, Perl outputs a warning in its warning mode, as this is most likely a user error. As PCRE2 has no facility for warning, an error is given in these cases. -

    -

    +

    +

    It is not possible to have the literal character "]" as the end character of a range. A pattern such as [W-]46] is interpreted as a class of two characters ("W" and "-") followed by a literal string "46]", so it would match "W46]" or @@ -1510,8 +1509,8 @@ range. A pattern such as [W-]46] is interpreted as a class of two characters the end of a range, so [W-\]46] is interpreted as a class containing a range and two other characters. The octal or hexadecimal representation of "]" can also be used to end a range. -

    -

    +

    +

    Ranges normally include all code points between the start and end characters, inclusive. They can also be used for code points specified numerically, for example [\000-\037]. Ranges can include any characters that are valid for the @@ -1520,23 +1519,23 @@ whose code points lie between 0xd800 and 0xdfff inclusive) may not be specified explicitly by default (the PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES option disables this check). However, ranges such as [\x{d7ff}-\x{e000}], which include the surrogates, are always permitted. -

    -

    +

    +

    If a range that includes letters is used when caseless matching is set, it matches the letters in either case. For example, [W-c] is equivalent to [][\\^_`wxyzabc], matched caselessly, and in a non-UTF mode, if character tables for a French locale are in use, [\xc8-\xcb] matches accented E characters in both cases. -

    -

    +

    +

    A circumflex can conveniently be used with the upper case character types to specify a more restricted set of characters than the matching lower case type. For example, the class [^\W_] matches any letter or digit, but not underscore, whereas [\w] includes underscore. A positive character class should be read as "something OR something OR ..." and a negative class as "NOT something AND NOT something AND NOT ...". -

    -

    +

    +

    The metacharacters that are recognized in character classes are backslash, hyphen (when it can be interpreted as specifying a range), circumflex (only at the start), and the terminating closing square bracket. An opening @@ -1547,63 +1546,63 @@ below), or a special compatibility feature (see "Compatibility feature for word boundaries" below. Escaping any non-alphanumeric character in a class turns it into a literal, whether or not it would otherwise be a metacharacter. -

    -
    PERL EXTENDED CHARACTER CLASSES
    -

    +

    +

    PERL EXTENDED CHARACTER CLASSES

    +

    From release 10.45 PCRE2 supports Perl's (?[...]) extended character class syntax. This can be used to perform set operations such as intersection on character classes. -

    -

    +

    +

    The syntax permitted within (?[...]) is quite different to ordinary character classes. Inside the extended class, there is an expression syntax consisting of "atoms", operators, and ordinary parentheses "()" used for grouping. Such classes always have the Perl /xx modifier (PCRE2 option PCRE2_EXTENDED_MORE) turned on within them. This means that literal space and tab characters are ignored everywhere in the class. -

    -

    +

    +

    The allowed atoms are individual characters specified by escape sequences such as \n or \x{123}, character types such as \d, POSIX classes such as [:alpha:], and nested ordinary (non-extended) character classes. For example, in (?[\d & [...]]) the nested class [...] follows the usual rules for ordinary character classes, in which parentheses are not metacharacters, and character literals and ranges are permitted. -

    -

    +

    +

    Character literals and ranges may not appear outside a nested ordinary character class because they are not atoms in the extended syntax. The extended syntax does not introduce any additional escape sequences, so (?[\y]) is an unknown escape, as it would be in [\y]. -

    -

    +

    +

    In the extended syntax, ^ does not negate a class (except within an ordinary class nested inside an extended class); it is instead a binary operator. -

    -

    +

    +

    The binary operators are "&" (intersection), "|" or "+" (union), "-" (subtraction) and "^" (symmetric difference). These are left-associative and "&" has higher (tighter) precedence, while the others have equal lower precedence. The one prefix unary operator is "!" (complement), with highest precedence. -

    -
    UTS#18 EXTENDED CHARACTER CLASSES
    -

    +

    +

    UTS#18 EXTENDED CHARACTER CLASSES

    +

    The PCRE2_ALT_EXTENDED_CLASS option enables an alternative to Perl's (?[...]) syntax, allowing instead extended class behaviour inside ordinary [...] character classes. This altered syntax for [...] classes is loosely described by the Unicode standard UTS#18. The PCRE2_ALT_EXTENDED_CLASS option does not prevent use of (?[...]) classes; it just changes the meaning of all [...] classes that are not nested inside a Perl (?[...]) class. -

    -

    +

    +

    Firstly, in ordinary Perl [...] syntax, an expression such as "[a[]" is a character class with two literal characters "a" and "[", but in UTS#18 extended classes the "[" character becomes an additional metacharacter within classes, denoting the start of a nested class, so a literal "[" must be escaped as "\[". -

    -

    +

    +

    Secondly, within the UTS#18 extended syntax, there are operators "||", "&&", "--" and "~~" which denote character class union, intersection, subtraction, and symmetric difference respectively. In standard Perl syntax, these would @@ -1613,21 +1612,21 @@ in constructs such as [\p{L}--[QW]] for "Unicode letters, other than Q and W". A literal "-" at the start or end of a range must be escaped, so while "[--1]" in Perl syntax is the range from hyphen to "1", it must be escaped as "[\--1]" in UTS#18 extended classes. -

    -

    +

    +

    Unlike Perl's (?[...]) extended classes, the PCRE2_EXTENDED_MORE option to ignore space and tab characters is not automatically enabled for UTS#18 extended classes, but it is honoured if set. -

    -

    +

    +

    Extended UTS#18 classes can be nested, and nested classes are themselves extended classes (unlike Perl, where nested classes must be simple classes). For example, [\p{L}&&[\p{Thai}||\p{Greek}]] matches any letter that is in the Thai or Greek scripts. Note that this means that no special grouping characters (such as the parentheses used in Perl's (?[...]) class syntax) are needed. -

    -

    +

    +

    Individual class items (literal characters, literal ranges, properties such as \d or \p{...}, and nested classes) can be combined by juxtaposition or by an operator. Juxtaposition is the implicit union operator, and binds more tightly @@ -1635,13 +1634,13 @@ than any explicit operator. Thus a sequence of literals and/or ranges behaves as if it is enclosed in square brackets. For example, [A-Z0-9&&[^E8]] is the same as [[A-Z0-9]&&[^E8]], which matches any upper case alphanumeric character except "E" or "8". -

    -

    +

    +

    Precedence between the explicit operators is not defined, so mixing operators is a syntax error. For example, [A&&B--C] is an error, but [A&&[B--C]] is valid. -

    -

    +

    +

    This is an emerging syntax which is being adopted gradually across the regex ecosystem: for example JavaScript adopted the "/v" flag in ECMAScript 2024; Python's "re" module reserves the syntax for future use with a FutureWarning @@ -1650,16 +1649,16 @@ providing insufficient guidance, engines interpret the syntax differently. Rust's "regex" crate and Python's "regex" PyPi module both implement UTS#18 extended classes, but with slight incompatibilities ([A||B&&C] is parsed as [A||[B&&C]] in Python's "regex" but as [[A||B]&&C] in Rust's "regex"). -

    -

    +

    +

    PCRE2's syntax adds syntax restrictions similar to ECMASCript's /v flag, so that all the UTS#18 extended classes accepted as valid by PCRE2 have the property that they are interpreted either with the same behaviour, or as invalid, by all other major engines. Please file an issue if you are aware of cross-engine differences in behaviour between PCRE2 and another major engine. -

    -
    POSIX CHARACTER CLASSES
    -

    +

    +

    POSIX CHARACTER CLASSES

    +

    Perl supports the POSIX notation for character classes. This uses names enclosed by [: and :] within the enclosing square brackets. PCRE2 also supports this notation, in both ordinary and extended classes. For example, @@ -1688,8 +1687,8 @@ The default "space" characters are HT (9), LF (10), VT (11), FF (12), CR (13), and space (32). If locale-specific matching is taking place, the list of space characters may be different; there may be fewer or more of them. "Space" and \s match the same set of characters, as do "word" and \w. -

    -

    +

    +

    The name "word" is a Perl extension, and "blank" is a GNU extension from Perl 5.8. Another Perl extension is negation, which is indicated by a ^ character after the colon. For example, @@ -1699,8 +1698,8 @@ after the colon. For example, matches "1", "2", or any non-digit. PCRE2 (and Perl) also recognize the POSIX syntax [.ch.] and [=ch=] where "ch" is a "collating element", but these are not supported, and an error is given if they are encountered. -

    -

    +

    +

    By default, characters with values greater than 127 do not match any of the POSIX character classes, although this may be different for characters in the range 128-255 when locale-specific matching is happening. However, in UCP mode, @@ -1720,8 +1719,8 @@ POSIX classes with other sequences, as follows:

    Negated versions, such as [:^alpha:] use \P instead of \p. Four other POSIX classes are handled specially in UCP mode: -

    -

    +

    +

    [:graph:] This matches characters that have glyphs that mark the page when printed. In Unicode property terms, it matches all characters with the L, M, N, P, S, or Cf @@ -1731,39 +1730,39 @@ properties, except for: U+180E Mongolian Vowel Separator U+2066 - U+2069 Various "isolate"s -

    -

    -

    +

  • +

    +

    [:print:] This matches the same characters as [:graph:] plus space characters that are not controls, that is, characters with the Zs property. -

    -

    +

    +

    [:punct:] This matches all characters that have the Unicode P (punctuation) property, plus those characters with code points less than 256 that have the S (Symbol) property. -

    -

    +

    +

    [:xdigit:] In addition to the ASCII hexadecimal digits, this also matches the "fullwidth" versions of those characters, whose Unicode code points start at U+FF10. This is a change that was made in PCRE2 release 10.43 for Perl compatibility. -

    -

    +

    +

    The other POSIX classes are unchanged by PCRE2_UCP, and match only characters with code points less than 256. -

    -

    +

    +

    There are two options that can be used to restrict the POSIX classes to ASCII characters when PCRE2_UCP is set. The option PCRE2_EXTRA_ASCII_DIGIT affects just [:digit:] and [:xdigit:]. Within a pattern, this can be set and unset by (?aT) and (?-aT). The PCRE2_EXTRA_ASCII_POSIX option disables UCP processing for all POSIX classes, including [:digit:] and [:xdigit:]. Within a pattern, (?aP) and (?-aP) set and unset both these options for consistency. -

    -
    COMPATIBILITY FEATURE FOR WORD BOUNDARIES
    -

    +

    +

    COMPATIBILITY FEATURE FOR WORD BOUNDARIES

    +

    In the POSIX.2 compliant library that was included in 4.4BSD Unix, the ugly syntax [[:<:]] and [[:>:]] is used for matching "start of word" and "end of word". PCRE2 treats these items as follows: @@ -1782,9 +1781,9 @@ normally shows which is wanted, without the need for the assertions that are used above in order to give exactly the POSIX behaviour. Note also that the PCRE2_UCP option changes the meaning of \w (and therefore \b) by default, so it also affects these POSIX sequences. -

    -
    VERTICAL BAR
    -

    +

    +

    VERTICAL BAR

    +

    Vertical bar characters are used to separate alternative patterns. For example, the pattern

    @@ -1797,9 +1796,9 @@ that succeeds is used. If the alternatives are within a group
     (defined below),
     "succeeds" means matching the rest of the main pattern as well as the
     alternative in the group.
    -

    -
    INTERNAL OPTION SETTING
    -

    +

    +

    INTERNAL OPTION SETTING

    +

    The settings of several options can be changed within a pattern by a sequence of letters enclosed between "(?" and ")". The following are Perl-compatible, and are described in detail in the @@ -1817,20 +1816,20 @@ For example, (?im) sets caseless, multiline matching. It is also possible to unset these options by preceding the relevant letters with a hyphen, for example (?-im). The two "extended" options are not independent; unsetting either one cancels the effects of both of them. -

    -

    +

    +

    A combined setting and unsetting such as (?im-sx), which sets PCRE2_CASELESS and PCRE2_MULTILINE while unsetting PCRE2_DOTALL and PCRE2_EXTENDED, is also permitted. Only one hyphen may appear in the options string. If a letter appears both before and after the hyphen, the option is unset. An empty options setting "(?)" is allowed. Needless to say, it has no effect. -

    -

    +

    +

    If the first character following (? is a circumflex, it causes all of the above options to be unset. Letters may follow the circumflex to cause some options to be re-instated, but a hyphen may not appear. -

    -

    +

    +

    Some PCRE2-specific options can be changed by the same mechanism using these pairs or individual letters:

    @@ -1846,13 +1845,13 @@ pairs or individual letters:
     However, except for 'r', these are not unset by (?^), which is equivalent to
     (?-imnrsx). If 'a' is not followed by any of the upper case letters shown
     above, it sets (or unsets) all the ASCII options.
    -

    -

    +

    +

    PCRE2_EXTRA_ASCII_DIGIT has no additional effect when PCRE2_EXTRA_ASCII_POSIX is set, but including it in (?aP) means that (?-aP) suppresses all ASCII restrictions for POSIX classes. -

    -

    +

    +

    When one of these option changes occurs at top level (that is, not inside group parentheses), the change applies until a subsequent change, or the end of the pattern. An option change within a group (see below for a description of @@ -1872,8 +1871,8 @@ matches "ab", "aB", "c", and "C", even though when matching "C" the first branch is abandoned before the option setting. This is because the effects of option settings happen at compile time. There would be some very weird behaviour otherwise. -

    -

    +

    +

    As a convenient shorthand, if any option settings are required at the start of a non-capturing group (see the next section), the option letters may appear between the "?" and the ":". Thus the two patterns @@ -1882,8 +1881,8 @@ appear between the "?" and the ":". Thus the two patterns (?:(?i)saturday|sunday)

    match exactly the same set of strings. -

    -

    +

    +

    Note: There are other PCRE2-specific options, applying to the whole pattern, which can be set by the application when the compiling function is called. In addition, the pattern can contain special leading sequences such as @@ -1895,9 +1894,9 @@ to set UTF and Unicode property modes; they are equivalent to setting the PCRE2_UTF and PCRE2_UCP options, respectively. However, the application can set the PCRE2_NEVER_UTF or PCRE2_NEVER_UCP options, which lock out the use of the (*UTF) and (*UCP) sequences. -

    -
    GROUPS
    -

    +

    +

    GROUPS

    +

    Groups are delimited by parentheses (round brackets), which can be nested. Turning part of a pattern into a group does two things:
    @@ -1915,8 +1914,8 @@ matches, the portion of the subject string that matched the group is passed back to the caller, separately from the portion that matched the whole pattern. (This applies only to the traditional matching function; the DFA matching function does not support capturing.) -

    -

    +

    +

    Opening parentheses are counted from left to right (starting from 1) to obtain numbers for capture groups. For example, if the string "the red king" is matched against the pattern @@ -1925,8 +1924,8 @@ matched against the pattern

    the captured substrings are "red king", "red", and "king", and are numbered 1, 2, and 3, respectively. -

    -

    +

    +

    The fact that plain parentheses fulfil two functions is not always helpful. There are often times when grouping is required without capturing. If an opening parenthesis is followed by a question mark and a colon, the group @@ -1938,8 +1937,8 @@ is matched against the pattern

  • the captured substrings are "white queen" and "queen", and are numbered 1 and 2. The maximum number of capture groups is 65535. -

    -

    +

    +

    As a convenient shorthand, if any option settings are required at the start of a non-capturing group, the option letters may appear between the "?" and the ":". Thus the two patterns @@ -1951,9 +1950,9 @@ match exactly the same set of strings. Because alternative branches are tried from left to right, and options are not reset until the end of the group is reached, an option setting in one branch does affect subsequent branches, so the above patterns match "SUNDAY" as well as "Saturday". -

    -
    DUPLICATE GROUP NUMBERS
    -

    +

    +

    DUPLICATE GROUP NUMBERS

    +

    Perl 5.10 introduced a feature whereby each alternative in a group uses the same numbers for its capturing parentheses. Such a group starts with (?| and is itself a non-capturing group. For example, consider this pattern: @@ -1987,30 +1986,30 @@ first one in the pattern with the given number. The following pattern matches A relative reference such as (?-1) is no different: it is just a convenient way of computing an absolute group number. -

    -

    +

    +

    If a condition test for a group's having matched refers to a non-unique number, the test is true if any group with that number has matched. -

    -

    +

    +

    An alternative approach to using this "branch reset" feature is to use duplicate named groups, as described in the next section. -

    -
    NAMED CAPTURE GROUPS
    -

    +

    +

    NAMED CAPTURE GROUPS

    +

    Identifying capture groups by number is simple, but it can be very hard to keep track of the numbers in complicated patterns. Furthermore, if an expression is modified, the numbers may change. To help with this difficulty, PCRE2 supports the naming of capture groups. This feature was not added to Perl until release 5.10. Python had the feature earlier, and PCRE1 introduced it at release 4.0, using the Python syntax. PCRE2 supports both the Perl and the Python syntax. -

    -

    +

    +

    In PCRE2, a capture group can be named in one of three ways: (?<name>...) or -(?'name'...) as in Perl, or (?P<name>...) as in Python. Names may be up to 128 -code units long. When PCRE2_UTF is not set, they may contain only ASCII +(?'name'...) as in Perl, or (?P<name>...) as in Python. Names may be up to +128 code units long. When PCRE2_UTF is not set, they may contain only ASCII alphanumeric characters and underscores, but must start with a non-digit. When PCRE2_UTF is set, the syntax of group names is extended to allow any Unicode letter or Unicode decimal digit. In other words, group names must match one of @@ -2025,16 +2024,16 @@ References to capture groups from other parts of the pattern, such as and conditions, can all be made by name as well as by number. -

    -

    +

    +

    Named capture groups are allocated numbers as well as names, exactly as if the names were not present. In both PCRE2 and Perl, capture groups are primarily identified by numbers; any names are just aliases for these numbers. The PCRE2 API provides function calls for extracting the complete name-to-number translation table from a compiled pattern, as well as convenience functions for extracting captured substrings by name. -

    -

    +

    +

    Warning: When more than one capture group has the same number, as described in the previous section, a name given to one of them applies to all of them. Perl allows identically numbered groups to have different names. @@ -2044,8 +2043,8 @@ Consider this pattern, where there are two capture groups, both numbered 1: Perl allows this, with both names AA and BB as aliases of group 1. Thus, after a successful match, both names yield the same value (either "aa" or "bb"). -

    -

    +

    +

    In an attempt to reduce confusion, PCRE2 does not allow the same group number to be associated with more than one name. The example above provokes a compile-time error. However, there is still scope for confusion. Consider this @@ -2056,8 +2055,8 @@ pattern: Although the second group number 1 is not explicitly named, the name AA is still an alias for any group 1. Whether the pattern matches "aa" or "bb", a reference by name to group AA yields the matched string. -

    -

    +

    +

    By default, a name must be unique within a pattern, except that duplicate names are permitted for groups with the same number, for example:

    @@ -2068,8 +2067,8 @@ option at compile time, or by the use of (?J) within the pattern, as described
     in the section entitled
     "Internal Option Setting"
     above.
    -

    -

    +

    +

    Duplicate names can be useful for patterns where only one instance of the named capture group can match. Suppose you want to match the name of a weekday, either as a 3-letter abbreviation or as the full name, and in both cases you @@ -2089,8 +2088,8 @@ the first (and in this example, the only) group of that name that matched. This saves searching to find which numbered group it was. (An alternative way of solving this problem is to use a "branch reset" group, as described in the previous section.) -

    -

    +

    +

    If you make a backreference to a non-unique named group from elsewhere in the pattern, the groups to which the name refers are checked in the order in which they appear in the overall pattern. The first one that is set is used for the @@ -2099,14 +2098,14 @@ reference. For example, this pattern matches both "foofoo" and "barbar" but not

       (?J)(?:(?<n>foo)|(?<n>bar))\k<n>
     
    -
    -

    -

    +

    +

    +

    If you make a subroutine call to a non-unique named group, the one that corresponds to the first occurrence of the name is used. In the absence of duplicate numbers this is the one with the lowest number. -

    -

    +

    +

    If you use a named reference in a condition test (see the section about conditions @@ -2117,9 +2116,9 @@ as testing by number. For further details of the interfaces for handling named capture groups, see the pcre2api documentation. -

    -
    REPETITION
    -

    +

    +

    REPETITION

    +

    Repetition is specified by quantifiers, which may follow any one of these items:

    @@ -2161,24 +2160,24 @@ taken as zero; in this case the upper limit must be present.
     This is a change in behaviour that happened in Perl 5.34.0 and PCRE2 10.43. In
     earlier versions such a sequence was not interpreted as a quantifier. Other
     regular expression engines may behave either way.
    -

    -

    +

    +

    If the characters that follow an opening brace do not match the syntax of a quantifier, the brace is taken as a literal character. In particular, this means that {,} is a literal string of three characters. -

    -

    +

    +

    Note that not every opening brace is potentially the start of a quantifier because braces are used in other items such as \N{U+345} or \k{name}. -

    -

    +

    +

    In UTF modes, quantifiers apply to characters rather than to individual code units. Thus, for example, \x{100}{2} matches two characters, each of which is represented by a two-byte sequence in a UTF-8 string. Similarly, \X{3} matches three Unicode extended grapheme clusters, each of which may be several code units long (and they may be of different lengths). -

    -

    +

    +

    The quantifier {0} is permitted, causing the expression to behave as if the previous item and the quantifier were not present. This may be useful for capture groups that are referenced as @@ -2187,8 +2186,8 @@ from elsewhere in the pattern (but see also the section entitled "Defining capture groups for use by reference only" below). Except for parenthesized groups, items that have a {0} quantifier are omitted from the compiled pattern. -

    -

    +

    +

    For convenience, the three most common quantifiers have single-character abbreviations:

    @@ -2207,8 +2206,8 @@ patterns are now accepted, but whenever an iteration of such a group matches no
     characters, matching moves on to the next item in the pattern instead of
     repeatedly matching an empty string. This does not prevent backtracking into
     any of the iterations if a subsequent item fails to match.
    -

    -

    +

    +

    By default, quantifiers are "greedy", that is, they match as much as possible (up to the maximum number of permitted repetitions), without causing the rest of the pattern to fail. The classic example of where this gives problems is in @@ -2238,32 +2237,32 @@ Because it has two uses, it can sometimes appear doubled, as in

    which matches one digit by preference, but can match two if that is the only way the rest of the pattern matches. -

    -

    +

    +

    If the PCRE2_UNGREEDY option is set (an option that is not available in Perl), the quantifiers are not greedy by default, but individual ones can be made greedy by following them with a question mark. In other words, it inverts the default behaviour. -

    -

    +

    +

    When a parenthesized group is quantified with a minimum repeat count that is greater than 1 or with a limited maximum, more memory is required for the compiled pattern, in proportion to the size of the minimum or maximum. -

    -

    +

    +

    If a pattern starts with .* or .{0,} and the PCRE2_DOTALL option (equivalent to Perl's /s) is set, thus allowing the dot to match newlines, the pattern is implicitly anchored, because whatever follows will be tried against every character position in the subject string, so there is no point in retrying the overall match at any position after the first. PCRE2 normally treats such a pattern as though it were preceded by \A. -

    -

    +

    +

    In cases where it is known that the subject string contains no newlines, it is worth setting PCRE2_DOTALL in order to obtain this optimization, or alternatively, using ^ to indicate anchoring explicitly. -

    -

    +

    +

    However, there are some cases where the optimization cannot be used. When .* is inside capturing parentheses that are the subject of a backreference elsewhere in the pattern, a match at the start may fail where a later one @@ -2273,8 +2272,8 @@ succeeds. Consider, for example:

    If the subject is "xyz123abc123" the match point is the fourth character. For this reason, such a pattern is not implicitly anchored. -

    -

    +

    +

    Another case where implicit anchoring is not applied is when the leading .* is inside an atomic group. Once again, a match at the start may fail where a later one succeeds. Consider this pattern: @@ -2285,8 +2284,8 @@ It matches "ab" in the subject "aab". The use of the backtracking control verbs (*PRUNE) and (*SKIP) also disable this optimization. To do so explicitly, either pass the compile option PCRE2_NO_DOTSTAR_ANCHOR, or call pcre2_set_optimize() with a PCRE2_DOTSTAR_ANCHOR_OFF directive. -

    -

    +

    +

    When a capture group is repeated, the value captured is the substring that matched the final iteration. For example, after

    @@ -2299,17 +2298,17 @@ captured values may have been set in previous iterations. For example, after
       (a|(b))+
     
    matches "aba" the value of the second captured substring is "b". -

    -
    ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS
    -

    +

    +

    ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS

    +

    With both maximizing ("greedy") and minimizing ("ungreedy" or "lazy") repetition, failure of what follows normally causes the repeated item to be re-evaluated to see if a different number of repeats allows the rest of the pattern to match. Sometimes it is useful to prevent this, either to change the nature of the match, or to cause it fail earlier than it otherwise might, when the author of the pattern knows there is no point in carrying on. -

    -

    +

    +

    Consider, for example, the pattern \d+foo when applied to the subject line

       123456bar
    @@ -2319,8 +2318,8 @@ action of the matcher is to try again with only 5 digits matching the \d+
     item, and then with 4, and so on, before ultimately failing. "Atomic grouping"
     (a term taken from Jeffrey Friedl's book) provides the means for specifying
     that once a group has matched, it is not to be re-evaluated in this way.
    -

    -

    +

    +

    If we use atomic grouping for the previous example, the matcher gives up immediately on failing to match "foo" the first time. The notation is a kind of special parenthesis, starting with (?> as in this example: @@ -2336,20 +2335,20 @@ This kind of parenthesized group "locks up" the part of the pattern it contains once it has matched, and a failure further into the pattern is prevented from backtracking into it. Backtracking past it to previous items, however, works as normal. -

    -

    +

    +

    An alternative description is that a group of this type matches exactly the string of characters that an identical standalone pattern would match, if anchored at the current point in the subject string. -

    -

    +

    +

    Atomic groups are not capture groups. Simple cases such as the above example can be thought of as a maximizing repeat that must swallow everything it can. So, while both \d+ and \d+? are prepared to adjust the number of digits they match in order to make the rest of the pattern match, (?>\d+) can only match an entire sequence of digits. -

    -

    +

    +

    Atomic groups in general can of course contain arbitrarily complicated expressions, and can be nested. However, when the contents of an atomic group is just a single repeated item, as in the example above, a simpler @@ -2369,23 +2368,23 @@ option is ignored. They are a convenient notation for the simpler forms of atomic group. However, there is no difference in the meaning of a possessive quantifier and the equivalent atomic group, though there may be a performance difference; possessive quantifiers should be slightly faster. -

    -

    +

    +

    The possessive quantifier syntax is an extension to the Perl 5.8 syntax. Jeffrey Friedl originated the idea (and the name) in the first edition of his book. Mike McCloskey liked it, so implemented it when he built Sun's Java package, and PCRE1 copied it from there. It found its way into Perl at release 5.10. -

    -

    +

    +

    PCRE2 has an optimization that automatically "possessifies" certain simple pattern constructs. For example, the sequence A+B is treated as A++B because there is no point in backtracking into a sequence of A's when B must follow. This feature can be disabled by the PCRE2_NO_AUTO_POSSESS option, by calling pcre2_set_optimize() with a PCRE2_AUTO_POSSESS_OFF directive, or by starting the pattern with (*NO_AUTO_POSSESS). -

    -

    +

    +

    When a pattern contains an unlimited repeat inside a group that can itself be repeated an unlimited number of times, the use of an atomic group is the only way to avoid some failing matches taking a very long time indeed. The pattern @@ -2410,23 +2409,23 @@ an atomic group, like this: ((?>\D+)|<\d+>)*[!?]

    sequences of non-digits cannot be broken, and failure happens quickly. -

    -
    BACKREFERENCES
    -

    +

    +

    BACKREFERENCES

    +

    Outside a character class, a backslash followed by a digit greater than 0 (and possibly further digits) is a backreference to a capture group earlier (that is, to its left) in the pattern, provided there have been that many previous capture groups. -

    -

    +

    +

    However, if the decimal number following the backslash is less than 8, it is always taken as a backreference, and causes an error only if there are not that many capture groups in the entire pattern. In other words, the group that is referenced need not be to the left of the reference for numbers less than 8. A "forward backreference" of this type can make sense when a repetition is involved and the group to the right has participated in an earlier iteration. -

    -

    +

    +

    It is not possible to have a numerical "forward backreference" to a group whose number is 8 or more using this syntax because a sequence such as \50 is interpreted as a character defined in octal. See the subsection entitled @@ -2435,8 +2434,8 @@ interpreted as a character defined in octal. See the subsection entitled for further details of the handling of digits following a backslash. Other forms of backreferencing do not suffer from this restriction. In particular, there is no problem when named capture groups are used (see below). -

    -

    +

    +

    Another way of avoiding the ambiguity inherent in the use of digits following a backslash is to use the \g escape sequence. This escape must be followed by a signed or unsigned number, optionally enclosed in braces. These examples are @@ -2464,14 +2463,14 @@ group 1: The use of relative references can be helpful in long patterns, and also in patterns that are created by joining together fragments that contain references within themselves. -

    -

    +

    +

    The sequence \g{+1} is a reference to the next capture group that is started after this item, and \g{+2} refers to the one after that, and so on. This kind of forward reference can be useful in patterns that repeat. Perl does not support the use of + in this way. -

    -

    +

    +

    A backreference matches whatever actually most recently matched the capture group in the current subject string, rather than anything at all that matches the group (see @@ -2488,8 +2487,8 @@ backreference, the case of letters is relevant. For example, matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capture group is matched caselessly. -

    -

    +

    +

    There are several different ways of writing backreferences to named capture groups. The .NET syntax is \k{name}, the Python syntax is (?=name), and the original Perl syntax is \k<name> or \k'name'. All of these are now supported @@ -2504,8 +2503,8 @@ We could rewrite the above example in any of the following ways: A capture group that is referenced by name may appear in the pattern before or after the reference. -

    -

    +

    +

    There may be more than one backreference to the same group. If a group has not actually been used in a particular match, backreferences to it always fail by default. For example, the pattern @@ -2515,8 +2514,8 @@ default. For example, the pattern always fails if it starts to match "a" rather than "bc". However, if the PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a backreference to an unset value matches an empty string. -

    -

    +

    +

    Because there may be many capture groups in a pattern, all digits following a backslash are taken as part of a potential backreference number. If the pattern continues with a digit character, some delimiter must be used to terminate the @@ -2524,11 +2523,11 @@ backreference. If the PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option is set, this can be white space. Otherwise, the \g{} syntax or an empty comment (see "Comments" below) can be used. -

    -
    +

    +

    Recursive backreferences -
    -

    +

    +

    A backreference that occurs inside the group to which it refers fails when the group is first used, so, for example, (a\1) never matches. However, such references can be useful inside repeated groups. For example, the pattern @@ -2541,70 +2540,70 @@ previous iteration. In order for this to work, the pattern must be such that the first iteration does not need to match the backreference. This can be done using alternation, as in the example above, or by a quantifier with a minimum of zero. -

    -

    +

    +

    For versions of PCRE2 less than 10.25, backreferences of this type used to cause the group that they reference to be treated as an atomic group. This restriction no longer applies, and backtracking into such groups can occur as normal. -

    -
    ASSERTIONS
    -

    +

    +

    ASSERTIONS

    +

    An assertion is a test that does not consume any characters. The test must succeed for the match to continue. The simple assertions coded as \b, \B, \A, \G, \Z, \z, ^ and $ are described above. -

    -

    +

    +

    More complicated assertions are coded as parenthesized groups. If matching such a group succeeds, matching continues after it, but with the matching position in the subject string reset to what it was before the assertion was processed. -

    -

    +

    +

    A special kind of assertion, called a "scan substring" assertion, matches a subpattern against a previously captured substring. This is described in the section entitled "Scan substring assertions" below. It is a PCRE2 extension, not compatible with Perl. -

    -

    +

    +

    The other goup-based assertions are of two kinds: those that look ahead of the current position in the subject string, and those that look behind it, and in each case an assertion may be positive (must match for the assertion to be true) or negative (must not match for the assertion to be true). -

    -

    +

    +

    The Perl-compatible lookaround assertions are atomic. If an assertion is true, but there is a subsequent matching failure, there is no backtracking into the assertion. However, there are some cases where non-atomic assertions can be useful. PCRE2 has some support for these, described in the section entitled "Non-atomic assertions" below, but they are not Perl-compatible. -

    -

    +

    +

    A lookaround assertion may appear as the condition in a conditional group (see below). In this case, the result of matching the assertion determines which branch of the condition is followed. -

    -

    +

    +

    Assertion groups are not capture groups. If an assertion contains capture groups within it, these are counted for the purposes of numbering the capture groups in the whole pattern. Within each branch of an assertion, locally captured substrings may be referenced in the usual way. For example, a sequence such as (.)\g{-1} can be used to check that two adjacent characters are the same. -

    -

    +

    +

    When a branch within an assertion fails to match, any substrings that were captured are discarded (as happens with any pattern branch that fails to match). A negative assertion is true only when all its branches fail to match; this means that no captured substrings are ever retained after a successful negative assertion. When an assertion contains a matching branch, what happens depends on the type of assertion. -

    -

    +

    +

    For a positive assertion, internally captured substrings in the successful branch are retained, and matching continues with the next pattern item after the assertion. For a negative assertion, a matching branch means that the @@ -2614,8 +2613,8 @@ assertion is not true. If such an assertion is being used as a condition in a the "no" branch of the condition. For other failing negative assertions, control passes to the previous backtracking point, thus discarding any captured strings within the assertion. -

    -

    +

    +

    Most assertion groups may be repeated; though it makes no sense to assert the same thing several times, the side effect of capturing in positive assertions may occasionally be useful. However, an assertion that forms the condition for @@ -2623,11 +2622,11 @@ a conditional group may not be quantified. PCRE2 used to restrict the repetition of assertions, but from release 10.35 the only restriction is that an unlimited maximum repetition is changed to be one more than the minimum. For example, {3,} is treated as {3,4}. -

    -
    +

    +

    Alphabetic assertion names -
    -

    +

    +

    Traditionally, symbolic sequences such as (?= and (?<= have been used to specify lookaround assertions. Perl 5.28 introduced some experimental alphabetic alternatives which might be easier to remember. They all start with @@ -2642,11 +2641,11 @@ the following synonyms: For example, (*pla:foo) is the same assertion as (?=foo). In the following sections, the various assertions are described using the original symbolic forms. -

    -
    +

    +

    Lookahead assertions -
    -

    +

    +

    Lookahead assertions start with (?= for positive assertions and (?! for negative assertions. For example,

    @@ -2666,17 +2665,17 @@ does not find an occurrence of "bar" that is preceded by something other than
     "foo"; it finds any occurrence of "bar" whatsoever, because the assertion
     (?!foo) is always true when the next three characters are "bar". A
     lookbehind assertion is needed to achieve the other effect.
    -

    -

    +

    +

    If you want to force a matching failure at some point in a pattern, the most convenient way to do it is with (?!) because an empty string always matches, so an assertion that requires there not to be an empty string must always fail. The backtracking control verb (*FAIL) or (*F) is a synonym for (?!). -

    -
    +

    +

    Lookbehind assertions -
    -

    +

    +

    Lookbehind assertions start with (?<= for positive assertions and (?<! for negative assertions. For example,

    @@ -2685,8 +2684,8 @@ negative assertions. For example,
     does find an occurrence of "bar" that is not preceded by "foo". The contents of
     a lookbehind assertion are restricted such that there must be a known maximum
     to the lengths of all the strings it matches. There are two cases:
    -

    -

    +

    +

    If every top-level alternative matches a fixed length, for example

       (?<=colour|color)
    @@ -2695,8 +2694,8 @@ there is a limit of 65535 characters to the lengths, which do not have to be
     the same, as this example demonstrates. This is the only kind of lookbehind
     supported by PCRE2 versions earlier than 10.43 and by the alternative matching
     function pcre2_dfa_match().
    -

    -

    +

    +

    In PCRE2 10.43 and later, pcre2_match() supports lookbehind assertions in which one or more top-level alternatives can match more than one string length, for example @@ -2709,23 +2708,23 @@ value set by the calling program (default 255 characters). Unlimited repetition (see above) can be used instead of a lookbehind assertion at the start of a pattern to get round the length limit restriction. -

    -

    +

    +

    In UTF-8 and UTF-16 modes, PCRE2 does not allow the \C escape (which matches a single code unit even in a UTF mode) to appear in lookbehind assertions, because it makes it impossible to calculate the length of the lookbehind. The \X and \R escapes, which can match different numbers of code units, are never permitted in lookbehinds. -

    -

    +

    +

    "Subroutine" calls (see below) such as (?2) or (?&X) are permitted in lookbehinds, as long as the called capture group matches a limited-length string. However, recursion, that is, a "subroutine" call into a group that is already active, is not supported. -

    -

    +

    +

    PCRE2 supports backreferences in lookbehinds, but only if certain conditions are met. The PCRE2_MATCH_UNSET_BACKREF option must not be set, there must be no use of (?| in the pattern (it creates duplicate group numbers), and if the @@ -2735,9 +2734,9 @@ matches words containing at least two characters that begin and end with the same character:

        \b(\w)\w++(?<=\1)
    -
    -

    -

    +

    +

    +

    Possessive quantifiers can be used in conjunction with lookbehind assertions to specify efficient matching at the end of subject strings. Consider a simple pattern such as @@ -2763,11 +2762,11 @@ quantifier; it can match only the entire string. The subsequent lookbehind assertion does a single test on the last four characters. If it fails, the match fails immediately. For long strings, this approach makes a significant difference to the processing time. -

    -
    +

    +

    Using multiple assertions -
    -

    +

    +

    Several assertions (of any sort) may occur in succession. For example,

       (?<=\d{3})(?<!999)foo
    @@ -2785,8 +2784,8 @@ doesn't match "123abcfoo". A pattern to do that is
     This time the first assertion looks at the preceding six characters, checking
     that the first three are digits, and then the second assertion checks that the
     preceding three characters are not "999".
    -

    -

    +

    +

    Assertions can be nested in any combination. For example,

       (?<=(?<!foo)bar)baz
    @@ -2798,9 +2797,9 @@ preceded by "foo", while
     
    is another pattern that matches "foo" preceded by three digits and any three characters that are not "999". -

    -
    NON-ATOMIC ASSERTIONS
    -

    +

    +

    NON-ATOMIC ASSERTIONS

    +

    Traditional lookaround assertions are atomic. That is, if an assertion is true, but there is a subsequent matching failure, there is no backtracking into the assertion. However, there are some cases where non-atomic positive assertions @@ -2822,8 +2821,8 @@ ignored. Inside the assertion, the greedy .* at first consumes the entire string, but then has to backtrack until the rest of the assertion can match a word, which is captured by group 1. In other words, when the assertion first succeeds, it captures the right-most word in the string. -

    -

    +

    +

    The current matching point is then reset to the start of the subject, and the rest of the pattern match checks for two occurrences of the captured word, using an ungreedy .*? to scan from the left. If this succeeds, we are done, but @@ -2831,42 +2830,42 @@ if the last word in the string does not occur twice, this part of the pattern fails. If a traditional atomic lookahead (?= or (*pla: had been used, the assertion could not be re-entered, and the whole match would fail. The pattern would succeed only if the very last word in the subject was found twice. -

    -

    +

    +

    Using a non-atomic lookahead, however, means that when the last word does not occur twice in the string, the lookahead can backtrack and find the second-last word, and so on, until either the match succeeds, or all words have been tested. -

    -

    +

    +

    Two conditions must be met for a non-atomic assertion to be useful: the contents of one or more capturing groups must change after a backtrack into the assertion, and there must be a backreference to a changed group later in the pattern. If this is not the case, the rest of the pattern match fails exactly as before because nothing has changed, so using a non-atomic assertion just wastes resources. -

    -

    +

    +

    There is one exception to backtracking into a non-atomic assertion. If an (*ACCEPT) control verb is triggered, the assertion succeeds atomically. That is, a subsequent match failure cannot backtrack into the assertion. -

    -

    +

    +

    Non-atomic assertions are not supported by the alternative matching function pcre2_dfa_match(). They are supported by JIT, but only if they do not contain any control verbs such as (*ACCEPT). (This may change in future). Note that assertions that appear as conditions for conditional groups (see below) must be atomic. -

    -
    SCAN SUBSTRING ASSERTIONS
    -

    +

    +

    SCAN SUBSTRING ASSERTIONS

    +

    A special kind of assertion, not compatible with Perl, makes it possible to check the contents of a captured substring by matching it with a subpattern. Because this involves capturing, this feature is not supported by pcre2_dfa_match(). -

    -

    +

    +

    A scan substring assertion starts with the sequence (*scan_substring: or (*scs: which is followed by a list of substring numbers (absolute or relative) and/or substring names enclosed in single quotes or angle brackets, all within @@ -2883,8 +2882,8 @@ contents of the first one that is found to be set that are scanned. When PCRE2_DUPNAMES is set and there are ambiguous group names, all groups with the same name are checked in numerical order. A scan substring assertion fails if none of the groups it references have been set. -

    -

    +

    +

    The pattern match on the substring is always anchored, that is, it must match from the start of the substring. There is no "bumpalong" if it does not match at the start. The end of the subject is temporarily reset to be the end of the @@ -2892,8 +2891,8 @@ substring, so \Z, \z, and $ will match there. However, the start of the subject is not reset. This means that ^ matches only if the substring is actually at the start of the main subject, but it also means that lookbehind assertions into what precedes the substring are possible. -

    -

    +

    +

    Here is a very simple example: find a word that contains the rare (in English) sequence of letters "rh" not at the start:

    @@ -2917,9 +2916,9 @@ characters such as "level" that are palindromes:
     Within a substring scanning subpattern, references to other groups work as
     normal. Capturing groups may appear, and will retain their values during
     ongoing matching if the assertion succeeds.
    -

    -
    SCRIPT RUNS
    -

    +

    +

    SCRIPT RUNS

    +

    In concept, a script run is a sequence of characters that are all from the same Unicode script such as Latin or Greek. However, because some scripts are commonly used together, and because some diacritical and other marks are used @@ -2929,8 +2928,8 @@ the rules that PCRE2 uses in the section entitled in the pcre2unicode documentation. -

    -

    +

    +

    If part of a pattern is enclosed between (*script_run: or (*sr: and a closing parenthesis, it fails if the sequence of characters that it matches are not a script run. After a failure, normal backtracking occurs. Script runs can be @@ -2954,9 +2953,9 @@ digits, underscore, and dots are permitted at the start:

       \s+(?=[0-9_.]*\p{Latin})(*sr:\S+)
     
    -
    -

    -

    +

    +

    +

    In many cases, backtracking into a script run pattern fragment is not desirable. The script run can employ an atomic group to prevent this. Because this is a common requirement, a shorthand notation is provided by @@ -2966,22 +2965,22 @@ this is a common requirement, a shorthand notation is provided by

    Note that the atomic group is inside the script run. Putting it outside would not prevent backtracking into the script run pattern. -

    -

    +

    +

    Support for script runs is not available if PCRE2 is compiled without Unicode support. A compile-time error is given if any of the above constructs is encountered. Script runs are not supported by the alternate matching function, pcre2_dfa_match() because they use the same mechanism as capturing parentheses. -

    -

    +

    +

    Warning: The (*ACCEPT) control verb (see below) should not be used within a script run group, because it causes an immediate exit from the group, bypassing the script run checking. -

    -
    CONDITIONAL GROUPS
    -

    +

    +

    CONDITIONAL GROUPS

    +

    It is possible to cause the matching process to obey a pattern fragment conditionally or to choose between two alternative fragments, depending on the result of an assertion, or whether a specific capture group has @@ -3000,16 +2999,16 @@ itself. This pattern fragment is an example where the alternatives are complex:

       (?(1) (A|B|C) | (D | (?(2)E|F) | E) )
     
    -
    -

    -

    +

    +

    +

    There are five kinds of condition: references to capture groups, references to recursion, two pseudo-conditions called DEFINE and VERSION, and assertions. -

    -
    +

    +

    Checking for a used capture group by number -
    -

    +

    +

    If the text between the parentheses consists of a sequence of digits, the condition is true if a capture group of that number has previously matched. If there is more than one capture group with the same number (see the earlier @@ -3022,8 +3021,8 @@ this condition) can be referenced by (?(-1), the next most recent by (?(-2), and so on. Inside loops it can also make sense to refer to subsequent groups. The next capture group to be opened can be referenced as (?(+1), and so on. The value zero in any of these forms is not used; it provokes a compile-time error. -

    -

    +

    +

    Consider the following pattern, which contains non-significant white space to make it more readable (assume the PCRE2_EXTENDED option) and to divide it into three parts for ease of discussion: @@ -3039,19 +3038,19 @@ the condition is true, and so the yes-pattern is executed and a closing parenthesis is required. Otherwise, since no-pattern is not present, the conditional group matches nothing. In other words, this pattern matches a sequence of non-parentheses, optionally enclosed in parentheses. -

    -

    +

    +

    If you were embedding this pattern in a larger one, you could use a relative reference:

       ...other stuff... ( \( )?    [^()]+    (?(-1) \) ) ...
     
    This makes the fragment independent of the parentheses in the larger pattern. -

    -
    +

    +

    Checking for a used capture group by name -
    -

    +

    +

    Perl uses the syntax (?(<name>)...) or (?('name')...) to test for a used capture group by name. For compatibility with earlier versions of PCRE1, which had this facility before Perl, the syntax (?(name)...) is also recognized. @@ -3064,11 +3063,11 @@ to use a named group gives this: If the name used in a condition of this kind is a duplicate, the test is applied to all groups of the same name, and is true if any one of them has matched. -

    -
    +

    +

    Checking for pattern recursion -
    -

    +

    +

    "Recursion" in this sense refers to any subroutine-like call from one part of the pattern to another, whether or not it is actually recursive. See the sections entitled @@ -3076,8 +3075,8 @@ sections entitled and "Groups as subroutines" below for details of recursion and subroutine calls. -

    -

    +

    +

    If a condition is the string (R), and there is no capture group with the name R, the condition is true if matching is currently in a recursion or subroutine call to the whole pattern or any capture group. If digits follow the letter R, @@ -3091,28 +3090,28 @@ However, in both cases, if there is a capture group with a matching name, the condition tests for its being set, as described in the section above, instead of testing for recursion. For example, creating a group with the name R1 by adding (?<R1>) to the above pattern completely changes its meaning. -

    -

    +

    +

    If a name preceded by ampersand follows the letter R, for example:

       (?(R&name)...)
     
    the condition is true if the most recent recursion is into a group of that name (which must exist within the pattern). -

    -

    +

    +

    This condition does not check the entire recursion stack. It tests only the current level. If the name used in a condition of this kind is a duplicate, the test is applied to all groups of the same name, and is true if any one of them is the most recent recursion. -

    -

    +

    +

    At "top level", all these recursion test conditions are false. -

    -
    +

    +

    Defining capture groups for use by reference only -
    -

    +

    +

    If the condition is the string (DEFINE), the condition is always false, even if there is a group with the name DEFINE. In this case, there may be only one alternative in the rest of the conditional group. It is always skipped if @@ -3132,11 +3131,11 @@ address (a number less than 256). When matching takes place, this part of the pattern is skipped because DEFINE acts like a false condition. The rest of the pattern uses references to the named group to match the four dot-separated components of an IPv4 address, insisting on a word boundary at each end. -

    -
    +

    +

    Checking the PCRE2 version -
    -

    +

    +

    Programs that link with a PCRE2 library can check the version by calling pcre2_config() with appropriate arguments. Users of applications that do not have access to the underlying code cannot do this. A special "condition" @@ -3148,19 +3147,18 @@ For example: (?(VERSION>=10.4)yes|no)

    This pattern matches "yes" if the PCRE2 version is greater or equal to 10.4, or -"no" otherwise. The fractional part of the version number may not contain more -than two digits. -

    -
    +"no" otherwise. The fractional part of the version number could be ommited. +

    +

    Assertion conditions -
    -

    +

    +

    If the condition is not in any of the above formats, it must be a parenthesized assertion. This may be a positive or negative lookahead or lookbehind assertion. However, it must be a traditional atomic assertion, not one of the non-atomic assertions. -

    -

    +

    +

    Consider this pattern, again containing non-significant white space, and with the two alternatives on the second line:

    @@ -3173,23 +3171,23 @@ presence of at least one letter in the subject. If a letter is found, the
     subject is matched against the first alternative; otherwise it is matched
     against the second. This pattern matches strings in one of the two forms
     dd-aaa-dd or dd-dd-dd, where aaa are letters and dd are digits.
    -

    -

    +

    +

    When an assertion that is a condition contains capture groups, any capturing that occurs in a matching branch is retained afterwards, for both positive and negative assertions, because matching always continues after the assertion, whether it succeeds or fails. (Compare non-conditional assertions, for which captures are retained only for positive assertions that succeed.) -

    -
    COMMENTS
    -

    +

    +

    COMMENTS

    +

    There are two ways of including comments in patterns that are processed by PCRE2. In both cases, the start of the comment must not be in a character class, nor in the middle of any other sequence of related characters such as (?: or a group name or number or a Unicode property name. The characters that make up a comment play no part in the pattern matching. -

    -

    +

    +

    The sequence (?# marks the start of a comment that continues up to the next closing parenthesis. Nested parentheses are not permitted. If the PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option is set, an unescaped # character @@ -3210,15 +3208,15 @@ On encountering the # character, pcre2_compile() skips along, looking for a newline in the pattern. The sequence \n is still literal at this stage, so it does not terminate the comment. Only an actual character with the code value 0x0a (the default newline) does so. -

    -
    RECURSIVE PATTERNS
    -

    +

    +

    RECURSIVE PATTERNS

    +

    Consider the problem of matching a string in parentheses, allowing for unlimited nested parentheses. Without the use of recursion, the best that can be done is to use a pattern that matches up to some fixed depth of nesting. It is not possible to handle an arbitrary nesting depth. -

    -

    +

    +

    For some time, Perl has provided a facility that allows regular expressions to recurse (amongst other things). It does this by interpolating Perl code in the expression at run time, and the code can refer to the expression itself. A Perl @@ -3229,22 +3227,22 @@ created like this:

    The (?p{...}) item interpolates Perl code at run time, and in this case refers recursively to the pattern in which it appears. -

    -

    +

    +

    Obviously, PCRE2 cannot support the interpolation of Perl code. Instead, it supports special syntax for recursion of the entire pattern, and also for individual capture group recursion. After its introduction in PCRE1 and Python, this kind of recursion was subsequently introduced into Perl at release 5.10. -

    -

    +

    +

    A special item that consists of (? followed by a number greater than zero and a closing parenthesis is a recursive subroutine call of the capture group of the given number, provided that it occurs inside that group. (If not, it is a non-recursive subroutine call, which is described in the next section.) The special item (?R) or (?0) is a recursive call of the entire regular expression. -

    -

    +

    +

    This PCRE2 pattern solves the nested parentheses problem (assume the PCRE2_EXTENDED option is set so that white space is ignored):

    @@ -3255,8 +3253,8 @@ substrings which can either be a sequence of non-parentheses, or a recursive
     match of the pattern itself (that is, a correctly parenthesized substring).
     Finally there is a closing parenthesis. Note the use of a possessive quantifier
     to avoid backtracking into sequences of non-parentheses.
    -

    -

    +

    +

    If this were part of a larger pattern, you would not want to recurse the entire pattern, so instead you could use this:

    @@ -3264,15 +3262,15 @@ pattern, so instead you could use this:
     
    We have put the pattern into parentheses, and caused the recursion to refer to them instead of the whole pattern. -

    -

    +

    +

    In a larger pattern, keeping track of parenthesis numbers can be tricky. This is made easier by the use of relative references. Instead of (?1) in the pattern above you can write (?-2) to refer to the second most recently opened parentheses preceding the recursion. In other words, a negative number counts capturing parentheses leftwards from the point at which it is encountered. -

    -

    +

    +

    Be aware however, that if duplicate capture group numbers are in use, relative references refer to the earliest group with the @@ -3286,15 +3284,15 @@ opened parentheses has the number 1, but it is the first such group (the (a) group) to which the recursion refers. This would be the same if an absolute reference (?1) was used. In other words, relative references are just a shorthand for computing a group number. -

    -

    +

    +

    It is also possible to refer to subsequent capture groups, by writing references such as (?+2). However, these cannot be recursive because the reference is not inside the parentheses that are referenced. They are always non-recursive subroutine calls, as described in the next section. -

    -

    +

    +

    An alternative approach is to use named parentheses. The Perl syntax for this is (?&name); PCRE1's earlier syntax (?P>name) is also supported. We could rewrite the above example as follows: @@ -3303,8 +3301,8 @@ rewrite the above example as follows:

    If there is more than one group with the same name, the earliest one is used. -

    -

    +

    +

    The example pattern that we have been looking at contains nested unlimited repeats, and so the use of a possessive quantifier for matching strings of non-parentheses is important when applying the pattern to strings that do not @@ -3316,8 +3314,8 @@ it yields "no match" quickly. However, if a possessive quantifier is not used, the match runs for a very long time indeed because there are so many different ways the + and * repeats can carve up the subject, and all have to be tested before failure can be reported. -

    -

    +

    +

    At the end of a match, the values of capturing parentheses are those from the outermost level. If you want to obtain intermediate values, a callout function can be used (see below and the @@ -3330,8 +3328,8 @@ the value for the inner capturing parentheses (numbered 2) is "ef", which is the last value taken on at the top level. If a capture group is not matched at the top level, its final captured value is unset, even if it was (temporarily) set at a deeper level during the matching process. -

    -

    +

    +

    Do not confuse the (?R) item with the condition (R), which tests for recursion. Consider this pattern, which matches text in angle brackets, allowing for arbitrary nesting. Only digits are allowed in nested brackets (that is, when @@ -3342,28 +3340,28 @@ recursing), whereas any characters are permitted at the outer level. In this pattern, (?(R) is the start of a conditional group, with two different alternatives for the recursive and non-recursive cases. The (?R) item is the actual recursive call. -

    -
    +

    +

    Differences in recursion processing between PCRE2 and Perl -
    -

    +

    +

    Some former differences between PCRE2 and Perl no longer exist. -

    -

    +

    +

    Before release 10.30, recursion processing in PCRE2 differed from Perl in that a recursive subroutine call was always treated as an atomic group. That is, once it had matched some of the subject string, it was never re-entered, even if it contained untried alternatives and there was a subsequent matching failure. (Historical note: PCRE implemented recursion before Perl did.) -

    -

    +

    +

    Starting with release 10.30, recursive subroutine calls are no longer treated as atomic. That is, they can be re-entered to try unused alternatives if there is a matching failure later in the pattern. This is now compatible with the way Perl works. If you want a subroutine call to be atomic, you must explicitly enclose it in an atomic group. -

    -

    +

    +

    Supporting backtracking into recursions simplifies certain types of recursive pattern. For example, this pattern matches palindromic strings:

    @@ -3383,8 +3381,8 @@ man, a plan, a canal: Panama!". Note the use of the possessive quantifier *+ to
     avoid backtracking into sequences of non-word characters. Without this, PCRE2
     takes a great deal longer (ten times or more) to match typical phrases, and
     Perl takes so long that you think it has gone into a loop.
    -

    -

    +

    +

    Another way in which PCRE2 and Perl used to differ in their recursion processing is in the handling of captured values. Formerly in Perl, when a group was called recursively or as a subroutine (see the next section), it @@ -3398,9 +3396,11 @@ the second group, when the backreference \1 fails to match "b", the second alternative matches "a" and then recurses. In the recursion, \1 does now match "b" and so the whole match succeeds. This match used to fail in Perl, but in later versions (I tried 5.024) it now works. -

    -
    GROUPS AS SUBROUTINES
    -

    +

    +

    +Groups as subroutines +

    +

    If the syntax for a recursive group call (either by number or by name) is used outside the parentheses to which it refers, it operates a bit like a subroutine in a programming language. More accurately, PCRE2 treats the referenced group @@ -3423,14 +3423,14 @@ matches "sense and sensibility" and "response and responsibility", but not

    is used, it does match "sense and responsibility" as well as the other two strings. Another example is given in the discussion of DEFINE above. -

    -

    +

    +

    Like recursions, subroutine calls used to be treated as atomic, but this changed at PCRE2 release 10.30, so backtracking into subroutine calls can now occur. However, any capturing parentheses that are set during the subroutine call revert to their previous values afterwards. -

    -

    +

    +

    Processing options such as case-independence are fixed when a group is defined, so if it is used as a subroutine, such options cannot be changed for different calls. For example, consider this pattern: @@ -3439,16 +3439,68 @@ different calls. For example, consider this pattern: It matches "abcabc". It does not match "abcABC" because the change of processing option does not affect the called group. -

    -

    +

    +

    The behaviour of backtracking control verbs in groups when called as subroutines is described in the section entitled "Backtracking verbs in subroutines" below. -

    -
    ONIGURUMA SUBROUTINE SYNTAX
    -

    +

    +

    +Recursion and subroutines with returned capture groups +

    +

    +Since PCRE2 10.46, recursion and subroutine calls may also specify a list of +capture groups to return. This is a PCRE2 syntax extension not supported by +Perl. The pattern matching recurses into the referenced expression as described +above, however, when the recursion returns to the calling expression the +subgroups captured during the recursion can be retained when the calling +expression's context is restored. +

    +

    +When used as a subroutine, this allows the subroutine's capture groups to +be used as return values. +

    +

    +Only the specific capture groups listed by the caller will be retained, using +the following syntax: +

    +  (?R(grouplist))       recurse whole pattern, returning capture groups
    +  (?n(grouplist))       )
    +  (?+n(grouplist))      )
    +  (?-n(grouplist))      ) call subroutine, returning capture groups
    +  (?&name(grouplist))   )
    +  (?P>name(grouplist))  )
    +
    +

    +

    +The list of capture groups "grouplist" is a comma-separated list of (absolute +or relative) group numbers, and group names enclosed in single quotes or angle +brackets. +

    +

    +Here is an example which first uses the DEFINE condition to create a re-usable +routine for matching a weekday, then calls that subroutine and retains the +groups it captures for use later: +

    +  (?x: # ignore whitespace for clarity
    +    # Define the routine "weekendday" which matches Saturday or
    +    # Sunday, and returns the Sat/Sun prefix as \k<short>.
    +    (?(DEFINE) (?<weekendday>
    +        (?|(?<short>Sat)urday|(?<short>Sun)day) ) )
    +    # Call the routine. Matches "Saturday,Sat" or "Sunday,Sun".
    +    (?&weekendday(<short>)),\k<short> )
    +
    +

    +

    +This feature is not available using the Oniguruma syntax \g<...> or \g'...' +below. +

    +

    +Oniguruma subroutine syntax +

    +

    For compatibility with Oniguruma, the non-Perl syntax \g followed by a name or a number enclosed either in angle brackets or single quotes, is an alternative syntax for calling a group as a subroutine, possibly recursively. Here are two @@ -3464,15 +3516,15 @@ plus or a minus sign it is taken as a relative reference. For example: Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not synonymous. The former is a backreference; the latter is a subroutine call. -

    -
    CALLOUTS
    -

    +

    +

    CALLOUTS

    +

    Perl has a feature whereby using the sequence (?{...}) causes arbitrary Perl code to be obeyed in the middle of matching a regular expression. This makes it possible, amongst other things, to extract different substrings that match the same pair of parentheses when there is a repetition. -

    -

    +

    +

    PCRE2 provides a similar feature, but of course it cannot obey arbitrary Perl code. The feature is called "callout". The caller of PCRE2 provides an external function by putting its entry point in a match context using the function @@ -3481,8 +3533,8 @@ or pcre2_dfa_match(). If no match context is passed, or if the callout entry point is set to NULL, callout points will be passed over silently during matching. To disallow callouts in the pattern syntax, you may use the PCRE2_EXTRA_NEVER_CALLOUT option. -

    -

    +

    +

    Within a regular expression, (?C<arg>) indicates a point at which the external function is to be called. There are two kinds of callout: those with a numerical argument and those with a string argument. (?C) on its own with no @@ -3490,15 +3542,15 @@ argument is treated as (?C0). A numerical argument allows the application to distinguish between different callouts. String arguments were added for release 10.20 to make it possible for script languages that use PCRE2 to embed short scripts within patterns in a similar way to Perl. -

    -

    +

    +

    During matching, when PCRE2 reaches a callout point, the external function is called. It is provided with the number or string argument of the callout, the position in the pattern, and one item of data that is also set in the match block. The callout function may cause matching to proceed, to backtrack, or to fail. -

    -

    +

    +

    By default, PCRE2 implements a number of optimizations at matching time, and one side-effect is that sometimes callouts are skipped. If you need all possible callouts to happen, you need to set options that disable the relevant @@ -3506,11 +3558,11 @@ optimizations. More details, including a complete description of the programming interface to the callout function, are given in the pcre2callout documentation. -

    -
    +

    +

    Callouts with numerical arguments -
    -

    +

    +

    If you just want to have a means of identifying different callout points, put a number less than 256 after the letter C. For example, this pattern has two callout points: @@ -3528,11 +3580,11 @@ example: Note that this applies only to assertion conditions, not to other types of condition. -

    -
    +

    +

    Callouts with string arguments -
    -

    +

    +

    A delimited string may be used instead of a number as a callout argument. The starting delimiter must be one of ` ' " ^ % # $ { and the ending delimiter is the same as the start, except for {, where the ending delimiter is }. If the @@ -3542,63 +3594,63 @@ example: (?C'ab ''c'' d')xyz(?C{any text})pqr The doubling is removed before the string is passed to the callout function. -

    -
    BACKTRACKING CONTROL
    -

    +

    +

    BACKTRACKING CONTROL

    +

    There are a number of special "Backtracking Control Verbs" (to use Perl's terminology) that modify the behaviour of backtracking during matching. They are generally of the form (*VERB) or (*VERB:NAME). Some verbs take either form, and may behave differently depending on whether or not a name argument is present. The names are not required to be unique within the pattern. -

    -

    +

    +

    By default, for compatibility with Perl, a name is any sequence of characters that does not include a closing parenthesis. The name is not processed in any way, and it is not possible to include a closing parenthesis in the name. This can be changed by setting the PCRE2_ALT_VERBNAMES option, but the result is no longer Perl-compatible. -

    -

    +

    +

    When PCRE2_ALT_VERBNAMES is set, backslash processing is applied to verb names and only an unescaped closing parenthesis terminates the name. However, the only backslash items that are permitted are \Q, \E, and sequences such as \x{100} that define character code points. Character type escapes such as \d are faulted. -

    -

    +

    +

    A closing parenthesis can be included in a name either as \) or between \Q and \E. In addition to backslash processing, if the PCRE2_EXTENDED or -PCRE2_EXTENDED_MORE option is also set, unescaped whitespace in verb names is +PCRE2_EXTENDED_MORE option is also set, unescaped white space in verb names is skipped, and #-comments are recognized, exactly as in the rest of the pattern. PCRE2_EXTENDED and PCRE2_EXTENDED_MORE do not affect verb names unless PCRE2_ALT_VERBNAMES is also set. -

    -

    +

    +

    The maximum length of a name is 255 in the 8-bit library and 65535 in the 16-bit and 32-bit libraries. If the name is empty, that is, if the closing parenthesis immediately follows the colon, the effect is as if the colon were not there. Any number of these verbs may occur in a pattern. Except for (*ACCEPT), they may not be quantified. -

    -

    +

    +

    Since these verbs are specifically related to backtracking, most of them can be used only when the pattern is to be matched using the traditional matching function or JIT, because they use backtracking algorithms. With the exception of (*FAIL), which behaves like a failing negative assertion, the backtracking control verbs cause an error if encountered by the DFA matching function. -

    -

    +

    +

    The behaviour of these verbs in repeated groups, assertions, and in capture groups called as subroutines (whether or not recursively) is documented below. -

    -
    +

    +

    Optimizations that affect backtracking verbs -
    -

    +

    +

    PCRE2 contains some optimizations that are used to speed up matching by running some checks at the start of each match attempt. For example, it may know the minimum length of matching subject, or that a particular character must be @@ -3613,15 +3665,15 @@ entitled in the pcre2api documentation. -

    -

    +

    +

    Experiments with Perl suggest that it too has similar optimizations, and like PCRE2, turning them off can change the result of a match. -

    -
    +

    +

    Verbs that act immediately -
    -

    +

    +

    The following verbs act as soon as they are encountered.

        (*ACCEPT) or (*ACCEPT:NAME)
    @@ -3631,8 +3683,8 @@ pattern. However, when it is inside a capture group that is called as a
     subroutine, only that group is ended successfully. Matching then continues
     at the outer level. If (*ACCEPT) in triggered in a positive assertion, the
     assertion succeeds; in a negative assertion, the assertion fails.
    -

    -

    +

    +

    If (*ACCEPT) is inside capturing parentheses, the data so far is captured. For example:

    @@ -3640,8 +3692,8 @@ example:
     
    This matches "AB", "AAD", or "ACD"; when it matches "AB", "B" is captured by the outer parentheses. -

    -

    +

    +

    (*ACCEPT) is the only backtracking verb that is allowed to be quantified because an ungreedy quantification with a minimum of zero acts only when a backtrack happens. Consider, for example, @@ -3653,8 +3705,8 @@ processes "BC"; if that fails, causing a backtrack, (*ACCEPT) is triggered and the match succeeds. In both cases, all but C is captured. Whereas (*COMMIT) (see below) means "fail on backtrack", a repeated (*ACCEPT) of this type means "succeed on backtrack". -

    -

    +

    +

    Warning: (*ACCEPT) should not be used within a script run group, because it causes an immediate exit from the group, bypassing the script run checking.

    @@ -3670,16 +3722,16 @@ nearest equivalent is the callout feature, as for example in this pattern:
     
    A match with the string "aaaa" always fails, but the callout is taken before each backtrack happens (in this example, 10 times). -

    -

    +

    +

    (*ACCEPT:NAME) and (*FAIL:NAME) behave the same as (*MARK:NAME)(*ACCEPT) and (*MARK:NAME)(*FAIL), respectively, that is, a (*MARK) is recorded just before the verb acts. -

    -
    +

    +

    Recording which path was taken -
    -

    +

    +

    There is one verb whose main purpose is to track how a match was arrived at, though it also has a secondary use in conjunction with advancing the match starting point (see (*SKIP) below). @@ -3688,8 +3740,8 @@ starting point (see (*SKIP) below).

    A name is always required with this verb. For all the other backtracking control verbs, a NAME argument is optional. -

    -

    +

    +

    When a match succeeds, the name of the last-encountered mark name on the matching path is passed back to the caller as described in the section entitled "Other information about the match" @@ -3699,8 +3751,8 @@ documentation. This applies to all instances of (*MARK) and other verbs, including those inside assertions and atomic groups. However, there are differences in those cases when (*MARK) is used in conjunction with (*SKIP) as described below. -

    -

    +

    +

    The mark name that was last encountered on the matching path is passed back. A verb without a NAME argument is ignored for this purpose. Here is an example of pcre2test output, where the "mark" modifier requests the retrieval and @@ -3718,13 +3770,13 @@ The (*MARK) name is tagged with "MK:" in this output, and in this example it indicates which of the two alternatives matched. This is a more efficient way of obtaining this information than putting each alternative in its own capturing parentheses. -

    -

    +

    +

    If a verb with a name is encountered in a positive assertion that is true, the name is recorded and passed back if it is the last-encountered. This does not happen for negative assertions or failing positive assertions. -

    -

    +

    +

    After a partial match or a failed match, the last encountered name in the entire match process is returned. For example:

    @@ -3736,18 +3788,18 @@ Note that in this unanchored example the mark is retained from the match
     attempt that started at the letter "X" in the subject. Subsequent match
     attempts starting at "P" and then with an empty string do not get as far as the
     (*MARK) item, but nevertheless do not reset it.
    -

    -

    +

    +

    If you are interested in (*MARK) values after failed matches, you should probably either set the PCRE2_NO_START_OPTIMIZE option or call pcre2_set_optimize() with a PCRE2_START_OPTIMIZE_OFF directive (see above) to ensure that the match is always attempted. -

    -
    +

    +

    Verbs that act after backtracking -
    -

    +

    +

    The following verbs do nothing when they are encountered. Matching continues with what follows, but if there is a subsequent match failure, causing a backtrack to the verb, a failure is forced. That is, backtracking cannot pass @@ -3756,8 +3808,8 @@ atomic group or in an atomic lookaround assertion that is true, its effect is confined to that group, because once the group has been matched, there is never any backtracking into it. Backtracking from beyond an atomic assertion or group ignores the entire group, and seeks a preceding backtracking point. -

    -

    +

    +

    These verbs differ in exactly what kind of failure occurs when backtracking reaches them. The behaviour described below is what happens when the verb is not in a subroutine or an assertion. Subsequent sections cover these special @@ -3776,19 +3828,19 @@ the current starting point, or not at all. For example:

    This matches "xxaab" but not "aacaab". It can be thought of as a kind of dynamic anchor, or "I've started, so I must finish." -

    -

    +

    +

    The behaviour of (*COMMIT:NAME) is not the same as (*MARK:NAME)(*COMMIT). It is like (*MARK:NAME) in that the name is remembered for passing back to the caller. However, (*SKIP:NAME) searches only for names that are set with (*MARK), ignoring those set by any of the other backtracking verbs. -

    -

    +

    +

    If there is more than one backtracking verb in a pattern, a different one that follows (*COMMIT) may be triggered first, so merely passing (*COMMIT) during a match does not always guarantee that a match must be at this starting point. -

    -

    +

    +

    Note that (*COMMIT) at the start of a pattern is not the same as an anchor, unless PCRE2's start-of-match optimizations are turned off, as shown in this output from pcre2test: @@ -3820,8 +3872,8 @@ simple cases, the use of (*PRUNE) is just an alternative to an atomic group or possessive quantifier, but there are some uses of (*PRUNE) that cannot be expressed in any other way. In an anchored pattern (*PRUNE) has the same effect as (*COMMIT). -

    -

    +

    +

    The behaviour of (*PRUNE:NAME) is not the same as (*MARK:NAME)(*PRUNE). It is like (*MARK:NAME) in that the name is remembered for passing back to the caller. However, (*SKIP:NAME) searches only for names set with (*MARK), @@ -3843,8 +3895,8 @@ next attempt at "c". Note that a possessive quantifier does not have the same effect as this example; although it would suppress backtracking during the first match attempt, the second attempt would start at the second character instead of skipping on to "c". -

    -

    +

    +

    If (*SKIP) is used to specify a new starting position that is the same as the starting position of the current match, or (by being inside a lookbehind) earlier, the position specified by (*SKIP) is ignored, and instead the normal @@ -3858,8 +3910,8 @@ most recent (*MARK) that has the same name. If one is found, the "bumpalong" advance is to the subject position that corresponds to that (*MARK) instead of to where (*SKIP) was encountered. If no (*MARK) with a matching name is found, the (*SKIP) is ignored. -

    -

    +

    +

    The search for a (*MARK) name uses the normal backtracking mechanism, which means that it does not see (*MARK) settings that are inside atomic groups or assertions, because they are never re-entered by backtracking. Compare the @@ -3883,8 +3935,8 @@ allows (*SKIP:X) to find the (*MARK) when it backtracks, and this causes a new matching attempt to start at the second character. This time, the (*MARK) is never seen because "a" does not match "b", so the matcher immediately jumps to the second branch of the pattern. -

    -

    +

    +

    Note that (*SKIP:NAME) searches only for names set by (*MARK:NAME). It ignores names that are set by other backtracking verbs.

    @@ -3903,14 +3955,14 @@ second alternative and tries COND2, without backtracking into COND1. If that
     succeeds and BAR fails, COND3 is tried. If subsequently BAZ fails, there are no
     more alternatives, so there is a backtrack to whatever came before the entire
     group. If (*THEN) is not inside an alternation, it acts like (*PRUNE).
    -

    -

    +

    +

    The behaviour of (*THEN:NAME) is not the same as (*MARK:NAME)(*THEN). It is like (*MARK:NAME) in that the name is remembered for passing back to the caller. However, (*SKIP:NAME) searches only for names set with (*MARK), ignoring those set by other backtracking verbs. -

    -

    +

    +

    A group that does not contain a | character is just a part of the enclosing alternative; it is not a nested alternation with only one alternative. The effect of (*THEN) extends beyond such a group to the enclosing alternative. @@ -3929,8 +3981,8 @@ behaves differently: The effect of (*THEN) is now confined to the inner group. After a failure in C, matching moves to (*FAIL), which causes the whole group to fail because there are no more alternatives to try. In this case, matching does backtrack into A. -

    -

    +

    +

    Note that a conditional group is not considered as having two alternatives, because only one is ever used. In other words, the | character in a conditional group has a different meaning. Ignoring white space, consider: @@ -3944,8 +3996,8 @@ backtrack to .*? as might perhaps be expected from the presence of the | character. The conditional group is part of the single alternative that comprises the whole pattern, and so the match fails. (If there was a backtrack into .*?, allowing it to match "b", the match would succeed.) -

    -

    +

    +

    The verbs just described provide four different "strengths" of control when subsequent matching fails. (*THEN) is the weakest, carrying on the match at the next alternative. (*PRUNE) comes next, failing the match at the current @@ -3953,11 +4005,11 @@ starting position, but allowing an advance to the next character (for an unanchored pattern). (*SKIP) is similar, except that the advance may be more than one character. (*COMMIT) is the strongest, causing the entire match to fail. -

    -
    +

    +

    More than one backtracking verb -
    -

    +

    +

    If more than one backtracking verb is present in a pattern, the one that is backtracked onto first acts. For example, consider this pattern, where A, B, etc. are complex pattern fragments: @@ -3976,11 +4028,11 @@ example: If there is a matching failure to the right, backtracking onto (*PRUNE) causes it to be triggered, and its action is taken. There can never be a backtrack onto (*COMMIT). -

    -
    +

    +

    Backtracking verbs in repeated groups -
    -

    +

    +

    PCRE2 sometimes differs from Perl in its handling of backtracking verbs in repeated groups. For example, consider:

    @@ -3989,37 +4041,37 @@ repeated groups. For example, consider:
     If the subject is "abac", Perl matches unless its optimizations are disabled,
     but PCRE2 always fails because the (*COMMIT) in the second repeat of the group
     acts.
    -

    -
    +

    +

    Backtracking verbs in assertions -
    -

    +

    +

    (*FAIL) in any assertion has its normal effect: it forces an immediate backtrack. The behaviour of the other backtracking verbs depends on whether or not the assertion is standalone or acting as the condition in a conditional group. -

    -

    +

    +

    (*ACCEPT) in a standalone positive assertion causes the assertion to succeed without any further processing; captured strings and a mark name (if set) are retained. In a standalone negative assertion, (*ACCEPT) causes the assertion to fail without any further processing; captured substrings and any mark name are discarded. -

    -

    +

    +

    If the assertion is a condition, (*ACCEPT) causes the condition to be true for a positive assertion and false for a negative one; captured substrings are retained in both cases. -

    -

    +

    +

    The remaining verbs act only when a later failure causes a backtrack to reach them. This means that, for the Perl-compatible assertions, their effect is confined to the assertion, because Perl lookaround assertions are atomic. A backtrack that occurs after such an assertion is complete does not jump back into the assertion. Note in particular that a (*MARK) name that is set in an assertion is not "seen" by an instance of (*SKIP:NAME) later in the pattern. -

    -

    +

    +

    PCRE2 now supports non-atomic positive assertions and also "scan substring" assertions, as described in the sections entitled "Non-atomic assertions" @@ -4029,57 +4081,57 @@ above. These assertions must be standalone (not used as conditions). They are not Perl-compatible. For these assertions, a later backtrack does jump back into the assertion, and therefore verbs such as (*COMMIT) can be triggered by backtracks from later in the pattern. -

    -

    +

    +

    The effect of (*THEN) is not allowed to escape beyond an assertion. If there are no more branches to try, (*THEN) causes a positive assertion to be false, and a negative assertion to be true. This behaviour differs from Perl when the assertion has only one branch. -

    -

    +

    +

    The other backtracking verbs are not treated specially if they appear in a standalone positive assertion. In a conditional positive assertion, backtracking (from within the assertion) into (*COMMIT), (*SKIP), or (*PRUNE) causes the condition to be false. However, for both standalone and conditional negative assertions, backtracking into (*COMMIT), (*SKIP), or (*PRUNE) causes the assertion to be true, without considering any further alternative branches. -

    -
    +

    +

    Backtracking verbs in subroutines -
    -

    +

    +

    These behaviours occur whether or not the group is called recursively. -

    -

    +

    +

    (*ACCEPT) in a group called as a subroutine causes the subroutine match to succeed without any further processing. Matching then continues after the subroutine call. Perl documents this behaviour. Perl's treatment of the other verbs in subroutines is different in some cases. -

    -

    +

    +

    (*FAIL) in a group called as a subroutine has its normal effect: it forces an immediate backtrack. -

    -

    +

    +

    (*COMMIT), (*SKIP), and (*PRUNE) cause the subroutine match to fail when triggered by being backtracked to in a group called as a subroutine. There is then a backtrack at the outer level. -

    -

    +

    +

    (*THEN), when triggered, skips to the next alternative in the innermost enclosing group that has alternatives (its normal behaviour). However, if there is no such group within the subroutine's group, the subroutine match fails and there is a backtrack at the outer level. -

    -
    EBCDIC ENVIRONMENTS
    -

    +

    +

    EBCDIC ENVIRONMENTS

    +

    Differences in the way PCRE behaves when it is running in an EBCDIC environment are covered in this section. -

    -
    +

    +

    Escape sequences -
    -

    +

    +

    When PCRE2 is compiled in EBCDIC mode, \N{U+hhh..} is not supported. \a, \e, \f, \n, \r, and \t generate the appropriate EBCDIC code values. The \c escape is processed as specified for Perl in the perlebcdic document. The @@ -4088,25 +4140,25 @@ only characters that are allowed after \c are A-Z, a-z, or one of @, [, \, ], \c@ encodes character code 0; after \c the letters (in either case) encode characters 1-26 (hex 01 to hex 1A); [, \, ], ^, and _ encode characters 27-31 (hex 1B to hex 1F), and \c? becomes either 255 (hex FF) or 95 (hex 5F). -

    -

    +

    +

    Thus, apart from \c?, these escapes generate the same character code values as they do in an ASCII or Unicode environment, though the meanings of the values mostly differ. For example, \cG always generates code value 7, which is BEL in ASCII but DEL in EBCDIC. -

    -

    +

    +

    The sequence \c? generates DEL (127, hex 7F) in an ASCII environment, but because 127 is not a control character in EBCDIC, Perl makes it generate the APC character. Unfortunately, there are several variants of EBCDIC. In most of them the APC character has the value 255 (hex FF), but in the one Perl calls POSIX-BC its value is 95 (hex 5F). If certain other characters have POSIX-BC values, PCRE2 makes \c? generate 95; otherwise it generates 255. -

    -
    +

    +

    Character classes -
    -

    +

    +

    In character classes there is a special case in EBCDIC environments for ranges whose end points are both specified as literal letters in the same case. For compatibility with Perl, EBCDIC code points within the range that are not @@ -4114,24 +4166,24 @@ letters are omitted. For example, [h-k] matches only four characters, even though the EBCDIC codes for h and k are 0x88 and 0x92, a range of 11 code points. However, if the range is specified numerically, for example, [\x88-\x92] or [h-\x92], all code points are included. -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2api(3), pcre2callout(3), pcre2matching(3), pcre2syntax(3), pcre2(3). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 27 November 2024 +

    +

    REVISION

    +

    +Last updated: 03 September 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2perform.html b/doc/html/pcre2perform.html index b595119..772e9f0 100644 --- a/doc/html/pcre2perform.html +++ b/doc/html/pcre2perform.html @@ -20,14 +20,14 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    PCRE2 PERFORMANCE
    -

    +

    PCRE2 PERFORMANCE

    +

    Two aspects of performance are discussed below: memory usage and processing time. The way you express your pattern as a regular expression can affect both of them. -

    -
    COMPILED PATTERN MEMORY USAGE
    -

    +

    +

    COMPILED PATTERN MEMORY USAGE

    +

    Patterns are compiled by PCRE2 into a reasonably efficient interpretive code, so that most simple patterns do not use much memory for storing the compiled version. However, there is one case where the memory usage of a compiled @@ -43,8 +43,8 @@ is compiled as if it were

  • (Technical aside: It is done this way so that backtrack points within each of the repetitions can be independently maintained.) -

    -

    +

    +

    For regular expressions whose quantifiers use only small numbers, this is not usually a problem. However, if the numbers are large, and particularly if such repetitions are nested, the memory usage can become an embarrassment. For @@ -59,8 +59,8 @@ this is reached with the above pattern if the outer repetition is increased from 3 to 4. PCRE2 can be compiled to use larger internal pointers and thus handle larger compiled patterns, but it is better to try to rewrite your pattern to use less memory if you can. -

    -

    +

    +

    One way of reducing the memory usage for such patterns is to make use of PCRE2's "subroutine" @@ -76,22 +76,22 @@ problem, this kind of rewriting will allow you to process patterns that PCRE2 cannot otherwise handle. The matching performance of the two different versions of the pattern are roughly the same. (This applies from release 10.30 - things were different in earlier releases.) -

    -
    STACK AND HEAP USAGE AT RUN TIME
    -

    +

    +

    STACK AND HEAP USAGE AT RUN TIME

    +

    From release 10.30, the interpretive (non-JIT) version of pcre2_match() uses very little system stack at run time. In earlier releases recursive function calls could use a great deal of stack, and this could cause problems, but this usage has been eliminated. Backtracking positions are now explicitly remembered in memory frames controlled by the code. -

    -

    +

    +

    The size of each frame depends on the size of pointer variables and the number of capturing parenthesized groups in the pattern being matched. On a 64-bit system the frame size for a pattern with no captures is 128 bytes. For each capturing group the size increases by 16 bytes. -

    -

    +

    +

    Until release 10.41, an initial 20KiB frames vector was allocated on the system stack, but this still caused some issues for multi-thread applications where each thread has a very small stack. From release 10.41 backtracking memory @@ -99,8 +99,8 @@ frames are always held in heap memory. An initial heap allocation is obtained the first time any match data block is passed to pcre2_match(). This is remembered with the match data block and re-used if that block is used for another match. It is freed when the match data block itself is freed. -

    -

    +

    +

    The size of the initial block is the larger of 20KiB or ten times the pattern's frame size, unless the heap limit is less than this, in which case the heap limit is used. If the initial block proves to be too small during matching, it @@ -108,8 +108,8 @@ is replaced by a larger block, subject to the heap limit. The heap limit is checked only when a new block is to be allocated. Reducing the heap limit between calls to pcre2_match() with the same match data block does not affect the saved block. -

    -

    +

    +

    In contrast to pcre2_match(), pcre2_dfa_match() does use recursive function calls, but only for processing atomic groups, lookaround assertions, and recursion within the pattern. The original version of the code used to @@ -118,14 +118,14 @@ problems for some patterns in environments with small stacks. From release 10.32 the code for pcre2_dfa_match() has been re-factored to use heap memory when necessary for internal workspace when recursing, though recursive function calls are still used. -

    -

    +

    +

    The "match depth" parameter can be used to limit the depth of function recursion, and the "match heap" parameter to limit heap memory in pcre2_dfa_match(). -

    -
    PROCESSING TIME
    -

    +

    +

    PROCESSING TIME

    +

    Certain items in regular expression patterns are processed more efficiently than others. It is more efficient to use a character class like [aeiou] than a set of single-character alternatives such as (a|e|i|o|u). In general, the @@ -133,14 +133,14 @@ simplest construction that provides the required behaviour is usually the most efficient. Jeffrey Friedl's book contains a lot of useful general discussion about optimizing regular expressions for efficient performance. This document contains a few observations about PCRE2. -

    -

    +

    +

    Using Unicode character properties (the \p, \P, and \X escapes) is slow, because PCRE2 has to use a multi-stage table lookup whenever it needs a character's property. If you can find an alternative pattern that does not use character properties, it will probably be faster. -

    -

    +

    +

    By default, the escape sequences \b, \d, \s, and \w, and the POSIX character classes such as [:alpha:] do not use Unicode properties, partly for backwards compatibility, and partly for performance reasons. However, you can @@ -149,8 +149,8 @@ character properties to be used. This can double the matching time for items such as \d, when matched with pcre2_match(); the performance loss is less with a DFA matching function, and in both cases there is not much difference for \b. -

    -

    +

    +

    When a pattern begins with .* not in atomic parentheses, nor in parentheses that are the subject of a backreference, and the PCRE2_DOTALL option is set, the pattern is implicitly anchored by PCRE2, since it can match only at the @@ -158,8 +158,8 @@ start of a subject string. If the pattern has multiple top-level branches, they must all be anchorable. The optimization can be disabled by the PCRE2_NO_DOTSTAR_ANCHOR option, and is automatically disabled if the pattern contains (*PRUNE) or (*SKIP). -

    -

    +

    +

    If PCRE2_DOTALL is not set, PCRE2 cannot make this optimization, because the dot metacharacter does not then match a newline, and if the subject string contains newlines, the pattern may match from the character immediately @@ -170,14 +170,14 @@ following one of them instead of from the very start. For example, the pattern matches the subject "first\nand second" (where \n stands for a newline character), with the match starting at the seventh character. In order to do this, PCRE2 has to retry the match starting after every newline in the subject. -

    -

    +

    +

    If you are using such a pattern with subject strings that do not contain newlines, the best performance is obtained by setting PCRE2_DOTALL, or starting the pattern with ^.* or ^.*? to indicate explicit anchoring. That saves PCRE2 from having to scan along the subject looking for a newline to restart at. -

    -

    +

    +

    Beware of patterns that contain nested indefinite repeats. These can take a long time to run when applied to a string that does not match. Consider the pattern fragment @@ -191,8 +191,8 @@ different numbers of times.) When the remainder of the pattern is such that the entire match is going to fail, PCRE2 has in principle to try every possible variation, and this can take an extremely long time, even for relatively short strings. -

    -

    +

    +

    An optimization catches some of the more simple cases such as

       (a+)*b
    @@ -208,8 +208,8 @@ by comparing the behaviour of
     with the pattern above. The former gives a failure almost instantly when
     applied to a whole line of "a" characters, whereas the latter takes an
     appreciable time with strings longer than about 20 characters.
    -

    -

    +

    +

    In many cases, the solution to this kind of performance issue is to use an atomic group or a possessive quantifier. This can often reduce memory requirements as well. As another example, consider this pattern: @@ -233,16 +233,16 @@ is used to stop any backtracking into the runs of non-"<" characters. This version also uses a lot less memory because entry to a new set of parentheses happens only when a "<" character that is not followed by "inet" is encountered (and we assume this is relatively rare). -

    -

    +

    +

    This example shows that one way of optimizing performance when matching long subject strings is to write repeated parenthesized subpatterns to match more than one character whenever possible. -

    -
    +

    +

    SETTING RESOURCE LIMITS -
    -

    +

    +

    You can set limits on the amount of processing that takes place when matching, and on the amount of heap memory that is used. The default values of the limits are very large, and unlikely ever to operate. They can be changed when PCRE2 is @@ -254,23 +254,23 @@ documentation and the section entitled in the pcre2api documentation. -

    -

    +

    +

    The pcre2test test program has a modifier called "find_limits" which, if applied to a subject line, causes it to find the smallest limits that allow a pattern to match. This is done by repeatedly matching with different limits. -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    +

    +

    REVISION

    +

    Last updated: 06 December 2022
    Copyright © 1997-2022 University of Cambridge. diff --git a/doc/html/pcre2posix.html b/doc/html/pcre2posix.html index bc60c3b..b07d73b 100644 --- a/doc/html/pcre2posix.html +++ b/doc/html/pcre2posix.html @@ -24,11 +24,11 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    SYNOPSIS
    -

    +

    SYNOPSIS

    +

    #include <pcre2posix.h> -

    -

    +

    +

    int pcre2_regcomp(regex_t *preg, const char *pattern, int cflags);
    @@ -42,22 +42,22 @@ please consult the man page, in case the conversion went wrong.

    void pcre2_regfree(regex_t *preg); -

    -
    DESCRIPTION
    -

    +

    +

    DESCRIPTION

    +

    This set of functions provides a POSIX-style API for the PCRE2 regular expression 8-bit library. There are no POSIX-style wrappers for PCRE2's 16-bit and 32-bit libraries. See the pcre2api documentation for a description of PCRE2's native API, which contains much additional functionality. -

    -

    +

    +

    IMPORTANT NOTE: The functions described here are NOT thread-safe, and should not be used in multi-threaded applications. They are also limited to processing subjects that are not bigger than 2GB. Use the native API instead. -

    -

    +

    +

    These functions are wrapper functions that ultimately call the PCRE2 native API. Their prototypes are defined in the pcre2posix.h header file, and they all have unique names starting with pcre2_. However, the @@ -65,20 +65,20 @@ they all have unique names starting with pcre2_. However, the standard POSIX names such regcomp() into pcre2_regcomp() etc. This means that a program can use the usual POSIX names without running the risk of accidentally linking with POSIX functions from a different library. -

    -

    +

    +

    On Unix-like systems the PCRE2 POSIX library is called libpcre2-posix, so can be accessed by adding -lpcre2-posix to the command for linking an application. Because the POSIX functions call the native ones, it is also necessary to add -lpcre2-8. -

    -

    +

    +

    On Windows systems, if you are linking to a DLL version of the library, it is recommended that PCRE2POSIX_SHARED is defined before including the pcre2posix.h header, as it will allow for a more efficient way to invoke the functions by adding the __declspec(dllimport) decorator. -

    -

    +

    +

    Although they were not defined as prototypes in pcre2posix.h, releases 10.33 to 10.36 of the library contained functions with the POSIX names regcomp() etc. These simply passed their arguments to the PCRE2 @@ -87,48 +87,48 @@ earlier versions of PCRE2, which had only POSIX names. However, this has proved troublesome in situations where a program links with several libraries, some of which use PCRE2's POSIX interface while others use the real POSIX functions. For this reason, the POSIX names have been removed since release 10.37. -

    -

    +

    +

    Calling the header file pcre2posix.h avoids any conflict with other POSIX libraries. It can, of course, be renamed or aliased as regex.h, which is the "correct" name, if there is no clash. It provides two structure types, regex_t for compiled internal forms, and regmatch_t for returning captured substrings. It also defines some constants whose names start with "REG_"; these are used for setting options and identifying error codes. -

    -
    USING THE POSIX FUNCTIONS
    -

    +

    +

    USING THE POSIX FUNCTIONS

    +

    Note that these functions are just POSIX-style wrappers for PCRE2's native API. They do not give POSIX regular expression behaviour, and they are not thread-safe or even POSIX compatible. -

    -

    +

    +

    Those POSIX option bits that can reasonably be mapped to PCRE2 native options have been implemented. In addition, the option REG_EXTENDED is defined with the value zero. This has no effect, but since programs that are written to the POSIX interface often use it, this makes it easier to slot in PCRE2 as a replacement library. Other POSIX options are not even defined. -

    -

    +

    +

    There are also some options that are not defined by POSIX. These have been added at the request of users who want to make use of certain PCRE2-specific features via the POSIX calling interface or to add BSD or GNU functionality. -

    -

    +

    +

    When PCRE2 is called via these functions, it is only the API that is POSIX-like in style. The syntax and semantics of the regular expressions themselves are still those of Perl, subject to the setting of various PCRE2 options, as described below. "POSIX-like in style" means that the API approximates to the POSIX definition; it is not fully POSIX-compatible, and in multi-unit encoding domains it is probably even less compatible. -

    -

    +

    +

    The descriptions below use the actual names of the functions, but, as described above, the standard POSIX names (without the pcre2_ prefix) may also be used. -

    -
    COMPILING A PATTERN
    -

    +

    +

    COMPILING A PATTERN

    +

    The function pcre2_regcomp() is called to compile a pattern into an internal form. By default, the pattern is a C string terminated by a binary zero (but see REG_PEND below). The preg argument is a pointer to a @@ -137,8 +137,8 @@ the compiled regular expression. It is also used for input when REG_PEND is set. The regex_t structure used by pcre2_regcomp() is defined in pcre2posix.h and is not the same as the structure used by other libraries that provide POSIX-style matching. -

    -

    +

    +

    The argument cflags is either zero, or contains one or more of the bits defined by the following macros:

    @@ -204,8 +204,8 @@ The PCRE2_UTF option is set when the regular expression is passed for
     compilation to the native function. This causes the pattern itself and all data
     strings used for matching it to be treated as UTF-8 strings. Note that REG_UTF
     is not part of the POSIX standard.
    -

    -

    +

    +

    In the absence of these flags, no options are passed to the native function. This means that the regex is compiled with PCRE2 default semantics. In particular, the way it handles newline characters in the subject string is the @@ -213,22 +213,22 @@ Perl way, not the POSIX way. Note that setting PCRE2_MULTILINE has only some of the effects specified for REG_NEWLINE. It does not affect the way newlines are matched by the dot metacharacter (they are not) or by a negative class such as [^a] (they are). -

    -

    +

    +

    The yield of pcre2_regcomp() is zero on success, and non-zero otherwise. The preg structure is filled in on success, and one other member of the structure (as well as re_endp) is public: re_nsub contains the number of capturing subpatterns in the regular expression. Various error codes are defined in the header file. -

    -

    +

    +

    NOTE: If the yield of pcre2_regcomp() is non-zero, you must not attempt to use the contents of the preg structure. If, for example, you pass it to pcre2_regexec(), the result is undefined and your program is likely to crash. -

    -
    MATCHING NEWLINE CHARACTERS
    -

    +

    +

    MATCHING NEWLINE CHARACTERS

    +

    This area is not simple, because POSIX and Perl take different views of things. It is not possible to get PCRE2 to obey POSIX semantics, but then PCRE2 was never intended to be a POSIX engine. The following table lists the different @@ -256,17 +256,17 @@ This behaviour is not what happens when PCRE2 is called via its POSIX API. By default, PCRE2's behaviour is the same as Perl's, except that there is no equivalent for PCRE2_DOLLAR_ENDONLY in Perl. In both PCRE2 and Perl, there is no way to stop newline from matching [^a]. -

    -

    +

    +

    Default POSIX newline handling can be obtained by setting PCRE2_DOTALL and PCRE2_DOLLAR_ENDONLY when calling pcre2_compile() directly, but there is no way to make PCRE2 behave exactly as for the REG_NEWLINE action. When using the POSIX API, passing REG_NEWLINE to PCRE2's pcre2_regcomp() function causes PCRE2_MULTILINE to be passed to pcre2_compile(), and REG_DOTALL passes PCRE2_DOTALL. There is no way to pass PCRE2_DOLLAR_ENDONLY. -

    -
    MATCHING A PATTERN
    -

    +

    +

    MATCHING A PATTERN

    +

    The function pcre2_regexec() is called to match a compiled pattern preg against a given string, which is by default terminated by a zero byte (but see REG_STARTEND below), subject to the options in eflags. @@ -295,33 +295,33 @@ When this option is set, the subject string starts at string + should point to the first character beyond the string. There may be binary zeros within the subject string, and indeed, using REG_STARTEND is the only way to pass a subject string that contains a binary zero. -

    -

    +

    +

    Whatever the value of pmatch[0].rm_so, the offsets of the matched string and any captured substrings are still given relative to the start of string itself. (Before PCRE2 release 10.30 these were given relative to string + pmatch[0].rm_so, but this differs from other implementations.) -

    -

    +

    +

    This is a BSD extension, compatible with but not specified by IEEE Standard 1003.2 (POSIX.2), and should be used with caution in software intended to be portable to other systems. Note that a non-zero rm_so does not imply REG_NOTBOL; REG_STARTEND affects only the location and length of the string, not how it is matched. Setting REG_STARTEND and passing pmatch as NULL are mutually exclusive; the error REG_INVARG is returned. -

    -

    +

    +

    If the pattern was compiled with the REG_NOSUB flag, no data about any matched strings is returned. The nmatch and pmatch arguments of pcre2_regexec() are ignored (except possibly as input for REG_STARTEND). -

    -

    +

    +

    The value of nmatch may be zero, and the value pmatch may be NULL (unless REG_STARTEND is set); in both these cases no data about any matched strings is returned. -

    -

    +

    +

    Otherwise, the portion of the string that was matched, and also any captured substrings, are returned via the pmatch argument, which points to an array of nmatch structures of type regmatch_t, containing the @@ -331,18 +331,18 @@ of each substring, respectively. The 0th element of the vector relates to the entire portion of string that was matched; subsequent elements relate to the capturing subpatterns of the regular expression. Unused entries in the array have both structure members set to -1. -

    -

    +

    +

    regmatch_t as well as the regoff_t typedef it uses are defined in pcre2posix.h and are not warranted to have the same size or layout as other similarly named types from other libraries that provide POSIX-style matching. -

    -

    +

    +

    A successful match yields a zero return; various error codes are defined in the header file, of which REG_NOMATCH is the "expected" failure code. -

    -
    ERROR MESSAGES
    -

    +

    +

    ERROR MESSAGES

    +

    The pcre2_regerror() function maps a non-zero errorcode from either pcre2_regcomp() or pcre2_regexec() to a printable message. If preg is not NULL, the error should have arisen from the use of that @@ -351,25 +351,25 @@ the buffer is too short, only the first errbuf_size - 1 characters of the error message are used. The yield of the function is the size of buffer needed to hold the whole message, including the terminating zero. This value is greater than errbuf_size if the message was truncated. -

    -
    MEMORY USAGE
    -

    +

    +

    MEMORY USAGE

    +

    Compiling a regular expression causes memory to be allocated and associated with the preg structure. The function pcre2_regfree() frees all such memory, after which preg may no longer be used as a compiled expression. -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    +

    +

    REVISION

    +

    Last updated: 27 November 2024
    Copyright © 1997-2024 University of Cambridge. diff --git a/doc/html/pcre2sample.html b/doc/html/pcre2sample.html index 0903f04..4984ebb 100644 --- a/doc/html/pcre2sample.html +++ b/doc/html/pcre2sample.html @@ -12,38 +12,38 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    PCRE2 SAMPLE PROGRAM -
    -

    +

    +

    A simple, complete demonstration program to get you started with using PCRE2 is supplied in the file pcre2demo.c in the src directory in the PCRE2 distribution. A listing of this program is given in the pcre2demo documentation. If you do not have a copy of the PCRE2 distribution, you can -save this listing to re-create the contents of pcre2demo.c. -

    -

    +save this listing to recreate the contents of pcre2demo.c. +

    +

    The demonstration program compiles the regular expression that is its first argument, and matches it against the subject string in its second argument. No PCRE2 options are set, and default character tables are used. If matching succeeds, the program outputs the portion of the subject that matched, together with the contents of any captured substrings. -

    -

    +

    +

    If the -g option is given on the command line, the program then goes on to check for further matches of the same regular expression in the same subject string. The logic is a little bit tricky because of the possibility of matching an empty string. Comments in the code explain what is going on. -

    -

    +

    +

    The code in pcre2demo.c is an 8-bit program that uses the PCRE2 8-bit library. It handles strings and characters that are stored in 8-bit code units. By default, one character corresponds to one code unit, but if the pattern starts with "(*UTF)", both it and the subject are treated as UTF-8 strings, where characters may occupy multiple code units. -

    -

    +

    +

    If PCRE2 is installed in the standard include and library directories for your operating system, you should be able to compile the demonstration program using a command like this: @@ -62,6 +62,7 @@ this:

       ./pcre2demo 'cat|dog' 'the cat sat on the mat'
       ./pcre2demo -g 'cat|dog' 'the dog sat on the cat'
    +  ./pcre2demo -i 'cat' 'the dog sat on the CAT'
     
    Note that there is a much more comprehensive test program, called pcre2test, @@ -70,8 +71,8 @@ three PCRE2 libraries (8-bit, 16-bit, and 32-bit, though not all three need be installed). The pcre2demo program is provided as a relatively simple coding example. -

    -

    +

    +

    If you try to run pcre2demo when PCRE2 is not installed in the standard library directory, you may get an @@ -85,23 +86,23 @@ need to add -R/usr/local/lib

    (for example) to the compile command to get round this problem. -

    -
    +

    +

    AUTHOR -
    -

    +

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    +

    +

    REVISION -
    -

    -Last updated: 14 November 2023 +

    +

    +Last updated: 28 February 2025
    Copyright © 1997-2016 University of Cambridge.
    diff --git a/doc/html/pcre2serialize.html b/doc/html/pcre2serialize.html index d189bde..16c2be7 100644 --- a/doc/html/pcre2serialize.html +++ b/doc/html/pcre2serialize.html @@ -20,8 +20,8 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    SAVING AND RE-USING PRECOMPILED PCRE2 PATTERNS
    -

    +

    SAVING AND RE-USING PRECOMPILED PCRE2 PATTERNS

    +

    int32_t pcre2_serialize_decode(pcre2_code **codes, int32_t number_of_codes, const uint8_t *bytes, pcre2_general_context *gcontext); @@ -48,8 +48,8 @@ the same code unit width, and must also have the same endianness, pointer width and PCRE2_SIZE type. For example, patterns compiled on a 32-bit system using PCRE2's 16-bit library cannot be reloaded on a 64-bit system, nor can they be reloaded using the 8-bit library. -

    -

    +

    +

    Note that "serialization" in PCRE2 does not convert compiled patterns to an abstract format like Java or .NET serialization. The serialized output is really just a bytecode dump, which is why it can only be reloaded in the same @@ -57,9 +57,9 @@ environment as the one that created it. Hence the restrictions mentioned above. Applications that are not statically linked with a fixed version of PCRE2 must be prepared to recompile patterns from their sources, in order to be immune to PCRE2 upgrades. -

    -
    SECURITY CONCERNS
    -

    +

    +

    SECURITY CONCERNS

    +

    The facility for saving and restoring compiled patterns is intended for use within individual applications. As such, the data supplied to pcre2_serialize_decode() is expected to be trusted data, not data from @@ -68,9 +68,9 @@ complete validation of what is being re-loaded. Corrupted data may cause undefined results. For example, if the length field of a pattern in the serialized data is corrupted, the deserializing code may read beyond the end of the byte stream that is passed to it. -

    -
    SAVING COMPILED PATTERNS
    -

    +

    +

    SAVING COMPILED PATTERNS

    +

    Before compiled patterns can be saved they must be serialized, which in PCRE2 means converting the pattern to a stream of bytes. A single byte stream may contain any number of compiled patterns, but they must all use the same @@ -80,8 +80,8 @@ character tables. A single copy of the tables is included in the byte stream in the pcre2api documentation. -

    -

    +

    +

    The function pcre2_serialize_encode() creates a serialized byte stream from a list of compiled patterns. Its first two arguments specify the list, being a pointer to a vector of pointers to compiled patterns, and the length of @@ -100,8 +100,8 @@ of serialized patterns, or one of the following negative error codes:

  • PCRE2_ERROR_BADMAGIC means either that a pattern's code has been corrupted, or that a slot in the vector does not point to a compiled pattern. -

    -

    +

    +

    Once a set of patterns has been serialized you can save the data in any appropriate manner. Here is sample code that compiles two patterns and writes them to a file. It assumes that the variable fd refers to a file that is @@ -124,17 +124,17 @@ application has been omitted for simplicity. Note that the serialized data is binary data that may contain any of the 256 possible byte values. On systems that make a distinction between binary and non-binary data, be sure that the file is opened for binary output. -

    -

    +

    +

    Serializing a set of patterns leaves the original data untouched, so they can still be used for matching. Their memory must eventually be freed in the usual way by calling pcre2_code_free(). When you have finished with the byte stream, it too must be freed by calling pcre2_serialize_free(). If this function is called with a NULL argument, it returns immediately without doing anything. -

    -
    RE-USING PRECOMPILED PATTERNS
    -

    +

    +

    RE-USING PRECOMPILED PATTERNS

    +

    In order to re-use a set of saved patterns you must first make the serialized byte stream available in main memory (for example, by reading from a file). The management of this memory block is up to the application. You can use the @@ -173,8 +173,8 @@ error codes:

    PCRE2_ERROR_BADMAGIC may mean that the data is corrupt, or that it was compiled on a system with different endianness. -

    -

    +

    +

    Decoded patterns can be used for matching in the usual way, and must be freed by calling pcre2_code_free(). However, be aware that there is a potential race issue if you are using multiple patterns that were decoded from a single @@ -185,24 +185,24 @@ freed, but there is no locking on this reference count. Therefore, if you want to call pcre2_code_free() for these patterns in different threads, you must arrange your own locking, and ensure that pcre2_code_free() cannot be called by two threads at the same time. -

    -

    +

    +

    If a pattern was processed by pcre2_jit_compile() before being serialized, the JIT data is discarded and so is no longer available after a save/restore cycle. You can, however, process a restored pattern with pcre2_jit_compile() if you wish. -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    +

    +

    REVISION

    +

    Last updated: 19 January 2024
    Copyright © 1997-2018 University of Cambridge. diff --git a/doc/html/pcre2syntax.html b/doc/html/pcre2syntax.html index 46da3d7..bd5bc01 100644 --- a/doc/html/pcre2syntax.html +++ b/doc/html/pcre2syntax.html @@ -49,8 +49,8 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    PCRE2 REGULAR EXPRESSION SYNTAX SUMMARY
    -

    +

    PCRE2 REGULAR EXPRESSION SYNTAX SUMMARY

    +

    The full syntax and semantics of the regular expression patterns that are supported by PCRE2 are described in the pcre2pattern @@ -59,9 +59,9 @@ syntax followed by the syntax of replacement strings in substitution function. The full description of the latter is in the pcre2api documentation. -

    -
    QUOTING
    -

    +

    +

    QUOTING

    +

       \x         where x is non-alphanumeric is a literal x
       \Q...\E    treat enclosed characters as literal
    @@ -71,9 +71,9 @@ PCRE2_EXTENDED is set, causing most other white space to be ignored. Note also
     that PCRE2's handling of \Q...\E has some differences from Perl's. See the
     pcre2pattern
     documentation for details.
    -

    -
    BRACED ITEMS
    -

    +

    +

    BRACED ITEMS

    +

    With one exception, wherever brace characters { and } are required to enclose data for constructions such as \g{2} or \k{name}, space and/or horizontal tab characters that follow { or precede } are allowed and are ignored. In the case @@ -81,9 +81,9 @@ of quantifiers, they may also appear before or after the comma. The exception is \u{...} which is not Perl-compatible and is recognized only when PCRE2_EXTRA_ALT_BSUX is set. This is an ECMAScript compatibility feature, and follows ECMAScript's behaviour. -

    -
    ESCAPED CHARACTERS
    -

    +

    +

    ESCAPED CHARACTERS

    +

    This table applies to ASCII and Unicode environments. An unrecognized escape sequence causes an error.

    @@ -104,8 +104,8 @@ sequence causes an error.
     \N{U+hh..} is synonymous with \x{hh..} but is not supported in environments
     that use EBCDIC code (mainly IBM mainframes). Note that \N not followed by an
     opening curly bracket has a different meaning (see below).
    -

    -

    +

    +

    If PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX is set ("ALT_BSUX mode"), the following are also recognized:

    @@ -119,8 +119,8 @@ recognized as a hexadecimal escape; otherwise it matches a literal "x".
     Likewise, if \u (in ALT_BSUX mode) is not followed by four hexadecimal digits
     or (in EXTRA_ALT_BSUX mode) a sequence of hex digits in curly brackets, it
     matches a literal "u".
    -

    -

    +

    +

    Note that \0dd is always an octal code. The treatment of backslash followed by a non-zero digit is complicated; for details see the section "Non-printing characters" @@ -128,9 +128,9 @@ in the pcre2pattern documentation, where details of escape processing in EBCDIC environments are also given. -

    -
    CHARACTER TYPES
    -

    +

    +

    CHARACTER TYPES

    +

       .          any character except newline;
                    in dotall mode, any character whatsoever
    @@ -155,8 +155,8 @@ also given.
     of a UTF-8 or UTF-16 character. The application can lock out the use of \C by
     setting the PCRE2_NEVER_BACKSLASH_C option. It is also possible to build PCRE2
     with the use of \C permanently disabled.
    -

    -

    +

    +

    By default, \d, \s, and \w match only ASCII characters, even in UTF-8 mode or in the 16-bit and 32-bit libraries. However, if locale-specific matching is happening, \s and \w may also match characters with code points in the range @@ -164,15 +164,15 @@ happening, \s and \w may also match characters with code points in the range sequences is changed to use Unicode properties and they match many more characters, but there are some option settings that can restrict individual sequences to matching only ASCII characters. -

    -

    +

    +

    Property descriptions in \p and \P are matched caselessly; hyphens, underscores, and ASCII white space characters are ignored, in accordance with Unicode's "loose matching" rules. For example, \p{Bidi_Class=al} is the same as \p{ bidi class = AL }. -

    -
    GENERAL CATEGORY PROPERTIES FOR \p and \P
    -

    +

    +

    GENERAL CATEGORY PROPERTIES FOR \p and \P

    +

       C          Other
       Cc         Control
    @@ -222,9 +222,9 @@ as \p{ bidi class = AL }.
     
    From release 10.45, when caseless matching is set, Ll, Lu, and Lt are all equivalent to Lc. -

    -
    PCRE2 SPECIAL CATEGORY PROPERTIES FOR \p and \P
    -

    +

    +

    PCRE2 SPECIAL CATEGORY PROPERTIES FOR \p and \P

    +

       Xan        Alphanumeric: union of properties L and N
       Xps        POSIX space: property Z or tab, NL, VT, FF, CR
    @@ -235,27 +235,27 @@ equivalent to Lc.
     
    Perl and POSIX space are now the same. Perl added VT to its space character set at release 5.18. -

    -
    BINARY PROPERTIES FOR \p AND \P
    -

    +

    +

    BINARY PROPERTIES FOR \p AND \P

    +

    Unicode defines a number of binary properties, that is, properties whose only values are true or false. You can obtain a list of those that are recognized by \p and \P, along with their abbreviations, by running this command:

       pcre2test -LP
    -
    -

    -
    SCRIPT MATCHING WITH \p AND \P
    -

    +

    +

    +

    SCRIPT MATCHING WITH \p AND \P

    +

    Many script names and their 4-letter abbreviations are recognized in \p{sc:...} or \p{scx:...} items, or on their own with \p (and also \P of course). You can obtain a list of these scripts by running this command:

       pcre2test -LS
    -
    -

    -
    THE BIDI_CLASS PROPERTY FOR \p AND \P
    -

    +

    +

    +

    THE BIDI_CLASS PROPERTY FOR \p AND \P

    +

       \p{Bidi_Class:<class>}   matches a character with the given class
       \p{BC:<class>}           matches a character with the given class
    @@ -285,10 +285,10 @@ The recognized classes are:
       RLO         right-to-left override
       S           segment separator
       WS          white space
    -
    -

    -
    CHARACTER CLASSES
    -

    +

    +

    +

    CHARACTER CLASSES

    +

       [...]       positive character class
       [^...]      negative character class
    @@ -314,8 +314,8 @@ The recognized classes are:
     In PCRE2, POSIX character set names recognize only ASCII characters by default,
     but some of them use Unicode properties if PCRE2_UCP is set. You can use
     \Q...\E inside a character class.
    -

    -

    +

    +

    When PCRE2_ALT_EXTENDED_CLASS is set, UTS#18 extended character classes may be used, allowing nested character classes, combined using set operators.

    @@ -326,13 +326,13 @@ used, allowing nested character classes, combined using set operators.
       x--y        set difference (AND NOT)
       x~~y        set symmetric difference (XOR)
     
    -
    -

    -
    PERL EXTENDED CHARACTER CLASSES
    -

    +

    +

    +

    PERL EXTENDED CHARACTER CLASSES

    +

       (?[...])                Perl extended character class
    -  (?[\p{Thai} & \p{Nd}])  operators; whitespace ignored
    +  (?[\p{Thai} & \p{Nd}])  operators; white space ignored
       (?[(x - y) & z])        parentheses for grouping
     
       (?[ [^3] & \p{Nd} ])    [...] is a nested ordinary class
    @@ -352,9 +352,9 @@ as an ordinary character class. Outside of a nested [...], the only items
     permitted are backslash-escapes, POSIX sets, operators, and parentheses. Inside
     a nested ordinary class, ^ has its usual meaning (inverts the class when used
     as the first character); outside of a nested class, ^ is the XOR operator.
    -

    -
    QUANTIFIERS
    -

    +

    +

    QUANTIFIERS

    +

       ?           0 or 1, greedy
       ?+          0 or 1, possessive
    @@ -375,10 +375,10 @@ as the first character); outside of a nested class, ^ is the XOR operator.
       {,m}        zero up to m, greedy
       {,m}+       zero up to m, possessive
       {,m}?       zero up to m, lazy
    -
    -

    -
    ANCHORS AND SIMPLE ASSERTIONS
    -

    +

    +

    +

    ANCHORS AND SIMPLE ASSERTIONS

    +

       \b          word boundary
       \B          not a word boundary
    @@ -393,10 +393,10 @@ as the first character); outside of a nested class, ^ is the XOR operator.
                     also before newline at end of subject
       \z          end of subject
       \G          first matching position in subject
    -
    -

    -
    REPORTED MATCH POINT SETTING
    -

    +

    +

    +

    REPORTED MATCH POINT SETTING

    +

       \K          set reported start of match
     
    @@ -404,15 +404,15 @@ From release 10.38 \K is not permitted by default in lookaround assertions, for compatibility with Perl. However, if the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option is set, the previous behaviour is re-enabled. When this option is set, \K is honoured in positive assertions, but ignored in negative ones. -

    -
    ALTERNATION
    -

    +

    +

    ALTERNATION

    +

       expr|expr|expr...
    -
    -

    -
    CAPTURING
    -

    + +

    +

    CAPTURING

    +

       (...)           capture group
       (?<name>...)    named capture group (Perl)
    @@ -425,22 +425,22 @@ option is set, the previous behaviour is re-enabled. When this option is set,
     In non-UTF modes, names may contain underscores and ASCII letters and digits;
     in UTF modes, any Unicode letters and Unicode decimal digits are permitted. In
     both cases, a name must not start with a digit.
    -

    -
    ATOMIC GROUPS
    -

    +

    +

    ATOMIC GROUPS

    +

       (?>...)         atomic non-capture group
       (*atomic:...)   atomic non-capture group
    -
    -

    -
    COMMENT
    -

    +

    +

    +

    COMMENT

    +

       (?#....)        comment (not nestable)
    -
    -

    -
    OPTION SETTING
    -

    + +

    +

    OPTION SETTING

    +

    Changes of these options within a group are automatically cancelled at the end of the group.

    @@ -465,15 +465,15 @@ of the group.
     (?aP) implies (?aT) as well, though this has no additional effect. However, it
     means that (?-aP) also implies (?-aT) and disables all ASCII restrictions for
     POSIX classes.
    -

    -

    +

    +

    Unsetting x or xx unsets both. Several options may be set at once, and a mixture of setting and unsetting such as (?i-x) is allowed, but there may be only one hyphen. Setting (but no unsetting) is allowed after (?^ for example (?^in). An option setting may appear at the start of a non-capture group, for example (?i:...). -

    -

    +

    +

    The following are recognized only at the very start of a pattern or after one of the newline or \R sequences or options with similar syntax. More than one of them may appear. For the first three, d is a decimal number. @@ -497,9 +497,9 @@ the limits set by the caller of pcre2_match() or pcre2_dfa_match() not increase them. LIMIT_RECURSION is an obsolete synonym for LIMIT_DEPTH. The application can lock out the use of (*UTF) and (*UCP) by setting the PCRE2_NEVER_UTF or PCRE2_NEVER_UCP options, respectively, at compile time. -

    -
    NEWLINE CONVENTION
    -

    +

    +

    NEWLINE CONVENTION

    +

    These are recognized only at the very start of the pattern or after option settings with a similar syntax.

    @@ -509,19 +509,19 @@ settings with a similar syntax.
       (*ANYCRLF)      all three of the above
       (*ANY)          any Unicode newline sequence
       (*NUL)          the NUL character (binary zero)
    -
    -

    -
    WHAT \R MATCHES
    -

    +

    +

    +

    WHAT \R MATCHES

    +

    These are recognized only at the very start of the pattern or after option setting with a similar syntax.

       (*BSR_ANYCRLF)  CR, LF, or CRLF
       (*BSR_UNICODE)  any Unicode newline sequence
    -
    -

    -
    LOOKAHEAD AND LOOKBEHIND ASSERTIONS
    -

    + +

    +

    LOOKAHEAD AND LOOKBEHIND ASSERTIONS

    +

       (?=...)                     )
       (*pla:...)                  ) positive lookahead
    @@ -545,9 +545,9 @@ the maximum for each branch is limited to a value set by the caller of
     pcre2_compile() or defaulted. The default is set when PCRE2 is built
     (ultimate default 255). If every branch matches a fixed number of characters,
     the limit for each branch is 65535 characters.
    -

    -
    NON-ATOMIC LOOKAROUND ASSERTIONS
    -

    +

    +

    NON-ATOMIC LOOKAROUND ASSERTIONS

    +

    These assertions are specific to PCRE2 and are not Perl-compatible.

       (?*...)                                )
    @@ -557,37 +557,37 @@ These assertions are specific to PCRE2 and are not Perl-compatible.
       (?<*...)                               )
       (*naplb:...)                           ) synonyms
       (*non_atomic_positive_lookbehind:...)  )
    -
    -

    -
    SUBSTRING SCAN ASSERTION
    -

    +

    +

    +

    SUBSTRING SCAN ASSERTION

    +

    This feature is not Perl-compatible.

       (*scan_substring:(grouplist)...)  scan captured substring
       (*scs:(grouplist)...)             scan captured substring
     
    -The comma-separated list may identify groups in any of the following ways: +The comma-separated list "grouplist" may identify groups in any of the +following ways:
       n       absolute reference
       +n      relative reference
       -n      relative reference
       <name>  name
       'name'  name
    -
    -
    -

    -
    SCRIPT RUNS
    -

    + +

    +

    SCRIPT RUNS

    +

       (*script_run:...)           ) script run, can be backtracked into
       (*sr:...)                   )
     
       (*atomic_script_run:...)    ) atomic script run
       (*asr:...)                  )
    -
    -

    -
    BACKREFERENCES
    -

    + +

    +

    BACKREFERENCES

    +

       \n              reference by number (can be ambiguous)
       \gn             reference by number
    @@ -601,10 +601,10 @@ The comma-separated list may identify groups in any of the following ways:
       \g{name}        reference by name (Perl)
       \k{name}        reference by name (.NET)
       (?P=name)       reference by name (Python)
    -
    -

    -
    SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)
    -

    + +

    +

    SUBROUTINE REFERENCES (POSSIBLY RECURSIVE)

    +

       (?R)            recurse whole pattern
       (?n)            call subroutine by absolute number
    @@ -620,33 +620,59 @@ The comma-separated list may identify groups in any of the following ways:
       \g'+n'          call subroutine by relative number (PCRE2 extension)
       \g<-n>          call subroutine by relative number (PCRE2 extension)
       \g'-n'          call subroutine by relative number (PCRE2 extension)
    -
    -

    -
    CONDITIONAL PATTERNS
    -

    + +The variants using parentheses (?...) may also specify a list of capture groups +to return, which shall be retained in the calling subexpression if set during +the recursion (this feature is not supported by Perl). +

    +  (?R(grouplist))       recurse whole pattern, returning capture groups
    +                          (PCRE2 extension)
    +  (?n(grouplist))       )
    +  (?+n(grouplist))      ) call subroutine, returning capture groups
    +  (?-n(grouplist))      )   (PCRE2 extension)
    +  (?&name(grouplist))   )
    +  (?P>name(grouplist))  )
    +
    +The comma-separated list "grouplist" uses the same syntax as +(*scan_substring:(grouplist)...), and may identify groups in any of the +following ways: +
    +  n       absolute reference
    +  +n      relative reference
    +  -n      relative reference
    +  <name>  name
    +  'name'  name
    +
    +

    +

    CONDITIONAL PATTERNS

    +

       (?(condition)yes-pattern)
       (?(condition)yes-pattern|no-pattern)
     
    -  (?(n)               absolute reference condition
    -  (?(+n)              relative reference condition (PCRE2 extension)
    -  (?(-n)              relative reference condition (PCRE2 extension)
    -  (?(<name>)          named reference condition (Perl)
    -  (?('name')          named reference condition (Perl)
    -  (?(name)            named reference condition (PCRE2, deprecated)
    -  (?(R)               overall recursion condition
    -  (?(Rn)              specific numbered group recursion condition
    -  (?(R&name)          specific named group recursion condition
    -  (?(DEFINE)          define groups for reference
    -  (?(VERSION[>]=n.m)  test PCRE2 version
    -  (?(assert)          assertion condition
    +  (?(n)                absolute reference condition
    +  (?(+n)               relative reference condition (PCRE2 extension)
    +  (?(-n)               relative reference condition (PCRE2 extension)
    +  (?(<name>)           named reference condition (Perl)
    +  (?('name')           named reference condition (Perl)
    +  (?(name)             named reference condition (PCRE2, deprecated)
    +  (?(R)                overall recursion condition
    +  (?(Rn)               specific numbered group recursion condition
    +  (?(R&name)           specific named group recursion condition
    +  (?(DEFINE)           define groups for reference
    +  (?(VERSION[>]=n[.m]) test PCRE2 version
    +  (?(assert)           assertion condition
     
    Note the ambiguity of (?(R) and (?(Rn) which might be named reference conditions or recursion tests. Such a condition is interpreted as a reference condition if the relevant named group exists. -

    -
    BACKTRACKING CONTROL
    -

    +
    +
    +The parts within brackets for the VERSION conditional syntax could be ommited. +The fractional part of the version number defaults to 0 in that case. +

    +

    BACKTRACKING CONTROL

    +

    All backtracking control verbs may be in the form (*VERB:NAME). For (*MARK) the name is mandatory, for the others it is optional. (*SKIP) changes its behaviour if :NAME is present. The others just set a name for passing back to the caller, @@ -671,9 +697,9 @@ pattern is not anchored. The effect of one of these verbs in a group called as a subroutine is confined to the subroutine call. -

    -
    CALLOUTS
    -

    +

    +

    CALLOUTS

    +

       (?C)            callout (assumed number 0)
       (?Cn)           callout with numerical data n
    @@ -682,9 +708,9 @@ to the subroutine call.
     The allowed string delimiters are ` ' " ^ % # $ (which are the same for the
     start and the end), and the starting delimiter { matched with the ending
     delimiter }. To encode the ending delimiter within the string, double it.
    -

    -
    REPLACEMENT STRINGS
    -

    +

    +

    REPLACEMENT STRINGS

    +

    If the PCRE2_SUBSTITUTE_LITERAL option is set, a replacement string for pcre2_substitute() is not interpreted. Otherwise, by default, the only special character is the dollar character in one of the following forms: @@ -696,31 +722,32 @@ special character is the dollar character in one of the following forms: $` insert the substring that precedes the match $' insert the substring that follows the match $_ insert the entire input string + $+ insert the highest-numbered capture group which matched $*MARK or ${*MARK} insert a control verb name

    For ${n}, n can be a name or a number. If PCRE2_SUBSTITUTE_EXTENDED is set, there is additional interpretation: -

    -

    +

    +

    1. Backslash is an escape character, and the forms described in "ESCAPED CHARACTERS" above are recognized. Also:

    -  \Q...\E   can be used to suppress interpretation
    -  \l        force the next character to lower case
    -  \u        force the next character to upper case
    -  \L        force subsequent characters to lower case
    -  \U        force subsequent characters to upper case
    -  \u\L      force next character to upper case, then all lower
    -  \l\U      force next character to lower case, then all upper
    -  \E        end \L or \U case forcing
    -  \b        backspace character (note: as in character class in pattern)
    -  \v        vertical tab character (note: not the same as in a pattern)
    +  \Q...\E can be used to suppress interpretation
    +  \l      force the next character to lower case
    +  \u      force the next character to upper case
    +  \L      force subsequent characters to lower case
    +  \U      force subsequent characters to upper case
    +  \u\L    force next character to upper case, then all lower
    +  \l\U    force next character to lower case, then all upper
    +  \E      end \L or \U case forcing
    +  \b      backspace character (note: as in character class in pattern)
    +  \v      vertical tab character (note: not the same as in a pattern)
     
    2. The Python form \g<n>, where the angle brackets are part of the syntax and n is either a group name or a number, is recognized as an alternative way of inserting the contents of a group, for example \g<3>. -

    -

    +

    +

    3. Capture substitution supports the following additional forms:

       ${n:-string}             default for unset group
    @@ -728,24 +755,24 @@ of inserting the contents of a group, for example \g<3>.
     
    The substitution strings themselves are expanded. Backslash can be used to escape colons and closing curly brackets. -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2pattern(3), pcre2api(3), pcre2callout(3), pcre2matching(3), pcre2(3). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 27 November 2024 +

    +

    REVISION

    +

    +Last updated: 14 October 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2test.html b/doc/html/pcre2test.html index db9073f..cc9136a 100644 --- a/doc/html/pcre2test.html +++ b/doc/html/pcre2test.html @@ -35,8 +35,8 @@ please consult the man page, in case the conversion went wrong.

  • AUTHOR
  • REVISION -
    SYNOPSIS
    -

    +

    SYNOPSIS

    +

    pcre2test [options] [input file [output file]]

    @@ -49,24 +49,24 @@ documentation. For details of the PCRE2 library function calls and their options, see the pcre2api documentation. -

    -

    +

    +

    The input for pcre2test is a sequence of regular expression patterns and subject strings to be matched. There are also command lines for setting defaults and controlling some special actions. The output shows the result of each match attempt. Modifiers on external or internal command lines, the patterns, and the subject lines specify PCRE2 function options, control how the subject is processed, and what output is produced. -

    -

    +

    +

    There are many obscure modifiers, some of which are specifically designed for use in conjunction with the test script and data files that are distributed as part of PCRE2. All the modifiers are documented here, some without much justification, but many of them are unlikely to be of use except when testing the libraries. -

    -
    PCRE2's 8-BIT, 16-BIT AND 32-BIT LIBRARIES
    -

    +

    +

    PCRE2's 8-BIT, 16-BIT AND 32-BIT LIBRARIES

    +

    Different versions of the PCRE2 library can be built to support character strings that are encoded in 8-bit, 16-bit, or 32-bit code units. One, two, or all three of these libraries may be simultaneously installed. The @@ -75,21 +75,21 @@ input and output are always in 8-bit format. When testing the 16-bit or 32-bit libraries, patterns and subject strings are converted to 16-bit or 32-bit format before being passed to the library functions. Results are converted back to 8-bit code units for output. -

    -

    +

    +

    In the rest of this document, the names of library functions and structures are given in generic form, for example, pcre2_compile(). The actual names used in the libraries have a suffix _8, _16, or _32, as appropriate. -

    -
    INPUT ENCODING
    -

    +

    +

    INPUT ENCODING

    +

    Input to pcre2test is processed line by line, either by calling the C library's fgets() function, or via the libreadline or libedit library. In some Windows environments character 26 (hex 1A) causes an immediate end of file, and no further data is read, so this character should be avoided unless you really want that action. -

    -

    +

    +

    The input is processed using C's string functions, so must not contain binary zeros, even though in Unix-like environments, fgets() treats any bytes other than newline as data characters. An error is generated if a binary zero @@ -98,11 +98,11 @@ which makes it possible to include any data value in strings that are passed to the library for matching. For patterns, there is a facility for specifying some or all of the 8-bit input characters as hexadecimal pairs, which makes it possible to include binary zeros. -

    -
    +

    +

    Input for the 16-bit and 32-bit libraries -
    -

    +

    +

    When testing the 16-bit or 32-bit libraries, there is a need to be able to generate character code points greater than 255 in the strings that are passed to the library. For subject lines and some patterns, backslash escapes can be @@ -110,8 +110,8 @@ used. In addition, when the utf modifier (see "Setting compilation options" below) is set, the pattern and any following subject lines are interpreted as UTF-8 strings and translated to UTF-16 or UTF-32 as appropriate. -

    -

    +

    +

    For non-UTF testing of wide characters, the utf8_input modifier can be used. This is mutually exclusive with utf, and is allowed only in 16-bit or 32-bit mode. It causes the pattern and following subject lines to be treated @@ -119,67 +119,63 @@ as UTF-8 according to the original definition (RFC 2279), which allows for character values up to 0x7fffffff. Each character is placed in one 16-bit or 32-bit code unit (in the 16-bit case, values greater than 0xffff cause an error to occur). -

    -

    +

    +

    UTF-8 (in its original definition) is not capable of encoding values greater than 0x7fffffff, but such values can be handled by the 32-bit library. When testing this library in non-UTF mode with utf8_input set, if any character is preceded by the byte 0xff (which is an invalid byte in UTF-8) 0x80000000 is added to the character's value. For subject strings, using an escape sequence is preferable. -

    -
    COMMAND LINE OPTIONS
    -

    +

    +

    COMMAND LINE OPTIONS

    +

    -8 If the 8-bit library has been built, this option causes it to be used (this is the default). If the 8-bit library has not been built, this option causes an error. -

    -

    +

    +

    -16 If the 16-bit library has been built, this option causes it to be used. If the 8-bit library has not been built, this is the default. If the 16-bit library has not been built, this option causes an error. -

    -

    +

    +

    -32 If the 32-bit library has been built, this option causes it to be used. If no other library has been built, this is the default. If the 32-bit library has not been built, this option causes an error. -

    -

    +

    +

    -ac Behave as if each pattern has the auto_callout modifier, that is, insert automatic callouts into every pattern that is compiled. -

    -

    +

    +

    -AC As for -ac, but in addition behave as if each subject line has the callout_extra modifier, that is, show additional information from callouts. -

    -

    +

    +

    -b Behave as if each pattern has the fullbincode modifier; the full internal binary form of the pattern is output after compilation. -

    -

    +

    +

    -C Output the version number of the PCRE2 library, and all available information about the optional features that are included, and then exit with zero exit code. All other options are ignored. If both -C and -LM are present, whichever is first is recognized. -

    -

    +

    +

    -C option Output information about a specific build-time option, then exit. This functionality is intended for use in scripts such as RunTest. The following options output the value and set the exit code as indicated:

    -  ebcdic-nl  the code for LF (= NL) in an EBCDIC environment:
    -               either 0x15 or 0x25
    -               0 if used in an ASCII/Unicode environment
    -               exit code is always 0
       linksize   the configured internal link size (2, 3, or 4)
                    exit code is set to the link size
       newline    the default newline setting:
    @@ -194,6 +190,10 @@ to the same value:
     
       backslash-C  \C is supported (not locked out)
       ebcdic       compiled for an EBCDIC environment
    +  ebcdic-io    if PCRE2 is compiled for EBCDIC, whether pcre2test's input and
    +                 output is EBCDIC or ASCII
    +  ebcdic-nl25  if PCRE2 is compiled for EBCDIC, whether NL (= LF) is 0x25
    +                 (otherwise it is 0x15, the default)
       jit          just-in-time support is available
       pcre2-16     the 16-bit library was built
       pcre2-32     the 32-bit library was built
    @@ -211,89 +211,106 @@ information. It returns one of the following values:
       3  Unexpected return from test call to pcre2_jit_compile()
     
    If an unknown option is given, an error message is output; the exit code is 0. -

    -

    +

    +

    +--colo[u]r[=<always,auto,never>] +By default, the output is coloured if the output file is a terminal (auto). +Force or suppress output of ANSI colour escapes with always and never +respectively. +

    +

    -d Behave as if each pattern has the debug modifier; the internal form and information about the compiled pattern is output after compilation; -d is equivalent to -b -i. -

    -

    +

    +

    -dfa Behave as if each subject line has the dfa modifier; matching is done using the pcre2_dfa_match() function instead of the default pcre2_match(). -

    -

    +

    +

    +-E +Run in "preprocess only" mode (similar to "gcc -E"). The "#if ... #endif" +commands are processed, and all other lines are printed verbatim. +

    +

    -error number[,number,...] Call pcre2_get_error_message() for each of the error numbers in the comma-separated list, display the resulting messages on the standard output, then exit with zero exit code. The numbers may be positive or negative. This is a convenience facility for PCRE2 maintainers. -

    -

    +

    +

    -help Output a brief summary these options and then exit. -

    -

    +

    +

    -i Behave as if each pattern has the info modifier; information about the compiled pattern is given after compilation. -

    -

    +

    +

    -jit Behave as if each pattern line has the jit modifier; after successful compilation, each pattern is passed to the just-in-time compiler, if available. -

    -

    +

    +

    -jitfast Behave as if each pattern line has the jitfast modifier; after successful compilation, each pattern is passed to the just-in-time compiler, if available, and each subject line is passed directly to the JIT matcher via its "fast path". -

    -

    +

    +

    -jitverify Behave as if each pattern line has the jitverify modifier; after successful compilation, each pattern is passed to the just-in-time compiler, if available, and the use of JIT for matching is verified. -

    -

    +

    +

    -LM List modifiers: write a list of available pattern and subject modifiers to the standard output, then exit with zero exit code. All other options are ignored. If both -C and any -Lx options are present, whichever is first is recognized. -

    -

    +

    +

    -LP List properties: write a list of recognized Unicode properties to the standard output, then exit with zero exit code. All other options are ignored. If both -C and any -Lx options are present, whichever is first is recognized. -

    -

    +

    +

    -LS List scripts: write a list of recognized Unicode script names to the standard output, then exit with zero exit code. All other options are ignored. If both -C and any -Lx options are present, whichever is first is recognized. -

    -

    +

    +

    +-malloc +Exercise malloc() failures, by first counting the number of calls made to malloc +during pattern compilation and matching, then re-running the compilation and +matching that many times, exercising a failure of each malloc() call. +

    +

    -pattern modifier-list Behave as if each pattern line contains the given modifiers. -

    -

    +

    +

    -q Do not output the version number of pcre2test at the start of execution. -

    -

    +

    +

    -S size On Unix-like systems, set the size of the run-time stack to size mebibytes (units of 1024*1024 bytes). -

    -

    +

    +

    -subject modifier-list Behave as if each subject line contains the given modifiers. -

    -

    +

    +

    -t Run each compile and match many times with a timer, and output the resulting times per compile or match. When JIT is used, separate times are given for the @@ -301,37 +318,42 @@ initial compile and the JIT compile. You can control the number of iterations that are used for timing by following -t with a number (as a separate item on the command line). For example, "-t 1000" iterates 1000 times. The default is to iterate 500,000 times. -

    -

    +

    +

    -tm This is like -t except that it times only the matching phase, not the compile phase. -

    -

    +

    +

    -T -TM These behave like -t and -tm, but in addition, at the end of a run, the total times for all compiles and matches are output. -

    -

    +

    +

    +-unittest +Run a fixed set of additional tests of the PCRE2 API which are not driven by +the test input files, and then exit. +

    +

    -version Output the PCRE2 version number and then exit. -

    -
    DESCRIPTION
    -

    +

    +

    DESCRIPTION

    +

    If pcre2test is given two filename arguments, it reads from the first and writes to the second. If the first name is "-", input is taken from the standard input. If pcre2test is given only one argument, it reads from that file and writes to stdout. Otherwise, it reads from stdin and writes to stdout. -

    -

    +

    +

    When pcre2test is built, a configuration option can specify that it should be linked with the libreadline or libedit library. When this is done, if the input is from a terminal, it is read using the readline() function. This provides line-editing and history facilities. The output from the -help option states whether or not readline() will be used. -

    -

    +

    +

    The program handles any number of tests, each of which consists of a set of input lines. Each set starts with a regular expression pattern, followed by any number of subject lines to be matched against that pattern. In between sets of @@ -340,14 +362,14 @@ some restrictions, can also be processed by the perltest.sh script that is distributed with PCRE2 as a means of checking that the behaviour of PCRE2 and Perl is the same. For a specification of perltest.sh, see the comments near its beginning. See also the #perltest command below. -

    -

    +

    +

    When the input is a terminal, pcre2test prompts for each line of input, using "re>" to prompt for regular expression patterns, and "data>" to prompt for subject lines. Command lines starting with # can be entered only in response to the "re>" prompt. -

    -

    +

    +

    Each subject line is matched separately and independently. If you want to do multi-line matches, you have to use the \n escape sequence (or \r or \r\n, etc., depending on the newline setting) in a single line of input to encode the @@ -355,14 +377,14 @@ newline sequences. There is no limit on the length of subject lines; the input buffer is automatically extended if it is too small. There are replication features that makes it possible to generate long repetitive pattern or subject lines without having to supply them explicitly. -

    -

    +

    +

    An empty line or the end of the file signals the end of the subject lines for a test, at which point a new pattern or command line is expected if there is still input to be read. -

    -
    COMMAND LINES
    -

    +

    +

    COMMAND LINES

    +

    In between sets of test data, a line that begins with # is interpreted as a command line. If the first character is followed by white space or an exclamation mark, the line is treated as a comment, and ignored. Otherwise, the @@ -376,8 +398,8 @@ the use of (*UTF) and (*UCP) at the start of patterns. This command also forces an error if a subsequent pattern contains any occurrences of \P, \p, or \X, which are still supported when PCRE2_UTF is not set, but which require Unicode property support to be included in the library. -

    -

    +

    +

    This is a trigger guard that is used in test files to ensure that UTF or Unicode property tests are not accidentally added to files that are used when Unicode support is not included in the library. Setting PCRE2_NEVER_UTF and @@ -407,8 +429,8 @@ pattern is compiled. The standard test files contain tests of various newline conventions, but the majority of the tests expect a single linefeed to be recognized as a newline by default. Without special action the tests would fail when PCRE2 is compiled with either CR or CRLF as the default newline. -

    -

    +

    +

    The #newline_default command specifies a list of newline types that are acceptable as the default. The types must be one of CR, LF, CRLF, ANYCRLF, ANY, or NUL (in upper or lower case), for example: @@ -421,8 +443,8 @@ first newline convention in the list (LF in the above example) is added to any pattern that does not already have a newline modifier. If the newline list is empty, the feature is turned off. This command is present in a number of the standard test input files. -

    -

    +

    +

    When the POSIX API is being tested there is no way to override the default newline convention, though it is possible to set the newline convention from within the pattern. A warning is given if the posix or posix_nosub @@ -440,8 +462,8 @@ This line is used in test files that can also be processed by perltest.sh to confirm that Perl gives the same results as PCRE2. Subsequent tests are checked for the use of pcre2test features that are incompatible with the perltest.sh script. -

    -

    +

    +

    Patterns must use '/' as their delimiter, and only certain modifiers are supported. Comment lines, #pattern commands, and #subject commands that set or unset "mark" are recognized and acted on. The #perltest, #forbid_utf, and @@ -468,19 +490,30 @@ in the section entitled "Saving and restoring compiled patterns"

    This command sets a default modifier list that applies to all subsequent subject lines. Modifiers on a subject line can change these settings. -

    -
    MODIFIER SYNTAX
    -

    +

    +  #if CONDITION
    +  ...
    +  #endif
    +
    +If CONDITION is true, then the command is printed, and its contents are +processed as normal, including printing the commandlines to the output. If +CONDITION is false, then all lines between the "#if" and "#endif" are skipped +and not printed. The CONDITION can be any of the conditions which are tested by +the "-C" commandline option and which set pcre2test's exit code to a boolean +value. The CONDITION may also be preceded by "!". +

    +

    MODIFIER SYNTAX

    +

    Modifier lists are used with both pattern and subject lines. Items in a list -are separated by commas followed by optional white space. Trailing whitespace +are separated by commas followed by optional white space. Trailing white space in a modifier list is ignored. Some modifiers may be given for both patterns and subject lines, whereas others are valid only for one or the other. Each modifier has a long name, for example "anchored", and some of them must be followed by an equals sign and a value, for example, "offset=12". Values cannot contain comma characters, but may contain spaces. Modifiers that do not take values may be preceded by a minus sign to turn off a previous setting. -

    -

    +

    +

    A few of the more common modifiers can also be specified as single letters, for example "i" for "caseless". In documentation, following the Perl convention, these are written with a slash ("the /i modifier") for clarity. Abbreviated @@ -492,9 +525,9 @@ sequence of these abbreviations. For example: This is a pattern line whose modifier list starts with two one-letter modifiers (/i and /g). The lower-case abbreviated modifiers are the same as used in Perl. -

    -
    PATTERN SYNTAX
    -

    +

    +

    PATTERN SYNTAX

    +

    A pattern line must start with one of the following characters (common symbols, excluding pattern meta-characters):

    @@ -524,12 +557,12 @@ backslash, because
     
    is interpreted as the first line of a pattern that starts with "abc/", causing pcre2test to read the next line as a continuation of the regular expression. -

    -

    +

    +

    A pattern can be followed by a modifier list (details below). -

    -
    SUBJECT LINE SYNTAX
    -

    +

    +

    SUBJECT LINE SYNTAX

    +

    Before each subject line is passed to pcre2_match(), pcre2_dfa_match(), or pcre2_jit_match(), leading and trailing white space is removed, and the line is scanned for backslash escapes, unless the @@ -558,8 +591,8 @@ modifier on the pattern. It is always recognized. There may be any number of hexadecimal digits inside the braces; invalid values provoke error messages but when using \N{U+hh...} with some invalid unicode characters they will be accepted with a warning instead. -

    -

    +

    +

    Note that even in UTF-8 mode, \xhh (and depending of how large, \ddd) describe one byte rather than one character; this makes it possible to construct invalid UTF-8 sequences for testing purposes. On the other hand, @@ -568,18 +601,18 @@ more than one byte if the value is greater than 127. To avoid the ambiguity it is preferred to use \N{U+hh...} when describing characters. When testing the 8-bit library not in UTF-8 mode, \x{hh} generates one byte for values that could fit on it, and causes an error for greater values. -

    -

    +

    +

    When testing the 16-bit library, not in UTF-16 mode, all 4-digit \x{hhhh} values are accepted. This makes it possible to construct invalid UTF-16 sequences for testing purposes. -

    -

    +

    +

    When testing the 32-bit library, not in UTF-32 mode, all 4 to 8-digit \x{...} values are accepted. This makes it possible to construct invalid UTF-32 sequences for testing purposes. -

    -

    +

    +

    There is a special backslash sequence that specifies replication of one or more characters:

    @@ -592,14 +625,14 @@ part of the file. For example:
     
    is converted to "abcabcabcabc". This feature does not support nesting. To include a closing square bracket in the characters, code it as \x5D. -

    -

    +

    +

    A backslash followed by an equals sign marks the end of the subject string and the start of a modifier list. For example:

       abc\=notbol,notempty
     
    -If the subject string is empty and \= is followed by whitespace, the line is +If the subject string is empty and \= is followed by white space, the line is treated as a comment line, and is not used for matching. For example:
       \= This is a comment.
    @@ -610,24 +643,24 @@ character. A backslash followed by anything else causes an error. However, if
     the very last character in the line is a backslash (and there is no modifier
     list), it is ignored. This gives a way of passing an empty line as data, since
     a real empty line terminates the data input.
    -

    -

    +

    +

    If the subject_literal modifier is set for a pattern, all subject lines that follow are treated as literals, with no special treatment of backslashes. No replication is possible, and any subject modifiers must be set as defaults by a #subject command. -

    -
    PATTERN MODIFIERS
    -

    +

    +

    PATTERN MODIFIERS

    +

    There are several types of modifier that can appear in pattern lines. Except where noted below, they may also be used in #pattern commands. A pattern's modifier list can add to or override default modifiers that were set by a previous #pattern command. -

    -
    +

    +

    Setting compilation options -
    -

    +

    +

    The following modifiers set options for pcre2_compile(). Most of them set bits in the options argument of that function, but those whose names start with PCRE2_EXTRA are additional options that are set in the compile context. @@ -711,11 +744,11 @@ calling pcre2_set_optimize() before invoking the regex compiler. See the pcre2_set_optimize documentation for details on these optimizations. -

    -
    +

    +

    Setting compilation controls -
    -

    +

    +

    The following modifiers affect the compilation process or request information about the pattern. There are single-letter abbreviations for some that are heavily used in the test files. @@ -758,41 +791,41 @@ heavily used in the test files. utf8_input treat input as UTF-8

    The effects of these modifiers are described in the following sections. -

    -
    +

    +

    Newline and \R handling -
    -

    +

    +

    The bsr modifier specifies what \R in a pattern should match. If it is set to "anycrlf", \R matches CR, LF, or CRLF only. If it is set to "unicode", \R matches any Unicode newline sequence. The default can be specified when PCRE2 is built; if it is not, the default is set to Unicode. -

    -

    +

    +

    The newline modifier specifies which characters are to be interpreted as newlines, both in the pattern and in subject lines. The type must be one of CR, LF, CRLF, ANYCRLF, ANY, or NUL (in upper or lower case). -

    -
    +

    +

    Information about a pattern -
    -

    +

    +

    The debug modifier is a shorthand for info,fullbincode, requesting all available information. -

    -

    +

    +

    The bincode modifier causes a representation of the compiled code to be output after compilation. This information does not contain length and offset values, which ensures that the same output is generated for different internal link sizes and different code unit widths. By using bincode, the same regression tests can be used in different environments. -

    -

    +

    +

    The fullbincode modifier, by contrast, does include length and offset values. This is used in a few special tests that run only for specific code unit widths and link sizes, and is also useful for one-off tests. -

    -

    +

    +

    The info modifier requests information about the compiled pattern (whether it is anchored, has a fixed first character, and so on). The information is obtained from the pcre2_pattern_info() function. Here are @@ -823,42 +856,42 @@ not necessarily the last character. These lines are omitted if no starting or ending code units are recorded. The subject length line is omitted when no_start_optimize is set because the minimum length is not calculated when it can never be used. -

    -

    +

    +

    The framesize modifier shows the size, in bytes, of each storage frame used by pcre2_match() for handling backtracking. The size depends on the number of capturing parentheses in the pattern. A vector of these frames is used at matching time; its overall size is shown when the heaframes_size subject modifier is set. -

    -

    +

    +

    The callout_info modifier requests information about all the callouts in the pattern. A list of them is output at the end of any other information that is requested. For each callout, either its number or string is given, followed by the item that follows it in the pattern. -

    -
    +

    +

    Passing a NULL context -
    -

    +

    +

    Normally, pcre2test passes a context block to pcre2_compile(). If the null_context modifier is set, however, NULL is passed. This is for testing that pcre2_compile() behaves correctly in this case (it uses default values). -

    -
    +

    +

    Passing a NULL pattern -
    -

    +

    +

    The null_pattern modifier is for testing the behaviour of pcre2_compile() when the pattern argument is NULL. The length value passed is the default PCRE2_ZERO_TERMINATED unless use_length is set. Any length other than zero causes an error. -

    -
    +

    +

    Specifying pattern characters in hexadecimal -
    -

    +

    +

    The hex modifier specifies that the characters of the pattern, except for substrings enclosed in single or double quotes, are to be interpreted as pairs of hexadecimal digits. This feature is provided as a way of creating patterns @@ -876,37 +909,37 @@ nine characters, only two of which are specified in hexadecimal: Either single or double quotes may be used. There is no way of including the delimiter within a substring. The hex and expand modifiers are mutually exclusive. -

    -
    +

    +

    Specifying the pattern's length -
    -

    +

    +

    By default, patterns are passed to the compiling functions as zero-terminated strings but can be passed by length instead of being zero-terminated. The use_length modifier causes this to happen. Using a length happens automatically (whether or not use_length is set) when hex is set, because patterns specified in hexadecimal may contain binary zeros. -

    -

    +

    +

    If hex or use_length is used with the POSIX wrapper API (see "Using the POSIX wrapper API" below), the REG_PEND extension is used to pass the pattern's length. -

    -
    +

    +

    Specifying a maximum for variable lookbehinds -
    -

    +

    +

    Variable lookbehind assertions are supported only if, for each one, there is a maximum length (in characters) that it can match. There is a limit on this, whose default can be set at build time, with an ultimate default of 255. The max_varlookbehind modifier uses the pcre2_set_max_varlookbehind() function to change the limit. Lookbehinds whose branches each match a fixed length are limited to 65535 characters per branch. -

    -
    +

    +

    Specifying wide characters in 16-bit and 32-bit modes -
    -

    +

    +

    In 16-bit and 32-bit modes, all input is automatically treated as UTF-8 and translated to UTF-16 or UTF-32 when the utf modifier is set. For testing the 16-bit and 32-bit libraries in non-UTF mode, the utf8_input modifier @@ -915,11 +948,11 @@ interpreted as UTF-8 as a means of specifying wide characters. More details are given in "Input encoding" above. -

    -
    +

    +

    Generating long repetitive patterns -
    -

    +

    +

    Some tests use long patterns that are very repetitive. Instead of creating a very long input line for such a pattern, you can use a special repetition feature, similar to the one described for subject lines above. If the @@ -934,21 +967,21 @@ cannot be nested. An initial "\[" sequence is recognized only if "]{" followed by decimal digits and "}" is found later in the pattern. If not, the characters remain in the pattern unaltered. The expand and hex modifiers are mutually exclusive. -

    -

    +

    +

    If part of an expanded pattern looks like an expansion, but is really part of the actual pattern, unwanted expansion can be avoided by giving two values in the quantifier. For example, \[AB]{6000,6000} is not recognized as an expansion item. -

    -

    +

    +

    If the info modifier is set on an expanded pattern, the result of the expansion is included in the information that is output. -

    -
    +

    +

    JIT compilation -
    -

    +

    +

    Just-in-time (JIT) compiling is a heavyweight optimization that can greatly speed up pattern matching. See the pcre2jit @@ -960,8 +993,8 @@ different code is generated for the different cases. See the partial modifier in "Subject Modifiers" below for details of how these options are specified for each match attempt. -

    -

    +

    +

    JIT compilation is requested by the jit pattern modifier, which may optionally be followed by an equals sign and a number in the range 0 to 7. The three bits that make up the number specify which of the three JIT operating @@ -989,34 +1022,34 @@ require it. Note also that if you request JIT compilation only for partial matching (for example, jit=2) but do not set the partial modifier on a subject line, that match will not use JIT code because none was compiled for non-partial matching. -

    -

    +

    +

    If JIT compilation is successful, the compiled JIT code will automatically be used when an appropriate type of match is run, except when incompatible run-time options are specified. For more details, see the pcre2jit documentation. See also the jitstack modifier below for a way of setting the size of the JIT stack. -

    -

    +

    +

    If the jitfast modifier is specified, matching is done using the JIT "fast path" interface, pcre2_jit_match(), which skips some of the sanity checks that are done by pcre2_match(), and of course does not work when JIT is not supported. If jitfast is specified without jit, jit=7 is assumed. -

    -

    +

    +

    If the jitverify modifier is specified, information about the compiled pattern shows whether JIT compilation was or was not successful. If jitverify is specified without jit, jit=7 is assumed. If JIT compilation is successful when jitverify is set, the text "(JIT)" is added to the first output line after a match or non match when JIT-compiled code was actually used in the match. -

    -
    +

    +

    Setting a locale -
    -

    +

    +

    The locale modifier must specify the name of a locale, for example:

       /pattern/locale=fr_FR
    @@ -1028,11 +1061,11 @@ are used when matching the following subject lines. The locale modifier
     applies only to the pattern on which it appears, but can be given in a
     #pattern command if a default is needed. Setting a locale and alternate
     character tables are mutually exclusive.
    -

    -
    +

    +

    Showing pattern memory -
    -

    +

    +

    The memory modifier causes the size in bytes of the memory used to hold the compiled pattern to be output. This does not include the size of the pcre2_code block; it is just the actual compiled data. If the pattern is @@ -1043,40 +1076,40 @@ also output. Here is an example: Memory allocation (code space): 21 Memory allocation (JIT code): 1910 -

    -

    -
    + +

    +

    Limiting nested parentheses -
    -

    +

    +

    The parens_nest_limit modifier sets a limit on the depth of nested parentheses in a pattern. Breaching the limit causes a compilation error. The default for the library is set when PCRE2 is built, but pcre2test sets its own default of 220, which is required for running the standard test suite. -

    -
    +

    +

    Limiting the pattern length -
    -

    +

    +

    The max_pattern_length modifier sets a limit, in code units, to the length of pattern that pcre2_compile() will accept. Breaching the limit causes a compilation error. The default is the largest number a PCRE2_SIZE variable can hold (essentially unlimited). -

    -
    +

    +

    Limiting the size of a compiled pattern -
    -

    +

    +

    The max_pattern_compiled_length modifier sets a limit, in bytes, to the amount of memory used by a compiled pattern. Breaching the limit causes a compilation error. The default is the largest number a PCRE2_SIZE variable can hold (essentially unlimited). -

    -
    +

    +

    Using the POSIX wrapper API -
    -

    +

    +

    The posix and posix_nosub modifiers cause pcre2test to call PCRE2 via the POSIX wrapper API rather than its native API. When posix_nosub is used, the POSIX option REG_NOSUB is passed to @@ -1101,21 +1134,21 @@ is passed to regerror() in the event of a compilation error. For example: This provides a means of testing the behaviour of regerror() when the buffer is too small for the error message. If this modifier has not been set, a large buffer is used. -

    -

    +

    +

    The aftertext and allaftertext subject modifiers work as described below. All other modifiers are either ignored, with a warning message, or cause an error. -

    -

    +

    +

    The pattern is passed to regcomp() as a zero-terminated string by default, but if the use_length or hex modifiers are set, the REG_PEND extension is used to pass it by length. -

    -
    +

    +

    Testing the stack guard feature -
    -

    +

    +

    The stackguard modifier is used to test the use of pcre2_set_compile_recursion_guard(), a function that is provided to enable stack availability to be checked during compilation (see the @@ -1126,11 +1159,11 @@ callback from pcre2_compile() to a local function. The argument it receives is the current nesting parenthesis depth; if this is greater than the value given by the modifier, non-zero is returned, causing the compilation to be aborted. -

    -
    +

    +

    Using alternative character tables -
    -

    +

    +

    The value specified for the tables modifier must be one of the digits 0, 1, 2, or 3. It causes a specific set of built-in character tables to be passed to pcre2_compile(). This is used in the PCRE2 tests to check behaviour @@ -1146,11 +1179,11 @@ In tables 2, some characters whose codes are greater than 128 are identified as letters, digits, spaces, etc. Tables 3 can be used only after a #loadtables command has loaded them from a binary file. Setting alternate character tables and a locale are mutually exclusive. -

    -
    +

    +

    Setting certain match controls -
    -

    +

    +

    The following modifiers are really subject modifiers, and are described under "Subject Modifiers" below. However, they may be included in a pattern's modifier list, in which case they are applied to every subject line that is @@ -1167,7 +1200,8 @@ process. heapframes_size show match data heapframes size jitstack=<n> set size of JIT stack mark show mark values - replace=<string> specify a replacement string + null_substitute_match_data substitute with NULL match data + replace=<str> specify a replacement string startchar show starting character when relevant substitute_callout use substitution callouts substitute_case_callout use substitution case callouts @@ -1183,20 +1217,20 @@ process. These modifiers may not appear in a #pattern command. If you want them as defaults, set them in a #subject command. -

    -
    +

    +

    Specifying literal subject lines -
    -

    +

    +

    If the subject_literal modifier is present on a pattern, all the subject lines that it matches are taken as literal strings, with no interpretation of backslashes. It is not possible to set subject modifiers on such lines, but any that are set as defaults by a #subject command are recognized. -

    -
    +

    +

    Saving a compiled pattern -
    -

    +

    +

    When a pattern with the push modifier is successfully compiled, it is pushed onto a stack of compiled patterns, and pcre2test expects the next line to contain a new pattern (or a command) instead of a subject line. This @@ -1213,11 +1247,11 @@ are ignored (for the stacked copy), with a warning message, except for replace, which causes an error. Note that jitverify, which is allowed, does not carry through to any subsequent matching that uses a stacked pattern. -

    -
    +

    +

    Testing foreign pattern conversion -
    -

    +

    +

    The experimental foreign pattern conversion functions in PCRE2 can be tested by setting the convert modifier. Its argument is a colon-separated list of options, which set the equivalent option for the pcre2_pattern_convert() @@ -1237,27 +1271,27 @@ result is reflected in the output and then passed to pcre2_compile(). The normal utf and no_utf_check options, if set, cause the PCRE2_CONVERT_UTF and PCRE2_CONVERT_NO_UTF_CHECK options to be passed to pcre2_pattern_convert(). -

    -

    +

    +

    By default, the conversion function is allowed to allocate a buffer for its output. However, if the convert_length modifier is set to a value greater than zero, pcre2test passes a buffer of the given length. This makes it possible to test the length check. -

    -

    +

    +

    The convert_glob_escape and convert_glob_separator modifiers can be used to specify the escape and separator characters for glob processing, overriding the defaults, which are operating-system dependent. -

    -
    SUBJECT MODIFIERS
    -

    +

    +

    SUBJECT MODIFIERS

    +

    The modifiers that can appear in subject lines and the #subject command are of two types. -

    -
    +

    +

    Setting match options -
    -

    +

    +

    The following modifiers set options for pcre2_match() or pcre2_dfa_match(). See pcre2api @@ -1280,15 +1314,15 @@ for a description of their effects. The partial matching modifiers are provided with abbreviations because they appear frequently in tests. -

    -

    +

    +

    If the posix or posix_nosub modifier was present on the pattern, causing the POSIX wrapper API to be used, the only option-setting modifiers that have any effect are notbol, notempty, and noteol, causing REG_NOTBOL, REG_NOTEMPTY, and REG_NOTEOL, respectively, to be passed to regexec(). The other modifiers are ignored, with a warning message. -

    -

    +

    +

    There is one additional modifier that can be used with the POSIX wrapper. It is ignored (with a warning) if used for non-POSIX matching.

    @@ -1302,11 +1336,11 @@ the subject string. For more detail of REG_STARTEND, see the
     documentation. If the subject string contains binary zeros (coded as escapes
     such as \x{00} because pcre2test does not support actual binary zeros in
     its input), you must use posix_startend to specify its length.
    -

    -
    +

    +

    Setting match controls -
    -

    +

    +

    The following modifiers affect the matching process or request additional information. Some of them may also be specified on a pattern line (see above), in which case they apply to every subject line that is matched against that @@ -1342,11 +1376,12 @@ pattern, but can be overridden by modifiers on the subject. null_context match with a NULL context null_replacement substitute with NULL replacement null_subject match with NULL subject + null_substitute_match_data substitute with NULL match data offset=<n> set starting offset offset_limit=<n> set offset limit ovector=<n> set size of output vector recursion_limit=<n> obsolete synonym for depth_limit - replace=<string> specify a replacement string + replace=<str> specify a replacement string startchar show startchar when relevant startoffset=<n> same as offset=<n> substitute_callout use substitution callouts @@ -1358,6 +1393,7 @@ pattern, but can be overridden by modifiers on the subject. substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY substitute_skip=<n> skip substitution number n substitute_stop=<n> skip substitution number n and greater + substitute_subject=<str> specify a different subject for substitution substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY zero_terminate pass the subject as zero-terminated @@ -1366,11 +1402,11 @@ The effects of these modifiers are described in the following sections. When matching via the POSIX wrapper API, the aftertext, allaftertext, and ovector subject modifiers work as described below. All other modifiers are either ignored, with a warning message, or cause an error. -

    -
    +

    +

    Showing more text -
    -

    +

    +

    The aftertext modifier requests that as well as outputting the part of the subject string that matched the entire pattern, pcre2test should in addition output the remainder of the subject string. This is useful for tests @@ -1378,8 +1414,8 @@ where the subject contains multiple copies of the same substring. The allaftertext modifier requests the same action for captured substrings as well as the main matched substring. In each case the remainder is output on the following line with a plus character following the capture number. -

    -

    +

    +

    The allusedtext modifier requests that all the text that was consulted during a successful pattern match by the interpreter should be shown, for both full and partial matches. This feature is not supported for JIT matching, and @@ -1402,8 +1438,8 @@ The first, complete match shows that the matched string is "abc", with the preceding and following strings "pqr" and "xyz" having been consulted during the match (when processing the assertions). The partial match can indicate only the preceding string. -

    -

    +

    +

    The startchar modifier requests that the starting character for the match be indicated, if it is different to the start of the matched string. The only time when this occurs is when \K has been processed as part of the match. In @@ -1418,11 +1454,11 @@ under the earlier characters. For example:

    Unlike allusedtext, the startchar modifier can be used with JIT. However, these two modifiers are mutually exclusive. -

    -
    +

    +

    Showing the value of all capture groups -
    -

    +

    +

    The allcaptures modifier requests that the values of all potential captured parentheses be output after a match. By default, only those up to the highest one actually used in the match are output (corresponding to the return @@ -1430,11 +1466,11 @@ code from pcre2_match()). Groups that did not take part in the match are output as "<unset>". This modifier is not relevant for DFA matching (which does no capturing) and does not apply when replace is specified; it is ignored, with a warning message, if present. -

    -
    +

    +

    Showing the entire ovector, for all outcomes -
    -

    +

    +

    The allvector modifier requests that the entire ovector be shown, whatever the outcome of the match. Compare allcaptures, which shows only up to the maximum number of capture groups for the pattern, and then only for a @@ -1447,11 +1483,11 @@ applies to all groups after the maximum capture group for the pattern. In other cases it applies to the entire ovector. After a partial match, the first two elements are the only ones that should be set. After a DFA match, the amount of ovector that is used depends on the number of matches that were found. -

    -
    +

    +

    Testing pattern callouts -
    -

    +

    +

    A callout function is supplied when pcre2test calls the library matching functions, unless callout_none is specified. Its behaviour can be controlled by various modifiers listed above whose names begin with @@ -1460,11 +1496,11 @@ controlled by various modifiers listed above whose names begin with Testing callouts from pcre2_substitute() is described separately in "Testing the substitution function" below. -

    -
    +

    +

    Finding all matches in a string -
    -

    +

    +

    Searching for all possible matches within a subject can be requested by the global or altglobal modifier. After finding a match, the matching function is called again to search the remainder of the subject. The difference @@ -1474,21 +1510,17 @@ to start searching at a new point within the entire string (which is what Perl does), whereas the latter passes over a shortened subject. This makes a difference to the matching process if the pattern begins with a lookbehind assertion (including \b or \B). -

    -

    +

    +

    If an empty string is matched, the next match is done with the -PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set, in order to search for -another, non-empty, match at the same point in the subject. If this match -fails, the start offset is advanced, and the normal match is retried. This -imitates the way Perl handles such cases when using the /g modifier or -the split() function. Normally, the start offset is advanced by one -character, but if the newline convention recognizes CRLF as a newline, and the -current character is CR followed by LF, an advance of two characters occurs. -

    -
    +PCRE2_NOTEMPTY_ATSTART flag set, in order to search for another, non-empty, +match at the same point in the subject. This imitates the way Perl handles such +cases when using the /g modifier or the split() function. +

    +

    Testing substring extraction functions -
    -

    +

    +

    The copy and get modifiers can be used to test the pcre2_substring_copy_xxx() and pcre2_substring_get_xxx() functions. They can be given more than once, and each can specify a capture group name or @@ -1499,43 +1531,43 @@ number, for example: If the #subject command is used to set default copy and/or get lists, these can be unset by specifying a negative number to cancel all numbered groups and an empty name to cancel all named groups. -

    -

    +

    +

    The getall modifier tests pcre2_substring_list_get(), which extracts all captured substrings. -

    -

    +

    +

    If the subject line is successfully matched, the substrings extracted by the convenience functions are output with C, G, or L after the string number instead of a colon. This is in addition to the normal full list. The string length (that is, the return from the extraction function) is given in parentheses after each substring, followed by the name when the extraction was by name. -

    -
    +

    +

    Testing the substitution function -
    -

    +

    +

    If the replace modifier is set, the pcre2_substitute() function is called instead of one of the matching functions (or after one call of pcre2_match() in the case of PCRE2_SUBSTITUTE_MATCHED). Note that replacement strings cannot contain commas, because a comma signifies the end of a modifier. This is not thought to be an issue in a test program. -

    -

    +

    +

    Specifying a completely empty replacement string disables this modifier. However, it is possible to specify an empty replacement by providing a buffer length, as described below, for an otherwise empty replacement. -

    -

    +

    +

    Unlike subject strings, pcre2test does not process replacement strings for escape sequences. In UTF mode, a replacement string is checked to see if it is a valid UTF-8 string. If so, it is correctly converted to a UTF string of the appropriate code unit width. If it is not a valid UTF-8 string, the individual code units are copied directly. This provides a means of passing an invalid UTF-8 string for testing purposes. -

    -

    +

    +

    The following modifiers set options (in additional to the normal match options) for pcre2_substitute():

    @@ -1551,8 +1583,8 @@ for pcre2_substitute():
     See the
     pcre2api
     documentation for details of these options.
    -

    -

    +

    +

    After a successful substitution, the modified string is output, preceded by the number of replacements. This may be zero if there were no matches. Here is a simple example of a substitution test: @@ -1574,7 +1606,7 @@ character. Here is an example that tests the edge case: 123abc123\=replace=[10]XYZ 1: 123XYZ123 123abc123\=replace=[9]XYZ - Failed: error -47: no more memory + Failed: error -48: no more memory

    The default action of pcre2_substitute() is to return PCRE2_ERROR_NOMEMORY when the output buffer is too small. However, if the @@ -1587,16 +1619,23 @@ for the trailing zero) as part of the error message. For example:
       /abc/substitute_overflow_length
           123abc123\=replace=[9]XYZ
    -  Failed: error -47: no more memory: 10 code units are needed
    +  Failed: error -48: no more memory: 10 code units are needed
     
    A replacement string is ignored with POSIX and DFA matching. Specifying partial matching provokes an error return ("bad option value") from pcre2_substitute(). -

    -
    +
    +
    +The substitute_subject modifier may be used to test the use of the PCRE2 +API, in which a client calls pcre2_match() followed by pcre2_substitute() +with PCRE2_SUBSTITUTE_MATCHED, but the client performs an unexpected and +unsupported modification of the subject buffer in-place, in between the match +and substitution. +

    +

    Testing substitute callouts -
    -

    +

    +

    If the substitute_callout modifier is set, a substitution callout function is set up. The null_context modifier must not be set, because the address of the callout function is passed in a match context. When the @@ -1614,8 +1653,8 @@ parenthesized number is the number of pairs that are set in the ovector (that is, one more than the number of capturing groups that were set). Then are listed the offsets of the old substring, its contents, and the same for the replacement. -

    -

    +

    +

    By default, the substitution callout function returns zero, which accepts the replacement and causes matching to continue if /g was used. Two further modifiers can be used to test other return values. If substitute_skip is @@ -1635,26 +1674,26 @@ either of them are set, substitute_callout is assumed. For example: If both are set for the same number, stop takes precedence. Only a single skip or stop is supported, which is sufficient for testing that the feature works. -

    -
    +

    +

    Testing substitute case callouts -
    -

    +

    +

    If the substitute_case_callout modifier is set, a substitution case callout function is set up. The callout function is called for each substituted chunk which is to be case-transformed. -

    -

    +

    +

    The callout function passed is a fixed function with implementation for certain behaviours: inputs which shrink when case-transformed; inputs which grow; inputs with distinct upper/lower/titlecase forms. The characters which are not special-cased for testing purposes are left unmodified, as if they are caseless characters. -

    -
    +

    +

    Setting the JIT stack size -
    -

    +

    +

    The jitstack modifier provides a way of setting the maximum stack size that is used by the just-in-time optimization code. It is ignored if JIT optimization is not being used. The value is a number of kibibytes (units of @@ -1662,19 +1701,19 @@ optimization is not being used. The value is a number of kibibytes (units of that is larger than the default is necessary only for very complicated patterns. If jitstack is set non-zero on a subject line it overrides any value that was set on the pattern. -

    -
    +

    +

    Setting heap, match, and depth limits -
    -

    +

    +

    The heap_limit, match_limit, and depth_limit modifiers set the appropriate limits in the match context. These values are ignored when the find_limits or find_limits_noheap modifier is specified. -

    -
    +

    +

    Finding minimum limits -
    -

    +

    +

    If the find_limits modifier is present on a subject line, pcre2test calls the relevant matching function several times, setting different values in the match context via pcre2_set_heap_limit(), @@ -1685,22 +1724,22 @@ modifier, find_limits_noheap, omits the heap limit. This is used in the standard tests, because the minimum heap limit varies between systems. If JIT is being used, only the match limit is relevant, and the other two are automatically omitted. -

    -

    +

    +

    When using this modifier, the pattern should not contain any limit settings such as (*LIMIT_MATCH=...) within it. If such a setting is present and is lower than the minimum matching value, the minimum value cannot be found because pcre2_set_match_limit() etc. are only able to reduce the value of an in-pattern limit; they cannot increase it. -

    -

    +

    +

    For non-DFA matching, the minimum depth_limit number is a measure of how much nested backtracking happens (that is, how deeply the pattern's tree is searched). In the case of DFA matching, depth_limit controls the depth of recursive calls of the internal function that is used for handling pattern recursion, lookaround assertions, and atomic groups. -

    -

    +

    +

    For non-DFA matching, the match_limit number is a measure of the amount of backtracking that takes place, and learning the minimum value can be instructive. For most simple matches, the number is quite small, but for @@ -1709,25 +1748,25 @@ very quickly with increasing length of subject string. In the case of DFA matching, match_limit controls the total number of calls, both recursive and non-recursive, to the internal matching function, thus controlling the overall amount of computing resource that is used. -

    -

    +

    +

    For both kinds of matching, the heap_limit number, which is in kibibytes (units of 1024 bytes), limits the amount of heap memory used for matching. -

    -
    +

    +

    Showing MARK names -
    -

    +

    +

    The mark modifier causes the names from backtracking control verbs that are returned from calls to pcre2_match() to be displayed. If a mark is returned for a match, non-match, or partial match, pcre2test shows it. For a match, it is on a line by itself, tagged with "MK:". Otherwise, it is added to the non-match message. -

    -
    +

    +

    Showing memory usage -
    -

    +

    +

    The memory modifier causes pcre2test to log the sizes of all heap memory allocation and freeing calls that occur during a call to pcre2_match() or pcre2_dfa_match(). In the latter case, heap memory @@ -1736,52 +1775,52 @@ allocation on the stack, so in many cases there will be no output. No heap memory is allocated during matching with JIT. For this modifier to work, the null_context modifier must not be set on both the pattern and the subject, though it can be set on one or the other. -

    -
    +

    +

    Showing the heap frame overall vector size -
    -

    +

    +

    The heapframes_size modifier is relevant for matches using pcre2_match() without JIT. After a match has run (whether successful or not) the size, in bytes, of the allocated heap frames vector that is left attached to the match data block is shown. If the matching action involved several calls to pcre2_match() (for example, global matching or for timing) only the final value is shown. -

    -

    +

    +

    This modifier is ignored, with a warning, for POSIX or DFA matching. JIT matching does not use the heap frames vector, so the size is always zero, unless there was a previous non-JIT match. Note that specifing a size of zero for the output vector (see below) causes pcre2test to free its match data block (and associated heap frames vector) and allocate a new one. -

    -
    +

    +

    Setting a starting offset -
    -

    +

    +

    The offset modifier sets an offset in the subject string at which matching starts. Its value is a number of code units, not characters. -

    -
    +

    +

    Setting an offset limit -
    -

    +

    +

    The offset_limit modifier sets a limit for unanchored matches. If a match cannot be found starting at or before this offset in the subject, a "no match" return is given. The data value is a number of code units, not characters. When this modifier is used, the use_offset_limit modifier must have been set for the pattern; if not, an error is generated. -

    -
    +

    +

    Setting the size of the output vector -
    -

    +

    +

    The ovector modifier applies only to the subject line in which it appears, though of course it can also be used to set a default in a #subject command. It specifies the number of pairs of offsets that are available for storing matching information. The default is 15. -

    -

    +

    +

    A value of zero is useful when testing the POSIX API because it causes regexec() to be called with a NULL capture vector. When not testing the POSIX API, a value of zero is used to cause @@ -1789,25 +1828,25 @@ POSIX API, a value of zero is used to cause new match block of exactly the right size for the pattern. (It is not possible to create a match block with a zero-length ovector; there is always at least one pair of offsets.) The old match data block is freed. -

    -
    +

    +

    Passing the subject as zero-terminated -
    -

    +

    +

    By default, the subject string is passed to a native API matching function with its correct length. In order to test the facility for passing a zero-terminated string, the zero_terminate modifier is provided. It causes the length to be passed as PCRE2_ZERO_TERMINATED. When matching via the POSIX interface, this modifier is ignored, with a warning. -

    -

    +

    +

    When testing pcre2_substitute(), this modifier also has the effect of passing the replacement string as zero-terminated. -

    -
    +

    +

    Passing a NULL context, subject, or replacement -
    -

    +

    +

    Normally, pcre2test passes a context block to pcre2_match(), pcre2_dfa_match(), pcre2_jit_match() or pcre2_substitute(). If the null_context modifier is set, however, NULL is passed. This is for @@ -1815,14 +1854,14 @@ testing that the matching and substitution functions behave correctly in this case (they use default values). This modifier cannot be used with the find_limits, find_limits_noheap, or substitute_callout modifiers. -

    -

    +

    +

    Similarly, for testing purposes, if the null_subject or null_replacement modifier is set, the subject or replacement string pointers are passed as NULL, respectively, to the relevant functions. -

    -
    THE ALTERNATIVE MATCHING FUNCTION
    -

    +

    +

    THE ALTERNATIVE MATCHING FUNCTION

    +

    By default, pcre2test uses the standard PCRE2 matching function, pcre2_match() to match each subject line. PCRE2 also supports an alternative matching function, pcre2_dfa_match(), which operates in a @@ -1830,19 +1869,19 @@ different way, and has some restrictions. The differences between the two functions are described in the pcre2matching documentation. -

    -

    +

    +

    If the dfa modifier is set, the alternative matching function is used. This function finds all possible matches at a given point in the subject. If, however, the dfa_shortest modifier is set, processing stops after the first match is found. This is always the shortest possible match. -

    -
    DEFAULT OUTPUT FROM pcre2test
    -

    +

    +

    DEFAULT OUTPUT FROM pcre2test

    +

    This section describes the output when the normal matching function, pcre2_match(), is being used. -

    -

    +

    +

    When a match succeeds, pcre2test outputs the list of captured substrings, starting with number 0 for the string that matched the whole pattern. Otherwise, it outputs "No match" when the return is PCRE2_ERROR_NOMATCH, or @@ -1851,8 +1890,8 @@ return is PCRE2_ERROR_PARTIAL. (Note that this is the entire substring that was inspected during the partial match; it may include characters before the actual match start if a lookbehind assertion, \K, \b, or \B was involved.) -

    -

    +

    +

    For any other return, pcre2test outputs the PCRE2 negative error number and a short descriptive phrase. If the error is a failed UTF string check, the code unit offset of the start of the failing character is also output. Here is @@ -1913,16 +1952,16 @@ modifier is past the end of the subject string): re> /xyz/ data> xyz\=offset=4 Error -24 (bad offset value) - -

    -

    + +

    +

    Note that whereas patterns can be continued over several lines (a plain ">" prompt is used for continuations), subject lines may not. However newlines can be included in a subject by means of the \n escape (or \r, \r\n, etc., depending on the newline sequence setting). -

    -
    OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION
    -

    +

    +

    OUTPUT FROM THE ALTERNATIVE MATCHING FUNCTION

    +

    When the alternative matching function, pcre2_dfa_match(), is used, the output consists of a list of all the matches that start at the first point in the subject where there is at least one match. For example: @@ -1940,8 +1979,8 @@ partially matching substring. Note that this is the entire substring that was inspected during the partial match; it may include characters before the actual match start if a lookbehind assertion, \b, or \B was involved. (\K is not supported for DFA matching.) -

    -

    +

    +

    If global matching is requested, the search for further matches resumes at the end of the longest match. For example:

    @@ -1956,9 +1995,9 @@ at the end of the longest match. For example:
     
    The alternative matching function does not support substring capture, so the modifiers that are concerned with captured substrings are not relevant. -

    -
    RESTARTING AFTER A PARTIAL MATCH
    -

    +

    +

    RESTARTING AFTER A PARTIAL MATCH

    +

    When the alternative matching function has given the PCRE2_ERROR_PARTIAL return, indicating that the subject partially matched the pattern, you can restart the match with additional subject data by means of the @@ -1973,19 +2012,19 @@ restart the match with additional subject data by means of the For further information about partial matching, see the pcre2partial documentation. -

    -
    CALLOUTS
    -

    +

    +

    CALLOUTS

    +

    If the pattern contains any callout requests, pcre2test's callout function is called during matching unless callout_none is specified. This works with both matching functions, and with JIT, though there are some differences in behaviour. The output for callouts with numerical arguments and those with string arguments is slightly different. -

    -
    +

    +

    Callouts with numerical arguments -
    -

    +

    +

    By default, the callout function displays the callout number, the start and current positions in the subject text at the callout time, and the next pattern item to be tested. For example: @@ -1999,8 +2038,8 @@ the seventh character, and when the next pattern item was \d. Just one circumflex is output if the start and current positions are the same, or if the current position precedes the start position, which can happen if the callout is in a lookbehind assertion. -

    -

    +

    +

    Callouts numbered 255 are assumed to be automatic callouts, inserted as a result of the auto_callout pattern modifier. In this case, instead of showing the callout number, the offset in the pattern, preceded by a plus, is @@ -2032,11 +2071,11 @@ a change of latest mark is passed to the callout function. For example: The mark changes between matching "a" and "b", but stays the same for the rest of the match, so nothing more is output. If, as a result of backtracking, the mark reverts to being unset, the text "<unset>" is output. -

    -
    +

    +

    Callouts with string arguments -
    -

    +

    +

    The output for a callout with a string argument is similar, except that instead of outputting a callout number before the position indicators, the callout string and its offset in the pattern string are output before the reflection of @@ -2053,27 +2092,27 @@ example: ^ ^ e 0: abcdef - -

    -
    + +

    +

    Callout modifiers -
    -

    +

    +

    The callout function in pcre2test returns zero (carry on matching) by default, but you can use a callout_fail modifier in a subject line to change this and other parameters of the callout (see below). -

    -

    +

    +

    If the callout_capture modifier is set, the current captured groups are output when a callout occurs. This is useful only for non-DFA matching, as pcre2_dfa_match() does not support capturing, so no captures are ever shown. -

    -

    +

    +

    The normal callout output, showing the callout number or pattern offset (as described above) is suppressed if the callout_no_where modifier is set. -

    -

    +

    +

    When using the interpretive matching function pcre2_match() without JIT, setting the callout_extra modifier causes additional output from pcre2test's callout function to be generated. For the first callout in a @@ -2123,15 +2162,15 @@ an immediate "no match", without any callouts, because the starting optimization fails to find "b" in the subject, which it knows must be present for any match. If no_auto_possess is not used, the "a+" item is turned into "a++", which reduces the number of backtracks. -

    -

    +

    +

    The callout_extra modifier has no effect if used with the DFA matching function, or with JIT. -

    -
    +

    +

    Return values from callouts -
    -

    +

    +

    The default return from the callout function is zero, which allows matching to continue. The callout_fail modifier can be given one or two numbers. If there is only one number, 1 is returned instead of 0 (causing matching to @@ -2142,35 +2181,35 @@ PCRE2_ERROR_CALLOUT is returned, causing the entire matching process to be aborted. If both these modifiers are set for the same callout number, callout_error takes precedence. Note that callouts with string arguments are always given the number zero. -

    -

    +

    +

    The callout_data modifier can be given an unsigned or a negative number. This is set as the "user data" that is passed to the matching function, and passed back when the callout function is invoked. Any value other than zero is used as a return from pcre2test's callout function. -

    -

    +

    +

    Inserting callouts can be helpful when using pcre2test to check complicated regular expressions. For further information about callouts, see the pcre2callout documentation. -

    -
    NON-PRINTING CHARACTERS
    -

    +

    +

    NON-PRINTING CHARACTERS

    +

    When pcre2test is outputting text in the compiled version of a pattern, bytes other than 32-126 are always treated as non-printing characters and are therefore shown as hex escapes. -

    -

    +

    +

    When pcre2test is outputting text that is a matched part of a subject string, it behaves in the same way, unless a different locale has been set for the pattern (using the locale modifier). In this case, the isprint() function is used to distinguish printing and non-printing characters. -

    -
    SAVING AND RESTORING COMPILED PATTERNS
    -

    +

    +

    SAVING AND RESTORING COMPILED PATTERNS

    +

    It is possible to save compiled patterns on disc or elsewhere, and reload them later, subject to a number of restrictions. JIT data cannot be saved. The host on which the patterns are reloaded must be running the same version of PCRE2, @@ -2180,20 +2219,20 @@ serialized, that is, converted to a stream of bytes. A single byte stream may contain any number of compiled patterns, but they must all use the same character tables. A single copy of the tables is included in the byte stream (its size is 1088 bytes). -

    -

    +

    +

    The functions whose names begin with pcre2_serialize_ are used for serializing and de-serializing. They are described in the pcre2serialize documentation. In this section we describe the features of pcre2test that can be used to test these functions. -

    -

    +

    +

    Note that "serialization" in PCRE2 does not convert compiled patterns to an abstract format like Java or .NET. It just makes a reloadable byte code stream. Hence the restrictions on reloading mentioned above. -

    -

    +

    +

    In pcre2test, when a pattern with push modifier is successfully compiled, it is pushed onto a stack of compiled patterns, and pcre2test expects the next line to contain a new pattern (or command) instead of a @@ -2204,8 +2243,8 @@ be compiled and retained. These modifiers are incompatible with posix, and control modifiers that act at match time are ignored (with a message) for the stacked patterns. The jitverify modifier applies only at compile time. -

    -

    +

    +

    The command

       #save <filename>
    @@ -2241,30 +2280,30 @@ reloads two patterns.
     
    If jitverify is used with #pop, it does not automatically imply jit, which is different behaviour from when it is used on a pattern. -

    -

    +

    +

    The #popcopy command is analogous to the pushcopy modifier in that it makes current a copy of the topmost stack pattern, leaving the original still on the stack. -

    -
    SEE ALSO
    -

    +

    +

    SEE ALSO

    +

    pcre2(3), pcre2api(3), pcre2callout(3), pcre2jit, pcre2matching(3), pcre2partial(d), pcre2pattern(3), pcre2serialize(3). -

    -
    AUTHOR
    -

    +

    +

    AUTHOR

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    REVISION
    -

    -Last updated: 26 December 2024 +

    +

    REVISION

    +

    +Last updated: 12 October 2025
    Copyright © 1997-2024 University of Cambridge.
    diff --git a/doc/html/pcre2unicode.html b/doc/html/pcre2unicode.html index 5b42532..8c278ae 100644 --- a/doc/html/pcre2unicode.html +++ b/doc/html/pcre2unicode.html @@ -12,18 +12,18 @@ This page is part of the PCRE2 HTML documentation. It was generated automatically from the original man page. If there is any nonsense in it, please consult the man page, in case the conversion went wrong.
    -
    +

    UNICODE AND UTF SUPPORT -
    -

    +

    +

    PCRE2 is normally built with Unicode support, though if you do not need it, you can build it without, in which case the library will be smaller. With Unicode support, PCRE2 has knowledge of Unicode character properties and can process strings of text in UTF-8, UTF-16, and UTF-32 format (depending on the code unit width), but this is not the default. Unless specifically requested, PCRE2 treats each code unit in a string as one character. -

    -

    +

    +

    There are two ways of telling PCRE2 to switch to UTF mode, where characters may consist of more than one code unit and the range of values is constrained. The program can call @@ -32,22 +32,22 @@ with the PCRE2_UTF option, or the pattern may start with the sequence (*UTF). However, the latter facility can be locked out by the PCRE2_NEVER_UTF option. That is, the programmer can prevent the supplier of the pattern from switching to UTF mode. -

    -

    +

    +

    Note that the PCRE2_MATCH_INVALID_UTF option (see below) forces PCRE2_UTF to be set. -

    -

    +

    +

    In UTF mode, both the pattern and any subject strings that are matched against it are treated as UTF strings instead of strings of individual one-code-unit characters. There are also some other changes to the way characters are handled, as documented below. -

    -
    +

    +

    UNICODE PROPERTY SUPPORT -
    -

    +

    +

    When PCRE2 is built with Unicode support, the escape sequences \p{..}, \P{..}, and \X can be used. This is not dependent on the PCRE2_UTF setting. The Unicode properties that can be tested are a subset of those that Perl @@ -55,8 +55,8 @@ supports. Currently they are limited to the general category properties such as Lu for an upper case letter or Nd for a decimal number, the derived properties Any and Lc (synonym L&), the Unicode script names such as Arabic or Han, Bidi_Class, Bidi_Control, and a few binary properties. -

    -

    +

    +

    The full lists are given in the pcre2pattern and @@ -65,34 +65,34 @@ documentation. In general, only the short names for properties are supported. For example, \p{L} matches a letter. Its longer synonym, \p{Letter}, is not supported. Furthermore, in Perl, many properties may optionally be prefixed by "Is", for compatibility with Perl 5.6. PCRE2 does not support this. -

    -
    +

    +

    WIDE CHARACTERS AND UTF MODES -
    -

    +

    +

    Code points less than 256 can be specified in patterns by either braced or unbraced hexadecimal escape sequences (for example, \x{b3} or \xb3). Larger values have to use braced sequences. Unbraced octal code points up to \777 are also recognized; larger ones can be coded using \o{...}. -

    -

    +

    +

    The escape sequence \N{U+<hex digits>} is recognized as another way of specifying a Unicode character by code point in a UTF mode. It is not allowed in non-UTF mode. -

    -

    +

    +

    In UTF mode, repeat quantifiers apply to complete UTF characters, not to individual code units. -

    -

    +

    +

    In UTF mode, the dot metacharacter matches one UTF character instead of a single code unit. -

    -

    +

    +

    In UTF mode, capture group names are not restricted to ASCII, and may contain any Unicode letters and decimal digits, as well as underscore. -

    -

    +

    +

    The escape sequence \C can be used to match a single code unit in UTF mode, but its use can lead to some strange effects because it breaks up multi-unit characters (see the description of \C in the @@ -100,8 +100,8 @@ characters (see the description of \C in the documentation). For this reason, there is a build-time option that disables support for \C completely. There is also a less draconian compile-time option for locking out the use of \C when a pattern is compiled. -

    -

    +

    +

    The use of \C is not supported by the alternative matching function pcre2_dfa_match() when in UTF-8 or UTF-16 mode, that is, when a character may consist of more than one code unit. The use of \C in these modes provokes @@ -109,8 +109,8 @@ a match-time error. Also, the JIT optimization does not support \C in these modes. If JIT optimization is requested for a UTF-8 or UTF-16 pattern that contains \C, it will not succeed, and so when pcre2_match() is called, the matching will be carried out by the interpretive function. -

    -

    +

    +

    The character escapes \b, \B, \d, \D, \s, \S, \w, and \W correctly test characters of any code value, but, by default, the characters that PCRE2 recognizes as digits, spaces, or word characters remain the same set as in @@ -127,21 +127,21 @@ that suppress this for individual escapes. For details see the section on in the pcre2pattern documentation. -

    -

    +

    +

    Like the escapes, characters that match the POSIX named character classes are all low-valued characters unless the PCRE2_UCP option is set, but there is an option to override this. -

    -

    +

    +

    In contrast to the character escapes and character classes, the special horizontal and vertical white space escapes (\h, \H, \v, and \V) do match all the appropriate Unicode characters, whether or not PCRE2_UCP is set. -

    -
    +

    +

    UNICODE CASE-EQUIVALENCE -
    -

    +

    +

    If either PCRE2_UTF or PCRE2_UCP is set, upper/lower case processing makes use of Unicode properties except for characters whose code points are less than 128 and that have at most two case-equivalent values. For these, a direct table @@ -149,8 +149,8 @@ lookup is used for speed. A few Unicode characters such as Greek sigma have more than two code points that are case-equivalent, and these are treated specially. Setting PCRE2_UCP without PCRE2_UTF allows Unicode-style case processing for non-UTF character encodings such as UCS-2. -

    -

    +

    +

    There are two ASCII characters (S and K) that, in addition to their ASCII lower case equivalents, have a non-ASCII one as well (long S and Kelvin sign). Recognition of these non-ASCII characters as case-equivalent to their ASCII @@ -166,9 +166,9 @@ ASCII or non-ASCII; there can be no mixing. U+212A (Kelvin sign) only case-equivalent to itself 's' = 'S' U+017F (long S) only case-equivalent to itself - -

    -

    + +

    +

    One language family, Turkish and Azeri, has its own case-insensitivity rules, which can be selected by setting PCRE2_EXTRA_TURKISH_CASING. This alters the behaviour of the 'i', 'I', U+0130 (capital I with dot above), and U+0131 @@ -181,50 +181,50 @@ behaviour of the 'i', 'I', U+0130 (capital I with dot above), and U+0131 With PCRE2_EXTRA_TURKISH_CASING: 'i' = U+0130 (capital I with dot above) U+0131 (small dotless i) = 'I' - -

    -

    + +

    +

    It is not allowed to specify both PCRE2_EXTRA_CASELESS_RESTRICT and PCRE2_EXTRA_TURKISH_CASING together. -

    -

    +

    +

    From release 10.45 the Unicode letter properties Lu (upper case), Ll (lower case), and Lt (title case) are all treated as Lc (cased letter) when caseless matching is set by the PCRE2_CASELESS option or (?i) within the pattern. -

    -
    +

    +

    SCRIPT RUNS -
    -

    +

    +

    The pattern constructs (*script_run:...) and (*atomic_script_run:...), with synonyms (*sr:...) and (*asr:...), verify that the string matched within the parentheses is a script run. In concept, a script run is a sequence of characters that are all from the same Unicode script. However, because some scripts are commonly used together, and because some diacritical and other marks are used with multiple scripts, it is not that simple. -

    -

    +

    +

    Every Unicode character has a Script property, mostly with a value corresponding to the name of a script, such as Latin, Greek, or Cyrillic. There are also three special values: -

    -

    +

    +

    "Unknown" is used for code points that have not been assigned, and also for the surrogate code points. In the PCRE2 32-bit library, characters whose code points are greater than the Unicode maximum (U+10FFFF), which are accessible only in non-UTF mode, are assigned the Unknown script. -

    -

    +

    +

    "Common" is used for characters that are used with many scripts. These include punctuation, emoji, mathematical, musical, and currency symbols, and the ASCII digits 0 to 9. -

    -

    +

    +

    "Inherited" is used for characters such as diacritical marks that modify a previous character. These are considered to take on the script of the character that they modify. -

    -

    +

    +

    Some Inherited characters are used with many scripts, but many of them are only normally used with a small number of scripts. For example, U+102E0 (Coptic Epact thousands mark) is used only with Arabic and Coptic. In order to make it @@ -234,37 +234,37 @@ characters, the list contains just one script, the same one as the Script property. However, for characters such as U+102E0 more than one Script is listed. There are also some Common characters that have a single, non-Common script in their Script Extension list. -

    -

    +

    +

    The next section describes the basic rules for deciding whether a given string of characters is a script run. Note, however, that there are some special cases involving the Chinese Han script, and an additional constraint for decimal digits. These are covered in subsequent sections. -

    -
    +

    +

    Basic script run rules -
    -

    +

    +

    A string that is less than two characters long is a script run. This is the only case in which an Unknown character can be part of a script run. Longer strings are checked using only the Script Extensions property, not the basic Script property. -

    -

    +

    +

    If a character's Script Extension property is the single value "Inherited", it is always accepted as part of a script run. This is also true for the property "Common", subject to the checking of decimal digits described below. All the remaining characters in a script run must have at least one script in common in their Script Extension lists. In set-theoretic terminology, the intersection of all the sets of scripts must not be empty. -

    -

    +

    +

    A simple example is an Internet name such as "google.com". The letters are all in the Latin script, and the dot is Common, so this string is a script run. However, the Cyrillic letter "o" looks exactly the same as the Latin "o"; a string that looks the same, but with Cyrillic "o"s is not a script run. -

    -

    +

    +

    More interesting examples involve characters with more than one script in their Script Extension. Consider the following characters:

    @@ -275,11 +275,11 @@ The first has the Script Extension list Arabic, Hanifi Rohingya, Syriac, and
     Thaana; the second has just Arabic and Hanifi Rohingya. Both of them could
     appear in script runs of either Arabic or Hanifi Rohingya. The first could also
     appear in Syriac or Thaana script runs, but the second could not.
    -

    -
    +

    +

    The Chinese Han script -
    -

    +

    +

    The Chinese Han script is commonly used in conjunction with other scripts for writing certain languages. Japanese uses the Hiragana and Katakana scripts together with Han; Korean uses Hangul and Han; Taiwanese Mandarin uses Bopomofo @@ -290,57 +290,57 @@ Han, or a mixture of Bopomofo and Han, but not, for example, a mixture of Hangul and Bopomofo and Han. PCRE2 (like Perl) follows Unicode's Technical Standard 39 ("Unicode Security Mechanisms", http://unicode.org/reports/tr39/) in allowing such mixtures. -

    -
    +

    +

    Decimal digits -
    -

    +

    +

    Unicode contains many sets of 10 decimal digits in different scripts, and some scripts (including the Common script) contain more than one set. Some of these decimal digits them are visually indistinguishable from the common ASCII digits. In addition to the script checking described above, if a script run contains any decimal digits, they must all come from the same set of 10 adjacent characters. -

    -
    +

    +

    VALIDITY OF UTF STRINGS -
    -

    +

    +

    When the PCRE2_UTF option is set, the strings passed as patterns and subjects are (by default) checked for validity on entry to the relevant functions. If an invalid UTF string is passed, a negative error code is returned. The code unit offset to the offending character can be extracted from the match data block by calling pcre2_get_startchar(), which is used for this purpose after a UTF error. -

    -

    +

    +

    In some situations, you may already know that your strings are valid, and therefore want to skip these checks in order to improve performance, for example in the case of a long subject string that is being scanned repeatedly. If you set the PCRE2_NO_UTF_CHECK option at compile time or at match time, PCRE2 assumes that the pattern or subject it is given (respectively) contains only valid UTF code unit sequences. -

    -

    +

    +

    If you pass an invalid UTF string when PCRE2_NO_UTF_CHECK is set, the result is undefined and your program may crash or loop indefinitely or give incorrect results. There is, however, one mode of matching that can handle invalid UTF subject strings. This is enabled by passing PCRE2_MATCH_INVALID_UTF to pcre2_compile() and is discussed below in the next section. The rest of this section covers the case when PCRE2_MATCH_INVALID_UTF is not set. -

    -

    +

    +

    Passing PCRE2_NO_UTF_CHECK to pcre2_compile() just disables the UTF check for the pattern; it does not also apply to subject strings. If you want to disable the check for a subject string you must pass this same option to pcre2_match() or pcre2_dfa_match(). -

    -

    +

    +

    UTF-16 and UTF-32 strings can indicate their endianness by special code knows as a byte-order mark (BOM). The PCRE2 functions do not handle this, expecting strings to be in host byte order. -

    -

    +

    +

    Unless PCRE2_NO_UTF_CHECK is set, a UTF string is checked before any other processing takes place. In the case of pcre2_match() and pcre2_dfa_match() calls with a non-zero starting offset, the check is @@ -352,33 +352,33 @@ Otherwise, it starts at the length of the longest lookbehind before the starting offset, or at the start of the subject if there are not that many characters before the starting offset. Note that the sequences \b and \B are one-character lookbehinds. -

    -

    +

    +

    In addition to checking the format of the string, there is a check to ensure that all code points lie in the range U+0 to U+10FFFF, excluding the surrogate area. The so-called "non-character" code points are not excluded because Unicode corrigendum #9 makes it clear that they should not be. -

    -

    +

    +

    Characters in the "Surrogate Area" of Unicode are reserved for use by UTF-16, where they are used in pairs to encode code points with values greater than 0xFFFF. The code points that are encoded by UTF-16 pairs are available independently in the UTF-8 and UTF-32 encodings. (In other words, the whole surrogate thing is a fudge for UTF-16 which unfortunately messes up UTF-8 and UTF-32.) -

    -

    +

    +

    Setting PCRE2_NO_UTF_CHECK at compile time does not disable the error that is given if an escape sequence for an invalid Unicode code point is encountered in the pattern. If you want to allow escape sequences such as \x{d800} (a surrogate code point) you can set the PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES extra option. However, this is possible only in UTF-8 and UTF-32 modes, because these values are not representable in UTF-16. -

    -
    +

    +

    Errors in UTF-8 strings -
    -

    +

    +

    The following negative error codes are given for invalid UTF-8 strings:

       PCRE2_ERROR_UTF8_ERR1
    @@ -442,111 +442,111 @@ character.
     
    The first byte of a character has the value 0xfe or 0xff. These values can never occur in a valid UTF-8 string. -

    -
    +

    +

    Errors in UTF-16 strings -
    -

    +

    +

    The following negative error codes are given for invalid UTF-16 strings:

       PCRE2_ERROR_UTF16_ERR1  Missing low surrogate at end of string
       PCRE2_ERROR_UTF16_ERR2  Invalid low surrogate follows high surrogate
       PCRE2_ERROR_UTF16_ERR3  Isolated low surrogate
     
    -
    -

    -
    +
    +

    +

    Errors in UTF-32 strings -
    -

    +

    +

    The following negative error codes are given for invalid UTF-32 strings:

       PCRE2_ERROR_UTF32_ERR1  Surrogate character (0xd800 to 0xdfff)
       PCRE2_ERROR_UTF32_ERR2  Code point is greater than 0x10ffff
     
    -
    -

    -
    + +

    +

    MATCHING IN INVALID UTF STRINGS -
    -

    +

    +

    You can run pattern matches on subject strings that may contain invalid UTF sequences if you call pcre2_compile() with the PCRE2_MATCH_INVALID_UTF option. This is supported by pcre2_match(), including JIT matching, but not by pcre2_dfa_match(). When PCRE2_MATCH_INVALID_UTF is set, it forces PCRE2_UTF to be set as well. Note, however, that the pattern itself must be a valid UTF string. -

    -

    +

    +

    If you do not set PCRE2_MATCH_INVALID_UTF when calling pcre2_compile, and you are not certain that your subject strings are valid UTF sequences, you should not make use of the JIT "fast path" function pcre2_jit_match() because it bypasses sanity checks, including the one for UTF validity. An invalid string may cause undefined behaviour, including looping, crashing, or giving the wrong answer. -

    -

    +

    +

    Setting PCRE2_MATCH_INVALID_UTF does not affect what pcre2_compile() generates, but if pcre2_jit_compile() is subsequently called, it does generate different code. If JIT is not used, the option affects the behaviour of the interpretive code in pcre2_match(). When PCRE2_MATCH_INVALID_UTF is set at compile time, PCRE2_NO_UTF_CHECK is ignored at match time. -

    -

    +

    +

    In this mode, an invalid code unit sequence in the subject never matches any pattern item. It does not match dot, it does not match \p{Any}, it does not even match negative items such as [^X]. A lookbehind assertion fails if it encounters an invalid sequence while moving the current point backwards. In other words, an invalid UTF code unit sequence acts as a barrier which no match can cross. -

    -

    +

    +

    You can also think of this as the subject being split up into fragments of valid UTF, delimited internally by invalid code unit sequences. The pattern is matched fragment by fragment. The result of a successful match, however, is given as code unit offsets in the entire subject string in the usual way. There are a few points to consider: -

    -

    +

    +

    The internal boundaries are not interpreted as the beginnings or ends of lines and so do not match circumflex or dollar characters in the pattern. -

    -

    +

    +

    If pcre2_match() is called with an offset that points to an invalid UTF-sequence, that sequence is skipped, and the match starts at the next valid UTF character, or the end of the subject. -

    -

    +

    +

    At internal fragment boundaries, \b and \B behave in the same way as at the beginning and end of the subject. For example, a sequence such as \bWORD\b would match an instance of WORD that is surrounded by invalid UTF code units. -

    -

    +

    +

    Using PCRE2_MATCH_INVALID_UTF, an application can run matches on arbitrary data, knowing that any matched strings that are returned are valid UTF. This can be useful when searching for UTF text in executable or other binary files. -

    -

    +

    +

    Note, however, that the 16-bit and 32-bit PCRE2 libraries process strings as sequences of uint16_t or uint32_t code points. They cannot find valid UTF sequences within an arbitrary string of bytes unless such sequences are suitably aligned. -

    -
    +

    +

    AUTHOR -
    -

    +

    +

    Philip Hazel
    Retired from University Computing Service
    Cambridge, England.
    -

    -
    +

    +

    REVISION -
    -

    +

    +

    Last updated: 27 November 2024
    Copyright © 1997-2024 University of Cambridge. diff --git a/doc/pcre2-config.1 b/doc/pcre2-config.1 index 3b7a8c2..c119a11 100644 --- a/doc/pcre2-config.1 +++ b/doc/pcre2-config.1 @@ -1,4 +1,4 @@ -.TH PCRE2-CONFIG 1 "28 September 2014" "PCRE2 10.46" +.TH PCRE2-CONFIG 1 "22 February 2025" "PCRE2 10.47" .SH NAME pcre2-config - program to return PCRE2 configuration .SH SYNOPSIS @@ -16,22 +16,23 @@ pcre2-config - program to return PCRE2 configuration .sp \fBpcre2-config\fP returns the configuration of the installed PCRE2 libraries and the options required to compile a program to use them. Some of the options -apply only to the 8-bit, or 16-bit, or 32-bit libraries, respectively, and are -not available for libraries that have not been built. If an unavailable option -is encountered, the "usage" information is output. +apply only to the 8-bit, 16-bit, or 32-bit libraries, respectively, and are not +available for libraries that have not been built. If an unavailable option is +encountered, the "usage" information is output. . . .SH OPTIONS .rs .TP 10 \fB--prefix\fP -Writes the directory prefix used in the PCRE2 installation for architecture -independent files (\fI/usr\fP on many systems, \fI/usr/local\fP on some -systems) to the standard output. +Writes the directory prefix used in the PCRE2 installation for +architecture-independent files (\fI/usr\fP on many systems, \fI/usr/local\fP on +some systems) to the standard output. .TP 10 \fB--exec-prefix\fP -Writes the directory prefix used in the PCRE2 installation for architecture -dependent files (normally the same as \fB--prefix\fP) to the standard output. +Writes the directory prefix used in the PCRE2 installation for +architecture-dependent files (normally the same as \fB--prefix\fP) to the +standard output. .TP 10 \fB--version\fP Writes the version number of the installed PCRE2 libraries to the standard @@ -82,5 +83,5 @@ system. It has been subsequently revised as a generic PCRE2 man page. .rs .sp .nf -Last updated: 28 September 2014 +Last updated: 22 February 2025 .fi diff --git a/doc/pcre2-config.txt b/doc/pcre2-config.txt index 9c70b40..74592eb 100644 --- a/doc/pcre2-config.txt +++ b/doc/pcre2-config.txt @@ -16,51 +16,51 @@ DESCRIPTION pcre2-config returns the configuration of the installed PCRE2 libraries and the options required to compile a program to use them. Some of the - options apply only to the 8-bit, or 16-bit, or 32-bit libraries, re- - spectively, and are not available for libraries that have not been - built. If an unavailable option is encountered, the "usage" information - is output. + options apply only to the 8-bit, 16-bit, or 32-bit libraries, respec- + tively, and are not available for libraries that have not been built. + If an unavailable option is encountered, the "usage" information is + output. OPTIONS - --prefix Writes the directory prefix used in the PCRE2 installation - for architecture independent files (/usr on many systems, + --prefix Writes the directory prefix used in the PCRE2 installation + for architecture-independent files (/usr on many systems, /usr/local on some systems) to the standard output. --exec-prefix - Writes the directory prefix used in the PCRE2 installation - for architecture dependent files (normally the same as --pre- + Writes the directory prefix used in the PCRE2 installation + for architecture-dependent files (normally the same as --pre- fix) to the standard output. --version Writes the version number of the installed PCRE2 libraries to the standard output. - --libs8 Writes to the standard output the command line options re- - quired to link with the 8-bit PCRE2 library (-lpcre2-8 on + --libs8 Writes to the standard output the command line options re- + quired to link with the 8-bit PCRE2 library (-lpcre2-8 on many systems). - --libs16 Writes to the standard output the command line options re- - quired to link with the 16-bit PCRE2 library (-lpcre2-16 on + --libs16 Writes to the standard output the command line options re- + quired to link with the 16-bit PCRE2 library (-lpcre2-16 on many systems). - --libs32 Writes to the standard output the command line options re- - quired to link with the 32-bit PCRE2 library (-lpcre2-32 on + --libs32 Writes to the standard output the command line options re- + quired to link with the 32-bit PCRE2 library (-lpcre2-32 on many systems). --libs-posix - Writes to the standard output the command line options re- + Writes to the standard output the command line options re- quired to link with PCRE2's POSIX API wrapper library (-lpcre2-posix -lpcre2-8 on many systems). - --cflags Writes to the standard output the command line options re- + --cflags Writes to the standard output the command line options re- quired to compile files that use PCRE2 (this may include some -I options, but is blank on many systems). --cflags-posix - Writes to the standard output the command line options re- - quired to compile files that use PCRE2's POSIX API wrapper - library (this may include some -I options, but is blank on + Writes to the standard output the command line options re- + quired to compile files that use PCRE2's POSIX API wrapper + library (this may include some -I options, but is blank on many systems). @@ -71,14 +71,14 @@ SEE ALSO AUTHOR - This manual page was originally written by Mark Baker for the Debian - GNU/Linux system. It has been subsequently revised as a generic PCRE2 + This manual page was originally written by Mark Baker for the Debian + GNU/Linux system. It has been subsequently revised as a generic PCRE2 man page. REVISION - Last updated: 28 September 2014 + Last updated: 22 February 2025 -PCRE2 10.46 28 September 2014 PCRE2-CONFIG(1) +PCRE2 10.47 22 February 2025 PCRE2-CONFIG(1) diff --git a/doc/pcre2.3 b/doc/pcre2.3 index 32c7c9c..1c3d9d2 100644 --- a/doc/pcre2.3 +++ b/doc/pcre2.3 @@ -1,4 +1,4 @@ -.TH PCRE2 3 "18 December 2024" "PCRE2 10.46" +.TH PCRE2 3 "22 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH INTRODUCTION @@ -16,14 +16,14 @@ obsolete and is no longer maintained. .P As well as Perl-style regular expression patterns, some features that appeared in Python and the original PCRE before they appeared in Perl are available -using the Python syntax. There is also some support for one or two .NET and -Oniguruma syntax items, and there are options for requesting some minor changes -that give better ECMAScript (aka JavaScript) compatibility. +using the Python syntax. There is also support for some .NET and Oniguruma +syntax items, and there are options for requesting minor changes that give +better ECMAScript (JavaScript) compatibility. .P The source code for PCRE2 can be compiled to support strings of 8-bit, 16-bit, or 32-bit code units, which means that up to three separate libraries may be -installed, one for each code unit size. The size of code unit is not related to -the bit size of the underlying hardware. In a 64-bit environment that also +installed, one for each code unit size. The size of a code unit is not related +to the bit size of the underlying hardware. In a 64-bit environment that also supports 32-bit applications, versions of PCRE2 that are compiled in both 64-bit and 32-bit modes may be needed. .P @@ -87,7 +87,7 @@ found in the and .\" HTML .\" -\fBNON-AUTOTOOLS_BUILD\fP +\fBNON-AUTOTOOLS-BUILD\fP .\" files in the source distribution. .P @@ -206,6 +206,6 @@ https://github.com/PCRE2Project/pcre2 .rs .sp .nf -Last updated: 18 December 2024 +Last updated: 22 February 2025 Copyright (c) 1997-2021 University of Cambridge. .fi diff --git a/doc/pcre2.txt b/doc/pcre2.txt index 9903edd..b0b564c 100644 --- a/doc/pcre2.txt +++ b/doc/pcre2.txt @@ -30,17 +30,17 @@ INTRODUCTION As well as Perl-style regular expression patterns, some features that appeared in Python and the original PCRE before they appeared in Perl - are available using the Python syntax. There is also some support for - one or two .NET and Oniguruma syntax items, and there are options for - requesting some minor changes that give better ECMAScript (aka - JavaScript) compatibility. + are available using the Python syntax. There is also support for some + .NET and Oniguruma syntax items, and there are options for requesting + minor changes that give better ECMAScript (JavaScript) compatibility. - The source code for PCRE2 can be compiled to support strings of 8-bit, + The source code for PCRE2 can be compiled to support strings of 8-bit, 16-bit, or 32-bit code units, which means that up to three separate li- - braries may be installed, one for each code unit size. The size of code - unit is not related to the bit size of the underlying hardware. In a - 64-bit environment that also supports 32-bit applications, versions of - PCRE2 that are compiled in both 64-bit and 32-bit modes may be needed. + braries may be installed, one for each code unit size. The size of a + code unit is not related to the bit size of the underlying hardware. In + a 64-bit environment that also supports 32-bit applications, versions + of PCRE2 that are compiled in both 64-bit and 32-bit modes may be + needed. The original work to extend PCRE to 16-bit and 32-bit code units was done by Zoltan Herczeg and Christian Persch, respectively. In all three @@ -76,7 +76,7 @@ INTRODUCTION client to discover which features are available. The features them- selves are described in the pcre2build page. Documentation about build- ing PCRE2 for various operating systems can be found in the README and - NON-AUTOTOOLS_BUILD files in the source distribution. + NON-AUTOTOOLS-BUILD files in the source distribution. The libraries contains a number of undocumented internal functions and data tables that are used by more than one of the exported external @@ -185,11 +185,11 @@ AUTHORS REVISION - Last updated: 18 December 2024 + Last updated: 22 February 2025 Copyright (c) 1997-2021 University of Cambridge. -PCRE2 10.46 18 December 2024 PCRE2(3) +PCRE2 10.47 22 February 2025 PCRE2(3) ------------------------------------------------------------------------------ @@ -381,7 +381,7 @@ PCRE2 NATIVE API STRING SUBSTITUTION FUNCTION int pcre2_substitute(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, pcre2_match_data *match_data, - pcre2_match_context *mcontext, PCRE2_SPTR replacementz, + pcre2_match_context *mcontext, PCRE2_SPTR replacement, PCRE2_SIZE rlength, PCRE2_UCHAR *outputbuffer, PCRE2_SIZE *outlengthptr); @@ -638,7 +638,7 @@ PCRE2 API OVERVIEW Finally, there are functions for finding out information about a com- piled pattern (pcre2_pattern_info()) and about the configuration with - which PCRE2 was built (pcre2_config()). + which PCRE2 was built (pcre2_config()) and that it is using. Functions with names ending with _free() are used for freeing memory blocks of various sorts. In all cases, if one of these functions is @@ -1337,61 +1337,69 @@ CHECKING BUILD-TIME OPTIONS recursions, lookarounds, and atomic groups in pcre2_dfa_match(). Fur- ther details are given with pcre2_set_depth_limit() above. + PCRE2_CONFIG_EFFECTIVE_LINKSIZE + + The output is a uint32_t integer that contains the number of bytes the + library uses for internal linkage in compiled regular expressions. Its + value is derived from the value that was provided at build time and + that is described below by PCRE2_CONFIG_LINKSIZE. + PCRE2_CONFIG_HEAPLIMIT - The output is a uint32_t integer that gives, in kibibytes, the default - limit for the amount of heap memory used by pcre2_match() or - pcre2_dfa_match(). Further details are given with + The output is a uint32_t integer that gives, in kibibytes, the default + limit for the amount of heap memory used by pcre2_match() or + pcre2_dfa_match(). Further details are given with pcre2_set_heap_limit() above. PCRE2_CONFIG_JIT - The output is a uint32_t integer that is set to one if support for - just-in-time compiling is included in the library; otherwise it is set + The output is a uint32_t integer that is set to one if support for + just-in-time compiling is included in the library; otherwise it is set to zero. Note that having the support in the library does not guarantee - that JIT will be used for any given match, and neither does it guaran- - tee that JIT will actually be able to function, because it may not be - able to allocate executable memory in some environments. There is a + that JIT will be used for any given match, and neither does it guaran- + tee that JIT will actually be able to function, because it may not be + able to allocate executable memory in some environments. There is a special call to pcre2_jit_compile() that can be used to check this. See the pcre2jit documentation for more details. PCRE2_CONFIG_JITTARGET - The where argument should point to a buffer that is at least 48 code - units long. (The exact length required can be found by calling - pcre2_config() with where set to NULL.) The buffer is filled with a - string that contains the name of the architecture for which the JIT - compiler is configured, for example "x86 32bit (little endian + un- - aligned)". If JIT support is not available, PCRE2_ERROR_BADOPTION is - returned, otherwise the number of code units used is returned. This is + The where argument should point to a buffer that is at least 64 code + units long. (The exact length required can be found by calling + pcre2_config() with where set to NULL.) The buffer is filled with a + string that contains the name of the architecture for which the JIT + compiler is configured, for example "x86 32bit (little endian + un- + aligned)". If JIT support is not available, PCRE2_ERROR_BADOPTION is + returned, otherwise the number of code units used is returned. This is the length of the string, plus one unit for the terminating zero. PCRE2_CONFIG_LINKSIZE - The output is a uint32_t integer that contains the number of bytes used - for internal linkage in compiled regular expressions. When PCRE2 is - configured, the value can be set to 2, 3, or 4, with the default being - 2. This is the value that is returned by pcre2_config(). However, when - the 16-bit library is compiled, a value of 3 is rounded up to 4, and - when the 32-bit library is compiled, internal linkages always use 4 - bytes, so the configured value is not relevant. + The output is a uint32_t integer that contains the number of bytes the + library was instructed to use for internal linkage in compiled regular + expressions. When PCRE2 is configured, the value can be set to 2, 3, + or 4, with the default being 2 for most libraries. + + The actual number of bytes used depends on the size of the code units + that the library supports and can be higher. See PCRE2_CONFIG_EFFEC- + TIVE_LINKSIZE above for details. The default value of 2 for the 8-bit and 16-bit libraries is sufficient - for all but the most massive patterns, since it allows the size of the - compiled pattern to be up to 65535 code units. Larger values allow - larger regular expressions to be compiled by those two libraries, but + for all but the most massive patterns, since it allows the size of the + compiled pattern to be up to 65535 code units. Larger values allow + larger regular expressions to be compiled by those two libraries, but at the expense of slower matching. PCRE2_CONFIG_MATCHLIMIT The output is a uint32_t integer that gives the default match limit for - pcre2_match(). Further details are given with pcre2_set_match_limit() + pcre2_match(). Further details are given with pcre2_set_match_limit() above. PCRE2_CONFIG_NEWLINE - The output is a uint32_t integer whose value specifies the default - character sequence that is recognized as meaning "newline". The values + The output is a uint32_t integer whose value specifies the default + character sequence that is recognized as meaning "newline". The values are: PCRE2_NEWLINE_CR Carriage return (CR) @@ -1401,23 +1409,23 @@ CHECKING BUILD-TIME OPTIONS PCRE2_NEWLINE_ANYCRLF Any of CR, LF, or CRLF PCRE2_NEWLINE_NUL The NUL character (binary zero) - The default should normally correspond to the standard sequence for + The default should normally correspond to the standard sequence for your operating system. PCRE2_CONFIG_NEVER_BACKSLASH_C - The output is a uint32_t integer that is set to one if the use of \C - was permanently disabled when PCRE2 was built; otherwise it is set to + The output is a uint32_t integer that is set to one if the use of \C + was permanently disabled when PCRE2 was built; otherwise it is set to zero. PCRE2_CONFIG_PARENSLIMIT - The output is a uint32_t integer that gives the maximum depth of nest- + The output is a uint32_t integer that gives the maximum depth of nest- ing of parentheses (of any kind) in a pattern. This limit is imposed to - cap the amount of system stack used when a pattern is compiled. It is - specified when PCRE2 is built; the default is 250. This limit does not + cap the amount of system stack used when a pattern is compiled. It is + specified when PCRE2 is built; the default is 250. This limit does not take into account the stack that may already be used by the calling ap- - plication. For finer control over compilation stack usage, see + plication. For finer control over compilation stack usage, see pcre2_set_compile_recursion_guard(). PCRE2_CONFIG_STACKRECURSE @@ -1428,30 +1436,30 @@ CHECKING BUILD-TIME OPTIONS PCRE2_CONFIG_TABLES_LENGTH The output is a uint32_t integer that gives the length of PCRE2's char- - acter processing tables in bytes. For details of these tables see the + acter processing tables in bytes. For details of these tables see the section on locale support below. PCRE2_CONFIG_UNICODE_VERSION - The where argument should point to a buffer that is at least 24 code - units long. (The exact length required can be found by calling - pcre2_config() with where set to NULL.) If PCRE2 has been compiled - without Unicode support, the buffer is filled with the text "Unicode - not supported". Otherwise, the Unicode version string (for example, - "8.0.0") is inserted. The number of code units used is returned. This + The where argument should point to a buffer that is at least 24 code + units long. (The exact length required can be found by calling + pcre2_config() with where set to NULL.) If PCRE2 has been compiled + without Unicode support, the buffer is filled with the text "Unicode + not supported". Otherwise, the Unicode version string (for example, + "8.0.0") is inserted. The number of code units used is returned. This is the length of the string plus one unit for the terminating zero. PCRE2_CONFIG_UNICODE - The output is a uint32_t integer that is set to one if Unicode support - is available; otherwise it is set to zero. Unicode support implies UTF + The output is a uint32_t integer that is set to one if Unicode support + is available; otherwise it is set to zero. Unicode support implies UTF support. PCRE2_CONFIG_VERSION - The where argument should point to a buffer that is at least 24 code - units long. (The exact length required can be found by calling - pcre2_config() with where set to NULL.) The buffer is filled with the + The where argument should point to a buffer that is at least 24 code + units long. (The exact length required can be found by calling + pcre2_config() with where set to NULL.) The buffer is filled with the PCRE2 version string, zero-terminated. The number of code units used is returned. This is the length of the string plus one unit for the termi- nating zero. @@ -1469,107 +1477,107 @@ COMPILING A PATTERN pcre2_code *pcre2_code_copy_with_tables(const pcre2_code *code); - The pcre2_compile() function compiles a pattern into an internal form. - The pattern is defined by a pointer to a string of code units and a + The pcre2_compile() function compiles a pattern into an internal form. + The pattern is defined by a pointer to a string of code units and a length in code units. If the pattern is zero-terminated, the length can - be specified as PCRE2_ZERO_TERMINATED. A NULL pattern pointer with a - length of zero is treated as an empty string (NULL with a non-zero - length causes an error return). The function returns a pointer to a + be specified as PCRE2_ZERO_TERMINATED. A NULL pattern pointer with a + length of zero is treated as an empty string (NULL with a non-zero + length causes an error return). The function returns a pointer to a block of memory that contains the compiled pattern and related data, or NULL if an error occurred. - If the compile context argument ccontext is NULL, memory for the com- - piled pattern is obtained by calling malloc(). Otherwise, it is ob- + If the compile context argument ccontext is NULL, memory for the com- + piled pattern is obtained by calling malloc(). Otherwise, it is ob- tained from the same memory function that was used for the compile con- text. The caller must free the memory by calling pcre2_code_free() when it is no longer needed. If pcre2_code_free() is called with a NULL ar- gument, it returns immediately, without doing anything. The function pcre2_code_copy() makes a copy of the compiled code in new - memory, using the same memory allocator as was used for the original. - However, if the code has been processed by the JIT compiler (see be- - low), the JIT information cannot be copied (because it is position-de- - pendent). The new copy can initially be used only for non-JIT match- - ing, though it can be passed to pcre2_jit_compile() if required. If + memory, using the same memory allocator as was used for the original. + However, if the code has been processed by the JIT compiler (see be- + low), the JIT information cannot be copied (because it is position-de- + pendent). The new copy can initially be used only for non-JIT match- + ing, though it can be passed to pcre2_jit_compile() if required. If pcre2_code_copy() is called with a NULL argument, it returns NULL. The pcre2_code_copy() function provides a way for individual threads in - a multithreaded application to acquire a private copy of shared com- - piled code. However, it does not make a copy of the character tables - used by the compiled pattern; the new pattern code points to the same - tables as the original code. (See "Locale Support" below for details - of these character tables.) In many applications the same tables are - used throughout, so this behaviour is appropriate. Nevertheless, there + a multithreaded application to acquire a private copy of shared com- + piled code. However, it does not make a copy of the character tables + used by the compiled pattern; the new pattern code points to the same + tables as the original code. (See "Locale Support" below for details + of these character tables.) In many applications the same tables are + used throughout, so this behaviour is appropriate. Nevertheless, there are occasions when a copy of a compiled pattern and the relevant tables - are needed. The pcre2_code_copy_with_tables() provides this facility. - Copies of both the code and the tables are made, with the new code - pointing to the new tables. The memory for the new tables is automati- - cally freed when pcre2_code_free() is called for the new copy of the - compiled code. If pcre2_code_copy_with_tables() is called with a NULL + are needed. The pcre2_code_copy_with_tables() provides this facility. + Copies of both the code and the tables are made, with the new code + pointing to the new tables. The memory for the new tables is automati- + cally freed when pcre2_code_free() is called for the new copy of the + compiled code. If pcre2_code_copy_with_tables() is called with a NULL argument, it returns NULL. - NOTE: When one of the matching functions is called, pointers to the + NOTE: When one of the matching functions is called, pointers to the compiled pattern and the subject string are set in the match data block - so that they can be referenced by the substring extraction functions - after a successful match. After running a match, you must not free a - compiled pattern or a subject string until after all operations on the - match data block have taken place, unless, in the case of the subject - string, you have used the PCRE2_COPY_MATCHED_SUBJECT option, which is - described in the section entitled "Option bits for pcre2_match()" be- + so that they can be referenced by the substring extraction functions + after a successful match. After running a match, you must not free a + compiled pattern or a subject string until after all operations on the + match data block have taken place, unless, in the case of the subject + string, you have used the PCRE2_COPY_MATCHED_SUBJECT option, which is + described in the section entitled "Option bits for pcre2_match()" be- low. - The options argument for pcre2_compile() contains various bit settings - that affect the compilation. It should be zero if none of them are re- - quired. The available options are described below. Some of them (in - particular, those that are compatible with Perl, but some others as - well) can also be set and unset from within the pattern (see the de- + The options argument for pcre2_compile() contains various bit settings + that affect the compilation. It should be zero if none of them are re- + quired. The available options are described below. Some of them (in + particular, those that are compatible with Perl, but some others as + well) can also be set and unset from within the pattern (see the de- tailed description in the pcre2pattern documentation). - For those options that can be different in different parts of the pat- - tern, the contents of the options argument specifies their settings at - the start of compilation. The PCRE2_ANCHORED, PCRE2_ENDANCHORED, and - PCRE2_NO_UTF_CHECK options can be set at the time of matching as well + For those options that can be different in different parts of the pat- + tern, the contents of the options argument specifies their settings at + the start of compilation. The PCRE2_ANCHORED, PCRE2_ENDANCHORED, and + PCRE2_NO_UTF_CHECK options can be set at the time of matching as well as at compile time. Some additional options and less frequently required compile-time para- - meters (for example, the newline setting) can be provided in a compile + meters (for example, the newline setting) can be provided in a compile context (as described above). If errorcode or erroroffset is NULL, pcre2_compile() returns NULL imme- - diately. Otherwise, the variables to which these point are set to an + diately. Otherwise, the variables to which these point are set to an error code and an offset (number of code units) within the pattern, re- spectively, when pcre2_compile() returns NULL because a compilation er- ror has occurred. There are over 100 positive error codes that pcre2_compile() may return if it finds an error in the pattern. There are also some negative error - codes that are used for invalid UTF strings when validity checking is - in force. These are the same as given by pcre2_match() and + codes that are used for invalid UTF strings when validity checking is + in force. These are the same as given by pcre2_match() and pcre2_dfa_match(), and are described in the pcre2unicode documentation. - There is no separate documentation for the positive error codes, be- - cause the textual error messages that are obtained by calling the + There is no separate documentation for the positive error codes, be- + cause the textual error messages that are obtained by calling the pcre2_get_error_message() function (see "Obtaining a textual error mes- - sage" below) should be self-explanatory. Macro names starting with - PCRE2_ERROR_ are defined for both positive and negative error codes in - pcre2.h. When compilation is successful errorcode is set to a value - that returns the message "no error" if passed to pcre2_get_error_mes- + sage" below) should be self-explanatory. Macro names starting with + PCRE2_ERROR_ are defined for both positive and negative error codes in + pcre2.h. When compilation is successful errorcode is set to a value + that returns the message "no error" if passed to pcre2_get_error_mes- sage(). The value returned in erroroffset is an indication of where in the pat- - tern an error occurred. When there is no error, zero is returned. A - non-zero value is not necessarily the furthest point in the pattern - that was read. For example, after the error "lookbehind assertion is - not fixed length", the error offset points to the start of the failing + tern an error occurred. When there is no error, zero is returned. A + non-zero value is not necessarily the furthest point in the pattern + that was read. For example, after the error "lookbehind assertion is + not fixed length", the error offset points to the start of the failing assertion. For an invalid UTF-8 or UTF-16 string, the offset is that of the first code unit of the failing character. - Some errors are not detected until the whole pattern has been scanned; - in these cases, the offset passed back is the length of the pattern. - Note that the offset is in code units, not characters, even in a UTF + Some errors are not detected until the whole pattern has been scanned; + in these cases, the offset passed back is the length of the pattern. + Note that the offset is in code units, not characters, even in a UTF mode. It may sometimes point into the middle of a UTF-8 or UTF-16 char- acter. - This code fragment shows a typical straightforward call to pcre2_com- + This code fragment shows a typical straightforward call to pcre2_com- pile(): pcre2_code *re; @@ -1586,81 +1594,80 @@ COMPILING A PATTERN Main compile options - The following names for option bits are defined in the pcre2.h header + The following names for option bits are defined in the pcre2.h header file: PCRE2_ANCHORED If this bit is set, the pattern is forced to be "anchored", that is, it - is constrained to match only at the first matching point in the string - that is being searched (the "subject string"). This effect can also be - achieved by appropriate constructs in the pattern itself, which is the + is constrained to match only at the first matching point in the string + that is being searched (the "subject string"). This effect can also be + achieved by appropriate constructs in the pattern itself, which is the only way to do it in Perl. PCRE2_ALLOW_EMPTY_CLASS - By default, for compatibility with Perl, a closing square bracket that - immediately follows an opening one is treated as a data character for - the class. When PCRE2_ALLOW_EMPTY_CLASS is set, it terminates the + By default, for compatibility with Perl, a closing square bracket that + immediately follows an opening one is treated as a data character for + the class. When PCRE2_ALLOW_EMPTY_CLASS is set, it terminates the class, which therefore contains no characters and so can never match. PCRE2_ALT_BSUX - This option request alternative handling of three escape sequences, - which makes PCRE2's behaviour more like ECMAscript (aka JavaScript). + This option request alternative handling of three escape sequences, + which makes PCRE2's behaviour more like ECMAscript (aka JavaScript). When it is set: (1) \U matches an upper case "U" character; by default \U causes a com- pile time error (Perl uses \U to upper case subsequent characters). (2) \u matches a lower case "u" character unless it is followed by four - hexadecimal digits, in which case the hexadecimal number defines the - code point to match. By default, \u causes a compile time error (Perl + hexadecimal digits, in which case the hexadecimal number defines the + code point to match. By default, \u causes a compile time error (Perl uses it to upper case the following character). - (3) \x matches a lower case "x" character unless it is followed by two - hexadecimal digits, in which case the hexadecimal number defines the - code point to match. By default, as in Perl, a hexadecimal number is - always expected after \x, but it may have zero, one, or two digits (so, - for example, \xz matches a binary zero character followed by z). + (3) \x matches a lower case "x" character unless it is followed by two + hexadecimal digits, in which case the hexadecimal number defines the + code point to match. By default, as in Perl, a hexadecimal number is + always expected after \x, but it may have one or two digits. ECMAscript 6 added additional functionality to \u. This can be accessed - using the PCRE2_EXTRA_ALT_BSUX extra option (see "Extra compile op- + using the PCRE2_EXTRA_ALT_BSUX extra option (see "Extra compile op- tions" below). Note that this alternative escape handling applies only - to patterns. Neither of these options affects the processing of re- + to patterns. Neither of these options affects the processing of re- placement strings passed to pcre2_substitute(). PCRE2_ALT_CIRCUMFLEX In multiline mode (when PCRE2_MULTILINE is set), the circumflex - metacharacter matches at the start of the subject (unless PCRE2_NOTBOL - is set), and also after any internal newline. However, it does not + metacharacter matches at the start of the subject (unless PCRE2_NOTBOL + is set), and also after any internal newline. However, it does not match after a newline at the end of the subject, for compatibility with - Perl. If you want a multiline circumflex also to match after a termi- + Perl. If you want a multiline circumflex also to match after a termi- nating newline, you must set PCRE2_ALT_CIRCUMFLEX. PCRE2_ALT_EXTENDED_CLASS - Alters the parsing of character classes to follow the extended syntax + Alters the parsing of character classes to follow the extended syntax described by Unicode UTS#18. The PCRE2_ALT_EXTENDED_CLASS option has no - impact on the behaviour of the Perl-specific "(?[...])" syntax for ex- - tended classes, but instead enables the alternative syntax of extended - class behaviour inside ordinary "[...]" character classes. See the - pcre2pattern documentation for details of the character classes sup- + impact on the behaviour of the Perl-specific "(?[...])" syntax for ex- + tended classes, but instead enables the alternative syntax of extended + class behaviour inside ordinary "[...]" character classes. See the + pcre2pattern documentation for details of the character classes sup- ported. PCRE2_ALT_VERBNAMES - By default, for compatibility with Perl, the name in any verb sequence - such as (*MARK:NAME) is any sequence of characters that does not in- - clude a closing parenthesis. The name is not processed in any way, and - it is not possible to include a closing parenthesis in the name. How- - ever, if the PCRE2_ALT_VERBNAMES option is set, normal backslash pro- - cessing is applied to verb names and only an unescaped closing paren- - thesis terminates the name. A closing parenthesis can be included in a - name either as \) or between \Q and \E. If the PCRE2_EXTENDED or - PCRE2_EXTENDED_MORE option is set with PCRE2_ALT_VERBNAMES, unescaped - whitespace in verb names is skipped and #-comments are recognized, ex- + By default, for compatibility with Perl, the name in any verb sequence + such as (*MARK:NAME) is any sequence of characters that does not in- + clude a closing parenthesis. The name is not processed in any way, and + it is not possible to include a closing parenthesis in the name. How- + ever, if the PCRE2_ALT_VERBNAMES option is set, normal backslash pro- + cessing is applied to verb names and only an unescaped closing paren- + thesis terminates the name. A closing parenthesis can be included in a + name either as \) or between \Q and \E. If the PCRE2_EXTENDED or + PCRE2_EXTENDED_MORE option is set with PCRE2_ALT_VERBNAMES, unescaped + white space in verb names is skipped and #-comments are recognized, ex- actly as in the rest of the pattern. PCRE2_AUTO_CALLOUT @@ -2901,15 +2908,9 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION starting point to discover that it is preceded by a letter. Finding all the matches in a subject is tricky when the pattern can - match an empty string. It is possible to emulate Perl's /g behaviour by - first trying the match again at the same offset, with the - PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED options, and then if that - fails, advancing the starting offset and trying an ordinary match - again. There is some code that demonstrates how to do this in the - pcre2demo sample program. In the most general case, you have to check - to see if the newline convention recognizes CRLF as a newline, and if - so, and the current character is CR followed by LF, advance the start- - ing offset by two characters instead of one. + match an empty string. PCRE2 includes a helper API to assist with this; + see the section entitled "Iterating over all matches" below for de- + tails. If a non-zero starting offset is passed when the pattern is anchored, a single attempt to match at the given offset is made. This can only suc- @@ -2939,156 +2940,156 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION The PCRE2_ANCHORED option limits pcre2_match() to matching at the first matching position. If a pattern was compiled with PCRE2_ANCHORED, or turned out to be anchored by virtue of its contents, it cannot be made - unachored at matching time. Note that setting the option at match time + unanchored at matching time. Note that setting the option at match time disables JIT matching. PCRE2_COPY_MATCHED_SUBJECT - By default, a pointer to the subject is remembered in the match data - block so that, after a successful match, it can be referenced by the - substring extraction functions. This means that the subject's memory - must not be freed until all such operations are complete. For some ap- - plications where the lifetime of the subject string is not guaranteed, - it may be necessary to make a copy of the subject string, but it is - wasteful to do this unless the match is successful. After a successful - match, if PCRE2_COPY_MATCHED_SUBJECT is set, the subject is copied and - the new pointer is remembered in the match data block instead of the - original subject pointer. The memory allocator that was used for the - match block itself is used. The copy is automatically freed when - pcre2_match_data_free() is called to free the match data block. It is + By default, a pointer to the subject is remembered in the match data + block so that, after a successful match, it can be referenced by the + substring extraction functions. This means that the subject's memory + must not be freed until all such operations are complete. For some ap- + plications where the lifetime of the subject string is not guaranteed, + it may be necessary to make a copy of the subject string, but it is + wasteful to do this unless the match is successful. After a successful + match, if PCRE2_COPY_MATCHED_SUBJECT is set, the subject is copied and + the new pointer is remembered in the match data block instead of the + original subject pointer. The memory allocator that was used for the + match block itself is used. The copy is automatically freed when + pcre2_match_data_free() is called to free the match data block. It is also automatically freed if the match data block is re-used for another match operation. PCRE2_DISABLE_RECURSELOOP_CHECK - This option is relevant only to pcre2_match() for interpretive match- - ing. It is ignored when JIT is used, and is forbidden for + This option is relevant only to pcre2_match() for interpretive match- + ing. It is ignored when JIT is used, and is forbidden for pcre2_dfa_match(). The use of recursion in patterns can lead to infinite loops. In the in- - terpretive matcher these would be eventually caught by the match or + terpretive matcher these would be eventually caught by the match or heap limits, but this could take a long time and/or use a lot of memory - if the limits are large. There is therefore a check at the start of - each recursion. If the same group is still active from a previous - call, and the current subject pointer is the same as it was at the - start of that group, and the furthest inspected character of the sub- + if the limits are large. There is therefore a check at the start of + each recursion. If the same group is still active from a previous + call, and the current subject pointer is the same as it was at the + start of that group, and the furthest inspected character of the sub- ject has not changed, an error is generated. - There are rare cases of matches that would complete, but nevertheless - trigger this error. This option disables the check. It is provided + There are rare cases of matches that would complete, but nevertheless + trigger this error. This option disables the check. It is provided mainly for testing when comparing JIT and interpretive behaviour. PCRE2_ENDANCHORED - If the PCRE2_ENDANCHORED option is set, any string that pcre2_match() - matches must be right at the end of the subject string. Note that set- + If the PCRE2_ENDANCHORED option is set, any string that pcre2_match() + matches must be right at the end of the subject string. Note that set- ting the option at match time disables JIT matching. PCRE2_NOTBOL This option specifies that first character of the subject string is not - the beginning of a line, so the circumflex metacharacter should not - match before it. Setting this without having set PCRE2_MULTILINE at + the beginning of a line, so the circumflex metacharacter should not + match before it. Setting this without having set PCRE2_MULTILINE at compile time causes circumflex never to match. This option affects only the behaviour of the circumflex metacharacter. It does not affect \A. PCRE2_NOTEOL This option specifies that the end of the subject string is not the end - of a line, so the dollar metacharacter should not match it nor (except - in multiline mode) a newline immediately before it. Setting this with- - out having set PCRE2_MULTILINE at compile time causes dollar never to + of a line, so the dollar metacharacter should not match it nor (except + in multiline mode) a newline immediately before it. Setting this with- + out having set PCRE2_MULTILINE at compile time causes dollar never to match. This option affects only the behaviour of the dollar metacharac- ter. It does not affect \Z or \z. PCRE2_NOTEMPTY An empty string is not considered to be a valid match if this option is - set. If there are alternatives in the pattern, they are tried. If all - the alternatives match the empty string, the entire match fails. For + set. If there are alternatives in the pattern, they are tried. If all + the alternatives match the empty string, the entire match fails. For example, if the pattern a?b? - is applied to a string not beginning with "a" or "b", it matches an + is applied to a string not beginning with "a" or "b", it matches an empty string at the start of the subject. With PCRE2_NOTEMPTY set, this - match is not valid, so pcre2_match() searches further into the string + match is not valid, so pcre2_match() searches further into the string for occurrences of "a" or "b". PCRE2_NOTEMPTY_ATSTART - This is like PCRE2_NOTEMPTY, except that it locks out an empty string + This is like PCRE2_NOTEMPTY, except that it locks out an empty string match only at the first matching position, that is, at the start of the - subject plus the starting offset. An empty string match later in the + subject plus the starting offset. An empty string match later in the subject is permitted. If the pattern is anchored, such a match can oc- cur only if the pattern contains \K. PCRE2_NO_JIT - By default, if a pattern has been successfully processed by - pcre2_jit_compile(), JIT is automatically used when pcre2_match() is - called with options that JIT supports. Setting PCRE2_NO_JIT disables + By default, if a pattern has been successfully processed by + pcre2_jit_compile(), JIT is automatically used when pcre2_match() is + called with options that JIT supports. Setting PCRE2_NO_JIT disables the use of JIT; it forces matching to be done by the interpreter. PCRE2_NO_UTF_CHECK When PCRE2_UTF is set at compile time, the validity of the subject as a - UTF string is checked unless PCRE2_NO_UTF_CHECK is passed to + UTF string is checked unless PCRE2_NO_UTF_CHECK is passed to pcre2_match() or PCRE2_MATCH_INVALID_UTF was passed to pcre2_compile(). The latter special case is discussed in detail in the pcre2unicode doc- umentation. - In the default case, if a non-zero starting offset is given, the check - is applied only to that part of the subject that could be inspected - during matching, and there is a check that the starting offset points - to the first code unit of a character or to the end of the subject. If - there are no lookbehind assertions in the pattern, the check starts at + In the default case, if a non-zero starting offset is given, the check + is applied only to that part of the subject that could be inspected + during matching, and there is a check that the starting offset points + to the first code unit of a character or to the end of the subject. If + there are no lookbehind assertions in the pattern, the check starts at the starting offset. Otherwise, it starts at the length of the longest - lookbehind before the starting offset, or at the start of the subject - if there are not that many characters before the starting offset. Note + lookbehind before the starting offset, or at the start of the subject + if there are not that many characters before the starting offset. Note that the sequences \b and \B are one-character lookbehinds. The check is carried out before any other processing takes place, and a - negative error code is returned if the check fails. There are several - UTF error codes for each code unit width, corresponding to different - problems with the code unit sequence. There are discussions about the - validity of UTF-8 strings, UTF-16 strings, and UTF-32 strings in the + negative error code is returned if the check fails. There are several + UTF error codes for each code unit width, corresponding to different + problems with the code unit sequence. There are discussions about the + validity of UTF-8 strings, UTF-16 strings, and UTF-32 strings in the pcre2unicode documentation. If you know that your subject is valid, and you want to skip this check for performance reasons, you can set the PCRE2_NO_UTF_CHECK option when - calling pcre2_match(). You might want to do this for the second and - subsequent calls to pcre2_match() if you are making repeated calls to + calling pcre2_match(). You might want to do this for the second and + subsequent calls to pcre2_match() if you are making repeated calls to find multiple matches in the same subject string. - Warning: Unless PCRE2_MATCH_INVALID_UTF was set at compile time, when - PCRE2_NO_UTF_CHECK is set at match time the effect of passing an in- + Warning: Unless PCRE2_MATCH_INVALID_UTF was set at compile time, when + PCRE2_NO_UTF_CHECK is set at match time the effect of passing an in- valid string as a subject, or an invalid value of startoffset, is unde- - fined. Your program may crash or loop indefinitely or give wrong re- + fined. Your program may crash or loop indefinitely or give wrong re- sults. PCRE2_PARTIAL_HARD PCRE2_PARTIAL_SOFT These options turn on the partial matching feature. A partial match oc- - curs if the end of the subject string is reached successfully, but + curs if the end of the subject string is reached successfully, but there are not enough subject characters to complete the match. In addi- - tion, either at least one character must have been inspected or the - pattern must contain a lookbehind, or the pattern must be one that + tion, either at least one character must have been inspected or the + pattern must contain a lookbehind, or the pattern must be one that could match an empty string. - If this situation arises when PCRE2_PARTIAL_SOFT (but not PCRE2_PAR- + If this situation arises when PCRE2_PARTIAL_SOFT (but not PCRE2_PAR- TIAL_HARD) is set, matching continues by testing any remaining alterna- - tives. Only if no complete match can be found is PCRE2_ERROR_PARTIAL - returned instead of PCRE2_ERROR_NOMATCH. In other words, PCRE2_PAR- - TIAL_SOFT specifies that the caller is prepared to handle a partial + tives. Only if no complete match can be found is PCRE2_ERROR_PARTIAL + returned instead of PCRE2_ERROR_NOMATCH. In other words, PCRE2_PAR- + TIAL_SOFT specifies that the caller is prepared to handle a partial match, but only if no complete match can be found. - If PCRE2_PARTIAL_HARD is set, it overrides PCRE2_PARTIAL_SOFT. In this - case, if a partial match is found, pcre2_match() immediately returns - PCRE2_ERROR_PARTIAL, without considering any other alternatives. In + If PCRE2_PARTIAL_HARD is set, it overrides PCRE2_PARTIAL_SOFT. In this + case, if a partial match is found, pcre2_match() immediately returns + PCRE2_ERROR_PARTIAL, without considering any other alternatives. In other words, when PCRE2_PARTIAL_HARD is set, a partial match is consid- - ered to be more important that an alternative complete match. + ered to be more important than an alternative complete match. There is a more detailed discussion of partial and multi-segment match- ing, with examples, in the pcre2partial documentation. @@ -3096,38 +3097,38 @@ MATCHING A PATTERN: THE TRADITIONAL FUNCTION NEWLINE HANDLING WHEN MATCHING - When PCRE2 is built, a default newline convention is set; this is usu- - ally the standard convention for the operating system. The default can - be overridden in a compile context by calling pcre2_set_newline(). It - can also be overridden by starting a pattern string with, for example, - (*CRLF), as described in the section on newline conventions in the - pcre2pattern page. During matching, the newline choice affects the be- - haviour of the dot, circumflex, and dollar metacharacters. It may also - alter the way the match starting position is advanced after a match + When PCRE2 is built, a default newline convention is set; this is usu- + ally the standard convention for the operating system. The default can + be overridden in a compile context by calling pcre2_set_newline(). It + can also be overridden by starting a pattern string with, for example, + (*CRLF), as described in the section on newline conventions in the + pcre2pattern page. During matching, the newline choice affects the be- + haviour of the dot, circumflex, and dollar metacharacters. It may also + alter the way the match starting position is advanced after a match failure for an unanchored pattern. When PCRE2_NEWLINE_CRLF, PCRE2_NEWLINE_ANYCRLF, or PCRE2_NEWLINE_ANY is - set as the newline convention, and a match attempt for an unanchored + set as the newline convention, and a match attempt for an unanchored pattern fails when the current starting position is at a CRLF sequence, - and the pattern contains no explicit matches for CR or LF characters, - the match position is advanced by two characters instead of one, in + and the pattern contains no explicit matches for CR or LF characters, + the match position is advanced by two characters instead of one, in other words, to after the CRLF. The above rule is a compromise that makes the most common cases work as - expected. For example, if the pattern is .+A (and the PCRE2_DOTALL op- - tion is not set), it does not match the string "\r\nA" because, after - failing at the start, it skips both the CR and the LF before retrying. - However, the pattern [\r\n]A does match that string, because it con- + expected. For example, if the pattern is .+A (and the PCRE2_DOTALL op- + tion is not set), it does not match the string "\r\nA" because, after + failing at the start, it skips both the CR and the LF before retrying. + However, the pattern [\r\n]A does match that string, because it con- tains an explicit CR or LF reference, and so advances only by one char- acter after the first failure. An explicit match for CR of LF is either a literal appearance of one of - those characters in the pattern, or one of the \r or \n or equivalent + those characters in the pattern, or one of the \r or \n or equivalent octal or hexadecimal escape sequences. Implicit matches such as [^X] do - not count, nor does \s, even though it includes CR and LF in the char- + not count, nor does \s, even though it includes CR and LF in the char- acters that it matches. - Notwithstanding the above, anomalous effects may still occur when CRLF + Notwithstanding the above, anomalous effects may still occur when CRLF is a valid newline sequence and explicit \r or \n escapes appear in the pattern. @@ -3138,51 +3139,52 @@ HOW PCRE2_MATCH() RETURNS A STRING AND CAPTURED SUBSTRINGS PCRE2_SIZE *pcre2_get_ovector_pointer(pcre2_match_data *match_data); - In general, a pattern matches a certain portion of the subject, and in - addition, further substrings from the subject may be picked out by - parenthesized parts of the pattern. Following the usage in Jeffrey - Friedl's book, this is called "capturing" in what follows, and the - phrase "capture group" (Perl terminology) is used for a fragment of a - pattern that picks out a substring. PCRE2 supports several other kinds + In general, a pattern matches a certain portion of the subject, and in + addition, further substrings from the subject may be picked out by + parenthesized parts of the pattern. Following the usage in Jeffrey + Friedl's book, this is called "capturing" in what follows, and the + phrase "capture group" (Perl terminology) is used for a fragment of a + pattern that picks out a substring. PCRE2 supports several other kinds of parenthesized group that do not cause substrings to be captured. The - pcre2_pattern_info() function can be used to find out how many capture + pcre2_pattern_info() function can be used to find out how many capture groups there are in a compiled pattern. - You can use auxiliary functions for accessing captured substrings by + You can use auxiliary functions for accessing captured substrings by number or by name, as described in sections below. Alternatively, you can make direct use of the vector of PCRE2_SIZE val- - ues, called the ovector, which contains the offsets of captured - strings. It is part of the match data block. The function - pcre2_get_ovector_pointer() returns the address of the ovector, and + ues, called the ovector, which contains the offsets of captured + strings. It is part of the match data block. The function + pcre2_get_ovector_pointer() returns the address of the ovector, and pcre2_get_ovector_count() returns the number of pairs of values it con- tains. Within the ovector, the first in each pair of values is set to the off- set of the first code unit of a substring, and the second is set to the - offset of the first code unit after the end of a substring. These val- - ues are always code unit offsets, not character offsets. That is, they + offset of the first code unit after the end of a substring. These val- + ues are always code unit offsets, not character offsets. That is, they are byte offsets in the 8-bit library, 16-bit offsets in the 16-bit li- brary, and 32-bit offsets in the 32-bit library. - After a partial match (error return PCRE2_ERROR_PARTIAL), only the - first pair of offsets (that is, ovector[0] and ovector[1]) are set. - They identify the part of the subject that was partially matched. See + After a partial match (error return PCRE2_ERROR_PARTIAL), only the + first pair of offsets (that is, ovector[0] and ovector[1]) are set. + They identify the part of the subject that was partially matched. See the pcre2partial documentation for details of partial matching. - After a fully successful match, the first pair of offsets identifies - the portion of the subject string that was matched by the entire pat- - tern. The next pair is used for the first captured substring, and so - on. The value returned by pcre2_match() is one more than the highest - numbered pair that has been set. For example, if two substrings have - been captured, the returned value is 3. If there are no captured sub- + After a fully successful match, the first pair of offsets identifies + the portion of the subject string that was matched by the entire pat- + tern. The next pair is used for the first captured substring, and so + on. The value returned by pcre2_match() is one more than the highest + numbered pair that has been set. For example, if two substrings have + been captured, the returned value is 3. If there are no captured sub- strings, the return value from a successful match is 1, indicating that just the first pair of offsets has been set. - If a pattern uses the \K escape sequence within a positive assertion, - the reported start of a successful match can be greater than the end of - the match. For example, if the pattern (?=ab\K) is matched against - "ab", the start and end offset values for the match are 2 and 0. + If a pattern uses the \K escape sequence within a positive lookahead + assertion, the reported start of a successful match can be greater than + the end of the match. For example, if the pattern (?=ab\K) is matched + against "ab", the start and end offset values for the match are 2 and + 0. If a capture group is matched repeatedly within a single match opera- tion, it is the last portion of the subject that it matched that is re- @@ -3398,8 +3400,92 @@ OBTAINING A TEXTUAL ERROR MESSAGE zero. If the error number is unknown, the negative error code PCRE2_ER- ROR_BADDATA is returned. If the buffer is too small, the message is truncated (but still with a trailing zero), and the negative error code - PCRE2_ERROR_NOMEMORY is returned. None of the messages are very long; - a buffer size of 120 code units is ample. + PCRE2_ERROR_NOMEMORY is returned. None of the messages is very long; a + buffer size of 120 code units is ample. + + +ITERATING OVER ALL MATCHES + + int pcre2_next_match(pcre2_match_data *match_data, + PCRE2_SIZE *pstart_offset, uint32_t *poptions); + + A common task for applications is to implement "global" matching behav- + iour, for example, replacing all matches in the subject; splitting the + subject on all matches; or simply counting the number of matches. The + pcre2_next_match() function helps with this task by providing the ap- + propriate parameters for the next match attempt (available since PCRE2 + 10.46). + + First, a match attempt should be made using one of the matching func- + tions (pcre2_match(), pcre2_dfa_match(), or pcre2_jit_match()). Then, + pcre2_next_match() can be called, providing the same match_data parame- + ter. + + It returns 0 ("false") if there is no need to make a further match at- + tempt, or 1 ("true") if another match should be attempted. Returning 1 + does not imply that there is another match, only that another match + should be attempted (which may return PCRE2_ERROR_NOMATCH). + + The *pstart_offset and *poptions are set if the function returns 1. + The *pstart_offset should be passed to the next match attempt directly, + and the *poptions should be passed to the next match attempt by combin- + ing with the application's match options using OR. + + There is some code that demonstrates how to do this in the pcre2demo + sample program. The general pattern is: + + uint32_t app_options = ...; + uint32_t global_options = 0; + PCRE2_SIZE start_offset = 0; + while (1) + { + int rc = pcre2_match(re, subject, subject_len, start_offset, + app_options | global_options, match_data, + match_context); + + if (rc == PCRE2_ERROR_NOMATCH) break; /* no match, and no more attempts */ + if (rc < 0) { ... exit } + + ...handle the match + + if (!pcre2_next_match(match_data, &start_offset, &global_options)) + break; /* no more attempts */ + } + + The guarantees provided by pcre2_next_match() are that the start_offset + will advance, so the loop will definitely terminate. The conditions + which ensure this are that either: (a) pcre2_next_match() returns 0 + (false); or (b) the returned *pstart_offset is strictly greater than + the previous start_offset; or (c) if the previous match was a success- + ful match of the empty string then the returned *pstart_offset is equal + to the previous ovector[1], and *poptions will be set to + PCRE2_NOTEMPTY_ATSTART to prevent another empty match from being re- + turned. + + A loop implemented as shown above will always terminate, unless there + is a bug in PCRE2. As a measure of "defensive programming", applica- + tions are encouraged to add an assertion or check to break their loop + if it does not make progress (and report the issue as a bug). + + If an application does not use the flag PCRE2_EXTRA_AL- + LOW_LOOKAROUND_BSK, then each match is "well-behaved" and satisfies: + + start_offset <= ovector[0] <= ovector[1]. + + In this case, the matches found by pcre2_match() with + pcre2_next_match() will be sorted, non-overlapping (possibly touching), + and with no duplicates. + + Otherwise, if PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK is used, then the guar- + antees are considerably weaker. We do not guarantee that the matches + will always advance: only that the start_offset will. The matches found + by pcre2_match() with pcre2_next_match() will be a finite sequence (as + pcre2_next_match() ensures that start_offset advances, so the search + will terminate). The matches can however be overlapping, can contain + duplicates, and (in truly pathological examples) may not even be sorted + by ovector[0]. Additionally, each match itself can end before it starts + (ovector[1] < ovector[0]). We recommend that applications do not set + PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK. EXTRACTING CAPTURED SUBSTRINGS BY NUMBER @@ -3417,39 +3503,39 @@ EXTRACTING CAPTURED SUBSTRINGS BY NUMBER void pcre2_substring_free(PCRE2_UCHAR *buffer); - Captured substrings can be accessed directly by using the ovector as + Captured substrings can be accessed directly by using the ovector as described above. For convenience, auxiliary functions are provided for - extracting captured substrings as new, separate, zero-terminated + extracting captured substrings as new, separate, zero-terminated strings. A substring that contains a binary zero is correctly extracted - and has a further zero added on the end, but the result is not, of + and has a further zero added on the end, but the result is not, of course, a C string. The functions in this section identify substrings by number. The number zero refers to the entire matched substring, with higher numbers refer- - ring to substrings captured by parenthesized groups. After a partial - match, only substring zero is available. An attempt to extract any - other substring gives the error PCRE2_ERROR_PARTIAL. The next section + ring to substrings captured by parenthesized groups. After a partial + match, only substring zero is available. An attempt to extract any + other substring gives the error PCRE2_ERROR_PARTIAL. The next section describes similar functions for extracting captured substrings by name. - If a pattern uses the \K escape sequence within a positive assertion, - the reported start of a successful match can be greater than the end of - the match. For example, if the pattern (?=ab\K) is matched against - "ab", the start and end offset values for the match are 2 and 0. In - this situation, calling these functions with a zero substring number - extracts a zero-length empty string. - - You can find the length in code units of a captured substring without - extracting it by calling pcre2_substring_length_bynumber(). The first - argument is a pointer to the match data block, the second is the group - number, and the third is a pointer to a variable into which the length - is placed. If you just want to know whether or not the substring has + If a pattern uses the \K escape sequence within a positive lookahead + assertion, the reported start of a successful match can be greater than + the end of the match. For example, if the pattern (?=ab\K) is matched + against "ab", the start and end offset values for the match are 2 and + 0. In this situation, calling these functions with a zero substring + number extracts a zero-length empty string. + + You can find the length in code units of a captured substring without + extracting it by calling pcre2_substring_length_bynumber(). The first + argument is a pointer to the match data block, the second is the group + number, and the third is a pointer to a variable into which the length + is placed. If you just want to know whether or not the substring has been captured, you can pass the third argument as NULL. - The pcre2_substring_copy_bynumber() function copies a captured sub- - string into a supplied buffer, whereas pcre2_substring_get_bynumber() - copies it into new memory, obtained using the same memory allocation - function that was used for the match data block. The first two argu- - ments of these functions are a pointer to the match data block and a + The pcre2_substring_copy_bynumber() function copies a captured sub- + string into a supplied buffer, whereas pcre2_substring_get_bynumber() + copies it into new memory, obtained using the same memory allocation + function that was used for the match data block. The first two argu- + ments of these functions are a pointer to the match data block and a capture group number. The final arguments of pcre2_substring_copy_bynumber() are a pointer to @@ -3458,25 +3544,25 @@ EXTRACTING CAPTURED SUBSTRINGS BY NUMBER for the extracted substring, excluding the terminating zero. For pcre2_substring_get_bynumber() the third and fourth arguments point - to variables that are updated with a pointer to the new memory and the - number of code units that comprise the substring, again excluding the - terminating zero. When the substring is no longer needed, the memory + to variables that are updated with a pointer to the new memory and the + number of code units that comprise the substring, again excluding the + terminating zero. When the substring is no longer needed, the memory should be freed by calling pcre2_substring_free(). - The return value from all these functions is zero for success, or a - negative error code. If the pattern match failed, the match failure - code is returned. If a substring number greater than zero is used af- - ter a partial match, PCRE2_ERROR_PARTIAL is returned. Other possible + The return value from all these functions is zero for success, or a + negative error code. If the pattern match failed, the match failure + code is returned. If a substring number greater than zero is used af- + ter a partial match, PCRE2_ERROR_PARTIAL is returned. Other possible error codes are: PCRE2_ERROR_NOMEMORY - The buffer was too small for pcre2_substring_copy_bynumber(), or the + The buffer was too small for pcre2_substring_copy_bynumber(), or the attempt to get memory failed for pcre2_substring_get_bynumber(). PCRE2_ERROR_NOSUBSTRING - There is no substring with that number in the pattern, that is, the + There is no substring with that number in the pattern, that is, the number is greater than the number of capturing parentheses. PCRE2_ERROR_UNAVAILABLE @@ -3487,8 +3573,8 @@ EXTRACTING CAPTURED SUBSTRINGS BY NUMBER PCRE2_ERROR_UNSET - The substring did not participate in the match. For example, if the - pattern is (abc)|(def) and the subject is "def", and the ovector con- + The substring did not participate in the match. For example, if the + pattern is (abc)|(def) and the subject is "def", and the ovector con- tains at least two capturing slots, substring number 1 is unset. @@ -3499,31 +3585,31 @@ EXTRACTING A LIST OF ALL CAPTURED SUBSTRINGS void pcre2_substring_list_free(PCRE2_UCHAR **list); - The pcre2_substring_list_get() function extracts all available sub- - strings and builds a list of pointers to them. It also (optionally) - builds a second list that contains their lengths (in code units), ex- - cluding a terminating zero that is added to each of them. All this is + The pcre2_substring_list_get() function extracts all available sub- + strings and builds a list of pointers to them. It also (optionally) + builds a second list that contains their lengths (in code units), ex- + cluding a terminating zero that is added to each of them. All this is done in a single block of memory that is obtained using the same memory allocation function that was used to get the match data block. - This function must be called only after a successful match. If called + This function must be called only after a successful match. If called after a partial match, the error code PCRE2_ERROR_PARTIAL is returned. - The address of the memory block is returned via listptr, which is also + The address of the memory block is returned via listptr, which is also the start of the list of string pointers. The end of the list is marked - by a NULL pointer. The address of the list of lengths is returned via - lengthsptr. If your strings do not contain binary zeros and you do not + by a NULL pointer. The address of the list of lengths is returned via + lengthsptr. If your strings do not contain binary zeros and you do not therefore need the lengths, you may supply NULL as the lengthsptr argu- - ment to disable the creation of a list of lengths. The yield of the - function is zero if all went well, or PCRE2_ERROR_NOMEMORY if the mem- - ory block could not be obtained. When the list is no longer needed, it + ment to disable the creation of a list of lengths. The yield of the + function is zero if all went well, or PCRE2_ERROR_NOMEMORY if the mem- + ory block could not be obtained. When the list is no longer needed, it should be freed by calling pcre2_substring_list_free(). If this function encounters a substring that is unset, which can happen - when capture group number n+1 matches some part of the subject, but - group n has not been used at all, it returns an empty string. This can + when capture group number n+1 matches some part of the subject, but + group n has not been used at all, it returns an empty string. This can be distinguished from a genuine zero-length substring by inspecting the - appropriate offset in the ovector, which contain PCRE2_UNSET for unset + appropriate offset in the ovector, which contain PCRE2_UNSET for unset substrings, or by calling pcre2_substring_length_bynumber(). @@ -3543,7 +3629,7 @@ EXTRACTING CAPTURED SUBSTRINGS BY NAME void pcre2_substring_free(PCRE2_UCHAR *buffer); - To extract a substring by name, you first have to find associated num- + To extract a substring by name, you first have to find associated num- ber. For example, for this pattern: (a+)b(?\d+)... @@ -3551,32 +3637,32 @@ EXTRACTING CAPTURED SUBSTRINGS BY NAME the number of the capture group called "xxx" is 2. If the name is known to be unique (PCRE2_DUPNAMES was not set), you can find the number from the name by calling pcre2_substring_number_from_name(). The first argu- - ment is the compiled pattern, and the second is the name. The yield of - the function is the group number, PCRE2_ERROR_NOSUBSTRING if there is - no group with that name, or PCRE2_ERROR_NOUNIQUESUBSTRING if there is - more than one group with that name. Given the number, you can extract - the substring directly from the ovector, or use one of the "bynumber" + ment is the compiled pattern, and the second is the name. The yield of + the function is the group number, PCRE2_ERROR_NOSUBSTRING if there is + no group with that name, or PCRE2_ERROR_NOUNIQUESUBSTRING if there is + more than one group with that name. Given the number, you can extract + the substring directly from the ovector, or use one of the "bynumber" functions described above. - For convenience, there are also "byname" functions that correspond to + For convenience, there are also "byname" functions that correspond to the "bynumber" functions, the only difference being that the second ar- - gument is a name instead of a number. If PCRE2_DUPNAMES is set and + gument is a name instead of a number. If PCRE2_DUPNAMES is set and there are duplicate names, these functions scan all the groups with the - given name, and return the captured substring from the first named + given name, and return the captured substring from the first named group that is set. - If there are no groups with the given name, PCRE2_ERROR_NOSUBSTRING is - returned. If all groups with the name have numbers that are greater + If there are no groups with the given name, PCRE2_ERROR_NOSUBSTRING is + returned. If all groups with the name have numbers that are greater than the number of slots in the ovector, PCRE2_ERROR_UNAVAILABLE is re- - turned. If there is at least one group with a slot in the ovector, but + turned. If there is at least one group with a slot in the ovector, but no group is found to be set, PCRE2_ERROR_UNSET is returned. Warning: If the pattern uses the (?| feature to set up multiple capture - groups with the same number, as described in the section on duplicate + groups with the same number, as described in the section on duplicate group numbers in the pcre2pattern page, you cannot use names to distin- - guish the different capture groups, because names are not included in - the compiled code. The matching process uses only numbers. For this - reason, the use of different names for groups with the same number + guish the different capture groups, because names are not included in + the compiled code. The matching process uses only numbers. For this + reason, the use of different names for groups with the same number causes an error at compile time. @@ -3589,30 +3675,32 @@ CREATING A NEW STRING WITH SUBSTITUTIONS PCRE2_SIZE rlength, PCRE2_UCHAR *outputbuffer, PCRE2_SIZE *outlengthptr); - This function optionally calls pcre2_match() and then makes a copy of - the subject string in outputbuffer, replacing parts that were matched + This function optionally calls pcre2_match() and then makes a copy of + the subject string in outputbuffer, replacing parts that were matched with the replacement string, whose length is supplied in rlength, which - can be given as PCRE2_ZERO_TERMINATED for a zero-terminated string. As - a special case, if replacement is NULL and rlength is zero, the re- - placement is assumed to be an empty string. If rlength is non-zero, an + can be given as PCRE2_ZERO_TERMINATED for a zero-terminated string. As + a special case, if replacement is NULL and rlength is zero, the re- + placement is assumed to be an empty string. If rlength is non-zero, an error occurs if replacement is NULL. There is an option (see PCRE2_SUBSTITUTE_REPLACEMENT_ONLY below) to re- - turn just the replacement string(s). The default action is to perform - just one replacement if the pattern matches, but there is an option - that requests multiple replacements (see PCRE2_SUBSTITUTE_GLOBAL be- + turn just the replacement string(s). The default action is to perform + just one replacement if the pattern matches, but there is an option + that requests multiple replacements (see PCRE2_SUBSTITUTE_GLOBAL be- low). - If successful, pcre2_substitute() returns the number of substitutions - that were carried out. This may be zero if no match was found, and is - never greater than one unless PCRE2_SUBSTITUTE_GLOBAL is set. A nega- + If successful, pcre2_substitute() returns the number of substitutions + that were carried out. This may be zero if no match was found, and is + never greater than one unless PCRE2_SUBSTITUTE_GLOBAL is set. A nega- tive value is returned if an error is detected. - Matches in which a \K item in a lookahead in the pattern causes the - match to end before it starts are not supported, and give rise to an + Matches in which a \K item in a lookahead in the pattern causes the + match to end before it starts are not supported, and give rise to an error return. For global replacements, matches in which \K in a lookbe- - hind causes the match to start earlier than the point that was reached - in the previous iteration are also not supported. + hind causes the match to start earlier than the point that was reached + in the previous iteration are also not supported. (These cases are only + possible if the pattern was compiled with the backwards-compatibility + option PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK.) The first seven arguments of pcre2_substitute() are the same as for pcre2_match(), except that the partial matching options are not permit- @@ -3623,79 +3711,102 @@ CREATING A NEW STRING WITH SUBSTITUTIONS If match_data is not NULL and PCRE2_SUBSTITUTE_MATCHED is not set, the provided block is used for all calls to pcre2_match(), and its contents - afterwards are the result of the final call. For global changes, this + afterwards are the result of the final call made internally by + pcre2_substitute() to the matching function. For global changes, this will always be a no-match error. The contents of the ovector within the match data block may or may not have been changed. - As well as the usual options for pcre2_match(), a number of additional - options can be set in the options argument of pcre2_substitute(). One - such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external - match_data block must be provided, and it must have already been used - for an external call to pcre2_match() with the same pattern and subject - arguments. The data in the match_data block (return code, offset vec- - tor) is then used for the first substitution instead of calling - pcre2_match() from within pcre2_substitute(). This allows an applica- - tion to check for a match before choosing to substitute, without having - to repeat the match. + As well as the usual options for pcre2_match(), a number of additional + options can be set in the options argument of pcre2_substitute(). One + such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external + match_data block must be provided, and it must have already been used + for an external call to pcre2_match() (or pcre2_jit_match()) with the + same pattern, subject pointer, effective subject length, start offset, + and match option arguments (substitute-specific options can be added to + the options argument). If any of these parameters is changed, + pcre2_substitute() returns an error. The data in the match_data block + (return code, offset vector) is used for the first substitution instead + of calling pcre2_match() from within pcre2_substitute(). This allows an + application to check for a match before choosing to substitute, without + having to repeat the match. + + If the contents of the subject buffer are mutated in between + pcre2_match() and a call to pcre2_substitute() with PCRE2_SUBSTI- + TUTE_MATCHED, the behaviour is unsafe; in particular, in this case, + PCRE2 is unable to ensure that the offsets in the ovector point to the + start of characters (with UTF-encoded input). The contents of the externally supplied match data block are not - changed when PCRE2_SUBSTITUTE_MATCHED is set. If PCRE2_SUBSTI- - TUTE_GLOBAL is also set, pcre2_match() is called after the first sub- - stitution to check for further matches, but this is done using an in- - ternally obtained match data block, thus always leaving the external - block unchanged. - - The code argument is not used for matching before the first substitu- - tion when PCRE2_SUBSTITUTE_MATCHED is set, but it must be provided, - even when PCRE2_SUBSTITUTE_GLOBAL is not set, because it contains in- + changed when PCRE2_SUBSTITUTE_MATCHED is set, and so the match block is + permitted for use in another call using PCRE2_SUBSTITUTE_MATCHED. If + PCRE2_SUBSTITUTE_GLOBAL is also set, pcre2_match() is called after the + first substitution to check for furthe matches, but this is done using + an internally obtained match data block, thus always leaving the exter- + nal block unchanged. + + The code argument is not used for matching before the first substitu- + tion when PCRE2_SUBSTITUTE_MATCHED is set, but it must be provided, + even when PCRE2_SUBSTITUTE_GLOBAL is not set, because it contains in- formation such as the UTF setting and the number of capturing parenthe- ses in the pattern. - The default action of pcre2_substitute() is to return a copy of the + When using PCRE2_SUBSTITUTE_MATCHED, you should not modify the subject + string in between the prior call to pcre2_match() and pcre2_substi- + tute(), as the substitution assumes that the passed-in ovector is com- + patible with the subject string. Although PCRE2 does verify that the + subject is a pointer to the same buffer, it cannot in general verify + whether the contents of the buffer have changed. For example, if the + subject buffer is mutated from one valid UTF-8 string to another valid + string, of the same length in code units, the ovector offsets are no + longer guaranteed to point to the start of a character. Beware that + with PCRE2_SUBSTITUTE_MATCHED in UTF mode, the subject string is not + re-scanned for UTF validity when pcre2_substitute() first uses it. + + The default action of pcre2_substitute() is to return a copy of the subject string with matched substrings replaced. However, if PCRE2_SUB- - STITUTE_REPLACEMENT_ONLY is set, only the replacement substrings are + STITUTE_REPLACEMENT_ONLY is set, only the replacement substrings are returned. In the global case, multiple replacements are concatenated in - the output buffer. Substitution callouts (see below) can be used to + the output buffer. Substitution callouts (see below) can be used to separate them if necessary. - The outlengthptr argument of pcre2_substitute() must point to a vari- - able that contains the length, in code units, of the output buffer. If - the function is successful, the value is updated to contain the length - in code units of the new string, excluding the trailing zero that is + The outlengthptr argument of pcre2_substitute() must point to a vari- + able that contains the length, in code units, of the output buffer. If + the function is successful, the value is updated to contain the length + in code units of the new string, excluding the trailing zero that is automatically added. - If the function is not successful, the value set via outlengthptr de- - pends on the type of error. For syntax errors in the replacement + If the function is not successful, the value set via outlengthptr de- + pends on the type of error. For syntax errors in the replacement string, the value is the offset in the replacement string where the er- - ror was detected. For other errors, the value is PCRE2_UNSET by de- + ror was detected. For other errors, the value is PCRE2_UNSET by de- fault. This includes the case of the output buffer being too small, un- less PCRE2_SUBSTITUTE_OVERFLOW_LENGTH is set. - PCRE2_SUBSTITUTE_OVERFLOW_LENGTH changes what happens when the output + PCRE2_SUBSTITUTE_OVERFLOW_LENGTH changes what happens when the output buffer is too small. The default action is to return PCRE2_ERROR_NOMEM- - ORY immediately. If this option is set, however, pcre2_substitute() + ORY immediately. If this option is set, however, pcre2_substitute() continues to go through the motions of matching and substituting (with- - out, of course, writing anything) in order to compute the size of - buffer that is needed, which will include the extra space for the ter- - minating NUL. This value is passed back via the outlengthptr variable, + out, of course, writing anything) in order to compute the size of + buffer that is needed, which will include the extra space for the ter- + minating NUL. This value is passed back via the outlengthptr variable, with the result of the function still being PCRE2_ERROR_NOMEMORY. - Passing a buffer size of zero is a permitted way of finding out how - much memory is needed for given substitution. However, this does mean + Passing a buffer size of zero is a permitted way of finding out how + much memory is needed for given substitution. However, this does mean that the entire operation is carried out twice. Depending on the appli- - cation, it may be more efficient to allocate a large buffer and free - the excess afterwards, instead of using PCRE2_SUBSTITUTE_OVER- + cation, it may be more efficient to allocate a large buffer and free + the excess afterwards, instead of using PCRE2_SUBSTITUTE_OVER- FLOW_LENGTH. - The replacement string, which is interpreted as a UTF string in UTF - mode, is checked for UTF validity unless PCRE2_NO_UTF_CHECK is set. An + The replacement string, which is interpreted as a UTF string in UTF + mode, is checked for UTF validity unless PCRE2_NO_UTF_CHECK is set. An invalid UTF replacement string causes an immediate return with the rel- evant UTF error code. - If PCRE2_SUBSTITUTE_LITERAL is set, the replacement string is not in- + If PCRE2_SUBSTITUTE_LITERAL is set, the replacement string is not in- terpreted in any way. By default, however, a dollar character is an es- - cape character that can specify the insertion of characters from cap- - ture groups and names from (*MARK) or other control verbs in the pat- + cape character that can specify the insertion of characters from cap- + ture groups and names from (*MARK) or other control verbs in the pat- tern. Dollar is the only escape character (backslash is treated as lit- eral). The following forms are recognized: @@ -3705,6 +3816,8 @@ CREATING A NEW STRING WITH SUBSTITUTIONS $` insert the substring that precedes the match $' insert the substring that follows the match $_ insert the entire input string + $+ insert the highest-numbered capture group which + matched $*MARK or ${*MARK} insert a control verb name Either a group number or a group name can be given for n, for example @@ -3738,6 +3851,18 @@ CREATING A NEW STRING WITH SUBSTITUTIONS subject string. If an offset limit is set in the match context, search- ing stops when that limit is reached. + Because global substitutions apply the pattern repeatedly to the sub- + ject string, and always iterate over non-overlapping matches, the sub- + stitutions done by pcre2_substitute() do not match and substitute text + inside the replacement strings themselves (no recursive/iterative sub- + stitution). However, applications can easily implement other alterna- + tive replacement strategies, such as iteratively replacing, then match- + ing and replacing on the result. The replacement loop inside pcre2_sub- + stitute() is simple and can be emulated in client code by allocating a + buffer, searching for matches in a loop, and calling pcre2_substitute() + with PCRE2_SUBSTITUTE_REPLACEMENT_ONLY an PCRE2_SUBSTITUTE_MATCHED, and + without PCRE2_SUBSTITUTE_GLOBAL. + You can restrict the effect of a global substitution to a portion of the subject string by setting either or both of startoffset and an off- set limit. Here is a pcre2test example: @@ -3782,59 +3907,59 @@ CREATING A NEW STRING WITH SUBSTITUTIONS given in the pcre2pattern page. The Python form \g, where the angle brackets are part of the syntax - and n is either a group name or number, is recognized as an altertive + and n is either a group name or number, is recognized as an alternative way of inserting the contents of a group, for example \g<3>. - There are also four escape sequences for forcing the case of inserted - letters. Case forcing applies to all inserted characters, including - those from capture groups and letters within \Q...\E quoted sequences. - The insertion mechanism has three states: no case forcing, force upper - case, and force lower case. The escape sequences change the current - state: \U and \L change to upper or lower case forcing, respectively, - and \E (when not terminating a \Q quoted sequence) reverts to no case - forcing. The sequences \u and \l force the next character (if it is a - letter) to upper or lower case, respectively, and then the state auto- + There are also four escape sequences for forcing the case of inserted + letters. Case forcing applies to all inserted characters, including + those from capture groups and letters within \Q...\E quoted sequences. + The insertion mechanism has three states: no case forcing, force upper + case, and force lower case. The escape sequences change the current + state: \U and \L change to upper or lower case forcing, respectively, + and \E (when not terminating a \Q quoted sequence) reverts to no case + forcing. The sequences \u and \l force the next character (if it is a + letter) to upper or lower case, respectively, and then the state auto- matically reverts to no case forcing. - However, if \u is immediately followed by \L or \l is immediately fol- - lowed by \U, the next character's case is forced by the first escape + However, if \u is immediately followed by \L or \l is immediately fol- + lowed by \U, the next character's case is forced by the first escape sequence, and subsequent characters by the second. This provides a "ti- - tle casing" facility that can be applied to group captures. For exam- - ple, if group 1 has captured "heLLo", the replacement string "\u\L$1" + tle casing" facility that can be applied to group captures. For exam- + ple, if group 1 has captured "heLLo", the replacement string "\u\L$1" becomes "Hello". If either PCRE2_UTF or PCRE2_UCP was set when the pattern was compiled, - Unicode properties are used for case forcing characters whose code - points are greater than 127. However, only simple case folding, as de- - termined by the Unicode file CaseFolding.txt is supported. PCRE2 does - not support language-specific special casing rules such as using dif- - ferent lower case Greek sigmas in the middle and ends of words (as de- + Unicode properties are used for case forcing characters whose code + points are greater than 127. However, only simple case folding, as de- + termined by the Unicode file CaseFolding.txt is supported. PCRE2 does + not support language-specific special casing rules such as using dif- + ferent lower case Greek sigmas in the middle and ends of words (as de- fined in the Unicode file SpecialCasing.txt). Note that case forcing sequences such as \U...\E do not nest. For exam- - ple, the result of processing "\Uaa\LBB\Ecc\E" is "AAbbcc"; the final - \E has no effect. Note also that the PCRE2_ALT_BSUX and PCRE2_EX- + ple, the result of processing "\Uaa\LBB\Ecc\E" is "AAbbcc"; the final + \E has no effect. Note also that the PCRE2_ALT_BSUX and PCRE2_EX- TRA_ALT_BSUX options do not apply to replacement strings. - The final effect of setting PCRE2_SUBSTITUTE_EXTENDED is to add more - flexibility to capture group substitution. The syntax is similar to + The final effect of setting PCRE2_SUBSTITUTE_EXTENDED is to add more + flexibility to capture group substitution. The syntax is similar to that used by Bash: ${n:-string} ${n:+string1:string2} - As in the simple case, n may be a group number or a name. The first - form specifies a default value. If group n is set, its value is in- - serted; if not, the string is expanded and the result inserted. The + As in the simple case, n may be a group number or a name. The first + form specifies a default value. If group n is set, its value is in- + serted; if not, the string is expanded and the result inserted. The second form specifies strings that are expanded and inserted when group - n is set or unset, respectively. The first form is just a convenient + n is set or unset, respectively. The first form is just a convenient shorthand for ${n:+${n}:string} - Backslash can be used to escape colons and closing curly brackets in - the replacement strings. A change of the case forcing state within a - replacement string remains in force afterwards, as shown in this + Backslash can be used to escape colons and closing curly brackets in + the replacement strings. A change of the case forcing state within a + replacement string remains in force afterwards, as shown in this pcre2test example: /(some)?(body)/substitute_extended,replace=${1:+\U:\L}HeLLo @@ -3843,8 +3968,8 @@ CREATING A NEW STRING WITH SUBSTITUTIONS somebody 1: HELLO - The PCRE2_SUBSTITUTE_UNSET_EMPTY option does not affect these extended - substitutions. However, PCRE2_SUBSTITUTE_UNKNOWN_UNSET does cause un- + The PCRE2_SUBSTITUTE_UNSET_EMPTY option does not affect these extended + substitutions. However, PCRE2_SUBSTITUTE_UNKNOWN_UNSET does cause un- known groups in the extended syntax forms to be treated as unset. If PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_UNKNOWN_UNSET, @@ -3853,39 +3978,39 @@ CREATING A NEW STRING WITH SUBSTITUTIONS Substitution errors - In the event of an error, pcre2_substitute() returns a negative error - code. Except for PCRE2_ERROR_NOMATCH (which is never returned), errors + In the event of an error, pcre2_substitute() returns a negative error + code. Except for PCRE2_ERROR_NOMATCH (which is never returned), errors from pcre2_match() are passed straight back. PCRE2_ERROR_NOSUBSTRING is returned for a non-existent substring inser- tion, unless PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set. PCRE2_ERROR_UNSET is returned for an unset substring insertion (includ- - ing an unknown substring when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) - when the simple (non-extended) syntax is used and PCRE2_SUBSTITUTE_UN- + ing an unknown substring when PCRE2_SUBSTITUTE_UNKNOWN_UNSET is set) + when the simple (non-extended) syntax is used and PCRE2_SUBSTITUTE_UN- SET_EMPTY is not set. - PCRE2_ERROR_NOMEMORY is returned if the output buffer is not big + PCRE2_ERROR_NOMEMORY is returned if the output buffer is not big enough. If the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option is set, the size - of buffer that is needed is returned via outlengthptr. Note that this + of buffer that is needed is returned via outlengthptr. Note that this does not happen by default. PCRE2_ERROR_NULL is returned if PCRE2_SUBSTITUTE_MATCHED is set but the - match_data argument is NULL or if the subject or replacement arguments - are NULL. For backward compatibility reasons an exception is made for + match_data argument is NULL or if the subject or replacement arguments + are NULL. For backward compatibility reasons an exception is made for the replacement argument if the rlength argument is also 0. - PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in - the replacement string, with more particular errors being PCRE2_ER- + PCRE2_ERROR_BADREPLACEMENT is used for miscellaneous syntax errors in + the replacement string, with more particular errors being PCRE2_ER- ROR_BADREPESCAPE (invalid escape sequence), PCRE2_ERROR_REPMISSINGBRACE - (closing curly bracket not found), PCRE2_ERROR_BADSUBSTITUTION (syntax - error in extended group substitution), and PCRE2_ERROR_BADSUBSPATTERN + (closing curly bracket not found), PCRE2_ERROR_BADSUBSTITUTION (syntax + error in extended group substitution), and PCRE2_ERROR_BADSUBSPATTERN (the pattern match ended before it started or the match started earlier - than the current position in the subject, which can happen if \K is - used in an assertion). + than the current position in the subject, which can happen if \K is + used in a lookaround assertion). As for all PCRE2 errors, a text message that describes the error can be - obtained by calling the pcre2_get_error_message() function (see "Ob- + obtained by calling the pcre2_get_error_message() function (see "Ob- taining a textual error message" above). Substitution callouts @@ -3894,23 +4019,23 @@ CREATING A NEW STRING WITH SUBSTITUTIONS int (*callout_function)(pcre2_substitute_callout_block *, void *), void *callout_data); - The pcre2_set_substitution_callout() function can be used to specify a - callout function for pcre2_substitute(). This information is passed in + The pcre2_set_substitute_callout() function can be used to specify a + callout function for pcre2_substitute(). This information is passed in a match context. The callout function is called after each substitution has been processed, but it can cause the replacement not to happen. - The callout function is not called for simulated substitutions that - happen as a result of the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option. In - this mode, when substitution processing exceeds the buffer space pro- - vided by the caller, processing continues by counting code units. The - simulation is unable to populate the callout block, and so the simula- + The callout function is not called for simulated substitutions that + happen as a result of the PCRE2_SUBSTITUTE_OVERFLOW_LENGTH option. In + this mode, when substitution processing exceeds the buffer space pro- + vided by the caller, processing continues by counting code units. The + simulation is unable to populate the callout block, and so the simula- tion is pessimistic about the required buffer size. Whichever is larger - of accepted or rejected substitution is reported as the required size. + of accepted or rejected substitution is reported as the required size. Therefore, the returned buffer length may be an overestimate (without a substitution callout, it is normally an exact measurement). The first argument of the callout function is a pointer to a substitute - callout block structure, which contains the following fields, not nec- + callout block structure, which contains the following fields, not nec- essarily in this order: uint32_t version; @@ -3921,34 +4046,34 @@ CREATING A NEW STRING WITH SUBSTITUTIONS uint32_t oveccount; PCRE2_SIZE output_offsets[2]; - The version field contains the version number of the block format. The - current version is 0. The version number will increase in future if - more fields are added, but the intention is never to remove any of the + The version field contains the version number of the block format. The + current version is 0. The version number will increase in future if + more fields are added, but the intention is never to remove any of the existing fields. The subscount field is the number of the current match. It is 1 for the first callout, 2 for the second, and so on. The input and output point- ers are copies of the values passed to pcre2_substitute(). - The ovector field points to the ovector, which contains the result of + The ovector field points to the ovector, which contains the result of the most recent match. The oveccount field contains the number of pairs that are set in the ovector, and is always greater than zero. - The output_offsets vector contains the offsets of the replacement in - the output string. This has already been processed for dollar and (if + The output_offsets vector contains the offsets of the replacement in + the output string. This has already been processed for dollar and (if requested) backslash substitutions as described above. - The second argument of the callout function is the value passed as - callout_data when the function was registered. The value returned by + The second argument of the callout function is the value passed as + callout_data when the function was registered. The value returned by the callout function is interpreted as follows: - If the value is zero, the replacement is accepted, and, if PCRE2_SUB- - STITUTE_GLOBAL is set, processing continues with a search for the next - match. If the value is not zero, the current replacement is not ac- - cepted. If the value is greater than zero, processing continues when - PCRE2_SUBSTITUTE_GLOBAL is set. Otherwise (the value is less than zero + If the value is zero, the replacement is accepted, and, if PCRE2_SUB- + STITUTE_GLOBAL is set, processing continues with a search for the next + match. If the value is not zero, the current replacement is not ac- + cepted. If the value is greater than zero, processing continues when + PCRE2_SUBSTITUTE_GLOBAL is set. Otherwise (the value is less than zero or PCRE2_SUBSTITUTE_GLOBAL is not set), the rest of the input is copied - to the output and the call to pcre2_substitute() exits, returning the + to the output and the call to pcre2_substitute() exits, returning the number of matches so far. Substitution case callouts @@ -3959,11 +4084,11 @@ CREATING A NEW STRING WITH SUBSTITUTIONS int, void *), void *callout_data); - The pcre2_set_substitution_case_callout() function can be used to spec- - ify a callout function for pcre2_substitute() to use when performing - case transformations. This does not affect any case insensitivity be- - haviour when performing a match, but only the user-visible transforma- - tions performed when processing a substitution such as: + The pcre2_set_substitute_case_callout() function can be used to specify + a callout function for pcre2_substitute() to use when performing case + transformations. This does not affect any case insensitivity behaviour + when performing a match, but only the user-visible transformations per- + formed when processing a substitution such as: pcre2_substitute(..., "\\U$1", ...) @@ -4293,11 +4418,11 @@ AUTHOR REVISION - Last updated: 26 December 2024 + Last updated: 19 October 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 26 December 2024 PCRE2API(3) +PCRE2 10.47 19 October 2025 PCRE2API(3) ------------------------------------------------------------------------------ @@ -4311,43 +4436,43 @@ NAME BUILDING PCRE2 PCRE2 is distributed with a configure script that can be used to build - the library in Unix-like environments using the applications known as - Autotools. Also in the distribution are files to support building using - CMake instead of configure. The text file README contains general in- - formation about building with Autotools (some of which is repeated be- - low), and also has some comments about building on various operating - systems. The files in the vms directory support building under OpenVMS. - There is a lot more information about building PCRE2 without using Au- - totools (including information about using CMake and building "by - hand") in the text file called NON-AUTOTOOLS-BUILD. You should consult - this file as well as the README file if you are building in a non-Unix- - like environment. + the library in Unix-like environments using the Autotools applications. + Also in the distribution are files to support building using CMake in- + stead of configure. The text file README contains general information + about building with Autotools (some of which is repeated below), and + also has some comments about building on various operating systems. The + files in the vms directory support building under OpenVMS. There is a + lot more information about building PCRE2 without using Autotools (in- + cluding information about using CMake and building "by hand") in the + text file called NON-AUTOTOOLS-BUILD. You should consult this file as + well as the README file if you are building in a non-Unix-like environ- + ment. PCRE2 BUILD-TIME OPTIONS The rest of this document describes the optional features of PCRE2 that - can be selected when the library is compiled. It assumes use of the - configure script, where the optional features are selected or dese- - lected by providing options to configure before running the make com- - mand. However, the same options can be selected in both Unix-like and - non-Unix-like environments if you are using CMake instead of configure + can be selected when the library is compiled. It assumes use of the + configure script, where the optional features are selected or dese- + lected by providing options to configure before running the make com- + mand. However, the same options can be selected in both Unix-like and + non-Unix-like environments if you are using CMake instead of configure to build PCRE2. - If you are not using Autotools or CMake, option selection can be done - by editing the config.h file, or by passing parameter settings to the + If you are not using Autotools or CMake, option selection can be done + by editing the config.h file, or by passing parameter settings to the compiler, as described in NON-AUTOTOOLS-BUILD. The complete list of options for configure (which includes the standard - ones such as the selection of the installation directory) can be ob- + ones such as the selection of the installation directory) can be ob- tained by running ./configure --help - The following sections include descriptions of "on/off" options whose + The following sections include descriptions of "on/off" options whose names begin with --enable or --disable. Because of the way that config- - ure works, --enable and --disable always come in pairs, so the comple- - mentary option always exists as well, but as it specifies the default, + ure works, --enable and --disable always come in pairs, so the comple- + mentary option always exists as well, but as it specifies the default, it is not described. Options that specify values have names that start with --with. At the end of a configure run, a summary of the configura- tion is output. @@ -4355,13 +4480,13 @@ PCRE2 BUILD-TIME OPTIONS BUILDING 8-BIT, 16-BIT AND 32-BIT LIBRARIES - By default, a library called libpcre2-8 is built, containing functions - that take string arguments contained in arrays of bytes, interpreted - either as single-byte characters, or UTF-8 strings. You can also build - two other libraries, called libpcre2-16 and libpcre2-32, which process - strings that are contained in arrays of 16-bit and 32-bit code units, + By default, a library called libpcre2-8 is built, containing functions + that take string arguments contained in arrays of bytes, interpreted + either as single-byte characters, or UTF-8 strings. You can also build + two other libraries, called libpcre2-16 and libpcre2-32, which process + strings that are contained in arrays of 16-bit and 32-bit code units, respectively. These can be interpreted either as single-unit characters - or UTF-16/UTF-32 strings. To build these additional libraries, add one + or UTF-16/UTF-32 strings. To build these additional libraries, add one or both of the following to the configure command: --enable-pcre2-16 @@ -4371,71 +4496,71 @@ BUILDING 8-BIT, 16-BIT AND 32-BIT LIBRARIES --disable-pcre2-8 - as well. At least one of the three libraries must be built. Note that - the POSIX wrapper is for the 8-bit library only, and that pcre2grep is - an 8-bit program. Neither of these are built if you select only the + as well. At least one of the three libraries must be built. Note that + the POSIX wrapper is for the 8-bit library only, and that pcre2grep is + an 8-bit program. Neither of these are built if you select only the 16-bit or 32-bit libraries. BUILDING SHARED AND STATIC LIBRARIES - The Autotools PCRE2 building process uses libtool to build both shared - and static libraries by default. You can suppress an unwanted library + The Autotools PCRE2 building process uses libtool to build both shared + and static libraries by default. You can suppress an unwanted library by adding one of --disable-shared --disable-static - to the configure command. Setting --disable-shared ensures that PCRE2 - libraries are built as static libraries. The binaries that are then - created as part of the build process (for example, pcre2test and - pcre2grep) are linked statically with one or more PCRE2 libraries, but - may also be dynamically linked with other libraries such as libc. If - you want these binaries to be fully statically linked, you can set LD- + to the configure command. Setting --disable-shared ensures that PCRE2 + libraries are built as static libraries. The binaries that are then + created as part of the build process (for example, pcre2test and + pcre2grep) are linked statically with one or more PCRE2 libraries, but + may also be dynamically linked with other libraries such as libc. If + you want these binaries to be fully statically linked, you can set LD- FLAGS like this: LDFLAGS=--static ./configure --disable-shared - Note the two hyphens in --static. Of course, this works only if static + Note the two hyphens in --static. Of course, this works only if static versions of all the relevant libraries are available for linking. UNICODE AND UTF SUPPORT - By default, PCRE2 is built with support for Unicode and UTF character + By default, PCRE2 is built with support for Unicode and UTF character strings. To build it without Unicode support, add --disable-unicode - to the configure command. This setting applies to all three libraries. - It is not possible to build one library with Unicode support and an- + to the configure command. This setting applies to all three libraries. + It is not possible to build one library with Unicode support and an- other without in the same configuration. - Of itself, Unicode support does not make PCRE2 treat strings as UTF-8, + Of itself, Unicode support does not make PCRE2 treat strings as UTF-8, UTF-16 or UTF-32. To do that, applications that use the library can set - the PCRE2_UTF option when they call pcre2_compile() to compile a pat- - tern. Alternatively, patterns may be started with (*UTF) unless the + the PCRE2_UTF option when they call pcre2_compile() to compile a pat- + tern. Alternatively, patterns may be started with (*UTF) unless the application has locked this out by setting PCRE2_NEVER_UTF. UTF support allows the libraries to process character code points up to - 0x10ffff in the strings that they handle. Unicode support also gives - access to the Unicode properties of characters, using pattern escapes + 0x10ffff in the strings that they handle. Unicode support also gives + access to the Unicode properties of characters, using pattern escapes such as \P, \p, and \X. Only the general category properties such as Lu - and Nd, script names, and some bi-directional properties are supported. - Details are given in the pcre2pattern documentation. + and Nd, script names, and some bi-directional and binary properties are + supported. Details are given in the pcre2pattern documentation. Pattern escapes such as \d and \w do not by default make use of Unicode - properties. The application can request that they do by setting the - PCRE2_UCP option. Unless the application has set PCRE2_NEVER_UCP, a + properties. The application can request that they do by setting the + PCRE2_UCP option. Unless the application has set PCRE2_NEVER_UCP, a pattern may also request this by starting with (*UCP). DISABLING THE USE OF \C The \C escape sequence, which matches a single code unit, even in a UTF - mode, can cause unpredictable behaviour because it may leave the cur- - rent matching point in the middle of a multi-code-unit character. The - application can lock it out by setting the PCRE2_NEVER_BACKSLASH_C op- + mode, can cause unpredictable behaviour because it may leave the cur- + rent matching point in the middle of a multi-code-unit character. The + application can lock it out by setting the PCRE2_NEVER_BACKSLASH_C op- tion when calling pcre2_compile(). There is also a build-time option --enable-never-backslash-C @@ -4445,27 +4570,27 @@ DISABLING THE USE OF \C JUST-IN-TIME COMPILER SUPPORT - Just-in-time (JIT) compiler support is included in the build by speci- + Just-in-time (JIT) compiler support is included in the build by speci- fying --enable-jit - This support is available only for certain hardware architectures. If - this option is set for an unsupported architecture, a building error + This support is available only for certain hardware architectures. If + this option is set for an unsupported architecture, a building error occurs. If in doubt, use --enable-jit=auto - which enables JIT only if the current hardware is supported. You can - check if JIT is enabled in the configuration summary that is output at - the end of a configure run. If you are enabling JIT under SELinux you + which enables JIT only if the current hardware is supported. You can + check if JIT is enabled in the configuration summary that is output at + the end of a configure run. If you are enabling JIT under SELinux you may also want to add --enable-jit-sealloc which enables the use of an execmem allocator in JIT that is compatible - with SELinux. This has no effect if JIT is not enabled. See the - pcre2jit documentation for a discussion of JIT usage. When JIT support + with SELinux. This has no effect if JIT is not enabled. See the + pcre2jit documentation for a discussion of JIT usage. When JIT support is enabled, pcre2grep automatically makes use of it, unless you add --disable-pcre2grep-jit @@ -4475,14 +4600,14 @@ JUST-IN-TIME COMPILER SUPPORT NEWLINE RECOGNITION - By default, PCRE2 interprets the linefeed (LF) character as indicating - the end of a line. This is the normal newline character on Unix-like - systems. You can compile PCRE2 to use carriage return (CR) instead, by + By default, PCRE2 interprets the linefeed (LF) character as indicating + the end of a line. This is the normal newline character on Unix-like + systems. You can compile PCRE2 to use carriage return (CR) instead, by adding --enable-newline-is-cr - to the configure command. There is also an --enable-newline-is-lf op- + to the configure command. There is also an --enable-newline-is-lf op- tion, which explicitly specifies linefeed as the newline character. Alternatively, you can specify that line endings are to be indicated by @@ -4495,126 +4620,126 @@ NEWLINE RECOGNITION --enable-newline-is-anycrlf - which causes PCRE2 to recognize any of the three sequences CR, LF, or + which causes PCRE2 to recognize any of the three sequences CR, LF, or CRLF as indicating a line ending. A fifth option, specified by --enable-newline-is-any - causes PCRE2 to recognize any Unicode newline sequence. The Unicode + causes PCRE2 to recognize any Unicode newline sequence. The Unicode newline sequences are the three just mentioned, plus the single charac- ters VT (vertical tab, U+000B), FF (form feed, U+000C), NEL (next line, - U+0085), LS (line separator, U+2028), and PS (paragraph separator, + U+0085), LS (line separator, U+2028), and PS (paragraph separator, U+2029). The final option is --enable-newline-is-nul - which causes NUL (binary zero) to be set as the default line-ending + which causes NUL (binary zero) to be set as the default line-ending character. Whatever default line ending convention is selected when PCRE2 is built - can be overridden by applications that use the library. At build time + can be overridden by applications that use the library. At build time it is recommended to use the standard for your operating system. WHAT \R MATCHES - By default, the sequence \R in a pattern matches any Unicode newline - sequence, independently of what has been selected as the line ending + By default, the sequence \R in a pattern matches any Unicode newline + sequence, independently of what has been selected as the line ending sequence. If you specify --enable-bsr-anycrlf - the default is changed so that \R matches only CR, LF, or CRLF. What- - ever is selected when PCRE2 is built can be overridden by applications + the default is changed so that \R matches only CR, LF, or CRLF. What- + ever is selected when PCRE2 is built can be overridden by applications that use the library. HANDLING VERY LARGE PATTERNS - Within a compiled pattern, offset values are used to point from one - part to another (for example, from an opening parenthesis to an alter- - nation metacharacter). By default, in the 8-bit and 16-bit libraries, - two-byte values are used for these offsets, leading to a maximum size + Within a compiled pattern, offset values are used to point from one + part to another (for example, from an opening parenthesis to an alter- + nation metacharacter). By default, in the 8-bit and 16-bit libraries, + two-byte values are used for these offsets, leading to a maximum size for a compiled pattern of around 64 thousand code units. This is suffi- - cient to handle all but the most gigantic patterns. Nevertheless, some + cient to handle all but the most gigantic patterns. Nevertheless, some people do want to process truly enormous patterns, so it is possible to - compile PCRE2 to use three-byte or four-byte offsets by adding a set- + compile PCRE2 to use three-byte or four-byte offsets by adding a set- ting such as --with-link-size=3 - to the configure command. The value given must be 2, 3, or 4. For the - 16-bit library, a value of 3 is rounded up to 4. In these libraries, - using longer offsets slows down the operation of PCRE2 because it has - to load additional data when handling them. For the 32-bit library the - value is always 4 and cannot be overridden; the value of --with-link- + to the configure command. The value given must be 2, 3, or 4. For the + 16-bit library, a value of 3 is rounded up to 4. In these libraries, + using longer offsets slows down the operation of PCRE2 because it has + to load additional data when handling them. For the 32-bit library the + value is always 4 and cannot be overridden; the value of --with-link- size is ignored. LIMITING PCRE2 RESOURCE USAGE The pcre2_match() function increments a counter each time it goes round - its main loop. Putting a limit on this counter controls the amount of - computing resource used by a single call to pcre2_match(). The limit + its main loop. Putting a limit on this counter controls the amount of + computing resource used by a single call to pcre2_match(). The limit can be changed at run time, as described in the pcre2api documentation. - The default is 10 million, but this can be changed by adding a setting + The default is 10 million, but this can be changed by adding a setting such as --with-match-limit=500000 - to the configure command. This setting also applies to the - pcre2_dfa_match() matching function, and to JIT matching (though the + to the configure command. This setting also applies to the + pcre2_dfa_match() matching function, and to JIT matching (though the counting is done differently). - The pcre2_match() function uses heap memory to record backtracking - points. The more nested backtracking points there are (that is, the - deeper the search tree), the more memory is needed. There is an upper - limit, specified in kibibytes (units of 1024 bytes). This limit can be - changed at run time, as described in the pcre2api documentation. The - default limit (in effect unlimited) is 20 million. You can change this + The pcre2_match() function uses heap memory to record backtracking + points. The more nested backtracking points there are (that is, the + deeper the search tree), the more memory is needed. There is an upper + limit, specified in kibibytes (units of 1024 bytes). This limit can be + changed at run time, as described in the pcre2api documentation. The + default limit (in effect unlimited) is 20 million. You can change this by a setting such as --with-heap-limit=500 - which limits the amount of heap to 500 KiB. This limit applies only to + which limits the amount of heap to 500 KiB. This limit applies only to interpretive matching in pcre2_match() and pcre2_dfa_match(), which may - also use the heap for internal workspace when processing complicated - patterns. This limit does not apply when JIT (which has its own memory + also use the heap for internal workspace when processing complicated + patterns. This limit does not apply when JIT (which has its own memory arrangements) is used. - You can also explicitly limit the depth of nested backtracking in the + You can also explicitly limit the depth of nested backtracking in the pcre2_match() interpreter. This limit defaults to the value that is set - for --with-match-limit. You can set a lower default limit by adding, + for --with-match-limit. You can set a lower default limit by adding, for example, --with-match-limit-depth=10000 - to the configure command. This value can be overridden at run time. - This depth limit indirectly limits the amount of heap memory that is - used, but because the size of each backtracking "frame" depends on the - number of capturing parentheses in a pattern, the amount of heap that - is used before the limit is reached varies from pattern to pattern. + to the configure command. This value can be overridden at run time. + This depth limit indirectly limits the amount of heap memory that is + used, but because the size of each backtracking "frame" depends on the + number of capturing parentheses in a pattern, the amount of heap that + is used before the limit is reached varies from pattern to pattern. This limit was more useful in versions before 10.30, where function re- cursion was used for backtracking. As well as applying to pcre2_match(), the depth limit also controls the - depth of recursive function calls in pcre2_dfa_match(). These are used - for lookaround assertions, atomic groups, and recursion within pat- + depth of recursive function calls in pcre2_dfa_match(). These are used + for lookaround assertions, atomic groups, and recursion within pat- terns. The limit does not apply to JIT matching. LIMITING VARIABLE-LENGTH LOOKBEHIND ASSERTIONS - Lookbehind assertions in which one or more branches can match a vari- - able number of characters are supported only if there is a maximum - matching length for each top-level branch. There is a limit to this - maximum that defaults to 255 characters. You can alter this default by + Lookbehind assertions in which one or more branches can match a vari- + able number of characters are supported only if there is a maximum + matching length for each top-level branch. There is a limit to this + maximum that defaults to 255 characters. You can alter this default by a setting such as --with-max-varlookbehind=100 The limit can be changed at runtime by calling pcre2_set_max_varlookbe- - hind(). Lookbehind assertions in which every branch matches a fixed + hind(). Lookbehind assertions in which every branch matches a fixed number of characters (not necessarily all the same) are not constrained by this limit. @@ -4623,58 +4748,66 @@ CREATING CHARACTER TABLES AT BUILD TIME PCRE2 uses fixed tables for processing characters whose code points are less than 256. By default, PCRE2 is built with a set of tables that are - distributed in the file src/pcre2_chartables.c.dist. These tables are + distributed in the file src/pcre2_chartables.c.dist. These tables are for ASCII codes only. If you add --enable-rebuild-chartables - to the configure command, the distributed tables are no longer used. + to the configure command, the distributed tables are no longer used. Instead, a program called pcre2_dftables is compiled and run. This out- puts the source for new set of tables, created in the default locale of - your C run-time system. This method of replacing the tables does not + your C run-time system. This method of replacing the tables does not work if you are cross compiling, because pcre2_dftables needs to be run on the local host and therefore not compiled with the cross compiler. If you need to create alternative tables when cross compiling, you will - have to do so "by hand". There may also be other reasons for creating - tables manually. To cause pcre2_dftables to be built on the local + have to do so "by hand". There may also be other reasons for creating + tables manually. To cause pcre2_dftables to be built on the local host, run a normal compiling command, and then run the program with the output file as its argument, for example: cc src/pcre2_dftables.c -o pcre2_dftables ./pcre2_dftables src/pcre2_chartables.c - This builds the tables in the default locale of the local host. If you + This builds the tables in the default locale of the local host. If you want to specify a locale, you must use the -L option: LC_ALL=fr_FR ./pcre2_dftables -L src/pcre2_chartables.c You can also specify -b (with or without -L). This causes the tables to - be written in binary instead of as source code. A set of binary tables - can be loaded into memory by an application and passed to pcre2_com- + be written in binary instead of as source code. A set of binary tables + can be loaded into memory by an application and passed to pcre2_com- pile() in the same way as tables created by calling pcre2_maketables(). - The tables are just a string of bytes, independent of hardware charac- - teristics such as endianness. This means they can be bundled with an - application that runs in different environments, to ensure consistent + The tables are just a string of bytes, independent of hardware charac- + teristics such as endianness. This means they can be bundled with an + application that runs in different environments, to ensure consistent behaviour. USING EBCDIC CODE - PCRE2 assumes by default that it will run in an environment where the - character code is ASCII or Unicode, which is a superset of ASCII. This + PCRE2 assumes by default that it will run in an environment where the + character code is ASCII or Unicode, which is a superset of ASCII. This is the case for most computer operating systems. PCRE2 can, however, be compiled to run in an 8-bit EBCDIC environment by adding --enable-ebcdic --disable-unicode - to the configure command. This setting implies --enable-rebuild-charta- - bles. You should only use it if you know that you are in an EBCDIC en- - vironment (for example, an IBM mainframe operating system). + to the configure command. You should only use it if you know that you + are in an EBCDIC environment (for example, an IBM mainframe operating + system). + + This setting implies --enable-rebuild-chartables, in order to ensure + that you have the correct default character tables for your system's + codepage. There is an exception when you set --enable-ebcdic-ignoring- + compiler (see below), which allows using a default set of EBCDIC 1047 + character tables rather than forcing use of --enable-rebuild-charta- + bles. - It is not possible to support both EBCDIC and UTF-8 codes in the same - version of the library. Consequently, --enable-unicode and --enable- - ebcdic are mutually exclusive. + It is not supported to enable both EBCDIC input and either ASCII or + UTF-8/16/32 in the same build of the library. When PCRE2 is built with + EBCDIC support, it always operates in EBCDIC, and consequently --en- + able-unicode and --enable-ebcdic are mutually exclusive. The EBCDIC character that corresponds to an ASCII LF is assumed to have the value 0x15 by default. However, in some EBCDIC environments, 0x25 @@ -4682,15 +4815,28 @@ USING EBCDIC CODE --enable-ebcdic-nl25 - as well as, or instead of, --enable-ebcdic. The EBCDIC character for CR - has the same value as in ASCII, namely, 0x0d. Whichever of 0x15 and - 0x25 is not chosen as LF is made to correspond to the Unicode NEL char- - acter (which, in Unicode, is 0x85). + (which implies --enable-ebcdic). The EBCDIC character for CR has the + same value as in ASCII, namely, 0x0d. Whichever of 0x15 and 0x25 is not + chosen as LF is made to correspond to the Unicode NEL character (which, + in Unicode, is 0x85). The options that select newline behaviour, such as --enable-newline-is- cr, and equivalent run-time options, refer to these character values in an EBCDIC environment. + On systems requiring an EBCDIC build of PCRE2, the compiler should be + set to use the correct codepage, so that C character literals such as + 'z' use the correct numeric value for whichever EBCDIC codpage is in + use. (PCRE2 cannot support multiple EBCDIC codepages dynamically.) How- + ever, if this not possible, then you can use + + --enable-ebcdic-ignoring-compiler + + in order to disregard the compiler's codepage, and instead force PCRE2 + to use numeric constants corresponding to the EBCDIC 1047 codepage in- + stead. This can be used to build (or test) EBCDIC support on an + ASCII/UTF-8 system such as Linux. + PCRE2GREP SUPPORT FOR EXTERNAL SCRIPTS @@ -4768,7 +4914,7 @@ PCRE2TEST OPTION FOR LIBREADLINE SUPPORT If your environment has not been set up so that an appropriate library is automatically included, you may need to add something like - LIBS="-ncurses" + LIBS="-lncurses" immediately before the configure command. @@ -4919,11 +5065,11 @@ AUTHOR REVISION - Last updated: 16 April 2024 + Last updated: 17 October 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 16 April 2024 PCRE2BUILD(3) +PCRE2 10.47 17 October 2025 PCRE2BUILD(3) ------------------------------------------------------------------------------ @@ -5352,11 +5498,11 @@ AUTHOR REVISION - Last updated: 19 January 2024 + Last updated: 26 February 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 19 January 2024 PCRE2CALLOUT(3) +PCRE2 10.47 26 February 2025 PCRE2CALLOUT(3) ------------------------------------------------------------------------------ @@ -5397,7 +5543,12 @@ DIFFERENCES BETWEEN PCRE2 AND PERL 4. If a braced quantifier such as {1,2} appears where there is nothing to repeat (for example, at the start of a branch), PCRE2 raises an er- - ror whereas Perl treats the quantifier characters as literal. + ror whereas Perl treats the quantifier characters as literal. When a + braced quantifier (...){min,max} has min > max, Perl treats it as an + item which fails to match any portion of the subject (as no number of + repetitions can meet the condition), and additionally issues a warning + when in warning mode. PCRE2 has no warning features, so it gives an er- + ror in this case. 5. Capture groups that occur inside negative lookaround assertions are counted, but their entries in the offsets vector are set only when a @@ -5546,7 +5697,7 @@ DIFFERENCES BETWEEN PCRE2 AND PERL (h) The partial matching facility is PCRE2-specific. - (i) The alternative matching function (pcre2_dfa_match() matches in a + (i) The alternative matching function (pcre2_dfa_match()) matches in a different way and is not Perl-compatible. (j) PCRE2 recognizes some special sequences such as (*CR) or (*NO_JIT) @@ -5567,12 +5718,12 @@ DIFFERENCES BETWEEN PCRE2 AND PERL (m) The scan substring assertion (syntax (*scs:(n)...)) is a PCRE2 ex- tension that is not available in Perl. - 20. Perl has different limits than PCRE2. See the pcre2limit documenta- - tion for details. Perl went with 5.10 from recursion to iteration keep- - ing the intermediate matches on the heap, which is ~10% slower but does - not fall into any stack-overflow limit. PCRE2 made a similar change at - release 10.30, and also has many build-time and run-time customizable - limits. + 20. Perl has different limits than PCRE2. See the pcre2limits documen- + tation for details. Perl went with 5.10 from recursion to iteration + keeping the intermediate matches on the heap, which is ~10% slower but + does not fall into any stack-overflow limit. PCRE2 made a similar + change at release 10.30, and also has many build-time and run-time cus- + tomizable limits. 21. Unlike Perl, PCRE2 doesn't have character set modifiers and spe- cially no way to set characters by context just like Perl's "/d". A @@ -5587,7 +5738,7 @@ DIFFERENCES BETWEEN PCRE2 AND PERL 23. Both PCRE2 and Perl error when \x{ escapes are invalid, but Perl tries to recover and prints a warning if the problem was that an in- - valid hexadecimal digit was found, since PCRE2 doesn't have warnings it + valid hexadecimal digit was found. Since PCRE2 doesn't have warnings it returns an error instead. Additionally, Perl accepts \x{} and gener- ates NUL unlike PCRE2. @@ -5606,11 +5757,11 @@ AUTHOR REVISION - Last updated: 02 October 2024 + Last updated: 02 June 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 02 October 2024 PCRE2COMPAT(3) +PCRE2 10.47 02 June 2025 PCRE2COMPAT(3) ------------------------------------------------------------------------------ @@ -6065,7 +6216,7 @@ REVISION Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 22 August 2024 PCRE2JIT(3) +PCRE2 10.47 22 August 2024 PCRE2JIT(3) ------------------------------------------------------------------------------ @@ -6120,18 +6271,20 @@ SIZE AND OTHER LIMITATIONS is set to 250. An application can change this limit by calling pcre2_set_parens_nest_limit() to set the limit in a compile context. - The maximum length of name for a named capture group is 32 code units, - and the maximum number of such groups is 10000. + The maximum length of the name for a named capture group as well as the + number of such groups is configurable at build time. The maximum length + for the name defaults to 128 code units, and the maximum number of such + groups to 10000. - The maximum length of a name in a (*MARK), (*PRUNE), (*SKIP), or - (*THEN) verb is 255 code units for the 8-bit library and 65535 code + The maximum length of a name in a (*MARK), (*PRUNE), (*SKIP), or + (*THEN) verb is 255 code units for the 8-bit library and 65535 code units for the 16-bit and 32-bit libraries. - The maximum length of a string argument to a callout is the largest + The maximum length of a string argument to a callout is the largest number a 32-bit unsigned integer can hold. - The maximum amount of heap memory used for matching is controlled by - the heap limit, which can be set in a pattern or in a match context. + The maximum amount of heap memory used for matching is controlled by + the heap limit, which can be set in a pattern or in a match context. The default is a very large number, effectively unlimited. @@ -6144,11 +6297,11 @@ AUTHOR REVISION - Last updated: 16 August 2023 + Last updated: 03 September 2025 Copyright (c) 1997-2023 University of Cambridge. -PCRE2 10.46 16 August 2023 PCRE2LIMITS(3) +PCRE2 10.47 03 September 2025 PCRE2LIMITS(3) ------------------------------------------------------------------------------ @@ -6164,18 +6317,18 @@ PCRE2 MATCHING ALGORITHMS This document describes the two different algorithms that are available in PCRE2 for matching a compiled regular expression against a given subject string. The "standard" algorithm is the one provided by the - pcre2_match() function. This works in the same as Perl's matching func- - tion, and provides a Perl-compatible matching operation. The just-in- - time (JIT) optimization that is described in the pcre2jit documentation - is compatible with this function. + pcre2_match() function. This works in the same way as Perl's matching + function, and provides a Perl-compatible matching operation. The just- + in-time (JIT) optimization that is described in the pcre2jit documenta- + tion is compatible with this function. An alternative algorithm is provided by the pcre2_dfa_match() function; it operates in a different way, and is not Perl-compatible. This alter- - native has advantages and disadvantages compared with the standard al- + native has advantages and disadvantages compared with the standard al- gorithm, and these are described below. When there is only one possible way in which a given subject string can - match a pattern, the two algorithms give the same answer. A difference + match a pattern, the two algorithms give the same answer. A difference arises, however, when there are multiple possibilities. For example, if the anchored pattern @@ -6192,114 +6345,114 @@ PCRE2 MATCHING ALGORITHMS REGULAR EXPRESSIONS AS TREES The set of strings that are matched by a regular expression can be rep- - resented as a tree structure. An unlimited repetition in the pattern - makes the tree of infinite size, but it is still a tree. Matching the - pattern to a given subject string (from a given starting point) can be - thought of as a search of the tree. There are two ways to search a - tree: depth-first and breadth-first, and these correspond to the two + resented as a tree structure. An unlimited repetition in the pattern + makes the tree of infinite size, but it is still a tree. Matching the + pattern to a given subject string (from a given starting point) can be + thought of as a search of the tree. There are two ways to search a + tree: depth-first and breadth-first, and these correspond to the two matching algorithms provided by PCRE2. THE STANDARD MATCHING ALGORITHM - In the terminology of Jeffrey Friedl's book "Mastering Regular Expres- - sions", the standard algorithm is an "NFA algorithm". It conducts a - depth-first search of the pattern tree. That is, it proceeds along a + In the terminology of Jeffrey Friedl's book "Mastering Regular Expres- + sions", the standard algorithm is an "NFA algorithm". It conducts a + depth-first search of the pattern tree. That is, it proceeds along a single path through the tree, checking that the subject matches what is - required. When there is a mismatch, the algorithm tries any alterna- - tives at the current point, and if they all fail, it backs up to the - previous branch point in the tree, and tries the next alternative - branch at that level. This often involves backing up (moving to the - left) in the subject string as well. The order in which repetition - branches are tried is controlled by the greedy or ungreedy nature of + required. When there is a mismatch, the algorithm tries any alterna- + tives at the current point, and if they all fail, it backs up to the + previous branch point in the tree, and tries the next alternative + branch at that level. This often involves backing up (moving to the + left) in the subject string as well. The order in which repetition + branches are tried is controlled by the greedy or ungreedy nature of the quantifier. - If a leaf node is reached, a matching string has been found, and at - that point the algorithm stops. Thus, if there is more than one possi- - ble match, this algorithm returns the first one that it finds. Whether - this is the shortest, the longest, or some intermediate length depends + If a leaf node is reached, a matching string has been found, and at + that point the algorithm stops. Thus, if there is more than one possi- + ble match, this algorithm returns the first one that it finds. Whether + this is the shortest, the longest, or some intermediate length depends on the way the alternations and the greedy or ungreedy repetition quan- tifiers are specified in the pattern. - Because it ends up with a single path through the tree, it is rela- - tively straightforward for this algorithm to keep track of the sub- - strings that are matched by portions of the pattern in parentheses. + Because it ends up with a single path through the tree, it is rela- + tively straightforward for this algorithm to keep track of the sub- + strings that are matched by portions of the pattern in parentheses. This provides support for capturing parentheses and backreferences. THE ALTERNATIVE MATCHING ALGORITHM - This algorithm conducts a breadth-first search of the tree. Starting - from the first matching point in the subject, it scans the subject + This algorithm conducts a breadth-first search of the tree. Starting + from the first matching point in the subject, it scans the subject string from left to right, once, character by character, and as it does - this, it remembers all the paths through the tree that represent valid - matches. In Friedl's terminology, this is a kind of "DFA algorithm", - though it is not implemented as a traditional finite state machine (it + this, it remembers all the paths through the tree that represent valid + matches. In Friedl's terminology, this is a kind of "DFA algorithm", + though it is not implemented as a traditional finite state machine (it keeps multiple states active simultaneously). - Although the general principle of this matching algorithm is that it - scans the subject string only once, without backtracking, there is one - exception: when a lookaround assertion is encountered, the characters - following or preceding the current point have to be independently in- + Although the general principle of this matching algorithm is that it + scans the subject string only once, without backtracking, there is one + exception: when a lookaround assertion is encountered, the characters + following or preceding the current point have to be independently in- spected. - The scan continues until either the end of the subject is reached, or - there are no more unterminated paths. At this point, terminated paths - represent the different matching possibilities (if there are none, the - match has failed). Thus, if there is more than one possible match, - this algorithm finds all of them, and in particular, it finds the - longest. The matches are returned in the output vector in decreasing - order of length. There is an option to stop the algorithm after the + The scan continues until either the end of the subject is reached, or + there are no more unterminated paths. At this point, terminated paths + represent the different matching possibilities (if there are none, the + match has failed). Thus, if there is more than one possible match, + this algorithm finds all of them, and in particular, it finds the + longest. The matches are returned in the output vector in decreasing + order of length. There is an option to stop the algorithm after the first match (which is necessarily the shortest) is found. - Note that the size of vector needed to contain all the results depends - on the number of simultaneous matches, not on the number of capturing - parentheses in the pattern. Using pcre2_match_data_create_from_pat- - tern() to create the match data block is therefore not advisable when + Note that the size of vector needed to contain all the results depends + on the number of simultaneous matches, not on the number of capturing + parentheses in the pattern. Using pcre2_match_data_create_from_pat- + tern() to create the match data block is therefore not advisable when doing DFA matching. - Note also that all the matches that are found start at the same point + Note also that all the matches that are found start at the same point in the subject. If the pattern cat(er(pillar)?)? - is matched against the string "the caterpillar catchment", the result - is the three strings "caterpillar", "cater", and "cat" that start at - the fifth character of the subject. The algorithm does not automati- + is matched against the string "the caterpillar catchment", the result + is the three strings "caterpillar", "cater", and "cat" that start at + the fifth character of the subject. The algorithm does not automati- cally move on to find matches that start at later positions. PCRE2's "auto-possessification" optimization usually applies to charac- - ter repeats at the end of a pattern (as well as internally). For exam- + ter repeats at the end of a pattern (as well as internally). For exam- ple, the pattern "a\d+" is compiled as if it were "a\d++" because there - is no point even considering the possibility of backtracking into the - repeated digits. For DFA matching, this means that only one possible - match is found. If you really do want multiple matches in such cases, - either use an ungreedy repeat ("a\d+?") or set the PCRE2_NO_AUTO_POS- + is no point even considering the possibility of backtracking into the + repeated digits. For DFA matching, this means that only one possible + match is found. If you really do want multiple matches in such cases, + either use an ungreedy repeat ("a\d+?") or set the PCRE2_NO_AUTO_POS- SESS option when compiling. - There are a number of features of PCRE2 regular expressions that are - not supported or behave differently in the alternative matching func- + There are a number of features of PCRE2 regular expressions that are + not supported or behave differently in the alternative matching func- tion. Those that are not supported cause an error if encountered. - 1. Because the algorithm finds all possible matches, the greedy or un- - greedy nature of repetition quantifiers is not relevant (though it may - affect auto-possessification, as just described). During matching, - greedy and ungreedy quantifiers are treated in exactly the same way. + 1. Because the algorithm finds all possible matches, the greedy or un- + greedy nature of repetition quantifiers is not relevant (though it may + affect auto-possessification, as just described). During matching, + greedy and ungreedy quantifiers are treated in exactly the same way. However, possessive quantifiers can make a difference when what follows - could also match what is quantified, for example in a pattern like + could also match what is quantified, for example in a pattern like this: ^a++\w! - This pattern matches "aaab!" but not "aaa!", which would be matched by - a non-possessive quantifier. Similarly, if an atomic group is present, - it is matched as if it were a standalone pattern at the current point, - and the longest match is then "locked in" for the rest of the overall + This pattern matches "aaab!" but not "aaa!", which would be matched by + a non-possessive quantifier. Similarly, if an atomic group is present, + it is matched as if it were a standalone pattern at the current point, + and the longest match is then "locked in" for the rest of the overall pattern. 2. When dealing with multiple paths through the tree simultaneously, it - is not straightforward to keep track of captured substrings for the - different matching possibilities, and PCRE2's implementation of this + is not straightforward to keep track of captured substrings for the + different matching possibilities, and PCRE2's implementation of this algorithm does not attempt to do this. This means that no captured sub- strings are available. @@ -6308,7 +6461,7 @@ THE ALTERNATIVE MATCHING ALGORITHM (a) Backreferences; - (b) Conditional expressions that use a backreference as the condition + (b) Conditional expressions that use a backreference as the condition or test for a specific group recursion; (c) Script runs; @@ -6316,36 +6469,36 @@ THE ALTERNATIVE MATCHING ALGORITHM (d) Scan substring assertions. 4. Because many paths through the tree may be active, the \K escape se- - quence, which resets the start of the match when encountered (but may + quence, which resets the start of the match when encountered (but may be on some paths and not on others), is not supported. - 5. Callouts are supported, but the value of the capture_top field is + 5. Callouts are supported, but the value of the capture_top field is always 1, and the value of the capture_last field is always 0. - 6. The \C escape sequence, which (in the standard algorithm) always + 6. The \C escape sequence, which (in the standard algorithm) always matches a single code unit, even in a UTF mode, is not supported in UTF - modes because the alternative algorithm moves through the subject - string one character (not code unit) at a time, for all active paths + modes because the alternative algorithm moves through the subject + string one character (not code unit) at a time, for all active paths through the tree. - 7. Except for (*FAIL), the backtracking control verbs such as (*PRUNE) - are not supported. (*FAIL) is supported, and behaves like a failing + 7. Except for (*FAIL), the backtracking control verbs such as (*PRUNE) + are not supported. (*FAIL) is supported, and behaves like a failing negative assertion. - 8. The PCRE2_MATCH_INVALID_UTF option for pcre2_compile() is not sup- + 8. The PCRE2_MATCH_INVALID_UTF option for pcre2_compile() is not sup- ported by pcre2_dfa_match(). ADVANTAGES OF THE ALTERNATIVE ALGORITHM - The main advantage of the alternative algorithm is that all possible + The main advantage of the alternative algorithm is that all possible matches (at a single point in the subject) are automatically found, and - in particular, the longest match is found. To find more than one match - at the same point using the standard algorithm, you have to do kludgy + in particular, the longest match is found. To find more than one match + at the same point using the standard algorithm, you have to do kludgy things with callouts. - Partial matching is possible with this algorithm, though it has some - limitations. The pcre2partial documentation gives details of partial + Partial matching is possible with this algorithm, though it has some + limitations. The pcre2partial documentation gives details of partial matching and discusses multi-segment matching. @@ -6353,8 +6506,8 @@ DISADVANTAGES OF THE ALTERNATIVE ALGORITHM The alternative algorithm suffers from a number of disadvantages: - 1. It is substantially slower than the standard algorithm. This is - partly because it has to search for all possible matches, but is also + 1. It is substantially slower than the standard algorithm. This is + partly because it has to search for all possible matches, but is also because it is less susceptible to optimization. 2. Capturing parentheses and other features such as backreferences that @@ -6377,11 +6530,11 @@ AUTHOR REVISION - Last updated: 30 August 2024 + Last updated: 22 February 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 30 August 2024 PCRE2MATCHING(3) +PCRE2 10.47 22 February 2025 PCRE2MATCHING(3) ------------------------------------------------------------------------------ @@ -6764,7 +6917,7 @@ REVISION Copyright (c) 1997-2019 University of Cambridge. -PCRE2 10.46 27 November 2024 PCRE2PARTIAL(3) +PCRE2 10.47 27 November 2024 PCRE2PARTIAL(3) ------------------------------------------------------------------------------ @@ -6892,32 +7045,32 @@ SPECIAL START-OF-PATTERN ITEMS If a pattern starts with (*NO_DOTSTAR_ANCHOR), it has the same effect as setting the PCRE2_NO_DOTSTAR_ANCHOR option, or calling pcre2_set_op- - timize() with a PCRE2_DOTSTAR_ANCHOR_OFF directive. This disables opti- - mizations that apply to patterns whose top-level branches all start - with .* (match any number of arbitrary characters). For more details, + timize() with a PCRE2_DOTSTAR_ANCHOR_OFF directive. This disables op- + timizations that apply to patterns whose top-level branches all start + with .* (match any number of arbitrary characters). For more details, see the pcre2api documentation. Disabling JIT compilation - If a pattern that starts with (*NO_JIT) is successfully compiled, an - attempt by the application to apply the JIT optimization by calling + If a pattern that starts with (*NO_JIT) is successfully compiled, an + attempt by the application to apply the JIT optimization by calling pcre2_jit_compile() is ignored. Setting match resource limits The pcre2_match() function contains a counter that is incremented every time it goes round its main loop. The caller of pcre2_match() can set a - limit on this counter, which therefore limits the amount of computing + limit on this counter, which therefore limits the amount of computing resource used for a match. The maximum depth of nested backtracking can - also be limited; this indirectly restricts the amount of heap memory - that is used, but there is also an explicit memory limit that can be + also be limited; this indirectly restricts the amount of heap memory + that is used, but there is also an explicit memory limit that can be set. - These facilities are provided to catch runaway matches that are pro- - voked by patterns with huge matching trees. A common example is a pat- - tern with nested unlimited repeats applied to a long string that does - not match. When one of these limits is reached, pcre2_match() gives an - error return. The limits can also be set by items at the start of the + These facilities are provided to catch runaway matches that are pro- + voked by patterns with huge matching trees. A common example is a pat- + tern with nested unlimited repeats applied to a long string that does + not match. When one of these limits is reached, pcre2_match() gives an + error return. The limits can also be set by items at the start of the pattern of the form (*LIMIT_HEAP=d) @@ -6925,35 +7078,35 @@ SPECIAL START-OF-PATTERN ITEMS (*LIMIT_DEPTH=d) where d is any number of decimal digits. However, the value of the set- - ting must be less than the value set (or defaulted) by the caller of - pcre2_match() for it to have any effect. In other words, the pattern - writer can lower the limits set by the programmer, but not raise them. - If there is more than one setting of one of these limits, the lower - value is used. The heap limit is specified in kibibytes (units of 1024 + ting must be less than the value set (or defaulted) by the caller of + pcre2_match() for it to have any effect. In other words, the pattern + writer can lower the limits set by the programmer, but not raise them. + If there is more than one setting of one of these limits, the lower + value is used. The heap limit is specified in kibibytes (units of 1024 bytes). - Prior to release 10.30, LIMIT_DEPTH was called LIMIT_RECURSION. This + Prior to release 10.30, LIMIT_DEPTH was called LIMIT_RECURSION. This name is still recognized for backwards compatibility. The heap limit applies only when the pcre2_match() or pcre2_dfa_match() interpreters are used for matching. It does not apply to JIT. The match - limit is used (but in a different way) when JIT is being used, or when + limit is used (but in a different way) when JIT is being used, or when pcre2_dfa_match() is called, to limit computing resource usage by those - matching functions. The depth limit is ignored by JIT but is relevant - for DFA matching, which uses function recursion for recursions within - the pattern and for lookaround assertions and atomic groups. In this + matching functions. The depth limit is ignored by JIT but is relevant + for DFA matching, which uses function recursion for recursions within + the pattern and for lookaround assertions and atomic groups. In this case, the depth limit controls the depth of such recursion. Newline conventions - PCRE2 supports six different conventions for indicating line breaks in - strings: a single CR (carriage return) character, a single LF (line- + PCRE2 supports six different conventions for indicating line breaks in + strings: a single CR (carriage return) character, a single LF (line- feed) character, the two-character sequence CRLF, any of the three pre- - ceding, any Unicode newline sequence, or the NUL character (binary - zero). The pcre2api page has further discussion about newlines, and + ceding, any Unicode newline sequence, or the NUL character (binary + zero). The pcre2api page has further discussion about newlines, and shows how to set the newline convention when calling pcre2_compile(). - It is also possible to specify a newline convention by starting a pat- + It is also possible to specify a newline convention by starting a pat- tern string with one of the following sequences: (*CR) carriage return @@ -6973,56 +7126,56 @@ SPECIAL START-OF-PATTERN ITEMS no longer a newline. If more than one of these settings is present, the last one is used. - The newline convention affects where the circumflex and dollar asser- + The newline convention affects where the circumflex and dollar asser- tions are true. It also affects the interpretation of the dot metachar- - acter when PCRE2_DOTALL is not set, and the behaviour of \N when not - followed by an opening brace. However, it does not affect what the \R - escape sequence matches. By default, this is any Unicode newline se- - quence, for Perl compatibility. However, this can be changed; see the + acter when PCRE2_DOTALL is not set, and the behaviour of \N when not + followed by an opening brace. However, it does not affect what the \R + escape sequence matches. By default, this is any Unicode newline se- + quence, for Perl compatibility. However, this can be changed; see the next section and the description of \R in the section entitled "Newline - sequences" below. A change of \R setting can be combined with a change + sequences" below. A change of \R setting can be combined with a change of newline convention. Specifying what \R matches It is possible to restrict \R to match only CR, LF, or CRLF (instead of - the complete set of Unicode line endings) by setting the option - PCRE2_BSR_ANYCRLF at compile time. This effect can also be achieved by - starting a pattern with (*BSR_ANYCRLF). For completeness, (*BSR_UNI- + the complete set of Unicode line endings) by setting the option + PCRE2_BSR_ANYCRLF at compile time. This effect can also be achieved by + starting a pattern with (*BSR_ANYCRLF). For completeness, (*BSR_UNI- CODE) is also recognized, corresponding to PCRE2_BSR_UNICODE. CHARACTERS AND METACHARACTERS - A regular expression is a pattern that is matched against a subject - string from left to right. Most characters stand for themselves in a - pattern, and match the corresponding characters in the subject. As a + A regular expression is a pattern that is matched against a subject + string from left to right. Most characters stand for themselves in a + pattern, and match the corresponding characters in the subject. As a trivial example, the pattern The quick brown fox matches a portion of a subject string that is identical to itself. When - caseless matching is specified (the PCRE2_CASELESS option or (?i) - within the pattern), letters are matched independently of case. Note - that there are two ASCII characters, K and S, that, in addition to - their lower case ASCII equivalents, are case-equivalent with Unicode - U+212A (Kelvin sign) and U+017F (long S) respectively when either + caseless matching is specified (the PCRE2_CASELESS option or (?i) + within the pattern), letters are matched independently of case. Note + that there are two ASCII characters, K and S, that, in addition to + their lower case ASCII equivalents, are case-equivalent with Unicode + U+212A (Kelvin sign) and U+017F (long S) respectively when either PCRE2_UTF or PCRE2_UCP is set, unless the PCRE2_EXTRA_CASELESS_RESTRICT - option is in force (either passed to pcre2_compile() or set by (*CASE- - LESS_RESTRICT) or (?r) within the pattern). If the PCRE2_EXTRA_TURK- - ISH_CASING option is in force (either passed to pcre2_compile() or set - by (*TURKISH_CASING) within the pattern), then the 'i' letters are + option is in force (either passed to pcre2_compile() or set by (*CASE- + LESS_RESTRICT) or (?r) within the pattern). If the PCRE2_EXTRA_TURK- + ISH_CASING option is in force (either passed to pcre2_compile() or set + by (*TURKISH_CASING) within the pattern), then the 'i' letters are matched according to Turkish and Azeri languages. The power of regular expressions comes from the ability to include wild cards, character classes, alternatives, and repetitions in the pattern. These are encoded in the pattern by the use of metacharacters, which do - not stand for themselves but instead are interpreted in some special + not stand for themselves but instead are interpreted in some special way. - There are two different sets of metacharacters: those that are recog- - nized anywhere in the pattern except within square brackets, and those - that are recognized within square brackets. Outside square brackets, + There are two different sets of metacharacters: those that are recog- + nized anywhere in the pattern except within square brackets, and those + that are recognized within square brackets. Outside square brackets, the metacharacters are as follows: \ general escape character with several uses @@ -7038,16 +7191,16 @@ CHARACTERS AND METACHARACTERS ? 0 or 1 quantifier; also quantifier minimizer { potential start of min/max quantifier - Brace characters { and } are also used to enclose data for construc- - tions such as \g{2} or \k{name}. In almost all uses of braces, space + Brace characters { and } are also used to enclose data for construc- + tions such as \g{2} or \k{name}. In almost all uses of braces, space and/or horizontal tab characters that follow { or precede } are allowed - and are ignored. In the case of quantifiers, they may also appear be- - fore or after the comma. The exception to this is \u{...} which is an - ECMAScript compatibility feature that is recognized only when the - PCRE2_EXTRA_ALT_BSUX option is set. ECMAScript does not ignore such + and are ignored. In the case of quantifiers, they may also appear be- + fore or after the comma. The exception to this is \u{...} which is an + ECMAScript compatibility feature that is recognized only when the + PCRE2_EXTRA_ALT_BSUX option is set. ECMAScript does not ignore such white space; it causes the item to be interpreted as literal. - Part of a pattern that is in square brackets is called a "character + Part of a pattern that is in square brackets is called a "character class". In a character class the only metacharacters are: \ general escape character @@ -7056,16 +7209,16 @@ CHARACTERS AND METACHARACTERS [ POSIX character class (if followed by POSIX syntax) ] terminates the character class - If a pattern is compiled with the PCRE2_EXTENDED option, most white + If a pattern is compiled with the PCRE2_EXTENDED option, most white space in the pattern, other than in a character class, within a \Q...\E - sequence, or between a # outside a character class and the next new- - line, inclusive, is ignored. An escaping backslash can be used to in- - clude a white space or a # character as part of the pattern. If the - PCRE2_EXTENDED_MORE option is set, the same applies, but in addition - unescaped space and horizontal tab characters are ignored inside a - character class. Note: only these two characters are ignored, not the - full set of pattern white space characters that are ignored outside a - character class. Option settings can be changed within a pattern; see + sequence, or between a # outside a character class and the next new- + line, inclusive, is ignored. An escaping backslash can be used to in- + clude a white space or a # character as part of the pattern. If the + PCRE2_EXTENDED_MORE option is set, the same applies, but in addition + unescaped space and horizontal tab characters are ignored inside a + character class. Note: only these two characters are ignored, not the + full set of pattern white space characters that are ignored outside a + character class. Option settings can be changed within a pattern; see the section entitled "Internal Option Setting" below. The following sections describe the use of each of the metacharacters. @@ -7074,30 +7227,30 @@ CHARACTERS AND METACHARACTERS BACKSLASH The backslash character has several uses. Firstly, if it is followed by - a character that is not a digit or a letter, it takes away any special - meaning that character may have. This use of backslash as an escape + a character that is not a digit or a letter, it takes away any special + meaning that character may have. This use of backslash as an escape character applies both inside and outside character classes. - For example, if you want to match a * character, you must write \* in - the pattern. This escaping action applies whether or not the following - character would otherwise be interpreted as a metacharacter, so it is - always safe to precede a non-alphanumeric with backslash to specify + For example, if you want to match a * character, you must write \* in + the pattern. This escaping action applies whether or not the following + character would otherwise be interpreted as a metacharacter, so it is + always safe to precede a non-alphanumeric with backslash to specify that it stands for itself. In particular, if you want to match a back- slash, you write \\. - Only ASCII digits and letters have any special meaning after a back- + Only ASCII digits and letters have any special meaning after a back- slash. All other characters (in particular, those whose code points are greater than 127) are treated as literals. - If you want to treat all characters in a sequence as literals, you can - do so by putting them between \Q and \E. Note that this includes white - space even when the PCRE2_EXTENDED option is set so that most other - white space is ignored. The behaviour is different from Perl in that $ + If you want to treat all characters in a sequence as literals, you can + do so by putting them between \Q and \E. Note that this includes white + space even when the PCRE2_EXTENDED option is set so that most other + white space is ignored. The behaviour is different from Perl in that $ and @ are handled as literals in \Q...\E sequences in PCRE2, whereas in - Perl, $ and @ cause variable interpolation. Also, Perl does "double- - quotish backslash interpolation" on any backslashes between \Q and \E - which, its documentation says, "may lead to confusing results". PCRE2 - treats a backslash between \Q and \E just like any other character. + Perl, $ and @ cause variable interpolation. Also, Perl does "double- + quotish backslash interpolation" on any backslashes between \Q and \E + which, its documentation says, "may lead to confusing results". PCRE2 + treats a backslash between \Q and \E just like any other character. Note the following examples: Pattern PCRE2 matches Perl matches @@ -7109,29 +7262,29 @@ BACKSLASH \QA\B\E A\B A\B \Q\\E \ \\E - The \Q...\E sequence is recognized both inside and outside character - classes. An isolated \E that is not preceded by \Q is ignored. If \Q - is not followed by \E later in the pattern, the literal interpretation - continues to the end of the pattern (that is, \E is assumed at the - end). If the isolated \Q is inside a character class, this causes an - error, because the character class is then not terminated by a closing + The \Q...\E sequence is recognized both inside and outside character + classes. An isolated \E that is not preceded by \Q is ignored. If \Q + is not followed by \E later in the pattern, the literal interpretation + continues to the end of the pattern (that is, \E is assumed at the + end). If the isolated \Q is inside a character class, this causes an + error, because the character class is then not terminated by a closing square bracket. - Another difference from Perl is that any appearance of \Q or \E inside - what might otherwise be a quantifier causes PCRE2 not to recognize the + Another difference from Perl is that any appearance of \Q or \E inside + what might otherwise be a quantifier causes PCRE2 not to recognize the sequence as a quantifier. Perl recognizes a quantifier if (redundantly) - either of the numbers is inside \Q...\E, but not if the separating - comma is. When not recognized as a quantifier a sequence such as + either of the numbers is inside \Q...\E, but not if the separating + comma is. When not recognized as a quantifier a sequence such as {\Q1\E,2} is treated as the literal string "{1,2}". Non-printing characters A second use of backslash provides a way of encoding non-printing char- - acters in patterns in a visible manner. There is no restriction on the - appearance of non-printing characters in a pattern, but when a pattern + acters in patterns in a visible manner. There is no restriction on the + appearance of non-printing characters in a pattern, but when a pattern is being prepared by text editing, it is often easier to use one of the - following escape sequences instead of the binary character it repre- - sents. In an ASCII or Unicode environment, these escapes are as fol- + following escape sequences instead of the binary character it repre- + sents. In an ASCII or Unicode environment, these escapes are as fol- lows: \a alarm, that is, the BEL character (hex 07) @@ -7151,97 +7304,97 @@ BACKSLASH A description of how back references work is given later, following the discussion of parenthesized groups. - By default, after \x that is not followed by {, one or two hexadecimal + By default, after \x that is not followed by {, one or two hexadecimal digits are read (letters can be in upper or lower case). If the charac- - ter that follows \x is neither { nor a hexadecimal digit, an error oc- - curs. This is different from Perl's default behaviour, which generates - a NUL character, but is in line with the behaviour of Perl's 'strict' + ter that follows \x is neither { nor a hexadecimal digit, an error oc- + curs. This is different from Perl's default behaviour, which generates + a NUL character, but is in line with the behaviour of Perl's 'strict' mode in re. - Any number of hexadecimal digits may appear between \x{ and }. If a - character other than a hexadecimal digit appears between \x{ and }, or + Any number of hexadecimal digits may appear between \x{ and }. If a + character other than a hexadecimal digit appears between \x{ and }, or if there is no terminating }, an error occurs. Characters whose code points are less than 256 can be defined by either of the two syntaxes for \x or by an octal sequence. There is no differ- ence in the way they are handled. For example, \xdc is exactly the same - as \x{dc} or \334. However, using the braced versions does make such + as \x{dc} or \334. However, using the braced versions does make such sequences easier to read. - Support is available for some ECMAScript (aka JavaScript) escape se- + Support is available for some ECMAScript (aka JavaScript) escape se- quences via two compile-time options. If PCRE2_ALT_BSUX is set, the se- - quence \x followed by { is not recognized. Only if \x is followed by - two hexadecimal digits is it recognized as a character escape. Other- - wise it is interpreted as a literal "x" character. In this mode, sup- - port for code points greater than 256 is provided by \u, which must be - followed by four hexadecimal digits; otherwise it is interpreted as a + quence \x followed by { is not recognized. Only if \x is followed by + two hexadecimal digits is it recognized as a character escape. Other- + wise it is interpreted as a literal "x" character. In this mode, sup- + port for code points greater than 256 is provided by \u, which must be + followed by four hexadecimal digits; otherwise it is interpreted as a literal "u" character. - PCRE2_EXTRA_ALT_BSUX has the same effect as PCRE2_ALT_BSUX and, in ad- + PCRE2_EXTRA_ALT_BSUX has the same effect as PCRE2_ALT_BSUX and, in ad- dition, \u{hhh..} is recognized as the character specified by hexadeci- mal code point. There may be any number of hexadecimal digits, but un- - like other places that also use curly brackets, spaces are not allowed - and would result in the string being interpreted as a literal. This + like other places that also use curly brackets, spaces are not allowed + and would result in the string being interpreted as a literal. This syntax is from ECMAScript 6. - The \N{U+hhh..} escape sequence is recognized only when PCRE2 is oper- - ating in UTF mode. Perl also uses \N{name} to specify characters by - Unicode name; PCRE2 does not support this. Note that when \N is not + The \N{U+hhh..} escape sequence is recognized only when PCRE2 is oper- + ating in UTF mode. Perl also uses \N{name} to specify characters by + Unicode name; PCRE2 does not support this. Note that when \N is not followed by an opening brace (curly bracket) it has an entirely differ- ent meaning, matching any character that is not a newline. - There are some legacy applications where the escape sequence \r is ex- - pected to match a newline. If the PCRE2_EXTRA_ESCAPED_CR_IS_LF option - is set, \r in a pattern is converted to \n so that it matches a LF + There are some legacy applications where the escape sequence \r is ex- + pected to match a newline. If the PCRE2_EXTRA_ESCAPED_CR_IS_LF option + is set, \r in a pattern is converted to \n so that it matches a LF (linefeed) instead of a CR (carriage return) character. - An error occurs if \c is not followed by a character whose ASCII code - point is in the range 32 to 126. The precise effect of \cx is as fol- - lows: if x is a lower case letter, it is converted to upper case. Then + An error occurs if \c is not followed by a character whose ASCII code + point is in the range 32 to 126. The precise effect of \cx is as fol- + lows: if x is a lower case letter, it is converted to upper case. Then bit 6 of the character (hex 40) is inverted. Thus \cA to \cZ become hex - 01 to hex 1A (A is 41, Z is 5A), but \c{ becomes hex 3B ({ is 7B), and - \c; becomes hex 7B (; is 3B). If the code unit following \c has a code + 01 to hex 1A (A is 41, Z is 5A), but \c{ becomes hex 3B ({ is 7B), and + \c; becomes hex 7B (; is 3B). If the code unit following \c has a code point less than 32 or greater than 126, a compile-time error occurs. - For differences in the way some escapes behave in EBCDIC environments, + For differences in the way some escapes behave in EBCDIC environments, see section "EBCDIC environments" below. Octal escapes and back references - The escape \o must be followed by a sequence of octal digits, enclosed - in braces. An error occurs if this is not the case. This escape pro- - vides a way of specifying character code points as octal numbers - greater than 0777, and it also allows octal numbers and backreferences + The escape \o must be followed by a sequence of octal digits, enclosed + in braces. An error occurs if this is not the case. This escape pro- + vides a way of specifying character code points as octal numbers + greater than 0777, and it also allows octal numbers and backreferences to be unambiguously distinguished. - If braces are not used, after \0 up to two further octal digits are - read. However, if the PCRE2_EXTRA_NO_BS0 option is set, at least one - more octal digit must follow \0 (use \00 to generate a NUL character). - Make sure you supply two digits after the initial zero if the pattern + If braces are not used, after \0 up to two further octal digits are + read. However, if the PCRE2_EXTRA_NO_BS0 option is set, at least one + more octal digit must follow \0 (use \00 to generate a NUL character). + Make sure you supply two digits after the initial zero if the pattern character that follows is itself an octal digit. - Inside a character class, when a backslash is followed by any octal - digit, up to three octal digits are read to generate a code point. Any - subsequent digits stand for themselves. The sequences \8 and \9 are + Inside a character class, when a backslash is followed by any octal + digit, up to three octal digits are read to generate a code point. Any + subsequent digits stand for themselves. The sequences \8 and \9 are treated as the literal characters "8" and "9". Outside a character class, Perl's handling of a backslash followed by a - digit other than 0 is complicated by ambiguity, and Perl has changed + digit other than 0 is complicated by ambiguity, and Perl has changed over time, causing PCRE2 also to change. From PCRE2 release 10.45 there - is an option called PCRE2_EXTRA_PYTHON_OCTAL that causes PCRE2 to use - Python's unambiguous rules. The next two subsections describe the two + is an option called PCRE2_EXTRA_PYTHON_OCTAL that causes PCRE2 to use + Python's unambiguous rules. The next two subsections describe the two sets of rules. For greater clarity and unambiguity, it is best to avoid following \ by - a digit greater than zero. Instead, use \o{...} or \x{...} to specify + a digit greater than zero. Instead, use \o{...} or \x{...} to specify numerical character code points, and \g{...} to specify backreferences. Perl rules for non-class backslash 1-9 - All the digits that follow the backslash are read as a decimal number. - If the number is less than 10, begins with the digit 8 or 9, or if + All the digits that follow the backslash are read as a decimal number. + If the number is less than 10, begins with the digit 8 or 9, or if there are at least that many previous capture groups in the expression, - the entire sequence is taken as a back reference. Otherwise, up to + the entire sequence is taken as a back reference. Otherwise, up to three octal digits are read to form a character code. For example: \040 is another way of writing an ASCII space @@ -7258,24 +7411,24 @@ BACKSLASH the value 255 (decimal) \81 is always a backreference - Note that octal values of 100 or greater that are specified using this - syntax must not be introduced by a leading zero, because no more than + Note that octal values of 100 or greater that are specified using this + syntax must not be introduced by a leading zero, because no more than three octal digits are ever read. Python rules for non_class backslash 1-9 - If there are at least three octal digits after the backslash, exactly - three are read as an octal code point number, but the value must be no - greater than \377, even in modes where higher code point values are - supported. Any subsequent digits stand for themselves. If there are - fewer than three octal digits, the sequence is taken as a decimal back - reference. Thus, for example, \12 is always a back reference, indepen- - dent of how many captures there are in the pattern. An error is gener- + If there are at least three octal digits after the backslash, exactly + three are read as an octal code point number, but the value must be no + greater than \377, even in modes where higher code point values are + supported. Any subsequent digits stand for themselves. If there are + fewer than three octal digits, the sequence is taken as a decimal back + reference. Thus, for example, \12 is always a back reference, indepen- + dent of how many captures there are in the pattern. An error is gener- ated for a reference to a non-existent capturing group. Constraints on character values - Characters that are specified using octal or hexadecimal numbers are + Characters that are specified using octal or hexadecimal numbers are limited to certain values, as follows: 8-bit non-UTF mode no greater than 0xff @@ -7284,45 +7437,45 @@ BACKSLASH All UTF modes no greater than 0x10ffff and a valid code point Invalid Unicode code points are all those in the range 0xd800 to 0xdfff - (the so-called "surrogate" code points). The check for these can be - disabled by the caller of pcre2_compile() by setting the option - PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES. However, this is possible only in - UTF-8 and UTF-32 modes, because these values are not representable in + (the so-called "surrogate" code points). The check for these can be + disabled by the caller of pcre2_compile() by setting the option + PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES. However, this is possible only in + UTF-8 and UTF-32 modes, because these values are not representable in UTF-16. Escape sequences in character classes All the sequences that define a single character value can be used both - inside and outside character classes. In addition, inside a character + inside and outside character classes. In addition, inside a character class, \b is interpreted as the backspace character (hex 08). When not followed by an opening brace, \N is not allowed in a character - class. \B, \R, and \X are not special inside a character class. Like - other unrecognized alphabetic escape sequences, they cause an error. + class. \B, \R, and \X are not special inside a character class. Like + other unrecognized alphabetic escape sequences, they cause an error. Outside a character class, these sequences have different meanings. Unsupported escape sequences - In Perl, the sequences \F, \l, \L, \u, and \U are recognized by its - string handler and used to modify the case of following characters. By - default, PCRE2 does not support these escape sequences in patterns. - However, if either of the PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX op- - tions is set, \U matches a "U" character, and \u can be used to define + In Perl, the sequences \F, \l, \L, \u, and \U are recognized by its + string handler and used to modify the case of following characters. By + default, PCRE2 does not support these escape sequences in patterns. + However, if either of the PCRE2_ALT_BSUX or PCRE2_EXTRA_ALT_BSUX op- + tions is set, \U matches a "U" character, and \u can be used to define a character by code point, as described above. Absolute and relative backreferences The sequence \g followed by a signed or unsigned number, optionally en- - closed in braces, is an absolute or relative backreference. A named - backreference can be coded as \g{name}. Backreferences are discussed + closed in braces, is an absolute or relative backreference. A named + backreference can be coded as \g{name}. Backreferences are discussed later, following the discussion of parenthesized groups. Absolute and relative subroutine calls - For compatibility with Oniguruma, the non-Perl syntax \g followed by a + For compatibility with Oniguruma, the non-Perl syntax \g followed by a name or a number enclosed either in angle brackets or single quotes, is - an alternative syntax for referencing a capture group as a subroutine. - Details are discussed later. Note that \g{...} (Perl syntax) and + an alternative syntax for referencing a capture group as a subroutine. + Details are discussed later. Note that \g{...} (Perl syntax) and \g<...> (Oniguruma syntax) are not synonymous. The former is a backref- erence; the latter is a subroutine call. @@ -7342,43 +7495,43 @@ BACKSLASH \w any "word" character \W any "non-word" character - The \N escape sequence has the same meaning as the "." metacharacter - when PCRE2_DOTALL is not set, but setting PCRE2_DOTALL does not change + The \N escape sequence has the same meaning as the "." metacharacter + when PCRE2_DOTALL is not set, but setting PCRE2_DOTALL does not change the meaning of \N. Note that when \N is followed by an opening brace it has a different meaning. See the section entitled "Non-printing charac- - ters" above for details. Perl also uses \N{name} to specify characters + ters" above for details. Perl also uses \N{name} to specify characters by Unicode name; PCRE2 does not support this. - Each pair of lower and upper case escape sequences partitions the com- - plete set of characters into two disjoint sets. Any given character - matches one, and only one, of each pair. The sequences can appear both - inside and outside character classes. They each match one character of - the appropriate type. If the current matching point is at the end of - the subject string, all of them fail, because there is no character to + Each pair of lower and upper case escape sequences partitions the com- + plete set of characters into two disjoint sets. Any given character + matches one, and only one, of each pair. The sequences can appear both + inside and outside character classes. They each match one character of + the appropriate type. If the current matching point is at the end of + the subject string, all of them fail, because there is no character to match. - The default \s characters are HT (9), LF (10), VT (11), FF (12), CR - (13), and space (32), which are defined as white space in the "C" lo- - cale. This list may vary if locale-specific matching is taking place. - For example, in some locales the "non-breaking space" character (\xA0) + The default \s characters are HT (9), LF (10), VT (11), FF (12), CR + (13), and space (32), which are defined as white space in the "C" lo- + cale. This list may vary if locale-specific matching is taking place. + For example, in some locales the "non-breaking space" character (\xA0) is recognized as white space, and in others the VT character is not. - A "word" character is an underscore or any character that is a letter - or digit. By default, the definition of letters and digits is con- + A "word" character is an underscore or any character that is a letter + or digit. By default, the definition of letters and digits is con- trolled by PCRE2's low-valued character tables, and may vary if locale- specific matching is taking place (see "Locale support" in the pcre2api - page). For example, in a French locale such as "fr_FR" in Unix-like - systems, or "french" in Windows, some character codes greater than 127 - are used for accented letters, and these are then matched by \w. The + page). For example, in a French locale such as "fr_FR" in Unix-like + systems, or "french" in Windows, some character codes greater than 127 + are used for accented letters, and these are then matched by \w. The use of locales with Unicode is discouraged. - By default, characters whose code points are greater than 127 never + By default, characters whose code points are greater than 127 never match \d, \s, or \w, and always match \D, \S, and \W, although this may - be different for characters in the range 128-255 when locale-specific - matching is happening. These escape sequences retain their original - meanings from before Unicode support was available, mainly for effi- - ciency reasons. If the PCRE2_UCP option is set, the behaviour is - changed so that Unicode properties are used to determine character + be different for characters in the range 128-255 when locale-specific + matching is happening. These escape sequences retain their original + meanings from before Unicode support was available, mainly for effi- + ciency reasons. If the PCRE2_UCP option is set, the behaviour is + changed so that Unicode properties are used to determine character types, as follows: \d any character that matches \p{Nd} (decimal digit) @@ -7386,25 +7539,25 @@ BACKSLASH \w any character that matches \p{L}, \p{N}, \p{Mn}, or \p{Pc} The addition of \p{Mn} (non-spacing mark) and the replacement of an ex- - plicit test for underscore with a test for \p{Pc} (connector punctua- + plicit test for underscore with a test for \p{Pc} (connector punctua- tion) happened in PCRE2 release 10.43. This brings PCRE2 into line with Perl. - The upper case escapes match the inverse sets of characters. Note that - \d matches only decimal digits, whereas \w matches any Unicode digit, + The upper case escapes match the inverse sets of characters. Note that + \d matches only decimal digits, whereas \w matches any Unicode digit, as well as other character categories. Note also that PCRE2_UCP affects - \b, and \B because they are defined in terms of \w and \W. Matching + \b, and \B because they are defined in terms of \w and \W. Matching these sequences is noticeably slower when PCRE2_UCP is set. - The effect of PCRE2_UCP on any one of these escape sequences can be - negated by the options PCRE2_EXTRA_ASCII_BSD, PCRE2_EXTRA_ASCII_BSS, - and PCRE2_EXTRA_ASCII_BSW, respectively. These options can be set and - reset within a pattern by means of an internal option setting (see be- + The effect of PCRE2_UCP on any one of these escape sequences can be + negated by the options PCRE2_EXTRA_ASCII_BSD, PCRE2_EXTRA_ASCII_BSS, + and PCRE2_EXTRA_ASCII_BSW, respectively. These options can be set and + reset within a pattern by means of an internal option setting (see be- low). - The sequences \h, \H, \v, and \V, in contrast to the other sequences, - which match only ASCII characters by default, always match a specific - list of code points, whether or not PCRE2_UCP is set. The horizontal + The sequences \h, \H, \v, and \V, in contrast to the other sequences, + which match only ASCII characters by default, always match a specific + list of code points, whether or not PCRE2_UCP is set. The horizontal space characters are: U+0009 Horizontal tab (HT) @@ -7437,36 +7590,36 @@ BACKSLASH U+2028 Line separator U+2029 Paragraph separator - In 8-bit, non-UTF-8 mode, only the characters with code points less + In 8-bit, non-UTF-8 mode, only the characters with code points less than 256 are relevant. Newline sequences - Outside a character class, by default, the escape sequence \R matches - any Unicode newline sequence. In 8-bit non-UTF-8 mode \R is equivalent + Outside a character class, by default, the escape sequence \R matches + any Unicode newline sequence. In 8-bit non-UTF-8 mode \R is equivalent to the following: (?>\r\n|\n|\x0b|\f|\r|\x85) This is an example of an "atomic group", details of which are given be- - low. This particular group matches either the two-character sequence - CR followed by LF, or one of the single characters LF (linefeed, - U+000A), VT (vertical tab, U+000B), FF (form feed, U+000C), CR (car- - riage return, U+000D), or NEL (next line, U+0085). Because this is an - atomic group, the two-character sequence is treated as a single unit + low. This particular group matches either the two-character sequence + CR followed by LF, or one of the single characters LF (linefeed, + U+000A), VT (vertical tab, U+000B), FF (form feed, U+000C), CR (car- + riage return, U+000D), or NEL (next line, U+0085). Because this is an + atomic group, the two-character sequence is treated as a single unit that cannot be split. In other modes, two additional characters whose code points are greater than 255 are added: LS (line separator, U+2028) and PS (paragraph sepa- - rator, U+2029). Unicode support is not needed for these characters to + rator, U+2029). Unicode support is not needed for these characters to be recognized. It is possible to restrict \R to match only CR, LF, or CRLF (instead of - the complete set of Unicode line endings) by setting the option - PCRE2_BSR_ANYCRLF at compile time. (BSR is an abbreviation for "back- + the complete set of Unicode line endings) by setting the option + PCRE2_BSR_ANYCRLF at compile time. (BSR is an abbreviation for "back- slash R".) This can be made the default when PCRE2 is built; if this is - the case, the other behaviour can be requested via the PCRE2_BSR_UNI- - CODE option. It is also possible to specify these settings by starting + the case, the other behaviour can be requested via the PCRE2_BSR_UNI- + CODE option. It is also possible to specify these settings by starting a pattern string with one of the following sequences: (*BSR_ANYCRLF) CR, LF, or CRLF only @@ -7474,33 +7627,33 @@ BACKSLASH These override the default and the options given to the compiling func- tion. Note that these special settings, which are not Perl-compatible, - are recognized only at the very start of a pattern, and that they must - be in upper case. If more than one of them is present, the last one is + are recognized only at the very start of a pattern, and that they must + be in upper case. If more than one of them is present, the last one is used. They can be combined with a change of newline convention; for ex- ample, a pattern can start with: (*ANY)(*BSR_ANYCRLF) - They can also be combined with the (*UTF) or (*UCP) special sequences. - Inside a character class, \R is treated as an unrecognized escape se- + They can also be combined with the (*UTF) or (*UCP) special sequences. + Inside a character class, \R is treated as an unrecognized escape se- quence, and causes an error. Unicode character properties - When PCRE2 is built with Unicode support (the default), three addi- - tional escape sequences that match characters with specific properties + When PCRE2 is built with Unicode support (the default), three addi- + tional escape sequences that match characters with specific properties are available. They can be used in any mode, though in 8-bit and 16-bit - non-UTF modes these sequences are of course limited to testing charac- - ters whose code points are less than U+0100 or U+10000, respectively. - In 32-bit non-UTF mode, code points greater than 0x10ffff (the Unicode - limit) may be encountered. These are all treated as being in the Un- + non-UTF modes these sequences are of course limited to testing charac- + ters whose code points are less than U+0100 or U+10000, respectively. + In 32-bit non-UTF mode, code points greater than 0x10ffff (the Unicode + limit) may be encountered. These are all treated as being in the Un- known script and with an unassigned type. - Matching characters by Unicode property is not fast, because PCRE2 has - to do a multistage table lookup in order to find a character's prop- + Matching characters by Unicode property is not fast, because PCRE2 has + to do a multistage table lookup in order to find a character's prop- erty. That is why the traditional escape sequences such as \d and \w do - not use Unicode properties in PCRE2 by default, though you can make - them do so by setting the PCRE2_UCP option or by starting the pattern + not use Unicode properties in PCRE2 by default, though you can make + them do so by setting the PCRE2_UCP option or by starting the pattern with (*UCP). The extra escape sequences that provide property support are: @@ -7509,20 +7662,20 @@ BACKSLASH \P{xx} a character without the xx property \X a Unicode extended grapheme cluster - For compatibility with Perl, negation can be specified by including a - circumflex between the opening brace and the property. For example, + For compatibility with Perl, negation can be specified by including a + circumflex between the opening brace and the property. For example, \p{^Lu} is the same as \P{Lu}. - In accordance with Unicode's "loose matching" rules, ASCII white space + In accordance with Unicode's "loose matching" rules, ASCII white space characters, hyphens, and underscores are ignored in the properties rep- resented by xx above. As well as the space character, ASCII white space can be tab, linefeed, vertical tab, formfeed, or carriage return. - Some properties are specified as a name only; others as a name and a - value, separated by a colon or an equals sign. The names and values - consist of ASCII letters and digits (with one Perl-specific exception, - see below). They are not case sensitive. Note, however, that the es- - capes themselves, \p and \P, are case sensitive. There are abbrevia- + Some properties are specified as a name only; others as a name and a + value, separated by a colon or an equals sign. The names and values + consist of ASCII letters and digits (with one Perl-specific exception, + see below). They are not case sensitive. Note, however, that the es- + capes themselves, \p and \P, are case sensitive. There are abbrevia- tions for many names. The following examples are all equivalent: \p{bidiclass=al} @@ -7531,30 +7684,30 @@ BACKSLASH \p{ Bi-di class = Al } \P{ ^ Bi-di class = Al } - There is support for Unicode script names, Unicode general category - properties, "Any", which matches any character (including newline), - Bidi_Class, a number of binary (yes/no) properties, and some special + There is support for Unicode script names, Unicode general category + properties, "Any", which matches any character (including newline), + Bidi_Class, a number of binary (yes/no) properties, and some special PCRE2 properties (described below). Certain other Perl properties such - as "InMusicalSymbols" are not supported by PCRE2. Note that \P{Any} + as "InMusicalSymbols" are not supported by PCRE2. Note that \P{Any} does not match any characters, so always causes a match failure. Script properties for \p and \P There are three different syntax forms for matching a script. Each Uni- - code character has a basic script and, optionally, a list of other + code character has a basic script and, optionally, a list of other scripts ("Script Extensions") with which it is commonly used. Using the Adlam script as an example, \p{sc:Adlam} matches characters whose basic script is Adlam, whereas \p{scx:Adlam} matches, in addition, characters - that have Adlam in their extensions list. The full names "script" and - "script extensions" for the property types are recognized and, as for - all property specifications, an equals sign is an alternative to the - colon. If a script name is given without a property type, for example, - \p{Adlam}, it is treated as \p{scx:Adlam}. Perl changed to this inter- + that have Adlam in their extensions list. The full names "script" and + "script extensions" for the property types are recognized and, as for + all property specifications, an equals sign is an alternative to the + colon. If a script name is given without a property type, for example, + \p{Adlam}, it is treated as \p{scx:Adlam}. Perl changed to this inter- pretation at release 5.26 and PCRE2 changed at release 10.40. Unassigned characters (and in non-UTF 32-bit mode, characters with code points greater than 0x10FFFF) are assigned the "Unknown" script. Others - that are not part of an identified script are lumped together as "Com- + that are not part of an identified script are lumped together as "Com- mon". The current list of recognized script names and their 4-character abbreviations can be obtained by running this command: @@ -7564,10 +7717,10 @@ BACKSLASH The general category property for \p and \P Each character has exactly one Unicode general category property, spec- - ified by a two-letter abbreviation. If only one letter is specified - with \p or \P, it includes all the general category properties that - start with that letter. In this case, in the absence of negation, the - curly brackets in the escape sequence are optional; these two examples + ified by a two-letter abbreviation. If only one letter is specified + with \p or \P, it includes all the general category properties that + start with that letter. In this case, in the absence of negation, the + curly brackets in the escape sequence are optional; these two examples have the same effect: \p{L} @@ -7620,25 +7773,25 @@ BACKSLASH Zp Paragraph separator Zs Space separator - Perl originally used the name L& for the Lc property. This is still - supported by Perl, but discouraged. PCRE2 also still supports it. This - property matches any character that has the Lu, Ll, or Lt property, in - other words, any letter that is not classified as a modifier or - "other". From release 10.45 of PCRE2 the properties Lu, Ll, and Lt are - all treated as Lc when case-independent matching is set by the - PCRE2_CASELESS option or (?i) within the pattern. The other properties + Perl originally used the name L& for the Lc property. This is still + supported by Perl, but discouraged. PCRE2 also still supports it. This + property matches any character that has the Lu, Ll, or Lt property, in + other words, any letter that is not classified as a modifier or + "other". From release 10.45 of PCRE2 the properties Lu, Ll, and Lt are + all treated as Lc when case-independent matching is set by the + PCRE2_CASELESS option or (?i) within the pattern. The other properties are not affected by caseless matching. - The Cs (Surrogate) property applies only to characters whose code - points are in the range U+D800 to U+DFFF. These characters are no dif- - ferent to any other character when PCRE2 is not in UTF mode (using the - 16-bit or 32-bit library). However, they are not valid in Unicode + The Cs (Surrogate) property applies only to characters whose code + points are in the range U+D800 to U+DFFF. These characters are no dif- + ferent to any other character when PCRE2 is not in UTF mode (using the + 16-bit or 32-bit library). However, they are not valid in Unicode strings and so cannot be tested by PCRE2 in UTF mode, unless UTF valid- - ity checking has been turned off (see the discussion of + ity checking has been turned off (see the discussion of PCRE2_NO_UTF_CHECK in the pcre2api page). - The long synonyms for property names that Perl supports (such as - \p{Letter}) are not supported by PCRE2, nor is it permitted to prefix + The long synonyms for property names that Perl supports (such as + \p{Letter}) are not supported by PCRE2, nor is it permitted to prefix any of these properties with "Is". No character that is in the Unicode table has the Cn (unassigned) prop- @@ -7647,9 +7800,9 @@ BACKSLASH Binary (yes/no) properties for \p and \P - Unicode defines a number of binary properties, that is, properties - whose only values are true or false. You can obtain a list of those - that are recognized by \p and \P, along with their abbreviations, by + Unicode defines a number of binary properties, that is, properties + whose only values are true or false. You can obtain a list of those + that are recognized by \p and \P, along with their abbreviations, by running this command: pcre2test -LP @@ -7686,63 +7839,63 @@ BACKSLASH S segment separator WS white space - As in all property specifications, an equals sign may be used instead - of a colon and the class names are case-insensitive. Only the short - names listed above are recognized; PCRE2 does not at present support + As in all property specifications, an equals sign may be used instead + of a colon and the class names are case-insensitive. Only the short + names listed above are recognized; PCRE2 does not at present support any long alternatives. Extended grapheme clusters - The \X escape matches any number of Unicode characters that form an + The \X escape matches any number of Unicode characters that form an "extended grapheme cluster", and treats the sequence as an atomic group - (see below). Unicode supports various kinds of composite character by - giving each character a grapheme breaking property, and having rules + (see below). Unicode supports various kinds of composite character by + giving each character a grapheme breaking property, and having rules that use these properties to define the boundaries of extended grapheme - clusters. The rules are defined in Unicode Standard Annex 29, "Unicode - Text Segmentation". Unicode 11.0.0 abandoned the use of some previous - properties that had been used for emojis. Instead it introduced vari- - ous emoji-specific properties. PCRE2 uses only the Extended Picto- + clusters. The rules are defined in Unicode Standard Annex 29, "Unicode + Text Segmentation". Unicode 11.0.0 abandoned the use of some previous + properties that had been used for emojis. Instead it introduced vari- + ous emoji-specific properties. PCRE2 uses only the Extended Picto- graphic property. - \X always matches at least one character. Then it decides whether to + \X always matches at least one character. Then it decides whether to add additional characters according to the following rules for ending a cluster: 1. End at the end of the subject string. - 2. Do not end between CR and LF; otherwise end after any control char- + 2. Do not end between CR and LF; otherwise end after any control char- acter. - 3. Do not break Hangul (a Korean script) syllable sequences. Hangul - characters are of five types: L, V, T, LV, and LVT. An L character may - be followed by an L, V, LV, or LVT character; an LV or V character may - be followed by a V or T character; an LVT or T character may be fol- + 3. Do not break Hangul (a Korean script) syllable sequences. Hangul + characters are of five types: L, V, T, LV, and LVT. An L character may + be followed by an L, V, LV, or LVT character; an LV or V character may + be followed by a V or T character; an LVT or T character may be fol- lowed only by a T character. 4. Do not end before extending characters or spacing marks or the zero- - width joiner (ZWJ) character. Characters with the "mark" property al- + width joiner (ZWJ) character. Characters with the "mark" property al- ways have the "extend" grapheme breaking property. 5. Do not end after prepend characters. - 6. Do not end within emoji modifier sequences or emoji ZWJ (zero-width - joiner) sequences. An emoji ZWJ sequence consists of a character with - the Extended_Pictographic property, optionally followed by one or more - characters with the Extend property, followed by the ZWJ character, + 6. Do not end within emoji modifier sequences or emoji ZWJ (zero-width + joiner) sequences. An emoji ZWJ sequence consists of a character with + the Extended_Pictographic property, optionally followed by one or more + characters with the Extend property, followed by the ZWJ character, followed by another Extended_Pictographic character. - 7. Do not break within emoji flag sequences. That is, do not break be- - tween regional indicator (RI) characters if there are an odd number of + 7. Do not break within emoji flag sequences. That is, do not break be- + tween regional indicator (RI) characters if there are an odd number of RI characters before the break point. 8. Otherwise, end the cluster. PCRE2's additional properties - As well as the standard Unicode properties described above, PCRE2 sup- + As well as the standard Unicode properties described above, PCRE2 sup- ports four more that make it possible to convert traditional escape se- - quences such as \w and \s to use Unicode properties. PCRE2 uses these - non-standard, non-Perl properties internally when PCRE2_UCP is set. + quences such as \w and \s to use Unicode properties. PCRE2 uses these + non-standard, non-Perl properties internally when PCRE2_UCP is set. However, they may also be used explicitly. These properties are: Xan Any alphanumeric character @@ -7750,74 +7903,74 @@ BACKSLASH Xsp Any Perl space character Xwd Any Perl "word" character - Xan matches characters that have either the L (letter) or the N (num- - ber) property. Xps matches the characters tab, linefeed, vertical tab, - form feed, or carriage return, and any other character that has the Z - (separator) property (this includes the space character). Xsp is the + Xan matches characters that have either the L (letter) or the N (num- + ber) property. Xps matches the characters tab, linefeed, vertical tab, + form feed, or carriage return, and any other character that has the Z + (separator) property (this includes the space character). Xsp is the same as Xps; in PCRE1 it used to exclude vertical tab, for Perl compat- ibility, but Perl changed. Xwd matches the same characters as Xan, plus - those that match Mn (non-spacing mark) or Pc (connector punctuation, + those that match Mn (non-spacing mark) or Pc (connector punctuation, which includes underscore). - There is another non-standard property, Xuc, which matches any charac- - ter that can be represented by a Universal Character Name in C++ and - other programming languages. These are the characters $, @, ` (grave - accent), and all characters with Unicode code points greater than or - equal to U+00A0, except for the surrogates U+D800 to U+DFFF. Note that - most base (ASCII) characters are excluded. (Universal Character Names - are of the form \uHHHH or \UHHHHHHHH where H is a hexadecimal digit. + There is another non-standard property, Xuc, which matches any charac- + ter that can be represented by a Universal Character Name in C++ and + other programming languages. These are the characters $, @, ` (grave + accent), and all characters with Unicode code points greater than or + equal to U+00A0, except for the surrogates U+D800 to U+DFFF. Note that + most base (ASCII) characters are excluded. (Universal Character Names + are of the form \uHHHH or \UHHHHHHHH where H is a hexadecimal digit. Note that the Xuc property does not match these sequences but the char- acters that they represent.) Resetting the match start - In normal use, the escape sequence \K causes any previously matched + In normal use, the escape sequence \K causes any previously matched characters not to be included in the final matched sequence that is re- turned. For example, the pattern: foo\Kbar - matches "foobar", but reports that it has matched "bar". \K does not + matches "foobar", but reports that it has matched "bar". \K does not interact with anchoring in any way. The pattern: ^foo\Kbar - matches only when the subject begins with "foobar" (in single line - mode), though it again reports the matched string as "bar". This fea- - ture is similar to a lookbehind assertion (described below), but the + matches only when the subject begins with "foobar" (in single line + mode), though it again reports the matched string as "bar". This fea- + ture is similar to a lookbehind assertion (described below), but the part of the pattern that precedes \K is not constrained to match a lim- - ited number of characters, as is required for a lookbehind assertion. - The use of \K does not interfere with the setting of captured sub- + ited number of characters, as is required for a lookbehind assertion. + The use of \K does not interfere with the setting of captured sub- strings. For example, when the pattern (foo)\Kbar matches "foobar", the first substring is still set to "foo". - From version 5.32.0 Perl forbids the use of \K in lookaround asser- - tions. From release 10.38 PCRE2 also forbids this by default. However, - the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option can be used when calling - pcre2_compile() to re-enable the previous behaviour. When this option + From version 5.32.0 Perl forbids the use of \K in lookaround asser- + tions. From release 10.38 PCRE2 also forbids this by default. However, + the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option can be used when calling + pcre2_compile() to re-enable the previous behaviour. When this option is set, \K is acted upon when it occurs inside positive assertions, but - is ignored in negative assertions. Note that when a pattern such as - (?=ab\K) matches, the reported start of the match can be greater than - the end of the match. Using \K in a lookbehind assertion at the start - of a pattern can also lead to odd effects. For example, consider this + is ignored in negative assertions. Note that when a pattern such as + (?=ab\K) matches, the reported start of the match can be greater than + the end of the match. Using \K in a lookbehind assertion at the start + of a pattern can also lead to odd effects. For example, consider this pattern: (?<=\Kfoo)bar - If the subject is "foobar", a call to pcre2_match() with a starting - offset of 3 succeeds and reports the matching string as "foobar", that - is, the start of the reported match is earlier than where the match + If the subject is "foobar", a call to pcre2_match() with a starting + offset of 3 succeeds and reports the matching string as "foobar", that + is, the start of the reported match is earlier than where the match started. Simple assertions - The final use of backslash is for certain simple assertions. An asser- - tion specifies a condition that has to be met at a particular point in - a match, without consuming any characters from the subject string. The - use of groups for more complicated assertions is described below. The + The final use of backslash is for certain simple assertions. An asser- + tion specifies a condition that has to be met at a particular point in + a match, without consuming any characters from the subject string. The + use of groups for more complicated assertions is described below. The backslashed assertions are: \b matches at a word boundary @@ -7828,193 +7981,193 @@ BACKSLASH \z matches only at the end of the subject \G matches at the first matching position in the subject - Inside a character class, \b has a different meaning; it matches the - backspace character. If any other of these assertions appears in a + Inside a character class, \b has a different meaning; it matches the + backspace character. If any other of these assertions appears in a character class, an "invalid escape sequence" error is generated. - A word boundary is a position in the subject string where the current - character and the previous character do not both match \w or \W (i.e. - one matches \w and the other matches \W), or the start or end of the - string if the first or last character matches \w, respectively. When - PCRE2 is built with Unicode support, the meanings of \w and \W can be + A word boundary is a position in the subject string where the current + character and the previous character do not both match \w or \W (i.e. + one matches \w and the other matches \W), or the start or end of the + string if the first or last character matches \w, respectively. When + PCRE2 is built with Unicode support, the meanings of \w and \W can be changed by setting the PCRE2_UCP option. When this is done, it also af- - fects \b and \B. Neither PCRE2 nor Perl has a separate "start of word" - or "end of word" metasequence. However, whatever follows \b normally - determines which it is. For example, the fragment \ba matches "a" at + fects \b and \B. Neither PCRE2 nor Perl has a separate "start of word" + or "end of word" metasequence. However, whatever follows \b normally + determines which it is. For example, the fragment \ba matches "a" at the start of a word. - The \A, \Z, and \z assertions differ from the traditional circumflex + The \A, \Z, and \z assertions differ from the traditional circumflex and dollar (described in the next section) in that they only ever match - at the very start and end of the subject string, whatever options are - set. Thus, they are independent of multiline mode. These three asser- - tions are not affected by the PCRE2_NOTBOL or PCRE2_NOTEOL options, - which affect only the behaviour of the circumflex and dollar metachar- - acters. However, if the startoffset argument of pcre2_match() is non- - zero, indicating that matching is to start at a point other than the - beginning of the subject, \A can never match. The difference between - \Z and \z is that \Z matches before a newline at the end of the string + at the very start and end of the subject string, whatever options are + set. Thus, they are independent of multiline mode. These three asser- + tions are not affected by the PCRE2_NOTBOL or PCRE2_NOTEOL options, + which affect only the behaviour of the circumflex and dollar metachar- + acters. However, if the startoffset argument of pcre2_match() is non- + zero, indicating that matching is to start at a point other than the + beginning of the subject, \A can never match. The difference between + \Z and \z is that \Z matches before a newline at the end of the string as well as at the very end, whereas \z matches only at the end. - The \G assertion is true only when the current matching position is at - the start point of the matching process, as specified by the startoff- - set argument of pcre2_match(). It differs from \A when the value of - startoffset is non-zero. By calling pcre2_match() multiple times with - appropriate arguments, you can mimic Perl's /g option, and it is in + The \G assertion is true only when the current matching position is at + the start point of the matching process, as specified by the startoff- + set argument of pcre2_match(). It differs from \A when the value of + startoffset is non-zero. By calling pcre2_match() multiple times with + appropriate arguments, you can mimic Perl's /g option, and it is in this kind of implementation where \G can be useful. - Note, however, that PCRE2's implementation of \G, being true at the - starting character of the matching process, is subtly different from - Perl's, which defines it as true at the end of the previous match. In - Perl, these can be different when the previously matched string was + Note, however, that PCRE2's implementation of \G, being true at the + starting character of the matching process, is subtly different from + Perl's, which defines it as true at the end of the previous match. In + Perl, these can be different when the previously matched string was empty. Because PCRE2 does just one match at a time, it cannot reproduce this behaviour. - If all the alternatives of a pattern begin with \G, the expression is + If all the alternatives of a pattern begin with \G, the expression is anchored to the starting match position, and the "anchored" flag is set in the compiled regular expression. CIRCUMFLEX AND DOLLAR - The circumflex and dollar metacharacters are zero-width assertions. - That is, they test for a particular condition being true without con- + The circumflex and dollar metacharacters are zero-width assertions. + That is, they test for a particular condition being true without con- suming any characters from the subject string. These two metacharacters - are concerned with matching the starts and ends of lines. If the new- - line convention is set so that only the two-character sequence CRLF is - recognized as a newline, isolated CR and LF characters are treated as + are concerned with matching the starts and ends of lines. If the new- + line convention is set so that only the two-character sequence CRLF is + recognized as a newline, isolated CR and LF characters are treated as ordinary data characters, and are not recognized as newlines. Outside a character class, in the default matching mode, the circumflex - character is an assertion that is true only if the current matching - point is at the start of the subject string. If the startoffset argu- - ment of pcre2_match() is non-zero, or if PCRE2_NOTBOL is set, circum- - flex can never match if the PCRE2_MULTILINE option is unset. Inside a - character class, circumflex has an entirely different meaning (see be- + character is an assertion that is true only if the current matching + point is at the start of the subject string. If the startoffset argu- + ment of pcre2_match() is non-zero, or if PCRE2_NOTBOL is set, circum- + flex can never match if the PCRE2_MULTILINE option is unset. Inside a + character class, circumflex has an entirely different meaning (see be- low). - Circumflex need not be the first character of the pattern if a number - of alternatives are involved, but it should be the first thing in each - alternative in which it appears if the pattern is ever to match that - branch. If all possible alternatives start with a circumflex, that is, - if the pattern is constrained to match only at the start of the sub- - ject, it is said to be an "anchored" pattern. (There are also other + Circumflex need not be the first character of the pattern if a number + of alternatives are involved, but it should be the first thing in each + alternative in which it appears if the pattern is ever to match that + branch. If all possible alternatives start with a circumflex, that is, + if the pattern is constrained to match only at the start of the sub- + ject, it is said to be an "anchored" pattern. (There are also other constructs that can cause a pattern to be anchored.) - The dollar character is an assertion that is true only if the current - matching point is at the end of the subject string, or immediately be- - fore a newline at the end of the string (by default), unless PCRE2_NO- - TEOL is set. Note, however, that it does not actually match the new- - line. Dollar need not be the last character of the pattern if a number - of alternatives are involved, but it should be the last item in any - branch in which it appears. Dollar has no special meaning in a charac- + The dollar character is an assertion that is true only if the current + matching point is at the end of the subject string, or immediately be- + fore a newline at the end of the string (by default), unless PCRE2_NO- + TEOL is set. Note, however, that it does not actually match the new- + line. Dollar need not be the last character of the pattern if a number + of alternatives are involved, but it should be the last item in any + branch in which it appears. Dollar has no special meaning in a charac- ter class. - The meaning of dollar can be changed so that it matches only at the - very end of the string, by setting the PCRE2_DOLLAR_ENDONLY option at + The meaning of dollar can be changed so that it matches only at the + very end of the string, by setting the PCRE2_DOLLAR_ENDONLY option at compile time. This does not affect the \Z assertion. The meanings of the circumflex and dollar metacharacters are changed if - the PCRE2_MULTILINE option is set. When this is the case, a dollar - character matches before any newlines in the string, as well as at the - very end, and a circumflex matches immediately after internal newlines - as well as at the start of the subject string. It does not match after - a newline that ends the string, for compatibility with Perl. However, + the PCRE2_MULTILINE option is set. When this is the case, a dollar + character matches before any newlines in the string, as well as at the + very end, and a circumflex matches immediately after internal newlines + as well as at the start of the subject string. It does not match after + a newline that ends the string, for compatibility with Perl. However, this can be changed by setting the PCRE2_ALT_CIRCUMFLEX option. - For example, the pattern /^abc$/ matches the subject string "def\nabc" - (where \n represents a newline) in multiline mode, but not otherwise. - Consequently, patterns that are anchored in single line mode because - all branches start with ^ are not anchored in multiline mode, and a - match for circumflex is possible when the startoffset argument of - pcre2_match() is non-zero. The PCRE2_DOLLAR_ENDONLY option is ignored + For example, the pattern /^abc$/ matches the subject string "def\nabc" + (where \n represents a newline) in multiline mode, but not otherwise. + Consequently, patterns that are anchored in single line mode because + all branches start with ^ are not anchored in multiline mode, and a + match for circumflex is possible when the startoffset argument of + pcre2_match() is non-zero. The PCRE2_DOLLAR_ENDONLY option is ignored if PCRE2_MULTILINE is set. - When the newline convention (see "Newline conventions" below) recog- - nizes the two-character sequence CRLF as a newline, this is preferred, - even if the single characters CR and LF are also recognized as new- - lines. For example, if the newline convention is "any", a multiline - mode circumflex matches before "xyz" in the string "abc\r\nxyz" rather - than after CR, even though CR on its own is a valid newline. (It also + When the newline convention (see "Newline conventions" below) recog- + nizes the two-character sequence CRLF as a newline, this is preferred, + even if the single characters CR and LF are also recognized as new- + lines. For example, if the newline convention is "any", a multiline + mode circumflex matches before "xyz" in the string "abc\r\nxyz" rather + than after CR, even though CR on its own is a valid newline. (It also matches at the very start of the string, of course.) - Note that the sequences \A, \Z, and \z can be used to match the start - and end of the subject in both modes, and if all branches of a pattern - start with \A it is always anchored, whether or not PCRE2_MULTILINE is + Note that the sequences \A, \Z, and \z can be used to match the start + and end of the subject in both modes, and if all branches of a pattern + start with \A it is always anchored, whether or not PCRE2_MULTILINE is set. FULL STOP (PERIOD, DOT) AND \N Outside a character class, a dot in the pattern matches any one charac- - ter in the subject string except (by default) a character that signi- + ter in the subject string except (by default) a character that signi- fies the end of a line. One or more characters may be specified as line terminators (see "Newline conventions" above). - Dot never matches a single line-ending character. When the two-charac- - ter sequence CRLF is the only line ending, dot does not match CR if it - is immediately followed by LF, but otherwise it matches all characters - (including isolated CRs and LFs). When ANYCRLF is selected for line - endings, no occurrences of CR of LF match dot. When all Unicode line + Dot never matches a single line-ending character. When the two-charac- + ter sequence CRLF is the only line ending, dot does not match CR if it + is immediately followed by LF, but otherwise it matches all characters + (including isolated CRs and LFs). When ANYCRLF is selected for line + endings, no occurrences of CR of LF match dot. When all Unicode line endings are being recognized, dot does not match CR or LF or any of the other line ending characters. - The behaviour of dot with regard to newlines can be changed. If the - PCRE2_DOTALL option is set, a dot matches any one character, without - exception. If the two-character sequence CRLF is present in the sub- + The behaviour of dot with regard to newlines can be changed. If the + PCRE2_DOTALL option is set, a dot matches any one character, without + exception. If the two-character sequence CRLF is present in the sub- ject string, it takes two dots to match it. - The handling of dot is entirely independent of the handling of circum- - flex and dollar, the only relationship being that they both involve + The handling of dot is entirely independent of the handling of circum- + flex and dollar, the only relationship being that they both involve newlines. Dot has no special meaning in a character class. - The escape sequence \N when not followed by an opening brace behaves - like a dot, except that it is not affected by the PCRE2_DOTALL option. - In other words, it matches any character except one that signifies the + The escape sequence \N when not followed by an opening brace behaves + like a dot, except that it is not affected by the PCRE2_DOTALL option. + In other words, it matches any character except one that signifies the end of a line. When \N is followed by an opening brace it has a different meaning. See - the section entitled "Non-printing characters" above for details. Perl - also uses \N{name} to specify characters by Unicode name; PCRE2 does + the section entitled "Non-printing characters" above for details. Perl + also uses \N{name} to specify characters by Unicode name; PCRE2 does not support this. MATCHING A SINGLE CODE UNIT - Outside a character class, the escape sequence \C matches any one code - unit, whether or not a UTF mode is set. In the 8-bit library, one code - unit is one byte; in the 16-bit library it is a 16-bit unit; in the - 32-bit library it is a 32-bit unit. Unlike a dot, \C always matches - line-ending characters. The feature is provided in Perl in order to + Outside a character class, the escape sequence \C matches any one code + unit, whether or not a UTF mode is set. In the 8-bit library, one code + unit is one byte; in the 16-bit library it is a 16-bit unit; in the + 32-bit library it is a 32-bit unit. Unlike a dot, \C always matches + line-ending characters. The feature is provided in Perl in order to match individual bytes in UTF-8 mode, but it is unclear how it can use- fully be used. - Because \C breaks up characters into individual code units, matching - one unit with \C in UTF-8 or UTF-16 mode means that the rest of the + Because \C breaks up characters into individual code units, matching + one unit with \C in UTF-8 or UTF-16 mode means that the rest of the string may start with a malformed UTF character. This has undefined re- sults, because PCRE2 assumes that it is matching character by character in a valid UTF string (by default it checks the subject string's valid- - ity at the start of processing unless the PCRE2_NO_UTF_CHECK or + ity at the start of processing unless the PCRE2_NO_UTF_CHECK or PCRE2_MATCH_INVALID_UTF option is used). - An application can lock out the use of \C by setting the - PCRE2_NEVER_BACKSLASH_C option when compiling a pattern. It is also + An application can lock out the use of \C by setting the + PCRE2_NEVER_BACKSLASH_C option when compiling a pattern. It is also possible to build PCRE2 with the use of \C permanently disabled. - PCRE2 does not allow \C to appear in lookbehind assertions (described - below) in UTF-8 or UTF-16 modes, because this would make it impossible - to calculate the length of the lookbehind. Neither the alternative + PCRE2 does not allow \C to appear in lookbehind assertions (described + below) in UTF-8 or UTF-16 modes, because this would make it impossible + to calculate the length of the lookbehind. Neither the alternative matching function pcre2_dfa_match() nor the JIT optimizer support \C in these UTF modes. The former gives a match-time error; the latter fails to optimize and so the match is always run using the interpreter. - In the 32-bit library, however, \C is always supported (when not ex- - plicitly locked out) because it always matches a single code unit, + In the 32-bit library, however, \C is always supported (when not ex- + plicitly locked out) because it always matches a single code unit, whether or not UTF-32 is specified. In general, the \C escape sequence is best avoided. However, one way of - using it that avoids the problem of malformed UTF-8 or UTF-16 charac- - ters is to use a lookahead to check the length of the next character, - as in this pattern, which could be used with a UTF-8 string (ignore + using it that avoids the problem of malformed UTF-8 or UTF-16 charac- + ters is to use a lookahead to check the length of the next character, + as in this pattern, which could be used with a UTF-8 string (ignore white space and line breaks): (?| (?=[\x00-\x7f])(\C) | @@ -8022,11 +8175,11 @@ MATCHING A SINGLE CODE UNIT (?=[\x{800}-\x{ffff}])(\C)(\C)(\C) | (?=[\x{10000}-\x{1fffff}])(\C)(\C)(\C)(\C)) - In this example, a group that starts with (?| resets the capturing - parentheses numbers in each alternative (see "Duplicate Group Numbers" + In this example, a group that starts with (?| resets the capturing + parentheses numbers in each alternative (see "Duplicate Group Numbers" below). The assertions at the start of each branch check the next UTF-8 - character for values whose encoding uses 1, 2, 3, or 4 bytes, respec- - tively. The character's individual bytes are then captured by the ap- + character for values whose encoding uses 1, 2, 3, or 4 bytes, respec- + tively. The character's individual bytes are then captured by the ap- propriate number of \C groups. @@ -8034,223 +8187,223 @@ SQUARE BRACKETS AND CHARACTER CLASSES An opening square bracket introduces a character class, terminated by a closing square bracket. A closing square bracket on its own is not spe- - cial by default. If a closing square bracket is required as a member + cial by default. If a closing square bracket is required as a member of the class, it should be the first data character in the class (after - an initial circumflex, if present) or escaped with a backslash. This - means that, by default, an empty class cannot be defined. However, if - the PCRE2_ALLOW_EMPTY_CLASS option is set, a closing square bracket at + an initial circumflex, if present) or escaped with a backslash. This + means that, by default, an empty class cannot be defined. However, if + the PCRE2_ALLOW_EMPTY_CLASS option is set, a closing square bracket at the start does end the (empty) class. - A character class matches a single character in the subject. A matched + A character class matches a single character in the subject. A matched character must be in the set of characters defined by the class, unless - the first character in the class definition is a circumflex, in which + the first character in the class definition is a circumflex, in which case the subject character must not be in the set defined by the class. - If a circumflex is actually required as a member of the class, ensure + If a circumflex is actually required as a member of the class, ensure it is not the first character, or escape it with a backslash. For example, the character class [aeiou] matches any lower case English - vowel, whereas [^aeiou] matches all other characters. Note that a cir- - cumflex is just a convenient notation for specifying the characters - that are in the class by enumerating those that are not. A class that + vowel, whereas [^aeiou] matches all other characters. Note that a cir- + cumflex is just a convenient notation for specifying the characters + that are in the class by enumerating those that are not. A class that starts with a circumflex is not an assertion; it still consumes a char- - acter from the subject string, and therefore it fails to match if the + acter from the subject string, and therefore it fails to match if the current pointer is at the end of the string. - Characters in a class may be specified by their code points using \o, - \x, or \N{U+hh..} in the usual way. When caseless matching is set, any - letters in a class represent both their upper case and lower case ver- - sions, so for example, a caseless [aeiou] matches "A" as well as "a", - and a caseless [^aeiou] does not match "A", whereas a caseful version - would. Note that there are two ASCII characters, K and S, that, in ad- - dition to their lower case ASCII equivalents, are case-equivalent with - Unicode U+212A (Kelvin sign) and U+017F (long S) respectively when ei- + Characters in a class may be specified by their code points using \o, + \x, or \N{U+hh..} in the usual way. When caseless matching is set, any + letters in a class represent both their upper case and lower case ver- + sions, so for example, a caseless [aeiou] matches "A" as well as "a", + and a caseless [^aeiou] does not match "A", whereas a caseful version + would. Note that there are two ASCII characters, K and S, that, in ad- + dition to their lower case ASCII equivalents, are case-equivalent with + Unicode U+212A (Kelvin sign) and U+017F (long S) respectively when ei- ther PCRE2_UTF or PCRE2_UCP is set. If you do not want these ASCII/non- - ASCII case equivalences, you can suppress them by setting PCRE2_EX- - TRA_CASELESS_RESTRICT, either as an option in a compile context, or by + ASCII case equivalences, you can suppress them by setting PCRE2_EX- + TRA_CASELESS_RESTRICT, either as an option in a compile context, or by including (*CASELESS_RESTRICT) or (?r) within a pattern. - Characters that might indicate line breaks are never treated in any - special way when matching character classes, whatever line-ending se- - quence is in use, and whatever setting of the PCRE2_DOTALL and - PCRE2_MULTILINE options is used. A class such as [^a] always matches + Characters that might indicate line breaks are never treated in any + special way when matching character classes, whatever line-ending se- + quence is in use, and whatever setting of the PCRE2_DOTALL and + PCRE2_MULTILINE options is used. A class such as [^a] always matches one of these characters. The generic character type escape sequences \d, \D, \h, \H, \p, \P, \s, - \S, \v, \V, \w, and \W may appear in a character class, and add the - characters that they match to the class. For example, [\dABCDEF] - matches any hexadecimal digit. In UTF modes, the PCRE2_UCP option af- + \S, \v, \V, \w, and \W may appear in a character class, and add the + characters that they match to the class. For example, [\dABCDEF] + matches any hexadecimal digit. In UTF modes, the PCRE2_UCP option af- fects the meanings of \d, \s, \w and their upper case partners, just as it does when they appear outside a character class, as described in the - section entitled "Generic character types" above. The escape sequence - \b has a different meaning inside a character class; it matches the - backspace character. The sequences \B, \R, and \X are not special in- - side a character class. Like any other unrecognized escape sequences, - they cause an error. The same is true for \N when not followed by an + section entitled "Generic character types" above. The escape sequence + \b has a different meaning inside a character class; it matches the + backspace character. The sequences \B, \R, and \X are not special in- + side a character class. Like any other unrecognized escape sequences, + they cause an error. The same is true for \N when not followed by an opening brace. - The minus (hyphen) character can be used to specify a range of charac- - ters in a character class. For example, [d-m] matches any letter be- - tween d and m, inclusive. If a minus character is required in a class, - it must be escaped with a backslash or appear in a position where it - cannot be interpreted as indicating a range, typically as the first or + The minus (hyphen) character can be used to specify a range of charac- + ters in a character class. For example, [d-m] matches any letter be- + tween d and m, inclusive. If a minus character is required in a class, + it must be escaped with a backslash or appear in a position where it + cannot be interpreted as indicating a range, typically as the first or last character in the class, or immediately after a range. For example, [b-d-z] matches letters in the range b to d, a hyphen character, or z. - There is some special treatment for alphabetic ranges in EBCDIC envi- + There is some special treatment for alphabetic ranges in EBCDIC envi- ronments; see the section "EBCDIC environments" below. Perl treats a hyphen as a literal if it appears before or after a POSIX class (see below) or before or after a character type escape such as \d - or \H. However, unless the hyphen is the last character in the class, - Perl outputs a warning in its warning mode, as this is most likely a - user error. As PCRE2 has no facility for warning, an error is given in + or \H. However, unless the hyphen is the last character in the class, + Perl outputs a warning in its warning mode, as this is most likely a + user error. As PCRE2 has no facility for warning, an error is given in these cases. It is not possible to have the literal character "]" as the end charac- - ter of a range. A pattern such as [W-]46] is interpreted as a class of - two characters ("W" and "-") followed by a literal string "46]", so it - would match "W46]" or "-46]". However, if the "]" is escaped with a - backslash it is interpreted as the end of a range, so [W-\]46] is in- - terpreted as a class containing a range and two other characters. The - octal or hexadecimal representation of "]" can also be used to end a + ter of a range. A pattern such as [W-]46] is interpreted as a class of + two characters ("W" and "-") followed by a literal string "46]", so it + would match "W46]" or "-46]". However, if the "]" is escaped with a + backslash it is interpreted as the end of a range, so [W-\]46] is in- + terpreted as a class containing a range and two other characters. The + octal or hexadecimal representation of "]" can also be used to end a range. Ranges normally include all code points between the start and end char- - acters, inclusive. They can also be used for code points specified nu- - merically, for example [\000-\037]. Ranges can include any characters - that are valid for the current mode. In any UTF mode, the so-called - "surrogate" characters (those whose code points lie between 0xd800 and - 0xdfff inclusive) may not be specified explicitly by default (the - PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES option disables this check). How- + acters, inclusive. They can also be used for code points specified nu- + merically, for example [\000-\037]. Ranges can include any characters + that are valid for the current mode. In any UTF mode, the so-called + "surrogate" characters (those whose code points lie between 0xd800 and + 0xdfff inclusive) may not be specified explicitly by default (the + PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES option disables this check). How- ever, ranges such as [\x{d7ff}-\x{e000}], which include the surrogates, are always permitted. If a range that includes letters is used when caseless matching is set, it matches the letters in either case. For example, [W-c] is equivalent - to [][\\^_`wxyzabc], matched caselessly, and in a non-UTF mode, if - character tables for a French locale are in use, [\xc8-\xcb] matches + to [][\\^_`wxyzabc], matched caselessly, and in a non-UTF mode, if + character tables for a French locale are in use, [\xc8-\xcb] matches accented E characters in both cases. - A circumflex can conveniently be used with the upper case character - types to specify a more restricted set of characters than the matching - lower case type. For example, the class [^\W_] matches any letter or + A circumflex can conveniently be used with the upper case character + types to specify a more restricted set of characters than the matching + lower case type. For example, the class [^\W_] matches any letter or digit, but not underscore, whereas [\w] includes underscore. A positive character class should be read as "something OR something OR ..." and a negative class as "NOT something AND NOT something AND NOT ...". - The metacharacters that are recognized in character classes are back- - slash, hyphen (when it can be interpreted as specifying a range), cir- - cumflex (only at the start), and the terminating closing square - bracket. An opening square bracket is also special when it can be in- - terpreted as introducing a POSIX class (see "Posix character classes" - below), or a special compatibility feature (see "Compatibility feature - for word boundaries" below. Escaping any non-alphanumeric character in + The metacharacters that are recognized in character classes are back- + slash, hyphen (when it can be interpreted as specifying a range), cir- + cumflex (only at the start), and the terminating closing square + bracket. An opening square bracket is also special when it can be in- + terpreted as introducing a POSIX class (see "Posix character classes" + below), or a special compatibility feature (see "Compatibility feature + for word boundaries" below. Escaping any non-alphanumeric character in a class turns it into a literal, whether or not it would otherwise be a metacharacter. PERL EXTENDED CHARACTER CLASSES - From release 10.45 PCRE2 supports Perl's (?[...]) extended character + From release 10.45 PCRE2 supports Perl's (?[...]) extended character class syntax. This can be used to perform set operations such as inter- section on character classes. - The syntax permitted within (?[...]) is quite different to ordinary - character classes. Inside the extended class, there is an expression - syntax consisting of "atoms", operators, and ordinary parentheses "()" - used for grouping. Such classes always have the Perl /xx modifier - (PCRE2 option PCRE2_EXTENDED_MORE) turned on within them. This means - that literal space and tab characters are ignored everywhere in the + The syntax permitted within (?[...]) is quite different to ordinary + character classes. Inside the extended class, there is an expression + syntax consisting of "atoms", operators, and ordinary parentheses "()" + used for grouping. Such classes always have the Perl /xx modifier + (PCRE2 option PCRE2_EXTENDED_MORE) turned on within them. This means + that literal space and tab characters are ignored everywhere in the class. - The allowed atoms are individual characters specified by escape se- - quences such as \n or \x{123}, character types such as \d, POSIX + The allowed atoms are individual characters specified by escape se- + quences such as \n or \x{123}, character types such as \d, POSIX classes such as [:alpha:], and nested ordinary (non-extended) character classes. For example, in (?[\d & [...]]) the nested class [...] follows - the usual rules for ordinary character classes, in which parentheses - are not metacharacters, and character literals and ranges are permit- + the usual rules for ordinary character classes, in which parentheses + are not metacharacters, and character literals and ranges are permit- ted. - Character literals and ranges may not appear outside a nested ordinary - character class because they are not atoms in the extended syntax. The - extended syntax does not introduce any additional escape sequences, so + Character literals and ranges may not appear outside a nested ordinary + character class because they are not atoms in the extended syntax. The + extended syntax does not introduce any additional escape sequences, so (?[\y]) is an unknown escape, as it would be in [\y]. In the extended syntax, ^ does not negate a class (except within an or- - dinary class nested inside an extended class); it is instead a binary + dinary class nested inside an extended class); it is instead a binary operator. - The binary operators are "&" (intersection), "|" or "+" (union), "-" - (subtraction) and "^" (symmetric difference). These are left-associa- - tive and "&" has higher (tighter) precedence, while the others have - equal lower precedence. The one prefix unary operator is "!" (comple- + The binary operators are "&" (intersection), "|" or "+" (union), "-" + (subtraction) and "^" (symmetric difference). These are left-associa- + tive and "&" has higher (tighter) precedence, while the others have + equal lower precedence. The one prefix unary operator is "!" (comple- ment), with highest precedence. UTS#18 EXTENDED CHARACTER CLASSES - The PCRE2_ALT_EXTENDED_CLASS option enables an alternative to Perl's - (?[...]) syntax, allowing instead extended class behaviour inside or- - dinary [...] character classes. This altered syntax for [...] classes - is loosely described by the Unicode standard UTS#18. The PCRE2_ALT_EX- - TENDED_CLASS option does not prevent use of (?[...]) classes; it just - changes the meaning of all [...] classes that are not nested inside a + The PCRE2_ALT_EXTENDED_CLASS option enables an alternative to Perl's + (?[...]) syntax, allowing instead extended class behaviour inside or- + dinary [...] character classes. This altered syntax for [...] classes + is loosely described by the Unicode standard UTS#18. The PCRE2_ALT_EX- + TENDED_CLASS option does not prevent use of (?[...]) classes; it just + changes the meaning of all [...] classes that are not nested inside a Perl (?[...]) class. Firstly, in ordinary Perl [...] syntax, an expression such as "[a[]" is - a character class with two literal characters "a" and "[", but in + a character class with two literal characters "a" and "[", but in UTS#18 extended classes the "[" character becomes an additional - metacharacter within classes, denoting the start of a nested class, so + metacharacter within classes, denoting the start of a nested class, so a literal "[" must be escaped as "\[". - Secondly, within the UTS#18 extended syntax, there are operators "||", - "&&", "--" and "~~" which denote character class union, intersection, - subtraction, and symmetric difference respectively. In standard Perl - syntax, these would simply be needlessly-repeated literals (except for - "--" which could be the start or end of a range). In UTS#18 extended + Secondly, within the UTS#18 extended syntax, there are operators "||", + "&&", "--" and "~~" which denote character class union, intersection, + subtraction, and symmetric difference respectively. In standard Perl + syntax, these would simply be needlessly-repeated literals (except for + "--" which could be the start or end of a range). In UTS#18 extended classes these operators can be used in constructs such as [\p{L}--[QW]] - for "Unicode letters, other than Q and W". A literal "-" at the start - or end of a range must be escaped, so while "[--1]" in Perl syntax is - the range from hyphen to "1", it must be escaped as "[\--1]" in UTS#18 + for "Unicode letters, other than Q and W". A literal "-" at the start + or end of a range must be escaped, so while "[--1]" in Perl syntax is + the range from hyphen to "1", it must be escaped as "[\--1]" in UTS#18 extended classes. Unlike Perl's (?[...]) extended classes, the PCRE2_EXTENDED_MORE option - to ignore space and tab characters is not automatically enabled for + to ignore space and tab characters is not automatically enabled for UTS#18 extended classes, but it is honoured if set. - Extended UTS#18 classes can be nested, and nested classes are them- + Extended UTS#18 classes can be nested, and nested classes are them- selves extended classes (unlike Perl, where nested classes must be sim- - ple classes). For example, [\p{L}&&[\p{Thai}||\p{Greek}]] matches any - letter that is in the Thai or Greek scripts. Note that this means that - no special grouping characters (such as the parentheses used in Perl's + ple classes). For example, [\p{L}&&[\p{Thai}||\p{Greek}]] matches any + letter that is in the Thai or Greek scripts. Note that this means that + no special grouping characters (such as the parentheses used in Perl's (?[...]) class syntax) are needed. - Individual class items (literal characters, literal ranges, properties - such as \d or \p{...}, and nested classes) can be combined by juxtapo- + Individual class items (literal characters, literal ranges, properties + such as \d or \p{...}, and nested classes) can be combined by juxtapo- sition or by an operator. Juxtaposition is the implicit union operator, - and binds more tightly than any explicit operator. Thus a sequence of + and binds more tightly than any explicit operator. Thus a sequence of literals and/or ranges behaves as if it is enclosed in square brackets. - For example, [A-Z0-9&&[^E8]] is the same as [[A-Z0-9]&&[^E8]], which + For example, [A-Z0-9&&[^E8]] is the same as [[A-Z0-9]&&[^E8]], which matches any upper case alphanumeric character except "E" or "8". Precedence between the explicit operators is not defined, so mixing op- - erators is a syntax error. For example, [A&&B--C] is an error, but + erators is a syntax error. For example, [A&&B--C] is an error, but [A&&[B--C]] is valid. - This is an emerging syntax which is being adopted gradually across the - regex ecosystem: for example JavaScript adopted the "/v" flag in EC- - MAScript 2024; Python's "re" module reserves the syntax for future use + This is an emerging syntax which is being adopted gradually across the + regex ecosystem: for example JavaScript adopted the "/v" flag in EC- + MAScript 2024; Python's "re" module reserves the syntax for future use with a FutureWarning for unescaped use of "[" as a literal within char- - acter classes. Due to UTS#18 providing insufficient guidance, engines - interpret the syntax differently. Rust's "regex" crate and Python's - "regex" PyPi module both implement UTS#18 extended classes, but with - slight incompatibilities ([A||B&&C] is parsed as [A||[B&&C]] in + acter classes. Due to UTS#18 providing insufficient guidance, engines + interpret the syntax differently. Rust's "regex" crate and Python's + "regex" PyPi module both implement UTS#18 extended classes, but with + slight incompatibilities ([A||B&&C] is parsed as [A||[B&&C]] in Python's "regex" but as [[A||B]&&C] in Rust's "regex"). - PCRE2's syntax adds syntax restrictions similar to ECMASCript's /v - flag, so that all the UTS#18 extended classes accepted as valid by - PCRE2 have the property that they are interpreted either with the same - behaviour, or as invalid, by all other major engines. Please file an + PCRE2's syntax adds syntax restrictions similar to ECMASCript's /v + flag, so that all the UTS#18 extended classes accepted as valid by + PCRE2 have the property that they are interpreted either with the same + behaviour, or as invalid, by all other major engines. Please file an issue if you are aware of cross-engine differences in behaviour between PCRE2 and another major engine. @@ -8258,8 +8411,8 @@ UTS#18 EXTENDED CHARACTER CLASSES POSIX CHARACTER CLASSES Perl supports the POSIX notation for character classes. This uses names - enclosed by [: and :] within the enclosing square brackets. PCRE2 also - supports this notation, in both ordinary and extended classes. For ex- + enclosed by [: and :] within the enclosing square brackets. PCRE2 also + supports this notation, in both ordinary and extended classes. For ex- ample, [01[:alpha:]%] @@ -8282,14 +8435,14 @@ POSIX CHARACTER CLASSES word "word" characters (same as \w) xdigit hexadecimal digits - The default "space" characters are HT (9), LF (10), VT (11), FF (12), - CR (13), and space (32). If locale-specific matching is taking place, - the list of space characters may be different; there may be fewer or - more of them. "Space" and \s match the same set of characters, as do + The default "space" characters are HT (9), LF (10), VT (11), FF (12), + CR (13), and space (32). If locale-specific matching is taking place, + the list of space characters may be different; there may be fewer or + more of them. "Space" and \s match the same set of characters, as do "word" and \w. - The name "word" is a Perl extension, and "blank" is a GNU extension - from Perl 5.8. Another Perl extension is negation, which is indicated + The name "word" is a Perl extension, and "blank" is a GNU extension + from Perl 5.8. Another Perl extension is negation, which is indicated by a ^ character after the colon. For example, [12[:^digit:]] @@ -8300,9 +8453,9 @@ POSIX CHARACTER CLASSES By default, characters with values greater than 127 do not match any of the POSIX character classes, although this may be different for charac- - ters in the range 128-255 when locale-specific matching is happening. - However, in UCP mode, unless certain options are set (see below), some - of the classes are changed so that Unicode character properties are + ters in the range 128-255 when locale-specific matching is happening. + However, in UCP mode, unless certain options are set (see below), some + of the classes are changed so that Unicode character properties are used. This is achieved by replacing POSIX classes with other sequences, as follows: @@ -8316,10 +8469,10 @@ POSIX CHARACTER CLASSES [:upper:] becomes \p{Lu} [:word:] becomes \p{Xwd} - Negated versions, such as [:^alpha:] use \P instead of \p. Four other + Negated versions, such as [:^alpha:] use \P instead of \p. Four other POSIX classes are handled specially in UCP mode: - [:graph:] This matches characters that have glyphs that mark the page + [:graph:] This matches characters that have glyphs that mark the page when printed. In Unicode property terms, it matches all char- acters with the L, M, N, P, S, or Cf properties, except for: @@ -8328,73 +8481,73 @@ POSIX CHARACTER CLASSES U+2066 - U+2069 Various "isolate"s - [:print:] This matches the same characters as [:graph:] plus space - characters that are not controls, that is, characters with + [:print:] This matches the same characters as [:graph:] plus space + characters that are not controls, that is, characters with the Zs property. [:punct:] This matches all characters that have the Unicode P (punctua- - tion) property, plus those characters with code points less + tion) property, plus those characters with code points less than 256 that have the S (Symbol) property. [:xdigit:] - In addition to the ASCII hexadecimal digits, this also - matches the "fullwidth" versions of those characters, whose - Unicode code points start at U+FF10. This is a change that + In addition to the ASCII hexadecimal digits, this also + matches the "fullwidth" versions of those characters, whose + Unicode code points start at U+FF10. This is a change that was made in PCRE2 release 10.43 for Perl compatibility. - The other POSIX classes are unchanged by PCRE2_UCP, and match only + The other POSIX classes are unchanged by PCRE2_UCP, and match only characters with code points less than 256. There are two options that can be used to restrict the POSIX classes to - ASCII characters when PCRE2_UCP is set. The option PCRE2_EX- - TRA_ASCII_DIGIT affects just [:digit:] and [:xdigit:]. Within a pat- - tern, this can be set and unset by (?aT) and (?-aT). The PCRE2_EX- - TRA_ASCII_POSIX option disables UCP processing for all POSIX classes, - including [:digit:] and [:xdigit:]. Within a pattern, (?aP) and (?-aP) + ASCII characters when PCRE2_UCP is set. The option PCRE2_EX- + TRA_ASCII_DIGIT affects just [:digit:] and [:xdigit:]. Within a pat- + tern, this can be set and unset by (?aT) and (?-aT). The PCRE2_EX- + TRA_ASCII_POSIX option disables UCP processing for all POSIX classes, + including [:digit:] and [:xdigit:]. Within a pattern, (?aP) and (?-aP) set and unset both these options for consistency. COMPATIBILITY FEATURE FOR WORD BOUNDARIES - In the POSIX.2 compliant library that was included in 4.4BSD Unix, the - ugly syntax [[:<:]] and [[:>:]] is used for matching "start of word" + In the POSIX.2 compliant library that was included in 4.4BSD Unix, the + ugly syntax [[:<:]] and [[:>:]] is used for matching "start of word" and "end of word". PCRE2 treats these items as follows: [[:<:]] is converted to \b(?=\w) [[:>:]] is converted to \b(?<=\w) Only these exact character sequences are recognized. A sequence such as - [a[:<:]b] provokes error for an unrecognized POSIX class name. This - support is not compatible with Perl. It is provided to help migrations + [a[:<:]b] provokes error for an unrecognized POSIX class name. This + support is not compatible with Perl. It is provided to help migrations from other environments, and is best not used in any new patterns. Note - that \b matches at the start and the end of a word (see "Simple asser- - tions" above), and in a Perl-style pattern the preceding or following - character normally shows which is wanted, without the need for the as- - sertions that are used above in order to give exactly the POSIX behav- - iour. Note also that the PCRE2_UCP option changes the meaning of \w - (and therefore \b) by default, so it also affects these POSIX se- + that \b matches at the start and the end of a word (see "Simple asser- + tions" above), and in a Perl-style pattern the preceding or following + character normally shows which is wanted, without the need for the as- + sertions that are used above in order to give exactly the POSIX behav- + iour. Note also that the PCRE2_UCP option changes the meaning of \w + (and therefore \b) by default, so it also affects these POSIX se- quences. VERTICAL BAR - Vertical bar characters are used to separate alternative patterns. For + Vertical bar characters are used to separate alternative patterns. For example, the pattern gilbert|sullivan - matches either "gilbert" or "sullivan". Any number of alternatives may - appear, and an empty alternative is permitted (matching the empty + matches either "gilbert" or "sullivan". Any number of alternatives may + appear, and an empty alternative is permitted (matching the empty string). The matching process tries each alternative in turn, from left - to right, and the first one that succeeds is used. If the alternatives - are within a group (defined below), "succeeds" means matching the rest + to right, and the first one that succeeds is used. If the alternatives + are within a group (defined below), "succeeds" means matching the rest of the main pattern as well as the alternative in the group. INTERNAL OPTION SETTING - The settings of several options can be changed within a pattern by a - sequence of letters enclosed between "(?" and ")". The following are + The settings of several options can be changed within a pattern by a + sequence of letters enclosed between "(?" and ")". The following are Perl-compatible, and are described in detail in the pcre2api documenta- tion. The option letters are: @@ -8407,21 +8560,21 @@ INTERNAL OPTION SETTING For example, (?im) sets caseless, multiline matching. It is also possi- ble to unset these options by preceding the relevant letters with a hy- - phen, for example (?-im). The two "extended" options are not indepen- + phen, for example (?-im). The two "extended" options are not indepen- dent; unsetting either one cancels the effects of both of them. - A combined setting and unsetting such as (?im-sx), which sets - PCRE2_CASELESS and PCRE2_MULTILINE while unsetting PCRE2_DOTALL and - PCRE2_EXTENDED, is also permitted. Only one hyphen may appear in the - options string. If a letter appears both before and after the hyphen, - the option is unset. An empty options setting "(?)" is allowed. Need- + A combined setting and unsetting such as (?im-sx), which sets + PCRE2_CASELESS and PCRE2_MULTILINE while unsetting PCRE2_DOTALL and + PCRE2_EXTENDED, is also permitted. Only one hyphen may appear in the + options string. If a letter appears both before and after the hyphen, + the option is unset. An empty options setting "(?)" is allowed. Need- less to say, it has no effect. - If the first character following (? is a circumflex, it causes all of - the above options to be unset. Letters may follow the circumflex to + If the first character following (? is a circumflex, it causes all of + the above options to be unset. Letters may follow the circumflex to cause some options to be re-instated, but a hyphen may not appear. - Some PCRE2-specific options can be changed by the same mechanism using + Some PCRE2-specific options can be changed by the same mechanism using these pairs or individual letters: aD for PCRE2_EXTRA_ASCII_BSD @@ -8433,36 +8586,36 @@ INTERNAL OPTION SETTING J for PCRE2_DUPNAMES U for PCRE2_UNGREEDY - However, except for 'r', these are not unset by (?^), which is equiva- - lent to (?-imnrsx). If 'a' is not followed by any of the upper case + However, except for 'r', these are not unset by (?^), which is equiva- + lent to (?-imnrsx). If 'a' is not followed by any of the upper case letters shown above, it sets (or unsets) all the ASCII options. - PCRE2_EXTRA_ASCII_DIGIT has no additional effect when PCRE2_EX- - TRA_ASCII_POSIX is set, but including it in (?aP) means that (?-aP) + PCRE2_EXTRA_ASCII_DIGIT has no additional effect when PCRE2_EX- + TRA_ASCII_POSIX is set, but including it in (?aP) means that (?-aP) suppresses all ASCII restrictions for POSIX classes. - When one of these option changes occurs at top level (that is, not in- - side group parentheses), the change applies until a subsequent change, - or the end of the pattern. An option change within a group (see below - for a description of groups) affects only that part of the group that - follows it. At the end of the group these options are reset to the + When one of these option changes occurs at top level (that is, not in- + side group parentheses), the change applies until a subsequent change, + or the end of the pattern. An option change within a group (see below + for a description of groups) affects only that part of the group that + follows it. At the end of the group these options are reset to the state they were before the group. For example, (a(?i)b)c - matches abc and aBc and no other strings (assuming PCRE2_CASELESS is - not set externally). Any changes made in one alternative do carry on + matches abc and aBc and no other strings (assuming PCRE2_CASELESS is + not set externally). Any changes made in one alternative do carry on into subsequent branches within the same group. For example, (a(?i)b|c) - matches "ab", "aB", "c", and "C", even though when matching "C" the - first branch is abandoned before the option setting. This is because - the effects of option settings happen at compile time. There would be + matches "ab", "aB", "c", and "C", even though when matching "C" the + first branch is abandoned before the option setting. This is because + the effects of option settings happen at compile time. There would be some very weird behaviour otherwise. - As a convenient shorthand, if any option settings are required at the - start of a non-capturing group (see the next section), the option let- + As a convenient shorthand, if any option settings are required at the + start of a non-capturing group (see the next section), the option let- ters may appear between the "?" and the ":". Thus the two patterns (?i:saturday|sunday) @@ -8470,39 +8623,39 @@ INTERNAL OPTION SETTING match exactly the same set of strings. - Note: There are other PCRE2-specific options, applying to the whole - pattern, which can be set by the application when the compiling func- - tion is called. In addition, the pattern can contain special leading - sequences such as (*CRLF) to override what the application has set or - what has been defaulted. Details are given in the section entitled + Note: There are other PCRE2-specific options, applying to the whole + pattern, which can be set by the application when the compiling func- + tion is called. In addition, the pattern can contain special leading + sequences such as (*CRLF) to override what the application has set or + what has been defaulted. Details are given in the section entitled "Newline sequences" above. There are also the (*UTF) and (*UCP) leading - sequences that can be used to set UTF and Unicode property modes; they - are equivalent to setting the PCRE2_UTF and PCRE2_UCP options, respec- + sequences that can be used to set UTF and Unicode property modes; they + are equivalent to setting the PCRE2_UTF and PCRE2_UCP options, respec- tively. However, the application can set the PCRE2_NEVER_UTF or - PCRE2_NEVER_UCP options, which lock out the use of the (*UTF) and + PCRE2_NEVER_UCP options, which lock out the use of the (*UTF) and (*UCP) sequences. GROUPS - Groups are delimited by parentheses (round brackets), which can be + Groups are delimited by parentheses (round brackets), which can be nested. Turning part of a pattern into a group does two things: 1. It localizes a set of alternatives. For example, the pattern cat(aract|erpillar|) - matches "cataract", "caterpillar", or "cat". Without the parentheses, + matches "cataract", "caterpillar", or "cat". Without the parentheses, it would match "cataract", "erpillar" or an empty string. - 2. It creates a "capture group". This means that, when the whole pat- - tern matches, the portion of the subject string that matched the group - is passed back to the caller, separately from the portion that matched - the whole pattern. (This applies only to the traditional matching + 2. It creates a "capture group". This means that, when the whole pat- + tern matches, the portion of the subject string that matched the group + is passed back to the caller, separately from the portion that matched + the whole pattern. (This applies only to the traditional matching function; the DFA matching function does not support capturing.) Opening parentheses are counted from left to right (starting from 1) to - obtain numbers for capture groups. For example, if the string "the red + obtain numbers for capture groups. For example, if the string "the red king" is matched against the pattern the ((red|white) (king|queen)) @@ -8510,11 +8663,11 @@ GROUPS the captured substrings are "red king", "red", and "king", and are num- bered 1, 2, and 3, respectively. - The fact that plain parentheses fulfil two functions is not always - helpful. There are often times when grouping is required without cap- - turing. If an opening parenthesis is followed by a question mark and a - colon, the group does not do any capturing, and is not counted when - computing the number of any subsequent capture groups. For example, if + The fact that plain parentheses fulfil two functions is not always + helpful. There are often times when grouping is required without cap- + turing. If an opening parenthesis is followed by a question mark and a + colon, the group does not do any capturing, and is not counted when + computing the number of any subsequent capture groups. For example, if the string "the white queen" is matched against the pattern the ((?:red|white) (king|queen)) @@ -8522,16 +8675,16 @@ GROUPS the captured substrings are "white queen" and "queen", and are numbered 1 and 2. The maximum number of capture groups is 65535. - As a convenient shorthand, if any option settings are required at the - start of a non-capturing group, the option letters may appear between + As a convenient shorthand, if any option settings are required at the + start of a non-capturing group, the option letters may appear between the "?" and the ":". Thus the two patterns (?i:saturday|sunday) (?:(?i)saturday|sunday) match exactly the same set of strings. Because alternative branches are - tried from left to right, and options are not reset until the end of - the group is reached, an option setting in one branch does affect sub- + tried from left to right, and options are not reset until the end of + the group is reached, an option setting in one branch does affect sub- sequent branches, so the above patterns match "SUNDAY" as well as "Sat- urday". @@ -8539,19 +8692,19 @@ GROUPS DUPLICATE GROUP NUMBERS Perl 5.10 introduced a feature whereby each alternative in a group uses - the same numbers for its capturing parentheses. Such a group starts - with (?| and is itself a non-capturing group. For example, consider + the same numbers for its capturing parentheses. Such a group starts + with (?| and is itself a non-capturing group. For example, consider this pattern: (?|(Sat)ur|(Sun))day - Because the two alternatives are inside a (?| group, both sets of cap- - turing parentheses are numbered one. Thus, when the pattern matches, - you can look at captured substring number one, whichever alternative - matched. This construct is useful when you want to capture part, but + Because the two alternatives are inside a (?| group, both sets of cap- + turing parentheses are numbered one. Thus, when the pattern matches, + you can look at captured substring number one, whichever alternative + matched. This construct is useful when you want to capture part, but not all, of one of a number of alternatives. Inside a (?| group, paren- - theses are numbered as usual, but the number is reset at the start of - each branch. The numbers of any capturing parentheses that follow the + theses are numbered as usual, but the number is reset at the start of + each branch. The numbers of any capturing parentheses that follow the whole group start after the highest number used in any branch. The fol- lowing example is taken from the Perl documentation. The numbers under- neath show in which buffer the captured content will be stored. @@ -8560,13 +8713,13 @@ DUPLICATE GROUP NUMBERS / ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x # 1 2 2 3 2 3 4 - A backreference to a capture group uses the most recent value that is + A backreference to a capture group uses the most recent value that is set for the group. The following pattern matches "abcabc" or "defdef": /(?|(abc)|(def))\1/ - In contrast, a subroutine call to a capture group always refers to the - first one in the pattern with the given number. The following pattern + In contrast, a subroutine call to a capture group always refers to the + first one in the pattern with the given number. The following pattern matches "abcabc" or "defabc": /(?|(abc)|(def))(?1)/ @@ -8577,24 +8730,24 @@ DUPLICATE GROUP NUMBERS If a condition test for a group's having matched refers to a non-unique number, the test is true if any group with that number has matched. - An alternative approach to using this "branch reset" feature is to use + An alternative approach to using this "branch reset" feature is to use duplicate named groups, as described in the next section. NAMED CAPTURE GROUPS Identifying capture groups by number is simple, but it can be very hard - to keep track of the numbers in complicated patterns. Furthermore, if - an expression is modified, the numbers may change. To help with this - difficulty, PCRE2 supports the naming of capture groups. This feature - was not added to Perl until release 5.10. Python had the feature ear- - lier, and PCRE1 introduced it at release 4.0, using the Python syntax. + to keep track of the numbers in complicated patterns. Furthermore, if + an expression is modified, the numbers may change. To help with this + difficulty, PCRE2 supports the naming of capture groups. This feature + was not added to Perl until release 5.10. Python had the feature ear- + lier, and PCRE1 introduced it at release 4.0, using the Python syntax. PCRE2 supports both the Perl and the Python syntax. - In PCRE2, a capture group can be named in one of three ways: + In PCRE2, a capture group can be named in one of three ways: (?...) or (?'name'...) as in Perl, or (?P...) as in Python. Names may be up to 128 code units long. When PCRE2_UTF is not set, they - may contain only ASCII alphanumeric characters and underscores, but + may contain only ASCII alphanumeric characters and underscores, but must start with a non-digit. When PCRE2_UTF is set, the syntax of group names is extended to allow any Unicode letter or Unicode decimal digit. In other words, group names must match one of these patterns: @@ -8602,42 +8755,42 @@ NAMED CAPTURE GROUPS ^[_A-Za-z][_A-Za-z0-9]*\z when PCRE2_UTF is not set ^[_\p{L}][_\p{L}\p{Nd}]*\z when PCRE2_UTF is set - References to capture groups from other parts of the pattern, such as - backreferences, recursion, and conditions, can all be made by name as + References to capture groups from other parts of the pattern, such as + backreferences, recursion, and conditions, can all be made by name as well as by number. Named capture groups are allocated numbers as well as names, exactly as - if the names were not present. In both PCRE2 and Perl, capture groups - are primarily identified by numbers; any names are just aliases for + if the names were not present. In both PCRE2 and Perl, capture groups + are primarily identified by numbers; any names are just aliases for these numbers. The PCRE2 API provides function calls for extracting the - complete name-to-number translation table from a compiled pattern, as - well as convenience functions for extracting captured substrings by + complete name-to-number translation table from a compiled pattern, as + well as convenience functions for extracting captured substrings by name. - Warning: When more than one capture group has the same number, as de- + Warning: When more than one capture group has the same number, as de- scribed in the previous section, a name given to one of them applies to - all of them. Perl allows identically numbered groups to have different + all of them. Perl allows identically numbered groups to have different names. Consider this pattern, where there are two capture groups, both numbered 1: (?|(?aa)|(?bb)) - Perl allows this, with both names AA and BB as aliases of group 1. + Perl allows this, with both names AA and BB as aliases of group 1. Thus, after a successful match, both names yield the same value (either "aa" or "bb"). - In an attempt to reduce confusion, PCRE2 does not allow the same group + In an attempt to reduce confusion, PCRE2 does not allow the same group number to be associated with more than one name. The example above pro- - vokes a compile-time error. However, there is still scope for confu- + vokes a compile-time error. However, there is still scope for confu- sion. Consider this pattern: (?|(?aa)|(bb)) Although the second group number 1 is not explicitly named, the name AA - is still an alias for any group 1. Whether the pattern matches "aa" or + is still an alias for any group 1. Whether the pattern matches "aa" or "bb", a reference by name to group AA yields the matched string. - By default, a name must be unique within a pattern, except that dupli- + By default, a name must be unique within a pattern, except that dupli- cate names are permitted for groups with the same number, for example: (?|(?aa)|(?bb)) @@ -8646,10 +8799,10 @@ NAMED CAPTURE GROUPS NAMES option at compile time, or by the use of (?J) within the pattern, as described in the section entitled "Internal Option Setting" above. - Duplicate names can be useful for patterns where only one instance of - the named capture group can match. Suppose you want to match the name - of a weekday, either as a 3-letter abbreviation or as the full name, - and in both cases you want to extract the abbreviation. This pattern + Duplicate names can be useful for patterns where only one instance of + the named capture group can match. Suppose you want to match the name + of a weekday, either as a 3-letter abbreviation or as the full name, + and in both cases you want to extract the abbreviation. This pattern (ignoring the line breaks) does the job: (?J) @@ -8659,17 +8812,17 @@ NAMED CAPTURE GROUPS (?Thu)(?:rsday)?| (?Sat)(?:urday)? - There are five capture groups, but only one is ever set after a match. - The convenience functions for extracting the data by name returns the - substring for the first (and in this example, the only) group of that + There are five capture groups, but only one is ever set after a match. + The convenience functions for extracting the data by name returns the + substring for the first (and in this example, the only) group of that name that matched. This saves searching to find which numbered group it - was. (An alternative way of solving this problem is to use a "branch + was. (An alternative way of solving this problem is to use a "branch reset" group, as described in the previous section.) - If you make a backreference to a non-unique named group from elsewhere - in the pattern, the groups to which the name refers are checked in the - order in which they appear in the overall pattern. The first one that - is set is used for the reference. For example, this pattern matches + If you make a backreference to a non-unique named group from elsewhere + in the pattern, the groups to which the name refers are checked in the + order in which they appear in the overall pattern. The first one that + is set is used for the reference. For example, this pattern matches both "foofoo" and "barbar" but not "foobar" or "barfoo": (?J)(?:(?foo)|(?bar))\k @@ -8682,15 +8835,15 @@ NAMED CAPTURE GROUPS If you use a named reference in a condition test (see the section about conditions below), either to check whether a capture group has matched, or to check for recursion, all groups with the same name are tested. If - the condition is true for any one of them, the overall condition is - true. This is the same behaviour as testing by number. For further de- - tails of the interfaces for handling named capture groups, see the + the condition is true for any one of them, the overall condition is + true. This is the same behaviour as testing by number. For further de- + tails of the interfaces for handling named capture groups, see the pcre2api documentation. REPETITION - Repetition is specified by quantifiers, which may follow any one of + Repetition is specified by quantifiers, which may follow any one of these items: a literal data character @@ -8706,16 +8859,16 @@ REPETITION If a quantifier does not follow a repeatable item, an error occurs. The general repetition quantifier specifies a minimum and maximum number of - permitted matches by giving two numbers in curly brackets (braces), - separated by a comma. The numbers must be less than 65536, and the + permitted matches by giving two numbers in curly brackets (braces), + separated by a comma. The numbers must be less than 65536, and the first must be less than or equal to the second. For example, z{2,4} - matches "zz", "zzz", or "zzzz". A closing brace on its own is not a - special character. If the second number is omitted, but the comma is - present, there is no upper limit; if the second number and the comma - are both omitted, the quantifier specifies an exact number of required + matches "zz", "zzz", or "zzzz". A closing brace on its own is not a + special character. If the second number is omitted, but the comma is + present, there is no upper limit; if the second number and the comma + are both omitted, the quantifier specifies an exact number of required matches. Thus [aeiou]{3,} @@ -8724,65 +8877,65 @@ REPETITION \d{8} - matches exactly 8 digits. If the first number is omitted, the lower + matches exactly 8 digits. If the first number is omitted, the lower limit is taken as zero; in this case the upper limit must be present. X{,4} is interpreted as X{0,4} - This is a change in behaviour that happened in Perl 5.34.0 and PCRE2 - 10.43. In earlier versions such a sequence was not interpreted as a + This is a change in behaviour that happened in Perl 5.34.0 and PCRE2 + 10.43. In earlier versions such a sequence was not interpreted as a quantifier. Other regular expression engines may behave either way. - If the characters that follow an opening brace do not match the syntax + If the characters that follow an opening brace do not match the syntax of a quantifier, the brace is taken as a literal character. In particu- lar, this means that {,} is a literal string of three characters. Note that not every opening brace is potentially the start of a quanti- - fier because braces are used in other items such as \N{U+345} or + fier because braces are used in other items such as \N{U+345} or \k{name}. In UTF modes, quantifiers apply to characters rather than to individual - code units. Thus, for example, \x{100}{2} matches two characters, each + code units. Thus, for example, \x{100}{2} matches two characters, each of which is represented by a two-byte sequence in a UTF-8 string. Simi- - larly, \X{3} matches three Unicode extended grapheme clusters, each of - which may be several code units long (and they may be of different + larly, \X{3} matches three Unicode extended grapheme clusters, each of + which may be several code units long (and they may be of different lengths). The quantifier {0} is permitted, causing the expression to behave as if the previous item and the quantifier were not present. This may be use- - ful for capture groups that are referenced as subroutines from else- - where in the pattern (but see also the section entitled "Defining cap- + ful for capture groups that are referenced as subroutines from else- + where in the pattern (but see also the section entitled "Defining cap- ture groups for use by reference only" below). Except for parenthesized - groups, items that have a {0} quantifier are omitted from the compiled + groups, items that have a {0} quantifier are omitted from the compiled pattern. - For convenience, the three most common quantifiers have single-charac- + For convenience, the three most common quantifiers have single-charac- ter abbreviations: * is equivalent to {0,} + is equivalent to {1,} ? is equivalent to {0,1} - It is possible to construct infinite loops by following a group that - can match no characters with a quantifier that has no upper limit, for + It is possible to construct infinite loops by following a group that + can match no characters with a quantifier that has no upper limit, for example: (a?)* - Earlier versions of Perl and PCRE1 used to give an error at compile + Earlier versions of Perl and PCRE1 used to give an error at compile time for such patterns. However, because there are cases where this can be useful, such patterns are now accepted, but whenever an iteration of - such a group matches no characters, matching moves on to the next item - in the pattern instead of repeatedly matching an empty string. This - does not prevent backtracking into any of the iterations if a subse- + such a group matches no characters, matching moves on to the next item + in the pattern instead of repeatedly matching an empty string. This + does not prevent backtracking into any of the iterations if a subse- quent item fails to match. - By default, quantifiers are "greedy", that is, they match as much as - possible (up to the maximum number of permitted repetitions), without - causing the rest of the pattern to fail. The classic example of where + By default, quantifiers are "greedy", that is, they match as much as + possible (up to the maximum number of permitted repetitions), without + causing the rest of the pattern to fail. The classic example of where this gives problems is in trying to match comments in C programs. These - appear between /* and */ and within the comment, individual * and / - characters may appear. An attempt to match C comments by applying the + appear between /* and */ and within the comment, individual * and / + characters may appear. An attempt to match C comments by applying the pattern /\*.*\*/ @@ -8791,17 +8944,17 @@ REPETITION /* first comment */ not comment /* second comment */ - fails, because it matches the entire string owing to the greediness of - the .* item. However, if a quantifier is followed by a question mark, + fails, because it matches the entire string owing to the greediness of + the .* item. However, if a quantifier is followed by a question mark, it ceases to be greedy, and instead matches the minimum number of times possible, so the pattern /\*.*?\*/ - does the right thing with C comments. The meaning of the various quan- + does the right thing with C comments. The meaning of the various quan- tifiers is not otherwise changed, just the preferred number of matches. - Do not confuse this use of question mark with its use as a quantifier - in its own right. Because it has two uses, it can sometimes appear + Do not confuse this use of question mark with its use as a quantifier + in its own right. Because it has two uses, it can sometimes appear doubled, as in \d??\d @@ -8810,56 +8963,56 @@ REPETITION only way the rest of the pattern matches. If the PCRE2_UNGREEDY option is set (an option that is not available in - Perl), the quantifiers are not greedy by default, but individual ones - can be made greedy by following them with a question mark. In other + Perl), the quantifiers are not greedy by default, but individual ones + can be made greedy by following them with a question mark. In other words, it inverts the default behaviour. - When a parenthesized group is quantified with a minimum repeat count - that is greater than 1 or with a limited maximum, more memory is re- + When a parenthesized group is quantified with a minimum repeat count + that is greater than 1 or with a limited maximum, more memory is re- quired for the compiled pattern, in proportion to the size of the mini- mum or maximum. - If a pattern starts with .* or .{0,} and the PCRE2_DOTALL option - (equivalent to Perl's /s) is set, thus allowing the dot to match new- - lines, the pattern is implicitly anchored, because whatever follows - will be tried against every character position in the subject string, - so there is no point in retrying the overall match at any position af- - ter the first. PCRE2 normally treats such a pattern as though it were + If a pattern starts with .* or .{0,} and the PCRE2_DOTALL option + (equivalent to Perl's /s) is set, thus allowing the dot to match new- + lines, the pattern is implicitly anchored, because whatever follows + will be tried against every character position in the subject string, + so there is no point in retrying the overall match at any position af- + ter the first. PCRE2 normally treats such a pattern as though it were preceded by \A. - In cases where it is known that the subject string contains no new- - lines, it is worth setting PCRE2_DOTALL in order to obtain this opti- + In cases where it is known that the subject string contains no new- + lines, it is worth setting PCRE2_DOTALL in order to obtain this opti- mization, or alternatively, using ^ to indicate anchoring explicitly. - However, there are some cases where the optimization cannot be used. - When .* is inside capturing parentheses that are the subject of a - backreference elsewhere in the pattern, a match at the start may fail + However, there are some cases where the optimization cannot be used. + When .* is inside capturing parentheses that are the subject of a + backreference elsewhere in the pattern, a match at the start may fail where a later one succeeds. Consider, for example: (.*)abc\1 - If the subject is "xyz123abc123" the match point is the fourth charac- + If the subject is "xyz123abc123" the match point is the fourth charac- ter. For this reason, such a pattern is not implicitly anchored. - Another case where implicit anchoring is not applied is when the lead- - ing .* is inside an atomic group. Once again, a match at the start may + Another case where implicit anchoring is not applied is when the lead- + ing .* is inside an atomic group. Once again, a match at the start may fail where a later one succeeds. Consider this pattern: (?>.*?a)b - It matches "ab" in the subject "aab". The use of the backtracking con- - trol verbs (*PRUNE) and (*SKIP) also disable this optimization. To do - so explicitly, either pass the compile option PCRE2_NO_DOTSTAR_ANCHOR, + It matches "ab" in the subject "aab". The use of the backtracking con- + trol verbs (*PRUNE) and (*SKIP) also disable this optimization. To do + so explicitly, either pass the compile option PCRE2_NO_DOTSTAR_ANCHOR, or call pcre2_set_optimize() with a PCRE2_DOTSTAR_ANCHOR_OFF directive. - When a capture group is repeated, the value captured is the substring + When a capture group is repeated, the value captured is the substring that matched the final iteration. For example, after (tweedle[dume]{3}\s*)+ has matched "tweedledum tweedledee" the value of the captured substring - is "tweedledee". However, if there are nested capture groups, the cor- - responding captured values may have been set in previous iterations. + is "tweedledee". However, if there are nested capture groups, the cor- + responding captured values may have been set in previous iterations. For example, after (a|(b))+ @@ -8869,57 +9022,57 @@ REPETITION ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS - With both maximizing ("greedy") and minimizing ("ungreedy" or "lazy") - repetition, failure of what follows normally causes the repeated item - to be re-evaluated to see if a different number of repeats allows the - rest of the pattern to match. Sometimes it is useful to prevent this, - either to change the nature of the match, or to cause it fail earlier - than it otherwise might, when the author of the pattern knows there is + With both maximizing ("greedy") and minimizing ("ungreedy" or "lazy") + repetition, failure of what follows normally causes the repeated item + to be re-evaluated to see if a different number of repeats allows the + rest of the pattern to match. Sometimes it is useful to prevent this, + either to change the nature of the match, or to cause it fail earlier + than it otherwise might, when the author of the pattern knows there is no point in carrying on. - Consider, for example, the pattern \d+foo when applied to the subject + Consider, for example, the pattern \d+foo when applied to the subject line 123456bar After matching all 6 digits and then failing to match "foo", the normal - action of the matcher is to try again with only 5 digits matching the - \d+ item, and then with 4, and so on, before ultimately failing. - "Atomic grouping" (a term taken from Jeffrey Friedl's book) provides + action of the matcher is to try again with only 5 digits matching the + \d+ item, and then with 4, and so on, before ultimately failing. + "Atomic grouping" (a term taken from Jeffrey Friedl's book) provides the means for specifying that once a group has matched, it is not to be re-evaluated in this way. - If we use atomic grouping for the previous example, the matcher gives - up immediately on failing to match "foo" the first time. The notation + If we use atomic grouping for the previous example, the matcher gives + up immediately on failing to match "foo" the first time. The notation is a kind of special parenthesis, starting with (?> as in this example: (?>\d+)foo - Perl 5.28 introduced an experimental alphabetic form starting with (* + Perl 5.28 introduced an experimental alphabetic form starting with (* which may be easier to remember: (*atomic:\d+)foo - This kind of parenthesized group "locks up" the part of the pattern it + This kind of parenthesized group "locks up" the part of the pattern it contains once it has matched, and a failure further into the pattern is - prevented from backtracking into it. Backtracking past it to previous + prevented from backtracking into it. Backtracking past it to previous items, however, works as normal. An alternative description is that a group of this type matches exactly - the string of characters that an identical standalone pattern would + the string of characters that an identical standalone pattern would match, if anchored at the current point in the subject string. - Atomic groups are not capture groups. Simple cases such as the above - example can be thought of as a maximizing repeat that must swallow - everything it can. So, while both \d+ and \d+? are prepared to adjust - the number of digits they match in order to make the rest of the pat- + Atomic groups are not capture groups. Simple cases such as the above + example can be thought of as a maximizing repeat that must swallow + everything it can. So, while both \d+ and \d+? are prepared to adjust + the number of digits they match in order to make the rest of the pat- tern match, (?>\d+) can only match an entire sequence of digits. - Atomic groups in general can of course contain arbitrarily complicated + Atomic groups in general can of course contain arbitrarily complicated expressions, and can be nested. However, when the contents of an atomic - group is just a single repeated item, as in the example above, a sim- - pler notation, called a "possessive quantifier" can be used. This con- - sists of an additional + character following a quantifier. Using this + group is just a single repeated item, as in the example above, a sim- + pler notation, called a "possessive quantifier" can be used. This con- + sists of an additional + character following a quantifier. Using this notation, the previous example can be rewritten as \d++foo @@ -8929,48 +9082,48 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS (abc|xyz){2,3}+ - Possessive quantifiers are always greedy; the setting of the PCRE2_UN- - GREEDY option is ignored. They are a convenient notation for the sim- - pler forms of atomic group. However, there is no difference in the - meaning of a possessive quantifier and the equivalent atomic group, - though there may be a performance difference; possessive quantifiers + Possessive quantifiers are always greedy; the setting of the PCRE2_UN- + GREEDY option is ignored. They are a convenient notation for the sim- + pler forms of atomic group. However, there is no difference in the + meaning of a possessive quantifier and the equivalent atomic group, + though there may be a performance difference; possessive quantifiers should be slightly faster. - The possessive quantifier syntax is an extension to the Perl 5.8 syn- - tax. Jeffrey Friedl originated the idea (and the name) in the first + The possessive quantifier syntax is an extension to the Perl 5.8 syn- + tax. Jeffrey Friedl originated the idea (and the name) in the first edition of his book. Mike McCloskey liked it, so implemented it when he - built Sun's Java package, and PCRE1 copied it from there. It found its + built Sun's Java package, and PCRE1 copied it from there. It found its way into Perl at release 5.10. - PCRE2 has an optimization that automatically "possessifies" certain - simple pattern constructs. For example, the sequence A+B is treated as - A++B because there is no point in backtracking into a sequence of A's - when B must follow. This feature can be disabled by the - PCRE2_NO_AUTO_POSSESS option, by calling pcre2_set_optimize() with a - PCRE2_AUTO_POSSESS_OFF directive, or by starting the pattern with + PCRE2 has an optimization that automatically "possessifies" certain + simple pattern constructs. For example, the sequence A+B is treated as + A++B because there is no point in backtracking into a sequence of A's + when B must follow. This feature can be disabled by the + PCRE2_NO_AUTO_POSSESS option, by calling pcre2_set_optimize() with a + PCRE2_AUTO_POSSESS_OFF directive, or by starting the pattern with (*NO_AUTO_POSSESS). When a pattern contains an unlimited repeat inside a group that can it- - self be repeated an unlimited number of times, the use of an atomic - group is the only way to avoid some failing matches taking a very long + self be repeated an unlimited number of times, the use of an atomic + group is the only way to avoid some failing matches taking a very long time indeed. The pattern (\D+|<\d+>)*[!?] - matches an unlimited number of substrings that either consist of non- - digits, or digits enclosed in <>, followed by either ! or ?. When it + matches an unlimited number of substrings that either consist of non- + digits, or digits enclosed in <>, followed by either ! or ?. When it matches, it runs quickly. However, if it is applied to aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - it takes a long time before reporting failure. This is because the - string can be divided between the internal \D+ repeat and the external - * repeat in a large number of ways, and all have to be tried. (The ex- + it takes a long time before reporting failure. This is because the + string can be divided between the internal \D+ repeat and the external + * repeat in a large number of ways, and all have to be tried. (The ex- ample uses [!?] rather than a single character at the end, because both PCRE2 and Perl have an optimization that allows for fast failure when a - single character is used. They remember the last single character that - is required for a match, and fail early if it is not present in the - string.) If the pattern is changed so that it uses an atomic group, + single character is used. They remember the last single character that + is required for a match, and fail early if it is not present in the + string.) If the pattern is changed so that it uses an atomic group, like this: ((?>\D+)|<\d+>)*[!?] @@ -8981,28 +9134,28 @@ ATOMIC GROUPING AND POSSESSIVE QUANTIFIERS BACKREFERENCES Outside a character class, a backslash followed by a digit greater than - 0 (and possibly further digits) is a backreference to a capture group + 0 (and possibly further digits) is a backreference to a capture group earlier (that is, to its left) in the pattern, provided there have been that many previous capture groups. - However, if the decimal number following the backslash is less than 8, - it is always taken as a backreference, and causes an error only if - there are not that many capture groups in the entire pattern. In other + However, if the decimal number following the backslash is less than 8, + it is always taken as a backreference, and causes an error only if + there are not that many capture groups in the entire pattern. In other words, the group that is referenced need not be to the left of the ref- - erence for numbers less than 8. A "forward backreference" of this type + erence for numbers less than 8. A "forward backreference" of this type can make sense when a repetition is involved and the group to the right has participated in an earlier iteration. - It is not possible to have a numerical "forward backreference" to a - group whose number is 8 or more using this syntax because a sequence - such as \50 is interpreted as a character defined in octal. See the + It is not possible to have a numerical "forward backreference" to a + group whose number is 8 or more using this syntax because a sequence + such as \50 is interpreted as a character defined in octal. See the subsection entitled "Non-printing characters" above for further details - of the handling of digits following a backslash. Other forms of back- - referencing do not suffer from this restriction. In particular, there + of the handling of digits following a backslash. Other forms of back- + referencing do not suffer from this restriction. In particular, there is no problem when named capture groups are used (see below). - Another way of avoiding the ambiguity inherent in the use of digits - following a backslash is to use the \g escape sequence. This escape + Another way of avoiding the ambiguity inherent in the use of digits + following a backslash is to use the \g escape sequence. This escape must be followed by a signed or unsigned number, optionally enclosed in braces. These examples are all identical: @@ -9010,54 +9163,54 @@ BACKREFERENCES (ring), \g1 (ring), \g{1} - An unsigned number specifies an absolute reference without the ambigu- + An unsigned number specifies an absolute reference without the ambigu- ity that is present in the older syntax. It is also useful when literal - digits follow the reference. A signed number is a relative reference. + digits follow the reference. A signed number is a relative reference. Consider this example: (abc(def)ghi)\g{-1} The sequence \g{-1} is a reference to the capture group whose number is - one less than the number of the next group to be started, so in this - example (where the next group would be numbered 3) is it equivalent to - \2, and \g{-2} would be equivalent to \1. Note that if this construct - is inside a capture group, that group is included in the count, so in + one less than the number of the next group to be started, so in this + example (where the next group would be numbered 3) is it equivalent to + \2, and \g{-2} would be equivalent to \1. Note that if this construct + is inside a capture group, that group is included in the count, so in this example \g{-2} also refers to group 1: (A)(\g{-2}B) - The use of relative references can be helpful in long patterns, and - also in patterns that are created by joining together fragments that + The use of relative references can be helpful in long patterns, and + also in patterns that are created by joining together fragments that contain references within themselves. - The sequence \g{+1} is a reference to the next capture group that is - started after this item, and \g{+2} refers to the one after that, and - so on. This kind of forward reference can be useful in patterns that + The sequence \g{+1} is a reference to the next capture group that is + started after this item, and \g{+2} refers to the one after that, and + so on. This kind of forward reference can be useful in patterns that repeat. Perl does not support the use of + in this way. - A backreference matches whatever actually most recently matched the - capture group in the current subject string, rather than anything at + A backreference matches whatever actually most recently matched the + capture group in the current subject string, rather than anything at all that matches the group (see "Groups as subroutines" below for a way of doing that). So the pattern (sens|respons)e and \1ibility - matches "sense and sensibility" and "response and responsibility", but - not "sense and responsibility". If caseful matching is in force at the - time of the backreference, the case of letters is relevant. For exam- + matches "sense and sensibility" and "response and responsibility", but + not "sense and responsibility". If caseful matching is in force at the + time of the backreference, the case of letters is relevant. For exam- ple, ((?i)rah)\s+\1 - matches "rah rah" and "RAH RAH", but not "RAH rah", even though the + matches "rah rah" and "RAH RAH", but not "RAH rah", even though the original capture group is matched caselessly. - There are several different ways of writing backreferences to named - capture groups. The .NET syntax is \k{name}, the Python syntax is - (?=name), and the original Perl syntax is \k or \k'name'. All of - these are now supported by both Perl and PCRE2. Perl 5.10's unified - backreference syntax, in which \g can be used for both numeric and - named references, is also supported by PCRE2. We could rewrite the + There are several different ways of writing backreferences to named + capture groups. The .NET syntax is \k{name}, the Python syntax is + (?=name), and the original Perl syntax is \k or \k'name'. All of + these are now supported by both Perl and PCRE2. Perl 5.10's unified + backreference syntax, in which \g can be used for both numeric and + named references, is also supported by PCRE2. We could rewrite the above example in any of the following ways: (?(?i)rah)\s+\k @@ -9065,120 +9218,120 @@ BACKREFERENCES (?P(?i)rah)\s+(?P=p1) (?(?i)rah)\s+\g{p1} - A capture group that is referenced by name may appear in the pattern + A capture group that is referenced by name may appear in the pattern before or after the reference. - There may be more than one backreference to the same group. If a group - has not actually been used in a particular match, backreferences to it + There may be more than one backreference to the same group. If a group + has not actually been used in a particular match, backreferences to it always fail by default. For example, the pattern (a|(bc))\2 - always fails if it starts to match "a" rather than "bc". However, if + always fails if it starts to match "a" rather than "bc". However, if the PCRE2_MATCH_UNSET_BACKREF option is set at compile time, a backref- erence to an unset value matches an empty string. - Because there may be many capture groups in a pattern, all digits fol- - lowing a backslash are taken as part of a potential backreference num- - ber. If the pattern continues with a digit character, some delimiter - must be used to terminate the backreference. If the PCRE2_EXTENDED or - PCRE2_EXTENDED_MORE option is set, this can be white space. Otherwise, + Because there may be many capture groups in a pattern, all digits fol- + lowing a backslash are taken as part of a potential backreference num- + ber. If the pattern continues with a digit character, some delimiter + must be used to terminate the backreference. If the PCRE2_EXTENDED or + PCRE2_EXTENDED_MORE option is set, this can be white space. Otherwise, the \g{} syntax or an empty comment (see "Comments" below) can be used. Recursive backreferences - A backreference that occurs inside the group to which it refers fails - when the group is first used, so, for example, (a\1) never matches. - However, such references can be useful inside repeated groups. For ex- + A backreference that occurs inside the group to which it refers fails + when the group is first used, so, for example, (a\1) never matches. + However, such references can be useful inside repeated groups. For ex- ample, the pattern (a|b\1)+ matches any number of "a"s and also "aba", "ababbaa" etc. At each iter- ation of the group, the backreference matches the character string cor- - responding to the previous iteration. In order for this to work, the - pattern must be such that the first iteration does not need to match - the backreference. This can be done using alternation, as in the exam- + responding to the previous iteration. In order for this to work, the + pattern must be such that the first iteration does not need to match + the backreference. This can be done using alternation, as in the exam- ple above, or by a quantifier with a minimum of zero. For versions of PCRE2 less than 10.25, backreferences of this type used - to cause the group that they reference to be treated as an atomic - group. This restriction no longer applies, and backtracking into such + to cause the group that they reference to be treated as an atomic + group. This restriction no longer applies, and backtracking into such groups can occur as normal. ASSERTIONS - An assertion is a test that does not consume any characters. The test - must succeed for the match to continue. The simple assertions coded as + An assertion is a test that does not consume any characters. The test + must succeed for the match to continue. The simple assertions coded as \b, \B, \A, \G, \Z, \z, ^ and $ are described above. - More complicated assertions are coded as parenthesized groups. If - matching such a group succeeds, matching continues after it, but with + More complicated assertions are coded as parenthesized groups. If + matching such a group succeeds, matching continues after it, but with the matching position in the subject string reset to what it was before the assertion was processed. - A special kind of assertion, called a "scan substring" assertion, - matches a subpattern against a previously captured substring. This is + A special kind of assertion, called a "scan substring" assertion, + matches a subpattern against a previously captured substring. This is described in the section entitled "Scan substring assertions" below. It is a PCRE2 extension, not compatible with Perl. The other goup-based assertions are of two kinds: those that look ahead - of the current position in the subject string, and those that look be- - hind it, and in each case an assertion may be positive (must match for + of the current position in the subject string, and those that look be- + hind it, and in each case an assertion may be positive (must match for the assertion to be true) or negative (must not match for the assertion to be true). - The Perl-compatible lookaround assertions are atomic. If an assertion - is true, but there is a subsequent matching failure, there is no back- - tracking into the assertion. However, there are some cases where non- - atomic assertions can be useful. PCRE2 has some support for these, de- + The Perl-compatible lookaround assertions are atomic. If an assertion + is true, but there is a subsequent matching failure, there is no back- + tracking into the assertion. However, there are some cases where non- + atomic assertions can be useful. PCRE2 has some support for these, de- scribed in the section entitled "Non-atomic assertions" below, but they are not Perl-compatible. - A lookaround assertion may appear as the condition in a conditional - group (see below). In this case, the result of matching the assertion + A lookaround assertion may appear as the condition in a conditional + group (see below). In this case, the result of matching the assertion determines which branch of the condition is followed. - Assertion groups are not capture groups. If an assertion contains cap- - ture groups within it, these are counted for the purposes of numbering - the capture groups in the whole pattern. Within each branch of an as- - sertion, locally captured substrings may be referenced in the usual - way. For example, a sequence such as (.)\g{-1} can be used to check + Assertion groups are not capture groups. If an assertion contains cap- + ture groups within it, these are counted for the purposes of numbering + the capture groups in the whole pattern. Within each branch of an as- + sertion, locally captured substrings may be referenced in the usual + way. For example, a sequence such as (.)\g{-1} can be used to check that two adjacent characters are the same. - When a branch within an assertion fails to match, any substrings that - were captured are discarded (as happens with any pattern branch that - fails to match). A negative assertion is true only when all its + When a branch within an assertion fails to match, any substrings that + were captured are discarded (as happens with any pattern branch that + fails to match). A negative assertion is true only when all its branches fail to match; this means that no captured substrings are ever - retained after a successful negative assertion. When an assertion con- + retained after a successful negative assertion. When an assertion con- tains a matching branch, what happens depends on the type of assertion. - For a positive assertion, internally captured substrings in the suc- - cessful branch are retained, and matching continues with the next pat- - tern item after the assertion. For a negative assertion, a matching - branch means that the assertion is not true. If such an assertion is - being used as a condition in a conditional group (see below), captured - substrings are retained, because matching continues with the "no" + For a positive assertion, internally captured substrings in the suc- + cessful branch are retained, and matching continues with the next pat- + tern item after the assertion. For a negative assertion, a matching + branch means that the assertion is not true. If such an assertion is + being used as a condition in a conditional group (see below), captured + substrings are retained, because matching continues with the "no" branch of the condition. For other failing negative assertions, control passes to the previous backtracking point, thus discarding any captured strings within the assertion. - Most assertion groups may be repeated; though it makes no sense to as- + Most assertion groups may be repeated; though it makes no sense to as- sert the same thing several times, the side effect of capturing in pos- itive assertions may occasionally be useful. However, an assertion that - forms the condition for a conditional group may not be quantified. - PCRE2 used to restrict the repetition of assertions, but from release - 10.35 the only restriction is that an unlimited maximum repetition is - changed to be one more than the minimum. For example, {3,} is treated + forms the condition for a conditional group may not be quantified. + PCRE2 used to restrict the repetition of assertions, but from release + 10.35 the only restriction is that an unlimited maximum repetition is + changed to be one more than the minimum. For example, {3,} is treated as {3,4}. Alphabetic assertion names - Traditionally, symbolic sequences such as (?= and (?<= have been used - to specify lookaround assertions. Perl 5.28 introduced some experimen- + Traditionally, symbolic sequences such as (?= and (?<= have been used + to specify lookaround assertions. Perl 5.28 introduced some experimen- tal alphabetic alternatives which might be easier to remember. They all - start with (* instead of (? and must be written using lower case let- + start with (* instead of (? and must be written using lower case let- ters. PCRE2 supports the following synonyms: (*positive_lookahead: or (*pla: is the same as (?= @@ -9186,8 +9339,8 @@ ASSERTIONS (*positive_lookbehind: or (*plb: is the same as (?<= (*negative_lookbehind: or (*nlb: is the same as (? .*? \b\1\b ){2} - For a subject such as "word1 word2 word3 word2 word3 word4" the result - is "word3". How does it work? At the start, ^(?x) anchors the pattern + For a subject such as "word1 word2 word3 word2 word3 word4" the result + is "word3". How does it work? At the start, ^(?x) anchors the pattern and sets the "x" option, which causes white space (introduced for read- - ability) to be ignored. Inside the assertion, the greedy .* at first + ability) to be ignored. Inside the assertion, the greedy .* at first consumes the entire string, but then has to backtrack until the rest of - the assertion can match a word, which is captured by group 1. In other - words, when the assertion first succeeds, it captures the right-most + the assertion can match a word, which is captured by group 1. In other + words, when the assertion first succeeds, it captures the right-most word in the string. - The current matching point is then reset to the start of the subject, - and the rest of the pattern match checks for two occurrences of the - captured word, using an ungreedy .*? to scan from the left. If this - succeeds, we are done, but if the last word in the string does not oc- - cur twice, this part of the pattern fails. If a traditional atomic - lookahead (?= or (*pla: had been used, the assertion could not be re- + The current matching point is then reset to the start of the subject, + and the rest of the pattern match checks for two occurrences of the + captured word, using an ungreedy .*? to scan from the left. If this + succeeds, we are done, but if the last word in the string does not oc- + cur twice, this part of the pattern fails. If a traditional atomic + lookahead (?= or (*pla: had been used, the assertion could not be re- entered, and the whole match would fail. The pattern would succeed only if the very last word in the subject was found twice. - Using a non-atomic lookahead, however, means that when the last word - does not occur twice in the string, the lookahead can backtrack and - find the second-last word, and so on, until either the match succeeds, + Using a non-atomic lookahead, however, means that when the last word + does not occur twice in the string, the lookahead can backtrack and + find the second-last word, and so on, until either the match succeeds, or all words have been tested. Two conditions must be met for a non-atomic assertion to be useful: the - contents of one or more capturing groups must change after a backtrack - into the assertion, and there must be a backreference to a changed - group later in the pattern. If this is not the case, the rest of the - pattern match fails exactly as before because nothing has changed, so + contents of one or more capturing groups must change after a backtrack + into the assertion, and there must be a backreference to a changed + group later in the pattern. If this is not the case, the rest of the + pattern match fails exactly as before because nothing has changed, so using a non-atomic assertion just wastes resources. - There is one exception to backtracking into a non-atomic assertion. If - an (*ACCEPT) control verb is triggered, the assertion succeeds atomi- - cally. That is, a subsequent match failure cannot backtrack into the + There is one exception to backtracking into a non-atomic assertion. If + an (*ACCEPT) control verb is triggered, the assertion succeeds atomi- + cally. That is, a subsequent match failure cannot backtrack into the assertion. - Non-atomic assertions are not supported by the alternative matching + Non-atomic assertions are not supported by the alternative matching function pcre2_dfa_match(). They are supported by JIT, but only if they do not contain any control verbs such as (*ACCEPT). (This may change in future). Note that assertions that appear as conditions for conditional @@ -9396,15 +9549,15 @@ NON-ATOMIC ASSERTIONS SCAN SUBSTRING ASSERTIONS - A special kind of assertion, not compatible with Perl, makes it possi- + A special kind of assertion, not compatible with Perl, makes it possi- ble to check the contents of a captured substring by matching it with a - subpattern. Because this involves capturing, this feature is not sup- + subpattern. Because this involves capturing, this feature is not sup- ported by pcre2_dfa_match(). - A scan substring assertion starts with the sequence (*scan_substring: + A scan substring assertion starts with the sequence (*scan_substring: or (*scs: which is followed by a list of substring numbers (absolute or - relative) and/or substring names enclosed in single quotes or angle - brackets, all within parentheses. The rest of the item is the subpat- + relative) and/or substring names enclosed in single quotes or angle + brackets, all within parentheses. The rest of the item is the subpat- tern that is applied to the substring, as shown in these examples: (*scan_substring:(1)...) @@ -9412,86 +9565,86 @@ SCAN SUBSTRING ASSERTIONS (*scs:('AB')...) (*scs:(1,'AB',-2)...) - The list of groups is checked in the order they are given, and it is + The list of groups is checked in the order they are given, and it is the contents of the first one that is found to be set that are scanned. - When PCRE2_DUPNAMES is set and there are ambiguous group names, all - groups with the same name are checked in numerical order. A scan sub- - string assertion fails if none of the groups it references have been + When PCRE2_DUPNAMES is set and there are ambiguous group names, all + groups with the same name are checked in numerical order. A scan sub- + string assertion fails if none of the groups it references have been set. The pattern match on the substring is always anchored, that is, it must - match from the start of the substring. There is no "bumpalong" if it - does not match at the start. The end of the subject is temporarily re- - set to be the end of the substring, so \Z, \z, and $ will match there. - However, the start of the subject is not reset. This means that ^ + match from the start of the substring. There is no "bumpalong" if it + does not match at the start. The end of the subject is temporarily re- + set to be the end of the substring, so \Z, \z, and $ will match there. + However, the start of the subject is not reset. This means that ^ matches only if the substring is actually at the start of the main sub- - ject, but it also means that lookbehind assertions into what precedes + ject, but it also means that lookbehind assertions into what precedes the substring are possible. - Here is a very simple example: find a word that contains the rare (in + Here is a very simple example: find a word that contains the rare (in English) sequence of letters "rh" not at the start: \b(\w++)(*scs:(1).+rh) - The first group captures a word which is then scanned by the second - group. This example does not actually need this heavyweight feature; + The first group captures a word which is then scanned by the second + group. This example does not actually need this heavyweight feature; the same match can be achieved with: \b\w+?rh\w*\b - When things are more complicated, however, scanning a captured sub- - string can be a useful way to describe the required match. For exmple, - there is a rather complicated pattern in the PCRE2 test data that + When things are more complicated, however, scanning a captured sub- + string can be a useful way to describe the required match. For exmple, + there is a rather complicated pattern in the PCRE2 test data that checks an entire subject string for a palindrome, that is, the sequence - of letters is the same in both directions. Suppose you want to search + of letters is the same in both directions. Suppose you want to search for individual words of two or more characters such as "level" that are palindromes: (\b\w{2,}+\b)(*scs:(1)...palindrome-matching-pattern...) Within a substring scanning subpattern, references to other groups work - as normal. Capturing groups may appear, and will retain their values + as normal. Capturing groups may appear, and will retain their values during ongoing matching if the assertion succeeds. SCRIPT RUNS - In concept, a script run is a sequence of characters that are all from - the same Unicode script such as Latin or Greek. However, because some - scripts are commonly used together, and because some diacritical and - other marks are used with multiple scripts, it is not that simple. + In concept, a script run is a sequence of characters that are all from + the same Unicode script such as Latin or Greek. However, because some + scripts are commonly used together, and because some diacritical and + other marks are used with multiple scripts, it is not that simple. There is a full description of the rules that PCRE2 uses in the section entitled "Script Runs" in the pcre2unicode documentation. - If part of a pattern is enclosed between (*script_run: or (*sr: and a - closing parenthesis, it fails if the sequence of characters that it - matches are not a script run. After a failure, normal backtracking oc- - curs. Script runs can be used to detect spoofing attacks using charac- - ters that look the same, but are from different scripts. The string - "paypal.com" is an infamous example, where the letters could be a mix- + If part of a pattern is enclosed between (*script_run: or (*sr: and a + closing parenthesis, it fails if the sequence of characters that it + matches are not a script run. After a failure, normal backtracking oc- + curs. Script runs can be used to detect spoofing attacks using charac- + ters that look the same, but are from different scripts. The string + "paypal.com" is an infamous example, where the letters could be a mix- ture of Latin and Cyrillic. This pattern ensures that the matched char- acters in a sequence of non-spaces that follow white space are a script run: \s+(*sr:\S+) - To be sure that they are all from the Latin script (for example), a + To be sure that they are all from the Latin script (for example), a lookahead can be used: \s+(?=\p{Latin})(*sr:\S+) This works as long as the first character is expected to be a character - in that script, and not (for example) punctuation, which is allowed - with any script. If this is not the case, a more creative lookahead is - needed. For example, if digits, underscore, and dots are permitted at + in that script, and not (for example) punctuation, which is allowed + with any script. If this is not the case, a more creative lookahead is + needed. For example, if digits, underscore, and dots are permitted at the start: \s+(?=[0-9_.]*\p{Latin})(*sr:\S+) - In many cases, backtracking into a script run pattern fragment is not - desirable. The script run can employ an atomic group to prevent this. - Because this is a common requirement, a shorthand notation is provided + In many cases, backtracking into a script run pattern fragment is not + desirable. The script run can employ an atomic group to prevent this. + Because this is a common requirement, a shorthand notation is provided by (*atomic_script_run: or (*asr: (*asr:...) is the same as (*sr:(?>...)) @@ -9499,13 +9652,13 @@ SCRIPT RUNS Note that the atomic group is inside the script run. Putting it outside would not prevent backtracking into the script run pattern. - Support for script runs is not available if PCRE2 is compiled without + Support for script runs is not available if PCRE2 is compiled without Unicode support. A compile-time error is given if any of the above con- - structs is encountered. Script runs are not supported by the alternate - matching function, pcre2_dfa_match() because they use the same mecha- + structs is encountered. Script runs are not supported by the alternate + matching function, pcre2_dfa_match() because they use the same mecha- nism as capturing parentheses. - Warning: The (*ACCEPT) control verb (see below) should not be used + Warning: The (*ACCEPT) control verb (see below) should not be used within a script run group, because it causes an immediate exit from the group, bypassing the script run checking. @@ -9514,117 +9667,117 @@ CONDITIONAL GROUPS It is possible to cause the matching process to obey a pattern fragment conditionally or to choose between two alternative fragments, depending - on the result of an assertion, or whether a specific capture group has + on the result of an assertion, or whether a specific capture group has already been matched. The two possible forms of conditional group are: (?(condition)yes-pattern) (?(condition)yes-pattern|no-pattern) - If the condition is satisfied, the yes-pattern is used; otherwise the - no-pattern (if present) is used. An absent no-pattern is equivalent to - an empty string (it always matches). If there are more than two alter- - natives in the group, a compile-time error occurs. Each of the two al- + If the condition is satisfied, the yes-pattern is used; otherwise the + no-pattern (if present) is used. An absent no-pattern is equivalent to + an empty string (it always matches). If there are more than two alter- + natives in the group, a compile-time error occurs. Each of the two al- ternatives may itself contain nested groups of any form, including con- - ditional groups; the restriction to two alternatives applies only at - the level of the condition itself. This pattern fragment is an example + ditional groups; the restriction to two alternatives applies only at + the level of the condition itself. This pattern fragment is an example where the alternatives are complex: (?(1) (A|B|C) | (D | (?(2)E|F) | E) ) There are five kinds of condition: references to capture groups, refer- - ences to recursion, two pseudo-conditions called DEFINE and VERSION, + ences to recursion, two pseudo-conditions called DEFINE and VERSION, and assertions. Checking for a used capture group by number - If the text between the parentheses consists of a sequence of digits, - the condition is true if a capture group of that number has previously - matched. If there is more than one capture group with the same number - (see the earlier section about duplicate group numbers), the condition - is true if any of them have matched. An alternative notation, which is + If the text between the parentheses consists of a sequence of digits, + the condition is true if a capture group of that number has previously + matched. If there is more than one capture group with the same number + (see the earlier section about duplicate group numbers), the condition + is true if any of them have matched. An alternative notation, which is a PCRE2 extension, not supported by Perl, is to precede the digits with a plus or minus sign. In this case, the group number is relative rather - than absolute. The most recently opened capture group (which could be - enclosing this condition) can be referenced by (?(-1), the next most + than absolute. The most recently opened capture group (which could be + enclosing this condition) can be referenced by (?(-1), the next most recent by (?(-2), and so on. Inside loops it can also make sense to re- - fer to subsequent groups. The next capture group to be opened can be - referenced as (?(+1), and so on. The value zero in any of these forms + fer to subsequent groups. The next capture group to be opened can be + referenced as (?(+1), and so on. The value zero in any of these forms is not used; it provokes a compile-time error. - Consider the following pattern, which contains non-significant white - space to make it more readable (assume the PCRE2_EXTENDED option) and + Consider the following pattern, which contains non-significant white + space to make it more readable (assume the PCRE2_EXTENDED option) and to divide it into three parts for ease of discussion: ( \( )? [^()]+ (?(1) \) ) - The first part matches an optional opening parenthesis, and if that + The first part matches an optional opening parenthesis, and if that character is present, sets it as the first captured substring. The sec- - ond part matches one or more characters that are not parentheses. The - third part is a conditional group that tests whether or not the first - capture group matched. If it did, that is, if subject started with an - opening parenthesis, the condition is true, and so the yes-pattern is - executed and a closing parenthesis is required. Otherwise, since no- + ond part matches one or more characters that are not parentheses. The + third part is a conditional group that tests whether or not the first + capture group matched. If it did, that is, if subject started with an + opening parenthesis, the condition is true, and so the yes-pattern is + executed and a closing parenthesis is required. Otherwise, since no- pattern is not present, the conditional group matches nothing. In other - words, this pattern matches a sequence of non-parentheses, optionally + words, this pattern matches a sequence of non-parentheses, optionally enclosed in parentheses. - If you were embedding this pattern in a larger one, you could use a + If you were embedding this pattern in a larger one, you could use a relative reference: ...other stuff... ( \( )? [^()]+ (?(-1) \) ) ... - This makes the fragment independent of the parentheses in the larger + This makes the fragment independent of the parentheses in the larger pattern. Checking for a used capture group by name - Perl uses the syntax (?()...) or (?('name')...) to test for a - used capture group by name. For compatibility with earlier versions of - PCRE1, which had this facility before Perl, the syntax (?(name)...) is - also recognized. Note, however, that undelimited names consisting of - the letter R followed by digits are ambiguous (see the following sec- + Perl uses the syntax (?()...) or (?('name')...) to test for a + used capture group by name. For compatibility with earlier versions of + PCRE1, which had this facility before Perl, the syntax (?(name)...) is + also recognized. Note, however, that undelimited names consisting of + the letter R followed by digits are ambiguous (see the following sec- tion). Rewriting the above example to use a named group gives this: (? \( )? [^()]+ (?() \) ) - If the name used in a condition of this kind is a duplicate, the test - is applied to all groups of the same name, and is true if any one of + If the name used in a condition of this kind is a duplicate, the test + is applied to all groups of the same name, and is true if any one of them has matched. Checking for pattern recursion - "Recursion" in this sense refers to any subroutine-like call from one - part of the pattern to another, whether or not it is actually recur- - sive. See the sections entitled "Recursive patterns" and "Groups as + "Recursion" in this sense refers to any subroutine-like call from one + part of the pattern to another, whether or not it is actually recur- + sive. See the sections entitled "Recursive patterns" and "Groups as subroutines" below for details of recursion and subroutine calls. - If a condition is the string (R), and there is no capture group with - the name R, the condition is true if matching is currently in a recur- - sion or subroutine call to the whole pattern or any capture group. If - digits follow the letter R, and there is no group with that name, the - condition is true if the most recent call is into a group with the - given number, which must exist somewhere in the overall pattern. This + If a condition is the string (R), and there is no capture group with + the name R, the condition is true if matching is currently in a recur- + sion or subroutine call to the whole pattern or any capture group. If + digits follow the letter R, and there is no group with that name, the + condition is true if the most recent call is into a group with the + given number, which must exist somewhere in the overall pattern. This is a contrived example that is equivalent to a+b: ((?(R1)a+|(?1)b)) - However, in both cases, if there is a capture group with a matching - name, the condition tests for its being set, as described in the sec- - tion above, instead of testing for recursion. For example, creating a - group with the name R1 by adding (?) to the above pattern com- + However, in both cases, if there is a capture group with a matching + name, the condition tests for its being set, as described in the sec- + tion above, instead of testing for recursion. For example, creating a + group with the name R1 by adding (?) to the above pattern com- pletely changes its meaning. If a name preceded by ampersand follows the letter R, for example: (?(R&name)...) - the condition is true if the most recent recursion is into a group of + the condition is true if the most recent recursion is into a group of that name (which must exist within the pattern). This condition does not check the entire recursion stack. It tests only - the current level. If the name used in a condition of this kind is a - duplicate, the test is applied to all groups of the same name, and is + the current level. If the name used in a condition of this kind is a + duplicate, the test is applied to all groups of the same name, and is true if any one of them is the most recent recursion. At "top level", all these recursion test conditions are false. @@ -9632,112 +9785,112 @@ CONDITIONAL GROUPS Defining capture groups for use by reference only If the condition is the string (DEFINE), the condition is always false, - even if there is a group with the name DEFINE. In this case, there may + even if there is a group with the name DEFINE. In this case, there may be only one alternative in the rest of the conditional group. It is al- - ways skipped if control reaches this point in the pattern; the idea of - DEFINE is that it can be used to define subroutines that can be refer- - enced from elsewhere. (The use of subroutines is described below.) For - example, a pattern to match an IPv4 address such as "192.168.23.245" + ways skipped if control reaches this point in the pattern; the idea of + DEFINE is that it can be used to define subroutines that can be refer- + enced from elsewhere. (The use of subroutines is described below.) For + example, a pattern to match an IPv4 address such as "192.168.23.245" could be written like this (ignore white space and line breaks): (?(DEFINE) (? 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) ) \b (?&byte) (\.(?&byte)){3} \b - The first part of the pattern is a DEFINE group inside which another - group named "byte" is defined. This matches an individual component of - an IPv4 address (a number less than 256). When matching takes place, - this part of the pattern is skipped because DEFINE acts like a false - condition. The rest of the pattern uses references to the named group - to match the four dot-separated components of an IPv4 address, insist- + The first part of the pattern is a DEFINE group inside which another + group named "byte" is defined. This matches an individual component of + an IPv4 address (a number less than 256). When matching takes place, + this part of the pattern is skipped because DEFINE acts like a false + condition. The rest of the pattern uses references to the named group + to match the four dot-separated components of an IPv4 address, insist- ing on a word boundary at each end. Checking the PCRE2 version - Programs that link with a PCRE2 library can check the version by call- - ing pcre2_config() with appropriate arguments. Users of applications - that do not have access to the underlying code cannot do this. A spe- - cial "condition" called VERSION exists to allow such users to discover + Programs that link with a PCRE2 library can check the version by call- + ing pcre2_config() with appropriate arguments. Users of applications + that do not have access to the underlying code cannot do this. A spe- + cial "condition" called VERSION exists to allow such users to discover which version of PCRE2 they are dealing with by using this condition to - match a string such as "yesno". VERSION must be followed either by "=" + match a string such as "yesno". VERSION must be followed either by "=" or ">=" and a version number. For example: (?(VERSION>=10.4)yes|no) - This pattern matches "yes" if the PCRE2 version is greater or equal to - 10.4, or "no" otherwise. The fractional part of the version number may - not contain more than two digits. + This pattern matches "yes" if the PCRE2 version is greater or equal to + 10.4, or "no" otherwise. The fractional part of the version number + could be ommited. Assertion conditions - If the condition is not in any of the above formats, it must be a - parenthesized assertion. This may be a positive or negative lookahead - or lookbehind assertion. However, it must be a traditional atomic as- + If the condition is not in any of the above formats, it must be a + parenthesized assertion. This may be a positive or negative lookahead + or lookbehind assertion. However, it must be a traditional atomic as- sertion, not one of the non-atomic assertions. - Consider this pattern, again containing non-significant white space, + Consider this pattern, again containing non-significant white space, and with the two alternatives on the second line: (?(?=[^a-z]*[a-z]) \d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} ) - The condition is a positive lookahead assertion that matches an op- + The condition is a positive lookahead assertion that matches an op- tional sequence of non-letters followed by a letter. In other words, it tests for the presence of at least one letter in the subject. If a let- - ter is found, the subject is matched against the first alternative; - otherwise it is matched against the second. This pattern matches - strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are + ter is found, the subject is matched against the first alternative; + otherwise it is matched against the second. This pattern matches + strings in one of the two forms dd-aaa-dd or dd-dd-dd, where aaa are letters and dd are digits. When an assertion that is a condition contains capture groups, any cap- - turing that occurs in a matching branch is retained afterwards, for - both positive and negative assertions, because matching always contin- - ues after the assertion, whether it succeeds or fails. (Compare non- - conditional assertions, for which captures are retained only for posi- + turing that occurs in a matching branch is retained afterwards, for + both positive and negative assertions, because matching always contin- + ues after the assertion, whether it succeeds or fails. (Compare non- + conditional assertions, for which captures are retained only for posi- tive assertions that succeed.) COMMENTS There are two ways of including comments in patterns that are processed - by PCRE2. In both cases, the start of the comment must not be in a - character class, nor in the middle of any other sequence of related - characters such as (?: or a group name or number or a Unicode property + by PCRE2. In both cases, the start of the comment must not be in a + character class, nor in the middle of any other sequence of related + characters such as (?: or a group name or number or a Unicode property name. The characters that make up a comment play no part in the pattern matching. - The sequence (?# marks the start of a comment that continues up to the - next closing parenthesis. Nested parentheses are not permitted. If the - PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option is set, an unescaped # - character also introduces a comment, which in this case continues to - immediately after the next newline character or character sequence in + The sequence (?# marks the start of a comment that continues up to the + next closing parenthesis. Nested parentheses are not permitted. If the + PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option is set, an unescaped # + character also introduces a comment, which in this case continues to + immediately after the next newline character or character sequence in the pattern. Which characters are interpreted as newlines is controlled - by an option passed to the compiling function or by a special sequence + by an option passed to the compiling function or by a special sequence at the start of the pattern, as described in the section entitled "New- line conventions" above. Note that the end of this type of comment is a - literal newline sequence in the pattern; escape sequences that happen + literal newline sequence in the pattern; escape sequences that happen to represent a newline do not count. For example, consider this pattern - when PCRE2_EXTENDED is set, and the default newline convention (a sin- + when PCRE2_EXTENDED is set, and the default newline convention (a sin- gle linefeed character) is in force: abc #comment \n still comment - On encountering the # character, pcre2_compile() skips along, looking - for a newline in the pattern. The sequence \n is still literal at this - stage, so it does not terminate the comment. Only an actual character + On encountering the # character, pcre2_compile() skips along, looking + for a newline in the pattern. The sequence \n is still literal at this + stage, so it does not terminate the comment. Only an actual character with the code value 0x0a (the default newline) does so. RECURSIVE PATTERNS - Consider the problem of matching a string in parentheses, allowing for - unlimited nested parentheses. Without the use of recursion, the best - that can be done is to use a pattern that matches up to some fixed - depth of nesting. It is not possible to handle an arbitrary nesting + Consider the problem of matching a string in parentheses, allowing for + unlimited nested parentheses. Without the use of recursion, the best + that can be done is to use a pattern that matches up to some fixed + depth of nesting. It is not possible to handle an arbitrary nesting depth. For some time, Perl has provided a facility that allows regular expres- - sions to recurse (amongst other things). It does this by interpolating - Perl code in the expression at run time, and the code can refer to the + sions to recurse (amongst other things). It does this by interpolating + Perl code in the expression at run time, and the code can refer to the expression itself. A Perl pattern using code interpolation to solve the parentheses problem can be created like this: @@ -9746,67 +9899,67 @@ RECURSIVE PATTERNS The (?p{...}) item interpolates Perl code at run time, and in this case refers recursively to the pattern in which it appears. - Obviously, PCRE2 cannot support the interpolation of Perl code. In- - stead, it supports special syntax for recursion of the entire pattern, + Obviously, PCRE2 cannot support the interpolation of Perl code. In- + stead, it supports special syntax for recursion of the entire pattern, and also for individual capture group recursion. After its introduction in PCRE1 and Python, this kind of recursion was subsequently introduced into Perl at release 5.10. - A special item that consists of (? followed by a number greater than - zero and a closing parenthesis is a recursive subroutine call of the - capture group of the given number, provided that it occurs inside that - group. (If not, it is a non-recursive subroutine call, which is de- + A special item that consists of (? followed by a number greater than + zero and a closing parenthesis is a recursive subroutine call of the + capture group of the given number, provided that it occurs inside that + group. (If not, it is a non-recursive subroutine call, which is de- scribed in the next section.) The special item (?R) or (?0) is a recur- sive call of the entire regular expression. - This PCRE2 pattern solves the nested parentheses problem (assume the + This PCRE2 pattern solves the nested parentheses problem (assume the PCRE2_EXTENDED option is set so that white space is ignored): \( ( [^()]++ | (?R) )* \) - First it matches an opening parenthesis. Then it matches any number of - substrings which can either be a sequence of non-parentheses, or a re- + First it matches an opening parenthesis. Then it matches any number of + substrings which can either be a sequence of non-parentheses, or a re- cursive match of the pattern itself (that is, a correctly parenthesized - substring). Finally there is a closing parenthesis. Note the use of a - possessive quantifier to avoid backtracking into sequences of non- + substring). Finally there is a closing parenthesis. Note the use of a + possessive quantifier to avoid backtracking into sequences of non- parentheses. - If this were part of a larger pattern, you would not want to recurse + If this were part of a larger pattern, you would not want to recurse the entire pattern, so instead you could use this: ( \( ( [^()]++ | (?1) )* \) ) - We have put the pattern into parentheses, and caused the recursion to + We have put the pattern into parentheses, and caused the recursion to refer to them instead of the whole pattern. - In a larger pattern, keeping track of parenthesis numbers can be - tricky. This is made easier by the use of relative references. Instead + In a larger pattern, keeping track of parenthesis numbers can be + tricky. This is made easier by the use of relative references. Instead of (?1) in the pattern above you can write (?-2) to refer to the second - most recently opened parentheses preceding the recursion. In other - words, a negative number counts capturing parentheses leftwards from + most recently opened parentheses preceding the recursion. In other + words, a negative number counts capturing parentheses leftwards from the point at which it is encountered. - Be aware however, that if duplicate capture group numbers are in use, - relative references refer to the earliest group with the appropriate + Be aware however, that if duplicate capture group numbers are in use, + relative references refer to the earliest group with the appropriate number. Consider, for example: (?|(a)|(b)) (c) (?-2) The first two capture groups (a) and (b) are both numbered 1, and group - (c) is number 2. When the reference (?-2) is encountered, the second - most recently opened parentheses has the number 1, but it is the first + (c) is number 2. When the reference (?-2) is encountered, the second + most recently opened parentheses has the number 1, but it is the first such group (the (a) group) to which the recursion refers. This would be - the same if an absolute reference (?1) was used. In other words, rela- + the same if an absolute reference (?1) was used. In other words, rela- tive references are just a shorthand for computing a group number. - It is also possible to refer to subsequent capture groups, by writing - references such as (?+2). However, these cannot be recursive because - the reference is not inside the parentheses that are referenced. They - are always non-recursive subroutine calls, as described in the next + It is also possible to refer to subsequent capture groups, by writing + references such as (?+2). However, these cannot be recursive because + the reference is not inside the parentheses that are referenced. They + are always non-recursive subroutine calls, as described in the next section. - An alternative approach is to use named parentheses. The Perl syntax - for this is (?&name); PCRE1's earlier syntax (?P>name) is also sup- + An alternative approach is to use named parentheses. The Perl syntax + for this is (?&name); PCRE1's earlier syntax (?P>name) is also sup- ported. We could rewrite the above example as follows: (? \( ( [^()]++ | (?&pn) )* \) ) @@ -9815,57 +9968,57 @@ RECURSIVE PATTERNS used. The example pattern that we have been looking at contains nested unlim- - ited repeats, and so the use of a possessive quantifier for matching - strings of non-parentheses is important when applying the pattern to + ited repeats, and so the use of a possessive quantifier for matching + strings of non-parentheses is important when applying the pattern to strings that do not match. For example, when this pattern is applied to (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() - it yields "no match" quickly. However, if a possessive quantifier is - not used, the match runs for a very long time indeed because there are - so many different ways the + and * repeats can carve up the subject, + it yields "no match" quickly. However, if a possessive quantifier is + not used, the match runs for a very long time indeed because there are + so many different ways the + and * repeats can carve up the subject, and all have to be tested before failure can be reported. - At the end of a match, the values of capturing parentheses are those - from the outermost level. If you want to obtain intermediate values, a + At the end of a match, the values of capturing parentheses are those + from the outermost level. If you want to obtain intermediate values, a callout function can be used (see below and the pcre2callout documenta- tion). If the pattern above is matched against (ab(cd)ef) - the value for the inner capturing parentheses (numbered 2) is "ef", - which is the last value taken on at the top level. If a capture group - is not matched at the top level, its final captured value is unset, - even if it was (temporarily) set at a deeper level during the matching + the value for the inner capturing parentheses (numbered 2) is "ef", + which is the last value taken on at the top level. If a capture group + is not matched at the top level, its final captured value is unset, + even if it was (temporarily) set at a deeper level during the matching process. - Do not confuse the (?R) item with the condition (R), which tests for - recursion. Consider this pattern, which matches text in angle brack- - ets, allowing for arbitrary nesting. Only digits are allowed in nested - brackets (that is, when recursing), whereas any characters are permit- + Do not confuse the (?R) item with the condition (R), which tests for + recursion. Consider this pattern, which matches text in angle brack- + ets, allowing for arbitrary nesting. Only digits are allowed in nested + brackets (that is, when recursing), whereas any characters are permit- ted at the outer level. < (?: (?(R) \d++ | [^<>]*+) | (?R)) * > - In this pattern, (?(R) is the start of a conditional group, with two - different alternatives for the recursive and non-recursive cases. The + In this pattern, (?(R) is the start of a conditional group, with two + different alternatives for the recursive and non-recursive cases. The (?R) item is the actual recursive call. Differences in recursion processing between PCRE2 and Perl Some former differences between PCRE2 and Perl no longer exist. - Before release 10.30, recursion processing in PCRE2 differed from Perl - in that a recursive subroutine call was always treated as an atomic - group. That is, once it had matched some of the subject string, it was - never re-entered, even if it contained untried alternatives and there - was a subsequent matching failure. (Historical note: PCRE implemented + Before release 10.30, recursion processing in PCRE2 differed from Perl + in that a recursive subroutine call was always treated as an atomic + group. That is, once it had matched some of the subject string, it was + never re-entered, even if it contained untried alternatives and there + was a subsequent matching failure. (Historical note: PCRE implemented recursion before Perl did.) - Starting with release 10.30, recursive subroutine calls are no longer + Starting with release 10.30, recursive subroutine calls are no longer treated as atomic. That is, they can be re-entered to try unused alter- - natives if there is a matching failure later in the pattern. This is - now compatible with the way Perl works. If you want a subroutine call + natives if there is a matching failure later in the pattern. This is + now compatible with the way Perl works. If you want a subroutine call to be atomic, you must explicitly enclose it in an atomic group. Supporting backtracking into recursions simplifies certain types of re- @@ -9873,47 +10026,46 @@ RECURSIVE PATTERNS ^((.)(?1)\2|.?)$ - The second branch in the group matches a single central character in - the palindrome when there are an odd number of characters, or nothing - when there are an even number of characters, but in order to work it - has to be able to try the second case when the rest of the pattern + The second branch in the group matches a single central character in + the palindrome when there are an odd number of characters, or nothing + when there are an even number of characters, but in order to work it + has to be able to try the second case when the rest of the pattern match fails. If you want to match typical palindromic phrases, the pat- - tern has to ignore all non-word characters, which can be done like + tern has to ignore all non-word characters, which can be done like this: ^\W*+((.)\W*+(?1)\W*+\2|\W*+.?)\W*+$ - If run with the PCRE2_CASELESS option, this pattern matches phrases - such as "A man, a plan, a canal: Panama!". Note the use of the posses- - sive quantifier *+ to avoid backtracking into sequences of non-word + If run with the PCRE2_CASELESS option, this pattern matches phrases + such as "A man, a plan, a canal: Panama!". Note the use of the posses- + sive quantifier *+ to avoid backtracking into sequences of non-word characters. Without this, PCRE2 takes a great deal longer (ten times or - more) to match typical phrases, and Perl takes so long that you think + more) to match typical phrases, and Perl takes so long that you think it has gone into a loop. - Another way in which PCRE2 and Perl used to differ in their recursion - processing is in the handling of captured values. Formerly in Perl, - when a group was called recursively or as a subroutine (see the next + Another way in which PCRE2 and Perl used to differ in their recursion + processing is in the handling of captured values. Formerly in Perl, + when a group was called recursively or as a subroutine (see the next section), it had no access to any values that were captured outside the - recursion, whereas in PCRE2 these values can be referenced. Consider + recursion, whereas in PCRE2 these values can be referenced. Consider this pattern: ^(.)(\1|a(?2)) - This pattern matches "bab". The first capturing parentheses match "b", + This pattern matches "bab". The first capturing parentheses match "b", then in the second group, when the backreference \1 fails to match "b", the second alternative matches "a" and then recurses. In the recursion, - \1 does now match "b" and so the whole match succeeds. This match used + \1 does now match "b" and so the whole match succeeds. This match used to fail in Perl, but in later versions (I tried 5.024) it now works. + Groups as subroutines -GROUPS AS SUBROUTINES - - If the syntax for a recursive group call (either by number or by name) - is used outside the parentheses to which it refers, it operates a bit - like a subroutine in a programming language. More accurately, PCRE2 + If the syntax for a recursive group call (either by number or by name) + is used outside the parentheses to which it refers, it operates a bit + like a subroutine in a programming language. More accurately, PCRE2 treats the referenced group as an independent subpattern which it tries - to match at the current matching position. The called group may be de- - fined before or after the reference. A numbered reference can be ab- + to match at the current matching position. The called group may be de- + fined before or after the reference. A numbered reference can be ab- solute or relative, as in these examples: (...(absolute)...)...(?2)... @@ -9924,35 +10076,75 @@ GROUPS AS SUBROUTINES (sens|respons)e and \1ibility - matches "sense and sensibility" and "response and responsibility", but + matches "sense and sensibility" and "response and responsibility", but not "sense and responsibility". If instead the pattern (sens|respons)e and (?1)ibility - is used, it does match "sense and responsibility" as well as the other - two strings. Another example is given in the discussion of DEFINE + is used, it does match "sense and responsibility" as well as the other + two strings. Another example is given in the discussion of DEFINE above. - Like recursions, subroutine calls used to be treated as atomic, but - this changed at PCRE2 release 10.30, so backtracking into subroutine - calls can now occur. However, any capturing parentheses that are set + Like recursions, subroutine calls used to be treated as atomic, but + this changed at PCRE2 release 10.30, so backtracking into subroutine + calls can now occur. However, any capturing parentheses that are set during the subroutine call revert to their previous values afterwards. - Processing options such as case-independence are fixed when a group is - defined, so if it is used as a subroutine, such options cannot be + Processing options such as case-independence are fixed when a group is + defined, so if it is used as a subroutine, such options cannot be changed for different calls. For example, consider this pattern: (abc)(?i:(?-1)) - It matches "abcabc". It does not match "abcABC" because the change of + It matches "abcabc". It does not match "abcABC" because the change of processing option does not affect the called group. - The behaviour of backtracking control verbs in groups when called as + The behaviour of backtracking control verbs in groups when called as subroutines is described in the section entitled "Backtracking verbs in subroutines" below. + Recursion and subroutines with returned capture groups -ONIGURUMA SUBROUTINE SYNTAX + Since PCRE2 10.46, recursion and subroutine calls may also specify a + list of capture groups to return. This is a PCRE2 syntax extension not + supported by Perl. The pattern matching recurses into the referenced + expression as described above, however, when the recursion returns to + the calling expression the subgroups captured during the recursion can + be retained when the calling expression's context is restored. + + When used as a subroutine, this allows the subroutine's capture groups + to be used as return values. + + Only the specific capture groups listed by the caller will be retained, + using the following syntax: + + (?R(grouplist)) recurse whole pattern, returning capture groups + (?n(grouplist)) ) + (?+n(grouplist)) ) + (?-n(grouplist)) ) call subroutine, returning capture groups + (?&name(grouplist)) ) + (?P>name(grouplist)) ) + + The list of capture groups "grouplist" is a comma-separated list of + (absolute or relative) group numbers, and group names enclosed in sin- + gle quotes or angle brackets. + + Here is an example which first uses the DEFINE condition to create a + re-usable routine for matching a weekday, then calls that subroutine + and retains the groups it captures for use later: + + (?x: # ignore whitespace for clarity + # Define the routine "weekendday" which matches Saturday or + # Sunday, and returns the Sat/Sun prefix as \k. + (?(DEFINE) (? + (?|(?Sat)urday|(?Sun)day) ) ) + # Call the routine. Matches "Saturday,Sat" or "Sunday,Sun". + (?&weekendday()),\k ) + + This feature is not available using the Oniguruma syntax \g<...> or + \g'...' below. + + Oniguruma subroutine syntax For compatibility with Oniguruma, the non-Perl syntax \g followed by a name or a number enclosed either in angle brackets or single quotes, is @@ -10070,10 +10262,10 @@ BACKTRACKING CONTROL A closing parenthesis can be included in a name either as \) or between \Q and \E. In addition to backslash processing, if the PCRE2_EXTENDED - or PCRE2_EXTENDED_MORE option is also set, unescaped whitespace in verb - names is skipped, and #-comments are recognized, exactly as in the rest - of the pattern. PCRE2_EXTENDED and PCRE2_EXTENDED_MORE do not affect - verb names unless PCRE2_ALT_VERBNAMES is also set. + or PCRE2_EXTENDED_MORE option is also set, unescaped white space in + verb names is skipped, and #-comments are recognized, exactly as in the + rest of the pattern. PCRE2_EXTENDED and PCRE2_EXTENDED_MORE do not af- + fect verb names unless PCRE2_ALT_VERBNAMES is also set. The maximum length of a name is 255 in the 8-bit library and 65535 in the 16-bit and 32-bit libraries. If the name is empty, that is, if the @@ -10590,11 +10782,11 @@ AUTHOR REVISION - Last updated: 27 November 2024 + Last updated: 03 September 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 27 November 2024 PCRE2PATTERN(3) +PCRE2 10.47 03 September 2025 PCRE2PATTERN(3) ------------------------------------------------------------------------------ @@ -10849,7 +11041,7 @@ REVISION Copyright (c) 1997-2022 University of Cambridge. -PCRE2 10.46 06 December 2022 PCRE2PERFORM(3) +PCRE2 10.47 06 December 2022 PCRE2PERFORM(3) ------------------------------------------------------------------------------ @@ -11207,7 +11399,7 @@ REVISION Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 27 November 2024 PCRE2POSIX(3) +PCRE2 10.47 27 November 2024 PCRE2POSIX(3) ------------------------------------------------------------------------------ @@ -11224,7 +11416,7 @@ PCRE2 SAMPLE PROGRAM PCRE2 is supplied in the file pcre2demo.c in the src directory in the PCRE2 distribution. A listing of this program is given in the pcre2demo documentation. If you do not have a copy of the PCRE2 distribution, you - can save this listing to re-create the contents of pcre2demo.c. + can save this listing to recreate the contents of pcre2demo.c. The demonstration program compiles the regular expression that is its first argument, and matches it against the subject string in its second @@ -11265,6 +11457,7 @@ PCRE2 SAMPLE PROGRAM ./pcre2demo 'cat|dog' 'the cat sat on the mat' ./pcre2demo -g 'cat|dog' 'the dog sat on the cat' + ./pcre2demo -i 'cat' 'the dog sat on the CAT' Note that there is a much more comprehensive test program, called pcre2test, which supports many more facilities for testing regular ex- @@ -11296,11 +11489,11 @@ AUTHOR REVISION - Last updated: 14 November 2023 + Last updated: 28 February 2025 Copyright (c) 1997-2016 University of Cambridge. -PCRE2 10.46 14 November 2023 PCRE2SAMPLE(3) +PCRE2 10.47 28 February 2025 PCRE2SAMPLE(3) ------------------------------------------------------------------------------ PCRE2SERIALIZE(3) Library Functions Manual PCRE2SERIALIZE(3) @@ -11491,7 +11684,7 @@ REVISION Copyright (c) 1997-2018 University of Cambridge. -PCRE2 10.46 19 January 2024 PCRE2SERIALIZE(3) +PCRE2 10.47 19 January 2024 PCRE2SERIALIZE(3) ------------------------------------------------------------------------------ @@ -11777,7 +11970,7 @@ CHARACTER CLASSES PERL EXTENDED CHARACTER CLASSES (?[...]) Perl extended character class - (?[\p{Thai} & \p{Nd}]) operators; whitespace ignored + (?[\p{Thai} & \p{Nd}]) operators; white space ignored (?[(x - y) & z]) parentheses for grouping (?[ [^3] & \p{Nd} ]) [...] is a nested ordinary class @@ -12013,8 +12206,8 @@ SUBSTRING SCAN ASSERTION (*scan_substring:(grouplist)...) scan captured substring (*scs:(grouplist)...) scan captured substring - The comma-separated list may identify groups in any of the following - ways: + The comma-separated list "grouplist" may identify groups in any of the + following ways: n absolute reference +n relative reference @@ -12065,29 +12258,56 @@ SUBROUTINE REFERENCES (POSSIBLY RECURSIVE) \g<-n> call subroutine by relative number (PCRE2 extension) \g'-n' call subroutine by relative number (PCRE2 extension) + The variants using parentheses (?...) may also specify a list of cap- + ture groups to return, which shall be retained in the calling subex- + pression if set during the recursion (this feature is not supported by + Perl). + + (?R(grouplist)) recurse whole pattern, returning capture groups + (PCRE2 extension) + (?n(grouplist)) ) + (?+n(grouplist)) ) call subroutine, returning capture groups + (?-n(grouplist)) ) (PCRE2 extension) + (?&name(grouplist)) ) + (?P>name(grouplist)) ) + + The comma-separated list "grouplist" uses the same syntax as + (*scan_substring:(grouplist)...), and may identify groups in any of the + following ways: + + n absolute reference + +n relative reference + -n relative reference + name + 'name' name + CONDITIONAL PATTERNS (?(condition)yes-pattern) (?(condition)yes-pattern|no-pattern) - (?(n) absolute reference condition - (?(+n) relative reference condition (PCRE2 extension) - (?(-n) relative reference condition (PCRE2 extension) - (?() named reference condition (Perl) - (?('name') named reference condition (Perl) - (?(name) named reference condition (PCRE2, deprecated) - (?(R) overall recursion condition - (?(Rn) specific numbered group recursion condition - (?(R&name) specific named group recursion condition - (?(DEFINE) define groups for reference - (?(VERSION[>]=n.m) test PCRE2 version - (?(assert) assertion condition + (?(n) absolute reference condition + (?(+n) relative reference condition (PCRE2 extension) + (?(-n) relative reference condition (PCRE2 extension) + (?() named reference condition (Perl) + (?('name') named reference condition (Perl) + (?(name) named reference condition (PCRE2, deprecated) + (?(R) overall recursion condition + (?(Rn) specific numbered group recursion condition + (?(R&name) specific named group recursion condition + (?(DEFINE) define groups for reference + (?(VERSION[>]=n[.m]) test PCRE2 version + (?(assert) assertion condition Note the ambiguity of (?(R) and (?(Rn) which might be named reference conditions or recursion tests. Such a condition is interpreted as a reference condition if the relevant named group exists. + The parts within brackets for the VERSION conditional syntax could be + ommited. The fractional part of the version number defaults to 0 in + that case. + BACKTRACKING CONTROL @@ -12143,25 +12363,26 @@ REPLACEMENT STRINGS $` insert the substring that precedes the match $' insert the substring that follows the match $_ insert the entire input string + $+ insert the highest-numbered capture group which + matched $*MARK or ${*MARK} insert a control verb name - For ${n}, n can be a name or a number. If PCRE2_SUBSTITUTE_EXTENDED is + For ${n}, n can be a name or a number. If PCRE2_SUBSTITUTE_EXTENDED is set, there is additional interpretation: - 1. Backslash is an escape character, and the forms described in "ES- + 1. Backslash is an escape character, and the forms described in "ES- CAPED CHARACTERS" above are recognized. Also: - \Q...\E can be used to suppress interpretation - \l force the next character to lower case - \u force the next character to upper case - \L force subsequent characters to lower case - \U force subsequent characters to upper case - \u\L force next character to upper case, then all lower - \l\U force next character to lower case, then all upper - \E end \L or \U case forcing - \b backspace character (note: as in character class in pat- - tern) - \v vertical tab character (note: not the same as in a pattern) + \Q...\E can be used to suppress interpretation + \l force the next character to lower case + \u force the next character to upper case + \L force subsequent characters to lower case + \U force subsequent characters to upper case + \u\L force next character to upper case, then all lower + \l\U force next character to lower case, then all upper + \E end \L or \U case forcing + \b backspace character (note: as in character class in pattern) + \v vertical tab character (note: not the same as in a pattern) 2. The Python form \g, where the angle brackets are part of the syn- tax and n is either a group name or a number, is recognized as an al- @@ -12191,11 +12412,11 @@ AUTHOR REVISION - Last updated: 27 November 2024 + Last updated: 14 October 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 27 November 2024 PCRE2SYNTAX(3) +PCRE2 10.47 14 October 2025 PCRE2SYNTAX(3) ------------------------------------------------------------------------------ @@ -12690,7 +12911,7 @@ REVISION Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 27 November 2024 PCRE2UNICODE(3) +PCRE2 10.47 27 November 2024 PCRE2UNICODE(3) ------------------------------------------------------------------------------ diff --git a/doc/pcre2_callout_enumerate.3 b/doc/pcre2_callout_enumerate.3 index 0c24114..9065fd8 100644 --- a/doc/pcre2_callout_enumerate.3 +++ b/doc/pcre2_callout_enumerate.3 @@ -1,4 +1,4 @@ -.TH PCRE2_COMPILE 3 "23 March 2017" "PCRE2 10.46" +.TH PCRE2_COMPILE 3 "23 March 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_code_copy.3 b/doc/pcre2_code_copy.3 index f7a2d78..9b6526f 100644 --- a/doc/pcre2_code_copy.3 +++ b/doc/pcre2_code_copy.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CODE_COPY 3 "22 November 2016" "PCRE2 10.46" +.TH PCRE2_CODE_COPY 3 "22 November 2016" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_code_copy_with_tables.3 b/doc/pcre2_code_copy_with_tables.3 index ebde43b..3896577 100644 --- a/doc/pcre2_code_copy_with_tables.3 +++ b/doc/pcre2_code_copy_with_tables.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CODE_COPY 3 "16 January 2017" "PCRE2 10.46" +.TH PCRE2_CODE_COPY 3 "16 January 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_code_free.3 b/doc/pcre2_code_free.3 index 101d395..ca660e8 100644 --- a/doc/pcre2_code_free.3 +++ b/doc/pcre2_code_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CODE_FREE 3 "28 June 2018" "PCRE2 10.46" +.TH PCRE2_CODE_FREE 3 "28 June 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_compile.3 b/doc/pcre2_compile.3 index e2dab62..eb40814 100644 --- a/doc/pcre2_compile.3 +++ b/doc/pcre2_compile.3 @@ -1,4 +1,4 @@ -.TH PCRE2_COMPILE 3 "30 October 2024" "PCRE2 10.46" +.TH PCRE2_COMPILE 3 "30 October 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_compile_context_copy.3 b/doc/pcre2_compile_context_copy.3 index 94a0c6e..c3353b5 100644 --- a/doc/pcre2_compile_context_copy.3 +++ b/doc/pcre2_compile_context_copy.3 @@ -1,4 +1,4 @@ -.TH PCRE2_COMPILE_CONTEXT_COPY 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_COMPILE_CONTEXT_COPY 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_compile_context_create.3 b/doc/pcre2_compile_context_create.3 index 9dcdaa3..f094977 100644 --- a/doc/pcre2_compile_context_create.3 +++ b/doc/pcre2_compile_context_create.3 @@ -1,4 +1,4 @@ -.TH PCRE2_COMPILE_CONTEXT_CREATE 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_COMPILE_CONTEXT_CREATE 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_compile_context_free.3 b/doc/pcre2_compile_context_free.3 index c9dd260..ded964e 100644 --- a/doc/pcre2_compile_context_free.3 +++ b/doc/pcre2_compile_context_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_COMPILE_CONTEXT_FREE 3 "28 June 2018" "PCRE2 10.46" +.TH PCRE2_COMPILE_CONTEXT_FREE 3 "28 June 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_config.3 b/doc/pcre2_config.3 index 37c1597..e109180 100644 --- a/doc/pcre2_config.3 +++ b/doc/pcre2_config.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CONFIG 3 "16 September 2017" "PCRE2 10.46" +.TH PCRE2_CONFIG 3 "03 September 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -6,8 +6,9 @@ PCRE2 - Perl-compatible regular expressions (revised API) .sp .B #include .PP -.SM +.nf .B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP); +.fi . .SH DESCRIPTION .rs @@ -28,36 +29,37 @@ PCRE2_CONFIG_UNICODE_VERSION, and PCRE2_CONFIG_VERSION it must point to a buffer that is large enough to hold the string. For all other codes it must point to a uint32_t integer variable. The available codes are: .sp - PCRE2_CONFIG_BSR Indicates what \eR matches by default: - PCRE2_BSR_UNICODE - PCRE2_BSR_ANYCRLF - PCRE2_CONFIG_COMPILED_WIDTHS Which of 8/16/32 support was compiled - PCRE2_CONFIG_DEPTHLIMIT Default backtracking depth limit - PCRE2_CONFIG_HEAPLIMIT Default heap memory limit + PCRE2_CONFIG_BSR Indicates what \eR matches by default: + PCRE2_BSR_UNICODE + PCRE2_BSR_ANYCRLF + PCRE2_CONFIG_COMPILED_WIDTHS Which of 8/16/32 support was compiled + PCRE2_CONFIG_DEPTHLIMIT Default backtracking depth limit + PCRE2_CONFIG_EFFECTIVE_LINKSIZE How many bytes are used for link size + PCRE2_CONFIG_HEAPLIMIT Default heap memory limit .\" JOIN - PCRE2_CONFIG_JIT Availability of just-in-time compiler - support (1=yes 0=no) + PCRE2_CONFIG_JIT Availability of just-in-time compiler + support (1=yes 0=no) .\" JOIN - PCRE2_CONFIG_JITTARGET Information (a string) about the target - architecture for the JIT compiler - PCRE2_CONFIG_LINKSIZE Configured internal link size (2, 3, 4) - PCRE2_CONFIG_MATCHLIMIT Default internal resource limit + PCRE2_CONFIG_JITTARGET Information (a string) about the target + architecture for the JIT compiler + PCRE2_CONFIG_LINKSIZE Configured internal link size (2, 3, 4) + PCRE2_CONFIG_MATCHLIMIT Default internal resource limit PCRE2_CONFIG_NEVER_BACKSLASH_C Whether or not \eC is disabled - PCRE2_CONFIG_NEWLINE Code for the default newline sequence: - PCRE2_NEWLINE_CR - PCRE2_NEWLINE_LF - PCRE2_NEWLINE_CRLF - PCRE2_NEWLINE_ANY - PCRE2_NEWLINE_ANYCRLF - PCRE2_NEWLINE_NUL - PCRE2_CONFIG_PARENSLIMIT Default parentheses nesting limit - PCRE2_CONFIG_RECURSIONLIMIT Obsolete: use PCRE2_CONFIG_DEPTHLIMIT - PCRE2_CONFIG_STACKRECURSE Obsolete: always returns 0 + PCRE2_CONFIG_NEWLINE Code for the default newline sequence: + PCRE2_NEWLINE_CR + PCRE2_NEWLINE_LF + PCRE2_NEWLINE_CRLF + PCRE2_NEWLINE_ANY + PCRE2_NEWLINE_ANYCRLF + PCRE2_NEWLINE_NUL + PCRE2_CONFIG_PARENSLIMIT Default parentheses nesting limit + PCRE2_CONFIG_RECURSIONLIMIT Obsolete: use PCRE2_CONFIG_DEPTHLIMIT + PCRE2_CONFIG_STACKRECURSE Obsolete: always returns 0 .\" JOIN - PCRE2_CONFIG_UNICODE Availability of Unicode support (1=yes - 0=no) - PCRE2_CONFIG_UNICODE_VERSION The Unicode version (a string) - PCRE2_CONFIG_VERSION The PCRE2 version (a string) + PCRE2_CONFIG_UNICODE Availability of Unicode support + (1=yes 0=no) + PCRE2_CONFIG_UNICODE_VERSION The Unicode version (a string) + PCRE2_CONFIG_VERSION The PCRE2 version (a string) .sp The function yields a non-negative value on success or the negative value PCRE2_ERROR_BADOPTION otherwise. This is also the result for the diff --git a/doc/pcre2_convert_context_copy.3 b/doc/pcre2_convert_context_copy.3 index 5f91691..32073f0 100644 --- a/doc/pcre2_convert_context_copy.3 +++ b/doc/pcre2_convert_context_copy.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CONVERT_CONTEXT_COPY 3 "12 July 2017" "PCRE2 10.46" +.TH PCRE2_CONVERT_CONTEXT_COPY 3 "12 July 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_convert_context_create.3 b/doc/pcre2_convert_context_create.3 index 73ccff4..6a5c9be 100644 --- a/doc/pcre2_convert_context_create.3 +++ b/doc/pcre2_convert_context_create.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CONVERT_CONTEXT_CREATE 3 "12 July 2017" "PCRE2 10.46" +.TH PCRE2_CONVERT_CONTEXT_CREATE 3 "12 July 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_convert_context_free.3 b/doc/pcre2_convert_context_free.3 index 6ae3541..7fbda34 100644 --- a/doc/pcre2_convert_context_free.3 +++ b/doc/pcre2_convert_context_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CONVERT_CONTEXT_FREE 3 "13 August 2018" "PCRE2 10.46" +.TH PCRE2_CONVERT_CONTEXT_FREE 3 "13 August 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_converted_pattern_free.3 b/doc/pcre2_converted_pattern_free.3 index d0c60ca..3b09fe7 100644 --- a/doc/pcre2_converted_pattern_free.3 +++ b/doc/pcre2_converted_pattern_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_CONVERTED_PATTERN_FREE 3 "13 August 2018" "PCRE2 10.46" +.TH PCRE2_CONVERTED_PATTERN_FREE 3 "13 August 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_dfa_match.3 b/doc/pcre2_dfa_match.3 index 299a7f8..4a4673b 100644 --- a/doc/pcre2_dfa_match.3 +++ b/doc/pcre2_dfa_match.3 @@ -1,4 +1,4 @@ -.TH PCRE2_DFA_MATCH 3 "31 August 2021" "PCRE2 10.46" +.TH PCRE2_DFA_MATCH 3 "31 August 2021" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_general_context_copy.3 b/doc/pcre2_general_context_copy.3 index a852018..1f73772 100644 --- a/doc/pcre2_general_context_copy.3 +++ b/doc/pcre2_general_context_copy.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GENERAL_CONTEXT_COPY 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_GENERAL_CONTEXT_COPY 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_general_context_create.3 b/doc/pcre2_general_context_create.3 index 445ca38..cd9e1b5 100644 --- a/doc/pcre2_general_context_create.3 +++ b/doc/pcre2_general_context_create.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GENERAL_CONTEXT_CREATE 3 "23 January 2023" "PCRE2 10.46" +.TH PCRE2_GENERAL_CONTEXT_CREATE 3 "23 January 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_general_context_free.3 b/doc/pcre2_general_context_free.3 index 83cd557..3d69d13 100644 --- a/doc/pcre2_general_context_free.3 +++ b/doc/pcre2_general_context_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GENERAL_CONTEXT_FREE 3 "28 June 2018" "PCRE2 10.46" +.TH PCRE2_GENERAL_CONTEXT_FREE 3 "28 June 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_get_error_message.3 b/doc/pcre2_get_error_message.3 index d86a671..cffc573 100644 --- a/doc/pcre2_get_error_message.3 +++ b/doc/pcre2_get_error_message.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GET_ERROR_MESSAGE 3 "24 March 2017" "PCRE2 10.46" +.TH PCRE2_GET_ERROR_MESSAGE 3 "24 March 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_get_mark.3 b/doc/pcre2_get_mark.3 index fd0725c..6d29106 100644 --- a/doc/pcre2_get_mark.3 +++ b/doc/pcre2_get_mark.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GET_MARK 3 "13 January 2018" "PCRE2 10.46" +.TH PCRE2_GET_MARK 3 "13 January 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_get_match_data_heapframes_size.3 b/doc/pcre2_get_match_data_heapframes_size.3 index 64a07f9..555bcd2 100644 --- a/doc/pcre2_get_match_data_heapframes_size.3 +++ b/doc/pcre2_get_match_data_heapframes_size.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE 3 "18 January 2023" "PCRE2 10.46" +.TH PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE 3 "18 January 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_get_match_data_size.3 b/doc/pcre2_get_match_data_size.3 index e5ba402..3ebc4fd 100644 --- a/doc/pcre2_get_match_data_size.3 +++ b/doc/pcre2_get_match_data_size.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GET_MATCH_DATA_SIZE 3 "17 October 2019" "PCRE2 10.46" +.TH PCRE2_GET_MATCH_DATA_SIZE 3 "17 October 2019" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_get_ovector_count.3 b/doc/pcre2_get_ovector_count.3 index c41ed7f..23f072d 100644 --- a/doc/pcre2_get_ovector_count.3 +++ b/doc/pcre2_get_ovector_count.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GET_OVECTOR_COUNT 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_GET_OVECTOR_COUNT 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_get_ovector_pointer.3 b/doc/pcre2_get_ovector_pointer.3 index 9cf5e99..7d9ec1e 100644 --- a/doc/pcre2_get_ovector_pointer.3 +++ b/doc/pcre2_get_ovector_pointer.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GET_OVECTOR_POINTER 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_GET_OVECTOR_POINTER 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_get_startchar.3 b/doc/pcre2_get_startchar.3 index 7c99df4..b9c4f7b 100644 --- a/doc/pcre2_get_startchar.3 +++ b/doc/pcre2_get_startchar.3 @@ -1,4 +1,4 @@ -.TH PCRE2_GET_STARTCHAR 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_GET_STARTCHAR 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_jit_compile.3 b/doc/pcre2_jit_compile.3 index 53cea8b..9961d47 100644 --- a/doc/pcre2_jit_compile.3 +++ b/doc/pcre2_jit_compile.3 @@ -1,4 +1,4 @@ -.TH PCRE2_JIT_COMPILE 3 "22 August 2024" "PCRE2 10.46" +.TH PCRE2_JIT_COMPILE 3 "22 August 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_jit_free_unused_memory.3 b/doc/pcre2_jit_free_unused_memory.3 index 3eb23db..fa1073a 100644 --- a/doc/pcre2_jit_free_unused_memory.3 +++ b/doc/pcre2_jit_free_unused_memory.3 @@ -1,4 +1,4 @@ -.TH PCRE2_JIT_FREE_UNUSED_MEMORY 3 "24 April 2020" "PCRE2 10.46" +.TH PCRE2_JIT_FREE_UNUSED_MEMORY 3 "24 April 2020" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_jit_match.3 b/doc/pcre2_jit_match.3 index 60e3a63..e147b90 100644 --- a/doc/pcre2_jit_match.3 +++ b/doc/pcre2_jit_match.3 @@ -1,4 +1,4 @@ -.TH PCRE2_JIT_MATCH 3 "20 January 2023" "PCRE2 10.46" +.TH PCRE2_JIT_MATCH 3 "20 January 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_jit_stack_assign.3 b/doc/pcre2_jit_stack_assign.3 index f3a0a04..61fc963 100644 --- a/doc/pcre2_jit_stack_assign.3 +++ b/doc/pcre2_jit_stack_assign.3 @@ -1,4 +1,4 @@ -.TH PCRE2_JIT_STACK_ASSIGN 3 "13 August 2018" "PCRE2 10.46" +.TH PCRE2_JIT_STACK_ASSIGN 3 "13 August 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_jit_stack_create.3 b/doc/pcre2_jit_stack_create.3 index 3ad2adc..494eee8 100644 --- a/doc/pcre2_jit_stack_create.3 +++ b/doc/pcre2_jit_stack_create.3 @@ -1,4 +1,4 @@ -.TH PCRE2_JIT_STACK_CREATE 3 "23 January 2023" "PCRE2 10.46" +.TH PCRE2_JIT_STACK_CREATE 3 "23 January 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_jit_stack_free.3 b/doc/pcre2_jit_stack_free.3 index 8f1d5a4..0b88759 100644 --- a/doc/pcre2_jit_stack_free.3 +++ b/doc/pcre2_jit_stack_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_JIT_STACK_FREE 3 "13 August 2018" "PCRE2 10.46" +.TH PCRE2_JIT_STACK_FREE 3 "26 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -6,8 +6,9 @@ PCRE2 - Perl-compatible regular expressions (revised API) .sp .B #include .PP -.SM +.nf .B void pcre2_jit_stack_free(pcre2_jit_stack *\fIjit_stack\fP); +.fi . .SH DESCRIPTION .rs diff --git a/doc/pcre2_maketables.3 b/doc/pcre2_maketables.3 index d859b31..b42933f 100644 --- a/doc/pcre2_maketables.3 +++ b/doc/pcre2_maketables.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MAKETABLES 3 "28 July 2019" "PCRE2 10.46" +.TH PCRE2_MAKETABLES 3 "26 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -6,8 +6,9 @@ PCRE2 - Perl-compatible regular expressions (revised API) .sp .B #include .PP -.SM +.nf .B const uint8_t *pcre2_maketables(pcre2_general_context *\fIgcontext\fP); +.fi . .SH DESCRIPTION .rs diff --git a/doc/pcre2_maketables_free.3 b/doc/pcre2_maketables_free.3 index 44a8db7..4b835c3 100644 --- a/doc/pcre2_maketables_free.3 +++ b/doc/pcre2_maketables_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MAKETABLES_FREE 3 "03 September 2019" "PCRE2 10.46" +.TH PCRE2_MAKETABLES_FREE 3 "03 September 2019" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_match.3 b/doc/pcre2_match.3 index 50cd1f2..5701b75 100644 --- a/doc/pcre2_match.3 +++ b/doc/pcre2_match.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MATCH 3 "27 January 2024" "PCRE2 10.46" +.TH PCRE2_MATCH 3 "27 January 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_match_context_copy.3 b/doc/pcre2_match_context_copy.3 index 88614b1..cbce67a 100644 --- a/doc/pcre2_match_context_copy.3 +++ b/doc/pcre2_match_context_copy.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MATCH_CONTEXT_COPY 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_MATCH_CONTEXT_COPY 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_match_context_create.3 b/doc/pcre2_match_context_create.3 index b20c702..ab624a3 100644 --- a/doc/pcre2_match_context_create.3 +++ b/doc/pcre2_match_context_create.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MATCH_CONTEXT_CREATE 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_MATCH_CONTEXT_CREATE 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_match_context_free.3 b/doc/pcre2_match_context_free.3 index 83c66a3..e0a4d62 100644 --- a/doc/pcre2_match_context_free.3 +++ b/doc/pcre2_match_context_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MATCH_CONTEXT_FREE 3 "28 June 2018" "PCRE2 10.46" +.TH PCRE2_MATCH_CONTEXT_FREE 3 "28 June 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_match_data_create.3 b/doc/pcre2_match_data_create.3 index 59c9de8..49ee289 100644 --- a/doc/pcre2_match_data_create.3 +++ b/doc/pcre2_match_data_create.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MATCH_DATA_CREATE 3 "28 August 2021" "PCRE2 10.46" +.TH PCRE2_MATCH_DATA_CREATE 3 "28 August 2021" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_match_data_create_from_pattern.3 b/doc/pcre2_match_data_create_from_pattern.3 index ec9a62f..d105b62 100644 --- a/doc/pcre2_match_data_create_from_pattern.3 +++ b/doc/pcre2_match_data_create_from_pattern.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MATCH_DATA_CREATE_FROM_PATTERN 3 "19 August 2022" "PCRE2 10.46" +.TH PCRE2_MATCH_DATA_CREATE_FROM_PATTERN 3 "11 August 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -15,19 +15,19 @@ PCRE2 - Perl-compatible regular expressions (revised API) .rs .sp This function creates a new match data block for holding the result of a match. -The first argument points to a compiled pattern. The number of capturing -parentheses within the pattern is used to compute the number of pairs of -offsets that are required in the match data block. These form the "output -vector" (ovector) within the match data block, and are used to identify the -matched string and any captured substrings when matching with -\fBpcre2_match()\fP. If you are using \fBpcre2_dfa_match()\fP, which uses the -output vector in a different way, you should use \fBpcre2_match_data_create()\fP -instead of this function. +If the first argument is NULL, this function returns NULL, otherwise the first +argument points to a compiled pattern. The number of capturing parentheses +within the pattern is used to compute the number of pairs of offsets that are +required in the match data block. These form the "output vector" (ovector) +within the match data block, and are used to identify the matched string and +any captured substrings when matching with \fBpcre2_match()\fP. If you are +using \fBpcre2_dfa_match()\fP, which uses the output vector in a different way, +you should use \fBpcre2_match_data_create()\fP instead of this function. .P The second argument points to a general context, for custom memory management, -or is NULL to use the same memory allocator as was used for the compiled +or is NULL to use the same memory allocator that was used for the compiled pattern. The result of the function is NULL if the memory for the block could -not be obtained. +not be obtained or if NULL was provided as the first argument. .P There is a complete description of the PCRE2 native API in the .\" HREF diff --git a/doc/pcre2_match_data_free.3 b/doc/pcre2_match_data_free.3 index 855ddce..245b3e2 100644 --- a/doc/pcre2_match_data_free.3 +++ b/doc/pcre2_match_data_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_MATCH_DATA_FREE 3 "16 August 2023" "PCRE2 10.46" +.TH PCRE2_MATCH_DATA_FREE 3 "16 August 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_next_match.3 b/doc/pcre2_next_match.3 new file mode 100644 index 0000000..4c8f4e9 --- /dev/null +++ b/doc/pcre2_next_match.3 @@ -0,0 +1,41 @@ +.TH PCRE2_NEXT_MATCH 3 "24 March 2025" "PCRE2 10.47" +.SH NAME +PCRE2 - Perl-compatible regular expressions (revised API) +.SH SYNOPSIS +.rs +.sp +.B #include +.PP +.nf +.B int pcre2_next_match(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SIZE *\fIpstart_offset\fP, uint32_t *\fIpoptions\fP);" +.fi +. +.SH DESCRIPTION +.rs +.sp +This function can be called after one of the match functions +(\fBpcre2_match()\fP, \fBpcre2_dfa_match()\fP, or \fBpcre2_jit_match()\fP), and +must be provided with the same \fImatch_data\fP parameter. It outputs the +appropriate parameters for searching for the next match in the same subject +string, and is suitable for applications providing "global" matching behaviour +(for example, replacing all matches in the subject, or splitting the subject on +all matches, or simply counting the number of matches). +.P +It returns 0 ("false") if there is no need to make any further match attempts, +or 1 ("true") if another match should be attempted. +.P +The *\fIpstart_offset\fP and *\fIpoptions\fP are set if the function returns 1. +The *\fIpstart_offset\fP should be passed to the next match attempt directly, +and the *\fIpoptions\fP should be passed to the next match attempt by combining +with the application's match options using OR. +.P +There is a complete description of the PCRE2 native API in the +.\" HREF +\fBpcre2api\fP +.\" +page and a description of the POSIX API in the +.\" HREF +\fBpcre2posix\fP +.\" +page. diff --git a/doc/pcre2_pattern_convert.3 b/doc/pcre2_pattern_convert.3 index f3266f2..4302c52 100644 --- a/doc/pcre2_pattern_convert.3 +++ b/doc/pcre2_pattern_convert.3 @@ -1,4 +1,4 @@ -.TH PCRE2_PATTERN_CONVERT 3 "12 July 2017" "PCRE2 10.46" +.TH PCRE2_PATTERN_CONVERT 3 "12 July 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_pattern_info.3 b/doc/pcre2_pattern_info.3 index 05e133e..aa8c662 100644 --- a/doc/pcre2_pattern_info.3 +++ b/doc/pcre2_pattern_info.3 @@ -1,4 +1,4 @@ -.TH PCRE2_PATTERN_INFO 3 "14 February 2019" "PCRE2 10.46" +.TH PCRE2_PATTERN_INFO 3 "14 February 2019" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_serialize_decode.3 b/doc/pcre2_serialize_decode.3 index b81cf7e..363d73c 100644 --- a/doc/pcre2_serialize_decode.3 +++ b/doc/pcre2_serialize_decode.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SERIALIZE_DECODE 3 "22 April 2022" "PCRE2 10.46" +.TH PCRE2_SERIALIZE_DECODE 3 "22 April 2022" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_serialize_encode.3 b/doc/pcre2_serialize_encode.3 index 9fb7aed..ca0ff3b 100644 --- a/doc/pcre2_serialize_encode.3 +++ b/doc/pcre2_serialize_encode.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SERIALIZE_ENCODE 3 "13 August 2018" "PCRE2 10.46" +.TH PCRE2_SERIALIZE_ENCODE 3 "13 August 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_serialize_free.3 b/doc/pcre2_serialize_free.3 index c90378d..fc563de 100644 --- a/doc/pcre2_serialize_free.3 +++ b/doc/pcre2_serialize_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SERIALIZE_FREE 3 "13 August 2018" "PCRE2 10.46" +.TH PCRE2_SERIALIZE_FREE 3 "13 August 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_serialize_get_number_of_codes.3 b/doc/pcre2_serialize_get_number_of_codes.3 index 689771f..9cb0fbb 100644 --- a/doc/pcre2_serialize_get_number_of_codes.3 +++ b/doc/pcre2_serialize_get_number_of_codes.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SERIALIZE_GET_NUMBER_OF_CODES 3 "13 August 2018" "PCRE2 10.46" +.TH PCRE2_SERIALIZE_GET_NUMBER_OF_CODES 3 "13 August 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_bsr.3 b/doc/pcre2_set_bsr.3 index 6fdf798..a0d6014 100644 --- a/doc/pcre2_set_bsr.3 +++ b/doc/pcre2_set_bsr.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_BSR 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_SET_BSR 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_callout.3 b/doc/pcre2_set_callout.3 index 6e8334c..a71dd7e 100644 --- a/doc/pcre2_set_callout.3 +++ b/doc/pcre2_set_callout.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_CALLOUT 3 "25 March 2017" "PCRE2 10.46" +.TH PCRE2_SET_CALLOUT 3 "25 March 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_character_tables.3 b/doc/pcre2_set_character_tables.3 index 252aa48..e6d0503 100644 --- a/doc/pcre2_set_character_tables.3 +++ b/doc/pcre2_set_character_tables.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_CHARACTER_TABLES 3 "15 April 2020" "PCRE2 10.46" +.TH PCRE2_SET_CHARACTER_TABLES 3 "15 April 2020" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_compile_extra_options.3 b/doc/pcre2_set_compile_extra_options.3 index 37e2d4c..56e8e00 100644 --- a/doc/pcre2_set_compile_extra_options.3 +++ b/doc/pcre2_set_compile_extra_options.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_COMPILE_EXTRA_OPTIONS 3 "14 October 2024" "PCRE2 10.46" +.TH PCRE2_SET_COMPILE_EXTRA_OPTIONS 3 "14 October 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_compile_recursion_guard.3 b/doc/pcre2_set_compile_recursion_guard.3 index e6126cb..44ed685 100644 --- a/doc/pcre2_set_compile_recursion_guard.3 +++ b/doc/pcre2_set_compile_recursion_guard.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_COMPILE_RECURSION_GUARD 3 "26 November 2014" "PCRE2 10.46" +.TH PCRE2_SET_COMPILE_RECURSION_GUARD 3 "26 November 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_depth_limit.3 b/doc/pcre2_set_depth_limit.3 index 5ae81db..a816a0c 100644 --- a/doc/pcre2_set_depth_limit.3 +++ b/doc/pcre2_set_depth_limit.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_DEPTH_LIMIT 3 "25 March 2017" "PCRE2 10.46" +.TH PCRE2_SET_DEPTH_LIMIT 3 "25 March 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_glob_escape.3 b/doc/pcre2_set_glob_escape.3 index 7e52e97..89c2ee3 100644 --- a/doc/pcre2_set_glob_escape.3 +++ b/doc/pcre2_set_glob_escape.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_GLOB_ESCAPE 3 "12 July 2017" "PCRE2 10.46" +.TH PCRE2_SET_GLOB_ESCAPE 3 "12 July 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_glob_separator.3 b/doc/pcre2_set_glob_separator.3 index 36ebdb9..14e8e2f 100644 --- a/doc/pcre2_set_glob_separator.3 +++ b/doc/pcre2_set_glob_separator.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_GLOB_SEPARATOR 3 "17 June 2018" "PCRE2 10.46" +.TH PCRE2_SET_GLOB_SEPARATOR 3 "17 June 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_heap_limit.3 b/doc/pcre2_set_heap_limit.3 index f240309..05a69f1 100644 --- a/doc/pcre2_set_heap_limit.3 +++ b/doc/pcre2_set_heap_limit.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_HEAP_LIMIT 3 "17 June 2018" "PCRE2 10.46" +.TH PCRE2_SET_HEAP_LIMIT 3 "17 June 2018" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_match_limit.3 b/doc/pcre2_set_match_limit.3 index c15172c..d5e34c1 100644 --- a/doc/pcre2_set_match_limit.3 +++ b/doc/pcre2_set_match_limit.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_MATCH_LIMIT 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_SET_MATCH_LIMIT 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_max_pattern_compiled_length.3 b/doc/pcre2_set_max_pattern_compiled_length.3 index 2d1e6dd..bfb7fe0 100644 --- a/doc/pcre2_set_max_pattern_compiled_length.3 +++ b/doc/pcre2_set_max_pattern_compiled_length.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_MAX_PATTERN_COMPILED_LENGTH 3 "09 June 2024" "PCRE2 10.46" +.TH PCRE2_SET_MAX_PATTERN_COMPILED_LENGTH 3 "09 June 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_max_pattern_length.3 b/doc/pcre2_set_max_pattern_length.3 index 7a8b345..7d5aa85 100644 --- a/doc/pcre2_set_max_pattern_length.3 +++ b/doc/pcre2_set_max_pattern_length.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_MAX_PATTERN_LENGTH 3 "05 October 2016" "PCRE2 10.46" +.TH PCRE2_SET_MAX_PATTERN_LENGTH 3 "05 October 2016" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_max_varlookbehind.3 b/doc/pcre2_set_max_varlookbehind.3 index ce97886..95bb273 100644 --- a/doc/pcre2_set_max_varlookbehind.3 +++ b/doc/pcre2_set_max_varlookbehind.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_NEWLINE 3 "11 August 2023" "PCRE2 10.46" +.TH PCRE2_SET_NEWLINE 3 "11 August 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_newline.3 b/doc/pcre2_set_newline.3 index 54747b7..40aae44 100644 --- a/doc/pcre2_set_newline.3 +++ b/doc/pcre2_set_newline.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_NEWLINE 3 "19 July 2017" "PCRE2 10.46" +.TH PCRE2_SET_NEWLINE 3 "19 July 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_offset_limit.3 b/doc/pcre2_set_offset_limit.3 index b9b694f..031b376 100644 --- a/doc/pcre2_set_offset_limit.3 +++ b/doc/pcre2_set_offset_limit.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_OFFSET_LIMIT 3 "22 September 2015" "PCRE2 10.46" +.TH PCRE2_SET_OFFSET_LIMIT 3 "22 September 2015" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_optimize.3 b/doc/pcre2_set_optimize.3 index 3fc4c9e..499cd62 100644 --- a/doc/pcre2_set_optimize.3 +++ b/doc/pcre2_set_optimize.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_OPTIMIZE 3 "22 September 2024" "PCRE2 10.46" +.TH PCRE2_SET_OPTIMIZE 3 "22 September 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_parens_nest_limit.3 b/doc/pcre2_set_parens_nest_limit.3 index ccc8542..bc19bf0 100644 --- a/doc/pcre2_set_parens_nest_limit.3 +++ b/doc/pcre2_set_parens_nest_limit.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_PARENS_NEST_LIMIT 3 "25 October 2014" "PCRE2 10.46" +.TH PCRE2_SET_PARENS_NEST_LIMIT 3 "25 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_recursion_limit.3 b/doc/pcre2_set_recursion_limit.3 index eeaad17..c0bc551 100644 --- a/doc/pcre2_set_recursion_limit.3 +++ b/doc/pcre2_set_recursion_limit.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_RECURSION_LIMIT 3 "19 July 2017" "PCRE2 10.46" +.TH PCRE2_SET_RECURSION_LIMIT 3 "19 July 2017" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_recursion_memory_management.3 b/doc/pcre2_set_recursion_memory_management.3 index 68bd7ba..392e514 100644 --- a/doc/pcre2_set_recursion_memory_management.3 +++ b/doc/pcre2_set_recursion_memory_management.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_RECURSION_MEMORY_MANAGEMENT 3 "23 January 2023" "PCRE2 10.46" +.TH PCRE2_SET_RECURSION_MEMORY_MANAGEMENT 3 "23 January 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_substitute_callout.3 b/doc/pcre2_set_substitute_callout.3 index bada5a3..a10359a 100644 --- a/doc/pcre2_set_substitute_callout.3 +++ b/doc/pcre2_set_substitute_callout.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_SUBSTITUTE_CALLOUT 3 "04 October 2024" "PCRE2 10.46" +.TH PCRE2_SET_SUBSTITUTE_CALLOUT 3 "04 October 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_set_substitute_case_callout.3 b/doc/pcre2_set_substitute_case_callout.3 index 5e54890..ab2f8f4 100644 --- a/doc/pcre2_set_substitute_case_callout.3 +++ b/doc/pcre2_set_substitute_case_callout.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SET_SUBSTITUTE_CASE_CALLOUT 3 "26 December 2024" "PCRE2 10.46" +.TH PCRE2_SET_SUBSTITUTE_CASE_CALLOUT 3 "26 December 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substitute.3 b/doc/pcre2_substitute.3 index 10ffcc8..b1fbd0c 100644 --- a/doc/pcre2_substitute.3 +++ b/doc/pcre2_substitute.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTITUTE 3 "27 November 2021" "PCRE2 10.46" +.TH PCRE2_SUBSTITUTE 3 "03 October 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -91,8 +91,9 @@ If PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_EXTENDED, PCRE2_SUBSTITUTE_UNKNOWN_UNSET, and PCRE2_SUBSTITUTE_UNSET_EMPTY are ignored. .P If PCRE2_SUBSTITUTE_MATCHED is set, \fImatch_data\fP must be non-NULL; its -contents must be the result of a call to \fBpcre2_match()\fP using the same -pattern and subject. +contents must be the result of a call to \fBpcre2_match()\fP (or +\fBpcre2_jit_match()\fP) using the same pattern, subject pointer, effective +subject length, start offset, and match options. .P The function returns the number of substitutions, which may be zero if there are no matches. The result may be greater than one only when diff --git a/doc/pcre2_substring_copy_byname.3 b/doc/pcre2_substring_copy_byname.3 index bffc429..78d05f4 100644 --- a/doc/pcre2_substring_copy_byname.3 +++ b/doc/pcre2_substring_copy_byname.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_COPY_BYNAME 3 "19 December 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_COPY_BYNAME 3 "19 December 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substring_copy_bynumber.3 b/doc/pcre2_substring_copy_bynumber.3 index c1ab9f3..bb0e1ec 100644 --- a/doc/pcre2_substring_copy_bynumber.3 +++ b/doc/pcre2_substring_copy_bynumber.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_COPY_BYNUMBER 3 "13 December 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_COPY_BYNUMBER 3 "13 December 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substring_free.3 b/doc/pcre2_substring_free.3 index 340be6c..47d13ed 100644 --- a/doc/pcre2_substring_free.3 +++ b/doc/pcre2_substring_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_FREE 3 "28 June 2018" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_FREE 3 "26 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -6,8 +6,9 @@ PCRE2 - Perl-compatible regular expressions (revised API) .sp .B #include .PP -.SM +.nf .B void pcre2_substring_free(PCRE2_UCHAR *\fIbuffer\fP); +.fi . .SH DESCRIPTION .rs diff --git a/doc/pcre2_substring_get_byname.3 b/doc/pcre2_substring_get_byname.3 index 90e3310..23abdaf 100644 --- a/doc/pcre2_substring_get_byname.3 +++ b/doc/pcre2_substring_get_byname.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_GET_BYNAME 3 "19 December 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_GET_BYNAME 3 "19 December 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substring_get_bynumber.3 b/doc/pcre2_substring_get_bynumber.3 index 8017f2d..ffa9dc6 100644 --- a/doc/pcre2_substring_get_bynumber.3 +++ b/doc/pcre2_substring_get_bynumber.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_GET_BYNUMBER 3 "13 December 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_GET_BYNUMBER 3 "13 December 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substring_length_byname.3 b/doc/pcre2_substring_length_byname.3 index 111fccd..d9cc946 100644 --- a/doc/pcre2_substring_length_byname.3 +++ b/doc/pcre2_substring_length_byname.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_LENGTH_BYNAME 3 "21 October 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_LENGTH_BYNAME 3 "26 September 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -19,9 +19,11 @@ The arguments are: .sp \fImatch_data\fP The match data block for the match \fIname\fP The substring name - \fIlength\fP Where to return the length + \fIlength\fP Where to return the length, or NULL .sp -The yield is zero on success, or an error code if the substring is not found. +The third argument may be NULL if all you want to know is whether or not a +substring is set. The yield is zero on success, or a negative error code +otherwise. .P There is a complete description of the PCRE2 native API in the .\" HREF diff --git a/doc/pcre2_substring_length_bynumber.3 b/doc/pcre2_substring_length_bynumber.3 index bc7c4c1..10e5233 100644 --- a/doc/pcre2_substring_length_bynumber.3 +++ b/doc/pcre2_substring_length_bynumber.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_LENGTH_BYNUMBER 3 "22 December 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_LENGTH_BYNUMBER 3 "22 December 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substring_list_free.3 b/doc/pcre2_substring_list_free.3 index 4e02b69..ee78b4e 100644 --- a/doc/pcre2_substring_list_free.3 +++ b/doc/pcre2_substring_list_free.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_LIST_FREE 3 "02 December 2023" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_LIST_FREE 3 "26 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -6,8 +6,9 @@ PCRE2 - Perl-compatible regular expressions (revised API) .sp .B #include .PP -.SM +.nf .B void pcre2_substring_list_free(PCRE2_UCHAR **\fIlist\fP); +.fi . .SH DESCRIPTION .rs diff --git a/doc/pcre2_substring_list_get.3 b/doc/pcre2_substring_list_get.3 index 20cc72c..50b50e4 100644 --- a/doc/pcre2_substring_list_get.3 +++ b/doc/pcre2_substring_list_get.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_LIST_GET 3 "21 October 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_LIST_GET 3 "21 October 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substring_nametable_scan.3 b/doc/pcre2_substring_nametable_scan.3 index 6a9f22a..fb93b2f 100644 --- a/doc/pcre2_substring_nametable_scan.3 +++ b/doc/pcre2_substring_nametable_scan.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_NAMETABLE_SCAN 3 "06 February 2019" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_NAMETABLE_SCAN 3 "06 February 2019" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2_substring_number_from_name.3 b/doc/pcre2_substring_number_from_name.3 index 03b445b..b9be3b5 100644 --- a/doc/pcre2_substring_number_from_name.3 +++ b/doc/pcre2_substring_number_from_name.3 @@ -1,4 +1,4 @@ -.TH PCRE2_SUBSTRING_NUMBER_FROM_NAME 3 "03 November 2014" "PCRE2 10.46" +.TH PCRE2_SUBSTRING_NUMBER_FROM_NAME 3 "03 November 2014" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS diff --git a/doc/pcre2api.3 b/doc/pcre2api.3 index b09d7ab..a5ea17b 100644 --- a/doc/pcre2api.3 +++ b/doc/pcre2api.3 @@ -1,4 +1,4 @@ -.TH PCRE2API 3 "26 December 2024" "PCRE2 10.46" +.TH PCRE2API 3 "19 October 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .sp @@ -105,7 +105,7 @@ document for an overview of all the PCRE2 documentation. .B " pcre2_compile_context *\fIccontext\fP, PCRE2_SIZE \fIvalue\fP);" .sp .B int pcre2_set_max_varlookbehind(pcre2_compile_contest *\fIccontext\fP, -.B " uint32_t \fIvalue\fP); +.B " uint32_t \fIvalue\fP);" .sp .B int pcre2_set_newline(pcre2_compile_context *\fIccontext\fP, .B " uint32_t \fIvalue\fP);" @@ -196,7 +196,7 @@ document for an overview of all the PCRE2 documentation. .B void pcre2_substring_list_free(PCRE2_UCHAR **\fIlist\fP); .sp .B int pcre2_substring_list_get(pcre2_match_data *\fImatch_data\fP, -.B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP); +.B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP);" .fi . . @@ -207,7 +207,7 @@ document for an overview of all the PCRE2 documentation. .B int pcre2_substitute(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP, .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP," .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP," -.B " pcre2_match_context *\fImcontext\fP, PCRE2_SPTR \fIreplacementz\fP," +.B " pcre2_match_context *\fImcontext\fP, PCRE2_SPTR \fIreplacement\fP," .B " PCRE2_SIZE \fIrlength\fP, PCRE2_UCHAR *\fIoutputbuffer\fP," .B " PCRE2_SIZE *\fIoutlengthptr\fP);" .fi @@ -497,7 +497,7 @@ compiled patterns on disc or elsewhere, and reloading them later. .P Finally, there are functions for finding out information about a compiled pattern (\fBpcre2_pattern_info()\fP) and about the configuration with which -PCRE2 was built (\fBpcre2_config()\fP). +PCRE2 was built (\fBpcre2_config()\fP) and that it is using. .P Functions with names ending with \fB_free()\fP are used for freeing memory blocks of various sorts. In all cases, if one of these functions is called with @@ -831,7 +831,7 @@ can hold, which is effectively unlimited. .sp .nf .B int pcre2_set_max_varlookbehind(pcre2_compile_contest *\fIccontext\fP, -.B " uint32_t \fIvalue\fP); +.B " uint32_t \fIvalue\fP);" .fi .sp This sets a maximum length for the number of characters matched by a @@ -1265,6 +1265,13 @@ The output is a uint32_t integer that gives the default limit for the depth of nested backtracking in \fBpcre2_match()\fP or the depth of nested recursions, lookarounds, and atomic groups in \fBpcre2_dfa_match()\fP. Further details are given with \fBpcre2_set_depth_limit()\fP above. +.sp + PCRE2_CONFIG_EFFECTIVE_LINKSIZE +.sp +The output is a uint32_t integer that contains the number of bytes the library +uses for internal linkage in compiled regular expressions. Its value is derived +from the value that was provided at build time and that is described below by +PCRE2_CONFIG_LINKSIZE. .sp PCRE2_CONFIG_HEAPLIMIT .sp @@ -1289,7 +1296,7 @@ documentation for more details. .sp PCRE2_CONFIG_JITTARGET .sp -The \fIwhere\fP argument should point to a buffer that is at least 48 code +The \fIwhere\fP argument should point to a buffer that is at least 64 code units long. (The exact length required can be found by calling \fBpcre2_config()\fP with \fBwhere\fP set to NULL.) The buffer is filled with a string that contains the name of the architecture for which the JIT compiler is @@ -1300,13 +1307,14 @@ for the terminating zero. .sp PCRE2_CONFIG_LINKSIZE .sp -The output is a uint32_t integer that contains the number of bytes used for -internal linkage in compiled regular expressions. When PCRE2 is configured, the -value can be set to 2, 3, or 4, with the default being 2. This is the value -that is returned by \fBpcre2_config()\fP. However, when the 16-bit library is -compiled, a value of 3 is rounded up to 4, and when the 32-bit library is -compiled, internal linkages always use 4 bytes, so the configured value is not -relevant. +The output is a uint32_t integer that contains the number of bytes the library +was instructed to use for internal linkage in compiled regular expressions. +When PCRE2 is configured, the value can be set to 2, 3, or 4, with the default +being 2 for most libraries. +.P +The actual number of bytes used depends on the size of the code units that the +library supports and can be higher. See PCRE2_CONFIG_EFFECTIVE_LINKSIZE above +for details. .P The default value of 2 for the 8-bit and 16-bit libraries is sufficient for all but the most massive patterns, since it allows the size of the compiled pattern @@ -1584,8 +1592,7 @@ case the following character). (3) \ex matches a lower case "x" character unless it is followed by two hexadecimal digits, in which case the hexadecimal number defines the code point to match. By default, as in Perl, a hexadecimal number is always expected after -\ex, but it may have zero, one, or two digits (so, for example, \exz matches a -binary zero character followed by z). +\ex, but it may have one or two digits. .P ECMAscript 6 added additional functionality to \eu. This can be accessed using the PCRE2_EXTRA_ALT_BSUX extra option (see "Extra compile options" @@ -1628,7 +1635,7 @@ option is set, normal backslash processing is applied to verb names and only an unescaped closing parenthesis terminates the name. A closing parenthesis can be included in a name either as \e) or between \eQ and \eE. If the PCRE2_EXTENDED or PCRE2_EXTENDED_MORE option is set with PCRE2_ALT_VERBNAMES, unescaped -whitespace in verb names is skipped and #-comments are recognized, exactly as +white space in verb names is skipped and #-comments are recognized, exactly as in the rest of the pattern. .sp PCRE2_AUTO_CALLOUT @@ -1926,8 +1933,9 @@ instead.) .sp This is an option whose main effect is at matching time. It does not change what \fBpcre2_compile()\fP generates, but it does affect the output of the JIT -compiler. Setting this option is equivalent to calling \fBpcre2_set_optimize()\fP -with the \fIdirective\fP parameter set to PCRE2_START_OPTIMIZE_OFF. +compiler. Setting this option is equivalent to calling +\fBpcre2_set_optimize()\fP with the \fIdirective\fP parameter set to +PCRE2_START_OPTIMIZE_OFF. .P There are a number of optimizations that may occur at the start of a match, in order to speed up the process. For example, if it is known that an unanchored @@ -2012,9 +2020,9 @@ only if PCRE2 has been compiled with Unicode support (which is the default). .P The PCRE2_EXTRA_CASELESS_RESTRICT option (see above) restricts caseless matching such that ASCII characters match only ASCII characters and non-ASCII -characters match only non-ASCII characters. The PCRE2_EXTRA_TURKISH_CASING option -(see above) alters the matching of the 'i' characters to follow their behaviour -in Turkish and Azeri languages. For further details on +characters match only non-ASCII characters. The PCRE2_EXTRA_TURKISH_CASING +option (see above) alters the matching of the 'i' characters to follow their +behaviour in Turkish and Azeri languages. For further details on PCRE2_EXTRA_CASELESS_RESTRICT and PCRE2_EXTRA_TURKISH_CASING, see the .\" HREF \fBpcre2unicode\fP @@ -2958,18 +2966,13 @@ is able to look behind the starting point to discover that it is preceded by a letter. .P Finding all the matches in a subject is tricky when the pattern can match an -empty string. It is possible to emulate Perl's /g behaviour by first trying the -match again at the same offset, with the PCRE2_NOTEMPTY_ATSTART and -PCRE2_ANCHORED options, and then if that fails, advancing the starting offset -and trying an ordinary match again. There is some code that demonstrates how to -do this in the -.\" HREF -\fBpcre2demo\fP +empty string. PCRE2 includes a helper API to assist with this; see the +section entitled "Iterating over all matches" +.\" HTML +.\" +below .\" -sample program. In the most general case, you have to check to see if the -newline convention recognizes CRLF as a newline, and if so, and the current -character is CR followed by LF, advance the starting offset by two characters -instead of one. +for details. .P If a non-zero starting offset is passed when the pattern is anchored, a single attempt to match at the given offset is made. This can only succeed if the @@ -2999,7 +3002,7 @@ PCRE2_DISABLE_RECURSELOOP_CHECK is ignored by JIT, but apart from PCRE2_NO_JIT .sp The PCRE2_ANCHORED option limits \fBpcre2_match()\fP to matching at the first matching position. If a pattern was compiled with PCRE2_ANCHORED, or turned out -to be anchored by virtue of its contents, it cannot be made unachored at +to be anchored by virtue of its contents, it cannot be made unanchored at matching time. Note that setting the option at match time disables JIT matching. .sp @@ -3162,7 +3165,7 @@ If PCRE2_PARTIAL_HARD is set, it overrides PCRE2_PARTIAL_SOFT. In this case, if a partial match is found, \fBpcre2_match()\fP immediately returns PCRE2_ERROR_PARTIAL, without considering any other alternatives. In other words, when PCRE2_PARTIAL_HARD is set, a partial match is considered to be more -important that an alternative complete match. +important than an alternative complete match. .P There is a more detailed discussion of partial and multi-segment matching, with examples, in the @@ -3285,10 +3288,10 @@ set. For example, if two substrings have been captured, the returned value is 3. If there are no captured substrings, the return value from a successful match is 1, indicating that just the first pair of offsets has been set. .P -If a pattern uses the \eK escape sequence within a positive assertion, the -reported start of a successful match can be greater than the end of the match. -For example, if the pattern (?=ab\eK) is matched against "ab", the start and -end offset values for the match are 2 and 0. +If a pattern uses the \eK escape sequence within a positive lookahead assertion, +the reported start of a successful match can be greater than the end of the +match. For example, if the pattern (?=ab\eK) is matched against "ab", the start +and end offset values for the match are 2 and 0. .P If a capture group is matched repeatedly within a single match operation, it is the last portion of the subject that it matched that is returned. @@ -3524,7 +3527,96 @@ returns the number of code units used, excluding the trailing zero. If the error number is unknown, the negative error code PCRE2_ERROR_BADDATA is returned. If the buffer is too small, the message is truncated (but still with a trailing zero), and the negative error code PCRE2_ERROR_NOMEMORY is returned. -None of the messages are very long; a buffer size of 120 code units is ample. +None of the messages is very long; a buffer size of 120 code units is ample. +. +. +.\" HTML +.SH "ITERATING OVER ALL MATCHES" +.rs +.sp +.nf +.B int pcre2_next_match(pcre2_match_data *\fImatch_data\fP, +.B " PCRE2_SIZE *\fIpstart_offset\fP, uint32_t *\fIpoptions\fP);" +.fi +.P +A common task for applications is to implement "global" matching behaviour, +for example, replacing all matches in the subject; splitting the subject on all +matches; or simply counting the number of matches. The \fBpcre2_next_match()\fP +function helps with this task by providing the appropriate parameters for the +next match attempt (available since PCRE2 10.46). +.P +First, a match attempt should be made using one of the matching functions +(\fBpcre2_match()\fP, \fBpcre2_dfa_match()\fP, or \fBpcre2_jit_match()\fP). +Then, \fBpcre2_next_match()\fP can be called, providing the same +\fImatch_data\fP parameter. +.P +It returns 0 ("false") if there is no need to make a further match attempt, or +1 ("true") if another match should be attempted. Returning 1 does not imply that +there is another match, only that another match should be attempted (which may +return PCRE2_ERROR_NOMATCH). +.P +The *\fIpstart_offset\fP and *\fIpoptions\fP are set if the function returns 1. +The *\fIpstart_offset\fP should be passed to the next match attempt directly, +and the *\fIpoptions\fP should be passed to the next match attempt by combining +with the application's match options using OR. +.P +There is some code that demonstrates how to do this in the +.\" HREF +\fBpcre2demo\fP +.\" +sample program. The general pattern is: +.sp +.nf + uint32_t app_options = ...; + uint32_t global_options = 0; + PCRE2_SIZE start_offset = 0; + while (1) + { + int rc = pcre2_match(re, subject, subject_len, start_offset, + app_options | global_options, match_data, + match_context); +\& + if (rc == PCRE2_ERROR_NOMATCH) break; /* no match, and no more attempts */ + if (rc < 0) { ... exit } +\& + ...handle the match +\& + if (!pcre2_next_match(match_data, &start_offset, &global_options)) + break; /* no more attempts */ + } +.fi +.P +The guarantees provided by \fBpcre2_next_match()\fP are that the start_offset +will advance, so the loop will definitely terminate. The conditions which +ensure this are that either: (a) pcre2_next_match() returns 0 (false); or +(b) the returned *\fIpstart_offset\fP is strictly greater than the previous +start_offset; or (c) if the previous match was a successful match of the empty +string then the returned *\fIpstart_offset\fP is equal to the previous +ovector[1], and *\fIpoptions\fP will be set to PCRE2_NOTEMPTY_ATSTART to prevent +another empty match from being returned. +.P +A loop implemented as shown above will always terminate, unless there is a bug +in PCRE2. As a measure of "defensive programming", applications are encouraged +to add an assertion or check to break their loop if it does not make progress +(and report the issue as a bug). +.P +If an application does not use the flag PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK, then +each match is "well-behaved" and satisfies: +.sp + start_offset <= ovector[0] <= ovector[1]. +.sp +In this case, the matches found by pcre2_match() with pcre2_next_match() will be +sorted, non-overlapping (possibly touching), and with no duplicates. +.P +Otherwise, if PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK is used, then the guarantees are +considerably weaker. We do not guarantee that the matches will always advance: +only that the start_offset will. The matches found by pcre2_match() with +pcre2_next_match() will be a finite sequence (as pcre2_next_match() ensures that +start_offset advances, so the search will terminate). The matches can however be +overlapping, can contain duplicates, and (in truly pathological examples) may +not even be sorted by ovector[0]. Additionally, each match itself can end before +it starts (ovector[1] < ovector[0]). We recommend that applications do not set +PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK. . . .\" HTML @@ -3563,11 +3655,12 @@ substring zero is available. An attempt to extract any other substring gives the error PCRE2_ERROR_PARTIAL. The next section describes similar functions for extracting captured substrings by name. .P -If a pattern uses the \eK escape sequence within a positive assertion, the -reported start of a successful match can be greater than the end of the match. -For example, if the pattern (?=ab\eK) is matched against "ab", the start and -end offset values for the match are 2 and 0. In this situation, calling these -functions with a zero substring number extracts a zero-length empty string. +If a pattern uses the \eK escape sequence within a positive lookahead assertion, +the reported start of a successful match can be greater than the end of the +match. For example, if the pattern (?=ab\eK) is matched against "ab", the start +and end offset values for the match are 2 and 0. In this situation, calling +these functions with a zero substring number extracts a zero-length empty +string. .P You can find the length in code units of a captured substring without extracting it by calling \fBpcre2_substring_length_bynumber()\fP. The first @@ -3626,7 +3719,7 @@ capturing slots, substring number 1 is unset. .sp .nf .B int pcre2_substring_list_get(pcre2_match_data *\fImatch_data\fP, -.B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP); +.B " PCRE2_UCHAR ***\fIlistptr\fP, PCRE2_SIZE **\fIlengthsptr\fP);" .sp .B void pcre2_substring_list_free(PCRE2_UCHAR **\fIlist\fP); .fi @@ -3756,7 +3849,8 @@ Matches in which a \eK item in a lookahead in the pattern causes the match to end before it starts are not supported, and give rise to an error return. For global replacements, matches in which \eK in a lookbehind causes the match to start earlier than the point that was reached in the previous iteration are -also not supported. +also not supported. (These cases are only possible if the pattern was compiled +with the backwards-compatibility option PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK.) .P The first seven arguments of \fBpcre2_substitute()\fP are the same as for \fBpcre2_match()\fP, except that the partial matching options are not @@ -3767,7 +3861,8 @@ allocate memory for the compiled code. .P If \fImatch_data\fP is not NULL and PCRE2_SUBSTITUTE_MATCHED is not set, the provided block is used for all calls to \fBpcre2_match()\fP, and its contents -afterwards are the result of the final call. For global changes, this will +afterwards are the result of the final call made internally by +\fBpcre2_substitute()\fP to the matching function. For global changes, this will always be a no-match error. The contents of the ovector within the match data block may or may not have been changed. .P @@ -3775,23 +3870,45 @@ As well as the usual options for \fBpcre2_match()\fP, a number of additional options can be set in the \fIoptions\fP argument of \fBpcre2_substitute()\fP. One such option is PCRE2_SUBSTITUTE_MATCHED. When this is set, an external \fImatch_data\fP block must be provided, and it must have already been used for -an external call to \fBpcre2_match()\fP with the same pattern and subject -arguments. The data in the \fImatch_data\fP block (return code, offset vector) -is then used for the first substitution instead of calling \fBpcre2_match()\fP -from within \fBpcre2_substitute()\fP. This allows an application to check for a -match before choosing to substitute, without having to repeat the match. +an external call to \fBpcre2_match()\fP (or \fBpcre2_jit_match()\fP) with the +same pattern, subject pointer, effective subject length, start offset, and match +option arguments (substitute-specific options can be added to the \fIoptions\fP +argument). If any of these parameters is changed, \fBpcre2_substitute()\fP +returns an error. The data in the \fImatch_data\fP block (return code, offset +vector) is used for the first substitution instead of calling +\fBpcre2_match()\fP from within \fBpcre2_substitute()\fP. This allows an +application to check for a match before choosing to substitute, without having +to repeat the match. +.P +If the contents of the subject buffer are mutated in between \fBpcre2_match()\fP +and a call to \fBpcre2_substitute()\fP with PCRE2_SUBSTITUTE_MATCHED, the +behaviour is unsafe; in particular, in this case, PCRE2 is unable to ensure that +the offsets in the ovector point to the start of characters (with UTF-encoded +input). .P The contents of the externally supplied match data block are not changed when -PCRE2_SUBSTITUTE_MATCHED is set. If PCRE2_SUBSTITUTE_GLOBAL is also set, -\fBpcre2_match()\fP is called after the first substitution to check for further -matches, but this is done using an internally obtained match data block, thus -always leaving the external block unchanged. +PCRE2_SUBSTITUTE_MATCHED is set, and so the match block is permitted for use in +another call using PCRE2_SUBSTITUTE_MATCHED. If PCRE2_SUBSTITUTE_GLOBAL is also +set, \fBpcre2_match()\fP is called after the first substitution to check for +furthe matches, but this is done using an internally obtained match data block, +thus always leaving the external block unchanged. .P The \fIcode\fP argument is not used for matching before the first substitution when PCRE2_SUBSTITUTE_MATCHED is set, but it must be provided, even when PCRE2_SUBSTITUTE_GLOBAL is not set, because it contains information such as the UTF setting and the number of capturing parentheses in the pattern. .P +When using PCRE2_SUBSTITUTE_MATCHED, you should not modify the subject string +in between the prior call to \fBpcre2_match()\fP and \fBpcre2_substitute()\fP, +as the substitution assumes that the passed-in ovector is compatible with the +subject string. Although PCRE2 does verify that the subject is a pointer to the +same buffer, it cannot in general verify whether the contents of the buffer have +changed. For example, if the subject buffer is mutated from one valid UTF-8 +string to another valid string, of the same length in code units, the ovector +offsets are no longer guaranteed to point to the start of a character. Beware +that with PCRE2_SUBSTITUTE_MATCHED in UTF mode, the subject string is not +re-scanned for UTF validity when \fBpcre2_substitute()\fP first uses it. +.P The default action of \fBpcre2_substitute()\fP is to return a copy of the subject string with matched substrings replaced. However, if PCRE2_SUBSTITUTE_REPLACEMENT_ONLY is set, only the replacement substrings are @@ -3847,10 +3964,11 @@ recognized: $` insert the substring that precedes the match $' insert the substring that follows the match $_ insert the entire input string + $+ insert the highest-numbered capture group which matched $*MARK or ${*MARK} insert a control verb name .sp -Either a group number or a group name can be given for \fIn\fP, for example $2 or -$NAME. Curly brackets are required only if the following character would be +Either a group number or a group name can be given for \fIn\fP, for example $2 +or $NAME. Curly brackets are required only if the following character would be interpreted as part of the number or name. The number may be zero to include the entire matched string. For example, if the pattern a(b)c is matched with "=abc=" and the replacement string "+$1$0$1+", the result is "=+babcb+=". @@ -3877,6 +3995,17 @@ Iteration is implemented by advancing the \fIstartoffset\fP value for each search, which is always passed the entire subject string. If an offset limit is set in the match context, searching stops when that limit is reached. .P +Because global substitutions apply the pattern repeatedly to the subject string, +and always iterate over non-overlapping matches, the substitutions done by +\fBpcre2_substitute()\fP do not match and substitute text inside the replacement +strings themselves (no recursive/iterative substitution). However, applications +can easily implement other alternative replacement strategies, such as +iteratively replacing, then matching and replacing on the result. The +replacement loop inside \fBpcre2_substitute()\fP is simple and can be emulated +in client code by allocating a buffer, searching for matches in a loop, and +calling \fBpcre2_substitute()\fP with PCRE2_SUBSTITUTE_REPLACEMENT_ONLY an +PCRE2_SUBSTITUTE_MATCHED, and without PCRE2_SUBSTITUTE_GLOBAL. +.P You can restrict the effect of a global substitution to a portion of the subject string by setting either or both of \fIstartoffset\fP and an offset limit. Here is a \fBpcre2test\fP example: @@ -3921,9 +4050,9 @@ in a pattern, which in Perl has some ambiguities. Details are given in the .\" page. .P -The Python form \eg, where the angle brackets are part of the syntax and \fIn\fP -is either a group name or number, is recognized as an altertive way of -inserting the contents of a group, for example \eg<3>. +The Python form \eg, where the angle brackets are part of the syntax and +\fIn\fP is either a group name or number, is recognized as an alternative way +of inserting the contents of a group, for example \eg<3>. .P There are also four escape sequences for forcing the case of inserted letters. Case forcing applies to all inserted characters, including those from capture @@ -4018,7 +4147,7 @@ replacement string, with more particular errors being PCRE2_ERROR_BADREPESCAPE not found), PCRE2_ERROR_BADSUBSTITUTION (syntax error in extended group substitution), and PCRE2_ERROR_BADSUBSPATTERN (the pattern match ended before it started or the match started earlier than the current position in the -subject, which can happen if \eK is used in an assertion). +subject, which can happen if \eK is used in a lookaround assertion). .P As for all PCRE2 errors, a text message that describes the error can be obtained by calling the \fBpcre2_get_error_message()\fP function (see @@ -4039,7 +4168,7 @@ above). .B " void *\fIcallout_data\fP);" .fi .sp -The \fBpcre2_set_substitution_callout()\fP function can be used to specify a +The \fBpcre2_set_substitute_callout()\fP function can be used to specify a callout function for \fBpcre2_substitute()\fP. This information is passed in a match context. The callout function is called after each substitution has been processed, but it can cause the replacement not to happen. @@ -4107,7 +4236,7 @@ matches so far. .B " void *\fIcallout_data\fP);" .fi .sp -The \fBpcre2_set_substitution_case_callout()\fP function can be used to specify +The \fBpcre2_set_substitute_case_callout()\fP function can be used to specify a callout function for \fBpcre2_substitute()\fP to use when performing case transformations. This does not affect any case insensitivity behaviour when performing a match, but only the user-visible transformations performed when @@ -4477,6 +4606,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 26 December 2024 +Last updated: 19 October 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2build.3 b/doc/pcre2build.3 index 787e02d..e7af55a 100644 --- a/doc/pcre2build.3 +++ b/doc/pcre2build.3 @@ -1,4 +1,4 @@ -.TH PCRE2BUILD 3 "16 April 2024" "PCRE2 10.46" +.TH PCRE2BUILD 3 "17 October 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) . @@ -7,9 +7,9 @@ PCRE2 - Perl-compatible regular expressions (revised API) .rs .sp PCRE2 is distributed with a \fBconfigure\fP script that can be used to build -the library in Unix-like environments using the applications known as -Autotools. Also in the distribution are files to support building using -\fBCMake\fP instead of \fBconfigure\fP. The text file +the library in Unix-like environments using the Autotools applications. Also in +the distribution are files to support building using \fBCMake\fP instead of +\fBconfigure\fP. The text file .\" HTML .\" \fBREADME\fP @@ -134,8 +134,8 @@ UTF support allows the libraries to process character code points up to 0x10ffff in the strings that they handle. Unicode support also gives access to the Unicode properties of characters, using pattern escapes such as \eP, \ep, and \eX. Only the general category properties such as \fILu\fP and \fINd\fP, -script names, and some bi-directional properties are supported. Details are -given in the +script names, and some bi-directional and binary properties are supported. +Details are given in the .\" HREF \fBpcre2pattern\fP .\" @@ -152,8 +152,8 @@ request this by starting with (*UCP). .sp The \eC escape sequence, which matches a single code unit, even in a UTF mode, can cause unpredictable behaviour because it may leave the current matching -point in the middle of a multi-code-unit character. The application can lock it -out by setting the PCRE2_NEVER_BACKSLASH_C option when calling +point in the middle of a multi-code-unit character. The application can lock +it out by setting the PCRE2_NEVER_BACKSLASH_C option when calling \fBpcre2_compile()\fP. There is also a build-time option .sp --enable-never-backslash-C @@ -395,13 +395,19 @@ most computer operating systems. PCRE2 can, however, be compiled to run in an .sp --enable-ebcdic --disable-unicode .sp -to the \fBconfigure\fP command. This setting implies ---enable-rebuild-chartables. You should only use it if you know that you are in -an EBCDIC environment (for example, an IBM mainframe operating system). +to the \fBconfigure\fP command. You should only use it if you know that you are +in an EBCDIC environment (for example, an IBM mainframe operating system). .P -It is not possible to support both EBCDIC and UTF-8 codes in the same version -of the library. Consequently, --enable-unicode and --enable-ebcdic are mutually -exclusive. +This setting implies --enable-rebuild-chartables, in order to ensure that you +have the correct default character tables for your system's codepage. There is +an exception when you set --enable-ebcdic-ignoring-compiler (see below), which +allows using a default set of EBCDIC 1047 character tables rather than forcing +use of --enable-rebuild-chartables. +.P +It is not supported to enable both EBCDIC input and either ASCII or UTF-8/16/32 +in the same build of the library. When PCRE2 is built with EBCDIC support, it +always operates in EBCDIC, and consequently --enable-unicode and --enable-ebcdic +are mutually exclusive. .P The EBCDIC character that corresponds to an ASCII LF is assumed to have the value 0x15 by default. However, in some EBCDIC environments, 0x25 is used. In @@ -409,14 +415,25 @@ such an environment you should use .sp --enable-ebcdic-nl25 .sp -as well as, or instead of, --enable-ebcdic. The EBCDIC character for CR has the -same value as in ASCII, namely, 0x0d. Whichever of 0x15 and 0x25 is \fInot\fP -chosen as LF is made to correspond to the Unicode NEL character (which, in -Unicode, is 0x85). +(which implies --enable-ebcdic). The EBCDIC character for CR has the same value +as in ASCII, namely, 0x0d. Whichever of 0x15 and 0x25 is \fInot\fP chosen as LF +is made to correspond to the Unicode NEL character (which, in Unicode, is 0x85). .P The options that select newline behaviour, such as --enable-newline-is-cr, and equivalent run-time options, refer to these character values in an EBCDIC environment. +.P +On systems requiring an EBCDIC build of PCRE2, the compiler should be set to use +the correct codepage, so that C character literals such as 'z' use the correct +numeric value for whichever EBCDIC codpage is in use. (PCRE2 cannot support +multiple EBCDIC codepages dynamically.) However, if this not possible, then you +can use +.sp + --enable-ebcdic-ignoring-compiler +.sp +in order to disregard the compiler's codepage, and instead force PCRE2 to use +numeric constants corresponding to the EBCDIC 1047 codepage instead. This can be +used to build (or test) EBCDIC support on an ASCII/UTF-8 system such as Linux. . . .SH "PCRE2GREP SUPPORT FOR EXTERNAL SCRIPTS" @@ -500,7 +517,7 @@ use), some extra configuration may be necessary. The INSTALL file for If your environment has not been set up so that an appropriate library is automatically included, you may need to add something like .sp - LIBS="-ncurses" + LIBS="-lncurses" .sp immediately before the \fBconfigure\fP command. . @@ -660,6 +677,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 16 April 2024 +Last updated: 17 October 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2callout.3 b/doc/pcre2callout.3 index 3726fbc..6ceefa4 100644 --- a/doc/pcre2callout.3 +++ b/doc/pcre2callout.3 @@ -1,4 +1,4 @@ -.TH PCRE2CALLOUT 3 "19 January 2024" "PCRE2 10.46" +.TH PCRE2CALLOUT 3 "26 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH SYNOPSIS @@ -6,7 +6,6 @@ PCRE2 - Perl-compatible regular expressions (revised API) .sp .B #include .PP -.SM .nf .B int (*pcre2_callout)(pcre2_callout_block *, void *); .sp @@ -452,6 +451,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 19 January 2024 +Last updated: 26 February 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2compat.3 b/doc/pcre2compat.3 index 131f576..0a6dc1b 100644 --- a/doc/pcre2compat.3 +++ b/doc/pcre2compat.3 @@ -1,4 +1,4 @@ -.TH PCRE2COMPAT 3 "02 October 2024" "PCRE2 10.46" +.TH PCRE2COMPAT 3 "02 June 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "DIFFERENCES BETWEEN PCRE2 AND PERL" @@ -34,7 +34,11 @@ any kind of quantifier on non-lookaround assertions. .P 4. If a braced quantifier such as {1,2} appears where there is nothing to repeat (for example, at the start of a branch), PCRE2 raises an error whereas -Perl treats the quantifier characters as literal. +Perl treats the quantifier characters as literal. When a braced quantifier +(...){min,max} has min > max, Perl treats it as an item which fails to match +any portion of the subject (as no number of repetitions can meet the +condition), and additionally issues a warning when in warning mode. PCRE2 has +no warning features, so it gives an error in this case. .P 5. Capture groups that occur inside negative lookaround assertions are counted, but their entries in the offsets vector are set only when a negative assertion @@ -186,7 +190,7 @@ variable interpolation, but not general hooks on every match. .sp (h) The partial matching facility is PCRE2-specific. .sp -(i) The alternative matching function (\fBpcre2_dfa_match()\fP matches in a +(i) The alternative matching function (\fBpcre2_dfa_match()\fP) matches in a different way and is not Perl-compatible. .sp (j) PCRE2 recognizes some special sequences such as (*CR) or (*NO_JIT) at @@ -209,7 +213,7 @@ that is not available in Perl. .P 20. Perl has different limits than PCRE2. See the .\" HREF -\fBpcre2limit\fP +\fBpcre2limits\fP .\" documentation for details. Perl went with 5.10 from recursion to iteration keeping the intermediate matches on the heap, which is ~10% slower but does not @@ -228,7 +232,7 @@ handled by PCRE2, either by the interpreter or the JIT. An example is .P 23. Both PCRE2 and Perl error when \ex{ escapes are invalid, but Perl tries to recover and prints a warning if the problem was that an invalid hexadecimal -digit was found, since PCRE2 doesn't have warnings it returns an error instead. +digit was found. Since PCRE2 doesn't have warnings it returns an error instead. Additionally, Perl accepts \ex{} and generates NUL unlike PCRE2. .P 24. From release 10.45, PCRE2 gives an error if \ex is not followed by a @@ -251,6 +255,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 02 October 2024 +Last updated: 02 June 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2convert.3 b/doc/pcre2convert.3 index 8b7a4e6..82448b5 100644 --- a/doc/pcre2convert.3 +++ b/doc/pcre2convert.3 @@ -1,4 +1,4 @@ -.TH PCRE2CONVERT 3 "14 November 2023" "PCRE2 10.46" +.TH PCRE2CONVERT 3 "14 November 2023" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "EXPERIMENTAL PATTERN CONVERSION FUNCTIONS" diff --git a/doc/pcre2demo.3 b/doc/pcre2demo.3 index 3f4da3b..fa08962 100644 --- a/doc/pcre2demo.3 +++ b/doc/pcre2demo.3 @@ -1,5 +1,5 @@ -.TH PCRE2DEMO 3 "31 August 2021" "PCRE2 10.46" -.\"AUTOMATICALLY GENERATED BY PrepareRelease - do not EDIT! +.TH PCRE2DEMO 3 "24 March 2025" "PCRE2 10.47" +.\"AUTOMATICALLY GENERATED BY UpdateAlways - do not EDIT! .SH NAME PCRE2DEMO - A demonstration C program for PCRE2 .SH "SOURCE CODE" @@ -101,36 +101,38 @@ PCRE2_SPTR pattern; /* PCRE2_SPTR is a pointer to unsigned code units of */ PCRE2_SPTR subject; /* the appropriate width (in this case, 8 bits). */ PCRE2_SPTR name_table; -int crlf_is_newline; int errornumber; -int find_all; +int find_all, caseless_match; int i; int rc; -int utf8; -uint32_t option_bits; uint32_t namecount; uint32_t name_entry_size; -uint32_t newline; PCRE2_SIZE erroroffset; PCRE2_SIZE *ovector; +PCRE2_SIZE ovector_last[2]; PCRE2_SIZE subject_length; pcre2_match_data *match_data; /************************************************************************** -* First, sort out the command line. There is only one possible option at * -* the moment, "-g" to request repeated matching to find all occurrences, * -* like Perl's /g option. We set the variable find_all to a non-zero value * -* if the -g option is present. * +* First, sort out the command line. Options: * +* - "-g" to request repeated matching to find all occurrences, * +* like Perl's /g option. We set the variable find_all to a non-zero * +* value if the -g option is present. * +* - "-i" to request caseless matching, like Perl's /i option. We set the * +* variable caseless_match to PCRE2_CASELESS if the -i option is * +* present. * **************************************************************************/ find_all = 0; +caseless_match = 0; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-g") == 0) find_all = 1; + else if (strcmp(argv[i], "-i") == 0) caseless_match = PCRE2_CASELESS; else if (argv[i][0] == '-') { printf("Unrecognised option %s\en", argv[i]); @@ -166,7 +168,7 @@ subject_length = (PCRE2_SIZE)strlen((char *)subject); re = pcre2_compile( pattern, /* the pattern */ PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */ - 0, /* default options */ + caseless_match, /* possibly enable caseless */ &errornumber, /* for error number */ &erroroffset, /* for error offset */ NULL); /* use default compile context */ @@ -246,11 +248,12 @@ if (rc == 0) printf("ovector was not big enough for all the captured substrings\en"); /* Since release 10.38 PCRE2 has locked out the use of \eK in lookaround -assertions. However, there is an option to re-enable the old behaviour. If that -is set, it is possible to run patterns such as /(?=.\eK)/ that use \eK in an -assertion to set the start of a match later than its end. In this demonstration -program, we show how to detect this case, but it shouldn't arise because the -option is never set. */ +assertions. This is the recommended behaviour. However, the option +PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK allows applications to re-enable the old +behaviour. If that is set, it is possible to run patterns such as /(?=.\eK)/ that +use \eK in an assertion to set the start of a match later than its end. In this +demonstration program, we show how to detect this case, although it cannot arise +because the option is never set. */ if (ovector[0] > ovector[1]) { @@ -289,7 +292,9 @@ we have to extract the count of named parentheses from the pattern. */ PCRE2_INFO_NAMECOUNT, /* get the number of named substrings */ &namecount); /* where to put the answer */ -if (namecount == 0) printf("No named substrings\en"); else +if (namecount == 0) + printf("No named substrings\en"); +else { PCRE2_SPTR tabptr; printf("Named substrings\en"); @@ -327,28 +332,8 @@ if (namecount == 0) printf("No named substrings\en"); else * to search for additional matches in the subject string, in a similar * * way to the /g option in Perl. This turns out to be trickier than you * * might think because of the possibility of matching an empty string. * -* What happens is as follows: * * * -* If the previous match was NOT for an empty string, we can just start * -* the next match at the end of the previous one. * -* * -* If the previous match WAS for an empty string, we can't do that, as it * -* would lead to an infinite loop. Instead, a call of pcre2_match() is * -* made with the PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set. The * -* first of these tells PCRE2 that an empty string at the start of the * -* subject is not a valid match; other possibilities must be tried. The * -* second flag restricts PCRE2 to one match attempt at the initial string * -* position. If this match succeeds, an alternative to the empty string * -* match has been found, and we can print it and proceed round the loop, * -* advancing by the length of whatever was found. If this match does not * -* succeed, we still stay in the loop, advancing by just one character. * -* In UTF-8 mode, which can be set by (*UTF) in the pattern, this may be * -* more than one byte. * -* * -* However, there is a complication concerned with newlines. When the * -* newline convention is such that CRLF is a valid newline, we must * -* advance by two characters rather than one. The newline convention can * -* be set in the regex by (*CR), etc.; if not, we must find the default. * +* To help with this task, PCRE2 provides the pcre2_next_match() helper. * *************************************************************************/ if (!find_all) /* Check for -g */ @@ -358,60 +343,21 @@ if (!find_all) /* Check for -g */ return 0; /* Exit the program. */ } -/* Before running the loop, check for UTF-8 and whether CRLF is a valid newline -sequence. First, find the options with which the regex was compiled and extract -the UTF state. */ - -(void)pcre2_pattern_info(re, PCRE2_INFO_ALLOPTIONS, &option_bits); -utf8 = (option_bits & PCRE2_UTF) != 0; - -/* Now find the newline convention and see whether CRLF is a valid newline -sequence. */ - -(void)pcre2_pattern_info(re, PCRE2_INFO_NEWLINE, &newline); -crlf_is_newline = newline == PCRE2_NEWLINE_ANY || - newline == PCRE2_NEWLINE_CRLF || - newline == PCRE2_NEWLINE_ANYCRLF; - /* Loop for second and subsequent matches */ +ovector_last[0] = ovector[0]; +ovector_last[1] = ovector[1]; + for (;;) { - uint32_t options = 0; /* Normally no options */ - PCRE2_SIZE start_offset = ovector[1]; /* Start at end of previous match */ + PCRE2_SIZE start_offset; + uint32_t options; - /* 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. */ + /* After each successful match, we use pcre2_next_match() to obtain the match + parameters for subsequent match attempts. */ - if (ovector[0] == ovector[1]) - { - if (ovector[0] == subject_length) break; - options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED; - } - - /* If the previous match was not an empty string, there is one tricky case to - consider. If a pattern contains \eK within a lookbehind assertion at the - start, the end of the matched string can be at the offset where the match - started. Without special action, this leads to a loop that keeps on matching - the same substring. We must detect this case and arrange to move the start on - by one character. The pcre2_get_startchar() function returns the starting - offset that was passed to pcre2_match(). */ - - else - { - PCRE2_SIZE startchar = pcre2_get_startchar(match_data); - if (start_offset <= startchar) - { - if (startchar >= subject_length) break; /* Reached end of subject. */ - start_offset = startchar + 1; /* Advance by one character. */ - if (utf8) /* If UTF-8, it may be more */ - { /* than one code unit. */ - for (; start_offset < subject_length; start_offset++) - if ((subject[start_offset] & 0xc0) != 0x80) break; - } - } - } + if (!pcre2_next_match(match_data, &start_offset, &options)) + break; /* Run the next matching operation */ @@ -424,38 +370,10 @@ for (;;) match_data, /* block for storing the result */ NULL); /* use default match context */ - /* This time, a result of NOMATCH isn't an error. If the value in "options" - is zero, it just means we have found all possible matches, so the loop ends. - Otherwise, it means we have failed to find a non-empty-string match at a - point where there was a previous empty-string match. In this case, we do what - Perl does: advance the matching position by one character, and continue. We - do this by setting the "end of previous match" offset, because that is picked - up at the top of the loop as the point at which to start again. - - There are two complications: (a) When CRLF is a valid newline sequence, and - the current position is just before it, advance by an extra byte. (b) - Otherwise we must ensure that we skip an entire UTF character if we are in - UTF mode. */ + /* If this match attempt fails, exit the loop for subsequent matches. */ if (rc == PCRE2_ERROR_NOMATCH) - { - if (options == 0) break; /* All matches found */ - ovector[1] = start_offset + 1; /* Advance one code unit */ - if (crlf_is_newline && /* If CRLF is a newline & */ - start_offset < subject_length - 1 && /* we are at CRLF, */ - subject[start_offset] == '\er' && - subject[start_offset + 1] == '\en') - ovector[1] += 1; /* Advance by one more. */ - else if (utf8) /* Otherwise, ensure we */ - { /* advance a whole UTF-8 */ - while (ovector[1] < subject_length) /* character. */ - { - if ((subject[ovector[1]] & 0xc0) != 0x80) break; - ovector[1] += 1; - } - } - continue; /* Go round the loop again */ - } + break; /* Other matching errors are not recoverable. */ @@ -467,7 +385,33 @@ for (;;) return 1; } - /* Match succeeded */ + /* This demonstration program depends on pcre2_next_match() to ensure that the + loop for second and subsequent matches does not run forever. However, it would + be robust practice for a production application to verify this. The following + block of code shows how to do this. This error case is not reachable unless + there is a bug in PCRE2. + + Because this program does not set the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option, + the logic is simple. We verify that either ovector[1] has advanced, or that we + have an empty match touching the end of a previous non-empty match. See the + API documentation for guidance if your application uses + PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK and searches for multiple matches. */ + + if (!(ovector[1] > ovector_last[1] || + (ovector[1] == ovector[0] && ovector_last[1] > ovector_last[0] && + ovector[1] == ovector_last[1]))) + { + printf("\e\eK was used in an assertion to yield non-advancing matches.\en"); + printf("Run abandoned\en"); + pcre2_match_data_free(match_data); + pcre2_code_free(re); + return 1; + } + + ovector_last[0] = ovector[0]; + ovector_last[1] = ovector[1]; + + /* Match succeeded. */ printf("\enMatch succeeded again at offset %d\en", (int)ovector[0]); @@ -477,9 +421,11 @@ for (;;) if (rc == 0) printf("ovector was not big enough for all the captured substrings\en"); - /* We must guard against patterns such as /(?=.\eK)/ that use \eK in an - assertion to set the start of a match later than its end. In this - demonstration program, we just detect this case and give up. */ + /* We guard against patterns such as /(?=.\eK)/ that use \eK in an assertion to + set the start of a match later than its end. As explained above, this case + should not occur because this demonstration program does not set the + PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option, however, we do include code showing + how to detect it. */ if (ovector[0] > ovector[1]) { @@ -502,7 +448,9 @@ for (;;) printf("%2d: %.*s\en", i, (int)substring_length, (char *)substring_start); } - if (namecount == 0) printf("No named substrings\en"); else + if (namecount == 0) + printf("No named substrings\en"); + else { PCRE2_SPTR tabptr = name_table; printf("Named substrings\en"); @@ -517,6 +465,7 @@ for (;;) } /* End of loop to find second and subsequent matches */ printf("\en"); + pcre2_match_data_free(match_data); pcre2_code_free(re); return 0; diff --git a/doc/pcre2grep.1 b/doc/pcre2grep.1 index 95872f1..559d923 100644 --- a/doc/pcre2grep.1 +++ b/doc/pcre2grep.1 @@ -1,4 +1,4 @@ -.TH PCRE2GREP 1 "04 February 2025" "PCRE2 10.46" +.TH PCRE2GREP 1 "24 January 2025" "PCRE2 10.47" .SH NAME pcre2grep - a grep with Perl-compatible regular expressions. .SH SYNOPSIS @@ -1022,6 +1022,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 04 February 2025 +Last updated: 24 January 2025 Copyright (c) 1997-2023 University of Cambridge. .fi diff --git a/doc/pcre2grep.txt b/doc/pcre2grep.txt index dd1a38e..55e362a 100644 --- a/doc/pcre2grep.txt +++ b/doc/pcre2grep.txt @@ -1099,8 +1099,8 @@ AUTHOR REVISION - Last updated: 04 February 2025 + Last updated: 24 January 2025 Copyright (c) 1997-2023 University of Cambridge. -PCRE2 10.46 04 February 2025 PCRE2GREP(1) +PCRE2 10.47 24 January 2025 PCRE2GREP(1) diff --git a/doc/pcre2jit.3 b/doc/pcre2jit.3 index 009a5ff..620b40c 100644 --- a/doc/pcre2jit.3 +++ b/doc/pcre2jit.3 @@ -1,4 +1,4 @@ -.TH PCRE2JIT 3 "22 August 2024" "PCRE2 10.46" +.TH PCRE2JIT 3 "22 August 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "PCRE2 JUST-IN-TIME COMPILER SUPPORT" diff --git a/doc/pcre2limits.3 b/doc/pcre2limits.3 index f51a7a8..b5122ed 100644 --- a/doc/pcre2limits.3 +++ b/doc/pcre2limits.3 @@ -1,4 +1,4 @@ -.TH PCRE2LIMITS 3 "16 August 2023" "PCRE2 10.46" +.TH PCRE2LIMITS 3 "03 September 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "SIZE AND OTHER LIMITATIONS" @@ -47,8 +47,13 @@ when PCRE2 is built; if not, the default is set to 250. An application can change this limit by calling pcre2_set_parens_nest_limit() to set the limit in a compile context. .P -The maximum length of name for a named capture group is 32 code units, and the -maximum number of such groups is 10000. +The maximum length of the name for a named capture group as well as the number +of such groups is configurable at build time. The maximum length for the name +defaults to +.\" DEFINE MAX_NAME_SIZE +128 code units, and the maximum number of such groups to +.\" DEFINE MAX_NAME_COUNT +10000. .P The maximum length of a name in a (*MARK), (*PRUNE), (*SKIP), or (*THEN) verb is 255 code units for the 8-bit library and 65535 code units for the 16-bit and @@ -76,6 +81,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 16 August 2023 +Last updated: 03 September 2025 Copyright (c) 1997-2023 University of Cambridge. .fi diff --git a/doc/pcre2matching.3 b/doc/pcre2matching.3 index 18ee75a..f84b071 100644 --- a/doc/pcre2matching.3 +++ b/doc/pcre2matching.3 @@ -1,4 +1,4 @@ -.TH PCRE2MATCHING 3 "30 August 2024" "PCRE2 10.46" +.TH PCRE2MATCHING 3 "22 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "PCRE2 MATCHING ALGORITHMS" @@ -7,7 +7,7 @@ PCRE2 - Perl-compatible regular expressions (revised API) This document describes the two different algorithms that are available in PCRE2 for matching a compiled regular expression against a given subject string. The "standard" algorithm is the one provided by the \fBpcre2_match()\fP -function. This works in the same as Perl's matching function, and provides a +function. This works in the same way as Perl's matching function, and provides a Perl-compatible matching operation. The just-in-time (JIT) optimization that is described in the .\" HREF @@ -223,6 +223,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 30 August 2024 +Last updated: 22 February 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2partial.3 b/doc/pcre2partial.3 index 0674f71..42a5c36 100644 --- a/doc/pcre2partial.3 +++ b/doc/pcre2partial.3 @@ -1,4 +1,4 @@ -.TH PCRE2PARTIAL 3 "27 November 2024" "PCRE2 10.46" +.TH PCRE2PARTIAL 3 "27 November 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "PARTIAL MATCHING IN PCRE2" diff --git a/doc/pcre2pattern.3 b/doc/pcre2pattern.3 index 242ba7a..0ad38db 100644 --- a/doc/pcre2pattern.3 +++ b/doc/pcre2pattern.3 @@ -1,4 +1,4 @@ -.TH PCRE2PATTERN 3 "27 November 2024" "PCRE2 10.46" +.TH PCRE2PATTERN 3 "03 September 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "PCRE2 REGULAR EXPRESSION DETAILS" @@ -150,10 +150,11 @@ documentation. .rs .sp If a pattern starts with (*NO_DOTSTAR_ANCHOR), it has the same effect as -setting the PCRE2_NO_DOTSTAR_ANCHOR option, or calling \fBpcre2_set_optimize()\fP -with a PCRE2_DOTSTAR_ANCHOR_OFF directive. This disables optimizations that -apply to patterns whose top-level branches all start with .* (match any number -of arbitrary characters). For more details, see the +setting the PCRE2_NO_DOTSTAR_ANCHOR option, or +calling \fBpcre2_set_optimize()\fP with a PCRE2_DOTSTAR_ANCHOR_OFF directive. +This disables optimizations that apply to patterns whose top-level branches +all start with .* (match any number of arbitrary characters). For more details, +see the .\" HREF \fBpcre2api\fP .\" @@ -1360,7 +1361,7 @@ it matches any character except one that signifies the end of a line. .P When \eN is followed by an opening brace it has a different meaning. See the section entitled -.\" HTML +.\" HTML .\" "Non-printing characters" .\" @@ -2015,8 +2016,9 @@ the naming of capture groups. This feature was not added to Perl until release using the Python syntax. PCRE2 supports both the Perl and the Python syntax. .P In PCRE2, a capture group can be named in one of three ways: (?...) or -(?'name'...) as in Perl, or (?P...) as in Python. Names may be up to 128 -code units long. When PCRE2_UTF is not set, they may contain only ASCII +(?'name'...) as in Perl, or (?P...) as in Python. Names may be up to +.\" DEFINE MAX_NAME_SIZE +128 code units long. When PCRE2_UTF is not set, they may contain only ASCII alphanumeric characters and underscores, but must start with a non-digit. When PCRE2_UTF is set, the syntax of group names is extended to allow any Unicode letter or Unicode decimal digit. In other words, group names must match one of @@ -3184,8 +3186,7 @@ For example: (?(VERSION>=10.4)yes|no) .sp This pattern matches "yes" if the PCRE2 version is greater or equal to 10.4, or -"no" otherwise. The fractional part of the version number may not contain more -than two digits. +"no" otherwise. The fractional part of the version number could be ommited. . . .SS "Assertion conditions" @@ -3442,7 +3443,7 @@ later versions (I tried 5.024) it now works. . . .\" HTML -.SH "GROUPS AS SUBROUTINES" +.SS "Groups as subroutines" .rs .sp If the syntax for a recursive group call (either by number or by name) is used @@ -3495,8 +3496,51 @@ in groups when called as subroutines is described in the section entitled below. . . +.SS "Recursion and subroutines with returned capture groups" +.rs +.sp +Since PCRE2 10.46, recursion and subroutine calls may also specify a list of +capture groups to return. This is a PCRE2 syntax extension not supported by +Perl. The pattern matching recurses into the referenced expression as described +above, however, when the recursion returns to the calling expression the +subgroups captured during the recursion can be retained when the calling +expression's context is restored. +.P +When used as a subroutine, this allows the subroutine's capture groups to +be used as return values. +.P +Only the specific capture groups listed by the caller will be retained, using +the following syntax: +.sp + (?R(grouplist)) recurse whole pattern, returning capture groups + (?n(grouplist)) ) + (?+n(grouplist)) ) + (?-n(grouplist)) ) call subroutine, returning capture groups + (?&name(grouplist)) ) + (?P>name(grouplist)) ) +.P +The list of capture groups "grouplist" is a comma-separated list of (absolute +or relative) group numbers, and group names enclosed in single quotes or angle +brackets. +.P +Here is an example which first uses the DEFINE condition to create a re-usable +routine for matching a weekday, then calls that subroutine and retains the +groups it captures for use later: +.sp + (?x: # ignore whitespace for clarity + # Define the routine "weekendday" which matches Saturday or + # Sunday, and returns the Sat/Sun prefix as \ek. + (?(DEFINE) (? + (?|(?Sat)urday|(?Sun)day) ) ) + # Call the routine. Matches "Saturday,Sat" or "Sunday,Sun". + (?&weekendday()),\ek ) +.P +This feature is not available using the Oniguruma syntax \eg<...> or \eg'...' +below. +. +. .\" HTML -.SH "ONIGURUMA SUBROUTINE SYNTAX" +.SS "Oniguruma subroutine syntax" .rs .sp For compatibility with Oniguruma, the non-Perl syntax \eg followed by a name or @@ -3618,7 +3662,7 @@ are faulted. .P A closing parenthesis can be included in a name either as \e) or between \eQ and \eE. In addition to backslash processing, if the PCRE2_EXTENDED or -PCRE2_EXTENDED_MORE option is also set, unescaped whitespace in verb names is +PCRE2_EXTENDED_MORE option is also set, unescaped white space in verb names is skipped, and #-comments are recognized, exactly as in the rest of the pattern. PCRE2_EXTENDED and PCRE2_EXTENDED_MORE do not affect verb names unless PCRE2_ALT_VERBNAMES is also set. @@ -4186,6 +4230,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 27 November 2024 +Last updated: 03 September 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2perform.3 b/doc/pcre2perform.3 index 2d3e33b..f419559 100644 --- a/doc/pcre2perform.3 +++ b/doc/pcre2perform.3 @@ -1,4 +1,4 @@ -.TH PCRE2PERFORM 3 "06 December 2022" "PCRE2 10.46" +.TH PCRE2PERFORM 3 "06 December 2022" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "PCRE2 PERFORMANCE" diff --git a/doc/pcre2posix.3 b/doc/pcre2posix.3 index 4eceda1..359f017 100644 --- a/doc/pcre2posix.3 +++ b/doc/pcre2posix.3 @@ -1,4 +1,4 @@ -.TH PCRE2POSIX 3 "27 November 2024" "PCRE2 10.46" +.TH PCRE2POSIX 3 "27 November 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "SYNOPSIS" diff --git a/doc/pcre2sample.3 b/doc/pcre2sample.3 index a55b795..505c3a7 100644 --- a/doc/pcre2sample.3 +++ b/doc/pcre2sample.3 @@ -1,4 +1,4 @@ -.TH PCRE2SAMPLE 3 "14 November 2023" "PCRE2 10.46" +.TH PCRE2SAMPLE 3 "28 February 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "PCRE2 SAMPLE PROGRAM" @@ -11,7 +11,7 @@ distribution. A listing of this program is given in the \fBpcre2demo\fP .\" documentation. If you do not have a copy of the PCRE2 distribution, you can -save this listing to re-create the contents of \fIpcre2demo.c\fP. +save this listing to recreate the contents of \fIpcre2demo.c\fP. .P The demonstration program compiles the regular expression that is its first argument, and matches it against the subject string in its second @@ -50,6 +50,7 @@ this: .sp ./pcre2demo 'cat|dog' 'the cat sat on the mat' ./pcre2demo -g 'cat|dog' 'the dog sat on the cat' + ./pcre2demo -i 'cat' 'the dog sat on the CAT' .sp Note that there is a much more comprehensive test program, called .\" HREF @@ -94,6 +95,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 14 November 2023 +Last updated: 28 February 2025 Copyright (c) 1997-2016 University of Cambridge. .fi diff --git a/doc/pcre2serialize.3 b/doc/pcre2serialize.3 index 4de8e30..15aa8fa 100644 --- a/doc/pcre2serialize.3 +++ b/doc/pcre2serialize.3 @@ -1,4 +1,4 @@ -.TH PCRE2SERIALIZE 3 "19 January 2024" "PCRE2 10.46" +.TH PCRE2SERIALIZE 3 "19 January 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "SAVING AND RE-USING PRECOMPILED PCRE2 PATTERNS" diff --git a/doc/pcre2syntax.3 b/doc/pcre2syntax.3 index 0fb37d9..d1a611b 100644 --- a/doc/pcre2syntax.3 +++ b/doc/pcre2syntax.3 @@ -1,4 +1,4 @@ -.TH PCRE2SYNTAX 3 "27 November 2024" "PCRE2 10.46" +.TH PCRE2SYNTAX 3 "14 October 2025" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "PCRE2 REGULAR EXPRESSION SYNTAX SUMMARY" @@ -303,7 +303,7 @@ used, allowing nested character classes, combined using set operators. .rs .sp (?[...]) Perl extended character class - (?[\ep{Thai} & \ep{Nd}]) operators; whitespace ignored + (?[\ep{Thai} & \ep{Nd}]) operators; white space ignored (?[(x - y) & z]) parentheses for grouping .sp (?[ [^3] & \ep{Nd} ]) [...] is a nested ordinary class @@ -543,14 +543,14 @@ This feature is not Perl-compatible. (*scan_substring:(grouplist)...) scan captured substring (*scs:(grouplist)...) scan captured substring .sp -The comma-separated list may identify groups in any of the following ways: +The comma-separated list "grouplist" may identify groups in any of the +following ways: .sp n absolute reference +n relative reference -n relative reference name 'name' name -.sp . . .SH "SCRIPT RUNS" @@ -597,6 +597,28 @@ The comma-separated list may identify groups in any of the following ways: \eg'+n' call subroutine by relative number (PCRE2 extension) \eg<-n> call subroutine by relative number (PCRE2 extension) \eg'-n' call subroutine by relative number (PCRE2 extension) +.sp +The variants using parentheses (?...) may also specify a list of capture groups +to return, which shall be retained in the calling subexpression if set during +the recursion (this feature is not supported by Perl). +.sp + (?R(grouplist)) recurse whole pattern, returning capture groups + (PCRE2 extension) + (?n(grouplist)) ) + (?+n(grouplist)) ) call subroutine, returning capture groups + (?-n(grouplist)) ) (PCRE2 extension) + (?&name(grouplist)) ) + (?P>name(grouplist)) ) +.sp +The comma-separated list "grouplist" uses the same syntax as +(*scan_substring:(grouplist)...), and may identify groups in any of the +following ways: +.sp + n absolute reference + +n relative reference + -n relative reference + name + 'name' name . . .SH "CONDITIONAL PATTERNS" @@ -605,22 +627,25 @@ The comma-separated list may identify groups in any of the following ways: (?(condition)yes-pattern) (?(condition)yes-pattern|no-pattern) .sp - (?(n) absolute reference condition - (?(+n) relative reference condition (PCRE2 extension) - (?(-n) relative reference condition (PCRE2 extension) - (?() named reference condition (Perl) - (?('name') named reference condition (Perl) - (?(name) named reference condition (PCRE2, deprecated) - (?(R) overall recursion condition - (?(Rn) specific numbered group recursion condition - (?(R&name) specific named group recursion condition - (?(DEFINE) define groups for reference - (?(VERSION[>]=n.m) test PCRE2 version - (?(assert) assertion condition + (?(n) absolute reference condition + (?(+n) relative reference condition (PCRE2 extension) + (?(-n) relative reference condition (PCRE2 extension) + (?() named reference condition (Perl) + (?('name') named reference condition (Perl) + (?(name) named reference condition (PCRE2, deprecated) + (?(R) overall recursion condition + (?(Rn) specific numbered group recursion condition + (?(R&name) specific named group recursion condition + (?(DEFINE) define groups for reference + (?(VERSION[>]=n[.m]) test PCRE2 version + (?(assert) assertion condition .sp Note the ambiguity of (?(R) and (?(Rn) which might be named reference conditions or recursion tests. Such a condition is interpreted as a reference condition if the relevant named group exists. +.sp +The parts within brackets for the VERSION conditional syntax could be ommited. +The fractional part of the version number defaults to 0 in that case. . . .SH "BACKTRACKING CONTROL" @@ -678,6 +703,7 @@ special character is the dollar character in one of the following forms: $` insert the substring that precedes the match $' insert the substring that follows the match $_ insert the entire input string + $+ insert the highest-numbered capture group which matched $*MARK or ${*MARK} insert a control verb name .sp For ${n}, n can be a name or a number. If PCRE2_SUBSTITUTE_EXTENDED is set, @@ -686,16 +712,16 @@ there is additional interpretation: 1. Backslash is an escape character, and the forms described in "ESCAPED CHARACTERS" above are recognized. Also: .sp - \eQ...\eE can be used to suppress interpretation - \el force the next character to lower case - \eu force the next character to upper case - \eL force subsequent characters to lower case - \eU force subsequent characters to upper case - \eu\eL force next character to upper case, then all lower - \el\eU force next character to lower case, then all upper - \eE end \eL or \eU case forcing - \eb backspace character (note: as in character class in pattern) - \ev vertical tab character (note: not the same as in a pattern) + \eQ...\eE can be used to suppress interpretation + \el force the next character to lower case + \eu force the next character to upper case + \eL force subsequent characters to lower case + \eU force subsequent characters to upper case + \eu\eL force next character to upper case, then all lower + \el\eU force next character to lower case, then all upper + \eE end \eL or \eU case forcing + \eb backspace character (note: as in character class in pattern) + \ev vertical tab character (note: not the same as in a pattern) .sp 2. The Python form \eg, where the angle brackets are part of the syntax and \fIn\fP is either a group name or a number, is recognized as an alternative way @@ -731,6 +757,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 27 November 2024 +Last updated: 14 October 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2test.1 b/doc/pcre2test.1 index a84b62a..7dbc731 100644 --- a/doc/pcre2test.1 +++ b/doc/pcre2test.1 @@ -1,4 +1,4 @@ -.TH PCRE2TEST 1 "26 December 2024" "PCRE2 10.46" +.TH PCRE2TEST 1 "12 October 2025" "PCRE2 10.47" .SH NAME pcre2test - a program for testing Perl-compatible regular expressions. .SH SYNOPSIS @@ -143,10 +143,6 @@ Output information about a specific build-time option, then exit. This functionality is intended for use in scripts such as \fBRunTest\fP. The following options output the value and set the exit code as indicated: .sp - ebcdic-nl the code for LF (= NL) in an EBCDIC environment: - either 0x15 or 0x25 - 0 if used in an ASCII/Unicode environment - exit code is always 0 linksize the configured internal link size (2, 3, or 4) exit code is set to the link size newline the default newline setting: @@ -161,6 +157,10 @@ to the same value: .sp backslash-C \eC is supported (not locked out) ebcdic compiled for an EBCDIC environment + ebcdic-io if PCRE2 is compiled for EBCDIC, whether pcre2test's input and + output is EBCDIC or ASCII + ebcdic-nl25 if PCRE2 is compiled for EBCDIC, whether NL (= LF) is 0x25 + (otherwise it is 0x15, the default) jit just-in-time support is available pcre2-16 the 16-bit library was built pcre2-32 the 32-bit library was built @@ -179,6 +179,11 @@ information. It returns one of the following values: .sp If an unknown option is given, an error message is output; the exit code is 0. .TP 10 +\fB--colo[u]r[=]\fP +By default, the output is coloured if the output file is a terminal (\fBauto\fP). +Force or suppress output of ANSI colour escapes with \fBalways\fP and \fBnever\fP +respectively. +.TP 10 \fB-d\fP Behave as if each pattern has the \fBdebug\fP modifier; the internal form and information about the compiled pattern is output after compilation; @@ -189,6 +194,10 @@ Behave as if each subject line has the \fBdfa\fP modifier; matching is done using the \fBpcre2_dfa_match()\fP function instead of the default \fBpcre2_match()\fP. .TP 10 +\fB-E\fP +Run in "preprocess only" mode (similar to "gcc -E"). The "#if ... #endif" +commands are processed, and all other lines are printed verbatim. +.TP 10 \fB-error\fP \fInumber[,number,...]\fP Call \fBpcre2_get_error_message()\fP for each of the error numbers in the comma-separated list, display the resulting messages on the standard output, @@ -232,6 +241,11 @@ List scripts: write a list of recognized Unicode script names to the standard output, then exit with zero exit code. All other options are ignored. If both -C and any -Lx options are present, whichever is first is recognized. .TP 10 +\fB-malloc\fP +Exercise malloc() failures, by first counting the number of calls made to malloc +during pattern compilation and matching, then re-running the compilation and +matching that many times, exercising a failure of each malloc() call. +.TP 10 \fB-pattern\fP \fImodifier-list\fP Behave as if each pattern line contains the given modifiers. .TP 10 @@ -261,6 +275,10 @@ compile phase. These behave like \fB-t\fP and \fB-tm\fP, but in addition, at the end of a run, the total times for all compiles and matches are output. .TP 10 +\fB-unittest\fP +Run a fixed set of additional tests of the PCRE2 API which are not driven by +the test input files, and then exit. +.TP 10 \fB-version\fP Output the PCRE2 version number and then exit. . @@ -420,13 +438,24 @@ below. .sp This command sets a default modifier list that applies to all subsequent subject lines. Modifiers on a subject line can change these settings. +.sp + #if CONDITION + ... + #endif +.sp +If CONDITION is true, then the command is printed, and its contents are +processed as normal, including printing the commandlines to the output. If +CONDITION is false, then all lines between the "#if" and "#endif" are skipped +and not printed. The CONDITION can be any of the conditions which are tested by +the "-C" commandline option and which set pcre2test's exit code to a boolean +value. The CONDITION may also be preceded by "!". . . .SH "MODIFIER SYNTAX" .rs .sp Modifier lists are used with both pattern and subject lines. Items in a list -are separated by commas followed by optional white space. Trailing whitespace +are separated by commas followed by optional white space. Trailing white space in a modifier list is ignored. Some modifiers may be given for both patterns and subject lines, whereas others are valid only for one or the other. Each modifier has a long name, for example "anchored", and some of them must be @@ -550,7 +579,7 @@ the start of a modifier list. For example: .sp abc\e=notbol,notempty .sp -If the subject string is empty and \e= is followed by whitespace, the line is +If the subject string is empty and \e= is followed by white space, the line is treated as a comment line, and is not used for matching. For example: .sp \e= This is a comment. @@ -1126,7 +1155,8 @@ process. heapframes_size show match data heapframes size jitstack= set size of JIT stack mark show mark values - replace= specify a replacement string + null_substitute_match_data substitute with NULL match data + replace= specify a replacement string startchar show starting character when relevant substitute_callout use substitution callouts substitute_case_callout use substitution case callouts @@ -1308,11 +1338,12 @@ pattern, but can be overridden by modifiers on the subject. null_context match with a NULL context null_replacement substitute with NULL replacement null_subject match with NULL subject + null_substitute_match_data substitute with NULL match data offset= set starting offset offset_limit= set offset limit ovector= set size of output vector recursion_limit= obsolete synonym for depth_limit - replace= specify a replacement string + replace= specify a replacement string startchar show startchar when relevant startoffset= same as offset= substitute_callout use substitution callouts @@ -1324,6 +1355,7 @@ pattern, but can be overridden by modifiers on the subject. substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY substitute_skip= skip substitution number n substitute_stop= skip substitution number n and greater + substitute_subject= specify a different subject for substitution substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY zero_terminate pass the subject as zero-terminated @@ -1446,13 +1478,9 @@ difference to the matching process if the pattern begins with a lookbehind assertion (including \eb or \eB). .P If an empty string is matched, the next match is done with the -PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set, in order to search for -another, non-empty, match at the same point in the subject. If this match -fails, the start offset is advanced, and the normal match is retried. This -imitates the way Perl handles such cases when using the \fB/g\fP modifier or -the \fBsplit()\fP function. Normally, the start offset is advanced by one -character, but if the newline convention recognizes CRLF as a newline, and the -current character is CR followed by LF, an advance of two characters occurs. +PCRE2_NOTEMPTY_ATSTART flag set, in order to search for another, non-empty, +match at the same point in the subject. This imitates the way Perl handles such +cases when using the \fB/g\fP modifier or the \fBsplit()\fP function. . . .SS "Testing substring extraction functions" @@ -1540,7 +1568,7 @@ character. Here is an example that tests the edge case: 123abc123\e=replace=[10]XYZ 1: 123XYZ123 123abc123\e=replace=[9]XYZ - Failed: error -47: no more memory + Failed: error -48: no more memory .sp The default action of \fBpcre2_substitute()\fP is to return PCRE2_ERROR_NOMEMORY when the output buffer is too small. However, if the @@ -1553,11 +1581,17 @@ for the trailing zero) as part of the error message. For example: .sp /abc/substitute_overflow_length 123abc123\e=replace=[9]XYZ - Failed: error -47: no more memory: 10 code units are needed + Failed: error -48: no more memory: 10 code units are needed .sp A replacement string is ignored with POSIX and DFA matching. Specifying partial matching provokes an error return ("bad option value") from \fBpcre2_substitute()\fP. +.sp +The \fBsubstitute_subject\fP modifier may be used to test the use of the PCRE2 +API, in which a client calls \fBpcre2_match()\fP followed by \fBpcre2_substitute()\fP +with PCRE2_SUBSTITUTE_MATCHED, but the client performs an unexpected and +unsupported modification of the subject buffer in-place, in between the match +and substitution. . . .SS "Testing substitute callouts" @@ -2241,6 +2275,6 @@ Cambridge, England. .rs .sp .nf -Last updated: 26 December 2024 +Last updated: 12 October 2025 Copyright (c) 1997-2024 University of Cambridge. .fi diff --git a/doc/pcre2test.txt b/doc/pcre2test.txt index 5df8c71..b868b91 100644 --- a/doc/pcre2test.txt +++ b/doc/pcre2test.txt @@ -132,10 +132,6 @@ COMMAND LINE OPTIONS as RunTest. The following options output the value and set the exit code as indicated: - ebcdic-nl the code for LF (= NL) in an EBCDIC environment: - either 0x15 or 0x25 - 0 if used in an ASCII/Unicode environment - exit code is always 0 linksize the configured internal link size (2, 3, or 4) exit code is set to the link size newline the default newline setting: @@ -150,6 +146,12 @@ COMMAND LINE OPTIONS backslash-C \C is supported (not locked out) ebcdic compiled for an EBCDIC environment + ebcdic-io if PCRE2 is compiled for EBCDIC, whether + pcre2test's input and + output is EBCDIC or ASCII + ebcdic-nl25 if PCRE2 is compiled for EBCDIC, whether NL (= + LF) is 0x25 + (otherwise it is 0x15, the default) jit just-in-time support is available pcre2-16 the 16-bit library was built pcre2-32 the 32-bit library was built @@ -157,9 +159,9 @@ COMMAND LINE OPTIONS unicode Unicode support is available Note that the availability of JIT support in the library does - not guarantee that it can actually be used because in some - environments it is unable to allocate executable memory. The - option "jitusable" gives more detailed information. It re- + not guarantee that it can actually be used because in some + environments it is unable to allocate executable memory. The + option "jitusable" gives more detailed information. It re- turns one of the following values: 0 JIT is available and usable @@ -167,9 +169,14 @@ COMMAND LINE OPTIONS 2 JIT is not available 3 Unexpected return from test call to pcre2_jit_compile() - If an unknown option is given, an error message is output; + If an unknown option is given, an error message is output; the exit code is 0. + --colo[u]r[=] + By default, the output is coloured if the output file is a + terminal (auto). Force or suppress output of ANSI colour es- + capes with always and never respectively. + -d Behave as if each pattern has the debug modifier; the inter- nal form and information about the compiled pattern is output after compilation; -d is equivalent to -b -i. @@ -178,48 +185,57 @@ COMMAND LINE OPTIONS is done using the pcre2_dfa_match() function instead of the default pcre2_match(). + -E Run in "preprocess only" mode (similar to "gcc -E"). The "#if + ... #endif" commands are processed, and all other lines are + printed verbatim. + -error number[,number,...] - Call pcre2_get_error_message() for each of the error numbers - in the comma-separated list, display the resulting messages - on the standard output, then exit with zero exit code. The - numbers may be positive or negative. This is a convenience + Call pcre2_get_error_message() for each of the error numbers + in the comma-separated list, display the resulting messages + on the standard output, then exit with zero exit code. The + numbers may be positive or negative. This is a convenience facility for PCRE2 maintainers. -help Output a brief summary these options and then exit. - -i Behave as if each pattern has the info modifier; information + -i Behave as if each pattern has the info modifier; information about the compiled pattern is given after compilation. - -jit Behave as if each pattern line has the jit modifier; after - successful compilation, each pattern is passed to the just- + -jit Behave as if each pattern line has the jit modifier; after + successful compilation, each pattern is passed to the just- in-time compiler, if available. - -jitfast Behave as if each pattern line has the jitfast modifier; af- - ter successful compilation, each pattern is passed to the + -jitfast Behave as if each pattern line has the jitfast modifier; af- + ter successful compilation, each pattern is passed to the just-in-time compiler, if available, and each subject line is passed directly to the JIT matcher via its "fast path". -jitverify - Behave as if each pattern line has the jitverify modifier; - after successful compilation, each pattern is passed to the - just-in-time compiler, if available, and the use of JIT for + Behave as if each pattern line has the jitverify modifier; + after successful compilation, each pattern is passed to the + just-in-time compiler, if available, and the use of JIT for matching is verified. -LM List modifiers: write a list of available pattern and subject - modifiers to the standard output, then exit with zero exit - code. All other options are ignored. If both -C and any -Lx + modifiers to the standard output, then exit with zero exit + code. All other options are ignored. If both -C and any -Lx options are present, whichever is first is recognized. - -LP List properties: write a list of recognized Unicode proper- - ties to the standard output, then exit with zero exit code. + -LP List properties: write a list of recognized Unicode proper- + ties to the standard output, then exit with zero exit code. All other options are ignored. If both -C and any -Lx options are present, whichever is first is recognized. -LS List scripts: write a list of recognized Unicode script names - to the standard output, then exit with zero exit code. All + to the standard output, then exit with zero exit code. All other options are ignored. If both -C and any -Lx options are present, whichever is first is recognized. + -malloc Exercise malloc() failures, by first counting the number of + calls made to malloc during pattern compilation and matching, + then re-running the compilation and matching that many times, + exercising a failure of each malloc() call. + -pattern modifier-list Behave as if each pattern line contains the given modifiers. @@ -247,166 +263,181 @@ COMMAND LINE OPTIONS a run, the total times for all compiles and matches are out- put. + -unittest Run a fixed set of additional tests of the PCRE2 API which + are not driven by the test input files, and then exit. + -version Output the PCRE2 version number and then exit. DESCRIPTION - If pcre2test is given two filename arguments, it reads from the first + If pcre2test is given two filename arguments, it reads from the first and writes to the second. If the first name is "-", input is taken from - the standard input. If pcre2test is given only one argument, it reads + the standard input. If pcre2test is given only one argument, it reads from that file and writes to stdout. Otherwise, it reads from stdin and writes to stdout. - When pcre2test is built, a configuration option can specify that it - should be linked with the libreadline or libedit library. When this is - done, if the input is from a terminal, it is read using the readline() + When pcre2test is built, a configuration option can specify that it + should be linked with the libreadline or libedit library. When this is + done, if the input is from a terminal, it is read using the readline() function. This provides line-editing and history facilities. The output from the -help option states whether or not readline() will be used. - The program handles any number of tests, each of which consists of a - set of input lines. Each set starts with a regular expression pattern, + The program handles any number of tests, each of which consists of a + set of input lines. Each set starts with a regular expression pattern, followed by any number of subject lines to be matched against that pat- tern. In between sets of test data, command lines that begin with # may appear. This file format, with some restrictions, can also be processed - by the perltest.sh script that is distributed with PCRE2 as a means of + by the perltest.sh script that is distributed with PCRE2 as a means of checking that the behaviour of PCRE2 and Perl is the same. For a speci- - fication of perltest.sh, see the comments near its beginning. See also + fication of perltest.sh, see the comments near its beginning. See also the #perltest command below. When the input is a terminal, pcre2test prompts for each line of input, - using "re>" to prompt for regular expression patterns, and "data>" to - prompt for subject lines. Command lines starting with # can be entered + using "re>" to prompt for regular expression patterns, and "data>" to + prompt for subject lines. Command lines starting with # can be entered only in response to the "re>" prompt. - Each subject line is matched separately and independently. If you want + Each subject line is matched separately and independently. If you want to do multi-line matches, you have to use the \n escape sequence (or \r - or \r\n, etc., depending on the newline setting) in a single line of - input to encode the newline sequences. There is no limit on the length - of subject lines; the input buffer is automatically extended if it is - too small. There are replication features that makes it possible to - generate long repetitive pattern or subject lines without having to + or \r\n, etc., depending on the newline setting) in a single line of + input to encode the newline sequences. There is no limit on the length + of subject lines; the input buffer is automatically extended if it is + too small. There are replication features that makes it possible to + generate long repetitive pattern or subject lines without having to supply them explicitly. - An empty line or the end of the file signals the end of the subject - lines for a test, at which point a new pattern or command line is ex- + An empty line or the end of the file signals the end of the subject + lines for a test, at which point a new pattern or command line is ex- pected if there is still input to be read. COMMAND LINES - In between sets of test data, a line that begins with # is interpreted + In between sets of test data, a line that begins with # is interpreted as a command line. If the first character is followed by white space or - an exclamation mark, the line is treated as a comment, and ignored. + an exclamation mark, the line is treated as a comment, and ignored. Otherwise, the following commands are recognized: #forbid_utf - Subsequent patterns automatically have the PCRE2_NEVER_UTF and - PCRE2_NEVER_UCP options set, which locks out the use of the PCRE2_UTF - and PCRE2_UCP options and the use of (*UTF) and (*UCP) at the start of - patterns. This command also forces an error if a subsequent pattern - contains any occurrences of \P, \p, or \X, which are still supported - when PCRE2_UTF is not set, but which require Unicode property support + Subsequent patterns automatically have the PCRE2_NEVER_UTF and + PCRE2_NEVER_UCP options set, which locks out the use of the PCRE2_UTF + and PCRE2_UCP options and the use of (*UTF) and (*UCP) at the start of + patterns. This command also forces an error if a subsequent pattern + contains any occurrences of \P, \p, or \X, which are still supported + when PCRE2_UTF is not set, but which require Unicode property support to be included in the library. - This is a trigger guard that is used in test files to ensure that UTF - or Unicode property tests are not accidentally added to files that are - used when Unicode support is not included in the library. Setting - PCRE2_NEVER_UTF and PCRE2_NEVER_UCP as a default can also be obtained - by the use of #pattern; the difference is that #forbid_utf cannot be - unset, and the automatic options are not displayed in pattern informa- + This is a trigger guard that is used in test files to ensure that UTF + or Unicode property tests are not accidentally added to files that are + used when Unicode support is not included in the library. Setting + PCRE2_NEVER_UTF and PCRE2_NEVER_UCP as a default can also be obtained + by the use of #pattern; the difference is that #forbid_utf cannot be + unset, and the automatic options are not displayed in pattern informa- tion, to avoid cluttering up test output. #load This command is used to load a set of precompiled patterns from a file, - as described in the section entitled "Saving and restoring compiled + as described in the section entitled "Saving and restoring compiled patterns" below. #loadtables - This command is used to load a set of binary character tables that can - be accessed by the tables=3 qualifier. Such tables can be created by + This command is used to load a set of binary character tables that can + be accessed by the tables=3 qualifier. Such tables can be created by the pcre2_dftables program with the -b option. #newline_default [] - When PCRE2 is built, a default newline convention can be specified. - This determines which characters and/or character pairs are recognized + When PCRE2 is built, a default newline convention can be specified. + This determines which characters and/or character pairs are recognized as indicating a newline in a pattern or subject string. The default can - be overridden when a pattern is compiled. The standard test files con- - tain tests of various newline conventions, but the majority of the - tests expect a single linefeed to be recognized as a newline by de- - fault. Without special action the tests would fail when PCRE2 is com- + be overridden when a pattern is compiled. The standard test files con- + tain tests of various newline conventions, but the majority of the + tests expect a single linefeed to be recognized as a newline by de- + fault. Without special action the tests would fail when PCRE2 is com- piled with either CR or CRLF as the default newline. The #newline_default command specifies a list of newline types that are - acceptable as the default. The types must be one of CR, LF, CRLF, ANY- + acceptable as the default. The types must be one of CR, LF, CRLF, ANY- CRLF, ANY, or NUL (in upper or lower case), for example: #newline_default LF Any anyCRLF If the default newline is in the list, this command has no effect. Oth- - erwise, except when testing the POSIX API, a newline modifier that + erwise, except when testing the POSIX API, a newline modifier that specifies the first newline convention in the list (LF in the above ex- - ample) is added to any pattern that does not already have a newline + ample) is added to any pattern that does not already have a newline modifier. If the newline list is empty, the feature is turned off. This command is present in a number of the standard test input files. - When the POSIX API is being tested there is no way to override the de- + When the POSIX API is being tested there is no way to override the de- fault newline convention, though it is possible to set the newline con- - vention from within the pattern. A warning is given if the posix or - posix_nosub modifier is used when #newline_default would set a default + vention from within the pattern. A warning is given if the posix or + posix_nosub modifier is used when #newline_default would set a default for the non-POSIX API. #pattern - This command sets a default modifier list that applies to all subse- + This command sets a default modifier list that applies to all subse- quent patterns. Modifiers on a pattern can change these settings. #perltest - This line is used in test files that can also be processed by perl- - test.sh to confirm that Perl gives the same results as PCRE2. Subse- - quent tests are checked for the use of pcre2test features that are in- + This line is used in test files that can also be processed by perl- + test.sh to confirm that Perl gives the same results as PCRE2. Subse- + quent tests are checked for the use of pcre2test features that are in- compatible with the perltest.sh script. - Patterns must use '/' as their delimiter, and only certain modifiers - are supported. Comment lines, #pattern commands, and #subject commands - that set or unset "mark" are recognized and acted on. The #perltest, - #forbid_utf, and #newline_default commands, which are needed in the + Patterns must use '/' as their delimiter, and only certain modifiers + are supported. Comment lines, #pattern commands, and #subject commands + that set or unset "mark" are recognized and acted on. The #perltest, + #forbid_utf, and #newline_default commands, which are needed in the relevant pcre2test files, are silently ignored. All other command lines - are ignored, but give a warning message. The #perltest command helps - detect tests that are accidentally put in the wrong file or use the - wrong delimiter. For more details of the perltest.sh script see the + are ignored, but give a warning message. The #perltest command helps + detect tests that are accidentally put in the wrong file or use the + wrong delimiter. For more details of the perltest.sh script see the comments it contains. #pop [] #popcopy [] - These commands are used to manipulate the stack of compiled patterns, - as described in the section entitled "Saving and restoring compiled + These commands are used to manipulate the stack of compiled patterns, + as described in the section entitled "Saving and restoring compiled patterns" below. #save - This command is used to save a set of compiled patterns to a file, as - described in the section entitled "Saving and restoring compiled pat- + This command is used to save a set of compiled patterns to a file, as + described in the section entitled "Saving and restoring compiled pat- terns" below. #subject - This command sets a default modifier list that applies to all subse- - quent subject lines. Modifiers on a subject line can change these set- + This command sets a default modifier list that applies to all subse- + quent subject lines. Modifiers on a subject line can change these set- tings. + #if CONDITION + ... + #endif + + If CONDITION is true, then the command is printed, and its contents are + processed as normal, including printing the commandlines to the output. + If CONDITION is false, then all lines between the "#if" and "#endif" + are skipped and not printed. The CONDITION can be any of the conditions + which are tested by the "-C" commandline option and which set + pcre2test's exit code to a boolean value. The CONDITION may also be + preceded by "!". + MODIFIER SYNTAX Modifier lists are used with both pattern and subject lines. Items in a list are separated by commas followed by optional white space. Trailing - whitespace in a modifier list is ignored. Some modifiers may be given + white space in a modifier list is ignored. Some modifiers may be given for both patterns and subject lines, whereas others are valid only for one or the other. Each modifier has a long name, for example "an- chored", and some of them must be followed by an equals sign and a @@ -534,7 +565,7 @@ SUBJECT LINE SYNTAX abc\=notbol,notempty - If the subject string is empty and \= is followed by whitespace, the + If the subject string is empty and \= is followed by white space, the line is treated as a comment line, and is not used for matching. For example: @@ -1045,7 +1076,8 @@ PATTERN MODIFIERS heapframes_size show match data heapframes size jitstack= set size of JIT stack mark show mark values - replace= specify a replacement string + null_substitute_match_data substitute with NULL match data + replace= specify a replacement string startchar show starting character when relevant substitute_callout use substitution callouts substitute_case_callout use substitution case callouts @@ -1205,11 +1237,12 @@ SUBJECT MODIFIERS null_context match with a NULL context null_replacement substitute with NULL replacement null_subject match with NULL subject + null_substitute_match_data substitute with NULL match data offset= set starting offset offset_limit= set offset limit ovector= set size of output vector recursion_limit= obsolete synonym for depth_limit - replace= specify a replacement string + replace= specify a replacement string startchar show startchar when relevant startoffset= same as offset= substitute_callout use substitution callouts @@ -1221,34 +1254,36 @@ SUBJECT MODIFIERS substitute_replacement_only use PCRE2_SUBSTITUTE_REPLACEMENT_ONLY substitute_skip= skip substitution number n substitute_stop= skip substitution number n and greater + substitute_subject= specify a different subject for sub- + stitution substitute_unknown_unset use PCRE2_SUBSTITUTE_UNKNOWN_UNSET substitute_unset_empty use PCRE2_SUBSTITUTE_UNSET_EMPTY zero_terminate pass the subject as zero-terminated The effects of these modifiers are described in the following sections. - When matching via the POSIX wrapper API, the aftertext, allaftertext, - and ovector subject modifiers work as described below. All other modi- + When matching via the POSIX wrapper API, the aftertext, allaftertext, + and ovector subject modifiers work as described below. All other modi- fiers are either ignored, with a warning message, or cause an error. Showing more text - The aftertext modifier requests that as well as outputting the part of + The aftertext modifier requests that as well as outputting the part of the subject string that matched the entire pattern, pcre2test should in addition output the remainder of the subject string. This is useful for tests where the subject contains multiple copies of the same substring. - The allaftertext modifier requests the same action for captured sub- + The allaftertext modifier requests the same action for captured sub- strings as well as the main matched substring. In each case the remain- der is output on the following line with a plus character following the capture number. - The allusedtext modifier requests that all the text that was consulted - during a successful pattern match by the interpreter should be shown, - for both full and partial matches. This feature is not supported for - JIT matching, and if requested with JIT it is ignored (with a warning - message). Setting this modifier affects the output if there is a look- - behind at the start of a match, or, for a complete match, a lookahead + The allusedtext modifier requests that all the text that was consulted + during a successful pattern match by the interpreter should be shown, + for both full and partial matches. This feature is not supported for + JIT matching, and if requested with JIT it is ignored (with a warning + message). Setting this modifier affects the output if there is a look- + behind at the start of a match, or, for a complete match, a lookahead at the end, or if \K is used in the pattern. Characters that precede or - follow the start and end of the actual match are indicated in the out- + follow the start and end of the actual match are indicated in the out- put by '<' or '>' characters underneath them. Here is an example: re> /(?<=pqr)abc(?=xyz)/ @@ -1259,16 +1294,16 @@ SUBJECT MODIFIERS Partial match: pqrabcxy <<< - The first, complete match shows that the matched string is "abc", with - the preceding and following strings "pqr" and "xyz" having been con- - sulted during the match (when processing the assertions). The partial + The first, complete match shows that the matched string is "abc", with + the preceding and following strings "pqr" and "xyz" having been con- + sulted during the match (when processing the assertions). The partial match can indicate only the preceding string. - The startchar modifier requests that the starting character for the - match be indicated, if it is different to the start of the matched + The startchar modifier requests that the starting character for the + match be indicated, if it is different to the start of the matched string. The only time when this occurs is when \K has been processed as part of the match. In this situation, the output for the matched string - is displayed from the starting character instead of from the match + is displayed from the starting character instead of from the match point, with circumflex characters under the earlier characters. For ex- ample: @@ -1277,7 +1312,7 @@ SUBJECT MODIFIERS 0: abcxyz ^^^ - Unlike allusedtext, the startchar modifier can be used with JIT. How- + Unlike allusedtext, the startchar modifier can be used with JIT. How- ever, these two modifiers are mutually exclusive. Showing the value of all capture groups @@ -1285,58 +1320,54 @@ SUBJECT MODIFIERS The allcaptures modifier requests that the values of all potential cap- tured parentheses be output after a match. By default, only those up to the highest one actually used in the match are output (corresponding to - the return code from pcre2_match()). Groups that did not take part in - the match are output as "". This modifier is not relevant for - DFA matching (which does no capturing) and does not apply when replace + the return code from pcre2_match()). Groups that did not take part in + the match are output as "". This modifier is not relevant for + DFA matching (which does no capturing) and does not apply when replace is specified; it is ignored, with a warning message, if present. Showing the entire ovector, for all outcomes The allvector modifier requests that the entire ovector be shown, what- ever the outcome of the match. Compare allcaptures, which shows only up - to the maximum number of capture groups for the pattern, and then only - for a successful complete non-DFA match. This modifier, which acts af- - ter any match result, and also for DFA matching, provides a means of - checking that there are no unexpected modifications to ovector fields. - Before each match attempt, the ovector is filled with a special value, - and if this is found in both elements of a capturing pair, "" is output. After a successful match, this applies to all - groups after the maximum capture group for the pattern. In other cases - it applies to the entire ovector. After a partial match, the first two - elements are the only ones that should be set. After a DFA match, the - amount of ovector that is used depends on the number of matches that + to the maximum number of capture groups for the pattern, and then only + for a successful complete non-DFA match. This modifier, which acts af- + ter any match result, and also for DFA matching, provides a means of + checking that there are no unexpected modifications to ovector fields. + Before each match attempt, the ovector is filled with a special value, + and if this is found in both elements of a capturing pair, "" is output. After a successful match, this applies to all + groups after the maximum capture group for the pattern. In other cases + it applies to the entire ovector. After a partial match, the first two + elements are the only ones that should be set. After a DFA match, the + amount of ovector that is used depends on the number of matches that were found. Testing pattern callouts - A callout function is supplied when pcre2test calls the library match- - ing functions, unless callout_none is specified. Its behaviour can be - controlled by various modifiers listed above whose names begin with - callout_. Details are given in the section entitled "Callouts" below. - Testing callouts from pcre2_substitute() is described separately in + A callout function is supplied when pcre2test calls the library match- + ing functions, unless callout_none is specified. Its behaviour can be + controlled by various modifiers listed above whose names begin with + callout_. Details are given in the section entitled "Callouts" below. + Testing callouts from pcre2_substitute() is described separately in "Testing the substitution function" below. Finding all matches in a string Searching for all possible matches within a subject can be requested by - the global or altglobal modifier. After finding a match, the matching - function is called again to search the remainder of the subject. The - difference between global and altglobal is that the former uses the - start_offset argument to pcre2_match() or pcre2_dfa_match() to start - searching at a new point within the entire string (which is what Perl + the global or altglobal modifier. After finding a match, the matching + function is called again to search the remainder of the subject. The + difference between global and altglobal is that the former uses the + start_offset argument to pcre2_match() or pcre2_dfa_match() to start + searching at a new point within the entire string (which is what Perl does), whereas the latter passes over a shortened subject. This makes a difference to the matching process if the pattern begins with a lookbe- hind assertion (including \b or \B). - If an empty string is matched, the next match is done with the - PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set, in order to search - for another, non-empty, match at the same point in the subject. If this - match fails, the start offset is advanced, and the normal match is re- - tried. This imitates the way Perl handles such cases when using the /g - modifier or the split() function. Normally, the start offset is ad- - vanced by one character, but if the newline convention recognizes CRLF - as a newline, and the current character is CR followed by LF, an ad- - vance of two characters occurs. + If an empty string is matched, the next match is done with the + PCRE2_NOTEMPTY_ATSTART flag set, in order to search for another, non- + empty, match at the same point in the subject. This imitates the way + Perl handles such cases when using the /g modifier or the split() func- + tion. Testing substring extraction functions @@ -1418,7 +1449,7 @@ SUBJECT MODIFIERS 123abc123\=replace=[10]XYZ 1: 123XYZ123 123abc123\=replace=[9]XYZ - Failed: error -47: no more memory + Failed: error -48: no more memory The default action of pcre2_substitute() is to return PCRE2_ER- ROR_NOMEMORY when the output buffer is too small. However, if the @@ -1432,12 +1463,18 @@ SUBJECT MODIFIERS /abc/substitute_overflow_length 123abc123\=replace=[9]XYZ - Failed: error -47: no more memory: 10 code units are needed + Failed: error -48: no more memory: 10 code units are needed A replacement string is ignored with POSIX and DFA matching. Specifying partial matching provokes an error return ("bad option value") from pcre2_substitute(). + The substitute_subject modifier may be used to test the use of the + PCRE2 API, in which a client calls pcre2_match() followed by pcre2_sub- + stitute() with PCRE2_SUBSTITUTE_MATCHED, but the client performs an un- + expected and unsupported modification of the subject buffer in-place, + in between the match and substitution. + Testing substitute callouts If the substitute_callout modifier is set, a substitution callout func- @@ -2061,8 +2098,8 @@ AUTHOR REVISION - Last updated: 26 December 2024 + Last updated: 12 October 2025 Copyright (c) 1997-2024 University of Cambridge. -PCRE2 10.46 26 December 2024 PCRE2TEST(1) +PCRE2 10.47 12 October 2025 PCRE2TEST(1) diff --git a/doc/pcre2unicode.3 b/doc/pcre2unicode.3 index 417baf3..cb9f519 100644 --- a/doc/pcre2unicode.3 +++ b/doc/pcre2unicode.3 @@ -1,4 +1,4 @@ -.TH PCRE2UNICODE 3 "27 November 2024" "PCRE2 10.46" +.TH PCRE2UNICODE 3 "27 November 2024" "PCRE2 10.47" .SH NAME PCRE2 - Perl-compatible regular expressions (revised API) .SH "UNICODE AND UTF SUPPORT" diff --git a/libpcre2-16.pc.in b/libpcre2-16.pc.in index bacb466..fe47b58 100644 --- a/libpcre2-16.pc.in +++ b/libpcre2-16.pc.in @@ -8,6 +8,7 @@ includedir=@includedir@ Name: libpcre2-16 Description: PCRE2 - Perl compatible regular expressions C library (2nd API) with 16 bit character support Version: @PACKAGE_VERSION@ +License: BSD-3-Clause WITH PCRE2-exception Libs: -L${libdir} -lpcre2-16@LIB_POSTFIX@ Libs.private: @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ Cflags: -I${includedir} @PCRE2_STATIC_CFLAG@ diff --git a/libpcre2-32.pc.in b/libpcre2-32.pc.in index 06241f0..f2e9192 100644 --- a/libpcre2-32.pc.in +++ b/libpcre2-32.pc.in @@ -8,6 +8,7 @@ includedir=@includedir@ Name: libpcre2-32 Description: PCRE2 - Perl compatible regular expressions C library (2nd API) with 32 bit character support Version: @PACKAGE_VERSION@ +License: BSD-3-Clause WITH PCRE2-exception Libs: -L${libdir} -lpcre2-32@LIB_POSTFIX@ Libs.private: @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ Cflags: -I${includedir} @PCRE2_STATIC_CFLAG@ diff --git a/libpcre2-8.pc.in b/libpcre2-8.pc.in index 246bb9e..8697a95 100644 --- a/libpcre2-8.pc.in +++ b/libpcre2-8.pc.in @@ -8,6 +8,7 @@ includedir=@includedir@ Name: libpcre2-8 Description: PCRE2 - Perl compatible regular expressions C library (2nd API) with 8 bit character support Version: @PACKAGE_VERSION@ +License: BSD-3-Clause WITH PCRE2-exception Libs: -L${libdir} -lpcre2-8@LIB_POSTFIX@ Libs.private: @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ Cflags: -I${includedir} @PCRE2_STATIC_CFLAG@ diff --git a/libpcre2-posix.pc.in b/libpcre2-posix.pc.in index 2f1e8f1..faac2c5 100644 --- a/libpcre2-posix.pc.in +++ b/libpcre2-posix.pc.in @@ -8,6 +8,7 @@ includedir=@includedir@ Name: libpcre2-posix Description: Posix compatible interface to libpcre2-8 Version: @PACKAGE_VERSION@ +License: BSD-3-Clause WITH PCRE2-exception Libs: -L${libdir} -lpcre2-posix@LIB_POSTFIX@ Cflags: -I${includedir} @PCRE2POSIX_CFLAG@ Requires.private: libpcre2-8 diff --git a/m4/ax_check_vscript.m4 b/m4/ax_check_vscript.m4 new file mode 100644 index 0000000..ed834ef --- /dev/null +++ b/m4/ax_check_vscript.m4 @@ -0,0 +1,153 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_vscript.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_VSCRIPT +# +# DESCRIPTION +# +# Check whether the linker supports version scripts. Version scripts are +# used when building shared libraries to bind symbols to version nodes +# (helping to detect incompatibilities) or to limit the visibility of +# non-public symbols. +# +# Output: +# +# If version scripts are supported, VSCRIPT_LDFLAGS will contain the +# appropriate flag to pass to the linker. On GNU systems this would +# typically be "-Wl,--version-script", and on Solaris it would typically +# be "-Wl,-M". +# +# Two Automake conditionals are also set: +# +# HAVE_VSCRIPT is true if the linker supports version scripts with +# entries that use simple wildcards, like "local: *". +# +# HAVE_VSCRIPT_COMPLEX is true if the linker supports version scripts with +# pattern matching wildcards, like "global: Java_*". +# +# On systems that do not support symbol versioning, such as Mac OS X, both +# conditionals will be false. They will also be false if the user passes +# "--disable-symvers" on the configure command line. +# +# Example: +# +# configure.ac: +# +# AX_CHECK_VSCRIPT +# +# Makefile.am: +# +# if HAVE_VSCRIPT +# libfoo_la_LDFLAGS += $(VSCRIPT_LDFLAGS),@srcdir@/libfoo.map +# endif +# +# if HAVE_VSCRIPT_COMPLEX +# libbar_la_LDFLAGS += $(VSCRIPT_LDFLAGS),@srcdir@/libbar.map +# endif +# +# LICENSE +# +# Copyright (c) 2014 Kevin Cernekee +# +# 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/m4/ax_pthread.m4 b/m4/ax_pthread.m4 index d90de34..9f35d13 100644 --- a/m4/ax_pthread.m4 +++ b/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" + ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags" ;; +esac - darwin*) - ax_pthread_flags="-pthread $ax_pthread_flags" +# Are we compiling with Clang? + +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 flag in $ax_pthread_flags; do +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do - case $flag in + 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/m4/pcre2_visibility.m4 b/m4/pcre2_visibility.m4 index 03f4fba..1e4e819 100644 --- a/m4/pcre2_visibility.m4 +++ b/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/m4/pcre2_zos.m4 b/m4/pcre2_zos.m4 new file mode 100644 index 0000000..2e5dbd4 --- /dev/null +++ b/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/perltest.sh b/perltest.sh index 37d4511..65031ce 100755 --- a/perltest.sh +++ b/perltest.sh @@ -118,9 +118,10 @@ fi # already have. NOTE: this is different to pcre2test where #pattern sets # defaults which can be overridden on individual patterns. The #subject command # may be used to set or unset a default "mark" modifier for data lines. This is -# the only use of #subject that is supported. The #perltest, #forbid_utf, and -# #newline_default commands, which are needed in the relevant pcre2test files, -# are ignored. Any other #-command is ignored, with a warning message. +# the only use of #subject that is supported. The #perltest, #forbid_utf, +# #newline_default, and #if...#endif commands, which are needed in the relevant +# pcre2test files, are ignored. Any other #-command is ignored, with a warning +# message. # # The pattern lines should use only / as the delimiter. The other characters # that pcre2test supports cause problems with this script. @@ -247,7 +248,7 @@ for (;;) } elsif ($_ =~ /^#/) { - if ($_ !~ /^#newline_default|^#perltest|^#forbid_utf/) + if ($_ !~ /^#newline_default|^#perltest|^#forbid_utf|^#if|^#endif/) { printf $outfile "** Warning: #-command ignored: %s", $_; } diff --git a/src/config-cmake.h.in b/src/config-cmake.h.in new file mode 100644 index 0000000..bcc62c0 --- /dev/null +++ b/src/config-cmake.h.in @@ -0,0 +1,55 @@ +/* config.h for CMake builds */ + +#cmakedefine HAVE_ASSERT_H 1 +#cmakedefine HAVE_BUILTIN_ASSUME 1 +#cmakedefine HAVE_BUILTIN_MUL_OVERFLOW 1 +#cmakedefine HAVE_BUILTIN_UNREACHABLE 1 +#cmakedefine HAVE_ATTRIBUTE_UNINITIALIZED 1 +#cmakedefine HAVE_DIRENT_H 1 +#cmakedefine HAVE_SYS_STAT_H 1 +#cmakedefine HAVE_SYS_TYPES_H 1 +#cmakedefine HAVE_UNISTD_H 1 +#cmakedefine HAVE_WINDOWS_H 1 + +#cmakedefine HAVE_MEMFD_CREATE 1 +#cmakedefine HAVE_SECURE_GETENV 1 + +#cmakedefine SUPPORT_PCRE2_8 1 +#cmakedefine SUPPORT_PCRE2_16 1 +#cmakedefine SUPPORT_PCRE2_32 1 +#cmakedefine DISABLE_PERCENT_ZT 1 + +#cmakedefine SUPPORT_LIBBZ2 1 +#cmakedefine SUPPORT_LIBEDIT 1 +#cmakedefine SUPPORT_LIBREADLINE 1 +#cmakedefine SUPPORT_LIBZ 1 + +#cmakedefine SUPPORT_JIT 1 +#cmakedefine SLJIT_PROT_EXECUTABLE_ALLOCATOR 1 +#cmakedefine SUPPORT_PCRE2GREP_JIT 1 +#cmakedefine SUPPORT_PCRE2GREP_CALLOUT 1 +#cmakedefine SUPPORT_PCRE2GREP_CALLOUT_FORK 1 +#cmakedefine SUPPORT_UNICODE 1 +#cmakedefine SUPPORT_VALGRIND 1 + +#cmakedefine BSR_ANYCRLF 1 +#cmakedefine EBCDIC 1 +#cmakedefine EBCDIC_NL25 1 +#cmakedefine EBCDIC_IGNORING_COMPILER 1 +#cmakedefine NEVER_BACKSLASH_C 1 + +#define PCRE2_EXPORT @PCRE2_EXPORT@ +#define LINK_SIZE @PCRE2_LINK_SIZE@ +#define HEAP_LIMIT @PCRE2_HEAP_LIMIT@ +#define MATCH_LIMIT @PCRE2_MATCH_LIMIT@ +#define MATCH_LIMIT_DEPTH @PCRE2_MATCH_LIMIT_DEPTH@ +#define MAX_VARLOOKBEHIND @PCRE2_MAX_VARLOOKBEHIND@ +#define NEWLINE_DEFAULT @NEWLINE_DEFAULT@ +#define PARENS_NEST_LIMIT @PCRE2_PARENS_NEST_LIMIT@ +#define PCRE2GREP_BUFSIZE @PCRE2GREP_BUFSIZE@ +#define PCRE2GREP_MAX_BUFSIZE @PCRE2GREP_MAX_BUFSIZE@ + +#define MAX_NAME_SIZE 128 +#define MAX_NAME_COUNT 10000 + +/* end config.h for CMake builds */ diff --git a/src/config.h.generic b/src/config.h.generic index e982933..48da31e 100644 --- a/src/config.h.generic +++ b/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.46" +#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.46" +#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.46" +#define VERSION "10.47" /* Number of bits in a file offset, on hosts where this is settable. */ /* #undef _FILE_OFFSET_BITS */ diff --git a/src/config.h.in b/src/config.h.in index be29681..0f2ef38 100644 --- a/src/config.h.in +++ b/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/src/libpcre2-16.sym b/src/libpcre2-16.sym new file mode 100644 index 0000000..fd5257d --- /dev/null +++ b/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/src/libpcre2-32.sym b/src/libpcre2-32.sym new file mode 100644 index 0000000..d4606c2 --- /dev/null +++ b/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/src/libpcre2-8.sym b/src/libpcre2-8.sym new file mode 100644 index 0000000..368b4e4 --- /dev/null +++ b/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/src/libpcre2-posix.sym b/src/libpcre2-posix.sym new file mode 100644 index 0000000..04a56cf --- /dev/null +++ b/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/src/pcre2.h.generic b/src/pcre2.h.generic index a6c739f..4034e5a 100644 --- a/src/pcre2.h.generic +++ b/src/pcre2.h.generic @@ -42,25 +42,21 @@ POSSIBILITY OF SUCH DAMAGE. /* The current PCRE version information. */ #define PCRE2_MAJOR 10 -#define PCRE2_MINOR 46 +#define PCRE2_MINOR 47 #define PCRE2_PRERELEASE -#define PCRE2_DATE 2025-08-27 +#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/src/pcre2.h.in b/src/pcre2.h.in index ca3f0b4..0dffe65 100644 --- a/src/pcre2.h.in +++ b/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/src/pcre2_auto_possess.c b/src/pcre2_auto_possess.c index 6d7f27b..4088032 100644 --- a/src/pcre2_auto_possess.c +++ b/src/pcre2_auto_possess.c @@ -38,16 +38,14 @@ 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" -#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 @@ -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/src/pcre2_chartables.c.dist b/src/pcre2_chartables.c.dist index 7362c3f..29f9200 100644 --- a/src/pcre2_chartables.c.dist +++ b/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/src/pcre2_chartables.c.ebcdic-1047-nl15 b/src/pcre2_chartables.c.ebcdic-1047-nl15 new file mode 100644 index 0000000..071a8f4 --- /dev/null +++ b/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/src/pcre2_chartables.c.ebcdic-1047-nl25 b/src/pcre2_chartables.c.ebcdic-1047-nl25 new file mode 100644 index 0000000..99ba81b --- /dev/null +++ b/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/src/pcre2_chkdint.c b/src/pcre2_chkdint.c index 7083023..7aeb640 100644 --- a/src/pcre2_chkdint.c +++ b/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/src/pcre2_compile.c b/src/pcre2_compile.c index 0ffac89..f126e41 100644 --- a/src/pcre2_compile.c +++ b/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. */ - 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; + start_pptr[0] = meta | 1; + start_pptr[1] = (uint32_t)(ng - cb->named_groups); - if (meta == META_SCS_NAME) + /* 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[0] = OP_DNCREF; - PUT2(code, 1, index); - PUT2(code, 1+IMM2_SIZE, count); - code += 1+2*IMM2_SIZE; - break; + 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; + + /* 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++) + ng = PRIV(compile_find_named_group)(name, length, cb); + + if (ng == NULL) { - if (length == ng->length && - PRIV(strncmp)(name, ng->name, length) == 0) - { - is_dupname = ng->isdup; - groupnumber = ng->number; + /* If the name was not found we have a bad reference. */ + *errorcodeptr = ERR15; + cb->erroroffset = offset; + return 0; + } - /* 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. */ + groupnumber = ng->number; - 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. */ + /* 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. */ - cb->backref_map |= (groupnumber < 32)? (1u << groupnumber) : 1; - if (groupnumber > cb->top_backref) - cb->top_backref = groupnumber; - } + if (meta == META_RECURSE_BYNAME) + { + meta_arg = groupnumber; + goto HANDLE_NUMERICAL_RECURSION; } - /* If the name was not found we have a bad reference. */ + /* For a back reference, update the back reference map and the + maximum back reference. */ - if (groupnumber == 0) - { - *errorcodeptr = ERR15; - cb->erroroffset = offset; - return 0; - } + 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/src/pcre2_compile.h b/src/pcre2_compile.h index c8bf610..331ca3a 100644 --- a/src/pcre2_compile.h +++ b/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/src/pcre2_compile_cgroup.c b/src/pcre2_compile_cgroup.c new file mode 100644 index 0000000..ee0cd06 --- /dev/null +++ b/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/src/pcre2_compile_class.c b/src/pcre2_compile_class.c index 6a73bb9..9a1fc02 100644 --- a/src/pcre2_compile_class.c +++ b/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/src/pcre2_config.c b/src/pcre2_config.c index 031981b..045f6e7 100644 --- a/src/pcre2_config.c +++ b/src/pcre2_config.c @@ -38,17 +38,10 @@ 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. */ +#include "pcre2_internal.h" -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 @@ -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/src/pcre2_context.c b/src/pcre2_context.c index 2345145..6246683 100644 --- a/src/pcre2_context.c +++ b/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/src/pcre2_convert.c b/src/pcre2_convert.c index d2b238c..ad7312a 100644 --- a/src/pcre2_convert.c +++ b/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/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c index ebf31d2..f507acf 100644 --- a/src/pcre2_dfa_match.c +++ b/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) + { + 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) { - 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) + { 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/src/pcre2_dftables.c b/src/pcre2_dftables.c index 0f9aedf..1d19870 100644 --- a/src/pcre2_dftables.c +++ b/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/src/pcre2_error.c b/src/pcre2_error.c index 8b7423c..df26add 100644 --- a/src/pcre2_error.c +++ b/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/src/pcre2_extuni.c b/src/pcre2_extuni.c index 91d839e..1b7f04b 100644 --- a/src/pcre2_extuni.c +++ b/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/src/pcre2_find_bracket.c b/src/pcre2_find_bracket.c index 486f453..e26ee99 100644 --- a/src/pcre2_find_bracket.c +++ b/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/src/pcre2_fuzzsupport.c b/src/pcre2_fuzzsupport.c index fa2b51b..ba3fc88 100644 --- a/src/pcre2_fuzzsupport.c +++ b/src/pcre2_fuzzsupport.c @@ -1,3 +1,44 @@ +/************************************************* +* 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-2023 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. +----------------------------------------------------------------------------- +*/ + + /*************************************************************************** Fuzzer driver for PCRE2. Given an arbitrary string of bytes and a length, it tries to compile and match it, deriving options from the string itself. If @@ -11,6 +52,7 @@ Updated February 2024 (Addison Crump added 16-bit/32-bit and JIT support) Further updates March/April/May 2024 by PH ***************************************************************************/ + #include #include #include @@ -29,8 +71,6 @@ Further updates March/April/May 2024 by PH #define PCRE2_CODE_UNIT_WIDTH 8 #endif -#include "config.h" -#include "pcre2.h" #include "pcre2_internal.h" #define MAX_MATCH_SIZE 1000 diff --git a/src/pcre2_internal.h b/src/pcre2_internal.h index 6e0a5e0..aa79409 100644 --- a/src/pcre2_internal.h +++ b/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/src/pcre2_intmodedep.h b/src/pcre2_intmodedep.h index 6b85813..6cefb61 100644 --- a/src/pcre2_intmodedep.h +++ b/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/src/pcre2_jit_char_inc.h b/src/pcre2_jit_char_inc.h index 69fe938..0976742 100644 --- a/src/pcre2_jit_char_inc.h +++ b/src/pcre2_jit_char_inc.h @@ -519,6 +519,8 @@ BOOL has_cmov, last_range_set; sljit_u32 category_list = 0; sljit_u32 items; int typereg = TMP1; +#else +(void)c; /* Avoid compiler warning. */ #endif /* SUPPORT_UNICODE */ SLJIT_ASSERT(common->locals_size >= SSIZE_OF(sw)); @@ -568,7 +570,7 @@ while (*cc == XCL_PROP || *cc == XCL_NOTPROP) break; } compares++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case PT_SC: status |= XCLASS_HAS_SCRIPT; @@ -696,13 +698,11 @@ if (status & XCLASS_NEEDS_UCD) 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); + sljit_emit_op2_shift(compiler, SLJIT_ADD | SLJIT_SHL_IMM | SLJIT_SRC2_UNDEFINED, TMP1, 0, TMP1, 0, TMP2, 0, UCD_BLOCK_SHIFT); OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2)); OP1(SLJIT_MOV_U16, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1); - OP2(SLJIT_SHL, TMP1, 0, TMP2, 0, SLJIT_IMM, 3); + sljit_emit_op2_shift(compiler, SLJIT_ADD | SLJIT_SHL_IMM | SLJIT_SRC2_UNDEFINED, TMP2, 0, TMP2, 0, TMP2, 0, 1); OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 2); - OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0); ccbegin = cc; @@ -768,7 +768,7 @@ if (status & XCLASS_NEEDS_UCD) case PT_SCX: if (cc[-1] == XCL_NOTPROP) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case PT_SC: compares--; @@ -1104,7 +1104,7 @@ if (ranges.range_count >= 6) depth = 0; first_item = 0; -last_item = ranges.range_count - 2; +last_item = (sljit_u32)(ranges.range_count - 2); has_cmov = sljit_has_cpu_feature(SLJIT_HAS_CMOV) != 0; while (TRUE) @@ -1486,7 +1486,7 @@ static PCRE2_SPTR SLJIT_FUNC do_extuni_utf(jit_arguments *args, PCRE2_SPTR cc) { PCRE2_SPTR start_subject = args->begin; PCRE2_SPTR end_subject = args->end; -int lgb, rgb, ricount; +int lgb = 0, rgb, ricount; PCRE2_SPTR prevcc, endcc, bptr; BOOL first = TRUE; BOOL was_ep_ZWJ = FALSE; @@ -1569,7 +1569,7 @@ static PCRE2_SPTR SLJIT_FUNC do_extuni_utf_invalid(jit_arguments *args, PCRE2_SP { PCRE2_SPTR start_subject = args->begin; PCRE2_SPTR end_subject = args->end; -int lgb, rgb, ricount; +int lgb = 0, rgb, ricount; PCRE2_SPTR prevcc, endcc, bptr; BOOL first = TRUE; BOOL was_ep_ZWJ = FALSE; @@ -1964,9 +1964,9 @@ switch(type) detect_partial_match(common, backtracks); if (type == OP_NOT_HSPACE) - read_char(common, 0x9, 0x3000, backtracks, READ_CHAR_UPDATE_STR_PTR); + read_char(common, 0x1, 0x3000, backtracks, READ_CHAR_UPDATE_STR_PTR); else - read_char(common, 0x9, 0x3000, NULL, 0); + read_char(common, 0x1, 0x3000, NULL, 0); add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL)); sljit_set_current_flags(compiler, SLJIT_SET_Z); @@ -1979,9 +1979,9 @@ switch(type) detect_partial_match(common, backtracks); if (type == OP_NOT_VSPACE) - read_char(common, 0xa, 0x2029, backtracks, READ_CHAR_UPDATE_STR_PTR); + read_char(common, 0x1, 0x2029, backtracks, READ_CHAR_UPDATE_STR_PTR); else - read_char(common, 0xa, 0x2029, NULL, 0); + read_char(common, 0x1, 0x2029, NULL, 0); add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL)); sljit_set_current_flags(compiler, SLJIT_SET_Z); diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c index 175eb68..3ab4592 100644 --- a/src/pcre2_jit_compile.c +++ b/src/pcre2_jit_compile.c @@ -39,10 +39,6 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #if defined(__has_feature) #if __has_feature(memory_sanitizer) #include @@ -339,6 +335,10 @@ typedef struct recurse_entry { jump_list *backtrack_calls; /* Points to the starting opcode. */ sljit_sw start; + /* Start of caller arguments. */ + PCRE2_SPTR arg_start; + /* Size of caller arguments in bytes. */ + sljit_uw arg_size; } recurse_entry; typedef struct recurse_backtrack { @@ -398,8 +398,10 @@ typedef struct compiler_common { 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; + /* Bitset which tells which capture brackets can be optimized. */ + sljit_u8 *optimized_cbrackets; + /* Bitset for tracking capture bracket status. */ + sljit_u8 *cbracket_bitset; /* Tells whether the starting offset is a target of then. */ sljit_u8 *then_offsets; /* Current position where a THEN must jump. */ @@ -443,6 +445,8 @@ typedef struct compiler_common { /* Locals used by fast fail optimization. */ sljit_s32 early_fail_start_ptr; sljit_s32 early_fail_end_ptr; + /* Byte length of optimized_cbrackets and cbracket_bitset. */ + sljit_u32 cbracket_bitset_length; /* Variables used by recursive call generator. */ sljit_s32 recurse_bitset_size; uint8_t *recurse_bitset; @@ -1143,6 +1147,18 @@ if (*cc >= OP_CRSTAR && *cc <= OP_CRPOSRANGE) return (current_locals_size >= locals_size) ? current_locals_size : locals_size; } +static SLJIT_INLINE BOOL is_optimized_cbracket(compiler_common *common, sljit_s32 capture_index) +{ +sljit_u8 bit = (sljit_u8)(1 << (capture_index & 0x7)); +return (common->optimized_cbrackets[capture_index >> 3] & bit) != 0; +} + +static SLJIT_INLINE void clear_optimized_cbracket(compiler_common *common, sljit_s32 capture_index) +{ +sljit_u8 mask = (sljit_u8)~(1 << (capture_index & 0x7)); +common->optimized_cbrackets[capture_index >> 3] &= mask; +} + static BOOL check_opcode_types(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR ccend) { int count; @@ -1193,7 +1209,7 @@ while (cc < ccend) case OP_REFI: case OP_REF: locals_size = ref_update_local_size(common, cc, locals_size); - common->optimized_cbracket[GET2(cc, 1)] = 0; + clear_optimized_cbracket(common, GET2(cc, 1)); cc += PRIV(OP_lengths)[*cc]; break; @@ -1208,7 +1224,7 @@ while (cc < ccend) case OP_CBRAPOS: case OP_SCBRAPOS: - common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0; + clear_optimized_cbracket(common, GET2(cc, 1 + LINK_SIZE)); cc += 1 + LINK_SIZE + IMM2_SIZE; break; @@ -1222,20 +1238,20 @@ while (cc < ccend) break; case OP_CREF: - common->optimized_cbracket[GET2(cc, 1)] = 0; + clear_optimized_cbracket(common, GET2(cc, 1)); cc += 1 + IMM2_SIZE; break; case OP_DNREFI: case OP_DNREF: locals_size = ref_update_local_size(common, cc, locals_size); - /* Fall through */ + PCRE2_FALLTHROUGH /* 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; + clear_optimized_cbracket(common, GET2(slot, 0)); slot += common->name_entry_size; } cc += PRIV(OP_lengths)[*cc]; @@ -1245,6 +1261,11 @@ while (cc < ccend) /* Set its value only once. */ set_recursive_head = TRUE; cc += 1 + LINK_SIZE; + while (*cc == OP_CREF) + { + clear_optimized_cbracket(common, GET2(cc, 1)); + cc += 1 + IMM2_SIZE; + } break; case OP_CALLOUT: @@ -1263,7 +1284,7 @@ while (cc < ccend) case OP_THEN_ARG: common->has_then = TRUE; common->control_head_ptr = 1; - /* Fall through. */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_COMMIT_ARG: case OP_PRUNE_ARG: @@ -1313,7 +1334,7 @@ while (cc < ccend) if (common->utf && locals_size <= 3 * SSIZE_OF(sw)) locals_size = 3 * SSIZE_OF(sw); #endif - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ default: cc = next_opcode(common, cc); if (cc == NULL) @@ -1379,7 +1400,7 @@ 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(*cc != OP_CBRA || is_optimized_cbracket(common, GET2(cc, 1 + LINK_SIZE))); SLJIT_ASSERT(start < EARLY_FAIL_ENHANCE_MAX); next_alt = cc + GET(cc, 1); @@ -1462,7 +1483,7 @@ do case OP_TYPEMINPLUS: if (count == 2) count = 3; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_TYPESTAR: case OP_TYPEPLUS: @@ -1491,7 +1512,7 @@ do case OP_TYPEMINUPTO: case OP_TYPEPOSUPTO: cc += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_TYPEQUERY: case OP_TYPEMINQUERY: @@ -1512,7 +1533,7 @@ do case OP_NOTMINPLUSI: if (count == 2) count = 3; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_STAR: case OP_PLUS: @@ -1565,7 +1586,7 @@ do case OP_NOTEXACTI: case OP_NOTPOSUPTOI: cc += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_QUERY: case OP_MINQUERY: @@ -1605,7 +1626,7 @@ do case OP_CRMINPLUS: if (count == 2) count = 3; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRSTAR: case OP_CRPLUS: @@ -1627,7 +1648,7 @@ do } cc += 2 * IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRQUERY: case OP_CRMINQUERY: case OP_CRPOSQUERY: @@ -1657,7 +1678,7 @@ do count = 3; end = bracketend(cc); - if (end[-1 - LINK_SIZE] != OP_KET || (*cc == OP_CBRA && common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)) + if (end[-1 - LINK_SIZE] != OP_KET || (*cc == OP_CBRA && !is_optimized_cbracket(common, GET2(cc, 1 + LINK_SIZE)))) break; prev_count = detect_early_fail(common, cc, private_data_start, depth + 1, prev_count); @@ -1838,7 +1859,8 @@ if (*next == OP_BRAZERO || *next == OP_BRAMINZERO) if (i == max) { - common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end; + /* Patterns must fit into an int32 even for link-size=4. */ + common->private_data_ptrs[max_end - common->start - LINK_SIZE] = (sljit_s32)(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; @@ -1853,7 +1875,7 @@ if (*next == OP_BRAZERO || *next == OP_BRAMINZERO) if (min >= 3) { - common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end; + common->private_data_ptrs[end - common->start - LINK_SIZE] = (sljit_s32)(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; @@ -2118,11 +2140,22 @@ while (cc < ccend) *private_data_start = private_data_ptr; } +static SLJIT_INLINE BOOL is_cbracket_processed(compiler_common *common, sljit_s32 capture_index) +{ +sljit_u8 bit = (sljit_u8)(1 << (capture_index & 0x7)); +sljit_u8 *ptr = common->cbracket_bitset + (capture_index >> 3); +sljit_u8 value = *ptr; + +*ptr |= bit; +return (value & bit) != 0; +} + /* 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; +int offset; BOOL stack_restore = FALSE; BOOL setsom_found = recursive; BOOL setmark_found = recursive; @@ -2136,6 +2169,8 @@ SLJIT_ASSERT(common->control_head_ptr != 0); *needs_control_head = FALSE; #endif +memset(common->cbracket_bitset, 0, common->cbracket_bitset_length); + if (ccend == NULL) { ccend = bracketend(cc) - (1 + LINK_SIZE); @@ -2196,7 +2231,15 @@ while (cc < ccend) length += 2; capture_last_found = TRUE; } + cc += 1 + LINK_SIZE; + while (*cc == OP_CREF) + { + offset = GET2(cc, 1); + if (!is_cbracket_processed(common, offset)) + length += 3; + cc += 1 + IMM2_SIZE; + } break; case OP_CBRA: @@ -2209,7 +2252,10 @@ while (cc < ccend) length += 2; capture_last_found = TRUE; } - length += 3; + + offset = GET2(cc, 1 + LINK_SIZE); + if (!is_cbracket_processed(common, offset)) + length += 3; cc += 1 + LINK_SIZE + IMM2_SIZE; break; @@ -2222,7 +2268,7 @@ while (cc < ccend) default: stack_restore = TRUE; - /* Fall through. */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOT_WORD_BOUNDARY: case OP_WORD_BOUNDARY: @@ -2322,6 +2368,8 @@ int offset; SLJIT_UNUSED_ARG(stacktop); SLJIT_ASSERT(stackpos >= stacktop + 2); +memset(common->cbracket_bitset, 0, common->cbracket_bitset_length); + stackpos = STACK(stackpos); if (ccend == NULL) { @@ -2395,6 +2443,23 @@ while (cc < ccend) capture_last_found = TRUE; } cc += 1 + LINK_SIZE; + while (*cc == OP_CREF) + { + offset = GET2(cc, 1); + if (!is_cbracket_processed(common, offset)) + { + offset <<= 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 + IMM2_SIZE; + } break; case OP_CBRA: @@ -2410,15 +2475,20 @@ while (cc < ccend) 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); + + offset = GET2(cc, 1 + LINK_SIZE); + if (!is_cbracket_processed(common, offset)) + { + offset <<= 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; @@ -2438,7 +2508,7 @@ SLJIT_ASSERT(stackpos == STACK(stacktop)); typedef struct delayed_mem_copy_status { struct sljit_compiler *compiler; int store_bases[RECURSE_TMP_REG_COUNT]; - int store_offsets[RECURSE_TMP_REG_COUNT]; + sljit_s32 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; @@ -2460,7 +2530,7 @@ 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) + int store_base, sljit_s32 store_offset) { struct sljit_compiler *compiler = status->compiler; int next_tmp_reg = status->next_tmp_reg; @@ -2537,17 +2607,31 @@ enum get_recurse_flags { recurse_flag_setsom_found = (1 << 2), recurse_flag_setmark_found = (1 << 3), recurse_flag_control_head_found = (1 << 4), + recurse_flag_recurse_arg = (1 << 5), }; 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; +PCRE2_SPTR alternative, cref; uint32_t recurse_flags = 0; memset(common->recurse_bitset, 0, common->recurse_bitset_size); +if (common->currententry->arg_size > 0) + { + cref = common->currententry->arg_start; + + do + { + offset = GET2(cref, 1); + recurse_check_bit(common, OVECTOR(offset << 1)); + cref += 1 + IMM2_SIZE; + } + while (*cref == OP_CREF); + } + #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD SLJIT_ASSERT(common->control_head_ptr != 0); recurse_flags |= recurse_flag_control_head_found; @@ -2573,6 +2657,8 @@ while (cc < ccend) if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) length++; cc += 1 + LINK_SIZE; + if (*cc == OP_CREF) + recurse_flags |= recurse_flag_recurse_arg; break; case OP_KET: @@ -2605,6 +2691,22 @@ while (cc < ccend) cc += 1 + LINK_SIZE; break; + case OP_CREF: + if ((recurse_flags & recurse_flag_recurse_arg) != 0) + { + offset = GET2(cc, 1); + if (recurse_check_bit(common, OVECTOR(offset << 1))) + { + SLJIT_ASSERT(recurse_check_bit(common, OVECTOR((offset << 1) + 1))); + length += 2; + } + + if (cc[1 + IMM2_SIZE] != OP_CREF) + recurse_flags &= ~(uint32_t)recurse_flag_recurse_arg; + } + cc += 1 + IMM2_SIZE; + break; + case OP_ASSERT_SCS: SLJIT_ASSERT(PRIVATE_DATA(cc) != 0); if (recurse_check_bit(common, PRIVATE_DATA(cc))) @@ -2620,7 +2722,7 @@ while (cc < ccend) 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))) + if (!is_optimized_cbracket(common, offset) && recurse_check_bit(common, OVECTOR_PRIV(offset))) length++; if (common->capture_last_ptr != 0 && recurse_check_bit(common, common->capture_last_ptr)) length++; @@ -2803,7 +2905,7 @@ static void copy_recurse_data(compiler_common *common, PCRE2_SPTR cc, PCRE2_SPTR int type, int stackptr, int stacktop, uint32_t recurse_flags) { delayed_mem_copy_status status; -PCRE2_SPTR alternative; +PCRE2_SPTR alternative, cref; sljit_sw private_srcw[2]; sljit_sw shared_srcw[3]; sljit_sw kept_shared_srcw[2]; @@ -2812,6 +2914,19 @@ int from_sp, base_reg, offset, i; memset(common->recurse_bitset, 0, common->recurse_bitset_size); +if (common->currententry->arg_size > 0) + { + cref = common->currententry->arg_start; + + do + { + offset = GET2(cref, 1); + recurse_check_bit(common, OVECTOR(offset << 1)); + cref += 1 + IMM2_SIZE; + } + while (*cref == OP_CREF); + } + #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); @@ -2924,12 +3039,16 @@ while (cc < ccend) 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; + if (*cc == OP_CREF) + recurse_flags |= recurse_flag_recurse_arg; break; case OP_KET: @@ -2962,6 +3081,24 @@ while (cc < ccend) cc += 1 + LINK_SIZE; break; + case OP_CREF: + if ((recurse_flags & recurse_flag_recurse_arg) != 0) + { + offset = GET2(cc, 1); + 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 (cc[1 + IMM2_SIZE] != OP_CREF) + recurse_flags &= ~(uint32_t)recurse_flag_recurse_arg; + } + cc += 1 + IMM2_SIZE; + break; + case OP_ASSERT_SCS: private_srcw[0] = PRIVATE_DATA(cc); private_srcw[1] = private_srcw[0] + sizeof(sljit_sw); @@ -2987,7 +3124,7 @@ while (cc < ccend) shared_count++; } - if (common->optimized_cbracket[offset] == 0) + if (!is_optimized_cbracket(common, offset)) { private_srcw[0] = OVECTOR_PRIV(offset); if (recurse_check_bit(common, private_srcw[0])) @@ -3184,7 +3321,7 @@ while (cc < ccend) SLJIT_ASSERT(private_srcw[i] != 0); if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, private_srcw[i]); + delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, (sljit_s32)private_srcw[i]); if (from_sp || type == recurse_swap_global) delayed_mem_copy_move(&status, SLJIT_SP, private_srcw[i], base_reg, stackptr); @@ -3204,7 +3341,7 @@ while (cc < ccend) SLJIT_ASSERT(shared_srcw[i] != 0); if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, shared_srcw[i]); + delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, (sljit_s32)shared_srcw[i]); if (from_sp || type == recurse_swap_global) delayed_mem_copy_move(&status, SLJIT_SP, shared_srcw[i], base_reg, stackptr); @@ -3224,7 +3361,7 @@ while (cc < ccend) SLJIT_ASSERT(kept_shared_srcw[i] != 0); if (!from_sp) - delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, kept_shared_srcw[i]); + delayed_mem_copy_move(&status, base_reg, stackptr, SLJIT_SP, (sljit_s32)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); @@ -3380,7 +3517,7 @@ 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) +static SLJIT_INLINE void allocate_stack(compiler_common *common, sljit_s32 size) { /* May destroy all locals and registers except TMP2. */ DEFINE_COMPILER; @@ -3401,7 +3538,7 @@ OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL1, TMP1, 0); add_stub(common, CMP(SLJIT_LESS, STACK_TOP, 0, STACK_LIMIT, 0)); } -static SLJIT_INLINE void free_stack(compiler_common *common, int size) +static SLJIT_INLINE void free_stack(compiler_common *common, sljit_s32 size) { DEFINE_COMPILER; @@ -3827,9 +3964,12 @@ oc = TABLE_GET(c, common->fcc, c); SLJIT_ASSERT(c != oc); bit = c ^ oc; + +#ifndef EBCDIC /* Optimized for English alphabet. */ if (c <= 127 && bit == 0x20) return (0 << 8) | 0x20; +#endif /* Since c != oc, they must have at least 1 bit difference. */ if (!is_powerof2(bit)) @@ -5433,8 +5573,7 @@ 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); +sljit_emit_op2_shift(compiler, SLJIT_ADD | SLJIT_SHL_IMM | SLJIT_SRC2_UNDEFINED, TMP1, 0, TMP1, 0, TMP2, 0, UCD_BLOCK_SHIFT); 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); @@ -5473,16 +5612,14 @@ 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); +sljit_emit_op2_shift(compiler, SLJIT_ADD | SLJIT_SHL_IMM | SLJIT_SRC2_UNDEFINED, TMP1, 0, TMP1, 0, TMP2, 0, UCD_BLOCK_SHIFT); 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). */ +/* TMP2 is multiplied by 12. Same as (TMP2 + (TMP2 << 1)) << 2. */ 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); +sljit_emit_op2_shift(compiler, SLJIT_ADD | SLJIT_SHL_IMM | SLJIT_SRC2_UNDEFINED, TMP2, 0, TMP2, 0, TMP2, 0, 1); +OP1(SLJIT_MOV_U8, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 2); OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0); } @@ -5807,7 +5944,7 @@ while (TRUE) { case OP_CHARI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHAR: last = FALSE; cc++; @@ -5844,7 +5981,7 @@ while (TRUE) case OP_MINPLUSI: case OP_POSPLUSI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_PLUS: case OP_MINPLUS: case OP_POSPLUS: @@ -5853,7 +5990,7 @@ while (TRUE) case OP_EXACTI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_EXACT: repeat = GET2(cc, 1); last = FALSE; @@ -5864,7 +6001,7 @@ while (TRUE) case OP_MINQUERYI: case OP_POSQUERYI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_QUERY: case OP_MINQUERY: case OP_POSQUERY: @@ -5996,7 +6133,7 @@ while (TRUE) case OP_NOT: case OP_NOTI: cc++; - /* Fall through. */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOT_DIGIT: case OP_NOT_WHITESPACE: case OP_NOT_WORDCHAR: @@ -6079,7 +6216,7 @@ while (TRUE) case OP_CRMINQUERY: case OP_CRPOSQUERY: last = FALSE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRSTAR: case OP_CRMINSTAR: case OP_CRPOSSTAR: @@ -6751,7 +6888,7 @@ if (JIT_HAS_FAST_FORWARD_CHAR_SIMD && (common->nltype == NLTYPE_FIXED || common- 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 + else { fast_forward_char_simd(common, common->newline, common->newline, 0); @@ -7435,10 +7572,22 @@ 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); +#ifdef EBCDIC +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_LF); +OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_VT); +OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_FF); +OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_CR); +OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_NEL); +#else +OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, CHAR_LF); +OP2U(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR - CHAR_LF); OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_NEL - CHAR_LF); +#endif #if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 #if PCRE2_CODE_UNIT_WIDTH == 8 if (common->utf) @@ -7446,7 +7595,7 @@ 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); + OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x2029 - CHAR_LF); #if PCRE2_CODE_UNIT_WIDTH == 8 } #endif @@ -7462,11 +7611,11 @@ DEFINE_COMPILER; sljit_emit_op_dst(compiler, SLJIT_FAST_ENTER, RETURN_ADDR, 0); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x09); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_HT); OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x20); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_SPACE); OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0xa0); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_NBSP); #if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 #if PCRE2_CODE_UNIT_WIDTH == 8 if (common->utf) @@ -7478,7 +7627,7 @@ if (common->utf) 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); + 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); @@ -7501,10 +7650,22 @@ 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); +#ifdef EBCDIC +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_LF); +OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_VT); +OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_FF); +OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_CR); +OP_FLAGS(SLJIT_OR, TMP2, 0, SLJIT_EQUAL); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_NEL); +#else +OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, CHAR_LF); +OP2U(SLJIT_SUB | SLJIT_SET_LESS_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR - CHAR_LF); OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_LESS_EQUAL); -OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); +OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, CHAR_NEL - CHAR_LF); +#endif #if defined SUPPORT_UNICODE || PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 #if PCRE2_CODE_UNIT_WIDTH == 8 if (common->utf) @@ -7512,7 +7673,7 @@ 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); + OP2U(SLJIT_SUB | SLJIT_SET_Z, TMP1, 0, SLJIT_IMM, 0x2029 - CHAR_LF); #if PCRE2_CODE_UNIT_WIDTH == 8 } #endif @@ -8447,11 +8608,18 @@ DEFINE_COMPILER; backtrack_common *backtrack; recurse_entry *entry = common->entries; recurse_entry *prev = NULL; +PCRE2_SPTR end; sljit_sw start = GET(cc, 1); +sljit_uw arg_size; PCRE2_SPTR start_cc; BOOL needs_control_head; -PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL); +end = cc + 1 + LINK_SIZE; + +while (*end == OP_CREF) + end += 1 + IMM2_SIZE; + +PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, end); /* Inlining simple patterns. */ if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack) @@ -8459,12 +8627,15 @@ if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head 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; + return end; } +cc += 1 + LINK_SIZE; +arg_size = (sljit_uw)IN_UCHARS(end - cc); while (entry != NULL) { - if (entry->start == start) + if (entry->start == start && entry->arg_size == arg_size + && (arg_size == 0 || memcmp(cc, entry->arg_start, arg_size) == 0)) break; prev = entry; entry = entry->next; @@ -8474,13 +8645,15 @@ if (entry == NULL) { entry = sljit_alloc_memory(compiler, sizeof(recurse_entry)); if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) - return NULL; + return end; entry->next = NULL; entry->entry_label = NULL; entry->backtrack_label = NULL; entry->entry_calls = NULL; entry->backtrack_calls = NULL; entry->start = start; + entry->arg_start = cc; + entry->arg_size = arg_size; if (prev != NULL) prev->next = entry; @@ -8497,7 +8670,7 @@ else /* 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; +return end; } static sljit_s32 SLJIT_FUNC do_callout_jit(struct jit_arguments *arguments, pcre2_callout_block *callout_block, PCRE2_SPTR *jit_ovector) @@ -8567,7 +8740,7 @@ unsigned int callout_length = (*cc == OP_CALLOUT) sljit_sw value1; sljit_sw value2; sljit_sw value3; -sljit_uw callout_arg_size = (common->re->top_bracket + 1) * 2 * SSIZE_OF(sw); +sljit_s32 callout_arg_size = (common->re->top_bracket + 1) * 2 * SSIZE_OF(sw); /* top_bracket is uint16 so maximum is 1MiB */ PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL); @@ -8660,7 +8833,7 @@ if (*cc == OP_REVERSE) else { SLJIT_ASSERT(*cc == OP_VREVERSE); - PUSH_BACKTRACK(sizeof(vreverse_backtrack), cc, NULL); + PUSH_BACKTRACK(sizeof(vreverse_backtrack), cc, cc + 1 + 2 * IMM2_SIZE); reverse_failed = &backtrack->own_backtracks; lmin = GET2(cc, 1); @@ -9304,7 +9477,7 @@ if (common->capture_last_ptr != 0) OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0); stacksize++; } -if (common->optimized_cbracket[offset >> 1] == 0) +if (!is_optimized_cbracket(common, offset >> 1)) { OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); @@ -9478,7 +9651,7 @@ 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) + if (!is_optimized_cbracket(common, offset)) { private_data_ptr = OVECTOR_PRIV(offset); offset <<= 1; @@ -9659,7 +9832,7 @@ if (opcode == OP_ONCE) else if (opcode == OP_CBRA || opcode == OP_SCBRA) { /* Saving the previous values. */ - if (common->optimized_cbracket[offset >> 1] != 0) + if (is_optimized_cbracket(common, offset >> 1)) { SLJIT_ASSERT(private_data_ptr == OVECTOR(offset)); allocate_stack(common, 2); @@ -9896,6 +10069,8 @@ if (opcode == OP_COND || opcode == OP_SCOND) assert->common.cc = matchingpath; BACKTRACK_AS(bracket_backtrack)->u.assert = assert; matchingpath = compile_assert_matchingpath(common, matchingpath, assert, TRUE); + if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) + return NULL; } } @@ -9936,7 +10111,7 @@ if (offset != 0) { if (common->capture_last_ptr != 0) stacksize++; - if (common->optimized_cbracket[offset >> 1] == 0) + if (!is_optimized_cbracket(common, offset >> 1)) stacksize += 2; } if (has_alternatives && opcode != OP_ONCE) @@ -9980,14 +10155,14 @@ if (has_alternatives) 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)); + BACKTRACK_AS(bracket_backtrack)->matching_mov_addr = sljit_emit_op_addr(compiler, SLJIT_MOV_ADDR, 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) +if (offset != 0 && is_optimized_cbracket(common, offset >> 1)) { SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0)); OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1), STR_PTR, 0); @@ -10149,7 +10324,7 @@ switch(opcode) 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); + SLJIT_ASSERT(!is_optimized_cbracket(common, offset)); cbraprivptr = OVECTOR_PRIV(offset); offset <<= 1; ccbegin = cc + 1 + LINK_SIZE + IMM2_SIZE; @@ -11331,7 +11506,7 @@ static SLJIT_INLINE PCRE2_SPTR compile_close_matchingpath(compiler_common *commo { DEFINE_COMPILER; int offset = GET2(cc, 1); -BOOL optimized_cbracket = common->optimized_cbracket[offset] != 0; +BOOL optimized_cbracket = is_optimized_cbracket(common, offset); /* Data will be discarded anyway... */ if (common->currententry != NULL) @@ -12202,7 +12377,7 @@ if (offset != 0) { if (common->capture_last_ptr != 0) { - SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0); + SLJIT_ASSERT(!is_optimized_cbracket(common, offset >> 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), common->capture_last_ptr, TMP1, 0); @@ -12211,7 +12386,7 @@ if (offset != 0) 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) + else if (!is_optimized_cbracket(common, offset >> 1)) { OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); @@ -12393,7 +12568,7 @@ if (has_alternatives) { if (common->capture_last_ptr != 0) stacksize++; - if (common->optimized_cbracket[offset >> 1] == 0) + if (!is_optimized_cbracket(common, offset >> 1)) stacksize += 2; } if (opcode != OP_ONCE) @@ -12427,10 +12602,10 @@ if (has_alternatives) 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)); + mov_addr = sljit_emit_op_addr(compiler, SLJIT_MOV_ADDR, SLJIT_MEM1(STACK_TOP), STACK(stacksize)); } - if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0) + if (offset != 0 && ket == OP_KETRMAX && is_optimized_cbracket(common, offset >> 1)) { /* 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)); @@ -12492,7 +12667,7 @@ if (has_alternatives) if (offset != 0) { /* Using both tmp register is better for instruction scheduling. */ - if (common->optimized_cbracket[offset >> 1] != 0) + if (is_optimized_cbracket(common, offset >> 1)) { OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0)); OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1)); @@ -12670,6 +12845,8 @@ if (current->cc[1] > OP_ASSERTBACK_NOT) { /* Manual call of compile_bracket_matchingpath and compile_bracket_backtrackingpath. */ compile_bracket_matchingpath(common, current->cc, current); + if (SLJIT_UNLIKELY(sljit_get_compiler_error(common->compiler))) + return; compile_bracket_backtrackingpath(common, current->top); } else @@ -12679,6 +12856,8 @@ else backtrack.matchingpath = CURRENT_AS(braminzero_backtrack)->matchingpath; /* Manual call of compile_assert_matchingpath. */ compile_assert_matchingpath(common, current->cc, &backtrack, FALSE); + if (SLJIT_UNLIKELY(sljit_get_compiler_error(common->compiler))) + return; } SLJIT_ASSERT(!current->simple_backtracks && !current->own_backtracks); } @@ -13093,7 +13272,7 @@ while (1) 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)); + mov_addr = sljit_emit_op_addr(compiler, SLJIT_MOV_ADDR, SLJIT_MEM1(STACK_TOP), STACK(1)); else OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, alt_count); } @@ -13360,7 +13539,8 @@ if (private_data_length > ~(sljit_uw)0 / sizeof(sljit_s32)) 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); +common->cbracket_bitset_length = ((re->top_bracket + 1) + (sljit_u32)7) & ~(sljit_u32)7; +total_length = common->cbracket_bitset_length << 1; if (~(sljit_uw)0 - private_data_length < total_length) return PCRE2_ERROR_NOMEMORY; @@ -13370,12 +13550,13 @@ 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; +common->optimized_cbrackets = ((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); +memset(common->optimized_cbrackets, 0, common->cbracket_bitset_length); #else -memset(common->optimized_cbracket, 1, re->top_bracket + 1); +memset(common->optimized_cbrackets, 0xff, common->cbracket_bitset_length); #endif +common->cbracket_bitset = common->optimized_cbrackets + common->cbracket_bitset_length; SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET); #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2 @@ -13440,7 +13621,7 @@ if (common->start_ptr == 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); + memset(common->optimized_cbrackets, 0, common->cbracket_bitset_length); 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); @@ -13591,6 +13772,34 @@ common->accept_label = LABEL(); if (common->accept != NULL) set_jumps(common->accept, common->accept_label); +/* 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 (common->has_set_som && + (common->re->extra_options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) == 0) + { + 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)); + } + OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)); + + /* (ovector[0] < jit_arguments->str)? */ + OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP2, 0, TMP1, 0); + /* Unconditionally set R0 (aka TMP1), in between the comparison that needs to + use TMP1, but before the jump. */ + OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_BAD_BACKSLASH_K); + add_jump(compiler, &common->abort, JUMP(SLJIT_LESS)); + /* (ovector[0] > STR_PTR)? NB. ovector[1] hasn't yet been set to STR_PTR. */ + add_jump(compiler, &common->abort, CMP(SLJIT_GREATER, TMP2, 0, STR_PTR, 0)); + } + /* This means we have a match. Update the ovector. */ copy_ovector(common, re->top_bracket + 1); common->quit_label = common->abort_label = LABEL(); @@ -14099,7 +14308,7 @@ return 0; #define INCLUDED_FROM_PCRE2_JIT_COMPILE -#include "pcre2_jit_match.c" -#include "pcre2_jit_misc.c" +#include "pcre2_jit_match_inc.h" +#include "pcre2_jit_misc_inc.h" /* End of pcre2_jit_compile.c */ diff --git a/src/pcre2_jit_match.c b/src/pcre2_jit_match.c deleted file mode 100644 index 8867f76..0000000 --- a/src/pcre2_jit_match.c +++ /dev/null @@ -1,200 +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 - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2023 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. ------------------------------------------------------------------------------ -*/ - -#ifndef INCLUDED_FROM_PCRE2_JIT_COMPILE -#error This file must be included from pcre2_jit_compile.c. -#endif - -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#include -#endif /* __has_feature(memory_sanitizer) */ -#endif /* defined(__has_feature) */ - -#ifdef SUPPORT_JIT - -static SLJIT_NOINLINE int jit_machine_stack_exec(jit_arguments *arguments, jit_function executable_func) -{ -sljit_u8 local_space[MACHINE_STACK_SIZE]; -struct sljit_stack local_stack; - -local_stack.min_start = local_space; -local_stack.start = local_space; -local_stack.end = local_space + MACHINE_STACK_SIZE; -local_stack.top = local_space + MACHINE_STACK_SIZE; -arguments->stack = &local_stack; -return executable_func(arguments); -} - -#endif - - -/************************************************* -* Do a JIT pattern match * -*************************************************/ - -/* This function runs a JIT pattern match. - -Arguments: - code points to the compiled expression - subject points to the subject string - length length of subject string (may contain binary zeros) - start_offset where to start in the subject string - options option bits - match_data points to a match_data block - mcontext points to a match context - -Returns: > 0 => success; value is the number of ovector pairs filled - = 0 => success, but ovector is not big enough - -1 => failed to match (PCRE2_ERROR_NOMATCH) - < -1 => some kind of unexpected problem -*/ - -PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION -pcre2_jit_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, - PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data, - pcre2_match_context *mcontext) -{ -#ifndef SUPPORT_JIT - -(void)code; -(void)subject; -(void)length; -(void)start_offset; -(void)options; -(void)match_data; -(void)mcontext; -return PCRE2_ERROR_JIT_BADOPTION; - -#else /* SUPPORT_JIT */ - -pcre2_real_code *re = (pcre2_real_code *)code; -executable_functions *functions = (executable_functions *)re->executable_jit; -pcre2_jit_stack *jit_stack; -uint32_t oveccount = match_data->oveccount; -uint32_t max_oveccount; -union { - void *executable_func; - jit_function call_executable_func; -} convert_executable_func; -jit_arguments arguments; -int rc; -int index = 0; - -if ((options & PCRE2_PARTIAL_HARD) != 0) - index = 2; -else if ((options & PCRE2_PARTIAL_SOFT) != 0) - index = 1; - -if (functions == NULL || functions->executable_funcs[index] == NULL) - return PCRE2_ERROR_JIT_BADOPTION; - -/* Sanity checks should be handled by pcre2_match. */ -arguments.str = subject + start_offset; -arguments.begin = subject; -arguments.end = subject + length; -arguments.match_data = match_data; -arguments.startchar_ptr = subject; -arguments.mark_ptr = NULL; -arguments.options = options; - -if (mcontext != NULL) - { - arguments.callout = mcontext->callout; - arguments.callout_data = mcontext->callout_data; - arguments.offset_limit = mcontext->offset_limit; - arguments.limit_match = (mcontext->match_limit < re->limit_match)? - mcontext->match_limit : re->limit_match; - if (mcontext->jit_callback != NULL) - jit_stack = mcontext->jit_callback(mcontext->jit_callback_data); - else - jit_stack = (pcre2_jit_stack *)mcontext->jit_callback_data; - } -else - { - arguments.callout = NULL; - arguments.callout_data = NULL; - arguments.offset_limit = PCRE2_UNSET; - arguments.limit_match = (MATCH_LIMIT < re->limit_match)? - MATCH_LIMIT : re->limit_match; - jit_stack = NULL; - } - - -max_oveccount = functions->top_bracket; -if (oveccount > max_oveccount) - oveccount = max_oveccount; -arguments.oveccount = oveccount << 1; - - -convert_executable_func.executable_func = functions->executable_funcs[index]; -if (jit_stack != NULL) - { - arguments.stack = (struct sljit_stack *)(jit_stack->stack); - rc = convert_executable_func.call_executable_func(&arguments); - } -else - rc = jit_machine_stack_exec(&arguments, convert_executable_func.call_executable_func); - -if (rc > (int)oveccount) - rc = 0; -match_data->code = re; -match_data->subject = (rc >= 0 || rc == PCRE2_ERROR_PARTIAL)? subject : NULL; -match_data->subject_length = length; -match_data->rc = rc; -match_data->startchar = arguments.startchar_ptr - subject; -match_data->leftchar = 0; -match_data->rightchar = 0; -match_data->mark = arguments.mark_ptr; -match_data->matchedby = PCRE2_MATCHEDBY_JIT; - -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -if (rc > 0) - __msan_unpoison(match_data->ovector, 2 * rc * sizeof(match_data->ovector[0])); -#endif /* __has_feature(memory_sanitizer) */ -#endif /* defined(__has_feature) */ - -return match_data->rc; - -#endif /* SUPPORT_JIT */ -} - -/* End of pcre2_jit_match.c */ diff --git a/src/pcre2_jit_match_inc.h b/src/pcre2_jit_match_inc.h new file mode 100644 index 0000000..32d4c8a --- /dev/null +++ b/src/pcre2_jit_match_inc.h @@ -0,0 +1,202 @@ +/************************************************* +* 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-2023 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. +----------------------------------------------------------------------------- +*/ + +#ifndef INCLUDED_FROM_PCRE2_JIT_COMPILE +#error This file must be included from pcre2_jit_compile.c. +#endif + +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) +#include +#endif /* __has_feature(memory_sanitizer) */ +#endif /* defined(__has_feature) */ + +#ifdef SUPPORT_JIT + +static SLJIT_NOINLINE int jit_machine_stack_exec(jit_arguments *arguments, jit_function executable_func) +{ +sljit_u8 local_space[MACHINE_STACK_SIZE]; +struct sljit_stack local_stack; + +local_stack.min_start = local_space; +local_stack.start = local_space; +local_stack.end = local_space + MACHINE_STACK_SIZE; +local_stack.top = local_space + MACHINE_STACK_SIZE; +arguments->stack = &local_stack; +return executable_func(arguments); +} + +#endif + + +/************************************************* +* Do a JIT pattern match * +*************************************************/ + +/* This function runs a JIT pattern match. + +Arguments: + code points to the compiled expression + subject points to the subject string + length length of subject string (may contain binary zeros) + start_offset where to start in the subject string + options option bits + match_data points to a match_data block + mcontext points to a match context + +Returns: > 0 => success; value is the number of ovector pairs filled + = 0 => success, but ovector is not big enough + -1 => failed to match (PCRE2_ERROR_NOMATCH) + < -1 => some kind of unexpected problem +*/ + +PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION +pcre2_jit_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, + PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data, + pcre2_match_context *mcontext) +{ +#ifndef SUPPORT_JIT + +(void)code; +(void)subject; +(void)length; +(void)start_offset; +(void)options; +(void)mcontext; +return match_data->rc = PCRE2_ERROR_JIT_BADOPTION; + +#else /* SUPPORT_JIT */ + +pcre2_real_code *re = (pcre2_real_code *)code; +executable_functions *functions = (executable_functions *)re->executable_jit; +pcre2_jit_stack *jit_stack; +uint32_t oveccount = match_data->oveccount; +uint32_t max_oveccount; +union { + void *executable_func; + jit_function call_executable_func; +} convert_executable_func; +jit_arguments arguments; +int rc; +int index = 0; + +if ((options & PCRE2_PARTIAL_HARD) != 0) + index = 2; +else if ((options & PCRE2_PARTIAL_SOFT) != 0) + index = 1; + +if (functions == NULL || functions->executable_funcs[index] == NULL) + return match_data->rc = PCRE2_ERROR_JIT_BADOPTION; + +/* Sanity checks should be handled by pcre2_match. */ +arguments.str = subject + start_offset; +arguments.begin = subject; +arguments.end = subject + length; +arguments.match_data = match_data; +arguments.startchar_ptr = subject; +arguments.mark_ptr = NULL; +arguments.options = options; + +if (mcontext != NULL) + { + arguments.callout = mcontext->callout; + arguments.callout_data = mcontext->callout_data; + arguments.offset_limit = mcontext->offset_limit; + arguments.limit_match = (mcontext->match_limit < re->limit_match)? + mcontext->match_limit : re->limit_match; + if (mcontext->jit_callback != NULL) + jit_stack = mcontext->jit_callback(mcontext->jit_callback_data); + else + jit_stack = (pcre2_jit_stack *)mcontext->jit_callback_data; + } +else + { + arguments.callout = NULL; + arguments.callout_data = NULL; + arguments.offset_limit = PCRE2_UNSET; + arguments.limit_match = (MATCH_LIMIT < re->limit_match)? + MATCH_LIMIT : re->limit_match; + jit_stack = NULL; + } + + +max_oveccount = functions->top_bracket; +if (oveccount > max_oveccount) + oveccount = max_oveccount; +arguments.oveccount = oveccount << 1; + + +convert_executable_func.executable_func = functions->executable_funcs[index]; +if (jit_stack != NULL) + { + arguments.stack = (struct sljit_stack *)(jit_stack->stack); + rc = convert_executable_func.call_executable_func(&arguments); + } +else + rc = jit_machine_stack_exec(&arguments, convert_executable_func.call_executable_func); + +if (rc > (int)oveccount) + rc = 0; +match_data->code = re; +match_data->subject = + (rc >= 0 || rc == PCRE2_ERROR_NOMATCH || rc == PCRE2_ERROR_PARTIAL)? subject : NULL; +match_data->subject_length = length; +match_data->start_offset = start_offset; +match_data->rc = rc; +match_data->startchar = arguments.startchar_ptr - subject; +match_data->leftchar = 0; +match_data->rightchar = 0; +match_data->mark = arguments.mark_ptr; +match_data->matchedby = PCRE2_MATCHEDBY_JIT; +match_data->options = options; + +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) +if (rc > 0) + __msan_unpoison(match_data->ovector, 2 * rc * sizeof(match_data->ovector[0])); +#endif /* __has_feature(memory_sanitizer) */ +#endif /* defined(__has_feature) */ + +return match_data->rc; + +#endif /* SUPPORT_JIT */ +} + +/* End of pcre2_jit_match_inc.h */ diff --git a/src/pcre2_jit_misc.c b/src/pcre2_jit_misc.c deleted file mode 100644 index c3abc0b..0000000 --- a/src/pcre2_jit_misc.c +++ /dev/null @@ -1,234 +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 - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016 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. ------------------------------------------------------------------------------ -*/ - - -#ifndef INCLUDED_FROM_PCRE2_JIT_COMPILE -#error This file must be included from pcre2_jit_compile.c. -#endif - - - -/************************************************* -* Free JIT read-only data * -*************************************************/ - -void -PRIV(jit_free_rodata)(void *current, void *allocator_data) -{ -#ifndef SUPPORT_JIT -(void)current; -(void)allocator_data; -#else /* SUPPORT_JIT */ -void *next; - -SLJIT_UNUSED_ARG(allocator_data); - -while (current != NULL) - { - next = *(void**)current; - SLJIT_FREE(current, allocator_data); - current = next; - } - -#endif /* SUPPORT_JIT */ -} - -/************************************************* -* Free JIT compiled code * -*************************************************/ - -void -PRIV(jit_free)(void *executable_jit, pcre2_memctl *memctl) -{ -#ifndef SUPPORT_JIT -(void)executable_jit; -(void)memctl; -#else /* SUPPORT_JIT */ - -executable_functions *functions = (executable_functions *)executable_jit; -void *allocator_data = memctl; -int i; - -for (i = 0; i < JIT_NUMBER_OF_COMPILE_MODES; i++) - { - if (functions->executable_funcs[i] != NULL) - sljit_free_code(functions->executable_funcs[i], NULL); - PRIV(jit_free_rodata)(functions->read_only_data_heads[i], allocator_data); - } - -SLJIT_FREE(functions, allocator_data); - -#endif /* SUPPORT_JIT */ -} - - -/************************************************* -* Free unused JIT memory * -*************************************************/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_jit_free_unused_memory(pcre2_general_context *gcontext) -{ -#ifndef SUPPORT_JIT -(void)gcontext; /* Suppress warning */ -#else /* SUPPORT_JIT */ -SLJIT_UNUSED_ARG(gcontext); -#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) -sljit_free_unused_memory_exec(); -#endif /* SLJIT_EXECUTABLE_ALLOCATOR */ -#endif /* SUPPORT_JIT */ -} - - - -/************************************************* -* Allocate a JIT stack * -*************************************************/ - -PCRE2_EXP_DEFN pcre2_jit_stack * PCRE2_CALL_CONVENTION -pcre2_jit_stack_create(size_t startsize, size_t maxsize, - pcre2_general_context *gcontext) -{ -#ifndef SUPPORT_JIT - -(void)gcontext; -(void)startsize; -(void)maxsize; -return NULL; - -#else /* SUPPORT_JIT */ - -pcre2_jit_stack *jit_stack; - -if (startsize == 0 || maxsize == 0 || maxsize > SIZE_MAX - STACK_GROWTH_RATE) - return NULL; -if (startsize > maxsize) - startsize = maxsize; -startsize = (startsize + STACK_GROWTH_RATE - 1) & (size_t)(~(STACK_GROWTH_RATE - 1)); -maxsize = (maxsize + STACK_GROWTH_RATE - 1) & (size_t)(~(STACK_GROWTH_RATE - 1)); - -jit_stack = PRIV(memctl_malloc)(sizeof(pcre2_real_jit_stack), (pcre2_memctl *)gcontext); -if (jit_stack == NULL) return NULL; -jit_stack->stack = sljit_allocate_stack(startsize, maxsize, &jit_stack->memctl); -if (jit_stack->stack == NULL) - { - jit_stack->memctl.free(jit_stack, jit_stack->memctl.memory_data); - return NULL; - } -return jit_stack; - -#endif -} - - -/************************************************* -* Assign a JIT stack to a pattern * -*************************************************/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_jit_stack_assign(pcre2_match_context *mcontext, pcre2_jit_callback callback, - void *callback_data) -{ -#ifndef SUPPORT_JIT -(void)mcontext; -(void)callback; -(void)callback_data; -#else /* SUPPORT_JIT */ - -if (mcontext == NULL) return; -mcontext->jit_callback = callback; -mcontext->jit_callback_data = callback_data; - -#endif /* SUPPORT_JIT */ -} - - -/************************************************* -* Free a JIT stack * -*************************************************/ - -PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION -pcre2_jit_stack_free(pcre2_jit_stack *jit_stack) -{ -#ifndef SUPPORT_JIT -(void)jit_stack; -#else /* SUPPORT_JIT */ -if (jit_stack != NULL) - { - sljit_free_stack((struct sljit_stack *)(jit_stack->stack), &jit_stack->memctl); - jit_stack->memctl.free(jit_stack, jit_stack->memctl.memory_data); - } -#endif /* SUPPORT_JIT */ -} - - -/************************************************* -* Get target CPU type * -*************************************************/ - -const char* -PRIV(jit_get_target)(void) -{ -#ifndef SUPPORT_JIT -return "JIT is not supported"; -#else /* SUPPORT_JIT */ -return sljit_get_platform_name(); -#endif /* SUPPORT_JIT */ -} - - -/************************************************* -* Get size of JIT code * -*************************************************/ - -size_t -PRIV(jit_get_size)(void *executable_jit) -{ -#ifndef SUPPORT_JIT -(void)executable_jit; -return 0; -#else /* SUPPORT_JIT */ -sljit_uw *executable_sizes = ((executable_functions *)executable_jit)->executable_sizes; -SLJIT_COMPILE_ASSERT(JIT_NUMBER_OF_COMPILE_MODES == 3, number_of_compile_modes_changed); -return executable_sizes[0] + executable_sizes[1] + executable_sizes[2]; -#endif -} - -/* End of pcre2_jit_misc.c */ diff --git a/src/pcre2_jit_misc_inc.h b/src/pcre2_jit_misc_inc.h new file mode 100644 index 0000000..0225fc6 --- /dev/null +++ b/src/pcre2_jit_misc_inc.h @@ -0,0 +1,234 @@ +/************************************************* +* 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 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. +----------------------------------------------------------------------------- +*/ + + +#ifndef INCLUDED_FROM_PCRE2_JIT_COMPILE +#error This file must be included from pcre2_jit_compile.c. +#endif + + + +/************************************************* +* Free JIT read-only data * +*************************************************/ + +void +PRIV(jit_free_rodata)(void *current, void *allocator_data) +{ +#ifndef SUPPORT_JIT +(void)current; +(void)allocator_data; +#else /* SUPPORT_JIT */ +void *next; + +SLJIT_UNUSED_ARG(allocator_data); + +while (current != NULL) + { + next = *(void**)current; + SLJIT_FREE(current, allocator_data); + current = next; + } + +#endif /* SUPPORT_JIT */ +} + +/************************************************* +* Free JIT compiled code * +*************************************************/ + +void +PRIV(jit_free)(void *executable_jit, pcre2_memctl *memctl) +{ +#ifndef SUPPORT_JIT +(void)executable_jit; +(void)memctl; +#else /* SUPPORT_JIT */ + +executable_functions *functions = (executable_functions *)executable_jit; +void *allocator_data = memctl; +int i; + +for (i = 0; i < JIT_NUMBER_OF_COMPILE_MODES; i++) + { + if (functions->executable_funcs[i] != NULL) + sljit_free_code(functions->executable_funcs[i], NULL); + PRIV(jit_free_rodata)(functions->read_only_data_heads[i], allocator_data); + } + +SLJIT_FREE(functions, allocator_data); + +#endif /* SUPPORT_JIT */ +} + + +/************************************************* +* Free unused JIT memory * +*************************************************/ + +PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION +pcre2_jit_free_unused_memory(pcre2_general_context *gcontext) +{ +#ifndef SUPPORT_JIT +(void)gcontext; /* Suppress warning */ +#else /* SUPPORT_JIT */ +SLJIT_UNUSED_ARG(gcontext); +#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) +sljit_free_unused_memory_exec(); +#endif /* SLJIT_EXECUTABLE_ALLOCATOR */ +#endif /* SUPPORT_JIT */ +} + + + +/************************************************* +* Allocate a JIT stack * +*************************************************/ + +PCRE2_EXP_DEFN pcre2_jit_stack * PCRE2_CALL_CONVENTION +pcre2_jit_stack_create(size_t startsize, size_t maxsize, + pcre2_general_context *gcontext) +{ +#ifndef SUPPORT_JIT + +(void)gcontext; +(void)startsize; +(void)maxsize; +return NULL; + +#else /* SUPPORT_JIT */ + +pcre2_jit_stack *jit_stack; + +if (startsize == 0 || maxsize == 0 || maxsize > SIZE_MAX - STACK_GROWTH_RATE) + return NULL; +if (startsize > maxsize) + startsize = maxsize; +startsize = (startsize + STACK_GROWTH_RATE - 1) & (size_t)(~(STACK_GROWTH_RATE - 1)); +maxsize = (maxsize + STACK_GROWTH_RATE - 1) & (size_t)(~(STACK_GROWTH_RATE - 1)); + +jit_stack = PRIV(memctl_malloc)(sizeof(pcre2_real_jit_stack), (pcre2_memctl *)gcontext); +if (jit_stack == NULL) return NULL; +jit_stack->stack = sljit_allocate_stack(startsize, maxsize, &jit_stack->memctl); +if (jit_stack->stack == NULL) + { + jit_stack->memctl.free(jit_stack, jit_stack->memctl.memory_data); + return NULL; + } +return jit_stack; + +#endif +} + + +/************************************************* +* Assign a JIT stack to a pattern * +*************************************************/ + +PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION +pcre2_jit_stack_assign(pcre2_match_context *mcontext, pcre2_jit_callback callback, + void *callback_data) +{ +#ifndef SUPPORT_JIT +(void)mcontext; +(void)callback; +(void)callback_data; +#else /* SUPPORT_JIT */ + +if (mcontext == NULL) return; +mcontext->jit_callback = callback; +mcontext->jit_callback_data = callback_data; + +#endif /* SUPPORT_JIT */ +} + + +/************************************************* +* Free a JIT stack * +*************************************************/ + +PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION +pcre2_jit_stack_free(pcre2_jit_stack *jit_stack) +{ +#ifndef SUPPORT_JIT +(void)jit_stack; +#else /* SUPPORT_JIT */ +if (jit_stack != NULL) + { + sljit_free_stack((struct sljit_stack *)(jit_stack->stack), &jit_stack->memctl); + jit_stack->memctl.free(jit_stack, jit_stack->memctl.memory_data); + } +#endif /* SUPPORT_JIT */ +} + + +/************************************************* +* Get target CPU type * +*************************************************/ + +const char* +PRIV(jit_get_target)(void) +{ +#ifndef SUPPORT_JIT +return "JIT is not supported"; +#else /* SUPPORT_JIT */ +return sljit_get_platform_name(); +#endif /* SUPPORT_JIT */ +} + + +/************************************************* +* Get size of JIT code * +*************************************************/ + +size_t +PRIV(jit_get_size)(void *executable_jit) +{ +#ifndef SUPPORT_JIT +(void)executable_jit; +return 0; +#else /* SUPPORT_JIT */ +sljit_uw *executable_sizes = ((executable_functions *)executable_jit)->executable_sizes; +SLJIT_COMPILE_ASSERT(JIT_NUMBER_OF_COMPILE_MODES == 3, number_of_compile_modes_changed); +return executable_sizes[0] + executable_sizes[1] + executable_sizes[2]; +#endif +} + +/* End of pcre2_jit_misc_inc.h */ diff --git a/src/pcre2_jit_neon_inc.h b/src/pcre2_jit_neon_inc.h deleted file mode 100644 index 1389a16..0000000 --- a/src/pcre2_jit_neon_inc.h +++ /dev/null @@ -1,354 +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 and Sebastian Pop - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2019 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. ------------------------------------------------------------------------------ -*/ - -# if defined(FFCS) -# if defined(FF_UTF) -# define FF_FUN ffcs_utf -# else -# define FF_FUN ffcs -# endif - -# elif defined(FFCS_2) -# if defined(FF_UTF) -# define FF_FUN ffcs_2_utf -# else -# define FF_FUN ffcs_2 -# endif - -# elif defined(FFCS_MASK) -# if defined(FF_UTF) -# define FF_FUN ffcs_mask_utf -# else -# define FF_FUN ffcs_mask -# endif - -# elif defined(FFCPS_0) -# if defined (FF_UTF) -# define FF_FUN ffcps_0_utf -# else -# define FF_FUN ffcps_0 -# endif - -# elif defined (FFCPS_1) -# if defined (FF_UTF) -# define FF_FUN ffcps_1_utf -# else -# define FF_FUN ffcps_1 -# endif - -# elif defined (FFCPS_DEFAULT) -# if defined (FF_UTF) -# define FF_FUN ffcps_default_utf -# else -# define FF_FUN ffcps_default -# endif -# endif - -#if (defined(__GNUC__) && defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__ ) \ - || (defined(__clang__) \ - && ((__clang_major__ == 3 && __clang_minor__ >= 3) || (__clang_major__ > 3))) -__attribute__((no_sanitize_address)) -#endif -static sljit_u8* SLJIT_FUNC FF_FUN(sljit_u8 *str_end, sljit_u8 **str_ptr, sljit_uw offs1, sljit_uw offs2, sljit_uw chars) -#undef FF_FUN -{ -quad_word qw; -int_char ic; - -SLJIT_UNUSED_ARG(offs1); -SLJIT_UNUSED_ARG(offs2); - -ic.x = chars; - -#if defined(FFCS) -sljit_u8 c1 = ic.c.c1; -vect_t vc1 = VDUPQ(c1); - -#elif defined(FFCS_2) -sljit_u8 c1 = ic.c.c1; -vect_t vc1 = VDUPQ(c1); -sljit_u8 c2 = ic.c.c2; -vect_t vc2 = VDUPQ(c2); - -#elif defined(FFCS_MASK) -sljit_u8 c1 = ic.c.c1; -vect_t vc1 = VDUPQ(c1); -sljit_u8 mask = ic.c.c2; -vect_t vmask = VDUPQ(mask); -#endif - -#if defined(FFCPS) -compare_type compare1_type = compare_match1; -compare_type compare2_type = compare_match1; -vect_t cmp1a, cmp1b, cmp2a, cmp2b; -const sljit_u32 diff = IN_UCHARS(offs1 - offs2); -PCRE2_UCHAR char1a = ic.c.c1; -PCRE2_UCHAR char2a = ic.c.c3; - -# ifdef FFCPS_CHAR1A2A -cmp1a = VDUPQ(char1a); -cmp2a = VDUPQ(char2a); -cmp1b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */ -cmp2b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */ -# else -PCRE2_UCHAR char1b = ic.c.c2; -PCRE2_UCHAR char2b = ic.c.c4; -if (char1a == char1b) - { - cmp1a = VDUPQ(char1a); - cmp1b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */ - } -else - { - sljit_u32 bit1 = char1a ^ char1b; - if (is_powerof2(bit1)) - { - compare1_type = compare_match1i; - cmp1a = VDUPQ(char1a | bit1); - cmp1b = VDUPQ(bit1); - } - else - { - compare1_type = compare_match2; - cmp1a = VDUPQ(char1a); - cmp1b = VDUPQ(char1b); - } - } - -if (char2a == char2b) - { - cmp2a = VDUPQ(char2a); - cmp2b = VDUPQ(0); /* to avoid errors on older compilers -Werror=maybe-uninitialized */ - } -else - { - sljit_u32 bit2 = char2a ^ char2b; - if (is_powerof2(bit2)) - { - compare2_type = compare_match1i; - cmp2a = VDUPQ(char2a | bit2); - cmp2b = VDUPQ(bit2); - } - else - { - compare2_type = compare_match2; - cmp2a = VDUPQ(char2a); - cmp2b = VDUPQ(char2b); - } - } -# endif - -*str_ptr += IN_UCHARS(offs1); -#endif - -#if PCRE2_CODE_UNIT_WIDTH != 8 -vect_t char_mask = VDUPQ(0xff); -#endif - -#if defined(FF_UTF) -restart:; -#endif - -#if defined(FFCPS) -if (*str_ptr >= str_end) - return NULL; -sljit_u8 *p1 = *str_ptr - diff; -#endif -sljit_s32 align_offset = ((uint64_t)*str_ptr & 0xf); -*str_ptr = (sljit_u8 *) ((uint64_t)*str_ptr & ~0xf); -vect_t data = VLD1Q(*str_ptr); -#if PCRE2_CODE_UNIT_WIDTH != 8 -data = VANDQ(data, char_mask); -#endif - -#if defined(FFCS) -vect_t eq = VCEQQ(data, vc1); - -#elif defined(FFCS_2) -vect_t eq1 = VCEQQ(data, vc1); -vect_t eq2 = VCEQQ(data, vc2); -vect_t eq = VORRQ(eq1, eq2); - -#elif defined(FFCS_MASK) -vect_t eq = VORRQ(data, vmask); -eq = VCEQQ(eq, vc1); - -#elif defined(FFCPS) -# if defined(FFCPS_DIFF1) -vect_t prev_data = data; -# endif - -vect_t data2; -if (p1 < *str_ptr) - { - data2 = VLD1Q(*str_ptr - diff); -#if PCRE2_CODE_UNIT_WIDTH != 8 - data2 = VANDQ(data2, char_mask); -#endif - } -else - data2 = shift_left_n_lanes(data, offs1 - offs2); - -if (compare1_type == compare_match1) - data = VCEQQ(data, cmp1a); -else - data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b); - -if (compare2_type == compare_match1) - data2 = VCEQQ(data2, cmp2a); -else - data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b); - -vect_t eq = VANDQ(data, data2); -#endif - -VST1Q(qw.mem, eq); -/* Ignore matches before the first STR_PTR. */ -if (align_offset < 8) - { - qw.dw[0] >>= align_offset * 8; - if (qw.dw[0]) - { - *str_ptr += align_offset + __builtin_ctzll(qw.dw[0]) / 8; - goto match; - } - if (qw.dw[1]) - { - *str_ptr += 8 + __builtin_ctzll(qw.dw[1]) / 8; - goto match; - } - } -else - { - qw.dw[1] >>= (align_offset - 8) * 8; - if (qw.dw[1]) - { - *str_ptr += align_offset + __builtin_ctzll(qw.dw[1]) / 8; - goto match; - } - } -*str_ptr += 16; - -while (*str_ptr < str_end) - { - vect_t orig_data = VLD1Q(*str_ptr); -#if PCRE2_CODE_UNIT_WIDTH != 8 - orig_data = VANDQ(orig_data, char_mask); -#endif - data = orig_data; - -#if defined(FFCS) - eq = VCEQQ(data, vc1); - -#elif defined(FFCS_2) - eq1 = VCEQQ(data, vc1); - eq2 = VCEQQ(data, vc2); - eq = VORRQ(eq1, eq2); - -#elif defined(FFCS_MASK) - eq = VORRQ(data, vmask); - eq = VCEQQ(eq, vc1); -#endif - -#if defined(FFCPS) -# if defined (FFCPS_DIFF1) - data2 = VEXTQ(prev_data, data, VECTOR_FACTOR - 1); -# else - data2 = VLD1Q(*str_ptr - diff); -# if PCRE2_CODE_UNIT_WIDTH != 8 - data2 = VANDQ(data2, char_mask); -# endif -# endif - -# ifdef FFCPS_CHAR1A2A - data = VCEQQ(data, cmp1a); - data2 = VCEQQ(data2, cmp2a); -# else - if (compare1_type == compare_match1) - data = VCEQQ(data, cmp1a); - else - data = fast_forward_char_pair_compare(compare1_type, data, cmp1a, cmp1b); - if (compare2_type == compare_match1) - data2 = VCEQQ(data2, cmp2a); - else - data2 = fast_forward_char_pair_compare(compare2_type, data2, cmp2a, cmp2b); -# endif - - eq = VANDQ(data, data2); -#endif - - VST1Q(qw.mem, eq); - if (qw.dw[0]) - *str_ptr += __builtin_ctzll(qw.dw[0]) / 8; - else if (qw.dw[1]) - *str_ptr += 8 + __builtin_ctzll(qw.dw[1]) / 8; - else { - *str_ptr += 16; -#if defined (FFCPS_DIFF1) - prev_data = orig_data; -#endif - continue; - } - -match:; - if (*str_ptr >= str_end) - /* Failed match. */ - return NULL; - -#if defined(FF_UTF) - if (utf_continue((PCRE2_SPTR)*str_ptr - offs1)) - { - /* Not a match. */ - *str_ptr += IN_UCHARS(1); - goto restart; - } -#endif - - /* Match. */ -#if defined (FFCPS) - *str_ptr -= IN_UCHARS(offs1); -#endif - return *str_ptr; - } - -/* Failed match. */ -return NULL; -} diff --git a/src/pcre2_jit_simd_inc.h b/src/pcre2_jit_simd_inc.h index 66e93cd..0a24cda 100644 --- a/src/pcre2_jit_simd_inc.h +++ b/src/pcre2_jit_simd_inc.h @@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #if !(defined SUPPORT_VALGRIND) #if ((defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ + || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ || (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) \ || (defined SLJIT_CONFIG_LOONGARCH_64 && SLJIT_CONFIG_LOONGARCH_64)) @@ -100,7 +101,7 @@ return CMP(SLJIT_NOT_EQUAL, reg, 0, SLJIT_IMM, 0xdc00); } #endif -#endif /* SLJIT_CONFIG_X86 || SLJIT_CONFIG_S390X */ +#endif /* SLJIT_CONFIG_X86 || SLJIT_CONFIG_ARM_64 || SLJIT_CONFIG_S390X || SLJIT_CONFIG_LOONGARCH_64 */ #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) @@ -228,7 +229,14 @@ switch (step) } } +/* The AVX2 code path is currently disabled. #define JIT_HAS_FAST_FORWARD_CHAR_SIMD (sljit_has_cpu_feature(SLJIT_HAS_SIMD)) +*/ +#if defined(SLJIT_CONFIG_X86_64) && SLJIT_CONFIG_X86_64 +#define JIT_HAS_FAST_FORWARD_CHAR_SIMD 1 +#else +#define JIT_HAS_FAST_FORWARD_CHAR_SIMD (sljit_has_cpu_feature(SLJIT_HAS_FPU)) +#endif static void fast_forward_char_simd(compiler_common *common, PCRE2_UCHAR char1, PCRE2_UCHAR char2, sljit_s32 offset) { @@ -246,10 +254,10 @@ struct sljit_jump *quit; struct sljit_jump *partial_quit[2]; vector_compare_type compare_type = vector_compare_match1; sljit_s32 tmp1_reg_ind = sljit_get_register_index(SLJIT_GP_REGISTER, TMP1); -sljit_s32 data_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR0); -sljit_s32 cmp1_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR1); -sljit_s32 cmp2_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR2); -sljit_s32 tmp_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR3); +sljit_s32 data_ind = sljit_get_register_index(reg_type, SLJIT_VR0); +sljit_s32 cmp1_ind = sljit_get_register_index(reg_type, SLJIT_VR1); +sljit_s32 cmp2_ind = sljit_get_register_index(reg_type, SLJIT_VR2); +sljit_s32 tmp_ind = sljit_get_register_index(reg_type, SLJIT_VR3); sljit_u32 bit = 0; int i; @@ -365,7 +373,14 @@ if (common->utf && offset > 0) #endif } +/* The AVX2 code path is currently disabled. #define JIT_HAS_FAST_REQUESTED_CHAR_SIMD (sljit_has_cpu_feature(SLJIT_HAS_SIMD)) +*/ +#if defined(SLJIT_CONFIG_X86_64) && SLJIT_CONFIG_X86_64 +#define JIT_HAS_FAST_REQUESTED_CHAR_SIMD 1 +#else +#define JIT_HAS_FAST_REQUESTED_CHAR_SIMD (sljit_has_cpu_feature(SLJIT_HAS_FPU)) +#endif static jump_list *fast_requested_char_simd(compiler_common *common, PCRE2_UCHAR char1, PCRE2_UCHAR char2) { @@ -380,10 +395,10 @@ struct sljit_jump *quit; jump_list *not_found = NULL; vector_compare_type compare_type = vector_compare_match1; sljit_s32 tmp1_reg_ind = sljit_get_register_index(SLJIT_GP_REGISTER, TMP1); -sljit_s32 data_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR0); -sljit_s32 cmp1_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR1); -sljit_s32 cmp2_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR2); -sljit_s32 tmp_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR3); +sljit_s32 data_ind = sljit_get_register_index(reg_type, SLJIT_VR0); +sljit_s32 cmp1_ind = sljit_get_register_index(reg_type, SLJIT_VR1); +sljit_s32 cmp2_ind = sljit_get_register_index(reg_type, SLJIT_VR2); +sljit_s32 tmp_ind = sljit_get_register_index(reg_type, SLJIT_VR3); sljit_u32 bit = 0; int i; @@ -471,7 +486,14 @@ return not_found; #ifndef _WIN64 +/* The AVX2 code path is currently disabled. #define JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD (sljit_has_cpu_feature(SLJIT_HAS_SIMD)) +*/ +#if defined(SLJIT_CONFIG_X86_64) && SLJIT_CONFIG_X86_64 +#define JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD 1 +#else +#define JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD (sljit_has_cpu_feature(SLJIT_HAS_FPU)) +#endif static void fast_forward_char_pair_simd(compiler_common *common, sljit_s32 offs1, PCRE2_UCHAR char1a, PCRE2_UCHAR char1b, sljit_s32 offs2, PCRE2_UCHAR char2a, PCRE2_UCHAR char2b) @@ -488,14 +510,14 @@ sljit_u32 bit1 = 0; sljit_u32 bit2 = 0; sljit_u32 diff = IN_UCHARS(offs1 - offs2); sljit_s32 tmp1_reg_ind = sljit_get_register_index(SLJIT_GP_REGISTER, TMP1); -sljit_s32 data1_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR0); -sljit_s32 data2_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR1); -sljit_s32 cmp1a_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR2); -sljit_s32 cmp2a_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR3); -sljit_s32 cmp1b_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR4); -sljit_s32 cmp2b_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR5); -sljit_s32 tmp1_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR6); -sljit_s32 tmp2_ind = sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_TMP_DEST_VREG); +sljit_s32 data1_ind = sljit_get_register_index(reg_type, SLJIT_VR0); +sljit_s32 data2_ind = sljit_get_register_index(reg_type, SLJIT_VR1); +sljit_s32 cmp1a_ind = sljit_get_register_index(reg_type, SLJIT_VR2); +sljit_s32 cmp2a_ind = sljit_get_register_index(reg_type, SLJIT_VR3); +sljit_s32 cmp1b_ind = sljit_get_register_index(reg_type, SLJIT_VR4); +sljit_s32 cmp2b_ind = sljit_get_register_index(reg_type, SLJIT_VR5); +sljit_s32 tmp1_ind = sljit_get_register_index(reg_type, SLJIT_VR6); +sljit_s32 tmp2_ind = sljit_get_register_index(reg_type, SLJIT_TMP_DEST_VREG); struct sljit_label *start; #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 struct sljit_label *restart; @@ -692,8 +714,8 @@ sljit_emit_simd_mov(compiler, reg_type, SLJIT_VR1, SLJIT_MEM1(STR_PTR), -(sljit_ for (i = 0; i < 4; i++) { - fast_forward_char_pair_sse2_compare(compiler, compare1_type, reg_type, i, data1_ind, cmp1a_ind, cmp1b_ind, tmp2_ind); - fast_forward_char_pair_sse2_compare(compiler, compare2_type, reg_type, i, data2_ind, cmp2a_ind, cmp2b_ind, tmp1_ind); + fast_forward_char_pair_sse2_compare(compiler, compare1_type, reg_type, i, data1_ind, cmp1a_ind, cmp1b_ind, tmp1_ind); + fast_forward_char_pair_sse2_compare(compiler, compare2_type, reg_type, i, data2_ind, cmp2a_ind, cmp2b_ind, tmp2_ind); } sljit_emit_simd_op2(compiler, SLJIT_SIMD_OP2_AND | reg_type, SLJIT_VR0, SLJIT_VR0, SLJIT_VR1, 0); @@ -744,286 +766,284 @@ if (common->match_end_ptr != 0) #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64 && (defined __ARM_NEON || defined __ARM_NEON__)) -#include - -typedef union { - unsigned int x; - struct { unsigned char c1, c2, c3, c4; } c; -} int_char; - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -static SLJIT_INLINE int utf_continue(PCRE2_SPTR s) -{ #if PCRE2_CODE_UNIT_WIDTH == 8 -return (*s & 0xc0) == 0x80; +#define PCRE2_REPLICATE_TYPE (SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_8) #elif PCRE2_CODE_UNIT_WIDTH == 16 -return (*s & 0xfc00) == 0xdc00; +#define PCRE2_REPLICATE_TYPE (SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_16) +#elif PCRE2_CODE_UNIT_WIDTH == 32 +#define PCRE2_REPLICATE_TYPE (SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32) #else -#error "Unknown code width" +#error "Unsupported unit width" #endif -} -#endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 */ +#define JIT_HAS_FAST_FORWARD_CHAR_SIMD 1 + +static void fast_forward_char_pair_sse2_compare(struct sljit_compiler *compiler, vector_compare_type compare_type, + int step, sljit_u32 dst_ind, sljit_u32 cmp1_ind, sljit_u32 cmp2_ind, sljit_u32 tmp_ind) +{ +sljit_u32 instruction; #if PCRE2_CODE_UNIT_WIDTH == 8 -# define VECTOR_FACTOR 16 -# define vect_t uint8x16_t -# define VLD1Q(X) vld1q_u8((sljit_u8 *)(X)) -# define VCEQQ vceqq_u8 -# define VORRQ vorrq_u8 -# define VST1Q vst1q_u8 -# define VDUPQ vdupq_n_u8 -# define VEXTQ vextq_u8 -# define VANDQ vandq_u8 -typedef union { - uint8_t mem[16]; - uint64_t dw[2]; -} quad_word; +sljit_u32 size = 0 << 22; #elif PCRE2_CODE_UNIT_WIDTH == 16 -# define VECTOR_FACTOR 8 -# define vect_t uint16x8_t -# define VLD1Q(X) vld1q_u16((sljit_u16 *)(X)) -# define VCEQQ vceqq_u16 -# define VORRQ vorrq_u16 -# define VST1Q vst1q_u16 -# define VDUPQ vdupq_n_u16 -# define VEXTQ vextq_u16 -# define VANDQ vandq_u16 -typedef union { - uint16_t mem[8]; - uint64_t dw[2]; -} quad_word; +sljit_u32 size = 1 << 22; +#elif PCRE2_CODE_UNIT_WIDTH == 32 +sljit_u32 size = 2 << 22; #else -# define VECTOR_FACTOR 4 -# define vect_t uint32x4_t -# define VLD1Q(X) vld1q_u32((sljit_u32 *)(X)) -# define VCEQQ vceqq_u32 -# define VORRQ vorrq_u32 -# define VST1Q vst1q_u32 -# define VDUPQ vdupq_n_u32 -# define VEXTQ vextq_u32 -# define VANDQ vandq_u32 -typedef union { - uint32_t mem[4]; - uint64_t dw[2]; -} quad_word; +#error "Unsupported unit width" #endif -#define FFCS -#include "pcre2_jit_neon_inc.h" -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -# define FF_UTF -# include "pcre2_jit_neon_inc.h" -# undef FF_UTF -#endif -#undef FFCS +SLJIT_ASSERT(step >= 0 && step <= 2); -#define FFCS_2 -#include "pcre2_jit_neon_inc.h" -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -# define FF_UTF -# include "pcre2_jit_neon_inc.h" -# undef FF_UTF -#endif -#undef FFCS_2 +if (step == 1) + { + /* CMEQ */ + instruction = 0x6e208c00 | size | (cmp1_ind << 16) | (dst_ind << 5) | dst_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + return; + } -#define FFCS_MASK -#include "pcre2_jit_neon_inc.h" -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -# define FF_UTF -# include "pcre2_jit_neon_inc.h" -# undef FF_UTF -#endif -#undef FFCS_MASK +if (compare_type != vector_compare_match2) + { + if (step == 0 && compare_type == vector_compare_match1i) + { + /* ORR */ + instruction = 0x4ea01c00 | (cmp2_ind << 16) | (dst_ind << 5) | dst_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + } + return; + } -#define JIT_HAS_FAST_FORWARD_CHAR_SIMD 1 +switch (step) + { + case 0: + /* CMEQ */ + instruction = 0x6e208c00 | size | (cmp2_ind << 16) | (dst_ind << 5) | tmp_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + return; + + case 2: + /* ORR */ + instruction = 0x4ea01c00 | (tmp_ind << 16) | (dst_ind << 5) | dst_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + return; + } +} static void fast_forward_char_simd(compiler_common *common, PCRE2_UCHAR char1, PCRE2_UCHAR char2, sljit_s32 offset) { DEFINE_COMPILER; -int_char ic; -struct sljit_jump *partial_quit, *quit; -/* Save temporary registers. */ -SLJIT_ASSERT(common->locals_size >= 2 * (int)sizeof(sljit_sw)); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL0, STR_PTR, 0); -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL1, TMP3, 0); +sljit_u32 instruction; +struct sljit_label *start; +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 +struct sljit_label *restart; +#endif +struct sljit_jump *quit; +struct sljit_jump *partial_quit[2]; +vector_compare_type compare_type = vector_compare_match1; +sljit_u32 data_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR0); +sljit_u32 cmp1_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR1); +sljit_u32 cmp2_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR2); +sljit_u32 tmp_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR3); +sljit_u32 bit = 0; +int i; -/* Prepare function arguments */ -OP1(SLJIT_MOV, SLJIT_R0, 0, STR_END, 0); -GET_LOCAL_BASE(SLJIT_R1, 0, LOCAL0); -OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, offset); +SLJIT_UNUSED_ARG(offset); -if (char1 == char2) +if (char1 != char2) { - ic.c.c1 = char1; - ic.c.c2 = char2; - OP1(SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, ic.x); + bit = char1 ^ char2; + compare_type = vector_compare_match1i; -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf && offset > 0) - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs_utf)); - else - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs)); -#else - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs)); -#endif - } -else - { - PCRE2_UCHAR mask = char1 ^ char2; - if (is_powerof2(mask)) + if (!is_powerof2(bit)) { - ic.c.c1 = char1 | mask; - ic.c.c2 = mask; - OP1(SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, ic.x); - -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf && offset > 0) - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs_mask_utf)); - else - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs_mask)); -#else - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs_mask)); -#endif + bit = 0; + compare_type = vector_compare_match2; } - else - { - ic.c.c1 = char1; - ic.c.c2 = char2; - OP1(SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, ic.x); + } + +partial_quit[0] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); +if (common->mode == PCRE2_JIT_COMPLETE) + add_jump(compiler, &common->failed_match, partial_quit[0]); + +/* First part (unaligned start) */ +if (char1 != char2) + sljit_emit_op1(compiler, SLJIT_MOV, TMP2, 0, SLJIT_IMM, bit != 0 ? bit : char2); +sljit_emit_op1(compiler, SLJIT_MOV, TMP1, 0, SLJIT_IMM, char1 | bit); + +if (char1 != char2) + sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR2, TMP2, 0); +sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR1, TMP1, 0); + +OP1(SLJIT_MOV, TMP2, 0, STR_PTR, 0); #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf && offset > 0) - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs_2_utf)); - else - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs_2)); -#else - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcs_2)); +restart = LABEL(); #endif - } - } -/* Restore registers. */ -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); -OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(SLJIT_SP), LOCAL1); -/* Check return value. */ -partial_quit = CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); +OP2(SLJIT_AND, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, ~(sljit_sw)0xf); +OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xf); + +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128 | SLJIT_SIMD_MEM_ALIGNED_128, SLJIT_VR0, SLJIT_MEM1(STR_PTR), 0); + +for (i = 0; i < 3; i++) + fast_forward_char_pair_sse2_compare(compiler, compare_type, i, data_ind, cmp1_ind, cmp2_ind, tmp_ind); + +/* SHRN */ +instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; +sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + +sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, SLJIT_VR0, 0, TMP1, 0); + +OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 2); +OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, TMP2, 0); +OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, TMP2, 0); + +quit = CMP(SLJIT_NOT_ZERO, TMP1, 0, SLJIT_IMM, 0); + +/* Second part (aligned) */ +start = LABEL(); + +OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 16); + +partial_quit[1] = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); if (common->mode == PCRE2_JIT_COMPLETE) - add_jump(compiler, &common->failed_match, partial_quit); + add_jump(compiler, &common->failed_match, partial_quit[1]); + +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128 | SLJIT_SIMD_MEM_ALIGNED_128, SLJIT_VR0, SLJIT_MEM1(STR_PTR), 0); +for (i = 0; i < 3; i++) + fast_forward_char_pair_sse2_compare(compiler, compare_type, i, data_ind, cmp1_ind, cmp2_ind, tmp_ind); + +/* SHRN */ +instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; +sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + +sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, SLJIT_VR0, 0, TMP1, 0); +CMPTO(SLJIT_ZERO, TMP1, 0, SLJIT_IMM, 0, start); + +JUMPHERE(quit); + +sljit_emit_op1(compiler, SLJIT_CTZ, TMP1, 0, TMP1, 0); +OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 2); +OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); -/* Fast forward STR_PTR to the result of memchr. */ -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0); if (common->mode != PCRE2_JIT_COMPLETE) { - quit = CMP(SLJIT_NOT_ZERO, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); - JUMPHERE(partial_quit); + JUMPHERE(partial_quit[0]); + JUMPHERE(partial_quit[1]); OP2U(SLJIT_SUB | SLJIT_SET_GREATER, STR_PTR, 0, STR_END, 0); SELECT(SLJIT_GREATER, STR_PTR, STR_END, 0, STR_PTR); - JUMPHERE(quit); } -} - -typedef enum { - compare_match1, - compare_match1i, - compare_match2, -} compare_type; +else + add_jump(compiler, &common->failed_match, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); -static inline vect_t fast_forward_char_pair_compare(compare_type ctype, vect_t dst, vect_t cmp1, vect_t cmp2) -{ -if (ctype == compare_match2) +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 +if (common->utf && offset > 0) { - vect_t tmp = dst; - dst = VCEQQ(dst, cmp1); - tmp = VCEQQ(tmp, cmp2); - dst = VORRQ(dst, tmp); - return dst; - } + SLJIT_ASSERT(common->mode == PCRE2_JIT_COMPLETE); -if (ctype == compare_match1i) - dst = VORRQ(dst, cmp2); -dst = VCEQQ(dst, cmp1); -return dst; -} + OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-offset)); -static SLJIT_INLINE sljit_u32 max_fast_forward_char_pair_offset(void) -{ -#if PCRE2_CODE_UNIT_WIDTH == 8 -return 15; -#elif PCRE2_CODE_UNIT_WIDTH == 16 -return 7; -#elif PCRE2_CODE_UNIT_WIDTH == 32 -return 3; -#else -#error "Unsupported unit width" + quit = jump_if_utf_char_start(compiler, TMP1); + + OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); + add_jump(compiler, &common->failed_match, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); + OP1(SLJIT_MOV, TMP2, 0, STR_PTR, 0); + JUMPTO(SLJIT_JUMP, restart); + + JUMPHERE(quit); + } #endif } -/* ARM doesn't have a shift left across lanes. */ -static SLJIT_INLINE vect_t shift_left_n_lanes(vect_t a, sljit_u8 n) +#define JIT_HAS_FAST_REQUESTED_CHAR_SIMD 1 + +static jump_list *fast_requested_char_simd(compiler_common *common, PCRE2_UCHAR char1, PCRE2_UCHAR char2) { -vect_t zero = VDUPQ(0); -SLJIT_ASSERT(0 < n && n < VECTOR_FACTOR); -/* VEXTQ takes an immediate as last argument. */ -#define C(X) case X: return VEXTQ(zero, a, VECTOR_FACTOR - X); -switch (n) +DEFINE_COMPILER; +sljit_u32 instruction; +struct sljit_label *start; +struct sljit_jump *quit; +jump_list *not_found = NULL; +vector_compare_type compare_type = vector_compare_match1; +sljit_u32 data_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR0); +sljit_u32 cmp1_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR1); +sljit_u32 cmp2_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR2); +sljit_u32 tmp_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR3); +sljit_u32 bit = 0; +int i; + +if (char1 != char2) { - C(1); C(2); C(3); -#if PCRE2_CODE_UNIT_WIDTH != 32 - C(4); C(5); C(6); C(7); -# if PCRE2_CODE_UNIT_WIDTH != 16 - C(8); C(9); C(10); C(11); C(12); C(13); C(14); C(15); -# endif -#endif - default: - /* Based on the ASSERT(0 < n && n < VECTOR_FACTOR) above, this won't - happen. The return is still here for compilers to not warn. */ - return a; + bit = char1 ^ char2; + compare_type = vector_compare_match1i; + + if (!is_powerof2(bit)) + { + bit = 0; + compare_type = vector_compare_match2; + } } -} -#define FFCPS -#define FFCPS_DIFF1 -#define FFCPS_CHAR1A2A +add_jump(compiler, ¬_found, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, STR_END, 0)); -#define FFCPS_0 -#include "pcre2_jit_neon_inc.h" -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -# define FF_UTF -# include "pcre2_jit_neon_inc.h" -# undef FF_UTF -#endif -#undef FFCPS_0 +/* First part (unaligned start) */ -#undef FFCPS_CHAR1A2A +if (char1 != char2) + sljit_emit_op1(compiler, SLJIT_MOV, TMP3, 0, SLJIT_IMM, bit != 0 ? bit : char2); +sljit_emit_op1(compiler, SLJIT_MOV, TMP2, 0, SLJIT_IMM, char1 | bit); -#define FFCPS_1 -#include "pcre2_jit_neon_inc.h" -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -# define FF_UTF -# include "pcre2_jit_neon_inc.h" -# undef FF_UTF -#endif -#undef FFCPS_1 +if (char1 != char2) + sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR2, TMP3, 0); +sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR1, TMP2, 0); -#undef FFCPS_DIFF1 +OP2(SLJIT_AND, TMP3, 0, TMP1, 0, SLJIT_IMM, ~(sljit_sw)0xf); +OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf); -#define FFCPS_DEFAULT -#include "pcre2_jit_neon_inc.h" -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 -# define FF_UTF -# include "pcre2_jit_neon_inc.h" -# undef FF_UTF -#endif -#undef FFCPS +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128 | SLJIT_SIMD_MEM_ALIGNED_128, SLJIT_VR0, SLJIT_MEM1(TMP3), 0); + +for (i = 0; i < 3; i++) + fast_forward_char_pair_sse2_compare(compiler, compare_type, i, data_ind, cmp1_ind, cmp2_ind, tmp_ind); + +/* SHRN */ +instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; +sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + +sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, SLJIT_VR0, 0, TMP1, 0); + +OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 2); +OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, TMP2, 0); +OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, TMP2, 0); + +quit = CMP(SLJIT_NOT_ZERO, TMP1, 0, SLJIT_IMM, 0); + +/* Second part (aligned) */ +start = LABEL(); + +OP2(SLJIT_ADD, TMP3, 0, TMP3, 0, SLJIT_IMM, 16); + +add_jump(compiler, ¬_found, CMP(SLJIT_GREATER_EQUAL, TMP3, 0, STR_END, 0)); + +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128 | SLJIT_SIMD_MEM_ALIGNED_128, SLJIT_VR0, SLJIT_MEM1(TMP3), 0); + +for (i = 0; i < 3; i++) + fast_forward_char_pair_sse2_compare(compiler, compare_type, i, data_ind, cmp1_ind, cmp2_ind, tmp_ind); + +/* SHRN */ +instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; +sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + +sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, SLJIT_VR0, 0, TMP1, 0); +CMPTO(SLJIT_ZERO, TMP1, 0, SLJIT_IMM, 0, start); + +JUMPHERE(quit); + +sljit_emit_op1(compiler, SLJIT_CTZ, TMP1, 0, TMP1, 0); +OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 2); +OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP3, 0); +add_jump(compiler, ¬_found, CMP(SLJIT_GREATER_EQUAL, TMP1, 0, STR_END, 0)); + +return not_found; +} #define JIT_HAS_FAST_FORWARD_CHAR_PAIR_SIMD 1 @@ -1031,81 +1051,214 @@ static void fast_forward_char_pair_simd(compiler_common *common, sljit_s32 offs1 PCRE2_UCHAR char1a, PCRE2_UCHAR char1b, sljit_s32 offs2, PCRE2_UCHAR char2a, PCRE2_UCHAR char2b) { DEFINE_COMPILER; +sljit_u32 instruction; +vector_compare_type compare1_type = vector_compare_match1; +vector_compare_type compare2_type = vector_compare_match1; +sljit_u32 bit1 = 0; +sljit_u32 bit2 = 0; sljit_u32 diff = IN_UCHARS(offs1 - offs2); -struct sljit_jump *partial_quit; -int_char ic; -SLJIT_ASSERT(common->mode == PCRE2_JIT_COMPLETE && offs1 > offs2); -SLJIT_ASSERT(diff <= IN_UCHARS(max_fast_forward_char_pair_offset())); -SLJIT_ASSERT(compiler->scratches == 5); +sljit_u32 data1_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR0); +sljit_u32 data2_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR1); +sljit_u32 cmp1a_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR2); +sljit_u32 cmp2a_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR3); +sljit_u32 cmp1b_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR4); +sljit_u32 cmp2b_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR5); +sljit_u32 tmp1_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR6); +sljit_u32 tmp2_ind = (sljit_u32)sljit_get_register_index(SLJIT_SIMD_REG_128, SLJIT_VR7); +struct sljit_label *start; +#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 +struct sljit_label *restart; +#endif +struct sljit_jump *jump[2]; +int i; -/* Save temporary register STR_PTR. */ -OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL0, STR_PTR, 0); +SLJIT_ASSERT(common->mode == PCRE2_JIT_COMPLETE && offs1 > offs2 && offs2 >= 0); +SLJIT_ASSERT(diff <= (unsigned)IN_UCHARS(max_fast_forward_char_pair_offset())); -/* Prepare arguments for the function call. */ -if (common->match_end_ptr == 0) - OP1(SLJIT_MOV, SLJIT_R0, 0, STR_END, 0); -else +if (char1a != char1b) { - OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), common->match_end_ptr); - OP2(SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, IN_UCHARS(offs1 + 1)); + bit1 = char1a ^ char1b; + compare1_type = vector_compare_match1i; - OP2U(SLJIT_SUB | SLJIT_SET_LESS, STR_END, 0, SLJIT_R0, 0); - SELECT(SLJIT_LESS, SLJIT_R0, STR_END, 0, SLJIT_R0); + if (!is_powerof2(bit1)) + { + bit1 = 0; + compare1_type = vector_compare_match2; + } } -GET_LOCAL_BASE(SLJIT_R1, 0, LOCAL0); -OP1(SLJIT_MOV_S32, SLJIT_R2, 0, SLJIT_IMM, offs1); -OP1(SLJIT_MOV_S32, SLJIT_R3, 0, SLJIT_IMM, offs2); -ic.c.c1 = char1a; -ic.c.c2 = char1b; -ic.c.c3 = char2a; -ic.c.c4 = char2b; -OP1(SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_IMM, ic.x); +if (char2a != char2b) + { + bit2 = char2a ^ char2b; + compare2_type = vector_compare_match1i; + + if (!is_powerof2(bit2)) + { + bit2 = 0; + compare2_type = vector_compare_match2; + } + } + +/* Initialize. */ +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_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(offs1 + 1)); + + OP2U(SLJIT_SUB | SLJIT_SET_LESS, TMP1, 0, STR_END, 0); + SELECT(SLJIT_LESS, STR_END, TMP1, 0, STR_END); + } + +OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offs1)); +add_jump(compiler, &common->failed_match, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); + +sljit_emit_op1(compiler, SLJIT_MOV, TMP1, 0, SLJIT_IMM, char1a | bit1); +sljit_emit_op1(compiler, SLJIT_MOV, TMP2, 0, SLJIT_IMM, char2a | bit2); +sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR2, TMP1, 0); +sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR3, TMP2, 0); + +if (char1a != char1b) + sljit_emit_op1(compiler, SLJIT_MOV, TMP1, 0, SLJIT_IMM, bit1 != 0 ? bit1 : char1b); + +if (char2a != char2b) + sljit_emit_op1(compiler, SLJIT_MOV, TMP2, 0, SLJIT_IMM, bit2 != 0 ? bit2 : char2b); + +if (char1a != char1b) + sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR4, TMP1, 0); + +if (char2a != char2b) + sljit_emit_simd_replicate(compiler, PCRE2_REPLICATE_TYPE, SLJIT_VR5, TMP2, 0); -if (diff == 1) { - if (char1a == char1b && char2a == char2b) { -#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcps_0_utf)); - else -#endif - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcps_0)); - } else { #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcps_1_utf)); - else +restart = LABEL(); #endif - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcps_1)); + +OP2(SLJIT_SUB, TMP1, 0, STR_PTR, 0, SLJIT_IMM, diff); +OP1(SLJIT_MOV, TMP2, 0, STR_PTR, 0); +OP2(SLJIT_AND, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, ~(sljit_sw)0xf); + +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128 | SLJIT_SIMD_MEM_ALIGNED_128, SLJIT_VR0, SLJIT_MEM1(STR_PTR), 0); + +jump[0] = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, STR_PTR, 0); + +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128, SLJIT_VR1, SLJIT_MEM1(STR_PTR), -(sljit_sw)diff); +jump[1] = JUMP(SLJIT_JUMP); + +JUMPHERE(jump[0]); + +if (diff >= 8) + { + /* MOV (element) */ + instruction = 0x6e180400 | (data1_ind << 5) | data2_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + + if (diff > 8) + { + /* SHL */ + instruction = 0x4f405400 | ((diff - 8) << 19) | (data2_ind << 5) | data2_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + } + } +else + { + /* MOV (element) */ + instruction = 0x6e180400 | (data1_ind << 5) | tmp1_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + + /* SHL */ + instruction = 0x4f405400 | (diff << 19) | (data1_ind << 5) | data2_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + + /* USHR */ + instruction = 0x6f400400 | (diff << 19) | (tmp1_ind << 5) | tmp1_ind; + sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + + sljit_emit_simd_op2(compiler, SLJIT_SIMD_OP2_OR | SLJIT_SIMD_REG_128, SLJIT_VR1, SLJIT_VR1, SLJIT_VR6, 0); + } + +JUMPHERE(jump[1]); + +OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xf); + +for (i = 0; i < 3; i++) + { + fast_forward_char_pair_sse2_compare(compiler, compare1_type, i, data1_ind, cmp1a_ind, cmp1b_ind, tmp1_ind); + fast_forward_char_pair_sse2_compare(compiler, compare2_type, i, data2_ind, cmp2a_ind, cmp2b_ind, tmp2_ind); + } + +sljit_emit_simd_op2(compiler, SLJIT_SIMD_OP2_AND | SLJIT_SIMD_REG_128, SLJIT_VR0, SLJIT_VR0, SLJIT_VR1, 0); + +/* SHRN */ +instruction = 0x0f0c8400 | (data1_ind << 5) | data1_ind; +sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + +sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, SLJIT_VR0, 0, TMP1, 0); + +/* Ignore matches before the first STR_PTR. */ +OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 2); +OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, TMP2, 0); +OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, TMP2, 0); + +jump[0] = CMP(SLJIT_NOT_ZERO, TMP1, 0, SLJIT_IMM, 0); + +/* Main loop. */ +start = LABEL(); + +OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 16); +add_jump(compiler, &common->failed_match, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); + +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128 | SLJIT_SIMD_MEM_ALIGNED_128, SLJIT_VR0, SLJIT_MEM1(STR_PTR), 0); +sljit_emit_simd_mov(compiler, SLJIT_SIMD_REG_128, SLJIT_VR1, SLJIT_MEM1(STR_PTR), -(sljit_sw)diff); + +for (i = 0; i < 3; i++) + { + fast_forward_char_pair_sse2_compare(compiler, compare1_type, i, data1_ind, cmp1a_ind, cmp1b_ind, tmp1_ind); + fast_forward_char_pair_sse2_compare(compiler, compare2_type, i, data2_ind, cmp2a_ind, cmp2b_ind, tmp2_ind); } -} else { + +sljit_emit_simd_op2(compiler, SLJIT_SIMD_OP2_AND | SLJIT_SIMD_REG_128, SLJIT_VR0, SLJIT_VR0, SLJIT_VR1, 0); + +/* SHRN */ +instruction = 0x0f0c8400 | (data1_ind << 5) | data1_ind; +sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); + +sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, SLJIT_VR0, 0, TMP1, 0); + +CMPTO(SLJIT_ZERO, TMP1, 0, SLJIT_IMM, 0, start); + +JUMPHERE(jump[0]); + +sljit_emit_op1(compiler, SLJIT_CTZ, TMP1, 0, TMP1, 0); +OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 2); +OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); + +add_jump(compiler, &common->failed_match, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); + #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 - if (common->utf) - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcps_default_utf)); - else -#endif - sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, W, W, W), - SLJIT_IMM, SLJIT_FUNC_ADDR(ffcps_default)); -} +if (common->utf) + { + OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-offs1)); + + jump[0] = jump_if_utf_char_start(compiler, TMP1); -/* Restore STR_PTR register. */ -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_SP), LOCAL0); + OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); + CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, restart); -/* Check return value. */ -partial_quit = CMP(SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0); -add_jump(compiler, &common->failed_match, partial_quit); + add_jump(compiler, &common->failed_match, JUMP(SLJIT_JUMP)); -/* Fast forward STR_PTR to the result of memchr. */ -OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0); + JUMPHERE(jump[0]); + } +#endif -JUMPHERE(partial_quit); +OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(offs1)); + +if (common->match_end_ptr != 0) + OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); } +#undef PCRE2_REPLICATE_TYPE + #endif /* SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64 */ #if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) @@ -1289,7 +1442,7 @@ if (char1 != char2) #else /* PCRE2_CODE_UNIT_WIDTH == 32 */ -for (int i = 0; i < 2; i++) +for (i = 0; i < 2; i++) { replicate_imm_vector(compiler, i, cmp1_ind, char1 | bit, TMP1); @@ -1483,7 +1636,7 @@ if (char1 != char2) #else /* PCRE2_CODE_UNIT_WIDTH == 32 */ -for (int i = 0; i < 2; i++) +for (i = 0; i < 2; i++) { replicate_imm_vector(compiler, i, cmp1_ind, char1 | bit, TMP3); @@ -1699,7 +1852,7 @@ if (char2a != char2b) #else /* PCRE2_CODE_UNIT_WIDTH == 32 */ -for (int i = 0; i < 2; i++) +for (i = 0; i < 2; i++) { replicate_imm_vector(compiler, i, cmp1a_ind, char1a | bit1, TMP1); @@ -1865,21 +2018,18 @@ typedef sljit_ins sljit_u32; #define IMM_UI2(imm) (((sljit_ins)(imm) << 10) & UI2_IMM_MASK) // LSX OPCODES: -#define VLD 0x2c000000 -#define VOR_V 0x71268000 -#define VAND_V 0x71260000 #define VBSLL_V 0x728e0000 #define VMSKLTZ_B 0x729c4000 #define VPICKVE2GR_WU 0x72f3e000 #if PCRE2_CODE_UNIT_WIDTH == 8 -#define VREPLGR2VR 0x729f0000 +#define VREPLGR2VR_X 0x729f0000 #define VSEQ 0x70000000 #elif PCRE2_CODE_UNIT_WIDTH == 16 -#define VREPLGR2VR 0x729f0400 +#define VREPLGR2VR_X 0x729f0400 #define VSEQ 0x70008000 #else -#define VREPLGR2VR 0x729f0800 +#define VREPLGR2VR_X 0x729f0800 #define VSEQ 0x70010000 #endif @@ -1956,14 +2106,14 @@ if (common->mode == PCRE2_JIT_COMPLETE) OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, char1 | bit); /* VREPLGR2VR.B/H/W vd, rj */ -push_inst(compiler, VREPLGR2VR | VD(cmp1_ind) | RJ_V(tmp1_reg_ind)); +push_inst(compiler, VREPLGR2VR_X | VD(cmp1_ind) | RJ_V(tmp1_reg_ind)); if (char1 != char2) { OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, bit != 0 ? bit : char2); /* VREPLGR2VR.B/H/W vd, rj */ - push_inst(compiler, VREPLGR2VR | VD(cmp2_ind) | RJ_V(tmp1_reg_ind)); + push_inst(compiler, VREPLGR2VR_X | VD(cmp2_ind) | RJ_V(tmp1_reg_ind)); } OP1(SLJIT_MOV, TMP2, 0, STR_PTR, 0); @@ -2086,14 +2236,14 @@ OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, char1 | bit); -/* VREPLGR2VR vd, rj */ -push_inst(compiler, VREPLGR2VR | VD(cmp1_ind) | RJ_V(tmp1_reg_ind)); +/* VREPLGR2VR.B/H/W vd, rj */ +push_inst(compiler, VREPLGR2VR_X | VD(cmp1_ind) | RJ_V(tmp1_reg_ind)); if (char1 != char2) { OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, bit != 0 ? bit : char2); - /* VREPLGR2VR vd, rj */ - push_inst(compiler, VREPLGR2VR | VD(cmp2_ind) | RJ_V(tmp1_reg_ind)); + /* VREPLGR2VR.B/H/W vd, rj */ + push_inst(compiler, VREPLGR2VR_X | VD(cmp2_ind) | RJ_V(tmp1_reg_ind)); } OP1(SLJIT_MOV, STR_PTR, 0, TMP2, 0); @@ -2213,13 +2363,13 @@ else } } -/* VREPLGR2VR vd, rj */ -push_inst(compiler, VREPLGR2VR | VD(cmp1a_ind) | RJ_V(tmp1_reg_ind)); +/* VREPLGR2VR.B/H/W vd, rj */ +push_inst(compiler, VREPLGR2VR_X | VD(cmp1a_ind) | RJ_V(tmp1_reg_ind)); if (char1a != char1b) { - /* VREPLGR2VR vd, rj */ - push_inst(compiler, VREPLGR2VR | VD(cmp1b_ind) | RJ_V(tmp2_reg_ind)); + /* VREPLGR2VR.B/H/W vd, rj */ + push_inst(compiler, VREPLGR2VR_X | VD(cmp1b_ind) | RJ_V(tmp2_reg_ind)); } if (char2a == char2b) @@ -2242,13 +2392,13 @@ else } } -/* VREPLGR2VR vd, rj */ -push_inst(compiler, VREPLGR2VR | VD(cmp2a_ind) | RJ_V(tmp1_reg_ind)); +/* VREPLGR2VR.B/H/W vd, rj */ +push_inst(compiler, VREPLGR2VR_X | VD(cmp2a_ind) | RJ_V(tmp1_reg_ind)); if (char2a != char2b) { - /* VREPLGR2VR vd, rj */ - push_inst(compiler, VREPLGR2VR | VD(cmp2b_ind) | RJ_V(tmp2_reg_ind)); + /* VREPLGR2VR.B/H/W vd, rj */ + push_inst(compiler, VREPLGR2VR_X | VD(cmp2b_ind) | RJ_V(tmp2_reg_ind)); } #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 diff --git a/src/pcre2_jit_test.c b/src/pcre2_jit_test.c index a7ade44..1fc44db 100644 --- a/src/pcre2_jit_test.c +++ b/src/pcre2_jit_test.c @@ -38,10 +38,14 @@ POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------------------------- */ -#ifdef HAVE_CONFIG_H + +#if defined HAVE_CONFIG_H && !defined PCRE2_CONFIG_H_IDEMPOTENT_GUARD +#define PCRE2_CONFIG_H_IDEMPOTENT_GUARD #include "config.h" #endif + + #include #include @@ -651,6 +655,7 @@ static struct regression_test_case regression_test_cases[] = { { MU, A, 0, 0, "a(?=)b", "ab" }, { MU, A, 0, 0 | F_NOMATCH, "a(?!)b", "ab" }, { MU, A, 0, 0, "(?(?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/src/pcre2_match.c b/src/pcre2_match.c index 34a92ea..d5574d7 100644 --- a/src/pcre2_match.c +++ b/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 */ @@ -5990,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. */ @@ -6263,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 */ @@ -6282,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; @@ -6296,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 @@ -6325,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); @@ -6370,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 */ } @@ -6453,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: @@ -6751,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 @@ -6801,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 } @@ -6839,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; @@ -6859,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; @@ -6897,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 @@ -6970,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) { @@ -7017,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 */ @@ -7056,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; } @@ -7074,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; } } @@ -7140,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 */ @@ -7192,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 @@ -7203,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 @@ -7268,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 */ @@ -7317,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 @@ -7361,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; } @@ -7377,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; } @@ -7853,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. */ @@ -8011,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 @@ -8022,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; } @@ -8057,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; @@ -8069,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/src/pcre2_match_data.c b/src/pcre2_match_data.c index 100e7c9..fade67a 100644 --- a/src/pcre2_match_data.c +++ b/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/src/pcre2_match_next.c b/src/pcre2_match_next.c new file mode 100644 index 0000000..ecd21d3 --- /dev/null +++ b/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/src/pcre2_newline.c b/src/pcre2_newline.c index 6e9366d..a7c9299 100644 --- a/src/pcre2_newline.c +++ b/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/src/pcre2_ord2utf.c b/src/pcre2_ord2utf.c index a1e9e08..3b8aead 100644 --- a/src/pcre2_ord2utf.c +++ b/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/src/pcre2_pattern_info.c b/src/pcre2_pattern_info.c index fe4d3c6..e0bd83a 100644 --- a/src/pcre2_pattern_info.c +++ b/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/src/pcre2_printint.c b/src/pcre2_printint.c deleted file mode 100644 index 84f84f8..0000000 --- a/src/pcre2_printint.c +++ /dev/null @@ -1,1111 +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 - 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)c); - else 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", c); else fprintf(f, "\\x{%x}", 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", c); else fprintf(f, "\\x{%x}", 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; - -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 (i = 0; i < 256; i++) - { - if ((map[i/8] & (1u << (i&7))) != 0) - { - int j; - for (j = i+1; j < 256; j++) - if ((map[j/8] & (1u << (j&7))) == 0) break; - if (i == '-' || i == '\\' || i == ']' || (first && i == '^')) - fprintf(f, "\\"); - if (PRINTABLE(i)) fprintf(f, "%c", i); - else fprintf(f, "\\x%02x", i); - first = FALSE; - if (--j > i) - { - if (j != i + 1) fprintf(f, "-"); - if (j == '-' || j == '\\' || j == ']') fprintf(f, "\\"); - if (PRINTABLE(j)) fprintf(f, "%c", j); - else fprintf(f, "\\x%02x", j); - } - i = j; - } - } -} - - - -/************************************************* -* 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 = "^"; - /* 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_REVERSE: - if (print_lengths) fprintf(f, "%3d ", GET2(code, 1)); - else fprintf(f, " "); - fprintf(f, "%s", OP_names[*code]); - break; - - case OP_VREVERSE: - if (print_lengths) fprintf(f, "%3d %d ", GET2(code, 1), - GET2(code, 1 + IMM2_SIZE)); - 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: - fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]); - break; - - case OP_DNCREF: - { - PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE; - fprintf(f, " %s Capture ref <", flag); - 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, " Cond recurse any"); - else - fprintf(f, " Cond recurse %d", c); - break; - - case OP_DNRREF: - { - PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE; - fprintf(f, " %s Cond recurse <", flag); - print_custring(f, entry); - fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); - } - break; - - case OP_FALSE: - fprintf(f, " Cond false"); - break; - - case OP_TRUE: - fprintf(f, " Cond true"); - 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"; - /* 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"; - /* 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"; - /* 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"; - /* 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"; - /* 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"; - extra = code[1 + IMM2_SIZE]; - /* Fall through */ - case OP_REF: - fprintf(f, " %s \\%d", flag, GET2(code,1)); - if (extra != 0) fprintf(f, " 0x%02x", extra); - ccode = code + OP_lengths[*code]; - goto CLASS_REF_REPEAT; - - case OP_DNREFI: - flag = "/i"; - extra = code[1 + 2*IMM2_SIZE]; - /* 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)); - if (extra != 0) fprintf(f, " 0x%02x", extra); - } - 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], 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", 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_THEN: - fprintf(f, " %s", OP_names[*code]); - break; - - case OP_CIRCM: - case OP_DOLLM: - flag = "/m"; - /* 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; - fprintf(f, "\n"); - } -} - -/* End of pcre2_printint.c */ diff --git a/src/pcre2_printint_inc.h b/src/pcre2_printint_inc.h new file mode 100644 index 0000000..4dd689e --- /dev/null +++ b/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/src/pcre2_script_run.c b/src/pcre2_script_run.c index 4926fa6..acdf41f 100644 --- a/src/pcre2_script_run.c +++ b/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/src/pcre2_serialize.c b/src/pcre2_serialize.c index a10e302..f10a3fa 100644 --- a/src/pcre2_serialize.c +++ b/src/pcre2_serialize.c @@ -38,16 +38,14 @@ 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" -#include "pcre2_internal.h" /* Magic number to provide a small check against being handed junk. */ diff --git a/src/pcre2_string_utils.c b/src/pcre2_string_utils.c index ebfa943..f1ac718 100644 --- a/src/pcre2_string_utils.c +++ b/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/src/pcre2_study.c b/src/pcre2_study.c index 85764ce..9f7fd6b 100644 --- a/src/pcre2_study.c +++ b/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/src/pcre2_substitute.c b/src/pcre2_substitute.c index 17040ce..5cb8474 100644 --- a/src/pcre2_substitute.c +++ b/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. */ - - if (rc < 0) - { - PCRE2_SIZE save_start; - - 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. */ + /* Any error other than no match returns the error code. No match breaks the + global loop. */ - 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 - } + if (rc == PCRE2_ERROR_NOMATCH) break; - /* 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; + } + + /* 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]); - 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 */ + } /* End of global loop */ /* Copy the rest of the subject unless not required, and terminate the output with a binary zero. */ diff --git a/src/pcre2_substring.c b/src/pcre2_substring.c index 88afd23..f68b464 100644 --- a/src/pcre2_substring.c +++ b/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/src/pcre2_tables.c b/src/pcre2_tables.c index 097a1ac..0b9b43b 100644 --- a/src/pcre2_tables.c +++ b/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 /* 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 /* SUPPORT_UNICODE */ +#endif /* EBCDIC support needed */ /* End of pcre2_tables.c */ diff --git a/src/pcre2_ucd.c b/src/pcre2_ucd.c index 4c5e516..1cbff3a 100644 --- a/src/pcre2_ucd.c +++ b/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/src/pcre2_ucptables.c b/src/pcre2_ucptables.c deleted file mode 100644 index d2b3403..0000000 --- a/src/pcre2_ucptables.c +++ /dev/null @@ -1,1596 +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 - Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2022 University of Cambridge - -This module is auto-generated from Unicode data files. DO NOT EDIT MANUALLY! -Instead, modify the maint/GenerateUcpTables.py script and run it to generate -a new version of this code. - ------------------------------------------------------------------------------ -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 SUPPORT_UNICODE - -/* The PRIV(utt)[] table below translates Unicode property names into type and -code values. It is searched by binary chop, so must be in collating sequence of -name. Originally, the table contained pointers to the name strings in the first -field of each entry. However, that leads to a large number of relocations when -a shared library is dynamically loaded. A significant reduction is made by -putting all the names into a single, large string and using offsets instead. -All letters are lower cased, and underscores are removed, in accordance with -the "loose matching" rules that Unicode advises and Perl uses. */ - -#define STRING_adlam0 STR_a STR_d STR_l STR_a STR_m "\0" -#define STRING_adlm0 STR_a STR_d STR_l STR_m "\0" -#define STRING_aghb0 STR_a STR_g STR_h STR_b "\0" -#define STRING_ahex0 STR_a STR_h STR_e STR_x "\0" -#define STRING_ahom0 STR_a STR_h STR_o STR_m "\0" -#define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0" -#define STRING_alphabetic0 STR_a STR_l STR_p STR_h STR_a STR_b STR_e STR_t STR_i STR_c "\0" -#define STRING_anatolianhieroglyphs0 STR_a STR_n STR_a STR_t STR_o STR_l STR_i STR_a STR_n STR_h STR_i STR_e STR_r STR_o STR_g STR_l STR_y STR_p STR_h STR_s "\0" -#define STRING_any0 STR_a STR_n STR_y "\0" -#define STRING_arab0 STR_a STR_r STR_a STR_b "\0" -#define STRING_arabic0 STR_a STR_r STR_a STR_b STR_i STR_c "\0" -#define STRING_armenian0 STR_a STR_r STR_m STR_e STR_n STR_i STR_a STR_n "\0" -#define STRING_armi0 STR_a STR_r STR_m STR_i "\0" -#define STRING_armn0 STR_a STR_r STR_m STR_n "\0" -#define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0" -#define STRING_asciihexdigit0 STR_a STR_s STR_c STR_i STR_i STR_h STR_e STR_x STR_d STR_i STR_g STR_i STR_t "\0" -#define STRING_avestan0 STR_a STR_v STR_e STR_s STR_t STR_a STR_n "\0" -#define STRING_avst0 STR_a STR_v STR_s STR_t "\0" -#define STRING_bali0 STR_b STR_a STR_l STR_i "\0" -#define STRING_balinese0 STR_b STR_a STR_l STR_i STR_n STR_e STR_s STR_e "\0" -#define STRING_bamu0 STR_b STR_a STR_m STR_u "\0" -#define STRING_bamum0 STR_b STR_a STR_m STR_u STR_m "\0" -#define STRING_bass0 STR_b STR_a STR_s STR_s "\0" -#define STRING_bassavah0 STR_b STR_a STR_s STR_s STR_a STR_v STR_a STR_h "\0" -#define STRING_batak0 STR_b STR_a STR_t STR_a STR_k "\0" -#define STRING_batk0 STR_b STR_a STR_t STR_k "\0" -#define STRING_beng0 STR_b STR_e STR_n STR_g "\0" -#define STRING_bengali0 STR_b STR_e STR_n STR_g STR_a STR_l STR_i "\0" -#define STRING_bhaiksuki0 STR_b STR_h STR_a STR_i STR_k STR_s STR_u STR_k STR_i "\0" -#define STRING_bhks0 STR_b STR_h STR_k STR_s "\0" -#define STRING_bidial0 STR_b STR_i STR_d STR_i STR_a STR_l "\0" -#define STRING_bidian0 STR_b STR_i STR_d STR_i STR_a STR_n "\0" -#define STRING_bidib0 STR_b STR_i STR_d STR_i STR_b "\0" -#define STRING_bidibn0 STR_b STR_i STR_d STR_i STR_b STR_n "\0" -#define STRING_bidic0 STR_b STR_i STR_d STR_i STR_c "\0" -#define STRING_bidicontrol0 STR_b STR_i STR_d STR_i STR_c STR_o STR_n STR_t STR_r STR_o STR_l "\0" -#define STRING_bidics0 STR_b STR_i STR_d STR_i STR_c STR_s "\0" -#define STRING_bidien0 STR_b STR_i STR_d STR_i STR_e STR_n "\0" -#define STRING_bidies0 STR_b STR_i STR_d STR_i STR_e STR_s "\0" -#define STRING_bidiet0 STR_b STR_i STR_d STR_i STR_e STR_t "\0" -#define STRING_bidifsi0 STR_b STR_i STR_d STR_i STR_f STR_s STR_i "\0" -#define STRING_bidil0 STR_b STR_i STR_d STR_i STR_l "\0" -#define STRING_bidilre0 STR_b STR_i STR_d STR_i STR_l STR_r STR_e "\0" -#define STRING_bidilri0 STR_b STR_i STR_d STR_i STR_l STR_r STR_i "\0" -#define STRING_bidilro0 STR_b STR_i STR_d STR_i STR_l STR_r STR_o "\0" -#define STRING_bidim0 STR_b STR_i STR_d STR_i STR_m "\0" -#define STRING_bidimirrored0 STR_b STR_i STR_d STR_i STR_m STR_i STR_r STR_r STR_o STR_r STR_e STR_d "\0" -#define STRING_bidinsm0 STR_b STR_i STR_d STR_i STR_n STR_s STR_m "\0" -#define STRING_bidion0 STR_b STR_i STR_d STR_i STR_o STR_n "\0" -#define STRING_bidipdf0 STR_b STR_i STR_d STR_i STR_p STR_d STR_f "\0" -#define STRING_bidipdi0 STR_b STR_i STR_d STR_i STR_p STR_d STR_i "\0" -#define STRING_bidir0 STR_b STR_i STR_d STR_i STR_r "\0" -#define STRING_bidirle0 STR_b STR_i STR_d STR_i STR_r STR_l STR_e "\0" -#define STRING_bidirli0 STR_b STR_i STR_d STR_i STR_r STR_l STR_i "\0" -#define STRING_bidirlo0 STR_b STR_i STR_d STR_i STR_r STR_l STR_o "\0" -#define STRING_bidis0 STR_b STR_i STR_d STR_i STR_s "\0" -#define STRING_bidiws0 STR_b STR_i STR_d STR_i STR_w STR_s "\0" -#define STRING_bopo0 STR_b STR_o STR_p STR_o "\0" -#define STRING_bopomofo0 STR_b STR_o STR_p STR_o STR_m STR_o STR_f STR_o "\0" -#define STRING_brah0 STR_b STR_r STR_a STR_h "\0" -#define STRING_brahmi0 STR_b STR_r STR_a STR_h STR_m STR_i "\0" -#define STRING_brai0 STR_b STR_r STR_a STR_i "\0" -#define STRING_braille0 STR_b STR_r STR_a STR_i STR_l STR_l STR_e "\0" -#define STRING_bugi0 STR_b STR_u STR_g STR_i "\0" -#define STRING_buginese0 STR_b STR_u STR_g STR_i STR_n STR_e STR_s STR_e "\0" -#define STRING_buhd0 STR_b STR_u STR_h STR_d "\0" -#define STRING_buhid0 STR_b STR_u STR_h STR_i STR_d "\0" -#define STRING_c0 STR_c "\0" -#define STRING_cakm0 STR_c STR_a STR_k STR_m "\0" -#define STRING_canadianaboriginal0 STR_c STR_a STR_n STR_a STR_d STR_i STR_a STR_n STR_a STR_b STR_o STR_r STR_i STR_g STR_i STR_n STR_a STR_l "\0" -#define STRING_cans0 STR_c STR_a STR_n STR_s "\0" -#define STRING_cari0 STR_c STR_a STR_r STR_i "\0" -#define STRING_carian0 STR_c STR_a STR_r STR_i STR_a STR_n "\0" -#define STRING_cased0 STR_c STR_a STR_s STR_e STR_d "\0" -#define STRING_caseignorable0 STR_c STR_a STR_s STR_e STR_i STR_g STR_n STR_o STR_r STR_a STR_b STR_l STR_e "\0" -#define STRING_caucasianalbanian0 STR_c STR_a STR_u STR_c STR_a STR_s STR_i STR_a STR_n STR_a STR_l STR_b STR_a STR_n STR_i STR_a STR_n "\0" -#define STRING_cc0 STR_c STR_c "\0" -#define STRING_cf0 STR_c STR_f "\0" -#define STRING_chakma0 STR_c STR_h STR_a STR_k STR_m STR_a "\0" -#define STRING_cham0 STR_c STR_h STR_a STR_m "\0" -#define STRING_changeswhencasefolded0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_c STR_a STR_s STR_e STR_f STR_o STR_l STR_d STR_e STR_d "\0" -#define STRING_changeswhencasemapped0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_c STR_a STR_s STR_e STR_m STR_a STR_p STR_p STR_e STR_d "\0" -#define STRING_changeswhenlowercased0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_l STR_o STR_w STR_e STR_r STR_c STR_a STR_s STR_e STR_d "\0" -#define STRING_changeswhentitlecased0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_t STR_i STR_t STR_l STR_e STR_c STR_a STR_s STR_e STR_d "\0" -#define STRING_changeswhenuppercased0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_u STR_p STR_p STR_e STR_r STR_c STR_a STR_s STR_e STR_d "\0" -#define STRING_cher0 STR_c STR_h STR_e STR_r "\0" -#define STRING_cherokee0 STR_c STR_h STR_e STR_r STR_o STR_k STR_e STR_e "\0" -#define STRING_chorasmian0 STR_c STR_h STR_o STR_r STR_a STR_s STR_m STR_i STR_a STR_n "\0" -#define STRING_chrs0 STR_c STR_h STR_r STR_s "\0" -#define STRING_ci0 STR_c STR_i "\0" -#define STRING_cn0 STR_c STR_n "\0" -#define STRING_co0 STR_c STR_o "\0" -#define STRING_common0 STR_c STR_o STR_m STR_m STR_o STR_n "\0" -#define STRING_copt0 STR_c STR_o STR_p STR_t "\0" -#define STRING_coptic0 STR_c STR_o STR_p STR_t STR_i STR_c "\0" -#define STRING_cpmn0 STR_c STR_p STR_m STR_n "\0" -#define STRING_cprt0 STR_c STR_p STR_r STR_t "\0" -#define STRING_cs0 STR_c STR_s "\0" -#define STRING_cuneiform0 STR_c STR_u STR_n STR_e STR_i STR_f STR_o STR_r STR_m "\0" -#define STRING_cwcf0 STR_c STR_w STR_c STR_f "\0" -#define STRING_cwcm0 STR_c STR_w STR_c STR_m "\0" -#define STRING_cwl0 STR_c STR_w STR_l "\0" -#define STRING_cwt0 STR_c STR_w STR_t "\0" -#define STRING_cwu0 STR_c STR_w STR_u "\0" -#define STRING_cypriot0 STR_c STR_y STR_p STR_r STR_i STR_o STR_t "\0" -#define STRING_cyprominoan0 STR_c STR_y STR_p STR_r STR_o STR_m STR_i STR_n STR_o STR_a STR_n "\0" -#define STRING_cyrillic0 STR_c STR_y STR_r STR_i STR_l STR_l STR_i STR_c "\0" -#define STRING_cyrl0 STR_c STR_y STR_r STR_l "\0" -#define STRING_dash0 STR_d STR_a STR_s STR_h "\0" -#define STRING_defaultignorablecodepoint0 STR_d STR_e STR_f STR_a STR_u STR_l STR_t STR_i STR_g STR_n STR_o STR_r STR_a STR_b STR_l STR_e STR_c STR_o STR_d STR_e STR_p STR_o STR_i STR_n STR_t "\0" -#define STRING_dep0 STR_d STR_e STR_p "\0" -#define STRING_deprecated0 STR_d STR_e STR_p STR_r STR_e STR_c STR_a STR_t STR_e STR_d "\0" -#define STRING_deseret0 STR_d STR_e STR_s STR_e STR_r STR_e STR_t "\0" -#define STRING_deva0 STR_d STR_e STR_v STR_a "\0" -#define STRING_devanagari0 STR_d STR_e STR_v STR_a STR_n STR_a STR_g STR_a STR_r STR_i "\0" -#define STRING_di0 STR_d STR_i "\0" -#define STRING_dia0 STR_d STR_i STR_a "\0" -#define STRING_diacritic0 STR_d STR_i STR_a STR_c STR_r STR_i STR_t STR_i STR_c "\0" -#define STRING_diak0 STR_d STR_i STR_a STR_k "\0" -#define STRING_divesakuru0 STR_d STR_i STR_v STR_e STR_s STR_a STR_k STR_u STR_r STR_u "\0" -#define STRING_dogr0 STR_d STR_o STR_g STR_r "\0" -#define STRING_dogra0 STR_d STR_o STR_g STR_r STR_a "\0" -#define STRING_dsrt0 STR_d STR_s STR_r STR_t "\0" -#define STRING_dupl0 STR_d STR_u STR_p STR_l "\0" -#define STRING_duployan0 STR_d STR_u STR_p STR_l STR_o STR_y STR_a STR_n "\0" -#define STRING_ebase0 STR_e STR_b STR_a STR_s STR_e "\0" -#define STRING_ecomp0 STR_e STR_c STR_o STR_m STR_p "\0" -#define STRING_egyp0 STR_e STR_g STR_y STR_p "\0" -#define STRING_egyptianhieroglyphs0 STR_e STR_g STR_y STR_p STR_t STR_i STR_a STR_n STR_h STR_i STR_e STR_r STR_o STR_g STR_l STR_y STR_p STR_h STR_s "\0" -#define STRING_elba0 STR_e STR_l STR_b STR_a "\0" -#define STRING_elbasan0 STR_e STR_l STR_b STR_a STR_s STR_a STR_n "\0" -#define STRING_elym0 STR_e STR_l STR_y STR_m "\0" -#define STRING_elymaic0 STR_e STR_l STR_y STR_m STR_a STR_i STR_c "\0" -#define STRING_emod0 STR_e STR_m STR_o STR_d "\0" -#define STRING_emoji0 STR_e STR_m STR_o STR_j STR_i "\0" -#define STRING_emojicomponent0 STR_e STR_m STR_o STR_j STR_i STR_c STR_o STR_m STR_p STR_o STR_n STR_e STR_n STR_t "\0" -#define STRING_emojimodifier0 STR_e STR_m STR_o STR_j STR_i STR_m STR_o STR_d STR_i STR_f STR_i STR_e STR_r "\0" -#define STRING_emojimodifierbase0 STR_e STR_m STR_o STR_j STR_i STR_m STR_o STR_d STR_i STR_f STR_i STR_e STR_r STR_b STR_a STR_s STR_e "\0" -#define STRING_emojipresentation0 STR_e STR_m STR_o STR_j STR_i STR_p STR_r STR_e STR_s STR_e STR_n STR_t STR_a STR_t STR_i STR_o STR_n "\0" -#define STRING_epres0 STR_e STR_p STR_r STR_e STR_s "\0" -#define STRING_ethi0 STR_e STR_t STR_h STR_i "\0" -#define STRING_ethiopic0 STR_e STR_t STR_h STR_i STR_o STR_p STR_i STR_c "\0" -#define STRING_ext0 STR_e STR_x STR_t "\0" -#define STRING_extendedpictographic0 STR_e STR_x STR_t STR_e STR_n STR_d STR_e STR_d STR_p STR_i STR_c STR_t STR_o STR_g STR_r STR_a STR_p STR_h STR_i STR_c "\0" -#define STRING_extender0 STR_e STR_x STR_t STR_e STR_n STR_d STR_e STR_r "\0" -#define STRING_extpict0 STR_e STR_x STR_t STR_p STR_i STR_c STR_t "\0" -#define STRING_gara0 STR_g STR_a STR_r STR_a "\0" -#define STRING_garay0 STR_g STR_a STR_r STR_a STR_y "\0" -#define STRING_geor0 STR_g STR_e STR_o STR_r "\0" -#define STRING_georgian0 STR_g STR_e STR_o STR_r STR_g STR_i STR_a STR_n "\0" -#define STRING_glag0 STR_g STR_l STR_a STR_g "\0" -#define STRING_glagolitic0 STR_g STR_l STR_a STR_g STR_o STR_l STR_i STR_t STR_i STR_c "\0" -#define STRING_gong0 STR_g STR_o STR_n STR_g "\0" -#define STRING_gonm0 STR_g STR_o STR_n STR_m "\0" -#define STRING_goth0 STR_g STR_o STR_t STR_h "\0" -#define STRING_gothic0 STR_g STR_o STR_t STR_h STR_i STR_c "\0" -#define STRING_gran0 STR_g STR_r STR_a STR_n "\0" -#define STRING_grantha0 STR_g STR_r STR_a STR_n STR_t STR_h STR_a "\0" -#define STRING_graphemebase0 STR_g STR_r STR_a STR_p STR_h STR_e STR_m STR_e STR_b STR_a STR_s STR_e "\0" -#define STRING_graphemeextend0 STR_g STR_r STR_a STR_p STR_h STR_e STR_m STR_e STR_e STR_x STR_t STR_e STR_n STR_d "\0" -#define STRING_graphemelink0 STR_g STR_r STR_a STR_p STR_h STR_e STR_m STR_e STR_l STR_i STR_n STR_k "\0" -#define STRING_grbase0 STR_g STR_r STR_b STR_a STR_s STR_e "\0" -#define STRING_greek0 STR_g STR_r STR_e STR_e STR_k "\0" -#define STRING_grek0 STR_g STR_r STR_e STR_k "\0" -#define STRING_grext0 STR_g STR_r STR_e STR_x STR_t "\0" -#define STRING_grlink0 STR_g STR_r STR_l STR_i STR_n STR_k "\0" -#define STRING_gujarati0 STR_g STR_u STR_j STR_a STR_r STR_a STR_t STR_i "\0" -#define STRING_gujr0 STR_g STR_u STR_j STR_r "\0" -#define STRING_gukh0 STR_g STR_u STR_k STR_h "\0" -#define STRING_gunjalagondi0 STR_g STR_u STR_n STR_j STR_a STR_l STR_a STR_g STR_o STR_n STR_d STR_i "\0" -#define STRING_gurmukhi0 STR_g STR_u STR_r STR_m STR_u STR_k STR_h STR_i "\0" -#define STRING_guru0 STR_g STR_u STR_r STR_u "\0" -#define STRING_gurungkhema0 STR_g STR_u STR_r STR_u STR_n STR_g STR_k STR_h STR_e STR_m STR_a "\0" -#define STRING_han0 STR_h STR_a STR_n "\0" -#define STRING_hang0 STR_h STR_a STR_n STR_g "\0" -#define STRING_hangul0 STR_h STR_a STR_n STR_g STR_u STR_l "\0" -#define STRING_hani0 STR_h STR_a STR_n STR_i "\0" -#define STRING_hanifirohingya0 STR_h STR_a STR_n STR_i STR_f STR_i STR_r STR_o STR_h STR_i STR_n STR_g STR_y STR_a "\0" -#define STRING_hano0 STR_h STR_a STR_n STR_o "\0" -#define STRING_hanunoo0 STR_h STR_a STR_n STR_u STR_n STR_o STR_o "\0" -#define STRING_hatr0 STR_h STR_a STR_t STR_r "\0" -#define STRING_hatran0 STR_h STR_a STR_t STR_r STR_a STR_n "\0" -#define STRING_hebr0 STR_h STR_e STR_b STR_r "\0" -#define STRING_hebrew0 STR_h STR_e STR_b STR_r STR_e STR_w "\0" -#define STRING_hex0 STR_h STR_e STR_x "\0" -#define STRING_hexdigit0 STR_h STR_e STR_x STR_d STR_i STR_g STR_i STR_t "\0" -#define STRING_hira0 STR_h STR_i STR_r STR_a "\0" -#define STRING_hiragana0 STR_h STR_i STR_r STR_a STR_g STR_a STR_n STR_a "\0" -#define STRING_hluw0 STR_h STR_l STR_u STR_w "\0" -#define STRING_hmng0 STR_h STR_m STR_n STR_g "\0" -#define STRING_hmnp0 STR_h STR_m STR_n STR_p "\0" -#define STRING_hung0 STR_h STR_u STR_n STR_g "\0" -#define STRING_idc0 STR_i STR_d STR_c "\0" -#define STRING_idcompatmathcontinue0 STR_i STR_d STR_c STR_o STR_m STR_p STR_a STR_t STR_m STR_a STR_t STR_h STR_c STR_o STR_n STR_t STR_i STR_n STR_u STR_e "\0" -#define STRING_idcompatmathstart0 STR_i STR_d STR_c STR_o STR_m STR_p STR_a STR_t STR_m STR_a STR_t STR_h STR_s STR_t STR_a STR_r STR_t "\0" -#define STRING_idcontinue0 STR_i STR_d STR_c STR_o STR_n STR_t STR_i STR_n STR_u STR_e "\0" -#define STRING_ideo0 STR_i STR_d STR_e STR_o "\0" -#define STRING_ideographic0 STR_i STR_d STR_e STR_o STR_g STR_r STR_a STR_p STR_h STR_i STR_c "\0" -#define STRING_ids0 STR_i STR_d STR_s "\0" -#define STRING_idsb0 STR_i STR_d STR_s STR_b "\0" -#define STRING_idsbinaryoperator0 STR_i STR_d STR_s STR_b STR_i STR_n STR_a STR_r STR_y STR_o STR_p STR_e STR_r STR_a STR_t STR_o STR_r "\0" -#define STRING_idst0 STR_i STR_d STR_s STR_t "\0" -#define STRING_idstart0 STR_i STR_d STR_s STR_t STR_a STR_r STR_t "\0" -#define STRING_idstrinaryoperator0 STR_i STR_d STR_s STR_t STR_r STR_i STR_n STR_a STR_r STR_y STR_o STR_p STR_e STR_r STR_a STR_t STR_o STR_r "\0" -#define STRING_idsu0 STR_i STR_d STR_s STR_u "\0" -#define STRING_idsunaryoperator0 STR_i STR_d STR_s STR_u STR_n STR_a STR_r STR_y STR_o STR_p STR_e STR_r STR_a STR_t STR_o STR_r "\0" -#define STRING_imperialaramaic0 STR_i STR_m STR_p STR_e STR_r STR_i STR_a STR_l STR_a STR_r STR_a STR_m STR_a STR_i STR_c "\0" -#define STRING_incb0 STR_i STR_n STR_c STR_b "\0" -#define STRING_inherited0 STR_i STR_n STR_h STR_e STR_r STR_i STR_t STR_e STR_d "\0" -#define STRING_inscriptionalpahlavi0 STR_i STR_n STR_s STR_c STR_r STR_i STR_p STR_t STR_i STR_o STR_n STR_a STR_l STR_p STR_a STR_h STR_l STR_a STR_v STR_i "\0" -#define STRING_inscriptionalparthian0 STR_i STR_n STR_s STR_c STR_r STR_i STR_p STR_t STR_i STR_o STR_n STR_a STR_l STR_p STR_a STR_r STR_t STR_h STR_i STR_a STR_n "\0" -#define STRING_ital0 STR_i STR_t STR_a STR_l "\0" -#define STRING_java0 STR_j STR_a STR_v STR_a "\0" -#define STRING_javanese0 STR_j STR_a STR_v STR_a STR_n STR_e STR_s STR_e "\0" -#define STRING_joinc0 STR_j STR_o STR_i STR_n STR_c "\0" -#define STRING_joincontrol0 STR_j STR_o STR_i STR_n STR_c STR_o STR_n STR_t STR_r STR_o STR_l "\0" -#define STRING_kaithi0 STR_k STR_a STR_i STR_t STR_h STR_i "\0" -#define STRING_kali0 STR_k STR_a STR_l STR_i "\0" -#define STRING_kana0 STR_k STR_a STR_n STR_a "\0" -#define STRING_kannada0 STR_k STR_a STR_n STR_n STR_a STR_d STR_a "\0" -#define STRING_katakana0 STR_k STR_a STR_t STR_a STR_k STR_a STR_n STR_a "\0" -#define STRING_kawi0 STR_k STR_a STR_w STR_i "\0" -#define STRING_kayahli0 STR_k STR_a STR_y STR_a STR_h STR_l STR_i "\0" -#define STRING_khar0 STR_k STR_h STR_a STR_r "\0" -#define STRING_kharoshthi0 STR_k STR_h STR_a STR_r STR_o STR_s STR_h STR_t STR_h STR_i "\0" -#define STRING_khitansmallscript0 STR_k STR_h STR_i STR_t STR_a STR_n STR_s STR_m STR_a STR_l STR_l STR_s STR_c STR_r STR_i STR_p STR_t "\0" -#define STRING_khmer0 STR_k STR_h STR_m STR_e STR_r "\0" -#define STRING_khmr0 STR_k STR_h STR_m STR_r "\0" -#define STRING_khoj0 STR_k STR_h STR_o STR_j "\0" -#define STRING_khojki0 STR_k STR_h STR_o STR_j STR_k STR_i "\0" -#define STRING_khudawadi0 STR_k STR_h STR_u STR_d STR_a STR_w STR_a STR_d STR_i "\0" -#define STRING_kiratrai0 STR_k STR_i STR_r STR_a STR_t STR_r STR_a STR_i "\0" -#define STRING_kits0 STR_k STR_i STR_t STR_s "\0" -#define STRING_knda0 STR_k STR_n STR_d STR_a "\0" -#define STRING_krai0 STR_k STR_r STR_a STR_i "\0" -#define STRING_kthi0 STR_k STR_t STR_h STR_i "\0" -#define STRING_l0 STR_l "\0" -#define STRING_l_AMPERSAND0 STR_l STR_AMPERSAND "\0" -#define STRING_lana0 STR_l STR_a STR_n STR_a "\0" -#define STRING_lao0 STR_l STR_a STR_o "\0" -#define STRING_laoo0 STR_l STR_a STR_o STR_o "\0" -#define STRING_latin0 STR_l STR_a STR_t STR_i STR_n "\0" -#define STRING_latn0 STR_l STR_a STR_t STR_n "\0" -#define STRING_lc0 STR_l STR_c "\0" -#define STRING_lepc0 STR_l STR_e STR_p STR_c "\0" -#define STRING_lepcha0 STR_l STR_e STR_p STR_c STR_h STR_a "\0" -#define STRING_limb0 STR_l STR_i STR_m STR_b "\0" -#define STRING_limbu0 STR_l STR_i STR_m STR_b STR_u "\0" -#define STRING_lina0 STR_l STR_i STR_n STR_a "\0" -#define STRING_linb0 STR_l STR_i STR_n STR_b "\0" -#define STRING_lineara0 STR_l STR_i STR_n STR_e STR_a STR_r STR_a "\0" -#define STRING_linearb0 STR_l STR_i STR_n STR_e STR_a STR_r STR_b "\0" -#define STRING_lisu0 STR_l STR_i STR_s STR_u "\0" -#define STRING_ll0 STR_l STR_l "\0" -#define STRING_lm0 STR_l STR_m "\0" -#define STRING_lo0 STR_l STR_o "\0" -#define STRING_loe0 STR_l STR_o STR_e "\0" -#define STRING_logicalorderexception0 STR_l STR_o STR_g STR_i STR_c STR_a STR_l STR_o STR_r STR_d STR_e STR_r STR_e STR_x STR_c STR_e STR_p STR_t STR_i STR_o STR_n "\0" -#define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0" -#define STRING_lowercase0 STR_l STR_o STR_w STR_e STR_r STR_c STR_a STR_s STR_e "\0" -#define STRING_lt0 STR_l STR_t "\0" -#define STRING_lu0 STR_l STR_u "\0" -#define STRING_lyci0 STR_l STR_y STR_c STR_i "\0" -#define STRING_lycian0 STR_l STR_y STR_c STR_i STR_a STR_n "\0" -#define STRING_lydi0 STR_l STR_y STR_d STR_i "\0" -#define STRING_lydian0 STR_l STR_y STR_d STR_i STR_a STR_n "\0" -#define STRING_m0 STR_m "\0" -#define STRING_mahajani0 STR_m STR_a STR_h STR_a STR_j STR_a STR_n STR_i "\0" -#define STRING_mahj0 STR_m STR_a STR_h STR_j "\0" -#define STRING_maka0 STR_m STR_a STR_k STR_a "\0" -#define STRING_makasar0 STR_m STR_a STR_k STR_a STR_s STR_a STR_r "\0" -#define STRING_malayalam0 STR_m STR_a STR_l STR_a STR_y STR_a STR_l STR_a STR_m "\0" -#define STRING_mand0 STR_m STR_a STR_n STR_d "\0" -#define STRING_mandaic0 STR_m STR_a STR_n STR_d STR_a STR_i STR_c "\0" -#define STRING_mani0 STR_m STR_a STR_n STR_i "\0" -#define STRING_manichaean0 STR_m STR_a STR_n STR_i STR_c STR_h STR_a STR_e STR_a STR_n "\0" -#define STRING_marc0 STR_m STR_a STR_r STR_c "\0" -#define STRING_marchen0 STR_m STR_a STR_r STR_c STR_h STR_e STR_n "\0" -#define STRING_masaramgondi0 STR_m STR_a STR_s STR_a STR_r STR_a STR_m STR_g STR_o STR_n STR_d STR_i "\0" -#define STRING_math0 STR_m STR_a STR_t STR_h "\0" -#define STRING_mc0 STR_m STR_c "\0" -#define STRING_mcm0 STR_m STR_c STR_m "\0" -#define STRING_me0 STR_m STR_e "\0" -#define STRING_medefaidrin0 STR_m STR_e STR_d STR_e STR_f STR_a STR_i STR_d STR_r STR_i STR_n "\0" -#define STRING_medf0 STR_m STR_e STR_d STR_f "\0" -#define STRING_meeteimayek0 STR_m STR_e STR_e STR_t STR_e STR_i STR_m STR_a STR_y STR_e STR_k "\0" -#define STRING_mend0 STR_m STR_e STR_n STR_d "\0" -#define STRING_mendekikakui0 STR_m STR_e STR_n STR_d STR_e STR_k STR_i STR_k STR_a STR_k STR_u STR_i "\0" -#define STRING_merc0 STR_m STR_e STR_r STR_c "\0" -#define STRING_mero0 STR_m STR_e STR_r STR_o "\0" -#define STRING_meroiticcursive0 STR_m STR_e STR_r STR_o STR_i STR_t STR_i STR_c STR_c STR_u STR_r STR_s STR_i STR_v STR_e "\0" -#define STRING_meroitichieroglyphs0 STR_m STR_e STR_r STR_o STR_i STR_t STR_i STR_c STR_h STR_i STR_e STR_r STR_o STR_g STR_l STR_y STR_p STR_h STR_s "\0" -#define STRING_miao0 STR_m STR_i STR_a STR_o "\0" -#define STRING_mlym0 STR_m STR_l STR_y STR_m "\0" -#define STRING_mn0 STR_m STR_n "\0" -#define STRING_modi0 STR_m STR_o STR_d STR_i "\0" -#define STRING_modifiercombiningmark0 STR_m STR_o STR_d STR_i STR_f STR_i STR_e STR_r STR_c STR_o STR_m STR_b STR_i STR_n STR_i STR_n STR_g STR_m STR_a STR_r STR_k "\0" -#define STRING_mong0 STR_m STR_o STR_n STR_g "\0" -#define STRING_mongolian0 STR_m STR_o STR_n STR_g STR_o STR_l STR_i STR_a STR_n "\0" -#define STRING_mro0 STR_m STR_r STR_o "\0" -#define STRING_mroo0 STR_m STR_r STR_o STR_o "\0" -#define STRING_mtei0 STR_m STR_t STR_e STR_i "\0" -#define STRING_mult0 STR_m STR_u STR_l STR_t "\0" -#define STRING_multani0 STR_m STR_u STR_l STR_t STR_a STR_n STR_i "\0" -#define STRING_myanmar0 STR_m STR_y STR_a STR_n STR_m STR_a STR_r "\0" -#define STRING_mymr0 STR_m STR_y STR_m STR_r "\0" -#define STRING_n0 STR_n "\0" -#define STRING_nabataean0 STR_n STR_a STR_b STR_a STR_t STR_a STR_e STR_a STR_n "\0" -#define STRING_nagm0 STR_n STR_a STR_g STR_m "\0" -#define STRING_nagmundari0 STR_n STR_a STR_g STR_m STR_u STR_n STR_d STR_a STR_r STR_i "\0" -#define STRING_nand0 STR_n STR_a STR_n STR_d "\0" -#define STRING_nandinagari0 STR_n STR_a STR_n STR_d STR_i STR_n STR_a STR_g STR_a STR_r STR_i "\0" -#define STRING_narb0 STR_n STR_a STR_r STR_b "\0" -#define STRING_nbat0 STR_n STR_b STR_a STR_t "\0" -#define STRING_nchar0 STR_n STR_c STR_h STR_a STR_r "\0" -#define STRING_nd0 STR_n STR_d "\0" -#define STRING_newa0 STR_n STR_e STR_w STR_a "\0" -#define STRING_newtailue0 STR_n STR_e STR_w STR_t STR_a STR_i STR_l STR_u STR_e "\0" -#define STRING_nko0 STR_n STR_k STR_o "\0" -#define STRING_nkoo0 STR_n STR_k STR_o STR_o "\0" -#define STRING_nl0 STR_n STR_l "\0" -#define STRING_no0 STR_n STR_o "\0" -#define STRING_noncharactercodepoint0 STR_n STR_o STR_n STR_c STR_h STR_a STR_r STR_a STR_c STR_t STR_e STR_r STR_c STR_o STR_d STR_e STR_p STR_o STR_i STR_n STR_t "\0" -#define STRING_nshu0 STR_n STR_s STR_h STR_u "\0" -#define STRING_nushu0 STR_n STR_u STR_s STR_h STR_u "\0" -#define STRING_nyiakengpuachuehmong0 STR_n STR_y STR_i STR_a STR_k STR_e STR_n STR_g STR_p STR_u STR_a STR_c STR_h STR_u STR_e STR_h STR_m STR_o STR_n STR_g "\0" -#define STRING_ogam0 STR_o STR_g STR_a STR_m "\0" -#define STRING_ogham0 STR_o STR_g STR_h STR_a STR_m "\0" -#define STRING_olchiki0 STR_o STR_l STR_c STR_h STR_i STR_k STR_i "\0" -#define STRING_olck0 STR_o STR_l STR_c STR_k "\0" -#define STRING_oldhungarian0 STR_o STR_l STR_d STR_h STR_u STR_n STR_g STR_a STR_r STR_i STR_a STR_n "\0" -#define STRING_olditalic0 STR_o STR_l STR_d STR_i STR_t STR_a STR_l STR_i STR_c "\0" -#define STRING_oldnortharabian0 STR_o STR_l STR_d STR_n STR_o STR_r STR_t STR_h STR_a STR_r STR_a STR_b STR_i STR_a STR_n "\0" -#define STRING_oldpermic0 STR_o STR_l STR_d STR_p STR_e STR_r STR_m STR_i STR_c "\0" -#define STRING_oldpersian0 STR_o STR_l STR_d STR_p STR_e STR_r STR_s STR_i STR_a STR_n "\0" -#define STRING_oldsogdian0 STR_o STR_l STR_d STR_s STR_o STR_g STR_d STR_i STR_a STR_n "\0" -#define STRING_oldsoutharabian0 STR_o STR_l STR_d STR_s STR_o STR_u STR_t STR_h STR_a STR_r STR_a STR_b STR_i STR_a STR_n "\0" -#define STRING_oldturkic0 STR_o STR_l STR_d STR_t STR_u STR_r STR_k STR_i STR_c "\0" -#define STRING_olduyghur0 STR_o STR_l STR_d STR_u STR_y STR_g STR_h STR_u STR_r "\0" -#define STRING_olonal0 STR_o STR_l STR_o STR_n STR_a STR_l "\0" -#define STRING_onao0 STR_o STR_n STR_a STR_o "\0" -#define STRING_oriya0 STR_o STR_r STR_i STR_y STR_a "\0" -#define STRING_orkh0 STR_o STR_r STR_k STR_h "\0" -#define STRING_orya0 STR_o STR_r STR_y STR_a "\0" -#define STRING_osage0 STR_o STR_s STR_a STR_g STR_e "\0" -#define STRING_osge0 STR_o STR_s STR_g STR_e "\0" -#define STRING_osma0 STR_o STR_s STR_m STR_a "\0" -#define STRING_osmanya0 STR_o STR_s STR_m STR_a STR_n STR_y STR_a "\0" -#define STRING_ougr0 STR_o STR_u STR_g STR_r "\0" -#define STRING_p0 STR_p "\0" -#define STRING_pahawhhmong0 STR_p STR_a STR_h STR_a STR_w STR_h STR_h STR_m STR_o STR_n STR_g "\0" -#define STRING_palm0 STR_p STR_a STR_l STR_m "\0" -#define STRING_palmyrene0 STR_p STR_a STR_l STR_m STR_y STR_r STR_e STR_n STR_e "\0" -#define STRING_patsyn0 STR_p STR_a STR_t STR_s STR_y STR_n "\0" -#define STRING_patternsyntax0 STR_p STR_a STR_t STR_t STR_e STR_r STR_n STR_s STR_y STR_n STR_t STR_a STR_x "\0" -#define STRING_patternwhitespace0 STR_p STR_a STR_t STR_t STR_e STR_r STR_n STR_w STR_h STR_i STR_t STR_e STR_s STR_p STR_a STR_c STR_e "\0" -#define STRING_patws0 STR_p STR_a STR_t STR_w STR_s "\0" -#define STRING_pauc0 STR_p STR_a STR_u STR_c "\0" -#define STRING_paucinhau0 STR_p STR_a STR_u STR_c STR_i STR_n STR_h STR_a STR_u "\0" -#define STRING_pc0 STR_p STR_c "\0" -#define STRING_pcm0 STR_p STR_c STR_m "\0" -#define STRING_pd0 STR_p STR_d "\0" -#define STRING_pe0 STR_p STR_e "\0" -#define STRING_perm0 STR_p STR_e STR_r STR_m "\0" -#define STRING_pf0 STR_p STR_f "\0" -#define STRING_phag0 STR_p STR_h STR_a STR_g "\0" -#define STRING_phagspa0 STR_p STR_h STR_a STR_g STR_s STR_p STR_a "\0" -#define STRING_phli0 STR_p STR_h STR_l STR_i "\0" -#define STRING_phlp0 STR_p STR_h STR_l STR_p "\0" -#define STRING_phnx0 STR_p STR_h STR_n STR_x "\0" -#define STRING_phoenician0 STR_p STR_h STR_o STR_e STR_n STR_i STR_c STR_i STR_a STR_n "\0" -#define STRING_pi0 STR_p STR_i "\0" -#define STRING_plrd0 STR_p STR_l STR_r STR_d "\0" -#define STRING_po0 STR_p STR_o "\0" -#define STRING_prependedconcatenationmark0 STR_p STR_r STR_e STR_p STR_e STR_n STR_d STR_e STR_d STR_c STR_o STR_n STR_c STR_a STR_t STR_e STR_n STR_a STR_t STR_i STR_o STR_n STR_m STR_a STR_r STR_k "\0" -#define STRING_prti0 STR_p STR_r STR_t STR_i "\0" -#define STRING_ps0 STR_p STR_s "\0" -#define STRING_psalterpahlavi0 STR_p STR_s STR_a STR_l STR_t STR_e STR_r STR_p STR_a STR_h STR_l STR_a STR_v STR_i "\0" -#define STRING_qaac0 STR_q STR_a STR_a STR_c "\0" -#define STRING_qaai0 STR_q STR_a STR_a STR_i "\0" -#define STRING_qmark0 STR_q STR_m STR_a STR_r STR_k "\0" -#define STRING_quotationmark0 STR_q STR_u STR_o STR_t STR_a STR_t STR_i STR_o STR_n STR_m STR_a STR_r STR_k "\0" -#define STRING_radical0 STR_r STR_a STR_d STR_i STR_c STR_a STR_l "\0" -#define STRING_regionalindicator0 STR_r STR_e STR_g STR_i STR_o STR_n STR_a STR_l STR_i STR_n STR_d STR_i STR_c STR_a STR_t STR_o STR_r "\0" -#define STRING_rejang0 STR_r STR_e STR_j STR_a STR_n STR_g "\0" -#define STRING_ri0 STR_r STR_i "\0" -#define STRING_rjng0 STR_r STR_j STR_n STR_g "\0" -#define STRING_rohg0 STR_r STR_o STR_h STR_g "\0" -#define STRING_runic0 STR_r STR_u STR_n STR_i STR_c "\0" -#define STRING_runr0 STR_r STR_u STR_n STR_r "\0" -#define STRING_s0 STR_s "\0" -#define STRING_samaritan0 STR_s STR_a STR_m STR_a STR_r STR_i STR_t STR_a STR_n "\0" -#define STRING_samr0 STR_s STR_a STR_m STR_r "\0" -#define STRING_sarb0 STR_s STR_a STR_r STR_b "\0" -#define STRING_saur0 STR_s STR_a STR_u STR_r "\0" -#define STRING_saurashtra0 STR_s STR_a STR_u STR_r STR_a STR_s STR_h STR_t STR_r STR_a "\0" -#define STRING_sc0 STR_s STR_c "\0" -#define STRING_sd0 STR_s STR_d "\0" -#define STRING_sentenceterminal0 STR_s STR_e STR_n STR_t STR_e STR_n STR_c STR_e STR_t STR_e STR_r STR_m STR_i STR_n STR_a STR_l "\0" -#define STRING_sgnw0 STR_s STR_g STR_n STR_w "\0" -#define STRING_sharada0 STR_s STR_h STR_a STR_r STR_a STR_d STR_a "\0" -#define STRING_shavian0 STR_s STR_h STR_a STR_v STR_i STR_a STR_n "\0" -#define STRING_shaw0 STR_s STR_h STR_a STR_w "\0" -#define STRING_shrd0 STR_s STR_h STR_r STR_d "\0" -#define STRING_sidd0 STR_s STR_i STR_d STR_d "\0" -#define STRING_siddham0 STR_s STR_i STR_d STR_d STR_h STR_a STR_m "\0" -#define STRING_signwriting0 STR_s STR_i STR_g STR_n STR_w STR_r STR_i STR_t STR_i STR_n STR_g "\0" -#define STRING_sind0 STR_s STR_i STR_n STR_d "\0" -#define STRING_sinh0 STR_s STR_i STR_n STR_h "\0" -#define STRING_sinhala0 STR_s STR_i STR_n STR_h STR_a STR_l STR_a "\0" -#define STRING_sk0 STR_s STR_k "\0" -#define STRING_sm0 STR_s STR_m "\0" -#define STRING_so0 STR_s STR_o "\0" -#define STRING_softdotted0 STR_s STR_o STR_f STR_t STR_d STR_o STR_t STR_t STR_e STR_d "\0" -#define STRING_sogd0 STR_s STR_o STR_g STR_d "\0" -#define STRING_sogdian0 STR_s STR_o STR_g STR_d STR_i STR_a STR_n "\0" -#define STRING_sogo0 STR_s STR_o STR_g STR_o "\0" -#define STRING_sora0 STR_s STR_o STR_r STR_a "\0" -#define STRING_sorasompeng0 STR_s STR_o STR_r STR_a STR_s STR_o STR_m STR_p STR_e STR_n STR_g "\0" -#define STRING_soyo0 STR_s STR_o STR_y STR_o "\0" -#define STRING_soyombo0 STR_s STR_o STR_y STR_o STR_m STR_b STR_o "\0" -#define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0" -#define STRING_sterm0 STR_s STR_t STR_e STR_r STR_m "\0" -#define STRING_sund0 STR_s STR_u STR_n STR_d "\0" -#define STRING_sundanese0 STR_s STR_u STR_n STR_d STR_a STR_n STR_e STR_s STR_e "\0" -#define STRING_sunu0 STR_s STR_u STR_n STR_u "\0" -#define STRING_sunuwar0 STR_s STR_u STR_n STR_u STR_w STR_a STR_r "\0" -#define STRING_sylo0 STR_s STR_y STR_l STR_o "\0" -#define STRING_sylotinagri0 STR_s STR_y STR_l STR_o STR_t STR_i STR_n STR_a STR_g STR_r STR_i "\0" -#define STRING_syrc0 STR_s STR_y STR_r STR_c "\0" -#define STRING_syriac0 STR_s STR_y STR_r STR_i STR_a STR_c "\0" -#define STRING_tagalog0 STR_t STR_a STR_g STR_a STR_l STR_o STR_g "\0" -#define STRING_tagb0 STR_t STR_a STR_g STR_b "\0" -#define STRING_tagbanwa0 STR_t STR_a STR_g STR_b STR_a STR_n STR_w STR_a "\0" -#define STRING_taile0 STR_t STR_a STR_i STR_l STR_e "\0" -#define STRING_taitham0 STR_t STR_a STR_i STR_t STR_h STR_a STR_m "\0" -#define STRING_taiviet0 STR_t STR_a STR_i STR_v STR_i STR_e STR_t "\0" -#define STRING_takr0 STR_t STR_a STR_k STR_r "\0" -#define STRING_takri0 STR_t STR_a STR_k STR_r STR_i "\0" -#define STRING_tale0 STR_t STR_a STR_l STR_e "\0" -#define STRING_talu0 STR_t STR_a STR_l STR_u "\0" -#define STRING_tamil0 STR_t STR_a STR_m STR_i STR_l "\0" -#define STRING_taml0 STR_t STR_a STR_m STR_l "\0" -#define STRING_tang0 STR_t STR_a STR_n STR_g "\0" -#define STRING_tangsa0 STR_t STR_a STR_n STR_g STR_s STR_a "\0" -#define STRING_tangut0 STR_t STR_a STR_n STR_g STR_u STR_t "\0" -#define STRING_tavt0 STR_t STR_a STR_v STR_t "\0" -#define STRING_telu0 STR_t STR_e STR_l STR_u "\0" -#define STRING_telugu0 STR_t STR_e STR_l STR_u STR_g STR_u "\0" -#define STRING_term0 STR_t STR_e STR_r STR_m "\0" -#define STRING_terminalpunctuation0 STR_t STR_e STR_r STR_m STR_i STR_n STR_a STR_l STR_p STR_u STR_n STR_c STR_t STR_u STR_a STR_t STR_i STR_o STR_n "\0" -#define STRING_tfng0 STR_t STR_f STR_n STR_g "\0" -#define STRING_tglg0 STR_t STR_g STR_l STR_g "\0" -#define STRING_thaa0 STR_t STR_h STR_a STR_a "\0" -#define STRING_thaana0 STR_t STR_h STR_a STR_a STR_n STR_a "\0" -#define STRING_thai0 STR_t STR_h STR_a STR_i "\0" -#define STRING_tibetan0 STR_t STR_i STR_b STR_e STR_t STR_a STR_n "\0" -#define STRING_tibt0 STR_t STR_i STR_b STR_t "\0" -#define STRING_tifinagh0 STR_t STR_i STR_f STR_i STR_n STR_a STR_g STR_h "\0" -#define STRING_tirh0 STR_t STR_i STR_r STR_h "\0" -#define STRING_tirhuta0 STR_t STR_i STR_r STR_h STR_u STR_t STR_a "\0" -#define STRING_tnsa0 STR_t STR_n STR_s STR_a "\0" -#define STRING_todhri0 STR_t STR_o STR_d STR_h STR_r STR_i "\0" -#define STRING_todr0 STR_t STR_o STR_d STR_r "\0" -#define STRING_toto0 STR_t STR_o STR_t STR_o "\0" -#define STRING_tulutigalari0 STR_t STR_u STR_l STR_u STR_t STR_i STR_g STR_a STR_l STR_a STR_r STR_i "\0" -#define STRING_tutg0 STR_t STR_u STR_t STR_g "\0" -#define STRING_ugar0 STR_u STR_g STR_a STR_r "\0" -#define STRING_ugaritic0 STR_u STR_g STR_a STR_r STR_i STR_t STR_i STR_c "\0" -#define STRING_uideo0 STR_u STR_i STR_d STR_e STR_o "\0" -#define STRING_unifiedideograph0 STR_u STR_n STR_i STR_f STR_i STR_e STR_d STR_i STR_d STR_e STR_o STR_g STR_r STR_a STR_p STR_h "\0" -#define STRING_unknown0 STR_u STR_n STR_k STR_n STR_o STR_w STR_n "\0" -#define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0" -#define STRING_uppercase0 STR_u STR_p STR_p STR_e STR_r STR_c STR_a STR_s STR_e "\0" -#define STRING_vai0 STR_v STR_a STR_i "\0" -#define STRING_vaii0 STR_v STR_a STR_i STR_i "\0" -#define STRING_variationselector0 STR_v STR_a STR_r STR_i STR_a STR_t STR_i STR_o STR_n STR_s STR_e STR_l STR_e STR_c STR_t STR_o STR_r "\0" -#define STRING_vith0 STR_v STR_i STR_t STR_h "\0" -#define STRING_vithkuqi0 STR_v STR_i STR_t STR_h STR_k STR_u STR_q STR_i "\0" -#define STRING_vs0 STR_v STR_s "\0" -#define STRING_wancho0 STR_w STR_a STR_n STR_c STR_h STR_o "\0" -#define STRING_wara0 STR_w STR_a STR_r STR_a "\0" -#define STRING_warangciti0 STR_w STR_a STR_r STR_a STR_n STR_g STR_c STR_i STR_t STR_i "\0" -#define STRING_wcho0 STR_w STR_c STR_h STR_o "\0" -#define STRING_whitespace0 STR_w STR_h STR_i STR_t STR_e STR_s STR_p STR_a STR_c STR_e "\0" -#define STRING_wspace0 STR_w STR_s STR_p STR_a STR_c STR_e "\0" -#define STRING_xan0 STR_x STR_a STR_n "\0" -#define STRING_xidc0 STR_x STR_i STR_d STR_c "\0" -#define STRING_xidcontinue0 STR_x STR_i STR_d STR_c STR_o STR_n STR_t STR_i STR_n STR_u STR_e "\0" -#define STRING_xids0 STR_x STR_i STR_d STR_s "\0" -#define STRING_xidstart0 STR_x STR_i STR_d STR_s STR_t STR_a STR_r STR_t "\0" -#define STRING_xpeo0 STR_x STR_p STR_e STR_o "\0" -#define STRING_xps0 STR_x STR_p STR_s "\0" -#define STRING_xsp0 STR_x STR_s STR_p "\0" -#define STRING_xsux0 STR_x STR_s STR_u STR_x "\0" -#define STRING_xuc0 STR_x STR_u STR_c "\0" -#define STRING_xwd0 STR_x STR_w STR_d "\0" -#define STRING_yezi0 STR_y STR_e STR_z STR_i "\0" -#define STRING_yezidi0 STR_y STR_e STR_z STR_i STR_d STR_i "\0" -#define STRING_yi0 STR_y STR_i "\0" -#define STRING_yiii0 STR_y STR_i STR_i STR_i "\0" -#define STRING_z0 STR_z "\0" -#define STRING_zanabazarsquare0 STR_z STR_a STR_n STR_a STR_b STR_a STR_z STR_a STR_r STR_s STR_q STR_u STR_a STR_r STR_e "\0" -#define STRING_zanb0 STR_z STR_a STR_n STR_b "\0" -#define STRING_zinh0 STR_z STR_i STR_n STR_h "\0" -#define STRING_zl0 STR_z STR_l "\0" -#define STRING_zp0 STR_z STR_p "\0" -#define STRING_zs0 STR_z STR_s "\0" -#define STRING_zyyy0 STR_z STR_y STR_y STR_y "\0" -#define STRING_zzzz0 STR_z STR_z STR_z STR_z "\0" - -const char PRIV(utt_names)[] = - STRING_adlam0 - STRING_adlm0 - STRING_aghb0 - STRING_ahex0 - STRING_ahom0 - STRING_alpha0 - STRING_alphabetic0 - STRING_anatolianhieroglyphs0 - STRING_any0 - STRING_arab0 - STRING_arabic0 - STRING_armenian0 - STRING_armi0 - STRING_armn0 - STRING_ascii0 - STRING_asciihexdigit0 - STRING_avestan0 - STRING_avst0 - STRING_bali0 - STRING_balinese0 - STRING_bamu0 - STRING_bamum0 - STRING_bass0 - STRING_bassavah0 - STRING_batak0 - STRING_batk0 - STRING_beng0 - STRING_bengali0 - STRING_bhaiksuki0 - STRING_bhks0 - STRING_bidial0 - STRING_bidian0 - STRING_bidib0 - STRING_bidibn0 - STRING_bidic0 - STRING_bidicontrol0 - STRING_bidics0 - STRING_bidien0 - STRING_bidies0 - STRING_bidiet0 - STRING_bidifsi0 - STRING_bidil0 - STRING_bidilre0 - STRING_bidilri0 - STRING_bidilro0 - STRING_bidim0 - STRING_bidimirrored0 - STRING_bidinsm0 - STRING_bidion0 - STRING_bidipdf0 - STRING_bidipdi0 - STRING_bidir0 - STRING_bidirle0 - STRING_bidirli0 - STRING_bidirlo0 - STRING_bidis0 - STRING_bidiws0 - STRING_bopo0 - STRING_bopomofo0 - STRING_brah0 - STRING_brahmi0 - STRING_brai0 - STRING_braille0 - STRING_bugi0 - STRING_buginese0 - STRING_buhd0 - STRING_buhid0 - STRING_c0 - STRING_cakm0 - STRING_canadianaboriginal0 - STRING_cans0 - STRING_cari0 - STRING_carian0 - STRING_cased0 - STRING_caseignorable0 - STRING_caucasianalbanian0 - STRING_cc0 - STRING_cf0 - STRING_chakma0 - STRING_cham0 - STRING_changeswhencasefolded0 - STRING_changeswhencasemapped0 - STRING_changeswhenlowercased0 - STRING_changeswhentitlecased0 - STRING_changeswhenuppercased0 - STRING_cher0 - STRING_cherokee0 - STRING_chorasmian0 - STRING_chrs0 - STRING_ci0 - STRING_cn0 - STRING_co0 - STRING_common0 - STRING_copt0 - STRING_coptic0 - STRING_cpmn0 - STRING_cprt0 - STRING_cs0 - STRING_cuneiform0 - STRING_cwcf0 - STRING_cwcm0 - STRING_cwl0 - STRING_cwt0 - STRING_cwu0 - STRING_cypriot0 - STRING_cyprominoan0 - STRING_cyrillic0 - STRING_cyrl0 - STRING_dash0 - STRING_defaultignorablecodepoint0 - STRING_dep0 - STRING_deprecated0 - STRING_deseret0 - STRING_deva0 - STRING_devanagari0 - STRING_di0 - STRING_dia0 - STRING_diacritic0 - STRING_diak0 - STRING_divesakuru0 - STRING_dogr0 - STRING_dogra0 - STRING_dsrt0 - STRING_dupl0 - STRING_duployan0 - STRING_ebase0 - STRING_ecomp0 - STRING_egyp0 - STRING_egyptianhieroglyphs0 - STRING_elba0 - STRING_elbasan0 - STRING_elym0 - STRING_elymaic0 - STRING_emod0 - STRING_emoji0 - STRING_emojicomponent0 - STRING_emojimodifier0 - STRING_emojimodifierbase0 - STRING_emojipresentation0 - STRING_epres0 - STRING_ethi0 - STRING_ethiopic0 - STRING_ext0 - STRING_extendedpictographic0 - STRING_extender0 - STRING_extpict0 - STRING_gara0 - STRING_garay0 - STRING_geor0 - STRING_georgian0 - STRING_glag0 - STRING_glagolitic0 - STRING_gong0 - STRING_gonm0 - STRING_goth0 - STRING_gothic0 - STRING_gran0 - STRING_grantha0 - STRING_graphemebase0 - STRING_graphemeextend0 - STRING_graphemelink0 - STRING_grbase0 - STRING_greek0 - STRING_grek0 - STRING_grext0 - STRING_grlink0 - STRING_gujarati0 - STRING_gujr0 - STRING_gukh0 - STRING_gunjalagondi0 - STRING_gurmukhi0 - STRING_guru0 - STRING_gurungkhema0 - STRING_han0 - STRING_hang0 - STRING_hangul0 - STRING_hani0 - STRING_hanifirohingya0 - STRING_hano0 - STRING_hanunoo0 - STRING_hatr0 - STRING_hatran0 - STRING_hebr0 - STRING_hebrew0 - STRING_hex0 - STRING_hexdigit0 - STRING_hira0 - STRING_hiragana0 - STRING_hluw0 - STRING_hmng0 - STRING_hmnp0 - STRING_hung0 - STRING_idc0 - STRING_idcompatmathcontinue0 - STRING_idcompatmathstart0 - STRING_idcontinue0 - STRING_ideo0 - STRING_ideographic0 - STRING_ids0 - STRING_idsb0 - STRING_idsbinaryoperator0 - STRING_idst0 - STRING_idstart0 - STRING_idstrinaryoperator0 - STRING_idsu0 - STRING_idsunaryoperator0 - STRING_imperialaramaic0 - STRING_incb0 - STRING_inherited0 - STRING_inscriptionalpahlavi0 - STRING_inscriptionalparthian0 - STRING_ital0 - STRING_java0 - STRING_javanese0 - STRING_joinc0 - STRING_joincontrol0 - STRING_kaithi0 - STRING_kali0 - STRING_kana0 - STRING_kannada0 - STRING_katakana0 - STRING_kawi0 - STRING_kayahli0 - STRING_khar0 - STRING_kharoshthi0 - STRING_khitansmallscript0 - STRING_khmer0 - STRING_khmr0 - STRING_khoj0 - STRING_khojki0 - STRING_khudawadi0 - STRING_kiratrai0 - STRING_kits0 - STRING_knda0 - STRING_krai0 - STRING_kthi0 - STRING_l0 - STRING_l_AMPERSAND0 - STRING_lana0 - STRING_lao0 - STRING_laoo0 - STRING_latin0 - STRING_latn0 - STRING_lc0 - STRING_lepc0 - STRING_lepcha0 - STRING_limb0 - STRING_limbu0 - STRING_lina0 - STRING_linb0 - STRING_lineara0 - STRING_linearb0 - STRING_lisu0 - STRING_ll0 - STRING_lm0 - STRING_lo0 - STRING_loe0 - STRING_logicalorderexception0 - STRING_lower0 - STRING_lowercase0 - STRING_lt0 - STRING_lu0 - STRING_lyci0 - STRING_lycian0 - STRING_lydi0 - STRING_lydian0 - STRING_m0 - STRING_mahajani0 - STRING_mahj0 - STRING_maka0 - STRING_makasar0 - STRING_malayalam0 - STRING_mand0 - STRING_mandaic0 - STRING_mani0 - STRING_manichaean0 - STRING_marc0 - STRING_marchen0 - STRING_masaramgondi0 - STRING_math0 - STRING_mc0 - STRING_mcm0 - STRING_me0 - STRING_medefaidrin0 - STRING_medf0 - STRING_meeteimayek0 - STRING_mend0 - STRING_mendekikakui0 - STRING_merc0 - STRING_mero0 - STRING_meroiticcursive0 - STRING_meroitichieroglyphs0 - STRING_miao0 - STRING_mlym0 - STRING_mn0 - STRING_modi0 - STRING_modifiercombiningmark0 - STRING_mong0 - STRING_mongolian0 - STRING_mro0 - STRING_mroo0 - STRING_mtei0 - STRING_mult0 - STRING_multani0 - STRING_myanmar0 - STRING_mymr0 - STRING_n0 - STRING_nabataean0 - STRING_nagm0 - STRING_nagmundari0 - STRING_nand0 - STRING_nandinagari0 - STRING_narb0 - STRING_nbat0 - STRING_nchar0 - STRING_nd0 - STRING_newa0 - STRING_newtailue0 - STRING_nko0 - STRING_nkoo0 - STRING_nl0 - STRING_no0 - STRING_noncharactercodepoint0 - STRING_nshu0 - STRING_nushu0 - STRING_nyiakengpuachuehmong0 - STRING_ogam0 - STRING_ogham0 - STRING_olchiki0 - STRING_olck0 - STRING_oldhungarian0 - STRING_olditalic0 - STRING_oldnortharabian0 - STRING_oldpermic0 - STRING_oldpersian0 - STRING_oldsogdian0 - STRING_oldsoutharabian0 - STRING_oldturkic0 - STRING_olduyghur0 - STRING_olonal0 - STRING_onao0 - STRING_oriya0 - STRING_orkh0 - STRING_orya0 - STRING_osage0 - STRING_osge0 - STRING_osma0 - STRING_osmanya0 - STRING_ougr0 - STRING_p0 - STRING_pahawhhmong0 - STRING_palm0 - STRING_palmyrene0 - STRING_patsyn0 - STRING_patternsyntax0 - STRING_patternwhitespace0 - STRING_patws0 - STRING_pauc0 - STRING_paucinhau0 - STRING_pc0 - STRING_pcm0 - STRING_pd0 - STRING_pe0 - STRING_perm0 - STRING_pf0 - STRING_phag0 - STRING_phagspa0 - STRING_phli0 - STRING_phlp0 - STRING_phnx0 - STRING_phoenician0 - STRING_pi0 - STRING_plrd0 - STRING_po0 - STRING_prependedconcatenationmark0 - STRING_prti0 - STRING_ps0 - STRING_psalterpahlavi0 - STRING_qaac0 - STRING_qaai0 - STRING_qmark0 - STRING_quotationmark0 - STRING_radical0 - STRING_regionalindicator0 - STRING_rejang0 - STRING_ri0 - STRING_rjng0 - STRING_rohg0 - STRING_runic0 - STRING_runr0 - STRING_s0 - STRING_samaritan0 - STRING_samr0 - STRING_sarb0 - STRING_saur0 - STRING_saurashtra0 - STRING_sc0 - STRING_sd0 - STRING_sentenceterminal0 - STRING_sgnw0 - STRING_sharada0 - STRING_shavian0 - STRING_shaw0 - STRING_shrd0 - STRING_sidd0 - STRING_siddham0 - STRING_signwriting0 - STRING_sind0 - STRING_sinh0 - STRING_sinhala0 - STRING_sk0 - STRING_sm0 - STRING_so0 - STRING_softdotted0 - STRING_sogd0 - STRING_sogdian0 - STRING_sogo0 - STRING_sora0 - STRING_sorasompeng0 - STRING_soyo0 - STRING_soyombo0 - STRING_space0 - STRING_sterm0 - STRING_sund0 - STRING_sundanese0 - STRING_sunu0 - STRING_sunuwar0 - STRING_sylo0 - STRING_sylotinagri0 - STRING_syrc0 - STRING_syriac0 - STRING_tagalog0 - STRING_tagb0 - STRING_tagbanwa0 - STRING_taile0 - STRING_taitham0 - STRING_taiviet0 - STRING_takr0 - STRING_takri0 - STRING_tale0 - STRING_talu0 - STRING_tamil0 - STRING_taml0 - STRING_tang0 - STRING_tangsa0 - STRING_tangut0 - STRING_tavt0 - STRING_telu0 - STRING_telugu0 - STRING_term0 - STRING_terminalpunctuation0 - STRING_tfng0 - STRING_tglg0 - STRING_thaa0 - STRING_thaana0 - STRING_thai0 - STRING_tibetan0 - STRING_tibt0 - STRING_tifinagh0 - STRING_tirh0 - STRING_tirhuta0 - STRING_tnsa0 - STRING_todhri0 - STRING_todr0 - STRING_toto0 - STRING_tulutigalari0 - STRING_tutg0 - STRING_ugar0 - STRING_ugaritic0 - STRING_uideo0 - STRING_unifiedideograph0 - STRING_unknown0 - STRING_upper0 - STRING_uppercase0 - STRING_vai0 - STRING_vaii0 - STRING_variationselector0 - STRING_vith0 - STRING_vithkuqi0 - STRING_vs0 - STRING_wancho0 - STRING_wara0 - STRING_warangciti0 - STRING_wcho0 - STRING_whitespace0 - STRING_wspace0 - STRING_xan0 - STRING_xidc0 - STRING_xidcontinue0 - STRING_xids0 - STRING_xidstart0 - STRING_xpeo0 - STRING_xps0 - STRING_xsp0 - STRING_xsux0 - STRING_xuc0 - STRING_xwd0 - STRING_yezi0 - STRING_yezidi0 - STRING_yi0 - STRING_yiii0 - STRING_z0 - STRING_zanabazarsquare0 - STRING_zanb0 - STRING_zinh0 - STRING_zl0 - STRING_zp0 - STRING_zs0 - STRING_zyyy0 - STRING_zzzz0; - -const ucp_type_table PRIV(utt)[] = { - { 0, PT_SCX, ucp_Adlam }, - { 6, PT_SCX, ucp_Adlam }, - { 11, PT_SCX, ucp_Caucasian_Albanian }, - { 16, PT_BOOL, ucp_ASCII_Hex_Digit }, - { 21, PT_SC, ucp_Ahom }, - { 26, PT_BOOL, ucp_Alphabetic }, - { 32, PT_BOOL, ucp_Alphabetic }, - { 43, PT_SC, ucp_Anatolian_Hieroglyphs }, - { 64, PT_ANY, 0 }, - { 68, PT_SCX, ucp_Arabic }, - { 73, PT_SCX, ucp_Arabic }, - { 80, PT_SCX, ucp_Armenian }, - { 89, PT_SC, ucp_Imperial_Aramaic }, - { 94, PT_SCX, ucp_Armenian }, - { 99, PT_BOOL, ucp_ASCII }, - { 105, PT_BOOL, ucp_ASCII_Hex_Digit }, - { 119, PT_SCX, ucp_Avestan }, - { 127, PT_SCX, ucp_Avestan }, - { 132, PT_SC, ucp_Balinese }, - { 137, PT_SC, ucp_Balinese }, - { 146, PT_SC, ucp_Bamum }, - { 151, PT_SC, ucp_Bamum }, - { 157, PT_SC, ucp_Bassa_Vah }, - { 162, PT_SC, ucp_Bassa_Vah }, - { 171, PT_SC, ucp_Batak }, - { 177, PT_SC, ucp_Batak }, - { 182, PT_SCX, ucp_Bengali }, - { 187, PT_SCX, ucp_Bengali }, - { 195, PT_SC, ucp_Bhaiksuki }, - { 205, PT_SC, ucp_Bhaiksuki }, - { 210, PT_BIDICL, ucp_bidiAL }, - { 217, PT_BIDICL, ucp_bidiAN }, - { 224, PT_BIDICL, ucp_bidiB }, - { 230, PT_BIDICL, ucp_bidiBN }, - { 237, PT_BOOL, ucp_Bidi_Control }, - { 243, PT_BOOL, ucp_Bidi_Control }, - { 255, PT_BIDICL, ucp_bidiCS }, - { 262, PT_BIDICL, ucp_bidiEN }, - { 269, PT_BIDICL, ucp_bidiES }, - { 276, PT_BIDICL, ucp_bidiET }, - { 283, PT_BIDICL, ucp_bidiFSI }, - { 291, PT_BIDICL, ucp_bidiL }, - { 297, PT_BIDICL, ucp_bidiLRE }, - { 305, PT_BIDICL, ucp_bidiLRI }, - { 313, PT_BIDICL, ucp_bidiLRO }, - { 321, PT_BOOL, ucp_Bidi_Mirrored }, - { 327, PT_BOOL, ucp_Bidi_Mirrored }, - { 340, PT_BIDICL, ucp_bidiNSM }, - { 348, PT_BIDICL, ucp_bidiON }, - { 355, PT_BIDICL, ucp_bidiPDF }, - { 363, PT_BIDICL, ucp_bidiPDI }, - { 371, PT_BIDICL, ucp_bidiR }, - { 377, PT_BIDICL, ucp_bidiRLE }, - { 385, PT_BIDICL, ucp_bidiRLI }, - { 393, PT_BIDICL, ucp_bidiRLO }, - { 401, PT_BIDICL, ucp_bidiS }, - { 407, PT_BIDICL, ucp_bidiWS }, - { 414, PT_SCX, ucp_Bopomofo }, - { 419, PT_SCX, ucp_Bopomofo }, - { 428, PT_SC, ucp_Brahmi }, - { 433, PT_SC, ucp_Brahmi }, - { 440, PT_SC, ucp_Braille }, - { 445, PT_SC, ucp_Braille }, - { 453, PT_SCX, ucp_Buginese }, - { 458, PT_SCX, ucp_Buginese }, - { 467, PT_SCX, ucp_Buhid }, - { 472, PT_SCX, ucp_Buhid }, - { 478, PT_GC, ucp_C }, - { 480, PT_SCX, ucp_Chakma }, - { 485, PT_SC, ucp_Canadian_Aboriginal }, - { 504, PT_SC, ucp_Canadian_Aboriginal }, - { 509, PT_SCX, ucp_Carian }, - { 514, PT_SCX, ucp_Carian }, - { 521, PT_BOOL, ucp_Cased }, - { 527, PT_BOOL, ucp_Case_Ignorable }, - { 541, PT_SCX, ucp_Caucasian_Albanian }, - { 559, PT_PC, ucp_Cc }, - { 562, PT_PC, ucp_Cf }, - { 565, PT_SCX, ucp_Chakma }, - { 572, PT_SC, ucp_Cham }, - { 577, PT_BOOL, ucp_Changes_When_Casefolded }, - { 599, PT_BOOL, ucp_Changes_When_Casemapped }, - { 621, PT_BOOL, ucp_Changes_When_Lowercased }, - { 643, PT_BOOL, ucp_Changes_When_Titlecased }, - { 665, PT_BOOL, ucp_Changes_When_Uppercased }, - { 687, PT_SCX, ucp_Cherokee }, - { 692, PT_SCX, ucp_Cherokee }, - { 701, PT_SC, ucp_Chorasmian }, - { 712, PT_SC, ucp_Chorasmian }, - { 717, PT_BOOL, ucp_Case_Ignorable }, - { 720, PT_PC, ucp_Cn }, - { 723, PT_PC, ucp_Co }, - { 726, PT_SC, ucp_Common }, - { 733, PT_SCX, ucp_Coptic }, - { 738, PT_SCX, ucp_Coptic }, - { 745, PT_SCX, ucp_Cypro_Minoan }, - { 750, PT_SCX, ucp_Cypriot }, - { 755, PT_PC, ucp_Cs }, - { 758, PT_SC, ucp_Cuneiform }, - { 768, PT_BOOL, ucp_Changes_When_Casefolded }, - { 773, PT_BOOL, ucp_Changes_When_Casemapped }, - { 778, PT_BOOL, ucp_Changes_When_Lowercased }, - { 782, PT_BOOL, ucp_Changes_When_Titlecased }, - { 786, PT_BOOL, ucp_Changes_When_Uppercased }, - { 790, PT_SCX, ucp_Cypriot }, - { 798, PT_SCX, ucp_Cypro_Minoan }, - { 810, PT_SCX, ucp_Cyrillic }, - { 819, PT_SCX, ucp_Cyrillic }, - { 824, PT_BOOL, ucp_Dash }, - { 829, PT_BOOL, ucp_Default_Ignorable_Code_Point }, - { 855, PT_BOOL, ucp_Deprecated }, - { 859, PT_BOOL, ucp_Deprecated }, - { 870, PT_SC, ucp_Deseret }, - { 878, PT_SCX, ucp_Devanagari }, - { 883, PT_SCX, ucp_Devanagari }, - { 894, PT_BOOL, ucp_Default_Ignorable_Code_Point }, - { 897, PT_BOOL, ucp_Diacritic }, - { 901, PT_BOOL, ucp_Diacritic }, - { 911, PT_SC, ucp_Dives_Akuru }, - { 916, PT_SC, ucp_Dives_Akuru }, - { 927, PT_SCX, ucp_Dogra }, - { 932, PT_SCX, ucp_Dogra }, - { 938, PT_SC, ucp_Deseret }, - { 943, PT_SCX, ucp_Duployan }, - { 948, PT_SCX, ucp_Duployan }, - { 957, PT_BOOL, ucp_Emoji_Modifier_Base }, - { 963, PT_BOOL, ucp_Emoji_Component }, - { 969, PT_SC, ucp_Egyptian_Hieroglyphs }, - { 974, PT_SC, ucp_Egyptian_Hieroglyphs }, - { 994, PT_SCX, ucp_Elbasan }, - { 999, PT_SCX, ucp_Elbasan }, - { 1007, PT_SC, ucp_Elymaic }, - { 1012, PT_SC, ucp_Elymaic }, - { 1020, PT_BOOL, ucp_Emoji_Modifier }, - { 1025, PT_BOOL, ucp_Emoji }, - { 1031, PT_BOOL, ucp_Emoji_Component }, - { 1046, PT_BOOL, ucp_Emoji_Modifier }, - { 1060, PT_BOOL, ucp_Emoji_Modifier_Base }, - { 1078, PT_BOOL, ucp_Emoji_Presentation }, - { 1096, PT_BOOL, ucp_Emoji_Presentation }, - { 1102, PT_SCX, ucp_Ethiopic }, - { 1107, PT_SCX, ucp_Ethiopic }, - { 1116, PT_BOOL, ucp_Extender }, - { 1120, PT_BOOL, ucp_Extended_Pictographic }, - { 1141, PT_BOOL, ucp_Extender }, - { 1150, PT_BOOL, ucp_Extended_Pictographic }, - { 1158, PT_SCX, ucp_Garay }, - { 1163, PT_SCX, ucp_Garay }, - { 1169, PT_SCX, ucp_Georgian }, - { 1174, PT_SCX, ucp_Georgian }, - { 1183, PT_SCX, ucp_Glagolitic }, - { 1188, PT_SCX, ucp_Glagolitic }, - { 1199, PT_SCX, ucp_Gunjala_Gondi }, - { 1204, PT_SCX, ucp_Masaram_Gondi }, - { 1209, PT_SCX, ucp_Gothic }, - { 1214, PT_SCX, ucp_Gothic }, - { 1221, PT_SCX, ucp_Grantha }, - { 1226, PT_SCX, ucp_Grantha }, - { 1234, PT_BOOL, ucp_Grapheme_Base }, - { 1247, PT_BOOL, ucp_Grapheme_Extend }, - { 1262, PT_BOOL, ucp_Grapheme_Link }, - { 1275, PT_BOOL, ucp_Grapheme_Base }, - { 1282, PT_SCX, ucp_Greek }, - { 1288, PT_SCX, ucp_Greek }, - { 1293, PT_BOOL, ucp_Grapheme_Extend }, - { 1299, PT_BOOL, ucp_Grapheme_Link }, - { 1306, PT_SCX, ucp_Gujarati }, - { 1315, PT_SCX, ucp_Gujarati }, - { 1320, PT_SCX, ucp_Gurung_Khema }, - { 1325, PT_SCX, ucp_Gunjala_Gondi }, - { 1338, PT_SCX, ucp_Gurmukhi }, - { 1347, PT_SCX, ucp_Gurmukhi }, - { 1352, PT_SCX, ucp_Gurung_Khema }, - { 1364, PT_SCX, ucp_Han }, - { 1368, PT_SCX, ucp_Hangul }, - { 1373, PT_SCX, ucp_Hangul }, - { 1380, PT_SCX, ucp_Han }, - { 1385, PT_SCX, ucp_Hanifi_Rohingya }, - { 1400, PT_SCX, ucp_Hanunoo }, - { 1405, PT_SCX, ucp_Hanunoo }, - { 1413, PT_SC, ucp_Hatran }, - { 1418, PT_SC, ucp_Hatran }, - { 1425, PT_SCX, ucp_Hebrew }, - { 1430, PT_SCX, ucp_Hebrew }, - { 1437, PT_BOOL, ucp_Hex_Digit }, - { 1441, PT_BOOL, ucp_Hex_Digit }, - { 1450, PT_SCX, ucp_Hiragana }, - { 1455, PT_SCX, ucp_Hiragana }, - { 1464, PT_SC, ucp_Anatolian_Hieroglyphs }, - { 1469, PT_SC, ucp_Pahawh_Hmong }, - { 1474, PT_SC, ucp_Nyiakeng_Puachue_Hmong }, - { 1479, PT_SCX, ucp_Old_Hungarian }, - { 1484, PT_BOOL, ucp_ID_Continue }, - { 1488, PT_BOOL, ucp_ID_Compat_Math_Continue }, - { 1509, PT_BOOL, ucp_ID_Compat_Math_Start }, - { 1527, PT_BOOL, ucp_ID_Continue }, - { 1538, PT_BOOL, ucp_Ideographic }, - { 1543, PT_BOOL, ucp_Ideographic }, - { 1555, PT_BOOL, ucp_ID_Start }, - { 1559, PT_BOOL, ucp_IDS_Binary_Operator }, - { 1564, PT_BOOL, ucp_IDS_Binary_Operator }, - { 1582, PT_BOOL, ucp_IDS_Trinary_Operator }, - { 1587, PT_BOOL, ucp_ID_Start }, - { 1595, PT_BOOL, ucp_IDS_Trinary_Operator }, - { 1614, PT_BOOL, ucp_IDS_Unary_Operator }, - { 1619, PT_BOOL, ucp_IDS_Unary_Operator }, - { 1636, PT_SC, ucp_Imperial_Aramaic }, - { 1652, PT_BOOL, ucp_InCB }, - { 1657, PT_SC, ucp_Inherited }, - { 1667, PT_SC, ucp_Inscriptional_Pahlavi }, - { 1688, PT_SC, ucp_Inscriptional_Parthian }, - { 1710, PT_SC, ucp_Old_Italic }, - { 1715, PT_SCX, ucp_Javanese }, - { 1720, PT_SCX, ucp_Javanese }, - { 1729, PT_BOOL, ucp_Join_Control }, - { 1735, PT_BOOL, ucp_Join_Control }, - { 1747, PT_SCX, ucp_Kaithi }, - { 1754, PT_SCX, ucp_Kayah_Li }, - { 1759, PT_SCX, ucp_Katakana }, - { 1764, PT_SCX, ucp_Kannada }, - { 1772, PT_SCX, ucp_Katakana }, - { 1781, PT_SC, ucp_Kawi }, - { 1786, PT_SCX, ucp_Kayah_Li }, - { 1794, PT_SC, ucp_Kharoshthi }, - { 1799, PT_SC, ucp_Kharoshthi }, - { 1810, PT_SC, ucp_Khitan_Small_Script }, - { 1828, PT_SC, ucp_Khmer }, - { 1834, PT_SC, ucp_Khmer }, - { 1839, PT_SCX, ucp_Khojki }, - { 1844, PT_SCX, ucp_Khojki }, - { 1851, PT_SCX, ucp_Khudawadi }, - { 1861, PT_SC, ucp_Kirat_Rai }, - { 1870, PT_SC, ucp_Khitan_Small_Script }, - { 1875, PT_SCX, ucp_Kannada }, - { 1880, PT_SC, ucp_Kirat_Rai }, - { 1885, PT_SCX, ucp_Kaithi }, - { 1890, PT_GC, ucp_L }, - { 1892, PT_LAMP, 0 }, - { 1895, PT_SC, ucp_Tai_Tham }, - { 1900, PT_SC, ucp_Lao }, - { 1904, PT_SC, ucp_Lao }, - { 1909, PT_SCX, ucp_Latin }, - { 1915, PT_SCX, ucp_Latin }, - { 1920, PT_LAMP, 0 }, - { 1923, PT_SC, ucp_Lepcha }, - { 1928, PT_SC, ucp_Lepcha }, - { 1935, PT_SCX, ucp_Limbu }, - { 1940, PT_SCX, ucp_Limbu }, - { 1946, PT_SCX, ucp_Linear_A }, - { 1951, PT_SCX, ucp_Linear_B }, - { 1956, PT_SCX, ucp_Linear_A }, - { 1964, PT_SCX, ucp_Linear_B }, - { 1972, PT_SCX, ucp_Lisu }, - { 1977, PT_PC, ucp_Ll }, - { 1980, PT_PC, ucp_Lm }, - { 1983, PT_PC, ucp_Lo }, - { 1986, PT_BOOL, ucp_Logical_Order_Exception }, - { 1990, PT_BOOL, ucp_Logical_Order_Exception }, - { 2012, PT_BOOL, ucp_Lowercase }, - { 2018, PT_BOOL, ucp_Lowercase }, - { 2028, PT_PC, ucp_Lt }, - { 2031, PT_PC, ucp_Lu }, - { 2034, PT_SCX, ucp_Lycian }, - { 2039, PT_SCX, ucp_Lycian }, - { 2046, PT_SCX, ucp_Lydian }, - { 2051, PT_SCX, ucp_Lydian }, - { 2058, PT_GC, ucp_M }, - { 2060, PT_SCX, ucp_Mahajani }, - { 2069, PT_SCX, ucp_Mahajani }, - { 2074, PT_SC, ucp_Makasar }, - { 2079, PT_SC, ucp_Makasar }, - { 2087, PT_SCX, ucp_Malayalam }, - { 2097, PT_SCX, ucp_Mandaic }, - { 2102, PT_SCX, ucp_Mandaic }, - { 2110, PT_SCX, ucp_Manichaean }, - { 2115, PT_SCX, ucp_Manichaean }, - { 2126, PT_SC, ucp_Marchen }, - { 2131, PT_SC, ucp_Marchen }, - { 2139, PT_SCX, ucp_Masaram_Gondi }, - { 2152, PT_BOOL, ucp_Math }, - { 2157, PT_PC, ucp_Mc }, - { 2160, PT_BOOL, ucp_Modifier_Combining_Mark }, - { 2164, PT_PC, ucp_Me }, - { 2167, PT_SC, ucp_Medefaidrin }, - { 2179, PT_SC, ucp_Medefaidrin }, - { 2184, PT_SC, ucp_Meetei_Mayek }, - { 2196, PT_SC, ucp_Mende_Kikakui }, - { 2201, PT_SC, ucp_Mende_Kikakui }, - { 2214, PT_SC, ucp_Meroitic_Cursive }, - { 2219, PT_SCX, ucp_Meroitic_Hieroglyphs }, - { 2224, PT_SC, ucp_Meroitic_Cursive }, - { 2240, PT_SCX, ucp_Meroitic_Hieroglyphs }, - { 2260, PT_SC, ucp_Miao }, - { 2265, PT_SCX, ucp_Malayalam }, - { 2270, PT_PC, ucp_Mn }, - { 2273, PT_SCX, ucp_Modi }, - { 2278, PT_BOOL, ucp_Modifier_Combining_Mark }, - { 2300, PT_SCX, ucp_Mongolian }, - { 2305, PT_SCX, ucp_Mongolian }, - { 2315, PT_SC, ucp_Mro }, - { 2319, PT_SC, ucp_Mro }, - { 2324, PT_SC, ucp_Meetei_Mayek }, - { 2329, PT_SCX, ucp_Multani }, - { 2334, PT_SCX, ucp_Multani }, - { 2342, PT_SCX, ucp_Myanmar }, - { 2350, PT_SCX, ucp_Myanmar }, - { 2355, PT_GC, ucp_N }, - { 2357, PT_SC, ucp_Nabataean }, - { 2367, PT_SC, ucp_Nag_Mundari }, - { 2372, PT_SC, ucp_Nag_Mundari }, - { 2383, PT_SCX, ucp_Nandinagari }, - { 2388, PT_SCX, ucp_Nandinagari }, - { 2400, PT_SC, ucp_Old_North_Arabian }, - { 2405, PT_SC, ucp_Nabataean }, - { 2410, PT_BOOL, ucp_Noncharacter_Code_Point }, - { 2416, PT_PC, ucp_Nd }, - { 2419, PT_SC, ucp_Newa }, - { 2424, PT_SC, ucp_New_Tai_Lue }, - { 2434, PT_SCX, ucp_Nko }, - { 2438, PT_SCX, ucp_Nko }, - { 2443, PT_PC, ucp_Nl }, - { 2446, PT_PC, ucp_No }, - { 2449, PT_BOOL, ucp_Noncharacter_Code_Point }, - { 2471, PT_SC, ucp_Nushu }, - { 2476, PT_SC, ucp_Nushu }, - { 2482, PT_SC, ucp_Nyiakeng_Puachue_Hmong }, - { 2503, PT_SC, ucp_Ogham }, - { 2508, PT_SC, ucp_Ogham }, - { 2514, PT_SC, ucp_Ol_Chiki }, - { 2522, PT_SC, ucp_Ol_Chiki }, - { 2527, PT_SCX, ucp_Old_Hungarian }, - { 2540, PT_SC, ucp_Old_Italic }, - { 2550, PT_SC, ucp_Old_North_Arabian }, - { 2566, PT_SCX, ucp_Old_Permic }, - { 2576, PT_SC, ucp_Old_Persian }, - { 2587, PT_SC, ucp_Old_Sogdian }, - { 2598, PT_SC, ucp_Old_South_Arabian }, - { 2614, PT_SCX, ucp_Old_Turkic }, - { 2624, PT_SCX, ucp_Old_Uyghur }, - { 2634, PT_SCX, ucp_Ol_Onal }, - { 2641, PT_SCX, ucp_Ol_Onal }, - { 2646, PT_SCX, ucp_Oriya }, - { 2652, PT_SCX, ucp_Old_Turkic }, - { 2657, PT_SCX, ucp_Oriya }, - { 2662, PT_SCX, ucp_Osage }, - { 2668, PT_SCX, ucp_Osage }, - { 2673, PT_SC, ucp_Osmanya }, - { 2678, PT_SC, ucp_Osmanya }, - { 2686, PT_SCX, ucp_Old_Uyghur }, - { 2691, PT_GC, ucp_P }, - { 2693, PT_SC, ucp_Pahawh_Hmong }, - { 2705, PT_SC, ucp_Palmyrene }, - { 2710, PT_SC, ucp_Palmyrene }, - { 2720, PT_BOOL, ucp_Pattern_Syntax }, - { 2727, PT_BOOL, ucp_Pattern_Syntax }, - { 2741, PT_BOOL, ucp_Pattern_White_Space }, - { 2759, PT_BOOL, ucp_Pattern_White_Space }, - { 2765, PT_SC, ucp_Pau_Cin_Hau }, - { 2770, PT_SC, ucp_Pau_Cin_Hau }, - { 2780, PT_PC, ucp_Pc }, - { 2783, PT_BOOL, ucp_Prepended_Concatenation_Mark }, - { 2787, PT_PC, ucp_Pd }, - { 2790, PT_PC, ucp_Pe }, - { 2793, PT_SCX, ucp_Old_Permic }, - { 2798, PT_PC, ucp_Pf }, - { 2801, PT_SCX, ucp_Phags_Pa }, - { 2806, PT_SCX, ucp_Phags_Pa }, - { 2814, PT_SC, ucp_Inscriptional_Pahlavi }, - { 2819, PT_SCX, ucp_Psalter_Pahlavi }, - { 2824, PT_SC, ucp_Phoenician }, - { 2829, PT_SC, ucp_Phoenician }, - { 2840, PT_PC, ucp_Pi }, - { 2843, PT_SC, ucp_Miao }, - { 2848, PT_PC, ucp_Po }, - { 2851, PT_BOOL, ucp_Prepended_Concatenation_Mark }, - { 2878, PT_SC, ucp_Inscriptional_Parthian }, - { 2883, PT_PC, ucp_Ps }, - { 2886, PT_SCX, ucp_Psalter_Pahlavi }, - { 2901, PT_SCX, ucp_Coptic }, - { 2906, PT_SC, ucp_Inherited }, - { 2911, PT_BOOL, ucp_Quotation_Mark }, - { 2917, PT_BOOL, ucp_Quotation_Mark }, - { 2931, PT_BOOL, ucp_Radical }, - { 2939, PT_BOOL, ucp_Regional_Indicator }, - { 2957, PT_SC, ucp_Rejang }, - { 2964, PT_BOOL, ucp_Regional_Indicator }, - { 2967, PT_SC, ucp_Rejang }, - { 2972, PT_SCX, ucp_Hanifi_Rohingya }, - { 2977, PT_SCX, ucp_Runic }, - { 2983, PT_SCX, ucp_Runic }, - { 2988, PT_GC, ucp_S }, - { 2990, PT_SCX, ucp_Samaritan }, - { 3000, PT_SCX, ucp_Samaritan }, - { 3005, PT_SC, ucp_Old_South_Arabian }, - { 3010, PT_SC, ucp_Saurashtra }, - { 3015, PT_SC, ucp_Saurashtra }, - { 3026, PT_PC, ucp_Sc }, - { 3029, PT_BOOL, ucp_Soft_Dotted }, - { 3032, PT_BOOL, ucp_Sentence_Terminal }, - { 3049, PT_SC, ucp_SignWriting }, - { 3054, PT_SCX, ucp_Sharada }, - { 3062, PT_SCX, ucp_Shavian }, - { 3070, PT_SCX, ucp_Shavian }, - { 3075, PT_SCX, ucp_Sharada }, - { 3080, PT_SC, ucp_Siddham }, - { 3085, PT_SC, ucp_Siddham }, - { 3093, PT_SC, ucp_SignWriting }, - { 3105, PT_SCX, ucp_Khudawadi }, - { 3110, PT_SCX, ucp_Sinhala }, - { 3115, PT_SCX, ucp_Sinhala }, - { 3123, PT_PC, ucp_Sk }, - { 3126, PT_PC, ucp_Sm }, - { 3129, PT_PC, ucp_So }, - { 3132, PT_BOOL, ucp_Soft_Dotted }, - { 3143, PT_SCX, ucp_Sogdian }, - { 3148, PT_SCX, ucp_Sogdian }, - { 3156, PT_SC, ucp_Old_Sogdian }, - { 3161, PT_SC, ucp_Sora_Sompeng }, - { 3166, PT_SC, ucp_Sora_Sompeng }, - { 3178, PT_SC, ucp_Soyombo }, - { 3183, PT_SC, ucp_Soyombo }, - { 3191, PT_BOOL, ucp_White_Space }, - { 3197, PT_BOOL, ucp_Sentence_Terminal }, - { 3203, PT_SC, ucp_Sundanese }, - { 3208, PT_SC, ucp_Sundanese }, - { 3218, PT_SCX, ucp_Sunuwar }, - { 3223, PT_SCX, ucp_Sunuwar }, - { 3231, PT_SCX, ucp_Syloti_Nagri }, - { 3236, PT_SCX, ucp_Syloti_Nagri }, - { 3248, PT_SCX, ucp_Syriac }, - { 3253, PT_SCX, ucp_Syriac }, - { 3260, PT_SCX, ucp_Tagalog }, - { 3268, PT_SCX, ucp_Tagbanwa }, - { 3273, PT_SCX, ucp_Tagbanwa }, - { 3282, PT_SCX, ucp_Tai_Le }, - { 3288, PT_SC, ucp_Tai_Tham }, - { 3296, PT_SC, ucp_Tai_Viet }, - { 3304, PT_SCX, ucp_Takri }, - { 3309, PT_SCX, ucp_Takri }, - { 3315, PT_SCX, ucp_Tai_Le }, - { 3320, PT_SC, ucp_New_Tai_Lue }, - { 3325, PT_SCX, ucp_Tamil }, - { 3331, PT_SCX, ucp_Tamil }, - { 3336, PT_SCX, ucp_Tangut }, - { 3341, PT_SC, ucp_Tangsa }, - { 3348, PT_SCX, ucp_Tangut }, - { 3355, PT_SC, ucp_Tai_Viet }, - { 3360, PT_SCX, ucp_Telugu }, - { 3365, PT_SCX, ucp_Telugu }, - { 3372, PT_BOOL, ucp_Terminal_Punctuation }, - { 3377, PT_BOOL, ucp_Terminal_Punctuation }, - { 3397, PT_SCX, ucp_Tifinagh }, - { 3402, PT_SCX, ucp_Tagalog }, - { 3407, PT_SCX, ucp_Thaana }, - { 3412, PT_SCX, ucp_Thaana }, - { 3419, PT_SCX, ucp_Thai }, - { 3424, PT_SCX, ucp_Tibetan }, - { 3432, PT_SCX, ucp_Tibetan }, - { 3437, PT_SCX, ucp_Tifinagh }, - { 3446, PT_SCX, ucp_Tirhuta }, - { 3451, PT_SCX, ucp_Tirhuta }, - { 3459, PT_SC, ucp_Tangsa }, - { 3464, PT_SCX, ucp_Todhri }, - { 3471, PT_SCX, ucp_Todhri }, - { 3476, PT_SCX, ucp_Toto }, - { 3481, PT_SCX, ucp_Tulu_Tigalari }, - { 3494, PT_SCX, ucp_Tulu_Tigalari }, - { 3499, PT_SC, ucp_Ugaritic }, - { 3504, PT_SC, ucp_Ugaritic }, - { 3513, PT_BOOL, ucp_Unified_Ideograph }, - { 3519, PT_BOOL, ucp_Unified_Ideograph }, - { 3536, PT_SC, ucp_Unknown }, - { 3544, PT_BOOL, ucp_Uppercase }, - { 3550, PT_BOOL, ucp_Uppercase }, - { 3560, PT_SC, ucp_Vai }, - { 3564, PT_SC, ucp_Vai }, - { 3569, PT_BOOL, ucp_Variation_Selector }, - { 3587, PT_SC, ucp_Vithkuqi }, - { 3592, PT_SC, ucp_Vithkuqi }, - { 3601, PT_BOOL, ucp_Variation_Selector }, - { 3604, PT_SC, ucp_Wancho }, - { 3611, PT_SC, ucp_Warang_Citi }, - { 3616, PT_SC, ucp_Warang_Citi }, - { 3627, PT_SC, ucp_Wancho }, - { 3632, PT_BOOL, ucp_White_Space }, - { 3643, PT_BOOL, ucp_White_Space }, - { 3650, PT_ALNUM, 0 }, - { 3654, PT_BOOL, ucp_XID_Continue }, - { 3659, PT_BOOL, ucp_XID_Continue }, - { 3671, PT_BOOL, ucp_XID_Start }, - { 3676, PT_BOOL, ucp_XID_Start }, - { 3685, PT_SC, ucp_Old_Persian }, - { 3690, PT_PXSPACE, 0 }, - { 3694, PT_SPACE, 0 }, - { 3698, PT_SC, ucp_Cuneiform }, - { 3703, PT_UCNC, 0 }, - { 3707, PT_WORD, 0 }, - { 3711, PT_SCX, ucp_Yezidi }, - { 3716, PT_SCX, ucp_Yezidi }, - { 3723, PT_SCX, ucp_Yi }, - { 3726, PT_SCX, ucp_Yi }, - { 3731, PT_GC, ucp_Z }, - { 3733, PT_SC, ucp_Zanabazar_Square }, - { 3749, PT_SC, ucp_Zanabazar_Square }, - { 3754, PT_SC, ucp_Inherited }, - { 3759, PT_PC, ucp_Zl }, - { 3762, PT_PC, ucp_Zp }, - { 3765, PT_PC, ucp_Zs }, - { 3768, PT_SC, ucp_Common }, - { 3773, PT_SC, ucp_Unknown } -}; - -const size_t PRIV(utt_size) = sizeof(PRIV(utt)) / sizeof(ucp_type_table); - -#endif /* SUPPORT_UNICODE */ - -/* End of pcre2_ucptables.c */ diff --git a/src/pcre2_ucptables_inc.h b/src/pcre2_ucptables_inc.h new file mode 100644 index 0000000..6f1731d --- /dev/null +++ b/src/pcre2_ucptables_inc.h @@ -0,0 +1,1596 @@ +/************************************************* +* 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-2022 University of Cambridge + +This module is auto-generated from Unicode data files. DO NOT EDIT MANUALLY! +Instead, modify the maint/GenerateUcpTables.py script and run it to generate +a new version of this code. + +----------------------------------------------------------------------------- +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 SUPPORT_UNICODE + +/* The PRIV(utt)[] table below translates Unicode property names into type and +code values. It is searched by binary chop, so must be in collating sequence of +name. Originally, the table contained pointers to the name strings in the first +field of each entry. However, that leads to a large number of relocations when +a shared library is dynamically loaded. A significant reduction is made by +putting all the names into a single, large string and using offsets instead. +All letters are lower cased, and underscores are removed, in accordance with +the "loose matching" rules that Unicode advises and Perl uses. */ + +#define STRING_adlam0 STR_a STR_d STR_l STR_a STR_m "\0" +#define STRING_adlm0 STR_a STR_d STR_l STR_m "\0" +#define STRING_aghb0 STR_a STR_g STR_h STR_b "\0" +#define STRING_ahex0 STR_a STR_h STR_e STR_x "\0" +#define STRING_ahom0 STR_a STR_h STR_o STR_m "\0" +#define STRING_alpha0 STR_a STR_l STR_p STR_h STR_a "\0" +#define STRING_alphabetic0 STR_a STR_l STR_p STR_h STR_a STR_b STR_e STR_t STR_i STR_c "\0" +#define STRING_anatolianhieroglyphs0 STR_a STR_n STR_a STR_t STR_o STR_l STR_i STR_a STR_n STR_h STR_i STR_e STR_r STR_o STR_g STR_l STR_y STR_p STR_h STR_s "\0" +#define STRING_any0 STR_a STR_n STR_y "\0" +#define STRING_arab0 STR_a STR_r STR_a STR_b "\0" +#define STRING_arabic0 STR_a STR_r STR_a STR_b STR_i STR_c "\0" +#define STRING_armenian0 STR_a STR_r STR_m STR_e STR_n STR_i STR_a STR_n "\0" +#define STRING_armi0 STR_a STR_r STR_m STR_i "\0" +#define STRING_armn0 STR_a STR_r STR_m STR_n "\0" +#define STRING_ascii0 STR_a STR_s STR_c STR_i STR_i "\0" +#define STRING_asciihexdigit0 STR_a STR_s STR_c STR_i STR_i STR_h STR_e STR_x STR_d STR_i STR_g STR_i STR_t "\0" +#define STRING_avestan0 STR_a STR_v STR_e STR_s STR_t STR_a STR_n "\0" +#define STRING_avst0 STR_a STR_v STR_s STR_t "\0" +#define STRING_bali0 STR_b STR_a STR_l STR_i "\0" +#define STRING_balinese0 STR_b STR_a STR_l STR_i STR_n STR_e STR_s STR_e "\0" +#define STRING_bamu0 STR_b STR_a STR_m STR_u "\0" +#define STRING_bamum0 STR_b STR_a STR_m STR_u STR_m "\0" +#define STRING_bass0 STR_b STR_a STR_s STR_s "\0" +#define STRING_bassavah0 STR_b STR_a STR_s STR_s STR_a STR_v STR_a STR_h "\0" +#define STRING_batak0 STR_b STR_a STR_t STR_a STR_k "\0" +#define STRING_batk0 STR_b STR_a STR_t STR_k "\0" +#define STRING_beng0 STR_b STR_e STR_n STR_g "\0" +#define STRING_bengali0 STR_b STR_e STR_n STR_g STR_a STR_l STR_i "\0" +#define STRING_bhaiksuki0 STR_b STR_h STR_a STR_i STR_k STR_s STR_u STR_k STR_i "\0" +#define STRING_bhks0 STR_b STR_h STR_k STR_s "\0" +#define STRING_bidial0 STR_b STR_i STR_d STR_i STR_a STR_l "\0" +#define STRING_bidian0 STR_b STR_i STR_d STR_i STR_a STR_n "\0" +#define STRING_bidib0 STR_b STR_i STR_d STR_i STR_b "\0" +#define STRING_bidibn0 STR_b STR_i STR_d STR_i STR_b STR_n "\0" +#define STRING_bidic0 STR_b STR_i STR_d STR_i STR_c "\0" +#define STRING_bidicontrol0 STR_b STR_i STR_d STR_i STR_c STR_o STR_n STR_t STR_r STR_o STR_l "\0" +#define STRING_bidics0 STR_b STR_i STR_d STR_i STR_c STR_s "\0" +#define STRING_bidien0 STR_b STR_i STR_d STR_i STR_e STR_n "\0" +#define STRING_bidies0 STR_b STR_i STR_d STR_i STR_e STR_s "\0" +#define STRING_bidiet0 STR_b STR_i STR_d STR_i STR_e STR_t "\0" +#define STRING_bidifsi0 STR_b STR_i STR_d STR_i STR_f STR_s STR_i "\0" +#define STRING_bidil0 STR_b STR_i STR_d STR_i STR_l "\0" +#define STRING_bidilre0 STR_b STR_i STR_d STR_i STR_l STR_r STR_e "\0" +#define STRING_bidilri0 STR_b STR_i STR_d STR_i STR_l STR_r STR_i "\0" +#define STRING_bidilro0 STR_b STR_i STR_d STR_i STR_l STR_r STR_o "\0" +#define STRING_bidim0 STR_b STR_i STR_d STR_i STR_m "\0" +#define STRING_bidimirrored0 STR_b STR_i STR_d STR_i STR_m STR_i STR_r STR_r STR_o STR_r STR_e STR_d "\0" +#define STRING_bidinsm0 STR_b STR_i STR_d STR_i STR_n STR_s STR_m "\0" +#define STRING_bidion0 STR_b STR_i STR_d STR_i STR_o STR_n "\0" +#define STRING_bidipdf0 STR_b STR_i STR_d STR_i STR_p STR_d STR_f "\0" +#define STRING_bidipdi0 STR_b STR_i STR_d STR_i STR_p STR_d STR_i "\0" +#define STRING_bidir0 STR_b STR_i STR_d STR_i STR_r "\0" +#define STRING_bidirle0 STR_b STR_i STR_d STR_i STR_r STR_l STR_e "\0" +#define STRING_bidirli0 STR_b STR_i STR_d STR_i STR_r STR_l STR_i "\0" +#define STRING_bidirlo0 STR_b STR_i STR_d STR_i STR_r STR_l STR_o "\0" +#define STRING_bidis0 STR_b STR_i STR_d STR_i STR_s "\0" +#define STRING_bidiws0 STR_b STR_i STR_d STR_i STR_w STR_s "\0" +#define STRING_bopo0 STR_b STR_o STR_p STR_o "\0" +#define STRING_bopomofo0 STR_b STR_o STR_p STR_o STR_m STR_o STR_f STR_o "\0" +#define STRING_brah0 STR_b STR_r STR_a STR_h "\0" +#define STRING_brahmi0 STR_b STR_r STR_a STR_h STR_m STR_i "\0" +#define STRING_brai0 STR_b STR_r STR_a STR_i "\0" +#define STRING_braille0 STR_b STR_r STR_a STR_i STR_l STR_l STR_e "\0" +#define STRING_bugi0 STR_b STR_u STR_g STR_i "\0" +#define STRING_buginese0 STR_b STR_u STR_g STR_i STR_n STR_e STR_s STR_e "\0" +#define STRING_buhd0 STR_b STR_u STR_h STR_d "\0" +#define STRING_buhid0 STR_b STR_u STR_h STR_i STR_d "\0" +#define STRING_c0 STR_c "\0" +#define STRING_cakm0 STR_c STR_a STR_k STR_m "\0" +#define STRING_canadianaboriginal0 STR_c STR_a STR_n STR_a STR_d STR_i STR_a STR_n STR_a STR_b STR_o STR_r STR_i STR_g STR_i STR_n STR_a STR_l "\0" +#define STRING_cans0 STR_c STR_a STR_n STR_s "\0" +#define STRING_cari0 STR_c STR_a STR_r STR_i "\0" +#define STRING_carian0 STR_c STR_a STR_r STR_i STR_a STR_n "\0" +#define STRING_cased0 STR_c STR_a STR_s STR_e STR_d "\0" +#define STRING_caseignorable0 STR_c STR_a STR_s STR_e STR_i STR_g STR_n STR_o STR_r STR_a STR_b STR_l STR_e "\0" +#define STRING_caucasianalbanian0 STR_c STR_a STR_u STR_c STR_a STR_s STR_i STR_a STR_n STR_a STR_l STR_b STR_a STR_n STR_i STR_a STR_n "\0" +#define STRING_cc0 STR_c STR_c "\0" +#define STRING_cf0 STR_c STR_f "\0" +#define STRING_chakma0 STR_c STR_h STR_a STR_k STR_m STR_a "\0" +#define STRING_cham0 STR_c STR_h STR_a STR_m "\0" +#define STRING_changeswhencasefolded0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_c STR_a STR_s STR_e STR_f STR_o STR_l STR_d STR_e STR_d "\0" +#define STRING_changeswhencasemapped0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_c STR_a STR_s STR_e STR_m STR_a STR_p STR_p STR_e STR_d "\0" +#define STRING_changeswhenlowercased0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_l STR_o STR_w STR_e STR_r STR_c STR_a STR_s STR_e STR_d "\0" +#define STRING_changeswhentitlecased0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_t STR_i STR_t STR_l STR_e STR_c STR_a STR_s STR_e STR_d "\0" +#define STRING_changeswhenuppercased0 STR_c STR_h STR_a STR_n STR_g STR_e STR_s STR_w STR_h STR_e STR_n STR_u STR_p STR_p STR_e STR_r STR_c STR_a STR_s STR_e STR_d "\0" +#define STRING_cher0 STR_c STR_h STR_e STR_r "\0" +#define STRING_cherokee0 STR_c STR_h STR_e STR_r STR_o STR_k STR_e STR_e "\0" +#define STRING_chorasmian0 STR_c STR_h STR_o STR_r STR_a STR_s STR_m STR_i STR_a STR_n "\0" +#define STRING_chrs0 STR_c STR_h STR_r STR_s "\0" +#define STRING_ci0 STR_c STR_i "\0" +#define STRING_cn0 STR_c STR_n "\0" +#define STRING_co0 STR_c STR_o "\0" +#define STRING_common0 STR_c STR_o STR_m STR_m STR_o STR_n "\0" +#define STRING_copt0 STR_c STR_o STR_p STR_t "\0" +#define STRING_coptic0 STR_c STR_o STR_p STR_t STR_i STR_c "\0" +#define STRING_cpmn0 STR_c STR_p STR_m STR_n "\0" +#define STRING_cprt0 STR_c STR_p STR_r STR_t "\0" +#define STRING_cs0 STR_c STR_s "\0" +#define STRING_cuneiform0 STR_c STR_u STR_n STR_e STR_i STR_f STR_o STR_r STR_m "\0" +#define STRING_cwcf0 STR_c STR_w STR_c STR_f "\0" +#define STRING_cwcm0 STR_c STR_w STR_c STR_m "\0" +#define STRING_cwl0 STR_c STR_w STR_l "\0" +#define STRING_cwt0 STR_c STR_w STR_t "\0" +#define STRING_cwu0 STR_c STR_w STR_u "\0" +#define STRING_cypriot0 STR_c STR_y STR_p STR_r STR_i STR_o STR_t "\0" +#define STRING_cyprominoan0 STR_c STR_y STR_p STR_r STR_o STR_m STR_i STR_n STR_o STR_a STR_n "\0" +#define STRING_cyrillic0 STR_c STR_y STR_r STR_i STR_l STR_l STR_i STR_c "\0" +#define STRING_cyrl0 STR_c STR_y STR_r STR_l "\0" +#define STRING_dash0 STR_d STR_a STR_s STR_h "\0" +#define STRING_defaultignorablecodepoint0 STR_d STR_e STR_f STR_a STR_u STR_l STR_t STR_i STR_g STR_n STR_o STR_r STR_a STR_b STR_l STR_e STR_c STR_o STR_d STR_e STR_p STR_o STR_i STR_n STR_t "\0" +#define STRING_dep0 STR_d STR_e STR_p "\0" +#define STRING_deprecated0 STR_d STR_e STR_p STR_r STR_e STR_c STR_a STR_t STR_e STR_d "\0" +#define STRING_deseret0 STR_d STR_e STR_s STR_e STR_r STR_e STR_t "\0" +#define STRING_deva0 STR_d STR_e STR_v STR_a "\0" +#define STRING_devanagari0 STR_d STR_e STR_v STR_a STR_n STR_a STR_g STR_a STR_r STR_i "\0" +#define STRING_di0 STR_d STR_i "\0" +#define STRING_dia0 STR_d STR_i STR_a "\0" +#define STRING_diacritic0 STR_d STR_i STR_a STR_c STR_r STR_i STR_t STR_i STR_c "\0" +#define STRING_diak0 STR_d STR_i STR_a STR_k "\0" +#define STRING_divesakuru0 STR_d STR_i STR_v STR_e STR_s STR_a STR_k STR_u STR_r STR_u "\0" +#define STRING_dogr0 STR_d STR_o STR_g STR_r "\0" +#define STRING_dogra0 STR_d STR_o STR_g STR_r STR_a "\0" +#define STRING_dsrt0 STR_d STR_s STR_r STR_t "\0" +#define STRING_dupl0 STR_d STR_u STR_p STR_l "\0" +#define STRING_duployan0 STR_d STR_u STR_p STR_l STR_o STR_y STR_a STR_n "\0" +#define STRING_ebase0 STR_e STR_b STR_a STR_s STR_e "\0" +#define STRING_ecomp0 STR_e STR_c STR_o STR_m STR_p "\0" +#define STRING_egyp0 STR_e STR_g STR_y STR_p "\0" +#define STRING_egyptianhieroglyphs0 STR_e STR_g STR_y STR_p STR_t STR_i STR_a STR_n STR_h STR_i STR_e STR_r STR_o STR_g STR_l STR_y STR_p STR_h STR_s "\0" +#define STRING_elba0 STR_e STR_l STR_b STR_a "\0" +#define STRING_elbasan0 STR_e STR_l STR_b STR_a STR_s STR_a STR_n "\0" +#define STRING_elym0 STR_e STR_l STR_y STR_m "\0" +#define STRING_elymaic0 STR_e STR_l STR_y STR_m STR_a STR_i STR_c "\0" +#define STRING_emod0 STR_e STR_m STR_o STR_d "\0" +#define STRING_emoji0 STR_e STR_m STR_o STR_j STR_i "\0" +#define STRING_emojicomponent0 STR_e STR_m STR_o STR_j STR_i STR_c STR_o STR_m STR_p STR_o STR_n STR_e STR_n STR_t "\0" +#define STRING_emojimodifier0 STR_e STR_m STR_o STR_j STR_i STR_m STR_o STR_d STR_i STR_f STR_i STR_e STR_r "\0" +#define STRING_emojimodifierbase0 STR_e STR_m STR_o STR_j STR_i STR_m STR_o STR_d STR_i STR_f STR_i STR_e STR_r STR_b STR_a STR_s STR_e "\0" +#define STRING_emojipresentation0 STR_e STR_m STR_o STR_j STR_i STR_p STR_r STR_e STR_s STR_e STR_n STR_t STR_a STR_t STR_i STR_o STR_n "\0" +#define STRING_epres0 STR_e STR_p STR_r STR_e STR_s "\0" +#define STRING_ethi0 STR_e STR_t STR_h STR_i "\0" +#define STRING_ethiopic0 STR_e STR_t STR_h STR_i STR_o STR_p STR_i STR_c "\0" +#define STRING_ext0 STR_e STR_x STR_t "\0" +#define STRING_extendedpictographic0 STR_e STR_x STR_t STR_e STR_n STR_d STR_e STR_d STR_p STR_i STR_c STR_t STR_o STR_g STR_r STR_a STR_p STR_h STR_i STR_c "\0" +#define STRING_extender0 STR_e STR_x STR_t STR_e STR_n STR_d STR_e STR_r "\0" +#define STRING_extpict0 STR_e STR_x STR_t STR_p STR_i STR_c STR_t "\0" +#define STRING_gara0 STR_g STR_a STR_r STR_a "\0" +#define STRING_garay0 STR_g STR_a STR_r STR_a STR_y "\0" +#define STRING_geor0 STR_g STR_e STR_o STR_r "\0" +#define STRING_georgian0 STR_g STR_e STR_o STR_r STR_g STR_i STR_a STR_n "\0" +#define STRING_glag0 STR_g STR_l STR_a STR_g "\0" +#define STRING_glagolitic0 STR_g STR_l STR_a STR_g STR_o STR_l STR_i STR_t STR_i STR_c "\0" +#define STRING_gong0 STR_g STR_o STR_n STR_g "\0" +#define STRING_gonm0 STR_g STR_o STR_n STR_m "\0" +#define STRING_goth0 STR_g STR_o STR_t STR_h "\0" +#define STRING_gothic0 STR_g STR_o STR_t STR_h STR_i STR_c "\0" +#define STRING_gran0 STR_g STR_r STR_a STR_n "\0" +#define STRING_grantha0 STR_g STR_r STR_a STR_n STR_t STR_h STR_a "\0" +#define STRING_graphemebase0 STR_g STR_r STR_a STR_p STR_h STR_e STR_m STR_e STR_b STR_a STR_s STR_e "\0" +#define STRING_graphemeextend0 STR_g STR_r STR_a STR_p STR_h STR_e STR_m STR_e STR_e STR_x STR_t STR_e STR_n STR_d "\0" +#define STRING_graphemelink0 STR_g STR_r STR_a STR_p STR_h STR_e STR_m STR_e STR_l STR_i STR_n STR_k "\0" +#define STRING_grbase0 STR_g STR_r STR_b STR_a STR_s STR_e "\0" +#define STRING_greek0 STR_g STR_r STR_e STR_e STR_k "\0" +#define STRING_grek0 STR_g STR_r STR_e STR_k "\0" +#define STRING_grext0 STR_g STR_r STR_e STR_x STR_t "\0" +#define STRING_grlink0 STR_g STR_r STR_l STR_i STR_n STR_k "\0" +#define STRING_gujarati0 STR_g STR_u STR_j STR_a STR_r STR_a STR_t STR_i "\0" +#define STRING_gujr0 STR_g STR_u STR_j STR_r "\0" +#define STRING_gukh0 STR_g STR_u STR_k STR_h "\0" +#define STRING_gunjalagondi0 STR_g STR_u STR_n STR_j STR_a STR_l STR_a STR_g STR_o STR_n STR_d STR_i "\0" +#define STRING_gurmukhi0 STR_g STR_u STR_r STR_m STR_u STR_k STR_h STR_i "\0" +#define STRING_guru0 STR_g STR_u STR_r STR_u "\0" +#define STRING_gurungkhema0 STR_g STR_u STR_r STR_u STR_n STR_g STR_k STR_h STR_e STR_m STR_a "\0" +#define STRING_han0 STR_h STR_a STR_n "\0" +#define STRING_hang0 STR_h STR_a STR_n STR_g "\0" +#define STRING_hangul0 STR_h STR_a STR_n STR_g STR_u STR_l "\0" +#define STRING_hani0 STR_h STR_a STR_n STR_i "\0" +#define STRING_hanifirohingya0 STR_h STR_a STR_n STR_i STR_f STR_i STR_r STR_o STR_h STR_i STR_n STR_g STR_y STR_a "\0" +#define STRING_hano0 STR_h STR_a STR_n STR_o "\0" +#define STRING_hanunoo0 STR_h STR_a STR_n STR_u STR_n STR_o STR_o "\0" +#define STRING_hatr0 STR_h STR_a STR_t STR_r "\0" +#define STRING_hatran0 STR_h STR_a STR_t STR_r STR_a STR_n "\0" +#define STRING_hebr0 STR_h STR_e STR_b STR_r "\0" +#define STRING_hebrew0 STR_h STR_e STR_b STR_r STR_e STR_w "\0" +#define STRING_hex0 STR_h STR_e STR_x "\0" +#define STRING_hexdigit0 STR_h STR_e STR_x STR_d STR_i STR_g STR_i STR_t "\0" +#define STRING_hira0 STR_h STR_i STR_r STR_a "\0" +#define STRING_hiragana0 STR_h STR_i STR_r STR_a STR_g STR_a STR_n STR_a "\0" +#define STRING_hluw0 STR_h STR_l STR_u STR_w "\0" +#define STRING_hmng0 STR_h STR_m STR_n STR_g "\0" +#define STRING_hmnp0 STR_h STR_m STR_n STR_p "\0" +#define STRING_hung0 STR_h STR_u STR_n STR_g "\0" +#define STRING_idc0 STR_i STR_d STR_c "\0" +#define STRING_idcompatmathcontinue0 STR_i STR_d STR_c STR_o STR_m STR_p STR_a STR_t STR_m STR_a STR_t STR_h STR_c STR_o STR_n STR_t STR_i STR_n STR_u STR_e "\0" +#define STRING_idcompatmathstart0 STR_i STR_d STR_c STR_o STR_m STR_p STR_a STR_t STR_m STR_a STR_t STR_h STR_s STR_t STR_a STR_r STR_t "\0" +#define STRING_idcontinue0 STR_i STR_d STR_c STR_o STR_n STR_t STR_i STR_n STR_u STR_e "\0" +#define STRING_ideo0 STR_i STR_d STR_e STR_o "\0" +#define STRING_ideographic0 STR_i STR_d STR_e STR_o STR_g STR_r STR_a STR_p STR_h STR_i STR_c "\0" +#define STRING_ids0 STR_i STR_d STR_s "\0" +#define STRING_idsb0 STR_i STR_d STR_s STR_b "\0" +#define STRING_idsbinaryoperator0 STR_i STR_d STR_s STR_b STR_i STR_n STR_a STR_r STR_y STR_o STR_p STR_e STR_r STR_a STR_t STR_o STR_r "\0" +#define STRING_idst0 STR_i STR_d STR_s STR_t "\0" +#define STRING_idstart0 STR_i STR_d STR_s STR_t STR_a STR_r STR_t "\0" +#define STRING_idstrinaryoperator0 STR_i STR_d STR_s STR_t STR_r STR_i STR_n STR_a STR_r STR_y STR_o STR_p STR_e STR_r STR_a STR_t STR_o STR_r "\0" +#define STRING_idsu0 STR_i STR_d STR_s STR_u "\0" +#define STRING_idsunaryoperator0 STR_i STR_d STR_s STR_u STR_n STR_a STR_r STR_y STR_o STR_p STR_e STR_r STR_a STR_t STR_o STR_r "\0" +#define STRING_imperialaramaic0 STR_i STR_m STR_p STR_e STR_r STR_i STR_a STR_l STR_a STR_r STR_a STR_m STR_a STR_i STR_c "\0" +#define STRING_incb0 STR_i STR_n STR_c STR_b "\0" +#define STRING_inherited0 STR_i STR_n STR_h STR_e STR_r STR_i STR_t STR_e STR_d "\0" +#define STRING_inscriptionalpahlavi0 STR_i STR_n STR_s STR_c STR_r STR_i STR_p STR_t STR_i STR_o STR_n STR_a STR_l STR_p STR_a STR_h STR_l STR_a STR_v STR_i "\0" +#define STRING_inscriptionalparthian0 STR_i STR_n STR_s STR_c STR_r STR_i STR_p STR_t STR_i STR_o STR_n STR_a STR_l STR_p STR_a STR_r STR_t STR_h STR_i STR_a STR_n "\0" +#define STRING_ital0 STR_i STR_t STR_a STR_l "\0" +#define STRING_java0 STR_j STR_a STR_v STR_a "\0" +#define STRING_javanese0 STR_j STR_a STR_v STR_a STR_n STR_e STR_s STR_e "\0" +#define STRING_joinc0 STR_j STR_o STR_i STR_n STR_c "\0" +#define STRING_joincontrol0 STR_j STR_o STR_i STR_n STR_c STR_o STR_n STR_t STR_r STR_o STR_l "\0" +#define STRING_kaithi0 STR_k STR_a STR_i STR_t STR_h STR_i "\0" +#define STRING_kali0 STR_k STR_a STR_l STR_i "\0" +#define STRING_kana0 STR_k STR_a STR_n STR_a "\0" +#define STRING_kannada0 STR_k STR_a STR_n STR_n STR_a STR_d STR_a "\0" +#define STRING_katakana0 STR_k STR_a STR_t STR_a STR_k STR_a STR_n STR_a "\0" +#define STRING_kawi0 STR_k STR_a STR_w STR_i "\0" +#define STRING_kayahli0 STR_k STR_a STR_y STR_a STR_h STR_l STR_i "\0" +#define STRING_khar0 STR_k STR_h STR_a STR_r "\0" +#define STRING_kharoshthi0 STR_k STR_h STR_a STR_r STR_o STR_s STR_h STR_t STR_h STR_i "\0" +#define STRING_khitansmallscript0 STR_k STR_h STR_i STR_t STR_a STR_n STR_s STR_m STR_a STR_l STR_l STR_s STR_c STR_r STR_i STR_p STR_t "\0" +#define STRING_khmer0 STR_k STR_h STR_m STR_e STR_r "\0" +#define STRING_khmr0 STR_k STR_h STR_m STR_r "\0" +#define STRING_khoj0 STR_k STR_h STR_o STR_j "\0" +#define STRING_khojki0 STR_k STR_h STR_o STR_j STR_k STR_i "\0" +#define STRING_khudawadi0 STR_k STR_h STR_u STR_d STR_a STR_w STR_a STR_d STR_i "\0" +#define STRING_kiratrai0 STR_k STR_i STR_r STR_a STR_t STR_r STR_a STR_i "\0" +#define STRING_kits0 STR_k STR_i STR_t STR_s "\0" +#define STRING_knda0 STR_k STR_n STR_d STR_a "\0" +#define STRING_krai0 STR_k STR_r STR_a STR_i "\0" +#define STRING_kthi0 STR_k STR_t STR_h STR_i "\0" +#define STRING_l0 STR_l "\0" +#define STRING_l_AMPERSAND0 STR_l STR_AMPERSAND "\0" +#define STRING_lana0 STR_l STR_a STR_n STR_a "\0" +#define STRING_lao0 STR_l STR_a STR_o "\0" +#define STRING_laoo0 STR_l STR_a STR_o STR_o "\0" +#define STRING_latin0 STR_l STR_a STR_t STR_i STR_n "\0" +#define STRING_latn0 STR_l STR_a STR_t STR_n "\0" +#define STRING_lc0 STR_l STR_c "\0" +#define STRING_lepc0 STR_l STR_e STR_p STR_c "\0" +#define STRING_lepcha0 STR_l STR_e STR_p STR_c STR_h STR_a "\0" +#define STRING_limb0 STR_l STR_i STR_m STR_b "\0" +#define STRING_limbu0 STR_l STR_i STR_m STR_b STR_u "\0" +#define STRING_lina0 STR_l STR_i STR_n STR_a "\0" +#define STRING_linb0 STR_l STR_i STR_n STR_b "\0" +#define STRING_lineara0 STR_l STR_i STR_n STR_e STR_a STR_r STR_a "\0" +#define STRING_linearb0 STR_l STR_i STR_n STR_e STR_a STR_r STR_b "\0" +#define STRING_lisu0 STR_l STR_i STR_s STR_u "\0" +#define STRING_ll0 STR_l STR_l "\0" +#define STRING_lm0 STR_l STR_m "\0" +#define STRING_lo0 STR_l STR_o "\0" +#define STRING_loe0 STR_l STR_o STR_e "\0" +#define STRING_logicalorderexception0 STR_l STR_o STR_g STR_i STR_c STR_a STR_l STR_o STR_r STR_d STR_e STR_r STR_e STR_x STR_c STR_e STR_p STR_t STR_i STR_o STR_n "\0" +#define STRING_lower0 STR_l STR_o STR_w STR_e STR_r "\0" +#define STRING_lowercase0 STR_l STR_o STR_w STR_e STR_r STR_c STR_a STR_s STR_e "\0" +#define STRING_lt0 STR_l STR_t "\0" +#define STRING_lu0 STR_l STR_u "\0" +#define STRING_lyci0 STR_l STR_y STR_c STR_i "\0" +#define STRING_lycian0 STR_l STR_y STR_c STR_i STR_a STR_n "\0" +#define STRING_lydi0 STR_l STR_y STR_d STR_i "\0" +#define STRING_lydian0 STR_l STR_y STR_d STR_i STR_a STR_n "\0" +#define STRING_m0 STR_m "\0" +#define STRING_mahajani0 STR_m STR_a STR_h STR_a STR_j STR_a STR_n STR_i "\0" +#define STRING_mahj0 STR_m STR_a STR_h STR_j "\0" +#define STRING_maka0 STR_m STR_a STR_k STR_a "\0" +#define STRING_makasar0 STR_m STR_a STR_k STR_a STR_s STR_a STR_r "\0" +#define STRING_malayalam0 STR_m STR_a STR_l STR_a STR_y STR_a STR_l STR_a STR_m "\0" +#define STRING_mand0 STR_m STR_a STR_n STR_d "\0" +#define STRING_mandaic0 STR_m STR_a STR_n STR_d STR_a STR_i STR_c "\0" +#define STRING_mani0 STR_m STR_a STR_n STR_i "\0" +#define STRING_manichaean0 STR_m STR_a STR_n STR_i STR_c STR_h STR_a STR_e STR_a STR_n "\0" +#define STRING_marc0 STR_m STR_a STR_r STR_c "\0" +#define STRING_marchen0 STR_m STR_a STR_r STR_c STR_h STR_e STR_n "\0" +#define STRING_masaramgondi0 STR_m STR_a STR_s STR_a STR_r STR_a STR_m STR_g STR_o STR_n STR_d STR_i "\0" +#define STRING_math0 STR_m STR_a STR_t STR_h "\0" +#define STRING_mc0 STR_m STR_c "\0" +#define STRING_mcm0 STR_m STR_c STR_m "\0" +#define STRING_me0 STR_m STR_e "\0" +#define STRING_medefaidrin0 STR_m STR_e STR_d STR_e STR_f STR_a STR_i STR_d STR_r STR_i STR_n "\0" +#define STRING_medf0 STR_m STR_e STR_d STR_f "\0" +#define STRING_meeteimayek0 STR_m STR_e STR_e STR_t STR_e STR_i STR_m STR_a STR_y STR_e STR_k "\0" +#define STRING_mend0 STR_m STR_e STR_n STR_d "\0" +#define STRING_mendekikakui0 STR_m STR_e STR_n STR_d STR_e STR_k STR_i STR_k STR_a STR_k STR_u STR_i "\0" +#define STRING_merc0 STR_m STR_e STR_r STR_c "\0" +#define STRING_mero0 STR_m STR_e STR_r STR_o "\0" +#define STRING_meroiticcursive0 STR_m STR_e STR_r STR_o STR_i STR_t STR_i STR_c STR_c STR_u STR_r STR_s STR_i STR_v STR_e "\0" +#define STRING_meroitichieroglyphs0 STR_m STR_e STR_r STR_o STR_i STR_t STR_i STR_c STR_h STR_i STR_e STR_r STR_o STR_g STR_l STR_y STR_p STR_h STR_s "\0" +#define STRING_miao0 STR_m STR_i STR_a STR_o "\0" +#define STRING_mlym0 STR_m STR_l STR_y STR_m "\0" +#define STRING_mn0 STR_m STR_n "\0" +#define STRING_modi0 STR_m STR_o STR_d STR_i "\0" +#define STRING_modifiercombiningmark0 STR_m STR_o STR_d STR_i STR_f STR_i STR_e STR_r STR_c STR_o STR_m STR_b STR_i STR_n STR_i STR_n STR_g STR_m STR_a STR_r STR_k "\0" +#define STRING_mong0 STR_m STR_o STR_n STR_g "\0" +#define STRING_mongolian0 STR_m STR_o STR_n STR_g STR_o STR_l STR_i STR_a STR_n "\0" +#define STRING_mro0 STR_m STR_r STR_o "\0" +#define STRING_mroo0 STR_m STR_r STR_o STR_o "\0" +#define STRING_mtei0 STR_m STR_t STR_e STR_i "\0" +#define STRING_mult0 STR_m STR_u STR_l STR_t "\0" +#define STRING_multani0 STR_m STR_u STR_l STR_t STR_a STR_n STR_i "\0" +#define STRING_myanmar0 STR_m STR_y STR_a STR_n STR_m STR_a STR_r "\0" +#define STRING_mymr0 STR_m STR_y STR_m STR_r "\0" +#define STRING_n0 STR_n "\0" +#define STRING_nabataean0 STR_n STR_a STR_b STR_a STR_t STR_a STR_e STR_a STR_n "\0" +#define STRING_nagm0 STR_n STR_a STR_g STR_m "\0" +#define STRING_nagmundari0 STR_n STR_a STR_g STR_m STR_u STR_n STR_d STR_a STR_r STR_i "\0" +#define STRING_nand0 STR_n STR_a STR_n STR_d "\0" +#define STRING_nandinagari0 STR_n STR_a STR_n STR_d STR_i STR_n STR_a STR_g STR_a STR_r STR_i "\0" +#define STRING_narb0 STR_n STR_a STR_r STR_b "\0" +#define STRING_nbat0 STR_n STR_b STR_a STR_t "\0" +#define STRING_nchar0 STR_n STR_c STR_h STR_a STR_r "\0" +#define STRING_nd0 STR_n STR_d "\0" +#define STRING_newa0 STR_n STR_e STR_w STR_a "\0" +#define STRING_newtailue0 STR_n STR_e STR_w STR_t STR_a STR_i STR_l STR_u STR_e "\0" +#define STRING_nko0 STR_n STR_k STR_o "\0" +#define STRING_nkoo0 STR_n STR_k STR_o STR_o "\0" +#define STRING_nl0 STR_n STR_l "\0" +#define STRING_no0 STR_n STR_o "\0" +#define STRING_noncharactercodepoint0 STR_n STR_o STR_n STR_c STR_h STR_a STR_r STR_a STR_c STR_t STR_e STR_r STR_c STR_o STR_d STR_e STR_p STR_o STR_i STR_n STR_t "\0" +#define STRING_nshu0 STR_n STR_s STR_h STR_u "\0" +#define STRING_nushu0 STR_n STR_u STR_s STR_h STR_u "\0" +#define STRING_nyiakengpuachuehmong0 STR_n STR_y STR_i STR_a STR_k STR_e STR_n STR_g STR_p STR_u STR_a STR_c STR_h STR_u STR_e STR_h STR_m STR_o STR_n STR_g "\0" +#define STRING_ogam0 STR_o STR_g STR_a STR_m "\0" +#define STRING_ogham0 STR_o STR_g STR_h STR_a STR_m "\0" +#define STRING_olchiki0 STR_o STR_l STR_c STR_h STR_i STR_k STR_i "\0" +#define STRING_olck0 STR_o STR_l STR_c STR_k "\0" +#define STRING_oldhungarian0 STR_o STR_l STR_d STR_h STR_u STR_n STR_g STR_a STR_r STR_i STR_a STR_n "\0" +#define STRING_olditalic0 STR_o STR_l STR_d STR_i STR_t STR_a STR_l STR_i STR_c "\0" +#define STRING_oldnortharabian0 STR_o STR_l STR_d STR_n STR_o STR_r STR_t STR_h STR_a STR_r STR_a STR_b STR_i STR_a STR_n "\0" +#define STRING_oldpermic0 STR_o STR_l STR_d STR_p STR_e STR_r STR_m STR_i STR_c "\0" +#define STRING_oldpersian0 STR_o STR_l STR_d STR_p STR_e STR_r STR_s STR_i STR_a STR_n "\0" +#define STRING_oldsogdian0 STR_o STR_l STR_d STR_s STR_o STR_g STR_d STR_i STR_a STR_n "\0" +#define STRING_oldsoutharabian0 STR_o STR_l STR_d STR_s STR_o STR_u STR_t STR_h STR_a STR_r STR_a STR_b STR_i STR_a STR_n "\0" +#define STRING_oldturkic0 STR_o STR_l STR_d STR_t STR_u STR_r STR_k STR_i STR_c "\0" +#define STRING_olduyghur0 STR_o STR_l STR_d STR_u STR_y STR_g STR_h STR_u STR_r "\0" +#define STRING_olonal0 STR_o STR_l STR_o STR_n STR_a STR_l "\0" +#define STRING_onao0 STR_o STR_n STR_a STR_o "\0" +#define STRING_oriya0 STR_o STR_r STR_i STR_y STR_a "\0" +#define STRING_orkh0 STR_o STR_r STR_k STR_h "\0" +#define STRING_orya0 STR_o STR_r STR_y STR_a "\0" +#define STRING_osage0 STR_o STR_s STR_a STR_g STR_e "\0" +#define STRING_osge0 STR_o STR_s STR_g STR_e "\0" +#define STRING_osma0 STR_o STR_s STR_m STR_a "\0" +#define STRING_osmanya0 STR_o STR_s STR_m STR_a STR_n STR_y STR_a "\0" +#define STRING_ougr0 STR_o STR_u STR_g STR_r "\0" +#define STRING_p0 STR_p "\0" +#define STRING_pahawhhmong0 STR_p STR_a STR_h STR_a STR_w STR_h STR_h STR_m STR_o STR_n STR_g "\0" +#define STRING_palm0 STR_p STR_a STR_l STR_m "\0" +#define STRING_palmyrene0 STR_p STR_a STR_l STR_m STR_y STR_r STR_e STR_n STR_e "\0" +#define STRING_patsyn0 STR_p STR_a STR_t STR_s STR_y STR_n "\0" +#define STRING_patternsyntax0 STR_p STR_a STR_t STR_t STR_e STR_r STR_n STR_s STR_y STR_n STR_t STR_a STR_x "\0" +#define STRING_patternwhitespace0 STR_p STR_a STR_t STR_t STR_e STR_r STR_n STR_w STR_h STR_i STR_t STR_e STR_s STR_p STR_a STR_c STR_e "\0" +#define STRING_patws0 STR_p STR_a STR_t STR_w STR_s "\0" +#define STRING_pauc0 STR_p STR_a STR_u STR_c "\0" +#define STRING_paucinhau0 STR_p STR_a STR_u STR_c STR_i STR_n STR_h STR_a STR_u "\0" +#define STRING_pc0 STR_p STR_c "\0" +#define STRING_pcm0 STR_p STR_c STR_m "\0" +#define STRING_pd0 STR_p STR_d "\0" +#define STRING_pe0 STR_p STR_e "\0" +#define STRING_perm0 STR_p STR_e STR_r STR_m "\0" +#define STRING_pf0 STR_p STR_f "\0" +#define STRING_phag0 STR_p STR_h STR_a STR_g "\0" +#define STRING_phagspa0 STR_p STR_h STR_a STR_g STR_s STR_p STR_a "\0" +#define STRING_phli0 STR_p STR_h STR_l STR_i "\0" +#define STRING_phlp0 STR_p STR_h STR_l STR_p "\0" +#define STRING_phnx0 STR_p STR_h STR_n STR_x "\0" +#define STRING_phoenician0 STR_p STR_h STR_o STR_e STR_n STR_i STR_c STR_i STR_a STR_n "\0" +#define STRING_pi0 STR_p STR_i "\0" +#define STRING_plrd0 STR_p STR_l STR_r STR_d "\0" +#define STRING_po0 STR_p STR_o "\0" +#define STRING_prependedconcatenationmark0 STR_p STR_r STR_e STR_p STR_e STR_n STR_d STR_e STR_d STR_c STR_o STR_n STR_c STR_a STR_t STR_e STR_n STR_a STR_t STR_i STR_o STR_n STR_m STR_a STR_r STR_k "\0" +#define STRING_prti0 STR_p STR_r STR_t STR_i "\0" +#define STRING_ps0 STR_p STR_s "\0" +#define STRING_psalterpahlavi0 STR_p STR_s STR_a STR_l STR_t STR_e STR_r STR_p STR_a STR_h STR_l STR_a STR_v STR_i "\0" +#define STRING_qaac0 STR_q STR_a STR_a STR_c "\0" +#define STRING_qaai0 STR_q STR_a STR_a STR_i "\0" +#define STRING_qmark0 STR_q STR_m STR_a STR_r STR_k "\0" +#define STRING_quotationmark0 STR_q STR_u STR_o STR_t STR_a STR_t STR_i STR_o STR_n STR_m STR_a STR_r STR_k "\0" +#define STRING_radical0 STR_r STR_a STR_d STR_i STR_c STR_a STR_l "\0" +#define STRING_regionalindicator0 STR_r STR_e STR_g STR_i STR_o STR_n STR_a STR_l STR_i STR_n STR_d STR_i STR_c STR_a STR_t STR_o STR_r "\0" +#define STRING_rejang0 STR_r STR_e STR_j STR_a STR_n STR_g "\0" +#define STRING_ri0 STR_r STR_i "\0" +#define STRING_rjng0 STR_r STR_j STR_n STR_g "\0" +#define STRING_rohg0 STR_r STR_o STR_h STR_g "\0" +#define STRING_runic0 STR_r STR_u STR_n STR_i STR_c "\0" +#define STRING_runr0 STR_r STR_u STR_n STR_r "\0" +#define STRING_s0 STR_s "\0" +#define STRING_samaritan0 STR_s STR_a STR_m STR_a STR_r STR_i STR_t STR_a STR_n "\0" +#define STRING_samr0 STR_s STR_a STR_m STR_r "\0" +#define STRING_sarb0 STR_s STR_a STR_r STR_b "\0" +#define STRING_saur0 STR_s STR_a STR_u STR_r "\0" +#define STRING_saurashtra0 STR_s STR_a STR_u STR_r STR_a STR_s STR_h STR_t STR_r STR_a "\0" +#define STRING_sc0 STR_s STR_c "\0" +#define STRING_sd0 STR_s STR_d "\0" +#define STRING_sentenceterminal0 STR_s STR_e STR_n STR_t STR_e STR_n STR_c STR_e STR_t STR_e STR_r STR_m STR_i STR_n STR_a STR_l "\0" +#define STRING_sgnw0 STR_s STR_g STR_n STR_w "\0" +#define STRING_sharada0 STR_s STR_h STR_a STR_r STR_a STR_d STR_a "\0" +#define STRING_shavian0 STR_s STR_h STR_a STR_v STR_i STR_a STR_n "\0" +#define STRING_shaw0 STR_s STR_h STR_a STR_w "\0" +#define STRING_shrd0 STR_s STR_h STR_r STR_d "\0" +#define STRING_sidd0 STR_s STR_i STR_d STR_d "\0" +#define STRING_siddham0 STR_s STR_i STR_d STR_d STR_h STR_a STR_m "\0" +#define STRING_signwriting0 STR_s STR_i STR_g STR_n STR_w STR_r STR_i STR_t STR_i STR_n STR_g "\0" +#define STRING_sind0 STR_s STR_i STR_n STR_d "\0" +#define STRING_sinh0 STR_s STR_i STR_n STR_h "\0" +#define STRING_sinhala0 STR_s STR_i STR_n STR_h STR_a STR_l STR_a "\0" +#define STRING_sk0 STR_s STR_k "\0" +#define STRING_sm0 STR_s STR_m "\0" +#define STRING_so0 STR_s STR_o "\0" +#define STRING_softdotted0 STR_s STR_o STR_f STR_t STR_d STR_o STR_t STR_t STR_e STR_d "\0" +#define STRING_sogd0 STR_s STR_o STR_g STR_d "\0" +#define STRING_sogdian0 STR_s STR_o STR_g STR_d STR_i STR_a STR_n "\0" +#define STRING_sogo0 STR_s STR_o STR_g STR_o "\0" +#define STRING_sora0 STR_s STR_o STR_r STR_a "\0" +#define STRING_sorasompeng0 STR_s STR_o STR_r STR_a STR_s STR_o STR_m STR_p STR_e STR_n STR_g "\0" +#define STRING_soyo0 STR_s STR_o STR_y STR_o "\0" +#define STRING_soyombo0 STR_s STR_o STR_y STR_o STR_m STR_b STR_o "\0" +#define STRING_space0 STR_s STR_p STR_a STR_c STR_e "\0" +#define STRING_sterm0 STR_s STR_t STR_e STR_r STR_m "\0" +#define STRING_sund0 STR_s STR_u STR_n STR_d "\0" +#define STRING_sundanese0 STR_s STR_u STR_n STR_d STR_a STR_n STR_e STR_s STR_e "\0" +#define STRING_sunu0 STR_s STR_u STR_n STR_u "\0" +#define STRING_sunuwar0 STR_s STR_u STR_n STR_u STR_w STR_a STR_r "\0" +#define STRING_sylo0 STR_s STR_y STR_l STR_o "\0" +#define STRING_sylotinagri0 STR_s STR_y STR_l STR_o STR_t STR_i STR_n STR_a STR_g STR_r STR_i "\0" +#define STRING_syrc0 STR_s STR_y STR_r STR_c "\0" +#define STRING_syriac0 STR_s STR_y STR_r STR_i STR_a STR_c "\0" +#define STRING_tagalog0 STR_t STR_a STR_g STR_a STR_l STR_o STR_g "\0" +#define STRING_tagb0 STR_t STR_a STR_g STR_b "\0" +#define STRING_tagbanwa0 STR_t STR_a STR_g STR_b STR_a STR_n STR_w STR_a "\0" +#define STRING_taile0 STR_t STR_a STR_i STR_l STR_e "\0" +#define STRING_taitham0 STR_t STR_a STR_i STR_t STR_h STR_a STR_m "\0" +#define STRING_taiviet0 STR_t STR_a STR_i STR_v STR_i STR_e STR_t "\0" +#define STRING_takr0 STR_t STR_a STR_k STR_r "\0" +#define STRING_takri0 STR_t STR_a STR_k STR_r STR_i "\0" +#define STRING_tale0 STR_t STR_a STR_l STR_e "\0" +#define STRING_talu0 STR_t STR_a STR_l STR_u "\0" +#define STRING_tamil0 STR_t STR_a STR_m STR_i STR_l "\0" +#define STRING_taml0 STR_t STR_a STR_m STR_l "\0" +#define STRING_tang0 STR_t STR_a STR_n STR_g "\0" +#define STRING_tangsa0 STR_t STR_a STR_n STR_g STR_s STR_a "\0" +#define STRING_tangut0 STR_t STR_a STR_n STR_g STR_u STR_t "\0" +#define STRING_tavt0 STR_t STR_a STR_v STR_t "\0" +#define STRING_telu0 STR_t STR_e STR_l STR_u "\0" +#define STRING_telugu0 STR_t STR_e STR_l STR_u STR_g STR_u "\0" +#define STRING_term0 STR_t STR_e STR_r STR_m "\0" +#define STRING_terminalpunctuation0 STR_t STR_e STR_r STR_m STR_i STR_n STR_a STR_l STR_p STR_u STR_n STR_c STR_t STR_u STR_a STR_t STR_i STR_o STR_n "\0" +#define STRING_tfng0 STR_t STR_f STR_n STR_g "\0" +#define STRING_tglg0 STR_t STR_g STR_l STR_g "\0" +#define STRING_thaa0 STR_t STR_h STR_a STR_a "\0" +#define STRING_thaana0 STR_t STR_h STR_a STR_a STR_n STR_a "\0" +#define STRING_thai0 STR_t STR_h STR_a STR_i "\0" +#define STRING_tibetan0 STR_t STR_i STR_b STR_e STR_t STR_a STR_n "\0" +#define STRING_tibt0 STR_t STR_i STR_b STR_t "\0" +#define STRING_tifinagh0 STR_t STR_i STR_f STR_i STR_n STR_a STR_g STR_h "\0" +#define STRING_tirh0 STR_t STR_i STR_r STR_h "\0" +#define STRING_tirhuta0 STR_t STR_i STR_r STR_h STR_u STR_t STR_a "\0" +#define STRING_tnsa0 STR_t STR_n STR_s STR_a "\0" +#define STRING_todhri0 STR_t STR_o STR_d STR_h STR_r STR_i "\0" +#define STRING_todr0 STR_t STR_o STR_d STR_r "\0" +#define STRING_toto0 STR_t STR_o STR_t STR_o "\0" +#define STRING_tulutigalari0 STR_t STR_u STR_l STR_u STR_t STR_i STR_g STR_a STR_l STR_a STR_r STR_i "\0" +#define STRING_tutg0 STR_t STR_u STR_t STR_g "\0" +#define STRING_ugar0 STR_u STR_g STR_a STR_r "\0" +#define STRING_ugaritic0 STR_u STR_g STR_a STR_r STR_i STR_t STR_i STR_c "\0" +#define STRING_uideo0 STR_u STR_i STR_d STR_e STR_o "\0" +#define STRING_unifiedideograph0 STR_u STR_n STR_i STR_f STR_i STR_e STR_d STR_i STR_d STR_e STR_o STR_g STR_r STR_a STR_p STR_h "\0" +#define STRING_unknown0 STR_u STR_n STR_k STR_n STR_o STR_w STR_n "\0" +#define STRING_upper0 STR_u STR_p STR_p STR_e STR_r "\0" +#define STRING_uppercase0 STR_u STR_p STR_p STR_e STR_r STR_c STR_a STR_s STR_e "\0" +#define STRING_vai0 STR_v STR_a STR_i "\0" +#define STRING_vaii0 STR_v STR_a STR_i STR_i "\0" +#define STRING_variationselector0 STR_v STR_a STR_r STR_i STR_a STR_t STR_i STR_o STR_n STR_s STR_e STR_l STR_e STR_c STR_t STR_o STR_r "\0" +#define STRING_vith0 STR_v STR_i STR_t STR_h "\0" +#define STRING_vithkuqi0 STR_v STR_i STR_t STR_h STR_k STR_u STR_q STR_i "\0" +#define STRING_vs0 STR_v STR_s "\0" +#define STRING_wancho0 STR_w STR_a STR_n STR_c STR_h STR_o "\0" +#define STRING_wara0 STR_w STR_a STR_r STR_a "\0" +#define STRING_warangciti0 STR_w STR_a STR_r STR_a STR_n STR_g STR_c STR_i STR_t STR_i "\0" +#define STRING_wcho0 STR_w STR_c STR_h STR_o "\0" +#define STRING_whitespace0 STR_w STR_h STR_i STR_t STR_e STR_s STR_p STR_a STR_c STR_e "\0" +#define STRING_wspace0 STR_w STR_s STR_p STR_a STR_c STR_e "\0" +#define STRING_xan0 STR_x STR_a STR_n "\0" +#define STRING_xidc0 STR_x STR_i STR_d STR_c "\0" +#define STRING_xidcontinue0 STR_x STR_i STR_d STR_c STR_o STR_n STR_t STR_i STR_n STR_u STR_e "\0" +#define STRING_xids0 STR_x STR_i STR_d STR_s "\0" +#define STRING_xidstart0 STR_x STR_i STR_d STR_s STR_t STR_a STR_r STR_t "\0" +#define STRING_xpeo0 STR_x STR_p STR_e STR_o "\0" +#define STRING_xps0 STR_x STR_p STR_s "\0" +#define STRING_xsp0 STR_x STR_s STR_p "\0" +#define STRING_xsux0 STR_x STR_s STR_u STR_x "\0" +#define STRING_xuc0 STR_x STR_u STR_c "\0" +#define STRING_xwd0 STR_x STR_w STR_d "\0" +#define STRING_yezi0 STR_y STR_e STR_z STR_i "\0" +#define STRING_yezidi0 STR_y STR_e STR_z STR_i STR_d STR_i "\0" +#define STRING_yi0 STR_y STR_i "\0" +#define STRING_yiii0 STR_y STR_i STR_i STR_i "\0" +#define STRING_z0 STR_z "\0" +#define STRING_zanabazarsquare0 STR_z STR_a STR_n STR_a STR_b STR_a STR_z STR_a STR_r STR_s STR_q STR_u STR_a STR_r STR_e "\0" +#define STRING_zanb0 STR_z STR_a STR_n STR_b "\0" +#define STRING_zinh0 STR_z STR_i STR_n STR_h "\0" +#define STRING_zl0 STR_z STR_l "\0" +#define STRING_zp0 STR_z STR_p "\0" +#define STRING_zs0 STR_z STR_s "\0" +#define STRING_zyyy0 STR_z STR_y STR_y STR_y "\0" +#define STRING_zzzz0 STR_z STR_z STR_z STR_z "\0" + +const char PRIV(utt_names)[] = + STRING_adlam0 + STRING_adlm0 + STRING_aghb0 + STRING_ahex0 + STRING_ahom0 + STRING_alpha0 + STRING_alphabetic0 + STRING_anatolianhieroglyphs0 + STRING_any0 + STRING_arab0 + STRING_arabic0 + STRING_armenian0 + STRING_armi0 + STRING_armn0 + STRING_ascii0 + STRING_asciihexdigit0 + STRING_avestan0 + STRING_avst0 + STRING_bali0 + STRING_balinese0 + STRING_bamu0 + STRING_bamum0 + STRING_bass0 + STRING_bassavah0 + STRING_batak0 + STRING_batk0 + STRING_beng0 + STRING_bengali0 + STRING_bhaiksuki0 + STRING_bhks0 + STRING_bidial0 + STRING_bidian0 + STRING_bidib0 + STRING_bidibn0 + STRING_bidic0 + STRING_bidicontrol0 + STRING_bidics0 + STRING_bidien0 + STRING_bidies0 + STRING_bidiet0 + STRING_bidifsi0 + STRING_bidil0 + STRING_bidilre0 + STRING_bidilri0 + STRING_bidilro0 + STRING_bidim0 + STRING_bidimirrored0 + STRING_bidinsm0 + STRING_bidion0 + STRING_bidipdf0 + STRING_bidipdi0 + STRING_bidir0 + STRING_bidirle0 + STRING_bidirli0 + STRING_bidirlo0 + STRING_bidis0 + STRING_bidiws0 + STRING_bopo0 + STRING_bopomofo0 + STRING_brah0 + STRING_brahmi0 + STRING_brai0 + STRING_braille0 + STRING_bugi0 + STRING_buginese0 + STRING_buhd0 + STRING_buhid0 + STRING_c0 + STRING_cakm0 + STRING_canadianaboriginal0 + STRING_cans0 + STRING_cari0 + STRING_carian0 + STRING_cased0 + STRING_caseignorable0 + STRING_caucasianalbanian0 + STRING_cc0 + STRING_cf0 + STRING_chakma0 + STRING_cham0 + STRING_changeswhencasefolded0 + STRING_changeswhencasemapped0 + STRING_changeswhenlowercased0 + STRING_changeswhentitlecased0 + STRING_changeswhenuppercased0 + STRING_cher0 + STRING_cherokee0 + STRING_chorasmian0 + STRING_chrs0 + STRING_ci0 + STRING_cn0 + STRING_co0 + STRING_common0 + STRING_copt0 + STRING_coptic0 + STRING_cpmn0 + STRING_cprt0 + STRING_cs0 + STRING_cuneiform0 + STRING_cwcf0 + STRING_cwcm0 + STRING_cwl0 + STRING_cwt0 + STRING_cwu0 + STRING_cypriot0 + STRING_cyprominoan0 + STRING_cyrillic0 + STRING_cyrl0 + STRING_dash0 + STRING_defaultignorablecodepoint0 + STRING_dep0 + STRING_deprecated0 + STRING_deseret0 + STRING_deva0 + STRING_devanagari0 + STRING_di0 + STRING_dia0 + STRING_diacritic0 + STRING_diak0 + STRING_divesakuru0 + STRING_dogr0 + STRING_dogra0 + STRING_dsrt0 + STRING_dupl0 + STRING_duployan0 + STRING_ebase0 + STRING_ecomp0 + STRING_egyp0 + STRING_egyptianhieroglyphs0 + STRING_elba0 + STRING_elbasan0 + STRING_elym0 + STRING_elymaic0 + STRING_emod0 + STRING_emoji0 + STRING_emojicomponent0 + STRING_emojimodifier0 + STRING_emojimodifierbase0 + STRING_emojipresentation0 + STRING_epres0 + STRING_ethi0 + STRING_ethiopic0 + STRING_ext0 + STRING_extendedpictographic0 + STRING_extender0 + STRING_extpict0 + STRING_gara0 + STRING_garay0 + STRING_geor0 + STRING_georgian0 + STRING_glag0 + STRING_glagolitic0 + STRING_gong0 + STRING_gonm0 + STRING_goth0 + STRING_gothic0 + STRING_gran0 + STRING_grantha0 + STRING_graphemebase0 + STRING_graphemeextend0 + STRING_graphemelink0 + STRING_grbase0 + STRING_greek0 + STRING_grek0 + STRING_grext0 + STRING_grlink0 + STRING_gujarati0 + STRING_gujr0 + STRING_gukh0 + STRING_gunjalagondi0 + STRING_gurmukhi0 + STRING_guru0 + STRING_gurungkhema0 + STRING_han0 + STRING_hang0 + STRING_hangul0 + STRING_hani0 + STRING_hanifirohingya0 + STRING_hano0 + STRING_hanunoo0 + STRING_hatr0 + STRING_hatran0 + STRING_hebr0 + STRING_hebrew0 + STRING_hex0 + STRING_hexdigit0 + STRING_hira0 + STRING_hiragana0 + STRING_hluw0 + STRING_hmng0 + STRING_hmnp0 + STRING_hung0 + STRING_idc0 + STRING_idcompatmathcontinue0 + STRING_idcompatmathstart0 + STRING_idcontinue0 + STRING_ideo0 + STRING_ideographic0 + STRING_ids0 + STRING_idsb0 + STRING_idsbinaryoperator0 + STRING_idst0 + STRING_idstart0 + STRING_idstrinaryoperator0 + STRING_idsu0 + STRING_idsunaryoperator0 + STRING_imperialaramaic0 + STRING_incb0 + STRING_inherited0 + STRING_inscriptionalpahlavi0 + STRING_inscriptionalparthian0 + STRING_ital0 + STRING_java0 + STRING_javanese0 + STRING_joinc0 + STRING_joincontrol0 + STRING_kaithi0 + STRING_kali0 + STRING_kana0 + STRING_kannada0 + STRING_katakana0 + STRING_kawi0 + STRING_kayahli0 + STRING_khar0 + STRING_kharoshthi0 + STRING_khitansmallscript0 + STRING_khmer0 + STRING_khmr0 + STRING_khoj0 + STRING_khojki0 + STRING_khudawadi0 + STRING_kiratrai0 + STRING_kits0 + STRING_knda0 + STRING_krai0 + STRING_kthi0 + STRING_l0 + STRING_l_AMPERSAND0 + STRING_lana0 + STRING_lao0 + STRING_laoo0 + STRING_latin0 + STRING_latn0 + STRING_lc0 + STRING_lepc0 + STRING_lepcha0 + STRING_limb0 + STRING_limbu0 + STRING_lina0 + STRING_linb0 + STRING_lineara0 + STRING_linearb0 + STRING_lisu0 + STRING_ll0 + STRING_lm0 + STRING_lo0 + STRING_loe0 + STRING_logicalorderexception0 + STRING_lower0 + STRING_lowercase0 + STRING_lt0 + STRING_lu0 + STRING_lyci0 + STRING_lycian0 + STRING_lydi0 + STRING_lydian0 + STRING_m0 + STRING_mahajani0 + STRING_mahj0 + STRING_maka0 + STRING_makasar0 + STRING_malayalam0 + STRING_mand0 + STRING_mandaic0 + STRING_mani0 + STRING_manichaean0 + STRING_marc0 + STRING_marchen0 + STRING_masaramgondi0 + STRING_math0 + STRING_mc0 + STRING_mcm0 + STRING_me0 + STRING_medefaidrin0 + STRING_medf0 + STRING_meeteimayek0 + STRING_mend0 + STRING_mendekikakui0 + STRING_merc0 + STRING_mero0 + STRING_meroiticcursive0 + STRING_meroitichieroglyphs0 + STRING_miao0 + STRING_mlym0 + STRING_mn0 + STRING_modi0 + STRING_modifiercombiningmark0 + STRING_mong0 + STRING_mongolian0 + STRING_mro0 + STRING_mroo0 + STRING_mtei0 + STRING_mult0 + STRING_multani0 + STRING_myanmar0 + STRING_mymr0 + STRING_n0 + STRING_nabataean0 + STRING_nagm0 + STRING_nagmundari0 + STRING_nand0 + STRING_nandinagari0 + STRING_narb0 + STRING_nbat0 + STRING_nchar0 + STRING_nd0 + STRING_newa0 + STRING_newtailue0 + STRING_nko0 + STRING_nkoo0 + STRING_nl0 + STRING_no0 + STRING_noncharactercodepoint0 + STRING_nshu0 + STRING_nushu0 + STRING_nyiakengpuachuehmong0 + STRING_ogam0 + STRING_ogham0 + STRING_olchiki0 + STRING_olck0 + STRING_oldhungarian0 + STRING_olditalic0 + STRING_oldnortharabian0 + STRING_oldpermic0 + STRING_oldpersian0 + STRING_oldsogdian0 + STRING_oldsoutharabian0 + STRING_oldturkic0 + STRING_olduyghur0 + STRING_olonal0 + STRING_onao0 + STRING_oriya0 + STRING_orkh0 + STRING_orya0 + STRING_osage0 + STRING_osge0 + STRING_osma0 + STRING_osmanya0 + STRING_ougr0 + STRING_p0 + STRING_pahawhhmong0 + STRING_palm0 + STRING_palmyrene0 + STRING_patsyn0 + STRING_patternsyntax0 + STRING_patternwhitespace0 + STRING_patws0 + STRING_pauc0 + STRING_paucinhau0 + STRING_pc0 + STRING_pcm0 + STRING_pd0 + STRING_pe0 + STRING_perm0 + STRING_pf0 + STRING_phag0 + STRING_phagspa0 + STRING_phli0 + STRING_phlp0 + STRING_phnx0 + STRING_phoenician0 + STRING_pi0 + STRING_plrd0 + STRING_po0 + STRING_prependedconcatenationmark0 + STRING_prti0 + STRING_ps0 + STRING_psalterpahlavi0 + STRING_qaac0 + STRING_qaai0 + STRING_qmark0 + STRING_quotationmark0 + STRING_radical0 + STRING_regionalindicator0 + STRING_rejang0 + STRING_ri0 + STRING_rjng0 + STRING_rohg0 + STRING_runic0 + STRING_runr0 + STRING_s0 + STRING_samaritan0 + STRING_samr0 + STRING_sarb0 + STRING_saur0 + STRING_saurashtra0 + STRING_sc0 + STRING_sd0 + STRING_sentenceterminal0 + STRING_sgnw0 + STRING_sharada0 + STRING_shavian0 + STRING_shaw0 + STRING_shrd0 + STRING_sidd0 + STRING_siddham0 + STRING_signwriting0 + STRING_sind0 + STRING_sinh0 + STRING_sinhala0 + STRING_sk0 + STRING_sm0 + STRING_so0 + STRING_softdotted0 + STRING_sogd0 + STRING_sogdian0 + STRING_sogo0 + STRING_sora0 + STRING_sorasompeng0 + STRING_soyo0 + STRING_soyombo0 + STRING_space0 + STRING_sterm0 + STRING_sund0 + STRING_sundanese0 + STRING_sunu0 + STRING_sunuwar0 + STRING_sylo0 + STRING_sylotinagri0 + STRING_syrc0 + STRING_syriac0 + STRING_tagalog0 + STRING_tagb0 + STRING_tagbanwa0 + STRING_taile0 + STRING_taitham0 + STRING_taiviet0 + STRING_takr0 + STRING_takri0 + STRING_tale0 + STRING_talu0 + STRING_tamil0 + STRING_taml0 + STRING_tang0 + STRING_tangsa0 + STRING_tangut0 + STRING_tavt0 + STRING_telu0 + STRING_telugu0 + STRING_term0 + STRING_terminalpunctuation0 + STRING_tfng0 + STRING_tglg0 + STRING_thaa0 + STRING_thaana0 + STRING_thai0 + STRING_tibetan0 + STRING_tibt0 + STRING_tifinagh0 + STRING_tirh0 + STRING_tirhuta0 + STRING_tnsa0 + STRING_todhri0 + STRING_todr0 + STRING_toto0 + STRING_tulutigalari0 + STRING_tutg0 + STRING_ugar0 + STRING_ugaritic0 + STRING_uideo0 + STRING_unifiedideograph0 + STRING_unknown0 + STRING_upper0 + STRING_uppercase0 + STRING_vai0 + STRING_vaii0 + STRING_variationselector0 + STRING_vith0 + STRING_vithkuqi0 + STRING_vs0 + STRING_wancho0 + STRING_wara0 + STRING_warangciti0 + STRING_wcho0 + STRING_whitespace0 + STRING_wspace0 + STRING_xan0 + STRING_xidc0 + STRING_xidcontinue0 + STRING_xids0 + STRING_xidstart0 + STRING_xpeo0 + STRING_xps0 + STRING_xsp0 + STRING_xsux0 + STRING_xuc0 + STRING_xwd0 + STRING_yezi0 + STRING_yezidi0 + STRING_yi0 + STRING_yiii0 + STRING_z0 + STRING_zanabazarsquare0 + STRING_zanb0 + STRING_zinh0 + STRING_zl0 + STRING_zp0 + STRING_zs0 + STRING_zyyy0 + STRING_zzzz0; + +const ucp_type_table PRIV(utt)[] = { + { 0, PT_SCX, ucp_Adlam }, + { 6, PT_SCX, ucp_Adlam }, + { 11, PT_SCX, ucp_Caucasian_Albanian }, + { 16, PT_BOOL, ucp_ASCII_Hex_Digit }, + { 21, PT_SC, ucp_Ahom }, + { 26, PT_BOOL, ucp_Alphabetic }, + { 32, PT_BOOL, ucp_Alphabetic }, + { 43, PT_SC, ucp_Anatolian_Hieroglyphs }, + { 64, PT_ANY, 0 }, + { 68, PT_SCX, ucp_Arabic }, + { 73, PT_SCX, ucp_Arabic }, + { 80, PT_SCX, ucp_Armenian }, + { 89, PT_SC, ucp_Imperial_Aramaic }, + { 94, PT_SCX, ucp_Armenian }, + { 99, PT_BOOL, ucp_ASCII }, + { 105, PT_BOOL, ucp_ASCII_Hex_Digit }, + { 119, PT_SCX, ucp_Avestan }, + { 127, PT_SCX, ucp_Avestan }, + { 132, PT_SC, ucp_Balinese }, + { 137, PT_SC, ucp_Balinese }, + { 146, PT_SC, ucp_Bamum }, + { 151, PT_SC, ucp_Bamum }, + { 157, PT_SC, ucp_Bassa_Vah }, + { 162, PT_SC, ucp_Bassa_Vah }, + { 171, PT_SC, ucp_Batak }, + { 177, PT_SC, ucp_Batak }, + { 182, PT_SCX, ucp_Bengali }, + { 187, PT_SCX, ucp_Bengali }, + { 195, PT_SC, ucp_Bhaiksuki }, + { 205, PT_SC, ucp_Bhaiksuki }, + { 210, PT_BIDICL, ucp_bidiAL }, + { 217, PT_BIDICL, ucp_bidiAN }, + { 224, PT_BIDICL, ucp_bidiB }, + { 230, PT_BIDICL, ucp_bidiBN }, + { 237, PT_BOOL, ucp_Bidi_Control }, + { 243, PT_BOOL, ucp_Bidi_Control }, + { 255, PT_BIDICL, ucp_bidiCS }, + { 262, PT_BIDICL, ucp_bidiEN }, + { 269, PT_BIDICL, ucp_bidiES }, + { 276, PT_BIDICL, ucp_bidiET }, + { 283, PT_BIDICL, ucp_bidiFSI }, + { 291, PT_BIDICL, ucp_bidiL }, + { 297, PT_BIDICL, ucp_bidiLRE }, + { 305, PT_BIDICL, ucp_bidiLRI }, + { 313, PT_BIDICL, ucp_bidiLRO }, + { 321, PT_BOOL, ucp_Bidi_Mirrored }, + { 327, PT_BOOL, ucp_Bidi_Mirrored }, + { 340, PT_BIDICL, ucp_bidiNSM }, + { 348, PT_BIDICL, ucp_bidiON }, + { 355, PT_BIDICL, ucp_bidiPDF }, + { 363, PT_BIDICL, ucp_bidiPDI }, + { 371, PT_BIDICL, ucp_bidiR }, + { 377, PT_BIDICL, ucp_bidiRLE }, + { 385, PT_BIDICL, ucp_bidiRLI }, + { 393, PT_BIDICL, ucp_bidiRLO }, + { 401, PT_BIDICL, ucp_bidiS }, + { 407, PT_BIDICL, ucp_bidiWS }, + { 414, PT_SCX, ucp_Bopomofo }, + { 419, PT_SCX, ucp_Bopomofo }, + { 428, PT_SC, ucp_Brahmi }, + { 433, PT_SC, ucp_Brahmi }, + { 440, PT_SC, ucp_Braille }, + { 445, PT_SC, ucp_Braille }, + { 453, PT_SCX, ucp_Buginese }, + { 458, PT_SCX, ucp_Buginese }, + { 467, PT_SCX, ucp_Buhid }, + { 472, PT_SCX, ucp_Buhid }, + { 478, PT_GC, ucp_C }, + { 480, PT_SCX, ucp_Chakma }, + { 485, PT_SC, ucp_Canadian_Aboriginal }, + { 504, PT_SC, ucp_Canadian_Aboriginal }, + { 509, PT_SCX, ucp_Carian }, + { 514, PT_SCX, ucp_Carian }, + { 521, PT_BOOL, ucp_Cased }, + { 527, PT_BOOL, ucp_Case_Ignorable }, + { 541, PT_SCX, ucp_Caucasian_Albanian }, + { 559, PT_PC, ucp_Cc }, + { 562, PT_PC, ucp_Cf }, + { 565, PT_SCX, ucp_Chakma }, + { 572, PT_SC, ucp_Cham }, + { 577, PT_BOOL, ucp_Changes_When_Casefolded }, + { 599, PT_BOOL, ucp_Changes_When_Casemapped }, + { 621, PT_BOOL, ucp_Changes_When_Lowercased }, + { 643, PT_BOOL, ucp_Changes_When_Titlecased }, + { 665, PT_BOOL, ucp_Changes_When_Uppercased }, + { 687, PT_SCX, ucp_Cherokee }, + { 692, PT_SCX, ucp_Cherokee }, + { 701, PT_SC, ucp_Chorasmian }, + { 712, PT_SC, ucp_Chorasmian }, + { 717, PT_BOOL, ucp_Case_Ignorable }, + { 720, PT_PC, ucp_Cn }, + { 723, PT_PC, ucp_Co }, + { 726, PT_SC, ucp_Common }, + { 733, PT_SCX, ucp_Coptic }, + { 738, PT_SCX, ucp_Coptic }, + { 745, PT_SCX, ucp_Cypro_Minoan }, + { 750, PT_SCX, ucp_Cypriot }, + { 755, PT_PC, ucp_Cs }, + { 758, PT_SC, ucp_Cuneiform }, + { 768, PT_BOOL, ucp_Changes_When_Casefolded }, + { 773, PT_BOOL, ucp_Changes_When_Casemapped }, + { 778, PT_BOOL, ucp_Changes_When_Lowercased }, + { 782, PT_BOOL, ucp_Changes_When_Titlecased }, + { 786, PT_BOOL, ucp_Changes_When_Uppercased }, + { 790, PT_SCX, ucp_Cypriot }, + { 798, PT_SCX, ucp_Cypro_Minoan }, + { 810, PT_SCX, ucp_Cyrillic }, + { 819, PT_SCX, ucp_Cyrillic }, + { 824, PT_BOOL, ucp_Dash }, + { 829, PT_BOOL, ucp_Default_Ignorable_Code_Point }, + { 855, PT_BOOL, ucp_Deprecated }, + { 859, PT_BOOL, ucp_Deprecated }, + { 870, PT_SC, ucp_Deseret }, + { 878, PT_SCX, ucp_Devanagari }, + { 883, PT_SCX, ucp_Devanagari }, + { 894, PT_BOOL, ucp_Default_Ignorable_Code_Point }, + { 897, PT_BOOL, ucp_Diacritic }, + { 901, PT_BOOL, ucp_Diacritic }, + { 911, PT_SC, ucp_Dives_Akuru }, + { 916, PT_SC, ucp_Dives_Akuru }, + { 927, PT_SCX, ucp_Dogra }, + { 932, PT_SCX, ucp_Dogra }, + { 938, PT_SC, ucp_Deseret }, + { 943, PT_SCX, ucp_Duployan }, + { 948, PT_SCX, ucp_Duployan }, + { 957, PT_BOOL, ucp_Emoji_Modifier_Base }, + { 963, PT_BOOL, ucp_Emoji_Component }, + { 969, PT_SC, ucp_Egyptian_Hieroglyphs }, + { 974, PT_SC, ucp_Egyptian_Hieroglyphs }, + { 994, PT_SCX, ucp_Elbasan }, + { 999, PT_SCX, ucp_Elbasan }, + { 1007, PT_SC, ucp_Elymaic }, + { 1012, PT_SC, ucp_Elymaic }, + { 1020, PT_BOOL, ucp_Emoji_Modifier }, + { 1025, PT_BOOL, ucp_Emoji }, + { 1031, PT_BOOL, ucp_Emoji_Component }, + { 1046, PT_BOOL, ucp_Emoji_Modifier }, + { 1060, PT_BOOL, ucp_Emoji_Modifier_Base }, + { 1078, PT_BOOL, ucp_Emoji_Presentation }, + { 1096, PT_BOOL, ucp_Emoji_Presentation }, + { 1102, PT_SCX, ucp_Ethiopic }, + { 1107, PT_SCX, ucp_Ethiopic }, + { 1116, PT_BOOL, ucp_Extender }, + { 1120, PT_BOOL, ucp_Extended_Pictographic }, + { 1141, PT_BOOL, ucp_Extender }, + { 1150, PT_BOOL, ucp_Extended_Pictographic }, + { 1158, PT_SCX, ucp_Garay }, + { 1163, PT_SCX, ucp_Garay }, + { 1169, PT_SCX, ucp_Georgian }, + { 1174, PT_SCX, ucp_Georgian }, + { 1183, PT_SCX, ucp_Glagolitic }, + { 1188, PT_SCX, ucp_Glagolitic }, + { 1199, PT_SCX, ucp_Gunjala_Gondi }, + { 1204, PT_SCX, ucp_Masaram_Gondi }, + { 1209, PT_SCX, ucp_Gothic }, + { 1214, PT_SCX, ucp_Gothic }, + { 1221, PT_SCX, ucp_Grantha }, + { 1226, PT_SCX, ucp_Grantha }, + { 1234, PT_BOOL, ucp_Grapheme_Base }, + { 1247, PT_BOOL, ucp_Grapheme_Extend }, + { 1262, PT_BOOL, ucp_Grapheme_Link }, + { 1275, PT_BOOL, ucp_Grapheme_Base }, + { 1282, PT_SCX, ucp_Greek }, + { 1288, PT_SCX, ucp_Greek }, + { 1293, PT_BOOL, ucp_Grapheme_Extend }, + { 1299, PT_BOOL, ucp_Grapheme_Link }, + { 1306, PT_SCX, ucp_Gujarati }, + { 1315, PT_SCX, ucp_Gujarati }, + { 1320, PT_SCX, ucp_Gurung_Khema }, + { 1325, PT_SCX, ucp_Gunjala_Gondi }, + { 1338, PT_SCX, ucp_Gurmukhi }, + { 1347, PT_SCX, ucp_Gurmukhi }, + { 1352, PT_SCX, ucp_Gurung_Khema }, + { 1364, PT_SCX, ucp_Han }, + { 1368, PT_SCX, ucp_Hangul }, + { 1373, PT_SCX, ucp_Hangul }, + { 1380, PT_SCX, ucp_Han }, + { 1385, PT_SCX, ucp_Hanifi_Rohingya }, + { 1400, PT_SCX, ucp_Hanunoo }, + { 1405, PT_SCX, ucp_Hanunoo }, + { 1413, PT_SC, ucp_Hatran }, + { 1418, PT_SC, ucp_Hatran }, + { 1425, PT_SCX, ucp_Hebrew }, + { 1430, PT_SCX, ucp_Hebrew }, + { 1437, PT_BOOL, ucp_Hex_Digit }, + { 1441, PT_BOOL, ucp_Hex_Digit }, + { 1450, PT_SCX, ucp_Hiragana }, + { 1455, PT_SCX, ucp_Hiragana }, + { 1464, PT_SC, ucp_Anatolian_Hieroglyphs }, + { 1469, PT_SC, ucp_Pahawh_Hmong }, + { 1474, PT_SC, ucp_Nyiakeng_Puachue_Hmong }, + { 1479, PT_SCX, ucp_Old_Hungarian }, + { 1484, PT_BOOL, ucp_ID_Continue }, + { 1488, PT_BOOL, ucp_ID_Compat_Math_Continue }, + { 1509, PT_BOOL, ucp_ID_Compat_Math_Start }, + { 1527, PT_BOOL, ucp_ID_Continue }, + { 1538, PT_BOOL, ucp_Ideographic }, + { 1543, PT_BOOL, ucp_Ideographic }, + { 1555, PT_BOOL, ucp_ID_Start }, + { 1559, PT_BOOL, ucp_IDS_Binary_Operator }, + { 1564, PT_BOOL, ucp_IDS_Binary_Operator }, + { 1582, PT_BOOL, ucp_IDS_Trinary_Operator }, + { 1587, PT_BOOL, ucp_ID_Start }, + { 1595, PT_BOOL, ucp_IDS_Trinary_Operator }, + { 1614, PT_BOOL, ucp_IDS_Unary_Operator }, + { 1619, PT_BOOL, ucp_IDS_Unary_Operator }, + { 1636, PT_SC, ucp_Imperial_Aramaic }, + { 1652, PT_BOOL, ucp_InCB }, + { 1657, PT_SC, ucp_Inherited }, + { 1667, PT_SC, ucp_Inscriptional_Pahlavi }, + { 1688, PT_SC, ucp_Inscriptional_Parthian }, + { 1710, PT_SC, ucp_Old_Italic }, + { 1715, PT_SCX, ucp_Javanese }, + { 1720, PT_SCX, ucp_Javanese }, + { 1729, PT_BOOL, ucp_Join_Control }, + { 1735, PT_BOOL, ucp_Join_Control }, + { 1747, PT_SCX, ucp_Kaithi }, + { 1754, PT_SCX, ucp_Kayah_Li }, + { 1759, PT_SCX, ucp_Katakana }, + { 1764, PT_SCX, ucp_Kannada }, + { 1772, PT_SCX, ucp_Katakana }, + { 1781, PT_SC, ucp_Kawi }, + { 1786, PT_SCX, ucp_Kayah_Li }, + { 1794, PT_SC, ucp_Kharoshthi }, + { 1799, PT_SC, ucp_Kharoshthi }, + { 1810, PT_SC, ucp_Khitan_Small_Script }, + { 1828, PT_SC, ucp_Khmer }, + { 1834, PT_SC, ucp_Khmer }, + { 1839, PT_SCX, ucp_Khojki }, + { 1844, PT_SCX, ucp_Khojki }, + { 1851, PT_SCX, ucp_Khudawadi }, + { 1861, PT_SC, ucp_Kirat_Rai }, + { 1870, PT_SC, ucp_Khitan_Small_Script }, + { 1875, PT_SCX, ucp_Kannada }, + { 1880, PT_SC, ucp_Kirat_Rai }, + { 1885, PT_SCX, ucp_Kaithi }, + { 1890, PT_GC, ucp_L }, + { 1892, PT_LAMP, 0 }, + { 1895, PT_SC, ucp_Tai_Tham }, + { 1900, PT_SC, ucp_Lao }, + { 1904, PT_SC, ucp_Lao }, + { 1909, PT_SCX, ucp_Latin }, + { 1915, PT_SCX, ucp_Latin }, + { 1920, PT_LAMP, 0 }, + { 1923, PT_SC, ucp_Lepcha }, + { 1928, PT_SC, ucp_Lepcha }, + { 1935, PT_SCX, ucp_Limbu }, + { 1940, PT_SCX, ucp_Limbu }, + { 1946, PT_SCX, ucp_Linear_A }, + { 1951, PT_SCX, ucp_Linear_B }, + { 1956, PT_SCX, ucp_Linear_A }, + { 1964, PT_SCX, ucp_Linear_B }, + { 1972, PT_SCX, ucp_Lisu }, + { 1977, PT_PC, ucp_Ll }, + { 1980, PT_PC, ucp_Lm }, + { 1983, PT_PC, ucp_Lo }, + { 1986, PT_BOOL, ucp_Logical_Order_Exception }, + { 1990, PT_BOOL, ucp_Logical_Order_Exception }, + { 2012, PT_BOOL, ucp_Lowercase }, + { 2018, PT_BOOL, ucp_Lowercase }, + { 2028, PT_PC, ucp_Lt }, + { 2031, PT_PC, ucp_Lu }, + { 2034, PT_SCX, ucp_Lycian }, + { 2039, PT_SCX, ucp_Lycian }, + { 2046, PT_SCX, ucp_Lydian }, + { 2051, PT_SCX, ucp_Lydian }, + { 2058, PT_GC, ucp_M }, + { 2060, PT_SCX, ucp_Mahajani }, + { 2069, PT_SCX, ucp_Mahajani }, + { 2074, PT_SC, ucp_Makasar }, + { 2079, PT_SC, ucp_Makasar }, + { 2087, PT_SCX, ucp_Malayalam }, + { 2097, PT_SCX, ucp_Mandaic }, + { 2102, PT_SCX, ucp_Mandaic }, + { 2110, PT_SCX, ucp_Manichaean }, + { 2115, PT_SCX, ucp_Manichaean }, + { 2126, PT_SC, ucp_Marchen }, + { 2131, PT_SC, ucp_Marchen }, + { 2139, PT_SCX, ucp_Masaram_Gondi }, + { 2152, PT_BOOL, ucp_Math }, + { 2157, PT_PC, ucp_Mc }, + { 2160, PT_BOOL, ucp_Modifier_Combining_Mark }, + { 2164, PT_PC, ucp_Me }, + { 2167, PT_SC, ucp_Medefaidrin }, + { 2179, PT_SC, ucp_Medefaidrin }, + { 2184, PT_SC, ucp_Meetei_Mayek }, + { 2196, PT_SC, ucp_Mende_Kikakui }, + { 2201, PT_SC, ucp_Mende_Kikakui }, + { 2214, PT_SC, ucp_Meroitic_Cursive }, + { 2219, PT_SCX, ucp_Meroitic_Hieroglyphs }, + { 2224, PT_SC, ucp_Meroitic_Cursive }, + { 2240, PT_SCX, ucp_Meroitic_Hieroglyphs }, + { 2260, PT_SC, ucp_Miao }, + { 2265, PT_SCX, ucp_Malayalam }, + { 2270, PT_PC, ucp_Mn }, + { 2273, PT_SCX, ucp_Modi }, + { 2278, PT_BOOL, ucp_Modifier_Combining_Mark }, + { 2300, PT_SCX, ucp_Mongolian }, + { 2305, PT_SCX, ucp_Mongolian }, + { 2315, PT_SC, ucp_Mro }, + { 2319, PT_SC, ucp_Mro }, + { 2324, PT_SC, ucp_Meetei_Mayek }, + { 2329, PT_SCX, ucp_Multani }, + { 2334, PT_SCX, ucp_Multani }, + { 2342, PT_SCX, ucp_Myanmar }, + { 2350, PT_SCX, ucp_Myanmar }, + { 2355, PT_GC, ucp_N }, + { 2357, PT_SC, ucp_Nabataean }, + { 2367, PT_SC, ucp_Nag_Mundari }, + { 2372, PT_SC, ucp_Nag_Mundari }, + { 2383, PT_SCX, ucp_Nandinagari }, + { 2388, PT_SCX, ucp_Nandinagari }, + { 2400, PT_SC, ucp_Old_North_Arabian }, + { 2405, PT_SC, ucp_Nabataean }, + { 2410, PT_BOOL, ucp_Noncharacter_Code_Point }, + { 2416, PT_PC, ucp_Nd }, + { 2419, PT_SC, ucp_Newa }, + { 2424, PT_SC, ucp_New_Tai_Lue }, + { 2434, PT_SCX, ucp_Nko }, + { 2438, PT_SCX, ucp_Nko }, + { 2443, PT_PC, ucp_Nl }, + { 2446, PT_PC, ucp_No }, + { 2449, PT_BOOL, ucp_Noncharacter_Code_Point }, + { 2471, PT_SC, ucp_Nushu }, + { 2476, PT_SC, ucp_Nushu }, + { 2482, PT_SC, ucp_Nyiakeng_Puachue_Hmong }, + { 2503, PT_SC, ucp_Ogham }, + { 2508, PT_SC, ucp_Ogham }, + { 2514, PT_SC, ucp_Ol_Chiki }, + { 2522, PT_SC, ucp_Ol_Chiki }, + { 2527, PT_SCX, ucp_Old_Hungarian }, + { 2540, PT_SC, ucp_Old_Italic }, + { 2550, PT_SC, ucp_Old_North_Arabian }, + { 2566, PT_SCX, ucp_Old_Permic }, + { 2576, PT_SC, ucp_Old_Persian }, + { 2587, PT_SC, ucp_Old_Sogdian }, + { 2598, PT_SC, ucp_Old_South_Arabian }, + { 2614, PT_SCX, ucp_Old_Turkic }, + { 2624, PT_SCX, ucp_Old_Uyghur }, + { 2634, PT_SCX, ucp_Ol_Onal }, + { 2641, PT_SCX, ucp_Ol_Onal }, + { 2646, PT_SCX, ucp_Oriya }, + { 2652, PT_SCX, ucp_Old_Turkic }, + { 2657, PT_SCX, ucp_Oriya }, + { 2662, PT_SCX, ucp_Osage }, + { 2668, PT_SCX, ucp_Osage }, + { 2673, PT_SC, ucp_Osmanya }, + { 2678, PT_SC, ucp_Osmanya }, + { 2686, PT_SCX, ucp_Old_Uyghur }, + { 2691, PT_GC, ucp_P }, + { 2693, PT_SC, ucp_Pahawh_Hmong }, + { 2705, PT_SC, ucp_Palmyrene }, + { 2710, PT_SC, ucp_Palmyrene }, + { 2720, PT_BOOL, ucp_Pattern_Syntax }, + { 2727, PT_BOOL, ucp_Pattern_Syntax }, + { 2741, PT_BOOL, ucp_Pattern_White_Space }, + { 2759, PT_BOOL, ucp_Pattern_White_Space }, + { 2765, PT_SC, ucp_Pau_Cin_Hau }, + { 2770, PT_SC, ucp_Pau_Cin_Hau }, + { 2780, PT_PC, ucp_Pc }, + { 2783, PT_BOOL, ucp_Prepended_Concatenation_Mark }, + { 2787, PT_PC, ucp_Pd }, + { 2790, PT_PC, ucp_Pe }, + { 2793, PT_SCX, ucp_Old_Permic }, + { 2798, PT_PC, ucp_Pf }, + { 2801, PT_SCX, ucp_Phags_Pa }, + { 2806, PT_SCX, ucp_Phags_Pa }, + { 2814, PT_SC, ucp_Inscriptional_Pahlavi }, + { 2819, PT_SCX, ucp_Psalter_Pahlavi }, + { 2824, PT_SC, ucp_Phoenician }, + { 2829, PT_SC, ucp_Phoenician }, + { 2840, PT_PC, ucp_Pi }, + { 2843, PT_SC, ucp_Miao }, + { 2848, PT_PC, ucp_Po }, + { 2851, PT_BOOL, ucp_Prepended_Concatenation_Mark }, + { 2878, PT_SC, ucp_Inscriptional_Parthian }, + { 2883, PT_PC, ucp_Ps }, + { 2886, PT_SCX, ucp_Psalter_Pahlavi }, + { 2901, PT_SCX, ucp_Coptic }, + { 2906, PT_SC, ucp_Inherited }, + { 2911, PT_BOOL, ucp_Quotation_Mark }, + { 2917, PT_BOOL, ucp_Quotation_Mark }, + { 2931, PT_BOOL, ucp_Radical }, + { 2939, PT_BOOL, ucp_Regional_Indicator }, + { 2957, PT_SC, ucp_Rejang }, + { 2964, PT_BOOL, ucp_Regional_Indicator }, + { 2967, PT_SC, ucp_Rejang }, + { 2972, PT_SCX, ucp_Hanifi_Rohingya }, + { 2977, PT_SCX, ucp_Runic }, + { 2983, PT_SCX, ucp_Runic }, + { 2988, PT_GC, ucp_S }, + { 2990, PT_SCX, ucp_Samaritan }, + { 3000, PT_SCX, ucp_Samaritan }, + { 3005, PT_SC, ucp_Old_South_Arabian }, + { 3010, PT_SC, ucp_Saurashtra }, + { 3015, PT_SC, ucp_Saurashtra }, + { 3026, PT_PC, ucp_Sc }, + { 3029, PT_BOOL, ucp_Soft_Dotted }, + { 3032, PT_BOOL, ucp_Sentence_Terminal }, + { 3049, PT_SC, ucp_SignWriting }, + { 3054, PT_SCX, ucp_Sharada }, + { 3062, PT_SCX, ucp_Shavian }, + { 3070, PT_SCX, ucp_Shavian }, + { 3075, PT_SCX, ucp_Sharada }, + { 3080, PT_SC, ucp_Siddham }, + { 3085, PT_SC, ucp_Siddham }, + { 3093, PT_SC, ucp_SignWriting }, + { 3105, PT_SCX, ucp_Khudawadi }, + { 3110, PT_SCX, ucp_Sinhala }, + { 3115, PT_SCX, ucp_Sinhala }, + { 3123, PT_PC, ucp_Sk }, + { 3126, PT_PC, ucp_Sm }, + { 3129, PT_PC, ucp_So }, + { 3132, PT_BOOL, ucp_Soft_Dotted }, + { 3143, PT_SCX, ucp_Sogdian }, + { 3148, PT_SCX, ucp_Sogdian }, + { 3156, PT_SC, ucp_Old_Sogdian }, + { 3161, PT_SC, ucp_Sora_Sompeng }, + { 3166, PT_SC, ucp_Sora_Sompeng }, + { 3178, PT_SC, ucp_Soyombo }, + { 3183, PT_SC, ucp_Soyombo }, + { 3191, PT_BOOL, ucp_White_Space }, + { 3197, PT_BOOL, ucp_Sentence_Terminal }, + { 3203, PT_SC, ucp_Sundanese }, + { 3208, PT_SC, ucp_Sundanese }, + { 3218, PT_SCX, ucp_Sunuwar }, + { 3223, PT_SCX, ucp_Sunuwar }, + { 3231, PT_SCX, ucp_Syloti_Nagri }, + { 3236, PT_SCX, ucp_Syloti_Nagri }, + { 3248, PT_SCX, ucp_Syriac }, + { 3253, PT_SCX, ucp_Syriac }, + { 3260, PT_SCX, ucp_Tagalog }, + { 3268, PT_SCX, ucp_Tagbanwa }, + { 3273, PT_SCX, ucp_Tagbanwa }, + { 3282, PT_SCX, ucp_Tai_Le }, + { 3288, PT_SC, ucp_Tai_Tham }, + { 3296, PT_SC, ucp_Tai_Viet }, + { 3304, PT_SCX, ucp_Takri }, + { 3309, PT_SCX, ucp_Takri }, + { 3315, PT_SCX, ucp_Tai_Le }, + { 3320, PT_SC, ucp_New_Tai_Lue }, + { 3325, PT_SCX, ucp_Tamil }, + { 3331, PT_SCX, ucp_Tamil }, + { 3336, PT_SCX, ucp_Tangut }, + { 3341, PT_SC, ucp_Tangsa }, + { 3348, PT_SCX, ucp_Tangut }, + { 3355, PT_SC, ucp_Tai_Viet }, + { 3360, PT_SCX, ucp_Telugu }, + { 3365, PT_SCX, ucp_Telugu }, + { 3372, PT_BOOL, ucp_Terminal_Punctuation }, + { 3377, PT_BOOL, ucp_Terminal_Punctuation }, + { 3397, PT_SCX, ucp_Tifinagh }, + { 3402, PT_SCX, ucp_Tagalog }, + { 3407, PT_SCX, ucp_Thaana }, + { 3412, PT_SCX, ucp_Thaana }, + { 3419, PT_SCX, ucp_Thai }, + { 3424, PT_SCX, ucp_Tibetan }, + { 3432, PT_SCX, ucp_Tibetan }, + { 3437, PT_SCX, ucp_Tifinagh }, + { 3446, PT_SCX, ucp_Tirhuta }, + { 3451, PT_SCX, ucp_Tirhuta }, + { 3459, PT_SC, ucp_Tangsa }, + { 3464, PT_SCX, ucp_Todhri }, + { 3471, PT_SCX, ucp_Todhri }, + { 3476, PT_SCX, ucp_Toto }, + { 3481, PT_SCX, ucp_Tulu_Tigalari }, + { 3494, PT_SCX, ucp_Tulu_Tigalari }, + { 3499, PT_SC, ucp_Ugaritic }, + { 3504, PT_SC, ucp_Ugaritic }, + { 3513, PT_BOOL, ucp_Unified_Ideograph }, + { 3519, PT_BOOL, ucp_Unified_Ideograph }, + { 3536, PT_SC, ucp_Unknown }, + { 3544, PT_BOOL, ucp_Uppercase }, + { 3550, PT_BOOL, ucp_Uppercase }, + { 3560, PT_SC, ucp_Vai }, + { 3564, PT_SC, ucp_Vai }, + { 3569, PT_BOOL, ucp_Variation_Selector }, + { 3587, PT_SC, ucp_Vithkuqi }, + { 3592, PT_SC, ucp_Vithkuqi }, + { 3601, PT_BOOL, ucp_Variation_Selector }, + { 3604, PT_SC, ucp_Wancho }, + { 3611, PT_SC, ucp_Warang_Citi }, + { 3616, PT_SC, ucp_Warang_Citi }, + { 3627, PT_SC, ucp_Wancho }, + { 3632, PT_BOOL, ucp_White_Space }, + { 3643, PT_BOOL, ucp_White_Space }, + { 3650, PT_ALNUM, 0 }, + { 3654, PT_BOOL, ucp_XID_Continue }, + { 3659, PT_BOOL, ucp_XID_Continue }, + { 3671, PT_BOOL, ucp_XID_Start }, + { 3676, PT_BOOL, ucp_XID_Start }, + { 3685, PT_SC, ucp_Old_Persian }, + { 3690, PT_PXSPACE, 0 }, + { 3694, PT_SPACE, 0 }, + { 3698, PT_SC, ucp_Cuneiform }, + { 3703, PT_UCNC, 0 }, + { 3707, PT_WORD, 0 }, + { 3711, PT_SCX, ucp_Yezidi }, + { 3716, PT_SCX, ucp_Yezidi }, + { 3723, PT_SCX, ucp_Yi }, + { 3726, PT_SCX, ucp_Yi }, + { 3731, PT_GC, ucp_Z }, + { 3733, PT_SC, ucp_Zanabazar_Square }, + { 3749, PT_SC, ucp_Zanabazar_Square }, + { 3754, PT_SC, ucp_Inherited }, + { 3759, PT_PC, ucp_Zl }, + { 3762, PT_PC, ucp_Zp }, + { 3765, PT_PC, ucp_Zs }, + { 3768, PT_SC, ucp_Common }, + { 3773, PT_SC, ucp_Unknown } +}; + +const size_t PRIV(utt_size) = sizeof(PRIV(utt)) / sizeof(ucp_type_table); + +#endif /* SUPPORT_UNICODE */ + +/* End of pcre2_ucptables_inc.h */ diff --git a/src/pcre2_util.h b/src/pcre2_util.h index ea86355..7bfbee0 100644 --- a/src/pcre2_util.h +++ b/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/src/pcre2_valid_utf.c b/src/pcre2_valid_utf.c index de411b9..3fac931 100644 --- a/src/pcre2_valid_utf.c +++ b/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/src/pcre2_xclass.c b/src/pcre2_xclass.c index 25de7cb..7bcae34 100644 --- a/src/pcre2_xclass.c +++ b/src/pcre2_xclass.c @@ -38,17 +38,15 @@ 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" -#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/src/pcre2demo.c b/src/pcre2demo.c index de2e584..fb9a7e2 100644 --- a/src/pcre2demo.c +++ b/src/pcre2demo.c @@ -73,36 +73,38 @@ PCRE2_SPTR pattern; /* PCRE2_SPTR is a pointer to unsigned code units of */ PCRE2_SPTR subject; /* the appropriate width (in this case, 8 bits). */ PCRE2_SPTR name_table; -int crlf_is_newline; int errornumber; -int find_all; +int find_all, caseless_match; int i; int rc; -int utf8; -uint32_t option_bits; uint32_t namecount; uint32_t name_entry_size; -uint32_t newline; PCRE2_SIZE erroroffset; PCRE2_SIZE *ovector; +PCRE2_SIZE ovector_last[2]; PCRE2_SIZE subject_length; pcre2_match_data *match_data; /************************************************************************** -* First, sort out the command line. There is only one possible option at * -* the moment, "-g" to request repeated matching to find all occurrences, * -* like Perl's /g option. We set the variable find_all to a non-zero value * -* if the -g option is present. * +* First, sort out the command line. Options: * +* - "-g" to request repeated matching to find all occurrences, * +* like Perl's /g option. We set the variable find_all to a non-zero * +* value if the -g option is present. * +* - "-i" to request caseless matching, like Perl's /i option. We set the * +* variable caseless_match to PCRE2_CASELESS if the -i option is * +* present. * **************************************************************************/ find_all = 0; +caseless_match = 0; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-g") == 0) find_all = 1; + else if (strcmp(argv[i], "-i") == 0) caseless_match = PCRE2_CASELESS; else if (argv[i][0] == '-') { printf("Unrecognised option %s\n", argv[i]); @@ -138,7 +140,7 @@ subject_length = (PCRE2_SIZE)strlen((char *)subject); re = pcre2_compile( pattern, /* the pattern */ PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */ - 0, /* default options */ + caseless_match, /* possibly enable caseless */ &errornumber, /* for error number */ &erroroffset, /* for error offset */ NULL); /* use default compile context */ @@ -218,11 +220,12 @@ if (rc == 0) printf("ovector was not big enough for all the captured substrings\n"); /* Since release 10.38 PCRE2 has locked out the use of \K in lookaround -assertions. However, there is an option to re-enable the old behaviour. If that -is set, it is possible to run patterns such as /(?=.\K)/ that use \K in an -assertion to set the start of a match later than its end. In this demonstration -program, we show how to detect this case, but it shouldn't arise because the -option is never set. */ +assertions. This is the recommended behaviour. However, the option +PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK allows applications to re-enable the old +behaviour. If that is set, it is possible to run patterns such as /(?=.\K)/ that +use \K in an assertion to set the start of a match later than its end. In this +demonstration program, we show how to detect this case, although it cannot arise +because the option is never set. */ if (ovector[0] > ovector[1]) { @@ -261,7 +264,9 @@ we have to extract the count of named parentheses from the pattern. */ PCRE2_INFO_NAMECOUNT, /* get the number of named substrings */ &namecount); /* where to put the answer */ -if (namecount == 0) printf("No named substrings\n"); else +if (namecount == 0) + printf("No named substrings\n"); +else { PCRE2_SPTR tabptr; printf("Named substrings\n"); @@ -299,28 +304,8 @@ if (namecount == 0) printf("No named substrings\n"); else * to search for additional matches in the subject string, in a similar * * way to the /g option in Perl. This turns out to be trickier than you * * might think because of the possibility of matching an empty string. * -* What happens is as follows: * * * -* If the previous match was NOT for an empty string, we can just start * -* the next match at the end of the previous one. * -* * -* If the previous match WAS for an empty string, we can't do that, as it * -* would lead to an infinite loop. Instead, a call of pcre2_match() is * -* made with the PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED flags set. The * -* first of these tells PCRE2 that an empty string at the start of the * -* subject is not a valid match; other possibilities must be tried. The * -* second flag restricts PCRE2 to one match attempt at the initial string * -* position. If this match succeeds, an alternative to the empty string * -* match has been found, and we can print it and proceed round the loop, * -* advancing by the length of whatever was found. If this match does not * -* succeed, we still stay in the loop, advancing by just one character. * -* In UTF-8 mode, which can be set by (*UTF) in the pattern, this may be * -* more than one byte. * -* * -* However, there is a complication concerned with newlines. When the * -* newline convention is such that CRLF is a valid newline, we must * -* advance by two characters rather than one. The newline convention can * -* be set in the regex by (*CR), etc.; if not, we must find the default. * +* To help with this task, PCRE2 provides the pcre2_next_match() helper. * *************************************************************************/ if (!find_all) /* Check for -g */ @@ -330,60 +315,21 @@ if (!find_all) /* Check for -g */ return 0; /* Exit the program. */ } -/* Before running the loop, check for UTF-8 and whether CRLF is a valid newline -sequence. First, find the options with which the regex was compiled and extract -the UTF state. */ - -(void)pcre2_pattern_info(re, PCRE2_INFO_ALLOPTIONS, &option_bits); -utf8 = (option_bits & PCRE2_UTF) != 0; - -/* Now find the newline convention and see whether CRLF is a valid newline -sequence. */ - -(void)pcre2_pattern_info(re, PCRE2_INFO_NEWLINE, &newline); -crlf_is_newline = newline == PCRE2_NEWLINE_ANY || - newline == PCRE2_NEWLINE_CRLF || - newline == PCRE2_NEWLINE_ANYCRLF; - /* Loop for second and subsequent matches */ +ovector_last[0] = ovector[0]; +ovector_last[1] = ovector[1]; + for (;;) { - uint32_t options = 0; /* Normally no options */ - PCRE2_SIZE start_offset = ovector[1]; /* Start at end of previous match */ + PCRE2_SIZE start_offset; + uint32_t options; - /* 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. */ + /* After each successful match, we use pcre2_next_match() to obtain the match + parameters for subsequent match attempts. */ - if (ovector[0] == ovector[1]) - { - if (ovector[0] == subject_length) break; - options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED; - } - - /* If the previous match was not an empty string, there is one tricky case to - consider. If a pattern contains \K within a lookbehind assertion at the - start, the end of the matched string can be at the offset where the match - started. Without special action, this leads to a loop that keeps on matching - the same substring. We must detect this case and arrange to move the start on - by one character. The pcre2_get_startchar() function returns the starting - offset that was passed to pcre2_match(). */ - - else - { - PCRE2_SIZE startchar = pcre2_get_startchar(match_data); - if (start_offset <= startchar) - { - if (startchar >= subject_length) break; /* Reached end of subject. */ - start_offset = startchar + 1; /* Advance by one character. */ - if (utf8) /* If UTF-8, it may be more */ - { /* than one code unit. */ - for (; start_offset < subject_length; start_offset++) - if ((subject[start_offset] & 0xc0) != 0x80) break; - } - } - } + if (!pcre2_next_match(match_data, &start_offset, &options)) + break; /* Run the next matching operation */ @@ -396,38 +342,10 @@ for (;;) match_data, /* block for storing the result */ NULL); /* use default match context */ - /* This time, a result of NOMATCH isn't an error. If the value in "options" - is zero, it just means we have found all possible matches, so the loop ends. - Otherwise, it means we have failed to find a non-empty-string match at a - point where there was a previous empty-string match. In this case, we do what - Perl does: advance the matching position by one character, and continue. We - do this by setting the "end of previous match" offset, because that is picked - up at the top of the loop as the point at which to start again. - - There are two complications: (a) When CRLF is a valid newline sequence, and - the current position is just before it, advance by an extra byte. (b) - Otherwise we must ensure that we skip an entire UTF character if we are in - UTF mode. */ + /* If this match attempt fails, exit the loop for subsequent matches. */ if (rc == PCRE2_ERROR_NOMATCH) - { - if (options == 0) break; /* All matches found */ - ovector[1] = start_offset + 1; /* Advance one code unit */ - if (crlf_is_newline && /* If CRLF is a newline & */ - start_offset < subject_length - 1 && /* we are at CRLF, */ - subject[start_offset] == '\r' && - subject[start_offset + 1] == '\n') - ovector[1] += 1; /* Advance by one more. */ - else if (utf8) /* Otherwise, ensure we */ - { /* advance a whole UTF-8 */ - while (ovector[1] < subject_length) /* character. */ - { - if ((subject[ovector[1]] & 0xc0) != 0x80) break; - ovector[1] += 1; - } - } - continue; /* Go round the loop again */ - } + break; /* Other matching errors are not recoverable. */ @@ -439,7 +357,33 @@ for (;;) return 1; } - /* Match succeeded */ + /* This demonstration program depends on pcre2_next_match() to ensure that the + loop for second and subsequent matches does not run forever. However, it would + be robust practice for a production application to verify this. The following + block of code shows how to do this. This error case is not reachable unless + there is a bug in PCRE2. + + Because this program does not set the PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option, + the logic is simple. We verify that either ovector[1] has advanced, or that we + have an empty match touching the end of a previous non-empty match. See the + API documentation for guidance if your application uses + PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK and searches for multiple matches. */ + + if (!(ovector[1] > ovector_last[1] || + (ovector[1] == ovector[0] && ovector_last[1] > ovector_last[0] && + ovector[1] == ovector_last[1]))) + { + printf("\\K was used in an assertion to yield non-advancing matches.\n"); + printf("Run abandoned\n"); + pcre2_match_data_free(match_data); + pcre2_code_free(re); + return 1; + } + + ovector_last[0] = ovector[0]; + ovector_last[1] = ovector[1]; + + /* Match succeeded. */ printf("\nMatch succeeded again at offset %d\n", (int)ovector[0]); @@ -449,9 +393,11 @@ for (;;) if (rc == 0) printf("ovector was not big enough for all the captured substrings\n"); - /* We must guard against patterns such as /(?=.\K)/ that use \K in an - assertion to set the start of a match later than its end. In this - demonstration program, we just detect this case and give up. */ + /* We guard against patterns such as /(?=.\K)/ that use \K in an assertion to + set the start of a match later than its end. As explained above, this case + should not occur because this demonstration program does not set the + PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK option, however, we do include code showing + how to detect it. */ if (ovector[0] > ovector[1]) { @@ -474,7 +420,9 @@ for (;;) printf("%2d: %.*s\n", i, (int)substring_length, (char *)substring_start); } - if (namecount == 0) printf("No named substrings\n"); else + if (namecount == 0) + printf("No named substrings\n"); + else { PCRE2_SPTR tabptr = name_table; printf("Named substrings\n"); @@ -489,6 +437,7 @@ for (;;) } /* End of loop to find second and subsequent matches */ printf("\n"); + pcre2_match_data_free(match_data); pcre2_code_free(re); return 0; diff --git a/src/pcre2grep.c b/src/pcre2grep.c index d56bfb4..705e15f 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -48,8 +48,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "config.h" #endif +#include "pcre2_util.h" + #include +#include #include +#include #include #include #include @@ -260,7 +264,7 @@ static const uint8_t *character_tables = NULL; static uint32_t pcre2_options = 0; static uint32_t extra_options = 0; -static PCRE2_SIZE heap_limit = PCRE2_UNSET; +static uint32_t heap_limit = ~(uint32_t)0; static uint32_t match_limit = 0; static uint32_t depth_limit = 0; @@ -469,7 +473,7 @@ static option_item optionlist[] = { { OP_NODATA, N_LBUFFER, NULL, "line-buffered", "use line buffering" }, { OP_NODATA, N_LOFFSETS, NULL, "line-offsets", "output line numbers and offsets, not text" }, { OP_STRING, N_LOCALE, &locale, "locale=locale", "use the named locale" }, - { OP_SIZE, N_H_LIMIT, &heap_limit, "heap-limit=number", "set PCRE2 heap limit option (kibibytes)" }, + { OP_U32NUMBER, N_H_LIMIT, &heap_limit, "heap-limit=number", "set PCRE2 heap limit option (kibibytes)" }, { OP_U32NUMBER, N_M_LIMIT, &match_limit, "match-limit=number", "set PCRE2 match limit option" }, { OP_U32NUMBER, N_M_LIMIT_DEP, &depth_limit, "depth-limit=number", "set PCRE2 depth limit option" }, { OP_U32NUMBER, N_M_LIMIT_DEP, &depth_limit, "recursion-limit=number", "obsolete synonym for depth-limit" }, @@ -531,44 +535,6 @@ const char utf8_table4[] = { 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 }; -#if !defined(VPCOMPAT) && !defined(HAVE_MEMMOVE) -/************************************************* -* Emulated memmove() for systems without it * -*************************************************/ - -/* This function can make use of bcopy() if it is available. Otherwise do it by -steam, as there are some non-Unix environments that lack both memmove() and -bcopy(). */ - -static void * -emulated_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 */ -} -#undef memmove -#define memmove(d,s,n) emulated_memmove(d,s,n) -#endif /* not VPCOMPAT && not HAVE_MEMMOVE */ - - /************************************************* * Convert code point to UTF-8 * @@ -831,7 +797,7 @@ return result; static void -init_colour_output() +init_colour_output(void) { if (do_colour) { @@ -860,7 +826,9 @@ native z/OS, and "no support". */ /************* Directory scanning Unix-style and z/OS ***********/ -#if (defined HAVE_SYS_STAT_H && defined HAVE_DIRENT_H && defined HAVE_SYS_TYPES_H) || defined NATIVE_ZOS +#if !defined WIN32 && \ + (defined HAVE_SYS_STAT_H && defined HAVE_DIRENT_H && defined HAVE_SYS_TYPES_H) || \ + defined NATIVE_ZOS #include #include #include @@ -964,7 +932,7 @@ return isatty(fileno(f)); /************* Print optionally coloured match Unix-style and z/OS **********/ static void -print_match(const void *buf, int length) +print_match(const void *buf, size_t length) { if (length == 0) return; if (do_colour) fprintf(stdout, "%c[%sm", 0x1b, colour_string); @@ -1100,7 +1068,7 @@ return _isatty(_fileno(f)); /************* Print optionally coloured match in Windows **********/ static void -print_match(const void *buf, int length) +print_match(const void *buf, size_t length) { if (length == 0) return; if (do_colour) @@ -1159,7 +1127,7 @@ return FALSE; /************* Print optionally coloured match when we can't do it **********/ static void -print_match(const void *buf, int length) +print_match(const void *buf, size_t length) { if (length == 0) return; FWRITE_IGNORE(buf, 1, length, stdout); @@ -1169,28 +1137,6 @@ FWRITE_IGNORE(buf, 1, length, stdout); -#ifndef HAVE_STRERROR -/************************************************* -* Provide strerror() for non-ANSI libraries * -*************************************************/ - -/* Some old-fashioned systems still around (e.g. SunOS4) don't have strerror() -in their libraries, but can provide the same facility by this simple -alternative function. */ - -extern int sys_nerr; -extern char *sys_errlist[]; - -char * -strerror(int n) -{ -if (n < 0 || n >= sys_nerr) return "unknown error number"; -return sys_errlist[n]; -} -#endif /* HAVE_STRERROR */ - - - /************************************************* * Usage function * *************************************************/ @@ -1263,8 +1209,8 @@ for (op = optionlist; op->one_char != 0; op++) n = 31 - printf(" -%c", op->one_char); else { - if (op->one_char > 0) sprintf(s, "-%c,", op->one_char); - else strcpy(s, " "); + if (op->one_char > 0) snprintf(s, sizeof(s), "-%c,", op->one_char); + else snprintf(s, sizeof(s), " "); n = 31 - printf(" %s --%s", s, op->long_name); } @@ -1303,7 +1249,7 @@ Returns: TRUE if the path is not excluded static BOOL test_incexc(char *path, patstr *ip, patstr *ep) { -int plen = strlen((const char *)path); +size_t plen = strlen((const char *)path); for (; ep != NULL; ep = ep->next) { @@ -2049,7 +1995,7 @@ switch (*(++string)) break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* The maximum capture number is 65535, so any number greater than that will always be an unknown capture number. We just stop incrementing, in order to @@ -2530,7 +2476,7 @@ necessary, otherwise assume fork(). */ #ifdef WIN32 (void)fflush(stdout); -result = _spawnvp(_P_WAIT, argsvector[0], (const char * const *)argsvector); +result = _spawnvp(_P_WAIT, argsvector[0], (const char * const *)argsvector) != 0; #elif defined __VMS { @@ -2584,7 +2530,7 @@ return result != 0; * Read a portion of the file into buffer * *************************************************/ -static PCRE2_SIZE +static ptrdiff_t fill_buffer(void *handle, int frtype, char *buffer, PCRE2_SIZE length, BOOL input_line_buffered) { @@ -2593,13 +2539,15 @@ PCRE2_SIZE nread; #ifdef SUPPORT_LIBZ if (frtype == FR_LIBZ) - return gzread((gzFile)handle, buffer, length); + return gzread((gzFile)handle, buffer, + (length > UINT_MAX)? UINT_MAX : (unsigned)length); else #endif #ifdef SUPPORT_LIBBZ2 if (frtype == FR_LIBBZ2) - return (PCRE2_SIZE)BZ2_bzread((BZFILE *)handle, buffer, length); + return BZ2_bzread((BZFILE *)handle, buffer, + (length > UINT_MAX)? UINT_MAX : (unsigned)length); else #endif @@ -2612,7 +2560,7 @@ if (nread > 0) VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(buffer, nread); if (nread < length) VALGRIND_MAKE_MEM_UNDEFINED(buffer + nread, length - nread); #endif -return nread; +return (ptrdiff_t)nread; } @@ -2657,6 +2605,7 @@ char *lastmatchrestart = main_buffer; char *ptr = main_buffer; char *endptr; PCRE2_SIZE bufflength; +ptrdiff_t buffrc; BOOL binary = FALSE; BOOL endhyphenpending = FALSE; BOOL lines_printed = FALSE; @@ -2682,13 +2631,17 @@ if (frtype != FR_LIBZ && frtype != FR_LIBBZ2) } else input_line_buffered = FALSE; -bufflength = fill_buffer(handle, frtype, main_buffer, bufsize, +buffrc = fill_buffer(handle, frtype, main_buffer, bufsize, input_line_buffered); +#if defined SUPPORT_LIBZ +if (frtype == FR_LIBZ && buffrc < 0) return 3; +#endif #ifdef SUPPORT_LIBBZ2 -if (frtype == FR_LIBBZ2 && (int)bufflength < 0) return 3; /* Gotcha: bufflength is PCRE2_SIZE */ +if (frtype == FR_LIBBZ2 && buffrc < 0) return 3; #endif +bufflength = (PCRE2_SIZE)buffrc; endptr = main_buffer + bufflength; /* Unless binary-files=text, see if we have a binary file. This uses the same @@ -2786,8 +2739,17 @@ while (ptr < endptr) /* Read more data into the buffer and then try to find the line ending again. */ - bufflength += fill_buffer(handle, frtype, main_buffer + bufflength, + buffrc = fill_buffer(handle, frtype, main_buffer + bufflength, bufsize - bufflength, input_line_buffered); + +#if defined SUPPORT_LIBZ + if (frtype == FR_LIBZ && buffrc < 0) return 3; +#endif +#ifdef SUPPORT_LIBBZ2 + if (frtype == FR_LIBBZ2 && buffrc < 0) return 3; +#endif + + bufflength += (PCRE2_SIZE)buffrc; endptr = main_buffer + bufflength; continue; } @@ -2919,7 +2881,7 @@ while (ptr < endptr) int n = om->groupnum; if (n == 0 || n < mrc) { - int plen = offsets[2*n + 1] - offsets[2*n]; + size_t plen = offsets[2*n + 1] - offsets[2*n]; if (plen > 0) { if (printed && om_separator != NULL) @@ -3258,8 +3220,17 @@ while (ptr < endptr) (void)memmove(main_buffer, main_buffer + bufthird, 2*bufthird); ptr -= bufthird; - bufflength = 2*bufthird + fill_buffer(handle, frtype, - main_buffer + 2*bufthird, bufthird, input_line_buffered); + buffrc = fill_buffer(handle, frtype, main_buffer + 2*bufthird, bufthird, + input_line_buffered); + +#if defined SUPPORT_LIBZ + if (frtype == FR_LIBZ && buffrc < 0) return 3; +#endif +#ifdef SUPPORT_LIBBZ2 + if (frtype == FR_LIBBZ2 && buffrc < 0) return 3; +#endif + + bufflength = 2*bufthird + (PCRE2_SIZE)buffrc; endptr = main_buffer + bufflength; /* Adjust any last match point */ @@ -3438,8 +3409,11 @@ if (isdirectory(pathname)) while ((nextfile = readdirectory(dir)) != NULL) { int frc; - int fnlength = strlen(pathname) + strlen(nextfile) + 2; - if (fnlength > FNBUFSIZ) + int prc; + if (strlen(pathname) + strlen(nextfile) + 2 > sizeof(childpath) || + (prc = snprintf(childpath, sizeof(childpath), "%s%c%s", pathname, + FILESEP, nextfile)) < 0 || + prc >= (int)sizeof(childpath)) { /* LCOV_EXCL_START - this is a "never" event */ fprintf(stderr, "pcre2grep: recursive filename is too long\n"); @@ -3447,7 +3421,6 @@ if (isdirectory(pathname)) break; /* LCOV_EXCL_STOP */ } - sprintf(childpath, "%s%c%s", pathname, FILESEP, nextfile); /* If the realpath() function is available, we can try to prevent endless recursion caused by a symlink pointing to a parent directory (GitHub @@ -3507,7 +3480,19 @@ if (iswild(pathname)) while ((nextfile = readdirectory(dir)) != NULL) { int frc; - sprintf(buffer, "%.512s%.128s", pathname, nextfile); + int prc; + if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer) || + (prc = snprintf(buffer, sizeof(buffer), "%s%s", pathname, + nextfile)) < 0 || + prc >= (int)sizeof(buffer)) + { + /* LCOV_EXCL_START - this is a "never" event */ + fprintf(stderr, "pcre2grep: wildcard filename is too long\n"); + rc = 2; + break; + /* LCOV_EXCL_STOP */ + } + frc = grep_or_recurse(buffer, dir_recurse, FALSE); if (frc > 1) rc = frc; else if (frc == 0 && rc == 1) rc = 0; @@ -3609,7 +3594,18 @@ rc = pcre2grep(handle, frtype, pathname, (filenames > FN_DEFAULT || #ifdef SUPPORT_LIBZ if (frtype == FR_LIBZ) + { + if (rc == 3) + { + int errnum; + const char *err = gzerror(ingz, &errnum); + if (!silent) + fprintf(stderr, "pcre2grep: Failed to read %s using zlib: %s\n", + pathname, err); + rc = 2; /* The normal "something went wrong" code */ + } gzclose(ingz); + } else #endif @@ -3736,16 +3732,16 @@ ordin(int n) { static char buffer[14]; char *p = buffer; -sprintf(p, "%d", n); +snprintf(p, sizeof(buffer), "%d", n); while (*p != 0) p++; n %= 100; if (n >= 11 && n <= 13) n = 0; switch (n%10) { - case 1: strcpy(p, "st"); break; - case 2: strcpy(p, "nd"); break; - case 3: strcpy(p, "rd"); break; - default: strcpy(p, "th"); break; + case 1: snprintf(p, (buffer + sizeof(buffer)) - p, "st"); break; + case 2: snprintf(p, (buffer + sizeof(buffer)) - p, "nd"); break; + case 3: snprintf(p, (buffer + sizeof(buffer)) - p, "rd"); break; + default: snprintf(p, (buffer + sizeof(buffer)) - p, "th"); break; } return buffer; } @@ -4054,10 +4050,10 @@ for (i = 1; i < argc; i++) (int)strlen(arg) : (int)(argequals - arg); if ((ret = snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name), - ret < 0 || ret > (int)sizeof(buff1)) || + ret < 0 || ret >= (int)sizeof(buff1)) || (ret = snprintf(buff2, sizeof(buff2), "%s%.*s", buff1, fulllen - baselen - 2, opbra + 1), - ret < 0 || ret > (int)sizeof(buff2))) + ret < 0 || ret >= (int)sizeof(buff2))) { /* LCOV_EXCL_START - this is a "never" event */ fprintf(stderr, "pcre2grep: Buffer overflow when parsing %s option\n", @@ -4259,9 +4255,9 @@ for (i = 1; i < argc; i++) else { unsigned long int n = decode_number(option_data, op, longop); - if (op->type == OP_U32NUMBER) *((uint32_t *)op->dataptr) = n; + if (op->type == OP_U32NUMBER) *((uint32_t *)op->dataptr) = (uint32_t)n; else if (op->type == OP_SIZE) *((PCRE2_SIZE *)op->dataptr) = n; - else *((int *)op->dataptr) = n; + else *((int *)op->dataptr) = (int)n; } } @@ -4331,7 +4327,7 @@ extra_options |= PCRE2_EXTRA_NEVER_CALLOUT; /* Put limits into the match context. */ -if (heap_limit != PCRE2_UNSET) pcre2_set_heap_limit(match_context, heap_limit); +if (heap_limit != ~(uint32_t)0) pcre2_set_heap_limit(match_context, heap_limit); if (match_limit > 0) pcre2_set_match_limit(match_context, match_limit); if (depth_limit > 0) pcre2_set_depth_limit(match_context, depth_limit); diff --git a/src/pcre2posix.c b/src/pcre2posix.c index f9dcbce..89b9594 100644 --- a/src/pcre2posix.c +++ b/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); + have_offset = 1; + offset_buf[sizeof(offset_buf) - 1] = 0; /* Paranoia for very old snprintf */ } -else + +for (i = 0; *message != 0; i++, message++) + if (i + 1 < errbuf_size) errbuf[i] = *message; + +if (have_offset) { - len = strlen(message); - if (errbuf_size != 0) - { - strncpy(errbuf, message, errbuf_size); - if (errbuf_size <= len) errbuf[errbuf_size - 1] = '\0'; - } - ret = (int)len; + for (message = offset_buf; *message != 0; i++, message++) + if (i + 1 < errbuf_size) errbuf[i] = *message; } -PCRE2_ASSERT(len > 0 || preg != NULL); - -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'; - - 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. */ + +if (errbuf_size > 0) + errbuf[(i < errbuf_size)? i : errbuf_size - 1] = 0; +i++; -return ret + 1; +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/src/pcre2posix.h b/src/pcre2posix.h index cccea57..198612a 100644 --- a/src/pcre2posix.h +++ b/src/pcre2posix.h @@ -118,41 +118,38 @@ typedef struct { regoff_t rm_eo; } regmatch_t; -/* 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 - - 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. */ - -#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. */ +file. So, we don't change existing definitions of PCRE2POSIX_EXP_DECL. -/* By default, we use the standard "extern" declarations. */ +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) +# 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 PCRE2_EXPORT -# define PCRE2POSIX_EXP_DEFN +# 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. 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. + +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 + /* 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/src/pcre2posix_test.c b/src/pcre2posix_test.c index c9c03a4..0dabbfb 100644 --- a/src/pcre2posix_test.c +++ b/src/pcre2posix_test.c @@ -1,13 +1,45 @@ /************************************************* -* PCRE2 POSIX interface test program * +* Perl-Compatible Regular Expressions * *************************************************/ -/* -Written by Philip Hazel, December 2022 -Copyright (c) 2022 -File last edited: December 2022 +/* 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. -This program tests the POSIX wrapper to the PCRE2 regular expression library. + Written by Philip Hazel + Original API code Copyright (c) 1997-2012 University of Cambridge + New API code Copyright (c) 2016-2023 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 program tests the POSIX wrapper to the PCRE2 regular expression library. The main PCRE2 test program is pcre2test, which also tests these function calls. This little program is needed to test the case where the client includes pcre2posix.h but not pcre2.h, mainly to make sure that it builds successfully. @@ -22,6 +54,7 @@ zero. If any test fails there is output to stderr, and the return code is 1. For testing purposes, the "-v" option causes verification output to be written to stdout. */ + #include #include #include @@ -144,12 +177,9 @@ for (int i = 0; i < count; i++) if (rc != 0) { - if (v) - { - char buffer[256]; - (void)regerror(rc, &re, buffer, sizeof(buffer)); - PRINTF("Compile error %d: %s (expected)\n", rc, buffer); - } + char buffer[256]; + (void)regerror(rc, &re, buffer, sizeof(buffer)); + PRINTF("Compile error %d: %s (expected)\n", rc, buffer); continue; } @@ -189,7 +219,7 @@ for (int i = 0; i < count; i++) } } - else if (v) + else { char buffer[256]; (void)regerror(rc, &re, buffer, sizeof(buffer)); diff --git a/src/pcre2test.c b/src/pcre2test.c index 80ab4f8..3242b5c 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -54,13 +54,18 @@ pcre2_internal.h that depend on PCRE2_CODE_UNIT_WIDTH. It does, however, make use of SUPPORT_PCRE2_8, SUPPORT_PCRE2_16, and SUPPORT_PCRE2_32, to ensure that it references only the enabled library functions. */ -#ifdef HAVE_CONFIG_H + +#if defined HAVE_CONFIG_H && !defined PCRE2_CONFIG_H_IDEMPOTENT_GUARD +#define PCRE2_CONFIG_H_IDEMPOTENT_GUARD #include "config.h" #endif + + #include #include #include +#include #include #include #include @@ -196,6 +201,9 @@ claim to be C99 don't support it (hence DISABLE_PERCENT_ZT). */ #define glue(a,b) a##b #define G(a,b) glue(a,b) +#define stringify(x) #x +#define STR(x) stringify(x) + /* Miscellaneous parameters and manifests */ #ifndef CLOCKS_PER_SEC @@ -207,7 +215,8 @@ claim to be C99 don't support it (hence DISABLE_PERCENT_ZT). */ #endif #define CFORE_UNSET UINT32_MAX /* Unset value for startend/cfail/cerror fields */ -#define CONVERT_UNSET UINT32_MAX /* Unset value for convert_type field */ +#define CONVERT_UNSET UINT32_MAX /* Unset value for convert_type/convert_length fields */ +#define MOD_STR_UNSET UINT8_MAX /* Sentinel length for unset string options */ #define DFA_WS_DIMENSION 1000 /* Size of DFA workspace */ #define DEFAULT_OVECCOUNT 15 /* Default ovector count */ #define JUNK_OFFSET 0xdeadbeef /* For initializing ovector */ @@ -217,7 +226,9 @@ claim to be C99 don't support it (hence DISABLE_PERCENT_ZT). */ #define PARENS_NEST_DEFAULT 220 /* Default parentheses nest limit */ #define PATSTACKSIZE 20 /* Pattern stack for save/restore testing */ #define REPLACE_MODSIZE 100 /* Field for reading 8-bit replacement */ +#define SUBSTITUTE_SUBJECT_MODSIZE 100 /* Field for reading 8-bit subject for substitute */ #define VERSION_SIZE 64 /* Size of buffer for the version strings */ +#define REPLACE_BUFFSIZE 256 /* Code units for replacement buffer */ /* Default JIT compile options */ @@ -225,33 +236,60 @@ claim to be C99 don't support it (hence DISABLE_PERCENT_ZT). */ PCRE2_JIT_PARTIAL_SOFT|\ PCRE2_JIT_PARTIAL_HARD) -/* Make sure the buffer into which replacement strings are copied is big enough -to hold them as 32-bit code units. */ - -#define REPLACE_BUFFSIZE 1024 /* This is a byte value */ - /* Execution modes */ -#define PCRE8_MODE 8 -#define PCRE16_MODE 16 -#define PCRE32_MODE 32 +#define PCRE2TEST_MODE_8 8 +#define PCRE2TEST_MODE_16 16 +#define PCRE2TEST_MODE_32 32 /* Processing returns */ -enum { PR_OK, PR_SKIP, PR_ABEND }; +enum { PR_OK, PR_SKIP, PR_ABEND, PR_ENDIF }; + +/* The macro EBCDIC_IO describes whether pcre2tests takes ASCII or EBCDIC as +its input files (or terminal input). If the compiler uses ASCII for character +literals, then we make pcre2test take ASCII as its input and output. This is +different to the core PCRE2 library, where we use macros like "CHAR_A" for every +single character and string literal used in pattern parsing and matching. It +would simply be too arduous to do the same for pcre2test, so we make its +input/output format match the compiler's codepage. */ +#if defined(EBCDIC) && 'a' == 0x81 +#define EBCDIC_IO 1 +#else +#define EBCDIC_IO 0 +#endif /* The macro PRINTABLE determines whether to print an output character as-is or as a hex value when showing compiled patterns. We use it in cases when the locale has not been explicitly changed, so as to get consistent output from systems that differ in their output from isprint() even in the "C" locale. */ -#ifdef EBCDIC -#define PRINTABLE(c) ((c) >= 64 && (c) < 255) +#if defined(EBCDIC) +#define PRINTABLE(c) printable(c) #else #define PRINTABLE(c) ((c) >= 32 && (c) < 127) #endif -#define PRINTOK(c) ((use_tables != NULL && c < 256)? isprint(c) : PRINTABLE(c)) +/* The macro CHAR_OUTPUT is used to output characters in pcre2test's output +format. The input character is encoded in PCRE2's native codepage (EBCDIC, if +enabled), but the output may differ in the case where pcre2test uses ASCII input +and output. */ +#if defined(EBCDIC) && !EBCDIC_IO +#define CHAR_OUTPUT(c) ebcdic_to_ascii(c) +#define CHAR_OUTPUT_HEX(c) CHAR_OUTPUT(c) +#define CHAR_INPUT(c) ascii_to_ebcdic(c) +#define CHAR_INPUT_HEX(c) CHAR_INPUT(c) +#elif defined(EBCDIC) +#define CHAR_OUTPUT(c) (c) +#define CHAR_OUTPUT_HEX(c) ebcdic_to_ascii(c) +#define CHAR_INPUT(c) (c) +#define CHAR_INPUT_HEX(c) ascii_to_ebcdic(c) +#else +#define CHAR_OUTPUT(c) (c) +#define CHAR_OUTPUT_HEX(c) CHAR_OUTPUT(c) +#define CHAR_INPUT(c) (c) +#define CHAR_INPUT_HEX(c) CHAR_INPUT(c) +#endif /* We have to include some of the library source files because we need to use some of the macros, internal structure definitions, and other internal @@ -266,25 +304,38 @@ so that the PCRE2_EXP_xxx macros get set appropriately for an application, not for building the library. Setting PCRE2_CODE_UNIT_WIDTH to zero cuts out all the width-specific settings -in pcre2.h and pcre2_internal.h. Defining PCRE2_BUILDING_PCRE2TEST cuts out the -check in pcre2_internal.h that ensures PCRE2_CODE_UNIT_WIDTH is 8, 16, or 32 -(which it needs to be when compiling one of the libraries). */ +in pcre2.h and pcre2_internal.h. Defining PCRE2_PCRE2TEST cuts out the check in +pcre2_internal.h that ensures PCRE2_CODE_UNIT_WIDTH is 8, 16, or 32 (which it +needs to be when compiling one of the libraries). */ #define PRIV(name) name #define PCRE2_CODE_UNIT_WIDTH 0 -#define PCRE2_BUILDING_PCRE2TEST +#define PCRE2_PCRE2TEST #include "pcre2.h" #include "pcre2posix.h" #include "pcre2_internal.h" -/* We need access to some of the data tables that PCRE2 uses. Defining -PCRE2_PCRE2TEST makes some minor changes in the files. The previous definition -of PRIV avoids name clashes. */ +/* We need access to some of the data tables that PCRE2 uses. The previous +definition of PCRE2_PCRE2TEST makes some minor changes in the files. The +previous definition of PRIV avoids name clashes. */ -#define PCRE2_PCRE2TEST #include "pcre2_tables.c" #include "pcre2_ucd.c" +/* Forward-declarations for PRINTABLE(), etc. */ + +#if defined(EBCDIC) +static BOOL printable(uint32_t c); +#endif +#if defined(EBCDIC) && !EBCDIC_IO +static void ascii_to_ebcdic_str(uint8_t *buf, size_t len); +static void ebcdic_to_ascii_str(uint8_t *buf, size_t len); +#endif +#if defined(EBCDIC) +static uint32_t ascii_to_ebcdic(uint32_t c); +static uint32_t ebcdic_to_ascii(uint32_t c); +#endif + /* 32-bit integer values in the input are read by strtoul() or strtol(). The check needed for overflow depends on whether long ints are in fact longer than ints. They are defined not to be shorter. */ @@ -317,7 +368,7 @@ these inclusions should not be changed. */ #define PCRE2_CODE_UNIT_WIDTH 8 #define PCRE2_SUFFIX(a) G(a,8) #include "pcre2_intmodedep.h" -#include "pcre2_printint.c" +#include "pcre2_printint_inc.h" #undef PCRE2_CODE_UNIT_WIDTH #undef PCRE2_SUFFIX #endif /* SUPPORT_PCRE2_8 */ @@ -326,7 +377,7 @@ these inclusions should not be changed. */ #define PCRE2_CODE_UNIT_WIDTH 16 #define PCRE2_SUFFIX(a) G(a,16) #include "pcre2_intmodedep.h" -#include "pcre2_printint.c" +#include "pcre2_printint_inc.h" #undef PCRE2_CODE_UNIT_WIDTH #undef PCRE2_SUFFIX #endif /* SUPPORT_PCRE2_16 */ @@ -335,14 +386,16 @@ these inclusions should not be changed. */ #define PCRE2_CODE_UNIT_WIDTH 32 #define PCRE2_SUFFIX(a) G(a,32) #include "pcre2_intmodedep.h" -#include "pcre2_printint.c" +#include "pcre2_printint_inc.h" #undef PCRE2_CODE_UNIT_WIDTH #undef PCRE2_SUFFIX #endif /* SUPPORT_PCRE2_32 */ -#define PCRE2_SUFFIX(a) a +#define PCRE2_CODE_UNIT_WIDTH 0 +#include "pcre2_intmodedep.h" /* Clear out the stale macros */ +#undef PCRE2_CODE_UNIT_WIDTH -#include "pcre2_chkdint.c" +#define PCRE2_SUFFIX(a) a /* We need to be able to check input text for UTF-8 validity, whatever code widths are actually available, because the input to pcre2test is always in @@ -357,41 +410,35 @@ extern int valid_utf(PCRE2_SPTR8, PCRE2_SIZE, PCRE2_SIZE *); #include "pcre2_valid_utf.c" #undef PCRE2_CODE_UNIT_WIDTH #undef PCRE2_SPTR +#define PCRE2_SPTR PCRE2_SUFFIX(PCRE2_SPTR) /* If we have 8-bit support, default to it; if there is also 16-or 32-bit -support, it can be selected by a command-line option. If there is no 8-bit -support, there must be 16-bit or 32-bit support, so default to one of them. The -config function, JIT stack, contexts, and version string are the same in all -modes, so use the form of the first that is available. */ +support, it can be selected by a command line option. If there is no 8-bit +support, there must be 16-bit or 32-bit support, so default to one of them. + +The contexts just happen to be exactly the same layout on all bit-widths +(although the contents are very much not the same). For example, the 8-bit +and 16-bit match contexts have the same fields, all at the same offsets and +sizes, but the function pointers for the callouts in the 8-bit context are not +of the same type as in the 16-bit context. When we are parsing the modifier +bits, it is convenient to be able to uniformly set flags in any of the contexts, +so for that purpose only we may ignore the differences between the contexts at +different bit-widths. Choose one arbitrarily (does not need to match the +test mode). */ #if defined SUPPORT_PCRE2_8 -#define DEFAULT_TEST_MODE PCRE8_MODE -#define VERSION_TYPE PCRE2_UCHAR8 -#define PCRE2_CONFIG pcre2_config_8 -#define PCRE2_JIT_STACK pcre2_jit_stack_8 -#define PCRE2_REAL_GENERAL_CONTEXT pcre2_real_general_context_8 +#define DEFAULT_TEST_MODE PCRE2TEST_MODE_8 #define PCRE2_REAL_COMPILE_CONTEXT pcre2_real_compile_context_8 -#define PCRE2_REAL_CONVERT_CONTEXT pcre2_real_convert_context_8 #define PCRE2_REAL_MATCH_CONTEXT pcre2_real_match_context_8 #elif defined SUPPORT_PCRE2_16 -#define DEFAULT_TEST_MODE PCRE16_MODE -#define VERSION_TYPE PCRE2_UCHAR16 -#define PCRE2_CONFIG pcre2_config_16 -#define PCRE2_JIT_STACK pcre2_jit_stack_16 -#define PCRE2_REAL_GENERAL_CONTEXT pcre2_real_general_context_16 +#define DEFAULT_TEST_MODE PCRE2TEST_MODE_16 #define PCRE2_REAL_COMPILE_CONTEXT pcre2_real_compile_context_16 -#define PCRE2_REAL_CONVERT_CONTEXT pcre2_real_convert_context_16 #define PCRE2_REAL_MATCH_CONTEXT pcre2_real_match_context_16 #elif defined SUPPORT_PCRE2_32 -#define DEFAULT_TEST_MODE PCRE32_MODE -#define VERSION_TYPE PCRE2_UCHAR32 -#define PCRE2_CONFIG pcre2_config_32 -#define PCRE2_JIT_STACK pcre2_jit_stack_32 -#define PCRE2_REAL_GENERAL_CONTEXT pcre2_real_general_context_32 +#define DEFAULT_TEST_MODE PCRE2TEST_MODE_32 #define PCRE2_REAL_COMPILE_CONTEXT pcre2_real_compile_context_32 -#define PCRE2_REAL_CONVERT_CONTEXT pcre2_real_convert_context_32 #define PCRE2_REAL_MATCH_CONTEXT pcre2_real_match_context_32 #endif @@ -402,12 +449,14 @@ typedef struct cmdstruct { int value; } cmdstruct; -enum { CMD_FORBID_UTF, CMD_LOAD, CMD_LOADTABLES, CMD_NEWLINE_DEFAULT, - CMD_PATTERN, CMD_PERLTEST, CMD_POP, CMD_POPCOPY, CMD_SAVE, CMD_SUBJECT, - CMD_UNKNOWN }; +enum { CMD_ENDIF, CMD_FORBID_UTF, CMD_IF, CMD_LOAD, CMD_LOADTABLES, + CMD_NEWLINE_DEFAULT, CMD_PATTERN, CMD_PERLTEST, CMD_POP, CMD_POPCOPY, + CMD_SAVE, CMD_SUBJECT, CMD_UNKNOWN }; static cmdstruct cmdlist[] = { + { "endif", CMD_ENDIF }, { "forbid_utf", CMD_FORBID_UTF }, + { "if", CMD_IF }, { "load", CMD_LOAD }, { "loadtables", CMD_LOADTABLES }, { "newline_default", CMD_NEWLINE_DEFAULT }, @@ -470,7 +519,7 @@ enum { MOD_CTC, /* Applies to a compile context */ MOD_OPT, /* Is an option bit */ MOD_OPTMZ, /* Is an optimization directive */ MOD_SIZ, /* Is a PCRE2_SIZE value */ - MOD_STR }; /* Is a string */ + MOD_STR }; /* Is a string; Pascal-encoded with length in first byte */ /* Control bits. Some apply to compiling, some to matching, but some can be set either on a pattern or a data line, so they must all be distinct. There are now @@ -512,7 +561,6 @@ so many of them that they are split into two fields. */ /* Combinations */ #define CTL_DEBUG (CTL_FULLBINCODE|CTL_INFO) /* For setting */ -#define CTL_ANYINFO (CTL_DEBUG|CTL_BINCODE|CTL_CALLOUT_INFO) #define CTL_ANYGLOB (CTL_ALTGLOBAL|CTL_GLOBAL) /* Second control word */ @@ -534,6 +582,7 @@ so many of them that they are split into two fields. */ #define CTL2_NULL_REPLACEMENT 0x00004000u #define CTL2_FRAMESIZE 0x00008000u #define CTL2_SUBSTITUTE_CASE_CALLOUT 0x00010000u +#define CTL2_NULL_SUBSTITUTE_MATCH_DATA 0x00020000u #define CTL2_HEAPFRAMES_SIZE 0x20000000u /* Informational */ #define CTL2_NL_SET 0x40000000u /* Informational */ @@ -564,19 +613,20 @@ different things in the two cases. */ CTL2_SUBSTITUTE_UNSET_EMPTY|\ CTL2_ALLVECTOR|\ CTL2_SUBSTITUTE_CASE_CALLOUT|\ + CTL2_NULL_SUBSTITUTE_MATCH_DATA|\ CTL2_HEAPFRAMES_SIZE) /* Structures for holding modifier information for patterns and subject strings (data). Fields containing modifiers that can be set either for a pattern or a -subject must be at the start and in the same order in both cases so that the -same offset in the big table below works for both. */ +subject (MOD_PD[P]/MOD_PND) must be at the start and in the same order in both +structures so that the same offset in the big table below works for both. */ typedef struct patctl { /* Structure for pattern modifiers. */ uint32_t options; /* Must be in same position as datctl */ uint32_t control; /* Must be in same position as datctl */ uint32_t control2; /* Must be in same position as datctl */ uint32_t jitstack; /* Must be in same position as datctl */ - uint8_t replacement[REPLACE_MODSIZE]; /* So must this */ + uint8_t replacement[1+REPLACE_MODSIZE]; /* So must this */ uint32_t substitute_skip; /* Must be in same position as datctl */ uint32_t substitute_stop; /* Must be in same position as datctl */ uint32_t jit; @@ -586,33 +636,59 @@ typedef struct patctl { /* Structure for pattern modifiers. */ uint32_t convert_length; uint32_t convert_glob_escape; uint32_t convert_glob_separator; - uint32_t regerror_buffsize; - uint8_t locale[LOCALESIZE]; + int32_t regerror_buffsize; + uint8_t locale[1+LOCALESIZE]; } patctl; #define MAXCPYGET 10 #define LENCPYGET 64 -typedef struct datctl { /* Structure for data line modifiers. */ - uint32_t options; /* Must be in same position as patctl */ - uint32_t control; /* Must be in same position as patctl */ - uint32_t control2; /* Must be in same position as patctl */ - uint32_t jitstack; /* Must be in same position as patctl */ - uint8_t replacement[REPLACE_MODSIZE]; /* So must this */ - uint32_t substitute_skip; /* Must be in same position as patctl */ - uint32_t substitute_stop; /* Must be in same position as patctl */ - uint32_t startend[2]; - uint32_t cerror[2]; - uint32_t cfail[2]; - int32_t callout_data; - int32_t copy_numbers[MAXCPYGET]; - int32_t get_numbers[MAXCPYGET]; - uint32_t oveccount; - uint32_t offset; - uint8_t copy_names[LENCPYGET]; - uint8_t get_names[LENCPYGET]; +typedef struct datctl { /* Structure for data line modifiers. */ + uint32_t options; /* Must be in same position as patctl */ + uint32_t control; /* Must be in same position as patctl */ + uint32_t control2; /* Must be in same position as patctl */ + uint32_t jitstack; /* Must be in same position as patctl */ + uint8_t replacement[1+REPLACE_MODSIZE]; /* So must this */ + uint32_t substitute_skip; /* Must be in same position as patctl */ + uint32_t substitute_stop; /* Must be in same position as patctl */ + uint8_t substitute_subject[1+SUBSTITUTE_SUBJECT_MODSIZE]; + uint32_t startend[2]; + uint32_t cerror[2]; + uint32_t cfail[2]; + int32_t callout_data; + int32_t copy_numbers[MAXCPYGET]; + int32_t get_numbers[MAXCPYGET]; + uint32_t oveccount; + PCRE2_SIZE offset; + uint8_t copy_names[LENCPYGET]; + uint8_t get_names[LENCPYGET]; } datctl; +/* Helper functions to zero out the structures. */ + +static void patctl_zero(patctl *p) +{ +memset(p, 0, sizeof(patctl)); +p->replacement[0] = MOD_STR_UNSET; +p->convert_type = CONVERT_UNSET; +p->convert_length = CONVERT_UNSET; +p->regerror_buffsize = -1; +p->locale[0] = MOD_STR_UNSET; +} + +static void datctl_zero(datctl *d) +{ +memset(d, 0, sizeof(datctl)); +d->replacement[0] = MOD_STR_UNSET; +d->substitute_subject[0] = MOD_STR_UNSET; +d->oveccount = DEFAULT_OVECCOUNT; +d->copy_numbers[0] = -1; +d->get_numbers[0] = -1; +d->startend[0] = d->startend[1] = CFORE_UNSET; +d->cerror[0] = d->cerror[1] = CFORE_UNSET; +d->cfail[0] = d->cfail[1] = CFORE_UNSET; +} + /* Ids for which context to modify. */ enum { CTX_PAT, /* Active pattern context */ @@ -626,9 +702,18 @@ enum { CTX_PAT, /* Active pattern context */ #define CO(name) offsetof(PCRE2_REAL_COMPILE_CONTEXT, name) #define MO(name) offsetof(PCRE2_REAL_MATCH_CONTEXT, name) #define PO(name) offsetof(patctl, name) -#define PD(name) PO(name) #define DO(name) offsetof(datctl, name) +/* Validate that the offsets for the shared fields do indeed match. */ + +STATIC_ASSERT(PO(options) == DO(options), options_mismatch); +STATIC_ASSERT(PO(control) == DO(control), control_mismatch); +STATIC_ASSERT(PO(control2) == DO(control2), control2_mismatch); +STATIC_ASSERT(PO(jitstack) == DO(jitstack), jitstack_mismatch); +STATIC_ASSERT(PO(replacement) == DO(replacement), replacement_mismatch); +STATIC_ASSERT(PO(substitute_skip) == DO(substitute_skip), substitute_skip_mismatch); +STATIC_ASSERT(PO(substitute_stop) == DO(substitute_stop), substitute_stop_mismatch); + /* Table of all long-form modifiers. Must be in collating sequence of modifier name because it is searched by binary chop. */ @@ -657,7 +742,7 @@ static modstruct modlist[] = { { "alt_extended_class", MOD_PAT, MOD_OPT, PCRE2_ALT_EXTENDED_CLASS, PO(options) }, { "alt_verbnames", MOD_PAT, MOD_OPT, PCRE2_ALT_VERBNAMES, PO(options) }, { "altglobal", MOD_PND, MOD_CTL, CTL_ALTGLOBAL, PO(control) }, - { "anchored", MOD_PD, MOD_OPT, PCRE2_ANCHORED, PD(options) }, + { "anchored", MOD_PD, MOD_OPT, PCRE2_ANCHORED, PO(options) }, { "ascii_all", MOD_CTC, MOD_OPT, PCRE2_EXTRA_ASCII_ALL, CO(extra_options) }, { "ascii_bsd", MOD_CTC, MOD_OPT, PCRE2_EXTRA_ASCII_BSD, CO(extra_options) }, { "ascii_bss", MOD_CTC, MOD_OPT, PCRE2_EXTRA_ASCII_BSS, CO(extra_options) }, @@ -697,7 +782,7 @@ static modstruct modlist[] = { { "dotstar_anchor", MOD_CTC, MOD_OPTMZ, PCRE2_DOTSTAR_ANCHOR, 0 }, { "dotstar_anchor_off", MOD_CTC, MOD_OPTMZ, PCRE2_DOTSTAR_ANCHOR_OFF, 0 }, { "dupnames", MOD_PATP, MOD_OPT, PCRE2_DUPNAMES, PO(options) }, - { "endanchored", MOD_PD, MOD_OPT, PCRE2_ENDANCHORED, PD(options) }, + { "endanchored", MOD_PD, MOD_OPT, PCRE2_ENDANCHORED, PO(options) }, { "escaped_cr_is_lf", MOD_CTC, MOD_OPT, PCRE2_EXTRA_ESCAPED_CR_IS_LF, CO(extra_options) }, { "expand", MOD_PAT, MOD_CTL, CTL_EXPAND, PO(control) }, { "extended", MOD_PATP, MOD_OPT, PCRE2_EXTENDED, PO(options) }, @@ -730,20 +815,20 @@ static modstruct modlist[] = { { "max_pattern_compiled_length", MOD_CTC, MOD_SIZ, 0, CO(max_pattern_compiled_length) }, { "max_pattern_length", MOD_CTC, MOD_SIZ, 0, CO(max_pattern_length) }, { "max_varlookbehind", MOD_CTC, MOD_INT, 0, CO(max_varlookbehind) }, - { "memory", MOD_PD, MOD_CTL, CTL_MEMORY, PD(control) }, + { "memory", MOD_PD, MOD_CTL, CTL_MEMORY, PO(control) }, { "multiline", MOD_PATP, MOD_OPT, PCRE2_MULTILINE, PO(options) }, { "never_backslash_c", MOD_PAT, MOD_OPT, PCRE2_NEVER_BACKSLASH_C, PO(options) }, { "never_callout", MOD_CTC, MOD_OPT, PCRE2_EXTRA_NEVER_CALLOUT, CO(extra_options) }, { "never_ucp", MOD_PAT, MOD_OPT, PCRE2_NEVER_UCP, PO(options) }, { "never_utf", MOD_PAT, MOD_OPT, PCRE2_NEVER_UTF, PO(options) }, - { "newline", MOD_CTC, MOD_NL, 0, CO(newline_convention) }, + { "newline", MOD_CTC, MOD_NL, 0, 0 }, { "no_auto_capture", MOD_PAT, MOD_OPT, PCRE2_NO_AUTO_CAPTURE, PO(options) }, { "no_auto_possess", MOD_PATP, MOD_OPT, PCRE2_NO_AUTO_POSSESS, PO(options) }, { "no_bs0", MOD_CTC, MOD_OPT, PCRE2_EXTRA_NO_BS0, CO(extra_options) }, { "no_dotstar_anchor", MOD_PAT, MOD_OPT, PCRE2_NO_DOTSTAR_ANCHOR, PO(options) }, { "no_jit", MOD_DATP, MOD_OPT, PCRE2_NO_JIT, DO(options) }, { "no_start_optimize", MOD_PATP, MOD_OPT, PCRE2_NO_START_OPTIMIZE, PO(options) }, - { "no_utf_check", MOD_PD, MOD_OPT, PCRE2_NO_UTF_CHECK, PD(options) }, + { "no_utf_check", MOD_PD, MOD_OPT, PCRE2_NO_UTF_CHECK, PO(options) }, { "notbol", MOD_DAT, MOD_OPT, PCRE2_NOTBOL, DO(options) }, { "notempty", MOD_DAT, MOD_OPT, PCRE2_NOTEMPTY, DO(options) }, { "notempty_atstart", MOD_DAT, MOD_OPT, PCRE2_NOTEMPTY_ATSTART, DO(options) }, @@ -752,7 +837,8 @@ static modstruct modlist[] = { { "null_pattern", MOD_PAT, MOD_CTL, CTL2_NULL_PATTERN, PO(control2) }, { "null_replacement", MOD_DAT, MOD_CTL, CTL2_NULL_REPLACEMENT, DO(control2) }, { "null_subject", MOD_DAT, MOD_CTL, CTL2_NULL_SUBJECT, DO(control2) }, - { "offset", MOD_DAT, MOD_INT, 0, DO(offset) }, + { "null_substitute_match_data", MOD_PND, MOD_CTL, CTL2_NULL_SUBSTITUTE_MATCH_DATA, PO(control2) }, + { "offset", MOD_DAT, MOD_SIZ, 0, DO(offset) }, { "offset_limit", MOD_CTM, MOD_SIZ, 0, MO(offset_limit)}, { "optimization_full", MOD_CTC, MOD_OPTMZ, PCRE2_OPTIMIZATION_FULL, 0 }, { "optimization_none", MOD_CTC, MOD_OPTMZ, PCRE2_OPTIMIZATION_NONE, 0 }, @@ -770,13 +856,13 @@ static modstruct modlist[] = { { "pushtablescopy", MOD_PAT, MOD_CTL, CTL_PUSHTABLESCOPY, PO(control) }, { "python_octal", MOD_CTC, MOD_OPT, PCRE2_EXTRA_PYTHON_OCTAL, CO(extra_options) }, { "recursion_limit", MOD_CTM, MOD_INT, 0, MO(depth_limit) }, /* Obsolete synonym */ - { "regerror_buffsize", MOD_PAT, MOD_INT, 0, PO(regerror_buffsize) }, + { "regerror_buffsize", MOD_PAT, MOD_INS, 0, PO(regerror_buffsize) }, { "replace", MOD_PND, MOD_STR, REPLACE_MODSIZE, PO(replacement) }, { "stackguard", MOD_PAT, MOD_INT, 0, PO(stackguard_test) }, { "start_optimize", MOD_CTC, MOD_OPTMZ, PCRE2_START_OPTIMIZE, 0 }, { "start_optimize_off", MOD_CTC, MOD_OPTMZ, PCRE2_START_OPTIMIZE_OFF, 0 }, { "startchar", MOD_PND, MOD_CTL, CTL_STARTCHAR, PO(control) }, - { "startoffset", MOD_DAT, MOD_INT, 0, DO(offset) }, + { "startoffset", MOD_DAT, MOD_SIZ, 0, DO(offset) }, { "subject_literal", MOD_PATP, MOD_CTL, CTL2_SUBJECT_LITERAL, PO(control2) }, { "substitute_callout", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_CALLOUT, PO(control2) }, { "substitute_case_callout", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_CASE_CALLOUT, PO(control2) }, @@ -787,6 +873,7 @@ static modstruct modlist[] = { { "substitute_replacement_only", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_REPLACEMENT_ONLY, PO(control2) }, { "substitute_skip", MOD_PND, MOD_INT, 0, PO(substitute_skip) }, { "substitute_stop", MOD_PND, MOD_INT, 0, PO(substitute_stop) }, + { "substitute_subject", MOD_DAT, MOD_STR, SUBSTITUTE_SUBJECT_MODSIZE, DO(substitute_subject) }, { "substitute_unknown_unset", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_UNKNOWN_UNSET, PO(control2) }, { "substitute_unset_empty", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_UNSET_EMPTY, PO(control2) }, { "tables", MOD_PAT, MOD_INT, 0, PO(tables_id) }, @@ -913,12 +1000,12 @@ table itself easier to read. */ #define SUPPORT_32 0 #endif -#ifdef EBCDIC +#if defined EBCDIC #define SUPPORT_EBCDIC 1 -#define EBCDIC_NL CHAR_LF +#define SUPPORT_EBCDIC_NL25 CHAR_LF == 0x25 #else #define SUPPORT_EBCDIC 0 -#define EBCDIC_NL 0 +#define SUPPORT_EBCDIC_NL25 0 #endif #ifdef NEVER_BACKSLASH_C @@ -935,7 +1022,6 @@ typedef struct coptstruct { enum { CONF_BSR, CONF_FIX, - CONF_FIZ, CONF_INT, CONF_NL, CONF_JU @@ -945,10 +1031,11 @@ static coptstruct coptlist[] = { { "backslash-C", CONF_FIX, BACKSLASH_C }, { "bsr", CONF_BSR, PCRE2_CONFIG_BSR }, { "ebcdic", CONF_FIX, SUPPORT_EBCDIC }, - { "ebcdic-nl", CONF_FIZ, EBCDIC_NL }, + { "ebcdic-io", CONF_FIX, EBCDIC_IO }, + { "ebcdic-nl25", CONF_FIX, SUPPORT_EBCDIC_NL25 }, { "jit", CONF_INT, PCRE2_CONFIG_JIT }, { "jitusable", CONF_JU, 0 }, - { "linksize", CONF_INT, PCRE2_CONFIG_LINKSIZE }, + { "linksize", CONF_INT, PCRE2_CONFIG_EFFECTIVE_LINKSIZE }, { "newline", CONF_NL, PCRE2_CONFIG_NEWLINE }, { "pcre2-16", CONF_FIX, SUPPORT_16 }, { "pcre2-32", CONF_FIX, SUPPORT_32 }, @@ -962,6 +1049,8 @@ static coptstruct coptlist[] = { #undef SUPPORT_16 #undef SUPPORT_32 #undef SUPPORT_EBCDIC +#undef SUPPORT_EBDCIC_NL25 +#undef BACKSLASH_C /* Types for the parser, to be used in process_data() */ @@ -977,24 +1066,25 @@ static FILE *infile; static FILE *outfile; static const void *last_callout_mark; -static PCRE2_JIT_STACK *jit_stack = NULL; -static size_t jit_stack_size = 0; static BOOL first_callout; static BOOL jit_was_used; static BOOL restrict_for_perl_test = FALSE; static BOOL show_memory = FALSE; +static BOOL preprocess_only = FALSE; +static BOOL inside_if = FALSE; +static BOOL malloc_testing = FALSE; static int jitrc; /* Return from JIT compile */ -static int test_mode = DEFAULT_TEST_MODE; static int timeit = 0; static int timeitm = 0; +static int mallocs_until_failure = INT_MAX; +static int mallocs_called = 0; -clock_t total_compile_time = 0; -clock_t total_jit_compile_time = 0; -clock_t total_match_time = 0; +static clock_t total_compile_time = 0; +static clock_t total_jit_compile_time = 0; +static clock_t total_match_time = 0; -static uint32_t code_unit_size; /* Bytes */ static uint32_t dfa_matched; static uint32_t forbid_utf = 0; static uint32_t maxlookbehind; @@ -1004,18 +1094,11 @@ static uint32_t maxcapcount; static uint16_t local_newline_default = 0; -static VERSION_TYPE jittarget[VERSION_SIZE]; -static VERSION_TYPE version[VERSION_SIZE]; -static VERSION_TYPE uversion[VERSION_SIZE]; - static patctl def_patctl; static patctl pat_patctl; static datctl def_datctl; static datctl dat_datctl; -static void *patstack[PATSTACKSIZE]; -static int patstacknext = 0; - static void *malloclist[MALLOCLISTSIZE]; static PCRE2_SIZE malloclistlength[MALLOCLISTSIZE]; static uint32_t malloclistptr = 0; @@ -1027,1489 +1110,101 @@ static regex_t preg = { NULL, NULL, 0, 0, 0, 0 }; static int *dfa_workspace = NULL; static const uint8_t *locale_tables = NULL; static const uint8_t *use_tables = NULL; -static uint8_t locale_name[32]; +static uint8_t locale_name[LOCALESIZE]; static uint8_t *tables3 = NULL; /* For binary-loaded tables */ static uint32_t loadtables_length = 0; /* We need buffers for building 16/32-bit strings; 8-bit strings don't need rebuilding, but set up the same naming scheme for use in macros. The "buffer" -buffer is where all input lines are read. Its size is the same as pbuffer8. -Pattern lines are always copied to pbuffer8 for use in callouts, even if they -are actually compiled from pbuffer16 or pbuffer32. */ +buffer is where all input lines are read. Its size is the same as pbuffer8. */ static size_t pbuffer8_size = 50000; /* Initial size, bytes */ static uint8_t *pbuffer8 = NULL; -static uint8_t *buffer = NULL; - -/* The dbuffer is where all processed data lines are put. In non-8-bit modes it -is cast as needed. For long data lines it grows as necessary. */ - -static size_t dbuffer_size = 1u << 14; /* Initial size, bytes */ -static uint8_t *dbuffer = NULL; - - -/* ---------------- Mode-dependent variables -------------------*/ - -#ifdef SUPPORT_PCRE2_8 -static pcre2_code_8 *compiled_code8; -static pcre2_general_context_8 *general_context8, *general_context_copy8; -static pcre2_compile_context_8 *pat_context8, *default_pat_context8; -static pcre2_convert_context_8 *con_context8, *default_con_context8; -static pcre2_match_context_8 *dat_context8, *default_dat_context8; -static pcre2_match_data_8 *match_data8; -#endif - #ifdef SUPPORT_PCRE2_16 -static pcre2_code_16 *compiled_code16; -static pcre2_general_context_16 *general_context16, *general_context_copy16; -static pcre2_compile_context_16 *pat_context16, *default_pat_context16; -static pcre2_convert_context_16 *con_context16, *default_con_context16; -static pcre2_match_context_16 *dat_context16, *default_dat_context16; -static pcre2_match_data_16 *match_data16; -static PCRE2_SIZE pbuffer16_size = 0; /* Set only when needed */ +static size_t pbuffer16_size = 0; /* Size, bytes! Set only when needed */ static uint16_t *pbuffer16 = NULL; #endif - #ifdef SUPPORT_PCRE2_32 -static pcre2_code_32 *compiled_code32; -static pcre2_general_context_32 *general_context32, *general_context_copy32; -static pcre2_compile_context_32 *pat_context32, *default_pat_context32; -static pcre2_convert_context_32 *con_context32, *default_con_context32; -static pcre2_match_context_32 *dat_context32, *default_dat_context32; -static pcre2_match_data_32 *match_data32; -static PCRE2_SIZE pbuffer32_size = 0; /* Set only when needed */ +static size_t pbuffer32_size = 0; /* Size, bytes! Set only when needed */ static uint32_t *pbuffer32 = NULL; #endif +static uint8_t *buffer = NULL; +/* The dbuffer is where all processed data lines are put. In non-8-bit modes it +is cast as needed. For long data lines it grows as necessary. */ -/* ---------------- Macros that work in all modes ----------------- */ - -#define CAST8VAR(x) CASTVAR(uint8_t *, x) -#define SET(x,y) SETOP(x,y,=) -#define SETPLUS(x,y) SETOP(x,y,+=) -#define strlen8(x) strlen((char *)x) - - -/* ---------------- Mode-dependent, runtime-testing macros ------------------*/ - -/* Define macros for variables and functions that must be selected dynamically -depending on the mode setting (8, 16, 32). These are dependent on which modes -are supported. */ - -#if (defined (SUPPORT_PCRE2_8) + defined (SUPPORT_PCRE2_16) + \ - defined (SUPPORT_PCRE2_32)) >= 2 - -/* ----- All three modes supported ----- */ - -#if defined(SUPPORT_PCRE2_8) && defined(SUPPORT_PCRE2_16) && defined(SUPPORT_PCRE2_32) - -#define CASTFLD(t,a,b) ((test_mode == PCRE8_MODE)? (t)(G(a,8)->b) : \ - (test_mode == PCRE16_MODE)? (t)(G(a,16)->b) : (t)(G(a,32)->b)) - -#define CASTVAR(t,x) ( \ - (test_mode == PCRE8_MODE)? (t)G(x,8) : \ - (test_mode == PCRE16_MODE)? (t)G(x,16) : (t)G(x,32)) - -#define CODE_UNIT(a,b) ( \ - (test_mode == PCRE8_MODE)? (uint32_t)(((PCRE2_SPTR8)(a))[b]) : \ - (test_mode == PCRE16_MODE)? (uint32_t)(((PCRE2_SPTR16)(a))[b]) : \ - (uint32_t)(((PCRE2_SPTR32)(a))[b])) - -#define CONCTXCPY(a,b) \ - if (test_mode == PCRE8_MODE) \ - memcpy(G(a,8),G(b,8),sizeof(pcre2_convert_context_8)); \ - else if (test_mode == PCRE16_MODE) \ - memcpy(G(a,16),G(b,16),sizeof(pcre2_convert_context_16)); \ - else memcpy(G(a,32),G(b,32),sizeof(pcre2_convert_context_32)) - -#define CONVERT_COPY(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - memcpy(G(a,8),(char *)b,c); \ - else if (test_mode == PCRE16_MODE) \ - memcpy(G(a,16),(char *)b,(c)*2); \ - else if (test_mode == PCRE32_MODE) \ - memcpy(G(a,32),(char *)b,(c)*4) - -#define DATCTXCPY(a,b) \ - if (test_mode == PCRE8_MODE) \ - memcpy(G(a,8),G(b,8),sizeof(pcre2_match_context_8)); \ - else if (test_mode == PCRE16_MODE) \ - memcpy(G(a,16),G(b,16),sizeof(pcre2_match_context_16)); \ - else memcpy(G(a,32),G(b,32),sizeof(pcre2_match_context_32)) - -#define FLD(a,b) ((test_mode == PCRE8_MODE)? G(a,8)->b : \ - (test_mode == PCRE16_MODE)? G(a,16)->b : G(a,32)->b) - -#define PATCTXCPY(a,b) \ - if (test_mode == PCRE8_MODE) \ - memcpy(G(a,8),G(b,8),sizeof(pcre2_compile_context_8)); \ - else if (test_mode == PCRE16_MODE) \ - memcpy(G(a,16),G(b,16),sizeof(pcre2_compile_context_16)); \ - else memcpy(G(a,32),G(b,32),sizeof(pcre2_compile_context_32)) - -#define PCHARS(lv, p, offset, len, utf, f) \ - if (test_mode == PCRE32_MODE) \ - lv = pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f); \ - else if (test_mode == PCRE16_MODE) \ - lv = pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f); \ - else \ - lv = pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f) - -#define PCHARSV(p, offset, len, utf, f) \ - if (test_mode == PCRE32_MODE) \ - (void)pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f); \ - else if (test_mode == PCRE16_MODE) \ - (void)pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f); \ - else \ - (void)pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f) - -#define PCRE2_CALLOUT_ENUMERATE(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_callout_enumerate_8(compiled_code8, \ - (int (*)(struct pcre2_callout_enumerate_block_8 *, void *))b,c); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_callout_enumerate_16(compiled_code16, \ - (int(*)(struct pcre2_callout_enumerate_block_16 *, void *))b,c); \ - else \ - a = pcre2_callout_enumerate_32(compiled_code32, \ - (int (*)(struct pcre2_callout_enumerate_block_32 *, void *))b,c) - -#define PCRE2_CODE_COPY_FROM_VOID(a,b) \ - if (test_mode == PCRE8_MODE) \ - G(a,8) = pcre2_code_copy_8(b); \ - else if (test_mode == PCRE16_MODE) \ - G(a,16) = pcre2_code_copy_16(b); \ - else \ - G(a,32) = pcre2_code_copy_32(b) - -#define PCRE2_CODE_COPY_TO_VOID(a,b) \ - if (test_mode == PCRE8_MODE) \ - a = (void *)pcre2_code_copy_8(G(b,8)); \ - else if (test_mode == PCRE16_MODE) \ - a = (void *)pcre2_code_copy_16(G(b,16)); \ - else \ - a = (void *)pcre2_code_copy_32(G(b,32)) - -#define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) \ - if (test_mode == PCRE8_MODE) \ - a = (void *)pcre2_code_copy_with_tables_8(G(b,8)); \ - else if (test_mode == PCRE16_MODE) \ - a = (void *)pcre2_code_copy_with_tables_16(G(b,16)); \ - else \ - a = (void *)pcre2_code_copy_with_tables_32(G(b,32)) - -#define PCRE2_COMPILE(a,b,c,d,e,f,g) \ - if (test_mode == PCRE8_MODE) \ - G(a,8) = pcre2_compile_8(b,c,d,e,f,g); \ - else if (test_mode == PCRE16_MODE) \ - G(a,16) = pcre2_compile_16(b,c,d,e,f,g); \ - else \ - G(a,32) = pcre2_compile_32(b,c,d,e,f,g) - -#define PCRE2_CONVERTED_PATTERN_FREE(a) \ - if (test_mode == PCRE8_MODE) pcre2_converted_pattern_free_8((PCRE2_UCHAR8 *)a); \ - else if (test_mode == PCRE16_MODE) pcre2_converted_pattern_free_16((PCRE2_UCHAR16 *)a); \ - else pcre2_converted_pattern_free_32((PCRE2_UCHAR32 *)a) - -#define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_dfa_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h,i,j); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_dfa_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h,i,j); \ - else \ - a = pcre2_dfa_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h,i,j) - -#define PCRE2_GET_ERROR_MESSAGE(r,a,b) \ - if (test_mode == PCRE8_MODE) \ - r = pcre2_get_error_message_8(a,G(b,8),G(G(b,8),_size)); \ - else if (test_mode == PCRE16_MODE) \ - r = pcre2_get_error_message_16(a,G(b,16),G(G(b,16),_size/2)); \ - else \ - r = pcre2_get_error_message_32(a,G(b,32),G(G(b,32),_size/4)) - -#define PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE(r,a) \ - if (test_mode == PCRE8_MODE) \ - r = pcre2_get_match_data_heapframes_size_8(G(a,8)); \ - else if (test_mode == PCRE16_MODE) \ - r = pcre2_get_match_data_heapframes_size_16(G(a,16)); \ - else \ - r = pcre2_get_match_data_heapframes_size_32(G(a,32)) - -#define PCRE2_GET_OVECTOR_COUNT(a,b) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_get_ovector_count_8(G(b,8)); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_get_ovector_count_16(G(b,16)); \ - else \ - a = pcre2_get_ovector_count_32(G(b,32)) - -#define PCRE2_GET_STARTCHAR(a,b) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_get_startchar_8(G(b,8)); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_get_startchar_16(G(b,16)); \ - else \ - a = pcre2_get_startchar_32(G(b,32)) - -#define PCRE2_JIT_COMPILE(r,a,b) \ - if (test_mode == PCRE8_MODE) r = pcre2_jit_compile_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) r = pcre2_jit_compile_16(G(a,16),b); \ - else r = pcre2_jit_compile_32(G(a,32),b) - -#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) \ - if (test_mode == PCRE8_MODE) pcre2_jit_free_unused_memory_8(G(a,8)); \ - else if (test_mode == PCRE16_MODE) pcre2_jit_free_unused_memory_16(G(a,16)); \ - else pcre2_jit_free_unused_memory_32(G(a,32)) - -#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_jit_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_jit_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h); \ - else \ - a = pcre2_jit_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h) - -#define PCRE2_JIT_STACK_CREATE(a,b,c,d) \ - if (test_mode == PCRE8_MODE) \ - a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_8(b,c,d); \ - else if (test_mode == PCRE16_MODE) \ - a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_16(b,c,d); \ - else \ - a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_32(b,c,d); - -#define PCRE2_JIT_STACK_ASSIGN(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - pcre2_jit_stack_assign_8(G(a,8),(pcre2_jit_callback_8)b,c); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_jit_stack_assign_16(G(a,16),(pcre2_jit_callback_16)b,c); \ - else \ - pcre2_jit_stack_assign_32(G(a,32),(pcre2_jit_callback_32)b,c); - -#define PCRE2_JIT_STACK_FREE(a) \ - if (test_mode == PCRE8_MODE) \ - pcre2_jit_stack_free_8((pcre2_jit_stack_8 *)a); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_jit_stack_free_16((pcre2_jit_stack_16 *)a); \ - else \ - pcre2_jit_stack_free_32((pcre2_jit_stack_32 *)a); - -#define PCRE2_MAKETABLES(a,c) \ - if (test_mode == PCRE8_MODE) a = pcre2_maketables_8(G(c,8)); \ - else if (test_mode == PCRE16_MODE) a = pcre2_maketables_16(G(c,16)); \ - else a = pcre2_maketables_32(G(c,32)) - -#define PCRE2_MAKETABLES_FREE(c,a) \ - if (test_mode == PCRE8_MODE) pcre2_maketables_free_8(G(c,8),a); \ - else if (test_mode == PCRE16_MODE) pcre2_maketables_free_16(G(c,16),a); \ - else pcre2_maketables_free_32(G(c,32),a) - -#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h); \ - else \ - a = pcre2_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h) - -#define PCRE2_MATCH_DATA_CREATE(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - G(a,8) = pcre2_match_data_create_8(b,G(c,8)); \ - else if (test_mode == PCRE16_MODE) \ - G(a,16) = pcre2_match_data_create_16(b,G(c,16)); \ - else \ - G(a,32) = pcre2_match_data_create_32(b,G(c,32)) - -#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),G(c,8)); \ - else if (test_mode == PCRE16_MODE) \ - G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),G(c,16)); \ - else \ - G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),G(c,32)) - -#define PCRE2_MATCH_DATA_FREE(a) \ - if (test_mode == PCRE8_MODE) \ - pcre2_match_data_free_8(G(a,8)); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_match_data_free_16(G(a,16)); \ - else \ - pcre2_match_data_free_32(G(a,32)) - -#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_pattern_convert_8(G(b,8),c,d,(PCRE2_UCHAR8 **)e,f,G(g,8)); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_pattern_convert_16(G(b,16),c,d,(PCRE2_UCHAR16 **)e,f,G(g,16)); \ - else \ - a = pcre2_pattern_convert_32(G(b,32),c,d,(PCRE2_UCHAR32 **)e,f,G(g,32)) - -#define PCRE2_PATTERN_INFO(a,b,c,d) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_pattern_info_8(G(b,8),c,d); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_pattern_info_16(G(b,16),c,d); \ - else \ - a = pcre2_pattern_info_32(G(b,32),c,d) - -#define PCRE2_PRINTINT(a) \ - if (test_mode == PCRE8_MODE) \ - pcre2_printint_8(compiled_code8,outfile,a); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_printint_16(compiled_code16,outfile,a); \ - else \ - pcre2_printint_32(compiled_code32,outfile,a) - -#define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \ - if (test_mode == PCRE8_MODE) \ - r = pcre2_serialize_decode_8((pcre2_code_8 **)a,b,c,G(d,8)); \ - else if (test_mode == PCRE16_MODE) \ - r = pcre2_serialize_decode_16((pcre2_code_16 **)a,b,c,G(d,16)); \ - else \ - r = pcre2_serialize_decode_32((pcre2_code_32 **)a,b,c,G(d,32)) - -#define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \ - if (test_mode == PCRE8_MODE) \ - r = pcre2_serialize_encode_8((const pcre2_code_8 **)a,b,c,d,G(e,8)); \ - else if (test_mode == PCRE16_MODE) \ - r = pcre2_serialize_encode_16((const pcre2_code_16 **)a,b,c,d,G(e,16)); \ - else \ - r = pcre2_serialize_encode_32((const pcre2_code_32 **)a,b,c,d,G(e,32)) - -#define PCRE2_SERIALIZE_FREE(a) \ - if (test_mode == PCRE8_MODE) \ - pcre2_serialize_free_8(a); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_serialize_free_16(a); \ - else \ - pcre2_serialize_free_32(a) - -#define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \ - if (test_mode == PCRE8_MODE) \ - r = pcre2_serialize_get_number_of_codes_8(a); \ - else if (test_mode == PCRE16_MODE) \ - r = pcre2_serialize_get_number_of_codes_16(a); \ - else \ - r = pcre2_serialize_get_number_of_codes_32(a); \ - -#define PCRE2_SET_CALLOUT(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_callout_8(G(a,8),(int (*)(pcre2_callout_block_8 *, void *))b,c); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_callout_16(G(a,16),(int (*)(pcre2_callout_block_16 *, void *))b,c); \ - else \ - pcre2_set_callout_32(G(a,32),(int (*)(pcre2_callout_block_32 *, void *))b,c); - -#define PCRE2_SET_CHARACTER_TABLES(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_character_tables_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_character_tables_16(G(a,16),b); \ - else \ - pcre2_set_character_tables_32(G(a,32),b) - -#define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_compile_recursion_guard_8(G(a,8),b,c); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_compile_recursion_guard_16(G(a,16),b,c); \ - else \ - pcre2_set_compile_recursion_guard_32(G(a,32),b,c) - -#define PCRE2_SET_DEPTH_LIMIT(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_depth_limit_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_depth_limit_16(G(a,16),b); \ - else \ - pcre2_set_depth_limit_32(G(a,32),b) - -#define PCRE2_SET_GLOB_SEPARATOR(r,a,b) \ - if (test_mode == PCRE8_MODE) \ - r = pcre2_set_glob_separator_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - r = pcre2_set_glob_separator_16(G(a,16),b); \ - else \ - r = pcre2_set_glob_separator_32(G(a,32),b) - -#define PCRE2_SET_GLOB_ESCAPE(r,a,b) \ - if (test_mode == PCRE8_MODE) \ - r = pcre2_set_glob_escape_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - r = pcre2_set_glob_escape_16(G(a,16),b); \ - else \ - r = pcre2_set_glob_escape_32(G(a,32),b) - -#define PCRE2_SET_HEAP_LIMIT(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_heap_limit_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_heap_limit_16(G(a,16),b); \ - else \ - pcre2_set_heap_limit_32(G(a,32),b) - -#define PCRE2_SET_MATCH_LIMIT(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_match_limit_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_match_limit_16(G(a,16),b); \ - else \ - pcre2_set_match_limit_32(G(a,32),b) - -#define PCRE2_SET_MAX_PATTERN_COMPILED_LENGTH(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_max_pattern_compiled_length_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_max_pattern_compiled_length_16(G(a,16),b); \ - else \ - pcre2_set_max_pattern_compiled_length_32(G(a,32),b) - -#define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_max_pattern_length_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_max_pattern_length_16(G(a,16),b); \ - else \ - pcre2_set_max_pattern_length_32(G(a,32),b) - -#define PCRE2_SET_MAX_VARLOOKBEHIND(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_max_varlookbehind_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_max_varlookbehind_16(G(a,16),b); \ - else \ - pcre2_set_max_varlookbehind_32(G(a,32),b) - -#define PCRE2_SET_OFFSET_LIMIT(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_offset_limit_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_offset_limit_16(G(a,16),b); \ - else \ - pcre2_set_offset_limit_32(G(a,32),b) - -#define PCRE2_SET_PARENS_NEST_LIMIT(a,b) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_parens_nest_limit_8(G(a,8),b); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_parens_nest_limit_16(G(a,16),b); \ - else \ - pcre2_set_parens_nest_limit_32(G(a,32),b) - -#define PCRE2_SET_SUBSTITUTE_CALLOUT(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_substitute_callout_8(G(a,8), \ - (int (*)(pcre2_substitute_callout_block_8 *, void *))b,c); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_substitute_callout_16(G(a,16), \ - (int (*)(pcre2_substitute_callout_block_16 *, void *))b,c); \ - else \ - pcre2_set_substitute_callout_32(G(a,32), \ - (int (*)(pcre2_substitute_callout_block_32 *, void *))b,c) - -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_substitute_case_callout_8(G(a,8),G(b,8),c); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_substitute_case_callout_16(G(a,16),G(b,16),c); \ - else \ - pcre2_set_substitute_case_callout_32(G(a,32),G(b,32),c) - -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT_NULL(a) \ - if (test_mode == PCRE8_MODE) \ - pcre2_set_substitute_case_callout_8(G(a,8),NULL,NULL); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_set_substitute_case_callout_16(G(a,16),NULL,NULL); \ - else \ - pcre2_set_substitute_case_callout_32(G(a,32),NULL,NULL) - -#define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substitute_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h, \ - (PCRE2_SPTR8)i,j,(PCRE2_UCHAR8 *)k,l); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substitute_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h, \ - (PCRE2_SPTR16)i,j,(PCRE2_UCHAR16 *)k,l); \ - else \ - a = pcre2_substitute_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h, \ - (PCRE2_SPTR32)i,j,(PCRE2_UCHAR32 *)k,l) - -#define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_copy_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 *)d,e); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_copy_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 *)d,e); \ - else \ - a = pcre2_substring_copy_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 *)d,e) - -#define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_copy_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 *)d,e); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_copy_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 *)d,e); \ - else \ - a = pcre2_substring_copy_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 *)d,e) - -#define PCRE2_SUBSTRING_FREE(a) \ - if (test_mode == PCRE8_MODE) pcre2_substring_free_8((PCRE2_UCHAR8 *)a); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_substring_free_16((PCRE2_UCHAR16 *)a); \ - else pcre2_substring_free_32((PCRE2_UCHAR32 *)a) - -#define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_get_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 **)d,e); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_get_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 **)d,e); \ - else \ - a = pcre2_substring_get_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 **)d,e) - -#define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_get_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 **)d,e); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_get_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 **)d,e); \ - else \ - a = pcre2_substring_get_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 **)d,e) - -#define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_length_byname_8(G(b,8),G(c,8),d); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_length_byname_16(G(b,16),G(c,16),d); \ - else \ - a = pcre2_substring_length_byname_32(G(b,32),G(c,32),d) - -#define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_length_bynumber_8(G(b,8),c,d); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_length_bynumber_16(G(b,16),c,d); \ - else \ - a = pcre2_substring_length_bynumber_32(G(b,32),c,d) - -#define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_list_get_8(G(b,8),(PCRE2_UCHAR8 ***)c,d); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_list_get_16(G(b,16),(PCRE2_UCHAR16 ***)c,d); \ - else \ - a = pcre2_substring_list_get_32(G(b,32),(PCRE2_UCHAR32 ***)c,d) - -#define PCRE2_SUBSTRING_LIST_FREE(a) \ - if (test_mode == PCRE8_MODE) \ - pcre2_substring_list_free_8((PCRE2_UCHAR8 **)a); \ - else if (test_mode == PCRE16_MODE) \ - pcre2_substring_list_free_16((PCRE2_UCHAR16 **)a); \ - else \ - pcre2_substring_list_free_32((PCRE2_UCHAR32 **)a) - -#define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \ - if (test_mode == PCRE8_MODE) \ - a = pcre2_substring_number_from_name_8(G(b,8),G(c,8)); \ - else if (test_mode == PCRE16_MODE) \ - a = pcre2_substring_number_from_name_16(G(b,16),G(c,16)); \ - else \ - a = pcre2_substring_number_from_name_32(G(b,32),G(c,32)) - -#define PTR(x) ( \ - (test_mode == PCRE8_MODE)? (void *)G(x,8) : \ - (test_mode == PCRE16_MODE)? (void *)G(x,16) : \ - (void *)G(x,32)) - -#define SETFLD(x,y,z) \ - if (test_mode == PCRE8_MODE) G(x,8)->y = z; \ - else if (test_mode == PCRE16_MODE) G(x,16)->y = z; \ - else G(x,32)->y = z - -#define SETFLDVEC(x,y,v,z) \ - if (test_mode == PCRE8_MODE) G(x,8)->y[v] = z; \ - else if (test_mode == PCRE16_MODE) G(x,16)->y[v] = z; \ - else G(x,32)->y[v] = z - -#define SETOP(x,y,z) \ - if (test_mode == PCRE8_MODE) G(x,8) z y; \ - else if (test_mode == PCRE16_MODE) G(x,16) z y; \ - else G(x,32) z y - -#define SETCASTPTR(x,y) \ - if (test_mode == PCRE8_MODE) \ - G(x,8) = (uint8_t *)(y); \ - else if (test_mode == PCRE16_MODE) \ - G(x,16) = (uint16_t *)(y); \ - else \ - G(x,32) = (uint32_t *)(y) - -#define STRLEN(p) ((test_mode == PCRE8_MODE)? ((int)strlen((char *)p)) : \ - (test_mode == PCRE16_MODE)? ((int)strlen16((PCRE2_SPTR16)p)) : \ - ((int)strlen32((PCRE2_SPTR32)p))) - -#define SUB1(a,b) \ - if (test_mode == PCRE8_MODE) G(a,8)(G(b,8)); \ - else if (test_mode == PCRE16_MODE) G(a,16)(G(b,16)); \ - else G(a,32)(G(b,32)) - -#define SUB2(a,b,c) \ - if (test_mode == PCRE8_MODE) G(a,8)(G(b,8),G(c,8)); \ - else if (test_mode == PCRE16_MODE) G(a,16)(G(b,16),G(c,16)); \ - else G(a,32)(G(b,32),G(c,32)) - -#define TEST(x,r,y) ( \ - (test_mode == PCRE8_MODE && G(x,8) r (y)) || \ - (test_mode == PCRE16_MODE && G(x,16) r (y)) || \ - (test_mode == PCRE32_MODE && G(x,32) r (y))) - -#define TESTFLD(x,f,r,y) ( \ - (test_mode == PCRE8_MODE && G(x,8)->f r (y)) || \ - (test_mode == PCRE16_MODE && G(x,16)->f r (y)) || \ - (test_mode == PCRE32_MODE && G(x,32)->f r (y))) - - -/* ----- Two out of three modes are supported ----- */ - -#else - -/* We can use some macro trickery to make a single set of definitions work in -the three different cases. */ - -/* ----- 32-bit and 16-bit but not 8-bit supported ----- */ - -#if defined(SUPPORT_PCRE2_32) && defined(SUPPORT_PCRE2_16) -#define BITONE 32 -#define BITTWO 16 - -/* ----- 32-bit and 8-bit but not 16-bit supported ----- */ - -#elif defined(SUPPORT_PCRE2_32) && defined(SUPPORT_PCRE2_8) -#define BITONE 32 -#define BITTWO 8 - -/* ----- 16-bit and 8-bit but not 32-bit supported ----- */ - -#else -#define BITONE 16 -#define BITTWO 8 -#endif - - -/* ----- Common macros for two-mode cases ----- */ - -#define BYTEONE (BITONE/8) -#define BYTETWO (BITTWO/8) - -#define CASTFLD(t,a,b) \ - ((test_mode == G(G(PCRE,BITONE),_MODE))? (t)(G(a,BITONE)->b) : \ - (t)(G(a,BITTWO)->b)) - -#define CASTVAR(t,x) ( \ - (test_mode == G(G(PCRE,BITONE),_MODE))? \ - (t)G(x,BITONE) : (t)G(x,BITTWO)) - -#define CODE_UNIT(a,b) ( \ - (test_mode == G(G(PCRE,BITONE),_MODE))? \ - (uint32_t)(((G(PCRE2_SPTR,BITONE))(a))[b]) : \ - (uint32_t)(((G(PCRE2_SPTR,BITTWO))(a))[b])) - -#define CONCTXCPY(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - memcpy(G(a,BITONE),G(b,BITONE),sizeof(G(pcre2_convert_context_,BITONE))); \ - else \ - memcpy(G(a,BITTWO),G(b,BITTWO),sizeof(G(pcre2_convert_context_,BITTWO))) - -#define CONVERT_COPY(a,b,c) \ - (test_mode == G(G(PCRE,BITONE),_MODE))? \ - memcpy(G(a,BITONE),(char *)b,(c)*BYTEONE) : \ - memcpy(G(a,BITTWO),(char *)b,(c)*BYTETWO) - -#define DATCTXCPY(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - memcpy(G(a,BITONE),G(b,BITONE),sizeof(G(pcre2_match_context_,BITONE))); \ - else \ - memcpy(G(a,BITTWO),G(b,BITTWO),sizeof(G(pcre2_match_context_,BITTWO))) - -#define FLD(a,b) \ - ((test_mode == G(G(PCRE,BITONE),_MODE))? G(a,BITONE)->b : G(a,BITTWO)->b) - -#define PATCTXCPY(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - memcpy(G(a,BITONE),G(b,BITONE),sizeof(G(pcre2_compile_context_,BITONE))); \ - else \ - memcpy(G(a,BITTWO),G(b,BITTWO),sizeof(G(pcre2_compile_context_,BITTWO))) - -#define PCHARS(lv, p, offset, len, utf, f) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - lv = G(pchars,BITONE)((G(PCRE2_SPTR,BITONE))(p)+offset, len, utf, f); \ - else \ - lv = G(pchars,BITTWO)((G(PCRE2_SPTR,BITTWO))(p)+offset, len, utf, f) - -#define PCHARSV(p, offset, len, utf, f) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - (void)G(pchars,BITONE)((G(PCRE2_SPTR,BITONE))(p)+offset, len, utf, f); \ - else \ - (void)G(pchars,BITTWO)((G(PCRE2_SPTR,BITTWO))(p)+offset, len, utf, f) - -#define PCRE2_CALLOUT_ENUMERATE(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_callout_enumerate,BITONE)(G(compiled_code,BITONE), \ - (int (*)(struct G(pcre2_callout_enumerate_block_,BITONE) *, void *))b,c); \ - else \ - a = G(pcre2_callout_enumerate,BITTWO)(G(compiled_code,BITTWO), \ - (int (*)(struct G(pcre2_callout_enumerate_block_,BITTWO) *, void *))b,c) - -#define PCRE2_CODE_COPY_FROM_VOID(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(a,BITONE) = G(pcre2_code_copy_,BITONE)(b); \ - else \ - G(a,BITTWO) = G(pcre2_code_copy_,BITTWO)(b) - -#define PCRE2_CODE_COPY_TO_VOID(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = (void *)G(pcre2_code_copy_,BITONE)(G(b,BITONE)); \ - else \ - a = (void *)G(pcre2_code_copy_,BITTWO)(G(b,BITTWO)) - -#define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = (void *)G(pcre2_code_copy_with_tables_,BITONE)(G(b,BITONE)); \ - else \ - a = (void *)G(pcre2_code_copy_with_tables_,BITTWO)(G(b,BITTWO)) - -#define PCRE2_COMPILE(a,b,c,d,e,f,g) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(a,BITONE) = G(pcre2_compile_,BITONE)(b,c,d,e,f,g); \ - else \ - G(a,BITTWO) = G(pcre2_compile_,BITTWO)(b,c,d,e,f,g) - -#define PCRE2_CONVERTED_PATTERN_FREE(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_converted_pattern_free_,BITONE)((G(PCRE2_UCHAR,BITONE) *)a); \ - else \ - G(pcre2_converted_pattern_free_,BITTWO)((G(PCRE2_UCHAR,BITTWO) *)a) - -#define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_dfa_match_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \ - G(g,BITONE),h,i,j); \ - else \ - a = G(pcre2_dfa_match_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \ - G(g,BITTWO),h,i,j) - -#define PCRE2_GET_ERROR_MESSAGE(r,a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_get_error_message_,BITONE)(a,G(b,BITONE),G(G(b,BITONE),_size/BYTEONE)); \ - else \ - r = G(pcre2_get_error_message_,BITTWO)(a,G(b,BITTWO),G(G(b,BITTWO),_size/BYTETWO)) - -#define PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE(r,a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_get_match_data_heapframes_size_,BITONE)(G(a,BITONE)); \ - else \ - r = G(pcre2_get_match_data_heapframes_size_,BITTWO)(G(a,BITTWO)) - -#define PCRE2_GET_OVECTOR_COUNT(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_get_ovector_count_,BITONE)(G(b,BITONE)); \ - else \ - a = G(pcre2_get_ovector_count_,BITTWO)(G(b,BITTWO)) - -#define PCRE2_GET_STARTCHAR(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_get_startchar_,BITONE)(G(b,BITONE)); \ - else \ - a = G(pcre2_get_startchar_,BITTWO)(G(b,BITTWO)) - -#define PCRE2_JIT_COMPILE(r,a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_jit_compile_,BITONE)(G(a,BITONE),b); \ - else \ - r = G(pcre2_jit_compile_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_jit_free_unused_memory_,BITONE)(G(a,BITONE)); \ - else \ - G(pcre2_jit_free_unused_memory_,BITTWO)(G(a,BITTWO)) - -#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_jit_match_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \ - G(g,BITONE),h); \ - else \ - a = G(pcre2_jit_match_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \ - G(g,BITTWO),h) - -#define PCRE2_JIT_STACK_CREATE(a,b,c,d) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = (PCRE2_JIT_STACK *)G(pcre2_jit_stack_create_,BITONE)(b,c,d); \ - else \ - a = (PCRE2_JIT_STACK *)G(pcre2_jit_stack_create_,BITTWO)(b,c,d); \ - -#define PCRE2_JIT_STACK_ASSIGN(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_jit_stack_assign_,BITONE)(G(a,BITONE),(G(pcre2_jit_callback_,BITONE))b,c); \ - else \ - G(pcre2_jit_stack_assign_,BITTWO)(G(a,BITTWO),(G(pcre2_jit_callback_,BITTWO))b,c); - -#define PCRE2_JIT_STACK_FREE(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_jit_stack_free_,BITONE)((G(pcre2_jit_stack_,BITONE) *)a); \ - else \ - G(pcre2_jit_stack_free_,BITTWO)((G(pcre2_jit_stack_,BITTWO) *)a); - -#define PCRE2_MAKETABLES(a,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_maketables_,BITONE)(G(c,BITONE)); \ - else \ - a = G(pcre2_maketables_,BITTWO)(G(c,BITTWO)) - -#define PCRE2_MAKETABLES_FREE(c,a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_maketables_free_,BITONE)(G(c,BITONE),a); \ - else \ - G(pcre2_maketables_free_,BITTWO)(G(c,BITTWO),a) - -#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_match_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \ - G(g,BITONE),h); \ - else \ - a = G(pcre2_match_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \ - G(g,BITTWO),h) - -#define PCRE2_MATCH_DATA_CREATE(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(a,BITONE) = G(pcre2_match_data_create_,BITONE)(b,G(c,BITONE)); \ - else \ - G(a,BITTWO) = G(pcre2_match_data_create_,BITTWO)(b,G(c,BITTWO)) - -#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(a,BITONE) = G(pcre2_match_data_create_from_pattern_,BITONE)(G(b,BITONE),G(c,BITONE)); \ - else \ - G(a,BITTWO) = G(pcre2_match_data_create_from_pattern_,BITTWO)(G(b,BITTWO),G(c,BITTWO)) - -#define PCRE2_MATCH_DATA_FREE(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_match_data_free_,BITONE)(G(a,BITONE)); \ - else \ - G(pcre2_match_data_free_,BITTWO)(G(a,BITTWO)) - -#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_pattern_convert_,BITONE)(G(b,BITONE),c,d,(G(PCRE2_UCHAR,BITONE) **)e,f,G(g,BITONE)); \ - else \ - a = G(pcre2_pattern_convert_,BITTWO)(G(b,BITTWO),c,d,(G(PCRE2_UCHAR,BITTWO) **)e,f,G(g,BITTWO)) - -#define PCRE2_PATTERN_INFO(a,b,c,d) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_pattern_info_,BITONE)(G(b,BITONE),c,d); \ - else \ - a = G(pcre2_pattern_info_,BITTWO)(G(b,BITTWO),c,d) - -#define PCRE2_PRINTINT(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_printint_,BITONE)(G(compiled_code,BITONE),outfile,a); \ - else \ - G(pcre2_printint_,BITTWO)(G(compiled_code,BITTWO),outfile,a) - -#define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_serialize_decode_,BITONE)((G(pcre2_code_,BITONE) **)a,b,c,G(d,BITONE)); \ - else \ - r = G(pcre2_serialize_decode_,BITTWO)((G(pcre2_code_,BITTWO) **)a,b,c,G(d,BITTWO)) - -#define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_serialize_encode_,BITONE)((G(const pcre2_code_,BITONE) **)a,b,c,d,G(e,BITONE)); \ - else \ - r = G(pcre2_serialize_encode_,BITTWO)((G(const pcre2_code_,BITTWO) **)a,b,c,d,G(e,BITTWO)) - -#define PCRE2_SERIALIZE_FREE(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_serialize_free_,BITONE)(a); \ - else \ - G(pcre2_serialize_free_,BITTWO)(a) - -#define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_serialize_get_number_of_codes_,BITONE)(a); \ - else \ - r = G(pcre2_serialize_get_number_of_codes_,BITTWO)(a) - -#define PCRE2_SET_CALLOUT(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_callout_,BITONE)(G(a,BITONE), \ - (int (*)(G(pcre2_callout_block_,BITONE) *, void *))b,c); \ - else \ - G(pcre2_set_callout_,BITTWO)(G(a,BITTWO), \ - (int (*)(G(pcre2_callout_block_,BITTWO) *, void *))b,c); - -#define PCRE2_SET_CHARACTER_TABLES(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_character_tables_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_character_tables_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_compile_recursion_guard_,BITONE)(G(a,BITONE),b,c); \ - else \ - G(pcre2_set_compile_recursion_guard_,BITTWO)(G(a,BITTWO),b,c) - -#define PCRE2_SET_DEPTH_LIMIT(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_depth_limit_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_depth_limit_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_GLOB_ESCAPE(r,a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_set_glob_escape_,BITONE)(G(a,BITONE),b); \ - else \ - r = G(pcre2_set_glob_escape_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_GLOB_SEPARATOR(r,a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - r = G(pcre2_set_glob_separator_,BITONE)(G(a,BITONE),b); \ - else \ - r = G(pcre2_set_glob_separator_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_HEAP_LIMIT(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_heap_limit_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_heap_limit_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_MATCH_LIMIT(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_match_limit_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_match_limit_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_MAX_PATTERN_COMPILED_LENGTH(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_max_pattern_compiled_length_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_max_pattern_compiled_length_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_max_pattern_length_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_max_pattern_length_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_MAX_VARLOOKBEHIND(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_max_varlookbehind_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_max_varlookbehind_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_OFFSET_LIMIT(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_offset_limit_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_offset_limit_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_PARENS_NEST_LIMIT(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_parens_nest_limit_,BITONE)(G(a,BITONE),b); \ - else \ - G(pcre2_set_parens_nest_limit_,BITTWO)(G(a,BITTWO),b) - -#define PCRE2_SET_SUBSTITUTE_CALLOUT(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_substitute_callout_,BITONE)(G(a,BITONE), \ - (int (*)(G(pcre2_substitute_callout_block_,BITONE) *, void *))b,c); \ - else \ - G(pcre2_set_substitute_callout_,BITTWO)(G(a,BITTWO), \ - (int (*)(G(pcre2_substitute_callout_block_,BITTWO) *, void *))b,c) - -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_substitute_case_callout_,BITONE)(G(a,BITONE),G(b,BITONE),c); \ - else \ - G(pcre2_set_substitute_case_callout_,BITTWO)(G(a,BITTWO),G(b,BITTWO),c) - -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT_NULL(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_set_substitute_case_callout_,BITONE)(G(a,BITONE),NULL,NULL); \ - else \ - G(pcre2_set_substitute_case_callout_,BITTWO)(G(a,BITTWO),NULL,NULL) - -#define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substitute_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \ - G(g,BITONE),h,(G(PCRE2_SPTR,BITONE))i,j, \ - (G(PCRE2_UCHAR,BITONE) *)k,l); \ - else \ - a = G(pcre2_substitute_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \ - G(g,BITTWO),h,(G(PCRE2_SPTR,BITTWO))i,j, \ - (G(PCRE2_UCHAR,BITTWO) *)k,l) - -#define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_copy_byname_,BITONE)(G(b,BITONE),G(c,BITONE),\ - (G(PCRE2_UCHAR,BITONE) *)d,e); \ - else \ - a = G(pcre2_substring_copy_byname_,BITTWO)(G(b,BITTWO),G(c,BITTWO),\ - (G(PCRE2_UCHAR,BITTWO) *)d,e) - -#define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_copy_bynumber_,BITONE)(G(b,BITONE),c,\ - (G(PCRE2_UCHAR,BITONE) *)d,e); \ - else \ - a = G(pcre2_substring_copy_bynumber_,BITTWO)(G(b,BITTWO),c,\ - (G(PCRE2_UCHAR,BITTWO) *)d,e) - -#define PCRE2_SUBSTRING_FREE(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_substring_free_,BITONE)((G(PCRE2_UCHAR,BITONE) *)a); \ - else G(pcre2_substring_free_,BITTWO)((G(PCRE2_UCHAR,BITTWO) *)a) - -#define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_get_byname_,BITONE)(G(b,BITONE),G(c,BITONE),\ - (G(PCRE2_UCHAR,BITONE) **)d,e); \ - else \ - a = G(pcre2_substring_get_byname_,BITTWO)(G(b,BITTWO),G(c,BITTWO),\ - (G(PCRE2_UCHAR,BITTWO) **)d,e) - -#define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_get_bynumber_,BITONE)(G(b,BITONE),c,\ - (G(PCRE2_UCHAR,BITONE) **)d,e); \ - else \ - a = G(pcre2_substring_get_bynumber_,BITTWO)(G(b,BITTWO),c,\ - (G(PCRE2_UCHAR,BITTWO) **)d,e) - -#define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_length_byname_,BITONE)(G(b,BITONE),G(c,BITONE),d); \ - else \ - a = G(pcre2_substring_length_byname_,BITTWO)(G(b,BITTWO),G(c,BITTWO),d) - -#define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_length_bynumber_,BITONE)(G(b,BITONE),c,d); \ - else \ - a = G(pcre2_substring_length_bynumber_,BITTWO)(G(b,BITTWO),c,d) - -#define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_list_get_,BITONE)(G(b,BITONE), \ - (G(PCRE2_UCHAR,BITONE) ***)c,d); \ - else \ - a = G(pcre2_substring_list_get_,BITTWO)(G(b,BITTWO), \ - (G(PCRE2_UCHAR,BITTWO) ***)c,d) - -#define PCRE2_SUBSTRING_LIST_FREE(a) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(pcre2_substring_list_free_,BITONE)((G(PCRE2_UCHAR,BITONE) **)a); \ - else \ - G(pcre2_substring_list_free_,BITTWO)((G(PCRE2_UCHAR,BITTWO) **)a) - -#define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - a = G(pcre2_substring_number_from_name_,BITONE)(G(b,BITONE),G(c,BITONE)); \ - else \ - a = G(pcre2_substring_number_from_name_,BITTWO)(G(b,BITTWO),G(c,BITTWO)) - -#define PTR(x) ( \ - (test_mode == G(G(PCRE,BITONE),_MODE))? (void *)G(x,BITONE) : \ - (void *)G(x,BITTWO)) - -#define SETFLD(x,y,z) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) G(x,BITONE)->y = z; \ - else G(x,BITTWO)->y = z - -#define SETFLDVEC(x,y,v,z) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) G(x,BITONE)->y[v] = z; \ - else G(x,BITTWO)->y[v] = z - -#define SETOP(x,y,z) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) G(x,BITONE) z y; \ - else G(x,BITTWO) z y - -#define SETCASTPTR(x,y) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(x,BITONE) = (G(G(uint,BITONE),_t) *)(y); \ - else \ - G(x,BITTWO) = (G(G(uint,BITTWO),_t) *)(y) - -#define STRLEN(p) ((test_mode == G(G(PCRE,BITONE),_MODE))? \ - G(strlen,BITONE)((G(PCRE2_SPTR,BITONE))p) : \ - G(strlen,BITTWO)((G(PCRE2_SPTR,BITTWO))p)) - -#define SUB1(a,b) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(a,BITONE)(G(b,BITONE)); \ - else \ - G(a,BITTWO)(G(b,BITTWO)) - -#define SUB2(a,b,c) \ - if (test_mode == G(G(PCRE,BITONE),_MODE)) \ - G(a,BITONE))(G(b,BITONE),G(c,BITONE)); \ - else \ - G(a,BITTWO))(G(b,BITTWO),G(c,BITTWO)) - -#define TEST(x,r,y) ( \ - (test_mode == G(G(PCRE,BITONE),_MODE) && G(x,BITONE) r (y)) || \ - (test_mode == G(G(PCRE,BITTWO),_MODE) && G(x,BITTWO) r (y))) - -#define TESTFLD(x,f,r,y) ( \ - (test_mode == G(G(PCRE,BITONE),_MODE) && G(x,BITONE)->f r (y)) || \ - (test_mode == G(G(PCRE,BITTWO),_MODE) && G(x,BITTWO)->f r (y))) - - -#endif /* Two out of three modes */ - -/* ----- End of cases where more than one mode is supported ----- */ - - -/* ----- Only 8-bit mode is supported ----- */ - -#elif defined SUPPORT_PCRE2_8 -#define CASTFLD(t,a,b) (t)(G(a,8)->b) -#define CASTVAR(t,x) (t)G(x,8) -#define CODE_UNIT(a,b) (uint32_t)(((PCRE2_SPTR8)(a))[b]) -#define CONCTXCPY(a,b) memcpy(G(a,8),G(b,8),sizeof(pcre2_convert_context_8)) -#define CONVERT_COPY(a,b,c) memcpy(G(a,8),(char *)b, c) -#define DATCTXCPY(a,b) memcpy(G(a,8),G(b,8),sizeof(pcre2_match_context_8)) -#define FLD(a,b) G(a,8)->b -#define PATCTXCPY(a,b) memcpy(G(a,8),G(b,8),sizeof(pcre2_compile_context_8)) -#define PCHARS(lv, p, offset, len, utf, f) \ - lv = pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f) -#define PCHARSV(p, offset, len, utf, f) \ - (void)pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f) -#define PCRE2_CALLOUT_ENUMERATE(a,b,c) \ - a = pcre2_callout_enumerate_8(compiled_code8, \ - (int (*)(struct pcre2_callout_enumerate_block_8 *, void *))b,c) -#define PCRE2_CODE_COPY_FROM_VOID(a,b) G(a,8) = pcre2_code_copy_8(b) -#define PCRE2_CODE_COPY_TO_VOID(a,b) a = (void *)pcre2_code_copy_8(G(b,8)) -#define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) a = (void *)pcre2_code_copy_with_tables_8(G(b,8)) -#define PCRE2_COMPILE(a,b,c,d,e,f,g) G(a,8) = pcre2_compile_8(b,c,d,e,f,g) -#define PCRE2_CONVERTED_PATTERN_FREE(a) \ - pcre2_converted_pattern_free_8((PCRE2_UCHAR8 *)a) -#define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \ - a = pcre2_dfa_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h,i,j) -#define PCRE2_GET_ERROR_MESSAGE(r,a,b) \ - r = pcre2_get_error_message_8(a,G(b,8),G(G(b,8),_size)) -#define PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE(r,a) \ - r = pcre2_get_match_data_heapframes_size_8(G(a,8)) -#define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_8(G(b,8)) -#define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_8(G(b,8)) -#define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_8(G(a,8),b) -#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_8(G(a,8)) -#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \ - a = pcre2_jit_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h) -#define PCRE2_JIT_STACK_CREATE(a,b,c,d) \ - a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_8(b,c,d); -#define PCRE2_JIT_STACK_ASSIGN(a,b,c) \ - pcre2_jit_stack_assign_8(G(a,8),(pcre2_jit_callback_8)b,c); -#define PCRE2_JIT_STACK_FREE(a) pcre2_jit_stack_free_8((pcre2_jit_stack_8 *)a); -#define PCRE2_MAKETABLES(a,c) a = pcre2_maketables_8(G(c,8)) -#define PCRE2_MAKETABLES_FREE(c,a) pcre2_maketables_free_8(G(c,8),a) -#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \ - a = pcre2_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h) -#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,8) = pcre2_match_data_create_8(b,G(c,8)) -#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \ - G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),G(c,8)) -#define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_8(G(a,8)) -#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_8(G(b,8),c,d,(PCRE2_UCHAR8 **)e,f,G(g,8)) -#define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_8(G(b,8),c,d) -#define PCRE2_PRINTINT(a) pcre2_printint_8(compiled_code8,outfile,a) -#define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \ - r = pcre2_serialize_decode_8((pcre2_code_8 **)a,b,c,G(d,8)) -#define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \ - r = pcre2_serialize_encode_8((const pcre2_code_8 **)a,b,c,d,G(e,8)) -#define PCRE2_SERIALIZE_FREE(a) pcre2_serialize_free_8(a) -#define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \ - r = pcre2_serialize_get_number_of_codes_8(a) -#define PCRE2_SET_CALLOUT(a,b,c) \ - pcre2_set_callout_8(G(a,8),(int (*)(pcre2_callout_block_8 *, void *))b,c) -#define PCRE2_SET_CHARACTER_TABLES(a,b) pcre2_set_character_tables_8(G(a,8),b) -#define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \ - pcre2_set_compile_recursion_guard_8(G(a,8),b,c) -#define PCRE2_SET_DEPTH_LIMIT(a,b) pcre2_set_depth_limit_8(G(a,8),b) -#define PCRE2_SET_GLOB_ESCAPE(r,a,b) r = pcre2_set_glob_escape_8(G(a,8),b) -#define PCRE2_SET_GLOB_SEPARATOR(r,a,b) r = pcre2_set_glob_separator_8(G(a,8),b) -#define PCRE2_SET_HEAP_LIMIT(a,b) pcre2_set_heap_limit_8(G(a,8),b) -#define PCRE2_SET_MATCH_LIMIT(a,b) pcre2_set_match_limit_8(G(a,8),b) -#define PCRE2_SET_MAX_PATTERN_COMPILED_LENGTH(a,b) pcre2_set_max_pattern_compiled_length_8(G(a,8),b) -#define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) pcre2_set_max_pattern_length_8(G(a,8),b) -#define PCRE2_SET_MAX_VARLOOKBEHIND(a,b) pcre2_set_max_varlookbehind_8(G(a,8),b) -#define PCRE2_SET_OFFSET_LIMIT(a,b) pcre2_set_offset_limit_8(G(a,8),b) -#define PCRE2_SET_PARENS_NEST_LIMIT(a,b) pcre2_set_parens_nest_limit_8(G(a,8),b) -#define PCRE2_SET_SUBSTITUTE_CALLOUT(a,b,c) \ - pcre2_set_substitute_callout_8(G(a,8), \ - (int (*)(pcre2_substitute_callout_block_8 *, void *))b,c) -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT(a,b,c) \ - pcre2_set_substitute_case_callout_8(G(a,8),G(b,8),c) -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT_NULL(a) \ - pcre2_set_substitute_case_callout_8(G(a,8),NULL,NULL) -#define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \ - a = pcre2_substitute_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h, \ - (PCRE2_SPTR8)i,j,(PCRE2_UCHAR8 *)k,l) -#define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \ - a = pcre2_substring_copy_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 *)d,e) -#define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \ - a = pcre2_substring_copy_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 *)d,e) -#define PCRE2_SUBSTRING_FREE(a) pcre2_substring_free_8((PCRE2_UCHAR8 *)a) -#define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \ - a = pcre2_substring_get_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 **)d,e) -#define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \ - a = pcre2_substring_get_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 **)d,e) -#define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \ - a = pcre2_substring_length_byname_8(G(b,8),G(c,8),d) -#define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \ - a = pcre2_substring_length_bynumber_8(G(b,8),c,d) -#define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \ - a = pcre2_substring_list_get_8(G(b,8),(PCRE2_UCHAR8 ***)c,d) -#define PCRE2_SUBSTRING_LIST_FREE(a) \ - pcre2_substring_list_free_8((PCRE2_UCHAR8 **)a) -#define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \ - a = pcre2_substring_number_from_name_8(G(b,8),G(c,8)); -#define PTR(x) (void *)G(x,8) -#define SETFLD(x,y,z) G(x,8)->y = z -#define SETFLDVEC(x,y,v,z) G(x,8)->y[v] = z -#define SETOP(x,y,z) G(x,8) z y -#define SETCASTPTR(x,y) G(x,8) = (uint8_t *)(y) -#define STRLEN(p) (int)strlen((char *)p) -#define SUB1(a,b) G(a,8)(G(b,8)) -#define SUB2(a,b,c) G(a,8)(G(b,8),G(c,8)) -#define TEST(x,r,y) (G(x,8) r (y)) -#define TESTFLD(x,f,r,y) (G(x,8)->f r (y)) - - -/* ----- Only 16-bit mode is supported ----- */ +static size_t dbuffer_size = 1u << 14; /* Initial size, bytes */ +static uint8_t *dbuffer = NULL; -#elif defined SUPPORT_PCRE2_16 -#define CASTFLD(t,a,b) (t)(G(a,16)->b) -#define CASTVAR(t,x) (t)G(x,16) -#define CODE_UNIT(a,b) (uint32_t)(((PCRE2_SPTR16)(a))[b]) -#define CONCTXCPY(a,b) memcpy(G(a,16),G(b,16),sizeof(pcre2_convert_context_16)) -#define CONVERT_COPY(a,b,c) memcpy(G(a,16),(char *)b, (c)*2) -#define DATCTXCPY(a,b) memcpy(G(a,16),G(b,16),sizeof(pcre2_match_context_16)) -#define FLD(a,b) G(a,16)->b -#define PATCTXCPY(a,b) memcpy(G(a,16),G(b,16),sizeof(pcre2_compile_context_16)) -#define PCHARS(lv, p, offset, len, utf, f) \ - lv = pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f) -#define PCHARSV(p, offset, len, utf, f) \ - (void)pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f) -#define PCRE2_CALLOUT_ENUMERATE(a,b,c) \ - a = pcre2_callout_enumerate_16(compiled_code16, \ - (int (*)(struct pcre2_callout_enumerate_block_16 *, void *))b,c) -#define PCRE2_CODE_COPY_FROM_VOID(a,b) G(a,16) = pcre2_code_copy_16(b) -#define PCRE2_CODE_COPY_TO_VOID(a,b) a = (void *)pcre2_code_copy_16(G(b,16)) -#define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) a = (void *)pcre2_code_copy_with_tables_16(G(b,16)) -#define PCRE2_COMPILE(a,b,c,d,e,f,g) G(a,16) = pcre2_compile_16(b,c,d,e,f,g) -#define PCRE2_CONVERTED_PATTERN_FREE(a) \ - pcre2_converted_pattern_free_16((PCRE2_UCHAR16 *)a) -#define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \ - a = pcre2_dfa_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h,i,j) -#define PCRE2_GET_ERROR_MESSAGE(r,a,b) \ - r = pcre2_get_error_message_16(a,G(b,16),G(G(b,16),_size/2)) -#define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_16(G(b,16)) -#define PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE(r,a) \ - r = pcre2_get_match_data_heapframes_size_16(G(a,16)) -#define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_16(G(b,16)) -#define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_16(G(a,16),b) -#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_16(G(a,16)) -#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \ - a = pcre2_jit_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h) -#define PCRE2_JIT_STACK_CREATE(a,b,c,d) \ - a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_16(b,c,d); -#define PCRE2_JIT_STACK_ASSIGN(a,b,c) \ - pcre2_jit_stack_assign_16(G(a,16),(pcre2_jit_callback_16)b,c); -#define PCRE2_JIT_STACK_FREE(a) pcre2_jit_stack_free_16((pcre2_jit_stack_16 *)a); -#define PCRE2_MAKETABLES(a,c) a = pcre2_maketables_16(G(c,16)) -#define PCRE2_MAKETABLES_FREE(c,a) pcre2_maketables_free_16(G(c,16),a) -#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \ - a = pcre2_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h) -#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,16) = pcre2_match_data_create_16(b,G(c,16)) -#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \ - G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),G(c,16)) -#define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_16(G(a,16)) -#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_16(G(b,16),c,d,(PCRE2_UCHAR16 **)e,f,G(g,16)) -#define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_16(G(b,16),c,d) -#define PCRE2_PRINTINT(a) pcre2_printint_16(compiled_code16,outfile,a) -#define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \ - r = pcre2_serialize_decode_16((pcre2_code_16 **)a,b,c,G(d,16)) -#define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \ - r = pcre2_serialize_encode_16((const pcre2_code_16 **)a,b,c,d,G(e,16)) -#define PCRE2_SERIALIZE_FREE(a) pcre2_serialize_free_16(a) -#define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \ - r = pcre2_serialize_get_number_of_codes_16(a) -#define PCRE2_SET_CALLOUT(a,b,c) \ - pcre2_set_callout_16(G(a,16),(int (*)(pcre2_callout_block_16 *, void *))b,c); -#define PCRE2_SET_CHARACTER_TABLES(a,b) pcre2_set_character_tables_16(G(a,16),b) -#define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \ - pcre2_set_compile_recursion_guard_16(G(a,16),b,c) -#define PCRE2_SET_DEPTH_LIMIT(a,b) pcre2_set_depth_limit_16(G(a,16),b) -#define PCRE2_SET_GLOB_ESCAPE(r,a,b) r = pcre2_set_glob_escape_16(G(a,16),b) -#define PCRE2_SET_GLOB_SEPARATOR(r,a,b) r = pcre2_set_glob_separator_16(G(a,16),b) -#define PCRE2_SET_HEAP_LIMIT(a,b) pcre2_set_heap_limit_16(G(a,16),b) -#define PCRE2_SET_MATCH_LIMIT(a,b) pcre2_set_match_limit_16(G(a,16),b) -#define PCRE2_SET_MAX_VARLOOKBEHIND(a,b) pcre2_set_max_varlookbehind_16(G(a,16),b) -#define PCRE2_SET_OFFSET_LIMIT(a,b) pcre2_set_offset_limit_16(G(a,16),b) -#define PCRE2_SET_PARENS_NEST_LIMIT(a,b) pcre2_set_parens_nest_limit_16(G(a,16),b) -#define PCRE2_SET_SUBSTITUTE_CALLOUT(a,b,c) \ - pcre2_set_substitute_callout_16(G(a,16), \ - (int (*)(pcre2_substitute_callout_block_16 *, void *))b,c) -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT(a,b,c) \ - pcre2_set_substitute_case_callout_16(G(a,16),G(b,16),c) -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT_NULL(a) \ - pcre2_set_substitute_case_callout_16(G(a,16),NULL,NULL) -#define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \ - a = pcre2_substitute_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h, \ - (PCRE2_SPTR16)i,j,(PCRE2_UCHAR16 *)k,l) -#define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \ - a = pcre2_substring_copy_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 *)d,e) -#define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \ - a = pcre2_substring_copy_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 *)d,e) -#define PCRE2_SUBSTRING_FREE(a) pcre2_substring_free_16((PCRE2_UCHAR16 *)a) -#define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \ - a = pcre2_substring_get_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 **)d,e) -#define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \ - a = pcre2_substring_get_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 **)d,e) -#define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \ - a = pcre2_substring_length_byname_16(G(b,16),G(c,16),d) -#define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \ - a = pcre2_substring_length_bynumber_16(G(b,16),c,d) -#define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \ - a = pcre2_substring_list_get_16(G(b,16),(PCRE2_UCHAR16 ***)c,d) -#define PCRE2_SUBSTRING_LIST_FREE(a) \ - pcre2_substring_list_free_16((PCRE2_UCHAR16 **)a) -#define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \ - a = pcre2_substring_number_from_name_16(G(b,16),G(c,16)); -#define PTR(x) (void *)G(x,16) -#define SETFLD(x,y,z) G(x,16)->y = z -#define SETFLDVEC(x,y,v,z) G(x,16)->y[v] = z -#define SETOP(x,y,z) G(x,16) z y -#define SETCASTPTR(x,y) G(x,16) = (uint16_t *)(y) -#define STRLEN(p) (int)strlen16((PCRE2_SPTR16)p) -#define SUB1(a,b) G(a,16)(G(b,16)) -#define SUB2(a,b,c) G(a,16)(G(b,16),G(c,16)) -#define TEST(x,r,y) (G(x,16) r (y)) -#define TESTFLD(x,f,r,y) (G(x,16)->f r (y)) - - -/* ----- Only 32-bit mode is supported ----- */ +/* ------------------ Colour highlighting definitions -------------------- */ + +/* Colour of input text that was a comment, when echoing back to the terminal */ +static const int clr_comment = 37; /* grey */ +/* Colour of other input text that is echoed back to the terminal */ +static const int clr_input = 32; /* green */ +/* Colour of prompt output */ +static const int clr_prompt = 34; /* blue */ +/* Colour of output that represents a PCRE2 API error */ +static const int clr_api_error = 35; /* magenta */ +/* Colour of error messages for the test script itself +(i.e. an error in the testing tool, not an API error) */ +static const int clr_test_error = 31; /* red */ +/* Colour of profiling information, which doesn't have a "right" answer */ +static const int clr_profiling = 36; /* cyan */ +/* No colour, for APIs that take a colour value */ +static const int clr_none = -1; + +enum { COLOUR_NEVER, COLOUR_ALWAYS, COLOUR_AUTO }; +static int colour_setting = COLOUR_AUTO; +static int colour_last_fd = -1; +static BOOL colour_fd_interactive = FALSE; -#elif defined SUPPORT_PCRE2_32 -#define CASTFLD(t,a,b) (t)(G(a,32)->b) -#define CASTVAR(t,x) (t)G(x,32) -#define CODE_UNIT(a,b) (uint32_t)(((PCRE2_SPTR32)(a))[b]) -#define CONCTXCPY(a,b) memcpy(G(a,32),G(b,32),sizeof(pcre2_convert_context_32)) -#define CONVERT_COPY(a,b,c) memcpy(G(a,32),(char *)b, (c)*4) -#define DATCTXCPY(a,b) memcpy(G(a,32),G(b,32),sizeof(pcre2_match_context_32)) -#define FLD(a,b) G(a,32)->b -#define PATCTXCPY(a,b) memcpy(G(a,32),G(b,32),sizeof(pcre2_compile_context_32)) -#define PCHARS(lv, p, offset, len, utf, f) \ - lv = pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f) -#define PCHARSV(p, offset, len, utf, f) \ - (void)pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f) -#define PCRE2_CALLOUT_ENUMERATE(a,b,c) \ - a = pcre2_callout_enumerate_32(compiled_code32, \ - (int (*)(struct pcre2_callout_enumerate_block_32 *, void *))b,c) -#define PCRE2_CODE_COPY_FROM_VOID(a,b) G(a,32) = pcre2_code_copy_32(b) -#define PCRE2_CODE_COPY_TO_VOID(a,b) a = (void *)pcre2_code_copy_32(G(b,32)) -#define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) a = (void *)pcre2_code_copy_with_tables_32(G(b,32)) -#define PCRE2_COMPILE(a,b,c,d,e,f,g) G(a,32) = pcre2_compile_32(b,c,d,e,f,g) -#define PCRE2_CONVERTED_PATTERN_FREE(a) \ - pcre2_converted_pattern_free_32((PCRE2_UCHAR32 *)a) -#define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \ - a = pcre2_dfa_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h,i,j) -#define PCRE2_GET_ERROR_MESSAGE(r,a,b) \ - r = pcre2_get_error_message_32(a,G(b,32),G(G(b,32),_size/4)) -#define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_32(G(b,32)) -#define PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE(r,a) \ - r = pcre2_get_match_data_heapframes_size_32(G(a,32)) -#define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_32(G(b,32)) -#define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_32(G(a,32),b) -#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_32(G(a,32)) -#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \ - a = pcre2_jit_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h) -#define PCRE2_JIT_STACK_CREATE(a,b,c,d) \ - a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_32(b,c,d); -#define PCRE2_JIT_STACK_ASSIGN(a,b,c) \ - pcre2_jit_stack_assign_32(G(a,32),(pcre2_jit_callback_32)b,c); -#define PCRE2_JIT_STACK_FREE(a) pcre2_jit_stack_free_32((pcre2_jit_stack_32 *)a); -#define PCRE2_MAKETABLES(a,c) a = pcre2_maketables_32(G(c,32)) -#define PCRE2_MAKETABLES_FREE(c,a) pcre2_maketables_free_32(G(c,32),a) -#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \ - a = pcre2_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h) -#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,32) = pcre2_match_data_create_32(b,G(c,32)) -#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \ - G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),G(c,32)) -#define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_32(G(a,32)) -#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_32(G(b,32),c,d,(PCRE2_UCHAR32 **)e,f,G(g,32)) -#define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_32(G(b,32),c,d) -#define PCRE2_PRINTINT(a) pcre2_printint_32(compiled_code32,outfile,a) -#define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \ - r = pcre2_serialize_decode_32((pcre2_code_32 **)a,b,c,G(d,32)) -#define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \ - r = pcre2_serialize_encode_32((const pcre2_code_32 **)a,b,c,d,G(e,32)) -#define PCRE2_SERIALIZE_FREE(a) pcre2_serialize_free_32(a) -#define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \ - r = pcre2_serialize_get_number_of_codes_32(a) -#define PCRE2_SET_CALLOUT(a,b,c) \ - pcre2_set_callout_32(G(a,32),(int (*)(pcre2_callout_block_32 *, void *))b,c) -#define PCRE2_SET_CHARACTER_TABLES(a,b) pcre2_set_character_tables_32(G(a,32),b) -#define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \ - pcre2_set_compile_recursion_guard_32(G(a,32),b,c) -#define PCRE2_SET_DEPTH_LIMIT(a,b) pcre2_set_depth_limit_32(G(a,32),b) -#define PCRE2_SET_GLOB_ESCAPE(r,a,b) r = pcre2_set_glob_escape_32(G(a,32),b) -#define PCRE2_SET_GLOB_SEPARATOR(r,a,b) r = pcre2_set_glob_separator_32(G(a,32),b) -#define PCRE2_SET_HEAP_LIMIT(a,b) pcre2_set_heap_limit_32(G(a,32),b) -#define PCRE2_SET_MATCH_LIMIT(a,b) pcre2_set_match_limit_32(G(a,32),b) -#define PCRE2_SET_MAX_VARLOOKBEHIND(a,b) pcre2_set_max_varlookbehind_32(G(a,32),b) -#define PCRE2_SET_OFFSET_LIMIT(a,b) pcre2_set_offset_limit_32(G(a,32),b) -#define PCRE2_SET_PARENS_NEST_LIMIT(a,b) pcre2_set_parens_nest_limit_32(G(a,32),b) -#define PCRE2_SET_SUBSTITUTE_CALLOUT(a,b,c) \ - pcre2_set_substitute_callout_32(G(a,32), \ - (int (*)(pcre2_substitute_callout_block_32 *, void *))b,c) -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT(a,b,c) \ - pcre2_set_substitute_case_callout_32(G(a,32),G(b,32),c) -#define PCRE2_SET_SUBSTITUTE_CASE_CALLOUT_NULL(a) \ - pcre2_set_substitute_case_callout_32(G(a,32),NULL,NULL) -#define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \ - a = pcre2_substitute_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h, \ - (PCRE2_SPTR32)i,j,(PCRE2_UCHAR32 *)k,l) -#define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \ - a = pcre2_substring_copy_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 *)d,e) -#define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \ - a = pcre2_substring_copy_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 *)d,e); -#define PCRE2_SUBSTRING_FREE(a) pcre2_substring_free_32((PCRE2_UCHAR32 *)a) -#define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \ - a = pcre2_substring_get_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 **)d,e) -#define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \ - a = pcre2_substring_get_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 **)d,e) -#define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \ - a = pcre2_substring_length_byname_32(G(b,32),G(c,32),d) -#define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \ - a = pcre2_substring_length_bynumber_32(G(b,32),c,d) -#define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \ - a = pcre2_substring_list_get_32(G(b,32),(PCRE2_UCHAR32 ***)c,d) -#define PCRE2_SUBSTRING_LIST_FREE(a) \ - pcre2_substring_list_free_32((PCRE2_UCHAR32 **)a) -#define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \ - a = pcre2_substring_number_from_name_32(G(b,32),G(c,32)); -#define PTR(x) (void *)G(x,32) -#define SETFLD(x,y,z) G(x,32)->y = z -#define SETFLDVEC(x,y,v,z) G(x,32)->y[v] = z -#define SETOP(x,y,z) G(x,32) z y -#define SETCASTPTR(x,y) G(x,32) = (uint32_t *)(y) -#define STRLEN(p) (int)strlen32((PCRE2_SPTR32)p) -#define SUB1(a,b) G(a,32)(G(b,32)) -#define SUB2(a,b,c) G(a,32)(G(b,32),G(c,32)) -#define TEST(x,r,y) (G(x,32) r (y)) -#define TESTFLD(x,f,r,y) (G(x,32)->f r (y)) +static BOOL +should_print_colour(int clr, FILE* f) +{ +if (f == NULL) return FALSE; +if (clr == clr_none) return FALSE; +if (colour_setting == COLOUR_NEVER) return FALSE; +if (colour_setting == COLOUR_AUTO) + { + if (fileno(f) != colour_last_fd) + { + colour_last_fd = fileno(f); + colour_fd_interactive = INTERACTIVE(f); + } + if (!colour_fd_interactive) return FALSE; + } +return TRUE; +} -#endif +/* Starts a block of colour (but only if colour is enabled). */ +static void +colour_begin(int clr, FILE* f) +{ +if (should_print_colour(clr, f)) + fprintf(f, "\x1b[%dm", clr); +} -/* ----- End of mode-specific function call macros ----- */ +/* Ends a block of colour (but only if colour is enabled). */ +static void +colour_end(FILE* f) +{ +colour_begin(0, f); +} +/* cfprintf is like fprintf but takes a colour to wrap its output. */ +static int +cfprintf(int clr, FILE *file, const char* fmt, ...) +{ +va_list args; +int ret; +va_start(args, fmt); +colour_begin(clr, file); +ret = vfprintf(file, fmt, args); +va_end(args); +colour_end(file); +return ret; +} @@ -2840,64 +1535,22 @@ static const uint8_t tables2[] = { -#if !defined(VPCOMPAT) && !defined(HAVE_MEMMOVE) -/************************************************* -* Emulated memmove() for systems without it * -*************************************************/ - -/* This function can make use of bcopy() if it is available. Otherwise do it by -steam, as there are some non-Unix environments that lack both memmove() and -bcopy(). */ - -static void * -emulated_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 */ -} -#undef memmove -#define memmove(d,s,n) emulated_memmove(d,s,n) -#endif /* not VPCOMPAT && not HAVE_MEMMOVE */ - - - -#ifndef HAVE_STRERROR /************************************************* -* Provide strerror() for non-ANSI libraries * +* Callout state reset * *************************************************/ -/* Some old-fashioned systems (e.g. SunOS4) didn't have strerror() in their -libraries. They may no longer be around, but just in case, we can try to -provide the same facility by this simple alternative function. */ - -extern int sys_nerr; -extern char *sys_errlist[]; +/* Several callout functions use global state to track progress. For convenience +this function resets all relevant state variables, for all the different +callouts. This ensures consistent execution when repeating a match. */ -char * -strerror(int n) +static void +reset_callout_state(void) { -if (n < 0 || n >= sys_nerr) return "unknown error number"; -return sys_errlist[n]; +mallocs_called = 0; +first_callout = TRUE; +last_callout_mark = NULL; +callout_count = 0; } -#endif /* HAVE_STRERROR */ @@ -2909,19 +1562,26 @@ return sys_errlist[n]; static void *my_malloc(size_t size, void *data) { -void *block = malloc(size); +void *block; + (void)data; -if (show_memory) + +mallocs_called++; +if (mallocs_until_failure != INT_MAX && mallocs_until_failure-- <= 0) + return NULL; + +block = malloc(size); +if (show_memory && outfile != NULL) { if (block == NULL) { - fprintf(outfile, "** malloc() failed for %" SIZ_FORM "\n", size); + cfprintf(clr_test_error, outfile, "** malloc() failed for %" SIZ_FORM "\n", size); } else { - fprintf(outfile, "malloc %5" SIZ_FORM, size); + cfprintf(clr_profiling, outfile, "malloc %5" SIZ_FORM, size); #ifdef DEBUG_SHOW_MALLOC_ADDRESSES - fprintf(outfile, " %p", block); /* Not portable */ + cfprintf(clr_profiling, outfile, " %p", block); /* Not portable */ #endif if (malloclistptr < MALLOCLISTSIZE) { @@ -2929,7 +1589,7 @@ if (show_memory) malloclistlength[malloclistptr++] = size; } else - fprintf(outfile, " (not remembered)"); + cfprintf(clr_profiling, outfile, " (not remembered)"); fprintf(outfile, "\n"); } } @@ -2939,17 +1599,18 @@ return block; static void my_free(void *block, void *data) { (void)data; -if (show_memory && block != NULL) + +if (show_memory && outfile != NULL && block != NULL) { uint32_t i, j; BOOL found = FALSE; - fprintf(outfile, "free"); + cfprintf(clr_profiling, outfile, "free"); for (i = 0; i < malloclistptr; i++) { if (block == malloclist[i]) { - fprintf(outfile, " %5" SIZ_FORM, malloclistlength[i]); + cfprintf(clr_profiling, outfile, " %5" SIZ_FORM, malloclistlength[i]); malloclistptr--; for (j = i; j < malloclistptr; j++) { @@ -2960,9 +1621,9 @@ if (show_memory && block != NULL) break; } } - if (!found) fprintf(outfile, " unremembered block"); + if (!found) cfprintf(clr_profiling, outfile, " unremembered block"); #ifdef DEBUG_SHOW_MALLOC_ADDRESSES - fprintf(outfile, " %p", block); /* Not portable */ + cfprintf(clr_profiling, outfile, " %p", block); /* Not portable */ #endif fprintf(outfile, "\n"); } @@ -2991,17 +1652,97 @@ return depth > pat_patctl.stackguard_test; } + /************************************************* -* JIT memory callback * +* EBCDIC support functions * *************************************************/ -static PCRE2_JIT_STACK* -jit_callback(void *arg) +#if defined(EBCDIC) +static BOOL +printable(uint32_t c) +{ +if ((c >= CHAR_a && c <= CHAR_i) || + (c >= CHAR_j && c <= CHAR_r) || + (c >= CHAR_s && c <= CHAR_z) || + (c >= CHAR_A && c <= CHAR_I) || + (c >= CHAR_J && c <= CHAR_R) || + (c >= CHAR_S && c <= CHAR_Z) || + (c >= CHAR_0 && c <= CHAR_9)) + return TRUE; + +switch (c) + { + case CHAR_SPACE: + case CHAR_EXCLAMATION_MARK: + case CHAR_QUOTATION_MARK: + case CHAR_NUMBER_SIGN: + case CHAR_DOLLAR_SIGN: + case CHAR_PERCENT_SIGN: + case CHAR_AMPERSAND: + case CHAR_APOSTROPHE: + case CHAR_LEFT_PARENTHESIS: + case CHAR_RIGHT_PARENTHESIS: + case CHAR_ASTERISK: + case CHAR_PLUS: + case CHAR_COMMA: + case CHAR_MINUS: + case CHAR_DOT: + case CHAR_SLASH: + case CHAR_COLON: + case CHAR_SEMICOLON: + case CHAR_LESS_THAN_SIGN: + case CHAR_EQUALS_SIGN: + case CHAR_GREATER_THAN_SIGN: + case CHAR_QUESTION_MARK: + case CHAR_COMMERCIAL_AT: + case CHAR_LEFT_SQUARE_BRACKET: + case CHAR_BACKSLASH: + case CHAR_RIGHT_SQUARE_BRACKET: + case CHAR_CIRCUMFLEX_ACCENT: + case CHAR_UNDERSCORE: + case CHAR_GRAVE_ACCENT: + case CHAR_LEFT_CURLY_BRACKET: + case CHAR_VERTICAL_LINE: + case CHAR_RIGHT_CURLY_BRACKET: + case CHAR_TILDE: + return TRUE; + } + +return FALSE; +} +#endif + +#if defined(EBCDIC) && !EBCDIC_IO +static void +ascii_to_ebcdic_str(uint8_t *buf, size_t len) +{ +for (size_t i = 0; i < len; ++i) + buf[i] = ascii_to_ebcdic_1047[buf[i]]; +} + +static void +ebcdic_to_ascii_str(uint8_t *buf, size_t len) +{ +for (size_t i = 0; i < len; ++i) + buf[i] = ebcdic_1047_to_ascii[buf[i]]; +} +#endif + +#if defined(EBCDIC) +static uint32_t +ascii_to_ebcdic(uint32_t c) { -jit_was_used = TRUE; -return (PCRE2_JIT_STACK *)arg; +return (c < 256)? ascii_to_ebcdic_1047[c] : c; } +static uint32_t +ebcdic_to_ascii(uint32_t c) +{ +return (c < 256)? ebcdic_1047_to_ascii[c] : c; +} +#endif + + /************************************************* * Convert UTF-8 character to code point * @@ -3025,7 +1766,7 @@ Returns: > 0 => the number of bytes consumed */ static int -utf82ord(PCRE2_SPTR8 utf8bytes, PCRE2_SPTR8 end, uint32_t *vptr) +utf8_to_ord(PCRE2_SPTR8 utf8bytes, PCRE2_SPTR8 end, uint32_t *vptr) { uint32_t c = *utf8bytes++; uint32_t d = c; @@ -3057,7 +1798,7 @@ for (j = 0; j < i; j++) /* Check that encoding was the correct unique one */ -for (j = 0; j < utf8_table1_size; j++) +for (j = 0; j < (int)utf8_table1_size; j++) if (d <= (uint32_t)utf8_table1[j]) break; if (j != i) return -(i+1); @@ -3069,6 +1810,85 @@ return i+1; +#ifdef SUPPORT_PCRE2_16 +/************************************************* +* Convert UTF-16 character to code point * +*************************************************/ + +/* This function reads one or more UTF-16 code units, and returns the +codepoint of that character. + +Argument: + utf16units a pointer to the units vector + end a pointer to the end of the units vector + vptr a pointer to an int to receive the value + +Returns: > 0 => the number of 16-bit units consumed + -1 => malformed UTF-16 +*/ + +static int +utf16_to_ord(PCRE2_SPTR16 utf16units, PCRE2_SPTR16 end, uint32_t *vptr) +{ +uint32_t c = *utf16units++; + +if (c >= 0xdc00 && c <= 0xdfff) return -1; + +if (c >= 0xd800 && c < 0xdc00) + { + uint32_t c2; + + if (utf16units >= end) return -1; + + c2 = *utf16units++; + if (c2 < 0xdc00 || c2 > 0xdfff) return -1; + *vptr = ((c & 0x3ff) << 10) + (c2 & 0x3ff) + 0x10000; + return 2; + } + +*vptr = c; +return 1; +} +#endif /* SUPPORT_PCRE2_16 */ + + + +/************************************************* +* Convert character value to UTF-8 * +*************************************************/ + +/* This function takes an integer value in the range 0 - 0x7fffffff +and encodes it as a UTF-8 character in 0 to 6 bytes. It is needed even when the +8-bit library is not supported, to generate UTF-8 output for non-ASCII +characters. + +Arguments: + cvalue the character value + utf8bytes pointer to buffer for result - at least 6 bytes long + +Returns: number of characters placed in the buffer +*/ + +static int +ord_to_utf8(uint32_t cvalue, uint8_t *utf8bytes) +{ +int i, j; +if (cvalue > 0x7fffffffu) + return -1; +for (i = 0; i < (int)utf8_table1_size; i++) + if (cvalue <= (uint32_t)utf8_table1[i]) break; +utf8bytes += i; +for (j = i; j > 0; j--) + { + *utf8bytes-- = 0x80 | (cvalue & 0x3f); + cvalue >>= 6; + } +*utf8bytes = utf8_table2[i] | cvalue; +return i + 1; +} + + + /************************************************* * Print one character * *************************************************/ @@ -3090,12 +1910,15 @@ pchar(uint32_t c, BOOL utf, FILE *f) int n = 0; char tempbuffer[16]; -if (PRINTOK(c)) +if (PRINTABLE(c)) { + c = CHAR_OUTPUT(c); if (f != NULL) fprintf(f, "%c", c); return 1; } +c = CHAR_OUTPUT_HEX(c); + if (c < 0x100) { if (utf) @@ -3111,451 +1934,55 @@ if (c < 0x100) } if (f != NULL) n = fprintf(f, "\\x{%02x}", c); - else n = sprintf(tempbuffer, "\\x{%02x}", c); + else n = snprintf(tempbuffer, sizeof(tempbuffer), "\\x{%02x}", c); return n >= 0 ? n : 0; } -#ifdef SUPPORT_PCRE2_16 /************************************************* -* Find length of 0-terminated 16-bit string * +* Expand input buffers * *************************************************/ -static size_t strlen16(PCRE2_SPTR16 p) -{ -PCRE2_SPTR16 pp = p; -while (*pp != 0) pp++; -return (int)(pp - p); -} -#endif /* SUPPORT_PCRE2_16 */ - - +/* This function doubles the size of the input buffer and the buffer for +keeping an 8-bit copy of patterns (pbuffer8), and copies the current buffers to +the new ones. -#ifdef SUPPORT_PCRE2_32 -/************************************************* -* Find length of 0-terminated 32-bit string * -*************************************************/ +Arguments: none +Returns: nothing (aborts if malloc() fails) +*/ -static size_t strlen32(PCRE2_SPTR32 p) +static void +expand_input_buffers(void) { -PCRE2_SPTR32 pp = p; -while (*pp != 0) pp++; -return (int)(pp - p); -} -#endif /* SUPPORT_PCRE2_32 */ +size_t new_pbuffer8_size = 2*pbuffer8_size; +uint8_t *new_buffer = (uint8_t *)malloc(new_pbuffer8_size); +uint8_t *new_pbuffer8 = (uint8_t *)malloc(new_pbuffer8_size); +if (new_buffer == NULL || new_pbuffer8 == NULL) + { + cfprintf(clr_test_error, stderr, "pcre2test: malloc(%" SIZ_FORM ") failed\n", + new_pbuffer8_size); + exit(1); + } -#ifdef SUPPORT_PCRE2_8 -/************************************************* -* Print 8-bit character string * -*************************************************/ +memcpy(new_buffer, buffer, pbuffer8_size); +memcpy(new_pbuffer8, pbuffer8, pbuffer8_size); -/* Must handle UTF-8 strings in utf8 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). */ +pbuffer8_size = new_pbuffer8_size; -static int pchars8(PCRE2_SPTR8 p, int length, BOOL utf, FILE *f) -{ -PCRE2_SPTR8 end; -uint32_t c = 0; -int yield = 0; -if (length < 0) length = *p++; -end = p + length; -while (length-- > 0) - { - if (utf) - { - int rc = utf82ord(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); - } +free(buffer); +free(pbuffer8); -return yield; +buffer = new_buffer; +pbuffer8 = new_pbuffer8; } -#endif -#ifdef SUPPORT_PCRE2_16 + /************************************************* -* Print 16-bit character string * -*************************************************/ - -/* Must handle UTF-16 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, just counts chars -without printing. */ - -static int pchars16(PCRE2_SPTR16 p, int length, BOOL utf, FILE *f) -{ -int yield = 0; -if (length < 0) length = *p++; -while (length-- > 0) - { - uint32_t c = *p++ & 0xffff; - if (utf && c >= 0xD800 && c < 0xDC00 && length > 0) - { - int d = *p & 0xffff; - if (d >= 0xDC00 && d <= 0xDFFF) - { - c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000; - length--; - p++; - } - } - yield += pchar(c, utf, f); - } -return yield; -} -#endif /* SUPPORT_PCRE2_16 */ - - - -#ifdef SUPPORT_PCRE2_32 -/************************************************* -* Print 32-bit character string * -*************************************************/ - -/* Must handle UTF-32 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, just counts chars -without printing. */ - -static int pchars32(PCRE2_SPTR32 p, int length, BOOL utf, FILE *f) -{ -int yield = 0; -(void)(utf); /* Avoid compiler warning */ -if (length < 0) length = *p++; -while (length-- > 0) - { - uint32_t c = *p++; - yield += pchar(c, utf, f); - } -return yield; -} -#endif /* SUPPORT_PCRE2_32 */ - - - - -/************************************************* -* Convert character value to UTF-8 * -*************************************************/ - -/* This function takes an integer value in the range 0 - 0x7fffffff -and encodes it as a UTF-8 character in 0 to 6 bytes. It is needed even when the -8-bit library is not supported, to generate UTF-8 output for non-ASCII -characters. - -Arguments: - cvalue the character value - utf8bytes pointer to buffer for result - at least 6 bytes long - -Returns: number of characters placed in the buffer -*/ - -static int -ord2utf8(uint32_t cvalue, uint8_t *utf8bytes) -{ -int i, j; -if (cvalue > 0x7fffffffu) - return -1; -for (i = 0; i < utf8_table1_size; i++) - if (cvalue <= (uint32_t)utf8_table1[i]) break; -utf8bytes += i; -for (j = i; j > 0; j--) - { - *utf8bytes-- = 0x80 | (cvalue & 0x3f); - cvalue >>= 6; - } -*utf8bytes = utf8_table2[i] | cvalue; -return i + 1; -} - - - -#ifdef SUPPORT_PCRE2_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) - { - fprintf(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 = utf82ord(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 - - - -#ifdef SUPPORT_PCRE2_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) - { - fprintf(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 = utf82ord(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 /* SUPPORT_PCRE2_32 */ - - - -/* This function is no longer used. Keep it around for a while, just in case it -needs to be re-instated. */ - -#ifdef NEVERNEVERNEVER - -/************************************************* -* Move back by so many characters * -*************************************************/ - -/* Given a code unit offset in a subject string, move backwards by a number of -characters, and return the resulting offset. - -Arguments: - subject pointer to the string - offset start offset - count count to move back by - utf TRUE if in UTF mode - -Returns: a possibly changed offset -*/ - -static PCRE2_SIZE -backchars(uint8_t *subject, PCRE2_SIZE offset, uint32_t count, BOOL utf) -{ -if (!utf || test_mode == PCRE32_MODE) - return (count >= offset)? 0 : (offset - count); - -else if (test_mode == PCRE8_MODE) - { - PCRE2_SPTR8 pp = (PCRE2_SPTR8)subject + offset; - for (; count > 0 && pp > (PCRE2_SPTR8)subject; count--) - { - pp--; - while ((*pp & 0xc0) == 0x80) pp--; - } - return pp - (PCRE2_SPTR8)subject; - } - -else /* 16-bit mode */ - { - PCRE2_SPTR16 pp = (PCRE2_SPTR16)subject + offset; - for (; count > 0 && pp > (PCRE2_SPTR16)subject; count--) - { - pp--; - if ((*pp & 0xfc00) == 0xdc00) pp--; - } - return pp - (PCRE2_SPTR16)subject; - } -} -#endif /* NEVERNEVERNEVER */ - - - -/************************************************* -* Expand input buffers * -*************************************************/ - -/* This function doubles the size of the input buffer and the buffer for -keeping an 8-bit copy of patterns (pbuffer8), and copies the current buffers to -the new ones. - -Arguments: none -Returns: nothing (aborts if malloc() fails) -*/ - -static void -expand_input_buffers(void) -{ -int new_pbuffer8_size = 2*pbuffer8_size; -uint8_t *new_buffer = (uint8_t *)malloc(new_pbuffer8_size); -uint8_t *new_pbuffer8 = (uint8_t *)malloc(new_pbuffer8_size); - -if (new_buffer == NULL || new_pbuffer8 == NULL) - { - fprintf(stderr, "pcre2test: malloc(%d) failed\n", new_pbuffer8_size); - exit(1); - } - -memcpy(new_buffer, buffer, pbuffer8_size); -memcpy(new_pbuffer8, pbuffer8, pbuffer8_size); - -pbuffer8_size = new_pbuffer8_size; - -free(buffer); -free(pbuffer8); - -buffer = new_buffer; -pbuffer8 = new_pbuffer8; -} - - - -/************************************************* -* Read or extend an input line * +* Read or extend an input line * *************************************************/ /* Input lines are read into buffer, but both patterns and data lines can be @@ -3585,40 +2012,50 @@ uint8_t *here = start; for (;;) { + size_t dlen; size_t rlen = (size_t)(pbuffer8_size - (here - buffer)); - if (rlen > 1000) - { - size_t dlen; - - /* If libreadline or libedit support is required, use readline() to read a - line if the input is a terminal. Note that readline() removes the trailing - newline, so we must put it back again, to be compatible with fgets(). */ + /* If libreadline or libedit support is required, use readline() to read a + line if the input is a terminal. Note that readline() removes the trailing + newline, so we must put it back again, to be compatible with fgets(). */ #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT) - if (INTERACTIVE(f)) + if (INTERACTIVE(f)) + { + char promptbuf[80]; + int snprintf_rc; + char *s; + if (should_print_colour(clr_prompt, stdout) && + (snprintf_rc = snprintf(promptbuf, sizeof(promptbuf), "\x1b[%dm%s\x1b[0m", clr_prompt, prompt)) > 0 && + snprintf_rc < (int)sizeof(promptbuf)) + s = readline(promptbuf); + else + s = readline(prompt); + if (s == NULL) return (here == start)? NULL : start; + dlen = strlen(s); + if (dlen > rlen - 2) { - size_t len; - char *s = readline(prompt); - if (s == NULL) return (here == start)? NULL : start; - len = strlen(s); - if (len > 0) add_history(s); - if (len > rlen - 1) len = rlen - 1; - memcpy(here, s, len); - here[len] = '\n'; - here[len+1] = 0; - free(s); + cfprintf(clr_test_error, outfile, "** Interactive input exceeds buffer space\n"); + exit(1); } - else + if (dlen > 0) add_history(s); + memcpy(here, s, dlen); + here[dlen] = '\n'; + here[dlen+1] = 0; + free(s); + return start; + } #endif + if (rlen > 1000) + { + int rlen_trunc = (rlen > (unsigned)INT_MAX)? INT_MAX : (int)rlen; + /* Read the next line by normal means, prompting if the file is a tty. */ - { - if (INTERACTIVE(f)) printf("%s", prompt); - if (fgets((char *)here, rlen, f) == NULL) - return (here == start)? NULL : start; - } + if (INTERACTIVE(f)) cfprintf(clr_prompt, stdout, "%s", prompt); + if (fgets((char *)here, rlen_trunc, f) == NULL) + return (here == start)? NULL : start; dlen = strlen((char *)here); here += dlen; @@ -3635,10 +2072,10 @@ for (;;) strlen() to give a short length. This is a hard error because pcre2test expects to work with C strings. */ - if (!INTERACTIVE(f) && dlen < rlen - 1 && !feof(f)) + if (dlen < (unsigned)rlen_trunc - 1 && !feof(f)) { - fprintf(outfile, "** Binary zero encountered in input\n"); - fprintf(outfile, "** pcre2test run abandoned\n"); + cfprintf(clr_test_error, outfile, "** Binary zero encountered in input\n"); + cfprintf(clr_test_error, outfile, "** pcre2test run abandoned\n"); exit(1); } } @@ -3672,13 +2109,15 @@ Returns: < 0, = 0, or > 0, according to the comparison */ static int -strncmpic(const uint8_t *s, const uint8_t *t, int n) +strncmpic(const uint8_t *s, const uint8_t *t, size_t n) { -while (n--) +if (n > 0) do { int c = tolower(*s++) - tolower(*t++); if (c != 0) return c; } +while (--n > 0); + return 0; } @@ -3698,7 +2137,7 @@ Returns: an index in the modifier list, or -1 on failure */ static int -scan_modifiers(const uint8_t *p, unsigned int len) +scan_modifiers(const uint8_t *p, size_t len) { int bot = 0; int top = MODLISTCOUNT; @@ -3706,595 +2145,256 @@ int top = MODLISTCOUNT; while (top > bot) { int mid = (bot + top)/2; - unsigned int mlen = strlen(modlist[mid].name); + size_t mlen = strlen(modlist[mid].name); int c = strncmp((const char *)p, modlist[mid].name, (len < mlen)? len : mlen); if (c == 0) { if (len == mlen) return mid; - c = (int)len - (int)mlen; + c = len > mlen ? 1 : -1; } if (c > 0) bot = mid + 1; else top = mid; } return -1; - } /************************************************* -* Check a modifer and find its field * +* Determine how to print an error offset * *************************************************/ -/* 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. +/* Each error code has an associated direction - does it refer +to the characters to the right or to the left of the offset? 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 + rc the error code associated with the offset + erroroffset the offset in the pattern where the error occurred + +Returns: -1 if the error is unimplemented + 0 if the offset is to be ignored (should be zero) + 1 if the error refers to the left of the offset + 2 if the error refers to the right of the offset + 3 if the error refers to both sides of the offset */ -static void * -check_modifier(modstruct *m, int ctx, patctl *pctl, datctl *dctl, uint32_t c) +static int +error_direction(int rc, PCRE2_SIZE erroroffset) { -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: - fprintf(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 = PTR(default_pat_context); - else if (ctx == CTX_PAT) field = PTR(pat_context); - break; - - case MOD_CTM: /* Match context modifier */ - if (ctx == CTX_DEFDAT) field = PTR(default_dat_context); - else if (ctx == CTX_DAT) field = PTR(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; - } +switch (rc) + { + /* These cases are all for things which don't affect a specific part of the + pattern, and should always return zero offset. */ + + case PCRE2_ERROR_NULL_PATTERN: + case PCRE2_ERROR_BAD_OPTIONS: + case PCRE2_ERROR_PATTERN_TOO_LARGE: + case PCRE2_ERROR_HEAP_FAILED: + case PCRE2_ERROR_UNICODE_NOT_SUPPORTED: + case PCRE2_ERROR_PARENTHESES_STACK_CHECK: + case PCRE2_ERROR_PATTERN_TOO_COMPLICATED: + case PCRE2_ERROR_PATTERN_STRING_TOO_LONG: + case PCRE2_ERROR_NO_SURROGATES_IN_UTF16: + case PCRE2_ERROR_BAD_LITERAL_OPTIONS: + case PCRE2_ERROR_PATTERN_COMPILED_SIZE_TOO_BIG: + case PCRE2_ERROR_EXTRA_CASING_REQUIRES_UNICODE: + case PCRE2_ERROR_TURKISH_CASING_REQUIRES_UTF: + case PCRE2_ERROR_EXTRA_CASING_INCOMPATIBLE: + return 0; + + /* A few exceptional cases use the errorofset to point rightwards. These are + used when indicating an error in a capture group or lookaround parentheses. + It is more user-friendly to identify the capture group by its start. */ + + case PCRE2_ERROR_PARENTHESES_NEST_TOO_DEEP: + case PCRE2_ERROR_LOOKBEHIND_NOT_FIXED_LENGTH: + case PCRE2_ERROR_TOO_MANY_CONDITION_BRANCHES: + case PCRE2_ERROR_LOOKBEHIND_TOO_COMPLICATED: + case PCRE2_ERROR_LOOKBEHIND_INVALID_BACKSLASH_C: + case PCRE2_ERROR_CALLOUT_NO_STRING_DELIMITER: + case PCRE2_ERROR_QUERY_BARJX_NEST_TOO_DEEP: + case PCRE2_ERROR_LOOKBEHIND_TOO_LONG: + case PCRE2_ERROR_MAX_VAR_LOOKBEHIND_EXCEEDED: + case PCRE2_ERROR_ECLASS_NEST_TOO_DEEP: + return 2; + + /* The standard erroroffset should occur just after the affected portion of + the pattern, unless there is a good reason not to do this. Consistency is + good, but if there's a specific need then that's more important. */ + + case PCRE2_ERROR_END_BACKSLASH: + case PCRE2_ERROR_END_BACKSLASH_C: + case PCRE2_ERROR_UNKNOWN_ESCAPE: + case PCRE2_ERROR_QUANTIFIER_OUT_OF_ORDER: + case PCRE2_ERROR_QUANTIFIER_TOO_BIG: + case PCRE2_ERROR_MISSING_SQUARE_BRACKET: + case PCRE2_ERROR_ESCAPE_INVALID_IN_CLASS: + case PCRE2_ERROR_CLASS_RANGE_ORDER: + case PCRE2_ERROR_QUANTIFIER_INVALID: + case PCRE2_ERROR_INVALID_AFTER_PARENS_QUERY: + case PCRE2_ERROR_POSIX_CLASS_NOT_IN_CLASS: + case PCRE2_ERROR_POSIX_NO_SUPPORT_COLLATING: + case PCRE2_ERROR_MISSING_CLOSING_PARENTHESIS: + return 1; + case PCRE2_ERROR_BAD_SUBPATTERN_REFERENCE: + return 3; /* TODO I'd like to fix this, but some of the cases are _hard_ */ + case PCRE2_ERROR_MISSING_COMMENT_CLOSING: + case PCRE2_ERROR_UNMATCHED_CLOSING_PARENTHESIS: + case PCRE2_ERROR_MISSING_CONDITION_CLOSING: + case PCRE2_ERROR_ZERO_RELATIVE_REFERENCE: + case PCRE2_ERROR_CONDITION_ASSERTION_EXPECTED: + case PCRE2_ERROR_BAD_RELATIVE_REFERENCE: + case PCRE2_ERROR_UNKNOWN_POSIX_CLASS: + case PCRE2_ERROR_CODE_POINT_TOO_BIG: + case PCRE2_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE: + case PCRE2_ERROR_CALLOUT_NUMBER_TOO_BIG: + case PCRE2_ERROR_MISSING_CALLOUT_CLOSING: + case PCRE2_ERROR_ESCAPE_INVALID_IN_VERB: + case PCRE2_ERROR_UNRECOGNIZED_AFTER_QUERY_P: + case PCRE2_ERROR_MISSING_NAME_TERMINATOR: + case PCRE2_ERROR_DUPLICATE_SUBPATTERN_NAME: + case PCRE2_ERROR_INVALID_SUBPATTERN_NAME: + case PCRE2_ERROR_UNICODE_PROPERTIES_UNAVAILABLE: + case PCRE2_ERROR_MALFORMED_UNICODE_PROPERTY: + case PCRE2_ERROR_UNKNOWN_UNICODE_PROPERTY: + case PCRE2_ERROR_SUBPATTERN_NAME_TOO_LONG: + case PCRE2_ERROR_TOO_MANY_NAMED_SUBPATTERNS: + case PCRE2_ERROR_CLASS_INVALID_RANGE: + case PCRE2_ERROR_OCTAL_BYTE_TOO_BIG: + return 1; + case PCRE2_ERROR_DEFINE_TOO_MANY_BRANCHES: + return 2; /* TODO Not ideally placed; I'd like to fix this */ + case PCRE2_ERROR_BACKSLASH_O_MISSING_BRACE: + case PCRE2_ERROR_BACKSLASH_G_SYNTAX: + case PCRE2_ERROR_PARENS_QUERY_R_MISSING_CLOSING: + case PCRE2_ERROR_VERB_UNKNOWN: + case PCRE2_ERROR_SUBPATTERN_NUMBER_TOO_BIG: + case PCRE2_ERROR_SUBPATTERN_NAME_EXPECTED: + case PCRE2_ERROR_INVALID_OCTAL: + case PCRE2_ERROR_SUBPATTERN_NAMES_MISMATCH: + case PCRE2_ERROR_MARK_MISSING_ARGUMENT: + case PCRE2_ERROR_INVALID_HEXADECIMAL: + case PCRE2_ERROR_BACKSLASH_C_SYNTAX: + case PCRE2_ERROR_BACKSLASH_K_SYNTAX: + case PCRE2_ERROR_BACKSLASH_N_IN_CLASS: + case PCRE2_ERROR_CALLOUT_STRING_TOO_LONG: + case PCRE2_ERROR_UNICODE_DISALLOWED_CODE_POINT: + return 1; + case PCRE2_ERROR_VERB_NAME_TOO_LONG: + case PCRE2_ERROR_BACKSLASH_U_CODE_POINT_TOO_BIG: + case PCRE2_ERROR_MISSING_OCTAL_OR_HEX_DIGITS: + case PCRE2_ERROR_VERSION_CONDITION_SYNTAX: + case PCRE2_ERROR_CALLOUT_BAD_STRING_DELIMITER: + case PCRE2_ERROR_BACKSLASH_C_CALLER_DISABLED: + case PCRE2_ERROR_BACKSLASH_C_LIBRARY_DISABLED: + case PCRE2_ERROR_SUPPORTED_ONLY_IN_UNICODE: + case PCRE2_ERROR_INVALID_HYPHEN_IN_OPTIONS: + case PCRE2_ERROR_ALPHA_ASSERTION_UNKNOWN: + case PCRE2_ERROR_SCRIPT_RUN_NOT_AVAILABLE: + case PCRE2_ERROR_TOO_MANY_CAPTURES: + case PCRE2_ERROR_MISSING_OCTAL_DIGIT: + return 1; + case PCRE2_ERROR_BACKSLASH_K_IN_LOOKAROUND: + return 3; /* TODO No erroroffset implemented yet, sadly */ + case PCRE2_ERROR_OVERSIZE_PYTHON_OCTAL: + case PCRE2_ERROR_CALLOUT_CALLER_DISABLED: + case PCRE2_ERROR_ECLASS_INVALID_OPERATOR: + case PCRE2_ERROR_ECLASS_UNEXPECTED_OPERATOR: + case PCRE2_ERROR_ECLASS_EXPECTED_OPERAND: + case PCRE2_ERROR_ECLASS_MIXED_OPERATORS: + case PCRE2_ERROR_ECLASS_HINT_SQUARE_BRACKET: + case PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_EXPR: + case PCRE2_ERROR_PERL_ECLASS_EMPTY_EXPR: + case PCRE2_ERROR_PERL_ECLASS_MISSING_CLOSE: + case PCRE2_ERROR_PERL_ECLASS_UNEXPECTED_CHAR: + case PCRE2_ERROR_EXPECTED_CAPTURE_GROUP: + case PCRE2_ERROR_MISSING_OPENING_PARENTHESIS: + case PCRE2_ERROR_MISSING_NUMBER_TERMINATOR: + return 1; -if (field == NULL) - { - if (c == 0) - fprintf(outfile, "** \"%s\" is not valid here\n", m->name); - else - fprintf(outfile, "** /%c is not valid here\n", c); - return NULL; + /* These two are a little fiddly. They can be triggered by passed-in options + (when erroroffset is zero), or by text in the pattern "(*UTF)". We only + indicate an pattern error in the latter case. */ + + case PCRE2_ERROR_UTF_IS_DISABLED: + case PCRE2_ERROR_UCP_IS_DISABLED: + return (erroroffset > 0)? 1 : 0; + + case PCRE2_ERROR_UTF8_ERR1: + case PCRE2_ERROR_UTF8_ERR2: + case PCRE2_ERROR_UTF8_ERR3: + case PCRE2_ERROR_UTF8_ERR4: + case PCRE2_ERROR_UTF8_ERR5: + case PCRE2_ERROR_UTF8_ERR6: + case PCRE2_ERROR_UTF8_ERR7: + case PCRE2_ERROR_UTF8_ERR8: + case PCRE2_ERROR_UTF8_ERR9: + case PCRE2_ERROR_UTF8_ERR10: + case PCRE2_ERROR_UTF8_ERR11: + case PCRE2_ERROR_UTF8_ERR12: + case PCRE2_ERROR_UTF8_ERR13: + case PCRE2_ERROR_UTF8_ERR14: + case PCRE2_ERROR_UTF8_ERR15: + case PCRE2_ERROR_UTF8_ERR16: + case PCRE2_ERROR_UTF8_ERR17: + case PCRE2_ERROR_UTF8_ERR18: + case PCRE2_ERROR_UTF8_ERR19: + case PCRE2_ERROR_UTF8_ERR20: + case PCRE2_ERROR_UTF8_ERR21: + case PCRE2_ERROR_UTF16_ERR1: + case PCRE2_ERROR_UTF16_ERR2: + case PCRE2_ERROR_UTF16_ERR3: + case PCRE2_ERROR_UTF32_ERR1: + case PCRE2_ERROR_UTF32_ERR2: + return 2; } -return (char *)field + offset; +return -1; } +#ifdef SUPPORT_PCRE2_8 /************************************************* -* Decode a modifier list * +* Show something in a 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 -*/ +/* This function just helps to keep the code that uses it tidier. It's used for +various lists of things where there needs to be introductory text before the +first item. As these calls are all in the POSIX-support code, they happen only +when 8-bit mode is supported. */ -static BOOL -decode_modifiers(uint8_t *p, int ctx, patctl *pctl, datctl *dctl) +static void +prmsg(const char **msg, const char *s) { -uint8_t *ep, *pp; -long li; -unsigned long uli; -BOOL first = TRUE; - -for (;;) - { - void *field; - modstruct *m; - BOOL off = FALSE; - unsigned int i, len; - int index; - char *endptr; +cfprintf(clr_test_error, outfile, "%s %s", *msg, s); +*msg = ""; +} +#endif /* SUPPORT_PCRE2_8 */ - /* 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. */ +/************************************************* +* Show control bits * +*************************************************/ - for (ep = p; *ep != 0 && *ep != ','; ep++); - if (*ep == 0) - { - while (ep > p && isspace(ep[-1])) ep--; - *ep = 0; - } +/* Called for mutually exclusive controls and for unsupported POSIX controls. +Because the bits are unique, this can be used for both pattern and data control +words. - /* Remember if the first character is '-'. */ +Arguments: + clr colour for output + controls control bits + controls2 more control bits + before text to print before - 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) - { - fprintf(outfile, "** Unrecognized modifier \"%.*s\"\n", (int)(ep-p), p); - if (ep - p == 1) - fprintf(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) - { - fprintf(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) - { - fprintf(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 tne 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++ != '=') - { - fprintf(outfile, "** '=' expected after \"%s\"\n", m->name); - return FALSE; - } - if (off) - { - fprintf(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) - { - fprintf(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: -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) - pcre2_set_optimize_8((pcre2_compile_context_8*)field, m->value); -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) - pcre2_set_optimize_16((pcre2_compile_context_16*)field, m->value); -#endif -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) - pcre2_set_optimize_32((pcre2_compile_context_32*)field, m->value); -#endif - 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; - } - /* 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) - { - *((uint16_t *)field) = NEWLINE_DEFAULT; - if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 &= ~CTL2_NL_SET; - else dctl->control2 &= ~CTL2_NL_SET; - } - else - { - *((uint16_t *)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) - { - fprintf(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) - { - fprintf(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) - { - fprintf(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) - { - fprintf(outfile, "** Overlong value for \"%s\" (max %d code units)\n", - m->name, m->value - 1); - return FALSE; - } - memcpy(field, pp, len); - ((uint8_t *)field)[len] = 0; - pp = ep; - break; - } - - if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0) - { - fprintf(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] != 0 || - (pctl->control & NOTPOP_CONTROLS) != 0)) - { - fprintf(outfile, "** \"%s\" is not valid here\n", m->name); - return FALSE; - } - } - -return TRUE; - -INVALID_VALUE: -fprintf(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; -PCRE2_PATTERN_INFO(rc, compiled_code, what, NULL); /* Exercise the code */ -PCRE2_PATTERN_INFO(rc, compiled_code, what, where); -if (rc >= 0) return 0; -if (rc != PCRE2_ERROR_UNSET || !unsetok) - { - fprintf(outfile, "Error %d from pcre2_pattern_info_%d(%d)\n", rc, test_mode, - what); - if (rc == PCRE2_ERROR_BADMODE) - fprintf(outfile, "Running in %d-bit mode but pattern was compiled in " - "%d-bit mode\n", test_mode, - 8 * (FLD(compiled_code, flags) & PCRE2_MODE_MASK)); - } -return rc; -} - - - -#ifdef SUPPORT_PCRE2_8 -/************************************************* -* Show something in a list * -*************************************************/ - -/* This function just helps to keep the code that uses it tidier. It's used for -various lists of things where there needs to be introductory text before the -first item. As these calls are all in the POSIX-support code, they happen only -when 8-bit mode is supported. */ - -static void -prmsg(const char **msg, const char *s) -{ -fprintf(outfile, "%s %s", *msg, s); -*msg = ""; -} -#endif /* SUPPORT_PCRE2_8 */ - - - -/************************************************* -* Show control bits * -*************************************************/ - -/* Called for mutually exclusive controls and for unsupported POSIX controls. -Because the bits are unique, this can be used for both pattern and data control -words. - -Arguments: - controls control bits - controls2 more control bits - before text to print before - -Returns: nothing -*/ +Returns: nothing +*/ static void -show_controls(uint32_t controls, uint32_t controls2, const char *before) +show_controls(int clr, uint32_t controls, uint32_t controls2, const char *before) { -fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", +cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", before, ((controls & CTL_AFTERTEXT) != 0)? " aftertext" : "", ((controls & CTL_ALLAFTERTEXT) != 0)? " allaftertext" : "", @@ -4328,6 +2428,7 @@ fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s ((controls & CTL_NULLCONTEXT) != 0)? " null_context" : "", ((controls2 & CTL2_NULL_REPLACEMENT) != 0)? " null_replacement" : "", ((controls2 & CTL2_NULL_SUBJECT) != 0)? " null_subject" : "", + ((controls2 & CTL2_NULL_SUBSTITUTE_MATCH_DATA) != 0)? " null_substitute_match_data" : "", ((controls & CTL_POSIX) != 0)? " posix" : "", ((controls & CTL_POSIX_NOSUB) != 0)? " posix_nosub" : "", ((controls & CTL_PUSH) != 0)? " push" : "", @@ -4357,6 +2458,7 @@ fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s /* Called from show_pattern_info() and for unsupported POSIX options. Arguments: + clr colour for output options an options word before text to print before after text to print after @@ -4365,10 +2467,10 @@ Returns: nothing */ static void -show_compile_options(uint32_t options, const char *before, const char *after) +show_compile_options(int clr, uint32_t options, const char *before, const char *after) { -if (options == 0) fprintf(outfile, "%s %s", before, after); -else fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", +if (options == 0) cfprintf(clr, outfile, "%s %s", before, after); +else cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", before, ((options & PCRE2_ALT_BSUX) != 0)? " alt_bsux" : "", ((options & PCRE2_ALT_CIRCUMFLEX) != 0)? " alt_circumflex" : "", @@ -4412,6 +2514,7 @@ else fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s% /* Called from show_pattern_info() and for unsupported POSIX options. Arguments: + clr colour for output options an options word before text to print before after text to print after @@ -4420,11 +2523,11 @@ Returns: nothing */ static void -show_compile_extra_options(uint32_t options, const char *before, +show_compile_extra_options(int clr, uint32_t options, const char *before, const char *after) { -if (options == 0) fprintf(outfile, "%s %s", before, after); -else fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", +if (options == 0) cfprintf(clr, outfile, "%s %s", before, after); +else cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", before, ((options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) != 0) ? " allow_lookaround_bsk" : "", ((options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) != 0)? " allow_surrogate_escapes" : "", @@ -4453,6 +2556,7 @@ else fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", /* Arguments: + clr colour for output flags an options word before text to print before after text to print after @@ -4461,10 +2565,10 @@ Returns: nothing */ static void -show_optimize_flags(uint32_t flags, const char *before, const char *after) +show_optimize_flags(int clr, uint32_t flags, const char *before, const char *after) { -if (flags == 0) fprintf(outfile, "%s%s", before, after); -else fprintf(outfile, "%s%s%s%s%s%s%s", +if (flags == 0) cfprintf(clr, outfile, "%s%s", before, after); +else cfprintf(clr, outfile, "%s%s%s%s%s%s%s", before, ((flags & PCRE2_OPTIM_AUTO_POSSESS) != 0) ? "auto_possess" : "", ((flags & PCRE2_OPTIM_AUTO_POSSESS) != 0 && (flags >> 1) != 0) ? "," : "", @@ -4483,9 +2587,9 @@ else fprintf(outfile, "%s%s%s%s%s%s%s", /* Called for unsupported POSIX options. */ static void -show_match_options(uint32_t options) +show_match_options(int clr, uint32_t options) { -fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", +cfprintf(clr, outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", ((options & PCRE2_ANCHORED) != 0)? " anchored" : "", ((options & PCRE2_COPY_MATCHED_SUBJECT) != 0)? " copy_matched_subject" : "", ((options & PCRE2_DFA_RESTART) != 0)? " dfa_restart" : "", @@ -4506,4309 +2610,399 @@ fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", /************************************************* -* Show memory usage info for a pattern * +* Open file for save/load commands * *************************************************/ -static void -show_memory_info(void) -{ -uint32_t name_count, name_entry_size; -PCRE2_SIZE size, cblock_size, data_size; - -/* One of the test_mode values will always be true, but to stop a compiler -warning we must initialize cblock_size. */ - -cblock_size = 0; -#ifdef SUPPORT_PCRE2_8 -if (test_mode == PCRE8_MODE) cblock_size = sizeof(pcre2_real_code_8); -#endif -#ifdef SUPPORT_PCRE2_16 -if (test_mode == PCRE16_MODE) cblock_size = sizeof(pcre2_real_code_16); -#endif -#ifdef SUPPORT_PCRE2_32 -if (test_mode == PCRE32_MODE) cblock_size = sizeof(pcre2_real_code_32); -#endif +/* This function decodes the file name and opens the file. -(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); +Arguments: + buffptr point after the #command + mode open mode + fptr points to the FILE variable + name name of # command -/* The uint32_t variables are cast before multiplying to avoid potential - integer overflow. */ -data_size = (PCRE2_SIZE)name_count * (PCRE2_SIZE)name_entry_size * (PCRE2_SIZE)code_unit_size; +Returns: PR_OK or PR_ABEND +*/ -fprintf(outfile, "Memory allocation - code size : %" SIZ_FORM "\n", size - - cblock_size - data_size); -if (data_size != 0) - fprintf(outfile, "Memory allocation - data size : %" SIZ_FORM "\n", data_size); +static int +open_file(uint8_t *buffptr, const char *mode, FILE **fptr, const char *name) +{ +char *endf; +char *filename = (char *)buffptr; +while (isspace((unsigned char)*filename)) filename++; +endf = filename + strlen(filename); +while (endf > filename && isspace((unsigned char)endf[-1])) endf--; -if (pat_patctl.jit != 0) +if (endf == filename) { - (void)pattern_info(PCRE2_INFO_JITSIZE, &size, FALSE); - fprintf(outfile, "Memory allocation - JIT code : %" SIZ_FORM "\n", size); + cfprintf(clr_test_error, outfile, "** File name expected after %s\n", name); + return PR_ABEND; } -} - +*endf = 0; +*fptr = fopen((const char *)filename, mode); +if (*fptr == NULL) + { + cfprintf(clr_test_error, outfile, "** Failed to open \"%s\": %s\n", filename, strerror(errno)); + return PR_ABEND; + } -/************************************************* -* 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); -fprintf(outfile, "Frame size for pcre2_match(): %" SIZ_FORM "\n", frame_size); +return PR_OK; } + /************************************************* -* Show heapframes size info for a match_data * +* Substitute case callout transform * *************************************************/ -static void -show_heapframes_size(void) +/* Function to implement our test-only custom case mappings. +To ease implementation, we only work in the ASCII range (so that we don't need +to read & write UTF sequences). +However, we aim to implement case mappings which fairly well represent the range +of interesting behaviours that exist for Unicode codepoints. */ + +static BOOL +case_transform(int to_case, int num_in, int *num_read, int *num_write, + uint32_t *c1, uint32_t *c2) { -PCRE2_SIZE heapframes_size; -PCRE2_GET_MATCH_DATA_HEAPFRAMES_SIZE(heapframes_size, match_data); -fprintf(outfile, "Heapframes size in match_data: %" SIZ_FORM "\n", - heapframes_size); -} +/* Let's have one character which aborts the substitution. */ +if (*c1 == CHAR_EXCLAMATION_MARK) return FALSE; +/* Default behaviour is to read one character, and write back that same one +character (treating all characters as "uncased"). */ +*num_read = *num_write = 1; +/* Add a normal case pair 'a' (l) <-> 'B' (t,u). Standard ASCII letter +behaviour, but with switched letters for testing. */ +if (*c1 == CHAR_a && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_B; +else if (*c1 == CHAR_B && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_a; -/************************************************* -* Get and output an error message * -*************************************************/ +/* Add a titlecased triplet 'd' (l) <-> 'D' (t) <-> 'Z' (u). Example: the +'dz'/'Dz'/'DZ' ligature character ("Latin Small Letter DZ" <-> "Latin Capital +Letter D with Small Letter Z" <-> "Latin Capital Letter DZ"). */ +else if (*c1 == CHAR_d && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = (to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST)? CHAR_D : CHAR_Z; +else if (*c1 == CHAR_D && to_case != PCRE2_SUBSTITUTE_CASE_TITLE_FIRST) + *c1 = (to_case == PCRE2_SUBSTITUTE_CASE_LOWER)? CHAR_d : CHAR_Z; +else if (*c1 == CHAR_Z && to_case != PCRE2_SUBSTITUTE_CASE_UPPER) + *c1 = (to_case == PCRE2_SUBSTITUTE_CASE_LOWER)? CHAR_d : CHAR_D; -static BOOL -print_error_message(int errorcode, const char *before, const char *after) -{ -int len; -PCRE2_GET_ERROR_MESSAGE(len, errorcode, pbuffer); -if (len < 0) +/* Expands when uppercased. Example: Esszet 'f' <-> 'SS'. */ +else if (*c1 == CHAR_f && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) { - fprintf(outfile, "\n** pcre2test internal error: cannot interpret error " - "number\n** Unexpected return (%d) from pcre2_get_error_message()\n", len); + *c1 = CHAR_S; + *c2 = CHAR_S; + *num_write = 2; } -else +else if (*c1 == CHAR_s && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_S; +else if (*c1 == CHAR_S && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_s; + +/* Expanding and contracting characters, 'o' <-> 'OO'. You can get this purely +due to UTF-8 encoding length, for example uppercase Omega (3 bytes in UTF-8) +lowercases to 2 bytes in UTF-8. */ +else if (num_in == 2 && *c1 == CHAR_O && *c2 == CHAR_O && + to_case == PCRE2_SUBSTITUTE_CASE_LOWER) { - fprintf(outfile, "%s", before); - PCHARSV(CASTVAR(void *, pbuffer), 0, len, FALSE, outfile); - fprintf(outfile, "%s", after); + *c1 = CHAR_o; + *num_read = 2; } -return len >= 0; -} - - -/************************************************* -* Callback function for callout enumeration * -*************************************************/ - -/* The only differences in the callout emumeration 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. - -Argument: - cb pointer to enumerate block - callout_data user data - -Returns: 0 -*/ - -static int callout_callback(pcre2_callout_enumerate_block_8 *cb, - void *callout_data) -{ -uint32_t i; -BOOL utf = (FLD(compiled_code, overall_options) & PCRE2_UTF) != 0; - -(void)callout_data; /* Not currently displayed */ - -fprintf(outfile, "Callout "); -if (cb->callout_string != NULL) +else if (*c1 == CHAR_o && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) { - uint32_t delimiter = CODE_UNIT(cb->callout_string, -1); - fprintf(outfile, "%c", delimiter); - PCHARSV(cb->callout_string, 0, - 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 ", delimiter); + *c1 = CHAR_O; + *c2 = CHAR_O; + *num_write = 2; } -else fprintf(outfile, "%d ", cb->callout_number); - -fprintf(outfile, "%.*s\n", - (int)((cb->next_item_length == 0)? 1 : cb->next_item_length), - pbuffer8 + cb->pattern_position); - -return 0; -} - - - -/************************************************* -* 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) -{ -uint32_t compile_options, overall_options, extra_options; -BOOL utf = (FLD(compiled_code, overall_options) & PCRE2_UTF) != 0; - -if ((pat_patctl.control & (CTL_BINCODE|CTL_FULLBINCODE)) != 0) +else if (num_in == 2 && *c1 == CHAR_p && *c2 == CHAR_p && + to_case != PCRE2_SUBSTITUTE_CASE_LOWER) { - fprintf(outfile, "------------------------------------------------------------------\n"); - PCRE2_PRINTINT((pat_patctl.control & CTL_FULLBINCODE) != 0); + *c1 = CHAR_P; + *num_read = 2; } - -if ((pat_patctl.control & CTL_INFO) != 0) +else if (*c1 == CHAR_P && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) { - int rc; - void *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; - - /* Exercise the error route. */ - - PCRE2_PATTERN_INFO(rc, compiled_code, 999, NULL); - (void)rc; - - /* 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--) - { - int imm2_size = test_mode == PCRE8_MODE ? 2 : 1; - uint32_t length = (uint32_t)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) - { -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) - { - PCRE2_SPTR32 nameptr = (PCRE2_SPTR32)nametable + imm2_size; - while (*nameptr != 0) - { - uint8_t u8buff[6]; - int len = ord2utf8(*nameptr++, u8buff); - fprintf(outfile, "%.*s", len, u8buff); - } - } -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) - { - PCRE2_SPTR16 nameptr = (PCRE2_SPTR16)nametable + imm2_size; - while (*nameptr != 0) - { - int len; - uint8_t u8buff[6]; - uint32_t c = *nameptr++ & 0xffff; - if (c >= 0xD800 && c < 0xDC00) - c = ((c & 0x3ff) << 10) + (*nameptr++ & 0x3ff) + 0x10000; - len = ord2utf8(c, u8buff); - fprintf(outfile, "%.*s", len, u8buff); - } - } -#endif -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) - fprintf(outfile, "%s", (PCRE2_SPTR8)nametable + imm2_size); -#endif - } - else /* Not UTF mode */ - { - PCHARSV(nametable, imm2_size, length, FALSE, outfile); - } - - while (length++ < nameentrysize - imm2_size) putc(' ', outfile); - -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) - fprintf(outfile, "%3d\n", (int)(((PCRE2_SPTR32)nametable)[0])); -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) - fprintf(outfile, "%3d\n", (int)(((PCRE2_SPTR16)nametable)[0])); -#endif -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) - fprintf(outfile, "%3d\n", (int)( - ((((PCRE2_SPTR8)nametable)[0]) << 8) | ((PCRE2_SPTR8)nametable)[1])); -#endif - - nametable = (void *)((PCRE2_UCHAR8 *)nametable + nameentrysize * code_unit_size); - } - } - - 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(compile_options, "Options:", "\n"); - else - { - show_compile_options(compile_options, "Compile options:", "\n"); - show_compile_options(overall_options, "Overall options:", "\n"); - } - } - - if (extra_options != 0) - show_compile_extra_options(extra_options, "Extra options:", "\n"); - - if (FLD(compiled_code, optimization_flags) != PCRE2_OPTIMIZATION_ALL) - show_optimize_flags(FLD(compiled_code, optimization_flags), "Optimizations: ", "\n"); - - if (jchanged) fprintf(outfile, "Duplicate name status changes\n"); - - if ((pat_patctl.control2 & CTL2_BSR_SET) != 0 || - (FLD(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 ((FLD(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 = - ((FLD(compiled_code, flags) & PCRE2_FIRSTCASELESS) == 0)? - "" : " (caseless)"; - if (PRINTOK(first_cunit)) - fprintf(outfile, "First code unit = \'%c\'%s\n", first_cunit, caseless); - else - { - fprintf(outfile, "First code unit = "); - pchar(first_cunit, FALSE, outfile); - fprintf(outfile, "%s\n", caseless); - } - } - else if (start_bits != NULL) - { - int i; - int c = 24; - fprintf(outfile, "Starting code units:"); - for (i = 0; i < 256; i++) - { - if ((start_bits[i/8] & (1u << (i&7))) != 0) - { - if (c > 75) - { - fprintf(outfile, "\n "); - c = 2; - } - if (PRINTOK(i) && i != ' ') - { - fprintf(outfile, " %c", i); - c += 2; - } - else - { - fprintf(outfile, " \\x%02x", i); - c += 5; - } - } - } - fprintf(outfile, "\n"); - } - - if (last_ctype != 0) - { - const char *caseless = - ((FLD(compiled_code, flags) & PCRE2_LASTCASELESS) == 0)? - "" : " (caseless)"; - if (PRINTOK(last_cunit)) - fprintf(outfile, "Last code unit = \'%c\'%s\n", last_cunit, caseless); - else - { - fprintf(outfile, "Last code unit = "); - pchar(last_cunit, FALSE, outfile); - fprintf(outfile, "%s\n", caseless); - } - } - - if ((FLD(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 (FLD(compiled_code, executable_jit) != NULL) - fprintf(outfile, "JIT compilation was successful\n"); - else - { - fprintf(outfile, "JIT compilation was not successful"); - if (jitrc != 0 && !print_error_message(jitrc, " (", ")")) - return PR_ABEND; - fprintf(outfile, "\n"); - } -#else - fprintf(outfile, "JIT support is not available in this version of PCRE2\n"); -#endif - } + *c1 = CHAR_p; + *c2 = CHAR_p; + *num_write = 2; } -if ((pat_patctl.control & CTL_CALLOUT_INFO) != 0) +/* Use 'l' -> 'Mn' or 'MN' as an expanding ligature, like 'fi' -> 'Fi' -> +'FI'. */ +else if (*c1 == CHAR_l && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) { - int errorcode; - PCRE2_CALLOUT_ENUMERATE(errorcode, callout_callback, 0); - if (errorcode != 0) - { - fprintf(outfile, "Callout enumerate failed: error %d: ", errorcode); - if (errorcode < 0 && !print_error_message(errorcode, "", "\n")) - return PR_ABEND; - return PR_SKIP; - } + *c1 = CHAR_M; + *c2 = (to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST)? CHAR_n : CHAR_N; + *num_write = 2; } +else if (*c1 == CHAR_M && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_m; +else if (*c1 == CHAR_m && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_M; +else if (*c1 == CHAR_N && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_n; +else if (*c1 == CHAR_n && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_N; -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) -{ -fprintf(outfile, "%s failed: error %d: ", msg, rc); -return print_error_message(rc, "", "\n"); -} - - - -/************************************************* -* Open file for save/load commands * -*************************************************/ - -/* This function decodes the file name and opens the file. - -Arguments: - buffptr point after the #command - mode open mode - fptr points to the FILE variable - name name of # command - -Returns: PR_OK or PR_ABEND -*/ - -static int -open_file(uint8_t *buffptr, const char *mode, FILE **fptr, const char *name) -{ -char *endf; -char *filename = (char *)buffptr; -while (isspace(*filename)) filename++; -endf = filename + strlen8(filename); -while (endf > filename && isspace(endf[-1])) endf--; - -if (endf == filename) - { - fprintf(outfile, "** File name expected after %s\n", name); - return PR_ABEND; - } +/* An example of a context-dependent mapping, the Greek Sigma. It lowercases +depending on the following character. Use 'c'/'k' -> 'K'. */ +else if ((*c1 == CHAR_c || *c1 == CHAR_k) && + to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_K; +else if (*c1 == CHAR_K && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = (num_in == 1 || *c2 == CHAR_SPACE)? CHAR_c : CHAR_k; -*endf = 0; -*fptr = fopen((const char *)filename, mode); -if (*fptr == NULL) +/* An example of a context-dependent multi mapping, the Dutch IJ. When those +letters appear together, they titlecase 'ij' (l) <-> 'IJ' (t) <-> 'IJ' (u). +Namely, English titlecasing of 'ijnssel' would be 'Ijnssel' (just uppercase the +first letter), but the Dutch rule is 'IJnssel'. */ +else if (num_in == 2 && (*c1 == CHAR_i || *c1 == CHAR_I) && + (*c2 == CHAR_j || *c2 == CHAR_J) && + to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST) { - fprintf(outfile, "** Failed to open \"%s\": %s\n", filename, strerror(errno)); - return PR_ABEND; + *c1 = CHAR_I; + *c2 = CHAR_J; + *num_read = 2; + *num_write = 2; } +else if (*c1 == CHAR_i && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_I; +else if (*c1 == CHAR_I && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_i; +else if (*c1 == CHAR_j && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_J; +else if (*c1 == CHAR_J && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) + *c1 = CHAR_j; -return PR_OK; +return TRUE; } /************************************************* -* Process command line * +* Show an entire ovector * *************************************************/ -/* 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. +/* This function is called after partial matching or match failure, when the +"allvector" modifier is set. It is a means of checking the contents of the +entire ovector, to ensure no modification of fields that should be unchanged. -Arguments: none +Arguments: + ovector points to the ovector + oveccount number of pairs -Returns: PR_OK continue processing next line - PR_SKIP skip to a blank line - PR_ABEND abort the pcre2test run +Returns: nothing */ -static int -process_command(void) +static void +show_ovector(PCRE2_SIZE *ovector, uint32_t oveccount) { -FILE *f; -PCRE2_SIZE serial_size; -size_t i; -int rc, cmd, cmdlen, yield; -uint16_t first_listed_newline; -const char *cmdname; -uint8_t *argptr, *serial; - -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 && - isspace(buffer[cmdlen+1])) - { - cmd = cmdlist[i].value; - break; - } - } - -argptr = buffer + cmdlen + 1; - -if (restrict_for_perl_test && cmd != CMD_PATTERN && cmd != CMD_SUBJECT) - { - fprintf(outfile, "** #%s is not allowed after #perltest\n", cmdname); - return PR_ABEND; - } - -switch(cmd) +uint32_t i; +for (i = 0; i < 2*oveccount; i += 2) { - case CMD_UNKNOWN: - fprintf(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; + PCRE2_SIZE start = ovector[i]; + PCRE2_SIZE end = ovector[i+1]; - /* 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) - { - fprintf(outfile, "** Can't pop off an empty stack\n"); - return PR_SKIP; - } - memset(&pat_patctl, 0, sizeof(patctl)); /* Completely unset */ - if (!decode_modifiers(argptr, CTX_POPPAT, &pat_patctl, NULL)) - return PR_SKIP; - - if (cmd == CMD_POP) - { - SET(compiled_code, patstack[--patstacknext]); - } - else - { - PCRE2_CODE_COPY_FROM_VOID(compiled_code, patstack[patstacknext - 1]); - } - - if (pat_patctl.jit != 0) - { - PCRE2_JIT_COMPILE(jitrc, compiled_code, pat_patctl.jit); - } - if ((pat_patctl.control & CTL_MEMORY) != 0) show_memory_info(); - if ((pat_patctl.control2 & CTL2_FRAMESIZE) != 0) show_framesize(); - if ((pat_patctl.control & CTL_ANYINFO) != 0) - { - 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) - { - fprintf(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; - - PCRE2_SERIALIZE_ENCODE(rc, 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) - { - fprintf(outfile, "** Wrong return from fwrite()\n"); - fclose(f); - return PR_ABEND; - } - - fclose(f); - PCRE2_SERIALIZE_FREE(serial); - while(patstacknext > 0) - { - SET(compiled_code, patstack[--patstacknext]); - SUB1(pcre2_code_free, compiled_code); - } - SET(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) - { - fprintf(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) - { - fprintf(outfile, "** Wrong return from fread()\n"); - yield = PR_ABEND; - } - else - { - PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(rc, serial); - if (rc < 0) - { - if (!serial_error(rc, "Get number of codes")) yield = PR_ABEND; - } - else - { - if (rc + patstacknext > PATSTACKSIZE) - { - fprintf(outfile, "** Not enough space on pattern stack for %d pattern%s\n", - rc, (rc == 1)? "" : "s"); - rc = PATSTACKSIZE - patstacknext; - fprintf(outfile, "** Decoding %d pattern%s\n", rc, - (rc == 1)? "" : "s"); - } - PCRE2_SERIALIZE_DECODE(rc, 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) - { - (void)PCRE2_CONFIG(PCRE2_CONFIG_TABLES_LENGTH, &loadtables_length); - tables3 = malloc(loadtables_length); - } - - if (tables3 == NULL) - { - fprintf(outfile, "** Failed: malloc failed for #loadtables\n"); - yield = PR_ABEND; - } - else if (fread(tables3, 1, loadtables_length, f) != loadtables_length) - { - fprintf(outfile, "** Wrong return from fread()\n"); - yield = PR_ABEND; - } - - fclose(f); - 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 errorcode; -void *use_pat_context; -void *use_pbuffer = NULL; -uint32_t use_forbid_utf = forbid_utf; -PCRE2_SIZE patlen; -PCRE2_SIZE valgrind_access_length; -PCRE2_SIZE erroroffset; - -/* The perltest.sh script supports only / as a delimiter. */ - -if (restrict_for_perl_test && delimiter != '/') - { - fprintf(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. */ - -PATCTXCPY(pat_context, default_pat_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) - { - fprintf(outfile, "** Unexpected EOF\n"); - return PR_ABEND; - } - if (!INTERACTIVE(infile)) fprintf(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 (test_mode == PCRE8_MODE) - { - fprintf(outfile, "** The utf8_input modifier is not allowed in 8-bit mode\n"); - return PR_SKIP; - } - if (utf) - { - fprintf(outfile, "** The utf and utf8_input modifiers are mutually exclusive\n"); - return PR_SKIP; - } - } - -/* The convert and posix modifiers are mutually exclusive. */ - -if (pat_patctl.convert_type != CONVERT_UNSET && - (pat_patctl.control & CTL_POSIX) != 0) - { - fprintf(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(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 and for reflecting -in callouts. 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) - { - fprintf(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)) - { - fprintf(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) - { - fprintf(outfile, "** Odd number of digits in hex pattern\n"); - return PR_SKIP; - } - d = *pp; - if (!isxdigit(d)) - { - fprintf(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); - *pt++ = ((isdigit(c)? (c - '0') : (c - 'A' + 10)) << 4) + - (isdigit(d)? (d - '0') : (d - 'A' + 10)); - } - } - *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] == '{') - { - uint32_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)) - { - fprintf(outfile, "** Pattern repeat count too large\n"); - return PR_SKIP; - } - - i = (uint32_t)uli; - pe = (uint8_t *)endptr; - if (*pe == '}') - { - if (i == 0) - { - fprintf(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] != 0) - { - if (pat_patctl.tables_id != 0) - { - fprintf(outfile, "** 'Locale' and 'tables' must not both be set\n"); - return PR_SKIP; - } - if (setlocale(LC_CTYPE, (const char *)pat_patctl.locale) == NULL) - { - fprintf(outfile, "** Failed to set locale \"%s\"\n", pat_patctl.locale); - return PR_SKIP; - } - if (strcmp((const char *)pat_patctl.locale, (const char *)locale_name) != 0) - { - strcpy((char *)locale_name, (char *)pat_patctl.locale); - if (locale_tables != NULL) - { - PCRE2_MAKETABLES_FREE(general_context, (const void *)locale_tables); - } - PCRE2_MAKETABLES(locale_tables, 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) - { - fprintf(outfile, "** 'Tables = 3' is invalid: binary tables have not " - "been loaded\n"); - return PR_SKIP; - } - use_tables = tables3; - break; - - default: - fprintf(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) - { -#ifdef SUPPORT_PCRE2_8 - int rc; - int cflags = 0; - const char *msg = "** Ignored with POSIX interface:"; -#endif - - if (test_mode != PCRE8_MODE) - { - fprintf(outfile, "** The POSIX interface is available only in 8-bit mode\n"); - return PR_SKIP; - } - -#ifdef SUPPORT_PCRE2_8 - /* Check for features that the POSIX interface does not support. */ - - if (pat_patctl.locale[0] != 0) prmsg(&msg, "locale"); - if (pat_patctl.replacement[0] != 0) 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( - pat_patctl.options & (uint32_t)(~POSIX_SUPPORTED_COMPILE_OPTIONS), - msg, ""); - msg = ""; - } - - if ((FLD(pat_context, extra_options) & - (uint32_t)(~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS)) != 0) - { - show_compile_extra_options( - FLD(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( - 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 (FLD(pat_context, max_pattern_length) != PCRE2_UNSET) - prmsg(&msg, "max_pattern_length"); - if (FLD(pat_context, max_pattern_compiled_length) != PCRE2_UNSET) - prmsg(&msg, "max_pattern_compiled_length"); - if (FLD(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; - } - - rc = regcomp(&preg, (char *)pbuffer8, cflags); - - /* Compiling failed */ - - if (rc != 0) - { - size_t bsize, usize; - int psize; - - preg.re_pcre2_code = NULL; /* In case something was left in there */ - preg.re_match_data = NULL; - - bsize = (pat_patctl.regerror_buffsize != 0)? - pat_patctl.regerror_buffsize : pbuffer8_size; - if (bsize + 8 < pbuffer8_size) - memcpy(pbuffer8 + bsize, "DEADBEEF", 8); - usize = regerror(rc, &preg, (char *)pbuffer8, bsize); - - /* Inside regerror(), snprintf() is used. If the buffer is too small, some - versions of snprintf() put a zero byte at the end, but others do not. - Therefore, we print a maximum of one less than the size of the buffer. */ - - psize = (int)bsize - 1; - fprintf(outfile, "Failed: POSIX code %d: %.*s\n", rc, psize, pbuffer8); - if (usize > bsize) - { - fprintf(outfile, "** regerror() message truncated\n"); - if (memcmp(pbuffer8 + bsize, "DEADBEEF", 8) != 0) - fprintf(outfile, "** regerror() buffer overflow\n"); - } - 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) - { - fprintf(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 /* SUPPORT_PCRE2_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] != 0) - { - fprintf(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(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(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; - -#ifdef SUPPORT_PCRE2_16 -if (test_mode == PCRE16_MODE) errorcode = to16(pbuffer8, utf, &patlen); -#endif - -#ifdef SUPPORT_PCRE2_32 -if (test_mode == PCRE32_MODE) errorcode = to32(pbuffer8, utf, &patlen); -#endif - -switch(errorcode) - { - case -1: - fprintf(outfile, "** Failed: invalid UTF-8 string cannot be " - "converted to %d-bit string\n", (test_mode == PCRE16_MODE)? 16:32); - return PR_SKIP; - - case -2: - fprintf(outfile, "** Failed: character value greater than 0x10ffff " - "cannot be converted to UTF\n"); - return PR_SKIP; - - case -3: - fprintf(outfile, "** Failed: character value greater than 0xffff " - "cannot be converted to 16-bit in non-UTF mode\n"); - return PR_SKIP; - - default: - break; - } - -/* 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 rc; - int convert_return = PR_OK; - uint32_t convert_options = pat_patctl.convert_type; - void *converted_pattern; - PCRE2_SIZE converted_length; - - if (pat_patctl.convert_length != 0) - { - converted_length = pat_patctl.convert_length; - converted_pattern = malloc(converted_length * code_unit_size); - if (converted_pattern == NULL) - { - fprintf(outfile, "** Failed: malloc failed for converted pattern\n"); - return PR_SKIP; - } - } - 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; - - CONCTXCPY(con_context, default_con_context); - - if (pat_patctl.convert_glob_escape != 0) - { - uint32_t escape = (pat_patctl.convert_glob_escape == '0')? 0 : - pat_patctl.convert_glob_escape; - PCRE2_SET_GLOB_ESCAPE(rc, con_context, escape); - if (rc != 0) - { - fprintf(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) - { - PCRE2_SET_GLOB_SEPARATOR(rc, con_context, pat_patctl.convert_glob_separator); - if (rc != 0) - { - fprintf(outfile, "** Invalid glob separator '%c'\n", - pat_patctl.convert_glob_separator); - convert_return = PR_SKIP; - goto CONVERT_FINISH; - } - } - - PCRE2_PATTERN_CONVERT(rc, pbuffer, patlen, convert_options, - &converted_pattern, &converted_length, con_context); - - if (rc != 0) - { - fprintf(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 - { - BOOL toolong; - PCHARSV(converted_pattern, 0, converted_length, utf, outfile); - fprintf(outfile, "\n"); - - if (test_mode == PCRE8_MODE) - toolong = (converted_length + 1 > pbuffer8_size); - else if (test_mode == PCRE16_MODE) - toolong = (2*(converted_length + 1) > pbuffer8_size); - else /* 32-bit */ - toolong = (4*(converted_length + 1) > pbuffer8_size); - - if (toolong) - { - fprintf(outfile, "** Pattern conversion is too long for the buffer\n"); - convert_return = PR_SKIP; - } - else - { - CONVERT_COPY(pbuffer, converted_pattern, converted_length + 1); - patlen = converted_length; - } - } - - /* Free the converted pattern. */ - - CONVERT_FINISH: - if (pat_patctl.convert_length != 0) - 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. */ - -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 -#ifdef SUPPORT_PCRE2_8 -if (test_mode == PCRE8_MODE && pbuffer8 != NULL) - { - VALGRIND_MAKE_MEM_NOACCESS(pbuffer8 + valgrind_access_length, - pbuffer8_size - valgrind_access_length); - } -#endif -#ifdef SUPPORT_PCRE2_16 -if (test_mode == PCRE16_MODE && pbuffer16 != NULL) - { - VALGRIND_MAKE_MEM_NOACCESS(pbuffer16 + valgrind_access_length, - pbuffer16_size - valgrind_access_length*sizeof(uint16_t)); - } -#endif -#ifdef SUPPORT_PCRE2_32 -if (test_mode == PCRE32_MODE && pbuffer32 != NULL) - { - VALGRIND_MAKE_MEM_NOACCESS(pbuffer32 + valgrind_access_length, - pbuffer32_size - valgrind_access_length*sizeof(uint32_t)); - } -#endif -#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) - { - SETFLD(pat_context, newline_convention, 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 : PTR(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 leave it as NULL if requested. */ - -if ((pat_patctl.control2 & CTL2_NULL_PATTERN) == 0) - { -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) use_pbuffer = pbuffer8; -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) use_pbuffer = pbuffer16; -#endif -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) use_pbuffer = pbuffer32; -#endif - } - -/* 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(); - PCRE2_COMPILE(compiled_code, use_pbuffer, patlen, - pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, - use_pat_context); - time_taken += clock() - start_time; - if (TEST(compiled_code, !=, NULL)) - { SUB1(pcre2_code_free, compiled_code); } - } - total_compile_time += time_taken; - fprintf(outfile, "Compile time %8.4f microseconds\n", - ((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit); - } - -/* A final compile that is used "for real". */ - -PCRE2_COMPILE(compiled_code, use_pbuffer, patlen, - pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, use_pat_context); - -/* If valgrind is supported, mark the pbuffer as accessible again. The 16-bit -and 32-bit buffers can be marked completely undefined, but we must leave the -pattern in the 8-bit buffer defined because it may be read from a callout -during matching. */ - -#ifdef SUPPORT_VALGRIND -#ifdef SUPPORT_PCRE2_8 -if (test_mode == PCRE8_MODE) - { - VALGRIND_MAKE_MEM_UNDEFINED(pbuffer8 + valgrind_access_length, - pbuffer8_size - valgrind_access_length); - } -#endif -#ifdef SUPPORT_PCRE2_16 -if (test_mode == PCRE16_MODE) - { - VALGRIND_MAKE_MEM_UNDEFINED(pbuffer16, pbuffer16_size); - } -#endif -#ifdef SUPPORT_PCRE2_32 -if (test_mode == PCRE32_MODE) - { - VALGRIND_MAKE_MEM_UNDEFINED(pbuffer32, pbuffer32_size); - } -#endif -#endif - -/* Call the JIT compiler if requested. When timing, 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 (TEST(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; - SUB1(pcre2_code_free, compiled_code); - PCRE2_COMPILE(compiled_code, use_pbuffer, patlen, - pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset, - use_pat_context); - start_time = clock(); - PCRE2_JIT_COMPILE(jitrc, compiled_code, pat_patctl.jit); - time_taken += clock() - start_time; - if (jitrc != 0) - { - fprintf(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) - fprintf(outfile, "JIT compile %8.4f microseconds\n", - ((1000000 / CLOCKS_PER_SEC) * (double)time_taken) / timeit); - } - else - { - PCRE2_JIT_COMPILE(jitrc, compiled_code, pat_patctl.jit); - if (jitrc != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0) - { - fprintf(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 (TEST(compiled_code, ==, NULL)) - { - fprintf(outfile, "Failed: error %d at offset %d: ", errorcode, - (int)erroroffset); - if (!print_error_message(errorcode, "", "\n")) 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 ((FLD(compiled_code, flags) & PCRE2_HASBKPORX) != 0) - { - fprintf(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) - { - SETFLD(compiled_code, flags, FLD(compiled_code, flags) | PCRE2_NL_SET); - } - -/* Output code size and other information if requested. */ - -if ((pat_patctl.control & CTL_MEMORY) != 0) show_memory_info(); -if ((pat_patctl.control2 & CTL2_FRAMESIZE) != 0) show_framesize(); -if ((pat_patctl.control & CTL_ANYINFO) != 0) - { - int 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) - { - fprintf(outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE); - return PR_ABEND; - } - patstack[patstacknext++] = PTR(compiled_code); - SET(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) - { - fprintf(outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE); - return PR_ABEND; - } - if ((pat_patctl.control & CTL_PUSHCOPY) != 0) - { - PCRE2_CODE_COPY_TO_VOID(patstack[patstacknext++], compiled_code); - } - else - { - PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(patstack[patstacknext++], - compiled_code); } - } - -return PR_OK; -} - - - -/************************************************* -* 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(uint8_t *pp, PCRE2_SIZE ulen, int errnumber, const char *msg) -{ -int capcount; -uint32_t min = 0; -uint32_t mid = 64; -uint32_t max = UINT32_MAX; - -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); - -#ifdef SUPPORT_PCRE2_8 - if (code_unit_size == 1) - { - match_data8->memctl.free(match_data8->heapframes, - match_data8->memctl.memory_data); - match_data8->heapframes = NULL; - match_data8->heapframes_size = 0; - } -#endif - -#ifdef SUPPORT_PCRE2_16 - if (code_unit_size == 2) - { - match_data16->memctl.free(match_data16->heapframes, - match_data16->memctl.memory_data); - match_data16->heapframes = NULL; - match_data16->heapframes_size = 0; - } -#endif - -#ifdef SUPPORT_PCRE2_32 - if (code_unit_size == 4) - { - match_data32->memctl.free(match_data32->heapframes, - match_data32->memctl.memory_data); - match_data32->heapframes = NULL; - match_data32->heapframes_size = 0; - } -#endif - } - - /* 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 */ - - 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 */ - PCRE2_DFA_MATCH(capcount, compiled_code, pp, ulen, dat_datctl.offset, - dat_datctl.options, match_data, - PTR(dat_context), dfa_workspace, DFA_WS_DIMENSION); - } - - else if ((pat_patctl.control & CTL_JITFAST) != 0) - PCRE2_JIT_MATCH(capcount, compiled_code, pp, ulen, dat_datctl.offset, - dat_datctl.options, match_data, PTR(dat_context)); - - else - { - PCRE2_MATCH(capcount, compiled_code, pp, ulen, dat_datctl.offset, - dat_datctl.options, match_data, PTR(dat_context)); - } - - if (capcount == errnumber) - { - if ((mid & 0x80000000u) != 0) - { - fprintf(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. The substitute callout block is -identical for all code unit widths, so we just pick one. - -Arguments: - scb pointer to substitute callout block - data_ptr callout data - -Returns: nothing -*/ - -static int -substitute_callout_function(pcre2_substitute_callout_block_8 *scb, - void *data_ptr) -{ -int yield = 0; -BOOL utf = (FLD(compiled_code, overall_options) & PCRE2_UTF) != 0; -(void)data_ptr; /* Not used */ - -fprintf(outfile, "%2d(%d) Old %" SIZ_FORM " %" SIZ_FORM " \"", - scb->subscount, scb->oveccount, - scb->ovector[0], scb->ovector[1]); - -PCHARSV(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]); - -PCHARSV(scb->output, scb->output_offsets[0], - scb->output_offsets[1] - scb->output_offsets[0], utf, outfile); - -if (scb->subscount == dat_datctl.substitute_stop) - { - yield = -1; - fprintf(outfile, " STOPPED"); - } -else if (scb->subscount == dat_datctl.substitute_skip) - { - yield = +1; - fprintf(outfile, " SKIPPED"); - } - -fprintf(outfile, "\"\n"); -return yield; -} - - -/************************************************* -* Substitute case callout function * -*************************************************/ - -/* Function to implement our test-only custom case mappings. -To ease implementation, we only work in the ASCII range (so that we don't need -to read & write UTF sequences). -However, we aim to implement case mappings which fairly well represent the range -of interesting behaviours that exist for Unicode codepoints. */ - -static BOOL -case_transform(int to_case, int num_in, int *num_read, int *num_write, - uint32_t *c1, uint32_t *c2) -{ -/* Let's have one character which aborts the substitution. */ -if (*c1 == '!') return FALSE; - -/* Default behaviour is to read one character, and write back that same one -character (treating all characters as "uncased"). */ -*num_read = *num_write = 1; - -/* Add a normal case pair 'a' (l) <-> 'B' (t,u). Standard ASCII letter -behaviour, but with switched letters for testing. */ -if (*c1 == 'a' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'B'; -else if (*c1 == 'B' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'a'; - -/* Add a titlecased triplet 'd' (l) <-> 'D' (t) <-> 'Z' (u). Example: the -'dz'/'Dz'/'DZ' ligature character ("Latin Small Letter DZ" <-> "Latin Capital -Letter D with Small Letter Z" <-> "Latin Capital Letter DZ"). */ -else if (*c1 == 'd' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = (to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST)? 'D' : 'Z'; -else if (*c1 == 'D' && to_case != PCRE2_SUBSTITUTE_CASE_TITLE_FIRST) - *c1 = (to_case == PCRE2_SUBSTITUTE_CASE_LOWER)? 'd' : 'Z'; -else if (*c1 == 'Z' && to_case != PCRE2_SUBSTITUTE_CASE_UPPER) - *c1 = (to_case == PCRE2_SUBSTITUTE_CASE_LOWER)? 'd' : 'D'; - -/* Expands when uppercased. Example: Esszet 'f' <-> 'SS'. */ -else if (*c1 == 'f' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - { - *c1 = 'S'; - *c2 = 'S'; - *num_write = 2; - } -else if (*c1 == 's' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'S'; -else if (*c1 == 'S' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 's'; - -/* Expanding and contracting characters, 'o' <-> 'OO'. You can get this purely -due to UTF-8 encoding length, for example uppercase Omega (3 bytes in UTF-8) -lowercases to 2 bytes in UTF-8. */ -else if (num_in == 2 && *c1 == 'O' && *c2 == 'O' && - to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - { - *c1 = 'o'; - *num_read = 2; - } -else if (*c1 == 'o' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - { - *c1 = 'O'; - *c2 = 'O'; - *num_write = 2; - } -else if (num_in == 2 && *c1 == 'p' && *c2 == 'p' && - to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - { - *c1 = 'P'; - *num_read = 2; - } -else if (*c1 == 'P' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - { - *c1 = 'p'; - *c2 = 'p'; - *num_write = 2; - } - -/* Use 'l' -> 'Mn' or 'MN' as an expanding ligature, like 'fi' -> 'Fi' -> -'FI'. */ -else if (*c1 == 'l' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - { - *c1 = 'M'; - *c2 = (to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST)? 'n' : 'N'; - *num_write = 2; - } -else if (*c1 == 'M' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'm'; -else if (*c1 == 'm' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'M'; -else if (*c1 == 'N' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'n'; -else if (*c1 == 'n' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'N'; - -/* An example of a context-dependent mapping, the Greek Sigma. It lowercases -depending on the following character. Use 'c'/'k' -> 'K'. */ -else if ((*c1 == 'c' || *c1 == 'k') && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'K'; -else if (*c1 == 'K' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = (num_in == 1 || *c2 == ' ')? 'c' : 'k'; - -/* An example of a context-dependent multi mapping, the Dutch IJ. When those -letters appear together, they titlecase 'ij' (l) <-> 'IJ' (t) <-> 'IJ' (u). -Namely, English titlecasing of 'ijnssel' would be 'Ijnssel' (just uppercase the -first letter), but the Dutch rule is 'IJnssel'. */ -else if (num_in == 2 && (*c1 == 'i' || *c1 == 'I') && - (*c2 == 'j' || *c2 == 'J') && - to_case == PCRE2_SUBSTITUTE_CASE_TITLE_FIRST) - { - *c1 = 'I'; - *c2 = 'J'; - *num_read = 2; - *num_write = 2; - } -else if (*c1 == 'i' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'I'; -else if (*c1 == 'I' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'i'; -else if (*c1 == 'j' && to_case != PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'J'; -else if (*c1 == 'J' && to_case == PCRE2_SUBSTITUTE_CASE_LOWER) - *c1 = 'j'; - -return TRUE; -} - -/* 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 -*/ - -#define substitute_case_callout_function(BITS) \ -static PCRE2_SIZE \ -G(substitute_case_callout_function,BITS)( \ - G(PCRE2_SPTR,BITS) input, PCRE2_SIZE input_len, \ - G(PCRE2_UCHAR,BITS) *output, PCRE2_SIZE output_cap, \ - int to_case, void *data_ptr) \ -{ \ -G(PCRE2_UCHAR,BITS) buf[16]; \ -G(PCRE2_SPTR,BITS) input_copy; \ -PCRE2_SIZE written = 0; \ -\ -(void)data_ptr; /* Not used */ \ -\ -if (input_len > sizeof(buf)/sizeof(*buf)) \ - { \ - G(PCRE2_UCHAR,BITS) *input_buf = malloc( \ - input_len * sizeof(G(PCRE2_UCHAR,BITS))); \ - if (input_buf == NULL) return ~(PCRE2_SIZE)0; \ - memcpy(input_buf, input, input_len * sizeof(G(PCRE2_UCHAR,BITS))); \ - input_copy = input_buf; \ - } \ -else \ - { \ - memcpy(buf, input, input_len * sizeof(G(PCRE2_UCHAR,BITS))); \ - 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((G(PCRE2_UCHAR,BITS) *)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, \ - output_cap * sizeof(G(PCRE2_UCHAR,BITS))); \ -\ -return written; \ -} - -#if defined SUPPORT_PCRE2_8 -substitute_case_callout_function(8) -#endif -#if defined SUPPORT_PCRE2_16 -substitute_case_callout_function(16) -#endif -#if defined SUPPORT_PCRE2_32 -substitute_case_callout_function(32) -#endif - - -/************************************************* -* 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_8 *cb, void *callout_data_ptr) -{ -FILE *f, *fdefault; -uint32_t i, pre_start, post_start, subject_length; -PCRE2_SIZE current_position; -BOOL utf = (FLD(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; - -/* 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"); - /* 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 = CODE_UNIT(cb->callout_string, -1); - fprintf(outfile, "Callout (%" SIZ_FORM "): %c", - cb->callout_string_offset, delimiter); - PCHARSV(cb->callout_string, 0, - 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", 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 - { - PCHARSV(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. */ - - PCHARS(pre_start, cb->subject, 0, 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. */ - - PCHARS(post_start, cb->subject, cb->start_match, - current_position - cb->start_match, utf, f); - - /* Print from the current position to the end. */ - - PCHARSV(cb->subject, current_position, cb->subject_length - current_position, - utf, f); - - /* Calculate the total subject printed length (no print). */ - - PCHARS(subject_length, cb->subject, 0, 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) - fprintf(outfile, "%.*s", (int)(cb->next_item_length), - pbuffer8 + cb->pattern_position); - else - fprintf(outfile, "End of pattern"); - - fprintf(outfile, "\n"); - } - -first_callout = FALSE; - -/* Show any mark info */ - -if (cb->mark != last_callout_mark) - { - if (cb->mark == NULL) - fprintf(outfile, "Latest Mark: \n"); - else - { - fprintf(outfile, "Latest Mark: "); - PCHARSV(cb->mark, -1, -1, utf, outfile); - putc('\n', outfile); - } - last_callout_mark = cb->mark; - } - -/* Show callout data */ - -if (callout_data_ptr != NULL) - { - int callout_data = *((int32_t *)callout_data_ptr); - if (callout_data != 0) - { - fprintf(outfile, "Callout data = %d\n", callout_data); - return callout_data; - } - } - -/* Keep count and give the appropriate return code */ - -callout_count++; - -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; - PCRE2_SIZE length, length2; - uint32_t copybuffer[256]; - uint32_t n = (uint32_t)(dat_datctl.copy_numbers[i]); - length = sizeof(copybuffer)/code_unit_size; - PCRE2_SUBSTRING_COPY_BYNUMBER(rc, match_data, n, copybuffer, &length); - if (rc < 0) - { - fprintf(outfile, "Copy substring %d failed (%d): ", n, rc); - if (!print_error_message(rc, "", "\n")) return FALSE; - } - else - { - PCRE2_SUBSTRING_LENGTH_BYNUMBER(rc, match_data, n, &length2); - if (rc < 0) - { - fprintf(outfile, "Get substring %d length failed (%d): ", n, rc); - if (!print_error_message(rc, "", "\n")) return FALSE; - } - else if (length2 != length) - { - fprintf(outfile, "Mismatched substring lengths: %" - SIZ_FORM " %" SIZ_FORM "\n", length, length2); - } - fprintf(outfile, "%2dC ", n); - PCHARSV(copybuffer, 0, length, utf, outfile); - fprintf(outfile, " (%" SIZ_FORM ")\n", length); - } - } - -/* Test copy strings by name */ - -nptr = dat_datctl.copy_names; -for (;;) - { - int rc; - int groupnumber; - PCRE2_SIZE length, length2; - uint32_t copybuffer[256]; - int namelen = strlen((const char *)nptr); -#if defined SUPPORT_PCRE2_16 || defined SUPPORT_PCRE2_32 - PCRE2_SIZE cnl = namelen; -#endif - if (namelen == 0) break; - -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) strcpy((char *)pbuffer8, (char *)nptr); -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE)(void)to16(nptr, utf, &cnl); -#endif -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE)(void)to32(nptr, utf, &cnl); -#endif - - PCRE2_SUBSTRING_NUMBER_FROM_NAME(groupnumber, compiled_code, pbuffer); - if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING) - fprintf(outfile, "Number not found for group \"%s\"\n", nptr); - - length = sizeof(copybuffer)/code_unit_size; - PCRE2_SUBSTRING_COPY_BYNAME(rc, match_data, pbuffer, copybuffer, &length); - if (rc < 0) - { - fprintf(outfile, "Copy substring \"%s\" failed (%d): ", nptr, rc); - if (!print_error_message(rc, "", "\n")) return FALSE; - } - else - { - PCRE2_SUBSTRING_LENGTH_BYNAME(rc, match_data, pbuffer, &length2); - if (rc < 0) - { - fprintf(outfile, "Get substring \"%s\" length failed (%d): ", nptr, rc); - if (!print_error_message(rc, "", "\n")) return FALSE; - } - else if (length2 != length) - { - fprintf(outfile, "Mismatched substring lengths: %" - SIZ_FORM " %" SIZ_FORM "\n", length, length2); - } - fprintf(outfile, " C "); - PCHARSV(copybuffer, 0, 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"); - } - 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; - void *gotbuffer; - uint32_t n = (uint32_t)(dat_datctl.get_numbers[i]); - PCRE2_SUBSTRING_GET_BYNUMBER(rc, match_data, n, &gotbuffer, &length); - if (rc < 0) - { - fprintf(outfile, "Get substring %d failed (%d): ", n, rc); - if (!print_error_message(rc, "", "\n")) return FALSE; - } - else - { - fprintf(outfile, "%2dG ", n); - PCHARSV(gotbuffer, 0, 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; - void *gotbuffer; - int rc; - int groupnumber; - int namelen = strlen((const char *)nptr); -#if defined SUPPORT_PCRE2_16 || defined SUPPORT_PCRE2_32 - PCRE2_SIZE cnl = namelen; -#endif - if (namelen == 0) break; - -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) strcpy((char *)pbuffer8, (char *)nptr); -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE)(void)to16(nptr, utf, &cnl); -#endif -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE)(void)to32(nptr, utf, &cnl); -#endif - - PCRE2_SUBSTRING_NUMBER_FROM_NAME(groupnumber, compiled_code, pbuffer); - if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING) - fprintf(outfile, "Number not found for group \"%s\"\n", nptr); - - PCRE2_SUBSTRING_GET_BYNAME(rc, match_data, pbuffer, &gotbuffer, &length); - if (rc < 0) - { - fprintf(outfile, "Get substring \"%s\" failed (%d): ", nptr, rc); - if (!print_error_message(rc, "", "\n")) return FALSE; - } - else - { - fprintf(outfile, " G "); - PCHARSV(gotbuffer, 0, 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; - void **stringlist; - PCRE2_SIZE *lengths; - PCRE2_SUBSTRING_LIST_GET(rc, match_data, &stringlist, &lengths); - if (rc < 0) - { - fprintf(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); - PCHARSV(stringlist[i], 0, lengths[i], utf, outfile); - putc('\n', outfile); - } - if (stringlist[i] != NULL) - fprintf(outfile, "string list not terminated by NULL\n"); - PCRE2_SUBSTRING_LIST_FREE(stringlist); - } - } - -return TRUE; -} - - - -/************************************************* -* Show an entire ovector * -*************************************************/ - -/* This function is called after partial matching or match failure, when the -"allvector" modifier is set. It is a means of checking the contents of the -entire ovector, to ensure no modification of fields that should be unchanged. - -Arguments: - ovector points to the ovector - oveccount number of pairs - -Returns: nothing -*/ - -static void -show_ovector(PCRE2_SIZE *ovector, uint32_t oveccount) -{ -uint32_t i; -for (i = 0; i < 2*oveccount; i += 2) - { - PCRE2_SIZE start = ovector[i]; - PCRE2_SIZE end = ovector[i+1]; - - fprintf(outfile, "%2d: ", i/2); - if (start == PCRE2_UNSET && end == PCRE2_UNSET) - fprintf(outfile, "\n"); - else if (start == JUNK_OFFSET && end == JUNK_OFFSET) - fprintf(outfile, "\n"); - else - fprintf(outfile, "%ld %ld\n", (unsigned long int)start, - (unsigned long int)end); - } -} - - -/************************************************* -* 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 len, ulen, arg_ulen; -uint32_t gmatched; -uint32_t c, k; -uint32_t g_notempty = 0; -uint8_t *p, *pp, *start_rep; -size_t needlen; -void *use_dat_context; -BOOL utf; -BOOL subject_literal; - -PCRE2_SIZE *ovector; -PCRE2_SIZE ovecsave[3]; -uint32_t oveccount; - -#ifdef SUPPORT_PCRE2_8 -uint8_t *q8 = NULL; -#endif -#ifdef SUPPORT_PCRE2_16 -uint16_t *q16 = NULL; -#endif -#ifdef SUPPORT_PCRE2_32 -uint32_t *q32 = NULL; -#endif - -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. */ - -DATCTXCPY(dat_context, default_dat_context); -memcpy(&dat_datctl, &def_datctl, sizeof(datctl)); -dat_datctl.control |= (pat_patctl.control & CTL_ALLPD); -dat_datctl.control2 |= (pat_patctl.control2 & CTL2_ALLPD); -strcpy((char *)dat_datctl.replacement, (char *)pat_patctl.replacement); -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. */ - -#ifdef SUPPORT_PCRE2_8 -utf = ((((pat_patctl.control & CTL_POSIX) != 0)? - ((pcre2_real_code_8 *)preg.re_pcre2_code)->overall_options : - FLD(compiled_code, overall_options)) & PCRE2_UTF) != 0; -#else -utf = (FLD(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 *q; - uint32_t cc; - int n = 1; - uint8_t *q_end = p + len; - - for (q = p; n > 0 && *q; q += n) n = utf82ord(q, q_end, &cc); - if (n <= 0) - { - fprintf(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 = (len+1) * code_unit_size; -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) - { - fprintf(stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n", dbuffer_size); - exit(1); - } - } -SETCASTPTR(q, dbuffer); /* Sets q8, q16, or q32, as appropriate. */ - -/* 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; - enum force_encoding encoding = FORCE_NONE; - - /* ] may mark the end of a replicated sequence */ - - if (c == ']' && start_rep != NULL) - { - PCRE2_SIZE d; - long li; - char *endptr; - - if (*p++ != '{') - { - fprintf(outfile, "** Expected '{' after \\[....]\n"); - return PR_OK; - } - - li = strtol((const char *)p, &endptr, 10); - if (S32OVERFLOW(li)) - { - fprintf(outfile, "** Repeat count too large\n"); - return PR_OK; - } - i = (int)li; - - p = (uint8_t *)endptr; - if (*p++ != '}') - { - fprintf(outfile, "** Expected '}' after \\[...]{...\n"); - return PR_OK; - } - - if (i-- <= 0) - { - fprintf(outfile, "** Zero or negative repeat not allowed\n"); - return PR_OK; - } - - replen = CAST8VAR(q) - start_rep; - if (PRIV(ckd_smul)(&d, replen, i)) - { - fprintf(outfile, "** Expanded content too large\n"); - return PR_OK; - } - needlen += d; - - if (needlen >= dbuffer_size) - { - size_t qoffset = CAST8VAR(q) - dbuffer; - size_t rep_offset = 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) - { - fprintf(stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n", - dbuffer_size); - exit(1); - } - SETCASTPTR(q, dbuffer + qoffset); - start_rep = dbuffer + rep_offset; - } - - while (i-- > 0) - { - memcpy(CAST8VAR(q), start_rep, replen); - SETPLUS(q, replen/code_unit_size); - } - - 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 (test_mode == PCRE32_MODE && c == 0xff && *p != 0) - { - topbit = 0x80000000; - c = *p++; - } - 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 = CHAR_BEL; break; - case 'b': c = '\b'; break; - case 'e': c = CHAR_ESC; break; - 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 && isdigit(*p) && *p < '8') - c = c * 8 + (*p++ - '0'); - - 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) - { - fprintf(outfile, "** \\o{ escape too large\n"); - return PR_OK; - } - else c = c * 8 + (*pt - '0'); - } - if (i == 0 || *pt != '}') - { - fprintf(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) - { - fprintf(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)); - } - if (i == 0 || *pt != '}') - { - fprintf(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++; - } -#if defined SUPPORT_PCRE2_8 - if (utf && (test_mode == PCRE8_MODE)) encoding = FORCE_RAW; -#endif - } - break; - - case 'N': - 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; - } - } - fprintf(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) - { - fprintf(outfile, "** Nested replication is not supported\n"); - return PR_OK; - } - start_rep = CAST8VAR(q); - continue; - - default: - if (isalnum(c)) - { - fprintf(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. */ - -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) - { - if (encoding == FORCE_RAW || !(utf || encoding == FORCE_UTF)) - { - if (c > 0xffu) - { - fprintf(outfile, "** Character \\x{%x} is greater than 255 " - "and UTF-8 mode is not enabled.\n", c); - fprintf(outfile, "** Truncation will probably give the wrong " - "result.\n"); - } - *q8++ = (uint8_t)c; - } - else - { - if (c > 0x7fffffff) - { - fprintf(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) - fprintf(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); - q8 += ord2utf8(c, q8); - } - } -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) - { - /* 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) - { - fprintf(outfile, "** Character \\x{%x} is greater than 0xffff " - "and UTF-16 mode is not enabled.\n", c); - fprintf(outfile, "** Truncation will probably give the wrong " - "result.\n"); - } - *q16++ = (uint16_t)c; - } - else - { - if (c > MAX_UTF_CODE_POINT) - { - fprintf(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; - *q16++ = 0xD800 | (c >> 10); - *q16++ = 0xDC00 | (c & 0x3ff); - } - else - { - if (encoding == FORCE_UTF && 0xe000u > c && c >= 0xd800u) - fprintf(outfile, "** Warning: character \\N{U+%x} is a surrogate " - "and should not be encoded as UTF-16\n", c); - *q16++ = c; - } - } - } -#endif -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) - { - if (encoding == FORCE_UTF && c > MAX_UTF_CODE_POINT) - fprintf(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); - *q32++ = c; - } -#endif - } - -ENDSTRING: -SET(*q, 0); -len = CASTVAR(uint8_t *, q) - dbuffer; /* Length in bytes */ -ulen = len/code_unit_size; /* 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(c, 0, "** Not allowed together:"); - fprintf(outfile, "\n"); - return PR_OK; - } - } - -if (dat_datctl.replacement[0] != 0) - { - if ((dat_datctl.control2 & CTL2_SUBSTITUTE_CALLOUT) != 0 && - (dat_datctl.control & CTL_NULLCONTEXT) != 0) - { - fprintf(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) - { - fprintf(outfile, "** Replacement case callouts are not supported with null_context.\n"); - return PR_OK; - } - - if ((dat_datctl.control & CTL_ALLCAPTURES) != 0) - fprintf(outfile, "** Ignored with replacement text: allcaptures\n"); - } - -/* Warn for modifiers that are ignored for DFA. */ - -if ((dat_datctl.control & CTL_DFA) != 0) - { - if ((dat_datctl.control & CTL_ALLCAPTURES) != 0) - fprintf(outfile, "** Ignored for DFA matching: allcaptures\n"); - if ((dat_datctl.control2 & CTL2_HEAPFRAMES_SIZE) != 0) - fprintf(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 = code_unit_size * (((pat_patctl.control & CTL_POSIX) + - (dat_datctl.control & CTL_ZERO_TERMINATE) != 0)? 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 - -/* 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. */ - -#ifdef SUPPORT_PCRE2_8 -if ((pat_patctl.control & CTL_POSIX) != 0) - { - int rc; - int eflags = 0; - regmatch_t *pmatch = NULL; - 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) - { - fprintf(outfile, "%s", msg); - show_match_options(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(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) - { - fprintf(outfile, "** Failed to get memory for recording matching " - "information (size set = %du)\n", dat_datctl.oveccount); - return PR_OK; - } - } - - if (dat_datctl.startend[0] != CFORE_UNSET) - { - pmatch[0].rm_so = dat_datctl.startend[0]; - pmatch[0].rm_eo = (dat_datctl.startend[1] != 0)? - dat_datctl.startend[1] : 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) - { - (void)regerror(rc, &preg, (char *)pbuffer8, pbuffer8_size); - fprintf(outfile, "No match: POSIX code %d: %s\n", rc, pbuffer8); - } - 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; - fprintf(outfile, "Start of matched string is beyond its end - " - "displaying from end to start.\n"); - } - fprintf(outfile, "%2d: ", (int)i); - PCHARSV(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. */ - PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile); - fprintf(outfile, "\n"); } - } - } - } - free(pmatch); - return PR_OK; - } -#endif /* SUPPORT_PCRE2_8 */ - - /* Handle matching via the native interface. Check for consistency of -modifiers. */ - -if (dat_datctl.startend[0] != CFORE_UNSET) - fprintf(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 && - FLD(compiled_code, executable_jit) != NULL) - { - fprintf(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 : PTR(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) - fprintf(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); - PCRE2_JIT_STACK_CREATE(jit_stack, 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); - } - -/* 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); - PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(match_data, compiled_code, - general_context); - PCRE2_GET_OVECTOR_COUNT(max_oveccount, match_data); - } -else if (dat_datctl.oveccount <= max_oveccount) - { - SETFLD(match_data, oveccount, dat_datctl.oveccount); - } -else - { - max_oveccount = dat_datctl.oveccount; - PCRE2_MATCH_DATA_FREE(match_data); - PCRE2_MATCH_DATA_CREATE(match_data, max_oveccount, general_context); - } - -if (CASTVAR(void *, match_data) == NULL) - { - fprintf(outfile, "** Failed to get memory for recording matching " - "information (size requested: %d)\n", dat_datctl.oveccount); - max_oveccount = 0; - return PR_OK; - } - -ovector = FLD(match_data, ovector); -PCRE2_GET_OVECTOR_COUNT(oveccount, match_data); - -/* Replacement processing is ignored for DFA matching. */ - -if (dat_datctl.replacement[0] != 0 && (dat_datctl.control & CTL_DFA) != 0) - { - fprintf(outfile, "** Ignored for DFA matching: replace\n"); - dat_datctl.replacement[0] = 0; - } - -/* 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] != 0) - { - int rc; - uint8_t *pr; - uint8_t rbuffer[REPLACE_BUFFSIZE]; - uint8_t nbuffer[REPLACE_BUFFSIZE]; - uint8_t *rbptr; - uint32_t xoptions; - uint32_t emoption; /* External match option */ - PCRE2_SIZE j, rlen, nsize, erroroffset; - BOOL badutf = FALSE; - -#ifdef SUPPORT_PCRE2_8 - uint8_t *r8 = NULL; -#endif -#ifdef SUPPORT_PCRE2_16 - uint16_t *r16 = NULL; -#endif -#ifdef SUPPORT_PCRE2_32 - uint32_t *r32 = NULL; -#endif - - /* 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) - fprintf(outfile, "** Timing is not supported with replace: ignored\n"); - - if ((dat_datctl.control & CTL_ALTGLOBAL) != 0) - fprintf(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) - { - if ((pat_patctl.control & CTL_JITFAST) != 0) - { - PCRE2_JIT_MATCH(rc, compiled_code, pp, arg_ulen, dat_datctl.offset, - dat_datctl.options, match_data, use_dat_context); - } - else - { - PCRE2_MATCH(rc, 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); - - SETCASTPTR(r, rbuffer); /* Sets r8, r16, or r32, as appropriate. */ - pr = dat_datctl.replacement; - - /* If the replacement starts with '[]' we interpret that as length - value for the replacement buffer. */ - - nsize = REPLACE_BUFFSIZE/code_unit_size; - if (*pr == '[') - { - PCRE2_SIZE n = 0; - while ((c = *(++pr)) >= CHAR_0 && c <= CHAR_9) n = n * 10 + (c - CHAR_0); - if (*pr++ != ']') - { - fprintf(outfile, "Bad buffer size in replacement string\n"); - return PR_OK; - } - if (n > nsize) - { - fprintf(outfile, "Replacement buffer setting (%" SIZ_FORM ") is too " - "large (max %" SIZ_FORM ")\n", n, nsize); - return PR_OK; - } - nsize = n; - } - - /* Now copy the replacement string to a buffer of the appropriate width. No - escape processing is done for replacements. 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(pr, strlen((const char *)pr), &erroroffset); - - /* Not UTF or invalid UTF-8: just copy the code units. */ - - if (!utf || badutf) - { - while ((c = *pr++) != 0) - { -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) *r8++ = c; -#endif -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) *r16++ = c; -#endif -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) *r32++ = c; -#endif - } - } - - /* Valid UTF-8 replacement string */ - - else while ((c = *pr++) != 0) - { - if (HASUTF8EXTRALEN(c)) { GETUTF8INC(c, pr); } - -#ifdef SUPPORT_PCRE2_8 - if (test_mode == PCRE8_MODE) r8 += ord2utf8(c, r8); -#endif - -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) - { - if (c >= 0x10000u) - { - c-= 0x10000u; - *r16++ = 0xD800 | (c >> 10); - *r16++ = 0xDC00 | (c & 0x3ff); - } - else *r16++ = c; - } -#endif - -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) *r32++ = c; -#endif - } - - SET(*r, 0); - if ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0) - rlen = PCRE2_ZERO_TERMINATED; - else - rlen = (CASTVAR(uint8_t *, r) - rbuffer)/code_unit_size; - - 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_NULL(dat_context); /* No callout */ - } - - /* There is a special option to set the replacement to NULL in order to test - that case. */ - - rbptr = ((dat_datctl.control2 & CTL2_NULL_REPLACEMENT) == 0)? rbuffer : NULL; - - PCRE2_SUBSTITUTE(rc, compiled_code, pp, arg_ulen, dat_datctl.offset, - dat_datctl.options|xoptions, match_data, use_dat_context, - rbptr, rlen, nbuffer, &nsize); - - if (rc < 0) - { - fprintf(outfile, "Failed: error %d", rc); - if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET) - fprintf(outfile, " at offset %ld in replacement", (long int)nsize); - fprintf(outfile, ": "); - if (!print_error_message(rc, "", "")) return PR_ABEND; - if (rc == PCRE2_ERROR_NOMEMORY && - (xoptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0) - fprintf(outfile, ": %ld code units are needed", (long int)nsize); - } - else - { - fprintf(outfile, "%2d: ", rc); - PCHARSV(nbuffer, 0, 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 altglobal (or first time round -the loop), set an "unset" value for the previous match info. */ - -ovecsave[0] = ovecsave[1] = ovecsave[2] = PCRE2_UNSET; - -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; - - if ((dat_datctl.control & CTL_DFA) != 0) - { - if ((dat_datctl.options & PCRE2_DFA_RESTART) != 0) - { - fprintf(outfile, "Timing DFA restarts is not supported\n"); - return PR_OK; - } - if (dfa_workspace == NULL) - dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int)); - start_time = clock(); - for (i = 0; i < timeitm; i++) - { - PCRE2_DFA_MATCH(capcount, 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++) - { - PCRE2_JIT_MATCH(capcount, 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++) - { - PCRE2_MATCH(capcount, 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); - fprintf(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) - { - capcount = 0; /* This stops compiler warnings */ - (void)capcount; - - if ((dat_datctl.control & CTL_FINDLIMITS_NOHEAP) == 0 && - (FLD(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 (FLD(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) - { - fprintf(outfile, "Matched, but offsets vector is too small to show all matches\n"); - capcount = dat_datctl.oveccount; - } - } - - /* Otherwise just run a single match, setting up a callout if required (the - default). There is a copy of the pattern in pbuffer8 for use by callouts. */ - - else - { - if ((dat_datctl.control & CTL_CALLOUT_NONE) == 0) - { - PCRE2_SET_CALLOUT(dat_context, callout_function, - (void *)(&dat_datctl.callout_data)); - first_callout = TRUE; - last_callout_mark = NULL; - callout_count = 0; - } - else - { - PCRE2_SET_CALLOUT(dat_context, NULL, NULL); /* No callout */ - } - - /* Run a single DFA or NFA match. */ - - 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 */ - PCRE2_DFA_MATCH(capcount, 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) - { - fprintf(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) - PCRE2_JIT_MATCH(capcount, compiled_code, pp, arg_ulen, dat_datctl.offset, - dat_datctl.options | g_notempty, match_data, use_dat_context); - else - PCRE2_MATCH(capcount, compiled_code, pp, arg_ulen, dat_datctl.offset, - dat_datctl.options | g_notempty, match_data, use_dat_context); - if (capcount == 0) - { - fprintf(outfile, "Matched, but too many substrings\n"); - capcount = dat_datctl.oveccount; - } - } - } - - /* 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. Don't just point to "" because that leads to a "loss of const" - warning. */ - - if (capcount >= 0) - { - if (pp == NULL) - { -#ifdef SUPPORT_VALGRIND - /* Mark the start of dbuffer addressable again. */ - VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, 1); -#endif - pp = dbuffer; - pp[0] = 0; - } - - if (capcount > (int)oveccount) /* Check for lunatic return value */ - { - fprintf(outfile, - "** PCRE2 error: returned count %d is too big for ovector count %d\n", - capcount, oveccount); - capcount = oveccount; - if ((dat_datctl.control & CTL_ANYGLOB) != 0) - { - fprintf(outfile, "** Global loop abandoned\n"); - dat_datctl.control &= ~CTL_ANYGLOB; /* Break g/G loop */ - } - } - - /* 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 ((FLD(match_data, flags) & PCRE2_MD_COPIED_SUBJECT) == 0) - fprintf(outfile, - "** PCRE2 error: flag not set after copy_matched_subject\n"); - - if (CASTFLD(const void *, match_data, subject) == pp) - fprintf(outfile, - "** PCRE2 error: copy_matched_subject has not copied\n"); - - if (memcmp(CASTFLD(const void *, match_data, subject), pp, ulen) != 0) - fprintf(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 changed. If it has not, check for an empty string match - at different starting offset from the previous match. This is a failed test - retry for null-matching patterns that don't match at their starting offset, - for example /(?<=\G.)/. A repeated match at the same point is not such a - pattern, and must be discarded, and we then proceed to seek a non-null - match at the current point. For any other repeated match, there is a bug - somewhere and we must break the loop because it will go on for ever. We - know that there are always at least two elements in the ovector. */ - - if (gmatched > 0 && ovecsave[0] == ovector[0] && ovecsave[1] == ovector[1]) - { - if (ovector[0] == ovector[1] && ovecsave[2] != dat_datctl.offset) - { - g_notempty = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED; - ovecsave[2] = dat_datctl.offset; - continue; /* Back to the top of the loop */ - } - fprintf(outfile, - "** PCRE2 error: global repeat returned the same string as previous\n"); - fprintf(outfile, "** Global loop abandoned\n"); - dat_datctl.control &= ~CTL_ANYGLOB; /* Break g/G loop */ - } - - /* "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 (capcount > (int)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]; - fprintf(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 - fprintf(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 = FLD(match_data, leftchar); - rightchar = FLD(match_data, rightchar); - showallused = i == 0 && (leftchar < start || rightchar > end); - } - else showallused = FALSE; - - if (showallused) - { - PCHARS(lleft, pp, leftchar, start - leftchar, utf, outfile); - PCHARS(lmiddle, pp, start, end - start, utf, outfile); - PCHARS(lright, 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; - PCRE2_GET_STARTCHAR(startchar, match_data); - PCHARS(lleft, pp, startchar, start - startchar, utf, outfile); - PCHARSV(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 - { - PCHARSV(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 - { - PCHARSV(pp, start, end - start, utf, outfile); - } + fprintf(outfile, "%2d: ", i/2); + if (start == PCRE2_UNSET && end == PCRE2_UNSET) + fprintf(outfile, "\n"); + else if (start == JUNK_OFFSET && end == JUNK_OFFSET) + fprintf(outfile, "\n"); + else + fprintf(outfile, "%ld %ld\n", (unsigned long int)start, + (unsigned long int)end); + } +} - 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); - PCHARSV(pp, ovector[i+1], ulen - ovector[i+1], utf, outfile); - fprintf(outfile, "\n"); - } - } +/************************************************* +* Mode-dependent code * +*************************************************/ - /* Output (*MARK) data if requested */ +/* All the mode-independent utilities should go above this section, so that +the mode-dependent code can use them. - if ((dat_datctl.control & CTL_MARK) != 0 && - TESTFLD(match_data, mark, !=, NULL)) - { - fprintf(outfile, "MK: "); - PCHARSV(CASTFLD(const void *, match_data, mark), -1, -1, utf, outfile); - fprintf(outfile, "\n"); - } +The structure is: + main + -> calls into usage, command line parsing, top-level dispatch + -> calls into mode-dependent code to handle input lines + -> calls into mode-independent utilities - /* Process copy/get strings */ +The ordering of the code blocks is therefore: + - mode-independent utilities (ABOVE THIS SECTION) + - mode-dependent code to handle input lines (THIS SECTION) + - usage, command line parsing, top-level dispatch (NEXT SECTION) + - main (AT THE BOTTOM) +*/ - if (!copy_and_get(utf, capcount)) return PR_ABEND; +/* --- Repeated pre-processor inclusions to build the mode-dependent code -- */ - } /* End of handling a successful match */ +#undef PCRE2_SUFFIX - /* 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. */ +#ifdef SUPPORT_PCRE2_8 +#define PCRE2_CODE_UNIT_WIDTH 8 +#define PCRE2_SUFFIX(a) G(a,8) +#include "pcre2_intmodedep.h" +#include "pcre2test_inc.h" +#undef PCRE2_CODE_UNIT_WIDTH +#undef PCRE2_SUFFIX +#endif - else if (capcount == PCRE2_ERROR_PARTIAL) - { - PCRE2_SIZE leftchar; - int backlength; - int rubriclength = 0; +#ifdef SUPPORT_PCRE2_16 +#define PCRE2_CODE_UNIT_WIDTH 16 +#define PCRE2_SUFFIX(a) G(a,16) +#include "pcre2_intmodedep.h" +#include "pcre2test_inc.h" +#undef PCRE2_CODE_UNIT_WIDTH +#undef PCRE2_SUFFIX +#endif - if ((dat_datctl.control & CTL_ALLUSEDTEXT) != 0) - { - leftchar = FLD(match_data, leftchar); - } - else leftchar = ovector[0]; +#ifdef SUPPORT_PCRE2_32 +#define PCRE2_CODE_UNIT_WIDTH 32 +#define PCRE2_SUFFIX(a) G(a,32) +#include "pcre2_intmodedep.h" +#include "pcre2test_inc.h" +#undef PCRE2_CODE_UNIT_WIDTH +#undef PCRE2_SUFFIX +#endif - fprintf(outfile, "Partial match"); - if ((dat_datctl.control & CTL_MARK) != 0 && - TESTFLD(match_data, mark, !=, NULL)) - { - fprintf(outfile, ", mark="); - PCHARS(rubriclength, CASTFLD(const void *, match_data, mark), -1, -1, utf, - outfile); - rubriclength += 7; - } - fprintf(outfile, ": "); - rubriclength += 15; +#define PCRE2_CODE_UNIT_WIDTH 0 +#include "pcre2_intmodedep.h" /* Clear out the stale macros */ +#undef PCRE2_CODE_UNIT_WIDTH - PCHARS(backlength, pp, leftchar, ovector[0] - leftchar, utf, outfile); - PCHARSV(pp, ovector[0], ovector[1] - ovector[0], utf, outfile); +#define PCRE2_SUFFIX(a) a - if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) - fprintf(outfile, " (JIT)"); - fprintf(outfile, "\n"); +/* --------------------------- Static variables ---------------------------- */ - if (backlength != 0) - { - for (int i = 0; i < rubriclength; i++) fprintf(outfile, " "); - for (int i = 0; i < backlength; i++) fprintf(outfile, "<"); - fprintf(outfile, "\n"); - } +/* Declared after mode-dependent code. */ - if (ulen != ovector[1]) - fprintf(outfile, "** ovector[1] is not equal to the subject length: " - "%ld != %ld\n", (unsigned long int)ovector[1], (unsigned long int)ulen); +static int test_mode = DEFAULT_TEST_MODE; - /* Process copy/get strings */ +/* -------------------- Mode-dependent dispatch helper --------------------- */ - if (!copy_and_get(utf, 1)) return PR_ABEND; +/* When there are three supported bit widths, use a three-way ternary. */ - /* "allvector" outputs the entire vector */ +#if defined(SUPPORT_PCRE2_8) && defined(SUPPORT_PCRE2_16) && defined(SUPPORT_PCRE2_32) - if ((dat_datctl.control2 & CTL2_ALLVECTOR) != 0) - show_ovector(ovector, oveccount); +#define DISPATCH(opt_ret, fname, fargs) opt_ret \ + ((test_mode == PCRE2TEST_MODE_8)? G(fname,8) fargs : \ + (test_mode == PCRE2TEST_MODE_16)? G(fname,16) fargs : \ + G(fname,32) fargs) - break; /* Out of the /g loop */ - } /* End of handling partial match */ +#elif (defined(SUPPORT_PCRE2_8) + defined(SUPPORT_PCRE2_16) + \ + defined(SUPPORT_PCRE2_32)) == 2 - /* Failed to match. If this is a /g or /G loop, we might previously have - set g_notempty (to PCRE2_NOTEMPTY_ATSTART|PCRE2_ANCHORED) after a null match. - If that is the case, this is not necessarily the end. We want to advance the - start offset, and continue. We won't be at the end of the string - that was - checked before setting g_notempty. We achieve the effect by pretending that a - single character was matched. +/* With some macro trickery, we can make a single definition work to dispatch +between any two bit widths. */ - Complication arises in the case when the newline convention is "any", "crlf", - or "anycrlf". If the previous match was at the end of a line terminated by - CRLF, an advance of one character just passes the CR, whereas we should - prefer the longer newline sequence, as does the code in pcre2_match(). +#if defined(SUPPORT_PCRE2_32) && defined(SUPPORT_PCRE2_16) +#define BITONE 32 +#define BITTWO 16 +#elif defined(SUPPORT_PCRE2_32) && defined(SUPPORT_PCRE2_8) +#define BITONE 32 +#define BITTWO 8 +#else +#define BITONE 16 +#define BITTWO 8 +#endif - Otherwise, in the case of UTF-8 or UTF-16 matching, the advance must be one - character, not one byte. */ +#define DISPATCH(opt_ret, fname, fargs) opt_ret \ + ((test_mode == G(PCRE2TEST_MODE_,BITONE))? G(fname,BITONE) fargs : \ + G(fname,BITTWO) fargs) - else if (g_notempty != 0) /* There was a previous null match */ - { - uint16_t nl = FLD(compiled_code, newline_convention); - PCRE2_SIZE start_offset = dat_datctl.offset; /* Where the match was */ - PCRE2_SIZE end_offset = start_offset + 1; - - if ((nl == PCRE2_NEWLINE_CRLF || nl == PCRE2_NEWLINE_ANY || - nl == PCRE2_NEWLINE_ANYCRLF) && - start_offset < ulen - 1 && - CODE_UNIT(pp, start_offset) == '\r' && - CODE_UNIT(pp, end_offset) == '\n') - end_offset++; - - else if (utf && test_mode != PCRE32_MODE) - { - if (test_mode == PCRE8_MODE) - { - for (; end_offset < ulen; end_offset++) - if ((((PCRE2_SPTR8)pp)[end_offset] & 0xc0) != 0x80) break; - } - else /* 16-bit mode */ - { - for (; end_offset < ulen; end_offset++) - if ((((PCRE2_SPTR16)pp)[end_offset] & 0xfc00) != 0xdc00) break; - } - } +#else /* Only one bit width supported */ - SETFLDVEC(match_data, ovector, 0, start_offset); - SETFLDVEC(match_data, ovector, 1, end_offset); - } /* End of handling null match in a global loop */ +#if defined(SUPPORT_PCRE2_32) +#define BITONE 32 +#elif defined(SUPPORT_PCRE2_16) +#define BITONE 16 +#else +#define BITONE 8 +#endif - /* A "normal" match failure. There will be a negative error number in - capcount. */ +#define DISPATCH(opt_ret, fname, fargs) \ + opt_ret (G(fname,BITONE) fargs) - else - { - switch(capcount) - { - case PCRE2_ERROR_NOMATCH: - if (gmatched == 0) - { - fprintf(outfile, "No match"); - if ((dat_datctl.control & CTL_MARK) != 0 && - TESTFLD(match_data, mark, !=, NULL)) - { - fprintf(outfile, ", mark = "); - PCHARSV(CASTFLD(const void *, 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; +#endif - case PCRE2_ERROR_BADUTFOFFSET: - fprintf(outfile, "Error %d (bad UTF-%d offset)\n", capcount, test_mode); - break; +/* -------------------- Mode-dependent dispatch wrappers ------------------- */ - default: - fprintf(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; - PCRE2_GET_STARTCHAR(startchar, match_data); - fprintf(outfile, " at offset %" SIZ_FORM, startchar); - } - fprintf(outfile, "\n"); - break; - } +static int jit_compile_test(void) +{ +DISPATCH(return, pcre2_jit_compile_, (NULL, PCRE2_JIT_TEST_ALLOC)); +} - break; /* Out of the /g loop */ - } /* End of failed match handling */ +static int pcre2_config(uint32_t what, void *where) +{ +DISPATCH(return, pcre2_config_, (what, where)); +} - /* Control reaches here in two circumstances: (a) after a match, and (b) - after a non-match that immediately followed a match on an empty string when - doing a global search. Such a match is done with PCRE2_NOTEMPTY_ATSTART and - PCRE2_ANCHORED set in g_notempty. The code above turns it into a fake match - of one character. So effectively we get here only after a match. If we - are not doing a global search, we are done. */ +static void config_str(uint32_t what, char *where) +{ +DISPATCH(, config_str_, (what, where)); +} - if ((dat_datctl.control & CTL_ANYGLOB) == 0) break; else - { - PCRE2_SIZE match_offset = FLD(match_data, ovector)[0]; - PCRE2_SIZE end_offset = FLD(match_data, ovector)[1]; - - /* We must now set up for the next iteration of a global search. If we have - matched an empty string, first check to see if we are at the end of the - subject. If so, the loop is over. Otherwise, mimic what Perl's /g option - does. Set PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED and try the match again - at the same point. If this fails it will be picked up above, where a fake - match is set up so that at this point we advance to the next character. - - However, in order to cope with patterns that never match at their starting - offset (e.g. /(?<=\G.)/) we don't do this when the match offset is greater - than the starting offset. This means there will be a retry with the - starting offset at the match offset. If this returns the same match again, - it is picked up above and ignored, and the special action is then taken. */ - - if (match_offset == end_offset) - { - if (end_offset == ulen) break; /* End of subject */ - if (match_offset <= dat_datctl.offset) - g_notempty = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED; - } +static BOOL decode_modifiers(uint8_t *p, int ctx, patctl *pctl, datctl *dctl) +{ +DISPATCH(return, decode_modifiers_, (p, ctx, pctl, dctl)); +} - /* However, even after matching a non-empty string, there is still one - tricky case. If a pattern contains \K within a lookbehind assertion at the - start, the end of the matched string can be at the offset where the match - started. In the case of a normal /g iteration without special action, this - leads to a loop that keeps on returning the same substring. The loop would - be caught above, but we really want to move on to the next match. */ +static BOOL +print_error_message_file(FILE *file, int errorcode, const char *before, + const char *after, BOOL badcode_ok) +{ +DISPATCH(return, print_error_message_file_, \ + (file, errorcode, before, after, badcode_ok)); +} - else - { - g_notempty = 0; /* Set for a "normal" repeat */ - if ((dat_datctl.control & CTL_GLOBAL) != 0) - { - PCRE2_SIZE startchar; - PCRE2_GET_STARTCHAR(startchar, match_data); - if (end_offset <= startchar) - { - if (startchar >= ulen) break; /* End of subject */ - end_offset = startchar + 1; - if (utf && test_mode != PCRE32_MODE) - { - if (test_mode == PCRE8_MODE) - { - for (; end_offset < ulen; end_offset++) - if ((((PCRE2_SPTR8)pp)[end_offset] & 0xc0) != 0x80) break; - } - else /* 16-bit mode */ - { - for (; end_offset < ulen; end_offset++) - if ((((PCRE2_SPTR16)pp)[end_offset] & 0xfc00) != 0xdc00) break; - } - } - } - } - } +static int process_command(void) +{ +DISPATCH(return, process_command_, ()); +} - /* For a normal global (/g) iteration, save the current ovector[0,1] and - the starting offset so that we can check that they do change each time. - Otherwise a matching bug that returns the same string causes an infinite - loop. It has happened! Then update the start offset, leaving other - parameters alone. */ +static int process_pattern(void) +{ +DISPATCH(return, process_pattern_, ()); +} - if ((dat_datctl.control & CTL_GLOBAL) != 0) - { - ovecsave[0] = ovector[0]; - ovecsave[1] = ovector[1]; - ovecsave[2] = dat_datctl.offset; - dat_datctl.offset = end_offset; - } +static BOOL have_active_pattern(void) +{ +DISPATCH(return, have_active_pattern_, ()); +} - /* For altglobal, just update the pointer and length. */ +static void free_active_pattern(void) +{ +DISPATCH(, free_active_pattern_, ()); +} - else - { - pp += end_offset * code_unit_size; - len -= end_offset * code_unit_size; - ulen -= end_offset; - if (arg_ulen != PCRE2_ZERO_TERMINATED) arg_ulen -= end_offset; - } - } - } /* End of global loop */ +static int process_data(void) +{ +DISPATCH(return, process_data_, ()); +} -/* All matching is done; show the resulting heapframe size if requested. */ +static void init_globals(void) +{ +DISPATCH(, init_globals_, ()); +} -if ((dat_datctl.control2 & CTL2_HEAPFRAMES_SIZE) != 0 && - (dat_datctl.control & CTL_DFA) == 0) - show_heapframes_size(); +static void free_globals(void) +{ +DISPATCH(, free_globals_, ()); +} -show_memory = FALSE; -return PR_OK; +static void unittest(void) +{ +DISPATCH(, unittest_, ()); } +#undef DISPATCH +#undef BITONE +#undef BITTWO @@ -8819,14 +3013,12 @@ return PR_OK; static void print_version(FILE *f, BOOL include_mode) { -char buf[16]; -VERSION_TYPE *vp; -fprintf(f, "PCRE2 version "); -for (vp = version; *vp != 0; vp++) fprintf(f, "%c", *vp); +char buf[VERSION_SIZE]; +config_str(PCRE2_CONFIG_VERSION, buf); +fprintf(f, "PCRE2 version %s", buf); if (include_mode) { - sprintf(buf, "%d-bit", test_mode); - fprintf(f, " (%s)", buf); + fprintf(f, " (%d-bit)", test_mode); } fprintf(f, "\n"); } @@ -8840,9 +3032,9 @@ fprintf(f, "\n"); static void print_unicode_version(FILE *f) { -VERSION_TYPE *vp; -fprintf(f, "Unicode version "); -for (vp = uversion; *vp != 0; vp++) fprintf(f, "%c", *vp); +char buf[VERSION_SIZE]; +config_str(PCRE2_CONFIG_UNICODE_VERSION, buf); +fprintf(f, "Unicode version %s", buf); } @@ -8854,8 +3046,9 @@ for (vp = uversion; *vp != 0; vp++) fprintf(f, "%c", *vp); static void print_jit_target(FILE *f) { -VERSION_TYPE *vp; -for (vp = jittarget; *vp != 0; vp++) fprintf(f, "%c", *vp); +char buf[VERSION_SIZE]; +config_str(PCRE2_CONFIG_JITTARGET, buf); +fputs(buf, f); } @@ -8916,8 +3109,10 @@ printf(" -C arg show a specific compile-time option and exit with its\n" printf(" value if numeric (else 0). The arg can be:\n"); printf(" backslash-C use of \\C is enabled [0, 1]\n"); printf(" bsr \\R type [ANYCRLF, ANY]\n"); -printf(" ebcdic compiled for EBCDIC character code [0,1]\n"); -printf(" ebcdic-nl NL code if compiled for EBCDIC\n"); +printf(" ebcdic compiled for EBCDIC character code [0, 1]\n"); +printf(" ebcdic-io if compiled for EBCDIC, whether pcre2test's input\n"); +printf(" and output is EBCDIC or ASCII [0, 1]\n"); +printf(" ebcdic-nl25 if compiled for EBCDIC, whether NL is 0x25 [0, 1]\n"); printf(" jit just-in-time compiler supported [0, 1]\n"); printf(" jitusable test JIT usability [0, 1, 2, 3]\n"); printf(" linksize internal link size [2, 3, 4]\n"); @@ -8926,8 +3121,11 @@ printf(" pcre2-8 8 bit library support enabled [0, 1]\n"); printf(" pcre2-16 16 bit library support enabled [0, 1]\n"); printf(" pcre2-32 32 bit library support enabled [0, 1]\n"); printf(" unicode Unicode and UTF support enabled [0, 1]\n"); +printf(" --colo[u]r[=]\n"); +printf(" show output in colour\n"); printf(" -d set default pattern modifier 'debug'\n"); printf(" -dfa set default subject modifier 'dfa'\n"); +printf(" -E preprocess input only (#if ... #endif)\n"); printf(" -error show messages for error numbers, then exit\n"); printf(" -help show usage information\n"); printf(" -i set default pattern modifier 'info'\n"); @@ -8937,6 +3135,7 @@ printf(" -jitverify set default pattern modifier 'jitverify'\n"); printf(" -LM list pattern and subject modifiers, then exit\n"); printf(" -LP list non-script properties, then exit\n"); printf(" -LS list supported scripts, then exit\n"); +printf(" -malloc exercise malloc() failures\n"); printf(" -q quiet: do not output PCRE2 version number at start\n"); printf(" -pattern set default pattern modifier fields\n"); printf(" -subject set default subject modifier fields\n"); @@ -8945,6 +3144,7 @@ printf(" -t [] time compilation and execution, repeating times\n"); printf(" -tm [] time execution (matching) only, repeating times\n"); printf(" -T same as -t, but show total times at the end\n"); printf(" -TM same as -tm, but show total time at the end\n"); +printf(" -unittest run unit tests, then exit\n"); printf(" -v|--version show PCRE2 version and exit\n"); } @@ -8956,8 +3156,9 @@ printf(" -v|--version show PCRE2 version and exit\n"); /* This option outputs configuration options and sets an appropriate return code when asked for a single option. The code is abstracted into a separate -function because of its size. Use whichever pcre2_config() function is -available. +function because of its size. + +Most, but not all, of the data is independent of the test mode. Argument: an option name or NULL Returns: the return code @@ -8968,23 +3169,23 @@ c_option(const char *arg) { uint32_t optval; unsigned int i = COPTLISTCOUNT; -int yield = 0; +int rc, yield = 0; -if (arg != NULL && arg[0] != CHAR_MINUS) +if (arg != NULL && arg[0] != '-') { for (i = 0; i < COPTLISTCOUNT; i++) if (strcmp(arg, coptlist[i].name) == 0) break; if (i >= COPTLISTCOUNT) { - fprintf(stderr, "** Unknown -C option \"%s\"\n", arg); + cfprintf(clr_test_error, stderr, "pcre2test: Unknown -C option \"%s\"\n", arg); return 0; } switch (coptlist[i].type) { case CONF_BSR: - (void)PCRE2_CONFIG(coptlist[i].value, &optval); + (void)pcre2_config(coptlist[i].value, &optval); printf("%s\n", (optval == PCRE2_BSR_ANYCRLF)? "ANYCRLF" : "ANY"); break; @@ -8993,27 +3194,21 @@ if (arg != NULL && arg[0] != CHAR_MINUS) printf("%d\n", yield); break; - case CONF_FIZ: - optval = coptlist[i].value; - printf("%d\n", optval); - break; - case CONF_INT: - (void)PCRE2_CONFIG(coptlist[i].value, &yield); + (void)pcre2_config(coptlist[i].value, &yield); printf("%d\n", yield); break; case CONF_NL: - (void)PCRE2_CONFIG(coptlist[i].value, &optval); + (void)pcre2_config(coptlist[i].value, &optval); print_newline_config(optval, TRUE); break; case CONF_JU: - SET(compiled_code, NULL); - PCRE2_JIT_COMPILE(yield, compiled_code, PCRE2_JIT_TEST_ALLOC); - switch(yield) + rc = jit_compile_test(); + switch(rc) { - case 0: break; + case 0: yield = 0; break; case PCRE2_ERROR_NOMEMORY: yield = 1; break; case PCRE2_ERROR_JIT_UNSUPPORTED: yield = 2; break; default: yield = 3; break; @@ -9067,9 +3262,14 @@ printf(" EBCDIC code support: LF is 0x%02x\n", CHAR_LF); #if defined NATIVE_ZOS printf(" EBCDIC code page %s or similar\n", pcrz_cpversion()); #endif +#if EBCDIC_IO +printf(" Input/output for pcre2test is EBCDIC\n"); +#else +printf(" Input/output for pcre2test is ASCII, not EBCDIC\n"); +#endif #endif -(void)PCRE2_CONFIG(PCRE2_CONFIG_COMPILED_WIDTHS, &optval); +(void)pcre2_config(PCRE2_CONFIG_COMPILED_WIDTHS, &optval); if (optval & 1) printf(" 8-bit support\n"); if (optval & 2) printf(" 16-bit support\n"); if (optval & 4) printf(" 32-bit support\n"); @@ -9078,7 +3278,7 @@ if (optval & 4) printf(" 32-bit support\n"); printf(" Valgrind support\n"); #endif -(void)PCRE2_CONFIG(PCRE2_CONFIG_UNICODE, &optval); +(void)pcre2_config(PCRE2_CONFIG_UNICODE, &optval); if (optval != 0) { printf(" UTF and UCP support ("); @@ -9087,7 +3287,7 @@ if (optval != 0) } else printf(" No Unicode support\n"); -(void)PCRE2_CONFIG(PCRE2_CONFIG_JIT, &optval); +(void)pcre2_config(PCRE2_CONFIG_JIT, &optval); if (optval != 0) { printf(" Just-in-time compiler support\n"); @@ -9096,9 +3296,8 @@ if (optval != 0) printf("\n"); printf(" Can allocate executable memory: "); - SET(compiled_code, NULL); - PCRE2_JIT_COMPILE(yield, compiled_code, PCRE2_JIT_TEST_ALLOC); - switch(yield) + rc = jit_compile_test(); + switch(rc) { case 0: printf("Yes\n"); @@ -9109,9 +3308,10 @@ if (optval != 0) break; default: - printf("\n** Unexpected return %d from " - "pcre2_jit_compile(NULL, PCRE2_JIT_TEST_ALLOC)\n", yield); - printf("** Should not occur\n"); + cfprintf(clr_test_error, stdout, "\n** Unexpected return %d from " + "pcre2_jit_compile(NULL, PCRE2_JIT_TEST_ALLOC)\n", rc); + cfprintf(clr_test_error, stdout, "** Should not occur\n"); + yield = 1; break; } } @@ -9120,23 +3320,26 @@ else printf(" No just-in-time compiler support\n"); } -(void)PCRE2_CONFIG(PCRE2_CONFIG_NEWLINE, &optval); +(void)pcre2_config(PCRE2_CONFIG_NEWLINE, &optval); print_newline_config(optval, FALSE); -(void)PCRE2_CONFIG(PCRE2_CONFIG_BSR, &optval); +(void)pcre2_config(PCRE2_CONFIG_BSR, &optval); printf(" \\R matches %s\n", (optval == PCRE2_BSR_ANYCRLF)? "CR, LF, or CRLF only" : "all Unicode newlines"); -(void)PCRE2_CONFIG(PCRE2_CONFIG_NEVER_BACKSLASH_C, &optval); +(void)pcre2_config(PCRE2_CONFIG_NEVER_BACKSLASH_C, &optval); printf(" \\C is %ssupported\n", optval? "not ":""); -(void)PCRE2_CONFIG(PCRE2_CONFIG_LINKSIZE, &optval); -printf(" Internal link size = %d\n", optval); -(void)PCRE2_CONFIG(PCRE2_CONFIG_PARENSLIMIT, &optval); +printf(" Internal link size\n"); +(void)pcre2_config(PCRE2_CONFIG_LINKSIZE, &optval); +printf(" Requested = %d\n", optval); +(void)pcre2_config(PCRE2_CONFIG_EFFECTIVE_LINKSIZE, &optval); +printf(" Effective = %d\n", optval); +(void)pcre2_config(PCRE2_CONFIG_PARENSLIMIT, &optval); printf(" Parentheses nest limit = %d\n", optval); -(void)PCRE2_CONFIG(PCRE2_CONFIG_HEAPLIMIT, &optval); +(void)pcre2_config(PCRE2_CONFIG_HEAPLIMIT, &optval); printf(" Default heap limit = %d kibibytes\n", optval); -(void)PCRE2_CONFIG(PCRE2_CONFIG_MATCHLIMIT, &optval); +(void)pcre2_config(PCRE2_CONFIG_MATCHLIMIT, &optval); printf(" Default match limit = %d\n", optval); -(void)PCRE2_CONFIG(PCRE2_CONFIG_DEPTHLIMIT, &optval); +(void)pcre2_config(PCRE2_CONFIG_DEPTHLIMIT, &optval); printf(" Default depth limit = %d\n", optval); #if defined SUPPORT_LIBREADLINE @@ -9147,7 +3350,7 @@ printf(" pcre2test has libedit support\n"); printf(" pcre2test has neither libreadline nor libedit support\n"); #endif -return 0; +return yield; } @@ -9263,7 +3466,7 @@ for (size_t i = 0; i < PRIV(utt_size); i++) const ucp_type_table *tt = PRIV(utt) + j; if (tt->type != t->type || tt->value != value) continue; if (m >= MAX_SYNONYMS) - printf("** Too many synonyms: %s ignored\n", + cfprintf(clr_test_error, stdout, "** Too many synonyms: %s ignored\n", PRIV(utt_names) + tt->name_offset); else fv[m++] = tt->name_offset; } @@ -9366,12 +3569,15 @@ for (i = 0; i < MODLISTCOUNT; i++) is_pattern = FALSE; break; - default: printf("** Unknown type for modifier \"%s\"\n", m->name); - /* Fall through */ case MOD_PD: /* Pattern or subject */ case MOD_PDP: /* As PD, OK for Perl-compatible test */ is_pattern = for_pattern; break; + + default: + printf("** Unknown type for modifier \"%s\"\n", m->name); + PCRE2_DEBUG_UNREACHABLE(); + exit(1); } if (for_pattern == is_pattern) @@ -9399,7 +3605,7 @@ for (i = 0, j = (n+1)/2; i < (n+1)/2; i++, j++) display_one_modifier(m, for_pattern); if (j < n) { - uint32_t k = 27 - strlen(m->name) - extra[i]; + size_t k = 27 - strlen(m->name) - extra[i]; while (k-- > 0) printf(" "); display_one_modifier(modlist + list[j], for_pattern); } @@ -9435,65 +3641,17 @@ display_selected_modifiers(FALSE, "SUBJECT"); int main(int argc, char **argv) { -uint32_t temp; uint32_t yield = 0; uint32_t op = 1; BOOL notdone = TRUE; BOOL quiet = FALSE; BOOL showtotaltimes = FALSE; BOOL skipping = FALSE; +BOOL skipping_endif = FALSE; char *arg_subject = NULL; char *arg_pattern = NULL; char *arg_error = NULL; -/* The offsets to the options and control bits fields of the pattern and data -control blocks must be the same so that common options and controls such as -"anchored" or "memory" can work for either of them from a single table entry. -We cannot test this till runtime because "offsetof" does not work in the -preprocessor. */ - -if (PO(options) != DO(options) || PO(control) != DO(control) || - PO(control2) != DO(control2)) - { - fprintf(stderr, "** Coding error: " - "options and control offsets for pattern and data must be the same.\n"); - return 1; - } - -/* Get the PCRE2 and Unicode version number and JIT target information, at the -same time checking that a request for the length gives the same answer. Also -check lengths for non-string items. */ - -if (PCRE2_CONFIG(PCRE2_CONFIG_VERSION, NULL) != - PCRE2_CONFIG(PCRE2_CONFIG_VERSION, version) || - - PCRE2_CONFIG(PCRE2_CONFIG_UNICODE_VERSION, NULL) != - PCRE2_CONFIG(PCRE2_CONFIG_UNICODE_VERSION, uversion) || - - PCRE2_CONFIG(PCRE2_CONFIG_JITTARGET, NULL) != - PCRE2_CONFIG(PCRE2_CONFIG_JITTARGET, jittarget) || - - PCRE2_CONFIG(PCRE2_CONFIG_UNICODE, NULL) != sizeof(uint32_t) || - PCRE2_CONFIG(PCRE2_CONFIG_MATCHLIMIT, NULL) != sizeof(uint32_t)) - { - fprintf(stderr, "** Error in pcre2_config(): bad length\n"); - return 1; - } - -/* Check that bad options are diagnosed. */ - -if (PCRE2_CONFIG(999, NULL) != PCRE2_ERROR_BADOPTION || - PCRE2_CONFIG(999, &temp) != PCRE2_ERROR_BADOPTION) - { - fprintf(stderr, "** Error in pcre2_config(): bad option not diagnosed\n"); - return 1; - } - -/* This configuration option is now obsolete, but running a quick check ensures -that its code is covered. */ - -(void)PCRE2_CONFIG(PCRE2_CONFIG_STACKRECURSE, &temp); - /* Get buffers from malloc() so that valgrind will check their misuse when debugging. They grow automatically when very long lines are read. The 16- and 32-bit buffers (pbuffer16, pbuffer32) are obtained only if needed. */ @@ -9514,16 +3672,8 @@ _setmode( _fileno( stdout ), _O_BINARY ); locale_name[0] = 0; -memset(&def_patctl, 0, sizeof(patctl)); -def_patctl.convert_type = CONVERT_UNSET; - -memset(&def_datctl, 0, sizeof(datctl)); -def_datctl.oveccount = DEFAULT_OVECCOUNT; -def_datctl.copy_numbers[0] = -1; -def_datctl.get_numbers[0] = -1; -def_datctl.startend[0] = def_datctl.startend[1] = CFORE_UNSET; -def_datctl.cerror[0] = def_datctl.cerror[1] = CFORE_UNSET; -def_datctl.cfail[0] = def_datctl.cfail[1] = CFORE_UNSET; +patctl_zero(&def_patctl); +datctl_zero(&def_datctl); /* Scan command line options. */ @@ -9557,6 +3707,16 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) goto EXIT; } + /* Perform additional edge-case and error-handling tests of public API + functions, which wouldn't otherwise be covered by the standard use of the API + in pcre2test. */ + + if (strcmp(arg, "-unittest") == 0) + { + unittest(); + goto EXIT; + } + /* Display and/or set return code for configuration options. */ if (strcmp(arg, "-C") == 0) @@ -9565,20 +3725,15 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) goto EXIT; } - /* Select operating mode. Ensure that pcre2_config() is called in 16-bit - and 32-bit modes because that won't happen naturally when 8-bit is also - configured. Also call some other functions that are not otherwise used. This - means that a coverage report won't claim there are uncalled functions. */ + /* Select operating mode. */ if (strcmp(arg, "-8") == 0) { #ifdef SUPPORT_PCRE2_8 - test_mode = PCRE8_MODE; - (void)pcre2_set_bsr_8(pat_context8, 999); - (void)pcre2_set_newline_8(pat_context8, 999); + test_mode = PCRE2TEST_MODE_8; #else - fprintf(stderr, - "** This version of PCRE2 was built without 8-bit support\n"); + cfprintf(clr_test_error, stderr, + "pcre2test: This version of PCRE2 was built without 8-bit support\n"); exit(1); #endif } @@ -9586,13 +3741,10 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) else if (strcmp(arg, "-16") == 0) { #ifdef SUPPORT_PCRE2_16 - test_mode = PCRE16_MODE; - (void)pcre2_config_16(PCRE2_CONFIG_VERSION, NULL); - (void)pcre2_set_bsr_16(pat_context16, 999); - (void)pcre2_set_newline_16(pat_context16, 999); + test_mode = PCRE2TEST_MODE_16; #else - fprintf(stderr, - "** This version of PCRE2 was built without 16-bit support\n"); + cfprintf(clr_test_error, stderr, + "pcre2test: This version of PCRE2 was built without 16-bit support\n"); exit(1); #endif } @@ -9600,17 +3752,18 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) else if (strcmp(arg, "-32") == 0) { #ifdef SUPPORT_PCRE2_32 - test_mode = PCRE32_MODE; - (void)pcre2_config_32(PCRE2_CONFIG_VERSION, NULL); - (void)pcre2_set_bsr_32(pat_context32, 999); - (void)pcre2_set_newline_32(pat_context32, 999); + test_mode = PCRE2TEST_MODE_32; #else - fprintf(stderr, - "** This version of PCRE2 was built without 32-bit support\n"); + cfprintf(clr_test_error, stderr, + "pcre2test: This version of PCRE2 was built without 32-bit support\n"); exit(1); #endif } + /* Set preprocess-only (only handle #if ... #endif) */ + + else if (strcmp(arg, "-E") == 0) preprocess_only = TRUE; + /* Set quiet (no version verification) */ else if (strcmp(arg, "-q") == 0) quiet = TRUE; @@ -9621,36 +3774,40 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) ((uli = strtoul(argv[op+1], &endptr, 10)), *endptr == 0)) { #if defined(_WIN32) || defined(WIN32) || defined(__HAIKU__) || defined(NATIVE_ZOS) || defined(__VMS) - fprintf(stderr, "pcre2test: -S is not supported on this OS\n"); + cfprintf(clr_test_error, stderr, "pcre2test: -S is not supported on this OS\n"); exit(1); #else - int rc; + int rc = 0; uint32_t stack_size; - struct rlimit rlim; - if (U32OVERFLOW(uli)) + struct rlimit rlim, rlim_old; + if (uli > INT32_MAX / (1024 * 1024)) { - fprintf(stderr, "** Argument for -S is too big\n"); + cfprintf(clr_test_error, stderr, "pcre2test: Argument for -S is too big\n"); exit(1); } stack_size = (uint32_t)uli; - getrlimit(RLIMIT_STACK, &rlim); + getrlimit(RLIMIT_STACK, &rlim_old); + rlim = rlim_old; rlim.rlim_cur = stack_size * 1024 * 1024; - if (rlim.rlim_cur > rlim.rlim_max) + if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max) { - fprintf(stderr, + cfprintf(clr_test_error, stderr, "pcre2test: requested stack size %luMiB is greater than hard limit ", (unsigned long int)stack_size); - if (rlim.rlim_max % (1024*1024) == 0) fprintf(stderr, "%luMiB\n", - (unsigned long int)(rlim.rlim_max/(1024 * 1024))); - else if (rlim.rlim_max % 1024 == 0) fprintf(stderr, "%luKiB\n", - (unsigned long int)(rlim.rlim_max/1024)); - else fprintf(stderr, "%lu bytes\n", (unsigned long int)(rlim.rlim_max)); + if (rlim.rlim_max % (1024*1024) == 0) + cfprintf(clr_test_error, stderr, "%luMiB\n", (unsigned long)(rlim.rlim_max/(1024*1024))); + else if (rlim.rlim_max % 1024 == 0) + cfprintf(clr_test_error, stderr, "%luKiB\n", (unsigned long)(rlim.rlim_max/1024)); + else + cfprintf(clr_test_error, stderr, "%lu bytes\n", (unsigned long)(rlim.rlim_max)); exit(1); } - rc = setrlimit(RLIMIT_STACK, &rlim); + if (rlim_old.rlim_cur != RLIM_INFINITY && rlim_old.rlim_cur <= INT32_MAX && + rlim.rlim_cur > rlim_old.rlim_cur) + rc = setrlimit(RLIMIT_STACK, &rlim); if (rc != 0) { - fprintf(stderr, "pcre2test: setting stack size %luMiB failed: %s\n", + cfprintf(clr_test_error, stderr, "pcre2test: setting stack size %luMiB failed: %s\n", (unsigned long int)stack_size, strerror(errno)); exit(1); } @@ -9678,7 +3835,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) else if (arg[4] == 'f') def_patctl.control |= CTL_JITFAST; def_patctl.jit = JIT_DEFAULT; /* full & partial */ #ifndef SUPPORT_JIT - fprintf(stderr, "** Warning: JIT support is not available: " + cfprintf(clr_test_error, stderr, "pcre2test: Warning: JIT support is not available: " "-jit[fast|verify] calls functions that do nothing.\n"); #endif } @@ -9694,12 +3851,12 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) { if (uli == 0) { - fprintf(stderr, "** Argument for %s must not be zero\n", arg); + cfprintf(clr_test_error, stderr, "pcre2test: Argument for %s must not be zero\n", arg); exit(1); } if (U32OVERFLOW(uli)) { - fprintf(stderr, "** Argument for %s is too big\n", arg); + cfprintf(clr_test_error, stderr, "pcre2test: Argument for %s is too big\n", arg); exit(1); } timeitm = (int)uli; @@ -9710,6 +3867,13 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) if (both) timeit = timeitm; } + /* Set malloc testing */ + + else if (strcmp(arg, "-malloc") == 0) + { + malloc_testing = TRUE; + } + /* Give help */ else if (strcmp(arg, "-help") == 0 || @@ -9749,7 +3913,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) CHECK_VALUE_EXISTS: if (argc <= 2) { - fprintf(stderr, "** Missing value for %s\n", arg); + cfprintf(clr_test_error, stderr, "pcre2test: Missing value for %s\n", arg); yield = 1; goto EXIT; } @@ -9757,11 +3921,31 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) argc--; } + else if (strcmp(arg, "--color") == 0 || strcmp(arg, "--colour") == 0) + { + colour_setting = COLOUR_ALWAYS; + } + + else if (strstr(arg, "--color=") == arg || strstr(arg, "--colour=") == arg) + { + char *val = strchr(arg, '=') + 1; + if (strcmp(val, "always") == 0) colour_setting = COLOUR_ALWAYS; + else if (strcmp(val, "never") == 0) colour_setting = COLOUR_NEVER; + else if (strcmp(val, "auto") == 0) colour_setting = COLOUR_AUTO; + else + { + cfprintf(clr_test_error, stderr, + "pcre2test: Invalid value for \"%.*s\"\n", (int)(val - 1 - arg), arg); + yield = 1; + goto EXIT; + } + } + /* Unrecognized option */ else { - fprintf(stderr, "** Unknown or malformed option \"%s\"\n", arg); + cfprintf(clr_test_error, stderr, "pcre2test: Unknown or malformed option \"%s\"\n", arg); usage(); yield = 1; goto EXIT; @@ -9775,78 +3959,24 @@ We wait to do this until we know which mode we are in. */ if (arg_error != NULL) { - int len; int errcode; char *endptr; - -/* Ensure the relevant non-8-bit buffer is available. Ensure that it is at -least 128 code units, because it is used for retrieving error messages. */ - -#ifdef SUPPORT_PCRE2_16 - if (test_mode == PCRE16_MODE) - { - pbuffer16_size = 256; - pbuffer16 = (uint16_t *)malloc(pbuffer16_size); - if (pbuffer16 == NULL) - { - fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n", - pbuffer16_size); - yield = 1; - goto EXIT; - } - } -#endif - -#ifdef SUPPORT_PCRE2_32 - if (test_mode == PCRE32_MODE) - { - pbuffer32_size = 512; - pbuffer32 = (uint32_t *)malloc(pbuffer32_size); - if (pbuffer32 == NULL) - { - fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n", - pbuffer32_size); - yield = 1; - goto EXIT; - } - } -#endif + long li; /* Loop along a list of error numbers. */ for (;;) { - errcode = strtol(arg_error, &endptr, 10); - if (*endptr != 0 && *endptr != CHAR_COMMA) + li = strtol(arg_error, &endptr, 10); + if (S32OVERFLOW(li) || (*endptr != 0 && *endptr != ',')) { - fprintf(stderr, "** \"%s\" is not a valid error number list\n", arg_error); + cfprintf(clr_test_error, stderr, "pcre2test: \"%s\" is not a valid error number list\n", arg_error); yield = 1; goto EXIT; } + errcode = (int)li; printf("Error %d: ", errcode); - PCRE2_GET_ERROR_MESSAGE(len, errcode, pbuffer); - if (len < 0) - { - switch (len) - { - case PCRE2_ERROR_BADDATA: - printf("PCRE2_ERROR_BADDATA (unknown error number)"); - break; - - case PCRE2_ERROR_NOMEMORY: - printf("PCRE2_ERROR_NOMEMORY (buffer too small)"); - break; - - default: - printf("Unexpected return (%d) from pcre2_get_error_message()", len); - break; - } - } - else - { - PCHARSV(CASTVAR(void *, pbuffer), 0, len, FALSE, stdout); - } - printf("\n"); + print_error_message_file(stdout, errcode, "", "\n", TRUE); if (*endptr == 0) goto EXIT; arg_error = endptr + 1; } @@ -9855,70 +3985,13 @@ least 128 code units, because it is used for retrieving error messages. */ } /* End of -error handling */ /* Initialize things that cannot be done until we know which test mode we are -running in. Exercise the general context copying and match data size functions, -which are not otherwise used. */ +running in. */ -code_unit_size = test_mode/8; max_oveccount = DEFAULT_OVECCOUNT; -/* Use macros to save a lot of duplication. */ - -#define CREATECONTEXTS \ - G(general_context,BITS) = G(pcre2_general_context_create_,BITS)(&my_malloc, &my_free, NULL); \ - G(general_context_copy,BITS) = G(pcre2_general_context_copy_,BITS)(G(general_context,BITS)); \ - G(default_pat_context,BITS) = G(pcre2_compile_context_create_,BITS)(G(general_context,BITS)); \ - G(pat_context,BITS) = G(pcre2_compile_context_copy_,BITS)(G(default_pat_context,BITS)); \ - G(default_dat_context,BITS) = G(pcre2_match_context_create_,BITS)(G(general_context,BITS)); \ - G(dat_context,BITS) = G(pcre2_match_context_copy_,BITS)(G(default_dat_context,BITS)); \ - G(default_con_context,BITS) = G(pcre2_convert_context_create_,BITS)(G(general_context,BITS)); \ - G(con_context,BITS) = G(pcre2_convert_context_copy_,BITS)(G(default_con_context,BITS)); \ - G(match_data,BITS) = G(pcre2_match_data_create_,BITS)(max_oveccount, G(general_context,BITS)) - -#define CONTEXTTESTS \ - (void)G(pcre2_set_compile_extra_options_,BITS)(G(pat_context,BITS), 0); \ - (void)G(pcre2_set_max_pattern_length_,BITS)(G(pat_context,BITS), 0); \ - (void)G(pcre2_set_max_pattern_compiled_length_,BITS)(G(pat_context,BITS), 0); \ - (void)G(pcre2_set_max_varlookbehind_,BITS)(G(pat_context,BITS), 0); \ - (void)G(pcre2_set_offset_limit_,BITS)(G(dat_context,BITS), 0); \ - (void)G(pcre2_get_match_data_size_,BITS)(G(match_data,BITS)) - -/* Call the appropriate functions for the current mode, and exercise some -functions that are not otherwise called. */ - -#ifdef SUPPORT_PCRE2_8 -#undef BITS -#define BITS 8 -if (test_mode == PCRE8_MODE) - { - CREATECONTEXTS; - CONTEXTTESTS; - } -#endif - -#ifdef SUPPORT_PCRE2_16 -#undef BITS -#define BITS 16 -if (test_mode == PCRE16_MODE) - { - CREATECONTEXTS; - CONTEXTTESTS; - } -#endif - -#ifdef SUPPORT_PCRE2_32 -#undef BITS -#define BITS 32 -if (test_mode == PCRE32_MODE) - { - CREATECONTEXTS; - CONTEXTTESTS; - } -#endif - -/* Set a default parentheses nest limit that is large enough to run the -standard tests (this also exercises the function). */ +/* Initialise the globals for the current mode. */ -PCRE2_SET_PARENS_NEST_LIMIT(default_pat_context, PARENS_NEST_DEFAULT); +init_globals(); /* Handle command line modifier settings, sending any error messages to stderr. We need to know the mode before modifying the context, and it is tidier @@ -9944,7 +4017,7 @@ if (argc > 1 && strcmp(argv[op], "-") != 0) infile = fopen(argv[op], INPUT_MODE); if (infile == NULL) { - printf("** Failed to open \"%s\": %s\n", argv[op], strerror(errno)); + cfprintf(clr_test_error, stderr, "pcre2test: Failed to open \"%s\": %s\n", argv[op], strerror(errno)); yield = 1; goto EXIT; } @@ -9959,7 +4032,7 @@ if (argc > 2) outfile = fopen(argv[op+1], OUTPUT_MODE); if (outfile == NULL) { - printf("** Failed to open \"%s\": %s\n", argv[op+1], strerror(errno)); + cfprintf(clr_test_error, stderr, "pcre2test: Failed to open \"%s\": %s\n", argv[op+1], strerror(errno)); yield = 1; goto EXIT; } @@ -9969,8 +4042,6 @@ if (argc > 2) if (!quiet) print_version(outfile, TRUE); -SET(compiled_code, NULL); - #ifdef SUPPORT_PCRE2_8 preg.re_pcre2_code = NULL; preg.re_match_data = NULL; @@ -9978,26 +4049,52 @@ preg.re_match_data = NULL; while (notdone) { - uint8_t *p; + const uint8_t *p; + const uint8_t *p_notsp; int rc = PR_OK; - BOOL expectdata = TEST(compiled_code, !=, NULL); + BOOL expectdata = have_active_pattern(); + BOOL is_pattern_comment; + BOOL is_data_comment; #ifdef SUPPORT_PCRE2_8 expectdata |= preg.re_pcre2_code != NULL; #endif if (extend_inputline(infile, buffer, expectdata? "data> " : " re> ") == NULL) break; - if (!INTERACTIVE(infile)) fprintf(outfile, "%s", (char *)buffer); + + /* Pre-process input lines with #if...#endif. */ + + if (skipping_endif) + { + if (strncmp((char*)buffer, "#endif", 6) != 0 || + !(buffer[6] == 0 || isspace(buffer[6]))) + continue; + skipping_endif = FALSE; + } + + /* Begin processing the line. */ + + p = p_notsp = buffer; + while (isspace(*p_notsp)) p_notsp++; + + is_pattern_comment = p[0] == '#' && + (isspace(p[1]) || p[1] == '!' || p[1] == 0); + is_data_comment = expectdata && p_notsp[0] == '\\' && p_notsp[1] == '=' && + (isspace(p_notsp[2]) || p_notsp[2] == 0); + + if (!INTERACTIVE(infile)) + cfprintf((is_pattern_comment || is_data_comment)? clr_comment : clr_input, + outfile, "%s", (char *)buffer); fflush(outfile); - p = buffer; + + if (preprocess_only && *p != '#') continue; /* If we have a pattern set up for testing, or we are skipping after a compile failure, a blank line terminates this test. */ if (expectdata || skipping) { - while (isspace(*p)) p++; - if (*p == 0) + if (*p_notsp == 0) { #ifdef SUPPORT_PCRE2_8 if (preg.re_pcre2_code != NULL) @@ -10007,11 +4104,7 @@ while (notdone) preg.re_match_data = NULL; } #endif /* SUPPORT_PCRE2_8 */ - if (TEST(compiled_code, !=, NULL)) - { - SUB1(pcre2_code_free, compiled_code); - SET(compiled_code, NULL); - } + free_active_pattern(); skipping = FALSE; setlocale(LC_CTYPE, "C"); } @@ -10019,7 +4112,7 @@ while (notdone) /* Otherwise, if we are not skipping, and the line is not a data comment line starting with "\=", process a data line. */ - else if (!skipping && !(p[0] == '\\' && p[1] == '=' && isspace(p[2]))) + else if (!skipping && !is_data_comment) { rc = process_data(); } @@ -10028,12 +4121,13 @@ while (notdone) /* We do not have a pattern set up for testing. Lines starting with # are either comments or special commands. Blank lines are ignored. Otherwise, the line must start with a valid delimiter. It is then processed as a pattern - line. A copy of the pattern is left in pbuffer8 for use by callouts. Under - valgrind, make the unused part of the buffer undefined, to catch overruns. */ + line. The pattern remains in pbuffer8/16/32 after compilation, for use by + callouts. Under valgrind, make the unused part of the buffer undefined, to + catch overruns. */ else if (*p == '#') { - if (isspace(p[1]) || p[1] == '!' || p[1] == 0) continue; + if (is_pattern_comment) continue; rc = process_command(); } @@ -10045,19 +4139,19 @@ while (notdone) else { - while (isspace(*p)) p++; - if (*p != 0) + if (*p_notsp != 0) { - fprintf(outfile, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer, + cfprintf(clr_test_error, outfile, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer, *buffer); rc = PR_SKIP; } } if (rc == PR_SKIP && !INTERACTIVE(infile)) skipping = TRUE; + else if (rc == PR_ENDIF) skipping_endif = TRUE; else if (rc == PR_ABEND) { - fprintf(outfile, "** pcre2test run abandoned\n"); + cfprintf(clr_test_error, outfile, "** pcre2test run abandoned\n"); yield = 1; goto EXIT; } @@ -10065,23 +4159,30 @@ while (notdone) /* Finish off a normal run. */ +if (skipping_endif) + { + cfprintf(clr_test_error, outfile, "** Expected #endif\n"); + yield = 1; + goto EXIT; + } + if (INTERACTIVE(infile)) fprintf(outfile, "\n"); if (showtotaltimes) { const char *pad = ""; - fprintf(outfile, "--------------------------------------\n"); + cfprintf(clr_profiling, outfile, "--------------------------------------\n"); if (timeit > 0) { - fprintf(outfile, "Total compile time %8.2f microseconds\n", + cfprintf(clr_profiling, outfile, "Total compile time %8.2f microseconds\n", ((1000000 / CLOCKS_PER_SEC) * (double)total_compile_time) / timeit); if (total_jit_compile_time > 0) - fprintf(outfile, "Total JIT compile %8.2f microseconds\n", + cfprintf(clr_profiling, outfile, "Total JIT compile %8.2f microseconds\n", ((1000000 / CLOCKS_PER_SEC) * (double)total_jit_compile_time) / \ timeit); pad = " "; } - fprintf(outfile, "Total match time %s%8.2f microseconds\n", pad, + cfprintf(clr_profiling, outfile, "Total match time %s%8.2f microseconds\n", pad, ((1000000 / CLOCKS_PER_SEC) * (double)total_match_time) / timeitm); } @@ -10095,57 +4196,22 @@ if (infile != NULL && INTERACTIVE(infile)) clear_history(); if (infile != NULL && infile != stdin) fclose(infile); if (outfile != NULL && outfile != stdout) fclose(outfile); -free(buffer); -free(dbuffer); -free(pbuffer8); -free(dfa_workspace); -free(tables3); -PCRE2_MAKETABLES_FREE(general_context, (const void *)locale_tables); -PCRE2_MATCH_DATA_FREE(match_data); -SUB1(pcre2_code_free, compiled_code); - -while(patstacknext-- > 0) - { - SET(compiled_code, patstack[patstacknext]); - SUB1(pcre2_code_free, compiled_code); - } - -PCRE2_JIT_FREE_UNUSED_MEMORY(general_context); -if (jit_stack != NULL) - { - PCRE2_JIT_STACK_FREE(jit_stack); - } - -#define FREECONTEXTS \ - G(pcre2_general_context_free_,BITS)(G(general_context,BITS)); \ - G(pcre2_general_context_free_,BITS)(G(general_context_copy,BITS)); \ - G(pcre2_compile_context_free_,BITS)(G(pat_context,BITS)); \ - G(pcre2_compile_context_free_,BITS)(G(default_pat_context,BITS)); \ - G(pcre2_match_context_free_,BITS)(G(dat_context,BITS)); \ - G(pcre2_match_context_free_,BITS)(G(default_dat_context,BITS)); \ - G(pcre2_convert_context_free_,BITS)(G(default_con_context,BITS)); \ - G(pcre2_convert_context_free_,BITS)(G(con_context,BITS)); - #ifdef SUPPORT_PCRE2_8 -#undef BITS -#define BITS 8 if (preg.re_pcre2_code != NULL) regfree(&preg); -FREECONTEXTS; #endif +free(buffer); +free(dbuffer); +free(pbuffer8); #ifdef SUPPORT_PCRE2_16 -#undef BITS -#define BITS 16 free(pbuffer16); -FREECONTEXTS; #endif - #ifdef SUPPORT_PCRE2_32 -#undef BITS -#define BITS 32 free(pbuffer32); -FREECONTEXTS; #endif +free(dfa_workspace); +free(tables3); +free_globals(); #if defined(__VMS) yield = SS$_NORMAL; /* Return values via DCL symbols */ diff --git a/src/pcre2test_inc.h b/src/pcre2test_inc.h new file mode 100644 index 0000000..8124e9c --- /dev/null +++ b/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/testdata/grepoutput b/testdata/grepoutput index f4e8996..13b0c7d 100644 --- a/testdata/grepoutput +++ b/testdata/grepoutput @@ -100,7 +100,7 @@ RC=0 ./testdata/grepinputx:To pat or not to pat, that is the question. RC=0 ---------------------------- Test 15 ----------------------------- -pcre2grep: Error in command-line regex at offset 4: quantifier does not follow a repeatable item +pcre2grep: Error in command-line regex at offset 5: quantifier does not follow a repeatable item RC=2 ---------------------------- Test 16 ----------------------------- pcre2grep: Failed to open ./testdata/nonexistfile: No such file or directory @@ -435,7 +435,7 @@ RC=0 597:binary RC=0 ---------------------------- Test 46 ------------------------------ -pcre2grep: Error in 1st command-line regex at offset 8: unmatched closing parenthesis +pcre2grep: Error in 1st command-line regex at offset 9: unmatched closing parenthesis RC=2 pcre2grep: Error in 2nd command-line regex at offset 9: missing closing parenthesis RC=2 @@ -989,7 +989,7 @@ RC=0 ---------------------------- Test 126 ----------------------------- ABCXYZ RC=0 -pcre2grep: Error in regex in line 2 of testtemp1grep at offset 4: unmatched closing parenthesis +pcre2grep: Error in regex in line 2 of testtemp1grep at offset 5: unmatched closing parenthesis RC=2 ---------------------------- Test 127 ----------------------------- pattern diff --git a/testdata/testinput1 b/testdata/testinput1 index 76a6308..64b697f 100644 --- a/testdata/testinput1 +++ b/testdata/testinput1 @@ -23,9 +23,13 @@ What do you know about the quick brown fox? What do you know about THE QUICK BROWN FOX? +#if !ebcdic + /abcd\t\n\r\f\a\e\071\x3b\$\\\?caxyz/ abcd\t\n\r\f\a\e9;\$\\?caxyz +#endif + /a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz/ abxyzpqrrrabbxyyyypqAzz abxyzpqrrrabbxyyyypqAzz @@ -107,9 +111,13 @@ bababbc babababc +#if !ebcdic + /^\ca\cA\c[;\c:/ \x01\x01\e;z +#endif + /^[ab\]cde]/ athing bthing @@ -243,7 +251,7 @@ \= Expect no match 1IN SOA non-sp1 non-sp2( -/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-z\d\-]*)*\.$/ +/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-Z\d\-]*)*\.$/ a. Z. 2. @@ -466,6 +474,8 @@ /^[ab]{1,3}(ab*?|b)/ aabbbbb +#if !ebcdic + / (?: [\040\t] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] )* \) )* \) )* # optional leading comment @@ -1262,6 +1272,8 @@ \= Expect no match The quick brown fox +#endif + /abc\0def\00pqr\000xyz\0000AB/ abc\0def\00pqr\000xyz\0000AB abc456 abc\0def\00pqr\000xyz\0000ABCDE @@ -1359,6 +1371,8 @@ /([^.]*)\.([^:]*):[t ]+(.*)/i track1.title:TBlah blah blah +#if !ebcdic + /^[W-c]+$/ WXY_^abc \= Expect no match @@ -1372,6 +1386,8 @@ WXY_^abc wxy_^ABC +#endif + /^abc$/m abc qqq\nabc @@ -1427,6 +1443,8 @@ \= Expect no match aaa +#if !ebcdic + /\x5c/ \\ @@ -1435,6 +1453,8 @@ \= Expect no match Zulu +#endif + /(abc)\1/i abcabc ABCabc @@ -1446,6 +1466,8 @@ \= Expect no match abc\ndef +#if !ebcdic + /(abc)\123/ abc\x53 @@ -1466,6 +1488,8 @@ abc\100\x30 abc\100\060 abc\100\60 + +#endif /^(A)(B)(C)(D)(E)(F)(G)(H)(I)\8\9$/ ABCDEFGHIHI @@ -1475,21 +1499,29 @@ \= Expect no match A8B9C\x00 +#if !ebcdic + /(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\12\123/ abcdefghijkllS /(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\12\123/ abcdefghijk\12S +#endif + /a{0}bc/ bc /(a|(bc)){0,0}?xyz/ xyz +#if !ebcdic + /abc[\10]de/ abc\010de +#endif + /abc[\1]de/ abc\1de @@ -1567,9 +1599,13 @@ aaaabcd aaAabcd +#if !ebcdic + /\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377/ \000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377 +#endif + /P[^*]TAIRE[^*]{1,6}?LL/ xxxxxxxxxxxPSTAIREISLLxxxxxxxxx @@ -1640,6 +1676,8 @@ 42 [abcd] ]abcd[ + +#if !ebcdic /^[W-\]46]/ W46]789 @@ -1653,6 +1691,8 @@ \= Expect no match -46]789 well + +#endif /\d\d\/\d\d\/\d\d\d\d/ 01/01/2000 @@ -2834,6 +2874,54 @@ /ab??c/i ABC +/x?(x|b)/ + xb + +/x??(x|b)/ + x + +/x?(x|b)/i + Xb + +/x??(x|b)/i + X + +/x{,2}(x|b)/ + xb + +/x{,2}?(x|b)/ + x + +/x{,2}(x|b)/i + Xb + +/x{,2}?(x|b)/i + X + +/[^b]?([^b]|b)/ + xb + +/[^b]??([^b]|b)/ + x + +/[^b]?([^b]|b)/i + Xb + +/[^b]??([^b]|b)/i + X + +/[^b]{,2}([^b]|b)/ + xb + +/[^b]{,2}?([^b]|b)/ + x + +/[^b]{,2}([^b]|b)/i + Xb + +/[^b]{,2}?([^b]|b)/i + X + /ab{0,1}?c/i ABC @@ -3769,12 +3857,16 @@ Regex regulär +#if !ebcdic + /Åæåä[à-ÿÀ-ß]+/ Åæåäà Åæåäÿ ÅæåäÀ Åæåäß +#endif + /(?<=Z)X./ \x84XAZXB @@ -4284,10 +4376,14 @@ >XYZ > X NY Z +#if !ebcdic + /\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/ >XY\x0aZ\x0aA\x0bNN\x0c >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c +#endif + /(foo)\Kbar/ foobar @@ -5620,6 +5716,8 @@ name)/mark Ax BAxy +#if !ebcdic + /^A\xBz/ A\x{0B}z @@ -5632,6 +5730,8 @@ name)/mark /^A\o{123}B/ A\123B +#endif + / ^ a + + b $ /x aaaab @@ -5745,9 +5845,13 @@ name)/mark /A[\8]B[\9]C/ A8B9C +#if !ebcdic + /(?1)()((((((\1++))\x85)+)|))/ \x85\x85 +#endif + /(?|(\k'Pm')|(?'Pm'))/ abcd @@ -5895,6 +5999,8 @@ ef) x/x,mark /^(?1)\d{3}(a)/ a123a +#if !ebcdic + # This pattern uses a lot of named subpatterns in order to match email # addresses in various formats. It's a heavy test for named subpatterns. In the # group, slash is coded as \x{2f} so that this pattern can also be @@ -5953,9 +6059,13 @@ ef) x/x,mark \= Expect no match A missing angle (?P=abn)(?/xx @@ -6422,6 +6534,8 @@ ef) x/x,mark /a{1,2,3}b/ a{1,2,3}b +#if !ebcdic + /\214748364/ >\x{8c}748364< @@ -6437,6 +6551,8 @@ ef) x/x,mark /\21300000000/ \x8b00000000 +#endif + /a{65536/ >a{65536< @@ -6739,6 +6855,8 @@ $/x \\ n +#if !ebcdic + /^(?[\x61])b/ ab \= Expect no match @@ -6751,6 +6869,8 @@ $/x \= Expect no match b +#endif + /(?[ [[:graph:]] ])/ a \= Expect no match diff --git a/testdata/testinput10 b/testdata/testinput10 index 3309f5e..c4ee276 100644 --- a/testdata/testinput10 +++ b/testdata/testinput10 @@ -353,6 +353,10 @@ /abc/utf,never_utf +/(*UCP)abc/never_ucp + +/abc/ucp,never_ucp + /A\x{391}\x{10427}\x{ff3a}\x{1fb0}/IBi,utf /A\x{391}\x{10427}\x{ff3a}\x{1fb0}/IB,utf @@ -455,6 +459,10 @@ \= Expect no match 123 +/\p{ Aሴ}/utf + +/\p{BC: Aሴ}/utf + /(*:*++++++++++++''''''''''''''''''''+''+++'+++x+++++++++++++++++++++++++++++++++++(++++++++++++++++++++:++++++%++:''''''''''''''''''''''''+++++++++++++++++++++++++++++++++++++++++++++++++++++-++++++++k+++++++''''+++'+++++++++++++++++++++++''''++++++++++++':Æ¿)/utf /[\s[:^ascii:]]/B,ucp @@ -494,6 +502,10 @@ /(?(á/utf +/^\cÄ£/utf + +/(?'Ù ABC'...)/utf + # Invalid UTF-8 tests /.../g,match_invalid_utf diff --git a/testdata/testinput12 b/testdata/testinput12 index 9763f73..c618f02 100644 --- a/testdata/testinput12 +++ b/testdata/testinput12 @@ -250,6 +250,10 @@ /abc/utf,never_utf +/(*UCP)abc/never_ucp + +/abc/ucp,never_ucp + /A\x{391}\x{10427}\x{ff3a}\x{1fb0}/IBi,utf /A\x{391}\x{10427}\x{ff3a}\x{1fb0}/IB,utf @@ -360,7 +364,11 @@ /\pP/ucp \x{7fffffff} -# A special extra option allows excaped surrogate code points in 32-bit mode, +/\p{ Aሴ}/utf + +/\p{BC: Aሴ}/utf + +# A special extra option allows escaped surrogate code points in 32-bit mode, # but subjects containing them must not be UTF-checked. These patterns give # errors in 16-bit mode. @@ -399,6 +407,10 @@ /(?(á/utf +/^\cÄ£/utf + +/(?'Ù ABC'...)/utf + # Invalid UTF-16/32 tests. /.../g,match_invalid_utf diff --git a/testdata/testinput15 b/testdata/testinput15 index 081b9e2..2bf168c 100644 --- a/testdata/testinput15 +++ b/testdata/testinput15 @@ -223,9 +223,13 @@ aaa bbb +#if !ebcdic + /[^\xff]((?1))/BI abcd +#endif + # These tests don't behave the same with JIT /\w+(?C1)/BI,no_auto_possess diff --git a/testdata/testinput17 b/testdata/testinput17 index 7dd2d8e..08fd72e 100644 --- a/testdata/testinput17 +++ b/testdata/testinput17 @@ -275,9 +275,13 @@ aaa bbb +#if !ebcdic + /[^\xff]((?1))/BI abcd +#endif + /(x(?1)){4}/ /[axm]{7}/ @@ -313,4 +317,22 @@ /(...)-(...)/jitfast abc-xyz\=get=2 +# Check the JIT sets all the correct match state for pcre2_substitute + +/abc/jitfast,replace=yy + zabcz + zabcz\=substitute_matched + +/abc/jitfast,replace=yy + zABCz + zABCz\=substitute_matched + +/abc/jitfast + ab\=replace=yy,partial_hard + ab\=replace=yy,partial_hard,substitute_matched + +/(?C1)abc/jitfast,replace=yy + zabcz\=callout_error=1 + zabcz\=callout_error=1,substitute_matched + # End of testinput17 diff --git a/testdata/testinput18 b/testdata/testinput18 index de3645d..a398746 100644 --- a/testdata/testinput18 +++ b/testdata/testinput18 @@ -61,6 +61,12 @@ aaaabbbbzzzz\=ovector=1 aaaabbbbzzzz\=ovector=2 +/(a)(b)/ + ab\=posix_startend=0:2,ovector=1 + ab\=posix_startend=0:2,ovector=0 + ab\=posix_startend=1:2,ovector=1 + ab\=posix_startend=1:2,ovector=0 + /(*ANY)ab.cd/ ab-cd ab=cd @@ -107,6 +113,22 @@ /\[A]{1000000}**/expand,regerror_buffsize=32 +/a(b/regerror_buffsize=0 + +/a(b/regerror_buffsize=1 + +/a(b/regerror_buffsize=12 + +/a(b/regerror_buffsize=13 + +/a(b/regerror_buffsize=14 + +/a(b/regerror_buffsize=15 + +/a(b/regerror_buffsize=25 + +/a(b/regerror_buffsize=26 + //posix_nosub \=offset=70000 diff --git a/testdata/testinput19 b/testdata/testinput19 index 7b2ab91..9c33fec 100644 --- a/testdata/testinput19 +++ b/testdata/testinput19 @@ -22,4 +22,6 @@ \= Expect UTF error A\xabB +/ AB /hex,utf + # End of testdata/testinput19 diff --git a/testdata/testinput2 b/testdata/testinput2 index aa9ff30..65e88bc 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -1926,12 +1926,82 @@ a\x85b \= Expect no match a\rb + a\r\nb /^a.b/newline=any \= Expect no match a\nb a\rb + a\r\nb + a\x85b + +/^a.b/newline=nul + a\nb +\= Expect no match + a\x{00}b + +/^a./newline=lf + a\r +\= Expect no match + a\n + +/^a./newline=cr + a\n +\= Expect no match + a\r + +/^a./newline=anycrlf + a\x85 +\= Expect no match + a\r + a\n + a\r\n + +/^a./newline=any +\= Expect no match + a\n + a\r + a\r\n + a\x85 + +/^a./newline=nul + a\n +\= Expect no match + a\x{00} + +/^b/m,newline=lf + a\nb +\= Expect no match + a\rb + +/^b/m,newline=cr + a\rb +\= Expect no match + a\nb + +/^b/m,newline=anycrlf + a\rb + a\nb + a\r\nb + \nb + \rb + \r\nb +\= Expect no match + a\x85b + +/^b/m,newline=any + a\nb + a\rb + a\r\nb a\x85b + \nb + \rb + \r\nb + +/^b/m,newline=nul + a\x{00}b +\= Expect no match + a\nb /^abc./gmx,newline=any abc1 \x0aabc2 \x0babc3xx \x0cabc4 \x0dabc5xx \x0d\x0aabc6 \x85abc7 JUNK @@ -2144,8 +2214,12 @@ /\v*B/B +#if !ebcdic + /\V+\x0a/B +#endif + /A+\h/B / *\H/B @@ -3133,8 +3207,14 @@ \= Expect no match abc\=offset=3 +#if !ebcdic + /^\cÄ£/ +#endif + +/^\c/ + /(?P(?P=abn)xxx)/B /(a\1z)/B @@ -3413,6 +3493,8 @@ /(a\1z)/B +#if !ebcdic + /^a\x41z/alt_bsux,allow_empty_class,match_unset_backref,dupnames aAz \= Expect no match @@ -3450,6 +3532,8 @@ /^\u{7a}/extra_alt_bsux zoo +#endif + /\u{}/extra_alt_bsux u{} @@ -3919,11 +4003,15 @@ /[a-[=xxx=]]+/ +#if !ebcdic + /[a-[!xxx!]]+/ /[A-[!xxx!]]+/ A]]] +#endif + /[a-\d]+/ /(?<0abc>xx)/ @@ -4089,6 +4177,8 @@ /(?(VERSION=10.101)yes|no)/ +/(?(VERSION=10z)yes|no)/ + # We should see the starting code unit, required code unit, and minimum length set for this regex: /abcd/I @@ -4313,7 +4403,6 @@ /a(b)c/substitute_extended ZabcZ\=replace=>${1:+ yes : no } - ZabcZ\=replace=>${1:+ \o{100} : \o{100} } ZabcZ\=replace=>${1:+ \o{Z} : no } ZabcZ\=replace=>${1:+ yes : \o{Z} } ZabcZ\=replace=>${1:+ \g<1> : no } @@ -4325,6 +4414,13 @@ ZabcZ\=replace=>${1:+ $<1 : no } ZabcZ\=replace=>${1:+ yes : $<1 } +#if !ebcdic + +/a(b)c/substitute_extended + ZabcZ\=replace=>${1:+ \o{100} : \o{100} } + +#endif + /a(b)c/substitute_extended ZabcZ\=replace=>${ ZabcZ\=replace=>${1 @@ -4522,12 +4618,35 @@ # Perl loops on this (PCRE2 used to!) +# duplicate matches /(?<=\Ka)/g,aftertext,allow_lookaround_bsk aaaaa /(?<=\Ka)/altglobal,aftertext,allow_lookaround_bsk aaaaa +# overlapping matches +/(?(?=\Gc)(?<=\Kb)c|(?<=\Kab))/g,aftertext,allow_lookaround_bsk + abc + +# not-sorted matches +/(?(?=\Gc)(?<=\Kab)|(?<=\Kb))/g,aftertext,allow_lookaround_bsk + abc + +# CRLF cases + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=LF + back\rstart back\nstart back\r\nstart back\r + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=CRLF + back\rstart back\nstart back\r\nstart back\r + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=ANYCRLF + back\rstart back\nstart back\r\nstart back\r + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=ANY + back\rstart back\nstart back\r\nstart back\r + /((?2){73}(?2))((?1))/info /abc/ @@ -4537,6 +4656,12 @@ /(abc)*/ \[abc]{5} +/(abc)*/ + \[abc]{1} + +/(abc)*/ + \[abc]{0} + /^/gm \n\n\n @@ -4689,6 +4814,21 @@ \= Expect no match aacb +/(^aa(*MARK:X)a(*SKIP:X)c|(?!^)a+b)/g + aaab + +/(^aa(*MARK:X)a(*SKIP:Y)c|(?!^)a+b)/g + aaab + +/(^aa(*MARK:Y)a(*SKIP:X)c|(?!^)a+b)/g + aaab + +/(^aa(*MARK:X)a(*SKIP:XX)c|(?!^)a+b)/g + aaab + +/(^aa(*MARK:XX)a(*SKIP:X)c|(?!^)a+b)/g + aaab + /(*MARK:a\zb)z/alt_verbnames /(*:ab\t(d\)c)xxx/ @@ -4755,11 +4895,15 @@ B)x/alt_verbnames,mark abcd\=null_context,find_limits abcd\=allusedtext,startchar +#if !ebcdic + /abcd/replace=w\rx\x82y\o{333}z(\Q12\$34$$\x34\E5$$),substitute_extended abcd /abcd/replace=w\rx\x82y\o{333}z(\Q12\$34$$\x34\E5$$),substitute_extended,substitute_literal >>abcd<< + +#endif /abcd/g,replace=\$1$2\,substitute_literal XabcdYabcdZ @@ -4826,6 +4970,8 @@ B)x/alt_verbnames,mark /abcd/g >abcd1234abcd5678<\=replace=wxyz,substitute_matched +#if !ebcdic + /abc/substitute_extended,replace=>\045< abc @@ -4835,6 +4981,8 @@ B)x/alt_verbnames,mark /abc/substitute_extended,replace=>\o{45}< abc +#endif + /abc/substitute_extended,replace=>\845< abc @@ -4862,6 +5010,34 @@ B)x/alt_verbnames,mark LabcR\=replace=>$'< LabcR\=replace=>$_< +/A(.)|B(.)/ + AMZ\=replace=>$+< + BMZ\=replace=>$+< + AMZ\=replace=>$+ + AMZ\=replace=>$+{name} + BMZ\=ovector=2 + BMZ\=ovector=3 + BMZ\=ovector=2,replace=>$+< + BMZ\=ovector=3,replace=>$+< + BMZ\=ovector=2,substitute_matched,replace=>$+< + BMZ\=ovector=3,substitute_matched,replace=>$+< + +/A|(B)/ + B\=replace=>$1< + A\=replace=>$1< + B\=substitute_unset_empty,replace=>$1< + A\=substitute_unset_empty,replace=>$1< + B\=replace=>$+< + A\=replace=>$+< + B\=substitute_unset_empty,replace=>$+< + A\=substitute_unset_empty,replace=>$+< + +/ABC/ + ABC\=replace=$+z + ABC\=substitute_unknown_unset,replace=$+z + ABC\=substitute_unset_empty,replace=$+z + ABC\=substitute_unknown_unset,substitute_unset_empty,replace=$+z + /^(o(\1{72}{\"{\\{00000059079}\d*){74}}){19}/I /((p(?'K/ @@ -4972,8 +5148,12 @@ a)"xI /()\Q\E*]/B,auto_callout a[bc]d +#if !ebcdic + /\x8a+f|;T?(*:;.'?`(\xeap ){![^()!y*''C*(?';]{1;(\x08)/B,alt_verbnames,dupnames,extended +#endif + # Tests for NULL characters in comments and verb "names" and callouts # /A#B\x00C\x0aZ/ @@ -5956,6 +6136,16 @@ a)"xI # ---- Non-atomic assertion tests ---- +/(*ploo:abc)/ + +/(*pla:abc/ + +/(*pla:/ + +/(*pla/ + +/(*pla}abc)/ + # Expect error: not allowed as a condition /(?(*napla:xx)bc)/ @@ -6069,6 +6259,8 @@ a)"xI /(?(VERSION=10.3)b)((?<=b).*)/B +/(?(VERSION>=10.3)b)((?<=b).*)/B + /[aA]b[cC]/IB /[cc]abcd/I @@ -6159,6 +6351,8 @@ a)"xI "(?<=X(?(DEFINE)(.*))(?1))." +#if !ebcdic + /\sxxx\s/tables=1 \= Expect no match AB\x{85}xxx\x{a0}XYZ @@ -6177,6 +6371,8 @@ a)"xI /^\w+/tables=3 École +#endif + /"(*MARK:>" 00 "<).."/hex,mark,no_start_optimize AB A\=ph @@ -6210,7 +6406,42 @@ a)"xI /^abc(?b\K))a(?=(?&sneaky))/g,allow_lookaround_bsk + ab + +/(?(DEFINE)(?b\K))a(?=(?&sneaky))/g + ab + zz + +/a|(?(DEFINE)(?\Ka))(?<=(?&sneaky))b/g,allow_lookaround_bsk + ab + +/a|(?(DEFINE)(?\Ka))(?<=(?&sneaky))b/g + ab + zz + +/a|(?(DEFINE)(?\K\Ga))(?<=(?&sneaky))b/g + ab + zz + +/(?=.{10}(?1))x(\K){0}/ + x1234567890 + +/(?=.{10}(.))(*scs:(1)(?2))x(\K){0}/ + x1234567890 + +/(?=.{5}(?1))\d*(\K){0}/ +\= Totally fine - pattern does nothing bad even though \K is reachable + 1234567890 +\= Not fine - the subject now causes the \K to misbehave + abcdefgh + # --------- # Tests for zero-length NULL to be treated as an empty string. @@ -6225,6 +6456,9 @@ a)"xI \=null_subject \=null_replacement +/abc/replace= + XabcY\=null_replacement + /X*/g,replace=xy \= Expect error >X<\=null_replacement @@ -6678,6 +6912,16 @@ a)"xI /(a)(b+)(*scs:(1)a(*ACCEPT))(\2)/ abbb +# Duplicated capture references + +/(a)(b)(c)(d)(*scs:(4,3,1,2,2,1,3,3,4,4)x)/B + +/(?a)(?b)(?c)(d)(*scs:(2,3,1,1,,)abc)/B,dupnames + +/(?a)(?b)(?c)(d)(*scs:(2,1,1,,)abc)/B,dupnames + +/(?a)(?b)(?c)(d)(?e)(?f)(*scs:(,5,3,2,1,4,1,4,,6,,)abc)/B,dupnames + # Tests for pcre2_set_optimize() /abc/I,optimization_none @@ -6731,6 +6975,8 @@ a)"xI # python_octal +#if !ebcdic + /\0-\00-\01-\012-\0123-\123-\1234/ \x00-\x00-\x01-\o{12}-\o{12}3-\o{123}-\o{123}4 @@ -6756,6 +7002,8 @@ a)"xI abc\=replace=\1 abc\=replace=\12 +#endif + # -------------- /a(?C)b/ @@ -7328,20 +7576,28 @@ a)"xI /[\\z]/B +#if !ebcdic + /[0-z]/B +#endif + /[0\-z]/B /[]z]/B /[ \]]/B +#if !ebcdic + /[ --]/B /[A-\]]/B /[A-\\]/B +#endif + /[\A]/ /[\Z]/ @@ -7373,11 +7629,15 @@ a)"xI \= Expect no match \\ +#if !ebcdic + /[a\x{e1}]/iB a A \x{e1} +#endif + # -------------- # Attempt at full coverage of the substitution buffer-management code - not @@ -7447,6 +7707,8 @@ a)"xI XacY\=replace=[2]$1 XacY\=substitute_overflow_length,replace=[2]$1 +#if !ebcdic + # a data character via an escape /abc/substitute_extended XabcY\=replace=\x{48} @@ -7454,6 +7716,8 @@ a)"xI XabcY\=substitute_overflow_length,replace=[1]\x{48} XXabcY\=substitute_overflow_length,replace=[1]\x{48} +#endif + # a replacement literal character /abc/ XabcY\=replace=Z @@ -7516,6 +7780,8 @@ a)"xI XacY\=replace=[2]\U$1 XacY\=substitute_overflow_length,replace=[2]\U$1 +#if !ebcdic + # a data character via an escape /abc/substitute_extended XabcY\=replace=\U\x{48} @@ -7524,6 +7790,8 @@ a)"xI XXabcY\=substitute_overflow_length,replace=[1]\U\x{48} XabcY\=substitute_case_callout,replace=\U\x{48} +#endif + # a replacement literal character /abc/substitute_extended XabcY\=replace=\UZ @@ -7774,4 +8042,236 @@ a)"xI # -------------- +# Tests for recurse with returned captures + +# Parse error tests + +/(?1/ + +/(?1(/ + +/(?R(1/ + +/(?R(1,/ + +/(?R0(1,2!/ + +/(?1(1,0))()/ + +/(?1(1,+2))()/ + +/(?1())/ + +# Operation tests + +/^(?1(2))\2(?(DEFINE)(a(.)b(.)c))/B + axbycx +\= Expect no match + axby + axbycy + +/^((.)(?.))(?1('id'))(.)/B + abcde + +/^(?1(3,2,2,3,2))(?1(3))(?(DEFINE)(a(.)b(.)c))/B + a1b2cafbgc + +/(?1(2))#(?1(3))#(?1(4))#(?(DEFINE)((.)\2(.)\3(.)\4))/ + aabbcc#ddeeff#gghhii!aabbcc#ddeeff#gghhii# +\= Expect no match + aabbcc#ddeeff#gghhii + +/^(?1(1,2)){2,4}(?(DEFINE)((..)#))xx#/B + aa#bb#xx# + aa#bb#cc#xx# + aa#bb#cc#dd#xx# +\= Expect no match + aa#xx# + aa#bb#cc#dd#ee#xx# + +/^(?1(1,2)){2,}+(?(DEFINE)((..)#))!/B + aa#bb#! + aa#bb#cc#dd#ee#! +\= Expect no match + aa#! + aa#bb#cc#dd#ee# + +/^(?1)(?(DEFINE)(<(?2(3,4))><\4\3>)((..)(..)))/ + + +/(?1)#(?(DEFINE)(a(.(*ACCEPT).)b))/ + #axyb#axax# + +/^(?>(?1()))!(?(DEFINE)((?..)(?..)))|abcde/dupnames + abcd! + abcde + +/<(?:[^<>]*?(?:(AB)[^<>]*|)(?:|(?R(1))))+>/ + cc

    ee> + dd>eehh>ii> + dd>ee + cc
    AB> + cc
    ee> + dd>ee + dd>eehh>ii> + dd>eehABhABh>ii> + +/(?:(?1())#){4}(?(DEFINE)((?()\2)(?.{3})))$/ + abc#abcdef#defghi#ghijkl# + abc#abcdef#defghi#ghijkl#jklmno# + abc#abcdef#defghi#ghijkl#jklmno#mnopqr# +\= Expect no match + abc#abcdef#defghi#ghijkl + abc#abcdef#defghi#ghXjkl# + +% # Define the routine "weekendday" which matches Saturday or Sunday, and + # returns the Sat/Sun prefix as \k. + (?(DEFINE)(?(?|(?Sat)urday|(?Sun)day))) + # Call the routine. Matches "Saturday,Sat" or "Sunday,Sun". + (?&weekendday()),\k %x + Saturday,Sat + Sunday,Sun +\= Expect no match + Saturday,Sun + +/()()()(?2(2,3,2,3,2))/B + abc + +# Test each syntax used for recursion + +/(?(R)(Sat)urday|(?R(1)),\1)/ + Saturday,Sat + +/(?(DEFINE)((Sat)urday))(?1(2)),\2/ + Saturday,Sat + +/(?(DEFINE)((Sat)urday))(?-2(-1)),\2/ + Saturday,Sat + +/(?+1(+2)),\2(?(DEFINE)((Sat)urday))/ + Saturday,Sat + +/(?(DEFINE)(?(?Sat)urday))(?&fn('ret')),\k/ + Saturday,Sat + +/(?(DEFINE)(?(?Sat)urday))(?P>fn()),\k/ + Saturday,Sat + +/(?(DEFINE)(?(?Sat)urday))\g,\k/ + +/(?(DEFINE)((Sat)urday))(?1),\2/ +\= Expect no match + Saturday,Sat + +/(?(DEFINE)((Sat)urday))(?1()),\2/ + +/(?(DEFINE)((Sat)(urday)))(?1(2,3)),\2,\3/ + Saturday,Sat,urday + +# -------------- + +# Test that a memory leak has been fixed +/x/replace=r,substitute_matched + x\=null_subject + +# Test that a couple of double frees have been fixed +/foo/replace=bar,substitute_matched + foo\=copy_matched_subject + foo\=global,copy_matched_subject + +# Tests for reading matches from NULL subjects +/(.?)/ + \=null_subject,copy=0,copy=1,get=0,get=1,getall + +# -------------- +# A batch of additional tests of pcre2_substitute error cases +# -------------- + +# Some baseline tests of the NULL-handling cases + +/\w+|^$/replace=<$&>,global + ::: + \=null_subject + foo\=zero_terminate + \=null_subject,zero_terminate + foo|bar\=offset=1 + +/\w+|^$/replace=<$&>,global,substitute_matched + ::: + \=null_subject + foo\=zero_terminate + \=null_subject,zero_terminate + foo|bar\=offset=1 + +/\w+|^$/replace=<$&>,global,null_substitute_match_data + ::: + \=null_subject + foo\=zero_terminate + \=null_subject,zero_terminate + foo|bar\=offset=1 + +/\w+|^$/replace=<$&>,global,substitute_matched,null_substitute_match_data + ::: + \=null_subject + foo\=zero_terminate + \=null_subject,zero_terminate + foo|bar\=offset=1 + +# Now some NULL context tests + +/\w+|^$/replace=<$&>,global + :::\=null_context + foo\=null_context + :::\=null_context,null_substitute_match_data + foo\=null_context,null_substitute_match_data + :::\=null_context,substitute_matched + foo\=null_context,substitute_matched + :::\=null_context,null_substitute_match_data,substitute_matched + foo\=null_context,null_substitute_match_data,substitute_matched + +# Failed matches: no-match; partial; other failure (callout-triggered) + +/abc/replace=yy + zABCz + zABCz\=substitute_matched + +/abc/ + ab\=replace=yy,partial_hard + ab\=replace=yy,partial_hard,substitute_matched + +/(?C1)abc/replace=yy + zabcz\=callout_error=1 + zabcz\=callout_error=1,substitute_matched + +# Exercise PCRE2_ERROR_DIFFSUBSSUBJECT branches + +# Changing the length is always an error +# (using PCRE2_ZERO_TERMINATED but with different length strings also counts) +# Using PCRE2_ZERO_TERMINATED vs a concrete length doesn't count as changing the length +/\w+|^$/replace=<$&>,global,substitute_matched + foo\=substitute_subject=foo + foo\=substitute_subject=foo,copy_matched_subject + foo\=substitute_subject=foo,zero_terminate + foo\=substitute_subject=f + foo\=substitute_subject=f,copy_matched_subject + foo\=substitute_subject=f,zero_terminate + \ + \=copy_matched_subject + \=zero_terminate + \=null_subject + \=null_subject,copy_matched_subject + +# Keeping the length the same, the offset the same, and the pointer the same +# Is ok, even if the contents DIFFER +/\w+|^$/replace=<$&>,global,substitute_matched + foo|bar\=offset=1,substitute_subject=F|OOBAR + foo|bar\=offset=1,substitute_subject=F|OOBAR,zero_terminate + +# With copy_matched_subject however we are able to detect the mismatch +/\w+|^$/replace=<$&>,global,substitute_matched + foo|bar\=offset=1,substitute_subject=foo|bar,copy_matched_subject + foo|bar\=offset=1,substitute_subject=F|OOBAR,copy_matched_subject + foo|bar\=offset=1,substitute_subject=F|OOBAR,copy_matched_subject,zero_terminate + + # End of testinput2 diff --git a/testdata/testinput24 b/testdata/testinput24 index 380e23c..03cecf9 100644 --- a/testdata/testinput24 +++ b/testdata/testinput24 @@ -21,12 +21,20 @@ "[ab/cd]" +#if !ebcdic + "[,-/]" +#endif + /[ab/ # Length check +/abc/convert_length=0 + +/abc/convert_length=1 + /abc/convert_length=11 /abc/convert_length=12 @@ -144,6 +152,8 @@ \= Expect no match pic03.j/g +#if !ebcdic + /A[+-0]B/ A+B A.B @@ -151,6 +161,8 @@ \= Expect no match A/B +#endif + /*x?z/ abc.xyz \= Expect no match @@ -161,15 +173,21 @@ \= Expect no match .xyz +#if !ebcdic + "[,-0]x?z" ,xyz \= Expect no match /xyz .xyz +#endif + ".x*" .xabc +#if !ebcdic + /a[--0]z/ a-z a.z @@ -178,6 +196,8 @@ a/z a1z +#endif + /<[a-c-d]>/ @@ -323,6 +343,26 @@ /a`*b/convert_glob_escape=x +# Tests of null and empty inputs + +/a*b/use_length + +//use_length + +# Error +/a*b/null_pattern + +# Error +//null_pattern + +# Error +/a*b/use_length,null_pattern + +# Kind-of error... pattern conversion succeeds, but it converts to a non-empty +# pattern, and null_pattern applies to the regex parse afterwards too, which +# fails. +//use_length,null_pattern + # -------- Tests of extended POSIX conversion -------- #pattern convert=unset:posix_extended @@ -359,6 +399,12 @@ /a***b/ +# Tests of empty inputs + +/a*b/use_length + +//use_length + # -------- Tests of basic POSIX conversion -------- #pattern convert=unset:posix_basic @@ -393,4 +439,10 @@ /a***b/ +# Tests of empty inputs + +/a*b/use_length + +//use_length + # End of testinput24 diff --git a/testdata/testinput28 b/testdata/testinput28 new file mode 100644 index 0000000..9f92a91 --- /dev/null +++ b/testdata/testinput28 @@ -0,0 +1,153 @@ +# This tests the EBCDIC support in PCRE2. It catches cases where explicit values +# such as 0x0a have been used instead of names like CHAR_LF. +# +# This test file however is checked in to the repository encoded as ISO-8859-1, +# using a reversible mapping from EBCDIC. This lets us easily author test cases. +# However, they will only be run against a genuine EBCDIC when the input and +# output files are converted to EBCDIC. +# +# There is also a special mode, on ASCII systems, where pcre2test takes ASCII +# input (actually, ISO-8859-1), and then does the transcoding internally before +# calling the genuinely-EBCDIC version of PCRE2. + +# Test default newline and variations + +/^A/m + ABC + 12\nABC + +/^A/m,newline=any + 12\nABC + 12\rABC + 12\r\nABC + 12\x85ABC + +/^A/m,newline=anycrlf + 12\nABC + 12\rABC + 12\r\nABC +\= Expect no match + 12\x85ABC + +# Test \h + +/^A\h/ + A B + A\tB + A\xA0B + +# Test \H + +/^A\H/ + AB + A\x42B +\= Expect no match + A B + +# Test \R + +/^A\R/ + A\nB + A\rB + A\x85B + A\x0bB + A\x0cB +\= Expect no match + A B + +# Test \v + +/^A\v/ + A\nB + A\rB + A\x85B + A\x0bB + A\x0cB +\= Expect no match + A B + +# Test \V + +/^A\V/ + A B +\= Expect no match + A\nB + A\rB + A\x85B + A\x0bB + A\x0cB + +# For repeated items, use an atomic group so that the output is the same +# for DFA matching (otherwise it may show multiple matches). + +# Test \h+ + +/^A(?>\h+)/ + A B + +# Test \H+ + +/^A(?>\H+)/ + AB +\= Expect no match + A B + +# Test \R+ + +/^A(?>\R+)/ + A\nB + A\rB + A\x85B + A\x0bB + A\x0cB +\= Expect no match + A B + +# Test \v+ + +/^A(?>\v+)/ + A\nB + A\rB + A\x85B + A\x0bB + A\x0cB +\= Expect no match + A B + +# Test \V+ + +/^A(?>\V+)/ + A B +\= Expect no match + A\nB + A\rB + A\x85B + A\x0bB + A\x0cB + +# Test \c functionality + +/\c@\cA\cb\cC\cd\cE\cf\cG\ch\cI\cJ\cK\cl\cm\cN\cO\cp\cq\cr\cS\cT\cV\cW\cX\cy\cZ/ + \x00\x01\x02\x03\x9c\x09\x86\x7f\x97\x8d\x8e\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x9d\x08\x87\x18\x19\x92 + \x00\x01\x02\x03\x9c\x09\x86\x7f\x97\x8d\x8e\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x9d\x08\x87\x18\x19\x92 + +#if !ebcdic-nl25 + +/^\x15$/ + \n + +/\cU/ + \x0a + \x85 + +#endif + +/\c[\c\\c]\c^\c_/ + \x8f\x1c\x1d\x1e\x1f + +/\c?/ + A\x9fB + +/\c&/ + +# End diff --git a/testdata/testinput29 b/testdata/testinput29 new file mode 100644 index 0000000..61992fa --- /dev/null +++ b/testdata/testinput29 @@ -0,0 +1,9 @@ +# This tests the EBCDIC support in PCRE2, specifically when NL has been +# configured to be 0x25. + +/^\x25$/ + \n + +/\cU/ + \x0a + \x85 diff --git a/testdata/testinput5 b/testdata/testinput5 index a0d2cd5..7f9f6a2 100644 --- a/testdata/testinput5 +++ b/testdata/testinput5 @@ -665,8 +665,6 @@ /\g{A}xxx#bх(?'A'123) (?'A'456)/Bx,newline=any,utf -/^\cÄ£/utf - /(\R*)(.)/s,utf \r\n \r\r\n\n\r @@ -1657,6 +1655,10 @@ "(*UTF)(*UCP)(.UTF).+X(\V+;\^(\D|)!999}(?(?C{7(?C')\H*\S*/^\x5\xa\\xd3\x85n?(;\D*(?m).[^mH+((*UCP)(*U:F)})(?!^)(?'" +/(?(?C'')\Qé/utf + +/(?(?C'')é/utf + /[\pS#moq]/ = @@ -2068,6 +2070,12 @@ /\N{U}/ +/\N{U+}/utf + +/\N{U+1}/ + +/\N{U+1 }/ + # This tests the non-UTF Unicode NEL pattern whitespace character, only # recognized by PCRE2 with /x when there is Unicode support. @@ -2143,8 +2151,6 @@ /(?'AB၌C'...)\g{AB၌C}/utf -/(?'Ù ABC'...)/utf - /(?'²ABC'...)/utf /(?'X²ABC'...)/utf @@ -2309,6 +2315,14 @@ s \x{17f} k \x{212a} +/(.) \1 z/Bir + s s z + s S z + +/(?J:(?s)|(?.)) \k z/Bir + s s z + s S z + /(.) \1/i,utf s S k K @@ -2788,10 +2802,6 @@ /(?\777< diff --git a/testdata/testinput6 b/testdata/testinput6 index 1fbe4ce..f6f5cbf 100644 --- a/testdata/testinput6 +++ b/testdata/testinput6 @@ -514,9 +514,13 @@ What do you know about the quick brown fox? What do you know about THE QUICK BROWN FOX? +#if !ebcdic + /abcd\t\n\r\f\a\e\071\x3b\$\\\?caxyz/ abcd\t\n\r\f\a\e9;\$\\?caxyz +#endif + /a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz/ abxyzpqrrrabbxyyyypqAzz abxyzpqrrrabbxyyyypqAzz @@ -609,9 +613,13 @@ bababbc babababc +#if !ebcdic + /^\ca\cA\c[\c{\c:/ \x01\x01\e;z +#endif + /^[ab\]cde]/ athing bthing @@ -745,7 +753,7 @@ \= Expect no match 1IN SOA non-sp1 non-sp2( -/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-z\d\-]*)*\.$/ +/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-Z\d\-]*)*\.$/ a. Z. 2. @@ -944,6 +952,8 @@ /^[ab]{1,3}(ab*?|b)/no_auto_possess aabbbbb +#if !ebcdic + / (?: [\040\t] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] )* \) )* \) )* # optional leading comment @@ -1740,6 +1750,8 @@ \= Expect no match The quick brown fox +#endif + /abc\0def\00pqr\000xyz\0000AB/ abc\0def\00pqr\000xyz\0000AB abc456 abc\0def\00pqr\000xyz\0000ABCDE @@ -1793,6 +1805,8 @@ /([^.]*)\.([^:]*):[t ]+(.*)/i track1.title:TBlah blah blah +#if !ebcdic + /^[W-c]+$/ WXY_^abc \= Expect no match @@ -1806,6 +1820,8 @@ WXY_^abc wxy_^ABC +#endif + /^abc$/m abc qqq\nabc @@ -1861,6 +1877,8 @@ \= Expect no match aaa +#if !ebcdic + /\x5c/ \\ @@ -1869,6 +1887,8 @@ \= Expect no match Zulu +#endif + /ab{3cd/ ab{3cd @@ -1892,6 +1912,8 @@ \= Expect no match abc\ndef +#if !ebcdic + /(abc)\123/ abc\x53 @@ -1916,15 +1938,21 @@ /(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\12\123/ abcdefghijk\12S +#endif + /a{0}bc/ bc /(a|(bc)){0,0}?xyz/ xyz +#if !ebcdic + /abc[\10]de/ abc\010de +#endif + /abc[\1]de/ abc\1de @@ -1996,9 +2024,13 @@ aaaabcd aaAabcd +#if !ebcdic + /\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377/ \000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377 +#endif + /P[^*]TAIRE[^*]{1,6}?LL/ xxxxxxxxxxxPSTAIREISLLxxxxxxxxx @@ -2069,6 +2101,8 @@ 42 [abcd] ]abcd[ + +#if !ebcdic /^[W-\]46]/ W46]789 @@ -2082,6 +2116,8 @@ \= Expect no match -46]789 well + +#endif /\d\d\/\d\d\/\d\d\d\d/ 01/01/2000 @@ -3921,12 +3957,16 @@ Regex regulär +#if !ebcdic + /Åæåä[à-ÿÀ-ß]+/ Åæåäà Åæåäÿ ÅæåäÀ Åæåäß +#endif + /(?<=Z)X./ \x84XAZXB @@ -3983,6 +4023,8 @@ AB aB +#if !ebcdic + /Content-Type\x3A[^\r\n]{6,}/ Content-Type:xxxxxyyy @@ -3995,6 +4037,8 @@ /Content-Type\x3A[^a]{6,}z/ Content-Type:xxxyyyz +#endif + /^abc/Im,newline=lf xyz\nabc xyz\r\nabc @@ -4232,10 +4276,14 @@ >XYZ > X NY Z +#if !ebcdic + /\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/ >XY\x0aZ\x0aA\x0bNN\x0c >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c +#endif + /.+A/newline=crlf \= Expect no match \r\nA @@ -5200,4 +5248,19 @@ # -------------- +/^(?1(2))(?(DEFINE)(a(.)b))/ + axb + +# Tests for reading matches from NULL subjects +/(.?)/ + \=null_subject,copy=0,get=0,getall + +# -------------- + +# Verify pcre2_substitute is blocked for DFA + +/abc/ + abc\=replace=xyz + abc\=replace=xyz,substitute_matched + # End of testinput6 diff --git a/testdata/testinput9 b/testdata/testinput9 index 0f3e0a8..eac74a6 100644 --- a/testdata/testinput9 +++ b/testdata/testinput9 @@ -4,6 +4,8 @@ #forbid_utf #newline_default lf any anycrlf +#if !ebcdic + /a\xc4\xa3b/ a\N{U+123}b \= Expect no match # error message (too big char) @@ -17,10 +19,14 @@ \= Expect no match # error message (too big char) \x{7fffffff} +#endif + /\x{100}/I /\o{400}/I +#if !ebcdic + / (?: [\040\t] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] )* \) )* \) )* # optional leading comment @@ -216,6 +222,8 @@ \) )* # optional trailing comment /Ix +#endif + /\h/I /\H/I @@ -240,8 +248,12 @@ /[\V]/B +#if !ebcdic + /[\x0a\V]/B +#endif + /\777/I /(*:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF)XX/mark @@ -260,8 +272,12 @@ /[\u0100-\u0200]/alt_bsux,allow_empty_class,match_unset_backref,dupnames +#if !ebcdic + /[^\x00-a]{12,}[^b-\xff]*/B +#endif + /[^\s]*\s* [^\W]+\W+ [^\d]*?\d0 [^\d\w]{4,6}?\w*A/B /(*MARK:a\x{100}b)z/alt_verbnames diff --git a/testdata/testinputEBC b/testdata/testinputEBC deleted file mode 100644 index 36df20b..0000000 --- a/testdata/testinputEBC +++ /dev/null @@ -1,137 +0,0 @@ -# This is a specialized test for checking, when PCRE2 is compiled with the -# EBCDIC option but in an ASCII environment, that newline, white space, and \c -# functionality is working. It catches cases where explicit values such as 0x0a -# have been used instead of names like CHAR_LF. Needless to say, it is not a -# genuine EBCDIC test! In patterns, alphabetic characters that follow a -# backslash must be in EBCDIC code. In data, NL, NEL, LF, ESC, and DEL must be -# in EBCDIC, but can of course be specified as escapes. - -# Test default newline and variations - -/^A/m - ABC - 12\x15ABC - -/^A/m,newline=any - 12\x15ABC - 12\x0dABC - 12\x0d\x15ABC - 12\x25ABC - -/^A/m,newline=anycrlf - 12\x15ABC - 12\x0dABC - 12\x0d\x15ABC - ** Fail - 12\x25ABC - -# Test \h - -/^A\ˆ/ - A B - A\x41B - -# Test \H - -/^A\È/ - AB - A\x42B - ** Fail - A B - A\x41B - -# Test \R - -/^A\Ù/ - A\x15B - A\x0dB - A\x25B - A\x0bB - A\x0cB - ** Fail - A B - -# Test \v - -/^A\¥/ - A\x15B - A\x0dB - A\x25B - A\x0bB - A\x0cB - ** Fail - A B - -# Test \V - -/^A\å/ - A B - ** Fail - A\x15B - A\x0dB - A\x25B - A\x0bB - A\x0cB - -# For repeated items, use an atomic group so that the output is the same -# for DFA matching (otherwise it may show multiple matches). - -# Test \h+ - -/^A(?>\ˆ+)/ - A B - -# Test \H+ - -/^A(?>\È+)/ - AB - ** Fail - A B - -# Test \R+ - -/^A(?>\Ù+)/ - A\x15B - A\x0dB - A\x25B - A\x0bB - A\x0cB - ** Fail - A B - -# Test \v+ - -/^A(?>\¥+)/ - A\x15B - A\x0dB - A\x25B - A\x0bB - A\x0cB - ** Fail - A B - -# Test \V+ - -/^A(?>\å+)/ - A B - ** Fail - A\x15B - A\x0dB - A\x25B - A\x0bB - A\x0cB - -# Test \c functionality - -/\ƒ@\ƒA\ƒb\ƒC\ƒd\ƒE\ƒf\ƒG\ƒh\ƒI\ƒJ\ƒK\ƒl\ƒm\ƒN\ƒO\ƒp\ƒq\ƒr\ƒS\ƒT\ƒu\ƒV\ƒW\ƒX\ƒy\ƒZ/ - \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f - -/\ƒ[\ƒ\\ƒ]\ƒ^\ƒ_/ - \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f - -/\ƒ?/ - A\xffB - -/\ƒ&/ - -# End diff --git a/testdata/testoutput1 b/testdata/testoutput1 index 4563f52..1e68118 100644 --- a/testdata/testoutput1 +++ b/testdata/testoutput1 @@ -31,10 +31,14 @@ No match What do you know about THE QUICK BROWN FOX? 0: THE QUICK BROWN FOX +#if !ebcdic + /abcd\t\n\r\f\a\e\071\x3b\$\\\?caxyz/ abcd\t\n\r\f\a\e9;\$\\?caxyz 0: abcd\x09\x0a\x0d\x0c\x07\x1b9;$\?caxyz +#endif + /a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz/ abxyzpqrrrabbxyyyypqAzz 0: abxyzpqrrrabbxyyyypqAzz @@ -203,10 +207,14 @@ No match babababc No match +#if !ebcdic + /^\ca\cA\c[;\c:/ \x01\x01\e;z 0: \x01\x01\x1b;z +#endif + /^[ab\]cde]/ athing 0: a @@ -450,7 +458,7 @@ No match 1IN SOA non-sp1 non-sp2( No match -/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-z\d\-]*)*\.$/ +/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-Z\d\-]*)*\.$/ a. 0: a. Z. @@ -899,6 +907,8 @@ No match 0: aabb 1: b +#if !ebcdic + / (?: [\040\t] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] )* \) )* \) )* # optional leading comment @@ -1711,6 +1721,8 @@ No match The quick brown fox No match +#endif + /abc\0def\00pqr\000xyz\0000AB/ abc\0def\00pqr\000xyz\0000AB 0: abc\x00def\x00pqr\x00xyz\x000AB @@ -1888,6 +1900,8 @@ No match 2: title 3: Blah blah blah +#if !ebcdic + /^[W-c]+$/ WXY_^abc 0: WXY_^abc @@ -1907,6 +1921,8 @@ No match wxy_^ABC 0: wxy_^ABC +#endif + /^abc$/m abc 0: abc @@ -1989,6 +2005,8 @@ No match aaa No match +#if !ebcdic + /\x5c/ \\ 0: \ @@ -2000,6 +2018,8 @@ No match Zulu No match +#endif + /(abc)\1/i abcabc 0: abcabc @@ -2020,6 +2040,8 @@ No match abc\ndef No match +#if !ebcdic + /(abc)\123/ abc\x53 0: abcS @@ -2062,6 +2084,8 @@ No match abc\100\60 0: abc@0 1: abc + +#endif /^(A)(B)(C)(D)(E)(F)(G)(H)(I)\8\9$/ ABCDEFGHIHI @@ -2083,6 +2107,8 @@ No match A8B9C\x00 No match +#if !ebcdic + /(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\12\123/ abcdefghijkllS 0: abcdefghijkllS @@ -2114,6 +2140,8 @@ No match 10: j 11: k +#endif + /a{0}bc/ bc 0: bc @@ -2122,10 +2150,14 @@ No match xyz 0: xyz +#if !ebcdic + /abc[\10]de/ abc\010de 0: abc\x08de +#endif + /abc[\1]de/ abc\1de 0: abc\x01de @@ -2260,10 +2292,14 @@ No match aaAabcd 0: b +#if !ebcdic + /\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377/ \000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377 0: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff +#endif + /P[^*]TAIRE[^*]{1,6}?LL/ xxxxxxxxxxxPSTAIREISLLxxxxxxxxx 0: PSTAIREISLL @@ -2392,6 +2428,8 @@ No match No match ]abcd[ No match + +#if !ebcdic /^[W-\]46]/ W46]789 @@ -2415,6 +2453,8 @@ No match No match well No match + +#endif /\d\d\/\d\d\/\d\d\d\d/ 01/01/2000 @@ -4446,6 +4486,86 @@ No match ABC 0: ABC +/x?(x|b)/ + xb + 0: xb + 1: b + +/x??(x|b)/ + x + 0: x + 1: x + +/x?(x|b)/i + Xb + 0: Xb + 1: b + +/x??(x|b)/i + X + 0: X + 1: X + +/x{,2}(x|b)/ + xb + 0: xb + 1: b + +/x{,2}?(x|b)/ + x + 0: x + 1: x + +/x{,2}(x|b)/i + Xb + 0: Xb + 1: b + +/x{,2}?(x|b)/i + X + 0: X + 1: X + +/[^b]?([^b]|b)/ + xb + 0: xb + 1: b + +/[^b]??([^b]|b)/ + x + 0: x + 1: x + +/[^b]?([^b]|b)/i + Xb + 0: Xb + 1: b + +/[^b]??([^b]|b)/i + X + 0: X + 1: X + +/[^b]{,2}([^b]|b)/ + xb + 0: xb + 1: b + +/[^b]{,2}?([^b]|b)/ + x + 0: x + 1: x + +/[^b]{,2}([^b]|b)/i + Xb + 0: Xb + 1: b + +/[^b]{,2}?([^b]|b)/i + X + 0: X + 1: X + /ab{0,1}?c/i ABC 0: ABC @@ -5964,6 +6084,8 @@ No match regulär 0: regul\xe4r +#if !ebcdic + /Åæåä[à-ÿÀ-ß]+/ Åæåäà 0: \xc5\xe6\xe5\xe4\xe0 @@ -5974,6 +6096,8 @@ No match Åæåäß 0: \xc5\xe6\xe5\xe4\xdf +#endif + /(?<=Z)X./ \x84XAZXB 0: XB @@ -6772,12 +6896,16 @@ No match > X NY Z No match +#if !ebcdic + /\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/ >XY\x0aZ\x0aA\x0bNN\x0c 0: XY\x0aZ\x0aA\x0bNN\x0c >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c 0: \x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c +#endif + /(foo)\Kbar/ foobar 0: bar @@ -8933,6 +9061,8 @@ No match 2: B 3: A +#if !ebcdic + /^A\xBz/ A\x{0B}z 0: A\x0bz @@ -8949,6 +9079,8 @@ No match A\123B 0: ASB +#endif + / ^ a + + b $ /x aaaab 0: aaaab @@ -9163,6 +9295,8 @@ No match A8B9C 0: A8B9C +#if !ebcdic + /(?1)()((((((\1++))\x85)+)|))/ \x85\x85 0: \x85\x85 @@ -9174,6 +9308,8 @@ No match 6: 7: +#endif + /(?|(\k'Pm')|(?'Pm'))/ abcd 0: @@ -9451,6 +9587,8 @@ No match 0: a123a 1: a +#if !ebcdic + # This pattern uses a lot of named subpatterns in order to match email # addresses in various formats. It's a heavy test for named subpatterns. In the # group, slash is coded as \x{2f} so that this pattern can also be @@ -9520,9 +9658,13 @@ No match No match The quick brown fox No match + +#endif # -------------------------------------------------------------------------- +#if !ebcdic + # This pattern uses named groups to match default PCRE2 patterns. It's another # heavy test for named subpatterns. Once again, code slash as \x{2f} and escape # $ even in classes so that this works with pcre2test. @@ -9717,6 +9859,8 @@ No match /(?P(?P=abn)(?/xx @@ -10169,6 +10313,8 @@ No match a{1,2,3}b 0: a{1,2,3}b +#if !ebcdic + /\214748364/ >\x{8c}748364< 0: \x8c748364 @@ -10188,6 +10334,8 @@ No match \x8b00000000 0: \x8b00000000 +#endif + /a{65536/ >a{65536< 0: a{65536 @@ -10624,6 +10772,8 @@ No match n No match +#if !ebcdic + /^(?[\x61])b/ ab 0: ab @@ -10642,6 +10792,8 @@ No match b No match +#endif + /(?[ [[:graph:]] ])/ a 0: a diff --git a/testdata/testoutput10 b/testdata/testoutput10 index d1bccf3..b8add04 100644 --- a/testdata/testoutput10 +++ b/testdata/testoutput10 @@ -7,18 +7,23 @@ /[Ã]/utf Failed: error -8 at offset 1: UTF-8 error: byte 2 top bits not 0x80 + here: [ |-->| Ã] /Ã/utf Failed: error -3 at offset 0: UTF-8 error: 1 byte missing at end + here: |-->| à /ÃÃÃxxx/utf Failed: error -8 at offset 0: UTF-8 error: byte 2 top bits not 0x80 + here: |-->| ÃÃÃxxx /‚‚‚‚‚‚‚Ã/utf Failed: error -22 at offset 2: UTF-8 error: isolated byte with 0x80 bit set + here:  |-->| ‚‚‚‚‚‚‚à /‚‚‚‚‚‚‚Ã/match_invalid_utf Failed: error -22 at offset 2: UTF-8 error: isolated byte with 0x80 bit set + here:  |-->| ‚‚‚‚‚‚‚à # Now test subjects @@ -714,6 +719,7 @@ Subject length lower bound = 2 /^[\QĀ\E-\QŐ\E/B,utf Failed: error 106 at offset 15: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| # This tests the stricter UTF-8 check according to RFC 3629. @@ -1083,10 +1089,18 @@ Failed: error -14: UTF-8 error: 6-byte character is not allowed (RFC 3629) at of /(*UTF8)abc/never_utf Failed: error 174 at offset 7: using UTF is disabled by the application + here: (*UTF8) |<--| abc /abc/utf,never_utf Failed: error 174 at offset 0: using UTF is disabled by the application +/(*UCP)abc/never_ucp +Failed: error 175 at offset 6: using UCP is disabled by the application + here: (*UCP) |<--| abc + +/abc/ucp,never_ucp +Failed: error 175 at offset 0: using UCP is disabled by the application + /A\x{391}\x{10427}\x{ff3a}\x{1fb0}/IBi,utf ------------------------------------------------------------------ Bra @@ -1525,8 +1539,17 @@ Failed: error -22: UTF-8 error: isolated byte with 0x80 bit set at offset 1 123 No match +/\p{ Aሴ}/utf +Failed: error 146 at offset 9: malformed \P or \p sequence + here: \p{ Aሴ |<--| } + +/\p{BC: Aሴ}/utf +Failed: error 146 at offset 11: malformed \P or \p sequence + here: \p{BC: Aሴ |<--| } + /(*:*++++++++++++''''''''''''''''''''+''+++'+++x+++++++++++++++++++++++++++++++++++(++++++++++++++++++++:++++++%++:''''''''''''''''''''''''+++++++++++++++++++++++++++++++++++++++++++++++++++++-++++++++k+++++++''''+++'+++++++++++++++++++++++''''++++++++++++':Æ¿)/utf Failed: error 176 at offset 259: name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN) + here: ...+++++++':Æ¿ |<--| ) /[\s[:^ascii:]]/B,ucp ------------------------------------------------------------------ @@ -1603,14 +1626,25 @@ No match /(?'ABáC6789012345678901234567890123012345678901234567890123456789AB012345678901234567890123456789AB012345678901234567890123456789AB'...)/utf Failed: error 148 at offset 132: subpattern name is too long (maximum 128 code units) + here: ...23456789AB |<--| '...) /(?'ABZC6789012345678901234567890123012345678901234567890123456789AB012345678901234567890123456789AB012345678901234567890123456789AB'...)/utf /(?(n/utf Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?) + here: (?(n |<--| /(?(á/utf Failed: error 142 at offset 5: syntax error in subpattern name (missing terminator?) + here: (?(á |<--| + +/^\cÄ£/utf +Failed: error 168 at offset 5: \c must be followed by a printable ASCII character + here: ^\cÄ£ |<--| + +/(?'Ù ABC'...)/utf +Failed: error 144 at offset 5: subpattern name must start with a non-digit + here: (?'Ù  |<--| ABC'...) # Invalid UTF-8 tests @@ -1969,17 +2003,21 @@ Failed: error 205 at offset 0: PCRE2_EXTRA_TURKISH_CASING requires UTF in 8-bit /\400/ Failed: error 151 at offset 4: octal value is greater than \377 in 8-bit non-UTF-8 mode + here: \400 |<--| /abc/substitute_extended abc\=replace=\400 Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: \400 |<--| /\400/python_octal Failed: error 202 at offset 4: octal value given by \ddd is greater than \377 (forbidden by PCRE2_EXTRA_PYTHON_OCTAL) + here: \400 |<--| /abc/substitute_extended,python_octal abc\=replace=\400 Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: \400 |<--| /\400/utf @@ -1989,10 +2027,12 @@ Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement /\400/utf,python_octal Failed: error 202 at offset 4: octal value given by \ddd is greater than \377 (forbidden by PCRE2_EXTRA_PYTHON_OCTAL) + here: \400 |<--| /abc/utf,substitute_extended,python_octal abc\=replace=\400 Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: \400 |<--| /[\x00-\x2f\x11-\xff]+/B ------------------------------------------------------------------ diff --git a/testdata/testoutput11-16 b/testdata/testoutput11-16 index 8b9cd01..684e532 100644 --- a/testdata/testoutput11-16 +++ b/testdata/testoutput11-16 @@ -532,6 +532,7 @@ MK: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789AB /\x{10000}/ Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too large + here: \x{10000 |<--| } /\o{20000}/ @@ -540,39 +541,51 @@ Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too /\x{110000}/ Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /\x{7fffffff}/ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{7fffffff |<--| } /\x{80000000}/ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| } /\x{ffffffff}/ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } /\x{100000000}/ Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...{100000000 |<--| } /\o{17777777777}/ Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...7777777777 |<--| } /\o{20000000000}/ Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...0000000000 |<--| } /\o{37777777777}/ Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...7777777777 |<--| } /\o{40000000000}/ Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...0000000000 |<--| } /\x{7fffffff}\x{7fffffff}/I Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{7fffffff |<--| }\x{7fffff... /\x{80000000}\x{80000000}/I Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }\x{800000... /\x{ffffffff}\x{ffffffff}/I Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| }\x{ffffff... # Non-UTF characters @@ -590,6 +603,7 @@ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is to /\x{400000}\x{800000}/IBi Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{400000 |<--| }\x{800000... # Check character ranges @@ -693,6 +707,7 @@ Subject length lower bound = 1 /ab\x{80000041}z/ Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{80000041 |<--| }z ab\x{80000041}z /(?i:A{1,}\6666666666)/ @@ -738,6 +753,7 @@ Failed: error 134 at offset 13: character code point value in \x{} or \o{} is to /[\x00-\x{6000}\x{3000}-\x{ffffffff}]#[\x00-\x{6000}\x{3000}-\x{ffffffff}]{5,7}?/B Failed: error 134 at offset 34: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| }]#[\x00-\... /[\x00-\x2f\x11-\xff]*?!/B ------------------------------------------------------------------ @@ -757,14 +773,17 @@ Failed: error 204 at offset 0: PCRE2_EXTRA_TURKISH_CASING require Unicode (UTF o /([\x{100}-\x{7fff}\x{9000}\x{9002}\x{9004}\x{9006}\x{9008}\x{10000}-\x{7fffffff}]{3,8}?).#/B Failed: error 134 at offset 66: character code point value in \x{} or \o{} is too large + here: ...8}\x{10000 |<--| }-\x{7ffff... \x{9001}\x{9007}\x{8000}\x{ffff}\x{9002}\x{7fff}\x{10000}\x{7fffffff}\x{500000}\x{9006}# /([\x{3000}\x{3001}\x{3003}\x{3004}\x{3006}\x{3007}\x{8000}-\x{ffff}\x{100001}\x{100002}\x{100004}\x{100005}\x{100007}\x{100008}\x{10000a}\x{10000b}\x{80000000}-\x{ffffffff}]{5,}).#/B Failed: error 134 at offset 76: character code point value in \x{} or \o{} is too large + here: ...}\x{100001 |<--| }\x{100002... \x{2fff}\x{3002}\x{7fff}\x{100000}\x{7fffffff}\x{3000}\x{3007}\x{8000}\x{ffff}\x{100001}\x{10000b}\x{80000000}\x{ffffffff}\x{3000}# /([^\x{4000}\x{4002}\x{4004}\x{4005}\x{4007}\x{4009}\x{400a}\x{f000}\x{f002}\x{f004}\x{f005}\x{f007}\x{f009}\x{f00a}\x{100000}\x{100002}\x{100004}\x{100005}\x{100007}\x{100009}\x{10000a}\x{a0000000}\x{a0000002}\x{a0000004}\x{a0000005}\x{a0000007}\x{a0000009}\x{a000000a}]+).#/B Failed: error 134 at offset 124: character code point value in \x{} or \o{} is too large + here: ...}\x{100000 |<--| }\x{100002... \x{4000}\x{4002}\x{4004}\x{4005}\x{4007}\x{4009}\x{400a}\x{3fff}\x{4001}\x{4003}\x{4006}\x{4008}\x{400b}\x{100}# \x{f000}\x{f002}\x{f004}\x{f005}\x{f007}\x{f009}\x{f00a}\x{efff}\x{f001}\x{f003}\x{f006}\x{f008}\x{f00b}\x{100}# \x{100000}\x{100002}\x{100004}\x{100005}\x{100007}\x{100009}\x{10000a}\x{fffff}\x{100001}\x{100003}\x{100006}\x{100008}\x{10000b}\x{100}# @@ -778,6 +797,7 @@ Failed: error 134 at offset 124: character code point value in \x{} or \o{} is t /\x{80000000}/B Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| } \x{80000000} \= Expect no match \x{7fffffff} @@ -785,6 +805,7 @@ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is to /[\x{80000000}-\x{8000000f}\x{8fffffff}]/B Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }-\x{80000... \x{80000002} \x{8fffffff} \= Expect no match @@ -793,6 +814,7 @@ Failed: error 134 at offset 12: character code point value in \x{} or \o{} is to /\x{80000000}/B,alt_extended_class Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| } \x{80000000} \= Expect no match \x{7fffffff} @@ -800,6 +822,7 @@ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is to /[\x{80000000}-\x{8000000f}\x{8fffffff}]/B,alt_extended_class Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }-\x{80000... \x{80000002} \x{8fffffff} \= Expect no match @@ -808,6 +831,7 @@ Failed: error 134 at offset 12: character code point value in \x{} or \o{} is to /[\x{80000000}-\x{8000000f}--\x{80000002}]/B,alt_extended_class Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }-\x{80000... \x{80000001} \x{80000003} \= Expect no match @@ -815,6 +839,7 @@ Failed: error 134 at offset 12: character code point value in \x{} or \o{} is to /[[\x{80000000}-\x{8000000f}]--[\x{80000002}]]/B,alt_extended_class Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }-\x{80000... \x{80000001} \x{80000003} \= Expect no match @@ -828,6 +853,7 @@ Failed: error 134 at offset 13: character code point value in \x{} or \o{} is to /(?[[\x{80000000}-\x{8000000f}]+\x{8fffffff}])/B Failed: error 134 at offset 15: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }-\x{80000... \x{80000002} \x{8fffffff} \= Expect no match @@ -836,6 +862,7 @@ Failed: error 134 at offset 15: character code point value in \x{} or \o{} is to /(?[[\x{80000000}-\x{8000000f}]-\x{80000002}])/B Failed: error 134 at offset 15: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }-\x{80000... \x{80000001} \x{80000003} \= Expect no match @@ -843,6 +870,7 @@ Failed: error 134 at offset 15: character code point value in \x{} or \o{} is to /(?[[\x{80000000}-\x{8000000f}]-\x{80000002}])/B Failed: error 134 at offset 15: character code point value in \x{} or \o{} is too large + here: ...x{80000000 |<--| }-\x{80000... \x{80000001} \x{80000003} \= Expect no match diff --git a/testdata/testoutput11-32 b/testdata/testoutput11-32 index 9b71cc6..8c22722 100644 --- a/testdata/testoutput11-32 +++ b/testdata/testoutput11-32 @@ -547,6 +547,7 @@ MK: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789AB /\x{100000000}/ Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...{100000000 |<--| } /\o{17777777777}/ @@ -556,6 +557,7 @@ Failed: error 134 at offset 12: character code point value in \x{} or \o{} is to /\o{40000000000}/ Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...0000000000 |<--| } /\x{7fffffff}\x{7fffffff}/I Capture group count = 0 diff --git a/testdata/testoutput12-16 b/testdata/testoutput12-16 index bd4d524..4883f5e 100644 --- a/testdata/testoutput12-16 +++ b/testdata/testoutput12-16 @@ -491,6 +491,7 @@ Subject length lower bound = 2 /^[\QĀ\E-\QŐ\E/B,utf Failed: error 106 at offset 13: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /X/utf XX\x{d800}\=no_utf_check @@ -542,10 +543,12 @@ Subject length lower bound = 1 /(*UTF-32)\x{11234}/ Failed: error 160 at offset 5: (*VERB) not recognized or malformed + here: (*UTF |<--| -32)\x{112... abcd\x{11234}pqr /(*UTF-32)\x{112}/ Failed: error 160 at offset 5: (*VERB) not recognized or malformed + here: (*UTF |<--| -32)\x{112... abcd\x{11234}pqr /(*CRLF)(*UTF16)(*BSR_UNICODE)a\Rb/I @@ -560,6 +563,7 @@ Subject length lower bound = 3 /(*CRLF)(*UTF32)(*BSR_UNICODE)a\Rb/I Failed: error 160 at offset 14: (*VERB) not recognized or malformed + here: ...LF)(*UTF32 |<--| )(*BSR_UNI... /\h/I,utf Capture group count = 0 @@ -770,6 +774,7 @@ Failed: error -33: bad offset value /í¼€/utf Failed: error -26 at offset 0: UTF-16 error: isolated low surrogate + here: |-->| í¼€ /\w+\x{C4}/B,utf ------------------------------------------------------------------ @@ -909,10 +914,18 @@ Failed: error -26 at offset 0: UTF-16 error: isolated low surrogate /(*UTF)abc/never_utf Failed: error 174 at offset 6: using UTF is disabled by the application + here: (*UTF) |<--| abc /abc/utf,never_utf Failed: error 174 at offset 0: using UTF is disabled by the application +/(*UCP)abc/never_ucp +Failed: error 175 at offset 6: using UCP is disabled by the application + here: (*UCP) |<--| abc + +/abc/ucp,never_ucp +Failed: error 175 at offset 0: using UCP is disabled by the application + /A\x{391}\x{10427}\x{ff3a}\x{1fb0}/IBi,utf ------------------------------------------------------------------ Bra @@ -1020,9 +1033,11 @@ Subject length lower bound = 1 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /\o{4200000}/utf Failed: error 134 at offset 10: character code point value in \x{} or \o{} is too large + here: \o{4200000 |<--| } /\x{100}*A/IB,utf ------------------------------------------------------------------ @@ -1405,7 +1420,15 @@ No match ** Truncation will probably give the wrong result. No match -# A special extra option allows excaped surrogate code points in 32-bit mode, +/\p{ Aሴ}/utf +Failed: error 146 at offset 7: malformed \P or \p sequence + here: \p{ Aሴ |<--| } + +/\p{BC: Aሴ}/utf +Failed: error 146 at offset 9: malformed \P or \p sequence + here: \p{BC: Aሴ |<--| } + +# A special extra option allows escaped surrogate code points in 32-bit mode, # but subjects containing them must not be UTF-checked. These patterns give # errors in 16-bit mode. @@ -1482,9 +1505,19 @@ Failed: error 191 at offset 0: PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is not allowe /(?(n/utf Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?) + here: (?(n |<--| /(?(á/utf Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?) + here: (?(á |<--| + +/^\cÄ£/utf +Failed: error 168 at offset 4: \c must be followed by a printable ASCII character + here: ^\cÄ£ |<--| + +/(?'Ù ABC'...)/utf +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: (?'Ù  |<--| ABC'...) # Invalid UTF-16/32 tests. @@ -1959,6 +1992,7 @@ No match /\x{802a0000}*/ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{802a0000 |<--| }* \x{802a0000}\x{802a0000} # UTF matching without UTF, check invalid UTF characters @@ -1973,6 +2007,7 @@ Failed: error 134 at offset 11: character code point value in \x{} or \o{} is to # This used to loop in 32-bit mode; it will fail in 16-bit mode. /[\x{ffffffff}]/caseless,ucp Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| }] \x{ffffffff}xyz # These are 32-bit tests for handing 0xffffffff when in UCP caselsss mode. They @@ -1980,21 +2015,25 @@ Failed: error 134 at offset 12: character code point value in \x{} or \o{} is to /k*\x{ffffffff}/caseless,ucp Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } \x{ffffffff} /k+\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } K\x{ffffffff} \= Expect no match \x{ffffffff}\x{ffffffff} /k{2}\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 15: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } \= Expect no match \x{ffffffff}\x{ffffffff}\x{ffffffff} /k\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } K\x{ffffffff} \= Expect no match \x{ffffffff}\x{ffffffff}\x{ffffffff} diff --git a/testdata/testoutput12-32 b/testdata/testoutput12-32 index c9587ee..5a4255f 100644 --- a/testdata/testoutput12-32 +++ b/testdata/testoutput12-32 @@ -486,6 +486,7 @@ Subject length lower bound = 2 /^[\QĀ\E-\QŐ\E/B,utf Failed: error 106 at offset 13: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /X/utf XX\x{d800}\=no_utf_check @@ -523,6 +524,7 @@ Failed: error -27: UTF-32 error: code points 0xd800-0xdfff are not defined at of /(*UTF16)\x{11234}/ Failed: error 160 at offset 7: (*VERB) not recognized or malformed + here: (*UTF16 |<--| )\x{11234} abcd\x{11234}pqr /(*UTF)\x{11234}/I @@ -536,14 +538,17 @@ Subject length lower bound = 1 /(*UTF-32)\x{11234}/ Failed: error 160 at offset 5: (*VERB) not recognized or malformed + here: (*UTF |<--| -32)\x{112... abcd\x{11234}pqr /(*UTF-32)\x{112}/ Failed: error 160 at offset 5: (*VERB) not recognized or malformed + here: (*UTF |<--| -32)\x{112... abcd\x{11234}pqr /(*CRLF)(*UTF16)(*BSR_UNICODE)a\Rb/I Failed: error 160 at offset 14: (*VERB) not recognized or malformed + here: ...LF)(*UTF16 |<--| )(*BSR_UNI... /(*CRLF)(*UTF32)(*BSR_UNICODE)a\Rb/I Capture group count = 0 @@ -764,6 +769,7 @@ Failed: error -33: bad offset value /í¼€/utf Failed: error -27 at offset 0: UTF-32 error: code points 0xd800-0xdfff are not defined + here: |-->| í¼€ /\w+\x{C4}/B,utf ------------------------------------------------------------------ @@ -903,10 +909,18 @@ Failed: error -27 at offset 0: UTF-32 error: code points 0xd800-0xdfff are not d /(*UTF)abc/never_utf Failed: error 174 at offset 6: using UTF is disabled by the application + here: (*UTF) |<--| abc /abc/utf,never_utf Failed: error 174 at offset 0: using UTF is disabled by the application +/(*UCP)abc/never_ucp +Failed: error 175 at offset 6: using UCP is disabled by the application + here: (*UCP) |<--| abc + +/abc/ucp,never_ucp +Failed: error 175 at offset 0: using UCP is disabled by the application + /A\x{391}\x{10427}\x{ff3a}\x{1fb0}/IBi,utf ------------------------------------------------------------------ Bra @@ -1014,9 +1028,11 @@ Subject length lower bound = 1 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /\o{4200000}/utf Failed: error 134 at offset 10: character code point value in \x{} or \o{} is too large + here: \o{4200000 |<--| } /\x{100}*A/IB,utf ------------------------------------------------------------------ @@ -1397,7 +1413,15 @@ No match \x{7fffffff} No match -# A special extra option allows excaped surrogate code points in 32-bit mode, +/\p{ Aሴ}/utf +Failed: error 146 at offset 7: malformed \P or \p sequence + here: \p{ Aሴ |<--| } + +/\p{BC: Aሴ}/utf +Failed: error 146 at offset 9: malformed \P or \p sequence + here: \p{BC: Aሴ |<--| } + +# A special extra option allows escaped surrogate code points in 32-bit mode, # but subjects containing them must not be UTF-checked. These patterns give # errors in 16-bit mode. @@ -1480,9 +1504,19 @@ No match /(?(n/utf Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?) + here: (?(n |<--| /(?(á/utf Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?) + here: (?(á |<--| + +/^\cÄ£/utf +Failed: error 168 at offset 4: \c must be followed by a printable ASCII character + here: ^\cÄ£ |<--| + +/(?'Ù ABC'...)/utf +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: (?'Ù  |<--| ABC'...) # Invalid UTF-16/32 tests. diff --git a/testdata/testoutput14-16 b/testdata/testoutput14-16 index c0c2d90..1356a37 100644 --- a/testdata/testoutput14-16 +++ b/testdata/testoutput14-16 @@ -128,21 +128,25 @@ No match /k*\x{ffffffff}/caseless,ucp Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } \x{ffffffff} /k+\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } K\x{ffffffff} \= Expect no match \x{ffffffff}\x{ffffffff} /k{2}\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 15: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } \= Expect no match \x{ffffffff}\x{ffffffff}\x{ffffffff} /k\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } K\x{ffffffff} \= Expect no match \x{ffffffff}\x{ffffffff}\x{ffffffff} diff --git a/testdata/testoutput14-8 b/testdata/testoutput14-8 index 69285db..2319f7a 100644 --- a/testdata/testoutput14-8 +++ b/testdata/testoutput14-8 @@ -87,36 +87,44 @@ No match /\x{120}\x{c1}/i,ucp,no_start_optimize Failed: error 134 at offset 6: character code point value in \x{} or \o{} is too large + here: \x{120 |<--| }\x{c1} \x{121}\x{e1} /\x{120}\x{c1}/i,ucp Failed: error 134 at offset 6: character code point value in \x{} or \o{} is too large + here: \x{120 |<--| }\x{c1} \x{121}\x{e1} /[^\x{120}]/i,no_start_optimize Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too large + here: [^\x{120 |<--| }] \x{121} /[^\x{120}]/i,ucp,no_start_optimize Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too large + here: [^\x{120 |<--| }] \= Expect no match \x{121} /[^\x{120}]/i Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too large + here: [^\x{120 |<--| }] \x{121} /[^\x{120}]/i,ucp Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too large + here: [^\x{120 |<--| }] \= Expect no match \x{121} /\x{120}{2}/i,ucp Failed: error 134 at offset 6: character code point value in \x{} or \o{} is too large + here: \x{120 |<--| }{2} \x{121}\x{121} /[^\x{120}]{2}/i,ucp Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too large + here: [^\x{120 |<--| }]{2} \= Expect no match \x{121}\x{121} @@ -128,21 +136,25 @@ Failed: error 134 at offset 8: character code point value in \x{} or \o{} is too /k*\x{ffffffff}/caseless,ucp Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } \x{ffffffff} /k+\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 13: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } K\x{ffffffff} \= Expect no match \x{ffffffff}\x{ffffffff} /k{2}\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 15: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } \= Expect no match \x{ffffffff}\x{ffffffff}\x{ffffffff} /k\x{ffffffff}/caseless,ucp,no_start_optimize Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } K\x{ffffffff} \= Expect no match \x{ffffffff}\x{ffffffff}\x{ffffffff} diff --git a/testdata/testoutput15 b/testdata/testoutput15 index e2407a7..b303955 100644 --- a/testdata/testoutput15 +++ b/testdata/testoutput15 @@ -112,9 +112,11 @@ Minimum depth limit = 10 /(*LIMIT_MATCH=12bc)abc/ Failed: error 160 at offset 16: (*VERB) not recognized or malformed + here: ...T_MATCH=12 |<--| bc)abc /(*LIMIT_MATCH=4294967290)abc/ Failed: error 160 at offset 23: (*VERB) not recognized or malformed + here: ...=429496729 |<--| 0)abc /(*LIMIT_DEPTH=4294967280)abc/I Capture group count = 0 @@ -450,6 +452,8 @@ Failed: error -52: nested recursion at the same subject position bbb Failed: error -52: nested recursion at the same subject position +#if !ebcdic + /[^\xff]((?1))/BI ------------------------------------------------------------------ Bra @@ -465,6 +469,8 @@ Subject length lower bound = 1 abcd Failed: error -52: nested recursion at the same subject position +#endif + # These tests don't behave the same with JIT /\w+(?C1)/BI,no_auto_possess diff --git a/testdata/testoutput17 b/testdata/testoutput17 index 95f3959..6d55008 100644 --- a/testdata/testoutput17 +++ b/testdata/testoutput17 @@ -503,6 +503,8 @@ Failed: error -46: JIT stack limit reached bbb Failed: error -46: JIT stack limit reached +#if !ebcdic + /[^\xff]((?1))/BI ------------------------------------------------------------------ Bra @@ -519,6 +521,8 @@ JIT compilation was successful abcd Failed: error -46: JIT stack limit reached +#endif + /(x(?1)){4}/ /[axm]{7}/ @@ -567,4 +571,34 @@ Failed: error -47: match limit exceeded 2: xyz 2G xyz (3) +# Check the JIT sets all the correct match state for pcre2_substitute + +/abc/jitfast,replace=yy + zabcz + 1: zyyz + zabcz\=substitute_matched + 1: zyyz + +/abc/jitfast,replace=yy + zABCz + 0: zABCz + zABCz\=substitute_matched + 0: zABCz + +/abc/jitfast + ab\=replace=yy,partial_hard +Failed: error -34: bad option value + ab\=replace=yy,partial_hard,substitute_matched +Failed: error -34: bad option value + +/(?C1)abc/jitfast,replace=yy + zabcz\=callout_error=1 +--->zabcz + 1 ^ a +Failed: error -37: callout error code + zabcz\=callout_error=1,substitute_matched +--->zabcz + 1 ^ a +Failed: error -37: callout error code + # End of testinput17 diff --git a/testdata/testoutput18 b/testdata/testoutput18 index 1dcde94..0e8d260 100644 --- a/testdata/testoutput18 +++ b/testdata/testoutput18 @@ -74,7 +74,7 @@ No match: POSIX code 17: match failed 0: abc /(abc)\2/ -Failed: POSIX code 15: bad back reference at offset 6 +Failed: POSIX code 15: bad back reference at offset 7 /(abc\1)/ \= Expect no match @@ -95,6 +95,16 @@ Matched without capture 0: aaaabbbbzz 1: bbbb +/(a)(b)/ + ab\=posix_startend=0:2,ovector=1 + 0: ab + ab\=posix_startend=0:2,ovector=0 +Matched without capture + ab\=posix_startend=1:2,ovector=1 +No match: POSIX code 17: match failed + ab\=posix_startend=1:2,ovector=0 +No match: POSIX code 17: match failed + /(*ANY)ab.cd/ ab-cd 0: ab-cd @@ -162,7 +172,38 @@ Failed: POSIX code 4: ? * + invalid at offset 100000 ** regerror() message truncated /\[A]{1000000}**/expand,regerror_buffsize=32 -Failed: POSIX code 4: ? * + invalid at offset 1000001 +Failed: POSIX code 4: ? * + invalid at offset 1000002 + +/a(b/regerror_buffsize=0 +Failed: POSIX code 11: +** regerror() message truncated + +/a(b/regerror_buffsize=1 +Failed: POSIX code 11: +** regerror() message truncated + +/a(b/regerror_buffsize=12 +Failed: POSIX code 11: unbalanced +** regerror() message truncated + +/a(b/regerror_buffsize=13 +Failed: POSIX code 11: unbalanced ( +** regerror() message truncated + +/a(b/regerror_buffsize=14 +Failed: POSIX code 11: unbalanced () +** regerror() message truncated + +/a(b/regerror_buffsize=15 +Failed: POSIX code 11: unbalanced () +** regerror() message truncated + +/a(b/regerror_buffsize=25 +Failed: POSIX code 11: unbalanced () at offset +** regerror() message truncated + +/a(b/regerror_buffsize=26 +Failed: POSIX code 11: unbalanced () at offset 3 //posix_nosub \=offset=70000 diff --git a/testdata/testoutput19 b/testdata/testoutput19 index 25aa67d..a553919 100644 --- a/testdata/testoutput19 +++ b/testdata/testoutput19 @@ -27,4 +27,7 @@ No match: POSIX code 17: match failed A\xabB No match: POSIX code 16: bad argument +/ AB /hex,utf +Failed: POSIX code 3: pattern error at offset 0 + # End of testdata/testinput19 diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 4fe19d9..23738a3 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -120,43 +120,56 @@ Subject length lower bound = 3 No match /ab\idef/ -Failed: error 103 at offset 3: unrecognized character follows \ +Failed: error 103 at offset 4: unrecognized character follows \ + here: ab\i |<--| def /(?X)ab\idef/ -Failed: error 111 at offset 2: unrecognized character after (? or (?- +Failed: error 111 at offset 3: unrecognized character after (? or (?- + here: (?X |<--| )ab\idef /x{5,4}/ Failed: error 104 at offset 5: numbers out of order in {} quantifier + here: x{5,4 |<--| } /z{65536}/ Failed: error 105 at offset 7: number too big in {} quantifier + here: z{65536 |<--| } /[abcd/ Failed: error 106 at offset 5: missing terminating ] for character class + here: [abcd |<--| /[\B]/B -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\B |<--| ] /[\R]/B -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\R |<--| ] /[\X]/B -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\X |<--| ] /[z-a]/ -Failed: error 108 at offset 3: range out of order in character class +Failed: error 108 at offset 4: range out of order in character class + here: [z-a |<--| ] /^*/ -Failed: error 109 at offset 1: quantifier does not follow a repeatable item +Failed: error 109 at offset 2: quantifier does not follow a repeatable item + here: ^* |<--| /(abc/ Failed: error 114 at offset 4: missing closing parenthesis + here: (abc |<--| /(?# abc/ Failed: error 118 at offset 7: missing ) after (?# comment + here: (?# abc |<--| /(?z)abc/ -Failed: error 111 at offset 2: unrecognized character after (? or (?- +Failed: error 111 at offset 3: unrecognized character after (? or (?- + here: (?z |<--| )abc /.*b/I Capture group count = 0 @@ -227,10 +240,12 @@ Starting code units: \x09 \x0a \x0b \x0c \x0d \x20 a b Subject length lower bound = 1 /(ab\2)/ -Failed: error 115 at offset 4: reference to non-existent subpattern +Failed: error 115 at offset 5: reference to non-existent subpattern + here: (ab\2 |<-->| ) /{4,5}abc/ -Failed: error 109 at offset 4: quantifier does not follow a repeatable item +Failed: error 109 at offset 5: quantifier does not follow a repeatable item + here: {4,5} |<--| abc /(a)(b)(c)\2/I Capture group count = 3 @@ -326,7 +341,8 @@ No match No match /(a)(b)(c)(d)(e)\6/ -Failed: error 115 at offset 16: reference to non-existent subpattern +Failed: error 115 at offset 17: reference to non-existent subpattern + here: ...c)(d)(e)\6 |<-->| /the quick brown fox/I Capture group count = 0 @@ -350,7 +366,8 @@ Subject length lower bound = 19 No match /ab(?z)cd/ -Failed: error 111 at offset 4: unrecognized character after (? or (?- +Failed: error 111 at offset 5: unrecognized character after (? or (?- + here: ab(?z |<--| )cd /^abc|def/I Capture group count = 0 @@ -376,10 +393,12 @@ Subject length lower bound = 3 3: def /)/ -Failed: error 122 at offset 0: unmatched closing parenthesis +Failed: error 122 at offset 1: unmatched closing parenthesis + here: ) |<--| /a[]b/ Failed: error 106 at offset 4: missing terminating ] for character class + here: a[]b |<--| /[^aeiou ]{3,}/I Capture group count = 0 @@ -478,6 +497,7 @@ No match /abc(?<=a+)b/ Failed: error 125 at offset 3: length of lookbehind assertion is not limited + here: abc |-->| (?<=a+)b /(?| (?(1)a|b|c... /(?(?=a)a|b|c)/ Failed: error 127 at offset 0: conditional subpattern contains more than two branches + here: |-->| (?(?=a)a|b... /(?(1a)/ Failed: error 124 at offset 4: missing closing parenthesis for condition + here: (?(1 |<--| a) /(?(1a))/ Failed: error 124 at offset 4: missing closing parenthesis for condition + here: (?(1 |<--| a)) /(?(?i))/ -Failed: error 128 at offset 2: atomic assertion expected after (?( or (?(?C) +Failed: error 128 at offset 3: atomic assertion expected after (?( or (?(?C) + here: (?( |<--| ?i)) /(?(abc))/ Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?( |<-->| abc)) /(?(?| (?<=ab(c+)... /(?<=ab(?<=c+)d)ef/ Failed: error 125 at offset 6: length of lookbehind assertion is not limited + here: (?<=ab |-->| (?<=c+)d)e... /The next three are in testinput2 because they have variable length branches/ @@ -824,106 +853,140 @@ No match # These are syntax tests from Perl 5.005 /a[b-a]/ -Failed: error 108 at offset 4: range out of order in character class +Failed: error 108 at offset 5: range out of order in character class + here: a[b-a |<--| ] /a[]b/ Failed: error 106 at offset 4: missing terminating ] for character class + here: a[]b |<--| /a[/ Failed: error 106 at offset 2: missing terminating ] for character class + here: a[ |<--| /*a/ -Failed: error 109 at offset 0: quantifier does not follow a repeatable item +Failed: error 109 at offset 1: quantifier does not follow a repeatable item + here: * |<--| a /(*)b/ -Failed: error 109 at offset 1: quantifier does not follow a repeatable item +Failed: error 109 at offset 2: quantifier does not follow a repeatable item + here: (* |<--| )b /abc)/ -Failed: error 122 at offset 3: unmatched closing parenthesis +Failed: error 122 at offset 4: unmatched closing parenthesis + here: abc) |<--| /(abc/ Failed: error 114 at offset 4: missing closing parenthesis + here: (abc |<--| /a**/ -Failed: error 109 at offset 2: quantifier does not follow a repeatable item +Failed: error 109 at offset 3: quantifier does not follow a repeatable item + here: a** |<--| /)(/ -Failed: error 122 at offset 0: unmatched closing parenthesis +Failed: error 122 at offset 1: unmatched closing parenthesis + here: ) |<--| ( /\1/ -Failed: error 115 at offset 1: reference to non-existent subpattern +Failed: error 115 at offset 2: reference to non-existent subpattern + here: \1 |<-->| /\2/ -Failed: error 115 at offset 1: reference to non-existent subpattern +Failed: error 115 at offset 2: reference to non-existent subpattern + here: \2 |<-->| /(a)|\2/ -Failed: error 115 at offset 5: reference to non-existent subpattern +Failed: error 115 at offset 6: reference to non-existent subpattern + here: (a)|\2 |<-->| /a[b-a]/Ii -Failed: error 108 at offset 4: range out of order in character class +Failed: error 108 at offset 5: range out of order in character class + here: a[b-a |<--| ] /a[]b/Ii Failed: error 106 at offset 4: missing terminating ] for character class + here: a[]b |<--| /a[/Ii Failed: error 106 at offset 2: missing terminating ] for character class + here: a[ |<--| /*a/Ii -Failed: error 109 at offset 0: quantifier does not follow a repeatable item +Failed: error 109 at offset 1: quantifier does not follow a repeatable item + here: * |<--| a /(*)b/Ii -Failed: error 109 at offset 1: quantifier does not follow a repeatable item +Failed: error 109 at offset 2: quantifier does not follow a repeatable item + here: (* |<--| )b /abc)/Ii -Failed: error 122 at offset 3: unmatched closing parenthesis +Failed: error 122 at offset 4: unmatched closing parenthesis + here: abc) |<--| /(abc/Ii Failed: error 114 at offset 4: missing closing parenthesis + here: (abc |<--| /a**/Ii -Failed: error 109 at offset 2: quantifier does not follow a repeatable item +Failed: error 109 at offset 3: quantifier does not follow a repeatable item + here: a** |<--| /)(/Ii -Failed: error 122 at offset 0: unmatched closing parenthesis +Failed: error 122 at offset 1: unmatched closing parenthesis + here: ) |<--| ( /:(?:/ Failed: error 114 at offset 4: missing closing parenthesis + here: :(?: |<--| /(?<%)b/ Failed: error 162 at offset 3: subpattern name expected + here: (?< |<--| %)b /a(?{)b/ -Failed: error 111 at offset 3: unrecognized character after (? or (?- +Failed: error 111 at offset 4: unrecognized character after (? or (?- + here: a(?{ |<--| )b /a(?{{})b/ -Failed: error 111 at offset 3: unrecognized character after (? or (?- +Failed: error 111 at offset 4: unrecognized character after (? or (?- + here: a(?{ |<--| {})b /a(?{}})b/ -Failed: error 111 at offset 3: unrecognized character after (? or (?- +Failed: error 111 at offset 4: unrecognized character after (? or (?- + here: a(?{ |<--| }})b /a(?{"{"})b/ -Failed: error 111 at offset 3: unrecognized character after (? or (?- +Failed: error 111 at offset 4: unrecognized character after (? or (?- + here: a(?{ |<--| "{"})b /a(?{"{"}})b/ -Failed: error 111 at offset 3: unrecognized character after (? or (?- +Failed: error 111 at offset 4: unrecognized character after (? or (?- + here: a(?{ |<--| "{"}})b /(?(1?)a|b)/ Failed: error 124 at offset 4: missing closing parenthesis for condition + here: (?(1 |<--| ?)a|b) /[a[:xyz:/ Failed: error 106 at offset 8: missing terminating ] for character class + here: [a[:xyz: |<--| /(?<=x+)y/ Failed: error 125 at offset 0: length of lookbehind assertion is not limited + here: |-->| (?<=x+)y /a{37,17}/ Failed: error 104 at offset 7: numbers out of order in {} quantifier + here: a{37,17 |<--| } /abc/\ Failed: error 101 at offset 4: \ at end of pattern + here: abc\ |<--| /abc/\i Failed: error 101 at offset 4: \ at end of pattern + here: abc\ |<--| /(a)bc(d)/I Capture group count = 2 @@ -944,6 +1007,7 @@ Subject length lower bound = 4 1: a 2: d Copy substring 5 failed (-49): unknown substring +Get substring 5 length failed (-49): unknown substring /(.{20})/I Capture group count = 1 @@ -2171,12 +2235,15 @@ Subject length lower bound = 1 /[[.ch.]]/I Failed: error 113 at offset 7: POSIX collating elements are not supported + here: [[.ch.] |<--| ] /[[=ch=]]/I Failed: error 113 at offset 7: POSIX collating elements are not supported + here: [[=ch=] |<--| ] /[[:rhubarb:]]/I Failed: error 130 at offset 12: unknown POSIX class name + here: ...:rhubarb:] |<--| ] /[[:upper:]]/Ii Capture group count = 0 @@ -2218,10 +2285,12 @@ No match No match /[\200-\110]/I -Failed: error 108 at offset 9: range out of order in character class +Failed: error 108 at offset 10: range out of order in character class + here: [\200-\110 |<--| ] /^(?(0)f|b)oo/I Failed: error 115 at offset 5: reference to non-existent subpattern + here: ^(?(0 |<-->| )f|b)oo # This one's here because of the large output vector needed @@ -3160,16 +3229,20 @@ Last code unit = 'c' Subject length lower bound = 3 /a+?+/I -Failed: error 109 at offset 3: quantifier does not follow a repeatable item +Failed: error 109 at offset 4: quantifier does not follow a repeatable item + here: a+?+ |<--| /a{2,3}?+b/I -Failed: error 109 at offset 7: quantifier does not follow a repeatable item +Failed: error 109 at offset 8: quantifier does not follow a repeatable item + here: a{2,3}?+ |<--| b /(?U)a+?+/I -Failed: error 109 at offset 7: quantifier does not follow a repeatable item +Failed: error 109 at offset 8: quantifier does not follow a repeatable item + here: (?U)a+?+ |<--| /a{2,3}?+b/I,ungreedy -Failed: error 109 at offset 7: quantifier does not follow a repeatable item +Failed: error 109 at offset 8: quantifier does not follow a repeatable item + here: a{2,3}?+ |<--| b /x(?U)a++b/IB ------------------------------------------------------------------ @@ -3267,50 +3340,64 @@ Last code unit = 'b' Subject length lower bound = 3 /[.x.]/I -Failed: error 113 at offset 0: POSIX collating elements are not supported +Failed: error 113 at offset 5: POSIX collating elements are not supported + here: [.x.] |<--| /[=x=]/I -Failed: error 113 at offset 0: POSIX collating elements are not supported +Failed: error 113 at offset 5: POSIX collating elements are not supported + here: [=x=] |<--| /[:x:]/I -Failed: error 112 at offset 0: POSIX named classes are supported only within a class +Failed: error 112 at offset 5: POSIX named classes are supported only within a class + here: [:x:] |<--| /\F/I Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \F |<--| /\l/I Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \l |<--| /\L/I Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \L |<--| /\N{name}/I -Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u +Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \N{ |<--| name} /\u/I Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \u |<--| /\U/I Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \U |<--| /\N{4}/ abcdefg 0: abcd /\N{,}/ -Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u +Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \N{ |<--| ,} /\N{25,ab}/ -Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u +Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \N{ |<--| 25,ab} /[\N]/ Failed: error 171 at offset 3: \N is not supported in a class + here: [\N |<--| ] /[\N{4}]/ -Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u +Failed: error 137 at offset 4: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: [\N{ |<--| 4}] /[\N{name}]/ -Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u +Failed: error 137 at offset 4: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: [\N{ |<--| name}] /a{1,3}b/ungreedy ab @@ -3318,12 +3405,15 @@ Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, /[/I Failed: error 106 at offset 1: missing terminating ] for character class + here: [ |<--| /[a-/I Failed: error 106 at offset 3: missing terminating ] for character class + here: [a- |<--| /[[:space:]/I Failed: error 106 at offset 10: missing terminating ] for character class + here: [[:space:] |<--| /[\s]/IB ------------------------------------------------------------------ @@ -3687,12 +3777,15 @@ Subject length lower bound = 2 /(?C256)ab/I Failed: error 138 at offset 6: number after (?C is greater than 255 + here: (?C256 |<--| )ab /(?Cab)xx/I -Failed: error 182 at offset 3: unrecognized string delimiter follows (?C +Failed: error 182 at offset 4: unrecognized string delimiter follows (?C + here: (?Ca |<--| b)xx /(?C12vr)x/I Failed: error 139 at offset 5: closing parenthesis for (?C expected + here: (?C12 |<--| vr)x /abc(?C)def/I Capture group count = 0 @@ -4119,9 +4212,11 @@ No match /(?1)/I Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?1 |<-->| ) /((?2)(abc)/I Failed: error 114 at offset 10: missing closing parenthesis + here: ((?2)(abc) |<--| /^(abc)def(?1)/I Capture group count = 1 @@ -4236,7 +4331,7 @@ Subject length lower bound = 4 Any Any Any - \1 + \g{1} bbb Recurse d @@ -4500,6 +4595,7 @@ Subject length lower bound = 8 2: gh Number not found for group "three" Copy substring "three" failed (-49): unknown substring +Get substring "three" length failed (-49): unknown substring /(?P)(?P)/IB ------------------------------------------------------------------ @@ -4556,9 +4652,11 @@ Subject length lower bound = 4 /(?Peks)(?Peccs)/I Failed: error 143 at offset 16: two named subpatterns have the same name (PCRE2_DUPNAMES not set) + here: ...eks)(?P |<--| eccs) /(?Pabc(?Pdef)(?Pxyz))/I Failed: error 143 at offset 31: two named subpatterns have the same name (PCRE2_DUPNAMES not set) + here: ...f)(?P |<--| xyz)) "\[((?P\d+)(,(?P>elem))*)\]"I Capture group count = 3 @@ -5570,12 +5668,15 @@ No match /a{11111111111111111111}/I Failed: error 105 at offset 22: number too big in {} quantifier + here: ...1111111111 |<--| } /(){64294967295}/I Failed: error 105 at offset 14: number too big in {} quantifier + here: ...4294967295 |<--| } /(){2,4294967295}/I Failed: error 105 at offset 15: number too big in {} quantifier + here: ...4294967295 |<--| } "(?i:a)(?i:b)(?i:c)(?i:d)(?i:e)(?i:f)(?i:g)(?i:h)(?i:i)(?i:j)(k)(?i:l)A\1B"I Capture group count = 1 @@ -5850,6 +5951,7 @@ Subject length lower bound = 1 /^((?Pa1)|(?Pa2)b)/I Failed: error 143 at offset 18: two named subpatterns have the same name (PCRE2_DUPNAMES not set) + here: ...a1)|(?P |<--| a2)b) /^((?Pa1)|(?Pa2)b)/I,dupnames Capture group count = 3 @@ -5877,6 +5979,7 @@ Subject length lower bound = 2 2: a1 Number not found for group "Z" Copy substring "Z" failed (-49): unknown substring +Get substring "Z" length failed (-49): unknown substring C a1 (2) A (non-unique) /(?|(?)(?)(?)|(?)(?)(?))/I,dupnames @@ -5920,6 +6023,7 @@ Subject length lower bound = 2 cd\=copy=A 0: cd Copy substring "A" failed (-55): requested value is not set +Get substring "A" length failed (-55): requested value is not set /^(?Pa)(?Pb)|cd(?Pef)(?Pgh)/I,dupnames Capture group count = 4 @@ -6041,6 +6145,7 @@ Subject length lower bound = 2 /^(?Pa) (?J:(?Pb)(?Pc)) (?Pd)/I Failed: error 143 at offset 38: two named subpatterns have the same name (PCRE2_DUPNAMES not set) + here: ...c)) (?P |<--| d) # In this next test, J is not set at the outer level; consequently it isn't set # in the pattern's options; consequently pcre2_substring_get_byname() produces @@ -6098,9 +6203,11 @@ Subject length lower bound = 2 /(?:(?(2y)a|b)(X))+/I Failed: error 124 at offset 7: missing closing parenthesis for condition + here: (?:(?(2 |<--| y)a|b)(X))... /(?:(?(ZA)a|b)(?PX))+/I Failed: error 115 at offset 6: reference to non-existent subpattern + here: (?:(?( |<-->| ZA)a|b)(?P... /(?:(?(ZZ)a|b)(?(ZZ)a|b)(?PX))+/I Capture group count = 1 @@ -6126,6 +6233,7 @@ Subject length lower bound = 3 /(?PX|Y))+/I Capture group count = 1 @@ -7216,12 +7324,15 @@ Subject length lower bound = 2 /(?x)(?'xyz>y)/I Failed: error 142 at offset 15: syntax error in subpattern name (missing terminator?) + here: ...c>x)(?'xyz |<--| >y) /(?P'abc'x)(?Py)/I -Failed: error 141 at offset 3: unrecognized character after (?P +Failed: error 141 at offset 4: unrecognized character after (?P + here: (?P' |<--| abc'x)(?P<... /^(?:(?(ZZ)a|b)(?X))+/ bXaX @@ -7238,6 +7349,7 @@ No match /^(?P>abc)(?xxx)/ Failed: error 115 at offset 5: reference to non-existent subpattern + here: ^(?P> |<-->| abc)(?abc)(?x|y)/ xx @@ -7498,12 +7610,15 @@ No match /(?(| R')stuff) /((abc (?(R) (?(R1)1) (?(R2)2) X | (?1) (?2) (?R) ))) /x abcabc1Xabc2XabcXabcabc @@ -7519,9 +7634,11 @@ Failed: error 115 at offset 4: reference to non-existent subpattern /(? (?'B' abc (?(R) (?(R&C)1) (?(R&B)2) X | (?1) (?2) (?R) ))) /x Failed: error 115 at offset 27: reference to non-existent subpattern + here: ...?(R) (?(R& |<-->| C)1) (?(R&... /^(?(DEFINE) abc | xyz ) /x Failed: error 154 at offset 4: DEFINE subpattern contains more than one branch + here: ^(?( |-->| DEFINE) ab... /(?(DEFINE) abc) xyz/Ix Capture group count = 0 @@ -7558,6 +7675,8 @@ No match \= Expect no match a\rb No match + a\r\nb +No match /^a.b/newline=any \= Expect no match @@ -7565,7 +7684,113 @@ No match No match a\rb No match + a\r\nb +No match + a\x85b +No match + +/^a.b/newline=nul + a\nb + 0: a\x0ab +\= Expect no match + a\x{00}b +No match + +/^a./newline=lf + a\r + 0: a\x0d +\= Expect no match + a\n +No match + +/^a./newline=cr + a\n + 0: a\x0a +\= Expect no match + a\r +No match + +/^a./newline=anycrlf + a\x85 + 0: a\x85 +\= Expect no match + a\r +No match + a\n +No match + a\r\n +No match + +/^a./newline=any +\= Expect no match + a\n +No match + a\r +No match + a\r\n +No match + a\x85 +No match + +/^a./newline=nul + a\n + 0: a\x0a +\= Expect no match + a\x{00} +No match + +/^b/m,newline=lf + a\nb + 0: b +\= Expect no match + a\rb +No match + +/^b/m,newline=cr + a\rb + 0: b +\= Expect no match + a\nb +No match + +/^b/m,newline=anycrlf + a\rb + 0: b + a\nb + 0: b + a\r\nb + 0: b + \nb + 0: b + \rb + 0: b + \r\nb + 0: b +\= Expect no match + a\x85b +No match + +/^b/m,newline=any + a\nb + 0: b + a\rb + 0: b + a\r\nb + 0: b a\x85b + 0: b + \nb + 0: b + \rb + 0: b + \r\nb + 0: b + +/^b/m,newline=nul + a\x{00}b + 0: b +\= Expect no match + a\nb No match /^abc./gmx,newline=any @@ -7728,18 +7953,23 @@ No match /^(a)\g-2/ Failed: error 115 at offset 8: reference to non-existent subpattern + here: ^(a)\g-2 |<-->| /^(a)\g/ Failed: error 157 at offset 6: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number + here: ^(a)\g |<--| /^(a)\g{0}/ Failed: error 115 at offset 9: reference to non-existent subpattern + here: ^(a)\g{0} |<-->| /^(a)\g{3/ -Failed: error 157 at offset 6: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number +Failed: error 219 at offset 8: syntax error in subpattern number (missing terminator?) + here: ^(a)\g{3 |<--| /^(a)\g{aa}/ Failed: error 115 at offset 7: reference to non-existent subpattern + here: ^(a)\g{ |<-->| aa} /^a.b/newline=lf a\rb @@ -7863,15 +8093,19 @@ No match /x(?-0)y/ Failed: error 126 at offset 5: a relative value of zero is not allowed + here: x(?-0 |<--| )y /x(?-1)y/ Failed: error 115 at offset 5: reference to non-existent subpattern + here: x(?-1 |<-->| )y /x(?+0)y/ Failed: error 126 at offset 5: a relative value of zero is not allowed + here: x(?+0 |<--| )y /x(?+1)y/ Failed: error 115 at offset 5: reference to non-existent subpattern + here: x(?+1 |<-->| )y /^(abc)?(?(-1)X|Y)/B ------------------------------------------------------------------ @@ -7931,6 +8165,7 @@ No match /(?(-1)a)/B Failed: error 115 at offset 5: reference to non-existent subpattern + here: (?(-1 |<-->| )a) /((?(-1)a))/B ------------------------------------------------------------------ @@ -7947,6 +8182,7 @@ Failed: error 115 at offset 5: reference to non-existent subpattern /((?(-2)a))/B Failed: error 115 at offset 6: reference to non-existent subpattern + here: ((?(-2 |<-->| )a)) /^(?(+1)X|Y)(.)/B ------------------------------------------------------------------ @@ -7981,6 +8217,7 @@ No match /\g{A/ Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?) + here: \g{A |<--| /(?|(abc)|(xyz))/B ------------------------------------------------------------------ @@ -8124,6 +8361,8 @@ No match End ------------------------------------------------------------------ +#if !ebcdic + /\V+\x0a/B ------------------------------------------------------------------ Bra @@ -8133,6 +8372,8 @@ No match End ------------------------------------------------------------------ +#endif + /A+\h/B ------------------------------------------------------------------ Bra @@ -8268,21 +8509,27 @@ No match /[\E]AAA/ Failed: error 106 at offset 7: missing terminating ] for character class + here: [\E]AAA |<--| /[\Q\E]AAA/ Failed: error 106 at offset 9: missing terminating ] for character class + here: [\Q\E]AAA |<--| /[^\E]AAA/ Failed: error 106 at offset 8: missing terminating ] for character class + here: [^\E]AAA |<--| /[^\Q\E]AAA/ Failed: error 106 at offset 10: missing terminating ] for character class + here: [^\Q\E]AAA |<--| /[\E^]AAA/ Failed: error 106 at offset 8: missing terminating ] for character class + here: [\E^]AAA |<--| /[\Q\E^]AAA/ Failed: error 106 at offset 10: missing terminating ] for character class + here: [\Q\E^]AAA |<--| /A(*PRUNE)B(*SKIP)C(*THEN)D(*COMMIT)E(*F)F(*FAIL)G(?!)H(*ACCEPT)I/B ------------------------------------------------------------------ @@ -8435,9 +8682,11 @@ No match /a(*MARK)b/ Failed: error 166 at offset 7: (*MARK) must have an argument + here: a(*MARK |<--| )b /\g6666666666/ Failed: error 161 at offset 12: subpattern number is too big + here: ...6666666666 |<--| /[\g6666666666]/B ------------------------------------------------------------------ @@ -8449,6 +8698,7 @@ Failed: error 161 at offset 12: subpattern number is too big /(?1)\c[/ Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?1 |<-->| )\c[ /.+A/newline=crlf \= Expect no match @@ -8470,6 +8720,7 @@ No match /a(*CR)b/ Failed: error 160 at offset 5: (*VERB) not recognized or malformed + here: a(*CR |<--| )b /(*CR)a.b/ a\nb @@ -8727,27 +8978,35 @@ Subject length lower bound = 2 /(?)(?&)/ Failed: error 162 at offset 9: subpattern name expected + here: (?)(?& |<--| ) /(?)(?&a)/ Failed: error 115 at offset 11: reference to non-existent subpattern + here: ...?)(?& |<-->| a) /(?)(?&aaaaaaaaaaaaaaaaaaaaaaa)/ Failed: error 115 at offset 9: reference to non-existent subpattern + here: (?)(?& |<-->| aaaaaaaaaa... /(?+-a)/ -Failed: error 129 at offset 2: digit expected after (?+ or (?- +Failed: error 129 at offset 4: digit expected after (?+ + here: (?+- |<--| a) /(?-+a)/ -Failed: error 111 at offset 3: unrecognized character after (? or (?- +Failed: error 111 at offset 4: unrecognized character after (? or (?- + here: (?-+ |<--| a) /(?(-1))/ Failed: error 115 at offset 5: reference to non-existent subpattern + here: (?(-1 |<-->| )) /(?(+10))/ Failed: error 115 at offset 4: reference to non-existent subpattern + here: (?(+ |<-->| 10)) /(?(10))/ Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?( |<-->| 10)) /(?(+2))()()/ @@ -8755,54 +9014,71 @@ Failed: error 115 at offset 3: reference to non-existent subpattern /\k''/ Failed: error 162 at offset 3: subpattern name expected + here: \k' |<--| ' /\k<>/ Failed: error 162 at offset 3: subpattern name expected + here: \k< |<--| > /\k{}/ Failed: error 162 at offset 3: subpattern name expected + here: \k{ |<--| } /\k/ Failed: error 169 at offset 2: \k is not followed by a braced, angle-bracketed, or quoted name + here: \k |<--| /\kabc/ Failed: error 169 at offset 2: \k is not followed by a braced, angle-bracketed, or quoted name + here: \k |<--| abc /(?P=)/ Failed: error 162 at offset 4: subpattern name expected + here: (?P= |<--| ) /(?P>)/ Failed: error 162 at offset 4: subpattern name expected + here: (?P> |<--| ) /[[:foo:]]/ Failed: error 130 at offset 8: unknown POSIX class name + here: [[:foo:] |<--| ] /[[:1234:]]/ Failed: error 130 at offset 9: unknown POSIX class name + here: [[:1234:] |<--| ] /[[:f\oo:]]/ Failed: error 130 at offset 9: unknown POSIX class name + here: [[:f\oo:] |<--| ] /[[: :]]/ Failed: error 130 at offset 6: unknown POSIX class name + here: [[: :] |<--| ] /[[:...:]]/ Failed: error 130 at offset 8: unknown POSIX class name + here: [[:...:] |<--| ] /[[:l\ower:]]/ Failed: error 130 at offset 11: unknown POSIX class name + here: ...[:l\ower:] |<--| ] /[[:abc\:]]/ Failed: error 130 at offset 9: unknown POSIX class name + here: [[:abc\:] |<--| ] /[abc[:x\]pqr:]]/ Failed: error 130 at offset 14: unknown POSIX class name + here: ...[:x\]pqr:] |<--| ] /[[:a\dz:]]/ Failed: error 130 at offset 9: unknown POSIX class name + here: [[:a\dz:] |<--| ] /(^(a|b\g<-1'c))/ -Failed: error 157 at offset 8: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number +Failed: error 219 at offset 11: syntax error in subpattern number (missing terminator?) + here: ...^(a|b\g<-1 |<--| 'c)) /^(?+1)(?x|y){0}z/ xzxx @@ -8846,10 +9122,12 @@ Partial match: cat /(?2)[]a()b](abc)/ Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?2 |<-->| )[]a()b](a... abcbabc /(?2)[^]a()b](abc)/ Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?2 |<-->| )[^]a()b](... abcbabc /(?1)[]a()b](abc)/ @@ -8876,17 +9154,21 @@ No match /(?&N)[]a(?)](?abc)/ Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?& |<-->| N)[]a(?... abc)](abc)/ Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?& |<-->| N)[]a(?... abc| )(a)(?|(b)... XYabcdY /^X(?&N)(a)(?|(b)|(q))(c)(d)(?Y)/ @@ -9716,18 +10000,23 @@ No match /(a)(?<=b+(?1))/ Failed: error 125 at offset 3: length of lookbehind assertion is not limited + here: (a) |-->| (?<=b+(?1)... /(a+)(?<=b(?1))/ Failed: error 125 at offset 4: length of lookbehind assertion is not limited + here: (a+) |-->| (?<=b(?1)) /(a(?<=b(?1)))/ Failed: error 125 at offset 2: length of lookbehind assertion is not limited + here: (a |-->| (?<=b(?1))... /(?<=b(?1))xyz/ Failed: error 115 at offset 8: reference to non-existent subpattern + here: (?<=b(?1 |<-->| ))xyz /(?<=b(?1))xyz(b+)pqrstuvew/ Failed: error 125 at offset 0: length of lookbehind assertion is not limited + here: |-->| (?<=b(?1))... /(a|bc)\1/I Capture group count = 1 @@ -9853,6 +10142,7 @@ Subject length lower bound = 1 /(?|(?A)|(?B))/ Failed: error 165 at offset 16: different names for subpatterns of the same number are not allowed + here: ...a>A)|(? |<--| B)) /(?:a(? (?')|(?")) | b(? (?')|(?")) ) @@ -9904,7 +10194,7 @@ No match Ket c Cond - Capture ref 2 + Capture dnref2 d Alt e @@ -9948,7 +10238,7 @@ No match Ket Ket Cond - Capture ref 2 + Capture dnref2 X Alt Y @@ -9995,7 +10285,7 @@ No match CBra 4 d Cond - Cond recurse 2 + Cond dnrec2 $ Alt Recurse @@ -10153,7 +10443,7 @@ No match ab CBra 2 c - \1 + \g{1} Ket d Alt @@ -10163,7 +10453,7 @@ No match ab CBra 2 c - \1 + \g{1} Ket d Alt @@ -10236,9 +10526,11 @@ No match /abc(*MARK:)pqr/ Failed: error 166 at offset 10: (*MARK) must have an argument + here: abc(*MARK: |<--| )pqr /abc(*:)pqr/ Failed: error 166 at offset 6: (*MARK) must have an argument + here: abc(*: |<--| )pqr /(*COMMIT:X)/B ------------------------------------------------------------------ @@ -10558,14 +10850,23 @@ Failed: error -33: bad offset value abc\=offset=3 No match +#if !ebcdic + /^\cÄ£/ -Failed: error 168 at offset 3: \c must be followed by a printable ASCII character +Failed: error 168 at offset 4: \c must be followed by a printable ASCII character + here: ^\cÄ |<--| £ + +#endif + +/^\c/ +Failed: error 102 at offset 3: \c at end of pattern + here: ^\c |<--| /(?P(?P=abn)xxx)/B ------------------------------------------------------------------ Bra CBra 1 - \1 + \g{1} xxx Ket Ket @@ -10577,7 +10878,7 @@ Failed: error 168 at offset 3: \c must be followed by a printable ASCII characte Bra CBra 1 a - \1 + \g{1} z Ket Ket @@ -10586,15 +10887,17 @@ Failed: error 168 at offset 3: \c must be followed by a printable ASCII characte /(?P(?P=abn)(?(?P=axn)xxx)/B Failed: error 115 at offset 12: reference to non-existent subpattern + here: ...P(?P= |<-->| axn)xxx) /(?P(?P=axn)xxx)(?yy)/B ------------------------------------------------------------------ Bra CBra 1 - \2 + \g{2} xxx Ket CBra 2 @@ -10710,6 +11013,7 @@ Subject length lower bound = 5 /(?<=(abc)+)X/ Failed: error 125 at offset 0: length of lookbehind assertion is not limited + here: |-->| (?<=(abc)+... /(^ab)/I Capture group count = 1 @@ -11216,7 +11520,7 @@ Matched, but too many substrings Bra Brazero Assert back - Reverse + 3 Reverse CBra 1 abc Ket @@ -11396,7 +11700,7 @@ No match ------------------------------------------------------------------ Bra CBra 1 - \1 + \g{1} xxx Ket Ket @@ -11408,13 +11712,15 @@ No match Bra CBra 1 a - \1 + \g{1} z Ket Ket End ------------------------------------------------------------------ +#if !ebcdic + /^a\x41z/alt_bsux,allow_empty_class,match_unset_backref,dupnames aAz 0: aAz @@ -11466,6 +11772,8 @@ No match zoo 0: z +#endif + /\u{}/extra_alt_bsux u{} 0: u{} @@ -11521,13 +11829,16 @@ No match /a[\NB]c/ Failed: error 171 at offset 4: \N is not supported in a class + here: a[\N |<--| B]c aNc /a[B-\Nc]/ Failed: error 171 at offset 6: \N is not supported in a class + here: a[B-\N |<--| c] /a[B\Nc]/ Failed: error 171 at offset 5: \N is not supported in a class + here: a[B\N |<--| c] /(a)(?2){0,1999}?(b)/ @@ -13299,20 +13610,25 @@ Subject length lower bound = 1 # End of special auto-possessive tests /^A\o{1239}B/ -Failed: error 164 at offset 8: non-octal character in \o{} (closing brace missing?) +Failed: error 164 at offset 9: non-octal character in \o{} (closing brace missing?) + here: ^A\o{1239 |<--| }B A\123B /^A\oB/ Failed: error 155 at offset 4: missing opening brace after \o + here: ^A\o |<--| B /^A\x{zz}B/ -Failed: error 167 at offset 5: non-hex character in \x{} (closing brace missing?) +Failed: error 167 at offset 6: non-hex character in \x{} (closing brace missing?) + here: ^A\x{z |<--| z}B /^A\x{12Z/ -Failed: error 167 at offset 7: non-hex character in \x{} (closing brace missing?) +Failed: error 167 at offset 8: non-hex character in \x{} (closing brace missing?) + here: ^A\x{12Z |<--| /^A\x{/ Failed: error 178 at offset 5: digits missing after \x or in \x{} or \o{} or \N{U+} + here: ^A\x{ |<--| /[ab]++/B,no_auto_possess ------------------------------------------------------------------ @@ -13348,79 +13664,107 @@ Failed: error 178 at offset 5: digits missing after \x or in \x{} or \o{} or \N{ /[a-[:digit:]]+/ Failed: error 150 at offset 12: invalid range in character class + here: ...-[:digit:] |<--| ]+ /[A-[:digit:]]+/ Failed: error 150 at offset 12: invalid range in character class + here: ...-[:digit:] |<--| ]+ /[a-[.xxx.]]+/ Failed: error 150 at offset 10: invalid range in character class + here: [a-[.xxx.] |<--| ]+ /[a-[=xxx=]]+/ Failed: error 150 at offset 10: invalid range in character class + here: [a-[=xxx=] |<--| ]+ + +#if !ebcdic /[a-[!xxx!]]+/ -Failed: error 108 at offset 3: range out of order in character class +Failed: error 108 at offset 4: range out of order in character class + here: [a-[ |<--| !xxx!]]+ /[A-[!xxx!]]+/ A]]] 0: A]]] +#endif + /[a-\d]+/ Failed: error 150 at offset 5: invalid range in character class + here: [a-\d |<--| ]+ /(?<0abc>xx)/ -Failed: error 144 at offset 3: subpattern name must start with a non-digit +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: (?<0 |<--| abc>xx) /(?&1abc)xx(?<1abc>y)/ -Failed: error 144 at offset 3: subpattern name must start with a non-digit +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: (?&1 |<--| abc)xx(?<1... /(?xx)/ Failed: error 142 at offset 5: syntax error in subpattern name (missing terminator?) + here: (?xx) /(?'0abc'xx)/ -Failed: error 144 at offset 3: subpattern name must start with a non-digit +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: (?'0 |<--| abc'xx) /(?P<0abc>xx)/ -Failed: error 144 at offset 4: subpattern name must start with a non-digit +Failed: error 144 at offset 5: subpattern name must start with a non-digit + here: (?P<0 |<--| abc>xx) /\k<5ghj>/ -Failed: error 144 at offset 3: subpattern name must start with a non-digit +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: \k<5 |<--| ghj> /\k'5ghj'/ -Failed: error 144 at offset 3: subpattern name must start with a non-digit +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: \k'5 |<--| ghj' /\k{2fgh}/ -Failed: error 144 at offset 3: subpattern name must start with a non-digit +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: \k{2 |<--| fgh} /(?P=8yuki)/ -Failed: error 144 at offset 4: subpattern name must start with a non-digit +Failed: error 144 at offset 5: subpattern name must start with a non-digit + here: (?P=8 |<--| yuki) /\g{4df}/ -Failed: error 157 at offset 2: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number +Failed: error 219 at offset 4: syntax error in subpattern number (missing terminator?) + here: \g{4 |<--| df} /(?&1abc)xx(?<1abc>y)/ -Failed: error 144 at offset 3: subpattern name must start with a non-digit +Failed: error 144 at offset 4: subpattern name must start with a non-digit + here: (?&1 |<--| abc)xx(?<1... /(?P>1abc)xx(?<1abc>y)/ -Failed: error 144 at offset 4: subpattern name must start with a non-digit +Failed: error 144 at offset 5: subpattern name must start with a non-digit + here: (?P>1 |<--| abc)xx(?<1... /\g'3gh'/ -Failed: error 157 at offset 2: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number +Failed: error 219 at offset 4: syntax error in subpattern number (missing terminator?) + here: \g'3 |<--| gh' /\g<5fg>/ -Failed: error 157 at offset 2: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number +Failed: error 219 at offset 4: syntax error in subpattern number (missing terminator?) + here: \g<5 |<--| fg> /(?(<4gh>)abc)/ -Failed: error 144 at offset 4: subpattern name must start with a non-digit +Failed: error 144 at offset 5: subpattern name must start with a non-digit + here: (?(<4 |<--| gh>)abc) /(?('4gh')abc)/ -Failed: error 144 at offset 4: subpattern name must start with a non-digit +Failed: error 144 at offset 5: subpattern name must start with a non-digit + here: (?('4 |<--| gh')abc) /(?(4gh)abc)/ Failed: error 124 at offset 4: missing closing parenthesis for condition + here: (?(4 |<--| gh)abc) /(?(R&6yh)abc)/ -Failed: error 144 at offset 5: subpattern name must start with a non-digit +Failed: error 144 at offset 6: subpattern name must start with a non-digit + here: (?(R&6 |<--| yh)abc) /(((a\2)|(a*)\g<-1>))*a?/B ------------------------------------------------------------------ @@ -13430,7 +13774,7 @@ Failed: error 144 at offset 5: subpattern name must start with a non-digit CBra 2 CBra 3 a - \2 + \g{2} Ket Alt CBra 4 @@ -13456,7 +13800,7 @@ Failed: error 144 at offset 5: subpattern name must start with a non-digit red \b Assert back - Reverse + 1 Reverse \w Ket Ket @@ -13501,6 +13845,7 @@ No match /[a[:<:]] should give error/ Failed: error 130 at offset 7: unknown POSIX class name + here: [a[:<:] |<--| ] should g... /(?=ab\K)/aftertext,allow_lookaround_bsk abcd\=startchar @@ -13516,10 +13861,10 @@ No match # Test stack guard external calls. /(((a)))/stackguard=1 -Failed: error 133 at offset 7: parentheses are too deeply nested (stack check) +Failed: error 133 at offset 0: parentheses are too deeply nested (stack check) /(((a)))/stackguard=2 -Failed: error 133 at offset 7: parentheses are too deeply nested (stack check) +Failed: error 133 at offset 0: parentheses are too deeply nested (stack check) /(((a)))/stackguard=3 @@ -13536,7 +13881,7 @@ Failed: error 133 at offset 7: parentheses are too deeply nested (stack check) \s*+ Ket Assert back - Reverse + 1 Reverse \w Ket Ket @@ -13545,33 +13890,43 @@ Failed: error 133 at offset 7: parentheses are too deeply nested (stack check) /\othing/ Failed: error 155 at offset 2: missing opening brace after \o + here: \o |<--| thing /\o{}/ Failed: error 178 at offset 3: digits missing after \x or in \x{} or \o{} or \N{U+} + here: \o{ |<--| } /\o{whatever}/ -Failed: error 164 at offset 3: non-octal character in \o{} (closing brace missing?) +Failed: error 164 at offset 4: non-octal character in \o{} (closing brace missing?) + here: \o{w |<--| hatever} /\xthing/ Failed: error 178 at offset 2: digits missing after \x or in \x{} or \o{} or \N{U+} + here: \x |<--| thing /^A\xZ/ Failed: error 178 at offset 4: digits missing after \x or in \x{} or \o{} or \N{U+} + here: ^A\x |<--| Z /^A\x/ Failed: error 178 at offset 4: digits missing after \x or in \x{} or \o{} or \N{U+} + here: ^A\x |<--| /\x{}/ Failed: error 178 at offset 3: digits missing after \x or in \x{} or \o{} or \N{U+} + here: \x{ |<--| } /\x{whatever}/ -Failed: error 167 at offset 3: non-hex character in \x{} (closing brace missing?) +Failed: error 167 at offset 4: non-hex character in \x{} (closing brace missing?) + here: \x{w |<--| hatever} /A\8B/ -Failed: error 115 at offset 2: reference to non-existent subpattern +Failed: error 115 at offset 3: reference to non-existent subpattern + here: A\8 |<-->| B /A\9B/ -Failed: error 115 at offset 2: reference to non-existent subpattern +Failed: error 115 at offset 3: reference to non-existent subpattern + here: A\9 |<-->| B # This one is here because Perl fails to match "12" for this pattern when the $ # is present. @@ -13684,16 +14039,22 @@ No match No match /(?(VERSION<10)yes|no)/ -Failed: error 179 at offset 10: syntax error or number too big in (?(VERSION condition +Failed: error 179 at offset 11: syntax error or number too big in (?(VERSION condition + here: ...?(VERSION< |<--| 10)yes|no) /(?(VERSION>10)yes|no)/ Failed: error 179 at offset 11: syntax error or number too big in (?(VERSION condition + here: ...?(VERSION> |<--| 10)yes|no) /(?(VERSION>=10.0.0)yes|no)/ -Failed: error 179 at offset 16: syntax error or number too big in (?(VERSION condition +Failed: error 179 at offset 17: syntax error or number too big in (?(VERSION condition + here: ...ION>=10.0. |<--| 0)yes|no) /(?(VERSION=10.101)yes|no)/ -Failed: error 179 at offset 16: syntax error or number too big in (?(VERSION condition + +/(?(VERSION=10z)yes|no)/ +Failed: error 179 at offset 14: syntax error or number too big in (?(VERSION condition + here: ...ERSION=10z |<--| )yes|no) # We should see the starting code unit, required code unit, and minimum length set for this regex: /abcd/I @@ -13745,6 +14106,7 @@ Optimizations: auto_possess,dotstar_anchor /(((((a)))))/parens_nest_limit=2 Failed: error 119 at offset 3: parentheses are too deeply nested + here: ((( |-->| ((a))))) /abc/replace=XYZ 123123 @@ -13792,27 +14154,33 @@ Failed: error 119 at offset 3: parentheses are too deeply nested /abc/replace=a$++ 123abc -Failed: error -35 at offset 2 in replacement: invalid replacement string +Failed: error -49 at offset 3 in replacement: unknown substring + here: a$+ |<--| + /abc/replace=a$bad 123abc Failed: error -49 at offset 5 in replacement: unknown substring + here: a$bad |<--| /abc/replace=a${A234567890123456789_123456789012}z 123abc Failed: error -49 at offset 36 in replacement: unknown substring + here: ...456789012} |<--| z /abc/replace=a${A23456789012345678901234567890123}z 123abc Failed: error -49 at offset 37 in replacement: unknown substring + here: ...567890123} |<--| z /abc/replace=a${bcd 123abc Failed: error -58 at offset 6 in replacement: expected closing curly bracket in replacement string + here: a${bcd |<--| /abc/replace=a${b+d}z 123abc Failed: error -58 at offset 4 in replacement: expected closing curly bracket in replacement string + here: a${b |<--| +d}z /abc/replace=[10]XYZ 123abc123 @@ -13879,18 +14247,22 @@ Failed: error -34: bad option value /(*:pear)apple/g,replace=${*MARKING} apple lemon blackberry Failed: error -35 at offset 11 in replacement: invalid replacement string + here: ...{*MARKING} |<--| /(*:pear)apple/g,replace=${*MARK-time apple lemon blackberry Failed: error -58 at offset 7 in replacement: expected closing curly bracket in replacement string + here: ${*MARK |<--| -time /(*:pear)apple/g,replace=${*mark} apple lemon blackberry Failed: error -35 at offset 8 in replacement: invalid replacement string + here: ${*mark} |<--| /(*:pear)apple|(*:orange)lemon|(*:strawberry)blackberry/g,replace=<$*MARKET> apple lemon blackberry Failed: error -35 at offset 9 in replacement: invalid replacement string + here: <$*MARKET |<--| > /(*:pear)apple|(*:orange)lemon|(*:strawberry)blackberry/g,replace=[22]${*MARK} apple lemon blackberry @@ -13990,128 +14362,179 @@ Failed: error -48: no more memory: 10 code units are needed 1: Z>b\2< Failed: error -49 at offset 3 in replacement: unknown substring + here: >\2 |<--| < ZabcZ\=replace=>\8< Failed: error -49 at offset 3 in replacement: unknown substring + here: >\8 |<--| < ZabcZ\=replace=>${1}< 1: Z>b${ 1 }< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >${ |<--| 1 }< ZabcZ\=replace=>${2}< Failed: error -49 at offset 5 in replacement: unknown substring + here: >${2} |<--| < ZabcZ\=replace=>${8}< Failed: error -49 at offset 5 in replacement: unknown substring + here: >${8} |<--| < ZabcZ\=replace=>$<1>< Failed: error -49 at offset 5 in replacement: unknown substring + here: >$<1> |<--| < ZabcZ\=replace=>$< 1 >< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >$< |<--| 1 >< ZabcZ\=replace=>$<2>< Failed: error -49 at offset 5 in replacement: unknown substring + here: >$<2> |<--| < ZabcZ\=replace=>$<8>< Failed: error -49 at offset 5 in replacement: unknown substring + here: >$<8> |<--| < ZabcZ\=replace=>\g<-1>< Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: >\g< |<--| -1>< ZabcZ\=replace=>\g<0>< 1: Z>abc\g<1>< 1: Z>b\g< 1 >< Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: >\g< |<--| 1 >< ZabcZ\=replace=>\g<2>< Failed: error -49 at offset 6 in replacement: unknown substring + here: >\g<2> |<--| < ZabcZ\=replace=>\g<8>< Failed: error -49 at offset 6 in replacement: unknown substring + here: >\g<8> |<--| < /(*:pear)apple/substitute_extended ZappleZ\=replace=>${*MARK}< 1: Z>pear$<*MARK>< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >$< |<--| *MARK>< ZappleZ\=replace=>\g<*MARK>< Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: >\g< |<--| *MARK>< /a(?b)c/substitute_extended ZabcZ\=replace=>${named}< 1: Z>b${noexist}< Failed: error -49 at offset 11 in replacement: unknown substring + here: ...${noexist} |<--| < ZabcZ\=replace=>${}< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >${ |<--| }< ZabcZ\=replace=>${ }< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >${ |<--| }< ZabcZ\=replace=>${ named }< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >${ |<--| named }< ZabcZ\=replace=>$< 1: Z>b$< Failed: error -49 at offset 11 in replacement: unknown substring + here: ...$ |<--| < ZabcZ\=replace=>$<>< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >$< |<--| >< ZabcZ\=replace=>$< >< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >$< |<--| >< ZabcZ\=replace=>$< named >< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >$< |<--| named >< ZabcZ\=replace=>\g< 1: Z>b\g< Failed: error -49 at offset 12 in replacement: unknown substring + here: ...g |<--| < ZabcZ\=replace=>\g<>< Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: >\g< |<--| >< ZabcZ\=replace=>\g< >< Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: >\g< |<--| >< ZabcZ\=replace=>\g< named >< Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: >\g< |<--| named >< /a(b)c/substitute_extended ZabcZ\=replace=>${1:+ yes : no } 1: Z> yes Z - ZabcZ\=replace=>${1:+ \o{100} : \o{100} } - 1: Z> @ Z ZabcZ\=replace=>${1:+ \o{Z} : no } -Failed: error -57 at offset 9 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 11 in replacement: bad escape sequence in replacement string + here: ...${1:+ \o{Z |<--| } : no } ZabcZ\=replace=>${1:+ yes : \o{Z} } -Failed: error -57 at offset 15 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 17 in replacement: bad escape sequence in replacement string + here: ...yes : \o{Z |<--| } } ZabcZ\=replace=>${1:+ \g<1> : no } 1: Z> b Z ZabcZ\=replace=>${1:+ yes : \g<1> } 1: Z> yes Z ZabcZ\=replace=>${1:+ \g<1 : no } -Failed: error -57 at offset 8 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 11 in replacement: bad escape sequence in replacement string + here: ...${1:+ \g<1 |<--| : no } ZabcZ\=replace=>${1:+ yes : \g<1 } -Failed: error -57 at offset 14 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 17 in replacement: bad escape sequence in replacement string + here: ...yes : \g<1 |<--| } ZabcZ\=replace=>${1:+ $<1> : no } Failed: error -49 at offset 11 in replacement: unknown substring + here: ...${1:+ $<1> |<--| : no } ZabcZ\=replace=>${1:+ yes : $<1> } 1: Z> yes Z ZabcZ\=replace=>${1:+ $<1 : no } Failed: error -35 at offset 10 in replacement: invalid replacement string + here: >${1:+ $<1 |<--| : no } ZabcZ\=replace=>${1:+ yes : $<1 } 1: Z> yes Z +#if !ebcdic + +/a(b)c/substitute_extended + ZabcZ\=replace=>${1:+ \o{100} : \o{100} } + 1: Z> @ Z + +#endif + /a(b)c/substitute_extended ZabcZ\=replace=>${ Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >${ |<--| ZabcZ\=replace=>${1 Failed: error -58 at offset 4 in replacement: expected closing curly bracket in replacement string + here: >${1 |<--| ZabcZ\=replace=>${1Z Failed: error -58 at offset 4 in replacement: expected closing curly bracket in replacement string + here: >${1 |<--| Z ZabcZ\=replace=>${1; Failed: error -58 at offset 4 in replacement: expected closing curly bracket in replacement string + here: >${1 |<--| ; ZabcZ\=replace=>$< Failed: error -35 at offset 3 in replacement: invalid replacement string + here: >$< |<--| ZabcZ\=replace=>$<1 Failed: error -35 at offset 4 in replacement: invalid replacement string + here: >$<1 |<--| ZabcZ\=replace=>$<1Z Failed: error -35 at offset 5 in replacement: invalid replacement string + here: >$<1Z |<--| ZabcZ\=replace=>$<1; Failed: error -35 at offset 4 in replacement: invalid replacement string + here: >$<1 |<--| ; ZabcZ\=replace=>\g< Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: >\g< |<--| ZabcZ\=replace=>\g<1 -Failed: error -57 at offset 3 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 5 in replacement: bad escape sequence in replacement string + here: >\g<1 |<--| ZabcZ\=replace=>\g<1Z -Failed: error -57 at offset 3 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 5 in replacement: bad escape sequence in replacement string + here: >\g<1 |<--| Z ZabcZ\=replace=>\g<1; -Failed: error -57 at offset 3 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 5 in replacement: bad escape sequence in replacement string + here: >\g<1 |<--| ; "((?=(?(?=(?(?=(?(?=()))))))))" a @@ -14155,6 +14578,7 @@ Start of matched string is beyond its end - displaying from end to start. Matched, but too many substrings 0: a Copy substring "A" failed (-54): requested value is not available +Get substring "A" length failed (-54): requested value is not available Get substring 2 failed (-54): requested value is not available Get substring "A" failed (-54): requested value is not available a\=ovector=2,copy=A,get=A,get=2 @@ -14168,6 +14592,7 @@ Matched, but too many substrings 0: b 1: Copy substring "A" failed (-55): requested value is not set +Get substring "A" length failed (-55): requested value is not set Get substring 2 failed (-54): requested value is not available Get substring "A" failed (-55): requested value is not set @@ -14176,6 +14601,7 @@ Get substring "A" failed (-55): requested value is not set Partial match: abc 0C abc (3) Copy substring 1 failed (-2): partial match +Get substring 1 length failed (-2): partial match get substring list failed (-2): partial match /^abc/info @@ -14370,7 +14796,8 @@ Matched, but too many substrings # OK in conditions. /(?(?=0)?)+/ -Failed: error 109 at offset 7: quantifier does not follow a repeatable item +Failed: error 109 at offset 8: quantifier does not follow a repeatable item + here: (?(?=0)? |<--| )+ /(?(?=0)(?=00)?00765)/ 00765 @@ -14412,7 +14839,7 @@ Matched, but too many substrings CBra 1 Recurse CBra 2 - \1 + \g{1} Ket Ket Ket @@ -14423,15 +14850,19 @@ Matched, but too many substrings /a(?C"/ Failed: error 181 at offset 4: missing terminating delimiter for callout with string argument + here: a(?C |-->| " /a(?C"a/ Failed: error 181 at offset 4: missing terminating delimiter for callout with string argument + here: a(?C |-->| "a /a(?C"a"/ Failed: error 139 at offset 7: closing parenthesis for (?C expected + here: a(?C"a" |<--| /a(?C"a"bcde(?C"b")xyz/ Failed: error 139 at offset 7: closing parenthesis for (?C expected + here: a(?C"a" |<--| bcde(?C"b"... /a(?C"a)b""c")/B ------------------------------------------------------------------ @@ -14654,7 +15085,8 @@ Failed: error -52: nested recursion at the same subject position # Perl fails to diagnose the absence of an assertion "(?(?.*!.*)?)" -Failed: error 128 at offset 2: atomic assertion expected after (?( or (?(?C) +Failed: error 128 at offset 3: atomic assertion expected after (?( or (?(?C) + here: (?( |<--| ?.*!.*)... "X((?2)()*+){2}+"B ------------------------------------------------------------------ @@ -14700,19 +15132,24 @@ Failed: error 128 at offset 2: atomic assertion expected after (?( or (?(?C) /(?<=\bABQ(3(?-7)))/ Failed: error 115 at offset 15: reference to non-existent subpattern + here: ...bABQ(3(?-7 |<-->| ))) /(?<=\bABQ(3(?+7)))/ Failed: error 115 at offset 15: reference to non-existent subpattern + here: ...bABQ(3(?+7 |<-->| ))) ";(?<=()((?3))((?2)))" Failed: error 125 at offset 1: length of lookbehind assertion is not limited + here: ; |-->| (?<=()((?3... # Perl loops on this (PCRE2 used to!) +# duplicate matches /(?<=\Ka)/g,aftertext,allow_lookaround_bsk aaaaa 0: a 0+ aaaa +global repeat returned the same match as previous 0: a 0+ aaa 0: a @@ -14735,6 +15172,106 @@ Failed: error 125 at offset 1: length of lookbehind assertion is not limited 0: a 0+ +# overlapping matches +/(?(?=\Gc)(?<=\Kb)c|(?<=\Kab))/g,aftertext,allow_lookaround_bsk + abc + 0: ab + 0+ c + 0: bc + 0+ + +# not-sorted matches +/(?(?=\Gc)(?<=\Kab)|(?<=\Kb))/g,aftertext,allow_lookaround_bsk + abc + 0: b + 0+ c + 0: ab + 0+ c + +# CRLF cases + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=LF + back\rstart back\nstart back\r\nstart back\r + 0: back + 0+ \x0dstart back\x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0astart back\x0d\x0astart back\x0d + 0: back + 0+ \x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0d\x0astart back\x0d + 0: back + 0+ \x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: back + 0+ \x0d +global repeat returned the same match as previous + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=CRLF + back\rstart back\nstart back\r\nstart back\r + 0: back + 0+ \x0dstart back\x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0astart back\x0d\x0astart back\x0d + 0: back + 0+ \x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0d\x0astart back\x0d + 0: back + 0+ \x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0d + 0: back + 0+ \x0d +global repeat returned the same match as previous + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=ANYCRLF + back\rstart back\nstart back\r\nstart back\r + 0: back + 0+ \x0dstart back\x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0astart back\x0d\x0astart back\x0d + 0: back + 0+ \x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0d\x0astart back\x0d + 0: back + 0+ \x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0d + 0: back + 0+ \x0d +global repeat returned the same match as previous + +/(?<=\Kback)|\Gstart/g,aftertext,allow_lookaround_bsk,newline=ANY + back\rstart back\nstart back\r\nstart back\r + 0: back + 0+ \x0dstart back\x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0astart back\x0d\x0astart back\x0d + 0: back + 0+ \x0astart back\x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0d\x0astart back\x0d + 0: back + 0+ \x0d\x0astart back\x0d +global repeat returned the same match as previous + 0: start + 0+ back\x0d + 0: back + 0+ \x0d +global repeat returned the same match as previous + /((?2){73}(?2))((?1))/info Capture group count = 2 May match empty string @@ -14750,6 +15287,15 @@ No match 0: abcabcabcabcabc 1: abc +/(abc)*/ + \[abc]{1} + 0: abc + 1: abc + +/(abc)*/ + \[abc]{0} +** Zero or negative repeat not allowed + /^/gm \n\n\n 0: @@ -14764,7 +15310,8 @@ No match 0: /((((((((x))))))))\81/ -Failed: error 115 at offset 19: reference to non-existent subpattern +Failed: error 115 at offset 20: reference to non-existent subpattern + here: ...)))))))\81 |<-->| xx1 /((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((x))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))\80/ @@ -14787,10 +15334,12 @@ Matched, but too many substrings 14: x /\80/ -Failed: error 115 at offset 2: reference to non-existent subpattern +Failed: error 115 at offset 3: reference to non-existent subpattern + here: \80 |<-->| /A\8B\9C/ -Failed: error 115 at offset 2: reference to non-existent subpattern +Failed: error 115 at offset 3: reference to non-existent subpattern + here: A\8 |<-->| B\9C A8B9C /(?x:((?'a')) # comment (with parentheses) and | vertical @@ -14837,7 +15386,7 @@ Subject length lower bound = 1 Recurse Recurse Alt - \1 + \g{1} Alt $ Ket @@ -14858,7 +15407,7 @@ Subject length lower bound = 1 Ket Recurse Alt - \1 + \g{1} Alt $ Ket @@ -14869,10 +15418,12 @@ Subject length lower bound = 1 ------------------------------------------------------------------ /(\9*+(?2);\3++()2|)++{/ -Failed: error 115 at offset 2: reference to non-existent subpattern +Failed: error 115 at offset 3: reference to non-existent subpattern + here: (\9 |<-->| *+(?2);\3+... /\V\x85\9*+((?2)\3++()2)*:2/ -Failed: error 115 at offset 7: reference to non-existent subpattern +Failed: error 115 at offset 8: reference to non-existent subpattern + here: \V\x85\9 |<-->| *+((?2)\3+... /(((?(R)){0,2}) (?'x'((?'R')((?'R')))))/dupnames @@ -14884,14 +15435,17 @@ Failed: error 115 at offset 7: reference to non-existent subpattern "(?=!((?2)(?))({8(?<=(?1){29}8bbbb\x16\xd\xc6^($(\xa9H4){4}h}?1)B))\x15')" Failed: error 125 at offset 16: length of lookbehind assertion is not limited + here: ...?2)(?))({8 |-->| (?<=(?1){2... /A(?'')Z/ Failed: error 162 at offset 4: subpattern name expected + here: A(?' |<--| ')Z "(?J:(?|(?'R')(\k'R')|((?'R'))))" /(?<=|(\,\$(?73591620449005828816)\xa8.{7}){6}\x09)/ Failed: error 161 at offset 32: subpattern number is too big + here: ...9005828816 |<--| )\xa8.{7})... /^(?:(?(1)x|)+)+$()/B ------------------------------------------------------------------ @@ -14913,15 +15467,19 @@ Failed: error 161 at offset 32: subpattern number is too big /[[:>:]](?<)/ Failed: error 162 at offset 10: subpattern name expected + here: [[:>:]](?< |<--| ) /((?x)(*:0))#(?'/ Failed: error 162 at offset 15: subpattern name expected + here: ...(*:0))#(?' |<--| /(?C$[$)(?<]/ Failed: error 162 at offset 10: subpattern name expected + here: (?C$[$)(?< |<--| ] /(?C$)$)(?<]/ Failed: error 162 at offset 10: subpattern name expected + here: (?C$)$)(?< |<--| ] /(?(R))*+/B ------------------------------------------------------------------ @@ -14929,7 +15487,7 @@ Failed: error 162 at offset 10: subpattern name expected Braposzero SBraPos SCond - Cond recurse any + Cond rec any Ket KetRpos Ket @@ -14940,6 +15498,7 @@ Failed: error 162 at offset 10: subpattern name expected /((?x)(?#))#(?'/ Failed: error 162 at offset 14: subpattern name expected + here: ...)(?#))#(?' |<--| /((?x)(?#))#(?'abc')/I Capture group count = 2 @@ -14950,6 +15509,7 @@ Subject length lower bound = 1 /[[:\\](?<[::]/ Failed: error 162 at offset 9: subpattern name expected + here: [[:\\](?< |<--| [::] /[[:\\](?'abc')[a:]/I Capture group count = 1 @@ -14960,6 +15520,7 @@ Subject length lower bound = 2 "[[[.\xe8Nq\xffq\xff\xe0\x2|||::Nq\xffq\xff\xe0\x6\x2|||::[[[:[::::::[[[[[::::::::[:[[[:[:::[[[[[[[[[[[[:::::::::::::::::[[.\xe8Nq\xffq\xff\xe0\x2|||::Nq\xffq\xff\xe0\x6\x2|||::[[[:[::::::[[[[[::::::::[:[[[:[:::[[[[[[[[[[[[[[:::E[[[:[:[[:[:::[[:::E[[[:[:[[:'[:::::E[[[:[::::::[[[:[[[[[[[::E[[[:[::::::[[[:[[[[[[[[:[[::[::::[[:::::::[[:[[[[[[[:[[::[:[[:[~" Failed: error 106 at offset 353: missing terminating ] for character class + here: ...[::[:[[:[~ |<--| /()(?(R)0)*+/B ------------------------------------------------------------------ @@ -14969,7 +15530,7 @@ Failed: error 106 at offset 353: missing terminating ] for character class Braposzero SBraPos SCond - Cond recurse any + Cond rec any 0 Ket KetRpos @@ -14979,12 +15540,15 @@ Failed: error 106 at offset 353: missing terminating ] for character class /(?R-:(?>abcd<< 1: >>w\rx\x82y\o{333}z(\Q12\$34$$\x34\E5$$)<< + +#endif /abcd/g,replace=\$1$2\,substitute_literal XabcdYabcdZ @@ -15238,6 +15839,7 @@ No match /abcd/replace=xy\kz,substitute_extended abcd Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: xy\k |<--| z /a(?:(b)|(c))/substitute_extended,replace=X${1:+1:-1}X${2:+2:-2} ab @@ -15270,22 +15872,27 @@ Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement /a/substitute_extended,replace=${*MARK:+a:b} a Failed: error -58 at offset 7 in replacement: expected closing curly bracket in replacement string + here: ${*MARK |<--| :+a:b} /(abcd)/replace=${1:+xy\kz},substitute_extended abcd -Failed: error -57 at offset 8 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 9 in replacement: bad escape sequence in replacement string + here: ${1:+xy\k |<--| z} /(abcd)/ abcd\=replace=${1:+xy\kz},substitute_extended -Failed: error -57 at offset 8 in replacement: bad escape sequence in replacement string +Failed: error -57 at offset 9 in replacement: bad escape sequence in replacement string + here: ${1:+xy\k |<--| z} /abcd/substitute_extended,replace=>$1< abcd Failed: error -49 at offset 3 in replacement: unknown substring + here: >$1 |<--| < /abcd/substitute_extended,replace=>xxx${xyz}<<< abcd Failed: error -49 at offset 10 in replacement: unknown substring + here: >xxx${xyz} |<--| <<< /(?J)(?:(?a)|(?b))/replace=<$A> [a] @@ -15295,11 +15902,13 @@ Failed: error -49 at offset 10 in replacement: unknown substring \= Expect error (a)\=ovector=1 Failed: error -54 at offset 3 in replacement: requested value is not available + here: <$A |<--| > /(a)|(b)/replace=<$1> \= Expect error b Failed: error -55 at offset 3 in replacement: requested value is not set + here: <$1 |<--| > /(aa)(BB)/substitute_extended,replace=\U$1\L$2\E$1..\U$1\l$2$1 aaBB @@ -15315,6 +15924,8 @@ Failed: error -55 at offset 3 in replacement: requested value is not set >abcd1234abcd5678<\=replace=wxyz,substitute_matched 2: >wxyz1234wxyz5678< +#if !ebcdic + /abc/substitute_extended,replace=>\045< abc 1: >%< @@ -15327,9 +15938,12 @@ Failed: error -55 at offset 3 in replacement: requested value is not set abc 1: >%< +#endif + /abc/substitute_extended,replace=>\845< abc Failed: error -49 at offset 5 in replacement: unknown substring + here: >\845 |<--| < /a(b)(c)/substitute_extended,replace=>\1< abc @@ -15342,6 +15956,7 @@ Failed: error -49 at offset 5 in replacement: unknown substring /a(b)(c)/substitute_extended,replace=>\3< abc Failed: error -49 at offset 3 in replacement: unknown substring + here: >\3 |<--| < /a(?b)c/substitute_extended abc\=replace=>${namED_1}< @@ -15365,6 +15980,68 @@ Failed: error -49 at offset 3 in replacement: unknown substring LabcR\=replace=>$_< 1: L>LabcR$+< + 1: >M$+< + 1: >M$+ + 1: >MZ + AMZ\=replace=>$+{name} +Failed: error -35 at offset 2 in replacement: invalid replacement string + here: >$ |<--| +{name} + BMZ\=ovector=2 +Matched, but too many substrings + 0: BM + 1: + BMZ\=ovector=3 + 0: BM + 1: + 2: M + BMZ\=ovector=2,replace=>$+< +Failed: error -54 at offset 3 in replacement: requested value is not available + here: >$+ |<--| < + BMZ\=ovector=3,replace=>$+< + 1: >M$+< +Failed: error -54 at offset 3 in replacement: requested value is not available + here: >$+ |<--| < + BMZ\=ovector=3,substitute_matched,replace=>$+< + 1: >M$1< + 1: >B< + A\=replace=>$1< +Failed: error -55 at offset 3 in replacement: requested value is not set + here: >$1 |<--| < + B\=substitute_unset_empty,replace=>$1< + 1: >B< + A\=substitute_unset_empty,replace=>$1< + 1: >< + B\=replace=>$+< + 1: >B< + A\=replace=>$+< +Failed: error -55 at offset 3 in replacement: requested value is not set + here: >$+ |<--| < + B\=substitute_unset_empty,replace=>$+< + 1: >B< + A\=substitute_unset_empty,replace=>$+< + 1: >< + +/ABC/ + ABC\=replace=$+z +Failed: error -49 at offset 2 in replacement: unknown substring + here: $+ |<--| z + ABC\=substitute_unknown_unset,replace=$+z +Failed: error -55 at offset 2 in replacement: requested value is not set + here: $+ |<--| z + ABC\=substitute_unset_empty,replace=$+z +Failed: error -49 at offset 2 in replacement: unknown substring + here: $+ |<--| z + ABC\=substitute_unknown_unset,substitute_unset_empty,replace=$+z + 1: z + /^(o(\1{72}{\"{\\{00000059079}\d*){74}}){19}/I Capture group count = 2 Max back reference = 1 @@ -15376,16 +16053,20 @@ Subject length lower bound = 65535 /((p(?'K/ Failed: error 142 at offset 7: syntax error in subpattern name (missing terminator?) + here: ((p(?'K |<--| /((p(?'K/no_auto_capture Failed: error 142 at offset 7: syntax error in subpattern name (missing terminator?) + here: ((p(?'K |<--| /abc/replace=A$3123456789Z abc Failed: error -49 at offset 3 in replacement: unknown substring + here: A$3 |<--| 123456789Z /(?| (?| (?<=a() +((... # Test the use of malloc for caching group information when there are more # groups than fit into the on-stack workspace. @@ -15662,6 +16346,8 @@ Subject length lower bound = 0 0: ] 1: +#if !ebcdic + /\x8a+f|;T?(*:;.'?`(\xeap ){![^()!y*''C*(?';]{1;(\x08)/B,alt_verbnames,dupnames,extended ------------------------------------------------------------------ Bra @@ -15681,6 +16367,8 @@ Subject length lower bound = 0 End ------------------------------------------------------------------ +#endif + # Tests for NULL characters in comments and verb "names" and callouts # /A#B\x00C\x0aZ/ @@ -15756,6 +16444,7 @@ Subject length lower bound = 0 /(8(*:6^\x09x\xa6l\)6!|\xd0:[^:|)\x09d\Z\d{85*m(?'(?<1!)*\W[*\xff]!!h\w]*\xbe;/alt_bsux,alt_verbnames,allow_empty_class,dollar_endonly,extended,multiline,never_utf,no_dotstar_anchor,no_start_optimize Failed: error 162 at offset 49: subpattern name expected + here: ...\d{85*m(?' |<--| (?<1!)*\W[... /a|(b)c/replace=>$1<,substitute_unset_empty cat @@ -15766,6 +16455,7 @@ Failed: error 162 at offset 49: subpattern name expected /a|(b)c/ cat\=replace=>$1< Failed: error -55 at offset 3 in replacement: requested value is not set + here: >$1 |<--| < cat\=replace=>$1<,substitute_unset_empty 1: c>$1<,substitute_unset_empty @@ -15774,6 +16464,7 @@ Failed: error -55 at offset 3 in replacement: requested value is not set /a|(b)c/substitute_extended cat\=replace=>${2:-xx}< Failed: error -49 at offset 9 in replacement: unknown substring + here: >${2:-xx} |<--| < cat\=replace=>${2:-xx}<,substitute_unknown_unset 1: c>xx${X:-xx}<,substitute_unknown_unset @@ -15788,18 +16479,22 @@ Failed: error -49 at offset 9 in replacement: unknown substring /a|(?'X'b)c/replace=>$Y<,substitute_unset_empty cat Failed: error -49 at offset 3 in replacement: unknown substring + here: >$Y |<--| < cat\=substitute_unknown_unset 1: c>$Y |<--| < /a|(b)c/replace=>$2<,substitute_unset_empty cat Failed: error -49 at offset 3 in replacement: unknown substring + here: >$2 |<--| < cat\=substitute_unknown_unset 1: c>$2 |<--| < /()()()/use_offset_limit \=ovector=11000000000 @@ -15847,7 +16542,8 @@ MK: A\x00b ** Unexpected non-hex-digit 'g' at offset 3 in hex pattern: quote missing? /(?J)(?'a'))(?'a')/ -Failed: error 122 at offset 10: unmatched closing parenthesis +Failed: error 122 at offset 11: unmatched closing parenthesis + here: ...?J)(?'a')) |<--| (?'a') /(?<=((?C)0))/ 9010 @@ -15878,12 +16574,15 @@ No match /'(*U'/hex Failed: error 160 at offset 3: (*VERB) not recognized or malformed + here: (*U |<--| /'(*'/hex -Failed: error 109 at offset 1: quantifier does not follow a repeatable item +Failed: error 109 at offset 2: quantifier does not follow a repeatable item + here: (* |<--| /'('/hex Failed: error 114 at offset 1: missing closing parenthesis + here: ( |<--| //hex @@ -15903,6 +16602,7 @@ No match /(?|([ab]))...(?<=\1)z/ Failed: error 125 at offset 13: length of lookbehind assertion is not limited + here: ...([ab]))... |-->| (?<=\1)z /([ab])(\1)...(?<=\2)z/ aa11az @@ -15912,6 +16612,7 @@ Failed: error 125 at offset 13: length of lookbehind assertion is not limited /(a\2)(b\1)(?<=\2)/ Failed: error 125 at offset 10: length of lookbehind assertion is not limited + here: (a\2)(b\1) |-->| (?<=\2) /(?[ab])...(?<=\k'A')z/ a11az @@ -15926,6 +16627,7 @@ No match /(?[ab])...(?<=\k'A')(?)z/dupnames Failed: error 125 at offset 13: length of lookbehind assertion is not limited + here: ...A>[ab])... |-->| (?<=\k'A')... # Perl does not support \g+n @@ -15958,14 +16660,17 @@ Failed: error 125 at offset 13: length of lookbehind assertion is not limited /[a-[:digit:]]+/ Failed: error 150 at offset 12: invalid range in character class + here: ...-[:digit:] |<--| ]+ a-a9-a /[A-[:digit:]]+/ Failed: error 150 at offset 12: invalid range in character class + here: ...-[:digit:] |<--| ]+ A-A9-A /[a-\d]+/ Failed: error 150 at offset 5: invalid range in character class + here: [a-\d |<--| ]+ a-a9-a /(?abc)(?(R)xyz)/B @@ -15975,7 +16680,7 @@ Failed: error 150 at offset 5: invalid range in character class abc Ket Cond - Cond recurse any + Cond rec any xyz Ket Ket @@ -16003,6 +16708,7 @@ Subject length lower bound = 0 /()(?<=(?0))/ Failed: error 125 at offset 2: length of lookbehind assertion is not limited + here: () |-->| (?<=(?0)) /(?*?\g'0/use_length -Failed: error 157 at offset 6: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number +Failed: error 219 at offset 8: syntax error in subpattern number (missing terminator?) + here: .>*?\g'0 |<--| /.>*?\g'0/ -Failed: error 157 at offset 6: \g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number +Failed: error 219 at offset 8: syntax error in subpattern number (missing terminator?) + here: .>*?\g'0 |<--| /{„Í„Í̈́Í{'{22{2{{2{'{22{{22{2{'{22{2{{2{{222{{2{'{22{2{22{2{'{22{2{{2{'{22{2{22{2{'{'{22{2{22{2{'{22{2{{2{'{22{2{22{2{'{222{2Ą̈́Í̈́Í{'{22{2{{2{'{22{{11{2{'{22{2{{2{{'{22{2{{2{'{22{{22{1{'{22{2{{2{{222{{2{'{22{2{22{2{'{/auto_callout @@ -16026,14 +16734,17 @@ Failed: error 157 at offset 6: \g is not followed by a braced, angle-bracketed, "(?(?C))" Failed: error 128 at offset 6: atomic assertion expected after (?( or (?(?C) + here: (?(?C) |<--| ) /(?(?(?(?(?(?))))))/ -Failed: error 128 at offset 2: atomic assertion expected after (?( or (?(?C) +Failed: error 128 at offset 3: atomic assertion expected after (?( or (?(?C) + here: (?( |<--| ?(?(?(?(?)... /(?<=(?1))((?s))/anchored /(*:ab)*/ -Failed: error 109 at offset 6: quantifier does not follow a repeatable item +Failed: error 109 at offset 7: quantifier does not follow a repeatable item + here: (*:ab)* |<--| %(*:(:(svvvvvvvvvv:]*[ Z!*;[]*[^[]*!^[+.+{{2,7}' _\\\\\\\\\\\\\)?.:.. *w////\\\Q\\\\\\\\\\\\\\\T\\\\\+/?/////'+\\\EEE?/////'+/*+/[^K]?]//(w)%never_backslash_c,alt_verbnames,auto_callout @@ -16044,6 +16755,7 @@ No match /(\x0e00\000000\xc)/replace=\P,substitute_extended \x0e00\000000\xc Failed: error -57 at offset 2 in replacement: bad escape sequence in replacement string + here: \P |<--| //replace=0 \=offset=7 @@ -16095,13 +16807,16 @@ Subject length lower bound = 1 /.+(?(?C'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'))?!XXXX.=X/ Failed: error 128 at offset 63: atomic assertion expected after (?( or (?(?C) + here: ...XXXXXXXX') |<--| )?!XXXX.=X .+(?(?C'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'))?!XXXX.=X /[:[:alnum:]-[[a:lnum:]+/ Failed: error 150 at offset 12: invalid range in character class + here: ...[:alnum:]- |<--| [[a:lnum:]... /((?(?C'')\QX\E(?!((?(?C'')(?!X=X));=)r*X=X));=)/ -Failed: error 128 at offset 11: atomic assertion expected after (?( or (?(?C) +Failed: error 128 at offset 9: atomic assertion expected after (?( or (?(?C) + here: ((?(?C'') |<--| \QX\E(?!((... /((?(?C'')\Q\E(?!((?(?C'')(?!X=X));=)r*X=X));=)/ @@ -16114,9 +16829,11 @@ Failed: error -37: callout error code /()(\g+65534)/ Failed: error 161 at offset 11: subpattern number is too big + here: ...)(\g+65534 |<--| ) /()(\g+65533)/ -Failed: error 115 at offset 10: reference to non-existent subpattern +Failed: error 115 at offset 11: reference to non-existent subpattern + here: ...)(\g+65533 |<-->| ) /Á\x00\x00\x00š(\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\2*\x00k\d+\x00‎\x00\x00\x00\x00\x00\2*\x00\x00\1*.){36}int^\x00\x00ÿÿ\x00š(\1{50779}?)J\w2/I Capture group count = 2 @@ -16228,7 +16945,8 @@ No match /(?)/expand Failed: error 197 at offset 131075: too many capturing groups (maximum 65535) + here: ...)()()(? |<--| ) /a(?:(*ACCEPT))??bc/ abc @@ -17595,10 +18337,12 @@ Failed: error 197 at offset 131075: too many capturing groups (maximum 65535) MK: XX /(*:\)?/ -Failed: error 109 at offset 5: quantifier does not follow a repeatable item +Failed: error 109 at offset 6: quantifier does not follow a repeatable item + here: (*:\)? |<--| /(*:\Q \E){5}/alt_verbnames -Failed: error 109 at offset 11: quantifier does not follow a repeatable item +Failed: error 109 at offset 12: quantifier does not follow a repeatable item + here: ...:\Q \E){5} |<--| /(?=abc)/I Capture group count = 0 @@ -17725,16 +18469,39 @@ Subject length lower bound = 0 # Addition overflow /( {32742} {42})(?| (?| (?<=\1{327... # ---- Non-atomic assertion tests ---- +/(*ploo:abc)/ +Failed: error 195 at offset 6: (*alpha_assertion) not recognized + here: (*ploo |<--| :abc) + +/(*pla:abc/ +Failed: error 114 at offset 9: missing closing parenthesis + here: (*pla:abc |<--| + +/(*pla:/ +Failed: error 114 at offset 6: missing closing parenthesis + here: (*pla: |<--| + +/(*pla/ +Failed: error 114 at offset 5: missing closing parenthesis + here: (*pla |<--| + +/(*pla}abc)/ +Failed: error 195 at offset 6: (*alpha_assertion) not recognized + here: (*pla} |<--| abc) + # Expect error: not allowed as a condition /(?(*napla:xx)bc)/ Failed: error 128 at offset 9: atomic assertion expected after (?( or (?(?C) + here: (?(*napla |<--| :xx)bc) /\A(*pla:.*\b(\w++))(?>.*?\b\1\b){3}/ word1 word3 word1 word2 word3 word2 word2 word1 word3 word4 @@ -17797,7 +18564,7 @@ No match ------------------------------------------------------------------ Bra Non-atomic assert back - Reverse + 2 Reverse ab Ket Ket @@ -17881,6 +18648,7 @@ No match # Expect error (recursion => not fixed length) /(\2)((?=(?<=\1)))/ Failed: error 125 at offset 8: length of lookbehind assertion is not limited + here: (\2)((?= |-->| (?<=\1))) /c*+(?<=[bc])/ abc\=ph @@ -17971,7 +18739,7 @@ Subject length lower bound = 1 Ket CBra 2 Assert back - Reverse + 1 Reverse b Ket Any*+ @@ -17989,7 +18757,7 @@ Subject length lower bound = 1 Ket CBra 1 Assert back - Reverse + 1 Reverse b Ket Any*+ @@ -18002,12 +18770,12 @@ Subject length lower bound = 1 ------------------------------------------------------------------ Bra Cond - Cond recurse 1 + Cond rec 1 b Ket CBra 1 Assert back - Reverse + 1 Reverse b Ket Any*+ @@ -18025,7 +18793,7 @@ Subject length lower bound = 1 Ket CBra 1 Assert back - Reverse + 1 Reverse b Ket Any*+ @@ -18043,7 +18811,25 @@ Subject length lower bound = 1 Ket CBra 1 Assert back - Reverse + 1 Reverse + b + Ket + Any*+ + Ket + Ket + End +------------------------------------------------------------------ + +/(?(VERSION>=10.3)b)((?<=b).*)/B +------------------------------------------------------------------ + Bra + Cond + Cond true + b + Ket + CBra 1 + Assert back + 1 Reverse b Ket Any*+ @@ -18177,6 +18963,7 @@ Callout 0: last capture = 2 \= Expect error xyzabcdxyzabcdxyz\=ovector=1 Failed: error -54 at offset 3 in replacement: requested value is not available + here: >$1 |<--| < /a(..)d/g,replace=>$1<,substitute_matched xyzabcdxyzabcdxyz @@ -18186,8 +18973,10 @@ Failed: error -54 at offset 3 in replacement: requested value is not available \= Expect error xyzabcdxyzabcdxyz\=ovector=1 Failed: error -54 at offset 3 in replacement: requested value is not available + here: >$1 |<--| < xyzabcdxyzabcdxyz\=ovector=1,substitute_unset_empty Failed: error -54 at offset 3 in replacement: requested value is not available + here: >$1 |<--| < /55|a(..)d/g,replace=>$1<,substitute_matched xyz55abcdxyzabcdxyz\=ovector=2,substitute_unset_empty @@ -18195,6 +18984,7 @@ Failed: error -54 at offset 3 in replacement: requested value is not available \= Expect error xyz55abcdxyzabcdxyz\=ovector=2 Failed: error -55 at offset 3 in replacement: requested value is not set + here: >$1 |<--| < /55|a(..)d/replace=>$1<,substitute_matched xyz55abcdxyzabcdxyz\=ovector=2,substitute_unset_empty @@ -18210,9 +19000,9 @@ Failed: error -55 at offset 3 in replacement: requested value is not set /abc/replace=,caseless XabcY - 0: abc + 1: XY XABCY - 0: ABC + 1: XY /abc/replace=[4],caseless XabcY @@ -18226,7 +19016,7 @@ Failed: error -55 at offset 3 in replacement: requested value is not set XABCY 1: X*Y XabcY\=replace= - 0: abc + 1: XY /abc/replace=\U$0,substitute_extended,substitute_case_callout XabcY @@ -18249,6 +19039,9 @@ Failed: error -55 at offset 3 in replacement: requested value is not set "(?<=X(?(DEFINE)(.*))(?1))." Failed: error 125 at offset 0: length of lookbehind assertion is not limited + here: |-->| (?<=X(?(DE... + +#if !ebcdic /\sxxx\s/tables=1 \= Expect no match @@ -18273,6 +19066,8 @@ No match École 0: \xc3 +#endif + /"(*MARK:>" 00 "<).."/hex,mark,no_start_optimize AB 0: AB @@ -18293,12 +19088,14 @@ MK: >\x00< /(?(VERSION=0.0/ Failed: error 179 at offset 14: syntax error or number too big in (?(VERSION condition + here: ...ERSION=0.0 |<--| # Perl has made \K in lookarounds an error. PCRE2 now rejects as well, unless # explicitly authorized. /(?=a\Kb)ab/ Failed: error 199 at offset 10: \K is not allowed in lookarounds (but see PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) + here: (?=a\Kb)ab |<-->| /(?=a\Kb)ab/allow_lookaround_bsk ab @@ -18306,6 +19103,7 @@ Failed: error 199 at offset 10: \K is not allowed in lookarounds (but see PCRE2_ /(?!a\Kb)ac/ Failed: error 199 at offset 10: \K is not allowed in lookarounds (but see PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) + here: (?!a\Kb)ac |<-->| /(?!a\Kb)ac/allow_lookaround_bsk ac @@ -18313,6 +19111,7 @@ Failed: error 199 at offset 10: \K is not allowed in lookarounds (but see PCRE2_ /^abc(?<=b\Kc)d/ Failed: error 199 at offset 14: \K is not allowed in lookarounds (but see PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) + here: ...(?<=b\Kc)d |<-->| /^abc(?<=b\Kc)d/allow_lookaround_bsk abcd @@ -18320,11 +19119,62 @@ Failed: error 199 at offset 14: \K is not allowed in lookarounds (but see PCRE2_ /^abc(?| /^abc(?b\K))a(?=(?&sneaky))/g,allow_lookaround_bsk + ab +Start of matched string is beyond its end - displaying from end to start. + 0: b + +/(?(DEFINE)(?b\K))a(?=(?&sneaky))/g + ab +Failed: error -75: disallowed use of \K in lookaround + zz +No match + +/a|(?(DEFINE)(?\Ka))(?<=(?&sneaky))b/g,allow_lookaround_bsk + ab + 0: a + 0: ab + +/a|(?(DEFINE)(?\Ka))(?<=(?&sneaky))b/g + ab + 0: a +Failed: error -75: disallowed use of \K in lookaround + zz +No match + +/a|(?(DEFINE)(?\K\Ga))(?<=(?&sneaky))b/g + ab + 0: a + zz +No match + +/(?=.{10}(?1))x(\K){0}/ + x1234567890 +Failed: error -75: disallowed use of \K in lookaround + +/(?=.{10}(.))(*scs:(1)(?2))x(\K){0}/ + x1234567890 +Failed: error -75: disallowed use of \K in lookaround + +/(?=.{5}(?1))\d*(\K){0}/ +\= Totally fine - pattern does nothing bad even though \K is reachable + 1234567890 + 0: 67890 +\= Not fine - the subject now causes the \K to misbehave + abcdefgh +Failed: error -75: disallowed use of \K in lookaround + # --------- # Tests for zero-length NULL to be treated as an empty string. @@ -18344,6 +19194,10 @@ Failed: error -51: NULL argument passed with non-zero length \=null_replacement 1: +/abc/replace= + XabcY\=null_replacement + 1: XY + /X*/g,replace=xy \= Expect error >X<\=null_replacement @@ -18438,6 +19292,7 @@ Failed: error 116 at offset 0: pattern passed as NULL with non-zero length # -------- Variable length lookbehinds -------- /12345(?<=\d{1,256})X/ Failed: error 200 at offset 5: branch too long in variable-length lookbehind assertion + here: 12345 |-->| (?<=\d{1,2... /(?<=(\d{1,256}))X/max_varlookbehind=256 12345XYZ @@ -18446,11 +19301,13 @@ Failed: error 200 at offset 5: branch too long in variable-length lookbehind ass /12345(?<=a?bc)X/max_varlookbehind=0 Failed: error 200 at offset 5: branch too long in variable-length lookbehind assertion + here: 12345 |-->| (?<=a?bc)X /12345(?<=abc)X/max_varlookbehind=0 /(?| (?| (?| 1)a|b) /(*scs:(0)a)/ Failed: error 115 at offset 8: reference to non-existent subpattern + here: (*scs:(0 |<-->| )a) /(*scan_substring:(1)a|b)/ Failed: error 115 at offset 18: reference to non-existent subpattern + here: ...ubstring:( |<-->| 1)a|b) /(*scs:()a|b)/ Failed: error 115 at offset 8: reference to non-existent subpattern + here: (*scs:(< |<-->| name>)a|b) /(*scan_substring:()a|b)/ Failed: error 115 at offset 19: reference to non-existent subpattern + here: ...bstring:(< |<-->| name>)a|b) /()(*scs:(1)+a)/ -Failed: error 109 at offset 11: quantifier does not follow a repeatable item +Failed: error 109 at offset 12: quantifier does not follow a repeatable item + here: ...(*scs:(1)+ |<--| a) /()(*scs:(1,1,1,1,1,1,1,1,2))/ Failed: error 115 at offset 25: reference to non-existent subpattern + here: ...1,1,1,1,1, |<-->| 2)) /()()(*scs:(1,2,1,2,1,2,2,'XYZ'))/ Failed: error 115 at offset 26: reference to non-existent subpattern + here: ...,2,1,2,2,' |<-->| XYZ')) # Tests for iterating scan_substring @@ -19060,6 +19930,7 @@ Failed: error 115 at offset 26: reference to non-existent subpattern /(\w++)=(?(*scs:(1)(abc))pqr|xyz)(\w++)/ Failed: error 128 at offset 14: atomic assertion expected after (?( or (?(?C) + here: ...+)=(?(*scs |<--| :(1)(abc))... # Tests for scan_substring @@ -19116,7 +19987,7 @@ No match Ket $ Ket - \2 + \g{2} Ket End ------------------------------------------------------------------ @@ -19570,7 +20441,7 @@ No match mno Ket Scan substring - Capture ref 2 + Capture dnref2 3 Capture ref 4 Capture ref Any @@ -19629,9 +20500,6 @@ No match a Ket Scan substring - 1 Capture ref - 1 Capture ref - 1 Capture ref 1 Capture ref a Ket @@ -19676,6 +20544,116 @@ No match 2: b 3: b +# Duplicated capture references + +/(a)(b)(c)(d)(*scs:(4,3,1,2,2,1,3,3,4,4)x)/B +------------------------------------------------------------------ + Bra + CBra 1 + a + Ket + CBra 2 + b + Ket + CBra 3 + c + Ket + CBra 4 + d + Ket + Scan substring + 4 Capture ref + 3 Capture ref + 1 Capture ref + 2 Capture ref + x + Ket + Ket + End +------------------------------------------------------------------ + +/(?a)(?b)(?c)(d)(*scs:(2,3,1,1,,)abc)/B,dupnames +------------------------------------------------------------------ + Bra + CBra 1 + a + Ket + CBra 2 + b + Ket + CBra 3 + c + Ket + CBra 4 + d + Ket + Scan substring + 2 Capture ref + 3 Capture ref + 1 Capture ref + abc + Ket + Ket + End +------------------------------------------------------------------ + +/(?a)(?b)(?c)(d)(*scs:(2,1,1,,)abc)/B,dupnames +------------------------------------------------------------------ + Bra + CBra 1 + a + Ket + CBra 2 + b + Ket + CBra 3 + c + Ket + CBra 4 + d + Ket + Scan substring + 2 Capture ref + 1 Capture ref + Capture dnref3 + abc + Ket + Ket + End +------------------------------------------------------------------ + +/(?a)(?b)(?c)(d)(?e)(?f)(*scs:(,5,3,2,1,4,1,4,,6,,)abc)/B,dupnames +------------------------------------------------------------------ + Bra + CBra 1 + a + Ket + CBra 2 + b + Ket + CBra 3 + c + Ket + CBra 4 + d + Ket + CBra 5 + e + Ket + CBra 6 + f + Ket + Scan substring + Capture dnref3 + 5 Capture ref + 4 Capture ref + Capture dnref2 + abc + Ket + Ket + End +------------------------------------------------------------------ + # Tests for pcre2_set_optimize() /abc/I,optimization_none @@ -19732,14 +20710,17 @@ Optimizations: auto_possess,dotstar_anchor # larger than GROUP_MAX, smaller than INT_MAX /a\800000b/ Failed: error 161 at offset 8: subpattern number is too big + here: a\800000 |<--| b # coming up on INT_MAX... (used to succeed with \8 being literal 8) /a\800000000b/ Failed: error 161 at offset 11: subpattern number is too big + here: ...\800000000 |<--| b # over INT_MAX (used to succeed with \8 being literal 8) /a\8000000000b/ Failed: error 161 at offset 12: subpattern number is too big + here: ...8000000000 |<--| b # -------------- @@ -19751,6 +20732,7 @@ Failed: error 161 at offset 12: subpattern number is too big /a\0b/no_bs0 Failed: error 198 at offset 3: octal digit missing after \0 (PCRE2_EXTRA_NO_BS0 is set) + here: a\0 |<--| b /b\x00c\00d/no_bs0 b\x{00}c\x{00}d @@ -19763,17 +20745,21 @@ Failed: error 198 at offset 3: octal digit missing after \0 (PCRE2_EXTRA_NO_BS0 /abc/substitute_extended,no_bs0 abc\=replace=a\0b Failed: error -57 at offset 3 in replacement: bad escape sequence in replacement string + here: a\0 |<--| b abc\=replace=b\x00c\00d 1: b\x00c\x00d # python_octal +#if !ebcdic + /\0-\00-\01-\012-\0123-\123-\1234/ \x00-\x00-\x01-\o{12}-\o{12}3-\o{123}-\o{123}4 0: \x00-\x00-\x01-\x0a-\x0a3-S-S4 /\1/ -Failed: error 115 at offset 1: reference to non-existent subpattern +Failed: error 115 at offset 2: reference to non-existent subpattern + here: \1 |<-->| /\12/ \o{12} @@ -19784,6 +20770,7 @@ Failed: error 115 at offset 1: reference to non-existent subpattern 1: \x00-\x00-\x01-\x0a-\x0a3-S-S4 abc\=replace=\1 Failed: error -49 at offset 2 in replacement: unknown substring + here: \1 |<--| abc\=replace=\12 1: \x0a @@ -19792,18 +20779,24 @@ Failed: error -49 at offset 2 in replacement: unknown substring 0: \x00-\x00-\x01-\x0a-\x0a3-S-S4 /\1/python_octal -Failed: error 115 at offset 1: reference to non-existent subpattern +Failed: error 115 at offset 2: reference to non-existent subpattern + here: \1 |<-->| /\12/python_octal -Failed: error 115 at offset 2: reference to non-existent subpattern +Failed: error 115 at offset 3: reference to non-existent subpattern + here: \12 |<-->| /abc/substitute_extended,python_octal abc\=replace=\0-\00-\01-\012-\0123-\123-\1234 1: \x00-\x00-\x01-\x0a-\x0a3-S-S4 abc\=replace=\1 Failed: error -49 at offset 2 in replacement: unknown substring + here: \1 |<--| abc\=replace=\12 Failed: error -49 at offset 3 in replacement: unknown substring + here: \12 |<--| + +#endif # -------------- @@ -19816,7 +20809,8 @@ Failed: error -49 at offset 3 in replacement: unknown substring 0: ab /a(?C)b/never_callout -Failed: error 203 at offset 3: using callouts is disabled by the application +Failed: error 203 at offset 4: using callouts is disabled by the application + here: a(?C |<--| )b # -------------- @@ -19828,9 +20822,11 @@ Failed: error 203 at offset 3: using callouts is disabled by the application /[a[]/alt_extended_class Failed: error 106 at offset 4: missing terminating ] for character class + here: [a[] |<--| /[a[B]/alt_extended_class Failed: error 212 at offset 5: missing terminating ] for extended character class (note '[' must be escaped under PCRE2_ALT_EXTENDED_CLASS) + here: [a[B] |<--| /[a[B]]C/B,alt_extended_class ------------------------------------------------------------------ @@ -20444,7 +21440,7 @@ No match CBra 1 [a-mo-z] Ket - \1 + \g{1} Ket End ------------------------------------------------------------------ @@ -20468,7 +21464,7 @@ No match [a-mo-z] y Ket - \1 + \g{1} Ket End ------------------------------------------------------------------ @@ -20487,7 +21483,7 @@ No match Bra Bra _ - \1 + \g{1} Alt CBra 1 [a-mo-z] @@ -20495,7 +21491,7 @@ No match Ket Bra _ - \1 + \g{1} Alt CBra 1 [a-mo-z] @@ -20521,7 +21517,7 @@ No match Bra Bra _ - \1 + \g{1} Alt CBra 1 [a-mo-z] @@ -20629,75 +21625,99 @@ No match /[a--/alt_extended_class Failed: error 106 at offset 4: missing terminating ] for character class + here: [a-- |<--| /[a--a/alt_extended_class Failed: error 106 at offset 5: missing terminating ] for character class + here: [a--a |<--| /[a--[a/alt_extended_class Failed: error 106 at offset 6: missing terminating ] for character class + here: [a--[a |<--| /[a--[a]/alt_extended_class Failed: error 212 at offset 7: missing terminating ] for extended character class (note '[' must be escaped under PCRE2_ALT_EXTENDED_CLASS) + here: [a--[a] |<--| /[a--[a]--/alt_extended_class Failed: error 212 at offset 9: missing terminating ] for extended character class (note '[' must be escaped under PCRE2_ALT_EXTENDED_CLASS) + here: [a--[a]-- |<--| /[a--]/alt_extended_class Failed: error 210 at offset 5: expected operand after operator in extended character class + here: [a--] |<--| /[--a]/alt_extended_class Failed: error 209 at offset 3: unexpected operator in extended character class (no preceding operand) + here: [-- |<--| a] /[^--a]/alt_extended_class Failed: error 209 at offset 4: unexpected operator in extended character class (no preceding operand) + here: [^-- |<--| a] /[--]/alt_extended_class Failed: error 209 at offset 3: unexpected operator in extended character class (no preceding operand) + here: [-- |<--| ] /[a---b]/alt_extended_class Failed: error 208 at offset 5: invalid operator in extended character class + here: [a--- |<--| b] /[a----b]/alt_extended_class Failed: error 208 at offset 6: invalid operator in extended character class + here: [a---- |<--| b] /[a&&&b]/alt_extended_class Failed: error 208 at offset 5: invalid operator in extended character class + here: [a&&& |<--| b] /[a|||b]/alt_extended_class Failed: error 208 at offset 5: invalid operator in extended character class + here: [a||| |<--| b] /[a~~~b]/alt_extended_class Failed: error 208 at offset 5: invalid operator in extended character class + here: [a~~~ |<--| b] /[a~~~~b]/alt_extended_class Failed: error 208 at offset 6: invalid operator in extended character class + here: [a~~~~ |<--| b] /[a~~/alt_extended_class Failed: error 106 at offset 4: missing terminating ] for character class + here: [a~~ |<--| /[a~~~/alt_extended_class Failed: error 208 at offset 5: invalid operator in extended character class + here: [a~~~ |<--| /[a~~~~/alt_extended_class Failed: error 208 at offset 6: invalid operator in extended character class + here: [a~~~~ |<--| /[a||b&&c]/alt_extended_class Failed: error 211 at offset 7: square brackets needed to clarify operator precedence in extended character class + here: [a||b&& |<--| c] /[a||b~~c]/alt_extended_class Failed: error 211 at offset 7: square brackets needed to clarify operator precedence in extended character class + here: [a||b~~ |<--| c] /[a~~b&&c]/alt_extended_class Failed: error 211 at offset 7: square brackets needed to clarify operator precedence in extended character class + here: [a~~b&& |<--| c] /[a--b~~c]/alt_extended_class Failed: error 211 at offset 7: square brackets needed to clarify operator precedence in extended character class + here: [a--b~~ |<--| c] /[a--b&&c]/alt_extended_class Failed: error 211 at offset 7: square brackets needed to clarify operator precedence in extended character class + here: [a--b&& |<--| c] /[a||b--c]/alt_extended_class Failed: error 211 at offset 7: square brackets needed to clarify operator precedence in extended character class + here: [a||b-- |<--| c] /[a||[b--c]]/alt_extended_class a @@ -20710,9 +21730,11 @@ No match /[\d-z]/B,alt_extended_class Failed: error 150 at offset 4: invalid range in character class + here: [\d- |<--| z] /[z-\d]/B,alt_extended_class Failed: error 150 at offset 5: invalid range in character class + here: [z-\d |<--| ] /[abc -- b]+/B,alt_extended_class ------------------------------------------------------------------ @@ -20732,13 +21754,16 @@ Failed: error 150 at offset 5: invalid range in character class No match /[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[z]&&a]]]]]]]]]]]]]]]/alt_extended_class -Failed: error 207 at offset 115: extended character class nesting is too deep +Failed: error 207 at offset 114: extended character class nesting is too deep + here: ...[a[b]&&a[a |-->| [z]&&a]]]]... /[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a[b]&&a[a&&a[z]]]]]]]]]]]]]]]]/alt_extended_class -Failed: error 207 at offset 118: extended character class nesting is too deep +Failed: error 207 at offset 117: extended character class nesting is too deep + here: ...b]&&a[a&&a |-->| [z]]]]]]]]... /[z&/alt_extended_class Failed: error 106 at offset 3: missing terminating ] for character class + here: [z& |<--| /[[^]~~[^]]/B,alt_extended_class,allow_empty_class ------------------------------------------------------------------ @@ -20778,16 +21803,20 @@ No match # bad-escape-is-literal does nothing inside (?[...]) /[ \j ]/ -Failed: error 103 at offset 3: unrecognized character follows \ +Failed: error 103 at offset 4: unrecognized character follows \ + here: [ \j |<--| ] /[ /\ Failed: error 101 at offset 3: \ at end of pattern + here: [ \ |<--| /(?[ \j ])/ -Failed: error 103 at offset 5: unrecognized character follows \ +Failed: error 103 at offset 6: unrecognized character follows \ + here: (?[ \j |<--| ]) /(?[ /\ Failed: error 101 at offset 5: \ at end of pattern + here: (?[ \ |<--| /[ \j ]/bad_escape_is_literal j @@ -20798,116 +21827,153 @@ No match /[ /\bad_escape_is_literal Failed: error 106 at offset 3: missing terminating ] for character class + here: [ \ |<--| /(?[ \j ])/bad_escape_is_literal -Failed: error 103 at offset 5: unrecognized character follows \ +Failed: error 103 at offset 6: unrecognized character follows \ + here: (?[ \j |<--| ]) /(?[ /\bad_escape_is_literal Failed: error 101 at offset 5: \ at end of pattern + here: (?[ \ |<--| /(?[ [\j] ])/bad_escape_is_literal -Failed: error 103 at offset 6: unrecognized character follows \ +Failed: error 103 at offset 7: unrecognized character follows \ + here: (?[ [\j |<--| ] ]) /(?[ (\j) ])/bad_escape_is_literal -Failed: error 103 at offset 6: unrecognized character follows \ +Failed: error 103 at offset 7: unrecognized character follows \ + here: (?[ (\j |<--| ) ]) # We can't test error cases in testinput1 /(?[])/ Failed: error 214 at offset 4: empty expression in extended character class + here: (?[] |<--| ) /(?[/ Failed: error 106 at offset 3: missing terminating ] for character class + here: (?[ |<--| /(?[]/ Failed: error 214 at offset 4: empty expression in extended character class + here: (?[] |<--| /(?[\n/ Failed: error 106 at offset 5: missing terminating ] for character class + here: (?[\n |<--| /(?[\n]/ Failed: error 215 at offset 6: terminating ] with no following closing parenthesis in (?[...] + here: (?[\n] |<--| /(?[\n]z)/ Failed: error 215 at offset 6: terminating ] with no following closing parenthesis in (?[...] + here: (?[\n] |<--| z) /(?[\n] )/ Failed: error 215 at offset 6: terminating ] with no following closing parenthesis in (?[...] + here: (?[\n] |<--| ) /(?[(/ Failed: error 114 at offset 4: missing closing parenthesis + here: (?[( |<--| /(?[( / Failed: error 106 at offset 5: missing terminating ] for character class + here: (?[( |<--| /(?[(\n/ Failed: error 106 at offset 6: missing terminating ] for character class + here: (?[(\n |<--| /(?[ \n + () ])/ Failed: error 214 at offset 11: empty expression in extended character class + here: ...?[ \n + () |<--| ]) /(?[1])/ Failed: error 216 at offset 4: unexpected character in (?[...]) extended character class + here: (?[1 |<--| ]) /(?[a])/ Failed: error 216 at offset 4: unexpected character in (?[...]) extended character class + here: (?[a |<--| ]) /(?[a-c])/ Failed: error 216 at offset 4: unexpected character in (?[...]) extended character class + here: (?[a |<--| -c]) /(?[(])/ Failed: error 114 at offset 4: missing closing parenthesis + here: (?[( |<--| ]) /(?[(\n])/ Failed: error 114 at offset 6: missing closing parenthesis + here: (?[(\n |<--| ]) /(?[\n)])/ Failed: error 122 at offset 6: unmatched closing parenthesis + here: (?[\n) |<--| ]) /(?[^\n])/ Failed: error 209 at offset 4: unexpected operator in extended character class (no preceding operand) + here: (?[^ |<--| \n]) /(?[ \n \t ])/ Failed: error 213 at offset 9: unexpected expression in extended character class (no preceding operator) + here: (?[ \n \t |<--| ]) /(?[ \d \t ])/ Failed: error 213 at offset 9: unexpected expression in extended character class (no preceding operator) + here: (?[ \d \t |<--| ]) /(?[ [\n] \t ])/ Failed: error 213 at offset 11: unexpected expression in extended character class (no preceding operator) + here: ...?[ [\n] \t |<--| ]) /(?[ (\n) \t ])/ Failed: error 213 at offset 11: unexpected expression in extended character class (no preceding operator) + here: ...?[ (\n) \t |<--| ]) /(?[ [:alpha:] \t ])/ Failed: error 213 at offset 16: unexpected expression in extended character class (no preceding operator) + here: ...alpha:] \t |<--| ]) /(?[ \n + \t \d ])/ Failed: error 213 at offset 14: unexpected expression in extended character class (no preceding operator) + here: ...\n + \t \d |<--| ]) /(?[ !\n \t ])/ Failed: error 213 at offset 10: unexpected expression in extended character class (no preceding operator) + here: (?[ !\n \t |<--| ]) /(?[ \n [:alpha:] ])/ Failed: error 213 at offset 16: unexpected expression in extended character class (no preceding operator) + here: ... [:alpha:] |<--| ]) /(?[ \n [\d] ])/ Failed: error 213 at offset 8: unexpected expression in extended character class (no preceding operator) + here: (?[ \n [ |<--| \d] ]) /(?[ \n (\t) ])/ Failed: error 213 at offset 8: unexpected expression in extended character class (no preceding operator) + here: (?[ \n ( |<--| \t) ]) /(?[ \n !\t ])/ Failed: error 213 at offset 8: unexpected expression in extended character class (no preceding operator) + here: (?[ \n ! |<--| \t ]) /(?[ \n \t ])/ Failed: error 213 at offset 9: unexpected expression in extended character class (no preceding operator) + here: (?[ \n \t |<--| ]) /(?[:graph:])/ Failed: error 216 at offset 4: unexpected character in (?[...]) extended character class + here: (?[: |<--| graph:]) /(?[\Qn\E])/ Failed: error 216 at offset 6: unexpected character in (?[...]) extended character class + here: (?[\Qn |<--| \E]) # maximum depth tests @@ -20921,66 +21987,86 @@ No match No match /(?[\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+([\n]&\n))))))))))))))])/ -Failed: error 207 at offset 158: extended character class nesting is too deep +Failed: error 207 at offset 157: extended character class nesting is too deep + here: ...n+[a]&\n+( |-->| [\n]&\n)))... /(?[\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n&[\n]))))))))))))))])/ -Failed: error 207 at offset 161: extended character class nesting is too deep +Failed: error 207 at offset 160: extended character class nesting is too deep + here: ...a]&\n+(\n& |-->| [\n]))))))... /(?[\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+(\n+[a]&\n+((\n)&\n))))))))))))))])/ -Failed: error 207 at offset 158: extended character class nesting is too deep +Failed: error 207 at offset 157: extended character class nesting is too deep + here: ...n+[a]&\n+( |-->| (\n)&\n)))... # -------------- /[[:digit:] -Z]/xx Failed: error 150 at offset 14: invalid range in character class + here: ...igit:] - |<--| Z] /[\d -Z]/xx Failed: error 150 at offset 7: invalid range in character class + here: [\d - |<--| Z] /[[:digit:]\E-H]/ Failed: error 150 at offset 13: invalid range in character class + here: ...digit:]\E- |<--| H] /[[:digit:]\Q\E-H]+/ Failed: error 150 at offset 15: invalid range in character class + here: ...git:]\Q\E- |<--| H]+ /[z-[:space:]]/ Failed: error 150 at offset 12: invalid range in character class + here: ...-[:space:] |<--| ] /[z-\d]/ Failed: error 150 at offset 5: invalid range in character class + here: [z-\d |<--| ] /[[:space:]-z]/ Failed: error 150 at offset 11: invalid range in character class + here: ...[:space:]- |<--| z] /[\d-z]/ Failed: error 150 at offset 4: invalid range in character class + here: [\d- |<--| z] /[\d-\w]/ Failed: error 150 at offset 4: invalid range in character class + here: [\d- |<--| \w] /[\Q/ Failed: error 106 at offset 3: missing terminating ] for character class + here: [\Q |<--| /[\Q/\ Failed: error 106 at offset 4: missing terminating ] for character class + here: [\Q\ |<--| /[\Q\E/ Failed: error 106 at offset 5: missing terminating ] for character class + here: [\Q\E |<--| /[\Q\n/ Failed: error 106 at offset 5: missing terminating ] for character class + here: [\Q\n |<--| /[\Q\n]/ Failed: error 106 at offset 6: missing terminating ] for character class + here: [\Q\n] |<--| /[\Q\n/\ Failed: error 106 at offset 6: missing terminating ] for character class + here: [\Q\n\ |<--| /[\Q\n\]/ Failed: error 106 at offset 7: missing terminating ] for character class + here: [\Q\n\] |<--| /[\Q\n\E/ Failed: error 106 at offset 7: missing terminating ] for character class + here: [\Q\n\E |<--| /[\Q\n\E]/ \\ @@ -20995,21 +22081,27 @@ No match /[z\Q/ Failed: error 106 at offset 4: missing terminating ] for character class + here: [z\Q |<--| /[z\Q/\ Failed: error 106 at offset 5: missing terminating ] for character class + here: [z\Q\ |<--| /[z\Q\E/ Failed: error 106 at offset 6: missing terminating ] for character class + here: [z\Q\E |<--| /[/\ Failed: error 101 at offset 2: \ at end of pattern + here: [\ |<--| /[\n/ Failed: error 106 at offset 3: missing terminating ] for character class + here: [\n |<--| /[\E/ Failed: error 106 at offset 3: missing terminating ] for character class + here: [\E |<--| /[\^z]/B ------------------------------------------------------------------ @@ -21035,6 +22127,8 @@ Failed: error 106 at offset 3: missing terminating ] for character class End ------------------------------------------------------------------ +#if !ebcdic + /[0-z]/B ------------------------------------------------------------------ Bra @@ -21043,6 +22137,8 @@ Failed: error 106 at offset 3: missing terminating ] for character class End ------------------------------------------------------------------ +#endif + /[0\-z]/B ------------------------------------------------------------------ Bra @@ -21067,6 +22163,8 @@ Failed: error 106 at offset 3: missing terminating ] for character class End ------------------------------------------------------------------ +#if !ebcdic + /[ --]/B ------------------------------------------------------------------ Bra @@ -21091,20 +22189,27 @@ Failed: error 106 at offset 3: missing terminating ] for character class End ------------------------------------------------------------------ +#endif + /[\A]/ -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\A |<--| ] /[\Z]/ -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\Z |<--| ] /[\z]/ -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\z |<--| ] /[\G]/ -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\G |<--| ] /[\K]/ -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\K |<--| ] /[\g<1>]/ < @@ -21139,6 +22244,8 @@ No match \\ No match +#if !ebcdic + /[a\x{e1}]/iB ------------------------------------------------------------------ Bra @@ -21153,6 +22260,8 @@ No match \x{e1} 0: \xe1 +#endif + # -------------- # Attempt at full coverage of the substitution buffer-management code - not @@ -21253,6 +22362,8 @@ Failed: error -48: no more memory XacY\=substitute_overflow_length,replace=[2]$1 Failed: error -48: no more memory: 3 code units are needed +#if !ebcdic + # a data character via an escape /abc/substitute_extended XabcY\=replace=\x{48} @@ -21264,6 +22375,8 @@ Failed: error -48: no more memory: 4 code units are needed XXabcY\=substitute_overflow_length,replace=[1]\x{48} Failed: error -48: no more memory: 5 code units are needed +#endif + # a replacement literal character /abc/ XabcY\=replace=Z @@ -21360,6 +22473,8 @@ Failed: error -48: no more memory XacY\=substitute_overflow_length,replace=[2]\U$1 Failed: error -48: no more memory: 3 code units are needed +#if !ebcdic + # a data character via an escape /abc/substitute_extended XabcY\=replace=\U\x{48} @@ -21373,6 +22488,8 @@ Failed: error -48: no more memory: 5 code units are needed XabcY\=substitute_case_callout,replace=\U\x{48} 1: XHY +#endif + # a replacement literal character /abc/substitute_extended XabcY\=replace=\UZ @@ -21830,6 +22947,573 @@ Failed: error -69: error performing replacement case transformation # -------------- +# Tests for recurse with returned captures + +# Parse error tests + +/(?1/ +Failed: error 114 at offset 3: missing closing parenthesis + here: (?1 |<--| + +/(?1(/ +Failed: error 217 at offset 4: expected capture group number or name + here: (?1( |<--| + +/(?R(1/ +Failed: error 114 at offset 5: missing closing parenthesis + here: (?R(1 |<--| + +/(?R(1,/ +Failed: error 217 at offset 6: expected capture group number or name + here: (?R(1, |<--| + +/(?R0(1,2!/ +Failed: error 158 at offset 3: (?R (recursive pattern call) must be followed by a closing parenthesis + here: (?R |<--| 0(1,2! + +/(?1(1,0))()/ +Failed: error 115 at offset 7: reference to non-existent subpattern + here: (?1(1,0 |<-->| ))() + +/(?1(1,+2))()/ +Failed: error 115 at offset 6: reference to non-existent subpattern + here: (?1(1, |<-->| +2))() + +/(?1())/ +Failed: error 115 at offset 3: reference to non-existent subpattern + here: (?1 |<-->| ()) + +# Operation tests + +/^(?1(2))\2(?(DEFINE)(a(.)b(.)c))/B +------------------------------------------------------------------ + Bra + ^ + Recurse + 2 Capture ref + \g{2} + Cond + Cond false + CBra 1 + a + CBra 2 + Any + Ket + b + CBra 3 + Any + Ket + c + Ket + Ket + Ket + End +------------------------------------------------------------------ + axbycx + 0: axbycx + 1: + 2: x +\= Expect no match + axby +No match + axbycy +No match + +/^((.)(?.))(?1('id'))(.)/B +------------------------------------------------------------------ + Bra + ^ + CBra 1 + CBra 2 + Any + Ket + CBra 3 + Any + Ket + Ket + Recurse + 3 Capture ref + CBra 4 + Any + Ket + Ket + End +------------------------------------------------------------------ + abcde + 0: abcde + 1: ab + 2: a + 3: d + 4: e + +/^(?1(3,2,2,3,2))(?1(3))(?(DEFINE)(a(.)b(.)c))/B +------------------------------------------------------------------ + Bra + ^ + Recurse + 2 Capture ref + 3 Capture ref + Recurse + 3 Capture ref + Cond + Cond false + CBra 1 + a + CBra 2 + Any + Ket + b + CBra 3 + Any + Ket + c + Ket + Ket + Ket + End +------------------------------------------------------------------ + a1b2cafbgc + 0: a1b2cafbgc + 1: + 2: 1 + 3: g + +/(?1(2))#(?1(3))#(?1(4))#(?(DEFINE)((.)\2(.)\3(.)\4))/ + aabbcc#ddeeff#gghhii!aabbcc#ddeeff#gghhii# + 0: aabbcc#ddeeff#gghhii# + 1: + 2: a + 3: e + 4: i +\= Expect no match + aabbcc#ddeeff#gghhii +No match + +/^(?1(1,2)){2,4}(?(DEFINE)((..)#))xx#/B +------------------------------------------------------------------ + Bra + ^ + Recurse + 1 Capture ref + 2 Capture ref + Recurse + 1 Capture ref + 2 Capture ref + Brazero + Bra + Bra + Recurse + 1 Capture ref + 2 Capture ref + Ket + Brazero + Bra + Recurse + 1 Capture ref + 2 Capture ref + Ket + Ket + Cond + Cond false + CBra 1 + CBra 2 + Any + Any + Ket + # + Ket + Ket + xx# + Ket + End +------------------------------------------------------------------ + aa#bb#xx# + 0: aa#bb#xx# + 1: + 2: bb + aa#bb#cc#xx# + 0: aa#bb#cc#xx# + 1: + 2: cc + aa#bb#cc#dd#xx# + 0: aa#bb#cc#dd#xx# + 1: + 2: dd +\= Expect no match + aa#xx# +No match + aa#bb#cc#dd#ee#xx# +No match + +/^(?1(1,2)){2,}+(?(DEFINE)((..)#))!/B +------------------------------------------------------------------ + Bra + ^ + Recurse + 1 Capture ref + 2 Capture ref + Recurse + 1 Capture ref + 2 Capture ref + Braposzero + SBraPos + Recurse + 1 Capture ref + 2 Capture ref + KetRpos + Cond + Cond false + CBra 1 + CBra 2 + Any + Any + Ket + # + Ket + Ket + ! + Ket + End +------------------------------------------------------------------ + aa#bb#! + 0: aa#bb#! + 1: + 2: bb + aa#bb#cc#dd#ee#! + 0: aa#bb#cc#dd#ee#! + 1: + 2: ee +\= Expect no match + aa#! +No match + aa#bb#cc#dd#ee# +No match + +/^(?1)(?(DEFINE)(<(?2(3,4))><\4\3>)((..)(..)))/ + + 0: + +/(?1)#(?(DEFINE)(a(.(*ACCEPT).)b))/ + #axyb#axax# + 0: ax# + +/^(?>(?1()))!(?(DEFINE)((?..)(?..)))|abcde/dupnames + abcd! + 0: abcd! + 1: + 2: ab + 3: cd + abcde + 0: abcde + +/<(?:[^<>]*?(?:(AB)[^<>]*|)(?:|(?R(1))))+>/ + cc
    ee> + 0: cc
    ee> + dd>eehh>ii> + 0: dd>eehh>ii> + dd>ee + 0: dd> + cc
    AB> + 0: cc
    AB> + 1: AB + cc
    ee> + 0: cc
    ee> + 1: AB + dd>ee + 0: dd> + 1: AB + dd>eehh>ii> + 0: dd>eehh>ii> + 1: AB + dd>eehABhABh>ii> + 0: dd>eehABhABh>ii> + 1: AB + +/(?:(?1())#){4}(?(DEFINE)((?()\2)(?.{3})))$/ + abc#abcdef#defghi#ghijkl# + 0: abc#abcdef#defghi#ghijkl# + 1: + 2: jkl + abc#abcdef#defghi#ghijkl#jklmno# + 0: def#defghi#ghijkl#jklmno# + 1: + 2: mno + abc#abcdef#defghi#ghijkl#jklmno#mnopqr# + 0: ghi#ghijkl#jklmno#mnopqr# + 1: + 2: pqr +\= Expect no match + abc#abcdef#defghi#ghijkl +No match + abc#abcdef#defghi#ghXjkl# +No match + +% # Define the routine "weekendday" which matches Saturday or Sunday, and + # returns the Sat/Sun prefix as \k. + (?(DEFINE)(?(?|(?Sat)urday|(?Sun)day))) + # Call the routine. Matches "Saturday,Sat" or "Sunday,Sun". + (?&weekendday()),\k %x + Saturday,Sat + 0: Saturday,Sat + 1: + 2: Sat + Sunday,Sun + 0: Sunday,Sun + 1: + 2: Sun +\= Expect no match + Saturday,Sun +No match + +/()()()(?2(2,3,2,3,2))/B +------------------------------------------------------------------ + Bra + CBra 1 + Ket + CBra 2 + Ket + CBra 3 + Ket + Recurse + 2 Capture ref + 3 Capture ref + Ket + End +------------------------------------------------------------------ + abc + 0: + 1: + 2: + 3: + +# Test each syntax used for recursion + +/(?(R)(Sat)urday|(?R(1)),\1)/ + Saturday,Sat + 0: Saturday,Sat + 1: Sat + +/(?(DEFINE)((Sat)urday))(?1(2)),\2/ + Saturday,Sat + 0: Saturday,Sat + 1: + 2: Sat + +/(?(DEFINE)((Sat)urday))(?-2(-1)),\2/ + Saturday,Sat + 0: Saturday,Sat + 1: + 2: Sat + +/(?+1(+2)),\2(?(DEFINE)((Sat)urday))/ + Saturday,Sat + 0: Saturday,Sat + 1: + 2: Sat + +/(?(DEFINE)(?(?Sat)urday))(?&fn('ret')),\k/ + Saturday,Sat + 0: Saturday,Sat + 1: + 2: Sat + +/(?(DEFINE)(?(?Sat)urday))(?P>fn()),\k/ + Saturday,Sat + 0: Saturday,Sat + 1: + 2: Sat + +/(?(DEFINE)(?(?Sat)urday))\g,\k/ +Failed: error 142 at offset 39: syntax error in subpattern name (missing terminator?) + here: ...day))\g,\... + +/(?(DEFINE)((Sat)urday))(?1),\2/ +\= Expect no match + Saturday,Sat +No match + +/(?(DEFINE)((Sat)urday))(?1()),\2/ +Failed: error 217 at offset 27: expected capture group number or name + here: ...rday))(?1( |<--| )),\2 + +/(?(DEFINE)((Sat)(urday)))(?1(2,3)),\2,\3/ + Saturday,Sat,urday + 0: Saturday,Sat,urday + 1: + 2: Sat + 3: urday + +# -------------- + +# Test that a memory leak has been fixed +/x/replace=r,substitute_matched + x\=null_subject +Failed: error -51: NULL argument passed with non-zero length + +# Test that a couple of double frees have been fixed +/foo/replace=bar,substitute_matched + foo\=copy_matched_subject + 1: bar + foo\=global,copy_matched_subject + 1: bar + +# Tests for reading matches from NULL subjects +/(.?)/ + \=null_subject,copy=0,copy=1,get=0,get=1,getall + 0: + 1: + 0C (0) + 1C (0) + 0G (0) + 1G (0) + 0L + 1L + +# -------------- +# A batch of additional tests of pcre2_substitute error cases +# -------------- + +# Some baseline tests of the NULL-handling cases + +/\w+|^$/replace=<$&>,global + ::: + 0: ::: + \=null_subject + 1: <> + foo\=zero_terminate + 1: + \=null_subject,zero_terminate +Failed: error -51: NULL argument passed with non-zero length + foo|bar\=offset=1 + 2: f| + +/\w+|^$/replace=<$&>,global,substitute_matched + ::: + 0: ::: + \=null_subject + 1: <> + foo\=zero_terminate + 1: + \=null_subject,zero_terminate +Failed: error -51: NULL argument passed with non-zero length + foo|bar\=offset=1 + 2: f| + +/\w+|^$/replace=<$&>,global,null_substitute_match_data + ::: + 0: ::: + \=null_subject + 1: <> + foo\=zero_terminate + 1: + \=null_subject,zero_terminate +Failed: error -51: NULL argument passed with non-zero length + foo|bar\=offset=1 + 2: f| + +/\w+|^$/replace=<$&>,global,substitute_matched,null_substitute_match_data + ::: +Failed: error -51: NULL argument passed with non-zero length + \=null_subject +Failed: error -51: NULL argument passed with non-zero length + foo\=zero_terminate +Failed: error -51: NULL argument passed with non-zero length + \=null_subject,zero_terminate +Failed: error -51: NULL argument passed with non-zero length + foo|bar\=offset=1 +Failed: error -51: NULL argument passed with non-zero length + +# Now some NULL context tests + +/\w+|^$/replace=<$&>,global + :::\=null_context + 0: ::: + foo\=null_context + 1: + :::\=null_context,null_substitute_match_data + 0: ::: + foo\=null_context,null_substitute_match_data + 1: + :::\=null_context,substitute_matched + 0: ::: + foo\=null_context,substitute_matched + 1: + :::\=null_context,null_substitute_match_data,substitute_matched +Failed: error -51: NULL argument passed with non-zero length + foo\=null_context,null_substitute_match_data,substitute_matched +Failed: error -51: NULL argument passed with non-zero length + +# Failed matches: no-match; partial; other failure (callout-triggered) + +/abc/replace=yy + zABCz + 0: zABCz + zABCz\=substitute_matched + 0: zABCz + +/abc/ + ab\=replace=yy,partial_hard +Failed: error -34: bad option value + ab\=replace=yy,partial_hard,substitute_matched +Failed: error -34: bad option value + +/(?C1)abc/replace=yy + zabcz\=callout_error=1 +--->zabcz + 1 ^ a +Failed: error -37: callout error code + zabcz\=callout_error=1,substitute_matched +--->zabcz + 1 ^ a +Failed: error -37: callout error code + +# Exercise PCRE2_ERROR_DIFFSUBSSUBJECT branches + +# Changing the length is always an error +# (using PCRE2_ZERO_TERMINATED but with different length strings also counts) +# Using PCRE2_ZERO_TERMINATED vs a concrete length doesn't count as changing the length +/\w+|^$/replace=<$&>,global,substitute_matched + foo\=substitute_subject=foo + 1: + foo\=substitute_subject=foo,copy_matched_subject + 1: + foo\=substitute_subject=foo,zero_terminate + 1: + foo\=substitute_subject=f +Failed: error -72: substitute subject differs from prior match call + foo\=substitute_subject=f,copy_matched_subject +Failed: error -72: substitute subject differs from prior match call + foo\=substitute_subject=f,zero_terminate +Failed: error -72: substitute subject differs from prior match call + \ + 1: <> + \=copy_matched_subject + 1: <> + \=zero_terminate + 1: <> + \=null_subject + 1: <> + \=null_subject,copy_matched_subject + 1: <> + +# Keeping the length the same, the offset the same, and the pointer the same +# Is ok, even if the contents DIFFER +/\w+|^$/replace=<$&>,global,substitute_matched + foo|bar\=offset=1,substitute_subject=F|OOBAR + 2: F<|O> + foo|bar\=offset=1,substitute_subject=F|OOBAR,zero_terminate + 2: F<|O> + +# With copy_matched_subject however we are able to detect the mismatch +/\w+|^$/replace=<$&>,global,substitute_matched + foo|bar\=offset=1,substitute_subject=foo|bar,copy_matched_subject + 2: f| + foo|bar\=offset=1,substitute_subject=F|OOBAR,copy_matched_subject +Failed: error -72: substitute subject differs from prior match call + foo|bar\=offset=1,substitute_subject=F|OOBAR,copy_matched_subject,zero_terminate +Failed: error -72: substitute subject differs from prior match call + + # End of testinput2 Error -80: PCRE2_ERROR_BADDATA (unknown error number) Error -62: bad serialized data diff --git a/testdata/testoutput21 b/testdata/testoutput21 index 3ded7ed..f17a9c0 100644 --- a/testdata/testoutput21 +++ b/testdata/testoutput21 @@ -77,6 +77,7 @@ /ab\Cde/never_backslash_c Failed: error 183 at offset 4: using \C is disabled by the application + here: ab\C |<--| de /ab\Cde/info Capture group count = 0 @@ -92,6 +93,7 @@ Subject length lower bound = 5 0: X /[\C]/ -Failed: error 107 at offset 2: escape sequence is invalid in character class +Failed: error 107 at offset 3: escape sequence is invalid in character class + here: [\C |<--| ] # End of testinput21 diff --git a/testdata/testoutput22-16 b/testdata/testoutput22-16 index 5421854..df6e82f 100644 --- a/testdata/testoutput22-16 +++ b/testdata/testoutput22-16 @@ -18,6 +18,7 @@ Subject length lower bound = 2 /(?<=ab\Cde)X/utf Failed: error 136 at offset 0: \C is not allowed in a lookbehind assertion in UTF-16 mode + here: |-->| (?<=ab\Cde... ab!deXYZ # Autopossessification tests diff --git a/testdata/testoutput22-8 b/testdata/testoutput22-8 index eab410e..ebc6dbc 100644 --- a/testdata/testoutput22-8 +++ b/testdata/testoutput22-8 @@ -18,6 +18,7 @@ Subject length lower bound = 2 /(?<=ab\Cde)X/utf Failed: error 136 at offset 0: \C is not allowed in a lookbehind assertion in UTF-8 mode + here: |-->| (?<=ab\Cde... ab!deXYZ # Autopossessification tests diff --git a/testdata/testoutput23 b/testdata/testoutput23 index 2914767..eea97ea 100644 --- a/testdata/testoutput23 +++ b/testdata/testoutput23 @@ -4,8 +4,10 @@ /a\Cb/ Failed: error 185 at offset 3: using \C is disabled in this PCRE2 library + here: a\C |<--| b /a[\C]b/ -Failed: error 107 at offset 3: escape sequence is invalid in character class +Failed: error 107 at offset 4: escape sequence is invalid in character class + here: a[\C |<--| ]b # End of testinput23 diff --git a/testdata/testoutput24 b/testdata/testoutput24 index 9c59893..feac502 100644 --- a/testdata/testoutput24 +++ b/testdata/testoutput24 @@ -24,14 +24,24 @@ "[ab/cd]" (?s)\A[ab/cd](?/ (?s)\A<[a-c\-d]>\z @@ -508,6 +530,33 @@ No match /a`*b/convert_glob_escape=x ** Invalid glob escape 'x' +# Tests of null and empty inputs + +/a*b/use_length +(?s)\Aa(*COMMIT)[^/]*?b\z + +//use_length +(?s)\A\z + +# Error +/a*b/null_pattern +** Pattern conversion error at offset 0: NULL argument passed with non-zero length + +# Error +//null_pattern +** Pattern conversion error at offset 0: NULL argument passed with non-zero length + +# Error +/a*b/use_length,null_pattern +** Pattern conversion error at offset 0: NULL argument passed with non-zero length + +# Kind-of error... pattern conversion succeeds, but it converts to a non-empty +# pattern, and null_pattern applies to the regex parse afterwards too, which +# fails. +//use_length,null_pattern +(?s)\A\z +Failed: error 116 at offset 0: pattern passed as NULL with non-zero length + # -------- Tests of extended POSIX conversion -------- #pattern convert=unset:posix_extended @@ -568,6 +617,14 @@ No match /a***b/ (*NUL)a*b +# Tests of empty inputs + +/a*b/use_length +(*NUL)a*b + +//use_length +(*NUL) + # -------- Tests of basic POSIX conversion -------- #pattern convert=unset:posix_basic @@ -621,4 +678,12 @@ No match /a***b/ (*NUL)a*b +# Tests of empty inputs + +/a*b/use_length +(*NUL)a*b + +//use_length +(*NUL) + # End of testinput24 diff --git a/testdata/testoutput28 b/testdata/testoutput28 new file mode 100644 index 0000000..60a82f9 --- /dev/null +++ b/testdata/testoutput28 @@ -0,0 +1,217 @@ +# This tests the EBCDIC support in PCRE2. It catches cases where explicit values +# such as 0x0a have been used instead of names like CHAR_LF. +# +# This test file however is checked in to the repository encoded as ISO-8859-1, +# using a reversible mapping from EBCDIC. This lets us easily author test cases. +# However, they will only be run against a genuine EBCDIC when the input and +# output files are converted to EBCDIC. +# +# There is also a special mode, on ASCII systems, where pcre2test takes ASCII +# input (actually, ISO-8859-1), and then does the transcoding internally before +# calling the genuinely-EBCDIC version of PCRE2. + +# Test default newline and variations + +/^A/m + ABC + 0: A + 12\nABC + 0: A + +/^A/m,newline=any + 12\nABC + 0: A + 12\rABC + 0: A + 12\r\nABC + 0: A + 12\x85ABC + 0: A + +/^A/m,newline=anycrlf + 12\nABC + 0: A + 12\rABC + 0: A + 12\r\nABC + 0: A +\= Expect no match + 12\x85ABC +No match + +# Test \h + +/^A\h/ + A B + 0: A + A\tB + 0: A\x09 + A\xA0B + 0: A\xa0 + +# Test \H + +/^A\H/ + AB + 0: AB + A\x42B + 0: AB +\= Expect no match + A B +No match + +# Test \R + +/^A\R/ + A\nB + 0: A\x0a + A\rB + 0: A\x0d + A\x85B + 0: A\x85 + A\x0bB + 0: A\x0b + A\x0cB + 0: A\x0c +\= Expect no match + A B +No match + +# Test \v + +/^A\v/ + A\nB + 0: A\x0a + A\rB + 0: A\x0d + A\x85B + 0: A\x85 + A\x0bB + 0: A\x0b + A\x0cB + 0: A\x0c +\= Expect no match + A B +No match + +# Test \V + +/^A\V/ + A B + 0: A +\= Expect no match + A\nB +No match + A\rB +No match + A\x85B +No match + A\x0bB +No match + A\x0cB +No match + +# For repeated items, use an atomic group so that the output is the same +# for DFA matching (otherwise it may show multiple matches). + +# Test \h+ + +/^A(?>\h+)/ + A B + 0: A + +# Test \H+ + +/^A(?>\H+)/ + AB + 0: AB +\= Expect no match + A B +No match + +# Test \R+ + +/^A(?>\R+)/ + A\nB + 0: A\x0a + A\rB + 0: A\x0d + A\x85B + 0: A\x85 + A\x0bB + 0: A\x0b + A\x0cB + 0: A\x0c +\= Expect no match + A B +No match + +# Test \v+ + +/^A(?>\v+)/ + A\nB + 0: A\x0a + A\rB + 0: A\x0d + A\x85B + 0: A\x85 + A\x0bB + 0: A\x0b + A\x0cB + 0: A\x0c +\= Expect no match + A B +No match + +# Test \V+ + +/^A(?>\V+)/ + A B + 0: A B +\= Expect no match + A\nB +No match + A\rB +No match + A\x85B +No match + A\x0bB +No match + A\x0cB +No match + +# Test \c functionality + +/\c@\cA\cb\cC\cd\cE\cf\cG\ch\cI\cJ\cK\cl\cm\cN\cO\cp\cq\cr\cS\cT\cV\cW\cX\cy\cZ/ + \x00\x01\x02\x03\x9c\x09\x86\x7f\x97\x8d\x8e\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x9d\x08\x87\x18\x19\x92 + 0: \x00\x01\x02\x03\x9c\x09\x86\x7f\x97\x8d\x8e\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x9d\x08\x87\x18\x19\x92 + \x00\x01\x02\x03\x9c\x09\x86\x7f\x97\x8d\x8e\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x9d\x08\x87\x18\x19\x92 + 0: \x00\x01\x02\x03\x9c\x09\x86\x7f\x97\x8d\x8e\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x9d\x08\x87\x18\x19\x92 + +#if !ebcdic-nl25 + +/^\x15$/ + \n + 0: \x0a + +/\cU/ + \x0a + 0: \x0a + \x85 +No match + +#endif + +/\c[\c\\c]\c^\c_/ + \x8f\x1c\x1d\x1e\x1f + 0: \x8f\x1c\x1d\x1e\x1f + +/\c?/ + A\x9fB + 0: \x9f + +/\c&/ +Failed: error 168 at offset 3: \c must be followed by a letter or one of @[\]^_? + here: \c& |<--| + +# End diff --git a/testdata/testoutput29 b/testdata/testoutput29 new file mode 100644 index 0000000..abe3d86 --- /dev/null +++ b/testdata/testoutput29 @@ -0,0 +1,12 @@ +# This tests the EBCDIC support in PCRE2, specifically when NL has been +# configured to be 0x25. + +/^\x25$/ + \n + 0: \x0a + +/\cU/ + \x0a +No match + \x85 + 0: \x85 diff --git a/testdata/testoutput3 b/testdata/testoutput3 index 1fd9d97..6199e8c 100644 --- a/testdata/testoutput3 +++ b/testdata/testoutput3 @@ -14,7 +14,7 @@ No match /^[\w]+/locale=fr_FR École - 0: École + 0: \xc9cole /^[\W]+/ École @@ -46,7 +46,7 @@ No match /^\w+/locale=fr_FR École - 0: École + 0: \xc9cole /(.+)\b(.+)/ École @@ -68,9 +68,9 @@ No match /École/i,locale=fr_FR École - 0: École + 0: \xc9cole école - 0: école + 0: \xe9cole /\w/I Capture group count = 0 @@ -82,8 +82,11 @@ Subject length lower bound = 1 Capture group count = 0 Starting code units: 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ a b c d e f g h i j k l m n o p q r s t u v w x y z - ª µ º À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â - ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ + \xaa \xb5 \xba \xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb + \xcc \xcd \xce \xcf \xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 \xd9 \xda \xdb + \xdc \xdd \xde \xdf \xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea + \xeb \xec \xed \xee \xef \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf8 \xf9 \xfa + \xfb \xfc \xfd \xfe \xff Subject length lower bound = 1 # All remaining tests are in the fr_FR locale, so set the default. @@ -92,35 +95,35 @@ Subject length lower bound = 1 /^[\xc8-\xc9]/i École - 0: É + 0: \xc9 école - 0: é + 0: \xe9 /^[\xc8-\xc9]/ École - 0: É + 0: \xc9 \= Expect no match école No match /\xb5/i µ - 0: µ + 0: \xb5 \= Expect no match \x9c No match /ÿ/i \xff - 0: ÿ + 0: \xff \= Expect no match y No match /(.)\1/i \xfe\xde - 0: þÞ - 1: þ + 0: \xfe\xde + 1: \xfe /\W+/ >>>\xaa<<< @@ -142,21 +145,21 @@ No match /\w+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[\w]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]][[:lower:]][[:upper:]]/IB ------------------------------------------------------------------ @@ -169,9 +172,11 @@ No match ------------------------------------------------------------------ Capture group count = 0 Starting code units: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - a b c d e f g h i j k l m n o p q r s t u v w x y z ª µ º À Á Â Ã Ä Å Æ Ç - È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í - î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ + a b c d e f g h i j k l m n o p q r s t u v w x y z \xaa \xb5 \xba \xc0 \xc1 + \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf \xd0 + \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf \xe0 + \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef + \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf8 \xf9 \xfa \xfb \xfc \xfd \xfe \xff Subject length lower bound = 3 # End of testinput3 diff --git a/testdata/testoutput3A b/testdata/testoutput3A index 5e7e120..ae703be 100644 --- a/testdata/testoutput3A +++ b/testdata/testoutput3A @@ -14,7 +14,7 @@ No match /^[\w]+/locale=fr_FR École - 0: École + 0: \xc9cole /^[\W]+/ École @@ -46,7 +46,7 @@ No match /^\w+/locale=fr_FR École - 0: École + 0: \xc9cole /(.+)\b(.+)/ École @@ -68,9 +68,9 @@ No match /École/i,locale=fr_FR École - 0: École + 0: \xc9cole école - 0: école + 0: \xe9cole /\w/I Capture group count = 0 @@ -82,8 +82,11 @@ Subject length lower bound = 1 Capture group count = 0 Starting code units: 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ a b c d e f g h i j k l m n o p q r s t u v w x y z - ª µ º À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â - ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ + \xaa \xb5 \xba \xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb + \xcc \xcd \xce \xcf \xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 \xd9 \xda \xdb + \xdc \xdd \xde \xdf \xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea + \xeb \xec \xed \xee \xef \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf8 \xf9 \xfa + \xfb \xfc \xfd \xfe \xff Subject length lower bound = 1 # All remaining tests are in the fr_FR locale, so set the default. @@ -92,35 +95,35 @@ Subject length lower bound = 1 /^[\xc8-\xc9]/i École - 0: É + 0: \xc9 école - 0: é + 0: \xe9 /^[\xc8-\xc9]/ École - 0: É + 0: \xc9 \= Expect no match école No match /\xb5/i µ - 0: µ + 0: \xb5 \= Expect no match \x9c No match /ÿ/i \xff - 0: ÿ + 0: \xff \= Expect no match y No match /(.)\1/i \xfe\xde - 0: þÞ - 1: þ + 0: \xfe\xde + 1: \xfe /\W+/ >>>\xaa<<< @@ -142,21 +145,21 @@ No match /\w+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[\w]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]][[:lower:]][[:upper:]]/IB ------------------------------------------------------------------ @@ -169,9 +172,11 @@ No match ------------------------------------------------------------------ Capture group count = 0 Starting code units: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - a b c d e f g h i j k l m n o p q r s t u v w x y z ª µ º À Á Â Ã Ä Å Æ Ç - È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í - î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ + a b c d e f g h i j k l m n o p q r s t u v w x y z \xaa \xb5 \xba \xc0 \xc1 + \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf \xd0 + \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf \xe0 + \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef + \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf8 \xf9 \xfa \xfb \xfc \xfd \xfe \xff Subject length lower bound = 3 # End of testinput3 diff --git a/testdata/testoutput3B b/testdata/testoutput3B index 0dcbee6..1651f81 100644 --- a/testdata/testoutput3B +++ b/testdata/testoutput3B @@ -14,7 +14,7 @@ No match /^[\w]+/locale=fr_FR École - 0: École + 0: \xc9cole /^[\W]+/ École @@ -46,7 +46,7 @@ No match /^\w+/locale=fr_FR École - 0: École + 0: \xc9cole /(.+)\b(.+)/ École @@ -68,9 +68,9 @@ No match /École/i,locale=fr_FR École - 0: École + 0: \xc9cole école - 0: école + 0: \xe9cole /\w/I Capture group count = 0 @@ -82,8 +82,11 @@ Subject length lower bound = 1 Capture group count = 0 Starting code units: 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ a b c d e f g h i j k l m n o p q r s t u v w x y z - ª µ º À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â - ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ + \xaa \xb5 \xba \xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb + \xcc \xcd \xce \xcf \xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 \xd9 \xda \xdb + \xdc \xdd \xde \xdf \xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea + \xeb \xec \xed \xee \xef \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf8 \xf9 \xfa + \xfb \xfc \xfd \xfe \xff Subject length lower bound = 1 # All remaining tests are in the fr_FR locale, so set the default. @@ -92,35 +95,35 @@ Subject length lower bound = 1 /^[\xc8-\xc9]/i École - 0: É + 0: \xc9 école - 0: é + 0: \xe9 /^[\xc8-\xc9]/ École - 0: É + 0: \xc9 \= Expect no match école No match /\xb5/i µ - 0: µ + 0: \xb5 \= Expect no match \x9c No match /ÿ/i \xff - 0: ÿ + 0: \xff \= Expect no match y No match /(.)\1/i \xfe\xde - 0: þÞ - 1: þ + 0: \xfe\xde + 1: \xfe /\W+/ >>>\xaa<<< @@ -142,21 +145,21 @@ No match /\w+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[\w]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]][[:lower:]][[:upper:]]/IB ------------------------------------------------------------------ @@ -169,9 +172,11 @@ No match ------------------------------------------------------------------ Capture group count = 0 Starting code units: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - a b c d e f g h i j k l m n o p q r s t u v w x y z ª µ º À Á Â Ã Ä Å Æ Ç - È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í - î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ + a b c d e f g h i j k l m n o p q r s t u v w x y z \xaa \xb5 \xba \xc0 \xc1 + \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf \xd0 + \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf \xe0 + \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef + \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf8 \xf9 \xfa \xfb \xfc \xfd \xfe \xff Subject length lower bound = 3 # End of testinput3 diff --git a/testdata/testoutput5 b/testdata/testoutput5 index 73d484c..fd36974 100644 --- a/testdata/testoutput5 +++ b/testdata/testoutput5 @@ -124,33 +124,43 @@ Optimizations: auto_possess,dotstar_anchor /\x{110000}/IB,utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /\o{4200000}/IB,utf Failed: error 134 at offset 10: character code point value in \x{} or \o{} is too large + here: \o{4200000 |<--| } /\x{ffffffff}/utf Failed: error 134 at offset 11: character code point value in \x{} or \o{} is too large + here: ...x{ffffffff |<--| } /\o{37777777777}/utf Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...7777777777 |<--| } /\x{100000000}/utf Failed: error 134 at offset 12: character code point value in \x{} or \o{} is too large + here: ...{100000000 |<--| } /\o{77777777777}/utf Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...7777777777 |<--| } /\x{d800}/utf Failed: error 173 at offset 7: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) + here: \x{d800 |<--| } /\o{154000}/utf Failed: error 173 at offset 9: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) + here: \o{154000 |<--| } /\x{dfff}/utf Failed: error 173 at offset 7: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) + here: \x{dfff |<--| } /\o{157777}/utf Failed: error 173 at offset 9: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) + here: \o{157777 |<--| } /\x{d7ff}/utf @@ -295,7 +305,8 @@ Last code unit = 'b' Subject length lower bound = 2 /[\x{200}-\x{100}]/utf -Failed: error 108 at offset 15: range out of order in character class +Failed: error 108 at offset 16: range out of order in character class + here: ...0}-\x{100} |<--| ] /[Ā-Ą]/utf \x{100} @@ -821,9 +832,11 @@ No match /[[:a\x{100}b:]]/utf Failed: error 130 at offset 14: unknown POSIX class name + here: ...\x{100}b:] |<--| ] /[\p{InvalidOrBadProperty}]/ Failed: error 147 at offset 25: unknown property after \P or \p + here: ...dProperty} |<--| ] /a[^]b/utf,allow_empty_class,match_unset_backref a\x{1234}b @@ -1382,7 +1395,7 @@ Partial match: X /\g{A}xxx#bXX(?'A'123) (?'A'456)/Bx,newline=any,utf ------------------------------------------------------------------ Bra - \1 + \g{1} xxx CBra 1 456 @@ -1394,7 +1407,7 @@ Partial match: X /\g{A}xxx#bх(?'A'123) (?'A'456)/Bx,newline=any,utf ------------------------------------------------------------------ Bra - \1 + \g{1} xxx CBra 1 456 @@ -1403,9 +1416,6 @@ Partial match: X End ------------------------------------------------------------------ -/^\cÄ£/utf -Failed: error 168 at offset 3: \c must be followed by a printable ASCII character - /(\R*)(.)/s,utf \r\n 0: \x{0d} @@ -1474,9 +1484,11 @@ Partial match: for /\x{d800}/utf Failed: error 173 at offset 7: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) + here: \x{d800 |<--| } /\x{dfff}/utf Failed: error 173 at offset 7: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) + here: \x{dfff |<--| } /\h+/utf \x{1681}\x{200b}\x{1680}\x{2000}\x{202f}\x{3000} @@ -1760,6 +1772,7 @@ No match /\ud800/utf,alt_bsux,allow_empty_class,match_unset_backref Failed: error 173 at offset 6: disallowed Unicode code point (>= 0xd800 && <= 0xdfff) + here: \ud800 |<--| /^\u{0000000000010ffff}/utf,extra_alt_bsux \x{10ffff} @@ -4009,6 +4022,7 @@ Subject length lower bound = 1 \x{17f}\x{17f}\x{17f}\x{17f}\x{17f} 0: \x{17f} 0+ \x{17f}\x{17f}\x{17f}\x{17f} +global repeat returned the same match as previous 0: \x{17f} 0+ \x{17f}\x{17f}\x{17f} 0: \x{17f} @@ -4032,12 +4046,22 @@ Subject length lower bound = 1 0+ "\xa\xf<(.\pZ*\P{Xwd}+^\xa8\3'3yq.::?(?J:()\xd1+!~:3'(8?:)':(?'d'(?'d'^u]!.+.+\\A\Ah(n+?9){7}+\K;(?'X'u'(?'c'(?'z'(?\xb::\xf0'|\xd3(\xae?'w(z\x8?P>l)\x8?P>a)'\H\R\xd1+!!~:3'(?:h$N{26875}\W+?\\=D{2}\x89(?i:Uy0\N({2\xa(\v\x85*){y*\A(()\p{L}+?\P{^Xan}'+?\xff\+pS\?|).{;y*\A(()\p{L}+?\8}\d?1(|)(/1){7}.+[Lp{Me}].\s\xdcC*?(?())(?))(?\g{d});\g{x}\x11\g{d}\x81\|$((?'X'\'X'(?'W''\x92()'9'\x83*))\xba*\!?^ <){)':;\xcc4'\xd1'(?'X'28))?-%--\x95$9*\4'|\xd1((''e\x94*$9:)*#(?'R')3)\x7?('P\xed')\\x16:;()\x1e\x10*:(?)\xd1+0!~:(?)'d'E:yD!\s(?'R'\x1e;\x10:U))|'\x9g!\xb0*){)\\x16:;()\x1e\x10\x87*:(?)\xd1+!~:(?)'}'\d'E:yD!\s(?'R'\x1e;\x10:U))|'))|)g!\xb0*R+9{29+)#(?'P'})*?pS\{3,}\x85,{0,}l{*UTF)(\xe{7}){3722,{9,}d{2,?|))|{)\(A?&d}}{\xa,}2}){3,}7,l{)22}(,}l:7{2,4}}29\x19+)#?'P'})*v?))\x5" -Failed: error 122 at offset 1227: unmatched closing parenthesis +Failed: error 122 at offset 1228: unmatched closing parenthesis + here: ...?'P'})*v?) |<--| )\x5 /$(&.+[\p{Me}].\s\xdcC*?(?())(?)\xd1+!~:(?)''(d'E:yD!\s(?'R'\x1e;\x10:U))|')g!\xb0*){29+))#(?'P'})*?/ "(*UTF)(*UCP)(.UTF).+X(\V+;\^(\D|)!999}(?(?C{7(?C')\H*\S*/^\x5\xa\\xd3\x85n?(;\D*(?m).[^mH+((*UCP)(*U:F)})(?!^)(?'" Failed: error 162 at offset 113: subpattern name expected + here: ...})(?!^)(?' |<--| + +/(?(?C'')\Qé/utf +Failed: error 128 at offset 8: atomic assertion expected after (?( or (?(?C) + here: (?(?C'') |<--| \Qé + +/(?(?C'')é/utf +Failed: error 128 at offset 8: atomic assertion expected after (?( or (?(?C) + here: (?(?C'') |<--| é /[\pS#moq]/ = @@ -4065,7 +4089,7 @@ MK: a\x{12345}b\x{09}(d)c Bra \b (ucp) Assert back - Reverse + 1 Reverse prop Xwd Ket X @@ -4175,6 +4199,7 @@ No match /(*UTF)C\x09((?| (?<=A\XB) /../utf,auto_callout \n\x{123}\x{123}\x{123}\x{123} @@ -4769,13 +4795,28 @@ Callout 0: last capture = 1 0: \x{1d1aa} /\N{U+}/ -Failed: error 193 at offset 2: \N{U+dddd} is supported only in Unicode (UTF) mode +Failed: error 193 at offset 6: \N{U+dddd} is supported only in Unicode (UTF) mode + here: \N{U+} |<--| /\N{U+}/utf Failed: error 178 at offset 5: digits missing after \x or in \x{} or \o{} or \N{U+} + here: \N{U+ |<--| } /\N{U}/ -Failed: error 137 at offset 2: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u +Failed: error 137 at offset 3: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u + here: \N{ |<--| U} + +/\N{U+}/utf +Failed: error 178 at offset 5: digits missing after \x or in \x{} or \o{} or \N{U+} + here: \N{U+ |<--| } + +/\N{U+1}/ +Failed: error 193 at offset 7: \N{U+dddd} is supported only in Unicode (UTF) mode + here: \N{U+1} |<--| + +/\N{U+1 }/ +Failed: error 193 at offset 8: \N{U+dddd} is supported only in Unicode (UTF) mode + here: \N{U+1 } |<--| # This tests the non-UTF Unicode NEL pattern whitespace character, only # recognized by PCRE2 with /x when there is Unicode support. @@ -4851,7 +4892,7 @@ MK: ABC ------------------------------------------------------------------ Bra Assert back - Reverse + 10 Reverse abc Assert X @@ -4936,15 +4977,15 @@ Subject length lower bound = 3 /(?'AB၌C'...)\g{AB၌C}/utf Failed: error 142 at offset 5: syntax error in subpattern name (missing terminator?) - -/(?'Ù ABC'...)/utf -Failed: error 144 at offset 3: subpattern name must start with a non-digit + here: (?'AB |<--| ၌C'...)\g{... /(?'²ABC'...)/utf Failed: error 162 at offset 3: subpattern name expected + here: (?' |<--| ²ABC'...) /(?'X²ABC'...)/utf Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?) + here: (?'X |<--| ²ABC'...) # ------- @@ -5024,6 +5065,7 @@ Subject length lower bound = 3 /\p{sc:L}/ Failed: error 147 at offset 8: unknown property after \P or \p + here: \p{sc:L} |<--| # Some Boolean property tests that differ from Perl @@ -5043,6 +5085,7 @@ Failed: error 147 at offset 8: unknown property after \P or \p /\p{\2b[:xäigi:t:_/ Failed: error 146 at offset 10: malformed \P or \p sequence + here: \p{\2b[:xä |<--| igi:t:_ # Tests for PCRE2_EXTRA_CASELESS_RESTRICT. Compare each test with and without # the restriction. @@ -5273,6 +5316,50 @@ No match k \x{212a} No match +/(.) \1 z/Bir +------------------------------------------------------------------ + Bra + CBra 1 + Any + Ket + /i + /i \g{1} 0x01 + /i z + Ket + End +------------------------------------------------------------------ + s s z + 0: s s z + 1: s + s S z + 0: s S z + 1: s + +/(?J:(?s)|(?.)) \k z/Bir +------------------------------------------------------------------ + Bra + Bra + CBra 1 + /i s + Ket + Alt + CBra 2 + Any + Ket + Ket + /i + /i \k2 0x01 + /i z + Ket + End +------------------------------------------------------------------ + s s z + 0: s s z + 1: s + s S z + 0: s S z + 1: s + /(.) \1/i,utf s S 0: s S @@ -6009,14 +6096,9 @@ No match (?\777< abc @@ -6046,6 +6128,7 @@ Failed: error 147 at offset 10: unknown property after \P or \p /\400/utf,python_octal Failed: error 202 at offset 4: octal value given by \ddd is greater than \377 (forbidden by PCRE2_EXTRA_PYTHON_OCTAL) + here: \400 |<--| /abc/utf,substitute_extended abc\=replace=\400 @@ -6054,6 +6137,7 @@ Failed: error 202 at offset 4: octal value given by \ddd is greater than \377 (f /abc/utf,substitute_extended,python_octal abc\=replace=\400 Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string + here: \400 |<--| # Character range merging tests @@ -6226,7 +6310,8 @@ No match # Freeing memory on error test /[\x{100}-\x{400}][\x{100}-\x{300}][\x{100}-\x{200}]\8/i,utf -Failed: error 115 at offset 52: reference to non-existent subpattern +Failed: error 115 at offset 53: reference to non-existent subpattern + here: ...\x{200}]\8 |<-->| # Character list tests @@ -6799,15 +6884,19 @@ No match /[\p{Lu}-z]/B,alt_extended_class Failed: error 150 at offset 8: invalid range in character class + here: [\p{Lu}- |<--| z] /[z-\p{Lu}]/B,alt_extended_class Failed: error 150 at offset 9: invalid range in character class + here: [z-\p{Lu} |<--| ] /[\pL-z]/B,alt_extended_class Failed: error 150 at offset 5: invalid range in character class + here: [\pL- |<--| z] /[z-\pL]/B,alt_extended_class Failed: error 150 at offset 6: invalid range in character class + here: [z-\pL |<--| ] /[\p{Lu}-&&-\pL]/B,alt_extended_class ------------------------------------------------------------------ @@ -7120,7 +7209,7 @@ No match CBra 1 [a-mo-z] Ket - \1 + \g{1} Ket End ------------------------------------------------------------------ @@ -7144,7 +7233,7 @@ No match [a-mo-z] y Ket - \1 + \g{1} Ket End ------------------------------------------------------------------ @@ -7163,7 +7252,7 @@ No match Bra Bra _ - \1 + \g{1} Alt CBra 1 [a-mo-z] @@ -7171,7 +7260,7 @@ No match Ket Bra _ - \1 + \g{1} Alt CBra 1 [a-mo-z] @@ -7197,7 +7286,7 @@ No match Bra Bra _ - \1 + \g{1} Alt CBra 1 [a-mo-z] @@ -8150,15 +8239,19 @@ No match /[z-\p{Lu}]/ Failed: error 150 at offset 9: invalid range in character class + here: [z-\p{Lu} |<--| ] /[z-\pL]/ Failed: error 150 at offset 6: invalid range in character class + here: [z-\pL |<--| ] /[\p{Lu}-z]/ Failed: error 150 at offset 8: invalid range in character class + here: [\p{Lu}- |<--| z] /[\pL-z]/ Failed: error 150 at offset 5: invalid range in character class + here: [\pL- |<--| z] /[a\x{e1}]/iB ------------------------------------------------------------------ diff --git a/testdata/testoutput6 b/testdata/testoutput6 index 74c40e9..8ecf004 100644 --- a/testdata/testoutput6 +++ b/testdata/testoutput6 @@ -923,10 +923,14 @@ No match What do you know about THE QUICK BROWN FOX? 0: THE QUICK BROWN FOX +#if !ebcdic + /abcd\t\n\r\f\a\e\071\x3b\$\\\?caxyz/ abcd\t\n\r\f\a\e9;\$\\?caxyz 0: abcd\x09\x0a\x0d\x0c\x07\x1b9;$\?caxyz +#endif + /a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz/ abxyzpqrrrabbxyyyypqAzz 0: abxyzpqrrrabbxyyyypqAzz @@ -1091,10 +1095,14 @@ No match babababc No match +#if !ebcdic + /^\ca\cA\c[\c{\c:/ \x01\x01\e;z 0: \x01\x01\x1b;z +#endif + /^[ab\]cde]/ athing 0: a @@ -1316,7 +1324,7 @@ No match 1IN SOA non-sp1 non-sp2( No match -/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-z\d\-]*)*\.$/ +/^[a-zA-Z\d][a-zA-Z\d\-]*(\.[a-zA-Z\d][a-zA-Z\d\-]*)*\.$/ a. 0: a. Z. @@ -1670,6 +1678,8 @@ No match 4: aab 5: aa +#if !ebcdic + / (?: [\040\t] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] )* \) )* \) )* # optional leading comment @@ -2494,6 +2504,8 @@ No match The quick brown fox No match +#endif + /abc\0def\00pqr\000xyz\0000AB/ abc\0def\00pqr\000xyz\0000AB 0: abc\x00def\x00pqr\x00xyz\x000AB @@ -2574,6 +2586,8 @@ No match track1.title:TBlah blah blah 0: track1.title:TBlah blah blah +#if !ebcdic + /^[W-c]+$/ WXY_^abc 0: WXY_^abc @@ -2593,6 +2607,8 @@ No match wxy_^ABC 0: wxy_^ABC +#endif + /^abc$/m abc 0: abc @@ -2674,6 +2690,8 @@ No match aaa No match +#if !ebcdic + /\x5c/ \\ 0: \ @@ -2685,6 +2703,8 @@ No match Zulu No match +#endif + /ab{3cd/ ab{3cd 0: ab{3cd @@ -2717,6 +2737,8 @@ No match abc\ndef No match +#if !ebcdic + /(abc)\123/ abc\x53 0: abcS @@ -2753,6 +2775,8 @@ No match abcdefghijk\12S 0: abcdefghijk\x0aS +#endif + /a{0}bc/ bc 0: bc @@ -2761,10 +2785,14 @@ No match xyz 0: xyz +#if !ebcdic + /abc[\10]de/ abc\010de 0: abc\x08de +#endif + /abc[\1]de/ abc\1de 0: abc\x01de @@ -2877,10 +2905,14 @@ No match aaAabcd 0: b +#if !ebcdic + /\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377/ \000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377 0: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff +#endif + /P[^*]TAIRE[^*]{1,6}?LL/ xxxxxxxxxxxPSTAIREISLLxxxxxxxxx 0: PSTAIREISLL @@ -3018,6 +3050,8 @@ No match No match ]abcd[ No match + +#if !ebcdic /^[W-\]46]/ W46]789 @@ -3041,6 +3075,8 @@ No match No match well No match + +#endif /\d\d\/\d\d\/\d\d\d\d/ 01/01/2000 @@ -5868,6 +5904,8 @@ No match regulär 0: regul\xe4r +#if !ebcdic + /Åæåä[à-ÿÀ-ß]+/ Åæåäà 0: \xc5\xe6\xe5\xe4\xe0 @@ -5878,6 +5916,8 @@ No match Åæåäß 0: \xc5\xe6\xe5\xe4\xdf +#endif + /(?<=Z)X./ \x84XAZXB 0: XB @@ -5961,6 +6001,8 @@ Partial match: 123 aB 0: B +#if !ebcdic + /Content-Type\x3A[^\r\n]{6,}/ Content-Type:xxxxxyyy 0: Content-Type:xxxxxyyy @@ -5977,6 +6019,8 @@ Partial match: 123 Content-Type:xxxyyyz 0: Content-Type:xxxyyyz +#endif + /^abc/Im,newline=lf Capture group count = 0 Options: multiline @@ -6423,12 +6467,16 @@ No match > X NY Z No match +#if !ebcdic + /\v*X\v?Y\v+Z\V*\x0a\V+\x0b\V{2,3}\x0c/ >XY\x0aZ\x0aA\x0bNN\x0c 0: XY\x0aZ\x0aA\x0bNN\x0c >\x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c 0: \x0a\x0dX\x0aY\x0a\x0bZZZ\x0aAAA\x0bNNN\x0c +#endif + /.+A/newline=crlf \= Expect no match \r\nA @@ -7454,6 +7502,7 @@ Get substring "A" failed (-41): function is not supported for DFA matching aa\=copy=A 0: aa Copy substring "A" failed (-41): function is not supported for DFA matching +Get substring "A" length failed (-41): function is not supported for DFA matching /a+/no_auto_possess a\=ovector=2,get=1,get=2,getall @@ -7475,6 +7524,7 @@ Get substring 2 failed (-54): requested value is not available Partial match: abc 0C abc (3) Copy substring 1 failed (-2): partial match +Get substring 1 length failed (-2): partial match get substring list failed (-2): partial match /ab(?C" any text with spaces ")cde/B @@ -8164,4 +8214,27 @@ No match # -------------- +/^(?1(2))(?(DEFINE)(a(.)b))/ + axb +Failed: error -42: pattern contains an item that is not supported for DFA matching + +# Tests for reading matches from NULL subjects +/(.?)/ + \=null_subject,copy=0,get=0,getall + 0: + 0C (0) + 0G (0) + 0L + +# -------------- + +# Verify pcre2_substitute is blocked for DFA + +/abc/ + abc\=replace=xyz +** Ignored for DFA matching: replace + 0: abc + abc\=replace=xyz,substitute_matched +Failed: error -41: function is not supported for DFA matching + # End of testinput6 diff --git a/testdata/testoutput8-16-2 b/testdata/testoutput8-16-2 index f2a3815..b8dba98 100644 --- a/testdata/testoutput8-16-2 +++ b/testdata/testoutput8-16-2 @@ -247,7 +247,7 @@ Memory allocation - data size : 6 9 Any 10 Any 11 Any - 12 \1 + 12 \g{1} 14 bbb 20 2 Recurse 22 d @@ -334,6 +334,7 @@ Memory allocation - code size : 16 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /[\x{ff}]/utf Memory allocation - code size : 14 @@ -453,6 +454,7 @@ Memory allocation - code size : 26 /^[\QĀ\E-\QŐ\E/utf Failed: error 106 at offset 13: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /[\p{L}]/ Memory allocation - code size : 24 @@ -729,7 +731,7 @@ Memory allocation - code size : 14 6 12 CBra 2 9 7 CBra 3 12 a - 14 \2 + 14 \g{2} 16 7 Ket 18 11 Alt 20 5 CBra 4 @@ -749,7 +751,7 @@ Memory allocation - code size : 14 2 12 CBra 1 5 7 Recurse 7 5 CBra 2 - 10 \1 + 10 \g{1} 12 5 Ket 14 12 Ket 16 16 Ket @@ -776,7 +778,7 @@ Memory allocation - code size : 14 6 19 Recurse 8 0 Recurse 10 4 Alt - 12 \1 + 12 \g{1} 14 3 Alt 16 $ 17 14 Ket @@ -797,7 +799,7 @@ Memory allocation - code size : 14 13 3 Ket 15 10 Recurse 17 4 Alt - 19 \1 + 19 \g{1} 21 3 Alt 23 $ 24 21 Ket @@ -820,7 +822,7 @@ Memory allocation - code size : 14 21 15 CBra 6 24 10 CBra 7 27 5 Once - 29 \1+ + 29 \g{1}+ 32 5 Ket 34 10 Ket 36 15 Ket @@ -842,6 +844,7 @@ Memory allocation - code size : 14 ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) /parens_nest_limit=1000,-fullbincode Failed: error 184 at offset 1129: (?| and/or (?J: or (?x: parentheses are too deeply nested + here: ...?|(?|(?|(? |-->| |(?|(?|(?|... # Use "expand" to create some very long patterns with nested parentheses, in # order to test workspace overflow. Again, this varies with code unit width, @@ -853,7 +856,7 @@ Failed: error 184 at offset 1129: (?| and/or (?J: or (?x: parentheses are too de /(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 /(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated +Failed: error 186 at offset 0: regular expression is too complicated /(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------ @@ -1012,12 +1015,13 @@ Subject length lower bound = 0 /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ Failed: error 114 at offset 509: missing closing parenthesis + here: ...](*ACCEPT) |<--| /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode #pattern -fullbincode /\[()]{65535}/expand -Failed: error 120 at offset 131070: regular expression is too large +Failed: error 120 at offset 0: regular expression is too large # End of testinput8 diff --git a/testdata/testoutput8-16-3 b/testdata/testoutput8-16-3 deleted file mode 100644 index d46ceba..0000000 --- a/testdata/testoutput8-16-3 +++ /dev/null @@ -1,1021 +0,0 @@ -# There are two sorts of patterns in this test. A number of them are -# representative patterns whose lengths and offsets are checked. This is just a -# doublecheck test to ensure the sizes don't go horribly wrong when something -# is changed. The operation of these patterns is checked in other tests. -# -# This file also contains tests whose output varies with code unit size and/or -# link size. Unicode support is required for these tests. There are separate -# output files for each code unit size and link size. - -#pattern fullbincode,memory - -/((?i)b)/ -Memory allocation - code size : 32 ------------------------------------------------------------------- - 0 12 Bra - 3 6 CBra 1 - 7 /i b - 9 6 Ket - 12 12 Ket - 15 End ------------------------------------------------------------------- - -/(?s)(.*X|^B)/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 20 Bra - 3 8 CBra 1 - 7 AllAny* - 9 X - 11 6 Alt - 14 ^ - 15 B - 17 14 Ket - 20 20 Ket - 23 End ------------------------------------------------------------------- - -/(?s:.*X|^B)/ -Memory allocation - code size : 46 ------------------------------------------------------------------- - 0 19 Bra - 3 7 Bra - 6 AllAny* - 8 X - 10 6 Alt - 13 ^ - 14 B - 16 13 Ket - 19 19 Ket - 22 End ------------------------------------------------------------------- - -/^[[:alnum:]]/ -Memory allocation - code size : 50 ------------------------------------------------------------------- - 0 21 Bra - 3 ^ - 4 [0-9A-Za-z] - 21 21 Ket - 24 End ------------------------------------------------------------------- - -/#/Ix -Memory allocation - code size : 14 ------------------------------------------------------------------- - 0 3 Bra - 3 3 Ket - 6 End ------------------------------------------------------------------- -Capture group count = 0 -May match empty string -Options: extended -Subject length lower bound = 0 - -/a#/Ix -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 a - 5 5 Ket - 8 End ------------------------------------------------------------------- -Capture group count = 0 -Options: extended -First code unit = 'a' -Subject length lower bound = 1 - -/x?+/ -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 x?+ - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/x++/ -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 x++ - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/x{1,3}+/ -Memory allocation - code size : 24 ------------------------------------------------------------------- - 0 8 Bra - 3 x - 5 x{0,2}+ - 8 8 Ket - 11 End ------------------------------------------------------------------- - -/(x)*+/ -Memory allocation - code size : 34 ------------------------------------------------------------------- - 0 13 Bra - 3 Braposzero - 4 6 CBraPos 1 - 8 x - 10 6 KetRpos - 13 13 Ket - 16 End ------------------------------------------------------------------- - -/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/ -Memory allocation - code size : 166 ------------------------------------------------------------------- - 0 79 Bra - 3 ^ - 4 72 CBra 1 - 8 6 CBra 2 - 12 a+ - 14 6 Ket - 17 22 CBra 3 - 21 [ab]+? - 39 22 Ket - 42 22 CBra 4 - 46 [bc]+ - 64 22 Ket - 67 6 CBra 5 - 71 \w*+ - 73 6 Ket - 76 72 Ket - 79 79 Ket - 82 End ------------------------------------------------------------------- - -"8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b" -Memory allocation - code size : 1652 ------------------------------------------------------------------- - 0 822 Bra - 3 8J$WE<.rX+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDDqmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X -821 \b -822 822 Ket -825 End ------------------------------------------------------------------- - -"\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b" -Memory allocation - code size : 1632 ------------------------------------------------------------------- - 0 812 Bra - 3 $<.X+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDDqmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X -811 \b -812 812 Ket -815 End ------------------------------------------------------------------- - -/(a(?1)b)/ -Memory allocation - code size : 42 ------------------------------------------------------------------- - 0 17 Bra - 3 11 CBra 1 - 7 a - 9 3 Recurse - 12 b - 14 11 Ket - 17 17 Ket - 20 End ------------------------------------------------------------------- - -/(a(?1)+b)/ -Memory allocation - code size : 54 ------------------------------------------------------------------- - 0 23 Bra - 3 17 CBra 1 - 7 a - 9 6 SBra - 12 3 Recurse - 15 6 KetRmax - 18 b - 20 17 Ket - 23 23 Ket - 26 End ------------------------------------------------------------------- - -/a(?Pb|c)d(?Pe)/ -Memory allocation - code size : 68 -Memory allocation - data size : 52 ------------------------------------------------------------------- - 0 30 Bra - 3 a - 5 6 CBra 1 - 9 b - 11 5 Alt - 14 c - 16 11 Ket - 19 d - 21 6 CBra 2 - 25 e - 27 6 Ket - 30 30 Ket - 33 End ------------------------------------------------------------------- - -/(?:a(?Pc(?Pd)))(?Pa)/ -Memory allocation - code size : 84 -Memory allocation - data size : 18 ------------------------------------------------------------------- - 0 38 Bra - 3 23 Bra - 6 a - 8 15 CBra 1 - 12 c - 14 6 CBra 2 - 18 d - 20 6 Ket - 23 15 Ket - 26 23 Ket - 29 6 CBra 3 - 33 a - 35 6 Ket - 38 38 Ket - 41 End ------------------------------------------------------------------- - -/(?Pa)...(?P=a)bbb(?P>a)d/ -Memory allocation - code size : 64 -Memory allocation - data size : 6 ------------------------------------------------------------------- - 0 28 Bra - 3 6 CBra 1 - 7 a - 9 6 Ket - 12 Any - 13 Any - 14 Any - 15 \1 - 17 bbb - 23 3 Recurse - 26 d - 28 28 Ket - 31 End ------------------------------------------------------------------- - -/abc(?C255)de(?C)f/ -Memory allocation - code size : 62 ------------------------------------------------------------------- - 0 27 Bra - 3 abc - 9 Callout 255 10 1 - 15 de - 19 Callout 0 16 1 - 25 f - 27 27 Ket - 30 End ------------------------------------------------------------------- - -/abcde/auto_callout -Memory allocation - code size : 106 ------------------------------------------------------------------- - 0 49 Bra - 3 Callout 255 0 1 - 9 a - 11 Callout 255 1 1 - 17 b - 19 Callout 255 2 1 - 25 c - 27 Callout 255 3 1 - 33 d - 35 Callout 255 4 1 - 41 e - 43 Callout 255 5 0 - 49 49 Ket - 52 End ------------------------------------------------------------------- - -/\x{100}/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{100} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/\x{1000}/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{1000} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/\x{10000}/utf -Memory allocation - code size : 20 ------------------------------------------------------------------- - 0 6 Bra - 3 \x{10000} - 6 6 Ket - 9 End ------------------------------------------------------------------- - -/\x{100000}/utf -Memory allocation - code size : 20 ------------------------------------------------------------------- - 0 6 Bra - 3 \x{100000} - 6 6 Ket - 9 End ------------------------------------------------------------------- - -/\x{10ffff}/utf -Memory allocation - code size : 20 ------------------------------------------------------------------- - 0 6 Bra - 3 \x{10ffff} - 6 6 Ket - 9 End ------------------------------------------------------------------- - -/\x{110000}/utf -Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large - -/[\x{ff}]/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{ff} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[\x{100}]/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{100} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/\x80/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{80} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/\xff/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{ff} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/\x{0041}\x{2262}\x{0391}\x{002e}/I,utf -Memory allocation - code size : 30 ------------------------------------------------------------------- - 0 11 Bra - 3 A\x{2262}\x{391}. - 11 11 Ket - 14 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = 'A' -Last code unit = '.' -Subject length lower bound = 4 - -/\x{D55c}\x{ad6d}\x{C5B4}/I,utf -Memory allocation - code size : 26 ------------------------------------------------------------------- - 0 9 Bra - 3 \x{d55c}\x{ad6d}\x{c5b4} - 9 9 Ket - 12 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = \x{d55c} -Last code unit = \x{c5b4} -Subject length lower bound = 3 - -/\x{65e5}\x{672c}\x{8a9e}/I,utf -Memory allocation - code size : 26 ------------------------------------------------------------------- - 0 9 Bra - 3 \x{65e5}\x{672c}\x{8a9e} - 9 9 Ket - 12 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = \x{65e5} -Last code unit = \x{8a9e} -Subject length lower bound = 3 - -/[\x{100}]/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{100} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[Z\x{100}]/utf -Memory allocation - code size : 60 ------------------------------------------------------------------- - 0 26 Bra - 3 [Z\x{100}] - 26 26 Ket - 29 End ------------------------------------------------------------------- - -/^[\x{100}\E-\Q\E\x{150}]/utf -Memory allocation - code size : 32 ------------------------------------------------------------------- - 0 12 Bra - 3 ^ - 4 [\x{100}-\x{150}] - 12 12 Ket - 15 End ------------------------------------------------------------------- - -/^[\QĀ\E-\QŐ\E]/utf -Memory allocation - code size : 32 ------------------------------------------------------------------- - 0 12 Bra - 3 ^ - 4 [\x{100}-\x{150}] - 12 12 Ket - 15 End ------------------------------------------------------------------- - -/^[\QĀ\E-\QŐ\E/utf -Failed: error 106 at offset 13: missing terminating ] for character class - -/[\p{L}]/ -Memory allocation - code size : 30 ------------------------------------------------------------------- - 0 11 Bra - 3 [\p{L}] - 11 11 Ket - 14 End ------------------------------------------------------------------- - -/[\p{^L}]/ -Memory allocation - code size : 30 ------------------------------------------------------------------- - 0 11 Bra - 3 [\P{L}] - 11 11 Ket - 14 End ------------------------------------------------------------------- - -/[\P{L}]/ -Memory allocation - code size : 30 ------------------------------------------------------------------- - 0 11 Bra - 3 [\P{L}] - 11 11 Ket - 14 End ------------------------------------------------------------------- - -/[\P{^L}]/ -Memory allocation - code size : 30 ------------------------------------------------------------------- - 0 11 Bra - 3 [\p{L}] - 11 11 Ket - 14 End ------------------------------------------------------------------- - -/[abc\p{L}\x{0660}]/utf -Memory allocation - code size : 66 ------------------------------------------------------------------- - 0 29 Bra - 3 [A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\xff\p{L}\x{660}] - 29 29 Ket - 32 End ------------------------------------------------------------------- - -/[\p{Nd}]/utf -Memory allocation - code size : 30 ------------------------------------------------------------------- - 0 11 Bra - 3 [\p{Nd}] - 11 11 Ket - 14 End ------------------------------------------------------------------- - -/[\p{Nd}+-]+/utf -Memory allocation - code size : 64 ------------------------------------------------------------------- - 0 28 Bra - 3 [+\-0-9\p{Nd}]++ - 28 28 Ket - 31 End ------------------------------------------------------------------- - -/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/i,utf -Memory allocation - code size : 36 ------------------------------------------------------------------- - 0 14 Bra - 3 /i A\x{391}\x{10427}\x{ff3a}\x{1fb0} - 14 14 Ket - 17 End ------------------------------------------------------------------- - -/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/utf -Memory allocation - code size : 36 ------------------------------------------------------------------- - 0 14 Bra - 3 A\x{391}\x{10427}\x{ff3a}\x{1fb0} - 14 14 Ket - 17 End ------------------------------------------------------------------- - -/[\x{105}-\x{109}]/i,utf -Memory allocation - code size : 30 ------------------------------------------------------------------- - 0 11 Bra - 3 [\x{104}-\x{109}] - 11 11 Ket - 14 End ------------------------------------------------------------------- - -/( ( (?(1)0|) )* )/x -Memory allocation - code size : 70 ------------------------------------------------------------------- - 0 31 Bra - 3 25 CBra 1 - 7 Brazero - 8 17 SCBra 2 - 12 7 Cond - 15 1 Capture ref - 17 0 - 19 3 Alt - 22 10 Ket - 25 17 KetRmax - 28 25 Ket - 31 31 Ket - 34 End ------------------------------------------------------------------- - -/( (?(1)0|)* )/x -Memory allocation - code size : 56 ------------------------------------------------------------------- - 0 24 Bra - 3 18 CBra 1 - 7 Brazero - 8 7 SCond - 11 1 Capture ref - 13 0 - 15 3 Alt - 18 10 KetRmax - 21 18 Ket - 24 24 Ket - 27 End ------------------------------------------------------------------- - -/[a]/ -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 a - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[a]/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 a - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[\xaa]/ -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{aa} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[\xaa]/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 \x{aa} - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[^a]/ -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 [^a] (not) - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[^a]/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 [^a] (not) - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[^\xaa]/ -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 [^\x{aa}] (not) - 5 5 Ket - 8 End ------------------------------------------------------------------- - -/[^\xaa]/utf -Memory allocation - code size : 18 ------------------------------------------------------------------- - 0 5 Bra - 3 [^\x{aa}] (not) - 5 5 Ket - 8 End ------------------------------------------------------------------- - -#pattern -memory - -/[^\d]/utf,ucp ------------------------------------------------------------------- - 0 11 Bra - 3 [^\p{Nd}] - 11 11 Ket - 14 End ------------------------------------------------------------------- - -/[[:^alpha:][:^cntrl:]]+/utf,ucp ------------------------------------------------------------------- - 0 15 Bra - 3 [\P{L}\P{Cc}]++ - 15 15 Ket - 18 End ------------------------------------------------------------------- - -/[[:^cntrl:][:^alpha:]]+/utf,ucp ------------------------------------------------------------------- - 0 15 Bra - 3 [\P{Cc}\P{L}]++ - 15 15 Ket - 18 End ------------------------------------------------------------------- - -/[[:alpha:]]+/utf,ucp ------------------------------------------------------------------- - 0 12 Bra - 3 [\p{L}]++ - 12 12 Ket - 15 End ------------------------------------------------------------------- - -/[[:^alpha:]\S]+/utf,ucp ------------------------------------------------------------------- - 0 15 Bra - 3 [\P{L}\P{Xsp}]++ - 15 15 Ket - 18 End ------------------------------------------------------------------- - -/abc(d|e)(*THEN)x(123(*THEN)4|567(b|q)(*THEN)xx)/ ------------------------------------------------------------------- - 0 70 Bra - 3 abc - 9 6 CBra 1 - 13 d - 15 5 Alt - 18 e - 20 11 Ket - 23 *THEN - 24 x - 26 13 CBra 2 - 30 123 - 36 *THEN - 37 4 - 39 28 Alt - 42 567 - 48 6 CBra 3 - 52 b - 54 5 Alt - 57 q - 59 11 Ket - 62 *THEN - 63 xx - 67 41 Ket - 70 70 Ket - 73 End ------------------------------------------------------------------- - -/(((a\2)|(a*)\g<-1>))*a?/ ------------------------------------------------------------------- - 0 46 Bra - 3 Brazero - 4 37 SCBra 1 - 8 15 CBra 2 - 12 8 CBra 3 - 16 a - 18 \2 - 20 8 Ket - 23 15 Alt - 26 6 CBra 4 - 30 a* - 32 6 Ket - 35 26 Recurse - 38 30 Ket - 41 37 KetRmax - 44 a?+ - 46 46 Ket - 49 End ------------------------------------------------------------------- - -/((?+1)(\1))/ ------------------------------------------------------------------- - 0 22 Bra - 3 16 CBra 1 - 7 10 Recurse - 10 6 CBra 2 - 14 \1 - 16 6 Ket - 19 16 Ket - 22 22 Ket - 25 End ------------------------------------------------------------------- - -"(?1)(?#?'){2}(a)" ------------------------------------------------------------------- - 0 18 Bra - 3 9 Recurse - 6 9 Recurse - 9 6 CBra 1 - 13 a - 15 6 Ket - 18 18 Ket - 21 End ------------------------------------------------------------------- - -/.((?2)(?R)|\1|$)()/ ------------------------------------------------------------------- - 0 33 Bra - 3 Any - 4 10 CBra 1 - 8 26 Recurse - 11 0 Recurse - 14 5 Alt - 17 \1 - 19 4 Alt - 22 $ - 23 19 Ket - 26 4 CBra 2 - 30 4 Ket - 33 33 Ket - 36 End ------------------------------------------------------------------- - -/.((?3)(?R)()(?2)|\1|$)()/ ------------------------------------------------------------------- - 0 43 Bra - 3 Any - 4 20 CBra 1 - 8 36 Recurse - 11 0 Recurse - 14 4 CBra 2 - 18 4 Ket - 21 14 Recurse - 24 5 Alt - 27 \1 - 29 4 Alt - 32 $ - 33 29 Ket - 36 4 CBra 3 - 40 4 Ket - 43 43 Ket - 46 End ------------------------------------------------------------------- - -/(?1)()((((((\1++))\x85)+)|))/ ------------------------------------------------------------------- - 0 69 Bra - 3 6 Recurse - 6 4 CBra 1 - 10 4 Ket - 13 53 CBra 2 - 17 43 CBra 3 - 21 36 CBra 4 - 25 29 CBra 5 - 29 20 CBra 6 - 33 13 CBra 7 - 37 6 Once - 40 \1+ - 43 6 Ket - 46 13 Ket - 49 20 Ket - 52 \x{85} - 54 29 KetRmax - 57 36 Ket - 60 3 Alt - 63 46 Ket - 66 53 Ket - 69 69 Ket - 72 End ------------------------------------------------------------------- - -# Check the absolute limit on nesting (?| etc. This varies with code unit -# width because the workspace is a different number of bytes. It will fail -# with link size 2 in 8-bit and 16-bit but not in 32-bit. - -/(?|(?|(?J:(?|(?x:(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?| -))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) -/parens_nest_limit=1000,-fullbincode - -# Use "expand" to create some very long patterns with nested parentheses, in -# order to test workspace overflow. Again, this varies with code unit width, -# and even when it fails in two modes, the error offset differs. It also varies -# with link size - hence multiple tests with different values. - -/(?'ABC'\[[bar](]{792}*THEN:\[A]{255}\[)]{793}/expand,-fullbincode,parens_nest_limit=1000 - -/(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 - -/(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated - -/(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------- - 0 110 Bra - 3 97 Once - 6 8 Cond - 9 1 Capture ref - 11 103 Recurse - 14 8 Ket - 17 8 Cond - 20 1 Capture ref - 22 103 Recurse - 25 8 Ket - 28 8 Cond - 31 1 Capture ref - 33 103 Recurse - 36 8 Ket - 39 8 Cond - 42 1 Capture ref - 44 103 Recurse - 47 8 Ket - 50 8 Cond - 53 1 Capture ref - 55 103 Recurse - 58 8 Ket - 61 8 Cond - 64 1 Capture ref - 66 103 Recurse - 69 8 Ket - 72 8 Cond - 75 1 Capture ref - 77 103 Recurse - 80 8 Ket - 83 14 SBraPos - 86 8 SCond - 89 1 Capture ref - 91 103 Recurse - 94 8 Ket - 97 14 KetRpos -100 97 Ket -103 4 CBra 1 -107 4 Ket -110 110 Ket -113 End ------------------------------------------------------------------- -Capture group count = 1 -Max back reference = 1 -May match empty string -Subject length lower bound = 0 - abcd - 0: - 1: - -/(?(1)|a(?1)b){2,}+()/debug ------------------------------------------------------------------- - 0 58 Bra - 3 45 Once - 6 5 Cond - 9 1 Capture ref - 11 10 Alt - 14 a - 16 51 Recurse - 19 b - 21 15 Ket - 24 21 SBraPos - 27 5 SCond - 30 1 Capture ref - 32 10 Alt - 35 a - 37 51 Recurse - 40 b - 42 15 Ket - 45 21 KetRpos - 48 45 Ket - 51 4 CBra 1 - 55 4 Ket - 58 58 Ket - 61 End ------------------------------------------------------------------- -Capture group count = 1 -Max back reference = 1 -May match empty string -Subject length lower bound = 0 - abcde -No match - -/((?1)(?2)(?3)(?4)(?5)(?6)(?7)(?8)(?9)(?9)(?8)(?7)(?6)(?5)(?4)(?3)(?2)(?1)(?0)){2,}()()()()()()()()()/debug ------------------------------------------------------------------- - 0 194 Bra - 3 61 CBra 1 - 7 3 Recurse - 10 131 Recurse - 13 138 Recurse - 16 145 Recurse - 19 152 Recurse - 22 159 Recurse - 25 166 Recurse - 28 173 Recurse - 31 180 Recurse - 34 180 Recurse - 37 173 Recurse - 40 166 Recurse - 43 159 Recurse - 46 152 Recurse - 49 145 Recurse - 52 138 Recurse - 55 131 Recurse - 58 3 Recurse - 61 0 Recurse - 64 61 Ket - 67 61 SCBra 1 - 71 3 Recurse - 74 131 Recurse - 77 138 Recurse - 80 145 Recurse - 83 152 Recurse - 86 159 Recurse - 89 166 Recurse - 92 173 Recurse - 95 180 Recurse - 98 180 Recurse -101 173 Recurse -104 166 Recurse -107 159 Recurse -110 152 Recurse -113 145 Recurse -116 138 Recurse -119 131 Recurse -122 3 Recurse -125 0 Recurse -128 61 KetRmax -131 4 CBra 2 -135 4 Ket -138 4 CBra 3 -142 4 Ket -145 4 CBra 4 -149 4 Ket -152 4 CBra 5 -156 4 Ket -159 4 CBra 6 -163 4 Ket -166 4 CBra 7 -170 4 Ket -173 4 CBra 8 -177 4 Ket -180 4 CBra 9 -184 4 Ket -187 4 CBra 10 -191 4 Ket -194 194 Ket -197 End ------------------------------------------------------------------- -Capture group count = 10 -May match empty string -Subject length lower bound = 0 - -/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ -Failed: error 114 at offset 509: missing closing parenthesis - -/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode - -#pattern -fullbincode - -/\[()]{65535}/expand - -# End of testinput8 diff --git a/testdata/testoutput8-16-4 b/testdata/testoutput8-16-4 index d46ceba..f2c2d2d 100644 --- a/testdata/testoutput8-16-4 +++ b/testdata/testoutput8-16-4 @@ -247,7 +247,7 @@ Memory allocation - data size : 6 12 Any 13 Any 14 Any - 15 \1 + 15 \g{1} 17 bbb 23 3 Recurse 26 d @@ -334,6 +334,7 @@ Memory allocation - code size : 20 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /[\x{ff}]/utf Memory allocation - code size : 18 @@ -453,6 +454,7 @@ Memory allocation - code size : 32 /^[\QĀ\E-\QŐ\E/utf Failed: error 106 at offset 13: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /[\p{L}]/ Memory allocation - code size : 30 @@ -729,7 +731,7 @@ Memory allocation - code size : 18 8 15 CBra 2 12 8 CBra 3 16 a - 18 \2 + 18 \g{2} 20 8 Ket 23 15 Alt 26 6 CBra 4 @@ -749,7 +751,7 @@ Memory allocation - code size : 18 3 16 CBra 1 7 10 Recurse 10 6 CBra 2 - 14 \1 + 14 \g{1} 16 6 Ket 19 16 Ket 22 22 Ket @@ -776,7 +778,7 @@ Memory allocation - code size : 18 8 26 Recurse 11 0 Recurse 14 5 Alt - 17 \1 + 17 \g{1} 19 4 Alt 22 $ 23 19 Ket @@ -797,7 +799,7 @@ Memory allocation - code size : 18 18 4 Ket 21 14 Recurse 24 5 Alt - 27 \1 + 27 \g{1} 29 4 Alt 32 $ 33 29 Ket @@ -820,7 +822,7 @@ Memory allocation - code size : 18 29 20 CBra 6 33 13 CBra 7 37 6 Once - 40 \1+ + 40 \g{1}+ 43 6 Ket 46 13 Ket 49 20 Ket @@ -852,7 +854,7 @@ Memory allocation - code size : 18 /(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 /(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated +Failed: error 186 at offset 0: regular expression is too complicated /(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------ @@ -1011,6 +1013,7 @@ Subject length lower bound = 0 /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ Failed: error 114 at offset 509: missing closing parenthesis + here: ...](*ACCEPT) |<--| /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode diff --git a/testdata/testoutput8-32-2 b/testdata/testoutput8-32-2 deleted file mode 100644 index e9865c8..0000000 --- a/testdata/testoutput8-32-2 +++ /dev/null @@ -1,1021 +0,0 @@ -# There are two sorts of patterns in this test. A number of them are -# representative patterns whose lengths and offsets are checked. This is just a -# doublecheck test to ensure the sizes don't go horribly wrong when something -# is changed. The operation of these patterns is checked in other tests. -# -# This file also contains tests whose output varies with code unit size and/or -# link size. Unicode support is required for these tests. There are separate -# output files for each code unit size and link size. - -#pattern fullbincode,memory - -/((?i)b)/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 5 CBra 1 - 5 /i b - 7 5 Ket - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/(?s)(.*X|^B)/ -Memory allocation - code size : 76 ------------------------------------------------------------------- - 0 16 Bra - 2 7 CBra 1 - 5 AllAny* - 7 X - 9 5 Alt - 11 ^ - 12 B - 14 12 Ket - 16 16 Ket - 18 End ------------------------------------------------------------------- - -/(?s:.*X|^B)/ -Memory allocation - code size : 72 ------------------------------------------------------------------- - 0 15 Bra - 2 6 Bra - 4 AllAny* - 6 X - 8 5 Alt - 10 ^ - 11 B - 13 11 Ket - 15 15 Ket - 17 End ------------------------------------------------------------------- - -/^[[:alnum:]]/ -Memory allocation - code size : 60 ------------------------------------------------------------------- - 0 12 Bra - 2 ^ - 3 [0-9A-Za-z] - 12 12 Ket - 14 End ------------------------------------------------------------------- - -/#/Ix -Memory allocation - code size : 20 ------------------------------------------------------------------- - 0 2 Bra - 2 2 Ket - 4 End ------------------------------------------------------------------- -Capture group count = 0 -May match empty string -Options: extended -Subject length lower bound = 0 - -/a#/Ix -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 a - 4 4 Ket - 6 End ------------------------------------------------------------------- -Capture group count = 0 -Options: extended -First code unit = 'a' -Subject length lower bound = 1 - -/x?+/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 x?+ - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/x++/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 x++ - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/x{1,3}+/ -Memory allocation - code size : 40 ------------------------------------------------------------------- - 0 7 Bra - 2 x - 4 x{0,2}+ - 7 7 Ket - 9 End ------------------------------------------------------------------- - -/(x)*+/ -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 Braposzero - 3 5 CBraPos 1 - 6 x - 8 5 KetRpos - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/ -Memory allocation - code size : 220 ------------------------------------------------------------------- - 0 52 Bra - 2 ^ - 3 47 CBra 1 - 6 5 CBra 2 - 9 a+ - 11 5 Ket - 13 13 CBra 3 - 16 [ab]+? - 26 13 Ket - 28 13 CBra 4 - 31 [bc]+ - 41 13 Ket - 43 5 CBra 5 - 46 \w*+ - 48 5 Ket - 50 47 Ket - 52 52 Ket - 54 End ------------------------------------------------------------------- - -"8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b" -Memory allocation - code size : 3296 ------------------------------------------------------------------- - 0 821 Bra - 2 8J$WE<.rX+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDDqmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X -820 \b -821 821 Ket -823 End ------------------------------------------------------------------- - -"\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b" -Memory allocation - code size : 3256 ------------------------------------------------------------------- - 0 811 Bra - 2 $<.X+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDDqmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X -810 \b -811 811 Ket -813 End ------------------------------------------------------------------- - -/(a(?1)b)/ -Memory allocation - code size : 64 ------------------------------------------------------------------- - 0 13 Bra - 2 9 CBra 1 - 5 a - 7 2 Recurse - 9 b - 11 9 Ket - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/(a(?1)+b)/ -Memory allocation - code size : 80 ------------------------------------------------------------------- - 0 17 Bra - 2 13 CBra 1 - 5 a - 7 4 SBra - 9 2 Recurse - 11 4 KetRmax - 13 b - 15 13 Ket - 17 17 Ket - 19 End ------------------------------------------------------------------- - -/a(?Pb|c)d(?Pe)/ -Memory allocation - code size : 108 -Memory allocation - data size : 104 ------------------------------------------------------------------- - 0 24 Bra - 2 a - 4 5 CBra 1 - 7 b - 9 4 Alt - 11 c - 13 9 Ket - 15 d - 17 5 CBra 2 - 20 e - 22 5 Ket - 24 24 Ket - 26 End ------------------------------------------------------------------- - -/(?:a(?Pc(?Pd)))(?Pa)/ -Memory allocation - code size : 128 -Memory allocation - data size : 36 ------------------------------------------------------------------- - 0 29 Bra - 2 18 Bra - 4 a - 6 12 CBra 1 - 9 c - 11 5 CBra 2 - 14 d - 16 5 Ket - 18 12 Ket - 20 18 Ket - 22 5 CBra 3 - 25 a - 27 5 Ket - 29 29 Ket - 31 End ------------------------------------------------------------------- - -/(?Pa)...(?P=a)bbb(?P>a)d/ -Memory allocation - code size : 108 -Memory allocation - data size : 12 ------------------------------------------------------------------- - 0 24 Bra - 2 5 CBra 1 - 5 a - 7 5 Ket - 9 Any - 10 Any - 11 Any - 12 \1 - 14 bbb - 20 2 Recurse - 22 d - 24 24 Ket - 26 End ------------------------------------------------------------------- - -/abc(?C255)de(?C)f/ -Memory allocation - code size : 100 ------------------------------------------------------------------- - 0 22 Bra - 2 abc - 8 Callout 255 10 1 - 12 de - 16 Callout 0 16 1 - 20 f - 22 22 Ket - 24 End ------------------------------------------------------------------- - -/abcde/auto_callout -Memory allocation - code size : 156 ------------------------------------------------------------------- - 0 36 Bra - 2 Callout 255 0 1 - 6 a - 8 Callout 255 1 1 - 12 b - 14 Callout 255 2 1 - 18 c - 20 Callout 255 3 1 - 24 d - 26 Callout 255 4 1 - 30 e - 32 Callout 255 5 0 - 36 36 Ket - 38 End ------------------------------------------------------------------- - -/\x{100}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{1000}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{1000} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{10000}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{10000} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{100000}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100000} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{10ffff}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{10ffff} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{110000}/utf -Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large - -/[\x{ff}]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{ff} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[\x{100}]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x80/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{80} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\xff/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{ff} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{0041}\x{2262}\x{0391}\x{002e}/I,utf -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 A\x{2262}\x{391}. - 10 10 Ket - 12 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = 'A' -Last code unit = '.' -Subject length lower bound = 4 - -/\x{D55c}\x{ad6d}\x{C5B4}/I,utf -Memory allocation - code size : 44 ------------------------------------------------------------------- - 0 8 Bra - 2 \x{d55c}\x{ad6d}\x{c5b4} - 8 8 Ket - 10 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = \x{d55c} -Last code unit = \x{c5b4} -Subject length lower bound = 3 - -/\x{65e5}\x{672c}\x{8a9e}/I,utf -Memory allocation - code size : 44 ------------------------------------------------------------------- - 0 8 Bra - 2 \x{65e5}\x{672c}\x{8a9e} - 8 8 Ket - 10 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = \x{65e5} -Last code unit = \x{8a9e} -Subject length lower bound = 3 - -/[\x{100}]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[Z\x{100}]/utf -Memory allocation - code size : 76 ------------------------------------------------------------------- - 0 16 Bra - 2 [Z\x{100}] - 16 16 Ket - 18 End ------------------------------------------------------------------- - -/^[\x{100}\E-\Q\E\x{150}]/utf -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 ^ - 3 [\x{100}-\x{150}] - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/^[\QĀ\E-\QŐ\E]/utf -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 ^ - 3 [\x{100}-\x{150}] - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/^[\QĀ\E-\QŐ\E/utf -Failed: error 106 at offset 13: missing terminating ] for character class - -/[\p{L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\p{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\p{^L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\P{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\P{L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\P{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\P{^L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\p{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[abc\p{L}\x{0660}]/utf -Memory allocation - code size : 88 ------------------------------------------------------------------- - 0 19 Bra - 2 [A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\xff\p{L}\x{660}] - 19 19 Ket - 21 End ------------------------------------------------------------------- - -/[\p{Nd}]/utf -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\p{Nd}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\p{Nd}+-]+/utf -Memory allocation - code size : 84 ------------------------------------------------------------------- - 0 18 Bra - 2 [+\-0-9\p{Nd}]++ - 18 18 Ket - 20 End ------------------------------------------------------------------- - -/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/i,utf -Memory allocation - code size : 60 ------------------------------------------------------------------- - 0 12 Bra - 2 /i A\x{391}\x{10427}\x{ff3a}\x{1fb0} - 12 12 Ket - 14 End ------------------------------------------------------------------- - -/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/utf -Memory allocation - code size : 60 ------------------------------------------------------------------- - 0 12 Bra - 2 A\x{391}\x{10427}\x{ff3a}\x{1fb0} - 12 12 Ket - 14 End ------------------------------------------------------------------- - -/[\x{105}-\x{109}]/i,utf -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\x{104}-\x{109}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/( ( (?(1)0|) )* )/x -Memory allocation - code size : 104 ------------------------------------------------------------------- - 0 23 Bra - 2 19 CBra 1 - 5 Brazero - 6 13 SCBra 2 - 9 6 Cond - 11 1 Capture ref - 13 0 - 15 2 Alt - 17 8 Ket - 19 13 KetRmax - 21 19 Ket - 23 23 Ket - 25 End ------------------------------------------------------------------- - -/( (?(1)0|)* )/x -Memory allocation - code size : 84 ------------------------------------------------------------------- - 0 18 Bra - 2 14 CBra 1 - 5 Brazero - 6 6 SCond - 8 1 Capture ref - 10 0 - 12 2 Alt - 14 8 KetRmax - 16 14 Ket - 18 18 Ket - 20 End ------------------------------------------------------------------- - -/[a]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 a - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[a]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 a - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[\xaa]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{aa} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[\xaa]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{aa} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^a]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^a] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^a]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^a] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^\xaa]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^\x{aa}] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^\xaa]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^\x{aa}] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -#pattern -memory - -/[^\d]/utf,ucp ------------------------------------------------------------------- - 0 9 Bra - 2 [^\p{Nd}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[[:^alpha:][:^cntrl:]]+/utf,ucp ------------------------------------------------------------------- - 0 13 Bra - 2 [\P{L}\P{Cc}]++ - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/[[:^cntrl:][:^alpha:]]+/utf,ucp ------------------------------------------------------------------- - 0 13 Bra - 2 [\P{Cc}\P{L}]++ - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/[[:alpha:]]+/utf,ucp ------------------------------------------------------------------- - 0 10 Bra - 2 [\p{L}]++ - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/[[:^alpha:]\S]+/utf,ucp ------------------------------------------------------------------- - 0 13 Bra - 2 [\P{L}\P{Xsp}]++ - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/abc(d|e)(*THEN)x(123(*THEN)4|567(b|q)(*THEN)xx)/ ------------------------------------------------------------------- - 0 60 Bra - 2 abc - 8 5 CBra 1 - 11 d - 13 4 Alt - 15 e - 17 9 Ket - 19 *THEN - 20 x - 22 12 CBra 2 - 25 123 - 31 *THEN - 32 4 - 34 24 Alt - 36 567 - 42 5 CBra 3 - 45 b - 47 4 Alt - 49 q - 51 9 Ket - 53 *THEN - 54 xx - 58 36 Ket - 60 60 Ket - 62 End ------------------------------------------------------------------- - -/(((a\2)|(a*)\g<-1>))*a?/ ------------------------------------------------------------------- - 0 35 Bra - 2 Brazero - 3 28 SCBra 1 - 6 12 CBra 2 - 9 7 CBra 3 - 12 a - 14 \2 - 16 7 Ket - 18 11 Alt - 20 5 CBra 4 - 23 a* - 25 5 Ket - 27 20 Recurse - 29 23 Ket - 31 28 KetRmax - 33 a?+ - 35 35 Ket - 37 End ------------------------------------------------------------------- - -/((?+1)(\1))/ ------------------------------------------------------------------- - 0 16 Bra - 2 12 CBra 1 - 5 7 Recurse - 7 5 CBra 2 - 10 \1 - 12 5 Ket - 14 12 Ket - 16 16 Ket - 18 End ------------------------------------------------------------------- - -"(?1)(?#?'){2}(a)" ------------------------------------------------------------------- - 0 13 Bra - 2 6 Recurse - 4 6 Recurse - 6 5 CBra 1 - 9 a - 11 5 Ket - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/.((?2)(?R)|\1|$)()/ ------------------------------------------------------------------- - 0 24 Bra - 2 Any - 3 7 CBra 1 - 6 19 Recurse - 8 0 Recurse - 10 4 Alt - 12 \1 - 14 3 Alt - 16 $ - 17 14 Ket - 19 3 CBra 2 - 22 3 Ket - 24 24 Ket - 26 End ------------------------------------------------------------------- - -/.((?3)(?R)()(?2)|\1|$)()/ ------------------------------------------------------------------- - 0 31 Bra - 2 Any - 3 14 CBra 1 - 6 26 Recurse - 8 0 Recurse - 10 3 CBra 2 - 13 3 Ket - 15 10 Recurse - 17 4 Alt - 19 \1 - 21 3 Alt - 23 $ - 24 21 Ket - 26 3 CBra 3 - 29 3 Ket - 31 31 Ket - 33 End ------------------------------------------------------------------- - -/(?1)()((((((\1++))\x85)+)|))/ ------------------------------------------------------------------- - 0 50 Bra - 2 4 Recurse - 4 3 CBra 1 - 7 3 Ket - 9 39 CBra 2 - 12 32 CBra 3 - 15 27 CBra 4 - 18 22 CBra 5 - 21 15 CBra 6 - 24 10 CBra 7 - 27 5 Once - 29 \1+ - 32 5 Ket - 34 10 Ket - 36 15 Ket - 38 \x{85} - 40 22 KetRmax - 42 27 Ket - 44 2 Alt - 46 34 Ket - 48 39 Ket - 50 50 Ket - 52 End ------------------------------------------------------------------- - -# Check the absolute limit on nesting (?| etc. This varies with code unit -# width because the workspace is a different number of bytes. It will fail -# with link size 2 in 8-bit and 16-bit but not in 32-bit. - -/(?|(?|(?J:(?|(?x:(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?| -))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) -/parens_nest_limit=1000,-fullbincode - -# Use "expand" to create some very long patterns with nested parentheses, in -# order to test workspace overflow. Again, this varies with code unit width, -# and even when it fails in two modes, the error offset differs. It also varies -# with link size - hence multiple tests with different values. - -/(?'ABC'\[[bar](]{792}*THEN:\[A]{255}\[)]{793}/expand,-fullbincode,parens_nest_limit=1000 - -/(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 - -/(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated - -/(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------- - 0 79 Bra - 2 70 Once - 4 6 Cond - 6 1 Capture ref - 8 74 Recurse - 10 6 Ket - 12 6 Cond - 14 1 Capture ref - 16 74 Recurse - 18 6 Ket - 20 6 Cond - 22 1 Capture ref - 24 74 Recurse - 26 6 Ket - 28 6 Cond - 30 1 Capture ref - 32 74 Recurse - 34 6 Ket - 36 6 Cond - 38 1 Capture ref - 40 74 Recurse - 42 6 Ket - 44 6 Cond - 46 1 Capture ref - 48 74 Recurse - 50 6 Ket - 52 6 Cond - 54 1 Capture ref - 56 74 Recurse - 58 6 Ket - 60 10 SBraPos - 62 6 SCond - 64 1 Capture ref - 66 74 Recurse - 68 6 Ket - 70 10 KetRpos - 72 70 Ket - 74 3 CBra 1 - 77 3 Ket - 79 79 Ket - 81 End ------------------------------------------------------------------- -Capture group count = 1 -Max back reference = 1 -May match empty string -Subject length lower bound = 0 - abcd - 0: - 1: - -/(?(1)|a(?1)b){2,}+()/debug ------------------------------------------------------------------- - 0 43 Bra - 2 34 Once - 4 4 Cond - 6 1 Capture ref - 8 8 Alt - 10 a - 12 38 Recurse - 14 b - 16 12 Ket - 18 16 SBraPos - 20 4 SCond - 22 1 Capture ref - 24 8 Alt - 26 a - 28 38 Recurse - 30 b - 32 12 Ket - 34 16 KetRpos - 36 34 Ket - 38 3 CBra 1 - 41 3 Ket - 43 43 Ket - 45 End ------------------------------------------------------------------- -Capture group count = 1 -Max back reference = 1 -May match empty string -Subject length lower bound = 0 - abcde -No match - -/((?1)(?2)(?3)(?4)(?5)(?6)(?7)(?8)(?9)(?9)(?8)(?7)(?6)(?5)(?4)(?3)(?2)(?1)(?0)){2,}()()()()()()()()()/debug ------------------------------------------------------------------- - 0 133 Bra - 2 41 CBra 1 - 5 2 Recurse - 7 88 Recurse - 9 93 Recurse - 11 98 Recurse - 13 103 Recurse - 15 108 Recurse - 17 113 Recurse - 19 118 Recurse - 21 123 Recurse - 23 123 Recurse - 25 118 Recurse - 27 113 Recurse - 29 108 Recurse - 31 103 Recurse - 33 98 Recurse - 35 93 Recurse - 37 88 Recurse - 39 2 Recurse - 41 0 Recurse - 43 41 Ket - 45 41 SCBra 1 - 48 2 Recurse - 50 88 Recurse - 52 93 Recurse - 54 98 Recurse - 56 103 Recurse - 58 108 Recurse - 60 113 Recurse - 62 118 Recurse - 64 123 Recurse - 66 123 Recurse - 68 118 Recurse - 70 113 Recurse - 72 108 Recurse - 74 103 Recurse - 76 98 Recurse - 78 93 Recurse - 80 88 Recurse - 82 2 Recurse - 84 0 Recurse - 86 41 KetRmax - 88 3 CBra 2 - 91 3 Ket - 93 3 CBra 3 - 96 3 Ket - 98 3 CBra 4 -101 3 Ket -103 3 CBra 5 -106 3 Ket -108 3 CBra 6 -111 3 Ket -113 3 CBra 7 -116 3 Ket -118 3 CBra 8 -121 3 Ket -123 3 CBra 9 -126 3 Ket -128 3 CBra 10 -131 3 Ket -133 133 Ket -135 End ------------------------------------------------------------------- -Capture group count = 10 -May match empty string -Subject length lower bound = 0 - -/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ -Failed: error 114 at offset 509: missing closing parenthesis - -/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode - -#pattern -fullbincode - -/\[()]{65535}/expand - -# End of testinput8 diff --git a/testdata/testoutput8-32-3 b/testdata/testoutput8-32-3 deleted file mode 100644 index e9865c8..0000000 --- a/testdata/testoutput8-32-3 +++ /dev/null @@ -1,1021 +0,0 @@ -# There are two sorts of patterns in this test. A number of them are -# representative patterns whose lengths and offsets are checked. This is just a -# doublecheck test to ensure the sizes don't go horribly wrong when something -# is changed. The operation of these patterns is checked in other tests. -# -# This file also contains tests whose output varies with code unit size and/or -# link size. Unicode support is required for these tests. There are separate -# output files for each code unit size and link size. - -#pattern fullbincode,memory - -/((?i)b)/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 5 CBra 1 - 5 /i b - 7 5 Ket - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/(?s)(.*X|^B)/ -Memory allocation - code size : 76 ------------------------------------------------------------------- - 0 16 Bra - 2 7 CBra 1 - 5 AllAny* - 7 X - 9 5 Alt - 11 ^ - 12 B - 14 12 Ket - 16 16 Ket - 18 End ------------------------------------------------------------------- - -/(?s:.*X|^B)/ -Memory allocation - code size : 72 ------------------------------------------------------------------- - 0 15 Bra - 2 6 Bra - 4 AllAny* - 6 X - 8 5 Alt - 10 ^ - 11 B - 13 11 Ket - 15 15 Ket - 17 End ------------------------------------------------------------------- - -/^[[:alnum:]]/ -Memory allocation - code size : 60 ------------------------------------------------------------------- - 0 12 Bra - 2 ^ - 3 [0-9A-Za-z] - 12 12 Ket - 14 End ------------------------------------------------------------------- - -/#/Ix -Memory allocation - code size : 20 ------------------------------------------------------------------- - 0 2 Bra - 2 2 Ket - 4 End ------------------------------------------------------------------- -Capture group count = 0 -May match empty string -Options: extended -Subject length lower bound = 0 - -/a#/Ix -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 a - 4 4 Ket - 6 End ------------------------------------------------------------------- -Capture group count = 0 -Options: extended -First code unit = 'a' -Subject length lower bound = 1 - -/x?+/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 x?+ - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/x++/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 x++ - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/x{1,3}+/ -Memory allocation - code size : 40 ------------------------------------------------------------------- - 0 7 Bra - 2 x - 4 x{0,2}+ - 7 7 Ket - 9 End ------------------------------------------------------------------- - -/(x)*+/ -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 Braposzero - 3 5 CBraPos 1 - 6 x - 8 5 KetRpos - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/^((a+)(?U)([ab]+)(?-U)([bc]+)(\w*))/ -Memory allocation - code size : 220 ------------------------------------------------------------------- - 0 52 Bra - 2 ^ - 3 47 CBra 1 - 6 5 CBra 2 - 9 a+ - 11 5 Ket - 13 13 CBra 3 - 16 [ab]+? - 26 13 Ket - 28 13 CBra 4 - 31 [bc]+ - 41 13 Ket - 43 5 CBra 5 - 46 \w*+ - 48 5 Ket - 50 47 Ket - 52 52 Ket - 54 End ------------------------------------------------------------------- - -"8J\$WE\<\.rX\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b" -Memory allocation - code size : 3296 ------------------------------------------------------------------- - 0 821 Bra - 2 8J$WE<.rX+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDDqmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X -820 \b -821 821 Ket -823 End ------------------------------------------------------------------- - -"\$\<\.X\+ix\[d1b\!H\#\?vV0vrK\:ZH1\=2M\>iV\;\?aPhFB\<\*vW\@QW\@sO9\}cfZA\-i\'w\%hKd6gt1UJP\,15_\#QY\$M\^Mss_U\/\]\&LK9\[5vQub\^w\[KDD\qmj\;2\}YWFdYx\.Ap\]hjCPTP\(n28k\+3\;o\&WXqs\/gOXdr\$\:r\'do0\;b4c\(f_Gr\=\"\\4\)\[01T7ajQJvL\$W\~mL_sS\/4h\:x\*\[ZN\=KLs\&L5zX\/\/\>it\,o\:aU\(\;Z\>pW\&T7oP\'2K\^E\:x9\'c\[\%z\-\,64JQ5AeH_G\#KijUKghQw\^\\vea3a\?kka_G\$8\#\`\*kynsxzBLru\'\]k_\[7FrVx\}\^\=\$blx\>s\-N\%j\;D\*aZDnsw\:YKZ\%Q\.Kne9\#hP\?\+b3\(SOvL\,\^\;\&u5\@\?5C5Bhb\=m\-vEh_L15Jl\]U\)0RP6\{q\%L\^_z5E\'Dw6X\b" -Memory allocation - code size : 3256 ------------------------------------------------------------------- - 0 811 Bra - 2 $<.X+ix[d1b!H#?vV0vrK:ZH1=2M>iV;?aPhFB<*vW@QW@sO9}cfZA-i'w%hKd6gt1UJP,15_#QY$M^Mss_U/]&LK9[5vQub^w[KDDqmj;2}YWFdYx.Ap]hjCPTP(n28k+3;o&WXqs/gOXdr$:r'do0;b4c(f_Gr="\4)[01T7ajQJvL$W~mL_sS/4h:x*[ZN=KLs&L5zX//>it,o:aU(;Z>pW&T7oP'2K^E:x9'c[%z-,64JQ5AeH_G#KijUKghQw^\vea3a?kka_G$8#`*kynsxzBLru']k_[7FrVx}^=$blx>s-N%j;D*aZDnsw:YKZ%Q.Kne9#hP?+b3(SOvL,^;&u5@?5C5Bhb=m-vEh_L15Jl]U)0RP6{q%L^_z5E'Dw6X -810 \b -811 811 Ket -813 End ------------------------------------------------------------------- - -/(a(?1)b)/ -Memory allocation - code size : 64 ------------------------------------------------------------------- - 0 13 Bra - 2 9 CBra 1 - 5 a - 7 2 Recurse - 9 b - 11 9 Ket - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/(a(?1)+b)/ -Memory allocation - code size : 80 ------------------------------------------------------------------- - 0 17 Bra - 2 13 CBra 1 - 5 a - 7 4 SBra - 9 2 Recurse - 11 4 KetRmax - 13 b - 15 13 Ket - 17 17 Ket - 19 End ------------------------------------------------------------------- - -/a(?Pb|c)d(?Pe)/ -Memory allocation - code size : 108 -Memory allocation - data size : 104 ------------------------------------------------------------------- - 0 24 Bra - 2 a - 4 5 CBra 1 - 7 b - 9 4 Alt - 11 c - 13 9 Ket - 15 d - 17 5 CBra 2 - 20 e - 22 5 Ket - 24 24 Ket - 26 End ------------------------------------------------------------------- - -/(?:a(?Pc(?Pd)))(?Pa)/ -Memory allocation - code size : 128 -Memory allocation - data size : 36 ------------------------------------------------------------------- - 0 29 Bra - 2 18 Bra - 4 a - 6 12 CBra 1 - 9 c - 11 5 CBra 2 - 14 d - 16 5 Ket - 18 12 Ket - 20 18 Ket - 22 5 CBra 3 - 25 a - 27 5 Ket - 29 29 Ket - 31 End ------------------------------------------------------------------- - -/(?Pa)...(?P=a)bbb(?P>a)d/ -Memory allocation - code size : 108 -Memory allocation - data size : 12 ------------------------------------------------------------------- - 0 24 Bra - 2 5 CBra 1 - 5 a - 7 5 Ket - 9 Any - 10 Any - 11 Any - 12 \1 - 14 bbb - 20 2 Recurse - 22 d - 24 24 Ket - 26 End ------------------------------------------------------------------- - -/abc(?C255)de(?C)f/ -Memory allocation - code size : 100 ------------------------------------------------------------------- - 0 22 Bra - 2 abc - 8 Callout 255 10 1 - 12 de - 16 Callout 0 16 1 - 20 f - 22 22 Ket - 24 End ------------------------------------------------------------------- - -/abcde/auto_callout -Memory allocation - code size : 156 ------------------------------------------------------------------- - 0 36 Bra - 2 Callout 255 0 1 - 6 a - 8 Callout 255 1 1 - 12 b - 14 Callout 255 2 1 - 18 c - 20 Callout 255 3 1 - 24 d - 26 Callout 255 4 1 - 30 e - 32 Callout 255 5 0 - 36 36 Ket - 38 End ------------------------------------------------------------------- - -/\x{100}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{1000}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{1000} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{10000}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{10000} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{100000}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100000} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{10ffff}/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{10ffff} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{110000}/utf -Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large - -/[\x{ff}]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{ff} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[\x{100}]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x80/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{80} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\xff/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{ff} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/\x{0041}\x{2262}\x{0391}\x{002e}/I,utf -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 A\x{2262}\x{391}. - 10 10 Ket - 12 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = 'A' -Last code unit = '.' -Subject length lower bound = 4 - -/\x{D55c}\x{ad6d}\x{C5B4}/I,utf -Memory allocation - code size : 44 ------------------------------------------------------------------- - 0 8 Bra - 2 \x{d55c}\x{ad6d}\x{c5b4} - 8 8 Ket - 10 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = \x{d55c} -Last code unit = \x{c5b4} -Subject length lower bound = 3 - -/\x{65e5}\x{672c}\x{8a9e}/I,utf -Memory allocation - code size : 44 ------------------------------------------------------------------- - 0 8 Bra - 2 \x{65e5}\x{672c}\x{8a9e} - 8 8 Ket - 10 End ------------------------------------------------------------------- -Capture group count = 0 -Options: utf -First code unit = \x{65e5} -Last code unit = \x{8a9e} -Subject length lower bound = 3 - -/[\x{100}]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{100} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[Z\x{100}]/utf -Memory allocation - code size : 76 ------------------------------------------------------------------- - 0 16 Bra - 2 [Z\x{100}] - 16 16 Ket - 18 End ------------------------------------------------------------------- - -/^[\x{100}\E-\Q\E\x{150}]/utf -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 ^ - 3 [\x{100}-\x{150}] - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/^[\QĀ\E-\QŐ\E]/utf -Memory allocation - code size : 52 ------------------------------------------------------------------- - 0 10 Bra - 2 ^ - 3 [\x{100}-\x{150}] - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/^[\QĀ\E-\QŐ\E/utf -Failed: error 106 at offset 13: missing terminating ] for character class - -/[\p{L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\p{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\p{^L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\P{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\P{L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\P{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\P{^L}]/ -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\p{L}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[abc\p{L}\x{0660}]/utf -Memory allocation - code size : 88 ------------------------------------------------------------------- - 0 19 Bra - 2 [A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\xff\p{L}\x{660}] - 19 19 Ket - 21 End ------------------------------------------------------------------- - -/[\p{Nd}]/utf -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\p{Nd}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[\p{Nd}+-]+/utf -Memory allocation - code size : 84 ------------------------------------------------------------------- - 0 18 Bra - 2 [+\-0-9\p{Nd}]++ - 18 18 Ket - 20 End ------------------------------------------------------------------- - -/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/i,utf -Memory allocation - code size : 60 ------------------------------------------------------------------- - 0 12 Bra - 2 /i A\x{391}\x{10427}\x{ff3a}\x{1fb0} - 12 12 Ket - 14 End ------------------------------------------------------------------- - -/A\x{391}\x{10427}\x{ff3a}\x{1fb0}/utf -Memory allocation - code size : 60 ------------------------------------------------------------------- - 0 12 Bra - 2 A\x{391}\x{10427}\x{ff3a}\x{1fb0} - 12 12 Ket - 14 End ------------------------------------------------------------------- - -/[\x{105}-\x{109}]/i,utf -Memory allocation - code size : 48 ------------------------------------------------------------------- - 0 9 Bra - 2 [\x{104}-\x{109}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/( ( (?(1)0|) )* )/x -Memory allocation - code size : 104 ------------------------------------------------------------------- - 0 23 Bra - 2 19 CBra 1 - 5 Brazero - 6 13 SCBra 2 - 9 6 Cond - 11 1 Capture ref - 13 0 - 15 2 Alt - 17 8 Ket - 19 13 KetRmax - 21 19 Ket - 23 23 Ket - 25 End ------------------------------------------------------------------- - -/( (?(1)0|)* )/x -Memory allocation - code size : 84 ------------------------------------------------------------------- - 0 18 Bra - 2 14 CBra 1 - 5 Brazero - 6 6 SCond - 8 1 Capture ref - 10 0 - 12 2 Alt - 14 8 KetRmax - 16 14 Ket - 18 18 Ket - 20 End ------------------------------------------------------------------- - -/[a]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 a - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[a]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 a - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[\xaa]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{aa} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[\xaa]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 \x{aa} - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^a]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^a] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^a]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^a] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^\xaa]/ -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^\x{aa}] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -/[^\xaa]/utf -Memory allocation - code size : 28 ------------------------------------------------------------------- - 0 4 Bra - 2 [^\x{aa}] (not) - 4 4 Ket - 6 End ------------------------------------------------------------------- - -#pattern -memory - -/[^\d]/utf,ucp ------------------------------------------------------------------- - 0 9 Bra - 2 [^\p{Nd}] - 9 9 Ket - 11 End ------------------------------------------------------------------- - -/[[:^alpha:][:^cntrl:]]+/utf,ucp ------------------------------------------------------------------- - 0 13 Bra - 2 [\P{L}\P{Cc}]++ - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/[[:^cntrl:][:^alpha:]]+/utf,ucp ------------------------------------------------------------------- - 0 13 Bra - 2 [\P{Cc}\P{L}]++ - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/[[:alpha:]]+/utf,ucp ------------------------------------------------------------------- - 0 10 Bra - 2 [\p{L}]++ - 10 10 Ket - 12 End ------------------------------------------------------------------- - -/[[:^alpha:]\S]+/utf,ucp ------------------------------------------------------------------- - 0 13 Bra - 2 [\P{L}\P{Xsp}]++ - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/abc(d|e)(*THEN)x(123(*THEN)4|567(b|q)(*THEN)xx)/ ------------------------------------------------------------------- - 0 60 Bra - 2 abc - 8 5 CBra 1 - 11 d - 13 4 Alt - 15 e - 17 9 Ket - 19 *THEN - 20 x - 22 12 CBra 2 - 25 123 - 31 *THEN - 32 4 - 34 24 Alt - 36 567 - 42 5 CBra 3 - 45 b - 47 4 Alt - 49 q - 51 9 Ket - 53 *THEN - 54 xx - 58 36 Ket - 60 60 Ket - 62 End ------------------------------------------------------------------- - -/(((a\2)|(a*)\g<-1>))*a?/ ------------------------------------------------------------------- - 0 35 Bra - 2 Brazero - 3 28 SCBra 1 - 6 12 CBra 2 - 9 7 CBra 3 - 12 a - 14 \2 - 16 7 Ket - 18 11 Alt - 20 5 CBra 4 - 23 a* - 25 5 Ket - 27 20 Recurse - 29 23 Ket - 31 28 KetRmax - 33 a?+ - 35 35 Ket - 37 End ------------------------------------------------------------------- - -/((?+1)(\1))/ ------------------------------------------------------------------- - 0 16 Bra - 2 12 CBra 1 - 5 7 Recurse - 7 5 CBra 2 - 10 \1 - 12 5 Ket - 14 12 Ket - 16 16 Ket - 18 End ------------------------------------------------------------------- - -"(?1)(?#?'){2}(a)" ------------------------------------------------------------------- - 0 13 Bra - 2 6 Recurse - 4 6 Recurse - 6 5 CBra 1 - 9 a - 11 5 Ket - 13 13 Ket - 15 End ------------------------------------------------------------------- - -/.((?2)(?R)|\1|$)()/ ------------------------------------------------------------------- - 0 24 Bra - 2 Any - 3 7 CBra 1 - 6 19 Recurse - 8 0 Recurse - 10 4 Alt - 12 \1 - 14 3 Alt - 16 $ - 17 14 Ket - 19 3 CBra 2 - 22 3 Ket - 24 24 Ket - 26 End ------------------------------------------------------------------- - -/.((?3)(?R)()(?2)|\1|$)()/ ------------------------------------------------------------------- - 0 31 Bra - 2 Any - 3 14 CBra 1 - 6 26 Recurse - 8 0 Recurse - 10 3 CBra 2 - 13 3 Ket - 15 10 Recurse - 17 4 Alt - 19 \1 - 21 3 Alt - 23 $ - 24 21 Ket - 26 3 CBra 3 - 29 3 Ket - 31 31 Ket - 33 End ------------------------------------------------------------------- - -/(?1)()((((((\1++))\x85)+)|))/ ------------------------------------------------------------------- - 0 50 Bra - 2 4 Recurse - 4 3 CBra 1 - 7 3 Ket - 9 39 CBra 2 - 12 32 CBra 3 - 15 27 CBra 4 - 18 22 CBra 5 - 21 15 CBra 6 - 24 10 CBra 7 - 27 5 Once - 29 \1+ - 32 5 Ket - 34 10 Ket - 36 15 Ket - 38 \x{85} - 40 22 KetRmax - 42 27 Ket - 44 2 Alt - 46 34 Ket - 48 39 Ket - 50 50 Ket - 52 End ------------------------------------------------------------------- - -# Check the absolute limit on nesting (?| etc. This varies with code unit -# width because the workspace is a different number of bytes. It will fail -# with link size 2 in 8-bit and 16-bit but not in 32-bit. - -/(?|(?|(?J:(?|(?x:(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?|(?| -))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) -/parens_nest_limit=1000,-fullbincode - -# Use "expand" to create some very long patterns with nested parentheses, in -# order to test workspace overflow. Again, this varies with code unit width, -# and even when it fails in two modes, the error offset differs. It also varies -# with link size - hence multiple tests with different values. - -/(?'ABC'\[[bar](]{792}*THEN:\[A]{255}\[)]{793}/expand,-fullbincode,parens_nest_limit=1000 - -/(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 - -/(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated - -/(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------- - 0 79 Bra - 2 70 Once - 4 6 Cond - 6 1 Capture ref - 8 74 Recurse - 10 6 Ket - 12 6 Cond - 14 1 Capture ref - 16 74 Recurse - 18 6 Ket - 20 6 Cond - 22 1 Capture ref - 24 74 Recurse - 26 6 Ket - 28 6 Cond - 30 1 Capture ref - 32 74 Recurse - 34 6 Ket - 36 6 Cond - 38 1 Capture ref - 40 74 Recurse - 42 6 Ket - 44 6 Cond - 46 1 Capture ref - 48 74 Recurse - 50 6 Ket - 52 6 Cond - 54 1 Capture ref - 56 74 Recurse - 58 6 Ket - 60 10 SBraPos - 62 6 SCond - 64 1 Capture ref - 66 74 Recurse - 68 6 Ket - 70 10 KetRpos - 72 70 Ket - 74 3 CBra 1 - 77 3 Ket - 79 79 Ket - 81 End ------------------------------------------------------------------- -Capture group count = 1 -Max back reference = 1 -May match empty string -Subject length lower bound = 0 - abcd - 0: - 1: - -/(?(1)|a(?1)b){2,}+()/debug ------------------------------------------------------------------- - 0 43 Bra - 2 34 Once - 4 4 Cond - 6 1 Capture ref - 8 8 Alt - 10 a - 12 38 Recurse - 14 b - 16 12 Ket - 18 16 SBraPos - 20 4 SCond - 22 1 Capture ref - 24 8 Alt - 26 a - 28 38 Recurse - 30 b - 32 12 Ket - 34 16 KetRpos - 36 34 Ket - 38 3 CBra 1 - 41 3 Ket - 43 43 Ket - 45 End ------------------------------------------------------------------- -Capture group count = 1 -Max back reference = 1 -May match empty string -Subject length lower bound = 0 - abcde -No match - -/((?1)(?2)(?3)(?4)(?5)(?6)(?7)(?8)(?9)(?9)(?8)(?7)(?6)(?5)(?4)(?3)(?2)(?1)(?0)){2,}()()()()()()()()()/debug ------------------------------------------------------------------- - 0 133 Bra - 2 41 CBra 1 - 5 2 Recurse - 7 88 Recurse - 9 93 Recurse - 11 98 Recurse - 13 103 Recurse - 15 108 Recurse - 17 113 Recurse - 19 118 Recurse - 21 123 Recurse - 23 123 Recurse - 25 118 Recurse - 27 113 Recurse - 29 108 Recurse - 31 103 Recurse - 33 98 Recurse - 35 93 Recurse - 37 88 Recurse - 39 2 Recurse - 41 0 Recurse - 43 41 Ket - 45 41 SCBra 1 - 48 2 Recurse - 50 88 Recurse - 52 93 Recurse - 54 98 Recurse - 56 103 Recurse - 58 108 Recurse - 60 113 Recurse - 62 118 Recurse - 64 123 Recurse - 66 123 Recurse - 68 118 Recurse - 70 113 Recurse - 72 108 Recurse - 74 103 Recurse - 76 98 Recurse - 78 93 Recurse - 80 88 Recurse - 82 2 Recurse - 84 0 Recurse - 86 41 KetRmax - 88 3 CBra 2 - 91 3 Ket - 93 3 CBra 3 - 96 3 Ket - 98 3 CBra 4 -101 3 Ket -103 3 CBra 5 -106 3 Ket -108 3 CBra 6 -111 3 Ket -113 3 CBra 7 -116 3 Ket -118 3 CBra 8 -121 3 Ket -123 3 CBra 9 -126 3 Ket -128 3 CBra 10 -131 3 Ket -133 133 Ket -135 End ------------------------------------------------------------------- -Capture group count = 10 -May match empty string -Subject length lower bound = 0 - -/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ -Failed: error 114 at offset 509: missing closing parenthesis - -/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode - -#pattern -fullbincode - -/\[()]{65535}/expand - -# End of testinput8 diff --git a/testdata/testoutput8-32-4 b/testdata/testoutput8-32-4 index e9865c8..670e55a 100644 --- a/testdata/testoutput8-32-4 +++ b/testdata/testoutput8-32-4 @@ -247,7 +247,7 @@ Memory allocation - data size : 12 9 Any 10 Any 11 Any - 12 \1 + 12 \g{1} 14 bbb 20 2 Recurse 22 d @@ -334,6 +334,7 @@ Memory allocation - code size : 28 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /[\x{ff}]/utf Memory allocation - code size : 28 @@ -453,6 +454,7 @@ Memory allocation - code size : 52 /^[\QĀ\E-\QŐ\E/utf Failed: error 106 at offset 13: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /[\p{L}]/ Memory allocation - code size : 48 @@ -729,7 +731,7 @@ Memory allocation - code size : 28 6 12 CBra 2 9 7 CBra 3 12 a - 14 \2 + 14 \g{2} 16 7 Ket 18 11 Alt 20 5 CBra 4 @@ -749,7 +751,7 @@ Memory allocation - code size : 28 2 12 CBra 1 5 7 Recurse 7 5 CBra 2 - 10 \1 + 10 \g{1} 12 5 Ket 14 12 Ket 16 16 Ket @@ -776,7 +778,7 @@ Memory allocation - code size : 28 6 19 Recurse 8 0 Recurse 10 4 Alt - 12 \1 + 12 \g{1} 14 3 Alt 16 $ 17 14 Ket @@ -797,7 +799,7 @@ Memory allocation - code size : 28 13 3 Ket 15 10 Recurse 17 4 Alt - 19 \1 + 19 \g{1} 21 3 Alt 23 $ 24 21 Ket @@ -820,7 +822,7 @@ Memory allocation - code size : 28 21 15 CBra 6 24 10 CBra 7 27 5 Once - 29 \1+ + 29 \g{1}+ 32 5 Ket 34 10 Ket 36 15 Ket @@ -852,7 +854,7 @@ Memory allocation - code size : 28 /(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 /(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated +Failed: error 186 at offset 0: regular expression is too complicated /(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------ @@ -1011,6 +1013,7 @@ Subject length lower bound = 0 /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ Failed: error 114 at offset 509: missing closing parenthesis + here: ...](*ACCEPT) |<--| /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode diff --git a/testdata/testoutput8-8-2 b/testdata/testoutput8-8-2 index 0ebc4d0..13b976e 100644 --- a/testdata/testoutput8-8-2 +++ b/testdata/testoutput8-8-2 @@ -247,7 +247,7 @@ Memory allocation - data size : 4 13 Any 14 Any 15 Any - 16 \1 + 16 \g{1} 19 bbb 25 3 Recurse 28 d @@ -334,6 +334,7 @@ Memory allocation - code size : 12 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /[\x{ff}]/utf Memory allocation - code size : 10 @@ -453,6 +454,7 @@ Memory allocation - code size : 18 /^[\QĀ\E-\QŐ\E/utf Failed: error 106 at offset 15: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /[\p{L}]/ Memory allocation - code size : 15 @@ -729,7 +731,7 @@ Memory allocation - code size : 10 9 18 CBra 2 14 10 CBra 3 19 a - 21 \2 + 21 \g{2} 24 10 Ket 27 16 Alt 30 7 CBra 4 @@ -749,7 +751,7 @@ Memory allocation - code size : 10 3 19 CBra 1 8 11 Recurse 11 8 CBra 2 - 16 \1 + 16 \g{1} 19 8 Ket 22 19 Ket 25 25 Ket @@ -776,7 +778,7 @@ Memory allocation - code size : 10 9 28 Recurse 12 0 Recurse 15 6 Alt - 18 \1 + 18 \g{1} 21 4 Alt 24 $ 25 21 Ket @@ -797,7 +799,7 @@ Memory allocation - code size : 10 20 5 Ket 23 15 Recurse 26 6 Alt - 29 \1 + 29 \g{1} 32 4 Alt 35 $ 36 32 Ket @@ -820,7 +822,7 @@ Memory allocation - code size : 10 34 23 CBra 6 39 15 CBra 7 44 7 Once - 47 \1+ + 47 \g{1}+ 51 7 Ket 54 15 Ket 57 23 Ket @@ -842,6 +844,7 @@ Memory allocation - code size : 10 ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) /parens_nest_limit=1000,-fullbincode Failed: error 184 at offset 1129: (?| and/or (?J: or (?x: parentheses are too deeply nested + here: ...?|(?|(?|(? |-->| |(?|(?|(?|... # Use "expand" to create some very long patterns with nested parentheses, in # order to test workspace overflow. Again, this varies with code unit width, @@ -853,7 +856,7 @@ Failed: error 184 at offset 1129: (?| and/or (?J: or (?x: parentheses are too de /(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 /(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated +Failed: error 186 at offset 0: regular expression is too complicated /(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------ @@ -1012,12 +1015,13 @@ Subject length lower bound = 0 /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ Failed: error 114 at offset 509: missing closing parenthesis + here: ...](*ACCEPT) |<--| /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode #pattern -fullbincode /\[()]{65535}/expand -Failed: error 120 at offset 131070: regular expression is too large +Failed: error 120 at offset 0: regular expression is too large # End of testinput8 diff --git a/testdata/testoutput8-8-3 b/testdata/testoutput8-8-3 index 04b3a3e..8c0abe1 100644 --- a/testdata/testoutput8-8-3 +++ b/testdata/testoutput8-8-3 @@ -247,7 +247,7 @@ Memory allocation - data size : 4 16 Any 17 Any 18 Any - 19 \1 + 19 \g{1} 22 bbb 28 4 Recurse 32 d @@ -334,6 +334,7 @@ Memory allocation - code size : 14 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /[\x{ff}]/utf Memory allocation - code size : 12 @@ -453,6 +454,7 @@ Memory allocation - code size : 21 /^[\QĀ\E-\QŐ\E/utf Failed: error 106 at offset 15: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /[\p{L}]/ Memory allocation - code size : 18 @@ -729,7 +731,7 @@ Memory allocation - code size : 12 11 21 CBra 2 17 11 CBra 3 23 a - 25 \2 + 25 \g{2} 28 11 Ket 32 20 Alt 36 8 CBra 4 @@ -749,7 +751,7 @@ Memory allocation - code size : 12 4 23 CBra 1 10 14 Recurse 14 9 CBra 2 - 20 \1 + 20 \g{1} 23 9 Ket 27 23 Ket 31 31 Ket @@ -776,7 +778,7 @@ Memory allocation - code size : 12 11 35 Recurse 15 0 Recurse 19 7 Alt - 23 \1 + 23 \g{1} 26 5 Alt 30 $ 31 26 Ket @@ -797,7 +799,7 @@ Memory allocation - code size : 12 25 6 Ket 29 19 Recurse 33 7 Alt - 37 \1 + 37 \g{1} 40 5 Alt 44 $ 45 40 Ket @@ -820,7 +822,7 @@ Memory allocation - code size : 12 42 28 CBra 6 48 18 CBra 7 54 8 Once - 58 \1+ + 58 \g{1}+ 62 8 Ket 66 18 Ket 70 28 Ket @@ -852,7 +854,7 @@ Memory allocation - code size : 12 /(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 /(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated +Failed: error 186 at offset 0: regular expression is too complicated /(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------ @@ -1011,6 +1013,7 @@ Subject length lower bound = 0 /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ Failed: error 114 at offset 509: missing closing parenthesis + here: ...](*ACCEPT) |<--| /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode diff --git a/testdata/testoutput8-8-4 b/testdata/testoutput8-8-4 index 42119f7..3377845 100644 --- a/testdata/testoutput8-8-4 +++ b/testdata/testoutput8-8-4 @@ -247,7 +247,7 @@ Memory allocation - data size : 4 19 Any 20 Any 21 Any - 22 \1 + 22 \g{1} 25 bbb 31 5 Recurse 36 d @@ -334,6 +334,7 @@ Memory allocation - code size : 16 /\x{110000}/utf Failed: error 134 at offset 9: character code point value in \x{} or \o{} is too large + here: \x{110000 |<--| } /[\x{ff}]/utf Memory allocation - code size : 14 @@ -453,6 +454,7 @@ Memory allocation - code size : 24 /^[\QĀ\E-\QŐ\E/utf Failed: error 106 at offset 15: missing terminating ] for character class + here: ...QĀ\E-\QŐ\E |<--| /[\p{L}]/ Memory allocation - code size : 21 @@ -729,7 +731,7 @@ Memory allocation - code size : 14 13 24 CBra 2 20 12 CBra 3 27 a - 29 \2 + 29 \g{2} 32 12 Ket 37 24 Alt 42 9 CBra 4 @@ -749,7 +751,7 @@ Memory allocation - code size : 14 5 27 CBra 1 12 17 Recurse 17 10 CBra 2 - 24 \1 + 24 \g{1} 27 10 Ket 32 27 Ket 37 37 Ket @@ -776,7 +778,7 @@ Memory allocation - code size : 14 13 42 Recurse 18 0 Recurse 23 8 Alt - 28 \1 + 28 \g{1} 31 6 Alt 36 $ 37 31 Ket @@ -797,7 +799,7 @@ Memory allocation - code size : 14 30 7 Ket 35 23 Recurse 40 8 Alt - 45 \1 + 45 \g{1} 48 6 Alt 53 $ 54 48 Ket @@ -820,7 +822,7 @@ Memory allocation - code size : 14 50 33 CBra 6 57 21 CBra 7 64 9 Once - 69 \1+ + 69 \g{1}+ 73 9 Ket 78 21 Ket 83 33 Ket @@ -852,7 +854,7 @@ Memory allocation - code size : 14 /(?'ABC'\[[bar](]{793}*THEN:\[A]{255}\[)]{794}/expand,-fullbincode,parens_nest_limit=1000 /(?'ABC'\[[bar](]{1793}*THEN:\[A]{255}\[)]{1794}/expand,-fullbincode,parens_nest_limit=2000 -Failed: error 186 at offset 12820: regular expression is too complicated +Failed: error 186 at offset 0: regular expression is too complicated /(?(1)(?1)){8,}+()/debug ------------------------------------------------------------------ @@ -1011,6 +1013,7 @@ Subject length lower bound = 0 /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/ Failed: error 114 at offset 509: missing closing parenthesis + here: ...](*ACCEPT) |<--| /([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))/-fullbincode diff --git a/testdata/testoutput9 b/testdata/testoutput9 index 7845dc1..df0daab 100644 --- a/testdata/testoutput9 +++ b/testdata/testoutput9 @@ -4,6 +4,8 @@ #forbid_utf #newline_default lf any anycrlf +#if !ebcdic + /a\xc4\xa3b/ a\N{U+123}b 0: a\xc4\xa3b @@ -36,11 +38,17 @@ Subject length lower bound = 6 ** Truncation will probably give the wrong result. No match +#endif + /\x{100}/I Failed: error 134 at offset 6: character code point value in \x{} or \o{} is too large + here: \x{100 |<--| } /\o{400}/I Failed: error 134 at offset 6: character code point value in \x{} or \o{} is too large + here: \o{400 |<--| } + +#if !ebcdic / (?: [\040\t] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] | \( (?: [^\\\x80-\xff\n\015()] | \\ [^\x80-\xff] )* \) )* @@ -244,6 +252,8 @@ Starting code units: \x09 \x20 ! " # $ % & ' ( * + - / 0 1 2 3 4 5 6 7 8 f g h i j k l m n o p q r s t u v w x y z { | } ~ \x7f Subject length lower bound = 3 +#endif + /\h/I Capture group count = 0 Starting code units: \x09 \x20 \xa0 @@ -319,6 +329,8 @@ Subject length lower bound = 1 End ------------------------------------------------------------------ +#if !ebcdic + /[\x0a\V]/B ------------------------------------------------------------------ Bra @@ -327,15 +339,20 @@ Subject length lower bound = 1 End ------------------------------------------------------------------ +#endif + /\777/I Failed: error 151 at offset 4: octal value is greater than \377 in 8-bit non-UTF-8 mode + here: \777 |<--| /(*:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF)XX/mark Failed: error 176 at offset 259: name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN) + here: ...6789ABCDEF |<--| )XX XX /(*:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF)XX/mark,alt_verbnames Failed: error 176 at offset 259: name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN) + here: ...6789ABCDEF |<--| )XX XX /(*:0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE)XX/mark @@ -350,9 +367,13 @@ MK: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789AB /\u0100/alt_bsux,allow_empty_class,match_unset_backref,dupnames Failed: error 177 at offset 6: character code point value in \u.... sequence is too large + here: \u0100 |<--| /[\u0100-\u0200]/alt_bsux,allow_empty_class,match_unset_backref,dupnames Failed: error 177 at offset 7: character code point value in \u.... sequence is too large + here: [\u0100 |<--| -\u0200] + +#if !ebcdic /[^\x00-a]{12,}[^b-\xff]*/B ------------------------------------------------------------------ @@ -363,6 +384,8 @@ Failed: error 177 at offset 7: character code point value in \u.... sequence is End ------------------------------------------------------------------ +#endif + /[^\s]*\s* [^\W]+\W+ [^\d]*?\d0 [^\d\w]{4,6}?\w*A/B ------------------------------------------------------------------ Bra @@ -384,23 +407,28 @@ Failed: error 177 at offset 7: character code point value in \u.... sequence is /(*MARK:a\x{100}b)z/alt_verbnames Failed: error 134 at offset 14: character code point value in \x{} or \o{} is too large + here: ...RK:a\x{100 |<--| }b)z /(*:*++++++++++++''''''''''''''''''''+''+++'+++x+++++++++++++++++++++++++++++++++++(++++++++++++++++++++:++++++%++:''''''''''''''''''''''''+++++++++++++++++++++++++++++++++++++++++++++++++++++-++++++++k+++++++''''+++'+++++++++++++++++++++++''''++++++++++++':Æ¿)/ Failed: error 176 at offset 259: name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN) + here: ...++++++':Æ¿ |<--| ) /(?i:A{1,}\6666666666)/ Failed: error 151 at offset 13: octal value is greater than \377 in 8-bit non-UTF-8 mode + here: ...:A{1,}\666 |<--| 6666666) A\x{1b6}6666666 # Should cause an error /abc/substitute_extended,replace=>\777< abc Failed: error -57 at offset 5 in replacement: bad escape sequence in replacement string + here: >\777 |<--| < # Should cause an error /abc/substitute_extended,replace=>\o{012345}< abc Failed: error -57 at offset 10 in replacement: bad escape sequence in replacement string + here: >\o{012345 |<--| }< /i/turkish_casing Failed: error 204 at offset 0: PCRE2_EXTRA_TURKISH_CASING require Unicode (UTF or UCP) mode diff --git a/testdata/testoutputEBC b/testdata/testoutputEBC deleted file mode 100644 index 4edc8f9..0000000 --- a/testdata/testoutputEBC +++ /dev/null @@ -1,206 +0,0 @@ -PCRE2 version 10.32-RC1 2018-02-19 -# This is a specialized test for checking, when PCRE2 is compiled with the -# EBCDIC option but in an ASCII environment, that newline, white space, and \c -# functionality is working. It catches cases where explicit values such as 0x0a -# have been used instead of names like CHAR_LF. Needless to say, it is not a -# genuine EBCDIC test! In patterns, alphabetic characters that follow a -# backslash must be in EBCDIC code. In data, NL, NEL, LF, ESC, and DEL must be -# in EBCDIC, but can of course be specified as escapes. - -# Test default newline and variations - -/^A/m - ABC - 0: A - 12\x15ABC - 0: A - -/^A/m,newline=any - 12\x15ABC - 0: A - 12\x0dABC - 0: A - 12\x0d\x15ABC - 0: A - 12\x25ABC - 0: A - -/^A/m,newline=anycrlf - 12\x15ABC - 0: A - 12\x0dABC - 0: A - 12\x0d\x15ABC - 0: A - ** Fail -No match - 12\x25ABC -No match - -# Test \h - -/^A\ˆ/ - A B - 0: A\x20 - A\x41B - 0: AA - -# Test \H - -/^A\È/ - AB - 0: AB - A\x42B - 0: AB - ** Fail -No match - A B -No match - A\x41B -No match - -# Test \R - -/^A\Ù/ - A\x15B - 0: A\x15 - A\x0dB - 0: A\x0d - A\x25B - 0: A\x25 - A\x0bB - 0: A\x0b - A\x0cB - 0: A\x0c - ** Fail -No match - A B -No match - -# Test \v - -/^A\¥/ - A\x15B - 0: A\x15 - A\x0dB - 0: A\x0d - A\x25B - 0: A\x25 - A\x0bB - 0: A\x0b - A\x0cB - 0: A\x0c - ** Fail -No match - A B -No match - -# Test \V - -/^A\å/ - A B - 0: A\x20 - ** Fail -No match - A\x15B -No match - A\x0dB -No match - A\x25B -No match - A\x0bB -No match - A\x0cB -No match - -# For repeated items, use an atomic group so that the output is the same -# for DFA matching (otherwise it may show multiple matches). - -# Test \h+ - -/^A(?>\ˆ+)/ - A B - 0: A\x20 - -# Test \H+ - -/^A(?>\È+)/ - AB - 0: AB - ** Fail -No match - A B -No match - -# Test \R+ - -/^A(?>\Ù+)/ - A\x15B - 0: A\x15 - A\x0dB - 0: A\x0d - A\x25B - 0: A\x25 - A\x0bB - 0: A\x0b - A\x0cB - 0: A\x0c - ** Fail -No match - A B -No match - -# Test \v+ - -/^A(?>\¥+)/ - A\x15B - 0: A\x15 - A\x0dB - 0: A\x0d - A\x25B - 0: A\x25 - A\x0bB - 0: A\x0b - A\x0cB - 0: A\x0c - ** Fail -No match - A B -No match - -# Test \V+ - -/^A(?>\å+)/ - A B - 0: A\x20B - ** Fail -No match - A\x15B -No match - A\x0dB -No match - A\x25B -No match - A\x0bB -No match - A\x0cB -No match - -# Test \c functionality - -/\ƒ@\ƒA\ƒb\ƒC\ƒd\ƒE\ƒf\ƒG\ƒh\ƒI\ƒJ\ƒK\ƒl\ƒm\ƒN\ƒO\ƒp\ƒq\ƒr\ƒS\ƒT\ƒu\ƒV\ƒW\ƒX\ƒy\ƒZ/ - \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f - 0: \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a - -/\ƒ[\ƒ\\ƒ]\ƒ^\ƒ_/ - \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f - 0: \x1b\x1c\x1d\x1e\x1f - -/\ƒ?/ - A\xffB - 0: \xff - -/\ƒ&/ -Failed: error 168 at offset 3: \c\x20must\x20be\x20followed\x20by\x20a\x20letter\x20or\x20one\x20of\x20[\]^_\x3f - -# End diff --git a/testdata/wintestoutput3 b/testdata/wintestoutput3 index 171b7fb..28cb388 100644 --- a/testdata/wintestoutput3 +++ b/testdata/wintestoutput3 @@ -14,7 +14,7 @@ No match /^[\w]+/locale=french École - 0: École + 0: \xc9cole /^[\W]+/ École @@ -46,7 +46,7 @@ No match /^\w+/locale=french École - 0: École + 0: \xc9cole /(.+)\b(.+)/ École @@ -68,9 +68,9 @@ No match /École/i,locale=french École - 0: École + 0: \xc9cole école - 0: école + 0: \xe9cole /\w/I Capture group count = 0 @@ -82,9 +82,12 @@ Subject length lower bound = 1 Capture group count = 0 Starting code units: 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ a b c d e f g h i j k l m n o p q r s t u v w x y z - ƒ Š Œ Ž š œ ž Ÿ ª ² ³ µ ¹ º À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö - Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý - þ ÿ + \x83 \x8a \x8c \x8e \x9a \x9c \x9e \x9f \xaa \xb2 \xb3 \xb5 \xb9 \xba \xc0 + \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf + \xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf + \xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee + \xef \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf8 \xf9 \xfa \xfb \xfc \xfd \xfe + \xff Subject length lower bound = 1 # All remaining tests are in the french locale, so set the default. @@ -93,35 +96,35 @@ Subject length lower bound = 1 /^[\xc8-\xc9]/i École - 0: É + 0: \xc9 école - 0: é + 0: \xe9 /^[\xc8-\xc9]/ École - 0: É + 0: \xc9 \= Expect no match école No match /\xb5/i µ - 0: µ + 0: \xb5 \= Expect no match \x9c No match /ÿ/i \xff - 0: ÿ + 0: \xff \= Expect no match y No match /(.)\1/i \xfe\xde - 0: þÞ - 1: þ + 0: \xfe\xde + 1: \xfe /\W+/ >>>\xaa<<< @@ -143,21 +146,21 @@ No match /\w+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[\w]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]]+/ >>>\xaa<<< - 0: ª + 0: \xaa >>>\xba<<< - 0: º + 0: \xba /[[:alpha:]][[:lower:]][[:upper:]]/IB ------------------------------------------------------------------ @@ -170,9 +173,12 @@ No match ------------------------------------------------------------------ Capture group count = 0 Starting code units: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - a b c d e f g h i j k l m n o p q r s t u v w x y z ƒ Š Œ Ž š œ ž Ÿ ª µ º - À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å - æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ + a b c d e f g h i j k l m n o p q r s t u v w x y z \x83 \x8a \x8c \x8e \x9a + \x9c \x9e \x9f \xaa \xb5 \xba \xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 + \xc9 \xca \xcb \xcc \xcd \xce \xcf \xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd8 + \xd9 \xda \xdb \xdc \xdd \xde \xdf \xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 + \xe8 \xe9 \xea \xeb \xec \xed \xee \xef \xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 + \xf8 \xf9 \xfa \xfb \xfc \xfd \xfe \xff Subject length lower bound = 3 # End of wintestinput3 diff --git a/vms/configure.com b/vms/configure.com index 831f38f..2356478 100644 --- a/vms/configure.com +++ b/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)