Re: [PHP4BETA] Extending PHP, Zend API
| From: | Paul S. Gumerman | Date: | Tue, 07 Mar 2000 17:22:27 +0000 |
| Subject: | Re: [PHP4BETA] Extending PHP, Zend API | ||
| References: | 1 2 3 4 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-11693@lists.php.net to get a copy of this message | ||
Andrei,
Whew! I'm surprised that I actually got it right.
Now I think I see what might be happening:
The top-level array is created at global scope and passed by reference to my function,
but I'm either creating the objects that get stuffed into it at the local scope, or
I'mfailing to set some needed refcount for them, so that they are destroyed at function
exit, and then again when the parent array is destroyed at script exit.
Methinks it's a miracle that its working at all now!
My guess is that the problem is only with the sub-arrays (and the objects placed into
them), since all the simple scalars are added via your add_index_xxx() or
add_assoc_xxx() API functions.
What do I need to do to make an array that is created within my extension module
function have global scope (and persistance)?
Here's the current code:
int read_response(zval *response) {
zval *arr;
.
.
.
case LTARRAY:
MAKE_STD_ZVAL(arr);
array_init(arr);
if (read_response(arr) == FAILURE)
return FAILURE;
if (*varname)
zend_hash_update(response->value.ht, varname, strlen(varname) + 1, (void *)
&arr, sizeof(zval *), NULL);
else
zend_hash_next_index_insert(response->value.ht, &arr, sizeof(zval *), NULL);
break;
Once I've got that right, do I need to do anything with the scalar objects I put in it
to make them persist until the script exits?
After this, I promise to go away and not bother you for while <g>.
Thanks,
Paul
Andrei Zmievski wrote:
> On Mon, 06 Mar 2000, Paul S. Gumerman wrote:
> > How does one create an array, and add elements to it? (or, perjaps I should say,
> > how does one do it *correctly* <g>)
>
> zval *array;
> MAKE_STD_ZVAL(array);
> array_init(array);
> add_index_long(array, 555);
>
> >
> > Why do the API calls (such as zend_hash_find and zend_hash_update) sometimes
> > want strlen(name) + 1, and other times want strlen(name) ?
>
> strlen(name) + 1 is required because hash functions need to know the
> exact length of the key, including the 0 at the end.
>
> > Since I do have this working, but suspect problems, what's the best procedure for
> > testing for memory leaks or other problems?
>
> Read the error messages and trace them.
>
> > I see various messages in the Apache log from zend_variables.c complaining of
> > overruns and Magic Numbers not being as expected (I assume). What precisely do
> > these messages mean, and how would I go about tracking down the problems?
> >
> > Here's one:
> > ---------------------------------------
> > zend_opcode.c(172) : Block 0x081D2128 status:
> > zend_variables.c(63) : Actual location (location was relayed)
> > Beginning: Overrun (magic=0x00050100, expected=0x7312F8DC)
> > End: Unknown
> > ====================================
>
> This means that the zval of type IS_STRING is being destructed twice.
> It's hard to tell what might be causing it, but maybe it's being
> deallocated automatically because of the reference counting.
>
> -Andrei
>
> "The time from now until the completion
> of the project tends to become constant." -- Douglas Hartree
>
> -------------------------------------------------------------------------
> This email server is running an evaluation copy of the MailShield anti-
> spam software. Please contact your email administrator if you have any
> questions about this message. MailShield product info: www.mailshield.com