mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
qapi: Avoid use of misnamed DO_UPCAST()
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 <eblake@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <1454075341-13658-3-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
6e8e5cb9aa
commit
d7bea75d35
3 changed files with 44 additions and 28 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue