Skip to content

PCRE2 support #2857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
94e8a0c
Path core for PCRE2 interoperation
weltling Oct 12, 2017
04218b4
Fix config.w32
weltling Oct 13, 2017
f4f94b6
Fix ret evaluation
weltling Oct 13, 2017
a1f4603
Fix config.m4
weltling Oct 14, 2017
cf9e419
Hide the pcre_cache_entry implementation
weltling Oct 14, 2017
1198ea9
Fix refcount type and add assert
weltling Oct 14, 2017
61db9ee
Fix config.h
weltling Oct 14, 2017
f944361
Add comment
weltling Oct 14, 2017
55f8a49
Fix visibility and double free
weltling Oct 14, 2017
e7a0c8a
Move to pemalloc/pefree
weltling Oct 14, 2017
d86233f
Fix datatype
weltling Oct 14, 2017
23232f9
Only need to assign stack once
weltling Oct 14, 2017
886d28c
Next refactoring round
weltling Oct 15, 2017
b803838
Implement setting extra compilation option and fix X modifier
weltling Oct 15, 2017
62e0e06
Fix JIT ini and subsequent handling
weltling Oct 15, 2017
ec63246
Rework MINFO and add version constants
weltling Oct 15, 2017
fe37d6d
Reorder pce items
weltling Oct 15, 2017
01e6852
Fix test
weltling Oct 15, 2017
0c36aa6
Add missing free
weltling Oct 15, 2017
85bbf2a
Rework comment
weltling Oct 16, 2017
80b9adc
Info table item
weltling Oct 16, 2017
4634d42
More robust PCRE2 initialization
weltling Oct 22, 2017
7151a34
Drop unused var
weltling Oct 22, 2017
fbe37cd
Fix start offset datatype and handling
weltling Oct 22, 2017
de10427
Retry PCRE2 init also in MINIT
weltling Oct 22, 2017
5c51c1d
Fix datatype
weltling Oct 22, 2017
7eda1e1
Not needed anymore with PCRE2
weltling Oct 22, 2017
5f3b8d7
Remove TODO
weltling Oct 22, 2017
34e1a35
Avoid unnecessary scoped var
weltling Oct 22, 2017
bebc1b0
Remove unused files
weltling Oct 31, 2017
14a366e
Bad UTF error is handled another way
weltling Nov 5, 2017
425c933
Check match data creation
weltling Nov 5, 2017
15e5094
More error checks
weltling Nov 5, 2017
08e0739
Error checks done and otherwise these functions return zero
weltling Nov 5, 2017
a4efe41
Missed error check
weltling Nov 5, 2017
8869ba3
Fix external PCRE2 version check
weltling Nov 9, 2017
15bb41a
Sync jit availability checks
weltling Nov 9, 2017
c9b4822
Fix symbol check for external pcre2
weltling Nov 9, 2017
0864586
Fix add library for external pcre2
weltling Nov 9, 2017
be984c0
Preallocate pcre2_match_data for offsets num <= 32
weltling Nov 13, 2017
ec68a9f
Zero global mdata after free
weltling Nov 13, 2017
cd2c26c
Check jit in pattern by flag instead of doing it on demand
dstogov Nov 13, 2017
5cc3525
Memorize match data usage
dstogov Nov 13, 2017
e110793
Don't overwrite poptions
weltling Nov 13, 2017
beabacb
Expand on preallocated match data usage
weltling Nov 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,4 @@ ext/sqlite3/tests/phpsql*
!ext/fileinfo/libmagic.patch
!ext/mbstring/oniguruma.patch
!scripts/dev/generate-phpt/tests/*.php
!ext/pcre/pcre2lib/config.h
4 changes: 2 additions & 2 deletions ext/fileinfo/libmagic/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
pcre_cache_entry *pce;
zend_string *res;
zend_string *repl;
int rep_cnt = 0;
size_t rep_cnt = 0;

(void)setlocale(LC_CTYPE, "C");

opts |= PCRE_MULTILINE;
opts |= PCRE2_MULTILINE;
convert_libmagic_pattern(&patt, (char*)pat, strlen(pat), opts);
if ((pce = pcre_get_compiled_regex_cache(Z_STR(patt))) == NULL) {
zval_ptr_dtor(&patt);
Expand Down
22 changes: 13 additions & 9 deletions ext/fileinfo/libmagic/softmagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,24 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
private int
check_fmt(struct magic_set *ms, struct magic *m)
{
pcre *pce;
int re_options, rv = -1;
pcre_extra *re_extra;
pcre2_code *pce;
uint32_t re_options, capture_count;
int rv = -1;
zend_string *pattern;

if (strchr(m->desc, '%') == NULL)
return 0;

(void)setlocale(LC_CTYPE, "C");
pattern = zend_string_init("~%[-0-9.]*s~", sizeof("~%[-0-9.]*s~") - 1, 0);
if ((pce = pcre_get_compiled_regex(pattern, &re_extra, &re_options)) == NULL) {
if ((pce = pcre_get_compiled_regex(pattern, &capture_count, &re_options)) == NULL) {
rv = -1;
} else {
rv = !pcre_exec(pce, re_extra, m->desc, strlen(m->desc), 0, re_options, NULL, 0);
pcre2_match_data *match_data = php_pcre_create_match_data(capture_count, pce);
if (match_data) {
rv = pcre2_match(pce, m->desc, strlen(m->desc), 0, re_options, match_data, php_pcre_mctx()) > 0;
php_pcre_free_match_data(match_data);
}
}
zend_string_release(pattern);
(void)setlocale(LC_CTYPE, "");
Expand Down Expand Up @@ -1725,10 +1729,10 @@ convert_libmagic_pattern(zval *pattern, char *val, int len, int options)
}
ZSTR_VAL(t)[j++] = '~';

if (options & PCRE_CASELESS)
if (options & PCRE2_CASELESS)
ZSTR_VAL(t)[j++] = 'i';

if (options & PCRE_MULTILINE)
if (options & PCRE2_MULTILINE)
ZSTR_VAL(t)[j++] = 'm';

ZSTR_VAL(t)[j]='\0';
Expand Down Expand Up @@ -1901,10 +1905,10 @@ magiccheck(struct magic_set *ms, struct magic *m)
int options = 0;
pcre_cache_entry *pce;

options |= PCRE_MULTILINE;
options |= PCRE2_MULTILINE;

if (m->str_flags & STRING_IGNORE_CASE) {
options |= PCRE_CASELESS;
options |= PCRE2_CASELESS;
}

convert_libmagic_pattern(&pattern, (char *)m->value.s, m->vallen, options);
Expand Down
40 changes: 24 additions & 16 deletions ext/filter/logical_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,10 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
zval *option_val;
zend_string *regexp;
int regexp_set;
pcre *re = NULL;
pcre_extra *pcre_extra = NULL;
int preg_options = 0;
int ovector[3];
int matches;
pcre2_code *re = NULL;
pcre2_match_data *match_data = NULL;
uint32_t preg_options, capture_count;
int rc;

/* Parse options */
FETCH_STR_OPTION(regexp, "regexp");
Expand All @@ -442,14 +441,19 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
RETURN_VALIDATION_FAILED
}

re = pcre_get_compiled_regex(regexp, &pcre_extra, &preg_options);
re = pcre_get_compiled_regex(regexp, &capture_count, &preg_options);
if (!re) {
RETURN_VALIDATION_FAILED
}
matches = pcre_exec(re, NULL, Z_STRVAL_P(value), (int)Z_STRLEN_P(value), 0, 0, ovector, 3);
match_data = php_pcre_create_match_data(capture_count, re);
if (!match_data) {
RETURN_VALIDATION_FAILED
}
rc = pcre2_match(re, Z_STRVAL_P(value), Z_STRLEN_P(value), 0, preg_options, match_data, php_pcre_mctx());
php_pcre_free_match_data(match_data);

/* 0 means that the vector is too small to hold all the captured substring offsets */
if (matches < 0) {
if (rc < 0) {
RETURN_VALIDATION_FAILED
}
}
Expand Down Expand Up @@ -599,12 +603,11 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
* Feel free to use and redistribute this code. But please keep this copyright notice.
*
*/
pcre *re = NULL;
pcre_extra *pcre_extra = NULL;
int preg_options = 0;
int ovector[150]; /* Needs to be a multiple of 3 */
int matches;
pcre2_code *re = NULL;
pcre2_match_data *match_data = NULL;
uint32_t preg_options = 0, capture_count;
zend_string *sregexp;
int rc;
const char regexp0[] = "/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E\\pL\\pN]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F\\pL\\pN]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E\\pL\\pN]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F\\pL\\pN]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iDu";
const char regexp1[] = "/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD";
const char *regexp;
Expand All @@ -624,16 +627,21 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
}

sregexp = zend_string_init(regexp, regexp_len, 0);
re = pcre_get_compiled_regex(sregexp, &pcre_extra, &preg_options);
re = pcre_get_compiled_regex(sregexp, &capture_count, &preg_options);
if (!re) {
zend_string_release(sregexp);
RETURN_VALIDATION_FAILED
}
zend_string_release(sregexp);
matches = pcre_exec(re, NULL, Z_STRVAL_P(value), (int)Z_STRLEN_P(value), 0, 0, ovector, 3);
match_data = php_pcre_create_match_data(capture_count, re);
if (!match_data) {
RETURN_VALIDATION_FAILED
}
rc = pcre2_match(re, Z_STRVAL_P(value), Z_STRLEN_P(value), 0, preg_options, match_data, php_pcre_mctx());
php_pcre_free_match_data(match_data);

/* 0 means that the vector is too small to hold all the captured substring offsets */
if (matches < 0) {
if (rc < 0) {
RETURN_VALIDATION_FAILED
}

Expand Down
24 changes: 18 additions & 6 deletions ext/opcache/zend_accelerator_blacklist.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#define ZEND_BLACKLIST_BLOCK_SIZE 32

struct _zend_regexp_list {
pcre *re;
pcre2_code *re;
zend_regexp_list *next;
};

Expand Down Expand Up @@ -73,10 +73,12 @@ static void blacklist_report_regexp_error(const char *pcre_error, int pcre_error

static void zend_accel_blacklist_update_regexp(zend_blacklist *blacklist)
{
const char *pcre_error;
int i, pcre_error_offset;
PCRE2_UCHAR pcre_error[256];
int i, errnumber;
PCRE2_SIZE pcre_error_offset;
zend_regexp_list **regexp_list_it, *it;
char regexp[12*1024], *p, *end, *c, *backtrack = NULL;
pcre2_compile_context *cctx = php_pcre_cctx();

if (blacklist->pos == 0) {
/* we have no blacklist to talk about */
Expand Down Expand Up @@ -177,8 +179,9 @@ static void zend_accel_blacklist_update_regexp(zend_blacklist *blacklist)
}
it->next = NULL;

if ((it->re = pcre_compile(regexp, PCRE_NO_AUTO_CAPTURE, &pcre_error, &pcre_error_offset, 0)) == NULL) {
if ((it->re = pcre2_compile(regexp, PCRE2_ZERO_TERMINATED, PCRE2_NO_AUTO_CAPTURE, &errnumber, &pcre_error_offset, cctx)) == NULL) {
free(it);
pcre2_get_error_message(errnumber, pcre_error, sizeof(pcre_error));
blacklist_report_regexp_error(pcre_error, pcre_error_offset);
return;
}
Expand Down Expand Up @@ -207,7 +210,7 @@ void zend_accel_blacklist_shutdown(zend_blacklist *blacklist)
if (blacklist->regexp_list) {
zend_regexp_list *temp, *it = blacklist->regexp_list;
while (it) {
pcre_free(it->re);
pcre2_code_free(it->re);
temp = it;
it = it->next;
free(temp);
Expand Down Expand Up @@ -338,15 +341,24 @@ zend_bool zend_accel_blacklist_is_blacklisted(zend_blacklist *blacklist, char *v
{
int ret = 0;
zend_regexp_list *regexp_list_it = blacklist->regexp_list;
pcre2_match_context *mctx = php_pcre_mctx();

if (regexp_list_it == NULL) {
return 0;
}
while (regexp_list_it != NULL) {
if (pcre_exec(regexp_list_it->re, NULL, verify_path, strlen(verify_path), 0, 0, NULL, 0) >= 0) {
pcre2_match_data *match_data = php_pcre_create_match_data(0, regexp_list_it->re);
if (!match_data) {
/* Alloc failed, but next one could still come through and match. */
continue;
}
int rc = pcre2_match(regexp_list_it->re, verify_path, strlen(verify_path), 0, 0, match_data, mctx);
if (rc >= 0) {
ret = 1;
php_pcre_free_match_data(match_data);
break;
}
php_pcre_free_match_data(match_data);
regexp_list_it = regexp_list_it->next;
}
return ret;
Expand Down
8 changes: 5 additions & 3 deletions ext/pcre/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// vim:ft=javascript

EXTENSION("pcre", "php_pcre.c", false /* never shared */,
"-Iext/pcre/pcrelib -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
ADD_SOURCES("ext/pcre/pcrelib", "pcre_chartables.c pcre_ucd.c pcre_compile.c pcre_config.c pcre_exec.c pcre_fullinfo.c pcre_get.c pcre_globals.c pcre_maketables.c pcre_newline.c pcre_ord2utf8.c pcre_refcount.c pcre_study.c pcre_tables.c pcre_valid_utf8.c pcre_version.c pcre_xclass.c pcre_jit_compile.c", "pcre");
"-Iext/pcre/pcre2lib -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
ADD_SOURCES("ext/pcre/pcre2lib", "pcre2_auto_possess.c pcre2_chartables.c pcre2_compile.c pcre2_config.c pcre2_context.c pcre2_dfa_match.c pcre2_error.c pcre2_jit_compile.c pcre2_maketables.c pcre2_match.c pcre2_match_data.c pcre2_newline.c pcre2_ord2utf.c pcre2_pattern_info.c pcre2_serialize.c pcre2_string_utils.c pcre2_study.c pcre2_substitute.c pcre2_substring.c pcre2_tables.c pcre2_ucd.c pcre2_valid_utf.c pcre2_xclass.c pcre2_find_bracket.c pcre2_convert.c ", "pcre");
ADD_DEF_FILE("ext\\pcre\\php_pcre.def");

AC_DEFINE('HAVE_BUNDLED_PCRE', 1, 'Using bundled PCRE library');
AC_DEFINE('HAVE_PCRE', 1, 'Have PCRE library');
AC_DEFINE('PCRE2_CODE_UNIT_WIDTH', 8, 'Have PCRE library');
AC_DEFINE("PCRE2_STATIC", 1, "");
PHP_PCRE="yes";
PHP_INSTALL_HEADERS("ext/pcre", "php_pcre.h pcrelib/");
PHP_INSTALL_HEADERS("ext/pcre", "php_pcre.h pcre2lib/");
ADD_FLAG("CFLAGS_PCRE", " /D HAVE_CONFIG_H");

ARG_WITH("pcre-jit", "Enable PCRE JIT support", "yes");
Expand Down
43 changes: 22 additions & 21 deletions ext/pcre/config0.m4
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,67 @@ PHP_ARG_WITH(pcre-jit,,[ --with-pcre-jit Enable PCRE JIT functionality
if test "$PHP_PCRE_REGEX" != "yes" && test "$PHP_PCRE_REGEX" != "no"; then
AC_MSG_CHECKING([for PCRE headers location])
for i in $PHP_PCRE_REGEX $PHP_PCRE_REGEX/include $PHP_PCRE_REGEX/include/pcre $PHP_PCRE_REGEX/local/include; do
test -f $i/pcre.h && PCRE_INCDIR=$i
test -f $i/pcre2.h && PCRE_INCDIR=$i
done

if test -z "$PCRE_INCDIR"; then
AC_MSG_ERROR([Could not find pcre.h in $PHP_PCRE_REGEX])
AC_MSG_ERROR([Could not find pcre2.h in $PHP_PCRE_REGEX])
fi
AC_MSG_RESULT([$PCRE_INCDIR])

AC_MSG_CHECKING([for PCRE library location])
for j in $PHP_PCRE_REGEX $PHP_PCRE_REGEX/$PHP_LIBDIR; do
test -f $j/libpcre.a || test -f $j/libpcre.$SHLIB_SUFFIX_NAME && PCRE_LIBDIR=$j
test -f $j/libpcre2.a || test -f $j/libpcre2.$SHLIB_SUFFIX_NAME && PCRE_LIBDIR=$j
done

if test -z "$PCRE_LIBDIR" ; then
AC_MSG_ERROR([Could not find libpcre.(a|$SHLIB_SUFFIX_NAME) in $PHP_PCRE_REGEX])
AC_MSG_ERROR([Could not find libpcre2.(a|$SHLIB_SUFFIX_NAME) in $PHP_PCRE_REGEX])
fi
AC_MSG_RESULT([$PCRE_LIBDIR])

changequote({,})
pcre_major=`grep PCRE_MAJOR $PCRE_INCDIR/pcre.h | sed -e 's/[^0-9]//g'`
pcre_minor=`grep PCRE_MINOR $PCRE_INCDIR/pcre.h | sed -e 's/[^0-9]//g'`
pcre_major=`grep PCRE2_MAJOR $PCRE_INCDIR/pcre2.h | sed -e 's/[^0-9]//g'`
pcre_minor=`grep PCRE2_MINOR $PCRE_INCDIR/pcre2.h | sed -e 's/[^0-9]//g'`
changequote([,])
pcre_minor_length=`echo "$pcre_minor" | wc -c | sed -e 's/[^0-9]//g'`
if test "$pcre_minor_length" -eq 2 ; then
pcre_minor="$pcre_minor"0
fi
pcre_version=$pcre_major$pcre_minor
if test "$pcre_version" -lt 660; then
AC_MSG_ERROR([The PCRE extension requires PCRE library version >= 6.6])
if test "$pcre_version" -lt 1030; then
AC_MSG_ERROR([The PCRE extension requires PCRE library version >= 10.30])
fi

PHP_CHECK_LIBRARY(pcre, pcre_jit_exec,
PHP_CHECK_LIBRARY(pcre2, pcre2_jit_exec,
[
AC_DEFINE(HAVE_PCRE_JIT_SUPPORT, 1, [ ])
],[
],[
-L$PCRE_LIBDIR
])
PHP_ADD_LIBRARY_WITH_PATH(pcre, $PCRE_LIBDIR)
PHP_ADD_LIBRARY_WITH_PATH(pcre2, $PCRE_LIBDIR)

AC_DEFINE(HAVE_PCRE, 1, [ ])
AC_DEFINE(PCRE2_CODE_UNIT_WIDTH, 8, [ ])
PHP_ADD_INCLUDE($PCRE_INCDIR)
PHP_NEW_EXTENSION(pcre, php_pcre.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_INSTALL_HEADERS([ext/pcre], [php_pcre.h])
else
AC_MSG_CHECKING([for PCRE library to use])
AC_MSG_RESULT([bundled])
pcrelib_sources="pcrelib/pcre_chartables.c pcrelib/pcre_ucd.c \
pcrelib/pcre_compile.c pcrelib/pcre_config.c pcrelib/pcre_exec.c \
pcrelib/pcre_fullinfo.c pcrelib/pcre_get.c pcrelib/pcre_globals.c \
pcrelib/pcre_maketables.c pcrelib/pcre_newline.c \
pcrelib/pcre_ord2utf8.c pcrelib/pcre_refcount.c pcrelib/pcre_study.c \
pcrelib/pcre_tables.c pcrelib/pcre_valid_utf8.c \
pcrelib/pcre_version.c pcrelib/pcre_xclass.c \
pcrelib/pcre_jit_compile.c"
PHP_PCRE_CFLAGS="-DHAVE_CONFIG_H -I@ext_srcdir@/pcrelib -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"
pcrelib_sources="pcre2lib/pcre2_auto_possess.c pcre2lib/pcre2_chartables.c pcre2lib/pcre2_compile.c \
pcre2lib/pcre2_config.c pcre2lib/pcre2_context.c pcre2lib/pcre2_dfa_match.c pcre2lib/pcre2_error.c \
pcre2lib/pcre2_jit_compile.c pcre2lib/pcre2_maketables.c pcre2lib/pcre2_match.c pcre2lib/pcre2_match_data.c \
pcre2lib/pcre2_newline.c pcre2lib/pcre2_ord2utf.c pcre2lib/pcre2_pattern_info.c pcre2lib/pcre2_serialize.c \
pcre2lib/pcre2_string_utils.c pcre2lib/pcre2_study.c pcre2lib/pcre2_substitute.c pcre2lib/pcre2_substring.c \
pcre2lib/pcre2_tables.c pcre2lib/pcre2_ucd.c pcre2lib/pcre2_valid_utf.c pcre2lib/pcre2_xclass.c \
pcre2lib/pcre2_find_bracket.c pcre2lib/pcre2_convert.c"
PHP_PCRE_CFLAGS="-DHAVE_CONFIG_H -I@ext_srcdir@/pcre2lib -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"
PHP_NEW_EXTENSION(pcre, $pcrelib_sources php_pcre.c, no,,$PHP_PCRE_CFLAGS)
PHP_ADD_BUILD_DIR($ext_builddir/pcrelib)
PHP_INSTALL_HEADERS([ext/pcre], [php_pcre.h pcrelib/])
PHP_ADD_BUILD_DIR($ext_builddir/pcre2lib)
PHP_INSTALL_HEADERS([ext/pcre], [php_pcre.h pcre2lib/])
AC_DEFINE(HAVE_BUNDLED_PCRE, 1, [ ])
AC_DEFINE(PCRE2_CODE_UNIT_WIDTH, 8, [ ])

if test "$PHP_PCRE_REGEX" != "no"; then
AC_MSG_CHECKING([whether to enable PCRE JIT functionality])
Expand Down
Loading