Professional Web Applications Themes

[PHP-DEV] internal hashtables [patch included] - PHP Development

At 02:53 PM 10/26/2003 -0200, Cristiano Duarte wrote: >Hi all, > >Just to remind about my problem: >After updating from latest CVS I still had problems with internal >hashtables. I want to make internal class constants and the engine reports >memory leaks. > >So I made this patch wich works for me and removed all memory leaks >regarding hashtables. > >This patch introduces a new macro called ZEND_INIT_INTERNAL_SYMTABLE wich is >to be used instead of ZEND_INIT_SYMTABLE when the hashtables is internal. >That's the only change that should be done in sources that needs internal >hashtables. This doesn't look right. Shouldn't ...

  1. #1

    Default Re: [PHP-DEV] internal hashtables [patch included]

    At 02:53 PM 10/26/2003 -0200, Cristiano Duarte wrote:
    >Hi all,
    >
    >Just to remind about my problem:
    >After updating from latest CVS I still had problems with internal
    >hashtables. I want to make internal class constants and the engine reports
    >memory leaks.
    >
    >So I made this patch wich works for me and removed all memory leaks
    >regarding hashtables.
    >
    >This patch introduces a new macro called ZEND_INIT_INTERNAL_SYMTABLE wich is
    >to be used instead of ZEND_INIT_SYMTABLE when the hashtables is internal.
    >That's the only change that should be done in sources that needs internal
    >hashtables.
    This doesn't look right. Shouldn't you make sure that module shutdown frees
    the hashtables? You can change the dtor if you need.
    I'm sorry but I don't quite understand what made you come up with this
    solution. Maybe I'm missing something.
    Andi

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

    Andi Gutmans Guest

  2. #2

    Default Re: [PHP-DEV] internal hashtables [patch included]

    "Andi Gutmans" <andizend.com> escreveu na mensagem
    news:5.1.0.14.2.20031026213148.03145288127.0.0.1. ..
    > This doesn't look right. Shouldn't you make sure that module shutdown
    frees
    > the hashtables? You can change the dtor if you need.
    > I'm sorry but I don't quite understand what made you come up with this
    > solution. Maybe I'm missing something.
    Shure I can free the hashtable on module shutdown, but since the hashtable
    is inside a class definition(class constants), should I unregister the class
    too ?
    I just put this code because the current symtable only supports userland
    defined class constants.
    What is the good practice in developing PHP extensions ? Free all classes
    defined within an extension at module shutdown ?

    Best Regards,

    Cristiano Duarte

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

    Cristiano Duarte Guest

  3. #3

    Default Re: [PHP-DEV] internal hashtables [patch included]

    Hi Andi,

    In fact Moriyoshi pointed out this problem in hist "Registering constants to
    internal classes (ZE2)" message:
    [url]http://www.zend.com/lists/php-dev/200307/msg00023.html[/url]

    The code I provided fix this problem, if it's a problem...

    Cristiano Duarte

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

    Cristiano Duarte Guest

  4. #4

    Default Re: [PHP-DEV] internal hashtables [patch included]

    ------=_NextPart_000_002E_01C39D84.D11A1FE0
    Content-Type: text/plain;
    cht="iso-8859-1"
    Content-Transfer-Encoding: 7bit
    > Can you please not send uuencoded stuff but just attach the files as
    > plain text?
    Sorry Derick, I didn't mean to.
    The patch is now included as plain text.

    Cristiano Duarte

    ------=_NextPart_000_002E_01C39D84.D11A1FE0
    Content-Type: text/plain; cht=us-ascii

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    ------=_NextPart_000_002E_01C39D84.D11A1FE0--
    Cristiano Duarte Guest

  5. #5

    Default Re: [PHP-DEV] internal hashtables [patch included]

    ------=_NextPart_000_0082_01C39D85.C89190A0
    Content-Type: text/plain;
    cht="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable
    > Can you please not send uuencoded stuff but just attach the files as=20
    > plain text?
    Sorry Derick, I didn't mean to.
    The patch is now included as plain text.

    Cristiano Duarte


    ------=_NextPart_000_0082_01C39D85.C89190A0
    Content-Type: text/plain; cht=us-ascii

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    ------=_NextPart_000_0082_01C39D85.C89190A0--
    Cristiano Duarte Guest

  6. #6

    Default Re: [PHP-DEV] internal hashtables [patch included]

    --------------080201040705070809050705
    Content-Type: text/plain; cht=us-ascii; format=flowed
    Content-Transfer-Encoding: 7bit

    Derick Rethans wrote:
    > Can you please not send uuencoded stuff but just attach the files as
    > plain text?
    Sorry Derick, I didn't mean to. :-(
    The patch is attached as plain text now.

    Cristiano Duarte

    --------------080201040705070809050705
    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 */

    /*


    --------------080201040705070809050705
    Content-Type: text/plain; cht=us-ascii

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    --------------080201040705070809050705--
    Cristiano Duarte Guest

  7. #7

    Default [PHP-DEV] internal hashtables [patch included]

    ------=_NextPart_000_0007_01C3A724.D196FB60
    Content-Type: text/plain;
    cht="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable

    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

    ------=_NextPart_000_0007_01C3A724.D196FB60
    Content-Type: text/plain; cht=us-ascii

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    ------=_NextPart_000_0007_01C3A724.D196FB60--
    Cristiano Duarte Guest

Similar Threads

  1. [PHP-DEV] [PATCH] Internal Hashtables bug
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: November 11th, 09:39 PM
  2. [PHP-DEV] internal hashtables [patch included]
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: November 10th, 03:02 AM
  3. [PHP-DEV] internal hashtables [patch included]
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: November 10th, 03:00 AM
  4. Replies: 0
    Last Post: July 16th, 07:48 AM
  5. #24671 [NEW]: Case problem with internal list of included files handling
    By stefan dot priebsch at e-novative dot de in forum PHP Development
    Replies: 0
    Last Post: July 16th, 07:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139