Skip to content

Commit e60ebc0

Browse files
committed
Revert FCI passing removal
1 parent 06a72af commit e60ebc0

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

ext/pcre/php_pcre.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ static int preg_get_backref(char **str, int *backref)
15461546
/* }}} */
15471547

15481548
/* Return NULL if an exception has occurred */
1549-
static zend_string *preg_do_repl_func(zend_fcall_info_cache *fcc, const char *subject, PCRE2_SIZE *offsets, zend_string **subpat_names, uint32_t num_subpats, int count, const PCRE2_SPTR mark, zend_long flags)
1549+
static zend_string *preg_do_repl_func(zend_fcall_info *fci, zend_fcall_info_cache *fcc, const char *subject, PCRE2_SIZE *offsets, zend_string **subpat_names, uint32_t num_subpats, int count, const PCRE2_SPTR mark, zend_long flags)
15501550
{
15511551
zend_string *result_str = NULL;
15521552
zval retval; /* Function return value */
@@ -1555,7 +1555,10 @@ static zend_string *preg_do_repl_func(zend_fcall_info_cache *fcc, const char *su
15551555
array_init_size(&arg, count + (mark ? 1 : 0));
15561556
populate_subpat_array(Z_ARRVAL(arg), subject, offsets, subpat_names, num_subpats, count, mark, flags);
15571557

1558-
zend_call_known_fcc(fcc, &retval, 1, &arg, NULL);
1558+
fci->retval = &retval;
1559+
fci->param_count = 1;
1560+
fci->params = &arg;
1561+
zend_call_function(fci, fcc);
15591562
zval_ptr_dtor(&arg);
15601563
/* No Exception has occurred */
15611564
if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) {
@@ -1835,8 +1838,10 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
18351838
}
18361839
/* }}} */
18371840

1838-
static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_string *subject_str, zend_fcall_info_cache *fcc, size_t limit, size_t *replace_count, zend_long flags)
1839-
{
1841+
static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_string *subject_str,
1842+
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
1843+
size_t limit, size_t *replace_count, zend_long flags
1844+
) {
18401845
uint32_t options; /* Execution options */
18411846
int count; /* Count of matched subpatterns */
18421847
zend_string **subpat_names; /* Array for named subpatterns */
@@ -1925,7 +1930,7 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
19251930

19261931
/* Use custom function to get replacement string and its length. */
19271932
zend_string *eval_result = preg_do_repl_func(
1928-
fcc, ZSTR_VAL(subject_str), offsets, subpat_names, num_subpats, count,
1933+
fci, fcc, ZSTR_VAL(subject_str), offsets, subpat_names, num_subpats, count,
19291934
pcre2_get_mark(match_data), flags);
19301935

19311936
if (UNEXPECTED(eval_result == NULL)) {
@@ -2028,7 +2033,7 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
20282033

20292034
static zend_always_inline zend_string *php_pcre_replace_func(zend_string *regex,
20302035
zend_string *subject_str,
2031-
zend_fcall_info_cache *fcc,
2036+
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
20322037
size_t limit, size_t *replace_count, zend_long flags)
20332038
{
20342039
pcre_cache_entry *pce; /* Compiled regular expression */
@@ -2039,7 +2044,7 @@ static zend_always_inline zend_string *php_pcre_replace_func(zend_string *regex,
20392044
return NULL;
20402045
}
20412046
pce->refcount++;
2042-
result = php_pcre_replace_func_impl(pce, subject_str, fcc, limit, replace_count, flags);
2047+
result = php_pcre_replace_func_impl(pce, subject_str, fci, fcc, limit, replace_count, flags);
20432048
pce->refcount--;
20442049

20452050
return result;
@@ -2143,13 +2148,13 @@ static zend_always_inline zend_string *php_replace_in_subject(
21432148
/* }}} */
21442149

21452150
static zend_string *php_replace_in_subject_func(zend_string *regex_str, const HashTable *regex_ht,
2146-
zend_fcall_info_cache *fcc,
2151+
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
21472152
zend_string *subject, size_t limit, size_t *replace_count, zend_long flags)
21482153
{
21492154
zend_string *result;
21502155

21512156
if (regex_str) {
2152-
result = php_pcre_replace_func(regex_str, subject, fcc, limit, replace_count, flags);
2157+
result = php_pcre_replace_func(regex_str, subject, fci, fcc, limit, replace_count, flags);
21532158
return result;
21542159
} else {
21552160
/* If regex is an array */
@@ -2171,7 +2176,7 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, const Ha
21712176
/* Do the actual replacement and put the result back into subject
21722177
for further replacements. */
21732178
result = php_pcre_replace_func(
2174-
regex_entry_str, subject, fcc, limit, replace_count, flags);
2179+
regex_entry_str, subject, fci, fcc, limit, replace_count, flags);
21752180
zend_tmp_string_release(tmp_regex_entry_str);
21762181
zend_string_release(subject);
21772182
subject = result;
@@ -2186,15 +2191,15 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, const Ha
21862191

21872192
static size_t php_preg_replace_func_impl(zval *return_value,
21882193
zend_string *regex_str, const HashTable *regex_ht,
2189-
zend_fcall_info_cache *fcc,
2194+
zend_fcall_info *fci, zend_fcall_info_cache *fcc,
21902195
zend_string *subject_str, const HashTable *subject_ht, zend_long limit_val, zend_long flags)
21912196
{
21922197
zend_string *result;
21932198
size_t replace_count = 0;
21942199

21952200
if (subject_str) {
21962201
result = php_replace_in_subject_func(
2197-
regex_str, regex_ht, fcc, subject_str, limit_val, &replace_count, flags);
2202+
regex_str, regex_ht, fci, fcc, subject_str, limit_val, &replace_count, flags);
21982203
if (result != NULL) {
21992204
RETVAL_STR(result);
22002205
} else {
@@ -2221,7 +2226,7 @@ static size_t php_preg_replace_func_impl(zval *return_value,
22212226
}
22222227

22232228
result = php_replace_in_subject_func(
2224-
regex_str, regex_ht, fcc, subject_entry_str, limit_val, &replace_count, flags);
2229+
regex_str, regex_ht, fci, fcc, subject_entry_str, limit_val, &replace_count, flags);
22252230
if (result != NULL) {
22262231
/* Add to return array */
22272232
ZVAL_STR(&zv, result);
@@ -2380,28 +2385,26 @@ PHP_FUNCTION(preg_replace_callback)
23802385
HashTable *subject_ht;
23812386
zend_long limit = -1, flags = 0;
23822387
size_t replace_count;
2383-
zend_fcall_info fci;
2388+
zend_fcall_info fci = empty_fcall_info;
23842389
zend_fcall_info_cache fcc = empty_fcall_info_cache;
23852390

23862391
/* Get function parameters and do error-checking. */
23872392
ZEND_PARSE_PARAMETERS_START(3, 6)
23882393
Z_PARAM_ARRAY_HT_OR_STR(regex_ht, regex_str)
2389-
Z_PARAM_FUNC_NO_TRAMPOLINE_FREE(fci, fcc)
2394+
Z_PARAM_FUNC(fci, fcc)
23902395
Z_PARAM_ARRAY_HT_OR_STR(subject_ht, subject_str)
23912396
Z_PARAM_OPTIONAL
23922397
Z_PARAM_LONG(limit)
23932398
Z_PARAM_ZVAL(zcount)
23942399
Z_PARAM_LONG(flags)
2395-
ZEND_PARSE_PARAMETERS_END_EX(goto free_trampoline);
2400+
ZEND_PARSE_PARAMETERS_END();
23962401

23972402
replace_count = php_preg_replace_func_impl(return_value, regex_str, regex_ht,
2398-
&fcc,
2403+
&fci, &fcc,
23992404
subject_str, subject_ht, limit, flags);
24002405
if (zcount) {
24012406
ZEND_TRY_ASSIGN_REF_LONG(zcount, replace_count);
24022407
}
2403-
free_trampoline:
2404-
zend_release_fcall_info_cache(&fcc);
24052408
}
24062409
/* }}} */
24072410

@@ -2437,13 +2440,18 @@ PHP_FUNCTION(preg_replace_callback_array)
24372440
}
24382441

24392442
zend_fcall_info_cache fcc = empty_fcall_info_cache;
2443+
zend_fcall_info fci = empty_fcall_info;
2444+
fci.size = sizeof(zend_fcall_info);
2445+
/* Copy potential trampoline */
2446+
ZVAL_COPY_VALUE(&fci.function_name, replace);
2447+
24402448
if (!zend_is_callable_ex(replace, NULL, 0, NULL, &fcc, NULL)) {
24412449
zend_argument_type_error(1, "must contain only valid callbacks");
24422450
goto error;
24432451
}
24442452

24452453
zval retval;
2446-
replace_count += php_preg_replace_func_impl(&retval, str_idx_regex, /* regex_ht */ NULL, &fcc,
2454+
replace_count += php_preg_replace_func_impl(&retval, str_idx_regex, /* regex_ht */ NULL, &fci, &fcc,
24472455
subject_str, subject_ht, limit, flags);
24482456
zend_release_fcall_info_cache(&fcc);
24492457

0 commit comments

Comments
 (0)