qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PULL 27/37] qapi: Remove null from schema language


From: Markus Armbruster
Subject: [PULL 27/37] qapi: Remove null from schema language
Date: Tue, 24 Sep 2019 14:33:24 +0200

We represent the parse tree as OrderedDict.  We fetch optional dict
members with .get().  So far, so good.

We represent null literals as None.  .get() returns None both for
"absent" and for "present, value is the null literal".  Uh-oh.

Test features-if-invalid exposes this bug: "'if': null" is
misinterpreted as absent "if".

We added null to the schema language to "allow [...] an explicit
default value" (commit e53188ada5 "qapi: Allow true, false and null in
schema json", v2.4.0).  Hasn't happened; null is still unused except
as generic invalid value in tests/.

To fix, we'd have to replace .get() by something more careful, or
represent null differently.  Feasible, but we got more and bigger fish
to fry right now.  Remove the null literal from the schema language.
Replace null in tests by another invalid value.

Test features-if-invalid now behaves as it should.

Signed-off-by: Markus Armbruster <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
 docs/devel/qapi-code-gen.txt                       |  4 ++--
 scripts/qapi/common.py                             |  4 ----
 tests/qapi-schema/features-if-invalid.err          |  1 +
 tests/qapi-schema/features-if-invalid.exit         |  2 +-
 tests/qapi-schema/features-if-invalid.json         |  3 +--
 tests/qapi-schema/features-if-invalid.out          | 14 --------------
 .../pragma-name-case-whitelist-crap.json           |  2 +-
 7 files changed, 6 insertions(+), 24 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index b12a5b4de8..64d9e4c6a9 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -52,7 +52,7 @@ Differences:
 * Strings are restricted to printable ASCII, and escape sequences to
   just '\\'.
 
-* Numbers are not supported.
+* Numbers and null are not supported.
 
 A second layer of syntax defines the sequences of JSON texts that are
 a correctly structured QAPI schema.  We provide a grammar for this
@@ -67,7 +67,7 @@ syntax in an EBNF-like notation:
   expression A separated by ,
 * Grouping: expression ( A ) matches expression A
 * JSON's structural characters are terminals: { } [ ] : ,
-* JSON's literal names are terminals: false true null
+* JSON's literal names are terminals: false true
 * String literals enclosed in 'single quotes' are terminal, and match
   this JSON string, with a leading '*' stripped off
 * When JSON object member's name starts with '*', the member is
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index b3383b17ef..ef7c7be4fd 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -548,10 +548,6 @@ class QAPISchemaParser(object):
                 self.val = False
                 self.cursor += 4
                 return
-            elif self.src.startswith('null', self.pos):
-                self.val = None
-                self.cursor += 3
-                return
             elif self.tok == '\n':
                 if self.cursor == len(self.src):
                     self.tok = None
diff --git a/tests/qapi-schema/features-if-invalid.err 
b/tests/qapi-schema/features-if-invalid.err
index e69de29bb2..295800b4fc 100644
--- a/tests/qapi-schema/features-if-invalid.err
+++ b/tests/qapi-schema/features-if-invalid.err
@@ -0,0 +1 @@
+tests/qapi-schema/features-if-invalid.json:2: 'if' condition must be a string 
or a list of strings
diff --git a/tests/qapi-schema/features-if-invalid.exit 
b/tests/qapi-schema/features-if-invalid.exit
index 573541ac97..d00491fd7e 100644
--- a/tests/qapi-schema/features-if-invalid.exit
+++ b/tests/qapi-schema/features-if-invalid.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/features-if-invalid.json 
b/tests/qapi-schema/features-if-invalid.json
index 7e4c1ad720..89c2a6c234 100644
--- a/tests/qapi-schema/features-if-invalid.json
+++ b/tests/qapi-schema/features-if-invalid.json
@@ -1,5 +1,4 @@
 # Cover feature with invalid 'if'
-# FIXME not rejected, misinterpreted as unconditional
 { 'struct': 'Stru',
   'data': {},
-  'features': [{'name': 'f', 'if': null }] }
+  'features': [{'name': 'f', 'if': false }] }
diff --git a/tests/qapi-schema/features-if-invalid.out 
b/tests/qapi-schema/features-if-invalid.out
index 9c2637baa3..e69de29bb2 100644
--- a/tests/qapi-schema/features-if-invalid.out
+++ b/tests/qapi-schema/features-if-invalid.out
@@ -1,14 +0,0 @@
-module None
-object q_empty
-enum QType
-    prefix QTYPE
-    member none
-    member qnull
-    member qnum
-    member qstring
-    member qdict
-    member qlist
-    member qbool
-module features-if-invalid.json
-object Stru
-    feature f
diff --git a/tests/qapi-schema/pragma-name-case-whitelist-crap.json 
b/tests/qapi-schema/pragma-name-case-whitelist-crap.json
index 58382bf4e4..734e1c617b 100644
--- a/tests/qapi-schema/pragma-name-case-whitelist-crap.json
+++ b/tests/qapi-schema/pragma-name-case-whitelist-crap.json
@@ -1,3 +1,3 @@
 # 'name-case-whitelist' must be list of strings
 
-{ 'pragma': { 'name-case-whitelist': null } }
+{ 'pragma': { 'name-case-whitelist': false } }
-- 
2.21.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]