9ae3a8
From 73cd8a69f21978e950706a633d9a25e10fe6ad2d Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <73cd8a69f21978e950706a633d9a25e10fe6ad2d.1387369730.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <091eecc4fa42754760dfff393dabcc2b444e9693.1387369730.git.minovotn@redhat.com>
9ae3a8
References: <091eecc4fa42754760dfff393dabcc2b444e9693.1387369730.git.minovotn@redhat.com>
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
Date: Tue, 10 Dec 2013 15:29:17 +0100
9ae3a8
Subject: [PATCH 17/21] qapi.py: Fix diagnosing non-objects at a schema's
9ae3a8
 top-level
9ae3a8
9ae3a8
RH-Author: Markus Armbruster <armbru@redhat.com>
9ae3a8
Message-id: <1386689361-30281-15-git-send-email-armbru@redhat.com>
9ae3a8
Patchwork-id: 56129
9ae3a8
O-Subject: [PATCH 7.0 qemu-kvm 14/18] qapi.py: Fix diagnosing non-objects at a schema's top-level
9ae3a8
Bugzilla: 997915
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
Report syntax error instead of crashing.
9ae3a8
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Message-id: 1374939721-7876-8-git-send-email-armbru@redhat.com
9ae3a8
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
(cherry picked from commit 5f3cd2b717c949f3afb502fb4c81193eb18ce6aa)
9ae3a8
---
9ae3a8
 scripts/qapi.py                               | 10 ++++++----
9ae3a8
 tests/qapi-schema/non-objects.err             |  2 +-
9ae3a8
 tests/qapi-schema/quoted-structural-chars.err |  2 +-
9ae3a8
 3 files changed, 8 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 scripts/qapi.py                               | 10 ++++++----
9ae3a8
 tests/qapi-schema/non-objects.err             |  2 +-
9ae3a8
 tests/qapi-schema/quoted-structural-chars.err |  2 +-
9ae3a8
 3 files changed, 8 insertions(+), 6 deletions(-)
9ae3a8
9ae3a8
diff --git a/scripts/qapi.py b/scripts/qapi.py
9ae3a8
index 12fb29a..75fc282 100644
9ae3a8
--- a/scripts/qapi.py
9ae3a8
+++ b/scripts/qapi.py
9ae3a8
@@ -64,7 +64,7 @@ class QAPISchema:
9ae3a8
         self.accept()
9ae3a8
 
9ae3a8
         while self.tok != None:
9ae3a8
-            self.exprs.append(self.get_expr())
9ae3a8
+            self.exprs.append(self.get_expr(False))
9ae3a8
 
9ae3a8
     def accept(self):
9ae3a8
         while True:
9ae3a8
@@ -117,7 +117,7 @@ class QAPISchema:
9ae3a8
             if self.tok != ':':
9ae3a8
                 raise QAPISchemaError(self, 'Expected ":"')
9ae3a8
             self.accept()
9ae3a8
-            expr[key] = self.get_expr()
9ae3a8
+            expr[key] = self.get_expr(True)
9ae3a8
             if self.tok == '}':
9ae3a8
                 self.accept()
9ae3a8
                 return expr
9ae3a8
@@ -135,7 +135,7 @@ class QAPISchema:
9ae3a8
         if not self.tok in [ '{', '[', "'" ]:
9ae3a8
             raise QAPISchemaError(self, 'Expected "{", "[", "]" or string')
9ae3a8
         while True:
9ae3a8
-            expr.append(self.get_expr())
9ae3a8
+            expr.append(self.get_expr(True))
9ae3a8
             if self.tok == ']':
9ae3a8
                 self.accept()
9ae3a8
                 return expr
9ae3a8
@@ -143,7 +143,9 @@ class QAPISchema:
9ae3a8
                 raise QAPISchemaError(self, 'Expected "," or "]"')
9ae3a8
             self.accept()
9ae3a8
 
9ae3a8
-    def get_expr(self):
9ae3a8
+    def get_expr(self, nested):
9ae3a8
+        if self.tok != '{' and not nested:
9ae3a8
+            raise QAPISchemaError(self, 'Expected "{"')
9ae3a8
         if self.tok == '{':
9ae3a8
             self.accept()
9ae3a8
             expr = self.get_members()
9ae3a8
diff --git a/tests/qapi-schema/non-objects.err b/tests/qapi-schema/non-objects.err
9ae3a8
index 48c849d..a6c2dc2 100644
9ae3a8
--- a/tests/qapi-schema/non-objects.err
9ae3a8
+++ b/tests/qapi-schema/non-objects.err
9ae3a8
@@ -1 +1 @@
9ae3a8
-Crashed: <type 'exceptions.AttributeError'>
9ae3a8
+<stdin>:1:1: Expected "{"
9ae3a8
diff --git a/tests/qapi-schema/quoted-structural-chars.err b/tests/qapi-schema/quoted-structural-chars.err
9ae3a8
index 48c849d..a6c2dc2 100644
9ae3a8
--- a/tests/qapi-schema/quoted-structural-chars.err
9ae3a8
+++ b/tests/qapi-schema/quoted-structural-chars.err
9ae3a8
@@ -1 +1 @@
9ae3a8
-Crashed: <type 'exceptions.AttributeError'>
9ae3a8
+<stdin>:1:1: Expected "{"
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8