Changeset 496 in svn for trunk/utils.c


Ignore:
Timestamp:
2008-01-04T11:38:57Z (8 years ago)
Author:
Xuefer
Message:

fixed #157: support user error handler for E_STRICT. E_STRICT is now cached

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils.c

    r485 r496  
    517517#define OG(x) (sandbox->orig_##x)
    518518/* }}} */
     519#ifdef E_STRICT
     520static void xc_sandbox_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) /* {{{ */
     521{
     522    xc_compilererror_t *compilererror;
     523    xc_sandbox_t *sandbox;
     524    TSRMLS_FETCH();
     525
     526    sandbox = (xc_sandbox_t *) XG(sandbox);
     527    assert(sandbox != NULL);
     528    if (sandbox->compilererror_cnt <= sandbox->compilererror_size) {
     529        if (sandbox->compilererror_size) {
     530            sandbox->compilererror_size += 16;
     531            sandbox->compilererrors = erealloc(sandbox->compilererrors, sandbox->compilererror_size * sizeof(sandbox->compilererrors));
     532        }
     533        else {
     534            sandbox->compilererror_size = 16;
     535            sandbox->compilererrors = emalloc(sandbox->compilererror_size * sizeof(sandbox->compilererrors));
     536        }
     537    }
     538    compilererror = &sandbox->compilererrors[sandbox->compilererror_cnt++];
     539    compilererror->type   = type;
     540    compilererror->lineno = error_lineno;
     541    compilererror->error_len = zend_vspprintf(&compilererror->error, 0, format, args);
     542}
     543/* }}} */
     544#endif
    519545#ifdef ZEND_ENGINE_2_1
    520546static zend_bool xc_auto_global_callback(char *name, uint name_len TSRMLS_DC) /* {{{ */
     
    622648#ifdef E_STRICT
    623649    sandbox->orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting);
    624     EG(user_error_handler_error_reporting) &= ~E_STRICT;
    625 #endif
    626 
     650    EG(user_error_handler_error_reporting) = 0;
     651
     652    sandbox->compilererror_cnt  = 0;
     653    sandbox->compilererror_size = 0;
     654    sandbox->orig_zend_error_cb = zend_error_cb;
     655    zend_error_cb = xc_sandbox_error_cb;
     656#endif
     657
     658    XG(sandbox) = (void *) sandbox;
    627659    return sandbox;
    628660}
     
    684716    }
    685717
     718#ifdef E_STRICT
     719    /* restore trigger errors */
     720    for (i = 0; i < sandbox->compilererror_cnt; i ++) {
     721        xc_compilererror_t *error = &sandbox->compilererrors[i];
     722        CG(zend_lineno) = error->lineno;
     723        zend_error(error->type, "%s", error->error);
     724    }
     725    CG(zend_lineno) = 0;
     726#endif
     727
    686728    i = 1;
    687729    zend_hash_add(&OG(included_files), sandbox->filename, strlen(sandbox->filename) + 1, (void *)&i, sizeof(int), NULL);
     
    690732void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */
    691733{
     734    XG(sandbox) = NULL;
     735#ifdef E_STRICT
     736    EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting;
     737    zend_error_cb = sandbox->orig_zend_error_cb;
     738#endif
     739
    692740    /* restore first first install function/class */
    693741#ifdef HAVE_XCACHE_CONSTANT
     
    731779    memcpy(&EG(included_files), &OG(included_files), sizeof(EG(included_files)));
    732780
    733 #ifdef E_STRICT
    734     EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting;
    735 #endif
    736 
     781    if (sandbox->compilererrors) {
     782        int i;
     783        for (i = 0; i < sandbox->compilererror_cnt; i ++) {
     784            efree(sandbox->compilererrors[i].error);
     785        }
     786        efree(sandbox->compilererrors);
     787    }
    737788    if (sandbox->alloc) {
    738789        efree(sandbox);
Note: See TracChangeset for help on using the changeset viewer.