| 1 |
<!DOCTYPE html><html><head> |
| 2 |
<meta charset="UTF-8"> |
| 3 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 4 |
<title>critcl::cutil - C Runtime In Tcl (CriTcl)</title> |
| 5 |
<style type="text/css"><!-- |
| 6 |
HTML { |
| 7 |
background: #FFFFFF; |
| 8 |
color: black; |
| 9 |
} |
| 10 |
BODY { |
| 11 |
background: #FFFFFF; |
| 12 |
color: black; |
| 13 |
} |
| 14 |
DIV.doctools { |
| 15 |
margin-left: 10%; |
| 16 |
margin-right: 10%; |
| 17 |
} |
| 18 |
DIV.doctools H1,DIV.doctools H2 { |
| 19 |
margin-left: -5%; |
| 20 |
} |
| 21 |
H1, H2, H3, H4 { |
| 22 |
margin-top: 1em; |
| 23 |
font-family: sans-serif; |
| 24 |
font-size: large; |
| 25 |
color: #005A9C; |
| 26 |
background: transparent; |
| 27 |
text-align: left; |
| 28 |
} |
| 29 |
H1.doctools_title { |
| 30 |
text-align: center; |
| 31 |
} |
| 32 |
UL,OL { |
| 33 |
margin-right: 0em; |
| 34 |
margin-top: 3pt; |
| 35 |
margin-bottom: 3pt; |
| 36 |
} |
| 37 |
UL LI { |
| 38 |
list-style: disc; |
| 39 |
} |
| 40 |
OL LI { |
| 41 |
list-style: decimal; |
| 42 |
} |
| 43 |
DT { |
| 44 |
padding-top: 1ex; |
| 45 |
} |
| 46 |
UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL { |
| 47 |
font: normal 12pt/14pt sans-serif; |
| 48 |
list-style: none; |
| 49 |
} |
| 50 |
LI.doctools_section, LI.doctools_subsection { |
| 51 |
list-style: none; |
| 52 |
margin-left: 0em; |
| 53 |
text-indent: 0em; |
| 54 |
padding: 0em; |
| 55 |
} |
| 56 |
PRE { |
| 57 |
display: block; |
| 58 |
font-family: monospace; |
| 59 |
white-space: pre; |
| 60 |
margin: 0%; |
| 61 |
padding-top: 0.5ex; |
| 62 |
padding-bottom: 0.5ex; |
| 63 |
padding-left: 1ex; |
| 64 |
padding-right: 1ex; |
| 65 |
width: 100%; |
| 66 |
} |
| 67 |
PRE.doctools_example { |
| 68 |
color: black; |
| 69 |
background: #f5dcb3; |
| 70 |
border: 1px solid black; |
| 71 |
} |
| 72 |
UL.doctools_requirements LI, UL.doctools_syntax LI { |
| 73 |
list-style: none; |
| 74 |
margin-left: 0em; |
| 75 |
text-indent: 0em; |
| 76 |
padding: 0em; |
| 77 |
} |
| 78 |
DIV.doctools_synopsis { |
| 79 |
color: black; |
| 80 |
background: #80ffff; |
| 81 |
border: 1px solid black; |
| 82 |
font-family: serif; |
| 83 |
margin-top: 1em; |
| 84 |
margin-bottom: 1em; |
| 85 |
} |
| 86 |
UL.doctools_syntax { |
| 87 |
margin-top: 1em; |
| 88 |
border-top: 1px solid black; |
| 89 |
} |
| 90 |
UL.doctools_requirements { |
| 91 |
margin-bottom: 1em; |
| 92 |
border-bottom: 1px solid black; |
| 93 |
} |
| 94 |
--></style> |
| 95 |
</head> |
| 96 |
<!-- Generated from file 'critcl_cutil.man' by tcllib/doctools with format 'html' |
| 97 |
--> |
| 98 |
<!-- Copyright &copy; 2011-2024 Andreas Kupries |
| 99 |
--> |
| 100 |
<!-- critcl::cutil.n |
| 101 |
--> |
| 102 |
<body><hr> [ |
| 103 |
<a href="../toc.html">Table Of Contents</a> |
| 104 |
| <a href="../index.html">Keyword Index</a> |
| 105 |
] <hr> |
| 106 |
<div class="doctools"> |
| 107 |
<h1 class="doctools_title">critcl::cutil(n) 0.3 doc "C Runtime In Tcl (CriTcl)"</h1> |
| 108 |
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2> |
| 109 |
<p>critcl::cutil - CriTcl - C-level Utilities</p> |
| 110 |
</div> |
| 111 |
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2> |
| 112 |
<ul class="doctools_toc"> |
| 113 |
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li> |
| 114 |
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li> |
| 115 |
<li class="doctools_section"><a href="#section1">Description</a></li> |
| 116 |
<li class="doctools_section"><a href="#section2">API</a></li> |
| 117 |
<li class="doctools_section"><a href="#section3">Allocation</a></li> |
| 118 |
<li class="doctools_section"><a href="#section4">Assertions</a></li> |
| 119 |
<li class="doctools_section"><a href="#section5">Tracing</a></li> |
| 120 |
<li class="doctools_section"><a href="#section6">Authors</a></li> |
| 121 |
<li class="doctools_section"><a href="#section7">Bugs, Ideas, Feedback</a></li> |
| 122 |
<li class="doctools_section"><a href="#keywords">Keywords</a></li> |
| 123 |
<li class="doctools_section"><a href="#category">Category</a></li> |
| 124 |
<li class="doctools_section"><a href="#copyright">Copyright</a></li> |
| 125 |
</ul> |
| 126 |
</div> |
| 127 |
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2> |
| 128 |
<div class="doctools_synopsis"> |
| 129 |
<ul class="doctools_requirements"> |
| 130 |
<li>package require <b class="pkgname">Tcl 8.6</b></li> |
| 131 |
<li>package require <b class="pkgname">critcl <span class="opt">?3.2?</span></b></li> |
| 132 |
<li>package require <b class="pkgname">critcl::cutil <span class="opt">?0.3?</span></b></li> |
| 133 |
</ul> |
| 134 |
<ul class="doctools_syntax"> |
| 135 |
<li><a href="#1"><b class="cmd">::critcl::cutil::alloc</b></a></li> |
| 136 |
<li><a href="#2"><b class="cmd">::critcl::cutil::assertions</b> <span class="opt">?<i class="arg">enable</i>?</span></a></li> |
| 137 |
<li><a href="#3"><b class="cmd">::critcl::cutil::tracer</b> <span class="opt">?<i class="arg">enable</i>?</span></a></li> |
| 138 |
<li><a href="#4"><b class="cmd">type* ALLOC (type)</b></a></li> |
| 139 |
<li><a href="#5"><b class="cmd">type* ALLOC_PLUS (type, int n)</b></a></li> |
| 140 |
<li><a href="#6"><b class="cmd">type* NALLOC (type, int n)</b></a></li> |
| 141 |
<li><a href="#7"><b class="cmd">type* REALLOC (type* var, type, int n)</b></a></li> |
| 142 |
<li><a href="#8"><b class="cmd">void FREE (type* var)</b></a></li> |
| 143 |
<li><a href="#9"><b class="cmd">void STREP (Tcl_Obj* o, char* s, int len)</b></a></li> |
| 144 |
<li><a href="#10"><b class="cmd">void STREP_DS (Tcl_Obj* o, Tcl_DString* ds)</b></a></li> |
| 145 |
<li><a href="#11"><b class="cmd">void STRDUP (varname, char* str)</b></a></li> |
| 146 |
<li><a href="#12"><b class="cmd">void ASSERT (expression, char* message</b></a></li> |
| 147 |
<li><a href="#13"><b class="cmd">void ASSERT_BOUNDS (int index, int size)</b></a></li> |
| 148 |
<li><a href="#14"><b class="cmd">void STOPAFTER(n)</b></a></li> |
| 149 |
<li><a href="#15"><b class="cmd">TRACE_ON</b></a></li> |
| 150 |
<li><a href="#16"><b class="cmd">TRACE_OFF</b></a></li> |
| 151 |
<li><a href="#17"><b class="cmd">TRACE_TAG_ON (identifier)</b></a></li> |
| 152 |
<li><a href="#18"><b class="cmd">TRACE_TAG_OFF (identifier)</b></a></li> |
| 153 |
<li><a href="#19"><b class="cmd">void TRACE_FUNC</b></a></li> |
| 154 |
<li><a href="#20"><b class="cmd">void TRACE_TAG_FUNC (tag)</b></a></li> |
| 155 |
<li><a href="#21"><b class="cmd">void TRACE_FUNC_VOID</b></a></li> |
| 156 |
<li><a href="#22"><b class="cmd">void TRACE_TAG_FUNC_VOID (tag)</b></a></li> |
| 157 |
<li><a href="#23"><b class="cmd">void TRACE_RETURN_VOID</b></a></li> |
| 158 |
<li><a href="#24"><b class="cmd">void TRACE_TAG_RETURN_VOID (tag)</b></a></li> |
| 159 |
<li><a href="#25"><b class="cmd">any TRACE_RETURN ( char* format, any x)</b></a></li> |
| 160 |
<li><a href="#26"><b class="cmd">any TRACE_TAG_RETURN (tag, char* format, any x)</b></a></li> |
| 161 |
<li><a href="#27"><b class="cmd">void TRACE ( char* format, ...)</b></a></li> |
| 162 |
<li><a href="#28"><b class="cmd">void TRACE_TAG (tag, char* format, ...)</b></a></li> |
| 163 |
<li><a href="#29"><b class="cmd">void TRACE_HEADER (int indent)</b></a></li> |
| 164 |
<li><a href="#30"><b class="cmd">void TRACE_TAG_HEADER (tag, int indent)</b></a></li> |
| 165 |
<li><a href="#31"><b class="cmd">void TRACE_CLOSER</b></a></li> |
| 166 |
<li><a href="#32"><b class="cmd">void TRACE_TAG_CLOSER (tag)</b></a></li> |
| 167 |
<li><a href="#33"><b class="cmd">void TRACE_ADD (const char* format, ...)</b></a></li> |
| 168 |
<li><a href="#34"><b class="cmd">void TRACE_TAG_ADD (tag, const char* format, ...)</b></a></li> |
| 169 |
<li><a href="#35"><b class="cmd">void TRACE_PUSH_SCOPE (const char* name)</b></a></li> |
| 170 |
<li><a href="#36"><b class="cmd">void TRACE_PUSH_FUNC</b></a></li> |
| 171 |
<li><a href="#37"><b class="cmd">void TRACE_PUSH_POP</b></a></li> |
| 172 |
<li><a href="#38"><b class="cmd">TRACE_TAG_VAR (tag)</b></a></li> |
| 173 |
<li><a href="#39"><b class="cmd">TRACE_RUN (code);</b></a></li> |
| 174 |
<li><a href="#40"><b class="cmd">TRACE_DO (code);</b></a></li> |
| 175 |
<li><a href="#41"><b class="cmd">TRACE_TAG_DO (tag, code);</b></a></li> |
| 176 |
</ul> |
| 177 |
</div> |
| 178 |
</div> |
| 179 |
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2> |
| 180 |
<p>Be welcome to the <i class="term">C Runtime In Tcl</i> (short: <i class="term"><a href="critcl.html">CriTcl</a></i>), a system for embedding and using C |
| 181 |
code from within <a href="http://core.tcl-lang.org/tcl">Tcl</a> scripts.</p> |
| 182 |
<p>This document is the reference manpage for the <b class="package">critcl::cutil</b> |
| 183 |
package. This package encapsulates a number of C-level utilites for |
| 184 |
easier writing of memory allocations, assertions, and narrative tracing |
| 185 |
and provides convenience commands to make these utilities accessible |
| 186 |
to critcl projects. |
| 187 |
Its intended audience are mainly developers wishing to write Tcl |
| 188 |
packages with embedded C code.</p> |
| 189 |
<p>This package resides in the Core Package Layer of CriTcl.</p> |
| 190 |
<p><img alt="arch_core" src="../image/arch_core.png"></p> |
| 191 |
<p>The reason for this is that the main <b class="package"><a href="critcl.html">critcl</a></b> package makes |
| 192 |
use of the facilities for narrative tracing when |
| 193 |
<b class="cmd">critcl::config trace</b> is set, to instrument commands and |
| 194 |
procedures.</p> |
| 195 |
</div> |
| 196 |
<div id="section2" class="doctools_section"><h2><a name="section2">API</a></h2> |
| 197 |
<dl class="doctools_definitions"> |
| 198 |
<dt><a name="1"><b class="cmd">::critcl::cutil::alloc</b></a></dt> |
| 199 |
<dd><p>This command provides a number C-preprocessor macros which make the |
| 200 |
writing of memory allocations for structures and arrays of structures |
| 201 |
easier.</p> |
| 202 |
<p>When run the header file "<b class="file">critcl_alloc.h</b>" is directly made |
| 203 |
available to the "<b class="file">.critcl</b>" file containing the command, and |
| 204 |
becomes available for use in <b class="cmd">#include</b> directives of companion |
| 205 |
C code declared via <b class="cmd">critcl::csources</b>.</p> |
| 206 |
<p>The macros definitions and their signatures are:</p> |
| 207 |
<pre class="doctools_example"> |
| 208 |
type* ALLOC (type) |
| 209 |
type* ALLOC_PLUS (type, int n) |
| 210 |
type* NALLOC (type, int n) |
| 211 |
type* REALLOC (type* var, type, int n) |
| 212 |
void FREE (type* var) |
| 213 |
void STREP (Tcl_Obj* o, char* s, int len); |
| 214 |
void STREP_DS (Tcl_Obj* o, Tcl_DString* ds); |
| 215 |
void STRDUP (varname, char* str); |
| 216 |
</pre> |
| 217 |
<p>The details of the semantics are explained in section |
| 218 |
<span class="sectref"><a href="#section3">Allocation</a></span>.</p> |
| 219 |
<p>The result of the command is an empty string.</p></dd> |
| 220 |
<dt><a name="2"><b class="cmd">::critcl::cutil::assertions</b> <span class="opt">?<i class="arg">enable</i>?</span></a></dt> |
| 221 |
<dd><p>This command provides a number C-preprocessor macros for the writing |
| 222 |
of assertions in C code.</p> |
| 223 |
<p>When invoked the header file "<b class="file">critcl_assert.h</b>" is directly |
| 224 |
made available to the "<b class="file">.critcl</b>" file containing the command, and |
| 225 |
becomes available for use in <b class="cmd">#include</b> directives of companion |
| 226 |
C code declared via <b class="cmd">critcl::csources</b>.</p> |
| 227 |
<p>The macro definitions and their signatures are</p> |
| 228 |
<pre class="doctools_example"> |
| 229 |
void ASSERT (expression, char* message); |
| 230 |
void ASSERT_BOUNDS (int index, int size); |
| 231 |
void STOPAFTER (int n); |
| 232 |
</pre> |
| 233 |
<p>Note that these definitions are conditional on the existence of |
| 234 |
the macro <b class="const">CRITCL_ASSERT</b>. |
| 235 |
Without a <b class="cmd">critcl::cflags -DCRITCL_ASSERT</b> all assertions in the |
| 236 |
C code are quiescent and not compiled into the object file. In other |
| 237 |
words, assertions can be (de)activated at will during build time, as |
| 238 |
needed by the user.</p> |
| 239 |
<p>For convenience this is controlled by <i class="arg">enable</i>. By default |
| 240 |
(<b class="const">false</b>) the facility available, but not active. |
| 241 |
Using <b class="const">true</b> not only makes it available, but activates it as |
| 242 |
well.</p> |
| 243 |
<p>The details of the semantics are explained in section |
| 244 |
<span class="sectref"><a href="#section4">Assertions</a></span>.</p> |
| 245 |
<p>The result of the command is an empty string.</p></dd> |
| 246 |
<dt><a name="3"><b class="cmd">::critcl::cutil::tracer</b> <span class="opt">?<i class="arg">enable</i>?</span></a></dt> |
| 247 |
<dd><p>This command provides a number C-preprocessor macros for tracing |
| 248 |
C-level internals.</p> |
| 249 |
<p>When invoked the header file "<b class="file">critcl_trace.h</b>" is directly |
| 250 |
made available to the "<b class="file">.critcl</b>" file containing the command, and |
| 251 |
becomes available for use in <b class="cmd">#include</b> directives of companion |
| 252 |
C code declared via <b class="cmd">critcl::csources</b>. Furthermore the "<b class="file">.c</b>" |
| 253 |
file containing the runtime support is added to the set of C companion |
| 254 |
files</p> |
| 255 |
<p>The macro definitions and their signatures are</p> |
| 256 |
<pre class="doctools_example"> |
| 257 |
/* (de)activation of named logical streams. |
| 258 |
* These are declarators, not statements. |
| 259 |
*/ |
| 260 |
TRACE_ON; |
| 261 |
TRACE_OFF; |
| 262 |
TRACE_TAG_ON (tag_identifier); |
| 263 |
TRACE_TAG_OFF (tag_identifier); |
| 264 |
/* |
| 265 |
* Higher level trace statements (convenience commands) |
| 266 |
*/ |
| 267 |
void TRACE_FUNC (const char* format, ...); |
| 268 |
void TRACE_FUNC_VOID; |
| 269 |
any TRACE_RETURN (const char* format, any x); |
| 270 |
void TRACE_RETURN_VOID; |
| 271 |
void TRACE (const char* format, ...); |
| 272 |
/* |
| 273 |
* Low-level trace statements the higher level ones above |
| 274 |
* are composed from. Scope management and output management. |
| 275 |
*/ |
| 276 |
void TRACE_PUSH_SCOPE (const char* scope); |
| 277 |
void TRACE_PUSH_FUNC; |
| 278 |
void TRACE_POP; |
| 279 |
void TRACE_HEADER (int indent); |
| 280 |
void TRACE_ADD (const char* format, ...); |
| 281 |
void TRACE_CLOSER; |
| 282 |
/* |
| 283 |
* Convert tag to the underlying status variable. |
| 284 |
*/ |
| 285 |
TRACE_TAG_VAR (tag) |
| 286 |
/* |
| 287 |
* Conditional use of arbitrary code. |
| 288 |
*/ |
| 289 |
TRACE_RUN (code); |
| 290 |
TRACE_DO (code); |
| 291 |
TRACE_TAG_DO (code); |
| 292 |
</pre> |
| 293 |
<p>Note that these definitions are conditional on the existence of |
| 294 |
the macro <b class="const">CRITCL_TRACER</b>. |
| 295 |
Without a <b class="cmd">critcl::cflags -DCRITCL_TRACER</b> all trace |
| 296 |
functionality in the C code is quiescent and not compiled into the |
| 297 |
object file. In other words, tracing can be (de)activated at will |
| 298 |
during build time, as needed by the user.</p> |
| 299 |
<p>For convenience this is controlled by <i class="arg">enable</i>. By default |
| 300 |
(<b class="const">false</b>) the facility available, but not active. |
| 301 |
Using <b class="const">true</b> not only makes it available, but activates it as |
| 302 |
well. |
| 303 |
Further note that the command <b class="cmd">critcl::config</b> now accepts a |
| 304 |
boolean option <b class="const">trace</b>. Setting it activates enter/exit tracing |
| 305 |
in all commands based on <b class="cmd">critcl::cproc</b>, with proper printing of |
| 306 |
arguments and results. This implicitly activates the tracing facility |
| 307 |
in general.</p> |
| 308 |
<p>The details of the semantics are explained in section |
| 309 |
<span class="sectref"><a href="#section5">Tracing</a></span></p> |
| 310 |
<p>The result of the command is an empty string.</p></dd> |
| 311 |
</dl> |
| 312 |
</div> |
| 313 |
<div id="section3" class="doctools_section"><h2><a name="section3">Allocation</a></h2> |
| 314 |
<dl class="doctools_definitions"> |
| 315 |
<dt><a name="4"><b class="cmd">type* ALLOC (type)</b></a></dt> |
| 316 |
<dd><p>This macro allocates a single element of the given <i class="arg">type</i> and |
| 317 |
returns a pointer to that memory.</p></dd> |
| 318 |
<dt><a name="5"><b class="cmd">type* ALLOC_PLUS (type, int n)</b></a></dt> |
| 319 |
<dd><p>This macro allocates a single element of the given <i class="arg">type</i>, plus an |
| 320 |
additional <i class="arg">n</i> bytes after the structure and returns a pointer to |
| 321 |
that memory.</p> |
| 322 |
<p>This is for variable-sized structures of. An example of such |
| 323 |
could be a generic list element structure which stores management |
| 324 |
information in the structure itself, and the value/payload immediately |
| 325 |
after, in the same memory block.</p></dd> |
| 326 |
<dt><a name="6"><b class="cmd">type* NALLOC (type, int n)</b></a></dt> |
| 327 |
<dd><p>This macro allocates <i class="arg">n</i> elements of the given <i class="arg">type</i> and |
| 328 |
returns a pointer to that memory.</p></dd> |
| 329 |
<dt><a name="7"><b class="cmd">type* REALLOC (type* var, type, int n)</b></a></dt> |
| 330 |
<dd><p>This macro expands or shrinks the memory associated with the C |
| 331 |
variable <i class="arg">var</i> of type <i class="arg">type</i> to hold <i class="arg">n</i> elements of the |
| 332 |
type. It returns a pointer to that memory. |
| 333 |
Remember, a reallocation may move the data to a new location in memory |
| 334 |
to satisfy the request. Returning a pointer instead of immediately |
| 335 |
assigning it to the <i class="arg">var</i> allows the user to validate the new |
| 336 |
pointer before trying to use it.</p></dd> |
| 337 |
<dt><a name="8"><b class="cmd">void FREE (type* var)</b></a></dt> |
| 338 |
<dd><p>This macro releases the memory referenced by the pointer variable |
| 339 |
<i class="arg">var</i>.</p></dd> |
| 340 |
<dt><a name="9"><b class="cmd">void STREP (Tcl_Obj* o, char* s, int len)</b></a></dt> |
| 341 |
<dd><p>This macro properly sets the string representation of the Tcl object |
| 342 |
<i class="arg">o</i> to a copy of the string <i class="arg">s</i>, expected to be of length |
| 343 |
<i class="arg">len</i>.</p></dd> |
| 344 |
<dt><a name="10"><b class="cmd">void STREP_DS (Tcl_Obj* o, Tcl_DString* ds)</b></a></dt> |
| 345 |
<dd><p>This macro properly sets the string representation of the Tcl object |
| 346 |
<i class="arg">o</i> to a copy of the string held by the <b class="type">DString</b> <i class="arg">ds</i>.</p></dd> |
| 347 |
<dt><a name="11"><b class="cmd">void STRDUP (varname, char* str)</b></a></dt> |
| 348 |
<dd><p>This macro duplicates the string <i class="arg">str</i> into the heap and stores |
| 349 |
the result into the named <b class="type">char*</b> variable <i class="arg">var</i>.</p></dd> |
| 350 |
</dl> |
| 351 |
</div> |
| 352 |
<div id="section4" class="doctools_section"><h2><a name="section4">Assertions</a></h2> |
| 353 |
<dl class="doctools_definitions"> |
| 354 |
<dt><a name="12"><b class="cmd">void ASSERT (expression, char* message</b></a></dt> |
| 355 |
<dd><p>This macro tests the <i class="arg">expression</i> and panics if it does not hold. |
| 356 |
The specified <i class="arg">message</i> is used as part of the panic. |
| 357 |
The <i class="arg">message</i> has to be a static string, it cannot be a variable.</p></dd> |
| 358 |
<dt><a name="13"><b class="cmd">void ASSERT_BOUNDS (int index, int size)</b></a></dt> |
| 359 |
<dd><p>This macro ensures that the <i class="arg">index</i> is in the |
| 360 |
range <b class="const">0</b> to <b class="const">size-1</b>.</p></dd> |
| 361 |
<dt><a name="14"><b class="cmd">void STOPAFTER(n)</b></a></dt> |
| 362 |
<dd><p>This macro throws a panic after it is called <i class="arg">n</i> times. |
| 363 |
Note, each separate instance of the macro has its own counter.</p></dd> |
| 364 |
</dl> |
| 365 |
</div> |
| 366 |
<div id="section5" class="doctools_section"><h2><a name="section5">Tracing</a></h2> |
| 367 |
<p>All output is printed to <b class="const">stdout</b>.</p> |
| 368 |
<dl class="doctools_definitions"> |
| 369 |
<dt><a name="15"><b class="cmd">TRACE_ON</b></a></dt> |
| 370 |
<dd></dd> |
| 371 |
<dt><a name="16"><b class="cmd">TRACE_OFF</b></a></dt> |
| 372 |
<dd></dd> |
| 373 |
<dt><a name="17"><b class="cmd">TRACE_TAG_ON (identifier)</b></a></dt> |
| 374 |
<dd></dd> |
| 375 |
<dt><a name="18"><b class="cmd">TRACE_TAG_OFF (identifier)</b></a></dt> |
| 376 |
<dd><p>These "commands" are actually declarators, for use outside of |
| 377 |
functions. They (de)activate specific logical streams, named either |
| 378 |
explicitly by the user, or implicitly, refering to the current file.</p> |
| 379 |
<p>For example:</p> |
| 380 |
<pre class="doctools_example"> |
| 381 |
TRACE_TAG_ON (lexer_in); |
| 382 |
</pre> |
| 383 |
<p>All high- and low-level trace commands producing output have |
| 384 |
the controlling tag as an implicit argument. The scope management |
| 385 |
commands do not take tags.</p></dd> |
| 386 |
<dt><a name="19"><b class="cmd">void TRACE_FUNC</b></a></dt> |
| 387 |
<dd></dd> |
| 388 |
<dt><a name="20"><b class="cmd">void TRACE_TAG_FUNC (tag)</b></a></dt> |
| 389 |
<dd></dd> |
| 390 |
<dt><a name="21"><b class="cmd">void TRACE_FUNC_VOID</b></a></dt> |
| 391 |
<dd></dd> |
| 392 |
<dt><a name="22"><b class="cmd">void TRACE_TAG_FUNC_VOID (tag)</b></a></dt> |
| 393 |
<dd><p>Use these macros at the beginning of a C function to record entry into |
| 394 |
it. The name of the entered function is an implicit argument |
| 395 |
(<b class="variable">__func__</b>), forcing users to have a C99 compiler..</p> |
| 396 |
<p>The tracer's runtime maintains a stack of active functions and |
| 397 |
expects that function return is signaled by either <b class="function">TRACE_RETURN</b>, |
| 398 |
<b class="function">TRACE_RETURN_VOID</b>, or the equivalent forms taking a tag.</p></dd> |
| 399 |
<dt><a name="23"><b class="cmd">void TRACE_RETURN_VOID</b></a></dt> |
| 400 |
<dd></dd> |
| 401 |
<dt><a name="24"><b class="cmd">void TRACE_TAG_RETURN_VOID (tag)</b></a></dt> |
| 402 |
<dd><p>Use these macros instead of</p> |
| 403 |
<pre class="doctools_example">return</pre> |
| 404 |
<p>to return from a void |
| 405 |
function. Beyond returning from the function this also signals the |
| 406 |
same to the tracer's runtime, popping the last entered function from |
| 407 |
its stack of active functions.</p></dd> |
| 408 |
<dt><a name="25"><b class="cmd">any TRACE_RETURN ( char* format, any x)</b></a></dt> |
| 409 |
<dd></dd> |
| 410 |
<dt><a name="26"><b class="cmd">any TRACE_TAG_RETURN (tag, char* format, any x)</b></a></dt> |
| 411 |
<dd><p>Use this macro instead of</p> |
| 412 |
<pre class="doctools_example">return x</pre> |
| 413 |
<p>to return from a |
| 414 |
non-void function. |
| 415 |
Beyond returning from the function with value <i class="arg">x</i> this also |
| 416 |
signals the same to the tracer's runtime, popping the last entered |
| 417 |
function from its stack of active functions. |
| 418 |
The <i class="arg">format</i> is expected to be a proper formatting string for |
| 419 |
<b class="function">printf</b> and analogues, able to stringify <i class="arg">x</i>.</p></dd> |
| 420 |
<dt><a name="27"><b class="cmd">void TRACE ( char* format, ...)</b></a></dt> |
| 421 |
<dd></dd> |
| 422 |
<dt><a name="28"><b class="cmd">void TRACE_TAG (tag, char* format, ...)</b></a></dt> |
| 423 |
<dd><p>This macro is the trace facilities' equivalent of <b class="function">printf</b>, |
| 424 |
printing arbitrary data under the control of the <i class="arg">format</i>.</p> |
| 425 |
<p>The printed text is closed with a newline, and indented as per |
| 426 |
the stack of active functions.</p></dd> |
| 427 |
<dt><a name="29"><b class="cmd">void TRACE_HEADER (int indent)</b></a></dt> |
| 428 |
<dd></dd> |
| 429 |
<dt><a name="30"><b class="cmd">void TRACE_TAG_HEADER (tag, int indent)</b></a></dt> |
| 430 |
<dd><p>This is the low-level macro which prints the beginning of a trace |
| 431 |
line. This prefix consists of physical location (file name and line |
| 432 |
number), if available, indentation as per the stack of active scopes |
| 433 |
(if activated), and the name of the active scope.</p></dd> |
| 434 |
<dt><a name="31"><b class="cmd">void TRACE_CLOSER</b></a></dt> |
| 435 |
<dd></dd> |
| 436 |
<dt><a name="32"><b class="cmd">void TRACE_TAG_CLOSER (tag)</b></a></dt> |
| 437 |
<dd><p>This is the low-level macro which prints the end of a trace |
| 438 |
line.</p></dd> |
| 439 |
<dt><a name="33"><b class="cmd">void TRACE_ADD (const char* format, ...)</b></a></dt> |
| 440 |
<dd></dd> |
| 441 |
<dt><a name="34"><b class="cmd">void TRACE_TAG_ADD (tag, const char* format, ...)</b></a></dt> |
| 442 |
<dd><p>This is the low-level macro which adds formatted data to the line.</p></dd> |
| 443 |
<dt><a name="35"><b class="cmd">void TRACE_PUSH_SCOPE (const char* name)</b></a></dt> |
| 444 |
<dd></dd> |
| 445 |
<dt><a name="36"><b class="cmd">void TRACE_PUSH_FUNC</b></a></dt> |
| 446 |
<dd></dd> |
| 447 |
<dt><a name="37"><b class="cmd">void TRACE_PUSH_POP</b></a></dt> |
| 448 |
<dd><p>These are the low-level macros for scope management. The first two |
| 449 |
forms push a new scope on the stack of active scopes, and the last |
| 450 |
forms pops the last scope pushed.</p></dd> |
| 451 |
<dt><a name="38"><b class="cmd">TRACE_TAG_VAR (tag)</b></a></dt> |
| 452 |
<dd><p>Helper macro converting from a tag identifier to the name of the |
| 453 |
underlying status variable.</p></dd> |
| 454 |
<dt><a name="39"><b class="cmd">TRACE_RUN (code);</b></a></dt> |
| 455 |
<dd><p>Conditionally insert the <i class="arg">code</i> at compile time when the tracing |
| 456 |
facility is activated.</p></dd> |
| 457 |
<dt><a name="40"><b class="cmd">TRACE_DO (code);</b></a></dt> |
| 458 |
<dd></dd> |
| 459 |
<dt><a name="41"><b class="cmd">TRACE_TAG_DO (tag, code);</b></a></dt> |
| 460 |
<dd><p>Insert the <i class="arg">code</i> at compile time when the tracing facility is |
| 461 |
activated, and execute the same when either the implicit tag for the |
| 462 |
file or the user-specified tag is active.</p></dd> |
| 463 |
</dl> |
| 464 |
</div> |
| 465 |
<div id="section6" class="doctools_section"><h2><a name="section6">Authors</a></h2> |
| 466 |
<p>Andreas Kupries</p> |
| 467 |
</div> |
| 468 |
<div id="section7" class="doctools_section"><h2><a name="section7">Bugs, Ideas, Feedback</a></h2> |
| 469 |
<p>This document, and the package it describes, will undoubtedly contain |
| 470 |
bugs and other problems. |
| 471 |
Please report such at <a href="https://github.com/andreas-kupries/critcl">https://github.com/andreas-kupries/critcl</a>. |
| 472 |
Please also report any ideas for enhancements you may have for either |
| 473 |
package and/or documentation.</p> |
| 474 |
</div> |
| 475 |
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2> |
| 476 |
<p><a href="../index.html#c_code">C code</a>, <a href="../index.html#embedded_c_code">Embedded C Code</a>, <a href="../index.html#code_generator">code generator</a>, <a href="../index.html#compile_run">compile & run</a>, <a href="../index.html#compiler">compiler</a>, <a href="../index.html#dynamic_code_generation">dynamic code generation</a>, <a href="../index.html#dynamic_compilation">dynamic compilation</a>, <a href="../index.html#generate_package">generate package</a>, <a href="../index.html#linker">linker</a>, <a href="../index.html#on_demand_compilation">on demand compilation</a>, <a href="../index.html#on_the_fly_compilation">on-the-fly compilation</a></p> |
| 477 |
</div> |
| 478 |
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2> |
| 479 |
<p>Glueing/Embedded C code</p> |
| 480 |
</div> |
| 481 |
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2> |
| 482 |
<p>Copyright © 2011-2024 Andreas Kupries</p> |
| 483 |
</div> |
| 484 |
</div></body></html> |