diff mbox series

[11/19] qapi: Reject blank 'if' conditions in addition to empty ones

Message ID 20190914153506.2151-12-armbru@redhat.com
State New
Headers show
Series qapi: Frontend fixes and cleanups | expand

Commit Message

Markus Armbruster Sept. 14, 2019, 3:34 p.m. UTC
"'if': 'COND'" generates "#if COND".  We reject empty COND because it
won't compile.  Blank COND won't compile any better, so reject that,
too.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/common.py             | 5 +++--
 tests/qapi-schema/bad-if-list.err  | 2 +-
 tests/qapi-schema/bad-if-list.json | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

Comments

Eric Blake Sept. 17, 2019, 6:06 p.m. UTC | #1
On 9/14/19 10:34 AM, Markus Armbruster wrote:
> "'if': 'COND'" generates "#if COND".  We reject empty COND because it
> won't compile.  Blank COND won't compile any better, so reject that,
> too.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox series

Patch

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index a58e904978..2b46164854 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -742,8 +742,9 @@  def check_if(expr, info):
         if not isinstance(ifcond, str):
             raise QAPISemError(
                 info, "'if' condition must be a string or a list of strings")
-        if ifcond == '':
-            raise QAPISemError(info, "'if' condition '' makes no sense")
+        if ifcond.strip() == '':
+            raise QAPISemError(info, "'if' condition '%s' makes no sense"
+                               % ifcond)
 
     ifcond = expr.get('if')
     if ifcond is None:
diff --git a/tests/qapi-schema/bad-if-list.err b/tests/qapi-schema/bad-if-list.err
index 0af6316f78..53af099083 100644
--- a/tests/qapi-schema/bad-if-list.err
+++ b/tests/qapi-schema/bad-if-list.err
@@ -1 +1 @@ 
-tests/qapi-schema/bad-if-list.json:2: 'if' condition '' makes no sense
+tests/qapi-schema/bad-if-list.json:2: 'if' condition ' ' makes no sense
diff --git a/tests/qapi-schema/bad-if-list.json b/tests/qapi-schema/bad-if-list.json
index 49ced9b9ca..ea3d95bb6b 100644
--- a/tests/qapi-schema/bad-if-list.json
+++ b/tests/qapi-schema/bad-if-list.json
@@ -1,3 +1,3 @@ 
 # check invalid 'if' content
 { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' },
-  'if': ['foo', ''] }
+  'if': ['foo', ' '] }