com php-src: Add pcre_get_compiled_regex_cache_ex( ) with local_aware flag: ext/pcre/php_pcre.c ext/pcre/php_pcre.h

From: Date: Tue, 08 Oct 2019 14:11:55 +0000
Subject: com php-src: Add pcre_get_compiled_regex_cache_ex( ) with local_aware flag: ext/pcre/php_pcre.c ext/pcre/php_pcre.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-108810@lists.php.net to get a copy of this message
Commit: a8f60ac9dd3ba8fed24370799603b92487fdf362 Author: Sergei Turchanov <turchanov@farpost.com> Tue, 8 Oct 2019 17:55:07 +1000 Committer: Nikita Popov <nikita.ppv@gmail.com> Tue, 8 Oct 2019 16:11:55 +0200 Parents: 46894580b06c1ba630a804ff0bbb9e61076720f4 Branches: PHP-7.2 PHP-7.3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a8f60ac9dd3ba8fed24370799603b92487fdf362 Log: Add pcre_get_compiled_regex_cache_ex() with local_aware flag A new function pcre_get_compiled_regex_cache_ex() is introduced, which allows to compile regexp pattern using the "C" locale instead of a current locale. This will be needed to replace setlocale() usage in fileinfo, which is not thread-safe. Changed paths: M ext/pcre/php_pcre.c M ext/pcre/php_pcre.h Diff: diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index d7d186540ab..f919faa298e 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -322,7 +322,7 @@ static zend_always_inline int calculate_unit_length(pcre_cache_entry *pce, char /* {{{ pcre_get_compiled_regex_cache */ -PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware) { pcre *re = NULL; pcre_extra *extra; @@ -344,7 +344,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) zend_string *key; #if HAVE_SETLOCALE - if (BG(locale_string) && + if (locale_aware && BG(locale_string) && (ZSTR_LEN(BG(locale_string)) != 1 && ZSTR_VAL(BG(locale_string))[0] != 'C')) { key = zend_string_alloc(ZSTR_LEN(regex) + ZSTR_LEN(BG(locale_string)) + 1, 0); memcpy(ZSTR_VAL(key), ZSTR_VAL(BG(locale_string)), ZSTR_LEN(BG(locale_string)) + 1); @@ -636,6 +636,14 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) } /* }}} */ +/* {{{ pcre_get_compiled_regex_cache + */ +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) +{ + return pcre_get_compiled_regex_cache_ex(regex, 1); +} +/* }}} */ + /* {{{ pcre_get_compiled_regex */ PHPAPI pcre* pcre_get_compiled_regex(zend_string *regex, pcre_extra **extra, int *preg_options) diff --git a/ext/pcre/php_pcre.h b/ext/pcre/php_pcre.h index 137cce5a9e7..62edb29da88 100644 --- a/ext/pcre/php_pcre.h +++ b/ext/pcre/php_pcre.h @@ -57,6 +57,7 @@ typedef struct { } pcre_cache_entry; PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex); +PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware); PHPAPI void php_pcre_match_impl( pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, zval *subpats, int global, int use_flags, zend_long flags, zend_long start_offset);

« previous php.cvs (#108810) next »