Re: Help with resources management

From: Date: Mon, 01 Nov 2004 18:06:46 +0000
Subject: Re: Help with resources management
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-1569@lists.php.net to get a copy of this message
Hi Sara, I'll send you the libssh file in another mail. As for your answer and after having answered my own answer on the list, I am seeing this a bit clearer. Now the problem is, as you say, that I need to get my zval back in another function (which is ssh_connect(SSH_OPTIONS options)) and that I'm messing with this. So my code now looks like this: static int le_ssh_options; static int le_ssh_session; ZEND_FUNCTION(ssh_options_new) { SSH_OPTIONS *options; if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; } options = options_new(); ZEND_REGISTER_RESOURCE(return_value, options, le_ssh_options); } ZEND_FUNCTION(ssh_connect) { SSH_SESSION *session; zval *options = NULL; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &options) == FAILURE) { WRONG_PARAM_COUNT; } session = ssh_connect(options); ZEND_REGISTER_RESOURCE(return_value, session, le_ssh_session); } My problems now are: - I don't know if le_ssh_options and le_ssh_session actually need to be declared as static int... - I get a warning for the line session = ssh_connect(options); because the variable is not the type expected: ssh.c:88: warning: passing arg 1 of `ssh_connect' from incompatible pointer type - for the moment I do not have a MINIT function (mainly because I'm first trying to get something out of this module) The second problem is the worst for now, as I'd really want to get an SSH_OPTIONS back from the resource. So I tried casting the resource as a SSH_OPTIONS like this: (SSH_OPTIONS) options; but that caused the same warning. Then I got from http://www.derickrethans.nl/pres-createext/talk.html that fetching resources should be done like this: ZEND_FUNCTION(ssh_connect) { SSH_SESSION *session; int c_id = -1; zval *o = NULL; SSH_OPTIONS *options; if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &o) == FAILURE) { WRONG_PARAM_COUNT; } if (o) { ZEND_FETCH_RESOURCE(options, SSH_OPTIONS *, &o, c_id, "ssh", le_ssh_options); } session = ssh_connect(options); ZEND_REGISTER_RESOURCE(return_value, session, le_ssh_session); } But I have no clue what c_id is (but it seems to work so far). Now I am just into adding more functions to get something to work. Thanks for the help. It was really really helpful. Yannick

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