Sharing resources between modules

From: Date: Sat, 19 Apr 2003 07:20:34 +0000
Subject: Sharing resources between modules
Groups: php.internals 
Request: Send a blank email to internals+get-970@lists.php.net to get a copy of this message
Hi guys, a quick question: Is it possible for one module to retrieve the resource structure registered by another module? For instance, assume that we have two loaded PHP modules, `php_a.so' and php_b.so'. A script calls a PHP function defined in php_a.so'. That function creates a structure, calls zend_register_resource(), and returns the resource ID. That same script then calls a PHP function defined in `php_b.so' that accepts the resource ID as a parameter. Would it be possible for the function in `php_b.so' to retrieve the structure associated with the resource ID registered in `php_a.so'? My thinking is that something like the following (semi-psudocode) should work: In the `php_a.so' function, which creates the resource: zval *myzvalp; mystruct *mystructp = emalloc(sizeof(mystruct)); MAKE_STD_ZVAL(myzvalp); zend_register_resource(myzvalp, mystructp, "my structure"); RETURN_RESOURCE(myzvalp); In the `php_b.so' function, which retrieves the resource: int res_type; mystruct *mystructp; zval *myzvalp; [ get myzvalp from the parameter list ] res_type = zend_fetch_list_dtor_id("my structure"); mystructp = (mystruct*)zend_fetch_resource(&myzvalp TSRMLS_CC, -1, "my structure", NULL, 1, res_type); if(mystructp) { [ mystructp should be the same as allocated in `php_a.so' ] } However, I see the `TSRMLS_CC' value in the zend_fetch_resource() call and this makes me wonder if zend_fetch_resource() is using something specific to the current module. Also, I'm guessing at the use of the zend_fetch_list_dtor_id() function, so any suggestions about a more appropriate way to do this (or a pointer to code where this is currently being done) would be appreciated. Thanks, Marshall

« previous php.internals (#970) next »