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