17
17
#include "php.h"
18
18
#include "php_ini.h"
19
19
#include "php_pcre.h"
20
+
21
+ #include <Optimizer/zend_func_info.h>
22
+
20
23
#include "ext/standard/info.h"
21
24
#include "ext/standard/basic_functions.h"
22
25
#include "zend_smart_str.h"
@@ -2381,38 +2384,38 @@ PHP_FUNCTION(preg_replace_callback)
2381
2384
zend_long limit = -1 , flags = 0 ;
2382
2385
size_t replace_count ;
2383
2386
zend_fcall_info fci ;
2384
- zend_fcall_info_cache fcc ;
2387
+ zend_fcall_info_cache fcc = empty_fcall_info_cache ;
2385
2388
2386
2389
/* Get function parameters and do error-checking. */
2387
2390
ZEND_PARSE_PARAMETERS_START (3 , 6 )
2388
2391
Z_PARAM_ARRAY_HT_OR_STR (regex_ht , regex_str )
2389
- Z_PARAM_FUNC (fci , fcc )
2392
+ Z_PARAM_FUNC_NO_TRAMPOLINE_FREE (fci , fcc )
2390
2393
Z_PARAM_ARRAY_HT_OR_STR (subject_ht , subject_str )
2391
2394
Z_PARAM_OPTIONAL
2392
2395
Z_PARAM_LONG (limit )
2393
2396
Z_PARAM_ZVAL (zcount )
2394
2397
Z_PARAM_LONG (flags )
2395
- ZEND_PARSE_PARAMETERS_END ( );
2398
+ ZEND_PARSE_PARAMETERS_END_EX ( goto free_trampoline );
2396
2399
2397
2400
replace_count = php_preg_replace_func_impl (return_value , regex_str , regex_ht ,
2398
2401
& fcc ,
2399
2402
subject_str , subject_ht , limit , flags );
2400
2403
if (zcount ) {
2401
2404
ZEND_TRY_ASSIGN_REF_LONG (zcount , replace_count );
2402
2405
}
2406
+ free_trampoline :
2407
+ zend_release_fcall_info_cache (& fcc );
2403
2408
}
2404
2409
/* }}} */
2405
2410
2406
2411
/* {{{ Perform Perl-style regular expression replacement using replacement callback. */
2407
2412
PHP_FUNCTION (preg_replace_callback_array )
2408
2413
{
2409
- zval zv , * replace , * zcount = NULL ;
2414
+ zval * replace , * zcount = NULL ;
2410
2415
HashTable * pattern , * subject_ht ;
2411
2416
zend_string * subject_str , * str_idx_regex ;
2412
2417
zend_long limit = -1 , flags = 0 ;
2413
2418
size_t replace_count = 0 ;
2414
- zend_fcall_info fci ;
2415
- zend_fcall_info_cache fcc ;
2416
2419
2417
2420
/* Get function parameters and do error-checking. */
2418
2421
ZEND_PARSE_PARAMETERS_START (2 , 5 )
@@ -2424,40 +2427,39 @@ PHP_FUNCTION(preg_replace_callback_array)
2424
2427
Z_PARAM_LONG (flags )
2425
2428
ZEND_PARSE_PARAMETERS_END ();
2426
2429
2427
- fci .size = sizeof (fci );
2428
- fci .object = NULL ;
2429
- fci .named_params = NULL ;
2430
-
2431
2430
if (subject_ht ) {
2432
2431
GC_TRY_ADDREF (subject_ht );
2433
2432
} else {
2434
2433
GC_TRY_ADDREF (subject_str );
2435
2434
}
2436
2435
2437
2436
ZEND_HASH_FOREACH_STR_KEY_VAL (pattern , str_idx_regex , replace ) {
2438
- if (!zend_is_callable_ex (replace , NULL , 0 , NULL , & fcc , NULL )) {
2439
- zend_argument_type_error (1 , "must contain only valid callbacks" );
2440
- goto error ;
2441
- }
2442
2437
if (!str_idx_regex ) {
2443
2438
zend_argument_type_error (1 , "must contain only string patterns as keys" );
2444
2439
goto error ;
2445
2440
}
2446
2441
2447
- ZVAL_COPY_VALUE (& fci .function_name , replace );
2442
+ zend_fcall_info_cache fcc = empty_fcall_info_cache ;
2443
+ if (!zend_is_callable_ex (replace , NULL , 0 , NULL , & fcc , NULL )) {
2444
+ zend_argument_type_error (1 , "must contain only valid callbacks" );
2445
+ goto error ;
2446
+ }
2448
2447
2449
- replace_count += php_preg_replace_func_impl (& zv , str_idx_regex , /* regex_ht */ NULL , & fcc ,
2448
+ zval retval ;
2449
+ replace_count += php_preg_replace_func_impl (& retval , str_idx_regex , /* regex_ht */ NULL , & fcc ,
2450
2450
subject_str , subject_ht , limit , flags );
2451
- switch (Z_TYPE (zv )) {
2451
+ zend_release_fcall_info_cache (& fcc );
2452
+
2453
+ switch (Z_TYPE (retval )) {
2452
2454
case IS_ARRAY :
2453
2455
ZEND_ASSERT (subject_ht );
2454
2456
zend_array_release (subject_ht );
2455
- subject_ht = Z_ARR (zv );
2457
+ subject_ht = Z_ARR (retval );
2456
2458
break ;
2457
2459
case IS_STRING :
2458
2460
ZEND_ASSERT (subject_str );
2459
2461
zend_string_release (subject_str );
2460
- subject_str = Z_STR (zv );
2462
+ subject_str = Z_STR (retval );
2461
2463
break ;
2462
2464
case IS_NULL :
2463
2465
RETVAL_NULL ();
0 commit comments