OK, so I've got a variable called retVal, which is a pointer to a structure. I'm allocating the variable (using emalloc as recommended by Zend) in the same way I do all over the place, and it always works fine, except in this one function.
When I get to the end of the function in question, I've figured out that retVal is pointing to the same memory location that is used for a zval* I've got!
It took me a while to figure out where the problem was.
I allocate and initialize retVal first, and everything is just fine until I try to initialize the zval* (named theList) using the Zend MAKE_STD_ZVAL() macro. After MAKE_STD_ZVAL() is done, I check the address of retVal and theList, and they are pointing to the same exact address in memory!! Before that, theList was NULL.
here's what's basically happening:
Code: Select all
variant* retVal = NULL;
zval* theList = NULL;
/* emalloc and init the variant */
retVal = new_variant(VT_NULL, NULL);
/* OK, retVal now has a valid address and valid struct members,
* verified by using printf("%p", retVal) or examined in gdb
*
* NOW, allocate the zval
*/
MAKE_STD_ZVAL(theList)
/* theList now points to retVal's memory location! */The worst part is that the address of the zval is supposed to get assigned to a member of the struct pointed to by retVal, so it turns into a real mess.
I could try allocating/initing retVal AFTER doing the zval, but why should I?
Does this look like I've found a bug in Zend, or am I doing something really stupid? I am working with PHP 4.2.3, by the way.