[PATCH 1/2] Add gnutls_assert_val idiom.
Jonathan Bastien-Filiatrault
joe at x2a.org
Fri Sep 17 05:32:05 CEST 2010
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 <joe at x2a.org>
---
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
More information about the Gnutls-devel
mailing list