Skip to content

Commit f24e597

Browse files
committed
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.
1 parent efcce55 commit f24e597

6 files changed

+17
-17
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ int zend_accel_invalidate(const char *filename, size_t filename_len, zend_bool f
12811281
}
12821282

12831283
/* Adds another key for existing cached script */
1284-
static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_hash_entry *bucket)
1284+
static void zend_accel_add_key(const char *key, unsigned int key_length, zend_accel_hash_entry *bucket)
12851285
{
12861286
if (!zend_accel_hash_str_find(&ZCSG(hash), key, key_length)) {
12871287
if (zend_accel_hash_is_full(&ZCSG(hash))) {
@@ -1360,7 +1360,7 @@ static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script
13601360
}
13611361
#endif
13621362

1363-
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)
1363+
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)
13641364
{
13651365
zend_accel_hash_entry *bucket;
13661366
uint32_t memory_used;
@@ -1550,7 +1550,7 @@ static void zend_accel_init_auto_globals(void)
15501550
}
15511551
}
15521552

1553-
static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handle, int type, char *key, zend_op_array **op_array_p)
1553+
static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handle, int type, const char *key, zend_op_array **op_array_p)
15541554
{
15551555
zend_persistent_script *new_persistent_script;
15561556
zend_op_array *orig_active_op_array;

ext/opcache/zend_accelerator_hash.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size)
7171
* Returns pointer the actual hash entry on success
7272
* key needs to be already allocated as it is not copied
7373
*/
74-
zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, char *key, uint32_t key_length, zend_bool indirect, void *data)
74+
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)
7575
{
7676
zend_ulong hash_value;
7777
zend_ulong index;
@@ -140,7 +140,7 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, char
140140
return entry;
141141
}
142142

143-
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)
143+
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)
144144
{
145145
zend_ulong index;
146146
zend_accel_hash_entry *entry;
@@ -203,7 +203,7 @@ zend_accel_hash_entry* zend_accel_hash_find_entry(zend_accel_hash *accel_hash, z
203203
/* Returns the data associated with key on success
204204
* Returns NULL if data doesn't exist
205205
*/
206-
void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
206+
void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
207207
{
208208
return zend_accel_hash_find_ex(
209209
accel_hash,
@@ -216,7 +216,7 @@ void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, char *key, uint32_t
216216
/* Returns the hash entry associated with key on success
217217
* Returns NULL if it doesn't exist
218218
*/
219-
zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
219+
zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
220220
{
221221
return (zend_accel_hash_entry *)zend_accel_hash_find_ex(
222222
accel_hash,
@@ -226,7 +226,7 @@ zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_has
226226
0);
227227
}
228228

229-
int zend_accel_hash_unlink(zend_accel_hash *accel_hash, char *key, uint32_t key_length)
229+
int zend_accel_hash_unlink(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
230230
{
231231
zend_ulong hash_value;
232232
zend_ulong index;

ext/opcache/zend_accelerator_hash.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef struct _zend_accel_hash_entry zend_accel_hash_entry;
4646

4747
struct _zend_accel_hash_entry {
4848
zend_ulong hash_value;
49-
char *key;
49+
const char *key;
5050
uint32_t key_length;
5151
zend_accel_hash_entry *next;
5252
void *data;
@@ -66,7 +66,7 @@ void zend_accel_hash_clean(zend_accel_hash *accel_hash);
6666

6767
zend_accel_hash_entry* zend_accel_hash_update(
6868
zend_accel_hash *accel_hash,
69-
char *key,
69+
const char *key,
7070
uint32_t key_length,
7171
zend_bool indirect,
7272
void *data);
@@ -81,17 +81,17 @@ zend_accel_hash_entry* zend_accel_hash_find_entry(
8181

8282
void* zend_accel_hash_str_find(
8383
zend_accel_hash *accel_hash,
84-
char *key,
84+
const char *key,
8585
uint32_t key_length);
8686

8787
zend_accel_hash_entry* zend_accel_hash_str_find_entry(
8888
zend_accel_hash *accel_hash,
89-
char *key,
89+
const char *key,
9090
uint32_t key_length);
9191

9292
int zend_accel_hash_unlink(
9393
zend_accel_hash *accel_hash,
94-
char *key,
94+
const char *key,
9595
uint32_t key_length);
9696

9797
static inline zend_bool zend_accel_hash_is_full(zend_accel_hash *accel_hash)

ext/opcache/zend_persist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ static void zend_accel_persist_class_table(HashTable *class_table)
842842
zend_hash_apply(class_table, (apply_func_t) zend_update_parent_ce);
843843
}
844844

845-
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, char **key, unsigned int key_length)
845+
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length)
846846
{
847847
script->mem = ZCG(mem);
848848

ext/opcache/zend_persist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define ZEND_PERSIST_H
2424

2525
int zend_accel_script_persistable(zend_persistent_script *script);
26-
uint32_t zend_accel_script_persist_calc(zend_persistent_script *script, char *key, unsigned int key_length, int for_shm);
27-
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, char **key, unsigned int key_length);
26+
uint32_t zend_accel_script_persist_calc(zend_persistent_script *script, const char *key, unsigned int key_length, int for_shm);
27+
zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script, const char **key, unsigned int key_length);
2828

2929
#endif /* ZEND_PERSIST_H */

ext/opcache/zend_persist_calc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static void zend_accel_persist_class_table_calc(HashTable *class_table)
394394
zend_hash_persist_calc(class_table, zend_persist_class_entry_calc);
395395
}
396396

397-
uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, char *key, unsigned int key_length, int for_shm)
397+
uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_script, const char *key, unsigned int key_length, int for_shm)
398398
{
399399
new_persistent_script->mem = NULL;
400400
new_persistent_script->size = 0;

0 commit comments

Comments
 (0)