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

From: Date: Mon, 22 Oct 2001 19:28:24 +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-7936@lists.php.net to get a copy of this message
> Get rid of newval. Just do: > > zval_add_ref(val); > add_index_zval(return_value, Z_LVAL_PP(start_key), val); Shouldn't really make a difference, but you are right, I can get rid of newval. > If that doesn't work, use direct zend_hash_index_update() call. Well, I don't understand why what I had isn't working. My first attempt was to just do a newval=*val; newval->refcount++; and then the insert. I was playing with this yesterday as well but it kept segfaulting on me, so I went with the copy approach. I should have invetigated further. Looking at it closer now, I see that it works as long as I don't try to add more than 65535 elements to the array. My test script was adding 100000 elements by default and it kept dumping on me. Is there s short somewhere in the equation here? The next_index stuff is using 4-byte ints, so it isn't that. Here is the current code. PHP_FUNCTION(array_init) { zval **start_key, **num, **val, *newval; long 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); 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(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--) { zval_add_ref(val); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), val, sizeof(val), NULL); } }

« previous php.cvs (#7936) next »