[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 08/25] tools/xenstore: make hashtable key and value parameters const
On 25.07.23 18:08, Julien Grall wrote:
Hi,
On 24/07/2023 12:02, Juergen Gross wrote:
The key and value are never modified by hashtable code, so they should
be marked as const.
You wrote this but...
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
V3:
- make value const, too.
---
tools/xenstore/hashtable.c | 7 ++++---
tools/xenstore/hashtable.h | 4 ++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c
index 11f6bf8f15..670dc01003 100644
--- a/tools/xenstore/hashtable.c
+++ b/tools/xenstore/hashtable.c
@@ -11,7 +11,8 @@
struct entry
{
- void *k, *v;
+ const void *k;
+ void *v;
... this is not const and ...
unsigned int h;
struct entry *next;
};
@@ -140,7 +141,7 @@ static int hashtable_expand(struct hashtable *h)
return 0;
}
-int hashtable_add(struct hashtable *h, void *k, void *v)
+int hashtable_add(struct hashtable *h, const void *k, const void *v)
{
/* This method allows duplicate keys - but they shouldn't be used */
unsigned int index;
@@ -164,7 +165,7 @@ int hashtable_add(struct hashtable *h, void *k, void *v)
e->k = k;
if (h->flags & HASHTABLE_FREE_KEY)
talloc_steal(e, k);
- e->v = v;
+ e->v = (void *)v;
... you cast-away the const here. I think this is a pretty bad idea.
Can you clarify why you are doing like that?
The value is never changed by the hashtable code, but it might be changed by
e.g. a caller of hashtable_search() (see e.g. callers of find_domain_struct()).
Somewhere I need to cast the const away. I could do so in hashtable_search()
in case you prefer me to do so.
Juergen
Attachment:
OpenPGP_0xB0DE9DD628BF132F.asc
Description: OpenPGP public key
Attachment:
OpenPGP_signature
Description: OpenPGP digital signature
|