Skip to content

Commit 035a27c

Browse files
committed
Only compute callback name in error cases
Mostly the callback name is only used to report an error. Try to avoid calculating it if no error occurred.
1 parent ee8e75a commit 035a27c

File tree

12 files changed

+54
-87
lines changed

12 files changed

+54
-87
lines changed

Zend/zend_builtin_functions.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,21 +1593,20 @@ ZEND_FUNCTION(trigger_error)
15931593
ZEND_FUNCTION(set_error_handler)
15941594
{
15951595
zval *error_handler;
1596-
zend_string *error_handler_name = NULL;
15971596
zend_long error_type = E_ALL;
15981597

15991598
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|l", &error_handler, &error_type) == FAILURE) {
16001599
return;
16011600
}
16021601

16031602
if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */
1604-
if (!zend_is_callable(error_handler, 0, &error_handler_name)) {
1603+
if (!zend_is_callable(error_handler, 0, NULL)) {
1604+
zend_string *error_handler_name = zend_get_callable_name(error_handler);
16051605
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
16061606
get_active_function_name(), error_handler_name?ZSTR_VAL(error_handler_name):"unknown");
16071607
zend_string_release(error_handler_name);
16081608
return;
16091609
}
1610-
zend_string_release(error_handler_name);
16111610
}
16121611

16131612
if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
@@ -1662,20 +1661,19 @@ ZEND_FUNCTION(restore_error_handler)
16621661
ZEND_FUNCTION(set_exception_handler)
16631662
{
16641663
zval *exception_handler;
1665-
zend_string *exception_handler_name = NULL;
16661664

16671665
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &exception_handler) == FAILURE) {
16681666
return;
16691667
}
16701668

16711669
if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
1672-
if (!zend_is_callable(exception_handler, 0, &exception_handler_name)) {
1670+
if (!zend_is_callable(exception_handler, 0, NULL)) {
1671+
zend_string *exception_handler_name = zend_get_callable_name(exception_handler);
16731672
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
16741673
get_active_function_name(), exception_handler_name?ZSTR_VAL(exception_handler_name):"unknown");
16751674
zend_string_release(exception_handler_name);
16761675
return;
16771676
}
1678-
zend_string_release(exception_handler_name);
16791677
}
16801678

16811679
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {

Zend/zend_execute_API.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,19 +703,18 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
703703
}
704704

705705
if (!fci_cache || !fci_cache->initialized) {
706-
zend_string *callable_name;
707706
char *error = NULL;
708707

709708
if (!fci_cache) {
710709
fci_cache = &fci_cache_local;
711710
}
712711

713-
if (!zend_is_callable_ex(&fci->function_name, fci->object, IS_CALLABLE_CHECK_SILENT, &callable_name, fci_cache, &error)) {
712+
if (!zend_is_callable_ex(&fci->function_name, fci->object, IS_CALLABLE_CHECK_SILENT, NULL, fci_cache, &error)) {
714713
if (error) {
714+
zend_string *callable_name
715+
= zend_get_callable_name_ex(&fci->function_name, fci->object);
715716
zend_error(E_WARNING, "Invalid callback %s, %s", ZSTR_VAL(callable_name), error);
716717
efree(error);
717-
}
718-
if (callable_name) {
719718
zend_string_release(callable_name);
720719
}
721720
if (EG(current_execute_data) == &dummy_execute_data) {
@@ -730,16 +729,12 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
730729
zend_error(E_DEPRECATED, "%s", error);
731730
efree(error);
732731
if (UNEXPECTED(EG(exception))) {
733-
if (callable_name) {
734-
zend_string_release(callable_name);
735-
}
736732
if (EG(current_execute_data) == &dummy_execute_data) {
737733
EG(current_execute_data) = dummy_execute_data.prev_execute_data;
738734
}
739735
return FAILURE;
740736
}
741737
}
742-
zend_string_release(callable_name);
743738
}
744739

745740
func = fci_cache->function_handler;

ext/interbase/ibase_events.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ PHP_FUNCTION(ibase_set_event_handler)
264264
* link resource id (int) as arguments. The value returned from the function is
265265
* used to determine if the event handler should remain set.
266266
*/
267-
zend_string *cb_name;
268267
zval *args, *cb_arg;
269268
ibase_db_link *ib_link;
270269
ibase_event *event;
@@ -318,12 +317,12 @@ PHP_FUNCTION(ibase_set_event_handler)
318317
}
319318

320319
/* get the callback */
321-
if (!zend_is_callable(cb_arg, 0, &cb_name)) {
320+
if (!zend_is_callable(cb_arg, 0, NULL)) {
321+
zend_string *cb_name = zend_get_callable_name(cb_arg);
322322
_php_ibase_module_error("Callback argument %s is not a callable function", ZSTR_VAL(cb_name));
323323
zend_string_release(cb_name);
324324
RETURN_FALSE;
325325
}
326-
zend_string_release(cb_name);
327326

328327
/* allocate the event resource */
329328
event = (ibase_event *) safe_emalloc(sizeof(ibase_event), 1, 0);

ext/ldap/ldap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,6 @@ PHP_FUNCTION(ldap_set_rebind_proc)
27832783
{
27842784
zval *link, *callback;
27852785
ldap_linkdata *ld;
2786-
zend_string *callback_name;
27872786

27882787
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz", &link, &callback) != SUCCESS) {
27892788
RETURN_FALSE;
@@ -2804,12 +2803,12 @@ PHP_FUNCTION(ldap_set_rebind_proc)
28042803
}
28052804

28062805
/* callable? */
2807-
if (!zend_is_callable(callback, 0, &callback_name)) {
2806+
if (!zend_is_callable(callback, 0, NULL)) {
2807+
zend_string *callback_name = zend_get_callable_name(callback);
28082808
php_error_docref(NULL, E_WARNING, "Two arguments expected for '%s' to be a valid callback", ZSTR_VAL(callback_name));
28092809
zend_string_release(callback_name);
28102810
RETURN_FALSE;
28112811
}
2812-
zend_string_release(callback_name);
28132812

28142813
/* register rebind procedure */
28152814
if (Z_ISUNDEF(ld->rebindproc)) {

ext/oci8/oci8_interface.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,18 @@ PHP_FUNCTION(oci_register_taf_callback)
4949
zval *z_connection;
5050
php_oci_connection *connection;
5151
zval *callback;
52-
zend_string *callback_name;
5352

5453
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|z!", &z_connection, &callback) == FAILURE) {
5554
return;
5655
}
5756

5857
if (callback) {
59-
if (!zend_is_callable(callback, 0, &callback_name)) {
58+
if (!zend_is_callable(callback, 0, NULL)) {
59+
zend_string *callback_name = zend_get_callable_name(callback);
6060
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(callback_name));
6161
zend_string_release(callback_name);
6262
RETURN_FALSE;
6363
}
64-
65-
zend_string_release(callback_name);
6664
}
6765

6866
PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);

ext/pcntl/pcntl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,6 @@ PHP_FUNCTION(pcntl_exec)
990990
PHP_FUNCTION(pcntl_signal)
991991
{
992992
zval *handle;
993-
zend_string *func_name;
994993
zend_long signo;
995994
zend_bool restart_syscalls = 1;
996995

@@ -1031,13 +1030,13 @@ PHP_FUNCTION(pcntl_signal)
10311030
RETURN_TRUE;
10321031
}
10331032

1034-
if (!zend_is_callable(handle, 0, &func_name)) {
1033+
if (!zend_is_callable(handle, 0, NULL)) {
1034+
zend_string *func_name = zend_get_callable_name(handle);
10351035
PCNTL_G(last_error) = EINVAL;
10361036
php_error_docref(NULL, E_WARNING, "%s is not a callable function name error", ZSTR_VAL(func_name));
10371037
zend_string_release(func_name);
10381038
RETURN_FALSE;
10391039
}
1040-
zend_string_release(func_name);
10411040

10421041
/* Add the function name to our signal table */
10431042
if (zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle)) {

ext/pcre/php_pcre.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,6 @@ static PHP_FUNCTION(preg_replace_callback)
20372037
{
20382038
zval *regex, *replace, *subject, *zcount = NULL;
20392039
zend_long limit = -1;
2040-
zend_string *callback_name;
20412040
int replace_count;
20422041
zend_fcall_info fci;
20432042
zend_fcall_info_cache fcc;
@@ -2052,13 +2051,13 @@ static PHP_FUNCTION(preg_replace_callback)
20522051
Z_PARAM_ZVAL_DEREF(zcount)
20532052
ZEND_PARSE_PARAMETERS_END();
20542053

2055-
if (!zend_is_callable_ex(replace, NULL, 0, &callback_name, &fcc, NULL)) {
2054+
if (!zend_is_callable_ex(replace, NULL, 0, NULL, &fcc, NULL)) {
2055+
zend_string *callback_name = zend_get_callable_name(replace);
20562056
php_error_docref(NULL, E_WARNING, "Requires argument 2, '%s', to be a valid callback", ZSTR_VAL(callback_name));
20572057
zend_string_release(callback_name);
20582058
ZVAL_STR(return_value, zval_get_string(subject));
20592059
return;
20602060
}
2061-
zend_string_release(callback_name);
20622061

20632062
fci.size = sizeof(fci);
20642063
fci.object = NULL;
@@ -2079,7 +2078,6 @@ static PHP_FUNCTION(preg_replace_callback_array)
20792078
zval regex, zv, *replace, *subject, *pattern, *zcount = NULL;
20802079
zend_long limit = -1;
20812080
zend_string *str_idx;
2082-
zend_string *callback_name;
20832081
int replace_count = 0;
20842082
zend_fcall_info fci;
20852083
zend_fcall_info_cache fcc;
@@ -2105,15 +2103,15 @@ static PHP_FUNCTION(preg_replace_callback_array)
21052103
RETURN_NULL();
21062104
}
21072105

2108-
if (!zend_is_callable_ex(replace, NULL, 0, &callback_name, &fcc, NULL)) {
2106+
if (!zend_is_callable_ex(replace, NULL, 0, NULL, &fcc, NULL)) {
2107+
zend_string *callback_name = zend_get_callable_name(replace);
21092108
php_error_docref(NULL, E_WARNING, "'%s' is not a valid callback", ZSTR_VAL(callback_name));
21102109
zend_string_release(callback_name);
21112110
zval_ptr_dtor(&regex);
21122111
zval_ptr_dtor(return_value);
21132112
ZVAL_COPY(return_value, subject);
21142113
return;
21152114
}
2116-
zend_string_release(callback_name);
21172115

21182116
ZVAL_COPY_VALUE(&fci.function_name, replace);
21192117

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
515515
size_t func_name_len;
516516
zend_long argc = -1;
517517
zend_long flags = 0;
518-
zend_string *cbname = NULL;
519518
pdo_dbh_t *dbh;
520519
pdo_sqlite_db_handle *H;
521520
int ret;
@@ -531,12 +530,12 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
531530
dbh = Z_PDO_DBH_P(getThis());
532531
PDO_CONSTRUCT_CHECK;
533532

534-
if (!zend_is_callable(callback, 0, &cbname)) {
533+
if (!zend_is_callable(callback, 0, NULL)) {
534+
zend_string *cbname = zend_get_callable_name(callback);
535535
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(cbname));
536536
zend_string_release(cbname);
537537
RETURN_FALSE;
538538
}
539-
zend_string_release(cbname);
540539

541540
H = (pdo_sqlite_db_handle *)dbh->driver_data;
542541

@@ -588,7 +587,6 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
588587
char *func_name;
589588
size_t func_name_len;
590589
zend_long argc = -1;
591-
zend_string *cbname = NULL;
592590
pdo_dbh_t *dbh;
593591
pdo_sqlite_db_handle *H;
594592
int ret;
@@ -604,18 +602,19 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
604602
dbh = Z_PDO_DBH_P(getThis());
605603
PDO_CONSTRUCT_CHECK;
606604

607-
if (!zend_is_callable(step_callback, 0, &cbname)) {
605+
if (!zend_is_callable(step_callback, 0, NULL)) {
606+
zend_string *cbname = zend_get_callable_name(step_callback);
608607
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(cbname));
609608
zend_string_release(cbname);
610609
RETURN_FALSE;
611610
}
612-
zend_string_release(cbname);
613-
if (!zend_is_callable(fini_callback, 0, &cbname)) {
611+
612+
if (!zend_is_callable(fini_callback, 0, NULL)) {
613+
zend_string *cbname = zend_get_callable_name(fini_callback);
614614
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(cbname));
615615
zend_string_release(cbname);
616616
RETURN_FALSE;
617617
}
618-
zend_string_release(cbname);
619618

620619
H = (pdo_sqlite_db_handle *)dbh->driver_data;
621620

@@ -651,7 +650,6 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)
651650
zval *callback;
652651
char *collation_name;
653652
size_t collation_name_len;
654-
zend_string *cbname = NULL;
655653
pdo_dbh_t *dbh;
656654
pdo_sqlite_db_handle *H;
657655
int ret;
@@ -664,12 +662,12 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)
664662
dbh = Z_PDO_DBH_P(getThis());
665663
PDO_CONSTRUCT_CHECK;
666664

667-
if (!zend_is_callable(callback, 0, &cbname)) {
665+
if (!zend_is_callable(callback, 0, NULL)) {
666+
zend_string *cbname = zend_get_callable_name(callback);
668667
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(cbname));
669668
zend_string_release(cbname);
670669
RETURN_FALSE;
671670
}
672-
zend_string_release(cbname);
673671

674672
H = (pdo_sqlite_db_handle *)dbh->driver_data;
675673

ext/readline/readline.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ static char **_readline_completion_cb(const char *text, int start, int end)
507507
return NULL;
508508
}
509509
matches[0] = strdup("");
510-
matches[1] = '\0';
510+
matches[1] = NULL;
511511
}
512512
}
513513
}
@@ -522,19 +522,18 @@ static char **_readline_completion_cb(const char *text, int start, int end)
522522

523523
PHP_FUNCTION(readline_completion_function)
524524
{
525-
zval *arg = NULL;
526-
zend_string *name = NULL;
525+
zval *arg;
527526

528527
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg)) {
529528
RETURN_FALSE;
530529
}
531530

532-
if (!zend_is_callable(arg, 0, &name)) {
531+
if (!zend_is_callable(arg, 0, NULL)) {
532+
zend_string *name = zend_get_callable_name(arg);
533533
php_error_docref(NULL, E_WARNING, "%s is not callable", ZSTR_VAL(name));
534534
zend_string_release(name);
535535
RETURN_FALSE;
536536
}
537-
zend_string_release(name);
538537

539538
zval_ptr_dtor(&_readline_completion);
540539
ZVAL_COPY(&_readline_completion, arg);
@@ -570,20 +569,19 @@ static void php_rl_callback_handler(char *the_line)
570569
PHP_FUNCTION(readline_callback_handler_install)
571570
{
572571
zval *callback;
573-
zend_string *name = NULL;
574572
char *prompt;
575573
size_t prompt_len;
576574

577575
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &prompt, &prompt_len, &callback)) {
578576
return;
579577
}
580578

581-
if (!zend_is_callable(callback, 0, &name)) {
579+
if (!zend_is_callable(callback, 0, NULL)) {
580+
zend_string *name = zend_get_callable_name(callback);
582581
php_error_docref(NULL, E_WARNING, "%s is not callable", ZSTR_VAL(name));
583582
zend_string_release(name);
584583
RETURN_FALSE;
585584
}
586-
zend_string_release(name);
587585

588586
if (Z_TYPE(_prepped_callback) != IS_UNDEF) {
589587
rl_callback_handler_remove();

ext/session/session.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,6 @@ static PHP_FUNCTION(session_set_save_handler)
18301830
{
18311831
zval *args = NULL;
18321832
int i, num_args, argc = ZEND_NUM_ARGS();
1833-
zend_string *name;
18341833
zend_string *ini_name, *ini_val;
18351834

18361835
if (PS(session_status) == php_session_active) {
@@ -1960,12 +1959,12 @@ static PHP_FUNCTION(session_set_save_handler)
19601959

19611960
/* At this point argc can only be between 6 and PS_NUM_APIS */
19621961
for (i = 0; i < argc; i++) {
1963-
if (!zend_is_callable(&args[i], 0, &name)) {
1962+
if (!zend_is_callable(&args[i], 0, NULL)) {
1963+
zend_string *name = zend_get_callable_name(&args[i]);
19641964
php_error_docref(NULL, E_WARNING, "Argument %d is not a valid callback", i+1);
19651965
zend_string_release(name);
19661966
RETURN_FALSE;
19671967
}
1968-
zend_string_release(name);
19691968
}
19701969

19711970
if (PS(mod) && PS(mod) != &ps_mod_user) {

0 commit comments

Comments
 (0)