Hi Marcus, Thanks for the info. I'm sending along the patch for 5.2 now, since I didn't know whether to wait until the MAIN patch was agreed to (that's what I got from your message), or if you wanted both first. :-)
I didn't realize tests were needed for every function, change, etc. (being new at this, sorry). And I don't see any tests for the current array_fill()... Anyway, if I need to make a test, how thorough should it be? Should all error messages be checked also, or not, since the message text may change in the future? Are tests needed before the patches will get committed? (Assuming they're agreed to, of course.) ;-) Again, don't know how long that takes either... Thanks, Matt ----- Original Message ----- From: "Marcus Boerger" <[EMAIL PROTECTED]> > Hello Matt, > > patch looks fine now, once we agree to this set you'd have to provide > a patch for 5.2 as well. Another thing we need is tests to ensure all > is working as expected. > > best regards > marcus
Index: ext/standard/array.c =================================================================== RCS file: /repository/php-src/ext/standard/array.c,v retrieving revision 1.308.2.21.2.2 diff -u -r1.308.2.21.2.2 array.c --- ext/standard/array.c 26 Jun 2006 18:48:56 -0000 1.308.2.21.2.2 +++ ext/standard/array.c 5 Jul 2006 08:42:00 -0000 @@ -1536,45 +1536,81 @@ Create an array containing num elements starting with index start_key each initialized to val */ PHP_FUNCTION(array_fill) { - zval **start_key, **num, **val, *newval; + zval **key_data, **num, **val, **entry; long i; + HashPosition pos; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &start_key, &num, &val) == FAILURE) { + if ((ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &key_data, &num, &val) == FAILURE) && + (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &key_data, &val) == FAILURE)) { WRONG_PARAM_COUNT; } - switch (Z_TYPE_PP(start_key)) { - case IS_STRING: - case IS_LONG: - case IS_DOUBLE: - /* allocate an array for return */ - array_init(return_value); - - if (PZVAL_IS_REF(*val)) { - SEPARATE_ZVAL(val); - } - convert_to_long_ex(start_key); - zval_add_ref(val); - zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(start_key), val, sizeof(val), NULL); - break; - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong data type for start key"); + if (ZEND_NUM_ARGS() == 2) { + if (Z_TYPE_PP(key_data) != IS_ARRAY) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "First parameter must be an array when passing 2 parameters"); RETURN_FALSE; - break; - } + } + } else { + switch (Z_TYPE_PP(key_data)) { + case IS_LONG: + case IS_STRING: + case IS_DOUBLE: + convert_to_long_ex(num); + + i = Z_LVAL_PP(num) - 1; + if (i < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements must be positive"); + RETURN_FALSE; + } - convert_to_long_ex(num); - i = Z_LVAL_PP(num) - 1; - if (i < 0) { - zend_hash_destroy(Z_ARRVAL_P(return_value)); - efree(Z_ARRVAL_P(return_value)); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements must be positive"); - RETURN_FALSE; + convert_to_long_ex(key_data); + break; + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong data type for start key"); + RETURN_FALSE; + break; + } } - newval = *val; - while (i--) { - zval_add_ref(&newval); - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &newval, sizeof(zval *), NULL); + + /* Initialize return array */ + array_init(return_value); + + if (PZVAL_IS_REF(*val)) { + SEPARATE_ZVAL(val); + } + + + if (Z_TYPE_PP(key_data) == IS_LONG) { + zval_add_ref(val); + zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(key_data), val, sizeof(zval *), NULL); + + while (i--) { + zval_add_ref(val); + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), val, sizeof(zval *), NULL); + } + } else { + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(key_data), &pos); + + while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(key_data), (void **)&entry, &pos) == SUCCESS) { + zval_add_ref(val); + + if (Z_TYPE_PP(entry) == IS_STRING) { + zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, val, sizeof(zval *), NULL); + } else if (Z_TYPE_PP(entry) == IS_LONG) { + zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), val, sizeof(zval *), NULL); + } else { + zval tmpkey; + + tmpkey = **entry; + zval_copy_ctor(&tmpkey); + convert_to_string(&tmpkey); + + zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL(tmpkey), Z_STRLEN(tmpkey) + 1, val, sizeof(zval *), NULL); + + zval_dtor(&tmpkey); + } + zend_hash_move_forward_ex(Z_ARRVAL_PP(key_data), &pos); + } } } /* }}} */
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php