Patchwork [02/16] qapi: introduce "size" type

login
register
mail settings
Submitter Laszlo Ersek
Date May 22, 2012, 10:45 a.m.
Message ID <1337683555-13301-3-git-send-email-lersek@redhat.com>
Download mbox | patch
Permalink /patch/160593/
State New
Headers show

Comments

Laszlo Ersek - May 22, 2012, 10:45 a.m.
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 qapi/qapi-visit-core.h |    4 ++++
 qapi/qapi-visit-core.c |    7 +++++++
 scripts/qapi.py        |    2 +-
 3 files changed, 12 insertions(+), 1 deletions(-)
Paolo Bonzini - June 5, 2012, 8:39 p.m.
Il 22/05/2012 12:45, Laszlo Ersek ha scritto:
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  qapi/qapi-visit-core.h |    4 ++++
>  qapi/qapi-visit-core.c |    7 +++++++
>  scripts/qapi.py        |    2 +-
>  3 files changed, 12 insertions(+), 1 deletions(-)
> 
> diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h
> index e850746..bab2fec 100644
> --- a/qapi/qapi-visit-core.h
> +++ b/qapi/qapi-visit-core.h
> @@ -39,6 +39,9 @@ struct Visitor
>                        const char *kind, const char *name, Error **errp);
>  
>      void (*type_int)(Visitor *v, int64_t *obj, const char *name, Error **errp);
> +    /* visit_type_size() falls back to (*type_int)() if type_size is unset */
> +    void (*type_size)(Visitor *v, int64_t *obj, const char *name,
> +                      Error **errp);
>      void (*type_bool)(Visitor *v, bool *obj, const char *name, Error **errp);
>      void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
>      void (*type_number)(Visitor *v, double *obj, const char *name,
> @@ -69,6 +72,7 @@ void visit_end_optional(Visitor *v, Error **errp);
>  void visit_type_enum(Visitor *v, int *obj, const char *strings[],
>                       const char *kind, const char *name, Error **errp);
>  void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp);
> +void visit_type_size(Visitor *v, int64_t *obj, const char *name, Error **errp);
>  void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
>  void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
>  void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp);
> diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
> index df1ed5c..ea31cf5 100644
> --- a/qapi/qapi-visit-core.c
> +++ b/qapi/qapi-visit-core.c
> @@ -95,6 +95,13 @@ void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
>      }
>  }
>  
> +void visit_type_size(Visitor *v, int64_t *obj, const char *name, Error **errp)
> +{
> +    if (!error_is_set(errp)) {
> +        (v->type_size ? v->type_size : v->type_int)(v, obj, name, errp);
> +    }
> +}
> +
>  void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp)
>  {
>      if (!error_is_set(errp)) {
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index e062336..6aebb0f 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -157,7 +157,7 @@ def is_enum(name):
>  def c_type(name):
>      if name == 'str':
>          return 'char *'
> -    elif name == 'int':
> +    elif name == 'int' or name == 'size':
>          return 'int64_t'
>      elif name == 'bool':
>          return 'bool'

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

Patch

diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h
index e850746..bab2fec 100644
--- a/qapi/qapi-visit-core.h
+++ b/qapi/qapi-visit-core.h
@@ -39,6 +39,9 @@  struct Visitor
                       const char *kind, const char *name, Error **errp);
 
     void (*type_int)(Visitor *v, int64_t *obj, const char *name, Error **errp);
+    /* visit_type_size() falls back to (*type_int)() if type_size is unset */
+    void (*type_size)(Visitor *v, int64_t *obj, const char *name,
+                      Error **errp);
     void (*type_bool)(Visitor *v, bool *obj, const char *name, Error **errp);
     void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
     void (*type_number)(Visitor *v, double *obj, const char *name,
@@ -69,6 +72,7 @@  void visit_end_optional(Visitor *v, Error **errp);
 void visit_type_enum(Visitor *v, int *obj, const char *strings[],
                      const char *kind, const char *name, Error **errp);
 void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp);
+void visit_type_size(Visitor *v, int64_t *obj, const char *name, Error **errp);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp);
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index df1ed5c..ea31cf5 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -95,6 +95,13 @@  void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp)
     }
 }
 
+void visit_type_size(Visitor *v, int64_t *obj, const char *name, Error **errp)
+{
+    if (!error_is_set(errp)) {
+        (v->type_size ? v->type_size : v->type_int)(v, obj, name, errp);
+    }
+}
+
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp)
 {
     if (!error_is_set(errp)) {
diff --git a/scripts/qapi.py b/scripts/qapi.py
index e062336..6aebb0f 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -157,7 +157,7 @@  def is_enum(name):
 def c_type(name):
     if name == 'str':
         return 'char *'
-    elif name == 'int':
+    elif name == 'int' or name == 'size':
         return 'int64_t'
     elif name == 'bool':
         return 'bool'