Rusty Russell wrote:
> Hi all,
> 
>    Converting to and from void * for callback functions loses type safety: 
> everywhere else we expect the compiler to catch incorrect pointer types 
> handed to functions.
> 
>    It's pretty simple to create typesafe callback functions using typeof, and 
> with a little gcc trickery we can allow both old-style and typesafe callbacks 
> to avoid churn on commonly-used routines.

I wasn't too convinced with only irq handler conversion but with other
things converted, I'm liking it very much.  I really like the timer
conversion as casting between void * and unsigned long is annoying.
Possible improvements.

* Passing NULL as data to callback which takes non-void pointer
  triggers warning.  I think this should be allowed.  Something like
  the following?

* Allowing non-pointer integral types which fit into pointer would be
  nice.  It's often convenient to pass integers to simple callbacks.

The following macro kinda-sorta achieves the above two but it doesn't
consider promotion of integer types and thus is too strict.  There
gotta be some way.

#define kthread_create(threadfn, data, namefmt...) ({           \
        int (*_threadfn)(typeof(data));                         \
        void *_data;                                            \
        _threadfn = 
__builtin_choose_expr(!__builtin_types_compatible_p(typeof(data), 
typeof(NULL)), \
                        (threadfn), (void *)(threadfn));        \
        _data = __builtin_choose_expr(sizeof(data) <= sizeof(void *), \
                        (void *)(unsigned long)data, (void *)data); \
        __kthread_create((void *)_threadfn, _data, namefmt);    \
})

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to