-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix static variable behavior with inheritance #6705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
db545b3
cbf9712
a0ab4ad
ac54035
04c4d5a
14fd6f8
394337c
574c79c
45ea188
87158f1
8e62b53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1029,28 +1029,32 @@ static uint32_t zend_add_try_element(uint32_t try_op) /* {{{ */ | |
} | ||
/* }}} */ | ||
|
||
void zend_init_static_variables_map_ptr(zend_op_array *op_array) | ||
{ | ||
if (op_array->static_variables) { | ||
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, | ||
zend_arena_alloc(&CG(arena), sizeof(HashTable *))); | ||
ZEND_MAP_PTR_SET(op_array->static_variables_ptr, NULL); | ||
} | ||
} | ||
|
||
ZEND_API void function_add_ref(zend_function *function) /* {{{ */ | ||
{ | ||
if (function->type == ZEND_USER_FUNCTION) { | ||
zend_op_array *op_array = &function->op_array; | ||
|
||
if (op_array->refcount) { | ||
(*op_array->refcount)++; | ||
} | ||
if (op_array->static_variables | ||
&& !(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) { | ||
GC_ADDREF(op_array->static_variables); | ||
} | ||
|
||
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) { | ||
ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_PRELOADED); | ||
ZEND_MAP_PTR_NEW(op_array->run_time_cache); | ||
ZEND_MAP_PTR_NEW(op_array->static_variables_ptr); | ||
} else { | ||
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables); | ||
ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void*))); | ||
ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void *))); | ||
ZEND_MAP_PTR_SET(op_array->run_time_cache, NULL); | ||
} | ||
|
||
zend_init_static_variables_map_ptr(op_array); | ||
} | ||
|
||
if (function->common.function_name) { | ||
|
@@ -7021,9 +7025,8 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{ | |
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) { | ||
op_array->fn_flags |= ZEND_ACC_PRELOADED; | ||
ZEND_MAP_PTR_NEW(op_array->run_time_cache); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably, won't need special map_ptr handling for preloading now. I'll check this, after you merge the PR. |
||
ZEND_MAP_PTR_NEW(op_array->static_variables_ptr); | ||
} else { | ||
ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void*))); | ||
ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void *))); | ||
ZEND_MAP_PTR_SET(op_array->run_time_cache, NULL); | ||
} | ||
|
||
|
@@ -7112,6 +7115,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{ | |
zend_do_extended_stmt(); | ||
zend_emit_final_return(0); | ||
|
||
zend_init_static_variables_map_ptr(op_array); | ||
pass_two(CG(active_op_array)); | ||
zend_oparray_context_end(&orig_oparray_context); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,28 +89,10 @@ static zend_function *zend_duplicate_internal_function(zend_function *func, zend | |
|
||
static zend_function *zend_duplicate_user_function(zend_function *func) /* {{{ */ | ||
{ | ||
zend_function *new_function; | ||
|
||
new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); | ||
memcpy(new_function, func, sizeof(zend_op_array)); | ||
|
||
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) { | ||
ZEND_ASSERT(new_function->op_array.fn_flags & ZEND_ACC_PRELOADED); | ||
ZEND_MAP_PTR_NEW(new_function->op_array.static_variables_ptr); | ||
} else { | ||
ZEND_MAP_PTR_INIT(new_function->op_array.static_variables_ptr, &new_function->op_array.static_variables); | ||
} | ||
|
||
HashTable *static_properties_ptr = ZEND_MAP_PTR_GET(func->op_array.static_variables_ptr); | ||
if (static_properties_ptr) { | ||
/* See: Zend/tests/method_static_var.phpt */ | ||
ZEND_MAP_PTR_SET(new_function->op_array.static_variables_ptr, static_properties_ptr); | ||
GC_TRY_ADDREF(static_properties_ptr); | ||
} else { | ||
GC_TRY_ADDREF(new_function->op_array.static_variables); | ||
} | ||
|
||
return new_function; | ||
zend_op_array *new_op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); | ||
memcpy(new_op_array, func, sizeof(zend_op_array)); | ||
zend_init_static_variables_map_ptr(new_op_array); | ||
return (zend_function *) new_op_array; | ||
} | ||
/* }}} */ | ||
|
||
|
@@ -2504,20 +2486,23 @@ static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce) | |
for (; p != end; p++) { | ||
zend_op_array *op_array, *new_op_array; | ||
void ***run_time_cache_ptr; | ||
HashTable **static_variables_ptr; | ||
|
||
op_array = Z_PTR(p->val); | ||
ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION); | ||
ZEND_ASSERT(op_array->scope == pce); | ||
ZEND_ASSERT(op_array->prototype == NULL); | ||
new_op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array) + sizeof(void*)); | ||
new_op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array) + 2 * sizeof(void*)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to allocate additional word if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
Z_PTR(p->val) = new_op_array; | ||
memcpy(new_op_array, op_array, sizeof(zend_op_array)); | ||
run_time_cache_ptr = (void***)(new_op_array + 1); | ||
*run_time_cache_ptr = NULL; | ||
static_variables_ptr = (HashTable **) (run_time_cache_ptr + 1); | ||
*static_variables_ptr = NULL; | ||
new_op_array->fn_flags &= ~ZEND_ACC_IMMUTABLE; | ||
new_op_array->scope = ce; | ||
ZEND_MAP_PTR_INIT(new_op_array->run_time_cache, run_time_cache_ptr); | ||
ZEND_MAP_PTR_INIT(new_op_array->static_variables_ptr, &new_op_array->static_variables); | ||
ZEND_MAP_PTR_INIT(new_op_array->static_variables_ptr, static_variables_ptr); | ||
|
||
zend_update_inherited_handler(constructor); | ||
zend_update_inherited_handler(destructor); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand way we need this new "static_variables" and can't reuse "func.static_variables" and "static_variables_ptr".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the changes in this file turned out to be unnecessary. I've reverted them.