Smart comparing of wl_display_interfaces

Pekka Paalanen ppaalanen at gmail.com
Wed Oct 15 23:46:39 PDT 2014


On Wed, 15 Oct 2014 22:44:25 +0400
Dmitry Cherkassov <dcherkassov at gmail.com> wrote:

> Hi list!
> 
> The definition of wl_display_interface symbol can come from
> libwayland-server.so or libwayland-client.so.
> 
> There is a code in closed source EGL implementation that does
> interfaces comparison via pointers, yielding negative results when
> addresses are different (one address is saved by QtWayland, the other
> one is from &wl_display_interface in EGL source code).
> 
> Is there a smarter way to compare wl_display_interface's?
> 
> There is this function:
> 
> wl_interface_equal(const struct wl_interface *a, const struct wl_interface *b)
> {
>     return a == b || strcmp(a->name, b->name) == 0;
> }
> 
> But as you can see it's not safe to use it alone because in case of
> bad pointer we will get undefined results.
> 
> Currently struct wl_interface is the following:
>  struct wl_interface {
>      const char *name;
>      int version;
>      int method_count;
>      const struct wl_message *methods;
>      int event_count;
>      const struct wl_message *events;
>  };
> 
> Since there is no magic field at the beginning it is not possible to
> see whether a pointer points to the valid wl_interface structure.
> 
> So my question is: how can we compare wl_interfaces in more clever and
> safer way?

Hmm, why would you ever have a bad pointer?

Bad pointers in general tend to cause crashes and stuff, so you
shouldn't be having a bad one in the first place.

What is the background for your question/problem?


Thanks,
pq


More information about the wayland-devel mailing list