From 6ce80fd80355d29b3ed8c2fa14251a9b8276a86a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 6 Aug 2018 08:53:27 +0200 Subject: qobject: Replace qobject_from_jsonf() by qobject_from_jsonf_nofail() Commit ab45015a968 "qobject: Let qobject_from_jsonf() fail instead of abort" fails to accomplish its stated aim: the function can still abort due to its use of &error_abort. Its rationale for letting it fail is that all remaining users cope fine with failure. Well, they're just fine with aborting, too; it's what they do on failure. Simply reverting the broken commit would bring back the unfortunate asymmetry between qobject_from_jsonf() and qobject_from_jsonv(): one aborts, the other returns null. So also rename it to qobject_from_jsonf_nofail(). Signed-off-by: Markus Armbruster Reviewed-by: Thomas Huth Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-7-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index 43b2ce2f33..dc509d51ae 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -15,11 +15,13 @@ #define QJSON_H QObject *qobject_from_json(const char *string, Error **errp); -QObject *qobject_from_jsonf(const char *string, ...) GCC_FMT_ATTR(1, 2); QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) GCC_FMT_ATTR(1, 0); -QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); +QObject *qobject_from_jsonf_nofail(const char *string, ...) + GCC_FMT_ATTR(1, 2); +QDict *qdict_from_jsonf_nofail(const char *string, ...) + GCC_FMT_ATTR(1, 2); QString *qobject_to_json(const QObject *obj); QString *qobject_to_json_pretty(const QObject *obj); -- cgit v1.2.3 From 4ff184689bf3d22b01c0d00c2bf6bf9595ff9b48 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 6 Aug 2018 08:53:28 +0200 Subject: qobject: New qobject_from_vjsonf_nofail(), qdict_from_vjsonf_nofail() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every printf()-like function sooner or later needs its vprintf()-like buddy. The next commit will need qobject_from_jsonf_nofail()'s buddy, and qdict_from_jsonf_nofail()'s buddy will be used later in this series. Add both. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-8-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index dc509d51ae..dce78583dc 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -18,8 +18,12 @@ QObject *qobject_from_json(const char *string, Error **errp); QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) GCC_FMT_ATTR(1, 0); +QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap) + GCC_FMT_ATTR(1, 0); QObject *qobject_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); +QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap) + GCC_FMT_ATTR(1, 0); QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2); -- cgit v1.2.3 From 2d36e843042d2ef47f3bfc47a1a83401fdb07b84 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 6 Aug 2018 08:53:31 +0200 Subject: qobject: qobject_from_jsonv() is dangerous, hide it away MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qobject_from_jsonv() takes ownership of %p arguments. On failure, we can't generally know whether we failed before or after %p, so ownership becomes indeterminate. To avoid leaks, callers passing %p must terminate on error, e.g. by passing &error_abort. Trap for the unwary; document and give the function internal linkage. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Eric Blake Message-Id: <20180806065344.7103-11-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index dce78583dc..5ebbe5a118 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -15,8 +15,6 @@ #define QJSON_H QObject *qobject_from_json(const char *string, Error **errp); -QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) - GCC_FMT_ATTR(1, 0); QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap) GCC_FMT_ATTR(1, 0); -- cgit v1.2.3