lib/sod.h: Introduce `SOD_RECKLESS' feature macro to inhibit checking.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 5 Aug 2019 09:26:41 +0000 (10:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 5 Aug 2019 09:26:41 +0000 (10:26 +0100)
Currently there isn't any, but there will be soon.

doc/runtime.tex
doc/sod.sty
lib/sod.3
lib/sod.h

index 46e470e..4f6d277 100644 (file)
@@ -615,6 +615,13 @@ instances and classes inherit from the standard @|SodObject| root object.
 While the translator can (at some effort) support alternative roots, they
 will require different run-time support machinery.
 
+\begin{describe}{feat}{SOD_RECKLESS}
+  Some of Sod's macros include runtime checking by default.  This checking
+  can be disabled if you value performance more than early diagnosis of
+  problems.  Define @|SOD_RECKLESS| to a nonzero value before including
+  @|<sod/sod.h>| to inhibit the runtime checking.
+\end{describe}
+
 
 \subsection{Layout utilities} \label{sec:runtime.object.layout}
 
index 0452348..531fce0 100644 (file)
 \definedescribecategory{ty}{type}
 \definedescribecategory{type}{type}
 \definedescribecategory{mac}{#1{macro}}
+\definedescribecategory{feat}{feature macro}
 \definedescribecategory{lmac}{local #1{macro}}
 \definedescribecategory{parse}{parser spec}
 \definedescribecategory{parseform}{parser form}
index 9f95c78..de46128 100644 (file)
--- a/lib/sod.3
+++ b/lib/sod.3
@@ -147,6 +147,16 @@ instances and classes inherit from the standard
 root object.
 While the translator can (at some effort) support alternative roots,
 they will require different run-time support machinery.
+.PP
+Some of Sod's macros include runtime checking by default.
+This checking can be disabled if you value performance
+more than early diagnosis of problems.
+Define
+.B SOD_RECKLESS
+to a nonzero value
+before including
+.B <sod/sod.h>
+to inhibit the runtime checking.
 .
 .SS Layout utilities
 The following macros are useful in
index 5a14ade..dd1ee03 100644 (file)
--- a/lib/sod.h
+++ b/lib/sod.h
@@ -116,6 +116,22 @@ SOD__VARARGS_MACROS_PREAMBLE
 
 #define SOD__IGNORE(var) ((void)(var))
 
+/* --- @SOD__PARANOIA@ --- *
+ *
+ * Arguments:  @cond@ = a condition to check
+ *             @conseq@ = a thing to evaluate to if the check passes
+ *             @alt@ = a thing to do if the check fails
+ *
+ * Use:                Check to make sure something is good at runtime, unless
+ *             disabled.
+ */
+
+#if SOD_RECKLESS
+#  define SOD__PARANOIA(cond, conseq, alt) (conseq)
+#else
+#  define SOD__PARANOIA(cond, conseq, alt) ((cond) ? (conseq) : (alt))
+#endif
+
 /* --- @SOD__CAR@ --- *
  *
  * Arguments:  @...@ = a nonempty list of arguments