mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-03 16:25:39 +00:00
qapi-visit: Less indirection in visit_type_Foo_fields()
We were passing 'Foo **obj' to the internal helper function, but all uses within the helper were via reads of '*obj'. Refactor things to pass one less level of indirection, by having the callers dereference before calling. For an example of the generated code change: |-static void visit_type_BalloonInfo_fields(Visitor *v, BalloonInfo **obj, Error **errp) |+static void visit_type_BalloonInfo_fields(Visitor *v, BalloonInfo *obj, Error **errp) | { | Error *err = NULL; | |- visit_type_int(v, "actual", &(*obj)->actual, &err); |+ visit_type_int(v, "actual", &obj->actual, &err); | error_propagate(errp, err); | } | |@@ -261,7 +261,7 @@ void visit_type_BalloonInfo(Visitor *v, | if (!*obj) { | goto out_obj; | } |- visit_type_BalloonInfo_fields(v, obj, &err); |+ visit_type_BalloonInfo_fields(v, *obj, &err); | out_obj: The refactoring will also make it easier to reuse the helpers in a future patch when implicit structs are stored directly in the parent struct rather than boxed through a pointer. Backports commit 655519030b5d20967ae3afa1fe91ef5ad4406065 from qemu
This commit is contained in:
parent
553e946627
commit
f5c93aa7ab
|
@ -16,11 +16,11 @@
|
|||
#include "qemu-common.h"
|
||||
#include "qapi-visit.h"
|
||||
|
||||
static void visit_type_DummyForceArrays_fields(Visitor *v, DummyForceArrays **obj, Error **errp)
|
||||
static void visit_type_DummyForceArrays_fields(Visitor *v, DummyForceArrays *obj, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
||||
visit_type_X86CPUFeatureWordInfoList(v, "unused", &(*obj)->unused, &err);
|
||||
visit_type_X86CPUFeatureWordInfoList(v, "unused", &obj->unused, &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -34,14 +34,13 @@ void visit_type_DummyForceArrays(Visitor *v, const char *name, DummyForceArrays
|
|||
Error *err = NULL;
|
||||
|
||||
visit_start_struct(v, name, (void **)obj, sizeof(DummyForceArrays), &err);
|
||||
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
if (!*obj) {
|
||||
goto out_obj;
|
||||
}
|
||||
visit_type_DummyForceArrays_fields(v, obj, &err);
|
||||
visit_type_DummyForceArrays_fields(v, *obj, &err);
|
||||
error_propagate(errp, err);
|
||||
err = NULL;
|
||||
out_obj:
|
||||
|
@ -64,25 +63,25 @@ void visit_type_QapiErrorClass(Visitor *v, const char *name, QapiErrorClass *obj
|
|||
*obj = value;
|
||||
}
|
||||
|
||||
static void visit_type_X86CPUFeatureWordInfo_fields(Visitor *v, X86CPUFeatureWordInfo **obj, Error **errp)
|
||||
static void visit_type_X86CPUFeatureWordInfo_fields(Visitor *v, X86CPUFeatureWordInfo *obj, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
||||
visit_type_int(v, "cpuid-input-eax", &(*obj)->cpuid_input_eax, &err);
|
||||
visit_type_int(v, "cpuid-input-eax", &obj->cpuid_input_eax, &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
if (visit_optional(v, "cpuid-input-ecx", &(*obj)->has_cpuid_input_ecx)) {
|
||||
visit_type_int(v, "cpuid-input-ecx", &(*obj)->cpuid_input_ecx, &err);
|
||||
if (visit_optional(v, "cpuid-input-ecx", &obj->has_cpuid_input_ecx)) {
|
||||
visit_type_int(v, "cpuid-input-ecx", &obj->cpuid_input_ecx, &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
visit_type_X86CPURegister32(v, "cpuid-register", &(*obj)->cpuid_register, &err);
|
||||
visit_type_X86CPURegister32(v, "cpuid-register", &obj->cpuid_register, &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
visit_type_int(v, "features", &(*obj)->features, &err);
|
||||
visit_type_int(v, "features", &obj->features, &err);
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -96,14 +95,13 @@ void visit_type_X86CPUFeatureWordInfo(Visitor *v, const char *name, X86CPUFeatur
|
|||
Error *err = NULL;
|
||||
|
||||
visit_start_struct(v, name, (void **)obj, sizeof(X86CPUFeatureWordInfo), &err);
|
||||
|
||||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
if (!*obj) {
|
||||
goto out_obj;
|
||||
}
|
||||
visit_type_X86CPUFeatureWordInfo_fields(v, obj, &err);
|
||||
visit_type_X86CPUFeatureWordInfo_fields(v, *obj, &err);
|
||||
error_propagate(errp, err);
|
||||
err = NULL;
|
||||
out_obj:
|
||||
|
|
|
@ -38,7 +38,7 @@ def gen_visit_fields_decl(typ):
|
|||
if typ.name not in struct_fields_seen:
|
||||
ret += mcgen('''
|
||||
|
||||
static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s **obj, Error **errp);
|
||||
static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error **errp);
|
||||
''',
|
||||
c_type=typ.c_name())
|
||||
struct_fields_seen.add(typ.name)
|
||||
|
@ -59,7 +59,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_type_%(c_type)s_fields(v, *obj, errp);
|
||||
visit_end_implicit_struct(v);
|
||||
}
|
||||
error_propagate(errp, err);
|
||||
|
@ -82,7 +82,7 @@ def gen_visit_struct_fields(name, base, members, variants):
|
|||
struct_fields_seen.add(name)
|
||||
ret += mcgen('''
|
||||
|
||||
static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **errp)
|
||||
static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **errp)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
||||
|
@ -91,19 +91,19 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e
|
|||
|
||||
if base:
|
||||
ret += mcgen('''
|
||||
visit_type_%(c_type)s_fields(v, (%(c_type)s **)obj, &err);
|
||||
visit_type_%(c_type)s_fields(v, (%(c_type)s *)obj, &err);
|
||||
''',
|
||||
c_type=base.c_name())
|
||||
ret += gen_err_check()
|
||||
|
||||
ret += gen_visit_fields(members, prefix='(*obj)->')
|
||||
ret += gen_visit_fields(members, prefix='obj->')
|
||||
|
||||
if variants:
|
||||
ret += mcgen('''
|
||||
if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) {
|
||||
if (!visit_start_union(v, !!obj->u.data, &err) || err) {
|
||||
goto out;
|
||||
}
|
||||
switch ((*obj)->%(c_name)s) {
|
||||
switch (obj->%(c_name)s) {
|
||||
''',
|
||||
c_name=c_name(variants.tag_member.name))
|
||||
|
||||
|
@ -118,13 +118,13 @@ static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s **obj, Error **e
|
|||
variants.tag_member.type.prefix))
|
||||
if simple_union_type:
|
||||
ret += mcgen('''
|
||||
visit_type_%(c_type)s(v, "data", &(*obj)->u.%(c_name)s, &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))
|
||||
else:
|
||||
ret += mcgen('''
|
||||
visit_type_implicit_%(c_type)s(v, &(*obj)->u.%(c_name)s, &err);
|
||||
visit_type_implicit_%(c_type)s(v, &obj->u.%(c_name)s, &err);
|
||||
''',
|
||||
c_type=var.type.c_name(),
|
||||
c_name=c_name(var.name))
|
||||
|
@ -271,7 +271,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
|
|||
if (!*obj) {
|
||||
goto out_obj;
|
||||
}
|
||||
visit_type_%(c_name)s_fields(v, obj, &err);
|
||||
visit_type_%(c_name)s_fields(v, *obj, &err);
|
||||
error_propagate(errp, err);
|
||||
err = NULL;
|
||||
out_obj:
|
||||
|
|
Loading…
Reference in a new issue