mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-22 19:45:35 +00:00
qapi: Simplify visits of optional fields
None of the visitor callbacks would set an error when testing if an optional field was present; make this part of the interface contract by eliminating the errp argument. The resulting generated code has a nice diff: |- visit_optional(v, &has_fdset_id, "fdset-id", &err); |- if (err) { |- goto out; |- } |+ visit_optional(v, &has_fdset_id, "fdset-id"); | if (has_fdset_id) { | visit_type_int(v, &fdset_id, "fdset-id", &err); | if (err) { | goto out; | } | } Backports commit 5cdc8831a795fb8452d7e34f644202fd724e122a from qemu
This commit is contained in:
parent
65d58b543e
commit
f3d2380f6d
|
@ -62,10 +62,7 @@ static void visit_type_X86CPUFeatureWordInfo_fields(Visitor *v, X86CPUFeatureWor
|
|||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
visit_optional(v, &(*obj)->has_cpuid_input_ecx, "cpuid-input-ecx", &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
visit_optional(v, &(*obj)->has_cpuid_input_ecx, "cpuid-input-ecx");
|
||||
if ((*obj)->has_cpuid_input_ecx) {
|
||||
visit_type_int(v, &(*obj)->cpuid_input_ecx, "cpuid-input-ecx", &err);
|
||||
if (err) {
|
||||
|
|
|
@ -52,9 +52,8 @@ struct Visitor
|
|||
void (*type_any)(Visitor *v, QObject **obj, const char *name,
|
||||
Error **errp);
|
||||
|
||||
/* May be NULL */
|
||||
void (*optional)(Visitor *v, bool *present, const char *name,
|
||||
Error **errp);
|
||||
/* 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);
|
||||
|
|
|
@ -36,8 +36,15 @@ 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);
|
||||
void visit_end_list(Visitor *v);
|
||||
void visit_optional(Visitor *v, bool *present, const char *name,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* Check if an optional member @name of an object needs visiting.
|
||||
* For input visitors, set *@present according to whether the
|
||||
* corresponding visit_type_*() needs calling; for other visitors,
|
||||
* leave *@present unchanged.
|
||||
*/
|
||||
void visit_optional(Visitor *v, bool *present, const char *name);
|
||||
|
||||
/**
|
||||
* Determine the qtype of the item @name in the current object visit.
|
||||
* For input visitors, set *@type to the correct qtype of a qapi
|
||||
|
|
|
@ -74,11 +74,10 @@ void visit_end_union(Visitor *v, bool data_present, Error **errp)
|
|||
}
|
||||
}
|
||||
|
||||
void visit_optional(Visitor *v, bool *present, const char *name,
|
||||
Error **errp)
|
||||
void visit_optional(Visitor *v, bool *present, const char *name)
|
||||
{
|
||||
if (v->optional) {
|
||||
v->optional(v, present, name, errp);
|
||||
v->optional(v, present, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -319,8 +319,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,
|
||||
Error **errp)
|
||||
static void qmp_input_optional(Visitor *v, bool *present, const char *name)
|
||||
{
|
||||
QmpInputVisitor *qiv = to_qiv(v);
|
||||
QObject *qobj = qmp_input_get_object(qiv, name, true);
|
||||
|
|
|
@ -297,8 +297,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,
|
||||
Error **errp)
|
||||
static void parse_optional(Visitor *v, bool *present, const char *name)
|
||||
{
|
||||
StringInputVisitor *siv = to_siv(v);
|
||||
|
||||
|
|
|
@ -1656,15 +1656,11 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False):
|
|||
for memb in members:
|
||||
if memb.optional:
|
||||
ret += mcgen('''
|
||||
visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s", %(errp)s);
|
||||
visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s");
|
||||
if (%(prefix)shas_%(c_name)s) {
|
||||
''',
|
||||
prefix=prefix, c_name=c_name(memb.name),
|
||||
name=memb.name, errp=errparg)
|
||||
ret += gen_err_check(skiperr=skiperr)
|
||||
ret += mcgen('''
|
||||
if (%(prefix)shas_%(c_name)s) {
|
||||
''',
|
||||
prefix=prefix, c_name=c_name(memb.name))
|
||||
push_indent()
|
||||
|
||||
# Ugly: sometimes we need to cast away const
|
||||
|
|
Loading…
Reference in a new issue