From: Xinchen Hui Date: Sat, 17 Feb 2018 08:39:31 +0000 (+0800) Subject: Merge branch 'PHP-7.2' X-Git-Tag: php-7.3.0alpha1~392 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55ef99e3b8fdeea0ad83cc650ff61797187ecb3d;p=php Merge branch 'PHP-7.2' * PHP-7.2: Update NEWS Fixed bug #75961 (Strange references behavior) Conflicts: ext/standard/array.c --- 55ef99e3b8fdeea0ad83cc650ff61797187ecb3d diff --cc ext/standard/array.c index 50ea6802ae,72a7813aa8..fd682d0727 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@@ -1419,14 -1428,16 +1422,16 @@@ static int php_array_walk(zval *array, HashTable *thash; zend_fcall_info orig_array_walk_fci; zend_fcall_info_cache orig_array_walk_fci_cache; - zval ref; - ZVAL_COPY_VALUE(&ref, zv); + zval rv; - ZVAL_DEREF(zv); - SEPARATE_ARRAY(zv); - thash = Z_ARRVAL_P(zv); + SEPARATE_ARRAY(Z_REFVAL_P(zv)); + ZVAL_COPY_VALUE(&rv, Z_REFVAL_P(zv)); + thash = Z_ARRVAL(rv); - if (thash->u.v.nApplyCount > 1) { + if (GC_IS_RECURSIVE(thash)) { php_error_docref(NULL, E_WARNING, "recursion detected"); + if (!was_ref) { + ZVAL_UNREF(zv); + } result = FAILURE; break; } @@@ -1435,15 -1446,15 +1440,15 @@@ orig_array_walk_fci = BG(array_walk_fci); orig_array_walk_fci_cache = BG(array_walk_fci_cache); - Z_ADDREF(ref); + Z_ADDREF(rv); - thash->u.v.nApplyCount++; + GC_PROTECT_RECURSION(thash); - result = php_array_walk(zv, userdata, recursive); - if (Z_TYPE_P(Z_REFVAL(ref)) == IS_ARRAY && thash == Z_ARRVAL_P(Z_REFVAL(ref))) { + result = php_array_walk(&rv, userdata, recursive); + if (Z_TYPE_P(Z_REFVAL_P(zv)) == IS_ARRAY && thash == Z_ARRVAL_P(Z_REFVAL_P(zv))) { /* If the hashtable changed in the meantime, we'll "leak" this apply count * increment -- our reference to thash is no longer valid. */ - thash->u.v.nApplyCount--; + GC_UNPROTECT_RECURSION(thash); } - zval_ptr_dtor(&ref); + zval_ptr_dtor(&rv); /* restore the fcall info and cache */ BG(array_walk_fci) = orig_array_walk_fci;