Browse Source

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

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@496 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 14 years ago
parent
commit
52c01c2e35
  1. 1
      ChangeLog
  2. 17
      processor/processor.m4
  3. 61
      utils.c
  4. 9
      utils.h
  5. 1
      xcache-test.ini
  6. 13
      xcache.c
  7. 13
      xcache.h
  8. 2
      xcache_globals.h

1
ChangeLog

@ -5,6 +5,7 @@ Ini Settings Changes
ChangeLog
========
* compiler errors: all compiler warning (e.g.: E_STRICT) is now cached and is supported for user handler
* added module dependency
* live with wrong system time: allow caching files with mtime in further
* bug fix for compatibility with Zend Optimizer and other non-cachable

17
processor/processor.m4

@ -740,6 +740,15 @@ DEF_STRUCT_P_FUNC(`xc_autoglobal_t', , `dnl {{{
')
dnl }}}
#endif
#ifdef E_STRICT
DEF_STRUCT_P_FUNC(`xc_compilererror_t', , `dnl {{{
DISPATCH(int, type)
DISPATCH(uint, lineno)
DISPATCH(int, error_len)
PROC_STRING_L(error, error_len)
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
zend_uint i;
@ -788,6 +797,14 @@ DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
', `
STRUCT_ARRAY(autoglobal_cnt, xc_autoglobal_t, autoglobals)
')
#endif
#ifdef E_STRICT
DISPATCH(zend_uint, compilererror_cnt)
IFRESTORE(`
COPY(compilererrors)
', `
STRUCT_ARRAY(compilererror_cnt, xc_compilererror_t, compilererrors)
')
#endif
DISPATCH(zend_bool, have_early_binding)
DISPATCH(zend_bool, have_references)

61
utils.c

@ -516,6 +516,32 @@ ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int op
#define TG(x) (sandbox->tmp_##x)
#define OG(x) (sandbox->orig_##x)
/* }}} */
#ifdef E_STRICT
static void xc_sandbox_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) /* {{{ */
{
xc_compilererror_t *compilererror;
xc_sandbox_t *sandbox;
TSRMLS_FETCH();
sandbox = (xc_sandbox_t *) XG(sandbox);
assert(sandbox != NULL);
if (sandbox->compilererror_cnt <= sandbox->compilererror_size) {
if (sandbox->compilererror_size) {
sandbox->compilererror_size += 16;
sandbox->compilererrors = erealloc(sandbox->compilererrors, sandbox->compilererror_size * sizeof(sandbox->compilererrors));
}
else {
sandbox->compilererror_size = 16;
sandbox->compilererrors = emalloc(sandbox->compilererror_size * sizeof(sandbox->compilererrors));
}
}
compilererror = &sandbox->compilererrors[sandbox->compilererror_cnt++];
compilererror->type = type;
compilererror->lineno = error_lineno;
compilererror->error_len = zend_vspprintf(&compilererror->error, 0, format, args);
}
/* }}} */
#endif
#ifdef ZEND_ENGINE_2_1
static zend_bool xc_auto_global_callback(char *name, uint name_len TSRMLS_DC) /* {{{ */
{
@ -621,9 +647,15 @@ xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /
#ifdef E_STRICT
sandbox->orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting);
EG(user_error_handler_error_reporting) &= ~E_STRICT;
EG(user_error_handler_error_reporting) = 0;
sandbox->compilererror_cnt = 0;
sandbox->compilererror_size = 0;
sandbox->orig_zend_error_cb = zend_error_cb;
zend_error_cb = xc_sandbox_error_cb;
#endif
XG(sandbox) = (void *) sandbox;
return sandbox;
}
/* }}} */
@ -683,12 +715,28 @@ static void xc_sandbox_install(xc_sandbox_t *sandbox, xc_install_action_t instal
xc_redo_pass_two(CG(active_op_array) TSRMLS_CC);
}
#ifdef E_STRICT
/* restore trigger errors */
for (i = 0; i < sandbox->compilererror_cnt; i ++) {
xc_compilererror_t *error = &sandbox->compilererrors[i];
CG(zend_lineno) = error->lineno;
zend_error(error->type, "%s", error->error);
}
CG(zend_lineno) = 0;
#endif
i = 1;
zend_hash_add(&OG(included_files), sandbox->filename, strlen(sandbox->filename) + 1, (void *)&i, sizeof(int), NULL);
}
/* }}} */
void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC) /* {{{ */
{
XG(sandbox) = NULL;
#ifdef E_STRICT
EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting;
zend_error_cb = sandbox->orig_zend_error_cb;
#endif
/* restore first first install function/class */
#ifdef HAVE_XCACHE_CONSTANT
EG(zend_constants) = OG(zend_constants);
@ -730,10 +778,13 @@ void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_D
/* restore orig here, as EG/CG holded tmp before */
memcpy(&EG(included_files), &OG(included_files), sizeof(EG(included_files)));
#ifdef E_STRICT
EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting;
#endif
if (sandbox->compilererrors) {
int i;
for (i = 0; i < sandbox->compilererror_cnt; i ++) {
efree(sandbox->compilererrors[i].error);
}
efree(sandbox->compilererrors);
}
if (sandbox->alloc) {
efree(sandbox);
}

9
utils.h

@ -79,7 +79,6 @@ ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int op
/* sandbox */
typedef struct {
int alloc;
int orig_user_error_handler_error_reporting;
char *filename;
HashTable orig_included_files;
@ -97,6 +96,14 @@ typedef struct {
HashTable tmp_auto_globals;
Bucket *tmp_internal_function_tail;
Bucket *tmp_internal_class_tail;
#ifdef E_STRICT
int orig_user_error_handler_error_reporting;
ZEND_API void (*orig_zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
zend_uint compilererror_cnt;
zend_uint compilererror_size;
xc_compilererror_t *compilererrors;
#endif
} xc_sandbox_t;
typedef enum _xc_install_action_t {

1
xcache-test.ini

@ -1,3 +1,4 @@
display_error = On
auto_globals_jit = Off
[xcache]

13
xcache.c

@ -664,6 +664,15 @@ static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRM
zend_u_is_auto_global(aginfo->type, aginfo->key, aginfo->key_len TSRMLS_CC);
}
#endif
#ifdef E_STRICT
/* restore trigger errors */
for (i = 0; i < p->compilererror_cnt; i ++) {
xc_compilererror_t *error = &p->compilererrors[i];
CG(zend_lineno) = error->lineno;
zend_error(error->type, "%s", error->error);
}
CG(zend_lineno) = 0;
#endif
i = 1;
zend_hash_add(&EG(included_files), xce->name.str.val, xce->name.str.len+1, (void *)&i, sizeof(int), NULL);
@ -1114,6 +1123,10 @@ static zend_op_array *xc_compile_php(xc_entry_data_php_t *php, zend_file_handle
#endif
}
/* }}} */
#ifdef E_STRICT
php->compilererrors = ((xc_sandbox_t *) XG(sandbox))->compilererrors;
php->compilererror_cnt = ((xc_sandbox_t *) XG(sandbox))->compilererror_cnt;
#endif
/* {{{ find inherited classes that should be early-binding */
php->have_early_binding = 0;
for (i = 0; i < php->classinfo_cnt; i ++) {

13
xcache.h

@ -265,6 +265,14 @@ typedef struct {
#endif
typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
typedef char xc_md5sum_t[16];
/* {{{ xc_compilererror_t */
typedef struct {
int type;
uint lineno;
int error_len;
char *error;
} xc_compilererror_t;
/* }}} */
/* {{{ xc_entry_data_php_t */
struct _xc_entry_data_php_t {
xc_hash_value_t hvalue; /* hash of md5 */
@ -297,6 +305,11 @@ struct _xc_entry_data_php_t {
xc_autoglobal_t *autoglobals;
#endif
#ifdef E_STRICT
zend_uint compilererror_cnt;
xc_compilererror_t *compilererrors;
#endif
zend_bool have_references;
};
/* }}} */

2
xcache_globals.h

@ -20,6 +20,8 @@ ZEND_BEGIN_MODULE_GLOBALS(xcache)
HashTable internal_function_table;
HashTable internal_class_table;
zend_bool internal_table_copied;
void *sandbox;
ZEND_END_MODULE_GLOBALS(xcache)
ZEND_EXTERN_MODULE_GLOBALS(xcache)

Loading…
Cancel
Save