Skip to content

Commit 05e0f53

Browse files
committed
ext/pcre: Refactor php_pcre_replace_func()
We don't need the FCI anymore Be more rigourous about the entries we receive
1 parent ca2af27 commit 05e0f53

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

ext/pcre/php_pcre.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,10 +2026,9 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
20262026
return result;
20272027
}
20282028

2029-
/* {{{ php_pcre_replace_func */
20302029
static zend_always_inline zend_string *php_pcre_replace_func(zend_string *regex,
20312030
zend_string *subject_str,
2032-
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
2031+
zend_fcall_info_cache *fcc,
20332032
size_t limit, size_t *replace_count, zend_long flags)
20342033
{
20352034
pcre_cache_entry *pce; /* Compiled regular expression */
@@ -2045,7 +2044,6 @@ static zend_always_inline zend_string *php_pcre_replace_func(zend_string *regex,
20452044

20462045
return result;
20472046
}
2048-
/* }}} */
20492047

20502048
/* {{{ php_pcre_replace_array */
20512049
static zend_string *php_pcre_replace_array(HashTable *regex,
@@ -2144,16 +2142,14 @@ static zend_always_inline zend_string *php_replace_in_subject(
21442142
}
21452143
/* }}} */
21462144

2147-
/* {{{ php_replace_in_subject_func */
21482145
static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTable *regex_ht,
21492146
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
21502147
zend_string *subject, size_t limit, size_t *replace_count, zend_long flags)
21512148
{
21522149
zend_string *result;
21532150

21542151
if (regex_str) {
2155-
result = php_pcre_replace_func(
2156-
regex_str, subject, fci, fcc, limit, replace_count, flags);
2152+
result = php_pcre_replace_func(regex_str, subject, fcc, limit, replace_count, flags);
21572153
return result;
21582154
} else {
21592155
/* If regex is an array */
@@ -2166,14 +2162,16 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl
21662162
/* For each entry in the regex array, get the entry */
21672163
ZEND_HASH_FOREACH_VAL(regex_ht, regex_entry) {
21682164
/* Make sure we're dealing with strings. */
2169-
zend_string *tmp_regex_entry_str;
2170-
zend_string *regex_entry_str = zval_get_tmp_string(regex_entry, &tmp_regex_entry_str);
2165+
zend_string *regex_entry_str = zval_try_get_string(regex_entry);
2166+
if (UNEXPECTED(regex_entry_str == NULL)) {
2167+
break;
2168+
}
21712169

21722170
/* Do the actual replacement and put the result back into subject
21732171
for further replacements. */
21742172
result = php_pcre_replace_func(
2175-
regex_entry_str, subject, fci, fcc, limit, replace_count, flags);
2176-
zend_tmp_string_release(tmp_regex_entry_str);
2173+
regex_entry_str, subject, fcc, limit, replace_count, flags);
2174+
zend_string_release_ex(regex_entry_str, false);
21772175
zend_string_release(subject);
21782176
subject = result;
21792177
if (UNEXPECTED(result == NULL)) {
@@ -2184,7 +2182,6 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl
21842182
return subject;
21852183
}
21862184
}
2187-
/* }}} */
21882185

21892186
/* {{{ preg_replace_func_impl */
21902187
static size_t preg_replace_func_impl(zval *return_value,

0 commit comments

Comments
 (0)