diff mbox

[1/7] qapi: support implicit structs in OptsVisitor

Message ID 88451f26df139c09b56b1525f3c5afeea43dd3db.1441627175.git.DirtY.iCE.hu@gmail.com
State New
Headers show

Commit Message

=?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Sept. 7, 2015, 12:08 p.m. UTC
They are required for flat unions (you still have to allocate the
structs).

Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
---
 qapi/opts-visitor.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Eric Blake Sept. 17, 2015, 8:30 p.m. UTC | #1
On 09/07/2015 06:08 AM, Kővágó, Zoltán wrote:
> They are required for flat unions (you still have to allocate the
> structs).
> 
> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
> ---
>  qapi/opts-visitor.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

and required for 'make check' to pass when 4/7 is applied, so:

Tested-by: Eric Blake <eblake@redhat.com>

> 
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 7ae33b3..aa68814 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -149,6 +149,12 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
>      }
>  }
>  
> +static void
> +opts_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp)
> +{
> +    opts_start_struct(v, obj, NULL, NULL, size, errp);

Works because ov->depth is always non-zero by the time any visitor
reaches this callback, triggering the early return in
opts_start_struct().  Might be slightly safer if you just did the
g_malloc0() here, to make sure no caller ever ends up re-initializing
ov->unprocessed_opts, but what you have works.
Eric Blake Sept. 18, 2015, 12:26 p.m. UTC | #2
On 09/17/2015 02:30 PM, Eric Blake wrote:
> On 09/07/2015 06:08 AM, Kővágó, Zoltán wrote:
>> They are required for flat unions (you still have to allocate the
>> structs).
>>
>> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
>> ---
>>  qapi/opts-visitor.c | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> 
> and required for 'make check' to pass when 4/7 is applied, so:
> 
> Tested-by: Eric Blake <eblake@redhat.com>
> 
>>
>> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
>> index 7ae33b3..aa68814 100644
>> --- a/qapi/opts-visitor.c
>> +++ b/qapi/opts-visitor.c
>> @@ -149,6 +149,12 @@ opts_start_struct(Visitor *v, void **obj, const char *kind,
>>      }
>>  }
>>  
>> +static void
>> +opts_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp)
>> +{
>> +    opts_start_struct(v, obj, NULL, NULL, size, errp);
> 
> Works because ov->depth is always non-zero by the time any visitor
> reaches this callback, triggering the early return in
> opts_start_struct().  Might be slightly safer if you just did the
> g_malloc0() here, to make sure no caller ever ends up re-initializing
> ov->unprocessed_opts, but what you have works.
> 

In fact, the alternative that just does a local malloc was proposed here:
https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg04746.html
diff mbox

Patch

diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 7ae33b3..aa68814 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -149,6 +149,12 @@  opts_start_struct(Visitor *v, void **obj, const char *kind,
     }
 }
 
+static void
+opts_start_implicit_struct(Visitor *v, void **obj, size_t size, Error **errp)
+{
+    opts_start_struct(v, obj, NULL, NULL, size, errp);
+}
+
 
 static gboolean
 ghr_true(gpointer ign_key, gpointer ign_value, gpointer ign_user_data)
@@ -185,6 +191,12 @@  opts_end_struct(Visitor *v, Error **errp)
     ov->fake_id_opt = NULL;
 }
 
+static void
+opts_end_implicit_struct(Visitor *v, Error **errp)
+{
+    opts_end_struct(v, errp);
+}
+
 
 static GQueue *
 lookup_distinct(const OptsVisitor *ov, const char *name, Error **errp)
@@ -508,6 +520,9 @@  opts_visitor_new(const QemuOpts *opts)
     ov->visitor.start_struct = &opts_start_struct;
     ov->visitor.end_struct   = &opts_end_struct;
 
+    ov->visitor.start_implicit_struct = &opts_start_implicit_struct;
+    ov->visitor.end_implicit_struct = &opts_end_implicit_struct;
+
     ov->visitor.start_list = &opts_start_list;
     ov->visitor.next_list  = &opts_next_list;
     ov->visitor.end_list   = &opts_end_list;