From 7c91aabd8964cfdf637f302c579c95401f21ce92 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:48 -0700 Subject: 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 - 2 files changed, 2 deletions(-) (limited to 'include') 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 -- cgit v1.2.3 From 4c40314a35816de635e7170eaacdc0c35be83a8a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:49 -0700 Subject: 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 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') 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); -- cgit v1.2.3 From f755dea79dc81b0d6a8f6414e0672e165e28d8ba Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:50 -0700 Subject: 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 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include') 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); }; -- cgit v1.2.3 From 04e070d217b4414f1f91aa8ad25fc0ae7ca0be93 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:51 -0700 Subject: 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 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'include') 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); }; -- cgit v1.2.3 From 4fa45492c3387c0fa51e8e81160ac9a7814f44a2 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:53 -0700 Subject: 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 --- include/qom/object.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'include') 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); /** -- cgit v1.2.3 From 51e72bc1dd6ace6e91d675f41a1f09bd00ab8043 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:54 -0700 Subject: 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 --- include/qapi/visitor.h | 52 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'include') 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 -- cgit v1.2.3 From d7bce9999df85c56c8cb1fcffd944d51bff8ff48 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:55 -0700 Subject: 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 --- include/qom/object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') 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); /** -- cgit v1.2.3 From 0b2a0d6bb2446060944061e53e87d0c7addede79 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:56 -0700 Subject: 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 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'include') 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 -- cgit v1.2.3 From 337283dffbb5ad5860ed00408a5fd0665c21be07 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:57 -0700 Subject: 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 --- include/qapi/visitor-impl.h | 11 ++++------- include/qapi/visitor.h | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'include') 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); -- cgit v1.2.3 From 08f9541dec51700abef0c37994213164ca4e4fc9 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 29 Jan 2016 06:48:59 -0700 Subject: 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 --- include/qapi/visitor-impl.h | 9 ++++++--- include/qapi/visitor.h | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'include') 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. -- cgit v1.2.3