Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Check jit in pattern by flag instead of doing it on demand
  • Loading branch information
dstogov authored and weltling committed Nov 13, 2017
commit cd2c26cf846df697f6145de0975dba6045f2f523
34 changes: 10 additions & 24 deletions ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

#define PREG_GREP_INVERT (1<<0)

#define PREG_JIT (1<<3)

#define PCRE_CACHE_SIZE 4096

struct _pcre_cache_entry {
Expand Down Expand Up @@ -708,7 +710,9 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
if (PCRE_G(jit)) {
/* Enable PCRE JIT compiler */
rc = pcre2_jit_compile(re, PCRE2_JIT_COMPLETE);
if (rc < 0) {
if (EXPECTED(rc >= 0)) {
poptions = PREG_JIT;
} else {
pcre2_get_error_message(rc, error, sizeof(error));
php_error_docref(NULL, E_WARNING, "JIT compilation failed: %s", error);
}
Expand Down Expand Up @@ -898,8 +902,6 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, size_t sub
PCRE2_SPTR mark = NULL; /* Target for MARK name */
zval marks; /* Array of marks for PREG_PATTERN_ORDER */
pcre2_match_data *match_data;
size_t jit_size;
int rc;
PCRE2_SIZE start_offset2;

ZVAL_UNDEF(&marks);
Expand Down Expand Up @@ -977,7 +979,6 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, size_t sub
no_utf_check = PCRE2_NO_UTF_CHECK;
}

rc = pcre2_pattern_info(pce->re, PCRE2_INFO_JITSIZE, &jit_size);
#endif
if (size_offsets <= 32) {
match_data = mdata;
Expand All @@ -998,7 +999,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, size_t sub
do {
/* Execute the regular expression. */
#ifdef HAVE_PCRE_JIT_SUPPORT
if (PCRE_G(jit) && !rc && jit_size > 0
if (PCRE_G(jit) && (pce->preg_options & PREG_JIT)
&& no_utf_check && !g_notempty) {
if (PCRE2_UNSET == start_offset2 || start_offset2 > subject_len) {
pcre_handle_exec_error(PCRE2_ERROR_BADOFFSET);
Expand Down Expand Up @@ -1432,8 +1433,6 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
size_t result_len; /* Length of result */
zend_string *result; /* Result of replacement */
pcre2_match_data *match_data;
size_t jit_size;
int rc;

if (UNEXPECTED(pce->preg_options & PREG_REPLACE_EVAL)) {
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
Expand Down Expand Up @@ -1470,7 +1469,6 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
no_utf_check = PCRE2_NO_UTF_CHECK;
}

rc = pcre2_pattern_info(pce->re, PCRE2_INFO_JITSIZE, &jit_size);
#endif
if (size_offsets <= 32) {
match_data = mdata;
Expand All @@ -1488,7 +1486,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
while (1) {
/* Execute the regular expression. */
#ifdef HAVE_PCRE_JIT_SUPPORT
if (PCRE_G(jit) && !rc && jit_size > 0
if (PCRE_G(jit) && (pce->preg_options & PREG_JIT)
&& no_utf_check && !g_notempty) {
count = pcre2_jit_match(pce->re, subject, subject_len, start_offset,
no_utf_check|g_notempty, match_data, mctx);
Expand Down Expand Up @@ -1681,8 +1679,6 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
zend_string *result; /* Result of replacement */
zend_string *eval_result=NULL; /* Result of custom function */
pcre2_match_data *match_data;
size_t jit_size;
int rc;

if (UNEXPECTED(pce->preg_options & PREG_REPLACE_EVAL)) {
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
Expand Down Expand Up @@ -1719,7 +1715,6 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
no_utf_check = PCRE2_NO_UTF_CHECK;
}

rc = pcre2_pattern_info(pce->re, PCRE2_INFO_JITSIZE, &jit_size);
#endif
match_data = pcre2_match_data_create_from_pattern(pce->re, gctx);
if (!match_data) {
Expand All @@ -1733,7 +1728,7 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
while (1) {
/* Execute the regular expression. */
#ifdef HAVE_PCRE_JIT_SUPPORT
if (PCRE_G(jit) && !rc && jit_size > 0
if (PCRE_G(jit) && (pce->preg_options & PREG_JIT)
&& no_utf_check && !g_notempty) {
count = pcre2_jit_match(pce->re, subject, subject_len, start_offset,
no_utf_check|g_notempty, match_data, mctx);
Expand Down Expand Up @@ -2338,8 +2333,6 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
uint32_t offset_capture; /* If offsets should be captured */
zval tmp;
pcre2_match_data *match_data;
size_t jit_size;
int rc;

no_empty = flags & PREG_SPLIT_NO_EMPTY;
delim_capture = flags & PREG_SPLIT_DELIM_CAPTURE;
Expand All @@ -2366,7 +2359,6 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
no_utf_check = PCRE2_NO_UTF_CHECK;
}

rc = pcre2_pattern_info(pce->re, PCRE2_INFO_JITSIZE, &jit_size);
#endif
if (size_offsets <= 32) {
match_data = mdata;
Expand All @@ -2381,7 +2373,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
/* Get next piece if no limit or limit not yet reached and something matched*/
while ((limit_val == -1 || limit_val > 1)) {
#ifdef HAVE_PCRE_JIT_SUPPORT
if (PCRE_G(jit) && !rc && jit_size > 0
if (PCRE_G(jit) && (pce->preg_options & PREG_JIT)
&& no_utf_check && !g_notempty) {
count = pcre2_jit_match(pce->re, ZSTR_VAL(subject_str), ZSTR_LEN(subject_str), start_offset,
no_utf_check|g_notempty, match_data, mctx);
Expand Down Expand Up @@ -2660,8 +2652,6 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
zend_bool invert; /* Whether to return non-matching
entries */
pcre2_match_data *match_data;
size_t jit_size;
int rc;
invert = flags & PREG_GREP_INVERT ? 1 : 0;

/* Calculate the size of the offsets array, and allocate memory for it. */
Expand All @@ -2682,18 +2672,14 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
return;
}

#ifdef HAVE_PCRE_JIT_SUPPORT
rc = pcre2_pattern_info(pce->re, PCRE2_INFO_JITSIZE, &jit_size);
#endif

/* Go through the input array */
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) {
zend_string *subject_str = zval_get_string(entry);

/* Perform the match */
#ifdef HAVE_PCRE_JIT_SUPPORT
no_utf_check = (pce->compile_options & PCRE2_UTF) ? 0 : PCRE2_NO_UTF_CHECK;
if (PCRE_G(jit) && !rc && jit_size > 0
if (PCRE_G(jit) && (pce->preg_options && PREG_JIT)
&& no_utf_check) {
count = pcre2_jit_match(pce->re, ZSTR_VAL(subject_str), ZSTR_LEN(subject_str), 0,
no_utf_check, match_data, mctx);
Expand Down