com php-src: More fixes for array/object casts with temporary variables: Zend/tests/object_array_cast.phpt Zend/zend_vm_def .h Zend/zend_vm_execute.h

From: Date: Mon, 13 Oct 2014 13:31:59 +0000
Subject: com php-src: More fixes for array/object casts with temporary variables: Zend/tests/object_array_cast.phpt Zend/zend_vm_def .h Zend/zend_vm_execute.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-82263@lists.php.net to get a copy of this message
Commit: 5d94ba6ec35edcc23fe90413af3ea4d380eee1d0 Author: Nikita Popov <nikic@php.net> Mon, 13 Oct 2014 15:19:23 +0200 Parents: e62edf2e58c31349498b3dcedd44b64d8fb1837f Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5d94ba6ec35edcc23fe90413af3ea4d380eee1d0 Log: More fixes for array/object casts with temporary variables Changed paths: A Zend/tests/object_array_cast.phpt M Zend/zend_vm_def.h M Zend/zend_vm_execute.h Diff: diff --git a/Zend/tests/object_array_cast.phpt b/Zend/tests/object_array_cast.phpt new file mode 100644 index 0000000..1cf3dbb --- /dev/null +++ b/Zend/tests/object_array_cast.phpt @@ -0,0 +1,47 @@ +--TEST-- +(object) (array) and (array) (object) casts +--FILE-- +<?php + +$arr = [1, 2, 3]; +var_dump((object) (array) $arr); +var_dump($arr); + +$obj = (object) [1, 2, 3]; +var_dump((array) (object) $obj); +var_dump($obj); + +?> +--EXPECT-- +object(stdClass)#1 (3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +object(stdClass)#1 (3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index a98e82d..af532e8 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -4058,15 +4058,13 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (OP1_TYPE != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (OP1_TYPE != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + Z_ADDREF_P(result); convert_to_array(result); } } else { @@ -4078,23 +4076,18 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (OP1_TYPE != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (OP1_TYPE != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + zval_opt_copy_ctor(result); convert_to_object(result); } } - - FREE_OP1_IF_VAR(); - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } + FREE_OP1(); CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 2acd9f9..0768aa6 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2893,15 +2893,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_CONST != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_CONST != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + Z_ADDREF_P(result); convert_to_array(result); } } else { @@ -2913,21 +2911,16 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_CONST != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_CONST != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + zval_opt_copy_ctor(result); convert_to_object(result); } } - - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } CHECK_EXCEPTION(); @@ -9709,15 +9702,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_TMP_VAR != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_TMP_VAR != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + Z_ADDREF_P(result); convert_to_array(result); } } else { @@ -9729,22 +9720,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_TMP_VAR != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_TMP_VAR != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + zval_opt_copy_ctor(result); convert_to_object(result); } } - - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } + zval_ptr_dtor_nogc(free_op1.var); CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -16430,15 +16417,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_VAR != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_VAR != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + Z_ADDREF_P(result); convert_to_array(result); } } else { @@ -16450,23 +16435,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_VAR != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_VAR != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + zval_opt_copy_ctor(result); convert_to_object(result); } } - - zval_ptr_dtor_nogc(free_op1.var); - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } + zval_ptr_dtor_nogc(free_op1.var); CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -34079,15 +34059,13 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_CV != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_CV != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + Z_ADDREF_P(result); convert_to_array(result); } } else { @@ -34099,21 +34077,16 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) if (UNEXPECTED(Z_OPT_COPYABLE_P(expr))) { zval_copy_ctor_func(expr); } - } else if (IS_CV != IS_TMP_VAR) { + } else { if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr); } } } else { ZVAL_COPY_VALUE(result, expr); - if (IS_CV != IS_TMP_VAR) { - zval_opt_copy_ctor(result); - } + zval_opt_copy_ctor(result); convert_to_object(result); } } - - CHECK_EXCEPTION(); - ZEND_VM_NEXT_OPCODE(); } CHECK_EXCEPTION();

« previous php.cvs (#82263) next »