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  *
12  * See the file "license.terms" for information on usage and redistribution
13  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14  *
15  * RCS: @(#) $Id: tclInt.h,v 1.118.2.3 2003/04/16 23:31:44 dgp Exp $
16  */
17 
18 #ifndef _TCLINT
19 #define _TCLINT
20 
21 /*
22  * Common include files needed by most of the Tcl source files are
23  * included here, so that system-dependent personalizations for the
24  * include files only have to be made in once place.  This results
25  * in a few extra includes, but greater modularity.  The order of
26  * the three groups of #includes is important.	For example, stdio.h
27  * is needed by tcl.h, and the _ANSI_ARGS_ declaration in tcl.h is
28  * needed by stdlib.h in some configurations.
29  */
30 
31 #ifndef _TCL
32 #include "tcl.h"
33 #endif
34 
35 #include <stdio.h>
36 
37 #include <ctype.h>
38 #ifdef NO_LIMITS_H
39 #   include "../compat/limits.h"
40 #else
41 #   include <limits.h>
42 #endif
43 #ifdef NO_STDLIB_H
44 #   include "../compat/stdlib.h"
45 #else
46 #   include <stdlib.h>
47 #endif
48 #ifdef NO_STRING_H
49 #include "../compat/string.h"
50 #else
51 #include <string.h>
52 #endif
53 
54 #undef TCL_STORAGE_CLASS
55 #ifdef BUILD_tcl
56 # define TCL_STORAGE_CLASS DLLEXPORT
57 #else
58 # ifdef USE_TCL_STUBS
59 #  define TCL_STORAGE_CLASS
60 # else
61 #  define TCL_STORAGE_CLASS DLLIMPORT
62 # endif
63 #endif
64 
65 /*
66  * The following procedures allow namespaces to be customized to
67  * support special name resolution rules for commands/variables.
68  *
69  */
70 
71 struct Tcl_ResolvedVarInfo;
72 
73 typedef Tcl_Var (Tcl_ResolveRuntimeVarProc) _ANSI_ARGS_((
74     Tcl_Interp* interp, struct Tcl_ResolvedVarInfo *vinfoPtr));
75 
76 typedef void (Tcl_ResolveVarDeleteProc) _ANSI_ARGS_((
77     struct Tcl_ResolvedVarInfo *vinfoPtr));
78 
79 /*
80  * The following structure encapsulates the routines needed to resolve a
81  * variable reference at runtime.  Any variable specific state will typically
82  * be appended to this structure.
83  */
84 
85 
86 typedef struct Tcl_ResolvedVarInfo {
87     Tcl_ResolveRuntimeVarProc *fetchProc;
88     Tcl_ResolveVarDeleteProc *deleteProc;
89 } Tcl_ResolvedVarInfo;
90 
91 
92 
93 typedef int (Tcl_ResolveCompiledVarProc) _ANSI_ARGS_((
94     Tcl_Interp* interp, CONST84 char* name, int length,
95     Tcl_Namespace *context, Tcl_ResolvedVarInfo **rPtr));
96 
97 typedef int (Tcl_ResolveVarProc) _ANSI_ARGS_((
98     Tcl_Interp* interp, CONST84 char* name, Tcl_Namespace *context,
99     int flags, Tcl_Var *rPtr));
100 
101 typedef int (Tcl_ResolveCmdProc) _ANSI_ARGS_((Tcl_Interp* interp,
102     CONST84 char* name, Tcl_Namespace *context, int flags,
103     Tcl_Command *rPtr));
104 
105 typedef struct Tcl_ResolverInfo {
106     Tcl_ResolveCmdProc *cmdResProc;	/* Procedure handling command name
107 					 * resolution. */
108     Tcl_ResolveVarProc *varResProc;	/* Procedure handling variable name
109 					 * resolution for variables that
110 					 * can only be handled at runtime. */
111     Tcl_ResolveCompiledVarProc *compiledVarResProc;
112 					/* Procedure handling variable name
113 					 * resolution at compile time. */
114 } Tcl_ResolverInfo;
115 
116 /*
117  *----------------------------------------------------------------
118  * Data structures related to namespaces.
119  *----------------------------------------------------------------
120  */
121 
122 /*
123  * The structure below defines a namespace.
124  * Note: the first five fields must match exactly the fields in a
125  * Tcl_Namespace structure (see tcl.h). If you change one, be sure to
126  * change the other.
127  */
128 
129 typedef struct Namespace {
130     char *name;			 /* The namespace's simple (unqualified)
131 				  * name. This contains no ::'s. The name of
132 				  * the global namespace is "" although "::"
133 				  * is an synonym. */
134     char *fullName;		 /* The namespace's fully qualified name.
135 				  * This starts with ::. */
136     ClientData clientData;	 /* An arbitrary value associated with this
137 				  * namespace. */
138     Tcl_NamespaceDeleteProc *deleteProc;
139 				 /* Procedure invoked when deleting the
140 				  * namespace to, e.g., free clientData. */
141     struct Namespace *parentPtr; /* Points to the namespace that contains
142 				  * this one. NULL if this is the global
143 				  * namespace. */
144     Tcl_HashTable childTable;	 /* Contains any child namespaces. Indexed
145 				  * by strings; values have type
146 				  * (Namespace *). */
147     long nsId;			 /* Unique id for the namespace. */
148     Tcl_Interp *interp;		 /* The interpreter containing this
149 				  * namespace. */
150     int flags;			 /* OR-ed combination of the namespace
151 				  * status flags NS_DYING and NS_DEAD
152 				  * listed below. */
153     int activationCount;	 /* Number of "activations" or active call
154 				  * frames for this namespace that are on
155 				  * the Tcl call stack. The namespace won't
156 				  * be freed until activationCount becomes
157 				  * zero. */
158     int refCount;		 /* Count of references by namespaceName *
159 				  * objects. The namespace can't be freed
160 				  * until refCount becomes zero. */
161     Tcl_HashTable cmdTable;	 /* Contains all the commands currently
162 				  * registered in the namespace. Indexed by
163 				  * strings; values have type (Command *).
164 				  * Commands imported by Tcl_Import have
165 				  * Command structures that point (via an
166 				  * ImportedCmdRef structure) to the
167 				  * Command structure in the source
168 				  * namespace's command table. */
169     Tcl_HashTable varTable;	 /* Contains all the (global) variables
170 				  * currently in this namespace. Indexed
171 				  * by strings; values have type (Var *). */
172     char **exportArrayPtr;	 /* Points to an array of string patterns
173 				  * specifying which commands are exported.
174 				  * A pattern may include "string match"
175 				  * style wildcard characters to specify
176 				  * multiple commands; however, no namespace
177 				  * qualifiers are allowed. NULL if no
178 				  * export patterns are registered. */
179     int numExportPatterns;	 /* Number of export patterns currently
180 				  * registered using "namespace export". */
181     int maxExportPatterns;	 /* Mumber of export patterns for which
182 				  * space is currently allocated. */
183     int cmdRefEpoch;		 /* Incremented if a newly added command
184 				  * shadows a command for which this
185 				  * namespace has already cached a Command *
186 				  * pointer; this causes all its cached
187 				  * Command* pointers to be invalidated. */
188     int resolverEpoch;		 /* Incremented whenever (a) the name resolution
189 				  * rules change for this namespace or (b) a
190 				  * newly added command shadows a command that
191 				  * is compiled to bytecodes.
192 				  * This invalidates all byte codes compiled
193 				  * in the namespace, causing the code to be
194 				  * recompiled under the new rules.*/
195     Tcl_ResolveCmdProc *cmdResProc;
196 				 /* If non-null, this procedure overrides
197 				  * the usual command resolution mechanism
198 				  * in Tcl.  This procedure is invoked
199 				  * within Tcl_FindCommand to resolve all
200 				  * command references within the namespace. */
201     Tcl_ResolveVarProc *varResProc;
202 				 /* If non-null, this procedure overrides
203 				  * the usual variable resolution mechanism
204 				  * in Tcl.  This procedure is invoked
205 				  * within Tcl_FindNamespaceVar to resolve all
206 				  * variable references within the namespace
207 				  * at runtime. */
208     Tcl_ResolveCompiledVarProc *compiledVarResProc;
209 				 /* If non-null, this procedure overrides
210 				  * the usual variable resolution mechanism
211 				  * in Tcl.  This procedure is invoked
212 				  * within LookupCompiledLocal to resolve
213 				  * variable references within the namespace
214 				  * at compile time. */
215 } Namespace;
216 
217 /*
218  * Flags used to represent the status of a namespace:
219  *
220  * NS_DYING -	1 means Tcl_DeleteNamespace has been called to delete the
221  *		namespace but there are still active call frames on the Tcl
222  *		stack that refer to the namespace. When the last call frame
223  *		referring to it has been popped, it's variables and command
224  *		will be destroyed and it will be marked "dead" (NS_DEAD).
225  *		The namespace can no longer be looked up by name.
226  * NS_DEAD -	1 means Tcl_DeleteNamespace has been called to delete the
227  *		namespace and no call frames still refer to it. Its
228  *		variables and command have already been destroyed. This bit
229  *		allows the namespace resolution code to recognize that the
230  *		namespace is "deleted". When the last namespaceName object
231  *		in any byte code code unit that refers to the namespace has
232  *		been freed (i.e., when the namespace's refCount is 0), the
233  *		namespace's storage will be freed.
234  */
235 
236 #define NS_DYING	0x01
237 #define NS_DEAD		0x02
238 
239 /*
240  * Flag passed to TclGetNamespaceForQualName to have it create all namespace
241  * components of a namespace-qualified name that cannot be found. The new
242  * namespaces are created within their specified parent. Note that this
243  * flag's value must not conflict with the values of the flags
244  * TCL_GLOBAL_ONLY, TCL_NAMESPACE_ONLY, and FIND_ONLY_NS (defined in
245  * tclNamesp.c).
246  */
247 
248 #define CREATE_NS_IF_UNKNOWN 0x800
249 
250 /*
251  *----------------------------------------------------------------
252  * Data structures related to variables.   These are used primarily
253  * in tclVar.c
254  *----------------------------------------------------------------
255  */
256 
257 /*
258  * The following structure defines a variable trace, which is used to
259  * invoke a specific C procedure whenever certain operations are performed
260  * on a variable.
261  */
262 
263 typedef struct VarTrace {
264     Tcl_VarTraceProc *traceProc;/* Procedure to call when operations given
265 				 * by flags are performed on variable. */
266     ClientData clientData;	/* Argument to pass to proc. */
267     int flags;			/* What events the trace procedure is
268 				 * interested in:  OR-ed combination of
269 				 * TCL_TRACE_READS, TCL_TRACE_WRITES,
270 				 * TCL_TRACE_UNSETS and TCL_TRACE_ARRAY. */
271     struct VarTrace *nextPtr;	/* Next in list of traces associated with
272 				 * a particular variable. */
273 } VarTrace;
274 
275 /*
276  * The following structure defines a command trace, which is used to
277  * invoke a specific C procedure whenever certain operations are performed
278  * on a command.
279  */
280 
281 typedef struct CommandTrace {
282     Tcl_CommandTraceProc *traceProc;/* Procedure to call when operations given
283 				     * by flags are performed on command. */
284     ClientData clientData;	    /* Argument to pass to proc. */
285     int flags;			    /* What events the trace procedure is
286 				     * interested in:  OR-ed combination of
287 				     * TCL_TRACE_RENAME, TCL_TRACE_DELETE. */
288     struct CommandTrace *nextPtr;   /* Next in list of traces associated with
289 				     * a particular command. */
290     int refCount;                   /* Used to ensure this structure is
291                                      * not deleted too early.  Keeps track
292                                      * of how many pieces of code have
293                                      * a pointer to this structure. */
294 } CommandTrace;
295 
296 /*
297  * When a command trace is active (i.e. its associated procedure is
298  * executing), one of the following structures is linked into a list
299  * associated with the command's interpreter.  The information in
300  * the structure is needed in order for Tcl to behave reasonably
301  * if traces are deleted while traces are active.
302  */
303 
304 typedef struct ActiveCommandTrace {
305     struct Command *cmdPtr;	/* Command that's being traced. */
306     struct ActiveCommandTrace *nextPtr;
307 				/* Next in list of all active command
308 				 * traces for the interpreter, or NULL
309 				 * if no more. */
310     CommandTrace *nextTracePtr;	/* Next trace to check after current
311 				 * trace procedure returns;  if this
312 				 * trace gets deleted, must update pointer
313 				 * to avoid using free'd memory. */
314 } ActiveCommandTrace;
315 
316 /*
317  * When a variable trace is active (i.e. its associated procedure is
318  * executing), one of the following structures is linked into a list
319  * associated with the variable's interpreter.	The information in
320  * the structure is needed in order for Tcl to behave reasonably
321  * if traces are deleted while traces are active.
322  */
323 
324 typedef struct ActiveVarTrace {
325     struct Var *varPtr;		/* Variable that's being traced. */
326     struct ActiveVarTrace *nextPtr;
327 				/* Next in list of all active variable
328 				 * traces for the interpreter, or NULL
329 				 * if no more. */
330     VarTrace *nextTracePtr;	/* Next trace to check after current
331 				 * trace procedure returns;  if this
332 				 * trace gets deleted, must update pointer
333 				 * to avoid using free'd memory. */
334 } ActiveVarTrace;
335 
336 /*
337  * The following structure describes an enumerative search in progress on
338  * an array variable;  this are invoked with options to the "array"
339  * command.
340  */
341 
342 typedef struct ArraySearch {
343     int id;			/* Integer id used to distinguish among
344 				 * multiple concurrent searches for the
345 				 * same array. */
346     struct Var *varPtr;		/* Pointer to array variable that's being
347 				 * searched. */
348     Tcl_HashSearch search;	/* Info kept by the hash module about
349 				 * progress through the array. */
350     Tcl_HashEntry *nextEntry;	/* Non-null means this is the next element
351 				 * to be enumerated (it's leftover from
352 				 * the Tcl_FirstHashEntry call or from
353 				 * an "array anymore" command).	 NULL
354 				 * means must call Tcl_NextHashEntry
355 				 * to get value to return. */
356     struct ArraySearch *nextPtr;/* Next in list of all active searches
357 				 * for this variable, or NULL if this is
358 				 * the last one. */
359 } ArraySearch;
360 
361 /*
362  * The structure below defines a variable, which associates a string name
363  * with a Tcl_Obj value. These structures are kept in procedure call frames
364  * (for local variables recognized by the compiler) or in the heap (for
365  * global variables and any variable not known to the compiler). For each
366  * Var structure in the heap, a hash table entry holds the variable name and
367  * a pointer to the Var structure.
368  */
369 
370 typedef struct Var {
371     union {
372 	Tcl_Obj *objPtr;	/* The variable's object value. Used for
373 				 * scalar variables and array elements. */
374 	Tcl_HashTable *tablePtr;/* For array variables, this points to
375 				 * information about the hash table used
376 				 * to implement the associative array.
377 				 * Points to malloc-ed data. */
378 	struct Var *linkPtr;	/* If this is a global variable being
379 				 * referred to in a procedure, or a variable
380 				 * created by "upvar", this field points to
381 				 * the referenced variable's Var struct. */
382     } value;
383     char *name;			/* NULL if the variable is in a hashtable,
384 				 * otherwise points to the variable's
385 				 * name. It is used, e.g., by TclLookupVar
386 				 * and "info locals". The storage for the
387 				 * characters of the name is not owned by
388 				 * the Var and must not be freed when
389 				 * freeing the Var. */
390     Namespace *nsPtr;		/* Points to the namespace that contains
391 				 * this variable or NULL if the variable is
392 				 * a local variable in a Tcl procedure. */
393     Tcl_HashEntry *hPtr;	/* If variable is in a hashtable, either the
394 				 * hash table entry that refers to this
395 				 * variable or NULL if the variable has been
396 				 * detached from its hash table (e.g. an
397 				 * array is deleted, but some of its
398 				 * elements are still referred to in
399 				 * upvars). NULL if the variable is not in a
400 				 * hashtable. This is used to delete an
401 				 * variable from its hashtable if it is no
402 				 * longer needed. */
403     int refCount;		/* Counts number of active uses of this
404 				 * variable, not including its entry in the
405 				 * call frame or the hash table: 1 for each
406 				 * additional variable whose linkPtr points
407 				 * here, 1 for each nested trace active on
408 				 * variable, and 1 if the variable is a
409 				 * namespace variable. This record can't be
410 				 * deleted until refCount becomes 0. */
411     VarTrace *tracePtr;		/* First in list of all traces set for this
412 				 * variable. */
413     ArraySearch *searchPtr;	/* First in list of all searches active
414 				 * for this variable, or NULL if none. */
415     int flags;			/* Miscellaneous bits of information about
416 				 * variable. See below for definitions. */
417 } Var;
418 
419 /*
420  * Flag bits for variables. The first three (VAR_SCALAR, VAR_ARRAY, and
421  * VAR_LINK) are mutually exclusive and give the "type" of the variable.
422  * VAR_UNDEFINED is independent of the variable's type.
423  *
424  * VAR_SCALAR -			1 means this is a scalar variable and not
425  *				an array or link. The "objPtr" field points
426  *				to the variable's value, a Tcl object.
427  * VAR_ARRAY -			1 means this is an array variable rather
428  *				than a scalar variable or link. The
429  *				"tablePtr" field points to the array's
430  *				hashtable for its elements.
431  * VAR_LINK -			1 means this Var structure contains a
432  *				pointer to another Var structure that
433  *				either has the real value or is itself
434  *				another VAR_LINK pointer. Variables like
435  *				this come about through "upvar" and "global"
436  *				commands, or through references to variables
437  *				in enclosing namespaces.
438  * VAR_UNDEFINED -		1 means that the variable is in the process
439  *				of being deleted. An undefined variable
440  *				logically does not exist and survives only
441  *				while it has a trace, or if it is a global
442  *				variable currently being used by some
443  *				procedure.
444  * VAR_IN_HASHTABLE -		1 means this variable is in a hashtable and
445  *				the Var structure is malloced. 0 if it is
446  *				a local variable that was assigned a slot
447  *				in a procedure frame by	the compiler so the
448  *				Var storage is part of the call frame.
449  * VAR_TRACE_ACTIVE -		1 means that trace processing is currently
450  *				underway for a read or write access, so
451  *				new read or write accesses should not cause
452  *				trace procedures to be called and the
453  *				variable can't be deleted.
454  * VAR_ARRAY_ELEMENT -		1 means that this variable is an array
455  *				element, so it is not legal for it to be
456  *				an array itself (the VAR_ARRAY flag had
457  *				better not be set).
458  * VAR_NAMESPACE_VAR -		1 means that this variable was declared
459  *				as a namespace variable. This flag ensures
460  *				it persists until its namespace is
461  *				destroyed or until the variable is unset;
462  *				it will persist even if it has not been
463  *				initialized and is marked undefined.
464  *				The variable's refCount is incremented to
465  *				reflect the "reference" from its namespace.
466  *
467  * The following additional flags are used with the CompiledLocal type
468  * defined below:
469  *
470  * VAR_ARGUMENT -		1 means that this variable holds a procedure
471  *				argument.
472  * VAR_TEMPORARY -		1 if the local variable is an anonymous
473  *				temporary variable. Temporaries have a NULL
474  *				name.
475  * VAR_RESOLVED -		1 if name resolution has been done for this
476  *				variable.
477  */
478 
479 #define VAR_SCALAR		0x1
480 #define VAR_ARRAY		0x2
481 #define VAR_LINK		0x4
482 #define VAR_UNDEFINED		0x8
483 #define VAR_IN_HASHTABLE	0x10
484 #define VAR_TRACE_ACTIVE	0x20
485 #define VAR_ARRAY_ELEMENT	0x40
486 #define VAR_NAMESPACE_VAR	0x80
487 
488 #define VAR_ARGUMENT		0x100
489 #define VAR_TEMPORARY		0x200
490 #define VAR_RESOLVED		0x400
491 
492 /*
493  * Macros to ensure that various flag bits are set properly for variables.
494  * The ANSI C "prototypes" for these macros are:
495  *
496  * EXTERN void	TclSetVarScalar _ANSI_ARGS_((Var *varPtr));
497  * EXTERN void	TclSetVarArray _ANSI_ARGS_((Var *varPtr));
498  * EXTERN void	TclSetVarLink _ANSI_ARGS_((Var *varPtr));
499  * EXTERN void	TclSetVarArrayElement _ANSI_ARGS_((Var *varPtr));
500  * EXTERN void	TclSetVarUndefined _ANSI_ARGS_((Var *varPtr));
501  * EXTERN void	TclClearVarUndefined _ANSI_ARGS_((Var *varPtr));
502  */
503 
504 #define TclSetVarScalar(varPtr) \
505     (varPtr)->flags = ((varPtr)->flags & ~(VAR_ARRAY|VAR_LINK)) | VAR_SCALAR
506 
507 #define TclSetVarArray(varPtr) \
508     (varPtr)->flags = ((varPtr)->flags & ~(VAR_SCALAR|VAR_LINK)) | VAR_ARRAY
509 
510 #define TclSetVarLink(varPtr) \
511     (varPtr)->flags = ((varPtr)->flags & ~(VAR_SCALAR|VAR_ARRAY)) | VAR_LINK
512 
513 #define TclSetVarArrayElement(varPtr) \
514     (varPtr)->flags = ((varPtr)->flags & ~VAR_ARRAY) | VAR_ARRAY_ELEMENT
515 
516 #define TclSetVarUndefined(varPtr) \
517     (varPtr)->flags |= VAR_UNDEFINED
518 
519 #define TclClearVarUndefined(varPtr) \
520     (varPtr)->flags &= ~VAR_UNDEFINED
521 
522 /*
523  * Macros to read various flag bits of variables.
524  * The ANSI C "prototypes" for these macros are:
525  *
526  * EXTERN int	TclIsVarScalar _ANSI_ARGS_((Var *varPtr));
527  * EXTERN int	TclIsVarLink _ANSI_ARGS_((Var *varPtr));
528  * EXTERN int	TclIsVarArray _ANSI_ARGS_((Var *varPtr));
529  * EXTERN int	TclIsVarUndefined _ANSI_ARGS_((Var *varPtr));
530  * EXTERN int	TclIsVarArrayElement _ANSI_ARGS_((Var *varPtr));
531  * EXTERN int	TclIsVarTemporary _ANSI_ARGS_((Var *varPtr));
532  * EXTERN int	TclIsVarArgument _ANSI_ARGS_((Var *varPtr));
533  * EXTERN int	TclIsVarResolved _ANSI_ARGS_((Var *varPtr));
534  */
535 
536 #define TclIsVarScalar(varPtr) \
537     ((varPtr)->flags & VAR_SCALAR)
538 
539 #define TclIsVarLink(varPtr) \
540     ((varPtr)->flags & VAR_LINK)
541 
542 #define TclIsVarArray(varPtr) \
543     ((varPtr)->flags & VAR_ARRAY)
544 
545 #define TclIsVarUndefined(varPtr) \
546     ((varPtr)->flags & VAR_UNDEFINED)
547 
548 #define TclIsVarArrayElement(varPtr) \
549     ((varPtr)->flags & VAR_ARRAY_ELEMENT)
550 
551 #define TclIsVarTemporary(varPtr) \
552     ((varPtr)->flags & VAR_TEMPORARY)
553 
554 #define TclIsVarArgument(varPtr) \
555     ((varPtr)->flags & VAR_ARGUMENT)
556 
557 #define TclIsVarResolved(varPtr) \
558     ((varPtr)->flags & VAR_RESOLVED)
559 
560 /*
561  *----------------------------------------------------------------
562  * Data structures related to procedures.  These are used primarily
563  * in tclProc.c, tclCompile.c, and tclExecute.c.
564  *----------------------------------------------------------------
565  */
566 
567 /*
568  * Forward declaration to prevent an error when the forward reference to
569  * Command is encountered in the Proc and ImportRef types declared below.
570  */
571 
572 struct Command;
573 
574 /*
575  * The variable-length structure below describes a local variable of a
576  * procedure that was recognized by the compiler. These variables have a
577  * name, an element in the array of compiler-assigned local variables in the
578  * procedure's call frame, and various other items of information. If the
579  * local variable is a formal argument, it may also have a default value.
580  * The compiler can't recognize local variables whose names are
581  * expressions (these names are only known at runtime when the expressions
582  * are evaluated) or local variables that are created as a result of an
583  * "upvar" or "uplevel" command. These other local variables are kept
584  * separately in a hash table in the call frame.
585  */
586 
587 typedef struct CompiledLocal {
588     struct CompiledLocal *nextPtr;
589 				/* Next compiler-recognized local variable
590 				 * for this procedure, or NULL if this is
591 				 * the last local. */
592     int nameLength;		/* The number of characters in local
593 				 * variable's name. Used to speed up
594 				 * variable lookups. */
595     int frameIndex;		/* Index in the array of compiler-assigned
596 				 * variables in the procedure call frame. */
597     int flags;			/* Flag bits for the local variable. Same as
598 				 * the flags for the Var structure above,
599 				 * although only VAR_SCALAR, VAR_ARRAY,
600 				 * VAR_LINK, VAR_ARGUMENT, VAR_TEMPORARY, and
601 				 * VAR_RESOLVED make sense. */
602     Tcl_Obj *defValuePtr;	/* Pointer to the default value of an
603 				 * argument, if any. NULL if not an argument
604 				 * or, if an argument, no default value. */
605     Tcl_ResolvedVarInfo *resolveInfo;
606 				/* Customized variable resolution info
607 				 * supplied by the Tcl_ResolveCompiledVarProc
608 				 * associated with a namespace. Each variable
609 				 * is marked by a unique ClientData tag
610 				 * during compilation, and that same tag
611 				 * is used to find the variable at runtime. */
612     char name[4];		/* Name of the local variable starts here.
613 				 * If the name is NULL, this will just be
614 				 * '\0'. The actual size of this field will
615 				 * be large enough to hold the name. MUST
616 				 * BE THE LAST FIELD IN THE STRUCTURE! */
617 } CompiledLocal;
618 
619 /*
620  * The structure below defines a command procedure, which consists of a
621  * collection of Tcl commands plus information about arguments and other
622  * local variables recognized at compile time.
623  */
624 
625 typedef struct Proc {
626     struct Interp *iPtr;	  /* Interpreter for which this command
627 				   * is defined. */
628     int refCount;		  /* Reference count: 1 if still present
629 				   * in command table plus 1 for each call
630 				   * to the procedure that is currently
631 				   * active. This structure can be freed
632 				   * when refCount becomes zero. */
633     struct Command *cmdPtr;	  /* Points to the Command structure for
634 				   * this procedure. This is used to get
635 				   * the namespace in which to execute
636 				   * the procedure. */
637     Tcl_Obj *bodyPtr;		  /* Points to the ByteCode object for
638 				   * procedure's body command. */
639     int numArgs;		  /* Number of formal parameters. */
640     int numCompiledLocals;	  /* Count of local variables recognized by
641 				   * the compiler including arguments and
642 				   * temporaries. */
643     CompiledLocal *firstLocalPtr; /* Pointer to first of the procedure's
644 				   * compiler-allocated local variables, or
645 				   * NULL if none. The first numArgs entries
646 				   * in this list describe the procedure's
647 				   * formal arguments. */
648     CompiledLocal *lastLocalPtr;  /* Pointer to the last allocated local
649 				   * variable or NULL if none. This has
650 				   * frame index (numCompiledLocals-1). */
651 } Proc;
652 
653 /*
654  * The structure below defines a command trace.	 This is used to allow Tcl
655  * clients to find out whenever a command is about to be executed.
656  */
657 
658 typedef struct Trace {
659     int level;			/* Only trace commands at nesting level
660 				 * less than or equal to this. */
661     Tcl_CmdObjTraceProc *proc;	/* Procedure to call to trace command. */
662     ClientData clientData;	/* Arbitrary value to pass to proc. */
663     struct Trace *nextPtr;	/* Next in list of traces for this interp. */
664     int flags;			/* Flags governing the trace - see
665 				 * Tcl_CreateObjTrace for details */
666     Tcl_CmdObjTraceDeleteProc* delProc;
667 				/* Procedure to call when trace is deleted */
668 } Trace;
669 
670 /*
671  * When an interpreter trace is active (i.e. its associated procedure
672  * is executing), one of the following structures is linked into a list
673  * associated with the interpreter.  The information in the structure
674  * is needed in order for Tcl to behave reasonably if traces are
675  * deleted while traces are active.
676  */
677 
678 typedef struct ActiveInterpTrace {
679     struct ActiveInterpTrace *nextPtr;
680 				/* Next in list of all active command
681 				 * traces for the interpreter, or NULL
682 				 * if no more. */
683     Trace *nextTracePtr;	/* Next trace to check after current
684 				 * trace procedure returns;  if this
685 				 * trace gets deleted, must update pointer
686 				 * to avoid using free'd memory. */
687 } ActiveInterpTrace;
688 
689 /*
690  * The structure below defines an entry in the assocData hash table which
691  * is associated with an interpreter. The entry contains a pointer to a
692  * function to call when the interpreter is deleted, and a pointer to
693  * a user-defined piece of data.
694  */
695 
696 typedef struct AssocData {
697     Tcl_InterpDeleteProc *proc;	/* Proc to call when deleting. */
698     ClientData clientData;	/* Value to pass to proc. */
699 } AssocData;
700 
701 /*
702  * The structure below defines a call frame. A call frame defines a naming
703  * context for a procedure call: its local naming scope (for local
704  * variables) and its global naming scope (a namespace, perhaps the global
705  * :: namespace). A call frame can also define the naming context for a
706  * namespace eval or namespace inscope command: the namespace in which the
707  * command's code should execute. The Tcl_CallFrame structures exist only
708  * while procedures or namespace eval/inscope's are being executed, and
709  * provide a kind of Tcl call stack.
710  *
711  * WARNING!! The structure definition must be kept consistent with the
712  * Tcl_CallFrame structure in tcl.h. If you change one, change the other.
713  */
714 
715 typedef struct CallFrame {
716     Namespace *nsPtr;		/* Points to the namespace used to resolve
717 				 * commands and global variables. */
718     int isProcCallFrame;	/* If nonzero, the frame was pushed to
719 				 * execute a Tcl procedure and may have
720 				 * local vars. If 0, the frame was pushed
721 				 * to execute a namespace command and var
722 				 * references are treated as references to
723 				 * namespace vars; varTablePtr and
724 				 * compiledLocals are ignored. */
725     int objc;			/* This and objv below describe the
726 				 * arguments for this procedure call. */
727     Tcl_Obj *CONST *objv;	/* Array of argument objects. */
728     struct CallFrame *callerPtr;
729 				/* Value of interp->framePtr when this
730 				 * procedure was invoked (i.e. next higher
731 				 * in stack of all active procedures). */
732     struct CallFrame *callerVarPtr;
733 				/* Value of interp->varFramePtr when this
734 				 * procedure was invoked (i.e. determines
735 				 * variable scoping within caller). Same
736 				 * as callerPtr unless an "uplevel" command
737 				 * or something equivalent was active in
738 				 * the caller). */
739     int level;			/* Level of this procedure, for "uplevel"
740 				 * purposes (i.e. corresponds to nesting of
741 				 * callerVarPtr's, not callerPtr's). 1 for
742 				 * outermost procedure, 0 for top-level. */
743     Proc *procPtr;		/* Points to the structure defining the
744 				 * called procedure. Used to get information
745 				 * such as the number of compiled local
746 				 * variables (local variables assigned
747 				 * entries ["slots"] in the compiledLocals
748 				 * array below). */
749     Tcl_HashTable *varTablePtr;	/* Hash table containing local variables not
750 				 * recognized by the compiler, or created at
751 				 * execution time through, e.g., upvar.
752 				 * Initially NULL and created if needed. */
753     int numCompiledLocals;	/* Count of local variables recognized by
754 				 * the compiler including arguments. */
755     Var* compiledLocals;	/* Points to the array of local variables
756 				 * recognized by the compiler. The compiler
757 				 * emits code that refers to these variables
758 				 * using an index into this array. */
759 } CallFrame;
760 
761 /*
762  *----------------------------------------------------------------
763  * Data structures and procedures related to TclHandles, which
764  * are a very lightweight method of preserving enough information
765  * to determine if an arbitrary malloc'd block has been deleted.
766  *----------------------------------------------------------------
767  */
768 
769 typedef VOID **TclHandle;
770 
771 /*
772  *----------------------------------------------------------------
773  * Data structures related to expressions.  These are used only in
774  * tclExpr.c.
775  *----------------------------------------------------------------
776  */
777 
778 /*
779  * The data structure below defines a math function (e.g. sin or hypot)
780  * for use in Tcl expressions.
781  */
782 
783 #define MAX_MATH_ARGS 5
784 typedef struct MathFunc {
785     int builtinFuncIndex;	/* If this is a builtin math function, its
786 				 * index in the array of builtin functions.
787 				 * (tclCompilation.h lists these indices.)
788 				 * The value is -1 if this is a new function
789 				 * defined by Tcl_CreateMathFunc. The value
790 				 * is also -1 if a builtin function is
791 				 * replaced by a Tcl_CreateMathFunc call. */
792     int numArgs;		/* Number of arguments for function. */
793     Tcl_ValueType argTypes[MAX_MATH_ARGS];
794 				/* Acceptable types for each argument. */
795     Tcl_MathProc *proc;		/* Procedure that implements this function.
796 				 * NULL if isBuiltinFunc is 1. */
797     ClientData clientData;	/* Additional argument to pass to the
798 				 * function when invoking it. NULL if
799 				 * isBuiltinFunc is 1. */
800 } MathFunc;
801 
802 /*
803  * These are a thin layer over TclpThreadKeyDataGet and TclpThreadKeyDataSet
804  * when threads are used, or an emulation if there are no threads.  These
805  * are really internal and Tcl clients should use Tcl_GetThreadData.
806  */
807 
808 EXTERN VOID *TclThreadDataKeyGet _ANSI_ARGS_((Tcl_ThreadDataKey *keyPtr));
809 EXTERN void TclThreadDataKeySet _ANSI_ARGS_((Tcl_ThreadDataKey *keyPtr, VOID *data));
810 
811 /*
812  * This is a convenience macro used to initialize a thread local storage ptr.
813  */
814 #define TCL_TSD_INIT(keyPtr)	(ThreadSpecificData *)Tcl_GetThreadData((keyPtr), sizeof(ThreadSpecificData))
815 
816 
817 /*
818  *----------------------------------------------------------------
819  * Data structures related to bytecode compilation and execution.
820  * These are used primarily in tclCompile.c, tclExecute.c, and
821  * tclBasic.c.
822  *----------------------------------------------------------------
823  */
824 
825 /*
826  * Forward declaration to prevent errors when the forward references to
827  * Tcl_Parse and CompileEnv are encountered in the procedure type
828  * CompileProc declared below.
829  */
830 
831 struct CompileEnv;
832 
833 /*
834  * The type of procedures called by the Tcl bytecode compiler to compile
835  * commands. Pointers to these procedures are kept in the Command structure
836  * describing each command. When a CompileProc returns, the interpreter's
837  * result is set to error information, if any. In addition, the CompileProc
838  * returns an integer value, which is one of the following:
839  *
840  * TCL_OK		Compilation completed normally.
841  * TCL_ERROR		Compilation failed because of an error;
842  *			the interpreter's result describes what went wrong.
843  * TCL_OUT_LINE_COMPILE	Compilation failed because, e.g., the command is
844  *			too complex for effective inline compilation. The
845  *			CompileProc believes the command is legal but
846  *			should be compiled "out of line" by emitting code
847  *			to invoke its command procedure at runtime.
848  */
849 
850 #define TCL_OUT_LINE_COMPILE	(TCL_CONTINUE + 1)
851 
852 typedef int (CompileProc) _ANSI_ARGS_((Tcl_Interp *interp,
853 	Tcl_Parse *parsePtr, struct CompileEnv *compEnvPtr));
854 
855 /*
856  * The type of procedure called from the compilation hook point in
857  * SetByteCodeFromAny.
858  */
859 
860 typedef int (CompileHookProc) _ANSI_ARGS_((Tcl_Interp *interp,
861 	struct CompileEnv *compEnvPtr, ClientData clientData));
862 
863 /*
864  * The data structure defining the execution environment for ByteCode's.
865  * There is one ExecEnv structure per Tcl interpreter. It holds the
866  * evaluation stack that holds command operands and results. The stack grows
867  * towards increasing addresses. The "stackTop" member is cached by
868  * TclExecuteByteCode in a local variable: it must be set before calling
869  * TclExecuteByteCode and will be restored by TclExecuteByteCode before it
870  * returns.
871  */
872 
873 typedef struct ExecEnv {
874     Tcl_Obj **stackPtr;		/* Points to the first item in the
875 				 * evaluation stack on the heap. */
876     int stackTop;		/* Index of current top of stack; -1 when
877 				 * the stack is empty. */
878     int stackEnd;		/* Index of last usable item in stack. */
879     Tcl_Obj *errorInfo;
880     Tcl_Obj *errorCode;
881 } ExecEnv;
882 
883 /*
884  * The definitions for the LiteralTable and LiteralEntry structures. Each
885  * interpreter contains a LiteralTable. It is used to reduce the storage
886  * needed for all the Tcl objects that hold the literals of scripts compiled
887  * by the interpreter. A literal's object is shared by all the ByteCodes
888  * that refer to the literal. Each distinct literal has one LiteralEntry
889  * entry in the LiteralTable. A literal table is a specialized hash table
890  * that is indexed by the literal's string representation, which may contain
891  * null characters.
892  *
893  * Note that we reduce the space needed for literals by sharing literal
894  * objects both within a ByteCode (each ByteCode contains a local
895  * LiteralTable) and across all an interpreter's ByteCodes (with the
896  * interpreter's global LiteralTable).
897  */
898 
899 typedef struct LiteralEntry {
900     struct LiteralEntry *nextPtr;	/* Points to next entry in this
901 					 * hash bucket or NULL if end of
902 					 * chain. */
903     Tcl_Obj *objPtr;			/* Points to Tcl object that
904 					 * holds the literal's bytes and
905 					 * length. */
906     int refCount;			/* If in an interpreter's global
907 					 * literal table, the number of
908 					 * ByteCode structures that share
909 					 * the literal object; the literal
910 					 * entry can be freed when refCount
911 					 * drops to 0. If in a local literal
912 					 * table, -1. */
913 } LiteralEntry;
914 
915 typedef struct LiteralTable {
916     LiteralEntry **buckets;		/* Pointer to bucket array. Each
917 					 * element points to first entry in
918 					 * bucket's hash chain, or NULL. */
919     LiteralEntry *staticBuckets[TCL_SMALL_HASH_TABLE];
920 					/* Bucket array used for small
921 					 * tables to avoid mallocs and
922 					 * frees. */
923     int numBuckets;			/* Total number of buckets allocated
924 					 * at **buckets. */
925     int numEntries;			/* Total number of entries present
926 					 * in table. */
927     int rebuildSize;			/* Enlarge table when numEntries
928 					 * gets to be this large. */
929     int mask;				/* Mask value used in hashing
930 					 * function. */
931 } LiteralTable;
932 
933 /*
934  * The following structure defines for each Tcl interpreter various
935  * statistics-related information about the bytecode compiler and
936  * interpreter's operation in that interpreter.
937  */
938 
939 #ifdef TCL_COMPILE_STATS
940 typedef struct ByteCodeStats {
941     long numExecutions;		  /* Number of ByteCodes executed. */
942     long numCompilations;	  /* Number of ByteCodes created. */
943     long numByteCodesFreed;	  /* Number of ByteCodes destroyed. */
944     long instructionCount[256];	  /* Number of times each instruction was
945 				   * executed. */
946 
947     double totalSrcBytes;	  /* Total source bytes ever compiled. */
948     double totalByteCodeBytes;	  /* Total bytes for all ByteCodes. */
949     double currentSrcBytes;	  /* Src bytes for all current ByteCodes. */
950     double currentByteCodeBytes;  /* Code bytes in all current ByteCodes. */
951 
952     long srcCount[32];		  /* Source size distribution: # of srcs of
953 				   * size [2**(n-1)..2**n), n in [0..32). */
954     long byteCodeCount[32];	  /* ByteCode size distribution. */
955     long lifetimeCount[32];	  /* ByteCode lifetime distribution (ms). */
956 
957     double currentInstBytes;	  /* Instruction bytes-current ByteCodes. */
958     double currentLitBytes;	  /* Current literal bytes. */
959     double currentExceptBytes;	  /* Current exception table bytes. */
960     double currentAuxBytes;	  /* Current auxiliary information bytes. */
961     double currentCmdMapBytes;	  /* Current src<->code map bytes. */
962 
963     long numLiteralsCreated;	  /* Total literal objects ever compiled. */
964     double totalLitStringBytes;	  /* Total string bytes in all literals. */
965     double currentLitStringBytes; /* String bytes in current literals. */
966     long literalCount[32];	  /* Distribution of literal string sizes. */
967 } ByteCodeStats;
968 #endif /* TCL_COMPILE_STATS */
969 
970 /*
971  *----------------------------------------------------------------
972  * Data structures related to commands.
973  *----------------------------------------------------------------
974  */
975 
976 /*
977  * An imported command is created in an namespace when it imports a "real"
978  * command from another namespace. An imported command has a Command
979  * structure that points (via its ClientData value) to the "real" Command
980  * structure in the source namespace's command table. The real command
981  * records all the imported commands that refer to it in a list of ImportRef
982  * structures so that they can be deleted when the real command is deleted.  */
983 
984 typedef struct ImportRef {
985     struct Command *importedCmdPtr;
986 				/* Points to the imported command created in
987 				 * an importing namespace; this command
988 				 * redirects its invocations to the "real"
989 				 * command. */
990     struct ImportRef *nextPtr;	/* Next element on the linked list of
991 				 * imported commands that refer to the
992 				 * "real" command. The real command deletes
993 				 * these imported commands on this list when
994 				 * it is deleted. */
995 } ImportRef;
996 
997 /*
998  * Data structure used as the ClientData of imported commands: commands
999  * created in an namespace when it imports a "real" command from another
1000  * namespace.
1001  */
1002 
1003 typedef struct ImportedCmdData {
1004     struct Command *realCmdPtr;	/* "Real" command that this imported command
1005 				 * refers to. */
1006     struct Command *selfPtr;	/* Pointer to this imported command. Needed
1007 				 * only when deleting it in order to remove
1008 				 * it from the real command's linked list of
1009 				 * imported commands that refer to it. */
1010 } ImportedCmdData;
1011 
1012 /*
1013  * A Command structure exists for each command in a namespace. The
1014  * Tcl_Command opaque type actually refers to these structures.
1015  */
1016 
1017 typedef struct Command {
1018     Tcl_HashEntry *hPtr;	/* Pointer to the hash table entry that
1019 				 * refers to this command. The hash table is
1020 				 * either a namespace's command table or an
1021 				 * interpreter's hidden command table. This
1022 				 * pointer is used to get a command's name
1023 				 * from its Tcl_Command handle. NULL means
1024 				 * that the hash table entry has been
1025 				 * removed already (this can happen if
1026 				 * deleteProc causes the command to be
1027 				 * deleted or recreated). */
1028     Namespace *nsPtr;		/* Points to the namespace containing this
1029 				 * command. */
1030     int refCount;		/* 1 if in command hashtable plus 1 for each
1031 				 * reference from a CmdName Tcl object
1032 				 * representing a command's name in a
1033 				 * ByteCode instruction sequence. This
1034 				 * structure can be freed when refCount
1035 				 * becomes zero. */
1036     int cmdEpoch;		/* Incremented to invalidate any references
1037 				 * that point to this command when it is
1038 				 * renamed, deleted, hidden, or exposed. */
1039     CompileProc *compileProc;	/* Procedure called to compile command. NULL
1040 				 * if no compile proc exists for command. */
1041     Tcl_ObjCmdProc *objProc;	/* Object-based command procedure. */
1042     ClientData objClientData;	/* Arbitrary value passed to object proc. */
1043     Tcl_CmdProc *proc;		/* String-based command procedure. */
1044     ClientData clientData;	/* Arbitrary value passed to string proc. */
1045     Tcl_CmdDeleteProc *deleteProc;
1046 				/* Procedure invoked when deleting command
1047 				 * to, e.g., free all client data. */
1048     ClientData deleteData;	/* Arbitrary value passed to deleteProc. */
1049     int flags;			/* Miscellaneous bits of information about
1050 				 * command. See below for definitions. */
1051     ImportRef *importRefPtr;	/* List of each imported Command created in
1052 				 * another namespace when this command is
1053 				 * imported. These imported commands
1054 				 * redirect invocations back to this
1055 				 * command. The list is used to remove all
1056 				 * those imported commands when deleting
1057 				 * this "real" command. */
1058     CommandTrace *tracePtr;	/* First in list of all traces set for this
1059 				 * command. */
1060 } Command;
1061 
1062 /*
1063  * Flag bits for commands.
1064  *
1065  * CMD_IS_DELETED -		Means that the command is in the process
1066  *                              of being deleted (its deleteProc is
1067  *                              currently executing). Other attempts to
1068  *                              delete the command should be ignored.
1069  * CMD_TRACE_ACTIVE -		1 means that trace processing is currently
1070  *				underway for a rename/delete change.
1071  *				See the two flags below for which is
1072  *				currently being processed.
1073  * CMD_HAS_EXEC_TRACES -	1 means that this command has at least
1074  *                              one execution trace (as opposed to simple
1075  *                              delete/rename traces) in its tracePtr list.
1076  * TCL_TRACE_RENAME -           A rename trace is in progress. Further
1077  *                              recursive renames will not be traced.
1078  * TCL_TRACE_DELETE -           A delete trace is in progress. Further
1079  *                              recursive deletes will not be traced.
1080  * (these last two flags are defined in tcl.h)
1081  */
1082 #define CMD_IS_DELETED		0x1
1083 #define CMD_TRACE_ACTIVE	0x2
1084 #define CMD_HAS_EXEC_TRACES	0x4
1085 
1086 /*
1087  *----------------------------------------------------------------
1088  * Data structures related to name resolution procedures.
1089  *----------------------------------------------------------------
1090  */
1091 
1092 /*
1093  * The interpreter keeps a linked list of name resolution schemes.
1094  * The scheme for a namespace is consulted first, followed by the
1095  * list of schemes in an interpreter, followed by the default
1096  * name resolution in Tcl.  Schemes are added/removed from the
1097  * interpreter's list by calling Tcl_AddInterpResolver and
1098  * Tcl_RemoveInterpResolver.
1099  */
1100 
1101 typedef struct ResolverScheme {
1102     char *name;			/* Name identifying this scheme. */
1103     Tcl_ResolveCmdProc *cmdResProc;
1104 				/* Procedure handling command name
1105 				 * resolution. */
1106     Tcl_ResolveVarProc *varResProc;
1107 				/* Procedure handling variable name
1108 				 * resolution for variables that
1109 				 * can only be handled at runtime. */
1110     Tcl_ResolveCompiledVarProc *compiledVarResProc;
1111 				/* Procedure handling variable name
1112 				 * resolution at compile time. */
1113 
1114     struct ResolverScheme *nextPtr;
1115 				/* Pointer to next record in linked list. */
1116 } ResolverScheme;
1117 
1118 /*
1119  *----------------------------------------------------------------
1120  * This structure defines an interpreter, which is a collection of
1121  * commands plus other state information related to interpreting
1122  * commands, such as variable storage. Primary responsibility for
1123  * this data structure is in tclBasic.c, but almost every Tcl
1124  * source file uses something in here.
1125  *----------------------------------------------------------------
1126  */
1127 
1128 typedef struct Interp {
1129 
1130     /*
1131      * Note:  the first three fields must match exactly the fields in
1132      * a Tcl_Interp struct (see tcl.h).	 If you change one, be sure to
1133      * change the other.
1134      *
1135      * The interpreter's result is held in both the string and the
1136      * objResultPtr fields. These fields hold, respectively, the result's
1137      * string or object value. The interpreter's result is always in the
1138      * result field if that is non-empty, otherwise it is in objResultPtr.
1139      * The two fields are kept consistent unless some C code sets
1140      * interp->result directly. Programs should not access result and
1141      * objResultPtr directly; instead, they should always get and set the
1142      * result using procedures such as Tcl_SetObjResult, Tcl_GetObjResult,
1143      * and Tcl_GetStringResult. See the SetResult man page for details.
1144      */
1145 
1146     char *result;		/* If the last command returned a string
1147 				 * result, this points to it. Should not be
1148 				 * accessed directly; see comment above. */
1149     Tcl_FreeProc *freeProc;	/* Zero means a string result is statically
1150 				 * allocated. TCL_DYNAMIC means string
1151 				 * result was allocated with ckalloc and
1152 				 * should be freed with ckfree. Other values
1153 				 * give address of procedure to invoke to
1154 				 * free the string result. Tcl_Eval must
1155 				 * free it before executing next command. */
1156     int errorLine;		/* When TCL_ERROR is returned, this gives
1157 				 * the line number in the command where the
1158 				 * error occurred (1 means first line). */
1159     struct TclStubs *stubTable;
1160 				/* Pointer to the exported Tcl stub table.
1161 				 * On previous versions of Tcl this is a
1162 				 * pointer to the objResultPtr or a pointer
1163 				 * to a buckets array in a hash table. We
1164 				 * therefore have to do some careful checking
1165 				 * before we can use this. */
1166 
1167     TclHandle handle;		/* Handle used to keep track of when this
1168 				 * interp is deleted. */
1169 
1170     Namespace *globalNsPtr;	/* The interpreter's global namespace. */
1171     Tcl_HashTable *hiddenCmdTablePtr;
1172 				/* Hash table used by tclBasic.c to keep
1173 				 * track of hidden commands on a per-interp
1174 				 * basis. */
1175     ClientData interpInfo;	/* Information used by tclInterp.c to keep
1176 				 * track of master/slave interps on
1177 				 * a per-interp basis. */
1178     Tcl_HashTable mathFuncTable;/* Contains all the math functions currently
1179 				 * defined for the interpreter.	 Indexed by
1180 				 * strings (function names); values have
1181 				 * type (MathFunc *). */
1182 
1183 
1184 
1185     /*
1186      * Information related to procedures and variables. See tclProc.c
1187      * and tclVar.c for usage.
1188      */
1189 
1190     int numLevels;		/* Keeps track of how many nested calls to
1191 				 * Tcl_Eval are in progress for this
1192 				 * interpreter.	 It's used to delay deletion
1193 				 * of the table until all Tcl_Eval
1194 				 * invocations are completed. */
1195     int maxNestingDepth;	/* If numLevels exceeds this value then Tcl
1196 				 * assumes that infinite recursion has
1197 				 * occurred and it generates an error. */
1198     CallFrame *framePtr;	/* Points to top-most in stack of all nested
1199 				 * procedure invocations.  NULL means there
1200 				 * are no active procedures. */
1201     CallFrame *varFramePtr;	/* Points to the call frame whose variables
1202 				 * are currently in use (same as framePtr
1203 				 * unless an "uplevel" command is
1204 				 * executing). NULL means no procedure is
1205 				 * active or "uplevel 0" is executing. */
1206     ActiveVarTrace *activeVarTracePtr;
1207 				/* First in list of active traces for
1208 				 * interp, or NULL if no active traces. */
1209     int returnCode;		/* Completion code to return if current
1210 				 * procedure exits with TCL_RETURN code. */
1211     char *errorInfo;		/* Value to store in errorInfo if returnCode
1212 				 * is TCL_ERROR.  Malloc'ed, may be NULL */
1213     char *errorCode;		/* Value to store in errorCode if returnCode
1214 				 * is TCL_ERROR.  Malloc'ed, may be NULL */
1215 
1216     /*
1217      * Information used by Tcl_AppendResult to keep track of partial
1218      * results.	 See Tcl_AppendResult code for details.
1219      */
1220 
1221     char *appendResult;		/* Storage space for results generated
1222 				 * by Tcl_AppendResult.	 Malloc-ed.  NULL
1223 				 * means not yet allocated. */
1224     int appendAvl;		/* Total amount of space available at
1225 				 * partialResult. */
1226     int appendUsed;		/* Number of non-null bytes currently
1227 				 * stored at partialResult. */
1228 
1229     /*
1230      * Information about packages.  Used only in tclPkg.c.
1231      */
1232 
1233     Tcl_HashTable packageTable;	/* Describes all of the packages loaded
1234 				 * in or available to this interpreter.
1235 				 * Keys are package names, values are
1236 				 * (Package *) pointers. */
1237     char *packageUnknown;	/* Command to invoke during "package
1238 				 * require" commands for packages that
1239 				 * aren't described in packageTable.
1240 				 * Malloc'ed, may be NULL. */
1241 
1242     /*
1243      * Miscellaneous information:
1244      */
1245 
1246     int cmdCount;		/* Total number of times a command procedure
1247 				 * has been called for this interpreter. */
1248     int evalFlags;		/* Flags to control next call to Tcl_Eval.
1249 				 * Normally zero, but may be set before
1250 				 * calling Tcl_Eval.  See below for valid
1251 				 * values. */
1252     int termOffset;		/* Offset of character just after last one
1253 				 * compiled or executed by Tcl_EvalObj. */
1254     LiteralTable literalTable;	/* Contains LiteralEntry's describing all
1255 				 * Tcl objects holding literals of scripts
1256 				 * compiled by the interpreter. Indexed by
1257 				 * the string representations of literals.
1258 				 * Used to avoid creating duplicate
1259 				 * objects. */
1260     int compileEpoch;		/* Holds the current "compilation epoch"
1261 				 * for this interpreter. This is
1262 				 * incremented to invalidate existing
1263 				 * ByteCodes when, e.g., a command with a
1264 				 * compile procedure is redefined. */
1265     Proc *compiledProcPtr;	/* If a procedure is being compiled, a
1266 				 * pointer to its Proc structure; otherwise,
1267 				 * this is NULL. Set by ObjInterpProc in
1268 				 * tclProc.c and used by tclCompile.c to
1269 				 * process local variables appropriately. */
1270     ResolverScheme *resolverPtr;
1271 				/* Linked list of name resolution schemes
1272 				 * added to this interpreter.  Schemes
1273 				 * are added/removed by calling
1274 				 * Tcl_AddInterpResolvers and
1275 				 * Tcl_RemoveInterpResolver. */
1276     Tcl_Obj *scriptFile;	/* NULL means there is no nested source
1277 				 * command active;  otherwise this points to
1278 				 * pathPtr of the file being sourced. */
1279     int flags;			/* Various flag bits.  See below. */
1280     long randSeed;		/* Seed used for rand() function. */
1281     Trace *tracePtr;		/* List of traces for this interpreter. */
1282     Tcl_HashTable *assocData;	/* Hash table for associating data with
1283 				 * this interpreter. Cleaned up when
1284 				 * this interpreter is deleted. */
1285     struct ExecEnv *execEnvPtr;	/* Execution environment for Tcl bytecode
1286 				 * execution. Contains a pointer to the
1287 				 * Tcl evaluation stack. */
1288     Tcl_Obj *emptyObjPtr;	/* Points to an object holding an empty
1289 				 * string. Returned by Tcl_ObjSetVar2 when
1290 				 * variable traces change a variable in a
1291 				 * gross way. */
1292     char resultSpace[TCL_RESULT_SIZE+1];
1293 				/* Static space holding small results. */
1294     Tcl_Obj *objResultPtr;	/* If the last command returned an object
1295 				 * result, this points to it. Should not be
1296 				 * accessed directly; see comment above. */
1297     Tcl_ThreadId threadId;	/* ID of thread that owns the interpreter */
1298 
1299     ActiveCommandTrace *activeCmdTracePtr;
1300 				/* First in list of active command traces for
1301 				 * interp, or NULL if no active traces. */
1302     ActiveInterpTrace *activeInterpTracePtr;
1303 				/* First in list of active traces for
1304 				 * interp, or NULL if no active traces. */
1305 
1306     int tracesForbiddingInline; /* Count of traces (in the list headed by
1307 				 * tracePtr) that forbid inline bytecode
1308 				 * compilation */
1309     /*
1310      * Statistical information about the bytecode compiler and interpreter's
1311      * operation.
1312      */
1313 
1314 #ifdef TCL_COMPILE_STATS
1315     ByteCodeStats stats;	/* Holds compilation and execution
1316 				 * statistics for this interpreter. */
1317 #endif /* TCL_COMPILE_STATS */
1318 } Interp;
1319 
1320 /*
1321  * EvalFlag bits for Interp structures:
1322  *
1323  * TCL_BRACKET_TERM	1 means that the current script is terminated by
1324  *			a close bracket rather than the end of the string.
1325  * TCL_ALLOW_EXCEPTIONS	1 means it's OK for the script to terminate with
1326  *			a code other than TCL_OK or TCL_ERROR;	0 means
1327  *			codes other than these should be turned into errors.
1328  */
1329 
1330 #define TCL_BRACKET_TERM	  1
1331 #define TCL_ALLOW_EXCEPTIONS	  4
1332 
1333 /*
1334  * Flag bits for Interp structures:
1335  *
1336  * DELETED:		Non-zero means the interpreter has been deleted:
1337  *			don't process any more commands for it, and destroy
1338  *			the structure as soon as all nested invocations of
1339  *			Tcl_Eval are done.
1340  * ERR_IN_PROGRESS:	Non-zero means an error unwind is already in
1341  *			progress. Zero means a command proc has been
1342  *			invoked since last error occured.
1343  * ERR_ALREADY_LOGGED:	Non-zero means information has already been logged
1344  *			in $errorInfo for the current Tcl_Eval instance,
1345  *			so Tcl_Eval needn't log it (used to implement the
1346  *			"error message log" command).
1347  * ERROR_CODE_SET:	Non-zero means that Tcl_SetErrorCode has been
1348  *			called to record information for the current
1349  *			error.	Zero means Tcl_Eval must clear the
1350  *			errorCode variable if an error is returned.
1351  * EXPR_INITIALIZED:	Non-zero means initialization specific to
1352  *			expressions has	been carried out.
1353  * DONT_COMPILE_CMDS_INLINE: Non-zero means that the bytecode compiler
1354  *			should not compile any commands into an inline
1355  *			sequence of instructions. This is set 1, for
1356  *			example, when command traces are requested.
1357  * RAND_SEED_INITIALIZED: Non-zero means that the randSeed value of the
1358  *			interp has not be initialized.	This is set 1
1359  *			when we first use the rand() or srand() functions.
1360  * SAFE_INTERP:		Non zero means that the current interp is a
1361  *			safe interp (ie it has only the safe commands
1362  *			installed, less priviledge than a regular interp).
1363  * USE_EVAL_DIRECT:	Non-zero means don't use the compiler or byte-code
1364  *			interpreter; instead, have Tcl_EvalObj call
1365  *			Tcl_EvalEx. Used primarily for testing the
1366  *			new parser.
1367  * INTERP_TRACE_IN_PROGRESS: Non-zero means that an interp trace is currently
1368  *			active; so no further trace callbacks should be
1369  *			invoked.
1370  */
1371 
1372 #define DELETED				    1
1373 #define ERR_IN_PROGRESS			    2
1374 #define ERR_ALREADY_LOGGED		    4
1375 #define ERROR_CODE_SET			    8
1376 #define EXPR_INITIALIZED		 0x10
1377 #define DONT_COMPILE_CMDS_INLINE	 0x20
1378 #define RAND_SEED_INITIALIZED		 0x40
1379 #define SAFE_INTERP			 0x80
1380 #define USE_EVAL_DIRECT			0x100
1381 #define INTERP_TRACE_IN_PROGRESS	0x200
1382 
1383 /*
1384  * Maximum number of levels of nesting permitted in Tcl commands (used
1385  * to catch infinite recursion).
1386  */
1387 
1388 #define MAX_NESTING_DEPTH	1000
1389 
1390 /*
1391  * The macro below is used to modify a "char" value (e.g. by casting
1392  * it to an unsigned character) so that it can be used safely with
1393  * macros such as isspace.
1394  */
1395 
1396 #define UCHAR(c) ((unsigned char) (c))
1397 
1398 /*
1399  * This macro is used to determine the offset needed to safely allocate any
1400  * data structure in memory. Given a starting offset or size, it "rounds up"
1401  * or "aligns" the offset to the next 8-byte boundary so that any data
1402  * structure can be placed at the resulting offset without fear of an
1403  * alignment error.
1404  *
1405  * WARNING!! DO NOT USE THIS MACRO TO ALIGN POINTERS: it will produce
1406  * the wrong result on platforms that allocate addresses that are divisible
1407  * by 4 or 2. Only use it for offsets or sizes.
1408  */
1409 
1410 #define TCL_ALIGN(x) (((int)(x) + 7) & ~7)
1411 
1412 /*
1413  * The following enum values are used to specify the runtime platform
1414  * setting of the tclPlatform variable.
1415  */
1416 
1417 typedef enum {
1418     TCL_PLATFORM_UNIX,		/* Any Unix-like OS. */
1419     TCL_PLATFORM_MAC,		/* MacOS. */
1420     TCL_PLATFORM_WINDOWS	/* Any Microsoft Windows OS. */
1421 } TclPlatformType;
1422 
1423 /*
1424  *  The following enum values are used to indicate the translation
1425  *  of a Tcl channel.  Declared here so that each platform can define
1426  *  TCL_PLATFORM_TRANSLATION to the native translation on that platform
1427  */
1428 
1429 typedef enum TclEolTranslation {
1430     TCL_TRANSLATE_AUTO,                 /* Eol == \r, \n and \r\n. */
1431     TCL_TRANSLATE_CR,                   /* Eol == \r. */
1432     TCL_TRANSLATE_LF,                   /* Eol == \n. */
1433     TCL_TRANSLATE_CRLF                  /* Eol == \r\n. */
1434 } TclEolTranslation;
1435 
1436 /*
1437  * Flags for TclInvoke:
1438  *
1439  * TCL_INVOKE_HIDDEN		Invoke a hidden command; if not set,
1440  *				invokes an exposed command.
1441  * TCL_INVOKE_NO_UNKNOWN	If set, "unknown" is not invoked if
1442  *				the command to be invoked is not found.
1443  *				Only has an effect if invoking an exposed
1444  *				command, i.e. if TCL_INVOKE_HIDDEN is not
1445  *				also set.
1446  * TCL_INVOKE_NO_TRACEBACK	Does not record traceback information if
1447  *				the invoked command returns an error.  Used
1448  *				if the caller plans on recording its own
1449  *				traceback information.
1450  */
1451 
1452 #define	TCL_INVOKE_HIDDEN	(1<<0)
1453 #define TCL_INVOKE_NO_UNKNOWN	(1<<1)
1454 #define TCL_INVOKE_NO_TRACEBACK	(1<<2)
1455 
1456 /*
1457  * The structure used as the internal representation of Tcl list
1458  * objects. This is an array of pointers to the element objects. This array
1459  * is grown (reallocated and copied) as necessary to hold all the list's
1460  * element pointers. The array might contain more slots than currently used
1461  * to hold all element pointers. This is done to make append operations
1462  * faster.
1463  */
1464 
1465 typedef struct List {
1466     int maxElemCount;		/* Total number of element array slots. */
1467     int elemCount;		/* Current number of list elements. */
1468     Tcl_Obj **elements;		/* Array of pointers to element objects. */
1469 } List;
1470 
1471 
1472 /*
1473  * The following types are used for getting and storing platform-specific
1474  * file attributes in tclFCmd.c and the various platform-versions of
1475  * that file. This is done to have as much common code as possible
1476  * in the file attributes code. For more information about the callbacks,
1477  * see TclFileAttrsCmd in tclFCmd.c.
1478  */
1479 
1480 typedef int (TclGetFileAttrProc) _ANSI_ARGS_((Tcl_Interp *interp,
1481 	int objIndex, Tcl_Obj *fileName, Tcl_Obj **attrObjPtrPtr));
1482 typedef int (TclSetFileAttrProc) _ANSI_ARGS_((Tcl_Interp *interp,
1483 	int objIndex, Tcl_Obj *fileName, Tcl_Obj *attrObjPtr));
1484 
1485 typedef struct TclFileAttrProcs {
1486     TclGetFileAttrProc *getProc;	/* The procedure for getting attrs. */
1487     TclSetFileAttrProc *setProc;	/* The procedure for setting attrs. */
1488 } TclFileAttrProcs;
1489 
1490 /*
1491  * Opaque handle used in pipeline routines to encapsulate platform-dependent
1492  * state.
1493  */
1494 
1495 typedef struct TclFile_ *TclFile;
1496 
1497 /*
1498  * Opaque names for platform specific types.
1499  */
1500 
1501 typedef struct TclpTime_t_    *TclpTime_t;
1502 
1503 /*
1504  * The "globParameters" argument of the function TclGlob is an
1505  * or'ed combination of the following values:
1506  */
1507 
1508 #define TCL_GLOBMODE_NO_COMPLAIN      1
1509 #define TCL_GLOBMODE_JOIN             2
1510 #define TCL_GLOBMODE_DIR              4
1511 #define TCL_GLOBMODE_TAILS            8
1512 
1513 /*
1514  *----------------------------------------------------------------
1515  * Data structures related to obsolete filesystem hooks
1516  *----------------------------------------------------------------
1517  */
1518 
1519 typedef int (TclStatProc_) _ANSI_ARGS_((CONST char *path, struct stat *buf));
1520 typedef int (TclAccessProc_) _ANSI_ARGS_((CONST char *path, int mode));
1521 typedef Tcl_Channel (TclOpenFileChannelProc_) _ANSI_ARGS_((Tcl_Interp *interp,
1522 	CONST char *fileName, CONST char *modeString,
1523 	int permissions));
1524 
1525 
1526 /*
1527  *----------------------------------------------------------------
1528  * Data structures related to procedures
1529  *----------------------------------------------------------------
1530  */
1531 
1532 typedef Tcl_CmdProc *TclCmdProcType;
1533 typedef Tcl_ObjCmdProc *TclObjCmdProcType;
1534 
1535 /*
1536  *----------------------------------------------------------------
1537  * Variables shared among Tcl modules but not used by the outside world.
1538  *----------------------------------------------------------------
1539  */
1540 
1541 extern Tcl_Time			tclBlockTime;
1542 extern int			tclBlockTimeSet;
1543 extern char *			tclExecutableName;
1544 extern char *			tclNativeExecutableName;
1545 extern char *			tclDefaultEncodingDir;
1546 extern Tcl_ChannelType		tclFileChannelType;
1547 extern char *			tclMemDumpFileName;
1548 extern TclPlatformType		tclPlatform;
1549 extern Tcl_NotifierProcs	tclOriginalNotifier;
1550 
1551 /*
1552  * Variables denoting the Tcl object types defined in the core.
1553  */
1554 
1555 extern Tcl_ObjType	tclBooleanType;
1556 extern Tcl_ObjType	tclByteArrayType;
1557 extern Tcl_ObjType	tclByteCodeType;
1558 extern Tcl_ObjType	tclDoubleType;
1559 extern Tcl_ObjType	tclEndOffsetType;
1560 extern Tcl_ObjType	tclIntType;
1561 extern Tcl_ObjType	tclListType;
1562 extern Tcl_ObjType	tclProcBodyType;
1563 extern Tcl_ObjType	tclStringType;
1564 extern Tcl_ObjType	tclArraySearchType;
1565 extern Tcl_ObjType	tclIndexType;
1566 extern Tcl_ObjType	tclNsNameType;
1567 extern Tcl_ObjType	tclWideIntType;
1568 
1569 /*
1570  * Variables denoting the hash key types defined in the core.
1571  */
1572 
1573 extern Tcl_HashKeyType tclArrayHashKeyType;
1574 extern Tcl_HashKeyType tclOneWordHashKeyType;
1575 extern Tcl_HashKeyType tclStringHashKeyType;
1576 extern Tcl_HashKeyType tclObjHashKeyType;
1577 
1578 /*
1579  * The head of the list of free Tcl objects, and the total number of Tcl
1580  * objects ever allocated and freed.
1581  */
1582 
1583 extern Tcl_Obj *	tclFreeObjList;
1584 
1585 #ifdef TCL_COMPILE_STATS
1586 extern long		tclObjsAlloced;
1587 extern long		tclObjsFreed;
1588 #define TCL_MAX_SHARED_OBJ_STATS 5
1589 extern long		tclObjsShared[TCL_MAX_SHARED_OBJ_STATS];
1590 #endif /* TCL_COMPILE_STATS */
1591 
1592 /*
1593  * Pointer to a heap-allocated string of length zero that the Tcl core uses
1594  * as the value of an empty string representation for an object. This value
1595  * is shared by all new objects allocated by Tcl_NewObj.
1596  */
1597 
1598 extern char *		tclEmptyStringRep;
1599 extern char		tclEmptyString;
1600 
1601 /*
1602  *----------------------------------------------------------------
1603  * Procedures shared among Tcl modules but not used by the outside
1604  * world:
1605  *----------------------------------------------------------------
1606  */
1607 
1608 EXTERN int		TclArraySet _ANSI_ARGS_((Tcl_Interp *interp,
1609 			    Tcl_Obj *arrayNameObj, Tcl_Obj *arrayElemObj));
1610 EXTERN int		TclCheckBadOctal _ANSI_ARGS_((Tcl_Interp *interp,
1611 			    CONST char *value));
1612 EXTERN void		TclExpandTokenArray _ANSI_ARGS_((
1613 			    Tcl_Parse *parsePtr));
1614 EXTERN int		TclFileAttrsCmd _ANSI_ARGS_((Tcl_Interp *interp,
1615 			    int objc, Tcl_Obj *CONST objv[]));
1616 EXTERN int		TclFileCopyCmd _ANSI_ARGS_((Tcl_Interp *interp,
1617 			    int objc, Tcl_Obj *CONST objv[])) ;
1618 EXTERN int		TclFileDeleteCmd _ANSI_ARGS_((Tcl_Interp *interp,
1619 			    int objc, Tcl_Obj *CONST objv[]));
1620 EXTERN int		TclFileMakeDirsCmd _ANSI_ARGS_((Tcl_Interp *interp,
1621 			    int objc, Tcl_Obj *CONST objv[])) ;
1622 EXTERN int		TclFileRenameCmd _ANSI_ARGS_((Tcl_Interp *interp,
1623 			    int objc, Tcl_Obj *CONST objv[])) ;
1624 EXTERN void		TclFinalizeAllocSubsystem _ANSI_ARGS_((void));
1625 EXTERN void		TclFinalizeCompExecEnv _ANSI_ARGS_((void));
1626 EXTERN void		TclFinalizeCompilation _ANSI_ARGS_((void));
1627 EXTERN void		TclFinalizeEncodingSubsystem _ANSI_ARGS_((void));
1628 EXTERN void		TclFinalizeEnvironment _ANSI_ARGS_((void));
1629 EXTERN void		TclFinalizeExecution _ANSI_ARGS_((void));
1630 EXTERN void		TclFinalizeIOSubsystem _ANSI_ARGS_((void));
1631 EXTERN void		TclFinalizeFilesystem _ANSI_ARGS_((void));
1632 EXTERN void		TclResetFilesystem _ANSI_ARGS_((void));
1633 EXTERN void		TclFinalizeLoad _ANSI_ARGS_((void));
1634 EXTERN void		TclFinalizeMemorySubsystem _ANSI_ARGS_((void));
1635 EXTERN void		TclFinalizeNotifier _ANSI_ARGS_((void));
1636 EXTERN void		TclFinalizeAsync _ANSI_ARGS_((void));
1637 EXTERN void		TclFinalizeSynchronization _ANSI_ARGS_((void));
1638 EXTERN void		TclFinalizeThreadData _ANSI_ARGS_((void));
1639 EXTERN void		TclFindEncodings _ANSI_ARGS_((CONST char *argv0));
1640 EXTERN int		TclGlob _ANSI_ARGS_((Tcl_Interp *interp,
1641 			    char *pattern, Tcl_Obj *unquotedPrefix,
1642 			    int globFlags, Tcl_GlobTypeData* types));
1643 EXTERN void		TclInitAlloc _ANSI_ARGS_((void));
1644 EXTERN void		TclInitDbCkalloc _ANSI_ARGS_((void));
1645 EXTERN void		TclInitEncodingSubsystem _ANSI_ARGS_((void));
1646 EXTERN void		TclInitIOSubsystem _ANSI_ARGS_((void));
1647 EXTERN void		TclInitNamespaceSubsystem _ANSI_ARGS_((void));
1648 EXTERN void		TclInitNotifier _ANSI_ARGS_((void));
1649 EXTERN void		TclInitObjSubsystem _ANSI_ARGS_((void));
1650 EXTERN void		TclInitSubsystems _ANSI_ARGS_((CONST char *argv0));
1651 EXTERN int		TclIsLocalScalar _ANSI_ARGS_((CONST char *src,
1652 			    int len));
1653 EXTERN int              TclJoinThread _ANSI_ARGS_((Tcl_ThreadId id,
1654 			    int* result));
1655 EXTERN Tcl_Obj *	TclLindexList _ANSI_ARGS_((Tcl_Interp* interp,
1656 						   Tcl_Obj* listPtr,
1657 						   Tcl_Obj* argPtr ));
1658 EXTERN Tcl_Obj *	TclLindexFlat _ANSI_ARGS_((Tcl_Interp* interp,
1659 						   Tcl_Obj* listPtr,
1660 						   int indexCount,
1661 						   Tcl_Obj *CONST indexArray[]
1662 						   ));
1663 EXTERN Tcl_Obj *	TclLsetList _ANSI_ARGS_((Tcl_Interp* interp,
1664 						 Tcl_Obj* listPtr,
1665 						 Tcl_Obj* indexPtr,
1666 						 Tcl_Obj* valuePtr
1667 						 ));
1668 EXTERN Tcl_Obj *	TclLsetFlat _ANSI_ARGS_((Tcl_Interp* interp,
1669 						 Tcl_Obj* listPtr,
1670 						 int indexCount,
1671 						 Tcl_Obj *CONST indexArray[],
1672 						 Tcl_Obj* valuePtr
1673 						 ));
1674 EXTERN int              TclParseBackslash _ANSI_ARGS_((CONST char *src,
1675                             int numBytes, int *readPtr, char *dst));
1676 EXTERN int		TclParseHex _ANSI_ARGS_((CONST char *src, int numBytes,
1677                             Tcl_UniChar *resultPtr));
1678 EXTERN int		TclParseInteger _ANSI_ARGS_((CONST char *string,
1679 			    int numBytes));
1680 EXTERN int		TclParseWhiteSpace _ANSI_ARGS_((CONST char *src,
1681 			    int numBytes, Tcl_Parse *parsePtr, char *typePtr));
1682 EXTERN int		TclpObjAccess _ANSI_ARGS_((Tcl_Obj *filename,
1683 			    int mode));
1684 EXTERN int              TclpObjLstat _ANSI_ARGS_((Tcl_Obj *pathPtr,
1685 			    Tcl_StatBuf *buf));
1686 EXTERN int		TclpCheckStackSpace _ANSI_ARGS_((void));
1687 EXTERN Tcl_Obj*         TclpTempFileName _ANSI_ARGS_((void));
1688 EXTERN Tcl_Obj*         TclNewFSPathObj _ANSI_ARGS_((Tcl_Obj *dirPtr,
1689 			    CONST char *addStrRep, int len));
1690 EXTERN int              TclpDeleteFile _ANSI_ARGS_((CONST char *path));
1691 EXTERN void		TclpFinalizeCondition _ANSI_ARGS_((
1692 			    Tcl_Condition *condPtr));
1693 EXTERN void		TclpFinalizeMutex _ANSI_ARGS_((Tcl_Mutex *mutexPtr));
1694 EXTERN void		TclpFinalizeThreadData _ANSI_ARGS_((
1695 			    Tcl_ThreadDataKey *keyPtr));
1696 EXTERN void		TclpFinalizeThreadDataKey _ANSI_ARGS_((
1697 			    Tcl_ThreadDataKey *keyPtr));
1698 EXTERN char *		TclpFindExecutable _ANSI_ARGS_((
1699 			    CONST char *argv0));
1700 EXTERN int		TclpFindVariable _ANSI_ARGS_((CONST char *name,
1701 			    int *lengthPtr));
1702 EXTERN void		TclpInitLibraryPath _ANSI_ARGS_((CONST char *argv0));
1703 EXTERN void		TclpInitLock _ANSI_ARGS_((void));
1704 EXTERN void		TclpInitPlatform _ANSI_ARGS_((void));
1705 EXTERN void		TclpInitUnlock _ANSI_ARGS_((void));
1706 EXTERN int              TclpLoadFile _ANSI_ARGS_((Tcl_Interp *interp,
1707 				Tcl_Obj *pathPtr,
1708 				CONST char *sym1, CONST char *sym2,
1709 				Tcl_PackageInitProc **proc1Ptr,
1710 				Tcl_PackageInitProc **proc2Ptr,
1711 				ClientData *clientDataPtr,
1712 				Tcl_FSUnloadFileProc **unloadProcPtr));
1713 EXTERN Tcl_Obj*		TclpObjListVolumes _ANSI_ARGS_((void));
1714 EXTERN void		TclpMasterLock _ANSI_ARGS_((void));
1715 EXTERN void		TclpMasterUnlock _ANSI_ARGS_((void));
1716 EXTERN int		TclpMatchFiles _ANSI_ARGS_((Tcl_Interp *interp,
1717 			    char *separators, Tcl_DString *dirPtr,
1718 			    char *pattern, char *tail));
1719 EXTERN int              TclpObjNormalizePath _ANSI_ARGS_((Tcl_Interp *interp,
1720 			    Tcl_Obj *pathPtr, int nextCheckpoint));
1721 EXTERN int		TclpObjCreateDirectory _ANSI_ARGS_((Tcl_Obj *pathPtr));
1722 EXTERN void             TclpNativeJoinPath _ANSI_ARGS_((Tcl_Obj *prefix,
1723 							char *joining));
1724 EXTERN Tcl_Obj*         TclpNativeSplitPath _ANSI_ARGS_((Tcl_Obj *pathPtr,
1725 							 int *lenPtr));
1726 EXTERN Tcl_PathType     TclpGetNativePathType _ANSI_ARGS_((Tcl_Obj *pathObjPtr,
1727 			    int *driveNameLengthPtr, Tcl_Obj **driveNameRef));
1728 EXTERN int 		TclCrossFilesystemCopy _ANSI_ARGS_((Tcl_Interp *interp,
1729 			    Tcl_Obj *source, Tcl_Obj *target));
1730 EXTERN int		TclpObjDeleteFile _ANSI_ARGS_((Tcl_Obj *pathPtr));
1731 EXTERN int		TclpObjCopyDirectory _ANSI_ARGS_((Tcl_Obj *srcPathPtr,
1732 				Tcl_Obj *destPathPtr, Tcl_Obj **errorPtr));
1733 EXTERN int		TclpObjCopyFile _ANSI_ARGS_((Tcl_Obj *srcPathPtr,
1734 				Tcl_Obj *destPathPtr));
1735 EXTERN int		TclpObjRemoveDirectory _ANSI_ARGS_((Tcl_Obj *pathPtr,
1736 				int recursive, Tcl_Obj **errorPtr));
1737 EXTERN int		TclpObjRenameFile _ANSI_ARGS_((Tcl_Obj *srcPathPtr,
1738 				Tcl_Obj *destPathPtr));
1739 EXTERN int		TclpMatchInDirectory _ANSI_ARGS_((Tcl_Interp *interp,
1740 			        Tcl_Obj *resultPtr, Tcl_Obj *pathPtr,
1741 				CONST char *pattern, Tcl_GlobTypeData *types));
1742 EXTERN Tcl_Obj*		TclpObjGetCwd _ANSI_ARGS_((Tcl_Interp *interp));
1743 EXTERN Tcl_Obj*		TclpObjLink _ANSI_ARGS_((Tcl_Obj *pathPtr,
1744 				Tcl_Obj *toPtr, int linkType));
1745 EXTERN int		TclpObjChdir _ANSI_ARGS_((Tcl_Obj *pathPtr));
1746 EXTERN Tcl_Obj*         TclFileDirname _ANSI_ARGS_((Tcl_Interp *interp,
1747 						    Tcl_Obj*pathPtr));
1748 EXTERN int		TclpObjStat _ANSI_ARGS_((Tcl_Obj *pathPtr, Tcl_StatBuf *buf));
1749 EXTERN Tcl_Channel	TclpOpenFileChannel _ANSI_ARGS_((Tcl_Interp *interp,
1750 			    Tcl_Obj *pathPtr, int mode,
1751 			    int permissions));
1752 EXTERN void		TclpCutFileChannel _ANSI_ARGS_((Tcl_Channel chan));
1753 EXTERN void		TclpSpliceFileChannel _ANSI_ARGS_((Tcl_Channel chan));
1754 EXTERN void		TclpPanic _ANSI_ARGS_(TCL_VARARGS(CONST char *,
1755 			    format));
1756 EXTERN char *		TclpReadlink _ANSI_ARGS_((CONST char *fileName,
1757 			    Tcl_DString *linkPtr));
1758 EXTERN void		TclpReleaseFile _ANSI_ARGS_((TclFile file));
1759 EXTERN void		TclpSetVariables _ANSI_ARGS_((Tcl_Interp *interp));
1760 EXTERN void		TclpUnloadFile _ANSI_ARGS_((Tcl_LoadHandle loadHandle));
1761 EXTERN VOID *		TclpThreadDataKeyGet _ANSI_ARGS_((
1762 			    Tcl_ThreadDataKey *keyPtr));
1763 EXTERN void		TclpThreadDataKeyInit _ANSI_ARGS_((
1764 			    Tcl_ThreadDataKey *keyPtr));
1765 EXTERN void		TclpThreadDataKeySet _ANSI_ARGS_((
1766 			    Tcl_ThreadDataKey *keyPtr, VOID *data));
1767 EXTERN void		TclpThreadExit _ANSI_ARGS_((int status));
1768 EXTERN void		TclRememberCondition _ANSI_ARGS_((Tcl_Condition *mutex));
1769 EXTERN void		TclRememberDataKey _ANSI_ARGS_((Tcl_ThreadDataKey *mutex));
1770 EXTERN VOID             TclRememberJoinableThread _ANSI_ARGS_((Tcl_ThreadId id));
1771 EXTERN void		TclRememberMutex _ANSI_ARGS_((Tcl_Mutex *mutex));
1772 EXTERN VOID             TclSignalExitThread _ANSI_ARGS_((Tcl_ThreadId id,
1773 			     int result));
1774 EXTERN void		TclTransferResult _ANSI_ARGS_((Tcl_Interp *sourceInterp,
1775 			    int result, Tcl_Interp *targetInterp));
1776 EXTERN Tcl_Obj*         TclpNativeToNormalized
1777                             _ANSI_ARGS_((ClientData clientData));
1778 EXTERN Tcl_Obj*	        TclpFilesystemPathType
1779 					_ANSI_ARGS_((Tcl_Obj* pathObjPtr));
1780 EXTERN Tcl_PackageInitProc* TclpFindSymbol _ANSI_ARGS_((Tcl_Interp *interp,
1781 			    Tcl_LoadHandle loadHandle, CONST char *symbol));
1782 EXTERN int              TclpDlopen _ANSI_ARGS_((Tcl_Interp *interp,
1783 			    Tcl_Obj *pathPtr,
1784 	                    Tcl_LoadHandle *loadHandle,
1785 		            Tcl_FSUnloadFileProc **unloadProcPtr));
1786 EXTERN int              TclpUtime _ANSI_ARGS_((Tcl_Obj *pathPtr,
1787 					       struct utimbuf *tval));
1788 
1789 /*
1790  *----------------------------------------------------------------
1791  * Command procedures in the generic core:
1792  *----------------------------------------------------------------
1793  */
1794 
1795 EXTERN int	Tcl_AfterObjCmd _ANSI_ARGS_((ClientData clientData,
1796 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1797 EXTERN int	Tcl_AppendObjCmd _ANSI_ARGS_((ClientData clientData,
1798 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1799 EXTERN int	Tcl_ArrayObjCmd _ANSI_ARGS_((ClientData clientData,
1800 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1801 EXTERN int	Tcl_BinaryObjCmd _ANSI_ARGS_((ClientData clientData,
1802 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1803 EXTERN int	Tcl_BreakObjCmd _ANSI_ARGS_((ClientData clientData,
1804 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1805 EXTERN int	Tcl_CaseObjCmd _ANSI_ARGS_((ClientData clientData,
1806 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1807 EXTERN int	Tcl_CatchObjCmd _ANSI_ARGS_((ClientData clientData,
1808 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1809 EXTERN int	Tcl_CdObjCmd _ANSI_ARGS_((ClientData clientData,
1810 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1811 EXTERN int	Tcl_ClockObjCmd _ANSI_ARGS_((ClientData clientData,
1812 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1813 EXTERN int	Tcl_CloseObjCmd _ANSI_ARGS_((ClientData clientData,
1814 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1815 EXTERN int	Tcl_ConcatObjCmd _ANSI_ARGS_((ClientData clientData,
1816 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1817 EXTERN int	Tcl_ContinueObjCmd _ANSI_ARGS_((ClientData clientData,
1818 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1819 EXTERN int	Tcl_EncodingObjCmd _ANSI_ARGS_((ClientData clientData,
1820 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1821 EXTERN int	Tcl_EofObjCmd _ANSI_ARGS_((ClientData clientData,
1822 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1823 EXTERN int	Tcl_ErrorObjCmd _ANSI_ARGS_((ClientData clientData,
1824 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1825 EXTERN int	Tcl_EvalObjCmd _ANSI_ARGS_((ClientData clientData,
1826 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1827 EXTERN int	Tcl_ExecObjCmd _ANSI_ARGS_((ClientData clientData,
1828 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1829 EXTERN int	Tcl_ExitObjCmd _ANSI_ARGS_((ClientData clientData,
1830 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1831 EXTERN int	Tcl_ExprObjCmd _ANSI_ARGS_((ClientData clientData,
1832 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1833 EXTERN int	Tcl_FblockedObjCmd _ANSI_ARGS_((ClientData clientData,
1834 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1835 EXTERN int	Tcl_FconfigureObjCmd _ANSI_ARGS_((ClientData clientData,
1836 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1837 EXTERN int	Tcl_FcopyObjCmd _ANSI_ARGS_((ClientData dummy,
1838 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1839 EXTERN int	Tcl_FileObjCmd _ANSI_ARGS_((ClientData dummy,
1840 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1841 EXTERN int	Tcl_FileEventObjCmd _ANSI_ARGS_((ClientData clientData,
1842 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1843 EXTERN int	Tcl_FlushObjCmd _ANSI_ARGS_((ClientData clientData,
1844 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1845 EXTERN int	Tcl_ForObjCmd _ANSI_ARGS_((ClientData clientData,
1846 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1847 EXTERN int	Tcl_ForeachObjCmd _ANSI_ARGS_((ClientData clientData,
1848 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1849 EXTERN int	Tcl_FormatObjCmd _ANSI_ARGS_((ClientData dummy,
1850 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1851 EXTERN int	Tcl_GetsObjCmd _ANSI_ARGS_((ClientData clientData,
1852 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1853 EXTERN int	Tcl_GlobalObjCmd _ANSI_ARGS_((ClientData clientData,
1854 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1855 EXTERN int	Tcl_GlobObjCmd _ANSI_ARGS_((ClientData clientData,
1856 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1857 EXTERN int	Tcl_IfObjCmd _ANSI_ARGS_((ClientData clientData,
1858 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1859 EXTERN int	Tcl_IncrObjCmd _ANSI_ARGS_((ClientData clientData,
1860 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1861 EXTERN int	Tcl_InfoObjCmd _ANSI_ARGS_((ClientData clientData,
1862 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1863 EXTERN int	Tcl_InterpObjCmd _ANSI_ARGS_((ClientData clientData,
1864 		    Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[]));
1865 EXTERN int	Tcl_JoinObjCmd _ANSI_ARGS_((ClientData clientData,
1866 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1867 EXTERN int	Tcl_LappendObjCmd _ANSI_ARGS_((ClientData clientData,
1868 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1869 EXTERN int	Tcl_LindexObjCmd _ANSI_ARGS_((ClientData clientData,
1870 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1871 EXTERN int	Tcl_LinsertObjCmd _ANSI_ARGS_((ClientData clientData,
1872 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1873 EXTERN int	Tcl_LlengthObjCmd _ANSI_ARGS_((ClientData clientData,
1874 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1875 EXTERN int	Tcl_ListObjCmd _ANSI_ARGS_((ClientData clientData,
1876 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1877 EXTERN int	Tcl_LoadObjCmd _ANSI_ARGS_((ClientData clientData,
1878 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1879 EXTERN int	Tcl_LrangeObjCmd _ANSI_ARGS_((ClientData clientData,
1880 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1881 EXTERN int	Tcl_LreplaceObjCmd _ANSI_ARGS_((ClientData clientData,
1882 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1883 EXTERN int	Tcl_LsearchObjCmd _ANSI_ARGS_((ClientData clientData,
1884 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1885 EXTERN int	Tcl_LsetObjCmd _ANSI_ARGS_((ClientData clientData,
1886                     Tcl_Interp* interp, int objc, Tcl_Obj *CONST objv[]));
1887 EXTERN int	Tcl_LsortObjCmd _ANSI_ARGS_((ClientData clientData,
1888 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1889 EXTERN int	Tcl_NamespaceObjCmd _ANSI_ARGS_((ClientData clientData,
1890 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1891 EXTERN int	Tcl_OpenObjCmd _ANSI_ARGS_((ClientData clientData,
1892 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1893 EXTERN int	Tcl_PackageObjCmd _ANSI_ARGS_((ClientData clientData,
1894 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1895 EXTERN int	Tcl_PidObjCmd _ANSI_ARGS_((ClientData clientData,
1896 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1897 EXTERN int	Tcl_PutsObjCmd _ANSI_ARGS_((ClientData clientData,
1898 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1899 EXTERN int	Tcl_PwdObjCmd _ANSI_ARGS_((ClientData clientData,
1900 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1901 EXTERN int	Tcl_ReadObjCmd _ANSI_ARGS_((ClientData clientData,
1902 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1903 EXTERN int	Tcl_RegexpObjCmd _ANSI_ARGS_((ClientData clientData,
1904 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1905 EXTERN int	Tcl_RegsubObjCmd _ANSI_ARGS_((ClientData clientData,
1906 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1907 EXTERN int	Tcl_RenameObjCmd _ANSI_ARGS_((ClientData clientData,
1908 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1909 EXTERN int	Tcl_ReturnObjCmd _ANSI_ARGS_((ClientData clientData,
1910 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1911 EXTERN int	Tcl_ScanObjCmd _ANSI_ARGS_((ClientData clientData,
1912 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1913 EXTERN int	Tcl_SeekObjCmd _ANSI_ARGS_((ClientData clientData,
1914 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1915 EXTERN int	Tcl_SetObjCmd _ANSI_ARGS_((ClientData clientData,
1916 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1917 EXTERN int	Tcl_SplitObjCmd _ANSI_ARGS_((ClientData clientData,
1918 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1919 EXTERN int	Tcl_SocketObjCmd _ANSI_ARGS_((ClientData clientData,
1920 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1921 EXTERN int	Tcl_SourceObjCmd _ANSI_ARGS_((ClientData clientData,
1922 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1923 EXTERN int	Tcl_StringObjCmd _ANSI_ARGS_((ClientData clientData,
1924 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1925 EXTERN int	Tcl_SubstObjCmd _ANSI_ARGS_((ClientData clientData,
1926 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1927 EXTERN int	Tcl_SwitchObjCmd _ANSI_ARGS_((ClientData clientData,
1928 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1929 EXTERN int	Tcl_TellObjCmd _ANSI_ARGS_((ClientData clientData,
1930 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1931 EXTERN int	Tcl_TimeObjCmd _ANSI_ARGS_((ClientData clientData,
1932 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1933 EXTERN int	Tcl_TraceObjCmd _ANSI_ARGS_((ClientData clientData,
1934 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1935 EXTERN int	Tcl_UnsetObjCmd _ANSI_ARGS_((ClientData clientData,
1936 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1937 EXTERN int	Tcl_UpdateObjCmd _ANSI_ARGS_((ClientData clientData,
1938 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1939 EXTERN int	Tcl_UplevelObjCmd _ANSI_ARGS_((ClientData clientData,
1940 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1941 EXTERN int	Tcl_UpvarObjCmd _ANSI_ARGS_((ClientData clientData,
1942 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1943 EXTERN int	Tcl_VariableObjCmd _ANSI_ARGS_((ClientData clientData,
1944 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1945 EXTERN int	Tcl_VwaitObjCmd _ANSI_ARGS_((ClientData clientData,
1946 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1947 EXTERN int	Tcl_WhileObjCmd _ANSI_ARGS_((ClientData clientData,
1948 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1949 
1950 /*
1951  *----------------------------------------------------------------
1952  * Command procedures found only in the Mac version of the core:
1953  *----------------------------------------------------------------
1954  */
1955 
1956 #ifdef MAC_TCL
1957 EXTERN int	Tcl_EchoCmd _ANSI_ARGS_((ClientData clientData,
1958 		    Tcl_Interp *interp, int argc, CONST84 char **argv));
1959 EXTERN int	Tcl_LsObjCmd _ANSI_ARGS_((ClientData clientData,
1960 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1961 EXTERN int	Tcl_BeepObjCmd _ANSI_ARGS_((ClientData clientData,
1962 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1963 EXTERN int	Tcl_MacSourceObjCmd _ANSI_ARGS_((ClientData clientData,
1964 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1965 EXTERN int	Tcl_ResourceObjCmd _ANSI_ARGS_((ClientData clientData,
1966 		    Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
1967 #endif
1968 
1969 /*
1970  *----------------------------------------------------------------
1971  * Compilation procedures for commands in the generic core:
1972  *----------------------------------------------------------------
1973  */
1974 
1975 EXTERN int	TclCompileAppendCmd _ANSI_ARGS_((Tcl_Interp *interp,
1976 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1977 EXTERN int	TclCompileBreakCmd _ANSI_ARGS_((Tcl_Interp *interp,
1978 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1979 EXTERN int	TclCompileCatchCmd _ANSI_ARGS_((Tcl_Interp *interp,
1980 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1981 EXTERN int	TclCompileContinueCmd _ANSI_ARGS_((Tcl_Interp *interp,
1982 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1983 EXTERN int	TclCompileExprCmd _ANSI_ARGS_((Tcl_Interp *interp,
1984 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1985 EXTERN int	TclCompileForCmd _ANSI_ARGS_((Tcl_Interp *interp,
1986 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1987 EXTERN int	TclCompileForeachCmd _ANSI_ARGS_((Tcl_Interp *interp,
1988 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1989 EXTERN int	TclCompileIfCmd _ANSI_ARGS_((Tcl_Interp *interp,
1990 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1991 EXTERN int	TclCompileIncrCmd _ANSI_ARGS_((Tcl_Interp *interp,
1992 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1993 EXTERN int	TclCompileLappendCmd _ANSI_ARGS_((Tcl_Interp *interp,
1994 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1995 EXTERN int	TclCompileLindexCmd _ANSI_ARGS_((Tcl_Interp *interp,
1996 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1997 EXTERN int	TclCompileListCmd _ANSI_ARGS_((Tcl_Interp *interp,
1998 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
1999 EXTERN int	TclCompileLlengthCmd _ANSI_ARGS_((Tcl_Interp *interp,
2000 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
2001 EXTERN int	TclCompileLsetCmd _ANSI_ARGS_((Tcl_Interp* interp,
2002 		    Tcl_Parse* parsePtr, struct CompileEnv* envPtr));
2003 EXTERN int	TclCompileRegexpCmd _ANSI_ARGS_((Tcl_Interp* interp,
2004 		    Tcl_Parse* parsePtr, struct CompileEnv* envPtr));
2005 EXTERN int	TclCompileReturnCmd _ANSI_ARGS_((Tcl_Interp *interp,
2006 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
2007 EXTERN int	TclCompileSetCmd _ANSI_ARGS_((Tcl_Interp *interp,
2008 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
2009 EXTERN int	TclCompileStringCmd _ANSI_ARGS_((Tcl_Interp *interp,
2010 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
2011 EXTERN int	TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp,
2012 		    Tcl_Parse *parsePtr, struct CompileEnv *envPtr));
2013 
2014 /*
2015  * Functions defined in generic/tclVar.c and currenttly exported only
2016  * for use by the bytecode compiler and engine. Some of these could later
2017  * be placed in the public interface.
2018  */
2019 
2020 EXTERN Var *	TclLookupArrayElement _ANSI_ARGS_((Tcl_Interp *interp,
2021 		    CONST char *arrayName, CONST char *elName, CONST int flags,
2022 		    CONST char *msg, CONST int createPart1,
2023 		    CONST int createPart2, Var *arrayPtr));
2024 EXTERN Var *    TclObjLookupVar _ANSI_ARGS_((Tcl_Interp *interp,
2025 		    Tcl_Obj *part1Ptr, CONST char *part2, int flags,
2026 		    CONST char *msg, CONST int createPart1,
2027 		    CONST int createPart2, Var **arrayPtrPtr));
2028 EXTERN Tcl_Obj *TclPtrGetVar _ANSI_ARGS_((Tcl_Interp *interp, Var *varPtr,
2029 		    Var *arrayPtr, CONST char *part1, CONST char *part2,
2030 		    CONST int flags));
2031 EXTERN Tcl_Obj *TclPtrSetVar _ANSI_ARGS_((Tcl_Interp *interp, Var *varPtr,
2032 		    Var *arrayPtr, CONST char *part1, CONST char *part2,
2033 		    Tcl_Obj *newValuePtr, CONST int flags));
2034 EXTERN Tcl_Obj *TclPtrIncrVar _ANSI_ARGS_((Tcl_Interp *interp, Var *varPtr,
2035 		    Var *arrayPtr, CONST char *part1, CONST char *part2,
2036 		    CONST long i, CONST int flags));
2037 
2038 /*
2039  *----------------------------------------------------------------
2040  * Macros used by the Tcl core to create and release Tcl objects.
2041  * TclNewObj(objPtr) creates a new object denoting an empty string.
2042  * TclDecrRefCount(objPtr) decrements the object's reference count,
2043  * and frees the object if its reference count is zero.
2044  * These macros are inline versions of Tcl_NewObj() and
2045  * Tcl_DecrRefCount(). Notice that the names differ in not having
2046  * a "_" after the "Tcl". Notice also that these macros reference
2047  * their argument more than once, so you should avoid calling them
2048  * with an expression that is expensive to compute or has
2049  * side effects. The ANSI C "prototypes" for these macros are:
2050  *
2051  * EXTERN void	TclNewObj _ANSI_ARGS_((Tcl_Obj *objPtr));
2052  * EXTERN void	TclDecrRefCount _ANSI_ARGS_((Tcl_Obj *objPtr));
2053  *
2054  * These macros are defined in terms of two macros that depend on
2055  * memory allocator in use: TclAllocObjStorage, TclFreeObjStorage.
2056  * They are defined below.
2057  *----------------------------------------------------------------
2058  */
2059 
2060 #ifdef TCL_COMPILE_STATS
2061 #  define TclIncrObjsAllocated() \
2062     tclObjsAlloced++
2063 #  define TclIncrObjsFreed() \
2064     tclObjsFreed++
2065 #else
2066 #  define TclIncrObjsAllocated()
2067 #  define TclIncrObjsFreed()
2068 #endif /* TCL_COMPILE_STATS */
2069 
2070 #define TclNewObj(objPtr) \
2071     TclAllocObjStorage(objPtr); \
2072     TclIncrObjsAllocated(); \
2073     (objPtr)->refCount = 0; \
2074     (objPtr)->bytes    = tclEmptyStringRep; \
2075     (objPtr)->length   = 0; \
2076     (objPtr)->typePtr  = NULL
2077 
2078 #define TclDecrRefCount(objPtr) \
2079     if (--(objPtr)->refCount <= 0) { \
2080 	if (((objPtr)->typePtr != NULL) \
2081 		&& ((objPtr)->typePtr->freeIntRepProc != NULL)) { \
2082 	    (objPtr)->typePtr->freeIntRepProc(objPtr); \
2083 	} \
2084 	if (((objPtr)->bytes != NULL) \
2085 		&& ((objPtr)->bytes != tclEmptyStringRep)) { \
2086 	    ckfree((char *) (objPtr)->bytes); \
2087 	} \
2088         TclFreeObjStorage(objPtr); \
2089 	TclIncrObjsFreed(); \
2090     }
2091 
2092 #ifdef TCL_MEM_DEBUG
2093 #  define TclAllocObjStorage(objPtr) \
2094        (objPtr) = (Tcl_Obj *) \
2095            Tcl_DbCkalloc(sizeof(Tcl_Obj), __FILE__, __LINE__)
2096 
2097 #  define TclFreeObjStorage(objPtr) \
2098        if ((objPtr)->refCount < -1) { \
2099            panic("Reference count for %lx was negative: %s line %d", \
2100 	           (objPtr), __FILE__, __LINE__); \
2101        } \
2102        ckfree((char *) (objPtr))
2103 
2104 #  define TclDbNewObj(objPtr, file, line) \
2105        (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \
2106        (objPtr)->refCount = 0; \
2107        (objPtr)->bytes    = tclEmptyStringRep; \
2108        (objPtr)->length   = 0; \
2109        (objPtr)->typePtr  = NULL; \
2110        TclIncrObjsAllocated()
2111 
2112 #elif defined(PURIFY)
2113 
2114 /*
2115  * The PURIFY mode is like the regular mode, but instead of doing block
2116  * Tcl_Obj allocation and keeping a freed list for efficiency, it always
2117  * allocates and frees a single Tcl_Obj so that tools like Purify can
2118  * better track memory leaks
2119  */
2120 
2121 #  define TclAllocObjStorage(objPtr) \
2122        (objPtr) = (Tcl_Obj *) Tcl_Ckalloc(sizeof(Tcl_Obj))
2123 
2124 #  define TclFreeObjStorage(objPtr) \
2125        ckfree((char *) (objPtr))
2126 
2127 #elif defined(TCL_THREADS) && defined(USE_THREAD_ALLOC)
2128 
2129 /*
2130  * The TCL_THREADS mode is like the regular mode but allocates Tcl_Obj's
2131  * from per-thread caches.
2132  */
2133 
2134 EXTERN Tcl_Obj *TclThreadAllocObj _ANSI_ARGS_((void));
2135 EXTERN void TclThreadFreeObj _ANSI_ARGS_((Tcl_Obj *));
2136 
2137 #  define TclAllocObjStorage(objPtr) \
2138        (objPtr) = TclThreadAllocObj()
2139 
2140 #  define TclFreeObjStorage(objPtr) \
2141        TclThreadFreeObj((objPtr))
2142 
2143 #else /* not TCL_MEM_DEBUG */
2144 
2145 #ifdef TCL_THREADS
2146 /* declared in tclObj.c */
2147 extern Tcl_Mutex tclObjMutex;
2148 #endif
2149 
2150 #  define TclAllocObjStorage(objPtr) \
2151        Tcl_MutexLock(&tclObjMutex); \
2152        if (tclFreeObjList == NULL) { \
2153 	   TclAllocateFreeObjects(); \
2154        } \
2155        (objPtr) = tclFreeObjList; \
2156        tclFreeObjList = (Tcl_Obj *) \
2157 	   tclFreeObjList->internalRep.otherValuePtr; \
2158        Tcl_MutexUnlock(&tclObjMutex)
2159 
2160 #  define TclFreeObjStorage(objPtr) \
2161        Tcl_MutexLock(&tclObjMutex); \
2162        (objPtr)->internalRep.otherValuePtr = (VOID *) tclFreeObjList; \
2163        tclFreeObjList = (objPtr); \
2164        Tcl_MutexUnlock(&tclObjMutex)
2165 
2166 #endif /* TCL_MEM_DEBUG */
2167 
2168 /*
2169  *----------------------------------------------------------------
2170  * Macro used by the Tcl core to set a Tcl_Obj's string representation
2171  * to a copy of the "len" bytes starting at "bytePtr". This code
2172  * works even if the byte array contains NULLs as long as the length
2173  * is correct. Because "len" is referenced multiple times, it should
2174  * be as simple an expression as possible. The ANSI C "prototype" for
2175  * this macro is:
2176  *
2177  * EXTERN void	TclInitStringRep _ANSI_ARGS_((Tcl_Obj *objPtr,
2178  *		    char *bytePtr, int len));
2179  *----------------------------------------------------------------
2180  */
2181 
2182 #define TclInitStringRep(objPtr, bytePtr, len) \
2183     if ((len) == 0) { \
2184 	(objPtr)->bytes	 = tclEmptyStringRep; \
2185 	(objPtr)->length = 0; \
2186     } else { \
2187 	(objPtr)->bytes = (char *) ckalloc((unsigned) ((len) + 1)); \
2188 	memcpy((VOID *) (objPtr)->bytes, (VOID *) (bytePtr), \
2189 		(unsigned) (len)); \
2190 	(objPtr)->bytes[len] = '\0'; \
2191 	(objPtr)->length = (len); \
2192     }
2193 
2194 /*
2195  *----------------------------------------------------------------
2196  * Macro used by the Tcl core to get the string representation's
2197  * byte array pointer from a Tcl_Obj. This is an inline version
2198  * of Tcl_GetString(). The macro's expression result is the string
2199  * rep's byte pointer which might be NULL. The bytes referenced by
2200  * this pointer must not be modified by the caller.
2201  * The ANSI C "prototype" for this macro is:
2202  *
2203  * EXTERN char *  TclGetString _ANSI_ARGS_((Tcl_Obj *objPtr));
2204  *----------------------------------------------------------------
2205  */
2206 
2207 #define TclGetString(objPtr) \
2208     ((objPtr)->bytes? (objPtr)->bytes : Tcl_GetString((objPtr)))
2209 
2210 /*
2211  *----------------------------------------------------------------
2212  * Macro used by the Tcl core to get a Tcl_WideInt value out of
2213  * a Tcl_Obj of the "wideInt" type.  Different implementation on
2214  * different platforms depending whether TCL_WIDE_INT_IS_LONG.
2215  *----------------------------------------------------------------
2216  */
2217 
2218 #ifdef TCL_WIDE_INT_IS_LONG
2219 #    define TclGetWide(resultVar, objPtr) \
2220 	(resultVar) = (objPtr)->internalRep.longValue
2221 #    define TclGetLongFromWide(resultVar, objPtr) \
2222 	(resultVar) = (objPtr)->internalRep.longValue
2223 #else
2224 #    define TclGetWide(resultVar, objPtr) \
2225 	(resultVar) = (objPtr)->internalRep.wideValue
2226 #    define TclGetLongFromWide(resultVar, objPtr) \
2227 	(resultVar) = Tcl_WideAsLong((objPtr)->internalRep.wideValue)
2228 #endif
2229 
2230 /*
2231  *----------------------------------------------------------------
2232  * Macro used by the Tcl core get a unicode char from a utf string.
2233  * It checks to see if we have a one-byte utf char before calling
2234  * the real Tcl_UtfToUniChar, as this will save a lot of time for
2235  * primarily ascii string handling. The macro's expression result
2236  * is 1 for the 1-byte case or the result of Tcl_UtfToUniChar.
2237  * The ANSI C "prototype" for this macro is:
2238  *
2239  * EXTERN int TclUtfToUniChar _ANSI_ARGS_((CONST char *string,
2240  *					   Tcl_UniChar *ch));
2241  *----------------------------------------------------------------
2242  */
2243 
2244 #define TclUtfToUniChar(str, chPtr) \
2245 	((((unsigned char) *(str)) < 0xC0) ? \
2246 	    ((*(chPtr) = (Tcl_UniChar) *(str)), 1) \
2247 	    : Tcl_UtfToUniChar(str, chPtr))
2248 
2249 /*
2250  *----------------------------------------------------------------
2251  * Macro used by the Tcl core to compare Unicode strings.  On
2252  * big-endian systems we can use the more efficient memcmp, but
2253  * this would not be lexically correct on little-endian systems.
2254  * The ANSI C "prototype" for this macro is:
2255  *
2256  * EXTERN int TclUniCharNcmp _ANSI_ARGS_((CONST Tcl_UniChar *cs,
2257  *         CONST Tcl_UniChar *ct, unsigned long n));
2258  *----------------------------------------------------------------
2259  */
2260 #ifdef WORDS_BIGENDIAN
2261 #   define TclUniCharNcmp(cs,ct,n) memcmp((cs),(ct),(n)*sizeof(Tcl_UniChar))
2262 #else /* !WORDS_BIGENDIAN */
2263 #   define TclUniCharNcmp Tcl_UniCharNcmp
2264 #endif /* WORDS_BIGENDIAN */
2265 
2266 #include "tclIntDecls.h"
2267 
2268 # undef TCL_STORAGE_CLASS
2269 # define TCL_STORAGE_CLASS DLLIMPORT
2270 
2271 #endif /* _TCLINT */
2272 
2273