Skip to content

Commit

Permalink
Use special type IS_ERROR instread of EG(error_zval). (we still need …
Browse files Browse the repository at this point in the history
…EG(error_zval) for SPL support).
  • Loading branch information
dstogov committed Jan 28, 2016
1 parent e99fe98 commit 86f54fc
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 147 deletions.
35 changes: 20 additions & 15 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ static zend_always_inline void zend_assign_to_object(zval *retval, zval *object,

if (object_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
do {
if (object_op_type == IS_VAR && UNEXPECTED(object == &EG(error_zval))) {
if (object_op_type == IS_VAR && UNEXPECTED(Z_TYPE_P(object) == IS_ERROR)) {
if (retval) {
ZVAL_NULL(retval);
}
Expand Down Expand Up @@ -1649,7 +1649,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
default:
zend_error(E_WARNING, "Illegal offset type");
retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
&EG(error_zval) : &EG(uninitialized_zval);
NULL : &EG(uninitialized_zval);
}
}
return retval;
Expand Down Expand Up @@ -1832,10 +1832,15 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval));
if (UNEXPECTED(retval == NULL)) {
zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
retval = &EG(error_zval);
ZVAL_ERROR(result);
return;
}
} else {
retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type);
if (UNEXPECTED(!retval)) {
ZVAL_ERROR(result);
return;
}
}
ZVAL_INDIRECT(result, retval);
return;
Expand All @@ -1860,11 +1865,11 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
zend_check_string_offset(dim, type);
zend_wrong_string_offset();
}
ZVAL_INDIRECT(result, &EG(error_zval));
ZVAL_ERROR(result);
} else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
if (!Z_OBJ_HT_P(container)->read_dimension) {
zend_throw_error(NULL, "Cannot use object as array");
retval = &EG(error_zval);
ZVAL_ERROR(result);
} else {
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);

Expand Down Expand Up @@ -1897,25 +1902,25 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
ZVAL_INDIRECT(result, retval);
}
} else {
ZVAL_INDIRECT(result, &EG(error_zval));
ZVAL_ERROR(result);
}
}
} else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
if (UNEXPECTED(container == &EG(error_zval))) {
ZVAL_INDIRECT(result, &EG(error_zval));
} else if (type != BP_VAR_UNSET) {
if (type != BP_VAR_UNSET) {
goto convert_to_array;
} else {
/* for read-mode only */
ZVAL_NULL(result);
}
} else if (EXPECTED(Z_TYPE_P(container) == IS_ERROR)) {
ZVAL_ERROR(result);
} else {
if (type == BP_VAR_UNSET) {
zend_error(E_WARNING, "Cannot unset offset in a non-array variable");
ZVAL_NULL(result);
} else {
zend_error(E_WARNING, "Cannot use a scalar value as an array");
ZVAL_INDIRECT(result, &EG(error_zval));
ZVAL_ERROR(result);
}
}
}
Expand Down Expand Up @@ -2044,8 +2049,8 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
{
if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
do {
if (container_op_type == IS_VAR && UNEXPECTED(container == &EG(error_zval))) {
ZVAL_INDIRECT(result, &EG(error_zval));
if (container_op_type == IS_VAR && UNEXPECTED(Z_TYPE_P(container) == IS_ERROR)) {
ZVAL_ERROR(result);
return;
}

Expand All @@ -2064,7 +2069,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
object_init(container);
} else {
zend_error(E_WARNING, "Attempt to modify property of non-object");
ZVAL_INDIRECT(result, &EG(error_zval));
ZVAL_ERROR(result);
return;
}
} while (0);
Expand Down Expand Up @@ -2107,7 +2112,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
}
} else {
zend_throw_error(NULL, "Cannot access undefined property for object with overloaded property access");
ZVAL_INDIRECT(result, &EG(error_zval));
ZVAL_ERROR(result);
}
} else {
ZVAL_INDIRECT(result, ptr);
Expand All @@ -2121,7 +2126,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
}
} else {
zend_error(E_WARNING, "This object doesn't support property references");
ZVAL_INDIRECT(result, &EG(error_zval));
ZVAL_ERROR(result);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void init_executor(void) /* {{{ */
zend_init_fpu();

ZVAL_NULL(&EG(uninitialized_zval));
ZVAL_NULL(&EG(error_zval));
ZVAL_ERROR(&EG(error_zval));
/* destroys stack frame, therefore makes core dumps worthless */
#if 0&&ZEND_DEBUG
original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
Expand Down
5 changes: 5 additions & 0 deletions Zend/zend_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ struct _zend_ast_ref {
/* internal types */
#define IS_INDIRECT 15
#define IS_PTR 17
#define IS_ERROR 19

static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
return pz->u1.v.type;
Expand Down Expand Up @@ -781,6 +782,10 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
Z_TYPE_INFO_P(z) = IS_PTR; \
} while (0)

#define ZVAL_ERROR(z) do { \
Z_TYPE_INFO_P(z) = IS_ERROR; \
} while (0)

#define Z_REFCOUNT_P(pz) zval_refcount_p(pz)
#define Z_SET_REFCOUNT_P(pz, rc) zval_set_refcount_p(pz, rc)
#define Z_ADDREF_P(pz) zval_addref_p(pz)
Expand Down
36 changes: 18 additions & 18 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,14 +789,14 @@ ZEND_VM_HELPER(zend_binary_assign_op_dim_helper, VAR|UNUSED|CV, CONST|TMPVAR|UNU

zend_fetch_dimension_address_RW(&rv, container, dim, OP2_TYPE);
value = get_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data1);
ZEND_ASSERT(Z_TYPE(rv) == IS_INDIRECT);
var_ptr = Z_INDIRECT(rv);

if (UNEXPECTED(var_ptr == &EG(error_zval))) {
if (UNEXPECTED(Z_TYPE(rv) == IS_ERROR)) {
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
} else {
ZEND_ASSERT(Z_TYPE(rv) == IS_INDIRECT);
var_ptr = Z_INDIRECT(rv);
ZVAL_DEREF(var_ptr);
SEPARATE_ZVAL_NOREF(var_ptr);

Expand Down Expand Up @@ -825,7 +825,7 @@ ZEND_VM_HELPER(zend_binary_assign_op_helper, VAR|CV, CONST|TMPVAR|CV, binary_op_
value = GET_OP2_ZVAL_PTR(BP_VAR_R);
var_ptr = GET_OP1_ZVAL_PTR_PTR(BP_VAR_RW);

if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
Expand Down Expand Up @@ -1247,7 +1247,7 @@ ZEND_VM_HANDLER(34, ZEND_PRE_INC, VAR|CV, ANY)
ZEND_VM_NEXT_OPCODE();
}

if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
Expand Down Expand Up @@ -1287,7 +1287,7 @@ ZEND_VM_HANDLER(35, ZEND_PRE_DEC, VAR|CV, ANY)
ZEND_VM_NEXT_OPCODE();
}

if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
}
Expand Down Expand Up @@ -1325,7 +1325,7 @@ ZEND_VM_HANDLER(36, ZEND_POST_INC, VAR|CV, ANY)
ZEND_VM_NEXT_OPCODE();
}

if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
ZVAL_NULL(EX_VAR(opline->result.var));
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -1358,7 +1358,7 @@ ZEND_VM_HANDLER(37, ZEND_POST_DEC, VAR|CV, ANY)
ZEND_VM_NEXT_OPCODE();
}

if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
ZVAL_NULL(EX_VAR(opline->result.var));
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -2139,7 +2139,7 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
variable_ptr = zend_hash_next_index_insert(Z_ARRVAL_P(object_ptr), &EG(uninitialized_zval));
if (UNEXPECTED(variable_ptr == NULL)) {
zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
variable_ptr = &EG(error_zval);
variable_ptr = NULL;
}
} else {
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
Expand All @@ -2148,7 +2148,7 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
FREE_OP2();
}
value = get_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data1);
if (UNEXPECTED(variable_ptr == &EG(error_zval))) {
if (UNEXPECTED(variable_ptr == NULL)) {
FREE_OP(free_op_data1);
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
Expand Down Expand Up @@ -2197,10 +2197,9 @@ ZEND_VM_C_LABEL(assign_dim_convert_to_array):
ZEND_VM_C_GOTO(try_assign_dim_array);
}
} else if (EXPECTED(Z_TYPE_P(object_ptr) <= IS_FALSE)) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(object_ptr == &EG(error_zval))) {
ZEND_VM_C_GOTO(assign_dim_clean);
}
ZEND_VM_C_GOTO(assign_dim_convert_to_array);
} else if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(object_ptr) == IS_ERROR)) {
ZEND_VM_C_GOTO(assign_dim_clean);
} else {
zend_error(E_WARNING, "Cannot use a scalar value as an array");
ZEND_VM_C_LABEL(assign_dim_clean):
Expand Down Expand Up @@ -2229,7 +2228,7 @@ ZEND_VM_HANDLER(38, ZEND_ASSIGN, VAR|CV, CONST|TMP|VAR|CV)
value = GET_OP2_ZVAL_PTR(BP_VAR_R);
variable_ptr = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);

if (OP1_TYPE == IS_VAR && UNEXPECTED(variable_ptr == &EG(error_zval))) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(variable_ptr) == IS_ERROR)) {
FREE_OP2();
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_NULL(EX_VAR(opline->result.var));
Expand Down Expand Up @@ -2258,7 +2257,8 @@ ZEND_VM_HANDLER(39, ZEND_ASSIGN_REF, VAR|CV, VAR|CV, SRC)

if (OP1_TYPE == IS_VAR &&
UNEXPECTED(Z_TYPE_P(EX_VAR(opline->op1.var)) != IS_INDIRECT) &&
UNEXPECTED(!Z_ISREF_P(EX_VAR(opline->op1.var)))) {
UNEXPECTED(Z_TYPE_P(EX_VAR(opline->op1.var)) != IS_REFERENCE) &&
UNEXPECTED(Z_TYPE_P(EX_VAR(opline->op1.var)) != IS_ERROR)) {
zend_throw_error(NULL, "Cannot assign by reference to overloaded object");
FREE_OP2_VAR_PTR();
HANDLE_EXCEPTION();
Expand All @@ -2279,8 +2279,8 @@ ZEND_VM_HANDLER(39, ZEND_ASSIGN_REF, VAR|CV, VAR|CV, SRC)
}

variable_ptr = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
if ((OP1_TYPE == IS_VAR && UNEXPECTED(variable_ptr == &EG(error_zval))) ||
(OP2_TYPE == IS_VAR && UNEXPECTED(value_ptr == &EG(error_zval)))) {
if ((OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(variable_ptr) == IS_ERROR)) ||
(OP2_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(value_ptr) == IS_ERROR))) {
variable_ptr = &EG(uninitialized_zval);
} else {
zend_assign_to_variable_reference(variable_ptr, value_ptr);
Expand Down Expand Up @@ -4268,7 +4268,7 @@ ZEND_VM_HANDLER(67, ZEND_SEND_REF, VAR|CV, NUM)
varptr = GET_OP1_ZVAL_PTR_PTR(BP_VAR_W);

arg = ZEND_CALL_VAR(EX(call), opline->result.var);
if (OP1_TYPE == IS_VAR && UNEXPECTED(varptr == &EG(error_zval))) {
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(varptr) == IS_ERROR)) {
ZVAL_NEW_REF(arg, &EG(uninitialized_zval));
ZEND_VM_NEXT_OPCODE();
}
Expand Down
Loading

0 comments on commit 86f54fc

Please sign in to comment.