felipe Thu Dec 25 11:05:20 2008 UTC
Modified files: (Branch: PHP_5_2)
/php-src/ext/standard array.c
Log:
- Fixed BC in array_unique (HASH_OF stuff), warning and CS in another part
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.60&r2=1.308.2.21.2.61&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.308.2.21.2.60
php-src/ext/standard/array.c:1.308.2.21.2.61
--- php-src/ext/standard/array.c:1.308.2.21.2.60 Sat Dec 13 00:38:29 2008
+++ php-src/ext/standard/array.c Thu Dec 25 11:05:19 2008
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.308.2.21.2.60 2008/12/13 00:38:29 andrei Exp $ */
+/* $Id: array.c,v 1.308.2.21.2.61 2008/12/25 11:05:19 felipe Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -1998,7 +1998,7 @@
zval **stack, /* Input stack */
**val; /* Value to be popped */
char *key = NULL;
- int key_len = 0;
+ uint key_len = 0;
ulong index;
/* Get the arguments and do error-checking */
@@ -2016,10 +2016,11 @@
}
/* Get the first or last value and copy it into the return value */
- if (off_the_end)
+ if (off_the_end) {
zend_hash_internal_pointer_end(Z_ARRVAL_PP(stack));
- else
+ } else {
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(stack));
+ }
zend_hash_get_current_data(Z_ARRVAL_PP(stack), (void **)&val);
RETVAL_ZVAL(*val, 1, 0);
@@ -2817,7 +2818,8 @@
Removes duplicate values from array */
PHP_FUNCTION(array_unique)
{
- zval *array, *tmp;
+ zval **array, *tmp;
+ HashTable *target_hash;
Bucket *p;
struct bucketindex {
Bucket *b;
@@ -2827,25 +2829,30 @@
unsigned int i;
long sort_type = SORT_REGULAR;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array,
&sort_type) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|l", &array,
&sort_type) == FAILURE) {
return;
}
+ target_hash = HASH_OF(*array);
+ if (!target_hash) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument
should be an array");
+ RETURN_FALSE;
+ }
set_compare_func(sort_type TSRMLS_CC);
array_init(return_value);
- zend_hash_copy(Z_ARRVAL_P(return_value), Z_ARRVAL_P(array),
(copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*));
+ zend_hash_copy(Z_ARRVAL_P(return_value), target_hash,
(copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*));
- if (Z_ARRVAL_P(array)->nNumOfElements <= 1) { /* nothing to do */
+ if (target_hash->nNumOfElements <= 1) { /* nothing to do */
return;
}
/* create and sort array with pointers to the target_hash buckets */
- arTmp = (struct bucketindex *)
pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex),
Z_ARRVAL_P(array)->persistent);
+ arTmp = (struct bucketindex *) pemalloc((target_hash->nNumOfElements +
1) * sizeof(struct bucketindex), target_hash->persistent);
if (!arTmp) {
RETURN_FALSE;
}
- for (i = 0, p = Z_ARRVAL_P(array)->pListHead; p; i++, p = p->pListNext)
{
+ for (i = 0, p = target_hash->pListHead; p; i++, p = p->pListNext) {
arTmp[i].b = p;
arTmp[i].i = i;
}
@@ -2875,7 +2882,7 @@
}
}
}
- pefree(arTmp, Z_ARRVAL_P(array)->persistent);
+ pefree(arTmp, target_hash->persistent);
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php