Changeset 640 in svn


Ignore:
Timestamp:
2009-07-05T16:43:38+02:00 (6 years ago)
Author:
Xuefer
Message:

copy only internal constant, clean constant on shutdown

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils.c

    r637 r640  
    597597#endif
    598598
    599 void xc_copy_zend_constant(zend_constant *c) /* {{{ */
    600 {
     599void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker) /* {{{ */
     600{
     601    Bucket *p;
     602    void *new_entry;
     603    zend_bool setTargetPointer;
     604
     605    setTargetPointer = !target->pInternalPointer;
     606    p = source->pListHead;
     607    while (p) {
     608        if (checker(p->pData)) {
     609            if (setTargetPointer && source->pInternalPointer == p) {
     610                target->pInternalPointer = NULL;
     611            }
     612            if (p->nKeyLength) {
     613                zend_hash_quick_update(target, p->arKey, p->nKeyLength, p->h, p->pData, size, &new_entry);
     614            } else {
     615                zend_hash_index_update(target, p->h, p->pData, size, &new_entry);
     616            }
     617            if (pCopyConstructor) {
     618                pCopyConstructor(new_entry);
     619            }
     620        }
     621        p = p->pListNext;
     622    }
     623    if (!target->pInternalPointer) {
     624        target->pInternalPointer = target->pListHead;
     625    }
     626}
     627/* }}} */
     628#ifdef HAVE_XCACHE_CONSTANT
     629static zend_bool xc_is_internal_zend_constant(zend_constant *c) /* {{{ */
     630{
     631    return (c->flags & CONST_PERSISTENT) ? 1 : 0;
     632}
     633/* }}} */
     634void xc_zend_constant_ctor(zend_constant *c) /* {{{ */
     635{
     636    assert((c->flags & CONST_PERSISTENT));
    601637#ifdef IS_UNICODE
    602638    c->name.u = zend_ustrndup(c->name.u, c->name_len - 1);
     
    604640    c->name = zend_strndup(c->name, c->name_len - 1);
    605641#endif
    606     if (!(c->flags & CONST_PERSISTENT)) {
    607         zval_copy_ctor(&c->value);
    608     }
    609 }
    610 /* }}} */
     642}
     643/* }}} */
     644void xc_zend_constant_dtor(zend_constant *c) /* {{{ */
     645{
     646    free(ZSTR_U(c->name));
     647}
     648/* }}} */
     649void xc_copy_internal_zend_constants(HashTable *target, HashTable *source) /* {{{ */
     650{
     651    zend_constant tmp_const;
     652    xc_hash_copy_if(target, source, (copy_ctor_func_t) xc_zend_constant_ctor, (void *) &tmp_const, sizeof(zend_constant), (xc_if_func_t) xc_is_internal_zend_constant);
     653}
     654/* }}} */
     655#endif
    611656xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */
    612657{
     
    646691    h = OG(zend_constants);
    647692    zend_hash_init_ex(&TG(zend_constants),  20, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
     693    xc_copy_internal_zend_constants(&TG(zend_constants), &XG(internal_constant_table));
    648694    {
    649695        zend_constant tmp_const;
    650         zend_hash_copy(&TG(zend_constants), &XG(internal_constant_table), (copy_ctor_func_t) xc_copy_zend_constant, (void *) &tmp_const, sizeof(tmp_const));
     696        zend_hash_copy(&TG(zend_constants), &XG(internal_constant_table), (copy_ctor_func_t) xc_zend_constant_ctor, (void *) &tmp_const, sizeof(tmp_const));
    651697    }
    652698#endif
  • trunk/utils.h

    r637 r640  
    123123xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC);
    124124void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC);
    125 void xc_copy_zend_constant(zend_constant *c);
     125
     126typedef zend_bool (*xc_if_func_t)(void *data);
     127
     128void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker);
     129#ifdef HAVE_XCACHE_CONSTANT
     130void xc_zend_constant_ctor(zend_constant *c);
     131void xc_zend_constant_dtor(zend_constant *c);
     132void xc_copy_internal_zend_constants(HashTable *target, HashTable *source);
     133#endif
  • trunk/xcache.c

    r638 r640  
    18541854
    18551855    if (!XG(internal_table_copied)) {
    1856 #ifdef HAVE_XCACHE_CONSTANT
    1857         zend_constant tmp_const;
    1858 #endif
    18591856        zend_function tmp_func;
    18601857        xc_cest_t tmp_cest;
     
    18671864
    18681865#ifdef HAVE_XCACHE_CONSTANT
    1869         zend_hash_init_ex(&XG(internal_constant_table), 20,  NULL, NULL, 1, 0);
     1866        zend_hash_init_ex(&XG(internal_constant_table), 20,  NULL, (dtor_func_t) xc_zend_constant_dtor, 1, 0);
    18701867#endif
    18711868        zend_hash_init_ex(&XG(internal_function_table), 100, NULL, NULL, 1, 0);
     
    18731870
    18741871#ifdef HAVE_XCACHE_CONSTANT
    1875         zend_hash_copy(&XG(internal_constant_table), EG(zend_constants), (copy_ctor_func_t) xc_copy_zend_constant, &tmp_const, sizeof(tmp_const));
     1872        xc_copy_internal_zend_constants(&XG(internal_constant_table), EG(zend_constants));
    18761873#endif
    18771874        zend_hash_copy(&XG(internal_function_table), CG(function_table), NULL, &tmp_func, sizeof(tmp_func));
     
    19341931
    19351932#ifdef HAVE_XCACHE_CONSTANT
    1936     zend_hash_init_ex(&xcache_globals->internal_constant_table, 1, NULL, NULL, 1, 0);
     1933    zend_hash_init_ex(&xcache_globals->internal_constant_table, 1, NULL, (dtor_func_t) xc_zend_constant_dtor, 1, 0);
    19371934#endif
    19381935    zend_hash_init_ex(&xcache_globals->internal_function_table, 1, NULL, NULL, 1, 0);
Note: See TracChangeset for help on using the changeset viewer.