qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance for stru


From: Kevin Wolf
Subject: Re: [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance for structs
Date: Fri, 20 Sep 2013 16:19:44 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Am 20.09.2013 um 15:33 hat Max Reitz geschrieben:
> On 2013-09-20 13:54, Kevin Wolf wrote:
> >This introduces a new 'base' key for struct definitions that refers to
> >another struct type. On the JSON level, the fields of the base type are
> >included directly into the same namespace as the fields of the defined
> >type, like with unions. On the C level, a pointer to a struct of the
> >base type is included.
> >
> >Signed-off-by: Kevin Wolf <address@hidden>

> >diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
> >index 1e44004..90cedd7 100644
> >--- a/scripts/qapi-visit.py
> >+++ b/scripts/qapi-visit.py
> >@@ -17,7 +17,7 @@ import os
> >  import getopt
> >  import errno
> >-def generate_visit_struct_fields(name, field_prefix, fn_prefix, members):
> >+def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, 
> >base = None):
> >      substructs = []
> >      ret = ''
> >      full_name = name if not fn_prefix else "%s_%s" % (name, fn_prefix)
> >@@ -42,6 +42,19 @@ static void visit_type_%(full_name)s_fields(Visitor *m, 
> >%(name)s ** obj, Error *
> >          name=name, full_name=full_name)
> >      push_indent()
> >+    if base:
> >+        ret += mcgen('''
> >+visit_start_implicit_struct(m, (void**) &(*obj)->%(c_name)s, 
> >sizeof(%(type)s), &err);
> Why do you just dereference obj here (implying it will never be NULL)...
> 
> >+if (!err) {
> >+    visit_type_%(type)s_fields(m, obj ? &(*obj)->%(c_prefix)s%(c_name)s : 
> >NULL, &err);
> ...but then you're checking whether it is NULL before dereferencing?

Because I'm clearly not understanding what I'm doing here... I can
change the first line into this:

visit_start_implicit_struct(m, obj ? (void**) &(*obj)->%(c_name)s : NULL, 
sizeof(%(type)s), &err);

I'm not sure what cases it would fix, but the surrounding code looks
like it's doing the check, so it can't hurt. visit_start_implicit_struct
seems to be able to handle NULL pointers.

Kevin



reply via email to

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