1 /* 2 +----------------------------------------------------------------------+ 3 | Zend Engine | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) Zend Technologies Ltd. (http://www.zend.com) | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 2.00 of the Zend license, | 8 | that is bundled with this package in the file LICENSE, and is | 9 | available through the world-wide-web at the following url: | 10 | http://www.zend.com/license/2_00.txt. | 11 | If you did not receive a copy of the Zend license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@zend.com so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Authors: Andi Gutmans <andi@php.net> | 16 | Zeev Suraski <zeev@php.net> | 17 | Dmitry Stogov <dmitry@php.net> | 18 +----------------------------------------------------------------------+ 19 */ 20 21 #ifndef ZEND_VARIABLES_H 22 #define ZEND_VARIABLES_H 23 24 #include "zend_types.h" 25 #include "zend_gc.h" 26 #include "zend_hash.h" 27 28 BEGIN_EXTERN_C() 29 30 ZEND_API void ZEND_FASTCALL rc_dtor_func(zend_refcounted *p); 31 ZEND_API void ZEND_FASTCALL zval_copy_ctor_func(zval *zvalue); 32 zval_ptr_dtor_nogc(zval * zval_ptr)33static zend_always_inline void zval_ptr_dtor_nogc(zval *zval_ptr) 34 { 35 if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) { 36 rc_dtor_func(Z_COUNTED_P(zval_ptr)); 37 } 38 } 39 i_zval_ptr_dtor(zval * zval_ptr)40static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr) 41 { 42 if (Z_REFCOUNTED_P(zval_ptr)) { 43 zend_refcounted *ref = Z_COUNTED_P(zval_ptr); 44 if (!GC_DELREF(ref)) { 45 rc_dtor_func(ref); 46 } else { 47 gc_check_possible_root(ref); 48 } 49 } 50 } 51 zval_copy_ctor(zval * zvalue)52static zend_always_inline void zval_copy_ctor(zval *zvalue) 53 { 54 if (Z_TYPE_P(zvalue) == IS_ARRAY) { 55 ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue))); 56 } else if (Z_REFCOUNTED_P(zvalue)) { 57 Z_ADDREF_P(zvalue); 58 } 59 } 60 zval_opt_copy_ctor(zval * zvalue)61static zend_always_inline void zval_opt_copy_ctor(zval *zvalue) 62 { 63 if (Z_OPT_TYPE_P(zvalue) == IS_ARRAY) { 64 ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue))); 65 } else if (Z_OPT_REFCOUNTED_P(zvalue)) { 66 Z_ADDREF_P(zvalue); 67 } 68 } 69 zval_ptr_dtor_str(zval * zval_ptr)70static zend_always_inline void zval_ptr_dtor_str(zval *zval_ptr) 71 { 72 if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) { 73 ZEND_ASSERT(Z_TYPE_P(zval_ptr) == IS_STRING); 74 ZEND_ASSERT(!ZSTR_IS_INTERNED(Z_STR_P(zval_ptr))); 75 ZEND_ASSERT(!(GC_FLAGS(Z_STR_P(zval_ptr)) & IS_STR_PERSISTENT)); 76 efree(Z_STR_P(zval_ptr)); 77 } 78 } 79 80 ZEND_API void zval_ptr_dtor(zval *zval_ptr); 81 ZEND_API void zval_internal_ptr_dtor(zval *zvalue); 82 83 /* Kept for compatibility */ 84 #define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue) 85 86 ZEND_API void zval_add_ref(zval *p); 87 88 END_EXTERN_C() 89 90 #define ZVAL_PTR_DTOR zval_ptr_dtor 91 #define ZVAL_INTERNAL_PTR_DTOR zval_internal_ptr_dtor 92 93 #endif 94