New PHP5 APC - version 3.0.19, using PHP5 5.2.0-8+etch11,
[php5-apc.git] / apc_main.c
index 3cfb279..3825399 100644 (file)
@@ -2,7 +2,7 @@
   +----------------------------------------------------------------------+
   | APC                                                                  |
   +----------------------------------------------------------------------+
-  | Copyright (c) 2006 The PHP Group                                     |
+  | Copyright (c) 2008 The PHP Group                                     |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
@@ -28,7 +28,7 @@
 
  */
 
-/* $Id: apc_main.c,v 3.103.2.2 2008/03/28 18:35:40 gopalv Exp $ */
+/* $Id: apc_main.c,v 3.103.2.7 2008/05/11 18:57:00 rasmus Exp $ */
 
 #include "apc_php.h"
 #include "apc_main.h"
@@ -279,7 +279,9 @@ default_compile:
     apc_cache_release(apc_cache, cache_entry);
 
     /* cannot free up cache data yet, it maybe in use */
-    
+   
+    zend_llist_del_element(&CG(open_files), h, compare_file_handles); /* We leak fds without this hack */
+
     h->type = ZEND_HANDLE_FILENAME;
 
     return NULL;
@@ -345,12 +347,13 @@ static zend_op_array* my_compile_file(zend_file_handle* h,
 
     if (cache_entry != NULL) {
         int dummy = 1;
-        int reset_opened_path = 0; 
         if (h->opened_path == NULL) {
-            h->opened_path = cache_entry->data.file.filename;
-            reset_opened_path = 1;
+            h->opened_path = estrdup(cache_entry->data.file.filename);
         }
         zend_hash_add(&EG(included_files), h->opened_path, strlen(h->opened_path)+1, (void *)&dummy, sizeof(int), NULL);
+
+        zend_llist_add_element(&CG(open_files), h); /* We leak fds without this hack */
+
         apc_stack_push(APCG(cache_stack), cache_entry);
         op_array = cached_compile(h, type TSRMLS_CC);
         if(op_array) {
@@ -363,9 +366,6 @@ static zend_op_array* my_compile_file(zend_file_handle* h,
         if(APCG(report_autofilter)) {
             apc_wprint("Recompiling %s", h->opened_path);
         }
-        if (reset_opened_path == 1) {
-            h->opened_path = NULL;
-        }
         /* TODO: check what happens with EG(included_files) */
     }
     
@@ -430,10 +430,10 @@ static zend_op_array* my_compile_file(zend_file_handle* h,
 
     mem_size = 0;
     APCG(mem_size_ptr) = &mem_size;
-    APCG(current_cache) = apc_cache;
     if(!(alloc_op_array = apc_copy_op_array(NULL, op_array, apc_sma_malloc, apc_sma_free TSRMLS_CC))) {
+        apc_cache_expunge(apc_cache,t);
+        apc_cache_expunge(apc_user_cache,t);
         APCG(mem_size_ptr) = NULL;
-        APCG(current_cache) = NULL;
 #if NONBLOCKING_LOCK_AVAILABLE
         if(APCG(write_lock)) {
             apc_cache_write_unlock(apc_cache);
@@ -445,8 +445,9 @@ static zend_op_array* my_compile_file(zend_file_handle* h,
     
     if(!(alloc_functions = apc_copy_new_functions(num_functions, apc_sma_malloc, apc_sma_free TSRMLS_CC))) {
         apc_free_op_array(alloc_op_array, apc_sma_free);
+        apc_cache_expunge(apc_cache,t);
+        apc_cache_expunge(apc_user_cache,t);
         APCG(mem_size_ptr) = NULL;
-        APCG(current_cache) = NULL;
 #if NONBLOCKING_LOCK_AVAILABLE
         if(APCG(write_lock)) {
             apc_cache_write_unlock(apc_cache);
@@ -458,8 +459,9 @@ static zend_op_array* my_compile_file(zend_file_handle* h,
     if(!(alloc_classes = apc_copy_new_classes(op_array, num_classes, apc_sma_malloc, apc_sma_free TSRMLS_CC))) {
         apc_free_op_array(alloc_op_array, apc_sma_free);
         apc_free_functions(alloc_functions, apc_sma_free);
+        apc_cache_expunge(apc_cache,t);
+        apc_cache_expunge(apc_user_cache,t);
         APCG(mem_size_ptr) = NULL;
-        APCG(current_cache) = NULL;
 #if NONBLOCKING_LOCK_AVAILABLE
         if(APCG(write_lock)) {
             apc_cache_write_unlock(apc_cache);
@@ -480,8 +482,9 @@ static zend_op_array* my_compile_file(zend_file_handle* h,
         apc_free_op_array(alloc_op_array, apc_sma_free);
         apc_free_functions(alloc_functions, apc_sma_free);
         apc_free_classes(alloc_classes, apc_sma_free);
+        apc_cache_expunge(apc_cache,t);
+        apc_cache_expunge(apc_user_cache,t);
         APCG(mem_size_ptr) = NULL;
-        APCG(current_cache) = NULL;
 #if NONBLOCKING_LOCK_AVAILABLE
         if(APCG(write_lock)) {
             apc_cache_write_unlock(apc_cache);
@@ -495,10 +498,12 @@ static zend_op_array* my_compile_file(zend_file_handle* h,
 
     if ((ret = apc_cache_insert(apc_cache, key, cache_entry, t)) != 1) {
         apc_cache_free_entry(cache_entry);
+        if(ret==-1) {
+            apc_cache_expunge(apc_cache,t);
+            apc_cache_expunge(apc_user_cache,t);
+        }
     }
 
-    APCG(current_cache) = NULL;
-
 #if NONBLOCKING_LOCK_AVAILABLE
     if(APCG(write_lock)) {
         apc_cache_write_unlock(apc_cache);