mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-25 21:28:03 +00:00
qapi-event: Simplify visit of non-implicit data
Commit 7ce106a9 documented why we don't generated a visit_type_FOO() for implicit types; and therefore events with an anonymous type for 'data' have to open-code a visit. Note that the open-coded visit in qapi-event.c is slightly different from what is done in qapi-visit.c for normal types, in part because we don't have to check for *obj being NULL or free things on error. But where the type is not implicit, it is nicer to reuse the normal visit instead of open-coding a duplicate. At the moment, the only event with a non-implicit 'data' is in the testsuite, where test-qapi-event.c changes as follows: |@@ -155,6 +155,7 @@ void qapi_event_send___org_qemu_x_event( | __org_qemu_x_Struct param = { | __org_qemu_x_member1, (char *)__org_qemu_x_member2, has_q_wchar_t, q_wchar_t | }; |+ __org_qemu_x_Struct *arg = ¶m; | | emit = qmp_event_get_func_emit(); | if (!emit) { |@@ -164,16 +165,7 @@ void qapi_event_send___org_qemu_x_event( | qmp = qmp_event_build_dict("__ORG.QEMU_X-EVENT"); | | v = qmp_output_visitor_new(&obj); |- |- visit_start_struct(v, "__ORG.QEMU_X-EVENT", NULL, 0, &err); |- if (err) { |- goto out; |- } |- visit_type___org_qemu_x_Struct_members(v, ¶m, &err); |- if (!err) { |- if (!err) { |- visit_check_struct(v, &err); |- } |- visit_end_struct(v, NULL); |+ visit_type___org_qemu_x_Struct(v, "__ORG.QEMU_X-EVENT", &arg, &err); | if (err) { | goto out; | } Backports commit 4d0b268fdb17a1fed10fe980e77fd388e5427bfd from qemu
This commit is contained in:
parent
b5220a6867
commit
6ff318b839
1 changed files with 17 additions and 2 deletions
|
@ -48,6 +48,11 @@ def gen_param_var(typ):
|
||||||
|
|
||||||
};
|
};
|
||||||
''')
|
''')
|
||||||
|
if not typ.is_implicit():
|
||||||
|
ret += mcgen('''
|
||||||
|
%(c_name)s *arg = ¶m;
|
||||||
|
''',
|
||||||
|
c_name=typ.c_name())
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,6 +96,14 @@ def gen_event_send(name, arg_type):
|
||||||
if arg_type and not arg_type.is_empty():
|
if arg_type and not arg_type.is_empty():
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
v = qmp_output_visitor_new(&obj);
|
v = qmp_output_visitor_new(&obj);
|
||||||
|
''')
|
||||||
|
if not arg_type.is_implicit():
|
||||||
|
ret += mcgen('''
|
||||||
|
visit_type_%(c_name)s(v, "%(name)s", &arg, &err);
|
||||||
|
''',
|
||||||
|
name=name, c_name=arg_type.c_name())
|
||||||
|
else:
|
||||||
|
ret += mcgen('''
|
||||||
|
|
||||||
visit_start_struct(v, "%(name)s", NULL, 0, &err);
|
visit_start_struct(v, "%(name)s", NULL, 0, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -101,14 +114,16 @@ def gen_event_send(name, arg_type):
|
||||||
visit_check_struct(v, &err);
|
visit_check_struct(v, &err);
|
||||||
}
|
}
|
||||||
visit_end_struct(v, NULL);
|
visit_end_struct(v, NULL);
|
||||||
|
''',
|
||||||
|
name=name, c_name=arg_type.c_name())
|
||||||
|
ret += mcgen('''
|
||||||
if (err) {
|
if (err) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
visit_complete(v, &obj);
|
visit_complete(v, &obj);
|
||||||
qdict_put_obj(qmp, "data", obj);
|
qdict_put_obj(qmp, "data", obj);
|
||||||
''',
|
''')
|
||||||
name=name, c_name=arg_type.c_name())
|
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
emit(%(c_enum)s, qmp, &err);
|
emit(%(c_enum)s, qmp, &err);
|
||||||
|
|
Loading…
Reference in a new issue