Skip to content

Commit dcf6649

Browse files
committed
Zend/zend_inheritance: Add some const modifiers
1 parent 10c9e4d commit dcf6649

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

Zend/zend_inheritance.c

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

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

@@ -310,7 +310,7 @@ static zend_class_entry *lookup_class(zend_class_entry *scope, zend_string *name
310310
}
311311

312312
/* Instanceof that's safe to use on unlinked classes. */
313-
static bool unlinked_instanceof(zend_class_entry *ce1, const zend_class_entry *ce2) {
313+
static bool unlinked_instanceof(const zend_class_entry *ce1, const zend_class_entry *ce2) {
314314
if (ce1 == ce2) {
315315
return 1;
316316
}
@@ -347,7 +347,7 @@ static bool unlinked_instanceof(zend_class_entry *ce1, const zend_class_entry *c
347347
}
348348
} else {
349349
for (i = 0; i < ce1->num_interfaces; i++) {
350-
zend_class_entry *ce = zend_lookup_class_ex(
350+
const zend_class_entry *ce = zend_lookup_class_ex(
351351
ce1->interface_names[i].name, ce1->interface_names[i].lc_name,
352352
ZEND_FETCH_CLASS_ALLOW_UNLINKED | ZEND_FETCH_CLASS_NO_AUTOLOAD);
353353
/* Avoid recursing if class implements itself. */
@@ -362,7 +362,7 @@ static bool unlinked_instanceof(zend_class_entry *ce1, const zend_class_entry *c
362362
}
363363

364364
static bool zend_type_permits_self(
365-
zend_type type, zend_class_entry *scope, zend_class_entry *self) {
365+
zend_type type, const zend_class_entry *scope, zend_class_entry *self) {
366366
if (ZEND_TYPE_FULL_MASK(type) & MAY_BE_OBJECT) {
367367
return 1;
368368
}
@@ -374,7 +374,7 @@ static bool zend_type_permits_self(
374374
ZEND_TYPE_FOREACH(type, single_type) {
375375
if (ZEND_TYPE_HAS_NAME(*single_type)) {
376376
zend_string *name = resolve_class_name(scope, ZEND_TYPE_NAME(*single_type));
377-
zend_class_entry *ce = lookup_class(self, name);
377+
const zend_class_entry *ce = lookup_class(self, name);
378378
if (ce && unlinked_instanceof(self, ce)) {
379379
return 1;
380380
}
@@ -584,7 +584,7 @@ static inheritance_status zend_is_class_subtype_of_type(
584584
return is_intersection ? INHERITANCE_SUCCESS : INHERITANCE_ERROR;
585585
}
586586

587-
static zend_string *get_class_from_type(zend_class_entry *scope, zend_type single_type) {
587+
static zend_string *get_class_from_type(const zend_class_entry *scope, zend_type single_type) {
588588
if (ZEND_TYPE_HAS_NAME(single_type)) {
589589
return resolve_class_name(scope, ZEND_TYPE_NAME(single_type));
590590
}
@@ -973,7 +973,7 @@ static ZEND_COLD zend_string *zend_get_function_declaration(
973973
{
974974
uint32_t idx = i;
975975
zend_op *op = fptr->op_array.opcodes;
976-
zend_op *end = op + fptr->op_array.last;
976+
const zend_op *end = op + fptr->op_array.last;
977977

978978
++idx;
979979
while (op < end) {
@@ -1366,7 +1366,7 @@ static inheritance_status verify_property_type_compatibility(
13661366
return INHERITANCE_SUCCESS;
13671367
}
13681368

1369-
static bool property_has_operation(zend_property_info *prop_info, zend_property_hook_kind kind)
1369+
static bool property_has_operation(const zend_property_info *prop_info, zend_property_hook_kind kind)
13701370
{
13711371
return (!(prop_info->flags & ZEND_ACC_VIRTUAL)
13721372
&& (kind == ZEND_PROPERTY_HOOK_GET || !(prop_info->flags & ZEND_ACC_READONLY)))
@@ -1649,7 +1649,7 @@ static inheritance_status class_constant_types_compatible(const zend_class_const
16491649
}
16501650

16511651
static bool do_inherit_constant_check(
1652-
zend_class_entry *ce, zend_class_constant *parent_constant, zend_string *name);
1652+
zend_class_entry *ce, const zend_class_constant *parent_constant, zend_string *name);
16531653

16541654
static void do_inherit_class_constant(zend_string *name, zend_class_constant *parent_const, zend_class_entry *ce) /* {{{ */
16551655
{
@@ -1722,7 +1722,7 @@ void zend_build_properties_info_table(zend_class_entry *ce)
17221722
} ZEND_HASH_FOREACH_END();
17231723
}
17241724

1725-
ZEND_API void zend_verify_hooked_property(zend_class_entry *ce, zend_property_info *prop_info, zend_string *prop_name)
1725+
ZEND_API void zend_verify_hooked_property(const zend_class_entry *ce, zend_property_info *prop_info, zend_string *prop_name)
17261726
{
17271727
if (!prop_info->hooks) {
17281728
return;
@@ -1746,7 +1746,7 @@ ZEND_API void zend_verify_hooked_property(zend_class_entry *ce, zend_property_in
17461746
ZVAL_NULL(&ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)]);
17471747
}
17481748
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
1749-
zend_function *func = prop_info->hooks[i];
1749+
const zend_function *func = prop_info->hooks[i];
17501750
if (func) {
17511751
if ((zend_property_hook_kind)i == ZEND_PROPERTY_HOOK_GET
17521752
&& (func->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)
@@ -2077,7 +2077,7 @@ static zend_always_inline bool check_trait_property_or_constant_value_compatibil
20772077

20782078
/** @return bool Returns true if the class constant should be inherited, i.e. whether it doesn't already exist. */
20792079
static bool do_inherit_constant_check(
2080-
zend_class_entry *ce, zend_class_constant *parent_constant, zend_string *name
2080+
zend_class_entry *ce, const zend_class_constant *parent_constant, zend_string *name
20812081
) {
20822082
zval *zv = zend_hash_find_known_hash(&ce->constants_table, name);
20832083
if (zv == NULL) {
@@ -2124,7 +2124,7 @@ static bool do_inherit_constant_check(
21242124
}
21252125
/* }}} */
21262126

2127-
static void do_inherit_iface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
2127+
static void do_inherit_iface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, const zend_class_entry *iface) /* {{{ */
21282128
{
21292129
if (do_inherit_constant_check(ce, c, name)) {
21302130
zend_class_constant *ct;
@@ -2301,7 +2301,7 @@ static void zend_do_implement_interfaces(zend_class_entry *ce, zend_class_entry
23012301
/* }}} */
23022302

23032303

2304-
void zend_inheritance_check_override(zend_class_entry *ce)
2304+
void zend_inheritance_check_override(const zend_class_entry *ce)
23052305
{
23062306
zend_function *f;
23072307

@@ -2423,7 +2423,7 @@ static void zend_fixup_trait_method(zend_function *fn, zend_class_entry *ce) /*
24232423
}
24242424
/* }}} */
24252425

2426-
static void zend_traits_check_private_final_inheritance(uint32_t original_fn_flags, zend_function *fn_copy, zend_string *name)
2426+
static void zend_traits_check_private_final_inheritance(uint32_t original_fn_flags, const zend_function *fn_copy, const zend_string *name)
24272427
{
24282428
/* If the function was originally already private+final, then it will have
24292429
* already been warned about. Only emit this error when the used trait method
@@ -2506,7 +2506,7 @@ static void zend_traits_copy_functions(zend_string *fnname, zend_function *fn, z
25062506
}
25072507
/* }}} */
25082508

2509-
static uint32_t zend_check_trait_usage(zend_class_entry *ce, zend_class_entry *trait, zend_class_entry **traits) /* {{{ */
2509+
static uint32_t zend_check_trait_usage(const zend_class_entry *ce, const zend_class_entry *trait, zend_class_entry **traits) /* {{{ */
25102510
{
25112511
if (UNEXPECTED((trait->ce_flags & ZEND_ACC_TRAIT) != ZEND_ACC_TRAIT)) {
25122512
zend_error_noreturn(E_COMPILE_ERROR, "Class %s is not a trait, Only traits may be used in 'as' and 'insteadof' statements", ZSTR_VAL(trait->name));
@@ -2612,7 +2612,7 @@ static void zend_traits_init_trait_structures(zend_class_entry *ce, zend_class_e
26122612
aliases = ecalloc(i, sizeof(zend_class_entry*));
26132613
i = 0;
26142614
while (ce->trait_aliases[i]) {
2615-
zend_trait_alias *cur_alias = ce->trait_aliases[i];
2615+
const zend_trait_alias *cur_alias = ce->trait_aliases[i];
26162616
cur_method_ref = &ce->trait_aliases[i]->trait_method;
26172617
lcname = zend_string_tolower(cur_method_ref->method_name);
26182618
if (cur_method_ref->class_name) {
@@ -3206,7 +3206,7 @@ static void add_property_hook_obligation(
32063206

32073207
static void resolve_delayed_variance_obligations(zend_class_entry *ce);
32083208

3209-
static void check_variance_obligation(variance_obligation *obligation) {
3209+
static void check_variance_obligation(const variance_obligation *obligation) {
32103210
if (obligation->type == OBLIGATION_DEPENDENCY) {
32113211
zend_class_entry *dependency_ce = obligation->dependency_ce;
32123212
if (dependency_ce->ce_flags & ZEND_ACC_UNRESOLVED_VARIANCE) {
@@ -3245,7 +3245,7 @@ static void check_variance_obligation(variance_obligation *obligation) {
32453245
}
32463246
}
32473247

3248-
static void load_delayed_classes(zend_class_entry *ce) {
3248+
static void load_delayed_classes(const zend_class_entry *ce) {
32493249
HashTable *delayed_autoloads = CG(delayed_autoloads);
32503250
if (!delayed_autoloads) {
32513251
return;
@@ -3274,11 +3274,11 @@ static void load_delayed_classes(zend_class_entry *ce) {
32743274
}
32753275

32763276
static void resolve_delayed_variance_obligations(zend_class_entry *ce) {
3277-
HashTable *all_obligations = CG(delayed_variance_obligations), *obligations;
3277+
HashTable *all_obligations = CG(delayed_variance_obligations);
32783278
zend_ulong num_key = (zend_ulong) (uintptr_t) ce;
32793279

32803280
ZEND_ASSERT(all_obligations != NULL);
3281-
obligations = zend_hash_index_find_ptr(all_obligations, num_key);
3281+
const HashTable *obligations = zend_hash_index_find_ptr(all_obligations, num_key);
32823282
ZEND_ASSERT(obligations != NULL);
32833283

32843284
variance_obligation *obligation;
@@ -3312,7 +3312,7 @@ static void check_unrecoverable_load_failure(const zend_class_entry *ce) {
33123312
} while (0)
33133313

33143314
static zend_op_array *zend_lazy_method_load(
3315-
zend_op_array *op_array, zend_class_entry *ce, const zend_class_entry *pce) {
3315+
const zend_op_array *op_array, zend_class_entry *ce, const zend_class_entry *pce) {
33163316
ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
33173317
ZEND_ASSERT(op_array->scope == pce);
33183318
ZEND_ASSERT(op_array->prototype == NULL);
@@ -3326,7 +3326,7 @@ static zend_op_array *zend_lazy_method_load(
33263326
return new_op_array;
33273327
}
33283328

3329-
static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce)
3329+
static zend_class_entry *zend_lazy_class_load(const zend_class_entry *pce)
33303330
{
33313331
zend_class_entry *ce = zend_arena_alloc(&CG(arena), sizeof(zend_class_entry));
33323332

@@ -3344,7 +3344,7 @@ static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce)
33443344
if (ce->default_properties_table) {
33453345
zval *dst = emalloc(sizeof(zval) * ce->default_properties_count);
33463346
zval *src = ce->default_properties_table;
3347-
zval *end = src + ce->default_properties_count;
3347+
const zval *end = src + ce->default_properties_count;
33483348

33493349
ce->default_properties_table = dst;
33503350
for (; src != end; src++, dst++) {
@@ -3384,7 +3384,7 @@ static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce)
33843384
if (ce->default_static_members_table) {
33853385
zval *dst = emalloc(sizeof(zval) * ce->default_static_members_count);
33863386
zval *src = ce->default_static_members_table;
3387-
zval *end = src + ce->default_static_members_count;
3387+
const zval *end = src + ce->default_static_members_count;
33883388

33893389
ce->default_static_members_table = dst;
33903390
for (; src != end; src++, dst++) {
@@ -3401,9 +3401,9 @@ static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce)
34013401
p = ce->properties_info.arData;
34023402
const Bucket *end = p + ce->properties_info.nNumUsed;
34033403
for (; p != end; p++) {
3404-
zend_property_info *prop_info, *new_prop_info;
3404+
zend_property_info *new_prop_info;
34053405

3406-
prop_info = Z_PTR(p->val);
3406+
const zend_property_info *prop_info = Z_PTR(p->val);
34073407
ZEND_ASSERT(prop_info->ce == pce);
34083408
ZEND_ASSERT(prop_info->prototype == prop_info);
34093409
new_prop_info= zend_arena_alloc(&CG(arena), sizeof(zend_property_info));
@@ -3437,9 +3437,9 @@ static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce)
34373437
p = ce->constants_table.arData;
34383438
const Bucket *end = p + ce->constants_table.nNumUsed;
34393439
for (; p != end; p++) {
3440-
zend_class_constant *c, *new_c;
3440+
zend_class_constant *new_c;
34413441

3442-
c = Z_PTR(p->val);
3442+
const zend_class_constant *c = Z_PTR(p->val);
34433443
ZEND_ASSERT(c->ce == pce);
34443444
new_c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
34453445
Z_PTR(p->val) = new_c;
@@ -3464,7 +3464,7 @@ static zend_class_entry *zend_lazy_class_load(zend_class_entry *pce)
34643464
} while (0)
34653465
#endif
34663466

3467-
ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string *lc_parent_name, zend_string *key) /* {{{ */
3467+
ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string *lc_parent_name, const zend_string *key) /* {{{ */
34683468
{
34693469
/* Load parent/interface dependencies first, so we can still gracefully abort linking
34703470
* with an exception and remove the class from the class table. This is only possible
@@ -3767,7 +3767,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
37673767
/* }}} */
37683768

37693769
/* Check whether early binding is prevented due to unresolved types in inheritance checks. */
3770-
static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_entry *parent_ce) /* {{{ */
3770+
static inheritance_status zend_can_early_bind(zend_class_entry *ce, const zend_class_entry *parent_ce) /* {{{ */
37713771
{
37723772
zend_string *key;
37733773
zend_function *parent_func;

Zend/zend_inheritance.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ static zend_always_inline void zend_do_inheritance(zend_class_entry *ce, zend_cl
3232
zend_do_inheritance_ex(ce, parent_ce, 0);
3333
}
3434

35-
ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string *lc_parent_name, zend_string *key);
35+
ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string *lc_parent_name, const zend_string *key);
3636

3737
void zend_verify_abstract_class(zend_class_entry *ce);
3838
void zend_build_properties_info_table(zend_class_entry *ce);
3939
ZEND_API zend_class_entry *zend_try_early_bind(zend_class_entry *ce, zend_class_entry *parent_ce, zend_string *lcname, zval *delayed_early_binding);
4040

41-
void zend_inheritance_check_override(zend_class_entry *ce);
41+
void zend_inheritance_check_override(const zend_class_entry *ce);
4242

4343
ZEND_API extern zend_class_entry* (*zend_inheritance_cache_get)(zend_class_entry *ce, zend_class_entry *parent, zend_class_entry **traits_and_interfaces);
4444
ZEND_API extern zend_class_entry* (*zend_inheritance_cache_add)(zend_class_entry *ce, zend_class_entry *proto, zend_class_entry *parent, zend_class_entry **traits_and_interfaces, HashTable *dependencies);
@@ -53,7 +53,7 @@ typedef enum {
5353
ZEND_API zend_inheritance_status zend_verify_property_hook_variance(const zend_property_info *prop_info, const zend_function *func);
5454
ZEND_API ZEND_COLD ZEND_NORETURN void zend_hooked_property_variance_error(const zend_property_info *prop_info);
5555
ZEND_API ZEND_COLD ZEND_NORETURN void zend_hooked_property_variance_error_ex(zend_string *value_param_name, zend_string *class_name, zend_string *prop_name);
56-
ZEND_API void zend_verify_hooked_property(zend_class_entry *ce, zend_property_info *prop_info, zend_string *prop_name);
56+
ZEND_API void zend_verify_hooked_property(const zend_class_entry *ce, zend_property_info *prop_info, zend_string *prop_name);
5757

5858
END_EXTERN_C()
5959

0 commit comments

Comments
 (0)