[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 03/15] qobject: introduce qobject_to_str()
From: |
Peter Xu |
Subject: |
[Qemu-devel] [RFC 03/15] qobject: introduce qobject_to_str() |
Date: |
Thu, 14 Sep 2017 15:50:24 +0800 |
A quick way to fetch string from qobject when it's a QString.
Signed-off-by: Peter Xu <address@hidden>
---
include/qapi/qmp/qstring.h | 1 +
qobject/qstring.c | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h
index 10076b7..bfdfa46 100644
--- a/include/qapi/qmp/qstring.h
+++ b/include/qapi/qmp/qstring.h
@@ -27,6 +27,7 @@ QString *qstring_from_str(const char *str);
QString *qstring_from_substr(const char *str, int start, int end);
size_t qstring_get_length(const QString *qstring);
const char *qstring_get_str(const QString *qstring);
+const char *qobject_get_str(const QObject *qstring);
void qstring_append_int(QString *qstring, int64_t value);
void qstring_append(QString *qstring, const char *str);
void qstring_append_chr(QString *qstring, int c);
diff --git a/qobject/qstring.c b/qobject/qstring.c
index c499fec..103efaf 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -129,6 +129,17 @@ const char *qstring_get_str(const QString *qstring)
}
/**
+ * qstring_get_str(): Return a pointer of the backstore string
+ *
+ * NOTE: the string will only be returned if the object is QString,
+ * otherwise NULL is returned.
+ */
+const char *qobject_get_str(const QObject *qstring)
+{
+ return qstring_get_str(qobject_to_qstring(qstring));
+}
+
+/**
* qstring_destroy_obj(): Free all memory allocated by a QString
* object
*/
--
2.7.4
- [Qemu-devel] [RFC 00/15] QMP: out-of-band (OOB) execution support, Peter Xu, 2017/09/14
- [Qemu-devel] [RFC 01/15] char-io: fix possible race on IOWatchPoll, Peter Xu, 2017/09/14
- [Qemu-devel] [RFC 02/15] qobject: allow NULL for qstring_get_str(), Peter Xu, 2017/09/14
- [Qemu-devel] [RFC 03/15] qobject: introduce qobject_to_str(),
Peter Xu <=
- [Qemu-devel] [RFC 04/15] monitor: move skip_flush into monitor_data_init, Peter Xu, 2017/09/14
- [Qemu-devel] [RFC 05/15] qjson: add "opaque" field to JSONMessageParser, Peter Xu, 2017/09/14
- [Qemu-devel] [RFC 06/15] monitor: move the cur_mon hack deeper for QMP, Peter Xu, 2017/09/14
- [Qemu-devel] [RFC 07/15] monitor: unify global init, Peter Xu, 2017/09/14