Skip to content

Commit 3c14339

Browse files
committed
New review round
1 parent 857ef14 commit 3c14339

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
@@ -1413,15 +1413,17 @@ static zend_result update_property(zval *val, zend_property_info *prop_info) {
14131413
return zval_update_constant_ex(val, prop_info->ce);
14141414
}
14151415

1416-
zend_result zend_update_class_constant(zend_class_constant *c, zval *value, zend_class_entry *scope)
1416+
ZEND_API zend_result zend_update_class_constant(zend_class_constant *c, zend_class_entry *scope)
14171417
{
1418+
ZEND_ASSERT(Z_TYPE(c->value) == IS_CONSTANT_AST);
1419+
14181420
if (EXPECTED(!ZEND_TYPE_IS_SET(c->type) || ZEND_TYPE_PURE_MASK(c->type) == MAY_BE_ANY)) {
1419-
return zval_update_constant_ex(value, scope);
1421+
return zval_update_constant_ex(&c->value, scope);
14201422
}
14211423

14221424
zval tmp;
14231425

1424-
ZVAL_COPY_OR_DUP(&tmp, value);
1426+
ZVAL_COPY(&tmp, &c->value);
14251427
zend_result result = zval_update_constant_ex(&tmp, scope);
14261428
if (result == FAILURE) {
14271429
zval_ptr_dtor(&tmp);
@@ -1433,9 +1435,8 @@ zend_result zend_update_class_constant(zend_class_constant *c, zval *value, zend
14331435
return FAILURE;
14341436
}
14351437

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

14401441
return SUCCESS;
14411442
}
@@ -1498,7 +1499,7 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type) /
14981499
}
14991500

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

Zend/zend_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ ZEND_API void zend_declare_class_constant_double(zend_class_entry *ce, const cha
440440
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);
441441
ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
442442

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

Zend/zend_constants.c

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

375375
MARK_CONSTANT_VISITED(ret_constant);
376-
ret = zend_update_class_constant(c, ret_constant, c->ce);
376+
ret = zend_update_class_constant(c, c->ce);
377377
RESET_CONSTANT_VISITED(ret_constant);
378378

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

Zend/zend_execute.c

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

928928
static zend_always_inline const zend_class_entry *zend_ce_from_type(
929-
const zend_class_entry *class_ce, const zend_type *type) {
929+
const zend_class_entry *scope, const zend_type *type) {
930930
ZEND_ASSERT(ZEND_TYPE_HAS_NAME(*type));
931931
zend_string *name = ZEND_TYPE_NAME(*type);
932932
if (ZSTR_HAS_CE_CACHE(name)) {
@@ -936,53 +936,53 @@ static zend_always_inline const zend_class_entry *zend_ce_from_type(
936936
}
937937
return ce;
938938
}
939-
return resolve_single_class_type(name, class_ce);
939+
return resolve_single_class_type(name, scope);
940940
}
941941

942-
static bool zend_check_intersection_for_property_or_class_constant_class_type(zend_type_list *intersection_type_list,
943-
const zend_class_entry *class_ce, const zend_class_entry *object_ce)
942+
static bool zend_check_intersection_for_property_or_class_constant_class_type(
943+
const zend_class_entry *scope, zend_type_list *intersection_type_list, const zend_class_entry *value_ce)
944944
{
945945
zend_type *list_type;
946946

947947
ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) {
948948
ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
949-
const zend_class_entry *ce = zend_ce_from_type(class_ce, list_type);
950-
if (!ce || !instanceof_function(object_ce, ce)) {
949+
const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
950+
if (!ce || !instanceof_function(value_ce, ce)) {
951951
return false;
952952
}
953953
} ZEND_TYPE_LIST_FOREACH_END();
954954
return true;
955955
}
956956

957957
static bool zend_check_and_resolve_property_or_class_constant_class_type(
958-
zend_type type, const zend_class_entry *class_ce, const zend_class_entry *object_ce) {
959-
if (ZEND_TYPE_HAS_LIST(type)) {
958+
const zend_class_entry *scope, zend_type member_type, const zend_class_entry *value_ce) {
959+
if (ZEND_TYPE_HAS_LIST(member_type)) {
960960
zend_type *list_type;
961-
if (ZEND_TYPE_IS_INTERSECTION(type)) {
961+
if (ZEND_TYPE_IS_INTERSECTION(member_type)) {
962962
return zend_check_intersection_for_property_or_class_constant_class_type(
963-
ZEND_TYPE_LIST(type), class_ce, object_ce);
963+
scope, ZEND_TYPE_LIST(member_type), value_ce);
964964
} else {
965-
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(type), list_type) {
965+
ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(member_type), list_type) {
966966
if (ZEND_TYPE_IS_INTERSECTION(*list_type)) {
967967
if (zend_check_intersection_for_property_or_class_constant_class_type(
968-
ZEND_TYPE_LIST(*list_type), class_ce, object_ce)) {
968+
scope, ZEND_TYPE_LIST(*list_type), value_ce)) {
969969
return true;
970970
}
971971
continue;
972972
}
973973
ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
974-
const zend_class_entry *ce = zend_ce_from_type(class_ce, list_type);
975-
if (ce && instanceof_function(object_ce, ce)) {
974+
const zend_class_entry *ce = zend_ce_from_type(scope, list_type);
975+
if (ce && instanceof_function(value_ce, ce)) {
976976
return true;
977977
}
978978
} ZEND_TYPE_LIST_FOREACH_END();
979979
return false;
980980
}
981-
} else if ((ZEND_TYPE_PURE_MASK(type) & MAY_BE_STATIC)) {
982-
return instanceof_function(object_ce, class_ce);
981+
} else if ((ZEND_TYPE_PURE_MASK(member_type) & MAY_BE_STATIC)) {
982+
return instanceof_function(value_ce, scope);
983983
} else {
984-
const zend_class_entry *ce = zend_ce_from_type(class_ce, &type);
985-
return ce && instanceof_function(object_ce, ce);
984+
const zend_class_entry *ce = zend_ce_from_type(scope, &member_type);
985+
return ce && instanceof_function(value_ce, ce);
986986
}
987987
}
988988

@@ -994,7 +994,7 @@ static zend_always_inline bool i_zend_check_property_type(const zend_property_in
994994
}
995995

996996
if (ZEND_TYPE_IS_COMPLEX(info->type) && Z_TYPE_P(property) == IS_OBJECT
997-
&& zend_check_and_resolve_property_or_class_constant_class_type(info->type, info->ce, Z_OBJCE_P(property))) {
997+
&& zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(property))) {
998998
return 1;
999999
}
10001000

@@ -1482,13 +1482,13 @@ static zend_always_inline bool zend_check_class_constant_type(zend_class_constan
14821482
}
14831483

14841484
if (((ZEND_TYPE_PURE_MASK(c->type) & MAY_BE_STATIC) || ZEND_TYPE_IS_COMPLEX(c->type)) && Z_TYPE_P(constant) == IS_OBJECT
1485-
&& zend_check_and_resolve_property_or_class_constant_class_type(c->type, c->ce, Z_OBJCE_P(constant))) {
1485+
&& zend_check_and_resolve_property_or_class_constant_class_type(c->ce, c->type, Z_OBJCE_P(constant))) {
14861486
return 1;
14871487
}
14881488

14891489
uint32_t type_mask = ZEND_TYPE_FULL_MASK(c->type);
14901490
ZEND_ASSERT(!(type_mask & (MAY_BE_CALLABLE|MAY_BE_NEVER|MAY_BE_VOID)));
1491-
return zend_verify_scalar_type_hint(type_mask, constant, 1, 0);
1491+
return zend_verify_scalar_type_hint(type_mask, constant, true, false);
14921492
}
14931493

14941494
ZEND_API bool zend_never_inline zend_verify_class_constant_type(zend_class_constant *c, zval *constant)
@@ -3518,7 +3518,7 @@ static zend_always_inline int i_zend_verify_type_assignable_zval(
35183518
}
35193519

35203520
if (ZEND_TYPE_IS_COMPLEX(type) && zv_type == IS_OBJECT
3521-
&& zend_check_and_resolve_property_or_class_constant_class_type(info->type, info->ce, Z_OBJCE_P(zv))) {
3521+
&& zend_check_and_resolve_property_or_class_constant_class_type(info->ce, info->type, Z_OBJCE_P(zv))) {
35223522
return 1;
35233523
}
35243524

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5955,7 +5955,7 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO
59555955
}
59565956
}
59575957
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
5958-
if (UNEXPECTED(zend_update_class_constant(c, value, c->ce) != SUCCESS)) {
5958+
if (UNEXPECTED(zend_update_class_constant(c, c->ce) != SUCCESS)) {
59595959
ZVAL_UNDEF(EX_VAR(opline->result.var));
59605960
FREE_OP2();
59615961
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
@@ -3762,7 +3762,7 @@ static bool preload_try_resolve_constants(zend_class_entry *ce)
37623762
ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) {
37633763
val = &c->value;
37643764
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
3765-
if (EXPECTED(zend_update_class_constant(c, val, c->ce) == SUCCESS)) {
3765+
if (EXPECTED(zend_update_class_constant(c, c->ce) == SUCCESS)) {
37663766
was_changed = changed = true;
37673767
} else {
37683768
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

@@ -3920,7 +3925,7 @@ ZEND_METHOD(ReflectionClassConstant, getValue)
39203925
GET_REFLECTION_OBJECT_PTR(ref);
39213926

39223927
if (Z_TYPE(ref->value) == IS_CONSTANT_AST) {
3923-
zend_result result = zend_update_class_constant(ref, &ref->value, ref->ce);
3928+
zend_result result = zend_update_class_constant(ref, ref->ce);
39243929
if (result == FAILURE) {
39253930
RETURN_THROWS();
39263931
}
@@ -4729,7 +4734,7 @@ ZEND_METHOD(ReflectionClass, getConstants)
47294734

47304735
array_init(return_value);
47314736
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, constant) {
4732-
if (UNEXPECTED(zend_update_class_constant(constant, &constant->value, constant->ce) != SUCCESS)) {
4737+
if (UNEXPECTED(zend_update_class_constant(constant, constant->ce) != SUCCESS)) {
47334738
RETURN_THROWS();
47344739
}
47354740

@@ -4788,7 +4793,7 @@ ZEND_METHOD(ReflectionClass, getConstant)
47884793
GET_REFLECTION_OBJECT_PTR(ce);
47894794
constants_table = CE_CONSTANTS_TABLE(ce);
47904795
ZEND_HASH_MAP_FOREACH_PTR(constants_table, c) {
4791-
if (UNEXPECTED(zend_update_class_constant(c, &c->value, c->ce) != SUCCESS)) {
4796+
if (UNEXPECTED(zend_update_class_constant(c, c->ce) != SUCCESS)) {
47924797
RETURN_THROWS();
47934798
}
47944799
} ZEND_HASH_FOREACH_END();

0 commit comments

Comments
 (0)