com php-src: Fixed bug (count on symbol tables): NEWS ext/standard/array.c

From: Date: Sun, 22 Nov 2015 04:58:29 +0000
Subject: com php-src: Fixed bug (count on symbol tables): NEWS ext/standard/array.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-89956@lists.php.net to get a copy of this message
Commit: eada2aa91add2de69bc5783b840a21243a7b0678 Author: Xinchen Hui <laruence@gmail.com> Sat, 21 Nov 2015 20:57:10 -0800 Parents: 31d93fcf4bb7efdbc6340692011a8b293eab07b8 Branches: PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eada2aa91add2de69bc5783b840a21243a7b0678 Log: Fixed bug (count on symbol tables) Changed paths: M NEWS M ext/standard/array.c Diff: diff --git a/NEWS b/NEWS index 4336257..b3b2d50 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,7 @@ PHP NEWS . Fixed bug #70940 (Segfault in soap / type_to_string). (Remi) - Standard: + . Fixed bug (count on symbol tables). (Laruence) . Fixed bug #70910 (extract() breaks variable references). (Laruence) - Streams/Socket diff --git a/ext/standard/array.c b/ext/standard/array.c index c1a716d..df9cc56 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -757,6 +757,41 @@ PHP_FUNCTION(ksort) } /* }}} */ +static uint32_t php_array_recalc_elements(HashTable *ht) /* {{{ */ +{ + zval *val; + uint32_t num = ht->nNumOfElements; + + ZEND_HASH_FOREACH_VAL(ht, val) { + if (Z_TYPE_P(val) == IS_UNDEF) continue; + if (Z_TYPE_P(val) == IS_INDIRECT) { + if (Z_TYPE_P(Z_INDIRECT_P(val)) == IS_UNDEF) { + num--; + } + } + } ZEND_HASH_FOREACH_END(); + return num; +} +/* }}} */ + +static uint32_t php_array_num_elements(zval *arr) /* {{{ */ +{ + uint32_t num; + HashTable *ht = Z_ARRVAL_P(arr); + if (UNEXPECTED(Z_SYMBOLTABLE_P(arr))) { + num = php_array_recalc_elements(ht); + } else if (UNEXPECTED(ht->u.v.flags & HASH_FLAG_HAS_EMPTY_IND)) { + num = php_array_recalc_elements(ht); + if (UNEXPECTED(ht->nNumOfElements == num)) { + ht->u.v.flags &= ~HASH_FLAG_HAS_EMPTY_IND; + } + } else { + num = zend_hash_num_elements(ht); + } + return num; +} +/* }}} */ + PHPAPI zend_long php_count_recursive(zval *array, zend_long mode) /* {{{ */ { zend_long cnt = 0; @@ -768,7 +803,7 @@ PHPAPI zend_long php_count_recursive(zval *array, zend_long mode) /* {{{ */ return 0; } - cnt = zend_hash_num_elements(Z_ARRVAL_P(array)); + cnt = php_array_num_elements(array); if (mode == COUNT_RECURSIVE) { if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(array))) { Z_ARRVAL_P(array)->u.v.nApplyCount++; @@ -813,7 +848,7 @@ PHP_FUNCTION(count) RETURN_LONG(0); break; case IS_ARRAY: - cnt = zend_hash_num_elements(Z_ARRVAL_P(array)); + cnt = php_array_num_elements(array); if (mode == COUNT_RECURSIVE) { ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), element) { ZVAL_DEREF(element);

« previous php.cvs (#89956) next »