From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6LYj-00011E-IS for qemu-devel@nongnu.org; Thu, 23 Jan 2014 09:47:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6LYc-0002vU-B0 for qemu-devel@nongnu.org; Thu, 23 Jan 2014 09:47:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44495) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6LYc-0002vK-2w for qemu-devel@nongnu.org; Thu, 23 Jan 2014 09:47:02 -0500 From: Amos Kong Date: Thu, 23 Jan 2014 22:46:34 +0800 Message-Id: <1390488396-16538-4-git-send-email-akong@redhat.com> In-Reply-To: <1390488396-16538-1-git-send-email-akong@redhat.com> References: <1390488396-16538-1-git-send-email-akong@redhat.com> Subject: [Qemu-devel] [PATCH v4 3/5] qobject: introduce qobject_get_str() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qiaonuohan@cn.fujitsu.com, lcapitulino@redhat.com, mdroth@linux.vnet.ibm.com, xiawenc@linux.vnet.ibm.com Signed-off-by: Amos Kong --- include/qapi/qmp/qstring.h | 1 + qobject/qstring.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h index 1bc3666..56b17cb 100644 --- a/include/qapi/qmp/qstring.h +++ b/include/qapi/qmp/qstring.h @@ -28,6 +28,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 *obj); 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 607b7a1..c470a86 100644 --- a/qobject/qstring.c +++ b/qobject/qstring.c @@ -135,6 +135,25 @@ const char *qstring_get_str(const QString *qstring) } /** + * qobject_to_str(): Convert a QObject to QString and return + * a pointer to the stored string + */ +const char *qobject_get_str(const QObject *data) +{ + QString *qstr; + + if (!data) { + return NULL; + } + qstr = qobject_to_qstring(data); + if (qstr) { + return qstring_get_str(qstr); + } else { + return NULL; + } +} + +/** * qstring_destroy_obj(): Free all memory allocated by a QString * object */ -- 1.8.4.2