Re: [PHP4BETA] creating nested arrays from C

From: Date: Tue, 12 Oct 1999 13:17:43 +0000
Subject: Re: [PHP4BETA] creating nested arrays from C
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-5501@lists.php.net to get a copy of this message
Dan Libby wrote: > I've checked my code very closely for memory errors, etc. I do not > believe there to be any. In fact, I created the following very simple > test case which exhibits the same random behavior: > > int i; > pval* array = return_value; > pval* array2; > > array_init(array); > > for (i=0; i < 15; i++) { > array2 = emalloc(sizeof(pval)); > array_init(array2); > add_long(array, "depth", i); > add_string(array2, "hi", "there", 1); > zend_hash_update(array, "sub_array", strlen("sub_array")+1, (void > *) &array2, sizeof(pval *), NULL); > array = array2; > } > return; -- End of excerpt from Dan Libby One of your problems is that you don't initialize the refcount of the value. Instead of: array2 = emalloc(sizeof(pval)); use MAKE_STD_ZVAL(array2) which will take care of it for you. Also the 4th parameter to zend_hash_update() should be (void**)&array2. -Andrei * The future has arrived, it's just not evenly distributed. -W. Gibson *

« previous php.version4 (#5501) next »