[RFC wayland] scanner: provide convenience defines for NULL handlers
Peter Hutterer
peter.hutterer at who-t.net
Tue Sep 24 11:44:35 PDT 2013
On Thu, Sep 19, 2013 at 12:50:23PM +0300, Pekka Paalanen wrote:
> On Thu, 19 Sep 2013 13:54:34 +1000
> Peter Hutterer <peter.hutterer at who-t.net> 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"
>
More information about the wayland-devel
mailing list