Skip to content

Commit e4498cc

Browse files
committed
New review round
1 parent 6d51940 commit e4498cc

File tree

8 files changed

+50
-44
lines changed

8 files changed

+50
-44
lines changed

Zend/zend_API.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,15 +1412,17 @@ static zend_result update_property(zval *val, zend_property_info *prop_info) {
14121412
return zval_update_constant_ex(val, prop_info->ce);
14131413
}
14141414

1415-
zend_result zend_update_class_constant(zend_class_constant *c, zval *value, zend_class_entry *scope)
1415+
ZEND_API zend_result zend_update_class_constant(zend_class_constant *c, zend_class_entry *scope)
14161416
{
1417+
ZEND_ASSERT(Z_TYPE(c->value) == IS_CONSTANT_AST);
1418+
14171419
if (EXPECTED(!ZEND_TYPE_IS_SET(c->type) || ZEND_TYPE_PURE_MASK(c->type) == MAY_BE_ANY)) {
1418-
return zval_update_constant_ex(value, scope);
1420+
return zval_update_constant_ex(&c->value, scope);
14191421
}
14201422

14211423
zval tmp;
14221424

1423-
ZVAL_COPY_OR_DUP(&tmp, value);
1425+
ZVAL_COPY(&tmp, &c->value);
14241426
zend_result result = zval_update_constant_ex(&tmp, scope);
14251427
if (result == FAILURE) {
14261428
zval_ptr_dtor(&tmp);
@@ -1432,9 +1434,8 @@ zend_result zend_update_class_constant(zend_class_constant *c, zval *value, zend
14321434
return FAILURE;
14331435
}
14341436

1435-
zval_ptr_dtor(value);
1436-
ZVAL_COPY_OR_DUP(value, &tmp);
1437-
zval_ptr_dtor(&tmp);
1437+
zval_ptr_dtor(&c->value);
1438+
ZVAL_COPY_VALUE(&c->value, &tmp);
14381439

14391440
return SUCCESS;
14401441
}
@@ -1497,7 +1498,7 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type) /
14971498
}
14981499

14991500
val = &c->value;
1500-
if (UNEXPECTED(zend_update_class_constant(c, val, c->ce) != SUCCESS)) {
1501+
if (UNEXPECTED(zend_update_class_constant(c, c->ce) != SUCCESS)) {
15011502
return FAILURE;
15021503
}
15031504
}

Zend/zend_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ ZEND_API void zend_declare_class_constant_double(zend_class_entry *ce, const cha
439439
ZEND_API void zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length);
440440
ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
441441

442-
zend_result zend_update_class_constant(zend_class_constant *c, zval *value, zend_class_entry *scope);
442+
ZEND_API zend_result zend_update_class_constant(zend_class_constant *c, zend_class_entry *scope);
443443
ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type);
444444
ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_type);
445445

Zend/zend_constants.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *
361361
}
362362

363363
MARK_CONSTANT_VISITED(ret_constant);
364-
ret = zend_update_class_constant(c, ret_constant, c->ce);
364+
ret = zend_update_class_constant(c, c->ce);
365365
RESET_CONSTANT_VISITED(ret_constant);
366366

367367
if (UNEXPECTED(ret != SUCCESS)) {

Zend/zend_execute.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ static const zend_class_entry *resolve_single_class_type(zend_string *name, cons
918918
}
919919

920920
static zend_always_inline const zend_class_entry *zend_ce_from_type(
921-
const zend_class_entry *class_ce, const zend_type *type) {
921+
const zend_class_entry *scope, const zend_type *type) {
922922
ZEND_ASSERT(ZEND_TYPE_HAS_NAME(*type));
923923
zend_string *name = ZEND_TYPE_NAME(*type);
924924
if (ZSTR_HAS_CE_CACHE(name)) {
@@ -928,53 +928,53 @@ static zend_always_inline const zend_class_entry *zend_ce_from_type(
928928
}
929929
return ce;
930930
}
931-
return resolve_single_class_type(name, class_ce);
931+
return resolve_single_class_type(name, scope);
932932
}
933933

934-
static bool zend_check_intersection_for_property_or_class_constant_class_type(zend_type_list *intersection_type_list,
935-
const zend_class_entry *class_ce, const zend_class_entry *object_ce)
934+
static bool zend_check_intersection_for_property_or_class_constant_class_type(
935+
const zend_class_entry *scope, zend_type_list *intersection_type_list, const zend_class_entry *value_ce)
936936
{
937937
zend_type *list_type;
938938

939939
ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) {
940940
ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
941-
const zend_class_entry *ce = zend_ce_from_type(class_ce, list_type);
942-
if (!ce || !instanceof_function(object_ce, ce)) {
941+
const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
942+
if (!ce || !instanceof_function(value_ce, ce)) {
943943
return false;
944944
}
945945
} ZEND_TYPE_LIST_FOREACH_END();
946946
return true;
947947
}
948948

949949
static bool zend_check_and_resolve_property_or_class_constant_class_type(
950-
zend_type type, const zend_class_entry *class_ce, const zend_class_entry *object_ce) {
951-
if (ZEND_TYPE_HAS_LIST(type)) {
950+
const zend_class_entry *scope, zend_type member_type, const zend_class_entry *value_ce) {
951+
if (ZEND_TYPE_HAS_LIST(member_type)) {
952952
zend_type *list_type;
953-
if (ZEND_TYPE_IS_INTERSECTION(type)) {
953+
if (ZEND_TYPE_IS_INTERSECTION(member_type)) {
954954
return zend_check_intersection_for_property_or_class_constant_class_type(
955-
ZEND_TYPE_LIST(type), class_ce, object_ce);
955+
scope, ZEND_TYPE_LIST(member_type), value_ce);
956956
} else {
957-
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(type), list_type) {
957+
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(member_type), list_type) {
958958
if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
959959
if (zend_check_intersection_for_property_or_class_constant_class_type(
960-
ZEND_TYPE_LIST(*list_type), class_ce, object_ce)) {
960+
scope, ZEND_TYPE_LIST(*list_type), value_ce)) {
961961
return true;
962962
}
963963
continue;
964964
}
965965
ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
966-
const zend_class_entry *ce = zend_ce_from_type(class_ce, list_type);
967-
if (ce && instanceof_function(object_ce, ce)) {
966+
const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
967+
if (ce && instanceof_function(value_ce, ce)) {
968968
return true;
969969
}
970970
} ZEND_TYPE_LIST_FOREACH_END();
971971
return false;
972972
}
973-
} else if ((ZEND_TYPE_PURE_MASK(type) & MAY_BE_STATIC)) {
974-
return instanceof_function(object_ce, class_ce);
973+
} else if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC)) {
974+
return instanceof_function(value_ce, scope);
975975
} else {
976-
const zend_class_entry *ce = zend_ce_from_type(class_ce, &type);
977-
return ce && instanceof_function(object_ce, ce);
976+
const zend_class_entry *ce = zend_ce_from_type(scope, &member_type);
977+
return ce && instanceof_function(value_ce, ce);
978978
}
979979
}
980980

@@ -986,7 +986,7 @@ static zend_always_inline bool i_zend_check_property_type(const zend_property_in
986986
}
987987

988988
if (ZEND_TYPE_IS_COMPLEX(info->type) && Z_TYPE_P(property) == IS_OBJECT
989-
&& zend_check_and_resolve_property_or_class_constant_class_type(info->type, info->ce, Z_OBJCE_P(property))) {
989+
&& zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(property))) {
990990
return 1;
991991
}
992992

@@ -1475,13 +1475,13 @@ static zend_always_inline bool zend_check_class_constant_type(zend_class_constan
14751475
}
14761476

14771477
if (((ZEND_TYPE_PURE_MASK(c->type) & MAY_BE_STATIC) || ZEND_TYPE_IS_COMPLEX(c->type)) && Z_TYPE_P(constant) == IS_OBJECT
1478-
&& zend_check_and_resolve_property_or_class_constant_class_type(c->type, c->ce, Z_OBJCE_P(constant))) {
1478+
&& zend_check_and_resolve_property_or_class_constant_class_type(c->ce, c->type, Z_OBJCE_P(constant))) {
14791479
return 1;
14801480
}
14811481

14821482
uint32_t type_mask = ZEND_TYPE_FULL_MASK(c->type);
14831483
ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_NEVER|MAY_BE_VOID)));
1484-
return zend_verify_scalar_type_hint(type_mask, constant, 1, 0);
1484+
return zend_verify_scalar_type_hint(type_mask, constant, true, false);
14851485
}
14861486

14871487
ZEND_API bool zend_never_inline zend_verify_class_constant_type(zend_class_constant *c, zval *constant)
@@ -3512,7 +3512,7 @@ static zend_always_inline int i_zend_verify_type_assignable_zval(
35123512
}
35133513

35143514
if (ZEND_TYPE_IS_COMPLEX(type) && zv_type == IS_OBJECT
3515-
&& zend_check_and_resolve_property_or_class_constant_class_type(info->type, info->ce, Z_OBJCE_P(zv))) {
3515+
&& zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(zv))) {
35163516
return 1;
35173517
}
35183518

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5991,7 +5991,7 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO
59915991
}
59925992
}
59935993
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
5994-
if (UNEXPECTED(zend_update_class_constant(c, value, c->ce) != SUCCESS)) {
5994+
if (UNEXPECTED(zend_update_class_constant(c, c->ce) != SUCCESS)) {
59955995
ZVAL_UNDEF(EX_VAR(opline->result.var));
59965996
FREE_OP2();
59975997
HANDLE_EXCEPTION();

Zend/zend_vm_execute.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,7 @@ static bool preload_try_resolve_constants(zend_class_entry *ce)
37603760
ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) {
37613761
val = &c->value;
37623762
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
3763-
if (EXPECTED(zend_update_class_constant(c, val, c->ce) == SUCCESS)) {
3763+
if (EXPECTED(zend_update_class_constant(c, c->ce) == SUCCESS)) {
37643764
was_changed = changed = true;
37653765
} else {
37663766
ok = false;

ext/reflection/php_reflection.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,13 +558,14 @@ static void _const_string(smart_str *str, char *name, zval *value, char *indent)
558558
/* {{{ _class_const_string */
559559
static void _class_const_string(smart_str *str, char *name, zend_class_constant *c, char *indent)
560560
{
561-
if (zend_update_class_constant(c, &c->value, c->ce) == FAILURE) {
561+
if (zend_update_class_constant(c, c->ce) == FAILURE) {
562562
return;
563563
}
564564

565565
const char *visibility = zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c));
566566
const char *final = ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_FINAL ? "final " : "";
567-
const char *type = ZEND_TYPE_IS_SET(c->type) ? ZSTR_VAL(zend_type_to_string(c->type)) : zend_zval_type_name(&c->value);
567+
zend_string *type_str = ZEND_TYPE_IS_SET(c->type) ? zend_type_to_string(c->type) : NULL;
568+
const char *type = type_str ? ZSTR_VAL(type_str) : zend_zval_type_name(&c->value);
568569
smart_str_append_printf(str, "%sConstant [ %s%s %s %s ] { ",
569570
indent, final, visibility, type, name);
570571
if (Z_TYPE(c->value) == IS_ARRAY) {
@@ -578,6 +579,10 @@ static void _class_const_string(smart_str *str, char *name, zend_class_constant
578579
zend_tmp_string_release(tmp_value_str);
579580
}
580581
smart_str_appends(str, " }\n");
582+
583+
if (type_str) {
584+
zend_string_release(type_str);
585+
}
581586
}
582587
/* }}} */
583588

@@ -3921,7 +3926,7 @@ ZEND_METHOD(ReflectionClassConstant, getValue)
39213926
GET_REFLECTION_OBJECT_PTR(ref);
39223927

39233928
if (Z_TYPE(ref->value) == IS_CONSTANT_AST) {
3924-
zend_result result = zend_update_class_constant(ref, &ref->value, ref->ce);
3929+
zend_result result = zend_update_class_constant(ref, ref->ce);
39253930
if (result == FAILURE) {
39263931
RETURN_THROWS();
39273932
}
@@ -4730,7 +4735,7 @@ ZEND_METHOD(ReflectionClass, getConstants)
47304735

47314736
array_init(return_value);
47324737
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, constant) {
4733-
if (UNEXPECTED(zend_update_class_constant(constant, &constant->value, constant->ce) != SUCCESS)) {
4738+
if (UNEXPECTED(zend_update_class_constant(constant, constant->ce) != SUCCESS)) {
47344739
RETURN_THROWS();
47354740
}
47364741

@@ -4789,7 +4794,7 @@ ZEND_METHOD(ReflectionClass, getConstant)
47894794
GET_REFLECTION_OBJECT_PTR(ce);
47904795
constants_table = CE_CONSTANTS_TABLE(ce);
47914796
ZEND_HASH_MAP_FOREACH_PTR(constants_table, c) {
4792-
if (UNEXPECTED(zend_update_class_constant(c, &c->value, c->ce) != SUCCESS)) {
4797+
if (UNEXPECTED(zend_update_class_constant(c, c->ce) != SUCCESS)) {
47934798
RETURN_THROWS();
47944799
}
47954800
} ZEND_HASH_FOREACH_END();

0 commit comments

Comments
 (0)