Skip to content

Commit e7cc738

Browse files
committed
minor faffing about
1 parent 2a23b94 commit e7cc738

1 file changed

Lines changed: 18 additions & 23 deletions

File tree

Zend/zend_execute.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ static zend_always_inline const zend_class_entry *zend_ce_from_type(
763763
return resolve_single_class_type(name, scope);
764764
}
765765

766-
static bool zend_check_intersection_type_from_list(
766+
static zend_type_check_status zend_check_intersection_type_from_list(
767767
const zend_type_list *intersection_type_list,
768768
const zend_class_entry *arg_ce,
769769
const zend_class_entry *scope
@@ -774,23 +774,22 @@ static bool zend_check_intersection_type_from_list(
774774
/* If type is not an instance of one of the types taking part in the
775775
* intersection it cannot be a valid instance of the whole intersection type. */
776776
if (UNEXPECTED(!ce || !instanceof_function(arg_ce, ce))) {
777-
return false;
777+
return ZEND_TYPE_CHECK_INVALID;
778778
}
779779
} ZEND_TYPE_LIST_FOREACH_END();
780-
return true;
780+
return ZEND_TYPE_CHECK_VALID;
781781
}
782782

783783
/* Usually coerce_arg will be the same pointer as arg */
784-
static bool zend_coerce_weak_scalar_type_declaration(uint32_t type_mask, const zval *arg, zval *coerce_arg)
784+
static zend_type_check_status zend_coerce_weak_scalar_type_declaration(uint32_t type_mask, const zval *arg, zval *coerce_arg)
785785
{
786786
zend_long lval;
787787
double dval;
788788
zend_string *str;
789789
bool bval;
790790

791-
ZEND_ASSERT(!Z_ISREF_P(arg));
792-
ZEND_ASSERT(!Z_ISREF_P(coerce_arg));
793-
if (UNEXPECTED(Z_ISUNDEF_P(coerce_arg))) {
791+
ZEND_ASSERT(!Z_ISREF_P(arg) && !Z_ISREF_P(coerce_arg));
792+
if (UNEXPECTED(arg != coerce_arg)) {
794793
ZVAL_COPY(coerce_arg, arg);
795794
}
796795

@@ -803,36 +802,36 @@ static bool zend_coerce_weak_scalar_type_declaration(uint32_t type_mask, const z
803802
if (type == IS_LONG) {
804803
zend_string_release(Z_STR_P(coerce_arg));
805804
ZVAL_LONG(coerce_arg, lval);
806-
return true;
805+
return ZEND_TYPE_CHECK_MAY_COERCE;
807806
}
808807
if (type == IS_DOUBLE) {
809808
zend_string_release(Z_STR_P(coerce_arg));
810809
ZVAL_DOUBLE(coerce_arg, dval);
811-
return true;
810+
return ZEND_TYPE_CHECK_MAY_COERCE;
812811
}
813812
} else if (zend_parse_arg_long_weak(arg, &lval, 0)) {
814813
zval_ptr_dtor(coerce_arg);
815814
ZVAL_LONG(coerce_arg, lval);
816-
return true;
815+
return ZEND_TYPE_CHECK_MAY_COERCE;
817816
} else if (UNEXPECTED(EG(exception))) {
818-
return false;
817+
return ZEND_TYPE_CHECK_INVALID;
819818
}
820819
}
821820
if ((type_mask & MAY_BE_DOUBLE) && zend_parse_arg_double_weak(arg, &dval, 0)) {
822821
zval_ptr_dtor(coerce_arg);
823822
ZVAL_DOUBLE(coerce_arg, dval);
824-
return true;
823+
return ZEND_TYPE_CHECK_MAY_COERCE;
825824
}
826825
if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(coerce_arg, &str, 0)) {
827826
/* on success "arg" is converted to IS_STRING */
828-
return true;
827+
return ZEND_TYPE_CHECK_MAY_COERCE;
829828
}
830829
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL && zend_parse_arg_bool_weak(arg, &bval, 0)) {
831830
zval_ptr_dtor(coerce_arg);
832831
ZVAL_BOOL(coerce_arg, bval);
833-
return true;
832+
return ZEND_TYPE_CHECK_MAY_COERCE;
834833
}
835-
return false;
834+
return ZEND_TYPE_CHECK_INVALID;
836835
}
837836

838837
static zend_type_check_status zend_check_type_slow(
@@ -857,14 +856,13 @@ static zend_type_check_status zend_check_type_slow(
857856
} else {
858857
ZEND_ASSERT(ZEND_TYPE_HAS_LIST(*type));
859858
if (ZEND_TYPE_IS_INTERSECTION(*type)) {
860-
return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), arg_ce, scope)
861-
? ZEND_TYPE_CHECK_VALID : ZEND_TYPE_CHECK_INVALID;
859+
return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), arg_ce, scope);
862860
} else {
863861
/* In a union type may be of simple atomic types or a DNF type */
864862
const zend_type *list_type;
865863
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) {
866864
if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
867-
if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), arg_ce, scope)) {
865+
if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), arg_ce, scope) == ZEND_TYPE_CHECK_VALID) {
868866
return ZEND_TYPE_CHECK_VALID;
869867
}
870868
} else {
@@ -913,9 +911,7 @@ static zend_type_check_status zend_check_type_slow(
913911
&& (type_mask & (MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_BOOL))
914912
) {
915913
if (coerce_arg) {
916-
zend_type_check_status status = zend_coerce_weak_scalar_type_declaration(type_mask, arg, coerce_arg)
917-
? ZEND_TYPE_CHECK_MAY_COERCE : ZEND_TYPE_CHECK_INVALID;
918-
return status;
914+
return zend_coerce_weak_scalar_type_declaration(type_mask, arg, coerce_arg);
919915
}
920916
if (Z_TYPE_P(arg) <= IS_STRING) {
921917
return ZEND_TYPE_CHECK_MAY_COERCE;
@@ -3887,8 +3883,7 @@ static zend_always_inline zend_type_check_status i_zend_verify_type_assignable_z
38873883
bool strict,
38883884
zval *coerced_value
38893885
) {
3890-
zend_type_check_status status = zend_check_type_ex(&info->type, zv, info->ce, strict, 0, coerced_value);
3891-
return status;
3886+
return zend_check_type_ex(&info->type, zv, info->ce, strict, 0, coerced_value);
38923887
}
38933888

38943889
ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict)

0 commit comments

Comments
 (0)