From c85b87fe066639f6fc299178c8d74048b7970d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 7 Mar 2018 17:03:34 -0500 Subject: [PATCH] qlit: move qlit from check-qjson to qobject/ Fix code style issues while at it, to please checkpatch. Backports commit 28035bcdf4647245743cf87cea3788331bf67a5f from qemu --- msvc/unicorn/unicorn/unicorn.vcxproj | 2 + msvc/unicorn/unicorn/unicorn.vcxproj.filters | 6 ++ .../unicorn_static/unicorn_static.vcxproj | 2 + .../unicorn_static.vcxproj.filters | 6 ++ qemu/header_gen.py | 1 + qemu/include/qapi/qmp/qlit.h | 49 ++++++++++ qemu/qobject/Makefile.objs | 2 +- qemu/qobject/qlit.c | 93 +++++++++++++++++++ 8 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 qemu/include/qapi/qmp/qlit.h create mode 100644 qemu/qobject/qlit.c diff --git a/msvc/unicorn/unicorn/unicorn.vcxproj b/msvc/unicorn/unicorn/unicorn.vcxproj index e52a09d8..6c31d7e1 100644 --- a/msvc/unicorn/unicorn/unicorn.vcxproj +++ b/msvc/unicorn/unicorn/unicorn.vcxproj @@ -211,6 +211,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\ + @@ -323,6 +324,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\ + diff --git a/msvc/unicorn/unicorn/unicorn.vcxproj.filters b/msvc/unicorn/unicorn/unicorn.vcxproj.filters index 6f250ed4..e33d35e9 100644 --- a/msvc/unicorn/unicorn/unicorn.vcxproj.filters +++ b/msvc/unicorn/unicorn/unicorn.vcxproj.filters @@ -104,6 +104,9 @@ qemu\qobject + + qemu\qobject + qemu\qobject @@ -412,6 +415,9 @@ qemu\include\qapi\qmp + + qemu\include\qapi\qmp + qemu\include\qapi\qmp diff --git a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj index c770a423..355a330b 100644 --- a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj +++ b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj @@ -39,6 +39,7 @@ + @@ -139,6 +140,7 @@ + diff --git a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters index 17d4f11b..b8555bb0 100644 --- a/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters +++ b/msvc/unicorn/unicorn_static/unicorn_static.vcxproj.filters @@ -132,6 +132,9 @@ qemu\qobject + + qemu\qobject + qemu\qobject @@ -402,6 +405,9 @@ qemu\include\qapi\qmp + + qemu\include\qapi\qmp + qemu\include\qapi\qmp diff --git a/qemu/header_gen.py b/qemu/header_gen.py index ed65006b..19615ae3 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -230,6 +230,7 @@ symbols = ( 'commonNaNToFloat32', 'commonNaNToFloat64', 'commonNaNToFloatx80', + 'compare_litqobj_to_qobj', 'compute_abs_deadline', 'cond_name', 'configure_accelerator', diff --git a/qemu/include/qapi/qmp/qlit.h b/qemu/include/qapi/qmp/qlit.h new file mode 100644 index 00000000..280db506 --- /dev/null +++ b/qemu/include/qapi/qmp/qlit.h @@ -0,0 +1,49 @@ +/* + * Copyright IBM, Corp. 2009 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster + * Marc-André Lureau + * + * 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 */ diff --git a/qemu/qobject/Makefile.objs b/qemu/qobject/Makefile.objs index 8997b525..2b33845c 100644 --- a/qemu/qobject/Makefile.objs +++ b/qemu/qobject/Makefile.objs @@ -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 diff --git a/qemu/qobject/qlit.c b/qemu/qobject/qlit.c new file mode 100644 index 00000000..bf47ad77 --- /dev/null +++ b/qemu/qobject/qlit.c @@ -0,0 +1,93 @@ +/* + * QLit literal qobject + * + * Copyright IBM, Corp. 2009 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster + * Marc-André Lureau + * + * 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; +}