From 5d94ba6ec35edcc23fe90413af3ea4d380eee1d0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 13 Oct 2014 15:19:23 +0200 Subject: More fixes for array/object casts with temporary variables --- Zend/tests/object_array_cast.phpt | 47 +++++++++++++++++++++++++++++ Zend/zend_vm_def.h | 17 ++++------- Zend/zend_vm_execute.h | 63 +++++++++++---------------------------- 3 files changed, 70 insertions(+), 57 deletions(-) create mode 100644 Zend/tests/object_array_cast.phpt diff --git a/Zend/tests/object_array_cast.phpt b/Zend/tests/object_array_cast.phpt new file mode 100644 index 0000000000..1cf3dbbd9c --- /dev/null +++ b/Zend/tests/object_array_cast.phpt @@ -0,0 +1,47 @@ +--TEST-- +(object) (array) and (array) (object) casts +--FILE-- + +--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 a98e82d83a..af532e88e4 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 2acd9f98c1..0768aa6df2 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(); -- cgit v1.2.1