1999-04-07 18:10:10 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-03-06 05:26:39 +00:00
|
|
|
| Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-07 18:10:10 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-03-06 05:26:39 +00:00
|
|
|
| This source file is subject to version 0.92 of the Zend license, |
|
1999-07-16 14:58:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-03-06 05:26:39 +00:00
|
|
|
| http://www.zend.com/license/0_92.txt. |
|
1999-07-16 14:58:16 +00: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-07 18:10:10 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
1999-07-16 14:58:16 +00:00
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
#include "zend_globals.h"
|
|
|
|
#include "zend_constants.h"
|
|
|
|
#include "zend_list.h"
|
|
|
|
|
|
|
|
ZEND_API char *empty_string = ""; /* in order to save emalloc() and efree() time for
|
|
|
|
* empty strings (usually used to denote empty
|
|
|
|
* return values in failed functions).
|
|
|
|
* The macro STR_FREE() will not efree() it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* this function MUST set the value for the variable to an empty string */
|
|
|
|
/* and empty strings must be evaluated as FALSE */
|
|
|
|
ZEND_API inline void var_reset(zval *var)
|
|
|
|
{
|
1999-12-29 17:29:26 +00:00
|
|
|
#if 0
|
1999-04-07 18:10:10 +00:00
|
|
|
var->type = IS_STRING;
|
|
|
|
var->value.str.val = empty_string;
|
|
|
|
var->value.str.len = 0;
|
1999-12-29 17:29:26 +00:00
|
|
|
#else
|
|
|
|
var->type = IS_BOOL;
|
|
|
|
var->value.lval = 0;
|
|
|
|
#endif
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ZEND_API inline void var_uninit(zval *var)
|
|
|
|
{
|
2000-01-04 13:22:58 +00:00
|
|
|
var->type = IS_NULL;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-17 17:33:37 +00:00
|
|
|
ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
if (zvalue->type==IS_LONG) {
|
2000-01-17 17:33:37 +00:00
|
|
|
return;
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
switch(zvalue->type) {
|
|
|
|
case IS_STRING:
|
|
|
|
case IS_CONSTANT:
|
1999-08-27 19:17:19 +00:00
|
|
|
STR_FREE_REL(zvalue->value.str.val);
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
case IS_ARRAY: {
|
|
|
|
ELS_FETCH();
|
|
|
|
|
|
|
|
if (zvalue->value.ht && (zvalue->value.ht != &EG(symbol_table))) {
|
1999-07-09 20:43:59 +00:00
|
|
|
zend_hash_destroy(zvalue->value.ht);
|
1999-12-27 19:07:33 +00:00
|
|
|
FREE_HASHTABLE(zvalue->value.ht);
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-07-10 11:45:23 +00:00
|
|
|
case IS_OBJECT:
|
|
|
|
zend_hash_destroy(zvalue->value.obj.properties);
|
1999-12-27 19:07:33 +00:00
|
|
|
FREE_HASHTABLE(zvalue->value.obj.properties);
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
case IS_RESOURCE:
|
|
|
|
/* destroy resource */
|
|
|
|
zend_list_delete(zvalue->value.lval);
|
|
|
|
break;
|
|
|
|
case IS_LONG:
|
|
|
|
case IS_DOUBLE:
|
|
|
|
case IS_BOOL:
|
2000-01-04 13:22:58 +00:00
|
|
|
case IS_NULL:
|
1999-04-07 18:10:10 +00:00
|
|
|
default:
|
2000-01-17 17:33:37 +00:00
|
|
|
return;
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-21 14:45:10 +00:00
|
|
|
ZEND_API void zval_del_ref(zval **p)
|
1999-10-07 12:20:40 +00:00
|
|
|
{
|
|
|
|
(*p)->refcount--;
|
|
|
|
if ((*p)->refcount==0) {
|
|
|
|
zval_dtor(*p);
|
1999-12-24 15:22:11 +00:00
|
|
|
FREE_ZVAL(*p);
|
1999-10-07 12:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-21 14:45:10 +00:00
|
|
|
ZEND_API void zval_add_ref(zval **p)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
(*p)->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-27 19:17:19 +00:00
|
|
|
ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
|
1999-04-07 18:10:10 +00:00
|
|
|
{
|
|
|
|
switch (zvalue->type) {
|
|
|
|
case IS_RESOURCE:
|
|
|
|
zend_list_addref(zvalue->value.lval);
|
|
|
|
break;
|
|
|
|
case IS_BOOL:
|
|
|
|
case IS_LONG:
|
2000-01-04 13:22:58 +00:00
|
|
|
case IS_NULL:
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
2000-04-26 22:10:06 +00:00
|
|
|
case IS_CONSTANT:
|
1999-04-07 18:10:10 +00:00
|
|
|
case IS_STRING:
|
|
|
|
if (zvalue->value.str.val) {
|
|
|
|
if (zvalue->value.str.len==0) {
|
1999-12-31 13:56:59 +00:00
|
|
|
zvalue->value.str.val = empty_string;
|
1999-04-07 18:10:10 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
1999-08-28 10:18:54 +00:00
|
|
|
zvalue->value.str.val = (char *) estrndup_rel(zvalue->value.str.val, zvalue->value.str.len);
|
1999-04-07 18:10:10 +00:00
|
|
|
break;
|
|
|
|
case IS_ARRAY: {
|
|
|
|
zval *tmp;
|
|
|
|
HashTable *original_ht = zvalue->value.ht;
|
|
|
|
ELS_FETCH();
|
|
|
|
|
1999-09-03 01:34:52 +00:00
|
|
|
if (!zvalue->value.ht) {
|
1999-04-07 18:10:10 +00:00
|
|
|
var_reset(zvalue);
|
|
|
|
return FAILURE;
|
1999-09-03 01:34:52 +00:00
|
|
|
} else if (zvalue->value.ht==&EG(symbol_table)) {
|
|
|
|
return SUCCESS; /* do nothing */
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
2000-02-25 17:55:33 +00:00
|
|
|
ALLOC_HASHTABLE_REL(zvalue->value.ht);
|
1999-12-21 17:14:31 +00:00
|
|
|
zend_hash_init(zvalue->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0);
|
2000-02-05 15:11:24 +00:00
|
|
|
zend_hash_copy(zvalue->value.ht, original_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IS_OBJECT: {
|
|
|
|
zval *tmp;
|
|
|
|
HashTable *original_ht = zvalue->value.obj.properties;
|
|
|
|
|
2000-02-25 17:55:33 +00:00
|
|
|
ALLOC_HASHTABLE_REL(zvalue->value.obj.properties);
|
1999-12-21 17:14:31 +00:00
|
|
|
zend_hash_init(zvalue->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
2000-02-05 15:11:24 +00:00
|
|
|
zend_hash_copy(zvalue->value.obj.properties, original_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
|
1999-04-07 18:10:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_API int zend_print_variable(zval *var)
|
|
|
|
{
|
|
|
|
return zend_print_zval(var, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-28 21:43:24 +00:00
|
|
|
#if ZEND_DEBUG
|
1999-08-27 19:17:19 +00:00
|
|
|
ZEND_API int _zval_copy_ctor_wrapper(zval *zvalue)
|
|
|
|
{
|
|
|
|
return zval_copy_ctor(zvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-17 17:33:37 +00:00
|
|
|
ZEND_API void _zval_dtor_wrapper(zval *zvalue)
|
1999-08-27 19:17:19 +00:00
|
|
|
{
|
2000-01-17 17:33:37 +00:00
|
|
|
zval_dtor(zvalue);
|
1999-08-27 19:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-01-17 17:33:37 +00:00
|
|
|
ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr)
|
1999-08-27 19:17:19 +00:00
|
|
|
{
|
2000-01-17 18:45:46 +00:00
|
|
|
zval_ptr_dtor(zval_ptr);
|
1999-08-27 19:17:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-04-07 18:10:10 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|