Skip to content

Add const to lots of pointers #10608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Zend/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void empty_partial_array(zval *zv)
Z_ARR_P(zv) = zend_new_array(8);
}

static void dup_partial_array(zval *dst, zval *src)
static void dup_partial_array(zval *dst, const zval *src)
{
MAKE_PARTIAL_ARRAY(dst);
Z_ARR_P(dst) = zend_array_dup(Z_ARR_P(src));
Expand All @@ -134,7 +134,7 @@ static void empty_partial_object(zval *zv)
Z_ARR_P(zv) = zend_new_array(8);
}

static void dup_partial_object(zval *dst, zval *src)
static void dup_partial_object(zval *dst, const zval *src)
{
MAKE_PARTIAL_OBJECT(dst);
Z_ARR_P(dst) = zend_array_dup(Z_ARR_P(src));
Expand All @@ -146,7 +146,7 @@ static inline bool value_known(zval *zv) {

/* Sets new value for variable and ensures that it is lower or equal
* the previous one in the constant propagation lattice. */
static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, zval *new) {
static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, const zval *new) {
zval *value = &ctx->values[var];
if (IS_BOT(value) || IS_TOP(new)) {
return;
Expand Down Expand Up @@ -186,7 +186,7 @@ static void set_value(scdf_ctx *scdf, sccp_ctx *ctx, int var, zval *new) {
#endif
}

static zval *get_op1_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
static zval *get_op1_value(sccp_ctx *ctx, zend_op *opline, const zend_ssa_op *ssa_op) {
if (opline->op1_type == IS_CONST) {
return CT_CONSTANT_EX(ctx->scdf.op_array, opline->op1.constant);
} else if (ssa_op->op1_use != -1) {
Expand All @@ -196,7 +196,7 @@ static zval *get_op1_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op)
}
}

static zval *get_op2_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
static zval *get_op2_value(sccp_ctx *ctx, const zend_op *opline, const zend_ssa_op *ssa_op) {
if (opline->op2_type == IS_CONST) {
return CT_CONSTANT_EX(ctx->scdf.op_array, opline->op2.constant);
} else if (ssa_op->op2_use != -1) {
Expand All @@ -207,7 +207,7 @@ static zval *get_op2_value(sccp_ctx *ctx, zend_op *opline, zend_ssa_op *ssa_op)
}

static bool can_replace_op1(
const zend_op_array *op_array, zend_op *opline, zend_ssa_op *ssa_op) {
const zend_op_array *op_array, const zend_op *opline, const zend_ssa_op *ssa_op) {
switch (opline->opcode) {
case ZEND_PRE_INC:
case ZEND_PRE_DEC:
Expand Down Expand Up @@ -441,7 +441,7 @@ static inline zend_result ct_eval_isset_dim(zval *result, uint32_t extended_valu
}
}

static inline zend_result ct_eval_del_array_elem(zval *result, zval *key) {
static inline zend_result ct_eval_del_array_elem(zval *result, const zval *key) {
ZEND_ASSERT(IS_PARTIAL_ARRAY(result));

switch (Z_TYPE_P(key)) {
Expand Down Expand Up @@ -475,7 +475,7 @@ static inline zend_result ct_eval_del_array_elem(zval *result, zval *key) {
return SUCCESS;
}

static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, zval *key) {
static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, const zval *key) {
if (!key) {
SEPARATE_ARRAY(result);
if ((value = zend_hash_next_index_insert(Z_ARR_P(result), value))) {
Expand Down Expand Up @@ -546,7 +546,7 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) {
return SUCCESS;
}

static inline zend_result ct_eval_assign_dim(zval *result, zval *value, zval *key) {
static inline zend_result ct_eval_assign_dim(zval *result, zval *value, const zval *key) {
switch (Z_TYPE_P(result)) {
case IS_NULL:
case IS_FALSE:
Expand Down Expand Up @@ -622,7 +622,7 @@ static inline zend_result ct_eval_isset_obj(zval *result, uint32_t extended_valu
}
}

static inline zend_result ct_eval_del_obj_prop(zval *result, zval *key) {
static inline zend_result ct_eval_del_obj_prop(zval *result, const zval *key) {
ZEND_ASSERT(IS_PARTIAL_OBJECT(result));

switch (Z_TYPE_P(key)) {
Expand All @@ -636,7 +636,7 @@ static inline zend_result ct_eval_del_obj_prop(zval *result, zval *key) {
return SUCCESS;
}

static inline zend_result ct_eval_add_obj_prop(zval *result, zval *value, zval *key) {
static inline zend_result ct_eval_add_obj_prop(zval *result, zval *value, const zval *key) {
switch (Z_TYPE_P(key)) {
case IS_STRING:
value = zend_symtable_update(Z_ARR_P(result), Z_STR_P(key), value);
Expand All @@ -649,7 +649,7 @@ static inline zend_result ct_eval_add_obj_prop(zval *result, zval *value, zval *
return SUCCESS;
}

static inline zend_result ct_eval_assign_obj(zval *result, zval *value, zval *key) {
static inline zend_result ct_eval_assign_obj(zval *result, zval *value, const zval *key) {
switch (Z_TYPE_P(result)) {
case IS_NULL:
case IS_FALSE:
Expand Down
12 changes: 6 additions & 6 deletions Zend/Optimizer/scdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ uint32_t scdf_remove_unreachable_blocks(scdf_ctx *scdf);

/* Add uses to worklist */
static inline void scdf_add_to_worklist(scdf_ctx *scdf, int var_num) {
zend_ssa *ssa = scdf->ssa;
zend_ssa_var *var = &ssa->vars[var_num];
const zend_ssa *ssa = scdf->ssa;
const zend_ssa_var *var = &ssa->vars[var_num];
int use;
zend_ssa_phi *phi;
FOREACH_USE(var, use) {
Expand All @@ -67,16 +67,16 @@ static inline void scdf_add_to_worklist(scdf_ctx *scdf, int var_num) {

/* This should usually not be necessary, however it's used for type narrowing. */
static inline void scdf_add_def_to_worklist(scdf_ctx *scdf, int var_num) {
zend_ssa_var *var = &scdf->ssa->vars[var_num];
const zend_ssa_var *var = &scdf->ssa->vars[var_num];
if (var->definition >= 0) {
zend_bitset_incl(scdf->instr_worklist, var->definition);
} else if (var->definition_phi) {
zend_bitset_incl(scdf->phi_var_worklist, var_num);
}
}

static inline uint32_t scdf_edge(zend_cfg *cfg, int from, int to) {
zend_basic_block *to_block = cfg->blocks + to;
static inline uint32_t scdf_edge(const zend_cfg *cfg, int from, int to) {
const zend_basic_block *to_block = cfg->blocks + to;
int i;

for (i = 0; i < to_block->predecessors_count; i++) {
Expand All @@ -89,7 +89,7 @@ static inline uint32_t scdf_edge(zend_cfg *cfg, int from, int to) {
ZEND_UNREACHABLE();
}

static inline bool scdf_is_edge_feasible(scdf_ctx *scdf, int from, int to) {
static inline bool scdf_is_edge_feasible(const scdf_ctx *scdf, int from, int to) {
uint32_t edge = scdf_edge(&scdf->ssa->cfg, from, to);
return zend_bitset_in(scdf->feasible_edges, edge);
}
Expand Down
4 changes: 2 additions & 2 deletions Zend/Optimizer/zend_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ zend_result zend_optimizer_eval_cast(zval *result, uint32_t type, zval *op1) /*
}
/* }}} */

zend_result zend_optimizer_eval_strlen(zval *result, zval *op1) /* {{{ */
zend_result zend_optimizer_eval_strlen(zval *result, const zval *op1) /* {{{ */
{
if (Z_TYPE_P(op1) != IS_STRING) {
return FAILURE;
Expand Down Expand Up @@ -231,7 +231,7 @@ void zend_optimizer_convert_to_free_op1(zend_op_array *op_array, zend_op *opline
}
}

int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv)
int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv)
{
int i = op_array->last_literal;
op_array->last_literal++;
Expand Down
4 changes: 2 additions & 2 deletions Zend/Optimizer/zend_optimizer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ static inline bool zend_optimizer_is_loop_var_free(const zend_op *opline) {
}

void zend_optimizer_convert_to_free_op1(zend_op_array *op_array, zend_op *opline);
int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv);
int zend_optimizer_add_literal(zend_op_array *op_array, const zval *zv);
bool zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int copy);
void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value);
bool zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value);
zend_result zend_optimizer_eval_binary_op(zval *result, zend_uchar opcode, zval *op1, zval *op2);
zend_result zend_optimizer_eval_unary_op(zval *result, zend_uchar opcode, zval *op1);
zend_result zend_optimizer_eval_cast(zval *result, uint32_t type, zval *op1);
zend_result zend_optimizer_eval_strlen(zval *result, zval *op1);
zend_result zend_optimizer_eval_strlen(zval *result, const zval *op1);
zend_result zend_optimizer_eval_special_func_call(
zval *result, zend_string *name, zend_string *arg);
bool zend_optimizer_update_op1_const(zend_op_array *op_array,
Expand Down
6 changes: 3 additions & 3 deletions Zend/Optimizer/zend_worklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static inline void zend_worklist_stack_push(zend_worklist_stack *stack, int i)
stack->buf[stack->len++] = i;
}

static inline int zend_worklist_stack_peek(zend_worklist_stack *stack)
static inline int zend_worklist_stack_peek(const zend_worklist_stack *stack)
{
ZEND_ASSERT(stack->len);
return stack->buf[stack->len - 1];
Expand Down Expand Up @@ -87,7 +87,7 @@ static inline void zend_worklist_prepare(zend_arena **arena, zend_worklist *work
zend_worklist_stack_prepare(arena, &worklist->stack, len);
}

static inline int zend_worklist_len(zend_worklist *worklist)
static inline int zend_worklist_len(const zend_worklist *worklist)
{
return worklist->stack.len;
}
Expand All @@ -105,7 +105,7 @@ static inline bool zend_worklist_push(zend_worklist *worklist, int i)
return 1;
}

static inline int zend_worklist_peek(zend_worklist *worklist)
static inline int zend_worklist_peek(const zend_worklist *worklist)
{
return zend_worklist_stack_peek(&worklist->stack);
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ static inline bool class_name_refers_to_active_ce(zend_string *class_name, uint3
}
/* }}} */

uint32_t zend_get_class_fetch_type(zend_string *name) /* {{{ */
uint32_t zend_get_class_fetch_type(const zend_string *name) /* {{{ */
{
if (zend_string_equals_literal_ci(name, "self")) {
return ZEND_FETCH_CLASS_SELF;
Expand Down Expand Up @@ -8500,7 +8500,7 @@ static bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
}
/* }}} */

ZEND_API bool zend_is_op_long_compatible(zval *op)
ZEND_API bool zend_is_op_long_compatible(const zval *op)
{
if (Z_TYPE_P(op) == IS_ARRAY) {
return false;
Expand All @@ -8522,7 +8522,7 @@ ZEND_API bool zend_is_op_long_compatible(zval *op)
return true;
}

ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op2) /* {{{ */
ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, const zval *op2) /* {{{ */
{
if ((opcode == ZEND_CONCAT || opcode == ZEND_FAST_CONCAT)) {
/* Array to string warning. */
Expand Down Expand Up @@ -8595,7 +8595,7 @@ static inline bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zva
}
/* }}} */

ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, zval *op)
ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, const zval *op)
{
if (opcode == ZEND_BW_NOT) {
/* BW_NOT on string does not convert the string into an integer. */
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ ZEND_API void pass_two(zend_op_array *op_array);
ZEND_API bool zend_is_compiling(void);
ZEND_API char *zend_make_compiled_string_description(const char *name);
ZEND_API void zend_initialize_class_data(zend_class_entry *ce, bool nullify_handlers);
uint32_t zend_get_class_fetch_type(zend_string *name);
uint32_t zend_get_class_fetch_type(const zend_string *name);
ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc);
ZEND_API bool zend_is_smart_branch(const zend_op *opline);

Expand Down Expand Up @@ -1204,8 +1204,8 @@ END_EXTERN_C()
/* The default value for CG(compiler_options) during eval() */
#define ZEND_COMPILE_DEFAULT_FOR_EVAL 0

ZEND_API bool zend_is_op_long_compatible(zval *op);
ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op2);
ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, zval *op);
ZEND_API bool zend_is_op_long_compatible(const zval *op);
ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, const zval *op2);
ZEND_API bool zend_unary_op_produces_error(uint32_t opcode, const zval *op);

#endif /* ZEND_COMPILE_H */
6 changes: 3 additions & 3 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ ZEND_API void ZEND_COLD zend_incompatible_string_to_long_error(const zend_string
zend_error(E_DEPRECATED, "Implicit conversion from float-string \"%s\" to int loses precision", ZSTR_VAL(s));
}

ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /* {{{ */
ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict) /* {{{ */
{
try_again:
switch (Z_TYPE_P(op)) {
Expand Down Expand Up @@ -935,7 +935,7 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /*
}
/* }}} */

ZEND_API double ZEND_FASTCALL zval_get_double_func(zval *op) /* {{{ */
ZEND_API double ZEND_FASTCALL zval_get_double_func(const zval *op) /* {{{ */
{
try_again:
switch (Z_TYPE_P(op)) {
Expand Down Expand Up @@ -2304,7 +2304,7 @@ static int hash_zval_identical_function(zval *z1, zval *z2) /* {{{ */
}
/* }}} */

ZEND_API bool ZEND_FASTCALL zend_is_identical(zval *op1, zval *op2) /* {{{ */
ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2) /* {{{ */
{
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
return 0;
Expand Down
12 changes: 6 additions & 6 deletions Zend/zend_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ZEND_API zend_result ZEND_FASTCALL shift_left_function(zval *result, zval *op1,
ZEND_API zend_result ZEND_FASTCALL shift_right_function(zval *result, zval *op1, zval *op2);
ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2);

ZEND_API bool ZEND_FASTCALL zend_is_identical(zval *op1, zval *op2);
ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2);

ZEND_API zend_result ZEND_FASTCALL is_equal_function(zval *result, zval *op1, zval *op2);
ZEND_API zend_result ZEND_FASTCALL is_identical_function(zval *result, zval *op1, zval *op2);
Expand Down Expand Up @@ -273,18 +273,18 @@ ZEND_API void ZEND_FASTCALL convert_to_boolean(zval *op);
ZEND_API void ZEND_FASTCALL convert_to_array(zval *op);
ZEND_API void ZEND_FASTCALL convert_to_object(zval *op);

ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict);
ZEND_API double ZEND_FASTCALL zval_get_double_func(zval *op);
ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict);
ZEND_API double ZEND_FASTCALL zval_get_double_func(const zval *op);
ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op);
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op);

static zend_always_inline zend_long zval_get_long(zval *op) {
static zend_always_inline zend_long zval_get_long(const zval *op) {
return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, false);
}
static zend_always_inline zend_long zval_get_long_ex(zval *op, bool is_strict) {
static zend_always_inline zend_long zval_get_long_ex(const zval *op, bool is_strict) {
return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, is_strict);
}
static zend_always_inline double zval_get_double(zval *op) {
static zend_always_inline double zval_get_double(const zval *op) {
return EXPECTED(Z_TYPE_P(op) == IS_DOUBLE) ? Z_DVAL_P(op) : zval_get_double_func(op);
}
static zend_always_inline zend_string *zval_get_string(zval *op) {
Expand Down