| 1 |
'\" |
| 2 |
'\" Generated from file 'critcl_cutil\&.man' by tcllib/doctools with format 'nroff' |
| 3 |
'\" Copyright (c) 2011-2024 Andreas Kupries |
| 4 |
'\" |
| 5 |
.TH "critcl::cutil" n 0\&.3 doc "C Runtime In Tcl (CriTcl)" |
| 6 |
.\" The -*- nroff -*- definitions below are for supplemental macros used |
| 7 |
.\" in Tcl/Tk manual entries. |
| 8 |
.\" |
| 9 |
.\" .AP type name in/out ?indent? |
| 10 |
.\" Start paragraph describing an argument to a library procedure. |
| 11 |
.\" type is type of argument (int, etc.), in/out is either "in", "out", |
| 12 |
.\" or "in/out" to describe whether procedure reads or modifies arg, |
| 13 |
.\" and indent is equivalent to second arg of .IP (shouldn't ever be |
| 14 |
.\" needed; use .AS below instead) |
| 15 |
.\" |
| 16 |
.\" .AS ?type? ?name? |
| 17 |
.\" Give maximum sizes of arguments for setting tab stops. Type and |
| 18 |
.\" name are examples of largest possible arguments that will be passed |
| 19 |
.\" to .AP later. If args are omitted, default tab stops are used. |
| 20 |
.\" |
| 21 |
.\" .BS |
| 22 |
.\" Start box enclosure. From here until next .BE, everything will be |
| 23 |
.\" enclosed in one large box. |
| 24 |
.\" |
| 25 |
.\" .BE |
| 26 |
.\" End of box enclosure. |
| 27 |
.\" |
| 28 |
.\" .CS |
| 29 |
.\" Begin code excerpt. |
| 30 |
.\" |
| 31 |
.\" .CE |
| 32 |
.\" End code excerpt. |
| 33 |
.\" |
| 34 |
.\" .VS ?version? ?br? |
| 35 |
.\" Begin vertical sidebar, for use in marking newly-changed parts |
| 36 |
.\" of man pages. The first argument is ignored and used for recording |
| 37 |
.\" the version when the .VS was added, so that the sidebars can be |
| 38 |
.\" found and removed when they reach a certain age. If another argument |
| 39 |
.\" is present, then a line break is forced before starting the sidebar. |
| 40 |
.\" |
| 41 |
.\" .VE |
| 42 |
.\" End of vertical sidebar. |
| 43 |
.\" |
| 44 |
.\" .DS |
| 45 |
.\" Begin an indented unfilled display. |
| 46 |
.\" |
| 47 |
.\" .DE |
| 48 |
.\" End of indented unfilled display. |
| 49 |
.\" |
| 50 |
.\" .SO ?manpage? |
| 51 |
.\" Start of list of standard options for a Tk widget. The manpage |
| 52 |
.\" argument defines where to look up the standard options; if |
| 53 |
.\" omitted, defaults to "options". The options follow on successive |
| 54 |
.\" lines, in three columns separated by tabs. |
| 55 |
.\" |
| 56 |
.\" .SE |
| 57 |
.\" End of list of standard options for a Tk widget. |
| 58 |
.\" |
| 59 |
.\" .OP cmdName dbName dbClass |
| 60 |
.\" Start of description of a specific option. cmdName gives the |
| 61 |
.\" option's name as specified in the class command, dbName gives |
| 62 |
.\" the option's name in the option database, and dbClass gives |
| 63 |
.\" the option's class in the option database. |
| 64 |
.\" |
| 65 |
.\" .UL arg1 arg2 |
| 66 |
.\" Print arg1 underlined, then print arg2 normally. |
| 67 |
.\" |
| 68 |
.\" .QW arg1 ?arg2? |
| 69 |
.\" Print arg1 in quotes, then arg2 normally (for trailing punctuation). |
| 70 |
.\" |
| 71 |
.\" .PQ arg1 ?arg2? |
| 72 |
.\" Print an open parenthesis, arg1 in quotes, then arg2 normally |
| 73 |
.\" (for trailing punctuation) and then a closing parenthesis. |
| 74 |
.\" |
| 75 |
.\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. |
| 76 |
.if t .wh -1.3i ^B |
| 77 |
.nr ^l \n(.l |
| 78 |
.ad b |
| 79 |
.\" # Start an argument description |
| 80 |
.de AP |
| 81 |
.ie !"\\$4"" .TP \\$4 |
| 82 |
.el \{\ |
| 83 |
. ie !"\\$2"" .TP \\n()Cu |
| 84 |
. el .TP 15 |
| 85 |
.\} |
| 86 |
.ta \\n()Au \\n()Bu |
| 87 |
.ie !"\\$3"" \{\ |
| 88 |
\&\\$1 \\fI\\$2\\fP (\\$3) |
| 89 |
.\".b |
| 90 |
.\} |
| 91 |
.el \{\ |
| 92 |
.br |
| 93 |
.ie !"\\$2"" \{\ |
| 94 |
\&\\$1 \\fI\\$2\\fP |
| 95 |
.\} |
| 96 |
.el \{\ |
| 97 |
\&\\fI\\$1\\fP |
| 98 |
.\} |
| 99 |
.\} |
| 100 |
.. |
| 101 |
.\" # define tabbing values for .AP |
| 102 |
.de AS |
| 103 |
.nr )A 10n |
| 104 |
.if !"\\$1"" .nr )A \\w'\\$1'u+3n |
| 105 |
.nr )B \\n()Au+15n |
| 106 |
.\" |
| 107 |
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n |
| 108 |
.nr )C \\n()Bu+\\w'(in/out)'u+2n |
| 109 |
.. |
| 110 |
.AS Tcl_Interp Tcl_CreateInterp in/out |
| 111 |
.\" # BS - start boxed text |
| 112 |
.\" # ^y = starting y location |
| 113 |
.\" # ^b = 1 |
| 114 |
.de BS |
| 115 |
.br |
| 116 |
.mk ^y |
| 117 |
.nr ^b 1u |
| 118 |
.if n .nf |
| 119 |
.if n .ti 0 |
| 120 |
.if n \l'\\n(.lu\(ul' |
| 121 |
.if n .fi |
| 122 |
.. |
| 123 |
.\" # BE - end boxed text (draw box now) |
| 124 |
.de BE |
| 125 |
.nf |
| 126 |
.ti 0 |
| 127 |
.mk ^t |
| 128 |
.ie n \l'\\n(^lu\(ul' |
| 129 |
.el \{\ |
| 130 |
.\" Draw four-sided box normally, but don't draw top of |
| 131 |
.\" box if the box started on an earlier page. |
| 132 |
.ie !\\n(^b-1 \{\ |
| 133 |
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' |
| 134 |
.\} |
| 135 |
.el \}\ |
| 136 |
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' |
| 137 |
.\} |
| 138 |
.\} |
| 139 |
.fi |
| 140 |
.br |
| 141 |
.nr ^b 0 |
| 142 |
.. |
| 143 |
.\" # VS - start vertical sidebar |
| 144 |
.\" # ^Y = starting y location |
| 145 |
.\" # ^v = 1 (for troff; for nroff this doesn't matter) |
| 146 |
.de VS |
| 147 |
.if !"\\$2"" .br |
| 148 |
.mk ^Y |
| 149 |
.ie n 'mc \s12\(br\s0 |
| 150 |
.el .nr ^v 1u |
| 151 |
.. |
| 152 |
.\" # VE - end of vertical sidebar |
| 153 |
.de VE |
| 154 |
.ie n 'mc |
| 155 |
.el \{\ |
| 156 |
.ev 2 |
| 157 |
.nf |
| 158 |
.ti 0 |
| 159 |
.mk ^t |
| 160 |
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' |
| 161 |
.sp -1 |
| 162 |
.fi |
| 163 |
.ev |
| 164 |
.\} |
| 165 |
.nr ^v 0 |
| 166 |
.. |
| 167 |
.\" # Special macro to handle page bottom: finish off current |
| 168 |
.\" # box/sidebar if in box/sidebar mode, then invoked standard |
| 169 |
.\" # page bottom macro. |
| 170 |
.de ^B |
| 171 |
.ev 2 |
| 172 |
'ti 0 |
| 173 |
'nf |
| 174 |
.mk ^t |
| 175 |
.if \\n(^b \{\ |
| 176 |
.\" Draw three-sided box if this is the box's first page, |
| 177 |
.\" draw two sides but no top otherwise. |
| 178 |
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c |
| 179 |
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c |
| 180 |
.\} |
| 181 |
.if \\n(^v \{\ |
| 182 |
.nr ^x \\n(^tu+1v-\\n(^Yu |
| 183 |
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c |
| 184 |
.\} |
| 185 |
.bp |
| 186 |
'fi |
| 187 |
.ev |
| 188 |
.if \\n(^b \{\ |
| 189 |
.mk ^y |
| 190 |
.nr ^b 2 |
| 191 |
.\} |
| 192 |
.if \\n(^v \{\ |
| 193 |
.mk ^Y |
| 194 |
.\} |
| 195 |
.. |
| 196 |
.\" # DS - begin display |
| 197 |
.de DS |
| 198 |
.RS |
| 199 |
.nf |
| 200 |
.sp |
| 201 |
.. |
| 202 |
.\" # DE - end display |
| 203 |
.de DE |
| 204 |
.fi |
| 205 |
.RE |
| 206 |
.sp |
| 207 |
.. |
| 208 |
.\" # SO - start of list of standard options |
| 209 |
.de SO |
| 210 |
'ie '\\$1'' .ds So \\fBoptions\\fR |
| 211 |
'el .ds So \\fB\\$1\\fR |
| 212 |
.SH "STANDARD OPTIONS" |
| 213 |
.LP |
| 214 |
.nf |
| 215 |
.ta 5.5c 11c |
| 216 |
.ft B |
| 217 |
.. |
| 218 |
.\" # SE - end of list of standard options |
| 219 |
.de SE |
| 220 |
.fi |
| 221 |
.ft R |
| 222 |
.LP |
| 223 |
See the \\*(So manual entry for details on the standard options. |
| 224 |
.. |
| 225 |
.\" # OP - start of full description for a single option |
| 226 |
.de OP |
| 227 |
.LP |
| 228 |
.nf |
| 229 |
.ta 4c |
| 230 |
Command-Line Name: \\fB\\$1\\fR |
| 231 |
Database Name: \\fB\\$2\\fR |
| 232 |
Database Class: \\fB\\$3\\fR |
| 233 |
.fi |
| 234 |
.IP |
| 235 |
.. |
| 236 |
.\" # CS - begin code excerpt |
| 237 |
.de CS |
| 238 |
.RS |
| 239 |
.nf |
| 240 |
.ta .25i .5i .75i 1i |
| 241 |
.. |
| 242 |
.\" # CE - end code excerpt |
| 243 |
.de CE |
| 244 |
.fi |
| 245 |
.RE |
| 246 |
.. |
| 247 |
.\" # UL - underline word |
| 248 |
.de UL |
| 249 |
\\$1\l'|0\(ul'\\$2 |
| 250 |
.. |
| 251 |
.\" # QW - apply quotation marks to word |
| 252 |
.de QW |
| 253 |
.ie '\\*(lq'"' ``\\$1''\\$2 |
| 254 |
.\"" fix emacs highlighting |
| 255 |
.el \\*(lq\\$1\\*(rq\\$2 |
| 256 |
.. |
| 257 |
.\" # PQ - apply parens and quotation marks to word |
| 258 |
.de PQ |
| 259 |
.ie '\\*(lq'"' (``\\$1''\\$2)\\$3 |
| 260 |
.\"" fix emacs highlighting |
| 261 |
.el (\\*(lq\\$1\\*(rq\\$2)\\$3 |
| 262 |
.. |
| 263 |
.\" # QR - quoted range |
| 264 |
.de QR |
| 265 |
.ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3 |
| 266 |
.\"" fix emacs highlighting |
| 267 |
.el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3 |
| 268 |
.. |
| 269 |
.\" # MT - "empty" string |
| 270 |
.de MT |
| 271 |
.QW "" |
| 272 |
.. |
| 273 |
.BS |
| 274 |
.SH NAME |
| 275 |
critcl::cutil \- CriTcl - C-level Utilities |
| 276 |
.SH SYNOPSIS |
| 277 |
package require \fBTcl 8\&.6\fR |
| 278 |
.sp |
| 279 |
package require \fBcritcl ?3\&.2?\fR |
| 280 |
.sp |
| 281 |
package require \fBcritcl::cutil ?0\&.3?\fR |
| 282 |
.sp |
| 283 |
\fB::critcl::cutil::alloc\fR |
| 284 |
.sp |
| 285 |
\fB::critcl::cutil::assertions\fR ?\fIenable\fR? |
| 286 |
.sp |
| 287 |
\fB::critcl::cutil::tracer\fR ?\fIenable\fR? |
| 288 |
.sp |
| 289 |
\fBtype* ALLOC (type)\fR |
| 290 |
.sp |
| 291 |
\fBtype* ALLOC_PLUS (type, int n)\fR |
| 292 |
.sp |
| 293 |
\fBtype* NALLOC (type, int n)\fR |
| 294 |
.sp |
| 295 |
\fBtype* REALLOC (type* var, type, int n)\fR |
| 296 |
.sp |
| 297 |
\fBvoid FREE (type* var)\fR |
| 298 |
.sp |
| 299 |
\fBvoid STREP (Tcl_Obj* o, char* s, int len)\fR |
| 300 |
.sp |
| 301 |
\fBvoid STREP_DS (Tcl_Obj* o, Tcl_DString* ds)\fR |
| 302 |
.sp |
| 303 |
\fBvoid STRDUP (varname, char* str)\fR |
| 304 |
.sp |
| 305 |
\fBvoid ASSERT (expression, char* message\fR |
| 306 |
.sp |
| 307 |
\fBvoid ASSERT_BOUNDS (int index, int size)\fR |
| 308 |
.sp |
| 309 |
\fBvoid STOPAFTER(n)\fR |
| 310 |
.sp |
| 311 |
\fBTRACE_ON\fR |
| 312 |
.sp |
| 313 |
\fBTRACE_OFF\fR |
| 314 |
.sp |
| 315 |
\fBTRACE_TAG_ON (identifier)\fR |
| 316 |
.sp |
| 317 |
\fBTRACE_TAG_OFF (identifier)\fR |
| 318 |
.sp |
| 319 |
\fBvoid TRACE_FUNC\fR |
| 320 |
.sp |
| 321 |
\fBvoid TRACE_TAG_FUNC (tag)\fR |
| 322 |
.sp |
| 323 |
\fBvoid TRACE_FUNC_VOID\fR |
| 324 |
.sp |
| 325 |
\fBvoid TRACE_TAG_FUNC_VOID (tag)\fR |
| 326 |
.sp |
| 327 |
\fBvoid TRACE_RETURN_VOID\fR |
| 328 |
.sp |
| 329 |
\fBvoid TRACE_TAG_RETURN_VOID (tag)\fR |
| 330 |
.sp |
| 331 |
\fBany TRACE_RETURN ( char* format, any x)\fR |
| 332 |
.sp |
| 333 |
\fBany TRACE_TAG_RETURN (tag, char* format, any x)\fR |
| 334 |
.sp |
| 335 |
\fBvoid TRACE ( char* format, \&.\&.\&.)\fR |
| 336 |
.sp |
| 337 |
\fBvoid TRACE_TAG (tag, char* format, \&.\&.\&.)\fR |
| 338 |
.sp |
| 339 |
\fBvoid TRACE_HEADER (int indent)\fR |
| 340 |
.sp |
| 341 |
\fBvoid TRACE_TAG_HEADER (tag, int indent)\fR |
| 342 |
.sp |
| 343 |
\fBvoid TRACE_CLOSER\fR |
| 344 |
.sp |
| 345 |
\fBvoid TRACE_TAG_CLOSER (tag)\fR |
| 346 |
.sp |
| 347 |
\fBvoid TRACE_ADD (const char* format, \&.\&.\&.)\fR |
| 348 |
.sp |
| 349 |
\fBvoid TRACE_TAG_ADD (tag, const char* format, \&.\&.\&.)\fR |
| 350 |
.sp |
| 351 |
\fBvoid TRACE_PUSH_SCOPE (const char* name)\fR |
| 352 |
.sp |
| 353 |
\fBvoid TRACE_PUSH_FUNC\fR |
| 354 |
.sp |
| 355 |
\fBvoid TRACE_PUSH_POP\fR |
| 356 |
.sp |
| 357 |
\fBTRACE_TAG_VAR (tag)\fR |
| 358 |
.sp |
| 359 |
\fBTRACE_RUN (code);\fR |
| 360 |
.sp |
| 361 |
\fBTRACE_DO (code);\fR |
| 362 |
.sp |
| 363 |
\fBTRACE_TAG_DO (tag, code);\fR |
| 364 |
.sp |
| 365 |
.BE |
| 366 |
.SH DESCRIPTION |
| 367 |
.PP |
| 368 |
Be welcome to the \fIC Runtime In Tcl\fR (short: \fICriTcl\fR), a system for embedding and using C |
| 369 |
code from within \fITcl\fR [http://core\&.tcl-lang\&.org/tcl] scripts\&. |
| 370 |
.PP |
| 371 |
This document is the reference manpage for the \fBcritcl::cutil\fR |
| 372 |
package\&. This package encapsulates a number of C-level utilites for |
| 373 |
easier writing of memory allocations, assertions, and narrative tracing |
| 374 |
and provides convenience commands to make these utilities accessible |
| 375 |
to critcl projects\&. |
| 376 |
Its intended audience are mainly developers wishing to write Tcl |
| 377 |
packages with embedded C code\&. |
| 378 |
.PP |
| 379 |
This package resides in the Core Package Layer of CriTcl\&. |
| 380 |
.PP |
| 381 |
.PS |
| 382 |
.nf |
| 383 |
+----------------+ |
| 384 |
|Applications | |
| 385 |
| critcl | |
| 386 |
| critcl::app | |
| 387 |
+----------------+ |
| 388 |
|
| 389 |
*================* |
| 390 |
|Core Packages | |
| 391 |
| critcl | |
| 392 |
| critcl::util | |
| 393 |
*================* |
| 394 |
|
| 395 |
+----------------+ |
| 396 |
|Support Packages| |
| 397 |
| stubs::* | |
| 398 |
| md5, platform | |
| 399 |
| \&.\&.\&. | |
| 400 |
+----------------+ |
| 401 |
|
| 402 |
.fi |
| 403 |
.PE |
| 404 |
.PP |
| 405 |
The reason for this is that the main \fBcritcl\fR package makes |
| 406 |
use of the facilities for narrative tracing when |
| 407 |
\fBcritcl::config trace\fR is set, to instrument commands and |
| 408 |
procedures\&. |
| 409 |
.SH API |
| 410 |
.TP |
| 411 |
\fB::critcl::cutil::alloc\fR |
| 412 |
This command provides a number C-preprocessor macros which make the |
| 413 |
writing of memory allocations for structures and arrays of structures |
| 414 |
easier\&. |
| 415 |
.sp |
| 416 |
When run the header file "\fIcritcl_alloc\&.h\fR" is directly made |
| 417 |
available to the "\fI\&.critcl\fR" file containing the command, and |
| 418 |
becomes available for use in \fB#include\fR directives of companion |
| 419 |
C code declared via \fBcritcl::csources\fR\&. |
| 420 |
.sp |
| 421 |
The macros definitions and their signatures are: |
| 422 |
.CS |
| 423 |
|
| 424 |
|
| 425 |
type* ALLOC (type) |
| 426 |
type* ALLOC_PLUS (type, int n) |
| 427 |
type* NALLOC (type, int n) |
| 428 |
type* REALLOC (type* var, type, int n) |
| 429 |
void FREE (type* var) |
| 430 |
|
| 431 |
void STREP (Tcl_Obj* o, char* s, int len); |
| 432 |
void STREP_DS (Tcl_Obj* o, Tcl_DString* ds); |
| 433 |
void STRDUP (varname, char* str); |
| 434 |
|
| 435 |
.CE |
| 436 |
.sp |
| 437 |
The details of the semantics are explained in section |
| 438 |
\fBAllocation\fR\&. |
| 439 |
.sp |
| 440 |
The result of the command is an empty string\&. |
| 441 |
.TP |
| 442 |
\fB::critcl::cutil::assertions\fR ?\fIenable\fR? |
| 443 |
This command provides a number C-preprocessor macros for the writing |
| 444 |
of assertions in C code\&. |
| 445 |
.sp |
| 446 |
When invoked the header file "\fIcritcl_assert\&.h\fR" is directly |
| 447 |
made available to the "\fI\&.critcl\fR" file containing the command, and |
| 448 |
becomes available for use in \fB#include\fR directives of companion |
| 449 |
C code declared via \fBcritcl::csources\fR\&. |
| 450 |
.sp |
| 451 |
The macro definitions and their signatures are |
| 452 |
.CS |
| 453 |
|
| 454 |
|
| 455 |
void ASSERT (expression, char* message); |
| 456 |
void ASSERT_BOUNDS (int index, int size); |
| 457 |
|
| 458 |
void STOPAFTER (int n); |
| 459 |
|
| 460 |
.CE |
| 461 |
.sp |
| 462 |
Note that these definitions are conditional on the existence of |
| 463 |
the macro \fBCRITCL_ASSERT\fR\&. |
| 464 |
Without a \fBcritcl::cflags -DCRITCL_ASSERT\fR all assertions in the |
| 465 |
C code are quiescent and not compiled into the object file\&. In other |
| 466 |
words, assertions can be (de)activated at will during build time, as |
| 467 |
needed by the user\&. |
| 468 |
.sp |
| 469 |
For convenience this is controlled by \fIenable\fR\&. By default |
| 470 |
(\fBfalse\fR) the facility available, but not active\&. |
| 471 |
Using \fBtrue\fR not only makes it available, but activates it as |
| 472 |
well\&. |
| 473 |
.sp |
| 474 |
The details of the semantics are explained in section |
| 475 |
\fBAssertions\fR\&. |
| 476 |
.sp |
| 477 |
The result of the command is an empty string\&. |
| 478 |
.TP |
| 479 |
\fB::critcl::cutil::tracer\fR ?\fIenable\fR? |
| 480 |
This command provides a number C-preprocessor macros for tracing |
| 481 |
C-level internals\&. |
| 482 |
.sp |
| 483 |
When invoked the header file "\fIcritcl_trace\&.h\fR" is directly |
| 484 |
made available to the "\fI\&.critcl\fR" file containing the command, and |
| 485 |
becomes available for use in \fB#include\fR directives of companion |
| 486 |
C code declared via \fBcritcl::csources\fR\&. Furthermore the "\fI\&.c\fR" |
| 487 |
file containing the runtime support is added to the set of C companion |
| 488 |
files |
| 489 |
.sp |
| 490 |
The macro definitions and their signatures are |
| 491 |
.CS |
| 492 |
|
| 493 |
|
| 494 |
/* (de)activation of named logical streams\&. |
| 495 |
* These are declarators, not statements\&. |
| 496 |
*/ |
| 497 |
|
| 498 |
TRACE_ON; |
| 499 |
TRACE_OFF; |
| 500 |
TRACE_TAG_ON (tag_identifier); |
| 501 |
TRACE_TAG_OFF (tag_identifier); |
| 502 |
|
| 503 |
/* |
| 504 |
* Higher level trace statements (convenience commands) |
| 505 |
*/ |
| 506 |
|
| 507 |
void TRACE_FUNC (const char* format, \&.\&.\&.); |
| 508 |
void TRACE_FUNC_VOID; |
| 509 |
any TRACE_RETURN (const char* format, any x); |
| 510 |
void TRACE_RETURN_VOID; |
| 511 |
void TRACE (const char* format, \&.\&.\&.); |
| 512 |
|
| 513 |
/* |
| 514 |
* Low-level trace statements the higher level ones above |
| 515 |
* are composed from\&. Scope management and output management\&. |
| 516 |
*/ |
| 517 |
|
| 518 |
void TRACE_PUSH_SCOPE (const char* scope); |
| 519 |
void TRACE_PUSH_FUNC; |
| 520 |
void TRACE_POP; |
| 521 |
|
| 522 |
void TRACE_HEADER (int indent); |
| 523 |
void TRACE_ADD (const char* format, \&.\&.\&.); |
| 524 |
void TRACE_CLOSER; |
| 525 |
|
| 526 |
/* |
| 527 |
* Convert tag to the underlying status variable\&. |
| 528 |
*/ |
| 529 |
|
| 530 |
TRACE_TAG_VAR (tag) |
| 531 |
|
| 532 |
/* |
| 533 |
* Conditional use of arbitrary code\&. |
| 534 |
*/ |
| 535 |
|
| 536 |
TRACE_RUN (code); |
| 537 |
TRACE_DO (code); |
| 538 |
TRACE_TAG_DO (code); |
| 539 |
|
| 540 |
.CE |
| 541 |
.sp |
| 542 |
Note that these definitions are conditional on the existence of |
| 543 |
the macro \fBCRITCL_TRACER\fR\&. |
| 544 |
Without a \fBcritcl::cflags -DCRITCL_TRACER\fR all trace |
| 545 |
functionality in the C code is quiescent and not compiled into the |
| 546 |
object file\&. In other words, tracing can be (de)activated at will |
| 547 |
during build time, as needed by the user\&. |
| 548 |
.sp |
| 549 |
For convenience this is controlled by \fIenable\fR\&. By default |
| 550 |
(\fBfalse\fR) the facility available, but not active\&. |
| 551 |
Using \fBtrue\fR not only makes it available, but activates it as |
| 552 |
well\&. |
| 553 |
Further note that the command \fBcritcl::config\fR now accepts a |
| 554 |
boolean option \fBtrace\fR\&. Setting it activates enter/exit tracing |
| 555 |
in all commands based on \fBcritcl::cproc\fR, with proper printing of |
| 556 |
arguments and results\&. This implicitly activates the tracing facility |
| 557 |
in general\&. |
| 558 |
.sp |
| 559 |
The details of the semantics are explained in section |
| 560 |
\fBTracing\fR |
| 561 |
.sp |
| 562 |
The result of the command is an empty string\&. |
| 563 |
.PP |
| 564 |
.SH ALLOCATION |
| 565 |
.TP |
| 566 |
\fBtype* ALLOC (type)\fR |
| 567 |
This macro allocates a single element of the given \fItype\fR and |
| 568 |
returns a pointer to that memory\&. |
| 569 |
.TP |
| 570 |
\fBtype* ALLOC_PLUS (type, int n)\fR |
| 571 |
This macro allocates a single element of the given \fItype\fR, plus an |
| 572 |
additional \fIn\fR bytes after the structure and returns a pointer to |
| 573 |
that memory\&. |
| 574 |
.sp |
| 575 |
This is for variable-sized structures of\&. An example of such |
| 576 |
could be a generic list element structure which stores management |
| 577 |
information in the structure itself, and the value/payload immediately |
| 578 |
after, in the same memory block\&. |
| 579 |
.TP |
| 580 |
\fBtype* NALLOC (type, int n)\fR |
| 581 |
This macro allocates \fIn\fR elements of the given \fItype\fR and |
| 582 |
returns a pointer to that memory\&. |
| 583 |
.TP |
| 584 |
\fBtype* REALLOC (type* var, type, int n)\fR |
| 585 |
This macro expands or shrinks the memory associated with the C |
| 586 |
variable \fIvar\fR of type \fItype\fR to hold \fIn\fR elements of the |
| 587 |
type\&. It returns a pointer to that memory\&. |
| 588 |
Remember, a reallocation may move the data to a new location in memory |
| 589 |
to satisfy the request\&. Returning a pointer instead of immediately |
| 590 |
assigning it to the \fIvar\fR allows the user to validate the new |
| 591 |
pointer before trying to use it\&. |
| 592 |
.TP |
| 593 |
\fBvoid FREE (type* var)\fR |
| 594 |
This macro releases the memory referenced by the pointer variable |
| 595 |
\fIvar\fR\&. |
| 596 |
.TP |
| 597 |
\fBvoid STREP (Tcl_Obj* o, char* s, int len)\fR |
| 598 |
This macro properly sets the string representation of the Tcl object |
| 599 |
\fIo\fR to a copy of the string \fIs\fR, expected to be of length |
| 600 |
\fIlen\fR\&. |
| 601 |
.TP |
| 602 |
\fBvoid STREP_DS (Tcl_Obj* o, Tcl_DString* ds)\fR |
| 603 |
This macro properly sets the string representation of the Tcl object |
| 604 |
\fIo\fR to a copy of the string held by the \fBDString\fR \fIds\fR\&. |
| 605 |
.TP |
| 606 |
\fBvoid STRDUP (varname, char* str)\fR |
| 607 |
This macro duplicates the string \fIstr\fR into the heap and stores |
| 608 |
the result into the named \fBchar*\fR variable \fIvar\fR\&. |
| 609 |
.PP |
| 610 |
.SH ASSERTIONS |
| 611 |
.TP |
| 612 |
\fBvoid ASSERT (expression, char* message\fR |
| 613 |
This macro tests the \fIexpression\fR and panics if it does not hold\&. |
| 614 |
The specified \fImessage\fR is used as part of the panic\&. |
| 615 |
The \fImessage\fR has to be a static string, it cannot be a variable\&. |
| 616 |
.TP |
| 617 |
\fBvoid ASSERT_BOUNDS (int index, int size)\fR |
| 618 |
This macro ensures that the \fIindex\fR is in the |
| 619 |
range \fB0\fR to \fBsize-1\fR\&. |
| 620 |
.TP |
| 621 |
\fBvoid STOPAFTER(n)\fR |
| 622 |
This macro throws a panic after it is called \fIn\fR times\&. |
| 623 |
Note, each separate instance of the macro has its own counter\&. |
| 624 |
.PP |
| 625 |
.SH TRACING |
| 626 |
All output is printed to \fBstdout\fR\&. |
| 627 |
.TP |
| 628 |
\fBTRACE_ON\fR |
| 629 |
.TP |
| 630 |
\fBTRACE_OFF\fR |
| 631 |
.TP |
| 632 |
\fBTRACE_TAG_ON (identifier)\fR |
| 633 |
.TP |
| 634 |
\fBTRACE_TAG_OFF (identifier)\fR |
| 635 |
These "commands" are actually declarators, for use outside of |
| 636 |
functions\&. They (de)activate specific logical streams, named either |
| 637 |
explicitly by the user, or implicitly, refering to the current file\&. |
| 638 |
.sp |
| 639 |
For example: |
| 640 |
.sp |
| 641 |
.CS |
| 642 |
|
| 643 |
|
| 644 |
TRACE_TAG_ON (lexer_in); |
| 645 |
|
| 646 |
.CE |
| 647 |
.sp |
| 648 |
All high- and low-level trace commands producing output have |
| 649 |
the controlling tag as an implicit argument\&. The scope management |
| 650 |
commands do not take tags\&. |
| 651 |
.TP |
| 652 |
\fBvoid TRACE_FUNC\fR |
| 653 |
.TP |
| 654 |
\fBvoid TRACE_TAG_FUNC (tag)\fR |
| 655 |
.TP |
| 656 |
\fBvoid TRACE_FUNC_VOID\fR |
| 657 |
.TP |
| 658 |
\fBvoid TRACE_TAG_FUNC_VOID (tag)\fR |
| 659 |
Use these macros at the beginning of a C function to record entry into |
| 660 |
it\&. The name of the entered function is an implicit argument |
| 661 |
(\fB__func__\fR), forcing users to have a C99 compiler\&.\&. |
| 662 |
.sp |
| 663 |
The tracer's runtime maintains a stack of active functions and |
| 664 |
expects that function return is signaled by either \fBTRACE_RETURN\fR, |
| 665 |
\fBTRACE_RETURN_VOID\fR, or the equivalent forms taking a tag\&. |
| 666 |
.TP |
| 667 |
\fBvoid TRACE_RETURN_VOID\fR |
| 668 |
.TP |
| 669 |
\fBvoid TRACE_TAG_RETURN_VOID (tag)\fR |
| 670 |
Use these macros instead of |
| 671 |
.CS |
| 672 |
|
| 673 |
return |
| 674 |
.CE |
| 675 |
.IP to return from a void |
| 676 |
function\&. Beyond returning from the function this also signals the |
| 677 |
same to the tracer's runtime, popping the last entered function from |
| 678 |
its stack of active functions\&. |
| 679 |
.TP |
| 680 |
\fBany TRACE_RETURN ( char* format, any x)\fR |
| 681 |
.TP |
| 682 |
\fBany TRACE_TAG_RETURN (tag, char* format, any x)\fR |
| 683 |
Use this macro instead of |
| 684 |
.CS |
| 685 |
|
| 686 |
return x |
| 687 |
.CE |
| 688 |
.IP to return from a |
| 689 |
non-void function\&. |
| 690 |
Beyond returning from the function with value \fIx\fR this also |
| 691 |
signals the same to the tracer's runtime, popping the last entered |
| 692 |
function from its stack of active functions\&. |
| 693 |
The \fIformat\fR is expected to be a proper formatting string for |
| 694 |
\fBprintf\fR and analogues, able to stringify \fIx\fR\&. |
| 695 |
.TP |
| 696 |
\fBvoid TRACE ( char* format, \&.\&.\&.)\fR |
| 697 |
.TP |
| 698 |
\fBvoid TRACE_TAG (tag, char* format, \&.\&.\&.)\fR |
| 699 |
This macro is the trace facilities' equivalent of \fBprintf\fR, |
| 700 |
printing arbitrary data under the control of the \fIformat\fR\&. |
| 701 |
.sp |
| 702 |
The printed text is closed with a newline, and indented as per |
| 703 |
the stack of active functions\&. |
| 704 |
.TP |
| 705 |
\fBvoid TRACE_HEADER (int indent)\fR |
| 706 |
.TP |
| 707 |
\fBvoid TRACE_TAG_HEADER (tag, int indent)\fR |
| 708 |
This is the low-level macro which prints the beginning of a trace |
| 709 |
line\&. This prefix consists of physical location (file name and line |
| 710 |
number), if available, indentation as per the stack of active scopes |
| 711 |
(if activated), and the name of the active scope\&. |
| 712 |
.TP |
| 713 |
\fBvoid TRACE_CLOSER\fR |
| 714 |
.TP |
| 715 |
\fBvoid TRACE_TAG_CLOSER (tag)\fR |
| 716 |
This is the low-level macro which prints the end of a trace |
| 717 |
line\&. |
| 718 |
.TP |
| 719 |
\fBvoid TRACE_ADD (const char* format, \&.\&.\&.)\fR |
| 720 |
.TP |
| 721 |
\fBvoid TRACE_TAG_ADD (tag, const char* format, \&.\&.\&.)\fR |
| 722 |
This is the low-level macro which adds formatted data to the line\&. |
| 723 |
.TP |
| 724 |
\fBvoid TRACE_PUSH_SCOPE (const char* name)\fR |
| 725 |
.TP |
| 726 |
\fBvoid TRACE_PUSH_FUNC\fR |
| 727 |
.TP |
| 728 |
\fBvoid TRACE_PUSH_POP\fR |
| 729 |
These are the low-level macros for scope management\&. The first two |
| 730 |
forms push a new scope on the stack of active scopes, and the last |
| 731 |
forms pops the last scope pushed\&. |
| 732 |
.TP |
| 733 |
\fBTRACE_TAG_VAR (tag)\fR |
| 734 |
Helper macro converting from a tag identifier to the name of the |
| 735 |
underlying status variable\&. |
| 736 |
.TP |
| 737 |
\fBTRACE_RUN (code);\fR |
| 738 |
Conditionally insert the \fIcode\fR at compile time when the tracing |
| 739 |
facility is activated\&. |
| 740 |
.TP |
| 741 |
\fBTRACE_DO (code);\fR |
| 742 |
.TP |
| 743 |
\fBTRACE_TAG_DO (tag, code);\fR |
| 744 |
Insert the \fIcode\fR at compile time when the tracing facility is |
| 745 |
activated, and execute the same when either the implicit tag for the |
| 746 |
file or the user-specified tag is active\&. |
| 747 |
.PP |
| 748 |
.SH AUTHORS |
| 749 |
Andreas Kupries |
| 750 |
.SH "BUGS, IDEAS, FEEDBACK" |
| 751 |
This document, and the package it describes, will undoubtedly contain |
| 752 |
bugs and other problems\&. |
| 753 |
Please report such at \fIhttps://github\&.com/andreas-kupries/critcl\fR\&. |
| 754 |
Please also report any ideas for enhancements you may have for either |
| 755 |
package and/or documentation\&. |
| 756 |
.SH KEYWORDS |
| 757 |
C code, Embedded C Code, code generator, compile & run, compiler, dynamic code generation, dynamic compilation, generate package, linker, on demand compilation, on-the-fly compilation |
| 758 |
.SH CATEGORY |
| 759 |
Glueing/Embedded C code |
| 760 |
.SH COPYRIGHT |
| 761 |
.nf |
| 762 |
Copyright (c) 2011-2024 Andreas Kupries |
| 763 |
|
| 764 |
.fi |