lkml.org 
[lkml]   [2009]   [Jul]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] kernel.h: Verify that arguments to swap() are the same type
    On Wed, 15 Jul 2009 18:34:21 -0700
    Joe Perches <joe@perches.com> wrote:

    > Signed-off-by: Joe Perches <joe@perches.com>
    >
    > diff --git a/include/linux/kernel.h b/include/linux/kernel.h
    > index d6320a3..72878a5 100644
    > --- a/include/linux/kernel.h
    > +++ b/include/linux/kernel.h
    > @@ -637,8 +637,13 @@ static inline void ftrace_dump(void) { }
    > /*
    > * swap - swap value of @a and @b
    > */
    > -#define swap(a, b) \
    > - do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
    > +#define swap(a, b) \
    > +do { \
    > + typeof(a) __tmp = (a); \
    > + BUILD_BUG_ON(!__same_type(__tmp, (b))); \
    > + (a) = (b); \
    > + (b) = __tmp; \
    > +} while (0)
    >

    I wonder if we can do

    typecheck(a, typeof(b));



    \
     
     \ /
      Last update: 2009-07-23 23:51    [W:0.022 / U:152.004 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site