summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libdimension/Makefile.am4
-rw-r--r--libdimension/compiler-internal.h (renamed from libdimension/compiler.h)2
-rw-r--r--libdimension/dimension-internal.h2
-rw-r--r--libdimension/dimension.h2
-rw-r--r--libdimension/dimension/compiler.h (renamed from libdimension/dimension/inline.h)11
-rw-r--r--libdimension/dimension/error.h20
-rw-r--r--libdimension/prtree.c3
7 files changed, 30 insertions, 14 deletions
diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am
index 35f56f7..c75241e 100644
--- a/libdimension/Makefile.am
+++ b/libdimension/Makefile.am
@@ -32,6 +32,7 @@ nobase_include_HEADERS = dimension.h \
dimension/cameras.h \
dimension/canvas.h \
dimension/color.h \
+ dimension/compiler.h \
dimension/csg.h \
dimension/dictionary.h \
dimension/error.h \
@@ -40,7 +41,6 @@ nobase_include_HEADERS = dimension.h \
dimension/future.h \
dimension/geometry.h \
dimension/gl.h \
- dimension/inline.h \
dimension/interior.h \
dimension/light.h \
dimension/lights.h \
@@ -69,7 +69,7 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \
canvas_pigment.c \
checker.c \
color.c \
- compiler.h \
+ compiler-internal.h \
cone.c \
cube.c \
csg.c \
diff --git a/libdimension/compiler.h b/libdimension/compiler-internal.h
index d6435d0..e59ece2 100644
--- a/libdimension/compiler.h
+++ b/libdimension/compiler-internal.h
@@ -20,7 +20,7 @@
/**
* @file
- * Compiler abstractions.
+ * Internally-used compiler abstractions.
*/
#include <stdbool.h>
diff --git a/libdimension/dimension-internal.h b/libdimension/dimension-internal.h
index 15a7e4c..eae585d 100644
--- a/libdimension/dimension-internal.h
+++ b/libdimension/dimension-internal.h
@@ -30,7 +30,7 @@
#define _GNU_SOURCE
#include "dimension.h"
#include "refcount-internal.h"
-#include "compiler.h"
+#include "compiler-internal.h"
#include "profile.h"
#include "platform.h"
#include "future-impl.h"
diff --git a/libdimension/dimension.h b/libdimension/dimension.h
index 59b73bd..375c2ec 100644
--- a/libdimension/dimension.h
+++ b/libdimension/dimension.h
@@ -74,7 +74,7 @@ typedef void dmnsn_callback_fn(void *ptr);
typedef void dmnsn_free_fn(void *ptr);
/* Include all the libdimension headers */
-#include <dimension/inline.h>
+#include <dimension/compiler.h>
#include <dimension/error.h>
#include <dimension/malloc.h>
#include <dimension/refcount.h>
diff --git a/libdimension/dimension/inline.h b/libdimension/dimension/compiler.h
index e17c60e..5ce8ce8 100644
--- a/libdimension/dimension/inline.h
+++ b/libdimension/dimension/compiler.h
@@ -20,10 +20,7 @@
/**
* @file
- * Inline function support. Handle inlines nicely without cheating and making
- * them static. The DMNSN_INLINE macro is set appropriately for the version of
- * C you're using, and non-inline versions are emitted in exactly one
- * translation unit when necessary.
+ * Compiler abstractions.
*/
/**
@@ -47,3 +44,9 @@
#define DMNSN_INLINE static
#endif
#endif
+
+#ifdef __GNUC__
+ #define DMNSN_UNREACHABLE() __builtin_unreachable();
+#else
+ #define DMNSN_UNREACHABLE()
+#endif
diff --git a/libdimension/dimension/error.h b/libdimension/dimension/error.h
index ae8ba01..894899a 100644
--- a/libdimension/dimension/error.h
+++ b/libdimension/dimension/error.h
@@ -39,8 +39,11 @@
* Report an error.
* @param[in] str A string to print explaining the error.
*/
-#define dmnsn_error(str) \
- dmnsn_report_error(true, DMNSN_FUNC, __FILE__, __LINE__, str)
+#define dmnsn_error(str) \
+ do { \
+ dmnsn_report_error(true, DMNSN_FUNC, __FILE__, __LINE__, str); \
+ DMNSN_UNREACHABLE(); \
+ } while (0)
/**
* @def dmnsn_assert
@@ -54,12 +57,23 @@
#define dmnsn_assert(expr, str) \
do { \
if (!(expr)) { \
- dmnsn_error((str)); \
+ dmnsn_error((str)); \
} \
} while (0)
#endif
/**
+ * @def dmnsn_unreachable
+ * Express that a line of code is unreachable.
+ * @param[in] str A string to print if the line is reached.
+ */
+#ifdef NDEBUG
+ #define dmnsn_unreachable(str) DMNSN_UNREACHABLE()
+#else
+ #define dmnsn_unreachable(str) dmnsn_error((str))
+#endif
+
+/**
* @internal
* Called by dmnsn_warning() and dmnsn_error(); don't call directly.
* @param[in] die Whether the error is fatal.
diff --git a/libdimension/prtree.c b/libdimension/prtree.c
index c59bcc4..33cb9a2 100644
--- a/libdimension/prtree.c
+++ b/libdimension/prtree.c
@@ -121,8 +121,7 @@ dmnsn_get_coordinate(const dmnsn_prnode * const *node, int comparator)
return -(*node)->bounding_box.max.z;
default:
- dmnsn_assert(false, "Invalid comparator.");
- return 0.0; /* Shut up compiler */
+ dmnsn_unreachable("Invalid comparator.");
}
}