Skip to content

Commit a3583d7

Browse files
zend_inheritance.c: make a bunch of pointers const (phpGH-15934)
* zend_inheritance.c: make a bunch of pointers `const` * Fix const double pointers
1 parent 1be989b commit a3583d7

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

Zend/zend_inheritance.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void zend_type_copy_ctor(zend_type *const type, bool use_arena, bool pers
9595
}
9696
}
9797

98-
static zend_function *zend_duplicate_internal_function(zend_function *func, zend_class_entry *ce) /* {{{ */
98+
static zend_function *zend_duplicate_internal_function(zend_function *func, const zend_class_entry *ce) /* {{{ */
9999
{
100100
zend_function *new_function;
101101

@@ -114,7 +114,7 @@ static zend_function *zend_duplicate_internal_function(zend_function *func, zend
114114
}
115115
/* }}} */
116116

117-
static zend_always_inline zend_function *zend_duplicate_function(zend_function *func, zend_class_entry *ce) /* {{{ */
117+
static zend_always_inline zend_function *zend_duplicate_function(zend_function *func, const zend_class_entry *ce) /* {{{ */
118118
{
119119
if (UNEXPECTED(func->type == ZEND_INTERNAL_FUNCTION)) {
120120
return zend_duplicate_internal_function(func, ce);
@@ -239,7 +239,7 @@ static zend_string *resolve_class_name(zend_class_entry *scope, zend_string *nam
239239
}
240240
}
241241

242-
static bool class_visible(zend_class_entry *ce) {
242+
static bool class_visible(const zend_class_entry *ce) {
243243
if (ce->type == ZEND_INTERNAL_CLASS) {
244244
return !(CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES);
245245
} else {
@@ -309,7 +309,7 @@ static zend_class_entry *lookup_class(zend_class_entry *scope, zend_string *name
309309
}
310310

311311
/* Instanceof that's safe to use on unlinked classes. */
312-
static bool unlinked_instanceof(zend_class_entry *ce1, zend_class_entry *ce2) {
312+
static bool unlinked_instanceof(zend_class_entry *ce1, const zend_class_entry *ce2) {
313313
if (ce1 == ce2) {
314314
return 1;
315315
}
@@ -874,7 +874,7 @@ static inheritance_status zend_do_perform_implementation_check(
874874
/* }}} */
875875

876876
static ZEND_COLD void zend_append_type_hint(
877-
smart_str *str, zend_class_entry *scope, zend_arg_info *arg_info, bool return_hint) /* {{{ */
877+
smart_str *str, zend_class_entry *scope, const zend_arg_info *arg_info, bool return_hint) /* {{{ */
878878
{
879879
if (ZEND_TYPE_IS_SET(arg_info->type)) {
880880
zend_string *type_str = zend_type_to_string_resolved(arg_info->type, scope);
@@ -1041,7 +1041,7 @@ static void ZEND_COLD emit_incompatible_method_error(
10411041
if (status == INHERITANCE_UNRESOLVED) {
10421042
// TODO Improve error message if first unresolved class is present in child and parent?
10431043
/* Fetch the first unresolved class from registered autoloads */
1044-
zend_string *unresolved_class = NULL;
1044+
const zend_string *unresolved_class = NULL;
10451045
ZEND_HASH_MAP_FOREACH_STR_KEY(CG(delayed_autoloads), unresolved_class) {
10461046
break;
10471047
} ZEND_HASH_FOREACH_END();
@@ -1051,7 +1051,7 @@ static void ZEND_COLD emit_incompatible_method_error(
10511051
"Could not check compatibility between %s and %s, because class %s is not available",
10521052
ZSTR_VAL(child_prototype), ZSTR_VAL(parent_prototype), ZSTR_VAL(unresolved_class));
10531053
} else if (status == INHERITANCE_WARNING) {
1054-
zend_attribute *return_type_will_change_attribute = zend_get_attribute_str(
1054+
const zend_attribute *return_type_will_change_attribute = zend_get_attribute_str(
10551055
child->common.attributes,
10561056
"returntypewillchange",
10571057
sizeof("returntypewillchange")-1
@@ -1407,7 +1407,7 @@ static void inherit_property_hook(
14071407
* compiler (variadic and by-ref args, etc). */
14081408
}
14091409

1410-
static prop_variance prop_get_variance(zend_property_info *prop_info) {
1410+
static prop_variance prop_get_variance(const zend_property_info *prop_info) {
14111411
bool unbacked = prop_info->flags & ZEND_ACC_VIRTUAL;
14121412
if (unbacked && prop_info->hooks) {
14131413
if (!prop_info->hooks[ZEND_PROPERTY_HOOK_SET]) {
@@ -2649,7 +2649,7 @@ static void zend_do_traits_method_binding(zend_class_entry *ce, zend_class_entry
26492649
}
26502650
/* }}} */
26512651

2652-
static zend_class_entry* find_first_constant_definition(zend_class_entry *ce, zend_class_entry **traits, size_t current_trait, zend_string *constant_name, zend_class_entry *colliding_ce) /* {{{ */
2652+
static const zend_class_entry* find_first_constant_definition(const zend_class_entry *ce, zend_class_entry **traits, size_t current_trait, zend_string *constant_name, const zend_class_entry *colliding_ce) /* {{{ */
26532653
{
26542654
/* This function is used to show the place of the existing conflicting
26552655
* definition in error messages when conflicts occur. Since trait constants
@@ -2674,7 +2674,7 @@ static zend_class_entry* find_first_constant_definition(zend_class_entry *ce, ze
26742674
/* }}} */
26752675

26762676
static void emit_incompatible_trait_constant_error(
2677-
zend_class_entry *ce, zend_class_constant *existing_constant, zend_class_constant *trait_constant, zend_string *name,
2677+
const zend_class_entry *ce, const zend_class_constant *existing_constant, const zend_class_constant *trait_constant, zend_string *name,
26782678
zend_class_entry **traits, size_t current_trait
26792679
) {
26802680
zend_error_noreturn(E_COMPILE_ERROR,
@@ -2770,7 +2770,7 @@ static void zend_do_traits_constant_binding(zend_class_entry *ce, zend_class_ent
27702770
}
27712771
/* }}} */
27722772

2773-
static zend_class_entry* find_first_property_definition(zend_class_entry *ce, zend_class_entry **traits, size_t current_trait, zend_string *prop_name, zend_class_entry *colliding_ce) /* {{{ */
2773+
static const zend_class_entry* find_first_property_definition(const zend_class_entry *ce, zend_class_entry **traits, size_t current_trait, zend_string *prop_name, const zend_class_entry *colliding_ce) /* {{{ */
27742774
{
27752775
size_t i;
27762776

@@ -2791,7 +2791,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
27912791
{
27922792
size_t i;
27932793
zend_property_info *property_info;
2794-
zend_property_info *colliding_prop;
2794+
const zend_property_info *colliding_prop;
27952795
zend_property_info *new_prop;
27962796
zend_string* prop_name;
27972797
zval* prop_value;
@@ -2963,11 +2963,11 @@ static void zend_do_bind_traits(zend_class_entry *ce, zend_class_entry **traits)
29632963
ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
29642964

29652965
typedef struct _zend_abstract_info {
2966-
zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
2966+
const zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
29672967
int cnt;
29682968
} zend_abstract_info;
29692969

2970-
static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai) /* {{{ */
2970+
static void zend_verify_abstract_class_function(const zend_function *fn, zend_abstract_info *ai) /* {{{ */
29712971
{
29722972
if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
29732973
ai->afn[ai->cnt] = fn;
@@ -2978,7 +2978,7 @@ static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract
29782978

29792979
void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
29802980
{
2981-
zend_function *func;
2981+
const zend_function *func;
29822982
zend_abstract_info ai;
29832983
bool is_explicit_abstract = (ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) != 0;
29842984
bool can_be_abstract = (ce->ce_flags & ZEND_ACC_ENUM) == 0;
@@ -2995,11 +2995,11 @@ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */
29952995
} ZEND_HASH_FOREACH_END();
29962996

29972997
if (!is_explicit_abstract) {
2998-
zend_property_info *prop_info;
2998+
const zend_property_info *prop_info;
29992999
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
30003000
if (prop_info->hooks) {
30013001
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
3002-
zend_function *fn = prop_info->hooks[i];
3002+
const zend_function *fn = prop_info->hooks[i];
30033003
if (fn && (fn->common.fn_flags & ZEND_ACC_ABSTRACT)) {
30043004
zend_verify_abstract_class_function(fn, &ai);
30053005
}
@@ -3245,7 +3245,7 @@ static void resolve_delayed_variance_obligations(zend_class_entry *ce) {
32453245
zend_hash_index_del(all_obligations, num_key);
32463246
}
32473247

3248-
static void check_unrecoverable_load_failure(zend_class_entry *ce) {
3248+
static void check_unrecoverable_load_failure(const zend_class_entry *ce) {
32493249
/* If this class has been used while unlinked through a variance obligation, it is not legal
32503250
* to remove the class from the class table and throw an exception, because there is already
32513251
* a dependence on the inheritance hierarchy of this specific class. Instead we fall back to
@@ -3264,7 +3264,7 @@ static void check_unrecoverable_load_failure(zend_class_entry *ce) {
32643264
} while (0)
32653265

32663266
static zend_op_array *zend_lazy_method_load(
3267-
zend_op_array *op_array, zend_class_entry *ce, zend_class_entry *pce) {
3267+
zend_op_array *op_array, zend_class_entry *ce, const zend_class_entry *pce) {
32683268
ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
32693269
ZEND_ASSERT(op_array->scope == pce);
32703270
ZEND_ASSERT(op_array->prototype == NULL);
@@ -3585,7 +3585,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
35853585
zend_verify_enum(ce);
35863586
}
35873587
if (ce->num_hooked_prop_variance_checks) {
3588-
zend_property_info *prop_info;
3588+
const zend_property_info *prop_info;
35893589
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop_info) {
35903590
if (prop_info->ce == ce && prop_info->hooks && prop_info->hooks[ZEND_PROPERTY_HOOK_SET]) {
35913591
switch (zend_verify_property_hook_variance(prop_info, prop_info->hooks[ZEND_PROPERTY_HOOK_SET])) {
@@ -3690,8 +3690,8 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
36903690
{
36913691
zend_string *key;
36923692
zend_function *parent_func;
3693-
zend_property_info *parent_info;
3694-
zend_class_constant *parent_const;
3693+
const zend_property_info *parent_info;
3694+
const zend_class_constant *parent_const;
36953695
inheritance_status overall_status = INHERITANCE_SUCCESS;
36963696

36973697
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, parent_func) {
@@ -3713,14 +3713,14 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
37133713
} ZEND_HASH_FOREACH_END();
37143714

37153715
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->properties_info, key, parent_info) {
3716-
zval *zv;
3716+
const zval *zv;
37173717
if ((parent_info->flags & ZEND_ACC_PRIVATE) || !ZEND_TYPE_IS_SET(parent_info->type)) {
37183718
continue;
37193719
}
37203720

37213721
zv = zend_hash_find_known_hash(&ce->properties_info, key);
37223722
if (zv) {
3723-
zend_property_info *child_info = Z_PTR_P(zv);
3723+
const zend_property_info *child_info = Z_PTR_P(zv);
37243724
if (ZEND_TYPE_IS_SET(child_info->type)) {
37253725
inheritance_status status = verify_property_type_compatibility(parent_info, child_info, prop_get_variance(parent_info), false, false);
37263726
if (UNEXPECTED(status != INHERITANCE_SUCCESS)) {
@@ -3731,14 +3731,14 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
37313731
} ZEND_HASH_FOREACH_END();
37323732

37333733
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->constants_table, key, parent_const) {
3734-
zval *zv;
3734+
const zval *zv;
37353735
if ((ZEND_CLASS_CONST_FLAGS(parent_const) & ZEND_ACC_PRIVATE) || !ZEND_TYPE_IS_SET(parent_const->type)) {
37363736
continue;
37373737
}
37383738

37393739
zv = zend_hash_find_known_hash(&ce->constants_table, key);
37403740
if (zv) {
3741-
zend_class_constant *child_const = Z_PTR_P(zv);
3741+
const zend_class_constant *child_const = Z_PTR_P(zv);
37423742
if (ZEND_TYPE_IS_SET(child_const->type)) {
37433743
inheritance_status status = class_constant_types_compatible(parent_const, child_const);
37443744
ZEND_ASSERT(status != INHERITANCE_WARNING);

0 commit comments

Comments
 (0)