diff mbox

[04/16] qapi: make visit_type_size fallback to type_int

Message ID 1374596592-7027-5-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov July 23, 2013, 4:23 p.m. UTC
From: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>

Currently visit_type_size checks if the visitor's type_size function pointer is
NULL. If not, it calls it, otherwise it calls v->type_uint64(). But neither of
these pointers are ever set. Fallback to calling v->type_int() in this third
(default) case.

Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 qapi/qapi-visit-core.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

Comments

Hu Tao July 25, 2013, 6:41 a.m. UTC | #1
On Tue, Jul 23, 2013 at 06:23:00PM +0200, Igor Mammedov wrote:
> From: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> 
> Currently visit_type_size checks if the visitor's type_size function pointer is
> NULL. If not, it calls it, otherwise it calls v->type_uint64(). But neither of
> these pointers are ever set. Fallback to calling v->type_int() in this third
> (default) case.
> 
> Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  qapi/qapi-visit-core.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
> index 401ee6e..fcacaff 100644
> --- a/qapi/qapi-visit-core.c
> +++ b/qapi/qapi-visit-core.c
> @@ -238,8 +238,17 @@ void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp)
>  
>  void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
>  {
> +    int64_t value;
>      if (!error_is_set(errp)) {
> -        (v->type_size ? v->type_size : v->type_uint64)(v, obj, name, errp);
> +        if (v->type_size) {
> +            v->type_size(v, obj, name, errp);
> +        } else if (v->type_uint64) {
> +            v->type_uint64(v, obj, name, errp);
> +        } else {
> +            value = *obj;
> +            v->type_int(v, &value, name, errp);
> +            *obj = value;
> +        }
>      }
>  }

This doesn't address comment from Michael Roth, quoted below:

---
I'd recommend just doing:

  if (v->type_size) {
      v->type_size(v, obj, name, errp);
  } else {
      visit_type_uint64(v, obj, name, errp);
  }

visit_type_uint64() already handles the fallback to visit_type_int() so no
need to duplicate.
---
Igor Mammedov July 25, 2013, 11:35 a.m. UTC | #2
On Thu, 25 Jul 2013 14:41:36 +0800
Hu Tao <hutao@cn.fujitsu.com> wrote:

> On Tue, Jul 23, 2013 at 06:23:00PM +0200, Igor Mammedov wrote:
> > From: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> > 
> > Currently visit_type_size checks if the visitor's type_size function pointer is
> > NULL. If not, it calls it, otherwise it calls v->type_uint64(). But neither of
> > these pointers are ever set. Fallback to calling v->type_int() in this third
> > (default) case.
> > 
> > Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  qapi/qapi-visit-core.c |   11 ++++++++++-
> >  1 files changed, 10 insertions(+), 1 deletions(-)
> > 
> > diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
> > index 401ee6e..fcacaff 100644
> > --- a/qapi/qapi-visit-core.c
> > +++ b/qapi/qapi-visit-core.c
> > @@ -238,8 +238,17 @@ void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp)
> >  
> >  void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
> >  {
> > +    int64_t value;
> >      if (!error_is_set(errp)) {
> > -        (v->type_size ? v->type_size : v->type_uint64)(v, obj, name, errp);
> > +        if (v->type_size) {
> > +            v->type_size(v, obj, name, errp);
> > +        } else if (v->type_uint64) {
> > +            v->type_uint64(v, obj, name, errp);
> > +        } else {
> > +            value = *obj;
> > +            v->type_int(v, &value, name, errp);
> > +            *obj = value;
> > +        }
> >      }
> >  }
> 
> This doesn't address comment from Michael Roth, quoted below:
> 
> ---
> I'd recommend just doing:
> 
>   if (v->type_size) {
>       v->type_size(v, obj, name, errp);
>   } else {
>       visit_type_uint64(v, obj, name, errp);
>   }
> 
> visit_type_uint64() already handles the fallback to visit_type_int() so no
> need to duplicate.
> ---
> 

I guess we can just drop this patch.
diff mbox

Patch

diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 401ee6e..fcacaff 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -238,8 +238,17 @@  void visit_type_int64(Visitor *v, int64_t *obj, const char *name, Error **errp)
 
 void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
 {
+    int64_t value;
     if (!error_is_set(errp)) {
-        (v->type_size ? v->type_size : v->type_uint64)(v, obj, name, errp);
+        if (v->type_size) {
+            v->type_size(v, obj, name, errp);
+        } else if (v->type_uint64) {
+            v->type_uint64(v, obj, name, errp);
+        } else {
+            value = *obj;
+            v->type_int(v, &value, name, errp);
+            *obj = value;
+        }
     }
 }