From 291928a80f39670929fcce222acd5e21d1434692 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 18 Dec 2015 08:52:41 +0100 Subject: [PATCH 01/31] qapi: Use Python 2.6 "except E as ..." syntax PEP 8 calls for it, because it's forward compatible with Python 3. Supported since Python 2.6, which we require (commit fec2103). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Acked-by: Stefan Hajnoczi Message-Id: <1450425164-24969-2-git-send-email-armbru@redhat.com> --- scripts/qapi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 7dec611d09..645dcf1427 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -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) @@ -1686,7 +1686,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 +1740,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 From cf6c63456b47118a7f0fbb917c220c0a483db6de Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 18 Dec 2015 08:52:42 +0100 Subject: [PATCH 02/31] scripts/qmp: Use Python 2.6 "except E as ..." syntax PEP 8 calls for it, because it's forward compatible with Python 3. Supported since Python 2.6, which we require (commit fec2103). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Acked-by: Stefan Hajnoczi Message-Id: <1450425164-24969-3-git-send-email-armbru@redhat.com> --- scripts/qmp/qemu-ga-client | 2 +- scripts/qmp/qmp | 4 ++-- scripts/qmp/qmp-shell | 2 +- scripts/qmp/qmp.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) 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: ', 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) From 86b227d984fde7069c49ceb92828a965baa11186 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 18 Dec 2015 08:52:43 +0100 Subject: [PATCH 03/31] Revert "tracetool: use Python 2.4-compatible exception handling syntax" This reverts commit 662da3854e3f490223373b40afdcfcc339d14aa5. We require Python 2.6 now (commit fec2103). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Acked-by: Stefan Hajnoczi Message-Id: <1450425164-24969-4-git-send-email-armbru@redhat.com> --- scripts/tracetool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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__": From 03e188102ca8d2eab16a8d0e7818c533a93bb799 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 18 Dec 2015 08:52:44 +0100 Subject: [PATCH 04/31] tests: Use Python 2.6 "except E as ..." syntax PEP 8 calls for it, because it's forward compatible with Python 3. Supported since Python 2.6, which we require (commit fec2103). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Acked-by: Stefan Hajnoczi Message-Id: <1450425164-24969-5-git-send-email-armbru@redhat.com> --- tests/image-fuzzer/runner.py | 12 ++++++------ tests/qemu-iotests/qed.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py index be7e283dd9..96a1c11b2f 100755 --- a/tests/image-fuzzer/runner.py +++ b/tests/image-fuzzer/runner.py @@ -157,7 +157,7 @@ class TestEnv(object): try: os.makedirs(self.current_dir) - except OSError, e: + except OSError as e: print >>sys.stderr, \ "Error: The working directory '%s' cannot be used. Reason: %s"\ % (self.work_dir, e[1]) @@ -244,7 +244,7 @@ class TestEnv(object): temp_log = StringIO.StringIO() try: retcode = run_app(temp_log, current_cmd) - except OSError, e: + except OSError as e: multilog("%sError: Start of '%s' failed. Reason: %s\n\n" % (test_summary, os.path.basename(current_cmd[0]), e[1]), @@ -356,7 +356,7 @@ if __name__ == '__main__': opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:hs:kvd:', ['command=', 'help', 'seed=', 'config=', 'keep_passed', 'verbose', 'duration=']) - except getopt.error, e: + except getopt.error as e: print >>sys.stderr, \ "Error: %s\n\nTry 'runner.py --help' for more information" % e sys.exit(1) @@ -374,7 +374,7 @@ if __name__ == '__main__': elif opt in ('-c', '--command'): try: command = json.loads(arg) - except (TypeError, ValueError, NameError), e: + except (TypeError, ValueError, NameError) as e: print >>sys.stderr, \ "Error: JSON array of test commands cannot be loaded.\n" \ "Reason: %s" % e @@ -390,7 +390,7 @@ if __name__ == '__main__': elif opt == '--config': try: config = json.loads(arg) - except (TypeError, ValueError, NameError), e: + except (TypeError, ValueError, NameError) as e: print >>sys.stderr, \ "Error: JSON array with the fuzzer configuration cannot" \ " be loaded\nReason: %s" % e @@ -414,7 +414,7 @@ if __name__ == '__main__': try: image_generator = __import__(generator_name) - except ImportError, e: + except ImportError as e: print >>sys.stderr, \ "Error: The image generator '%s' cannot be imported.\n" \ "Reason: %s" % (generator_name, e) diff --git a/tests/qemu-iotests/qed.py b/tests/qemu-iotests/qed.py index 52ff845590..748068d7fe 100755 --- a/tests/qemu-iotests/qed.py +++ b/tests/qemu-iotests/qed.py @@ -227,7 +227,7 @@ def main(): qed = QED(open(filename, 'r+b')) try: globals()[cmd](qed, *sys.argv[3:]) - except TypeError, e: + except TypeError as e: sys.stderr.write(globals()[cmd].__doc__ + '\n') sys.exit(1) From 6e8e5cb9aa663ba59d4ca0f4cb8307d75163e31a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:37 -0700 Subject: [PATCH 05/31] qobject: Document more shortcomings in our number handling We've already documented that our JSON parsing is locale dependent; but we should also document that our JSON output has the same problem. Additionally, JSON requires finite values (you have to upgrade to JSON5 to get support for Inf or NaN), and our output truncates floating point numbers to the point of losing significant precision that could cause the receiver to read a different value. Sadly, this series is not going to be the one that addresses these problems. Fix some trailing whitespace I noticed in the vicinity. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-2-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qobject/json-parser.c | 6 ++++-- qobject/qjson.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 77c9382c5e..6c05f6cc70 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -1,5 +1,5 @@ /* - * JSON Parser + * JSON Parser * * Copyright IBM, Corp. 2009 * @@ -518,7 +518,9 @@ static QObject *parse_literal(JSONParserContext *ctxt) /* fall through to JSON_FLOAT */ } case JSON_FLOAT: - /* FIXME dependent on locale */ + /* FIXME dependent on locale; a pervasive issue in QEMU */ + /* FIXME our lexer matches RFC 7159 in forbidding Inf or NaN, + * but those might be useful extensions beyond JSON */ return QOBJECT(qfloat_from_double(strtod(token->str, NULL))); default: abort(); diff --git a/qobject/qjson.c b/qobject/qjson.c index b8cc4ca964..06dc210cbf 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -238,6 +238,15 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent) char buffer[1024]; int len; + /* FIXME: snprintf() is locale dependent; but JSON requires + * numbers to be formatted as if in the C locale. Dependence + * on C locale is a pervasive issue in QEMU. */ + /* FIXME: This risks printing Inf or NaN, which are not valid + * JSON values. */ + /* FIXME: the default precision of 6 for %f often causes + * rounding errors; we should be using DBL_DECIMAL_DIG (17), + * and only rounding to a shorter number if the result would + * still produce the same floating point value. */ len = snprintf(buffer, sizeof(buffer), "%f", qfloat_get_double(val)); while (len > 0 && buffer[len - 1] == '0') { len--; @@ -248,7 +257,7 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent) } else { buffer[len] = 0; } - + qstring_append(str, buffer); break; } From d7bea75d35a44023efc9d481d3a1a2600677b2ef Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:38 -0700 Subject: [PATCH 06/31] qapi: Avoid use of misnamed DO_UPCAST() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macro DO_UPCAST() is incorrectly named: it converts from a parent class to a derived class (which is a downcast). Better, and more consistent with some of the other qapi visitors, is to use the container_of() macro through a to_FOO() helper. Names like 'to_ov()' may be a bit short, but for a static helper it doesn't hurt too much, and matches existing practice in files like qmp-input-visitor.c. Our current definition of container_of() is weaker than DO_UPCAST(), in that it does not require the derived class to have Visitor as its first member, but this does not hurt our usage patterns in qapi visitors. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-3-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qapi/opts-visitor.c | 28 +++++++++++++++++----------- qapi/string-input-visitor.c | 23 ++++++++++++++--------- qapi/string-output-visitor.c | 21 +++++++++++++-------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index eb7d85b0ec..4955ac833f 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -90,6 +90,12 @@ struct OptsVisitor }; +static OptsVisitor *to_ov(Visitor *v) +{ + return container_of(v, OptsVisitor, visitor); +} + + static void destroy_list(gpointer list) { @@ -122,7 +128,7 @@ static void opts_start_struct(Visitor *v, void **obj, const char *kind, const char *name, size_t size, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); const QemuOpt *opt; if (obj) { @@ -161,7 +167,7 @@ ghr_true(gpointer ign_key, gpointer ign_value, gpointer ign_user_data) static void opts_end_struct(Visitor *v, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); GQueue *any; if (--ov->depth > 0) { @@ -203,7 +209,7 @@ lookup_distinct(const OptsVisitor *ov, const char *name, Error **errp) static void opts_start_list(Visitor *v, const char *name, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); /* we can't traverse a list in a list */ assert(ov->list_mode == LM_NONE); @@ -217,7 +223,7 @@ opts_start_list(Visitor *v, const char *name, Error **errp) static GenericList * opts_next_list(Visitor *v, GenericList **list, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); GenericList **link; switch (ov->list_mode) { @@ -266,7 +272,7 @@ opts_next_list(Visitor *v, GenericList **list, Error **errp) static void opts_end_list(Visitor *v, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); assert(ov->list_mode == LM_STARTED || ov->list_mode == LM_IN_PROGRESS || @@ -308,7 +314,7 @@ processed(OptsVisitor *ov, const char *name) static void opts_type_str(Visitor *v, char **obj, const char *name, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); const QemuOpt *opt; opt = lookup_scalar(ov, name, errp); @@ -324,7 +330,7 @@ opts_type_str(Visitor *v, char **obj, const char *name, Error **errp) static void opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); const QemuOpt *opt; opt = lookup_scalar(ov, name, errp); @@ -357,7 +363,7 @@ opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) static void opts_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); const QemuOpt *opt; const char *str; long long val; @@ -413,7 +419,7 @@ opts_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) static void opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); const QemuOpt *opt; const char *str; unsigned long long val; @@ -465,7 +471,7 @@ opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) static void opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); const QemuOpt *opt; int64_t val; char *endptr; @@ -491,7 +497,7 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) static void opts_optional(Visitor *v, bool *present, const char *name) { - OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v); + OptsVisitor *ov = to_ov(v); /* we only support a single mandatory scalar field in a list node */ assert(ov->list_mode == LM_NONE); diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 8c5ff7e1d2..52db4cf32b 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -33,6 +33,11 @@ struct StringInputVisitor const char *string; }; +static StringInputVisitor *to_siv(Visitor *v) +{ + return container_of(v, StringInputVisitor, visitor); +} + static void free_range(void *range, void *dummy) { g_free(range); @@ -121,7 +126,7 @@ error: static void start_list(Visitor *v, const char *name, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); parse_str(siv, errp); @@ -137,7 +142,7 @@ start_list(Visitor *v, const char *name, Error **errp) static GenericList * next_list(Visitor *v, GenericList **list, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); GenericList **link; Range *r; @@ -176,14 +181,14 @@ next_list(Visitor *v, GenericList **list, Error **errp) static void end_list(Visitor *v, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); siv->head = true; } static void parse_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); if (!siv->string) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", @@ -225,7 +230,7 @@ error: static void parse_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); Error *err = NULL; uint64_t val; @@ -247,7 +252,7 @@ static void parse_type_size(Visitor *v, uint64_t *obj, const char *name, static void parse_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); if (siv->string) { if (!strcasecmp(siv->string, "on") || @@ -271,7 +276,7 @@ static void parse_type_bool(Visitor *v, bool *obj, const char *name, static void parse_type_str(Visitor *v, char **obj, const char *name, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); if (siv->string) { *obj = g_strdup(siv->string); } else { @@ -283,7 +288,7 @@ static void parse_type_str(Visitor *v, char **obj, const char *name, static void parse_type_number(Visitor *v, double *obj, const char *name, Error **errp) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); char *endp = (char *) siv->string; double val; @@ -302,7 +307,7 @@ static void parse_type_number(Visitor *v, double *obj, const char *name, static void parse_optional(Visitor *v, bool *present, const char *name) { - StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v); + StringInputVisitor *siv = to_siv(v); if (!siv->string) { *present = false; diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index b04cec4cf7..b0313cb53a 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -67,6 +67,11 @@ struct StringOutputVisitor GList *ranges; }; +static StringOutputVisitor *to_sov(Visitor *v) +{ + return container_of(v, StringOutputVisitor, visitor); +} + static void string_output_set(StringOutputVisitor *sov, char *string) { if (sov->string) { @@ -120,7 +125,7 @@ static void format_string(StringOutputVisitor *sov, Range *r, bool next, static void print_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); GList *l; switch (sov->list_mode) { @@ -196,7 +201,7 @@ static void print_type_int(Visitor *v, int64_t *obj, const char *name, static void print_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); static const char suffixes[] = { 'B', 'K', 'M', 'G', 'T', 'P', 'E' }; uint64_t div, val; char *out; @@ -227,14 +232,14 @@ static void print_type_size(Visitor *v, uint64_t *obj, const char *name, static void print_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); string_output_set(sov, g_strdup(*obj ? "true" : "false")); } static void print_type_str(Visitor *v, char **obj, const char *name, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); char *out; if (sov->human) { @@ -248,14 +253,14 @@ static void print_type_str(Visitor *v, char **obj, const char *name, static void print_type_number(Visitor *v, double *obj, const char *name, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); string_output_set(sov, g_strdup_printf("%f", *obj)); } static void start_list(Visitor *v, const char *name, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); /* we can't traverse a list in a list */ assert(sov->list_mode == LM_NONE); @@ -266,7 +271,7 @@ start_list(Visitor *v, const char *name, Error **errp) static GenericList * next_list(Visitor *v, GenericList **list, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); GenericList *ret = NULL; if (*list) { if (sov->head) { @@ -293,7 +298,7 @@ next_list(Visitor *v, GenericList **list, Error **errp) static void end_list(Visitor *v, Error **errp) { - StringOutputVisitor *sov = DO_UPCAST(StringOutputVisitor, visitor, v); + StringOutputVisitor *sov = to_sov(v); assert(sov->list_mode == LM_STARTED || sov->list_mode == LM_END || From 77577cb8d6ec9d787e22c5e4ab17ee85fa3f753d Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:39 -0700 Subject: [PATCH 07/31] qapi: Drop dead dealloc visitor variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 0b9d8542 added StackEntry.is_list_head, but forgot to delete the now-unused QapiDeallocVisitor.is_list_head. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-4-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qapi/qapi-dealloc-visitor.c | 1 - 1 file changed, 1 deletion(-) diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index 9340446633..b5abbf5115 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -29,7 +29,6 @@ struct QapiDeallocVisitor { Visitor visitor; QTAILQ_HEAD(, StackEntry) stack; - bool is_list_head; }; static QapiDeallocVisitor *to_qov(Visitor *v) From 4894b00b27926223bafc8cc993ab7b8ebe160bc0 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:40 -0700 Subject: [PATCH 08/31] qapi: Dealloc visitor does not need a type_size() The intent of having the visitor type_size() callback differ from type_uint64() is to allow special handling for sizes; the visitor core gracefully falls back to type_uint64() if there is no need for the distinction. Since the dealloc visitor does nothing for any of the int visits, drop the pointless size handler. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-5-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qapi/qapi-dealloc-visitor.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index b5abbf5115..c805a7a87d 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -159,11 +159,6 @@ static void qapi_dealloc_type_anything(Visitor *v, QObject **obj, } } -static void qapi_dealloc_type_size(Visitor *v, uint64_t *obj, const char *name, - Error **errp) -{ -} - static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char * const strings[], const char *kind, const char *name, @@ -225,7 +220,6 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_any = qapi_dealloc_type_anything; - v->visitor.type_size = qapi_dealloc_type_size; v->visitor.start_union = qapi_dealloc_start_union; QTAILQ_INIT(&v->stack); From e408311546b633b232312450d9017f4db21df0dc Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:41 -0700 Subject: [PATCH 09/31] qapi: Drop dead parameter in gen_params() Commit 5cdc8831 reworked gen_params() to be simpler, but forgot to clean up a now-unused errp named argument. No change to generated code. Reported-by: Markus Armbruster Signed-off-by: Eric Blake Message-Id: <1454075341-13658-6-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 645dcf1427..0f032c3e67 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 @@ -1649,7 +1649,7 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False): if (visit_optional(v, &%(prefix)shas_%(c_name)s, "%(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 From 7019738d4c9ce49b8fad09e9774393ad127b835d Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:42 -0700 Subject: [PATCH 10/31] hmp: Drop pointless allocation during qapi visit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The qapi visitor contract allows us to visit a virtual structure, where we don't have any corresponding qapi struct. Most such uses pass NULL for @obj; but these two callers were passing a dummy pointer, which then gets allocated to heap memory but then immediately freed without use. Clean this up to suppress unwanted allocation, like we do elsewhere. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-7-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- hmp.c | 4 +--- vl.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index cb03a156d2..6071a0b85b 100644 --- a/hmp.c +++ b/hmp.c @@ -1657,7 +1657,6 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) QemuOpts *opts; char *type = NULL; char *id = NULL; - void *dummy = NULL; OptsVisitor *ov; QDict *pdict; @@ -1669,7 +1668,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) ov = opts_visitor_new(opts); pdict = qdict_clone_shallow(qdict); - visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err); + visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err); if (err) { goto out_clean; } @@ -1701,7 +1700,6 @@ out_clean: qemu_opts_del(opts); g_free(id); g_free(type); - g_free(dummy); out: hmp_handle_error(mon, &err); diff --git a/vl.c b/vl.c index c581e3978b..db51ebd2a6 100644 --- a/vl.c +++ b/vl.c @@ -2821,7 +2821,6 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) Error *err = NULL; char *type = NULL; char *id = NULL; - void *dummy = NULL; OptsVisitor *ov; QDict *pdict; bool (*type_predicate)(const char *) = opaque; @@ -2829,7 +2828,7 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) ov = opts_visitor_new(opts); pdict = qemu_opts_to_qdict(opts, NULL); - visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err); + visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err); if (err) { goto out; } @@ -2864,7 +2863,6 @@ out: QDECREF(pdict); g_free(id); g_free(type); - g_free(dummy); if (err) { error_report_err(err); return -1; From 9b65859d5e2e43fa89365224c5330e8c72ab760b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:43 -0700 Subject: [PATCH 11/31] hmp: Cache use of qapi visitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cache the visitor in a local variable instead of repeatedly calling the accessor. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-8-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- hmp.c | 12 +++++++----- vl.c | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hmp.c b/hmp.c index 6071a0b85b..6a49886138 100644 --- a/hmp.c +++ b/hmp.c @@ -1659,6 +1659,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) char *id = NULL; OptsVisitor *ov; QDict *pdict; + Visitor *v; opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); if (err) { @@ -1667,28 +1668,29 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) ov = opts_visitor_new(opts); pdict = qdict_clone_shallow(qdict); + v = opts_get_visitor(ov); - visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err); + visit_start_struct(v, NULL, NULL, NULL, 0, &err); if (err) { goto out_clean; } qdict_del(pdict, "qom-type"); - visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err); + visit_type_str(v, &type, "qom-type", &err); if (err) { goto out_end; } qdict_del(pdict, "id"); - visit_type_str(opts_get_visitor(ov), &id, "id", &err); + visit_type_str(v, &id, "id", &err); if (err) { goto out_end; } - object_add(type, id, pdict, opts_get_visitor(ov), &err); + object_add(type, id, pdict, v, &err); out_end: - visit_end_struct(opts_get_visitor(ov), &err_end); + visit_end_struct(v, &err_end); if (!err && err_end) { qmp_object_del(id, NULL); } diff --git a/vl.c b/vl.c index db51ebd2a6..245b2bad6d 100644 --- a/vl.c +++ b/vl.c @@ -2824,17 +2824,19 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) OptsVisitor *ov; QDict *pdict; bool (*type_predicate)(const char *) = opaque; + Visitor *v; ov = opts_visitor_new(opts); pdict = qemu_opts_to_qdict(opts, NULL); + v = opts_get_visitor(ov); - visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err); + visit_start_struct(v, NULL, NULL, NULL, 0, &err); if (err) { goto out; } qdict_del(pdict, "qom-type"); - visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err); + visit_type_str(v, &type, "qom-type", &err); if (err) { goto out; } @@ -2843,16 +2845,16 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) } qdict_del(pdict, "id"); - visit_type_str(opts_get_visitor(ov), &id, "id", &err); + visit_type_str(v, &id, "id", &err); if (err) { goto out; } - object_add(type, id, pdict, opts_get_visitor(ov), &err); + object_add(type, id, pdict, v, &err); if (err) { goto out; } - visit_end_struct(opts_get_visitor(ov), &err); + visit_end_struct(v, &err); if (err) { qmp_object_del(id, NULL); } From 014791b0df927226b794d14696724b9c9c0583d0 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:44 -0700 Subject: [PATCH 12/31] vl: Ensure qapi visitor properly ends struct visit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guarantee that visit_end_struct() is called if visit_start_struct() succeeded. This matches the behavior of most other uses of visitors, and is a step towards the possibility of a future patch that adds and enforces some tighter semantics to the visitor interface (namely, cleanup of the visitor would no longer have to mop up as many leftovers from an aborted partial visit). The change to code here matches the flow of hmp.c:hmp_object_add(); a later patch will then further simplify the cleanup logic of both places by refactoring visit_end_struct() to not require a second local error object. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-9-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- vl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vl.c b/vl.c index 245b2bad6d..300a609479 100644 --- a/vl.c +++ b/vl.c @@ -2819,6 +2819,7 @@ static bool object_create_delayed(const char *type) static int object_create(void *opaque, QemuOpts *opts, Error **errp) { Error *err = NULL; + Error *err_end = NULL; char *type = NULL; char *id = NULL; OptsVisitor *ov; @@ -2841,23 +2842,24 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) goto out; } if (!type_predicate(type)) { + visit_end_struct(v, NULL); goto out; } qdict_del(pdict, "id"); visit_type_str(v, &id, "id", &err); if (err) { - goto out; + goto out_end; } object_add(type, id, pdict, v, &err); - if (err) { - goto out; - } - visit_end_struct(v, &err); - if (err) { + +out_end: + visit_end_struct(v, &err_end); + if (!err && err_end) { qmp_object_del(id, NULL); } + error_propagate(&err, err_end); out: opts_visitor_cleanup(ov); From 9dbb8fa7eff6e5e4cfd83ea26dc67f8404b84aa2 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:45 -0700 Subject: [PATCH 13/31] balloon: Improve use of qapi visitor Rework the control flow of balloon_stats_get_all() to make it easier for a later patch to split visit_end_struct(). Also switch to the uint64 visitor to match the data type. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-10-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- hw/virtio/virtio-balloon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 5c3020331c..06912bbe6d 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -133,9 +133,11 @@ static void balloon_stats_get_all(Object *obj, struct Visitor *v, if (err) { goto out_end; } - for (i = 0; !err && i < VIRTIO_BALLOON_S_NR; i++) { - visit_type_int64(v, (int64_t *) &s->stats[i], balloon_stat_names[i], - &err); + for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) { + visit_type_uint64(v, &s->stats[i], balloon_stat_names[i], &err); + if (err) { + break; + } } error_propagate(errp, err); err = NULL; From a16e3e5c5825c90887a863513916f93eeec16c55 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:46 -0700 Subject: [PATCH 14/31] qapi: Improve generated event use of qapi visitor All other successful clients of visit_start_struct() were paired with an unconditional visit_end_struct(); but the generated code for events was relying on qmp_output_visitor_cleanup() to work on an incomplete visit. Alter the code to guarantee that the struct is completed, which will make a future patch to split visit_end_struct() easier to reason about. While at it, drop some assertions and comments that are not present in other uses of the qmp output visitor, and pass NULL rather than "" as the 'kind' parameter (matching most other uses where obj is NULL). The changes to the generated code look like: | qmp = qmp_event_build_dict("DEVICE_TRAY_MOVED"); | | 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, "", "DEVICE_TRAY_MOVED", 0, &err); |+ visit_start_struct(v, NULL, NULL, "DEVICE_TRAY_MOVED", 0, &err); | if (err) { | goto out; | } | visit_type_str(v, (char **)&device, "device", &err); | if (err) { |- goto out; |+ goto out_obj; | } | visit_type_bool(v, &tray_open, "tray-open", &err); | if (err) { |- goto out; |+ goto out_obj; | } |- 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); | emit(QAPI_EVENT_DEVICE_TRAY_MOVED, qmp, &err); Note that the 'goto out_obj' with no intervening code before the label, as well as the construct of 'err ? NULL : &err', are both a bit unusual but also temporary; they get fixed in a later patch that splits visit_end_struct() to drop its errp parameter by moving some checking before the label. But until that time, this was the simplest way to avoid the appearance of passing a possibly-set error to visit_end_struct(), even though actual code inspection shows that visit_end_struct() for a QMP output visitor will never set an error. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-11-git-send-email-eblake@redhat.com> [Commit message's code diff tweaked] Signed-off-by: Markus Armbruster --- scripts/qapi-event.py | 16 +++++++--------- scripts/qapi.py | 5 +++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 720486f06c..0f5534f6c3 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 @@ -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, NULL, NULL, "%(name)s", 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.py b/scripts/qapi.py index 0f032c3e67..9254e48fe3 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -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' @@ -1664,7 +1665,7 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False): 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() From 92b09babc11b60458c28cfe37eaa314de50e6241 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:47 -0700 Subject: [PATCH 15/31] qapi: Track all failures between visit_start/stop Inside the generated code between visit_start_struct() and visit_end_struct(), we were blindly setting the error into the caller's errp parameter. But a future patch to split visit_end_struct() will require that we take action based on whether an error has occurred, which requires us to track all actions through a local err. Rewrite the visits to be more in line with the other generated calls. Generated code changes look like: | visit_start_struct(v, (void **)obj, "Abort", name, sizeof(Abort), &err); |- if (!err) { |- if (*obj) { |- visit_type_Abort_fields(v, obj, errp); |- } |- visit_end_struct(v, &err); |+ if (err) { |+ goto out; | } |+ if (!*obj) { |+ goto out_obj; |+ } |+ visit_type_Abort_fields(v, obj, &err); |+ error_propagate(errp, err); |+ err = NULL; |+out_obj: |+ visit_end_struct(v, &err); |+out: | error_propagate(errp, err); | } Signed-off-by: Eric Blake Message-Id: <1454075341-13658-12-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi-visit.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index b93690b608..ec16e365a6 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 @@ -123,12 +123,18 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error 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); + 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); } ''', From 7c91aabd8964cfdf637f302c579c95401f21ce92 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:48 -0700 Subject: [PATCH 16/31] qapi-visit: Kill unused visit_end_union() The generated code can call visit_end_union() without having called visit_start_union(). Example: if (!*obj) { goto out_obj; } visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err); if (err) { goto out_obj; // if we go from here... } if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) { goto out_obj; } switch ((*obj)->arch) { [...] } out_obj: // ... then *obj is true, and ... error_propagate(errp, err); err = NULL; if (*obj) { // we end up here visit_end_union(v, !!(*obj)->u.data, &err); } error_propagate(errp, err); Harmless only because no visitor implements end_union(). Clean it up anyway, by deleting the function as useless. Messed up since we have visit_end_union (commit cee2ded). Signed-off-by: Markus Armbruster Message-Id: <1453902888-20457-3-git-send-email-armbru@redhat.com> [expand scope of patch to delete rather than repair] Signed-off-by: Eric Blake Message-Id: <1454075341-13658-13-git-send-email-eblake@redhat.com> --- include/qapi/visitor-impl.h | 1 - include/qapi/visitor.h | 1 - qapi/qapi-visit-core.c | 8 +------- scripts/qapi-visit.py | 5 ----- 4 files changed, 1 insertion(+), 14 deletions(-) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 44a21b79d6..f314894f30 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -58,7 +58,6 @@ struct Visitor /* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Error **errp); bool (*start_union)(Visitor *v, bool data_present, Error **errp); - void (*end_union)(Visitor *v, bool data_present, Error **errp); }; void input_type_enum(Visitor *v, int *obj, const char * const strings[], diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index a14a16d755..83ac3ad279 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -70,6 +70,5 @@ void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp); void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp); void visit_type_any(Visitor *v, QObject **obj, const char *name, Error **errp); bool visit_start_union(Visitor *v, bool data_present, Error **errp); -void visit_end_union(Visitor *v, bool data_present, Error **errp); #endif diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 8473d3c571..060316b9b0 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -1,6 +1,7 @@ /* * Core Definitions for QAPI Visitor Classes * + * Copyright (C) 2012-2016 Red Hat, Inc. * Copyright IBM, Corp. 2011 * * Authors: @@ -67,13 +68,6 @@ bool visit_start_union(Visitor *v, bool data_present, Error **errp) return true; } -void visit_end_union(Visitor *v, bool data_present, Error **errp) -{ - if (v->end_union) { - v->end_union(v, data_present, errp); - } -} - bool visit_optional(Visitor *v, bool *present, const char *name) { if (v->optional) { diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index ec16e365a6..f98bb5f608 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -318,11 +318,6 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error abort(); } 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); From 4c40314a35816de635e7170eaacdc0c35be83a8a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:49 -0700 Subject: [PATCH 17/31] qapi: Prefer type_int64 over type_int in visitors The qapi builtin type 'int' is basically shorthand for the type 'int64'. In fact, since no visitor was providing the optional type_int64() callback, visit_type_int64() was just always falling back to type_int(), cementing the equivalence between the types. However, some visitors are providing a type_uint64() callback. For purposes of code consistency, it is nicer if all visitors use the paired type_int64/type_uint64 names rather than the mismatched type_int/type_uint64. So this patch just renames the signed int callbacks in place, dropping the type_int() callback as redundant, and a later patch will focus on the unsigned int callbacks. Add some FIXMEs to questionable reuse of errp in code touched by the rename, while at it (the reuse works as long as the callbacks don't modify value when setting an error, but it's not a good example to set) - a later patch will then fix those. No change in functionality here, although further cleanups are in the pipeline. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-14-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/visitor-impl.h | 6 ++++-- qapi/opts-visitor.c | 4 ++-- qapi/qapi-dealloc-visitor.c | 6 +++--- qapi/qapi-visit-core.c | 36 ++++++++++++++++++++++-------------- qapi/qmp-input-visitor.c | 6 +++--- qapi/qmp-output-visitor.c | 6 +++--- qapi/string-input-visitor.c | 6 +++--- qapi/string-output-visitor.c | 6 +++--- 8 files changed, 43 insertions(+), 33 deletions(-) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index f314894f30..319efe8af5 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -36,7 +36,10 @@ struct Visitor void (*get_next_type)(Visitor *v, QType *type, bool promote_int, const char *name, Error **errp); - void (*type_int)(Visitor *v, int64_t *obj, const char *name, Error **errp); + /* Must be set. */ + void (*type_int64)(Visitor *v, int64_t *obj, const char *name, + Error **errp); + /* Must be set. */ void (*type_bool)(Visitor *v, bool *obj, const char *name, Error **errp); void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp); void (*type_number)(Visitor *v, double *obj, const char *name, @@ -54,7 +57,6 @@ struct Visitor void (*type_int8)(Visitor *v, int8_t *obj, const char *name, Error **errp); void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp); void (*type_int32)(Visitor *v, int32_t *obj, const char *name, Error **errp); - void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Error **errp); /* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Error **errp); bool (*start_union)(Visitor *v, bool data_present, Error **errp); diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 4955ac833f..14db02c923 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -361,7 +361,7 @@ opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) static void -opts_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) +opts_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; @@ -529,7 +529,7 @@ opts_visitor_new(const QemuOpts *opts) */ ov->visitor.type_enum = &input_type_enum; - ov->visitor.type_int = &opts_type_int; + ov->visitor.type_int64 = &opts_type_int64; ov->visitor.type_uint64 = &opts_type_uint64; ov->visitor.type_size = &opts_type_size; ov->visitor.type_bool = &opts_type_bool; diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index c805a7a87d..07d7337b79 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -136,8 +136,8 @@ static void qapi_dealloc_type_str(Visitor *v, char **obj, const char *name, } } -static void qapi_dealloc_type_int(Visitor *v, int64_t *obj, const char *name, - Error **errp) +static void qapi_dealloc_type_int64(Visitor *v, int64_t *obj, const char *name, + Error **errp) { } @@ -215,7 +215,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.next_list = qapi_dealloc_next_list; v->visitor.end_list = qapi_dealloc_end_list; v->visitor.type_enum = qapi_dealloc_type_enum; - v->visitor.type_int = qapi_dealloc_type_int; + v->visitor.type_int64 = qapi_dealloc_type_int64; v->visitor.type_bool = qapi_dealloc_type_bool; v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 060316b9b0..2446a1287b 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -92,7 +92,7 @@ void visit_type_enum(Visitor *v, int *obj, const char * const strings[], void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) { - v->type_int(v, obj, name, errp); + v->type_int64(v, obj, name, errp); } void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp) @@ -103,8 +103,10 @@ void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp) v->type_uint8(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); if (value < 0 || value > UINT8_MAX) { + /* FIXME questionable reuse of errp if callback changed + value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "uint8_t"); return; @@ -121,8 +123,10 @@ void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp v->type_uint16(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); if (value < 0 || value > UINT16_MAX) { + /* FIXME questionable reuse of errp if callback changed + value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "uint16_t"); return; @@ -139,8 +143,10 @@ void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp v->type_uint32(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); if (value < 0 || value > UINT32_MAX) { + /* FIXME questionable reuse of errp if callback changed + value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "uint32_t"); return; @@ -157,7 +163,7 @@ void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp v->type_uint64(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); *obj = value; } } @@ -170,8 +176,10 @@ void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp) v->type_int8(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); if (value < INT8_MIN || value > INT8_MAX) { + /* FIXME questionable reuse of errp if callback changed + value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "int8_t"); return; @@ -188,8 +196,10 @@ void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp) v->type_int16(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); if (value < INT16_MIN || value > INT16_MAX) { + /* FIXME questionable reuse of errp if callback changed + value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "int16_t"); return; @@ -206,8 +216,10 @@ void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp) v->type_int32(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); if (value < INT32_MIN || value > INT32_MAX) { + /* FIXME questionable reuse of errp if callback changed + value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "int32_t"); return; @@ -218,11 +230,7 @@ void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp) void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp) { - if (v->type_int64) { - v->type_int64(v, obj, name, errp); - } else { - v->type_int(v, obj, name, errp); - } + v->type_int64(v, obj, name, errp); } void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) @@ -235,7 +243,7 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) v->type_uint64(v, obj, name, errp); } else { value = *obj; - v->type_int(v, &value, name, errp); + v->type_int64(v, &value, name, errp); *obj = value; } } diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index edb8bd2d68..d1668e343f 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -225,8 +225,8 @@ static void qmp_input_get_next_type(Visitor *v, QType *type, bool promote_int, } } -static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name, - Error **errp) +static void qmp_input_type_int64(Visitor *v, int64_t *obj, const char *name, + Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QInt *qint = qobject_to_qint(qmp_input_get_object(qiv, name, true)); @@ -342,7 +342,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj) v->visitor.next_list = qmp_input_next_list; v->visitor.end_list = qmp_input_end_list; v->visitor.type_enum = input_type_enum; - v->visitor.type_int = qmp_input_type_int; + v->visitor.type_int64 = qmp_input_type_int64; v->visitor.type_bool = qmp_input_type_bool; v->visitor.type_str = qmp_input_type_str; v->visitor.type_number = qmp_input_type_number; diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index b064fb5a91..a13cf9154d 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -159,8 +159,8 @@ static void qmp_output_end_list(Visitor *v, Error **errp) qmp_output_pop(qov); } -static void qmp_output_type_int(Visitor *v, int64_t *obj, const char *name, - Error **errp) +static void qmp_output_type_int64(Visitor *v, int64_t *obj, const char *name, + Error **errp) { QmpOutputVisitor *qov = to_qov(v); qmp_output_add(qov, name, qint_from_int(*obj)); @@ -242,7 +242,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void) v->visitor.next_list = qmp_output_next_list; v->visitor.end_list = qmp_output_end_list; v->visitor.type_enum = output_type_enum; - v->visitor.type_int = qmp_output_type_int; + v->visitor.type_int64 = qmp_output_type_int64; v->visitor.type_bool = qmp_output_type_bool; v->visitor.type_str = qmp_output_type_str; v->visitor.type_number = qmp_output_type_number; diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 52db4cf32b..ffe8cb2f3d 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -185,8 +185,8 @@ end_list(Visitor *v, Error **errp) siv->head = true; } -static void parse_type_int(Visitor *v, int64_t *obj, const char *name, - Error **errp) +static void parse_type_int64(Visitor *v, int64_t *obj, const char *name, + Error **errp) { StringInputVisitor *siv = to_siv(v); @@ -336,7 +336,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v = g_malloc0(sizeof(*v)); v->visitor.type_enum = input_type_enum; - v->visitor.type_int = parse_type_int; + v->visitor.type_int64 = parse_type_int64; v->visitor.type_size = parse_type_size; v->visitor.type_bool = parse_type_bool; v->visitor.type_str = parse_type_str; diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index b0313cb53a..cf8dfc8b48 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -122,8 +122,8 @@ static void format_string(StringOutputVisitor *sov, Range *r, bool next, } } -static void print_type_int(Visitor *v, int64_t *obj, const char *name, - Error **errp) +static void print_type_int64(Visitor *v, int64_t *obj, const char *name, + Error **errp) { StringOutputVisitor *sov = to_sov(v); GList *l; @@ -346,7 +346,7 @@ StringOutputVisitor *string_output_visitor_new(bool human) v->string = g_string_new(NULL); v->human = human; v->visitor.type_enum = output_type_enum; - v->visitor.type_int = print_type_int; + v->visitor.type_int64 = print_type_int64; v->visitor.type_size = print_type_size; v->visitor.type_bool = print_type_bool; v->visitor.type_str = print_type_str; From f755dea79dc81b0d6a8f6414e0672e165e28d8ba Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:50 -0700 Subject: [PATCH 18/31] qapi: Make all visitors supply uint64 callbacks Our qapi visitor contract supports multiple integer visitors, but left the type_uint64 visitor as optional (falling back on type_int64); which in turn can lead to awkward behavior with numbers larger than INT64_MAX (the user has to be aware of twos complement, and deal with negatives). This patch does not address the disparity in handling large values as negatives. It merely moves the fallback from uint64 to int64 from the visitor core to the visitors, where the issue can actually be fixed, by implementing the missing type_uint64() callbacks on top of the respective type_int64() callbacks, and with a FIXME comment explaining why that's wrong. With that done, we now have a type_uint64() callback in every driver, so we can make it mandatory from the core. And although the type_int64() callback can cover the entire valid range of type_uint{8,16,32} on valid user input, using type_uint64() to avoid mixed signedness makes more sense. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-15-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/visitor-impl.h | 9 ++++++--- qapi/qapi-dealloc-visitor.c | 6 ++++++ qapi/qapi-visit-core.c | 36 +++++++++++------------------------- qapi/qmp-input-visitor.c | 17 +++++++++++++++++ qapi/qmp-output-visitor.c | 9 +++++++++ qapi/string-input-visitor.c | 15 +++++++++++++++ qapi/string-output-visitor.c | 9 +++++++++ 7 files changed, 73 insertions(+), 28 deletions(-) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 319efe8af5..92c4bcbb90 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -40,6 +40,12 @@ struct Visitor void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Error **errp); /* Must be set. */ + void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name, + Error **errp); + /* Optional; fallback is type_uint64(). */ + void (*type_size)(Visitor *v, uint64_t *obj, const char *name, + Error **errp); + /* Must be set. */ void (*type_bool)(Visitor *v, bool *obj, const char *name, Error **errp); void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp); void (*type_number)(Visitor *v, double *obj, const char *name, @@ -53,12 +59,9 @@ struct Visitor void (*type_uint8)(Visitor *v, uint8_t *obj, const char *name, Error **errp); void (*type_uint16)(Visitor *v, uint16_t *obj, const char *name, Error **errp); void (*type_uint32)(Visitor *v, uint32_t *obj, const char *name, Error **errp); - void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name, Error **errp); void (*type_int8)(Visitor *v, int8_t *obj, const char *name, Error **errp); void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp); void (*type_int32)(Visitor *v, int32_t *obj, const char *name, Error **errp); - /* visit_type_size() falls back to (*type_uint64)() if type_size is unset */ - void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Error **errp); bool (*start_union)(Visitor *v, bool data_present, Error **errp); }; diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index 07d7337b79..2c257d8b48 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -141,6 +141,11 @@ static void qapi_dealloc_type_int64(Visitor *v, int64_t *obj, const char *name, { } +static void qapi_dealloc_type_uint64(Visitor *v, uint64_t *obj, + const char *name, Error **errp) +{ +} + static void qapi_dealloc_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { @@ -216,6 +221,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.end_list = qapi_dealloc_end_list; v->visitor.type_enum = qapi_dealloc_type_enum; v->visitor.type_int64 = qapi_dealloc_type_int64; + v->visitor.type_uint64 = qapi_dealloc_type_uint64; v->visitor.type_bool = qapi_dealloc_type_bool; v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 2446a1287b..afcd59be9a 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -97,14 +97,14 @@ void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp) { - int64_t value; + uint64_t value; if (v->type_uint8) { v->type_uint8(v, obj, name, errp); } else { value = *obj; - v->type_int64(v, &value, name, errp); - if (value < 0 || value > UINT8_MAX) { + v->type_uint64(v, &value, name, errp); + if (value > UINT8_MAX) { /* FIXME questionable reuse of errp if callback changed value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, @@ -117,14 +117,14 @@ void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp) void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp) { - int64_t value; + uint64_t value; if (v->type_uint16) { v->type_uint16(v, obj, name, errp); } else { value = *obj; - v->type_int64(v, &value, name, errp); - if (value < 0 || value > UINT16_MAX) { + v->type_uint64(v, &value, name, errp); + if (value > UINT16_MAX) { /* FIXME questionable reuse of errp if callback changed value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, @@ -137,14 +137,14 @@ void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp) { - int64_t value; + uint64_t value; if (v->type_uint32) { v->type_uint32(v, obj, name, errp); } else { value = *obj; - v->type_int64(v, &value, name, errp); - if (value < 0 || value > UINT32_MAX) { + v->type_uint64(v, &value, name, errp); + if (value > UINT32_MAX) { /* FIXME questionable reuse of errp if callback changed value on error */ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, @@ -157,15 +157,7 @@ void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) { - int64_t value; - - if (v->type_uint64) { - v->type_uint64(v, obj, name, errp); - } else { - value = *obj; - v->type_int64(v, &value, name, errp); - *obj = value; - } + v->type_uint64(v, obj, name, errp); } void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp) @@ -235,16 +227,10 @@ void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp) void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) { - int64_t value; - if (v->type_size) { v->type_size(v, obj, name, errp); - } else if (v->type_uint64) { - v->type_uint64(v, obj, name, errp); } else { - value = *obj; - v->type_int64(v, &value, name, errp); - *obj = value; + v->type_uint64(v, obj, name, errp); } } diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index d1668e343f..5eb67dfc30 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -240,6 +240,22 @@ static void qmp_input_type_int64(Visitor *v, int64_t *obj, const char *name, *obj = qint_get_int(qint); } +static void qmp_input_type_uint64(Visitor *v, uint64_t *obj, const char *name, + Error **errp) +{ + /* FIXME: qobject_to_qint mishandles values over INT64_MAX */ + QmpInputVisitor *qiv = to_qiv(v); + QInt *qint = qobject_to_qint(qmp_input_get_object(qiv, name, true)); + + if (!qint) { + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", + "integer"); + return; + } + + *obj = qint_get_int(qint); +} + static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { @@ -343,6 +359,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj) v->visitor.end_list = qmp_input_end_list; v->visitor.type_enum = input_type_enum; v->visitor.type_int64 = qmp_input_type_int64; + v->visitor.type_uint64 = qmp_input_type_uint64; v->visitor.type_bool = qmp_input_type_bool; v->visitor.type_str = qmp_input_type_str; v->visitor.type_number = qmp_input_type_number; diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index a13cf9154d..8a24a00309 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -166,6 +166,14 @@ static void qmp_output_type_int64(Visitor *v, int64_t *obj, const char *name, qmp_output_add(qov, name, qint_from_int(*obj)); } +static void qmp_output_type_uint64(Visitor *v, uint64_t *obj, const char *name, + Error **errp) +{ + /* FIXME: QMP outputs values larger than INT64_MAX as negative */ + QmpOutputVisitor *qov = to_qov(v); + qmp_output_add(qov, name, qint_from_int(*obj)); +} + static void qmp_output_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) { @@ -243,6 +251,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void) v->visitor.end_list = qmp_output_end_list; v->visitor.type_enum = output_type_enum; v->visitor.type_int64 = qmp_output_type_int64; + v->visitor.type_uint64 = qmp_output_type_uint64; v->visitor.type_bool = qmp_output_type_bool; v->visitor.type_str = qmp_output_type_str; v->visitor.type_number = qmp_output_type_number; diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index ffe8cb2f3d..4c2344771b 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -227,6 +227,20 @@ error: "an int64 value or range"); } +static void parse_type_uint64(Visitor *v, uint64_t *obj, const char *name, + Error **errp) +{ + /* FIXME: parse_type_int64 mishandles values over INT64_MAX */ + int64_t i; + Error *err = NULL; + parse_type_int64(v, &i, name, &err); + if (err) { + error_propagate(errp, err); + } else { + *obj = i; + } +} + static void parse_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) { @@ -337,6 +351,7 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.type_enum = input_type_enum; v->visitor.type_int64 = parse_type_int64; + v->visitor.type_uint64 = parse_type_uint64; v->visitor.type_size = parse_type_size; v->visitor.type_bool = parse_type_bool; v->visitor.type_str = parse_type_str; diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index cf8dfc8b48..8400c8beeb 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -198,6 +198,14 @@ static void print_type_int64(Visitor *v, int64_t *obj, const char *name, } } +static void print_type_uint64(Visitor *v, uint64_t *obj, const char *name, + Error **errp) +{ + /* FIXME: print_type_int64 mishandles values over INT64_MAX */ + int64_t i = *obj; + print_type_int64(v, &i, name, errp); +} + static void print_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) { @@ -347,6 +355,7 @@ StringOutputVisitor *string_output_visitor_new(bool human) v->human = human; v->visitor.type_enum = output_type_enum; v->visitor.type_int64 = print_type_int64; + v->visitor.type_uint64 = print_type_uint64; v->visitor.type_size = print_type_size; v->visitor.type_bool = print_type_bool; v->visitor.type_str = print_type_str; From 04e070d217b4414f1f91aa8ad25fc0ae7ca0be93 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:51 -0700 Subject: [PATCH 19/31] qapi: Consolidate visitor small integer callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 4e27e819 introduced optional visitor callbacks for all sorts of int types, but no visitor has supplied any of the callbacks for sizes less than 64 bits. In other words, the generic implementation based on using type_[u]int64() followed by bounds-checking works just fine. In the interest of simplicity, it's easier to make the visitor callback interface not have to worry about the other sizes. Adding some helper functions minimizes the boilerplate required to correct FIXMEs added earlier with regards to questionable reuse of errp, particularly now that we can guarantee from a single file audit that value is unchanged if an error is set. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-16-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/visitor-impl.h | 8 +- qapi/qapi-visit-core.c | 152 +++++++++++++----------------------- 2 files changed, 57 insertions(+), 103 deletions(-) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 92c4bcbb90..29e2c087fe 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -1,7 +1,7 @@ /* * Core Definitions for QAPI Visitor implementations * - * Copyright (C) 2012 Red Hat, Inc. + * Copyright (C) 2012-2016 Red Hat, Inc. * * Author: Paolo Bonizni * @@ -56,12 +56,6 @@ struct Visitor /* May be NULL; most useful for input visitors. */ void (*optional)(Visitor *v, bool *present, const char *name); - void (*type_uint8)(Visitor *v, uint8_t *obj, const char *name, Error **errp); - void (*type_uint16)(Visitor *v, uint16_t *obj, const char *name, Error **errp); - void (*type_uint32)(Visitor *v, uint32_t *obj, const char *name, Error **errp); - void (*type_int8)(Visitor *v, int8_t *obj, const char *name, Error **errp); - void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp); - void (*type_int32)(Visitor *v, int32_t *obj, const char *name, Error **errp); bool (*start_union)(Visitor *v, bool data_present, Error **errp); }; diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index afcd59be9a..7228dc2350 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -95,129 +95,89 @@ void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) v->type_int64(v, obj, name, errp); } +static void visit_type_uintN(Visitor *v, uint64_t *obj, const char *name, + uint64_t max, const char *type, Error **errp) +{ + Error *err = NULL; + uint64_t value = *obj; + + v->type_uint64(v, &value, name, &err); + if (err) { + error_propagate(errp, err); + } else if (value > max) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", type); + } else { + *obj = value; + } +} + void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp) { - uint64_t value; - - if (v->type_uint8) { - v->type_uint8(v, obj, name, errp); - } else { - value = *obj; - v->type_uint64(v, &value, name, errp); - if (value > UINT8_MAX) { - /* FIXME questionable reuse of errp if callback changed - value on error */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "uint8_t"); - return; - } - *obj = value; - } + uint64_t value = *obj; + visit_type_uintN(v, &value, name, UINT8_MAX, "uint8_t", errp); + *obj = value; } -void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp) +void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, + Error **errp) { - uint64_t value; - - if (v->type_uint16) { - v->type_uint16(v, obj, name, errp); - } else { - value = *obj; - v->type_uint64(v, &value, name, errp); - if (value > UINT16_MAX) { - /* FIXME questionable reuse of errp if callback changed - value on error */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "uint16_t"); - return; - } - *obj = value; - } + uint64_t value = *obj; + visit_type_uintN(v, &value, name, UINT16_MAX, "uint16_t", errp); + *obj = value; } -void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp) +void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, + Error **errp) { - uint64_t value; - - if (v->type_uint32) { - v->type_uint32(v, obj, name, errp); - } else { - value = *obj; - v->type_uint64(v, &value, name, errp); - if (value > UINT32_MAX) { - /* FIXME questionable reuse of errp if callback changed - value on error */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "uint32_t"); - return; - } - *obj = value; - } + uint64_t value = *obj; + visit_type_uintN(v, &value, name, UINT32_MAX, "uint32_t", errp); + *obj = value; } -void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) +void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, + Error **errp) { v->type_uint64(v, obj, name, errp); } -void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp) +static void visit_type_intN(Visitor *v, int64_t *obj, const char *name, + int64_t min, int64_t max, const char *type, + Error **errp) { - int64_t value; + Error *err = NULL; + int64_t value = *obj; - if (v->type_int8) { - v->type_int8(v, obj, name, errp); + v->type_int64(v, &value, name, &err); + if (err) { + error_propagate(errp, err); + } else if (value < min || value > max) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + name ? name : "null", type); } else { - value = *obj; - v->type_int64(v, &value, name, errp); - if (value < INT8_MIN || value > INT8_MAX) { - /* FIXME questionable reuse of errp if callback changed - value on error */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "int8_t"); - return; - } *obj = value; } } +void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp) +{ + int64_t value = *obj; + visit_type_intN(v, &value, name, INT8_MIN, INT8_MAX, "int8_t", errp); + *obj = value; +} + void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp) { - int64_t value; - - if (v->type_int16) { - v->type_int16(v, obj, name, errp); - } else { - value = *obj; - v->type_int64(v, &value, name, errp); - if (value < INT16_MIN || value > INT16_MAX) { - /* FIXME questionable reuse of errp if callback changed - value on error */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "int16_t"); - return; - } - *obj = value; - } + int64_t value = *obj; + visit_type_intN(v, &value, name, INT16_MIN, INT16_MAX, "int16_t", errp); + *obj = value; } void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp) { - int64_t value; - - if (v->type_int32) { - v->type_int32(v, obj, name, errp); - } else { - value = *obj; - v->type_int64(v, &value, name, errp); - if (value < INT32_MIN || value > INT32_MAX) { - /* FIXME questionable reuse of errp if callback changed - value on error */ - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - name ? name : "null", "int32_t"); - return; - } - *obj = value; - } + int64_t value = *obj; + visit_type_intN(v, &value, name, INT32_MIN, INT32_MAX, "int32_t", errp); + *obj = value; } void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp) From 395a233f7c089f23e3c0d43ce34c709dc5acd7de Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:52 -0700 Subject: [PATCH 20/31] qapi: Don't cast Enum* to int* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C compilers are allowed to represent enums as a smaller type than int, if all enum values fit in the smaller type. There are even compiler flags that force the use of this smaller representation, although using them changes the ABI of a binary. Therefore, our generated code for visit_type_ENUM() (for all qapi enums) was wrong for casting Enum* to int* when calling visit_type_enum(). It appears that no one has been using compiler ABI switches for qemu, because if they had, we are potentially dereferencing beyond bounds or even risking a SIGBUS on platforms where unaligned pointer dereferencing is fatal. But it is still better to avoid the practice entirely, and just use the correct types. This matches the fix for alternate qapi types, done earlier in commit 0426d53 "qapi: Simplify visiting of alternate types", with generated code changing as: | void visit_type_QType(Visitor *v, QType *obj, const char *name, Error **errp) | { |- visit_type_enum(v, (int *)obj, QType_lookup, "QType", name, errp); |+ int value = *obj; |+ visit_type_enum(v, &value, QType_lookup, "QType", name, errp); |+ *obj = value; | } Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-17-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi-visit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index f98bb5f608..ba75667e03 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -178,12 +178,13 @@ 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) { - visit_type_enum(v, (int *)obj, %(c_name)s_lookup, "%(name)s", name, errp); + int value = *obj; + visit_type_enum(v, &value, %(c_name)s_lookup, "%(name)s", name, errp); + *obj = value; } ''', c_name=c_name(name), name=name) From 4fa45492c3387c0fa51e8e81160ac9a7814f44a2 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:53 -0700 Subject: [PATCH 21/31] qom: Use typedef for Visitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to repeat 'struct Visitor' when we already have it in typedefs.h. Omitting the redundant 'struct' also makes a later patch easier to search for all object property callbacks that are associated with a Visitor. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-18-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- hw/misc/edu.c | 4 ++-- hw/virtio/virtio-balloon.c | 6 +++--- include/qom/object.h | 9 ++++----- qom/object.c | 4 ++-- target-i386/cpu.c | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/hw/misc/edu.c b/hw/misc/edu.c index 2639c64253..65e8f20e85 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -363,8 +363,8 @@ static void pci_edu_uninit(PCIDevice *pdev) timer_del(&edu->dma_timer); } -static void edu_obj_uint64(Object *obj, struct Visitor *v, void *opaque, - const char *name, Error **errp) +static void edu_obj_uint64(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) { uint64_t *val = opaque; diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 06912bbe6d..7d05d3fc96 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -113,7 +113,7 @@ static void balloon_stats_poll_cb(void *opaque) s->stats_vq_elem = NULL; } -static void balloon_stats_get_all(Object *obj, struct Visitor *v, +static void balloon_stats_get_all(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { Error *err = NULL; @@ -151,7 +151,7 @@ out: error_propagate(errp, err); } -static void balloon_stats_get_poll_interval(Object *obj, struct Visitor *v, +static void balloon_stats_get_poll_interval(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { @@ -159,7 +159,7 @@ static void balloon_stats_get_poll_interval(Object *obj, struct Visitor *v, visit_type_int(v, &s->stats_poll_interval, name, errp); } -static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v, +static void balloon_stats_set_poll_interval(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { diff --git a/include/qom/object.h b/include/qom/object.h index d0dafe986c..3e7e99dff1 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -18,10 +18,9 @@ #include #include #include "qemu/queue.h" +#include "qemu/typedefs.h" #include "qapi/error.h" -struct Visitor; - struct TypeImpl; typedef struct TypeImpl *Type; @@ -298,7 +297,7 @@ typedef struct InterfaceInfo InterfaceInfo; * Called when trying to get/set a property. */ typedef void (ObjectPropertyAccessor)(Object *obj, - struct Visitor *v, + Visitor *v, void *opaque, const char *name, Error **errp); @@ -1025,7 +1024,7 @@ void object_unparent(Object *obj); * * Reads a property from a object. */ -void object_property_get(Object *obj, struct Visitor *v, const char *name, +void object_property_get(Object *obj, Visitor *v, const char *name, Error **errp); /** @@ -1161,7 +1160,7 @@ void object_property_get_uint16List(Object *obj, const char *name, * * Writes a property to a object. */ -void object_property_set(Object *obj, struct Visitor *v, const char *name, +void object_property_set(Object *obj, Visitor *v, const char *name, Error **errp); /** diff --git a/qom/object.c b/qom/object.c index 5904081ba9..3506a98803 100644 --- a/qom/object.c +++ b/qom/object.c @@ -2185,7 +2185,7 @@ typedef struct { char *target_name; } AliasProperty; -static void property_get_alias(Object *obj, struct Visitor *v, void *opaque, +static void property_get_alias(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { AliasProperty *prop = opaque; @@ -2193,7 +2193,7 @@ static void property_get_alias(Object *obj, struct Visitor *v, void *opaque, object_property_get(prop->target_obj, v, prop->target_name, errp); } -static void property_set_alias(Object *obj, struct Visitor *v, void *opaque, +static void property_set_alias(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { AliasProperty *prop = opaque; diff --git a/target-i386/cpu.c b/target-i386/cpu.c index b2556441cc..60bfa80a70 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2945,7 +2945,7 @@ typedef struct BitProperty { } BitProperty; static void x86_cpu_get_bit_prop(Object *obj, - struct Visitor *v, + Visitor *v, void *opaque, const char *name, Error **errp) @@ -2956,7 +2956,7 @@ static void x86_cpu_get_bit_prop(Object *obj, } static void x86_cpu_set_bit_prop(Object *obj, - struct Visitor *v, + Visitor *v, void *opaque, const char *name, Error **errp) From 51e72bc1dd6ace6e91d675f41a1f09bd00ab8043 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:54 -0700 Subject: [PATCH 22/31] qapi: Swap visit_* arguments for consistent 'name' placement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JSON uses "name":value, but many of our visitor interfaces were called with visit_type_FOO(v, &value, name, errp). This can be a bit confusing to have to mentally swap the parameter order to match JSON order. It's particularly bad for visit_start_struct(), where the 'name' parameter is smack in the middle of the otherwise-related group of 'obj, kind, size' parameters! It's time to do a global swap of the parameter ordering, so that the 'name' parameter is always immediately after the Visitor argument. Additional reason in favor of the swap: the existing include/qjson.h prefers listing 'name' first in json_prop_*(), and I have plans to unify that file with the qapi visitors; listing 'name' first in qapi will minimize churn to the (admittedly few) qjson.h clients. Later patches will then fix docs, object.h, visitor-impl.h, and those clients to match. Done by first patching scripts/qapi*.py by hand to make generated files do what I want, then by running the following Coccinelle script to affect the rest of the code base: $ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'` I then had to apply some touchups (Coccinelle insisted on TAB indentation in visitor.h, and botched the signature of visit_type_enum() by rewriting 'const char *const strings[]' to the syntactically invalid 'const char*const[] strings'). The movement of parameters is sufficient to provoke compiler errors if any callers were missed. // Part 1: Swap declaration order @@ type TV, TErr, TObj, T1, T2; identifier OBJ, ARG1, ARG2; @@ void visit_start_struct -(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp) +(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp) { ... } @@ type bool, TV, T1; identifier ARG1; @@ bool visit_optional -(TV v, T1 ARG1, const char *name) +(TV v, const char *name, T1 ARG1) { ... } @@ type TV, TErr, TObj, T1; identifier OBJ, ARG1; @@ void visit_get_next_type -(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp) +(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp) { ... } @@ type TV, TErr, TObj, T1, T2; identifier OBJ, ARG1, ARG2; @@ void visit_type_enum -(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp) +(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp) { ... } @@ type TV, TErr, TObj; identifier OBJ; identifier VISIT_TYPE =~ "^visit_type_"; @@ void VISIT_TYPE -(TV v, TObj OBJ, const char *name, TErr errp) +(TV v, const char *name, TObj OBJ, TErr errp) { ... } // Part 2: swap caller order @@ expression V, NAME, OBJ, ARG1, ARG2, ERR; identifier VISIT_TYPE =~ "^visit_type_"; @@ ( -visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR) +visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR) | -visit_optional(V, ARG1, NAME) +visit_optional(V, NAME, ARG1) | -visit_get_next_type(V, OBJ, ARG1, NAME, ERR) +visit_get_next_type(V, NAME, OBJ, ARG1, ERR) | -visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR) +visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR) | -VISIT_TYPE(V, OBJ, NAME, ERR) +VISIT_TYPE(V, NAME, OBJ, ERR) ) Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- backends/hostmem.c | 8 +-- block/qapi.c | 2 +- blockdev.c | 4 +- bootdevice.c | 4 +- hmp.c | 8 +-- hw/acpi/core.c | 4 +- hw/acpi/ich9.c | 14 +++--- hw/core/machine.c | 10 ++-- hw/core/qdev-properties-system.c | 12 ++--- hw/core/qdev-properties.c | 66 ++++++++++++------------ hw/core/qdev.c | 2 +- hw/i386/pc.c | 14 +++--- hw/ide/qdev.c | 4 +- hw/intc/xics.c | 8 +-- hw/isa/lpc_ich9.c | 2 +- hw/mem/pc-dimm.c | 2 +- hw/misc/edu.c | 2 +- hw/misc/tmp105.c | 4 +- hw/net/ne2000-isa.c | 4 +- hw/pci-host/piix.c | 8 +-- hw/pci-host/q35.c | 10 ++-- hw/ppc/spapr_drc.c | 12 ++--- hw/usb/dev-storage.c | 4 +- hw/virtio/virtio-balloon.c | 12 ++--- include/qapi/visitor.h | 52 +++++++++++-------- memory.c | 8 +-- net/dump.c | 4 +- net/filter-buffer.c | 4 +- net/net.c | 4 +- numa.c | 6 +-- qapi/qapi-visit-core.c | 54 +++++++++++--------- qemu-img.c | 11 ++-- qom/object.c | 49 +++++++++--------- replay/replay-input.c | 4 +- scripts/qapi-commands.py | 4 +- scripts/qapi-event.py | 2 +- scripts/qapi-types.py | 2 +- scripts/qapi-visit.py | 28 +++++------ scripts/qapi.py | 4 +- target-i386/cpu.c | 30 +++++------ target-ppc/translate_init.c | 4 +- tests/test-opts-visitor.c | 6 +-- tests/test-qdev-global-props.c | 4 +- tests/test-qmp-commands.c | 2 +- tests/test-qmp-input-strict.c | 28 +++++------ tests/test-qmp-input-visitor.c | 80 +++++++++++++++--------------- tests/test-qmp-output-visitor.c | 34 ++++++------- tests/test-string-input-visitor.c | 34 ++++++------- tests/test-string-output-visitor.c | 16 +++--- tests/test-visitor-serialization.c | 54 ++++++++++---------- util/qemu-sockets.c | 4 +- vl.c | 4 +- 52 files changed, 385 insertions(+), 371 deletions(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index 60e882c628..da80662fcd 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -33,7 +33,7 @@ host_memory_backend_get_size(Object *obj, Visitor *v, void *opaque, HostMemoryBackend *backend = MEMORY_BACKEND(obj); uint64_t value = backend->size; - visit_type_size(v, &value, name, errp); + visit_type_size(v, name, &value, errp); } static void @@ -49,7 +49,7 @@ host_memory_backend_set_size(Object *obj, Visitor *v, void *opaque, goto out; } - visit_type_size(v, &value, name, &local_err); + visit_type_size(v, name, &value, &local_err); if (local_err) { goto out; } @@ -92,7 +92,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, void *opaque, node = &(*node)->next; } while (true); - visit_type_uint16List(v, &host_nodes, name, errp); + visit_type_uint16List(v, name, &host_nodes, errp); } static void @@ -103,7 +103,7 @@ host_memory_backend_set_host_nodes(Object *obj, Visitor *v, void *opaque, HostMemoryBackend *backend = MEMORY_BACKEND(obj); uint16List *l = NULL; - visit_type_uint16List(v, &l, name, errp); + visit_type_uint16List(v, name, &l, errp); while (l) { bitmap_set(backend->host_nodes, l->value, 1); diff --git a/block/qapi.c b/block/qapi.c index 2e8310591d..67891b7d19 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -641,7 +641,7 @@ void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f, QmpOutputVisitor *ov = qmp_output_visitor_new(); QObject *obj, *data; - visit_type_ImageInfoSpecific(qmp_output_get_visitor(ov), &info_spec, NULL, + visit_type_ImageInfoSpecific(qmp_output_get_visitor(ov), NULL, &info_spec, &error_abort); obj = qmp_output_get_qobject(ov); assert(qobject_type(obj) == QTYPE_QDICT); diff --git a/blockdev.c b/blockdev.c index e1b6b0f0e1..1f7347821c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3860,8 +3860,8 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp) } } - visit_type_BlockdevOptions(qmp_output_get_visitor(ov), - &options, NULL, &local_err); + visit_type_BlockdevOptions(qmp_output_get_visitor(ov), NULL, &options, + &local_err); if (local_err) { error_propagate(errp, local_err); goto fail; diff --git a/bootdevice.c b/bootdevice.c index 1ee7b117de..149ee3aaf0 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -275,7 +275,7 @@ static void device_get_bootindex(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { BootIndexProperty *prop = opaque; - visit_type_int32(v, prop->bootindex, name, errp); + visit_type_int32(v, name, prop->bootindex, errp); } static void device_set_bootindex(Object *obj, Visitor *v, void *opaque, @@ -285,7 +285,7 @@ static void device_set_bootindex(Object *obj, Visitor *v, void *opaque, int32_t boot_index; Error *local_err = NULL; - visit_type_int32(v, &boot_index, name, &local_err); + visit_type_int32(v, name, &boot_index, &local_err); if (local_err) { goto out; } diff --git a/hmp.c b/hmp.c index 6a49886138..27d6867664 100644 --- a/hmp.c +++ b/hmp.c @@ -1676,13 +1676,13 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) } qdict_del(pdict, "qom-type"); - visit_type_str(v, &type, "qom-type", &err); + visit_type_str(v, "qom-type", &type, &err); if (err) { goto out_end; } qdict_del(pdict, "id"); - visit_type_str(v, &id, "id", &err); + visit_type_str(v, "id", &id, &err); if (err) { goto out_end; } @@ -1948,8 +1948,8 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) while (m) { ov = string_output_visitor_new(false); - visit_type_uint16List(string_output_get_visitor(ov), - &m->value->host_nodes, NULL, NULL); + visit_type_uint16List(string_output_get_visitor(ov), NULL, + &m->value->host_nodes, NULL); monitor_printf(mon, "memory backend: %d\n", i); monitor_printf(mon, " size: %" PRId64 "\n", m->value->size); monitor_printf(mon, " merge: %s\n", diff --git a/hw/acpi/core.c b/hw/acpi/core.c index edf3f960a7..3a14e90cd0 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -243,7 +243,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp) OptsVisitor *ov; ov = opts_visitor_new(opts); - visit_type_AcpiTableOptions(opts_get_visitor(ov), &hdrs, NULL, &err); + visit_type_AcpiTableOptions(opts_get_visitor(ov), NULL, &hdrs, &err); opts_visitor_cleanup(ov); } @@ -302,7 +302,7 @@ out: QapiDeallocVisitor *dv; dv = qapi_dealloc_visitor_new(); - visit_type_AcpiTableOptions(qapi_dealloc_get_visitor(dv), &hdrs, NULL, + visit_type_AcpiTableOptions(qapi_dealloc_get_visitor(dv), NULL, &hdrs, NULL); qapi_dealloc_visitor_cleanup(dv); } diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c index 746d8901e4..c3b6035f34 100644 --- a/hw/acpi/ich9.c +++ b/hw/acpi/ich9.c @@ -290,7 +290,7 @@ static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v, ICH9LPCPMRegs *pm = opaque; uint32_t value = pm->pm_io_base + ICH9_PMIO_GPE0_STS; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static bool ich9_pm_get_memory_hotplug_support(Object *obj, Error **errp) @@ -315,7 +315,7 @@ static void ich9_pm_get_disable_s3(Object *obj, Visitor *v, ICH9LPCPMRegs *pm = opaque; uint8_t value = pm->disable_s3; - visit_type_uint8(v, &value, name, errp); + visit_type_uint8(v, name, &value, errp); } static void ich9_pm_set_disable_s3(Object *obj, Visitor *v, @@ -326,7 +326,7 @@ static void ich9_pm_set_disable_s3(Object *obj, Visitor *v, Error *local_err = NULL; uint8_t value; - visit_type_uint8(v, &value, name, &local_err); + visit_type_uint8(v, name, &value, &local_err); if (local_err) { goto out; } @@ -342,7 +342,7 @@ static void ich9_pm_get_disable_s4(Object *obj, Visitor *v, ICH9LPCPMRegs *pm = opaque; uint8_t value = pm->disable_s4; - visit_type_uint8(v, &value, name, errp); + visit_type_uint8(v, name, &value, errp); } static void ich9_pm_set_disable_s4(Object *obj, Visitor *v, @@ -353,7 +353,7 @@ static void ich9_pm_set_disable_s4(Object *obj, Visitor *v, Error *local_err = NULL; uint8_t value; - visit_type_uint8(v, &value, name, &local_err); + visit_type_uint8(v, name, &value, &local_err); if (local_err) { goto out; } @@ -369,7 +369,7 @@ static void ich9_pm_get_s4_val(Object *obj, Visitor *v, ICH9LPCPMRegs *pm = opaque; uint8_t value = pm->s4_val; - visit_type_uint8(v, &value, name, errp); + visit_type_uint8(v, name, &value, errp); } static void ich9_pm_set_s4_val(Object *obj, Visitor *v, @@ -380,7 +380,7 @@ static void ich9_pm_set_s4_val(Object *obj, Visitor *v, Error *local_err = NULL; uint8_t value; - visit_type_uint8(v, &value, name, &local_err); + visit_type_uint8(v, name, &value, &local_err); if (local_err) { goto out; } diff --git a/hw/core/machine.c b/hw/core/machine.c index 1261368add..03d9a951b2 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -41,7 +41,7 @@ static void machine_set_kernel_irqchip(Object *obj, Visitor *v, MachineState *ms = MACHINE(obj); OnOffSplit mode; - visit_type_OnOffSplit(v, &mode, name, &err); + visit_type_OnOffSplit(v, name, &mode, &err); if (err) { error_propagate(errp, err); return; @@ -75,7 +75,7 @@ static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v, MachineState *ms = MACHINE(obj); int64_t value = ms->kvm_shadow_mem; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v, @@ -86,7 +86,7 @@ static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v, Error *error = NULL; int64_t value; - visit_type_int(v, &value, name, &error); + visit_type_int(v, name, &value, &error); if (error) { error_propagate(errp, error); return; @@ -177,7 +177,7 @@ static void machine_get_phandle_start(Object *obj, Visitor *v, MachineState *ms = MACHINE(obj); int64_t value = ms->phandle_start; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void machine_set_phandle_start(Object *obj, Visitor *v, @@ -188,7 +188,7 @@ static void machine_set_phandle_start(Object *obj, Visitor *v, Error *error = NULL; int64_t value; - visit_type_int(v, &value, name, &error); + visit_type_int(v, name, &value, &error); if (error) { error_propagate(errp, error); return; diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index ff00f5c9cb..acbe403c63 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -31,7 +31,7 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, char *p; p = *ptr ? print(*ptr) : g_strdup(""); - visit_type_str(v, &p, name, errp); + visit_type_str(v, name, &p, errp); g_free(p); } @@ -51,7 +51,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, return; } - visit_type_str(v, &str, name, &local_err); + visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -202,7 +202,7 @@ static void get_netdev(Object *obj, Visitor *v, void *opaque, NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop); char *p = g_strdup(peers_ptr->ncs[0] ? peers_ptr->ncs[0]->name : ""); - visit_type_str(v, &p, name, errp); + visit_type_str(v, name, &p, errp); g_free(p); } @@ -223,7 +223,7 @@ static void set_netdev(Object *obj, Visitor *v, void *opaque, return; } - visit_type_str(v, &str, name, &local_err); + visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -308,7 +308,7 @@ static void get_vlan(Object *obj, Visitor *v, void *opaque, } } - visit_type_int32(v, &id, name, errp); + visit_type_int32(v, name, &id, errp); } static void set_vlan(Object *obj, Visitor *v, void *opaque, @@ -327,7 +327,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque, return; } - visit_type_int32(v, &id, name, &local_err); + visit_type_int32(v, name, &id, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index e878e80c67..77f354233f 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -49,8 +49,8 @@ static void get_enum(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; int *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_enum(v, ptr, prop->info->enum_table, - prop->info->name, prop->name, errp); + visit_type_enum(v, prop->name, ptr, prop->info->enum_table, + prop->info->name, errp); } static void set_enum(Object *obj, Visitor *v, void *opaque, @@ -65,8 +65,8 @@ static void set_enum(Object *obj, Visitor *v, void *opaque, return; } - visit_type_enum(v, ptr, prop->info->enum_table, - prop->info->name, prop->name, errp); + visit_type_enum(v, prop->name, ptr, prop->info->enum_table, + prop->info->name, errp); } /* Bit */ @@ -96,7 +96,7 @@ static void prop_get_bit(Object *obj, Visitor *v, void *opaque, uint32_t *p = qdev_get_prop_ptr(dev, prop); bool value = (*p & qdev_get_prop_mask(prop)) != 0; - visit_type_bool(v, &value, name, errp); + visit_type_bool(v, name, &value, errp); } static void prop_set_bit(Object *obj, Visitor *v, void *opaque, @@ -112,7 +112,7 @@ static void prop_set_bit(Object *obj, Visitor *v, void *opaque, return; } - visit_type_bool(v, &value, name, &local_err); + visit_type_bool(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -154,7 +154,7 @@ static void prop_get_bit64(Object *obj, Visitor *v, void *opaque, uint64_t *p = qdev_get_prop_ptr(dev, prop); bool value = (*p & qdev_get_prop_mask64(prop)) != 0; - visit_type_bool(v, &value, name, errp); + visit_type_bool(v, name, &value, errp); } static void prop_set_bit64(Object *obj, Visitor *v, void *opaque, @@ -170,7 +170,7 @@ static void prop_set_bit64(Object *obj, Visitor *v, void *opaque, return; } - visit_type_bool(v, &value, name, &local_err); + visit_type_bool(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -194,7 +194,7 @@ static void get_bool(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; bool *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_bool(v, ptr, name, errp); + visit_type_bool(v, name, ptr, errp); } static void set_bool(Object *obj, Visitor *v, void *opaque, @@ -209,7 +209,7 @@ static void set_bool(Object *obj, Visitor *v, void *opaque, return; } - visit_type_bool(v, ptr, name, errp); + visit_type_bool(v, name, ptr, errp); } PropertyInfo qdev_prop_bool = { @@ -227,7 +227,7 @@ static void get_uint8(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; uint8_t *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_uint8(v, ptr, name, errp); + visit_type_uint8(v, name, ptr, errp); } static void set_uint8(Object *obj, Visitor *v, void *opaque, @@ -242,7 +242,7 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque, return; } - visit_type_uint8(v, ptr, name, errp); + visit_type_uint8(v, name, ptr, errp); } PropertyInfo qdev_prop_uint8 = { @@ -260,7 +260,7 @@ static void get_uint16(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; uint16_t *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_uint16(v, ptr, name, errp); + visit_type_uint16(v, name, ptr, errp); } static void set_uint16(Object *obj, Visitor *v, void *opaque, @@ -275,7 +275,7 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque, return; } - visit_type_uint16(v, ptr, name, errp); + visit_type_uint16(v, name, ptr, errp); } PropertyInfo qdev_prop_uint16 = { @@ -293,7 +293,7 @@ static void get_uint32(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; uint32_t *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_uint32(v, ptr, name, errp); + visit_type_uint32(v, name, ptr, errp); } static void set_uint32(Object *obj, Visitor *v, void *opaque, @@ -308,7 +308,7 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque, return; } - visit_type_uint32(v, ptr, name, errp); + visit_type_uint32(v, name, ptr, errp); } static void get_int32(Object *obj, Visitor *v, void *opaque, @@ -318,7 +318,7 @@ static void get_int32(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; int32_t *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_int32(v, ptr, name, errp); + visit_type_int32(v, name, ptr, errp); } static void set_int32(Object *obj, Visitor *v, void *opaque, @@ -333,7 +333,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque, return; } - visit_type_int32(v, ptr, name, errp); + visit_type_int32(v, name, ptr, errp); } PropertyInfo qdev_prop_uint32 = { @@ -357,7 +357,7 @@ static void get_uint64(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; uint64_t *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_uint64(v, ptr, name, errp); + visit_type_uint64(v, name, ptr, errp); } static void set_uint64(Object *obj, Visitor *v, void *opaque, @@ -372,7 +372,7 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque, return; } - visit_type_uint64(v, ptr, name, errp); + visit_type_uint64(v, name, ptr, errp); } PropertyInfo qdev_prop_uint64 = { @@ -398,9 +398,9 @@ static void get_string(Object *obj, Visitor *v, void *opaque, if (!*ptr) { char *str = (char *)""; - visit_type_str(v, &str, name, errp); + visit_type_str(v, name, &str, errp); } else { - visit_type_str(v, ptr, name, errp); + visit_type_str(v, name, ptr, errp); } } @@ -418,7 +418,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque, return; } - visit_type_str(v, &str, name, &local_err); + visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -461,7 +461,7 @@ static void get_mac(Object *obj, Visitor *v, void *opaque, mac->a[0], mac->a[1], mac->a[2], mac->a[3], mac->a[4], mac->a[5]); - visit_type_str(v, &p, name, errp); + visit_type_str(v, name, &p, errp); } static void set_mac(Object *obj, Visitor *v, void *opaque, @@ -479,7 +479,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque, return; } - visit_type_str(v, &str, name, &local_err); + visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -573,11 +573,11 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, return; } - visit_type_str(v, &str, name, &local_err); + visit_type_str(v, name, &str, &local_err); if (local_err) { error_free(local_err); local_err = NULL; - visit_type_int32(v, &value, name, &local_err); + visit_type_int32(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); } else if (value < -1 || value > 255) { @@ -644,7 +644,7 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque, return; } - visit_type_uint16(v, &value, name, &local_err); + visit_type_uint16(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -690,7 +690,7 @@ static void get_pci_host_devaddr(Object *obj, Visitor *v, void *opaque, addr->domain, addr->bus, addr->slot, addr->function); assert(rc == sizeof(buffer) - 1); - visit_type_str(v, &p, name, errp); + visit_type_str(v, name, &p, errp); } /* @@ -715,7 +715,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque, return; } - visit_type_str(v, &str, name, &local_err); + visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -837,7 +837,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, void *opaque, name); return; } - visit_type_uint32(v, alenptr, name, &local_err); + visit_type_uint32(v, name, alenptr, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1101,7 +1101,7 @@ static void get_size(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; uint64_t *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_size(v, ptr, name, errp); + visit_type_size(v, name, ptr, errp); } static void set_size(Object *obj, Visitor *v, void *opaque, @@ -1111,7 +1111,7 @@ static void set_size(Object *obj, Visitor *v, void *opaque, Property *prop = opaque; uint64_t *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_size(v, ptr, name, errp); + visit_type_size(v, name, ptr, errp); } PropertyInfo qdev_prop_size = { diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 779de2ba93..c731bb2032 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -903,7 +903,7 @@ static void qdev_get_legacy_property(Object *obj, Visitor *v, void *opaque, char *ptr = buffer; prop->info->print(dev, prop, buffer, sizeof(buffer)); - visit_type_str(v, &ptr, name, errp); + visit_type_str(v, name, &ptr, errp); } /** diff --git a/hw/i386/pc.c b/hw/i386/pc.c index af2fe84ffb..5dcdde412e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1747,7 +1747,7 @@ pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque, PCMachineState *pcms = PC_MACHINE(obj); int64_t value = memory_region_size(&pcms->hotplug_memory.mr); - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v, @@ -1757,7 +1757,7 @@ static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v, PCMachineState *pcms = PC_MACHINE(obj); uint64_t value = pcms->max_ram_below_4g; - visit_type_size(v, &value, name, errp); + visit_type_size(v, name, &value, errp); } static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v, @@ -1768,7 +1768,7 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v, Error *error = NULL; uint64_t value; - visit_type_size(v, &value, name, &error); + visit_type_size(v, name, &value, &error); if (error) { error_propagate(errp, error); return; @@ -1796,7 +1796,7 @@ static void pc_machine_get_vmport(Object *obj, Visitor *v, void *opaque, PCMachineState *pcms = PC_MACHINE(obj); OnOffAuto vmport = pcms->vmport; - visit_type_OnOffAuto(v, &vmport, name, errp); + visit_type_OnOffAuto(v, name, &vmport, errp); } static void pc_machine_set_vmport(Object *obj, Visitor *v, void *opaque, @@ -1804,7 +1804,7 @@ static void pc_machine_set_vmport(Object *obj, Visitor *v, void *opaque, { PCMachineState *pcms = PC_MACHINE(obj); - visit_type_OnOffAuto(v, &pcms->vmport, name, errp); + visit_type_OnOffAuto(v, name, &pcms->vmport, errp); } bool pc_machine_is_smm_enabled(PCMachineState *pcms) @@ -1838,7 +1838,7 @@ static void pc_machine_get_smm(Object *obj, Visitor *v, void *opaque, PCMachineState *pcms = PC_MACHINE(obj); OnOffAuto smm = pcms->smm; - visit_type_OnOffAuto(v, &smm, name, errp); + visit_type_OnOffAuto(v, name, &smm, errp); } static void pc_machine_set_smm(Object *obj, Visitor *v, void *opaque, @@ -1846,7 +1846,7 @@ static void pc_machine_set_smm(Object *obj, Visitor *v, void *opaque, { PCMachineState *pcms = PC_MACHINE(obj); - visit_type_OnOffAuto(v, &pcms->smm, name, errp); + visit_type_OnOffAuto(v, name, &pcms->smm, errp); } static bool pc_machine_get_nvdimm(Object *obj, Error **errp) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 21607d99b9..572f61dbd4 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -205,7 +205,7 @@ static void ide_dev_get_bootindex(Object *obj, Visitor *v, void *opaque, { IDEDevice *d = IDE_DEVICE(obj); - visit_type_int32(v, &d->conf.bootindex, name, errp); + visit_type_int32(v, name, &d->conf.bootindex, errp); } static void ide_dev_set_bootindex(Object *obj, Visitor *v, void *opaque, @@ -215,7 +215,7 @@ static void ide_dev_set_bootindex(Object *obj, Visitor *v, void *opaque, int32_t boot_index; Error *local_err = NULL; - visit_type_int32(v, &boot_index, name, &local_err); + visit_type_int32(v, name, &boot_index, &local_err); if (local_err) { goto out; } diff --git a/hw/intc/xics.c b/hw/intc/xics.c index cd91ddc4d1..dafcdeb1e0 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -95,7 +95,7 @@ static void xics_prop_get_nr_irqs(Object *obj, Visitor *v, XICSState *icp = XICS_COMMON(obj); int64_t value = icp->nr_irqs; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void xics_prop_set_nr_irqs(Object *obj, Visitor *v, @@ -106,7 +106,7 @@ static void xics_prop_set_nr_irqs(Object *obj, Visitor *v, Error *error = NULL; int64_t value; - visit_type_int(v, &value, name, &error); + visit_type_int(v, name, &value, &error); if (error) { error_propagate(errp, error); return; @@ -129,7 +129,7 @@ static void xics_prop_get_nr_servers(Object *obj, Visitor *v, XICSState *icp = XICS_COMMON(obj); int64_t value = icp->nr_servers; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void xics_prop_set_nr_servers(Object *obj, Visitor *v, @@ -141,7 +141,7 @@ static void xics_prop_set_nr_servers(Object *obj, Visitor *v, Error *error = NULL; int64_t value; - visit_type_int(v, &value, name, &error); + visit_type_int(v, name, &value, &error); if (error) { error_propagate(errp, error); return; diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c index d198945686..e439955789 100644 --- a/hw/isa/lpc_ich9.c +++ b/hw/isa/lpc_ich9.c @@ -577,7 +577,7 @@ static void ich9_lpc_get_sci_int(Object *obj, Visitor *v, ICH9LPCState *lpc = ICH9_LPC_DEVICE(obj); uint32_t value = ich9_lpc_sci_irq(lpc); - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void ich9_lpc_add_properties(ICH9LPCState *lpc) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 32d00ddee7..6514428265 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -383,7 +383,7 @@ static void pc_dimm_get_size(Object *obj, Visitor *v, void *opaque, mr = host_memory_backend_get_memory(dimm->hostmem, errp); value = memory_region_size(mr); - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void pc_dimm_check_memdev_is_busy(Object *obj, const char *name, diff --git a/hw/misc/edu.c b/hw/misc/edu.c index 65e8f20e85..1486441d7c 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -368,7 +368,7 @@ static void edu_obj_uint64(Object *obj, Visitor *v, void *opaque, { uint64_t *val = opaque; - visit_type_uint64(v, val, name, errp); + visit_type_uint64(v, name, val, errp); } static void edu_instance_init(Object *obj) diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c index e102b40756..562d8cc643 100644 --- a/hw/misc/tmp105.c +++ b/hw/misc/tmp105.c @@ -59,7 +59,7 @@ static void tmp105_get_temperature(Object *obj, Visitor *v, void *opaque, TMP105State *s = TMP105(obj); int64_t value = s->temperature * 1000 / 256; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } /* Units are 0.001 centigrades relative to 0 C. s->temperature is 8.8 @@ -72,7 +72,7 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; int64_t temp; - visit_type_int(v, &temp, name, &local_err); + visit_type_int(v, name, &temp, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index ac7277bb0f..6d1e963fc1 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -100,7 +100,7 @@ static void isa_ne2000_get_bootindex(Object *obj, Visitor *v, void *opaque, ISANE2000State *isa = ISA_NE2000(obj); NE2000State *s = &isa->ne2000; - visit_type_int32(v, &s->c.bootindex, name, errp); + visit_type_int32(v, name, &s->c.bootindex, errp); } static void isa_ne2000_set_bootindex(Object *obj, Visitor *v, void *opaque, @@ -111,7 +111,7 @@ static void isa_ne2000_set_bootindex(Object *obj, Visitor *v, void *opaque, int32_t boot_index; Error *local_err = NULL; - visit_type_int32(v, &boot_index, name, &local_err); + visit_type_int32(v, name, &boot_index, &local_err); if (local_err) { goto out; } diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 3832ed6893..8ff5c6b0b0 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -222,7 +222,7 @@ static void i440fx_pcihost_get_pci_hole_start(Object *obj, Visitor *v, I440FXState *s = I440FX_PCI_HOST_BRIDGE(obj); uint32_t value = s->pci_info.w32.begin; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void i440fx_pcihost_get_pci_hole_end(Object *obj, Visitor *v, @@ -232,7 +232,7 @@ static void i440fx_pcihost_get_pci_hole_end(Object *obj, Visitor *v, I440FXState *s = I440FX_PCI_HOST_BRIDGE(obj); uint32_t value = s->pci_info.w32.end; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v, @@ -244,7 +244,7 @@ static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v, pci_bus_get_w64_range(h->bus, &w64); - visit_type_uint64(v, &w64.begin, name, errp); + visit_type_uint64(v, name, &w64.begin, errp); } static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v, @@ -256,7 +256,7 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v, pci_bus_get_w64_range(h->bus, &w64); - visit_type_uint64(v, &w64.end, name, errp); + visit_type_uint64(v, name, &w64.end, errp); } static void i440fx_pcihost_initfn(Object *obj) diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 42b421edfb..0966eb5c89 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -74,7 +74,7 @@ static void q35_host_get_pci_hole_start(Object *obj, Visitor *v, Q35PCIHost *s = Q35_HOST_DEVICE(obj); uint32_t value = s->mch.pci_info.w32.begin; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void q35_host_get_pci_hole_end(Object *obj, Visitor *v, @@ -84,7 +84,7 @@ static void q35_host_get_pci_hole_end(Object *obj, Visitor *v, Q35PCIHost *s = Q35_HOST_DEVICE(obj); uint32_t value = s->mch.pci_info.w32.end; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void q35_host_get_pci_hole64_start(Object *obj, Visitor *v, @@ -96,7 +96,7 @@ static void q35_host_get_pci_hole64_start(Object *obj, Visitor *v, pci_bus_get_w64_range(h->bus, &w64); - visit_type_uint64(v, &w64.begin, name, errp); + visit_type_uint64(v, name, &w64.begin, errp); } static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v, @@ -108,7 +108,7 @@ static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v, pci_bus_get_w64_range(h->bus, &w64); - visit_type_uint64(v, &w64.end, name, errp); + visit_type_uint64(v, name, &w64.end, errp); } static void q35_host_get_mmcfg_size(Object *obj, Visitor *v, @@ -118,7 +118,7 @@ static void q35_host_get_mmcfg_size(Object *obj, Visitor *v, PCIExpressHost *e = PCIE_HOST_BRIDGE(obj); uint32_t value = e->size; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static Property mch_props[] = { diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 90016e63a1..fda6a95288 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -221,7 +221,7 @@ static void prop_get_index(Object *obj, Visitor *v, void *opaque, sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj); sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); uint32_t value = (uint32_t)drck->get_index(drc); - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void prop_get_type(Object *obj, Visitor *v, void *opaque, @@ -230,7 +230,7 @@ static void prop_get_type(Object *obj, Visitor *v, void *opaque, sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj); sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); uint32_t value = (uint32_t)drck->get_type(drc); - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static char *prop_get_name(Object *obj, Error **errp) @@ -248,7 +248,7 @@ static void prop_get_entity_sense(Object *obj, Visitor *v, void *opaque, uint32_t value; drck->entity_sense(drc, &value); - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void prop_get_fdt(Object *obj, Visitor *v, void *opaque, @@ -260,7 +260,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, void *opaque, void *fdt; if (!drc->fdt) { - visit_start_struct(v, NULL, NULL, name, 0, &err); + visit_start_struct(v, name, NULL, NULL, 0, &err); if (!err) { visit_end_struct(v, &err); } @@ -283,7 +283,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, void *opaque, case FDT_BEGIN_NODE: fdt_depth++; name = fdt_get_name(fdt, fdt_offset, &name_len); - visit_start_struct(v, NULL, NULL, name, 0, &err); + visit_start_struct(v, name, NULL, NULL, 0, &err); if (err) { error_propagate(errp, err); return; @@ -309,7 +309,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, void *opaque, return; } for (i = 0; i < prop_len; i++) { - visit_type_uint8(v, (uint8_t *)&prop->data[i], NULL, &err); + visit_type_uint8(v, NULL, (uint8_t *)&prop->data[i], &err); if (err) { error_propagate(errp, err); return; diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index f7ab741a5b..dafbea3484 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -787,7 +787,7 @@ static void usb_msd_get_bootindex(Object *obj, Visitor *v, void *opaque, USBDevice *dev = USB_DEVICE(obj); MSDState *s = USB_STORAGE_DEV(dev); - visit_type_int32(v, &s->conf.bootindex, name, errp); + visit_type_int32(v, name, &s->conf.bootindex, errp); } static void usb_msd_set_bootindex(Object *obj, Visitor *v, void *opaque, @@ -798,7 +798,7 @@ static void usb_msd_set_bootindex(Object *obj, Visitor *v, void *opaque, int32_t boot_index; Error *local_err = NULL; - visit_type_int32(v, &boot_index, name, &local_err); + visit_type_int32(v, name, &boot_index, &local_err); if (local_err) { goto out; } diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 7d05d3fc96..b46cb580a0 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -120,21 +120,21 @@ static void balloon_stats_get_all(Object *obj, Visitor *v, VirtIOBalloon *s = opaque; int i; - visit_start_struct(v, NULL, "guest-stats", name, 0, &err); + visit_start_struct(v, name, NULL, "guest-stats", 0, &err); if (err) { goto out; } - visit_type_int(v, &s->stats_last_update, "last-update", &err); + visit_type_int(v, "last-update", &s->stats_last_update, &err); if (err) { goto out_end; } - visit_start_struct(v, NULL, NULL, "stats", 0, &err); + visit_start_struct(v, "stats", NULL, NULL, 0, &err); if (err) { goto out_end; } for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) { - visit_type_uint64(v, &s->stats[i], balloon_stat_names[i], &err); + visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], &err); if (err) { break; } @@ -156,7 +156,7 @@ static void balloon_stats_get_poll_interval(Object *obj, Visitor *v, Error **errp) { VirtIOBalloon *s = opaque; - visit_type_int(v, &s->stats_poll_interval, name, errp); + visit_type_int(v, name, &s->stats_poll_interval, errp); } static void balloon_stats_set_poll_interval(Object *obj, Visitor *v, @@ -167,7 +167,7 @@ static void balloon_stats_set_poll_interval(Object *obj, Visitor *v, Error *local_err = NULL; int64_t value; - visit_type_int(v, &value, name, &local_err); + visit_type_int(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 83ac3ad279..0b5cd4179e 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -27,8 +27,8 @@ typedef struct GenericList struct GenericList *next; } GenericList; -void visit_start_struct(Visitor *v, void **obj, const char *kind, - const char *name, size_t size, Error **errp); +void visit_start_struct(Visitor *v, const char *name, void **obj, + const char *kind, size_t size, Error **errp); void visit_end_struct(Visitor *v, Error **errp); void visit_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp); @@ -43,7 +43,7 @@ void visit_end_list(Visitor *v, Error **errp); * corresponding visit_type_*() needs calling; for other visitors, * leave *@present unchanged. Return *@present for convenience. */ -bool visit_optional(Visitor *v, bool *present, const char *name); +bool visit_optional(Visitor *v, const char *name, bool *present); /** * Determine the qtype of the item @name in the current object visit. @@ -51,24 +51,34 @@ bool visit_optional(Visitor *v, bool *present, const char *name); * alternate type; for other visitors, leave *@type unchanged. * If @promote_int, treat integers as QTYPE_FLOAT. */ -void visit_get_next_type(Visitor *v, QType *type, bool promote_int, - const char *name, Error **errp); -void visit_type_enum(Visitor *v, int *obj, const char * const strings[], - const char *kind, const char *name, Error **errp); -void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp); -void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp); -void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error **errp); -void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error **errp); -void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp); -void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp); -void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp); -void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp); -void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp); -void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp); -void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp); -void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp); -void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp); -void visit_type_any(Visitor *v, QObject **obj, const char *name, Error **errp); +void visit_get_next_type(Visitor *v, const char *name, QType *type, + bool promote_int, Error **errp); +void visit_type_enum(Visitor *v, const char *name, int *obj, + const char *const strings[], const char *kind, + Error **errp); +void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp); +void visit_type_uint8(Visitor *v, const char *name, uint8_t *obj, + Error **errp); +void visit_type_uint16(Visitor *v, const char *name, uint16_t *obj, + Error **errp); +void visit_type_uint32(Visitor *v, const char *name, uint32_t *obj, + Error **errp); +void visit_type_uint64(Visitor *v, const char *name, uint64_t *obj, + Error **errp); +void visit_type_int8(Visitor *v, const char *name, int8_t *obj, Error **errp); +void visit_type_int16(Visitor *v, const char *name, int16_t *obj, + Error **errp); +void visit_type_int32(Visitor *v, const char *name, int32_t *obj, + Error **errp); +void visit_type_int64(Visitor *v, const char *name, int64_t *obj, + Error **errp); +void visit_type_size(Visitor *v, const char *name, uint64_t *obj, + Error **errp); +void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp); +void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp); +void visit_type_number(Visitor *v, const char *name, double *obj, + Error **errp); +void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp); bool visit_start_union(Visitor *v, bool data_present, Error **errp); #endif diff --git a/memory.c b/memory.c index 39c539cd59..1618dc8914 100644 --- a/memory.c +++ b/memory.c @@ -934,7 +934,7 @@ static void memory_region_get_addr(Object *obj, Visitor *v, void *opaque, MemoryRegion *mr = MEMORY_REGION(obj); uint64_t value = mr->addr; - visit_type_uint64(v, &value, name, errp); + visit_type_uint64(v, name, &value, errp); } static void memory_region_get_container(Object *obj, Visitor *v, void *opaque, @@ -946,7 +946,7 @@ static void memory_region_get_container(Object *obj, Visitor *v, void *opaque, if (mr->container) { path = object_get_canonical_path(OBJECT(mr->container)); } - visit_type_str(v, &path, name, errp); + visit_type_str(v, name, &path, errp); if (mr->container) { g_free(path); } @@ -966,7 +966,7 @@ static void memory_region_get_priority(Object *obj, Visitor *v, void *opaque, MemoryRegion *mr = MEMORY_REGION(obj); int32_t value = mr->priority; - visit_type_int32(v, &value, name, errp); + visit_type_int32(v, name, &value, errp); } static bool memory_region_get_may_overlap(Object *obj, Error **errp) @@ -982,7 +982,7 @@ static void memory_region_get_size(Object *obj, Visitor *v, void *opaque, MemoryRegion *mr = MEMORY_REGION(obj); uint64_t value = memory_region_size(mr); - visit_type_uint64(v, &value, name, errp); + visit_type_uint64(v, name, &value, errp); } static void memory_region_initfn(Object *obj) diff --git a/net/dump.c b/net/dump.c index dc0f33948d..60bc5ce66e 100644 --- a/net/dump.c +++ b/net/dump.c @@ -278,7 +278,7 @@ static void filter_dump_get_maxlen(Object *obj, Visitor *v, void *opaque, NetFilterDumpState *nfds = FILTER_DUMP(obj); uint32_t value = nfds->maxlen; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void filter_dump_set_maxlen(Object *obj, Visitor *v, void *opaque, @@ -288,7 +288,7 @@ static void filter_dump_set_maxlen(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; uint32_t value; - visit_type_uint32(v, &value, name, &local_err); + visit_type_uint32(v, name, &value, &local_err); if (local_err) { goto out; } diff --git a/net/filter-buffer.c b/net/filter-buffer.c index 2353d5bc75..236d950c31 100644 --- a/net/filter-buffer.c +++ b/net/filter-buffer.c @@ -139,7 +139,7 @@ static void filter_buffer_get_interval(Object *obj, Visitor *v, void *opaque, FilterBufferState *s = FILTER_BUFFER(obj); uint32_t value = s->interval; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void filter_buffer_set_interval(Object *obj, Visitor *v, void *opaque, @@ -149,7 +149,7 @@ static void filter_buffer_set_interval(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; uint32_t value; - visit_type_uint32(v, &value, name, &local_err); + visit_type_uint32(v, name, &value, &local_err); if (local_err) { goto out; } diff --git a/net/net.c b/net/net.c index c5e414fe3c..aebf7531a8 100644 --- a/net/net.c +++ b/net/net.c @@ -1046,9 +1046,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) static void net_visit(Visitor *v, int is_netdev, void **object, Error **errp) { if (is_netdev) { - visit_type_Netdev(v, (Netdev **)object, NULL, errp); + visit_type_Netdev(v, NULL, (Netdev **)object, errp); } else { - visit_type_NetLegacy(v, (NetLegacy **)object, NULL, errp); + visit_type_NetLegacy(v, NULL, (NetLegacy **)object, errp); } } diff --git a/numa.c b/numa.c index e1a05698a9..4c4f7f572e 100644 --- a/numa.c +++ b/numa.c @@ -219,7 +219,7 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp) { OptsVisitor *ov = opts_visitor_new(opts); - visit_type_NumaOptions(opts_get_visitor(ov), &object, NULL, &err); + visit_type_NumaOptions(opts_get_visitor(ov), NULL, &object, &err); opts_visitor_cleanup(ov); } @@ -246,8 +246,8 @@ error: if (object) { QapiDeallocVisitor *dv = qapi_dealloc_visitor_new(); - visit_type_NumaOptions(qapi_dealloc_get_visitor(dv), - &object, NULL, NULL); + visit_type_NumaOptions(qapi_dealloc_get_visitor(dv), NULL, &object, + NULL); qapi_dealloc_visitor_cleanup(dv); } diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 7228dc2350..cd8e6031c5 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -19,8 +19,8 @@ #include "qapi/visitor.h" #include "qapi/visitor-impl.h" -void visit_start_struct(Visitor *v, void **obj, const char *kind, - const char *name, size_t size, Error **errp) +void visit_start_struct(Visitor *v, const char *name, void **obj, + const char *kind, size_t size, Error **errp) { v->start_struct(v, obj, kind, name, size, errp); } @@ -68,7 +68,7 @@ bool visit_start_union(Visitor *v, bool data_present, Error **errp) return true; } -bool visit_optional(Visitor *v, bool *present, const char *name) +bool visit_optional(Visitor *v, const char *name, bool *present) { if (v->optional) { v->optional(v, present, name); @@ -76,21 +76,22 @@ bool visit_optional(Visitor *v, bool *present, const char *name) return *present; } -void visit_get_next_type(Visitor *v, QType *type, bool promote_int, - const char *name, Error **errp) +void visit_get_next_type(Visitor *v, const char *name, QType *type, + bool promote_int, Error **errp) { if (v->get_next_type) { v->get_next_type(v, type, promote_int, name, errp); } } -void visit_type_enum(Visitor *v, int *obj, const char * const strings[], - const char *kind, const char *name, Error **errp) +void visit_type_enum(Visitor *v, const char *name, int *obj, + const char *const strings[], const char *kind, + Error **errp) { v->type_enum(v, obj, strings, kind, name, errp); } -void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp) +void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp) { v->type_int64(v, obj, name, errp); } @@ -112,14 +113,15 @@ static void visit_type_uintN(Visitor *v, uint64_t *obj, const char *name, } } -void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp) +void visit_type_uint8(Visitor *v, const char *name, uint8_t *obj, + Error **errp) { uint64_t value = *obj; visit_type_uintN(v, &value, name, UINT8_MAX, "uint8_t", errp); *obj = value; } -void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, +void visit_type_uint16(Visitor *v, const char *name, uint16_t *obj, Error **errp) { uint64_t value = *obj; @@ -127,7 +129,7 @@ void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, *obj = value; } -void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, +void visit_type_uint32(Visitor *v, const char *name, uint32_t *obj, Error **errp) { uint64_t value = *obj; @@ -135,7 +137,7 @@ void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, *obj = value; } -void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, +void visit_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { v->type_uint64(v, obj, name, errp); @@ -159,33 +161,37 @@ static void visit_type_intN(Visitor *v, int64_t *obj, const char *name, } } -void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp) +void visit_type_int8(Visitor *v, const char *name, int8_t *obj, Error **errp) { int64_t value = *obj; visit_type_intN(v, &value, name, INT8_MIN, INT8_MAX, "int8_t", errp); *obj = value; } -void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp) +void visit_type_int16(Visitor *v, const char *name, int16_t *obj, + Error **errp) { int64_t value = *obj; visit_type_intN(v, &value, name, INT16_MIN, INT16_MAX, "int16_t", errp); *obj = value; } -void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp) +void visit_type_int32(Visitor *v, const char *name, int32_t *obj, + Error **errp) { int64_t value = *obj; visit_type_intN(v, &value, name, INT32_MIN, INT32_MAX, "int32_t", errp); *obj = value; } -void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp) +void visit_type_int64(Visitor *v, const char *name, int64_t *obj, + Error **errp) { v->type_int64(v, obj, name, errp); } -void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) +void visit_type_size(Visitor *v, const char *name, uint64_t *obj, + Error **errp) { if (v->type_size) { v->type_size(v, obj, name, errp); @@ -194,23 +200,23 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) } } -void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) +void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { v->type_bool(v, obj, name, errp); } -void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp) +void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp) { v->type_str(v, obj, name, errp); } -void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp) +void visit_type_number(Visitor *v, const char *name, double *obj, + Error **errp) { v->type_number(v, obj, name, errp); } -void visit_type_any(Visitor *v, QObject **obj, const char *name, - Error **errp) +void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) { v->type_any(v, obj, name, errp); } @@ -231,7 +237,7 @@ void output_type_enum(Visitor *v, int *obj, const char * const strings[], } enum_str = (char *)strings[value]; - visit_type_str(v, &enum_str, name, errp); + visit_type_str(v, name, &enum_str, errp); } void input_type_enum(Visitor *v, int *obj, const char * const strings[], @@ -244,7 +250,7 @@ void input_type_enum(Visitor *v, int *obj, const char * const strings[], assert(strings); - visit_type_str(v, &enum_str, name, &local_err); + visit_type_str(v, name, &enum_str, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/qemu-img.c b/qemu-img.c index f121980707..163d8c1664 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -376,8 +376,8 @@ static void dump_json_image_check(ImageCheck *check, bool quiet) QString *str; QmpOutputVisitor *ov = qmp_output_visitor_new(); QObject *obj; - visit_type_ImageCheck(qmp_output_get_visitor(ov), - &check, NULL, &local_err); + visit_type_ImageCheck(qmp_output_get_visitor(ov), NULL, &check, + &local_err); obj = qmp_output_get_qobject(ov); str = qobject_to_json_pretty(obj); assert(str != NULL); @@ -1942,8 +1942,8 @@ static void dump_json_image_info_list(ImageInfoList *list) QString *str; QmpOutputVisitor *ov = qmp_output_visitor_new(); QObject *obj; - visit_type_ImageInfoList(qmp_output_get_visitor(ov), - &list, NULL, &local_err); + visit_type_ImageInfoList(qmp_output_get_visitor(ov), NULL, &list, + &local_err); obj = qmp_output_get_qobject(ov); str = qobject_to_json_pretty(obj); assert(str != NULL); @@ -1959,8 +1959,7 @@ static void dump_json_image_info(ImageInfo *info) QString *str; QmpOutputVisitor *ov = qmp_output_visitor_new(); QObject *obj; - visit_type_ImageInfo(qmp_output_get_visitor(ov), - &info, NULL, &local_err); + visit_type_ImageInfo(qmp_output_get_visitor(ov), NULL, &info, &local_err); obj = qmp_output_get_qobject(ov); str = qobject_to_json_pretty(obj); assert(str != NULL); diff --git a/qom/object.c b/qom/object.c index 3506a98803..66cafacf9a 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1244,8 +1244,8 @@ int object_property_get_enum(Object *obj, const char *name, str = string_output_get_string(sov); siv = string_input_visitor_new(str); string_output_visitor_cleanup(sov); - visit_type_enum(string_input_get_visitor(siv), - &ret, enumprop->strings, NULL, name, errp); + visit_type_enum(string_input_get_visitor(siv), name, &ret, + enumprop->strings, NULL, errp); g_free(str); string_input_visitor_cleanup(siv); @@ -1270,8 +1270,7 @@ void object_property_get_uint16List(Object *obj, const char *name, } str = string_output_get_string(ov); iv = string_input_visitor_new(str); - visit_type_uint16List(string_input_get_visitor(iv), - list, NULL, errp); + visit_type_uint16List(string_input_get_visitor(iv), NULL, list, errp); g_free(str); string_input_visitor_cleanup(iv); @@ -1343,7 +1342,7 @@ static void object_get_child_property(Object *obj, Visitor *v, void *opaque, gchar *path; path = object_get_canonical_path(child); - visit_type_str(v, &path, name, errp); + visit_type_str(v, name, &path, errp); g_free(path); } @@ -1414,11 +1413,11 @@ static void object_get_link_property(Object *obj, Visitor *v, void *opaque, if (*child) { path = object_get_canonical_path(*child); - visit_type_str(v, &path, name, errp); + visit_type_str(v, name, &path, errp); g_free(path); } else { path = (gchar *)""; - visit_type_str(v, &path, name, errp); + visit_type_str(v, name, &path, errp); } } @@ -1472,7 +1471,7 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque, Object *new_target = NULL; char *path = NULL; - visit_type_str(v, &path, name, &local_err); + visit_type_str(v, name, &path, &local_err); if (!local_err && strcmp(path, "") != 0) { new_target = object_resolve_link(obj, name, path, &local_err); @@ -1739,7 +1738,7 @@ static void property_get_str(Object *obj, Visitor *v, void *opaque, return; } - visit_type_str(v, &value, name, errp); + visit_type_str(v, name, &value, errp); g_free(value); } @@ -1750,7 +1749,7 @@ static void property_set_str(Object *obj, Visitor *v, void *opaque, char *value; Error *local_err = NULL; - visit_type_str(v, &value, name, &local_err); + visit_type_str(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1831,7 +1830,7 @@ static void property_get_bool(Object *obj, Visitor *v, void *opaque, return; } - visit_type_bool(v, &value, name, errp); + visit_type_bool(v, name, &value, errp); } static void property_set_bool(Object *obj, Visitor *v, void *opaque, @@ -1841,7 +1840,7 @@ static void property_set_bool(Object *obj, Visitor *v, void *opaque, bool value; Error *local_err = NULL; - visit_type_bool(v, &value, name, &local_err); + visit_type_bool(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1914,7 +1913,7 @@ static void property_get_enum(Object *obj, Visitor *v, void *opaque, return; } - visit_type_enum(v, &value, prop->strings, NULL, name, errp); + visit_type_enum(v, name, &value, prop->strings, NULL, errp); } static void property_set_enum(Object *obj, Visitor *v, void *opaque, @@ -1924,7 +1923,7 @@ static void property_set_enum(Object *obj, Visitor *v, void *opaque, int value; Error *err = NULL; - visit_type_enum(v, &value, prop->strings, NULL, name, &err); + visit_type_enum(v, name, &value, prop->strings, NULL, &err); if (err) { error_propagate(errp, err); return; @@ -2005,31 +2004,31 @@ static void property_get_tm(Object *obj, Visitor *v, void *opaque, goto out; } - visit_start_struct(v, NULL, "struct tm", name, 0, &err); + visit_start_struct(v, name, NULL, "struct tm", 0, &err); if (err) { goto out; } - visit_type_int32(v, &value.tm_year, "tm_year", &err); + visit_type_int32(v, "tm_year", &value.tm_year, &err); if (err) { goto out_end; } - visit_type_int32(v, &value.tm_mon, "tm_mon", &err); + visit_type_int32(v, "tm_mon", &value.tm_mon, &err); if (err) { goto out_end; } - visit_type_int32(v, &value.tm_mday, "tm_mday", &err); + visit_type_int32(v, "tm_mday", &value.tm_mday, &err); if (err) { goto out_end; } - visit_type_int32(v, &value.tm_hour, "tm_hour", &err); + visit_type_int32(v, "tm_hour", &value.tm_hour, &err); if (err) { goto out_end; } - visit_type_int32(v, &value.tm_min, "tm_min", &err); + visit_type_int32(v, "tm_min", &value.tm_min, &err); if (err) { goto out_end; } - visit_type_int32(v, &value.tm_sec, "tm_sec", &err); + visit_type_int32(v, "tm_sec", &value.tm_sec, &err); if (err) { goto out_end; } @@ -2097,7 +2096,7 @@ static void property_get_uint8_ptr(Object *obj, Visitor *v, Error **errp) { uint8_t value = *(uint8_t *)opaque; - visit_type_uint8(v, &value, name, errp); + visit_type_uint8(v, name, &value, errp); } static void property_get_uint16_ptr(Object *obj, Visitor *v, @@ -2105,7 +2104,7 @@ static void property_get_uint16_ptr(Object *obj, Visitor *v, Error **errp) { uint16_t value = *(uint16_t *)opaque; - visit_type_uint16(v, &value, name, errp); + visit_type_uint16(v, name, &value, errp); } static void property_get_uint32_ptr(Object *obj, Visitor *v, @@ -2113,7 +2112,7 @@ static void property_get_uint32_ptr(Object *obj, Visitor *v, Error **errp) { uint32_t value = *(uint32_t *)opaque; - visit_type_uint32(v, &value, name, errp); + visit_type_uint32(v, name, &value, errp); } static void property_get_uint64_ptr(Object *obj, Visitor *v, @@ -2121,7 +2120,7 @@ static void property_get_uint64_ptr(Object *obj, Visitor *v, Error **errp) { uint64_t value = *(uint64_t *)opaque; - visit_type_uint64(v, &value, name, errp); + visit_type_uint64(v, name, &value, errp); } void object_property_add_uint8_ptr(Object *obj, const char *name, diff --git a/replay/replay-input.c b/replay/replay-input.c index 4270ca1837..93616be930 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -29,7 +29,7 @@ static InputEvent *qapi_clone_InputEvent(InputEvent *src) qov = qmp_output_visitor_new(); ov = qmp_output_get_visitor(qov); - visit_type_InputEvent(ov, &src, NULL, &error_abort); + visit_type_InputEvent(ov, NULL, &src, &error_abort); obj = qmp_output_get_qobject(qov); qmp_output_visitor_cleanup(qov); if (!obj) { @@ -38,7 +38,7 @@ static InputEvent *qapi_clone_InputEvent(InputEvent *src) qiv = qmp_input_visitor_new(obj); iv = qmp_input_get_visitor(qiv); - visit_type_InputEvent(iv, &dst, NULL, &error_abort); + visit_type_InputEvent(iv, NULL, &dst, &error_abort); qmp_input_visitor_cleanup(qiv); qobject_decref(obj); 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 0f5534f6c3..edd446b74d 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -63,7 +63,7 @@ def gen_event_send(name, arg_type): qov = qmp_output_visitor_new(); v = qmp_output_get_visitor(qov); - visit_start_struct(v, NULL, NULL, "%(name)s", 0, &err); + visit_start_struct(v, "%(name)s", NULL, NULL, 0, &err); ''', name=name) ret += gen_err_check() 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 ba75667e03..35505acd98 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -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) @@ -118,11 +118,11 @@ 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); + visit_start_struct(v, name, (void **)obj, "%(name)s", sizeof(%(c_name)s), &err); if (err) { goto out; } @@ -150,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; @@ -164,7 +164,7 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error !err && (i = visit_next_list(v, prev, &err)) != 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); @@ -180,10 +180,10 @@ out: def gen_visit_enum(name): 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) { int value = *obj; - visit_type_enum(v, &value, %(c_name)s_lookup, "%(name)s", name, errp); + visit_type_enum(v, name, &value, %(c_name)s_lookup, "%(name)s", errp); *obj = value; } ''', @@ -198,7 +198,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; @@ -206,7 +206,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; } @@ -217,7 +217,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(), @@ -255,11 +255,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, "%(name)s", sizeof(%(c_name)s), &err); if (err) { goto out; } @@ -276,7 +276,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), @@ -300,7 +300,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)) diff --git a/scripts/qapi.py b/scripts/qapi.py index 9254e48fe3..7519cf8e7a 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1647,7 +1647,7 @@ 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) @@ -1660,7 +1660,7 @@ 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, diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 60bfa80a70..c9b8b16b3a 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1541,7 +1541,7 @@ static void x86_cpuid_version_get_family(Object *obj, Visitor *v, void *opaque, if (value == 0xf) { value += (env->cpuid_version >> 20) & 0xff; } - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, @@ -1554,7 +1554,7 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; int64_t value; - visit_type_int(v, &value, name, &local_err); + visit_type_int(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1582,7 +1582,7 @@ static void x86_cpuid_version_get_model(Object *obj, Visitor *v, void *opaque, value = (env->cpuid_version >> 4) & 0xf; value |= ((env->cpuid_version >> 16) & 0xf) << 4; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, @@ -1595,7 +1595,7 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; int64_t value; - visit_type_int(v, &value, name, &local_err); + visit_type_int(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1619,7 +1619,7 @@ static void x86_cpuid_version_get_stepping(Object *obj, Visitor *v, int64_t value; value = env->cpuid_version & 0xf; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, @@ -1633,7 +1633,7 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, Error *local_err = NULL; int64_t value; - visit_type_int(v, &value, name, &local_err); + visit_type_int(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1726,7 +1726,7 @@ static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque, int64_t value; value = cpu->env.tsc_khz * 1000; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, @@ -1738,7 +1738,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, Error *local_err = NULL; int64_t value; - visit_type_int(v, &value, name, &local_err); + visit_type_int(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1758,7 +1758,7 @@ static void x86_cpuid_get_apic_id(Object *obj, Visitor *v, void *opaque, X86CPU *cpu = X86_CPU(obj); int64_t value = cpu->apic_id; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, @@ -1777,7 +1777,7 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, return; } - visit_type_int(v, &value, name, &error); + visit_type_int(v, name, &value, &error); if (error) { error_propagate(errp, error); return; @@ -1822,7 +1822,7 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, void *opaque, list = &list_entries[w]; } - visit_type_X86CPUFeatureWordInfoList(v, &list, "feature-words", &err); + visit_type_X86CPUFeatureWordInfoList(v, "feature-words", &list, &err); error_propagate(errp, err); } @@ -1832,7 +1832,7 @@ static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque, X86CPU *cpu = X86_CPU(obj); int64_t value = cpu->hyperv_spinlock_attempts; - visit_type_int(v, &value, name, errp); + visit_type_int(v, name, &value, errp); } static void x86_set_hv_spinlocks(Object *obj, Visitor *v, void *opaque, @@ -1844,7 +1844,7 @@ static void x86_set_hv_spinlocks(Object *obj, Visitor *v, void *opaque, Error *err = NULL; int64_t value; - visit_type_int(v, &value, name, &err); + visit_type_int(v, name, &value, &err); if (err) { error_propagate(errp, err); return; @@ -2952,7 +2952,7 @@ static void x86_cpu_get_bit_prop(Object *obj, { BitProperty *fp = opaque; bool value = (*fp->ptr & fp->mask) == fp->mask; - visit_type_bool(v, &value, name, errp); + visit_type_bool(v, name, &value, errp); } static void x86_cpu_set_bit_prop(Object *obj, @@ -2971,7 +2971,7 @@ static void x86_cpu_set_bit_prop(Object *obj, return; } - visit_type_bool(v, &value, name, &local_err); + visit_type_bool(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index cdd18ac630..82f85f9ba2 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -8060,7 +8060,7 @@ static void powerpc_get_compat(Object *obj, Visitor *v, break; } - visit_type_str(v, &value, name, errp); + visit_type_str(v, name, &value, errp); } static void powerpc_set_compat(Object *obj, Visitor *v, @@ -8071,7 +8071,7 @@ static void powerpc_set_compat(Object *obj, Visitor *v, Property *prop = opaque; uint32_t *max_compat = qdev_get_prop_ptr(DEVICE(obj), prop); - visit_type_str(v, &value, name, &error); + visit_type_str(v, name, &value, &error); if (error) { error_propagate(errp, error); return; diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c index 1c753d9824..9600b97012 100644 --- a/tests/test-opts-visitor.c +++ b/tests/test-opts-visitor.c @@ -44,7 +44,7 @@ setup_fixture(OptsVisitorFixture *f, gconstpointer test_data) g_assert(opts != NULL); ov = opts_visitor_new(opts); - visit_type_UserDefOptions(opts_get_visitor(ov), &f->userdef, NULL, + visit_type_UserDefOptions(opts_get_visitor(ov), NULL, &f->userdef, &f->err); opts_visitor_cleanup(ov); qemu_opts_del(opts); @@ -58,8 +58,8 @@ teardown_fixture(OptsVisitorFixture *f, gconstpointer test_data) QapiDeallocVisitor *dv; dv = qapi_dealloc_visitor_new(); - visit_type_UserDefOptions(qapi_dealloc_get_visitor(dv), &f->userdef, - NULL, NULL); + visit_type_UserDefOptions(qapi_dealloc_get_visitor(dv), NULL, + &f->userdef, NULL); qapi_dealloc_visitor_cleanup(dv); } error_free(f->err); diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c index 0be98355c0..e728611b31 100644 --- a/tests/test-qdev-global-props.c +++ b/tests/test-qdev-global-props.c @@ -124,7 +124,7 @@ static void prop1_accessor(Object *obj, { MyType *mt = DYNAMIC_TYPE(obj); - visit_type_uint32(v, &mt->prop1, name, errp); + visit_type_uint32(v, name, &mt->prop1, errp); } static void prop2_accessor(Object *obj, @@ -135,7 +135,7 @@ static void prop2_accessor(Object *obj, { MyType *mt = DYNAMIC_TYPE(obj); - visit_type_uint32(v, &mt->prop2, name, errp); + visit_type_uint32(v, name, &mt->prop2, errp); } static void dynamic_instance_init(Object *obj) diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 9f35b80a45..4d267b6a83 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -217,7 +217,7 @@ static void test_dealloc_partial(void) qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text))); qiv = qmp_input_visitor_new(QOBJECT(ud2_dict)); - visit_type_UserDefTwo(qmp_input_get_visitor(qiv), &ud2, NULL, &err); + visit_type_UserDefTwo(qmp_input_get_visitor(qiv), NULL, &ud2, &err); qmp_input_visitor_cleanup(qiv); QDECREF(ud2_dict); } diff --git a/tests/test-qmp-input-strict.c b/tests/test-qmp-input-strict.c index f1c2e3ba67..775ad39d93 100644 --- a/tests/test-qmp-input-strict.c +++ b/tests/test-qmp-input-strict.c @@ -98,7 +98,7 @@ static void test_validate_struct(TestInputVisitorData *data, v = validate_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }"); - visit_type_TestStruct(v, &p, NULL, &error_abort); + visit_type_TestStruct(v, NULL, &p, &error_abort); g_free(p->string); g_free(p); } @@ -114,7 +114,7 @@ static void test_validate_struct_nested(TestInputVisitorData *data, "'dict2': { 'userdef': { 'integer': 42, " "'string': 'string' }, 'string': 'string2'}}}"); - visit_type_UserDefTwo(v, &udp, NULL, &error_abort); + visit_type_UserDefTwo(v, NULL, &udp, &error_abort); qapi_free_UserDefTwo(udp); } @@ -126,7 +126,7 @@ static void test_validate_list(TestInputVisitorData *data, v = validate_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]"); - visit_type_UserDefOneList(v, &head, NULL, &error_abort); + visit_type_UserDefOneList(v, NULL, &head, &error_abort); qapi_free_UserDefOneList(head); } @@ -138,7 +138,7 @@ static void test_validate_union_native_list(TestInputVisitorData *data, v = validate_test_init(data, "{ 'type': 'integer', 'data' : [ 1, 2 ] }"); - visit_type_UserDefNativeListUnion(v, &tmp, NULL, &error_abort); + visit_type_UserDefNativeListUnion(v, NULL, &tmp, &error_abort); qapi_free_UserDefNativeListUnion(tmp); } @@ -154,7 +154,7 @@ static void test_validate_union_flat(TestInputVisitorData *data, "'string': 'str', " "'boolean': true }"); - visit_type_UserDefFlatUnion(v, &tmp, NULL, &error_abort); + visit_type_UserDefFlatUnion(v, NULL, &tmp, &error_abort); qapi_free_UserDefFlatUnion(tmp); } @@ -166,7 +166,7 @@ static void test_validate_alternate(TestInputVisitorData *data, v = validate_test_init(data, "42"); - visit_type_UserDefAlternate(v, &tmp, NULL, &error_abort); + visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); qapi_free_UserDefAlternate(tmp); } @@ -179,7 +179,7 @@ static void test_validate_fail_struct(TestInputVisitorData *data, v = validate_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo', 'extra': 42 }"); - visit_type_TestStruct(v, &p, NULL, &err); + visit_type_TestStruct(v, NULL, &p, &err); error_free_or_abort(&err); if (p) { g_free(p->string); @@ -196,7 +196,7 @@ static void test_validate_fail_struct_nested(TestInputVisitorData *data, v = validate_test_init(data, "{ 'string0': 'string0', 'dict1': { 'string1': 'string1', 'dict2': { 'userdef1': { 'integer': 42, 'string': 'string', 'extra': [42, 23, {'foo':'bar'}] }, 'string2': 'string2'}}}"); - visit_type_UserDefTwo(v, &udp, NULL, &err); + visit_type_UserDefTwo(v, NULL, &udp, &err); error_free_or_abort(&err); qapi_free_UserDefTwo(udp); } @@ -210,7 +210,7 @@ static void test_validate_fail_list(TestInputVisitorData *data, v = validate_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44, 'extra': 'ggg' } ]"); - visit_type_UserDefOneList(v, &head, NULL, &err); + visit_type_UserDefOneList(v, NULL, &head, &err); error_free_or_abort(&err); qapi_free_UserDefOneList(head); } @@ -225,7 +225,7 @@ static void test_validate_fail_union_native_list(TestInputVisitorData *data, v = validate_test_init(data, "{ 'type': 'integer', 'data' : [ 'string' ] }"); - visit_type_UserDefNativeListUnion(v, &tmp, NULL, &err); + visit_type_UserDefNativeListUnion(v, NULL, &tmp, &err); error_free_or_abort(&err); qapi_free_UserDefNativeListUnion(tmp); } @@ -239,7 +239,7 @@ static void test_validate_fail_union_flat(TestInputVisitorData *data, v = validate_test_init(data, "{ 'string': 'c', 'integer': 41, 'boolean': true }"); - visit_type_UserDefFlatUnion(v, &tmp, NULL, &err); + visit_type_UserDefFlatUnion(v, NULL, &tmp, &err); error_free_or_abort(&err); qapi_free_UserDefFlatUnion(tmp); } @@ -254,7 +254,7 @@ static void test_validate_fail_union_flat_no_discrim(TestInputVisitorData *data, /* test situation where discriminator field ('enum1' here) is missing */ v = validate_test_init(data, "{ 'integer': 42, 'string': 'c', 'string1': 'd', 'string2': 'e' }"); - visit_type_UserDefFlatUnion2(v, &tmp, NULL, &err); + visit_type_UserDefFlatUnion2(v, NULL, &tmp, &err); error_free_or_abort(&err); qapi_free_UserDefFlatUnion2(tmp); } @@ -268,7 +268,7 @@ static void test_validate_fail_alternate(TestInputVisitorData *data, v = validate_test_init(data, "3.14"); - visit_type_UserDefAlternate(v, &tmp, NULL, &err); + visit_type_UserDefAlternate(v, NULL, &tmp, &err); error_free_or_abort(&err); qapi_free_UserDefAlternate(tmp); } @@ -281,7 +281,7 @@ static void do_test_validate_qmp_introspect(TestInputVisitorData *data, v = validate_test_init_raw(data, schema_json); - visit_type_SchemaInfoList(v, &schema, NULL, &error_abort); + visit_type_SchemaInfoList(v, NULL, &schema, &error_abort); g_assert(schema); qapi_free_SchemaInfoList(schema); diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c index b4a5bee6a5..f6bd408db3 100644 --- a/tests/test-qmp-input-visitor.c +++ b/tests/test-qmp-input-visitor.c @@ -93,7 +93,7 @@ static void test_visitor_in_int(TestInputVisitorData *data, v = visitor_input_test_init(data, "%" PRId64, value); - visit_type_int(v, &res, NULL, &error_abort); + visit_type_int(v, NULL, &res, &error_abort); g_assert_cmpint(res, ==, value); } @@ -110,7 +110,7 @@ static void test_visitor_in_int_overflow(TestInputVisitorData *data, */ v = visitor_input_test_init(data, "%f", DBL_MAX); - visit_type_int(v, &res, NULL, &err); + visit_type_int(v, NULL, &res, &err); error_free_or_abort(&err); } @@ -122,7 +122,7 @@ static void test_visitor_in_bool(TestInputVisitorData *data, v = visitor_input_test_init(data, "true"); - visit_type_bool(v, &res, NULL, &error_abort); + visit_type_bool(v, NULL, &res, &error_abort); g_assert_cmpint(res, ==, true); } @@ -134,7 +134,7 @@ static void test_visitor_in_number(TestInputVisitorData *data, v = visitor_input_test_init(data, "%f", value); - visit_type_number(v, &res, NULL, &error_abort); + visit_type_number(v, NULL, &res, &error_abort); g_assert_cmpfloat(res, ==, value); } @@ -146,7 +146,7 @@ static void test_visitor_in_string(TestInputVisitorData *data, v = visitor_input_test_init(data, "%s", value); - visit_type_str(v, &res, NULL, &error_abort); + visit_type_str(v, NULL, &res, &error_abort); g_assert_cmpstr(res, ==, value); g_free(res); @@ -163,7 +163,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data, v = visitor_input_test_init(data, "%s", EnumOne_lookup[i]); - visit_type_EnumOne(v, &res, NULL, &error_abort); + visit_type_EnumOne(v, NULL, &res, &error_abort); g_assert_cmpint(i, ==, res); } } @@ -177,7 +177,7 @@ static void test_visitor_in_struct(TestInputVisitorData *data, v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }"); - visit_type_TestStruct(v, &p, NULL, &error_abort); + visit_type_TestStruct(v, NULL, &p, &error_abort); g_assert_cmpint(p->integer, ==, -42); g_assert(p->boolean == true); g_assert_cmpstr(p->string, ==, "foo"); @@ -197,7 +197,7 @@ static void test_visitor_in_struct_nested(TestInputVisitorData *data, "'dict2': { 'userdef': { 'integer': 42, " "'string': 'string' }, 'string': 'string2'}}}"); - visit_type_UserDefTwo(v, &udp, NULL, &error_abort); + visit_type_UserDefTwo(v, NULL, &udp, &error_abort); g_assert_cmpstr(udp->string0, ==, "string0"); g_assert_cmpstr(udp->dict1->string1, ==, "string1"); @@ -218,7 +218,7 @@ static void test_visitor_in_list(TestInputVisitorData *data, v = visitor_input_test_init(data, "[ { 'string': 'string0', 'integer': 42 }, { 'string': 'string1', 'integer': 43 }, { 'string': 'string2', 'integer': 44 } ]"); - visit_type_UserDefOneList(v, &head, NULL, &error_abort); + visit_type_UserDefOneList(v, NULL, &head, &error_abort); g_assert(head != NULL); for (i = 0, item = head; item; item = item->next, i++) { @@ -234,7 +234,7 @@ static void test_visitor_in_list(TestInputVisitorData *data, /* An empty list is valid */ v = visitor_input_test_init(data, "[]"); - visit_type_UserDefOneList(v, &head, NULL, &error_abort); + visit_type_UserDefOneList(v, NULL, &head, &error_abort); g_assert(!head); } @@ -250,14 +250,14 @@ static void test_visitor_in_any(TestInputVisitorData *data, QObject *qobj; v = visitor_input_test_init(data, "-42"); - visit_type_any(v, &res, NULL, &error_abort); + visit_type_any(v, NULL, &res, &error_abort); qint = qobject_to_qint(res); g_assert(qint); g_assert_cmpint(qint_get_int(qint), ==, -42); qobject_decref(res); v = visitor_input_test_init(data, "{ 'integer': -42, 'boolean': true, 'string': 'foo' }"); - visit_type_any(v, &res, NULL, &error_abort); + visit_type_any(v, NULL, &res, &error_abort); qdict = qobject_to_qdict(res); g_assert(qdict && qdict_size(qdict) == 3); qobj = qdict_get(qdict, "integer"); @@ -291,7 +291,7 @@ static void test_visitor_in_union_flat(TestInputVisitorData *data, "'string': 'str', " "'boolean': true }"); - visit_type_UserDefFlatUnion(v, &tmp, NULL, &error_abort); + visit_type_UserDefFlatUnion(v, NULL, &tmp, &error_abort); g_assert_cmpint(tmp->enum1, ==, ENUM_ONE_VALUE1); g_assert_cmpstr(tmp->string, ==, "str"); g_assert_cmpint(tmp->integer, ==, 41); @@ -311,19 +311,19 @@ static void test_visitor_in_alternate(TestInputVisitorData *data, UserDefAlternate *tmp; v = visitor_input_test_init(data, "42"); - visit_type_UserDefAlternate(v, &tmp, NULL, &error_abort); + visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); g_assert_cmpint(tmp->type, ==, QTYPE_QINT); g_assert_cmpint(tmp->u.i, ==, 42); qapi_free_UserDefAlternate(tmp); v = visitor_input_test_init(data, "'string'"); - visit_type_UserDefAlternate(v, &tmp, NULL, &error_abort); + visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); g_assert_cmpint(tmp->type, ==, QTYPE_QSTRING); g_assert_cmpstr(tmp->u.s, ==, "string"); qapi_free_UserDefAlternate(tmp); v = visitor_input_test_init(data, "false"); - visit_type_UserDefAlternate(v, &tmp, NULL, &err); + visit_type_UserDefAlternate(v, NULL, &tmp, &err); error_free_or_abort(&err); qapi_free_UserDefAlternate(tmp); } @@ -343,36 +343,36 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data, /* Parsing an int */ v = visitor_input_test_init(data, "42"); - visit_type_AltStrBool(v, &asb, NULL, &err); + visit_type_AltStrBool(v, NULL, &asb, &err); error_free_or_abort(&err); qapi_free_AltStrBool(asb); v = visitor_input_test_init(data, "42"); - visit_type_AltStrNum(v, &asn, NULL, &error_abort); + visit_type_AltStrNum(v, NULL, &asn, &error_abort); g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(asn->u.n, ==, 42); qapi_free_AltStrNum(asn); v = visitor_input_test_init(data, "42"); - visit_type_AltNumStr(v, &ans, NULL, &error_abort); + visit_type_AltNumStr(v, NULL, &ans, &error_abort); g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(ans->u.n, ==, 42); qapi_free_AltNumStr(ans); v = visitor_input_test_init(data, "42"); - visit_type_AltStrInt(v, &asi, NULL, &error_abort); + visit_type_AltStrInt(v, NULL, &asi, &error_abort); g_assert_cmpint(asi->type, ==, QTYPE_QINT); g_assert_cmpint(asi->u.i, ==, 42); qapi_free_AltStrInt(asi); v = visitor_input_test_init(data, "42"); - visit_type_AltIntNum(v, &ain, NULL, &error_abort); + visit_type_AltIntNum(v, NULL, &ain, &error_abort); g_assert_cmpint(ain->type, ==, QTYPE_QINT); g_assert_cmpint(ain->u.i, ==, 42); qapi_free_AltIntNum(ain); v = visitor_input_test_init(data, "42"); - visit_type_AltNumInt(v, &ani, NULL, &error_abort); + visit_type_AltNumInt(v, NULL, &ani, &error_abort); g_assert_cmpint(ani->type, ==, QTYPE_QINT); g_assert_cmpint(ani->u.i, ==, 42); qapi_free_AltNumInt(ani); @@ -380,35 +380,35 @@ static void test_visitor_in_alternate_number(TestInputVisitorData *data, /* Parsing a double */ v = visitor_input_test_init(data, "42.5"); - visit_type_AltStrBool(v, &asb, NULL, &err); + visit_type_AltStrBool(v, NULL, &asb, &err); error_free_or_abort(&err); qapi_free_AltStrBool(asb); v = visitor_input_test_init(data, "42.5"); - visit_type_AltStrNum(v, &asn, NULL, &error_abort); + visit_type_AltStrNum(v, NULL, &asn, &error_abort); g_assert_cmpint(asn->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(asn->u.n, ==, 42.5); qapi_free_AltStrNum(asn); v = visitor_input_test_init(data, "42.5"); - visit_type_AltNumStr(v, &ans, NULL, &error_abort); + visit_type_AltNumStr(v, NULL, &ans, &error_abort); g_assert_cmpint(ans->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(ans->u.n, ==, 42.5); qapi_free_AltNumStr(ans); v = visitor_input_test_init(data, "42.5"); - visit_type_AltStrInt(v, &asi, NULL, &err); + visit_type_AltStrInt(v, NULL, &asi, &err); error_free_or_abort(&err); qapi_free_AltStrInt(asi); v = visitor_input_test_init(data, "42.5"); - visit_type_AltIntNum(v, &ain, NULL, &error_abort); + visit_type_AltIntNum(v, NULL, &ain, &error_abort); g_assert_cmpint(ain->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(ain->u.n, ==, 42.5); qapi_free_AltIntNum(ain); v = visitor_input_test_init(data, "42.5"); - visit_type_AltNumInt(v, &ani, NULL, &error_abort); + visit_type_AltNumInt(v, NULL, &ani, &error_abort); g_assert_cmpint(ani->type, ==, QTYPE_QFLOAT); g_assert_cmpfloat(ani->u.n, ==, 42.5); qapi_free_AltNumInt(ani); @@ -435,7 +435,7 @@ static void test_native_list_integer_helper(TestInputVisitorData *data, gstr_list->str); v = visitor_input_test_init_raw(data, gstr_union->str); - visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &error_abort); + visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort); g_assert(cvalue != NULL); g_assert_cmpint(cvalue->type, ==, kind); @@ -596,7 +596,7 @@ static void test_visitor_in_native_list_bool(TestInputVisitorData *data, gstr_list->str); v = visitor_input_test_init_raw(data, gstr_union->str); - visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &error_abort); + visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort); g_assert(cvalue != NULL); g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN); @@ -629,7 +629,7 @@ static void test_visitor_in_native_list_string(TestInputVisitorData *data, gstr_list->str); v = visitor_input_test_init_raw(data, gstr_union->str); - visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &error_abort); + visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort); g_assert(cvalue != NULL); g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING); @@ -666,7 +666,7 @@ static void test_visitor_in_native_list_number(TestInputVisitorData *data, gstr_list->str); v = visitor_input_test_init_raw(data, gstr_union->str); - visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &error_abort); + visit_type_UserDefNativeListUnion(v, NULL, &cvalue, &error_abort); g_assert(cvalue != NULL); g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER); @@ -706,7 +706,7 @@ static void test_visitor_in_errors(TestInputVisitorData *data, v = visitor_input_test_init(data, "{ 'integer': false, 'boolean': 'foo', " "'string': -42 }"); - visit_type_TestStruct(v, &p, NULL, &err); + visit_type_TestStruct(v, NULL, &p, &err); error_free_or_abort(&err); /* FIXME - a failed parse should not leave a partially-allocated p * for us to clean up; this could cause callers to leak memory. */ @@ -716,7 +716,7 @@ static void test_visitor_in_errors(TestInputVisitorData *data, g_free(p); v = visitor_input_test_init(data, "[ '1', '2', false, '3' ]"); - visit_type_strList(v, &q, NULL, &err); + visit_type_strList(v, NULL, &q, &err); error_free_or_abort(&err); assert(q); qapi_free_strList(q); @@ -734,35 +734,35 @@ static void test_visitor_in_wrong_type(TestInputVisitorData *data, /* Make sure arrays and structs cannot be confused */ v = visitor_input_test_init(data, "[]"); - visit_type_TestStruct(v, &p, NULL, &err); + visit_type_TestStruct(v, NULL, &p, &err); error_free_or_abort(&err); g_assert(!p); v = visitor_input_test_init(data, "{}"); - visit_type_strList(v, &q, NULL, &err); + visit_type_strList(v, NULL, &q, &err); error_free_or_abort(&err); assert(!q); /* Make sure primitives and struct cannot be confused */ v = visitor_input_test_init(data, "1"); - visit_type_TestStruct(v, &p, NULL, &err); + visit_type_TestStruct(v, NULL, &p, &err); error_free_or_abort(&err); g_assert(!p); v = visitor_input_test_init(data, "{}"); - visit_type_int(v, &i, NULL, &err); + visit_type_int(v, NULL, &i, &err); error_free_or_abort(&err); /* Make sure primitives and arrays cannot be confused */ v = visitor_input_test_init(data, "1"); - visit_type_strList(v, &q, NULL, &err); + visit_type_strList(v, NULL, &q, &err); error_free_or_abort(&err); assert(!q); v = visitor_input_test_init(data, "[]"); - visit_type_int(v, &i, NULL, &err); + visit_type_int(v, NULL, &i, &err); error_free_or_abort(&err); } diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index 30784424e4..4df94bcb59 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -47,7 +47,7 @@ static void test_visitor_out_int(TestOutputVisitorData *data, int64_t value = -42; QObject *obj; - visit_type_int(data->ov, &value, NULL, &error_abort); + visit_type_int(data->ov, NULL, &value, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -63,7 +63,7 @@ static void test_visitor_out_bool(TestOutputVisitorData *data, bool value = true; QObject *obj; - visit_type_bool(data->ov, &value, NULL, &error_abort); + visit_type_bool(data->ov, NULL, &value, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -79,7 +79,7 @@ static void test_visitor_out_number(TestOutputVisitorData *data, double value = 3.14; QObject *obj; - visit_type_number(data->ov, &value, NULL, &error_abort); + visit_type_number(data->ov, NULL, &value, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -95,7 +95,7 @@ static void test_visitor_out_string(TestOutputVisitorData *data, char *string = (char *) "Q E M U"; QObject *obj; - visit_type_str(data->ov, &string, NULL, &error_abort); + visit_type_str(data->ov, NULL, &string, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -112,7 +112,7 @@ static void test_visitor_out_no_string(TestOutputVisitorData *data, QObject *obj; /* A null string should return "" */ - visit_type_str(data->ov, &string, NULL, &error_abort); + visit_type_str(data->ov, NULL, &string, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -129,7 +129,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data, EnumOne i; for (i = 0; i < ENUM_ONE__MAX; i++) { - visit_type_EnumOne(data->ov, &i, "unused", &error_abort); + visit_type_EnumOne(data->ov, "unused", &i, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -148,7 +148,7 @@ static void test_visitor_out_enum_errors(TestOutputVisitorData *data, for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { err = NULL; - visit_type_EnumOne(data->ov, &bad_values[i], "unused", &err); + visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); g_assert(err); error_free(err); } @@ -165,7 +165,7 @@ static void test_visitor_out_struct(TestOutputVisitorData *data, QObject *obj; QDict *qdict; - visit_type_TestStruct(data->ov, &p, NULL, &error_abort); + visit_type_TestStruct(data->ov, NULL, &p, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -210,7 +210,7 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data, ud2->dict1->dict3->userdef->integer = value; ud2->dict1->dict3->string = g_strdup(strings[3]); - visit_type_UserDefTwo(data->ov, &ud2, "unused", &error_abort); + visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -257,7 +257,7 @@ static void test_visitor_out_struct_errors(TestOutputVisitorData *data, err = NULL; u.has_enum1 = true; u.enum1 = bad_values[i]; - visit_type_UserDefOne(data->ov, &pu, "unused", &err); + visit_type_UserDefOne(data->ov, "unused", &pu, &err); g_assert(err); error_free(err); } @@ -289,7 +289,7 @@ static void test_visitor_out_list(TestOutputVisitorData *data, head = p; } - visit_type_TestStructList(data->ov, &head, NULL, &error_abort); + visit_type_TestStructList(data->ov, NULL, &head, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -356,7 +356,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, QObject *obj; qobj = QOBJECT(qint_from_int(-42)); - visit_type_any(data->ov, &qobj, NULL, &error_abort); + visit_type_any(data->ov, NULL, &qobj, &error_abort); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); g_assert(qobject_type(obj) == QTYPE_QINT); @@ -369,7 +369,7 @@ static void test_visitor_out_any(TestOutputVisitorData *data, qdict_put(qdict, "boolean", qbool_from_bool(true)); qdict_put(qdict, "string", qstring_from_str("foo")); qobj = QOBJECT(qdict); - visit_type_any(data->ov, &qobj, NULL, &error_abort); + visit_type_any(data->ov, NULL, &qobj, &error_abort); qobject_decref(qobj); obj = qmp_output_get_qobject(data->qov); g_assert(obj != NULL); @@ -406,7 +406,7 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data, tmp->integer = 41; tmp->u.value1->boolean = true; - visit_type_UserDefFlatUnion(data->ov, &tmp, NULL, &error_abort); + visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort); arg = qmp_output_get_qobject(data->qov); g_assert(qobject_type(arg) == QTYPE_QDICT); @@ -431,7 +431,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->type = QTYPE_QINT; tmp->u.i = 42; - visit_type_UserDefAlternate(data->ov, &tmp, NULL, &error_abort); + visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); arg = qmp_output_get_qobject(data->qov); g_assert(qobject_type(arg) == QTYPE_QINT); @@ -444,7 +444,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, tmp->type = QTYPE_QSTRING; tmp->u.s = g_strdup("hello"); - visit_type_UserDefAlternate(data->ov, &tmp, NULL, &error_abort); + visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); arg = qmp_output_get_qobject(data->qov); g_assert(qobject_type(arg) == QTYPE_QSTRING); @@ -690,7 +690,7 @@ static void test_native_list(TestOutputVisitorData *data, cvalue->type = kind; init_native_list(cvalue); - visit_type_UserDefNativeListUnion(data->ov, &cvalue, NULL, &error_abort); + visit_type_UserDefNativeListUnion(data->ov, NULL, &cvalue, &error_abort); obj = qmp_output_get_qobject(data->qov); check_native_list(obj, cvalue->type); diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-visitor.c index 8e3433e0c7..d99498d098 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -59,7 +59,7 @@ static void test_visitor_in_int(TestInputVisitorData *data, v = visitor_input_test_init(data, "-42"); - visit_type_int(v, &res, NULL, &err); + visit_type_int(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(res, ==, value); } @@ -74,7 +74,7 @@ static void test_visitor_in_intList(TestInputVisitorData *data, v = visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8"); - visit_type_int16List(v, &res, NULL, &error_abort); + visit_type_int16List(v, NULL, &res, &error_abort); tmp = res; while (i < sizeof(value) / sizeof(value[0])) { g_assert(tmp); @@ -100,42 +100,42 @@ static void test_visitor_in_bool(TestInputVisitorData *data, v = visitor_input_test_init(data, "true"); - visit_type_bool(v, &res, NULL, &err); + visit_type_bool(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(res, ==, true); visitor_input_teardown(data, unused); v = visitor_input_test_init(data, "yes"); - visit_type_bool(v, &res, NULL, &err); + visit_type_bool(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(res, ==, true); visitor_input_teardown(data, unused); v = visitor_input_test_init(data, "on"); - visit_type_bool(v, &res, NULL, &err); + visit_type_bool(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(res, ==, true); visitor_input_teardown(data, unused); v = visitor_input_test_init(data, "false"); - visit_type_bool(v, &res, NULL, &err); + visit_type_bool(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(res, ==, false); visitor_input_teardown(data, unused); v = visitor_input_test_init(data, "no"); - visit_type_bool(v, &res, NULL, &err); + visit_type_bool(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(res, ==, false); visitor_input_teardown(data, unused); v = visitor_input_test_init(data, "off"); - visit_type_bool(v, &res, NULL, &err); + visit_type_bool(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(res, ==, false); } @@ -149,7 +149,7 @@ static void test_visitor_in_number(TestInputVisitorData *data, v = visitor_input_test_init(data, "3.14"); - visit_type_number(v, &res, NULL, &err); + visit_type_number(v, NULL, &res, &err); g_assert(!err); g_assert_cmpfloat(res, ==, value); } @@ -163,7 +163,7 @@ static void test_visitor_in_string(TestInputVisitorData *data, v = visitor_input_test_init(data, value); - visit_type_str(v, &res, NULL, &err); + visit_type_str(v, NULL, &res, &err); g_assert(!err); g_assert_cmpstr(res, ==, value); @@ -182,7 +182,7 @@ static void test_visitor_in_enum(TestInputVisitorData *data, v = visitor_input_test_init(data, EnumOne_lookup[i]); - visit_type_EnumOne(v, &res, NULL, &err); + visit_type_EnumOne(v, NULL, &res, &err); g_assert(!err); g_assert_cmpint(i, ==, res); @@ -220,29 +220,29 @@ static void test_visitor_in_fuzz(TestInputVisitorData *data, } v = visitor_input_test_init(data, buf); - visit_type_int(v, &ires, NULL, NULL); + visit_type_int(v, NULL, &ires, NULL); visitor_input_teardown(data, NULL); v = visitor_input_test_init(data, buf); - visit_type_intList(v, &ilres, NULL, NULL); + visit_type_intList(v, NULL, &ilres, NULL); visitor_input_teardown(data, NULL); v = visitor_input_test_init(data, buf); - visit_type_bool(v, &bres, NULL, NULL); + visit_type_bool(v, NULL, &bres, NULL); visitor_input_teardown(data, NULL); v = visitor_input_test_init(data, buf); - visit_type_number(v, &nres, NULL, NULL); + visit_type_number(v, NULL, &nres, NULL); visitor_input_teardown(data, NULL); v = visitor_input_test_init(data, buf); sres = NULL; - visit_type_str(v, &sres, NULL, NULL); + visit_type_str(v, NULL, &sres, NULL); g_free(sres); visitor_input_teardown(data, NULL); v = visitor_input_test_init(data, buf); - visit_type_EnumOne(v, &eres, NULL, NULL); + visit_type_EnumOne(v, NULL, &eres, NULL); visitor_input_teardown(data, NULL); } } diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c index 7aecdfcefb..4f4450fe70 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -61,7 +61,7 @@ static void test_visitor_out_int(TestOutputVisitorData *data, Error *err = NULL; char *str; - visit_type_int(data->ov, &value, NULL, &err); + visit_type_int(data->ov, NULL, &value, &err); g_assert(!err); str = string_output_get_string(data->sov); @@ -90,7 +90,7 @@ static void test_visitor_out_intList(TestOutputVisitorData *data, tmp = &(*tmp)->next; } - visit_type_intList(data->ov, &list, NULL, &err); + visit_type_intList(data->ov, NULL, &list, &err); g_assert(err == NULL); str = string_output_get_string(data->sov); @@ -120,7 +120,7 @@ static void test_visitor_out_bool(TestOutputVisitorData *data, bool value = true; char *str; - visit_type_bool(data->ov, &value, NULL, &err); + visit_type_bool(data->ov, NULL, &value, &err); g_assert(!err); str = string_output_get_string(data->sov); @@ -136,7 +136,7 @@ static void test_visitor_out_number(TestOutputVisitorData *data, Error *err = NULL; char *str; - visit_type_number(data->ov, &value, NULL, &err); + visit_type_number(data->ov, NULL, &value, &err); g_assert(!err); str = string_output_get_string(data->sov); @@ -153,7 +153,7 @@ static void test_visitor_out_string(TestOutputVisitorData *data, Error *err = NULL; char *str; - visit_type_str(data->ov, &string, NULL, &err); + visit_type_str(data->ov, NULL, &string, &err); g_assert(!err); str = string_output_get_string(data->sov); @@ -174,7 +174,7 @@ static void test_visitor_out_no_string(TestOutputVisitorData *data, char *str; /* A null string should return "" */ - visit_type_str(data->ov, &string, NULL, &err); + visit_type_str(data->ov, NULL, &string, &err); g_assert(!err); str = string_output_get_string(data->sov); @@ -197,7 +197,7 @@ static void test_visitor_out_enum(TestOutputVisitorData *data, for (i = 0; i < ENUM_ONE__MAX; i++) { char *str_human; - visit_type_EnumOne(data->ov, &i, "unused", &err); + visit_type_EnumOne(data->ov, "unused", &i, &err); g_assert(!err); str_human = g_strdup_printf("\"%s\"", EnumOne_lookup[i]); @@ -222,7 +222,7 @@ static void test_visitor_out_enum_errors(TestOutputVisitorData *data, for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { err = NULL; - visit_type_EnumOne(data->ov, &bad_values[i], "unused", &err); + visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); g_assert(err); error_free(err); } diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index 9f67f9e003..f74a6df97b 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -101,40 +101,40 @@ static void visit_primitive_type(Visitor *v, void **native, Error **errp) PrimitiveType *pt = *native; switch(pt->type) { case PTYPE_STRING: - visit_type_str(v, (char **)&pt->value.string, NULL, errp); + visit_type_str(v, NULL, (char **)&pt->value.string, errp); break; case PTYPE_BOOLEAN: - visit_type_bool(v, &pt->value.boolean, NULL, errp); + visit_type_bool(v, NULL, &pt->value.boolean, errp); break; case PTYPE_NUMBER: - visit_type_number(v, &pt->value.number, NULL, errp); + visit_type_number(v, NULL, &pt->value.number, errp); break; case PTYPE_INTEGER: - visit_type_int(v, &pt->value.integer, NULL, errp); + visit_type_int(v, NULL, &pt->value.integer, errp); break; case PTYPE_U8: - visit_type_uint8(v, &pt->value.u8, NULL, errp); + visit_type_uint8(v, NULL, &pt->value.u8, errp); break; case PTYPE_U16: - visit_type_uint16(v, &pt->value.u16, NULL, errp); + visit_type_uint16(v, NULL, &pt->value.u16, errp); break; case PTYPE_U32: - visit_type_uint32(v, &pt->value.u32, NULL, errp); + visit_type_uint32(v, NULL, &pt->value.u32, errp); break; case PTYPE_U64: - visit_type_uint64(v, &pt->value.u64, NULL, errp); + visit_type_uint64(v, NULL, &pt->value.u64, errp); break; case PTYPE_S8: - visit_type_int8(v, &pt->value.s8, NULL, errp); + visit_type_int8(v, NULL, &pt->value.s8, errp); break; case PTYPE_S16: - visit_type_int16(v, &pt->value.s16, NULL, errp); + visit_type_int16(v, NULL, &pt->value.s16, errp); break; case PTYPE_S32: - visit_type_int32(v, &pt->value.s32, NULL, errp); + visit_type_int32(v, NULL, &pt->value.s32, errp); break; case PTYPE_S64: - visit_type_int64(v, &pt->value.s64, NULL, errp); + visit_type_int64(v, NULL, &pt->value.s64, errp); break; case PTYPE_EOL: g_assert_not_reached(); @@ -146,40 +146,40 @@ static void visit_primitive_list(Visitor *v, void **native, Error **errp) PrimitiveList *pl = *native; switch (pl->type) { case PTYPE_STRING: - visit_type_strList(v, &pl->value.strings, NULL, errp); + visit_type_strList(v, NULL, &pl->value.strings, errp); break; case PTYPE_BOOLEAN: - visit_type_boolList(v, &pl->value.booleans, NULL, errp); + visit_type_boolList(v, NULL, &pl->value.booleans, errp); break; case PTYPE_NUMBER: - visit_type_numberList(v, &pl->value.numbers, NULL, errp); + visit_type_numberList(v, NULL, &pl->value.numbers, errp); break; case PTYPE_INTEGER: - visit_type_intList(v, &pl->value.integers, NULL, errp); + visit_type_intList(v, NULL, &pl->value.integers, errp); break; case PTYPE_S8: - visit_type_int8List(v, &pl->value.s8_integers, NULL, errp); + visit_type_int8List(v, NULL, &pl->value.s8_integers, errp); break; case PTYPE_S16: - visit_type_int16List(v, &pl->value.s16_integers, NULL, errp); + visit_type_int16List(v, NULL, &pl->value.s16_integers, errp); break; case PTYPE_S32: - visit_type_int32List(v, &pl->value.s32_integers, NULL, errp); + visit_type_int32List(v, NULL, &pl->value.s32_integers, errp); break; case PTYPE_S64: - visit_type_int64List(v, &pl->value.s64_integers, NULL, errp); + visit_type_int64List(v, NULL, &pl->value.s64_integers, errp); break; case PTYPE_U8: - visit_type_uint8List(v, &pl->value.u8_integers, NULL, errp); + visit_type_uint8List(v, NULL, &pl->value.u8_integers, errp); break; case PTYPE_U16: - visit_type_uint16List(v, &pl->value.u16_integers, NULL, errp); + visit_type_uint16List(v, NULL, &pl->value.u16_integers, errp); break; case PTYPE_U32: - visit_type_uint32List(v, &pl->value.u32_integers, NULL, errp); + visit_type_uint32List(v, NULL, &pl->value.u32_integers, errp); break; case PTYPE_U64: - visit_type_uint64List(v, &pl->value.u64_integers, NULL, errp); + visit_type_uint64List(v, NULL, &pl->value.u64_integers, errp); break; default: g_assert_not_reached(); @@ -213,7 +213,7 @@ static void struct_cleanup(TestStruct *ts) static void visit_struct(Visitor *v, void **native, Error **errp) { - visit_type_TestStruct(v, (TestStruct **)native, NULL, errp); + visit_type_TestStruct(v, NULL, (TestStruct **)native, errp); } static UserDefTwo *nested_struct_create(void) @@ -264,12 +264,12 @@ static void nested_struct_cleanup(UserDefTwo *udnp) static void visit_nested_struct(Visitor *v, void **native, Error **errp) { - visit_type_UserDefTwo(v, (UserDefTwo **)native, NULL, errp); + visit_type_UserDefTwo(v, NULL, (UserDefTwo **)native, errp); } static void visit_nested_struct_list(Visitor *v, void **native, Error **errp) { - visit_type_UserDefTwoList(v, (UserDefTwoList **)native, NULL, errp); + visit_type_UserDefTwoList(v, NULL, (UserDefTwoList **)native, errp); } /* test cases */ diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 51354dfb6d..b665cdb98f 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -1117,7 +1117,7 @@ void qapi_copy_SocketAddress(SocketAddress **p_dest, qov = qmp_output_visitor_new(); ov = qmp_output_get_visitor(qov); - visit_type_SocketAddress(ov, &src, NULL, &error_abort); + visit_type_SocketAddress(ov, NULL, &src, &error_abort); obj = qmp_output_get_qobject(qov); qmp_output_visitor_cleanup(qov); if (!obj) { @@ -1126,7 +1126,7 @@ void qapi_copy_SocketAddress(SocketAddress **p_dest, qiv = qmp_input_visitor_new(obj); iv = qmp_input_get_visitor(qiv); - visit_type_SocketAddress(iv, p_dest, NULL, &error_abort); + visit_type_SocketAddress(iv, NULL, p_dest, &error_abort); qmp_input_visitor_cleanup(qiv); qobject_decref(obj); } diff --git a/vl.c b/vl.c index 300a609479..4379beccf7 100644 --- a/vl.c +++ b/vl.c @@ -2837,7 +2837,7 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) } qdict_del(pdict, "qom-type"); - visit_type_str(v, &type, "qom-type", &err); + visit_type_str(v, "qom-type", &type, &err); if (err) { goto out; } @@ -2847,7 +2847,7 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) } qdict_del(pdict, "id"); - visit_type_str(v, &id, "id", &err); + visit_type_str(v, "id", &id, &err); if (err) { goto out_end; } From d7bce9999df85c56c8cb1fcffd944d51bff8ff48 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:55 -0700 Subject: [PATCH 23/31] qom: Swap 'name' next to visitor in ObjectPropertyAccessor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to the previous patch, it's nice to have all functions in the tree that involve a visitor and a name for conversion to or from QAPI to consistently stick the 'name' parameter next to the Visitor parameter. Done by manually changing include/qom/object.h and qom/object.c, then running this Coccinelle script and touching up the fallout (Coccinelle insisted on adding some trailing whitespace). @ rule1 @ identifier fn; typedef Object, Visitor, Error; identifier obj, v, opaque, name, errp; @@ void fn - (Object *obj, Visitor *v, void *opaque, const char *name, + (Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { ... } @@ identifier rule1.fn; expression obj, v, opaque, name, errp; @@ fn(obj, v, - opaque, name, + name, opaque, errp) Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- backends/hostmem.c | 16 ++--- bootdevice.c | 8 +-- hw/acpi/ich9.c | 35 ++++------ hw/core/machine.c | 14 ++-- hw/core/qdev-properties-system.c | 32 ++++----- hw/core/qdev-properties.c | 116 +++++++++++++++---------------- hw/core/qdev.c | 5 +- hw/i386/pc.c | 29 ++++---- hw/ide/qdev.c | 8 +-- hw/intc/xics.c | 12 ++-- hw/isa/lpc_ich9.c | 5 +- hw/mem/pc-dimm.c | 4 +- hw/misc/edu.c | 4 +- hw/misc/tmp105.c | 8 +-- hw/net/ne2000-isa.c | 10 +-- hw/pci-host/piix.c | 10 +-- hw/pci-host/q35.c | 13 ++-- hw/ppc/spapr_drc.c | 16 ++--- hw/usb/dev-storage.c | 8 +-- hw/virtio/virtio-balloon.c | 8 +-- include/qom/object.h | 4 +- memory.c | 18 ++--- net/dump.c | 8 +-- net/filter-buffer.c | 10 +-- qom/object.c | 75 ++++++++++---------- target-i386/cpu.c | 67 +++++++++--------- target-ppc/translate_init.c | 8 +-- tests/test-qdev-global-props.c | 14 ++-- 28 files changed, 278 insertions(+), 287 deletions(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index da80662fcd..6c6f0da6d9 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -27,8 +27,8 @@ QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_INTERLEAVE != MPOL_INTERLEAVE); #endif static void -host_memory_backend_get_size(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +host_memory_backend_get_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { HostMemoryBackend *backend = MEMORY_BACKEND(obj); uint64_t value = backend->size; @@ -37,8 +37,8 @@ host_memory_backend_get_size(Object *obj, Visitor *v, void *opaque, } static void -host_memory_backend_set_size(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +host_memory_backend_set_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { HostMemoryBackend *backend = MEMORY_BACKEND(obj); Error *local_err = NULL; @@ -64,8 +64,8 @@ out: } static void -host_memory_backend_get_host_nodes(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { HostMemoryBackend *backend = MEMORY_BACKEND(obj); uint16List *host_nodes = NULL; @@ -96,8 +96,8 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, void *opaque, } static void -host_memory_backend_set_host_nodes(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +host_memory_backend_set_host_nodes(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { #ifdef CONFIG_NUMA HostMemoryBackend *backend = MEMORY_BACKEND(obj); diff --git a/bootdevice.c b/bootdevice.c index 149ee3aaf0..dbc0159392 100644 --- a/bootdevice.c +++ b/bootdevice.c @@ -271,15 +271,15 @@ typedef struct { DeviceState *dev; } BootIndexProperty; -static void device_get_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void device_get_bootindex(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { BootIndexProperty *prop = opaque; visit_type_int32(v, name, prop->bootindex, errp); } -static void device_set_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void device_set_bootindex(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { BootIndexProperty *prop = opaque; int32_t boot_index; diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c index c3b6035f34..4f9ce05d04 100644 --- a/hw/acpi/ich9.c +++ b/hw/acpi/ich9.c @@ -283,9 +283,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, } } -static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; uint32_t value = pm->pm_io_base + ICH9_PMIO_GPE0_STS; @@ -308,9 +307,8 @@ static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value, s->pm.acpi_memory_hotplug.is_enabled = value; } -static void ich9_pm_get_disable_s3(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_pm_get_disable_s3(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; uint8_t value = pm->disable_s3; @@ -318,9 +316,8 @@ static void ich9_pm_get_disable_s3(Object *obj, Visitor *v, visit_type_uint8(v, name, &value, errp); } -static void ich9_pm_set_disable_s3(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_pm_set_disable_s3(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; Error *local_err = NULL; @@ -335,9 +332,8 @@ out: error_propagate(errp, local_err); } -static void ich9_pm_get_disable_s4(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_pm_get_disable_s4(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; uint8_t value = pm->disable_s4; @@ -345,9 +341,8 @@ static void ich9_pm_get_disable_s4(Object *obj, Visitor *v, visit_type_uint8(v, name, &value, errp); } -static void ich9_pm_set_disable_s4(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_pm_set_disable_s4(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; Error *local_err = NULL; @@ -362,9 +357,8 @@ out: error_propagate(errp, local_err); } -static void ich9_pm_get_s4_val(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_pm_get_s4_val(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; uint8_t value = pm->s4_val; @@ -372,9 +366,8 @@ static void ich9_pm_get_s4_val(Object *obj, Visitor *v, visit_type_uint8(v, name, &value, errp); } -static void ich9_pm_set_s4_val(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_pm_set_s4_val(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCPMRegs *pm = opaque; Error *local_err = NULL; diff --git a/hw/core/machine.c b/hw/core/machine.c index 03d9a951b2..6d1a0d8eeb 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -34,7 +34,7 @@ static void machine_set_accel(Object *obj, const char *value, Error **errp) } static void machine_set_kernel_irqchip(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { Error *err = NULL; @@ -69,7 +69,7 @@ static void machine_set_kernel_irqchip(Object *obj, Visitor *v, } static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { MachineState *ms = MACHINE(obj); @@ -79,7 +79,7 @@ static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v, } static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { MachineState *ms = MACHINE(obj); @@ -171,8 +171,8 @@ static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) } static void machine_get_phandle_start(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) + const char *name, void *opaque, + Error **errp) { MachineState *ms = MACHINE(obj); int64_t value = ms->phandle_start; @@ -181,8 +181,8 @@ static void machine_get_phandle_start(Object *obj, Visitor *v, } static void machine_set_phandle_start(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) + const char *name, void *opaque, + Error **errp) { MachineState *ms = MACHINE(obj); Error *error = NULL; diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index acbe403c63..e10cede749 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -112,14 +112,14 @@ static char *print_drive(void *ptr) return g_strdup(blk_name(ptr)); } -static void get_drive(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { get_pointer(obj, v, opaque, print_drive, name, errp); } -static void set_drive(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { set_pointer(obj, v, opaque, parse_drive, name, errp); } @@ -173,14 +173,14 @@ static char *print_chr(void *ptr) return g_strdup(val); } -static void get_chr(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_chr(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { get_pointer(obj, v, opaque, print_chr, name, errp); } -static void set_chr(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { set_pointer(obj, v, opaque, parse_chr, name, errp); } @@ -194,8 +194,8 @@ PropertyInfo qdev_prop_chr = { }; /* --- netdev device --- */ -static void get_netdev(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_netdev(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -206,8 +206,8 @@ static void get_netdev(Object *obj, Visitor *v, void *opaque, g_free(p); } -static void set_netdev(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_netdev(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -293,8 +293,8 @@ static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len) return snprintf(dest, len, ""); } -static void get_vlan(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_vlan(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -311,8 +311,8 @@ static void get_vlan(Object *obj, Visitor *v, void *opaque, visit_type_int32(v, name, &id, errp); } -static void set_vlan(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_vlan(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 77f354233f..6a9289921f 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -42,8 +42,8 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) return ptr; } -static void get_enum(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_enum(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -53,8 +53,8 @@ static void get_enum(Object *obj, Visitor *v, void *opaque, prop->info->name, errp); } -static void set_enum(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -88,8 +88,8 @@ static void bit_prop_set(DeviceState *dev, Property *props, bool val) } } -static void prop_get_bit(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_get_bit(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -99,8 +99,8 @@ static void prop_get_bit(Object *obj, Visitor *v, void *opaque, visit_type_bool(v, name, &value, errp); } -static void prop_set_bit(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_set_bit(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -146,8 +146,8 @@ static void bit64_prop_set(DeviceState *dev, Property *props, bool val) } } -static void prop_get_bit64(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_get_bit64(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -157,8 +157,8 @@ static void prop_get_bit64(Object *obj, Visitor *v, void *opaque, visit_type_bool(v, name, &value, errp); } -static void prop_set_bit64(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_set_bit64(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -187,8 +187,8 @@ PropertyInfo qdev_prop_bit64 = { /* --- bool --- */ -static void get_bool(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -197,8 +197,8 @@ static void get_bool(Object *obj, Visitor *v, void *opaque, visit_type_bool(v, name, ptr, errp); } -static void set_bool(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_bool(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -220,8 +220,8 @@ PropertyInfo qdev_prop_bool = { /* --- 8bit integer --- */ -static void get_uint8(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_uint8(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -230,8 +230,8 @@ static void get_uint8(Object *obj, Visitor *v, void *opaque, visit_type_uint8(v, name, ptr, errp); } -static void set_uint8(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_uint8(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -253,8 +253,8 @@ PropertyInfo qdev_prop_uint8 = { /* --- 16bit integer --- */ -static void get_uint16(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_uint16(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -263,8 +263,8 @@ static void get_uint16(Object *obj, Visitor *v, void *opaque, visit_type_uint16(v, name, ptr, errp); } -static void set_uint16(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_uint16(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -286,8 +286,8 @@ PropertyInfo qdev_prop_uint16 = { /* --- 32bit integer --- */ -static void get_uint32(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_uint32(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -296,8 +296,8 @@ static void get_uint32(Object *obj, Visitor *v, void *opaque, visit_type_uint32(v, name, ptr, errp); } -static void set_uint32(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_uint32(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -311,8 +311,8 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque, visit_type_uint32(v, name, ptr, errp); } -static void get_int32(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_int32(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -321,8 +321,8 @@ static void get_int32(Object *obj, Visitor *v, void *opaque, visit_type_int32(v, name, ptr, errp); } -static void set_int32(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_int32(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -350,8 +350,8 @@ PropertyInfo qdev_prop_int32 = { /* --- 64bit integer --- */ -static void get_uint64(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_uint64(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -360,8 +360,8 @@ static void get_uint64(Object *obj, Visitor *v, void *opaque, visit_type_uint64(v, name, ptr, errp); } -static void set_uint64(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_uint64(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -389,8 +389,8 @@ static void release_string(Object *obj, const char *name, void *opaque) g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj), prop)); } -static void get_string(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_string(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -404,8 +404,8 @@ static void get_string(Object *obj, Visitor *v, void *opaque, } } -static void set_string(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_string(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -448,8 +448,8 @@ PropertyInfo qdev_prop_ptr = { * 01:02:03:04:05:06 * 01-02-03-04-05-06 */ -static void get_mac(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_mac(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -464,8 +464,8 @@ static void get_mac(Object *obj, Visitor *v, void *opaque, visit_type_str(v, name, &p, errp); } -static void set_mac(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -558,8 +558,8 @@ PropertyInfo qdev_prop_fdc_drive_type = { /* * bus-local address, i.e. "$slot" or "$slot.$fn" */ -static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_pci_devfn(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -629,8 +629,8 @@ PropertyInfo qdev_prop_pci_devfn = { /* --- blocksize --- */ -static void set_blocksize(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_blocksize(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -676,8 +676,8 @@ PropertyInfo qdev_prop_blocksize = { /* --- pci host address --- */ -static void get_pci_host_devaddr(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -697,8 +697,8 @@ static void get_pci_host_devaddr(Object *obj, Visitor *v, void *opaque, * Parse [:]:. * if is not supplied, it's assumed to be 0. */ -static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -811,8 +811,8 @@ static void array_element_release(Object *obj, const char *name, void *opaque) g_free(p); } -static void set_prop_arraylen(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_prop_arraylen(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { /* Setter for the property which defines the length of a * variable-sized property array. As well as actually setting the @@ -1094,8 +1094,8 @@ void qdev_prop_set_globals(DeviceState *dev) /* --- 64bit unsigned int 'size' type --- */ -static void get_size(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void get_size(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; @@ -1104,8 +1104,8 @@ static void get_size(Object *obj, Visitor *v, void *opaque, visit_type_size(v, name, ptr, errp); } -static void set_size(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void set_size(Object *obj, Visitor *v, const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index c731bb2032..db41aa1f26 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -893,8 +893,9 @@ char *qdev_get_dev_path(DeviceState *dev) * Legacy property handling */ -static void qdev_get_legacy_property(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void qdev_get_legacy_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 5dcdde412e..0aeefd2c0d 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1741,8 +1741,9 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState *machine, } static void -pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); int64_t value = memory_region_size(&pcms->hotplug_memory.mr); @@ -1751,8 +1752,8 @@ pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque, } static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) + const char *name, void *opaque, + Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); uint64_t value = pcms->max_ram_below_4g; @@ -1761,8 +1762,8 @@ static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v, } static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) + const char *name, void *opaque, + Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); Error *error = NULL; @@ -1790,8 +1791,8 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v, pcms->max_ram_below_4g = value; } -static void pc_machine_get_vmport(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void pc_machine_get_vmport(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); OnOffAuto vmport = pcms->vmport; @@ -1799,8 +1800,8 @@ static void pc_machine_get_vmport(Object *obj, Visitor *v, void *opaque, visit_type_OnOffAuto(v, name, &vmport, errp); } -static void pc_machine_set_vmport(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void pc_machine_set_vmport(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); @@ -1832,8 +1833,8 @@ bool pc_machine_is_smm_enabled(PCMachineState *pcms) return false; } -static void pc_machine_get_smm(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void pc_machine_get_smm(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); OnOffAuto smm = pcms->smm; @@ -1841,8 +1842,8 @@ static void pc_machine_get_smm(Object *obj, Visitor *v, void *opaque, visit_type_OnOffAuto(v, name, &smm, errp); } -static void pc_machine_set_smm(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void pc_machine_set_smm(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 572f61dbd4..2d14a768f1 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -200,16 +200,16 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) return 0; } -static void ide_dev_get_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { IDEDevice *d = IDE_DEVICE(obj); visit_type_int32(v, name, &d->conf.bootindex, errp); } -static void ide_dev_set_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { IDEDevice *d = IDE_DEVICE(obj); int32_t boot_index; diff --git a/hw/intc/xics.c b/hw/intc/xics.c index dafcdeb1e0..e66ae32881 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -89,8 +89,8 @@ static void xics_common_reset(DeviceState *d) device_reset(DEVICE(icp->ics)); } -static void xics_prop_get_nr_irqs(Object *obj, Visitor *v, - void *opaque, const char *name, Error **errp) +static void xics_prop_get_nr_irqs(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { XICSState *icp = XICS_COMMON(obj); int64_t value = icp->nr_irqs; @@ -98,8 +98,8 @@ static void xics_prop_get_nr_irqs(Object *obj, Visitor *v, visit_type_int(v, name, &value, errp); } -static void xics_prop_set_nr_irqs(Object *obj, Visitor *v, - void *opaque, const char *name, Error **errp) +static void xics_prop_set_nr_irqs(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { XICSState *icp = XICS_COMMON(obj); XICSStateClass *info = XICS_COMMON_GET_CLASS(icp); @@ -123,7 +123,7 @@ static void xics_prop_set_nr_irqs(Object *obj, Visitor *v, } static void xics_prop_get_nr_servers(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { XICSState *icp = XICS_COMMON(obj); @@ -133,7 +133,7 @@ static void xics_prop_get_nr_servers(Object *obj, Visitor *v, } static void xics_prop_set_nr_servers(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { XICSState *icp = XICS_COMMON(obj); diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c index e439955789..6cf2eb607d 100644 --- a/hw/isa/lpc_ich9.c +++ b/hw/isa/lpc_ich9.c @@ -570,9 +570,8 @@ Object *ich9_lpc_find(void) return o; } -static void ich9_lpc_get_sci_int(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void ich9_lpc_get_sci_int(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { ICH9LPCState *lpc = ICH9_LPC_DEVICE(obj); uint32_t value = ich9_lpc_sci_irq(lpc); diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 6514428265..1aa12c64d0 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -373,8 +373,8 @@ static Property pc_dimm_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void pc_dimm_get_size(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { int64_t value; MemoryRegion *mr; diff --git a/hw/misc/edu.c b/hw/misc/edu.c index 1486441d7c..888ba49a0e 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -363,8 +363,8 @@ static void pci_edu_uninit(PCIDevice *pdev) timer_del(&edu->dma_timer); } -static void edu_obj_uint64(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void edu_obj_uint64(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { uint64_t *val = opaque; diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c index 562d8cc643..b53f6babad 100644 --- a/hw/misc/tmp105.c +++ b/hw/misc/tmp105.c @@ -53,8 +53,8 @@ static void tmp105_alarm_update(TMP105State *s) tmp105_interrupt_update(s); } -static void tmp105_get_temperature(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { TMP105State *s = TMP105(obj); int64_t value = s->temperature * 1000 / 256; @@ -65,8 +65,8 @@ static void tmp105_get_temperature(Object *obj, Visitor *v, void *opaque, /* Units are 0.001 centigrades relative to 0 C. s->temperature is 8.8 * fixed point, so units are 1/256 centigrades. A simple ratio will do. */ -static void tmp105_set_temperature(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { TMP105State *s = TMP105(obj); Error *local_err = NULL; diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index 6d1e963fc1..8dca7c936b 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -94,8 +94,9 @@ static void isa_ne2000_class_initfn(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); } -static void isa_ne2000_get_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void isa_ne2000_get_bootindex(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { ISANE2000State *isa = ISA_NE2000(obj); NE2000State *s = &isa->ne2000; @@ -103,8 +104,9 @@ static void isa_ne2000_get_bootindex(Object *obj, Visitor *v, void *opaque, visit_type_int32(v, name, &s->c.bootindex, errp); } -static void isa_ne2000_set_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void isa_ne2000_set_bootindex(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { ISANE2000State *isa = ISA_NE2000(obj); NE2000State *s = &isa->ne2000; diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 8ff5c6b0b0..41aa66f828 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -216,7 +216,7 @@ static const VMStateDescription vmstate_i440fx = { }; static void i440fx_pcihost_get_pci_hole_start(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { I440FXState *s = I440FX_PCI_HOST_BRIDGE(obj); @@ -226,7 +226,7 @@ static void i440fx_pcihost_get_pci_hole_start(Object *obj, Visitor *v, } static void i440fx_pcihost_get_pci_hole_end(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { I440FXState *s = I440FX_PCI_HOST_BRIDGE(obj); @@ -236,8 +236,8 @@ static void i440fx_pcihost_get_pci_hole_end(Object *obj, Visitor *v, } static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) + const char *name, + void *opaque, Error **errp) { PCIHostState *h = PCI_HOST_BRIDGE(obj); Range w64; @@ -248,7 +248,7 @@ static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v, } static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { PCIHostState *h = PCI_HOST_BRIDGE(obj); diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 0966eb5c89..115fb8c046 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -68,7 +68,7 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge, } static void q35_host_get_pci_hole_start(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { Q35PCIHost *s = Q35_HOST_DEVICE(obj); @@ -78,7 +78,7 @@ static void q35_host_get_pci_hole_start(Object *obj, Visitor *v, } static void q35_host_get_pci_hole_end(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { Q35PCIHost *s = Q35_HOST_DEVICE(obj); @@ -88,7 +88,7 @@ static void q35_host_get_pci_hole_end(Object *obj, Visitor *v, } static void q35_host_get_pci_hole64_start(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { PCIHostState *h = PCI_HOST_BRIDGE(obj); @@ -100,7 +100,7 @@ static void q35_host_get_pci_hole64_start(Object *obj, Visitor *v, } static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { PCIHostState *h = PCI_HOST_BRIDGE(obj); @@ -111,9 +111,8 @@ static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v, visit_type_uint64(v, name, &w64.end, errp); } -static void q35_host_get_mmcfg_size(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void q35_host_get_mmcfg_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { PCIExpressHost *e = PCIE_HOST_BRIDGE(obj); uint32_t value = e->size; diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index fda6a95288..e40617faba 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -215,8 +215,8 @@ static uint32_t entity_sense(sPAPRDRConnector *drc, sPAPRDREntitySense *state) return RTAS_OUT_SUCCESS; } -static void prop_get_index(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_get_index(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj); sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); @@ -224,8 +224,8 @@ static void prop_get_index(Object *obj, Visitor *v, void *opaque, visit_type_uint32(v, name, &value, errp); } -static void prop_get_type(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_get_type(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj); sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); @@ -240,8 +240,8 @@ static char *prop_get_name(Object *obj, Error **errp) return g_strdup(drck->get_name(drc)); } -static void prop_get_entity_sense(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_get_entity_sense(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj); sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); @@ -251,8 +251,8 @@ static void prop_get_entity_sense(Object *obj, Visitor *v, void *opaque, visit_type_uint32(v, name, &value, errp); } -static void prop_get_fdt(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void prop_get_fdt(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj); Error *err = NULL; diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index dafbea3484..5ae0424923 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -781,8 +781,8 @@ static void usb_msd_class_initfn_storage(ObjectClass *klass, void *data) dc->props = msd_properties; } -static void usb_msd_get_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void usb_msd_get_bootindex(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { USBDevice *dev = USB_DEVICE(obj); MSDState *s = USB_STORAGE_DEV(dev); @@ -790,8 +790,8 @@ static void usb_msd_get_bootindex(Object *obj, Visitor *v, void *opaque, visit_type_int32(v, name, &s->conf.bootindex, errp); } -static void usb_msd_set_bootindex(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void usb_msd_set_bootindex(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { USBDevice *dev = USB_DEVICE(obj); MSDState *s = USB_STORAGE_DEV(dev); diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index b46cb580a0..0d7033a572 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -113,8 +113,8 @@ static void balloon_stats_poll_cb(void *opaque) s->stats_vq_elem = NULL; } -static void balloon_stats_get_all(Object *obj, Visitor *v, - void *opaque, const char *name, Error **errp) +static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { Error *err = NULL; VirtIOBalloon *s = opaque; @@ -152,7 +152,7 @@ out: } static void balloon_stats_get_poll_interval(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { VirtIOBalloon *s = opaque; @@ -160,7 +160,7 @@ static void balloon_stats_get_poll_interval(Object *obj, Visitor *v, } static void balloon_stats_set_poll_interval(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { VirtIOBalloon *s = opaque; diff --git a/include/qom/object.h b/include/qom/object.h index 3e7e99dff1..698827d948 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -290,16 +290,16 @@ typedef struct InterfaceInfo InterfaceInfo; * ObjectPropertyAccessor: * @obj: the object that owns the property * @v: the visitor that contains the property data - * @opaque: the object property opaque * @name: the name of the property + * @opaque: the object property opaque * @errp: a pointer to an Error that is filled if getting/setting fails. * * Called when trying to get/set a property. */ typedef void (ObjectPropertyAccessor)(Object *obj, Visitor *v, - void *opaque, const char *name, + void *opaque, Error **errp); /** diff --git a/memory.c b/memory.c index 1618dc8914..09041edd43 100644 --- a/memory.c +++ b/memory.c @@ -928,8 +928,8 @@ void memory_region_init(MemoryRegion *mr, } } -static void memory_region_get_addr(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void memory_region_get_addr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { MemoryRegion *mr = MEMORY_REGION(obj); uint64_t value = mr->addr; @@ -937,8 +937,9 @@ static void memory_region_get_addr(Object *obj, Visitor *v, void *opaque, visit_type_uint64(v, name, &value, errp); } -static void memory_region_get_container(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void memory_region_get_container(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { MemoryRegion *mr = MEMORY_REGION(obj); gchar *path = (gchar *)""; @@ -960,8 +961,9 @@ static Object *memory_region_resolve_container(Object *obj, void *opaque, return OBJECT(mr->container); } -static void memory_region_get_priority(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void memory_region_get_priority(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { MemoryRegion *mr = MEMORY_REGION(obj); int32_t value = mr->priority; @@ -976,8 +978,8 @@ static bool memory_region_get_may_overlap(Object *obj, Error **errp) return mr->may_overlap; } -static void memory_region_get_size(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void memory_region_get_size(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { MemoryRegion *mr = MEMORY_REGION(obj); uint64_t value = memory_region_size(mr); diff --git a/net/dump.c b/net/dump.c index 60bc5ce66e..61dec9d61d 100644 --- a/net/dump.c +++ b/net/dump.c @@ -272,8 +272,8 @@ static void filter_dump_setup(NetFilterState *nf, Error **errp) net_dump_state_init(&nfds->ds, nfds->filename, nfds->maxlen, errp); } -static void filter_dump_get_maxlen(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void filter_dump_get_maxlen(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { NetFilterDumpState *nfds = FILTER_DUMP(obj); uint32_t value = nfds->maxlen; @@ -281,8 +281,8 @@ static void filter_dump_get_maxlen(Object *obj, Visitor *v, void *opaque, visit_type_uint32(v, name, &value, errp); } -static void filter_dump_set_maxlen(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void filter_dump_set_maxlen(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { NetFilterDumpState *nfds = FILTER_DUMP(obj); Error *local_err = NULL; diff --git a/net/filter-buffer.c b/net/filter-buffer.c index 236d950c31..12ad2e30d4 100644 --- a/net/filter-buffer.c +++ b/net/filter-buffer.c @@ -133,8 +133,9 @@ static void filter_buffer_class_init(ObjectClass *oc, void *data) nfc->receive_iov = filter_buffer_receive_iov; } -static void filter_buffer_get_interval(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void filter_buffer_get_interval(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { FilterBufferState *s = FILTER_BUFFER(obj); uint32_t value = s->interval; @@ -142,8 +143,9 @@ static void filter_buffer_get_interval(Object *obj, Visitor *v, void *opaque, visit_type_uint32(v, name, &value, errp); } -static void filter_buffer_set_interval(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void filter_buffer_set_interval(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { FilterBufferState *s = FILTER_BUFFER(obj); Error *local_err = NULL; diff --git a/qom/object.c b/qom/object.c index 66cafacf9a..db40ae71f5 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1062,7 +1062,7 @@ void object_property_get(Object *obj, Visitor *v, const char *name, if (!prop->get) { error_setg(errp, QERR_PERMISSION_DENIED); } else { - prop->get(obj, v, prop->opaque, name, errp); + prop->get(obj, v, name, prop->opaque, errp); } } @@ -1077,7 +1077,7 @@ void object_property_set(Object *obj, Visitor *v, const char *name, if (!prop->set) { error_setg(errp, QERR_PERMISSION_DENIED); } else { - prop->set(obj, v, prop->opaque, name, errp); + prop->set(obj, v, name, prop->opaque, errp); } } @@ -1335,8 +1335,9 @@ Object *object_get_objects_root(void) return container_get(object_get_root(), "/objects"); } -static void object_get_child_property(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void object_get_child_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { Object *child = opaque; gchar *path; @@ -1404,8 +1405,9 @@ typedef struct { ObjectPropertyLinkFlags flags; } LinkProperty; -static void object_get_link_property(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void object_get_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { LinkProperty *lprop = opaque; Object **child = lprop->child; @@ -1461,8 +1463,9 @@ static Object *object_resolve_link(Object *obj, const char *name, return target; } -static void object_set_link_property(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void object_set_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { Error *local_err = NULL; LinkProperty *prop = opaque; @@ -1725,8 +1728,8 @@ typedef struct StringProperty void (*set)(Object *, const char *, Error **); } StringProperty; -static void property_get_str(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_get_str(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { StringProperty *prop = opaque; char *value; @@ -1742,8 +1745,8 @@ static void property_get_str(Object *obj, Visitor *v, void *opaque, g_free(value); } -static void property_set_str(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_set_str(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { StringProperty *prop = opaque; char *value; @@ -1817,8 +1820,8 @@ typedef struct BoolProperty void (*set)(Object *, bool, Error **); } BoolProperty; -static void property_get_bool(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_get_bool(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { BoolProperty *prop = opaque; bool value; @@ -1833,8 +1836,8 @@ static void property_get_bool(Object *obj, Visitor *v, void *opaque, visit_type_bool(v, name, &value, errp); } -static void property_set_bool(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_set_bool(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { BoolProperty *prop = opaque; bool value; @@ -1900,8 +1903,8 @@ void object_class_property_add_bool(ObjectClass *klass, const char *name, } } -static void property_get_enum(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_get_enum(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { EnumProperty *prop = opaque; int value; @@ -1916,8 +1919,8 @@ static void property_get_enum(Object *obj, Visitor *v, void *opaque, visit_type_enum(v, name, &value, prop->strings, NULL, errp); } -static void property_set_enum(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_set_enum(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { EnumProperty *prop = opaque; int value; @@ -1992,8 +1995,8 @@ typedef struct TMProperty { void (*get)(Object *, struct tm *, Error **); } TMProperty; -static void property_get_tm(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_get_tm(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { TMProperty *prop = opaque; Error *err = NULL; @@ -2091,33 +2094,29 @@ static char *qdev_get_type(Object *obj, Error **errp) return g_strdup(object_get_typename(obj)); } -static void property_get_uint8_ptr(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void property_get_uint8_ptr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { uint8_t value = *(uint8_t *)opaque; visit_type_uint8(v, name, &value, errp); } -static void property_get_uint16_ptr(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void property_get_uint16_ptr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { uint16_t value = *(uint16_t *)opaque; visit_type_uint16(v, name, &value, errp); } -static void property_get_uint32_ptr(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void property_get_uint32_ptr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { uint32_t value = *(uint32_t *)opaque; visit_type_uint32(v, name, &value, errp); } -static void property_get_uint64_ptr(Object *obj, Visitor *v, - void *opaque, const char *name, - Error **errp) +static void property_get_uint64_ptr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { uint64_t value = *(uint64_t *)opaque; visit_type_uint64(v, name, &value, errp); @@ -2184,16 +2183,16 @@ typedef struct { char *target_name; } AliasProperty; -static void property_get_alias(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_get_alias(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { AliasProperty *prop = opaque; object_property_get(prop->target_obj, v, prop->target_name, errp); } -static void property_set_alias(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void property_set_alias(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { AliasProperty *prop = opaque; diff --git a/target-i386/cpu.c b/target-i386/cpu.c index c9b8b16b3a..3fa14bf171 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1530,8 +1530,9 @@ static void report_unavailable_features(FeatureWord w, uint32_t mask) } } -static void x86_cpuid_version_get_family(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_version_get_family(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { X86CPU *cpu = X86_CPU(obj); CPUX86State *env = &cpu->env; @@ -1544,8 +1545,9 @@ static void x86_cpuid_version_get_family(Object *obj, Visitor *v, void *opaque, visit_type_int(v, name, &value, errp); } -static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_version_set_family(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { X86CPU *cpu = X86_CPU(obj); CPUX86State *env = &cpu->env; @@ -1573,8 +1575,9 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, } } -static void x86_cpuid_version_get_model(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_version_get_model(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { X86CPU *cpu = X86_CPU(obj); CPUX86State *env = &cpu->env; @@ -1585,8 +1588,9 @@ static void x86_cpuid_version_get_model(Object *obj, Visitor *v, void *opaque, visit_type_int(v, name, &value, errp); } -static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_version_set_model(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { X86CPU *cpu = X86_CPU(obj); CPUX86State *env = &cpu->env; @@ -1611,7 +1615,7 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, } static void x86_cpuid_version_get_stepping(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { X86CPU *cpu = X86_CPU(obj); @@ -1623,7 +1627,7 @@ static void x86_cpuid_version_get_stepping(Object *obj, Visitor *v, } static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, - void *opaque, const char *name, + const char *name, void *opaque, Error **errp) { X86CPU *cpu = X86_CPU(obj); @@ -1719,8 +1723,8 @@ static void x86_cpuid_set_model_id(Object *obj, const char *model_id, } } -static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { X86CPU *cpu = X86_CPU(obj); int64_t value; @@ -1729,8 +1733,8 @@ static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque, visit_type_int(v, name, &value, errp); } -static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { X86CPU *cpu = X86_CPU(obj); const int64_t min = 0; @@ -1752,8 +1756,8 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, cpu->env.tsc_khz = cpu->env.user_tsc_khz = value / 1000; } -static void x86_cpuid_get_apic_id(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_get_apic_id(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { X86CPU *cpu = X86_CPU(obj); int64_t value = cpu->apic_id; @@ -1761,8 +1765,8 @@ static void x86_cpuid_get_apic_id(Object *obj, Visitor *v, void *opaque, visit_type_int(v, name, &value, errp); } -static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { X86CPU *cpu = X86_CPU(obj); DeviceState *dev = DEVICE(obj); @@ -1797,8 +1801,9 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, } /* Generic getter for "feature-words" and "filtered-features" properties */ -static void x86_cpu_get_feature_words(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_cpu_get_feature_words(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { uint32_t *array = (uint32_t *)opaque; FeatureWord w; @@ -1826,8 +1831,8 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, void *opaque, error_propagate(errp, err); } -static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_get_hv_spinlocks(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { X86CPU *cpu = X86_CPU(obj); int64_t value = cpu->hyperv_spinlock_attempts; @@ -1835,8 +1840,8 @@ static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque, visit_type_int(v, name, &value, errp); } -static void x86_set_hv_spinlocks(Object *obj, Visitor *v, void *opaque, - const char *name, Error **errp) +static void x86_set_hv_spinlocks(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { const int64_t min = 0xFFF; const int64_t max = UINT_MAX; @@ -2944,22 +2949,16 @@ typedef struct BitProperty { uint32_t mask; } BitProperty; -static void x86_cpu_get_bit_prop(Object *obj, - Visitor *v, - void *opaque, - const char *name, - Error **errp) +static void x86_cpu_get_bit_prop(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { BitProperty *fp = opaque; bool value = (*fp->ptr & fp->mask) == fp->mask; visit_type_bool(v, name, &value, errp); } -static void x86_cpu_set_bit_prop(Object *obj, - Visitor *v, - void *opaque, - const char *name, - Error **errp) +static void x86_cpu_set_bit_prop(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); BitProperty *fp = opaque; diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 82f85f9ba2..bd0cffca23 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -8035,8 +8035,8 @@ POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data) pcc->l1_icache_size = 0x10000; } -static void powerpc_get_compat(Object *obj, Visitor *v, - void *opaque, const char *name, Error **errp) +static void powerpc_get_compat(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { char *value = (char *)""; Property *prop = opaque; @@ -8063,8 +8063,8 @@ static void powerpc_get_compat(Object *obj, Visitor *v, visit_type_str(v, name, &value, errp); } -static void powerpc_set_compat(Object *obj, Visitor *v, - void *opaque, const char *name, Error **errp) +static void powerpc_set_compat(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { Error *error = NULL; char *value = NULL; diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c index e728611b31..07c182338b 100644 --- a/tests/test-qdev-global-props.c +++ b/tests/test-qdev-global-props.c @@ -116,22 +116,16 @@ static void test_static_globalprop(void) #define TYPE_UNUSED_HOTPLUG "hotplug-type" #define TYPE_UNUSED_NOHOTPLUG "nohotplug-type" -static void prop1_accessor(Object *obj, - Visitor *v, - void *opaque, - const char *name, - Error **errp) +static void prop1_accessor(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { MyType *mt = DYNAMIC_TYPE(obj); visit_type_uint32(v, name, &mt->prop1, errp); } -static void prop2_accessor(Object *obj, - Visitor *v, - void *opaque, - const char *name, - Error **errp) +static void prop2_accessor(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) { MyType *mt = DYNAMIC_TYPE(obj); From 0b2a0d6bb2446060944061e53e87d0c7addede79 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:56 -0700 Subject: [PATCH 24/31] qapi: Swap 'name' in visit_* callbacks to match public API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As explained in the previous patches, matching argument order of 'name, &value' to JSON's "name":value makes sense. However, while the last two patches were easy with Coccinelle, I ended up doing this one all by hand. Now all the visitor callbacks match the main interface. The compiler is able to enforce that all clients match the changed interface in visitor-impl.h, even where two pointers are being swapped, because only one of the two pointers is const (if that were not the case, then C's looseness on treating 'char *' like 'void *' would have made review a bit harder). Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-21-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- include/qapi/visitor-impl.h | 39 +++++++++++++++++++----------------- qapi/opts-visitor.c | 16 +++++++-------- qapi/qapi-dealloc-visitor.c | 25 +++++++++++------------ qapi/qapi-visit-core.c | 38 +++++++++++++++++------------------ qapi/qmp-input-visitor.c | 22 ++++++++++---------- qapi/qmp-output-visitor.c | 16 +++++++-------- qapi/string-input-visitor.c | 16 +++++++-------- qapi/string-output-visitor.c | 16 +++++++-------- 8 files changed, 95 insertions(+), 93 deletions(-) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 29e2c087fe..734cc13854 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -18,8 +18,8 @@ struct Visitor { /* Must be set */ - void (*start_struct)(Visitor *v, void **obj, const char *kind, - const char *name, size_t size, Error **errp); + void (*start_struct)(Visitor *v, const char *name, void **obj, + const char *kind, size_t size, Error **errp); void (*end_struct)(Visitor *v, Error **errp); void (*start_implicit_struct)(Visitor *v, void **obj, size_t size, @@ -30,38 +30,41 @@ struct Visitor GenericList *(*next_list)(Visitor *v, GenericList **list, Error **errp); void (*end_list)(Visitor *v, Error **errp); - void (*type_enum)(Visitor *v, int *obj, const char * const strings[], - const char *kind, const char *name, Error **errp); + void (*type_enum)(Visitor *v, const char *name, int *obj, + const char *const strings[], const char *kind, + Error **errp); /* May be NULL; only needed for input visitors. */ - void (*get_next_type)(Visitor *v, QType *type, bool promote_int, - const char *name, Error **errp); + void (*get_next_type)(Visitor *v, const char *name, QType *type, + bool promote_int, Error **errp); /* Must be set. */ - void (*type_int64)(Visitor *v, int64_t *obj, const char *name, + void (*type_int64)(Visitor *v, const char *name, int64_t *obj, Error **errp); /* Must be set. */ - void (*type_uint64)(Visitor *v, uint64_t *obj, const char *name, + void (*type_uint64)(Visitor *v, const char *name, uint64_t *obj, Error **errp); /* Optional; fallback is type_uint64(). */ - void (*type_size)(Visitor *v, uint64_t *obj, const char *name, + void (*type_size)(Visitor *v, const char *name, uint64_t *obj, Error **errp); /* Must be set. */ - void (*type_bool)(Visitor *v, bool *obj, const char *name, Error **errp); - void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp); - void (*type_number)(Visitor *v, double *obj, const char *name, + void (*type_bool)(Visitor *v, const char *name, bool *obj, Error **errp); + void (*type_str)(Visitor *v, const char *name, char **obj, Error **errp); + void (*type_number)(Visitor *v, const char *name, double *obj, Error **errp); - void (*type_any)(Visitor *v, QObject **obj, const char *name, + void (*type_any)(Visitor *v, const char *name, QObject **obj, Error **errp); /* May be NULL; most useful for input visitors. */ - void (*optional)(Visitor *v, bool *present, const char *name); + void (*optional)(Visitor *v, const char *name, bool *present); bool (*start_union)(Visitor *v, bool data_present, Error **errp); }; -void input_type_enum(Visitor *v, int *obj, const char * const strings[], - const char *kind, const char *name, Error **errp); -void output_type_enum(Visitor *v, int *obj, const char * const strings[], - const char *kind, const char *name, Error **errp); +void input_type_enum(Visitor *v, const char *name, int *obj, + const char *const strings[], const char *kind, + Error **errp); +void output_type_enum(Visitor *v, const char *name, int *obj, + const char *const strings[], const char *kind, + Error **errp); #endif diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 14db02c923..a62da35173 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -125,8 +125,8 @@ opts_visitor_insert(GHashTable *unprocessed_opts, const QemuOpt *opt) static void -opts_start_struct(Visitor *v, void **obj, const char *kind, - const char *name, size_t size, Error **errp) +opts_start_struct(Visitor *v, const char *name, void **obj, const char *kind, + size_t size, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; @@ -312,7 +312,7 @@ processed(OptsVisitor *ov, const char *name) static void -opts_type_str(Visitor *v, char **obj, const char *name, Error **errp) +opts_type_str(Visitor *v, const char *name, char **obj, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; @@ -328,7 +328,7 @@ opts_type_str(Visitor *v, char **obj, const char *name, Error **errp) /* mimics qemu-option.c::parse_option_bool() */ static void -opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) +opts_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; @@ -361,7 +361,7 @@ opts_type_bool(Visitor *v, bool *obj, const char *name, Error **errp) static void -opts_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp) +opts_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; @@ -417,7 +417,7 @@ opts_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp) static void -opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) +opts_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; @@ -469,7 +469,7 @@ opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) static void -opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) +opts_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; @@ -495,7 +495,7 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp) static void -opts_optional(Visitor *v, bool *present, const char *name) +opts_optional(Visitor *v, const char *name, bool *present) { OptsVisitor *ov = to_ov(v); diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index 2c257d8b48..556137ec66 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -59,8 +59,8 @@ static void *qapi_dealloc_pop(QapiDeallocVisitor *qov) return value; } -static void qapi_dealloc_start_struct(Visitor *v, void **obj, const char *kind, - const char *name, size_t unused, +static void qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj, + const char *kind, size_t unused, Error **errp) { QapiDeallocVisitor *qov = to_qov(v); @@ -128,7 +128,7 @@ static void qapi_dealloc_end_list(Visitor *v, Error **errp) assert(obj == NULL); /* should've been list head tracker with no payload */ } -static void qapi_dealloc_type_str(Visitor *v, char **obj, const char *name, +static void qapi_dealloc_type_str(Visitor *v, const char *name, char **obj, Error **errp) { if (obj) { @@ -136,38 +136,37 @@ static void qapi_dealloc_type_str(Visitor *v, char **obj, const char *name, } } -static void qapi_dealloc_type_int64(Visitor *v, int64_t *obj, const char *name, +static void qapi_dealloc_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { } -static void qapi_dealloc_type_uint64(Visitor *v, uint64_t *obj, - const char *name, Error **errp) +static void qapi_dealloc_type_uint64(Visitor *v, const char *name, + uint64_t *obj, Error **errp) { } -static void qapi_dealloc_type_bool(Visitor *v, bool *obj, const char *name, +static void qapi_dealloc_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { } -static void qapi_dealloc_type_number(Visitor *v, double *obj, const char *name, +static void qapi_dealloc_type_number(Visitor *v, const char *name, double *obj, Error **errp) { } -static void qapi_dealloc_type_anything(Visitor *v, QObject **obj, - const char *name, Error **errp) +static void qapi_dealloc_type_anything(Visitor *v, const char *name, + QObject **obj, Error **errp) { if (obj) { qobject_decref(*obj); } } -static void qapi_dealloc_type_enum(Visitor *v, int *obj, +static void qapi_dealloc_type_enum(Visitor *v, const char *name, int *obj, const char * const strings[], - const char *kind, const char *name, - Error **errp) + const char *kind, Error **errp) { } diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index cd8e6031c5..3164f42fe1 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -22,7 +22,7 @@ void visit_start_struct(Visitor *v, const char *name, void **obj, const char *kind, size_t size, Error **errp) { - v->start_struct(v, obj, kind, name, size, errp); + v->start_struct(v, name, obj, kind, size, errp); } void visit_end_struct(Visitor *v, Error **errp) @@ -71,7 +71,7 @@ bool visit_start_union(Visitor *v, bool data_present, Error **errp) bool visit_optional(Visitor *v, const char *name, bool *present) { if (v->optional) { - v->optional(v, present, name); + v->optional(v, name, present); } return *present; } @@ -80,7 +80,7 @@ void visit_get_next_type(Visitor *v, const char *name, QType *type, bool promote_int, Error **errp) { if (v->get_next_type) { - v->get_next_type(v, type, promote_int, name, errp); + v->get_next_type(v, name, type, promote_int, errp); } } @@ -88,12 +88,12 @@ void visit_type_enum(Visitor *v, const char *name, int *obj, const char *const strings[], const char *kind, Error **errp) { - v->type_enum(v, obj, strings, kind, name, errp); + v->type_enum(v, name, obj, strings, kind, errp); } void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp) { - v->type_int64(v, obj, name, errp); + v->type_int64(v, name, obj, errp); } static void visit_type_uintN(Visitor *v, uint64_t *obj, const char *name, @@ -102,7 +102,7 @@ static void visit_type_uintN(Visitor *v, uint64_t *obj, const char *name, Error *err = NULL; uint64_t value = *obj; - v->type_uint64(v, &value, name, &err); + v->type_uint64(v, name, &value, &err); if (err) { error_propagate(errp, err); } else if (value > max) { @@ -140,7 +140,7 @@ void visit_type_uint32(Visitor *v, const char *name, uint32_t *obj, void visit_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { - v->type_uint64(v, obj, name, errp); + v->type_uint64(v, name, obj, errp); } static void visit_type_intN(Visitor *v, int64_t *obj, const char *name, @@ -150,7 +150,7 @@ static void visit_type_intN(Visitor *v, int64_t *obj, const char *name, Error *err = NULL; int64_t value = *obj; - v->type_int64(v, &value, name, &err); + v->type_int64(v, name, &value, &err); if (err) { error_propagate(errp, err); } else if (value < min || value > max) { @@ -187,42 +187,42 @@ void visit_type_int32(Visitor *v, const char *name, int32_t *obj, void visit_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { - v->type_int64(v, obj, name, errp); + v->type_int64(v, name, obj, errp); } void visit_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp) { if (v->type_size) { - v->type_size(v, obj, name, errp); + v->type_size(v, name, obj, errp); } else { - v->type_uint64(v, obj, name, errp); + v->type_uint64(v, name, obj, errp); } } void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { - v->type_bool(v, obj, name, errp); + v->type_bool(v, name, obj, errp); } void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp) { - v->type_str(v, obj, name, errp); + v->type_str(v, name, obj, errp); } void visit_type_number(Visitor *v, const char *name, double *obj, Error **errp) { - v->type_number(v, obj, name, errp); + v->type_number(v, name, obj, errp); } void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) { - v->type_any(v, obj, name, errp); + v->type_any(v, name, obj, errp); } -void output_type_enum(Visitor *v, int *obj, const char * const strings[], - const char *kind, const char *name, +void output_type_enum(Visitor *v, const char *name, int *obj, + const char *const strings[], const char *kind, Error **errp) { int i = 0; @@ -240,8 +240,8 @@ void output_type_enum(Visitor *v, int *obj, const char * const strings[], visit_type_str(v, name, &enum_str, errp); } -void input_type_enum(Visitor *v, int *obj, const char * const strings[], - const char *kind, const char *name, +void input_type_enum(Visitor *v, const char *name, int *obj, + const char *const strings[], const char *kind, Error **errp) { Error *local_err = NULL; diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index 5eb67dfc30..f3a0fd55c9 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -115,8 +115,8 @@ static void qmp_input_pop(QmpInputVisitor *qiv, Error **errp) qiv->nb_stack--; } -static void qmp_input_start_struct(Visitor *v, void **obj, const char *kind, - const char *name, size_t size, Error **errp) +static void qmp_input_start_struct(Visitor *v, const char *name, void **obj, + const char *kind, size_t size, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, true); @@ -209,8 +209,8 @@ static void qmp_input_end_list(Visitor *v, Error **errp) qmp_input_pop(qiv, errp); } -static void qmp_input_get_next_type(Visitor *v, QType *type, bool promote_int, - const char *name, Error **errp) +static void qmp_input_get_next_type(Visitor *v, const char *name, QType *type, + bool promote_int, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, false); @@ -225,7 +225,7 @@ static void qmp_input_get_next_type(Visitor *v, QType *type, bool promote_int, } } -static void qmp_input_type_int64(Visitor *v, int64_t *obj, const char *name, +static void qmp_input_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); @@ -240,7 +240,7 @@ static void qmp_input_type_int64(Visitor *v, int64_t *obj, const char *name, *obj = qint_get_int(qint); } -static void qmp_input_type_uint64(Visitor *v, uint64_t *obj, const char *name, +static void qmp_input_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { /* FIXME: qobject_to_qint mishandles values over INT64_MAX */ @@ -256,7 +256,7 @@ static void qmp_input_type_uint64(Visitor *v, uint64_t *obj, const char *name, *obj = qint_get_int(qint); } -static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name, +static void qmp_input_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); @@ -271,7 +271,7 @@ static void qmp_input_type_bool(Visitor *v, bool *obj, const char *name, *obj = qbool_get_bool(qbool); } -static void qmp_input_type_str(Visitor *v, char **obj, const char *name, +static void qmp_input_type_str(Visitor *v, const char *name, char **obj, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); @@ -286,7 +286,7 @@ static void qmp_input_type_str(Visitor *v, char **obj, const char *name, *obj = g_strdup(qstring_get_str(qstr)); } -static void qmp_input_type_number(Visitor *v, double *obj, const char *name, +static void qmp_input_type_number(Visitor *v, const char *name, double *obj, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); @@ -310,7 +310,7 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name, "number"); } -static void qmp_input_type_any(Visitor *v, QObject **obj, const char *name, +static void qmp_input_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); @@ -320,7 +320,7 @@ static void qmp_input_type_any(Visitor *v, QObject **obj, const char *name, *obj = qobj; } -static void qmp_input_optional(Visitor *v, bool *present, const char *name) +static void qmp_input_optional(Visitor *v, const char *name, bool *present) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, true); diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index 8a24a00309..fe002cd5c8 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -111,8 +111,8 @@ static void qmp_output_add_obj(QmpOutputVisitor *qov, const char *name, } } -static void qmp_output_start_struct(Visitor *v, void **obj, const char *kind, - const char *name, size_t unused, +static void qmp_output_start_struct(Visitor *v, const char *name, void **obj, + const char *kind, size_t unused, Error **errp) { QmpOutputVisitor *qov = to_qov(v); @@ -159,14 +159,14 @@ static void qmp_output_end_list(Visitor *v, Error **errp) qmp_output_pop(qov); } -static void qmp_output_type_int64(Visitor *v, int64_t *obj, const char *name, +static void qmp_output_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { QmpOutputVisitor *qov = to_qov(v); qmp_output_add(qov, name, qint_from_int(*obj)); } -static void qmp_output_type_uint64(Visitor *v, uint64_t *obj, const char *name, +static void qmp_output_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { /* FIXME: QMP outputs values larger than INT64_MAX as negative */ @@ -174,14 +174,14 @@ static void qmp_output_type_uint64(Visitor *v, uint64_t *obj, const char *name, qmp_output_add(qov, name, qint_from_int(*obj)); } -static void qmp_output_type_bool(Visitor *v, bool *obj, const char *name, +static void qmp_output_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { QmpOutputVisitor *qov = to_qov(v); qmp_output_add(qov, name, qbool_from_bool(*obj)); } -static void qmp_output_type_str(Visitor *v, char **obj, const char *name, +static void qmp_output_type_str(Visitor *v, const char *name, char **obj, Error **errp) { QmpOutputVisitor *qov = to_qov(v); @@ -192,14 +192,14 @@ static void qmp_output_type_str(Visitor *v, char **obj, const char *name, } } -static void qmp_output_type_number(Visitor *v, double *obj, const char *name, +static void qmp_output_type_number(Visitor *v, const char *name, double *obj, Error **errp) { QmpOutputVisitor *qov = to_qov(v); qmp_output_add(qov, name, qfloat_from_double(*obj)); } -static void qmp_output_type_any(Visitor *v, QObject **obj, const char *name, +static void qmp_output_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) { QmpOutputVisitor *qov = to_qov(v); diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 4c2344771b..cdf129cb7d 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -185,7 +185,7 @@ end_list(Visitor *v, Error **errp) siv->head = true; } -static void parse_type_int64(Visitor *v, int64_t *obj, const char *name, +static void parse_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { StringInputVisitor *siv = to_siv(v); @@ -227,13 +227,13 @@ error: "an int64 value or range"); } -static void parse_type_uint64(Visitor *v, uint64_t *obj, const char *name, +static void parse_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { /* FIXME: parse_type_int64 mishandles values over INT64_MAX */ int64_t i; Error *err = NULL; - parse_type_int64(v, &i, name, &err); + parse_type_int64(v, name, &i, &err); if (err) { error_propagate(errp, err); } else { @@ -241,7 +241,7 @@ static void parse_type_uint64(Visitor *v, uint64_t *obj, const char *name, } } -static void parse_type_size(Visitor *v, uint64_t *obj, const char *name, +static void parse_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp) { StringInputVisitor *siv = to_siv(v); @@ -263,7 +263,7 @@ static void parse_type_size(Visitor *v, uint64_t *obj, const char *name, *obj = val; } -static void parse_type_bool(Visitor *v, bool *obj, const char *name, +static void parse_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { StringInputVisitor *siv = to_siv(v); @@ -287,7 +287,7 @@ static void parse_type_bool(Visitor *v, bool *obj, const char *name, "boolean"); } -static void parse_type_str(Visitor *v, char **obj, const char *name, +static void parse_type_str(Visitor *v, const char *name, char **obj, Error **errp) { StringInputVisitor *siv = to_siv(v); @@ -299,7 +299,7 @@ static void parse_type_str(Visitor *v, char **obj, const char *name, } } -static void parse_type_number(Visitor *v, double *obj, const char *name, +static void parse_type_number(Visitor *v, const char *name, double *obj, Error **errp) { StringInputVisitor *siv = to_siv(v); @@ -319,7 +319,7 @@ static void parse_type_number(Visitor *v, double *obj, const char *name, *obj = val; } -static void parse_optional(Visitor *v, bool *present, const char *name) +static void parse_optional(Visitor *v, const char *name, bool *present) { StringInputVisitor *siv = to_siv(v); diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index 8400c8beeb..3ce6a3bf67 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -122,7 +122,7 @@ static void format_string(StringOutputVisitor *sov, Range *r, bool next, } } -static void print_type_int64(Visitor *v, int64_t *obj, const char *name, +static void print_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { StringOutputVisitor *sov = to_sov(v); @@ -198,16 +198,16 @@ static void print_type_int64(Visitor *v, int64_t *obj, const char *name, } } -static void print_type_uint64(Visitor *v, uint64_t *obj, const char *name, +static void print_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { /* FIXME: print_type_int64 mishandles values over INT64_MAX */ int64_t i = *obj; - print_type_int64(v, &i, name, errp); + print_type_int64(v, name, &i, errp); } -static void print_type_size(Visitor *v, uint64_t *obj, const char *name, - Error **errp) +static void print_type_size(Visitor *v, const char *name, uint64_t *obj, + Error **errp) { StringOutputVisitor *sov = to_sov(v); static const char suffixes[] = { 'B', 'K', 'M', 'G', 'T', 'P', 'E' }; @@ -237,14 +237,14 @@ static void print_type_size(Visitor *v, uint64_t *obj, const char *name, string_output_set(sov, out); } -static void print_type_bool(Visitor *v, bool *obj, const char *name, +static void print_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { StringOutputVisitor *sov = to_sov(v); string_output_set(sov, g_strdup(*obj ? "true" : "false")); } -static void print_type_str(Visitor *v, char **obj, const char *name, +static void print_type_str(Visitor *v, const char *name, char **obj, Error **errp) { StringOutputVisitor *sov = to_sov(v); @@ -258,7 +258,7 @@ static void print_type_str(Visitor *v, char **obj, const char *name, string_output_set(sov, out); } -static void print_type_number(Visitor *v, double *obj, const char *name, +static void print_type_number(Visitor *v, const char *name, double *obj, Error **errp) { StringOutputVisitor *sov = to_sov(v); From 337283dffbb5ad5860ed00408a5fd0665c21be07 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:57 -0700 Subject: [PATCH 25/31] qapi: Drop unused 'kind' for struct/enum visit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit visit_start_struct() and visit_type_enum() had a 'kind' argument that was usually set to either the stringized version of the corresponding qapi type name, or to NULL (although some clients didn't even get that right). But nothing ever used the argument. It's even hard to argue that it would be useful in a debugger, as a stack backtrace also tells which type is being visited. Therefore, drop the 'kind' argument as dead. Signed-off-by: Eric Blake Reviewed-by: Marc-André Lureau Message-Id: <1454075341-13658-22-git-send-email-eblake@redhat.com> [Harmless rebase mistake cleaned up] Signed-off-by: Markus Armbruster --- hmp.c | 2 +- hw/core/qdev-properties.c | 6 ++---- hw/ppc/spapr_drc.c | 4 ++-- hw/virtio/virtio-balloon.c | 4 ++-- include/qapi/visitor-impl.h | 11 ++++------- include/qapi/visitor.h | 5 ++--- qapi/opts-visitor.c | 2 +- qapi/qapi-dealloc-visitor.c | 6 ++---- qapi/qapi-visit-core.c | 15 ++++++--------- qapi/qmp-input-visitor.c | 2 +- qapi/qmp-output-visitor.c | 3 +-- qom/object.c | 8 ++++---- scripts/qapi-event.py | 2 +- scripts/qapi-visit.py | 12 ++++++------ vl.c | 2 +- 15 files changed, 36 insertions(+), 48 deletions(-) diff --git a/hmp.c b/hmp.c index 27d6867664..3e2a9891c4 100644 --- a/hmp.c +++ b/hmp.c @@ -1670,7 +1670,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) pdict = qdict_clone_shallow(qdict); v = opts_get_visitor(ov); - visit_start_struct(v, NULL, NULL, NULL, 0, &err); + visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out_clean; } diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 6a9289921f..bc89800246 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -49,8 +49,7 @@ static void get_enum(Object *obj, Visitor *v, const char *name, void *opaque, Property *prop = opaque; int *ptr = qdev_get_prop_ptr(dev, prop); - visit_type_enum(v, prop->name, ptr, prop->info->enum_table, - prop->info->name, errp); + visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp); } static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque, @@ -65,8 +64,7 @@ static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque, return; } - visit_type_enum(v, prop->name, ptr, prop->info->enum_table, - prop->info->name, errp); + visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp); } /* Bit */ diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index e40617faba..1aac6f2f68 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -260,7 +260,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name, void *fdt; if (!drc->fdt) { - visit_start_struct(v, name, NULL, NULL, 0, &err); + visit_start_struct(v, name, NULL, 0, &err); if (!err) { visit_end_struct(v, &err); } @@ -283,7 +283,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name, case FDT_BEGIN_NODE: fdt_depth++; name = fdt_get_name(fdt, fdt_offset, &name_len); - visit_start_struct(v, name, NULL, NULL, 0, &err); + visit_start_struct(v, name, NULL, 0, &err); if (err) { error_propagate(errp, err); return; diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 0d7033a572..a382f43f92 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -120,7 +120,7 @@ static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name, VirtIOBalloon *s = opaque; int i; - visit_start_struct(v, name, NULL, "guest-stats", 0, &err); + visit_start_struct(v, name, NULL, 0, &err); if (err) { goto out; } @@ -129,7 +129,7 @@ static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name, goto out_end; } - visit_start_struct(v, "stats", NULL, NULL, 0, &err); + visit_start_struct(v, "stats", NULL, 0, &err); if (err) { goto out_end; } diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 734cc13854..337f99973f 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -19,7 +19,7 @@ struct Visitor { /* Must be set */ void (*start_struct)(Visitor *v, const char *name, void **obj, - const char *kind, size_t size, Error **errp); + size_t size, Error **errp); void (*end_struct)(Visitor *v, Error **errp); void (*start_implicit_struct)(Visitor *v, void **obj, size_t size, @@ -31,8 +31,7 @@ struct Visitor void (*end_list)(Visitor *v, Error **errp); void (*type_enum)(Visitor *v, const char *name, int *obj, - const char *const strings[], const char *kind, - Error **errp); + const char *const strings[], Error **errp); /* May be NULL; only needed for input visitors. */ void (*get_next_type)(Visitor *v, const char *name, QType *type, bool promote_int, Error **errp); @@ -61,10 +60,8 @@ struct Visitor }; void input_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], const char *kind, - Error **errp); + const char *const strings[], Error **errp); void output_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], const char *kind, - Error **errp); + const char *const strings[], Error **errp); #endif diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 0b5cd4179e..997555dbd7 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -28,7 +28,7 @@ typedef struct GenericList } GenericList; void visit_start_struct(Visitor *v, const char *name, void **obj, - const char *kind, size_t size, Error **errp); + size_t size, Error **errp); void visit_end_struct(Visitor *v, Error **errp); void visit_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp); @@ -54,8 +54,7 @@ bool visit_optional(Visitor *v, const char *name, bool *present); void visit_get_next_type(Visitor *v, const char *name, QType *type, bool promote_int, Error **errp); void visit_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], const char *kind, - Error **errp); + const char *const strings[], Error **errp); void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp); void visit_type_uint8(Visitor *v, const char *name, uint8_t *obj, Error **errp); diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index a62da35173..d1c0c5abf7 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -125,7 +125,7 @@ opts_visitor_insert(GHashTable *unprocessed_opts, const QemuOpt *opt) static void -opts_start_struct(Visitor *v, const char *name, void **obj, const char *kind, +opts_start_struct(Visitor *v, const char *name, void **obj, size_t size, Error **errp) { OptsVisitor *ov = to_ov(v); diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index 556137ec66..7c2148dc2e 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -60,8 +60,7 @@ static void *qapi_dealloc_pop(QapiDeallocVisitor *qov) } static void qapi_dealloc_start_struct(Visitor *v, const char *name, void **obj, - const char *kind, size_t unused, - Error **errp) + size_t unused, Error **errp) { QapiDeallocVisitor *qov = to_qov(v); qapi_dealloc_push(qov, obj); @@ -165,8 +164,7 @@ static void qapi_dealloc_type_anything(Visitor *v, const char *name, } static void qapi_dealloc_type_enum(Visitor *v, const char *name, int *obj, - const char * const strings[], - const char *kind, Error **errp) + const char * const strings[], Error **errp) { } diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 3164f42fe1..2be026c7db 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -20,9 +20,9 @@ #include "qapi/visitor-impl.h" void visit_start_struct(Visitor *v, const char *name, void **obj, - const char *kind, size_t size, Error **errp) + size_t size, Error **errp) { - v->start_struct(v, name, obj, kind, size, errp); + v->start_struct(v, name, obj, size, errp); } void visit_end_struct(Visitor *v, Error **errp) @@ -85,10 +85,9 @@ void visit_get_next_type(Visitor *v, const char *name, QType *type, } void visit_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], const char *kind, - Error **errp) + const char *const strings[], Error **errp) { - v->type_enum(v, name, obj, strings, kind, errp); + v->type_enum(v, name, obj, strings, errp); } void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp) @@ -222,8 +221,7 @@ void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) } void output_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], const char *kind, - Error **errp) + const char *const strings[], Error **errp) { int i = 0; int value = *obj; @@ -241,8 +239,7 @@ void output_type_enum(Visitor *v, const char *name, int *obj, } void input_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], const char *kind, - Error **errp) + const char *const strings[], Error **errp) { Error *local_err = NULL; int64_t value = 0; diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index f3a0fd55c9..92eee26438 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -116,7 +116,7 @@ static void qmp_input_pop(QmpInputVisitor *qiv, Error **errp) } static void qmp_input_start_struct(Visitor *v, const char *name, void **obj, - const char *kind, size_t size, Error **errp) + size_t size, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, true); diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index fe002cd5c8..ff480a61a3 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -112,8 +112,7 @@ static void qmp_output_add_obj(QmpOutputVisitor *qov, const char *name, } static void qmp_output_start_struct(Visitor *v, const char *name, void **obj, - const char *kind, size_t unused, - Error **errp) + size_t unused, Error **errp) { QmpOutputVisitor *qov = to_qov(v); QDict *dict = qdict_new(); diff --git a/qom/object.c b/qom/object.c index db40ae71f5..844ae7a0fd 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1245,7 +1245,7 @@ int object_property_get_enum(Object *obj, const char *name, siv = string_input_visitor_new(str); string_output_visitor_cleanup(sov); visit_type_enum(string_input_get_visitor(siv), name, &ret, - enumprop->strings, NULL, errp); + enumprop->strings, errp); g_free(str); string_input_visitor_cleanup(siv); @@ -1916,7 +1916,7 @@ static void property_get_enum(Object *obj, Visitor *v, const char *name, return; } - visit_type_enum(v, name, &value, prop->strings, NULL, errp); + visit_type_enum(v, name, &value, prop->strings, errp); } static void property_set_enum(Object *obj, Visitor *v, const char *name, @@ -1926,7 +1926,7 @@ static void property_set_enum(Object *obj, Visitor *v, const char *name, int value; Error *err = NULL; - visit_type_enum(v, name, &value, prop->strings, NULL, &err); + visit_type_enum(v, name, &value, prop->strings, &err); if (err) { error_propagate(errp, err); return; @@ -2007,7 +2007,7 @@ static void property_get_tm(Object *obj, Visitor *v, const char *name, goto out; } - visit_start_struct(v, name, NULL, "struct tm", 0, &err); + visit_start_struct(v, name, NULL, 0, &err); if (err) { goto out; } diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index edd446b74d..07bcb73d3d 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -63,7 +63,7 @@ def gen_event_send(name, arg_type): qov = qmp_output_visitor_new(); v = qmp_output_get_visitor(qov); - visit_start_struct(v, "%(name)s", NULL, NULL, 0, &err); + visit_start_struct(v, "%(name)s", NULL, 0, &err); ''', name=name) ret += gen_err_check() diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 35505acd98..308000fbbe 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -122,7 +122,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error { Error *err = NULL; - visit_start_struct(v, name, (void **)obj, "%(name)s", sizeof(%(c_name)s), &err); + visit_start_struct(v, name, (void **)obj, sizeof(%(c_name)s), &err); if (err) { goto out; } @@ -138,7 +138,7 @@ out: error_propagate(errp, err); } ''', - name=name, c_name=c_name(name)) + c_name=c_name(name)) return ret @@ -183,11 +183,11 @@ def gen_visit_enum(name): void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s *obj, Error **errp) { int value = *obj; - visit_type_enum(v, name, &value, %(c_name)s_lookup, "%(name)s", errp); + 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): @@ -259,7 +259,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error { Error *err = NULL; - visit_start_struct(v, name, (void **)obj, "%(name)s", sizeof(%(c_name)s), &err); + visit_start_struct(v, name, (void **)obj, sizeof(%(c_name)s), &err); if (err) { goto out; } @@ -267,7 +267,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error goto out_obj; } ''', - c_name=c_name(name), name=name) + c_name=c_name(name)) if base: ret += mcgen(''' diff --git a/vl.c b/vl.c index 4379beccf7..00dc9979e1 100644 --- a/vl.c +++ b/vl.c @@ -2831,7 +2831,7 @@ static int object_create(void *opaque, QemuOpts *opts, Error **errp) pdict = qemu_opts_to_qdict(opts, NULL); v = opts_get_visitor(ov); - visit_start_struct(v, NULL, NULL, NULL, 0, &err); + visit_start_struct(v, NULL, NULL, 0, &err); if (err) { goto out; } From bdd8e6b5d8a9def83d491a3f41c10424fc366258 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:58 -0700 Subject: [PATCH 26/31] qapi: Tighten qmp_input_end_list() The only way that qmp_input_pop() will set errp is if a dictionary was the most recent thing pushed. Since we don't have any push(struct)/pop(list) or push(list)/pop(struct) mismatches (such a mismatch is a programming bug), we therefore cannot set errp inside qmp_input_end_list(). Make this obvious by using &error_abort. A later patch will then remove the errp parameter of qmp_input_pop(), but that will first require the larger task of splitting visit_end_struct(). Signed-off-by: Eric Blake Message-Id: <1454075341-13658-23-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qapi/qmp-input-visitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index 92eee26438..4563c20c13 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -206,7 +206,7 @@ static void qmp_input_end_list(Visitor *v, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); - qmp_input_pop(qiv, errp); + qmp_input_pop(qiv, &error_abort); } static void qmp_input_get_next_type(Visitor *v, const char *name, QType *type, From 08f9541dec51700abef0c37994213164ca4e4fc9 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:59 -0700 Subject: [PATCH 27/31] qapi: Drop unused error argument for list and implicit struct No backend was setting an error when ending the visit of a list or implicit struct, or when moving to the next list node. Make the callers a bit easier to follow by making this a part of the contract, and removing the errp argument - callers can then unconditionally end an object as part of cleanup without having to think about whether a second error is dominated by a first, because there is no second error. A later patch will then tackle the larger task of splitting visit_end_struct(), which can indeed set an error. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-24-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- hw/ppc/spapr_drc.c | 6 +----- include/qapi/visitor-impl.h | 9 ++++++--- include/qapi/visitor.h | 8 +++++--- qapi/opts-visitor.c | 6 +++--- qapi/qapi-dealloc-visitor.c | 8 ++++---- qapi/qapi-visit-core.c | 12 ++++++------ qapi/qmp-input-visitor.c | 11 +++-------- qapi/qmp-output-visitor.c | 6 +++--- qapi/string-input-visitor.c | 8 +++----- qapi/string-output-visitor.c | 8 +++----- scripts/qapi-visit.py | 12 ++++-------- 11 files changed, 41 insertions(+), 53 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 1aac6f2f68..ef063c05cf 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -315,11 +315,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name, return; } } - visit_end_list(v, &err); - if (err) { - error_propagate(errp, err); - return; - } + visit_end_list(v); break; } default: diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 337f99973f..ea252f8e3a 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -24,11 +24,14 @@ struct Visitor void (*start_implicit_struct)(Visitor *v, void **obj, size_t size, Error **errp); - void (*end_implicit_struct)(Visitor *v, Error **errp); + /* May be NULL */ + void (*end_implicit_struct)(Visitor *v); void (*start_list)(Visitor *v, const char *name, Error **errp); - GenericList *(*next_list)(Visitor *v, GenericList **list, Error **errp); - void (*end_list)(Visitor *v, Error **errp); + /* Must be set */ + GenericList *(*next_list)(Visitor *v, GenericList **list); + /* Must be set */ + void (*end_list)(Visitor *v); void (*type_enum)(Visitor *v, const char *name, int *obj, const char *const strings[], Error **errp); diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 997555dbd7..5e581dcf7e 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -1,6 +1,7 @@ /* * Core Definitions for QAPI Visitor Classes * + * Copyright (C) 2012-2016 Red Hat, Inc. * Copyright IBM, Corp. 2011 * * Authors: @@ -32,10 +33,11 @@ void visit_start_struct(Visitor *v, const char *name, void **obj, void visit_end_struct(Visitor *v, Error **errp); void visit_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp); -void visit_end_implicit_struct(Visitor *v, Error **errp); +void visit_end_implicit_struct(Visitor *v); + void visit_start_list(Visitor *v, const char *name, Error **errp); -GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp); -void visit_end_list(Visitor *v, Error **errp); +GenericList *visit_next_list(Visitor *v, GenericList **list); +void visit_end_list(Visitor *v); /** * Check if an optional member @name of an object needs visiting. diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index d1c0c5abf7..d54f75b5e7 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -1,7 +1,7 @@ /* * Options Visitor * - * Copyright Red Hat, Inc. 2012, 2013 + * Copyright Red Hat, Inc. 2012-2016 * * Author: Laszlo Ersek * @@ -221,7 +221,7 @@ opts_start_list(Visitor *v, const char *name, Error **errp) static GenericList * -opts_next_list(Visitor *v, GenericList **list, Error **errp) +opts_next_list(Visitor *v, GenericList **list) { OptsVisitor *ov = to_ov(v); GenericList **link; @@ -270,7 +270,7 @@ opts_next_list(Visitor *v, GenericList **list, Error **errp) static void -opts_end_list(Visitor *v, Error **errp) +opts_end_list(Visitor *v) { OptsVisitor *ov = to_ov(v); diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index 7c2148dc2e..2659d3fcca 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -1,6 +1,7 @@ /* * Dealloc Visitor * + * Copyright (C) 2012-2016 Red Hat, Inc. * Copyright IBM, Corp. 2011 * * Authors: @@ -84,7 +85,7 @@ static void qapi_dealloc_start_implicit_struct(Visitor *v, qapi_dealloc_push(qov, obj); } -static void qapi_dealloc_end_implicit_struct(Visitor *v, Error **errp) +static void qapi_dealloc_end_implicit_struct(Visitor *v) { QapiDeallocVisitor *qov = to_qov(v); void **obj = qapi_dealloc_pop(qov); @@ -99,8 +100,7 @@ static void qapi_dealloc_start_list(Visitor *v, const char *name, Error **errp) qapi_dealloc_push(qov, NULL); } -static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp, - Error **errp) +static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp) { GenericList *list = *listp; QapiDeallocVisitor *qov = to_qov(v); @@ -120,7 +120,7 @@ static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp, return NULL; } -static void qapi_dealloc_end_list(Visitor *v, Error **errp) +static void qapi_dealloc_end_list(Visitor *v) { QapiDeallocVisitor *qov = to_qov(v); void *obj = qapi_dealloc_pop(qov); diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 2be026c7db..f856286461 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -38,10 +38,10 @@ void visit_start_implicit_struct(Visitor *v, void **obj, size_t size, } } -void visit_end_implicit_struct(Visitor *v, Error **errp) +void visit_end_implicit_struct(Visitor *v) { if (v->end_implicit_struct) { - v->end_implicit_struct(v, errp); + v->end_implicit_struct(v); } } @@ -50,14 +50,14 @@ void visit_start_list(Visitor *v, const char *name, Error **errp) v->start_list(v, name, errp); } -GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp) +GenericList *visit_next_list(Visitor *v, GenericList **list) { - return v->next_list(v, list, errp); + return v->next_list(v, list); } -void visit_end_list(Visitor *v, Error **errp) +void visit_end_list(Visitor *v) { - v->end_list(v, errp); + v->end_list(v); } bool visit_start_union(Visitor *v, bool data_present, Error **errp) diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index 4563c20c13..362a1a33a8 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -1,6 +1,7 @@ /* * Input Visitor * + * Copyright (C) 2012-2016 Red Hat, Inc. * Copyright IBM, Corp. 2011 * * Authors: @@ -154,10 +155,6 @@ static void qmp_input_start_implicit_struct(Visitor *v, void **obj, } } -static void qmp_input_end_implicit_struct(Visitor *v, Error **errp) -{ -} - static void qmp_input_start_list(Visitor *v, const char *name, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); @@ -172,8 +169,7 @@ static void qmp_input_start_list(Visitor *v, const char *name, Error **errp) qmp_input_push(qiv, qobj, errp); } -static GenericList *qmp_input_next_list(Visitor *v, GenericList **list, - Error **errp) +static GenericList *qmp_input_next_list(Visitor *v, GenericList **list) { QmpInputVisitor *qiv = to_qiv(v); GenericList *entry; @@ -202,7 +198,7 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list, return entry; } -static void qmp_input_end_list(Visitor *v, Error **errp) +static void qmp_input_end_list(Visitor *v) { QmpInputVisitor *qiv = to_qiv(v); @@ -353,7 +349,6 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj) v->visitor.start_struct = qmp_input_start_struct; v->visitor.end_struct = qmp_input_end_struct; v->visitor.start_implicit_struct = qmp_input_start_implicit_struct; - v->visitor.end_implicit_struct = qmp_input_end_implicit_struct; v->visitor.start_list = qmp_input_start_list; v->visitor.next_list = qmp_input_next_list; v->visitor.end_list = qmp_input_end_list; diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index ff480a61a3..41f92c8ca9 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -1,6 +1,7 @@ /* * Core Definitions for QAPI/QMP Command Registry * + * Copyright (C) 2012-2016 Red Hat, Inc. * Copyright IBM, Corp. 2011 * * Authors: @@ -136,8 +137,7 @@ static void qmp_output_start_list(Visitor *v, const char *name, Error **errp) qmp_output_push(qov, list); } -static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp, - Error **errp) +static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp) { GenericList *list = *listp; QmpOutputVisitor *qov = to_qov(v); @@ -152,7 +152,7 @@ static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp, return list ? list->next : NULL; } -static void qmp_output_end_list(Visitor *v, Error **errp) +static void qmp_output_end_list(Visitor *v) { QmpOutputVisitor *qov = to_qov(v); qmp_output_pop(qov); diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index cdf129cb7d..18b9339768 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -1,7 +1,7 @@ /* * String parsing visitor * - * Copyright Red Hat, Inc. 2012 + * Copyright Red Hat, Inc. 2012-2016 * * Author: Paolo Bonzini * @@ -139,8 +139,7 @@ start_list(Visitor *v, const char *name, Error **errp) } } -static GenericList * -next_list(Visitor *v, GenericList **list, Error **errp) +static GenericList *next_list(Visitor *v, GenericList **list) { StringInputVisitor *siv = to_siv(v); GenericList **link; @@ -178,8 +177,7 @@ next_list(Visitor *v, GenericList **list, Error **errp) return *link; } -static void -end_list(Visitor *v, Error **errp) +static void end_list(Visitor *v) { StringInputVisitor *siv = to_siv(v); siv->head = true; diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index 3ce6a3bf67..b980bd3265 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -1,7 +1,7 @@ /* * String printing Visitor * - * Copyright Red Hat, Inc. 2012 + * Copyright Red Hat, Inc. 2012-2016 * * Author: Paolo Bonzini * @@ -276,8 +276,7 @@ start_list(Visitor *v, const char *name, Error **errp) sov->head = true; } -static GenericList * -next_list(Visitor *v, GenericList **list, Error **errp) +static GenericList *next_list(Visitor *v, GenericList **list) { StringOutputVisitor *sov = to_sov(v); GenericList *ret = NULL; @@ -303,8 +302,7 @@ next_list(Visitor *v, GenericList **list, Error **errp) return ret; } -static void -end_list(Visitor *v, Error **errp) +static void end_list(Visitor *v) { StringOutputVisitor *sov = to_sov(v); diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 308000fbbe..0fdcebcca8 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -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); } @@ -161,15 +161,13 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, 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, 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); } @@ -230,9 +228,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, 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); } From a86156401559cb4401cf9ecc704faeab6fc8bb19 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:49:00 -0700 Subject: [PATCH 28/31] qmp: Fix reference-counting of qnull on empty output visit Commit 6c2f9a15 ensured that we would not return NULL when the caller used an output visitor but had nothing to visit. But in doing so, it added a FIXME about a reference count leak that could abort qemu in the (unlikely) case of SIZE_MAX such visits (more plausible on 32-bit). (Although that commit suggested we might fix it in time for 2.5, we ran out of time; fortunately, it is unlikely enough to bite that it was not worth worrying about during the 2.5 release.) This fixes things by documenting the internal contracts, and explaining why the internal function can return NULL and only the public facing interface needs to worry about qnull(), thus avoiding over-referencing the qnull_ global object. It does not, however, fix the stupidity of the stack mixing up two separate pieces of information; add a FIXME to explain that issue, which will be fixed shortly in a future patch. Signed-off-by: Eric Blake Cc: qemu-stable@nongnu.org Message-Id: <1454075341-13658-25-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qapi/qmp-output-visitor.c | 41 +++++++++++++++++++++++++++------ tests/test-qmp-output-visitor.c | 2 ++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index 41f92c8ca9..4500e3bc49 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -31,6 +31,15 @@ typedef QTAILQ_HEAD(QStack, QStackEntry) QStack; struct QmpOutputVisitor { Visitor visitor; + /* FIXME: we are abusing stack to hold two separate pieces of + * information: the current root object in slot 0, and the stack + * of N objects still being built in slots 1 through N (for N+1 + * slots in use). Worse, our behavior is inconsistent: + * qmp_output_add_obj() visiting two top-level scalars in a row + * discards the first in favor of the second, but visiting two + * top-level objects in a row tries to append the second object + * into the first (since the first object was placed in the stack + * in both slot 0 and 1, but only popped from slot 1). */ QStack stack; }; @@ -43,10 +52,12 @@ static QmpOutputVisitor *to_qov(Visitor *v) return container_of(v, QmpOutputVisitor, visitor); } +/* Push @value onto the stack of current QObjects being built */ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value) { QStackEntry *e = g_malloc0(sizeof(*e)); + assert(value); e->value = value; if (qobject_type(e->value) == QTYPE_QLIST) { e->is_list_head = true; @@ -54,44 +65,53 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value) QTAILQ_INSERT_HEAD(&qov->stack, e, node); } +/* Pop a value off the stack of QObjects being built, and return it. */ static QObject *qmp_output_pop(QmpOutputVisitor *qov) { QStackEntry *e = QTAILQ_FIRST(&qov->stack); QObject *value; + + assert(e); QTAILQ_REMOVE(&qov->stack, e, node); value = e->value; + assert(value); g_free(e); return value; } +/* Grab the root QObject, if any */ static QObject *qmp_output_first(QmpOutputVisitor *qov) { QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack); - /* - * FIXME Wrong, because qmp_output_get_qobject() will increment - * the refcnt *again*. We need to think through how visitors - * handle null. - */ if (!e) { - return qnull(); + /* No root */ + return NULL; } - + assert(e->value); return e->value; } +/* Peek at the top of the stack of QObjects being built. + * The stack must not be empty. */ static QObject *qmp_output_last(QmpOutputVisitor *qov) { QStackEntry *e = QTAILQ_FIRST(&qov->stack); + + assert(e && e->value); return e->value; } +/* Add @value to the current QObject being built. + * If the stack is visiting a dictionary or list, @value is now owned + * by that container. Otherwise, @value is now the root. */ static void qmp_output_add_obj(QmpOutputVisitor *qov, const char *name, QObject *value) { QObject *cur; if (QTAILQ_EMPTY(&qov->stack)) { + /* Stack was empty, track this object as root */ qmp_output_push_obj(qov, value); return; } @@ -100,13 +120,17 @@ static void qmp_output_add_obj(QmpOutputVisitor *qov, const char *name, switch (qobject_type(cur)) { case QTYPE_QDICT: + assert(name); qdict_put_obj(qobject_to_qdict(cur), name, value); break; case QTYPE_QLIST: qlist_append_obj(qobject_to_qlist(cur), value); break; default: + /* The previous root was a scalar, replace it with a new root */ + /* FIXME this is abusing the stack; see comment above */ qobject_decref(qmp_output_pop(qov)); + assert(QTAILQ_EMPTY(&qov->stack)); qmp_output_push_obj(qov, value); break; } @@ -206,11 +230,14 @@ static void qmp_output_type_any(Visitor *v, const char *name, QObject **obj, qmp_output_add_obj(qov, name, *obj); } +/* Finish building, and return the root object. Will not be NULL. */ QObject *qmp_output_get_qobject(QmpOutputVisitor *qov) { QObject *obj = qmp_output_first(qov); if (obj) { qobject_incref(obj); + } else { + obj = qnull(); } return obj; } diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index 4df94bcb59..26dc752b81 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -461,6 +461,8 @@ static void test_visitor_out_empty(TestOutputVisitorData *data, arg = qmp_output_get_qobject(data->qov); g_assert(qobject_type(arg) == QTYPE_QNULL); + /* Check that qnull reference counting is sane */ + g_assert(arg->refcnt == 2); qobject_decref(arg); } From 455ba08afde784466420449d01c6458f88349d55 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:49:01 -0700 Subject: [PATCH 29/31] qmp: Don't abuse stack to track qmp-output root The previous commit documented an inconsistency in how we are using the stack of qmp-output-visitor. Normally, pushing a single top-level object puts the object on the stack twice: once as the root, and once as the current container being appended to; but popping that struct only pops once. However, qmp_ouput_add() was trying to either set up the added object as the new root (works if you parse two top-level scalars in a row: the second replaces the first as the root) or as a member of the current container (works as long as you have an open container on the stack; but if you have popped the first top-level container, it then resolves to the root and still tries to add into that existing container). Fix the stupidity by not tracking two separate things in the stack. Drop the now-useless qmp_output_first() and qmp_output_last() while at it. Saved for a later patch: we still are rather sloppy in that qmp_output_get_object() can be called in the middle of a parse, rather than requiring that a visit is complete. Signed-off-by: Eric Blake Message-Id: <1454075341-13658-26-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qapi/qmp-output-visitor.c | 89 ++++++++++++--------------------------- 1 file changed, 26 insertions(+), 63 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index 4500e3bc49..f47eefa626 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -31,16 +31,8 @@ typedef QTAILQ_HEAD(QStack, QStackEntry) QStack; struct QmpOutputVisitor { Visitor visitor; - /* FIXME: we are abusing stack to hold two separate pieces of - * information: the current root object in slot 0, and the stack - * of N objects still being built in slots 1 through N (for N+1 - * slots in use). Worse, our behavior is inconsistent: - * qmp_output_add_obj() visiting two top-level scalars in a row - * discards the first in favor of the second, but visiting two - * top-level objects in a row tries to append the second object - * into the first (since the first object was placed in the stack - * in both slot 0 and 1, but only popped from slot 1). */ - QStack stack; + QStack stack; /* Stack of containers that haven't yet been finished */ + QObject *root; /* Root of the output visit */ }; #define qmp_output_add(qov, name, value) \ @@ -57,6 +49,7 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value) { QStackEntry *e = g_malloc0(sizeof(*e)); + assert(qov->root); assert(value); e->value = value; if (qobject_type(e->value) == QTYPE_QLIST) { @@ -79,60 +72,32 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov) return value; } -/* Grab the root QObject, if any */ -static QObject *qmp_output_first(QmpOutputVisitor *qov) -{ - QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack); - - if (!e) { - /* No root */ - return NULL; - } - assert(e->value); - return e->value; -} - -/* Peek at the top of the stack of QObjects being built. - * The stack must not be empty. */ -static QObject *qmp_output_last(QmpOutputVisitor *qov) -{ - QStackEntry *e = QTAILQ_FIRST(&qov->stack); - - assert(e && e->value); - return e->value; -} - /* Add @value to the current QObject being built. * If the stack is visiting a dictionary or list, @value is now owned * by that container. Otherwise, @value is now the root. */ static void qmp_output_add_obj(QmpOutputVisitor *qov, const char *name, QObject *value) { - QObject *cur; + QStackEntry *e = QTAILQ_FIRST(&qov->stack); + QObject *cur = e ? e->value : NULL; - if (QTAILQ_EMPTY(&qov->stack)) { - /* Stack was empty, track this object as root */ - qmp_output_push_obj(qov, value); - return; - } - - cur = qmp_output_last(qov); - - switch (qobject_type(cur)) { - case QTYPE_QDICT: - assert(name); - qdict_put_obj(qobject_to_qdict(cur), name, value); - break; - case QTYPE_QLIST: - qlist_append_obj(qobject_to_qlist(cur), value); - break; - default: - /* The previous root was a scalar, replace it with a new root */ - /* FIXME this is abusing the stack; see comment above */ - qobject_decref(qmp_output_pop(qov)); - assert(QTAILQ_EMPTY(&qov->stack)); - qmp_output_push_obj(qov, value); - break; + if (!cur) { + /* FIXME we should require the user to reset the visitor, rather + * than throwing away the previous root */ + qobject_decref(qov->root); + qov->root = value; + } else { + switch (qobject_type(cur)) { + case QTYPE_QDICT: + assert(name); + qdict_put_obj(qobject_to_qdict(cur), name, value); + break; + case QTYPE_QLIST: + qlist_append_obj(qobject_to_qlist(cur), value); + break; + default: + g_assert_not_reached(); + } } } @@ -233,7 +198,9 @@ static void qmp_output_type_any(Visitor *v, const char *name, QObject **obj, /* Finish building, and return the root object. Will not be NULL. */ QObject *qmp_output_get_qobject(QmpOutputVisitor *qov) { - QObject *obj = qmp_output_first(qov); + /* FIXME: we should require that a visit occurred, and that it is + * complete (no starts without a matching end) */ + QObject *obj = qov->root; if (obj) { qobject_incref(obj); } else { @@ -251,16 +218,12 @@ void qmp_output_visitor_cleanup(QmpOutputVisitor *v) { QStackEntry *e, *tmp; - /* The bottom QStackEntry, if any, owns the root QObject. See the - * qmp_output_push_obj() invocations in qmp_output_add_obj(). */ - QObject *root = QTAILQ_EMPTY(&v->stack) ? NULL : qmp_output_first(v); - QTAILQ_FOREACH_SAFE(e, &v->stack, node, tmp) { QTAILQ_REMOVE(&v->stack, e, node); g_free(e); } - qobject_decref(root); + qobject_decref(v->root); g_free(v); } From 86ae191163d48ff4ff9d9996868e6cfe92a82449 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 2 Feb 2016 07:51:41 -0700 Subject: [PATCH 30/31] qapi: Fix compilation failure on MIPS and SPARC Commit 86f4b687 broke compilation on MIPS and SPARC, which have a preprocessor pollution of '#define mips 1' and '#define sparc 1', respectively. Treat it the same way as we do for the pollution with 'unix', so that QMP remains backwards compatible and only the C code needs to use the alternative 'q_mips', 'q_sparc' spelling. CC: James Hogan CC: Peter Maydell Signed-off-by: Eric Blake Tested-by: James Hogan Signed-off-by: Markus Armbruster --- cpus.c | 10 +++++----- hmp.c | 8 +++++--- scripts/qapi.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cpus.c b/cpus.c index 882b61851a..898426ca56 100644 --- a/cpus.c +++ b/cpus.c @@ -1576,13 +1576,13 @@ CpuInfoList *qmp_query_cpus(Error **errp) info->value->u.ppc->nip = env->nip; #elif defined(TARGET_SPARC) info->value->arch = CPU_INFO_ARCH_SPARC; - info->value->u.sparc = g_new0(CpuInfoSPARC, 1); - info->value->u.sparc->pc = env->pc; - info->value->u.sparc->npc = env->npc; + info->value->u.q_sparc = g_new0(CpuInfoSPARC, 1); + info->value->u.q_sparc->pc = env->pc; + info->value->u.q_sparc->npc = env->npc; #elif defined(TARGET_MIPS) info->value->arch = CPU_INFO_ARCH_MIPS; - info->value->u.mips = g_new0(CpuInfoMIPS, 1); - info->value->u.mips->PC = env->active_tc.PC; + info->value->u.q_mips = g_new0(CpuInfoMIPS, 1); + info->value->u.q_mips->PC = env->active_tc.PC; #elif defined(TARGET_TRICORE) info->value->arch = CPU_INFO_ARCH_TRICORE; info->value->u.tricore = g_new0(CpuInfoTricore, 1); diff --git a/hmp.c b/hmp.c index 3e2a9891c4..c6419da72f 100644 --- a/hmp.c +++ b/hmp.c @@ -319,11 +319,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict) monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->u.ppc->nip); break; case CPU_INFO_ARCH_SPARC: - monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->u.sparc->pc); - monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->u.sparc->npc); + monitor_printf(mon, " pc=0x%016" PRIx64, + cpu->value->u.q_sparc->pc); + monitor_printf(mon, " npc=0x%016" PRIx64, + cpu->value->u.q_sparc->npc); break; case CPU_INFO_ARCH_MIPS: - monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.mips->PC); + monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.q_mips->PC); break; case CPU_INFO_ARCH_TRICORE: monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->u.tricore->PC); diff --git a/scripts/qapi.py b/scripts/qapi.py index 7519cf8e7a..f40dc9e777 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -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): From 423aeaf219890e8a7311dbeef1a925020027c2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Vilanova?= Date: Thu, 4 Feb 2016 19:29:17 +0100 Subject: [PATCH 31/31] qapi: Add missing JSON files in build dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Forgotten in commit 1dde0f4 (trace.json) and commit fafa4d5 (rocker.json). Signed-off-by: Lluís Vilanova Message-Id: <145461055662.15201.2702170180078718114.stgit@localhost> Reviewed-by: Eric Blake [Commit message tweaked] Signed-off-by: Markus Armbruster --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d0de2d46b6..30b1b2db4c 100644 --- a/Makefile +++ b/Makefile @@ -272,7 +272,8 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \ $(SRC_PATH)/qapi/event.json $(SRC_PATH)/qapi/introspect.json \ - $(SRC_PATH)/qapi/crypto.json + $(SRC_PATH)/qapi/crypto.json $(SRC_PATH)/qapi/rocker.json \ + $(SRC_PATH)/qapi/trace.json qapi-types.c qapi-types.h :\ $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)