Skip to content

Commit 973ae8d

Browse files
committed
Move the whole "cold" path into the "cold" function.
1 parent 3e164de commit 973ae8d

File tree

3 files changed

+26
-58
lines changed

3 files changed

+26
-58
lines changed

Zend/zend_execute.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_index(const
19991999
zend_error(E_WARNING, "Undefined array key \"%s\"", ZSTR_VAL(offset));
20002000
}
20012001

2002-
ZEND_API ZEND_COLD zend_result ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval)
2002+
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval)
20032003
{
20042004
/* The array may be destroyed while throwing the notice.
20052005
* Temporarily increase the refcount to detect this situation. */
@@ -2009,30 +2009,36 @@ ZEND_API ZEND_COLD zend_result ZEND_FASTCALL zend_undefined_offset_write(HashTab
20092009
zend_undefined_offset(lval);
20102010
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
20112011
zend_array_destroy(ht);
2012-
return FAILURE;
2012+
return NULL;
20132013
}
20142014
if (EG(exception)) {
2015-
return FAILURE;
2015+
return NULL;
20162016
}
2017-
return SUCCESS;
2017+
return zend_hash_index_add_new(ht, lval, &EG(uninitialized_zval));
20182018
}
20192019

2020-
ZEND_API ZEND_COLD zend_result ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset)
2020+
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset)
20212021
{
2022+
zval *retval;
2023+
20222024
/* The array may be destroyed while throwing the notice.
20232025
* Temporarily increase the refcount to detect this situation. */
20242026
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
20252027
GC_ADDREF(ht);
20262028
}
2029+
/* Key may be released while throwing the undefined index warning. */
2030+
zend_string_addref(offset);
20272031
zend_undefined_index(offset);
20282032
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
20292033
zend_array_destroy(ht);
2030-
return FAILURE;
2031-
}
2032-
if (EG(exception)) {
2033-
return FAILURE;
2034+
retval = NULL;
2035+
} else if (EG(exception)) {
2036+
retval = NULL;
2037+
} else {
2038+
retval = zend_hash_add_new(ht, offset, &EG(uninitialized_zval));
20342039
}
2035-
return SUCCESS;
2040+
zend_string_release(offset);
2041+
return retval;
20362042
}
20372043

20382044
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_undefined_method(const zend_class_entry *ce, const zend_string *method)
@@ -2167,10 +2173,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
21672173
retval = &EG(uninitialized_zval);
21682174
break;
21692175
case BP_VAR_RW:
2170-
if (UNEXPECTED(zend_undefined_offset_write(ht, hval) == FAILURE)) {
2171-
return NULL;
2172-
}
2173-
retval = zend_hash_index_add_new(ht, hval, &EG(uninitialized_zval));
2176+
retval = zend_undefined_offset_write(ht, hval);
21742177
break;
21752178
}
21762179
} else {
@@ -2196,14 +2199,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
21962199
retval = &EG(uninitialized_zval);
21972200
break;
21982201
case BP_VAR_RW:
2199-
/* Key may be released while throwing the undefined index warning. */
2200-
zend_string_addref(offset_key);
2201-
if (UNEXPECTED(zend_undefined_index_write(ht, offset_key) == FAILURE)) {
2202-
zend_string_release(offset_key);
2203-
return NULL;
2204-
}
2205-
retval = zend_hash_add_new(ht, offset_key, &EG(uninitialized_zval));
2206-
zend_string_release(offset_key);
2202+
retval = zend_undefined_index_write(ht, offset_key);
22072203
break;
22082204
}
22092205
}

Zend/zend_execute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(zend_property_inf
6565

6666
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(zend_property_info *prop, zval *zv);
6767
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(zend_property_info *prop1, zend_property_info *prop2, zval *zv);
68-
ZEND_API ZEND_COLD zend_result ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval);
69-
ZEND_API ZEND_COLD zend_result ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset);
68+
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval);
69+
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset);
7070

7171
ZEND_API bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, bool strict, bool is_internal_arg);
7272
ZEND_API ZEND_COLD void zend_verify_arg_error(

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,7 @@ static zval* ZEND_FASTCALL zend_jit_hash_index_lookup_rw(HashTable *ht, zend_lon
255255
zval *retval = _zend_hash_index_find(ht, idx);
256256

257257
if (!retval) {
258-
if (UNEXPECTED(zend_undefined_offset_write(ht, idx) == FAILURE)) {
259-
return NULL;
260-
}
261-
retval = zend_hash_index_add_new(ht, idx, &EG(uninitialized_zval));
258+
retval = zend_undefined_offset_write(ht, idx);
262259
}
263260
return retval;
264261
}
@@ -268,13 +265,7 @@ static zval* ZEND_FASTCALL zend_jit_hash_lookup_rw(HashTable *ht, zend_string *s
268265
zval *retval = zend_hash_find_ex(ht, str, 1);
269266
if (!retval) {
270267
/* Key may be released while throwing the undefined index warning. */
271-
zend_string_addref(str);
272-
if (UNEXPECTED(zend_undefined_index_write(ht, str) == FAILURE)) {
273-
zend_string_release(str);
274-
return NULL;
275-
}
276-
retval = zend_hash_add_new(ht, str, &EG(uninitialized_zval));
277-
zend_string_release(str);
268+
retval = zend_undefined_index_write(ht, str);
278269
}
279270
return retval;
280271
}
@@ -300,10 +291,7 @@ static zval* ZEND_FASTCALL zend_jit_symtable_lookup_rw(HashTable *ht, zend_strin
300291
if (_zend_handle_numeric_str_ex(str->val, str->len, &idx)) {
301292
retval = zend_hash_index_find(ht, idx);
302293
if (!retval) {
303-
if (UNEXPECTED(zend_undefined_index_write(ht, str) == FAILURE)) {
304-
return NULL;
305-
}
306-
retval = zend_hash_index_add_new(ht, idx, &EG(uninitialized_zval));
294+
retval = zend_undefined_index_write(ht, str);
307295
}
308296
return retval;
309297
}
@@ -312,13 +300,7 @@ static zval* ZEND_FASTCALL zend_jit_symtable_lookup_rw(HashTable *ht, zend_strin
312300
retval = zend_hash_find(ht, str);
313301
if (!retval) {
314302
/* Key may be released while throwing the undefined index warning. */
315-
zend_string_addref(str);
316-
if (UNEXPECTED(zend_undefined_index_write(ht, str) == FAILURE)) {
317-
zend_string_release(str);
318-
return NULL;
319-
}
320-
retval = zend_hash_add_new(ht, str, &EG(uninitialized_zval));
321-
zend_string_release(str);
303+
retval = zend_undefined_index_write(ht, str);
322304
}
323305
return retval;
324306
}
@@ -619,13 +601,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
619601
retval = zend_hash_find(ht, offset_key);
620602
if (!retval) {
621603
/* Key may be released while throwing the undefined index warning. */
622-
zend_string_addref(offset_key);
623-
if (UNEXPECTED(zend_undefined_index_write(ht, offset_key) == FAILURE)) {
624-
zend_string_release(offset_key);
625-
return NULL;
626-
}
627-
retval = zend_hash_add_new(ht, offset_key, &EG(uninitialized_zval));
628-
zend_string_release(offset_key);
604+
retval = zend_undefined_index_write(ht, offset_key);
629605
}
630606
return retval;
631607

@@ -634,11 +610,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
634610
return retval;
635611

636612
num_undef:
637-
if (UNEXPECTED(zend_undefined_offset_write(ht, hval) == FAILURE)) {
638-
return NULL;
639-
}
640-
retval = zend_hash_index_add_new(ht, hval, &EG(uninitialized_zval));
641-
return retval;
613+
return zend_undefined_offset_write(ht, hval);
642614
}
643615

644616
static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim)

0 commit comments

Comments
 (0)