cvs: ZendEngine2 / zend_API.c zend_API.h zend_compile.c zend_default_classes.c zend_execute_API.c zend_variables.c zend_variables.h
| From: | Marcus Boerger | Date: | Sun, 24 Aug 2003 17:32:47 +0000 |
| Subject: | cvs: ZendEngine2 / zend_API.c zend_API.h zend_compile.c zend_default_classes.c zend_execute_API.c zend_variables.c zend_variables.h | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-1699@lists.php.net to get a copy of this message | ||
helly Sun Aug 24 13:32:47 2003 EDT
Modified files:
/ZendEngine2 zend_API.c zend_API.h zend_compile.c
zend_default_classes.c zend_execute_API.c
zend_variables.c zend_variables.h
Log:
- Provide appropriate way to destroy internal zval's.
- Allow internal zval's of type string and disallow complex types.
- Define the default string for extensions at class level instead of ctor.
Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.208 ZendEngine2/zend_API.c:1.209 --- ZendEngine2/zend_API.c:1.208 Sun Aug 24 12:27:01 2003 +++ ZendEngine2/zend_API.c Sun Aug 24 13:32:47 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.208 2003/08/24 16:27:01 zeev Exp $ */ +/* $Id: zend_API.c,v 1.209 2003/08/24 17:32:47 helly Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -1629,6 +1629,16 @@ } else { target_symbol_table = &ce->default_properties; } + switch(Z_TYPE_P(property)) { + case IS_ARRAY: + case IS_CONSTANT_ARRAY: + case IS_OBJECT: + case IS_RESOURCE: + zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources"); + break; + default: + break; + } switch (access_type & ZEND_ACC_PPP_MASK) { case ZEND_ACC_PRIVATE: { char *priv_name; @@ -1688,6 +1698,21 @@ } INIT_PZVAL(property); ZVAL_LONG(property, value); + return zend_declare_property(ce, name, name_length, property, access_type); +} + +ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type) +{ + zval *property; + int len = strlen(value); + + if (ce->type & ZEND_INTERNAL_CLASS) { + property = malloc(sizeof(zval)); + } else { + ALLOC_ZVAL(property); + } + INIT_PZVAL(property); + ZVAL_STRINGL(property, zend_strndup(value, len), len, 0); return zend_declare_property(ce, name, name_length, property, access_type); } Index: ZendEngine2/zend_API.h diff -u ZendEngine2/zend_API.h:1.158 ZendEngine2/zend_API.h:1.159 --- ZendEngine2/zend_API.h:1.158 Sun Aug 24 12:35:58 2003 +++ ZendEngine2/zend_API.h Sun Aug 24 13:32:47 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.h,v 1.158 2003/08/24 16:35:58 helly Exp $ */ +/* $Id: zend_API.h,v 1.159 2003/08/24 17:32:47 helly Exp $ */ #ifndef ZEND_API_H #define ZEND_API_H @@ -168,6 +168,7 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type); ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type); ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type); +ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type); ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC); ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.466 ZendEngine2/zend_compile.c:1.467 --- ZendEngine2/zend_compile.c:1.466 Sun Aug 24 12:17:45 2003 +++ ZendEngine2/zend_compile.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.466 2003/08/24 16:17:45 zeev Exp $ */ +/* $Id: zend_compile.c,v 1.467 2003/08/24 17:32:47 helly Exp $ */ #include "zend_language_parser.h" #include "zend.h" @@ -3406,22 +3406,6 @@ } -static void zval_ptr_dtor_internal(zval **zval_ptr) -{ -#if DEBUG_ZEND>=2 - printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, (*zval_ptr)->refcount, (*zval_ptr)->refcount-1); -#endif - (*zval_ptr)->refcount--; - if ((*zval_ptr)->refcount==0) { - zval_dtor(*zval_ptr); - free(*zval_ptr); - } else if ((*zval_ptr)->refcount == 1) { - (*zval_ptr)->is_ref = 0; - } -} - -#define ZVAL_PTR_DTOR_INTERNAL (void (*)(void *)) zval_ptr_dtor_internal - void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC) { zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0; @@ -3433,7 +3417,7 @@ ce->doc_comment = NULL; ce->doc_comment_len = 0; - zend_hash_init_ex(&ce->default_properties, 0, NULL, persistent_hashes ? ZVAL_PTR_DTOR_INTERNAL : ZVAL_PTR_DTOR, persistent_hashes, 0); + zend_hash_init_ex(&ce->default_properties, 0, NULL, persistent_hashes ? ZVAL_INTERNAL_PTR_DTOR : ZVAL_PTR_DTOR, persistent_hashes, 0); zend_hash_init_ex(&ce->properties_info, 0, NULL, (dtor_func_t) (persistent_hashes ? zend_destroy_property_info_internal : zend_destroy_property_info), persistent_hashes, 0); if (persistent_hashes) { Index: ZendEngine2/zend_default_classes.c diff -u ZendEngine2/zend_default_classes.c:1.15 ZendEngine2/zend_default_classes.c:1.16 --- ZendEngine2/zend_default_classes.c:1.15 Sun Aug 24 12:09:12 2003 +++ ZendEngine2/zend_default_classes.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_default_classes.c,v 1.15 2003/08/24 16:09:12 zeev Exp $ */ +/* $Id: zend_default_classes.c,v 1.16 2003/08/24 17:32:47 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -36,7 +36,6 @@ zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - zend_update_property_string(class_type, &obj, "message", sizeof("message")-1, "Unknown exception" TSRMLS_CC); zend_update_property_string(class_type, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); zend_update_property_long(class_type, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); @@ -125,7 +124,7 @@ default_exception_ptr = zend_register_internal_class(&default_exception TSRMLS_CC); default_exception_ptr->create_object = zend_default_exception_new; - zend_declare_property_null(default_exception_ptr, "message", sizeof("message")-1, ZEND_ACC_PROTECTED); + zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "Unknown exception", ZEND_ACC_PROTECTED); zend_declare_property_long(default_exception_ptr, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED); zend_declare_property_null(default_exception_ptr, "file", sizeof("file")-1, ZEND_ACC_PROTECTED); zend_declare_property_null(default_exception_ptr, "line", sizeof("line")-1, ZEND_ACC_PROTECTED); Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.232 ZendEngine2/zend_execute_API.c:1.233 --- ZendEngine2/zend_execute_API.c:1.232 Sun Aug 24 09:10:03 2003 +++ ZendEngine2/zend_execute_API.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.232 2003/08/24 13:10:03 helly Exp $ */ +/* $Id: zend_execute_API.c,v 1.233 2003/08/24 17:32:47 helly Exp $ */ #include <stdio.h> #include <signal.h> @@ -353,6 +353,21 @@ if ((*zval_ptr)->refcount==0) { zval_dtor(*zval_ptr); safe_free_zval_ptr(*zval_ptr); + } else if ((*zval_ptr)->refcount == 1) { + (*zval_ptr)->is_ref = 0; + } +} + + +ZEND_API void _zval_internal_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) +{ +#if DEBUG_ZEND>=2 + printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, (*zval_ptr)->refcount, (*zval_ptr)->refcount-1); +#endif + (*zval_ptr)->refcount--; + if ((*zval_ptr)->refcount==0) { + zval_internal_dtor(*zval_ptr); + free(*zval_ptr); } else if ((*zval_ptr)->refcount == 1) { (*zval_ptr)->is_ref = 0; } Index: ZendEngine2/zend_variables.c diff -u ZendEngine2/zend_variables.c:1.52 ZendEngine2/zend_variables.c:1.53 --- ZendEngine2/zend_variables.c:1.52 Tue Jun 10 16:03:25 2003 +++ ZendEngine2/zend_variables.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_variables.c,v 1.52 2003/06/10 20:03:25 imajes Exp $ */ +/* $Id: zend_variables.c,v 1.53 2003/08/24 17:32:47 helly Exp $ */ #include <stdio.h> #include "zend.h" @@ -80,6 +80,32 @@ } +ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC) +{ + switch (zvalue->type & ~IS_CONSTANT_INDEX) { + case IS_STRING: + case IS_CONSTANT: + CHECK_ZVAL_STRING_REL(zvalue); + if (zvalue->value.str.val != empty_string) { + free(zvalue->value.str.val); + } + break; + case IS_ARRAY: + case IS_CONSTANT_ARRAY: + case IS_OBJECT: + case IS_RESOURCE: + zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources"); + break; + case IS_LONG: + case IS_DOUBLE: + case IS_BOOL: + case IS_NULL: + default: + break; + } +} + + ZEND_API void zval_add_ref(zval **p) { (*p)->refcount++; @@ -159,10 +185,21 @@ } +ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue) +{ + zval_internal_dtor(zvalue); +} + ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr) { zval_ptr_dtor(zval_ptr); +} + + +ZEND_API void _zval_internal_ptr_dtor_wrapper(zval **zval_ptr) +{ + zval_internal_ptr_dtor(zval_ptr); } #endif Index: ZendEngine2/zend_variables.h diff -u ZendEngine2/zend_variables.h:1.26 ZendEngine2/zend_variables.h:1.27 --- ZendEngine2/zend_variables.h:1.26 Tue Jun 10 16:03:25 2003 +++ ZendEngine2/zend_variables.h Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_variables.h,v 1.26 2003/06/10 20:03:25 imajes Exp $ */ +/* $Id: zend_variables.h,v 1.27 2003/08/24 17:32:47 helly Exp $ */ #ifndef ZEND_VARIABLES_H #define ZEND_VARIABLES_H @@ -29,21 +29,31 @@ ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC); ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC); ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC); +ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC); +ZEND_API void _zval_internal_ptr_dtor(zval **zvalue ZEND_FILE_LINE_DC); #define zval_copy_ctor(zvalue) _zval_copy_ctor((zvalue) ZEND_FILE_LINE_CC) #define zval_dtor(zvalue) _zval_dtor((zvalue) ZEND_FILE_LINE_CC) #define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC) +#define zval_internal_dtor(zvalue) _zval_internal_dtor((zvalue) ZEND_FILE_LINE_CC) +#define zval_internal_ptr_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC) #if ZEND_DEBUG ZEND_API int _zval_copy_ctor_wrapper(zval *zvalue); ZEND_API void _zval_dtor_wrapper(zval *zvalue); ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr); +ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue); +ZEND_API void _zval_internal_ptr_dtor_wrapper(zval **zvalue); #define zval_copy_ctor_wrapper _zval_copy_ctor_wrapper #define zval_dtor_wrapper _zval_dtor_wrapper #define zval_ptr_dtor_wrapper _zval_ptr_dtor_wrapper +#define zval_internal_dtor_wrapper _zval_internal_dtor_wrapper +#define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor_wrapper #else #define zval_copy_ctor_wrapper _zval_copy_ctor #define zval_dtor_wrapper _zval_dtor #define zval_ptr_dtor_wrapper _zval_ptr_dtor +#define zval_internal_dtor_wrapper _zval_internal_dtor +#define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor #endif END_EXTERN_C() @@ -53,6 +63,8 @@ #define ZVAL_DESTRUCTOR (void (*)(void *)) zval_dtor_wrapper #define ZVAL_PTR_DTOR (void (*)(void *)) zval_ptr_dtor_wrapper +#define ZVAL_INTERNAL_DTOR (void (*)(void *)) zval_internal_dtor_wrapper +#define ZVAL_INTERNAL_PTR_DTOR (void (*)(void *)) zval_internal_ptr_dtor_wrapper #define ZVAL_COPY_CTOR (void (*)(void *)) zval_copy_ctor_wrapper #endif
Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.208 ZendEngine2/zend_API.c:1.209 --- ZendEngine2/zend_API.c:1.208 Sun Aug 24 12:27:01 2003 +++ ZendEngine2/zend_API.c Sun Aug 24 13:32:47 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.208 2003/08/24 16:27:01 zeev Exp $ */ +/* $Id: zend_API.c,v 1.209 2003/08/24 17:32:47 helly Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -1629,6 +1629,16 @@ } else { target_symbol_table = &ce->default_properties; } + switch(Z_TYPE_P(property)) { + case IS_ARRAY: + case IS_CONSTANT_ARRAY: + case IS_OBJECT: + case IS_RESOURCE: + zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources"); + break; + default: + break; + } switch (access_type & ZEND_ACC_PPP_MASK) { case ZEND_ACC_PRIVATE: { char *priv_name; @@ -1688,6 +1698,21 @@ } INIT_PZVAL(property); ZVAL_LONG(property, value); + return zend_declare_property(ce, name, name_length, property, access_type); +} + +ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type) +{ + zval *property; + int len = strlen(value); + + if (ce->type & ZEND_INTERNAL_CLASS) { + property = malloc(sizeof(zval)); + } else { + ALLOC_ZVAL(property); + } + INIT_PZVAL(property); + ZVAL_STRINGL(property, zend_strndup(value, len), len, 0); return zend_declare_property(ce, name, name_length, property, access_type); } Index: ZendEngine2/zend_API.h diff -u ZendEngine2/zend_API.h:1.158 ZendEngine2/zend_API.h:1.159 --- ZendEngine2/zend_API.h:1.158 Sun Aug 24 12:35:58 2003 +++ ZendEngine2/zend_API.h Sun Aug 24 13:32:47 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.h,v 1.158 2003/08/24 16:35:58 helly Exp $ */ +/* $Id: zend_API.h,v 1.159 2003/08/24 17:32:47 helly Exp $ */ #ifndef ZEND_API_H #define ZEND_API_H @@ -168,6 +168,7 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type); ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type); ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type); +ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type); ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC); ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC); Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.466 ZendEngine2/zend_compile.c:1.467 --- ZendEngine2/zend_compile.c:1.466 Sun Aug 24 12:17:45 2003 +++ ZendEngine2/zend_compile.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.466 2003/08/24 16:17:45 zeev Exp $ */ +/* $Id: zend_compile.c,v 1.467 2003/08/24 17:32:47 helly Exp $ */ #include "zend_language_parser.h" #include "zend.h" @@ -3406,22 +3406,6 @@ } -static void zval_ptr_dtor_internal(zval **zval_ptr) -{ -#if DEBUG_ZEND>=2 - printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, (*zval_ptr)->refcount, (*zval_ptr)->refcount-1); -#endif - (*zval_ptr)->refcount--; - if ((*zval_ptr)->refcount==0) { - zval_dtor(*zval_ptr); - free(*zval_ptr); - } else if ((*zval_ptr)->refcount == 1) { - (*zval_ptr)->is_ref = 0; - } -} - -#define ZVAL_PTR_DTOR_INTERNAL (void (*)(void *)) zval_ptr_dtor_internal - void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC) { zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0; @@ -3433,7 +3417,7 @@ ce->doc_comment = NULL; ce->doc_comment_len = 0; - zend_hash_init_ex(&ce->default_properties, 0, NULL, persistent_hashes ? ZVAL_PTR_DTOR_INTERNAL : ZVAL_PTR_DTOR, persistent_hashes, 0); + zend_hash_init_ex(&ce->default_properties, 0, NULL, persistent_hashes ? ZVAL_INTERNAL_PTR_DTOR : ZVAL_PTR_DTOR, persistent_hashes, 0); zend_hash_init_ex(&ce->properties_info, 0, NULL, (dtor_func_t) (persistent_hashes ? zend_destroy_property_info_internal : zend_destroy_property_info), persistent_hashes, 0); if (persistent_hashes) { Index: ZendEngine2/zend_default_classes.c diff -u ZendEngine2/zend_default_classes.c:1.15 ZendEngine2/zend_default_classes.c:1.16 --- ZendEngine2/zend_default_classes.c:1.15 Sun Aug 24 12:09:12 2003 +++ ZendEngine2/zend_default_classes.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_default_classes.c,v 1.15 2003/08/24 16:09:12 zeev Exp $ */ +/* $Id: zend_default_classes.c,v 1.16 2003/08/24 17:32:47 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -36,7 +36,6 @@ zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - zend_update_property_string(class_type, &obj, "message", sizeof("message")-1, "Unknown exception" TSRMLS_CC); zend_update_property_string(class_type, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); zend_update_property_long(class_type, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); @@ -125,7 +124,7 @@ default_exception_ptr = zend_register_internal_class(&default_exception TSRMLS_CC); default_exception_ptr->create_object = zend_default_exception_new; - zend_declare_property_null(default_exception_ptr, "message", sizeof("message")-1, ZEND_ACC_PROTECTED); + zend_declare_property_string(default_exception_ptr, "message", sizeof("message")-1, "Unknown exception", ZEND_ACC_PROTECTED); zend_declare_property_long(default_exception_ptr, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED); zend_declare_property_null(default_exception_ptr, "file", sizeof("file")-1, ZEND_ACC_PROTECTED); zend_declare_property_null(default_exception_ptr, "line", sizeof("line")-1, ZEND_ACC_PROTECTED); Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.232 ZendEngine2/zend_execute_API.c:1.233 --- ZendEngine2/zend_execute_API.c:1.232 Sun Aug 24 09:10:03 2003 +++ ZendEngine2/zend_execute_API.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.232 2003/08/24 13:10:03 helly Exp $ */ +/* $Id: zend_execute_API.c,v 1.233 2003/08/24 17:32:47 helly Exp $ */ #include <stdio.h> #include <signal.h> @@ -353,6 +353,21 @@ if ((*zval_ptr)->refcount==0) { zval_dtor(*zval_ptr); safe_free_zval_ptr(*zval_ptr); + } else if ((*zval_ptr)->refcount == 1) { + (*zval_ptr)->is_ref = 0; + } +} + + +ZEND_API void _zval_internal_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) +{ +#if DEBUG_ZEND>=2 + printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, (*zval_ptr)->refcount, (*zval_ptr)->refcount-1); +#endif + (*zval_ptr)->refcount--; + if ((*zval_ptr)->refcount==0) { + zval_internal_dtor(*zval_ptr); + free(*zval_ptr); } else if ((*zval_ptr)->refcount == 1) { (*zval_ptr)->is_ref = 0; } Index: ZendEngine2/zend_variables.c diff -u ZendEngine2/zend_variables.c:1.52 ZendEngine2/zend_variables.c:1.53 --- ZendEngine2/zend_variables.c:1.52 Tue Jun 10 16:03:25 2003 +++ ZendEngine2/zend_variables.c Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_variables.c,v 1.52 2003/06/10 20:03:25 imajes Exp $ */ +/* $Id: zend_variables.c,v 1.53 2003/08/24 17:32:47 helly Exp $ */ #include <stdio.h> #include "zend.h" @@ -80,6 +80,32 @@ } +ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC) +{ + switch (zvalue->type & ~IS_CONSTANT_INDEX) { + case IS_STRING: + case IS_CONSTANT: + CHECK_ZVAL_STRING_REL(zvalue); + if (zvalue->value.str.val != empty_string) { + free(zvalue->value.str.val); + } + break; + case IS_ARRAY: + case IS_CONSTANT_ARRAY: + case IS_OBJECT: + case IS_RESOURCE: + zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources"); + break; + case IS_LONG: + case IS_DOUBLE: + case IS_BOOL: + case IS_NULL: + default: + break; + } +} + + ZEND_API void zval_add_ref(zval **p) { (*p)->refcount++; @@ -159,10 +185,21 @@ } +ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue) +{ + zval_internal_dtor(zvalue); +} + ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr) { zval_ptr_dtor(zval_ptr); +} + + +ZEND_API void _zval_internal_ptr_dtor_wrapper(zval **zval_ptr) +{ + zval_internal_ptr_dtor(zval_ptr); } #endif Index: ZendEngine2/zend_variables.h diff -u ZendEngine2/zend_variables.h:1.26 ZendEngine2/zend_variables.h:1.27 --- ZendEngine2/zend_variables.h:1.26 Tue Jun 10 16:03:25 2003 +++ ZendEngine2/zend_variables.h Sun Aug 24 13:32:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_variables.h,v 1.26 2003/06/10 20:03:25 imajes Exp $ */ +/* $Id: zend_variables.h,v 1.27 2003/08/24 17:32:47 helly Exp $ */ #ifndef ZEND_VARIABLES_H #define ZEND_VARIABLES_H @@ -29,21 +29,31 @@ ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC); ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC); ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC); +ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC); +ZEND_API void _zval_internal_ptr_dtor(zval **zvalue ZEND_FILE_LINE_DC); #define zval_copy_ctor(zvalue) _zval_copy_ctor((zvalue) ZEND_FILE_LINE_CC) #define zval_dtor(zvalue) _zval_dtor((zvalue) ZEND_FILE_LINE_CC) #define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC) +#define zval_internal_dtor(zvalue) _zval_internal_dtor((zvalue) ZEND_FILE_LINE_CC) +#define zval_internal_ptr_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC) #if ZEND_DEBUG ZEND_API int _zval_copy_ctor_wrapper(zval *zvalue); ZEND_API void _zval_dtor_wrapper(zval *zvalue); ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr); +ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue); +ZEND_API void _zval_internal_ptr_dtor_wrapper(zval **zvalue); #define zval_copy_ctor_wrapper _zval_copy_ctor_wrapper #define zval_dtor_wrapper _zval_dtor_wrapper #define zval_ptr_dtor_wrapper _zval_ptr_dtor_wrapper +#define zval_internal_dtor_wrapper _zval_internal_dtor_wrapper +#define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor_wrapper #else #define zval_copy_ctor_wrapper _zval_copy_ctor #define zval_dtor_wrapper _zval_dtor #define zval_ptr_dtor_wrapper _zval_ptr_dtor +#define zval_internal_dtor_wrapper _zval_internal_dtor +#define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor #endif END_EXTERN_C() @@ -53,6 +63,8 @@ #define ZVAL_DESTRUCTOR (void (*)(void *)) zval_dtor_wrapper #define ZVAL_PTR_DTOR (void (*)(void *)) zval_ptr_dtor_wrapper +#define ZVAL_INTERNAL_DTOR (void (*)(void *)) zval_internal_dtor_wrapper +#define ZVAL_INTERNAL_PTR_DTOR (void (*)(void *)) zval_internal_ptr_dtor_wrapper #define ZVAL_COPY_CTOR (void (*)(void *)) zval_copy_ctor_wrapper #endif