mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-10 23:05:28 +00:00
qapi: Fix alternates that accept 'number' but not 'int'
The QMP input visitor allows integral values to be assigned by promotion to a QTYPE_QFLOAT. However, when parsing an alternate, we did not take this into account, such that an alternate that accepts 'number' and some other type, but not 'int', would reject integral values. With this patch, we now have the following desirable table: alternate has case selected for 'int' 'number' QTYPE_QINT QTYPE_QFLOAT no no error error no yes 'number' 'number' yes no 'int' error yes yes 'int' 'number' While it is unlikely that we will ever use 'number' in an alternate other than in the testsuite, it never hurts to be more precise in what we allow. Backports commit d00341af384665d259af475b14c96bb8414df415 from qemu
This commit is contained in:
parent
a6b494dcae
commit
65d58b543e
msvc/unicorn
qemu
|
@ -18,28 +18,6 @@
|
|||
#include "qapi-types.h"
|
||||
#include "qapi-visit.h"
|
||||
|
||||
const char *const QapiErrorClass_lookup[] = {
|
||||
"GenericError",
|
||||
"CommandNotFound",
|
||||
"DeviceEncrypted",
|
||||
"DeviceNotActive",
|
||||
"DeviceNotFound",
|
||||
"KVMMissingCap",
|
||||
NULL,
|
||||
};
|
||||
|
||||
const char *const X86CPURegister32_lookup[] = {
|
||||
"EAX",
|
||||
"EBX",
|
||||
"ECX",
|
||||
"EDX",
|
||||
"ESP",
|
||||
"EBP",
|
||||
"ESI",
|
||||
"EDI",
|
||||
NULL,
|
||||
};
|
||||
|
||||
void qapi_free_DummyForceArrays(DummyForceArrays *obj)
|
||||
{
|
||||
QapiDeallocVisitor *qdv;
|
||||
|
@ -67,6 +45,16 @@ const char *const QType_lookup[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
const char *const QapiErrorClass_lookup[] = {
|
||||
"GenericError",
|
||||
"CommandNotFound",
|
||||
"DeviceEncrypted",
|
||||
"DeviceNotActive",
|
||||
"DeviceNotFound",
|
||||
"KVMMissingCap",
|
||||
NULL,
|
||||
};
|
||||
|
||||
void qapi_free_X86CPUFeatureWordInfo(X86CPUFeatureWordInfo *obj)
|
||||
{
|
||||
QapiDeallocVisitor *qdv;
|
||||
|
@ -97,6 +85,18 @@ void qapi_free_X86CPUFeatureWordInfoList(X86CPUFeatureWordInfoList *obj)
|
|||
qapi_dealloc_visitor_cleanup(qdv);
|
||||
}
|
||||
|
||||
const char *const X86CPURegister32_lookup[] = {
|
||||
"EAX",
|
||||
"EBX",
|
||||
"ECX",
|
||||
"EDX",
|
||||
"ESP",
|
||||
"EBP",
|
||||
"ESI",
|
||||
"EDI",
|
||||
NULL,
|
||||
};
|
||||
|
||||
void qapi_free_anyList(anyList *obj)
|
||||
{
|
||||
QapiDeallocVisitor *qdv;
|
||||
|
|
|
@ -33,7 +33,7 @@ struct Visitor
|
|||
void (*type_enum)(Visitor *v, int *obj, const char * const strings[],
|
||||
const char *kind, const char *name, Error **errp);
|
||||
/* May be NULL; only needed for input visitors. */
|
||||
void (*get_next_type)(Visitor *v, QType *type,
|
||||
void (*get_next_type)(Visitor *v, QType *type, bool promote_int,
|
||||
const char *name, Error **errp);
|
||||
/* Must be set. */
|
||||
void (*type_int64)(Visitor *v, int64_t *obj, const char *name,
|
||||
|
|
|
@ -42,8 +42,9 @@ 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
|
||||
* alternate type; for other visitors, leave *@type unchanged.
|
||||
* If @promote_int, treat integers as QTYPE_FLOAT.
|
||||
*/
|
||||
void visit_get_next_type(Visitor *v, QType *type,
|
||||
void visit_get_next_type(Visitor *v, QType *type, bool promote_int,
|
||||
const char *name, Error **errp);
|
||||
void visit_type_enum(Visitor *v, int *obj, const char * const strings[],
|
||||
const char *kind, const char *name, Error **errp);
|
||||
|
|
|
@ -82,11 +82,11 @@ void visit_optional(Visitor *v, bool *present, const char *name,
|
|||
}
|
||||
}
|
||||
|
||||
void visit_get_next_type(Visitor *v, QType *type,
|
||||
void visit_get_next_type(Visitor *v, QType *type, bool promote_int,
|
||||
const char *name, Error **errp)
|
||||
{
|
||||
if (v->get_next_type) {
|
||||
v->get_next_type(v, type, name, errp);
|
||||
v->get_next_type(v, type, promote_int, name, errp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ static void qmp_input_end_list(Visitor *v)
|
|||
qmp_input_pop(qiv, &error_abort);
|
||||
}
|
||||
|
||||
static void qmp_input_get_next_type(Visitor *v, QType *type,
|
||||
static void qmp_input_get_next_type(Visitor *v, QType *type, bool promote_int,
|
||||
const char *name, Error **errp)
|
||||
{
|
||||
QmpInputVisitor *qiv = to_qiv(v);
|
||||
|
@ -218,6 +218,9 @@ static void qmp_input_get_next_type(Visitor *v, QType *type,
|
|||
error_setg(errp, QERR_MISSING_PARAMETER, name ? name : "null");
|
||||
return;
|
||||
}
|
||||
if (promote_int && *type == QTYPE_QINT) {
|
||||
*type = QTYPE_QFLOAT;
|
||||
}
|
||||
*type = qobject_type(qobj);
|
||||
}
|
||||
|
||||
|
|
|
@ -181,6 +181,11 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *name, Error
|
|||
|
||||
|
||||
def gen_visit_alternate(name, variants):
|
||||
promote_int = 'true'
|
||||
for var in variants.variants:
|
||||
if var.type.alternate_qtype() == 'QTYPE_QINT':
|
||||
promote_int = 'false'
|
||||
|
||||
ret = mcgen('''
|
||||
|
||||
void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp)
|
||||
|
@ -191,16 +196,14 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error
|
|||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
visit_get_next_type(v, &(*obj)->type, name, &err);
|
||||
visit_get_next_type(v, &(*obj)->type, %(promote_int)s, name, &err);
|
||||
if (err) {
|
||||
goto out_obj;
|
||||
}
|
||||
switch ((*obj)->type) {
|
||||
''',
|
||||
c_name=c_name(name))
|
||||
c_name=c_name(name), promote_int=promote_int)
|
||||
|
||||
# FIXME: When 'number' but not 'int' is present in the alternate, we
|
||||
# should allow QTYPE_INT to promote to QTYPE_FLOAT.
|
||||
for var in variants.variants:
|
||||
ret += mcgen('''
|
||||
case %(case)s:
|
||||
|
|
Loading…
Reference in a new issue