Index: trunk/xcache.c
===================================================================
--- trunk/xcache.c	(revision 858)
+++ trunk/xcache.c	(revision 859)
@@ -4,5 +4,5 @@
 #endif
 
-#if 0
+#if 1
 #define SHOW_DPRINT
 #endif
@@ -337,5 +337,5 @@
 					xc_entry_php_t *p_php = (xc_entry_php_t *) p;
 					xc_entry_php_t *xce_php = (xc_entry_php_t *) xce;
-					fresh = p_php->file_mtime == xce_php->file_mtime && p_php->php->file_size == xce_php->php->file_size;
+					fresh = p_php->file_mtime == xce_php->file_mtime && p_php->file_size == xce_php->file_size;
 				}
 				break;
@@ -364,9 +364,9 @@
 }
 /* }}} */
-static void xc_entry_hold_php_dmz(xc_cache_t *cache, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
-{
-	TRACE("hold %s", xce->entry.name.str.val);
-	xce->refcount ++;
-	xc_stack_push(&XG(php_holds)[cache->cacheid], (void *)xce);
+static void xc_entry_hold_php_dmz(xc_cache_t *cache, xc_entry_php_t *entry TSRMLS_DC) /* {{{ */
+{
+	TRACE("hold %d:%s", entry->file_inode, entry->entry.name.str.val);
+	entry->refcount ++;
+	xc_stack_push(&XG(php_holds)[cache->cacheid], (void *)entry);
 }
 /* }}} */
@@ -686,10 +686,10 @@
 			add_assoc_long_ex(ei, ZEND_STRS("size"),          entry->size + php->size);
 			add_assoc_long_ex(ei, ZEND_STRS("phprefcount"),   php->refcount);
-			add_assoc_long_ex(ei, ZEND_STRS("file_size"),     php->file_size);
+			add_assoc_long_ex(ei, ZEND_STRS("file_mtime"),    entry_php->file_mtime);
+			add_assoc_long_ex(ei, ZEND_STRS("file_size"),     entry_php->file_size);
 #ifdef HAVE_INODE
 			add_assoc_long_ex(ei, ZEND_STRS("file_device"),   entry_php->file_device);
 			add_assoc_long_ex(ei, ZEND_STRS("file_inode"),    entry_php->file_inode);
 #endif
-			add_assoc_long_ex(ei, ZEND_STRS("file_mtime"),    entry_php->file_mtime);
 
 #ifdef HAVE_XCACHE_CONSTANT
@@ -826,17 +826,17 @@
 	xc_stack_t *s;
 	xc_cache_t *cache;
-	xc_entry_t *xce;
+	xc_entry_php_t *xce;
 
 	for (i = 0; i < cachecount; i ++) {
 		s = &holds[i];
-		TRACE("holded %d", xc_stack_count(s));
+		TRACE("holded %d items", xc_stack_count(s));
 		if (xc_stack_count(s)) {
 			cache = caches[i];
 			ENTER_LOCK(cache) {
 				while (xc_stack_count(s)) {
-					xce = (xc_entry_t*) xc_stack_pop(s);
-					TRACE("unhold %s", xce->name.str.val);
-					((xc_entry_php_t *) xce)->refcount ++;
-					assert(((xc_entry_php_t *) xce)->refcount >= 0);
+					xce = (xc_entry_php_t *) xc_stack_pop(s);
+					TRACE("unhold %d:%s", xce->file_inode, xce->entry.name.str.val);
+					xce->refcount ++;
+					assert(xce->refcount >= 0);
 				}
 			} LEAVE_LOCK(cache);
@@ -905,22 +905,4 @@
 }
 /* }}} */
-
-#if 0 /* {{{ note about php hashing */
-the folling note is written in the form of "got = from"
-
-TODO: open_basedir
-
-opened_path = stat || zend_compile_file
-
-phphashid = inode ? inode : hash(basename)
-md5key = md5(relativepath)
-md5hashid = hash(md5key)
-cachehashid = multislot ? hash(basename) : hash(phphashid)
-
-cached = phphashid -> md5key -> cachedmd5info -> cachedphp
-cachedphp = [phphashid, fullpath]
-restoredphp = [fullpath, phphashid]
-
-#endif /* }}} */
 
 #define HASH(i) (i)
@@ -974,13 +956,4 @@
 /* }}} */
 #define xc_entry_hash_var xc_entry_hash_name
-static inline xc_hash_value_t xc_entry_hash_php(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
-{
-	return
-#ifdef HAVE_INODE
-		xce->file_inode ? HASH(xce->file_device + xce->file_inode) :
-#endif
-		xc_entry_hash_php_basename(xce TSRMLS_CC);
-}
-/* }}} */
 static void xc_entry_free_key_php(xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
 {
@@ -1000,13 +973,11 @@
 /* }}} */
 
-static int xc_entry_init_key_php(xc_entry_hash_t *entry_hash, xc_entry_php_t *xce, const char *filename TSRMLS_DC) /* {{{ */
-{
-	char opened_path_buffer[MAXPATHLEN];
-
-	if (!filename || !SG(request_info).path_translated) {
+static int xc_entry_init_key_php(xc_compiler_t *compiler TSRMLS_DC) /* {{{ */
+{
+	if (!compiler->filename || !SG(request_info).path_translated) {
 		return FAILURE;
 	}
 
-	if (strstr(filename, "://") != NULL) {
+	if (strstr(compiler->filename, "://") != NULL) {
 		return FAILURE;
 	}
@@ -1015,5 +986,5 @@
 		struct stat buf, *pbuf;
 
-		if (strcmp(SG(request_info).path_translated, filename) == 0) {
+		if (strcmp(SG(request_info).path_translated, compiler->filename) == 0) {
 			/* sapi has already done this stat() for us */
 			pbuf = sapi_get_stat(TSRMLS_C);
@@ -1025,6 +996,6 @@
 		/* absolute path */
 		pbuf = &buf;
-		if (IS_ABSOLUTE_PATH(filename, strlen(filename))) {
-			if (VCWD_STAT(filename, pbuf) != 0) {
+		if (IS_ABSOLUTE_PATH(compiler->filename, strlen(compiler->filename))) {
+			if (VCWD_STAT(compiler->filename, pbuf) != 0) {
 				return FAILURE;
 			}
@@ -1033,6 +1004,6 @@
 
 		/* relative path */
-		if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) {
-			const char *ptr = filename + 1;
+		if (*compiler->filename == '.' && (IS_SLASH(compiler->filename[1]) || compiler->filename[1] == '.')) {
+			const char *ptr = compiler->filename + 1;
 			if (*ptr == '.') {
 				while (*(++ptr) == '.');
@@ -1042,5 +1013,5 @@
 			}
 
-			if (VCWD_STAT(filename, pbuf) != 0) {
+			if (VCWD_STAT(compiler->filename, pbuf) != 0) {
 				return FAILURE;
 			}
@@ -1050,5 +1021,5 @@
 
 		/* use include_path */
-		if (xc_stat(filename, PG(include_path), pbuf TSRMLS_CC) != SUCCESS) {
+		if (xc_stat(compiler->filename, PG(include_path), pbuf TSRMLS_CC) != SUCCESS) {
 			return FAILURE;
 		}
@@ -1064,43 +1035,53 @@
 		}
 
-		xce->file_mtime   = pbuf->st_mtime;
+		compiler->new_entry.file_mtime   = pbuf->st_mtime;
+		compiler->new_entry.file_size    = pbuf->st_size;
 #ifdef HAVE_INODE
-		xce->file_device  = pbuf->st_dev;
-		xce->file_inode   = pbuf->st_ino;
-#endif
-		xce->php->file_size = pbuf->st_size;
+		compiler->new_entry.file_device  = pbuf->st_dev;
+		compiler->new_entry.file_inode   = pbuf->st_ino;
+#endif
 	}
 	else { /* XG(inode) */
-		xce->file_mtime   = 0;
+		compiler->new_entry.file_mtime   = 0;
+		compiler->new_entry.file_size    = 0;
 #ifdef HAVE_INODE
-		xce->file_device  = 0;
-		xce->file_inode   = 0;
-#endif
-		xce->php->file_size = 0;
-	}
-
+		compiler->new_entry.file_device  = 0;
+		compiler->new_entry.file_inode   = 0;
+#endif
+		compiler->opened_path = expand_filepath(compiler->filename, compiler->opened_path_buffer TSRMLS_CC);
+	}
+
+	UNISW(NOTHING, compiler->new_entry.entry.name_type = IS_STRING;)
+	compiler->new_entry.entry.name.str.val = (char *) (compiler->opened_path ? compiler->opened_path : compiler->filename);
+	compiler->new_entry.entry.name.str.len = strlen(compiler->new_entry.entry.name.str.val);
+
+	{
+		xc_hash_value_t basename_hash_value;
+		if (
+			xc_php_hcache.size > 1
 #ifdef HAVE_INODE
-	if (!xce->file_inode)
-#endif
-	{
-		/* hash on filename, let's expand it to real path */
-		/* FIXME */
-		filename = expand_filepath(filename, opened_path_buffer TSRMLS_CC);
-		if (filename == NULL) {
-			return FAILURE;
-		}
-	}
-
-	UNISW(NOTHING, xce->entry.name_type = IS_STRING;)
-	xce->entry.name.str.val = (char *) filename;
-	xce->entry.name.str.len = strlen(filename);
-
-	entry_hash->cacheslotid = xc_php_hcache.size > 1 ? xc_hash_fold(xc_entry_hash_php_basename(xce TSRMLS_CC), &xc_php_hcache) : 0;
-	entry_hash->entryslotid = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry);
-	xce->filepath  = NULL;
-	xce->dirpath   = NULL;
+			|| !compiler->new_entry.file_inode
+#endif
+			)
+		{
+			basename_hash_value = xc_entry_hash_php_basename(&compiler->new_entry TSRMLS_CC);
+		}
+
+		compiler->entry_hash.cacheid = xc_php_hcache.size > 1 ? xc_hash_fold(basename_hash_value, &xc_php_hcache) : 0;
+		compiler->entry_hash.entryslotid = xc_hash_fold(
+#ifdef HAVE_INODE
+				compiler->new_entry.file_inode
+				? HASH(compiler->new_entry.file_device + compiler->new_entry.file_inode)
+				:
+#endif
+				basename_hash_value
+				, &xc_php_hentry);
+	}
+
+	compiler->new_entry.filepath  = NULL;
+	compiler->new_entry.dirpath   = NULL;
 #ifdef IS_UNICODE
-	xce->ufilepath = NULL;
-	xce->udirpath  = NULL;
+	compiler->new_entry.ufilepath = NULL;
+	compiler->new_entry.udirpath  = NULL;
 #endif
 
@@ -1113,5 +1094,5 @@
 }
 /* }}} */
-static int xc_entry_init_key_php_md5(xc_cache_t *cache, xc_entry_data_php_t *php, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */
+static int xc_entry_init_key_php_md5(xc_cache_t *cache, xc_compiler_t *compiler TSRMLS_DC) /* {{{ */
 {
 	unsigned char   buf[1024];
@@ -1121,5 +1102,5 @@
 	ulong           old_rsid = EG(regular_list).nNextFreeElement;
 
-	stream = php_stream_open_wrapper(xce->entry.name.str.val, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL);
+	stream = php_stream_open_wrapper(compiler->new_entry.entry.name.str.val, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL);
 	if (!stream) {
 		return FAILURE;
@@ -1130,5 +1111,5 @@
 		PHP_MD5Update(&context, buf, n);
 	}
-	PHP_MD5Final((unsigned char *) php->md5.digest, &context);
+	PHP_MD5Final((unsigned char *) compiler->new_php.md5.digest, &context);
 
 	php_stream_close(stream);
@@ -1141,9 +1122,9 @@
 	}
 
-	php->hvalue = (xc_php_hash_md5(php TSRMLS_CC) & cache->hphp->mask);
+	compiler->new_php.hvalue = (xc_php_hash_md5(&compiler->new_php TSRMLS_CC) & cache->hphp->mask);
 #ifdef XCACHE_DEBUG
 	{
 		char md5str[33];
-		make_digest(md5str, (unsigned char *) php->md5.digest);
+		make_digest(md5str, (unsigned char *) compiler->new_php.md5.digest);
 		TRACE("md5 %s", md5str);
 	}
@@ -1153,13 +1134,13 @@
 }
 /* }}} */
-static void xc_entry_init_key_php_entry(xc_entry_php_t *xce, ZEND_24(const) char *filepath TSRMLS_DC) /* {{{*/
-{
-	xce->filepath     = filepath;
-	xce->filepath_len = strlen(xce->filepath);
-	xce->dirpath      = estrndup(xce->filepath, xce->filepath_len);
-	xce->dirpath_len  = zend_dirname(xce->dirpath, xce->filepath_len);
+static void xc_entry_init_key_php_entry(xc_entry_php_t *entry_php, ZEND_24(const) char *filepath TSRMLS_DC) /* {{{*/
+{
+	entry_php->filepath     = filepath;
+	entry_php->filepath_len = strlen(entry_php->filepath);
+	entry_php->dirpath      = estrndup(entry_php->filepath, entry_php->filepath_len);
+	entry_php->dirpath_len  = zend_dirname(entry_php->dirpath, entry_php->filepath_len);
 #ifdef IS_UNICODE
-	zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &xce->ufilepath, &xce->ufilepath_len, xce->filepath, xce->filepath_len TSRMLS_CC);
-	zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &xce->udirpath,  &xce->udirpath_len,  xce->dirpath,  xce->dirpath_len TSRMLS_CC);
+	zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &entry_php->ufilepath, &entry_php->ufilepath_len, entry_php->filepath, entry_php->filepath_len TSRMLS_CC);
+	zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &entry_php->udirpath,  &entry_php->udirpath_len,  entry_php->dirpath,  entry_php->dirpath_len TSRMLS_CC);
 #endif
 }
@@ -1212,5 +1193,5 @@
 } xc_const_usage_t;
 /* }}} */
-static void xc_collect_op_array_info(xc_entry_php_t *xce, xc_entry_data_php_t *php, xc_const_usage_t *usage, xc_op_array_info_t *op_array_info, zend_op_array *op_array TSRMLS_DC) /* {{{ */
+static void xc_collect_op_array_info(xc_compiler_t *compiler, xc_const_usage_t *usage, xc_op_array_info_t *op_array_info, zend_op_array *op_array TSRMLS_DC) /* {{{ */
 {
 	int i;
@@ -1220,5 +1201,5 @@
 
 #define XCACHE_ANALYZE_LITERAL(type) \
-	if (zend_binary_strcmp(Z_STRVAL(literal->constant), Z_STRLEN(literal->constant), xce->type##path, xce->type##path_len) == 0) { \
+	if (zend_binary_strcmp(Z_STRVAL(literal->constant), Z_STRLEN(literal->constant), compiler->new_entry.type##path, compiler->new_entry.type##path_len) == 0) { \
 		usage->type##path_used = 1; \
 		literalinfo |= xcache_##literal##_is_##type; \
@@ -1226,5 +1207,5 @@
 
 #define XCACHE_U_ANALYZE_LITERAL(type) \
-	if (zend_u_##binary_strcmp(Z_USTRVAL(literal->constant), Z_USTRLEN(literal->constant), xce->u##type##path, xce->u##type##path_len) == 0) { \
+	if (zend_u_##binary_strcmp(Z_USTRVAL(literal->constant), Z_USTRLEN(literal->constant), compiler->new_entry.u##type##path, compiler->new_entry.u##type##path_len) == 0) { \
 		usage->u##type##path_used = 1; \
 		literalinfo |= xcache_##literal##_is_##type; \
@@ -1232,5 +1213,5 @@
 
 #define XCACHE_ANALYZE_OP(type, op) \
-	if (zend_binary_strcmp(Z_STRVAL(Z_OP_CONSTANT(opline->op)), Z_STRLEN(Z_OP_CONSTANT(opline->op)), xce->type##path, xce->type##path_len) == 0) { \
+	if (zend_binary_strcmp(Z_STRVAL(Z_OP_CONSTANT(opline->op)), Z_STRLEN(Z_OP_CONSTANT(opline->op)), compiler->new_entry.type##path, compiler->new_entry.type##path_len) == 0) { \
 		usage->type##path_used = 1; \
 		oplineinfo |= xcache_##op##_is_##type; \
@@ -1238,5 +1219,5 @@
 
 #define XCACHE_U_ANALYZE_OP(type, op) \
-	if (zend_u_##binary_strcmp(Z_USTRVAL(Z_OP_CONSTANT(opline->op)), Z_USTRLEN(Z_OP_CONSTANT(opline->op)), xce->u##type##path, xce->u##type##path_len) == 0) { \
+	if (zend_u_##binary_strcmp(Z_USTRVAL(Z_OP_CONSTANT(opline->op)), Z_USTRLEN(Z_OP_CONSTANT(opline->op)), compiler->new_entry.u##type##path, compiler->new_entry.u##type##path_len) == 0) { \
 		usage->u##type##path_used = 1; \
 		oplineinfo |= xcache_##op##_is_##type; \
@@ -1502,5 +1483,5 @@
 }
 /* }}} */
-static zend_op_array *xc_compile_php(xc_entry_php_t *xce, xc_entry_data_php_t *php, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
+static zend_op_array *xc_compile_php(xc_compiler_t *compiler, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
 {
 	zend_op_array *op_array;
@@ -1515,5 +1496,5 @@
 	old_constinfo_cnt = zend_hash_num_elements(EG(zend_constants));
 
-	php->op_array = NULL;
+	compiler->new_php.op_array = NULL;
 	XG(initial_compile_file_called) = 0;
 	zend_try {
@@ -1538,21 +1519,21 @@
 	/* {{{ prepare */
 	zend_restore_compiled_filename(h->opened_path ? h->opened_path : (char *) h->filename TSRMLS_CC);
-	php->op_array      = op_array;
+	compiler->new_php.op_array = op_array;
 
 #ifdef HAVE_XCACHE_CONSTANT
-	php->constinfo_cnt  = zend_hash_num_elements(EG(zend_constants)) - old_constinfo_cnt;
-#endif
-	php->funcinfo_cnt   = zend_hash_num_elements(CG(function_table)) - old_funcinfo_cnt;
-	php->classinfo_cnt  = zend_hash_num_elements(CG(class_table))    - old_classinfo_cnt;
+	compiler->new_php.constinfo_cnt  = zend_hash_num_elements(EG(zend_constants)) - old_constinfo_cnt;
+#endif
+	compiler->new_php.funcinfo_cnt   = zend_hash_num_elements(CG(function_table)) - old_funcinfo_cnt;
+	compiler->new_php.classinfo_cnt  = zend_hash_num_elements(CG(class_table))    - old_classinfo_cnt;
 #ifdef ZEND_ENGINE_2_1
-	/* {{{ count php->autoglobal_cnt */ {
+	/* {{{ count new_php.autoglobal_cnt */ {
 		Bucket *b;
 
-		php->autoglobal_cnt = 0;
+		compiler->new_php.autoglobal_cnt = 0;
 		for (b = CG(auto_globals)->pListHead; b != NULL; b = b->pListNext) {
 			zend_auto_global *auto_global = (zend_auto_global *) b->pData;
 			/* check if actived */
 			if (auto_global->auto_global_callback && !auto_global->armed) {
-				php->autoglobal_cnt ++;
+				compiler->new_php.autoglobal_cnt ++;
 			}
 		}
@@ -1562,12 +1543,12 @@
 
 #define X_ALLOC_N(var, cnt) do {     \
-	if (php->cnt) {                  \
-		ECALLOC_N(php->var, php->cnt); \
-		if (!php->var) {             \
+	if (compiler->new_php.cnt) {                  \
+		ECALLOC_N(compiler->new_php.var, compiler->new_php.cnt); \
+		if (!compiler->new_php.var) {             \
 			goto err_alloc;          \
 		}                            \
 	}                                \
 	else {                           \
-		php->var = NULL;             \
+		compiler->new_php.var = NULL;             \
 	}                                \
 } while (0)
@@ -1591,5 +1572,5 @@
 #define COPY_H(vartype, var, cnt, name, datatype) do {        \
 	for (i = 0, j = 0; b; i ++, b = b->pListNext) {           \
-		vartype *data = &php->var[j];                         \
+		vartype *data = &compiler->new_php.var[j];                         \
                                                               \
 		if (i < old_##cnt) {                                  \
@@ -1598,5 +1579,5 @@
 		j ++;                                                 \
                                                               \
-		assert(i < old_##cnt + php->cnt);                     \
+		assert(i < old_##cnt + compiler->new_php.cnt);                     \
 		assert(b->pData);                                     \
 		memcpy(&data->name, b->pData, sizeof(datatype));      \
@@ -1630,7 +1611,7 @@
 			/* check if actived */
 			if (auto_global->auto_global_callback && !auto_global->armed) {
-				xc_autoglobal_t *data = &php->autoglobals[i];
-
-				assert(i < php->autoglobal_cnt);
+				xc_autoglobal_t *data = &compiler->new_php.autoglobals[i];
+
+				assert(i < compiler->new_php.autoglobal_cnt);
 				i ++;
 				UNISW(NOTHING, data->type = b->key.type;)
@@ -1654,9 +1635,9 @@
 		unsigned int i;
 
-		xc_entry_init_key_php_entry(xce, zend_get_compiled_filename(TSRMLS_C) TSRMLS_CC);
+		xc_entry_init_key_php_entry(&compiler->new_entry, zend_get_compiled_filename(TSRMLS_C) TSRMLS_CC);
 		memset(&const_usage, 0, sizeof(const_usage));
 
-		for (i = 0; i < php->classinfo_cnt; i ++) {
-			xc_classinfo_t *classinfo = &php->classinfos[i];
+		for (i = 0; i < compiler->new_php.classinfo_cnt; i ++) {
+			xc_classinfo_t *classinfo = &compiler->new_php.classinfos[i];
 			zend_class_entry *ce = CestToCePtr(classinfo->cest);
 			classinfo->methodinfo_cnt = ce->function_table.nTableSize;
@@ -1670,5 +1651,5 @@
 
 				for (j = 0, b = ce->function_table.pListHead; b; j ++, b = b->pListNext) {
-					xc_collect_op_array_info(xce, php, &const_usage, &classinfo->methodinfos[j], (zend_op_array *) b->pData TSRMLS_CC);
+					xc_collect_op_array_info(compiler, &const_usage, &classinfo->methodinfos[j], (zend_op_array *) b->pData TSRMLS_CC);
 				}
 			}
@@ -1678,16 +1659,16 @@
 		}
 
-		for (i = 0; i < php->funcinfo_cnt; i ++) {
-			xc_collect_op_array_info(xce, php, &const_usage, &php->funcinfos[i].op_array_info, (zend_op_array *) &php->funcinfos[i].func TSRMLS_CC);
-		}
-
-		xc_collect_op_array_info(xce, php, &const_usage, &php->op_array_info, php->op_array TSRMLS_CC);
+		for (i = 0; i < compiler->new_php.funcinfo_cnt; i ++) {
+			xc_collect_op_array_info(compiler, &const_usage, &compiler->new_php.funcinfos[i].op_array_info, (zend_op_array *) &compiler->new_php.funcinfos[i].func TSRMLS_CC);
+		}
+
+		xc_collect_op_array_info(compiler, &const_usage, &compiler->new_php.op_array_info, compiler->new_php.op_array TSRMLS_CC);
 
 		/* file/dir path free unused */
 #define X_FREE_UNUSED(var) \
 		if (!const_usage.var##path_used) { \
-			efree(xce->var##path); \
-			xce->var##path = NULL; \
-			xce->var##path_len = 0; \
+			efree(compiler->new_entry.var##path); \
+			compiler->new_entry.var##path = NULL; \
+			compiler->new_entry.var##path_len = 0; \
 		}
 		/* filepath is required to restore op_array->filename, so no free filepath here */
@@ -1701,20 +1682,20 @@
 	/* }}} */
 #ifdef XCACHE_ERROR_CACHING
-	php->compilererrors = ((xc_sandbox_t *) XG(sandbox))->compilererrors;
-	php->compilererror_cnt = ((xc_sandbox_t *) XG(sandbox))->compilererror_cnt;
+	compiler->new_php.compilererrors = ((xc_sandbox_t *) XG(sandbox))->compilererrors;
+	compiler->new_php.compilererror_cnt = ((xc_sandbox_t *) XG(sandbox))->compilererror_cnt;
 #endif
 #ifndef ZEND_COMPILE_DELAYED_BINDING
 	/* {{{ find inherited classes that should be early-binding */
-	php->have_early_binding = 0;
+	compiler->new_php.have_early_binding = 0;
 	{
 		int i;
-		for (i = 0; i < php->classinfo_cnt; i ++) {
-			php->classinfos[i].oplineno = -1;
-		}
-	}
-
-	xc_undo_pass_two(php->op_array TSRMLS_CC);
-	xc_foreach_early_binding_class(php->op_array, xc_cache_early_binding_class_cb, (void *) php TSRMLS_CC);
-	xc_redo_pass_two(php->op_array TSRMLS_CC);
+		for (i = 0; i < compiler->new_php.classinfo_cnt; i ++) {
+			compiler->new_php.classinfos[i].oplineno = -1;
+		}
+	}
+
+	xc_undo_pass_two(compiler->new_php.op_array TSRMLS_CC);
+	xc_foreach_early_binding_class(compiler->new_php.op_array, xc_cache_early_binding_class_cb, (void *) compiler->new_php.SRMLS_CC);
+	xc_redo_pass_two(compiler->new_php.op_array TSRMLS_CC);
 	/* }}} */
 #endif
@@ -1723,5 +1704,5 @@
 
 err_alloc:
-	xc_free_php(php TSRMLS_CC);
+	xc_free_php(&compiler->new_php TSRMLS_CC);
 
 err_bailout:
@@ -1735,25 +1716,25 @@
 }
 /* }}} */
-static zend_op_array *xc_compile_restore(xc_entry_php_t *stored_xce, zend_file_handle *h TSRMLS_DC) /* {{{ */
+static zend_op_array *xc_compile_restore(xc_entry_php_t *stored_entry, xc_entry_data_php_t *stored_php, zend_file_handle *h TSRMLS_DC) /* {{{ */
 {
 	zend_op_array *op_array;
-	xc_entry_php_t xce;
-	xc_entry_data_php_t php;
+	xc_entry_php_t restored_entry;
+	xc_entry_data_php_t restored_php;
 	zend_bool catched;
 
 	CG(in_compilation)    = 1;
-	CG(compiled_filename) = stored_xce->entry.name.str.val;
+	CG(compiled_filename) = stored_entry->entry.name.str.val;
 	CG(zend_lineno)       = 0;
-	TRACE("restoring %s", stored_xce->entry.name.str.val);
-	xc_processor_restore_xc_entry_php_t(&xce, stored_xce TSRMLS_CC);
-	xc_processor_restore_xc_entry_data_php_t(stored_xce, &php, xce.php, xc_readonly_protection TSRMLS_CC);
-	xce.php = &php;
+	TRACE("restoring %d:%s", stored_entry->file_inode, stored_entry->entry.name.str.val);
+	xc_processor_restore_xc_entry_php_t(&restored_entry, stored_entry TSRMLS_CC);
+	xc_processor_restore_xc_entry_data_php_t(stored_entry, &restored_php, stored_php, xc_readonly_protection TSRMLS_CC);
+	restored_entry.php = &restored_php;
 #ifdef SHOW_DPRINT
-	xc_dprint(&xce, 0 TSRMLS_CC);
+	xc_dprint(&restored_entry, 0 TSRMLS_CC);
 #endif
 
 	catched = 0;
 	zend_try {
-		op_array = xc_entry_install(&xce, h TSRMLS_CC);
+		op_array = xc_entry_install(&restored_entry, h TSRMLS_CC);
 	} zend_catch {
 		catched = 1;
@@ -1761,13 +1742,13 @@
 
 #ifdef HAVE_XCACHE_CONSTANT
-	if (php.constinfos) {
-		efree(php.constinfos);
-	}
-#endif
-	if (php.funcinfos) {
-		efree(php.funcinfos);
-	}
-	if (php.classinfos) {
-		efree(php.classinfos);
+	if (restored_php.constinfos) {
+		efree(restored_php.constinfos);
+	}
+#endif
+	if (restored_php.funcinfos) {
+		efree(restored_php.funcinfos);
+	}
+	if (restored_php.classinfos) {
+		efree(restored_php.classinfos);
 	}
 
@@ -1777,5 +1758,5 @@
 	CG(in_compilation)    = 0;
 	CG(compiled_filename) = NULL;
-	TRACE("restored  %s", stored_xce->entry.name.str.val);
+	TRACE("restored %d:%s", stored_entry->file_inode, stored_entry->entry.name.str.val);
 	return op_array;
 }
@@ -1787,14 +1768,37 @@
 }
 /* }}} */
-static zend_op_array *xc_compile_file_ex(xc_entry_hash_t *entry_hash, xc_entry_php_t *xce, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
-{
+static zend_op_array *xc_compile_file_ex(xc_compiler_t *compiler, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
+{
+	/*
+	if (clog) {
+		return old;
+	}
+
+	if (cached_entry = getby entry_hash) {
+		php = cached_entry.php;
+		php = restore(php);
+		return php;
+	}
+	else {
+		if (!(php = getby md5)) {
+			if (clog) {
+				return old;
+			}
+			php = compile();
+			entry = create entries[entry];
+		}
+
+		entry.php = php;
+		return php;
+	}
+	*/
+
 	zend_op_array *op_array;
-	xc_entry_php_t *stored_xce;
+	xc_entry_php_t *stored_entry;
 	xc_entry_data_php_t *stored_php;
 	zend_bool gaveup = 0;
 	zend_bool catched = 0;
-	zend_bool newlycompiled;
 	xc_sandbox_t sandbox;
-	xc_cache_t *cache = xc_php_caches[entry_hash->cacheslotid];
+	xc_cache_t *cache = xc_php_caches[compiler->entry_hash.cacheid];
 
 	/* stale clogs precheck */
@@ -1803,42 +1807,52 @@
 		return old_compile_file(h, type TSRMLS_CC);
 	}
+
 	/* {{{ entry_lookup/hit/md5_init/php_lookup */
-	stored_xce = NULL;
+	stored_entry = NULL;
 	stored_php = NULL;
 	ENTER_LOCK_EX(cache) {
-		stored_xce = (xc_entry_php_t *) xc_entry_find_dmz(XC_TYPE_PHP, cache, entry_hash->entryslotid, (xc_entry_t *) xce TSRMLS_CC);
-		if (stored_xce) {
+		stored_entry = (xc_entry_php_t *) xc_entry_find_dmz(XC_TYPE_PHP, cache, compiler->entry_hash.entryslotid, (xc_entry_t *) &compiler->new_entry TSRMLS_CC);
+		if (stored_entry) {
 			xc_cache_hit_dmz(cache TSRMLS_CC);
 
-			TRACE("hit %s, holding", stored_xce->entry.name.str.val);
-			xc_entry_hold_php_dmz(cache, stored_xce TSRMLS_CC);
-		}
-		else {
-			cache->misses ++;
-			TRACE("miss %s", xce->entry.name.str.val);
-
-			if (xc_entry_init_key_php_md5(cache, xce->php, xce TSRMLS_CC) != SUCCESS) {
-				gaveup = 1;
-				break;
-			}
-
-			stored_php = xc_php_find_dmz(cache, xce->php TSRMLS_CC);
-
-			/* miss but compiling */
-			if (!stored_php) {
-				if (XG(request_time) - cache->compiling < 30) {
-					TRACE("%s", "miss but compiling");
-					cache->clogs ++;
-					gaveup = 1;
-					break;
-				}
-				TRACE("%s", "php_lookup miss");
-			}
-			else {
-				TRACE("%s", "php_lookup hit");
-			}
-
-			cache->compiling = XG(request_time);
-		}
+			TRACE(" hit %d:%s, holding", compiler->new_entry.file_inode, stored_entry->entry.name.str.val);
+			xc_entry_hold_php_dmz(cache, stored_entry TSRMLS_CC);
+			stored_php = stored_entry->php;
+			break;
+		}
+
+		cache->misses ++;
+		TRACE("miss entry %d:%s", compiler->new_entry.file_inode, compiler->new_entry.entry.name.str.val);
+
+		if (xc_entry_init_key_php_md5(cache, compiler TSRMLS_CC) != SUCCESS) {
+			gaveup = 1;
+			break;
+		}
+
+		stored_php = xc_php_find_dmz(cache, &compiler->new_php TSRMLS_CC);
+
+		/* miss but compiling */
+		if (stored_php) {
+			compiler->new_entry.php = stored_php;
+			xc_php_addref_dmz(stored_php);
+			if (!compiler->opened_path) {
+				compiler->opened_path = expand_filepath(compiler->filename, compiler->opened_path_buffer TSRMLS_CC);
+			}
+			xc_entry_init_key_php_entry(&compiler->new_entry, compiler->opened_path TSRMLS_CC);
+			stored_entry = xc_entry_php_store_dmz(cache, compiler->entry_hash.entryslotid, &compiler->new_entry TSRMLS_CC);
+			TRACE(" cached %d:%s, holding", compiler->new_entry.file_inode, stored_entry->entry.name.str.val);
+			xc_entry_hold_php_dmz(cache, stored_entry TSRMLS_CC);
+			break;
+		}
+
+		if (XG(request_time) - cache->compiling < 30) {
+			TRACE("%s", "miss php, but compiling");
+			cache->clogs ++;
+			gaveup = 1;
+			break;
+		}
+
+		TRACE("%s", "miss php, going to compile");
+		cache->compiling = XG(request_time);
 	} LEAVE_LOCK_EX(cache);
 
@@ -1848,7 +1862,7 @@
 	}
 
-	/* hit */
-	if (stored_xce) {
-		return xc_compile_restore(stored_xce, h TSRMLS_CC);
+	/* found entry */
+	if (stored_entry) {
+		return xc_compile_restore(stored_entry, stored_php, h TSRMLS_CC);
 	}
 
@@ -1858,89 +1872,60 @@
 	}
 	/* }}} */
+
 	op_array = NULL;
 	/* {{{ compile */
-	if (stored_php) {
-		newlycompiled = 0;
-		xc_entry_init_key_php_entry(xce, h->opened_path ? h->opened_path : h->filename TSRMLS_CC);
-		xce->php = stored_php;
-	}
-	else {
-		newlycompiled = 1;
-
-		/* make compile inside sandbox */
-		xc_sandbox_init(&sandbox, h->opened_path ? h->opened_path : h->filename TSRMLS_CC);
+	/* make compile inside sandbox */
+	xc_sandbox_init(&sandbox, h->opened_path ? h->opened_path : h->filename TSRMLS_CC);
 
 #ifdef HAVE_XCACHE_CONSTANT
-		xce->php->constinfos  = NULL;
-#endif
-		xce->php->funcinfos   = NULL;
-		xce->php->classinfos  = NULL;
+	compiler->new_php.constinfos  = NULL;
+#endif
+	compiler->new_php.funcinfos   = NULL;
+	compiler->new_php.classinfos  = NULL;
 #ifdef ZEND_ENGINE_2_1
-		xce->php->autoglobals = NULL;
-#endif
-
-		memset(&xce->php->op_array_info, 0, sizeof(xce->php->op_array_info));
-
-		zend_try {
-			op_array = xc_compile_php(xce, xce->php, h, type TSRMLS_CC);
-		} zend_catch {
-			catched = 1;
-		} zend_end_try();
-
-		if (catched || !op_array) {
-			goto err_aftersandbox;
-		}
-
-		/* not cachable */
-		if (!xce->php->op_array) {
-			cache->compiling = 0;
-			/* it's not cachable, but don't scare the users with high misses */
-			cache->misses --;
-			xc_sandbox_free(&sandbox, XC_InstallNoBinding TSRMLS_CC);
-			return op_array;
-		}
+	compiler->new_php.autoglobals = NULL;
+#endif
+	memset(&compiler->new_php.op_array_info, 0, sizeof(compiler->new_php.op_array_info));
+
+	zend_try {
+		op_array = xc_compile_php(compiler, h, type TSRMLS_CC);
+	} zend_catch {
+		catched = 1;
+	} zend_end_try();
+
+	if (catched || !op_array) {
+		goto err_aftersandbox;
+	}
+
+	/* not cachable */
+	if (!compiler->new_php.op_array) {
+		cache->compiling = 0;
+		/* it's not cachable, but don't scare the users with high misses */
+		cache->misses --;
+		xc_sandbox_free(&sandbox, XC_InstallNoBinding TSRMLS_CC);
+		return op_array;
 	}
 	/* }}} */
-#ifdef HAVE_INODE
-	/* {{{ path name fix
-	 * inode enabled entry hash/compare on name
-	 * do not update to its name to real pathname
-	 * WARNING: this code is required to be after compile
-	 */
-	if (xce->file_inode) {
-		const char *filename = h->opened_path ? h->opened_path : h->filename;
-		if (xce->entry.name.str.val != filename) {
-			xce->entry.name.str.val = (char *) filename;
-			xce->entry.name.str.len = strlen(filename);
-		}
-	}
-	/* }}} */
-#endif
 #ifdef SHOW_DPRINT
-	xc_dprint(xce, 0 TSRMLS_CC);
-#endif
-	stored_xce = NULL;
+	compiler->new_entry.php = &compiler->new_php;
+	xc_dprint(&compiler->new_entry, 0 TSRMLS_CC);
+#endif
 	ENTER_LOCK_EX(cache) { /* {{{ php_store/entry_store */
 		/* php_store */
-		if (newlycompiled) {
-			stored_php = xc_php_store_dmz(cache, xce->php TSRMLS_CC);
-			if (!stored_php) {
-				/* error */
-				break;
-			}
+		stored_php = xc_php_store_dmz(cache, &compiler->new_php TSRMLS_CC);
+		if (!stored_php) {
+			/* error */
+			break;
 		}
 		/* entry_store */
+		compiler->new_entry.php = stored_php;
 		xc_php_addref_dmz(stored_php);
-		stored_xce = xc_entry_php_store_dmz(cache, entry_hash->entryslotid, xce TSRMLS_CC);
-		if (stored_xce) {
-			stored_xce->php = stored_php;
-		}
-		else {
-			/* error */
+		stored_entry = xc_entry_php_store_dmz(cache, compiler->entry_hash.entryslotid, &compiler->new_entry TSRMLS_CC);
+		if (!stored_entry) {
 			xc_php_release_dmz(cache, stored_php);
 		}
 	} LEAVE_LOCK_EX(cache);
 	/* }}} */
-	TRACE("%s", stored_xce ? "stored" : "store failed");
+	TRACE("%s", stored_entry ? "stored" : "store failed");
 
 	cache->compiling = 0;
@@ -1949,9 +1934,7 @@
 	}
 
-	if (newlycompiled) {
-		xc_free_php(xce->php TSRMLS_CC);
-	}
-
-	if (stored_xce) {
+	xc_free_php(&compiler->new_php TSRMLS_CC);
+
+	if (stored_entry) {
 		if (op_array) {
 #ifdef ZEND_ENGINE_2
@@ -1963,25 +1946,19 @@
 			h = NULL;
 		}
-		if (newlycompiled) {
-			xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
-		}
-		return xc_compile_restore(stored_xce, h TSRMLS_CC);
+		xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
+		return xc_compile_restore(stored_entry, stored_php, h TSRMLS_CC);
 	}
 	else {
-		if (newlycompiled) {
-			zend_op_array *old_active_op_array = CG(active_op_array);
-			/* install it */
-			CG(active_op_array) = op_array;
-			xc_sandbox_free(&sandbox, XC_Install TSRMLS_CC);
-			CG(active_op_array) = old_active_op_array;
-		}
+		zend_op_array *old_active_op_array = CG(active_op_array);
+		/* install it */
+		CG(active_op_array) = op_array;
+		xc_sandbox_free(&sandbox, XC_Install TSRMLS_CC);
+		CG(active_op_array) = old_active_op_array;
 	}
 	return op_array;
 
 err_aftersandbox:
-	if (newlycompiled) {
-		xc_free_php(xce->php TSRMLS_CC);
-		xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
-	}
+	xc_free_php(&compiler->new_php TSRMLS_CC);
+	xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC);
 
 	if (catched) {
@@ -1995,30 +1972,28 @@
 static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
 {
+	xc_compiler_t compiler;
 	zend_op_array *op_array;
-	xc_entry_php_t xce;
-	xc_entry_hash_t entry_hash;
-	xc_entry_data_php_t php;
-	const char *filename;
 
 	assert(xc_initized);
 
-	TRACE("type = %d\n", h->type);
+	TRACE("xc_compile_file: type=%d name=%s", h->type, h->filename ? h->filename : "NULL");
 	if (!XG(cacher)) {
 		op_array = old_compile_file(h, type TSRMLS_CC);
+		TRACE("%s", "cacher not enabled");
 		return op_array;
 	}
 
 	/* {{{ entry_init_key */
-	filename = h->opened_path ? h->opened_path : h->filename;
-	xce.php = &php;
-	if (xc_entry_init_key_php(&entry_hash, &xce, filename TSRMLS_CC) != SUCCESS) {
-		TRACE("failed to init key for %s", filename);
+	compiler.opened_path = h->opened_path;
+	compiler.filename = compiler.opened_path ? compiler.opened_path : h->filename;
+	if (xc_entry_init_key_php(&compiler TSRMLS_CC) != SUCCESS) {
+		TRACE("failed to init key for %s", compiler.filename);
 		return old_compile_file(h, type TSRMLS_CC);
 	}
 	/* }}} */
 
-	op_array = xc_compile_file_ex(&entry_hash, &xce, h, type TSRMLS_CC);
-
-	xc_entry_free_key_php(&xce TSRMLS_CC);
+	op_array = xc_compile_file_ex(&compiler, h, type TSRMLS_CC);
+
+	xc_entry_free_key_php(&compiler.new_entry TSRMLS_CC);
 
 	return op_array;
@@ -2676,5 +2651,5 @@
 	hv = xc_entry_hash_var((xc_entry_t *) xce TSRMLS_CC);
 
-	entry_hash->cacheslotid = (hv & xc_var_hcache.mask);
+	entry_hash->cacheid = (hv & xc_var_hcache.mask);
 	hv >>= xc_var_hcache.bits;
 	entry_hash->entryslotid = (hv & xc_var_hentry.mask);
@@ -2700,5 +2675,5 @@
 	}
 	xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
-	cache = xc_var_caches[entry_hash.cacheslotid];
+	cache = xc_var_caches[entry_hash.cacheid];
 
 	ENTER_LOCK(cache) {
@@ -2742,5 +2717,5 @@
 
 	xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
-	cache = xc_var_caches[entry_hash.cacheslotid];
+	cache = xc_var_caches[entry_hash.cacheid];
 
 	ENTER_LOCK(cache) {
@@ -2772,5 +2747,5 @@
 	}
 	xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
-	cache = xc_var_caches[entry_hash.cacheslotid];
+	cache = xc_var_caches[entry_hash.cacheid];
 
 	ENTER_LOCK(cache) {
@@ -2806,5 +2781,5 @@
 	}
 	xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
-	cache = xc_var_caches[entry_hash.cacheslotid];
+	cache = xc_var_caches[entry_hash.cacheid];
 
 	ENTER_LOCK(cache) {
@@ -2879,5 +2854,5 @@
 
 	xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC);
-	cache = xc_var_caches[entry_hash.cacheslotid];
+	cache = xc_var_caches[entry_hash.cacheid];
 
 	ENTER_LOCK(cache) {
@@ -2918,7 +2893,7 @@
 			xce.entry.ctime = stored_xce->entry.ctime;
 			xce.entry.hits  = stored_xce->entry.hits;
-			xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
-		}
-		xc_entry_var_store_dmz(cache, entry_hash.cacheslotid, &xce TSRMLS_CC);
+			xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC);
+		}
+		xc_entry_var_store_dmz(cache, entry_hash.entryslotid, &xce TSRMLS_CC);
 
 	} LEAVE_LOCK(cache);
