Skip to content
Closed
Show file tree
Hide file tree
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
Hide the pcre_cache_entry implementation
  • Loading branch information
weltling committed Nov 9, 2017
commit cf9e41971518a4089c43a8755d66c7fb653295d9
27 changes: 27 additions & 0 deletions ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
# define PCRE2_NOTEMPTY_ATSTART PCRE_NOTEMPTY
#endif

struct _pcre_cache_entry {
pcre2_code *re;
uint32_t preg_options;
uint32_t capture_count;
uint32_t name_count;
#if HAVE_SETLOCALE
const uint8_t *tables;
#endif
uint32_t compile_options;
int refcount;
};

enum {
PHP_PCRE_NO_ERROR = 0,
PHP_PCRE_INTERNAL_ERROR,
Expand Down Expand Up @@ -2649,6 +2661,21 @@ PHPAPI pcre2_compile_context *php_pcre_cctx(void)
return cctx;
}/*}}}*/

PHPAPI void php_pcre_pce_incref(pcre_cache_entry *pce)
{/*{{{*/
pce->refcount++;
}/*}}}*/

PHPAPI void php_pcre_pce_decref(pcre_cache_entry *pce)
{/*{{{*/
pce->refcount--;
}/*}}}*/

PHPAPI pcre2_code *php_pcre_pce_re(pcre_cache_entry *pce)
{/*{{{*/
return pce->re;
}/*}}}*/

#endif /* HAVE_PCRE || HAVE_BUNDLED_PCRE */

/*
Expand Down
14 changes: 3 additions & 11 deletions ext/pcre/php_pcre.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@ extern zend_module_entry pcre_module_entry;
#include "php_version.h"
#define PHP_PCRE_VERSION PHP_VERSION

struct _pcre_cache_entry {
pcre2_code *re;
uint32_t preg_options;
uint32_t capture_count;
uint32_t name_count;
#if HAVE_SETLOCALE
const uint8_t *tables;
#endif
uint32_t compile_options;
int refcount;
};
typedef struct _pcre_cache_entry pcre_cache_entry;

PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex);
Expand All @@ -73,6 +62,9 @@ PHPAPI void php_pcre_grep_impl( pcre_cache_entry *pce, zval *input, zval *ret
PHPAPI pcre2_match_context *php_pcre_mctx(void);
PHPAPI pcre2_general_context *php_pcre_gctx(void);
PHPAPI pcre2_compile_context *php_pcre_cctx(void);
PHPAPI void php_pcre_pce_incref(pcre_cache_entry *);
PHPAPI void php_pcre_pce_decref(pcre_cache_entry *);
PHPAPI pcre2_code *php_pcre_pce_re(pcre_cache_entry *);

ZEND_BEGIN_MODULE_GLOBALS(pcre)
HashTable pcre_cache;
Expand Down
14 changes: 8 additions & 6 deletions ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
/* pcre_get_compiled_regex_cache has already sent error */
return NULL;
}
intern->u.regex.pce->refcount++;
php_pcre_pce_incref(intern->u.regex.pce);
break;
}
#endif
Expand Down Expand Up @@ -2034,7 +2034,8 @@ SPL_METHOD(RegexIterator, accept)
size_t count = 0;
zval zcount, *replacement, tmp_replacement, rv;
pcre2_match_data *match_data;
int re;
pcre2_code *re;
int rc;

if (zend_parse_parameters_none() == FAILURE) {
return;
Expand All @@ -2059,10 +2060,11 @@ SPL_METHOD(RegexIterator, accept)
{
case REGIT_MODE_MAX: /* won't happen but makes compiler happy */
case REGIT_MODE_MATCH:
match_data = pcre2_match_data_create_from_pattern(intern->u.regex.pce->re, php_pcre_gctx());
re = php_pcre_pce_re(intern->u.regex.pce);
match_data = pcre2_match_data_create_from_pattern(re, php_pcre_gctx());
/* XXX error check. */
re = pcre2_match(intern->u.regex.pce->re, ZSTR_VAL(subject), ZSTR_LEN(subject), 0, 0, match_data, php_pcre_mctx());
RETVAL_BOOL(re >= 0);
rc = pcre2_match(re, ZSTR_VAL(subject), ZSTR_LEN(subject), 0, 0, match_data, php_pcre_mctx());
RETVAL_BOOL(rc >= 0);
pcre2_match_data_free(match_data);
break;

Expand Down Expand Up @@ -2327,7 +2329,7 @@ static void spl_dual_it_free_storage(zend_object *_object)
#if HAVE_PCRE || HAVE_BUNDLED_PCRE
if (object->dit_type == DIT_RegexIterator || object->dit_type == DIT_RecursiveRegexIterator) {
if (object->u.regex.pce) {
object->u.regex.pce->refcount--;
php_pcre_pce_decref(object->u.regex.pce);
}
if (object->u.regex.regex) {
zend_string_release(object->u.regex.regex);
Expand Down