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 of
14 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 *
16 * RCS: @(#) $Id: tclInt.h,v 1.362.2.14 2010/07/25 10:13:48 nijtmans Exp $
17 */
18
19#ifndef _TCLINT
20#define _TCLINT
21
22/*
23 * Some numerics configuration options.
24 */
25
26#undef NO_WIDE_TYPE
27#undef ACCEPT_NAN
28
29/*
30 * Common include files needed by most of the Tcl source files are included
31 * here, so that system-dependent personalizations for the include files only
32 * have to be made in once place. This results in a few extra includes, but
33 * greater modularity. The order of the three groups of #includes is
34 * important. For example, stdio.h is needed by tcl.h, and the _ANSI_ARGS_
35 * declaration in tcl.h is needed by stdlib.h in some configurations.
36 */
37
38#include "tclPort.h"
39
40#include <stdio.h>
41
42#include <ctype.h>
43#ifdef NO_STDLIB_H
44#   include "../compat/stdlib.h"
45#else
46#   include <stdlib.h>
47#endif
48#ifdef NO_STRING_H
49#include "../compat/string.h"
50#else
51#include <string.h>
52#endif
53#ifdef STDC_HEADERS
54#include <stddef.h>
55#else
56typedef int ptrdiff_t;
57#endif
58
59/*
60 * Ensure WORDS_BIGENDIAN is defined correctly:
61 * Needs to happen here in addition to configure to work with fat compiles on
62 * Darwin (where configure runs only once for multiple architectures).
63 */
64
65#ifdef HAVE_SYS_TYPES_H
66#    include <sys/types.h>
67#endif
68#ifdef HAVE_SYS_PARAM_H
69#    include <sys/param.h>
70#endif
71#ifdef BYTE_ORDER
72#    ifdef BIG_ENDIAN
73#	 if BYTE_ORDER == BIG_ENDIAN
74#	     undef WORDS_BIGENDIAN
75#	     define WORDS_BIGENDIAN 1
76#	 endif
77#    endif
78#    ifdef LITTLE_ENDIAN
79#	 if BYTE_ORDER == LITTLE_ENDIAN
80#	     undef WORDS_BIGENDIAN
81#	 endif
82#    endif
83#endif
84
85/*
86 * Used to tag functions that are only to be visible within the module being
87 * built and not outside it (where this is supported by the linker).
88 */
89
90#ifndef MODULE_SCOPE
91#   ifdef __cplusplus
92#	define MODULE_SCOPE extern "C"
93#   else
94#	define MODULE_SCOPE extern
95#   endif
96#endif
97
98/*
99 * When Tcl_WideInt and long are the same type, there's no value in
100 * having a tclWideIntType separate from the tclIntType.
101 */
102#ifdef TCL_WIDE_INT_IS_LONG
103#define NO_WIDE_TYPE
104#endif
105
106/*
107 * Macros used to cast between pointers and integers (e.g. when storing an int
108 * in ClientData), on 64-bit architectures they avoid gcc warning about "cast
109 * to/from pointer from/to integer of different size".
110 */
111
112#if !defined(INT2PTR) && !defined(PTR2INT)
113#   if defined(HAVE_INTPTR_T) || defined(intptr_t)
114#	define INT2PTR(p) ((void *)(intptr_t)(p))
115#	define PTR2INT(p) ((int)(intptr_t)(p))
116#   else
117#	define INT2PTR(p) ((void *)(p))
118#	define PTR2INT(p) ((int)(p))
119#   endif
120#endif
121#if !defined(UINT2PTR) && !defined(PTR2UINT)
122#   if defined(HAVE_UINTPTR_T) || defined(uintptr_t)
123#	define UINT2PTR(p) ((void *)(uintptr_t)(p))
124#	define PTR2UINT(p) ((unsigned int)(uintptr_t)(p))
125#   else
126#	define UINT2PTR(p) ((void *)(p))
127#	define PTR2UINT(p) ((unsigned int)(p))
128#   endif
129#endif
130
131/*
132 * The following procedures allow namespaces to be customized to support
133 * special name resolution rules for commands/variables.
134 */
135
136struct Tcl_ResolvedVarInfo;
137
138typedef Tcl_Var (Tcl_ResolveRuntimeVarProc)(Tcl_Interp *interp,
139	struct Tcl_ResolvedVarInfo *vinfoPtr);
140
141typedef void (Tcl_ResolveVarDeleteProc)(struct Tcl_ResolvedVarInfo *vinfoPtr);
142
143/*
144 * The following structure encapsulates the routines needed to resolve a
145 * variable reference at runtime. Any variable specific state will typically
146 * be appended to this structure.
147 */
148
149typedef struct Tcl_ResolvedVarInfo {
150    Tcl_ResolveRuntimeVarProc *fetchProc;
151    Tcl_ResolveVarDeleteProc *deleteProc;
152} Tcl_ResolvedVarInfo;
153
154typedef int (Tcl_ResolveCompiledVarProc)(Tcl_Interp *interp,
155	CONST84 char *name, int length, Tcl_Namespace *context,
156	Tcl_ResolvedVarInfo **rPtr);
157
158typedef int (Tcl_ResolveVarProc)(Tcl_Interp *interp, CONST84 char *name,
159	Tcl_Namespace *context, int flags, Tcl_Var *rPtr);
160
161typedef int (Tcl_ResolveCmdProc)(Tcl_Interp *interp, CONST84 char *name,
162	Tcl_Namespace *context, int flags, Tcl_Command *rPtr);
163
164typedef struct Tcl_ResolverInfo {
165    Tcl_ResolveCmdProc *cmdResProc;
166				/* Procedure handling command name
167				 * resolution. */
168    Tcl_ResolveVarProc *varResProc;
169				/* Procedure handling variable name resolution
170				 * for variables that can only be handled at
171				 * runtime. */
172    Tcl_ResolveCompiledVarProc *compiledVarResProc;
173				/* Procedure handling variable name resolution
174				 * at compile time. */
175} Tcl_ResolverInfo;
176
177/*
178 *----------------------------------------------------------------
179 * Data structures related to namespaces.
180 *----------------------------------------------------------------
181 */
182
183typedef struct Tcl_Ensemble Tcl_Ensemble;
184typedef struct NamespacePathEntry NamespacePathEntry;
185
186/*
187 * Special hashtable for variables: this is just a Tcl_HashTable with an nsPtr
188 * field added at the end: in this way variables can find their namespace
189 * without having to copy a pointer in their struct: they can access it via
190 * their hPtr->tablePtr.
191 */
192
193typedef struct TclVarHashTable {
194    Tcl_HashTable table;
195    struct Namespace *nsPtr;
196} TclVarHashTable;
197
198/*
199 * This is for itcl - it likes to search our varTables directly :(
200 */
201
202#define TclVarHashFindVar(tablePtr, key) \
203    TclVarHashCreateVar((tablePtr), (key), NULL)
204
205
206/*
207 * The structure below defines a namespace.
208 * Note: the first five fields must match exactly the fields in a
209 * Tcl_Namespace structure (see tcl.h). If you change one, be sure to change
210 * the other.
211 */
212
213typedef struct Namespace {
214    char *name;			/* The namespace's simple (unqualified) name.
215				 * This contains no ::'s. The name of the
216				 * global namespace is "" although "::" is an
217				 * synonym. */
218    char *fullName;		/* The namespace's fully qualified name. This
219				 * starts with ::. */
220    ClientData clientData;	/* An arbitrary value associated with this
221				 * namespace. */
222    Tcl_NamespaceDeleteProc *deleteProc;
223				/* Procedure invoked when deleting the
224				 * namespace to, e.g., free clientData. */
225    struct Namespace *parentPtr;/* Points to the namespace that contains this
226				 * one. NULL if this is the global
227				 * namespace. */
228    Tcl_HashTable childTable;	/* Contains any child namespaces. Indexed by
229				 * strings; values have type (Namespace *). */
230    long nsId;			/* Unique id for the namespace. */
231    Tcl_Interp *interp;		/* The interpreter containing this
232				 * namespace. */
233    int flags;			/* OR-ed combination of the namespace status
234				 * flags NS_DYING and NS_DEAD listed below. */
235    int activationCount;	/* Number of "activations" or active call
236				 * frames for this namespace that are on the
237				 * Tcl call stack. The namespace won't be
238				 * freed until activationCount becomes zero. */
239    int refCount;		/* Count of references by namespaceName
240				 * objects. The namespace can't be freed until
241				 * refCount becomes zero. */
242    Tcl_HashTable cmdTable;	/* Contains all the commands currently
243				 * registered in the namespace. Indexed by
244				 * strings; values have type (Command *).
245				 * Commands imported by Tcl_Import have
246				 * Command structures that point (via an
247				 * ImportedCmdRef structure) to the Command
248				 * structure in the source namespace's command
249				 * table. */
250    TclVarHashTable varTable;	/* Contains all the (global) variables
251				 * currently in this namespace. Indexed by
252				 * strings; values have type (Var *). */
253    char **exportArrayPtr;	/* Points to an array of string patterns
254				 * specifying which commands are exported. A
255				 * pattern may include "string match" style
256				 * wildcard characters to specify multiple
257				 * commands; however, no namespace qualifiers
258				 * are allowed. NULL if no export patterns are
259				 * registered. */
260    int numExportPatterns;	/* Number of export patterns currently
261				 * registered using "namespace export". */
262    int maxExportPatterns;	/* Mumber of export patterns for which space
263				 * is currently allocated. */
264    int cmdRefEpoch;		/* Incremented if a newly added command
265				 * shadows a command for which this namespace
266				 * has already cached a Command* pointer; this
267				 * causes all its cached Command* pointers to
268				 * be invalidated. */
269    int resolverEpoch;		/* Incremented whenever (a) the name
270				 * resolution rules change for this namespace
271				 * or (b) a newly added command shadows a
272				 * command that is compiled to bytecodes. This
273				 * invalidates all byte codes compiled in the
274				 * namespace, causing the code to be
275				 * recompiled under the new rules.*/
276    Tcl_ResolveCmdProc *cmdResProc;
277				/* If non-null, this procedure overrides the
278				 * usual command resolution mechanism in Tcl.
279				 * This procedure is invoked within
280				 * Tcl_FindCommand to resolve all command
281				 * references within the namespace. */
282    Tcl_ResolveVarProc *varResProc;
283				/* If non-null, this procedure overrides the
284				 * usual variable resolution mechanism in Tcl.
285				 * This procedure is invoked within
286				 * Tcl_FindNamespaceVar to resolve all
287				 * variable references within the namespace at
288				 * runtime. */
289    Tcl_ResolveCompiledVarProc *compiledVarResProc;
290				/* If non-null, this procedure overrides the
291				 * usual variable resolution mechanism in Tcl.
292				 * This procedure is invoked within
293				 * LookupCompiledLocal to resolve variable
294				 * references within the namespace at compile
295				 * time. */
296    int exportLookupEpoch;	/* Incremented whenever a command is added to
297				 * a namespace, removed from a namespace or
298				 * the exports of a namespace are changed.
299				 * Allows TIP#112-driven command lists to be
300				 * validated efficiently. */
301    Tcl_Ensemble *ensembles;	/* List of structures that contain the details
302				 * of the ensembles that are implemented on
303				 * top of this namespace. */
304    Tcl_Obj *unknownHandlerPtr;	/* A script fragment to be used when command
305				 * resolution in this namespace fails. TIP
306				 * 181. */
307    int commandPathLength;	/* The length of the explicit path. */
308    NamespacePathEntry *commandPathArray;
309				/* The explicit path of the namespace as an
310				 * array. */
311    NamespacePathEntry *commandPathSourceList;
312				/* Linked list of path entries that point to
313				 * this namespace. */
314} Namespace;
315
316/*
317 * An entry on a namespace's command resolution path.
318 */
319
320struct NamespacePathEntry {
321    Namespace *nsPtr;		/* What does this path entry point to? If it
322				 * is NULL, this path entry points is
323				 * redundant and should be skipped. */
324    Namespace *creatorNsPtr;	/* Where does this path entry point from? This
325				 * allows for efficient invalidation of
326				 * references when the path entry's target
327				 * updates its current list of defined
328				 * commands. */
329    NamespacePathEntry *prevPtr, *nextPtr;
330				/* Linked list pointers or NULL at either end
331				 * of the list that hangs off Namespace's
332				 * commandPathSourceList field. */
333};
334
335/*
336 * Flags used to represent the status of a namespace:
337 *
338 * NS_DYING -	1 means Tcl_DeleteNamespace has been called to delete the
339 *		namespace but there are still active call frames on the Tcl
340 *		stack that refer to the namespace. When the last call frame
341 *		referring to it has been popped, it's variables and command
342 *		will be destroyed and it will be marked "dead" (NS_DEAD). The
343 *		namespace can no longer be looked up by name.
344 * NS_DEAD -	1 means Tcl_DeleteNamespace has been called to delete the
345 *		namespace and no call frames still refer to it. Its variables
346 *		and command have already been destroyed. This bit allows the
347 *		namespace resolution code to recognize that the namespace is
348 *		"deleted". When the last namespaceName object in any byte code
349 *		unit that refers to the namespace has been freed (i.e., when
350 *		the namespace's refCount is 0), the namespace's storage will
351 *		be freed.
352 * NS_KILLED    1 means that TclTeardownNamespace has already been called on
353 *              this namespace and it should not be called again [Bug 1355942]
354 */
355
356#define NS_DYING	0x01
357#define NS_DEAD		0x02
358#define NS_KILLED	0x04
359
360/*
361 * Flags passed to TclGetNamespaceForQualName:
362 *
363 * TCL_GLOBAL_ONLY		- (see tcl.h) Look only in the global ns.
364 * TCL_NAMESPACE_ONLY		- (see tcl.h) Look only in the context ns.
365 * TCL_CREATE_NS_IF_UNKNOWN	- Create unknown namespaces.
366 * TCL_FIND_ONLY_NS		- The name sought is a namespace name.
367 */
368
369#define TCL_CREATE_NS_IF_UNKNOWN	0x800
370#define TCL_FIND_ONLY_NS		0x1000
371
372/*
373 * The data cached in an ensemble subcommand's Tcl_Obj rep (reference in
374 * otherValuePtr field). This structure is not shared between Tcl_Objs
375 * referring to the same subcommand, even where one is a duplicate of another.
376 */
377
378typedef struct {
379    Namespace *nsPtr;		/* The namespace backing the ensemble which
380				 * this is a subcommand of. */
381    int epoch;			/* Used to confirm when the data in this
382				 * really structure matches up with the
383				 * ensemble. */
384    Tcl_Command token;		/* Reference to the comamnd for which this
385				 * structure is a cache of the resolution. */
386    char *fullSubcmdName;	/* The full (local) name of the subcommand,
387				 * allocated with ckalloc(). */
388    Tcl_Obj *realPrefixObj;	/* Object containing the prefix words of the
389				 * command that implements this ensemble
390				 * subcommand. */
391} EnsembleCmdRep;
392
393/*
394 * Flag to enable bytecode compilation of an ensemble.
395 */
396
397#define ENSEMBLE_COMPILE 0x4
398
399/*
400 *----------------------------------------------------------------
401 * Data structures related to variables. These are used primarily in tclVar.c
402 *----------------------------------------------------------------
403 */
404
405/*
406 * The following structure defines a variable trace, which is used to invoke a
407 * specific C procedure whenever certain operations are performed on a
408 * variable.
409 */
410
411typedef struct VarTrace {
412    Tcl_VarTraceProc *traceProc;/* Procedure to call when operations given by
413				 * flags are performed on variable. */
414    ClientData clientData;	/* Argument to pass to proc. */
415    int flags;			/* What events the trace procedure is
416				 * interested in: OR-ed combination of
417				 * TCL_TRACE_READS, TCL_TRACE_WRITES,
418				 * TCL_TRACE_UNSETS and TCL_TRACE_ARRAY. */
419    struct VarTrace *nextPtr;	/* Next in list of traces associated with a
420				 * particular variable. */
421} VarTrace;
422
423/*
424 * The following structure defines a command trace, which is used to invoke a
425 * specific C procedure whenever certain operations are performed on a
426 * command.
427 */
428
429typedef struct CommandTrace {
430    Tcl_CommandTraceProc *traceProc;
431				/* Procedure to call when operations given by
432				 * flags are performed on command. */
433    ClientData clientData;	/* Argument to pass to proc. */
434    int flags;			/* What events the trace procedure is
435				 * interested in: OR-ed combination of
436				 * TCL_TRACE_RENAME, TCL_TRACE_DELETE. */
437    struct CommandTrace *nextPtr;
438				/* Next in list of traces associated with a
439				 * particular command. */
440    int refCount;		/* Used to ensure this structure is not
441				 * deleted too early. Keeps track of how many
442				 * pieces of code have a pointer to this
443				 * structure. */
444} CommandTrace;
445
446/*
447 * When a command trace is active (i.e. its associated procedure is executing)
448 * one of the following structures is linked into a list associated with the
449 * command's interpreter. The information in the structure is needed in order
450 * for Tcl to behave reasonably if traces are deleted while traces are active.
451 */
452
453typedef struct ActiveCommandTrace {
454    struct Command *cmdPtr;	/* Command that's being traced. */
455    struct ActiveCommandTrace *nextPtr;
456				/* Next in list of all active command traces
457				 * for the interpreter, or NULL if no more. */
458    CommandTrace *nextTracePtr;	/* Next trace to check after current trace
459				 * procedure returns; if this trace gets
460				 * deleted, must update pointer to avoid using
461				 * free'd memory. */
462    int reverseScan;		/* Boolean set true when traces are scanning
463				 * in reverse order. */
464} ActiveCommandTrace;
465
466/*
467 * When a variable trace is active (i.e. its associated procedure is
468 * executing) one of the following structures is linked into a list associated
469 * with the variable's interpreter. The information in the structure is needed
470 * in order for Tcl to behave reasonably if traces are deleted while traces
471 * are active.
472 */
473
474typedef struct ActiveVarTrace {
475    struct Var *varPtr;		/* Variable that's being traced. */
476    struct ActiveVarTrace *nextPtr;
477				/* Next in list of all active variable traces
478				 * for the interpreter, or NULL if no more. */
479    VarTrace *nextTracePtr;	/* Next trace to check after current trace
480				 * procedure returns; if this trace gets
481				 * deleted, must update pointer to avoid using
482				 * free'd memory. */
483} ActiveVarTrace;
484
485/*
486 * The following structure describes an enumerative search in progress on an
487 * array variable; this are invoked with options to the "array" command.
488 */
489
490typedef struct ArraySearch {
491    int id;			/* Integer id used to distinguish among
492				 * multiple concurrent searches for the same
493				 * array. */
494    struct Var *varPtr;		/* Pointer to array variable that's being
495				 * searched. */
496    Tcl_HashSearch search;	/* Info kept by the hash module about progress
497				 * through the array. */
498    Tcl_HashEntry *nextEntry;	/* Non-null means this is the next element to
499				 * be enumerated (it's leftover from the
500				 * Tcl_FirstHashEntry call or from an "array
501				 * anymore" command). NULL means must call
502				 * Tcl_NextHashEntry to get value to
503				 * return. */
504    struct ArraySearch *nextPtr;/* Next in list of all active searches for
505				 * this variable, or NULL if this is the last
506				 * one. */
507} ArraySearch;
508
509/*
510 * The structure below defines a variable, which associates a string name with
511 * a Tcl_Obj value. These structures are kept in procedure call frames (for
512 * local variables recognized by the compiler) or in the heap (for global
513 * variables and any variable not known to the compiler). For each Var
514 * structure in the heap, a hash table entry holds the variable name and a
515 * pointer to the Var structure.
516 */
517
518typedef struct Var {
519    int flags;			/* Miscellaneous bits of information about
520				 * variable. See below for definitions. */
521    union {
522	Tcl_Obj *objPtr;	/* The variable's object value. Used for
523				 * scalar variables and array elements. */
524	TclVarHashTable *tablePtr;/* For array variables, this points to
525				 * information about the hash table used to
526				 * implement the associative array. Points to
527				 * ckalloc-ed data. */
528	struct Var *linkPtr;	/* If this is a global variable being referred
529				 * to in a procedure, or a variable created by
530				 * "upvar", this field points to the
531				 * referenced variable's Var struct. */
532    } value;
533} Var;
534
535typedef struct VarInHash {
536    Var var;
537    int refCount;		/* Counts number of active uses of this
538				 * variable: 1 for the entry in the hash
539				 * table, 1 for each additional variable whose
540				 * linkPtr points here, 1 for each nested
541				 * trace active on variable, and 1 if the
542				 * variable is a namespace variable. This
543				 * record can't be deleted until refCount
544				 * becomes 0. */
545    Tcl_HashEntry entry;	/* The hash table entry that refers to this
546				 * variable. This is used to find the name of
547				 * the variable and to delete it from its
548				 * hashtable if it is no longer needed. It
549				 * also holds the variable's name. */
550} VarInHash;
551
552/*
553 * Flag bits for variables. The first two (VAR_ARRAY and VAR_LINK) are
554 * mutually exclusive and give the "type" of the variable. If none is set,
555 * this is a scalar variable.
556 *
557 * VAR_ARRAY -			1 means this is an array variable rather than
558 *				a scalar variable or link. The "tablePtr"
559 *				field points to the array's hashtable for its
560 *				elements.
561 * VAR_LINK -			1 means this Var structure contains a pointer
562 *				to another Var structure that either has the
563 *				real value or is itself another VAR_LINK
564 *				pointer. Variables like this come about
565 *				through "upvar" and "global" commands, or
566 *				through references to variables in enclosing
567 *				namespaces.
568 *
569 * Flags that indicate the type and status of storage; none is set for
570 * compiled local variables (Var structs).
571 *
572 * VAR_IN_HASHTABLE -		1 means this variable is in a hashtable and
573 *				the Var structure is malloced. 0 if it is a
574 *				local variable that was assigned a slot in a
575 *				procedure frame by the compiler so the Var
576 *				storage is part of the call frame.
577 * VAR_DEAD_HASH		1 means that this var's entry in the hashtable
578 *				has already been deleted.
579 * VAR_ARRAY_ELEMENT -		1 means that this variable is an array
580 *				element, so it is not legal for it to be an
581 *				array itself (the VAR_ARRAY flag had better
582 *				not be set).
583 * VAR_NAMESPACE_VAR -		1 means that this variable was declared as a
584 *				namespace variable. This flag ensures it
585 *				persists until its namespace is destroyed or
586 *				until the variable is unset; it will persist
587 *				even if it has not been initialized and is
588 *				marked undefined. The variable's refCount is
589 *				incremented to reflect the "reference" from
590 *				its namespace.
591 *
592 * Flag values relating to the variable's trace and search status.
593 *
594 * VAR_TRACED_READ
595 * VAR_TRACED_WRITE
596 * VAR_TRACED_UNSET
597 * VAR_TRACED_ARRAY
598 * VAR_TRACE_ACTIVE -		1 means that trace processing is currently
599 *				underway for a read or write access, so new
600 *				read or write accesses should not cause trace
601 *				procedures to be called and the variable can't
602 *				be deleted.
603 * VAR_SEARCH_ACTIVE
604 *
605 * The following additional flags are used with the CompiledLocal type defined
606 * below:
607 *
608 * VAR_ARGUMENT -		1 means that this variable holds a procedure
609 *				argument.
610 * VAR_TEMPORARY -		1 if the local variable is an anonymous
611 *				temporary variable. Temporaries have a NULL
612 *				name.
613 * VAR_RESOLVED -		1 if name resolution has been done for this
614 *				variable.
615 * VAR_IS_ARGS			1 if this variable is the last argument and is
616 *				named "args".
617 */
618
619/*
620 * FLAGS RENUMBERED: everything breaks already, make things simpler.
621 *
622 * IMPORTANT: skip the values 0x10, 0x20, 0x40, 0x800 corresponding to
623 * TCL_TRACE_(READS/WRITES/UNSETS/ARRAY): makes code simpler in tclTrace.c
624 *
625 * Keep the flag values for VAR_ARGUMENT and VAR_TEMPORARY so that old values
626 * in precompiled scripts keep working.
627 */
628
629/* Type of value (0 is scalar) */
630#define VAR_ARRAY		0x1
631#define VAR_LINK		0x2
632
633/* Type of storage (0 is compiled local) */
634#define VAR_IN_HASHTABLE	0x4
635#define VAR_DEAD_HASH		0x8
636#define VAR_ARRAY_ELEMENT	0x1000
637#define VAR_NAMESPACE_VAR	0x80	/* KEEP OLD VALUE for Itcl */
638
639#define VAR_ALL_HASH \
640	(VAR_IN_HASHTABLE|VAR_DEAD_HASH|VAR_NAMESPACE_VAR|VAR_ARRAY_ELEMENT)
641
642/* Trace and search state. */
643
644#define VAR_TRACED_READ		0x10	/* TCL_TRACE_READS */
645#define VAR_TRACED_WRITE	0x20	/* TCL_TRACE_WRITES */
646#define VAR_TRACED_UNSET	0x40	/* TCL_TRACE_UNSETS */
647#define VAR_TRACED_ARRAY	0x800	/* TCL_TRACE_ARRAY */
648#define VAR_TRACE_ACTIVE	0x2000
649#define VAR_SEARCH_ACTIVE	0x4000
650#define VAR_ALL_TRACES \
651	(VAR_TRACED_READ|VAR_TRACED_WRITE|VAR_TRACED_ARRAY|VAR_TRACED_UNSET)
652
653/* Special handling on initialisation (only CompiledLocal). */
654#define VAR_ARGUMENT		0x100	/* KEEP OLD VALUE! See tclProc.c */
655#define VAR_TEMPORARY		0x200	/* KEEP OLD VALUE! See tclProc.c */
656#define VAR_IS_ARGS		0x400
657#define VAR_RESOLVED		0x8000
658
659/*
660 * Macros to ensure that various flag bits are set properly for variables.
661 * The ANSI C "prototypes" for these macros are:
662 *
663 * MODULE_SCOPE void	TclSetVarScalar(Var *varPtr);
664 * MODULE_SCOPE void	TclSetVarArray(Var *varPtr);
665 * MODULE_SCOPE void	TclSetVarLink(Var *varPtr);
666 * MODULE_SCOPE void	TclSetVarArrayElement(Var *varPtr);
667 * MODULE_SCOPE void	TclSetVarUndefined(Var *varPtr);
668 * MODULE_SCOPE void	TclClearVarUndefined(Var *varPtr);
669 */
670
671#define TclSetVarScalar(varPtr) \
672    (varPtr)->flags &= ~(VAR_ARRAY|VAR_LINK)
673
674#define TclSetVarArray(varPtr) \
675    (varPtr)->flags = ((varPtr)->flags & ~VAR_LINK) | VAR_ARRAY
676
677#define TclSetVarLink(varPtr) \
678    (varPtr)->flags = ((varPtr)->flags & ~VAR_ARRAY) | VAR_LINK
679
680#define TclSetVarArrayElement(varPtr) \
681    (varPtr)->flags = ((varPtr)->flags & ~VAR_ARRAY) | VAR_ARRAY_ELEMENT
682
683#define TclSetVarUndefined(varPtr) \
684    (varPtr)->flags &= ~(VAR_ARRAY|VAR_LINK);\
685    (varPtr)->value.objPtr = NULL
686
687#define TclClearVarUndefined(varPtr)
688
689#define TclSetVarTraceActive(varPtr) \
690    (varPtr)->flags |= VAR_TRACE_ACTIVE
691
692#define TclClearVarTraceActive(varPtr) \
693    (varPtr)->flags &= ~VAR_TRACE_ACTIVE
694
695#define TclSetVarNamespaceVar(varPtr) \
696    if (!TclIsVarNamespaceVar(varPtr)) {\
697	(varPtr)->flags |= VAR_NAMESPACE_VAR;\
698	((VarInHash *)(varPtr))->refCount++;\
699    }
700
701#define TclClearVarNamespaceVar(varPtr) \
702    if (TclIsVarNamespaceVar(varPtr)) {\
703	(varPtr)->flags &= ~VAR_NAMESPACE_VAR;\
704	((VarInHash *)(varPtr))->refCount--;\
705    }
706
707/*
708 * Macros to read various flag bits of variables.
709 * The ANSI C "prototypes" for these macros are:
710 *
711 * MODULE_SCOPE int	TclIsVarScalar(Var *varPtr);
712 * MODULE_SCOPE int	TclIsVarLink(Var *varPtr);
713 * MODULE_SCOPE int	TclIsVarArray(Var *varPtr);
714 * MODULE_SCOPE int	TclIsVarUndefined(Var *varPtr);
715 * MODULE_SCOPE int	TclIsVarArrayElement(Var *varPtr);
716 * MODULE_SCOPE int	TclIsVarTemporary(Var *varPtr);
717 * MODULE_SCOPE int	TclIsVarArgument(Var *varPtr);
718 * MODULE_SCOPE int	TclIsVarResolved(Var *varPtr);
719 */
720
721#define TclIsVarScalar(varPtr) \
722    !((varPtr)->flags & (VAR_ARRAY|VAR_LINK))
723
724#define TclIsVarLink(varPtr) \
725    ((varPtr)->flags & VAR_LINK)
726
727#define TclIsVarArray(varPtr) \
728    ((varPtr)->flags & VAR_ARRAY)
729
730#define TclIsVarUndefined(varPtr) \
731    ((varPtr)->value.objPtr == NULL)
732
733#define TclIsVarArrayElement(varPtr) \
734    ((varPtr)->flags & VAR_ARRAY_ELEMENT)
735
736#define TclIsVarNamespaceVar(varPtr) \
737    ((varPtr)->flags & VAR_NAMESPACE_VAR)
738
739#define TclIsVarTemporary(varPtr) \
740    ((varPtr)->flags & VAR_TEMPORARY)
741
742#define TclIsVarArgument(varPtr) \
743    ((varPtr)->flags & VAR_ARGUMENT)
744
745#define TclIsVarResolved(varPtr) \
746    ((varPtr)->flags & VAR_RESOLVED)
747
748#define TclIsVarTraceActive(varPtr) \
749    ((varPtr)->flags & VAR_TRACE_ACTIVE)
750
751#define TclIsVarTraced(varPtr) \
752    ((varPtr)->flags & VAR_ALL_TRACES)
753
754#define TclIsVarInHash(varPtr) \
755    ((varPtr)->flags & VAR_IN_HASHTABLE)
756
757#define TclIsVarDeadHash(varPtr) \
758    ((varPtr)->flags & VAR_DEAD_HASH)
759
760#define TclGetVarNsPtr(varPtr) \
761    (TclIsVarInHash(varPtr) \
762	? ((TclVarHashTable *) ((((VarInHash *) (varPtr))->entry.tablePtr)))->nsPtr \
763	: NULL)
764
765#define VarHashRefCount(varPtr) \
766    ((VarInHash *) (varPtr))->refCount
767
768/*
769 * Macros for direct variable access by TEBC.
770 */
771
772#define TclIsVarDirectReadable(varPtr) \
773    (   !((varPtr)->flags & (VAR_ARRAY|VAR_LINK|VAR_TRACED_READ)) \
774    &&  (varPtr)->value.objPtr)
775
776#define TclIsVarDirectWritable(varPtr) \
777    !((varPtr)->flags & (VAR_ARRAY|VAR_LINK|VAR_TRACED_WRITE|VAR_DEAD_HASH))
778
779#define TclIsVarDirectModifyable(varPtr) \
780    (   !((varPtr)->flags & (VAR_ARRAY|VAR_LINK|VAR_TRACED_READ|VAR_TRACED_WRITE)) \
781    &&  (varPtr)->value.objPtr)
782
783#define TclIsVarDirectReadable2(varPtr, arrayPtr) \
784    (TclIsVarDirectReadable(varPtr) &&\
785	(!(arrayPtr) || !((arrayPtr)->flags & VAR_TRACED_READ)))
786
787#define TclIsVarDirectWritable2(varPtr, arrayPtr) \
788    (TclIsVarDirectWritable(varPtr) &&\
789	(!(arrayPtr) || !((arrayPtr)->flags & VAR_TRACED_WRITE)))
790
791#define TclIsVarDirectModifyable2(varPtr, arrayPtr) \
792    (TclIsVarDirectModifyable(varPtr) &&\
793	(!(arrayPtr) || !((arrayPtr)->flags & (VAR_TRACED_READ|VAR_TRACED_WRITE))))
794
795/*
796 *----------------------------------------------------------------
797 * Data structures related to procedures. These are used primarily in
798 * tclProc.c, tclCompile.c, and tclExecute.c.
799 *----------------------------------------------------------------
800 */
801
802/*
803 * Forward declaration to prevent an error when the forward reference to
804 * Command is encountered in the Proc and ImportRef types declared below.
805 */
806
807struct Command;
808
809/*
810 * The variable-length structure below describes a local variable of a
811 * procedure that was recognized by the compiler. These variables have a name,
812 * an element in the array of compiler-assigned local variables in the
813 * procedure's call frame, and various other items of information. If the
814 * local variable is a formal argument, it may also have a default value. The
815 * compiler can't recognize local variables whose names are expressions (these
816 * names are only known at runtime when the expressions are evaluated) or
817 * local variables that are created as a result of an "upvar" or "uplevel"
818 * command. These other local variables are kept separately in a hash table in
819 * the call frame.
820 */
821
822typedef struct CompiledLocal {
823    struct CompiledLocal *nextPtr;
824				/* Next compiler-recognized local variable for
825				 * this procedure, or NULL if this is the last
826				 * local. */
827    int nameLength;		/* The number of characters in local
828				 * variable's name. Used to speed up variable
829				 * lookups. */
830    int frameIndex;		/* Index in the array of compiler-assigned
831				 * variables in the procedure call frame. */
832    int flags;			/* Flag bits for the local variable. Same as
833				 * the flags for the Var structure above,
834				 * although only VAR_ARGUMENT, VAR_TEMPORARY,
835				 * and VAR_RESOLVED make sense. */
836    Tcl_Obj *defValuePtr;	/* Pointer to the default value of an
837				 * argument, if any. NULL if not an argument
838				 * or, if an argument, no default value. */
839    Tcl_ResolvedVarInfo *resolveInfo;
840				/* Customized variable resolution info
841				 * supplied by the Tcl_ResolveCompiledVarProc
842				 * associated with a namespace. Each variable
843				 * is marked by a unique ClientData tag during
844				 * compilation, and that same tag is used to
845				 * find the variable at runtime. */
846    char name[4];		/* Name of the local variable starts here. If
847				 * the name is NULL, this will just be '\0'.
848				 * The actual size of this field will be large
849				 * enough to hold the name. MUST BE THE LAST
850				 * FIELD IN THE STRUCTURE! */
851} CompiledLocal;
852
853/*
854 * The structure below defines a command procedure, which consists of a
855 * collection of Tcl commands plus information about arguments and other local
856 * variables recognized at compile time.
857 */
858
859typedef struct Proc {
860    struct Interp *iPtr;	/* Interpreter for which this command is
861				 * defined. */
862    int refCount;		/* Reference count: 1 if still present in
863				 * command table plus 1 for each call to the
864				 * procedure that is currently active. This
865				 * structure can be freed when refCount
866				 * becomes zero. */
867    struct Command *cmdPtr;	/* Points to the Command structure for this
868				 * procedure. This is used to get the
869				 * namespace in which to execute the
870				 * procedure. */
871    Tcl_Obj *bodyPtr;		/* Points to the ByteCode object for
872				 * procedure's body command. */
873    int numArgs;		/* Number of formal parameters. */
874    int numCompiledLocals;	/* Count of local variables recognized by the
875				 * compiler including arguments and
876				 * temporaries. */
877    CompiledLocal *firstLocalPtr;
878				/* Pointer to first of the procedure's
879				 * compiler-allocated local variables, or NULL
880				 * if none. The first numArgs entries in this
881				 * list describe the procedure's formal
882				 * arguments. */
883    CompiledLocal *lastLocalPtr;/* Pointer to the last allocated local
884				 * variable or NULL if none. This has frame
885				 * index (numCompiledLocals-1). */
886} Proc;
887
888/*
889 * The type of functions called to process errors found during the execution
890 * of a procedure (or lambda term or ...).
891 */
892
893typedef void (*ProcErrorProc)(Tcl_Interp *interp, Tcl_Obj *procNameObj);
894
895/*
896 * The structure below defines a command trace. This is used to allow Tcl
897 * clients to find out whenever a command is about to be executed.
898 */
899
900typedef struct Trace {
901    int level;			/* Only trace commands at nesting level less
902				 * than or equal to this. */
903    Tcl_CmdObjTraceProc *proc;	/* Procedure to call to trace command. */
904    ClientData clientData;	/* Arbitrary value to pass to proc. */
905    struct Trace *nextPtr;	/* Next in list of traces for this interp. */
906    int flags;			/* Flags governing the trace - see
907				 * Tcl_CreateObjTrace for details. */
908    Tcl_CmdObjTraceDeleteProc *delProc;
909				/* Procedure to call when trace is deleted. */
910} Trace;
911
912/*
913 * When an interpreter trace is active (i.e. its associated procedure is
914 * executing), one of the following structures is linked into a list
915 * associated with the interpreter. The information in the structure is needed
916 * in order for Tcl to behave reasonably if traces are deleted while traces
917 * are active.
918 */
919
920typedef struct ActiveInterpTrace {
921    struct ActiveInterpTrace *nextPtr;
922				/* Next in list of all active command traces
923				 * for the interpreter, or NULL if no more. */
924    Trace *nextTracePtr;	/* Next trace to check after current trace
925				 * procedure returns; if this trace gets
926				 * deleted, must update pointer to avoid using
927				 * free'd memory. */
928    int reverseScan;		/* Boolean set true when traces are scanning
929				 * in reverse order. */
930} ActiveInterpTrace;
931
932/*
933 * Flag values designating types of execution traces. See tclTrace.c for
934 * related flag values.
935 *
936 * TCL_TRACE_ENTER_EXEC		- triggers enter/enterstep traces.
937 * 				- passed to Tcl_CreateObjTrace to set up
938 *				  "enterstep" traces.
939 * TCL_TRACE_LEAVE_EXEC		- triggers leave/leavestep traces.
940 * 				- passed to Tcl_CreateObjTrace to set up
941 *				  "leavestep" traces.
942 */
943
944#define TCL_TRACE_ENTER_EXEC	1
945#define TCL_TRACE_LEAVE_EXEC	2
946
947/*
948 * The structure below defines an entry in the assocData hash table which is
949 * associated with an interpreter. The entry contains a pointer to a function
950 * to call when the interpreter is deleted, and a pointer to a user-defined
951 * piece of data.
952 */
953
954typedef struct AssocData {
955    Tcl_InterpDeleteProc *proc;	/* Proc to call when deleting. */
956    ClientData clientData;	/* Value to pass to proc. */
957} AssocData;
958
959/*
960 * The structure below defines a call frame. A call frame defines a naming
961 * context for a procedure call: its local naming scope (for local variables)
962 * and its global naming scope (a namespace, perhaps the global :: namespace).
963 * A call frame can also define the naming context for a namespace eval or
964 * namespace inscope command: the namespace in which the command's code should
965 * execute. The Tcl_CallFrame structures exist only while procedures or
966 * namespace eval/inscope's are being executed, and provide a kind of Tcl call
967 * stack.
968 *
969 * WARNING!! The structure definition must be kept consistent with the
970 * Tcl_CallFrame structure in tcl.h. If you change one, change the other.
971 */
972
973/*
974 * Will be grown to contain: pointers to the varnames (allocated at the end),
975 * plus the init values for each variable (suitable to be memcopied on init)
976 */
977
978typedef struct LocalCache {
979    int refCount;
980    int numVars;
981    Tcl_Obj *varName0;
982} LocalCache;
983
984#define localName(framePtr, i) \
985    ((&((framePtr)->localCachePtr->varName0))[(i)])
986
987MODULE_SCOPE void	TclFreeLocalCache(Tcl_Interp *interp,
988			    LocalCache *localCachePtr);
989
990typedef struct CallFrame {
991    Namespace *nsPtr;		/* Points to the namespace used to resolve
992				 * commands and global variables. */
993    int isProcCallFrame;	/* If 0, the frame was pushed to execute a
994				 * namespace command and var references are
995				 * treated as references to namespace vars;
996				 * varTablePtr and compiledLocals are ignored.
997				 * If FRAME_IS_PROC is set, the frame was
998				 * pushed to execute a Tcl procedure and may
999				 * have local vars. */
1000    int objc;			/* This and objv below describe the arguments
1001				 * for this procedure call. */
1002    Tcl_Obj *const *objv;	/* Array of argument objects. */
1003    struct CallFrame *callerPtr;
1004				/* Value of interp->framePtr when this
1005				 * procedure was invoked (i.e. next higher in
1006				 * stack of all active procedures). */
1007    struct CallFrame *callerVarPtr;
1008				/* Value of interp->varFramePtr when this
1009				 * procedure was invoked (i.e. determines
1010				 * variable scoping within caller). Same as
1011				 * callerPtr unless an "uplevel" command or
1012				 * something equivalent was active in the
1013				 * caller). */
1014    int level;			/* Level of this procedure, for "uplevel"
1015				 * purposes (i.e. corresponds to nesting of
1016				 * callerVarPtr's, not callerPtr's). 1 for
1017				 * outermost procedure, 0 for top-level. */
1018    Proc *procPtr;		/* Points to the structure defining the called
1019				 * procedure. Used to get information such as
1020				 * the number of compiled local variables
1021				 * (local variables assigned entries ["slots"]
1022				 * in the compiledLocals array below). */
1023    TclVarHashTable *varTablePtr;
1024				/* Hash table containing local variables not
1025				 * recognized by the compiler, or created at
1026				 * execution time through, e.g., upvar.
1027				 * Initially NULL and created if needed. */
1028    int numCompiledLocals;	/* Count of local variables recognized by the
1029				 * compiler including arguments. */
1030    Var *compiledLocals;	/* Points to the array of local variables
1031				 * recognized by the compiler. The compiler
1032				 * emits code that refers to these variables
1033				 * using an index into this array. */
1034    ClientData clientData;	/* Pointer to some context that is used by
1035				 * object systems. The meaning of the contents
1036				 * of this field is defined by the code that
1037				 * sets it, and it should only ever be set by
1038				 * the code that is pushing the frame. In that
1039				 * case, the code that sets it should also
1040				 * have some means of discovering what the
1041				 * meaning of the value is, which we do not
1042				 * specify. */
1043    LocalCache *localCachePtr;
1044} CallFrame;
1045
1046#define FRAME_IS_PROC	0x1
1047#define FRAME_IS_LAMBDA 0x2
1048
1049/*
1050 * TIP #280
1051 * The structure below defines a command frame. A command frame provides
1052 * location information for all commands executing a tcl script (source, eval,
1053 * uplevel, procedure bodies, ...). The runtime structure essentially contains
1054 * the stack trace as it would be if the currently executing command were to
1055 * throw an error.
1056 *
1057 * For commands where it makes sense it refers to the associated CallFrame as
1058 * well.
1059 *
1060 * The structures are chained in a single list, with the top of the stack
1061 * anchored in the Interp structure.
1062 *
1063 * Instances can be allocated on the C stack, or the heap, the former making
1064 * cleanup a bit simpler.
1065 */
1066
1067typedef struct CmdFrame {
1068    /*
1069     * General data. Always available.
1070     */
1071
1072    int type;			/* Values see below. */
1073    int level;			/* Number of frames in stack, prevent O(n)
1074				 * scan of list. */
1075    int *line;			/* Lines the words of the command start on. */
1076    int nline;
1077    CallFrame *framePtr;	/* Procedure activation record, may be
1078				 * NULL. */
1079    struct CmdFrame *nextPtr;	/* Link to calling frame. */
1080    /*
1081     * Data needed for Eval vs TEBC
1082     *
1083     * EXECUTION CONTEXTS and usage of CmdFrame
1084     *
1085     * Field	  TEBC		  EvalEx	  EvalObjEx
1086     * =======	  ====		  ======	  =========
1087     * level	  yes		  yes		  yes
1088     * type	  BC/PREBC	  SRC/EVAL	  EVAL_LIST
1089     * line0	  yes		  yes		  yes
1090     * framePtr	  yes		  yes		  yes
1091     * =======	  ====		  ======	  =========
1092     *
1093     * =======	  ====		  ======	  ========= union data
1094     * line1	  -		  yes		  -
1095     * line3	  -		  yes		  -
1096     * path	  -		  yes		  -
1097     * -------	  ----		  ------	  ---------
1098     * codePtr	  yes		  -		  -
1099     * pc	  yes		  -		  -
1100     * =======	  ====		  ======	  =========
1101     *
1102     * =======	  ====		  ======	  ========= | union cmd
1103     * listPtr	  -		  -		  yes	    |
1104     * -------	  ----		  ------	  --------- |
1105     * cmd	  yes		  yes		  -	    |
1106     * cmdlen	  yes		  yes		  -	    |
1107     * -------	  ----		  ------	  --------- |
1108     */
1109
1110    union {
1111	struct {
1112	    Tcl_Obj *path;	/* Path of the sourced file the command is
1113				 * in. */
1114	} eval;
1115	struct {
1116	    const void *codePtr;/* Byte code currently executed... */
1117	    const char *pc;	/* ... and instruction pointer. */
1118	} tebc;
1119    } data;
1120    union {
1121	struct {
1122	    const char *cmd;	/* The executed command, if possible... */
1123	    int len;		/* ... and its length. */
1124	} str;
1125	Tcl_Obj *listPtr;	/* Tcl_EvalObjEx, cmd list. */
1126    } cmd;
1127} CmdFrame;
1128
1129typedef struct CFWord {
1130    CmdFrame *framePtr;		/* CmdFrame to access. */
1131    int word;			/* Index of the word in the command. */
1132    int refCount;		/* Number of times the word is on the
1133				 * stack. */
1134} CFWord;
1135
1136typedef struct CFWordBC {
1137    CmdFrame *framePtr;		/* CmdFrame to access. */
1138    int pc;			/* Instruction pointer of a command in
1139				 * ExtCmdLoc.loc[.] */
1140    int word;			/* Index of word in
1141				 * ExtCmdLoc.loc[cmd]->line[.] */
1142    struct CFWordBC *prevPtr;	/* Previous entry in stack for same Tcl_Obj. */
1143} CFWordBC;
1144
1145/*
1146 * Structure to record the locations of invisible continuation lines in
1147 * literal scripts, as character offset from the beginning of the script. Both
1148 * compiler and direct evaluator use this information to adjust their line
1149 * counters when tracking through the script, because when it is invoked the
1150 * continuation line marker as a whole has been removed already, meaning that
1151 * the \n which was part of it is gone as well, breaking regular line
1152 * tracking.
1153 *
1154 * These structures are allocated and filled by both the function
1155 * TclSubstTokens() in the file "tclParse.c" and its caller TclEvalEx() in the
1156 * file "tclBasic.c", and stored in the thread-global hashtable "lineCLPtr" in
1157 * file "tclObj.c". They are used by the functions TclSetByteCodeFromAny() and
1158 * TclCompileScript(), both found in the file "tclCompile.c". Their memory is
1159 * released by the function TclFreeObj(), in the file "tclObj.c", and also by
1160 * the function TclThreadFinalizeObjects(), in the same file.
1161 */
1162
1163#define CLL_END		(-1)
1164
1165typedef struct ContLineLoc {
1166    int num;			/* Number of entries in loc, not counting the
1167				 * final -1 marker entry. */
1168    int loc[1];			/* Table of locations, as character offsets.
1169				 * The table is allocated as part of the
1170				 * structure, extending behind the nominal end
1171				 * of the structure. An entry containing the
1172				 * value -1 is put after the last location, as
1173				 * end-marker/sentinel. */
1174} ContLineLoc;
1175
1176/*
1177 * The following macros define the allowed values for the type field of the
1178 * CmdFrame structure above. Some of the values occur only in the extended
1179 * location data referenced via the 'baseLocPtr'.
1180 *
1181 * TCL_LOCATION_EVAL	  : Frame is for a script evaluated by EvalEx.
1182 * TCL_LOCATION_EVAL_LIST : Frame is for a script evaluated by the list
1183 *			    optimization path of EvalObjEx.
1184 * TCL_LOCATION_BC	  : Frame is for bytecode.
1185 * TCL_LOCATION_PREBC	  : Frame is for precompiled bytecode.
1186 * TCL_LOCATION_SOURCE	  : Frame is for a script evaluated by EvalEx, from a
1187 *			    sourced file.
1188 * TCL_LOCATION_PROC	  : Frame is for bytecode of a procedure.
1189 *
1190 * A TCL_LOCATION_BC type in a frame can be overridden by _SOURCE and _PROC
1191 * types, per the context of the byte code in execution.
1192 */
1193
1194#define TCL_LOCATION_EVAL	(0) /* Location in a dynamic eval script. */
1195#define TCL_LOCATION_EVAL_LIST	(1) /* Location in a dynamic eval script,
1196				     * list-path. */
1197#define TCL_LOCATION_BC		(2) /* Location in byte code. */
1198#define TCL_LOCATION_PREBC	(3) /* Location in precompiled byte code, no
1199				     * location. */
1200#define TCL_LOCATION_SOURCE	(4) /* Location in a file. */
1201#define TCL_LOCATION_PROC	(5) /* Location in a dynamic proc. */
1202#define TCL_LOCATION_LAST	(6) /* Number of values in the enum. */
1203
1204/*
1205 * Structure passed to describe procedure-like "procedures" that are not
1206 * procedures (e.g. a lambda) so that their details can be reported correctly
1207 * by [info frame]. Contains a sub-structure for each extra field.
1208 */
1209
1210typedef Tcl_Obj *(*GetFrameInfoValueProc)(ClientData clientData);
1211typedef struct {
1212    const char *name;		/* Name of this field. */
1213    GetFrameInfoValueProc proc;	/* Function to generate a Tcl_Obj* from the
1214				 * clientData, or just use the clientData
1215				 * directly (after casting) if NULL. */
1216    ClientData clientData;	/* Context for above function, or Tcl_Obj* if
1217				 * proc field is NULL. */
1218} ExtraFrameInfoField;
1219typedef struct {
1220    int length;			/* Length of array. */
1221    ExtraFrameInfoField fields[2];
1222				/* Really as long as necessary, but this is
1223				 * long enough for nearly anything. */
1224} ExtraFrameInfo;
1225
1226/*
1227 *----------------------------------------------------------------
1228 * Data structures and procedures related to TclHandles, which are a very
1229 * lightweight method of preserving enough information to determine if an
1230 * arbitrary malloc'd block has been deleted.
1231 *----------------------------------------------------------------
1232 */
1233
1234typedef void **TclHandle;
1235
1236/*
1237 *----------------------------------------------------------------
1238 * Experimental flag value passed to Tcl_GetRegExpFromObj. Intended for use
1239 * only by Expect. It will probably go away in a later release.
1240 *----------------------------------------------------------------
1241 */
1242
1243#define TCL_REG_BOSONLY 002000	/* Prepend \A to pattern so it only matches at
1244				 * the beginning of the string. */
1245
1246/*
1247 * These are a thin layer over TclpThreadKeyDataGet and TclpThreadKeyDataSet
1248 * when threads are used, or an emulation if there are no threads. These are
1249 * really internal and Tcl clients should use Tcl_GetThreadData.
1250 */
1251
1252MODULE_SCOPE void *	TclThreadDataKeyGet(Tcl_ThreadDataKey *keyPtr);
1253MODULE_SCOPE void	TclThreadDataKeySet(Tcl_ThreadDataKey *keyPtr,
1254			    void *data);
1255
1256/*
1257 * This is a convenience macro used to initialize a thread local storage ptr.
1258 */
1259
1260#define TCL_TSD_INIT(keyPtr) \
1261  (ThreadSpecificData *)Tcl_GetThreadData((keyPtr), sizeof(ThreadSpecificData))
1262
1263/*
1264 *----------------------------------------------------------------
1265 * Data structures related to bytecode compilation and execution. These are
1266 * used primarily in tclCompile.c, tclExecute.c, and tclBasic.c.
1267 *----------------------------------------------------------------
1268 */
1269
1270/*
1271 * Forward declaration to prevent errors when the forward references to
1272 * Tcl_Parse and CompileEnv are encountered in the procedure type CompileProc
1273 * declared below.
1274 */
1275
1276struct CompileEnv;
1277
1278/*
1279 * The type of procedures called by the Tcl bytecode compiler to compile
1280 * commands. Pointers to these procedures are kept in the Command structure
1281 * describing each command. The integer value returned by a CompileProc must
1282 * be one of the following:
1283 *
1284 * TCL_OK		Compilation completed normally.
1285 * TCL_ERROR 		Compilation could not be completed. This can be just a
1286 * 			judgment by the CompileProc that the command is too
1287 * 			complex to compile effectively, or it can indicate
1288 * 			that in the current state of the interp, the command
1289 * 			would raise an error. The bytecode compiler will not
1290 * 			do any error reporting at compiler time. Error
1291 * 			reporting is deferred until the actual runtime,
1292 * 			because by then changes in the interp state may allow
1293 * 			the command to be successfully evaluated.
1294 * TCL_OUT_LINE_COMPILE	A source-compatible alias for TCL_ERROR, kept for the
1295 * 			sake of old code only.
1296 */
1297
1298#define TCL_OUT_LINE_COMPILE	TCL_ERROR
1299
1300typedef int (CompileProc)(Tcl_Interp *interp, Tcl_Parse *parsePtr,
1301	struct Command *cmdPtr, struct CompileEnv *compEnvPtr);
1302
1303/*
1304 * The type of procedure called from the compilation hook point in
1305 * SetByteCodeFromAny.
1306 */
1307
1308typedef int (CompileHookProc)(Tcl_Interp *interp,
1309	struct CompileEnv *compEnvPtr, ClientData clientData);
1310
1311/*
1312 * The data structure for a (linked list of) execution stacks.
1313 */
1314
1315typedef struct ExecStack {
1316    struct ExecStack *prevPtr;
1317    struct ExecStack *nextPtr;
1318    Tcl_Obj **markerPtr;
1319    Tcl_Obj **endPtr;
1320    Tcl_Obj **tosPtr;
1321    Tcl_Obj *stackWords[1];
1322} ExecStack;
1323
1324/*
1325 * The data structure defining the execution environment for ByteCode's.
1326 * There is one ExecEnv structure per Tcl interpreter. It holds the evaluation
1327 * stack that holds command operands and results. The stack grows towards
1328 * increasing addresses. The member stackPtr points to the stackItems of the
1329 * currently active execution stack.
1330 */
1331
1332typedef struct ExecEnv {
1333    ExecStack *execStackPtr;	/* Points to the first item in the evaluation
1334				 * stack on the heap. */
1335    Tcl_Obj *constants[2];	/* Pointers to constant "0" and "1" objs. */
1336} ExecEnv;
1337
1338/*
1339 * The definitions for the LiteralTable and LiteralEntry structures. Each
1340 * interpreter contains a LiteralTable. It is used to reduce the storage
1341 * needed for all the Tcl objects that hold the literals of scripts compiled
1342 * by the interpreter. A literal's object is shared by all the ByteCodes that
1343 * refer to the literal. Each distinct literal has one LiteralEntry entry in
1344 * the LiteralTable. A literal table is a specialized hash table that is
1345 * indexed by the literal's string representation, which may contain null
1346 * characters.
1347 *
1348 * Note that we reduce the space needed for literals by sharing literal
1349 * objects both within a ByteCode (each ByteCode contains a local
1350 * LiteralTable) and across all an interpreter's ByteCodes (with the
1351 * interpreter's global LiteralTable).
1352 */
1353
1354typedef struct LiteralEntry {
1355    struct LiteralEntry *nextPtr;
1356				/* Points to next entry in this hash bucket or
1357				 * NULL if end of chain. */
1358    Tcl_Obj *objPtr;		/* Points to Tcl object that holds the
1359				 * literal's bytes and length. */
1360    int refCount;		/* If in an interpreter's global literal
1361				 * table, the number of ByteCode structures
1362				 * that share the literal object; the literal
1363				 * entry can be freed when refCount drops to
1364				 * 0. If in a local literal table, -1. */
1365    Namespace *nsPtr;		/* Namespace in which this literal is used. We
1366				 * try to avoid sharing literal non-FQ command
1367				 * names among different namespaces to reduce
1368				 * shimmering. */
1369} LiteralEntry;
1370
1371typedef struct LiteralTable {
1372    LiteralEntry **buckets;	/* Pointer to bucket array. Each element
1373				 * points to first entry in bucket's hash
1374				 * chain, or NULL. */
1375    LiteralEntry *staticBuckets[TCL_SMALL_HASH_TABLE];
1376				/* Bucket array used for small tables to avoid
1377				 * mallocs and frees. */
1378    int numBuckets;		/* Total number of buckets allocated at
1379				 * **buckets. */
1380    int numEntries;		/* Total number of entries present in
1381				 * table. */
1382    int rebuildSize;		/* Enlarge table when numEntries gets to be
1383				 * this large. */
1384    int mask;			/* Mask value used in hashing function. */
1385} LiteralTable;
1386
1387/*
1388 * The following structure defines for each Tcl interpreter various
1389 * statistics-related information about the bytecode compiler and
1390 * interpreter's operation in that interpreter.
1391 */
1392
1393#ifdef TCL_COMPILE_STATS
1394typedef struct ByteCodeStats {
1395    long numExecutions;		/* Number of ByteCodes executed. */
1396    long numCompilations;	/* Number of ByteCodes created. */
1397    long numByteCodesFreed;	/* Number of ByteCodes destroyed. */
1398    long instructionCount[256];	/* Number of times each instruction was
1399				 * executed. */
1400
1401    double totalSrcBytes;	/* Total source bytes ever compiled. */
1402    double totalByteCodeBytes;	/* Total bytes for all ByteCodes. */
1403    double currentSrcBytes;	/* Src bytes for all current ByteCodes. */
1404    double currentByteCodeBytes;/* Code bytes in all current ByteCodes. */
1405
1406    long srcCount[32];		/* Source size distribution: # of srcs of
1407				 * size [2**(n-1)..2**n), n in [0..32). */
1408    long byteCodeCount[32];	/* ByteCode size distribution. */
1409    long lifetimeCount[32];	/* ByteCode lifetime distribution (ms). */
1410
1411    double currentInstBytes;	/* Instruction bytes-current ByteCodes. */
1412    double currentLitBytes;	/* Current literal bytes. */
1413    double currentExceptBytes;	/* Current exception table bytes. */
1414    double currentAuxBytes;	/* Current auxiliary information bytes. */
1415    double currentCmdMapBytes;	/* Current src<->code map bytes. */
1416
1417    long numLiteralsCreated;	/* Total literal objects ever compiled. */
1418    double totalLitStringBytes;	/* Total string bytes in all literals. */
1419    double currentLitStringBytes;
1420				/* String bytes in current literals. */
1421    long literalCount[32];	/* Distribution of literal string sizes. */
1422} ByteCodeStats;
1423#endif /* TCL_COMPILE_STATS */
1424
1425/*
1426 * Structure used in implementation of those core ensembles which are
1427 * partially compiled. Used as an array of these, with a terminating field
1428 * whose 'name' is NULL.
1429 */
1430
1431typedef struct {
1432    const char *name;		/* The name of the subcommand. */
1433    Tcl_ObjCmdProc *proc;	/* The implementation of the subcommand. */
1434    CompileProc *compileProc;	/* The compiler for the subcommand. */
1435} EnsembleImplMap;
1436
1437/*
1438 *----------------------------------------------------------------
1439 * Data structures related to commands.
1440 *----------------------------------------------------------------
1441 */
1442
1443/*
1444 * An imported command is created in an namespace when it imports a "real"
1445 * command from another namespace. An imported command has a Command structure
1446 * that points (via its ClientData value) to the "real" Command structure in
1447 * the source namespace's command table. The real command records all the
1448 * imported commands that refer to it in a list of ImportRef structures so
1449 * that they can be deleted when the real command is deleted.
1450 */
1451
1452typedef struct ImportRef {
1453    struct Command *importedCmdPtr;
1454				/* Points to the imported command created in
1455				 * an importing namespace; this command
1456				 * redirects its invocations to the "real"
1457				 * command. */
1458    struct ImportRef *nextPtr;	/* Next element on the linked list of imported
1459				 * commands that refer to the "real" command.
1460				 * The real command deletes these imported
1461				 * commands on this list when it is
1462				 * deleted. */
1463} ImportRef;
1464
1465/*
1466 * Data structure used as the ClientData of imported commands: commands
1467 * created in an namespace when it imports a "real" command from another
1468 * namespace.
1469 */
1470
1471typedef struct ImportedCmdData {
1472    struct Command *realCmdPtr;	/* "Real" command that this imported command
1473				 * refers to. */
1474    struct Command *selfPtr;	/* Pointer to this imported command. Needed
1475				 * only when deleting it in order to remove it
1476				 * from the real command's linked list of
1477				 * imported commands that refer to it. */
1478} ImportedCmdData;
1479
1480/*
1481 * A Command structure exists for each command in a namespace. The Tcl_Command
1482 * opaque type actually refers to these structures.
1483 */
1484
1485typedef struct Command {
1486    Tcl_HashEntry *hPtr;	/* Pointer to the hash table entry that refers
1487				 * to this command. The hash table is either a
1488				 * namespace's command table or an
1489				 * interpreter's hidden command table. This
1490				 * pointer is used to get a command's name
1491				 * from its Tcl_Command handle. NULL means
1492				 * that the hash table entry has been removed
1493				 * already (this can happen if deleteProc
1494				 * causes the command to be deleted or
1495				 * recreated). */
1496    Namespace *nsPtr;		/* Points to the namespace containing this
1497				 * command. */
1498    int refCount;		/* 1 if in command hashtable plus 1 for each
1499				 * reference from a CmdName Tcl object
1500				 * representing a command's name in a ByteCode
1501				 * instruction sequence. This structure can be
1502				 * freed when refCount becomes zero. */
1503    int cmdEpoch;		/* Incremented to invalidate any references
1504				 * that point to this command when it is
1505				 * renamed, deleted, hidden, or exposed. */
1506    CompileProc *compileProc;	/* Procedure called to compile command. NULL
1507				 * if no compile proc exists for command. */
1508    Tcl_ObjCmdProc *objProc;	/* Object-based command procedure. */
1509    ClientData objClientData;	/* Arbitrary value passed to object proc. */
1510    Tcl_CmdProc *proc;		/* String-based command procedure. */
1511    ClientData clientData;	/* Arbitrary value passed to string proc. */
1512    Tcl_CmdDeleteProc *deleteProc;
1513				/* Procedure invoked when deleting command to,
1514				 * e.g., free all client data. */
1515    ClientData deleteData;	/* Arbitrary value passed to deleteProc. */
1516    int flags;			/* Miscellaneous bits of information about
1517				 * command. See below for definitions. */
1518    ImportRef *importRefPtr;	/* List of each imported Command created in
1519				 * another namespace when this command is
1520				 * imported. These imported commands redirect
1521				 * invocations back to this command. The list
1522				 * is used to remove all those imported
1523				 * commands when deleting this "real"
1524				 * command. */
1525    CommandTrace *tracePtr;	/* First in list of all traces set for this
1526				 * command. */
1527} Command;
1528
1529/*
1530 * Flag bits for commands.
1531 *
1532 * CMD_IS_DELETED -		Means that the command is in the process of
1533 *				being deleted (its deleteProc is currently
1534 *				executing). Other attempts to delete the
1535 *				command should be ignored.
1536 * CMD_TRACE_ACTIVE -		1 means that trace processing is currently
1537 *				underway for a rename/delete change. See the
1538 *				two flags below for which is currently being
1539 *				processed.
1540 * CMD_HAS_EXEC_TRACES -	1 means that this command has at least one
1541 *				execution trace (as opposed to simple
1542 *				delete/rename traces) in its tracePtr list.
1543 * TCL_TRACE_RENAME -		A rename trace is in progress. Further
1544 *				recursive renames will not be traced.
1545 * TCL_TRACE_DELETE -		A delete trace is in progress. Further
1546 *				recursive deletes will not be traced.
1547 * (these last two flags are defined in tcl.h)
1548 */
1549
1550#define CMD_IS_DELETED		    0x1
1551#define CMD_TRACE_ACTIVE	    0x2
1552#define CMD_HAS_EXEC_TRACES	    0x4
1553
1554/*
1555 *----------------------------------------------------------------
1556 * Data structures related to name resolution procedures.
1557 *----------------------------------------------------------------
1558 */
1559
1560/*
1561 * The interpreter keeps a linked list of name resolution schemes. The scheme
1562 * for a namespace is consulted first, followed by the list of schemes in an
1563 * interpreter, followed by the default name resolution in Tcl. Schemes are
1564 * added/removed from the interpreter's list by calling Tcl_AddInterpResolver
1565 * and Tcl_RemoveInterpResolver.
1566 */
1567
1568typedef struct ResolverScheme {
1569    char *name;			/* Name identifying this scheme. */
1570    Tcl_ResolveCmdProc *cmdResProc;
1571				/* Procedure handling command name
1572				 * resolution. */
1573    Tcl_ResolveVarProc *varResProc;
1574				/* Procedure handling variable name resolution
1575				 * for variables that can only be handled at
1576				 * runtime. */
1577    Tcl_ResolveCompiledVarProc *compiledVarResProc;
1578				/* Procedure handling variable name resolution
1579				 * at compile time. */
1580
1581    struct ResolverScheme *nextPtr;
1582				/* Pointer to next record in linked list. */
1583} ResolverScheme;
1584
1585/*
1586 * Forward declaration of the TIP#143 limit handler structure.
1587 */
1588
1589typedef struct LimitHandler LimitHandler;
1590
1591/*
1592 * TIP #268.
1593 * Values for the selection mode, i.e the package require preferences.
1594 */
1595
1596enum PkgPreferOptions {
1597    PKG_PREFER_LATEST, PKG_PREFER_STABLE
1598};
1599
1600/*
1601 *----------------------------------------------------------------
1602 * This structure defines an interpreter, which is a collection of commands
1603 * plus other state information related to interpreting commands, such as
1604 * variable storage. Primary responsibility for this data structure is in
1605 * tclBasic.c, but almost every Tcl source file uses something in here.
1606 *----------------------------------------------------------------
1607 */
1608
1609typedef struct Interp {
1610    /*
1611     * Note: the first three fields must match exactly the fields in a
1612     * Tcl_Interp struct (see tcl.h). If you change one, be sure to change the
1613     * other.
1614     *
1615     * The interpreter's result is held in both the string and the
1616     * objResultPtr fields. These fields hold, respectively, the result's
1617     * string or object value. The interpreter's result is always in the
1618     * result field if that is non-empty, otherwise it is in objResultPtr.
1619     * The two fields are kept consistent unless some C code sets
1620     * interp->result directly. Programs should not access result and
1621     * objResultPtr directly; instead, they should always get and set the
1622     * result using procedures such as Tcl_SetObjResult, Tcl_GetObjResult, and
1623     * Tcl_GetStringResult. See the SetResult man page for details.
1624     */
1625
1626    char *result;		/* If the last command returned a string
1627				 * result, this points to it. Should not be
1628				 * accessed directly; see comment above. */
1629    Tcl_FreeProc *freeProc;	/* Zero means a string result is statically
1630				 * allocated. TCL_DYNAMIC means string result
1631				 * was allocated with ckalloc and should be
1632				 * freed with ckfree. Other values give
1633				 * address of procedure to invoke to free the
1634				 * string result. Tcl_Eval must free it before
1635				 * executing next command. */
1636    int errorLine;		/* When TCL_ERROR is returned, this gives the
1637				 * line number in the command where the error
1638				 * occurred (1 means first line). */
1639    struct TclStubs *stubTable;
1640				/* Pointer to the exported Tcl stub table. On
1641				 * previous versions of Tcl this is a pointer
1642				 * to the objResultPtr or a pointer to a
1643				 * buckets array in a hash table. We therefore
1644				 * have to do some careful checking before we
1645				 * can use this. */
1646
1647    TclHandle handle;		/* Handle used to keep track of when this
1648				 * interp is deleted. */
1649
1650    Namespace *globalNsPtr;	/* The interpreter's global namespace. */
1651    Tcl_HashTable *hiddenCmdTablePtr;
1652				/* Hash table used by tclBasic.c to keep track
1653				 * of hidden commands on a per-interp
1654				 * basis. */
1655    ClientData interpInfo;	/* Information used by tclInterp.c to keep
1656				 * track of master/slave interps on a
1657				 * per-interp basis. */
1658    Tcl_HashTable unused2;	/* No longer used (was mathFuncTable) */
1659
1660    /*
1661     * Information related to procedures and variables. See tclProc.c and
1662     * tclVar.c for usage.
1663     */
1664
1665    int numLevels;		/* Keeps track of how many nested calls to
1666				 * Tcl_Eval are in progress for this
1667				 * interpreter. It's used to delay deletion of
1668				 * the table until all Tcl_Eval invocations
1669				 * are completed. */
1670    int maxNestingDepth;	/* If numLevels exceeds this value then Tcl
1671				 * assumes that infinite recursion has
1672				 * occurred and it generates an error. */
1673    CallFrame *framePtr;	/* Points to top-most in stack of all nested
1674				 * procedure invocations. */
1675    CallFrame *varFramePtr;	/* Points to the call frame whose variables
1676				 * are currently in use (same as framePtr
1677				 * unless an "uplevel" command is
1678				 * executing). */
1679    ActiveVarTrace *activeVarTracePtr;
1680				/* First in list of active traces for interp,
1681				 * or NULL if no active traces. */
1682    int returnCode;		/* [return -code] parameter. */
1683    CallFrame *rootFramePtr;	/* Global frame pointer for this
1684				 * interpreter. */
1685    Namespace *lookupNsPtr;	/* Namespace to use ONLY on the next
1686				 * TCL_EVAL_INVOKE call to Tcl_EvalObjv. */
1687
1688    /*
1689     * Information used by Tcl_AppendResult to keep track of partial results.
1690     * See Tcl_AppendResult code for details.
1691     */
1692
1693    char *appendResult;		/* Storage space for results generated by
1694				 * Tcl_AppendResult. Ckalloc-ed. NULL means
1695				 * not yet allocated. */
1696    int appendAvl;		/* Total amount of space available at
1697				 * partialResult. */
1698    int appendUsed;		/* Number of non-null bytes currently stored
1699				 * at partialResult. */
1700
1701    /*
1702     * Information about packages. Used only in tclPkg.c.
1703     */
1704
1705    Tcl_HashTable packageTable;	/* Describes all of the packages loaded in or
1706				 * available to this interpreter. Keys are
1707				 * package names, values are (Package *)
1708				 * pointers. */
1709    char *packageUnknown;	/* Command to invoke during "package require"
1710				 * commands for packages that aren't described
1711				 * in packageTable. Ckalloc'ed, may be
1712				 * NULL. */
1713    /*
1714     * Miscellaneous information:
1715     */
1716
1717    int cmdCount;		/* Total number of times a command procedure
1718				 * has been called for this interpreter. */
1719    int evalFlags;		/* Flags to control next call to Tcl_Eval.
1720				 * Normally zero, but may be set before
1721				 * calling Tcl_Eval. See below for valid
1722				 * values. */
1723    int unused1;		/* No longer used (was termOffset) */
1724    LiteralTable literalTable;	/* Contains LiteralEntry's describing all Tcl
1725				 * objects holding literals of scripts
1726				 * compiled by the interpreter. Indexed by the
1727				 * string representations of literals. Used to
1728				 * avoid creating duplicate objects. */
1729    int compileEpoch;		/* Holds the current "compilation epoch" for
1730				 * this interpreter. This is incremented to
1731				 * invalidate existing ByteCodes when, e.g., a
1732				 * command with a compile procedure is
1733				 * redefined. */
1734    Proc *compiledProcPtr;	/* If a procedure is being compiled, a pointer
1735				 * to its Proc structure; otherwise, this is
1736				 * NULL. Set by ObjInterpProc in tclProc.c and
1737				 * used by tclCompile.c to process local
1738				 * variables appropriately. */
1739    ResolverScheme *resolverPtr;
1740				/* Linked list of name resolution schemes
1741				 * added to this interpreter. Schemes are
1742				 * added and removed by calling
1743				 * Tcl_AddInterpResolvers and
1744				 * Tcl_RemoveInterpResolver respectively. */
1745    Tcl_Obj *scriptFile;	/* NULL means there is no nested source
1746				 * command active; otherwise this points to
1747				 * pathPtr of the file being sourced. */
1748    int flags;			/* Various flag bits. See below. */
1749    long randSeed;		/* Seed used for rand() function. */
1750    Trace *tracePtr;		/* List of traces for this interpreter. */
1751    Tcl_HashTable *assocData;	/* Hash table for associating data with this
1752				 * interpreter. Cleaned up when this
1753				 * interpreter is deleted. */
1754    struct ExecEnv *execEnvPtr;	/* Execution environment for Tcl bytecode
1755				 * execution. Contains a pointer to the Tcl
1756				 * evaluation stack. */
1757    Tcl_Obj *emptyObjPtr;	/* Points to an object holding an empty
1758				 * string. Returned by Tcl_ObjSetVar2 when
1759				 * variable traces change a variable in a
1760				 * gross way. */
1761    char resultSpace[TCL_RESULT_SIZE+1];
1762				/* Static space holding small results. */
1763    Tcl_Obj *objResultPtr;	/* If the last command returned an object
1764				 * result, this points to it. Should not be
1765				 * accessed directly; see comment above. */
1766    Tcl_ThreadId threadId;	/* ID of thread that owns the interpreter. */
1767
1768    ActiveCommandTrace *activeCmdTracePtr;
1769				/* First in list of active command traces for
1770				 * interp, or NULL if no active traces. */
1771    ActiveInterpTrace *activeInterpTracePtr;
1772				/* First in list of active traces for interp,
1773				 * or NULL if no active traces. */
1774
1775    int tracesForbiddingInline;	/* Count of traces (in the list headed by
1776				 * tracePtr) that forbid inline bytecode
1777				 * compilation. */
1778
1779    /*
1780     * Fields used to manage extensible return options (TIP 90).
1781     */
1782
1783    Tcl_Obj *returnOpts;	/* A dictionary holding the options to the
1784				 * last [return] command. */
1785
1786    Tcl_Obj *errorInfo;		/* errorInfo value (now as a Tcl_Obj). */
1787    Tcl_Obj *eiVar;		/* cached ref to ::errorInfo variable. */
1788    Tcl_Obj *errorCode;		/* errorCode value (now as a Tcl_Obj). */
1789    Tcl_Obj *ecVar;		/* cached ref to ::errorInfo variable. */
1790    int returnLevel;		/* [return -level] parameter. */
1791
1792    /*
1793     * Resource limiting framework support (TIP#143).
1794     */
1795
1796    struct {
1797	int active;		/* Flag values defining which limits have been
1798				 * set. */
1799	int granularityTicker;	/* Counter used to determine how often to
1800				 * check the limits. */
1801	int exceeded;		/* Which limits have been exceeded, described
1802				 * as flag values the same as the 'active'
1803				 * field. */
1804
1805	int cmdCount;		/* Limit for how many commands to execute in
1806				 * the interpreter. */
1807	LimitHandler *cmdHandlers;
1808				/* Handlers to execute when the limit is
1809				 * reached. */
1810	int cmdGranularity;	/* Mod factor used to determine how often to
1811				 * evaluate the limit check. */
1812
1813	Tcl_Time time;		/* Time limit for execution within the
1814				 * interpreter. */
1815	LimitHandler *timeHandlers;
1816				/* Handlers to execute when the limit is
1817				 * reached. */
1818	int timeGranularity;	/* Mod factor used to determine how often to
1819				 * evaluate the limit check. */
1820	Tcl_TimerToken timeEvent;
1821				/* Handle for a timer callback that will occur
1822				 * when the time-limit is exceeded. */
1823
1824	Tcl_HashTable callbacks;/* Mapping from (interp,type) pair to data
1825				 * used to install a limit handler callback to
1826				 * run in _this_ interp when the limit is
1827				 * exceeded. */
1828    } limit;
1829
1830    /*
1831     * Information for improved default error generation from ensembles
1832     * (TIP#112).
1833     */
1834
1835    struct {
1836	Tcl_Obj *const *sourceObjs;
1837				/* What arguments were actually input into the
1838				 * *root* ensemble command? (Nested ensembles
1839				 * don't rewrite this.) NULL if we're not
1840				 * processing an ensemble. */
1841	int numRemovedObjs;	/* How many arguments have been stripped off
1842				 * because of ensemble processing. */
1843	int numInsertedObjs;	/* How many of the current arguments were
1844				 * inserted by an ensemble. */
1845    } ensembleRewrite;
1846
1847    /*
1848     * TIP #219: Global info for the I/O system.
1849     */
1850
1851    Tcl_Obj *chanMsg;		/* Error message set by channel drivers, for
1852				 * the propagation of arbitrary Tcl errors.
1853				 * This information, if present (chanMsg not
1854				 * NULL), takes precedence over a POSIX error
1855				 * code returned by a channel operation. */
1856
1857    /*
1858     * Source code origin information (TIP #280).
1859     */
1860
1861    CmdFrame *cmdFramePtr;	/* Points to the command frame containing the
1862				 * location information for the current
1863				 * command. */
1864    const CmdFrame *invokeCmdFramePtr;
1865				/* Points to the command frame which is the
1866				 * invoking context of the bytecode compiler.
1867				 * NULL when the byte code compiler is not
1868				 * active. */
1869    int invokeWord;		/* Index of the word in the command which
1870				 * is getting compiled. */
1871    Tcl_HashTable *linePBodyPtr;/* This table remembers for each statically
1872				 * defined procedure the location information
1873				 * for its body. It is keyed by the address of
1874				 * the Proc structure for a procedure. The
1875				 * values are "struct CmdFrame*". */
1876    Tcl_HashTable *lineBCPtr;	/* This table remembers for each ByteCode
1877				 * object the location information for its
1878				 * body. It is keyed by the address of the
1879				 * Proc structure for a procedure. The values
1880				 * are "struct ExtCmdLoc*". (See
1881				 * tclCompile.h) */
1882    Tcl_HashTable *lineLABCPtr;
1883    Tcl_HashTable *lineLAPtr;	/* This table remembers for each argument of a
1884				 * command on the execution stack the index of
1885				 * the argument in the command, and the
1886				 * location data of the command. It is keyed
1887				 * by the address of the Tcl_Obj containing
1888				 * the argument. The values are "struct
1889				 * CFWord*" (See tclBasic.c). This allows
1890				 * commands like uplevel, eval, etc. to find
1891				 * location information for their arguments,
1892				 * if they are a proper literal argument to an
1893				 * invoking command. Alt view: An index to the
1894				 * CmdFrame stack keyed by command argument
1895				 * holders. */
1896    ContLineLoc *scriptCLLocPtr;/* This table points to the location data for
1897				 * invisible continuation lines in the script,
1898				 * if any. This pointer is set by the function
1899				 * TclEvalObjEx() in file "tclBasic.c", and
1900				 * used by function ...() in the same file.
1901				 * It does for the eval/direct path of script
1902				 * execution what CompileEnv.clLoc does for
1903				 * the bytecode compiler.
1904				 */
1905    /*
1906     * TIP #268. The currently active selection mode, i.e. the package require
1907     * preferences.
1908     */
1909
1910    int packagePrefer;		/* Current package selection mode. */
1911
1912    /*
1913     * Hashtables for variable traces and searches.
1914     */
1915
1916    Tcl_HashTable varTraces;	/* Hashtable holding the start of a variable's
1917				 * active trace list; varPtr is the key. */
1918    Tcl_HashTable varSearches;	/* Hashtable holding the start of a variable's
1919				 * active searches list; varPtr is the key. */
1920    /*
1921     * The thread-specific data ekeko: cache pointers or values that
1922     *  (a) do not change during the thread's lifetime
1923     *  (b) require access to TSD to determine at runtime
1924     *  (c) are accessed very often (e.g., at each command call)
1925     *
1926     * Note that these are the same for all interps in the same thread. They
1927     * just have to be initialised for the thread's master interp, slaves
1928     * inherit the value.
1929     *
1930     * They are used by the macros defined below.
1931     */
1932
1933    void *allocCache;
1934    void *pendingObjDataPtr;	/* Pointer to the Cache and PendingObjData
1935				 * structs for this interp's thread; see
1936				 * tclObj.c and tclThreadAlloc.c */
1937    int *asyncReadyPtr;		/* Pointer to the asyncReady indicator for
1938				 * this interp's thread; see tclAsync.c */
1939    int *stackBound;		/* Pointer to the limit stack address
1940				 * allowable for invoking a new command
1941				 * without "risking" a C-stack overflow; see
1942				 * TclpCheckStackSpace in the platform's
1943				 * directory. */
1944
1945
1946#ifdef TCL_COMPILE_STATS
1947    /*
1948     * Statistical information about the bytecode compiler and interpreter's
1949     * operation.
1950     */
1951
1952    ByteCodeStats stats;	/* Holds compilation and execution statistics
1953				 * for this interpreter. */
1954#endif /* TCL_COMPILE_STATS */
1955} Interp;
1956
1957/*
1958 * Macros that use the TSD-ekeko.
1959 */
1960
1961#define TclAsyncReady(iPtr) \
1962    *((iPtr)->asyncReadyPtr)
1963
1964/*
1965 * General list of interpreters. Doubly linked for easier removal of items
1966 * deep in the list.
1967 */
1968
1969typedef struct InterpList {
1970    Interp *interpPtr;
1971    struct InterpList *prevPtr;
1972    struct InterpList *nextPtr;
1973} InterpList;
1974
1975/*
1976 * Macros for splicing into and out of doubly linked lists. They assume
1977 * existence of struct items 'prevPtr' and 'nextPtr'.
1978 *
1979 * a = element to add or remove.
1980 * b = list head.
1981 *
1982 * TclSpliceIn adds to the head of the list.
1983 */
1984
1985#define TclSpliceIn(a,b)			\
1986    (a)->nextPtr = (b);				\
1987    if ((b) != NULL) {				\
1988	(b)->prevPtr = (a);			\
1989    }						\
1990    (a)->prevPtr = NULL, (b) = (a);
1991
1992#define TclSpliceOut(a,b)			\
1993    if ((a)->prevPtr != NULL) {			\
1994	(a)->prevPtr->nextPtr = (a)->nextPtr;	\
1995    } else {					\
1996	(b) = (a)->nextPtr;			\
1997    }						\
1998    if ((a)->nextPtr != NULL) {			\
1999	(a)->nextPtr->prevPtr = (a)->prevPtr;	\
2000    }
2001
2002/*
2003 * EvalFlag bits for Interp structures:
2004 *
2005 * TCL_ALLOW_EXCEPTIONS	1 means it's OK for the script to terminate with a
2006 *			code other than TCL_OK or TCL_ERROR; 0 means codes
2007 *			other than these should be turned into errors.
2008 */
2009
2010#define TCL_ALLOW_EXCEPTIONS	4
2011#define TCL_EVAL_FILE		2
2012#define TCL_EVAL_CTX		8
2013
2014/*
2015 * Flag bits for Interp structures:
2016 *
2017 * DELETED:		Non-zero means the interpreter has been deleted:
2018 *			don't process any more commands for it, and destroy
2019 *			the structure as soon as all nested invocations of
2020 *			Tcl_Eval are done.
2021 * ERR_ALREADY_LOGGED:	Non-zero means information has already been logged in
2022 *			iPtr->errorInfo for the current Tcl_Eval instance, so
2023 *			Tcl_Eval needn't log it (used to implement the "error
2024 *			message log" command).
2025 * DONT_COMPILE_CMDS_INLINE: Non-zero means that the bytecode compiler should
2026 *			not compile any commands into an inline sequence of
2027 *			instructions. This is set 1, for example, when command
2028 *			traces are requested.
2029 * RAND_SEED_INITIALIZED: Non-zero means that the randSeed value of the interp
2030 *			has not be initialized. This is set 1 when we first
2031 *			use the rand() or srand() functions.
2032 * SAFE_INTERP:		Non zero means that the current interp is a safe
2033 *			interp (i.e. it has only the safe commands installed,
2034 *			less priviledge than a regular interp).
2035 * INTERP_TRACE_IN_PROGRESS: Non-zero means that an interp trace is currently
2036 *			active; so no further trace callbacks should be
2037 *			invoked.
2038 * INTERP_ALTERNATE_WRONG_ARGS: Used for listing second and subsequent forms
2039 *			of the wrong-num-args string in Tcl_WrongNumArgs.
2040 *			Makes it append instead of replacing and uses
2041 *			different intermediate text.
2042 *
2043 * WARNING: For the sake of some extensions that have made use of former
2044 * internal values, do not re-use the flag values 2 (formerly ERR_IN_PROGRESS)
2045 * or 8 (formerly ERROR_CODE_SET).
2046 */
2047
2048#define DELETED				     1
2049#define ERR_ALREADY_LOGGED		     4
2050#define DONT_COMPILE_CMDS_INLINE	  0x20
2051#define RAND_SEED_INITIALIZED		  0x40
2052#define SAFE_INTERP			  0x80
2053#define INTERP_TRACE_IN_PROGRESS	 0x200
2054#define INTERP_ALTERNATE_WRONG_ARGS	 0x400
2055#define ERR_LEGACY_COPY			 0x800
2056
2057/*
2058 * Maximum number of levels of nesting permitted in Tcl commands (used to
2059 * catch infinite recursion).
2060 */
2061
2062#define MAX_NESTING_DEPTH	1000
2063
2064/*
2065 * TIP#143 limit handler internal representation.
2066 */
2067
2068struct LimitHandler {
2069    int flags;			/* The state of this particular handler. */
2070    Tcl_LimitHandlerProc *handlerProc;
2071				/* The handler callback. */
2072    ClientData clientData;	/* Opaque argument to the handler callback. */
2073    Tcl_LimitHandlerDeleteProc *deleteProc;
2074				/* How to delete the clientData. */
2075    LimitHandler *prevPtr;	/* Previous item in linked list of
2076				 * handlers. */
2077    LimitHandler *nextPtr;	/* Next item in linked list of handlers. */
2078};
2079
2080/*
2081 * Values for the LimitHandler flags field.
2082 *	LIMIT_HANDLER_ACTIVE - Whether the handler is currently being
2083 *		processed; handlers are never to be entered reentrantly.
2084 *	LIMIT_HANDLER_DELETED - Whether the handler has been deleted. This
2085 *		should not normally be observed because when a handler is
2086 *		deleted it is also spliced out of the list of handlers, but
2087 *		even so we will be careful.
2088 */
2089
2090#define LIMIT_HANDLER_ACTIVE	0x01
2091#define LIMIT_HANDLER_DELETED	0x02
2092
2093/*
2094 * The macro below is used to modify a "char" value (e.g. by casting it to an
2095 * unsigned character) so that it can be used safely with macros such as
2096 * isspace.
2097 */
2098
2099#define UCHAR(c) ((unsigned char) (c))
2100
2101/*
2102 * This macro is used to properly align the memory allocated by Tcl, giving
2103 * the same alignment as the native malloc.
2104 */
2105
2106#if defined(__APPLE__)
2107#define TCL_ALLOCALIGN	16
2108#else
2109#define TCL_ALLOCALIGN	(2*sizeof(void *))
2110#endif
2111
2112/*
2113 * This macro is used to determine the offset needed to safely allocate any
2114 * data structure in memory. Given a starting offset or size, it "rounds up"
2115 * or "aligns" the offset to the next 8-byte boundary so that any data
2116 * structure can be placed at the resulting offset without fear of an
2117 * alignment error.
2118 *
2119 * WARNING!! DO NOT USE THIS MACRO TO ALIGN POINTERS: it will produce the
2120 * wrong result on platforms that allocate addresses that are divisible by 4
2121 * or 2. Only use it for offsets or sizes.
2122 *
2123 * This macro is only used by tclCompile.c in the core (Bug 926445). It
2124 * however not be made file static, as extensions that touch bytecodes
2125 * (notably tbcload) require it.
2126 */
2127
2128#define TCL_ALIGN(x) (((int)(x) + 7) & ~7)
2129
2130/*
2131 * The following enum values are used to specify the runtime platform setting
2132 * of the tclPlatform variable.
2133 */
2134
2135typedef enum {
2136    TCL_PLATFORM_UNIX = 0,	/* Any Unix-like OS. */
2137    TCL_PLATFORM_WINDOWS = 2	/* Any Microsoft Windows OS. */
2138} TclPlatformType;
2139
2140/*
2141 * The following enum values are used to indicate the translation of a Tcl
2142 * channel. Declared here so that each platform can define
2143 * TCL_PLATFORM_TRANSLATION to the native translation on that platform.
2144 */
2145
2146typedef enum TclEolTranslation {
2147    TCL_TRANSLATE_AUTO,		/* Eol == \r, \n and \r\n. */
2148    TCL_TRANSLATE_CR,		/* Eol == \r. */
2149    TCL_TRANSLATE_LF,		/* Eol == \n. */
2150    TCL_TRANSLATE_CRLF		/* Eol == \r\n. */
2151} TclEolTranslation;
2152
2153/*
2154 * Flags for TclInvoke:
2155 *
2156 * TCL_INVOKE_HIDDEN		Invoke a hidden command; if not set, invokes
2157 *				an exposed command.
2158 * TCL_INVOKE_NO_UNKNOWN	If set, "unknown" is not invoked if the
2159 *				command to be invoked is not found. Only has
2160 *				an effect if invoking an exposed command,
2161 *				i.e. if TCL_INVOKE_HIDDEN is not also set.
2162 * TCL_INVOKE_NO_TRACEBACK	Does not record traceback information if the
2163 *				invoked command returns an error. Used if the
2164 *				caller plans on recording its own traceback
2165 *				information.
2166 */
2167
2168#define	TCL_INVOKE_HIDDEN	(1<<0)
2169#define TCL_INVOKE_NO_UNKNOWN	(1<<1)
2170#define TCL_INVOKE_NO_TRACEBACK	(1<<2)
2171
2172/*
2173 * The structure used as the internal representation of Tcl list objects. This
2174 * struct is grown (reallocated and copied) as necessary to hold all the
2175 * list's element pointers. The struct might contain more slots than currently
2176 * used to hold all element pointers. This is done to make append operations
2177 * faster.
2178 */
2179
2180typedef struct List {
2181    int refCount;
2182    int maxElemCount;		/* Total number of element array slots. */
2183    int elemCount;		/* Current number of list elements. */
2184    int canonicalFlag;		/* Set if the string representation was
2185				 * derived from the list representation. May
2186				 * be ignored if there is no string rep at
2187				 * all.*/
2188    Tcl_Obj *elements;		/* First list element; the struct is grown to
2189				 * accomodate all elements. */
2190} List;
2191
2192/*
2193 * Macro used to get the elements of a list object.
2194 */
2195
2196#define ListRepPtr(listPtr) \
2197    ((List *) (listPtr)->internalRep.twoPtrValue.ptr1)
2198
2199#define ListObjGetElements(listPtr, objc, objv) \
2200    ((objv) = &(ListRepPtr(listPtr)->elements), \
2201     (objc) = ListRepPtr(listPtr)->elemCount)
2202
2203#define ListObjLength(listPtr, len) \
2204    ((len) = ListRepPtr(listPtr)->elemCount)
2205
2206#define TclListObjGetElements(interp, listPtr, objcPtr, objvPtr) \
2207    (((listPtr)->typePtr == &tclListType) \
2208	    ? ((ListObjGetElements((listPtr), *(objcPtr), *(objvPtr))), TCL_OK)\
2209	    : Tcl_ListObjGetElements((interp), (listPtr), (objcPtr), (objvPtr)))
2210
2211#define TclListObjLength(interp, listPtr, lenPtr) \
2212    (((listPtr)->typePtr == &tclListType) \
2213	    ? ((ListObjLength((listPtr), *(lenPtr))), TCL_OK)\
2214	    : Tcl_ListObjLength((interp), (listPtr), (lenPtr)))
2215
2216/*
2217 * Macros providing a faster path to integers: Tcl_GetLongFromObj everywhere,
2218 * Tcl_GetIntFromObj and TclGetIntForIndex on platforms where longs are ints.
2219 *
2220 * WARNING: these macros eval their args more than once.
2221 */
2222
2223#define TclGetLongFromObj(interp, objPtr, longPtr) \
2224    (((objPtr)->typePtr == &tclIntType)	\
2225	    ? ((*(longPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2226	    : Tcl_GetLongFromObj((interp), (objPtr), (longPtr)))
2227
2228#if (LONG_MAX == INT_MAX)
2229#define TclGetIntFromObj(interp, objPtr, intPtr) \
2230    (((objPtr)->typePtr == &tclIntType)	\
2231	    ? ((*(intPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2232	    : Tcl_GetIntFromObj((interp), (objPtr), (intPtr)))
2233#define TclGetIntForIndexM(interp, objPtr, endValue, idxPtr) \
2234    (((objPtr)->typePtr == &tclIntType)	\
2235	    ? ((*(idxPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
2236	    : TclGetIntForIndex((interp), (objPtr), (endValue), (idxPtr)))
2237#else
2238#define TclGetIntFromObj(interp, objPtr, intPtr) \
2239    Tcl_GetIntFromObj((interp), (objPtr), (intPtr))
2240#define TclGetIntForIndexM(interp, objPtr, ignore, idxPtr)	\
2241    TclGetIntForIndex(interp, objPtr, ignore, idxPtr)
2242#endif
2243
2244/*
2245 * Flag values for TclTraceDictPath().
2246 *
2247 * DICT_PATH_READ indicates that all entries on the path must exist but no
2248 * updates will be needed.
2249 *
2250 * DICT_PATH_UPDATE indicates that we are going to be doing an update at the
2251 * tip of the path, so duplication of shared objects should be done along the
2252 * way.
2253 *
2254 * DICT_PATH_EXISTS indicates that we are performing an existance test and a
2255 * lookup failure should therefore not be an error. If (and only if) this flag
2256 * is set, TclTraceDictPath() will return the special value
2257 * DICT_PATH_NON_EXISTENT if the path is not traceable.
2258 *
2259 * DICT_PATH_CREATE (which also requires the DICT_PATH_UPDATE bit to be set)
2260 * indicates that we are to create non-existant dictionaries on the path.
2261 */
2262
2263#define DICT_PATH_READ		0
2264#define DICT_PATH_UPDATE	1
2265#define DICT_PATH_EXISTS	2
2266#define DICT_PATH_CREATE	5
2267
2268#define DICT_PATH_NON_EXISTENT	((Tcl_Obj *) (void *) 1)
2269
2270/*
2271 *----------------------------------------------------------------
2272 * Data structures related to the filesystem internals
2273 *----------------------------------------------------------------
2274 */
2275
2276/*
2277 * The version_2 filesystem is private to Tcl. As and when these changes have
2278 * been thoroughly tested and investigated a new public filesystem interface
2279 * will be released. The aim is more versatile virtual filesystem interfaces,
2280 * more efficiency in 'path' manipulation and usage, and cleaner filesystem
2281 * code internally.
2282 */
2283
2284#define TCL_FILESYSTEM_VERSION_2	((Tcl_FSVersion) 0x2)
2285typedef ClientData (TclFSGetCwdProc2)(ClientData clientData);
2286
2287/*
2288 * The following types are used for getting and storing platform-specific file
2289 * attributes in tclFCmd.c and the various platform-versions of that file.
2290 * This is done to have as much common code as possible in the file attributes
2291 * code. For more information about the callbacks, see TclFileAttrsCmd in
2292 * tclFCmd.c.
2293 */
2294
2295typedef int (TclGetFileAttrProc)(Tcl_Interp *interp, int objIndex,
2296	Tcl_Obj *fileName, Tcl_Obj **attrObjPtrPtr);
2297typedef int (TclSetFileAttrProc)(Tcl_Interp *interp, int objIndex,
2298	Tcl_Obj *fileName, Tcl_Obj *attrObjPtr);
2299
2300typedef struct TclFileAttrProcs {
2301    TclGetFileAttrProc *getProc;/* The procedure for getting attrs. */
2302    TclSetFileAttrProc *setProc;/* The procedure for setting attrs. */
2303} TclFileAttrProcs;
2304
2305/*
2306 * Opaque handle used in pipeline routines to encapsulate platform-dependent
2307 * state.
2308 */
2309
2310typedef struct TclFile_ *TclFile;
2311
2312/*
2313 * The "globParameters" argument of the function TclGlob is an or'ed
2314 * combination of the following values:
2315 */
2316
2317#define TCL_GLOBMODE_NO_COMPLAIN	1
2318#define TCL_GLOBMODE_JOIN		2
2319#define TCL_GLOBMODE_DIR		4
2320#define TCL_GLOBMODE_TAILS		8
2321
2322typedef enum Tcl_PathPart {
2323    TCL_PATH_DIRNAME,
2324    TCL_PATH_TAIL,
2325    TCL_PATH_EXTENSION,
2326    TCL_PATH_ROOT
2327} Tcl_PathPart;
2328
2329/*
2330 *----------------------------------------------------------------
2331 * Data structures related to obsolete filesystem hooks
2332 *----------------------------------------------------------------
2333 */
2334
2335typedef int (TclStatProc_)(CONST char *path, struct stat *buf);
2336typedef int (TclAccessProc_)(CONST char *path, int mode);
2337typedef Tcl_Channel (TclOpenFileChannelProc_)(Tcl_Interp *interp,
2338	CONST char *fileName, CONST char *modeString, int permissions);
2339
2340/*
2341 *----------------------------------------------------------------
2342 * Data structures related to procedures
2343 *----------------------------------------------------------------
2344 */
2345
2346typedef Tcl_CmdProc *TclCmdProcType;
2347typedef Tcl_ObjCmdProc *TclObjCmdProcType;
2348
2349/*
2350 *----------------------------------------------------------------
2351 * Data structures for process-global values.
2352 *----------------------------------------------------------------
2353 */
2354
2355typedef void (TclInitProcessGlobalValueProc)(char **valuePtr, int *lengthPtr,
2356	Tcl_Encoding *encodingPtr);
2357
2358/*
2359 * A ProcessGlobalValue struct exists for each internal value in Tcl that is
2360 * to be shared among several threads. Each thread sees a (Tcl_Obj) copy of
2361 * the value, and the master is kept as a counted string, with epoch and mutex
2362 * control. Each ProcessGlobalValue struct should be a static variable in some
2363 * file.
2364 */
2365
2366typedef struct ProcessGlobalValue {
2367    int epoch;			/* Epoch counter to detect changes in the
2368				 * master value. */
2369    int numBytes;		/* Length of the master string. */
2370    char *value;		/* The master string value. */
2371    Tcl_Encoding encoding;	/* system encoding when master string was
2372				 * initialized. */
2373    TclInitProcessGlobalValueProc *proc;
2374    				/* A procedure to initialize the master string
2375				 * copy when a "get" request comes in before
2376				 * any "set" request has been received. */
2377    Tcl_Mutex mutex;		/* Enforce orderly access from multiple
2378				 * threads. */
2379    Tcl_ThreadDataKey key;	/* Key for per-thread data holding the
2380				 * (Tcl_Obj) copy for each thread. */
2381} ProcessGlobalValue;
2382
2383/*
2384 *----------------------------------------------------------------------
2385 * Flags for TclParseNumber
2386 *----------------------------------------------------------------------
2387 */
2388
2389#define TCL_PARSE_DECIMAL_ONLY		1
2390				/* Leading zero doesn't denote octal or
2391				 * hex. */
2392#define TCL_PARSE_OCTAL_ONLY		2
2393				/* Parse octal even without prefix. */
2394#define TCL_PARSE_HEXADECIMAL_ONLY	4
2395				/* Parse hexadecimal even without prefix. */
2396#define TCL_PARSE_INTEGER_ONLY		8
2397				/* Disable floating point parsing. */
2398#define TCL_PARSE_SCAN_PREFIXES		16
2399				/* Use [scan] rules dealing with 0?
2400				 * prefixes. */
2401#define TCL_PARSE_NO_WHITESPACE		32
2402				/* Reject leading/trailing whitespace. */
2403
2404/*
2405 *----------------------------------------------------------------------
2406 * Type values TclGetNumberFromObj
2407 *----------------------------------------------------------------------
2408 */
2409
2410#define TCL_NUMBER_LONG		1
2411#define TCL_NUMBER_WIDE		2
2412#define TCL_NUMBER_BIG		3
2413#define TCL_NUMBER_DOUBLE	4
2414#define TCL_NUMBER_NAN		5
2415
2416/*
2417 *----------------------------------------------------------------
2418 * Variables shared among Tcl modules but not used by the outside world.
2419 *----------------------------------------------------------------
2420 */
2421
2422MODULE_SCOPE char *tclNativeExecutableName;
2423MODULE_SCOPE int tclFindExecutableSearchDone;
2424MODULE_SCOPE char *tclMemDumpFileName;
2425MODULE_SCOPE TclPlatformType tclPlatform;
2426MODULE_SCOPE Tcl_NotifierProcs tclOriginalNotifier;
2427
2428/*
2429 * TIP #233 (Virtualized Time)
2430 * Data for the time hooks, if any.
2431 */
2432
2433MODULE_SCOPE Tcl_GetTimeProc *tclGetTimeProcPtr;
2434MODULE_SCOPE Tcl_ScaleTimeProc *tclScaleTimeProcPtr;
2435MODULE_SCOPE ClientData tclTimeClientData;
2436
2437/*
2438 * Variables denoting the Tcl object types defined in the core.
2439 */
2440
2441MODULE_SCOPE Tcl_ObjType tclBignumType;
2442MODULE_SCOPE Tcl_ObjType tclBooleanType;
2443MODULE_SCOPE Tcl_ObjType tclByteArrayType;
2444MODULE_SCOPE Tcl_ObjType tclByteCodeType;
2445MODULE_SCOPE Tcl_ObjType tclDoubleType;
2446MODULE_SCOPE Tcl_ObjType tclEndOffsetType;
2447MODULE_SCOPE Tcl_ObjType tclIntType;
2448MODULE_SCOPE Tcl_ObjType tclListType;
2449MODULE_SCOPE Tcl_ObjType tclDictType;
2450MODULE_SCOPE Tcl_ObjType tclProcBodyType;
2451MODULE_SCOPE Tcl_ObjType tclStringType;
2452MODULE_SCOPE Tcl_ObjType tclArraySearchType;
2453MODULE_SCOPE Tcl_ObjType tclEnsembleCmdType;
2454#ifndef NO_WIDE_TYPE
2455MODULE_SCOPE Tcl_ObjType tclWideIntType;
2456#endif
2457MODULE_SCOPE Tcl_ObjType tclRegexpType;
2458
2459/*
2460 * Variables denoting the hash key types defined in the core.
2461 */
2462
2463MODULE_SCOPE Tcl_HashKeyType tclArrayHashKeyType;
2464MODULE_SCOPE Tcl_HashKeyType tclOneWordHashKeyType;
2465MODULE_SCOPE Tcl_HashKeyType tclStringHashKeyType;
2466MODULE_SCOPE Tcl_HashKeyType tclObjHashKeyType;
2467
2468/*
2469 * The head of the list of free Tcl objects, and the total number of Tcl
2470 * objects ever allocated and freed.
2471 */
2472
2473MODULE_SCOPE Tcl_Obj *	tclFreeObjList;
2474
2475#ifdef TCL_COMPILE_STATS
2476MODULE_SCOPE long	tclObjsAlloced;
2477MODULE_SCOPE long	tclObjsFreed;
2478#define TCL_MAX_SHARED_OBJ_STATS 5
2479MODULE_SCOPE long	tclObjsShared[TCL_MAX_SHARED_OBJ_STATS];
2480#endif /* TCL_COMPILE_STATS */
2481
2482/*
2483 * Pointer to a heap-allocated string of length zero that the Tcl core uses as
2484 * the value of an empty string representation for an object. This value is
2485 * shared by all new objects allocated by Tcl_NewObj.
2486 */
2487
2488MODULE_SCOPE char *	tclEmptyStringRep;
2489MODULE_SCOPE char	tclEmptyString;
2490
2491/*
2492 *----------------------------------------------------------------
2493 * Procedures shared among Tcl modules but not used by the outside world:
2494 *----------------------------------------------------------------
2495 */
2496
2497MODULE_SCOPE void       TclAdvanceContinuations(int* line, int** next, int loc);
2498MODULE_SCOPE void       TclAdvanceLines(int *line, const char *start,
2499			    const char *end);
2500MODULE_SCOPE void       TclArgumentEnter(Tcl_Interp* interp,
2501			    Tcl_Obj* objv[], int objc, CmdFrame* cf);
2502MODULE_SCOPE void       TclArgumentRelease(Tcl_Interp* interp,
2503			    Tcl_Obj* objv[], int objc);
2504MODULE_SCOPE void       TclArgumentGet(Tcl_Interp* interp, Tcl_Obj* obj,
2505			    CmdFrame **cfPtrPtr, int *wordPtr);
2506MODULE_SCOPE void       TclArgumentBCEnter(Tcl_Interp *interp,
2507			    Tcl_Obj* objv[], int objc,
2508			    void *codePtr, CmdFrame *cfPtr, int pc);
2509MODULE_SCOPE void       TclArgumentBCRelease(Tcl_Interp *interp,
2510			    Tcl_Obj *objv[], int objc,
2511			    void *codePtr, int pc);
2512MODULE_SCOPE int	TclArraySet(Tcl_Interp *interp,
2513			    Tcl_Obj *arrayNameObj, Tcl_Obj *arrayElemObj);
2514MODULE_SCOPE double	TclBignumToDouble(mp_int *bignum);
2515MODULE_SCOPE int	TclByteArrayMatch(const unsigned char *string,
2516			    int strLen, const unsigned char *pattern,
2517			    int ptnLen, int flags);
2518MODULE_SCOPE double	TclCeil(mp_int *a);
2519MODULE_SCOPE int	TclCheckBadOctal(Tcl_Interp *interp, const char *value);
2520MODULE_SCOPE int	TclChanCaughtErrorBypass(Tcl_Interp *interp,
2521			    Tcl_Channel chan);
2522MODULE_SCOPE void	TclCleanupLiteralTable(Tcl_Interp *interp,
2523			    LiteralTable *tablePtr);
2524MODULE_SCOPE ContLineLoc* TclContinuationsEnter(Tcl_Obj *objPtr, int num,
2525			    int *loc);
2526MODULE_SCOPE void	TclContinuationsEnterDerived(Tcl_Obj *objPtr,
2527			    int start, int *clNext);
2528MODULE_SCOPE ContLineLoc* TclContinuationsGet(Tcl_Obj *objPtr);
2529MODULE_SCOPE void	TclContinuationsCopy(Tcl_Obj *objPtr,
2530			    Tcl_Obj *originObjPtr);
2531MODULE_SCOPE int	TclDoubleDigits(char *buf, double value, int *signum);
2532MODULE_SCOPE void	TclDeleteNamespaceVars(Namespace *nsPtr);
2533/* TIP #280 - Modified token based evulation, with line information. */
2534MODULE_SCOPE int	TclEvalEx(Tcl_Interp *interp, const char *script,
2535			    int numBytes, int flags, int line,
2536			    int *clNextOuter, CONST char *outerScript);
2537MODULE_SCOPE int	TclFileAttrsCmd(Tcl_Interp *interp,
2538			    int objc, Tcl_Obj *const objv[]);
2539MODULE_SCOPE int	TclFileCopyCmd(Tcl_Interp *interp,
2540			    int objc, Tcl_Obj *const objv[]);
2541MODULE_SCOPE int	TclFileDeleteCmd(Tcl_Interp *interp,
2542			    int objc, Tcl_Obj *const objv[]);
2543MODULE_SCOPE int	TclFileMakeDirsCmd(Tcl_Interp *interp,
2544			    int objc, Tcl_Obj *const objv[]);
2545MODULE_SCOPE int	TclFileRenameCmd(Tcl_Interp *interp,
2546			    int objc, Tcl_Obj *const objv[]);
2547MODULE_SCOPE void	TclCreateLateExitHandler(Tcl_ExitProc *proc,
2548			    ClientData clientData);
2549MODULE_SCOPE void	TclDeleteLateExitHandler(Tcl_ExitProc *proc,
2550			    ClientData clientData);
2551MODULE_SCOPE void	TclFinalizeAllocSubsystem(void);
2552MODULE_SCOPE void	TclFinalizeAsync(void);
2553MODULE_SCOPE void	TclFinalizeDoubleConversion(void);
2554MODULE_SCOPE void	TclFinalizeEncodingSubsystem(void);
2555MODULE_SCOPE void	TclFinalizeEnvironment(void);
2556MODULE_SCOPE void	TclFinalizeExecution(void);
2557MODULE_SCOPE void	TclFinalizeIOSubsystem(void);
2558MODULE_SCOPE void	TclFinalizeFilesystem(void);
2559MODULE_SCOPE void	TclResetFilesystem(void);
2560MODULE_SCOPE void	TclFinalizeLoad(void);
2561MODULE_SCOPE void	TclFinalizeLock(void);
2562MODULE_SCOPE void	TclFinalizeMemorySubsystem(void);
2563MODULE_SCOPE void	TclFinalizeNotifier(void);
2564MODULE_SCOPE void	TclFinalizeObjects(void);
2565MODULE_SCOPE void	TclFinalizePreserve(void);
2566MODULE_SCOPE void	TclFinalizeSynchronization(void);
2567MODULE_SCOPE void	TclFinalizeThreadAlloc(void);
2568MODULE_SCOPE void	TclFinalizeThreadData(void);
2569MODULE_SCOPE void	TclFinalizeThreadObjects(void);
2570MODULE_SCOPE double	TclFloor(mp_int *a);
2571MODULE_SCOPE void	TclFormatNaN(double value, char *buffer);
2572MODULE_SCOPE int	TclFSFileAttrIndex(Tcl_Obj *pathPtr,
2573			    const char *attributeName, int *indexPtr);
2574MODULE_SCOPE void	TclFSUnloadTempFile(Tcl_LoadHandle loadHandle);
2575MODULE_SCOPE int *	TclGetAsyncReadyPtr(void);
2576MODULE_SCOPE Tcl_Obj *	TclGetBgErrorHandler(Tcl_Interp *interp);
2577MODULE_SCOPE int	TclGetChannelFromObj(Tcl_Interp *interp,
2578			    Tcl_Obj *objPtr, Tcl_Channel *chanPtr,
2579			    int *modePtr, int flags);
2580MODULE_SCOPE int	TclGetNumberFromObj(Tcl_Interp *interp,
2581			    Tcl_Obj *objPtr, ClientData *clientDataPtr,
2582			    int *typePtr);
2583MODULE_SCOPE int	TclGetOpenModeEx(Tcl_Interp *interp,
2584			    const char *modeString, int *seekFlagPtr,
2585			    int *binaryPtr);
2586MODULE_SCOPE Tcl_Obj *	TclGetProcessGlobalValue(ProcessGlobalValue *pgvPtr);
2587MODULE_SCOPE const char *TclGetSrcInfoForCmd(Interp *iPtr, int *lenPtr);
2588MODULE_SCOPE int	TclGlob(Tcl_Interp *interp, char *pattern,
2589			    Tcl_Obj *unquotedPrefix, int globFlags,
2590			    Tcl_GlobTypeData *types);
2591MODULE_SCOPE int	TclIncrObj(Tcl_Interp *interp, Tcl_Obj *valuePtr,
2592			    Tcl_Obj *incrPtr);
2593MODULE_SCOPE Tcl_Obj *	TclIncrObjVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
2594			    Tcl_Obj *part2Ptr, Tcl_Obj *incrPtr, int flags);
2595MODULE_SCOPE int	TclInfoExistsCmd(ClientData dummy, Tcl_Interp *interp,
2596			    int objc, Tcl_Obj *const objv[]);
2597MODULE_SCOPE Tcl_Obj *	TclInfoFrame(Tcl_Interp *interp, CmdFrame *framePtr);
2598MODULE_SCOPE int	TclInfoGlobalsCmd(ClientData dummy, Tcl_Interp *interp,
2599			    int objc, Tcl_Obj *const objv[]);
2600MODULE_SCOPE int	TclInfoLocalsCmd(ClientData dummy, Tcl_Interp *interp,
2601			    int objc, Tcl_Obj *const objv[]);
2602MODULE_SCOPE int	TclInfoVarsCmd(ClientData dummy, Tcl_Interp *interp,
2603			    int objc, Tcl_Obj *const objv[]);
2604MODULE_SCOPE void	TclInitAlloc(void);
2605MODULE_SCOPE void	TclInitDbCkalloc(void);
2606MODULE_SCOPE void	TclInitDoubleConversion(void);
2607MODULE_SCOPE void	TclInitEmbeddedConfigurationInformation(
2608			    Tcl_Interp *interp);
2609MODULE_SCOPE void	TclInitEncodingSubsystem(void);
2610MODULE_SCOPE void	TclInitIOSubsystem(void);
2611MODULE_SCOPE void	TclInitLimitSupport(Tcl_Interp *interp);
2612MODULE_SCOPE void	TclInitNamespaceSubsystem(void);
2613MODULE_SCOPE void	TclInitNotifier(void);
2614MODULE_SCOPE void	TclInitObjSubsystem(void);
2615MODULE_SCOPE void	TclInitSubsystems(void);
2616MODULE_SCOPE int	TclInterpReady(Tcl_Interp *interp);
2617MODULE_SCOPE int	TclIsLocalScalar(const char *src, int len);
2618MODULE_SCOPE int	TclJoinThread(Tcl_ThreadId id, int *result);
2619MODULE_SCOPE void	TclLimitRemoveAllHandlers(Tcl_Interp *interp);
2620MODULE_SCOPE Tcl_Obj *	TclLindexList(Tcl_Interp *interp,
2621			    Tcl_Obj *listPtr, Tcl_Obj *argPtr);
2622MODULE_SCOPE Tcl_Obj *	TclLindexFlat(Tcl_Interp *interp, Tcl_Obj *listPtr,
2623			    int indexCount, Tcl_Obj *const indexArray[]);
2624/* TIP #280 */
2625MODULE_SCOPE void	TclListLines(Tcl_Obj *listObj, int line, int n,
2626			    int *lines, Tcl_Obj *const *elems);
2627MODULE_SCOPE Tcl_Obj *	TclListObjCopy(Tcl_Interp *interp, Tcl_Obj *listPtr);
2628MODULE_SCOPE int	TclLoadFile(Tcl_Interp *interp, Tcl_Obj *pathPtr,
2629			    int symc, const char *symbols[],
2630			    Tcl_PackageInitProc **procPtrs[],
2631			    Tcl_LoadHandle *handlePtr,
2632			    ClientData *clientDataPtr,
2633			    Tcl_FSUnloadFileProc **unloadProcPtr);
2634MODULE_SCOPE Tcl_Obj *	TclLsetList(Tcl_Interp *interp, Tcl_Obj *listPtr,
2635			    Tcl_Obj *indexPtr, Tcl_Obj *valuePtr);
2636MODULE_SCOPE Tcl_Obj *	TclLsetFlat(Tcl_Interp *interp, Tcl_Obj *listPtr,
2637			    int indexCount, Tcl_Obj *const indexArray[],
2638			    Tcl_Obj *valuePtr);
2639MODULE_SCOPE Tcl_Command TclMakeEnsemble(Tcl_Interp *interp, const char *name,
2640			    const EnsembleImplMap map[]);
2641MODULE_SCOPE int	TclMarkList(Tcl_Interp *interp, const char *list,
2642			    const char *end, int *argcPtr,
2643			    const int **argszPtr, const char ***argvPtr);
2644MODULE_SCOPE int	TclMergeReturnOptions(Tcl_Interp *interp, int objc,
2645			    Tcl_Obj *const objv[], Tcl_Obj **optionsPtrPtr,
2646			    int *codePtr, int *levelPtr);
2647MODULE_SCOPE int	TclNokia770Doubles();
2648MODULE_SCOPE void	TclObjVarErrMsg(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
2649			    Tcl_Obj *part2Ptr, const char *operation,
2650			    const char *reason, int index);
2651MODULE_SCOPE int	TclObjInvokeNamespace(Tcl_Interp *interp,
2652			    int objc, Tcl_Obj *const objv[],
2653			    Tcl_Namespace *nsPtr, int flags);
2654MODULE_SCOPE int	TclObjUnsetVar2(Tcl_Interp *interp,
2655			    Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags);
2656MODULE_SCOPE int	TclParseBackslash(const char *src,
2657			    int numBytes, int *readPtr, char *dst);
2658MODULE_SCOPE int	TclParseHex(const char *src, int numBytes,
2659			    Tcl_UniChar *resultPtr);
2660MODULE_SCOPE int	TclParseNumber(Tcl_Interp *interp, Tcl_Obj *objPtr,
2661			    const char *expected, const char *bytes,
2662			    int numBytes, const char **endPtrPtr, int flags);
2663MODULE_SCOPE void	TclParseInit(Tcl_Interp *interp, const char *string,
2664			    int numBytes, Tcl_Parse *parsePtr);
2665MODULE_SCOPE int	TclParseAllWhiteSpace(const char *src, int numBytes);
2666MODULE_SCOPE int	TclProcessReturn(Tcl_Interp *interp,
2667			    int code, int level, Tcl_Obj *returnOpts);
2668#ifndef TCL_NO_STACK_CHECK
2669MODULE_SCOPE int        TclpGetCStackParams(int **stackBoundPtr);
2670#endif
2671MODULE_SCOPE int	TclpObjLstat(Tcl_Obj *pathPtr, Tcl_StatBuf *buf);
2672MODULE_SCOPE Tcl_Obj *	TclpTempFileName(void);
2673MODULE_SCOPE Tcl_Obj *	TclNewFSPathObj(Tcl_Obj *dirPtr, const char *addStrRep,
2674			    int len);
2675MODULE_SCOPE int	TclpDeleteFile(const char *path);
2676MODULE_SCOPE void	TclpFinalizeCondition(Tcl_Condition *condPtr);
2677MODULE_SCOPE void	TclpFinalizeMutex(Tcl_Mutex *mutexPtr);
2678MODULE_SCOPE void	TclpFinalizePipes(void);
2679MODULE_SCOPE void	TclpFinalizeSockets(void);
2680MODULE_SCOPE int	TclpThreadCreate(Tcl_ThreadId *idPtr,
2681			    Tcl_ThreadCreateProc proc, ClientData clientData,
2682			    int stackSize, int flags);
2683MODULE_SCOPE int	TclpFindVariable(const char *name, int *lengthPtr);
2684MODULE_SCOPE void	TclpInitLibraryPath(char **valuePtr,
2685			    int *lengthPtr, Tcl_Encoding *encodingPtr);
2686MODULE_SCOPE void	TclpInitLock(void);
2687MODULE_SCOPE void	TclpInitPlatform(void);
2688MODULE_SCOPE void	TclpInitUnlock(void);
2689MODULE_SCOPE int	TclpLoadFile(Tcl_Interp *interp, Tcl_Obj *pathPtr,
2690			    const char *sym1, const char *sym2,
2691			    Tcl_PackageInitProc **proc1Ptr,
2692			    Tcl_PackageInitProc **proc2Ptr,
2693			    ClientData *clientDataPtr,
2694			    Tcl_FSUnloadFileProc **unloadProcPtr);
2695MODULE_SCOPE Tcl_Obj *	TclpObjListVolumes(void);
2696MODULE_SCOPE void	TclpMasterLock(void);
2697MODULE_SCOPE void	TclpMasterUnlock(void);
2698MODULE_SCOPE int	TclpMatchFiles(Tcl_Interp *interp, char *separators,
2699			    Tcl_DString *dirPtr, char *pattern, char *tail);
2700MODULE_SCOPE int	TclpObjNormalizePath(Tcl_Interp *interp,
2701			    Tcl_Obj *pathPtr, int nextCheckpoint);
2702MODULE_SCOPE void	TclpNativeJoinPath(Tcl_Obj *prefix, char *joining);
2703MODULE_SCOPE Tcl_Obj *	TclpNativeSplitPath(Tcl_Obj *pathPtr, int *lenPtr);
2704MODULE_SCOPE Tcl_PathType TclpGetNativePathType(Tcl_Obj *pathPtr,
2705			    int *driveNameLengthPtr, Tcl_Obj **driveNameRef);
2706MODULE_SCOPE int	TclCrossFilesystemCopy(Tcl_Interp *interp,
2707			    Tcl_Obj *source, Tcl_Obj *target);
2708MODULE_SCOPE int	TclpMatchInDirectory(Tcl_Interp *interp,
2709			    Tcl_Obj *resultPtr, Tcl_Obj *pathPtr,
2710			    const char *pattern, Tcl_GlobTypeData *types);
2711MODULE_SCOPE ClientData	TclpGetNativeCwd(ClientData clientData);
2712MODULE_SCOPE Tcl_FSDupInternalRepProc TclNativeDupInternalRep;
2713MODULE_SCOPE Tcl_Obj *	TclpObjLink(Tcl_Obj *pathPtr, Tcl_Obj *toPtr,
2714			    int linkType);
2715MODULE_SCOPE int	TclpObjChdir(Tcl_Obj *pathPtr);
2716MODULE_SCOPE Tcl_Obj *	TclPathPart(Tcl_Interp *interp, Tcl_Obj *pathPtr,
2717			    Tcl_PathPart portion);
2718#ifndef TclpPanic
2719MODULE_SCOPE void	TclpPanic(const char *format, ...);
2720#endif
2721MODULE_SCOPE char *	TclpReadlink(const char *fileName,
2722			    Tcl_DString *linkPtr);
2723#ifndef TclpReleaseFile
2724MODULE_SCOPE void	TclpReleaseFile(TclFile file);
2725#endif
2726MODULE_SCOPE void	TclpSetInterfaces(void);
2727MODULE_SCOPE void	TclpSetVariables(Tcl_Interp *interp);
2728MODULE_SCOPE void	TclpUnloadFile(Tcl_LoadHandle loadHandle);
2729MODULE_SCOPE void *	TclpThreadDataKeyGet(Tcl_ThreadDataKey *keyPtr);
2730MODULE_SCOPE void	TclpThreadDataKeySet(Tcl_ThreadDataKey *keyPtr,
2731			    void *data);
2732MODULE_SCOPE void	TclpThreadExit(int status);
2733MODULE_SCOPE size_t	TclpThreadGetStackSize(void);
2734MODULE_SCOPE void	TclRememberCondition(Tcl_Condition *mutex);
2735MODULE_SCOPE void	TclRememberJoinableThread(Tcl_ThreadId id);
2736MODULE_SCOPE void	TclRememberMutex(Tcl_Mutex *mutex);
2737MODULE_SCOPE void	TclRemoveScriptLimitCallbacks(Tcl_Interp *interp);
2738MODULE_SCOPE int	TclReToGlob(Tcl_Interp *interp, const char *reStr,
2739			    int reStrLen, Tcl_DString *dsPtr, int *flagsPtr);
2740MODULE_SCOPE void	TclSetBgErrorHandler(Tcl_Interp *interp,
2741			    Tcl_Obj *cmdPrefix);
2742MODULE_SCOPE void	TclSetBignumIntRep(Tcl_Obj *objPtr,
2743			    mp_int *bignumValue);
2744MODULE_SCOPE void	TclSetCmdNameObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
2745			    Command *cmdPtr);
2746MODULE_SCOPE void	TclSetProcessGlobalValue(ProcessGlobalValue *pgvPtr,
2747			    Tcl_Obj *newValue, Tcl_Encoding encoding);
2748MODULE_SCOPE void	TclSignalExitThread(Tcl_ThreadId id, int result);
2749MODULE_SCOPE void *	TclStackRealloc(Tcl_Interp *interp, void *ptr,
2750			    int numBytes);
2751MODULE_SCOPE int	TclStringMatch(const char *str, int strLen,
2752			    const char *pattern, int ptnLen, int flags);
2753MODULE_SCOPE int	TclStringMatchObj(Tcl_Obj *stringObj,
2754			    Tcl_Obj *patternObj, int flags);
2755MODULE_SCOPE Tcl_Obj *	TclStringObjReverse(Tcl_Obj *objPtr);
2756MODULE_SCOPE int	TclSubstTokens(Tcl_Interp *interp, Tcl_Token *tokenPtr,
2757			    int count, int *tokensLeftPtr, int line,
2758			    int *clNextOuter, CONST char *outerScript);
2759MODULE_SCOPE void	TclTransferResult(Tcl_Interp *sourceInterp, int result,
2760			    Tcl_Interp *targetInterp);
2761MODULE_SCOPE Tcl_Obj *	TclpNativeToNormalized(ClientData clientData);
2762MODULE_SCOPE Tcl_Obj *	TclpFilesystemPathType(Tcl_Obj *pathPtr);
2763MODULE_SCOPE Tcl_PackageInitProc *TclpFindSymbol(Tcl_Interp *interp,
2764			    Tcl_LoadHandle loadHandle, const char *symbol);
2765MODULE_SCOPE int	TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr,
2766			    Tcl_LoadHandle *loadHandle,
2767			    Tcl_FSUnloadFileProc **unloadProcPtr);
2768MODULE_SCOPE int	TclpUtime(Tcl_Obj *pathPtr, struct utimbuf *tval);
2769#ifdef TCL_LOAD_FROM_MEMORY
2770MODULE_SCOPE void *	TclpLoadMemoryGetBuffer(Tcl_Interp *interp, int size);
2771MODULE_SCOPE int	TclpLoadMemory(Tcl_Interp *interp, void *buffer,
2772			    int size, int codeSize, Tcl_LoadHandle *loadHandle,
2773			    Tcl_FSUnloadFileProc **unloadProcPtr);
2774#endif
2775MODULE_SCOPE void	TclInitThreadStorage(void);
2776MODULE_SCOPE void	TclpFinalizeThreadDataThread(void);
2777MODULE_SCOPE void	TclFinalizeThreadStorage(void);
2778#ifdef TCL_WIDE_CLICKS
2779MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void);
2780MODULE_SCOPE double	TclpWideClicksToNanoseconds(Tcl_WideInt clicks);
2781#endif
2782MODULE_SCOPE Tcl_Obj *	TclDisassembleByteCodeObj(Tcl_Obj *objPtr);
2783
2784/*
2785 *----------------------------------------------------------------
2786 * Command procedures in the generic core:
2787 *----------------------------------------------------------------
2788 */
2789
2790MODULE_SCOPE int	Tcl_AfterObjCmd(ClientData clientData,
2791			    Tcl_Interp *interp, int objc,
2792			    Tcl_Obj *const objv[]);
2793MODULE_SCOPE int	Tcl_AppendObjCmd(ClientData clientData,
2794			    Tcl_Interp *interp, int objc,
2795			    Tcl_Obj *const objv[]);
2796MODULE_SCOPE int	Tcl_ApplyObjCmd(ClientData clientData,
2797			    Tcl_Interp *interp, int objc,
2798			    Tcl_Obj *const objv[]);
2799MODULE_SCOPE int	Tcl_ArrayObjCmd(ClientData clientData,
2800			    Tcl_Interp *interp, int objc,
2801			    Tcl_Obj *const objv[]);
2802MODULE_SCOPE int	Tcl_BinaryObjCmd(ClientData clientData,
2803			    Tcl_Interp *interp, int objc,
2804			    Tcl_Obj *const objv[]);
2805MODULE_SCOPE int	Tcl_BreakObjCmd(ClientData clientData,
2806			    Tcl_Interp *interp, int objc,
2807			    Tcl_Obj *const objv[]);
2808MODULE_SCOPE int	Tcl_CaseObjCmd(ClientData clientData,
2809			    Tcl_Interp *interp, int objc,
2810			    Tcl_Obj *const objv[]);
2811MODULE_SCOPE int	Tcl_CatchObjCmd(ClientData clientData,
2812			    Tcl_Interp *interp, int objc,
2813			    Tcl_Obj *const objv[]);
2814MODULE_SCOPE int	Tcl_CdObjCmd(ClientData clientData,
2815			    Tcl_Interp *interp, int objc,
2816			    Tcl_Obj *const objv[]);
2817MODULE_SCOPE Tcl_Command TclInitChanCmd(Tcl_Interp *interp);
2818MODULE_SCOPE int	TclChanCreateObjCmd(ClientData clientData,
2819			    Tcl_Interp *interp, int objc,
2820			    Tcl_Obj *const objv[]);
2821MODULE_SCOPE int	TclChanPostEventObjCmd(ClientData clientData,
2822			    Tcl_Interp *interp, int objc,
2823			    Tcl_Obj *const objv[]);
2824MODULE_SCOPE void	TclClockInit(Tcl_Interp *interp);
2825MODULE_SCOPE int	TclClockOldscanObjCmd(
2826			    ClientData clientData, Tcl_Interp *interp,
2827			    int objc, Tcl_Obj *const objv[]);
2828MODULE_SCOPE int	Tcl_CloseObjCmd(ClientData clientData,
2829			    Tcl_Interp *interp, int objc,
2830			    Tcl_Obj *const objv[]);
2831MODULE_SCOPE int	Tcl_ConcatObjCmd(ClientData clientData,
2832			    Tcl_Interp *interp, int objc,
2833			    Tcl_Obj *const objv[]);
2834MODULE_SCOPE int	Tcl_ContinueObjCmd(ClientData clientData,
2835			    Tcl_Interp *interp, int objc,
2836			    Tcl_Obj *const objv[]);
2837MODULE_SCOPE Tcl_TimerToken TclCreateAbsoluteTimerHandler(
2838			    Tcl_Time *timePtr, Tcl_TimerProc *proc,
2839			    ClientData clientData);
2840MODULE_SCOPE int	TclDefaultBgErrorHandlerObjCmd(
2841			    ClientData clientData, Tcl_Interp *interp,
2842			    int objc, Tcl_Obj *const objv[]);
2843MODULE_SCOPE Tcl_Command TclInitDictCmd(Tcl_Interp *interp);
2844MODULE_SCOPE int	Tcl_DisassembleObjCmd(ClientData clientData,
2845			    Tcl_Interp *interp, int objc,
2846			    Tcl_Obj *const objv[]);
2847MODULE_SCOPE int	Tcl_EncodingObjCmd(ClientData clientData,
2848			    Tcl_Interp *interp, int objc,
2849			    Tcl_Obj *const objv[]);
2850MODULE_SCOPE int	Tcl_EofObjCmd(ClientData clientData,
2851			    Tcl_Interp *interp, int objc,
2852			    Tcl_Obj *const objv[]);
2853MODULE_SCOPE int	Tcl_ErrorObjCmd(ClientData clientData,
2854			    Tcl_Interp *interp, int objc,
2855			    Tcl_Obj *const objv[]);
2856MODULE_SCOPE int	Tcl_EvalObjCmd(ClientData clientData,
2857			    Tcl_Interp *interp, int objc,
2858			    Tcl_Obj *const objv[]);
2859MODULE_SCOPE int	Tcl_ExecObjCmd(ClientData clientData,
2860			    Tcl_Interp *interp, int objc,
2861			    Tcl_Obj *const objv[]);
2862MODULE_SCOPE int	Tcl_ExitObjCmd(ClientData clientData,
2863			    Tcl_Interp *interp, int objc,
2864			    Tcl_Obj *const objv[]);
2865MODULE_SCOPE int	Tcl_ExprObjCmd(ClientData clientData,
2866			    Tcl_Interp *interp, int objc,
2867			    Tcl_Obj *const objv[]);
2868MODULE_SCOPE int	Tcl_FblockedObjCmd(ClientData clientData,
2869			    Tcl_Interp *interp, int objc,
2870			    Tcl_Obj *const objv[]);
2871MODULE_SCOPE int	Tcl_FconfigureObjCmd(
2872			    ClientData clientData, Tcl_Interp *interp,
2873			    int objc, Tcl_Obj *const objv[]);
2874MODULE_SCOPE int	Tcl_FcopyObjCmd(ClientData dummy,
2875			    Tcl_Interp *interp, int objc,
2876			    Tcl_Obj *const objv[]);
2877MODULE_SCOPE int	Tcl_FileObjCmd(ClientData dummy,
2878			    Tcl_Interp *interp, int objc,
2879			    Tcl_Obj *const objv[]);
2880MODULE_SCOPE int	Tcl_FileEventObjCmd(ClientData clientData,
2881			    Tcl_Interp *interp, int objc,
2882			    Tcl_Obj *const objv[]);
2883MODULE_SCOPE int	Tcl_FlushObjCmd(ClientData clientData,
2884			    Tcl_Interp *interp, int objc,
2885			    Tcl_Obj *const objv[]);
2886MODULE_SCOPE int	Tcl_ForObjCmd(ClientData clientData,
2887			    Tcl_Interp *interp, int objc,
2888			    Tcl_Obj *const objv[]);
2889MODULE_SCOPE int	Tcl_ForeachObjCmd(ClientData clientData,
2890			    Tcl_Interp *interp, int objc,
2891			    Tcl_Obj *const objv[]);
2892MODULE_SCOPE int	Tcl_FormatObjCmd(ClientData dummy,
2893			    Tcl_Interp *interp, int objc,
2894			    Tcl_Obj *const objv[]);
2895MODULE_SCOPE int	Tcl_GetsObjCmd(ClientData clientData,
2896			    Tcl_Interp *interp, int objc,
2897			    Tcl_Obj *const objv[]);
2898MODULE_SCOPE int	Tcl_GlobalObjCmd(ClientData clientData,
2899			    Tcl_Interp *interp, int objc,
2900			    Tcl_Obj *const objv[]);
2901MODULE_SCOPE int	Tcl_GlobObjCmd(ClientData clientData,
2902			    Tcl_Interp *interp, int objc,
2903			    Tcl_Obj *const objv[]);
2904MODULE_SCOPE int	Tcl_IfObjCmd(ClientData clientData,
2905			    Tcl_Interp *interp, int objc,
2906			    Tcl_Obj *const objv[]);
2907MODULE_SCOPE int	Tcl_IncrObjCmd(ClientData clientData,
2908			    Tcl_Interp *interp, int objc,
2909			    Tcl_Obj *const objv[]);
2910MODULE_SCOPE Tcl_Command TclInitInfoCmd(Tcl_Interp *interp);
2911MODULE_SCOPE int	Tcl_InterpObjCmd(ClientData clientData,
2912			    Tcl_Interp *interp, int argc,
2913			    Tcl_Obj *const objv[]);
2914MODULE_SCOPE int	Tcl_JoinObjCmd(ClientData clientData,
2915			    Tcl_Interp *interp, int objc,
2916			    Tcl_Obj *const objv[]);
2917MODULE_SCOPE int	Tcl_LappendObjCmd(ClientData clientData,
2918			    Tcl_Interp *interp, int objc,
2919			    Tcl_Obj *const objv[]);
2920MODULE_SCOPE int	Tcl_LassignObjCmd(ClientData clientData,
2921			    Tcl_Interp *interp, int objc,
2922			    Tcl_Obj *const objv[]);
2923MODULE_SCOPE int	Tcl_LindexObjCmd(ClientData clientData,
2924			    Tcl_Interp *interp, int objc,
2925			    Tcl_Obj *const objv[]);
2926MODULE_SCOPE int	Tcl_LinsertObjCmd(ClientData clientData,
2927			    Tcl_Interp *interp, int objc,
2928			    Tcl_Obj *const objv[]);
2929MODULE_SCOPE int	Tcl_LlengthObjCmd(ClientData clientData,
2930			    Tcl_Interp *interp, int objc,
2931			    Tcl_Obj *const objv[]);
2932MODULE_SCOPE int	Tcl_ListObjCmd(ClientData clientData,
2933			    Tcl_Interp *interp, int objc,
2934			    Tcl_Obj *const objv[]);
2935MODULE_SCOPE int	Tcl_LoadObjCmd(ClientData clientData,
2936			    Tcl_Interp *interp, int objc,
2937			    Tcl_Obj *const objv[]);
2938MODULE_SCOPE int	Tcl_LrangeObjCmd(ClientData clientData,
2939			    Tcl_Interp *interp, int objc,
2940			    Tcl_Obj *const objv[]);
2941MODULE_SCOPE int	Tcl_LrepeatObjCmd(ClientData clientData,
2942			    Tcl_Interp *interp, int objc,
2943			    Tcl_Obj *const objv[]);
2944MODULE_SCOPE int	Tcl_LreplaceObjCmd(ClientData clientData,
2945			    Tcl_Interp *interp, int objc,
2946			    Tcl_Obj *const objv[]);
2947MODULE_SCOPE int	Tcl_LreverseObjCmd(ClientData clientData,
2948			    Tcl_Interp *interp, int objc,
2949			    Tcl_Obj *const objv[]);
2950MODULE_SCOPE int	Tcl_LsearchObjCmd(ClientData clientData,
2951			    Tcl_Interp *interp, int objc,
2952			    Tcl_Obj *const objv[]);
2953MODULE_SCOPE int	Tcl_LsetObjCmd(ClientData clientData,
2954			    Tcl_Interp *interp, int objc,
2955			    Tcl_Obj *const objv[]);
2956MODULE_SCOPE int	Tcl_LsortObjCmd(ClientData clientData,
2957			    Tcl_Interp *interp, int objc,
2958			    Tcl_Obj *const objv[]);
2959MODULE_SCOPE int	Tcl_NamespaceObjCmd(ClientData clientData,
2960			    Tcl_Interp *interp, int objc,
2961			    Tcl_Obj *const objv[]);
2962MODULE_SCOPE int	Tcl_OpenObjCmd(ClientData clientData,
2963			    Tcl_Interp *interp, int objc,
2964			    Tcl_Obj *const objv[]);
2965MODULE_SCOPE int	Tcl_PackageObjCmd(ClientData clientData,
2966			    Tcl_Interp *interp, int objc,
2967			    Tcl_Obj *const objv[]);
2968MODULE_SCOPE int	Tcl_PidObjCmd(ClientData clientData,
2969			    Tcl_Interp *interp, int objc,
2970			    Tcl_Obj *const objv[]);
2971MODULE_SCOPE int	Tcl_PutsObjCmd(ClientData clientData,
2972			    Tcl_Interp *interp, int objc,
2973			    Tcl_Obj *const objv[]);
2974MODULE_SCOPE int	Tcl_PwdObjCmd(ClientData clientData,
2975			    Tcl_Interp *interp, int objc,
2976			    Tcl_Obj *const objv[]);
2977MODULE_SCOPE int	Tcl_ReadObjCmd(ClientData clientData,
2978			    Tcl_Interp *interp, int objc,
2979			    Tcl_Obj *const objv[]);
2980MODULE_SCOPE int	Tcl_RegexpObjCmd(ClientData clientData,
2981			    Tcl_Interp *interp, int objc,
2982			    Tcl_Obj *const objv[]);
2983MODULE_SCOPE int	Tcl_RegsubObjCmd(ClientData clientData,
2984			    Tcl_Interp *interp, int objc,
2985			    Tcl_Obj *const objv[]);
2986MODULE_SCOPE int	Tcl_RenameObjCmd(ClientData clientData,
2987			    Tcl_Interp *interp, int objc,
2988			    Tcl_Obj *const objv[]);
2989MODULE_SCOPE int	Tcl_ReturnObjCmd(ClientData clientData,
2990			    Tcl_Interp *interp, int objc,
2991			    Tcl_Obj *const objv[]);
2992MODULE_SCOPE int	Tcl_ScanObjCmd(ClientData clientData,
2993			    Tcl_Interp *interp, int objc,
2994			    Tcl_Obj *const objv[]);
2995MODULE_SCOPE int	Tcl_SeekObjCmd(ClientData clientData,
2996			    Tcl_Interp *interp, int objc,
2997			    Tcl_Obj *const objv[]);
2998MODULE_SCOPE int	Tcl_SetObjCmd(ClientData clientData,
2999			    Tcl_Interp *interp, int objc,
3000			    Tcl_Obj *const objv[]);
3001MODULE_SCOPE int	Tcl_SplitObjCmd(ClientData clientData,
3002			    Tcl_Interp *interp, int objc,
3003			    Tcl_Obj *const objv[]);
3004MODULE_SCOPE int	Tcl_SocketObjCmd(ClientData clientData,
3005			    Tcl_Interp *interp, int objc,
3006			    Tcl_Obj *const objv[]);
3007MODULE_SCOPE int	Tcl_SourceObjCmd(ClientData clientData,
3008			    Tcl_Interp *interp, int objc,
3009			    Tcl_Obj *const objv[]);
3010MODULE_SCOPE Tcl_Command TclInitStringCmd(Tcl_Interp *interp);
3011MODULE_SCOPE int	Tcl_SubstObjCmd(ClientData clientData,
3012			    Tcl_Interp *interp, int objc,
3013			    Tcl_Obj *const objv[]);
3014MODULE_SCOPE int	Tcl_SwitchObjCmd(ClientData clientData,
3015			    Tcl_Interp *interp, int objc,
3016			    Tcl_Obj *const objv[]);
3017MODULE_SCOPE int	Tcl_TellObjCmd(ClientData clientData,
3018			    Tcl_Interp *interp, int objc,
3019			    Tcl_Obj *const objv[]);
3020MODULE_SCOPE int	Tcl_TimeObjCmd(ClientData clientData,
3021			    Tcl_Interp *interp, int objc,
3022			    Tcl_Obj *const objv[]);
3023MODULE_SCOPE int	Tcl_TraceObjCmd(ClientData clientData,
3024			    Tcl_Interp *interp, int objc,
3025			    Tcl_Obj *const objv[]);
3026MODULE_SCOPE int	Tcl_UnloadObjCmd(ClientData clientData,
3027			    Tcl_Interp *interp, int objc,
3028			    Tcl_Obj *const objv[]);
3029MODULE_SCOPE int	Tcl_UnsetObjCmd(ClientData clientData,
3030			    Tcl_Interp *interp, int objc,
3031			    Tcl_Obj *const objv[]);
3032MODULE_SCOPE int	Tcl_UpdateObjCmd(ClientData clientData,
3033			    Tcl_Interp *interp, int objc,
3034			    Tcl_Obj *const objv[]);
3035MODULE_SCOPE int	Tcl_UplevelObjCmd(ClientData clientData,
3036			    Tcl_Interp *interp, int objc,
3037			    Tcl_Obj *const objv[]);
3038MODULE_SCOPE int	Tcl_UpvarObjCmd(ClientData clientData,
3039			    Tcl_Interp *interp, int objc,
3040			    Tcl_Obj *const objv[]);
3041MODULE_SCOPE int	Tcl_VariableObjCmd(ClientData clientData,
3042			    Tcl_Interp *interp, int objc,
3043			    Tcl_Obj *const objv[]);
3044MODULE_SCOPE int	Tcl_VwaitObjCmd(ClientData clientData,
3045			    Tcl_Interp *interp, int objc,
3046			    Tcl_Obj *const objv[]);
3047MODULE_SCOPE int	Tcl_WhileObjCmd(ClientData clientData,
3048			    Tcl_Interp *interp, int objc,
3049			    Tcl_Obj *const objv[]);
3050
3051/*
3052 *----------------------------------------------------------------
3053 * Compilation procedures for commands in the generic core:
3054 *----------------------------------------------------------------
3055 */
3056
3057MODULE_SCOPE int	TclCompileAppendCmd(Tcl_Interp *interp,
3058			    Tcl_Parse *parsePtr, Command *cmdPtr,
3059			    struct CompileEnv *envPtr);
3060MODULE_SCOPE int	TclCompileBreakCmd(Tcl_Interp *interp,
3061			    Tcl_Parse *parsePtr, Command *cmdPtr,
3062			    struct CompileEnv *envPtr);
3063MODULE_SCOPE int	TclCompileCatchCmd(Tcl_Interp *interp,
3064			    Tcl_Parse *parsePtr, Command *cmdPtr,
3065			    struct CompileEnv *envPtr);
3066MODULE_SCOPE int	TclCompileContinueCmd(Tcl_Interp *interp,
3067			    Tcl_Parse *parsePtr, Command *cmdPtr,
3068			    struct CompileEnv *envPtr);
3069MODULE_SCOPE int	TclCompileDictAppendCmd(Tcl_Interp *interp,
3070			    Tcl_Parse *parsePtr, Command *cmdPtr,
3071			    struct CompileEnv *envPtr);
3072MODULE_SCOPE int	TclCompileDictForCmd(Tcl_Interp *interp,
3073			    Tcl_Parse *parsePtr, Command *cmdPtr,
3074			    struct CompileEnv *envPtr);
3075MODULE_SCOPE int	TclCompileDictGetCmd(Tcl_Interp *interp,
3076			    Tcl_Parse *parsePtr, Command *cmdPtr,
3077			    struct CompileEnv *envPtr);
3078MODULE_SCOPE int	TclCompileDictIncrCmd(Tcl_Interp *interp,
3079			    Tcl_Parse *parsePtr, Command *cmdPtr,
3080			    struct CompileEnv *envPtr);
3081MODULE_SCOPE int	TclCompileDictLappendCmd(Tcl_Interp *interp,
3082			    Tcl_Parse *parsePtr, Command *cmdPtr,
3083			    struct CompileEnv *envPtr);
3084MODULE_SCOPE int	TclCompileDictSetCmd(Tcl_Interp *interp,
3085			    Tcl_Parse *parsePtr, Command *cmdPtr,
3086			    struct CompileEnv *envPtr);
3087MODULE_SCOPE int	TclCompileDictUpdateCmd(Tcl_Interp *interp,
3088			    Tcl_Parse *parsePtr, Command *cmdPtr,
3089			    struct CompileEnv *envPtr);
3090MODULE_SCOPE int	TclCompileEnsemble(Tcl_Interp *interp,
3091			    Tcl_Parse *parsePtr, Command *cmdPtr,
3092			    struct CompileEnv *envPtr);
3093MODULE_SCOPE int	TclCompileExprCmd(Tcl_Interp *interp,
3094			    Tcl_Parse *parsePtr, Command *cmdPtr,
3095			    struct CompileEnv *envPtr);
3096MODULE_SCOPE int	TclCompileForCmd(Tcl_Interp *interp,
3097			    Tcl_Parse *parsePtr, Command *cmdPtr,
3098			    struct CompileEnv *envPtr);
3099MODULE_SCOPE int	TclCompileForeachCmd(Tcl_Interp *interp,
3100			    Tcl_Parse *parsePtr, Command *cmdPtr,
3101			    struct CompileEnv *envPtr);
3102MODULE_SCOPE int	TclCompileGlobalCmd(Tcl_Interp *interp,
3103			    Tcl_Parse *parsePtr, Command *cmdPtr,
3104			    struct CompileEnv *envPtr);
3105MODULE_SCOPE int	TclCompileIfCmd(Tcl_Interp *interp,
3106			    Tcl_Parse *parsePtr, Command *cmdPtr,
3107			    struct CompileEnv *envPtr);
3108MODULE_SCOPE int	TclCompileInfoExistsCmd(Tcl_Interp *interp,
3109			    Tcl_Parse *parsePtr, Command *cmdPtr,
3110			    struct CompileEnv *envPtr);
3111MODULE_SCOPE int	TclCompileIncrCmd(Tcl_Interp *interp,
3112			    Tcl_Parse *parsePtr, Command *cmdPtr,
3113			    struct CompileEnv *envPtr);
3114MODULE_SCOPE int	TclCompileLappendCmd(Tcl_Interp *interp,
3115			    Tcl_Parse *parsePtr, Command *cmdPtr,
3116			    struct CompileEnv *envPtr);
3117MODULE_SCOPE int	TclCompileLassignCmd(Tcl_Interp *interp,
3118			    Tcl_Parse *parsePtr, Command *cmdPtr,
3119			    struct CompileEnv *envPtr);
3120MODULE_SCOPE int	TclCompileLindexCmd(Tcl_Interp *interp,
3121			    Tcl_Parse *parsePtr, Command *cmdPtr,
3122			    struct CompileEnv *envPtr);
3123MODULE_SCOPE int	TclCompileListCmd(Tcl_Interp *interp,
3124			    Tcl_Parse *parsePtr, Command *cmdPtr,
3125			    struct CompileEnv *envPtr);
3126MODULE_SCOPE int	TclCompileLlengthCmd(Tcl_Interp *interp,
3127			    Tcl_Parse *parsePtr, Command *cmdPtr,
3128			    struct CompileEnv *envPtr);
3129MODULE_SCOPE int	TclCompileLsetCmd(Tcl_Interp *interp,
3130			    Tcl_Parse *parsePtr, Command *cmdPtr,
3131			    struct CompileEnv *envPtr);
3132MODULE_SCOPE int	TclCompileNamespaceCmd(Tcl_Interp *interp,
3133			    Tcl_Parse *parsePtr, Command *cmdPtr,
3134			    struct CompileEnv *envPtr);
3135MODULE_SCOPE int	TclCompileNoOp(Tcl_Interp *interp,
3136			    Tcl_Parse *parsePtr, Command *cmdPtr,
3137			    struct CompileEnv *envPtr);
3138MODULE_SCOPE int	TclCompileRegexpCmd(Tcl_Interp *interp,
3139			    Tcl_Parse *parsePtr, Command *cmdPtr,
3140			    struct CompileEnv *envPtr);
3141MODULE_SCOPE int	TclCompileReturnCmd(Tcl_Interp *interp,
3142			    Tcl_Parse *parsePtr, Command *cmdPtr,
3143			    struct CompileEnv *envPtr);
3144MODULE_SCOPE int	TclCompileSetCmd(Tcl_Interp *interp,
3145			    Tcl_Parse *parsePtr, Command *cmdPtr,
3146			    struct CompileEnv *envPtr);
3147MODULE_SCOPE int	TclCompileStringCmpCmd(Tcl_Interp *interp,
3148			    Tcl_Parse *parsePtr, Command *cmdPtr,
3149			    struct CompileEnv *envPtr);
3150MODULE_SCOPE int	TclCompileStringEqualCmd(Tcl_Interp *interp,
3151			    Tcl_Parse *parsePtr, Command *cmdPtr,
3152			    struct CompileEnv *envPtr);
3153MODULE_SCOPE int	TclCompileStringIndexCmd(Tcl_Interp *interp,
3154			    Tcl_Parse *parsePtr, Command *cmdPtr,
3155			    struct CompileEnv *envPtr);
3156MODULE_SCOPE int	TclCompileStringLenCmd(Tcl_Interp *interp,
3157			    Tcl_Parse *parsePtr, Command *cmdPtr,
3158			    struct CompileEnv *envPtr);
3159MODULE_SCOPE int	TclCompileStringMatchCmd(Tcl_Interp *interp,
3160			    Tcl_Parse *parsePtr, Command *cmdPtr,
3161			    struct CompileEnv *envPtr);
3162MODULE_SCOPE int	TclCompileSwitchCmd(Tcl_Interp *interp,
3163			    Tcl_Parse *parsePtr, Command *cmdPtr,
3164			    struct CompileEnv *envPtr);
3165MODULE_SCOPE int	TclCompileUpvarCmd(Tcl_Interp *interp,
3166			    Tcl_Parse *parsePtr, Command *cmdPtr,
3167			    struct CompileEnv *envPtr);
3168MODULE_SCOPE int	TclCompileVariableCmd(Tcl_Interp *interp,
3169			    Tcl_Parse *parsePtr, Command *cmdPtr,
3170			    struct CompileEnv *envPtr);
3171MODULE_SCOPE int	TclCompileWhileCmd(Tcl_Interp *interp,
3172			    Tcl_Parse *parsePtr, Command *cmdPtr,
3173			    struct CompileEnv *envPtr);
3174
3175MODULE_SCOPE int	TclInvertOpCmd(ClientData clientData,
3176			    Tcl_Interp *interp, int objc,
3177			    Tcl_Obj *const objv[]);
3178MODULE_SCOPE int	TclCompileInvertOpCmd(Tcl_Interp *interp,
3179			    Tcl_Parse *parsePtr, Command *cmdPtr,
3180			    struct CompileEnv *envPtr);
3181MODULE_SCOPE int	TclNotOpCmd(ClientData clientData,
3182			    Tcl_Interp *interp, int objc,
3183			    Tcl_Obj *const objv[]);
3184MODULE_SCOPE int	TclCompileNotOpCmd(Tcl_Interp *interp,
3185			    Tcl_Parse *parsePtr, Command *cmdPtr,
3186			    struct CompileEnv *envPtr);
3187MODULE_SCOPE int	TclAddOpCmd(ClientData clientData,
3188			    Tcl_Interp *interp, int objc,
3189			    Tcl_Obj *const objv[]);
3190MODULE_SCOPE int	TclCompileAddOpCmd(Tcl_Interp *interp,
3191			    Tcl_Parse *parsePtr, Command *cmdPtr,
3192			    struct CompileEnv *envPtr);
3193MODULE_SCOPE int	TclMulOpCmd(ClientData clientData,
3194			    Tcl_Interp *interp, int objc,
3195			    Tcl_Obj *const objv[]);
3196MODULE_SCOPE int	TclCompileMulOpCmd(Tcl_Interp *interp,
3197			    Tcl_Parse *parsePtr, Command *cmdPtr,
3198			    struct CompileEnv *envPtr);
3199MODULE_SCOPE int	TclAndOpCmd(ClientData clientData,
3200			    Tcl_Interp *interp, int objc,
3201			    Tcl_Obj *const objv[]);
3202MODULE_SCOPE int	TclCompileAndOpCmd(Tcl_Interp *interp,
3203			    Tcl_Parse *parsePtr, Command *cmdPtr,
3204			    struct CompileEnv *envPtr);
3205MODULE_SCOPE int	TclOrOpCmd(ClientData clientData,
3206			    Tcl_Interp *interp, int objc,
3207			    Tcl_Obj *const objv[]);
3208MODULE_SCOPE int	TclCompileOrOpCmd(Tcl_Interp *interp,
3209			    Tcl_Parse *parsePtr, Command *cmdPtr,
3210			    struct CompileEnv *envPtr);
3211MODULE_SCOPE int	TclXorOpCmd(ClientData clientData,
3212			    Tcl_Interp *interp, int objc,
3213			    Tcl_Obj *const objv[]);
3214MODULE_SCOPE int	TclCompileXorOpCmd(Tcl_Interp *interp,
3215			    Tcl_Parse *parsePtr, Command *cmdPtr,
3216			    struct CompileEnv *envPtr);
3217MODULE_SCOPE int	TclPowOpCmd(ClientData clientData,
3218			    Tcl_Interp *interp, int objc,
3219			    Tcl_Obj *const objv[]);
3220MODULE_SCOPE int	TclCompilePowOpCmd(Tcl_Interp *interp,
3221			    Tcl_Parse *parsePtr, Command *cmdPtr,
3222			    struct CompileEnv *envPtr);
3223MODULE_SCOPE int	TclLshiftOpCmd(ClientData clientData,
3224			    Tcl_Interp *interp, int objc,
3225			    Tcl_Obj *const objv[]);
3226MODULE_SCOPE int	TclCompileLshiftOpCmd(Tcl_Interp *interp,
3227			    Tcl_Parse *parsePtr, Command *cmdPtr,
3228			    struct CompileEnv *envPtr);
3229MODULE_SCOPE int	TclRshiftOpCmd(ClientData clientData,
3230			    Tcl_Interp *interp, int objc,
3231			    Tcl_Obj *const objv[]);
3232MODULE_SCOPE int	TclCompileRshiftOpCmd(Tcl_Interp *interp,
3233			    Tcl_Parse *parsePtr, Command *cmdPtr,
3234			    struct CompileEnv *envPtr);
3235MODULE_SCOPE int	TclModOpCmd(ClientData clientData,
3236			    Tcl_Interp *interp, int objc,
3237			    Tcl_Obj *const objv[]);
3238MODULE_SCOPE int	TclCompileModOpCmd(Tcl_Interp *interp,
3239			    Tcl_Parse *parsePtr, Command *cmdPtr,
3240			    struct CompileEnv *envPtr);
3241MODULE_SCOPE int	TclNeqOpCmd(ClientData clientData,
3242			    Tcl_Interp *interp, int objc,
3243			    Tcl_Obj *const objv[]);
3244MODULE_SCOPE int	TclCompileNeqOpCmd(Tcl_Interp *interp,
3245			    Tcl_Parse *parsePtr, Command *cmdPtr,
3246			    struct CompileEnv *envPtr);
3247MODULE_SCOPE int	TclStrneqOpCmd(ClientData clientData,
3248			    Tcl_Interp *interp, int objc,
3249			    Tcl_Obj *const objv[]);
3250MODULE_SCOPE int	TclCompileStrneqOpCmd(Tcl_Interp *interp,
3251			    Tcl_Parse *parsePtr, Command *cmdPtr,
3252			    struct CompileEnv *envPtr);
3253MODULE_SCOPE int	TclInOpCmd(ClientData clientData,
3254			    Tcl_Interp *interp, int objc,
3255			    Tcl_Obj *const objv[]);
3256MODULE_SCOPE int	TclCompileInOpCmd(Tcl_Interp *interp,
3257			    Tcl_Parse *parsePtr, Command *cmdPtr,
3258			    struct CompileEnv *envPtr);
3259MODULE_SCOPE int	TclNiOpCmd(ClientData clientData,
3260			    Tcl_Interp *interp, int objc,
3261			    Tcl_Obj *const objv[]);
3262MODULE_SCOPE int	TclCompileNiOpCmd(Tcl_Interp *interp,
3263			    Tcl_Parse *parsePtr, Command *cmdPtr,
3264			    struct CompileEnv *envPtr);
3265MODULE_SCOPE int	TclMinusOpCmd(ClientData clientData,
3266			    Tcl_Interp *interp, int objc,
3267			    Tcl_Obj *const objv[]);
3268MODULE_SCOPE int	TclCompileMinusOpCmd(Tcl_Interp *interp,
3269			    Tcl_Parse *parsePtr, Command *cmdPtr,
3270			    struct CompileEnv *envPtr);
3271MODULE_SCOPE int	TclDivOpCmd(ClientData clientData,
3272			    Tcl_Interp *interp, int objc,
3273			    Tcl_Obj *const objv[]);
3274MODULE_SCOPE int	TclCompileDivOpCmd(Tcl_Interp *interp,
3275			    Tcl_Parse *parsePtr, Command *cmdPtr,
3276			    struct CompileEnv *envPtr);
3277MODULE_SCOPE int	TclLessOpCmd(ClientData clientData,
3278			    Tcl_Interp *interp, int objc,
3279			    Tcl_Obj *const objv[]);
3280MODULE_SCOPE int	TclCompileLessOpCmd(Tcl_Interp *interp,
3281			    Tcl_Parse *parsePtr, Command *cmdPtr,
3282			    struct CompileEnv *envPtr);
3283MODULE_SCOPE int	TclLeqOpCmd(ClientData clientData,
3284			    Tcl_Interp *interp, int objc,
3285			    Tcl_Obj *const objv[]);
3286MODULE_SCOPE int	TclCompileLeqOpCmd(Tcl_Interp *interp,
3287			    Tcl_Parse *parsePtr, Command *cmdPtr,
3288			    struct CompileEnv *envPtr);
3289MODULE_SCOPE int	TclGreaterOpCmd(ClientData clientData,
3290			    Tcl_Interp *interp, int objc,
3291			    Tcl_Obj *const objv[]);
3292MODULE_SCOPE int	TclCompileGreaterOpCmd(Tcl_Interp *interp,
3293			    Tcl_Parse *parsePtr, Command *cmdPtr,
3294			    struct CompileEnv *envPtr);
3295MODULE_SCOPE int	TclGeqOpCmd(ClientData clientData,
3296			    Tcl_Interp *interp, int objc,
3297			    Tcl_Obj *const objv[]);
3298MODULE_SCOPE int	TclCompileGeqOpCmd(Tcl_Interp *interp,
3299			    Tcl_Parse *parsePtr, Command *cmdPtr,
3300			    struct CompileEnv *envPtr);
3301MODULE_SCOPE int	TclEqOpCmd(ClientData clientData,
3302			    Tcl_Interp *interp, int objc,
3303			    Tcl_Obj *const objv[]);
3304MODULE_SCOPE int	TclCompileEqOpCmd(Tcl_Interp *interp,
3305			    Tcl_Parse *parsePtr, Command *cmdPtr,
3306			    struct CompileEnv *envPtr);
3307MODULE_SCOPE int	TclStreqOpCmd(ClientData clientData,
3308			    Tcl_Interp *interp, int objc,
3309			    Tcl_Obj *const objv[]);
3310MODULE_SCOPE int	TclCompileStreqOpCmd(Tcl_Interp *interp,
3311			    Tcl_Parse *parsePtr, Command *cmdPtr,
3312			    struct CompileEnv *envPtr);
3313
3314/*
3315 * Functions defined in generic/tclVar.c and currenttly exported only for use
3316 * by the bytecode compiler and engine. Some of these could later be placed in
3317 * the public interface.
3318 */
3319
3320MODULE_SCOPE Var *	TclObjLookupVarEx(Tcl_Interp * interp,
3321			    Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags,
3322			    const char *msg, const int createPart1,
3323			    const int createPart2, Var **arrayPtrPtr);
3324MODULE_SCOPE Var *	TclLookupArrayElement(Tcl_Interp *interp,
3325			    Tcl_Obj *arrayNamePtr, Tcl_Obj *elNamePtr,
3326			    const int flags, const char *msg,
3327			    const int createPart1, const int createPart2,
3328			    Var *arrayPtr, int index);
3329MODULE_SCOPE Tcl_Obj *	TclPtrGetVar(Tcl_Interp *interp,
3330			    Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr,
3331			    Tcl_Obj *part2Ptr, const int flags, int index);
3332MODULE_SCOPE Tcl_Obj *	TclPtrSetVar(Tcl_Interp *interp,
3333			    Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr,
3334			    Tcl_Obj *part2Ptr, Tcl_Obj *newValuePtr,
3335			    const int flags, int index);
3336MODULE_SCOPE Tcl_Obj *	TclPtrIncrObjVar(Tcl_Interp *interp,
3337			    Var *varPtr, Var *arrayPtr, Tcl_Obj *part1Ptr,
3338			    Tcl_Obj *part2Ptr, Tcl_Obj *incrPtr,
3339			    const int flags, int index);
3340MODULE_SCOPE int	TclPtrObjMakeUpvar(Tcl_Interp *interp, Var *otherPtr,
3341			    Tcl_Obj *myNamePtr, int myFlags, int index);
3342MODULE_SCOPE void	TclInvalidateNsPath(Namespace *nsPtr);
3343
3344/*
3345 * The new extended interface to the variable traces.
3346 */
3347
3348MODULE_SCOPE int	TclObjCallVarTraces(Interp *iPtr, Var *arrayPtr,
3349			    Var *varPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr,
3350			    int flags, int leaveErrMsg, int index);
3351
3352/*
3353 * So tclObj.c and tclDictObj.c can share these implementations.
3354 */
3355
3356MODULE_SCOPE int	TclCompareObjKeys(void *keyPtr, Tcl_HashEntry *hPtr);
3357MODULE_SCOPE void	TclFreeObjEntry(Tcl_HashEntry *hPtr);
3358MODULE_SCOPE unsigned	TclHashObjKey(Tcl_HashTable *tablePtr, void *keyPtr);
3359
3360/*
3361 *----------------------------------------------------------------
3362 * Macros used by the Tcl core to create and release Tcl objects.
3363 * TclNewObj(objPtr) creates a new object denoting an empty string.
3364 * TclDecrRefCount(objPtr) decrements the object's reference count, and frees
3365 * the object if its reference count is zero. These macros are inline versions
3366 * of Tcl_NewObj() and Tcl_DecrRefCount(). Notice that the names differ in not
3367 * having a "_" after the "Tcl". Notice also that these macros reference their
3368 * argument more than once, so you should avoid calling them with an
3369 * expression that is expensive to compute or has side effects. The ANSI C
3370 * "prototypes" for these macros are:
3371 *
3372 * MODULE_SCOPE void	TclNewObj(Tcl_Obj *objPtr);
3373 * MODULE_SCOPE void	TclDecrRefCount(Tcl_Obj *objPtr);
3374 *
3375 * These macros are defined in terms of two macros that depend on memory
3376 * allocator in use: TclAllocObjStorage, TclFreeObjStorage. They are defined
3377 * below.
3378 *----------------------------------------------------------------
3379 */
3380
3381/*
3382 * DTrace object allocation probe macros.
3383 */
3384
3385#ifdef USE_DTRACE
3386#include "tclDTrace.h"
3387#define	TCL_DTRACE_OBJ_CREATE(objPtr)	TCL_OBJ_CREATE(objPtr)
3388#define	TCL_DTRACE_OBJ_FREE(objPtr)	TCL_OBJ_FREE(objPtr)
3389#else /* USE_DTRACE */
3390#define	TCL_DTRACE_OBJ_CREATE(objPtr)	{}
3391#define	TCL_DTRACE_OBJ_FREE(objPtr)	{}
3392#endif /* USE_DTRACE */
3393
3394#ifdef TCL_COMPILE_STATS
3395#  define TclIncrObjsAllocated() \
3396    tclObjsAlloced++
3397#  define TclIncrObjsFreed() \
3398    tclObjsFreed++
3399#else
3400#  define TclIncrObjsAllocated()
3401#  define TclIncrObjsFreed()
3402#endif /* TCL_COMPILE_STATS */
3403
3404#ifndef TCL_MEM_DEBUG
3405# define TclNewObj(objPtr) \
3406    TclIncrObjsAllocated(); \
3407    TclAllocObjStorage(objPtr); \
3408    (objPtr)->refCount = 0; \
3409    (objPtr)->bytes    = tclEmptyStringRep; \
3410    (objPtr)->length   = 0; \
3411    (objPtr)->typePtr  = NULL; \
3412    TCL_DTRACE_OBJ_CREATE(objPtr)
3413
3414/*
3415 * Invalidate the string rep first so we can use the bytes value for our
3416 * pointer chain, and signal an obj deletion (as opposed to shimmering) with
3417 * 'length == -1'.
3418 * Use empty 'if ; else' to handle use in unbraced outer if/else conditions.
3419 */
3420
3421# define TclDecrRefCount(objPtr) \
3422    if (--(objPtr)->refCount > 0) ; else { \
3423	if (!(objPtr)->typePtr || !(objPtr)->typePtr->freeIntRepProc) { \
3424	    TCL_DTRACE_OBJ_FREE(objPtr); \
3425	    if ((objPtr)->bytes \
3426		    && ((objPtr)->bytes != tclEmptyStringRep)) { \
3427		ckfree((char *) (objPtr)->bytes); \
3428	    } \
3429	    (objPtr)->length = -1; \
3430	    TclFreeObjStorage(objPtr); \
3431	    TclIncrObjsFreed(); \
3432	} else { \
3433	    TclFreeObj(objPtr); \
3434	} \
3435    }
3436
3437#if defined(PURIFY)
3438
3439/*
3440 * The PURIFY mode is like the regular mode, but instead of doing block
3441 * Tcl_Obj allocation and keeping a freed list for efficiency, it always
3442 * allocates and frees a single Tcl_Obj so that tools like Purify can better
3443 * track memory leaks.
3444 */
3445
3446#  define TclAllocObjStorage(objPtr) \
3447	(objPtr) = (Tcl_Obj *) Tcl_Alloc(sizeof(Tcl_Obj))
3448
3449#  define TclFreeObjStorage(objPtr) \
3450	ckfree((char *) (objPtr))
3451
3452#undef USE_THREAD_ALLOC
3453#elif defined(TCL_THREADS) && defined(USE_THREAD_ALLOC)
3454
3455/*
3456 * The TCL_THREADS mode is like the regular mode but allocates Tcl_Obj's from
3457 * per-thread caches.
3458 */
3459
3460MODULE_SCOPE Tcl_Obj *	TclThreadAllocObj(void);
3461MODULE_SCOPE void	TclThreadFreeObj(Tcl_Obj *);
3462MODULE_SCOPE Tcl_Mutex *TclpNewAllocMutex(void);
3463MODULE_SCOPE void	TclFreeAllocCache(void *);
3464MODULE_SCOPE void *	TclpGetAllocCache(void);
3465MODULE_SCOPE void	TclpSetAllocCache(void *);
3466MODULE_SCOPE void	TclpFreeAllocMutex(Tcl_Mutex *mutex);
3467MODULE_SCOPE void	TclpFreeAllocCache(void *);
3468
3469#  define TclAllocObjStorage(objPtr) \
3470	(objPtr) = TclThreadAllocObj()
3471
3472#  define TclFreeObjStorage(objPtr) \
3473	TclThreadFreeObj((objPtr))
3474
3475#else /* not PURIFY or USE_THREAD_ALLOC */
3476
3477#ifdef TCL_THREADS
3478/* declared in tclObj.c */
3479MODULE_SCOPE Tcl_Mutex	tclObjMutex;
3480#endif
3481
3482#  define TclAllocObjStorage(objPtr) \
3483	Tcl_MutexLock(&tclObjMutex); \
3484	if (tclFreeObjList == NULL) { \
3485	    TclAllocateFreeObjects(); \
3486	} \
3487	(objPtr) = tclFreeObjList; \
3488	tclFreeObjList = (Tcl_Obj *) \
3489		tclFreeObjList->internalRep.otherValuePtr; \
3490	Tcl_MutexUnlock(&tclObjMutex)
3491
3492#  define TclFreeObjStorage(objPtr) \
3493	Tcl_MutexLock(&tclObjMutex); \
3494	(objPtr)->internalRep.otherValuePtr = (void *) tclFreeObjList; \
3495	tclFreeObjList = (objPtr); \
3496	Tcl_MutexUnlock(&tclObjMutex)
3497#endif
3498
3499#else /* TCL_MEM_DEBUG */
3500MODULE_SCOPE void	TclDbInitNewObj(Tcl_Obj *objPtr, CONST char *file,
3501			    int line);
3502
3503# define TclDbNewObj(objPtr, file, line) \
3504    TclIncrObjsAllocated(); \
3505    (objPtr) = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), (file), (line)); \
3506    TclDbInitNewObj((objPtr), (file), (line)); \
3507    TCL_DTRACE_OBJ_CREATE(objPtr)
3508
3509# define TclNewObj(objPtr) \
3510    TclDbNewObj(objPtr, __FILE__, __LINE__);
3511
3512# define TclDecrRefCount(objPtr) \
3513    Tcl_DbDecrRefCount(objPtr, __FILE__, __LINE__)
3514
3515# define TclNewListObjDirect(objc, objv) \
3516    TclDbNewListObjDirect(objc, objv, __FILE__, __LINE__)
3517
3518#undef USE_THREAD_ALLOC
3519#endif /* TCL_MEM_DEBUG */
3520
3521/*
3522 *----------------------------------------------------------------
3523 * Macro used by the Tcl core to set a Tcl_Obj's string representation to a
3524 * copy of the "len" bytes starting at "bytePtr". This code works even if the
3525 * byte array contains NULLs as long as the length is correct. Because "len"
3526 * is referenced multiple times, it should be as simple an expression as
3527 * possible. The ANSI C "prototype" for this macro is:
3528 *
3529 * MODULE_SCOPE void TclInitStringRep(Tcl_Obj *objPtr, char *bytePtr, int len);
3530 *
3531 * This macro should only be called on an unshared objPtr where
3532 *  objPtr->typePtr->freeIntRepProc == NULL
3533 *----------------------------------------------------------------
3534 */
3535
3536#define TclInitStringRep(objPtr, bytePtr, len) \
3537    if ((len) == 0) { \
3538	(objPtr)->bytes	 = tclEmptyStringRep; \
3539	(objPtr)->length = 0; \
3540    } else { \
3541	(objPtr)->bytes = (char *) ckalloc((unsigned) ((len) + 1)); \
3542	memcpy((void *) (objPtr)->bytes, (void *) (bytePtr), \
3543		(unsigned) (len)); \
3544	(objPtr)->bytes[len] = '\0'; \
3545	(objPtr)->length = (len); \
3546    }
3547
3548/*
3549 *----------------------------------------------------------------
3550 * Macro used by the Tcl core to get the string representation's byte array
3551 * pointer from a Tcl_Obj. This is an inline version of Tcl_GetString(). The
3552 * macro's expression result is the string rep's byte pointer which might be
3553 * NULL. The bytes referenced by this pointer must not be modified by the
3554 * caller. The ANSI C "prototype" for this macro is:
3555 *
3556 * MODULE_SCOPE char *	TclGetString(Tcl_Obj *objPtr);
3557 *----------------------------------------------------------------
3558 */
3559
3560#define TclGetString(objPtr) \
3561    ((objPtr)->bytes? (objPtr)->bytes : Tcl_GetString((objPtr)))
3562
3563#define TclGetStringFromObj(objPtr, lenPtr) \
3564    ((objPtr)->bytes \
3565	    ? (*(lenPtr) = (objPtr)->length, (objPtr)->bytes)	\
3566	    : Tcl_GetStringFromObj((objPtr), (lenPtr)))
3567
3568/*
3569 *----------------------------------------------------------------
3570 * Macro used by the Tcl core to clean out an object's internal
3571 * representation. Does not actually reset the rep's bytes. The ANSI C
3572 * "prototype" for this macro is:
3573 *
3574 * MODULE_SCOPE void	TclFreeIntRep(Tcl_Obj *objPtr);
3575 *----------------------------------------------------------------
3576 */
3577
3578#define TclFreeIntRep(objPtr) \
3579    if ((objPtr)->typePtr != NULL && \
3580	    (objPtr)->typePtr->freeIntRepProc != NULL) { \
3581	(objPtr)->typePtr->freeIntRepProc(objPtr); \
3582    }
3583
3584/*
3585 *----------------------------------------------------------------
3586 * Macro used by the Tcl core to clean out an object's string representation.
3587 * The ANSI C "prototype" for this macro is:
3588 *
3589 * MODULE_SCOPE void	TclInvalidateStringRep(Tcl_Obj *objPtr);
3590 *----------------------------------------------------------------
3591 */
3592
3593#define TclInvalidateStringRep(objPtr) \
3594    if (objPtr->bytes != NULL) { \
3595	if (objPtr->bytes != tclEmptyStringRep) { \
3596	    ckfree((char *) objPtr->bytes); \
3597	} \
3598	objPtr->bytes = NULL; \
3599    }
3600
3601/*
3602 *----------------------------------------------------------------
3603 * Macros used by the Tcl core to grow Tcl_Token arrays. They use the same
3604 * growth algorithm as used in tclStringObj.c for growing strings. The ANSI C
3605 * "prototype" for this macro is:
3606 *
3607 * MODULE_SCOPE void	TclGrowTokenArray(Tcl_Token *tokenPtr, int used,
3608 *				int available, int append,
3609 *				Tcl_Token *staticPtr);
3610 * MODULE_SCOPE void	TclGrowParseTokenArray(Tcl_Parse *parsePtr,
3611 *				int append);
3612 *----------------------------------------------------------------
3613 */
3614
3615#define TCL_MAX_TOKENS (int)(UINT_MAX / sizeof(Tcl_Token))
3616#define TCL_MIN_TOKEN_GROWTH 50
3617#define TclGrowTokenArray(tokenPtr, used, available, append, staticPtr)	\
3618{									\
3619    int needed = (used) + (append);					\
3620    if (needed > TCL_MAX_TOKENS) {					\
3621	Tcl_Panic("max # of tokens for a Tcl parse (%d) exceeded",	\
3622		TCL_MAX_TOKENS);					\
3623    }									\
3624    if (needed > (available)) {						\
3625	int allocated = 2 * needed;					\
3626	Tcl_Token *oldPtr = (tokenPtr);					\
3627	Tcl_Token *newPtr;						\
3628	if (oldPtr == (staticPtr)) {					\
3629	    oldPtr = NULL;						\
3630	}								\
3631	if (allocated > TCL_MAX_TOKENS) {				\
3632	    allocated = TCL_MAX_TOKENS;					\
3633	}								\
3634	newPtr = (Tcl_Token *) attemptckrealloc((char *) oldPtr,	\
3635		(unsigned int) (allocated * sizeof(Tcl_Token)));	\
3636	if (newPtr == NULL) {						\
3637	    allocated = needed + (append) + TCL_MIN_TOKEN_GROWTH;	\
3638	    if (allocated > TCL_MAX_TOKENS) {				\
3639		allocated = TCL_MAX_TOKENS;				\
3640	    }								\
3641	    newPtr = (Tcl_Token *) ckrealloc((char *) oldPtr,		\
3642		    (unsigned int) (allocated * sizeof(Tcl_Token)));	\
3643	}								\
3644	(available) = allocated;					\
3645	if (oldPtr == NULL) {						\
3646	    memcpy((VOID *) newPtr, (VOID *) staticPtr,			\
3647		    (size_t) ((used) * sizeof(Tcl_Token)));		\
3648	}								\
3649	(tokenPtr) = newPtr;						\
3650    }									\
3651}
3652
3653#define TclGrowParseTokenArray(parsePtr, append)			\
3654    TclGrowTokenArray((parsePtr)->tokenPtr, (parsePtr)->numTokens,	\
3655	    (parsePtr)->tokensAvailable, (append),			\
3656	    (parsePtr)->staticTokens)
3657
3658/*
3659 *----------------------------------------------------------------
3660 * Macro used by the Tcl core get a unicode char from a utf string. It checks
3661 * to see if we have a one-byte utf char before calling the real
3662 * Tcl_UtfToUniChar, as this will save a lot of time for primarily ASCII
3663 * string handling. The macro's expression result is 1 for the 1-byte case or
3664 * the result of Tcl_UtfToUniChar. The ANSI C "prototype" for this macro is:
3665 *
3666 * MODULE_SCOPE int	TclUtfToUniChar(const char *string, Tcl_UniChar *ch);
3667 *----------------------------------------------------------------
3668 */
3669
3670#define TclUtfToUniChar(str, chPtr) \
3671	((((unsigned char) *(str)) < 0xC0) ? \
3672	    ((*(chPtr) = (Tcl_UniChar) *(str)), 1) \
3673	    : Tcl_UtfToUniChar(str, chPtr))
3674
3675/*
3676 *----------------------------------------------------------------
3677 * Macro used by the Tcl core to compare Unicode strings. On big-endian
3678 * systems we can use the more efficient memcmp, but this would not be
3679 * lexically correct on little-endian systems. The ANSI C "prototype" for
3680 * this macro is:
3681 *
3682 * MODULE_SCOPE int	TclUniCharNcmp(const Tcl_UniChar *cs,
3683 *			    const Tcl_UniChar *ct, unsigned long n);
3684 *----------------------------------------------------------------
3685 */
3686
3687#ifdef WORDS_BIGENDIAN
3688#   define TclUniCharNcmp(cs,ct,n) memcmp((cs),(ct),(n)*sizeof(Tcl_UniChar))
3689#else /* !WORDS_BIGENDIAN */
3690#   define TclUniCharNcmp Tcl_UniCharNcmp
3691#endif /* WORDS_BIGENDIAN */
3692
3693/*
3694 *----------------------------------------------------------------
3695 * Macro used by the Tcl core to increment a namespace's export export epoch
3696 * counter. The ANSI C "prototype" for this macro is:
3697 *
3698 * MODULE_SCOPE void	TclInvalidateNsCmdLookup(Namespace *nsPtr);
3699 *----------------------------------------------------------------
3700 */
3701
3702#define TclInvalidateNsCmdLookup(nsPtr) \
3703    if ((nsPtr)->numExportPatterns) { \
3704	(nsPtr)->exportLookupEpoch++; \
3705    }
3706
3707/*
3708 *----------------------------------------------------------------------
3709 *
3710 * Core procedures added to libtommath for bignum manipulation.
3711 *
3712 *----------------------------------------------------------------------
3713 */
3714
3715MODULE_SCOPE int	TclTommath_Init(Tcl_Interp *interp);
3716MODULE_SCOPE void	TclBNInitBignumFromLong(mp_int *bignum, long initVal);
3717MODULE_SCOPE void	TclBNInitBignumFromWideInt(mp_int *bignum,
3718			    Tcl_WideInt initVal);
3719MODULE_SCOPE void	TclBNInitBignumFromWideUInt(mp_int *bignum,
3720			    Tcl_WideUInt initVal);
3721
3722/*
3723 *----------------------------------------------------------------
3724 * Macro used by the Tcl core to check whether a pattern has any characters
3725 * special to [string match]. The ANSI C "prototype" for this macro is:
3726 *
3727 * MODULE_SCOPE int	TclMatchIsTrivial(const char *pattern);
3728 *----------------------------------------------------------------
3729 */
3730
3731#define TclMatchIsTrivial(pattern)	strpbrk((pattern), "*[?\\") == NULL
3732
3733/*
3734 *----------------------------------------------------------------
3735 * Macro used by the Tcl core to write the string rep of a long integer to a
3736 * character buffer. The ANSI C "prototype" for this macro is:
3737 *
3738 * MODULE_SCOPE int	TclFormatInt(char *buf, long n);
3739 *----------------------------------------------------------------
3740 */
3741
3742#define TclFormatInt(buf, n)		sprintf((buf), "%ld", (long)(n))
3743
3744/*
3745 *----------------------------------------------------------------
3746 * Macros used by the Tcl core to set a Tcl_Obj's numeric representation
3747 * avoiding the corresponding function calls in time critical parts of the
3748 * core. They should only be called on unshared objects. The ANSI C
3749 * "prototypes" for these macros are:
3750 *
3751 * MODULE_SCOPE void	TclSetIntObj(Tcl_Obj *objPtr, int intValue);
3752 * MODULE_SCOPE void	TclSetLongObj(Tcl_Obj *objPtr, long longValue);
3753 * MODULE_SCOPE void	TclSetBooleanObj(Tcl_Obj *objPtr, long boolValue);
3754 * MODULE_SCOPE void	TclSetWideIntObj(Tcl_Obj *objPtr, Tcl_WideInt w);
3755 * MODULE_SCOPE void	TclSetDoubleObj(Tcl_Obj *objPtr, double d);
3756 *----------------------------------------------------------------
3757 */
3758
3759#define TclSetIntObj(objPtr, i) \
3760    TclInvalidateStringRep(objPtr);\
3761    TclFreeIntRep(objPtr); \
3762    (objPtr)->internalRep.longValue = (long)(i); \
3763    (objPtr)->typePtr = &tclIntType
3764
3765#define TclSetLongObj(objPtr, l) \
3766    TclSetIntObj((objPtr), (l))
3767
3768/*
3769 * NOTE: There is to be no such thing as a "pure" boolean. Boolean values set
3770 * programmatically go straight to being "int" Tcl_Obj's, with value 0 or 1.
3771 * The only "boolean" Tcl_Obj's shall be those holding the cached boolean
3772 * value of strings like: "yes", "no", "true", "false", "on", "off".
3773 */
3774
3775#define TclSetBooleanObj(objPtr, b) \
3776    TclSetIntObj((objPtr), ((b)? 1 : 0));
3777
3778#ifndef NO_WIDE_TYPE
3779#define TclSetWideIntObj(objPtr, w) \
3780    TclInvalidateStringRep(objPtr);\
3781    TclFreeIntRep(objPtr); \
3782    (objPtr)->internalRep.wideValue = (Tcl_WideInt)(w); \
3783    (objPtr)->typePtr = &tclWideIntType
3784#endif
3785
3786#define TclSetDoubleObj(objPtr, d) \
3787    TclInvalidateStringRep(objPtr);\
3788    TclFreeIntRep(objPtr); \
3789    (objPtr)->internalRep.doubleValue = (double)(d); \
3790    (objPtr)->typePtr = &tclDoubleType
3791
3792/*
3793 *----------------------------------------------------------------
3794 * Macros used by the Tcl core to create and initialise objects of standard
3795 * types, avoiding the corresponding function calls in time critical parts of
3796 * the core. The ANSI C "prototypes" for these macros are:
3797 *
3798 * MODULE_SCOPE void	TclNewIntObj(Tcl_Obj *objPtr, int i);
3799 * MODULE_SCOPE void	TclNewLongObj(Tcl_Obj *objPtr, long l);
3800 * MODULE_SCOPE void	TclNewBooleanObj(Tcl_Obj *objPtr, int b);
3801 * MODULE_SCOPE void	TclNewWideObj(Tcl_Obj *objPtr, Tcl_WideInt w);
3802 * MODULE_SCOPE void	TclNewDoubleObj(Tcl_Obj *objPtr, double d);
3803 * MODULE_SCOPE void	TclNewStringObj(Tcl_Obj *objPtr, char *s, int len);
3804 * MODULE_SCOPE void	TclNewLiteralStringObj(Tcl_Obj*objPtr, char*sLiteral);
3805 *
3806 *----------------------------------------------------------------
3807 */
3808
3809#ifndef TCL_MEM_DEBUG
3810#define TclNewIntObj(objPtr, i) \
3811    TclIncrObjsAllocated(); \
3812    TclAllocObjStorage(objPtr); \
3813    (objPtr)->refCount = 0; \
3814    (objPtr)->bytes = NULL; \
3815    (objPtr)->internalRep.longValue = (long)(i); \
3816    (objPtr)->typePtr = &tclIntType; \
3817    TCL_DTRACE_OBJ_CREATE(objPtr)
3818
3819#define TclNewLongObj(objPtr, l) \
3820    TclNewIntObj((objPtr), (l))
3821
3822/*
3823 * NOTE: There is to be no such thing as a "pure" boolean.
3824 * See comment above TclSetBooleanObj macro above.
3825 */
3826#define TclNewBooleanObj(objPtr, b) \
3827    TclNewIntObj((objPtr), ((b)? 1 : 0))
3828
3829#define TclNewDoubleObj(objPtr, d) \
3830    TclIncrObjsAllocated(); \
3831    TclAllocObjStorage(objPtr); \
3832    (objPtr)->refCount = 0; \
3833    (objPtr)->bytes = NULL; \
3834    (objPtr)->internalRep.doubleValue = (double)(d); \
3835    (objPtr)->typePtr = &tclDoubleType; \
3836    TCL_DTRACE_OBJ_CREATE(objPtr)
3837
3838#define TclNewStringObj(objPtr, s, len) \
3839    TclIncrObjsAllocated(); \
3840    TclAllocObjStorage(objPtr); \
3841    (objPtr)->refCount = 0; \
3842    TclInitStringRep((objPtr), (s), (len));\
3843    (objPtr)->typePtr = NULL; \
3844    TCL_DTRACE_OBJ_CREATE(objPtr)
3845
3846#else /* TCL_MEM_DEBUG */
3847#define TclNewIntObj(objPtr, i) \
3848    (objPtr) = Tcl_NewIntObj(i)
3849
3850#define TclNewLongObj(objPtr, l) \
3851    (objPtr) = Tcl_NewLongObj(l)
3852
3853#define TclNewBooleanObj(objPtr, b) \
3854    (objPtr) = Tcl_NewBooleanObj(b)
3855
3856#define TclNewDoubleObj(objPtr, d) \
3857    (objPtr) = Tcl_NewDoubleObj(d)
3858
3859#define TclNewStringObj(objPtr, s, len) \
3860    (objPtr) = Tcl_NewStringObj((s), (len))
3861#endif /* TCL_MEM_DEBUG */
3862
3863/*
3864 * The sLiteral argument *must* be a string literal; the incantation with
3865 * sizeof(sLiteral "") will fail to compile otherwise.
3866 */
3867#define TclNewLiteralStringObj(objPtr, sLiteral) \
3868    TclNewStringObj((objPtr), (sLiteral), (int) (sizeof(sLiteral "") - 1))
3869
3870/*
3871 *----------------------------------------------------------------
3872 * Macros used by the Tcl core to test for some special double values.
3873 * The ANSI C "prototypes" for these macros are:
3874 *
3875 * MODULE_SCOPE int	TclIsInfinite(double d);
3876 * MODULE_SCOPE int	TclIsNaN(double d);
3877 */
3878
3879#ifdef _MSC_VER
3880#    define TclIsInfinite(d)	(!(_finite((d))))
3881#    define TclIsNaN(d)		(_isnan((d)))
3882#else
3883#    define TclIsInfinite(d)	((d) > DBL_MAX || (d) < -DBL_MAX)
3884#    ifdef NO_ISNAN
3885#	 define TclIsNaN(d)	((d) != (d))
3886#    else
3887#	 define TclIsNaN(d)	(isnan(d))
3888#    endif
3889#endif
3890
3891/*
3892 * ----------------------------------------------------------------------
3893 * Macro to use to find the offset of a field in a structure. Computes number
3894 * of bytes from beginning of structure to a given field.
3895 */
3896
3897#ifdef offsetof
3898#define TclOffset(type, field) ((int) offsetof(type, field))
3899#else
3900#define TclOffset(type, field) ((int) ((char *) &((type *) 0)->field))
3901#endif
3902
3903/*
3904 *----------------------------------------------------------------
3905 * Inline version of Tcl_GetCurrentNamespace and Tcl_GetGlobalNamespace.
3906 */
3907
3908#define TclGetCurrentNamespace(interp) \
3909    (Tcl_Namespace *) ((Interp *)(interp))->varFramePtr->nsPtr
3910
3911#define TclGetGlobalNamespace(interp) \
3912    (Tcl_Namespace *) ((Interp *)(interp))->globalNsPtr
3913
3914/*
3915 *----------------------------------------------------------------
3916 * Inline version of TclCleanupCommand; still need the function as it is in
3917 * the internal stubs, but the core can use the macro instead.
3918 */
3919
3920#define TclCleanupCommandMacro(cmdPtr) \
3921    if (--(cmdPtr)->refCount <= 0) { \
3922	ckfree((char *) (cmdPtr));\
3923    }
3924
3925/*
3926 *----------------------------------------------------------------
3927 * Inline versions of Tcl_LimitReady() and Tcl_LimitExceeded to limit number
3928 * of calls out of the critical path. Note that this code isn't particularly
3929 * readable; the non-inline version (in tclInterp.c) is much easier to
3930 * understand. Note also that these macros takes different args (iPtr->limit)
3931 * to the non-inline version.
3932 */
3933
3934#define TclLimitExceeded(limit) ((limit).exceeded != 0)
3935
3936#define TclLimitReady(limit)						\
3937    (((limit).active == 0) ? 0 :					\
3938    (++(limit).granularityTicker,					\
3939    ((((limit).active & TCL_LIMIT_COMMANDS) &&				\
3940	    (((limit).cmdGranularity == 1) ||				\
3941	    ((limit).granularityTicker % (limit).cmdGranularity == 0)))	\
3942	    ? 1 :							\
3943    (((limit).active & TCL_LIMIT_TIME) &&				\
3944	    (((limit).timeGranularity == 1) ||				\
3945	    ((limit).granularityTicker % (limit).timeGranularity == 0)))\
3946	    ? 1 : 0)))
3947
3948
3949#include "tclIntDecls.h"
3950#include "tclIntPlatDecls.h"
3951#include "tclTomMathDecls.h"
3952
3953#endif /* _TCLINT */
3954
3955/*
3956 * Local Variables:
3957 * mode: c
3958 * c-basic-offset: 4
3959 * fill-column: 78
3960 * End:
3961 */
3962