qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/8] qapi script: report error for default case in u


From: Wenchao Xia
Subject: [Qemu-devel] [PATCH 2/8] qapi script: report error for default case in union visit
Date: Thu, 7 Nov 2013 03:33:34 +0800

It is possible to reach default case, when an union have a enum
discriminator, so don't abort() but report the error message.

Signed-off-by: Wenchao Xia <address@hidden>
---
 scripts/qapi-visit.py |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index c39e628..b3d3af8 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -223,6 +223,8 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const 
char *name, Error **
                 c_type = type_name(members[key]),
                 c_name = c_fun(key))
 
+    # Only support input visitor for an anon union now, and it is not possible
+    # to reach default, so abort() here, see the logic for (*obj)->kind
     ret += mcgen('''
         default:
             abort();
@@ -312,15 +314,23 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, 
const char *name, Error **
                 c_type=type_name(members[key]),
                 c_name=c_fun(key))
 
+    # Tell caller the value is invalid, since the discriminator value maybe an
+    # unmapped enum value.
     ret += mcgen('''
             default:
-                abort();
+                error_setg(&err,
+                           "Invalid discriminator value %(pi)s for %(name)s",
+                           (*obj)->kind);
+                break;
             }
         }
         error_propagate(errp, err);
         err = NULL;
     }
-''')
+''',
+                pi="%d",
+                name=name)
+
     pop_indent()
     ret += mcgen('''
         /* Always call end_struct if start_struct succeeded.  */
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]