andrei Sat Dec 13 00:38:31 2008 UTC Modified files: (Branch: PHP_5_2) /php-src NEWS /php-src/ext/standard array.c /php-src/ext/standard/tests/array array_unique_error.phpt array_unique_variation1.phpt array_unique_variation2.phpt array_unique_variation6.phpt array_unique_variation8.phpt Log: MFH
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1359&r2=1.2027.2.547.2.1360&diff_format=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.547.2.1359 php-src/NEWS:1.2027.2.547.2.1360 --- php-src/NEWS:1.2027.2.547.2.1359 Fri Dec 12 04:21:01 2008 +++ php-src/NEWS Sat Dec 13 00:38:28 2008 @@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2009, PHP 5.2.9 +- Added optional sorting type flag parameter to array_unique(), default is + SORT_REGULAR. (Andrei) - Fixed security issue in imagerotate(), background colour isn't validated correctly with a non truecolour image. (Scott) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.59&r2=1.308.2.21.2.60&diff_format=u Index: php-src/ext/standard/array.c diff -u php-src/ext/standard/array.c:1.308.2.21.2.59 php-src/ext/standard/array.c:1.308.2.21.2.60 --- php-src/ext/standard/array.c:1.308.2.21.2.59 Wed Nov 26 01:00:36 2008 +++ php-src/ext/standard/array.c Sat Dec 13 00:38:29 2008 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: array.c,v 1.308.2.21.2.59 2008/11/26 01:00:36 lbarnaud Exp $ */ +/* $Id: array.c,v 1.308.2.21.2.60 2008/12/13 00:38:29 andrei Exp $ */ #include "php.h" #include "php_ini.h" @@ -2813,12 +2813,11 @@ } /* }}} */ -/* {{{ proto array array_unique(array input) +/* {{{ proto array array_unique(array input [, int sort_flags]) Removes duplicate values from array */ PHP_FUNCTION(array_unique) { - zval **array, *tmp; - HashTable *target_hash; + zval *array, *tmp; Bucket *p; struct bucketindex { Bucket *b; @@ -2826,34 +2825,31 @@ }; struct bucketindex *arTmp, *cmpdata, *lastkept; unsigned int i; + long sort_type = SORT_REGULAR; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { + return; } + set_compare_func(sort_type TSRMLS_CC); + array_init(return_value); - zend_hash_copy(Z_ARRVAL_P(return_value), target_hash, (copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*)); + zend_hash_copy(Z_ARRVAL_P(return_value), Z_ARRVAL_P(array), (copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*)); - if (target_hash->nNumOfElements <= 1) { /* nothing to do */ + if (Z_ARRVAL_P(array)->nNumOfElements <= 1) { /* nothing to do */ return; } /* create and sort array with pointers to the target_hash buckets */ - arTmp = (struct bucketindex *) pemalloc((target_hash->nNumOfElements + 1) * sizeof(struct bucketindex), target_hash->persistent); + arTmp = (struct bucketindex *) pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex), Z_ARRVAL_P(array)->persistent); if (!arTmp) { RETURN_FALSE; } - for (i = 0, p = target_hash->pListHead; p; i++, p = p->pListNext) { + for (i = 0, p = Z_ARRVAL_P(array)->pListHead; p; i++, p = p->pListNext) { arTmp[i].b = p; arTmp[i].i = i; } arTmp[i].b = NULL; - set_compare_func(SORT_STRING TSRMLS_CC); zend_qsort((void *) arTmp, i, sizeof(struct bucketindex), array_data_compare TSRMLS_CC); /* go through the sorted array and delete duplicates from the copy */ @@ -2879,7 +2875,7 @@ } } } - pefree(arTmp, target_hash->persistent); + pefree(arTmp, Z_ARRVAL_P(array)->persistent); } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_error.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u Index: php-src/ext/standard/tests/array/array_unique_error.phpt diff -u php-src/ext/standard/tests/array/array_unique_error.phpt:1.1.4.2 php-src/ext/standard/tests/array/array_unique_error.phpt:1.1.4.3 --- php-src/ext/standard/tests/array/array_unique_error.phpt:1.1.4.2 Sun Dec 9 14:44:18 2007 +++ php-src/ext/standard/tests/array/array_unique_error.phpt Sat Dec 13 00:38:29 2008 @@ -17,7 +17,7 @@ echo "\n-- Testing array_unique() function with more than expected no. of arguments --\n"; $input = array(1, 2); $extra_arg = 10; -var_dump( array_unique($input, $extra_arg) ); +var_dump( array_unique($input, SORT_NUMERIC, $extra_arg) ); echo "Done"; ?> @@ -26,11 +26,11 @@ -- Testing array_unique() function with zero arguments -- -Warning: Wrong parameter count for array_unique() in %s on line %d +Warning: array_unique() expects at least 1 parameter, 0 given in %s on line %d NULL -- Testing array_unique() function with more than expected no. of arguments -- -Warning: Wrong parameter count for array_unique() in %s on line %d +Warning: array_unique() expects at most 2 parameters, 3 given in %s on line %d NULL Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation1.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u Index: php-src/ext/standard/tests/array/array_unique_variation1.phpt diff -u php-src/ext/standard/tests/array/array_unique_variation1.phpt:1.1.4.2 php-src/ext/standard/tests/array/array_unique_variation1.phpt:1.1.4.3 --- php-src/ext/standard/tests/array/array_unique_variation1.phpt:1.1.4.2 Sun Dec 9 14:44:18 2007 +++ php-src/ext/standard/tests/array/array_unique_variation1.phpt Sat Dec 13 00:38:29 2008 @@ -98,97 +98,98 @@ *** Testing array_unique() : Passing non array values to $input argument *** -- Iteration 1 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 2 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 3 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 4 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL -- Iteration 5 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 6 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 7 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 8 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 9 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL -- Iteration 10 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 11 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 12 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 13 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 14 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 15 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL -- Iteration 16 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 17 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 18 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 19 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 20 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL -- Iteration 21 -- -array(0) { -} + +Warning: array_unique() expects parameter 1 to be array, object given in %s on line %d +NULL -- Iteration 22 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 23 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL -- Iteration 24 -- -Warning: array_unique(): The argument should be an array in %s on line %d -bool(false) -Done \ No newline at end of file +Warning: array_unique() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation2.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u Index: php-src/ext/standard/tests/array/array_unique_variation2.phpt diff -u php-src/ext/standard/tests/array/array_unique_variation2.phpt:1.1.4.2 php-src/ext/standard/tests/array/array_unique_variation2.phpt:1.1.4.3 --- php-src/ext/standard/tests/array/array_unique_variation2.phpt:1.1.4.2 Sun Dec 9 14:44:18 2007 +++ php-src/ext/standard/tests/array/array_unique_variation2.phpt Sat Dec 13 00:38:29 2008 @@ -74,7 +74,7 @@ $iterator = 1; foreach($inputs as $input) { echo "-- Iteration $iterator --\n"; - var_dump( array_unique($input) ); + var_dump( array_unique($input, SORT_STRING) ); $iterator++; } http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation6.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u Index: php-src/ext/standard/tests/array/array_unique_variation6.phpt diff -u php-src/ext/standard/tests/array/array_unique_variation6.phpt:1.1.4.2 php-src/ext/standard/tests/array/array_unique_variation6.phpt:1.1.4.3 --- php-src/ext/standard/tests/array/array_unique_variation6.phpt:1.1.4.2 Sun Dec 9 14:44:18 2007 +++ php-src/ext/standard/tests/array/array_unique_variation6.phpt Sat Dec 13 00:38:29 2008 @@ -29,7 +29,7 @@ 5 => $value4 ); -var_dump( array_unique($input) ); +var_dump( array_unique($input, SORT_STRING) ); echo "Done"; ?> http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation8.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u Index: php-src/ext/standard/tests/array/array_unique_variation8.phpt diff -u php-src/ext/standard/tests/array/array_unique_variation8.phpt:1.1.4.2 php-src/ext/standard/tests/array/array_unique_variation8.phpt:1.1.4.3 --- php-src/ext/standard/tests/array/array_unique_variation8.phpt:1.1.4.2 Sun Dec 9 14:44:18 2007 +++ php-src/ext/standard/tests/array/array_unique_variation8.phpt Sat Dec 13 00:38:29 2008 @@ -22,7 +22,7 @@ array(1, 2, 3, 1) ); -var_dump( array_unique($input) ); +var_dump( array_unique($input, SORT_STRING) ); echo "Done"; ?>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php