Re: Re: ZEND_UPDATE_RESOURCE() macro please

From: Date: Sun, 16 Jul 2000 16:27:46 +0000
Subject: Re: Re: ZEND_UPDATE_RESOURCE() macro please
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-24671@lists.php.net to get a copy of this message
Think of a backend library which uses a linked list to iterate through a result set. To write a PHP function in line with our various other result set fetching functions it would need to look something like: PHP_FUNCTION(fetch_value) { zval **result; res *res_pointer; if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &result)==FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(res_pointer, res *, result, -1, "My Resource", le_myres); array_init(return_value); add_assoc_string(return_value,"blah",res_pointer->value,1); res_pointer = next_resource(res_pointer); ZEND_UPDATE_RESOURCE(res_pointer,le_myres); } ie. calling fetch_value() will return res_pointer->value and move the result pointer to the next pointer in the result set. And in the backend, the next_resource() function looks something like this: void next_resource(res *res_pointer) { res *next, *tmp; tmp = res_pointer; next = tmp->next; free(tmp); return(next); } ie. walking through the result set frees as we go. The destructor function in PHP would only need to free from the current result pointer and onwards, so although I suppose I could use a res **, then I would have to keep track of which elements I had visited and thus which ones had gotten freed on me. -Rasmus On Sun, 16 Jul 2000, Zeev Suraski wrote: > How does it make sense? > > Zeev > > At 12:50 16-07-00, Rasmus Lerdorf wrote: > >I need to update the pointer a resource identifier is pointing to without > >destroying or recreating the resource. I don't see a macro for doing > >that. > > > >-Rasmus > > -- > Zeev Suraski <zeev@zend.com> http://www.zend.com/ > > >

« previous php.dev (#24671) next »