php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_variables.c
Go to the documentation of this file.
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#include <stdio.h>
22#include "zend.h"
23#include "zend_API.h"
24#include "zend_ast.h"
25#include "zend_globals.h"
26#include "zend_constants.h"
27#include "zend_list.h"
28
29#if ZEND_DEBUG
31#else
32# define zend_string_destroy _efree
33#endif
34static void ZEND_FASTCALL zend_reference_destroy(zend_reference *ref);
35static void ZEND_FASTCALL zend_empty_destroy(zend_reference *ref);
36
38
39static const zend_rc_dtor_func_t zend_rc_dtor_func[] = {
40 [IS_UNDEF] = (zend_rc_dtor_func_t)zend_empty_destroy,
41 [IS_NULL] = (zend_rc_dtor_func_t)zend_empty_destroy,
42 [IS_FALSE] = (zend_rc_dtor_func_t)zend_empty_destroy,
43 [IS_TRUE] = (zend_rc_dtor_func_t)zend_empty_destroy,
44 [IS_LONG] = (zend_rc_dtor_func_t)zend_empty_destroy,
45 [IS_DOUBLE] = (zend_rc_dtor_func_t)zend_empty_destroy,
50 [IS_REFERENCE] = (zend_rc_dtor_func_t)zend_reference_destroy,
52};
53
59
60#if ZEND_DEBUG
62{
65 ZEND_ASSERT(GC_REFCOUNT(str) == 0);
67 efree(str);
68}
69#endif
70
71static void ZEND_FASTCALL zend_reference_destroy(zend_reference *ref)
72{
74 i_zval_ptr_dtor(&ref->val);
75 efree_size(ref, sizeof(zend_reference));
76}
77
78static void ZEND_FASTCALL zend_empty_destroy(zend_reference *ref)
79{
80}
81
82ZEND_API void zval_ptr_dtor(zval *zval_ptr) /* {{{ */
83{
84 i_zval_ptr_dtor(zval_ptr);
85}
86/* }}} */
87
88ZEND_API void zval_internal_ptr_dtor(zval *zval_ptr) /* {{{ */
89{
90 if (Z_REFCOUNTED_P(zval_ptr)) {
91 zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
92
93 if (GC_DELREF(ref) == 0) {
94 if (Z_TYPE_P(zval_ptr) == IS_STRING) {
95 zend_string *str = (zend_string*)ref;
96
100 free(str);
101 } else {
102 zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects, resources or reference");
103 }
104 }
105 }
106}
107/* }}} */
108
109/* This function should only be used as a copy constructor, i.e. it
110 * should only be called AFTER a zval has been copied to another
111 * location using ZVAL_COPY_VALUE. Do not call it before copying,
112 * otherwise a reference may be leaked. */
114{
115 if (Z_REFCOUNTED_P(p)) {
116 if (Z_ISREF_P(p) && Z_REFCOUNT_P(p) == 1) {
118 } else {
119 Z_ADDREF_P(p);
120 }
121 }
122}
123
125{
126 if (EXPECTED(Z_TYPE_P(zvalue) == IS_ARRAY)) {
127 ZVAL_ARR(zvalue, zend_array_dup(Z_ARRVAL_P(zvalue)));
128 } else if (EXPECTED(Z_TYPE_P(zvalue) == IS_STRING)) {
130 CHECK_ZVAL_STRING(Z_STR_P(zvalue));
131 ZVAL_NEW_STR(zvalue, zend_string_dup(Z_STR_P(zvalue), 0));
132 } else {
134 }
135}
p
Definition session.c:1105
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format,...)
Definition zend.c:1703
#define CHECK_ZVAL_STRING(z)
Definition zend_API.h:936
#define efree_size(ptr, size)
Definition zend_alloc.h:138
#define efree(ptr)
Definition zend_alloc.h:155
ZEND_API void ZEND_FASTCALL zend_ast_ref_destroy(zend_ast_ref *ast)
Definition zend_ast.c:1211
struct _zval_struct zval
#define ZEND_API
#define E_CORE_ERROR
Definition zend_errors.h:27
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
#define ZEND_REF_HAS_TYPE_SOURCES(ref)
ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
Definition zend_hash.c:1808
ZEND_API HashTable *ZEND_FASTCALL zend_array_dup(HashTable *source)
Definition zend_hash.c:2438
ZEND_API void ZEND_FASTCALL zend_list_free(zend_resource *res)
Definition zend_list.c:55
struct _zend_string zend_string
ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object)
#define EXPECTED(condition)
#define ZEND_FASTCALL
#define ZEND_ASSERT(c)
#define ZEND_UNREACHABLE()
#define ZSTR_IS_INTERNED(s)
Definition zend_string.h:84
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define IS_TRUE
Definition zend_types.h:603
#define GC_TYPE(p)
Definition zend_types.h:755
#define Z_ISREF_P(zval_p)
Definition zend_types.h:954
#define Z_REFVAL_P(zval_p)
#define IS_FALSE
Definition zend_types.h:602
#define IS_UNDEF
Definition zend_types.h:600
#define Z_ARRVAL_P(zval_p)
Definition zend_types.h:987
#define IS_STRING
Definition zend_types.h:606
#define Z_REFCOUNTED_P(zval_p)
Definition zend_types.h:921
#define IS_RESOURCE
Definition zend_types.h:609
#define IS_ARRAY
Definition zend_types.h:607
#define IS_DOUBLE
Definition zend_types.h:605
#define Z_COUNTED_P(zval_p)
Definition zend_types.h:699
#define Z_STR_P(zval_p)
Definition zend_types.h:972
#define GC_DELREF(p)
Definition zend_types.h:710
#define GC_FLAGS(p)
Definition zend_types.h:756
#define Z_ADDREF_P(pz)
#define IS_NULL
Definition zend_types.h:601
#define IS_OBJECT
Definition zend_types.h:608
#define IS_LONG
Definition zend_types.h:604
#define ZVAL_ARR(z, a)
#define IS_REFERENCE
Definition zend_types.h:610
#define ZVAL_NEW_STR(z, s)
#define ZVAL_COPY(z, v)
struct _zend_refcounted zend_refcounted
Definition zend_types.h:95
#define Z_REFCOUNT_P(pz)
#define IS_CONSTANT_AST
Definition zend_types.h:611
#define GC_REFCOUNT(p)
Definition zend_types.h:707
struct _zend_reference zend_reference
Definition zend_types.h:100
#define IS_STR_PERSISTENT
Definition zend_types.h:818
ZEND_API void ZEND_FASTCALL zval_copy_ctor_func(zval *zvalue)
#define zend_string_destroy
ZEND_API void ZEND_FASTCALL rc_dtor_func(zend_refcounted *p)
ZEND_API void zval_internal_ptr_dtor(zval *zval_ptr)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
void(ZEND_FASTCALL * zend_rc_dtor_func_t)(zend_refcounted *p)
ZEND_API void zval_add_ref(zval *p)