Patchwork [04/10] qapi: shortcut visits on errors

login
register
mail settings
Submitter Paolo Bonzini
Date March 22, 2012, 11:51 a.m.
Message ID <1332417072-20329-5-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/148233/
State New
Headers show

Comments

Paolo Bonzini - March 22, 2012, 11:51 a.m.
We can exit very soon if we enter a visitor with a preexisting error.
This simplifies some cases because we will not have to deal with
obj being non-NULL while *obj is NULL.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/qapi-visit.py |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
Anthony Liguori - March 22, 2012, 8:17 p.m.
On 03/22/2012 06:51 AM, Paolo Bonzini wrote:
> We can exit very soon if we enter a visitor with a preexisting error.
> This simplifies some cases because we will not have to deal with
> obj being non-NULL while *obj is NULL.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   scripts/qapi-visit.py |    9 +++++++++
>   1 files changed, 9 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
> index 54117d4..b242315 100644
> --- a/scripts/qapi-visit.py
> +++ b/scripts/qapi-visit.py
> @@ -61,6 +61,9 @@ def generate_visit_struct(name, members):
>
>   void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
>   {
> +    if (error_is_set(errp)) {
> +        return;
> +    }
>       visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), errp);
>   ''',
>                   name=name)
> @@ -81,6 +84,9 @@ void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name,
>   {
>       GenericList *i, **head = (GenericList **)obj;
>
> +    if (error_is_set(errp)) {
> +        return;
> +    }
>       visit_start_list(m, name, errp);
>
>       for (*head = i = visit_next_list(m, head, errp); i; i = visit_next_list(m,&i, errp)) {
> @@ -112,6 +118,9 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
>   {
>       Error *err = NULL;
>
> +    if (error_is_set(errp)) {
> +        return;
> +    }
>       visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s),&err);
>       visit_type_%(name)sKind(m,&(*obj)->kind, "type",&err);
>       if (err) {

Patch

diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 54117d4..b242315 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -61,6 +61,9 @@  def generate_visit_struct(name, members):
 
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
 {
+    if (error_is_set(errp)) {
+        return;
+    }
     visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), errp);
 ''',
                 name=name)
@@ -81,6 +84,9 @@  void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name,
 {
     GenericList *i, **head = (GenericList **)obj;
 
+    if (error_is_set(errp)) {
+        return;
+    }
     visit_start_list(m, name, errp);
 
     for (*head = i = visit_next_list(m, head, errp); i; i = visit_next_list(m, &i, errp)) {
@@ -112,6 +118,9 @@  void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
 {
     Error *err = NULL;
 
+    if (error_is_set(errp)) {
+        return;
+    }
     visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err);
     visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err);
     if (err) {