Skip to content

Commit fd89943

Browse files
committed
Zend: Exception::__toString() no need to allocate the method name
1 parent f61ae00 commit fd89943

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

Zend/zend_exceptions.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -695,32 +695,23 @@ ZEND_METHOD(Exception, __toString)
695695
zval trace, *exception;
696696
zend_class_entry *base_ce;
697697
zend_string *str;
698-
zend_fcall_info fci;
699698
zval rv, tmp;
700-
zend_string *fname;
701699

702700
ZEND_PARSE_PARAMETERS_NONE();
703701

704702
str = ZSTR_EMPTY_ALLOC();
705703

706704
exception = ZEND_THIS;
707-
fname = ZSTR_INIT_LITERAL("gettraceasstring", 0);
708705

709706
while (exception && Z_TYPE_P(exception) == IS_OBJECT && instanceof_function(Z_OBJCE_P(exception), zend_ce_throwable)) {
710707
zend_string *prev_str = str;
711708
zend_string *message = zval_get_string(GET_PROPERTY(exception, ZEND_STR_MESSAGE));
712709
zend_string *file = zval_get_string(GET_PROPERTY(exception, ZEND_STR_FILE));
713710
zend_long line = zval_get_long(GET_PROPERTY(exception, ZEND_STR_LINE));
711+
zend_function *getTraceAsString = zend_hash_str_find_ptr(&Z_OBJCE_P(exception)->function_table, ZEND_STRS("gettraceasstring"));
714712

715-
fci.size = sizeof(fci);
716-
ZVAL_STR(&fci.function_name, fname);
717-
fci.object = Z_OBJ_P(exception);
718-
fci.retval = &trace;
719-
fci.param_count = 0;
720-
fci.params = NULL;
721-
fci.named_params = NULL;
722-
723-
zend_call_function(&fci, NULL);
713+
ZEND_ASSERT(getTraceAsString && "Method getTraceAsString must exist");
714+
zend_call_known_function(getTraceAsString, Z_OBJ_P(exception), Z_OBJCE_P(exception), &trace, 0, NULL, NULL);
724715

725716
if (Z_TYPE(trace) != IS_STRING) {
726717
zval_ptr_dtor(&trace);
@@ -765,7 +756,6 @@ ZEND_METHOD(Exception, __toString)
765756
break;
766757
}
767758
}
768-
zend_string_release_ex(fname, 0);
769759

770760
exception = ZEND_THIS;
771761
/* Reset apply counts */

0 commit comments

Comments
 (0)