From 4bb1d272fa46016dd0fe269a637e3b0722d51a24 Mon Sep 17 00:00:00 2001 From: edgrif <edgrif> Date: Fri, 27 Nov 2009 13:15:30 +0000 Subject: [PATCH] add macros to do gtk like 'return_if_fail' testing. --- src/include/ZMap/zmapUtilsLog.h | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/include/ZMap/zmapUtilsLog.h b/src/include/ZMap/zmapUtilsLog.h index 034e7ef8f..197e66d4c 100755 --- a/src/include/ZMap/zmapUtilsLog.h +++ b/src/include/ZMap/zmapUtilsLog.h @@ -25,9 +25,9 @@ * Description: Contains macros, functions etc. for logging. * * HISTORY: - * Last edited: Nov 19 15:43 2008 (edgrif) + * Last edited: Nov 20 18:08 2009 (edgrif) * Created: Mon Mar 29 16:51:28 2004 (edgrif) - * CVS info: $Id: zmapUtilsLog.h,v 1.8 2008-11-19 15:44:12 edgrif Exp $ + * CVS info: $Id: zmapUtilsLog.h,v 1.9 2009-11-27 13:15:30 edgrif Exp $ *------------------------------------------------------------------- */ #ifndef ZMAP_UTILS_LOG_H @@ -158,4 +158,40 @@ void zMapLogMsg(char *domain, GLogLevelFlags log_level, /* make logging from totalview evaluations a lot easier... */ void zMapLogQuark(GQuark quark); + + + +/* Use this macro like this: + * + * zMapLogReturnIfFail(widget != NULL) ; + * + * Logs the error and returns from the function if widget is NULL. + * + */ +#define zMapLogReturnIfFail(expr) \ + G_STMT_START{ \ + if (expr) { } else \ + { \ + zMapLogMsg(ZMAPLOG_DOMAIN, \ + G_LOG_LEVEL_CRITICAL, \ + ZMAP_LOG_CODE_PARAMS, \ + "Expr failed: \"%s\"" , \ + #expr) ; \ + return; \ + }; }G_STMT_END + +#define zMapLogReturnValIfFail(expr, val) G_STMT_START{ \ + if (expr) { } else \ + { \ + zMapLogMsg(ZMAPLOG_DOMAIN, \ + G_LOG_LEVEL_CRITICAL, \ + ZMAP_LOG_CODE_PARAMS, \ + "Expr failed: \"%s\"" , \ + #expr) ; \ + return (val); \ + }; }G_STMT_END + + + + #endif /* ZMAP_UTILS_LOG_H */ -- GitLab