Revision: 667
http://vcs.pcre.org/viewvc?view=rev&revision=667
Author: ph10
Date: 2011-08-22 15:57:32 +0100 (Mon, 22 Aug 2011)
Log Message:
-----------
Commit all the changes for JIT support, but without any documentation yet.
Modified Paths:
--------------
code/trunk/CMakeLists.txt
code/trunk/Makefile.am
code/trunk/RunGrepTest
code/trunk/config-cmake.h.in
code/trunk/maint/ManyConfigTests
code/trunk/pcre_config.c
code/trunk/pcre_exec.c
code/trunk/pcre_internal.h
code/trunk/pcrecpp_unittest.cc
code/trunk/pcregrep.c
code/trunk/pcretest.c
Added Paths:
-----------
code/trunk/pcre_jit_test.c
Modified: code/trunk/CMakeLists.txt
===================================================================
--- code/trunk/CMakeLists.txt 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/CMakeLists.txt 2011-08-22 14:57:32 UTC (rev 667)
@@ -38,6 +38,7 @@
# 2010-01-02 PH added test for stdint.h
# 2010-03-02 PH added test for inttypes.h
# 2011-08-01 PH added PCREGREP_BUFSIZE
+# 2011-08-22 PH added PCRE_SUPPORT_JIT
PROJECT(PCRE C CXX)
@@ -112,6 +113,9 @@
SET(PCRE_POSIX_MALLOC_THRESHOLD "10" CACHE STRING
"Threshold for malloc() usage. See POSIX_MALLOC_THRESHOLD in config.h.in for details.")
+SET(PCRE_SUPPORT_JIT OFF CACHE BOOL
+ "Enable support for Just-in-time compiling.")
+
SET(PCRE_SUPPORT_UNICODE_PROPERTIES OFF CACHE BOOL
"Enable support for Unicode properties. (If set, UTF-8 support will be enabled as well)")
@@ -206,6 +210,10 @@
SET(SUPPORT_UCP 1)
ENDIF(PCRE_SUPPORT_UNICODE_PROPERTIES)
+IF(PCRE_SUPPORT_JIT)
+ SET(SUPPORT_JIT 1)
+ENDIF(PCRE_SUPPORT_JIT)
+
# This next one used to contain
# SET(PCRETEST_LIBS ${READLINE_LIBRARY})
# but I was advised to add the NCURSES test as well, along with
@@ -313,6 +321,7 @@
pcre_get.c
pcre_globals.c
pcre_info.c
+ pcre_jit_compile.c
pcre_newline.c
pcre_maketables.c
pcre_ord2utf8.c
@@ -429,6 +438,12 @@
ADD_EXECUTABLE(pcretest pcretest.c)
SET(targets ${targets} pcretest)
TARGET_LINK_LIBRARIES(pcretest pcreposix ${PCRETEST_LIBS})
+
+ IF(PCRE_SUPPORT_JIT)
+ ADD_EXECUTABLE(pcre_jit_test pcre_jit_test.c)
+ SET(targets ${targets} pcre_jit_test)
+ TARGET_LINK_LIBRARIES(pcre_jit_test pcre)
+ ENDIF(PCRE_SUPPORT_JIT)
IF(PCRE_BUILD_PCRECPP)
ADD_EXECUTABLE(pcrecpp_unittest pcrecpp_unittest.cc)
@@ -440,7 +455,6 @@
)
ENDIF(MINGW AND NON_STANDARD_LIB_NAMES AND NOT PCRE_STATIC)
-
ADD_EXECUTABLE(pcre_scanner_unittest pcre_scanner_unittest.cc)
SET(targets ${targets} pcre_scanner_unittest)
TARGET_LINK_LIBRARIES(pcre_scanner_unittest pcrecpp)
@@ -471,6 +485,12 @@
ADD_TEST(pcre_test cmd /C ${PROJECT_SOURCE_DIR}/RunTest.bat)
ENDIF(WIN32)
+ IF(PCRE_SUPPORT_JIT)
+ GET_TARGET_PROPERTY(PCRE_JIT_TEST_EXE
+ pcre_jit_test
+ DEBUG_LOCATION)
+ ENDIF(PCRE_SUPPORT_JIT)
+
GET_TARGET_PROPERTY(PCRECPP_UNITTEST_EXE
pcrecpp_unittest
DEBUG_LOCATION)
@@ -483,6 +503,9 @@
pcre_stringpiece_unittest
DEBUG_LOCATION)
+ IF(PCRE_SUPPORT_JIT)
+ ADD_TEST(pcre_jit_test ${PCRE_JIT_TEST_EXE})
+ ENDIF(PCRE_SUPPORT_JIT)
ADD_TEST(pcrecpp_test ${PCRECPP_UNITTEST_EXE})
ADD_TEST(pcre_scanner_test ${PCRE_SCANNER_UNITTEST_EXE})
ADD_TEST(pcre_stringpiece_test ${PCRE_STRINGPIECE_UNITTEST_EXE})
@@ -546,6 +569,7 @@
MESSAGE(STATUS " C++ compiler flags .............. : ${CMAKE_CXX_FLAGS}${cxxfsp}${CMAKE_CXX_FLAGS_${buildtype}}")
MESSAGE(STATUS "")
MESSAGE(STATUS " Build C++ library ............... : ${PCRE_BUILD_PCRECPP}")
+ MESSAGE(STATUS " Enable JIT compiling support .... : ${PCRE_SUPPORT_JIT}")
MESSAGE(STATUS " Enable UTF-8 support ............ : ${PCRE_SUPPORT_UNICODE_PROPERTIES}")
MESSAGE(STATUS " Unicode properties .............. : ${PCRE_SUPPORT_UNICODE_PROPERTIES}")
MESSAGE(STATUS " Newline char/sequence ........... : ${PCRE_NEWLINE}")
Modified: code/trunk/Makefile.am
===================================================================
--- code/trunk/Makefile.am 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/Makefile.am 2011-08-22 14:57:32 UTC (rev 667)
@@ -174,6 +174,7 @@
pcre_globals.c \
pcre_info.c \
pcre_internal.h \
+ pcre_jit_compile.c \
pcre_maketables.c \
pcre_newline.c \
pcre_ord2utf8.c \
@@ -196,10 +197,38 @@
# pcre_chartables.c, used unless --enable-rebuild-chartables is specified.
EXTRA_DIST += pcre_printint.src pcre_chartables.c.dist
+# The JIT compiler lives in a separate directory, but its files are #included
+# when pcre_jit_compile.c is processed, so they must be distributed.
+EXTRA_DIST += \
+ sljit/sljitConfig.h \
+ sljit/sljitConfigInternal.h \
+ sljit/sljitExecAllocator.c \
+ sljit/sljitLir.c \
+ sljit/sljitLir.h \
+ sljit/sljitNativeARM_Thumb2.c \
+ sljit/sljitNativeARM_v5.c \
+ sljit/sljitNativeMIPS_32.c \
+ sljit/sljitNativeMIPS_common.c \
+ sljit/sljitNativePPC_32.c \
+ sljit/sljitNativePPC_64.c \
+ sljit/sljitNativePPC_common.c \
+ sljit/sljitNativeX86_32.c \
+ sljit/sljitNativeX86_64.c \
+ sljit/sljitNativeX86_common.c \
+ sljit/sljitUtils.c
+
libpcre_la_LDFLAGS = $(EXTRA_LIBPCRE_LDFLAGS)
CLEANFILES += pcre_chartables.c
+## If JIT support is enabled, arrange for the JIT test program to run.
+if WITH_JIT
+TESTS += pcre_jit_test
+noinst_PROGRAMS += pcre_jit_test
+pcre_jit_test_SOURCES = pcre_jit_test.c
+pcre_jit_test_LDADD = libpcre.la
+endif # WITH_JIT
+
## A version of the main pcre library that has a posix re API.
lib_LTLIBRARIES += libpcreposix.la
libpcreposix_la_SOURCES = \
@@ -321,7 +350,7 @@
# nice DLL for Windows use". (It is used by the pcre.dll target.)
DLL_OBJS= pcre_compile.o pcre_config.o \
pcre_dfa_exec.o pcre_exec.o pcre_fullinfo.o pcre_get.o \
- pcre_globals.o pcre_info.o pcre_maketables.o \
+ pcre_globals.o pcre_info.o pcre_jit_compile.o pcre_maketables.o \
pcre_newline.o pcre_ord2utf8.o pcre_refcount.o \
pcre_study.o pcre_tables.o pcre_try_flipped.o \
pcre_ucd.o pcre_valid_utf8.o pcre_version.o \
Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/RunGrepTest 2011-08-22 14:57:32 UTC (rev 667)
@@ -13,7 +13,7 @@
valgrind=
while [ $# -gt 0 ] ; do
case $1 in
- valgrind) valgrind="valgrind -q --leak-check=no";;
+ valgrind) valgrind="valgrind -q --leak-check=no --smc-check=all";;
*) echo "RunGrepTest: Unknown argument $1"; exit 1;;
esac
shift
Modified: code/trunk/config-cmake.h.in
===================================================================
--- code/trunk/config-cmake.h.in 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/config-cmake.h.in 2011-08-22 14:57:32 UTC (rev 667)
@@ -18,6 +18,7 @@
#cmakedefine PCRE_STATIC 1
+#cmakedefine SUPPORT_JIT 1
#cmakedefine SUPPORT_UTF8 1
#cmakedefine SUPPORT_UCP 1
#cmakedefine EBCDIC 1
Modified: code/trunk/maint/ManyConfigTests
===================================================================
--- code/trunk/maint/ManyConfigTests 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/maint/ManyConfigTests 2011-08-22 14:57:32 UTC (rev 667)
@@ -140,7 +140,9 @@
"--enable-newline-is-cr --disable-shared" \
"--enable-newline-is-crlf --disable-shared" \
"--enable-newline-is-anycrlf --enable-bsr-anycrlf --disable-shared" \
- "--enable-utf8 --enable-newline-is-any --enable-unicode-properties --disable-stack-for-recursion --disable-static --disable-cpp"
+ "--enable-utf8 --enable-newline-is-any --enable-unicode-properties --disable-stack-for-recursion --disable-static --disable-cpp" \
+ "--enable-jit --enable-unicode-properties" \
+ "--enable-jit --enable-unicode-properties --with-link-size=3"
do
runtest
done
Modified: code/trunk/pcre_config.c
===================================================================
--- code/trunk/pcre_config.c 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/pcre_config.c 2011-08-22 14:57:32 UTC (rev 667)
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2009 University of Cambridge
+ Copyright (c) 1997-2011 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -83,6 +83,14 @@
#endif
break;
+ case PCRE_CONFIG_JIT:
+#ifdef SUPPORT_JIT
+ *((int *)where) = 1;
+#else
+ *((int *)where) = 0;
+#endif
+ break;
+
case PCRE_CONFIG_NEWLINE:
*((int *)where) = NEWLINE;
break;
Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/pcre_exec.c 2011-08-22 14:57:32 UTC (rev 667)
@@ -5761,7 +5761,7 @@
PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
int offsetcount)
{
-int rc, ocount;
+int rc, ocount, arg_offset_max;
int first_byte = -1;
int req_byte = -1;
int req_byte2 = -1;
@@ -5797,9 +5797,60 @@
if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
-/* This information is for finding all the numbers associated with a given
-name, for condition testing. */
+/* These two settings are used in the code for checking a UTF-8 string that
+follows immediately afterwards. Other values in the md block are used only
+during "normal" pcre_exec() processing, not when the JIT support is in use,
+so they are set up later. */
+utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
+md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
+ ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
+
+/* Check a UTF-8 string if required. Pass back the character offset and error
+code for an invalid string if a results vector is available. */
+
+#ifdef SUPPORT_UTF8
+if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
+ {
+ int erroroffset;
+ int errorcode = _pcre_valid_utf8((USPTR)subject, length, &erroroffset);
+ if (errorcode != 0)
+ {
+ if (offsetcount >= 2)
+ {
+ offsets[0] = erroroffset;
+ offsets[1] = errorcode;
+ }
+ return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?
+ PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
+ }
+
+ /* Check that a start_offset points to the start of a UTF-8 character. */
+ if (start_offset > 0 && start_offset < length &&
+ (((USPTR)subject)[start_offset] & 0xc0) == 0x80)
+ return PCRE_ERROR_BADUTF8_OFFSET;
+ }
+#endif
+
+/* If the pattern was successfully studied with JIT support, run the JIT
+executable instead of the rest of this function. Most options must be set at
+compile time for the JIT code to be usable. Fallback to the normal code path if
+an unsupported flag is set. In particular, JIT does not support partial
+matching. */
+
+#ifdef SUPPORT_JIT
+if (extra_data != NULL
+ && (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
+ && extra_data->executable_jit != NULL
+ && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |
+ PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART)) == 0)
+ return _pcre_jit_exec(re, extra_data->executable_jit, subject, length,
+ start_offset, options, offsets, offsetcount);
+#endif
+
+/* Carry on with non-JIT matching. This information is for finding all the
+numbers associated with a given name, for condition testing. */
+
md->name_table = (uschar *)re + re->name_table_offset;
md->name_count = re->name_count;
md->name_entry_size = re->name_entry_size;
@@ -5865,7 +5916,6 @@
end_subject = md->end_subject;
md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
-utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
md->use_ucp = (re->options & PCRE_UCP) != 0;
md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
@@ -5876,10 +5926,7 @@
md->noteol = (options & PCRE_NOTEOL) != 0;
md->notempty = (options & PCRE_NOTEMPTY) != 0;
md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
-md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
- ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
-
md->hitend = FALSE;
md->mark = NULL; /* In case never set */
@@ -5961,39 +6008,13 @@
if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
return PCRE_ERROR_BADPARTIAL;
-/* Check a UTF-8 string if required. Pass back the character offset and error
-code for an invalid string if a results vector is available. */
-
-#ifdef SUPPORT_UTF8
-if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
- {
- int erroroffset;
- int errorcode = _pcre_valid_utf8((USPTR)subject, length, &erroroffset);
- if (errorcode != 0)
- {
- if (offsetcount >= 2)
- {
- offsets[0] = erroroffset;
- offsets[1] = errorcode;
- }
- return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?
- PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
- }
-
- /* Check that a start_offset points to the start of a UTF-8 character. */
-
- if (start_offset > 0 && start_offset < length &&
- (((USPTR)subject)[start_offset] & 0xc0) == 0x80)
- return PCRE_ERROR_BADUTF8_OFFSET;
- }
-#endif
-
/* If the expression has got more back references than the offsets supplied can
hold, we get a temporary chunk of working store to use during the matching.
Otherwise, we can use the vector supplied, rounding down its size to a multiple
of 3. */
ocount = offsetcount - (offsetcount % 3);
+arg_offset_max = (2*ocount)/3;
if (re->top_backref > 0 && re->top_backref >= ocount/3)
{
@@ -6368,22 +6389,23 @@
{
if (using_temporary_offsets)
{
- if (offsetcount >= 4)
+ if (arg_offset_max >= 4)
{
memcpy(offsets + 2, md->offset_vector + 2,
- (offsetcount - 2) * sizeof(int));
+ (arg_offset_max - 2) * sizeof(int));
DPRINTF(("Copied offsets from temporary memory\n"));
}
- if (md->end_offset_top > offsetcount) md->offset_overflow = TRUE;
+ if (md->end_offset_top > arg_offset_max) md->offset_overflow = TRUE;
DPRINTF(("Freeing temporary memory\n"));
(pcre_free)(md->offset_vector);
}
- /* Set the return code to the number of captured strings, or 0 if there are
+ /* Set the return code to the number of captured strings, or 0 if there were
too many to fit into the vector. */
+
+ rc = (md->offset_overflow && md->end_offset_top >= arg_offset_max)?
+ 0 : md->end_offset_top/2;
- rc = md->offset_overflow? 0 : md->end_offset_top/2;
-
/* If there is space in the offset vector, set any unused pairs at the end of
the pattern to -1 for backwards compatibility. It is documented that this
happens. In earlier versions, the whole set of potential capturing offsets
Modified: code/trunk/pcre_internal.h
===================================================================
--- code/trunk/pcre_internal.h 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/pcre_internal.h 2011-08-22 14:57:32 UTC (rev 667)
@@ -624,7 +624,8 @@
PCRE_DFA_RESTART|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
PCRE_NO_START_OPTIMIZE)
-#define PUBLIC_STUDY_OPTIONS 0 /* None defined */
+#define PUBLIC_STUDY_OPTIONS \
+ PCRE_STUDY_JIT_COMPILE
/* Magic number to provide a small check against being handed junk. Also used
to detect whether a pattern was compiled on a host of different endianness. */
@@ -1912,6 +1913,10 @@
extern const int _pcre_utf8_table3[];
extern const uschar _pcre_utf8_table4[];
+#ifdef SUPPORT_JIT
+extern const uschar _pcre_utf8_char_sizes[];
+#endif
+
extern const int _pcre_utf8_table1_size;
extern const char _pcre_utt_names[];
@@ -1936,6 +1941,12 @@
extern BOOL _pcre_was_newline(USPTR, int, USPTR, int *, BOOL);
extern BOOL _pcre_xclass(int, const uschar *);
+#ifdef SUPPORT_JIT
+extern void _pcre_jit_compile(const real_pcre *, pcre_extra *);
+extern int _pcre_jit_exec(const real_pcre *, void *, PCRE_SPTR,
+ int, int, int, int *, int);
+extern void _pcre_jit_free(void *);
+#endif
/* Unicode character database (UCD) */
@@ -1949,8 +1960,10 @@
extern const uschar _pcre_ucd_stage1[];
extern const pcre_uint16 _pcre_ucd_stage2[];
extern const int _pcre_ucp_gentype[];
+#ifdef SUPPORT_JIT
+extern const int _pcre_ucp_typerange[];
+#endif
-
/* UCD access macros */
#define UCD_BLOCK_SIZE 128
Added: code/trunk/pcre_jit_test.c
===================================================================
--- code/trunk/pcre_jit_test.c (rev 0)
+++ code/trunk/pcre_jit_test.c 2011-08-22 14:57:32 UTC (rev 667)
@@ -0,0 +1,668 @@
+/*************************************************
+* 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.
+
+ Main Library written by Philip Hazel
+ Copyright (c) 1997-2011 University of Cambridge
+
+ This JIT compiler regression test program was written by Zoltan Herczeg
+ Copyright (c) 2010-2011
+
+-----------------------------------------------------------------------------
+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 <stdio.h>
+#include <string.h>
+#include <time.h>
+#include "pcre.h"
+
+#define PCRE_BUG 0x80000000
+
+/*
+ Hungarian utf8 characters
+ \xc3\xa9 = 0xe9 = 233 (e') \xc3\x89 = 0xc9 = 201 (E')
+ \xc3\xa1 = 0xe1 = 225 (a') \xc3\x81 = 0xc1 = 193 (A')
+ \xe6\x92\xad = 0x64ad = 25773 (a valid kanji)
+ \xc2\x85 = 0x85 (NExt Line = NEL)
+ \xc2\xa1 = 0xa1 (Inverted Exclamation Mark)
+ \xe2\x80\xa8 = 0x2028 (Line Separator)
+ \xc8\xba = 570 \xe2\xb1\xa5 = 11365 (lowercase length != uppercase length)
+ \xcc\x8d = 781 (Something with Mark property)
+*/
+
+static void setstack(pcre_extra *extra);
+static void regression_tests(void);
+
+int main(void)
+{
+ regression_tests();
+ return 0;
+}
+
+static pcre_jit_stack* callback(void *arg)
+{
+ return (pcre_jit_stack *)arg;
+}
+
+static void setstack(pcre_extra *extra)
+{
+ static pcre_jit_stack *stack;
+ if (stack) pcre_jit_stack_free(stack);
+ stack = pcre_jit_stack_alloc(1, 1024 * 1024);
+ pcre_assign_jit_callback(extra, callback, stack);
+}
+
+/* --------------------------------------------------------------------------------------- */
+
+#define MUA (PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF)
+#define MUAP (PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF | PCRE_UCP)
+#define CMUA (PCRE_CASELESS | PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF)
+#define CMUAP (PCRE_CASELESS | PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF | PCRE_UCP)
+#define MA (PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF)
+#define MAP (PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF | PCRE_UCP)
+#define CMA (PCRE_CASELESS | PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF)
+
+struct regression_test_case {
+ int flags;
+ int start_offset;
+ const char *pattern;
+ const char *input;
+};
+
+static struct regression_test_case regression_test_cases[] = {
+ /* Constant strings. */
+ { MUA, 0, "AbC", "AbAbC" },
+ { MUA, 0, "ACCEPT", "AACACCACCEACCEPACCEPTACCEPTT" },
+ { CMUA, 0, "aA#\xc3\xa9\xc3\x81", "aA#Aa#\xc3\x89\xc3\xa1" },
+ { MA, 0, "[^a]", "aAbB" },
+ { CMA, 0, "[^m]", "mMnN" },
+ { MA, 0, "a[^b][^#]", "abacd" },
+ { CMA, 0, "A[^B][^E]", "abacd" },
+ { CMUA, 0, "[^x][^#]", "XxBll" },
+ { MUA, 0, "[^a]", "aaa\xc3\xa1#Ab" },
+ { CMUA, 0, "[^A]", "aA\xe6\x92\xad" },
+ { MUA, 0, "\\W(\\W)?\\w", "\r\n+bc" },
+ { MUA, 0, "\\W(\\W)?\\w", "\n\r+bc" },
+ { MUA, 0, "\\W(\\W)?\\w", "\r\r+bc" },
+ { MUA, 0, "\\W(\\W)?\\w", "\n\n+bc" },
+ { MUA, 0, "[axd]", "sAXd" },
+ { CMUA, 0, "[axd]", "sAXd" },
+ { CMUA, 0, "[^axd]", "DxA" },
+ { MUA, 0, "[a-dA-C]", "\xe6\x92\xad\xc3\xa9.B" },
+ { MUA, 0, "[^a-dA-C]", "\xe6\x92\xad\xc3\xa9" },
+ { CMUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },
+ { MUA, 0, "[^\xc3\xa9]", "\xc3\xa9\xc3\x89." },
+ { MUA, 0, "[^a]", "\xc2\x80[]" },
+ { CMUA, 0, "\xf0\x90\x90\xa7", "\xf0\x90\x91\x8f" },
+ { CMA, 0, "1a2b3c4", "1a2B3c51A2B3C4" },
+ { PCRE_CASELESS, 0, "\xff#a", "\xff#\xff\xfe##\xff#A" },
+ { PCRE_CASELESS, 0, "\xfe", "\xff\xfc#\xfe\xfe" },
+ { PCRE_CASELESS, 0, "a1", "Aa1" },
+
+ /* Assertions. */
+ { MUA, 0, "\\b[^A]", "A_B#" },
+ { MA, 0, "\\b\\W", "\n*" },
+ { MUA, 0, "\\B[^,]\\b[^s]\\b", "#X" },
+ { MAP, 0, "\\B", "_\xa1" },
+ { MAP, 0, "\\b_\\b[,A]\\B", "_," },
+ { MUAP, 0, "\\b", "\xe6\x92\xad!" },
+ { MUAP, 0, "\\B", "_\xc2\xa1\xc3\xa1\xc2\x85" },
+ { MUAP, 0, "\\b[^A]\\B[^c]\\b[^_]\\B", "_\xc3\xa1\xe2\x80\xa8" },
+ { MUAP, 0, "\\b\\w+\\B", "\xc3\x89\xc2\xa1\xe6\x92\xad\xc3\x81\xc3\xa1" },
+ { MUA, 0, "\\b.", "\xcd\xbe" },
+ { MA, 0, "\\R^", "\n" },
+ { MA, 1, "^", "\n" },
+ { 0, 0, "^ab", "ab" },
+ { 0, 0, "^ab", "aab" },
+ { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "^a", "\r\raa\n\naa\r\naa" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF, 0, "^-", "\xe2\x80\xa8--\xc2\x85-\r\n-" },
+ { PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "^-", "a--b--\x85--" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY, 0, "^-", "a--\xe2\x80\xa8--" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY, 0, "^-", "a--\xc2\x85--" },
+ { 0, 0, "ab$", "ab" },
+ { 0, 0, "ab$", "ab\r\n" },
+ { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "a$", "\r\raa\n\naa\r\naa" },
+ { PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "a$", "aaa" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANYCRLF, 0, "#$", "#\xc2\x85###\r#" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY, 0, "#$", "#\xe2\x80\xa9" },
+ { PCRE_NOTBOL | PCRE_NEWLINE_ANY, 0, "^a", "aa\naa" },
+ { PCRE_NOTBOL | PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "^a", "aa\naa" },
+ { PCRE_NOTEOL | PCRE_NEWLINE_ANY, 0, "a$", "aa\naa" },
+ { PCRE_NOTEOL | PCRE_NEWLINE_ANY, 0, "a$", "aa\r\n" },
+ { PCRE_UTF8 | PCRE_DOLLAR_ENDONLY | PCRE_NEWLINE_ANY, 0, "\\p{Any}{2,}$", "aa\r\n" },
+ { PCRE_NOTEOL | PCRE_MULTILINE | PCRE_NEWLINE_ANY, 0, "a$", "aa\naa" },
+ { PCRE_NEWLINE_CR, 0, ".\\Z", "aaa" },
+ { PCRE_NEWLINE_CR | PCRE_UTF8, 0, "a\\Z", "aaa\r" },
+ { PCRE_NEWLINE_CR, 0, ".\\Z", "aaa\n" },
+ { PCRE_NEWLINE_CRLF, 0, ".\\Z", "aaa\r" },
+ { PCRE_NEWLINE_CRLF | PCRE_UTF8, 0, ".\\Z", "aaa\n" },
+ { PCRE_NEWLINE_CRLF, 0, ".\\Z", "aaa\r\n" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\n" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r\n" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\xe2\x80\xa8" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\n" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".\\Z", "aaa\r\n" },
+ { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, ".\\Z", "aaa\xc2\x85" },
+ { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, ".\\Z", "aaa\xe2\x80\xa8" },
+ { MA, 0, "\\Aa", "aaa" },
+ { MA, 1, "\\Aa", "aaa" },
+ { MA, 1, "\\Ga", "aaa" },
+ { MA, 1, "\\Ga", "aba" },
+ { MA, 0, "a\\z", "aaa" },
+ { MA, 0, "a\\z", "aab" },
+
+ /* Brackets. */
+ { MUA, 0, "(ab|bb|cd)", "bacde" },
+ { MUA, 0, "(?:ab|a)(bc|c)", "ababc" },
+ { MUA, 0, "((ab|(cc))|(bb)|(?:cd|efg))", "abac" },
+ { CMUA, 0, "((aB|(Cc))|(bB)|(?:cd|EFg))", "AcCe" },
+ { MUA, 0, "((ab|(cc))|(bb)|(?:cd|ebg))", "acebebg" },
+ { MUA, 0, "(?:(a)|(?:b))(cc|(?:d|e))(a|b)k", "accabdbbccbk" },
+
+ /* Greedy and non-greedy ? operators. */
+ { MUA, 0, "(?:a)?a", "laab" },
+ { CMUA, 0, "(A)?A", "llaab" },
+ { MUA, 0, "(a)?\?a", "aab" }, /* ?? is the prefix of trygraphs in GCC. */
+ { MUA, 0, "(a)?a", "manm" },
+ { CMUA, 0, "(a|b)?\?d((?:e)?)", "ABABdx" },
+ { MUA, 0, "(a|b)?\?d((?:e)?)", "abcde" },
+ { MUA, 0, "((?:ab)?\?g|b(?:g(nn|d)?\?)?)?\?(?:n)?m", "abgnbgnnbgdnmm" },
+
+ /* Greedy and non-greedy + operators */
+ { MUA, 0, "(aa)+aa", "aaaaaaa" },
+ { MUA, 0, "(aa)+?aa", "aaaaaaa" },
+ { MUA, 0, "(?:aba|ab|a)+l", "ababamababal" },
+ { MUA, 0, "(?:aba|ab|a)+?l", "ababamababal" },
+ { MUA, 0, "(a(?:bc|cb|b|c)+?|ss)+e", "accssabccbcacbccbbXaccssabccbcacbccbbe" },
+ { MUA, 0, "(a(?:bc|cb|b|c)+|ss)+?e", "accssabccbcacbccbbXaccssabccbcacbccbbe" },
+ { MUA, 0, "(?:(b(c)+?)+)?\?(?:(bc)+|(cb)+)+(?:m)+", "bccbcccbcbccbcbPbccbcccbcbccbcbmmn" },
+
+ /* Greedy and non-greedy * operators */
+ { CMUA, 0, "(?:AA)*AB", "aaaaaaamaaaaaaab" },
+ { MUA, 0, "(?:aa)*?ab", "aaaaaaamaaaaaaab" },
+ { MUA, 0, "(aa|ab)*ab", "aaabaaab" },
+ { CMUA, 0, "(aa|Ab)*?aB", "aaabaaab" },
+ { MUA, 0, "(a|b)*(?:a)*(?:b)*m", "abbbaaababanabbbaaababamm" },
+ { MUA, 0, "(a|b)*?(?:a)*?(?:b)*?m", "abbbaaababanabbbaaababamm" },
+ { MA, 0, "a(a(\\1*)a|(b)b+){0}a", "aa" },
+ { MA, 0, "((?:a|)*){0}a", "a" },
+
+ /* Combining ? + * operators */
+ { MUA, 0, "((bm)+)?\?(?:a)*(bm)+n|((am)+?)?(?:a)+(am)*n", "bmbmabmamaaamambmaman" },
+ { MUA, 0, "(((ab)?cd)*ef)+g", "abcdcdefcdefefmabcdcdefcdefefgg" },
+ { MUA, 0, "(((ab)?\?cd)*?ef)+?g", "abcdcdefcdefefmabcdcdefcdefefgg" },
+ { MUA, 0, "(?:(ab)?c|(?:ab)+?d)*g", "ababcdccababddg" },
+ { MUA, 0, "(?:(?:ab)?\?c|(ab)+d)*?g", "ababcdccababddg" },
+
+ /* Single character iterators. */
+ { MUA, 0, "(a+aab)+aaaab", "aaaabcaaaabaabcaabcaaabaaaab" },
+ { MUA, 0, "(a*a*aab)+x", "aaaaabaabaaabmaabx" },
+ { MUA, 0, "(a*?(b|ab)a*?)+x", "aaaabcxbbaabaacbaaabaabax" },
+ { MUA, 0, "(a+(ab|ad)a+)+x", "aaabaaaadaabaaabaaaadaaax" },
+ { MUA, 0, "(a?(a)a?)+(aaa)", "abaaabaaaaaaaa" },
+ { MUA, 0, "(a?\?(a)a?\?)+(b)", "aaaacaaacaacacbaaab" },
+ { MUA, 0, "(a{0,4}(b))+d", "aaaaaabaabcaaaaabaaaaabd" },
+ { MUA, 0, "(a{0,4}?[^b])+d+(a{0,4}[^b])d+", "aaaaadaaaacaadddaaddd" },
+ { MUA, 0, "(ba{2})+c", "baabaaabacbaabaac" },
+ { MUA, 0, "(a*+bc++)+", "aaabbcaaabcccab" },
+ { MUA, 0, "(a?+[^b])+", "babaacacb" },
+ { MUA, 0, "(a{0,3}+b)(a{0,3}+b)(a{0,3}+)[^c]", "abaabaaacbaabaaaac" },
+ { CMUA, 0, "([a-c]+[d-f]+?)+?g", "aBdacdehAbDaFgA" },
+ { CMUA, 0, "[c-f]+k", "DemmFke" },
+ { MUA, 0, "([DGH]{0,4}M)+", "GGDGHDGMMHMDHHGHM" },
+ { MUA, 0, "([a-c]{4,}s)+", "abasabbasbbaabsbba" },
+ { CMUA, 0, "[ace]{3,7}", "AcbDAcEEcEd" },
+ { CMUA, 0, "[ace]{3,7}?", "AcbDAcEEcEd" },
+ { CMUA, 0, "[ace]{3,}", "AcbDAcEEcEd" },
+ { CMUA, 0, "[ace]{3,}?", "AcbDAcEEcEd" },
+ { MUA, 0, "[ckl]{2,}?g", "cdkkmlglglkcg" },
+ { CMUA, 0, "[ace]{5}?", "AcCebDAcEEcEd" },
+ { MUA, 0, "([AbC]{3,5}?d)+", "BACaAbbAEAACCbdCCbdCCAAbb" },
+ { MUA, 0, "([^ab]{0,}s){2}", "abaabcdsABamsDDs" },
+ { MUA, 0, "\\b\\w+\\B", "x,a_cd" },
+ { MUAP, 0, "\\b[^\xc2\xa1]+\\B", "\xc3\x89\xc2\xa1\xe6\x92\xad\xc3\x81\xc3\xa1" },
+ { CMUA, 0, "[^b]+(a*)([^c]?d{3})", "aaaaddd" },
+
+ /* Basic character sets. */
+ { MUA, 0, "(?:\\s)+(?:\\S)+", "ab \t\xc3\xa9\xe6\x92\xad " },
+ { MUA, 0, "(\\w)*(k)(\\W)?\?", "abcdef abck11" },
+ { MUA, 0, "\\((\\d)+\\)\\D", "a() (83 (8)2 (9)ab" },
+ { MUA, 0, "\\w(\\s|(?:\\d)*,)+\\w\\wb", "a 5, 4,, bb 5, 4,, aab" },
+ { MUA, 0, "(\\v+)(\\V+)", "\x0e\xc2\x85\xe2\x80\xa8\x0b\x09\xe2\x80\xa9" },
+ { MUA, 0, "(\\h+)(\\H+)", "\xe2\x80\xa8\xe2\x80\x80\x20\xe2\x80\x8a\xe2\x81\x9f\xe3\x80\x80\x09\x20\xc2\xa0\x0a" },
+
+ /* Unicode properties. */
+ { MUAP, 0, "[1-5\xc3\xa9\\w]", "\xc3\xa1_" },
+ { MUAP, 0, "[\xc3\x81\\p{Ll}]", "A_\xc3\x89\xc3\xa1" },
+ { MUAP, 0, "[\\Wd-h_x-z]+", "a\xc2\xa1#_yhzdxi" },
+ { MUAP, 0, "[\\P{Any}]", "abc" },
+ { MUAP, 0, "[^\\p{Any}]", "abc" },
+ { MUAP, 0, "[\\P{Any}\xc3\xa1-\xc3\xa8]", "abc" },
+ { MUAP, 0, "[^\\p{Any}\xc3\xa1-\xc3\xa8]", "abc" },
+ { MUAP, 0, "[\xc3\xa1-\xc3\xa8\\P{Any}]", "abc" },
+ { MUAP, 0, "[^\xc3\xa1-\xc3\xa8\\p{Any}]", "abc" },
+ { MUAP, 0, "[\xc3\xa1-\xc3\xa8\\p{Any}]", "abc" },
+ { MUAP, 0, "[^\xc3\xa1-\xc3\xa8\\P{Any}]", "abc" },
+ { MUAP, 0, "[b-\xc3\xa9\\s]", "a\xc\xe6\x92\xad" },
+ { CMUAP, 0, "[\xc2\x85-\xc2\x89\xc3\x89]", "\xc2\x84\xc3\xa9" },
+ { MUAP, 0, "[^b-d^&\\s]{3,}", "db^ !a\xe2\x80\xa8_ae" },
+ { MUAP, 0, "[^\\S\\P{Any}][\\sN]{1,3}[\\P{N}]{4}", "\xe2\x80\xaa\xa N\x9\xc3\xa9_0" },
+ { MUA, 0, "[^\\P{L}\x9!D-F\xa]{2,3}", "\x9,.DF\xa.CG\xc3\x81" },
+ { CMUAP, 0, "[\xc3\xa1-\xc3\xa9_\xe2\x80\xa0-\xe2\x80\xaf]{1,5}[^\xe2\x80\xa0-\xe2\x80\xaf]", "\xc2\xa1\xc3\x89\xc3\x89\xe2\x80\xaf_\xe2\x80\xa0" },
+ { MUAP, 0, "[\xc3\xa2-\xc3\xa6\xc3\x81-\xc3\x84\xe2\x80\xa8-\xe2\x80\xa9\xe6\x92\xad\\p{Zs}]{2,}", "\xe2\x80\xa7\xe2\x80\xa9\xe6\x92\xad \xe6\x92\xae" },
+ { MUAP, 0, "[\\P{L&}]{2}[^\xc2\x85-\xc2\x89\\p{Ll}\\p{Lu}]{2}", "\xc3\xa9\xe6\x92\xad.a\xe6\x92\xad|\xc2\x8a#" },
+ { PCRE_UCP, 0, "[a-b\\s]{2,5}[^a]", "AB baaa" },
+
+ /* Possible empty brackets. */
+ { MUA, 0, "(?:|ab||bc|a)+d", "abcxabcabd" },
+ { MUA, 0, "(|ab||bc|a)+d", "abcxabcabd" },
+ { MUA, 0, "(?:|ab||bc|a)*d", "abcxabcabd" },
+ { MUA, 0, "(|ab||bc|a)*d", "abcxabcabd" },
+ { MUA, 0, "(?:|ab||bc|a)+?d", "abcxabcabd" },
+ { MUA, 0, "(|ab||bc|a)+?d", "abcxabcabd" },
+ { MUA, 0, "(?:|ab||bc|a)*?d", "abcxabcabd" },
+ { MUA, 0, "(|ab||bc|a)*?d", "abcxabcabd" },
+ { MUA, 0, "(((a)*?|(?:ba)+)+?|(?:|c|ca)*)*m", "abaacaccabacabalabaacaccabacabamm" },
+ { MUA, 0, "(?:((?:a)*|(ba)+?)+|(|c|ca)*?)*?m", "abaacaccabacabalabaacaccabacabamm" },
+
+ /* Start offset. */
+ { MUA, 3, "(\\d|(?:\\w)*\\w)+", "0ac01Hb" },
+ { MUA, 4, "(\\w\\W\\w)+", "ab#d" },
+ { MUA, 2, "(\\w\\W\\w)+", "ab#d" },
+ { MUA, 1, "(\\w\\W\\w)+", "ab#d" },
+
+ /* Newline. */
+ { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "\\W{0,2}[^#]{3}", "\r\n#....." },
+ { PCRE_MULTILINE | PCRE_NEWLINE_CR, 0, "\\W{0,2}[^#]{3}", "\r\n#....." },
+ { PCRE_MULTILINE | PCRE_NEWLINE_CRLF, 0, "\\W{1,3}[^#]", "\r\n##...." },
+
+ /* Any character except newline or any newline. */
+ { PCRE_NEWLINE_CRLF, 0, ".", "\r" },
+ { PCRE_NEWLINE_CRLF | PCRE_UTF8, 0, ".(.).", "a\xc3\xa1\r\n\n\r\r" },
+ { PCRE_NEWLINE_ANYCRLF, 0, ".(.)", "a\rb\nc\r\n\xc2\x85\xe2\x80\xa8" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".(.)", "a\rb\nc\r\n\xc2\x85\xe2\x80\xa8" },
+ { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, "(.).", "a\rb\nc\r\n\xc2\x85\xe2\x80\xa9$de" },
+ { PCRE_NEWLINE_ANYCRLF | PCRE_UTF8, 0, ".(.).", "\xe2\x80\xa8\nb\r" },
+ { PCRE_NEWLINE_ANY, 0, "(.)(.)", "#\x85#\r#\n#\r\n#\x84" },
+ { PCRE_NEWLINE_ANY | PCRE_UTF8, 0, "(.+)#", "#\rMn\xc2\x85#\n###" },
+ { PCRE_BSR_ANYCRLF, 0, "\\R", "\r" },
+ { PCRE_BSR_ANYCRLF, 0, "\\R", "\x85#\r\n#" },
+ { PCRE_BSR_UNICODE | PCRE_UTF8, 0, "\\R", "ab\xe2\x80\xa8#c" },
+ { PCRE_BSR_UNICODE | PCRE_UTF8, 0, "\\R", "ab\r\nc" },
+ { PCRE_NEWLINE_CRLF | PCRE_BSR_UNICODE | PCRE_UTF8, 0, "(\\R.)+", "\xc2\x85\r\n#\xe2\x80\xa8\n\r\n\r" },
+ { MUA, 0, "\\R+", "ab" },
+ { MUA, 0, "\\R+", "ab\r\n\r" },
+ { MUA, 0, "\\R*", "ab\r\n\r" },
+ { MUA, 0, "\\R*", "\r\n\r" },
+ { MUA, 0, "\\R{2,4}", "\r\nab\r\r" },
+ { MUA, 0, "\\R{2,4}", "\r\nab\n\n\n\r\r\r" },
+ { MUA, 0, "\\R{2,}", "\r\nab\n\n\n\r\r\r" },
+ { MUA, 0, "\\R{0,3}", "\r\n\r\n\r\n\r\n\r\n" },
+ { MUA, 0, "\\R+\\R\\R", "\r\n\r\n" },
+ { MUA, 0, "\\R+\\R\\R", "\r\r\r" },
+ { MUA, 0, "\\R*\\R\\R", "\n\r" },
+ { MUA, 0, "\\R{2,4}\\R\\R", "\r\r\r" },
+ { MUA, 0, "\\R{2,4}\\R\\R", "\r\r\r\r" },
+
+ /* Atomic groups (no fallback from "next" direction). */
+ { MUA, 0, "(?>ab)ab", "bab" },
+ { MUA, 0, "(?>(ab))ab", "bab" },
+ { MUA, 0, "(?>ab)+abc(?>de)*def(?>gh)?ghe(?>ij)+?k(?>lm)*?n(?>op)?\?op",
+ "bababcdedefgheijijklmlmnop" },
+ { MUA, 0, "(?>a(b)+a|(ab)?\?(b))an", "abban" },
+ { MUA, 0, "(?>ab+a|(?:ab)?\?b)an", "abban" },
+ { MUA, 0, "((?>ab|ad|)*?)(?>|c)*abad", "abababcababad" },
+ { MUA, 0, "(?>(aa|b|)*+(?>(##)|###)*d|(aa)(?>(baa)?)m)", "aabaa#####da" },
+ { MUA, 0, "((?>a|)+?)b", "aaacaaab" },
+ { MUA, 0, "(?>x|)*$", "aaa" },
+ { MUA, 0, "(?>(x)|)*$", "aaa" },
+ { MUA, 0, "(?>x|())*$", "aaa" },
+ { MUA, 0, "((?>[cxy]a|[a-d])*?)b", "aaa+ aaab" },
+ { MUA, 0, "((?>[cxy](a)|[a-d])*?)b", "aaa+ aaab" },
+ { MUA, 0, "(?>((?>(a+))))bab|(?>((?>(a+))))bb", "aaaabaaabaabab" },
+ { MUA, 0, "(?>(?>a+))bab|(?>(?>a+))bb", "aaaabaaabaabab" },
+ { MUA, 0, "(?>(a)c|(?>(c)|(a))a)b*?bab", "aaaabaaabaabab" },
+ { MUA, 0, "(?>ac|(?>c|a)a)b*?bab", "aaaabaaabaabab" },
+ { MUA, 0, "(?>(b)b|(a))*b(?>(c)|d)?x", "ababcaaabdbx" },
+ { MUA, 0, "(?>bb|a)*b(?>c|d)?x", "ababcaaabdbx" },
+ { MUA, 0, "(?>(bb)|a)*b(?>c|(d))?x", "ababcaaabdbx" },
+ { MUA, 0, "(?>(a))*?(?>(a))+?(?>(a))??x", "aaaaaacccaaaaabax" },
+ { MUA, 0, "(?>a)*?(?>a)+?(?>a)??x", "aaaaaacccaaaaabax" },
+ { MUA, 0, "(?>(a)|)*?(?>(a)|)+?(?>(a)|)??x", "aaaaaacccaaaaabax" },
+ { MUA, 0, "(?>a|)*?(?>a|)+?(?>a|)??x", "aaaaaacccaaaaabax" },
+ { MUA, 0, "(?>a(?>(a{0,2}))*?b|aac)+b", "aaaaaaacaaaabaaaaacaaaabaacaaabb" },
+ { CMA, 0, "(?>((?>a{32}|b+|(a*))?(?>c+|d*)?\?)+e)+?f", "aaccebbdde bbdaaaccebbdee bbdaaaccebbdeef" },
+ { MUA, 0, "(?>(?:(?>aa|a||x)+?b|(?>aa|a||(x))+?c)?(?>[ad]{0,2})*?d)+d", "aaacdbaabdcabdbaaacd aacaabdbdcdcaaaadaabcbaadd" },
+ { MUA, 0, "(?>(?:(?>aa|a||(x))+?b|(?>aa|a||x)+?c)?(?>[ad]{0,2})*?d)+d", "aaacdbaabdcabdbaaacd aacaabdbdcdcaaaadaabcbaadd" },
+ { MUA, 0, "\\X", "\xcc\x8d\xcc\x8d" },
+ { MUA, 0, "\\X", "\xcc\x8d\xcc\x8d#\xcc\x8d\xcc\x8d" },
+ { MUA, 0, "\\X+..", "\xcc\x8d#\xcc\x8d#\xcc\x8d\xcc\x8d" },
+ { MUA, 0, "\\X{2,4}", "abcdef" },
+ { MUA, 0, "\\X{2,4}?", "abcdef" },
+ { MUA, 0, "\\X{2,4}..", "#\xcc\x8d##" },
+ { MUA, 0, "\\X{2,4}..", "#\xcc\x8d#\xcc\x8d##" },
+ { MUA, 0, "(c(ab)?+ab)+", "cabcababcab" },
+ { MUA, 0, "(?>(a+)b)+aabab", "aaaabaaabaabab" },
+
+ /* Possessive quantifiers. */
+ { MUA, 0, "(?:a|b)++m", "mababbaaxababbaam" },
+ { MUA, 0, "(?:a|b)*+m", "mababbaaxababbaam" },
+ { MUA, 0, "(?:a|b)*+m", "ababbaaxababbaam" },
+ { MUA, 0, "(a|b)++m", "mababbaaxababbaam" },
+ { MUA, 0, "(a|b)*+m", "mababbaaxababbaam" },
+ { MUA, 0, "(a|b)*+m", "ababbaaxababbaam" },
+ { MUA, 0, "(a|b(*ACCEPT))++m", "maaxab" },
+ { MUA, 0, "(?:b*)++m", "bxbbxbbbxm" },
+ { MUA, 0, "(?:b*)++m", "bxbbxbbbxbbm" },
+ { MUA, 0, "(?:b*)*+m", "bxbbxbbbxm" },
+ { MUA, 0, "(?:b*)*+m", "bxbbxbbbxbbm" },
+ { MUA, 0, "(b*)++m", "bxbbxbbbxm" },
+ { MUA, 0, "(b*)++m", "bxbbxbbbxbbm" },
+ { MUA, 0, "(b*)*+m", "bxbbxbbbxm" },
+ { MUA, 0, "(b*)*+m", "bxbbxbbbxbbm" },
+ { MUA, 0, "(?:a|(b))++m", "mababbaaxababbaam" },
+ { MUA, 0, "(?:(a)|b)*+m", "mababbaaxababbaam" },
+ { MUA, 0, "(?:(a)|(b))*+m", "ababbaaxababbaam" },
+ { MUA, 0, "(a|(b))++m", "mababbaaxababbaam" },
+ { MUA, 0, "((a)|b)*+m", "mababbaaxababbaam" },
+ { MUA, 0, "((a)|(b))*+m", "ababbaaxababbaam" },
+ { MUA, 0, "(a|(b)(*ACCEPT))++m", "maaxab" },
+ { MUA, 0, "(?:(b*))++m", "bxbbxbbbxm" },
+ { MUA, 0, "(?:(b*))++m", "bxbbxbbbxbbm" },
+ { MUA, 0, "(?:(b*))*+m", "bxbbxbbbxm" },
+ { MUA, 0, "(?:(b*))*+m", "bxbbxbbbxbbm" },
+ { MUA, 0, "((b*))++m", "bxbbxbbbxm" },
+ { MUA, 0, "((b*))++m", "bxbbxbbbxbbm" },
+ { MUA, 0, "((b*))*+m", "bxbbxbbbxm" },
+ { MUA, 0, "((b*))*+m", "bxbbxbbbxbbm" },
+ { MUA, 0, "(?>(b{2,4}))(?:(?:(aa|c))++m|(?:(aa|c))+n)", "bbaacaaccaaaacxbbbmbn" },
+ { MUA, 0, "((?:b)++a)+(cd)*+m", "bbababbacdcdnbbababbacdcdm" },
+ { MUA, 0, "((?:(b))++a)+((c)d)*+m", "bbababbacdcdnbbababbacdcdm" },
+ { MUA, 0, "(?:(?:(?:ab)*+k)++(?:n(?:cd)++)*+)*+m", "ababkkXababkkabkncXababkkabkncdcdncdXababkkabkncdcdncdkkabkncdXababkkabkncdcdncdkkabkncdm" },
+ { MUA, 0, "(?:((ab)*+(k))++(n(?:c(d))++)*+)*+m", "ababkkXababkkabkncXababkkabkncdcdncdXababkkabkncdcdncdkkabkncdXababkkabkncdcdncdkkabkncdm" },
+
+ /* Back references. */
+ { MUA, 0, "(aa|bb)(\\1*)(ll|)(\\3*)bbbbbbc", "aaaaaabbbbbbbbc" },
+ { CMUA, 0, "(aa|bb)(\\1+)(ll|)(\\3+)bbbbbbc", "bBbbBbCbBbbbBbbcbbBbbbBBbbC" },
+ { CMA, 0, "(a{2,4})\\1", "AaAaaAaA" },
+ { MUA, 0, "(aa|bb)(\\1?)aa(\\1?)(ll|)(\\4+)bbc", "aaaaaaaabbaabbbbaabbbbc" },
+ { MUA, 0, "(aa|bb)(\\1{0,5})(ll|)(\\3{0,5})cc", "bbxxbbbbxxaaaaaaaaaaaaaaaacc" },
+ { MUA, 0, "(aa|bb)(\\1{3,5})(ll|)(\\3{3,5})cc", "bbbbbbbbbbbbaaaaaaccbbbbbbbbbbbbbbcc" },
+ { MUA, 0, "(aa|bb)(\\1{3,})(ll|)(\\3{3,})cc", "bbbbbbbbbbbbaaaaaaccbbbbbbbbbbbbbbcc" },
+ { MUA, 0, "(\\w+)b(\\1+)c", "GabGaGaDbGaDGaDc" },
+ { MUA, 0, "(?:(aa)|b)\\1?b", "bb" },
+ { CMUA, 0, "(aa|bb)(\\1*?)aa(\\1+?)", "bBBbaaAAaaAAaa" },
+ { MUA, 0, "(aa|bb)(\\1*?)(dd|)cc(\\3+?)", "aaaaaccdd" },
+ { CMUA, 0, "(?:(aa|bb)(\\1?\?)cc){2}(\\1?\?)", "aAaABBbbAAaAcCaAcCaA" },
+ { MUA, 0, "(?:(aa|bb)(\\1{3,5}?)){2}(dd|)(\\3{3,5}?)", "aaaaaabbbbbbbbbbaaaaaaaaaaaaaa" },
+ { CMA, 0, "(?:(aa|bb)(\\1{3,}?)){2}(dd|)(\\3{3,}?)", "aaaaaabbbbbbbbbbaaaaaaaaaaaaaa" },
+ { MUA, 0, "(?:(aa|bb)(\\1{0,3}?)){2}(dd|)(\\3{0,3}?)b(\\1{0,3}?)(\\1{0,3})", "aaaaaaaaaaaaaaabaaaaa" },
+ { MUA, 0, "(a(?:\\1|)a){3}b", "aaaaaaaaaaab" },
+ { MA, 0, "(a?)b(\\1\\1*\\1+\\1?\\1*?\\1+?\\1??\\1*+\\1++\\1?+\\1{4}\\1{3,5}\\1{4,}\\1{0,5}\\1{3,5}?\\1{4,}?\\1{0,5}?\\1{3,5}+\\1{4,}+\\1{0,5}+#){2}d", "bb#b##d" },
+ { MUAP, 0, "(\\P{N})\\1{2,}", ".www." },
+ { MUAP, 0, "(\\P{N})\\1{0,2}", "wwwww." },
+ { MUAP, 0, "(\\P{N})\\1{1,2}ww", "wwww" },
+ { MUAP, 0, "(\\P{N})\\1{1,2}ww", "wwwww" },
+ { PCRE_UCP, 0, "(\\P{N})\\1{2,}", ".www." },
+
+ /* Assertions. */
+ { MUA, 0, "(?=xx|yy|zz)\\w{4}", "abczzdefg" },
+ { MUA, 0, "(?=((\\w+)b){3}|ab)", "dbbbb ab" },
+ { MUA, 0, "(?!ab|bc|cd)[a-z]{2}", "Xabcdef" },
+ { MUA, 0, "(?<=aaa|aa|a)a", "aaa" },
+ { MUA, 2, "(?<=aaa|aa|a)a", "aaa" },
+ { MA, 0, "(?<=aaa|aa|a)a", "aaa" },
+ { MA, 2, "(?<=aaa|aa|a)a", "aaa" },
+ { MUA, 0, "(\\d{2})(?!\\w+c|(((\\w?)m){2}n)+|\\1)", "x5656" },
+ { MUA, 0, "((?=((\\d{2,6}\\w){2,}))\\w{5,20}K){2,}", "567v09708K12l00M00 567v09708K12l00M00K45K" },
+ { MUA, 0, "(?=(?:(?=\\S+a)\\w*(b)){3})\\w+\\d", "bba bbab nbbkba nbbkba0kl" },
+ { MUA, 0, "(?>a(?>(b+))a(?=(..)))*?k", "acabbcabbaabacabaabbakk" },
+ { MUA, 0, "((?(?=(a))a)+k)", "bbak" },
+ { MUA, 0, "((?(?=a)a)+k)", "bbak" },
+ { MUA, 0, "(?=(?>(a))m)amk", "a k" },
+ { MUA, 0, "(?!(?>(a))m)amk", "a k" },
+ { MUA, 0, "(?>(?=(a))am)amk", "a k" },
+ { MUA, 0, "(?=(?>a|(?=(?>(b+))a|c)[a-c]+)*?m)[a-cm]+k", "aaam bbam baaambaam abbabba baaambaamk" },
+ { MUA, 0, "(?> ?\?\\b(?(?=\\w{1,4}(a))m)\\w{0,8}bc){2,}?", "bca ssbc mabd ssbc mabc" },
+ { MUA, 0, "(?:(?=ab)?[^n][^n])+m", "ababcdabcdcdabnababcdabcdcdabm" },
+ { MUA, 0, "(?:(?=a(b))?[^n][^n])+m", "ababcdabcdcdabnababcdabcdcdabm" },
+ { MUA, 0, "(?:(?=.(.))??\\1.)+m", "aabbbcbacccanaabbbcbacccam" },
+ { MUA, 0, "(?:(?=.)??[a-c])+m", "abacdcbacacdcaccam" },
+ { MUA, 0, "((?!a)?(?!([^a]))?)+$", "acbab" },
+ { MUA, 0, "((?!a)?\?(?!([^a]))?\?)+$", "acbab" },
+
+ /* Not empty, ACCEPT, FAIL */
+ { MUA | PCRE_NOTEMPTY, 0, "a*", "bcx" },
+ { MUA | PCRE_NOTEMPTY, 0, "a*", "bcaad" },
+ { MUA | PCRE_NOTEMPTY, 0, "a*?", "bcaad" },
+ { MUA | PCRE_NOTEMPTY_ATSTART, 0, "a*", "bcaad" },
+ { MUA, 0, "a(*ACCEPT)b", "ab" },
+ { MUA | PCRE_NOTEMPTY, 0, "a*(*ACCEPT)b", "bcx" },
+ { MUA | PCRE_NOTEMPTY, 0, "a*(*ACCEPT)b", "bcaad" },
+ { MUA | PCRE_NOTEMPTY, 0, "a*?(*ACCEPT)b", "bcaad" },
+ { MUA | PCRE_NOTEMPTY, 0, "(?:z|a*(*ACCEPT)b)", "bcx" },
+ { MUA | PCRE_NOTEMPTY, 0, "(?:z|a*(*ACCEPT)b)", "bcaad" },
+ { MUA | PCRE_NOTEMPTY, 0, "(?:z|a*?(*ACCEPT)b)", "bcaad" },
+ { MUA | PCRE_NOTEMPTY_ATSTART, 0, "a*(*ACCEPT)b", "bcx" },
+ { MUA | PCRE_NOTEMPTY_ATSTART, 0, "a*(*ACCEPT)b", "" },
+ { MUA, 0, "((a(*ACCEPT)b))", "ab" },
+ { MUA, 0, "(a(*FAIL)a|a)", "aaa" },
+ { MUA, 0, "(?=ab(*ACCEPT)b)a", "ab" },
+ { MUA, 0, "(?=(?:x|ab(*ACCEPT)b))", "ab" },
+ { MUA, 0, "(?=(a(b(*ACCEPT)b)))a", "ab" },
+ { MUA | PCRE_NOTEMPTY, 0, "(?=a*(*ACCEPT))c", "c" },
+
+ /* Conditional blocks. */
+ { MUA, 0, "(?(?=(a))a|b)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?!(b))a|b)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?=a)a|b)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?!b)a|b)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?=(a))a*|b*)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?!(b))a*|b*)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?!(b))(?:aaaaaa|a)|(?:bbbbbb|b))+aaaak", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb aaaaaaak" },
+ { MUA, 0, "(?(?!b)(?:aaaaaa|a)|(?:bbbbbb|b))+aaaak", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb aaaaaaak" },
+ { MUA | PCRE_BUG, 0, "(?(?!(b))(?:aaaaaa|a)|(?:bbbbbb|b))+bbbbk", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb bbbbbbbk" },
+ { MUA, 0, "(?(?!b)(?:aaaaaa|a)|(?:bbbbbb|b))+bbbbk", "aaaaaaaaaaaaaa bbbbbbbbbbbbbbb bbbbbbbk" },
+ { MUA, 0, "(?(?=a)a*|b*)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?!b)a*|b*)+k", "ababbalbbadabak" },
+ { MUA, 0, "(?(?=a)ab)", "a" },
+ { MUA, 0, "(?(?<!b)c)", "b" },
+ { MUA, 0, "(?(DEFINE)a(b))", "a" },
+ { MUA, 0, "a(?(DEFINE)(?:b|(?:c?)+)*)", "a" },
+ { MUA, 0, "(?(?=.[a-c])[k-l]|[A-D])", "kdB" },
+ { MUA, 0, "(?(?!.{0,4}[cd])(aa|bb)|(cc|dd))+", "aabbccddaa" },
+ { MUA, 0, "(?(?=[^#@]*@)(aaab|aa|aba)|(aba|aab)){3,}", "aaabaaaba#aaabaaaba#aaabaaaba@" },
+ { MUA, 0, "((?=\\w{5})\\w(?(?=\\w*k)\\d|[a-f_])*\\w\\s)+", "mol m10kk m088k _f_a_ mbkkl" },
+ { MUA, 0, "(c)?\?(?(1)a|b)", "cdcaa" },
+ { MUA, 0, "(c)?\?(?(1)a|b)", "cbb" },
+ { MUA | PCRE_BUG, 0, "(?(?=(a))(aaaa|a?))+aak", "aaaaab aaaaak" },
+ { MUA, 0, "(?(?=a)(aaaa|a?))+aak", "aaaaab aaaaak" },
+ { MUA, 0, "(?(?!(b))(aaaa|a?))+aak", "aaaaab aaaaak" },
+ { MUA, 0, "(?(?!b)(aaaa|a?))+aak", "aaaaab aaaaak" },
+ { MUA | PCRE_BUG, 0, "(?(?=(a))a*)+aak", "aaaaab aaaaak" },
+ { MUA, 0, "(?(?=a)a*)+aak", "aaaaab aaaaak" },
+ { MUA, 0, "(?(?!(b))a*)+aak", "aaaaab aaaaak" },
+ { MUA, 0, "(?(?!b)a*)+aak", "aaaaab aaaaak" },
+ { MUA, 0, "(?(?=(?=(?!(x))a)aa)aaa|(?(?=(?!y)bb)bbb))*k", "abaabbaaabbbaaabbb abaabbaaabbbaaabbbk" },
+
+ /* Set start of match. */
+ { MUA, 0, "(?:\\Ka)*aaaab", "aaaaaaaa aaaaaaabb" },
+ { MUA, 0, "(?>\\Ka\\Ka)*aaaab", "aaaaaaaa aaaaaaaaaabb" },
+ { MUA, 0, "a+\\K(?<=\\Gaa)a", "aaaaaa" },
+ { MUA | PCRE_NOTEMPTY, 0, "a\\K(*ACCEPT)b", "aa" },
+ { MUA | PCRE_NOTEMPTY_ATSTART, 0, "a\\K(*ACCEPT)b", "aa" },
+
+ /* First line. */
+ { MUA | PCRE_FIRSTLINE, 0, "\\p{Any}a", "bb\naaa" },
+ { MUA | PCRE_FIRSTLINE, 0, "\\p{Any}a", "bb\r\naaa" },
+ { MUA | PCRE_FIRSTLINE, 0, "(?<=a)", "a" },
+ { MUA | PCRE_FIRSTLINE, 0, "[^a][^b]", "ab" },
+ { MUA | PCRE_FIRSTLINE, 0, "a", "\na" },
+ { MUA | PCRE_FIRSTLINE, 0, "[abc]", "\na" },
+ { MUA | PCRE_FIRSTLINE, 0, "^a", "\na" },
+ { MUA | PCRE_FIRSTLINE, 0, "^(?<=\n)", "\na" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY | PCRE_FIRSTLINE, 0, "#", "\xc2\x85#" },
+ { PCRE_MULTILINE | PCRE_NEWLINE_ANY | PCRE_FIRSTLINE, 0, "#", "\x85#" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_ANY | PCRE_FIRSTLINE, 0, "^#", "\xe2\x80\xa8#" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0, "\\p{Any}", "\r\na" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0, ".", "\r" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0, "a", "\ra" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0, "ba", "bbb\r\nba" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 0, "\\p{Any}{4}|a", "\r\na" },
+ { PCRE_MULTILINE | PCRE_UTF8 | PCRE_NEWLINE_CRLF | PCRE_FIRSTLINE, 1, ".", "\r\n" },
+
+ /* Recurse. */
+ { MUA, 0, "(a)(?1)", "aa" },
+ { MUA, 0, "((a))(?1)", "aa" },
+ { MUA, 0, "(b|a)(?1)", "aa" },
+ { MUA, 0, "(b|(a))(?1)", "aa" },
+ { MUA, 0, "((a)(b)(?:a*))(?1)", "aba" },
+ { MUA, 0, "((a)(b)(?:a*))(?1)", "abab" },
+ { MUA, 0, "((a+)c(?2))b(?1)", "aacaabaca" },
+ { MUA, 0, "((?2)b|(a)){2}(?1)", "aabab" },
+ { MUA, 0, "(?1)(a)*+(?2)(b(?1))", "aababa" },
+ { MUA, 0, "(?1)(((a(*ACCEPT)))b)", "axaa" },
+ { MUA, 0, "(?1)(?(DEFINE) (((ac(*ACCEPT)))b) )", "akaac" },
+ { MUA, 0, "(a+)b(?1)b\\1", "abaaabaaaaa" },
+ { MUA, 0, "(?(DEFINE)(aa|a))(?1)ab", "aab" },
+ { MUA, 0, "(?(DEFINE)(a\\Kb))(?1)+ababc", "abababxabababc" },
+ { MUA, 0, "(a\\Kb)(?1)+ababc", "abababxababababc" },
+ { MUA, 0, "(a\\Kb)(?1)+ababc", "abababxababababxc" },
+ { MUA, 0, "b|<(?R)*>", "<<b>" },
+ { MUA, 0, "(a\\K){0}(?:(?1)b|ac)", "ac" },
+ { MUA, 0, "(?(DEFINE)(a(?2)|b)(b(?1)|(a)))(?:(?1)|(?2))m", "ababababnababababaam" },
+
+ /* Deep recursion. */
+ { MUA, 0, "((((?:(?:(?:\\w)+)?)*|(?>\\w)+?)+|(?>\\w)?\?)*)?\\s", "aaaaa+ " },
+ { MUA, 0, "(?:((?:(?:(?:\\w*?)+)??|(?>\\w)?|\\w*+)*)+)+?\\s", "aaa+ " },
+
+ { 0, 0, NULL, NULL }
+};
+
+static void regression_tests(void)
+{
+ pcre *re;
+ struct regression_test_case *current = regression_test_cases;
+ const char *error;
+ pcre_extra *extra;
+ int ovector1[32];
+ int ovector2[32];
+ int return_value1, return_value2;
+ int i, err_offs;
+ int total = 0, succesful = 0;
+ int counter = 0;
+
+ printf("Running JIT regression tests:\n");
+ while (current->pattern) {
+ /* printf("\nPattern: %s :", current->pattern); */
+ total++;
+
+ error = NULL;
+ re = pcre_compile(current->pattern, current->flags & ~(PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART | PCRE_BUG), &error, &err_offs, NULL);
+
+ if (!re) {
+ printf("\nCannot compile pattern: %s\n", current->pattern);
+ current++;
+ continue;
+ }
+
+ error = NULL;
+ extra = pcre_study(re, PCRE_STUDY_JIT_COMPILE, &error);
+ if (!extra) {
+ printf("\nCannot study pattern: %s\n", current->pattern);
+ current++;
+ continue;
+ }
+
+ if (!(extra->flags & PCRE_EXTRA_EXECUTABLE_JIT)) {
+ printf("\nJIT compiler does not support: %s\n", current->pattern);
+ current++;
+ continue;
+ }
+
+ counter++;
+ if ((counter & 0x3) != 0)
+ setstack(extra);
+
+ for (i = 0; i < 32; ++i)
+ ovector1[i] = -2;
+ return_value1 = pcre_exec(re, extra, current->input, strlen(current->input), current->start_offset, current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART), ovector1, 32);
+
+ for (i = 0; i < 32; ++i)
+ ovector2[i] = -2;
+ return_value2 = pcre_exec(re, NULL, current->input, strlen(current->input), current->start_offset, current->flags & (PCRE_NOTBOL | PCRE_NOTEOL | PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART), ovector2, 32);
+
+ /* If PCRE_BUG is set, just run the test, but do not compare the results.
+ Segfaults can still be captured. */
+ if (!(current->flags & PCRE_BUG)) {
+ if (return_value1 != return_value2) {
+ printf("\nReturn value differs(%d:%d): '%s' @ '%s'\n", return_value1, return_value2, current->pattern, current->input);
+ current++;
+ continue;
+ }
+
+ if (return_value1 >= 0) {
+ return_value1 *= 2;
+ err_offs = 0;
+ for (i = 0; i < return_value1; ++i)
+ if (ovector1[i] != ovector2[i]) {
+ printf("\nOvector[%d] value differs(%d:%d): '%s' @ '%s' \n", i, ovector1[i], ovector2[i], current->pattern, current->input);
+ err_offs = 1;
+ }
+ if (err_offs) {
+ current++;
+ continue;
+ }
+ }
+ }
+
+ pcre_free_study(extra);
+ pcre_free(re);
+
+ /* printf("[%d-%d]%s", ovector1[0], ovector1[1], (current->flags & PCRE_CASELESS) ? "C" : ""); */
+ printf(".");
+ fflush(stdout);
+ current++;
+ succesful++;
+ }
+
+ if (total == succesful)
+ printf("\nAll JIT regression tests are successfully passed.\n");
+ else
+ printf("\nSuccessful test ratio: %d%%\n", succesful * 100 / total);
+}
+
+/* End of pcre_jit_test.c */
Modified: code/trunk/pcrecpp_unittest.cc
===================================================================
--- code/trunk/pcrecpp_unittest.cc 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/pcrecpp_unittest.cc 2011-08-22 14:57:32 UTC (rev 667)
@@ -833,6 +833,7 @@
return 0;
}
+ printf("PCRE C++ wrapper tests\n");
printf("Testing FullMatch\n");
int i;
Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/pcregrep.c 2011-08-22 14:57:32 UTC (rev 667)
@@ -168,6 +168,7 @@
static int filenames = FN_DEFAULT;
static int only_matching = -1;
static int process_options = 0;
+static int study_options = 0;
static unsigned long int match_limit = 0;
static unsigned long int match_limit_recursion = 0;
@@ -238,6 +239,7 @@
{ OP_NODATA, 'H', NULL, "with-filename", "force the prefixing filename on output" },
{ OP_NODATA, 'h', NULL, "no-filename", "suppress the prefixing filename on output" },
{ OP_NODATA, 'i', NULL, "ignore-case", "ignore case distinctions" },
+ { OP_NODATA, 'j', NULL, "jit", "use JIT compiler if available" },
{ OP_NODATA, 'l', NULL, "files-with-matches", "print only FILE names containing matches" },
{ OP_NODATA, 'L', NULL, "files-without-match","print only FILE names not containing matches" },
{ OP_STRING, N_LABEL, &stdin_name, "label=name", "set name for standard input" },
@@ -1862,6 +1864,7 @@
case 'H': filenames = FN_FORCE; break;
case 'h': filenames = FN_NONE; break;
case 'i': options |= PCRE_CASELESS; break;
+ case 'j': study_options |= PCRE_STUDY_JIT_COMPILE; break;
case 'l': omit_zero_count = TRUE; filenames = FN_MATCH_ONLY; break;
case 'L': filenames = FN_NOMATCH_ONLY; break;
case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break;
@@ -2571,7 +2574,7 @@
for (j = 0; j < pattern_count; j++)
{
- hints_list[j] = pcre_study(pattern_list[j], 0, &error);
+ hints_list[j] = pcre_study(pattern_list[j], study_options, &error);
if (error != NULL)
{
char s[16];
@@ -2696,7 +2699,7 @@
{
for (i = 0; i < hint_count; i++)
{
- if (hints_list[i] != NULL) free(hints_list[i]);
+ if (hints_list[i] != NULL) pcre_free_study(hints_list[i]);
}
free(hints_list);
}
Modified: code/trunk/pcretest.c
===================================================================
--- code/trunk/pcretest.c 2011-08-22 14:56:43 UTC (rev 666)
+++ code/trunk/pcretest.c 2011-08-22 14:57:32 UTC (rev 667)
@@ -112,11 +112,13 @@
external symbols to prevent clashes. */
#define _pcre_ucp_gentype ucp_gentype
+#define _pcre_ucp_typerange ucp_typerange
#define _pcre_utf8_table1 utf8_table1
#define _pcre_utf8_table1_size utf8_table1_size
#define _pcre_utf8_table2 utf8_table2
#define _pcre_utf8_table3 utf8_table3
#define _pcre_utf8_table4 utf8_table4
+#define _pcre_utf8_char_sizes utf8_char_sizes
#define _pcre_utt utt
#define _pcre_utt_size utt_size
#define _pcre_utt_names utt_names
@@ -579,8 +581,16 @@
#endif /* HAVE_STRERROR */
+/*************************************************
+* JIT memory callback *
+*************************************************/
+static pcre_jit_stack* jit_callback(void *arg)
+{
+return (pcre_jit_stack *)arg;
+}
+
/*************************************************
* Read or extend an input line *
*************************************************/
@@ -987,8 +997,8 @@
* Local malloc functions *
*************************************************/
-/* Alternative malloc function, to test functionality and show the size of the
-compiled re. */
+/* Alternative malloc function, to test functionality and save the size of a
+compiled re. The show_malloc variable is set only during matching. */
static void *new_malloc(size_t size)
{
@@ -1006,7 +1016,6 @@
free(block);
}
-
/* For recursion malloc/free, to test stacking calls */
static void *stack_malloc(size_t size)
@@ -1195,7 +1204,8 @@
#endif
printf(" -q quiet: do not output PCRE version number at start\n");
printf(" -S <n> set stack size to <n> megabytes\n");
-printf(" -s force each pattern to be studied\n"
+printf(" -s force each pattern to be studied at basic level\n"
+ " -s+ force each pattern to be studied, using JIT if available\n"
" -t time compilation and execution\n");
printf(" -t <n> time compilation and execution, repeating <n> times\n");
printf(" -tm time execution (matching) only\n");
@@ -1223,7 +1233,8 @@
int timeitm = 0;
int showinfo = 0;
int showstore = 0;
-int force_study = 0;
+int force_study = -1;
+int force_study_options = 0;
int quiet = 0;
int size_offsets = 45;
int size_offsets_max;
@@ -1237,6 +1248,9 @@
int yield = 0;
int stack_size;
+pcre_jit_stack *jit_stack = NULL;
+
+
/* These vectors store, end-to-end, a list of captured substring names. Assume
that 1024 is plenty long enough for the few names we'll be testing. */
@@ -1273,7 +1287,12 @@
unsigned char *endptr;
if (strcmp(argv[op], "-m") == 0) showstore = 1;
- else if (strcmp(argv[op], "-s") == 0) force_study = 1;
+ else if (strcmp(argv[op], "-s") == 0) force_study = 0;
+ else if (strcmp(argv[op], "-s+") == 0)
+ {
+ force_study = 1;
+ force_study_options = PCRE_STUDY_JIT_COMPILE;
+ }
else if (strcmp(argv[op], "-q") == 0) quiet = 1;
else if (strcmp(argv[op], "-b") == 0) debug = 1;
else if (strcmp(argv[op], "-i") == 0) showinfo = 1;
@@ -1338,6 +1357,8 @@
printf(" %sUTF-8 support\n", rc? "" : "No ");
(void)pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &rc);
printf(" %sUnicode properties support\n", rc? "" : "No ");
+ (void)pcre_config(PCRE_CONFIG_JIT, &rc);
+ printf(" %sJust-in-time compiler support\n", rc? "" : "No ");
(void)pcre_config(PCRE_CONFIG_NEWLINE, &rc);
/* Note that these values are always the ASCII values, even
in EBCDIC environments. CR is 13 and NL is 10. */
@@ -1538,7 +1559,7 @@
{
FAIL_READ:
fprintf(outfile, "Failed to read data from %s\n", p);
- if (extra != NULL) new_free(extra);
+ if (extra != NULL) pcre_free_study(extra);
if (re != NULL) new_free(re);
fclose(f);
continue;
@@ -1604,7 +1625,6 @@
/* Look for options after final delimiter */
options = 0;
- study_options = 0;
log_store = showstore; /* default from command line */
while (*pp != 0)
@@ -1641,8 +1661,17 @@
#endif
case 'S':
- if (do_study == 0) do_study = 1; else
+ if (do_study == 0)
{
+ do_study = 1;
+ if (*pp == '+')
+ {
+ study_options |= PCRE_STUDY_JIT_COMPILE;
+ pp++;
+ }
+ }
+ else
+ {
do_study = 0;
no_force_study = 1;
}
@@ -1836,7 +1865,7 @@
suppresses the effect of /S (used for a few test patterns where studying is
never sensible). */
- if (do_study || (force_study && !no_force_study))
+ if (do_study || (force_study >= 0 && !no_force_study))
{
if (timeit > 0)
{
@@ -1844,14 +1873,14 @@
clock_t time_taken;
clock_t start_time = clock();
for (i = 0; i < timeit; i++)
- extra = pcre_study(re, study_options, &error);
+ extra = pcre_study(re, study_options | force_study_options, &error);
time_taken = clock() - start_time;
- if (extra != NULL) free(extra);
+ if (extra != NULL) pcre_free_study(extra);
fprintf(outfile, " Study time %.4f milliseconds\n",
(((double)time_taken * 1000.0) / (double)timeit) /
(double)CLOCKS_PER_SEC);
}
- extra = pcre_study(re, study_options, &error);
+ extra = pcre_study(re, study_options | force_study_options, &error);
if (error != NULL)
fprintf(outfile, "Failed to study: %s\n", error);
else if (extra != NULL)
@@ -2079,7 +2108,7 @@
when auto-callouts are involved, the output from runs with and without
-s should be identical. */
- if (do_study || (force_study && showinfo && !no_force_study))
+ if (do_study || (force_study >= 0 && showinfo && !no_force_study))
{
if (extra == NULL)
fprintf(outfile, "Study returned NULL\n");
@@ -2123,6 +2152,22 @@
fprintf(outfile, "\n");
}
}
+
+ /* Show this only if the JIT was set by /S, not by -s. */
+
+ if ((study_options & PCRE_STUDY_JIT_COMPILE) != 0)
+ {
+ int jit;
+ new_info(re, extra, PCRE_INFO_JIT, &jit);
+ if (jit)
+ fprintf(outfile, "JIT study was successful\n");
+ else
+#ifdef SUPPORT_JIT
+ fprintf(outfile, "JIT study was not successful\n");
+#else
+ fprintf(outfile, "JIT support is not available in this version of PCRE\n");
+#endif
+ }
}
}
@@ -2176,7 +2221,7 @@
}
new_free(re);
- if (extra != NULL) new_free(extra);
+ if (extra != NULL) pcre_free_study(extra);
if (locale_set)
{
new_free((void *)tables);
@@ -2443,6 +2488,18 @@
getnamesptr = npp;
}
continue;
+
+ case 'J':
+ while(isdigit(*p)) n = n * 10 + *p++ - '0';
+ if (extra != NULL
+ && (extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0
+ && extra->executable_jit != NULL)
+ {
+ if (jit_stack != NULL) pcre_jit_stack_free(jit_stack);
+ jit_stack = pcre_jit_stack_alloc(1, n * 1024);
+ pcre_assign_jit_callback(extra, jit_callback, jit_stack);
+ }
+ continue;
case 'L':
getlist = 1;
@@ -2654,7 +2711,10 @@
/* If find_match_limit is set, we want to do repeated matches with
varying limits in order to find the minimum value for the match limit and
- for the recursion limit. */
+ for the recursion limit. The match limits are relevant only to the normal
+ running of pcre_exec(), so disable the JIT optimization. This makes it
+ possible to run the same set of tests with and without JIT externally
+ requested. */
if (find_match_limit)
{
@@ -2663,7 +2723,8 @@
extra = (pcre_extra *)malloc(sizeof(pcre_extra));
extra->flags = 0;
}
-
+ else extra->flags &= ~PCRE_EXTRA_EXECUTABLE_JIT;
+
(void)check_match_limit(re, extra, bptr, len, start_offset,
options|g_notempty, use_offsets, use_size_offsets,
PCRE_EXTRA_MATCH_LIMIT, &(extra->match_limit),
@@ -2861,7 +2922,6 @@
fprintf(outfile, "%2dL %s\n", i, stringlist[i]);
if (stringlist[i] != NULL)
fprintf(outfile, "string list not terminated by NULL\n");
- /* free((void *)stringlist); */
pcre_free_substring_list(stringlist);
}
}
@@ -3012,13 +3072,18 @@
#endif
if (re != NULL) new_free(re);
- if (extra != NULL) new_free(extra);
+ if (extra != NULL) pcre_free_study(extra);
if (locale_set)
{
new_free((void *)tables);
setlocale(LC_CTYPE, "C");
locale_set = 0;
}
+ if (jit_stack != NULL)
+ {
+ pcre_jit_stack_free(jit_stack);
+ jit_stack = NULL;
+ }
}
if (infile == stdin) fprintf(outfile, "\n");