Skip to content

Commit f60cc03

Browse files
committed
Keep zval_get_long() similar to an (int) cast
1 parent d0da616 commit f60cc03

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
@@ -2575,7 +2575,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container,
25752575
if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
25762576
|| (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
25772577
&& IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
2578-
lval = zval_get_long(offset);
2578+
lval = zval_get_long_ex(offset, /* is_lax */ false);
25792579
goto str_offset;
25802580
}
25812581
return 0;
@@ -2614,7 +2614,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *containe
26142614
if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
26152615
|| (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
26162616
&& IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
2617-
lval = zval_get_long(offset);
2617+
lval = zval_get_long_ex(offset, /* is_lax */ false);
26182618
goto str_offset;
26192619
}
26202620
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
@@ -5230,7 +5230,7 @@ ZEND_VM_C_LABEL(send_array):
52305230
zval *op2 = GET_OP2_ZVAL_PTR(BP_VAR_R);
52315231
uint32_t skip = opline->extended_value;
52325232
uint32_t count = zend_hash_num_elements(ht);
5233-
zend_long len = zval_get_long(op2);
5233+
zend_long len = zval_get_long_ex(op2, /* is_lax */ false);
52345234

52355235
if (len < 0) {
52365236
len += (zend_long)(count - skip);
@@ -6104,7 +6104,7 @@ ZEND_VM_COLD_CONST_HANDLER(51, ZEND_CAST, CONST|TMP|VAR|CV, ANY, TYPE)
61046104

61056105
switch (opline->extended_value) {
61066106
case IS_LONG:
6107-
ZVAL_LONG(result, zval_get_long_ex(expr, /* lax */ true));
6107+
ZVAL_LONG(result, zval_get_long(expr));
61086108
break;
61096109
case IS_DOUBLE:
61106110
ZVAL_DOUBLE(result, zval_get_double(expr));
@@ -9028,6 +9028,7 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED)
90289028
zval retval;
90299029

90309030
zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
9031+
// TODO Should this use zval_get_long_ex(&retval, /* is lax */ false);
90319032
count = zval_get_long(&retval);
90329033
zval_ptr_dtor(&retval);
90339034
break;
@@ -9600,7 +9601,7 @@ ZEND_VM_C_LABEL(fetch_dim_r_index_array):
96009601
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
96019602
offset = Z_LVAL_P(dim);
96029603
} else {
9603-
offset = zval_get_long(dim);
9604+
offset = zval_get_long_ex(dim, /* is_lax */ false);
96049605
}
96059606
ht = Z_ARRVAL_P(container);
96069607
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));
@@ -38087,7 +38089,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCO
3808738089

3808838090
switch (opline->extended_value) {
3808938091
case IS_LONG:
38090-
ZVAL_LONG(result, zval_get_long_ex(expr, /* lax */ true));
38092+
ZVAL_LONG(result, zval_get_long(expr));
3809138093
break;
3809238094
case IS_DOUBLE:
3809338095
ZVAL_DOUBLE(result, zval_get_double(expr));
@@ -42550,7 +42552,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_DIM_R_INDEX_
4255042552
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
4255142553
offset = Z_LVAL_P(dim);
4255242554
} else {
42553-
offset = zval_get_long(dim);
42555+
offset = zval_get_long_ex(dim, /* is_lax */ false);
4255442556
}
4255542557
ht = Z_ARRVAL_P(container);
4255642558
ZEND_HASH_INDEX_FIND(ht, offset, value, fetch_dim_r_index_undef);
@@ -42602,7 +42604,7 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_DIM_R_INDEX_
4260242604
if (EXPECTED(Z_TYPE_P(dim) == IS_LONG)) {
4260342605
offset = Z_LVAL_P(dim);
4260442606
} else {
42605-
offset = zval_get_long(dim);
42607+
offset = zval_get_long_ex(dim, /* is_lax */ false);
4260642608
}
4260742609
ht = Z_ARRVAL_P(container);
4260842610
ZEND_HASH_INDEX_FIND(ht, offset, value, fetch_dim_r_index_undef);
@@ -47544,6 +47546,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
4754447546
zval retval;
4754547547

4754647548
zend_call_method_with_0_params(zobj, NULL, NULL, "count", &retval);
47549+
// TODO Should this use zval_get_long_ex(&retval, /* is lax */ false);
4754747550
count = zval_get_long(&retval);
4754847551
zval_ptr_dtor(&retval);
4754947552
break;

0 commit comments

Comments
 (0)