More groundwork for pcre2test: POSIX support.

This commit is contained in:
Philip.Hazel 2014-04-30 16:55:24 +00:00
parent 06ba06c763
commit 9812ca8b0a
16 changed files with 2056 additions and 937 deletions

View File

@ -221,12 +221,6 @@ AC_ARG_ENABLE(pcretest-libreadline,
[link pcretest with libreadline]),
, enable_pcretest_libreadline=no)
# Handle --with-posix-malloc-threshold=NBYTES
AC_ARG_WITH(posix-malloc-threshold,
AS_HELP_STRING([--with-posix-malloc-threshold=NBYTES],
[threshold for POSIX malloc usage (default=10)]),
, with_posix_malloc_threshold=10)
# Handle --with-link-size=N
AC_ARG_WITH(link-size,
AS_HELP_STRING([--with-link-size=N],
@ -595,15 +589,6 @@ AC_DEFINE_UNQUOTED([LINK_SIZE], [$with_link_size], [
majority of cases. However, PCRE can also be compiled to use 3 or 4
bytes instead. This allows for longer patterns in extreme cases.])
AC_DEFINE_UNQUOTED([POSIX_MALLOC_THRESHOLD], [$with_posix_malloc_threshold], [
When calling PCRE via the POSIX interface, additional working storage
is required for holding the pointers to capturing substrings because
PCRE requires three integers per substring, whereas the POSIX
interface provides only two. If the number of expected substrings is
small, the wrapper function uses space on the stack, because this is
faster than using malloc() for each call. The threshold above which
the stack is no longer used is defined by POSIX_MALLOC_THRESHOLD.])
AC_DEFINE_UNQUOTED([PARENS_NEST_LIMIT], [$with_parens_nest_limit], [
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
@ -877,7 +862,6 @@ $PACKAGE-$VERSION configuration summary:
EBCDIC code for NL .............. : ${ebcdic_nl_code}
Rebuild char tables ............. : ${enable_rebuild_chartables}
Use stack recursion ............. : ${enable_stack_for_recursion}
POSIX mem threshold ............. : ${with_posix_malloc_threshold}
Internal link size .............. : ${with_link_size}
Nested parentheses limit ........ : ${with_parens_nest_limit}
Match limit ..................... : ${with_match_limit}

View File

@ -234,15 +234,6 @@ sure both macros are undefined; an emulation function will then be used. */
lines. */
#define PCREGREP_BUFSIZE 20480
/* When calling PCRE via the POSIX interface, additional working storage is
required for holding the pointers to capturing substrings because PCRE
requires three integers per substring, whereas the POSIX interface provides
only two. If the number of expected substrings is small, the wrapper
function uses space on the stack, because this is faster than using
malloc() for each call. The threshold above which the stack is no longer
used is defined by POSIX_MALLOC_THRESHOLD. */
#define POSIX_MALLOC_THRESHOLD 10
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
/* #undef PTHREAD_CREATE_JOINABLE */

View File

@ -233,15 +233,6 @@ sure both macros are undefined; an emulation function will then be used. */
lines. */
#undef PCREGREP_BUFSIZE
/* When calling PCRE via the POSIX interface, additional working storage is
required for holding the pointers to capturing substrings because PCRE
requires three integers per substring, whereas the POSIX interface provides
only two. If the number of expected substrings is small, the wrapper
function uses space on the stack, because this is faster than using
malloc() for each call. The threshold above which the stack is no longer
used is defined by POSIX_MALLOC_THRESHOLD. */
#undef POSIX_MALLOC_THRESHOLD
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
#undef PTHREAD_CREATE_JOINABLE

View File

@ -138,106 +138,114 @@ D is inspected during pcre2_dfa_exec() execution
/* Newline and \R settings, for use in the compile context. */
#define PCRE2_NEWLINE_CR 0
#define PCRE2_NEWLINE_LF 1
#define PCRE2_NEWLINE_CRLF 2
#define PCRE2_NEWLINE_ANY 3
#define PCRE2_NEWLINE_ANYCRLF 4
#define PCRE2_NEWLINE_DEFAULT 0
#define PCRE2_NEWLINE_CR 1
#define PCRE2_NEWLINE_LF 2
#define PCRE2_NEWLINE_CRLF 3
#define PCRE2_NEWLINE_ANY 4
#define PCRE2_NEWLINE_ANYCRLF 5
#define PCRE2_BSR_UNICODE 0
#define PCRE2_BSR_ANYCRLF 1
#define PCRE2_BSR_DEFAULT 0
#define PCRE2_BSR_UNICODE 1
#define PCRE2_BSR_ANYCRLF 2
/* Exec-time and get/set-time error codes */
/* Match-time and get/set-time error codes */
#define PCRE2_ERROR_NOMATCH (-1)
#define PCRE2_ERROR_NULL (-2)
#define PCRE2_ERROR_BADOPTION (-3)
#define PCRE2_ERROR_BADMAGIC (-4)
#define PCRE2_ERROR_UNKNOWN_OPCODE (-5)
#define PCRE2_ERROR_NOMEMORY (-6)
#define PCRE2_ERROR_NOSUBSTRING (-7)
#define PCRE2_ERROR_MATCHLIMIT (-8)
#define PCRE2_ERROR_CALLOUT (-9) /* Never used by PCRE2 itself */
#define PCRE2_ERROR_PARTIAL (-10)
#define PCRE2_ERROR_BADPARTIAL (-11)
#define PCRE2_ERROR_INTERNAL (-12)
#define PCRE2_ERROR_BADCOUNT (-13)
#define PCRE2_ERROR_DFA_UITEM (-14)
#define PCRE2_ERROR_DFA_UCOND (-15)
#define PCRE2_ERROR_DFA_UMLIMIT (-16)
#define PCRE2_ERROR_DFA_WSSIZE (-17)
#define PCRE2_ERROR_DFA_RECURSE (-18)
#define PCRE2_ERROR_RECURSIONLIMIT (-19)
#define PCRE2_ERROR_BADOFFSET (-20)
#define PCRE2_ERROR_BADCOUNT (-2)
#define PCRE2_ERROR_BADENDIANNESS (-3)
#define PCRE2_ERROR_BADLENGTH (-4)
#define PCRE2_ERROR_BADMAGIC (-5)
#define PCRE2_ERROR_BADMODE (-6)
#define PCRE2_ERROR_BADOFFSET (-7)
#define PCRE2_ERROR_BADOPTION (-8)
#define PCRE2_ERROR_BADPARTIAL (-9)
#define PCRE2_ERROR_BADUTF (-10)
#define PCRE2_ERROR_BADUTF_OFFSET (-11)
#define PCRE2_ERROR_CALLOUT (-12) /* Never used by PCRE2 itself */
#define PCRE2_ERROR_INTERNAL (-13)
#define PCRE2_ERROR_JIT_BADOPTION (-14)
#define PCRE2_ERROR_JIT_STACKLIMIT (-15)
#define PCRE2_ERROR_MATCHLIMIT (-16)
#define PCRE2_ERROR_NOMEMORY (-17)
#define PCRE2_ERROR_NOSUBSTRING (-18)
#define PCRE2_ERROR_NULL (-19)
#define PCRE2_ERROR_PARTIAL (-20)
#define PCRE2_ERROR_RECURSELOOP (-21)
#define PCRE2_ERROR_JIT_STACKLIMIT (-22)
#define PCRE2_ERROR_BADMODE (-23)
#define PCRE2_ERROR_BADENDIANNESS (-24)
#define PCRE2_ERROR_DFA_BADRESTART (-25)
#define PCRE2_ERROR_JIT_BADOPTION (-26)
#define PCRE2_ERROR_BADLENGTH (-27)
#define PCRE2_ERROR_UNSET (-28)
#define PCRE2_ERROR_BADUTF_OFFSET (-29)
#define PCRE2_ERROR_RECURSIONLIMIT (-22)
#define PCRE2_ERROR_UNKNOWN_OPCODE (-23)
#define PCRE2_ERROR_UNSET (-24)
#define PCRE2_ERROR_DFA_BADRESTART (-30)
#define PCRE2_ERROR_DFA_RECURSE (-31)
#define PCRE2_ERROR_DFA_UCOND (-32)
#define PCRE2_ERROR_DFA_UITEM (-33)
#define PCRE2_ERROR_DFA_UMLIMIT (-34)
#define PCRE2_ERROR_DFA_WSSIZE (-35)
/* Specific error codes for UTF-8 validity checks */
#define PCRE2_ERROR_UTF8_ERR1 (-31)
#define PCRE2_ERROR_UTF8_ERR2 (-32)
#define PCRE2_ERROR_UTF8_ERR3 (-33)
#define PCRE2_ERROR_UTF8_ERR4 (-34)
#define PCRE2_ERROR_UTF8_ERR5 (-35)
#define PCRE2_ERROR_UTF8_ERR6 (-36)
#define PCRE2_ERROR_UTF8_ERR7 (-37)
#define PCRE2_ERROR_UTF8_ERR8 (-38)
#define PCRE2_ERROR_UTF8_ERR9 (-39)
#define PCRE2_ERROR_UTF8_ERR10 (-40)
#define PCRE2_ERROR_UTF8_ERR11 (-41)
#define PCRE2_ERROR_UTF8_ERR12 (-42)
#define PCRE2_ERROR_UTF8_ERR13 (-43)
#define PCRE2_ERROR_UTF8_ERR14 (-44)
#define PCRE2_ERROR_UTF8_ERR15 (-45)
#define PCRE2_ERROR_UTF8_ERR16 (-46)
#define PCRE2_ERROR_UTF8_ERR17 (-47)
#define PCRE2_ERROR_UTF8_ERR18 (-48)
#define PCRE2_ERROR_UTF8_ERR19 (-49)
#define PCRE2_ERROR_UTF8_ERR20 (-50)
#define PCRE2_ERROR_UTF8_ERR21 (-51)
#define PCRE2_ERROR_UTF8_ERR1 (-41)
#define PCRE2_ERROR_UTF8_ERR2 (-42)
#define PCRE2_ERROR_UTF8_ERR3 (-43)
#define PCRE2_ERROR_UTF8_ERR4 (-44)
#define PCRE2_ERROR_UTF8_ERR5 (-45)
#define PCRE2_ERROR_UTF8_ERR6 (-46)
#define PCRE2_ERROR_UTF8_ERR7 (-47)
#define PCRE2_ERROR_UTF8_ERR8 (-48)
#define PCRE2_ERROR_UTF8_ERR9 (-49)
#define PCRE2_ERROR_UTF8_ERR10 (-50)
#define PCRE2_ERROR_UTF8_ERR11 (-51)
#define PCRE2_ERROR_UTF8_ERR12 (-52)
#define PCRE2_ERROR_UTF8_ERR13 (-53)
#define PCRE2_ERROR_UTF8_ERR14 (-54)
#define PCRE2_ERROR_UTF8_ERR15 (-55)
#define PCRE2_ERROR_UTF8_ERR16 (-56)
#define PCRE2_ERROR_UTF8_ERR17 (-57)
#define PCRE2_ERROR_UTF8_ERR18 (-58)
#define PCRE2_ERROR_UTF8_ERR19 (-59)
#define PCRE2_ERROR_UTF8_ERR20 (-60)
#define PCRE2_ERROR_UTF8_ERR21 (-61)
/* Specific error codes for UTF-16 validity checks */
#define PCRE2_ERROR_UTF16_ERR1 (-52)
#define PCRE2_ERROR_UTF16_ERR2 (-53)
#define PCRE2_ERROR_UTF16_ERR3 (-54)
#define PCRE2_ERROR_UTF16_ERR1 (-62)
#define PCRE2_ERROR_UTF16_ERR2 (-63)
#define PCRE2_ERROR_UTF16_ERR3 (-64)
/* Specific error codes for UTF-32 validity checks */
#define PCRE2_ERROR_UTF32_ERR1 (-55)
#define PCRE2_ERROR_UTF32_ERR3 (-56)
#define PCRE2_ERROR_UTF32_ERR1 (-65)
#define PCRE2_ERROR_UTF32_ERR3 (-66)
/* Request types for pcre2_pattern_info() */
#define PCRE2_INFO_BACKREFMAX 0
#define PCRE2_INFO_CAPTURECOUNT 1
#define PCRE2_INFO_COMPILE_OPTIONS 2
#define PCRE2_INFO_FIRSTCODEUNIT 3
#define PCRE2_INFO_FIRSTCODETYPE 4
#define PCRE2_INFO_FIRSTTABLE 5
#define PCRE2_INFO_HASCRORLF 6
#define PCRE2_INFO_JCHANGED 7
#define PCRE2_INFO_JIT 8
#define PCRE2_INFO_JITSIZE 9
#define PCRE2_INFO_LASTCODEUNIT 10
#define PCRE2_INFO_LASTCODETYPE 11
#define PCRE2_INFO_MATCH_EMPTY 12
#define PCRE2_INFO_MATCH_LIMIT 13
#define PCRE2_INFO_MAXLOOKBEHIND 14
#define PCRE2_INFO_MINLENGTH 15
#define PCRE2_INFO_NAMECOUNT 16
#define PCRE2_INFO_NAMEENTRYSIZE 17
#define PCRE2_INFO_NAMETABLE 18
#define PCRE2_INFO_PATTERN_OPTIONS 19
#define PCRE2_INFO_RECURSION_LIMIT 20
#define PCRE2_INFO_SIZE 21
#define PCRE2_INFO_BSR_CONVENTION 1
#define PCRE2_INFO_CAPTURECOUNT 2
#define PCRE2_INFO_COMPILE_OPTIONS 3
#define PCRE2_INFO_FIRSTCODEUNIT 4
#define PCRE2_INFO_FIRSTCODETYPE 5
#define PCRE2_INFO_FIRSTBITMAP 6
#define PCRE2_INFO_HASCRORLF 7
#define PCRE2_INFO_JCHANGED 8
#define PCRE2_INFO_JIT 9
#define PCRE2_INFO_JITSIZE 10
#define PCRE2_INFO_LASTCODEUNIT 11
#define PCRE2_INFO_LASTCODETYPE 12
#define PCRE2_INFO_MATCH_EMPTY 13
#define PCRE2_INFO_MATCH_LIMIT 14
#define PCRE2_INFO_MAXLOOKBEHIND 15
#define PCRE2_INFO_MINLENGTH 16
#define PCRE2_INFO_NAMECOUNT 17
#define PCRE2_INFO_NAMEENTRYSIZE 18
#define PCRE2_INFO_NAMETABLE 19
#define PCRE2_INFO_NEWLINE_CONVENTION 20
#define PCRE2_INFO_PATTERN_OPTIONS 21
#define PCRE2_INFO_RECURSION_LIMIT 22
#define PCRE2_INFO_SIZE 23
/* Request types for pcre2_config(). */
@ -249,9 +257,8 @@ D is inspected during pcre2_dfa_exec() execution
#define PCRE2_CONFIG_MATCH_LIMIT_RECURSION 5
#define PCRE2_CONFIG_NEWLINE 6
#define PCRE2_CONFIG_PARENS_LIMIT 7
#define PCRE2_CONFIG_POSIX_MALLOC_THRESHOLD 8
#define PCRE2_CONFIG_STACKRECURSE 9
#define PCRE2_CONFIG_UTF 10
#define PCRE2_CONFIG_STACKRECURSE 8
#define PCRE2_CONFIG_UTF 9
/* A value that is used to indicate 'unset' in unsigned size_t fields. */

View File

@ -138,106 +138,114 @@ D is inspected during pcre2_dfa_exec() execution
/* Newline and \R settings, for use in the compile context. */
#define PCRE2_NEWLINE_CR 0
#define PCRE2_NEWLINE_LF 1
#define PCRE2_NEWLINE_CRLF 2
#define PCRE2_NEWLINE_ANY 3
#define PCRE2_NEWLINE_ANYCRLF 4
#define PCRE2_NEWLINE_DEFAULT 0
#define PCRE2_NEWLINE_CR 1
#define PCRE2_NEWLINE_LF 2
#define PCRE2_NEWLINE_CRLF 3
#define PCRE2_NEWLINE_ANY 4
#define PCRE2_NEWLINE_ANYCRLF 5
#define PCRE2_BSR_UNICODE 0
#define PCRE2_BSR_ANYCRLF 1
#define PCRE2_BSR_DEFAULT 0
#define PCRE2_BSR_UNICODE 1
#define PCRE2_BSR_ANYCRLF 2
/* Exec-time and get/set-time error codes */
/* Match-time and get/set-time error codes */
#define PCRE2_ERROR_NOMATCH (-1)
#define PCRE2_ERROR_NULL (-2)
#define PCRE2_ERROR_BADOPTION (-3)
#define PCRE2_ERROR_BADMAGIC (-4)
#define PCRE2_ERROR_UNKNOWN_OPCODE (-5)
#define PCRE2_ERROR_NOMEMORY (-6)
#define PCRE2_ERROR_NOSUBSTRING (-7)
#define PCRE2_ERROR_MATCHLIMIT (-8)
#define PCRE2_ERROR_CALLOUT (-9) /* Never used by PCRE2 itself */
#define PCRE2_ERROR_PARTIAL (-10)
#define PCRE2_ERROR_BADPARTIAL (-11)
#define PCRE2_ERROR_INTERNAL (-12)
#define PCRE2_ERROR_BADCOUNT (-13)
#define PCRE2_ERROR_DFA_UITEM (-14)
#define PCRE2_ERROR_DFA_UCOND (-15)
#define PCRE2_ERROR_DFA_UMLIMIT (-16)
#define PCRE2_ERROR_DFA_WSSIZE (-17)
#define PCRE2_ERROR_DFA_RECURSE (-18)
#define PCRE2_ERROR_RECURSIONLIMIT (-19)
#define PCRE2_ERROR_BADOFFSET (-20)
#define PCRE2_ERROR_BADCOUNT (-2)
#define PCRE2_ERROR_BADENDIANNESS (-3)
#define PCRE2_ERROR_BADLENGTH (-4)
#define PCRE2_ERROR_BADMAGIC (-5)
#define PCRE2_ERROR_BADMODE (-6)
#define PCRE2_ERROR_BADOFFSET (-7)
#define PCRE2_ERROR_BADOPTION (-8)
#define PCRE2_ERROR_BADPARTIAL (-9)
#define PCRE2_ERROR_BADUTF (-10)
#define PCRE2_ERROR_BADUTF_OFFSET (-11)
#define PCRE2_ERROR_CALLOUT (-12) /* Never used by PCRE2 itself */
#define PCRE2_ERROR_INTERNAL (-13)
#define PCRE2_ERROR_JIT_BADOPTION (-14)
#define PCRE2_ERROR_JIT_STACKLIMIT (-15)
#define PCRE2_ERROR_MATCHLIMIT (-16)
#define PCRE2_ERROR_NOMEMORY (-17)
#define PCRE2_ERROR_NOSUBSTRING (-18)
#define PCRE2_ERROR_NULL (-19)
#define PCRE2_ERROR_PARTIAL (-20)
#define PCRE2_ERROR_RECURSELOOP (-21)
#define PCRE2_ERROR_JIT_STACKLIMIT (-22)
#define PCRE2_ERROR_BADMODE (-23)
#define PCRE2_ERROR_BADENDIANNESS (-24)
#define PCRE2_ERROR_DFA_BADRESTART (-25)
#define PCRE2_ERROR_JIT_BADOPTION (-26)
#define PCRE2_ERROR_BADLENGTH (-27)
#define PCRE2_ERROR_UNSET (-28)
#define PCRE2_ERROR_BADUTF_OFFSET (-29)
#define PCRE2_ERROR_RECURSIONLIMIT (-22)
#define PCRE2_ERROR_UNKNOWN_OPCODE (-23)
#define PCRE2_ERROR_UNSET (-24)
#define PCRE2_ERROR_DFA_BADRESTART (-30)
#define PCRE2_ERROR_DFA_RECURSE (-31)
#define PCRE2_ERROR_DFA_UCOND (-32)
#define PCRE2_ERROR_DFA_UITEM (-33)
#define PCRE2_ERROR_DFA_UMLIMIT (-34)
#define PCRE2_ERROR_DFA_WSSIZE (-35)
/* Specific error codes for UTF-8 validity checks */
#define PCRE2_ERROR_UTF8_ERR1 (-31)
#define PCRE2_ERROR_UTF8_ERR2 (-32)
#define PCRE2_ERROR_UTF8_ERR3 (-33)
#define PCRE2_ERROR_UTF8_ERR4 (-34)
#define PCRE2_ERROR_UTF8_ERR5 (-35)
#define PCRE2_ERROR_UTF8_ERR6 (-36)
#define PCRE2_ERROR_UTF8_ERR7 (-37)
#define PCRE2_ERROR_UTF8_ERR8 (-38)
#define PCRE2_ERROR_UTF8_ERR9 (-39)
#define PCRE2_ERROR_UTF8_ERR10 (-40)
#define PCRE2_ERROR_UTF8_ERR11 (-41)
#define PCRE2_ERROR_UTF8_ERR12 (-42)
#define PCRE2_ERROR_UTF8_ERR13 (-43)
#define PCRE2_ERROR_UTF8_ERR14 (-44)
#define PCRE2_ERROR_UTF8_ERR15 (-45)
#define PCRE2_ERROR_UTF8_ERR16 (-46)
#define PCRE2_ERROR_UTF8_ERR17 (-47)
#define PCRE2_ERROR_UTF8_ERR18 (-48)
#define PCRE2_ERROR_UTF8_ERR19 (-49)
#define PCRE2_ERROR_UTF8_ERR20 (-50)
#define PCRE2_ERROR_UTF8_ERR21 (-51)
#define PCRE2_ERROR_UTF8_ERR1 (-41)
#define PCRE2_ERROR_UTF8_ERR2 (-42)
#define PCRE2_ERROR_UTF8_ERR3 (-43)
#define PCRE2_ERROR_UTF8_ERR4 (-44)
#define PCRE2_ERROR_UTF8_ERR5 (-45)
#define PCRE2_ERROR_UTF8_ERR6 (-46)
#define PCRE2_ERROR_UTF8_ERR7 (-47)
#define PCRE2_ERROR_UTF8_ERR8 (-48)
#define PCRE2_ERROR_UTF8_ERR9 (-49)
#define PCRE2_ERROR_UTF8_ERR10 (-50)
#define PCRE2_ERROR_UTF8_ERR11 (-51)
#define PCRE2_ERROR_UTF8_ERR12 (-52)
#define PCRE2_ERROR_UTF8_ERR13 (-53)
#define PCRE2_ERROR_UTF8_ERR14 (-54)
#define PCRE2_ERROR_UTF8_ERR15 (-55)
#define PCRE2_ERROR_UTF8_ERR16 (-56)
#define PCRE2_ERROR_UTF8_ERR17 (-57)
#define PCRE2_ERROR_UTF8_ERR18 (-58)
#define PCRE2_ERROR_UTF8_ERR19 (-59)
#define PCRE2_ERROR_UTF8_ERR20 (-60)
#define PCRE2_ERROR_UTF8_ERR21 (-61)
/* Specific error codes for UTF-16 validity checks */
#define PCRE2_ERROR_UTF16_ERR1 (-52)
#define PCRE2_ERROR_UTF16_ERR2 (-53)
#define PCRE2_ERROR_UTF16_ERR3 (-54)
#define PCRE2_ERROR_UTF16_ERR1 (-62)
#define PCRE2_ERROR_UTF16_ERR2 (-63)
#define PCRE2_ERROR_UTF16_ERR3 (-64)
/* Specific error codes for UTF-32 validity checks */
#define PCRE2_ERROR_UTF32_ERR1 (-55)
#define PCRE2_ERROR_UTF32_ERR3 (-56)
#define PCRE2_ERROR_UTF32_ERR1 (-65)
#define PCRE2_ERROR_UTF32_ERR3 (-66)
/* Request types for pcre2_pattern_info() */
#define PCRE2_INFO_BACKREFMAX 0
#define PCRE2_INFO_CAPTURECOUNT 1
#define PCRE2_INFO_COMPILE_OPTIONS 2
#define PCRE2_INFO_FIRSTCODEUNIT 3
#define PCRE2_INFO_FIRSTCODETYPE 4
#define PCRE2_INFO_FIRSTTABLE 5
#define PCRE2_INFO_HASCRORLF 6
#define PCRE2_INFO_JCHANGED 7
#define PCRE2_INFO_JIT 8
#define PCRE2_INFO_JITSIZE 9
#define PCRE2_INFO_LASTCODEUNIT 10
#define PCRE2_INFO_LASTCODETYPE 11
#define PCRE2_INFO_MATCH_EMPTY 12
#define PCRE2_INFO_MATCH_LIMIT 13
#define PCRE2_INFO_MAXLOOKBEHIND 14
#define PCRE2_INFO_MINLENGTH 15
#define PCRE2_INFO_NAMECOUNT 16
#define PCRE2_INFO_NAMEENTRYSIZE 17
#define PCRE2_INFO_NAMETABLE 18
#define PCRE2_INFO_PATTERN_OPTIONS 19
#define PCRE2_INFO_RECURSION_LIMIT 20
#define PCRE2_INFO_SIZE 21
#define PCRE2_INFO_BSR_CONVENTION 1
#define PCRE2_INFO_CAPTURECOUNT 2
#define PCRE2_INFO_COMPILE_OPTIONS 3
#define PCRE2_INFO_FIRSTCODEUNIT 4
#define PCRE2_INFO_FIRSTCODETYPE 5
#define PCRE2_INFO_FIRSTBITMAP 6
#define PCRE2_INFO_HASCRORLF 7
#define PCRE2_INFO_JCHANGED 8
#define PCRE2_INFO_JIT 9
#define PCRE2_INFO_JITSIZE 10
#define PCRE2_INFO_LASTCODEUNIT 11
#define PCRE2_INFO_LASTCODETYPE 12
#define PCRE2_INFO_MATCH_EMPTY 13
#define PCRE2_INFO_MATCH_LIMIT 14
#define PCRE2_INFO_MAXLOOKBEHIND 15
#define PCRE2_INFO_MINLENGTH 16
#define PCRE2_INFO_NAMECOUNT 17
#define PCRE2_INFO_NAMEENTRYSIZE 18
#define PCRE2_INFO_NAMETABLE 19
#define PCRE2_INFO_NEWLINE_CONVENTION 20
#define PCRE2_INFO_PATTERN_OPTIONS 21
#define PCRE2_INFO_RECURSION_LIMIT 22
#define PCRE2_INFO_SIZE 23
/* Request types for pcre2_config(). */
@ -249,9 +257,8 @@ D is inspected during pcre2_dfa_exec() execution
#define PCRE2_CONFIG_MATCH_LIMIT_RECURSION 5
#define PCRE2_CONFIG_NEWLINE 6
#define PCRE2_CONFIG_PARENS_LIMIT 7
#define PCRE2_CONFIG_POSIX_MALLOC_THRESHOLD 8
#define PCRE2_CONFIG_STACKRECURSE 9
#define PCRE2_CONFIG_UTF 10
#define PCRE2_CONFIG_STACKRECURSE 8
#define PCRE2_CONFIG_UTF 9
/* A value that is used to indicate 'unset' in unsigned size_t fields. */

View File

@ -55,8 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_code_free(pcre2_code *code)
{
code=code;
return;
if (code != NULL) code->memctl.free(code, code->memctl.memory_data);
}
@ -86,9 +85,16 @@ PCRE2_EXP_DEFN pcre2_code * PCRE2_CALL_CONVENTION
pcre2_compile(PCRE2_SPTR pattern, int patlen, uint32_t options, int *errorcode,
size_t *erroroffset, pcre2_compile_context *ccontext)
{
pcre2_compile_context default_context;
pcre2_code *c = NULL;
patlen = patlen; options = options;
patlen = patlen;
if (ccontext == NULL)
{
PRIV(compile_context_init)(&default_context, TRUE);
ccontext = &default_context;
}
/* Fudge while testing pcre2test. */
@ -96,12 +102,21 @@ patlen = patlen; options = options;
if (pattern[0] == 'Y')
{
c = ccontext->malloc(sizeof(pcre2_real_code), NULL);
c = ccontext->memctl.malloc(sizeof(pcre2_real_code), NULL);
c->memctl = ccontext->memctl;
c->magic_number = MAGIC_NUMBER;
c->size = sizeof(pcre2_real_code);
c->name_table_offset = sizeof(pcre2_real_code);
c->compile_options = options;
c->flags = PCRE2_CODE_UNIT_WIDTH/8;
c->limit_match = 0;
c->limit_recursion = 0;
c->max_lookbehind = 0;
c->minlength = 3;
c->top_bracket = 1;
c->top_backref = 1;
c->bsr_convention = ccontext->bsr_convention;
c->newline_convention = ccontext->newline_convention;
c->name_count = 0;
c->name_entry_size = 0;
}

View File

@ -109,10 +109,6 @@ switch (what)
*((unsigned long int *)where) = PARENS_NEST_LIMIT;
break;
case PCRE2_CONFIG_POSIX_MALLOC_THRESHOLD:
*((int *)where) = POSIX_MALLOC_THRESHOLD;
break;
case PCRE2_CONFIG_STACKRECURSE:
#ifdef NO_RECURSE
*((int *)where) = 0;

View File

@ -69,9 +69,50 @@ free(block);
/*************************************************
* Create contexts *
* Get a block and save memory control *
*************************************************/
/* This internal function is called to get a block of memory in which the
memory control data is to be stored for future use.
Arguments:
size amount of memory required
offset offset in memory block to memctl structure
gcontext a general context or NULL
Returns: pointer to memory or NULL on failure
*/
PCRE2_EXP_DEFN void *
PRIV(memctl_malloc)(size_t size, size_t offset,
pcre2_general_context *gcontext)
{
pcre2_memctl *memctl;
void *yield = (gcontext == NULL)? malloc(size) :
gcontext->memctl.malloc(size, gcontext->memctl.memory_data);
if (yield == NULL) return NULL;
memctl = (pcre2_memctl *)(((uint8_t *)yield) + offset);
if (gcontext == NULL)
{
memctl->malloc = default_malloc;
memctl->free = default_free;
memctl->memory_data = NULL;
}
else *memctl = gcontext->memctl;
return yield;
}
/*************************************************
* Create and initialize contexts *
*************************************************/
/* Initializing for compile and match contexts is done in separate, private
functions so that these can be called from functions such as pcre2_compile()
when an external context is not supplied. The initializing functions have an
option to set up default memory management. */
PCRE2_EXP_DEFN pcre2_general_context * PCRE2_CALL_CONVENTION
pcre2_general_context_create(void *(*private_malloc)(size_t, void *),
void (*private_free)(void *, void *), void *memory_data)
@ -80,81 +121,72 @@ pcre2_general_context *gcontext;
if (private_malloc == NULL) private_malloc = default_malloc;
if (private_free == NULL) private_free = default_free;
gcontext = private_malloc(sizeof(pcre2_real_general_context), memory_data);
gcontext->malloc = private_malloc;
gcontext->free = private_free;
gcontext->memory_data = memory_data;
if (gcontext == NULL) return NULL;
gcontext->memctl.malloc = private_malloc;
gcontext->memctl.free = private_free;
gcontext->memctl.memory_data = memory_data;
return gcontext;
}
PCRE2_EXP_DEFN void
PRIV(compile_context_init)(pcre2_compile_context *ccontext, BOOL defmemctl)
{
if (defmemctl)
{
ccontext->memctl.malloc = default_malloc;
ccontext->memctl.free = default_free;
ccontext->memctl.memory_data = NULL;
}
ccontext->stack_guard = NULL;
ccontext->tables = PRIV(default_tables);
ccontext->bsr_convention = PCRE2_BSR_DEFAULT;
ccontext->newline_convention = PCRE2_NEWLINE_DEFAULT;
ccontext->parens_nest_limit = PARENS_NEST_LIMIT;
}
PCRE2_EXP_DEFN pcre2_compile_context * PCRE2_CALL_CONVENTION
pcre2_compile_context_create(pcre2_general_context *gcontext)
{
pcre2_compile_context *ccontext;
void *(*compile_malloc)(size_t, void *);
void (*compile_free)(void *, void *);
void *memory_data;
if (gcontext == NULL)
{
compile_malloc = default_malloc;
compile_free = default_free;
memory_data = NULL;
}
else
{
compile_malloc = gcontext->malloc;
compile_free = gcontext->free;
memory_data = gcontext->memory_data;
}
ccontext = compile_malloc(sizeof(pcre2_real_compile_context), memory_data);
pcre2_compile_context *ccontext = PRIV(memctl_malloc)(
sizeof(pcre2_real_compile_context),
offsetof(pcre2_real_compile_context, memctl),
gcontext);
if (ccontext == NULL) return NULL;
ccontext->malloc = compile_malloc;
ccontext->free = compile_free;
ccontext->memory_data = memory_data;
ccontext->stack_guard = NULL;
ccontext->tables = PRIV(default_tables);
#ifdef BSR_ANYCRLF
ccontext->bsr_convention = PCRE2_BSR_ANYCRLF;
#else
ccontext->bsr_convention = PCRE2_BSR_UNICODE;
#endif
ccontext->newline_convention = NEWLINE;
ccontext->parens_nest_limit = PARENS_NEST_LIMIT;
PRIV(compile_context_init)(ccontext, FALSE);
return ccontext;
}
PCRE2_EXP_DEFN void
PRIV(match_context_init)(pcre2_match_context *mcontext, BOOL defmemctl)
{
if (defmemctl)
{
mcontext->memctl.malloc = default_malloc;
mcontext->memctl.free = default_free;
mcontext->memctl.memory_data = NULL;
}
#ifdef NO_RECURSE
mcontext->stack_malloc = mcontext->malloc;
mcontext->stack_free = mcontext->free;
#endif
mcontext->callout = NULL;
mcontext->match_limit = MATCH_LIMIT;
mcontext->recursion_limit = MATCH_LIMIT_RECURSION;
}
PCRE2_EXP_DEFN pcre2_match_context * PCRE2_CALL_CONVENTION
pcre2_match_context_create(pcre2_general_context *gcontext)
{
pcre2_match_context *mcontext;
void *(*match_malloc)(size_t, void *);
void (*match_free)(void *, void *);
void *memory_data;
if (gcontext == NULL)
{
match_malloc = default_malloc;
match_free = default_free;
memory_data = NULL;
}
else
{
match_malloc = gcontext->malloc;
match_free = gcontext->free;
memory_data = gcontext->memory_data;
}
mcontext = match_malloc(sizeof(pcre2_real_match_context), memory_data);
pcre2_match_context *mcontext = PRIV(memctl_malloc)(
sizeof(pcre2_real_match_context),
offsetof(pcre2_real_compile_context, memctl),
gcontext);
if (mcontext == NULL) return NULL;
mcontext->malloc = match_malloc;
mcontext->free = match_free;
mcontext->memory_data = memory_data;
#ifdef NO_RECURSE
mcontext->stack_malloc = match_malloc;
mcontext->stack_free = match_free;
#endif
mcontext->callout = NULL;
mcontext->match_limit = MATCH_LIMIT;
mcontext->recursion_limit = MATCH_LIMIT_RECURSION;
PRIV(match_context_init)(mcontext, FALSE);
return mcontext;
}
@ -167,7 +199,8 @@ PCRE2_EXP_DEFN pcre2_general_context * PCRE2_CALL_CONVENTION
pcre2_general_context_copy(pcre2_general_context *gcontext)
{
pcre2_general_context *new =
gcontext->malloc(sizeof(pcre2_real_general_context), gcontext->memory_data);
gcontext->memctl.malloc(sizeof(pcre2_real_general_context),
gcontext->memctl.memory_data);
if (new == NULL) return NULL;
memcpy(new, gcontext, sizeof(pcre2_real_general_context));
return new;
@ -178,7 +211,8 @@ PCRE2_EXP_DEFN pcre2_compile_context * PCRE2_CALL_CONVENTION
pcre2_compile_context_copy(pcre2_compile_context *ccontext)
{
pcre2_compile_context *new =
ccontext->malloc(sizeof(pcre2_real_compile_context), ccontext->memory_data);
ccontext->memctl.malloc(sizeof(pcre2_real_compile_context),
ccontext->memctl.memory_data);
if (new == NULL) return NULL;
memcpy(new, ccontext, sizeof(pcre2_real_compile_context));
return new;
@ -189,7 +223,8 @@ PCRE2_EXP_DEFN pcre2_match_context * PCRE2_CALL_CONVENTION
pcre2_match_context_copy(pcre2_match_context *mcontext)
{
pcre2_match_context *new =
mcontext->malloc(sizeof(pcre2_real_match_context), mcontext->memory_data);
mcontext->memctl.malloc(sizeof(pcre2_real_match_context),
mcontext->memctl.memory_data);
if (new == NULL) return NULL;
memcpy(new, mcontext, sizeof(pcre2_real_match_context));
return new;
@ -205,21 +240,21 @@ return new;
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_general_context_free(pcre2_general_context *gcontext)
{
gcontext->free(gcontext, gcontext->memory_data);
gcontext->memctl.free(gcontext, gcontext->memctl.memory_data);
}
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_compile_context_free(pcre2_compile_context *ccontext)
{
ccontext->free(ccontext, ccontext->memory_data);
ccontext->memctl.free(ccontext, ccontext->memctl.memory_data);
}
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_match_context_free(pcre2_match_context *mcontext)
{
mcontext->free(mcontext, mcontext->memory_data);
mcontext->memctl.free(mcontext, mcontext->memctl.memory_data);
}

View File

@ -1,5 +1,44 @@
/* This is a placeholder, just enough to allow dummy functions to compile, but
with some of the new PCRE2 context stuff added. */
/*************************************************
* 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) 2014 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.
-----------------------------------------------------------------------------
*/
/* FIXME: this file is incomplete, being gradually built. */
#include <ctype.h>
#include <limits.h>
@ -22,7 +61,6 @@ with some of the new PCRE2 context stuff added. */
extern const uint8_t PRIV(default_tables)[];
/* What follows is "real" code for PCRE2. */
typedef int BOOL;
@ -134,17 +172,18 @@ bytes in a code unit in that mode. */
#define PCRE2_MODE8 0x00000001 /* compiled in 8 bit mode */
#define PCRE2_MODE16 0x00000002 /* compiled in 16 bit mode */
#define PCRE2_MODE32 0x00000004 /* compiled in 32 bit mode */
#define PCRE2_FIRSTSET 0x00000010 /* first_char is set */
#define PCRE2_FCH_CASELESS 0x00000020 /* caseless first char */
#define PCRE2_REQCHSET 0x00000040 /* req_byte is set */
#define PCRE2_RCH_CASELESS 0x00000080 /* caseless requested char */
#define PCRE2_STARTLINE 0x00000100 /* start after \n for multiline */
#define PCRE2_JCHANGED 0x00000200 /* j option used in pattern */
#define PCRE2_HASCRORLF 0x00000400 /* explicit \r or \n in pattern */
#define PCRE2_HASTHEN 0x00000800 /* pattern contains (*THEN) */
#define PCRE2_MLSET 0x00001000 /* match limit set by pattern */
#define PCRE2_RLSET 0x00002000 /* recursion limit set by pattern */
#define PCRE2_MATCH_EMPTY 0x00004000 /* pattern can match empty string */
#define PCRE2_FIRSTSET 0x00000010 /* first_code unit is set */
#define PCRE2_FIRSTCASELESS 0x00000020 /* caseless first code unit */
#define PCRE2_FIRSTMAPSET 0x00000040 /* bitmap of first code units is set */
#define PCRE2_LASTSET 0x00000080 /* last code unit is set */
#define PCRE2_LASTCASELESS 0x00000100 /* caseless last code unit */
#define PCRE2_STARTLINE 0x00000200 /* start after \n for multiline */
#define PCRE2_JCHANGED 0x00000400 /* j option used in pattern */
#define PCRE2_HASCRORLF 0x00000800 /* explicit \r or \n in pattern */
#define PCRE2_HASTHEN 0x00001000 /* pattern contains (*THEN) */
#define PCRE2_MLSET 0x00002000 /* match limit set by pattern */
#define PCRE2_RLSET 0x00004000 /* recursion limit set by pattern */
#define PCRE2_MATCH_EMPTY 0x00008000 /* pattern can match empty string */
#define PCRE2_MODE_MASK (PCRE2_MODE8 | PCRE2_MODE16 | PCRE2_MODE32)
@ -762,23 +801,40 @@ only. */
/* -------------------- End of character and string names -------------------*/
/* Private structures that are mode-independent. */
/* Structure to hold data for custom memory management. */
/* Only these bits are allowed when setting context options. */
typedef struct pcre2_memctl {
void * (*malloc)(size_t, void *);
void (*free)(void *, void *);
void *memory_data;
} pcre2_memctl;
#define PCRE2_CONTEXT_OPTIONS (\
PCRE2_ALT_BSUX|PCRE2_DOLLAR_ENDONLY|PCRE2_DUPNAMES|PCRE2_ALLOW_EMPTY_CLASS|\
PCRE2_MATCH_UNSET_BACKREF|PCRE2_NEVER_UTF|PCRE2_NEVER_UCP|PCRE2_UTF|\
PCRE2_UCP)
/* The private structures used by PCRE are defined in a separate file. When
compiling the library, PCRE2_CODE_UNIT_WIDTH will be defined, so we include
them at the appropriate width. When compiling pcretest, however, that macro is
not set at this point because pcretest needs to include them at all supported
widths. */
/* The other private structures used by PCRE are defined in a separate file.
When compiling the library, PCRE2_CODE_UNIT_WIDTH will be defined, and we
include them at the appropriate width. When compiling pcre2test, however, that
macro is not set at this point because pcre2test needs to include them at all
supported widths. */
#ifdef PCRE2_CODE_UNIT_WIDTH
#include "pcre2_intstructs.h"
#endif
/* Internal shared functions. These are functions that are used by more than
one of the library's exported public functions. They have to be "external" in
the C sense, but are not part of the PCRE public API. They are not referenced
from pcre2test, and must not be defined when no code unit width is available.
*/
#ifdef PCRE2_CODE_UNIT_WIDTH
#define _pcre2_compile_context_init PCRE2_SUFFIX(_pcre2_compile_context_init_)
#define _pcre2_match_context_init PCRE2_SUFFIX(_pcre2_match_context_init_)
#define _pcre2_memctl_malloc PCRE2_SUFFIX(_pcre2_memctl_malloc_)
extern void _pcre2_compile_context_init(pcre2_compile_context *, BOOL);
extern void _pcre2_match_context_init(pcre2_match_context *, BOOL);
extern void *_pcre2_memctl_malloc(size_t, size_t, pcre2_general_context *);
#endif
/* End of pcre2_internal.h */

View File

@ -38,25 +38,21 @@ POSSIBILITY OF SUCH DAMAGE.
-----------------------------------------------------------------------------
*/
/* This module contains the private structures needed by pcre2_internal.h. They
are kept separate so that they can be #included multiple times for different
code unit widths by pcre2test. */
/* This module contains the private mode-dependent structures needed by
pcre2_internal.h. They are kept separate so that they can be #included multiple
times for different code unit widths by pcre2test. */
/* The real general context structure */
/* The real general context structure. At present it hold only data for custom
memory control. */
typedef struct pcre2_real_general_context {
void * (*malloc)(size_t, void *);
void (*free)(void *, void *);
void *memory_data;
pcre2_memctl memctl;
} pcre2_real_general_context;
/* The real compile context structure */
typedef struct pcre2_real_compile_context {
void * (*malloc)(size_t, void *);
void (*free)(void *, void *);
void * memory_data;
pcre2_memctl memctl;
int (*stack_guard)(uint32_t);
const unsigned char *tables;
uint16_t bsr_convention;
@ -67,9 +63,7 @@ typedef struct pcre2_real_compile_context {
/* The real match context structure. */
typedef struct pcre2_real_match_context {
void * (*malloc)(size_t, void *);
void (*free)(void *, void *);
void * memory_data;
pcre2_memctl memctl;
#ifdef NO_RECURSE
void * (*stack_malloc)(size_t, void *);
void (*stack_free)(void *, void *);
@ -79,19 +73,37 @@ typedef struct pcre2_real_match_context {
uint32_t recursion_limit;
} pcre2_real_match_context;
/* The reat match data structure. */
typedef struct pcre2_real_match_data {
pcre2_memctl memctl;
size_t leftchar; /* Offset to leftmost code unit */
size_t rightchar; /* Offset to rightmost code unit */
size_t startchar; /* Offset to starting code unit */
PCRE2_SPTR mark; /* Pointer to last mark */
uint16_t oveccount; /* Number of pairs */
size_t ovector[1]; /* The first field */
} pcre2_real_match_data;
/* The real compiled code structure */
typedef struct pcre2_real_code {
uint32_t magic_number;
pcre2_memctl memctl;
void *executable_jit; /* Pointer to JIT code */
uint8_t start_bitmap[32]; /* Bitmap for starting code unit < 256 */
uint32_t magic_number; /* Paranoid and endianness check */
uint32_t size; /* Total that was malloc-ed */
uint32_t compile_options; /* Options passed to pcre2_compile() */
uint32_t pattern_options; /* Options taken from the pattern */
uint32_t flags; /* Various state flags */
uint32_t limit_match; /* Limit set in the pattern */
uint32_t limit_recursion; /* Limit set in the pattern */
uint32_t first_char; /* Starting character */
uint32_t req_char; /* This character must be seen */
uint32_t first_codeunit; /* Starting code unit */
uint32_t last_codeunit; /* This codeunit must be seen */
uint16_t bsr_convention; /* What \R matches */
uint16_t newline_convention; /* What is a newline? */
uint16_t max_lookbehind; /* Longest lookbehind (characters) */
uint16_t minlength; /* Minimum length of match */
uint16_t top_bracket; /* Highest numbered group */
uint16_t top_backref; /* Highest numbered back reference */
uint16_t name_table_offset; /* Offset to name table that follows */

View File

@ -76,6 +76,33 @@ pcre2_match( const pcre2_code *code, PCRE2_SPTR subject, int length,
size_t start_offset, uint32_t options, pcre2_match_data *match_data,
pcre2_match_context *mcontext)
{
/* Fudge for testing pcre2test */
if (subject[start_offset] == 'Y')
{
match_data->leftchar = 0;
match_data->rightchar = 3;
match_data->startchar = 0;
match_data->mark = NULL;
switch (match_data->oveccount)
{
case 0: return 0;
case 1: match_data->ovector[0] = start_offset;
match_data->ovector[1] = start_offset + 4;
return 0;
default: match_data->ovector[0] = start_offset;
match_data->ovector[1] = start_offset + 4;
match_data->ovector[2] = start_offset + 1;
match_data->ovector[3] = start_offset + 3;
return 2;
}
}
mcontext=mcontext;code=code;subject=subject;length=length;
start_offset=start_offset; options=options; match_data=match_data;
return PCRE2_ERROR_NOMATCH;

View File

@ -46,17 +46,19 @@ POSSIBILITY OF SUCH DAMAGE.
#include "pcre2_internal.h"
/* FIXME: these are all dummy functions */
/*************************************************
* Create a match data block given ovector size *
*************************************************/
PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION
pcre2_match_data_create(size_t ovecsize, pcre2_general_context *gcontext)
pcre2_match_data_create(size_t oveccount, pcre2_general_context *gcontext)
{
gcontext=gcontext;ovecsize=ovecsize;
return NULL;
pcre2_match_data *yield = PRIV(memctl_malloc)(
sizeof(pcre2_match_data) + 3*oveccount*sizeof(size_t),
offsetof(pcre2_real_match_data, memctl), gcontext);
yield->oveccount = oveccount;
return yield;
}
@ -69,8 +71,8 @@ PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION
pcre2_match_data_create_from_pattern(pcre2_code *code,
pcre2_general_context *gcontext)
{
code=code;gcontext=gcontext;
return NULL;
return pcre2_match_data_create(((pcre2_real_code *)code)->top_bracket + 1,
gcontext);
}
@ -82,8 +84,8 @@ return NULL;
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_match_data_free(pcre2_match_data *match_data)
{
match_data=match_data;
return;
if (match_data != NULL)
match_data->memctl.free(match_data, match_data->memctl.memory_data);
}
@ -95,8 +97,7 @@ return;
PCRE2_EXP_DEFN size_t PCRE2_CALL_CONVENTION
pcre2_get_leftchar(pcre2_match_data *match_data)
{
match_data=match_data;
return 0;
return match_data->leftchar;
}
@ -108,8 +109,7 @@ return 0;
PCRE2_EXP_DEFN PCRE2_SPTR PCRE2_CALL_CONVENTION
pcre2_get_mark(pcre2_match_data *match_data)
{
match_data=match_data;
return NULL;
return match_data->mark;
}
@ -121,8 +121,7 @@ return NULL;
PCRE2_EXP_DEFN size_t * PCRE2_CALL_CONVENTION
pcre2_get_ovector_pointer(pcre2_match_data *match_data)
{
match_data=match_data;
return NULL;
return match_data->ovector;
}
@ -134,8 +133,7 @@ return NULL;
PCRE2_EXP_DEFN size_t PCRE2_CALL_CONVENTION
pcre2_get_ovector_count(pcre2_match_data *match_data)
{
match_data=match_data;
return 0;
return match_data->oveccount;
}
@ -147,8 +145,7 @@ return 0;
PCRE2_EXP_DEFN size_t PCRE2_CALL_CONVENTION
pcre2_get_rightchar(pcre2_match_data *match_data)
{
match_data=match_data;
return 0;
return match_data->rightchar;
}
@ -160,8 +157,7 @@ return 0;
PCRE2_EXP_DEFN size_t PCRE2_CALL_CONVENTION
pcre2_get_startchar(pcre2_match_data *match_data)
{
match_data=match_data;
return 0;
return match_data->startchar;
}
/* End of pcre2_match_data.c */

View File

@ -84,6 +84,80 @@ if ((re->flags & (PCRE2_CODE_UNIT_WIDTH/8)) == 0)
switch(what)
{
case PCRE2_INFO_BACKREFMAX:
*((int *)where) = re->top_backref;
break;
case PCRE2_INFO_BSR_CONVENTION:
*((uint32_t *)where) = re->bsr_convention;
break;
case PCRE2_INFO_CAPTURECOUNT:
*((int *)where) = re->top_bracket;
break;
case PCRE2_INFO_COMPILE_OPTIONS:
*((int *)where) = re->compile_options;
break;
case PCRE2_INFO_FIRSTCODETYPE:
*((int *)where) = ((re->flags & PCRE2_FIRSTSET) != 0)? 1 :
((re->flags & PCRE2_STARTLINE) != 0)? 2 : 0;
break;
case PCRE2_INFO_FIRSTCODEUNIT:
*((uint32_t *)where) = ((re->flags & PCRE2_FIRSTSET) != 0)?
re->first_codeunit : 0;
break;
case PCRE2_INFO_FIRSTBITMAP:
*((const uint8_t **)where) = ((re->flags & PCRE2_FIRSTMAPSET) != 0)?
&(re->start_bitmap[0]) : NULL;
break;
case PCRE2_INFO_HASCRORLF:
*((int *)where) = (re->flags & PCRE2_HASCRORLF) != 0;
break;
case PCRE2_INFO_JCHANGED:
*((int *)where) = (re->flags & PCRE2_JCHANGED) != 0;
break;
case PCRE2_INFO_JITSIZE:
#ifdef SUPPORT_JIT
*((size_t *)where) = (re->executable_jit != NULL)?
PRIV(jit_get_size)(re->executable_jit) : 0;
#else
*((size_t *)where) = 0;
#endif
break;
case PCRE2_INFO_LASTCODETYPE:
*((int *)where) = ((re->flags & PCRE2_LASTSET) != 0)? 1 : 0;
break;
case PCRE2_INFO_LASTCODEUNIT:
*((uint32_t *)where) = ((re->flags & PCRE2_LASTSET) != 0)?
re->last_codeunit : 0;
break;
case PCRE2_INFO_MATCH_EMPTY:
*((int *)where) = (re->flags & PCRE2_MATCH_EMPTY) != 0;
break;
case PCRE2_INFO_MATCH_LIMIT:
if ((re->flags & PCRE2_MLSET) == 0) return PCRE2_ERROR_UNSET;
*((uint32_t *)where) = re->limit_match;
break;
case PCRE2_INFO_MAXLOOKBEHIND:
*((int *)where) = re->max_lookbehind;
break;
case PCRE2_INFO_MINLENGTH:
*((int *)where) = re->minlength;
break;
case PCRE2_INFO_NAMEENTRYSIZE:
*((int *)where) = re->name_entry_size;
break;
@ -92,19 +166,25 @@ switch(what)
*((int *)where) = re->name_count;
break;
case PCRE2_INFO_SIZE:
*((size_t *)where) = re->size;
case PCRE2_INFO_NAMETABLE:
*((PCRE2_SPTR*)where) = (PCRE2_SPTR)re + re->name_table_offset;
break;
case PCRE2_INFO_JITSIZE:
#ifdef SUPPORT_JIT
*((size_t *)where) =
(re->flags & PCRE2_EXTRA_EXECUTABLE_JIT) != 0 &&
re->executable_jit != NULL)?
PRIV(jit_get_size)(re->executable_jit) : 0;
#else
*((size_t *)where) = 0;
#endif
case PCRE2_INFO_NEWLINE_CONVENTION:
*((uint32_t *)where) = re->newline_convention;
break;
case PCRE2_INFO_PATTERN_OPTIONS:
*((int *)where) = re->pattern_options;
break;
case PCRE2_INFO_RECURSION_LIMIT:
if ((re->flags & PCRE2_RLSET) == 0) return PCRE2_ERROR_UNSET;
*((uint32_t *)where) = re->limit_recursion;
break;
case PCRE2_INFO_SIZE:
*((size_t *)where) = re->size;
break;
default: return PCRE2_ERROR_BADOPTION;

View File

@ -68,24 +68,19 @@ already set. */
#include "pcre2_internal.h"
#include "pcre2posix.h"
/* 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
don't. */
/* FIXME: The compile/match functions have not yet been converted to PCRE2.
They currently always fail. */
/* FIXME: This needs re-designing to be less silly. */
/* Table to translate PCRE2 compile time error codes into POSIX error codes. */
static const int eint[] = {
0, /* no error */
static const int eint1[] = {
0, /* No error */
REG_EESCAPE, /* \ at end of pattern */
REG_EESCAPE, /* \c at end of pattern */
REG_EESCAPE, /* unrecognized character follows \ */
REG_BADBR, /* numbers out of order in {} quantifier */
/* 5 */
REG_BADBR, /* number too big in {} quantifier */
5, REG_BADBR, /* number too big in {} quantifier */
REG_EBRACK, /* missing terminating ] for character class */
REG_ECTYPE, /* invalid escape sequence in character class */
REG_ERANGE, /* range out of order in character class */
@ -106,82 +101,15 @@ static const int eint[] = {
REG_ESIZE, /* regular expression too large */
REG_ESPACE, /* failed to get memory */
REG_EPAREN, /* unmatched parentheses */
REG_ASSERT, /* internal error: code overflow */
REG_BADPAT, /* unrecognized character after (?< */
/* 25 */
REG_BADPAT, /* lookbehind assertion is not fixed length */
REG_BADPAT, /* malformed number or name after (?( */
REG_BADPAT, /* conditional group contains more than two branches */
REG_BADPAT, /* assertion expected after (?( */
REG_BADPAT, /* (?R or (?[+-]digits must be followed by ) */
/* 30 */
REG_ECTYPE, /* unknown POSIX class name */
REG_BADPAT, /* POSIX collating elements are not supported */
REG_INVARG, /* this version of PCRE2 is not compiled with PCRE2_UTF8 support */
REG_BADPAT, /* spare error */
REG_BADPAT, /* character value in \x{} or \o{} is too large */
/* 35 */
REG_BADPAT, /* invalid condition (?(0) */
REG_BADPAT, /* \C not allowed in lookbehind assertion */
REG_EESCAPE, /* PCRE2 does not support \L, \l, \N, \U, or \u */
REG_BADPAT, /* number after (?C is > 255 */
REG_BADPAT, /* closing ) for (?C expected */
/* 40 */
REG_BADPAT, /* recursive call could loop indefinitely */
REG_BADPAT, /* unrecognized character after (?P */
REG_BADPAT, /* syntax error in subpattern name (missing terminator) */
REG_BADPAT, /* two named subpatterns have the same name */
REG_BADPAT, /* invalid UTF-8 string */
/* 45 */
REG_BADPAT, /* support for \P, \p, and \X has not been compiled */
REG_BADPAT, /* malformed \P or \p sequence */
REG_BADPAT, /* unknown property name after \P or \p */
REG_BADPAT, /* subpattern name is too long (maximum 32 characters) */
REG_BADPAT, /* too many named subpatterns (maximum 10,000) */
/* 50 */
REG_BADPAT, /* repeated subpattern is too long */
REG_BADPAT, /* octal value is greater than \377 (not in UTF-8 mode) */
REG_BADPAT, /* internal error: overran compiling workspace */
REG_BADPAT, /* internal error: previously-checked referenced subpattern not found */
REG_BADPAT, /* DEFINE group contains more than one branch */
/* 55 */
REG_BADPAT, /* repeating a DEFINE group is not allowed */
REG_INVARG, /* inconsistent NEWLINE options */
REG_BADPAT, /* \g is not followed followed by an (optionally braced) non-zero number */
REG_BADPAT, /* a numbered reference must not be zero */
REG_BADPAT, /* an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT) */
/* 60 */
REG_BADPAT, /* (*VERB) not recognized */
REG_BADPAT, /* number is too big */
REG_BADPAT, /* subpattern name expected */
REG_BADPAT, /* digit expected after (?+ */
REG_BADPAT, /* ] is an invalid data character in JavaScript compatibility mode */
/* 65 */
REG_BADPAT, /* different names for subpatterns of the same number are not allowed */
REG_BADPAT, /* (*MARK) must have an argument */
REG_INVARG, /* this version of PCRE2 is not compiled with PCRE2_UCP support */
REG_BADPAT, /* \c must be followed by an ASCII character */
REG_BADPAT, /* \k is not followed by a braced, angle-bracketed, or quoted name */
/* 70 */
REG_BADPAT, /* internal error: unknown opcode in find_fixedlength() */
REG_BADPAT, /* \N is not supported in a class */
REG_BADPAT, /* too many forward references */
REG_BADPAT, /* disallowed UTF-8/16/32 code point (>= 0xd800 && <= 0xdfff) */
REG_BADPAT, /* invalid UTF-16 string (should not occur) */
/* 75 */
REG_BADPAT, /* overlong MARK name */
REG_BADPAT, /* character value in \u.... sequence is too large */
REG_BADPAT, /* invalid UTF-32 string (should not occur) */
REG_BADPAT, /* setting UTF is disabled by the application */
REG_BADPAT, /* non-hex character in \\x{} (closing brace missing?) */
/* 80 */
REG_BADPAT, /* non-octal character in \o{} (closing brace missing?) */
REG_BADPAT, /* missing opening brace after \o */
REG_BADPAT, /* parentheses too deeply nested */
REG_BADPAT, /* invalid range in character class */
REG_BADPAT, /* group name must start with a non-digit */
/* 85 */
REG_BADPAT /* parentheses too deeply nested (stack check) */
REG_ASSERT /* internal error: code overflow */
};
static const int eint2[] = {
30, REG_ECTYPE, /* unknown POSIX class name */
32, REG_INVARG, /* this version of PCRE2 is not compiled with PCRE2_UTF8 support */
37, REG_EESCAPE, /* PCRE2 does not support \L, \l, \N, \U, or \u */
56, REG_INVARG, /* inconsistent NEWLINE options */
67, REG_INVARG, /* this version of PCRE2 is not compiled with PCRE2_UCP support */
};
/* Table of texts corresponding to POSIX error codes */
@ -252,7 +180,8 @@ return length + addlength;
PCRE2POSIX_EXP_DEFN void PCRE2_CALL_CONVENTION
regfree(regex_t *preg)
{
free(preg->re_pcre2_code);
pcre2_match_data_free(preg->re_match_data);
pcre2_code_free(preg->re_pcre2_code);
}
@ -275,14 +204,7 @@ Returns: 0 on success
PCRE2POSIX_EXP_DEFN int PCRE2_CALL_CONVENTION
regcomp(regex_t *preg, const char *pattern, int cflags)
{
/* FIXME: */
preg=preg;pattern=pattern;cflags=cflags;
return REG_BADPAT;
#ifdef NEVER
const char *errorptr;
int erroffset;
size_t erroffset;
int errorcode;
int options = 0;
int re_nsub = 0;
@ -291,67 +213,51 @@ if ((cflags & REG_ICASE) != 0) options |= PCRE2_CASELESS;
if ((cflags & REG_NEWLINE) != 0) options |= PCRE2_MULTILINE;
if ((cflags & REG_DOTALL) != 0) options |= PCRE2_DOTALL;
if ((cflags & REG_NOSUB) != 0) options |= PCRE2_NO_AUTO_CAPTURE;
if ((cflags & REG_UTF8) != 0) options |= PCRE2_UTF;
if ((cflags & REG_UTF) != 0) options |= PCRE2_UTF;
if ((cflags & REG_UCP) != 0) options |= PCRE2_UCP;
if ((cflags & REG_UNGREEDY) != 0) options |= PCRE2_UNGREEDY;
preg->re_pcre = pcre_compile2(pattern, options, &errorcode, &errorptr,
&erroffset, NULL);
preg->re_pcre2_code = pcre2_compile((PCRE2_SPTR)pattern, -1, options,
&errorcode, &erroffset, NULL);
preg->re_erroffset = erroffset;
/* Safety: if the error code is too big for the translation vector (which
should not happen, but we all make mistakes), return REG_BADPAT. */
if (preg->re_pcre == NULL)
if (preg->re_pcre2_code == NULL)
{
return (errorcode < (int)(sizeof(eint)/sizeof(const int)))?
eint[errorcode] : REG_BADPAT;
unsigned int i;
if (errorcode < (int)(sizeof(eint1)/sizeof(const int)))
return eint1[errorcode];
for (i = 0; i < sizeof(eint2)/(2*sizeof(const int)); i += 2)
if (errorcode == eint2[i]) return eint2[i+1];
return REG_BADPAT;
}
(void)pcre_fullinfo((const pcre *)preg->re_pcre, NULL, PCRE2_INFO_CAPTURECOUNT,
&re_nsub);
(void)pcre2_pattern_info((const pcre2_code *)preg->re_pcre2_code,
PCRE2_INFO_CAPTURECOUNT, &re_nsub);
preg->re_nsub = (size_t)re_nsub;
preg->re_match_data = ((cflags & REG_NOSUB) != 0)? NULL :
pcre2_match_data_create(re_nsub + 1, NULL);
return 0;
#endif /* NEVER */
}
/*************************************************
* Match a regular expression *
*************************************************/
/* Unfortunately, PCRE requires 3 ints of working space for each captured
substring, so we have to get and release working store instead of just using
the POSIX structures as was done in earlier releases when PCRE needed only 2
ints. However, if the number of possible capturing brackets is small, use a
block of store on the stack, to reduce the use of malloc/free. The threshold is
in a macro that can be changed at configure time.
If REG_NOSUB was specified at compile time, the PCRE_NO_AUTO_CAPTURE flag will
be set. When this is the case, the nmatch and pmatch arguments are ignored, and
the only result is yes/no/error. */
/* A suitable match_data block, large enough to hold all possible captures, was
obtained when the pattern was compiled, to save having to allocate and free it
for each match. If REG_NOSUB was specified at compile time, the
PCRE_NO_AUTO_CAPTURE flag will be set. When this is the case, the nmatch and
pmatch arguments are ignored, and the only result is yes/no/error. */
PCRE2POSIX_EXP_DEFN int PCRE2_CALL_CONVENTION
regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
/* FIXME */
preg=preg;string=string;nmatch=nmatch;pmatch=pmatch;eflags=eflags;
return REG_NOMATCH;
#ifdef NEVER
int rc, so, eo;
int options = 0;
int *ovector = NULL;
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
BOOL allocated_ovector = FALSE;
BOOL nosub =
(REAL_PCRE2_OPTIONS((const pcre *)preg->re_pcre) & PCRE2_NO_AUTO_CAPTURE) != 0;
pcre2_match_data *md = (pcre2_match_data *)preg->re_match_data;
if ((eflags & REG_NOTBOL) != 0) options |= PCRE2_NOTBOL;
if ((eflags & REG_NOTEOL) != 0) options |= PCRE2_NOTEOL;
@ -360,25 +266,10 @@ if ((eflags & REG_NOTEMPTY) != 0) options |= PCRE2_NOTEMPTY;
((regex_t *)preg)->re_erroffset = (size_t)(-1); /* Only has meaning after compile */
/* When no string data is being returned, or no vector has been passed in which
to put it, ensure that nmatch is zero. Otherwise, ensure the vector for holding
the return data is large enough. */
to put it, ensure that nmatch is zero. */
if (nosub || pmatch == NULL) nmatch = 0;
else if (nmatch > 0)
{
if (nmatch <= POSIX_MALLOC_THRESHOLD)
{
ovector = &(small_ovector[0]);
}
else
{
if (nmatch > INT_MAX/(sizeof(int) * 3)) return REG_ESPACE;
ovector = (int *)malloc(sizeof(int) * nmatch * 3);
if (ovector == NULL) return REG_ESPACE;
allocated_ovector = TRUE;
}
}
if ((((pcre2_real_code *)(preg->re_pcre2_code))->compile_options &
PCRE2_NO_AUTO_CAPTURE) != 0 || pmatch == NULL) nmatch = 0;
/* REG_STARTEND is a BSD extension, to allow for non-NUL-terminated strings.
The man page from OS X says "REG_STARTEND affects only the location of the
@ -396,59 +287,40 @@ else
eo = (int)strlen(string);
}
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string + so, (eo - so),
0, options, ovector, (int)(nmatch * 3));
if (rc == 0) rc = (int)nmatch; /* All captured slots were filled in */
rc = pcre2_match((const pcre2_code *)preg->re_pcre2_code,
(PCRE2_SPTR)string + so, (eo - so), 0, options, md, NULL);
/* Successful match */
if (rc >= 0)
{
size_t i;
if (!nosub)
{
if ((size_t)rc > nmatch) rc = (int)nmatch;
for (i = 0; i < (size_t)rc; i++)
{
pmatch[i].rm_so = ovector[i*2];
pmatch[i].rm_eo = ovector[i*2+1];
pmatch[i].rm_so = md->ovector[i*2];
pmatch[i].rm_eo = md->ovector[i*2+1];
}
if (allocated_ovector) free(ovector);
for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
}
return 0;
}
/* Unsuccessful match */
if (allocated_ovector) free(ovector);
switch(rc)
{
/* ========================================================================== */
/* These cases are never obeyed. This is a fudge that causes a compile-time
error if the vector eint, which is indexed by compile-time error number, is
not the correct length. It seems to be the only way to do such a check at
compile time, as the sizeof() operator does not work in the C preprocessor.
As all the PCRE2_ERROR_xxx values are negative, we can use 0 and 1. */
case 0:
case (sizeof(eint)/sizeof(int) == ERRCOUNT):
return REG_ASSERT;
/* ========================================================================== */
case PCRE2_ERROR_NOMATCH: return REG_NOMATCH;
case PCRE2_ERROR_NULL: return REG_INVARG;
case PCRE2_ERROR_BADOPTION: return REG_INVARG;
case PCRE2_ERROR_BADMAGIC: return REG_INVARG;
case PCRE2_ERROR_UNKNOWN_NODE: return REG_ASSERT;
case PCRE2_ERROR_NOMEMORY: return REG_ESPACE;
case PCRE2_ERROR_MATCHLIMIT: return REG_ESPACE;
case PCRE2_ERROR_BADUTF8: return REG_INVARG;
case PCRE2_ERROR_BADUTF8_OFFSET: return REG_INVARG;
case PCRE2_ERROR_BADMODE: return REG_INVARG;
default: return REG_ASSERT;
case PCRE2_ERROR_BADMODE: return REG_INVARG;
case PCRE2_ERROR_BADMAGIC: return REG_INVARG;
case PCRE2_ERROR_BADOPTION: return REG_INVARG;
case PCRE2_ERROR_BADUTF: return REG_INVARG;
case PCRE2_ERROR_BADUTF_OFFSET: return REG_INVARG;
case PCRE2_ERROR_MATCHLIMIT: return REG_ESPACE;
case PCRE2_ERROR_NOMATCH: return REG_NOMATCH;
case PCRE2_ERROR_NOMEMORY: return REG_ESPACE;
case PCRE2_ERROR_NULL: return REG_INVARG;
case PCRE2_ERROR_UNKNOWN_OPCODE: return REG_ASSERT;
}
#endif /* NEVER */
}
/* End of pcre2posix.c */

View File

@ -95,6 +95,7 @@ enum {
typedef struct {
void *re_pcre2_code;
void *re_match_data;
size_t re_nsub;
size_t re_erroffset;
} regex_t;

File diff suppressed because it is too large Load Diff