Skip to content

Commit 0980e45

Browse files
committed
ext/pcre: Refactor php_replace_in_subject_func()
We don't need the FCI anymore Make the Hashtable param const Throw exception on non string entries
1 parent d759628 commit 0980e45

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ext/pcre/php_pcre.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,9 +2142,8 @@ static zend_always_inline zend_string *php_replace_in_subject(
21422142
}
21432143
/* }}} */
21442144

2145-
/* {{{ php_replace_in_subject_func */
2146-
static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTable *regex_ht,
2147-
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
2145+
static zend_string *php_replace_in_subject_func(zend_string *regex_str, const HashTable *regex_ht,
2146+
zend_fcall_info_cache *fcc,
21482147
zend_string *subject, size_t limit, size_t *replace_count, zend_long flags)
21492148
{
21502149
zend_string *result;
@@ -2164,7 +2163,10 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl
21642163
ZEND_HASH_FOREACH_VAL(regex_ht, regex_entry) {
21652164
/* Make sure we're dealing with strings. */
21662165
zend_string *tmp_regex_entry_str;
2167-
zend_string *regex_entry_str = zval_get_tmp_string(regex_entry, &tmp_regex_entry_str);
2166+
zend_string *regex_entry_str = zval_try_get_tmp_string(regex_entry, &tmp_regex_entry_str);
2167+
if (UNEXPECTED(regex_entry_str == NULL)) {
2168+
break;
2169+
}
21682170

21692171
/* Do the actual replacement and put the result back into subject
21702172
for further replacements. */
@@ -2181,7 +2183,6 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl
21812183
return subject;
21822184
}
21832185
}
2184-
/* }}} */
21852186

21862187
/* {{{ preg_replace_func_impl */
21872188
static size_t preg_replace_func_impl(zval *return_value,
@@ -2194,7 +2195,7 @@ static size_t preg_replace_func_impl(zval *return_value,
21942195

21952196
if (subject_str) {
21962197
result = php_replace_in_subject_func(
2197-
regex_str, regex_ht, fci, fcc, subject_str, limit_val, &replace_count, flags);
2198+
regex_str, regex_ht, fcc, subject_str, limit_val, &replace_count, flags);
21982199
if (result != NULL) {
21992200
RETVAL_STR(result);
22002201
} else {
@@ -2218,7 +2219,7 @@ static size_t preg_replace_func_impl(zval *return_value,
22182219
zend_string *subject_entry_str = zval_get_tmp_string(subject_entry, &tmp_subject_entry_str);
22192220

22202221
result = php_replace_in_subject_func(
2221-
regex_str, regex_ht, fci, fcc, subject_entry_str, limit_val, &replace_count, flags);
2222+
regex_str, regex_ht, fcc, subject_entry_str, limit_val, &replace_count, flags);
22222223
if (result != NULL) {
22232224
/* Add to return array */
22242225
ZVAL_STR(&zv, result);

0 commit comments

Comments
 (0)