Skip to content

Commit b84bdd4

Browse files
committed
minor faffing about
1 parent 1700561 commit b84bdd4

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

Zend/zend_execute.c

Lines changed: 19 additions & 24 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,21 +774,20 @@ 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

789-
ZEND_ASSERT(!Z_ISREF_P(arg));
790-
ZEND_ASSERT(!Z_ISREF_P(coerce_arg));
791-
if (UNEXPECTED(Z_ISUNDEF_P(coerce_arg))) {
789+
ZEND_ASSERT(!Z_ISREF_P(arg) && !Z_ISREF_P(coerce_arg));
790+
if (UNEXPECTED(arg != coerce_arg)) {
792791
ZVAL_COPY(coerce_arg, arg);
793792
}
794793

@@ -801,43 +800,43 @@ static bool zend_coerce_weak_scalar_type_declaration(uint32_t type_mask, const z
801800
if (type == IS_LONG) {
802801
zend_string_release(Z_STR_P(coerce_arg));
803802
ZVAL_LONG(coerce_arg, lval);
804-
return true;
803+
return ZEND_TYPE_CHECK_MAY_COERCE;
805804
}
806805
if (type == IS_DOUBLE) {
807806
zend_string_release(Z_STR_P(coerce_arg));
808807
ZVAL_DOUBLE(coerce_arg, dval);
809-
return true;
808+
return ZEND_TYPE_CHECK_MAY_COERCE;
810809
}
811810
} else if (zend_parse_arg_long_weak(arg, &lval, 0)) {
812811
zval_ptr_dtor(coerce_arg);
813812
ZVAL_LONG(coerce_arg, lval);
814-
return true;
813+
return ZEND_TYPE_CHECK_MAY_COERCE;
815814
} else if (UNEXPECTED(EG(exception))) {
816-
return false;
815+
return ZEND_TYPE_CHECK_INVALID;
817816
}
818817
}
819818
if (type_mask & MAY_BE_DOUBLE) {
820819
dval = zend_parse_arg_double_weak(arg, 0);
821820
if (EXPECTED(!zend_isnan(dval))) {
822821
zval_ptr_dtor(coerce_arg);
823822
ZVAL_DOUBLE(coerce_arg, dval);
824-
return true;
823+
return ZEND_TYPE_CHECK_MAY_COERCE;
825824
}
826825
}
827826
if ((type_mask & MAY_BE_STRING) && zend_parse_arg_str_weak(coerce_arg, 0)) {
828827
/* on success "coerce_arg" is converted to IS_STRING */
829-
return true;
828+
return ZEND_TYPE_CHECK_MAY_COERCE;
830829
}
831830
if ((type_mask & MAY_BE_BOOL) == MAY_BE_BOOL) {
832831
zpp_parse_bool_status bval = zend_parse_arg_bool_weak(arg, 0);
833832
if (UNEXPECTED(bval == ZPP_PARSE_BOOL_STATUS_ERROR)) {
834-
return false;
833+
return ZEND_TYPE_CHECK_INVALID;
835834
}
836835
zval_ptr_dtor(coerce_arg);
837836
ZVAL_BOOL(coerce_arg, bval);
838-
return true;
837+
return ZEND_TYPE_CHECK_MAY_COERCE;
839838
}
840-
return false;
839+
return ZEND_TYPE_CHECK_INVALID;
841840
}
842841

843842
static zend_type_check_status zend_check_type_slow(
@@ -862,14 +861,13 @@ static zend_type_check_status zend_check_type_slow(
862861
} else {
863862
ZEND_ASSERT(ZEND_TYPE_HAS_LIST(*type));
864863
if (ZEND_TYPE_IS_INTERSECTION(*type)) {
865-
return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), arg_ce, scope)
866-
? ZEND_TYPE_CHECK_VALID : ZEND_TYPE_CHECK_INVALID;
864+
return zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*type), arg_ce, scope);
867865
} else {
868866
/* In a union type may be of simple atomic types or a DNF type */
869867
const zend_type *list_type;
870868
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(*type), list_type) {
871869
if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
872-
if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), arg_ce, scope)) {
870+
if (zend_check_intersection_type_from_list(ZEND_TYPE_LIST(*list_type), arg_ce, scope) == ZEND_TYPE_CHECK_VALID) {
873871
return ZEND_TYPE_CHECK_VALID;
874872
}
875873
} else {
@@ -918,9 +916,7 @@ static zend_type_check_status zend_check_type_slow(
918916
&& (type_mask & (MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_BOOL))
919917
) {
920918
if (coerce_arg) {
921-
zend_type_check_status status = zend_coerce_weak_scalar_type_declaration(type_mask, arg, coerce_arg)
922-
? ZEND_TYPE_CHECK_MAY_COERCE : ZEND_TYPE_CHECK_INVALID;
923-
return status;
919+
return zend_coerce_weak_scalar_type_declaration(type_mask, arg, coerce_arg);
924920
}
925921
if (Z_TYPE_P(arg) <= IS_STRING) {
926922
return ZEND_TYPE_CHECK_MAY_COERCE;
@@ -3892,8 +3888,7 @@ static zend_always_inline zend_type_check_status i_zend_verify_type_assignable_z
38923888
bool strict,
38933889
zval *coerced_value
38943890
) {
3895-
zend_type_check_status status = zend_check_type_ex(&info->type, zv, info->ce, strict, 0, coerced_value);
3896-
return status;
3891+
return zend_check_type_ex(&info->type, zv, info->ce, strict, 0, coerced_value);
38973892
}
38983893

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

0 commit comments

Comments
 (0)