qapi: Remove null from schema language
authorMarkus Armbruster <armbru@redhat.com>
Sat, 14 Sep 2019 15:34:56 +0000 (17:34 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Tue, 24 Sep 2019 12:07:23 +0000 (14:07 +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 <armbru@redhat.com>
Message-Id: <20190914153506.2151-10-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
docs/devel/qapi-code-gen.txt
scripts/qapi/common.py
tests/qapi-schema/features-if-invalid.err
tests/qapi-schema/features-if-invalid.exit
tests/qapi-schema/features-if-invalid.json
tests/qapi-schema/features-if-invalid.out
tests/qapi-schema/pragma-name-case-whitelist-crap.json

index b12a5b4de810ed8d7ba3ac30c2da599f725a83b4..64d9e4c6a9f4765cd96d27690fc698c0b1b902bf 100644 (file)
@@ -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
index b3383b17efe715285dba0a40f2c41d82f1cc060c..ef7c7be4fdb417d2816a6e665fd508e3a5d13f6c 100644 (file)
@@ -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
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..295800b4fc02f940f5bb8b37a6912888d53546ff 100644 (file)
@@ -0,0 +1 @@
+tests/qapi-schema/features-if-invalid.json:2: 'if' condition must be a string or a list of strings
index 573541ac9702dd3969c9bc859d2b91ec1f7e6e56..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d 100644 (file)
@@ -1 +1 @@
-0
+1
index 7e4c1ad720ed120b8090276926580b68c57c9910..89c2a6c2342befda12febd5772f0f0d08afbe5cf 100644 (file)
@@ -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 }] }
index 9c2637baa39ea77d33d72f7d8518067841225fd0..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -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
index 58382bf4e4717169d82272b8f5798a52769e010e..734e1c617b431da85eb213d1b32e52f31828c999 100644 (file)
@@ -1,3 +1,3 @@
 # 'name-case-whitelist' must be list of strings
 
-{ 'pragma': { 'name-case-whitelist': null } }
+{ 'pragma': { 'name-case-whitelist': false } }