Skip to content

Commit 4b4869f

Browse files
committed
Merge common "cold" part
1 parent b224878 commit 4b4869f

File tree

1 file changed

+48
-79
lines changed

1 file changed

+48
-79
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 48 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -676,48 +676,56 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
676676
return retval;
677677
}
678678

679-
static void ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zval *container, zval *dim, zval *result)
679+
static zend_never_inline zend_long zend_check_string_offset(zval *dim/*, int type*/)
680680
{
681681
zend_long offset;
682682

683-
try_string_offset:
684-
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
685-
switch (Z_TYPE_P(dim)) {
686-
case IS_STRING:
687-
{
688-
bool trailing_data = false;
689-
/* For BC reasons we allow errors so that we can warn on leading numeric string */
690-
if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
691-
/* allow errors */ true, NULL, &trailing_data)) {
692-
if (UNEXPECTED(trailing_data)) {
693-
zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
694-
}
695-
goto out;
683+
try_again:
684+
switch(Z_TYPE_P(dim)) {
685+
case IS_LONG:
686+
return Z_LVAL_P(dim);
687+
case IS_STRING:
688+
{
689+
bool trailing_data = false;
690+
/* For BC reasons we allow errors so that we can warn on leading numeric string */
691+
if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
692+
/* allow errors */ true, NULL, &trailing_data)) {
693+
if (UNEXPECTED(trailing_data) /*&& type != BP_VAR_UNSET*/) {
694+
zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
696695
}
697-
zend_jit_illegal_string_offset(dim);
698-
break;
696+
return offset;
699697
}
700-
case IS_UNDEF:
701-
zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
702-
case IS_DOUBLE:
703-
case IS_NULL:
704-
case IS_FALSE:
705-
case IS_TRUE:
706-
zend_error(E_WARNING, "String offset cast occurred");
707-
break;
708-
case IS_REFERENCE:
709-
dim = Z_REFVAL_P(dim);
710-
goto try_string_offset;
711-
default:
712-
zend_jit_illegal_string_offset(dim);
713-
break;
698+
zend_jit_illegal_string_offset(dim);
699+
break;
714700
}
701+
case IS_UNDEF:
702+
zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
703+
case IS_DOUBLE:
704+
case IS_NULL:
705+
case IS_FALSE:
706+
case IS_TRUE:
707+
zend_error(E_WARNING, "String offset cast occurred");
708+
break;
709+
case IS_REFERENCE:
710+
dim = Z_REFVAL_P(dim);
711+
goto try_again;
712+
default:
713+
zend_jit_illegal_string_offset(dim);
714+
break;
715+
}
715716

716-
offset = _zval_get_long_func(dim);
717+
return _zval_get_long_func(dim);
718+
}
719+
720+
static void ZEND_FASTCALL zend_jit_fetch_dim_str_r_helper(zval *container, zval *dim, zval *result)
721+
{
722+
zend_long offset;
723+
724+
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
725+
offset = zend_check_string_offset(dim/*, BP_VAR_R*/);
717726
} else {
718727
offset = Z_LVAL_P(dim);
719728
}
720-
out:
721729

722730
if (UNEXPECTED(Z_STRLEN_P(container) < ((offset < 0) ? -(size_t)offset : ((size_t)offset + 1)))) {
723731
zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset);
@@ -824,51 +832,6 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_obj_is_helper(zval *container, zval
824832
}
825833
}
826834

827-
static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type)
828-
{
829-
zend_long offset;
830-
831-
try_again:
832-
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
833-
switch(Z_TYPE_P(dim)) {
834-
case IS_STRING:
835-
{
836-
bool trailing_data = false;
837-
/* For BC reasons we allow errors so that we can warn on leading numeric string */
838-
if (IS_LONG == is_numeric_string_ex(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL,
839-
/* allow errors */ true, NULL, &trailing_data)) {
840-
if (UNEXPECTED(trailing_data) && type != BP_VAR_UNSET) {
841-
zend_error(E_WARNING, "Illegal string offset \"%s\"", Z_STRVAL_P(dim));
842-
}
843-
return offset;
844-
}
845-
zend_jit_illegal_string_offset(dim);
846-
break;
847-
}
848-
case IS_UNDEF:
849-
zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
850-
case IS_DOUBLE:
851-
case IS_NULL:
852-
case IS_FALSE:
853-
case IS_TRUE:
854-
zend_error(E_WARNING, "String offset cast occurred");
855-
break;
856-
case IS_REFERENCE:
857-
dim = Z_REFVAL_P(dim);
858-
goto try_again;
859-
default:
860-
zend_jit_illegal_string_offset(dim);
861-
break;
862-
}
863-
864-
offset = _zval_get_long_func(dim);
865-
} else {
866-
offset = Z_LVAL_P(dim);
867-
}
868-
869-
return offset;
870-
}
871-
872835
static zend_never_inline ZEND_COLD void zend_wrong_string_offset(void)
873836
{
874837
const char *msg = NULL;
@@ -975,7 +938,11 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
975938
size_t string_len;
976939
zend_long offset;
977940

978-
offset = zend_check_string_offset(dim, BP_VAR_W);
941+
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
942+
offset = zend_check_string_offset(dim/*, BP_VAR_W*/);
943+
} else {
944+
offset = Z_LVAL_P(dim);
945+
}
979946
if (offset < -(zend_long)Z_STRLEN_P(str)) {
980947
/* Error on negative offset */
981948
zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset);
@@ -1108,7 +1075,9 @@ static void ZEND_FASTCALL zend_jit_assign_dim_op_helper(zval *container, zval *d
11081075
if (!dim) {
11091076
zend_throw_error(NULL, "[] operator not supported for strings");
11101077
} else {
1111-
zend_check_string_offset(dim, BP_VAR_RW);
1078+
if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
1079+
zend_check_string_offset(dim/*, BP_VAR_RW*/);
1080+
}
11121081
zend_wrong_string_offset();
11131082
}
11141083
//??? } else if (EXPECTED(Z_TYPE_P(container) <= IS_FALSE)) {

0 commit comments

Comments
 (0)