Re: Is it the right way to pass an argument to callback?
| From: | Ruslan Osmanov | Date: | Thu, 15 Dec 2011 18:06:28 +0000 |
| Subject: | Re: Is it the right way to pass an argument to callback? | ||
| References: | 1 2 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-8975@lists.php.net to get a copy of this message | ||
Johannes Schlüter-2 wrote:
>
> Hi,
>
> On Sun, 2011-11-06 at 20:37 +0500, Ruslan Osmanov wrote:
>> Hello.
>>
>> I wonder if I pass a callback argument here the right way:
>> http://susepaste.org/99481533
>
> I didn't look deep into it, but two comments:
>
> * php_eio_cb_t *cb_data_ptr = emalloc(sizeof(php_eio_cb_t)); -
> this will leak if zend_parse_parameters fails. Better allocate
> later (or efree before return)
> * For callbacks you should use the zend_parse_parameters "f"
> modifier. Grepping for 'if
> (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f' will give
> you some examples and README.PARAMETER_PARSING_API has some
> docs.
>
> johannes
>
>
Hello.
I'm trying to make it parsing callbacks with "f". But zend_fcall_info *
and zend_fcall_info * pointers live within PHP_FUNCTION() only. If I save
them to
an insatnce of struct as
php_eio_cb_t *eio_cb = ecalloc(1, sizeof(php_eio_cb_t));
eio_cb->fci = emalloc(sizeof(zend_fcall_info));
eio_cb->fcc = emalloc(sizeof(zend_fcall_info_cache));
*eio_cb->fci = *fci_ptr;
*eio_cb->fcc = *fcc_ptr;
and put into some
call(..., my_callback, eio_cb);
static void my_callback(data) {
/* data->fci and data->fcc contain garbage */
}
So I merely want to preserve fcall info until my_callback is called.
Tried to get answer on the IRC with no luck.
-----
Regards,
Ruslan Osmanov
Blog: http://osmanov-dev-notes.blogspot.com/
Twitter: @ruslan_osmanov
--
View this message in context: http://old.nabble.com/Is-it-the-right-way-to-pass-an-argument-to-callback--tp32790869p32982928.html
Sent from the Pecl - Dev mailing list archive at Nabble.com.