mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
- 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.
This commit is contained in:
parent
cec053f707
commit
19ec7a09fc
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user