On Thu, Sep 19, 2013 at 12:50:23PM +0300, Pekka Paalanen wrote:
> On Thu, 19 Sep 2013 13:54:34 +1000
> Peter Hutterer <[email protected]> wrote:
> 
> > Instead of NULL, a client that doesn't implement all callbacks of a listener
> > can use named defines to increase readability of the code. For example:
> > 
> > const struct wl_pointer_listener pointer_listener = {
> >     WL_POINTER_ENTER_HANDLER_NONE,
> >     WL_POINTER_LEAVE_HANDLER_NONE,
> >     motion_handler,
> >     button_handler,
> >     axis_handler,
> > };
> > 
> > These are defined as typed NULL, so getting the order wrong will yield a
> > compiler warning in most cases - at least where neighbouring functions don't
> > have the same signature.
> > 
> >  #define WL_POINTER_ENTER_HANDLER_NONE \
> >  ((void(*)(void *, struct wl_pointer *, uint32_t , struct wl_surface *, 
> > wl_fixed_t , wl_fixed_t )) NULL)
> > ---
> > Just gathering interest in this, if we want this I'll polish it up and test
> > it a bit more.
> 
> Hi,
> 
> are you sure a NULL handler function pointer is actually legal?
> I thought we segfault if it is NULL and the event comes to dispatch.
> Or was there some earlier patch that lifted this restriction?

yes, you're right, wonder why that didn't trigger in my tests here.
I'll send a patch for that too, if it's actually wanted.

Cheers,
   Peter

> 
> >  src/scanner.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> > 
> > diff --git a/src/scanner.c b/src/scanner.c
> > index d02d865..a41da11 100644
> > --- a/src/scanner.c
> > +++ b/src/scanner.c
> > @@ -872,6 +872,23 @@ emit_structs(struct wl_list *message_list, struct 
> > interface *interface)
> >     printf("};\n\n");
> >  
> >     if (!is_interface) {
> > +       wl_list_for_each(m, message_list, link) {
> > +           printf("#define %s_%s_HANDLER_NONE ((void(*)(",
> > +                  interface->uppercase_name, m->uppercase_name);
> > +                   printf("void *, "),
> > +                   printf("struct %s *", interface->name);
> > +           wl_list_for_each(a, &m->arg_list, link) {
> > +                   printf(", ");
> > +                   if (a->type == OBJECT && a->interface_name == NULL)
> > +                           printf("void *");
> > +                   else if (a->type == NEW_ID)
> > +                           printf("struct %s *", a->interface_name);
> > +                   else
> > +                           emit_type(a);
> > +           }
> > +           printf(")) NULL)\n");
> > +       }
> > +
> >         printf("static inline int\n"
> >                "%s_add_listener(struct %s *%s,\n"
> >                "%sconst struct %s_listener *listener, void *data)\n"
> 
_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to