Re: Re: shared memory extention

From: Date: Thu, 15 Apr 2010 15:44:05 +0000
Subject: Re: Re: shared memory extention
References: 1 2 3 4 5  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-7157@lists.php.net to get a copy of this message
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 > >

« previous php.pecl.dev (#7157) next »