mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Centralize class initialization
This commit is contained in:
parent
1b8755994e
commit
c17c7a2bfa
5 changed files with 41 additions and 74 deletions
20
Zend/zend.c
20
Zend/zend.c
|
@ -374,25 +374,10 @@ static void register_standard_class(void)
|
|||
zend_standard_class_def = malloc(sizeof(zend_class_entry));
|
||||
|
||||
zend_standard_class_def->type = ZEND_INTERNAL_CLASS;
|
||||
zend_standard_class_def->name_length = sizeof("stdClass") - 1;
|
||||
zend_standard_class_def->name = zend_strndup("stdClass", zend_standard_class_def->name_length);
|
||||
zend_standard_class_def->name_length = sizeof("stdClass") - 1;
|
||||
zend_standard_class_def->parent = NULL;
|
||||
zend_hash_init_ex(&zend_standard_class_def->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&zend_standard_class_def->properties_info, 0, NULL, (dtor_func_t) zend_destroy_property_info, 1, 0);
|
||||
zend_standard_class_def->static_members = (HashTable *) malloc(sizeof(HashTable));
|
||||
zend_hash_init_ex(zend_standard_class_def->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&zend_standard_class_def->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&zend_standard_class_def->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&zend_standard_class_def->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
|
||||
zend_standard_class_def->constructor = NULL;
|
||||
zend_standard_class_def->destructor = NULL;
|
||||
zend_standard_class_def->clone = NULL;
|
||||
zend_standard_class_def->__call = NULL;
|
||||
zend_standard_class_def->__get = NULL;
|
||||
zend_standard_class_def->__set = NULL;
|
||||
zend_standard_class_def->refcount = 1;
|
||||
zend_standard_class_def->constants_updated = 0;
|
||||
zend_standard_class_def->ce_flags = 0;
|
||||
zend_initialize_class_data(zend_standard_class_def, 1);
|
||||
|
||||
zend_hash_add(GLOBAL_CLASS_TABLE, "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry *), NULL);
|
||||
}
|
||||
|
@ -1075,6 +1060,7 @@ void free_estring(char **str_p)
|
|||
efree(*str_p);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
|
|
@ -444,6 +444,7 @@ ZEND_API extern char *empty_string;
|
|||
|
||||
ZEND_API void free_estring(char **str_p);
|
||||
|
||||
|
||||
#define STR_FREE(ptr) if (ptr && ptr!=empty_string) { efree(ptr); }
|
||||
#define STR_FREE_REL(ptr) if (ptr && ptr!=empty_string) { efree_rel(ptr); }
|
||||
|
||||
|
|
|
@ -1358,25 +1358,15 @@ ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *orig_c
|
|||
char *lowercase_name = zend_strndup(orig_class_entry->name, orig_class_entry->name_length);
|
||||
*class_entry = *orig_class_entry;
|
||||
|
||||
zend_str_tolower(lowercase_name, class_entry->name_length);
|
||||
|
||||
class_entry->type = ZEND_INTERNAL_CLASS;
|
||||
class_entry->parent = NULL;
|
||||
class_entry->refcount = 1;
|
||||
class_entry->constants_updated = 0;
|
||||
class_entry->ce_flags = 0;
|
||||
zend_hash_init(&class_entry->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1);
|
||||
zend_hash_init(&class_entry->properties_info, 0, NULL, (dtor_func_t) zend_destroy_property_info, 1);
|
||||
class_entry->static_members = (HashTable *) malloc(sizeof(HashTable));
|
||||
zend_hash_init(class_entry->static_members, 0, NULL, ZVAL_PTR_DTOR, 1);
|
||||
zend_hash_init(&class_entry->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1);
|
||||
zend_hash_init(&class_entry->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1);
|
||||
zend_hash_init(&class_entry->class_table, 10, NULL, ZEND_CLASS_DTOR, 1);
|
||||
zend_initialize_class_data(class_entry, 0);
|
||||
|
||||
if (class_entry->builtin_functions) {
|
||||
zend_register_functions(class_entry, class_entry->builtin_functions, &class_entry->function_table, MODULE_PERSISTENT TSRMLS_CC);
|
||||
}
|
||||
|
||||
zend_str_tolower(lowercase_name, class_entry->name_length);
|
||||
zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, &class_entry, sizeof(zend_class_entry *), NULL);
|
||||
free(lowercase_name);
|
||||
return class_entry;
|
||||
|
|
|
@ -1650,33 +1650,14 @@ static void create_class(HashTable *class_table, char *name, int name_length, ze
|
|||
|
||||
new_class_entry = emalloc(sizeof(zend_class_entry));
|
||||
*ce = new_class_entry;
|
||||
|
||||
new_class_entry->type = ZEND_USER_CLASS;
|
||||
new_class_entry->name = estrndup(name, name_length);
|
||||
new_class_entry->name_length = name_length;
|
||||
new_class_entry->refcount = 1;
|
||||
new_class_entry->constants_updated = 0;
|
||||
new_class_entry->ce_flags = 0;
|
||||
new_class_entry->parent = NULL;
|
||||
zend_initialize_class_data(new_class_entry, 1);
|
||||
|
||||
zend_str_tolower(new_class_entry->name, new_class_entry->name_length);
|
||||
|
||||
zend_hash_init(&new_class_entry->function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->class_table, 10, NULL, ZEND_CLASS_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->default_properties, 10, NULL, ZVAL_PTR_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->properties_info, 10, NULL, (dtor_func_t) zend_destroy_property_info, 0);
|
||||
ALLOC_HASHTABLE(new_class_entry->static_members);
|
||||
zend_hash_init(new_class_entry->static_members, 10, NULL, ZVAL_PTR_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->constants_table, 10, NULL, ZVAL_PTR_DTOR, 0);
|
||||
|
||||
new_class_entry->constructor = NULL;
|
||||
new_class_entry->destructor = NULL;
|
||||
new_class_entry->clone = NULL;
|
||||
new_class_entry->__get = NULL;
|
||||
new_class_entry->__set = NULL;
|
||||
new_class_entry->__call = NULL;
|
||||
|
||||
new_class_entry->create_object = NULL;
|
||||
new_class_entry->parent = NULL;
|
||||
|
||||
if (zend_hash_update(class_table, new_class_entry->name, name_length+1, &new_class_entry, sizeof(zend_class_entry *), NULL) == FAILURE) {
|
||||
zend_error(E_COMPILE_ERROR, "Can't create class. Fatal error, please report!");
|
||||
}
|
||||
|
@ -2117,11 +2098,11 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znod
|
|||
zend_class_entry *new_class_entry = emalloc(sizeof(zend_class_entry));
|
||||
|
||||
class_token->u.previously_active_class_entry = CG(active_class_entry);
|
||||
new_class_entry->type = ZEND_USER_CLASS;
|
||||
if (!(strcmp(class_name->u.constant.value.str.val, "main") && strcmp(class_name->u.constant.value.str.val, "self") &&
|
||||
strcmp(class_name->u.constant.value.str.val, "parent"))) {
|
||||
zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved", class_name->u.constant.value.str.val);
|
||||
}
|
||||
|
||||
if (CG(active_class_entry)) {
|
||||
new_class_entry->name_length = sizeof("::")-1 + class_name->u.constant.value.str.len + CG(active_class_entry)->name_length;
|
||||
new_class_entry->name = emalloc(new_class_entry->name_length+1);
|
||||
|
@ -2133,36 +2114,17 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znod
|
|||
new_class_entry->name = class_name->u.constant.value.str.val;
|
||||
new_class_entry->name_length = class_name->u.constant.value.str.len;
|
||||
}
|
||||
new_class_entry->refcount = 1;
|
||||
new_class_entry->constants_updated = 0;
|
||||
new_class_entry->ce_flags = 0;
|
||||
|
||||
zend_str_tolower(new_class_entry->name, new_class_entry->name_length);
|
||||
|
||||
zend_hash_init(&new_class_entry->function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->class_table, 10, NULL, ZEND_CLASS_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->default_properties, 10, NULL, ZVAL_PTR_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->properties_info, 10, NULL, (dtor_func_t) zend_destroy_property_info, 0);
|
||||
ALLOC_HASHTABLE(new_class_entry->static_members);
|
||||
zend_hash_init(new_class_entry->static_members, 10, NULL, ZVAL_PTR_DTOR, 0);
|
||||
zend_hash_init(&new_class_entry->constants_table, 10, NULL, ZVAL_PTR_DTOR, 0);
|
||||
|
||||
new_class_entry->constructor = NULL;
|
||||
new_class_entry->destructor = NULL;
|
||||
new_class_entry->clone = NULL;
|
||||
new_class_entry->__get = NULL;
|
||||
new_class_entry->__set = NULL;
|
||||
new_class_entry->__call = NULL;
|
||||
|
||||
new_class_entry->create_object = NULL;
|
||||
new_class_entry->type = ZEND_USER_CLASS;
|
||||
new_class_entry->parent = NULL;
|
||||
zend_initialize_class_data(new_class_entry, 1);
|
||||
|
||||
if (parent_class_name->op_type != IS_UNUSED) {
|
||||
doing_inheritance = 1;
|
||||
}
|
||||
|
||||
zend_str_tolower(new_class_entry->name, new_class_entry->name_length);
|
||||
opline = get_next_op(CG(active_op_array) TSRMLS_CC);
|
||||
|
||||
opline->op1.op_type = IS_CONST;
|
||||
build_runtime_defined_function_key(&opline->op1.u.constant, new_class_entry->name, new_class_entry->name_length, opline TSRMLS_CC);
|
||||
|
||||
|
@ -2336,6 +2298,7 @@ void zend_do_fetch_property(znode *result, znode *object, znode *property TSRMLS
|
|||
*result = opline_ptr->result;
|
||||
if (CG(active_class_entry)
|
||||
&& !zend_hash_exists(&CG(active_class_entry)->properties_info, property->u.constant.value.str.val, property->u.constant.value.str.len+1)) {
|
||||
property->u.constant.value.str.val = estrndup(property->u.constant.value.str.val, property->u.constant.value.str.len);
|
||||
zend_do_declare_property(property, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_IMPLICIT_PUBLIC TSRMLS_CC);
|
||||
}
|
||||
return;
|
||||
|
@ -3196,6 +3159,31 @@ void zend_destroy_property_info(zend_property_info *property_info)
|
|||
}
|
||||
|
||||
|
||||
void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers)
|
||||
{
|
||||
ce->refcount = 1;
|
||||
ce->constants_updated = 0;
|
||||
ce->ce_flags = 0;
|
||||
|
||||
zend_hash_init_ex(&ce->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&ce->properties_info, 0, NULL, (dtor_func_t) zend_destroy_property_info, 1, 0);
|
||||
ce->static_members = (HashTable *) malloc(sizeof(HashTable));
|
||||
zend_hash_init_ex(ce->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&ce->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&ce->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
|
||||
zend_hash_init_ex(&ce->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
|
||||
|
||||
if (nullify_handlers) {
|
||||
ce->constructor = NULL;
|
||||
ce->destructor = NULL;
|
||||
ce->clone = NULL;
|
||||
ce->__get = NULL;
|
||||
ce->__set = NULL;
|
||||
ce->__call = NULL;
|
||||
ce->create_object = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
|
|
@ -461,6 +461,8 @@ int pass_two(zend_op_array *op_array TSRMLS_DC);
|
|||
zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array);
|
||||
ZEND_API zend_bool zend_is_compiling(TSRMLS_D);
|
||||
ZEND_API char *zend_make_compiled_string_description(char *name TSRMLS_DC);
|
||||
void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers);
|
||||
|
||||
|
||||
int zend_register_auto_global(char *name, uint name_len TSRMLS_DC);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue