Skip to content

Commit 86f54fc

Browse files
committed
Use special type IS_ERROR instread of EG(error_zval). (we still need EG(error_zval) for SPL support).
1 parent e99fe98 commit 86f54fc

File tree

6 files changed

+154
-147
lines changed

6 files changed

+154
-147
lines changed

Zend/zend_execute.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ static zend_always_inline void zend_assign_to_object(zval *retval, zval *object,
11061106

11071107
if (object_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
11081108
do {
1109-
if (object_op_type == IS_VAR && UNEXPECTED(object == &EG(error_zval))) {
1109+
if (object_op_type == IS_VAR && UNEXPECTED(Z_TYPE_P(object) == IS_ERROR)) {
11101110
if (retval) {
11111111
ZVAL_NULL(retval);
11121112
}
@@ -1649,7 +1649,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
16491649
default:
16501650
zend_error(E_WARNING, "Illegal offset type");
16511651
retval = (type == BP_VAR_W || type == BP_VAR_RW) ?
1652-
&EG(error_zval) : &EG(uninitialized_zval);
1652+
NULL : &EG(uninitialized_zval);
16531653
}
16541654
}
16551655
return retval;
@@ -1832,10 +1832,15 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
18321832
retval = zend_hash_next_index_insert(Z_ARRVAL_P(container), &EG(uninitialized_zval));
18331833
if (UNEXPECTED(retval == NULL)) {
18341834
zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
1835-
retval = &EG(error_zval);
1835+
ZVAL_ERROR(result);
1836+
return;
18361837
}
18371838
} else {
18381839
retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type);
1840+
if (UNEXPECTED(!retval)) {
1841+
ZVAL_ERROR(result);
1842+
return;
1843+
}
18391844
}
18401845
ZVAL_INDIRECT(result, retval);
18411846
return;
@@ -1860,11 +1865,11 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
18601865
zend_check_string_offset(dim, type);
18611866
zend_wrong_string_offset();
18621867
}
1863-
ZVAL_INDIRECT(result, &EG(error_zval));
1868+
ZVAL_ERROR(result);
18641869
} else if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
18651870
if (!Z_OBJ_HT_P(container)->read_dimension) {
18661871
zend_throw_error(NULL, "Cannot use object as array");
1867-
retval = &EG(error_zval);
1872+
ZVAL_ERROR(result);
18681873
} else {
18691874
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result);
18701875

@@ -1897,25 +1902,25 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
18971902
ZVAL_INDIRECT(result, retval);
18981903
}
18991904
} else {
1900-
ZVAL_INDIRECT(result, &EG(error_zval));
1905+
ZVAL_ERROR(result);
19011906
}
19021907
}
19031908
} else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {
1904-
if (UNEXPECTED(container == &EG(error_zval))) {
1905-
ZVAL_INDIRECT(result, &EG(error_zval));
1906-
} else if (type != BP_VAR_UNSET) {
1909+
if (type != BP_VAR_UNSET) {
19071910
goto convert_to_array;
19081911
} else {
19091912
/* for read-mode only */
19101913
ZVAL_NULL(result);
19111914
}
1915+
} else if (EXPECTED(Z_TYPE_P(container) == IS_ERROR)) {
1916+
ZVAL_ERROR(result);
19121917
} else {
19131918
if (type == BP_VAR_UNSET) {
19141919
zend_error(E_WARNING, "Cannot unset offset in a non-array variable");
19151920
ZVAL_NULL(result);
19161921
} else {
19171922
zend_error(E_WARNING, "Cannot use a scalar value as an array");
1918-
ZVAL_INDIRECT(result, &EG(error_zval));
1923+
ZVAL_ERROR(result);
19191924
}
19201925
}
19211926
}
@@ -2044,8 +2049,8 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
20442049
{
20452050
if (container_op_type != IS_UNUSED && UNEXPECTED(Z_TYPE_P(container) != IS_OBJECT)) {
20462051
do {
2047-
if (container_op_type == IS_VAR && UNEXPECTED(container == &EG(error_zval))) {
2048-
ZVAL_INDIRECT(result, &EG(error_zval));
2052+
if (container_op_type == IS_VAR && UNEXPECTED(Z_TYPE_P(container) == IS_ERROR)) {
2053+
ZVAL_ERROR(result);
20492054
return;
20502055
}
20512056

@@ -2064,7 +2069,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
20642069
object_init(container);
20652070
} else {
20662071
zend_error(E_WARNING, "Attempt to modify property of non-object");
2067-
ZVAL_INDIRECT(result, &EG(error_zval));
2072+
ZVAL_ERROR(result);
20682073
return;
20692074
}
20702075
} while (0);
@@ -2107,7 +2112,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
21072112
}
21082113
} else {
21092114
zend_throw_error(NULL, "Cannot access undefined property for object with overloaded property access");
2110-
ZVAL_INDIRECT(result, &EG(error_zval));
2115+
ZVAL_ERROR(result);
21112116
}
21122117
} else {
21132118
ZVAL_INDIRECT(result, ptr);
@@ -2121,7 +2126,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
21212126
}
21222127
} else {
21232128
zend_error(E_WARNING, "This object doesn't support property references");
2124-
ZVAL_INDIRECT(result, &EG(error_zval));
2129+
ZVAL_ERROR(result);
21252130
}
21262131
}
21272132

Zend/zend_execute_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void init_executor(void) /* {{{ */
130130
zend_init_fpu();
131131

132132
ZVAL_NULL(&EG(uninitialized_zval));
133-
ZVAL_NULL(&EG(error_zval));
133+
ZVAL_ERROR(&EG(error_zval));
134134
/* destroys stack frame, therefore makes core dumps worthless */
135135
#if 0&&ZEND_DEBUG
136136
original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);

Zend/zend_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ struct _zend_ast_ref {
324324
/* internal types */
325325
#define IS_INDIRECT 15
326326
#define IS_PTR17
327+
#define IS_ERROR19
327328

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

785+
#define ZVAL_ERROR(z) do { \
786+
Z_TYPE_INFO_P(z) = IS_ERROR; \
787+
} while (0)
788+
784789
#define Z_REFCOUNT_P(pz) zval_refcount_p(pz)
785790
#define Z_SET_REFCOUNT_P(pz, rc) zval_set_refcount_p(pz, rc)
786791
#define Z_ADDREF_P(pz) zval_addref_p(pz)

Zend/zend_vm_def.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -789,14 +789,14 @@ ZEND_VM_HELPER(zend_binary_assign_op_dim_helper, VAR|UNUSED|CV, CONST|TMPVAR|UNU
789789

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

795-
if (UNEXPECTED(var_ptr == &EG(error_zval))) {
793+
if (UNEXPECTED(Z_TYPE(rv) == IS_ERROR)) {
796794
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
797795
ZVAL_NULL(EX_VAR(opline->result.var));
798796
}
799797
} else {
798+
ZEND_ASSERT(Z_TYPE(rv) == IS_INDIRECT);
799+
var_ptr = Z_INDIRECT(rv);
800800
ZVAL_DEREF(var_ptr);
801801
SEPARATE_ZVAL_NOREF(var_ptr);
802802

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

828-
if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
828+
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
829829
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
830830
ZVAL_NULL(EX_VAR(opline->result.var));
831831
}
@@ -1247,7 +1247,7 @@ ZEND_VM_HANDLER(34, ZEND_PRE_INC, VAR|CV, ANY)
12471247
ZEND_VM_NEXT_OPCODE();
12481248
}
12491249

1250-
if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
1250+
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
12511251
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
12521252
ZVAL_NULL(EX_VAR(opline->result.var));
12531253
}
@@ -1287,7 +1287,7 @@ ZEND_VM_HANDLER(35, ZEND_PRE_DEC, VAR|CV, ANY)
12871287
ZEND_VM_NEXT_OPCODE();
12881288
}
12891289

1290-
if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
1290+
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
12911291
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
12921292
ZVAL_NULL(EX_VAR(opline->result.var));
12931293
}
@@ -1325,7 +1325,7 @@ ZEND_VM_HANDLER(36, ZEND_POST_INC, VAR|CV, ANY)
13251325
ZEND_VM_NEXT_OPCODE();
13261326
}
13271327

1328-
if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
1328+
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
13291329
ZVAL_NULL(EX_VAR(opline->result.var));
13301330
ZEND_VM_NEXT_OPCODE();
13311331
}
@@ -1358,7 +1358,7 @@ ZEND_VM_HANDLER(37, ZEND_POST_DEC, VAR|CV, ANY)
13581358
ZEND_VM_NEXT_OPCODE();
13591359
}
13601360

1361-
if (OP1_TYPE == IS_VAR && UNEXPECTED(var_ptr == &EG(error_zval))) {
1361+
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(var_ptr) == IS_ERROR)) {
13621362
ZVAL_NULL(EX_VAR(opline->result.var));
13631363
ZEND_VM_NEXT_OPCODE();
13641364
}
@@ -2139,7 +2139,7 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
21392139
variable_ptr = zend_hash_next_index_insert(Z_ARRVAL_P(object_ptr), &EG(uninitialized_zval));
21402140
if (UNEXPECTED(variable_ptr == NULL)) {
21412141
zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
2142-
variable_ptr = &EG(error_zval);
2142+
variable_ptr = NULL;
21432143
}
21442144
} else {
21452145
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
@@ -2148,7 +2148,7 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
21482148
FREE_OP2();
21492149
}
21502150
value = get_zval_ptr_r((opline+1)->op1_type, (opline+1)->op1, execute_data, &free_op_data1);
2151-
if (UNEXPECTED(variable_ptr == &EG(error_zval))) {
2151+
if (UNEXPECTED(variable_ptr == NULL)) {
21522152
FREE_OP(free_op_data1);
21532153
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
21542154
ZVAL_NULL(EX_VAR(opline->result.var));
@@ -2197,10 +2197,9 @@ ZEND_VM_C_LABEL(assign_dim_convert_to_array):
21972197
ZEND_VM_C_GOTO(try_assign_dim_array);
21982198
}
21992199
} else if (EXPECTED(Z_TYPE_P(object_ptr) <= IS_FALSE)) {
2200-
if (OP1_TYPE == IS_VAR && UNEXPECTED(object_ptr == &EG(error_zval))) {
2201-
ZEND_VM_C_GOTO(assign_dim_clean);
2202-
}
22032200
ZEND_VM_C_GOTO(assign_dim_convert_to_array);
2201+
} else if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(object_ptr) == IS_ERROR)) {
2202+
ZEND_VM_C_GOTO(assign_dim_clean);
22042203
} else {
22052204
zend_error(E_WARNING, "Cannot use a scalar value as an array");
22062205
ZEND_VM_C_LABEL(assign_dim_clean):
@@ -2229,7 +2228,7 @@ ZEND_VM_HANDLER(38, ZEND_ASSIGN, VAR|CV, CONST|TMP|VAR|CV)
22292228
value = GET_OP2_ZVAL_PTR(BP_VAR_R);
22302229
variable_ptr = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
22312230

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

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

22812281
variable_ptr = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_W);
2282-
if ((OP1_TYPE == IS_VAR && UNEXPECTED(variable_ptr == &EG(error_zval))) ||
2283-
(OP2_TYPE == IS_VAR && UNEXPECTED(value_ptr == &EG(error_zval)))) {
2282+
if ((OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(variable_ptr) == IS_ERROR)) ||
2283+
(OP2_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(value_ptr) == IS_ERROR))) {
22842284
variable_ptr = &EG(uninitialized_zval);
22852285
} else {
22862286
zend_assign_to_variable_reference(variable_ptr, value_ptr);
@@ -4268,7 +4268,7 @@ ZEND_VM_HANDLER(67, ZEND_SEND_REF, VAR|CV, NUM)
42684268
varptr = GET_OP1_ZVAL_PTR_PTR(BP_VAR_W);
42694269

42704270
arg = ZEND_CALL_VAR(EX(call), opline->result.var);
4271-
if (OP1_TYPE == IS_VAR && UNEXPECTED(varptr == &EG(error_zval))) {
4271+
if (OP1_TYPE == IS_VAR && UNEXPECTED(Z_TYPE_P(varptr) == IS_ERROR)) {
42724272
ZVAL_NEW_REF(arg, &EG(uninitialized_zval));
42734273
ZEND_VM_NEXT_OPCODE();
42744274
}

0 commit comments

Comments
 (0)