Re: Callling callbacks

From: Date: Mon, 26 Apr 2010 16:32:52 +0000
Subject: Re: Callling callbacks
References: 1 2 3 4  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-7190@lists.php.net to get a copy of this message
On Mon, 26 Apr 2010 11:38:37 +0100, Johannes Schlüter <johannes@schlueters.de> wrote:
On Thu, 2010-04-22 at 20:21 +0100, "Gustavo Lopes" wrote:
So which is it? Accepting the callback as a zval*, increment its refcount and store it and then creating zend_fcall_info(_cache) on each callback execution using zend_fcall_info_init?
See http://github.com/johannes/php-test-helpers/blob/master/test_helpers.c#L218 where I'm registering a callback and http://github.com/johannes/php-test-helpers/blob/master/test_helpers.c#L107 where I call it. http://github.com/johannes/php-test-helpers/blob/master/test_helpers.c#L74 is the cleanup.
Thank you. I did try and had no success increasing the refcounts but instead of function_name and, in 5.3, object_ptr it was function_name and, in 5.2, object_pp (since I was only crashing in 5.3). So I was close :p I ended up implementing the approach above, but it's obviously less efficient: I first call zend_is_callable (which btw has a different signature in 5.2 and 5.3) on the passed zval to validate the callback, increment the refcount of the zval and then use that zval to call zend_fcall_info_init (again, different signature) to create the zend_fcall_info(_cache) on each callback call. The call is executed with zend_call_function. I'll rewrite it when I have the time. People here seem to really hate writing documentation, I've never had to read so much source code to understand an API. And even then there's no consistent way things are done, maybe because there's an excessive number of macros and convenience functions. For instance, I've probably seen a dozen ways object properties are changed, with varying levels of abstraction. Not that I'm complaining, I find it mildly interesting :p -- Gustavo Lopes

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