Changeset 640 in svn for trunk/utils.c


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

copy only internal constant, clean constant on shutdown

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.