Skip to content

Commit a8f60ac

Browse files
turchanovnikic
authored andcommitted
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.
1 parent 4689458 commit a8f60ac

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

ext/pcre/php_pcre.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static zend_always_inline int calculate_unit_length(pcre_cache_entry *pce, char
322322

323323
/* {{{ pcre_get_compiled_regex_cache
324324
*/
325-
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
325+
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware)
326326
{
327327
pcre *re = NULL;
328328
pcre_extra *extra;
@@ -344,7 +344,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
344344
zend_string *key;
345345

346346
#if HAVE_SETLOCALE
347-
if (BG(locale_string) &&
347+
if (locale_aware && BG(locale_string) &&
348348
(ZSTR_LEN(BG(locale_string)) != 1 && ZSTR_VAL(BG(locale_string))[0] != 'C')) {
349349
key = zend_string_alloc(ZSTR_LEN(regex) + ZSTR_LEN(BG(locale_string)) + 1, 0);
350350
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)
636636
}
637637
/* }}} */
638638

639+
/* {{{ pcre_get_compiled_regex_cache
640+
*/
641+
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
642+
{
643+
return pcre_get_compiled_regex_cache_ex(regex, 1);
644+
}
645+
/* }}} */
646+
639647
/* {{{ pcre_get_compiled_regex
640648
*/
641649
PHPAPI pcre* pcre_get_compiled_regex(zend_string *regex, pcre_extra **extra, int *preg_options)

ext/pcre/php_pcre.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ typedef struct {
5757
} pcre_cache_entry;
5858

5959
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex);
60+
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, int locale_aware);
6061

6162
PHPAPI void php_pcre_match_impl( pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value,
6263
zval *subpats, int global, int use_flags, zend_long flags, zend_long start_offset);

0 commit comments

Comments
 (0)