mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
qlit: move qlit from check-qjson to qobject/
Fix code style issues while at it, to please checkpatch. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20170825105913.4060-3-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
0f9afc2a8b
commit
28035bcdf4
4 changed files with 140 additions and 96 deletions
|
@ -16,6 +16,7 @@
|
|||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/types.h"
|
||||
#include "qapi/qmp/qjson.h"
|
||||
#include "qapi/qmp/qlit.h"
|
||||
#include "qemu-common.h"
|
||||
|
||||
static void escaped_string(void)
|
||||
|
@ -1059,101 +1060,6 @@ static void keyword_literal(void)
|
|||
QDECREF(null);
|
||||
}
|
||||
|
||||
typedef struct LiteralQDictEntry LiteralQDictEntry;
|
||||
typedef struct LiteralQObject LiteralQObject;
|
||||
|
||||
struct LiteralQObject
|
||||
{
|
||||
int type;
|
||||
union {
|
||||
int64_t qnum;
|
||||
const char *qstr;
|
||||
LiteralQDictEntry *qdict;
|
||||
LiteralQObject *qlist;
|
||||
} value;
|
||||
};
|
||||
|
||||
struct LiteralQDictEntry
|
||||
{
|
||||
const char *key;
|
||||
LiteralQObject value;
|
||||
};
|
||||
|
||||
#define QLIT_QNUM(val) (LiteralQObject){.type = QTYPE_QNUM, .value.qnum = (val)}
|
||||
#define QLIT_QSTR(val) (LiteralQObject){.type = QTYPE_QSTRING, .value.qstr = (val)}
|
||||
#define QLIT_QDICT(val) (LiteralQObject){.type = QTYPE_QDICT, .value.qdict = (val)}
|
||||
#define QLIT_QLIST(val) (LiteralQObject){.type = QTYPE_QLIST, .value.qlist = (val)}
|
||||
|
||||
typedef struct QListCompareHelper
|
||||
{
|
||||
int index;
|
||||
LiteralQObject *objs;
|
||||
int result;
|
||||
} QListCompareHelper;
|
||||
|
||||
static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs);
|
||||
|
||||
static void compare_helper(QObject *obj, void *opaque)
|
||||
{
|
||||
QListCompareHelper *helper = opaque;
|
||||
|
||||
if (helper->result == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (helper->objs[helper->index].type == QTYPE_NONE) {
|
||||
helper->result = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
helper->result = compare_litqobj_to_qobj(&helper->objs[helper->index++], obj);
|
||||
}
|
||||
|
||||
static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs)
|
||||
{
|
||||
int64_t val;
|
||||
|
||||
if (!rhs || lhs->type != qobject_type(rhs)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (lhs->type) {
|
||||
case QTYPE_QNUM:
|
||||
g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val));
|
||||
return lhs->value.qnum == val;
|
||||
case QTYPE_QSTRING:
|
||||
return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to_qstring(rhs))) == 0);
|
||||
case QTYPE_QDICT: {
|
||||
int i;
|
||||
|
||||
for (i = 0; lhs->value.qdict[i].key; i++) {
|
||||
QObject *obj = qdict_get(qobject_to_qdict(rhs), lhs->value.qdict[i].key);
|
||||
|
||||
if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
case QTYPE_QLIST: {
|
||||
QListCompareHelper helper;
|
||||
|
||||
helper.index = 0;
|
||||
helper.objs = lhs->value.qlist;
|
||||
helper.result = 1;
|
||||
|
||||
qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper);
|
||||
|
||||
return helper.result;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void simple_dict(void)
|
||||
{
|
||||
int i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue