]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: dynhash/dynset: a bit of const-correctness
authorNick Alcock <nick.alcock@oracle.com>
Thu, 24 Apr 2025 13:06:38 +0000 (14:06 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Thu, 30 Oct 2025 14:27:43 +0000 (14:27 +0000)
A pile of dynhash and dynset functions were requiring non-const hashes/sets
unnecessarily.  Fix them.

libctf/ctf-hash.c
libctf/ctf-impl.h
libctf/ctf-inlines.h

index a599607e3d2b59fa740da503f06f652f18c5c203..6b81b562af8e1adb9b646dff830db24a0f4f03d7 100644 (file)
@@ -396,7 +396,7 @@ ctf_dynhash_empty (ctf_dynhash_t *hp)
 }
 
 size_t
-ctf_dynhash_elements (ctf_dynhash_t *hp)
+ctf_dynhash_elements (const ctf_dynhash_t *hp)
 {
   return htab_elements (hp->htab);
 }
@@ -524,7 +524,7 @@ ctf_dynhash_iter_remove (ctf_dynhash_t *hp, ctf_hash_iter_remove_f fun,
    of this into some sort of errno or ctf_errno, which is invariably
    positive.  So doing this simplifies essentially all callers.  */
 int
-ctf_dynhash_next (ctf_dynhash_t *h, ctf_next_t **it, void **key, void **value)
+ctf_dynhash_next (const ctf_dynhash_t *h, ctf_next_t **it, void **key, void **value)
 {
   ctf_next_t *i = *it;
   ctf_helem_t *slot;
@@ -627,7 +627,7 @@ ctf_dynhash_sort_by_name (const ctf_next_hkv_t *one, const ctf_next_hkv_t *two,
 
    If SORT_FUN is null, thunks to ctf_dynhash_next.  */
 int
-ctf_dynhash_next_sorted (ctf_dynhash_t *h, ctf_next_t **it, void **key,
+ctf_dynhash_next_sorted (const ctf_dynhash_t *h, ctf_next_t **it, void **key,
                         void **value, ctf_hash_sort_f sort_fun, void *sort_arg)
 {
   ctf_next_t *i = *it;
@@ -792,7 +792,7 @@ ctf_dynset_remove (ctf_dynset_t *hp, const void *key)
 }
 
 size_t
-ctf_dynset_elements (ctf_dynset_t *hp)
+ctf_dynset_elements (const ctf_dynset_t *hp)
 {
   return htab_elements ((struct htab *) hp);
 }
@@ -849,7 +849,7 @@ ctf_dynset_lookup_any (ctf_dynset_t *hp)
 
    Otherwise, just like ctf_dynhash_next.  */
 int
-ctf_dynset_next (ctf_dynset_t *hp, ctf_next_t **it, void **key)
+ctf_dynset_next (const ctf_dynset_t *hp, ctf_next_t **it, void **key)
 {
   struct htab *htab = (struct htab *) hp;
   ctf_next_t *i = *it;
index 935b4e22507860db553412792f4ef9e6ca725b1c..f3349beb4014bd36cb65c0744eb03afd4d108ebb 100644 (file)
@@ -685,7 +685,7 @@ extern ctf_dynhash_t *ctf_dynhash_create_sized (unsigned long, ctf_hash_fun,
 
 extern int ctf_dynhash_insert (ctf_dynhash_t *, void *, void *);
 extern void ctf_dynhash_remove (ctf_dynhash_t *, const void *);
-extern size_t ctf_dynhash_elements (ctf_dynhash_t *);
+extern size_t ctf_dynhash_elements (const ctf_dynhash_t *);
 extern void ctf_dynhash_empty (ctf_dynhash_t *);
 extern int ctf_dynhash_insert_type (ctf_dict_t *, ctf_dynhash_t *, uint32_t, uint32_t);
 extern ctf_id_t ctf_dynhash_lookup_type (ctf_dynhash_t *, const char *);
@@ -701,9 +701,9 @@ extern void *ctf_dynhash_iter_find (ctf_dynhash_t *, ctf_hash_iter_find_f,
 extern int ctf_dynhash_sort_by_name (const ctf_next_hkv_t *,
                                     const ctf_next_hkv_t *,
                                     void * _libctf_unused_);
-extern int ctf_dynhash_next (ctf_dynhash_t *, ctf_next_t **,
+extern int ctf_dynhash_next (const ctf_dynhash_t *, ctf_next_t **,
                             void **key, void **value);
-extern int ctf_dynhash_next_sorted (ctf_dynhash_t *, ctf_next_t **,
+extern int ctf_dynhash_next_sorted (const ctf_dynhash_t *, ctf_next_t **,
                                    void **key, void **value, ctf_hash_sort_f,
                                    void *);
 extern int ctf_dynhash_next_remove (ctf_next_t * const *);
@@ -711,12 +711,12 @@ extern int ctf_dynhash_next_remove (ctf_next_t * const *);
 extern ctf_dynset_t *ctf_dynset_create (htab_hash, htab_eq, ctf_hash_free_fun);
 extern int ctf_dynset_insert (ctf_dynset_t *, void *);
 extern void ctf_dynset_remove (ctf_dynset_t *, const void *);
-extern size_t ctf_dynset_elements (ctf_dynset_t *);
+extern size_t ctf_dynset_elements (const ctf_dynset_t *);
 extern void ctf_dynset_destroy (ctf_dynset_t *);
 extern void *ctf_dynset_lookup (ctf_dynset_t *, const void *);
 extern int ctf_dynset_exists (ctf_dynset_t *, const void *key,
                              const void **orig_key);
-extern int ctf_dynset_next (ctf_dynset_t *, ctf_next_t **, void **key);
+extern int ctf_dynset_next (const ctf_dynset_t *, ctf_next_t **, void **key);
 extern void *ctf_dynset_lookup_any (ctf_dynset_t *);
 
 extern void ctf_sha1_init (ctf_sha1_t *);
index d1f0691bdae7d61dd0b762bb3e5e4616ec018395..bf4b61e5cea4b72d8d2a400f5cf164bfb8d9dd05 100644 (file)
@@ -47,7 +47,7 @@ ctf_forwardable_kind (int kind)
 }
 
 static inline int
-ctf_dynhash_cnext_sorted (ctf_dynhash_t *h, ctf_next_t **i, const void **key,
+ctf_dynhash_cnext_sorted (const ctf_dynhash_t *h, ctf_next_t **i, const void **key,
                          const void **value, ctf_hash_sort_f sort_fun,
                          void *sort_arg)
 {
@@ -56,7 +56,7 @@ ctf_dynhash_cnext_sorted (ctf_dynhash_t *h, ctf_next_t **i, const void **key,
 }
 
 static inline int
-ctf_dynhash_cnext (ctf_dynhash_t *h, ctf_next_t **it,
+ctf_dynhash_cnext (const ctf_dynhash_t *h, ctf_next_t **it,
                  const void **key, const void **value)
 {
   return ctf_dynhash_next (h, it, (void **) key, (void **) value);
@@ -69,7 +69,7 @@ ctf_dynhash_cinsert (ctf_dynhash_t *h, const void *k, const void *v)
 }
 
 static inline int
-ctf_dynset_cnext (ctf_dynset_t *h, ctf_next_t **it, const void **key)
+ctf_dynset_cnext (const ctf_dynset_t *h, ctf_next_t **it, const void **key)
 {
   return ctf_dynset_next (h, it, (void **) key);
 }