Commit d50b91f4fee for php.net
commit d50b91f4fee7bdf65379a2bd31c5f044d7fc716d
Author: Gina Peter Banyard <girgias@php.net>
Date: Mon Mar 9 16:41:41 2026 +0000
ext/opcache: add const qualifiers
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 6ca8171c0a8..43625d6727f 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -1053,7 +1053,7 @@ accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_
!EG(current_execute_data) &&
file_handle->primary_script) {
- zend_stat_t *tmpbuf = sapi_module.get_stat();
+ const zend_stat_t *tmpbuf = sapi_module.get_stat();
if (tmpbuf) {
if (size) {
@@ -1134,7 +1134,7 @@ accel_time_t zend_get_file_handle_timestamp(zend_file_handle *file_handle, size_
return statbuf.st_mtime;
}
-static inline zend_result do_validate_timestamps(zend_persistent_script *persistent_script, zend_file_handle *file_handle)
+static inline zend_result do_validate_timestamps(const zend_persistent_script *persistent_script, zend_file_handle *file_handle)
{
zend_file_handle ps_handle;
zend_string *full_path_ptr = NULL;
@@ -1239,7 +1239,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
} else {
const char *include_path = NULL, *cwd = NULL;
int include_path_len = 0, cwd_len = 0;
- zend_string *parent_script = NULL;
+ const zend_string *parent_script = NULL;
if (EXPECTED(ZCG(cwd_key_len))) {
cwd = ZCG(cwd_key);
@@ -1274,7 +1274,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
}
if (str) {
char buf[32];
- char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, STRTAB_STR_TO_POS(&ZCSG(interned_strings), str));
+ const char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, STRTAB_STR_TO_POS(&ZCSG(interned_strings), str));
cwd_len = ZCG(cwd_key_len) = buf + sizeof(buf) - 1 - res;
cwd = ZCG(cwd_key);
@@ -1318,7 +1318,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
}
if (str) {
char buf[32];
- char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, STRTAB_STR_TO_POS(&ZCSG(interned_strings), str));
+ const char *res = zend_print_long_to_buf(buf + sizeof(buf) - 1, STRTAB_STR_TO_POS(&ZCSG(interned_strings), str));
include_path_len = ZCG(include_path_key_len) = buf + sizeof(buf) - 1 - res;
include_path = ZCG(include_path_key);
@@ -1517,7 +1517,7 @@ static void zend_accel_add_key(zend_string *key, zend_accel_hash_entry *bucket)
}
}
-static zend_always_inline bool is_phar_file(zend_string *filename)
+static zend_always_inline bool is_phar_file(const zend_string *filename)
{
return filename && ZSTR_LEN(filename) >= sizeof(".phar") &&
!memcmp(ZSTR_VAL(filename) + ZSTR_LEN(filename) - (sizeof(".phar")-1), ".phar", sizeof(".phar")-1) &&
@@ -1987,7 +1987,7 @@ static zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int
return op_array;
}
-static bool check_persistent_script_access(zend_persistent_script *persistent_script)
+static bool check_persistent_script_access(const zend_persistent_script *persistent_script)
{
char *phar_path, *ptr;
if ((ZSTR_LEN(persistent_script->script.filename)<sizeof("phar://.phar")) ||
@@ -2288,7 +2288,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
return zend_accel_load_script(persistent_script, from_shared_memory);
}
-static zend_always_inline zend_inheritance_cache_entry* zend_accel_inheritance_cache_find(zend_inheritance_cache_entry *entry, zend_class_entry *ce, zend_class_entry *parent, zend_class_entry **traits_and_interfaces, bool *needs_autoload_ptr)
+static zend_always_inline zend_inheritance_cache_entry* zend_accel_inheritance_cache_find(zend_inheritance_cache_entry *entry, const zend_class_entry *ce, const zend_class_entry *parent, zend_class_entry **traits_and_interfaces, bool *needs_autoload_ptr)
{
uint32_t i;
@@ -2310,10 +2310,10 @@ static zend_always_inline zend_inheritance_cache_entry* zend_accel_inheritance_c
}
if (found && entry->dependencies) {
for (i = 0; i < entry->dependencies_count; i++) {
- zend_class_entry *ce = zend_lookup_class_ex(entry->dependencies[i].name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
+ const zend_class_entry *dependency_ce = zend_lookup_class_ex(entry->dependencies[i].name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
- if (ce != entry->dependencies[i].ce) {
- if (!ce) {
+ if (dependency_ce != entry->dependencies[i].ce) {
+ if (!dependency_ce) {
needs_autoload = true;
} else {
found = false;
@@ -2354,9 +2354,9 @@ static zend_class_entry* zend_accel_inheritance_cache_get(zend_class_entry *ce,
}
for (uint32_t i = 0; i < entry->dependencies_count; i++) {
- zend_class_entry *ce = zend_lookup_class_ex(entry->dependencies[i].name, NULL, 0);
+ const zend_class_entry *dependency_ce = zend_lookup_class_ex(entry->dependencies[i].name, NULL, 0);
- if (ce == NULL) {
+ if (dependency_ce == NULL) {
return NULL;
}
}
@@ -2585,7 +2585,7 @@ static zend_string* persistent_zend_resolve_path(zend_string *filename)
/* lookup by "not-real" path */
key = accel_make_persistent_key(filename);
if (key) {
- zend_accel_hash_entry *bucket = zend_accel_hash_find_entry(&ZCSG(hash), key);
+ const zend_accel_hash_entry *bucket = zend_accel_hash_find_entry(&ZCSG(hash), key);
if (bucket != NULL) {
zend_persistent_script *persistent_script = (zend_persistent_script *)bucket->data;
if (!persistent_script->corrupted) {
@@ -3640,7 +3640,7 @@ static void preload_shutdown(void)
if (EG(function_table)) {
ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(function_table), zv) {
- zend_function *func = Z_PTR_P(zv);
+ const zend_function *func = Z_PTR_P(zv);
if (func->type == ZEND_INTERNAL_FUNCTION) {
break;
}
@@ -3649,7 +3649,7 @@ static void preload_shutdown(void)
if (EG(class_table)) {
ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) {
- zend_class_entry *ce = Z_PTR_P(zv);
+ const zend_class_entry *ce = Z_PTR_P(zv);
if (ce->type == ZEND_INTERNAL_CLASS && Z_TYPE_P(zv) != IS_ALIAS_PTR) {
break;
}
@@ -3676,7 +3676,7 @@ static void preload_restart(void)
}
}
-static size_t preload_try_strip_filename(zend_string *filename) {
+static size_t preload_try_strip_filename(const zend_string *filename) {
/*FIXME: better way to handle eval()'d code? see COMPILED_STRING_DESCRIPTION_FORMAT */
if (ZSTR_LEN(filename) > sizeof(" eval()'d code")
&& *(ZSTR_VAL(filename) + ZSTR_LEN(filename) - sizeof(" eval()'d code")) == ':') {
@@ -3797,17 +3797,17 @@ static void preload_sort_classes(void *base, size_t count, size_t siz, compare_f
Bucket *b2;
Bucket *end = b1 + count;
Bucket tmp;
- zend_class_entry *ce, *p;
+ const zend_class_entry *ce, *p;
while (b1 < end) {
try_again:
- ce = (zend_class_entry*)Z_PTR(b1->val);
+ ce = Z_PTR(b1->val);
if (ce->parent && (ce->ce_flags & ZEND_ACC_LINKED)) {
p = ce->parent;
if (p->type == ZEND_USER_CLASS) {
b2 = b1 + 1;
while (b2 < end) {
- if (p == Z_PTR(b2->val)) {
+ if (p == Z_PTR(b2->val)) {
tmp = *b1;
*b1 = *b2;
*b2 = tmp;
@@ -3824,7 +3824,7 @@ static void preload_sort_classes(void *base, size_t count, size_t siz, compare_f
if (p->type == ZEND_USER_CLASS) {
b2 = b1 + 1;
while (b2 < end) {
- if (p == Z_PTR(b2->val)) {
+ if (p == Z_PTR(b2->val)) {
tmp = *b1;
*b1 = *b2;
*b2 = tmp;
@@ -3850,7 +3850,7 @@ static zend_result preload_resolve_deps(preload_error *error, const zend_class_e
if (ce->parent_name) {
zend_string *key = zend_string_tolower(ce->parent_name);
- zend_class_entry *parent = zend_hash_find_ptr(EG(class_table), key);
+ const zend_class_entry *parent = zend_hash_find_ptr(EG(class_table), key);
zend_string_release(key);
if (!parent) {
error->kind = "Unknown parent ";
@@ -3861,7 +3861,7 @@ static zend_result preload_resolve_deps(preload_error *error, const zend_class_e
if (ce->num_interfaces) {
for (uint32_t i = 0; i < ce->num_interfaces; i++) {
- zend_class_entry *interface =
+ const zend_class_entry *interface =
zend_hash_find_ptr(EG(class_table), ce->interface_names[i].lc_name);
if (!interface) {
error->kind = "Unknown interface ";
@@ -3873,7 +3873,7 @@ static zend_result preload_resolve_deps(preload_error *error, const zend_class_e
if (ce->num_traits) {
for (uint32_t i = 0; i < ce->num_traits; i++) {
- zend_class_entry *trait =
+ const zend_class_entry *trait =
zend_hash_find_ptr(EG(class_table), ce->trait_names[i].lc_name);
if (!trait) {
error->kind = "Unknown trait ";
@@ -3978,7 +3978,7 @@ static void preload_error_cb(int type, zend_string *error_filename, const uint32
static void preload_remove_declares(zend_op_array *op_array)
{
zend_op *opline = op_array->opcodes;
- zend_op *end = opline + op_array->last;
+ const zend_op *end = opline + op_array->last;
uint32_t skip_dynamic_func_count = 0;
zend_string *key;
zend_op_array *func;
@@ -4269,7 +4269,7 @@ static void preload_remove_empty_includes(void)
if (script->empty) {
bool empty = true;
zend_op *opline = script->script.main_op_array.opcodes;
- zend_op *end = opline + script->script.main_op_array.last;
+ const zend_op *end = opline + script->script.main_op_array.last;
while (opline < end) {
if (opline->opcode == ZEND_INCLUDE_OR_EVAL &&
@@ -4310,7 +4310,7 @@ static void preload_remove_empty_includes(void)
/* remove empty includes */
ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) {
zend_op *opline = script->script.main_op_array.opcodes;
- zend_op *end = opline + script->script.main_op_array.last;
+ const zend_op *end = opline + script->script.main_op_array.last;
while (opline < end) {
if (opline->opcode == ZEND_INCLUDE_OR_EVAL &&
@@ -4321,7 +4321,7 @@ static void preload_remove_empty_includes(void)
zend_string *resolved_path = preload_resolve_path(Z_STR_P(RT_CONSTANT(opline, opline->op1)));
if (resolved_path) {
- zend_persistent_script *incl = zend_hash_find_ptr(preload_scripts, resolved_path);
+ const zend_persistent_script *incl = zend_hash_find_ptr(preload_scripts, resolved_path);
if (incl && incl->empty && opline->result_type == IS_UNUSED) {
MAKE_NOP(opline);
} else {
@@ -4339,7 +4339,7 @@ static void preload_remove_empty_includes(void)
} ZEND_HASH_FOREACH_END();
}
-static void preload_register_trait_methods(zend_class_entry *ce) {
+static void preload_register_trait_methods(const zend_class_entry *ce) {
zend_op_array *op_array;
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) {
@@ -4372,7 +4372,7 @@ static void preload_fix_trait_op_array(zend_op_array *op_array)
return;
}
- zend_op_array *orig_op_array = zend_shared_alloc_get_xlat_entry(op_array->refcount);
+ const zend_op_array *orig_op_array = zend_shared_alloc_get_xlat_entry(op_array->refcount);
ZEND_ASSERT(orig_op_array && "Must be in xlat table");
zend_string *function_name = op_array->function_name;
@@ -4390,7 +4390,7 @@ static void preload_fix_trait_op_array(zend_op_array *op_array)
op_array->static_variables = ht;
}
-static void preload_fix_trait_methods(zend_class_entry *ce)
+static void preload_fix_trait_methods(const zend_class_entry *ce)
{
zend_op_array *op_array;
@@ -4415,7 +4415,7 @@ static void preload_fix_trait_methods(zend_class_entry *ce)
static void preload_optimize(zend_persistent_script *script)
{
- zend_class_entry *ce;
+ const zend_class_entry *ce;
zend_persistent_script *tmp_script;
zend_shared_alloc_init_xlat_table();
@@ -4512,10 +4512,10 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
static void preload_load(size_t orig_map_ptr_static_last)
{
/* Load into process tables */
- zend_script *script = &ZCSG(preload_script)->script;
+ const zend_script *script = &ZCSG(preload_script)->script;
if (zend_hash_num_elements(&script->function_table)) {
Bucket *p = script->function_table.arData;
- Bucket *end = p + script->function_table.nNumUsed;
+ const Bucket *end = p + script->function_table.nNumUsed;
zend_hash_extend(CG(function_table),
CG(function_table)->nNumUsed + script->function_table.nNumUsed, 0);
@@ -4526,7 +4526,7 @@ static void preload_load(size_t orig_map_ptr_static_last)
if (zend_hash_num_elements(&script->class_table)) {
Bucket *p = script->class_table.arData;
- Bucket *end = p + script->class_table.nNumUsed;
+ const Bucket *end = p + script->class_table.nNumUsed;
zend_hash_extend(CG(class_table),
CG(class_table)->nNumUsed + script->class_table.nNumUsed, 0);
@@ -4574,7 +4574,7 @@ static void preload_load(size_t orig_map_ptr_static_last)
}
#if HAVE_JIT
-static void zend_accel_clear_call_graph_ptrs(zend_op_array *op_array)
+static void zend_accel_clear_call_graph_ptrs(const zend_op_array *op_array)
{
ZEND_ASSERT(ZEND_USER_CODE(op_array->type));
zend_func_info *info = ZEND_FUNC_INFO(op_array);
@@ -4584,9 +4584,9 @@ static void zend_accel_clear_call_graph_ptrs(zend_op_array *op_array)
}
}
-static void accel_reset_arena_info(zend_persistent_script *script)
+static void accel_reset_arena_info(const zend_persistent_script *script)
{
- zend_op_array *op_array;
+ const zend_op_array *op_array;
zend_class_entry *ce;
zend_accel_clear_call_graph_ptrs(&script->script.main_op_array);