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 Saturday, July 1, 2006, 12:30:48 PM, you wrote: > Index: ext/standard/array.c > =================================================================== > RCS file: /repository/php-src/ext/standard/array.c,v > retrieving revision 1.350 > diff -u -r1.350 array.c > --- ext/standard/array.c 25 Jun 2006 19:19:31 -0000 1.350 > +++ ext/standard/array.c 1 Jul 2006 09:58:26 -0000 > @@ -1625,46 +1625,83 @@ > 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_UNICODE: > - 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_UNICODE: > + 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; > + } > + } > + > + /* Initialize return array */ > + array_init(return_value); > + > + if (PZVAL_IS_REF(*val)) { > + SEPARATE_ZVAL(val); > } > - newval = *val; > - while (i--) { > - zval_add_ref(&newval); > - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), > &newval, sizeof(zval *), NULL); > + > + > + 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 || > + Z_TYPE_PP(entry) == IS_UNICODE) { > + > zend_u_symtable_update(Z_ARRVAL_P(return_value), Z_TYPE_PP(entry), > Z_UNIVAL_PP(entry), Z_UNILEN_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); > + } > } > } > /* }}} */ Best regards, Marcus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php