Skip to content

Commit cfee4e0

Browse files
committed
Keep zval_get_long() similar to an (int) cast
1 parent 554b6da commit cfee4e0

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

Zend/zend_execute.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container,
25652565
if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
25662566
|| (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
25672567
&& IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
2568-
lval = zval_get_long(offset);
2568+
lval = zval_get_long_ex(offset, /* is_lax */ false);
25692569
goto str_offset;
25702570
}
25712571
return 0;
@@ -2604,7 +2604,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *containe
26042604
if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
26052605
|| (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
26062606
&& IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
2607-
lval = zval_get_long(offset);
2607+
lval = zval_get_long_ex(offset, /* is_lax */ false);
26082608
goto str_offset;
26092609
}
26102610
return 1;

Zend/zend_operators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ ZEND_API void ZEND_FASTCALL convert_to_long(zval *op) /* {{{ */
473473
case IS_STRING:
474474
{
475475
zend_string *str = Z_STR_P(op);
476-
ZVAL_LONG(op, zval_get_long_ex(op, /* is lax */ true));
476+
ZVAL_LONG(op, zval_get_long(op));
477477
zend_string_release_ex(str, 0);
478478
}
479479
break;

Zend/zend_operators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op);
286286
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op);
287287

288288
static zend_always_inline zend_long zval_get_long(zval *op) {
289-
return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, 0);
289+
return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, true);
290290
}
291291
static zend_always_inline zend_long zval_get_long_ex(zval *op, bool is_lax) {
292292
return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, is_lax);

Zend/zend_vm_def.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5223,7 +5223,7 @@ ZEND_VM_C_LABEL(send_array):
52235223
zval *op2 = GET_OP2_ZVAL_PTR(BP_VAR_R);
52245224
uint32_t skip = opline->extended_value;
52255225
uint32_t count = zend_hash_num_elements(ht);
5226-
zend_long len = zval_get_long(op2);
5226+
zend_long len = zval_get_long_ex(op2, /* is_lax */ false);
52275227

52285228
if (len < 0) {
52295229
len += (zend_long)(count - skip);
@@ -6097,7 +6097,7 @@ ZEND_VM_COLD_CONST_HANDLER(51, ZEND_CAST, CONST|TMP|VAR|CV, ANY, TYPE)
60976097

60986098
switch (opline->extended_value) {
60996099
case IS_LONG:
6100-
ZVAL_LONG(result, zval_get_long_ex(expr, /* lax */ true));
6100+
ZVAL_LONG(result, zval_get_long(expr));
61016101
break;
61026102
case IS_DOUBLE:
61036103
ZVAL_DOUBLE(result, zval_get_double(expr));
@@ -9021,6 +9021,7 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED)
90219021
zval retval;
90229022

90239023
zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9024+
// TODO Should this use zval_get_long_ex(&retval, /* is lax */ false);
90249025
count = zval_get_long(&retval);
90259026
zval_ptr_dtor(&retval);
90269027
break;
@@ -9593,7 +9594,7 @@ ZEND_VM_C_LABEL(fetch_dim_r_index_array):
95939594
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
95949595
offset = Z_LVAL_P(dim);
95959596
} else {
9596-
offset = zval_get_long(dim);
9597+
offset = zval_get_long_ex(dim, /* is_lax */ false);
95979598
}
95989599
ht = Z_ARRVAL_P(container);
95999600
ZEND_HASH_INDEX_FIND(ht, offset, value, ZEND_VM_C_LABEL(fetch_dim_r_index_undef));

Zend/zend_vm_execute.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O
23372337
zval *op2 = get_zval_ptr(opline->op2_type, opline->op2, BP_VAR_R);
23382338
uint32_t skip = opline->extended_value;
23392339
uint32_t count = zend_hash_num_elements(ht);
2340-
zend_long len = zval_get_long(op2);
2340+
zend_long len = zval_get_long_ex(op2, /* is_lax */ false);
23412341

23422342
if (len < 0) {
23432343
len += (zend_long)(count - skip);
@@ -4723,7 +4723,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CONST_H
47234723

47244724
switch (opline->extended_value) {
47254725
case IS_LONG:
4726-
ZVAL_LONG(result, zval_get_long_ex(expr, /* lax */ true));
4726+
ZVAL_LONG(result, zval_get_long(expr));
47274727
break;
47284728
case IS_DOUBLE:
47294729
ZVAL_DOUBLE(result, zval_get_double(expr));
@@ -8294,7 +8294,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_DIM_R_INDEX_
82948294
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
82958295
offset = Z_LVAL_P(dim);
82968296
} else {
8297-
offset = zval_get_long(dim);
8297+
offset = zval_get_long_ex(dim, /* is_lax */ false);
82988298
}
82998299
ht = Z_ARRVAL_P(container);
83008300
ZEND_HASH_INDEX_FIND(ht, offset, value, fetch_dim_r_index_undef);
@@ -10528,6 +10528,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
1052810528
zval retval;
1052910529

1053010530
zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
10531+
// TODO Should this use zval_get_long_ex(&retval, /* is lax */ false);
1053110532
count = zval_get_long(&retval);
1053210533
zval_ptr_dtor(&retval);
1053310534
break;
@@ -16088,7 +16089,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_DIM_R_INDEX_
1608816089
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
1608916090
offset = Z_LVAL_P(dim);
1609016091
} else {
16091-
offset = zval_get_long(dim);
16092+
offset = zval_get_long_ex(dim, /* is_lax */ false);
1609216093
}
1609316094
ht = Z_ARRVAL_P(container);
1609416095
ZEND_HASH_INDEX_FIND(ht, offset, value, fetch_dim_r_index_undef);
@@ -16140,7 +16141,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_DIM_R_INDEX_
1614016141
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
1614116142
offset = Z_LVAL_P(dim);
1614216143
} else {
16143-
offset = zval_get_long(dim);
16144+
offset = zval_get_long_ex(dim, /* is_lax */ false);
1614416145
}
1614516146
ht = Z_ARRVAL_P(container);
1614616147
ZEND_HASH_INDEX_FIND(ht, offset, value, fetch_dim_r_index_undef);
@@ -17782,6 +17783,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
1778217783
zval retval;
1778317784

1778417785
zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
17786+
// TODO Should this use zval_get_long_ex(&retval, /* is lax */ false);
1778517787
count = zval_get_long(&retval);
1778617788
zval_ptr_dtor(&retval);
1778717789
break;
@@ -18945,7 +18947,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPC
1894518947

1894618948
switch (opline->extended_value) {
1894718949
case IS_LONG:
18948-
ZVAL_LONG(result, zval_get_long_ex(expr, /* lax */ true));
18950+
ZVAL_LONG(result, zval_get_long(expr));
1894918951
break;
1895018952
case IS_DOUBLE:
1895118953
ZVAL_DOUBLE(result, zval_get_double(expr));
@@ -21559,7 +21561,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPC
2155921561

2156021562
switch (opline->extended_value) {
2156121563
case IS_LONG:
21562-
ZVAL_LONG(result, zval_get_long_ex(expr, /* lax */ true));
21564+
ZVAL_LONG(result, zval_get_long(expr));
2156321565
break;
2156421566
case IS_DOUBLE:
2156521567
ZVAL_DOUBLE(result, zval_get_double(expr));
@@ -38080,7 +38082,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCO
3808038082

3808138083
switch (opline->extended_value) {
3808238084
case IS_LONG:
38083-
ZVAL_LONG(result, zval_get_long_ex(expr, /* lax */ true));
38085+
ZVAL_LONG(result, zval_get_long(expr));
3808438086
break;
3808538087
case IS_DOUBLE:
3808638088
ZVAL_DOUBLE(result, zval_get_double(expr));
@@ -42543,7 +42545,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_DIM_R_INDEX_
4254342545
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
4254442546
offset = Z_LVAL_P(dim);
4254542547
} else {
42546-
offset = zval_get_long(dim);
42548+
offset = zval_get_long_ex(dim, /* is_lax */ false);
4254742549
}
4254842550
ht = Z_ARRVAL_P(container);
4254942551
ZEND_HASH_INDEX_FIND(ht, offset, value, fetch_dim_r_index_undef);
@@ -42595,7 +42597,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_DIM_R_INDEX_
4259542597
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
4259642598
offset = Z_LVAL_P(dim);
4259742599
} else {
42598-
offset = zval_get_long(dim);
42600+
offset = zval_get_long_ex(dim, /* is_lax */ false);
4259942601
}
4260042602
ht = Z_ARRVAL_P(container);
4260142603
ZEND_HASH_INDEX_FIND(ht, offset, value, fetch_dim_r_index_undef);
@@ -47537,6 +47539,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
4753747539
zval retval;
4753847540

4753947541
zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
47542+
// TODO Should this use zval_get_long_ex(&retval, /* is lax */ false);
4754047543
count = zval_get_long(&retval);
4754147544
zval_ptr_dtor(&retval);
4754247545
break;

0 commit comments

Comments
 (0)