1 /*
2  * tclInt.h --
3  *
4  *	Declarations of things used internally by the Tcl interpreter.
5  *
6  * Copyright (c) 1987-1993 The Regents of the University of California.
7  * Copyright (c) 1993-1997 Lucent Technologies.
8  * Copyright (c) 1994-1998 Sun Microsystems, Inc.
9  * Copyright (c) 1998-1999 by Scriptics Corporation.
10  * Copyright (c) 2001, 2002 by Kevin B. Kenny.  All rights reserved.
11  * Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net>
12  * Copyright (c) 2006-2008 by Joe Mistachkin.  All rights reserved.
13  * Copyright (c) 2008 by Miguel Sofer. All rights reserved.
14  *
15  * See the file "license.terms" for information on usage and redistribution of
16  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
17  */
18 
19 #ifndef _TCLINT
20 #define _TCLINT
21 
22 /*
23  * Some numerics configuration options.
24  */
25 
26 #undef ACCEPT_NAN
27 
28 /*
29  * Common include files needed by most of the Tcl source files are included
30  * here, so that system-dependent personalizations for the include files only
31  * have to be made in once place. This results in a few extra includes, but
32  * greater modularity. The order of the three groups of #includes is
33  * important. For example, stdio.h is needed by tcl.h.
34  */
35 
36 #include "tclPort.h"
37 
38 #include <stdio.h>
39 
40 #include <ctype.h>
41 #ifdef NO_STDLIB_H
42 #   include "../compat/stdlib.h"
43 #else
44 #   include <stdlib.h>
45 #endif
46 #ifdef NO_STRING_H
47 #include "../compat/string.h"
48 #else
49 #include <string.h>
50 #endif
51 #if defined(STDC_HEADERS) || defined(__STDC__) || defined(__C99__FUNC__) \
52      || defined(__cplusplus) || defined(_MSC_VER) || defined(__ICC)
53 #include <stddef.h>
54 #else
55 typedef int ptrdiff_t;
56 #endif
57 
58 /*
59  * Ensure WORDS_BIGENDIAN is defined correctly:
60  * Needs to happen here in addition to configure to work with fat compiles on
61  * Darwin (where configure runs only once for multiple architectures).
62  */
63 
64 #ifdef HAVE_SYS_TYPES_H
65 #    include <sys/types.h>
66 #endif
67 #ifdef HAVE_SYS_PARAM_H
68 #    include <sys/param.h>
69 #endif
70 #ifdef BYTE_ORDER
71 #    ifdef BIG_ENDIAN
72 #	 if BYTE_ORDER == BIG_ENDIAN
73 #	     undef WORDS_BIGENDIAN
74 #	     define WORDS_BIGENDIAN 1
75 #	 endif
76 #    endif
77 #    ifdef LITTLE_ENDIAN
78 #	 if BYTE_ORDER == LITTLE_ENDIAN
79 #	     undef WORDS_BIGENDIAN
80 #	 endif
81 #    endif
82 #endif
83 
84 /*
85  * Used to tag functions that are only to be visible within the module being
86  * built and not outside it (where this is supported by the linker).
87  */
88 
89 #ifndef MODULE_SCOPE
90 #   ifdef __cplusplus
91 #	define MODULE_SCOPE extern "C"
92 #   else
93 #	define MODULE_SCOPE extern
94 #   endif
95 #endif
96 
97 /*
98  * Macros used to cast between pointers and integers (e.g. when storing an int
99  * in ClientData), on 64-bit architectures they avoid gcc warning about "cast
100  * to/from pointer from/to integer of different size".
101  */
102 
103 #if !defined(INT2PTR) && !defined(PTR2INT)
104 #   if defined(HAVE_INTPTR_T) || defined(intptr_t)
105 #	define INT2PTR(p) ((void *)(intptr_t)(p))
106 #	define PTR2INT(p) ((int)(intptr_t)(p))
107 #   else
108 #	define INT2PTR(p) ((void *)(p))
109 #	define PTR2INT(p) ((int)(p))
110 #   endif
111 #endif
112 #if !defined(UINT2PTR) && !defined(PTR2UINT)
113 #   if defined(HAVE_UINTPTR_T) || defined(uintptr_t)
114 #	define UINT2PTR(p) ((void *)(uintptr_t)(p))
115 #	define PTR2UINT(p) ((unsigned int)(uintptr_t)(p))
116 #   else
117 #	define UINT2PTR(p) ((void *)(p))
118 #	define PTR2UINT(p) ((unsigned int)(p))
119 #   endif
120 #endif
121 
122 #if defined(_WIN32) && defined(_MSC_VER)
123 #   define vsnprintf _vsnprintf
124 #endif
125 
126 /*
127  * The following procedures allow namespaces to be customized to support
128  * special name resolution rules for commands/variables.
129  */
130 
131 struct Tcl_ResolvedVarInfo;
132 
133 typedef Tcl_Var (Tcl_ResolveRuntimeVarProc)(Tcl_Interp *interp,
134 	struct Tcl_ResolvedVarInfo *vinfoPtr);
135 
136 typedef void (Tcl_ResolveVarDeleteProc)(struct Tcl_ResolvedVarInfo *vinfoPtr);
137 
138 /*
139  * The following structure encapsulates the routines needed to resolve a
140  * variable reference at runtime. Any variable specific state will typically
141  * be appended to this structure.
142  */
143 
144 typedef struct Tcl_ResolvedVarInfo {
145     Tcl_ResolveRuntimeVarProc *fetchProc;
146     Tcl_ResolveVarDeleteProc *deleteProc;
147 } Tcl_ResolvedVarInfo;
148 
149 typedef int (Tcl_ResolveCompiledVarProc)(Tcl_Interp *interp,
150 	CONST84 char *name, int length, Tcl_Namespace *context,
151 	Tcl_ResolvedVarInfo **rPtr);
152 
153 typedef int (Tcl_ResolveVarProc)(Tcl_Interp *interp, CONST84 char *name,
154 	Tcl_Namespace *context, int flags, Tcl_Var *rPtr);
155 
156 typedef int (Tcl_ResolveCmdProc)(Tcl_Interp *interp, CONST84 char *name,
157 	Tcl_Namespace *context, int flags, Tcl_Command *rPtr);
158 
159 typedef struct Tcl_ResolverInfo {
160     Tcl_ResolveCmdProc *cmdResProc;
161 				/* Procedure handling command name
162 				 * resolution. */
163     Tcl_ResolveVarProc *varResProc;
164 				/* Procedure handling variable name resolution
165 				 * for variables that can only be handled at
166 				 * runtime. */
167     Tcl_ResolveCompiledVarProc *compiledVarResProc;
168 				/* Procedure handling variable name resolution
169 				 * at compile time. */
170 } Tcl_ResolverInfo;
171 
172 /*
173  * This flag bit should not interfere with TCL_GLOBAL_ONLY,
174  * TCL_NAMESPACE_ONLY, or TCL_LEAVE_ERR_MSG; it signals that the variable
175  * lookup is performed for upvar (or similar) purposes, with slightly
176  * different rules:
177  *    - Bug #696893 - variable is either proc-local or in the current
178  *	namespace; never follow the second (global) resolution path
179  *    - Bug #631741 - do not use special namespace or interp resolvers
180  *
181  * It should also not collide with the (deprecated) TCL_PARSE_PART1 flag
182  * (Bug #835020)
183  */
184 
185 #define TCL_AVOID_RESOLVERS 0x40000
186 
187 /*
188  *----------------------------------------------------------------
189  * Data structures related to namespaces.
190  *----------------------------------------------------------------
191  */
192 
193 typedef struct Tcl_Ensemble Tcl_Ensemble;
194 typedef struct NamespacePathEntry NamespacePathEntry;
195 
196 /*
197  * Special hashtable for variables: this is just a Tcl_HashTable with an nsPtr
198  * field added at the end: in this way variables can find their namespace
199  * without having to copy a pointer in their struct: they can access it via
200  * their hPtr->tablePtr.
201  */
202 
203 typedef struct TclVarHashTable {
204     Tcl_HashTable table;
205     struct Namespace *nsPtr;
206 } TclVarHashTable;
207 
208 /*
209  * This is for itcl - it likes to search our varTables directly :(
210  */
211 
212 #define TclVarHashFindVar(tablePtr, key) \
213     TclVarHashCreateVar((tablePtr), (key), NULL)
214 
215 /*
216  * Define this to reduce the amount of space that the average namespace
217  * consumes by only allocating the table of child namespaces when necessary.
218  * Defining it breaks compatibility for Tcl extensions (e.g., itcl) which
219  * reach directly into the Namespace structure.
220  */
221 
222 #undef BREAK_NAMESPACE_COMPAT
223 
224 /*
225  * The structure below defines a namespace.
226  * Note: the first five fields must match exactly the fields in a
227  * Tcl_Namespace structure (see tcl.h). If you change one, be sure to change
228  * the other.
229  */
230 
231 typedef struct Namespace {
232     char *name;			/* The namespace's simple (unqualified) name.
233 				 * This contains no ::'s. The name of the
234 				 * global namespace is "" although "::" is an
235 				 * synonym. */
236     char *fullName;		/* The namespace's fully qualified name. This
237 				 * starts with ::. */
238     ClientData clientData;	/* An arbitrary value associated with this
239 				 * namespace. */
240     Tcl_NamespaceDeleteProc *deleteProc;
241 				/* Procedure invoked when deleting the
242 				 * namespace to, e.g., free clientData. */
243     struct Namespace *parentPtr;/* Points to the namespace that contains this
244 				 * one. NULL if this is the global
245 				 * namespace. */
246 #ifndef BREAK_NAMESPACE_COMPAT
247     Tcl_HashTable childTable;	/* Contains any child namespaces. Indexed by
248 				 * strings; values have type (Namespace *). */
249 #else
250     Tcl_HashTable *childTablePtr;
251 				/* Contains any child namespaces. Indexed by
252 				 * strings; values have type (Namespace *). If
253 				 * NULL, there are no children. */
254 #endif
255     long nsId;			/* Unique id for the namespace. */
256     Tcl_Interp *interp;		/* The interpreter containing this
257 				 * namespace. */
258     int flags;			/* OR-ed combination of the namespace status
259 				 * flags NS_DYING and NS_DEAD listed below. */
260     int activationCount;	/* Number of "activations" or active call
261 				 * frames for this namespace that are on the
262 				 * Tcl call stack. The namespace won't be
263 				 * freed until activationCount becomes zero. */
264     int refCount;		/* Count of references by namespaceName
265 				 * objects. The namespace can't be freed until
266 				 * refCount becomes zero. */
267     Tcl_HashTable cmdTable;	/* Contains all the commands currently
268 				 * registered in the namespace. Indexed by
269 				 * strings; values have type (Command *).
270 				 * Commands imported by Tcl_Import have
271 				 * Command structures that point (via an
272 				 * ImportedCmdRef structure) to the Command
273 				 * structure in the source namespace's command
274 				 * table. */
275     TclVarHashTable varTable;	/* Contains all the (global) variables
276 				 * currently in this namespace. Indexed by
277 				 * strings; values have type (Var *). */
278     char **exportArrayPtr;	/* Points to an array of string patterns
279 				 * specifying which commands are exported. A
280 				 * pattern may include "string match" style
281 				 * wildcard characters to specify multiple
282 				 * commands; however, no namespace qualifiers
283 				 * are allowed. NULL if no export patterns are
284 				 * registered. */
285     int numExportPatterns;	/* Number of export patterns currently
286 				 * registered using "namespace export". */
287     int maxExportPatterns;	/* Mumber of export patterns for which space
288 				 * is currently allocated. */
289     int cmdRefEpoch;		/* Incremented if a newly added command
290 				 * shadows a command for which this namespace
291 				 * has already cached a Command* pointer; this
292 				 * causes all its cached Command* pointers to
293 				 * be invalidated. */
294     int resolverEpoch;		/* Incremented whenever (a) the name
295 				 * resolution rules change for this namespace
296 				 * or (b) a newly added command shadows a
297 				 * command that is compiled to bytecodes. This
298 				 * invalidates all byte codes compiled in the
299 				 * namespace, causing the code to be
300 				 * recompiled under the new rules.*/
301     Tcl_ResolveCmdProc *cmdResProc;
302 				/* If non-null, this procedure overrides the
303 				 * usual command resolution mechanism in Tcl.
304 				 * This procedure is invoked within
305 				 * Tcl_FindCommand to resolve all command
306 				 * references within the namespace. */
307     Tcl_ResolveVarProc *varResProc;
308 				/* If non-null, this procedure overrides the
309 				 * usual variable resolution mechanism in Tcl.
310 				 * This procedure is invoked within
311 				 * Tcl_FindNamespaceVar to resolve all
312 				 * variable references within the namespace at
313 				 * runtime. */
314     Tcl_ResolveCompiledVarProc *compiledVarResProc;
315 				/* If non-null, this procedure overrides the
316 				 * usual variable resolution mechanism in Tcl.
317 				 * This procedure is invoked within
318 				 * LookupCompiledLocal to resolve variable
319 				 * references within the namespace at compile
320 				 * time. */
321     int exportLookupEpoch;	/* Incremented whenever a command is added to
322 				 * a namespace, removed from a namespace or
323 				 * the exports of a namespace are changed.
324 				 * Allows TIP#112-driven command lists to be
325 				 * validated efficiently. */
326     Tcl_Ensemble *ensembles;	/* List of structures that contain the details
327 				 * of the ensembles that are implemented on
328 				 * top of this namespace. */
329     Tcl_Obj *unknownHandlerPtr;	/* A script fragment to be used when command
330 				 * resolution in this namespace fails. TIP
331 				 * 181. */
332     int commandPathLength;	/* The length of the explicit path. */
333     NamespacePathEntry *commandPathArray;
334 				/* The explicit path of the namespace as an
335 				 * array. */
336     NamespacePathEntry *commandPathSourceList;
337 				/* Linked list of path entries that point to
338 				 * this namespace. */
339     Tcl_NamespaceDeleteProc *earlyDeleteProc;
340 				/* Just like the deleteProc field (and called
341 				 * with the same clientData) but called at the
342 				 * start of the deletion process, so there is
343 				 * a chance for code to do stuff inside the
344 				 * namespace before deletion completes. */
345 } Namespace;
346 
347 /*
348  * An entry on a namespace's command resolution path.
349  */
350 
351 struct NamespacePathEntry {
352     Namespace *nsPtr;		/* What does this path entry point to? If it
353 				 * is NULL, this path entry points is
354 				 * redundant and should be skipped. */
355     Namespace *creatorNsPtr;	/* Where does this path entry point from? This
356 				 * allows for efficient invalidation of
357 				 * references when the path entry's target
358 				 * updates its current list of defined
359 				 * commands. */
360     NamespacePathEntry *prevPtr, *nextPtr;
361 				/* Linked list pointers or NULL at either end
362 				 * of the list that hangs off Namespace's
363 				 * commandPathSourceList field. */
364 };
365 
366 /*
367  * Flags used to represent the status of a namespace:
368  *
369  * NS_DYING -	1 means Tcl_DeleteNamespace has been called to delete the
370  *		namespace but there are still active call frames on the Tcl
371  *		stack that refer to the namespace. When the last call frame
372  *		referring to it has been popped, it's variables and command
373  *		will be destroyed and it will be marked "dead" (NS_DEAD). The
374  *		namespace can no longer be looked up by name.
375  * NS_DEAD -	1 means Tcl_DeleteNamespace has been called to delete the
376  *		namespace and no call frames still refer to it. Its variables
377  *		and command have already been destroyed. This bit allows the
378  *		namespace resolution code to recognize that the namespace is
379  *		"deleted". When the last namespaceName object in any byte code
380  *		unit that refers to the namespace has been freed (i.e., when
381  *		the namespace's refCount is 0), the namespace's storage will
382  *		be freed.
383  * NS_KILLED -	1 means that TclTeardownNamespace has already been called on
384  *		this namespace and it should not be called again [Bug 1355942]
385  * NS_SUPPRESS_COMPILATION -
386  *		Marks the commands in this namespace for not being compiled,
387  *		forcing them to be looked up every time.
388  */
389 
390 #define NS_DYING	0x01
391 #define NS_DEAD		0x02
392 #define NS_KILLED	0x04
393 #define NS_SUPPRESS_COMPILATION	0x08
394 
395 /*
396  * Flags passed to TclGetNamespaceForQualName:
397  *
398  * TCL_GLOBAL_ONLY		- (see tcl.h) Look only in the global ns.
399  * TCL_NAMESPACE_ONLY		- (see tcl.h) Look only in the context ns.
400  * TCL_CREATE_NS_IF_UNKNOWN	- Create unknown namespaces.
401  * TCL_FIND_ONLY_NS		- The name sought is a namespace name.
402  */
403 
404 #define TCL_CREATE_NS_IF_UNKNOWN	0x800
405 #define TCL_FIND_ONLY_NS		0x1000
406 
407 /*
408  * The client data for an ensemble command. This consists of the table of
409  * commands that are actually exported by the namespace, and an epoch counter
410  * that, combined with the exportLookupEpoch field of the namespace structure,
411  * defines whether the table contains valid data or will need to be recomputed
412  * next time the ensemble command is called.
413  */
414 
415 typedef struct EnsembleConfig {
416     Namespace *nsPtr;		/* The namespace backing this ensemble up. */
417     Tcl_Command token;		/* The token for the command that provides
418 				 * ensemble support for the namespace, or NULL
419 				 * if the command has been deleted (or never
420 				 * existed; the global namespace never has an
421 				 * ensemble command.) */
422     int epoch;			/* The epoch at which this ensemble's table of
423 				 * exported commands is valid. */
424     char **subcommandArrayPtr;	/* Array of ensemble subcommand names. At all
425 				 * consistent points, this will have the same
426 				 * number of entries as there are entries in
427 				 * the subcommandTable hash. */
428     Tcl_HashTable subcommandTable;
429 				/* Hash table of ensemble subcommand names,
430 				 * which are its keys so this also provides
431 				 * the storage management for those subcommand
432 				 * names. The contents of the entry values are
433 				 * object version the prefix lists to use when
434 				 * substituting for the command/subcommand to
435 				 * build the ensemble implementation command.
436 				 * Has to be stored here as well as in
437 				 * subcommandDict because that field is NULL
438 				 * when we are deriving the ensemble from the
439 				 * namespace exports list. FUTURE WORK: use
440 				 * object hash table here. */
441     struct EnsembleConfig *next;/* The next ensemble in the linked list of
442 				 * ensembles associated with a namespace. If
443 				 * this field points to this ensemble, the
444 				 * structure has already been unlinked from
445 				 * all lists, and cannot be found by scanning
446 				 * the list from the namespace's ensemble
447 				 * field. */
448     int flags;			/* ORed combo of TCL_ENSEMBLE_PREFIX,
449 				 * ENSEMBLE_DEAD and ENSEMBLE_COMPILE. */
450 
451     /* OBJECT FIELDS FOR ENSEMBLE CONFIGURATION */
452 
453     Tcl_Obj *subcommandDict;	/* Dictionary providing mapping from
454 				 * subcommands to their implementing command
455 				 * prefixes, or NULL if we are to build the
456 				 * map automatically from the namespace
457 				 * exports. */
458     Tcl_Obj *subcmdList;	/* List of commands that this ensemble
459 				 * actually provides, and whose implementation
460 				 * will be built using the subcommandDict (if
461 				 * present and defined) and by simple mapping
462 				 * to the namespace otherwise. If NULL,
463 				 * indicates that we are using the (dynamic)
464 				 * list of currently exported commands. */
465     Tcl_Obj *unknownHandler;	/* Script prefix used to handle the case when
466 				 * no match is found (according to the rule
467 				 * defined by flag bit TCL_ENSEMBLE_PREFIX) or
468 				 * NULL to use the default error-generating
469 				 * behaviour. The script execution gets all
470 				 * the arguments to the ensemble command
471 				 * (including objv[0]) and will have the
472 				 * results passed directly back to the caller
473 				 * (including the error code) unless the code
474 				 * is TCL_CONTINUE in which case the
475 				 * subcommand will be reparsed by the ensemble
476 				 * core, presumably because the ensemble
477 				 * itself has been updated. */
478     Tcl_Obj *parameterList;	/* List of ensemble parameter names. */
479     int numParameters;		/* Cached number of parameters. This is either
480 				 * 0 (if the parameterList field is NULL) or
481 				 * the length of the list in the parameterList
482 				 * field. */
483 } EnsembleConfig;
484 
485 /*
486  * Various bits for the EnsembleConfig.flags field.
487  */
488 
489 #define ENSEMBLE_DEAD	0x1	/* Flag value to say that the ensemble is dead
490 				 * and on its way out. */
491 #define ENSEMBLE_COMPILE 0x4	/* Flag to enable bytecode compilation of an
492 				 * ensemble. */
493 
494 /*
495  *----------------------------------------------------------------
496  * Data structures related to variables. These are used primarily in tclVar.c
497  *----------------------------------------------------------------
498  */
499 
500 /*
501  * The following structure defines a variable trace, which is used to invoke a
502  * specific C procedure whenever certain operations are performed on a
503  * variable.
504  */
505 
506 typedef struct VarTrace {
507     Tcl_VarTraceProc *traceProc;/* Procedure to call when operations given by
508 				 * flags are performed on variable. */
509     ClientData clientData;	/* Argument to pass to proc. */
510     int flags;			/* What events the trace procedure is
511 				 * interested in: OR-ed combination of
512 				 * TCL_TRACE_READS, TCL_TRACE_WRITES,
513 				 * TCL_TRACE_UNSETS and TCL_TRACE_ARRAY. */
514     struct VarTrace *nextPtr;	/* Next in list of traces associated with a
515 				 * particular variable. */
516 } VarTrace;
517 
518 /*
519  * The following structure defines a command trace, which is used to invoke a
520  * specific C procedure whenever certain operations are performed on a
521  * command.
522  */
523 
524 typedef struct CommandTrace {
525     Tcl_CommandTraceProc *traceProc;
526 				/* Procedure to call when operations given by
527 				 * flags are performed on command. */
528     ClientData clientData;	/* Argument to pass to proc. */
529     int flags;			/* What events the trace procedure is
530 				 * interested in: OR-ed combination of
531 				 * TCL_TRACE_RENAME, TCL_TRACE_DELETE. */
532     struct CommandTrace *nextPtr;
533 				/* Next in list of traces associated with a
534 				 * particular command. */
535     int refCount;		/* Used to ensure this structure is not
536 				 * deleted too early. Keeps track of how many
537 				 * pieces of code have a pointer to this
538 				 * structure. */
539 } CommandTrace;
540 
541 /*
542  * When a command trace is active (i.e. its associated procedure is executing)
543  * one of the following structures is linked into a list associated with the
544  * command's interpreter. The information in the structure is needed in order
545  * for Tcl to behave reasonably if traces are deleted while traces are active.
546  */
547 
548 typedef struct ActiveCommandTrace {
549     struct Command *cmdPtr;	/* Command that's being traced. */
550     struct ActiveCommandTrace *nextPtr;
551 				/* Next in list of all active command traces
552 				 * for the interpreter, or NULL if no more. */
553     CommandTrace *nextTracePtr;	/* Next trace to check after current trace
554 				 * procedure returns; if this trace gets
555 				 * deleted, must update pointer to avoid using
556 				 * free'd memory. */
557     int reverseScan;		/* Boolean set true when traces are scanning
558 				 * in reverse order. */
559 } ActiveCommandTrace;
560 
561 /*
562  * When a variable trace is active (i.e. its associated procedure is
563  * executing) one of the following structures is linked into a list associated
564  * with the variable's interpreter. The information in the structure is needed
565  * in order for Tcl to behave reasonably if traces are deleted while traces
566  * are active.
567  */
568 
569 typedef struct ActiveVarTrace {
570     struct Var *varPtr;		/* Variable that's being traced. */
571     struct ActiveVarTrace *nextPtr;
572 				/* Next in list of all active variable traces
573 				 * for the interpreter, or NULL if no more. */
574     VarTrace *nextTracePtr;	/* Next trace to check after current trace
575 				 * procedure returns; if this trace gets
576 				 * deleted, must update pointer to avoid using
577 				 * free'd memory. */
578 } ActiveVarTrace;
579 
580 /*
581  * The structure below defines a variable, which associates a string name with
582  * a Tcl_Obj value. These structures are kept in procedure call frames (for
583  * local variables recognized by the compiler) or in the heap (for global
584  * variables and any variable not known to the compiler). For each Var
585  * structure in the heap, a hash table entry holds the variable name and a
586  * pointer to the Var structure.
587  */
588 
589 typedef struct Var {
590     int flags;			/* Miscellaneous bits of information about
591 				 * variable. See below for definitions. */
592     union {
593 	Tcl_Obj *objPtr;	/* The variable's object value. Used for
594 				 * scalar variables and array elements. */
595 	TclVarHashTable *tablePtr;/* For array variables, this points to
596 				 * information about the hash table used to
597 				 * implement the associative array. Points to
598 				 * ckalloc-ed data. */
599 	struct Var *linkPtr;	/* If this is a global variable being referred
600 				 * to in a procedure, or a variable created by
601 				 * "upvar", this field points to the
602 				 * referenced variable's Var struct. */
603     } value;
604 } Var;
605 
606 typedef struct VarInHash {
607     Var var;
608     int refCount;		/* Counts number of active uses of this
609 				 * variable: 1 for the entry in the hash
610 				 * table, 1 for each additional variable whose
611 				 * linkPtr points here, 1 for each nested
612 				 * trace active on variable, and 1 if the
613 				 * variable is a namespace variable. This
614 				 * record can't be deleted until refCount
615 				 * becomes 0. */
616     Tcl_HashEntry entry;	/* The hash table entry that refers to this
617 				 * variable. This is used to find the name of
618 				 * the variable and to delete it from its
619 				 * hashtable if it is no longer needed. It
620 				 * also holds the variable's name. */
621 } VarInHash;
622 
623 /*
624  * Flag bits for variables. The first two (VAR_ARRAY and VAR_LINK) are
625  * mutually exclusive and give the "type" of the variable. If none is set,
626  * this is a scalar variable.
627  *
628  * VAR_ARRAY -			1 means this is an array variable rather than
629  *				a scalar variable or link. The "tablePtr"
630  *				field points to the array's hashtable for its
631  *				elements.
632  * VAR_LINK -			1 means this Var structure contains a pointer
633  *				to another Var structure that either has the
634  *				real value or is itself another VAR_LINK
635  *				pointer. Variables like this come about
636  *				through "upvar" and "global" commands, or
637  *				through references to variables in enclosing
638  *				namespaces.
639  *
640  * Flags that indicate the type and status of storage; none is set for
641  * compiled local variables (Var structs).
642  *
643  * VAR_IN_HASHTABLE -		1 means this variable is in a hashtable and
644  *				the Var structure is malloced. 0 if it is a
645  *				local variable that was assigned a slot in a
646  *				procedure frame by the compiler so the Var
647  *				storage is part of the call frame.
648  * VAR_DEAD_HASH		1 means that this var's entry in the hashtable
649  *				has already been deleted.
650  * VAR_ARRAY_ELEMENT -		1 means that this variable is an array
651  *				element, so it is not legal for it to be an
652  *				array itself (the VAR_ARRAY flag had better
653  *				not be set).
654  * VAR_NAMESPACE_VAR -		1 means that this variable was declared as a
655  *				namespace variable. This flag ensures it
656  *				persists until its namespace is destroyed or
657  *				until the variable is unset; it will persist
658  *				even if it has not been initialized and is
659  *				marked undefined. The variable's refCount is
660  *				incremented to reflect the "reference" from
661  *				its namespace.
662  *
663  * Flag values relating to the variable's trace and search status.
664  *
665  * VAR_TRACED_READ
666  * VAR_TRACED_WRITE
667  * VAR_TRACED_UNSET
668  * VAR_TRACED_ARRAY
669  * VAR_TRACE_ACTIVE -		1 means that trace processing is currently
670  *				underway for a read or write access, so new
671  *				read or write accesses should not cause trace
672  *				procedures to be called and the variable can't
673  *				be deleted.
674  * VAR_SEARCH_ACTIVE
675  *
676  * The following additional flags are used with the CompiledLocal type defined
677  * below:
678  *
679  * VAR_ARGUMENT -		1 means that this variable holds a procedure
680  *				argument.
681  * VAR_TEMPORARY -		1 if the local variable is an anonymous
682  *				temporary variable. Temporaries have a NULL
683  *				name.
684  * VAR_RESOLVED -		1 if name resolution has been done for this
685  *				variable.
686  * VAR_IS_ARGS			1 if this variable is the last argument and is
687  *				named "args".
688  */
689 
690 /*
691  * FLAGS RENUMBERED: everything breaks already, make things simpler.
692  *
693  * IMPORTANT: skip the values 0x10, 0x20, 0x40, 0x800 corresponding to
694  * TCL_TRACE_(READS/WRITES/UNSETS/ARRAY): makes code simpler in tclTrace.c
695  *
696  * Keep the flag values for VAR_ARGUMENT and VAR_TEMPORARY so that old values
697  * in precompiled scripts keep working.
698  */
699 
700 /* Type of value (0 is scalar) */
701 #define VAR_ARRAY		0x1
702 #define VAR_LINK		0x2
703 
704 /* Type of storage (0 is compiled local) */
705 #define VAR_IN_HASHTABLE	0x4
706 #define VAR_DEAD_HASH		0x8
707 #define VAR_ARRAY_ELEMENT	0x1000
708 #define VAR_NAMESPACE_VAR	0x80	/* KEEP OLD VALUE for Itcl */
709 
710 #define VAR_ALL_HASH \
711 	(VAR_IN_HASHTABLE|VAR_DEAD_HASH|VAR_NAMESPACE_VAR|VAR_ARRAY_ELEMENT)
712 
713 /* Trace and search state. */
714 
715 #define VAR_TRACED_READ		0x10	/* TCL_TRACE_READS */
716 #define VAR_TRACED_WRITE	0x20	/* TCL_TRACE_WRITES */
717 #define VAR_TRACED_UNSET	0x40	/* TCL_TRACE_UNSETS */
718 #define VAR_TRACED_ARRAY	0x800	/* TCL_TRACE_ARRAY */
719 #define VAR_TRACE_ACTIVE	0x2000
720 #define VAR_SEARCH_ACTIVE	0x4000
721 #define VAR_ALL_TRACES \
722 	(VAR_TRACED_READ|VAR_TRACED_WRITE|VAR_TRACED_ARRAY|VAR_TRACED_UNSET)
723 
724 /* Special handling on initialisation (only CompiledLocal). */
725 #define VAR_ARGUMENT		0x100	/* KEEP OLD VALUE! See tclProc.c */
726 #define VAR_TEMPORARY		0x200	/* KEEP OLD VALUE! See tclProc.c */
727 #define VAR_IS_ARGS		0x400
728 #define VAR_RESOLVED		0x8000
729 
730 /*
731  * Macros to ensure that various flag bits are set properly for variables.
732  * The ANSI C "prototypes" for these macros are:
733  *
734  * MODULE_SCOPE void	TclSetVarScalar(Var *varPtr);
735  * MODULE_SCOPE void	TclSetVarArray(Var *varPtr);
736  * MODULE_SCOPE void	TclSetVarLink(Var *varPtr);
737  * MODULE_SCOPE void	TclSetVarArrayElement(Var *varPtr);
738  * MODULE_SCOPE void	TclSetVarUndefined(Var *varPtr);
739  * MODULE_SCOPE void	TclClearVarUndefined(Var *varPtr);
740  */
741 
742 #define TclSetVarScalar(varPtr) \
743     (varPtr)->flags &= ~(VAR_ARRAY|VAR_LINK)
744 
745 #define TclSetVarArray(varPtr) \
746     (varPtr)->flags = ((varPtr)->flags & ~VAR_LINK) | VAR_ARRAY
747 
748 #define TclSetVarLink(varPtr) \
749     (varPtr)->flags = ((varPtr)->flags & ~VAR_ARRAY) | VAR_LINK
750 
751 #define TclSetVarArrayElement(varPtr) \
752     (varPtr)->flags = ((varPtr)->flags & ~VAR_ARRAY) | VAR_ARRAY_ELEMENT
753 
754 #define TclSetVarUndefined(varPtr) \
755     (varPtr)->flags &= ~(VAR_ARRAY|VAR_LINK);\
756     (varPtr)->value.objPtr = NULL
757 
758 #define TclClearVarUndefined(varPtr)
759 
760 #define TclSetVarTraceActive(varPtr) \
761     (varPtr)->flags |= VAR_TRACE_ACTIVE
762 
763 #define TclClearVarTraceActive(varPtr) \
764     (varPtr)->flags &= ~VAR_TRACE_ACTIVE
765 
766 #define TclSetVarNamespaceVar(varPtr) \
767     if (!TclIsVarNamespaceVar(varPtr)) {\
768 	(varPtr)->flags |= VAR_NAMESPACE_VAR;\
769 	if (TclIsVarInHash(varPtr)) {\
770 	    ((VarInHash *)(varPtr))->refCount++;\
771 	}\
772     }
773 
774 #define TclClearVarNamespaceVar(varPtr) \
775     if (TclIsVarNamespaceVar(varPtr)) {\
776 	(varPtr)->flags &= ~VAR_NAMESPACE_VAR;\
777 	if (TclIsVarInHash(varPtr)) {\
778 	    ((VarInHash *)(varPtr))->refCount--;\
779 	}\
780     }
781 
782 /*
783  * Macros to read various flag bits of variables.
784  * The ANSI C "prototypes" for these macros are:
785  *
786  * MODULE_SCOPE int	TclIsVarScalar(Var *varPtr);
787  * MODULE_SCOPE int	TclIsVarLink(Var *varPtr);
788  * MODULE_SCOPE int	TclIsVarArray(Var *varPtr);
789  * MODULE_SCOPE int	TclIsVarUndefined(Var *varPtr);
790  * MODULE_SCOPE int	TclIsVarArrayElement(Var *varPtr);
791  * MODULE_SCOPE int	TclIsVarTemporary(Var *varPtr);
792  * MODULE_SCOPE int	TclIsVarArgument(Var *varPtr);
793  * MODULE_SCOPE int	TclIsVarResolved(Var *varPtr);
794  */
795 
796 #define TclIsVarScalar(varPtr) \
797     !((varPtr)->flags & (VAR_ARRAY|VAR_LINK))
798 
799 #define TclIsVarLink(varPtr) \
800     ((varPtr)->flags & VAR_LINK)
801 
802 #define TclIsVarArray(varPtr) \
803     ((varPtr)->flags & VAR_ARRAY)
804 
805 #define TclIsVarUndefined(varPtr) \
806     ((varPtr)->value.objPtr == NULL)
807 
808 #define TclIsVarArrayElement(varPtr) \
809     ((varPtr)->flags & VAR_ARRAY_ELEMENT)
810 
811 #define TclIsVarNamespaceVar(varPtr) \
812     ((varPtr)->flags & VAR_NAMESPACE_VAR)
813 
814 #define TclIsVarTemporary(varPtr) \
815     ((varPtr)->flags & VAR_TEMPORARY)
816 
817 #define TclIsVarArgument(varPtr) \
818     ((varPtr)->flags & VAR_ARGUMENT)
819 
820 #define TclIsVarResolved(varPtr) \
821     ((varPtr)->flags & VAR_RESOLVED)
822 
823 #define TclIsVarTraceActive(varPtr) \
824     ((varPtr)->flags & VAR_TRACE_ACTIVE)
825 
826 #define TclIsVarTraced(varPtr) \
827     ((varPtr)->flags & VAR_ALL_TRACES)
828 
829 #define TclIsVarInHash(varPtr) \
830     ((varPtr)->flags & VAR_IN_HASHTABLE)
831 
832 #define TclIsVarDeadHash(varPtr) \
833     ((varPtr)->flags & VAR_DEAD_HASH)
834 
835 #define TclGetVarNsPtr(varPtr) \
836     (TclIsVarInHash(varPtr) \
837 	? ((TclVarHashTable *) ((((VarInHash *) (varPtr))->entry.tablePtr)))->nsPtr \
838 	: NULL)
839 
840 #define VarHashRefCount(varPtr) \
841     ((VarInHash *) (varPtr))->refCount
842 
843 /*
844  * Macros for direct variable access by TEBC.
845  */
846 
847 #define TclIsVarDirectReadable(varPtr) \
848     (   !((varPtr)->flags & (VAR_ARRAY|VAR_LINK|VAR_TRACED_READ)) \
849     &&  (varPtr)->value.objPtr)
850 
851 #define TclIsVarDirectWritable(varPtr) \
852     !((varPtr)->flags & (VAR_ARRAY|VAR_LINK|VAR_TRACED_WRITE|VAR_DEAD_HASH))
853 
854 #define TclIsVarDirectUnsettable(varPtr) \
855     !((varPtr)->flags & (VAR_ARRAY|VAR_LINK|VAR_TRACED_READ|VAR_TRACED_WRITE|VAR_TRACED_UNSET|VAR_DEAD_HASH))
856 
857 #define TclIsVarDirectModifyable(varPtr) \
858     (   !((varPtr)->flags & (VAR_ARRAY|VAR_LINK|VAR_TRACED_READ|VAR_TRACED_WRITE)) \
859     &&  (varPtr)->value.objPtr)
860 
861 #define TclIsVarDirectReadable2(varPtr, arrayPtr) \
862     (TclIsVarDirectReadable(varPtr) &&\
863 	(!(arrayPtr) || !((arrayPtr)->flags & VAR_TRACED_READ)))
864 
865 #define TclIsVarDirectWritable2(varPtr, arrayPtr) \
866     (TclIsVarDirectWritable(varPtr) &&\
867 	(!(arrayPtr) || !((arrayPtr)->flags & VAR_TRACED_WRITE)))
868 
869 #define TclIsVarDirectModifyable2(varPtr, arrayPtr) \
870     (TclIsVarDirectModifyable(varPtr) &&\
871 	(!(arrayPtr) || !((arrayPtr)->flags & (VAR_TRACED_READ|VAR_TRACED_WRITE))))
872 
873 /*
874  *----------------------------------------------------------------
875  * Data structures related to procedures. These are used primarily in
876  * tclProc.c, tclCompile.c, and tclExecute.c.
877  *----------------------------------------------------------------
878  */
879 
880 #if defined(__GNUC__) && (__GNUC__ > 2)
881 #   define TCLFLEXARRAY 0
882 #else
883 #   define TCLFLEXARRAY 1
884 #endif
885 
886 /*
887  * Forward declaration to prevent an error when the forward reference to
888  * Command is encountered in the Proc and ImportRef types declared below.
889  */
890 
891 struct Command;
892 
893 /*
894  * The variable-length structure below describes a local variable of a
895  * procedure that was recognized by the compiler. These variables have a name,
896  * an element in the array of compiler-assigned local variables in the
897  * procedure's call frame, and various other items of information. If the
898  * local variable is a formal argument, it may also have a default value. The
899  * compiler can't recognize local variables whose names are expressions (these
900  * names are only known at runtime when the expressions are evaluated) or
901  * local variables that are created as a result of an "upvar" or "uplevel"
902  * command. These other local variables are kept separately in a hash table in
903  * the call frame.
904  */
905 
906 typedef struct CompiledLocal {
907     struct CompiledLocal *nextPtr;
908 				/* Next compiler-recognized local variable for
909 				 * this procedure, or NULL if this is the last
910 				 * local. */
911     int nameLength;		/* The number of bytes in local variable's name.
912 				 * Among others used to speed up var lookups. */
913     int frameIndex;		/* Index in the array of compiler-assigned
914 				 * variables in the procedure call frame. */
915     int flags;			/* Flag bits for the local variable. Same as
916 				 * the flags for the Var structure above,
917 				 * although only VAR_ARGUMENT, VAR_TEMPORARY,
918 				 * and VAR_RESOLVED make sense. */
919     Tcl_Obj *defValuePtr;	/* Pointer to the default value of an
920 				 * argument, if any. NULL if not an argument
921 				 * or, if an argument, no default value. */
922     Tcl_ResolvedVarInfo *resolveInfo;
923 				/* Customized variable resolution info
924 				 * supplied by the Tcl_ResolveCompiledVarProc
925 				 * associated with a namespace. Each variable
926 				 * is marked by a unique ClientData tag during
927 				 * compilation, and that same tag is used to
928 				 * find the variable at runtime. */
929     char name[TCLFLEXARRAY];		/* Name of the local variable starts here. If
930 				 * the name is NULL, this will just be '\0'.
931 				 * The actual size of this field will be large
932 				 * enough to hold the name. MUST BE THE LAST
933 				 * FIELD IN THE STRUCTURE! */
934 } CompiledLocal;
935 
936 /*
937  * The structure below defines a command procedure, which consists of a
938  * collection of Tcl commands plus information about arguments and other local
939  * variables recognized at compile time.
940  */
941 
942 typedef struct Proc {
943     struct Interp *iPtr;	/* Interpreter for which this command is
944 				 * defined. */
945     int refCount;		/* Reference count: 1 if still present in
946 				 * command table plus 1 for each call to the
947 				 * procedure that is currently active. This
948 				 * structure can be freed when refCount
949 				 * becomes zero. */
950     struct Command *cmdPtr;	/* Points to the Command structure for this
951 				 * procedure. This is used to get the
952 				 * namespace in which to execute the
953 				 * procedure. */
954     Tcl_Obj *bodyPtr;		/* Points to the ByteCode object for
955 				 * procedure's body command. */
956     int numArgs;		/* Number of formal parameters. */
957     int numCompiledLocals;	/* Count of local variables recognized by the
958 				 * compiler including arguments and
959 				 * temporaries. */
960     CompiledLocal *firstLocalPtr;
961 				/* Pointer to first of the procedure's
962 				 * compiler-allocated local variables, or NULL
963 				 * if none. The first numArgs entries in this
964 				 * list describe the procedure's formal
965 				 * arguments. */
966     CompiledLocal *lastLocalPtr;/* Pointer to the last allocated local
967 				 * variable or NULL if none. This has frame
968 				 * index (numCompiledLocals-1). */
969 } Proc;
970 
971 /*
972  * The type of functions called to process errors found during the execution
973  * of a procedure (or lambda term or ...).
974  */
975 
976 typedef void (ProcErrorProc)(Tcl_Interp *interp, Tcl_Obj *procNameObj);
977 
978 /*
979  * The structure below defines a command trace. This is used to allow Tcl
980  * clients to find out whenever a command is about to be executed.
981  */
982 
983 typedef struct Trace {
984     int level;			/* Only trace commands at nesting level less
985 				 * than or equal to this. */
986     Tcl_CmdObjTraceProc *proc;	/* Procedure to call to trace command. */
987     ClientData clientData;	/* Arbitrary value to pass to proc. */
988     struct Trace *nextPtr;	/* Next in list of traces for this interp. */
989     int flags;			/* Flags governing the trace - see
990 				 * Tcl_CreateObjTrace for details. */
991     Tcl_CmdObjTraceDeleteProc *delProc;
992 				/* Procedure to call when trace is deleted. */
993 } Trace;
994 
995 /*
996  * When an interpreter trace is active (i.e. its associated procedure is
997  * executing), one of the following structures is linked into a list
998  * associated with the interpreter. The information in the structure is needed
999  * in order for Tcl to behave reasonably if traces are deleted while traces
1000  * are active.
1001  */
1002 
1003 typedef struct ActiveInterpTrace {
1004     struct ActiveInterpTrace *nextPtr;
1005 				/* Next in list of all active command traces
1006 				 * for the interpreter, or NULL if no more. */
1007     Trace *nextTracePtr;	/* Next trace to check after current trace
1008 				 * procedure returns; if this trace gets
1009 				 * deleted, must update pointer to avoid using
1010 				 * free'd memory. */
1011     int reverseScan;		/* Boolean set true when traces are scanning
1012 				 * in reverse order. */
1013 } ActiveInterpTrace;
1014 
1015 /*
1016  * Flag values designating types of execution traces. See tclTrace.c for
1017  * related flag values.
1018  *
1019  * TCL_TRACE_ENTER_EXEC		- triggers enter/enterstep traces.
1020  * 				- passed to Tcl_CreateObjTrace to set up
1021  *				  "enterstep" traces.
1022  * TCL_TRACE_LEAVE_EXEC		- triggers leave/leavestep traces.
1023  * 				- passed to Tcl_CreateObjTrace to set up
1024  *				  "leavestep" traces.
1025  */
1026 
1027 #define TCL_TRACE_ENTER_EXEC	1
1028 #define TCL_TRACE_LEAVE_EXEC	2
1029 
1030 /*
1031  * The structure below defines an entry in the assocData hash table which is
1032  * associated with an interpreter. The entry contains a pointer to a function
1033  * to call when the interpreter is deleted, and a pointer to a user-defined
1034  * piece of data.
1035  */
1036 
1037 typedef struct AssocData {
1038     Tcl_InterpDeleteProc *proc;	/* Proc to call when deleting. */
1039     ClientData clientData;	/* Value to pass to proc. */
1040 } AssocData;
1041 
1042 /*
1043  * The structure below defines a call frame. A call frame defines a naming
1044  * context for a procedure call: its local naming scope (for local variables)
1045  * and its global naming scope (a namespace, perhaps the global :: namespace).
1046  * A call frame can also define the naming context for a namespace eval or
1047  * namespace inscope command: the namespace in which the command's code should
1048  * execute. The Tcl_CallFrame structures exist only while procedures or
1049  * namespace eval/inscope's are being executed, and provide a kind of Tcl call
1050  * stack.
1051  *
1052  * WARNING!! The structure definition must be kept consistent with the
1053  * Tcl_CallFrame structure in tcl.h. If you change one, change the other.
1054  */
1055 
1056 /*
1057  * Will be grown to contain: pointers to the varnames (allocated at the end),
1058  * plus the init values for each variable (suitable to be memcopied on init)
1059  */
1060 
1061 typedef struct LocalCache {
1062     int refCount;
1063     int numVars;
1064     Tcl_Obj *varName0;
1065 } LocalCache;
1066 
1067 #define localName(framePtr, i) \
1068     ((&((framePtr)->localCachePtr->varName0))[(i)])
1069 
1070 MODULE_SCOPE void	TclFreeLocalCache(Tcl_Interp *interp,
1071 			    LocalCache *localCachePtr);
1072 
1073 typedef struct CallFrame {
1074     Namespace *nsPtr;		/* Points to the namespace used to resolve
1075 				 * commands and global variables. */
1076     int isProcCallFrame;	/* If 0, the frame was pushed to execute a
1077 				 * namespace command and var references are
1078 				 * treated as references to namespace vars;
1079 				 * varTablePtr and compiledLocals are ignored.
1080 				 * If FRAME_IS_PROC is set, the frame was
1081 				 * pushed to execute a Tcl procedure and may
1082 				 * have local vars. */
1083     int objc;			/* This and objv below describe the arguments
1084 				 * for this procedure call. */
1085     Tcl_Obj *const *objv;	/* Array of argument objects. */
1086     struct CallFrame *callerPtr;
1087 				/* Value of interp->framePtr when this
1088 				 * procedure was invoked (i.e. next higher in
1089 				 * stack of all active procedures). */
1090     struct CallFrame *callerVarPtr;
1091 				/* Value of interp->varFramePtr when this
1092 				 * procedure was invoked (i.e. determines
1093 				 * variable scoping within caller). Same as
1094 				 * callerPtr unless an "uplevel" command or
1095 				 * something equivalent was active in the
1096 				 * caller). */
1097     int level;			/* Level of this procedure, for "uplevel"
1098 				 * purposes (i.e. corresponds to nesting of
1099 				 * callerVarPtr's, not callerPtr's). 1 for
1100 				 * outermost procedure, 0 for top-level. */
1101     Proc *procPtr;		/* Points to the structure defining the called
1102 				 * procedure. Used to get information such as
1103 				 * the number of compiled local variables
1104 				 * (local variables assigned entries ["slots"]
1105 				 * in the compiledLocals array below). */
1106     TclVarHashTable *varTablePtr;
1107 				/* Hash table containing local variables not
1108 				 * recognized by the compiler, or created at
1109 				 * execution time through, e.g., upvar.
1110 				 * Initially NULL and created if needed. */
1111     int numCompiledLocals;	/* Count of local variables recognized by the
1112 				 * compiler including arguments. */
1113     Var *compiledLocals;	/* Points to the array of local variables
1114 				 * recognized by the compiler. The compiler
1115 				 * emits code that refers to these variables
1116 				 * using an index into this array. */
1117     ClientData clientData;	/* Pointer to some context that is used by
1118 				 * object systems. The meaning of the contents
1119 				 * of this field is defined by the code that
1120 				 * sets it, and it should only ever be set by
1121 				 * the code that is pushing the frame. In that
1122 				 * case, the code that sets it should also
1123 				 * have some means of discovering what the
1124 				 * meaning of the value is, which we do not
1125 				 * specify. */
1126     LocalCache *localCachePtr;
1127     Tcl_Obj    *tailcallPtr;
1128 				/* NULL if no tailcall is scheduled */
1129 } CallFrame;
1130 
1131 #define FRAME_IS_PROC	0x1
1132 #define FRAME_IS_LAMBDA 0x2
1133 #define FRAME_IS_METHOD	0x4	/* The frame is a method body, and the frame's
1134 				 * clientData field contains a CallContext
1135 				 * reference. Part of TIP#257. */
1136 #define FRAME_IS_OO_DEFINE 0x8	/* The frame is part of the inside workings of
1137 				 * the [oo::define] command; the clientData
1138 				 * field contains an Object reference that has
1139 				 * been confirmed to refer to a class. Part of
1140 				 * TIP#257. */
1141 
1142 /*
1143  * TIP #280
1144  * The structure below defines a command frame. A command frame provides
1145  * location information for all commands executing a tcl script (source, eval,
1146  * uplevel, procedure bodies, ...). The runtime structure essentially contains
1147  * the stack trace as it would be if the currently executing command were to
1148  * throw an error.
1149  *
1150  * For commands where it makes sense it refers to the associated CallFrame as
1151  * well.
1152  *
1153  * The structures are chained in a single list, with the top of the stack
1154  * anchored in the Interp structure.
1155  *
1156  * Instances can be allocated on the C stack, or the heap, the former making
1157  * cleanup a bit simpler.
1158  */
1159 
1160 typedef struct CmdFrame {
1161     /*
1162      * General data. Always available.
1163      */
1164 
1165     int type;			/* Values see below. */
1166     int level;			/* Number of frames in stack, prevent O(n)
1167 				 * scan of list. */
1168     int *line;			/* Lines the words of the command start on. */
1169     int nline;
1170     CallFrame *framePtr;	/* Procedure activation record, may be
1171 				 * NULL. */
1172     struct CmdFrame *nextPtr;	/* Link to calling frame. */
1173     /*
1174      * Data needed for Eval vs TEBC
1175      *
1176      * EXECUTION CONTEXTS and usage of CmdFrame
1177      *
1178      * Field	  TEBC		  EvalEx
1179      * =======	  ====		  ======
1180      * level	  yes		  yes
1181      * type	  BC/PREBC	  SRC/EVAL
1182      * line0	  yes		  yes
1183      * framePtr	  yes		  yes
1184      * =======	  ====		  ======
1185      *
1186      * =======	  ====		  ========= union data
1187      * line1	  -		  yes
1188      * line3	  -		  yes
1189      * path	  -		  yes
1190      * -------	  ----		  ------
1191      * codePtr	  yes		  -
1192      * pc	  yes		  -
1193      * =======	  ====		  ======
1194      *
1195      * =======	  ====		  ========= union cmd
1196      * str.cmd	  yes		  yes
1197      * str.len	  yes		  yes
1198      * -------	  ----		  ------
1199      */
1200 
1201     union {
1202 	struct {
1203 	    Tcl_Obj *path;	/* Path of the sourced file the command is
1204 				 * in. */
1205 	} eval;
1206 	struct {
1207 	    const void *codePtr;/* Byte code currently executed... */
1208 	    const char *pc;	/* ... and instruction pointer. */
1209 	} tebc;
1210     } data;
1211     Tcl_Obj *cmdObj;
1212     const char *cmd;		/* The executed command, if possible... */
1213     int len;			/* ... and its length. */
1214     const struct CFWordBC *litarg;
1215 				/* Link to set of literal arguments which have
1216 				 * ben pushed on the lineLABCPtr stack by
1217 				 * TclArgumentBCEnter(). These will be removed
1218 				 * by TclArgumentBCRelease. */
1219 } CmdFrame;
1220 
1221 typedef struct CFWord {
1222     CmdFrame *framePtr;		/* CmdFrame to access. */
1223     int word;			/* Index of the word in the command. */
1224     int refCount;		/* Number of times the word is on the
1225 				 * stack. */
1226 } CFWord;
1227 
1228 typedef struct CFWordBC {
1229     CmdFrame *framePtr;		/* CmdFrame to access. */
1230     int pc;			/* Instruction pointer of a command in
1231 				 * ExtCmdLoc.loc[.] */
1232     int word;			/* Index of word in
1233 				 * ExtCmdLoc.loc[cmd]->line[.] */
1234     struct CFWordBC *prevPtr;	/* Previous entry in stack for same Tcl_Obj. */
1235     struct CFWordBC *nextPtr;	/* Next entry for same command call. See
1236 				 * CmdFrame litarg field for the list start. */
1237     Tcl_Obj *obj;		/* Back reference to hashtable key */
1238 } CFWordBC;
1239 
1240 /*
1241  * Structure to record the locations of invisible continuation lines in
1242  * literal scripts, as character offset from the beginning of the script. Both
1243  * compiler and direct evaluator use this information to adjust their line
1244  * counters when tracking through the script, because when it is invoked the
1245  * continuation line marker as a whole has been removed already, meaning that
1246  * the \n which was part of it is gone as well, breaking regular line
1247  * tracking.
1248  *
1249  * These structures are allocated and filled by both the function
1250  * TclSubstTokens() in the file "tclParse.c" and its caller TclEvalEx() in the
1251  * file "tclBasic.c", and stored in the thread-global hashtable "lineCLPtr" in
1252  * file "tclObj.c". They are used by the functions TclSetByteCodeFromAny() and
1253  * TclCompileScript(), both found in the file "tclCompile.c". Their memory is
1254  * released by the function TclFreeObj(), in the file "tclObj.c", and also by
1255  * the function TclThreadFinalizeObjects(), in the same file.
1256  */
1257 
1258 #define CLL_END		(-1)
1259 
1260 typedef struct ContLineLoc {
1261     int num;			/* Number of entries in loc, not counting the
1262 				 * final -1 marker entry. */
1263     int loc[TCLFLEXARRAY];/* Table of locations, as character offsets.
1264 				 * The table is allocated as part of the
1265 				 * structure, extending behind the nominal end
1266 				 * of the structure. An entry containing the
1267 				 * value -1 is put after the last location, as
1268 				 * end-marker/sentinel. */
1269 } ContLineLoc;
1270 
1271 /*
1272  * The following macros define the allowed values for the type field of the
1273  * CmdFrame structure above. Some of the values occur only in the extended
1274  * location data referenced via the 'baseLocPtr'.
1275  *
1276  * TCL_LOCATION_EVAL	  : Frame is for a script evaluated by EvalEx.
1277  * TCL_LOCATION_BC	  : Frame is for bytecode.
1278  * TCL_LOCATION_PREBC	  : Frame is for precompiled bytecode.
1279  * TCL_LOCATION_SOURCE	  : Frame is for a script evaluated by EvalEx, from a
1280  *			    sourced file.
1281  * TCL_LOCATION_PROC	  : Frame is for bytecode of a procedure.
1282  *
1283  * A TCL_LOCATION_BC type in a frame can be overridden by _SOURCE and _PROC
1284  * types, per the context of the byte code in execution.
1285  */
1286 
1287 #define TCL_LOCATION_EVAL	(0) /* Location in a dynamic eval script. */
1288 #define TCL_LOCATION_BC		(2) /* Location in byte code. */
1289 #define TCL_LOCATION_PREBC	(3) /* Location in precompiled byte code, no
1290 				     * location. */
1291 #define TCL_LOCATION_SOURCE	(4) /* Location in a file. */
1292 #define TCL_LOCATION_PROC	(5) /* Location in a dynamic proc. */
1293 #define TCL_LOCATION_LAST	(6) /* Number of values in the enum. */
1294 
1295 /*
1296  * Structure passed to describe procedure-like "procedures" that are not
1297  * procedures (e.g. a lambda) so that their details can be reported correctly
1298  * by [info frame]. Contains a sub-structure for each extra field.
1299  */
1300 
1301 typedef Tcl_Obj * (GetFrameInfoValueProc)(ClientData clientData);
1302 typedef struct {
1303     const char *name;		/* Name of this field. */
1304     GetFrameInfoValueProc *proc;	/* Function to generate a Tcl_Obj* from the
1305 				 * clientData, or just use the clientData
1306 				 * directly (after casting) if NULL. */
1307     ClientData clientData;	/* Context for above function, or Tcl_Obj* if
1308 				 * proc field is NULL. */
1309 } ExtraFrameInfoField;
1310 typedef struct {
1311     int length;			/* Length of array. */
1312     ExtraFrameInfoField fields[2];
1313 				/* Really as long as necessary, but this is
1314 				 * long enough for nearly anything. */
1315 } ExtraFrameInfo;
1316 
1317 /*
1318  *----------------------------------------------------------------
1319  * Data structures and procedures related to TclHandles, which are a very
1320  * lightweight method of preserving enough information to determine if an
1321  * arbitrary malloc'd block has been deleted.
1322  *----------------------------------------------------------------
1323  */
1324 
1325 typedef void **TclHandle;
1326 
1327 /*
1328  *----------------------------------------------------------------
1329  * Experimental flag value passed to Tcl_GetRegExpFromObj. Intended for use
1330  * only by Expect. It will probably go away in a later release.
1331  *----------------------------------------------------------------
1332  */
1333 
1334 #define TCL_REG_BOSONLY 002000	/* Prepend \A to pattern so it only matches at
1335 				 * the beginning of the string. */
1336 
1337 /*
1338  * These are a thin layer over TclpThreadKeyDataGet and TclpThreadKeyDataSet
1339  * when threads are used, or an emulation if there are no threads. These are
1340  * really internal and Tcl clients should use Tcl_GetThreadData.
1341  */
1342 
1343 MODULE_SCOPE void *	TclThreadDataKeyGet(Tcl_ThreadDataKey *keyPtr);
1344 MODULE_SCOPE void	TclThreadDataKeySet(Tcl_ThreadDataKey *keyPtr,
1345 			    void *data);
1346 
1347 /*
1348  * This is a convenience macro used to initialize a thread local storage ptr.
1349  */
1350 
1351 #define TCL_TSD_INIT(keyPtr) \
1352   (ThreadSpecificData *)Tcl_GetThreadData((keyPtr), sizeof(ThreadSpecificData))
1353 
1354 /*
1355  *----------------------------------------------------------------
1356  * Data structures related to bytecode compilation and execution. These are
1357  * used primarily in tclCompile.c, tclExecute.c, and tclBasic.c.
1358  *----------------------------------------------------------------
1359  */
1360 
1361 /*
1362  * Forward declaration to prevent errors when the forward references to
1363  * Tcl_Parse and CompileEnv are encountered in the procedure type CompileProc
1364  * declared below.
1365  */
1366 
1367 struct CompileEnv;
1368 
1369 /*
1370  * The type of procedures called by the Tcl bytecode compiler to compile
1371  * commands. Pointers to these procedures are kept in the Command structure
1372  * describing each command. The integer value returned by a CompileProc must
1373  * be one of the following:
1374  *
1375  * TCL_OK		Compilation completed normally.
1376  * TCL_ERROR 		Compilation could not be completed. This can be just a
1377  * 			judgment by the CompileProc that the command is too
1378  * 			complex to compile effectively, or it can indicate
1379  * 			that in the current state of the interp, the command
1380  * 			would raise an error. The bytecode compiler will not
1381  * 			do any error reporting at compiler time. Error
1382  * 			reporting is deferred until the actual runtime,
1383  * 			because by then changes in the interp state may allow
1384  * 			the command to be successfully evaluated.
1385  * TCL_OUT_LINE_COMPILE	A source-compatible alias for TCL_ERROR, kept for the
1386  * 			sake of old code only.
1387  */
1388 
1389 #define TCL_OUT_LINE_COMPILE	TCL_ERROR
1390 
1391 typedef int (CompileProc)(Tcl_Interp *interp, Tcl_Parse *parsePtr,
1392 	struct Command *cmdPtr, struct CompileEnv *compEnvPtr);
1393 
1394 /*
1395  * The type of procedure called from the compilation hook point in
1396  * SetByteCodeFromAny.
1397  */
1398 
1399 typedef int (CompileHookProc)(Tcl_Interp *interp,
1400 	struct CompileEnv *compEnvPtr, ClientData clientData);
1401 
1402 /*
1403  * The data structure for a (linked list of) execution stacks.
1404  */
1405 
1406 typedef struct ExecStack {
1407     struct ExecStack *prevPtr;
1408     struct ExecStack *nextPtr;
1409     Tcl_Obj **markerPtr;
1410     Tcl_Obj **endPtr;
1411     Tcl_Obj **tosPtr;
1412     Tcl_Obj *stackWords[TCLFLEXARRAY];
1413 } ExecStack;
1414 
1415 /*
1416  * The data structure defining the execution environment for ByteCode's.
1417  * There is one ExecEnv structure per Tcl interpreter. It holds the evaluation
1418  * stack that holds command operands and results. The stack grows towards
1419  * increasing addresses. The member stackPtr points to the stackItems of the
1420  * currently active execution stack.
1421  */
1422 
1423 typedef struct CorContext {
1424     struct CallFrame *framePtr;
1425     struct CallFrame *varFramePtr;
1426     struct CmdFrame *cmdFramePtr;  /* See Interp.cmdFramePtr */
1427     Tcl_HashTable *lineLABCPtr;    /* See Interp.lineLABCPtr */
1428 } CorContext;
1429 
1430 typedef struct CoroutineData {
1431     struct Command *cmdPtr;	/* The command handle for the coroutine. */
1432     struct ExecEnv *eePtr;	/* The special execution environment (stacks,
1433 				 * etc.) for the coroutine. */
1434     struct ExecEnv *callerEEPtr;/* The execution environment for the caller of
1435 				 * the coroutine, which might be the
1436 				 * interpreter global environment or another
1437 				 * coroutine. */
1438     CorContext caller;
1439     CorContext running;
1440     Tcl_HashTable *lineLABCPtr;    /* See Interp.lineLABCPtr */
1441     void *stackLevel;
1442     int auxNumLevels;		/* While the coroutine is running the
1443 				 * numLevels of the create/resume command is
1444 				 * stored here; for suspended coroutines it
1445 				 * holds the nesting numLevels at yield. */
1446     int nargs;                  /* Number of args required for resuming this
1447 				 * coroutine; -2 means "0 or 1" (default), -1
1448 				 * means "any" */
1449 } CoroutineData;
1450 
1451 typedef struct ExecEnv {
1452     ExecStack *execStackPtr;	/* Points to the first item in the evaluation
1453 				 * stack on the heap. */
1454     Tcl_Obj *constants[2];	/* Pointers to constant "0" and "1" objs. */
1455     struct Tcl_Interp *interp;
1456     struct NRE_callback *callbackPtr;
1457 				/* Top callback in NRE's stack. */
1458     struct CoroutineData *corPtr;
1459     int rewind;
1460 } ExecEnv;
1461 
1462 #define COR_IS_SUSPENDED(corPtr) \
1463     ((corPtr)->stackLevel == NULL)
1464 
1465 /*
1466  * The definitions for the LiteralTable and LiteralEntry structures. Each
1467  * interpreter contains a LiteralTable. It is used to reduce the storage
1468  * needed for all the Tcl objects that hold the literals of scripts compiled
1469  * by the interpreter. A literal's object is shared by all the ByteCodes that
1470  * refer to the literal. Each distinct literal has one LiteralEntry entry in
1471  * the LiteralTable. A literal table is a specialized hash table that is
1472  * indexed by the literal's string representation, which may contain null
1473  * characters.
1474  *
1475  * Note that we reduce the space needed for literals by sharing literal
1476  * objects both within a ByteCode (each ByteCode contains a local
1477  * LiteralTable) and across all an interpreter's ByteCodes (with the
1478  * interpreter's global LiteralTable).
1479  */
1480 
1481 typedef struct LiteralEntry {
1482     struct LiteralEntry *nextPtr;
1483 				/* Points to next entry in this hash bucket or
1484 				 * NULL if end of chain. */
1485     Tcl_Obj *objPtr;		/* Points to Tcl object that holds the
1486 				 * literal's bytes and length. */
1487     int refCount;		/* If in an interpreter's global literal
1488 				 * table, the number of ByteCode structures
1489 				 * that share the literal object; the literal
1490 				 * entry can be freed when refCount drops to
1491 				 * 0. If in a local literal table, -1. */
1492     Namespace *nsPtr;		/* Namespace in which this literal is used. We
1493 				 * try to avoid sharing literal non-FQ command
1494 				 * names among different namespaces to reduce
1495 				 * shimmering. */
1496 } LiteralEntry;
1497 
1498 typedef struct LiteralTable {
1499     LiteralEntry **buckets;	/* Pointer to bucket array. Each element
1500 				 * points to first entry in bucket's hash
1501 				 * chain, or NULL. */
1502     LiteralEntry *staticBuckets[TCL_SMALL_HASH_TABLE];
1503 				/* Bucket array used for small tables to avoid
1504 				 * mallocs and frees. */
1505     int numBuckets;		/* Total number of buckets allocated at
1506 				 * **buckets. */
1507     int numEntries;		/* Total number of entries present in
1508 				 * table. */
1509     int rebuildSize;		/* Enlarge table when numEntries gets to be
1510 				 * this large. */
1511     int mask;			/* Mask value used in hashing function. */
1512 } LiteralTable;
1513 
1514 /*
1515  * The following structure defines for each Tcl interpreter various
1516  * statistics-related information about the bytecode compiler and
1517  * interpreter's operation in that interpreter.
1518  */
1519 
1520 #ifdef TCL_COMPILE_STATS
1521 typedef struct ByteCodeStats {
1522     long numExecutions;		/* Number of ByteCodes executed. */
1523     long numCompilations;	/* Number of ByteCodes created. */
1524     long numByteCodesFreed;	/* Number of ByteCodes destroyed. */
1525     long instructionCount[256];	/* Number of times each instruction was
1526 				 * executed. */
1527 
1528     double totalSrcBytes;	/* Total source bytes ever compiled. */
1529     double totalByteCodeBytes;	/* Total bytes for all ByteCodes. */
1530     double currentSrcBytes;	/* Src bytes for all current ByteCodes. */
1531     double currentByteCodeBytes;/* Code bytes in all current ByteCodes. */
1532 
1533     long srcCount[32];		/* Source size distribution: # of srcs of
1534 				 * size [2**(n-1)..2**n), n in [0..32). */
1535     long byteCodeCount[32];	/* ByteCode size distribution. */
1536     long lifetimeCount[32];	/* ByteCode lifetime distribution (ms). */
1537 
1538     double currentInstBytes;	/* Instruction bytes-current ByteCodes. */
1539     double currentLitBytes;	/* Current literal bytes. */
1540     double currentExceptBytes;	/* Current exception table bytes. */
1541     double currentAuxBytes;	/* Current auxiliary information bytes. */
1542     double currentCmdMapBytes;	/* Current src<->code map bytes. */
1543 
1544     long numLiteralsCreated;	/* Total literal objects ever compiled. */
1545     double totalLitStringBytes;	/* Total string bytes in all literals. */
1546     double currentLitStringBytes;
1547 				/* String bytes in current literals. */
1548     long literalCount[32];	/* Distribution of literal string sizes. */
1549 } ByteCodeStats;
1550 #endif /* TCL_COMPILE_STATS */
1551 
1552 /*
1553  * Structure used in implementation of those core ensembles which are
1554  * partially compiled. Used as an array of these, with a terminating field
1555  * whose 'name' is NULL.
1556  */
1557 
1558 typedef struct {
1559     const char *name;		/* The name of the subcommand. */
1560     Tcl_ObjCmdProc *proc;	/* The implementation of the subcommand. */
1561     CompileProc *compileProc;	/* The compiler for the subcommand. */
1562     Tcl_ObjCmdProc *nreProc;	/* NRE implementation of this command. */
1563     ClientData clientData;	/* Any clientData to give the command. */
1564     int unsafe;			/* Whether this command is to be hidden by
1565 				 * default in a safe interpreter. */
1566 } EnsembleImplMap;
1567 
1568 /*
1569  *----------------------------------------------------------------
1570  * Data structures related to commands.
1571  *----------------------------------------------------------------
1572  */
1573 
1574 /*
1575  * An imported command is created in an namespace when it imports a "real"
1576  * command from another namespace. An imported command has a Command structure
1577  * that points (via its ClientData value) to the "real" Command structure in
1578  * the source namespace's command table. The real command records all the
1579  * imported commands that refer to it in a list of ImportRef structures so
1580  * that they can be deleted when the real command is deleted.
1581  */
1582 
1583 typedef struct ImportRef {
1584     struct Command *importedCmdPtr;
1585 				/* Points to the imported command created in
1586 				 * an importing namespace; this command
1587 				 * redirects its invocations to the "real"
1588 				 * command. */
1589     struct ImportRef *nextPtr;	/* Next element on the linked list of imported
1590 				 * commands that refer to the "real" command.
1591 				 * The real command deletes these imported
1592 				 * commands on this list when it is
1593 				 * deleted. */
1594 } ImportRef;
1595 
1596 /*
1597  * Data structure used as the ClientData of imported commands: commands
1598  * created in an namespace when it imports a "real" command from another
1599  * namespace.
1600  */
1601 
1602 typedef struct ImportedCmdData {
1603     struct Command *realCmdPtr;	/* "Real" command that this imported command
1604 				 * refers to. */
1605     struct Command *selfPtr;	/* Pointer to this imported command. Needed
1606 				 * only when deleting it in order to remove it
1607 				 * from the real command's linked list of
1608 				 * imported commands that refer to it. */
1609 } ImportedCmdData;
1610 
1611 /*
1612  * A Command structure exists for each command in a namespace. The Tcl_Command
1613  * opaque type actually refers to these structures.
1614  */
1615 
1616 typedef struct Command {
1617     Tcl_HashEntry *hPtr;	/* Pointer to the hash table entry that refers
1618 				 * to this command. The hash table is either a
1619 				 * namespace's command table or an
1620 				 * interpreter's hidden command table. This
1621 				 * pointer is used to get a command's name
1622 				 * from its Tcl_Command handle. NULL means
1623 				 * that the hash table entry has been removed
1624 				 * already (this can happen if deleteProc
1625 				 * causes the command to be deleted or
1626 				 * recreated). */
1627     Namespace *nsPtr;		/* Points to the namespace containing this
1628 				 * command. */
1629     int refCount;		/* 1 if in command hashtable plus 1 for each
1630 				 * reference from a CmdName Tcl object
1631 				 * representing a command's name in a ByteCode
1632 				 * instruction sequence. This structure can be
1633 				 * freed when refCount becomes zero. */
1634     int cmdEpoch;		/* Incremented to invalidate any references
1635 				 * that point to this command when it is
1636 				 * renamed, deleted, hidden, or exposed. */
1637     CompileProc *compileProc;	/* Procedure called to compile command. NULL
1638 				 * if no compile proc exists for command. */
1639     Tcl_ObjCmdProc *objProc;	/* Object-based command procedure. */
1640     ClientData objClientData;	/* Arbitrary value passed to object proc. */
1641     Tcl_CmdProc *proc;		/* String-based command procedure. */
1642     ClientData clientData;	/* Arbitrary value passed to string proc. */
1643     Tcl_CmdDeleteProc *deleteProc;
1644 				/* Procedure invoked when deleting command to,
1645 				 * e.g., free all client data. */
1646     ClientData deleteData;	/* Arbitrary value passed to deleteProc. */
1647     int flags;			/* Miscellaneous bits of information about
1648 				 * command. See below for definitions. */
1649     ImportRef *importRefPtr;	/* List of each imported Command created in
1650 				 * another namespace when this command is
1651 				 * imported. These imported commands redirect
1652 				 * invocations back to this command. The list
1653 				 * is used to remove all those imported
1654 				 * commands when deleting this "real"
1655 				 * command. */
1656     CommandTrace *tracePtr;	/* First in list of all traces set for this
1657 				 * command. */
1658     Tcl_ObjCmdProc *nreProc;	/* NRE implementation of this command. */
1659 } Command;
1660 
1661 /*
1662  * Flag bits for commands.
1663  *
1664  * CMD_IS_DELETED -		Means that the command is in the process of
1665  *				being deleted (its deleteProc is currently
1666  *				executing). Other attempts to delete the
1667  *				command should be ignored.
1668  * CMD_TRACE_ACTIVE -		1 means that trace processing is currently
1669  *				underway for a rename/delete change. See the
1670  *				two flags below for which is currently being
1671  *				processed.
1672  * CMD_HAS_EXEC_TRACES -	1 means that this command has at least one
1673  *				execution trace (as opposed to simple
1674  *				delete/rename traces) in its tracePtr list.
1675  * CMD_COMPILES_EXPANDED -	1 means that this command has a compiler that
1676  *				can handle expansion (provided it is not the
1677  *				first word).
1678  * TCL_TRACE_RENAME -		A rename trace is in progress. Further
1679  *				recursive renames will not be traced.
1680  * TCL_TRACE_DELETE -		A delete trace is in progress. Further
1681  *				recursive deletes will not be traced.
1682  * (these last two flags are defined in tcl.h)
1683  */
1684 
1685 #define CMD_IS_DELETED		    0x01
1686 #define CMD_TRACE_ACTIVE	    0x02
1687 #define CMD_HAS_EXEC_TRACES	    0x04
1688 #define CMD_COMPILES_EXPANDED	    0x08
1689 #define CMD_REDEF_IN_PROGRESS	    0x10
1690 #define CMD_VIA_RESOLVER	    0x20
1691 #define CMD_DEAD                    0x40
1692 
1693 
1694 /*
1695  *----------------------------------------------------------------
1696  * Data structures related to name resolution procedures.
1697  *----------------------------------------------------------------
1698  */
1699 
1700 /*
1701  * The interpreter keeps a linked list of name resolution schemes. The scheme
1702  * for a namespace is consulted first, followed by the list of schemes in an
1703  * interpreter, followed by the default name resolution in Tcl. Schemes are
1704  * added/removed from the interpreter's list by calling Tcl_AddInterpResolver
1705  * and Tcl_RemoveInterpResolver.
1706  */
1707 
1708 typedef struct ResolverScheme {
1709     char *name;			/* Name identifying this scheme. */
1710     Tcl_ResolveCmdProc *cmdResProc;
1711 				/* Procedure handling command name
1712 				 * resolution. */
1713     Tcl_ResolveVarProc *varResProc;
1714 				/* Procedure handling variable name resolution
1715 				 * for variables that can only be handled at
1716 				 * runtime. */
1717     Tcl_ResolveCompiledVarProc *compiledVarResProc;
1718 				/* Procedure handling variable name resolution
1719 				 * at compile time. */
1720 
1721     struct ResolverScheme *nextPtr;
1722 				/* Pointer to next record in linked list. */
1723 } ResolverScheme;
1724 
1725 /*
1726  * Forward declaration of the TIP#143 limit handler structure.
1727  */
1728 
1729 typedef struct LimitHandler LimitHandler;
1730 
1731 /*
1732  * TIP #268.
1733  * Values for the selection mode, i.e the package require preferences.
1734  */
1735 
1736 enum PkgPreferOptions {
1737     PKG_PREFER_LATEST, PKG_PREFER_STABLE
1738 };
1739 
1740 /*
1741  *----------------------------------------------------------------
1742  * This structure shadows the first few fields of the memory cache for the
1743  * allocator defined in tclThreadAlloc.c; it has to be kept in sync with the
1744  * definition there.
1745  * Some macros require knowledge of some fields in the struct in order to
1746  * avoid hitting the TSD unnecessarily. In order to facilitate this, a pointer
1747  * to the relevant fields is kept in the allocCache field in struct Interp.
1748  *----------------------------------------------------------------
1749  */
1750 
1751 typedef struct AllocCache {
1752     struct Cache *nextPtr;	/* Linked list of cache entries. */
1753     Tcl_ThreadId owner;		/* Which thread's cache is this? */
1754     Tcl_Obj *firstObjPtr;	/* List of free objects for thread. */
1755     int numObjects;		/* Number of objects for thread. */
1756 } AllocCache;
1757 
1758 /*
1759  *----------------------------------------------------------------
1760  * This structure defines an interpreter, which is a collection of commands
1761  * plus other state information related to interpreting commands, such as
1762  * variable storage. Primary responsibility for this data structure is in
1763  * tclBasic.c, but almost every Tcl source file uses something in here.
1764  *----------------------------------------------------------------
1765  */
1766 
1767 typedef struct Interp {
1768     /*
1769      * Note: the first three fields must match exactly the fields in a
1770      * Tcl_Interp struct (see tcl.h). If you change one, be sure to change the
1771      * other.
1772      *
1773      * The interpreter's result is held in both the string and the
1774      * objResultPtr fields. These fields hold, respectively, the result's
1775      * string or object value. The interpreter's result is always in the
1776      * result field if that is non-empty, otherwise it is in objResultPtr.
1777      * The two fields are kept consistent unless some C code sets
1778      * interp->result directly. Programs should not access result and
1779      * objResultPtr directly; instead, they should always get and set the
1780      * result using procedures such as Tcl_SetObjResult, Tcl_GetObjResult, and
1781      * Tcl_GetStringResult. See the SetResult man page for details.
1782      */
1783 
1784     char *result;		/* If the last command returned a string
1785 				 * result, this points to it. Should not be
1786 				 * accessed directly; see comment above. */
1787     Tcl_FreeProc *freeProc;	/* Zero means a string result is statically
1788 				 * allocated. TCL_DYNAMIC means string result
1789 				 * was allocated with ckalloc and should be
1790 				 * freed with ckfree. Other values give
1791 				 * address of procedure to invoke to free the
1792 				 * string result. Tcl_Eval must free it before
1793 				 * executing next command. */
1794     int errorLine;		/* When TCL_ERROR is returned, this gives the
1795 				 * line number in the command where the error
1796 				 * occurred (1 means first line). */
1797     const struct TclStubs *stubTable;
1798 				/* Pointer to the exported Tcl stub table. On
1799 				 * previous versions of Tcl this is a pointer
1800 				 * to the objResultPtr or a pointer to a
1801 				 * buckets array in a hash table. We therefore
1802 				 * have to do some careful checking before we
1803 				 * can use this. */
1804 
1805     TclHandle handle;		/* Handle used to keep track of when this
1806 				 * interp is deleted. */
1807 
1808     Namespace *globalNsPtr;	/* The interpreter's global namespace. */
1809     Tcl_HashTable *hiddenCmdTablePtr;
1810 				/* Hash table used by tclBasic.c to keep track
1811 				 * of hidden commands on a per-interp
1812 				 * basis. */
1813     ClientData interpInfo;	/* Information used by tclInterp.c to keep
1814 				 * track of parent/child interps on a
1815 				 * per-interp basis. */
1816     union {
1817 	void (*optimizer)(void *envPtr);
1818 	Tcl_HashTable unused2;	/* No longer used (was mathFuncTable). The
1819 				 * unused space in interp was repurposed for
1820 				 * pluggable bytecode optimizers. The core
1821 				 * contains one optimizer, which can be
1822 				 * selectively overridden by extensions. */
1823     } extra;
1824 
1825     /*
1826      * Information related to procedures and variables. See tclProc.c and
1827      * tclVar.c for usage.
1828      */
1829 
1830     int numLevels;		/* Keeps track of how many nested calls to
1831 				 * Tcl_Eval are in progress for this
1832 				 * interpreter. It's used to delay deletion of
1833 				 * the table until all Tcl_Eval invocations
1834 				 * are completed. */
1835     int maxNestingDepth;	/* If numLevels exceeds this value then Tcl
1836 				 * assumes that infinite recursion has
1837 				 * occurred and it generates an error. */
1838     CallFrame *framePtr;	/* Points to top-most in stack of all nested
1839 				 * procedure invocations. */
1840     CallFrame *varFramePtr;	/* Points to the call frame whose variables
1841 				 * are currently in use (same as framePtr
1842 				 * unless an "uplevel" command is
1843 				 * executing). */
1844     ActiveVarTrace *activeVarTracePtr;
1845 				/* First in list of active traces for interp,
1846 				 * or NULL if no active traces. */
1847     int returnCode;		/* [return -code] parameter. */
1848     CallFrame *rootFramePtr;	/* Global frame pointer for this
1849 				 * interpreter. */
1850     Namespace *lookupNsPtr;	/* Namespace to use ONLY on the next
1851 				 * TCL_EVAL_INVOKE call to Tcl_EvalObjv. */
1852 
1853     /*
1854      * Information used by Tcl_AppendResult to keep track of partial results.
1855      * See Tcl_AppendResult code for details.
1856      */
1857 
1858     char *appendResult;		/* Storage space for results generated by
1859 				 * Tcl_AppendResult. Ckalloc-ed. NULL means
1860 				 * not yet allocated. */
1861     int appendAvl;		/* Total amount of space available at
1862 				 * partialResult. */
1863     int appendUsed;		/* Number of non-null bytes currently stored
1864 				 * at partialResult. */
1865 
1866     /*
1867      * Information about packages. Used only in tclPkg.c.
1868      */
1869 
1870     Tcl_HashTable packageTable;	/* Describes all of the packages loaded in or
1871 				 * available to this interpreter. Keys are
1872 				 * package names, values are (Package *)
1873 				 * pointers. */
1874     char *packageUnknown;	/* Command to invoke during "package require"
1875 				 * commands for packages that aren't described
1876 				 * in packageTable. Ckalloc'ed, may be
1877 				 * NULL. */
1878     /*
1879      * Miscellaneous information:
1880      */
1881 
1882     int cmdCount;		/* Total number of times a command procedure
1883 				 * has been called for this interpreter. */
1884     int evalFlags;		/* Flags to control next call to Tcl_Eval.
1885 				 * Normally zero, but may be set before
1886 				 * calling Tcl_Eval. See below for valid
1887 				 * values. */
1888     int unused1;		/* No longer used (was termOffset) */
1889     LiteralTable literalTable;	/* Contains LiteralEntry's describing all Tcl
1890 				 * objects holding literals of scripts
1891 				 * compiled by the interpreter. Indexed by the
1892 				 * string representations of literals. Used to
1893 				 * avoid creating duplicate objects. */
1894     int compileEpoch;		/* Holds the current "compilation epoch" for
1895 				 * this interpreter. This is incremented to
1896 				 * invalidate existing ByteCodes when, e.g., a
1897 				 * command with a compile procedure is
1898 				 * redefined. */
1899     Proc *compiledProcPtr;	/* If a procedure is being compiled, a pointer
1900 				 * to its Proc structure; otherwise, this is
1901 				 * NULL. Set by ObjInterpProc in tclProc.c and
1902 				 * used by tclCompile.c to process local
1903 				 * variables appropriately. */
1904     ResolverScheme *resolverPtr;
1905 				/* Linked list of name resolution schemes
1906 				 * added to this interpreter. Schemes are
1907 				 * added and removed by calling
1908 				 * Tcl_AddInterpResolvers and
1909 				 * Tcl_RemoveInterpResolver respectively. */
1910     Tcl_Obj *scriptFile;	/* NULL means there is no nested source
1911 				 * command active; otherwise this points to
1912 				 * pathPtr of the file being sourced. */
1913     int flags;			/* Various flag bits. See below. */
1914     long randSeed;		/* Seed used for rand() function. */
1915     Trace *tracePtr;		/* List of traces for this interpreter. */
1916     Tcl_HashTable *assocData;	/* Hash table for associating data with this
1917 				 * interpreter. Cleaned up when this
1918 				 * interpreter is deleted. */
1919     struct ExecEnv *execEnvPtr;	/* Execution environment for Tcl bytecode
1920 				 * execution. Contains a pointer to the Tcl
1921 				 * evaluation stack. */
1922     Tcl_Obj *emptyObjPtr;	/* Points to an object holding an empty
1923 				 * string. Returned by Tcl_ObjSetVar2 when
1924 				 * variable traces change a variable in a
1925 				 * gross way. */
1926     char resultSpace[TCL_RESULT_SIZE+1];
1927 				/* Static space holding small results. */
1928     Tcl_Obj *objResultPtr;	/* If the last command returned an object
1929 				 * result, this points to it. Should not be
1930 				 * accessed directly; see comment above. */
1931     Tcl_ThreadId threadId;	/* ID of thread that owns the interpreter. */
1932 
1933     ActiveCommandTrace *activeCmdTracePtr;
1934 				/* First in list of active command traces for
1935 				 * interp, or NULL if no active traces. */
1936     ActiveInterpTrace *activeInterpTracePtr;
1937 				/* First in list of active traces for interp,
1938 				 * or NULL if no active traces. */
1939 
1940     int tracesForbiddingInline;	/* Count of traces (in the list headed by
1941 				 * tracePtr) that forbid inline bytecode
1942 				 * compilation. */
1943 
1944     /*
1945      * Fields used to manage extensible return options (TIP 90).
1946      */
1947 
1948     Tcl_Obj *returnOpts;	/* A dictionary holding the options to the
1949 				 * last [return] command. */
1950 
1951     Tcl_Obj *errorInfo;		/* errorInfo value (now as a Tcl_Obj). */
1952     Tcl_Obj *eiVar;		/* cached ref to ::errorInfo variable. */
1953     Tcl_Obj *errorCode;		/* errorCode value (now as a Tcl_Obj). */
1954     Tcl_Obj *ecVar;		/* cached ref to ::errorInfo variable. */
1955     int returnLevel;		/* [return -level] parameter. */
1956 
1957     /*
1958      * Resource limiting framework support (TIP#143).
1959      */
1960 
1961     struct {
1962 	int active;		/* Flag values defining which limits have been
1963 				 * set. */
1964 	int granularityTicker;	/* Counter used to determine how often to
1965 				 * check the limits. */
1966 	int exceeded;		/* Which limits have been exceeded, described
1967 				 * as flag values the same as the 'active'
1968 				 * field. */
1969 
1970 	int cmdCount;		/* Limit for how many commands to execute in
1971 				 * the interpreter. */
1972 	LimitHandler *cmdHandlers;
1973 				/* Handlers to execute when the limit is
1974 				 * reached. */
1975 	int cmdGranularity;	/* Mod factor used to determine how often to
1976 				 * evaluate the limit check. */
1977 
1978 	Tcl_Time time;		/* Time limit for execution within the
1979 				 * interpreter. */
1980 	LimitHandler *timeHandlers;
1981 				/* Handlers to execute when the limit is
1982 				 * reached. */
1983 	int timeGranularity;	/* Mod factor used to determine how often to
1984 				 * evaluate the limit check. */
1985 	Tcl_TimerToken timeEvent;
1986 				/* Handle for a timer callback that will occur
1987 				 * when the time-limit is exceeded. */
1988 
1989 	Tcl_HashTable callbacks;/* Mapping from (interp,type) pair to data
1990 				 * used to install a limit handler callback to
1991 				 * run in _this_ interp when the limit is
1992 				 * exceeded. */
1993     } limit;
1994 
1995     /*
1996      * Information for improved default error generation from ensembles
1997      * (TIP#112).
1998      */
1999 
2000     struct {
2001 	Tcl_Obj *const *sourceObjs;
2002 				/* What arguments were actually input into the
2003 				 * *root* ensemble command? (Nested ensembles
2004 				 * don't rewrite this.) NULL if we're not
2005 				 * processing an ensemble. */
2006 	int numRemovedObjs;	/* How many arguments have been stripped off
2007 				 * because of ensemble processing. */
2008 	int numInsertedObjs;	/* How many of the current arguments were
2009 				 * inserted by an ensemble. */
2010     } ensembleRewrite;
2011 
2012     /*
2013      * TIP #219: Global info for the I/O system.
2014      */
2015 
2016     Tcl_Obj *chanMsg;		/* Error message set by channel drivers, for
2017 				 * the propagation of arbitrary Tcl errors.
2018 				 * This information, if present (chanMsg not
2019 				 * NULL), takes precedence over a POSIX error
2020 				 * code returned by a channel operation. */
2021 
2022     /*
2023      * Source code origin information (TIP #280).
2024      */
2025 
2026     CmdFrame *cmdFramePtr;	/* Points to the command frame containing the
2027 				 * location information for the current
2028 				 * command. */
2029     const CmdFrame *invokeCmdFramePtr;
2030 				/* Points to the command frame which is the
2031 				 * invoking context of the bytecode compiler.
2032 				 * NULL when the byte code compiler is not
2033 				 * active. */
2034     int invokeWord;		/* Index of the word in the command which
2035 				 * is getting compiled. */
2036     Tcl_HashTable *linePBodyPtr;/* This table remembers for each statically
2037 				 * defined procedure the location information
2038 				 * for its body. It is keyed by the address of
2039 				 * the Proc structure for a procedure. The
2040 				 * values are "struct CmdFrame*". */
2041     Tcl_HashTable *lineBCPtr;	/* This table remembers for each ByteCode
2042 				 * object the location information for its
2043 				 * body. It is keyed by the address of the
2044 				 * Proc structure for a procedure. The values
2045 				 * are "struct ExtCmdLoc*". (See
2046 				 * tclCompile.h) */
2047     Tcl_HashTable *lineLABCPtr;
2048     Tcl_HashTable *lineLAPtr;	/* This table remembers for each argument of a
2049 				 * command on the execution stack the index of
2050 				 * the argument in the command, and the
2051 				 * location data of the command. It is keyed
2052 				 * by the address of the Tcl_Obj containing
2053 				 * the argument. The values are "struct
2054 				 * CFWord*" (See tclBasic.c). This allows
2055 				 * commands like uplevel, eval, etc. to find
2056 				 * location information for their arguments,
2057 				 * if they are a proper literal argument to an
2058 				 * invoking command. Alt view: An index to the
2059 				 * CmdFrame stack keyed by command argument
2060 				 * holders. */
2061     ContLineLoc *scriptCLLocPtr;/* This table points to the location data for
2062 				 * invisible continuation lines in the script,
2063 				 * if any. This pointer is set by the function
2064 				 * TclEvalObjEx() in file "tclBasic.c", and
2065 				 * used by function ...() in the same file.
2066 				 * It does for the eval/direct path of script
2067 				 * execution what CompileEnv.clLoc does for
2068 				 * the bytecode compiler.
2069 				 */
2070     /*
2071      * TIP #268. The currently active selection mode, i.e. the package require
2072      * preferences.
2073      */
2074 
2075     int packagePrefer;		/* Current package selection mode. */
2076 
2077     /*
2078      * Hashtables for variable traces and searches.
2079      */
2080 
2081     Tcl_HashTable varTraces;	/* Hashtable holding the start of a variable's
2082 				 * active trace list; varPtr is the key. */
2083     Tcl_HashTable varSearches;	/* Hashtable holding the start of a variable's
2084 				 * active searches list; varPtr is the key. */
2085     /*
2086      * The thread-specific data ekeko: cache pointers or values that
2087      *  (a) do not change during the thread's lifetime
2088      *  (b) require access to TSD to determine at runtime
2089      *  (c) are accessed very often (e.g., at each command call)
2090      *
2091      * Note that these are the same for all interps in the same thread. They
2092      * just have to be initialised for the thread's parent interp, children
2093      * inherit the value.
2094      *
2095      * They are used by the macros defined below.
2096      */
2097 
2098     AllocCache *allocCache;
2099     void *pendingObjDataPtr;	/* Pointer to the Cache and PendingObjData
2100 				 * structs for this interp's thread; see
2101 				 * tclObj.c and tclThreadAlloc.c */
2102     int *asyncReadyPtr;		/* Pointer to the asyncReady indicator for
2103 				 * this interp's thread; see tclAsync.c */
2104     /*
2105      * The pointer to the object system root ekeko. c.f. TIP #257.
2106      */
2107     void *objectFoundation;	/* Pointer to the Foundation structure of the
2108 				 * object system, which contains things like
2109 				 * references to key namespaces. See
2110 				 * tclOOInt.h and tclOO.c for real definition
2111 				 * and setup. */
2112 
2113     struct NRE_callback *deferredCallbacks;
2114 				/* Callbacks that are set previous to a call
2115 				 * to some Eval function but that actually
2116 				 * belong to the command that is about to be
2117 				 * called - i.e., they should be run *before*
2118 				 * any tailcall is invoked. */
2119 
2120     /*
2121      * TIP #285, Script cancellation support.
2122      */
2123 
2124     Tcl_AsyncHandler asyncCancel;
2125 				/* Async handler token for Tcl_CancelEval. */
2126     Tcl_Obj *asyncCancelMsg;	/* Error message set by async cancel handler
2127 				 * for the propagation of arbitrary Tcl
2128 				 * errors. This information, if present
2129 				 * (asyncCancelMsg not NULL), takes precedence
2130 				 * over the default error messages returned by
2131 				 * a script cancellation operation. */
2132 
2133 	/*
2134 	 * TIP #348 IMPLEMENTATION  -  Substituted error stack
2135 	 */
2136     Tcl_Obj *errorStack;	/* [info errorstack] value (as a Tcl_Obj). */
2137     Tcl_Obj *upLiteral;		/* "UP" literal for [info errorstack] */
2138     Tcl_Obj *callLiteral;	/* "CALL" literal for [info errorstack] */
2139     Tcl_Obj *innerLiteral;	/* "INNER" literal for [info errorstack] */
2140     Tcl_Obj *innerContext;	/* cached list for fast reallocation */
2141     int resetErrorStack;        /* controls cleaning up of ::errorStack */
2142 
2143 #ifdef TCL_COMPILE_STATS
2144     /*
2145      * Statistical information about the bytecode compiler and interpreter's
2146      * operation. This should be the last field of Interp.
2147      */
2148 
2149     ByteCodeStats stats;	/* Holds compilation and execution statistics
2150 				 * for this interpreter. */
2151 #endif /* TCL_COMPILE_STATS */
2152 } Interp;
2153 
2154 /*
2155  * Macros that use the TSD-ekeko.
2156  */
2157 
2158 #define TclAsyncReady(iPtr) \
2159     *((iPtr)->asyncReadyPtr)
2160 
2161 /*
2162  * Macros for script cancellation support (TIP #285).
2163  */
2164 
2165 #define TclCanceled(iPtr) \
2166     (((iPtr)->flags & CANCELED) || ((iPtr)->flags & TCL_CANCEL_UNWIND))
2167 
2168 #define TclSetCancelFlags(iPtr, cancelFlags)   \
2169     (iPtr)->flags |= CANCELED;                 \
2170     if ((cancelFlags) & TCL_CANCEL_UNWIND) {   \
2171         (iPtr)->flags |= TCL_CANCEL_UNWIND;    \
2172     }
2173 
2174 #define TclUnsetCancelFlags(iPtr) \
2175     (iPtr)->flags &= (~(CANCELED | TCL_CANCEL_UNWIND))
2176 
2177 /*
2178  * Macros for splicing into and out of doubly linked lists. They assume
2179  * existence of struct items 'prevPtr' and 'nextPtr'.
2180  *
2181  * a = element to add or remove.
2182  * b = list head.
2183  *
2184  * TclSpliceIn adds to the head of the list.
2185  */
2186 
2187 #define TclSpliceIn(a,b)			\
2188     (a)->nextPtr = (b);				\
2189     if ((b) != NULL) {				\
2190 	(b)->prevPtr = (a);			\
2191     }						\
2192     (a)->prevPtr = NULL, (b) = (a);
2193 
2194 #define TclSpliceOut(a,b)			\
2195     if ((a)->prevPtr != NULL) {			\
2196 	(a)->prevPtr->nextPtr = (a)->nextPtr;	\
2197     } else {					\
2198 	(b) = (a)->nextPtr;			\
2199     }						\
2200     if ((a)->nextPtr != NULL) {			\
2201 	(a)->nextPtr->prevPtr = (a)->prevPtr;	\
2202     }
2203 
2204 /*
2205  * EvalFlag bits for Interp structures:
2206  *
2207  * TCL_ALLOW_EXCEPTIONS	1 means it's OK for the script to terminate with a
2208  *			code other than TCL_OK or TCL_ERROR; 0 means codes
2209  *			other than these should be turned into errors.
2210  */
2211 
2212 #define TCL_ALLOW_EXCEPTIONS		0x04
2213 #define TCL_EVAL_FILE			0x02
2214 #define TCL_EVAL_SOURCE_IN_FRAME	0x10
2215 #define TCL_EVAL_NORESOLVE		0x20
2216 #define TCL_EVAL_DISCARD_RESULT		0x40
2217 
2218 /*
2219  * Flag bits for Interp structures:
2220  *
2221  * DELETED:		Non-zero means the interpreter has been deleted:
2222  *			don't process any more commands for it, and destroy
2223  *			the structure as soon as all nested invocations of
2224  *			Tcl_Eval are done.
2225  * ERR_ALREADY_LOGGED:	Non-zero means information has already been logged in
2226  *			iPtr->errorInfo for the current Tcl_Eval instance, so
2227  *			Tcl_Eval needn't log it (used to implement the "error
2228  *			message log" command).
2229  * DONT_COMPILE_CMDS_INLINE: Non-zero means that the bytecode compiler should
2230  *			not compile any commands into an inline sequence of
2231  *			instructions. This is set 1, for example, when command
2232  *			traces are requested.
2233  * RAND_SEED_INITIALIZED: Non-zero means that the randSeed value of the interp
2234  *			has not be initialized. This is set 1 when we first
2235  *			use the rand() or srand() functions.
2236  * SAFE_INTERP:		Non zero means that the current interp is a safe
2237  *			interp (i.e. it has only the safe commands installed,
2238  *			less privilege than a regular interp).
2239  * INTERP_DEBUG_FRAME:	Used for switching on various extra interpreter
2240  *			debug/info mechanisms (e.g. info frame eval/uplevel
2241  *			tracing) which are performance intensive.
2242  * INTERP_TRACE_IN_PROGRESS: Non-zero means that an interp trace is currently
2243  *			active; so no further trace callbacks should be
2244  *			invoked.
2245  * INTERP_ALTERNATE_WRONG_ARGS: Used for listing second and subsequent forms
2246  *			of the wrong-num-args string in Tcl_WrongNumArgs.
2247  *			Makes it append instead of replacing and uses
2248  *			different intermediate text.
2249  * CANCELED:		Non-zero means that the script in progress should be
2250  *			canceled as soon as possible. This can be checked by
2251  *			extensions (and the core itself) by calling
2252  *			Tcl_Canceled and checking if TCL_ERROR is returned.
2253  *			This is a one-shot flag that is reset immediately upon
2254  *			being detected; however, if the TCL_CANCEL_UNWIND flag
2255  *			is set Tcl_Canceled will continue to report that the
2256  *			script in progress has been canceled thereby allowing
2257  *			the evaluation stack for the interp to be fully
2258  *			unwound.
2259  *
2260  * WARNING: For the sake of some extensions that have made use of former
2261  * internal values, do not re-use the flag values 2 (formerly ERR_IN_PROGRESS)
2262  * or 8 (formerly ERROR_CODE_SET).
2263  */
2264 
2265 #define DELETED				     1
2266 #define ERR_ALREADY_LOGGED		     4
2267 #define INTERP_DEBUG_FRAME		  0x10
2268 #define DONT_COMPILE_CMDS_INLINE	  0x20
2269 #define RAND_SEED_INITIALIZED		  0x40
2270 #define SAFE_INTERP			  0x80
2271 #define INTERP_TRACE_IN_PROGRESS	 0x200
2272 #define INTERP_ALTERNATE_WRONG_ARGS	 0x400
2273 #define ERR_LEGACY_COPY			 0x800
2274 #define CANCELED			0x1000
2275 
2276 /*
2277  * Maximum number of levels of nesting permitted in Tcl commands (used to
2278  * catch infinite recursion).
2279  */
2280 
2281 #define MAX_NESTING_DEPTH	1000
2282 
2283 /*
2284  * The macro below is used to modify a "char" value (e.g. by casting it to an
2285  * unsigned character) so that it can be used safely with macros such as
2286  * isspace.
2287  */
2288 
2289 #define UCHAR(c) ((unsigned char) (c))
2290 
2291 /*
2292  * This macro is used to properly align the memory allocated by Tcl, giving
2293  * the same alignment as the native malloc.
2294  */
2295 
2296 #if defined(__APPLE__)
2297 #define TCL_ALLOCALIGN	16
2298 #else
2299 #define TCL_ALLOCALIGN	(2*sizeof(void *))
2300 #endif
2301 
2302 /*
2303  * This macro is used to determine the offset needed to safely allocate any
2304  * data structure in memory. Given a starting offset or size, it "rounds up"
2305  * or "aligns" the offset to the next 8-byte boundary so that any data
2306  * structure can be placed at the resulting offset without fear of an
2307  * alignment error.
2308  *
2309  * WARNING!! DO NOT USE THIS MACRO TO ALIGN POINTERS: it will produce the
2310  * wrong result on platforms that allocate addresses that are divisible by 4
2311  * or 2. Only use it for offsets or sizes.
2312  *
2313  * This macro is only used by tclCompile.c in the core (Bug 926445). It
2314  * however not be made file static, as extensions that touch bytecodes
2315  * (notably tbcload) require it.
2316  */
2317 
2318 #define TCL_ALIGN(x) (((int)(x) + 7) & ~7)
2319 
2320 /*
2321  * The following enum values are used to specify the runtime platform setting
2322  * of the tclPlatform variable.
2323  */
2324 
2325 typedef enum {
2326     TCL_PLATFORM_UNIX = 0,	/* Any Unix-like OS. */
2327     TCL_PLATFORM_WINDOWS = 2	/* Any Microsoft Windows OS. */
2328 } TclPlatformType;
2329 
2330 /*
2331  * The following enum values are used to indicate the translation of a Tcl
2332  * channel. Declared here so that each platform can define
2333  * TCL_PLATFORM_TRANSLATION to the native translation on that platform.
2334  */
2335 
2336 typedef enum TclEolTranslation {
2337     TCL_TRANSLATE_AUTO,		/* Eol == \r, \n and \r\n. */
2338     TCL_TRANSLATE_CR,		/* Eol == \r. */
2339     TCL_TRANSLATE_LF,		/* Eol == \n. */
2340     TCL_TRANSLATE_CRLF		/* Eol == \r\n. */
2341 } TclEolTranslation;
2342 
2343 /*
2344  * Flags for TclInvoke:
2345  *
2346  * TCL_INVOKE_HIDDEN		Invoke a hidden command; if not set, invokes
2347  *				an exposed command.
2348  * TCL_INVOKE_NO_UNKNOWN	If set, "unknown" is not invoked if the
2349  *				command to be invoked is not found. Only has
2350  *				an effect if invoking an exposed command,
2351  *				i.e. if TCL_INVOKE_HIDDEN is not also set.
2352  * TCL_INVOKE_NO_TRACEBACK	Does not record traceback information if the
2353  *				invoked command returns an error. Used if the
2354  *				caller plans on recording its own traceback
2355  *				information.
2356  */
2357 
2358 #define	TCL_INVOKE_HIDDEN	(1<<0)
2359 #define TCL_INVOKE_NO_UNKNOWN	(1<<1)
2360 #define TCL_INVOKE_NO_TRACEBACK	(1<<2)
2361 
2362 /*
2363  * The structure used as the internal representation of Tcl list objects. This
2364  * struct is grown (reallocated and copied) as necessary to hold all the
2365  * list's element pointers. The struct might contain more slots than currently
2366  * used to hold all element pointers. This is done to make append operations
2367  * faster.
2368  */
2369 
2370 typedef struct List {
2371     int refCount;
2372     int maxElemCount;		/* Total number of element array slots. */
2373     int elemCount;		/* Current number of list elements. */
2374     int canonicalFlag;		/* Set if the string representation was
2375 				 * derived from the list representation. May
2376 				 * be ignored if there is no string rep at
2377 				 * all.*/
2378     Tcl_Obj *elements;		/* First list element; the struct is grown to
2379 				 * accommodate all elements. */
2380 } List;
2381 
2382 #define LIST_MAX \
2383 	(1 + (int)(((size_t)UINT_MAX - sizeof(List))/sizeof(Tcl_Obj *)))
2384 #define LIST_SIZE(numElems) \
2385 	(unsigned)(sizeof(List) + (((numElems) - 1) * sizeof(Tcl_Obj *)))
2386 
2387 /*
2388  * Macro used to get the elements of a list object.
2389  */
2390 
2391 #define ListRepPtr(listPtr) \
2392     ((List *) (listPtr)->internalRep.twoPtrValue.ptr1)
2393 
2394 /* Not used any more */
2395 #define ListSetIntRep(objPtr, listRepPtr) \
2396     (objPtr)->internalRep.twoPtrValue.ptr1 = (void *)(listRepPtr), \
2397     (objPtr)->internalRep.twoPtrValue.ptr2 = NULL, \
2398     (listRepPtr)->refCount++, \
2399     (objPtr)->typePtr = &tclListType
2400 
2401 #define ListObjGetElements(listPtr, objc, objv) \
2402     ((objv) = &(ListRepPtr(listPtr)->elements), \
2403      (objc) = ListRepPtr(listPtr)->elemCount)
2404 
2405 #define ListObjLength(listPtr, len) \
2406     ((len) = ListRepPtr(listPtr)->elemCount)
2407 
2408 #define ListObjIsCanonical(listPtr) \
2409     (((listPtr)->bytes == NULL) || ListRepPtr(listPtr)->canonicalFlag)
2410 
2411 #define TclListObjGetElements(interp, listPtr, objcPtr, objvPtr) \
2412     (((listPtr)->typePtr == &tclListType) \
2413 	    ? ((ListObjGetElements((listPtr), *(objcPtr), *(objvPtr))), TCL_OK)\
2414 	    : Tcl_ListObjGetElements((interp), (listPtr), (objcPtr), (objvPtr)))
2415 
2416 #define TclListObjLength(interp, listPtr, lenPtr) \
2417     (((listPtr)->typePtr == &tclListType) \
2418 	    ? ((ListObjLength((listPtr), *(lenPtr))), TCL_OK)\
2419 	    : Tcl_ListObjLength((interp), (listPtr), (lenPtr)))
2420 
2421 #define TclListObjIsCanonical(listPtr) \
2422     (((listPtr)->typePtr == &tclListType) ? ListObjIsCanonical((listPtr)) : 0)
2423 
2424 /*
2425  * Modes for collecting (or not) in the implementations of TclNRForeachCmd,
2426  * TclNRLmapCmd and their compilations.
2427  */
2428 
2429 #define TCL_EACH_KEEP_NONE  0	/* Discard iteration result like [foreach] */
2430 #define TCL_EACH_COLLECT    1	/* Collect iteration result like [lmap] */
2431 
2432 /*
2433  * Macros providing a faster path to integers: Tcl_GetLongFromObj,
2434  * Tcl_GetIntFromObj and TclGetIntForIndex.
2435  *
2436  * WARNING: these macros eval their args more than once.
2437  */
2438 
2439 #define TclGetLongFromObj(interp, objPtr, longPtr) \
2440     (((objPtr)->typePtr == &tclIntType)	\
2441 	    ? ((*(longPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2442 	    : Tcl_GetLongFromObj((interp), (objPtr), (longPtr)))
2443 
2444 #if (LONG_MAX == INT_MAX)
2445 #define TclGetIntFromObj(interp, objPtr, intPtr) \
2446     (((objPtr)->typePtr == &tclIntType)	\
2447 	    ? ((*(intPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2448 	    : Tcl_GetIntFromObj((interp), (objPtr), (intPtr)))
2449 #define TclGetIntForIndexM(interp, objPtr, endValue, idxPtr) \
2450     (((objPtr)->typePtr == &tclIntType)	\
2451 	    ? ((*(idxPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2452 	    : TclGetIntForIndex((interp), (objPtr), (endValue), (idxPtr)))
2453 #else
2454 #define TclGetIntFromObj(interp, objPtr, intPtr) \
2455     (((objPtr)->typePtr == &tclIntType \
2456 	    && (objPtr)->internalRep.longValue >= -(Tcl_WideInt)(UINT_MAX) \
2457 	    && (objPtr)->internalRep.longValue <= (Tcl_WideInt)(UINT_MAX))	\
2458 	    ? ((*(intPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2459 	    : Tcl_GetIntFromObj((interp), (objPtr), (intPtr)))
2460 #define TclGetIntForIndexM(interp, objPtr, endValue, idxPtr) \
2461     (((objPtr)->typePtr == &tclIntType \
2462 	    && (objPtr)->internalRep.longValue >= INT_MIN \
2463 	    && (objPtr)->internalRep.longValue <= INT_MAX)	\
2464 	    ? ((*(idxPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2465 	    : TclGetIntForIndex((interp), (objPtr), (endValue), (idxPtr)))
2466 #endif
2467 
2468 /*
2469  * Macro used to save a function call for common uses of
2470  * Tcl_GetWideIntFromObj(). The ANSI C "prototype" is:
2471  *
2472  * MODULE_SCOPE int TclGetWideIntFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
2473  *			Tcl_WideInt *wideIntPtr);
2474  */
2475 
2476 #ifdef TCL_WIDE_INT_IS_LONG
2477 #define TclGetWideIntFromObj(interp, objPtr, wideIntPtr) \
2478     (((objPtr)->typePtr == &tclIntType)					\
2479 	? (*(wideIntPtr) = (Tcl_WideInt)				\
2480 		((objPtr)->internalRep.longValue), TCL_OK) :		\
2481 	Tcl_GetWideIntFromObj((interp), (objPtr), (wideIntPtr)))
2482 #else /* !TCL_WIDE_INT_IS_LONG */
2483 #define TclGetWideIntFromObj(interp, objPtr, wideIntPtr)		\
2484     (((objPtr)->typePtr == &tclWideIntType)				\
2485 	? (*(wideIntPtr) = (objPtr)->internalRep.wideValue, TCL_OK) :	\
2486     ((objPtr)->typePtr == &tclIntType)					\
2487 	? (*(wideIntPtr) = (Tcl_WideInt)				\
2488 		((objPtr)->internalRep.longValue), TCL_OK) :		\
2489 	Tcl_GetWideIntFromObj((interp), (objPtr), (wideIntPtr)))
2490 #endif /* TCL_WIDE_INT_IS_LONG */
2491 
2492 /*
2493  * Flag values for TclTraceDictPath().
2494  *
2495  * DICT_PATH_READ indicates that all entries on the path must exist but no
2496  * updates will be needed.
2497  *
2498  * DICT_PATH_UPDATE indicates that we are going to be doing an update at the
2499  * tip of the path, so duplication of shared objects should be done along the
2500  * way.
2501  *
2502  * DICT_PATH_EXISTS indicates that we are performing an existence test and a
2503  * lookup failure should therefore not be an error. If (and only if) this flag
2504  * is set, TclTraceDictPath() will return the special value
2505  * DICT_PATH_NON_EXISTENT if the path is not traceable.
2506  *
2507  * DICT_PATH_CREATE (which also requires the DICT_PATH_UPDATE bit to be set)
2508  * indicates that we are to create non-existent dictionaries on the path.
2509  */
2510 
2511 #define DICT_PATH_READ		0
2512 #define DICT_PATH_UPDATE	1
2513 #define DICT_PATH_EXISTS	2
2514 #define DICT_PATH_CREATE	5
2515 
2516 #define DICT_PATH_NON_EXISTENT	((Tcl_Obj *) (void *) 1)
2517 
2518 /*
2519  *----------------------------------------------------------------
2520  * Data structures related to the filesystem internals
2521  *----------------------------------------------------------------
2522  */
2523 
2524 /*
2525  * The version_2 filesystem is private to Tcl. As and when these changes have
2526  * been thoroughly tested and investigated a new public filesystem interface
2527  * will be released. The aim is more versatile virtual filesystem interfaces,
2528  * more efficiency in 'path' manipulation and usage, and cleaner filesystem
2529  * code internally.
2530  */
2531 
2532 #define TCL_FILESYSTEM_VERSION_2	((Tcl_FSVersion) 0x2)
2533 typedef ClientData (TclFSGetCwdProc2)(ClientData clientData);
2534 typedef int (Tcl_FSLoadFileProc2) (Tcl_Interp *interp, Tcl_Obj *pathPtr,
2535 	Tcl_LoadHandle *handlePtr, Tcl_FSUnloadFileProc **unloadProcPtr, int flags);
2536 
2537 /*
2538  * The following types are used for getting and storing platform-specific file
2539  * attributes in tclFCmd.c and the various platform-versions of that file.
2540  * This is done to have as much common code as possible in the file attributes
2541  * code. For more information about the callbacks, see TclFileAttrsCmd in
2542  * tclFCmd.c.
2543  */
2544 
2545 typedef int (TclGetFileAttrProc)(Tcl_Interp *interp, int objIndex,
2546 	Tcl_Obj *fileName, Tcl_Obj **attrObjPtrPtr);
2547 typedef int (TclSetFileAttrProc)(Tcl_Interp *interp, int objIndex,
2548 	Tcl_Obj *fileName, Tcl_Obj *attrObjPtr);
2549 
2550 typedef struct TclFileAttrProcs {
2551     TclGetFileAttrProc *getProc;/* The procedure for getting attrs. */
2552     TclSetFileAttrProc *setProc;/* The procedure for setting attrs. */
2553 } TclFileAttrProcs;
2554 
2555 /*
2556  * Opaque handle used in pipeline routines to encapsulate platform-dependent
2557  * state.
2558  */
2559 
2560 typedef struct TclFile_ *TclFile;
2561 
2562 /*
2563  * The "globParameters" argument of the function TclGlob is an or'ed
2564  * combination of the following values:
2565  */
2566 
2567 #define TCL_GLOBMODE_NO_COMPLAIN	1
2568 #define TCL_GLOBMODE_JOIN		2
2569 #define TCL_GLOBMODE_DIR		4
2570 #define TCL_GLOBMODE_TAILS		8
2571 
2572 typedef enum Tcl_PathPart {
2573     TCL_PATH_DIRNAME,
2574     TCL_PATH_TAIL,
2575     TCL_PATH_EXTENSION,
2576     TCL_PATH_ROOT
2577 } Tcl_PathPart;
2578 
2579 /*
2580  *----------------------------------------------------------------
2581  * Data structures related to obsolete filesystem hooks
2582  *----------------------------------------------------------------
2583  */
2584 
2585 typedef int (TclStatProc_)(const char *path, struct stat *buf);
2586 typedef int (TclAccessProc_)(const char *path, int mode);
2587 typedef Tcl_Channel (TclOpenFileChannelProc_)(Tcl_Interp *interp,
2588 	const char *fileName, const char *modeString, int permissions);
2589 
2590 /*
2591  *----------------------------------------------------------------
2592  * Data structures related to procedures
2593  *----------------------------------------------------------------
2594  */
2595 
2596 typedef Tcl_CmdProc *TclCmdProcType;
2597 typedef Tcl_ObjCmdProc *TclObjCmdProcType;
2598 
2599 /*
2600  *----------------------------------------------------------------
2601  * Data structures for process-global values.
2602  *----------------------------------------------------------------
2603  */
2604 
2605 typedef void (TclInitProcessGlobalValueProc)(char **valuePtr, int *lengthPtr,
2606 	Tcl_Encoding *encodingPtr);
2607 
2608 /*
2609  * A ProcessGlobalValue struct exists for each internal value in Tcl that is
2610  * to be shared among several threads. Each thread sees a (Tcl_Obj) copy of
2611  * the value, and the gobal value is kept as a counted string, with epoch and
2612  * mutex control. Each ProcessGlobalValue struct should be a static variable in
2613  * some file.
2614  */
2615 
2616 typedef struct ProcessGlobalValue {
2617     int epoch;			/* Epoch counter to detect changes in the
2618 				 * global value. */
2619     int numBytes;		/* Length of the global string. */
2620     char *value;		/* The global string value. */
2621     Tcl_Encoding encoding;	/* system encoding when global string was
2622 				 * initialized. */
2623     TclInitProcessGlobalValueProc *proc;
2624     				/* A procedure to initialize the global string
2625 				 * copy when a "get" request comes in before
2626 				 * any "set" request has been received. */
2627     Tcl_Mutex mutex;		/* Enforce orderly access from multiple
2628 				 * threads. */
2629     Tcl_ThreadDataKey key;	/* Key for per-thread data holding the
2630 				 * (Tcl_Obj) copy for each thread. */
2631 } ProcessGlobalValue;
2632 
2633 /*
2634  *----------------------------------------------------------------------
2635  * Flags for TclParseNumber
2636  *----------------------------------------------------------------------
2637  */
2638 
2639 #define TCL_PARSE_DECIMAL_ONLY		1
2640 				/* Leading zero doesn't denote octal or
2641 				 * hex. */
2642 #define TCL_PARSE_OCTAL_ONLY		2
2643 				/* Parse octal even without prefix. */
2644 #define TCL_PARSE_HEXADECIMAL_ONLY	4
2645 				/* Parse hexadecimal even without prefix. */
2646 #define TCL_PARSE_INTEGER_ONLY		8
2647 				/* Disable floating point parsing. */
2648 #define TCL_PARSE_SCAN_PREFIXES		16
2649 				/* Use [scan] rules dealing with 0?
2650 				 * prefixes. */
2651 #define TCL_PARSE_NO_WHITESPACE		32
2652 				/* Reject leading/trailing whitespace. */
2653 #define TCL_PARSE_BINARY_ONLY	64
2654 				/* Parse binary even without prefix. */
2655 
2656 /*
2657  *----------------------------------------------------------------------
2658  * Type values TclGetNumberFromObj
2659  *----------------------------------------------------------------------
2660  */
2661 
2662 #define TCL_NUMBER_LONG		1
2663 #define TCL_NUMBER_WIDE		2
2664 #define TCL_NUMBER_BIG		3
2665 #define TCL_NUMBER_DOUBLE	4
2666 #define TCL_NUMBER_NAN		5
2667 
2668 /*
2669  *----------------------------------------------------------------
2670  * Variables shared among Tcl modules but not used by the outside world.
2671  *----------------------------------------------------------------
2672  */
2673 
2674 MODULE_SCOPE char *tclNativeExecutableName;
2675 MODULE_SCOPE int tclFindExecutableSearchDone;
2676 MODULE_SCOPE char *tclMemDumpFileName;
2677 MODULE_SCOPE TclPlatformType tclPlatform;
2678 MODULE_SCOPE Tcl_NotifierProcs tclNotifierHooks;
2679 
2680 MODULE_SCOPE Tcl_Encoding tclIdentityEncoding;
2681 
2682 /*
2683  * TIP #233 (Virtualized Time)
2684  * Data for the time hooks, if any.
2685  */
2686 
2687 MODULE_SCOPE Tcl_GetTimeProc *tclGetTimeProcPtr;
2688 MODULE_SCOPE Tcl_ScaleTimeProc *tclScaleTimeProcPtr;
2689 MODULE_SCOPE ClientData tclTimeClientData;
2690 
2691 /*
2692  * Variables denoting the Tcl object types defined in the core.
2693  */
2694 
2695 MODULE_SCOPE const Tcl_ObjType tclBignumType;
2696 MODULE_SCOPE const Tcl_ObjType tclBooleanType;
2697 MODULE_SCOPE const Tcl_ObjType tclByteArrayType;
2698 MODULE_SCOPE const Tcl_ObjType tclByteCodeType;
2699 MODULE_SCOPE const Tcl_ObjType tclDoubleType;
2700 MODULE_SCOPE const Tcl_ObjType tclEndOffsetType;
2701 MODULE_SCOPE const Tcl_ObjType tclIntType;
2702 MODULE_SCOPE const Tcl_ObjType tclListType;
2703 MODULE_SCOPE const Tcl_ObjType tclDictType;
2704 MODULE_SCOPE const Tcl_ObjType tclProcBodyType;
2705 MODULE_SCOPE const Tcl_ObjType tclStringType;
2706 MODULE_SCOPE const Tcl_ObjType tclArraySearchType;
2707 MODULE_SCOPE const Tcl_ObjType tclEnsembleCmdType;
2708 #ifndef TCL_WIDE_INT_IS_LONG
2709 MODULE_SCOPE const Tcl_ObjType tclWideIntType;
2710 #endif
2711 MODULE_SCOPE const Tcl_ObjType tclRegexpType;
2712 MODULE_SCOPE Tcl_ObjType tclCmdNameType;
2713 
2714 /*
2715  * Variables denoting the hash key types defined in the core.
2716  */
2717 
2718 MODULE_SCOPE const Tcl_HashKeyType tclArrayHashKeyType;
2719 MODULE_SCOPE const Tcl_HashKeyType tclOneWordHashKeyType;
2720 MODULE_SCOPE const Tcl_HashKeyType tclStringHashKeyType;
2721 MODULE_SCOPE const Tcl_HashKeyType tclObjHashKeyType;
2722 
2723 /*
2724  * The head of the list of free Tcl objects, and the total number of Tcl
2725  * objects ever allocated and freed.
2726  */
2727 
2728 MODULE_SCOPE Tcl_Obj *	tclFreeObjList;
2729 
2730 #ifdef TCL_COMPILE_STATS
2731 MODULE_SCOPE long	tclObjsAlloced;
2732 MODULE_SCOPE long	tclObjsFreed;
2733 #define TCL_MAX_SHARED_OBJ_STATS 5
2734 MODULE_SCOPE long	tclObjsShared[TCL_MAX_SHARED_OBJ_STATS];
2735 #endif /* TCL_COMPILE_STATS */
2736 
2737 /*
2738  * Pointer to a heap-allocated string of length zero that the Tcl core uses as
2739  * the value of an empty string representation for an object. This value is
2740  * shared by all new objects allocated by Tcl_NewObj.
2741  */
2742 
2743 MODULE_SCOPE char *	tclEmptyStringRep;
2744 MODULE_SCOPE char	tclEmptyString;
2745 
2746 enum CheckEmptyStringResult {
2747 	TCL_EMPTYSTRING_UNKNOWN = -1, TCL_EMPTYSTRING_NO, TCL_EMPTYSTRING_YES
2748 };
2749 
2750 /*
2751  *----------------------------------------------------------------
2752  * Procedures shared among Tcl modules but not used by the outside world,
2753  * introduced by/for NRE.
2754  *----------------------------------------------------------------
2755  */
2756 
2757 MODULE_SCOPE Tcl_ObjCmdProc TclNRApplyObjCmd;
2758 MODULE_SCOPE Tcl_ObjCmdProc TclNREvalObjCmd;
2759 MODULE_SCOPE Tcl_ObjCmdProc TclNRCatchObjCmd;
2760 MODULE_SCOPE Tcl_ObjCmdProc TclNRExprObjCmd;
2761 MODULE_SCOPE Tcl_ObjCmdProc TclNRForObjCmd;
2762 MODULE_SCOPE Tcl_ObjCmdProc TclNRForeachCmd;
2763 MODULE_SCOPE Tcl_ObjCmdProc TclNRIfObjCmd;
2764 MODULE_SCOPE Tcl_ObjCmdProc TclNRLmapCmd;
2765 MODULE_SCOPE Tcl_ObjCmdProc TclNRPackageObjCmd;
2766 MODULE_SCOPE Tcl_ObjCmdProc TclNRSourceObjCmd;
2767 MODULE_SCOPE Tcl_ObjCmdProc TclNRSubstObjCmd;
2768 MODULE_SCOPE Tcl_ObjCmdProc TclNRSwitchObjCmd;
2769 MODULE_SCOPE Tcl_ObjCmdProc TclNRTryObjCmd;
2770 MODULE_SCOPE Tcl_ObjCmdProc TclNRUplevelObjCmd;
2771 MODULE_SCOPE Tcl_ObjCmdProc TclNRWhileObjCmd;
2772 
2773 MODULE_SCOPE Tcl_NRPostProc TclNRForIterCallback;
2774 MODULE_SCOPE Tcl_NRPostProc TclNRCoroutineActivateCallback;
2775 MODULE_SCOPE Tcl_ObjCmdProc TclNRTailcallObjCmd;
2776 MODULE_SCOPE Tcl_NRPostProc TclNRTailcallEval;
2777 MODULE_SCOPE Tcl_ObjCmdProc TclNRCoroutineObjCmd;
2778 MODULE_SCOPE Tcl_ObjCmdProc TclNRYieldObjCmd;
2779 MODULE_SCOPE Tcl_ObjCmdProc TclNRYieldmObjCmd;
2780 MODULE_SCOPE Tcl_ObjCmdProc TclNRYieldToObjCmd;
2781 MODULE_SCOPE Tcl_ObjCmdProc TclNRInvoke;
2782 MODULE_SCOPE Tcl_NRPostProc TclNRReleaseValues;
2783 
2784 MODULE_SCOPE void  TclSetTailcall(Tcl_Interp *interp, Tcl_Obj *tailcallPtr);
2785 MODULE_SCOPE void  TclPushTailcallPoint(Tcl_Interp *interp);
2786 
2787 /* These two can be considered for the public api */
2788 MODULE_SCOPE void  TclMarkTailcall(Tcl_Interp *interp);
2789 MODULE_SCOPE void  TclSkipTailcall(Tcl_Interp *interp);
2790 
2791 /*
2792  * This structure holds the data for the various iteration callbacks used to
2793  * NRE the 'for' and 'while' commands. We need a separate structure because we
2794  * have more than the 4 client data entries we can provide directly thorugh
2795  * the callback API. It is the 'word' information which puts us over the
2796  * limit. It is needed because the loop body is argument 4 of 'for' and
2797  * argument 2 of 'while'. Not providing the correct index confuses the #280
2798  * code. We TclSmallAlloc/Free this.
2799  */
2800 
2801 typedef struct ForIterData {
2802     Tcl_Obj *cond;		/* Loop condition expression. */
2803     Tcl_Obj *body;		/* Loop body. */
2804     Tcl_Obj *next;		/* Loop step script, NULL for 'while'. */
2805     const char *msg;		/* Error message part. */
2806     int word;			/* Index of the body script in the command */
2807 } ForIterData;
2808 
2809 /* TIP #357 - Structure doing the bookkeeping of handles for Tcl_LoadFile
2810  *            and Tcl_FindSymbol. This structure corresponds to an opaque
2811  *            typedef in tcl.h */
2812 
2813 typedef void* TclFindSymbolProc(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
2814 				const char* symbol);
2815 struct Tcl_LoadHandle_ {
2816     ClientData clientData;	/* Client data is the load handle in the
2817 				 * native filesystem if a module was loaded
2818 				 * there, or an opaque pointer to a structure
2819 				 * for further bookkeeping on load-from-VFS
2820 				 * and load-from-memory */
2821     TclFindSymbolProc* findSymbolProcPtr;
2822 				/* Procedure that resolves symbols in a
2823 				 * loaded module */
2824     Tcl_FSUnloadFileProc* unloadFileProcPtr;
2825 				/* Procedure that unloads a loaded module */
2826 };
2827 
2828 /* Flags for conversion of doubles to digit strings */
2829 
2830 #define TCL_DD_SHORTEST 		0x4
2831 				/* Use the shortest possible string */
2832 #define TCL_DD_STEELE   		0x5
2833 				/* Use the original Steele&White algorithm */
2834 #define TCL_DD_E_FORMAT 		0x2
2835 				/* Use a fixed-length string of digits,
2836 				 * suitable for E format*/
2837 #define TCL_DD_F_FORMAT 		0x3
2838 				/* Use a fixed number of digits after the
2839 				 * decimal point, suitable for F format */
2840 
2841 #define TCL_DD_SHORTEN_FLAG 		0x4
2842 				/* Allow return of a shorter digit string
2843 				 * if it converts losslessly */
2844 #define TCL_DD_NO_QUICK 		0x8
2845 				/* Debug flag: forbid quick FP conversion */
2846 
2847 #define TCL_DD_CONVERSION_TYPE_MASK	0x3
2848 				/* Mask to isolate the conversion type */
2849 #define TCL_DD_STEELE0 			0x1
2850 				/* 'Steele&White' after masking */
2851 #define TCL_DD_SHORTEST0		0x0
2852 				/* 'Shortest possible' after masking */
2853 
2854 /*
2855  *----------------------------------------------------------------
2856  * Procedures shared among Tcl modules but not used by the outside world:
2857  *----------------------------------------------------------------
2858  */
2859 
2860 MODULE_SCOPE void	TclAppendBytesToByteArray(Tcl_Obj *objPtr,
2861 			    const unsigned char *bytes, int len);
2862 MODULE_SCOPE int	TclNREvalCmd(Tcl_Interp *interp, Tcl_Obj *objPtr,
2863 			    int flags);
2864 MODULE_SCOPE void	TclAdvanceContinuations(int *line, int **next,
2865 			    int loc);
2866 MODULE_SCOPE void	TclAdvanceLines(int *line, const char *start,
2867 			    const char *end);
2868 MODULE_SCOPE void	TclArgumentEnter(Tcl_Interp *interp,
2869 			    Tcl_Obj *objv[], int objc, CmdFrame *cf);
2870 MODULE_SCOPE void	TclArgumentRelease(Tcl_Interp *interp,
2871 			    Tcl_Obj *objv[], int objc);
2872 MODULE_SCOPE void	TclArgumentBCEnter(Tcl_Interp *interp,
2873 			    Tcl_Obj *objv[], int objc,
2874 			    void *codePtr, CmdFrame *cfPtr, int cmd, int pc);
2875 MODULE_SCOPE void	TclArgumentBCRelease(Tcl_Interp *interp,
2876 			    CmdFrame *cfPtr);
2877 MODULE_SCOPE void	TclArgumentGet(Tcl_Interp *interp, Tcl_Obj *obj,
2878 			    CmdFrame **cfPtrPtr, int *wordPtr);
2879 MODULE_SCOPE double	TclBignumToDouble(const mp_int *bignum);
2880 MODULE_SCOPE int	TclByteArrayMatch(const unsigned char *string,
2881 			    int strLen, const unsigned char *pattern,
2882 			    int ptnLen, int flags);
2883 MODULE_SCOPE double	TclCeil(const mp_int *a);
2884 MODULE_SCOPE void	TclChannelPreserve(Tcl_Channel chan);
2885 MODULE_SCOPE void	TclChannelRelease(Tcl_Channel chan);
2886 MODULE_SCOPE int	TclCheckArrayTraces(Tcl_Interp *interp, Var *varPtr,
2887 			    Var *arrayPtr, Tcl_Obj *name, int index);
2888 MODULE_SCOPE int	TclCheckBadOctal(Tcl_Interp *interp,
2889 			    const char *value);
2890 MODULE_SCOPE int	TclCheckEmptyString(Tcl_Obj *objPtr);
2891 MODULE_SCOPE int	TclChanCaughtErrorBypass(Tcl_Interp *interp,
2892 			    Tcl_Channel chan);
2893 MODULE_SCOPE Tcl_ObjCmdProc TclChannelNamesCmd;
2894 MODULE_SCOPE Tcl_NRPostProc TclClearRootEnsemble;
2895 MODULE_SCOPE ContLineLoc *TclContinuationsEnter(Tcl_Obj *objPtr, int num,
2896 			    int *loc);
2897 MODULE_SCOPE void	TclContinuationsEnterDerived(Tcl_Obj *objPtr,
2898 			    int start, int *clNext);
2899 MODULE_SCOPE ContLineLoc *TclContinuationsGet(Tcl_Obj *objPtr);
2900 MODULE_SCOPE void	TclContinuationsCopy(Tcl_Obj *objPtr,
2901 			    Tcl_Obj *originObjPtr);
2902 MODULE_SCOPE int	TclConvertElement(const char *src, int length,
2903 			    char *dst, int flags);
2904 MODULE_SCOPE Tcl_Command TclCreateObjCommandInNs (
2905 			    Tcl_Interp *interp,
2906 			    const char *cmdName,
2907 			    Tcl_Namespace *nsPtr,
2908 			    Tcl_ObjCmdProc *proc,
2909 			    ClientData clientData,
2910 			    Tcl_CmdDeleteProc *deleteProc);
2911 MODULE_SCOPE Tcl_Command TclCreateEnsembleInNs(
2912 			    Tcl_Interp *interp,
2913 			    const char *name,
2914 			    Tcl_Namespace *nameNamespacePtr,
2915 			    Tcl_Namespace *ensembleNamespacePtr,
2916 			    int flags);
2917 MODULE_SCOPE void	TclDeleteNamespaceVars(Namespace *nsPtr);
2918 MODULE_SCOPE int	TclFindDictElement(Tcl_Interp *interp,
2919 			    const char *dict, int dictLength,
2920 			    const char **elementPtr, const char **nextPtr,
2921 			    int *sizePtr, int *literalPtr);
2922 /* TIP #280 - Modified token based evulation, with line information. */
2923 MODULE_SCOPE int	TclEvalEx(Tcl_Interp *interp, const char *script,
2924 			    int numBytes, int flags, int line,
2925 			    int *clNextOuter, const char *outerScript);
2926 MODULE_SCOPE Tcl_ObjCmdProc TclFileAttrsCmd;
2927 MODULE_SCOPE Tcl_ObjCmdProc TclFileCopyCmd;
2928 MODULE_SCOPE Tcl_ObjCmdProc TclFileDeleteCmd;
2929 MODULE_SCOPE Tcl_ObjCmdProc TclFileLinkCmd;
2930 MODULE_SCOPE Tcl_ObjCmdProc TclFileMakeDirsCmd;
2931 MODULE_SCOPE Tcl_ObjCmdProc TclFileReadLinkCmd;
2932 MODULE_SCOPE Tcl_ObjCmdProc TclFileRenameCmd;
2933 MODULE_SCOPE Tcl_ObjCmdProc TclFileTemporaryCmd;
2934 MODULE_SCOPE void	TclCreateLateExitHandler(Tcl_ExitProc *proc,
2935 			    ClientData clientData);
2936 MODULE_SCOPE void	TclDeleteLateExitHandler(Tcl_ExitProc *proc,
2937 			    ClientData clientData);
2938 MODULE_SCOPE char *	TclDStringAppendObj(Tcl_DString *dsPtr,
2939 			    Tcl_Obj *objPtr);
2940 MODULE_SCOPE char *	TclDStringAppendDString(Tcl_DString *dsPtr,
2941 			    Tcl_DString *toAppendPtr);
2942 MODULE_SCOPE Tcl_Obj *	TclDStringToObj(Tcl_DString *dsPtr);
2943 MODULE_SCOPE Tcl_Obj *const *	TclFetchEnsembleRoot(Tcl_Interp *interp,
2944 			    Tcl_Obj *const *objv, int objc, int *objcPtr);
2945 MODULE_SCOPE Tcl_Obj *const *TclEnsembleGetRewriteValues(Tcl_Interp *interp);
2946 MODULE_SCOPE Tcl_Namespace *TclEnsureNamespace(Tcl_Interp *interp,
2947 			    Tcl_Namespace *namespacePtr);
2948 
2949 MODULE_SCOPE void	TclFinalizeAllocSubsystem(void);
2950 MODULE_SCOPE void	TclFinalizeAsync(void);
2951 MODULE_SCOPE void	TclFinalizeDoubleConversion(void);
2952 MODULE_SCOPE void	TclFinalizeEncodingSubsystem(void);
2953 MODULE_SCOPE void	TclFinalizeEnvironment(void);
2954 MODULE_SCOPE void	TclFinalizeEvaluation(void);
2955 MODULE_SCOPE void	TclFinalizeExecution(void);
2956 MODULE_SCOPE void	TclFinalizeIOSubsystem(void);
2957 MODULE_SCOPE void	TclFinalizeFilesystem(void);
2958 MODULE_SCOPE void	TclResetFilesystem(void);
2959 MODULE_SCOPE void	TclFinalizeLoad(void);
2960 MODULE_SCOPE void	TclFinalizeLock(void);
2961 MODULE_SCOPE void	TclFinalizeMemorySubsystem(void);
2962 MODULE_SCOPE void	TclFinalizeNotifier(void);
2963 MODULE_SCOPE void	TclFinalizeObjects(void);
2964 MODULE_SCOPE void	TclFinalizePreserve(void);
2965 MODULE_SCOPE void	TclFinalizeSynchronization(void);
2966 MODULE_SCOPE void	TclFinalizeThreadAlloc(void);
2967 MODULE_SCOPE void	TclFinalizeThreadAllocThread(void);
2968 MODULE_SCOPE void	TclFinalizeThreadData(int quick);
2969 MODULE_SCOPE void	TclFinalizeThreadObjects(void);
2970 MODULE_SCOPE double	TclFloor(const mp_int *a);
2971 MODULE_SCOPE void	TclFormatNaN(double value, char *buffer);
2972 MODULE_SCOPE int	TclFSFileAttrIndex(Tcl_Obj *pathPtr,
2973 			    const char *attributeName, int *indexPtr);
2974 MODULE_SCOPE Tcl_Command TclNRCreateCommandInNs (
2975 			    Tcl_Interp *interp,
2976 			    const char *cmdName,
2977 			    Tcl_Namespace *nsPtr,
2978 			    Tcl_ObjCmdProc *proc,
2979 			    Tcl_ObjCmdProc *nreProc,
2980 			    ClientData clientData,
2981 			    Tcl_CmdDeleteProc *deleteProc);
2982 
2983 MODULE_SCOPE int	TclNREvalFile(Tcl_Interp *interp, Tcl_Obj *pathPtr,
2984 			    const char *encodingName);
2985 MODULE_SCOPE void	TclFSUnloadTempFile(Tcl_LoadHandle loadHandle);
2986 MODULE_SCOPE int *	TclGetAsyncReadyPtr(void);
2987 MODULE_SCOPE Tcl_Obj *	TclGetBgErrorHandler(Tcl_Interp *interp);
2988 MODULE_SCOPE int	TclGetChannelFromObj(Tcl_Interp *interp,
2989 			    Tcl_Obj *objPtr, Tcl_Channel *chanPtr,
2990 			    int *modePtr, int flags);
2991 MODULE_SCOPE CmdFrame *	TclGetCmdFrameForProcedure(Proc *procPtr);
2992 MODULE_SCOPE int	TclGetCompletionCodeFromObj(Tcl_Interp *interp,
2993 			    Tcl_Obj *value, int *code);
2994 MODULE_SCOPE int	TclGetNumberFromObj(Tcl_Interp *interp,
2995 			    Tcl_Obj *objPtr, ClientData *clientDataPtr,
2996 			    int *typePtr);
2997 MODULE_SCOPE int	TclGetOpenModeEx(Tcl_Interp *interp,
2998 			    const char *modeString, int *seekFlagPtr,
2999 			    int *binaryPtr);
3000 MODULE_SCOPE Tcl_Obj *	TclGetProcessGlobalValue(ProcessGlobalValue *pgvPtr);
3001 MODULE_SCOPE Tcl_Obj *	TclGetSourceFromFrame(CmdFrame *cfPtr, int objc,
3002 			    Tcl_Obj *const objv[]);
3003 MODULE_SCOPE char *	TclGetStringStorage(Tcl_Obj *objPtr,
3004 			    unsigned int *sizePtr);
3005 MODULE_SCOPE int	TclGlob(Tcl_Interp *interp, char *pattern,
3006 			    Tcl_Obj *unquotedPrefix, int globFlags,
3007 			    Tcl_GlobTypeData *types);
3008 MODULE_SCOPE int	TclIncrObj(Tcl_Interp *interp, Tcl_Obj *valuePtr,
3009 			    Tcl_Obj *incrPtr);
3010 MODULE_SCOPE Tcl_Obj *	TclIncrObjVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
3011 			    Tcl_Obj *part2Ptr, Tcl_Obj *incrPtr, int flags);
3012 MODULE_SCOPE int	TclInfoExistsCmd(ClientData dummy, Tcl_Interp *interp,
3013 			    int objc, Tcl_Obj *const objv[]);
3014 MODULE_SCOPE int	TclInfoCoroutineCmd(ClientData dummy, Tcl_Interp *interp,
3015 			    int objc, Tcl_Obj *const objv[]);
3016 MODULE_SCOPE Tcl_Obj *	TclInfoFrame(Tcl_Interp *interp, CmdFrame *framePtr);
3017 MODULE_SCOPE int	TclInfoGlobalsCmd(ClientData dummy, Tcl_Interp *interp,
3018 			    int objc, Tcl_Obj *const objv[]);
3019 MODULE_SCOPE int	TclInfoLocalsCmd(ClientData dummy, Tcl_Interp *interp,
3020 			    int objc, Tcl_Obj *const objv[]);
3021 MODULE_SCOPE int	TclInfoVarsCmd(ClientData dummy, Tcl_Interp *interp,
3022 			    int objc, Tcl_Obj *const objv[]);
3023 MODULE_SCOPE void	TclInitAlloc(void);
3024 MODULE_SCOPE void	TclInitDbCkalloc(void);
3025 MODULE_SCOPE void	TclInitDoubleConversion(void);
3026 MODULE_SCOPE void	TclInitEmbeddedConfigurationInformation(
3027 			    Tcl_Interp *interp);
3028 MODULE_SCOPE void	TclInitEncodingSubsystem(void);
3029 MODULE_SCOPE void	TclInitIOSubsystem(void);
3030 MODULE_SCOPE void	TclInitLimitSupport(Tcl_Interp *interp);
3031 MODULE_SCOPE void	TclInitNamespaceSubsystem(void);
3032 MODULE_SCOPE void	TclInitNotifier(void);
3033 MODULE_SCOPE void	TclInitObjSubsystem(void);
3034 MODULE_SCOPE void	TclInitSubsystems(void);
3035 MODULE_SCOPE int	TclInterpReady(Tcl_Interp *interp);
3036 MODULE_SCOPE int	TclIsBareword(int byte);
3037 MODULE_SCOPE Tcl_Obj *	TclJoinPath(int elements, Tcl_Obj * const objv[],
3038 			    int forceRelative);
3039 MODULE_SCOPE int	TclJoinThread(Tcl_ThreadId id, int *result);
3040 MODULE_SCOPE void	TclLimitRemoveAllHandlers(Tcl_Interp *interp);
3041 MODULE_SCOPE Tcl_Obj *	TclLindexList(Tcl_Interp *interp,
3042 			    Tcl_Obj *listPtr, Tcl_Obj *argPtr);
3043 MODULE_SCOPE Tcl_Obj *	TclLindexFlat(Tcl_Interp *interp, Tcl_Obj *listPtr,
3044 			    int indexCount, Tcl_Obj *const indexArray[]);
3045 /* TIP #280 */
3046 MODULE_SCOPE void	TclListLines(Tcl_Obj *listObj, int line, int n,
3047 			    int *lines, Tcl_Obj *const *elems);
3048 MODULE_SCOPE Tcl_Obj *	TclListObjCopy(Tcl_Interp *interp, Tcl_Obj *listPtr);
3049 MODULE_SCOPE Tcl_Obj *	TclLsetList(Tcl_Interp *interp, Tcl_Obj *listPtr,
3050 			    Tcl_Obj *indexPtr, Tcl_Obj *valuePtr);
3051 MODULE_SCOPE Tcl_Obj *	TclLsetFlat(Tcl_Interp *interp, Tcl_Obj *listPtr,
3052 			    int indexCount, Tcl_Obj *const indexArray[],
3053 			    Tcl_Obj *valuePtr);
3054 MODULE_SCOPE Tcl_Command TclMakeEnsemble(Tcl_Interp *interp, const char *name,
3055 			    const EnsembleImplMap map[]);
3056 MODULE_SCOPE int	TclMaxListLength(const char *bytes, int numBytes,
3057 			    const char **endPtr);
3058 MODULE_SCOPE int	TclMergeReturnOptions(Tcl_Interp *interp, int objc,
3059 			    Tcl_Obj *const objv[], Tcl_Obj **optionsPtrPtr,
3060 			    int *codePtr, int *levelPtr);
3061 MODULE_SCOPE Tcl_Obj *  TclNoErrorStack(Tcl_Interp *interp, Tcl_Obj *options);
3062 MODULE_SCOPE int	TclNokia770Doubles(void);
3063 MODULE_SCOPE void	TclNsDecrRefCount(Namespace *nsPtr);
3064 MODULE_SCOPE void	TclNsDecrRefCount(Namespace *nsPtr);
3065 MODULE_SCOPE int	TclNamespaceDeleted(Namespace *nsPtr);
3066 MODULE_SCOPE void	TclObjVarErrMsg(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
3067 			    Tcl_Obj *part2Ptr, const char *operation,
3068 			    const char *reason, int index);
3069 MODULE_SCOPE int	TclObjInvokeNamespace(Tcl_Interp *interp,
3070 			    int objc, Tcl_Obj *const objv[],
3071 			    Tcl_Namespace *nsPtr, int flags);
3072 MODULE_SCOPE int	TclObjUnsetVar2(Tcl_Interp *interp,
3073 			    Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags);
3074 MODULE_SCOPE int	TclParseBackslash(const char *src,
3075 			    int numBytes, int *readPtr, char *dst);
3076 MODULE_SCOPE int	TclParseNumber(Tcl_Interp *interp, Tcl_Obj *objPtr,
3077 			    const char *expected, const char *bytes,
3078 			    int numBytes, const char **endPtrPtr, int flags);
3079 MODULE_SCOPE void	TclParseInit(Tcl_Interp *interp, const char *string,
3080 			    int numBytes, Tcl_Parse *parsePtr);
3081 MODULE_SCOPE int	TclParseAllWhiteSpace(const char *src, int numBytes);
3082 MODULE_SCOPE int	TclProcessReturn(Tcl_Interp *interp,
3083 			    int code, int level, Tcl_Obj *returnOpts);
3084 MODULE_SCOPE int	TclpObjLstat(Tcl_Obj *pathPtr, Tcl_StatBuf *buf);
3085 MODULE_SCOPE Tcl_Obj *	TclpTempFileName(void);
3086 MODULE_SCOPE Tcl_Obj *  TclpTempFileNameForLibrary(Tcl_Interp *interp, Tcl_Obj* pathPtr);
3087 MODULE_SCOPE Tcl_Obj *	TclNewFSPathObj(Tcl_Obj *dirPtr, const char *addStrRep,
3088 			    int len);
3089 MODULE_SCOPE int	TclpDeleteFile(const void *path);
3090 MODULE_SCOPE void	TclpFinalizeCondition(Tcl_Condition *condPtr);
3091 MODULE_SCOPE void	TclpFinalizeMutex(Tcl_Mutex *mutexPtr);
3092 MODULE_SCOPE void	TclpFinalizePipes(void);
3093 MODULE_SCOPE void	TclpFinalizeSockets(void);
3094 MODULE_SCOPE int	TclCreateSocketAddress(Tcl_Interp *interp,
3095 			    struct addrinfo **addrlist,
3096 			    const char *host, int port, int willBind,
3097 			    const char **errorMsgPtr);
3098 MODULE_SCOPE int	TclpThreadCreate(Tcl_ThreadId *idPtr,
3099 			    Tcl_ThreadCreateProc *proc, ClientData clientData,
3100 			    int stackSize, int flags);
3101 MODULE_SCOPE int	TclpFindVariable(const char *name, int *lengthPtr);
3102 MODULE_SCOPE void	TclpInitLibraryPath(char **valuePtr,
3103 			    int *lengthPtr, Tcl_Encoding *encodingPtr);
3104 MODULE_SCOPE void	TclpInitLock(void);
3105 MODULE_SCOPE void	TclpInitPlatform(void);
3106 MODULE_SCOPE void	TclpInitUnlock(void);
3107 MODULE_SCOPE Tcl_Obj *	TclpObjListVolumes(void);
3108 MODULE_SCOPE void	TclpGlobalLock(void);
3109 MODULE_SCOPE void	TclpGlobalUnlock(void);
3110 MODULE_SCOPE int	TclpMatchFiles(Tcl_Interp *interp, char *separators,
3111 			    Tcl_DString *dirPtr, char *pattern, char *tail);
3112 MODULE_SCOPE int	TclpObjNormalizePath(Tcl_Interp *interp,
3113 			    Tcl_Obj *pathPtr, int nextCheckpoint);
3114 MODULE_SCOPE void	TclpNativeJoinPath(Tcl_Obj *prefix, const char *joining);
3115 MODULE_SCOPE Tcl_Obj *	TclpNativeSplitPath(Tcl_Obj *pathPtr, int *lenPtr);
3116 MODULE_SCOPE Tcl_PathType TclpGetNativePathType(Tcl_Obj *pathPtr,
3117 			    int *driveNameLengthPtr, Tcl_Obj **driveNameRef);
3118 MODULE_SCOPE int	TclCrossFilesystemCopy(Tcl_Interp *interp,
3119 			    Tcl_Obj *source, Tcl_Obj *target);
3120 MODULE_SCOPE int	TclpMatchInDirectory(Tcl_Interp *interp,
3121 			    Tcl_Obj *resultPtr, Tcl_Obj *pathPtr,
3122 			    const char *pattern, Tcl_GlobTypeData *types);
3123 MODULE_SCOPE ClientData	TclpGetNativeCwd(ClientData clientData);
3124 MODULE_SCOPE Tcl_FSDupInternalRepProc TclNativeDupInternalRep;
3125 MODULE_SCOPE Tcl_Obj *	TclpObjLink(Tcl_Obj *pathPtr, Tcl_Obj *toPtr,
3126 			    int linkType);
3127 MODULE_SCOPE int	TclpObjChdir(Tcl_Obj *pathPtr);
3128 MODULE_SCOPE Tcl_Channel TclpOpenTemporaryFile(Tcl_Obj *dirObj,
3129 			    Tcl_Obj *basenameObj, Tcl_Obj *extensionObj,
3130 			    Tcl_Obj *resultingNameObj);
3131 MODULE_SCOPE Tcl_Obj *	TclPathPart(Tcl_Interp *interp, Tcl_Obj *pathPtr,
3132 			    Tcl_PathPart portion);
3133 MODULE_SCOPE char *	TclpReadlink(const char *fileName,
3134 			    Tcl_DString *linkPtr);
3135 MODULE_SCOPE void	TclpSetVariables(Tcl_Interp *interp);
3136 MODULE_SCOPE void *	TclThreadStorageKeyGet(Tcl_ThreadDataKey *keyPtr);
3137 MODULE_SCOPE void	TclThreadStorageKeySet(Tcl_ThreadDataKey *keyPtr,
3138 			    void *data);
3139 MODULE_SCOPE void	TclpThreadExit(int status);
3140 MODULE_SCOPE void	TclRememberCondition(Tcl_Condition *mutex);
3141 MODULE_SCOPE void	TclRememberJoinableThread(Tcl_ThreadId id);
3142 MODULE_SCOPE void	TclRememberMutex(Tcl_Mutex *mutex);
3143 MODULE_SCOPE void	TclRemoveScriptLimitCallbacks(Tcl_Interp *interp);
3144 MODULE_SCOPE int	TclReToGlob(Tcl_Interp *interp, const char *reStr,
3145 			    int reStrLen, Tcl_DString *dsPtr, int *flagsPtr,
3146 			    int *quantifiersFoundPtr);
3147 MODULE_SCOPE int	TclScanElement(const char *string, int length,
3148 			    char *flagPtr);
3149 MODULE_SCOPE void	TclSetBgErrorHandler(Tcl_Interp *interp,
3150 			    Tcl_Obj *cmdPrefix);
3151 MODULE_SCOPE void	TclSetBignumInternalRep(Tcl_Obj *objPtr,
3152 			    mp_int *bignumValue);
3153 MODULE_SCOPE int	TclSetBooleanFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
3154 MODULE_SCOPE void	TclSetCmdNameObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
3155 			    Command *cmdPtr);
3156 MODULE_SCOPE void	TclSetDuplicateObj(Tcl_Obj *dupPtr, Tcl_Obj *objPtr);
3157 MODULE_SCOPE void	TclSetProcessGlobalValue(ProcessGlobalValue *pgvPtr,
3158 			    Tcl_Obj *newValue, Tcl_Encoding encoding);
3159 MODULE_SCOPE void	TclSignalExitThread(Tcl_ThreadId id, int result);
3160 MODULE_SCOPE void	TclSpellFix(Tcl_Interp *interp,
3161 			    Tcl_Obj *const *objv, int objc, int subIdx,
3162 			    Tcl_Obj *bad, Tcl_Obj *fix);
3163 MODULE_SCOPE void *	TclStackRealloc(Tcl_Interp *interp, void *ptr,
3164 			    int numBytes);
3165 
3166 typedef int (*memCmpFn_t)(const void*, const void*, size_t);
3167 MODULE_SCOPE int	TclStringCmp (Tcl_Obj *value1Ptr, Tcl_Obj *value2Ptr,
3168 			    int checkEq, int nocase, int reqlength);
3169 MODULE_SCOPE int	TclStringCmpOpts (Tcl_Interp *interp, int objc, Tcl_Obj *const objv[],
3170 			    int *nocase, int *reqlength);
3171 MODULE_SCOPE int	TclStringMatch(const char *str, int strLen,
3172 			    const char *pattern, int ptnLen, int flags);
3173 MODULE_SCOPE int	TclStringMatchObj(Tcl_Obj *stringObj,
3174 			    Tcl_Obj *patternObj, int flags);
3175 MODULE_SCOPE Tcl_Obj *	TclStringReverse(Tcl_Obj *objPtr);
3176 MODULE_SCOPE void	TclSubstCompile(Tcl_Interp *interp, const char *bytes,
3177 			    int numBytes, int flags, int line,
3178 			    struct CompileEnv *envPtr);
3179 MODULE_SCOPE int	TclSubstOptions(Tcl_Interp *interp, int numOpts,
3180 			    Tcl_Obj *const opts[], int *flagPtr);
3181 MODULE_SCOPE void	TclSubstParse(Tcl_Interp *interp, const char *bytes,
3182 			    int numBytes, int flags, Tcl_Parse *parsePtr,
3183 			    Tcl_InterpState *statePtr);
3184 MODULE_SCOPE int	TclSubstTokens(Tcl_Interp *interp, Tcl_Token *tokenPtr,
3185 			    int count, int *tokensLeftPtr, int line,
3186 			    int *clNextOuter, const char *outerScript);
3187 MODULE_SCOPE int	TclTrim(const char *bytes, int numBytes,
3188 			    const char *trim, int numTrim, int *trimRight);
3189 MODULE_SCOPE int	TclTrimLeft(const char *bytes, int numBytes,
3190 			    const char *trim, int numTrim);
3191 MODULE_SCOPE int	TclTrimRight(const char *bytes, int numBytes,
3192 			    const char *trim, int numTrim);
3193 MODULE_SCOPE int	TclUtfCasecmp(const char *cs, const char *ct);
3194 MODULE_SCOPE int	TclUtfToUCS4(const char *, int *);
3195 MODULE_SCOPE int	TclUCS4ToUtf(int, char *);
3196 MODULE_SCOPE int	TclUCS4ToLower(int ch);
3197 #if TCL_UTF_MAX == 4
3198     MODULE_SCOPE int	TclGetUCS4(Tcl_Obj *, int);
3199     MODULE_SCOPE int	TclUniCharToUCS4(const Tcl_UniChar *, int *);
3200 #else
3201 #   define TclGetUCS4 Tcl_GetUniChar
3202 #   define TclUniCharToUCS4(src, ptr) (*ptr = *(src),1)
3203 #endif
3204 
3205 /*
3206  * Bytes F0-F4 are start-bytes for 4-byte sequences.
3207  * Byte 0xED can be the start-byte of an upper surrogate. In that case,
3208  * TclUtfToUCS4() might read the lower surrogate following it too.
3209  */
3210 #   define TclUCS4Complete(src, length) (((unsigned)(UCHAR(*(src)) - 0xF0) < 5) \
3211 	    ? ((length) >= 4) : (UCHAR(*(src)) == 0xED) ? ((length) >= 6) : Tcl_UtfCharComplete((src), (length)))
3212 MODULE_SCOPE Tcl_Obj *	TclpNativeToNormalized(ClientData clientData);
3213 MODULE_SCOPE Tcl_Obj *	TclpFilesystemPathType(Tcl_Obj *pathPtr);
3214 MODULE_SCOPE int	TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr,
3215 			    Tcl_LoadHandle *loadHandle,
3216 			    Tcl_FSUnloadFileProc **unloadProcPtr, int flags);
3217 MODULE_SCOPE int	TclpUtime(Tcl_Obj *pathPtr, struct utimbuf *tval);
3218 #ifdef TCL_LOAD_FROM_MEMORY
3219 MODULE_SCOPE void *	TclpLoadMemoryGetBuffer(Tcl_Interp *interp, int size);
3220 MODULE_SCOPE int	TclpLoadMemory(Tcl_Interp *interp, void *buffer,
3221 			    int size, int codeSize, Tcl_LoadHandle *loadHandle,
3222 			    Tcl_FSUnloadFileProc **unloadProcPtr, int flags);
3223 #endif
3224 MODULE_SCOPE void	TclInitThreadStorage(void);
3225 MODULE_SCOPE void	TclFinalizeThreadDataThread(void);
3226 MODULE_SCOPE void	TclFinalizeThreadStorage(void);
3227 
3228 /* TclWideMUInt -- wide integer used for measurement calculations: */
3229 #if (!defined(_WIN32) || !defined(_MSC_VER) || (_MSC_VER >= 1400))
3230 #   define TclWideMUInt Tcl_WideUInt
3231 #else
3232 /* older MSVS may not allow conversions between unsigned __int64 and double) */
3233 #   define TclWideMUInt Tcl_WideInt
3234 #endif
3235 #ifdef TCL_WIDE_CLICKS
3236 MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void);
3237 MODULE_SCOPE double	TclpWideClicksToNanoseconds(Tcl_WideInt clicks);
3238 MODULE_SCOPE double	TclpWideClickInMicrosec(void);
3239 #else
3240 #   ifdef _WIN32
3241 #	define TCL_WIDE_CLICKS 1
3242 MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void);
3243 MODULE_SCOPE double	TclpWideClickInMicrosec(void);
3244 #	define		TclpWideClicksToNanoseconds(clicks) \
3245 				((double)(clicks) * TclpWideClickInMicrosec() * 1000)
3246 #   endif
3247 #endif
3248 MODULE_SCOPE Tcl_WideInt TclpGetMicroseconds(void);
3249 
3250 MODULE_SCOPE int	TclZlibInit(Tcl_Interp *interp);
3251 MODULE_SCOPE void *	TclpThreadCreateKey(void);
3252 MODULE_SCOPE void	TclpThreadDeleteKey(void *keyPtr);
3253 MODULE_SCOPE void	TclpThreadSetGlobalTSD(void *tsdKeyPtr, void *ptr);
3254 MODULE_SCOPE void *	TclpThreadGetGlobalTSD(void *tsdKeyPtr);
3255 
3256 MODULE_SCOPE void	TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length);
3257 
3258 /*
3259  * Many parsing tasks need a common definition of whitespace.
3260  * Use this routine and macro to achieve that and place
3261  * optimization (fragile on changes) in one place.
3262  */
3263 
3264 MODULE_SCOPE int	TclIsSpaceProc(int byte);
3265 #	define TclIsSpaceProcM(byte) \
3266 		(((byte) > 0x20) ? 0 : TclIsSpaceProc(byte))
3267 
3268 /*
3269  *----------------------------------------------------------------
3270  * Command procedures in the generic core:
3271  *----------------------------------------------------------------
3272  */
3273 
3274 MODULE_SCOPE int	Tcl_AfterObjCmd(ClientData clientData,
3275 			    Tcl_Interp *interp, int objc,
3276 			    Tcl_Obj *const objv[]);
3277 MODULE_SCOPE int	Tcl_AppendObjCmd(ClientData clientData,
3278 			    Tcl_Interp *interp, int objc,
3279 			    Tcl_Obj *const objv[]);
3280 MODULE_SCOPE int	Tcl_ApplyObjCmd(ClientData clientData,
3281 			    Tcl_Interp *interp, int objc,
3282 			    Tcl_Obj *const objv[]);
3283 MODULE_SCOPE Tcl_Command TclInitArrayCmd(Tcl_Interp *interp);
3284 MODULE_SCOPE Tcl_Command TclInitBinaryCmd(Tcl_Interp *interp);
3285 MODULE_SCOPE int	Tcl_BreakObjCmd(ClientData clientData,
3286 			    Tcl_Interp *interp, int objc,
3287 			    Tcl_Obj *const objv[]);
3288 MODULE_SCOPE int	Tcl_CaseObjCmd(ClientData clientData,
3289 			    Tcl_Interp *interp, int objc,
3290 			    Tcl_Obj *const objv[]);
3291 MODULE_SCOPE int	Tcl_CatchObjCmd(ClientData clientData,
3292 			    Tcl_Interp *interp, int objc,
3293 			    Tcl_Obj *const objv[]);
3294 MODULE_SCOPE int	Tcl_CdObjCmd(ClientData clientData,
3295 			    Tcl_Interp *interp, int objc,
3296 			    Tcl_Obj *const objv[]);
3297 MODULE_SCOPE Tcl_Command TclInitChanCmd(Tcl_Interp *interp);
3298 MODULE_SCOPE int	TclChanCreateObjCmd(ClientData clientData,
3299 			    Tcl_Interp *interp, int objc,
3300 			    Tcl_Obj *const objv[]);
3301 MODULE_SCOPE int	TclChanPostEventObjCmd(ClientData clientData,
3302 			    Tcl_Interp *interp, int objc,
3303 			    Tcl_Obj *const objv[]);
3304 MODULE_SCOPE int	TclChanPopObjCmd(ClientData clientData,
3305 			    Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
3306 MODULE_SCOPE int	TclChanPushObjCmd(ClientData clientData,
3307 			    Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
3308 MODULE_SCOPE void	TclClockInit(Tcl_Interp *interp);
3309 MODULE_SCOPE int	TclClockOldscanObjCmd(
3310 			    ClientData clientData, Tcl_Interp *interp,
3311 			    int objc, Tcl_Obj *const objv[]);
3312 MODULE_SCOPE int	Tcl_CloseObjCmd(ClientData clientData,
3313 			    Tcl_Interp *interp, int objc,
3314 			    Tcl_Obj *const objv[]);
3315 MODULE_SCOPE int	Tcl_ConcatObjCmd(ClientData clientData,
3316 			    Tcl_Interp *interp, int objc,
3317 			    Tcl_Obj *const objv[]);
3318 MODULE_SCOPE int	Tcl_ContinueObjCmd(ClientData clientData,
3319 			    Tcl_Interp *interp, int objc,
3320 			    Tcl_Obj *const objv[]);
3321 MODULE_SCOPE Tcl_TimerToken TclCreateAbsoluteTimerHandler(
3322 			    Tcl_Time *timePtr, Tcl_TimerProc *proc,
3323 			    ClientData clientData);
3324 MODULE_SCOPE int	TclDefaultBgErrorHandlerObjCmd(
3325 			    ClientData clientData, Tcl_Interp *interp,
3326 			    int objc, Tcl_Obj *const objv[]);
3327 MODULE_SCOPE Tcl_Command TclInitDictCmd(Tcl_Interp *interp);
3328 MODULE_SCOPE int	TclDictWithFinish(Tcl_Interp *interp, Var *varPtr,
3329 			    Var *arrayPtr, Tcl_Obj *part1Ptr,
3330 			    Tcl_Obj *part2Ptr, int index, int pathc,
3331 			    Tcl_Obj *const pathv[], Tcl_Obj *keysPtr);
3332 MODULE_SCOPE Tcl_Obj *	TclDictWithInit(Tcl_Interp *interp, Tcl_Obj *dictPtr,
3333 			    int pathc, Tcl_Obj *const pathv[]);
3334 MODULE_SCOPE int	Tcl_DisassembleObjCmd(ClientData clientData,
3335 			    Tcl_Interp *interp, int objc,
3336 			    Tcl_Obj *const objv[]);
3337 
3338 /* Assemble command function */
3339 MODULE_SCOPE int	Tcl_AssembleObjCmd(ClientData clientData,
3340 			    Tcl_Interp *interp, int objc,
3341 			    Tcl_Obj *const objv[]);
3342 MODULE_SCOPE int	TclNRAssembleObjCmd(ClientData clientData,
3343 			    Tcl_Interp *interp, int objc,
3344 			    Tcl_Obj *const objv[]);
3345 MODULE_SCOPE Tcl_Command TclInitEncodingCmd(Tcl_Interp *interp);
3346 MODULE_SCOPE int	TclMakeEncodingCommandSafe(Tcl_Interp *interp);
3347 MODULE_SCOPE int	Tcl_EofObjCmd(ClientData clientData,
3348 			    Tcl_Interp *interp, int objc,
3349 			    Tcl_Obj *const objv[]);
3350 MODULE_SCOPE int	Tcl_ErrorObjCmd(ClientData clientData,
3351 			    Tcl_Interp *interp, int objc,
3352 			    Tcl_Obj *const objv[]);
3353 MODULE_SCOPE int	Tcl_EvalObjCmd(ClientData clientData,
3354 			    Tcl_Interp *interp, int objc,
3355 			    Tcl_Obj *const objv[]);
3356 MODULE_SCOPE int	Tcl_ExecObjCmd(ClientData clientData,
3357 			    Tcl_Interp *interp, int objc,
3358 			    Tcl_Obj *const objv[]);
3359 MODULE_SCOPE int	Tcl_ExitObjCmd(ClientData clientData,
3360 			    Tcl_Interp *interp, int objc,
3361 			    Tcl_Obj *const objv[]);
3362 MODULE_SCOPE int	Tcl_ExprObjCmd(ClientData clientData,
3363 			    Tcl_Interp *interp, int objc,
3364 			    Tcl_Obj *const objv[]);
3365 MODULE_SCOPE int	Tcl_FblockedObjCmd(ClientData clientData,
3366 			    Tcl_Interp *interp, int objc,
3367 			    Tcl_Obj *const objv[]);
3368 MODULE_SCOPE int	Tcl_FconfigureObjCmd(
3369 			    ClientData clientData, Tcl_Interp *interp,
3370 			    int objc, Tcl_Obj *const objv[]);
3371 MODULE_SCOPE int	Tcl_FcopyObjCmd(ClientData dummy,
3372 			    Tcl_Interp *interp, int objc,
3373 			    Tcl_Obj *const objv[]);
3374 MODULE_SCOPE Tcl_Command TclInitFileCmd(Tcl_Interp *interp);
3375 MODULE_SCOPE int	TclMakeFileCommandSafe(Tcl_Interp *interp);
3376 MODULE_SCOPE int	Tcl_FileEventObjCmd(ClientData clientData,
3377 			    Tcl_Interp *interp, int objc,
3378 			    Tcl_Obj *const objv[]);
3379 MODULE_SCOPE int	Tcl_FlushObjCmd(ClientData clientData,
3380 			    Tcl_Interp *interp, int objc,
3381 			    Tcl_Obj *const objv[]);
3382 MODULE_SCOPE int	Tcl_ForObjCmd(ClientData clientData,
3383 			    Tcl_Interp *interp, int objc,
3384 			    Tcl_Obj *const objv[]);
3385 MODULE_SCOPE int	Tcl_ForeachObjCmd(ClientData clientData,
3386 			    Tcl_Interp *interp, int objc,
3387 			    Tcl_Obj *const objv[]);
3388 MODULE_SCOPE int	Tcl_FormatObjCmd(ClientData dummy,
3389 			    Tcl_Interp *interp, int objc,
3390 			    Tcl_Obj *const objv[]);
3391 MODULE_SCOPE int	Tcl_GetsObjCmd(ClientData clientData,
3392 			    Tcl_Interp *interp, int objc,
3393 			    Tcl_Obj *const objv[]);
3394 MODULE_SCOPE int	Tcl_GlobalObjCmd(ClientData clientData,
3395 			    Tcl_Interp *interp, int objc,
3396 			    Tcl_Obj *const objv[]);
3397 MODULE_SCOPE int	Tcl_GlobObjCmd(ClientData clientData,
3398 			    Tcl_Interp *interp, int objc,
3399 			    Tcl_Obj *const objv[]);
3400 MODULE_SCOPE int	Tcl_IfObjCmd(ClientData clientData,
3401 			    Tcl_Interp *interp, int objc,
3402 			    Tcl_Obj *const objv[]);
3403 MODULE_SCOPE int	Tcl_IncrObjCmd(ClientData clientData,
3404 			    Tcl_Interp *interp, int objc,
3405 			    Tcl_Obj *const objv[]);
3406 MODULE_SCOPE Tcl_Command TclInitInfoCmd(Tcl_Interp *interp);
3407 MODULE_SCOPE int	Tcl_InterpObjCmd(ClientData clientData,
3408 			    Tcl_Interp *interp, int argc,
3409 			    Tcl_Obj *const objv[]);
3410 MODULE_SCOPE int	Tcl_JoinObjCmd(ClientData clientData,
3411 			    Tcl_Interp *interp, int objc,
3412 			    Tcl_Obj *const objv[]);
3413 MODULE_SCOPE int	Tcl_LappendObjCmd(ClientData clientData,
3414 			    Tcl_Interp *interp, int objc,
3415 			    Tcl_Obj *const objv[]);
3416 MODULE_SCOPE int	Tcl_LassignObjCmd(ClientData clientData,
3417 			    Tcl_Interp *interp, int objc,
3418 			    Tcl_Obj *const objv[]);
3419 MODULE_SCOPE int	Tcl_LindexObjCmd(ClientData clientData,
3420 			    Tcl_Interp *interp, int objc,
3421 			    Tcl_Obj *const objv[]);
3422 MODULE_SCOPE int	Tcl_LinsertObjCmd(ClientData clientData,
3423 			    Tcl_Interp *interp, int objc,
3424 			    Tcl_Obj *const objv[]);
3425 MODULE_SCOPE int	Tcl_LlengthObjCmd(ClientData clientData,
3426 			    Tcl_Interp *interp, int objc,
3427 			    Tcl_Obj *const objv[]);
3428 MODULE_SCOPE int	Tcl_ListObjCmd(ClientData clientData,
3429 			    Tcl_Interp *interp, int objc,
3430 			    Tcl_Obj *const objv[]);
3431 MODULE_SCOPE int	Tcl_LmapObjCmd(ClientData clientData,
3432 			    Tcl_Interp *interp, int objc,
3433 			    Tcl_Obj *const objv[]);
3434 MODULE_SCOPE int	Tcl_LoadObjCmd(ClientData clientData,
3435 			    Tcl_Interp *interp, int objc,
3436 			    Tcl_Obj *const objv[]);
3437 MODULE_SCOPE int	Tcl_LrangeObjCmd(ClientData clientData,
3438 			    Tcl_Interp *interp, int objc,
3439 			    Tcl_Obj *const objv[]);
3440 MODULE_SCOPE int	Tcl_LrepeatObjCmd(ClientData clientData,
3441 			    Tcl_Interp *interp, int objc,
3442 			    Tcl_Obj *const objv[]);
3443 MODULE_SCOPE int	Tcl_LreplaceObjCmd(ClientData clientData,
3444 			    Tcl_Interp *interp, int objc,
3445 			    Tcl_Obj *const objv[]);
3446 MODULE_SCOPE int	Tcl_LreverseObjCmd(ClientData clientData,
3447 			    Tcl_Interp *interp, int objc,
3448 			    Tcl_Obj *const objv[]);
3449 MODULE_SCOPE int	Tcl_LsearchObjCmd(ClientData clientData,
3450 			    Tcl_Interp *interp, int objc,
3451 			    Tcl_Obj *const objv[]);
3452 MODULE_SCOPE int	Tcl_LsetObjCmd(ClientData clientData,
3453 			    Tcl_Interp *interp, int objc,
3454 			    Tcl_Obj *const objv[]);
3455 MODULE_SCOPE int	Tcl_LsortObjCmd(ClientData clientData,
3456 			    Tcl_Interp *interp, int objc,
3457 			    Tcl_Obj *const objv[]);
3458 MODULE_SCOPE Tcl_Command TclInitNamespaceCmd(Tcl_Interp *interp);
3459 MODULE_SCOPE int	TclNamespaceEnsembleCmd(ClientData dummy,
3460 			    Tcl_Interp *interp, int objc,
3461 			    Tcl_Obj *const objv[]);
3462 MODULE_SCOPE int	Tcl_OpenObjCmd(ClientData clientData,
3463 			    Tcl_Interp *interp, int objc,
3464 			    Tcl_Obj *const objv[]);
3465 MODULE_SCOPE int	Tcl_PackageObjCmd(ClientData clientData,
3466 			    Tcl_Interp *interp, int objc,
3467 			    Tcl_Obj *const objv[]);
3468 MODULE_SCOPE int	Tcl_PidObjCmd(ClientData clientData,
3469 			    Tcl_Interp *interp, int objc,
3470 			    Tcl_Obj *const objv[]);
3471 MODULE_SCOPE Tcl_Command TclInitPrefixCmd(Tcl_Interp *interp);
3472 MODULE_SCOPE int	Tcl_PutsObjCmd(ClientData clientData,
3473 			    Tcl_Interp *interp, int objc,
3474 			    Tcl_Obj *const objv[]);
3475 MODULE_SCOPE int	Tcl_PwdObjCmd(ClientData clientData,
3476 			    Tcl_Interp *interp, int objc,
3477 			    Tcl_Obj *const objv[]);
3478 MODULE_SCOPE int	Tcl_ReadObjCmd(ClientData clientData,
3479 			    Tcl_Interp *interp, int objc,
3480 			    Tcl_Obj *const objv[]);
3481 MODULE_SCOPE int	Tcl_RegexpObjCmd(ClientData clientData,
3482 			    Tcl_Interp *interp, int objc,
3483 			    Tcl_Obj *const objv[]);
3484 MODULE_SCOPE int	Tcl_RegsubObjCmd(ClientData clientData,
3485 			    Tcl_Interp *interp, int objc,
3486 			    Tcl_Obj *const objv[]);
3487 MODULE_SCOPE int	Tcl_RenameObjCmd(ClientData clientData,
3488 			    Tcl_Interp *interp, int objc,
3489 			    Tcl_Obj *const objv[]);
3490 MODULE_SCOPE int	Tcl_RepresentationCmd(ClientData clientData,
3491 			    Tcl_Interp *interp, int objc,
3492 			    Tcl_Obj *const objv[]);
3493 MODULE_SCOPE int	Tcl_ReturnObjCmd(ClientData clientData,
3494 			    Tcl_Interp *interp, int objc,
3495 			    Tcl_Obj *const objv[]);
3496 MODULE_SCOPE int	Tcl_ScanObjCmd(ClientData clientData,
3497 			    Tcl_Interp *interp, int objc,
3498 			    Tcl_Obj *const objv[]);
3499 MODULE_SCOPE int	Tcl_SeekObjCmd(ClientData clientData,
3500 			    Tcl_Interp *interp, int objc,
3501 			    Tcl_Obj *const objv[]);
3502 MODULE_SCOPE int	Tcl_SetObjCmd(ClientData clientData,
3503 			    Tcl_Interp *interp, int objc,
3504 			    Tcl_Obj *const objv[]);
3505 MODULE_SCOPE int	Tcl_SplitObjCmd(ClientData clientData,
3506 			    Tcl_Interp *interp, int objc,
3507 			    Tcl_Obj *const objv[]);
3508 MODULE_SCOPE int	Tcl_SocketObjCmd(ClientData clientData,
3509 			    Tcl_Interp *interp, int objc,
3510 			    Tcl_Obj *const objv[]);
3511 MODULE_SCOPE int	Tcl_SourceObjCmd(ClientData clientData,
3512 			    Tcl_Interp *interp, int objc,
3513 			    Tcl_Obj *const objv[]);
3514 MODULE_SCOPE Tcl_Command TclInitStringCmd(Tcl_Interp *interp);
3515 MODULE_SCOPE int	Tcl_SubstObjCmd(ClientData clientData,
3516 			    Tcl_Interp *interp, int objc,
3517 			    Tcl_Obj *const objv[]);
3518 MODULE_SCOPE int	Tcl_SwitchObjCmd(ClientData clientData,
3519 			    Tcl_Interp *interp, int objc,
3520 			    Tcl_Obj *const objv[]);
3521 MODULE_SCOPE int	Tcl_TellObjCmd(ClientData clientData,
3522 			    Tcl_Interp *interp, int objc,
3523 			    Tcl_Obj *const objv[]);
3524 MODULE_SCOPE int	Tcl_ThrowObjCmd(ClientData dummy, Tcl_Interp *interp,
3525 			    int objc, Tcl_Obj *const objv[]);
3526 MODULE_SCOPE int	Tcl_TimeObjCmd(ClientData clientData,
3527 			    Tcl_Interp *interp, int objc,
3528 			    Tcl_Obj *const objv[]);
3529 MODULE_SCOPE int	Tcl_TimeRateObjCmd(ClientData clientData,
3530 			    Tcl_Interp *interp, int objc,
3531 			    Tcl_Obj *const objv[]);
3532 MODULE_SCOPE int	Tcl_TraceObjCmd(ClientData clientData,
3533 			    Tcl_Interp *interp, int objc,
3534 			    Tcl_Obj *const objv[]);
3535 MODULE_SCOPE int	Tcl_TryObjCmd(ClientData clientData,
3536 			    Tcl_Interp *interp, int objc,
3537 			    Tcl_Obj *const objv[]);
3538 MODULE_SCOPE int	Tcl_UnloadObjCmd(ClientData clientData,
3539 			    Tcl_Interp *interp, int objc,
3540 			    Tcl_Obj *const objv[]);
3541 MODULE_SCOPE int	Tcl_UnsetObjCmd(ClientData clientData,
3542 			    Tcl_Interp *interp, int objc,
3543 			    Tcl_Obj *const objv[]);
3544 MODULE_SCOPE int	Tcl_UpdateObjCmd(ClientData clientData,
3545 			    Tcl_Interp *interp, int objc,
3546 			    Tcl_Obj *const objv[]);
3547 MODULE_SCOPE int	Tcl_UplevelObjCmd(ClientData clientData,
3548 			    Tcl_Interp *interp, int objc,
3549 			    Tcl_Obj *const objv[]);
3550 MODULE_SCOPE int	Tcl_UpvarObjCmd(ClientData clientData,
3551 			    Tcl_Interp *interp, int objc,
3552 			    Tcl_Obj *const objv[]);
3553 MODULE_SCOPE int	Tcl_VariableObjCmd(ClientData clientData,
3554 			    Tcl_Interp *interp, int objc,
3555 			    Tcl_Obj *const objv[]);
3556 MODULE_SCOPE int	Tcl_VwaitObjCmd(ClientData clientData,
3557 			    Tcl_Interp *interp, int objc,
3558 			    Tcl_Obj *const objv[]);
3559 MODULE_SCOPE int	Tcl_WhileObjCmd(ClientData clientData,
3560 			    Tcl_Interp *interp, int objc,
3561 			    Tcl_Obj *const objv[]);
3562 
3563 /*
3564  *----------------------------------------------------------------
3565  * Compilation procedures for commands in the generic core:
3566  *----------------------------------------------------------------
3567  */
3568 
3569 MODULE_SCOPE int	TclCompileAppendCmd(Tcl_Interp *interp,
3570 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3571 			    struct CompileEnv *envPtr);
3572 MODULE_SCOPE int	TclCompileArrayExistsCmd(Tcl_Interp *interp,
3573 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3574 			    struct CompileEnv *envPtr);
3575 MODULE_SCOPE int	TclCompileArraySetCmd(Tcl_Interp *interp,
3576 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3577 			    struct CompileEnv *envPtr);
3578 MODULE_SCOPE int	TclCompileArrayUnsetCmd(Tcl_Interp *interp,
3579 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3580 			    struct CompileEnv *envPtr);
3581 MODULE_SCOPE int	TclCompileBreakCmd(Tcl_Interp *interp,
3582 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3583 			    struct CompileEnv *envPtr);
3584 MODULE_SCOPE int	TclCompileCatchCmd(Tcl_Interp *interp,
3585 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3586 			    struct CompileEnv *envPtr);
3587 MODULE_SCOPE int	TclCompileClockClicksCmd(Tcl_Interp *interp,
3588 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3589 			    struct CompileEnv *envPtr);
3590 MODULE_SCOPE int	TclCompileClockReadingCmd(Tcl_Interp *interp,
3591 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3592 			    struct CompileEnv *envPtr);
3593 MODULE_SCOPE int	TclCompileConcatCmd(Tcl_Interp *interp,
3594 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3595 			    struct CompileEnv *envPtr);
3596 MODULE_SCOPE int	TclCompileContinueCmd(Tcl_Interp *interp,
3597 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3598 			    struct CompileEnv *envPtr);
3599 MODULE_SCOPE int	TclCompileDictAppendCmd(Tcl_Interp *interp,
3600 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3601 			    struct CompileEnv *envPtr);
3602 MODULE_SCOPE int	TclCompileDictCreateCmd(Tcl_Interp *interp,
3603 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3604 			    struct CompileEnv *envPtr);
3605 MODULE_SCOPE int	TclCompileDictExistsCmd(Tcl_Interp *interp,
3606 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3607 			    struct CompileEnv *envPtr);
3608 MODULE_SCOPE int	TclCompileDictForCmd(Tcl_Interp *interp,
3609 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3610 			    struct CompileEnv *envPtr);
3611 MODULE_SCOPE int	TclCompileDictGetCmd(Tcl_Interp *interp,
3612 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3613 			    struct CompileEnv *envPtr);
3614 MODULE_SCOPE int	TclCompileDictIncrCmd(Tcl_Interp *interp,
3615 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3616 			    struct CompileEnv *envPtr);
3617 MODULE_SCOPE int	TclCompileDictLappendCmd(Tcl_Interp *interp,
3618 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3619 			    struct CompileEnv *envPtr);
3620 MODULE_SCOPE int	TclCompileDictMapCmd(Tcl_Interp *interp,
3621 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3622 			    struct CompileEnv *envPtr);
3623 MODULE_SCOPE int	TclCompileDictMergeCmd(Tcl_Interp *interp,
3624 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3625 			    struct CompileEnv *envPtr);
3626 MODULE_SCOPE int	TclCompileDictSetCmd(Tcl_Interp *interp,
3627 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3628 			    struct CompileEnv *envPtr);
3629 MODULE_SCOPE int	TclCompileDictUnsetCmd(Tcl_Interp *interp,
3630 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3631 			    struct CompileEnv *envPtr);
3632 MODULE_SCOPE int	TclCompileDictUpdateCmd(Tcl_Interp *interp,
3633 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3634 			    struct CompileEnv *envPtr);
3635 MODULE_SCOPE int	TclCompileDictWithCmd(Tcl_Interp *interp,
3636 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3637 			    struct CompileEnv *envPtr);
3638 MODULE_SCOPE int	TclCompileEnsemble(Tcl_Interp *interp,
3639 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3640 			    struct CompileEnv *envPtr);
3641 MODULE_SCOPE int	TclCompileErrorCmd(Tcl_Interp *interp,
3642 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3643 			    struct CompileEnv *envPtr);
3644 MODULE_SCOPE int	TclCompileExprCmd(Tcl_Interp *interp,
3645 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3646 			    struct CompileEnv *envPtr);
3647 MODULE_SCOPE int	TclCompileForCmd(Tcl_Interp *interp,
3648 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3649 			    struct CompileEnv *envPtr);
3650 MODULE_SCOPE int	TclCompileForeachCmd(Tcl_Interp *interp,
3651 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3652 			    struct CompileEnv *envPtr);
3653 MODULE_SCOPE int	TclCompileFormatCmd(Tcl_Interp *interp,
3654 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3655 			    struct CompileEnv *envPtr);
3656 MODULE_SCOPE int	TclCompileGlobalCmd(Tcl_Interp *interp,
3657 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3658 			    struct CompileEnv *envPtr);
3659 MODULE_SCOPE int	TclCompileIfCmd(Tcl_Interp *interp,
3660 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3661 			    struct CompileEnv *envPtr);
3662 MODULE_SCOPE int	TclCompileInfoCommandsCmd(Tcl_Interp *interp,
3663 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3664 			    struct CompileEnv *envPtr);
3665 MODULE_SCOPE int	TclCompileInfoCoroutineCmd(Tcl_Interp *interp,
3666 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3667 			    struct CompileEnv *envPtr);
3668 MODULE_SCOPE int	TclCompileInfoExistsCmd(Tcl_Interp *interp,
3669 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3670 			    struct CompileEnv *envPtr);
3671 MODULE_SCOPE int	TclCompileInfoLevelCmd(Tcl_Interp *interp,
3672 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3673 			    struct CompileEnv *envPtr);
3674 MODULE_SCOPE int	TclCompileInfoObjectClassCmd(Tcl_Interp *interp,
3675 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3676 			    struct CompileEnv *envPtr);
3677 MODULE_SCOPE int	TclCompileInfoObjectIsACmd(Tcl_Interp *interp,
3678 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3679 			    struct CompileEnv *envPtr);
3680 MODULE_SCOPE int	TclCompileInfoObjectNamespaceCmd(Tcl_Interp *interp,
3681 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3682 			    struct CompileEnv *envPtr);
3683 MODULE_SCOPE int	TclCompileIncrCmd(Tcl_Interp *interp,
3684 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3685 			    struct CompileEnv *envPtr);
3686 MODULE_SCOPE int	TclCompileLappendCmd(Tcl_Interp *interp,
3687 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3688 			    struct CompileEnv *envPtr);
3689 MODULE_SCOPE int	TclCompileLassignCmd(Tcl_Interp *interp,
3690 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3691 			    struct CompileEnv *envPtr);
3692 MODULE_SCOPE int	TclCompileLindexCmd(Tcl_Interp *interp,
3693 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3694 			    struct CompileEnv *envPtr);
3695 MODULE_SCOPE int	TclCompileLinsertCmd(Tcl_Interp *interp,
3696 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3697 			    struct CompileEnv *envPtr);
3698 MODULE_SCOPE int	TclCompileListCmd(Tcl_Interp *interp,
3699 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3700 			    struct CompileEnv *envPtr);
3701 MODULE_SCOPE int	TclCompileLlengthCmd(Tcl_Interp *interp,
3702 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3703 			    struct CompileEnv *envPtr);
3704 MODULE_SCOPE int	TclCompileLmapCmd(Tcl_Interp *interp,
3705 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3706 			    struct CompileEnv *envPtr);
3707 MODULE_SCOPE int	TclCompileLrangeCmd(Tcl_Interp *interp,
3708 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3709 			    struct CompileEnv *envPtr);
3710 MODULE_SCOPE int	TclCompileLreplaceCmd(Tcl_Interp *interp,
3711 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3712 			    struct CompileEnv *envPtr);
3713 MODULE_SCOPE int	TclCompileLsetCmd(Tcl_Interp *interp,
3714 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3715 			    struct CompileEnv *envPtr);
3716 MODULE_SCOPE int	TclCompileNamespaceCodeCmd(Tcl_Interp *interp,
3717 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3718 			    struct CompileEnv *envPtr);
3719 MODULE_SCOPE int	TclCompileNamespaceCurrentCmd(Tcl_Interp *interp,
3720 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3721 			    struct CompileEnv *envPtr);
3722 MODULE_SCOPE int	TclCompileNamespaceOriginCmd(Tcl_Interp *interp,
3723 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3724 			    struct CompileEnv *envPtr);
3725 MODULE_SCOPE int	TclCompileNamespaceQualifiersCmd(Tcl_Interp *interp,
3726 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3727 			    struct CompileEnv *envPtr);
3728 MODULE_SCOPE int	TclCompileNamespaceTailCmd(Tcl_Interp *interp,
3729 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3730 			    struct CompileEnv *envPtr);
3731 MODULE_SCOPE int	TclCompileNamespaceUpvarCmd(Tcl_Interp *interp,
3732 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3733 			    struct CompileEnv *envPtr);
3734 MODULE_SCOPE int	TclCompileNamespaceWhichCmd(Tcl_Interp *interp,
3735 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3736 			    struct CompileEnv *envPtr);
3737 MODULE_SCOPE int	TclCompileNoOp(Tcl_Interp *interp,
3738 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3739 			    struct CompileEnv *envPtr);
3740 MODULE_SCOPE int	TclCompileObjectNextCmd(Tcl_Interp *interp,
3741 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3742 			    struct CompileEnv *envPtr);
3743 MODULE_SCOPE int	TclCompileObjectNextToCmd(Tcl_Interp *interp,
3744 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3745 			    struct CompileEnv *envPtr);
3746 MODULE_SCOPE int	TclCompileObjectSelfCmd(Tcl_Interp *interp,
3747 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3748 			    struct CompileEnv *envPtr);
3749 MODULE_SCOPE int	TclCompileRegexpCmd(Tcl_Interp *interp,
3750 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3751 			    struct CompileEnv *envPtr);
3752 MODULE_SCOPE int	TclCompileRegsubCmd(Tcl_Interp *interp,
3753 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3754 			    struct CompileEnv *envPtr);
3755 MODULE_SCOPE int	TclCompileReturnCmd(Tcl_Interp *interp,
3756 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3757 			    struct CompileEnv *envPtr);
3758 MODULE_SCOPE int	TclCompileSetCmd(Tcl_Interp *interp,
3759 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3760 			    struct CompileEnv *envPtr);
3761 MODULE_SCOPE int	TclCompileStringCatCmd(Tcl_Interp *interp,
3762 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3763 			    struct CompileEnv *envPtr);
3764 MODULE_SCOPE int	TclCompileStringCmpCmd(Tcl_Interp *interp,
3765 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3766 			    struct CompileEnv *envPtr);
3767 MODULE_SCOPE int	TclCompileStringEqualCmd(Tcl_Interp *interp,
3768 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3769 			    struct CompileEnv *envPtr);
3770 MODULE_SCOPE int	TclCompileStringFirstCmd(Tcl_Interp *interp,
3771 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3772 			    struct CompileEnv *envPtr);
3773 MODULE_SCOPE int	TclCompileStringIndexCmd(Tcl_Interp *interp,
3774 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3775 			    struct CompileEnv *envPtr);
3776 MODULE_SCOPE int	TclCompileStringIsCmd(Tcl_Interp *interp,
3777 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3778 			    struct CompileEnv *envPtr);
3779 MODULE_SCOPE int	TclCompileStringLastCmd(Tcl_Interp *interp,
3780 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3781 			    struct CompileEnv *envPtr);
3782 MODULE_SCOPE int	TclCompileStringLenCmd(Tcl_Interp *interp,
3783 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3784 			    struct CompileEnv *envPtr);
3785 MODULE_SCOPE int	TclCompileStringMapCmd(Tcl_Interp *interp,
3786 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3787 			    struct CompileEnv *envPtr);
3788 MODULE_SCOPE int	TclCompileStringMatchCmd(Tcl_Interp *interp,
3789 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3790 			    struct CompileEnv *envPtr);
3791 MODULE_SCOPE int	TclCompileStringRangeCmd(Tcl_Interp *interp,
3792 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3793 			    struct CompileEnv *envPtr);
3794 MODULE_SCOPE int	TclCompileStringReplaceCmd(Tcl_Interp *interp,
3795 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3796 			    struct CompileEnv *envPtr);
3797 MODULE_SCOPE int	TclCompileStringToLowerCmd(Tcl_Interp *interp,
3798 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3799 			    struct CompileEnv *envPtr);
3800 MODULE_SCOPE int	TclCompileStringToTitleCmd(Tcl_Interp *interp,
3801 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3802 			    struct CompileEnv *envPtr);
3803 MODULE_SCOPE int	TclCompileStringToUpperCmd(Tcl_Interp *interp,
3804 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3805 			    struct CompileEnv *envPtr);
3806 MODULE_SCOPE int	TclCompileStringTrimCmd(Tcl_Interp *interp,
3807 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3808 			    struct CompileEnv *envPtr);
3809 MODULE_SCOPE int	TclCompileStringTrimLCmd(Tcl_Interp *interp,
3810 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3811 			    struct CompileEnv *envPtr);
3812 MODULE_SCOPE int	TclCompileStringTrimRCmd(Tcl_Interp *interp,
3813 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3814 			    struct CompileEnv *envPtr);
3815 MODULE_SCOPE int	TclCompileSubstCmd(Tcl_Interp *interp,
3816 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3817 			    struct CompileEnv *envPtr);
3818 MODULE_SCOPE int	TclCompileSwitchCmd(Tcl_Interp *interp,
3819 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3820 			    struct CompileEnv *envPtr);
3821 MODULE_SCOPE int	TclCompileTailcallCmd(Tcl_Interp *interp,
3822 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3823 			    struct CompileEnv *envPtr);
3824 MODULE_SCOPE int	TclCompileThrowCmd(Tcl_Interp *interp,
3825 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3826 			    struct CompileEnv *envPtr);
3827 MODULE_SCOPE int	TclCompileTryCmd(Tcl_Interp *interp,
3828 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3829 			    struct CompileEnv *envPtr);
3830 MODULE_SCOPE int	TclCompileUnsetCmd(Tcl_Interp *interp,
3831 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3832 			    struct CompileEnv *envPtr);
3833 MODULE_SCOPE int	TclCompileUpvarCmd(Tcl_Interp *interp,
3834 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3835 			    struct CompileEnv *envPtr);
3836 MODULE_SCOPE int	TclCompileVariableCmd(Tcl_Interp *interp,
3837 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3838 			    struct CompileEnv *envPtr);
3839 MODULE_SCOPE int	TclCompileWhileCmd(Tcl_Interp *interp,
3840 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3841 			    struct CompileEnv *envPtr);
3842 MODULE_SCOPE int	TclCompileYieldCmd(Tcl_Interp *interp,
3843 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3844 			    struct CompileEnv *envPtr);
3845 MODULE_SCOPE int	TclCompileYieldToCmd(Tcl_Interp *interp,
3846 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3847 			    struct CompileEnv *envPtr);
3848 MODULE_SCOPE int	TclCompileBasic0ArgCmd(Tcl_Interp *interp,
3849 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3850 			    struct CompileEnv *envPtr);
3851 MODULE_SCOPE int	TclCompileBasic1ArgCmd(Tcl_Interp *interp,
3852 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3853 			    struct CompileEnv *envPtr);
3854 MODULE_SCOPE int	TclCompileBasic2ArgCmd(Tcl_Interp *interp,
3855 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3856 			    struct CompileEnv *envPtr);
3857 MODULE_SCOPE int	TclCompileBasic3ArgCmd(Tcl_Interp *interp,
3858 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3859 			    struct CompileEnv *envPtr);
3860 MODULE_SCOPE int	TclCompileBasic0Or1ArgCmd(Tcl_Interp *interp,
3861 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3862 			    struct CompileEnv *envPtr);
3863 MODULE_SCOPE int	TclCompileBasic1Or2ArgCmd(Tcl_Interp *interp,
3864 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3865 			    struct CompileEnv *envPtr);
3866 MODULE_SCOPE int	TclCompileBasic2Or3ArgCmd(Tcl_Interp *interp,
3867 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3868 			    struct CompileEnv *envPtr);
3869 MODULE_SCOPE int	TclCompileBasic0To2ArgCmd(Tcl_Interp *interp,
3870 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3871 			    struct CompileEnv *envPtr);
3872 MODULE_SCOPE int	TclCompileBasic1To3ArgCmd(Tcl_Interp *interp,
3873 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3874 			    struct CompileEnv *envPtr);
3875 MODULE_SCOPE int	TclCompileBasicMin0ArgCmd(Tcl_Interp *interp,
3876 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3877 			    struct CompileEnv *envPtr);
3878 MODULE_SCOPE int	TclCompileBasicMin1ArgCmd(Tcl_Interp *interp,
3879 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3880 			    struct CompileEnv *envPtr);
3881 MODULE_SCOPE int	TclCompileBasicMin2ArgCmd(Tcl_Interp *interp,
3882 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3883 			    struct CompileEnv *envPtr);
3884 
3885 MODULE_SCOPE int	TclInvertOpCmd(ClientData clientData,
3886 			    Tcl_Interp *interp, int objc,
3887 			    Tcl_Obj *const objv[]);
3888 MODULE_SCOPE int	TclCompileInvertOpCmd(Tcl_Interp *interp,
3889 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3890 			    struct CompileEnv *envPtr);
3891 MODULE_SCOPE int	TclNotOpCmd(ClientData clientData,
3892 			    Tcl_Interp *interp, int objc,
3893 			    Tcl_Obj *const objv[]);
3894 MODULE_SCOPE int	TclCompileNotOpCmd(Tcl_Interp *interp,
3895 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3896 			    struct CompileEnv *envPtr);
3897 MODULE_SCOPE int	TclAddOpCmd(ClientData clientData,
3898 			    Tcl_Interp *interp, int objc,
3899 			    Tcl_Obj *const objv[]);
3900 MODULE_SCOPE int	TclCompileAddOpCmd(Tcl_Interp *interp,
3901 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3902 			    struct CompileEnv *envPtr);
3903 MODULE_SCOPE int	TclMulOpCmd(ClientData clientData,
3904 			    Tcl_Interp *interp, int objc,
3905 			    Tcl_Obj *const objv[]);
3906 MODULE_SCOPE int	TclCompileMulOpCmd(Tcl_Interp *interp,
3907 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3908 			    struct CompileEnv *envPtr);
3909 MODULE_SCOPE int	TclAndOpCmd(ClientData clientData,
3910 			    Tcl_Interp *interp, int objc,
3911 			    Tcl_Obj *const objv[]);
3912 MODULE_SCOPE int	TclCompileAndOpCmd(Tcl_Interp *interp,
3913 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3914 			    struct CompileEnv *envPtr);
3915 MODULE_SCOPE int	TclOrOpCmd(ClientData clientData,
3916 			    Tcl_Interp *interp, int objc,
3917 			    Tcl_Obj *const objv[]);
3918 MODULE_SCOPE int	TclCompileOrOpCmd(Tcl_Interp *interp,
3919 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3920 			    struct CompileEnv *envPtr);
3921 MODULE_SCOPE int	TclXorOpCmd(ClientData clientData,
3922 			    Tcl_Interp *interp, int objc,
3923 			    Tcl_Obj *const objv[]);
3924 MODULE_SCOPE int	TclCompileXorOpCmd(Tcl_Interp *interp,
3925 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3926 			    struct CompileEnv *envPtr);
3927 MODULE_SCOPE int	TclPowOpCmd(ClientData clientData,
3928 			    Tcl_Interp *interp, int objc,
3929 			    Tcl_Obj *const objv[]);
3930 MODULE_SCOPE int	TclCompilePowOpCmd(Tcl_Interp *interp,
3931 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3932 			    struct CompileEnv *envPtr);
3933 MODULE_SCOPE int	TclLshiftOpCmd(ClientData clientData,
3934 			    Tcl_Interp *interp, int objc,
3935 			    Tcl_Obj *const objv[]);
3936 MODULE_SCOPE int	TclCompileLshiftOpCmd(Tcl_Interp *interp,
3937 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3938 			    struct CompileEnv *envPtr);
3939 MODULE_SCOPE int	TclRshiftOpCmd(ClientData clientData,
3940 			    Tcl_Interp *interp, int objc,
3941 			    Tcl_Obj *const objv[]);
3942 MODULE_SCOPE int	TclCompileRshiftOpCmd(Tcl_Interp *interp,
3943 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3944 			    struct CompileEnv *envPtr);
3945 MODULE_SCOPE int	TclModOpCmd(ClientData clientData,
3946 			    Tcl_Interp *interp, int objc,
3947 			    Tcl_Obj *const objv[]);
3948 MODULE_SCOPE int	TclCompileModOpCmd(Tcl_Interp *interp,
3949 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3950 			    struct CompileEnv *envPtr);
3951 MODULE_SCOPE int	TclNeqOpCmd(ClientData clientData,
3952 			    Tcl_Interp *interp, int objc,
3953 			    Tcl_Obj *const objv[]);
3954 MODULE_SCOPE int	TclCompileNeqOpCmd(Tcl_Interp *interp,
3955 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3956 			    struct CompileEnv *envPtr);
3957 MODULE_SCOPE int	TclStrneqOpCmd(ClientData clientData,
3958 			    Tcl_Interp *interp, int objc,
3959 			    Tcl_Obj *const objv[]);
3960 MODULE_SCOPE int	TclCompileStrneqOpCmd(Tcl_Interp *interp,
3961 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3962 			    struct CompileEnv *envPtr);
3963 MODULE_SCOPE int	TclInOpCmd(ClientData clientData,
3964 			    Tcl_Interp *interp, int objc,
3965 			    Tcl_Obj *const objv[]);
3966 MODULE_SCOPE int	TclCompileInOpCmd(Tcl_Interp *interp,
3967 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3968 			    struct CompileEnv *envPtr);
3969 MODULE_SCOPE int	TclNiOpCmd(ClientData clientData,
3970 			    Tcl_Interp *interp, int objc,
3971 			    Tcl_Obj *const objv[]);
3972 MODULE_SCOPE int	TclCompileNiOpCmd(Tcl_Interp *interp,
3973 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3974 			    struct CompileEnv *envPtr);
3975 MODULE_SCOPE int	TclMinusOpCmd(ClientData clientData,
3976 			    Tcl_Interp *interp, int objc,
3977 			    Tcl_Obj *const objv[]);
3978 MODULE_SCOPE int	TclCompileMinusOpCmd(Tcl_Interp *interp,
3979 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3980 			    struct CompileEnv *envPtr);
3981 MODULE_SCOPE int	TclDivOpCmd(ClientData clientData,
3982 			    Tcl_Interp *interp, int objc,
3983 			    Tcl_Obj *const objv[]);
3984 MODULE_SCOPE int	TclCompileDivOpCmd(Tcl_Interp *interp,
3985 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3986 			    struct CompileEnv *envPtr);
3987 MODULE_SCOPE int	TclCompileLessOpCmd(Tcl_Interp *interp,
3988 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3989 			    struct CompileEnv *envPtr);
3990 MODULE_SCOPE int	TclCompileLeqOpCmd(Tcl_Interp *interp,
3991 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3992 			    struct CompileEnv *envPtr);
3993 MODULE_SCOPE int	TclCompileGreaterOpCmd(Tcl_Interp *interp,
3994 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3995 			    struct CompileEnv *envPtr);
3996 MODULE_SCOPE int	TclCompileGeqOpCmd(Tcl_Interp *interp,
3997 			    Tcl_Parse *parsePtr, Command *cmdPtr,
3998 			    struct CompileEnv *envPtr);
3999 MODULE_SCOPE int	TclCompileEqOpCmd(Tcl_Interp *interp,
4000 			    Tcl_Parse *parsePtr, Command *cmdPtr,
4001 			    struct CompileEnv *envPtr);
4002 MODULE_SCOPE int	TclCompileStreqOpCmd(Tcl_Interp *interp,
4003 			    Tcl_Parse *parsePtr, Command *cmdPtr,
4004 			    struct CompileEnv *envPtr);
4005 
4006 MODULE_SCOPE int	TclCompileAssembleCmd(Tcl_Interp *interp,
4007 			    Tcl_Parse *parsePtr, Command *cmdPtr,
4008 			    struct CompileEnv *envPtr);
4009 
4010 /*
4011  * Functions defined in generic/tclVar.c and currently exported only for use
4012  * by the bytecode compiler and engine. Some of these could later be placed in
4013  * the public interface.
4014  */
4015 
4016 MODULE_SCOPE Var *	TclObjLookupVarEx(Tcl_Interp * interp,
4017 			    Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags,
4018 			    const char *msg, const int createPart1,
4019 			    const int createPart2, Var **arrayPtrPtr);
4020 MODULE_SCOPE Var *	TclLookupArrayElement(Tcl_Interp *interp,
4021 			    Tcl_Obj *arrayNamePtr, Tcl_Obj *elNamePtr,
4022 			    const int flags, const char *msg,
4023 			    const int createPart1, const int createPart2,
4024 			    Var *arrayPtr, int index);
4025 MODULE_SCOPE Tcl_Obj *	TclPtrGetVarIdx(Tcl_Interp *interp,
4026 			    Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr,
4027 			    Tcl_Obj *part2Ptr, const int flags, int index);
4028 MODULE_SCOPE Tcl_Obj *	TclPtrSetVarIdx(Tcl_Interp *interp,
4029 			    Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr,
4030 			    Tcl_Obj *part2Ptr, Tcl_Obj *newValuePtr,
4031 			    const int flags, int index);
4032 MODULE_SCOPE Tcl_Obj *	TclPtrIncrObjVarIdx(Tcl_Interp *interp,
4033 			    Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr,
4034 			    Tcl_Obj *part2Ptr, Tcl_Obj *incrPtr,
4035 			    const int flags, int index);
4036 MODULE_SCOPE int	TclPtrObjMakeUpvarIdx(Tcl_Interp *interp,
4037 			    Var *otherPtr, Tcl_Obj *myNamePtr, int myFlags,
4038 			    int index);
4039 MODULE_SCOPE int	TclPtrUnsetVarIdx(Tcl_Interp *interp, Var *varPtr,
4040 			    Var *arrayPtr, Tcl_Obj *part1Ptr,
4041 			    Tcl_Obj *part2Ptr, const int flags,
4042 			    int index);
4043 MODULE_SCOPE void	TclInvalidateNsPath(Namespace *nsPtr);
4044 MODULE_SCOPE void	TclFindArrayPtrElements(Var *arrayPtr,
4045 			    Tcl_HashTable *tablePtr);
4046 
4047 /*
4048  * The new extended interface to the variable traces.
4049  */
4050 
4051 MODULE_SCOPE int	TclObjCallVarTraces(Interp *iPtr, Var *arrayPtr,
4052 			    Var *varPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr,
4053 			    int flags, int leaveErrMsg, int index);
4054 
4055 /*
4056  * So tclObj.c and tclDictObj.c can share these implementations.
4057  */
4058 
4059 MODULE_SCOPE int	TclCompareObjKeys(void *keyPtr, Tcl_HashEntry *hPtr);
4060 MODULE_SCOPE void	TclFreeObjEntry(Tcl_HashEntry *hPtr);
4061 MODULE_SCOPE unsigned	TclHashObjKey(Tcl_HashTable *tablePtr, void *keyPtr);
4062 
4063 MODULE_SCOPE int	TclFullFinalizationRequested(void);
4064 
4065 /*
4066  * Utility routines for encoding index values as integers. Used by both
4067  * some of the command compilers and by [lsort] and [lsearch].
4068  */
4069 
4070 MODULE_SCOPE int	TclIndexEncode(Tcl_Interp *interp, Tcl_Obj *objPtr,
4071 			    int before, int after, int *indexPtr);
4072 MODULE_SCOPE int	TclIndexDecode(int encoded, int endValue);
4073 
4074 MODULE_SCOPE void	TclBN_s_mp_reverse(unsigned char *s, size_t len);
4075 
4076 /* Constants used in index value encoding routines. */
4077 #define TCL_INDEX_END           (-2)
4078 #define TCL_INDEX_BEFORE        (-1)
4079 #define TCL_INDEX_START         (0)
4080 #define TCL_INDEX_AFTER         (INT_MAX)
4081 
4082 /*
4083  *----------------------------------------------------------------
4084  * Macros used by the Tcl core to create and release Tcl objects.
4085  * TclNewObj(objPtr) creates a new object denoting an empty string.
4086  * TclDecrRefCount(objPtr) decrements the object's reference count, and frees
4087  * the object if its reference count is zero. These macros are inline versions
4088  * of Tcl_NewObj() and Tcl_DecrRefCount(). Notice that the names differ in not
4089  * having a "_" after the "Tcl". Notice also that these macros reference their
4090  * argument more than once, so you should avoid calling them with an
4091  * expression that is expensive to compute or has side effects. The ANSI C
4092  * "prototypes" for these macros are:
4093  *
4094  * MODULE_SCOPE void	TclNewObj(Tcl_Obj *objPtr);
4095  * MODULE_SCOPE void	TclDecrRefCount(Tcl_Obj *objPtr);
4096  *
4097  * These macros are defined in terms of two macros that depend on memory
4098  * allocator in use: TclAllocObjStorage, TclFreeObjStorage. They are defined
4099  * below.
4100  *----------------------------------------------------------------
4101  */
4102 
4103 /*
4104  * DTrace object allocation probe macros.
4105  */
4106 
4107 #ifdef USE_DTRACE
4108 #ifndef _TCLDTRACE_H
4109 #include "tclDTrace.h"
4110 #endif
4111 #define	TCL_DTRACE_OBJ_CREATE(objPtr)	TCL_OBJ_CREATE(objPtr)
4112 #define	TCL_DTRACE_OBJ_FREE(objPtr)	TCL_OBJ_FREE(objPtr)
4113 #else /* USE_DTRACE */
4114 #define	TCL_DTRACE_OBJ_CREATE(objPtr)	{}
4115 #define	TCL_DTRACE_OBJ_FREE(objPtr)	{}
4116 #endif /* USE_DTRACE */
4117 
4118 #ifdef TCL_COMPILE_STATS
4119 #  define TclIncrObjsAllocated() \
4120     tclObjsAlloced++
4121 #  define TclIncrObjsFreed() \
4122     tclObjsFreed++
4123 #else
4124 #  define TclIncrObjsAllocated()
4125 #  define TclIncrObjsFreed()
4126 #endif /* TCL_COMPILE_STATS */
4127 
4128 #  define TclAllocObjStorage(objPtr)		\
4129 	TclAllocObjStorageEx(NULL, (objPtr))
4130 
4131 #  define TclFreeObjStorage(objPtr)		\
4132 	TclFreeObjStorageEx(NULL, (objPtr))
4133 
4134 #ifndef TCL_MEM_DEBUG
4135 # define TclNewObj(objPtr) \
4136     TclIncrObjsAllocated(); \
4137     TclAllocObjStorage(objPtr); \
4138     (objPtr)->refCount = 0; \
4139     (objPtr)->bytes    = tclEmptyStringRep; \
4140     (objPtr)->length   = 0; \
4141     (objPtr)->typePtr  = NULL; \
4142     TCL_DTRACE_OBJ_CREATE(objPtr)
4143 
4144 /*
4145  * Invalidate the string rep first so we can use the bytes value for our
4146  * pointer chain, and signal an obj deletion (as opposed to shimmering) with
4147  * 'length == -1'.
4148  * Use empty 'if ; else' to handle use in unbraced outer if/else conditions.
4149  */
4150 
4151 # define TclDecrRefCount(objPtr) \
4152     if ((objPtr)->refCount-- > 1) ; else { \
4153 	if (!(objPtr)->typePtr || !(objPtr)->typePtr->freeIntRepProc) { \
4154 	    TCL_DTRACE_OBJ_FREE(objPtr); \
4155 	    if ((objPtr)->bytes \
4156 		    && ((objPtr)->bytes != tclEmptyStringRep)) { \
4157 		ckfree((char *) (objPtr)->bytes); \
4158 	    } \
4159 	    (objPtr)->length = -1; \
4160 	    TclFreeObjStorage(objPtr); \
4161 	    TclIncrObjsFreed(); \
4162 	} else { \
4163 	    TclFreeObj(objPtr); \
4164 	} \
4165     }
4166 
4167 #if defined(PURIFY)
4168 
4169 /*
4170  * The PURIFY mode is like the regular mode, but instead of doing block
4171  * Tcl_Obj allocation and keeping a freed list for efficiency, it always
4172  * allocates and frees a single Tcl_Obj so that tools like Purify can better
4173  * track memory leaks.
4174  */
4175 
4176 #  define TclAllocObjStorageEx(interp, objPtr) \
4177 	(objPtr) = (Tcl_Obj *) ckalloc(sizeof(Tcl_Obj))
4178 
4179 #  define TclFreeObjStorageEx(interp, objPtr) \
4180 	ckfree((char *) (objPtr))
4181 
4182 #undef USE_THREAD_ALLOC
4183 #undef USE_TCLALLOC
4184 #elif defined(TCL_THREADS) && defined(USE_THREAD_ALLOC)
4185 
4186 /*
4187  * The TCL_THREADS mode is like the regular mode but allocates Tcl_Obj's from
4188  * per-thread caches.
4189  */
4190 
4191 MODULE_SCOPE Tcl_Obj *	TclThreadAllocObj(void);
4192 MODULE_SCOPE void	TclThreadFreeObj(Tcl_Obj *);
4193 MODULE_SCOPE Tcl_Mutex *TclpNewAllocMutex(void);
4194 MODULE_SCOPE void	TclFreeAllocCache(void *);
4195 MODULE_SCOPE void *	TclpGetAllocCache(void);
4196 MODULE_SCOPE void	TclpSetAllocCache(void *);
4197 MODULE_SCOPE void	TclpFreeAllocMutex(Tcl_Mutex *mutex);
4198 MODULE_SCOPE void	TclpFreeAllocCache(void *);
4199 
4200 /*
4201  * These macros need to be kept in sync with the code of TclThreadAllocObj()
4202  * and TclThreadFreeObj().
4203  *
4204  * Note that the optimiser should resolve the case (interp==NULL) at compile
4205  * time.
4206  */
4207 
4208 #  define ALLOC_NOBJHIGH 1200
4209 
4210 #  define TclAllocObjStorageEx(interp, objPtr)				\
4211     do {								\
4212 	AllocCache *cachePtr;						\
4213 	if (((interp) == NULL) ||					\
4214 		((cachePtr = ((Interp *)(interp))->allocCache),		\
4215 			(cachePtr->numObjects == 0))) {			\
4216 	    (objPtr) = TclThreadAllocObj();				\
4217 	} else {							\
4218 	    (objPtr) = cachePtr->firstObjPtr;				\
4219 	    cachePtr->firstObjPtr = (Tcl_Obj *)(objPtr)->internalRep.twoPtrValue.ptr1; \
4220 	    --cachePtr->numObjects;					\
4221 	}								\
4222     } while (0)
4223 
4224 #  define TclFreeObjStorageEx(interp, objPtr)				\
4225     do {								\
4226 	AllocCache *cachePtr;						\
4227 	if (((interp) == NULL) ||					\
4228 		((cachePtr = ((Interp *)(interp))->allocCache),		\
4229 			((cachePtr->numObjects == 0) ||			\
4230 			(cachePtr->numObjects >= ALLOC_NOBJHIGH)))) {	\
4231 	    TclThreadFreeObj(objPtr);					\
4232 	} else {							\
4233 	    (objPtr)->internalRep.twoPtrValue.ptr1 = cachePtr->firstObjPtr; \
4234 	    cachePtr->firstObjPtr = objPtr;				\
4235 	    ++cachePtr->numObjects;					\
4236 	}								\
4237     } while (0)
4238 
4239 #else /* not PURIFY or USE_THREAD_ALLOC */
4240 
4241 #if defined(USE_TCLALLOC) && USE_TCLALLOC
4242     MODULE_SCOPE void TclFinalizeAllocSubsystem();
4243     MODULE_SCOPE void TclInitAlloc();
4244 #else
4245 #   define USE_TCLALLOC 0
4246 #endif
4247 
4248 #ifdef TCL_THREADS
4249 /* declared in tclObj.c */
4250 MODULE_SCOPE Tcl_Mutex	tclObjMutex;
4251 #endif
4252 
4253 #  define TclAllocObjStorageEx(interp, objPtr) \
4254     do {								\
4255 	Tcl_MutexLock(&tclObjMutex);					\
4256 	if (tclFreeObjList == NULL) {					\
4257 	    TclAllocateFreeObjects();					\
4258 	}								\
4259 	(objPtr) = tclFreeObjList;					\
4260 	tclFreeObjList = (Tcl_Obj *)					\
4261 		tclFreeObjList->internalRep.twoPtrValue.ptr1;		\
4262 	Tcl_MutexUnlock(&tclObjMutex);					\
4263     } while (0)
4264 
4265 #  define TclFreeObjStorageEx(interp, objPtr) \
4266     do {							       \
4267 	Tcl_MutexLock(&tclObjMutex);				       \
4268 	(objPtr)->internalRep.twoPtrValue.ptr1 = (void *) tclFreeObjList; \
4269 	tclFreeObjList = (objPtr);				       \
4270 	Tcl_MutexUnlock(&tclObjMutex);				       \
4271     } while (0)
4272 #endif
4273 
4274 #else /* TCL_MEM_DEBUG */
4275 MODULE_SCOPE void	TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
4276 			    int line);
4277 
4278 # define TclDbNewObj(objPtr, file, line) \
4279     do { \
4280 	TclIncrObjsAllocated();						\
4281 	(objPtr) = (Tcl_Obj *)						\
4282 		Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line));		\
4283 	TclDbInitNewObj((objPtr), (file), (line));			\
4284 	TCL_DTRACE_OBJ_CREATE(objPtr);					\
4285     } while (0)
4286 
4287 # define TclNewObj(objPtr) \
4288     TclDbNewObj(objPtr, __FILE__, __LINE__);
4289 
4290 # define TclDecrRefCount(objPtr) \
4291     Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__)
4292 
4293 # define TclNewListObjDirect(objc, objv) \
4294     TclDbNewListObjDirect(objc, objv, __FILE__, __LINE__)
4295 
4296 #undef USE_THREAD_ALLOC
4297 #endif /* TCL_MEM_DEBUG */
4298 
4299 /*
4300  *----------------------------------------------------------------
4301  * Macro used by the Tcl core to set a Tcl_Obj's string representation to a
4302  * copy of the "len" bytes starting at "bytePtr". This code works even if the
4303  * byte array contains NULLs as long as the length is correct. Because "len"
4304  * is referenced multiple times, it should be as simple an expression as
4305  * possible. The ANSI C "prototype" for this macro is:
4306  *
4307  * MODULE_SCOPE void TclInitStringRep(Tcl_Obj *objPtr, char *bytePtr, int len);
4308  *
4309  * This macro should only be called on an unshared objPtr where
4310  *  objPtr->typePtr->freeIntRepProc == NULL
4311  *----------------------------------------------------------------
4312  */
4313 
4314 #define TclInitStringRep(objPtr, bytePtr, len) \
4315     if ((len) == 0) { \
4316 	(objPtr)->bytes	 = tclEmptyStringRep; \
4317 	(objPtr)->length = 0; \
4318     } else { \
4319 	(objPtr)->bytes = (char *) ckalloc((len) + 1); \
4320 	memcpy((objPtr)->bytes, (bytePtr), (len)); \
4321 	(objPtr)->bytes[len] = '\0'; \
4322 	(objPtr)->length = (len); \
4323     }
4324 
4325 /*
4326  *----------------------------------------------------------------
4327  * Macro used by the Tcl core to get the string representation's byte array
4328  * pointer from a Tcl_Obj. This is an inline version of Tcl_GetString(). The
4329  * macro's expression result is the string rep's byte pointer which might be
4330  * NULL. The bytes referenced by this pointer must not be modified by the
4331  * caller. The ANSI C "prototype" for this macro is:
4332  *
4333  * MODULE_SCOPE char *	TclGetString(Tcl_Obj *objPtr);
4334  *----------------------------------------------------------------
4335  */
4336 
4337 #define TclGetString(objPtr) \
4338     ((objPtr)->bytes? (objPtr)->bytes : Tcl_GetString((objPtr)))
4339 
4340 #define TclGetStringFromObj(objPtr, lenPtr) \
4341     ((objPtr)->bytes \
4342 	    ? (*(lenPtr) = (objPtr)->length, (objPtr)->bytes)	\
4343 	    : Tcl_GetStringFromObj((objPtr), (lenPtr)))
4344 
4345 /*
4346  *----------------------------------------------------------------
4347  * Macro used by the Tcl core to clean out an object's internal
4348  * representation. Does not actually reset the rep's bytes. The ANSI C
4349  * "prototype" for this macro is:
4350  *
4351  * MODULE_SCOPE void	TclFreeIntRep(Tcl_Obj *objPtr);
4352  *----------------------------------------------------------------
4353  */
4354 
4355 #define TclFreeIntRep(objPtr) \
4356     if ((objPtr)->typePtr != NULL) { \
4357 	if ((objPtr)->typePtr->freeIntRepProc != NULL) { \
4358 	    (objPtr)->typePtr->freeIntRepProc(objPtr); \
4359 	} \
4360 	(objPtr)->typePtr = NULL; \
4361     }
4362 
4363 /*
4364  *----------------------------------------------------------------
4365  * Macro used by the Tcl core to clean out an object's string representation.
4366  * The ANSI C "prototype" for this macro is:
4367  *
4368  * MODULE_SCOPE void	TclInvalidateStringRep(Tcl_Obj *objPtr);
4369  *----------------------------------------------------------------
4370  */
4371 
4372 #define TclInvalidateStringRep(objPtr) \
4373     do { \
4374 	Tcl_Obj *_isobjPtr = (Tcl_Obj *)(objPtr); \
4375 	if (_isobjPtr->bytes != NULL) { \
4376 	    if (_isobjPtr->bytes != tclEmptyStringRep) { \
4377 		ckfree((char *)_isobjPtr->bytes); \
4378 	    } \
4379 	    _isobjPtr->bytes = NULL; \
4380 	} \
4381     } while (0)
4382 
4383 #define TclHasStringRep(objPtr) \
4384     ((objPtr)->bytes != NULL)
4385 
4386 /*
4387  *----------------------------------------------------------------
4388  * Macros used by the Tcl core to grow Tcl_Token arrays. They use the same
4389  * growth algorithm as used in tclStringObj.c for growing strings. The ANSI C
4390  * "prototype" for this macro is:
4391  *
4392  * MODULE_SCOPE void	TclGrowTokenArray(Tcl_Token *tokenPtr, int used,
4393  *				int available, int append,
4394  *				Tcl_Token *staticPtr);
4395  * MODULE_SCOPE void	TclGrowParseTokenArray(Tcl_Parse *parsePtr,
4396  *				int append);
4397  *----------------------------------------------------------------
4398  */
4399 
4400 /* General tuning for minimum growth in Tcl growth algorithms */
4401 #ifndef TCL_MIN_GROWTH
4402 #  ifdef TCL_GROWTH_MIN_ALLOC
4403      /* Support for any legacy tuners */
4404 #    define TCL_MIN_GROWTH TCL_GROWTH_MIN_ALLOC
4405 #  else
4406 #    define TCL_MIN_GROWTH 1024
4407 #  endif
4408 #endif
4409 
4410 /* Token growth tuning, default to the general value. */
4411 #ifndef TCL_MIN_TOKEN_GROWTH
4412 #define TCL_MIN_TOKEN_GROWTH TCL_MIN_GROWTH/sizeof(Tcl_Token)
4413 #endif
4414 
4415 #define TCL_MAX_TOKENS (int)(UINT_MAX / sizeof(Tcl_Token))
4416 #define TclGrowTokenArray(tokenPtr, used, available, append, staticPtr)	\
4417     do {								\
4418 	int _needed = (used) + (append);					\
4419 	if (_needed > TCL_MAX_TOKENS) {					\
4420 	    Tcl_Panic("max # of tokens for a Tcl parse (%d) exceeded",	\
4421 		    TCL_MAX_TOKENS);					\
4422 	}								\
4423 	if (_needed > (available)) {					\
4424 	    int allocated = 2 * _needed;					\
4425 	    Tcl_Token *oldPtr = (tokenPtr);				\
4426 	    Tcl_Token *newPtr;						\
4427 	    if (oldPtr == (staticPtr)) {				\
4428 		oldPtr = NULL;						\
4429 	    }								\
4430 	    if (allocated > TCL_MAX_TOKENS) {				\
4431 		allocated = TCL_MAX_TOKENS;				\
4432 	    }								\
4433 	    newPtr = (Tcl_Token *) attemptckrealloc((char *) oldPtr,	\
4434 		    (unsigned int) (allocated * sizeof(Tcl_Token)));	\
4435 	    if (newPtr == NULL) {					\
4436 		allocated = _needed + (append) + TCL_MIN_TOKEN_GROWTH;	\
4437 		if (allocated > TCL_MAX_TOKENS) {			\
4438 		    allocated = TCL_MAX_TOKENS;				\
4439 		}							\
4440 		newPtr = (Tcl_Token *) ckrealloc((char *) oldPtr,	\
4441 			(unsigned int) (allocated * sizeof(Tcl_Token))); \
4442 	    }								\
4443 	    (available) = allocated;					\
4444 	    if (oldPtr == NULL) {					\
4445 		memcpy(newPtr, staticPtr,				\
4446 			(size_t) ((used) * sizeof(Tcl_Token)));		\
4447 	    }								\
4448 	    (tokenPtr) = newPtr;					\
4449 	}								\
4450     } while (0)
4451 
4452 #define TclGrowParseTokenArray(parsePtr, append)			\
4453     TclGrowTokenArray((parsePtr)->tokenPtr, (parsePtr)->numTokens,	\
4454 	    (parsePtr)->tokensAvailable, (append),			\
4455 	    (parsePtr)->staticTokens)
4456 
4457 /*
4458  *----------------------------------------------------------------
4459  * Macro used by the Tcl core get a unicode char from a utf string. It checks
4460  * to see if we have a one-byte utf char before calling the real
4461  * Tcl_UtfToUniChar, as this will save a lot of time for primarily ASCII
4462  * string handling. The macro's expression result is 1 for the 1-byte case or
4463  * the result of Tcl_UtfToUniChar. The ANSI C "prototype" for this macro is:
4464  *
4465  * MODULE_SCOPE int	TclUtfToUniChar(const char *string, Tcl_UniChar *ch);
4466  *----------------------------------------------------------------
4467  */
4468 
4469 #define TclUtfToUniChar(str, chPtr) \
4470 	(((UCHAR(*(str))) < 0x80) ?		\
4471 	    ((*(chPtr) = UCHAR(*(str))), 1)	\
4472 	    : Tcl_UtfToUniChar(str, chPtr))
4473 
4474 /*
4475  *----------------------------------------------------------------
4476  * Macro counterpart of the Tcl_NumUtfChars() function. To be used in speed-
4477  * -sensitive points where it pays to avoid a function call in the common case
4478  * of counting along a string of all one-byte characters.  The ANSI C
4479  * "prototype" for this macro is:
4480  *
4481  * MODULE_SCOPE void	TclNumUtfChars(int numChars, const char *bytes,
4482  *				int numBytes);
4483  *----------------------------------------------------------------
4484  */
4485 
4486 #define TclNumUtfChars(numChars, bytes, numBytes) \
4487     do { \
4488 	int _count, _i = (numBytes); \
4489 	unsigned char *_str = (unsigned char *) (bytes); \
4490 	while (_i && (*_str < 0xC0)) { _i--; _str++; } \
4491 	_count = (numBytes) - _i; \
4492 	if (_i) { \
4493 	    _count += Tcl_NumUtfChars((bytes) + _count, _i); \
4494 	} \
4495 	(numChars) = _count; \
4496     } while (0);
4497 
4498 #define TclUtfPrev(src, start) \
4499 	(((src) < (start)+2) ? (start) : \
4500 	(UCHAR(*((src) - 1))) < 0x80 ? (src)-1 : \
4501 	Tcl_UtfPrev(src, start))
4502 
4503 /*
4504  *----------------------------------------------------------------
4505  * Macro that encapsulates the logic that determines when it is safe to
4506  * interpret a string as a byte array directly. In summary, the object must be
4507  * a byte array and must not have a string representation (as the operations
4508  * that it is used in are defined on strings, not byte arrays). Theoretically
4509  * it is possible to also be efficient in the case where the object's bytes
4510  * field is filled by generation from the byte array (c.f. list canonicality)
4511  * but we don't do that at the moment since this is purely about efficiency.
4512  * The ANSI C "prototype" for this macro is:
4513  *
4514  * MODULE_SCOPE int	TclIsPureByteArray(Tcl_Obj *objPtr);
4515  *----------------------------------------------------------------
4516  */
4517 
4518 #define TclIsPureByteArray(objPtr) \
4519 	(((objPtr)->typePtr==&tclByteArrayType) && ((objPtr)->bytes==NULL))
4520 #define TclIsPureDict(objPtr) \
4521 	(((objPtr)->bytes==NULL) && ((objPtr)->typePtr==&tclDictType))
4522 
4523 #define TclIsPureList(objPtr) \
4524 	(((objPtr)->bytes==NULL) && ((objPtr)->typePtr==&tclListType))
4525 
4526 /*
4527  *----------------------------------------------------------------
4528  * Macro used by the Tcl core to compare Unicode strings. On big-endian
4529  * systems we can use the more efficient memcmp, but this would not be
4530  * lexically correct on little-endian systems. The ANSI C "prototype" for
4531  * this macro is:
4532  *
4533  * MODULE_SCOPE int	TclUniCharNcmp(const Tcl_UniChar *cs,
4534  *			    const Tcl_UniChar *ct, unsigned long n);
4535  *----------------------------------------------------------------
4536  */
4537 
4538 #if defined(WORDS_BIGENDIAN) && (TCL_UTF_MAX != 4)
4539 #   define TclUniCharNcmp(cs,ct,n) memcmp((cs),(ct),(n)*sizeof(Tcl_UniChar))
4540 #else /* !WORDS_BIGENDIAN */
4541 #   define TclUniCharNcmp Tcl_UniCharNcmp
4542 #endif /* WORDS_BIGENDIAN */
4543 
4544 /*
4545  *----------------------------------------------------------------
4546  * Macro used by the Tcl core to increment a namespace's export epoch
4547  * counter. The ANSI C "prototype" for this macro is:
4548  *
4549  * MODULE_SCOPE void	TclInvalidateNsCmdLookup(Namespace *nsPtr);
4550  *----------------------------------------------------------------
4551  */
4552 
4553 #define TclInvalidateNsCmdLookup(nsPtr) \
4554     if ((nsPtr)->numExportPatterns) {		\
4555 	(nsPtr)->exportLookupEpoch++;		\
4556     }						\
4557     if ((nsPtr)->commandPathLength) {		\
4558 	(nsPtr)->cmdRefEpoch++;			\
4559     }
4560 
4561 /*
4562  *----------------------------------------------------------------------
4563  *
4564  * Core procedure added to libtommath for bignum manipulation.
4565  *
4566  *----------------------------------------------------------------------
4567  */
4568 
4569 MODULE_SCOPE Tcl_PackageInitProc TclTommath_Init;
4570 
4571 /*
4572  *----------------------------------------------------------------------
4573  *
4574  * External (platform specific) initialization routine, these declarations
4575  * explicitly don't use EXTERN since this code does not get compiled into the
4576  * library:
4577  *
4578  *----------------------------------------------------------------------
4579  */
4580 
4581 MODULE_SCOPE Tcl_PackageInitProc TclplatformtestInit;
4582 MODULE_SCOPE Tcl_PackageInitProc TclObjTest_Init;
4583 MODULE_SCOPE Tcl_PackageInitProc TclThread_Init;
4584 MODULE_SCOPE Tcl_PackageInitProc Procbodytest_Init;
4585 MODULE_SCOPE Tcl_PackageInitProc Procbodytest_SafeInit;
4586 
4587 /*
4588  *----------------------------------------------------------------
4589  * Macro used by the Tcl core to check whether a pattern has any characters
4590  * special to [string match]. The ANSI C "prototype" for this macro is:
4591  *
4592  * MODULE_SCOPE int	TclMatchIsTrivial(const char *pattern);
4593  *----------------------------------------------------------------
4594  */
4595 
4596 #define TclMatchIsTrivial(pattern) \
4597     (strpbrk((pattern), "*[?\\") == NULL)
4598 
4599 /*
4600  *----------------------------------------------------------------
4601  * Macros used by the Tcl core to set a Tcl_Obj's numeric representation
4602  * avoiding the corresponding function calls in time critical parts of the
4603  * core. They should only be called on unshared objects. The ANSI C
4604  * "prototypes" for these macros are:
4605  *
4606  * MODULE_SCOPE void	TclSetIntObj(Tcl_Obj *objPtr, int intValue);
4607  * MODULE_SCOPE void	TclSetLongObj(Tcl_Obj *objPtr, long longValue);
4608  * MODULE_SCOPE void	TclSetBooleanObj(Tcl_Obj *objPtr, long boolValue);
4609  * MODULE_SCOPE void	TclSetWideIntObj(Tcl_Obj *objPtr, Tcl_WideInt w);
4610  * MODULE_SCOPE void	TclSetDoubleObj(Tcl_Obj *objPtr, double d);
4611  *----------------------------------------------------------------
4612  */
4613 
4614 #define TclSetLongObj(objPtr, i) \
4615     do {						\
4616 	TclInvalidateStringRep(objPtr);			\
4617 	TclFreeIntRep(objPtr);				\
4618 	(objPtr)->internalRep.longValue = (long)(i);	\
4619 	(objPtr)->typePtr = &tclIntType;		\
4620     } while (0)
4621 
4622 #define TclSetIntObj(objPtr, l) \
4623     TclSetLongObj(objPtr, l)
4624 
4625 /*
4626  * NOTE: There is to be no such thing as a "pure" boolean. Boolean values set
4627  * programmatically go straight to being "int" Tcl_Obj's, with value 0 or 1.
4628  * The only "boolean" Tcl_Obj's shall be those holding the cached boolean
4629  * value of strings like: "yes", "no", "true", "false", "on", "off".
4630  */
4631 
4632 #define TclSetBooleanObj(objPtr, b) \
4633     TclSetLongObj(objPtr, (b)!=0);
4634 
4635 #ifndef TCL_WIDE_INT_IS_LONG
4636 #define TclSetWideIntObj(objPtr, w) \
4637     do {							\
4638 	TclInvalidateStringRep(objPtr);				\
4639 	TclFreeIntRep(objPtr);					\
4640 	(objPtr)->internalRep.wideValue = (Tcl_WideInt)(w);	\
4641 	(objPtr)->typePtr = &tclWideIntType;			\
4642     } while (0)
4643 #endif
4644 
4645 #define TclSetDoubleObj(objPtr, d) \
4646     do {							\
4647 	TclInvalidateStringRep(objPtr);				\
4648 	TclFreeIntRep(objPtr);					\
4649 	(objPtr)->internalRep.doubleValue = (double)(d);	\
4650 	(objPtr)->typePtr = &tclDoubleType;			\
4651     } while (0)
4652 
4653 /*
4654  *----------------------------------------------------------------
4655  * Macros used by the Tcl core to create and initialise objects of standard
4656  * types, avoiding the corresponding function calls in time critical parts of
4657  * the core. The ANSI C "prototypes" for these macros are:
4658  *
4659  * MODULE_SCOPE void	TclNewIntObj(Tcl_Obj *objPtr, int i);
4660  * MODULE_SCOPE void	TclNewLongObj(Tcl_Obj *objPtr, long l);
4661  * MODULE_SCOPE void	TclNewBooleanObj(Tcl_Obj *objPtr, int b);
4662  * MODULE_SCOPE void	TclNewWideObj(Tcl_Obj *objPtr, Tcl_WideInt w);
4663  * MODULE_SCOPE void	TclNewDoubleObj(Tcl_Obj *objPtr, double d);
4664  * MODULE_SCOPE void	TclNewStringObj(Tcl_Obj *objPtr, char *s, int len);
4665  * MODULE_SCOPE void	TclNewLiteralStringObj(Tcl_Obj*objPtr, char*sLiteral);
4666  *
4667  *----------------------------------------------------------------
4668  */
4669 
4670 #ifndef TCL_MEM_DEBUG
4671 #define TclNewLongObj(objPtr, i) \
4672     do {						\
4673 	TclIncrObjsAllocated();				\
4674 	TclAllocObjStorage(objPtr);			\
4675 	(objPtr)->refCount = 0;				\
4676 	(objPtr)->bytes = NULL;				\
4677 	(objPtr)->internalRep.longValue = (long)(i);	\
4678 	(objPtr)->typePtr = &tclIntType;		\
4679 	TCL_DTRACE_OBJ_CREATE(objPtr);			\
4680     } while (0)
4681 
4682 #define TclNewIntObj(objPtr, l) \
4683     TclNewLongObj(objPtr, l)
4684 
4685 /*
4686  * NOTE: There is to be no such thing as a "pure" boolean.
4687  * See comment above TclSetBooleanObj macro above.
4688  */
4689 #define TclNewBooleanObj(objPtr, b) \
4690     TclNewLongObj((objPtr), (b)!=0)
4691 
4692 #define TclNewDoubleObj(objPtr, d) \
4693     do {							\
4694 	TclIncrObjsAllocated();					\
4695 	TclAllocObjStorage(objPtr);				\
4696 	(objPtr)->refCount = 0;					\
4697 	(objPtr)->bytes = NULL;					\
4698 	(objPtr)->internalRep.doubleValue = (double)(d);	\
4699 	(objPtr)->typePtr = &tclDoubleType;			\
4700 	TCL_DTRACE_OBJ_CREATE(objPtr);				\
4701     } while (0)
4702 
4703 #define TclNewStringObj(objPtr, s, len) \
4704     do {							\
4705 	TclIncrObjsAllocated();					\
4706 	TclAllocObjStorage(objPtr);				\
4707 	(objPtr)->refCount = 0;					\
4708 	TclInitStringRep((objPtr), (s), (len));			\
4709 	(objPtr)->typePtr = NULL;				\
4710 	TCL_DTRACE_OBJ_CREATE(objPtr);				\
4711     } while (0)
4712 
4713 #else /* TCL_MEM_DEBUG */
4714 #define TclNewIntObj(objPtr, i) \
4715     (objPtr) = Tcl_NewIntObj(i)
4716 
4717 #define TclNewLongObj(objPtr, l) \
4718     (objPtr) = Tcl_NewLongObj(l)
4719 
4720 #define TclNewBooleanObj(objPtr, b) \
4721     (objPtr) = Tcl_NewBooleanObj(b)
4722 
4723 #define TclNewDoubleObj(objPtr, d) \
4724     (objPtr) = Tcl_NewDoubleObj(d)
4725 
4726 #define TclNewStringObj(objPtr, s, len) \
4727     (objPtr) = Tcl_NewStringObj((s), (len))
4728 #endif /* TCL_MEM_DEBUG */
4729 
4730 /*
4731  * The sLiteral argument *must* be a string literal; the incantation with
4732  * sizeof(sLiteral "") will fail to compile otherwise.
4733  */
4734 #define TclNewLiteralStringObj(objPtr, sLiteral) \
4735     TclNewStringObj((objPtr), (sLiteral), (int) (sizeof(sLiteral "") - 1))
4736 
4737 /*
4738  *----------------------------------------------------------------
4739  * Convenience macros for DStrings.
4740  * The ANSI C "prototypes" for these macros are:
4741  *
4742  * MODULE_SCOPE char * TclDStringAppendLiteral(Tcl_DString *dsPtr,
4743  *			const char *sLiteral);
4744  * MODULE_SCOPE void   TclDStringClear(Tcl_DString *dsPtr);
4745  */
4746 
4747 #define TclDStringAppendLiteral(dsPtr, sLiteral) \
4748     Tcl_DStringAppend((dsPtr), (sLiteral), (int) (sizeof(sLiteral "") - 1))
4749 #define TclDStringClear(dsPtr) \
4750     Tcl_DStringSetLength((dsPtr), 0)
4751 
4752 /*
4753  *----------------------------------------------------------------
4754  * Macros used by the Tcl core to test for some special double values.
4755  * The ANSI C "prototypes" for these macros are:
4756  *
4757  * MODULE_SCOPE int	TclIsInfinite(double d);
4758  * MODULE_SCOPE int	TclIsNaN(double d);
4759  */
4760 
4761 #ifdef _MSC_VER
4762 #    define TclIsInfinite(d)	(!(_finite((d))))
4763 #    define TclIsNaN(d)		(_isnan((d)))
4764 #else
4765 #    define TclIsInfinite(d)	((d) > DBL_MAX || (d) < -DBL_MAX)
4766 #    ifdef NO_ISNAN
4767 #	 define TclIsNaN(d)	((d) != (d))
4768 #    else
4769 #	 define TclIsNaN(d)	(isnan(d))
4770 #    endif
4771 #endif
4772 
4773 /*
4774  * ----------------------------------------------------------------------
4775  * Macro to use to find the offset of a field in a structure. Computes number
4776  * of bytes from beginning of structure to a given field.
4777  */
4778 
4779 #ifdef offsetof
4780 #define TclOffset(type, field) ((int) offsetof(type, field))
4781 #else
4782 #define TclOffset(type, field) ((int) ((char *) &((type *) 0)->field))
4783 #endif
4784 
4785 /*
4786  *----------------------------------------------------------------
4787  * Inline version of Tcl_GetCurrentNamespace and Tcl_GetGlobalNamespace.
4788  */
4789 
4790 #define TclGetCurrentNamespace(interp) \
4791     (Tcl_Namespace *) ((Interp *)(interp))->varFramePtr->nsPtr
4792 
4793 #define TclGetGlobalNamespace(interp) \
4794     (Tcl_Namespace *) ((Interp *)(interp))->globalNsPtr
4795 
4796 /*
4797  *----------------------------------------------------------------
4798  * Inline version of TclCleanupCommand; still need the function as it is in
4799  * the internal stubs, but the core can use the macro instead.
4800  */
4801 
4802 #define TclCleanupCommandMacro(cmdPtr) \
4803     if ((cmdPtr)->refCount-- <= 1) { \
4804 	ckfree((char *) (cmdPtr));\
4805     }
4806 
4807 /*
4808  *----------------------------------------------------------------
4809  * Inline versions of Tcl_LimitReady() and Tcl_LimitExceeded to limit number
4810  * of calls out of the critical path. Note that this code isn't particularly
4811  * readable; the non-inline version (in tclInterp.c) is much easier to
4812  * understand. Note also that these macros takes different args (iPtr->limit)
4813  * to the non-inline version.
4814  */
4815 
4816 #define TclLimitExceeded(limit) ((limit).exceeded != 0)
4817 
4818 #define TclLimitReady(limit)						\
4819     (((limit).active == 0) ? 0 :					\
4820     (++(limit).granularityTicker,					\
4821     ((((limit).active & TCL_LIMIT_COMMANDS) &&				\
4822 	    (((limit).cmdGranularity == 1) ||				\
4823 	    ((limit).granularityTicker % (limit).cmdGranularity == 0)))	\
4824 	    ? 1 :							\
4825     (((limit).active & TCL_LIMIT_TIME) &&				\
4826 	    (((limit).timeGranularity == 1) ||				\
4827 	    ((limit).granularityTicker % (limit).timeGranularity == 0)))\
4828 	    ? 1 : 0)))
4829 
4830 /*
4831  * Compile-time assertions: these produce a compile time error if the
4832  * expression is not known to be true at compile time. If the assertion is
4833  * known to be false, the compiler (or optimizer?) will error out with
4834  * "division by zero". If the assertion cannot be evaluated at compile time,
4835  * the compiler will error out with "non-static initializer".
4836  *
4837  * Adapted with permission from
4838  * http://www.pixelbeat.org/programming/gcc/static_assert.html
4839  */
4840 
4841 #define TCL_CT_ASSERT(e) \
4842     {enum { ct_assert_value = 1/(!!(e)) };}
4843 
4844 /*
4845  *----------------------------------------------------------------
4846  * Allocator for small structs (<=sizeof(Tcl_Obj)) using the Tcl_Obj pool.
4847  * Only checked at compile time.
4848  *
4849  * ONLY USE FOR CONSTANT nBytes.
4850  *
4851  * DO NOT LET THEM CROSS THREAD BOUNDARIES
4852  *----------------------------------------------------------------
4853  */
4854 
4855 #define TclSmallAlloc(nbytes, memPtr) \
4856     TclSmallAllocEx(NULL, (nbytes), (memPtr))
4857 
4858 #define TclSmallFree(memPtr) \
4859     TclSmallFreeEx(NULL, (memPtr))
4860 
4861 #ifndef TCL_MEM_DEBUG
4862 #define TclSmallAllocEx(interp, nbytes, memPtr) \
4863     do {								\
4864 	Tcl_Obj *_objPtr;						\
4865 	TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj));			\
4866 	TclIncrObjsAllocated();						\
4867 	TclAllocObjStorageEx((interp), (_objPtr));			\
4868 	memPtr = (ClientData) (_objPtr);					\
4869     } while (0)
4870 
4871 #define TclSmallFreeEx(interp, memPtr) \
4872     do {								\
4873 	TclFreeObjStorageEx((interp), (Tcl_Obj *) (memPtr));		\
4874 	TclIncrObjsFreed();						\
4875     } while (0)
4876 
4877 #else    /* TCL_MEM_DEBUG */
4878 #define TclSmallAllocEx(interp, nbytes, memPtr) \
4879     do {								\
4880 	Tcl_Obj *_objPtr;						\
4881 	TCL_CT_ASSERT((nbytes)<=sizeof(Tcl_Obj));			\
4882 	TclNewObj(_objPtr);						\
4883 	memPtr = (ClientData) _objPtr;					\
4884     } while (0)
4885 
4886 #define TclSmallFreeEx(interp, memPtr) \
4887     do {								\
4888 	Tcl_Obj *_objPtr = (Tcl_Obj *) memPtr;				\
4889 	_objPtr->bytes = NULL;						\
4890 	_objPtr->typePtr = NULL;					\
4891 	_objPtr->refCount = 1;						\
4892 	TclDecrRefCount(_objPtr);					\
4893     } while (0)
4894 #endif   /* TCL_MEM_DEBUG */
4895 
4896 /*
4897  * Support for Clang Static Analyzer <http://clang-analyzer.llvm.org>
4898  */
4899 
4900 #if defined(PURIFY) && defined(__clang__)
4901 #if __has_feature(attribute_analyzer_noreturn) && \
4902 	!defined(Tcl_Panic) && defined(Tcl_Panic_TCL_DECLARED)
4903 void Tcl_Panic(const char *, ...) __attribute__((analyzer_noreturn));
4904 #endif
4905 #if !defined(CLANG_ASSERT)
4906 #include <assert.h>
4907 #define CLANG_ASSERT(x) assert(x)
4908 #endif
4909 #elif !defined(CLANG_ASSERT)
4910 #define CLANG_ASSERT(x)
4911 #endif /* PURIFY && __clang__ */
4912 
4913 /*
4914  *----------------------------------------------------------------
4915  * Parameters, structs and macros for the non-recursive engine (NRE)
4916  *----------------------------------------------------------------
4917  */
4918 
4919 #define NRE_USE_SMALL_ALLOC	1  /* Only turn off for debugging purposes. */
4920 #ifndef NRE_ENABLE_ASSERTS
4921 #define NRE_ENABLE_ASSERTS	0
4922 #endif
4923 
4924 /*
4925  * This is the main data struct for representing NR commands. It is designed
4926  * to fit in sizeof(Tcl_Obj) in order to exploit the fastest memory allocator
4927  * available.
4928  */
4929 
4930 typedef struct NRE_callback {
4931     Tcl_NRPostProc *procPtr;
4932     ClientData data[4];
4933     struct NRE_callback *nextPtr;
4934 } NRE_callback;
4935 
4936 #define TOP_CB(iPtr) (((Interp *)(iPtr))->execEnvPtr->callbackPtr)
4937 
4938 /*
4939  * Inline version of Tcl_NRAddCallback.
4940  */
4941 
4942 #define TclNRAddCallback(interp,postProcPtr,data0,data1,data2,data3) \
4943     do {								\
4944 	NRE_callback *_callbackPtr;					\
4945 	TCLNR_ALLOC((interp), (_callbackPtr));				\
4946 	_callbackPtr->procPtr = (postProcPtr);				\
4947 	_callbackPtr->data[0] = (ClientData)(data0);			\
4948 	_callbackPtr->data[1] = (ClientData)(data1);			\
4949 	_callbackPtr->data[2] = (ClientData)(data2);			\
4950 	_callbackPtr->data[3] = (ClientData)(data3);			\
4951 	_callbackPtr->nextPtr = TOP_CB(interp);				\
4952 	TOP_CB(interp) = _callbackPtr;					\
4953     } while (0)
4954 
4955 #if NRE_USE_SMALL_ALLOC
4956 #define TCLNR_ALLOC(interp, ptr) \
4957     TclSmallAllocEx(interp, sizeof(NRE_callback), (ptr))
4958 #define TCLNR_FREE(interp, ptr)  TclSmallFreeEx((interp), (ptr))
4959 #else
4960 #define TCLNR_ALLOC(interp, ptr) \
4961     (ptr = ((ClientData) ckalloc(sizeof(NRE_callback))))
4962 #define TCLNR_FREE(interp, ptr)  ckfree((char *) (ptr))
4963 #endif
4964 
4965 #if NRE_ENABLE_ASSERTS
4966 #define NRE_ASSERT(expr) assert((expr))
4967 #else
4968 #define NRE_ASSERT(expr)
4969 #endif
4970 
4971 #include "tclIntDecls.h"
4972 #include "tclIntPlatDecls.h"
4973 #include "tclTomMathDecls.h"
4974 
4975 #if !defined(USE_TCL_STUBS) && !defined(TCL_MEM_DEBUG)
4976 #define Tcl_AttemptAlloc(size)        TclpAlloc(size)
4977 #define Tcl_AttemptRealloc(ptr, size) TclpRealloc((ptr), (size))
4978 #define Tcl_Free(ptr)                 TclpFree(ptr)
4979 #endif
4980 
4981 /*
4982  * Other externals.
4983  */
4984 
4985 MODULE_SCOPE size_t TclEnvEpoch; /* Epoch of the tcl environment
4986                                          * (if changed with tcl-env). */
4987 
4988 #endif /* _TCLINT */
4989 
4990 /*
4991  * Local Variables:
4992  * mode: c
4993  * c-basic-offset: 4
4994  * fill-column: 78
4995  * End:
4996  */
4997