Skip to content

Commit 6fadb72

Browse files
committed
Move exceptional code into "cold" helpers
1 parent 27908ba commit 6fadb72

File tree

3 files changed

+497
-659
lines changed

3 files changed

+497
-659
lines changed

Zend/zend_execute.c

Lines changed: 126 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ static zend_always_inline void zend_verify_return_type(zend_function *zf, zval *
10241024
}
10251025
}
10261026

1027-
static ZEND_COLD int zend_verify_missing_return_type(zend_function *zf, void **cache_slot)
1027+
static ZEND_COLD int zend_verify_missing_return_type(const zend_function *zf, void **cache_slot)
10281028
{
10291029
zend_arg_info *ret_info = zf->common.arg_info - 1;
10301030

@@ -1046,10 +1046,20 @@ static ZEND_COLD int zend_verify_missing_return_type(zend_function *zf, void **c
10461046
return 1;
10471047
}
10481048

1049+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_object_as_array(void)
1050+
{
1051+
zend_throw_error(NULL, "Cannot use object as array");
1052+
}
1053+
1054+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_illegal_offset(void)
1055+
{
1056+
zend_error(E_WARNING, "Illegal offset type");
1057+
}
1058+
10491059
static zend_never_inline void zend_assign_to_object_dim(zval *object, zval *dim, zval *value)
10501060
{
10511061
if (UNEXPECTED(!Z_OBJ_HT_P(object)->write_dimension)) {
1052-
zend_throw_error(NULL, "Cannot use object as array");
1062+
zend_use_object_as_array();
10531063
return;
10541064
}
10551065

@@ -1117,7 +1127,7 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type
11171127
dim = Z_REFVAL_P(dim);
11181128
goto try_again;
11191129
default:
1120-
zend_error(E_WARNING, "Illegal offset type");
1130+
zend_illegal_offset();
11211131
break;
11221132
}
11231133

@@ -1291,6 +1301,14 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_check(
12911301
zend_tmp_string_release(property_name);
12921302
}
12931303

1304+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc)
1305+
{
1306+
zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
1307+
fbc->common.scope ? ZSTR_VAL(fbc->common.scope->name) : "",
1308+
fbc->common.scope ? "::" : "",
1309+
ZSTR_VAL(fbc->common.function_name));
1310+
}
1311+
12941312
static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zval *value, zval *result EXECUTE_DATA_DC)
12951313
{
12961314
zend_uchar c;
@@ -1532,6 +1550,87 @@ static zend_always_inline HashTable *zend_get_target_symbol_table(int fetch_type
15321550
return ht;
15331551
}
15341552

1553+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_offset(zend_long lval)
1554+
{
1555+
zend_error(E_NOTICE, "Undefined offset: " ZEND_LONG_FMT, lval);
1556+
}
1557+
1558+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_index(const zend_string *offset)
1559+
{
1560+
zend_error(E_NOTICE, "Undefined index: %s", ZSTR_VAL(offset));
1561+
}
1562+
1563+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_method(const zend_class_entry *ce, const zend_string *method)
1564+
{
1565+
zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(ce->name), ZSTR_VAL(method));
1566+
}
1567+
1568+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_invalid_method_call(zval *object, zval *function_name)
1569+
{
1570+
zend_throw_error(NULL, "Call to a member function %s() on %s", Z_STRVAL_P(function_name), zend_get_type_by_const(Z_TYPE_P(object)));
1571+
}
1572+
1573+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_non_static_method_call(const zend_function *fbc)
1574+
{
1575+
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
1576+
zend_error(E_DEPRECATED,
1577+
"Non-static method %s::%s() should not be called statically",
1578+
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
1579+
} else {
1580+
zend_throw_error(
1581+
zend_ce_error,
1582+
"Non-static method %s::%s() cannot be called statically",
1583+
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
1584+
}
1585+
}
1586+
1587+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num)
1588+
{
1589+
zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
1590+
arg_num,
1591+
func->common.scope ? ZSTR_VAL(func->common.scope->name) : "",
1592+
func->common.scope ? "::" : "",
1593+
ZSTR_VAL(func->common.function_name));
1594+
}
1595+
1596+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_scalar_as_array(void)
1597+
{
1598+
zend_error(E_WARNING, "Cannot use a scalar value as an array");
1599+
}
1600+
1601+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void)
1602+
{
1603+
zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
1604+
}
1605+
1606+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
1607+
{
1608+
zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
1609+
}
1610+
1611+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_new_element_for_string(void)
1612+
{
1613+
zend_throw_error(NULL, "[] operator not supported for strings");
1614+
}
1615+
1616+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_modify_property_of_non_object(zval *property)
1617+
{
1618+
zend_string *tmp;
1619+
zend_string *property_name = zval_get_tmp_string(property, &tmp);
1620+
zend_error(E_WARNING, "Attempt to modify property '%s' of non-object", ZSTR_VAL(property_name));
1621+
zend_tmp_string_release(tmp);
1622+
}
1623+
1624+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_access_undefined_propery_in_overloaded_object(void)
1625+
{
1626+
zend_throw_error(NULL, "Cannot access undefined property for object with overloaded property access");
1627+
}
1628+
1629+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_unsupported_property_reference(void)
1630+
{
1631+
zend_error(E_WARNING, "This object doesn't support property references");
1632+
}
1633+
15351634
static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht, const zval *dim, int dim_type, int type EXECUTE_DATA_DC)
15361635
{
15371636
zval *retval;
@@ -1547,14 +1646,14 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
15471646
num_undef:
15481647
switch (type) {
15491648
case BP_VAR_R:
1550-
zend_error(E_NOTICE,"Undefined offset: " ZEND_LONG_FMT, hval);
1649+
zend_undefined_offset(hval);
15511650
/* break missing intentionally */
15521651
case BP_VAR_UNSET:
15531652
case BP_VAR_IS:
15541653
retval = &EG(uninitialized_zval);
15551654
break;
15561655
case BP_VAR_RW:
1557-
zend_error(E_NOTICE,"Undefined offset: " ZEND_LONG_FMT, hval);
1656+
zend_undefined_offset(hval);
15581657
retval = zend_hash_index_update(ht, hval, &EG(uninitialized_zval));
15591658
break;
15601659
case BP_VAR_W:
@@ -1577,14 +1676,14 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
15771676
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
15781677
switch (type) {
15791678
case BP_VAR_R:
1580-
zend_error(E_NOTICE, "Undefined index: %s", ZSTR_VAL(offset_key));
1679+
zend_undefined_index(offset_key);
15811680
/* break missing intentionally */
15821681
case BP_VAR_UNSET:
15831682
case BP_VAR_IS:
15841683
retval = &EG(uninitialized_zval);
15851684
break;
15861685
case BP_VAR_RW:
1587-
zend_error(E_NOTICE,"Undefined index: %s", ZSTR_VAL(offset_key));
1686+
zend_undefined_index(offset_key);
15881687
/* break missing intentionally */
15891688
case BP_VAR_W:
15901689
ZVAL_NULL(retval);
@@ -1595,14 +1694,14 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
15951694
} else {
15961695
switch (type) {
15971696
case BP_VAR_R:
1598-
zend_error(E_NOTICE, "Undefined index: %s", ZSTR_VAL(offset_key));
1697+
zend_undefined_index(offset_key);
15991698
/* break missing intentionally */
16001699
case BP_VAR_UNSET:
16011700
case BP_VAR_IS:
16021701
retval = &EG(uninitialized_zval);
16031702
break;
16041703
case BP_VAR_RW:
1605-
zend_error(E_NOTICE,"Undefined index: %s", ZSTR_VAL(offset_key));
1704+
zend_undefined_index(offset_key);
16061705
retval = zend_hash_update(ht, offset_key, &EG(uninitialized_zval));
16071706
break;
16081707
case BP_VAR_W:
@@ -1622,7 +1721,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
16221721
hval = zend_dval_to_lval(Z_DVAL_P(dim));
16231722
goto num_index;
16241723
case IS_RESOURCE:
1625-
zend_error(E_NOTICE, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
1724+
zend_use_resource_as_offset(dim);
16261725
hval = Z_RES_HANDLE_P(dim);
16271726
goto num_index;
16281727
case IS_FALSE:
@@ -1635,7 +1734,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
16351734
dim = Z_REFVAL_P(dim);
16361735
goto try_again;
16371736
default:
1638-
zend_error(E_WARNING, "Illegal offset type");
1737+
zend_illegal_offset();
16391738
retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
16401739
NULL : &EG(uninitialized_zval);
16411740
}
@@ -1674,7 +1773,7 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
16741773
if (dim == NULL) {
16751774
retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval));
16761775
if (UNEXPECTED(retval == NULL)) {
1677-
zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
1776+
zend_cannot_add_element();
16781777
ZVAL_ERROR(result);
16791778
return;
16801779
}
@@ -1695,7 +1794,7 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
16951794
}
16961795
if (UNEXPECTED(Z_TYPE_P(container) == IS_STRING)) {
16971796
if (dim == NULL) {
1698-
zend_throw_error(NULL, "[] operator not supported for strings");
1797+
zend_use_new_element_for_string();
16991798
} else {
17001799
zend_check_string_offset(dim, type EXECUTE_DATA_CC);
17011800
zend_wrong_string_offset(EXECUTE_DATA_C);
@@ -1707,7 +1806,7 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
17071806
dim = &EG(uninitialized_zval);
17081807
}
17091808
if (!Z_OBJ_HT_P(container)->read_dimension) {
1710-
zend_throw_error(NULL, "Cannot use object as array");
1809+
zend_use_object_as_array();
17111810
ZVAL_ERROR(result);
17121811
} else {
17131812
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);
@@ -1759,7 +1858,7 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
17591858
zend_error(E_WARNING, "Cannot unset offset in a non-array variable");
17601859
ZVAL_NULL(result);
17611860
} else {
1762-
zend_error(E_WARNING, "Cannot use a scalar value as an array");
1861+
zend_use_scalar_as_array();
17631862
ZVAL_ERROR(result);
17641863
}
17651864
}
@@ -1829,7 +1928,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
18291928
dim = Z_REFVAL_P(dim);
18301929
goto try_string_offset;
18311930
default:
1832-
zend_error(E_WARNING, "Illegal offset type");
1931+
zend_illegal_offset();
18331932
break;
18341933
}
18351934

@@ -1861,7 +1960,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
18611960
dim = &EG(uninitialized_zval);
18621961
}
18631962
if (!Z_OBJ_HT_P(container)->read_dimension) {
1864-
zend_throw_error(NULL, "Cannot use object as array");
1963+
zend_use_object_as_array();
18651964
ZVAL_NULL(result);
18661965
} else {
18671966
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);
@@ -1939,9 +2038,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
19392038
object_init(container);
19402039
} else {
19412040
if (container_op_type != IS_VAR || EXPECTED(!Z_ISERROR_P(container))) {
1942-
zend_string *property_name = zval_get_string(prop_ptr);
1943-
zend_error(E_WARNING, "Attempt to modify property '%s' of non-object", ZSTR_VAL(property_name));
1944-
zend_string_release(property_name);
2041+
zend_modify_property_of_non_object(prop_ptr);
19452042
}
19462043
ZVAL_ERROR(result);
19472044
return;
@@ -1986,7 +2083,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
19862083
ZVAL_UNREF(ptr);
19872084
}
19882085
} else {
1989-
zend_throw_error(NULL, "Cannot access undefined property for object with overloaded property access");
2086+
zend_access_undefined_propery_in_overloaded_object();
19902087
ZVAL_ERROR(result);
19912088
}
19922089
} else {
@@ -1995,7 +2092,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
19952092
} else if (EXPECTED(Z_OBJ_HT_P(container)->read_property)) {
19962093
goto use_read_property;
19972094
} else {
1998-
zend_error(E_WARNING, "This object doesn't support property references");
2095+
zend_unsupported_property_reference();
19992096
ZVAL_ERROR(result);
20002097
}
20012098
}
@@ -2581,7 +2678,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
25812678
}
25822679
if (UNEXPECTED(fbc == NULL)) {
25832680
if (EXPECTED(!EG(exception))) {
2584-
zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(called_scope->name), ZSTR_VAL(mname));
2681+
zend_undefined_method(called_scope, mname);
25852682
}
25862683
zend_string_release(lcname);
25872684
zend_string_release(mname);
@@ -2592,18 +2689,8 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_string(zend_s
25922689
zend_string_release(mname);
25932690

25942691
if (UNEXPECTED(!(fbc->common.fn_flags & ZEND_ACC_STATIC))) {
2595-
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
2596-
zend_error(E_DEPRECATED,
2597-
"Non-static method %s::%s() should not be called statically",
2598-
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
2599-
if (UNEXPECTED(EG(exception) != NULL)) {
2600-
return NULL;
2601-
}
2602-
} else {
2603-
zend_throw_error(
2604-
zend_ce_error,
2605-
"Non-static method %s::%s() cannot be called statically",
2606-
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
2692+
zend_non_static_method_call(fbc);
2693+
if (UNEXPECTED(EG(exception) != NULL)) {
26072694
return NULL;
26082695
}
26092696
}
@@ -2713,23 +2800,13 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
27132800
}
27142801
if (UNEXPECTED(fbc == NULL)) {
27152802
if (EXPECTED(!EG(exception))) {
2716-
zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(called_scope->name), Z_STRVAL_P(method));
2803+
zend_undefined_method(called_scope, Z_STR_P(method));
27172804
}
27182805
return NULL;
27192806
}
27202807
if (!(fbc->common.fn_flags & ZEND_ACC_STATIC)) {
2721-
if (fbc->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
2722-
zend_error(E_DEPRECATED,
2723-
"Non-static method %s::%s() should not be called statically",
2724-
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
2725-
if (UNEXPECTED(EG(exception) != NULL)) {
2726-
return NULL;
2727-
}
2728-
} else {
2729-
zend_throw_error(
2730-
zend_ce_error,
2731-
"Non-static method %s::%s() cannot be called statically",
2732-
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
2808+
zend_non_static_method_call(fbc);
2809+
if (UNEXPECTED(EG(exception) != NULL)) {
27332810
return NULL;
27342811
}
27352812
}
@@ -2740,7 +2817,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
27402817
fbc = Z_OBJ_HT_P(obj)->get_method(&object, Z_STR_P(method), NULL);
27412818
if (UNEXPECTED(fbc == NULL)) {
27422819
if (EXPECTED(!EG(exception))) {
2743-
zend_throw_error(NULL, "Call to undefined method %s::%s()", ZSTR_VAL(object->ce->name), Z_STRVAL_P(method));
2820+
zend_undefined_method(object->ce, Z_STR_P(method));
27442821
}
27452822
return NULL;
27462823
}

0 commit comments

Comments
 (0)