Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/812342/?format=api
{ "id": 812342, "url": "http://patchwork.ozlabs.org/api/patches/812342/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911110623.24981-20-marcandre.lureau@redhat.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "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-20-marcandre.lureau@redhat.com>", "list_archive_url": null, "date": "2017-09-11T11:05:52", "name": "[v3,19/50] qapi: add 'if' to enum members", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "5c55d72de04f02abce87bd7cd3d2725d384e633f", "submitter": { "id": 66774, "url": "http://patchwork.ozlabs.org/api/people/66774/?format=api", "name": "Marc-André Lureau", "email": "marcandre.lureau@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170911110623.24981-20-marcandre.lureau@redhat.com/mbox/", "series": [ { "id": 2480, "url": "http://patchwork.ozlabs.org/api/series/2480/?format=api", "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/812342/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/812342/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-mx03.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com", "ext-mx03.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 3xrQdd2gCCz9sBd\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 11 Sep 2017 21:27:49 +1000 (AEST)", "from localhost ([::1]:56831 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 1drMsV-0006dO-8V\n\tfor incoming@patchwork.ozlabs.org; Mon, 11 Sep 2017 07:27:47 -0400", "from eggs.gnu.org ([2001:4830:134:3::10]:43052)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <marcandre.lureau@redhat.com>) id 1drMYi-0005a6-OQ\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:07:22 -0400", "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <marcandre.lureau@redhat.com>) id 1drMYg-0006TY-Vu\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:07:20 -0400", "from mx1.redhat.com ([209.132.183.28]:59358)\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 1drMYg-0006Ss-Ne\n\tfor qemu-devel@nongnu.org; Mon, 11 Sep 2017 07:07:18 -0400", "from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\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 D17A1D5BB0;\n\tMon, 11 Sep 2017 11:07:17 +0000 (UTC)", "from localhost (ovpn-112-47.ams2.redhat.com [10.36.112.47])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 676E060179;\n\tMon, 11 Sep 2017 11:07:17 +0000 (UTC)" ], "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com D17A1D5BB0", "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:52 +0200", "Message-Id": "<20170911110623.24981-20-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.11", "X-Greylist": "Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.27]);\n\tMon, 11 Sep 2017 11:07:17 +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 19/50] qapi: add 'if' to enum members", "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, Michael Roth <mdroth@linux.vnet.ibm.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": "Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>\n---\n scripts/qapi.py | 39 ++++++++++++++++++++++++++++-----\n tests/Makefile.include | 1 -\n tests/qapi-schema/enum-dict-member.err | 1 -\n tests/qapi-schema/enum-dict-member.exit | 1 -\n tests/qapi-schema/enum-dict-member.json | 2 --\n tests/qapi-schema/enum-dict-member.out | 0\n tests/qapi-schema/qapi-schema-test.json | 5 +++--\n tests/qapi-schema/qapi-schema-test.out | 3 ++-\n tests/qapi-schema/test-qapi.py | 2 ++\n 9 files changed, 41 insertions(+), 13 deletions(-)\n delete mode 100644 tests/qapi-schema/enum-dict-member.err\n delete mode 100644 tests/qapi-schema/enum-dict-member.exit\n delete mode 100644 tests/qapi-schema/enum-dict-member.json\n delete mode 100644 tests/qapi-schema/enum-dict-member.out", "diff": "diff --git a/scripts/qapi.py b/scripts/qapi.py\nindex 386a577a59..1535de9ce7 100644\n--- a/scripts/qapi.py\n+++ b/scripts/qapi.py\n@@ -659,6 +659,14 @@ def check_if(expr, info):\n info, \"'if' condition must be a string or a list of strings\")\n \n \n+def check_unknown_keys(info, dict, allowed_keys):\n+ diff = set(dict) - allowed_keys\n+ if not diff:\n+ return\n+ raise QAPISemError(info, \"Dictionnary has unknown keys: %s (allowed: %s)\" %\n+ (', '.join(diff), ', '.join(allowed_keys)))\n+\n+\n def check_type(info, source, value, allow_array=False,\n allow_dict=False, allow_optional=False,\n allow_metas=[]):\n@@ -739,6 +747,10 @@ def check_event(expr, info):\n allow_metas=meta)\n \n \n+def enum_get_values(expr):\n+ return [e if isinstance(e, str) else e['name'] for e in expr['data']]\n+\n+\n def check_union(expr, info):\n name = expr['union']\n base = expr.get('base')\n@@ -798,7 +810,7 @@ def check_union(expr, info):\n # If the discriminator names an enum type, then all members\n # of 'data' must also be members of the enum type.\n if enum_define:\n- if key not in enum_define['data']:\n+ if key not in enum_get_values(enum_define):\n raise QAPISemError(info,\n \"Discriminator value '%s' is not found in \"\n \"enum '%s'\"\n@@ -806,7 +818,7 @@ def check_union(expr, info):\n \n # If discriminator is user-defined, ensure all values are covered\n if enum_define:\n- for value in enum_define['data']:\n+ for value in enum_get_values(enum_define):\n if value not in members.keys():\n raise QAPISemError(info, \"Union '%s' data missing '%s' branch\"\n % (name, value))\n@@ -837,7 +849,7 @@ def check_alternate(expr, info):\n if qtype == 'QTYPE_QSTRING':\n enum_expr = enum_types.get(value)\n if enum_expr:\n- for v in enum_expr['data']:\n+ for v in enum_get_values(enum_expr):\n if v in ['on', 'off']:\n conflicting.add('QTYPE_QBOOL')\n if re.match(r'[-+0-9.]', v): # lazy, could be tightened\n@@ -865,6 +877,14 @@ def check_enum(expr, info):\n raise QAPISemError(info,\n \"Enum '%s' requires a string for 'prefix'\" % name)\n for member in members:\n+ if isinstance(member, dict):\n+ if 'name' not in member:\n+ raise QAPISemError(info, \"Dictionary member of enum '%s' must \"\n+ \"have a 'name' key\" % name)\n+ if 'if' in member:\n+ check_if(member, info)\n+ check_unknown_keys(info, member, {'name', 'if'})\n+ member = member['name']\n check_name(info, \"Member of enum '%s'\" % name, member,\n enum_member=True)\n \n@@ -1280,9 +1300,11 @@ class QAPISchemaObjectType(QAPISchemaType):\n class QAPISchemaMember(object):\n role = 'member'\n \n- def __init__(self, name):\n+ def __init__(self, name, ifcond=None):\n assert isinstance(name, str)\n+ assert ifcond is None or isinstance(ifcond, str)\n self.name = name\n+ self.ifcond = ifcond\n self.owner = None\n \n def set_owner(self, name):\n@@ -1559,7 +1581,14 @@ class QAPISchema(object):\n qtype_values, 'QTYPE'))\n \n def _make_enum_members(self, values):\n- return [QAPISchemaMember(v) for v in values]\n+ enum = []\n+ for v in values:\n+ ifcond = None\n+ if isinstance(v, dict):\n+ ifcond = v.get('if')\n+ v = v['name']\n+ enum.append(QAPISchemaMember(v, ifcond))\n+ return enum\n \n def _make_implicit_enum_type(self, name, info, ifcond, values):\n # See also QAPISchemaObjectTypeMember._pretty_owner()\ndiff --git a/tests/Makefile.include b/tests/Makefile.include\nindex 8dac7c9083..a9f0ddbe01 100644\n--- a/tests/Makefile.include\n+++ b/tests/Makefile.include\n@@ -443,7 +443,6 @@ qapi-schema += empty.json\n qapi-schema += enum-bad-name.json\n qapi-schema += enum-bad-prefix.json\n qapi-schema += enum-clash-member.json\n-qapi-schema += enum-dict-member.json\n qapi-schema += enum-int-member.json\n qapi-schema += enum-member-case.json\n qapi-schema += enum-missing-data.json\ndiff --git a/tests/qapi-schema/enum-dict-member.err b/tests/qapi-schema/enum-dict-member.err\ndeleted file mode 100644\nindex 8ca146ea59..0000000000\n--- a/tests/qapi-schema/enum-dict-member.err\n+++ /dev/null\n@@ -1 +0,0 @@\n-tests/qapi-schema/enum-dict-member.json:2: Member of enum 'MyEnum' requires a string name\ndiff --git a/tests/qapi-schema/enum-dict-member.exit b/tests/qapi-schema/enum-dict-member.exit\ndeleted file mode 100644\nindex d00491fd7e..0000000000\n--- a/tests/qapi-schema/enum-dict-member.exit\n+++ /dev/null\n@@ -1 +0,0 @@\n-1\ndiff --git a/tests/qapi-schema/enum-dict-member.json b/tests/qapi-schema/enum-dict-member.json\ndeleted file mode 100644\nindex 79672e0f09..0000000000\n--- a/tests/qapi-schema/enum-dict-member.json\n+++ /dev/null\n@@ -1,2 +0,0 @@\n-# we reject any enum member that is not a string\n-{ 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] }\ndiff --git a/tests/qapi-schema/enum-dict-member.out b/tests/qapi-schema/enum-dict-member.out\ndeleted file mode 100644\nindex e69de29bb2..0000000000\ndiff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json\nindex dc2c444fc1..ad2b405d83 100644\n--- a/tests/qapi-schema/qapi-schema-test.json\n+++ b/tests/qapi-schema/qapi-schema-test.json\n@@ -194,7 +194,8 @@\n { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' },\n 'if': 'defined(TEST_IF_STRUCT)' }\n \n-{ 'enum': 'TestIfEnum', 'data': [ 'foo', 'bar' ],\n+{ 'enum': 'TestIfEnum', 'data':\n+ [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],\n 'if': 'defined(TEST_IF_ENUM)' }\n \n { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' },\n@@ -203,7 +204,7 @@\n { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct' },\n 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }\n \n-{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct' },\n+{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': 'TestIfEnum' },\n 'if': 'defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)' }\n \n { 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' },\ndiff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out\nindex 9a7cafc269..8a0cf1a551 100644\n--- a/tests/qapi-schema/qapi-schema-test.out\n+++ b/tests/qapi-schema/qapi-schema-test.out\n@@ -74,7 +74,7 @@ command TestIfCmd q_obj_TestIfCmd-arg -> None\n if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)\n enum TestIfEnum\n member foo:\n- member bar:\n+ member bar: if=defined(TEST_IF_ENUM_BAR)\n if defined(TEST_IF_ENUM)\n event TestIfEvent q_obj_TestIfEvent-arg\n boxed=False\n@@ -228,6 +228,7 @@ object q_obj_EVENT_D-arg\n member enum3: EnumOne optional=True\n object q_obj_TestIfCmd-arg\n member foo: TestIfStruct optional=False\n+ member bar: TestIfEnum optional=False\n if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)\n object q_obj_TestIfEvent-arg\n member foo: TestIfStruct optional=False\ndiff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py\nindex 67c6c1ecef..a86c3b5ee1 100644\n--- a/tests/qapi-schema/test-qapi.py\n+++ b/tests/qapi-schema/test-qapi.py\n@@ -56,6 +56,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):\n print ' member %s:' % m.name,\n if isinstance(m, QAPISchemaObjectTypeMember):\n print '%s optional=%s' % (m.type.name, m.optional),\n+ if m.ifcond:\n+ print 'if=%s' % m.ifcond,\n print\n \n @staticmethod\n", "prefixes": [ "v3", "19/50" ] }