Problem with returning a resource.
| From: | Gordon Heydon | Date: | Wed, 14 Jul 2004 04:50:36 +0000 |
| Subject: | Problem with returning a resource. | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-952@lists.php.net to get a copy of this message | ||
Hello,
I am in the process of writting an extension to php, but I have run into
a problem when I try to return a resource back to the php program, php
then segfaults.
I have included below the code that I am triing to get to work, in the
hopes that someone can point and laugh at me while they show me the
mistake that I made.
Thanks in advance.
Gordon.
PHP_FUNCTION(rbo_open)
{
char *account = NULL;
char *object = NULL;
char *username = NULL;
char *password = NULL;
int argc = ZEND_NUM_ARGS();
int account_len;
int object_len;
int username_len;
int password_len;
zval *rbo = NULL;
RBOObj *rboobj = NULL;
if (argc == 4) {
if (zend_parse_parameters(argc TSRMLS_CC, "ssss", &account,
&account_len, &object, &object_len, &username, &username_len, &password,
&password_len) == FAILURE)
return;
}
else if (argc == 2) {
if (zend_parse_parameters(argc TSRMLS_CC, "ss", &account,
&account_len, &object, &object_len) == FAILURE)
return;
}
else {
php_error(E_WARNING, "rbo_open: wrong number of arguments");
RETURN_FALSE;
}
zend_printf("%s %s\n",account, object);
if (rboobj = rbo_open(account, object, username, password)) {
zend_printf("rbo_open(%s,%s) complete\n",account, object);
ZEND_REGISTER_RESOURCE(rbo, rboobj, rbo_rsrc_id);
zend_printf("%ld\n", *rbo);
zend_printf("rbo_open(%s,%s) register resource\n",account, object);
RETURN_RESOURCE(rbo);
}
else {
zend_printf("rbo_open(%s,%s) failed\n",account, object);
RETURN_FALSE;
}
}
/* }}} */
--
Gordon Heydon <gordon@heydon.com.au>