diff options
author | Xinchen Hui <laruence@php.net> | 2014-07-30 10:47:03 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@php.net> | 2014-07-30 10:47:03 +0800 |
commit | 2147799524b16a088c72d23221a8d808d0aff45c (patch) | |
tree | 96d1200eef14cc81f88636d953c6bee9a8c7a15e /ext/standard/array.c | |
parent | a0a4eb23ee9631e52bd604540a55ba8e66825488 (diff) | |
parent | 70fb0e751913a408e7906adba8bcaff08da44e9e (diff) | |
download | php-git-2147799524b16a088c72d23221a8d808d0aff45c.tar.gz |
Merge branch 'phpng' of https://git.php.net/repository/php-src into phpng
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r-- | ext/standard/array.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index 0e01b2ec68..731c374582 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -607,6 +607,7 @@ static int php_array_user_compare(const void *a, const void *b TSRMLS_DC) /* {{{ PHP_FUNCTION(usort) { zval *array; + zend_refcounted *arr; unsigned int refcount; PHP_ARRAY_CMP_FUNC_VARS; @@ -617,30 +618,31 @@ PHP_FUNCTION(usort) return; } - /* Clear the is_ref flag, so the attemts to modify the array in user + /* Increase reference counter, so the attemts to modify the array in user * comparison function will create a copy of array and won't affect the * original array. The fact of modification is detected using refcount * comparison. The result of sorting in such case is undefined and the * function returns FALSE. */ -//??? Z_UNSET_ISREF_P(array); + Z_ADDREF_P(array); refcount = Z_REFCOUNT_P(array); + arr = Z_COUNTED_P(array); if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 1 TSRMLS_CC) == FAILURE) { RETVAL_FALSE; } else { if (refcount > Z_REFCOUNT_P(array)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array was modified by the user comparison function"); + if (--GC_REFCOUNT(arr) <= 0) { + _zval_dtor_func(arr ZEND_FILE_LINE_CC); + } RETVAL_FALSE; } else { + Z_DELREF_P(array); RETVAL_TRUE; } } - if (Z_REFCOUNT_P(array) > 1) { -//??? Z_SET_ISREF_P(array); - } - PHP_ARRAY_CMP_FUNC_RESTORE(); } /* }}} */ @@ -650,6 +652,7 @@ PHP_FUNCTION(usort) PHP_FUNCTION(uasort) { zval *array; + zend_refcounted *arr; unsigned int refcount; PHP_ARRAY_CMP_FUNC_VARS; @@ -660,30 +663,31 @@ PHP_FUNCTION(uasort) return; } - /* Clear the is_ref flag, so the attemts to modify the array in user - * comaprison function will create a copy of array and won't affect the + /* Increase reference counter, so the attemts to modify the array in user + * comparison function will create a copy of array and won't affect the * original array. The fact of modification is detected using refcount * comparison. The result of sorting in such case is undefined and the * function returns FALSE. */ -//??? Z_UNSET_ISREF_P(array); + Z_ADDREF_P(array); refcount = Z_REFCOUNT_P(array); + arr = Z_COUNTED_P(array); if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 0 TSRMLS_CC) == FAILURE) { RETVAL_FALSE; } else { if (refcount > Z_REFCOUNT_P(array)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array was modified by the user comparison function"); + if (--GC_REFCOUNT(arr) <= 0) { + _zval_dtor_func(arr ZEND_FILE_LINE_CC); + } RETVAL_FALSE; } else { + Z_DELREF_P(array); RETVAL_TRUE; } } - if (Z_REFCOUNT_P(array) > 1) { -//??? Z_SET_ISREF_P(array); - } - PHP_ARRAY_CMP_FUNC_RESTORE(); } /* }}} */ @@ -736,6 +740,7 @@ static int php_array_user_key_compare(const void *a, const void *b TSRMLS_DC) /* PHP_FUNCTION(uksort) { zval *array; + zend_refcounted *arr; unsigned int refcount; PHP_ARRAY_CMP_FUNC_VARS; @@ -746,30 +751,31 @@ PHP_FUNCTION(uksort) return; } - /* Clear the is_ref flag, so the attemts to modify the array in user - * comaprison function will create a copy of array and won't affect the + /* Increase reference counter, so the attemts to modify the array in user + * comparison function will create a copy of array and won't affect the * original array. The fact of modification is detected using refcount * comparison. The result of sorting in such case is undefined and the * function returns FALSE. */ -//??? Z_UNSET_ISREF_P(array); + Z_ADDREF_P(array); refcount = Z_REFCOUNT_P(array); + arr = Z_COUNTED_P(array); if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_key_compare, 0 TSRMLS_CC) == FAILURE) { RETVAL_FALSE; } else { if (refcount > Z_REFCOUNT_P(array)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array was modified by the user comparison function"); + if (--GC_REFCOUNT(arr) <= 0) { + _zval_dtor_func(arr ZEND_FILE_LINE_CC); + } RETVAL_FALSE; } else { + Z_DELREF_P(array); RETVAL_TRUE; } } - if (Z_REFCOUNT_P(array) > 1) { -//??? Z_SET_ISREF_P(array); - } - PHP_ARRAY_CMP_FUNC_RESTORE(); } /* }}} */ |