From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsOva-0006K7-Gh for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsOvX-0006iI-E1 for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53670) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsOvX-0006hh-7m for qemu-devel@nongnu.org; Thu, 14 Sep 2017 03:51:11 -0400 From: Peter Xu Date: Thu, 14 Sep 2017 15:50:24 +0800 Message-Id: <1505375436-28439-4-git-send-email-peterx@redhat.com> In-Reply-To: <1505375436-28439-1-git-send-email-peterx@redhat.com> References: <1505375436-28439-1-git-send-email-peterx@redhat.com> Subject: [Qemu-devel] [RFC 03/15] qobject: introduce qobject_to_str() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , "Daniel P . Berrange" , Stefan Hajnoczi , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Eric Blake , Laurent Vivier , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , "Dr . David Alan Gilbert" A quick way to fetch string from qobject when it's a QString. Signed-off-by: Peter Xu --- 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