[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v3 03/27] qobject: introduce qobject_get_try_str()
From: |
Peter Xu |
Subject: |
[Qemu-devel] [RFC v3 03/27] qobject: introduce qobject_get_try_str() |
Date: |
Mon, 6 Nov 2017 17:46:19 +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 34278bd639..12ae4e1c29 100644
--- a/include/qapi/qmp/qstring.h
+++ b/include/qapi/qmp/qstring.h
@@ -28,6 +28,7 @@ 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 *qstring_get_try_str(const QString *qstring);
+const char *qobject_get_try_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 9df04e3c7b..bbe689a9e3 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -139,6 +139,17 @@ const char *qstring_get_try_str(const QString *qstring)
}
/**
+ * qobject_get_try_str(): Return a pointer of the backstore string
+ *
+ * NOTE: the string will only be returned if the object is valid, and
+ * its type is QString, otherwise NULL is returned.
+ */
+const char *qobject_get_try_str(const QObject *qstring)
+{
+ return qstring_get_try_str(qobject_to_qstring(qstring));
+}
+
+/**
* qstring_destroy_obj(): Free all memory allocated by a QString
* object
*/
--
2.13.5
- [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, (continued)
- [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Peter Xu, 2017/11/06
- Re: [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Fam Zheng, 2017/11/07
- Re: [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Stefan Hajnoczi, 2017/11/13
- Re: [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Peter Xu, 2017/11/14
- Re: [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Stefan Hajnoczi, 2017/11/14
- Re: [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Peter Xu, 2017/11/14
- Re: [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Stefan Hajnoczi, 2017/11/15
- Re: [Qemu-devel] [RFC v3 01/27] char-io: fix possible race on IOWatchPoll, Peter Xu, 2017/11/15
[Qemu-devel] [RFC v3 02/27] qobject: introduce qstring_get_try_str(), Peter Xu, 2017/11/06
[Qemu-devel] [RFC v3 03/27] qobject: introduce qobject_get_try_str(),
Peter Xu <=
[Qemu-devel] [RFC v3 04/27] qobject: let object_property_get_str() use new API, Peter Xu, 2017/11/06
[Qemu-devel] [RFC v3 05/27] monitor: move skip_flush into monitor_data_init, Peter Xu, 2017/11/06
[Qemu-devel] [RFC v3 06/27] qjson: add "opaque" field to JSONMessageParser, Peter Xu, 2017/11/06
[Qemu-devel] [RFC v3 07/27] monitor: move the cur_mon hack deeper for QMP, Peter Xu, 2017/11/06
[Qemu-devel] [RFC v3 08/27] monitor: unify global init, Peter Xu, 2017/11/06