diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/qapi-commands.py | 4 | ||||
-rw-r--r-- | scripts/qapi-event.py | 16 | ||||
-rw-r--r-- | scripts/qapi-types.py | 2 | ||||
-rw-r--r-- | scripts/qapi-visit.py | 72 | ||||
-rw-r--r-- | scripts/qapi.py | 23 | ||||
-rwxr-xr-x | scripts/qmp/qemu-ga-client | 2 | ||||
-rwxr-xr-x | scripts/qmp/qmp | 4 | ||||
-rwxr-xr-x | scripts/qmp/qmp-shell | 2 | ||||
-rw-r--r-- | scripts/qmp/qmp.py | 4 | ||||
-rwxr-xr-x | scripts/tracetool.py | 4 |
10 files changed, 65 insertions, 68 deletions
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 561e47a42b..91c5a4e8cd 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -131,7 +131,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out, Visitor *v; v = qmp_output_get_visitor(qov); - visit_type_%(c_name)s(v, &ret_in, "unused", &err); + visit_type_%(c_name)s(v, "unused", &ret_in, &err); if (err) { goto out; } @@ -142,7 +142,7 @@ out: qmp_output_visitor_cleanup(qov); qdv = qapi_dealloc_visitor_new(); v = qapi_dealloc_get_visitor(qdv); - visit_type_%(c_name)s(v, &ret_in, "unused", NULL); + visit_type_%(c_name)s(v, "unused", &ret_in, NULL); qapi_dealloc_visitor_cleanup(qdv); } ''', diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 720486f06c..07bcb73d3d 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -2,7 +2,7 @@ # QAPI event generator # # Copyright (c) 2014 Wenchao Xia -# Copyright (c) 2015 Red Hat Inc. +# Copyright (c) 2015-2016 Red Hat Inc. # # Authors: # Wenchao Xia <wenchaoqemu@gmail.com> @@ -61,25 +61,23 @@ def gen_event_send(name, arg_type): if arg_type and arg_type.members: ret += mcgen(''' qov = qmp_output_visitor_new(); - g_assert(qov); - v = qmp_output_get_visitor(qov); - g_assert(v); - /* Fake visit, as if all members are under a structure */ - visit_start_struct(v, NULL, "", "%(name)s", 0, &err); + visit_start_struct(v, "%(name)s", NULL, 0, &err); ''', name=name) ret += gen_err_check() - ret += gen_visit_fields(arg_type.members, need_cast=True) + ret += gen_visit_fields(arg_type.members, need_cast=True, + label='out_obj') ret += mcgen(''' - visit_end_struct(v, &err); +out_obj: + visit_end_struct(v, err ? NULL : &err); if (err) { goto out; } obj = qmp_output_get_qobject(qov); - g_assert(obj != NULL); + g_assert(obj); qdict_put_obj(qmp, "data", obj); ''') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 0d862698a4..d3f631a2f4 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -155,7 +155,7 @@ void qapi_free_%(c_name)s(%(c_name)s *obj) qdv = qapi_dealloc_visitor_new(); v = qapi_dealloc_get_visitor(qdv); - visit_type_%(c_name)s(v, &obj, NULL, NULL); + visit_type_%(c_name)s(v, NULL, &obj, NULL); qapi_dealloc_visitor_cleanup(qdv); } ''', diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index b93690b608..0fdcebcca8 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -2,7 +2,7 @@ # QAPI visitor generator # # Copyright IBM, Corp. 2011 -# Copyright (C) 2014-2015 Red Hat, Inc. +# Copyright (C) 2014-2016 Red Hat, Inc. # # Authors: # Anthony Liguori <aliguori@us.ibm.com> @@ -29,7 +29,7 @@ def gen_visit_decl(name, scalar=False): if not scalar: c_type += '*' return mcgen(''' -void visit_type_%(c_name)s(Visitor *v, %(c_type)sobj, const char *name, Error **errp); +void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_type)sobj, Error **errp); ''', c_name=c_name(name), c_type=c_type) @@ -62,7 +62,7 @@ static void visit_type_implicit_%(c_type)s(Visitor *v, %(c_type)s **obj, Error * visit_start_implicit_struct(v, (void **)obj, sizeof(%(c_type)s), &err); if (!err) { visit_type_%(c_type)s_fields(v, obj, errp); - visit_end_implicit_struct(v, &err); + visit_end_implicit_struct(v); } error_propagate(errp, err); } @@ -118,21 +118,27 @@ def gen_visit_struct(name, base, members): # call qapi_free_FOO() to avoid a memory leak of the partial FOO. ret += mcgen(''' -void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp) +void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error **errp) { Error *err = NULL; - visit_start_struct(v, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err); - if (!err) { - if (*obj) { - visit_type_%(c_name)s_fields(v, obj, errp); - } - visit_end_struct(v, &err); + visit_start_struct(v, name, (void **)obj, sizeof(%(c_name)s), &err); + if (err) { + goto out; + } + if (!*obj) { + goto out_obj; } + visit_type_%(c_name)s_fields(v, obj, &err); + error_propagate(errp, err); + err = NULL; +out_obj: + visit_end_struct(v, &err); +out: error_propagate(errp, err); } ''', - name=name, c_name=c_name(name)) + c_name=c_name(name)) return ret @@ -144,7 +150,7 @@ def gen_visit_list(name, element_type): # call qapi_free_FOOList() to avoid a memory leak of the partial FOOList. return mcgen(''' -void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp) +void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error **errp) { Error *err = NULL; GenericList *i, **prev; @@ -155,15 +161,13 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error } for (prev = (GenericList **)obj; - !err && (i = visit_next_list(v, prev, &err)) != NULL; + !err && (i = visit_next_list(v, prev)) != NULL; prev = &i) { %(c_name)s *native_i = (%(c_name)s *)i; - visit_type_%(c_elt_type)s(v, &native_i->value, NULL, &err); + visit_type_%(c_elt_type)s(v, NULL, &native_i->value, &err); } - error_propagate(errp, err); - err = NULL; - visit_end_list(v, &err); + visit_end_list(v); out: error_propagate(errp, err); } @@ -172,15 +176,16 @@ out: def gen_visit_enum(name): - # FIXME cast from enum *obj to int * invalidly assumes enum is int return mcgen(''' -void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *name, Error **errp) +void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s *obj, Error **errp) { - visit_type_enum(v, (int *)obj, %(c_name)s_lookup, "%(name)s", name, errp); + int value = *obj; + visit_type_enum(v, name, &value, %(c_name)s_lookup, errp); + *obj = value; } ''', - c_name=c_name(name), name=name) + c_name=c_name(name)) def gen_visit_alternate(name, variants): @@ -191,7 +196,7 @@ def gen_visit_alternate(name, variants): ret = mcgen(''' -void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp) +void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error **errp) { Error *err = NULL; @@ -199,7 +204,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error if (err) { goto out; } - visit_get_next_type(v, &(*obj)->type, %(promote_int)s, name, &err); + visit_get_next_type(v, name, &(*obj)->type, %(promote_int)s, &err); if (err) { goto out_obj; } @@ -210,7 +215,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error for var in variants.variants: ret += mcgen(''' case %(case)s: - visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, name, &err); + visit_type_%(c_type)s(v, name, &(*obj)->u.%(c_name)s, &err); break; ''', case=var.type.alternate_qtype(), @@ -223,9 +228,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error "%(name)s"); } out_obj: - error_propagate(errp, err); - err = NULL; - visit_end_implicit_struct(v, &err); + visit_end_implicit_struct(v); out: error_propagate(errp, err); } @@ -248,11 +251,11 @@ def gen_visit_union(name, base, variants): ret += mcgen(''' -void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp) +void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error **errp) { Error *err = NULL; - visit_start_struct(v, (void **)obj, "%(name)s", name, sizeof(%(c_name)s), &err); + visit_start_struct(v, name, (void **)obj, sizeof(%(c_name)s), &err); if (err) { goto out; } @@ -260,7 +263,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error goto out_obj; } ''', - c_name=c_name(name), name=name) + c_name=c_name(name)) if base: ret += mcgen(''' @@ -269,7 +272,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error c_name=base.c_name()) else: ret += mcgen(''' - visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err); + visit_type_%(c_type)s(v, "%(name)s", &(*obj)->%(c_name)s, &err); ''', c_type=variants.tag_member.type.c_name(), c_name=c_name(variants.tag_member.name), @@ -293,7 +296,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error var.name)) if simple_union_type: ret += mcgen(''' - visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, "data", &err); + visit_type_%(c_type)s(v, "data", &(*obj)->u.%(c_name)s, &err); ''', c_type=simple_union_type.c_name(), c_name=c_name(var.name)) @@ -314,11 +317,6 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error out_obj: error_propagate(errp, err); err = NULL; - if (*obj) { - visit_end_union(v, !!(*obj)->u.data, &err); - } - error_propagate(errp, err); - err = NULL; visit_end_struct(v, &err); out: error_propagate(errp, err); diff --git a/scripts/qapi.py b/scripts/qapi.py index 7dec611d09..f40dc9e777 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -2,7 +2,7 @@ # QAPI helper library # # Copyright IBM, Corp. 2011 -# Copyright (c) 2013-2015 Red Hat Inc. +# Copyright (c) 2013-2016 Red Hat Inc. # # Authors: # Anthony Liguori <aliguori@us.ibm.com> @@ -167,7 +167,7 @@ class QAPISchemaParser(object): continue try: fobj = open(incl_abs_fname, 'r') - except IOError, e: + except IOError as e: raise QAPIExprError(expr_info, '%s: %s' % (e.strerror, include)) exprs_include = QAPISchemaParser(fobj, previously_included, @@ -1189,7 +1189,7 @@ class QAPISchema(object): self._predefining = False self._def_exprs() self.check() - except (QAPISchemaError, QAPIExprError), err: + except (QAPISchemaError, QAPIExprError) as err: print >>sys.stderr, err exit(1) @@ -1482,7 +1482,7 @@ def c_name(name, protect=True): 'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not', 'not_eq', 'or', 'or_eq', 'xor', 'xor_eq']) # namespace pollution: - polluted_words = set(['unix', 'errno']) + polluted_words = set(['unix', 'errno', 'mips', 'sparc']) name = name.translate(c_name_trans) if protect and (name in c89_words | c99_words | c11_words | gcc_words | cpp_words | polluted_words): @@ -1636,7 +1636,8 @@ def gen_err_check(label='out', skiperr=False): label=label) -def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False): +def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False, + label='out'): ret = '' if skiperr: errparg = 'NULL' @@ -1646,10 +1647,10 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False): for memb in members: if memb.optional: ret += mcgen(''' - if (visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s")) { + if (visit_optional(v, "%(name)s", &%(prefix)shas_%(c_name)s)) { ''', prefix=prefix, c_name=c_name(memb.name), - name=memb.name, errp=errparg) + name=memb.name) push_indent() # Ugly: sometimes we need to cast away const @@ -1659,12 +1660,12 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False): cast = '' ret += mcgen(''' - visit_type_%(c_type)s(v, %(cast)s&%(prefix)s%(c_name)s, "%(name)s", %(errp)s); + visit_type_%(c_type)s(v, "%(name)s", %(cast)s&%(prefix)s%(c_name)s, %(errp)s); ''', c_type=memb.type.c_name(), prefix=prefix, cast=cast, c_name=c_name(memb.name), name=memb.name, errp=errparg) - ret += gen_err_check(skiperr=skiperr) + ret += gen_err_check(skiperr=skiperr, label=label) if memb.optional: pop_indent() @@ -1686,7 +1687,7 @@ def parse_command_line(extra_options="", extra_long_options=[]): "chp:o:" + extra_options, ["source", "header", "prefix=", "output-dir="] + extra_long_options) - except getopt.GetoptError, err: + except getopt.GetoptError as err: print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err)) sys.exit(1) @@ -1740,7 +1741,7 @@ def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, if output_dir: try: os.makedirs(output_dir) - except os.error, e: + except os.error as e: if e.errno != errno.EEXIST: raise diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client index 9908f21093..fd056056ff 100755 --- a/scripts/qmp/qemu-ga-client +++ b/scripts/qmp/qemu-ga-client @@ -259,7 +259,7 @@ def main(address, cmd, args): try: client = QemuGuestAgentClient(address) - except QemuGuestAgent.error, e: + except QemuGuestAgent.error as e: import errno print(e) diff --git a/scripts/qmp/qmp b/scripts/qmp/qmp index 1db3c7ffeb..514b539a6b 100755 --- a/scripts/qmp/qmp +++ b/scripts/qmp/qmp @@ -91,8 +91,8 @@ def main(args): try: os.environ['QMP_PATH'] = path os.execvp(fullcmd, [fullcmd] + args) - except OSError, (errno, msg): - if errno == 2: + except OSError as exc: + if exc.errno == 2: print 'Command "%s" not found.' % (fullcmd) return 1 raise diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index fa39bf0d7b..7a402edf2a 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -240,7 +240,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): def _execute_cmd(self, cmdline): try: qmpcmd = self.__build_cmd(cmdline) - except Exception, e: + except Exception as e: print 'Error while parsing command line: %s' % e print 'command format: <command-name> ', print '[arg-name1=arg1] ... [arg-nameN=argN]' diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index 1d38e3e9e7..779332f321 100644 --- a/scripts/qmp/qmp.py +++ b/scripts/qmp/qmp.py @@ -92,7 +92,7 @@ class QEMUMonitorProtocol: self.__sock.setblocking(0) try: self.__json_read() - except socket.error, err: + except socket.error as err: if err[0] == errno.EAGAIN: # No data available pass @@ -150,7 +150,7 @@ class QEMUMonitorProtocol: """ try: self.__sock.sendall(json.dumps(qmp_cmd)) - except socket.error, err: + except socket.error as err: if err[0] == errno.EPIPE: return raise socket.error(err) diff --git a/scripts/tracetool.py b/scripts/tracetool.py index 83bde7bda9..7b82959e84 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -71,7 +71,7 @@ def main(args): try: opts, args = getopt.getopt(args[1:], "", long_opts) - except getopt.GetoptError, err: + except getopt.GetoptError as err: error_opt(str(err)) check_backends = False @@ -132,7 +132,7 @@ def main(args): try: tracetool.generate(sys.stdin, arg_format, arg_backends, binary=binary, probe_prefix=probe_prefix) - except tracetool.TracetoolError, e: + except tracetool.TracetoolError as e: error_opt(str(e)) if __name__ == "__main__": |