[PATCH wayland] server: Make serial number 0 mean invalid

Derek Foreman derekf at osg.samsung.com
Wed Sep 30 09:45:18 PDT 2015


On 30/09/15 11:37 AM, Bill Spitzak wrote:
> 
> 
> On Wed, Sep 30, 2015 at 8:59 AM, Derek Foreman <derekf at osg.samsung.com
> <mailto:derekf at osg.samsung.com>> wrote:
> 
>     Having an invalid serial number is quite useful - for example, we can
>     have protocol requests that optionally take a serial number or 0
>     instead of having two similar requests.
> 
>     Signed-off-by: Derek Foreman <derekf at osg.samsung.com
>     <mailto:derekf at osg.samsung.com>>
>     ---
> 
>     Well, let's see where this goes ;)
> 
> 
> I certainly hope this sort of thing is accepted.

There was some discussion about it on irc back in February, seemed to be
at least a little interest.

>     I do wonder if we should have a wl_serial_compare() as part of wayland
>     but the semantics are tricky (a big serial and a small serial may
>     actually
>     have happened quite close to eachother if the small happened after a
>     wrap around).
> 
> 
> Just let the programmers use signed arithmetic. There is no reason to
> make this too complicated. If SIGNED_SERIAL_T is the signed equivalent
> to the serial number, then the following will detect if a is before b:
> 
>   SIGNED_SERIAL_T(a-b) < 0
> 
> This sets the "arbitrary distance" to 1/2 the entire serial space.

So you're in favour of not bothering to give a helper function in
libwayland, and just expecting everyone to do their own thing?

Sounds good to me, I'll tally votes before I waste any time writing a
helper then. :)

>     --- a/src/wayland-server.c
>     +++ b/src/wayland-server.c
>     @@ -826,7 +826,7 @@ wl_display_create(void)
>             wl_signal_init(&display->destroy_signal);
> 
>             display->id = 1;
>     -       display->serial = 0;
>     +       display->serial = 1;
> 
>             wl_array_init(&display->additional_shm_formats);
> 
>     @@ -979,6 +979,9 @@ wl_display_next_serial(struct wl_display *display)
>      {
>             display->serial++;
> 
>     +       if (display->serial == 0)
>     +               display->serial++;
>     +
>             return display->serial;
>      }
> 
> 
> I suspect this causes the first event to have a serial number of 2, not
> 1. Not a big deal, but it might be better to initialize the serial
> number to zero, or you can initialize it to -1 if you want the structure
> to always have a valid serial number.
> 

It's possible, I think, to call wl_display_get_serial() without ever
having called wl_display_next_serial() - not sure whether that's
considered valid or not.

So I figured I'd take a chance at throwing away 1 of the billions in
order to not have to worry about that.

Thanks for taking a look.




More information about the wayland-devel mailing list