Remove remaining (now unused) code under HEAP_MATCH_RECURSE, and make the build

systems give a warning of the obsolescence of --disable-stack-for-recursion and 
the equivalent CMake setting.
This commit is contained in:
Philip.Hazel 2017-03-11 17:39:02 +00:00
parent deee290c39
commit 02779c9a67
10 changed files with 78 additions and 144 deletions

View File

@ -77,6 +77,7 @@
# 2016-10-05 PH fixed a typo (PCRE should be PCRE2) in above patch
# fix by David Gaussmann
# 2016-10-07 PH added PCREGREP_MAX_BUFSIZE
# 2017-03-11 PH turned HEAP_MATCH_RECURSE into a NO-OP for 10.30
PROJECT(PCRE2 C)
@ -158,7 +159,7 @@ SET(PCRE2_NEWLINE "LF" CACHE STRING
"What to recognize as a newline (one of CR, LF, CRLF, ANY, ANYCRLF).")
SET(PCRE2_HEAP_MATCH_RECURSE OFF CACHE BOOL
"If ON, then don't use stack recursion when matching. See HEAP_MATCH_RECURSE in config.h.in for details.")
"Obsolete option: do not use")
SET(PCRE2_SUPPORT_JIT OFF CACHE BOOL
"Enable support for Just-in-time compiling.")
@ -353,10 +354,6 @@ IF(PCRE2_EBCDIC_NL25)
SET(EBCDIC_NL25 1)
ENDIF(PCRE2_EBCDIC_NL25)
IF(PCRE2_HEAP_MATCH_RECURSE)
SET(HEAP_MATCH_RECURSE 1)
ENDIF(PCRE2_HEAP_MATCH_RECURSE)
# Output files
CONFIGURE_FILE(config-cmake.h.in
@ -738,6 +735,10 @@ ELSE(BUILD_SHARED_LIBS)
SET(BUILD_STATIC_LIBS ON)
ENDIF(BUILD_SHARED_LIBS)
IF(PCRE2_HEAP_MATCH_RECURSE)
MESSAGE(WARNING "HEAP_MATCH_RECURSE is obsolete and does nothing.")
ENDIF(PCRE2_HEAP_MATCH_RECURSE)
IF(PCRE2_SHOW_REPORT)
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
IF (CMAKE_C_FLAGS)
@ -762,7 +763,6 @@ IF(PCRE2_SHOW_REPORT)
MESSAGE(STATUS " EBCDIC coding ................... : ${PCRE2_EBCDIC}")
MESSAGE(STATUS " EBCDIC coding with NL=0x25 ...... : ${PCRE2_EBCDIC_NL25}")
MESSAGE(STATUS " Rebuild char tables ............. : ${PCRE2_REBUILD_CHARTABLES}")
MESSAGE(STATUS " Use heap recursion .............. : ${PCRE2_HEAP_MATCH_RECURSE}")
MESSAGE(STATUS " Internal link size .............. : ${PCRE2_LINK_SIZE}")
MESSAGE(STATUS " Parentheses nest limit .......... : ${PCRE2_PARENS_NEST_LIMIT}")
MESSAGE(STATUS " Match limit ..................... : ${PCRE2_MATCH_LIMIT}")

View File

@ -215,12 +215,6 @@ AC_ARG_ENABLE(ebcdic-nl25,
[set EBCDIC code for NL to 0x25 instead of 0x15; it implies --enable-ebcdic]),
, enable_ebcdic_nl25=no)
# Handle --disable-stack-for-recursion
AC_ARG_ENABLE(stack-for-recursion,
AS_HELP_STRING([--disable-stack-for-recursion],
[don't use stack recursion when matching]),
, enable_stack_for_recursion=yes)
# Handle --enable-pcre2grep-libz
AC_ARG_ENABLE(pcre2grep-libz,
AS_HELP_STRING([--enable-pcre2grep-libz],
@ -305,6 +299,17 @@ AC_ARG_ENABLE(fuzz_support,
AS_HELP_STRING([--enable-fuzz-support],
[enable fuzzer support]),
, enable_fuzz_support=no)
# Handle --disable-stack-for-recursion
# This option became obsolete at release 10.30.
AC_ARG_ENABLE(stack-for-recursion,,
, enable_stack_for_recursion=yes)
# Original code
# AC_ARG_ENABLE(stack-for-recursion,
# AS_HELP_STRING([--disable-stack-for-recursion],
# [don't use stack recursion when matching]),
# , enable_stack_for_recursion=yes)
# Set the default value for pcre2-8
if test "x$enable_pcre2_8" = "xunset"
@ -588,16 +593,6 @@ if test "$enable_unicode" = "yes"; then
code *or* ASCII/Unicode, but not both at once.])
fi
if test "$enable_stack_for_recursion" = "no"; then
AC_DEFINE([HEAP_MATCH_RECURSE], [], [
PCRE2 uses recursive function calls to handle backtracking while
matching. This can sometimes be a problem on systems that have
stacks of limited size. Define HEAP_MATCH_RECURSE to any value to get a
version that doesn't use recursion in the match() function; instead
it creates its own stack by steam using memory from the heap. For more
detail, see the comments and other stuff just above the match() function.])
fi
if test "$enable_pcre2grep_libz" = "yes"; then
AC_DEFINE([SUPPORT_LIBZ], [], [
Define to any value to allow pcre2grep to be linked with libz, so that it is
@ -681,24 +676,21 @@ AC_DEFINE_UNQUOTED([PARENS_NEST_LIMIT], [$with_parens_nest_limit], [
stack that is used while compiling a pattern.])
AC_DEFINE_UNQUOTED([MATCH_LIMIT], [$with_match_limit], [
The value of MATCH_LIMIT determines the default number of times the
internal match() function can be called during a single execution of
pcre2_match(). There is a runtime interface for setting a different
limit. The limit exists in order to catch runaway regular
expressions that take for ever to determine that they do not match.
The default is set very large so that it does not accidentally catch
legitimate cases.])
The value of MATCH_LIMIT determines the default number of times the internal
match() function can record a backtrack position during a single matching
attempt. There is a runtime interface for setting a different limit. The
limit exists in order to catch runaway regular expressions that take for ever
to determine that they do not match. The default is set very large so that it
does not accidentally catch legitimate cases.])
AC_DEFINE_UNQUOTED([MATCH_LIMIT_RECURSION], [$with_match_limit_recursion], [
The above limit applies to all calls of match(), whether or not they
increase the recursion depth. In some environments it is desirable
to limit the depth of recursive calls of match() more strictly, in
order to restrict the maximum amount of stack (or heap, if
HEAP_MATCH_RECURSE is defined) that is used. The value of
MATCH_LIMIT_RECURSION applies only to recursive calls of match(). To
have any useful effect, it must be less than the value of
MATCH_LIMIT. The default is to use the same value as MATCH_LIMIT.
There is a runtime method for setting a different limit.])
The above limit applies to all backtracks, whether or not they are nested. In
some environments it is desirable to limit the nesting of backtracking more
strictly, in order to restrict the maximum amount of heap memory that is
used. The value of MATCH_LIMIT_RECURSION provides this facility. To have any
useful effect, it must be less than the value of MATCH_LIMIT. The default is
to use the same value as MATCH_LIMIT. There is a runtime method for setting a
different limit.])
AC_DEFINE([MAX_NAME_SIZE], [32], [
This limit is parameterized just in case anybody ever wants to
@ -914,6 +906,15 @@ AC_CONFIG_COMMANDS([delete-old-chartables], [rm -f pcre2_chartables.c])
AC_OUTPUT
# --disable-stack-for-recursion is obsolete and has no effect.
if test "$enable_stack_for_recursion" = "no"; then
cat <<EOF
WARNING: --disable-stack-for-recursion is obsolete and has no effect.
EOF
fi
# Print out a nice little message after configure is run displaying the
# chosen options.
@ -949,7 +950,6 @@ $PACKAGE-$VERSION configuration summary:
EBCDIC coding ...................... : ${enable_ebcdic}
EBCDIC code for NL ................. : ${ebcdic_nl_code}
Rebuild char tables ................ : ${enable_rebuild_chartables}
Use stack recursion ................ : ${enable_stack_for_recursion}
Internal link size ................. : ${with_link_size}
Nested parentheses limit ........... : ${with_parens_nest_limit}
Match limit ........................ : ${with_match_limit}

View File

@ -132,14 +132,6 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to 1 if you have the <zlib.h> header file. */
/* #undef HAVE_ZLIB_H */
/* PCRE2 uses recursive function calls to handle backtracking while matching.
This can sometimes be a problem on systems that have stacks of limited
size. Define HEAP_MATCH_RECURSE to any value to get a version that doesn't
use recursion in the match() function; instead it creates its own stack by
steam using memory from the heap. For more detail, see the comments and
other stuff just above the match() function. */
/* #undef HEAP_MATCH_RECURSE */
/* The value of LINK_SIZE determines the number of bytes used to store links
as offsets within the compiled regex. The default is 2, which allows for
compiled patterns up to 64K long. This covers the vast majority of cases.
@ -156,23 +148,22 @@ sure both macros are undefined; an emulation function will then be used. */
#endif
/* The value of MATCH_LIMIT determines the default number of times the
internal match() function can be called during a single execution of
pcre2_match(). There is a runtime interface for setting a different limit.
The limit exists in order to catch runaway regular expressions that take
for ever to determine that they do not match. The default is set very large
so that it does not accidentally catch legitimate cases. */
internal match() function can record a backtrack position during a single
matching attempt. There is a runtime interface for setting a different
limit. The limit exists in order to catch runaway regular expressions that
take for ever to determine that they do not match. The default is set very
large so that it does not accidentally catch legitimate cases. */
#ifndef MATCH_LIMIT
#define MATCH_LIMIT 10000000
#endif
/* The above limit applies to all calls of match(), whether or not they
increase the recursion depth. In some environments it is desirable to limit
the depth of recursive calls of match() more strictly, in order to restrict
the maximum amount of stack (or heap, if HEAP_MATCH_RECURSE is defined)
that is used. The value of MATCH_LIMIT_RECURSION applies only to recursive
calls of match(). To have any useful effect, it must be less than the value
of MATCH_LIMIT. The default is to use the same value as MATCH_LIMIT. There
is a runtime method for setting a different limit. */
/* The above limit applies to all backtracks, whether or not they are nested.
In some environments it is desirable to limit the nesting of backtracking
more strictly, in order to restrict the maximum amount of heap memory that
is used. The value of MATCH_LIMIT_RECURSION provides this facility. To have
any useful effect, it must be less than the value of MATCH_LIMIT. The
default is to use the same value as MATCH_LIMIT. There is a runtime method
for setting a different limit. */
#ifndef MATCH_LIMIT_RECURSION
#define MATCH_LIMIT_RECURSION MATCH_LIMIT
#endif
@ -212,7 +203,7 @@ sure both macros are undefined; an emulation function will then be used. */
#define PACKAGE_NAME "PCRE2"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "PCRE2 10.23"
#define PACKAGE_STRING "PCRE2 10.30-DEV"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "pcre2"
@ -221,7 +212,7 @@ sure both macros are undefined; an emulation function will then be used. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "10.23"
#define PACKAGE_VERSION "10.30-DEV"
/* 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
@ -336,7 +327,7 @@ sure both macros are undefined; an emulation function will then be used. */
#endif
/* Version number of package */
#define VERSION "10.23"
#define VERSION "10.30-DEV"
/* Define to 1 if on MINIX. */
/* #undef _MINIX */

View File

@ -132,14 +132,6 @@ sure both macros are undefined; an emulation function will then be used. */
/* Define to 1 if you have the <zlib.h> header file. */
#undef HAVE_ZLIB_H
/* PCRE2 uses recursive function calls to handle backtracking while matching.
This can sometimes be a problem on systems that have stacks of limited
size. Define HEAP_MATCH_RECURSE to any value to get a version that doesn't
use recursion in the match() function; instead it creates its own stack by
steam using memory from the heap. For more detail, see the comments and
other stuff just above the match() function. */
#undef HEAP_MATCH_RECURSE
/* The value of LINK_SIZE determines the number of bytes used to store links
as offsets within the compiled regex. The default is 2, which allows for
compiled patterns up to 64K long. This covers the vast majority of cases.
@ -151,21 +143,20 @@ sure both macros are undefined; an emulation function will then be used. */
#undef LT_OBJDIR
/* The value of MATCH_LIMIT determines the default number of times the
internal match() function can be called during a single execution of
pcre2_match(). There is a runtime interface for setting a different limit.
The limit exists in order to catch runaway regular expressions that take
for ever to determine that they do not match. The default is set very large
so that it does not accidentally catch legitimate cases. */
internal match() function can record a backtrack position during a single
matching attempt. There is a runtime interface for setting a different
limit. The limit exists in order to catch runaway regular expressions that
take for ever to determine that they do not match. The default is set very
large so that it does not accidentally catch legitimate cases. */
#undef MATCH_LIMIT
/* The above limit applies to all calls of match(), whether or not they
increase the recursion depth. In some environments it is desirable to limit
the depth of recursive calls of match() more strictly, in order to restrict
the maximum amount of stack (or heap, if HEAP_MATCH_RECURSE is defined)
that is used. The value of MATCH_LIMIT_RECURSION applies only to recursive
calls of match(). To have any useful effect, it must be less than the value
of MATCH_LIMIT. The default is to use the same value as MATCH_LIMIT. There
is a runtime method for setting a different limit. */
/* The above limit applies to all backtracks, whether or not they are nested.
In some environments it is desirable to limit the nesting of backtracking
more strictly, in order to restrict the maximum amount of heap memory that
is used. The value of MATCH_LIMIT_RECURSION provides this facility. To have
any useful effect, it must be less than the value of MATCH_LIMIT. The
default is to use the same value as MATCH_LIMIT. There is a runtime method
for setting a different limit. */
#undef MATCH_LIMIT_RECURSION
/* This limit is parameterized just in case anybody ever wants to change it.

View File

@ -304,7 +304,7 @@ numbers must not be changed. */
#define PCRE2_CONFIG_NEWLINE 5
#define PCRE2_CONFIG_PARENSLIMIT 6
#define PCRE2_CONFIG_RECURSIONLIMIT 7
#define PCRE2_CONFIG_STACKRECURSE 8
#define PCRE2_CONFIG_STACKRECURSE 8 /* Obsolete */
#define PCRE2_CONFIG_UNICODE 9
#define PCRE2_CONFIG_UNICODE_VERSION 10
#define PCRE2_CONFIG_VERSION 11

View File

@ -304,7 +304,7 @@ numbers must not be changed. */
#define PCRE2_CONFIG_NEWLINE 5
#define PCRE2_CONFIG_PARENSLIMIT 6
#define PCRE2_CONFIG_RECURSIONLIMIT 7
#define PCRE2_CONFIG_STACKRECURSE 8
#define PCRE2_CONFIG_STACKRECURSE 8 /* Obsolete */
#define PCRE2_CONFIG_UNICODE 9
#define PCRE2_CONFIG_UNICODE_VERSION 10
#define PCRE2_CONFIG_VERSION 11

View File

@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
New API code Copyright (c) 2016 University of Cambridge
New API code Copyright (c) 2016-2017 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@ -90,7 +90,7 @@ if (where == NULL) /* Requests a length */
case PCRE2_CONFIG_NEWLINE:
case PCRE2_CONFIG_PARENSLIMIT:
case PCRE2_CONFIG_RECURSIONLIMIT:
case PCRE2_CONFIG_STACKRECURSE:
case PCRE2_CONFIG_STACKRECURSE: /* Obsolete */
case PCRE2_CONFIG_UNICODE:
return sizeof(uint32_t);
@ -154,13 +154,12 @@ switch (what)
case PCRE2_CONFIG_RECURSIONLIMIT:
*((uint32_t *)where) = MATCH_LIMIT_RECURSION;
break;
/* This is now obsolete. The stack is no longer used via recursion for
handling backtracking in pcre2_match(). */
case PCRE2_CONFIG_STACKRECURSE:
#ifdef HEAP_MATCH_RECURSE
*((uint32_t *)where) = 0;
#else
*((uint32_t *)where) = 1;
#endif
break;
case PCRE2_CONFIG_UNICODE_VERSION:

View File

@ -161,9 +161,6 @@ when no context is supplied to a match function. */
const pcre2_match_context PRIV(default_match_context) = {
{ default_malloc, default_free, NULL },
#ifdef HEAP_MATCH_RECURSE
{ default_malloc, default_free, NULL },
#endif
#ifdef SUPPORT_JIT
NULL,
NULL,
@ -370,21 +367,18 @@ mcontext->recursion_limit = limit;
return 0;
}
/* This function became obsolete at release 10.30. It is kept as a no-op for
backwards compatibility. */
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_set_recursion_memory_management(pcre2_match_context *mcontext,
void *(*mymalloc)(size_t, void *), void (*myfree)(void *, void *),
void *mydata)
{
#ifdef HEAP_MATCH_RECURSE
mcontext->stack_memctl.malloc = mymalloc;
mcontext->stack_memctl.free = myfree;
mcontext->stack_memctl.memory_data = mydata;
#else
(void)mcontext;
(void)mymalloc;
(void)myfree;
(void)mydata;
#endif
return 0;
}

View File

@ -578,9 +578,6 @@ typedef struct pcre2_real_compile_context {
typedef struct pcre2_real_match_context {
pcre2_memctl memctl;
#ifdef HEAP_MATCH_RECURSE
pcre2_memctl stack_memctl;
#endif
#ifdef SUPPORT_JIT
pcre2_jit_callback jit_callback;
void *jit_callback_data;

View File

@ -2446,26 +2446,6 @@ if (show_memory)
free(block);
}
/* For recursion malloc/free, to test stacking calls */
#ifdef HEAP_MATCH_RECURSE
static void *my_stack_malloc(size_t size, void *data)
{
void *block = malloc(size);
(void)data;
if (show_memory)
fprintf(outfile, "stack_malloc %3d %p\n", (int)size, block);
return block;
}
static void my_stack_free(void *block, void *data)
{
(void)data;
if (show_memory)
fprintf(outfile, "stack_free %p\n", block);
free(block);
}
#endif /* HEAP_MATCH_RECURSE */
/*************************************************
@ -7307,10 +7287,6 @@ printf(" Parentheses nest limit = %d\n", optval);
printf(" Default match limit = %d\n", optval);
(void)PCRE2_CONFIG(PCRE2_CONFIG_RECURSIONLIMIT, &optval);
printf(" Default recursion depth limit = %d\n", optval);
(void)PCRE2_CONFIG(PCRE2_CONFIG_STACKRECURSE, &optval);
printf(" Match recursion uses %s", optval? "stack" : "heap");
printf("\n");
return 0;
}
@ -7668,9 +7644,8 @@ if (arg_error != NULL)
} /* End of -error handling */
/* Initialize things that cannot be done until we know which test mode we are
running in. When HEAP_MATCH_RECURSE is undefined, calling pcre2_set_recursion_
memory_management() is a no-op, but we call it in order to exercise it. Also
exercise the general context copying function, which is not otherwise used. */
running in. Exercise the general context copying function, which is not
otherwise used. */
code_unit_size = test_mode/8;
max_oveccount = DEFAULT_OVECCOUNT;
@ -7686,16 +7661,6 @@ max_oveccount = DEFAULT_OVECCOUNT;
G(dat_context,BITS) = G(pcre2_match_context_copy_,BITS)(G(default_dat_context,BITS)); \
G(match_data,BITS) = G(pcre2_match_data_create_,BITS)(max_oveccount, G(general_context,BITS))
#ifdef HEAP_MATCH_RECURSE
#define SETRECURSEMEMMAN \
(void)G(pcre2_set_recursion_memory_management_,BITS) \
(G(default_dat_context,BITS), \
&my_stack_malloc, &my_stack_free, NULL)
#else
#define SETRECURSEMEMMAN \
(void)G(pcre2_set_recursion_memory_management_,BITS)(NULL, NULL, NULL, NULL)
#endif
/* Call the appropriate functions for the current mode. */
#ifdef SUPPORT_PCRE2_8
@ -7704,7 +7669,6 @@ max_oveccount = DEFAULT_OVECCOUNT;
if (test_mode == PCRE8_MODE)
{
CREATECONTEXTS;
SETRECURSEMEMMAN;
}
#endif
@ -7714,7 +7678,6 @@ if (test_mode == PCRE8_MODE)
if (test_mode == PCRE16_MODE)
{
CREATECONTEXTS;
SETRECURSEMEMMAN;
}
#endif
@ -7724,7 +7687,6 @@ if (test_mode == PCRE16_MODE)
if (test_mode == PCRE32_MODE)
{
CREATECONTEXTS;
SETRECURSEMEMMAN;
}
#endif