Re: [PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
To allow us to do this: $a = array('a' = 1, 'b' = 2); $b = $a; $c = $a; array_merge_recursive($b, $c); The old check has a problem, because $b $c are write only copies *src_entry == *dest_entry condition is met and the function incorrectly terminates claiming a circular reference. We cannot use is_ref field to verify references since that field is always 0 no matter what. So, we rely on an interesting property of refcount, which causes refcount to be odd when we have a reference and even we simply have a write only copy. Ilia On June 17, 2003 10:06 am, Andrei Zmievski wrote: On Mon, 16 Jun 2003, Ilia Alshanetsky wrote: + if (*src_entry == *dest_entry ((*dest_entry)-refcount % 2)) { Why this %2 test? -Andrei For every complex problem, there is a solution that is simple, neat, and wrong. -- H. L. Mencken -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
On Tue, Jun 17, 2003 at 10:24:46AM -0400, Ilia A. wrote: The old check has a problem, because $b $c are write only copies *src_entry == *dest_entry condition is met and the function incorrectly terminates claiming a circular reference. We cannot use is_ref field to verify references since that field is always 0 no matter what. So, we rely on an interesting property of refcount, which causes refcount to be odd when we have a reference and even we simply have a write only copy. Golly, that sounds like a swell thing to document alongside of the code. -- Jon Parise ([EMAIL PROTECTED]) :: The PHP Project (http://www.php.net/) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
On Tue, 17 Jun 2003, Ilia A. wrote: references since that field is always 0 no matter what. So, we rely on an interesting property of refcount, which causes refcount to be odd when we have a reference and even we simply have a write only copy. Can you explain the rationality behind this property? Why can't we have is_ref=0 and refcount=3? -Andrei * All of the above is my opinion, unless specified otherwise. * -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array bug24198.phpt
iliaa Mon Jun 16 13:35:16 2003 EDT Added files: /php4/ext/standard/tests/array bug24198.phpt Modified files: /php4/ext/standard array.c Log: Fixed bug #24198 (Invalid recursion detection in array_merge_recurcive()) Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.233 php4/ext/standard/array.c:1.234 --- php4/ext/standard/array.c:1.233 Thu Jun 12 11:11:11 2003 +++ php4/ext/standard/array.c Mon Jun 16 13:35:16 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.233 2003/06/12 15:11:11 andrey Exp $ */ +/* $Id: array.c,v 1.234 2003/06/16 17:35:16 iliaa Exp $ */ #include php.h #include php_ini.h @@ -2141,7 +2141,7 @@ case HASH_KEY_IS_STRING: if (recursive zend_hash_find(dest, string_key, string_key_len, (void **)dest_entry) == SUCCESS) { - if (*src_entry == *dest_entry) { + if (*src_entry == *dest_entry ((*dest_entry)-refcount % 2)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, recursion detected); return 0; } Index: php4/ext/standard/tests/array/bug24198.phpt +++ php4/ext/standard/tests/array/bug24198.phpt --TEST--n Bug #24198 (array_merge_recursive() invalid recursion detection) --FILE-- ?php $c = array('a' = 'aa','b' = 'bb'); var_dump(array_merge_recursive($c, $c)); ? --EXPECT-- array(2) { [a]= array(2) { [0]= string(2) aa [1]= string(2) aa } [b]= array(2) { [0]= string(2) bb [1]= string(2) bb } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
andrey Thu Jun 12 11:11:11 2003 EDT Modified files: /php4/ext/standard array.c Log: silly bug Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.232 php4/ext/standard/array.c:1.233 --- php4/ext/standard/array.c:1.232 Tue Jun 10 16:03:37 2003 +++ php4/ext/standard/array.c Thu Jun 12 11:11:11 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.232 2003/06/10 20:03:37 imajes Exp $ */ +/* $Id: array.c,v 1.233 2003/06/12 15:11:11 andrey Exp $ */ #include php.h #include php_ini.h @@ -3775,8 +3775,8 @@ zval_add_ref(entry_values); add_index_zval(return_value, Z_LVAL_PP(entry_keys), *entry_values); } - zend_hash_move_forward_ex(Z_ARRVAL_PP(entry_keys), pos_keys); - zend_hash_move_forward_ex(Z_ARRVAL_PP(entry_values), pos_values); + zend_hash_move_forward_ex(Z_ARRVAL_P(keys), pos_keys); + zend_hash_move_forward_ex(Z_ARRVAL_P(values), pos_values); } } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
sterlingThu Jun 5 09:58:15 2003 EDT Modified files: /php4/ext/standard array.c Log: fix array_key_exists() from HANDLE_NUMERIC() changes # need to go through this file and find any stuff that relies on this # change Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.230 php4/ext/standard/array.c:1.231 --- php4/ext/standard/array.c:1.230 Tue May 20 14:18:56 2003 +++ php4/ext/standard/array.c Thu Jun 5 09:58:14 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.230 2003/05/20 18:18:56 sterling Exp $ */ +/* $Id: array.c,v 1.231 2003/06/05 13:58:14 sterling Exp $ */ #include php.h #include php_ini.h @@ -3629,6 +3629,7 @@ { zval **key, /* key to check for */ **array; /* array to check in */ + long lvalue; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(ZEND_NUM_ARGS(), key, array) == FAILURE) { @@ -3642,11 +3643,14 @@ switch (Z_TYPE_PP(key)) { case IS_STRING: - if (zend_hash_exists(HASH_OF(*array), Z_STRVAL_PP(key), Z_STRLEN_PP(key)+1)) { + if (zend_is_numeric_key(*key, lvalue)) { + if (zend_hash_index_exists(HASH_OF(*array), lvalue)) { + RETURN_TRUE; + } + } else if (zend_hash_exists(HASH_OF(*array), Z_STRVAL_PP(key), Z_STRLEN_PP(key)+1)) { RETURN_TRUE; } RETURN_FALSE; - case IS_LONG: if (zend_hash_index_exists(HASH_OF(*array), Z_LVAL_PP(key))) { RETURN_TRUE; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
pollita Thu Apr 3 13:33:05 2003 EDT Modified files: /php4/ext/standard array.c Log: Kludgy fix for floating point drift causing problems like range(1.0,1.5,0.1) == array(1.0,1.1,1.2,1.3,1.4); Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.224 php4/ext/standard/array.c:1.225 --- php4/ext/standard/array.c:1.224 Tue Apr 1 16:47:21 2003 +++ php4/ext/standard/array.c Thu Apr 3 13:33:05 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.224 2003/04/01 21:47:21 rasmus Exp $ */ +/* $Id: array.c,v 1.225 2003/04/03 18:33:05 pollita Exp $ */ #include php.h #include php_ini.h @@ -81,6 +81,8 @@ #define INTERSECT_NORMAL 0 #define INTERSECT_ASSOC1 +#define DOUBLE_DRIFT_FIX 0.001 + PHP_MINIT_FUNCTION(array) { #ifdef ZTS @@ -1543,7 +1545,7 @@ err = 1; goto err; } - for (; low = high; low -= step) { + for (; low = (high - DOUBLE_DRIFT_FIX); low -= step) { add_next_index_double(return_value, low); } } else if (high low) {/* Positive steps */ @@ -1551,7 +1553,7 @@ err = 1; goto err; } - for (; low = high; low += step) { + for (; low = (high + DOUBLE_DRIFT_FIX); low += step) { add_next_index_double(return_value, low); } } else { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
rasmus Tue Apr 1 16:47:21 2003 EDT Modified files: /php4/ext/standard array.c Log: MFB Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.223 php4/ext/standard/array.c:1.224 --- php4/ext/standard/array.c:1.223 Thu Mar 27 13:57:53 2003 +++ php4/ext/standard/array.c Tue Apr 1 16:47:21 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.223 2003/03/27 18:57:53 iliaa Exp $ */ +/* $Id: array.c,v 1.224 2003/04/01 21:47:21 rasmus Exp $ */ #include php.h #include php_ini.h @@ -2465,6 +2465,10 @@ /* Populate the pads array */ num_pads = pad_size_abs - input_size; + if(num_pads 1048576) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, You may only pad up to 1048576 elements at a time); + RETURN_FALSE; + } pads = (zval ***)emalloc(num_pads * sizeof(zval **)); for (i = 0; i num_pads; i++) { pads[i] = pad_value; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
iliaa Thu Mar 27 13:57:53 2003 EDT Modified files: /php4/ext/standard array.c Log: CS Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.222 php4/ext/standard/array.c:1.223 --- php4/ext/standard/array.c:1.222 Sat Feb 22 08:55:11 2003 +++ php4/ext/standard/array.c Thu Mar 27 13:57:53 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.222 2003/02/22 13:55:11 andrey Exp $ */ +/* $Id: array.c,v 1.223 2003/03/27 18:57:53 iliaa Exp $ */ #include php.h #include php_ini.h @@ -360,8 +360,7 @@ convert_to_string(second); } - result = strnatcmp_ex(Z_STRVAL(first), Z_STRLEN(first), - Z_STRVAL(second), Z_STRLEN(second), fold_case); + result = strnatcmp_ex(Z_STRVAL(first), Z_STRLEN(first), Z_STRVAL(second), Z_STRLEN(second), fold_case); if (Z_TYPE_P(fval) != IS_STRING) zval_dtor(first); @@ -750,7 +749,7 @@ if (zend_hash_get_current_data(target_hash, (void **) entry) == FAILURE) { RETURN_FALSE; } - + *return_value = **entry; zval_copy_ctor(return_value); } @@ -949,7 +948,7 @@ *retval_ptr, /* Return value - unused */ *key; /* Entry key */ char *string_key; - uint string_key_len; + uint string_key_len; ulong num_key; HashPosition pos; @@ -1095,7 +1094,7 @@ uint str_key_len; char *string_key; int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function; - + if (ZEND_NUM_ARGS() 2 || ZEND_NUM_ARGS() 3 || zend_get_parameters_ex(ZEND_NUM_ARGS(), value, array, strict) == FAILURE) { WRONG_PARAM_COUNT; @@ -1129,7 +1128,7 @@ RETURN_TRUE; } else { /* Return current key */ - switch (zend_hash_get_current_key_ex(target_hash, string_key, str_key_len, num_key, 0, pos)) { + switch (zend_hash_get_current_key_ex(target_hash, string_key, str_key_len, num_key, 0, pos)) { case HASH_KEY_IS_STRING: RETURN_STRINGL(string_key, str_key_len-1, 1); break; @@ -1142,7 +1141,7 @@ zend_hash_move_forward_ex(target_hash, pos); } - + RETURN_FALSE; } @@ -1706,8 +1705,7 @@ ALLOC_HASHTABLE(out_hash); zend_hash_init(out_hash, 0, NULL, ZVAL_PTR_DTOR, 0); - /* Start at the beginning of the input hash and copy - entries to output hash until offset is reached */ + /* Start at the beginning of the input hash and copy entries to output hash until offset is reached */ for (pos=0, p=in_hash-pListHead; posoffset p ; pos++, p=p-pListNext) { /* Get entry and increase reference count */ entry = *((zval **)p-pData); @@ -1720,8 +1718,7 @@ zend_hash_next_index_insert(out_hash, entry, sizeof(zval *), NULL); } - /* If hash for removed entries exists, go until offset+length - and copy the entries to it */ + /* If hash for removed entries exists, go until offset+length and copy the entries to it */ if (removed != NULL) { for ( ; posoffset+length p; pos++, p=p-pListNext) { entry = *((zval **)p-pData); @@ -1736,8 +1733,7 @@ /* If there are entries to insert.. */ if (list != NULL) { - /* ..for each one, create a new zval, copy entry into it - and copy it into the output hash */ + /* ..for each one, create a new zval, copy entry into it and copy it into the output hash */ for (i=0; ilist_count; i++) { entry = *list[i]; if (entry-refcount=1000) { @@ -1776,10 +1772,10 @@ PHP_FUNCTION(array_push) { zval ***args, /* Function arguments array */ - *stack, /* Input array */ - *new_var; /* Variable to be pushed */ - int i, /* Loop counter */ -argc; /* Number of function arguments */ + *stack, /* Input array */ + *new_var; /* Variable to be pushed */ + int i, /* Loop counter */ +argc; /* Number of function arguments */ /* Get the argument
[PHP-CVS] cvs: php4 /ext/standard array.c
sniper Mon Feb 3 11:57:02 2003 EDT Modified files: /php4/ext/standard array.c Log: - Fixed bug: #21998 (array_pop() did not reset the current array position) # This behaves now same as in PHP 4.2.3 Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.217 php4/ext/standard/array.c:1.218 --- php4/ext/standard/array.c:1.217 Fri Jan 24 11:29:39 2003 +++ php4/ext/standard/array.c Mon Feb 3 11:57:02 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.217 2003/01/24 16:29:39 iliaa Exp $ */ +/* $Id: array.c,v 1.218 2003/02/03 16:57:02 sniper Exp $ */ #include php.h #include php_ini.h @@ -1823,6 +1823,8 @@ } else if (!key_len) { Z_ARRVAL_PP(stack)-nNextFreeElement = Z_ARRVAL_PP(stack)-nNextFreeElement - 1; } + + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(stack)); } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c assert.c browscap.c html.c
iliaa Fri Jan 24 11:29:40 2003 EDT Modified files: /php4/ext/standard array.c assert.c browscap.c html.c Log: zend_error - php_error_docref. Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.216 php4/ext/standard/array.c:1.217 --- php4/ext/standard/array.c:1.216 Tue Jan 21 09:53:16 2003 +++ php4/ext/standard/array.c Fri Jan 24 11:29:39 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.216 2003/01/21 14:53:16 iliaa Exp $ */ +/* $Id: array.c,v 1.217 2003/01/24 16:29:39 iliaa Exp $ */ #include php.h #include php_ini.h @@ -2083,8 +2083,7 @@ zend_hash_find(dest, string_key, string_key_len, (void **)dest_entry) == SUCCESS) { if (*src_entry == *dest_entry) { - zend_error(E_WARNING, %s(): recursion detected, - get_active_function_name(TSRMLS_C)); + php_error_docref(NULL TSRMLS_CC, +E_WARNING, recursion detected); return 0; } SEPARATE_ZVAL(dest_entry); Index: php4/ext/standard/assert.c diff -u php4/ext/standard/assert.c:1.51 php4/ext/standard/assert.c:1.52 --- php4/ext/standard/assert.c:1.51 Tue Dec 31 11:07:32 2002 +++ php4/ext/standard/assert.c Fri Jan 24 11:29:40 2003 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: assert.c,v 1.51 2002/12/31 16:07:32 sebastian Exp $ */ +/* $Id: assert.c,v 1.52 2003/01/24 16:29:40 iliaa Exp $ */ /* {{{ includes/startup/misc */ @@ -157,8 +157,8 @@ compiled_string_description = zend_make_compiled_string_description(assert code TSRMLS_CC); if (zend_eval_string(myeval, retval, compiled_string_description TSRMLS_CC) == FAILURE) { efree(compiled_string_description); - zend_error(E_ERROR, Failure evaluating code:\n%s, myeval); - /* zend_error() does not return in this case. */ + php_error_docref(NULL TSRMLS_CC, E_ERROR, Failure evaluating +code:\n%s, myeval); + /* php_error_docref() does not return in this case. */ } efree(compiled_string_description); Index: php4/ext/standard/browscap.c diff -u php4/ext/standard/browscap.c:1.67 php4/ext/standard/browscap.c:1.68 --- php4/ext/standard/browscap.c:1.67 Sat Jan 11 18:05:19 2003 +++ php4/ext/standard/browscap.cFri Jan 24 11:29:40 2003 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: browscap.c,v 1.67 2003/01/11 23:05:19 moriyoshi Exp $ */ +/* $Id: browscap.c,v 1.68 2003/01/24 16:29:40 iliaa Exp $ */ #include php.h #include php_regex.h @@ -228,7 +228,7 @@ case 0: if (!PG(http_globals)[TRACK_VARS_SERVER] || zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]-value.ht, HTTP_USER_AGENT, sizeof(HTTP_USER_AGENT), (void **) agent_name)==FAILURE) { - zend_error(E_WARNING, HTTP_USER_AGENT variable is not set, cannot determine user agent name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, +HTTP_USER_AGENT variable is not set, cannot determine user agent name); RETURN_FALSE; } break; Index: php4/ext/standard/html.c diff -u php4/ext/standard/html.c:1.70 php4/ext/standard/html.c:1.71 --- php4/ext/standard/html.c:1.70 Fri Jan 3 09:37:42 2003 +++ php4/ext/standard/html.cFri Jan 24 11:29:40 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: html.c,v 1.70 2003/01/03 14:37:42 hyanantha Exp $ */ +/* $Id: html.c,v 1.71 2003/01/24 16:29:40 iliaa Exp $ */ #include php.h #if PHP_WIN32 @@ -703,7 +703,7 @@ /* When we have MBCS entities in the tables above, this will need to handle it */ if (k 0xff) { - zend_error(E_WARNING, cannot yet handle MBCS in html_entity_decode()!); + php_error_docref(NULL TSRMLS_CC, E_WARNING, +cannot yet handle MBCS!); } replacement[0] = k; replacement[1] = '\0'; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c basic_functions.c php_array.h
andrey Mon Jan 13 13:12:23 2003 EDT Modified files: /php4/ext/standard array.c basic_functions.c php_array.h Log: added array_combine(). Creates an array by using the elements of the first parameter as keys and the elements of the second as correspoding keys. Error is thrown in case the arrays has different number of elements. Number of elements 0 is not valid for both parameters. Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.214 php4/ext/standard/array.c:1.215 --- php4/ext/standard/array.c:1.214 Fri Jan 3 00:05:12 2003 +++ php4/ext/standard/array.c Mon Jan 13 13:12:23 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.214 2003/01/03 05:05:12 moriyoshi Exp $ */ +/* $Id: array.c,v 1.215 2003/01/13 18:12:23 andrey Exp $ */ #include php.h #include php_ini.h @@ -3647,6 +3647,48 @@ /* Add the final chunk if there is one. */ if (chunk) { add_next_index_zval(return_value, chunk); + } +} +/* }}} */ + +/* {{{ proto array array_combine(array keys, array values) + Creates an array by using the elements of the first parameter as keys and the +elements of the second as correspoding keys */ +PHP_FUNCTION(array_combine) +{ + zval *values, *keys; + HashPosition pos_values, pos_keys; + zval **entry_keys, **entry_values; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, aa, keys, values) == +FAILURE) { + return; + } + + if (zend_hash_num_elements(Z_ARRVAL_P(keys)) == 0 || +zend_hash_num_elements(Z_ARRVAL_P(values)) == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Both parameters should +have number of elements at least 0); + RETURN_FALSE; + } + + + if (zend_hash_num_elements(Z_ARRVAL_P(keys)) != +zend_hash_num_elements(Z_ARRVAL_P(values))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Both parameters should +have equal number of elements); + RETURN_FALSE; + } + + array_init(return_value); + + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(keys), pos_keys); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), pos_values); + while (zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), (void **)entry_keys, +pos_keys) == SUCCESS +zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void +**)entry_values, pos_values) == SUCCESS) { + if (Z_TYPE_PP(entry_keys) == IS_STRING) { + zval_add_ref(entry_values); + add_assoc_zval(return_value, Z_STRVAL_PP(entry_keys), +*entry_values); + } else if (Z_TYPE_PP(entry_keys) == IS_LONG) { + zval_add_ref(entry_values); + add_index_zval(return_value, Z_LVAL_PP(entry_keys), +*entry_values); + } + zend_hash_move_forward_ex(Z_ARRVAL_PP(entry_keys), pos_keys); + zend_hash_move_forward_ex(Z_ARRVAL_PP(entry_values), pos_values); } } /* }}} */ Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.558 php4/ext/standard/basic_functions.c:1.559 --- php4/ext/standard/basic_functions.c:1.558 Sun Jan 12 09:47:17 2003 +++ php4/ext/standard/basic_functions.c Mon Jan 13 13:12:23 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: basic_functions.c,v 1.558 2003/01/12 14:47:17 sebastian Exp $ */ +/* $Id: basic_functions.c,v 1.559 2003/01/13 18:12:23 andrey Exp $ */ #include php.h #include php_streams.h @@ -845,6 +845,7 @@ PHP_FE(array_filter, NULL) PHP_FE(array_map, NULL) PHP_FE(array_chunk, NULL) + PHP_FE(array_combine, + NULL) PHP_FE(array_key_exists, NULL) /* aliases from array.c */ Index: php4/ext/standard/php_array.h diff -u php4/ext/standard/php_array.h:1.40 php4/ext/standard/php_array.h:1.41 --- php4/ext/standard/php_array.h:1.40 Tue Dec 31 11:07:50 2002 +++ php4/ext/standard/php_array.h Mon Jan 13 13:12:23 2003 @@ -19,7 +19,7 @@ +--+ */ -/* $Id: php_array.h,v 1.40 2002/12/31 16:07:50 sebastian Exp $ */ +/* $Id: php_array.h,v 1.41 2003/01/13 18:12:23 andrey Exp $ */
[PHP-CVS] cvs: php4 /ext/standard array.c
moriyoshi Fri Jan 3 00:05:13 2003 EDT Modified files: /php4/ext/standard array.c Log: Fixed small leaks in array_map() in case the first parameter is NULL like array_map(NULL, array(...)); Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.213 php4/ext/standard/array.c:1.214 --- php4/ext/standard/array.c:1.213 Tue Dec 31 11:07:31 2002 +++ php4/ext/standard/array.c Fri Jan 3 00:05:12 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.213 2002/12/31 16:07:31 sebastian Exp $ */ +/* $Id: array.c,v 1.214 2003/01/03 05:05:12 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -3418,6 +3418,8 @@ WRONG_PARAM_COUNT; } + RETVAL_NULL(); + callback = *args[0]; if (Z_TYPE_P(callback) != IS_NULL) { if (!zend_is_callable(callback, 0, callback_name)) { @@ -3438,6 +3440,7 @@ if (Z_TYPE_PP(args[i+1]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, Argument #%d should be an array, i + 2); efree(array_len); + efree(array_pos); efree(args); return; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c /ext/standard/tests/array range.phpt
iliaa Fri Dec 20 12:16:32 2002 EDT Added files: /php4/ext/standard/tests/array range.phpt Modified files: /php4/ext/standard array.c Log: When low high are the same return an array containing the low value. Added support for float values and handling of numeric values being passed as strings. Added a test case for range(). Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.210 php4/ext/standard/array.c:1.211 --- php4/ext/standard/array.c:1.210 Mon Dec 9 10:54:38 2002 +++ php4/ext/standard/array.c Fri Dec 20 12:16:31 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.210 2002/12/09 15:54:38 moriyoshi Exp $ */ +/* $Id: array.c,v 1.211 2002/12/20 17:16:31 iliaa Exp $ */ #include php.h #include php_ini.h @@ -1421,78 +1421,133 @@ Create an array containing the range of integers or characters from low to high (inclusive) */ PHP_FUNCTION(range) { - zval *zlow, *zhigh; - long step = 1; + zval *zlow, *zhigh, *zstep = NULL; + int err = 0, is_step_double = 0; + double step = 1.0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, zz|l, zlow, - zhigh, step) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, zz|z, zlow, zhigh, +zstep) == FAILURE) { RETURN_FALSE; } - /* We only want positive step values. */ - if (step 0) { - step *= -1; - } + if (zstep) { + if (Z_TYPE_P(zstep) == IS_DOUBLE || (Z_TYPE_P(zstep) == IS_STRING +is_numeric_string(Z_STRVAL_P(zstep), Z_STRLEN_P(zstep), NULL, NULL, 0) == IS_DOUBLE)) +{ + is_step_double = 1; + } + + convert_to_double_ex(zstep); + step = Z_DVAL_P(zstep); + + /* We only want positive step values. */ + if (step 0.0) { + step *= -1; + } + } /* Initialize the return_value as an array. */ array_init(return_value); /* If the range is given as strings, generate an array of characters. */ if (Z_TYPE_P(zlow) == IS_STRING Z_TYPE_P(zhigh) == IS_STRING) { + int type1, type2; unsigned char *low, *high; + long lstep = (long) step; + type1 = is_numeric_string(Z_STRVAL_P(zlow), Z_STRLEN_P(zlow), NULL, +NULL, 0); + type2 = is_numeric_string(Z_STRVAL_P(zhigh), Z_STRLEN_P(zhigh), NULL, +NULL, 0); + + if (type1 == IS_DOUBLE || type2 == IS_DOUBLE || is_step_double) { + goto double_str; + } else if (type1 == IS_LONG || type2 == IS_LONG) { + goto long_str; + } + convert_to_string_ex(zlow); convert_to_string_ex(zhigh); low = (unsigned char *)Z_STRVAL_P(zlow); high = (unsigned char *)Z_STRVAL_P(zhigh); if (*low *high) { /* Negative steps */ - if (*low - *high step || step = 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, step exceeds the specified range); - zval_dtor(return_value); - RETURN_FALSE; + if (*low - *high lstep || lstep = 0) { + err = 1; + goto err; } for (; *low = *high; (*low) -= (unsigned int)step) { add_next_index_stringl(return_value, low, 1, 1); } - } else {/* Positive steps */ - if (*high - *low step || step = 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, step exceeds the specified range); - zval_dtor(return_value); - RETURN_FALSE; + } else if (*high *low) { /* Positive steps */ + if (*high - *low lstep || lstep = 0) { + err = 1; + goto err; } - for (; *low = *high; (*low) += (unsigned int)step) { + for (; *low = *high; (*low) += (unsigned int)lstep) { add_next_index_stringl(return_value, low, 1, 1); } + } else { + add_next_index_stringl(return_value, low, 1, 1); + } + } else if (Z_TYPE_P(zlow) == IS_DOUBLE || Z_TYPE_P(zhigh) == IS_DOUBLE || +is_step_double) { + double low, high;
[PHP-CVS] cvs: php4 /ext/standard array.c
moriyoshi Mon Dec 9 10:54:38 2002 EDT Modified files: /php4/ext/standard array.c Log: @- Let array_search() accept objects as a needle under ZendEngine2. (Moriyoshi) Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.209 php4/ext/standard/array.c:1.210 --- php4/ext/standard/array.c:1.209 Fri Dec 6 12:35:52 2002 +++ php4/ext/standard/array.c Mon Dec 9 10:54:38 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.209 2002/12/06 17:35:52 iliaa Exp $ */ +/* $Id: array.c,v 1.210 2002/12/09 15:54:38 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -1054,11 +1054,13 @@ zend_get_parameters_ex(ZEND_NUM_ARGS(), value, array, strict) == FAILURE) { WRONG_PARAM_COUNT; } - + +#ifndef ZEND_ENGINE_2 if (Z_TYPE_PP(value) == IS_OBJECT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, Wrong datatype for first argument); RETURN_FALSE; } +#endif if (Z_TYPE_PP(array) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, Wrong datatype for second argument); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
iliaa Fri Dec 6 12:35:52 2002 EDT Modified files: /php4/ext/standard array.c Log: Fixed bug #20865, array_key_exists() could not locate NULL keys. Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.208 php4/ext/standard/array.c:1.209 --- php4/ext/standard/array.c:1.208 Thu Dec 5 17:28:00 2002 +++ php4/ext/standard/array.c Fri Dec 6 12:35:52 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.208 2002/12/05 22:28:00 iliaa Exp $ */ +/* $Id: array.c,v 1.209 2002/12/06 17:35:52 iliaa Exp $ */ #include php.h #include php_ini.h @@ -3504,6 +3504,11 @@ case IS_LONG: if (zend_hash_index_exists(HASH_OF(*array), Z_LVAL_PP(key))) { + RETURN_TRUE; + } + RETURN_FALSE; + case IS_NULL: + if (zend_hash_exists(HASH_OF(*array), , 1)) { RETURN_TRUE; } RETURN_FALSE; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c
is it ok to have NULL keys in the arrays? Best regards Andrey Hristov - Original Message - From: Ilia Alshanetsky [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, December 06, 2002 7:35 PM Subject: [PHP-CVS] cvs: php4 /ext/standard array.c iliaa Fri Dec 6 12:35:52 2002 EDT Modified files: /php4/ext/standard array.c Log: Fixed bug #20865, array_key_exists() could not locate NULL keys. Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.208 php4/ext/standard/array.c:1.209 --- php4/ext/standard/array.c:1.208 Thu Dec 5 17:28:00 2002 +++ php4/ext/standard/array.c Fri Dec 6 12:35:52 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.208 2002/12/05 22:28:00 iliaa Exp $ */ +/* $Id: array.c,v 1.209 2002/12/06 17:35:52 iliaa Exp $ */ #include php.h #include php_ini.h @@ -3504,6 +3504,11 @@ case IS_LONG: if (zend_hash_index_exists(HASH_OF(*array), Z_LVAL_PP(key))) { + RETURN_TRUE; + } + RETURN_FALSE; + case IS_NULL: + if (zend_hash_exists(HASH_OF(*array), , 1)) { RETURN_TRUE; } RETURN_FALSE; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c
- Original Message - From: Ilia A. [EMAIL PROTECTED] To: Andrey Hristov [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, December 06, 2002 8:00 PM Subject: Re: [PHP-CVS] cvs: php4 /ext/standard array.c On December 6, 2002 12:53 pm, Andrey Hristov wrote: is it ok to have NULL keys in the arrays? It seems to work fine. For example $array[NULL] will return the value of the NULL key if it is available just another trick with NULL :) Andrey -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
moriyoshi Wed Dec 4 11:41:29 2002 EDT Modified files: /php4/ext/standard array.c Log: Fixed segfaults of array_walk() when keys are passed to cb by reference. Fixed bug #12776. Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.206 php4/ext/standard/array.c:1.207 --- php4/ext/standard/array.c:1.206 Tue Dec 3 10:02:06 2002 +++ php4/ext/standard/array.c Wed Dec 4 11:41:28 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.206 2002/12/03 15:02:06 moriyoshi Exp $ */ +/* $Id: array.c,v 1.207 2002/12/04 16:41:28 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -953,9 +953,6 @@ ulong num_key; HashPosition pos; - /* Allocate space for key */ - MAKE_STD_ZVAL(key); - /* Set up known arguments */ args[1] = key; args[2] = userdata; @@ -964,14 +961,15 @@ /* Iterate through hash */ while (zend_hash_get_current_data_ex(target_hash, (void **)args[0], pos) == SUCCESS) { + /* Allocate space for key */ + MAKE_STD_ZVAL(key); + /* Set up the key */ if (zend_hash_get_current_key_ex(target_hash, string_key, string_key_len, num_key, 0, pos) == HASH_KEY_IS_LONG) { Z_TYPE_P(key) = IS_LONG; Z_LVAL_P(key) = num_key; } else { - Z_TYPE_P(key) = IS_STRING; - Z_STRVAL_P(key) = string_key; - Z_STRLEN_P(key) = string_key_len-1; + ZVAL_STRINGL(key, string_key, string_key_len-1, 1); } /* Call the userland function */ @@ -992,9 +990,9 @@ break; } + zval_ptr_dtor(key); zend_hash_move_forward_ex(target_hash, pos); } - zval_ptr_dtor(key); return 0; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
moriyoshi Tue Dec 3 10:02:07 2002 EDT Modified files: /php4/ext/standard array.c Log: Fixed leaks in array_walk() Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.205 php4/ext/standard/array.c:1.206 --- php4/ext/standard/array.c:1.205 Tue Nov 26 17:12:40 2002 +++ php4/ext/standard/array.c Tue Dec 3 10:02:06 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.205 2002/11/26 22:12:40 moriyoshi Exp $ */ +/* $Id: array.c,v 1.206 2002/12/03 15:02:06 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -994,7 +994,7 @@ zend_hash_move_forward_ex(target_hash, pos); } - efree(key); + zval_ptr_dtor(key); return 0; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
moriyoshi Tue Nov 26 16:21:33 2002 EDT Modified files: /php4/ext/standard array.c Log: Fixed incorrect error messages of array_walk() in case the callback is specified in an array form Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.202 php4/ext/standard/array.c:1.203 --- php4/ext/standard/array.c:1.202 Sat Nov 23 06:27:56 2002 +++ php4/ext/standard/array.c Tue Nov 26 16:21:32 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.202 2002/11/23 11:27:56 moriyoshi Exp $ */ +/* $Id: array.c,v 1.203 2002/11/26 21:21:32 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -980,8 +980,37 @@ zval_ptr_dtor(retval_ptr); } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to call %s() - function does not exist, + if (Z_TYPE_PP(BG(array_walk_func_name)) == IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to +call %s() - function does not exist, (*BG(array_walk_func_name))-value.str.val); + } else if (Z_TYPE_PP(BG(array_walk_func_name)) == IS_ARRAY) { + char *obj_name = NULL; + zval **obj; + zval **mt_name; + + if +(zend_hash_index_find(Z_ARRVAL_PP(BG(array_walk_func_name)), + 0, (void **)obj) == SUCCESS + +zend_hash_index_find(Z_ARRVAL_PP(BG(array_walk_func_name)), + 1, (void **)mt_name) == SUCCESS +Z_TYPE_PP(mt_name) == IS_STRING) { + switch (Z_TYPE_PP(obj)) { + case IS_OBJECT: + obj_name = +Z_OBJ_PP(obj)-ce-name; + break; + + case IS_STRING: + obj_name = Z_STRVAL_PP(obj); + break; + } + } + + if (obj_name != NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, +Unable to call %s::%s() - function does not exist, + obj_name, Z_STRVAL_PP(mt_name)); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, +Invalid function name); + } + } } zend_hash_move_forward_ex(target_hash, pos); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
moriyoshi Tue Nov 26 17:12:40 2002 EDT Modified files: /php4/ext/standard array.c Log: Improved the error reporting portion of array_walk() as suggested by Markus Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.204 php4/ext/standard/array.c:1.205 --- php4/ext/standard/array.c:1.204 Tue Nov 26 16:51:37 2002 +++ php4/ext/standard/array.c Tue Nov 26 17:12:40 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.204 2002/11/26 21:51:37 moriyoshi Exp $ */ +/* $Id: array.c,v 1.205 2002/11/26 22:12:40 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -980,37 +980,15 @@ zval_ptr_dtor(retval_ptr); } else { - if (Z_TYPE_PP(BG(array_walk_func_name)) == IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to call %s() - function does not exist, - (*BG(array_walk_func_name))-value.str.val); - } else if (Z_TYPE_PP(BG(array_walk_func_name)) == IS_ARRAY) { - char *obj_name = NULL; - zval **obj; - zval **mt_name; - - if (zend_hash_index_find(Z_ARRVAL_PP(BG(array_walk_func_name)), - 0, (void **)obj) == SUCCESS - zend_hash_index_find(Z_ARRVAL_PP(BG(array_walk_func_name)), - 1, (void **)mt_name) == SUCCESS -Z_TYPE_PP(mt_name) == IS_STRING) { - switch (Z_TYPE_PP(obj)) { - case IS_OBJECT: - obj_name = Z_OBJ_PP(obj)-ce-name; - break; - - case IS_STRING: - obj_name = Z_STRVAL_PP(obj); - break; - } - } - - if (obj_name != NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to call %s::%s() - function does not exist, - obj_name, Z_STRVAL_PP(mt_name)); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid function name); - } + char *func_name; + + if (zend_is_callable(*BG(array_walk_func_name), 0, +func_name)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to +call %s(), func_name); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to +call %s() - function does not exist, func_name); } + + efree(func_name); break; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
moriyoshi Sat Nov 23 06:27:56 2002 EDT Modified files: /php4/ext/standard array.c Log: Fixed some odd behaviours of range() Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.201 php4/ext/standard/array.c:1.202 --- php4/ext/standard/array.c:1.201 Thu Nov 14 21:16:41 2002 +++ php4/ext/standard/array.c Sat Nov 23 06:27:56 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.201 2002/11/15 02:16:41 moriyoshi Exp $ */ +/* $Id: array.c,v 1.202 2002/11/23 11:27:56 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -1435,19 +1435,29 @@ /* If the range is given as strings, generate an array of characters. */ if (Z_TYPE_P(zlow) == IS_STRING Z_TYPE_P(zhigh) == IS_STRING) { - char *low, *high; + unsigned char *low, *high; convert_to_string_ex(zlow); convert_to_string_ex(zhigh); - low = Z_STRVAL_P(zlow); - high = Z_STRVAL_P(zhigh); + low = (unsigned char *)Z_STRVAL_P(zlow); + high = (unsigned char *)Z_STRVAL_P(zhigh); if (*low *high) { /* Negative steps */ - for (; *low = *high; (*low) -= step) { + if (*low - *high step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step +exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } + for (; *low = *high; (*low) -= (unsigned int)step) { add_next_index_stringl(return_value, low, 1, 1); } } else {/* Positive steps */ - for (; *low = *high; (*low) += step) { + if (*high - *low step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step +exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } + for (; *low = *high; (*low) += (unsigned int)step) { add_next_index_stringl(return_value, low, 1, 1); } } @@ -1460,10 +1470,20 @@ high = Z_LVAL_P(zhigh); if (low high) { /* Negative steps */ + if (low - high step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step +exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } for (; low = high; low -= step) { add_next_index_long(return_value, low); } } else {/* Positive steps */ + if (high - low step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step +exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } for (; low = high; low += step) { add_next_index_long(return_value, low); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c
Just a notice: The third optional parameter is not suggested in the branch. Therefore I won't try to merge this patch to PHP_4_3, but due to this decision the behaviour of the function slightly differs one another in the cases like range(A, Ä); Moriyoshi Moriyoshi Koizumi [EMAIL PROTECTED] wrote: moriyoshi Sat Nov 23 06:27:56 2002 EDT Modified files: /php4/ext/standardarray.c Log: Fixed some odd behaviours of range() Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.201 php4/ext/standard/array.c:1.202 --- php4/ext/standard/array.c:1.201 Thu Nov 14 21:16:41 2002 +++ php4/ext/standard/array.c Sat Nov 23 06:27:56 2002 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: array.c,v 1.201 2002/11/15 02:16:41 moriyoshi Exp $ */ +/* $Id: array.c,v 1.202 2002/11/23 11:27:56 moriyoshi Exp $ */ #include php.h #include php_ini.h @@ -1435,19 +1435,29 @@ /* If the range is given as strings, generate an array of characters. */ if (Z_TYPE_P(zlow) == IS_STRING Z_TYPE_P(zhigh) == IS_STRING) { - char *low, *high; + unsigned char *low, *high; convert_to_string_ex(zlow); convert_to_string_ex(zhigh); - low = Z_STRVAL_P(zlow); - high = Z_STRVAL_P(zhigh); + low = (unsigned char *)Z_STRVAL_P(zlow); + high = (unsigned char *)Z_STRVAL_P(zhigh); if (*low *high) { /* Negative steps */ - for (; *low = *high; (*low) -= step) { + if (*low - *high step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } + for (; *low = *high; (*low) -= (unsigned int)step) { add_next_index_stringl(return_value, low, 1, 1); } } else {/* Positive steps */ - for (; *low = *high; (*low) += step) { + if (*high - *low step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } + for (; *low = *high; (*low) += (unsigned int)step) { add_next_index_stringl(return_value, low, 1, 1); } } @@ -1460,10 +1470,20 @@ high = Z_LVAL_P(zhigh); if (low high) { /* Negative steps */ + if (low - high step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } for (; low = high; low -= step) { add_next_index_long(return_value, low); } } else {/* Positive steps */ + if (high - low step || step = 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, step exceeds the specified range); + zval_dtor(return_value); + RETURN_FALSE; + } for (; low = high; low += step) { add_next_index_long(return_value, low); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
iliaa Tue Nov 5 11:19:20 2002 EDT Modified files: /php4/ext/standard array.c Log: Fixed a memory leak in array_fill(). The refcount hack is now done for ZE1 only and is slightly faster then the original. After this patch array_fill() can consistently create arrays with 65k elements. Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.197 php4/ext/standard/array.c:1.198 --- php4/ext/standard/array.c:1.197 Thu Oct 10 15:24:45 2002 +++ php4/ext/standard/array.c Tue Nov 5 11:19:19 2002 -21,7 +21,7 +--+ */ -/* $Id: array.c,v 1.197 2002/10/10 19:24:45 sterling Exp $ */ +/* $Id: array.c,v 1.198 2002/11/05 16:19:19 iliaa Exp $ */ #include php.h #include php_ini.h -1397,11 +1397,14 } newval = *val; while (i--) { - if (!(i%62000)) { +#ifndef ZEND_ENGINE_2 + if (newval-refcount = 62000) { MAKE_STD_ZVAL(newval); *newval = **val; zval_copy_ctor(newval); + newval-refcount = 0; } +#endif zval_add_ref(newval); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), newval, sizeof(zval *), NULL); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c
sterlingThu Oct 10 15:24:46 2002 EDT Modified files: /php4/ext/standard array.c Log: revert patch Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.196 php4/ext/standard/array.c:1.197 --- php4/ext/standard/array.c:1.196 Wed Oct 9 14:29:45 2002 +++ php4/ext/standard/array.c Thu Oct 10 15:24:45 2002 -21,7 +21,7 +--+ */ -/* $Id: array.c,v 1.196 2002/10/09 18:29:45 sterling Exp $ */ +/* $Id: array.c,v 1.197 2002/10/10 19:24:45 sterling Exp $ */ #include php.h #include php_ini.h -705,16 +705,21 Move array argument's internal pointer to the previous element and return it */ PHP_FUNCTION(prev) { - zval **entry; - zval *array; + pval **array, **entry; + HashTable *target_hash; - if (zend_parse_parameters(1 TSRMLS_CC, a, array) == FAILURE) { + 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, Passed variable is not an +array or object); RETURN_FALSE; } - zend_hash_move_backwards(Z_ARRVAL_P(array)); + zend_hash_move_backwards(target_hash); if (return_value_used) { - if (zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) entry) == FAILURE) { + if (zend_hash_get_current_data(target_hash, (void **) entry) == +FAILURE) { RETURN_FALSE; } -728,16 +733,21 Move array argument's internal pointer to the next element and return it */ PHP_FUNCTION(next) { - zval **entry; - zval *array; + pval **array, **entry; + HashTable *target_hash; - if (zend_parse_parameters(1 TSRMLS_CC, a, array) == FAILURE) { + 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, Passed variable is not an +array or object); RETURN_FALSE; } - zend_hash_move_forward(Z_ARRVAL_P(array)); + zend_hash_move_forward(target_hash); if (return_value_used) { - if (zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) entry) == FAILURE) { + if (zend_hash_get_current_data(target_hash, (void **) entry) == +FAILURE) { RETURN_FALSE; } -751,16 +761,21 Set array argument's internal pointer to the first element and return it */ PHP_FUNCTION(reset) { - zval **entry; - zval *array; + pval **array, **entry; + HashTable *target_hash; - if (zend_parse_parameters(1 TSRMLS_CC, a, array) == FAILURE) { + 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, Passed variable is not an +array or object); RETURN_FALSE; } - zend_hash_internal_pointer_reset(Z_ARRVAL_P(array)); + zend_hash_internal_pointer_reset(target_hash); if (return_value_used) { - if (zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) entry) == FAILURE) { + if (zend_hash_get_current_data(target_hash, (void **) entry) == +FAILURE) { RETURN_FALSE; } -774,17 +789,20 Return the element currently pointed to by the internal array pointer */ PHP_FUNCTION(current) { - zval **entry; - zval *array; + pval **array, **entry; + HashTable *target_hash; - if (zend_parse_parameters(1 TSRMLS_CC, a, array) == FAILURE) { + 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, Passed variable is not an +array or object); RETURN_FALSE; } - - if (zend_hash_get_current_data(Z_ARRVAL_P(array), (void **) entry) == FAILURE) { + if (zend_hash_get_current_data(target_hash, (void **) entry) == FAILURE) { RETURN_FALSE; } - *return_value = **entry; zval_copy_ctor(return_value); } -794,27 +812,29 Return the key of the element currently pointed to by the internal array pointer */ PHP_FUNCTION(key) { - zval *array; - char *string_key; - uint string_key_length; - ulong num_key = -1; + pval **array; + char *string_key; + uint
Re: [PHP-CVS] cvs: php4 /ext/standard array.c
On 9 Oct 2002, Sterling Hughes wrote: On Wed, 2002-10-09 at 22:21, Thies C. Arntzen wrote: On Wed, Oct 09, 2002 at 06:29:45PM -, Sterling Hughes wrote: sterling Wed Oct 9 14:29:45 2002 EDT Modified files: /php4/ext/standardarray.c Log: clean these functions up using zend_parse_parameters and nuke the use of HASH_OF() which is inappropriate in these cases... will prev still work on objects after your patch? none of them do - none of them should either - why would you want to access an object like you would an _indexed_ array? It breaks BC, s... revert? (Not that I see any use either :) If you're at it, please add some tests for the test framework too. Derick -- --- Derick Rethans http://derickrethans.nl/ JDI Media Solutions --[ if you hold a unix shell to your ear, do you hear the c? ]- -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard array.c
On Wed, 2002-10-09 at 22:45, Derick Rethans wrote: On 9 Oct 2002, Sterling Hughes wrote: On Wed, 2002-10-09 at 22:21, Thies C. Arntzen wrote: On Wed, Oct 09, 2002 at 06:29:45PM -, Sterling Hughes wrote: sterlingWed Oct 9 14:29:45 2002 EDT Modified files: /php4/ext/standard array.c Log: clean these functions up using zend_parse_parameters and nuke the use of HASH_OF() which is inappropriate in these cases... will prev still work on objects after your patch? none of them do - none of them should either - why would you want to access an object like you would an _indexed_ array? It breaks BC, s... revert? (Not that I see any use either :) If you're at it, please add some tests for the test framework too. Well, it breaks it in a not-really-breaking-bc-manner. To my knowledge this was never documented to work. I don't think anyone will miss this feature - if someone will, and is/has used it, please write in and let me know, the patch can be modified to work on objects. But then again, it really wouldn't work well on objects anyhow (even before my patch), so i really don't see the point. -Sterling -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard array.c php_array.h
andrei Tue Sep 10 14:34:17 2002 EDT Modified files: /php4/ext/standard array.c php_array.h Log: - Fixed array_merge_recursive() to avoid problems with merging cyclical arrays (bug #16064). (Andrei) Index: php4/ext/standard/array.c diff -u php4/ext/standard/array.c:1.185 php4/ext/standard/array.c:1.186 --- php4/ext/standard/array.c:1.185 Mon Sep 9 16:05:20 2002 +++ php4/ext/standard/array.c Tue Sep 10 14:34:16 2002 -21,7 +21,7 +--+ */ -/* $Id: array.c,v 1.185 2002/09/09 20:05:20 andrei Exp $ */ +/* $Id: array.c,v 1.186 2002/09/10 18:34:16 andrei Exp $ */ #include php.h #include php_ini.h -1966,7 +1966,7 /* }}} */ -PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive) +PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive) { zval **src_entry, **dest_entry; -1982,10 +1982,16 if (recursive zend_hash_find(dest, string_key, string_key_len, (void **)dest_entry) == SUCCESS) { + if (*src_entry == *dest_entry) { + zend_error(E_WARNING, %s(): recursion +detected, + +get_active_function_name()); + return 0; + } convert_to_array_ex(dest_entry); convert_to_array_ex(src_entry); - php_array_merge(Z_ARRVAL_PP(dest_entry), - Z_ARRVAL_PP(src_entry), recursive); + if (!php_array_merge(Z_ARRVAL_PP(dest_entry), + +Z_ARRVAL_PP(src_entry), recursive)) + return 0; } else { (*src_entry)-refcount++; -2002,6 +2008,8 zend_hash_move_forward_ex(src, pos); } + + return 1; } static void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive) Index: php4/ext/standard/php_array.h diff -u php4/ext/standard/php_array.h:1.35 php4/ext/standard/php_array.h:1.36 --- php4/ext/standard/php_array.h:1.35 Mon May 13 13:28:38 2002 +++ php4/ext/standard/php_array.h Tue Sep 10 14:34:16 2002 -19,7 +19,7 +--+ */ -/* $Id: php_array.h,v 1.35 2002/05/13 17:28:38 andrei Exp $ */ +/* $Id: php_array.h,v 1.36 2002/09/10 18:34:16 andrei Exp $ */ #ifndef PHP_ARRAY_H #define PHP_ARRAY_H -83,7 +83,7 PHP_FUNCTION(array_chunk); HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **); -PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive); +PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive); int multisort_compare(const void *a, const void *b TSRMLS_DC); typedef struct { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php