From 558e70ee837c7456495f5399c7e62504206ea99b Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 5 Aug 2019 10:26:41 +0100 Subject: [PATCH] lib/sod.h: Introduce `SOD_RECKLESS' feature macro to inhibit checking. Currently there isn't any, but there will be soon. --- doc/runtime.tex | 7 +++++++ doc/sod.sty | 1 + lib/sod.3 | 10 ++++++++++ lib/sod.h | 16 ++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/doc/runtime.tex b/doc/runtime.tex index 46e470e..4f6d277 100644 --- a/doc/runtime.tex +++ b/doc/runtime.tex @@ -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 + @|| to inhibit the runtime checking. +\end{describe} + \subsection{Layout utilities} \label{sec:runtime.object.layout} diff --git a/doc/sod.sty b/doc/sod.sty index 0452348..531fce0 100644 --- a/doc/sod.sty +++ b/doc/sod.sty @@ -215,6 +215,7 @@ \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} diff --git a/lib/sod.3 b/lib/sod.3 index 9f95c78..de46128 100644 --- 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 +to inhibit the runtime checking. . .SS Layout utilities The following macros are useful in diff --git a/lib/sod.h b/lib/sod.h index 5a14ade..dd1ee03 100644 --- 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 -- 2.11.0