Re: com php-src: Fixed bug (count on symbol tables): NEWS ext/standard/array.c
| From: | Xinchen Hui | Date: | Sun, 22 Nov 2015 14:57:24 +0000 |
| Subject: | Re: com php-src: Fixed bug (count on symbol tables): NEWS ext/standard/array.c | ||
| References: | 1 2 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-89959@lists.php.net to get a copy of this message | ||
Hey:
On Sun, Nov 22, 2015 at 5:20 PM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Sun, Nov 22, 2015 at 5:58 AM, Xinchen Hui <laruence@php.net> wrote:
>
>> Commit: eada2aa91add2de69bc5783b840a21243a7b0678
>> Author: Xinchen Hui <laruence@gmail.com> Sat, 21 Nov 2015
>> 20:57:10 -0800
>> Parents: 31d93fcf4bb7efdbc6340692011a8b293eab07b8
>> Branches: PHP-7.0 master
>>
>> Link:
>> X®½¥
>> rø�<~n›;·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;
>> +}
>> +/* }}} */
>>
>
> This code is now duplicated between array.c and var.c. Can we move this
> into a common zend_hash function?
>
yeah, I knew.
I was plan to make the function in array.c as PHPAPI, but I also prefer
move this into zend_hash, so I decide to discuss with Dmitry on Monday
before I do it.
thanks
>
>
> Nikita
>
--
Xinchen Hui
@Laruence
http://www.laruence.com/