com php-src: Avoid function copying: Zend/zend_compile.c

From: Date: Mon, 27 Aug 2018 09:47:32 +0000
Subject: com php-src: Avoid function copying: Zend/zend_compile.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-102885@lists.php.net to get a copy of this message
Commit: 02eded868c5fb307ce2b87042db1fd9a2e6ef1f7 Author: Dmitry Stogov <dmitry@zend.com> Mon, 27 Aug 2018 12:47:32 +0300 Parents: e42e8b1051a8abeaa8e6053653a4ff43438766e2 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=02eded868c5fb307ce2b87042db1fd9a2e6ef1f7 Log: Avoid function copying Changed paths: M Zend/zend_compile.c Diff: diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 9f974d9..2b39001 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1057,21 +1057,21 @@ ZEND_API int do_bind_function(zval *lcname) /* {{{ */ rtd_key = lcname + 1; zv = zend_hash_find_ex(EG(function_table), Z_STR_P(rtd_key), 1); - function = (zend_function*)Z_PTR_P(zv); - new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); - memcpy(new_function, function, sizeof(zend_op_array)); - if (zend_hash_add_ptr(EG(function_table), Z_STR_P(lcname), new_function) == NULL) { - do_bind_function_error(Z_STR_P(lcname), &new_function->op_array, 0); - return FAILURE; - } else { + new_function = function = (zend_function*)Z_PTR_P(zv); + if (function->op_array.static_variables + && !(function->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) { + new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); + memcpy(new_function, function, sizeof(zend_op_array)); + function->op_array.static_variables = NULL; /* NULL out the unbound function */ if (function->op_array.refcount) { (*function->op_array.refcount)++; } - if (!(function->op_array.fn_flags & ZEND_ACC_IMMUTABLE)) { - function->op_array.static_variables = NULL; /* NULL out the unbound function */ - } - return SUCCESS; } + if (UNEXPECTED(zend_hash_add_ptr(EG(function_table), Z_STR_P(lcname), new_function) == NULL)) { + do_bind_function_error(Z_STR_P(lcname), &new_function->op_array, 0); + return FAILURE; + } + return SUCCESS; } /* }}} */

« previous php.cvs (#102885) next »