]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commit
maint: avoid 'const fooPtr' in hashes
authorEric Blake <eblake@redhat.com>
Sat, 5 Oct 2013 02:30:35 +0000 (20:30 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 14 Oct 2013 17:40:24 +0000 (11:40 -0600)
commitb43efdaa1315b5dc078a302df651829314dd0e7b
tree8209d5b7e3e26692042f13b10d080fba568645ce
parenta5da54236005b92877a4787423a8c0e1c04f9e0c
maint: avoid 'const fooPtr' in hashes

'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can).  But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).

Fix up virhash to provide a const-correct interface: all actions
that don't modify the table take a const table.  Note that in
one case (virHashSearch), we actually strip const away - we aren't
modifying the contents of the table, so much as associated data
for ensuring that the code uses the table correctly (if this were
C++, it would be a case for the 'mutable' keyword).

* src/util/virhash.h (virHashKeyComparator, virHashEqual): Use
intended type.
(virHashSize, virHashTableSize, virHashLookup, virHashSearch):
Make const-correct.
* src/util/virhash.c (virHashEqualData, virHashEqual)
(virHashLookup, virHashSize, virHashTableSize, virHashSearch)
(virHashComputeKey): Fix fallout.
* src/conf/nwfilter_params.c
(virNWFilterFormatParameterNameSorter): Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesFilterOrderSort): Likewise.
* tests/virhashtest.c (testHashGetItemsCompKey)
(testHashGetItemsCompValue): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/conf/nwfilter_params.c
src/nwfilter/nwfilter_ebiptables_driver.c
src/util/virhash.c
src/util/virhash.h
tests/virhashtest.c