@@ -1,6 +1,6 @@
#######################################################################
# QObject
-qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
+qobject-obj-y = qint.o qstring.o qdict.o qemu-misc.o qlist.o qfloat.o qbool.o
qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
qobject-obj-y += qerror.o
@@ -53,22 +53,6 @@ QDict *qobject_to_qdict(const QObject *obj)
}
/**
- * tdb_hash(): based on the hash agorithm from gdbm, via tdb
- * (from module-init-tools)
- */
-static unsigned int tdb_hash(const char *name)
-{
- unsigned value; /* Used to compute the hash value. */
- unsigned i; /* Used to cycle through random values. */
-
- /* Set the initial value from the key size. */
- for (value = 0x238F13AF * strlen(name), i=0; name[i]; i++)
- value = (value + (((const unsigned char *)name)[i] << (i*5 % 24)));
-
- return (1103515243 * value + 12345);
-}
-
-/**
* alloc_entry(): allocate a new QDictEntry
*/
static QDictEntry *alloc_entry(const char *key, QObject *value)
@@ -113,7 +97,7 @@ void qdict_put_obj(QDict *qdict, const char *key, QObject *value)
unsigned int hash;
QDictEntry *entry;
- hash = tdb_hash(key) % QDICT_HASH_SIZE;
+ hash = qemu_hash(key) % QDICT_HASH_SIZE;
entry = qdict_find(qdict, key, hash);
if (entry) {
/* replace key's value */
@@ -137,7 +121,7 @@ QObject *qdict_get(const QDict *qdict, const char *key)
{
QDictEntry *entry;
- entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_HASH_SIZE);
+ entry = qdict_find(qdict, key, qemu_hash(key) % QDICT_HASH_SIZE);
return (entry == NULL ? NULL : entry->value);
}
@@ -148,7 +132,7 @@ QObject *qdict_get(const QDict *qdict, const char *key)
*/
int qdict_haskey(const QDict *qdict, const char *key)
{
- unsigned int hash = tdb_hash(key) % QDICT_HASH_SIZE;
+ unsigned int hash = qemu_hash(key) % QDICT_HASH_SIZE;
return (qdict_find(qdict, key, hash) == NULL ? 0 : 1);
}
@@ -347,7 +331,7 @@ void qdict_del(QDict *qdict, const char *key)
{
QDictEntry *entry;
- entry = qdict_find(qdict, key, tdb_hash(key) % QDICT_HASH_SIZE);
+ entry = qdict_find(qdict, key, qemu_hash(key) % QDICT_HASH_SIZE);
if (entry) {
QLIST_REMOVE(entry, next);
qentry_destroy(entry);
@@ -17,6 +17,9 @@ typedef struct QEMUTimer QEMUTimer;
typedef struct QEMUFile QEMUFile;
typedef struct QEMUBH QEMUBH;
+/* Hash function definition */
+unsigned int qemu_hash(const char *name);
+
/* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that
cannot include the following headers without conflicts. This condition has
to be removed once dyngen is gone. */
new file mode 100644
@@ -0,0 +1,24 @@
+/*
+ * Definition of tdb_hash() moved here, from qdict.c. Renamed to qemu_hash()
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+#include "qemu-common.h"
+
+/**
+ * tdb_hash(): based on the hash agorithm from gdbm, via tdb
+ * (from module-init-tools). Renamed to qemu_hash().
+ */
+unsigned int qemu_hash(const char *name)
+{
+ unsigned value; /* Used to compute the hash value. */
+ unsigned i; /* Used to cycle through random values. */
+
+ /* Set the initial value from the key size. */
+ for (value = 0x238F13AF * strlen(name), i=0; name[i]; i++)
+ value = (value + (((const unsigned char *)name)[i] << (i*5 % 24)));
+
+ return (1103515243 * value + 12345);
+}