1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2018-01-02 12:57:58 +08:00
|
|
|
| Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:16:21 +08:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
2015-01-03 17:22:58 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2001-12-11 23:16:21 +08:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
1999-07-16 22:58:16 +08:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2018-11-01 23:20:07 +08:00
|
|
|
| Authors: Andi Gutmans <andi@php.net> |
|
|
|
|
| Zeev Suraski <zeev@php.net> |
|
|
|
|
| Dmitry Stogov <dmitry@php.net> |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_API.h"
|
2013-10-31 15:57:12 +08:00
|
|
|
#include "zend_ast.h"
|
1999-04-08 02:10:10 +08:00
|
|
|
#include "zend_globals.h"
|
|
|
|
#include "zend_constants.h"
|
|
|
|
#include "zend_list.h"
|
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
static void ZEND_FASTCALL zend_string_destroy(zend_string *str);
|
|
|
|
static void ZEND_FASTCALL zend_reference_destroy(zend_reference *ref);
|
|
|
|
static void ZEND_FASTCALL zend_empty_destroy(zend_reference *ref);
|
2018-01-16 05:57:47 +08:00
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
typedef void (ZEND_FASTCALL *zend_rc_dtor_func_t)(zend_refcounted *p);
|
2018-01-16 05:57:47 +08:00
|
|
|
|
2018-07-06 19:14:44 +08:00
|
|
|
static const zend_rc_dtor_func_t zend_rc_dtor_func[] = {
|
|
|
|
/* IS_UNDEF */ (zend_rc_dtor_func_t)zend_empty_destroy,
|
|
|
|
/* IS_NULL */ (zend_rc_dtor_func_t)zend_empty_destroy,
|
|
|
|
/* IS_FALSE */ (zend_rc_dtor_func_t)zend_empty_destroy,
|
|
|
|
/* IS_TRUE */ (zend_rc_dtor_func_t)zend_empty_destroy,
|
|
|
|
/* IS_LONG */ (zend_rc_dtor_func_t)zend_empty_destroy,
|
|
|
|
/* IS_DOUBLE */ (zend_rc_dtor_func_t)zend_empty_destroy,
|
|
|
|
/* IS_STRING */ (zend_rc_dtor_func_t)zend_string_destroy,
|
2018-09-16 23:14:46 +08:00
|
|
|
/* IS_ARRAY */ (zend_rc_dtor_func_t)zend_array_destroy,
|
|
|
|
/* IS_OBJECT */ (zend_rc_dtor_func_t)zend_objects_store_del,
|
|
|
|
/* IS_RESOURCE */ (zend_rc_dtor_func_t)zend_list_free,
|
2018-07-06 19:14:44 +08:00
|
|
|
/* IS_REFERENCE */ (zend_rc_dtor_func_t)zend_reference_destroy,
|
2018-09-16 23:14:46 +08:00
|
|
|
/* IS_CONSTANT_AST */ (zend_rc_dtor_func_t)zend_ast_ref_destroy
|
2018-01-16 05:57:47 +08:00
|
|
|
};
|
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL rc_dtor_func(zend_refcounted *p)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2018-01-16 05:57:47 +08:00
|
|
|
ZEND_ASSERT(GC_TYPE(p) <= IS_CONSTANT_AST);
|
2018-07-23 20:24:07 +08:00
|
|
|
zend_rc_dtor_func[GC_TYPE(p)](p);
|
2018-01-16 05:57:47 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
static void ZEND_FASTCALL zend_string_destroy(zend_string *str)
|
2018-01-16 05:57:47 +08:00
|
|
|
{
|
2018-07-23 20:24:07 +08:00
|
|
|
CHECK_ZVAL_STRING(str);
|
2018-01-16 05:57:47 +08:00
|
|
|
ZEND_ASSERT(!ZSTR_IS_INTERNED(str));
|
|
|
|
ZEND_ASSERT(GC_REFCOUNT(str) == 0);
|
2018-05-28 21:27:12 +08:00
|
|
|
ZEND_ASSERT(!(GC_FLAGS(str) & IS_STR_PERSISTENT));
|
|
|
|
efree(str);
|
2018-01-16 05:57:47 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
static void ZEND_FASTCALL zend_reference_destroy(zend_reference *ref)
|
2018-01-16 05:57:47 +08:00
|
|
|
{
|
2018-09-16 23:12:44 +08:00
|
|
|
i_zval_ptr_dtor(&ref->val);
|
2018-01-16 05:57:47 +08:00
|
|
|
efree_size(ref, sizeof(zend_reference));
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
static void ZEND_FASTCALL zend_empty_destroy(zend_reference *ref)
|
2018-01-16 05:57:47 +08:00
|
|
|
{
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
ZEND_API void zval_ptr_dtor(zval *zval_ptr) /* {{{ */
|
2003-08-25 01:32:47 +08:00
|
|
|
{
|
2018-09-16 23:12:44 +08:00
|
|
|
i_zval_ptr_dtor(zval_ptr);
|
2003-08-25 01:32:47 +08:00
|
|
|
}
|
2018-07-04 05:50:57 +08:00
|
|
|
/* }}} */
|
2003-08-25 01:32:47 +08:00
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
ZEND_API void zval_internal_ptr_dtor(zval *zval_ptr) /* {{{ */
|
2014-02-17 21:59:18 +08:00
|
|
|
{
|
2018-07-04 05:50:57 +08:00
|
|
|
if (Z_REFCOUNTED_P(zval_ptr)) {
|
|
|
|
zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
|
|
|
|
|
|
|
|
if (GC_DELREF(ref) == 0) {
|
|
|
|
if (Z_TYPE_P(zval_ptr) == IS_STRING) {
|
|
|
|
zend_string *str = (zend_string*)ref;
|
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
CHECK_ZVAL_STRING(str);
|
2018-07-04 05:50:57 +08:00
|
|
|
ZEND_ASSERT(!ZSTR_IS_INTERNED(str));
|
|
|
|
ZEND_ASSERT((GC_FLAGS(str) & IS_STR_PERSISTENT));
|
|
|
|
free(str);
|
|
|
|
} else {
|
|
|
|
zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects, resources or reference");
|
2014-04-14 17:24:43 +08:00
|
|
|
}
|
2018-07-04 05:50:57 +08:00
|
|
|
}
|
2014-02-17 21:59:18 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-04 05:50:57 +08:00
|
|
|
/* }}} */
|
2003-08-25 01:32:47 +08:00
|
|
|
|
2015-01-06 00:02:11 +08:00
|
|
|
/* This function should only be used as a copy constructor, i.e. it
|
|
|
|
* should only be called AFTER a zval has been copied to another
|
|
|
|
* location using ZVAL_COPY_VALUE. Do not call it before copying,
|
|
|
|
* otherwise a reference may be leaked. */
|
2014-02-10 14:04:30 +08:00
|
|
|
ZEND_API void zval_add_ref(zval *p)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2014-02-28 15:03:05 +08:00
|
|
|
if (Z_REFCOUNTED_P(p)) {
|
2014-03-06 16:37:46 +08:00
|
|
|
if (Z_ISREF_P(p) && Z_REFCOUNT_P(p) == 1) {
|
2014-06-05 20:04:11 +08:00
|
|
|
ZVAL_COPY(p, Z_REFVAL_P(p));
|
2014-03-06 16:37:46 +08:00
|
|
|
} else {
|
|
|
|
Z_ADDREF_P(p);
|
|
|
|
}
|
2014-02-10 14:04:30 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
2018-07-23 20:24:07 +08:00
|
|
|
ZEND_API void ZEND_FASTCALL zval_copy_ctor_func(zval *zvalue)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2016-05-06 14:23:37 +08:00
|
|
|
if (EXPECTED(Z_TYPE_P(zvalue) == IS_ARRAY)) {
|
|
|
|
ZVAL_ARR(zvalue, zend_array_dup(Z_ARRVAL_P(zvalue)));
|
2017-09-13 06:45:57 +08:00
|
|
|
} else if (EXPECTED(Z_TYPE_P(zvalue) == IS_STRING)) {
|
2017-12-07 20:01:23 +08:00
|
|
|
ZEND_ASSERT(!ZSTR_IS_INTERNED(Z_STR_P(zvalue)));
|
2018-07-23 20:24:07 +08:00
|
|
|
CHECK_ZVAL_STRING(Z_STR_P(zvalue));
|
2017-09-13 06:45:57 +08:00
|
|
|
ZVAL_NEW_STR(zvalue, zend_string_dup(Z_STR_P(zvalue), 0));
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2003-02-01 09:49:15 +08:00
|
|
|
* indent-tabs-mode: t
|
1999-04-08 02:10:10 +08:00
|
|
|
* End:
|
|
|
|
*/
|