|
[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
Hi Juergen, On 26/07/2023 07:19, Juergen Gross wrote: 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... My problem is not with the placement of the const but the fact you are removing the const. I agree that the hashtable code is not meant to modify the content. However, as you wrote, the caller of hashtable_search() could modify the content. So, for me, the value should not be const in the hashtable code. To give a concrete example, with the current interface we are telling the user that what they store in the hashtable can be modified at some point. By adding 'const' for the value in hashtable_add(), we can mislead a user to think it is fine to store static string, yet this is not enforced all the way through. So one could mistakenly think that values returned hashtable_search() can be modified. And the compiler will not be here to help enforcing it because you cast-away the const. Do you have any code in this series that requires the 'const' in hashtable_add()? If so, can you point me to the patch and I will have a look? If not, then I will strongly argue that this should be dropped because dropping a const is always a recipe for disaster. Cheers, -- Julien Grall
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |