From: "Daniel P. Berrange" <berrange(a)redhat.com>
In preparation for conversion over to use the Murmurhash3
algorithm, convert various virHash APIs to use size_t or
uint32 for their return values/parameters, instead of the
variable size 'unsigned long' or 'int' types
---
src/util/cgroup.c | 4 +-
src/util/hash.c | 56 +++++++++++++++++++++++++++-------------------------
src/util/hash.h | 14 ++++++------
3 files changed, 38 insertions(+), 36 deletions(-)
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 25f2691..a270965 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -1636,9 +1636,9 @@ cleanup:
}
-static unsigned long virCgroupPidCode(const void *name)
+static uint32_t virCgroupPidCode(const void *name)
{
- return (unsigned long)name;
+ return (uint32_t)(int64_t)name;
}
static bool virCgroupPidEqual(const void *namea, const void *nameb)
{
diff --git a/src/util/hash.c b/src/util/hash.c
index ff86f16..20d3a12 100644
--- a/src/util/hash.c
+++ b/src/util/hash.c
@@ -57,8 +57,8 @@ struct _virHashEntry {
*/
struct _virHashTable {
virHashEntryPtr *table;
- int size;
- int nbElems;
+ size_t size;
+ size_t nbElems;
/* True iff we are iterating over hash entries. */
bool iterating;
/* Pointer to the current entry during iteration. */
@@ -70,17 +70,17 @@ struct _virHashTable {
virHashKeyFree keyFree;
};
-static unsigned long virHashStrCode(const void *name)
+static uint32_t virHashStrCode(const void *name)
{
const char *str = name;
- unsigned long value = 0L;
+ uint32_t value = 0L;
char ch;
if (str != NULL) {
value += 30 * (*str);
while ((ch = *str++) != 0) {
value =
- value ^ ((value << 5) + (value >> 3) + (unsigned long) ch);
+ value ^ ((value << 5) + (value >> 3) + (uint32_t) ch);
}
}
return value;
@@ -102,10 +102,10 @@ static void virHashStrFree(void *name)
}
-static unsigned long
+static size_t
virHashComputeKey(virHashTablePtr table, const void *name)
{
- unsigned long value = table->keyCode(name);
+ uint32_t value = table->keyCode(name);
return (value % table->size);
}
@@ -122,7 +122,7 @@ virHashComputeKey(virHashTablePtr table, const void *name)
*
* Returns the newly created object, or NULL if an error occurred.
*/
-virHashTablePtr virHashCreateFull(int size,
+virHashTablePtr virHashCreateFull(ssize_t size,
virHashDataFree dataFree,
virHashKeyCode keyCode,
virHashKeyEqual keyEqual,
@@ -166,7 +166,7 @@ virHashTablePtr virHashCreateFull(int size,
*
* Returns the newly created object, or NULL if an error occurred.
*/
-virHashTablePtr virHashCreate(int size, virHashDataFree dataFree)
+virHashTablePtr virHashCreate(ssize_t size, virHashDataFree dataFree)
{
return virHashCreateFull(size,
dataFree,
@@ -186,13 +186,13 @@ virHashTablePtr virHashCreate(int size, virHashDataFree dataFree)
* Returns 0 in case of success, -1 in case of failure
*/
static int
-virHashGrow(virHashTablePtr table, int size)
+virHashGrow(virHashTablePtr table, size_t size)
{
- int oldsize, i;
+ size_t oldsize, i;
virHashEntryPtr *oldtable;
#ifdef DEBUG_GROW
- unsigned long nbElem = 0;
+ size_t nbElem = 0;
#endif
if (table == NULL)
@@ -218,7 +218,7 @@ virHashGrow(virHashTablePtr table, int size)
virHashEntryPtr iter = oldtable[i];
while (iter) {
virHashEntryPtr next = iter->next;
- unsigned long key = virHashComputeKey(table, iter->name);
+ size_t key = virHashComputeKey(table, iter->name);
iter->next = table->table[key];
table->table[key] = iter;
@@ -250,7 +250,7 @@ virHashGrow(virHashTablePtr table, int size)
void
virHashFree(virHashTablePtr table)
{
- int i;
+ size_t i;
if (table == NULL)
return;
@@ -278,7 +278,7 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name,
void *userdata,
bool is_update)
{
- unsigned long key, len = 0;
+ size_t key, len = 0;
virHashEntryPtr entry;
char *new_name;
@@ -372,7 +372,7 @@ virHashUpdateEntry(virHashTablePtr table, const void *name,
void *
virHashLookup(virHashTablePtr table, const void *name)
{
- unsigned long key;
+ size_t key;
virHashEntryPtr entry;
if (!table || !name)
@@ -419,7 +419,7 @@ void *virHashSteal(virHashTablePtr table, const void *name)
* Returns the number of elements in the hash table or
* -1 in case of error
*/
-int
+ssize_t
virHashSize(virHashTablePtr table)
{
if (table == NULL)
@@ -436,7 +436,7 @@ virHashSize(virHashTablePtr table)
* Returns the number of keys in the hash table or
* -1 in case of error
*/
-int
+ssize_t
virHashTableSize(virHashTablePtr table)
{
if (table == NULL)
@@ -499,9 +499,10 @@ virHashRemoveEntry(virHashTablePtr table, const void *name)
*
* Returns number of items iterated over upon completion, -1 on failure
*/
-int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data)
+ssize_t
+virHashForEach(virHashTablePtr table, virHashIterator iter, void *data)
{
- int i, count = 0;
+ size_t i, count = 0;
if (table == NULL || iter == NULL)
return (-1);
@@ -542,11 +543,12 @@ int virHashForEach(virHashTablePtr table, virHashIterator iter, void
*data)
*
* Returns number of items removed on success, -1 on failure
*/
-int virHashRemoveSet(virHashTablePtr table,
- virHashSearcher iter,
- const void *data)
+ssize_t
+virHashRemoveSet(virHashTablePtr table,
+ virHashSearcher iter,
+ const void *data)
{
- int i, count = 0;
+ size_t i, count = 0;
if (table == NULL || iter == NULL)
return (-1);
@@ -595,7 +597,7 @@ void *virHashSearch(virHashTablePtr table,
virHashSearcher iter,
const void *data)
{
- int i;
+ size_t i;
if (table == NULL || iter == NULL)
return (NULL);
@@ -622,7 +624,7 @@ void *virHashSearch(virHashTablePtr table,
struct getKeysIter
{
virHashKeyValuePair *sortArray;
- unsigned arrayIdx;
+ size_t arrayIdx;
};
static void virHashGetKeysIterator(void *payload,
@@ -641,7 +643,7 @@ typedef int (*qsort_comp)(const void *, const void *);
virHashKeyValuePairPtr virHashGetItems(virHashTablePtr table,
virHashKeyComparator compar)
{
- int numElems = virHashSize(table);
+ ssize_t numElems = virHashSize(table);
struct getKeysIter iter = {
.arrayIdx = 0,
.sortArray = NULL,
diff --git a/src/util/hash.h b/src/util/hash.h
index 9da2da5..2420045 100644
--- a/src/util/hash.h
+++ b/src/util/hash.h
@@ -60,7 +60,7 @@ typedef int (*virHashSearcher) (const void *payload, const void *name,
*
* Returns the hash code
*/
-typedef unsigned long (*virHashKeyCode)(const void *name);
+typedef uint32_t (*virHashKeyCode)(const void *name);
/**
* virHashKeyEqual:
* @namea: the first hash key
@@ -93,17 +93,17 @@ typedef void (*virHashKeyFree)(void *name);
/*
* Constructor and destructor.
*/
-virHashTablePtr virHashCreate(int size,
+virHashTablePtr virHashCreate(ssize_t size,
virHashDataFree dataFree);
-virHashTablePtr virHashCreateFull(int size,
+virHashTablePtr virHashCreateFull(ssize_t size,
virHashDataFree dataFree,
virHashKeyCode keyCode,
virHashKeyEqual keyEqual,
virHashKeyCopy keyCopy,
virHashKeyFree keyFree);
void virHashFree(virHashTablePtr table);
-int virHashSize(virHashTablePtr table);
-int virHashTableSize(virHashTablePtr table);
+ssize_t virHashSize(virHashTablePtr table);
+ssize_t virHashTableSize(virHashTablePtr table);
/*
* Add a new entry to the hash table.
@@ -168,8 +168,8 @@ bool virHashEqual(const virHashTablePtr table1,
/*
* Iterators
*/
-int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data);
-int virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, const void *data);
+ssize_t virHashForEach(virHashTablePtr table, virHashIterator iter, void *data);
+ssize_t virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, const void *data);
void *virHashSearch(virHashTablePtr table, virHashSearcher iter, const void *data);
#endif /* ! __VIR_HASH_H__ */
--
1.7.7.5