Back to index

php5  5.3.10
zend_variables.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | Zend Engine                                                          |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 2.00 of the Zend license,     |
00008    | that is bundled with this package in the file LICENSE, and is        | 
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.zend.com/license/2_00.txt.                                |
00011    | If you did not receive a copy of the Zend license and are unable to  |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@zend.com so we can mail you a copy immediately.              |
00014    +----------------------------------------------------------------------+
00015    | Authors: Andi Gutmans <andi@zend.com>                                |
00016    |          Zeev Suraski <zeev@zend.com>                                |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: zend_variables.c 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #include <stdio.h>
00023 #include "zend.h"
00024 #include "zend_API.h"
00025 #include "zend_globals.h"
00026 #include "zend_constants.h"
00027 #include "zend_list.h"
00028 
00029 
00030 ZEND_API void _zval_dtor_func(zval *zvalue ZEND_FILE_LINE_DC)
00031 {
00032        switch (Z_TYPE_P(zvalue) & IS_CONSTANT_TYPE_MASK) {
00033               case IS_STRING:
00034               case IS_CONSTANT:
00035                      CHECK_ZVAL_STRING_REL(zvalue);
00036                      STR_FREE_REL(zvalue->value.str.val);
00037                      break;
00038               case IS_ARRAY:
00039               case IS_CONSTANT_ARRAY: {
00040                             TSRMLS_FETCH();
00041 
00042                             if (zvalue->value.ht && (zvalue->value.ht != &EG(symbol_table))) {
00043                                    zend_hash_destroy(zvalue->value.ht);
00044                                    FREE_HASHTABLE(zvalue->value.ht);
00045                             }
00046                      }
00047                      break;
00048               case IS_OBJECT:
00049                      {
00050                             TSRMLS_FETCH();
00051 
00052                             Z_OBJ_HT_P(zvalue)->del_ref(zvalue TSRMLS_CC);
00053                      }
00054                      break;
00055               case IS_RESOURCE:
00056                      {
00057                             TSRMLS_FETCH();
00058 
00059                             /* destroy resource */
00060                             zend_list_delete(zvalue->value.lval);
00061                      }
00062                      break;
00063               case IS_LONG:
00064               case IS_DOUBLE:
00065               case IS_BOOL:
00066               case IS_NULL:
00067               default:
00068                      return;
00069                      break;
00070        }
00071 }
00072 
00073 
00074 ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC)
00075 {
00076        switch (Z_TYPE_P(zvalue) & IS_CONSTANT_TYPE_MASK) {
00077               case IS_STRING:
00078               case IS_CONSTANT:
00079                      CHECK_ZVAL_STRING_REL(zvalue);
00080                      free(zvalue->value.str.val);
00081                      break;
00082               case IS_ARRAY:
00083               case IS_CONSTANT_ARRAY:
00084               case IS_OBJECT:
00085               case IS_RESOURCE:
00086                      zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
00087                      break;
00088               case IS_LONG:
00089               case IS_DOUBLE:
00090               case IS_BOOL:
00091               case IS_NULL:
00092               default:
00093                      break;
00094        }
00095 }
00096 
00097 
00098 ZEND_API void zval_add_ref(zval **p)
00099 {
00100        Z_ADDREF_PP(p);
00101 }
00102 
00103 
00104 ZEND_API void _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
00105 {
00106        switch (Z_TYPE_P(zvalue) & IS_CONSTANT_TYPE_MASK) {
00107               case IS_RESOURCE: {
00108                             TSRMLS_FETCH();
00109 
00110                             zend_list_addref(zvalue->value.lval);
00111                      }
00112                      break;
00113               case IS_BOOL:
00114               case IS_LONG:
00115               case IS_NULL:
00116                      break;
00117               case IS_CONSTANT:
00118               case IS_STRING:
00119                      CHECK_ZVAL_STRING_REL(zvalue);
00120                      zvalue->value.str.val = (char *) estrndup_rel(zvalue->value.str.val, zvalue->value.str.len);
00121                      break;
00122               case IS_ARRAY:
00123               case IS_CONSTANT_ARRAY: {
00124                             zval *tmp;
00125                             HashTable *original_ht = zvalue->value.ht;
00126                             HashTable *tmp_ht = NULL;
00127                             TSRMLS_FETCH();
00128 
00129                             if (zvalue->value.ht == &EG(symbol_table)) {
00130                                    return; /* do nothing */
00131                             }
00132                             ALLOC_HASHTABLE_REL(tmp_ht);
00133                             zend_hash_init(tmp_ht, zend_hash_num_elements(original_ht), NULL, ZVAL_PTR_DTOR, 0);
00134                             zend_hash_copy(tmp_ht, original_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
00135                             zvalue->value.ht = tmp_ht;
00136                      }
00137                      break;
00138               case IS_OBJECT:
00139                      {
00140                             TSRMLS_FETCH();
00141                             Z_OBJ_HT_P(zvalue)->add_ref(zvalue TSRMLS_CC);
00142                      }
00143                      break;
00144        }
00145 }
00146 
00147 
00148 ZEND_API int zend_print_variable(zval *var) 
00149 {
00150        return zend_print_zval(var, 0);
00151 }
00152 
00153 
00154 ZEND_API void _zval_dtor_wrapper(zval *zvalue)
00155 {
00156        TSRMLS_FETCH();
00157 
00158        GC_REMOVE_ZVAL_FROM_BUFFER(zvalue);
00159        zval_dtor(zvalue);
00160 }
00161 
00162 ZEND_API void zval_property_ctor(zval **p) /* {{{ */
00163 {
00164        zval *orig_ptr = *p;
00165 
00166        ALLOC_ZVAL(*p);
00167        **p = *orig_ptr;
00168        zval_copy_ctor(*p);
00169        Z_SET_REFCOUNT_PP(p, 1);
00170        Z_UNSET_ISREF_PP(p);
00171 }
00172 /* }}} */
00173 
00174 #if ZEND_DEBUG
00175 ZEND_API void _zval_copy_ctor_wrapper(zval *zvalue)
00176 {
00177        zval_copy_ctor(zvalue);
00178 }
00179 
00180 
00181 ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue)
00182 {
00183        zval_internal_dtor(zvalue);
00184 }
00185 
00186 
00187 ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr)
00188 {
00189        zval_ptr_dtor(zval_ptr);
00190 }
00191 
00192 
00193 ZEND_API void _zval_internal_ptr_dtor_wrapper(zval **zval_ptr)
00194 {
00195        zval_internal_ptr_dtor(zval_ptr);
00196 }
00197 #endif
00198 
00199 /*
00200  * Local variables:
00201  * tab-width: 4
00202  * c-basic-offset: 4
00203  * indent-tabs-mode: t
00204  * End:
00205  */