From: Marcus Boerger Date: Wed, 12 Oct 2005 22:37:30 +0000 (+0000) Subject: - Add/expose function to compile and access pcre_cache_entry structs X-Git-Tag: RELEASE_0_9_1~129 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb48d356bd4965ffe2602a963d35cebf712a6f5b;p=php - Add/expose function to compile and access pcre_cache_entry structs --- diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index e10b6f4988..8b74cf34d3 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -124,18 +124,9 @@ static int pcre_clean_cache(void *data, void *arg TSRMLS_DC) } /* }}} */ -/* {{{ pcre_get_compiled_regex +/* {{{ pcre_get_compiled_regex_cache_ex */ -PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_options TSRMLS_DC) -{ - int compile_options; - return pcre_get_compiled_regex_ex(regex, extra, preg_options, &compile_options TSRMLS_CC); -} -/* }}} */ - -/* {{{ pcre_get_compiled_regex_ex - */ -PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC) +static pcre_cache_entry* pcre_get_compiled_regex_cache_ex(char *regex, int regex_len, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC) { pcre *re = NULL; int coptions = 0; @@ -147,7 +138,6 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr char end_delimiter; char *p, *pp; char *pattern; - int regex_len; int do_study = 0; int poptions = 0; unsigned const char *tables = NULL; @@ -174,7 +164,7 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr *extra = pce->extra; *preg_options = pce->preg_options; *compile_options = pce->compile_options; - return pce->re; + return pce; #if HAVE_SETLOCALE } } @@ -334,9 +324,41 @@ PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *pr new_entry.tables = tables; #endif zend_hash_update(&PCRE_G(pcre_cache), regex, regex_len+1, (void *)&new_entry, - sizeof(pcre_cache_entry), NULL); + sizeof(pcre_cache_entry), (void**)&pce); + + return pce; +} +/* }}} */ - return re; +/* {{{ pcre_get_compiled_regex + */ +PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_options TSRMLS_DC) +{ + int compile_options; + pcre_cache_entry * pce = pcre_get_compiled_regex_cache_ex(regex, strlen(regex), extra, preg_options, &compile_options TSRMLS_CC); + + return pce ? pce->re : NULL; +} +/* }}} */ + +/* {{{ pcre_get_compiled_regex_ex + */ +PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC) +{ + pcre_cache_entry * pce = pcre_get_compiled_regex_cache_ex(regex, strlen(regex), extra, preg_options, compile_options TSRMLS_CC); + + return pce ? pce->re : NULL; +} +/* }}} */ + +/* {{{ pcre_get_compiled_regex_cache + */ +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC) +{ + pcre_extra *extra; + int preg_options; + int compile_options; + return pcre_get_compiled_regex_cache_ex(regex, regex_len, &extra, &preg_options, &compile_options TSRMLS_CC); } /* }}} */ diff --git a/ext/pcre/php_pcre.h b/ext/pcre/php_pcre.h index fafd68bafb..8d1f8f62fe 100644 --- a/ext/pcre/php_pcre.h +++ b/ext/pcre/php_pcre.h @@ -57,8 +57,11 @@ typedef struct { unsigned const char *tables; #endif int compile_options; + int refcount; } pcre_cache_entry; +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC); + ZEND_BEGIN_MODULE_GLOBALS(pcre) HashTable pcre_cache; ZEND_END_MODULE_GLOBALS(pcre)