gnutls-devel
[Top][All Lists]
Advanced

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

[PATCH 1/2] Add gnutls_assert_val idiom.


From: Jonathan Bastien-Filiatrault
Subject: [PATCH 1/2] Add gnutls_assert_val idiom.
Date: Thu, 16 Sep 2010 23:32:05 -0400

 This warrants being made in an inline function or macro since it is
 used throughout the code. This converts 4 line repetitive blocks into
 1 line.

Signed-off-by: Jonathan Bastien-Filiatrault <address@hidden>
---
 lib/gnutls_errors.h |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/lib/gnutls_errors.h b/lib/gnutls_errors.h
index 8bc0c6f..7ed3da9 100644
--- a/lib/gnutls_errors.h
+++ b/lib/gnutls_errors.h
@@ -83,4 +83,21 @@ _gnutls_log (int, const char *fmt, ...)
 
 #endif /* C99_MACROS */
 
+/* GCC won't inline this by itself and results in a "fatal warning"
+   otherwise. Making this a macro has been tried, but it interacts
+   badly with the do..while in the expansion. Welcome to the dark
+   side. */
+static inline
+#ifdef __GNUC__
+ __attribute__ ((always_inline))
+#endif
+int
+gnutls_assert_val_int (int val, const char* file, int line)
+{
+  _gnutls_debug_log( "ASSERT: %s:%d\n", file, line);
+  return val;
+}
+
+#define gnutls_assert_val(x) gnutls_assert_val_int(x, __FILE__, __LINE__)
+
 #endif /* GNUTLS_ERRORS_H */
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]