Re: Segfault problem with --enable-maintainer-zts

From: Date: Sun, 05 Apr 2009 16:25:11 +0000
Subject: Re: Segfault problem with --enable-maintainer-zts
References: 1 2 3  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-6296@lists.php.net to get a copy of this message
Hi Cesar, Op 5 apr 2009, om 17:48 heeft Cesar D. Rodas het volgende geschreven:
Hello, 2009/4/5 Bas van Beek <bas@tobin.nl>:
In your PHP_MINIT_FUNCTION() add a line similar to this: #ifdef ZTS ts_allocate_id(
       &textcat_globals_id,
       sizeof(textcat_globals),
       (ts_allocate_ctor)textcat_globals_ctor,
       (ts_allocate_dtor)textcat_globals_dtor
); #else
       textcat_globals_ctor(&textcat_globals TSRMLS_CC);
#endif
I've tried but didn't work this part when I compiled on ZTS, but works in this way ZEND_INIT_MODULE_GLOBALS(textcat, _constructor_functions , NULL);
Yes ZEND_INIT_MODULE_GLOBALS does basically the same (as it's a macro to ts_allocate_id) I made the mistake of doing sizeof(textcat_globals) instead of sizeof(zend_textcat_globals) in my example to you. If you are using a dtor function to shut down items in your global struct you will still need to call the dtor function in non ZTS mode in your PHP_MSHUTDOWN_FUNCTION
In your PHP_MSHUTDOWN_FUNCTION() add a line similar to this: #ifndef ZTS
       textcat_globals_dtor(&textcat_globals TSRMLS_CC);
#endif If you need additional construction and destruction of globals items use functions like these: static void textcat_global_ctor(zend_textcat_globals* textcat_globals TSRMLS_DC) {
       /* the struct is already allocated... you can setup and/or allocate
items in the struct */
       textcat_globals->mystringitem = emalloc(MYSTRINGSIZE);
       textcat_globals->threshold = ....
} static void textcat_global_dtor(zend_textcat_globals* textcat_globals TSRMLS_DC) {
       /* if items within the struct need to be freed, do it here... */
       efree(textcat_globals->mystringitem);
} The ts_allocate_id() function takes care of allocating and freeing global structs per thread and calling the ctor and dtor functions. In non ZTS mode you need to call the ctor and dtor functions in the MINIT and MSHUTDOWN functions yourself. If you don't need to setup or take down items in the structs you can forget about the ctor and dtor functions and pass NULL to arguments 3 and 4 of ts_allocate_id() kind regards, Bas van Beek
--Cesar D. Rodas http://cesar.la/ Phone: +595-961-974165 Phyllis Diller - "If it weren't for baseball, many kids wouldn't know what a millionaire looked like." -- PECL development discussion Mailing List (http://pecl.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


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