[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2] libxl: Fix incorrect return of OSEVENT_HOOK macro
On 05/09/2012 09:19 AM, Ian Jackson wrote: > Daniel De Graaf writes ("[PATCH] libxl: Fix incorrect return of OSEVENT_HOOK > macro"): >> The OSEVENT_HOOK_INTERN macro incorrectly returned the value of the >> expression CTX->osevent_in_hook-- (usually 1) instead of the value of >> the function call it made. Change the macro to a statement including the >> return variable to fix this. > > Well spotted, thanks. But I think it would be better to use the GCC > statement expression syntax to avoid changing the call sites ? > > Ian. > Agreed, using the statement expression syntax seems cleaner here. ------8<------------------------------ The OSEVENT_HOOK_INTERN macro incorrectly returned the value of the expression CTX->osevent_in_hook-- (usually 1) instead of the value of the function call it made. Fix the macro to return the proper value. Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx> --- tools/libxl/libxl_event.c | 31 +++++++++++++++++++------------ 1 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index 638b9ab..bee0e27 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -27,18 +27,25 @@ * these macros, with the ctx locked. Likewise all the "occurred" * entrypoints from the application should assert(!in_hook); */ -#define OSEVENT_HOOK_INTERN(defval, hookname, ...) \ - (CTX->osevent_hooks \ - ? (CTX->osevent_in_hook++, \ - CTX->osevent_hooks->hookname(CTX->osevent_user, __VA_ARGS__), \ - CTX->osevent_in_hook--) \ - : defval) - -#define OSEVENT_HOOK(hookname,...) \ - OSEVENT_HOOK_INTERN(0, hookname, __VA_ARGS__) - -#define OSEVENT_HOOK_VOID(hookname,...) \ - OSEVENT_HOOK_INTERN((void)0, hookname, __VA_ARGS__) +#define OSEVENT_HOOK(hookname,...) ({ \ + int rc; \ + if (CTX->osevent_hooks) { \ + CTX->osevent_in_hook++; \ + rc = CTX->osevent_hooks->hookname(CTX->osevent_user, __VA_ARGS__); \ + CTX->osevent_in_hook--; \ + } else { \ + rc = 0; \ + } \ + rc; \ +}) + +#define OSEVENT_HOOK_VOID(hookname,...) do { \ + if (CTX->osevent_hooks) { \ + CTX->osevent_in_hook++; \ + CTX->osevent_hooks->hookname(CTX->osevent_user, __VA_ARGS__); \ + CTX->osevent_in_hook--; \ + } \ +} while (0) /* * fd events _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |