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

Bill Spitzak spitzak at gmail.com
Wed Sep 30 09:37:35 PDT 2015


On Wed, Sep 30, 2015 at 8:59 AM, Derek Foreman <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>
> ---
>
> Well, let's see where this goes ;)
>

I certainly hope this sort of thing is accepted.

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.

--- 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150930/067c8b2a/attachment-0001.html>


More information about the wayland-devel mailing list