On 07/30/2013 04:03 PM, Johannes Schlüter wrote:
On Tue, 2013-07-30 at 15:37 +0500, Ruslan Osmanov wrote:
So what is the proper way to deal with zend_fcall_info.object_ptr's
refcount? I didn't find a Zend API function to copy fcall info.
I also didn't find a way to obtain the caller's "this_ptr" pointer.
EG(This) points to current (Event) this_ptr, not Foo's this_ptr.
This hit me, too. I once thought about "fixing" this in
zend_parse_parameters but figured this would cause an anomaly where the
caller suddenly has to free memory allocated in zpp.
My solution for this is here:
https://github.com/johannes/php-test-helpers/blob/master/test_helpers.c#L342
and here
https://github.com/johannes/php-test-helpers/blob/master/test_helpers.c#L178
hope this helps,
johannes
Thanks for your reply.
I see, you fixed it by freeing handler->fci before assigning new pointer
to it. It works probably because the only user handler(THG(new_handler)
is moving around.
But in my case fci is created by zend_parse_arguments() ant put into
newly allocated object. Something like the following:
/* ... */
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
php_event_t *e;
struct event *event;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f",
&fci, &fcc) == FAILURE) {
return;
}
e = emalloc(sizeof(struct event));
/* ... */
Z_ADDREF_P(fci.function_name);
if (fci.object_ptr) {
Z_ADDREF_P(fci.object_ptr);
}
if (ZEND_FCI_INITIALIZED(*pfci)) {
e->fci = (zend_fcall_info *) safe_emalloc(1,
sizeof(zend_fcall_info), 0);
e->fcc = (zend_fcall_info_cache *) safe_emalloc(1,
sizeof(zend_fcall_info_cache), 0);
memcpy(e->fci, pfci, sizeof(zend_fcall_info));
memcpy(e->fcc, pfcc, sizeof(zend_fcall_info_cache));
PHP_EVENT_FCI_ADDREF(e->fci);
} else {
e->fci = NULL;
e->fcc = NULL;
}
So I have to search for another workaround.
--
Ruslan Osmanov
--
PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php