]> granicus.if.org Git - php/commitdiff
Step 1 in nuking the garbage collector:
authorZeev Suraski <zeev@php.net>
Fri, 9 Jul 1999 17:24:47 +0000 (17:24 +0000)
committerZeev Suraski <zeev@php.net>
Fri, 9 Jul 1999 17:24:47 +0000 (17:24 +0000)
- Change the hash destructor to return int
- Don't kill the bucket on hash_destroy if the destructor returns 0

15 files changed:
Zend/zend.c
Zend/zend_API.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_constants.c
Zend/zend_constants.h
Zend/zend_execute_API.c
Zend/zend_hash.c
Zend/zend_hash.h
Zend/zend_list.c
Zend/zend_list.h
Zend/zend_modules.h
Zend/zend_opcode.c
Zend/zend_variables.c
Zend/zend_variables.h

index 5f4ba6e16c2a7122188ec95ec867507ca41de469..9c2b23b31f704354d1319d8f33250bde952ecc75 100644 (file)
@@ -203,7 +203,7 @@ static void register_standard_class()
        zend_standard_class_def.name = zend_strndup("stdClass", zend_standard_class_def.name_length);
        zend_standard_class_def.parent = NULL;
        zend_hash_init(&zend_standard_class_def.default_properties, 0, NULL, PVAL_PTR_DTOR, 1);
-       zend_hash_init(&zend_standard_class_def.function_table, 0, NULL, (void (*)(void *)) destroy_zend_function, 1);
+       zend_hash_init(&zend_standard_class_def.function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1);
        zend_standard_class_def.handle_function_call = NULL;
        zend_standard_class_def.handle_property_get = NULL;
        zend_standard_class_def.handle_property_set = NULL;
@@ -220,11 +220,11 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals)
        zend_class_entry tmp_class;
 
        compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
-       zend_hash_init(compiler_globals->function_table, 100, NULL, (void (*)(void *)) destroy_zend_function, 1);
+       zend_hash_init(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1);
        zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function));
 
        compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
-       zend_hash_init(compiler_globals->class_table, 10, NULL, (void (*)(void *)) destroy_zend_class, 1);
+       zend_hash_init(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1);
        zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref, &tmp_class, sizeof(zend_class_entry));
 }
 
@@ -303,10 +303,10 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions)
 #endif
        GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
        GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
-       zend_hash_init(GLOBAL_FUNCTION_TABLE, 100, NULL, (void (*)(void *)) destroy_zend_function, 1);
-       zend_hash_init(GLOBAL_CLASS_TABLE, 10, NULL, (void (*)(void *)) destroy_zend_class, 1);
+       zend_hash_init(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1);
+       zend_hash_init(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1);
        register_standard_class();
-       zend_hash_init(&module_registry, 50, NULL, (void (*)(void *)) module_destructor, 1);
+       zend_hash_init(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1);
        zend_hash_init(&list_destructors, 50, NULL, NULL, 1);
 
 #ifdef ZTS
index 6e30d592c7e01c76a7cac18a2541c921d7ed0702..fdda38c1098911ea67e428cb7b1d31c199e5164a 100644 (file)
@@ -767,7 +767,7 @@ ZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry
        class_entry->refcount = (int *) malloc(sizeof(int));
        *class_entry->refcount = 1;
        zend_hash_init(&class_entry->default_properties, 0, NULL, PVAL_PTR_DTOR, 1);
-       zend_hash_init(&class_entry->function_table, 0, NULL, (void (*)(void *)) destroy_zend_function, 1);
+       zend_hash_init(&class_entry->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1);
 
        zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, class_entry, sizeof(zend_class_entry), (void **) &register_class);
        free(lowercase_name);
index 30b0db63abb250e899b1f72793de43d23511b78c..10e4b78c162e2c61118d55ba8b6ecc0125a733f5 100644 (file)
@@ -1219,7 +1219,7 @@ void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_
        
        zend_str_tolower(CG(class_entry).name, CG(class_entry).name_length);
 
-       zend_hash_init(&CG(class_entry).function_table, 10, NULL, (void (*)(void *)) destroy_zend_function, 0);
+       zend_hash_init(&CG(class_entry).function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);
        zend_hash_init(&CG(class_entry).default_properties, 10, NULL, PVAL_PTR_DTOR, 0);
 
        /* code for inheritance from parent class */
index bdbaaafc9acc2a2e2178cdb80091dce983c46905..2568c7662e3392f5bdf97af4f5bcb0caefec4727 100644 (file)
@@ -350,10 +350,13 @@ ZEND_API void zend_close_file_handle(zend_file_handle *file_handle CLS_DC);
 ZEND_API void zend_open_file_dtor(void *f);
 END_EXTERN_C()
 
-ZEND_API void destroy_zend_function(zend_function *function);
-ZEND_API void destroy_zend_class(zend_class_entry *ce);
+ZEND_API int destroy_zend_function(zend_function *function);
+ZEND_API int destroy_zend_class(zend_class_entry *ce);
 void zend_class_add_ref(zend_class_entry *ce);
 
+#define ZEND_FUNCTION_DTOR (int (*)(void *)) destroy_zend_function
+#define ZEND_CLASS_DTOR (int (*)(void *)) destroy_zend_class
+
 zend_op *get_next_op(zend_op_array *op_array CLS_DC);
 int get_next_op_number(zend_op_array *op_array);
 int print_class(zend_class_entry *class_entry);
index a533026f486b5cae0eac972889ed815083e93d57..cce14b8cc79a2581fde9b7e994770d42fb651cf4 100644 (file)
 #include "zend_globals.h"
 
 
-void free_zend_constant(zend_constant *c)
+int free_zend_constant(zend_constant *c)
 {
        if (!(c->flags & CONST_PERSISTENT)) {
                zval_dtor(&c->value);
        }
        free(c->name);
+       return 1;
 }
 
 
@@ -86,7 +87,7 @@ int zend_startup_constants(ELS_D)
 
        EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
 
-       if (zend_hash_init(EG(zend_constants), 20, NULL, (void(*)(void *)) free_zend_constant, 1)==FAILURE) {
+       if (zend_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1)==FAILURE) {
                return FAILURE;
        }
 
index d36ae6ba615eef7ce4530263b94536711d98fff7..efc52fdb2f148e899143c2570f0a06f63cf7415b 100644 (file)
@@ -41,7 +41,7 @@ typedef struct _zend_constant {
 #define REGISTER_MAIN_STRINGL_CONSTANT(name,str,len,flags)  zend_register_stringl_constant((name),sizeof(name),(str),(len),(flags),0 ELS_CC)
 
 void clean_module_constants(int module_number);
-void free_zend_constant(zend_constant *c);
+int free_zend_constant(zend_constant *c);
 int zend_startup_constants(ELS_D);
 int zend_shutdown_constants(ELS_D);
 void clean_non_persistent_constants(void);
@@ -52,4 +52,6 @@ ZEND_API void zend_register_string_constant(char *name, uint name_len, char *str
 ZEND_API void zend_register_stringl_constant(char *name, uint name_len, char *strval, uint strlen, int flags, int module_number ELS_DC);
 ZEND_API void zend_register_constant(zend_constant *c ELS_DC);
 
+#define ZEND_CONSTANT_DTOR (int (*)(void *)) free_zend_constant
+
 #endif
index 9679ff92dd0ce3b0e538ebff14682bc50fb44b30..924b9f32cc3a81c49df9f63938d3dbca566e4a22 100644 (file)
@@ -195,7 +195,7 @@ ZEND_API inline void safe_free_zval_ptr(zval *p)
 }
 
 
-ZEND_API void zval_ptr_dtor(zval **zval_ptr)
+ZEND_API int zval_ptr_dtor(zval **zval_ptr)
 {
 #if DEBUG_ZEND>=2
        printf("Reducing refcount for %x (%x):  %d->%d\n", *zval_ptr, zval_ptr, (*zval_ptr)->refcount, (*zval_ptr)->refcount-1);
@@ -205,6 +205,7 @@ ZEND_API void zval_ptr_dtor(zval **zval_ptr)
                zval_dtor(*zval_ptr);
                safe_free_zval_ptr(*zval_ptr);
        }
+       return 1;
 }
 
 
index 285cc840f8d8ee31ac6ca4071b1de18bbe6bc89b..edb8da272fe8b04239f4e1b1045f01a1e09a3b44 100644 (file)
@@ -71,7 +71,7 @@ ZEND_API ulong hashpjw(char *arKey, uint nKeyLength)
 }
 
 
-ZEND_API int zend_hash_init(HashTable *ht, uint nSize, ulong(*pHashFunction) (char *arKey, uint nKeyLength), void (*pDestructor) (void *pData),int persistent)
+ZEND_API int zend_hash_init(HashTable *ht, uint nSize, ulong(*pHashFunction) (char *arKey, uint nKeyLength), int (*pDestructor) (void *pData),int persistent)
 {
        uint i;
 
@@ -720,6 +720,7 @@ ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLen
 ZEND_API void zend_hash_destroy(HashTable *ht)
 {
        Bucket *p, *q;
+       int delete_bucket;
 
        p = ht->pListHead;
        while (p != NULL) {
@@ -727,13 +728,19 @@ ZEND_API void zend_hash_destroy(HashTable *ht)
                p = p->pListNext;
                if (!q->bIsPointer) {
                        if (ht->pDestructor) {
-                               ht->pDestructor(q->pData);
+                               delete_bucket = ht->pDestructor(q->pData);
+                       } else {
+                               delete_bucket = 1;
                        }
                        if (!q->pDataPtr && q->pData) {
                                pefree(q->pData,ht->persistent);
                        }
+               } else {
+                       delete_bucket = 1;
+               }
+               if (delete_bucket) {
+                       pefree(q,ht->persistent);
                }
-               pefree(q,ht->persistent);
        }
        pefree(ht->arBuckets,ht->persistent);
 }
index fb4d59579d4679d27dd24ef482757741eaa51c74..e6e9a78e27008e44d4e40fc8382ce161eabd784b 100644 (file)
@@ -56,7 +56,7 @@ typedef struct hashtable {
        Bucket *pListHead;
        Bucket *pListTail;
        Bucket **arBuckets;
-       void (*pDestructor) (void *pData);
+       int (*pDestructor) (void *pData);
        unsigned char persistent;
 } HashTable;
 
@@ -64,7 +64,7 @@ typedef struct hashtable {
 BEGIN_EXTERN_C()
 
 /* startup/shutdown */
-ZEND_API int zend_hash_init(HashTable *ht, uint nSize, ulong(*pHashFunction) (char *arKey, uint nKeyLength), void (*pDestructor) (void *pData), int persistent);
+ZEND_API int zend_hash_init(HashTable *ht, uint nSize, ulong(*pHashFunction) (char *arKey, uint nKeyLength), int (*pDestructor) (void *pData), int persistent);
 ZEND_API void zend_hash_destroy(HashTable *ht);
 
 ZEND_API void zend_hash_clean(HashTable *ht);
index 6285c9697059f5062008aefe7430efde6e088016..61a8abf1115b08f3b2da2db8dbd6065d568baba8 100644 (file)
@@ -133,7 +133,7 @@ ZEND_API void *zend_plist_find(int id, int *type)
 }
 
 
-void list_entry_destructor(void *ptr)
+int list_entry_destructor(void *ptr)
 {
        list_entry *le = (list_entry *) ptr;
        list_destructors_entry *ld;
@@ -145,10 +145,11 @@ void list_entry_destructor(void *ptr)
        } else {
                zend_error(E_WARNING,"Unknown list entry type in request shutdown (%d)",le->type);
        }
+       return 1;
 }
 
 
-void plist_entry_destructor(void *ptr)
+int plist_entry_destructor(void *ptr)
 {
        list_entry *le = (list_entry *) ptr;
        list_destructors_entry *ld;
@@ -160,6 +161,7 @@ void plist_entry_destructor(void *ptr)
        } else {
                zend_error(E_WARNING,"Unknown persistent list entry type in module shutdown (%d)",le->type);
        }
+       return 1;
 }
 
 
index 2e1dfc94abe39979fcffc01c22d9cffc93e3df94..681cbf1a4938120e364964fe1d445fb9ae00b7dc 100644 (file)
@@ -42,8 +42,8 @@ enum list_entry_type {
        LE_DB=1000
 };
 
-void list_entry_destructor(void *ptr);
-void plist_entry_destructor(void *ptr);
+int list_entry_destructor(void *ptr);
+int plist_entry_destructor(void *ptr);
 
 int clean_module_resource_destructors(list_destructors_entry *ld, int *module_number);
 int init_resource_list(ELS_D);
index 8609e797747f2981baaa5a0043a474fc96de7444..6d6b34ff44c9bb602bc0d652c45c770f83bca586 100644 (file)
@@ -52,4 +52,5 @@ extern void module_destructor(zend_module_entry *module);
 extern int module_registry_cleanup(zend_module_entry *module);
 extern int module_registry_request_startup(zend_module_entry *module);
 
+#define ZEND_MODULE_DTOR (int (*)(void *)) module_destructor
 #endif
index 96ff8687dcb0369584035f284632f12d4022a933..ba351af1a7f71e2d2f3fe6f879585b3065d7971c 100644 (file)
@@ -99,7 +99,7 @@ void init_op_array(zend_op_array *op_array, int initial_ops_size)
 }
 
 
-ZEND_API void destroy_zend_function(zend_function *function)
+ZEND_API int destroy_zend_function(zend_function *function)
 {
        switch (function->type) {
                case ZEND_USER_FUNCTION:
@@ -109,13 +109,14 @@ ZEND_API void destroy_zend_function(zend_function *function)
                        /* do nothing */
                        break;
        }
+       return 1;
 }
 
 
-ZEND_API void destroy_zend_class(zend_class_entry *ce)
+ZEND_API int destroy_zend_class(zend_class_entry *ce)
 {
        if (--(*ce->refcount)>0) {
-               return;
+               return 1;
        }
        switch (ce->type) {
                case ZEND_USER_CLASS:
@@ -131,6 +132,7 @@ ZEND_API void destroy_zend_class(zend_class_entry *ce)
                        zend_hash_destroy(&ce->default_properties);
                        break;
        }
+       return 1;
 }
 
 
index a4365435d7207a75cae21d6b56f812f9bb8fd947..26ba3dbbafd25c9c41c2d0cffc9fff3d4ca97564 100644 (file)
@@ -47,7 +47,7 @@ ZEND_API inline void var_uninit(zval *var)
 }
                
 
-ZEND_API void zval_dtor(zval *zvalue)
+ZEND_API int zval_dtor(zval *zvalue)
 {
        if (zvalue->type==IS_LONG) {
                return;
index c72990d7f5d3a7b83461bbe6679e1c58ed7ae9e5..2b276f3a59e84e0d722dc9cd805b276dfdbafd49 100644 (file)
@@ -22,14 +22,14 @@ ZEND_API int zend_print_variable(zval *var);
 
 BEGIN_EXTERN_C()
 ZEND_API int zval_copy_ctor(zval *zvalue);
-ZEND_API void zval_dtor(zval *zvalue);
+ZEND_API int zval_dtor(zval *zvalue);
 END_EXTERN_C()
 
-ZEND_API void zval_ptr_dtor(zval **zval_ptr);
+ZEND_API int zval_ptr_dtor(zval **zval_ptr);
 void zval_add_ref(zval **p);
 
-#define PVAL_DESTRUCTOR (void (*)(void *)) zval_dtor
-#define PVAL_PTR_DTOR (void (*)(void *)) zval_ptr_dtor
+#define PVAL_DESTRUCTOR (int (*)(void *)) zval_dtor
+#define PVAL_PTR_DTOR (int (*)(void *)) zval_ptr_dtor
 #define PVAL_COPY_CTOR (void (*)(void *)) zval_copy_ctor
 
 ZEND_API void var_reset(zval *var);