qlit: move qlit from check-qjson to qobject/

Fix code style issues while at it, to please checkpatch.

Backports commit 28035bcdf4647245743cf87cea3788331bf67a5f from qemu
This commit is contained in:
Marc-André Lureau 2018-03-07 17:03:34 -05:00 committed by Lioncash
parent 101f763077
commit c85b87fe06
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
8 changed files with 160 additions and 1 deletions

View file

@ -211,6 +211,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\
<ClCompile Include="..\..\..\qemu\qobject\qfloat.c" /> <ClCompile Include="..\..\..\qemu\qobject\qfloat.c" />
<ClCompile Include="..\..\..\qemu\qobject\qint.c" /> <ClCompile Include="..\..\..\qemu\qobject\qint.c" />
<ClCompile Include="..\..\..\qemu\qobject\qlist.c" /> <ClCompile Include="..\..\..\qemu\qobject\qlist.c" />
<ClCompile Include="..\..\..\qemu\qobject\qlit.c" />
<ClCompile Include="..\..\..\qemu\qobject\qnull.c" /> <ClCompile Include="..\..\..\qemu\qobject\qnull.c" />
<ClCompile Include="..\..\..\qemu\qobject\qobject.c" /> <ClCompile Include="..\..\..\qemu\qobject\qobject.c" />
<ClCompile Include="..\..\..\qemu\qobject\qstring.c" /> <ClCompile Include="..\..\..\qemu\qobject\qstring.c" />
@ -323,6 +324,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qerror.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qerror.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qjson.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qjson.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlit.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qnum.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qnum.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qobject.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qobject.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qstring.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qstring.h" />

View file

@ -104,6 +104,9 @@
<ClCompile Include="..\..\..\qemu\qobject\qlist.c"> <ClCompile Include="..\..\..\qemu\qobject\qlist.c">
<Filter>qemu\qobject</Filter> <Filter>qemu\qobject</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qlit.c">
<Filter>qemu\qobject</Filter>
</ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qnull.c"> <ClCompile Include="..\..\..\qemu\qobject\qnull.c">
<Filter>qemu\qobject</Filter> <Filter>qemu\qobject</Filter>
</ClCompile> </ClCompile>
@ -412,6 +415,9 @@
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h"> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h">
<Filter>qemu\include\qapi\qmp</Filter> <Filter>qemu\include\qapi\qmp</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlit.h">
<Filter>qemu\include\qapi\qmp</Filter>
</ClInclude>
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qnum.h"> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qnum.h">
<Filter>qemu\include\qapi\qmp</Filter> <Filter>qemu\include\qapi\qmp</Filter>
</ClInclude> </ClInclude>

View file

@ -39,6 +39,7 @@
<ClCompile Include="..\..\..\qemu\qobject\qfloat.c" /> <ClCompile Include="..\..\..\qemu\qobject\qfloat.c" />
<ClCompile Include="..\..\..\qemu\qobject\qint.c" /> <ClCompile Include="..\..\..\qemu\qobject\qint.c" />
<ClCompile Include="..\..\..\qemu\qobject\qlist.c" /> <ClCompile Include="..\..\..\qemu\qobject\qlist.c" />
<ClCompile Include="..\..\..\qemu\qobject\qlit.c" />
<ClCompile Include="..\..\..\qemu\qobject\qnull.c" /> <ClCompile Include="..\..\..\qemu\qobject\qnull.c" />
<ClCompile Include="..\..\..\qemu\qobject\qobject.c" /> <ClCompile Include="..\..\..\qemu\qobject\qobject.c" />
<ClCompile Include="..\..\..\qemu\qobject\qstring.c" /> <ClCompile Include="..\..\..\qemu\qobject\qstring.c" />
@ -139,6 +140,7 @@
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qint.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qint.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qjson.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qjson.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlit.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qobject.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qobject.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qstring.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qstring.h" />
<ClInclude Include="..\..\..\qemu\include\qapi\string-input-visitor.h" /> <ClInclude Include="..\..\..\qemu\include\qapi\string-input-visitor.h" />

View file

@ -132,6 +132,9 @@
<ClCompile Include="..\..\..\qemu\qobject\qlist.c"> <ClCompile Include="..\..\..\qemu\qobject\qlist.c">
<Filter>qemu\qobject</Filter> <Filter>qemu\qobject</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qlit.c">
<Filter>qemu\qobject</Filter>
</ClCompile>
<ClCompile Include="..\..\..\qemu\qobject\qnull.c"> <ClCompile Include="..\..\..\qemu\qobject\qnull.c">
<Filter>qemu\qobject</Filter> <Filter>qemu\qobject</Filter>
</ClCompile> </ClCompile>
@ -402,6 +405,9 @@
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h"> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlist.h">
<Filter>qemu\include\qapi\qmp</Filter> <Filter>qemu\include\qapi\qmp</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qlit.h">
<Filter>qemu\include\qapi\qmp</Filter>
</ClInclude>
<ClInclude Include="..\..\..\qemu\include\qapi\qmp\qnum.h"> <ClInclude Include="..\..\..\qemu\include\qapi\qmp\qnum.h">
<Filter>qemu\include\qapi\qmp</Filter> <Filter>qemu\include\qapi\qmp</Filter>
</ClInclude> </ClInclude>

View file

@ -230,6 +230,7 @@ symbols = (
'commonNaNToFloat32', 'commonNaNToFloat32',
'commonNaNToFloat64', 'commonNaNToFloat64',
'commonNaNToFloatx80', 'commonNaNToFloatx80',
'compare_litqobj_to_qobj',
'compute_abs_deadline', 'compute_abs_deadline',
'cond_name', 'cond_name',
'configure_accelerator', 'configure_accelerator',

View file

@ -0,0 +1,49 @@
/*
* Copyright IBM, Corp. 2009
* Copyright (c) 2013, 2015, 2017 Red Hat Inc.
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
* Markus Armbruster <armbru@redhat.com>
* Marc-André Lureau <marcandre.lureau@redhat.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*
*/
#ifndef QLIT_H
#define QLIT_H
#include "qapi-types.h"
#include "qobject.h"
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)}
int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs);
#endif /* QLIT_H */

View file

@ -1 +1 @@
util-obj-y = qnull.o qobject.o qstring.o qdict.o qlist.o qbool.o qnum.o util-obj-y = qnull.o qobject.o qstring.o qdict.o qlist.o qbool.o qnum.o qlit.o

93
qemu/qobject/qlit.c Normal file
View file

@ -0,0 +1,93 @@
/*
* QLit literal qobject
*
* Copyright IBM, Corp. 2009
* Copyright (c) 2013, 2015, 2017 Red Hat Inc.
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
* Markus Armbruster <armbru@redhat.com>
* Marc-André Lureau <marcandre.lureau@redhat.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
*/
#include "qemu/osdep.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/qlit.h"
#include "qapi/qmp/qnum.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qstring.h"
typedef struct QListCompareHelper {
int index;
LiteralQObject *objs;
int result;
} QListCompareHelper;
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);
}
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;
}