Skip to content

Commit 297179d

Browse files
authored
zend_object_handlers: add some const qualifiers (#20402)
1 parent 0953e89 commit 297179d

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

Zend/zend_API.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,10 +1687,9 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti
16871687
if (object->ce->default_properties_count) {
16881688
zval *prop;
16891689
zend_string *key;
1690-
zend_property_info *property_info;
16911690

16921691
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, prop) {
1693-
property_info = zend_get_property_info(object->ce, key, 1);
1692+
const zend_property_info *property_info = zend_get_property_info(object->ce, key, 1);
16941693
if (property_info != ZEND_WRONG_PROPERTY_INFO &&
16951694
property_info &&
16961695
(property_info->flags & ZEND_ACC_STATIC) == 0) {
@@ -1719,7 +1718,7 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
17191718
zval *prop, tmp;
17201719
zend_string *key;
17211720
zend_long h;
1722-
zend_property_info *property_info;
1721+
const zend_property_info *property_info;
17231722

17241723
ZEND_HASH_FOREACH_KEY_VAL(properties, h, key, prop) {
17251724
if (key) {

Zend/zend_object_handlers.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ ZEND_API HashTable *rebuild_object_properties_internal(zend_object *zobj) /* {{{
106106
/* Implements the fast path for array cast */
107107
ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj) /* {{{ */
108108
{
109-
zend_property_info *prop_info;
110-
zend_class_entry *ce = zobj->ce;
109+
const zend_class_entry *ce = zobj->ce;
111110
HashTable *ht;
112111
zval* prop;
113112
int i;
@@ -118,7 +117,7 @@ ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj) /*
118117
if (ce->default_properties_count) {
119118
zend_hash_real_init_mixed(ht);
120119
for (i = 0; i < ce->default_properties_count; i++) {
121-
prop_info = ce->properties_info_table[i];
120+
const zend_property_info *prop_info = ce->properties_info_table[i];
122121

123122
if (!prop_info) {
124123
continue;
@@ -192,7 +191,7 @@ ZEND_API HashTable *zend_std_get_gc(zend_object *zobj, zval **table, int *n) /*
192191

193192
ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
194193
{
195-
zend_class_entry *ce = object->ce;
194+
const zend_class_entry *ce = object->ce;
196195
zval retval;
197196
HashTable *ht;
198197

@@ -334,7 +333,7 @@ static ZEND_COLD zend_never_inline bool zend_deprecated_dynamic_property(
334333
zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated",
335334
ZSTR_VAL(obj->ce->name), ZSTR_VAL(member));
336335
if (UNEXPECTED(GC_DELREF(obj) == 0)) {
337-
zend_class_entry *ce = obj->ce;
336+
const zend_class_entry *ce = obj->ce;
338337
zend_objects_store_del(obj);
339338
if (!EG(exception)) {
340339
/* We cannot continue execution and have to throw an exception */
@@ -347,7 +346,7 @@ static ZEND_COLD zend_never_inline bool zend_deprecated_dynamic_property(
347346
}
348347

349348
static ZEND_COLD zend_never_inline void zend_readonly_property_unset_error(
350-
zend_class_entry *ce, zend_string *member) {
349+
const zend_class_entry *ce, const zend_string *member) {
351350
zend_throw_error(NULL, "Cannot unset readonly property %s::$%s",
352351
ZSTR_VAL(ce->name), ZSTR_VAL(member));
353352
}
@@ -711,15 +710,15 @@ static bool zend_should_call_hook(const zend_property_info *prop_info, const zen
711710
return true;
712711
}
713712

714-
static ZEND_COLD void zend_throw_no_prop_backing_value_access(zend_string *class_name, zend_string *prop_name, bool is_read)
713+
static ZEND_COLD void zend_throw_no_prop_backing_value_access(const zend_string *class_name, const zend_string *prop_name, bool is_read)
715714
{
716715
zend_throw_error(NULL, "Must not %s virtual property %s::$%s",
717716
is_read ? "read from" : "write to",
718717
ZSTR_VAL(class_name), ZSTR_VAL(prop_name));
719718
}
720719

721720
static bool zend_call_get_hook(
722-
const zend_property_info *prop_info, zend_string *prop_name,
721+
const zend_property_info *prop_info, const zend_string *prop_name,
723722
zend_function *get, zend_object *zobj, zval *rv)
724723
{
725724
if (!zend_should_call_hook(prop_info, zobj)) {
@@ -842,15 +841,15 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
842841
goto exit;
843842
}
844843

845-
zend_class_entry *ce = zobj->ce;
844+
const zend_class_entry *ce = zobj->ce;
846845

847846
if (!zend_call_get_hook(prop_info, name, get, zobj, rv)) {
848847
if (EG(exception)) {
849848
return &EG(uninitialized_zval);
850849
}
851850

852851
/* Reads from backing store can only occur in hooks, and hence will always remain simple. */
853-
zend_execute_data *execute_data = EG(current_execute_data);
852+
const zend_execute_data *execute_data = EG(current_execute_data);
854853
if (cache_slot && EX(opline) && EX(opline)->opcode == ZEND_FETCH_OBJ_R && EX(opline)->op1_type == IS_UNUSED) {
855854
ZEND_SET_PROPERTY_HOOK_SIMPLE_READ(cache_slot);
856855
}
@@ -1274,15 +1273,15 @@ found:;
12741273
}
12751274
/* }}} */
12761275

1277-
static ZEND_COLD zend_never_inline void zend_bad_array_access(zend_class_entry *ce) /* {{{ */
1276+
static ZEND_COLD zend_never_inline void zend_bad_array_access(const zend_class_entry *ce) /* {{{ */
12781277
{
12791278
zend_throw_error(NULL, "Cannot use object of type %s as array", ZSTR_VAL(ce->name));
12801279
}
12811280
/* }}} */
12821281

12831282
ZEND_API zval *zend_std_read_dimension(zend_object *object, zval *offset, int type, zval *rv) /* {{{ */
12841283
{
1285-
zend_class_entry *ce = object->ce;
1284+
const zend_class_entry *ce = object->ce;
12861285
zval tmp_offset;
12871286

12881287
/* arrayaccess_funcs_ptr is set if (and only if) the class implements zend_ce_arrayaccess */
@@ -1333,7 +1332,7 @@ ZEND_API zval *zend_std_read_dimension(zend_object *object, zval *offset, int ty
13331332

13341333
ZEND_API void zend_std_write_dimension(zend_object *object, zval *offset, zval *value) /* {{{ */
13351334
{
1336-
zend_class_entry *ce = object->ce;
1335+
const zend_class_entry *ce = object->ce;
13371336
zval tmp_offset;
13381337

13391338
zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr;
@@ -1356,7 +1355,7 @@ ZEND_API void zend_std_write_dimension(zend_object *object, zval *offset, zval *
13561355
// todo: make zend_std_has_dimension return bool as well
13571356
ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check_empty) /* {{{ */
13581357
{
1359-
zend_class_entry *ce = object->ce;
1358+
const zend_class_entry *ce = object->ce;
13601359
zval retval, tmp_offset;
13611360
bool result;
13621361

@@ -1610,7 +1609,7 @@ ZEND_API void zend_std_unset_property(zend_object *zobj, zend_string *name, void
16101609

16111610
ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset) /* {{{ */
16121611
{
1613-
zend_class_entry *ce = object->ce;
1612+
const zend_class_entry *ce = object->ce;
16141613
zval tmp_offset;
16151614

16161615
zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr;
@@ -1626,7 +1625,7 @@ ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset) /* {{{
16261625
}
16271626
/* }}} */
16281627

1629-
static zend_never_inline zend_function *zend_get_parent_private_method(zend_class_entry *scope, zend_class_entry *ce, zend_string *function_name) /* {{{ */
1628+
static zend_never_inline zend_function *zend_get_parent_private_method(const zend_class_entry *scope, const zend_class_entry *ce, zend_string *function_name) /* {{{ */
16301629
{
16311630
zval *func;
16321631
zend_function *fbc;
@@ -1747,7 +1746,7 @@ static ZEND_FUNCTION(zend_parent_hook_get_trampoline)
17471746
}
17481747

17491748
zval rv;
1750-
zval *retval = obj->handlers->read_property(obj, prop_name, BP_VAR_R, NULL, &rv);
1749+
const zval *retval = obj->handlers->read_property(obj, prop_name, BP_VAR_R, NULL, &rv);
17511750
if (retval == &rv) {
17521751
RETVAL_COPY_VALUE(retval);
17531752
} else {
@@ -1846,7 +1845,6 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
18461845
zval *func;
18471846
zend_function *fbc;
18481847
zend_string *lc_method_name;
1849-
zend_class_entry *scope;
18501848
ALLOCA_FLAG(use_heap);
18511849

18521850
if (EXPECTED(key != NULL)) {
@@ -1874,7 +1872,7 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
18741872

18751873
/* Check access level */
18761874
if (fbc->op_array.fn_flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
1877-
scope = zend_get_executed_scope();
1875+
const zend_class_entry *scope = zend_get_executed_scope();
18781876

18791877
if (fbc->common.scope != scope) {
18801878
if (fbc->op_array.fn_flags & ZEND_ACC_CHANGED) {
@@ -1930,7 +1928,7 @@ static zend_always_inline zend_function *get_static_method_fallback(
19301928
}
19311929
}
19321930

1933-
ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_string *function_name, const zval *key) /* {{{ */
1931+
ZEND_API zend_function *zend_std_get_static_method(const zend_class_entry *ce, zend_string *function_name, const zval *key) /* {{{ */
19341932
{
19351933
zend_string *lc_function_name;
19361934
if (EXPECTED(key != NULL)) {
@@ -1944,7 +1942,7 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_st
19441942
if (EXPECTED(func)) {
19451943
fbc = Z_FUNC_P(func);
19461944
if (!(fbc->common.fn_flags & ZEND_ACC_PUBLIC)) {
1947-
zend_class_entry *scope = zend_get_executed_scope();
1945+
const zend_class_entry *scope = zend_get_executed_scope();
19481946
ZEND_ASSERT(!(fbc->common.fn_flags & ZEND_ACC_PUBLIC));
19491947
if (!zend_check_method_accessible(fbc, scope)) {
19501948
zend_function *fallback_fbc = get_static_method_fallback(ce, function_name);
@@ -2442,7 +2440,7 @@ ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *w
24422440
{
24432441
switch (type) {
24442442
case IS_STRING: {
2445-
zend_class_entry *ce = readobj->ce;
2443+
const zend_class_entry *ce = readobj->ce;
24462444
if (ce->__tostring) {
24472445
zval retval;
24482446
GC_ADDREF(readobj);
@@ -2475,7 +2473,7 @@ ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *w
24752473
ZEND_API zend_result zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */
24762474
{
24772475
zend_class_entry *ce = obj->ce;
2478-
zval *func = zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));
2476+
const zval *func = zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));
24792477

24802478
if (func == NULL) {
24812479
return FAILURE;

Zend/zend_object_handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ extern const ZEND_API zend_object_handlers std_object_handlers;
248248
#define ZEND_PROPERTY_EXISTS 0x2 /* Property exists */
249249

250250
ZEND_API void zend_class_init_statics(zend_class_entry *ce);
251-
ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_string *function_name_strval, const zval *key);
251+
ZEND_API zend_function *zend_std_get_static_method(const zend_class_entry *ce, zend_string *function_name_strval, const zval *key);
252252
ZEND_API zval *zend_std_get_static_property_with_info(zend_class_entry *ce, zend_string *property_name, int type, struct _zend_property_info **prop_info);
253253
ZEND_API zval *zend_std_get_static_property(zend_class_entry *ce, zend_string *property_name, int type);
254254
ZEND_API ZEND_COLD bool zend_std_unset_static_property(const zend_class_entry *ce, const zend_string *property_name);

0 commit comments

Comments
 (0)