com php-src: Fixed bug #70241 (Skipped assertions affect Generator returns): NEWS Zend/tests/bug70241.phpt Zend/zend_compile.c

From: Date: Tue, 11 Aug 2015 20:12:06 +0000
Subject: com php-src: Fixed bug #70241 (Skipped assertions affect Generator returns): NEWS Zend/tests/bug70241.phpt Zend/zend_compile.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-88479@lists.php.net to get a copy of this message
Commit: dbd8edbbd08fbb2906ee9b540348b340715b5dbe Author: Bob Weinand <bobwei9@hotmail.com> Tue, 11 Aug 2015 22:12:06 +0200 Parents: af0d6256d5f95556d93685fb8b34e09406e85f8f Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dbd8edbbd08fbb2906ee9b540348b340715b5dbe Log: Fixed bug #70241 (Skipped assertions affect Generator returns) Bugs: https://bugs.php.net/70241 Changed paths: M NEWS A Zend/tests/bug70241.phpt M Zend/zend_compile.c Diff: diff --git a/NEWS b/NEWS index 147b47b..3d02db7 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ PHP NEWS . Fixed bug #69487 (SAPI may truncate POST data). (cmb) . Fixed bug #70198 (Checking liveness does not work as expected). (Shafreeck Sea, Anatol Belski) + . Fixed bug #70241 (Skipped assertions affect Generator returns). (Bob) - CLI server: . Fixed bug #66606 (Sets HTTP_CONTENT_TYPE but not CONTENT_TYPE). diff --git a/Zend/tests/bug70241.phpt b/Zend/tests/bug70241.phpt new file mode 100644 index 0000000..74218e9 --- /dev/null +++ b/Zend/tests/bug70241.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #70241 (Skipped assertions affect Generator returns) +--INI-- +zend.assertions=-1 +--FILE-- +<?php + +function foo () { + assert(yield 1); + return null; +} + +var_dump(foo() instanceof Generator); + +?> +--EXPECT-- +bool(true) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 606775a..9c54245 100644 --- a/Zend/zend_compile..c +++ b/Zend/zend_compile.c @@ -1128,6 +1128,32 @@ void zend_do_early_binding(void) /* {{{ */ } /* }}} */ +static void zend_mark_function_as_generator() /* {{{ */ +{ + if (!CG(active_op_array)->function_name) { + zend_error_noreturn(E_COMPILE_ERROR, + "The \"yield\" expression can only be used inside a function"); + } + if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { + const char *msg = "Generators may only declare a return type of Generator, Iterator or Traversable, %s is not permitted"; + if (!CG(active_op_array)->arg_info[-1].class_name) { + zend_error_noreturn(E_COMPILE_ERROR, msg, + zend_get_type_by_const(CG(active_op_array)->arg_info[-1].type_hint)); + } + if (!(ZSTR_LEN(CG(active_op_array)->arg_info[-1].class_name) == sizeof("Traversable")-1 + && zend_binary_strcasecmp(ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name), sizeof("Traversable")-1, "Traversable", sizeof("Traversable")-1) == 0) && + !(ZSTR_LEN(CG(active_op_array)->arg_info[-1].class_name) == sizeof("Iterator")-1 + && zend_binary_strcasecmp(ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name), sizeof("Iterator")-1, "Iterator", sizeof("Iterator")-1) == 0) && + !(ZSTR_LEN(CG(active_op_array)->arg_info[-1].class_name) == sizeof("Generator")-1 + && zend_binary_strcasecmp(ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name), sizeof("Generator")-1, "Generator", sizeof("Generator")-1) == 0)) { + zend_error_noreturn(E_COMPILE_ERROR, msg, ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name)); + } + } + + CG(active_op_array)->fn_flags |= ZEND_ACC_GENERATOR; +} +/* }}} */ + ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array) /* {{{ */ { if (op_array->early_binding != (uint32_t)-1) { @@ -3041,6 +3067,22 @@ int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcnam } /* }}} */ +static void zend_compile_assert_side_effects(zend_ast *ast) /* {{{ */ +{ + int i; + int children = zend_ast_is_list(ast) ? zend_ast_get_list(ast)->children : zend_ast_get_num_children(ast); + + for (i = 0; i < children; i++) { + zend_ast *child = (zend_ast_is_list(ast) ? zend_ast_get_list(ast)->child : ast->child)[i]; + if (child->kind == ZEND_AST_YIELD) { + zend_mark_function_as_generator(); + } else if (ast->kind >= ZEND_AST_IS_LIST_SHIFT) { + zend_compile_assert_side_effects(child); + } + } +} +/* }}} */ + static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc) /* {{{ */ { if (EG(assertions) >= 0) { @@ -3081,6 +3123,8 @@ static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string * } result->op_type = IS_CONST; ZVAL_TRUE(&result->u.constant); + + zend_compile_assert_side_effects((zend_ast *) args); } return SUCCESS; @@ -6186,32 +6230,6 @@ void zend_compile_exit(znode *result, zend_ast *ast) /* {{{ */ } /* }}} */ -static void zend_mark_function_as_generator() /* {{{ */ -{ - if (!CG(active_op_array)->function_name) { - zend_error_noreturn(E_COMPILE_ERROR, - "The \"yield\" expression can only be used inside a function"); - } - if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { - const char *msg = "Generators may only declare a return type of Generator, Iterator or Traversable, %s is not permitted"; - if (!CG(active_op_array)->arg_info[-1].class_name) { - zend_error_noreturn(E_COMPILE_ERROR, msg, - zend_get_type_by_const(CG(active_op_array)->arg_info[-1].type_hint)); - } - if (!(ZSTR_LEN(CG(active_op_array)->arg_info[-1].class_name) == sizeof("Traversable")-1 - && zend_binary_strcasecmp(ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name), sizeof("Traversable")-1, "Traversable", sizeof("Traversable")-1) == 0) && - !(ZSTR_LEN(CG(active_op_array)->arg_info[-1].class_name) == sizeof("Iterator")-1 - && zend_binary_strcasecmp(ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name), sizeof("Iterator")-1, "Iterator", sizeof("Iterator")-1) == 0) && - !(ZSTR_LEN(CG(active_op_array)->arg_info[-1].class_name) == sizeof("Generator")-1 - && zend_binary_strcasecmp(ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name), sizeof("Generator")-1, "Generator", sizeof("Generator")-1) == 0)) { - zend_error_noreturn(E_COMPILE_ERROR, msg, ZSTR_VAL(CG(active_op_array)->arg_info[-1].class_name)); - } - } - - CG(active_op_array)->fn_flags |= ZEND_ACC_GENERATOR; -} -/* }}} */ - void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */ { zend_ast *value_ast = ast->child[0];

« previous php.cvs (#88479) next »