Skip to content

Commit

Permalink
qapi: Replace start_optional()/end_optional() by optional()
Browse files Browse the repository at this point in the history
Semantics of end_optional() differ subtly from the other end_FOO()
callbacks: when start_FOO() succeeds, the matching end_FOO() gets
called regardless of what happens in between.  end_optional() gets
called only when everything in between succeeds as well.  Entirely
undocumented, like all of the visitor API.

The only user of Visitor Callback end_optional() never did anything,
and was removed in commit 9f9ab46.

I'm about to clean up error handling in the generated visitor code,
and end_optional() is in my way.  No users mean no test cases, and
making non-trivial cleanup transformations without test cases doesn't
strike me as a good idea.

Drop end_optional(), and rename start_optional() to optional().  We
can always go back to a pair of callbacks when we have an actual need.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Luiz Capitulino <[email protected]>
  • Loading branch information
Markus Armbruster authored and Luiz Capitulino committed May 15, 2014
1 parent cbc9553 commit e2cd0f4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 31 deletions.
5 changes: 2 additions & 3 deletions include/qapi/visitor-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ struct Visitor
Error **errp);

/* May be NULL */
void (*start_optional)(Visitor *v, bool *present, const char *name,
Error **errp);
void (*end_optional)(Visitor *v, Error **errp);
void (*optional)(Visitor *v, bool *present, const char *name,
Error **errp);

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);
Expand Down
5 changes: 2 additions & 3 deletions include/qapi/visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ void visit_end_implicit_struct(Visitor *v, Error **errp);
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);
void visit_start_optional(Visitor *v, bool *present, const char *name,
Error **errp);
void visit_end_optional(Visitor *v, Error **errp);
void visit_optional(Visitor *v, bool *present, const char *name,
Error **errp);
void visit_get_next_type(Visitor *v, int *obj, const int *qtypes,
const char *name, Error **errp);
void visit_type_enum(Visitor *v, int *obj, const char *strings[],
Expand Down
5 changes: 2 additions & 3 deletions qapi/opts-visitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)


static void
opts_start_optional(Visitor *v, bool *present, const char *name,
Error **errp)
opts_optional(Visitor *v, bool *present, const char *name, Error **errp)
{
OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);

Expand Down Expand Up @@ -528,7 +527,7 @@ opts_visitor_new(const QemuOpts *opts)
/* type_number() is not filled in, but this is not the first visitor to
* skip some mandatory methods... */

ov->visitor.start_optional = &opts_start_optional;
ov->visitor.optional = &opts_optional;

ov->opts_root = opts;

Expand Down
15 changes: 4 additions & 11 deletions qapi/qapi-visit-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,11 @@ void visit_end_list(Visitor *v, Error **errp)
v->end_list(v, errp);
}

void visit_start_optional(Visitor *v, bool *present, const char *name,
Error **errp)
void visit_optional(Visitor *v, bool *present, const char *name,
Error **errp)
{
if (!error_is_set(errp) && v->start_optional) {
v->start_optional(v, present, name, errp);
}
}

void visit_end_optional(Visitor *v, Error **errp)
{
if (!error_is_set(errp) && v->end_optional) {
v->end_optional(v, errp);
if (!error_is_set(errp) && v->optional) {
v->optional(v, present, name, errp);
}
}

Expand Down
6 changes: 3 additions & 3 deletions qapi/qmp-input-visitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name,
}
}

static void qmp_input_start_optional(Visitor *v, bool *present,
const char *name, Error **errp)
static void qmp_input_optional(Visitor *v, bool *present, const char *name,
Error **errp)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true);
Expand Down Expand Up @@ -329,7 +329,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj)
v->visitor.type_bool = qmp_input_type_bool;
v->visitor.type_str = qmp_input_type_str;
v->visitor.type_number = qmp_input_type_number;
v->visitor.start_optional = qmp_input_start_optional;
v->visitor.optional = qmp_input_optional;
v->visitor.get_next_type = qmp_input_get_next_type;

qmp_input_push(v, obj, NULL);
Expand Down
6 changes: 3 additions & 3 deletions qapi/string-input-visitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ static void parse_type_number(Visitor *v, double *obj, const char *name,
*obj = val;
}

static void parse_start_optional(Visitor *v, bool *present,
const char *name, Error **errp)
static void parse_optional(Visitor *v, bool *present, const char *name,
Error **errp)
{
StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);

Expand Down Expand Up @@ -155,7 +155,7 @@ StringInputVisitor *string_input_visitor_new(const char *str)
v->visitor.type_bool = parse_type_bool;
v->visitor.type_str = parse_type_str;
v->visitor.type_number = parse_type_number;
v->visitor.start_optional = parse_start_optional;
v->visitor.optional = parse_optional;

v->string = str;
return v;
Expand Down
5 changes: 2 additions & 3 deletions scripts/qapi-commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def gen_visitor_input_block(args, dealloc=False):
for argname, argtype, optional, structured in parse_args(args):
if optional:
ret += mcgen('''
visit_start_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
if (has_%(c_name)s) {
''',
c_name=c_var(argname), name=argname, errp=errparg)
Expand All @@ -145,8 +145,7 @@ def gen_visitor_input_block(args, dealloc=False):
pop_indent()
ret += mcgen('''
}
visit_end_optional(v, %(errp)s);
''', errp=errparg)
''')

if dealloc:
ret += mcgen('''
Expand Down
3 changes: 1 addition & 2 deletions scripts/qapi-visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base =
for argname, argentry, optional, structured in parse_args(members):
if optional:
ret += mcgen('''
visit_start_optional(m, &(*obj)->%(c_prefix)shas_%(c_name)s, "%(name)s", &err);
visit_optional(m, &(*obj)->%(c_prefix)shas_%(c_name)s, "%(name)s", &err);
if ((*obj)->%(prefix)shas_%(c_name)s) {
''',
c_prefix=c_var(field_prefix), prefix=field_prefix,
Expand All @@ -82,7 +82,6 @@ def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base =
pop_indent()
ret += mcgen('''
}
visit_end_optional(m, &err);
''')

pop_indent()
Expand Down

0 comments on commit e2cd0f4

Please sign in to comment.