[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 01/14] qdict: Add qdict_change_key()
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v3 01/14] qdict: Add qdict_change_key() |
Date: |
Wed, 6 Apr 2016 20:28:37 +0200 |
This is a shorthand function for changing a QDict's entry's key.
Signed-off-by: Max Reitz <address@hidden>
---
include/qapi/qmp/qdict.h | 1 +
qobject/qdict.c | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index 8a3ac13..3e0d7df 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -39,6 +39,7 @@ size_t qdict_size(const QDict *qdict);
void qdict_put_obj(QDict *qdict, const char *key, QObject *value);
void qdict_del(QDict *qdict, const char *key);
int qdict_haskey(const QDict *qdict, const char *key);
+bool qdict_change_key(QDict *qdict, const char *old_key, const char *new_key);
QObject *qdict_get(const QDict *qdict, const char *key);
QDict *qobject_to_qdict(const QObject *obj);
void qdict_iter(const QDict *qdict,
diff --git a/qobject/qdict.c b/qobject/qdict.c
index ae6ad06..2eacb3d 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -170,6 +170,29 @@ int qdict_haskey(const QDict *qdict, const char *key)
}
/**
+ * qdict_change_key(): Changes an entry's key
+ *
+ * Removes the entry with the key 'old_key' and inserts its associated value as
+ * a new entry with the key 'new_key'.
+ *
+ * Returns false if 'old_key' does not exist, true otherwise.
+ */
+bool qdict_change_key(QDict *qdict, const char *old_key, const char *new_key)
+{
+ QObject *value = qdict_get(qdict, old_key);
+
+ if (!value) {
+ return false;
+ }
+
+ qobject_incref(value);
+ qdict_del(qdict, old_key);
+ qdict_put_obj(qdict, new_key, value);
+
+ return true;
+}
+
+/**
* qdict_size(): Return the size of the dictionary
*/
size_t qdict_size(const QDict *qdict)
--
2.8.0
- [Qemu-devel] [PATCH v3 for-2.7 00/14] qapi: Allow blockdev-add for NBD, Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 02/14] block/nbd: Drop trailing "." in error messages, Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 01/14] qdict: Add qdict_change_key(),
Max Reitz <=
- [Qemu-devel] [PATCH v3 03/14] block/nbd: Reject port parameter without host, Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 05/14] block/nbd: Use qdict_put(), Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 04/14] block/nbd: Default port in nbd_refresh_filename(), Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 06/14] block/nbd: Add nbd_has_filename_options_conflict(), Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 07/14] block/nbd: "address" in nbd_refresh_filename(), Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 09/14] block/nbd: Use SocketAddress options, Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 08/14] block/nbd: Accept SocketAddress, Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 10/14] qapi: Allow blockdev-add for NBD, Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 11/14] iotests.py: Add qemu_nbd function, Max Reitz, 2016/04/06
- [Qemu-devel] [PATCH v3 12/14] iotests.py: Allow concurrent qemu instances, Max Reitz, 2016/04/06