2011-11-15 01:05:29 +04:00
|
|
|
/*
|
|
|
|
* QMP Output Visitor unit-tests.
|
|
|
|
*
|
2015-05-04 18:05:06 +03:00
|
|
|
* Copyright (C) 2011, 2015 Red Hat Inc.
|
2011-11-15 01:05:29 +04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2012-12-06 14:22:34 +04:00
|
|
|
#include "qemu-common.h"
|
2011-11-15 01:05:29 +04:00
|
|
|
#include "qapi/qmp-output-visitor.h"
|
|
|
|
#include "test-qapi-types.h"
|
|
|
|
#include "test-qapi-visit.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/qmp/types.h"
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
typedef struct TestOutputVisitorData {
|
|
|
|
QmpOutputVisitor *qov;
|
|
|
|
Visitor *ov;
|
|
|
|
} TestOutputVisitorData;
|
|
|
|
|
|
|
|
static void visitor_output_setup(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
data->qov = qmp_output_visitor_new();
|
|
|
|
g_assert(data->qov != NULL);
|
|
|
|
|
|
|
|
data->ov = qmp_output_get_visitor(data->qov);
|
|
|
|
g_assert(data->ov != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void visitor_output_teardown(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
qmp_output_visitor_cleanup(data->qov);
|
|
|
|
data->qov = NULL;
|
|
|
|
data->ov = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_int(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
int64_t value = -42;
|
|
|
|
QObject *obj;
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_int(data->ov, NULL, &value, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QINT);
|
|
|
|
g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, value);
|
|
|
|
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_bool(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
bool value = true;
|
|
|
|
QObject *obj;
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_bool(data->ov, NULL, &value, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QBOOL);
|
2015-05-16 01:24:59 +03:00
|
|
|
g_assert(qbool_get_bool(qobject_to_qbool(obj)) == value);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_number(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
double value = 3.14;
|
|
|
|
QObject *obj;
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_number(data->ov, NULL, &value, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QFLOAT);
|
|
|
|
g_assert(qfloat_get_double(qobject_to_qfloat(obj)) == value);
|
|
|
|
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_string(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
char *string = (char *) "Q E M U";
|
|
|
|
QObject *obj;
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_str(data->ov, NULL, &string, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QSTRING);
|
|
|
|
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, string);
|
|
|
|
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_no_string(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
char *string = NULL;
|
|
|
|
QObject *obj;
|
|
|
|
|
|
|
|
/* A null string should return "" */
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_str(data->ov, NULL, &string, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QSTRING);
|
|
|
|
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==, "");
|
|
|
|
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_enum(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
QObject *obj;
|
|
|
|
EnumOne i;
|
|
|
|
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
for (i = 0; i < ENUM_ONE__MAX; i++) {
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_EnumOne(data->ov, "unused", &i, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QSTRING);
|
|
|
|
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==,
|
|
|
|
EnumOne_lookup[i]);
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 };
|
2014-05-02 15:26:29 +04:00
|
|
|
Error *err;
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
|
2014-05-02 15:26:29 +04:00
|
|
|
err = NULL;
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err);
|
2014-05-02 15:26:29 +04:00
|
|
|
g_assert(err);
|
|
|
|
error_free(err);
|
2011-11-15 01:05:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void test_visitor_out_struct(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
TestStruct test_struct = { .integer = 42,
|
|
|
|
.boolean = false,
|
|
|
|
.string = (char *) "foo"};
|
|
|
|
TestStruct *p = &test_struct;
|
|
|
|
QObject *obj;
|
|
|
|
QDict *qdict;
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_TestStruct(data->ov, NULL, &p, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QDICT);
|
|
|
|
|
|
|
|
qdict = qobject_to_qdict(obj);
|
|
|
|
g_assert_cmpint(qdict_size(qdict), ==, 3);
|
|
|
|
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 42);
|
2015-05-16 01:25:00 +03:00
|
|
|
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, false);
|
2011-11-15 01:05:29 +04:00
|
|
|
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "foo");
|
|
|
|
|
|
|
|
QDECREF(qdict);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
int64_t value = 42;
|
2015-05-04 18:05:29 +03:00
|
|
|
UserDefTwo *ud2;
|
2011-11-15 01:05:29 +04:00
|
|
|
QObject *obj;
|
|
|
|
QDict *qdict, *dict1, *dict2, *dict3, *userdef;
|
|
|
|
const char *string = "user def string";
|
2012-02-25 16:47:10 +04:00
|
|
|
const char *strings[] = { "forty two", "forty three", "forty four",
|
|
|
|
"forty five" };
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
ud2 = g_malloc0(sizeof(*ud2));
|
|
|
|
ud2->string0 = g_strdup(strings[0]);
|
|
|
|
|
qapi: Drop tests for inline nested structs
A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument;
but existing use of inline nested structs conflicts with that goal.
More precisely, a definition in the QAPI schema associates a name
with a set of properties:
Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } }
associates the global name 'Foo' with properties (meta-type struct)
and MEMBERS...
Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type
TYPE) and (optional false) within type Foo
The syntax of example 1 is extensible; if we need another property,
we add another name/value pair to the dictionary (such as
'base':TYPE). The syntax of example 2 is not extensible, because
the right hand side can only be a type.
We have used name encoding to add a property: "'*mumble': 'int'"
associates 'mumble' with (type int) and (optional true). Nice,
but doesn't scale. So the solution is to change our existing uses
to be syntactic sugar to an extensible form:
NAME: TYPE --> NAME: { 'type': TYPE, 'optional': false }
*ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }
This patch fixes the testsuite to avoid inline nested types, by
breaking the nesting into explicit types; it means that the type
is now boxed instead of unboxed in C code, but makes no difference
on the wire (and if desired, a later patch could change the
generator to not do so much boxing in C). When touching code to
add new allocations, also convert existing allocations to
consistently prefer typesafe g_new0 over g_malloc0 when a type
name is involved.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-05-04 18:05:30 +03:00
|
|
|
ud2->dict1 = g_malloc0(sizeof(*ud2->dict1));
|
|
|
|
ud2->dict1->string1 = g_strdup(strings[1]);
|
|
|
|
|
|
|
|
ud2->dict1->dict2 = g_malloc0(sizeof(*ud2->dict1->dict2));
|
|
|
|
ud2->dict1->dict2->userdef = g_new0(UserDefOne, 1);
|
|
|
|
ud2->dict1->dict2->userdef->string = g_strdup(string);
|
qapi: Unbox base members
Rather than storing a base class as a pointer to a box, just
store the fields of that base class in the same order, so that
a child struct can be directly cast to its parent. This gives
less malloc overhead, less pointer dereferencing, and even less
generated code. Compare to the earlier commit 1e6c1616a "qapi:
Generate a nicer struct for flat unions" (although that patch
had fewer places to change, as less of qemu was directly using
qapi structs for flat unions). It also allows us to turn on
automatic type-safe wrappers for upcasting to the base class
of a struct.
Changes to the generated code look like this in qapi-types.h:
| struct SpiceChannel {
|- SpiceBasicInfo *base;
|+ /* Members inherited from SpiceBasicInfo: */
|+ char *host;
|+ char *port;
|+ NetworkAddressFamily family;
|+ /* Own members: */
| int64_t connection_id;
as well as additional upcast functions like qapi_SpiceChannel_base().
Meanwhile, changes to qapi-visit.c look like:
| static void visit_type_SpiceChannel_fields(Visitor *v, SpiceChannel **obj, Error **errp)
| {
| Error *err = NULL;
|
|- visit_type_implicit_SpiceBasicInfo(v, &(*obj)->base, &err);
|+ visit_type_SpiceBasicInfo_fields(v, (SpiceBasicInfo **)obj, &err);
| if (err) {
(the cast is necessary, since our upcast wrappers only deal with a
single pointer, not pointer-to-pointer); plus the wholesale
elimination of some now-unused visit_type_implicit_FOO() functions.
Without boxing, the corner case of one empty struct having
another empty struct as its base type now requires inserting a
dummy member (previously, the 'Base *base' member sufficed).
And now that we no longer consume a 'base' member in the generated
C struct, we can delete the former negative struct-base-clash-base
test.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1445898903-12082-11-git-send-email-eblake@redhat.com>
[Commit message tweaked slightly]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-10-27 01:34:49 +03:00
|
|
|
ud2->dict1->dict2->userdef->integer = value;
|
qapi: Drop tests for inline nested structs
A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument;
but existing use of inline nested structs conflicts with that goal.
More precisely, a definition in the QAPI schema associates a name
with a set of properties:
Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } }
associates the global name 'Foo' with properties (meta-type struct)
and MEMBERS...
Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type
TYPE) and (optional false) within type Foo
The syntax of example 1 is extensible; if we need another property,
we add another name/value pair to the dictionary (such as
'base':TYPE). The syntax of example 2 is not extensible, because
the right hand side can only be a type.
We have used name encoding to add a property: "'*mumble': 'int'"
associates 'mumble' with (type int) and (optional true). Nice,
but doesn't scale. So the solution is to change our existing uses
to be syntactic sugar to an extensible form:
NAME: TYPE --> NAME: { 'type': TYPE, 'optional': false }
*ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }
This patch fixes the testsuite to avoid inline nested types, by
breaking the nesting into explicit types; it means that the type
is now boxed instead of unboxed in C code, but makes no difference
on the wire (and if desired, a later patch could change the
generator to not do so much boxing in C). When touching code to
add new allocations, also convert existing allocations to
consistently prefer typesafe g_new0 over g_malloc0 when a type
name is involved.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-05-04 18:05:30 +03:00
|
|
|
ud2->dict1->dict2->string = g_strdup(strings[2]);
|
|
|
|
|
|
|
|
ud2->dict1->dict3 = g_malloc0(sizeof(*ud2->dict1->dict3));
|
|
|
|
ud2->dict1->has_dict3 = true;
|
|
|
|
ud2->dict1->dict3->userdef = g_new0(UserDefOne, 1);
|
|
|
|
ud2->dict1->dict3->userdef->string = g_strdup(string);
|
qapi: Unbox base members
Rather than storing a base class as a pointer to a box, just
store the fields of that base class in the same order, so that
a child struct can be directly cast to its parent. This gives
less malloc overhead, less pointer dereferencing, and even less
generated code. Compare to the earlier commit 1e6c1616a "qapi:
Generate a nicer struct for flat unions" (although that patch
had fewer places to change, as less of qemu was directly using
qapi structs for flat unions). It also allows us to turn on
automatic type-safe wrappers for upcasting to the base class
of a struct.
Changes to the generated code look like this in qapi-types.h:
| struct SpiceChannel {
|- SpiceBasicInfo *base;
|+ /* Members inherited from SpiceBasicInfo: */
|+ char *host;
|+ char *port;
|+ NetworkAddressFamily family;
|+ /* Own members: */
| int64_t connection_id;
as well as additional upcast functions like qapi_SpiceChannel_base().
Meanwhile, changes to qapi-visit.c look like:
| static void visit_type_SpiceChannel_fields(Visitor *v, SpiceChannel **obj, Error **errp)
| {
| Error *err = NULL;
|
|- visit_type_implicit_SpiceBasicInfo(v, &(*obj)->base, &err);
|+ visit_type_SpiceBasicInfo_fields(v, (SpiceBasicInfo **)obj, &err);
| if (err) {
(the cast is necessary, since our upcast wrappers only deal with a
single pointer, not pointer-to-pointer); plus the wholesale
elimination of some now-unused visit_type_implicit_FOO() functions.
Without boxing, the corner case of one empty struct having
another empty struct as its base type now requires inserting a
dummy member (previously, the 'Base *base' member sufficed).
And now that we no longer consume a 'base' member in the generated
C struct, we can delete the former negative struct-base-clash-base
test.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1445898903-12082-11-git-send-email-eblake@redhat.com>
[Commit message tweaked slightly]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-10-27 01:34:49 +03:00
|
|
|
ud2->dict1->dict3->userdef->integer = value;
|
qapi: Drop tests for inline nested structs
A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument;
but existing use of inline nested structs conflicts with that goal.
More precisely, a definition in the QAPI schema associates a name
with a set of properties:
Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } }
associates the global name 'Foo' with properties (meta-type struct)
and MEMBERS...
Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type
TYPE) and (optional false) within type Foo
The syntax of example 1 is extensible; if we need another property,
we add another name/value pair to the dictionary (such as
'base':TYPE). The syntax of example 2 is not extensible, because
the right hand side can only be a type.
We have used name encoding to add a property: "'*mumble': 'int'"
associates 'mumble' with (type int) and (optional true). Nice,
but doesn't scale. So the solution is to change our existing uses
to be syntactic sugar to an extensible form:
NAME: TYPE --> NAME: { 'type': TYPE, 'optional': false }
*ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }
This patch fixes the testsuite to avoid inline nested types, by
breaking the nesting into explicit types; it means that the type
is now boxed instead of unboxed in C code, but makes no difference
on the wire (and if desired, a later patch could change the
generator to not do so much boxing in C). When touching code to
add new allocations, also convert existing allocations to
consistently prefer typesafe g_new0 over g_malloc0 when a type
name is involved.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-05-04 18:05:30 +03:00
|
|
|
ud2->dict1->dict3->string = g_strdup(strings[3]);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QDICT);
|
|
|
|
|
|
|
|
qdict = qobject_to_qdict(obj);
|
|
|
|
g_assert_cmpint(qdict_size(qdict), ==, 2);
|
|
|
|
g_assert_cmpstr(qdict_get_str(qdict, "string0"), ==, strings[0]);
|
|
|
|
|
|
|
|
dict1 = qdict_get_qdict(qdict, "dict1");
|
|
|
|
g_assert_cmpint(qdict_size(dict1), ==, 3);
|
|
|
|
g_assert_cmpstr(qdict_get_str(dict1, "string1"), ==, strings[1]);
|
|
|
|
|
|
|
|
dict2 = qdict_get_qdict(dict1, "dict2");
|
|
|
|
g_assert_cmpint(qdict_size(dict2), ==, 2);
|
2015-05-04 18:05:29 +03:00
|
|
|
g_assert_cmpstr(qdict_get_str(dict2, "string"), ==, strings[2]);
|
|
|
|
userdef = qdict_get_qdict(dict2, "userdef");
|
2011-11-15 01:05:29 +04:00
|
|
|
g_assert_cmpint(qdict_size(userdef), ==, 2);
|
|
|
|
g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value);
|
|
|
|
g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string);
|
|
|
|
|
|
|
|
dict3 = qdict_get_qdict(dict1, "dict3");
|
|
|
|
g_assert_cmpint(qdict_size(dict3), ==, 2);
|
2015-05-04 18:05:29 +03:00
|
|
|
g_assert_cmpstr(qdict_get_str(dict3, "string"), ==, strings[3]);
|
|
|
|
userdef = qdict_get_qdict(dict3, "userdef");
|
2011-11-15 01:05:29 +04:00
|
|
|
g_assert_cmpint(qdict_size(userdef), ==, 2);
|
|
|
|
g_assert_cmpint(qdict_get_int(userdef, "integer"), ==, value);
|
|
|
|
g_assert_cmpstr(qdict_get_str(userdef, "string"), ==, string);
|
|
|
|
|
|
|
|
QDECREF(qdict);
|
2015-05-04 18:05:29 +03:00
|
|
|
qapi_free_UserDefTwo(ud2);
|
2011-11-15 01:05:29 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 14:22:49 +04:00
|
|
|
static void test_visitor_out_struct_errors(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 11:52:57 +03:00
|
|
|
EnumOne bad_values[] = { ENUM_ONE__MAX, -1 };
|
qapi: Unbox base members
Rather than storing a base class as a pointer to a box, just
store the fields of that base class in the same order, so that
a child struct can be directly cast to its parent. This gives
less malloc overhead, less pointer dereferencing, and even less
generated code. Compare to the earlier commit 1e6c1616a "qapi:
Generate a nicer struct for flat unions" (although that patch
had fewer places to change, as less of qemu was directly using
qapi structs for flat unions). It also allows us to turn on
automatic type-safe wrappers for upcasting to the base class
of a struct.
Changes to the generated code look like this in qapi-types.h:
| struct SpiceChannel {
|- SpiceBasicInfo *base;
|+ /* Members inherited from SpiceBasicInfo: */
|+ char *host;
|+ char *port;
|+ NetworkAddressFamily family;
|+ /* Own members: */
| int64_t connection_id;
as well as additional upcast functions like qapi_SpiceChannel_base().
Meanwhile, changes to qapi-visit.c look like:
| static void visit_type_SpiceChannel_fields(Visitor *v, SpiceChannel **obj, Error **errp)
| {
| Error *err = NULL;
|
|- visit_type_implicit_SpiceBasicInfo(v, &(*obj)->base, &err);
|+ visit_type_SpiceBasicInfo_fields(v, (SpiceBasicInfo **)obj, &err);
| if (err) {
(the cast is necessary, since our upcast wrappers only deal with a
single pointer, not pointer-to-pointer); plus the wholesale
elimination of some now-unused visit_type_implicit_FOO() functions.
Without boxing, the corner case of one empty struct having
another empty struct as its base type now requires inserting a
dummy member (previously, the 'Base *base' member sufficed).
And now that we no longer consume a 'base' member in the generated
C struct, we can delete the former negative struct-base-clash-base
test.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1445898903-12082-11-git-send-email-eblake@redhat.com>
[Commit message tweaked slightly]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-10-27 01:34:49 +03:00
|
|
|
UserDefOne u = {0};
|
|
|
|
UserDefOne *pu = &u;
|
2014-05-02 15:26:29 +04:00
|
|
|
Error *err;
|
2012-03-20 14:22:49 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
|
2014-05-02 15:26:29 +04:00
|
|
|
err = NULL;
|
2012-03-20 14:22:49 +04:00
|
|
|
u.has_enum1 = true;
|
|
|
|
u.enum1 = bad_values[i];
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_UserDefOne(data->ov, "unused", &pu, &err);
|
2014-05-02 15:26:29 +04:00
|
|
|
g_assert(err);
|
|
|
|
error_free(err);
|
2012-03-20 14:22:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
static void test_visitor_out_list(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
2015-11-06 09:35:26 +03:00
|
|
|
const char *value_str = "list value";
|
2011-11-15 01:05:29 +04:00
|
|
|
TestStructList *p, *head = NULL;
|
|
|
|
const int max_items = 10;
|
|
|
|
bool value_bool = true;
|
|
|
|
int value_int = 10;
|
|
|
|
QListEntry *entry;
|
|
|
|
QObject *obj;
|
|
|
|
QList *qlist;
|
|
|
|
int i;
|
|
|
|
|
2015-11-06 09:35:26 +03:00
|
|
|
/* Build the list in reverse order... */
|
2011-11-15 01:05:29 +04:00
|
|
|
for (i = 0; i < max_items; i++) {
|
|
|
|
p = g_malloc0(sizeof(*p));
|
|
|
|
p->value = g_malloc0(sizeof(*p->value));
|
2015-11-06 09:35:26 +03:00
|
|
|
p->value->integer = value_int + (max_items - i - 1);
|
2011-11-15 01:05:29 +04:00
|
|
|
p->value->boolean = value_bool;
|
2015-11-06 09:35:26 +03:00
|
|
|
p->value->string = g_strdup(value_str);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
p->next = head;
|
|
|
|
head = p;
|
|
|
|
}
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_TestStructList(data->ov, NULL, &head, &error_abort);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QLIST);
|
|
|
|
|
|
|
|
qlist = qobject_to_qlist(obj);
|
|
|
|
g_assert(!qlist_empty(qlist));
|
|
|
|
|
2015-11-06 09:35:26 +03:00
|
|
|
/* ...and ensure that the visitor sees it in order */
|
2011-11-15 01:05:29 +04:00
|
|
|
i = 0;
|
|
|
|
QLIST_FOREACH_ENTRY(qlist, entry) {
|
|
|
|
QDict *qdict;
|
|
|
|
|
|
|
|
g_assert(qobject_type(entry->value) == QTYPE_QDICT);
|
|
|
|
qdict = qobject_to_qdict(entry->value);
|
|
|
|
g_assert_cmpint(qdict_size(qdict), ==, 3);
|
2015-11-06 09:35:26 +03:00
|
|
|
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, value_int + i);
|
2011-11-15 01:05:29 +04:00
|
|
|
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, value_bool);
|
|
|
|
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, value_str);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
g_assert_cmpint(i, ==, max_items);
|
|
|
|
|
|
|
|
QDECREF(qlist);
|
2015-11-06 09:35:26 +03:00
|
|
|
qapi_free_TestStructList(head);
|
2011-11-15 01:05:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
2015-05-04 18:05:29 +03:00
|
|
|
UserDefTwoList *p, *head = NULL;
|
2011-11-15 01:05:29 +04:00
|
|
|
const char string[] = "foo bar";
|
|
|
|
int i, max_count = 1024;
|
|
|
|
|
|
|
|
for (i = 0; i < max_count; i++) {
|
|
|
|
p = g_malloc0(sizeof(*p));
|
|
|
|
p->value = g_malloc0(sizeof(*p->value));
|
|
|
|
|
|
|
|
p->value->string0 = g_strdup(string);
|
qapi: Drop tests for inline nested structs
A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument;
but existing use of inline nested structs conflicts with that goal.
More precisely, a definition in the QAPI schema associates a name
with a set of properties:
Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } }
associates the global name 'Foo' with properties (meta-type struct)
and MEMBERS...
Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type
TYPE) and (optional false) within type Foo
The syntax of example 1 is extensible; if we need another property,
we add another name/value pair to the dictionary (such as
'base':TYPE). The syntax of example 2 is not extensible, because
the right hand side can only be a type.
We have used name encoding to add a property: "'*mumble': 'int'"
associates 'mumble' with (type int) and (optional true). Nice,
but doesn't scale. So the solution is to change our existing uses
to be syntactic sugar to an extensible form:
NAME: TYPE --> NAME: { 'type': TYPE, 'optional': false }
*ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }
This patch fixes the testsuite to avoid inline nested types, by
breaking the nesting into explicit types; it means that the type
is now boxed instead of unboxed in C code, but makes no difference
on the wire (and if desired, a later patch could change the
generator to not do so much boxing in C). When touching code to
add new allocations, also convert existing allocations to
consistently prefer typesafe g_new0 over g_malloc0 when a type
name is involved.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-05-04 18:05:30 +03:00
|
|
|
p->value->dict1 = g_new0(UserDefTwoDict, 1);
|
|
|
|
p->value->dict1->string1 = g_strdup(string);
|
|
|
|
p->value->dict1->dict2 = g_new0(UserDefTwoDictDict, 1);
|
|
|
|
p->value->dict1->dict2->userdef = g_new0(UserDefOne, 1);
|
|
|
|
p->value->dict1->dict2->userdef->string = g_strdup(string);
|
qapi: Unbox base members
Rather than storing a base class as a pointer to a box, just
store the fields of that base class in the same order, so that
a child struct can be directly cast to its parent. This gives
less malloc overhead, less pointer dereferencing, and even less
generated code. Compare to the earlier commit 1e6c1616a "qapi:
Generate a nicer struct for flat unions" (although that patch
had fewer places to change, as less of qemu was directly using
qapi structs for flat unions). It also allows us to turn on
automatic type-safe wrappers for upcasting to the base class
of a struct.
Changes to the generated code look like this in qapi-types.h:
| struct SpiceChannel {
|- SpiceBasicInfo *base;
|+ /* Members inherited from SpiceBasicInfo: */
|+ char *host;
|+ char *port;
|+ NetworkAddressFamily family;
|+ /* Own members: */
| int64_t connection_id;
as well as additional upcast functions like qapi_SpiceChannel_base().
Meanwhile, changes to qapi-visit.c look like:
| static void visit_type_SpiceChannel_fields(Visitor *v, SpiceChannel **obj, Error **errp)
| {
| Error *err = NULL;
|
|- visit_type_implicit_SpiceBasicInfo(v, &(*obj)->base, &err);
|+ visit_type_SpiceBasicInfo_fields(v, (SpiceBasicInfo **)obj, &err);
| if (err) {
(the cast is necessary, since our upcast wrappers only deal with a
single pointer, not pointer-to-pointer); plus the wholesale
elimination of some now-unused visit_type_implicit_FOO() functions.
Without boxing, the corner case of one empty struct having
another empty struct as its base type now requires inserting a
dummy member (previously, the 'Base *base' member sufficed).
And now that we no longer consume a 'base' member in the generated
C struct, we can delete the former negative struct-base-clash-base
test.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1445898903-12082-11-git-send-email-eblake@redhat.com>
[Commit message tweaked slightly]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-10-27 01:34:49 +03:00
|
|
|
p->value->dict1->dict2->userdef->integer = 42;
|
qapi: Drop tests for inline nested structs
A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument;
but existing use of inline nested structs conflicts with that goal.
More precisely, a definition in the QAPI schema associates a name
with a set of properties:
Example 1: { 'struct': 'Foo', 'data': { MEMBERS... } }
associates the global name 'Foo' with properties (meta-type struct)
and MEMBERS...
Example 2: 'mumble': TYPE
within MEMBERS... above associates 'mumble' with properties (type
TYPE) and (optional false) within type Foo
The syntax of example 1 is extensible; if we need another property,
we add another name/value pair to the dictionary (such as
'base':TYPE). The syntax of example 2 is not extensible, because
the right hand side can only be a type.
We have used name encoding to add a property: "'*mumble': 'int'"
associates 'mumble' with (type int) and (optional true). Nice,
but doesn't scale. So the solution is to change our existing uses
to be syntactic sugar to an extensible form:
NAME: TYPE --> NAME: { 'type': TYPE, 'optional': false }
*ONAME: TYPE --> ONAME: { 'type': TYPE, 'optional': true }
This patch fixes the testsuite to avoid inline nested types, by
breaking the nesting into explicit types; it means that the type
is now boxed instead of unboxed in C code, but makes no difference
on the wire (and if desired, a later patch could change the
generator to not do so much boxing in C). When touching code to
add new allocations, also convert existing allocations to
consistently prefer typesafe g_new0 over g_malloc0 when a type
name is involved.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-05-04 18:05:30 +03:00
|
|
|
p->value->dict1->dict2->string = g_strdup(string);
|
|
|
|
p->value->dict1->has_dict3 = false;
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
p->next = head;
|
|
|
|
head = p;
|
|
|
|
}
|
|
|
|
|
2015-05-04 18:05:29 +03:00
|
|
|
qapi_free_UserDefTwoList(head);
|
2011-11-15 01:05:29 +04:00
|
|
|
}
|
|
|
|
|
2015-09-16 14:06:24 +03:00
|
|
|
static void test_visitor_out_any(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
QObject *qobj;
|
|
|
|
QInt *qint;
|
|
|
|
QBool *qbool;
|
|
|
|
QString *qstring;
|
|
|
|
QDict *qdict;
|
|
|
|
QObject *obj;
|
|
|
|
|
|
|
|
qobj = QOBJECT(qint_from_int(-42));
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_any(data->ov, NULL, &qobj, &error_abort);
|
2015-09-16 14:06:24 +03:00
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
g_assert(qobject_type(obj) == QTYPE_QINT);
|
|
|
|
g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, -42);
|
|
|
|
qobject_decref(obj);
|
|
|
|
qobject_decref(qobj);
|
|
|
|
|
|
|
|
qdict = qdict_new();
|
|
|
|
qdict_put(qdict, "integer", qint_from_int(-42));
|
|
|
|
qdict_put(qdict, "boolean", qbool_from_bool(true));
|
|
|
|
qdict_put(qdict, "string", qstring_from_str("foo"));
|
|
|
|
qobj = QOBJECT(qdict);
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_any(data->ov, NULL, &qobj, &error_abort);
|
2015-11-06 09:35:29 +03:00
|
|
|
qobject_decref(qobj);
|
2015-09-16 14:06:24 +03:00
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
|
|
|
g_assert(obj != NULL);
|
|
|
|
qdict = qobject_to_qdict(obj);
|
|
|
|
g_assert(qdict);
|
|
|
|
qobj = qdict_get(qdict, "integer");
|
|
|
|
g_assert(qobj);
|
|
|
|
qint = qobject_to_qint(qobj);
|
|
|
|
g_assert(qint);
|
|
|
|
g_assert_cmpint(qint_get_int(qint), ==, -42);
|
|
|
|
qobj = qdict_get(qdict, "boolean");
|
|
|
|
g_assert(qobj);
|
|
|
|
qbool = qobject_to_qbool(qobj);
|
|
|
|
g_assert(qbool);
|
|
|
|
g_assert(qbool_get_bool(qbool) == true);
|
|
|
|
qobj = qdict_get(qdict, "string");
|
|
|
|
g_assert(qobj);
|
|
|
|
qstring = qobject_to_qstring(qobj);
|
|
|
|
g_assert(qstring);
|
|
|
|
g_assert_cmpstr(qstring_get_str(qstring), ==, "foo");
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
|
2014-03-01 11:40:33 +04:00
|
|
|
static void test_visitor_out_union_flat(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
QObject *arg;
|
|
|
|
QDict *qdict;
|
|
|
|
|
|
|
|
UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion));
|
2015-07-31 11:30:04 +03:00
|
|
|
tmp->enum1 = ENUM_ONE_VALUE1;
|
2014-03-05 06:44:39 +04:00
|
|
|
tmp->string = g_strdup("str");
|
2015-10-27 01:34:53 +03:00
|
|
|
tmp->u.value1 = g_malloc0(sizeof(UserDefA));
|
|
|
|
tmp->integer = 41;
|
|
|
|
tmp->u.value1->boolean = true;
|
2014-03-01 11:40:33 +04:00
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort);
|
2014-03-01 11:40:33 +04:00
|
|
|
arg = qmp_output_get_qobject(data->qov);
|
|
|
|
|
|
|
|
g_assert(qobject_type(arg) == QTYPE_QDICT);
|
|
|
|
qdict = qobject_to_qdict(arg);
|
|
|
|
|
2014-03-05 06:44:39 +04:00
|
|
|
g_assert_cmpstr(qdict_get_str(qdict, "enum1"), ==, "value1");
|
|
|
|
g_assert_cmpstr(qdict_get_str(qdict, "string"), ==, "str");
|
2015-10-27 01:34:53 +03:00
|
|
|
g_assert_cmpint(qdict_get_int(qdict, "integer"), ==, 41);
|
2014-03-01 11:40:33 +04:00
|
|
|
g_assert_cmpint(qdict_get_bool(qdict, "boolean"), ==, true);
|
|
|
|
|
|
|
|
qapi_free_UserDefFlatUnion(tmp);
|
|
|
|
QDECREF(qdict);
|
|
|
|
}
|
|
|
|
|
2015-05-04 18:05:11 +03:00
|
|
|
static void test_visitor_out_alternate(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
2014-03-01 11:40:30 +04:00
|
|
|
{
|
|
|
|
QObject *arg;
|
2015-11-06 09:35:32 +03:00
|
|
|
UserDefAlternate *tmp;
|
2014-03-01 11:40:30 +04:00
|
|
|
|
2015-11-06 09:35:32 +03:00
|
|
|
tmp = g_new0(UserDefAlternate, 1);
|
qapi: Simplify visiting of alternate types
Previously, working with alternates required two lookup arrays
and some indirection: for type Foo, we created Foo_qtypes[]
which maps each qtype to a value of the generated FooKind enum,
then look up that value in FooKind_lookup[] like we do for other
union types.
This has a couple of subtle bugs. First, the generator was
creating a call with a parameter '(int *) &(*obj)->type' where
type is an enum type; this is unsafe if the compiler chooses
to store the enum type in a different size than int, where
assigning through the wrong size pointer can corrupt data or
cause a SIGBUS.
Related bug, not not fixed in this patch: qapi-visit.py's
gen_visit_enum() generates a cast of its enum * argument to
int *. Marked FIXME.
Second, since the values of the FooKind enum start at zero, all
entries of the Foo_qtypes[] array that were not explicitly
initialized will map to the same branch of the union as the
first member of the alternate, rather than triggering a desired
failure in visit_get_next_type(). Fortunately, the bug seldom
bites; the very next thing the input visitor does is try to
parse the incoming JSON with the wrong parser, which normally
fails; the output visitor is not used with a C struct in that
state, and the dealloc visitor has nothing to clean up (so
there is no leak).
However, the second bug IS observable in one case: parsing an
integer causes unusual behavior in an alternate that contains
at least a 'number' member but no 'int' member, because the
'number' parser accepts QTYPE_QINT in addition to the expected
QTYPE_QFLOAT (that is, since 'int' is not a member, the type
QTYPE_QINT accidentally maps to FooKind 0; if this enum value
is the 'number' branch the integer parses successfully, but if
the 'number' branch is not first, some other branch tries to
parse the integer and rejects it). A later patch will worry
about fixing alternates to always parse all inputs that a
non-alternate 'number' would accept, for now this is still
marked FIXME in the updated test-qmp-input-visitor.c, to
merely point out that new undesired behavior of 'ans' matches
the existing undesired behavior of 'asn'.
This patch fixes the default-initialization bug by deleting the
indirection, and modifying get_next_type() to directly assign a
QTypeCode parameter. This in turn fixes the type-casting bug,
as we are no longer casting a pointer to enum to a questionable
size. There is no longer a need to generate an implicit FooKind
enum associated with the alternate type (since the QMP wire
format never uses the stringized counterparts of the C union
member names). Since the updated visit_get_next_type() does not
know which qtypes are expected, the generated visitor is
modified to generate an error statement if an unexpected type is
encountered.
Callers now have to know the QTYPE_* mapping when looking at the
discriminator; but so far, only the testsuite was even using the
C struct of an alternate types. I considered the possibility of
keeping the internal enum FooKind, but initialized differently
than most generated arrays, as in:
typedef enum FooKind {
FOO_KIND_A = QTYPE_QDICT,
FOO_KIND_B = QTYPE_QINT,
} FooKind;
to create nicer aliases for knowing when to use foo->a or foo->b
when inspecting foo->type; but it turned out to add too much
complexity, especially without a client.
There is a user-visible side effect to this change, but I
consider it to be an improvement. Previously,
the invalid QMP command:
{"execute":"blockdev-add", "arguments":{"options":
{"driver":"raw", "id":"a", "file":true}}}
failed with:
{"error": {"class": "GenericError",
"desc": "Invalid parameter type for 'file', expected: QDict"}}
(visit_get_next_type() succeeded, and the error comes from the
visit_type_BlockdevOptions() expecting {}; there is no mention of
the fact that a string would also work). Now it fails with:
{"error": {"class": "GenericError",
"desc": "Invalid parameter type for 'file', expected: BlockdevRef"}}
(the error when the next type doesn't match any expected types for
the overall alternate).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1449033659-25497-5-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-12-02 08:20:48 +03:00
|
|
|
tmp->type = QTYPE_QINT;
|
2015-10-27 01:34:53 +03:00
|
|
|
tmp->u.i = 42;
|
2014-03-01 11:40:30 +04:00
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
|
2014-03-01 11:40:30 +04:00
|
|
|
arg = qmp_output_get_qobject(data->qov);
|
|
|
|
|
|
|
|
g_assert(qobject_type(arg) == QTYPE_QINT);
|
|
|
|
g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), ==, 42);
|
|
|
|
|
2015-05-04 18:05:11 +03:00
|
|
|
qapi_free_UserDefAlternate(tmp);
|
2015-11-06 09:35:29 +03:00
|
|
|
qobject_decref(arg);
|
2015-11-06 09:35:32 +03:00
|
|
|
|
|
|
|
tmp = g_new0(UserDefAlternate, 1);
|
qapi: Simplify visiting of alternate types
Previously, working with alternates required two lookup arrays
and some indirection: for type Foo, we created Foo_qtypes[]
which maps each qtype to a value of the generated FooKind enum,
then look up that value in FooKind_lookup[] like we do for other
union types.
This has a couple of subtle bugs. First, the generator was
creating a call with a parameter '(int *) &(*obj)->type' where
type is an enum type; this is unsafe if the compiler chooses
to store the enum type in a different size than int, where
assigning through the wrong size pointer can corrupt data or
cause a SIGBUS.
Related bug, not not fixed in this patch: qapi-visit.py's
gen_visit_enum() generates a cast of its enum * argument to
int *. Marked FIXME.
Second, since the values of the FooKind enum start at zero, all
entries of the Foo_qtypes[] array that were not explicitly
initialized will map to the same branch of the union as the
first member of the alternate, rather than triggering a desired
failure in visit_get_next_type(). Fortunately, the bug seldom
bites; the very next thing the input visitor does is try to
parse the incoming JSON with the wrong parser, which normally
fails; the output visitor is not used with a C struct in that
state, and the dealloc visitor has nothing to clean up (so
there is no leak).
However, the second bug IS observable in one case: parsing an
integer causes unusual behavior in an alternate that contains
at least a 'number' member but no 'int' member, because the
'number' parser accepts QTYPE_QINT in addition to the expected
QTYPE_QFLOAT (that is, since 'int' is not a member, the type
QTYPE_QINT accidentally maps to FooKind 0; if this enum value
is the 'number' branch the integer parses successfully, but if
the 'number' branch is not first, some other branch tries to
parse the integer and rejects it). A later patch will worry
about fixing alternates to always parse all inputs that a
non-alternate 'number' would accept, for now this is still
marked FIXME in the updated test-qmp-input-visitor.c, to
merely point out that new undesired behavior of 'ans' matches
the existing undesired behavior of 'asn'.
This patch fixes the default-initialization bug by deleting the
indirection, and modifying get_next_type() to directly assign a
QTypeCode parameter. This in turn fixes the type-casting bug,
as we are no longer casting a pointer to enum to a questionable
size. There is no longer a need to generate an implicit FooKind
enum associated with the alternate type (since the QMP wire
format never uses the stringized counterparts of the C union
member names). Since the updated visit_get_next_type() does not
know which qtypes are expected, the generated visitor is
modified to generate an error statement if an unexpected type is
encountered.
Callers now have to know the QTYPE_* mapping when looking at the
discriminator; but so far, only the testsuite was even using the
C struct of an alternate types. I considered the possibility of
keeping the internal enum FooKind, but initialized differently
than most generated arrays, as in:
typedef enum FooKind {
FOO_KIND_A = QTYPE_QDICT,
FOO_KIND_B = QTYPE_QINT,
} FooKind;
to create nicer aliases for knowing when to use foo->a or foo->b
when inspecting foo->type; but it turned out to add too much
complexity, especially without a client.
There is a user-visible side effect to this change, but I
consider it to be an improvement. Previously,
the invalid QMP command:
{"execute":"blockdev-add", "arguments":{"options":
{"driver":"raw", "id":"a", "file":true}}}
failed with:
{"error": {"class": "GenericError",
"desc": "Invalid parameter type for 'file', expected: QDict"}}
(visit_get_next_type() succeeded, and the error comes from the
visit_type_BlockdevOptions() expecting {}; there is no mention of
the fact that a string would also work). Now it fails with:
{"error": {"class": "GenericError",
"desc": "Invalid parameter type for 'file', expected: BlockdevRef"}}
(the error when the next type doesn't match any expected types for
the overall alternate).
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1449033659-25497-5-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-12-02 08:20:48 +03:00
|
|
|
tmp->type = QTYPE_QSTRING;
|
2015-11-06 09:35:32 +03:00
|
|
|
tmp->u.s = g_strdup("hello");
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort);
|
2015-11-06 09:35:32 +03:00
|
|
|
arg = qmp_output_get_qobject(data->qov);
|
|
|
|
|
|
|
|
g_assert(qobject_type(arg) == QTYPE_QSTRING);
|
|
|
|
g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), ==, "hello");
|
|
|
|
|
|
|
|
qapi_free_UserDefAlternate(tmp);
|
|
|
|
qobject_decref(arg);
|
2014-03-01 11:40:30 +04:00
|
|
|
}
|
|
|
|
|
2014-05-26 16:40:56 +04:00
|
|
|
static void test_visitor_out_empty(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
QObject *arg;
|
|
|
|
|
|
|
|
arg = qmp_output_get_qobject(data->qov);
|
qapi: Make output visitor return qnull() instead of NULL
Before commit 1d10b44, it crashed. Since then, it returns NULL, with
a FIXME comment. The FIXME is valid: code that assumes QObject *
can't be null exists. I'm not aware of a way to feed this problematic
return value to code that actually chokes on null in the current code,
but the next few commits will create one, failing "make check".
Commit 481b002 solved a very similar problem by introducing a special
null QObject. Using this special null QObject is clearly the right
way to resolve this FIXME, so do that, and update the test
accordingly.
However, the patch isn't quite right: it messes up the reference
counting. After about SIZE_MAX visits, the reference counter
overflows, failing the assertion in qnull_destroy_obj(). Because
that's many orders of magnitude more visits of nulls than we expect,
we take this patch despite its flaws, to get the QMP introspection
stuff in without further delay. We'll want to fix it for real before
the release.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1442401589-24189-21-git-send-email-armbru@redhat.com>
2015-09-16 14:06:23 +03:00
|
|
|
g_assert(qobject_type(arg) == QTYPE_QNULL);
|
2016-01-29 16:49:00 +03:00
|
|
|
/* Check that qnull reference counting is sane */
|
|
|
|
g_assert(arg->refcnt == 2);
|
qapi: Make output visitor return qnull() instead of NULL
Before commit 1d10b44, it crashed. Since then, it returns NULL, with
a FIXME comment. The FIXME is valid: code that assumes QObject *
can't be null exists. I'm not aware of a way to feed this problematic
return value to code that actually chokes on null in the current code,
but the next few commits will create one, failing "make check".
Commit 481b002 solved a very similar problem by introducing a special
null QObject. Using this special null QObject is clearly the right
way to resolve this FIXME, so do that, and update the test
accordingly.
However, the patch isn't quite right: it messes up the reference
counting. After about SIZE_MAX visits, the reference counter
overflows, failing the assertion in qnull_destroy_obj(). Because
that's many orders of magnitude more visits of nulls than we expect,
we take this patch despite its flaws, to get the QMP introspection
stuff in without further delay. We'll want to fix it for real before
the release.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1442401589-24189-21-git-send-email-armbru@redhat.com>
2015-09-16 14:06:23 +03:00
|
|
|
qobject_decref(arg);
|
2014-05-26 16:40:56 +04:00
|
|
|
}
|
|
|
|
|
2013-05-11 02:46:09 +04:00
|
|
|
static void init_native_list(UserDefNativeListUnion *cvalue)
|
|
|
|
{
|
|
|
|
int i;
|
2015-10-27 01:34:53 +03:00
|
|
|
switch (cvalue->type) {
|
2013-05-11 02:46:09 +04:00
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: {
|
2015-10-27 01:34:53 +03:00
|
|
|
intList **list = &cvalue->u.integer;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(intList, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S8: {
|
2015-10-27 01:34:53 +03:00
|
|
|
int8List **list = &cvalue->u.s8;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(int8List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S16: {
|
2015-10-27 01:34:53 +03:00
|
|
|
int16List **list = &cvalue->u.s16;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(int16List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S32: {
|
2015-10-27 01:34:53 +03:00
|
|
|
int32List **list = &cvalue->u.s32;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(int32List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S64: {
|
2015-10-27 01:34:53 +03:00
|
|
|
int64List **list = &cvalue->u.s64;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(int64List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U8: {
|
2015-10-27 01:34:53 +03:00
|
|
|
uint8List **list = &cvalue->u.u8;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(uint8List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U16: {
|
2015-10-27 01:34:53 +03:00
|
|
|
uint16List **list = &cvalue->u.u16;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(uint16List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U32: {
|
2015-10-27 01:34:53 +03:00
|
|
|
uint32List **list = &cvalue->u.u32;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(uint32List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U64: {
|
2015-10-27 01:34:53 +03:00
|
|
|
uint64List **list = &cvalue->u.u64;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(uint64List, 1);
|
|
|
|
(*list)->value = i;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN: {
|
2015-10-27 01:34:53 +03:00
|
|
|
boolList **list = &cvalue->u.boolean;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(boolList, 1);
|
|
|
|
(*list)->value = (i % 3 == 0);
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_STRING: {
|
2015-10-27 01:34:53 +03:00
|
|
|
strList **list = &cvalue->u.string;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(strList, 1);
|
|
|
|
(*list)->value = g_strdup_printf("%d", i);
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER: {
|
2015-10-27 01:34:53 +03:00
|
|
|
numberList **list = &cvalue->u.number;
|
2013-05-11 02:46:09 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
*list = g_new0(numberList, 1);
|
|
|
|
(*list)->value = (double)i / 3;
|
|
|
|
(*list)->next = NULL;
|
|
|
|
list = &(*list)->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2013-07-25 20:21:28 +04:00
|
|
|
g_assert_not_reached();
|
2013-05-11 02:46:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_native_list(QObject *qobj,
|
|
|
|
UserDefNativeListUnionKind kind)
|
|
|
|
{
|
|
|
|
QDict *qdict;
|
|
|
|
QList *qlist;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_assert(qobj);
|
|
|
|
g_assert(qobject_type(qobj) == QTYPE_QDICT);
|
|
|
|
qdict = qobject_to_qdict(qobj);
|
|
|
|
g_assert(qdict);
|
|
|
|
g_assert(qdict_haskey(qdict, "data"));
|
|
|
|
qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data")));
|
|
|
|
|
|
|
|
switch (kind) {
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S8:
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S16:
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S32:
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_S64:
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U8:
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U16:
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U32:
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_U64:
|
|
|
|
/* all integer elements in JSON arrays get stored into QInts when
|
|
|
|
* we convert to QObjects, so we can check them all in the same
|
|
|
|
* fashion, so simply fall through here
|
|
|
|
*/
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER:
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
QObject *tmp;
|
|
|
|
QInt *qvalue;
|
|
|
|
tmp = qlist_peek(qlist);
|
|
|
|
g_assert(tmp);
|
|
|
|
qvalue = qobject_to_qint(tmp);
|
|
|
|
g_assert_cmpint(qint_get_int(qvalue), ==, i);
|
|
|
|
qobject_decref(qlist_pop(qlist));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN:
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
QObject *tmp;
|
|
|
|
QBool *qvalue;
|
|
|
|
tmp = qlist_peek(qlist);
|
|
|
|
g_assert(tmp);
|
|
|
|
qvalue = qobject_to_qbool(tmp);
|
2015-05-16 01:24:59 +03:00
|
|
|
g_assert_cmpint(qbool_get_bool(qvalue), ==, i % 3 == 0);
|
2013-05-11 02:46:09 +04:00
|
|
|
qobject_decref(qlist_pop(qlist));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_STRING:
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
QObject *tmp;
|
|
|
|
QString *qvalue;
|
|
|
|
gchar str[8];
|
|
|
|
tmp = qlist_peek(qlist);
|
|
|
|
g_assert(tmp);
|
|
|
|
qvalue = qobject_to_qstring(tmp);
|
|
|
|
sprintf(str, "%d", i);
|
|
|
|
g_assert_cmpstr(qstring_get_str(qvalue), ==, str);
|
|
|
|
qobject_decref(qlist_pop(qlist));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER:
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
QObject *tmp;
|
|
|
|
QFloat *qvalue;
|
|
|
|
GString *double_expected = g_string_new("");
|
|
|
|
GString *double_actual = g_string_new("");
|
|
|
|
|
|
|
|
tmp = qlist_peek(qlist);
|
|
|
|
g_assert(tmp);
|
|
|
|
qvalue = qobject_to_qfloat(tmp);
|
|
|
|
g_string_printf(double_expected, "%.6f", (double)i / 3);
|
|
|
|
g_string_printf(double_actual, "%.6f", qfloat_get_double(qvalue));
|
|
|
|
g_assert_cmpstr(double_actual->str, ==, double_expected->str);
|
|
|
|
|
|
|
|
qobject_decref(qlist_pop(qlist));
|
|
|
|
g_string_free(double_expected, true);
|
|
|
|
g_string_free(double_actual, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2013-07-25 20:21:28 +04:00
|
|
|
g_assert_not_reached();
|
2013-05-11 02:46:09 +04:00
|
|
|
}
|
|
|
|
QDECREF(qlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_native_list(TestOutputVisitorData *data,
|
|
|
|
const void *unused,
|
|
|
|
UserDefNativeListUnionKind kind)
|
|
|
|
{
|
|
|
|
UserDefNativeListUnion *cvalue = g_new0(UserDefNativeListUnion, 1);
|
|
|
|
QObject *obj;
|
|
|
|
|
2015-10-27 01:34:53 +03:00
|
|
|
cvalue->type = kind;
|
2013-05-11 02:46:09 +04:00
|
|
|
init_native_list(cvalue);
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 16:48:54 +03:00
|
|
|
visit_type_UserDefNativeListUnion(data->ov, NULL, &cvalue, &error_abort);
|
2013-05-11 02:46:09 +04:00
|
|
|
|
|
|
|
obj = qmp_output_get_qobject(data->qov);
|
2015-10-27 01:34:53 +03:00
|
|
|
check_native_list(obj, cvalue->type);
|
2013-05-11 02:46:09 +04:00
|
|
|
qapi_free_UserDefNativeListUnion(cvalue);
|
|
|
|
qobject_decref(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_int(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_int8(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_int16(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_int32(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S32);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_int64(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S64);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_uint8(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_uint16(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_uint32(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U32);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_uint64(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U64);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_bool(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_str(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_visitor_out_native_list_number(TestOutputVisitorData *data,
|
|
|
|
const void *unused)
|
|
|
|
{
|
|
|
|
test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER);
|
|
|
|
}
|
|
|
|
|
2011-11-15 01:05:29 +04:00
|
|
|
static void output_visitor_test_add(const char *testpath,
|
|
|
|
TestOutputVisitorData *data,
|
|
|
|
void (*test_func)(TestOutputVisitorData *data, const void *user_data))
|
|
|
|
{
|
|
|
|
g_test_add(testpath, TestOutputVisitorData, data, visitor_output_setup,
|
|
|
|
test_func, visitor_output_teardown);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
TestOutputVisitorData out_visitor_data;
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
output_visitor_test_add("/visitor/output/int",
|
|
|
|
&out_visitor_data, test_visitor_out_int);
|
|
|
|
output_visitor_test_add("/visitor/output/bool",
|
|
|
|
&out_visitor_data, test_visitor_out_bool);
|
|
|
|
output_visitor_test_add("/visitor/output/number",
|
|
|
|
&out_visitor_data, test_visitor_out_number);
|
|
|
|
output_visitor_test_add("/visitor/output/string",
|
|
|
|
&out_visitor_data, test_visitor_out_string);
|
|
|
|
output_visitor_test_add("/visitor/output/no-string",
|
|
|
|
&out_visitor_data, test_visitor_out_no_string);
|
|
|
|
output_visitor_test_add("/visitor/output/enum",
|
|
|
|
&out_visitor_data, test_visitor_out_enum);
|
|
|
|
output_visitor_test_add("/visitor/output/enum-errors",
|
|
|
|
&out_visitor_data, test_visitor_out_enum_errors);
|
|
|
|
output_visitor_test_add("/visitor/output/struct",
|
|
|
|
&out_visitor_data, test_visitor_out_struct);
|
|
|
|
output_visitor_test_add("/visitor/output/struct-nested",
|
|
|
|
&out_visitor_data, test_visitor_out_struct_nested);
|
2012-03-20 14:22:49 +04:00
|
|
|
output_visitor_test_add("/visitor/output/struct-errors",
|
|
|
|
&out_visitor_data, test_visitor_out_struct_errors);
|
2011-11-15 01:05:29 +04:00
|
|
|
output_visitor_test_add("/visitor/output/list",
|
|
|
|
&out_visitor_data, test_visitor_out_list);
|
2015-09-16 14:06:24 +03:00
|
|
|
output_visitor_test_add("/visitor/output/any",
|
|
|
|
&out_visitor_data, test_visitor_out_any);
|
2011-11-15 01:05:29 +04:00
|
|
|
output_visitor_test_add("/visitor/output/list-qapi-free",
|
|
|
|
&out_visitor_data, test_visitor_out_list_qapi_free);
|
2014-03-01 11:40:33 +04:00
|
|
|
output_visitor_test_add("/visitor/output/union-flat",
|
|
|
|
&out_visitor_data, test_visitor_out_union_flat);
|
2015-05-04 18:05:11 +03:00
|
|
|
output_visitor_test_add("/visitor/output/alternate",
|
|
|
|
&out_visitor_data, test_visitor_out_alternate);
|
2014-05-26 16:40:56 +04:00
|
|
|
output_visitor_test_add("/visitor/output/empty",
|
|
|
|
&out_visitor_data, test_visitor_out_empty);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/int",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_int);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/int8",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_int8);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/int16",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_int16);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/int32",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_int32);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/int64",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_int64);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/uint8",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_uint8);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/uint16",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_uint16);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/uint32",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_uint32);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/uint64",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_uint64);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/bool",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_bool);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/string",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_str);
|
2013-05-11 02:46:09 +04:00
|
|
|
output_visitor_test_add("/visitor/output/native_list/number",
|
2015-05-04 18:05:06 +03:00
|
|
|
&out_visitor_data,
|
|
|
|
test_visitor_out_native_list_number);
|
2011-11-15 01:05:29 +04:00
|
|
|
|
|
|
|
g_test_run();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|