mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging
* remotes/qmp-unstable/queue/qmp: (38 commits) Revert "qapi: Clean up superfluous null check in qapi_dealloc_type_str()" qapi: Document optional arguments' backwards compatibility qmp: use valid JSON in transaction example qmp: Don't use error_is_set() to suppress additional errors dump: Drop pointless error_is_set(), DumpState member errp qemu-option: Clean up fragile use of error_is_set() qga: Drop superfluous error_is_set() qga: Clean up fragile use of error_is_set() qapi: Clean up fragile use of error_is_set() tests/qapi-schema: Drop superfluous error_is_set() qapi: Drop redundant, unclean error_is_set() hmp: Guard against misuse of hmp_handle_error() qga: Use return values instead of error_is_set(errp) error: Consistently name Error ** objects errp, and not err qmp: Consistently name Error ** objects errp, and not err qga: Consistently name Error ** objects errp, and not err qmp hmp: Consistently name Error * objects err, and not errp pci-assign: assigned_initfn(): set monitor error in common error handler pci-assign: propagate errors from assign_intx() pci-assign: propagate errors from assign_device() ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
06b4f00d53
95 changed files with 942 additions and 665 deletions
|
@ -369,9 +369,10 @@ def gen_command_def_prologue(prefix="", proxy=False):
|
|||
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:m",
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m",
|
||||
["source", "header", "prefix=",
|
||||
"output-dir=", "type=", "middle"])
|
||||
"input-file=", "output-dir=",
|
||||
"type=", "middle"])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
@ -389,6 +390,8 @@ do_h = False
|
|||
for o, a in opts:
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-t", "--type"):
|
||||
|
@ -420,7 +423,7 @@ except os.error, e:
|
|||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
exprs = parse_schema(sys.stdin)
|
||||
exprs = parse_schema(input_file)
|
||||
commands = filter(lambda expr: expr.has_key('command'), exprs)
|
||||
commands = filter(lambda expr: not expr.has_key('gen'), commands)
|
||||
|
||||
|
|
|
@ -279,14 +279,15 @@ void qapi_free_%(type)s(%(c_type)s obj)
|
|||
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
|
||||
["source", "header", "builtins",
|
||||
"prefix=", "output-dir="])
|
||||
"prefix=", "input-file=", "output-dir="])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
||||
output_dir = ""
|
||||
input_file = ""
|
||||
prefix = ""
|
||||
c_file = 'qapi-types.c'
|
||||
h_file = 'qapi-types.h'
|
||||
|
@ -298,6 +299,8 @@ do_builtins = False
|
|||
for o, a in opts:
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-c", "--source"):
|
||||
|
@ -378,7 +381,7 @@ fdecl.write(mcgen('''
|
|||
''',
|
||||
guard=guardname(h_file)))
|
||||
|
||||
exprs = parse_schema(sys.stdin)
|
||||
exprs = parse_schema(input_file)
|
||||
exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
|
||||
|
||||
fdecl.write(guardstart("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
|
||||
|
|
|
@ -397,13 +397,14 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **e
|
|||
name=name)
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
|
||||
["source", "header", "builtins", "prefix=",
|
||||
"output-dir="])
|
||||
"input-file=", "output-dir="])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
sys.exit(1)
|
||||
|
||||
input_file = ""
|
||||
output_dir = ""
|
||||
prefix = ""
|
||||
c_file = 'qapi-visit.c'
|
||||
|
@ -416,6 +417,8 @@ do_builtins = False
|
|||
for o, a in opts:
|
||||
if o in ("-p", "--prefix"):
|
||||
prefix = a
|
||||
elif o in ("-i", "--input-file"):
|
||||
input_file = a
|
||||
elif o in ("-o", "--output-dir"):
|
||||
output_dir = a + "/"
|
||||
elif o in ("-c", "--source"):
|
||||
|
@ -494,7 +497,7 @@ fdecl.write(mcgen('''
|
|||
''',
|
||||
prefix=prefix, guard=guardname(h_file)))
|
||||
|
||||
exprs = parse_schema(sys.stdin)
|
||||
exprs = parse_schema(input_file)
|
||||
|
||||
# to avoid header dependency hell, we always generate declarations
|
||||
# for built-in types in our header files and simply guard them
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
# This work is licensed under the terms of the GNU GPL, version 2.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import re
|
||||
from ordereddict import OrderedDict
|
||||
import os
|
||||
import sys
|
||||
|
||||
builtin_types = [
|
||||
|
@ -35,9 +37,17 @@ builtin_type_qtypes = {
|
|||
'uint64': 'QTYPE_QINT',
|
||||
}
|
||||
|
||||
def error_path(parent):
|
||||
res = ""
|
||||
while parent:
|
||||
res = ("In file included from %s:%d:\n" % (parent['file'],
|
||||
parent['line'])) + res
|
||||
parent = parent['parent']
|
||||
return res
|
||||
|
||||
class QAPISchemaError(Exception):
|
||||
def __init__(self, schema, msg):
|
||||
self.fp = schema.fp
|
||||
self.input_file = schema.input_file
|
||||
self.msg = msg
|
||||
self.col = 1
|
||||
self.line = schema.line
|
||||
|
@ -46,23 +56,31 @@ class QAPISchemaError(Exception):
|
|||
self.col = (self.col + 7) % 8 + 1
|
||||
else:
|
||||
self.col += 1
|
||||
self.info = schema.parent_info
|
||||
|
||||
def __str__(self):
|
||||
return "%s:%s:%s: %s" % (self.fp.name, self.line, self.col, self.msg)
|
||||
return error_path(self.info) + \
|
||||
"%s:%d:%d: %s" % (self.input_file, self.line, self.col, self.msg)
|
||||
|
||||
class QAPIExprError(Exception):
|
||||
def __init__(self, expr_info, msg):
|
||||
self.fp = expr_info['fp']
|
||||
self.line = expr_info['line']
|
||||
self.info = expr_info
|
||||
self.msg = msg
|
||||
|
||||
def __str__(self):
|
||||
return "%s:%s: %s" % (self.fp.name, self.line, self.msg)
|
||||
return error_path(self.info['parent']) + \
|
||||
"%s:%d: %s" % (self.info['file'], self.info['line'], self.msg)
|
||||
|
||||
class QAPISchema:
|
||||
|
||||
def __init__(self, fp):
|
||||
self.fp = fp
|
||||
def __init__(self, fp, input_relname=None, include_hist=[], parent_info=None):
|
||||
input_fname = os.path.abspath(fp.name)
|
||||
if input_relname is None:
|
||||
input_relname = fp.name
|
||||
self.input_dir = os.path.dirname(input_fname)
|
||||
self.input_file = input_relname
|
||||
self.include_hist = include_hist + [(input_relname, input_fname)]
|
||||
self.parent_info = parent_info
|
||||
self.src = fp.read()
|
||||
if self.src == '' or self.src[-1] != '\n':
|
||||
self.src += '\n'
|
||||
|
@ -73,10 +91,33 @@ class QAPISchema:
|
|||
self.accept()
|
||||
|
||||
while self.tok != None:
|
||||
expr_info = {'fp': fp, 'line': self.line}
|
||||
expr_elem = {'expr': self.get_expr(False),
|
||||
'info': expr_info}
|
||||
self.exprs.append(expr_elem)
|
||||
expr_info = {'file': input_relname, 'line': self.line, 'parent': self.parent_info}
|
||||
expr = self.get_expr(False)
|
||||
if isinstance(expr, dict) and "include" in expr:
|
||||
if len(expr) != 1:
|
||||
raise QAPIExprError(expr_info, "Invalid 'include' directive")
|
||||
include = expr["include"]
|
||||
if not isinstance(include, str):
|
||||
raise QAPIExprError(expr_info,
|
||||
'Expected a file name (string), got: %s'
|
||||
% include)
|
||||
include_path = os.path.join(self.input_dir, include)
|
||||
if any(include_path == elem[1]
|
||||
for elem in self.include_hist):
|
||||
raise QAPIExprError(expr_info, "Inclusion loop for %s"
|
||||
% include)
|
||||
try:
|
||||
fobj = open(include_path, 'r')
|
||||
except IOError as e:
|
||||
raise QAPIExprError(expr_info,
|
||||
'%s: %s' % (e.strerror, include))
|
||||
exprs_include = QAPISchema(fobj, include,
|
||||
self.include_hist, expr_info)
|
||||
self.exprs.extend(exprs_include.exprs)
|
||||
else:
|
||||
expr_elem = {'expr': expr,
|
||||
'info': expr_info}
|
||||
self.exprs.append(expr_elem)
|
||||
|
||||
def accept(self):
|
||||
while True:
|
||||
|
@ -263,10 +304,10 @@ def check_exprs(schema):
|
|||
if expr.has_key('union'):
|
||||
check_union(expr, expr_elem['info'])
|
||||
|
||||
def parse_schema(fp):
|
||||
def parse_schema(input_file):
|
||||
try:
|
||||
schema = QAPISchema(fp)
|
||||
except QAPISchemaError, e:
|
||||
schema = QAPISchema(open(input_file, "r"))
|
||||
except (QAPISchemaError, QAPIExprError), e:
|
||||
print >>sys.stderr, e
|
||||
exit(1)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue