From 54fa31f03b0a4eb9d7ac38943282de7f4da19c4f Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Wed, 5 Dec 2018 16:23:18 -0800 Subject: [PATCH] Add RETURN_ERROR_IF Macro That Logs Debug Information When Check Fails --- lib/common/zstd_internal.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/common/zstd_internal.h b/lib/common/zstd_internal.h index edeb74b9..73fc7705 100644 --- a/lib/common/zstd_internal.h +++ b/lib/common/zstd_internal.h @@ -56,6 +56,14 @@ extern "C" { #define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */ #define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */ +#define RETURN_ERROR_IF(cond, err, ...) \ + if (cond) { \ + RAWLOG(3, "%s:%d: check %s failed, returning %s", __FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \ + RAWLOG(3, ": " __VA_ARGS__); \ + RAWLOG(3, "\n"); \ + return ERROR(err); \ + } + /*-************************************* * Common constants