Re: Problem with returning a resource.
| From: | (Uwe Steinmann) | Date: | Wed, 14 Jul 2004 07:00:52 +0000 |
| Subject: | Re: Problem with returning a resource. | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-953@lists.php.net to get a copy of this message | ||
On Wed, Jul 14, 2004 at 02:50:36PM +1000, Gordon Heydon wrote:
> 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,
Ever considered to say "ss|ss" here instead of checking for argc?
> &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)) {
Is your rbo_open() able to handle invalid values for username and
password? Both are not initialized if argc is 2.
> zend_printf("rbo_open(%s,%s) complete\n",account, object);
> ZEND_REGISTER_RESOURCE(rbo, rboobj, rbo_rsrc_id);
How about
ZEND_REGISTER_RESOURCE(return_value, rboobj, rbo_rsrc_id);
I suppose the resource behind rbo_rsrc_id has been registered
with zend_register_list_destructors_ex()
> zend_printf("%ld\n", *rbo);
> zend_printf("rbo_open(%s,%s) register resource\n",account, object);
> RETURN_RESOURCE(rbo);
.. and than you won't need this.
> }
> else {
> zend_printf("rbo_open(%s,%s) failed\n",account, object);
> RETURN_FALSE;
> }
> }
> /* }}} */
>
> --
> Gordon Heydon <gordon@heydon.com.au>
>
> --
> PECL development discussion Mailing List (http://pecl.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
MMK GmbH, Universitaetsstr. 11, 58097 Hagen
Uwe.Steinmann@mmk-hagen.de
Tel: +2331 840446 Fax: +2331 843920