0001-Add-compile-time-checked-assert_compatible_types-mac.patch

text/x-patch

Filename: 0001-Add-compile-time-checked-assert_compatible_types-mac.patch
Type: text/x-patch
Part: 0
Message: Re: embedded list v3

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0001
Subject: Add compile time checked assert_compatible_types macro to c.h
File+
src/include/c.h 27 0
From 52a9d3740158c00a19d3939dc91c2a88afca3480 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 28 Sep 2012 13:18:26 +0200
Subject: [PATCH 1/4] Add compile time checked assert_compatible_types macro
 to c.h

Useful for generating better error messages in other macros.
---
 src/include/c.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/include/c.h b/src/include/c.h
index 50e1ecf..024ed5c 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -857,4 +857,31 @@ extern int	fdatasync(int fildes);
 /* /port compatibility functions */
 #include "port.h"
 
+/*
+ * Macro that makes sure two types are the same at compile time
+ *
+ * Used only to emit better error messages, we support compilers without
+ * support for _Static_assert and without support for
+ * __builtin_types_compatible_p and compound expressions which are a gcc
+ * extensions
+ */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#define assert_compatible_types(a, b)									 \
+	do {																 \
+		_Static_assert(												 \
+			__builtin_types_compatible_p(a, __typeof__ (b) ),			 \
+			"variable `" #b "` is not compatible to type `" #a "`" );	 \
+	} while(0)
+
+#define assert_compatible_types_bool(a, b)								 \
+	({																	 \
+		assert_compatible_types(a, b);									 \
+		true;															 \
+	})
+#else
+#define assert_compatible_types(a, b) (void)0
+#define assert_compatible_types_bool(a, b) true
+#endif
+
+
 #endif   /* C_H */
-- 
1.7.12.289.g0ce9864.dirty