Re: cvs: php4 /ext/standard array.c basic_functions.c php_array.h

From: Date: Mon, 22 Oct 2001 19:04:48 +0000
Subject: Re: cvs: php4 /ext/standard array.c basic_functions.c php_array.h
References: 1 2  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-7934@lists.php.net to get a copy of this message
On Mon, 22 Oct 2001, rasmus@lerdorf.on.ca wrote: > 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); Get rid of newval. Just do: zval_add_ref(val); add_index_zval(return_value, Z_LVAL_PP(start_key), val); If that doesn't work, use direct zend_hash_index_update() call. > 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); > } > } > -Andrei "The galaxy is, in other words, an immensely, intrinsically, and inexhaustibly interesting place." -- Iain M. Banks

« previous php.cvs (#7934) next »