]> granicus.if.org Git - php/commitdiff
Constify key access for hash and formal params
authorAnatol Belski <ab@php.net>
Thu, 19 Oct 2017 09:32:42 +0000 (11:32 +0200)
committerAnatol Belski <ab@php.net>
Thu, 19 Oct 2017 10:07:08 +0000 (12:07 +0200)
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.

ext/opcache/ZendAccelerator.c
ext/opcache/zend_accelerator_hash.c
ext/opcache/zend_accelerator_hash.h
ext/opcache/zend_persist.c
ext/opcache/zend_persist.h
ext/opcache/zend_persist_calc.c

index d0edfa08a239c0683e34d430c355b0f3390e94db..5e0ab19e5797ed2a349407e5cbced060931d8f20 100644 (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;
index 14a83e623bd3f029a7a823a52199447f872daef5..f1f5c43f8448007bcc4ceeb4ae8b17ca5a51e266 100644 (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;
index 1c5b82280ade9fb6ef9c757f3f766463b8f6d5ff..a7ab046cd5490dc1ab2810e3c90e1b0fe0bf6f96 100644 (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)
index dd68305dbd37d3a128c1f57476a2715633937d48..d2d943ddbbc49480ffd276bf180ba887c1bebb8c 100644 (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);
 
index f1a036b880d887712a710451917d5e7c33acd5d1..154c769b54e18de4123e83e3d3cbee6bc75dec68 100644 (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 */
index 312d0d164d2d1e59a6902dd5809dce7910ff2ad6..fd55380ed56e6976cd44e58e6e3baea3586e0000 100644 (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;