[lkml]   [2008]   [Mar]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH 5/5] typesafe: TIMER_INITIALIZER and setup_timer
On Thursday 06 March 2008 21:40:35 Al Viro wrote:
> extern void decay_to_pointer(void const volatile *);
> #define check_callback_type(f,x) (sizeof((0 ? decay_to_pointer(x),(f)(x) :
> (void)0), 0)) #define __setup_timer(timer, func, arg) \
> do { \
> struct timer_list *__timer = (timer); \
> __timer->function = (void (*)(unsigned long))(func); \
> __timer->data = (unsigned long)(arg); \
> (void)check_callback_type(func, arg); \
> } while(0)

Thanks for that snippet; it's much more complete than the last one I found.
I especially like the handling of const- and volatile-taking callback fns.
My version is uglier, pasted below.

There are three problems I see here. First, the lack of warning for "void
intfn(int); DECLARE_TIMER(t, intfn, 0);", but that's relatively minor.
Second, the change of all the users is just churn, with cast_if_type() it can
be done over the next couple of years, if ever.

Worst, I can't see a way to apply your technique in general, for
non-void-returning functions (eg. interrupt handlers).

Here's the typesafe_cb () helper function from ccan (there are also
typesafe_cb_preargs and postargs for callbacks with extra args):

/* Doesn't handle const volatile, but can be added. */
#define typesafe_cb(rettype, fn, arg) \
cast_if_type(cast_if_type(cast_if_type((fn), \
rettype (*)(const typeof(arg)), \
rettype (*)(void *)), \
rettype (*)(volatile typeof(arg)), \
rettype (*)(void *)), \
rettype (*)(typeof(arg)), \
rettype (*)(void *))

> PS: apologies for missing your previous mail; ETOOBIGMBOX ;-/

That's fine, happens to all of us. I was a little disappointed to return from
holiday to discover that either your work or mine hadn't been merged tho :)


 \ /
  Last update: 2008-03-10 02:11    [W:0.067 / U:3.168 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site