Re: Need some help
| From: | Siewn | Date: | Mon, 07 Mar 2005 10:05:34 +0000 |
| Subject: | Re: Need some help | ||
| References: | 1 2 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-2126@lists.php.net to get a copy of this message | ||
Thanks for your answer, I'll try it very soon.
I've just one more question : I've just read this interesting article http://www.zend.com/php/internals/extension-writing1.php and I wonder whether or not I should use pemalloc rather than emalloc for my tree which must be global
Tristan Croiset
val khokhlov wrote:
Hello Siewn, Friday, February 25, 2005, 8:39:43 PM, you wrote: S> But I don't understand how to use this. In the skeleton created by S> ext_skel, there are two places for global variables: S> In the .h, just after ZEND_BEGIN_MODULE_GLOBALS ("declare any global S> variables you may nee")in .h (assuming the ext is named "foo"):ZEND_BEGIN_MODULE_GLOBALS(foo) void *bar; ZEND_END_MODULE_GLOBALS(foo) #ifdef ZTS #define FOOG(v) TSRMG(foo_globals_id, zend_foo_globals *, v) #else #define FOOG(v) (foo_globals.v) #endifin .c:static void php_foo_init_globals(zend_foo_globals *foo_globals) {// init foo_globals here foo_globals->bar = emalloc(...);} PHP_MINIT_FUNCTION(foo) {ZEND_INIT_MODULE_GLOBALS(foo, php_foo_init_globals, php_foo_free_globals); // ^- php_foo_free_globals can be NULL is not used return SUCCESS;} // then you can access you global var using FOOG(bar) S> Or in the .c, just after ZEND_DECLARE_MODULES_GLOBALS ("true global S> ressources - no need for thread safety here") S> Which one I must used to declare my tree ?you see, when you have a threaded environment, all threads canaccess each other vars, so, afaik, declaring globals in the above-mentioned way will add some thread-unique stuff to them, so one thread won't access another's vars.if you don't care of this (for example, forked-environment-onlyextension or some var that is common to all threads), you may use a simple variable (true global). also, if you need some var to be shared across all threads, you certainly shouldn't use module globals for it S> A should I add she TSRMLS_CC after the last argument of all functions S> which use the tree and access the tree with MYEXTENSION_G(the_tree) ?TSRMLS_C and TSRMLS_CC - afaik, yes MYEXTENSION_G(the_tree) - whatever define you use (e.g., FOOG(bar))p.s.: _C is used when a function takes no arguments, _CC is used otherwise void func1() - define as "void func1(TSRMLS_D)", call as "func1(TSRMLS_C)" void func2(params) - define as "void func2(params TSRMLS_DC)", call as "func2(params TSRMLS_CC)" S> And finally, should I malloc all the nodes with malloc or emalloc ?emalloc()S> The second thing is related : S> If I put in PHP_MINIT_FUNCTION: S> and in PHP_MSHUTDOWN_FUNCTION:sorry, i don't know why it happens