lkml.org 
[lkml]   [2008]   [Jan]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 0/6] RFC: Typesafe callbacks
    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


    \
     
     \ /
      Last update: 2008-01-20 13:59    [W:4.217 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site