{"id":812314,"url":"http://patchwork.ozlabs.org/api/patches/812314/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911110623.24981-2-marcandre.lureau@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170911110623.24981-2-marcandre.lureau@redhat.com>","list_archive_url":null,"date":"2017-09-11T11:05:34","name":"[v3,01/50] qlit: add qobject_from_qlit()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2ea0bd33f0ef4224e747d35e8d2c6314bb3e4785","submitter":{"id":66774,"url":"http://patchwork.ozlabs.org/api/people/66774/?format=json","name":"Marc-André Lureau","email":"marcandre.lureau@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911110623.24981-2-marcandre.lureau@redhat.com/mbox/","series":[{"id":2480,"url":"http://patchwork.ozlabs.org/api/series/2480/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2480","date":"2017-09-11T11:05:33","name":"Hi,","version":3,"mbox":"http://patchwork.ozlabs.org/series/2480/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/812314/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/812314/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=marcandre.lureau@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xrQFC52bGz9s7G\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 21:10:06 +1000 (AEST)","from localhost ([::1]:56746 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drMbL-0007N7-GS\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 07:10:03 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:42542)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <marcandre.lureau@redhat.com>) id 1drMXz-0004kM-TU\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:06:41 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <marcandre.lureau@redhat.com>) id 1drMXv-0005xV-UK\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:06:35 -0400","from mx1.redhat.com ([209.132.183.28]:59436)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <marcandre.lureau@redhat.com>)\n\tid 1drMXv-0005wX-Mo\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:06:31 -0400","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id D70C033B417\n\tfor <qemu-devel@nongnu.org>; Mon, 11 Sep 2017 11:06:30 +0000 (UTC)","from localhost (ovpn-112-47.ams2.redhat.com [10.36.112.47])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 5C7216EC83;\n\tMon, 11 Sep 2017 11:06:28 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com D70C033B417","From":"=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Mon, 11 Sep 2017 13:05:34 +0200","Message-Id":"<20170911110623.24981-2-marcandre.lureau@redhat.com>","In-Reply-To":"<20170911110623.24981-1-marcandre.lureau@redhat.com>","References":"<20170911110623.24981-1-marcandre.lureau@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.30]);\n\tMon, 11 Sep 2017 11:06:30 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PATCH v3 01/50] qlit: add qobject_from_qlit()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>,\n\tarmbru@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Instanciate a QObject* form a literal QLitObject.\n\nSigned-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>\n---\n include/qapi/qmp/qlit.h |  2 ++\n qobject/qlit.c          | 36 ++++++++++++++++++++++++++++++++++++\n tests/check-qlit.c      | 26 ++++++++++++++++++++++++++\n 3 files changed, 64 insertions(+)","diff":"diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h\nindex b18406bce9..56feb25e04 100644\n--- a/include/qapi/qmp/qlit.h\n+++ b/include/qapi/qmp/qlit.h\n@@ -51,4 +51,6 @@ struct QLitDictEntry {\n \n bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);\n \n+QObject *qobject_from_qlit(const QLitObject *qlit);\n+\n #endif /* QLIT_H */\ndiff --git a/qobject/qlit.c b/qobject/qlit.c\nindex 3c4882c784..df2ad97d33 100644\n--- a/qobject/qlit.c\n+++ b/qobject/qlit.c\n@@ -82,3 +82,39 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)\n \n     return false;\n }\n+\n+QObject *qobject_from_qlit(const QLitObject *qlit)\n+{\n+    switch (qlit->type) {\n+    case QTYPE_QNULL:\n+        return QOBJECT(qnull());\n+    case QTYPE_QNUM:\n+        return QOBJECT(qnum_from_int(qlit->value.qnum));\n+    case QTYPE_QSTRING:\n+        return QOBJECT(qstring_from_str(qlit->value.qstr));\n+    case QTYPE_QDICT: {\n+        QDict *qdict = qdict_new();\n+        QLitDictEntry *e;\n+\n+        for (e = qlit->value.qdict; e->key; e++) {\n+            qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value));\n+        }\n+        return QOBJECT(qdict);\n+    }\n+    case QTYPE_QLIST: {\n+        QList *qlist = qlist_new();\n+        QLitObject *e;\n+\n+        for (e = qlit->value.qlist; e->type != QTYPE_NONE; e++) {\n+            qlist_append_obj(qlist, qobject_from_qlit(e));\n+        }\n+        return QOBJECT(qlist);\n+    }\n+    case QTYPE_QBOOL:\n+        return QOBJECT(qbool_from_bool(qlit->value.qbool));\n+    case QTYPE_NONE:\n+        assert(0);\n+    }\n+\n+    return NULL;\n+}\ndiff --git a/tests/check-qlit.c b/tests/check-qlit.c\nindex c59ec1ab88..acd6e02e96 100644\n--- a/tests/check-qlit.c\n+++ b/tests/check-qlit.c\n@@ -64,11 +64,37 @@ static void qlit_equal_qobject_test(void)\n     qobject_decref(qobj);\n }\n \n+static void qobject_from_qlit_test(void)\n+{\n+    QObject *obj, *qobj = qobject_from_qlit(&qlit);\n+    QDict *qdict;\n+    QList *bee;\n+\n+    qdict = qobject_to_qdict(qobj);\n+    g_assert_cmpint(qdict_get_int(qdict, \"foo\"), ==, 42);\n+    g_assert_cmpstr(qdict_get_str(qdict, \"bar\"), ==, \"hello world\");\n+    g_assert(qobject_type(qdict_get(qdict, \"baz\")) == QTYPE_QNULL);\n+\n+    bee = qdict_get_qlist(qdict, \"bee\");\n+    obj = qlist_pop(bee);\n+    g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), ==, 43);\n+    qobject_decref(obj);\n+    obj = qlist_pop(bee);\n+    g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), ==, 44);\n+    qobject_decref(obj);\n+    obj = qlist_pop(bee);\n+    g_assert(qbool_get_bool(qobject_to_qbool(obj)));\n+    qobject_decref(obj);\n+\n+    qobject_decref(qobj);\n+}\n+\n int main(int argc, char **argv)\n {\n     g_test_init(&argc, &argv, NULL);\n \n     g_test_add_func(\"/qlit/equal_qobject\", qlit_equal_qobject_test);\n+    g_test_add_func(\"/qlit/qobject_from_qlit\", qobject_from_qlit_test);\n \n     return g_test_run();\n }\n","prefixes":["v3","01/50"]}