[PATCH wayland] Add "enum" attribute to "arg" elements
Pekka Paalanen
ppaalanen at gmail.com
Mon Apr 20 00:03:31 PDT 2015
On Sun, 19 Apr 2015 12:51:50 +0000
Jeroen Bollen <jbinero at gmail.com> wrote:
> Hello,
>
> It seems like this discussion died off. Currently there is no way to tell,
> from the Wayland XML specification whether an argument is a bitfield, or
> whether the argument takes an enum and what enum this is.
Hi,
I'm starting to think that using the name "enum" may have been a minor
mistake. We are using it to define namespaced constants in the XML
files, similar to how you use #define in C with some naming conventions.
True, we use the enum type defitions to define these constants in C
rather than #defines. I'm not sure if that has any more rationale
behind it than it was convenient and allows debuggers to explain the
values when cast to the enum type.
Nothing guarantees, that an <enum> element strictly describes a complete
enumeration or even a bitfield. You can have entries which contain
several bits of a bitfield. You don't have to list all allowed
entries, and so on. You could even have an <enum> that lists only
special values and then say a set of other values are allowed, e.g.
list some negative specials and say all positive values are also
allowed. We have never excluded this kind of use, though I don't think
we use it in the core. It doesn't say anything about extensions not in
core, though.
Enumerations could be incomplete. For instance in the current
xdg-shell.xml proposal in Weston, xdg_surface.state definition says
that others are welcome to use other values from their own ranges.
Also, adding the strict type information to the XML spec has no benefit
for C, which is the de facto language for Wayland core developers. A C
compiler also does not raise errors if you violate the rules. This and
all the above are the likely reasons why adding the strict type
information is not interesting, at least for me.
Making the enum rules more strict has a possibility to break existing
users, but to me it is unclear if the benefit would outweigh that
con or the freedom.
On the wire, an enum or bitfield is still just an uint (or int), and a
buggy client or server may cause the other to receive illegal values.
Do the strongly typed languages have checks against that? Can you
define what happens if the value is illegal for an enum? Or do you have
to write that check manually in any case?
So, the big question here is: do we even want to have strict enum types?
Just because some languages have them is not a reason enough to bring
them into the XML language, IMO. Answering that question would take
effort while it is easy to just ignore it seemingly without any harm.
Thanks,
pq
More information about the wayland-devel
mailing list