aboutsummaryrefslogtreecommitdiffstats
path: root/src/lisp.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp.h')
-rw-r--r--src/lisp.h41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/lisp.h b/src/lisp.h
index 6638cc66e9f..e4a2caa1083 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -31,6 +31,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31#include <limits.h> 31#include <limits.h>
32 32
33#include <intprops.h> 33#include <intprops.h>
34#include <verify.h>
34 35
35INLINE_HEADER_BEGIN 36INLINE_HEADER_BEGIN
36 37
@@ -113,28 +114,48 @@ typedef EMACS_UINT uprintmax_t;
113 114
114/* Extra internal type checking? */ 115/* Extra internal type checking? */
115 116
116/* Define an Emacs version of 'assert (COND)'. COND should be free of 117/* Define Emacs versions of <assert.h>'s 'assert (COND)' and <verify.h>'s
117 side effects; it may be evaluated zero or more times. */ 118 'assume (COND)'. COND should be free of side effects, as it may or
119 may not be evaluated.
120
121 'eassert (COND)' checks COND at runtime if ENABLE_CHECKING is
122 defined and suppress_checking is false, and does nothing otherwise.
123 Emacs dies if COND is checked and is false. The suppress_checking
124 variable is initialized to 0 in alloc.c. Set it to 1 using a
125 debugger to temporarily disable aborting on detected internal
126 inconsistencies or error conditions.
127
128 In some cases, a good compiler may be able to optimize away the
129 eassert macro even if ENABLE_CHECKING is true, e.g., if XSTRING (x)
130 uses eassert to test STRINGP (x), but a particular use of XSTRING
131 is invoked only after testing that STRINGP (x) is true, making the
132 test redundant.
133
134 eassume is like eassert except that it also causes the compiler to
135 assume that COND is true afterwards, regardless of whether runtime
136 checking is enabled. This can improve performance in some cases,
137 though it can degrade performance in others. It's often suboptimal
138 for COND to call external functions or access volatile storage. */
139
118#ifndef ENABLE_CHECKING 140#ifndef ENABLE_CHECKING
119# define eassert(cond) ((void) (0 && (cond))) /* Check that COND compiles. */ 141# define eassert(cond) ((void) (0 && (cond))) /* Check that COND compiles. */
142# define eassume(cond) assume (cond)
120#else /* ENABLE_CHECKING */ 143#else /* ENABLE_CHECKING */
121 144
122extern _Noreturn void die (const char *, const char *, int); 145extern _Noreturn void die (const char *, const char *, int);
123 146
124/* The suppress_checking variable is initialized to 0 in alloc.c. Set
125 it to 1 using a debugger to temporarily disable aborting on
126 detected internal inconsistencies or error conditions.
127
128 In some cases, a good compiler may be able to optimize away the
129 eassert macro altogether, e.g., if XSTRING (x) uses eassert to test
130 STRINGP (x), but a particular use of XSTRING is invoked only after
131 testing that STRINGP (x) is true, making the test redundant. */
132extern bool suppress_checking EXTERNALLY_VISIBLE; 147extern bool suppress_checking EXTERNALLY_VISIBLE;
133 148
134# define eassert(cond) \ 149# define eassert(cond) \
135 (suppress_checking || (cond) \ 150 (suppress_checking || (cond) \
136 ? (void) 0 \ 151 ? (void) 0 \
137 : die (# cond, __FILE__, __LINE__)) 152 : die (# cond, __FILE__, __LINE__))
153# define eassume(cond) \
154 (suppress_checking \
155 ? assume (cond) \
156 : (cond) \
157 ? (void) 0 \
158 : die (# cond, __FILE__, __LINE__))
138#endif /* ENABLE_CHECKING */ 159#endif /* ENABLE_CHECKING */
139 160
140 161