Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Wez Furlong

On 2001-05-12 13:45:25, "Andi Gutmans" <[EMAIL PROTECTED]> wrote:
> At 11:50 AM 5/12/2001 +0100, Wez Furlong wrote:
> >I would like to see an add_assoc_zval() macro to complement
> There is an add_assoc_zval() function.

Doh!
I wonder why I didn't see it before...

--Wez.


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Andi Gutmans

At 11:50 AM 5/12/2001 +0100, Wez Furlong wrote:
>Hi,
>
>I would like to see an add_assoc_zval() macro to complement the other add_
>functions.

There is an add_assoc_zval() function.

Andi


>Just thought that I would throw that in while there are a couple of threads
>in the Zend API... :-)
>
>--Wez.


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Wez Furlong

Hi,

I would like to see an add_assoc_zval() macro to complement the other add_
functions.

Just thought that I would throw that in while there are a couple of threads
in the Zend API... :-)

--Wez.


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Zeev Suraski

At 14:39 12/5/2001, Andi Gutmans wrote:
>By the way, another thing. You don't have to do the zval_copy_ctor() == 
>SUCCESS either. I guess it is more correct but we don't do it anywhere in 
>our code and if it ever happens we're screwed anyway. It could probably 
>return void but I'd have to go back in time and think why it was done the 
>way it was :)

It can't really fail today, other than failing for out-of-memory, in which 
we bail straight out...

Zeev


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Andi Gutmans

At 11:28 AM 5/12/2001 +0100, Wez Furlong wrote:
>On 2001-05-12 10:12:14, "Andi Gutmans" <[EMAIL PROTECTED]> wrote:
> > The code is almost OK. The only problem is that the reference count and
>
> > is_ref from rfcbuf->headers are also copied to *headers. So what you
>should
> > be doing (if you only add it once to the return_value) is to do
> > INIT_PZVAL(headers) before the hash_update so that they are reset to
> > refcount=1 is_ref=0.
>
>Like this?
>
>zval * headers;
>
>MAKE_STD_ZVAL(headers);
>*headers = *rfcbuf->headers;
>INIT_PZVAL(headers);
>if (zval_copy_ctor(headers) == SUCCESS)  {
> zend_hash_update(HASH_OF(return_value), "headers",
> sizeof("headers"), &headers, sizeof(headers)
> NULL);
>}

Yep that's good.
By the way, another thing. You don't have to do the zval_copy_ctor() == 
SUCCESS either. I guess it is more correct but we don't do it anywhere in 
our code and if it ever happens we're screwed anyway. It could probably 
return void but I'd have to go back in time and think why it was done the 
way it was :)

Andi


> > And by the way, zval_copy_ctor does recursive copy constructing so your
>
> > code is OK.
>
>Great; that's a relief :-)
>
>Thanks!
>
>--Wez.


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Wez Furlong

On 2001-05-12 10:12:14, "Andi Gutmans" <[EMAIL PROTECTED]> wrote:
> The code is almost OK. The only problem is that the reference count and

> is_ref from rfcbuf->headers are also copied to *headers. So what you
should 
> be doing (if you only add it once to the return_value) is to do 
> INIT_PZVAL(headers) before the hash_update so that they are reset to 
> refcount=1 is_ref=0.

Like this?

zval * headers;

MAKE_STD_ZVAL(headers);
*headers = *rfcbuf->headers;
INIT_PZVAL(headers);
if (zval_copy_ctor(headers) == SUCCESS)  {
zend_hash_update(HASH_OF(return_value), "headers",
sizeof("headers"), &headers, sizeof(headers)
NULL);
}

> And by the way, zval_copy_ctor does recursive copy constructing so your

> code is OK.

Great; that's a relief :-)

Thanks!

--Wez.




-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Wez Furlong

On 2001-05-12 04:29:19, "Jason Greene" <[EMAIL PROTECTED]> wrote:
> zval_copy_ctor used on an array makes a reference copy of the array.
> Basically, it just copies all the data items in the hashtable and then
adds one to the 
> reference count for all data items. 
> 
> Looking at the code, it appears to not recursively copy into nested
arrays.
> (Could be part of your problem)
> Since this is a reference copy, you can not free the memory used by 
> the array you are copying. I am assuming that this is the cause of your
default.

Strange stuff.
Is there a nice handy API to copy the array completely?
I switched to zval_copy_ctor from a manually maintained hash table and
copying loop for readability; it's a shame to have to switch back.

I'll dig a bit more; I've just thought of another piece of code that might
be the culprit...

--Wez.


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-12 Thread Andi Gutmans

At 02:42 AM 5/12/2001 +0100, Wez Furlong wrote:
>Hi,
>
>In my mailparse extension I am building up an array to contain the headers
>while parsing the message.  The array is held in a zval in the internal C
>structure, one for each message part.
>
>When the "user space" code requests info for a particular message part it
>is returned as an assoc. array. One of the keys contains the headers;
>
>eg:
>
>$info => array(
>"content-type" => "text/plain",
>"headers" => array(
>"to" => "[EMAIL PROTECTED]",
>"from" => [EMAIL PROTECTED]"
>)
>);
>
>So far, to do this I am using this code:
>
>zval * headers;
>
>MAKE_STD_ZVAL(headers);
>*headers = *rfcbuf->headers;
>if (zval_copy_ctor(headers) == SUCCESS)  {
>zend_hash_update(HASH_OF(return_value), "headers",
>strlen("headers") + 1, &headers, sizeof(headers)
>NULL);
>}
>
>where rfcbuf->headers is a "zval *" created using MAKE_STD_ZVAL and
>array_init.
>
>It seems to work OK.
>
>Is it correct?  The ZendAPI docs aren't 100% clear about using the copy
>constructor, and I am experiencing intermittent segfaults in a specific
>part of my "application" that uses this code.

The code is almost OK. The only problem is that the reference count and 
is_ref from rfcbuf->headers are also copied to *headers. So what you should 
be doing (if you only add it once to the return_value) is to do 
INIT_PZVAL(headers) before the hash_update so that they are reset to 
refcount=1 is_ref=0.
Also a small tip, use sizeof("headers") instead of strlen("headers")+1. It 
is much faster as it is evaluated at compile-time.
And by the way, zval_copy_ctor does recursive copy constructing so your 
code is OK.

Andi


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-11 Thread Jason Greene

Sorry,
default=segfault
spellcheck got me 

-Jason
- Original Message - 
From: "Jason Greene" <[EMAIL PROTECTED]>
To: "Wez Furlong" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, May 11, 2001 10:29 PM
Subject: Re: [PHP-DEV] zval_copy_ctor


> zval_copy_ctor used on an array makes a reference copy of the array.
> Basically, it just copies all the data items in the hashtable and then adds one to 
>the 
> reference count for all data items. 
> 
> Looking at the code, it appears to not recursively copy into nested arrays.
> (Could be part of your problem)
> Since this is a reference copy, you can not free the memory used by 
> the array you are copying. I am assuming that this is the cause of your default.
> 
> -Jason
> 
> 
> 
> - Original Message - 
> From: "Wez Furlong" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, May 11, 2001 8:42 PM
> Subject: [PHP-DEV] zval_copy_ctor
> 
> 
> > Hi,
> > 
> > In my mailparse extension I am building up an array to contain the headers
> > while parsing the message.  The array is held in a zval in the internal C
> > structure, one for each message part.
> > 
> > When the "user space" code requests info for a particular message part it
> > is returned as an assoc. array. One of the keys contains the headers;
> > 
> > eg:
> > 
> > $info => array(
> >"content-type" => "text/plain",
> >"headers" => array(
> >"to" => "[EMAIL PROTECTED]",
> >"from" => [EMAIL PROTECTED]"
> >)
> > );
> > 
> > So far, to do this I am using this code:
> > 
> > zval * headers;
> > 
> > MAKE_STD_ZVAL(headers);
> > *headers = *rfcbuf->headers;
> > if (zval_copy_ctor(headers) == SUCCESS)  {
> >zend_hash_update(HASH_OF(return_value), "headers",
> >strlen("headers") + 1, &headers, sizeof(headers)
> >NULL);
> > }
> > 
> > where rfcbuf->headers is a "zval *" created using MAKE_STD_ZVAL and
> > array_init.
> > 
> > It seems to work OK.
> > 
> > Is it correct?  The ZendAPI docs aren't 100% clear about using the copy
> > constructor, and I am experiencing intermittent segfaults in a specific
> > part of my "application" that uses this code.
> > 
> > --Wez.
> > 
> > 
> > 
> > -- 
> > PHP Development Mailing List <http://www.php.net/>
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> > 
> 


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] zval_copy_ctor

2001-05-11 Thread Jason Greene

zval_copy_ctor used on an array makes a reference copy of the array.
Basically, it just copies all the data items in the hashtable and then adds one to the 
reference count for all data items. 

Looking at the code, it appears to not recursively copy into nested arrays.
(Could be part of your problem)
Since this is a reference copy, you can not free the memory used by 
the array you are copying. I am assuming that this is the cause of your default.

-Jason



- Original Message - 
From: "Wez Furlong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, May 11, 2001 8:42 PM
Subject: [PHP-DEV] zval_copy_ctor


> Hi,
> 
> In my mailparse extension I am building up an array to contain the headers
> while parsing the message.  The array is held in a zval in the internal C
> structure, one for each message part.
> 
> When the "user space" code requests info for a particular message part it
> is returned as an assoc. array. One of the keys contains the headers;
> 
> eg:
> 
> $info => array(
>"content-type" => "text/plain",
>"headers" => array(
>"to" => "[EMAIL PROTECTED]",
>"from" => [EMAIL PROTECTED]"
>)
> );
> 
> So far, to do this I am using this code:
> 
> zval * headers;
> 
> MAKE_STD_ZVAL(headers);
> *headers = *rfcbuf->headers;
> if (zval_copy_ctor(headers) == SUCCESS)  {
>zend_hash_update(HASH_OF(return_value), "headers",
>strlen("headers") + 1, &headers, sizeof(headers)
>NULL);
> }
> 
> where rfcbuf->headers is a "zval *" created using MAKE_STD_ZVAL and
> array_init.
> 
> It seems to work OK.
> 
> Is it correct?  The ZendAPI docs aren't 100% clear about using the copy
> constructor, and I am experiencing intermittent segfaults in a specific
> part of my "application" that uses this code.
> 
> --Wez.
> 
> 
> 
> -- 
> PHP Development Mailing List 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]