Re: cvs: php4 /ext/standard array.c basic_functions.c php_array.h
| From: | rasmus at lerdorf dot on dot ca | Date: | Mon, 22 Oct 2001 18:52:26 +0000 |
| Subject: | Re: cvs: php4 /ext/standard array.c basic_functions.c php_array.h | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-7932@lists.php.net to get a copy of this message | ||
> On Mon, 22 Oct 2001, Rasmus Lerdorf wrote:
> > Hrm. Code snippet? Do I need to build this zval myself or this there a
> > convenience function for this one?
>
> Just do zval_add_ref() on the zval** you get from user as the init
> value.
Ok, is_ref is 0 (well, I don't check, but it is on my test), I up the
refcount, but it still isn't right.
PHP_FUNCTION(array_init)
{
zval **start_key, **num, **val, *newval;
int i;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &start_key, &num, &val) ==
FAILURE) {
WRONG_PARAM_COUNT;
}
/* allocate an array for return */
if (array_init(return_value) == FAILURE) {
RETURN_FALSE;
}
switch(Z_TYPE_PP(start_key)) {
case IS_STRING:
case IS_LONG:
case IS_DOUBLE:
convert_to_long_ex(start_key);
newval = *val;
zval_add_ref(&newval);
add_index_zval(return_value, Z_LVAL_PP(start_key), newval);
break;
default:
php_error(E_WARNING, "Wrong datatype for start key in array_init()");
RETURN_FALSE;
break;
}
convert_to_long_ex(num);
i = Z_LVAL_PP(num) - 1;
if(i<0) {
php_error(E_WARNING, "Number of elements must be positive in array_init()");
RETURN_FALSE;
}
while(i--) {
newval = *val;
zval_add_ref(&newval);
add_next_index_zval(return_value, newval);
}
}