|
|
|
|
|
|
|
|
|
|
xen-devel
Re: [Xen-devel] [PATCH 1 of 4] xl: idl: Abolish keyed union types
On Thu, 2011-01-06 at 17:56 +0000, Ian Jackson wrote:
> Gianni Tedesco writes ("[Xen-devel] [PATCH 1 of 4] xl: idl: Abolish keyed
> union types"):
> > xl: idl: Abolish keyed union types
> >
> > Since the IDL file has become useful for generating language
> > bindings it has become apparent that the KeyedUnion type has no
> > straightforward translation to scripting languages which have no
> > notion of unions.
>
> Uhh? Most scripting languages' aggregate types are practically
> nothing _but_ unions!
Not really sure I follow this.
> The correct translation of a keyed union would probably be an
> aggregate (eg, in Python, a dictionary) containing an entry for the
> key and entries for whatever version of the union it involved.
Hrm, I don't think we can easily do it this way. We create full fledged
python types to correspond to the C types currently. Probably the more
natural construction for unions would be basically the C equivalent of:
class Foo:
def __init__(self):
self.__hidden = xl.thing_pv()
def __getattr__(self, k):
return self.__hidden.__getattr__(k)
def __setattr__(self, k, v):
if k == 'hvm':
if v:
self.__hidden = xl.thing_hvm()
# copy all attributes from before
elif v:
self.__hidden = xl.thing_pv()
# copy all attributes from before
return self.__hidden.__setattr__(k, v)
so that:
x = Foo()
x.pv_thing = True
x.pv_thing
>>> True
x.hvm = True
x.pv_thing
>>> Exception: AttributeError
x.hvm_thing = 'thing'
In other words, frob the getter/setter table whenever the key is set. I
could probably implement this if required as a pre-requisite for the
rest of the series but it may take a day or two.
Alternatively, I have some further patches to do with the Python binding
which does some more sophisticated stuff and I could re-introduce the
KeyedUnion later?
> > Turns out this is only used in domain_build_info which is hardly a memory
> > criticial structure.
>
> However I don't have a strong opinion about the desirability of using
> a tagged union for this particular structure.
Hence my casualness in abolishing it.
Gianni
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
|
|
|
|