]> git.proxmox.com Git - qemu.git/blobdiff - qdict.c
pflash_cfi01: remove unused total_len field
[qemu.git] / qdict.c
diff --git a/qdict.c b/qdict.c
index a28a0a9f97fd7ff6f1546e1efa63cd4ea542aa1d..4bf308b61c6227961323d38b48542f0d24fee674 100644 (file)
--- a/qdict.c
+++ b/qdict.c
@@ -35,7 +35,7 @@ QDict *qdict_new(void)
 {
     QDict *qdict;
 
-    qdict = qemu_mallocz(sizeof(*qdict));
+    qdict = g_malloc0(sizeof(*qdict));
     QOBJECT_INIT(qdict, &qdict_type);
 
     return qdict;
@@ -75,8 +75,8 @@ static QDictEntry *alloc_entry(const char *key, QObject *value)
 {
     QDictEntry *entry;
 
-    entry = qemu_mallocz(sizeof(*entry));
-    entry->key = qemu_strdup(key);
+    entry = g_malloc0(sizeof(*entry));
+    entry->key = g_strdup(key);
     entry->value = value;
 
     return entry;
@@ -307,6 +307,24 @@ int64_t qdict_get_try_int(const QDict *qdict, const char *key,
     return qint_get_int(qobject_to_qint(obj));
 }
 
+/**
+ * qdict_get_try_bool(): Try to get a bool mapped by 'key'
+ *
+ * Return bool mapped by 'key', if it is not present in the
+ * dictionary or if the stored object is not of QBool type
+ * 'def_value' will be returned.
+ */
+int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value)
+{
+    QObject *obj;
+
+    obj = qdict_get(qdict, key);
+    if (!obj || qobject_type(obj) != QTYPE_QBOOL)
+        return def_value;
+
+    return qbool_get_int(qobject_to_qbool(obj));
+}
+
 /**
  * qdict_get_try_str(): Try to get a pointer to the stored string
  * mapped by 'key'
@@ -392,8 +410,8 @@ static void qentry_destroy(QDictEntry *e)
     assert(e->value != NULL);
 
     qobject_decref(e->value);
-    qemu_free(e->key);
-    qemu_free(e);
+    g_free(e->key);
+    g_free(e);
 }
 
 /**
@@ -434,5 +452,5 @@ static void qdict_destroy_obj(QObject *obj)
         }
     }
 
-    qemu_free(qdict);
+    g_free(qdict);
 }