Andi,

Why so? It doesn't affect any compatibility.

Yes it does, and more particularly it prevents any fix for the win32/ZTS issue until people upgrade to the new module API. If everyone has to add an extra #ifdef into MSHUTDOWN to get around the new situation, but then has to take it away again 2 versions later... bleh... it's all wrong :)

Sara said earlier on IRC that it would be good to make the win32/ZTS thing a separate issue. I think so too.

Attached are patches for fixing the win32/ZTS thing only when needed - this will _only_ work if you apply Dmitry's patch to 5_2 as well. The idea being that this way everybody's covered.

It's similar for 5_1, except that it doesn't need the check for Dmitry's changes.

I don't think we'll need my input for HEAD. As someone said earlier, people will make changes for PHP 6.0 that they might not be ready or willing to make for PHP 5.*. A good suggestion Sara came out with for PECL (this was also on IRC) was to have some version check and offer up different #ext.c files accordingly. At present we don't have that option, but we will if the module API number is bumped following Dmitry's changes.

I still don't like it - but I'm quite good at smelling the way the goldfish are swimming :-\

- Steph


At 02:31 PM 6/8/2006, Ilia Alshanetsky wrote:
The patch is good, but I think this change maybe a bit too extreme
for PHP 5.2


On 8-Jun-06, at 8:15 AM, Dmitry Stogov wrote:

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.
<zts_globals-2.diff.txt>

Ilia Alshanetsky




--
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


Index: Zend/zend_API.c
===================================================================
RCS file: /repository/ZendEngine2/zend_API.c,v
retrieving revision 1.296.2.27.2.17
diff -u -r1.296.2.27.2.17 zend_API.c
--- Zend/zend_API.c     7 Jun 2006 09:43:54 -0000       1.296.2.27.2.17
+++ Zend/zend_API.c     8 Jun 2006 23:10:25 -0000
@@ -32,6 +32,7 @@

/* these variables are true statics/globals, and have to be mutex'ed on every 
access */
static int module_count=0;
+static int dl_module_count=0;
ZEND_API HashTable module_registry;

/* this function doesn't check for too many parameters */
@@ -1888,7 +1889,16 @@

#if HAVE_LIBDL || defined(HAVE_MACH_O_DYLD_H)
#if !(defined(NETWARE) && defined(APACHE_1_BUILD))
+
        if (module->handle) {
+#ifdef ZTS
+               if (!module->globals_id_ptr) {
+                       int table_size;
+
+                       table_size = tsrm_table_size() + 1;
+                       ts_free_id(table_size - zend_dl_module_count());
+               }
+#endif
                DL_UNLOAD(module->handle);
        }
#endif
@@ -1936,6 +1946,12 @@
        return ++module_count;
}

+/* return the dl module count */
+int zend_dl_module_count(void)
+{
+       return ++dl_module_count;
+}
+
static zend_class_entry *do_register_internal_class(zend_class_entry 
*orig_class_entry, zend_uint ce_flags TSRMLS_DC)
{
        zend_class_entry *class_entry = malloc(sizeof(zend_class_entry));
Index: Zend/zend_API.h
===================================================================
RCS file: /repository/ZendEngine2/zend_API.h,v
retrieving revision 1.207.2.8.2.3
diff -u -r1.207.2.8.2.3 zend_API.h
--- Zend/zend_API.h     7 Jun 2006 09:43:54 -0000       1.207.2.8.2.3
+++ Zend/zend_API.h     8 Jun 2006 22:31:07 -0000
@@ -160,6 +160,7 @@
#endif

int zend_next_free_module(void);
+int zend_dl_module_count(void);

BEGIN_EXTERN_C()
ZEND_API int zend_get_parameters(int ht, int param_count, ...);
Index: TSRM/TSRM.c
===================================================================
RCS file: /repository/TSRM/TSRM.c,v
retrieving revision 1.68.2.3
diff -u -r1.68.2.3 TSRM.c
--- TSRM/TSRM.c 14 Mar 2006 15:16:07 -0000      1.68.2.3
+++ TSRM/TSRM.c 8 Jun 2006 22:38:44 -0000
@@ -542,7 +542,7 @@

                        while (p) {
                                if (p->count > j && p->storage[j]) {
-                                       if (resource_types_table && 
resource_types_table[j].dtor) {
+                                       if (resource_types_table && 
resource_types_table[j].dtor && !resource_types_table[j].done) {
                                                
resource_types_table[j].dtor(p->storage[j], &p->storage);
                                        }
                                        free(p->storage[j]);
@@ -587,6 +587,13 @@
}


+/* Obtain the current resource table size */
+TSRM_API int tsrm_table_size(void)
+{
+       return id_count;
+}
+
+
/* Allocate a mutex */
TSRM_API MUTEX_T tsrm_mutex_alloc(void)
{
Index: TSRM/TSRM.h
===================================================================
RCS file: /repository/TSRM/TSRM.h,v
retrieving revision 1.50.2.2
diff -u -r1.50.2.2 TSRM.h
--- TSRM/TSRM.h 14 Mar 2006 15:16:07 -0000      1.50.2.2
+++ TSRM/TSRM.h 8 Jun 2006 22:10:43 -0000
@@ -127,6 +127,7 @@

/* utility functions */
TSRM_API THREAD_T tsrm_thread_id(void);
+TSRM_API int tsrm_table_size(void);
TSRM_API MUTEX_T tsrm_mutex_alloc(void);
TSRM_API void tsrm_mutex_free(MUTEX_T mutexp);
TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp);

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

Reply via email to