From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFJsJ-0007h8-3X for qemu-devel@nongnu.org; Thu, 16 Nov 2017 08:06:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFJsE-0005f9-VU for qemu-devel@nongnu.org; Thu, 16 Nov 2017 08:06:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37698) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eFJsE-0005bf-ON for qemu-devel@nongnu.org; Thu, 16 Nov 2017 08:06:30 -0500 From: Peter Xu Date: Thu, 16 Nov 2017 21:05:45 +0800 Message-Id: <20171116130610.23582-3-peterx@redhat.com> In-Reply-To: <20171116130610.23582-1-peterx@redhat.com> References: <20171116130610.23582-1-peterx@redhat.com> Subject: [Qemu-devel] [RFC v4 02/27] qobject: introduce qobject_get_try_str() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , "Daniel P . Berrange" , Paolo Bonzini , Fam Zheng , Juan Quintela , mdroth@linux.vnet.ibm.com, peterx@redhat.com, Eric Blake , Laurent Vivier , Markus Armbruster , marcandre.lureau@redhat.com, "Dr . David Alan Gilbert" A quick way to fetch string from qobject when it's a QString. Reviewed-by: Fam Zheng 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 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.6