Skip to content

Commit 777187c

Browse files
committed
Don't use UNREFs during array operations
Perform DEREFs instead. We were already doing this in some, but not all places. While UNREFs are supposed to be transparent, in practice they have rare observable side effects. Calling array_merge() on an array should never change how that array behaves.
1 parent 9cd2d77 commit 777187c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

ext/standard/array.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,7 +3612,7 @@ PHP_FUNCTION(array_slice)
36123612
}
36133613
if (UNEXPECTED(Z_ISREF_P(entry)) &&
36143614
UNEXPECTED(Z_REFCOUNT_P(entry) == 1)) {
3615-
ZVAL_UNREF(entry);
3615+
entry = Z_REFVAL_P(entry);
36163616
}
36173617
Z_TRY_ADDREF_P(entry);
36183618
ZEND_HASH_FILL_ADD(entry);
@@ -3725,7 +3725,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */
37253725
ZEND_HASH_FOREACH_VAL(src, src_entry) {
37263726
if (UNEXPECTED(Z_ISREF_P(src_entry)) &&
37273727
UNEXPECTED(Z_REFCOUNT_P(src_entry) == 1)) {
3728-
ZVAL_UNREF(src_entry);
3728+
src_entry = Z_REFVAL_P(src_entry);
37293729
}
37303730
Z_TRY_ADDREF_P(src_entry);
37313731
ZEND_HASH_FILL_ADD(src_entry);
@@ -3735,7 +3735,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */
37353735
ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) {
37363736
if (UNEXPECTED(Z_ISREF_P(src_entry) &&
37373737
Z_REFCOUNT_P(src_entry) == 1)) {
3738-
ZVAL_UNREF(src_entry);
3738+
src_entry = Z_REFVAL_P(src_entry);
37393739
}
37403740
Z_TRY_ADDREF_P(src_entry);
37413741
if (string_key) {
@@ -3883,7 +3883,7 @@ static inline void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETE
38833883
ZEND_HASH_FOREACH_VAL(src, src_entry) {
38843884
if (UNEXPECTED(Z_ISREF_P(src_entry) &&
38853885
Z_REFCOUNT_P(src_entry) == 1)) {
3886-
ZVAL_UNREF(src_entry);
3886+
src_entry = Z_REFVAL_P(src_entry);
38873887
}
38883888
Z_TRY_ADDREF_P(src_entry);
38893889
ZEND_HASH_FILL_ADD(src_entry);
@@ -3895,7 +3895,7 @@ static inline void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETE
38953895
ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) {
38963896
if (UNEXPECTED(Z_ISREF_P(src_entry) &&
38973897
Z_REFCOUNT_P(src_entry) == 1)) {
3898-
ZVAL_UNREF(src_entry);
3898+
src_entry = Z_REFVAL_P(src_entry);
38993899
}
39003900
Z_TRY_ADDREF_P(src_entry);
39013901
if (EXPECTED(string_key)) {
@@ -4285,7 +4285,7 @@ PHP_FUNCTION(array_reverse)
42854285
ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL_P(input), entry) {
42864286
if (UNEXPECTED(Z_ISREF_P(entry) &&
42874287
Z_REFCOUNT_P(entry) == 1)) {
4288-
ZVAL_UNREF(entry);
4288+
entry = Z_REFVAL_P(entry);
42894289
}
42904290
Z_TRY_ADDREF_P(entry);
42914291
ZEND_HASH_FILL_ADD(entry);
@@ -4679,7 +4679,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
46794679
if (Z_TYPE_P(val) == IS_UNDEF) continue;
46804680
}
46814681
if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) {
4682-
ZVAL_UNREF(val);
4682+
val = Z_REFVAL_P(val);
46834683
}
46844684
if (p->key == NULL) {
46854685
ok = 1;
@@ -5090,7 +5090,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
50905090
if (Z_TYPE_P(val) == IS_UNDEF) continue;
50915091
}
50925092
if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) {
5093-
ZVAL_UNREF(val);
5093+
val = Z_REFVAL_P(val);
50945094
}
50955095
if (p->key == NULL) {
50965096
ok = 1;

0 commit comments

Comments
 (0)