qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [qapi] Cannot use list of strings


From: Amos Kong
Subject: Re: [Qemu-devel] [qapi] Cannot use list of strings
Date: Tue, 16 Apr 2013 18:13:22 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Apr 16, 2013 at 10:54:56AM +0200, Paolo Bonzini wrote:
> Il 16/04/2013 10:49, Stefan Hajnoczi ha scritto:
> >> > Tried using a list of strings as an argument to a command, but the 
> >> > generated
> >> > code references the 'strList' type, which does not exist.
> >> > 
> >> > Is a specialized version for "['str']" missing, or should I define my 
> >> > own type
> >> > with a single field of 'str' type?
> > akong just hit this too.

That thread: http://marc.info/?l=qemu-devel&m=136572276530702&w=3

> > I think it's a question for aliguori, luiz, or mdroth.
> 
> Laszlo defined and used String for this purpose:

Eric said String list contains additional JSON structure.
At least, it works.

===================== using StringList
    '*unicast':        ['String'],
    '*multicast':      ['String']

{
    "return": [
        {
            "name": "virtio-net-pci.0", 
            "multicast": [
                {
                    "str": "01:80:c2:00:00:21"
                }, 
                {
                    "str": "00:00:00:00:00:00"
                }
            ]
        }, 
        ....
    ]
}
======================== using strList
    '*unicast':        ['str'],
    '*multicast':      ['str']

Eric, is it expected format?

{
    "return": [
        {
            "name": "virtio-net-pci.0", 
            "multicast": [
                    "str": "01:80:c2:00:00:21",
                    "str": "00:00:00:00:00:00"
            ]
        },
        ....
    ]
}
========================

I changed qapi scripts to define struct, struct list,
visit/free functions for 'str'. But it conflicts with
existed str functions. I hadn't find a solution.

Do we need to defind strList & visit functions in qapi-core files?
not generated by scripts.


diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 9e19920..5167d85 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -282,6 +282,10 @@ fdecl.write(mcgen('''
 exprs = parse_schema(sys.stdin)
 exprs = filter(lambda expr: not expr.has_key('gen'), exprs)

+ret = "\n"
+ret += generate_fwd_struct('str', {'str': 'str'})
+fdecl.write(ret)
+
 for expr in exprs:
     ret = "\n"
     if expr.has_key('type'):
@@ -319,6 +323,15 @@ for expr in exprs:
         continue
     fdecl.write(ret)

+ret = "\n"
+ret += generate_struct('str', "", {'str': 'str'}) + "\n"
+ret += generate_type_cleanup_decl('str' + "List")
+fdef.write(generate_type_cleanup('str' + "List") + "\n")
+ret += generate_type_cleanup_decl('str')
+fdef.write(generate_type_cleanup('str') + "\n")
+
+fdecl.write(ret)
+
 fdecl.write('''
 #endif
 ''')
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index a276540..089dda7 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -354,6 +354,13 @@ for expr in exprs:
         ret += generate_enum_declaration(expr['enum'], expr['data'])
         fdecl.write(ret)

+ret = generate_visit_struct('str', {'str': 'str'})
+ret += generate_visit_list('str', {'str': 'str'})
+fdef.write(ret)
+
+ret = generate_declaration('str', {'str': 'str'})
+fdecl.write(ret)
+
 fdecl.write('''
 #endif
 ''')

 
> ##
> # @String
> #
> # A fat type wrapping 'str', to be embedded in lists.
> #
> # Since 1.2
> ##
> { 'type': 'String',
>   'data': {
>     'str': 'str' } }

-- 
                        Amos.



reply via email to

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