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