Constify key access for hash and formal params

Keys created in shared memory and won't be modified and are free'd on
restart. Otherwise, keys passed to functions should not be modified,
too.
This commit is contained in:
Anatol Belski 2017-10-19 11:32:42 +02:00
parent efcce55360
commit f24e597c85
6 changed files with 17 additions and 17 deletions

View File

@ -1281,7 +1281,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f
}
/* Adds another key for existing cached script */
static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_hash_entry *bucket)
static void zend_accel_add_key(const char *key, unsigned int key_length, zend_accel_hash_entry *bucket)
{
if (!zend_accel_hash_str_find(&ZCSG(hash), key, key_length)) {
if (zend_accel_hash_is_full(&ZCSG(hash))) {
@ -1360,7 +1360,7 @@ static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script
}
#endif
static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_script *new_persistent_script, char *key, unsigned int key_length, int *from_shared_memory)
static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_script *new_persistent_script, const char *key, unsigned int key_length, int *from_shared_memory)
{
zend_accel_hash_entry *bucket;
uint32_t memory_used;
@ -1550,7 +1550,7 @@ static void zend_accel_init_auto_globals(void)
}
}
static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handle, int type, char *key, zend_op_array **op_array_p)
static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handle, int type, const char *key, zend_op_array **op_array_p)
{
zend_persistent_script *new_persistent_script;
zend_op_array *orig_active_op_array;

View File

@ -71,7 +71,7 @@ void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size)
* Returns pointer the actual hash entry on success
* key needs to be already allocated as it is not copied
*/
zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, char *key, uint32_t key_length, zend_bool indirect, void *data)
zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, const char *key, uint32_t key_length, zend_bool indirect, void *data)
{
zend_ulong hash_value;
zend_ulong index;
@ -140,7 +140,7 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, char
return entry;
}
static zend_always_inline void* zend_accel_hash_find_ex(zend_accel_hash *accel_hash, char *key, uint32_t key_length, zend_ulong hash_value, int data)
static zend_always_inline void* zend_accel_hash_find_ex(zend_accel_hash *accel_hash, const char *key, uint32_t key_length, zend_ulong hash_value, int data)
{
zend_ulong index;
zend_accel_hash_entry *entry;
@ -203,7 +203,7 @@ zend_accel_hash_entry* zend_accel_hash_find_entry(zend_accel_hash *accel_hash, z
/* Returns the data associated with key on success
* Returns NULL if data doesn't exist
*/
void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
{
return zend_accel_hash_find_ex(
accel_hash,
@ -216,7 +216,7 @@ void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, char *key, uint32_t
/* Returns the hash entry associated with key on success
* Returns NULL if it doesn't exist
*/
zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
{
return (zend_accel_hash_entry *)zend_accel_hash_find_ex(
accel_hash,
@ -226,7 +226,7 @@ zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_has
0);
}
int zend_accel_hash_unlink(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
int zend_accel_hash_unlink(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
{
zend_ulong hash_value;
zend_ulong index;

View File

@ -46,7 +46,7 @@ typedef struct _zend_accel_hash_entry zend_accel_hash_entry;
struct _zend_accel_hash_entry {
zend_ulong hash_value;
char *key;
const char *key;
uint32_t key_length;
zend_accel_hash_entry *next;
void *data;
@ -66,7 +66,7 @@ void zend_accel_hash_clean(zend_accel_hash *accel_hash);
zend_accel_hash_entry* zend_accel_hash_update(
zend_accel_hash *accel_hash,
char *key,
const char *key,
uint32_t key_length,
zend_bool indirect,
void *data);
@ -81,17 +81,17 @@ zend_accel_hash_entry* zend_accel_hash_find_entry(
void* zend_accel_hash_str_find(
zend_accel_hash *accel_hash,
char *key,
const char *key,
uint32_t key_length);
zend_accel_hash_entry* zend_accel_hash_str_find_entry(
zend_accel_hash *accel_hash,
char *key,
const char *key,
uint32_t key_length);
int zend_accel_hash_unlink(
zend_accel_hash *accel_hash,
char *key,
const char *key,
uint32_t key_length);
static inline zend_bool zend_accel_hash_is_full(zend_accel_hash *accel_hash)

View File

@ -842,7 +842,7 @@ static void zend_accel_persist_class_table(HashTable *class_table)
zend_hash_apply(class_table, (apply_func_t) zend_update_parent_ce);
}
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, char **key, unsigned int key_length)
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length)
{
script->mem = ZCG(mem);

View File

@ -23,7 +23,7 @@
#define ZEND_PERSIST_H
int zend_accel_script_persistable(zend_persistent_script *script);
uint32_t zend_accel_script_persist_calc(zend_persistent_script *script, char *key, unsigned int key_length, int for_shm);
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, char **key, unsigned int key_length);
uint32_t zend_accel_script_persist_calc(zend_persistent_script *script, const char *key, unsigned int key_length, int for_shm);
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length);
#endif /* ZEND_PERSIST_H */

View File

@ -394,7 +394,7 @@ static void zend_accel_persist_class_table_calc(HashTable *class_table)
zend_hash_persist_calc(class_table, zend_persist_class_entry_calc);
}
uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, char *key, unsigned int key_length, int for_shm)
uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, const char *key, unsigned int key_length, int for_shm)
{
new_persistent_script->mem = NULL;
new_persistent_script->size = 0;