Re: Problem with returning a resource.

From: Date: Thu, 15 Jul 2004 02:30:40 +0000
Subject: Re: Problem with returning a resource.
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-954@lists.php.net to get a copy of this message
Hello, Thanks for the response. On Wed, 2004-07-14 at 17:00, Uwe Steinmann wrote: > 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 ... > > 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? Ah, that would be a lot better, but I didn't know that. > > > &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. Yes they are to top of the subroutine they are being initilised to NULL. > > > 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 tried that, I think the segfault is coming after it returns from my subroutine to php. > I suppose the resource behind rbo_rsrc_id has been registered > with zend_register_list_destructors_ex() Yes, in the module init function. PHP_MINIT_FUNCTION(phprbo) { /* If you have INI entries, uncomment these lines ZEND_INIT_MODULE_GLOBALS(phprbo, php_phprbo_init_globals, NULL); REGISTER_INI_ENTRIES(); */ rbo_rsrc_id = zend_register_list_destructors_ex(phprbo_rboobj_distruction_handler, NULL, rbo_rsrc_name, module_number); rs_rsrc_id = zend_register_list_destructors_ex(phprbo_null_distruction_handler, NULL, rs_rsrc_name, module_number); return SUCCESS; } and here are my subroutine. void phprbo_rboobj_distruction_handler(zend_rsrc_list_entry *rsrc TSRMLS_DC) { RBOObj *rboobj = (RBOObj *)rsrc->ptr; if (rboobj) { rbo_close(rboobj); } } I am not sure where I am going wrong. Thanks for the help. I am most likely made a simple mistake. -- Gordon Heydon <gordon@heydon.com.au>

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