lkml.org 
[lkml]   [2012]   [Apr]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC 1/3] typecheck: extend typecheck.h with more useful typechecking macros
    Date
    Add macros to compare multiple parameters to a given type, and macros to
    compare multiple parameters between themselves.

    Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
    ---
    include/linux/typecheck.h | 42 ++++++++++++++++++++++++++++++++++--------
    1 files changed, 34 insertions(+), 8 deletions(-)

    diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
    index eb5b74a..a495dcb 100644
    --- a/include/linux/typecheck.h
    +++ b/include/linux/typecheck.h
    @@ -5,20 +5,46 @@
    * Check at compile time that something is of a particular type.
    * Always evaluates to 1 so you may use it easily in comparisons.
    */
    -#define typecheck(type,x) \
    -({ type __dummy; \
    - typeof(x) __dummy2; \
    - (void)(&__dummy == &__dummy2); \
    - 1; \
    +#define typecheck(type,x) \
    +({ type __dummy; \
    + typeof(x) __dummy2; \
    + (void)(&__dummy == &__dummy2); \
    + 1; \
    +})
    +
    +#define typecheck2(type,x,y) \
    +({ typecheck(type, x); \
    + typecheck(type, y); \
    + 1; \
    +})
    +
    +#define typecheck3(type,x,y,z) \
    +({ typecheck2(type,x,y); \
    + typecheck(type,z); \
    + 1; \
    +})
    +
    +#define typecmp2(x,y) \
    +({ typeof(x) __x = (x); \
    + typeof(y) __y = (y); \
    + typecheck(typeof(x),x); \
    + typecheck(typeof(y),y); \
    + (void)(&__x==&__y); \
    + 1; \
    +})
    +
    +#define typecmp3(x,y,z) \
    +({ typecmp2((x),(y)); \
    + typecmp2((x),(z)); \
    })

    /*
    * Check at compile time that 'function' is a certain type, or is a pointer
    * to that type (needs to use typedef for the function type.)
    */
    -#define typecheck_fn(type,function) \
    -({ typeof(type) __tmp = function; \
    - (void)__tmp; \
    +#define typecheck_fn(type,function) \
    +({ typeof(type) __tmp = function; \
    + (void)__tmp; \
    })

    #endif /* TYPECHECK_H_INCLUDED */
    --
    1.7.8.5


    \
     
     \ /
      Last update: 2012-04-14 21:19    [W:0.023 / U:0.176 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site