Changeset 95 in svn for trunk/utils.c


Ignore:
Timestamp:
2006-07-16T11:07:57Z (9 years ago)
Author:
Xuefer
Message:

fixed #20, default: --enable-xcache-constant=yes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils.c

    r88 r95  
    265265#endif
    266266
     267#ifdef HAVE_XCACHE_CONSTANT
     268void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, void *key, uint len TSRMLS_DC) /* {{{ */
     269{
     270    if (zend_u_hash_add(EG(zend_constants), type, key, len,
     271                constant, sizeof(zend_constant),
     272                NULL
     273                ) == FAILURE) {
     274        CG(in_compilation) = 1;
     275        CG(compiled_filename) = filename;
     276        CG(zend_lineno) = 0;
     277        zend_error(E_NOTICE, "Constant %s already defined", key);
     278        free(constant->name);
     279        if (!(constant->flags & CONST_PERSISTENT)) {
     280            zval_dtor(&constant->value);
     281        }
     282    }
     283}
     284/* }}} */
     285#endif
    267286void xc_install_function(char *filename, zend_function *func, zend_uchar type, void *key, uint len TSRMLS_DC) /* {{{ */
    268287{
     
    316335#define OG(x) (sandbox->orig_##x)
    317336/* }}} */
     337#ifdef HAVE_XCACHE_CONSTANT
     338static void xc_constant_copy_ctor(zend_constant *c) /* {{{ */
     339{
     340    c->name = zend_strndup(c->name, c->name_len - 1);
     341    if (!(c->flags & CONST_PERSISTENT)) {
     342        zval_copy_ctor(&c->value);
     343    }
     344}
     345/* }}} */
     346#endif
    318347xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */
    319348{
     
    325354        sandbox->alloc = 1;
    326355    }
     356
    327357    memcpy(&OG(included_files), &EG(included_files), sizeof(EG(included_files)));
    328358    memcpy(&OG(open_files), &CG(open_files), sizeof(CG(open_files)));
     359
     360#ifdef HAVE_XCACHE_CONSTANT
     361    OG(zend_constants) = EG(zend_constants);
     362    EG(zend_constants) = &TG(zend_constants);
     363#endif
    329364
    330365    OG(function_table) = CG(function_table);
     
    342377    zend_llist_init(TG(open_files), sizeof(zend_file_handle), (void (*)(void *)) zend_file_handle_dtor, 0);
    343378    zend_hash_init_ex(TG(included_files), 5, NULL, NULL, 0, 1);
     379#ifdef HAVE_XCACHE_CONSTANT
     380    zend_hash_init_ex(&TG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
     381#endif
    344382    zend_hash_init_ex(&TG(function_table), 128, NULL, ZEND_FUNCTION_DTOR, 0, 0);
    345383    zend_hash_init_ex(&TG(class_table), 16, NULL, ZEND_CLASS_DTOR, 0, 0);
     
    356394    zend_llist_position lpos;
    357395    zend_file_handle *handle;
     396
     397#ifdef HAVE_XCACHE_CONSTANT
     398    b = TG(zend_constants).pListHead;
     399    /* install constants */
     400    while (b != NULL) {
     401        zend_constant *c = (zend_constant*) b->pData;
     402        xc_install_constant(sandbox->filename, c,
     403                BUCKET_KEY_TYPE(b), BUCKET_KEY(b), b->nKeyLength TSRMLS_CC);
     404        b = b->pListNext;
     405    }
     406#endif
    358407
    359408    b = TG(function_table).pListHead;
     
    386435{
    387436    /* restore first first install function/class */
     437#ifdef HAVE_XCACHE_CONSTANT
     438    EG(zend_constants) = OG(zend_constants);
     439#endif
    388440    CG(function_table) = OG(function_table);
    389441    CG(class_table)    = OG(class_table);
     
    394446
    395447        /* no free as it's installed */
     448#ifdef HAVE_XCACHE_CONSTANT
     449        TG(zend_constants).pDestructor = NULL;
     450#endif
    396451        TG(function_table).pDestructor = NULL;
    397452        TG(class_table).pDestructor = NULL;
     
    400455
    401456    /* destroy all the tmp */
     457#ifdef HAVE_XCACHE_CONSTANT
     458    zend_hash_destroy(&TG(zend_constants));
     459#endif
    402460    zend_hash_destroy(&TG(function_table));
    403461    zend_hash_destroy(&TG(class_table));
Note: See TracChangeset for help on using the changeset viewer.