Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5330 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97097 invoked by uid 1010); 10 Nov 2003 02:59:59 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 97073 invoked by uid 1007); 10 Nov 2003 02:59:59 -0000 Message-ID: <20031110025959.97072.qmail@pb1.pair.com> To: internals@lists.php.net Date: Mon, 10 Nov 2003 00:59:46 -0200 User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4.1) Gecko/20031008 X-Accept-Language: en-us, en MIME-Version: 1.0 References: <20031026165338.18992.qmail@pb1.pair.com> In-Reply-To: <20031026165338.18992.qmail@pb1.pair.com> Content-Type: multipart/mixed; boundary="------------020109010809000001030305" X-Posted-By: 200.196.104.198 Subject: Re: internal hashtables [patch included] From: cunha17@uol.com.br (Cristiano Duarte) --------------020109010809000001030305 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Hi all, I guess I found a bug at "zend_compile.c". IMHO when you want to create an internal hashtable, that will be filled with internal zvals (malloc'ed instead of emalloc'ed), you should pass the "internal zval destructor" to the hashtable initialization function. Currently, "zend_compile.c" uses the "default zval destructor" for internal and standard zvals. It leads to some error messages (about efree'ing blocks that weren't emalloc'ed) at the end of execution. Am I right, I mean is this the correct behaviour of an internal hashtable ? Anyway, the patch attached fixes it. Best Regards, Cristiano Duarte --------------020109010809000001030305 Content-Type: text/plain; name="ze2_internal_symtables.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ze2_internal_symtables.patch" ? php-src/ZendEngine1 Index: php-src/Zend/zend_alloc.c =================================================================== RCS file: /repository/ZendEngine2/zend_alloc.c,v retrieving revision 1.129 diff -u -r1.129 zend_alloc.c --- php-src/Zend/zend_alloc.c 17 Oct 2003 02:29:06 -0000 1.129 +++ php-src/Zend/zend_alloc.c 26 Oct 2003 16:57:39 -0000 @@ -477,6 +477,10 @@ zend_uint grand_total_leaks=0; #endif + if (zend_internal_nOfHashTables() > 0) { + zend_gc_destroy_internal_hashtables(); + } + #if defined(ZEND_MM) && !ZEND_DEBUG if (clean_cache) { zend_mm_shutdown(&AG(mm_heap)); Index: php-src/Zend/zend_hash.c =================================================================== RCS file: /repository/ZendEngine2/zend_hash.c,v retrieving revision 1.113 diff -u -r1.113 zend_hash.c --- php-src/Zend/zend_hash.c 29 Aug 2003 07:34:37 -0000 1.113 +++ php-src/Zend/zend_hash.c 26 Oct 2003 16:57:40 -0000 @@ -1313,6 +1313,48 @@ } #endif +struct _internal_hashtables { + HashTable **list; + int nOfHashTables; +}; +struct _internal_hashtables *internal_hashtables = NULL; + +int zend_internal_nOfHashTables() { + return (internal_hashtables == NULL) ? 0 : internal_hashtables->nOfHashTables; +} + +void zend_gc_add_internal_hashtable(HashTable *ht TSRMLS_DC) { + HashTable **ptr; + if (internal_hashtables == NULL) { + internal_hashtables = malloc(sizeof(struct _internal_hashtables)); + internal_hashtables->nOfHashTables = 0; + internal_hashtables->list = NULL; + } + internal_hashtables->list = realloc(internal_hashtables->list, sizeof(HashTable*) * (internal_hashtables->nOfHashTables + 1)); + ptr = internal_hashtables->list; + ptr += internal_hashtables->nOfHashTables; + *ptr = ht; + ++(internal_hashtables->nOfHashTables); +} + +void zend_gc_destroy_internal_hashtables() { + HashTable **ptr; + if (internal_hashtables != NULL) { + ptr = internal_hashtables->list; + if (ptr != NULL) { + int i; + for (i = 0; i < internal_hashtables->nOfHashTables; ++i) { + zend_hash_destroy(*ptr); + ++ptr; + } + free(internal_hashtables->list); + internal_hashtables->list = NULL; + free(internal_hashtables); + internal_hashtables = NULL; + } + } +} + /* * Local variables: * tab-width: 4 Index: php-src/Zend/zend_hash.h =================================================================== RCS file: /repository/ZendEngine2/zend_hash.h,v retrieving revision 1.75 diff -u -r1.75 zend_hash.h --- php-src/Zend/zend_hash.h 25 Sep 2003 15:38:35 -0000 1.75 +++ php-src/Zend/zend_hash.h 26 Oct 2003 16:57:40 -0000 @@ -350,6 +350,14 @@ return zend_hash_exists(ht, arKey, nKeyLength); } +#define ZEND_INIT_INTERNAL_SYMTABLE(ht) \ + ZEND_INIT_SYMTABLE(ht); \ + zend_gc_add_internal_hashtable(ht TSRMLS_CC); + +int zend_internal_nOfHashTables(); +void zend_gc_add_internal_hashtable(HashTable *ht TSRMLS_DC); +void zend_gc_destroy_internal_hashtables(); + #endif /* ZEND_HASH_H */ /* --------------020109010809000001030305--