com php-src: Fixed ext/standard/tests/array/unexpected_array _mod_bug.phpt: ext/standard/array.c
| From: | Dmitry Stogov | Date: | Tue, 29 Jul 2014 14:19:41 +0000 |
| Subject: | com php-src: Fixed ext/standard/tests/array/unexpected_array _mod_bug.phpt: ext/standard/array.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79615@lists.php.net to get a copy of this message | ||
Commit: dda7e84f10bffb0eca57754e682530988edab235
Author: Dmitry Stogov <dmitry@zend.com> Tue, 29 Jul 2014 18:19:41 +0400
Parents: 46fcd3fc08de938293a8a4fe25f9d1ed18457f4a
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dda7e84f10bffb0eca57754e682530988edab235
Log:
Fixed ext/standard/tests/array/unexpected_array_mod_bug.phpt
Changed paths:
M ext/standard/array.c
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 0e01b2e..731c374 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();
}
/* }}} */