Re: [PECL-DEV] Re: shared memory extention

[email protected] (Geoffrey McRae) Fri, 16 Apr 2010 01:44:05 +1000
Newsgroups php.pecl.dev
Message-ID <[email protected]>
Thanks for the help,

I have another question, hopefully simple...
how do I get the parent zval of a zval that has is_ref set to true?

I have 99% of the code functional now, just need to figure out this
array reference issue.

Or even better yet, is there a way to compare two zval's and see if they
are pointing to the the same data?

-Geoff

On Wed, 2010-04-14 at 14:57 +0200, Johannes Schlüter wrote:
> Hi,
> 
> On Wed, 2010-04-14 at 22:06 +1000, Geoffrey McRae wrote:
> > No Problems, I dont really care what licence it lives under. I am
> > re-working some of its code base to add array support, as for object
> > support, if I can figure out how to serialize the object in the
> > extension then I will do so.
> > 
> > Can I just call __serialize on the object?
> 
> No. (well, yes you could, but it makes little sense as general approach)
> 
> Sample code to serialize a zval:
> 
> #include "ext/standard/smart_str.h"
> #include "ext/standard/php_var.h"
> 
> zval *data; /* data to be serialized */
> php_serialize_data_t var_hash; /* temporary data */
> smart_str buf = {0}; /* result will be stored in there */
> 
> PHP_VAR_SERIALIZE_INIT(var_hash);
> php_var_serialize(&buf, &data, &var_hash TSRMLS_CC);
> PHP_VAR_SERIALIZE_DESTROY(var_hash);
> 
> 
> buf.c then has the data as char*, buf.len the length. In case of a
> problem buf.c will be NULL.
> 
> The var_hash thing is needed as the serializer supports serializing
> different related zvals in sequence. (This was needed for sessions and
> register_globals ...)
> 
> Serializing looks like that:
> 
> unsigned char *data; /* serialized data */
> int data_len; /* length of the serialized data */
> php_unserialize_data_t var_hash;
> 
> PHP_VAR_UNSERIALIZE_INIT(var_hash);
> if (!php_var_unserialize(&return_value, &data, data + data_len, &var_hash TSRMLS_CC)) {
> 	PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
>         /* error handling */
> } else {
> 	PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
> 	/* success, return_value is filled */
> }
> 
> You can also check the implementation of (un)serialize in ext/standard,
> this was from some other code I had at hand right now.
> 
> hope it helps
> 
> johannes
> 
>