Re: Storing zvals in hash tables in resources

From: Date: Fri, 22 Oct 2010 23:05:29 +0000
Subject: Re: Storing zvals in hash tables in resources
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-49959@lists.php.net to get a copy of this message
On Fri, 22 Oct 2010 22:22:06 +0100, Martin Jansen <martin@divbyzero.net> wrote:
I'm trying to store zvals in a hash table which is part of a resource. Unfortunately the zvals do not seem to "persist" between function calls: [...]
    ALLOC_HASHTABLE(ctx->variables);
    zend_hash_init(ctx->variables, 32, NULL, NULL, 0);
You probably want to give a destructor to zend_hash_init, since you're storing zvals, that would be ZVAL_PTR_DTOR.
[...]
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz",
        &zcontext, &name, &name_len, &value) == FAILURE)
    {
        return;
    }
    ZEND_FETCH_RESOURCE(ctx, foo_context*, &zcontext, -1,
        FOO_CONTEXT_RES_NAME, le_adl_context);
    zend_hash_update(ctx->variables, name, name_len + 1, &value,
sizeof(zval*), NULL);
You're not incrementing the refcount of the value you're adding to the hash table. Call zval_add_ref. -- Gustavo Lopes

« previous php.internals (#49959) next »