[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [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.

Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
 tools/libxl/libxl_event.c |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c
index 638b9ab..6aced19 100644
--- a/tools/libxl/libxl_event.c
+++ b/tools/libxl/libxl_event.c
@@ -27,18 +27,23 @@
  * 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_RET(rc, hookname,...) do {                             \
+    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;                                                             \
+    }                                                                       \
+} while (0)
+
+#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
@@ -54,7 +59,7 @@ int libxl__ev_fd_register(libxl__gc *gc, libxl__ev_fd *ev,
 
     CTX_LOCK;
 
-    rc = OSEVENT_HOOK(fd_register, fd, &ev->for_app_reg, events, ev);
+    OSEVENT_HOOK_RET(rc, fd_register, fd, &ev->for_app_reg, events, ev);
     if (rc) goto out;
 
     ev->fd = fd;
@@ -77,7 +82,7 @@ int libxl__ev_fd_modify(libxl__gc *gc, libxl__ev_fd *ev, 
short events)
     CTX_LOCK;
     assert(libxl__ev_fd_isregistered(ev));
 
-    rc = OSEVENT_HOOK(fd_modify, ev->fd, &ev->for_app_reg, events);
+    OSEVENT_HOOK_RET(rc, fd_modify, ev->fd, &ev->for_app_reg, events);
     if (rc) goto out;
 
     ev->events = events;
@@ -147,7 +152,7 @@ static int time_register_finite(libxl__gc *gc, 
libxl__ev_time *ev,
 {
     int rc;
 
-    rc = OSEVENT_HOOK(timeout_register, &ev->for_app_reg, abs, ev);
+    OSEVENT_HOOK_RET(rc, timeout_register, &ev->for_app_reg, abs, ev);
     if (rc) return rc;
 
     ev->infinite = 0;
@@ -226,7 +231,7 @@ int libxl__ev_time_modify_abs(libxl__gc *gc, libxl__ev_time 
*ev,
         rc = time_register_finite(gc, ev, abs);
         if (rc) goto out;
     } else {
-        rc = OSEVENT_HOOK(timeout_modify, &ev->for_app_reg, abs);
+        OSEVENT_HOOK_RET(rc, timeout_modify, &ev->for_app_reg, abs);
         if (rc) goto out;
 
         LIBXL_TAILQ_REMOVE(&CTX->etimes, ev, entry);
-- 
1.7.7.6


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.