Re: Defining custom structs in skeleton
| From: | Andrey Hristov | Date: | Wed, 22 Sep 2004 21:49:20 +0000 |
| Subject: | Re: Defining custom structs in skeleton | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-1374@lists.php.net to get a copy of this message | ||
Yannick Warnier wrote:
Hi, I am currently trying to get a C librabry into a PHP extension but I am having problems when 'making' the auto-generated extension files. I think the problem comes from the way I'm trying to use data types. I followed the steps described in http://talks.php.net/show/extending-php-apachecon2003 to define the functions I'd like to use from the libssh library, create a .def file, use ext_skel, update config.m4, configure... Then "make" gives me plenty of errors like: /tmp/ssh/ssh.c: In function `zif_open_session_channel': /tmp/ssh/ssh.c:232: error: parse error before '?' token /tmp/ssh/ssh.c:232: error: parse error before '?' token It seems like the problem is the special data types definitions in libssh. For example, I want to import this function: SSH_SESSION *ssh_connect(SSH_OPTIONS *options); Which uses SSH_SESSION and SSH_OPTIONS, both being structs defined earlier in the libssh library. And for this error case, I would like to use CHANNEL *open_session_channel(SSH_SESSION *session,int window,int maxpacket); Which also uses SSH_SESSION. The lines around 232 (indicated by >>>) in ssh.c are: PHP_FUNCTION(open_session_channel) {see Derick's talk on creating extensions here : http://www.derickrethans.nl/pres-createext/talk.html I see 3 slides devoted to working with resources. More or less, malloc a variable (in the function you have declared a pointer), register the variable and you get zval. Return this zval to the user. When the user passes back the zval you can check whether it is a resource (IS_RESOURCE or with zend_parse_parameters()) and with the resource you can get back a pointer to the memory previously allocated. Another detail is that you have to provide a pointer to a function which is used by ZE for automatic deallocation (destruction) of the resource, whenever that is needed. This function is usually short and is more or less a cast and efree(). He shows a wrapper of the AALIB(ASCII Art Lib). Hope this helps, Andreyint argc = ZEND_NUM_ARGS(); int session_id = -1; long window; long maxpacket; zval *session = NULL;if (zend_parse_parameters(argc TSRMLS_CC, "rll", &session, &window,&maxpacket) == FAILURE)return;if (session) {ZEND_FETCH_RESOURCE(???, ???, session, session_id, "???",???_rsrc_id); }php_error(E_WARNING, "open_session_channel: not yet implemented");} I couldn't find any doc about this kind of "features" of extension-making, so I didn't even try to declare those data types in my definition file and have used "resource" instead of those SSH_SESSION types. Could someone point me out on some kind of doc or help me with this? is in ssh.c: Obviously I need to understand how custom data types can be defined in my skeleton file, then maybe I will get things right in ssh.c. Thanks, Yannick Hi,