Hey Dmitry, all,

Disclaimer: I've had a sneak preview on this one.

I really don't like this going into 5_2 branch, and the more I think about it the less sure I am about it going into HEAD either. It would mean renaming all the ctor/dtor functions to the new globals, which is going to take an awful lot of #ifdef'ing in PECL extensions if they're going to retain compatibility across all the current versions of PHP.

I've spent some time fiddling with this stuff as a result.

In ZTS builds the dtor functions are actually called correctly, at the point when the resource is freed. The original ZTS problem (of how to store the TSRM resource ID in the zend_module_entry struct) is resolvable without going to all those lengths - I have it running locally and can provide a patch when I clean up my source - but would still involve a change to the module API, because that's unavoidable. Just a far less radical change from the perspective of extension authors.

In non-ZTS builds the dtor functions are only called from MSHUTDOWN, and that's a separate issue altogether. I've been toying with the idea of storing a pointer to the dtor (where one exists) in a hashtable keyed on module name and calling it from the module destructor. I've got as far as the module destructor recognising when there's a dtor declared in ZEND_INIT_MODULE_GLOBALS, but the next part's kind of eluding me at present. If you're interested I'll pull together what I have so far and send it over to the experts :)

The 'down' side is that I don't know how much storing extension dtor info in this way would impact startup speed, and I've no way to check. But then again I don't know how storing it in the module struct would impact startup speed either...

- Steph

----- Original Message ----- From: "Dmitry Stogov" <[EMAIL PROTECTED]>
To: <internals@lists.php.net>; "Ilia Alshanetsky" <[EMAIL PROTECTED]>
Cc: "Andi Gutmans" <[EMAIL PROTECTED]>; "Steph" <[EMAIL PROTECTED]>
Sent: Thursday, June 08, 2006 2:15 PM
Subject: [PHP-DEV] [PATCH] Automatic module globals management


Hi,

The attached patch (for PHP_5_2) implements automatic management of module
globals.
The problem that module globals must be unregistered before extension
unloading, because "globls_dtor" function is unloaded together with
extension and cannot be called.

To solve this problem extension writers now use the following pattern:

PHP_MSHUTDOWN_FUNCTION(mod_name)
{
-#ifdef ZTS
- ts_free_id(mod_name_globals_id);
-#else
- mod_name_globals_dtor(&mod_name_globals TSRMLS_CC);
-#endif

With my patch, extension writers should just extend module descriptor with
globals descriptor and ctor/dtor callbacks.

 PHP_RSHUTDOWN(mod_name),
 PHP_MINFO(mod_name),
 NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES
+ NULL,
+ ZEND_MG(mod_name),
+ ZEND_MGCTOR(mod_name),
+ ZEND_MGCTOR(mod_name),
+ STANDARD_MODULE_PROPERTIES_EX2
};

Old extensions are source compatible and may work without modification.
The patch modifies only several extensions, but will modify others too.

I like commit the patch into HEAD and PHP_5_2.
Any objections, additional ideas?

Thanks. Dmitry.


__________ NOD32 1.1380 (20060125) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com




--------------------------------------------------------------------------------


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

__________ NOD32 1.1380 (20060125) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to