]> granicus.if.org Git - php/commitdiff
- Provide appropriate way to destroy internal zval's.
authorMarcus Boerger <helly@php.net>
Sun, 24 Aug 2003 17:32:47 +0000 (17:32 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 24 Aug 2003 17:32:47 +0000 (17:32 +0000)
- Allow internal zval's of type string and disallow complex types.
- Define the default string for extensions at class level instead of ctor.

Zend/zend_API.c
Zend/zend_API.h
Zend/zend_compile.c
Zend/zend_default_classes.c
Zend/zend_exceptions.c
Zend/zend_execute_API.c
Zend/zend_variables.c
Zend/zend_variables.h

index 3451f0ff5a81dbf812ff6bca2f944fff9a45c756..53f7d48219004823ab7c050f2f643f6cc414332a 100644 (file)
@@ -1629,6 +1629,16 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_le
        } 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;
@@ -1691,6 +1701,21 @@ ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int na
        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);
+}
+
 ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC)
 {
        zval property;
index 9703b52b66f622a49a46609c6b3733633c6d66e6..ad500c15325755cc6fb9479462e8ab390fa6a5c0 100644 (file)
@@ -168,6 +168,7 @@ ZEND_API char *zend_get_module_version(char *module_name);
 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 92de94344d197e75471bb893ad11b8abee4a2aaa..30c36d92a2ea8c47c0e55a040430183a241959e6 100644 (file)
@@ -3406,22 +3406,6 @@ again:
 }
 
 
-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 @@ void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers
        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 116dbabe193e22ddada682b45bcc3b0dea4923d0..db0363e9394dd319412f3d781ff9c8c0b0a22486 100644 (file)
@@ -36,7 +36,6 @@ static zend_object_value zend_default_exception_new(zend_class_entry *class_type
        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 @@ static void zend_register_default_exception(TSRMLS_D)
        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 116dbabe193e22ddada682b45bcc3b0dea4923d0..db0363e9394dd319412f3d781ff9c8c0b0a22486 100644 (file)
@@ -36,7 +36,6 @@ static zend_object_value zend_default_exception_new(zend_class_entry *class_type
        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 @@ static void zend_register_default_exception(TSRMLS_D)
        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 28f7347b308d3a5f1edad0c54b05de843ad72114..39dea80c74d67b00d4c92d2e381f44e7c06cb58d 100644 (file)
@@ -359,6 +359,21 @@ ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC)
 }
 
 
+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;
+       }
+}
+
+
 ZEND_API int zend_is_true(zval *op)
 {
        return i_zend_is_true(op);
index a3de3627a5b0de6fb9a533c1840f1406fd6be4fc..12480d9491ecf6a897d1653fa5fbc616e3487e96 100644 (file)
@@ -80,6 +80,32 @@ ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC)
 }
 
 
+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,11 +185,22 @@ ZEND_API void _zval_dtor_wrapper(zval *zvalue)
 }
 
 
+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 9d43fcbde8db876827a1cc6a5af481e5a249c574..a37671e6f86446640b1cc3e97b0a0863e3077fd0 100644 (file)
@@ -29,21 +29,31 @@ BEGIN_EXTERN_C()
 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 @@ ZEND_API void zval_add_ref(zval **p);
 
 #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