@@ -513,11 +513,6 @@ void visit_set_policy(Visitor *v, CompatPolicy *policy);
* is an input visitor.
*
* Return true on success, false on failure.
- *
- * May call visit_type_str() under the hood, and the enum visit may
- * fail even if the corresponding string visit succeeded; this implies
- * that an input visitor's visit_type_str() must have no unwelcome
- * side effects.
*/
bool visit_type_enum(Visitor *v, const char *name, int *obj,
const QEnumLookup *lookup, Error **errp);
@@ -359,11 +359,6 @@ opts_type_str(Visitor *v, const char *name, char **obj, bool consume,
return false;
}
*obj = g_strdup(opt->str ? opt->str : "");
- /* Note that we consume a string even if this is called as part of
- * an enum visit that later fails because the string is not a
- * valid enum value; this is harmless because tracking what gets
- * consumed only matters to visit_end_struct() as the final error
- * check if there were no other failures during the visit. */
if (consume) {
processed(ov, name);
}
@@ -411,7 +411,7 @@ static bool input_type_enum(Visitor *v, const char *name, int *obj,
int64_t value;
g_autofree char *enum_str = NULL;
- if (!visit_type_str(v, name, &enum_str, errp)) {
+ if (!visit_type_str_preserving(v, name, &enum_str, errp)) {
return false;
}
@@ -430,6 +430,8 @@ static bool input_type_enum(Visitor *v, const char *name, int *obj,
return false;
}
+ enum_str = NULL;
+ visit_type_str(v, name, &enum_str, &error_abort);
*obj = value;
return true;
}
Consuming a value when visit_type_enum() fails makes it impossible to reinterpret the value with a different type. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> --- include/qapi/visitor.h | 5 ----- qapi/opts-visitor.c | 5 ----- qapi/qapi-visit-core.c | 4 +++- 3 files changed, 3 insertions(+), 11 deletions(-)