aboutsummaryrefslogtreecommitdiff
path: root/qapi/qapi-visit-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'qapi/qapi-visit-core.c')
-rw-r--r--qapi/qapi-visit-core.c165
1 files changed, 88 insertions, 77 deletions
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 74aa9c04bd..5a9c47aabf 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -36,7 +36,7 @@ void visit_free(Visitor *v)
}
}
-void visit_start_struct(Visitor *v, const char *name, void **obj,
+bool visit_start_struct(Visitor *v, const char *name, void **obj,
size_t size, Error **errp)
{
Error *err = NULL;
@@ -51,14 +51,13 @@ void visit_start_struct(Visitor *v, const char *name, void **obj,
assert(!err != !*obj);
}
error_propagate(errp, err);
+ return !err;
}
-void visit_check_struct(Visitor *v, Error **errp)
+bool visit_check_struct(Visitor *v, Error **errp)
{
trace_visit_check_struct(v);
- if (v->check_struct) {
- v->check_struct(v, errp);
- }
+ return v->check_struct ? v->check_struct(v, errp) : true;
}
void visit_end_struct(Visitor *v, void **obj)
@@ -67,7 +66,7 @@ void visit_end_struct(Visitor *v, void **obj)
v->end_struct(v, obj);
}
-void visit_start_list(Visitor *v, const char *name, GenericList **list,
+bool visit_start_list(Visitor *v, const char *name, GenericList **list,
size_t size, Error **errp)
{
Error *err = NULL;
@@ -79,6 +78,7 @@ void visit_start_list(Visitor *v, const char *name, GenericList **list,
assert(!(err && *list));
}
error_propagate(errp, err);
+ return !err;
}
GenericList *visit_next_list(Visitor *v, GenericList *tail, size_t size)
@@ -88,12 +88,10 @@ GenericList *visit_next_list(Visitor *v, GenericList *tail, size_t size)
return v->next_list(v, tail, size);
}
-void visit_check_list(Visitor *v, Error **errp)
+bool visit_check_list(Visitor *v, Error **errp)
{
trace_visit_check_list(v);
- if (v->check_list) {
- v->check_list(v, errp);
- }
+ return v->check_list ? v->check_list(v, errp) : true;
}
void visit_end_list(Visitor *v, void **obj)
@@ -102,7 +100,7 @@ void visit_end_list(Visitor *v, void **obj)
v->end_list(v, obj);
}
-void visit_start_alternate(Visitor *v, const char *name,
+bool visit_start_alternate(Visitor *v, const char *name,
GenericAlternate **obj, size_t size,
Error **errp)
{
@@ -118,6 +116,7 @@ void visit_start_alternate(Visitor *v, const char *name,
assert(v->start_alternate && !err != !*obj);
}
error_propagate(errp, err);
+ return !err;
}
void visit_end_alternate(Visitor *v, void **obj)
@@ -147,155 +146,168 @@ bool visit_is_dealloc(Visitor *v)
return v->type == VISITOR_DEALLOC;
}
-void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp)
+bool visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp)
{
assert(obj);
trace_visit_type_int(v, name, obj);
- v->type_int64(v, name, obj, errp);
+ return v->type_int64(v, name, obj, errp);
}
-static void visit_type_uintN(Visitor *v, uint64_t *obj, const char *name,
+static bool visit_type_uintN(Visitor *v, uint64_t *obj, const char *name,
uint64_t max, const char *type, Error **errp)
{
- Error *err = NULL;
uint64_t value = *obj;
assert(v->type == VISITOR_INPUT || value <= max);
- v->type_uint64(v, name, &value, &err);
- if (err) {
- error_propagate(errp, err);
- } else if (value > max) {
+ if (!v->type_uint64(v, name, &value, errp)) {
+ return false;
+ }
+ if (value > max) {
assert(v->type == VISITOR_INPUT);
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
name ? name : "null", type);
- } else {
- *obj = value;
+ return false;
}
+ *obj = value;
+ return true;
}
-void visit_type_uint8(Visitor *v, const char *name, uint8_t *obj,
+bool visit_type_uint8(Visitor *v, const char *name, uint8_t *obj,
Error **errp)
{
uint64_t value;
+ bool ok;
trace_visit_type_uint8(v, name, obj);
value = *obj;
- visit_type_uintN(v, &value, name, UINT8_MAX, "uint8_t", errp);
+ ok = visit_type_uintN(v, &value, name, UINT8_MAX, "uint8_t", errp);
*obj = value;
+ return ok;
}
-void visit_type_uint16(Visitor *v, const char *name, uint16_t *obj,
+bool visit_type_uint16(Visitor *v, const char *name, uint16_t *obj,
Error **errp)
{
uint64_t value;
+ bool ok;
trace_visit_type_uint16(v, name, obj);
value = *obj;
- visit_type_uintN(v, &value, name, UINT16_MAX, "uint16_t", errp);
+ ok = visit_type_uintN(v, &value, name, UINT16_MAX, "uint16_t", errp);
*obj = value;
+ return ok;
}
-void visit_type_uint32(Visitor *v, const char *name, uint32_t *obj,
+bool visit_type_uint32(Visitor *v, const char *name, uint32_t *obj,
Error **errp)
{
uint64_t value;
+ bool ok;
trace_visit_type_uint32(v, name, obj);
value = *obj;
- visit_type_uintN(v, &value, name, UINT32_MAX, "uint32_t", errp);
+ ok = visit_type_uintN(v, &value, name, UINT32_MAX, "uint32_t", errp);
*obj = value;
+ return ok;
}
-void visit_type_uint64(Visitor *v, const char *name, uint64_t *obj,
+bool visit_type_uint64(Visitor *v, const char *name, uint64_t *obj,
Error **errp)
{
assert(obj);
trace_visit_type_uint64(v, name, obj);
- v->type_uint64(v, name, obj, errp);
+ return v->type_uint64(v, name, obj, errp);
}
-static void visit_type_intN(Visitor *v, int64_t *obj, const char *name,
+static bool visit_type_intN(Visitor *v, int64_t *obj, const char *name,
int64_t min, int64_t max, const char *type,
Error **errp)
{
- Error *err = NULL;
int64_t value = *obj;
assert(v->type == VISITOR_INPUT || (value >= min && value <= max));
- v->type_int64(v, name, &value, &err);
- if (err) {
- error_propagate(errp, err);
- } else if (value < min || value > max) {
+ if (!v->type_int64(v, name, &value, errp)) {
+ return false;
+ }
+ if (value < min || value > max) {
assert(v->type == VISITOR_INPUT);
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
name ? name : "null", type);
- } else {
- *obj = value;
+ return false;
}
+ *obj = value;
+ return true;
}
-void visit_type_int8(Visitor *v, const char *name, int8_t *obj, Error **errp)
+bool visit_type_int8(Visitor *v, const char *name, int8_t *obj, Error **errp)
{
int64_t value;
+ bool ok;
trace_visit_type_int8(v, name, obj);
value = *obj;
- visit_type_intN(v, &value, name, INT8_MIN, INT8_MAX, "int8_t", errp);
+ ok = visit_type_intN(v, &value, name, INT8_MIN, INT8_MAX, "int8_t", errp);
*obj = value;
+ return ok;
}
-void visit_type_int16(Visitor *v, const char *name, int16_t *obj,
+bool visit_type_int16(Visitor *v, const char *name, int16_t *obj,
Error **errp)
{
int64_t value;
+ bool ok;
trace_visit_type_int16(v, name, obj);
value = *obj;
- visit_type_intN(v, &value, name, INT16_MIN, INT16_MAX, "int16_t", errp);
+ ok = visit_type_intN(v, &value, name, INT16_MIN, INT16_MAX, "int16_t",
+ errp);
*obj = value;
+ return ok;
}
-void visit_type_int32(Visitor *v, const char *name, int32_t *obj,
+bool visit_type_int32(Visitor *v, const char *name, int32_t *obj,
Error **errp)
{
int64_t value;
+ bool ok;
trace_visit_type_int32(v, name, obj);
value = *obj;
- visit_type_intN(v, &value, name, INT32_MIN, INT32_MAX, "int32_t", errp);
+ ok = visit_type_intN(v, &value, name, INT32_MIN, INT32_MAX, "int32_t",
+ errp);
*obj = value;
+ return ok;
}
-void visit_type_int64(Visitor *v, const char *name, int64_t *obj,
+bool visit_type_int64(Visitor *v, const char *name, int64_t *obj,
Error **errp)
{
assert(obj);
trace_visit_type_int64(v, name, obj);
- v->type_int64(v, name, obj, errp);
+ return v->type_int64(v, name, obj, errp);
}
-void visit_type_size(Visitor *v, const char *name, uint64_t *obj,
+bool visit_type_size(Visitor *v, const char *name, uint64_t *obj,
Error **errp)
{
assert(obj);
trace_visit_type_size(v, name, obj);
if (v->type_size) {
- v->type_size(v, name, obj, errp);
- } else {
- v->type_uint64(v, name, obj, errp);
+ return v->type_size(v, name, obj, errp);
}
+ return v->type_uint64(v, name, obj, errp);
}
-void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp)
+bool visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp)
{
assert(obj);
trace_visit_type_bool(v, name, obj);
- v->type_bool(v, name, obj, errp);
+ return v->type_bool(v, name, obj, errp);
}
-void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp)
+bool visit_type_str(Visitor *v, const char *name, char **obj, Error **errp)
{
Error *err = NULL;
@@ -310,89 +322,88 @@ void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp)
assert(!err != !*obj);
}
error_propagate(errp, err);
+ return !err;
}
-void visit_type_number(Visitor *v, const char *name, double *obj,
+bool visit_type_number(Visitor *v, const char *name, double *obj,
Error **errp)
{
assert(obj);
trace_visit_type_number(v, name, obj);
- v->type_number(v, name, obj, errp);
+ return v->type_number(v, name, obj, errp);
}
-void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp)
+bool visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp)
{
- Error *err = NULL;
+ bool ok;
assert(obj);
assert(v->type != VISITOR_OUTPUT || *obj);
trace_visit_type_any(v, name, obj);
- v->type_any(v, name, obj, &err);
+ ok = v->type_any(v, name, obj, errp);
if (v->type == VISITOR_INPUT) {
- assert(!err != !*obj);
+ assert(ok != !*obj);
}
- error_propagate(errp, err);
+ return ok;
}
-void visit_type_null(Visitor *v, const char *name, QNull **obj,
+bool visit_type_null(Visitor *v, const char *name, QNull **obj,
Error **errp)
{
trace_visit_type_null(v, name, obj);
- v->type_null(v, name, obj, errp);
+ return v->type_null(v, name, obj, errp);
}
-static void output_type_enum(Visitor *v, const char *name, int *obj,
+static bool output_type_enum(Visitor *v, const char *name, int *obj,
const QEnumLookup *lookup, Error **errp)
{
int value = *obj;
char *enum_str;
enum_str = (char *)qapi_enum_lookup(lookup, value);
- visit_type_str(v, name, &enum_str, errp);
+ return visit_type_str(v, name, &enum_str, errp);
}
-static void input_type_enum(Visitor *v, const char *name, int *obj,
+static bool input_type_enum(Visitor *v, const char *name, int *obj,
const QEnumLookup *lookup, Error **errp)
{
- Error *local_err = NULL;
int64_t value;
char *enum_str;
- visit_type_str(v, name, &enum_str, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
+ if (!visit_type_str(v, name, &enum_str, errp)) {
+ return false;
}
value = qapi_enum_parse(lookup, enum_str, -1, NULL);
if (value < 0) {
error_setg(errp, QERR_INVALID_PARAMETER, enum_str);
g_free(enum_str);
- return;
+ return false;
}
g_free(enum_str);
*obj = value;
+ return true;
}
-void visit_type_enum(Visitor *v, const char *name, int *obj,
+bool visit_type_enum(Visitor *v, const char *name, int *obj,
const QEnumLookup *lookup, Error **errp)
{
assert(obj && lookup);
trace_visit_type_enum(v, name, obj);
switch (v->type) {
case VISITOR_INPUT:
- input_type_enum(v, name, obj, lookup, errp);
- break;
+ return input_type_enum(v, name, obj, lookup, errp);
case VISITOR_OUTPUT:
- output_type_enum(v, name, obj, lookup, errp);
- break;
+ return output_type_enum(v, name, obj, lookup, errp);
case VISITOR_CLONE:
/* nothing further to do, scalar value was already copied by
* g_memdup() during visit_start_*() */
- break;
+ return true;
case VISITOR_DEALLOC:
/* nothing to deallocate for a scalar */
- break;
+ return true;
+ default:
+ abort();
}
}