Skip to content

Commit e50275e

Browse files
committed
Zend/zend_execute: make several pointers const
1 parent 2d85ed5 commit e50275e

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

Zend/zend_execute.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ static bool zend_verify_weak_scalar_type_hint(uint32_t type_mask, zval *arg)
757757
}
758758

759759
#if ZEND_DEBUG
760-
static bool can_convert_to_string(zval *zv) {
760+
static bool can_convert_to_string(const zval *zv) {
761761
/* We don't call cast_object here, because this check must be side-effect free. As this
762762
* is only used for a sanity check of arginfo/zpp consistency, it's okay if we accept
763763
* more than actually allowed here. */
@@ -769,7 +769,7 @@ static bool can_convert_to_string(zval *zv) {
769769
}
770770

771771
/* Used to sanity-check internal arginfo types without performing any actual type conversions. */
772-
static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask, zval *arg)
772+
static bool zend_verify_weak_scalar_type_hint_no_sideeffect(uint32_t type_mask, const zval *arg)
773773
{
774774
zend_long lval;
775775
double dval;
@@ -814,7 +814,7 @@ ZEND_API bool zend_verify_scalar_type_hint(uint32_t type_mask, zval *arg, bool s
814814
return zend_verify_weak_scalar_type_hint(type_mask, arg);
815815
}
816816

817-
ZEND_COLD zend_never_inline void zend_verify_property_type_error(zend_property_info *info, zval *property)
817+
ZEND_COLD zend_never_inline void zend_verify_property_type_error(const zend_property_info *info, const zval *property)
818818
{
819819
zend_string *type_str;
820820

@@ -832,7 +832,7 @@ ZEND_COLD zend_never_inline void zend_verify_property_type_error(zend_property_i
832832
zend_string_release(type_str);
833833
}
834834

835-
ZEND_COLD void zend_match_unhandled_error(zval *value)
835+
ZEND_COLD void zend_match_unhandled_error(const zval *value)
836836
{
837837
smart_str msg = {0};
838838

@@ -852,18 +852,18 @@ ZEND_COLD void zend_match_unhandled_error(zval *value)
852852
}
853853

854854
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(
855-
zend_property_info *info) {
855+
const zend_property_info *info) {
856856
zend_throw_error(NULL, "Cannot modify readonly property %s::$%s",
857857
ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
858858
}
859859

860-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(zend_property_info *info)
860+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info)
861861
{
862862
zend_throw_error(NULL, "Cannot indirectly modify readonly property %s::$%s",
863863
ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
864864
}
865865

866-
static zend_class_entry *resolve_single_class_type(zend_string *name, zend_class_entry *self_ce) {
866+
static const zend_class_entry *resolve_single_class_type(zend_string *name, const zend_class_entry *self_ce) {
867867
if (zend_string_equals_literal_ci(name, "self")) {
868868
return self_ce;
869869
} else if (zend_string_equals_literal_ci(name, "parent")) {
@@ -873,8 +873,8 @@ static zend_class_entry *resolve_single_class_type(zend_string *name, zend_class
873873
}
874874
}
875875

876-
static zend_always_inline zend_class_entry *zend_ce_from_type(
877-
zend_property_info *info, zend_type *type) {
876+
static zend_always_inline const zend_class_entry *zend_ce_from_type(
877+
const zend_property_info *info, const zend_type *type) {
878878
ZEND_ASSERT(ZEND_TYPE_HAS_NAME(*type));
879879
zend_string *name = ZEND_TYPE_NAME(*type);
880880
if (ZSTR_HAS_CE_CACHE(name)) {
@@ -888,13 +888,13 @@ static zend_always_inline zend_class_entry *zend_ce_from_type(
888888
}
889889

890890
static bool zend_check_intersection_for_property_class_type(zend_type_list *intersection_type_list,
891-
zend_property_info *info, zend_class_entry *object_ce)
891+
const zend_property_info *info, const zend_class_entry *object_ce)
892892
{
893893
zend_type *list_type;
894894

895895
ZEND_TYPE_LIST_FOREACH(intersection_type_list, list_type) {
896896
ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
897-
zend_class_entry *ce = zend_ce_from_type(info, list_type);
897+
const zend_class_entry *ce = zend_ce_from_type(info, list_type);
898898
if (!ce || !instanceof_function(object_ce, ce)) {
899899
return false;
900900
}
@@ -903,7 +903,7 @@ static bool zend_check_intersection_for_property_class_type(zend_type_list *inte
903903
}
904904

905905
static bool zend_check_and_resolve_property_class_type(
906-
zend_property_info *info, zend_class_entry *object_ce) {
906+
const zend_property_info *info, const zend_class_entry *object_ce) {
907907
if (ZEND_TYPE_HAS_LIST(info->type)) {
908908
zend_type *list_type;
909909
if (ZEND_TYPE_IS_INTERSECTION(info->type)) {
@@ -919,20 +919,20 @@ static bool zend_check_and_resolve_property_class_type(
919919
continue;
920920
}
921921
ZEND_ASSERT(!ZEND_TYPE_HAS_LIST(*list_type));
922-
zend_class_entry *ce = zend_ce_from_type(info, list_type);
922+
const zend_class_entry *ce = zend_ce_from_type(info, list_type);
923923
if (ce && instanceof_function(object_ce, ce)) {
924924
return true;
925925
}
926926
} ZEND_TYPE_LIST_FOREACH_END();
927927
return false;
928928
}
929929
} else {
930-
zend_class_entry *ce = zend_ce_from_type(info, &info->type);
930+
const zend_class_entry *ce = zend_ce_from_type(info, &info->type);
931931
return ce && instanceof_function(object_ce, ce);
932932
}
933933
}
934934

935-
static zend_always_inline bool i_zend_check_property_type(zend_property_info *info, zval *property, bool strict)
935+
static zend_always_inline bool i_zend_check_property_type(const zend_property_info *info, zval *property, bool strict)
936936
{
937937
ZEND_ASSERT(!Z_ISREF_P(property));
938938
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(info->type, Z_TYPE_P(property)))) {
@@ -949,7 +949,7 @@ static zend_always_inline bool i_zend_check_property_type(zend_property_info *in
949949
return zend_verify_scalar_type_hint(type_mask, property, strict, 0);
950950
}
951951

952-
static zend_always_inline bool i_zend_verify_property_type(zend_property_info *info, zval *property, bool strict)
952+
static zend_always_inline bool i_zend_verify_property_type(const zend_property_info *info, zval *property, bool strict)
953953
{
954954
if (i_zend_check_property_type(info, property, strict)) {
955955
return 1;
@@ -959,7 +959,7 @@ static zend_always_inline bool i_zend_verify_property_type(zend_property_info *i
959959
return 0;
960960
}
961961

962-
ZEND_API bool zend_never_inline zend_verify_property_type(zend_property_info *info, zval *property, bool strict) {
962+
ZEND_API bool zend_never_inline zend_verify_property_type(const zend_property_info *info, zval *property, bool strict) {
963963
return i_zend_verify_property_type(info, property, strict);
964964
}
965965

@@ -3360,7 +3360,7 @@ static zend_always_inline zend_result zend_fetch_static_property_address(zval **
33603360
return SUCCESS;
33613361
}
33623362

3363-
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(zend_property_info *prop1, zend_property_info *prop2, zval *zv) {
3363+
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) {
33643364
zend_string *type1_str = zend_type_to_string(prop1->type);
33653365
zend_string *type2_str = zend_type_to_string(prop2->type);
33663366
zend_type_error("Reference with value of type %s held by property %s::$%s of type %s is not compatible with property %s::$%s of type %s",
@@ -3376,7 +3376,7 @@ ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(zend_property_info *prop1
33763376
zend_string_release(type2_str);
33773377
}
33783378

3379-
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(zend_property_info *prop, zval *zv) {
3379+
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(const zend_property_info *prop, const zval *zv) {
33803380
zend_string *type_str = zend_type_to_string(prop->type);
33813381
zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s",
33823382
zend_zval_type_name(zv),
@@ -3387,7 +3387,7 @@ ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(zend_property_info *prop,
33873387
zend_string_release(type_str);
33883388
}
33893389

3390-
ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(zend_property_info *prop1, zend_property_info *prop2, zval *zv) {
3390+
ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv) {
33913391
zend_string *type1_str = zend_type_to_string(prop1->type);
33923392
zend_string *type2_str = zend_type_to_string(prop2->type);
33933393
zend_type_error("Cannot assign %s to reference held by property %s::$%s of type %s and property %s::$%s of type %s, as this would result in an inconsistent type conversion",
@@ -3405,7 +3405,7 @@ ZEND_API ZEND_COLD void zend_throw_conflicting_coercion_error(zend_property_info
34053405

34063406
/* 1: valid, 0: invalid, -1: may be valid after type coercion */
34073407
static zend_always_inline int i_zend_verify_type_assignable_zval(
3408-
zend_property_info *info, zval *zv, bool strict) {
3408+
const zend_property_info *info, const zval *zv, bool strict) {
34093409
zend_type type = info->type;
34103410
uint32_t type_mask;
34113411
zend_uchar zv_type = Z_TYPE_P(zv);
@@ -3447,11 +3447,11 @@ static zend_always_inline int i_zend_verify_type_assignable_zval(
34473447

34483448
ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict)
34493449
{
3450-
zend_property_info *prop;
3450+
const zend_property_info *prop;
34513451

34523452
/* The value must satisfy each property type, and coerce to the same value for each property
34533453
* type. Remember the first coerced type and value we've seen for this purpose. */
3454-
zend_property_info *first_prop = NULL;
3454+
const zend_property_info *first_prop = NULL;
34553455
zval coerced_value;
34563456
ZVAL_UNDEF(&coerced_value);
34573457

@@ -3557,7 +3557,7 @@ ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *orig_value, ze
35573557
return variable_ptr;
35583558
}
35593559

3560-
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(zend_property_info *prop_info, zval *orig_val, bool strict) {
3560+
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(const zend_property_info *prop_info, zval *orig_val, bool strict) {
35613561
zval *val = orig_val;
35623562
if (Z_ISREF_P(val) && ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(val))) {
35633563
int result;
@@ -3574,7 +3574,7 @@ ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(zend_property_inf
35743574
zval tmp;
35753575
ZVAL_COPY(&tmp, val);
35763576
if (zend_verify_weak_scalar_type_hint(ZEND_TYPE_FULL_MASK(prop_info->type), &tmp)) {
3577-
zend_property_info *ref_prop = ZEND_REF_FIRST_SOURCE(Z_REF_P(orig_val));
3577+
const zend_property_info *ref_prop = ZEND_REF_FIRST_SOURCE(Z_REF_P(orig_val));
35783578
zend_throw_ref_type_error_type(ref_prop, prop_info, val);
35793579
zval_ptr_dtor(&tmp);
35803580
return 0;
@@ -3615,7 +3615,7 @@ ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_l
36153615
source_list->list = ZEND_PROPERTY_INFO_SOURCE_FROM_LIST(list);
36163616
}
36173617

3618-
ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, zend_property_info *prop)
3618+
ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, const zend_property_info *prop)
36193619
{
36203620
zend_property_info_list *list = ZEND_PROPERTY_INFO_SOURCE_TO_LIST(source_list->list);
36213621
zend_property_info **ptr, **end;

Zend/zend_execute.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, u
6565
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim);
6666

6767
ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict);
68-
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(zend_property_info *prop_info, zval *orig_val, bool strict);
68+
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(const zend_property_info *prop_info, zval *orig_val, bool strict);
6969

70-
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(zend_property_info *prop, zval *zv);
71-
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(zend_property_info *prop1, zend_property_info *prop2, zval *zv);
70+
ZEND_API ZEND_COLD void zend_throw_ref_type_error_zval(const zend_property_info *prop, const zval *zv);
71+
ZEND_API ZEND_COLD void zend_throw_ref_type_error_type(const zend_property_info *prop1, const zend_property_info *prop2, const zval *zv);
7272
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_offset_write(HashTable *ht, zend_long lval);
7373
ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht, zend_string *offset);
7474
ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void);
7575

76-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(zend_property_info *info);
77-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(zend_property_info *info);
76+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(const zend_property_info *info);
77+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info);
7878

7979
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(void);
8080

@@ -108,7 +108,7 @@ ZEND_API bool zend_verify_internal_return_type(zend_function *zf, zval *ret);
108108

109109

110110
ZEND_API void ZEND_FASTCALL zend_ref_add_type_source(zend_property_info_source_list *source_list, zend_property_info *prop);
111-
ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, zend_property_info *prop);
111+
ZEND_API void ZEND_FASTCALL zend_ref_del_type_source(zend_property_info_source_list *source_list, const zend_property_info *prop);
112112

113113
ZEND_API zval* zend_assign_to_typed_ref(zval *variable_ptr, zval *value, zend_uchar value_type, bool strict);
114114

@@ -452,8 +452,8 @@ ZEND_API int ZEND_FASTCALL zend_handle_undef_args(zend_execute_data *call);
452452

453453
#define ZEND_CLASS_HAS_TYPE_HINTS(ce) ((ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) == ZEND_ACC_HAS_TYPE_HINTS)
454454

455-
ZEND_API bool zend_verify_property_type(zend_property_info *info, zval *property, bool strict);
456-
ZEND_COLD void zend_verify_property_type_error(zend_property_info *info, zval *property);
455+
ZEND_API bool zend_verify_property_type(const zend_property_info *info, zval *property, bool strict);
456+
ZEND_COLD void zend_verify_property_type_error(const zend_property_info *info, const zval *property);
457457

458458
#define ZEND_REF_ADD_TYPE_SOURCE(ref, source) \
459459
zend_ref_add_type_source(&ZEND_REF_TYPE_SOURCES(ref), source)
@@ -482,7 +482,7 @@ ZEND_COLD void zend_verify_property_type_error(zend_property_info *info, zval *p
482482
} \
483483
} while (0)
484484

485-
ZEND_COLD void zend_match_unhandled_error(zval *value);
485+
ZEND_COLD void zend_match_unhandled_error(const zval *value);
486486

487487
END_EXTERN_C()
488488

0 commit comments

Comments
 (0)