cvs: php4 /ext/standard array.c
| From: | Harald Radi | Date: | Mon, 10 Jun 2002 12:21:58 +0000 |
| Subject: | cvs: php4 /ext/standard array.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-12280@lists.php.net to get a copy of this message | ||
phanto Mon Jun 10 08:21:58 2002 EDT
Modified files:
/php4/ext/standard array.c
Log:
fix the build
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.164 php4/ext/standard/array.c:1.165
--- php4/ext/standard/array.c:1.164 Sun Jun 9 22:28:32 2002
+++ php4/ext/standard/array.c Mon Jun 10 08:21:58 2002
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.164 2002/06/10 02:28:32 andrei Exp $ */
+/* $Id: array.c,v 1.165 2002/06/10 12:21:58 phanto Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -1435,23 +1435,16 @@
/* }}} */
-/* {{{ proto bool shuffle(array array_arg)
- Randomly shuffle the contents of an array */
-PHP_FUNCTION(shuffle)
+static void array_data_shuffle(zval *array TSRMLS_DC)
{
- zval *array;
Bucket **elems, *temp;
HashTable *hash;
int j, n_elems, cur_elem = 0, rnd_idx, n_left;
- TSRMLS_FETCH();
-
- if (zend_parse_parameters(1 TSRMLS_CC, "a", &array) == FAILURE) {
- RETURN_FALSE;
- }
n_elems = zend_hash_num_elements(Z_ARRVAL_P(array));
+
if (n_elems <= 1) {
- RETURN_TRUE;
+ return;
}
elems = (Bucket **)emalloc(n_elems * sizeof(Bucket *));
@@ -1496,7 +1489,20 @@
HANDLE_UNBLOCK_INTERRUPTIONS();
efree(elems);
-
+}
+
+/* {{{ proto bool shuffle(array array_arg)
+ Randomly shuffle the contents of an array */
+PHP_FUNCTION(shuffle)
+{
+ zval *array;
+
+ if (zend_parse_parameters(1 TSRMLS_CC, "a", &array) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ array_data_shuffle(array TSRMLS_CC);
+
RETURN_TRUE;
}
/* }}} */
@@ -2946,10 +2952,7 @@
}
if (num_req_val == num_avail) {
- if (zend_hash_sort(Z_ARRVAL_P(return_value), (sort_func_t)php_mergesort, array_data_shuffle, 1
TSRMLS_CC) == FAILURE) {
- zval_dtor(return_value);
- RETURN_FALSE;
- }
+ array_data_shuffle(return_value TSRMLS_CC);
}
}
/* }}} */