Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/generic/tclInt.h @ 35

Last change on this file since 35 was 25, checked in by landauf, 17 years ago

added tcl to libs

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