From: Andi Gutmans Date: Tue, 12 Mar 2002 19:22:29 +0000 (+0000) Subject: - Another couple of indirection fixes. X-Git-Tag: help~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb6976e46d6a0e3ce596358f866384e277849bc2;p=php - Another couple of indirection fixes. - Make class_entry->refcount be part of the structure and not allocated. --- diff --git a/Zend/zend.c b/Zend/zend.c index 713bdfd5e8..6c6815bd3f 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -265,8 +265,7 @@ static void register_standard_class(void) zend_standard_class_def->handle_function_call = NULL; zend_standard_class_def->handle_property_get = NULL; zend_standard_class_def->handle_property_set = NULL; - zend_standard_class_def->refcount = (int *) malloc(sizeof(int)); - *zend_standard_class_def->refcount = 1; + zend_standard_class_def->refcount = 1; zend_hash_add(GLOBAL_CLASS_TABLE, "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry *), NULL); } diff --git a/Zend/zend.h b/Zend/zend.h index e7b0704b0a..3cb1eb58f4 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -265,7 +265,7 @@ struct _zend_class_entry { char *name; uint name_length; struct _zend_class_entry *parent; - int *refcount; + int refcount; zend_bool constants_updated; HashTable function_table; diff --git a/Zend/zend_API.c b/Zend/zend_API.c index d85eafddb5..26ee2ce77d 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -212,10 +212,7 @@ static int zend_check_class(zval *obj, zend_class_entry *expected_ce) } for (ce = Z_OBJCE_P(obj); ce != NULL; ce = ce->parent) { - /* - * C'est une UGLY HACK. - */ - if (ce->refcount == expected_ce->refcount) { + if (ce == expected_ce) { return 1; } } @@ -1228,8 +1225,7 @@ ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *orig_c class_entry->type = ZEND_INTERNAL_CLASS; class_entry->parent = NULL; - class_entry->refcount = (int *) malloc(sizeof(int)); - *class_entry->refcount = 1; + class_entry->refcount = 1; class_entry->constants_updated = 0; zend_hash_init(&class_entry->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1); zend_hash_init(&class_entry->private_properties, 0, NULL, ZVAL_PTR_DTOR, 1); diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index d1fc686b6e..235fc5cd0d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1516,8 +1516,7 @@ static void create_class(HashTable *class_table, char *name, int name_length, ze 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 = (int *) emalloc(sizeof(int)); - *new_class_entry->refcount = 1; + new_class_entry->refcount = 1; new_class_entry->constants_updated = 0; zend_str_tolower(new_class_entry->name, new_class_entry->name_length); @@ -1578,9 +1577,9 @@ static int create_nested_class(HashTable *class_table, char *path, zend_class_en } last = cur; } - (*new_ce->refcount)++; + new_ce->refcount++; if (zend_hash_add(&ce->class_table, last, strlen(last)+1, &new_ce, sizeof(zend_class_entry *), NULL) == FAILURE) { - (*new_ce->refcount)--; + new_ce->refcount--; zend_error(E_ERROR, "Cannot redeclare class %s", last); return FAILURE; } @@ -1628,9 +1627,9 @@ ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_tabl if (strchr(opline->op2.u.constant.value.str.val, ':')) { return create_nested_class(class_table, opline->op2.u.constant.value.str.val, ce); } - (*ce->refcount)++; + ce->refcount++; if (zend_hash_add(class_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, &ce, sizeof(zend_class_entry *), NULL)==FAILURE) { - (*ce->refcount)--; + ce->refcount--; if (!compile_time) { zend_error(E_ERROR, "Cannot redeclare class %s", opline->op2.u.constant.value.str.val); } @@ -1662,7 +1661,7 @@ ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_tabl } else { ce = *pce; } - (*ce->refcount)++; + ce->refcount++; /* Obtain parent class */ parent_name_length = class_name - opline->op2.u.constant.value.str.val - 1; @@ -1671,7 +1670,7 @@ ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_tabl if (!compile_time) { zend_error(E_ERROR, "Class %s: Cannot inherit from undefined class %s", class_name, parent_name); } - (*ce->refcount)--; + ce->refcount--; efree(parent_name); return FAILURE; } @@ -1684,7 +1683,7 @@ ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_tabl if (!compile_time) { zend_error(E_ERROR, "Cannot redeclare class %s", opline->op2.u.constant.value.str.val); } - (*ce->refcount)--; + ce->refcount--; zend_hash_destroy(&ce->function_table); zend_hash_destroy(&ce->default_properties); zend_hash_destroy(&ce->private_properties); @@ -2015,8 +2014,7 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znod new_class_entry->type = ZEND_USER_CLASS; 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 = (int *) emalloc(sizeof(int)); - *new_class_entry->refcount = 1; + new_class_entry->refcount = 1; new_class_entry->constants_updated = 0; zend_str_tolower(new_class_entry->name, new_class_entry->name_length); diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index 9de9c78a4f..ed10615c83 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -110,7 +110,7 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce) { zend_class_entry *ce = *pce; - if (--(*ce->refcount)>0) { + if (--ce->refcount > 0) { return; } switch (ce->type) { @@ -119,7 +119,6 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce) zend_hash_destroy(&ce->private_properties); zend_hash_destroy(ce->static_members); efree(ce->name); - efree(ce->refcount); zend_hash_destroy(&ce->function_table); FREE_HASHTABLE(ce->static_members); zend_hash_destroy(&ce->constants_table); @@ -131,7 +130,6 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce) zend_hash_destroy(&ce->private_properties); zend_hash_destroy(ce->static_members); free(ce->name); - free(ce->refcount); zend_hash_destroy(&ce->function_table); free(ce->static_members); zend_hash_destroy(&ce->constants_table); @@ -144,7 +142,7 @@ ZEND_API void destroy_zend_class(zend_class_entry **pce) void zend_class_add_ref(zend_class_entry **ce) { - (*(*ce)->refcount)++; + (*ce)->refcount++; } diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 0695b4606e..a74be6b6a3 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -549,7 +549,7 @@ ZEND_API void convert_to_object(zval *op) /* OBJECTS_OPTIMIZE */ TSRMLS_FETCH(); - object_and_properties_init(op, &zend_standard_class_def, op->value.ht); + object_and_properties_init(op, zend_standard_class_def, op->value.ht); return; break; }