[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH RFC] lib: extend ASSERT()
The increasing amount of constructs along the lines of if ( !condition ) { ASSERT_UNREACHABLE(); return; } is not only longer than necessary, but also doesn't produce incident specific console output (except for file name and line number). Allow the intended effect to be achieved with ASSERT(), by giving it a second parameter allowing specification of the action to take in release builds in case an assertion would have triggered in a debug one. The example above then becomes ASSERT(condition, return); Make sure the condition will continue to not get evaluated when just a single argument gets passed to ASSERT(). Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> --- RFC: The use of a control flow construct as a macro argument may be controversial. --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -818,11 +818,7 @@ int xenmem_add_to_physmap(struct domain union add_to_physmap_extra extra = {}; struct page_info *pages[16]; - if ( !paging_mode_translate(d) ) - { - ASSERT_UNREACHABLE(); - return -EACCES; - } + ASSERT(paging_mode_translate(d), return -EACCES); if ( xatp->space == XENMAPSPACE_gmfn_foreign ) extra.foreign_domid = DOMID_INVALID; --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -55,12 +55,14 @@ #endif #ifndef NDEBUG -#define ASSERT(p) \ +#define ASSERT(p, ...) \ do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0) #define ASSERT_UNREACHABLE() assert_failed("unreachable") #define debug_build() 1 #else -#define ASSERT(p) do { if ( 0 && (p) ) {} } while (0) +#define ASSERT(p, alt...) do { \ + if ( !count_args(alt) || unlikely(!(p)) ) { alt; } \ + } while ( 0 ) #define ASSERT_UNREACHABLE() do { } while (0) #define debug_build() 0 #endif
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |