New PHP5 APC - version 3.0.19, using PHP5 5.2.0-8+etch11,
[php5-apc.git] / apc_compile.c
index 7627a55..112bb40 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_compile.c,v 3.87.2.4 2008/03/28 21:05:14 rasmus Exp $ */
+/* $Id: apc_compile.c,v 3.87.2.8 2008/05/11 18:57:00 rasmus Exp $ */
 
 #include "apc_compile.h"
 #include "apc_globals.h"
@@ -100,7 +100,7 @@ static zval* my_copy_zval(zval*, const zval*, apc_malloc_t, apc_free_t);
 static znode* my_copy_znode(znode*, znode*, apc_malloc_t, apc_free_t);
 static zend_op* my_copy_zend_op(zend_op*, zend_op*, apc_malloc_t, apc_free_t);
 static zend_function* my_copy_function(zend_function*, zend_function*, apc_malloc_t, apc_free_t);
-static zend_function_entry* my_copy_function_entry(zend_function_entry*, zend_function_entry*, apc_malloc_t, apc_free_t);
+static zend_function_entry* my_copy_function_entry(zend_function_entry*, const zend_function_entry*, apc_malloc_t, apc_free_t);
 static zend_class_entry* my_copy_class_entry(zend_class_entry*, zend_class_entry*, apc_malloc_t, apc_free_t);
 static HashTable* my_copy_hashtable_ex(HashTable*, HashTable*, ht_copy_fun_t, ht_free_fun_t, int, apc_malloc_t, apc_free_t, ht_check_copy_fun_t, ...);
 #define my_copy_hashtable( dst, src, copy_fn, free_fn, holds_ptr, allocate, deallocate) \
@@ -108,8 +108,8 @@ static HashTable* my_copy_hashtable_ex(HashTable*, HashTable*, ht_copy_fun_t, ht
 static HashTable* my_copy_static_variables(zend_op_array* src, apc_malloc_t allocate, apc_free_t deallocate);
 #ifdef ZEND_ENGINE_2
 static zend_property_info* my_copy_property_info(zend_property_info* dst, zend_property_info* src, apc_malloc_t allocate, apc_free_t deallocate);
-static zend_arg_info* my_copy_arg_info_array(zend_arg_info*, zend_arg_info*, uint, apc_malloc_t, apc_free_t);
-static zend_arg_info* my_copy_arg_info(zend_arg_info*, zend_arg_info*, apc_malloc_t, apc_free_t);
+static zend_arg_info* my_copy_arg_info_array(zend_arg_info*, const zend_arg_info*, uint, apc_malloc_t, apc_free_t);
+static zend_arg_info* my_copy_arg_info(zend_arg_info*, const zend_arg_info*, apc_malloc_t, apc_free_t);
 #endif
 /*
  * The "destroy" functions free the memory associated with a particular data
@@ -292,10 +292,21 @@ static zval** my_copy_zval_ptr(zval** dst, const zval** src, apc_malloc_t alloca
         local_dst_alloc = 1;
     }
 
+#ifdef ZEND_ENGINE_2_3
+    if(!(dst[0] = (zval*) allocate(sizeof(zval_gc_info)))) {
+        if(local_dst_alloc) deallocate(dst);
+        return NULL;
+    }
+
+    if(allocate == apc_php_malloc) {
+        GC_ZVAL_INIT(dst[0]);
+    }
+#else
     if(!(dst[0] = (zval*) allocate(sizeof(zval)))) {
         if(local_dst_alloc) deallocate(dst);
         return NULL;
     }
+#endif
     if(!(dst_new = my_copy_zval(*dst, *src, allocate, deallocate))) {
         if(local_dst_alloc) deallocate(dst);
         return NULL;
@@ -305,8 +316,8 @@ static zval** my_copy_zval_ptr(zval** dst, const zval** src, apc_malloc_t alloca
         *dst = dst_new;
     }
 
-    Z_SET_REFCOUNT_PP(dst, Z_REFCOUNT_PP(src));
-    Z_SET_ISREF_TO_PP(dst, Z_ISREF_PP(src));
+    Z_SET_REFCOUNT_PP(dst, Z_REFCOUNT_PP((zval**)src));
+    Z_SET_ISREF_TO_PP(dst, Z_ISREF_PP((zval**)src));
     
     return dst;
 }
@@ -501,7 +512,7 @@ static zend_function* my_copy_function(zend_function* dst, zend_function* src, a
 /* }}} */
 
 /* {{{ my_copy_function_entry */
-static zend_function_entry* my_copy_function_entry(zend_function_entry* dst, zend_function_entry* src, apc_malloc_t allocate, apc_free_t deallocate)
+static zend_function_entry* my_copy_function_entry(zend_function_entry* dst, const zend_function_entry* src, apc_malloc_t allocate, apc_free_t deallocate)
 {
     int local_dst_alloc = 0;
     assert(src != NULL);
@@ -550,7 +561,7 @@ static zend_function_entry* my_copy_function_entry(zend_function_entry* dst, zen
     return dst;
 
 cleanup:
-    if(dst->fname) deallocate(dst->fname);
+    if(dst->fname) deallocate((char*)dst->fname);
     if(local_dst_alloc) deallocate(dst);
     return NULL;
 }
@@ -629,7 +640,7 @@ static zend_property_info* my_copy_property_info_for_execution(zend_property_inf
 /* }}} */
 
 /* {{{ my_copy_arg_info_array */
-static zend_arg_info* my_copy_arg_info_array(zend_arg_info* dst, zend_arg_info* src, uint num_args, apc_malloc_t allocate, apc_free_t deallocate)
+static zend_arg_info* my_copy_arg_info_array(zend_arg_info* dst, const zend_arg_info* src, uint num_args, apc_malloc_t allocate, apc_free_t deallocate)
 {
     int local_dst_alloc = 0;
     int i = 0;
@@ -656,7 +667,7 @@ static zend_arg_info* my_copy_arg_info_array(zend_arg_info* dst, zend_arg_info*
 /* }}} */
 
 /* {{{ my_copy_arg_info */
-static zend_arg_info* my_copy_arg_info(zend_arg_info* dst, zend_arg_info* src, apc_malloc_t allocate, apc_free_t deallocate)
+static zend_arg_info* my_copy_arg_info(zend_arg_info* dst, const zend_arg_info* src, apc_malloc_t allocate, apc_free_t deallocate)
 {
     int local_dst_alloc = 0;
     
@@ -690,8 +701,8 @@ static zend_arg_info* my_copy_arg_info(zend_arg_info* dst, zend_arg_info* src, a
     return dst;
 
 cleanup:
-    if(dst->name) deallocate(dst->name);
-    if(dst->class_name) deallocate(dst->name);
+    if(dst->name) deallocate((char*)dst->name);
+    if(dst->class_name) deallocate((char*)dst->class_name);
     if(local_dst_alloc) deallocate(dst);
     return NULL;
 }
@@ -881,12 +892,12 @@ static zend_class_entry* my_copy_class_entry(zend_class_entry* dst, zend_class_e
 
 
         for (i = 0; i < n; i++) {
-            if(!my_copy_function_entry(&dst->builtin_functions[i],
+            if(!my_copy_function_entry((zend_function_entry*)(&dst->builtin_functions[i]),
                                    &src->builtin_functions[i],
                                    allocate, deallocate)) {
                 int ii;
 
-                for(ii=i-1; i>=0; i--) my_destroy_function_entry(&dst->builtin_functions[ii], deallocate);
+                for(ii=i-1; ii>=0; ii--) my_destroy_function_entry((zend_function_entry*)(&dst->builtin_functions[ii]), deallocate);
                 goto cleanup;
             }
         }
@@ -913,7 +924,7 @@ cleanup:
     if(dst->refcount) deallocate(dst->refcount);
 #endif
     
-    if(dst->builtin_functions) deallocate(dst->builtin_functions);
+    if(dst->builtin_functions) deallocate((zend_function_entry*)dst->builtin_functions);
     if(dst->function_table.arBuckets) my_destroy_hashtable(&dst->function_table, (ht_free_fun_t) my_free_function, deallocate);
     if(dst->default_properties.arBuckets) my_destroy_hashtable(&dst->default_properties, (ht_free_fun_t) my_free_zval_ptr, deallocate);
 
@@ -1089,7 +1100,15 @@ zval* apc_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_
     assert(src != NULL);
 
     if (!dst) {
+#ifdef ZEND_ENGINE_2_3
+        CHECK(dst = (zval*) allocate(sizeof(zval_gc_info)));
+
+        if(allocate == apc_php_malloc) {
+            GC_ZVAL_INIT(dst);
+        }
+#else
         CHECK(dst = (zval*) allocate(sizeof(zval)));
+#endif
         local_dst_alloc = 1;
     }
 
@@ -1712,10 +1731,10 @@ static void my_destroy_function_entry(zend_function_entry* src, apc_free_t deall
 {
     assert(src != NULL);
 
-    deallocate(src->fname);
+    deallocate((char*)src->fname);
 #ifdef ZEND_ENGINE_2    
     if (src->arg_info) {
-            my_free_arg_info_array(src->arg_info, src->num_args, deallocate);
+            my_free_arg_info_array((zend_arg_info*)src->arg_info, src->num_args, deallocate);
     }
 #else
     if (src->func_arg_types) {
@@ -1756,8 +1775,8 @@ static void my_destroy_arg_info(zend_arg_info* src, apc_free_t deallocate)
 {
     assert(src != NULL);
 
-    deallocate(src->name);
-    deallocate(src->class_name);
+    deallocate((char*)src->name);
+    deallocate((char*)src->class_name);
 }
 /* }}} */
 #endif    
@@ -1807,9 +1826,9 @@ static void my_destroy_class_entry(zend_class_entry* src, apc_free_t deallocate)
 
     if (src->builtin_functions) {
         for (i = 0; src->builtin_functions[i].fname != NULL; i++) {
-            my_destroy_function_entry(&src->builtin_functions[i], deallocate);
+            my_destroy_function_entry((zend_function_entry*)(&src->builtin_functions[i]), deallocate);
         }
-        deallocate(src->builtin_functions);
+        deallocate((zend_function_entry*)src->builtin_functions);
     }
 }
 /* }}} */