if ((function = zend_hash_str_find_ptr(&ce->parent->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1)) != NULL) {
/* inherit parent's constructor */
if (function->type == ZEND_INTERNAL_FUNCTION) {
- new_function = pemalloc(sizeof(zend_internal_function), 1);
- memcpy(new_function, function, sizeof(zend_internal_function));
+ if (ce->type & ZEND_INTERNAL_CLASS) {
+ new_function = pemalloc(sizeof(zend_internal_function), 1);
+ memcpy(new_function, function, sizeof(zend_internal_function));
+ } else {
+ new_function = zend_arena_alloc(&CG(arena), sizeof(zend_internal_function));
+ memcpy(new_function, function, sizeof(zend_internal_function));
+ new_function->common.fn_flags |= ZEND_ACC_ARENA_ALLOCATED;
+ }
} else {
new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
memcpy(new_function, function, sizeof(zend_op_array));
(function = zend_hash_find_ptr(&ce->parent->function_table, lc_parent_class_name)) != NULL) {
if (function->common.fn_flags & ZEND_ACC_CTOR) {
/* inherit parent's constructor */
- new_function = pemalloc(sizeof(zend_function), function->type == ZEND_INTERNAL_FUNCTION);
- memcpy(new_function, function, sizeof(zend_function));
+ if (function->type == ZEND_INTERNAL_FUNCTION) {
+ if (ce->type & ZEND_INTERNAL_CLASS) {
+ new_function = pemalloc(sizeof(zend_internal_function), 1);
+ memcpy(new_function, function, sizeof(zend_internal_function));
+ } else {
+ new_function = zend_arena_alloc(&CG(arena), sizeof(zend_internal_function));
+ memcpy(new_function, function, sizeof(zend_internal_function));
+ new_function->common.fn_flags |= ZEND_ACC_ARENA_ALLOCATED;
+ }
+ } else {
+ new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
+ memcpy(new_function, function, sizeof(zend_op_array));
+ }
zend_hash_update_ptr(&ce->function_table, lc_parent_class_name, new_function);
function_add_ref(new_function);
}
}
/* }}} */
-static zend_function *do_inherit_method(zend_function *old_function TSRMLS_DC) /* {{{ */
+static zend_function *do_inherit_method(zend_function *old_function, zend_class_entry *ce TSRMLS_DC) /* {{{ */
{
zend_function *new_function;
if (old_function->type == ZEND_INTERNAL_FUNCTION) {
- new_function = pemalloc(sizeof(zend_internal_function), 1);
- memcpy(new_function, old_function, sizeof(zend_internal_function));
+ if (ce->type & ZEND_INTERNAL_CLASS) {
+ new_function = pemalloc(sizeof(zend_internal_function), 1);
+ memcpy(new_function, old_function, sizeof(zend_internal_function));
+ } else {
+ new_function = zend_arena_alloc(&CG(arena), sizeof(zend_internal_function));
+ memcpy(new_function, old_function, sizeof(zend_internal_function));
+ new_function->common.fn_flags |= ZEND_ACC_ARENA_ALLOCATED;
+ }
} else {
new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
memcpy(new_function, old_function, sizeof(zend_op_array));
ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, func) {
if (do_inherit_method_check(&ce->function_table, func, key, ce)) {
- zend_function *new_func = do_inherit_method(func TSRMLS_CC);
+ zend_function *new_func = do_inherit_method(func, ce TSRMLS_CC);
zend_hash_add_new_ptr(&ce->function_table, key, new_func);
}
} ZEND_HASH_FOREACH_END();
ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->function_table, key, func) {
if (do_inherit_method_check(&ce->function_table, func, key, ce)) {
- zend_function *new_func = do_inherit_method(func TSRMLS_CC);
+ zend_function *new_func = do_inherit_method(func, ce TSRMLS_CC);
zend_hash_add_new_ptr(&ce->function_table, key, new_func);
}
} ZEND_HASH_FOREACH_END();
ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC)
{
- switch (function->type) {
- case ZEND_USER_FUNCTION:
- destroy_op_array((zend_op_array *) function TSRMLS_CC);
- break;
- case ZEND_INTERNAL_FUNCTION:
- if (function->common.function_name) {
- zend_string_release(function->common.function_name);
- }
- /* do nothing */
- break;
+ if (function->type == ZEND_USER_FUNCTION) {
+ destroy_op_array(&function->op_array TSRMLS_CC);
+ } else {
+ ZEND_ASSERT(function->type == ZEND_INTERNAL_FUNCTION);
+ ZEND_ASSERT(function->common.function_name);
+ zend_string_release(function->common.function_name);
}
}
zend_function *function = Z_PTR_P(zv);
TSRMLS_FETCH();
- destroy_zend_function(function TSRMLS_CC);
- if (function->type == ZEND_INTERNAL_FUNCTION) {
- pefree(function, 1);
- } else if (!function->common.function_name) {
- efree_size(function, sizeof(zend_op_array));
+ if (function->type == ZEND_USER_FUNCTION) {
+ ZEND_ASSERT(function->common.function_name);
+ destroy_op_array(&function->op_array TSRMLS_CC);
+ /* op_arrays are allocated on arena, so we don't have to free them */
+//??? efree_size(function, sizeof(zend_op_array));
+ } else {
+ ZEND_ASSERT(function->type == ZEND_INTERNAL_FUNCTION);
+ ZEND_ASSERT(function->common.function_name);
+ zend_string_release(function->common.function_name);
+ if (!(function->common.fn_flags & ZEND_ACC_ARENA_ALLOCATED)) {
+ pefree(function, 1);
+ }
}
}