diff --git a/processor/head.m4 b/processor/head.m4 index 38605e6..c9696ed 100644 --- a/processor/head.m4 +++ b/processor/head.m4 @@ -178,7 +178,7 @@ IFASSERT(` #undef C_RELAYLINE #define C_RELAYLINE , __LINE__ ') -static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr const str, long size IFASSERT(`, int relayline')) { +static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFASSERT(`, int relayline')) { pushdef(`__LINE__', `relayline') int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size); long dummy = 1; @@ -200,7 +200,7 @@ static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, /* }}} */ /* {{{ xc_store_string_n */ REDEF(`KIND', `store') -static inline zstr xc_store_string_n(xc_processor_t *processor, zend_uchar type, const_zstr const str, long size IFASSERT(`, int relayline')) { +static inline zstr xc_store_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFASSERT(`, int relayline')) { pushdef(`__LINE__', `relayline') int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size); zstr ret, *pret; diff --git a/processor/processor.m4 b/processor/processor.m4 index cccd325..79b111b 100644 --- a/processor/processor.m4 +++ b/processor/processor.m4 @@ -410,6 +410,8 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{ dnl runtime binding: ADD_TRAIT will deal with it COPYNULL(traits) COPYZERO(num_traits) + STRUCT_ARRAY(, zend_trait_alias_ptr, trait_aliases) + STRUCT_ARRAY(, zend_trait_precedence_ptr, trait_precedences) # endif #else IFRESTORE(` @@ -425,8 +427,6 @@ DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{ ') PROCESS(zend_uint, num_interfaces) #endif - STRUCT_ARRAY(, zend_trait_alias_ptr, trait_aliases) - STRUCT_ARRAY(, zend_trait_precedence_ptr, trait_precedences) # ifdef ZEND_ENGINE_2_4 DISABLECHECK(` diff --git a/utils.c b/utils.c index ff348df..2a295f9 100644 --- a/utils.c +++ b/utils.c @@ -481,7 +481,7 @@ static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table, #endif #ifdef HAVE_XCACHE_CONSTANT -void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ +void xc_install_constant(ZEND_24(const) char *filename, zend_constant *constant, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ { if (zend_u_hash_add(EG(zend_constants), type, key, len, constant, sizeof(zend_constant), @@ -501,7 +501,7 @@ void xc_install_constant(char *filename, zend_constant *constant, zend_uchar typ } /* }}} */ #endif -void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ +void xc_install_function(ZEND_24(const) char *filename, zend_function *func, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ { zend_bool istmpkey; @@ -531,7 +531,7 @@ void xc_install_function(char *filename, zend_function *func, zend_uchar type, z } } /* }}} */ -ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ +ZESW(xc_cest_t *, void) xc_install_class(ZEND_24(const) char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC) /* {{{ */ { zend_bool istmpkey; zend_class_entry *cep = CestToCePtr(*cest); @@ -629,7 +629,7 @@ static void xc_sandbox_error_cb(int type, const char *error_filename, const uint /* }}} */ #endif #ifdef ZEND_ENGINE_2_1 -static zend_bool xc_auto_global_callback(char *name, uint name_len TSRMLS_DC) /* {{{ */ +static zend_bool xc_auto_global_callback(ZEND_24(const) char *name, uint name_len TSRMLS_DC) /* {{{ */ { return 0; } @@ -709,7 +709,7 @@ void xc_copy_internal_zend_constants(HashTable *target, HashTable *source) /* {{ } /* }}} */ #endif -xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */ +xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(const) char *filename TSRMLS_DC) /* {{{ */ { HashTable *h; diff --git a/utils.h b/utils.h index d386244..4b4ca2b 100644 --- a/utils.h +++ b/utils.h @@ -68,10 +68,10 @@ int xc_foreach_early_binding_class(zend_op_array *op_array, void (*callback)(zen /* installer */ #ifdef HAVE_XCACHE_CONSTANT -void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC); +void xc_install_constant(ZEND_24(const) char *filename, zend_constant *constant, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); #endif -void xc_install_function(char *filename, zend_function *func, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC); -ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len, ulong h TSRMLS_DC); +void xc_install_function(ZEND_24(const) char *filename, zend_function *func, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); +ZESW(xc_cest_t *, void) xc_install_class(ZEND_24(const) char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC); #if defined(E_STRICT) || defined(E_DEPRECATED) #define XCACHE_ERROR_CACHING @@ -80,7 +80,7 @@ ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int op /* sandbox */ typedef struct { int alloc; - char *filename; + ZEND_24(const) char *filename; HashTable orig_included_files; HashTable *tmp_included_files; @@ -121,7 +121,7 @@ typedef enum _xc_install_action_t { } xc_install_action_t; void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce)); -xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC); +xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(const) char *filename TSRMLS_DC); void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC); typedef zend_bool (*xc_if_func_t)(void *data); diff --git a/xcache.c b/xcache.c index 6fd9371..7f63d5c 100644 --- a/xcache.c +++ b/xcache.c @@ -37,13 +37,13 @@ #include "opcode_spec.h" #include "utils.h" -#define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > pentry->ctime + (pentry)->ttl) +#define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > (pentry)->ctime + (pentry)->ttl) #define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0) -#define LOCK(x) xc_lock(x->lck) -#define UNLOCK(x) xc_unlock(x->lck) +#define LOCK(x) xc_lock((x)->lck) +#define UNLOCK(x) xc_unlock((x)->lck) #define ENTER_LOCK_EX(x) \ - xc_lock(x->lck); \ + xc_lock((x)->lck); \ zend_try { \ do #define LEAVE_LOCK_EX(x) \ @@ -51,7 +51,7 @@ } zend_catch { \ catched = 1; \ } zend_end_try(); \ - xc_unlock(x->lck) + xc_unlock((x)->lck) #define ENTER_LOCK(x) do { \ int catched = 0; \ @@ -858,14 +858,14 @@ static int xc_stat(const char *filename, const char *include_path, struct stat * /* fall back to current directory */ if (zend_is_executing(TSRMLS_C)) { - char *path = zend_get_executed_filename(TSRMLS_C); - if (path && path[0] != '[') { - int len = strlen(path); - while ((--len >= 0) && !IS_SLASH(path[len])) { + const char *executed_filename = zend_get_executed_filename(TSRMLS_C); + if (executed_filename && executed_filename[0] != '[') { + int len = strlen(executed_filename); + while ((--len >= 0) && !IS_SLASH(executed_filename[len])) { /* skipped */ } if (len > 0 && len + strlen(filename) + 1 < MAXPATHLEN - 1) { - strcpy(filepath, path); + strcpy(filepath, executed_filename); strcpy(filepath + len + 1, filename); if (VCWD_STAT(filepath, pbuf) == 0) { ret = SUCCESS; @@ -885,10 +885,10 @@ finish: /* }}} */ #define HASH(i) (i) -#define HASH_ZSTR_L(t, s, l) HASH(zend_u_inline_hash_func(t, s, (l + 1) * sizeof(UChar))) -#define HASH_STR_S(s, l) HASH(zend_inline_hash_func(s, l)) -#define HASH_STR_L(s, l) HASH_STR_S(s, l + 1) -#define HASH_STR(s) HASH_STR_L(s, strlen(s) + 1) +#define HASH_ZSTR_L(t, s, l) HASH(zend_u_inline_hash_func((t), (s), ((l) + 1) * sizeof(UChar))) +#define HASH_STR_S(s, l) HASH(zend_inline_hash_func((s), (l))) +#define HASH_STR_L(s, l) HASH_STR_S((s), (l) + 1) +#define HASH_STR(s) HASH_STR_L((s), strlen((s)) + 1) #define HASH_NUM(n) HASH(n) static inline xc_hash_value_t xc_hash_fold(xc_hash_value_t hvalue, const xc_hash_t *hasher) /* {{{ fold hash bits as needed */ { @@ -961,15 +961,10 @@ static void xc_entry_free_key_php(xc_entry_t *xce TSRMLS_DC) /* {{{ */ } /* }}} */ -static int xc_entry_init_key_php(xc_entry_t *xce, char *filename TSRMLS_DC) /* {{{ */ +static int xc_entry_init_key_php(xc_entry_t *xce, const char *filename TSRMLS_DC) /* {{{ */ { char opened_path_buffer[MAXPATHLEN]; - struct stat buf, *pbuf; - xc_hash_value_t hv; int cacheid; - xc_entry_data_php_t *php; - char *ptr; - time_t delta; if (!filename || !SG(request_info).path_translated) { return FAILURE; @@ -979,9 +974,9 @@ static int xc_entry_init_key_php(xc_entry_t *xce, char *filename TSRMLS_DC) /* { return FAILURE; } - php = xce->data.php; - if (XG(stat)) { + struct stat buf, *pbuf; + if (strcmp(SG(request_info).path_translated, filename) == 0) { /* sapi has already done this stat() for us */ pbuf = sapi_get_stat(TSRMLS_C); @@ -1001,7 +996,7 @@ static int xc_entry_init_key_php(xc_entry_t *xce, char *filename TSRMLS_DC) /* { /* relative path */ if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) { - ptr = filename + 1; + const char *ptr = filename + 1; if (*ptr == '.') { while (*(++ptr) == '.'); if (!IS_SLASH(*ptr)) { @@ -1024,9 +1019,11 @@ not_relative_path: /* fall */ stat_done: - delta = XG(request_time) - pbuf->st_mtime; - if (abs(delta) < 2 && !xc_test) { - return FAILURE; + { + time_t delta = XG(request_time) - pbuf->st_mtime; + if (abs(delta) < 2 && !xc_test) { + return FAILURE; + } } xce->mtime = pbuf->st_mtime; @@ -1034,7 +1031,7 @@ stat_done: xce->device = pbuf->st_dev; xce->inode = pbuf->st_ino; #endif - php->sourcesize = pbuf->st_size; + xce->data.php->sourcesize = pbuf->st_size; } else { /* XG(inode) */ xce->mtime = 0; @@ -1042,7 +1039,7 @@ stat_done: xce->device = 0; xce->inode = 0; #endif - php->sourcesize = 0; + xce->data.php->sourcesize = 0; } #ifdef HAVE_INODE @@ -1058,23 +1055,13 @@ stat_done: } UNISW(NOTHING, xce->name_type = IS_STRING;) - xce->name.str.val = filename; + xce->name.str.val = (char *) filename; xce->name.str.len = strlen(filename); - if (xc_php_hcache.size > 1) { - hv = xc_entry_hash_php_basename(xce TSRMLS_CC); - cacheid = xc_hash_fold(hv, &xc_php_hcache); - } - else { - cacheid = 0; - } + cacheid = xc_php_hcache.size > 1 ? xc_hash_fold(xc_entry_hash_php_basename(xce TSRMLS_CC), &xc_php_hcache) : 0; xce->cache = xc_php_caches[cacheid]; - - hv = xc_entry_hash_php(xce TSRMLS_CC); - xce->hvalue = xc_hash_fold(hv, &xc_php_hentry); - + xce->hvalue = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry); xce->type = XC_TYPE_PHP; - xce->filepath = NULL; xce->dirpath = NULL; #ifdef IS_UNICODE @@ -1087,7 +1074,7 @@ stat_done: /* }}} */ static inline xc_hash_value_t xc_php_hash_md5(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ { - return HASH_STR_S(&php->md5, sizeof(php->md5)); + return HASH_STR_S(php->md5.digest, sizeof(php->md5)); } /* }}} */ static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce TSRMLS_DC) /* {{{ */ @@ -1096,7 +1083,6 @@ static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce T PHP_MD5_CTX context; int n; php_stream *stream; - xc_hash_value_t hv; ulong old_rsid = EG(regular_list).nNextFreeElement; stream = php_stream_open_wrapper(xce->name.str.val, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL); @@ -1119,9 +1105,8 @@ static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce T return FAILURE; } - hv = xc_php_hash_md5(php TSRMLS_CC); php->cache = xce->cache; - php->hvalue = (hv & php->cache->hphp->mask); + php->hvalue = (xc_php_hash_md5(php TSRMLS_CC) & php->cache->hphp->mask); #ifdef XCACHE_DEBUG { char md5str[33]; @@ -1133,7 +1118,7 @@ static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce T return SUCCESS; } /* }}} */ -static void xc_entry_init_key_php_entry(xc_entry_t *xce, char *filepath TSRMLS_DC) /* {{{*/ +static void xc_entry_init_key_php_entry(xc_entry_t *xce, ZEND_24(const) char *filepath TSRMLS_DC) /* {{{*/ { xce->filepath = filepath; xce->filepath_len = strlen(xce->filepath); @@ -1517,7 +1502,7 @@ static zend_op_array *xc_compile_php(xc_entry_t *xce, xc_entry_data_php_t *php, /* }}} */ /* {{{ prepare */ - zend_restore_compiled_filename(h->opened_path ? h->opened_path : h->filename TSRMLS_CC); + zend_restore_compiled_filename(h->opened_path ? h->opened_path : (char *) h->filename TSRMLS_CC); php->op_array = op_array; #ifdef HAVE_XCACHE_CONSTANT @@ -1889,9 +1874,9 @@ static zend_op_array *xc_compile_file_ex(xc_entry_t *xce, zend_file_handle *h, i * WARNING: this code is required to be after compile */ if (xce->inode) { - char *filename = h->opened_path ? h->opened_path : h->filename; + const char *filename = h->opened_path ? h->opened_path : h->filename; if (xce->name.str.val != filename) { - xce->name.str.val = filename; + xce->name.str.val = (char *) filename; xce->name.str.len = strlen(filename); } } @@ -1978,7 +1963,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) / zend_op_array *op_array; xc_entry_t xce; xc_entry_data_php_t php; - char *filename; + const char *filename; assert(xc_initized); diff --git a/xcache.h b/xcache.h index 434c9b2..3beebfe 100644 --- a/xcache.h +++ b/xcache.h @@ -41,6 +41,11 @@ #else # define ZESW(v1, v2) v2 #endif +#ifdef ZEND_ENGINE_2_4 +# define ZEND_24(x) x +#else +# define ZEND_24(x) +#endif #ifdef do_alloca_with_limit # define my_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap) @@ -149,6 +154,14 @@ typedef znode znode_op; #ifndef IS_UNICODE typedef char *zstr; typedef const char *const_zstr; +#ifdef ZEND_ENGINE_2_4 +typedef const char *const24_zstr; +typedef const char *const24_str; +#else +typedef char *const24_zstr; +typedef char *const24_str; +#endif + # define ZSTR_S(s) (s) # define ZSTR_U(s) (s) # define ZSTR_V(s) (s) @@ -291,16 +304,16 @@ typedef struct { /* {{{ xc_classinfo_t */ typedef struct { #ifdef IS_UNICODE - zend_uchar type; + zend_uchar type; #endif - zstr key; - zend_uint key_size; - ulong h; - zend_uint methodinfo_cnt; + const24_zstr key; + zend_uint key_size; + ulong h; + zend_uint methodinfo_cnt; xc_op_array_info_t *methodinfos; - xc_cest_t cest; + xc_cest_t cest; #ifndef ZEND_COMPILE_DELAYED_BINDING - int oplineno; + int oplineno; #endif } xc_classinfo_t; /* }}} */ @@ -308,11 +321,11 @@ typedef struct { /* {{{ xc_constinfo_t */ typedef struct { #ifdef IS_UNICODE - zend_uchar type; + zend_uchar type; #endif - zstr key; - zend_uint key_size; - ulong h; + const24_zstr key; + zend_uint key_size; + ulong h; zend_constant constant; } xc_constinfo_t; /* }}} */ @@ -320,11 +333,11 @@ typedef struct { /* {{{ xc_funcinfo_t */ typedef struct { #ifdef IS_UNICODE - zend_uchar type; + zend_uchar type; #endif - zstr key; - zend_uint key_size; - ulong h; + const24_zstr key; + zend_uint key_size; + ulong h; xc_op_array_info_t op_array_info; zend_function func; } xc_funcinfo_t; @@ -333,11 +346,11 @@ typedef struct { /* {{{ xc_autoglobal_t */ typedef struct { #ifdef IS_UNICODE - zend_uchar type; + zend_uchar type; #endif - zstr key; - zend_uint key_len; - ulong h; + const24_zstr key; + zend_uint key_len; + ulong h; } xc_autoglobal_t; /* }}} */ #endif @@ -437,7 +450,7 @@ struct _xc_entry_t { /* php only */ int filepath_len; - char *filepath; + ZEND_24(const) char *filepath; int dirpath_len; char *dirpath; #ifdef IS_UNICODE