Skip to content

Commit af49cff

Browse files
committed
ext/pcre: Refactor preg_replace_func_impl()
We don't need FCI anymore Make the Hashtable params const Rename function to indicate it is a PHP pcre function
1 parent a942303 commit af49cff

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

ext/pcre/php_pcre.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,11 +2183,10 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, const Ha
21832183
}
21842184
}
21852185

2186-
/* {{{ preg_replace_func_impl */
2187-
static size_t preg_replace_func_impl(zval *return_value,
2188-
zend_string *regex_str, HashTable *regex_ht,
2189-
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
2190-
zend_string *subject_str, HashTable *subject_ht, zend_long limit_val, zend_long flags)
2186+
static size_t php_preg_replace_func_impl(zval *return_value,
2187+
zend_string *regex_str, const HashTable *regex_ht,
2188+
zend_fcall_info_cache *fcc,
2189+
zend_string *subject_str, const HashTable *subject_ht, zend_long limit_val, zend_long flags)
21912190
{
21922191
zend_string *result;
21932192
size_t replace_count = 0;
@@ -2215,7 +2214,10 @@ static size_t preg_replace_func_impl(zval *return_value,
22152214
and add the result to the return_value array. */
22162215
ZEND_HASH_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) {
22172216
zend_string *tmp_subject_entry_str;
2218-
zend_string *subject_entry_str = zval_get_tmp_string(subject_entry, &tmp_subject_entry_str);
2217+
zend_string *subject_entry_str = zval_try_get_tmp_string(subject_entry, &tmp_subject_entry_str);
2218+
if (UNEXPECTED(subject_entry_str == NULL)) {
2219+
break;
2220+
}
22192221

22202222
result = php_replace_in_subject_func(
22212223
regex_str, regex_ht, fcc, subject_entry_str, limit_val, &replace_count, flags);
@@ -2234,7 +2236,6 @@ static size_t preg_replace_func_impl(zval *return_value,
22342236

22352237
return replace_count;
22362238
}
2237-
/* }}} */
22382239

22392240
static void _preg_replace_common(
22402241
zval *return_value,
@@ -2392,8 +2393,8 @@ PHP_FUNCTION(preg_replace_callback)
23922393
Z_PARAM_LONG(flags)
23932394
ZEND_PARSE_PARAMETERS_END();
23942395

2395-
replace_count = preg_replace_func_impl(return_value, regex_str, regex_ht,
2396-
&fci, &fcc,
2396+
replace_count = php_preg_replace_func_impl(return_value, regex_str, regex_ht,
2397+
&fcc,
23972398
subject_str, subject_ht, limit, flags);
23982399
if (zcount) {
23992400
ZEND_TRY_ASSIGN_REF_LONG(zcount, replace_count);
@@ -2444,7 +2445,7 @@ PHP_FUNCTION(preg_replace_callback_array)
24442445

24452446
ZVAL_COPY_VALUE(&fci.function_name, replace);
24462447

2447-
replace_count += preg_replace_func_impl(&zv, str_idx_regex, /* regex_ht */ NULL, &fci, &fcc,
2448+
replace_count += php_preg_replace_func_impl(&zv, str_idx_regex, /* regex_ht */ NULL, &fcc,
24482449
subject_str, subject_ht, limit, flags);
24492450
switch (Z_TYPE(zv)) {
24502451
case IS_ARRAY:

0 commit comments

Comments
 (0)