From cb3b0cd8c48cf7315ad64c05425f9dca7ac6068c Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 30 Aug 2018 12:13:39 +0200 Subject: [PATCH] Add an helper CHECK_ERROR_CLEANUP macro Extend the existing CHECK_ERROR macro to allow some code to be executed right before raising Virterror. Rework CHECK_ERROR to use CHECK_ERROR_CLEANUP. --- libvirt/libvirt_c_prologue.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libvirt/libvirt_c_prologue.c b/libvirt/libvirt_c_prologue.c index af4a4e9..c41e48d 100644 --- a/libvirt/libvirt_c_prologue.c +++ b/libvirt/libvirt_c_prologue.c @@ -43,11 +43,18 @@ static value Val_virconnectcredential (const virConnectCredentialPtr cred); caml_leave_blocking_section (); \ } while (0) +/* Empty macro to use as empty parameter for other macros, since + * a null token as parameter when calling a macro is not allowed + * before C99. + */ +#define EMPTY /* Check error condition from a libvirt function, and automatically raise * an exception if one is found. */ +#define CHECK_ERROR_CLEANUP(cond, cleanup, fn) \ + do { if (cond) { cleanup; _raise_virterror (fn); } } while (0) #define CHECK_ERROR(cond, fn) \ - do { if (cond) _raise_virterror (fn); } while (0) + CHECK_ERROR_CLEANUP(cond, EMPTY, fn) /*----------------------------------------------------------------------*/ -- 1.8.3.1